1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 package complex.imageManager;
23 
24 import com.sun.star.lang.XComponent;
25 import com.sun.star.lang.XInitialization;
26 import com.sun.star.lang.XMultiServiceFactory;
27 import com.sun.star.lang.XTypeProvider;
28 import com.sun.star.uno.UnoRuntime;
29 import com.sun.star.uno.XInterface;
30 import com.sun.star.ui.XImageManager;
31 import com.sun.star.ui.XModuleUIConfigurationManagerSupplier;
32 import com.sun.star.ui.XUIConfiguration;
33 import com.sun.star.ui.XUIConfigurationManager;
34 import com.sun.star.ui.XUIConfigurationPersistence;
35 
36 
37 // ---------- junit imports -----------------
38 import lib.TestParameters;
39 import org.junit.After;
40 import org.junit.AfterClass;
41 import org.junit.Before;
42 import org.junit.BeforeClass;
43 import org.junit.Test;
44 import org.openoffice.test.OfficeConnection;
45 import static org.junit.Assert.*;
46 // ------------------------------------------
47 
48 /**
49  *
50  */
51 public class CheckImageManager  {
52     boolean checkUIConfigManager = false;
53     XMultiServiceFactory xMSF = null;
54     /**
55      * The test parameters
56      */
57     private static TestParameters param = null;
58 
before()59     @Before public void before()
60     {
61         xMSF = getMSF();
62         param = new TestParameters();
63         param.put("ServiceFactory", xMSF); // some qadevOOo functions need the ServiceFactory
64     }
65 
66 //    public String[] getTestMethodNames() {
67 //        return new String[]{"checkImageManagerFromModule"};//, "checkImageManager"};
68 //    }
69 
checkImageManagerFromModule()70     @Test public void checkImageManagerFromModule()
71     {
72         System.out.println(" **** ImageManager from ModuleUIConfigurationManager *** ");
73         XUIConfigurationManager xManager = null;
74         try {
75             Object o = (XInterface)xMSF.createInstance(
76                     "com.sun.star.ui.ModuleUIConfigurationManagerSupplier");
77             XModuleUIConfigurationManagerSupplier xMUICMS =
78                     UnoRuntime.queryInterface(XModuleUIConfigurationManagerSupplier.class, o);
79             xManager = xMUICMS.getUIConfigurationManager(
80                     "com.sun.star.text.TextDocument");
81         }
82         catch(com.sun.star.uno.Exception e) {
83             fail("Exception. " + e.getMessage());
84         }
85         XImageManager xImageManager = UnoRuntime.queryInterface(XImageManager.class, xManager.getImageManager());
86         performChecks(xImageManager, "ModuleUIConfig", xManager);
87     }
88 
checkImageManager()89     public void checkImageManager() {
90         System.out.println(" **** ImageManager from UIConfigurationManager *** ");
91         XUIConfigurationManager xManager = null;
92         try {
93             xManager = UnoRuntime.queryInterface(XUIConfigurationManager.class, xMSF.createInstance("com.sun.star.comp.framework.UIConfigurationManager"));
94         }
95         catch(com.sun.star.uno.Exception e) {
96             fail("Exception. " + e.getMessage());
97         }
98 
99         XImageManager xImageManager = UnoRuntime.queryInterface(XImageManager.class, xManager.getImageManager());
100         performChecks(xImageManager, "UIConfig", xManager);
101     }
102 
performChecks(XImageManager xImageManager, String testObjectName, XUIConfigurationManager xManager)103     private void performChecks(XImageManager xImageManager, String testObjectName, XUIConfigurationManager xManager) {
104         util.dbg.printInterfaces(xImageManager);
105 
106         OXUIConfigurationListenerImpl configListener = new OXUIConfigurationListenerImpl(xManager, xMSF);
107         param.put("XUIConfiguration.XUIConfigurationListenerImpl", configListener);
108 
109         XInitialization xInit = UnoRuntime.queryInterface(XInitialization.class, xImageManager);
110         _XInitialization _xInit = new _XInitialization(param, xInit);
111         assertTrue(testObjectName + "::XInitialization.initialize", _xInit._initialize());
112 
113         // xImageManager is already there, just write a test ;-)
114         _XImageManager _xImage = new _XImageManager(param, xImageManager);
115         assertTrue(testObjectName + "::XImageManager.getAllImageNames", _xImage._getAllImageNames());
116         assertTrue(testObjectName + "::XImageManager.getImages", _xImage._getImages());
117         assertTrue(testObjectName + "::XImageManager.hasImage", _xImage._hasImage());
118         assertTrue(testObjectName + "::XImageManager.insertImages", _xImage._insertImages());
119         assertTrue(testObjectName + "::XImageManager.removeImages", _xImage._removeImages());
120         assertTrue(testObjectName + "::XImageManager.replaceImages", _xImage._replaceImages());
121         assertTrue(testObjectName + "::XImageManager.reset", _xImage._reset());
122 
123         XTypeProvider xType = UnoRuntime.queryInterface(XTypeProvider.class, xImageManager);
124         _XTypeProvider _xType = new _XTypeProvider(param, xType);
125         assertTrue(testObjectName + "::XTypeProvider.getImplementationId", _xType._getImplementationId());
126         assertTrue(testObjectName + "::XTypeProvider.getTypes", _xType._getTypes());
127 
128         XUIConfiguration xUIConfig = UnoRuntime.queryInterface(XUIConfiguration.class, xImageManager);
129         _XUIConfiguration _xUIConfig = new _XUIConfiguration(param, xUIConfig);
130         _xUIConfig.before();
131         assertTrue(testObjectName + "::XUIConfig.addConfigurationListener", _xUIConfig._addConfigurationListener());
132         assertTrue(testObjectName + "::XUIConfig.removeConfigurationListener", _xUIConfig._removeConfigurationListener());
133 
134         XUIConfigurationPersistence xUIConfigPersistence = (XUIConfigurationPersistence)UnoRuntime.queryInterface(XUIConfiguration.class, xImageManager);
135         _XUIConfigurationPersistence _xUIConfigPersistence = new _XUIConfigurationPersistence(param, xUIConfigPersistence);
136         _xUIConfigPersistence.before();
137         assertTrue(testObjectName + "::XUIConfigPersistence.isModified", _xUIConfigPersistence._isModified());
138         // System.out.println(testObjectName + "::XUIConfigPersistence.isReadOnly "+ _xUIConfigPersistence._isReadOnly());
139         assertTrue(testObjectName + "::XUIConfigPersistence.isReadOnly", _xUIConfigPersistence._isReadOnly());
140         assertTrue(testObjectName + "::XUIConfigPersistence.reload", _xUIConfigPersistence._reload());
141         assertTrue(testObjectName + "::XUIConfigPersistence.store", _xUIConfigPersistence._store());
142         assertTrue(testObjectName + "::XUIConfigPersistence.storeToStorage", _xUIConfigPersistence._storeToStorage());
143 
144         XComponent xComp = UnoRuntime.queryInterface(XComponent.class, xImageManager);
145         _XComponent _xComp = new _XComponent(param, xComp);
146         _xComp.before();
147         assertTrue(testObjectName + "::XComponent.addEventListener", _xComp._addEventListener());
148         assertTrue(testObjectName + "::XComponent.removeEventListener", _xComp._removeEventListener());
149         assertTrue(testObjectName + "::XComponent.dispose", _xComp._dispose());
150     }
151 
152 
153     class OXUIConfigurationListenerImpl implements _XUIConfiguration.XUIConfigurationListenerImpl {
154         private boolean triggered = false;
155         private XUIConfigurationManager xUIManager = null;
156         private XMultiServiceFactory xMSF = null;
157 
OXUIConfigurationListenerImpl(XUIConfigurationManager xUIManager, XMultiServiceFactory xMSF)158         public OXUIConfigurationListenerImpl(XUIConfigurationManager xUIManager, XMultiServiceFactory xMSF) {
159 
160             this.xUIManager = xUIManager;
161             this.xMSF = xMSF;
162         }
163 
actionWasTriggered()164         public boolean actionWasTriggered() {
165             return triggered;
166         }
167 
disposing(com.sun.star.lang.EventObject eventObject)168         public void disposing(com.sun.star.lang.EventObject eventObject) {
169             triggered = true;
170         }
171 
elementInserted(com.sun.star.ui.ConfigurationEvent configurationEvent)172         public void elementInserted(com.sun.star.ui.ConfigurationEvent configurationEvent) {
173             triggered = true;
174         }
175 
elementRemoved(com.sun.star.ui.ConfigurationEvent configurationEvent)176         public void elementRemoved(com.sun.star.ui.ConfigurationEvent configurationEvent) {
177             triggered = true;
178         }
179 
elementReplaced(com.sun.star.ui.ConfigurationEvent configurationEvent)180         public void elementReplaced(com.sun.star.ui.ConfigurationEvent configurationEvent) {
181             triggered = true;
182         }
183 
fireEvent()184         public void fireEvent() {
185             // remove for real action:
186             triggered = !triggered;
187 /*            try {
188                 XIndexAccess xMenuBarSettings = xUIManager.getSettings(
189                                         "private:resource/menubar/menubar", true);
190 
191             }
192             catch(com.sun.star.container.NoSuchElementException e) {
193                 System.out.println("_XUIConfiguration.XUIConfigurationListenerImpl: Exception.");
194                 e.printStackTrace((java.io.PrintWriter)log);
195             }
196             catch(com.sun.star.lang.IllegalArgumentException e) {
197                 System.out.println("_XUIConfiguration.XUIConfigurationListenerImpl: Exception.");
198                 e.printStackTrace((java.io.PrintWriter)log);
199             }
200             catch(com.sun.star.lang.IllegalAccessException e) {
201                 System.out.println("_XUIConfiguration.XUIConfigurationListenerImpl: Exception.");
202                 e.printStackTrace((java.io.PrintWriter)log);
203             }
204             catch(com.sun.star.lang.IndexOutOfBoundsException e) {
205                 System.out.println("_XUIConfiguration.XUIConfigurationListenerImpl: Exception.");
206                 e.printStackTrace((java.io.PrintWriter)log);
207             }
208             catch(com.sun.star.lang.WrappedTargetException e) {
209                 System.out.println("_XUIConfiguration.XUIConfigurationListenerImpl: Exception.");
210                 e.printStackTrace((java.io.PrintWriter)log);
211             } */
212         }
213 
reset()214         public void reset() {
215             // remove comment for real function
216             //triggered = false;
217         }
218 
219     }
220 
getMSF()221     private XMultiServiceFactory getMSF()
222     {
223         final XMultiServiceFactory xMSF1 = UnoRuntime.queryInterface(XMultiServiceFactory.class, connection.getComponentContext().getServiceManager());
224         return xMSF1;
225     }
226 
227     // setup and close connections
228     @BeforeClass
setUpConnection()229     public static void setUpConnection() throws Exception
230     {
231         System.out.println("setUpConnection()");
232         connection.setUp();
233     }
234 
235     @AfterClass
tearDownConnection()236     public static void tearDownConnection()
237             throws InterruptedException, com.sun.star.uno.Exception
238     {
239         System.out.println("tearDownConnection()");
240         connection.tearDown();
241     }
242     private static final OfficeConnection connection = new OfficeConnection();
243 
244 }
245