Debian Codegraph @

framework/qa/complex/imageManager/CheckImageManager.java

raw
1 /*
2 * This file is part of the LibreOffice project.
3 *
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 *
8 * This file incorporates work covered by the following license notice:
9 *
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
17 */
18
19 package complex.imageManager;
20
21 import com.sun.star.lang.XComponent;
22 import com.sun.star.lang.XInitialization;
23 import com.sun.star.lang.XMultiServiceFactory;
24 import com.sun.star.lang.XTypeProvider;
25 import com.sun.star.uno.UnoRuntime;
26 import com.sun.star.ui.XImageManager;
27 import com.sun.star.ui.XModuleUIConfigurationManagerSupplier;
28 import com.sun.star.ui.XUIConfiguration;
29 import com.sun.star.ui.XUIConfigurationManager;
30 import com.sun.star.ui.XUIConfigurationPersistence;
31
32
33 // ---------- junit imports -----------------
34 import lib.TestParameters;
35 import org.junit.AfterClass;
36 import org.junit.Before;
37 import org.junit.BeforeClass;
38 import org.junit.Test;
39 import org.openoffice.test.OfficeConnection;
40 import static org.junit.Assert.*;
41
42
43 /**
44 *
45 */
46 public class CheckImageManager {
47 boolean checkUIConfigManager = false;
48 XMultiServiceFactory xMSF = null;
49 /**
50 * The test parameters
51 */
52 private TestParameters param = null;
53
54 @Before public void before()
55 {
56 xMSF = getMSF();
57 param = new TestParameters();
58 param.put("ServiceFactory", xMSF); // some qadevOOo functions need the ServiceFactory
59 }
60
61
62 @Test public void checkImageManagerFromModule()
63 {
64 System.out.println(" **** ImageManager from ModuleUIConfigurationManager *** ");
65 XUIConfigurationManager xManager = null;
66 try {
67 Object o = xMSF.createInstance(
68 "com.sun.star.ui.ModuleUIConfigurationManagerSupplier");
69 XModuleUIConfigurationManagerSupplier xMUICMS =
70 UnoRuntime.queryInterface(XModuleUIConfigurationManagerSupplier.class, o);
71 xManager = xMUICMS.getUIConfigurationManager(
72 "com.sun.star.text.TextDocument");
73 }
74 catch(com.sun.star.uno.Exception e) {
75 fail("Exception. " + e.getMessage());
76 }
77 XImageManager xImageManager = UnoRuntime.queryInterface(XImageManager.class, xManager.getImageManager());
78 performChecks(xImageManager, "ModuleUIConfig");
79 }
80
81 public void checkImageManager() {
82 System.out.println(" **** ImageManager from UIConfigurationManager *** ");
83 XUIConfigurationManager xManager = null;
84 try {
85 xManager = UnoRuntime.queryInterface(XUIConfigurationManager.class, xMSF.createInstance("com.sun.star.comp.framework.UIConfigurationManager"));
86 }
87 catch(com.sun.star.uno.Exception e) {
88 fail("Exception. " + e.getMessage());
89 }
90
91 XImageManager xImageManager = UnoRuntime.queryInterface(XImageManager.class, xManager.getImageManager());
92 performChecks(xImageManager, "UIConfig");
93 }
94
95 private void performChecks(XImageManager xImageManager, String testObjectName) {
96 util.dbg.printInterfaces(xImageManager);
97
98 OXUIConfigurationListenerImpl configListener = new OXUIConfigurationListenerImpl();
99 param.put("XUIConfiguration.XUIConfigurationListenerImpl", configListener);
100
101 XInitialization xInit = UnoRuntime.queryInterface(XInitialization.class, xImageManager);
102 _XInitialization _xInit = new _XInitialization(param, xInit);
103 assertTrue(testObjectName + "::XInitialization.initialize", _xInit._initialize());
104
105 // xImageManager is already there, just write a test ;-)
106 _XImageManager _xImage = new _XImageManager(xImageManager);
107 assertTrue(testObjectName + "::XImageManager.getAllImageNames", _xImage._getAllImageNames());
108 assertTrue(testObjectName + "::XImageManager.getImages", _xImage._getImages());
109 assertTrue(testObjectName + "::XImageManager.hasImage", _xImage._hasImage());
110 assertTrue(testObjectName + "::XImageManager.insertImages", _xImage._insertImages());
111 assertTrue(testObjectName + "::XImageManager.removeImages", _xImage._removeImages());
112 assertTrue(testObjectName + "::XImageManager.replaceImages", _xImage._replaceImages());
113 assertTrue(testObjectName + "::XImageManager.reset", _xImage._reset());
114
115 XTypeProvider xType = UnoRuntime.queryInterface(XTypeProvider.class, xImageManager);
116 _XTypeProvider _xType = new _XTypeProvider(xType);
117 assertTrue(testObjectName + "::XTypeProvider.getImplementationId", _xType._getImplementationId());
118 assertTrue(testObjectName + "::XTypeProvider.getTypes", _xType._getTypes());
119
120 XUIConfiguration xUIConfig = UnoRuntime.queryInterface(XUIConfiguration.class, xImageManager);
121 _XUIConfiguration _xUIConfig = new _XUIConfiguration(param, xUIConfig);
122 _xUIConfig.before();
123 assertTrue(testObjectName + "::XUIConfig.addConfigurationListener", _xUIConfig._addConfigurationListener());
124 assertTrue(testObjectName + "::XUIConfig.removeConfigurationListener", _xUIConfig._removeConfigurationListener());
125
126 XUIConfigurationPersistence xUIConfigPersistence = (XUIConfigurationPersistence)UnoRuntime.queryInterface(XUIConfiguration.class, xImageManager);
127 _XUIConfigurationPersistence _xUIConfigPersistence = new _XUIConfigurationPersistence(param, xUIConfigPersistence);
128 _xUIConfigPersistence.before();
129 assertTrue(testObjectName + "::XUIConfigPersistence.isModified", _xUIConfigPersistence._isModified());
130 assertTrue(testObjectName + "::XUIConfigPersistence.isReadOnly", _xUIConfigPersistence._isReadOnly());
131 assertTrue(testObjectName + "::XUIConfigPersistence.reload", _xUIConfigPersistence._reload());
132 assertTrue(testObjectName + "::XUIConfigPersistence.store", _xUIConfigPersistence._store());
133 assertTrue(testObjectName + "::XUIConfigPersistence.storeToStorage", _xUIConfigPersistence._storeToStorage());
134
135 XComponent xComp = UnoRuntime.queryInterface(XComponent.class, xImageManager);
136 _XComponent _xComp = new _XComponent(param, xComp);
137 _xComp.before();
138 assertTrue(testObjectName + "::XComponent.addEventListener", _xComp._addEventListener());
139 assertTrue(testObjectName + "::XComponent.removeEventListener", _xComp._removeEventListener());
140 assertTrue(testObjectName + "::XComponent.dispose", _xComp._dispose());
141 }
142
143
144 private static class OXUIConfigurationListenerImpl implements _XUIConfiguration.XUIConfigurationListenerImpl {
145 private boolean triggered = false;
146
147 public boolean actionWasTriggered() {
148 return triggered;
149 }
150
151 public void disposing(com.sun.star.lang.EventObject eventObject) {
152 triggered = true;
153 }
154
155 public void elementInserted(com.sun.star.ui.ConfigurationEvent configurationEvent) {
156 triggered = true;
157 }
158
159 public void elementRemoved(com.sun.star.ui.ConfigurationEvent configurationEvent) {
160 triggered = true;
161 }
162
163 public void elementReplaced(com.sun.star.ui.ConfigurationEvent configurationEvent) {
164 triggered = true;
165 }
166
167 public void fireEvent() {
168 // remove for real action:
169 triggered = !triggered;
170 }
171
172 public void reset() {
173 // remove comment for real function
174 //triggered = false;
175 }
176
177 }
178
179 private XMultiServiceFactory getMSF()
180 {
181 return UnoRuntime.queryInterface(XMultiServiceFactory.class, connection.getComponentContext().getServiceManager());
182 }
183
184 // setup and close connections
185 @BeforeClass
186 public static void setUpConnection() throws Exception
187 {
188 System.out.println("setUpConnection()");
189 connection.setUp();
190 }
191
192 @AfterClass
193 public static void tearDownConnection()
194 throws InterruptedException, com.sun.star.uno.Exception
195 {
196 System.out.println("tearDownConnection()");
197 connection.tearDown();
198 }
199 private static final OfficeConnection connection = new OfficeConnection();
200
201 }