Bump version to 4.1-6
[LibreOffice.git] / framework / qa / complex / imageManager / CheckImageManager.java
blob40f194c69e52a7c06a0229c283a05fa80ebbaa27
1 /*
2 * This file is part of the LibreOffice project.
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/.
8 * This file incorporates work covered by the following license notice:
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 .
19 package complex.imageManager;
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;
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 // ------------------------------------------
43 /**
46 public class CheckImageManager {
47 boolean checkUIConfigManager = false;
48 XMultiServiceFactory xMSF = null;
49 /**
50 * The test parameters
52 private static TestParameters param = null;
54 @Before public void before()
56 xMSF = getMSF();
57 param = new TestParameters();
58 param.put("ServiceFactory", xMSF); // some qadevOOo functions need the ServiceFactory
62 @Test public void checkImageManagerFromModule()
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");
74 catch(com.sun.star.uno.Exception e) {
75 fail("Exception. " + e.getMessage());
77 XImageManager xImageManager = UnoRuntime.queryInterface(XImageManager.class, xManager.getImageManager());
78 performChecks(xImageManager, "ModuleUIConfig", xManager);
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"));
87 catch(com.sun.star.uno.Exception e) {
88 fail("Exception. " + e.getMessage());
91 XImageManager xImageManager = UnoRuntime.queryInterface(XImageManager.class, xManager.getImageManager());
92 performChecks(xImageManager, "UIConfig", xManager);
95 private void performChecks(XImageManager xImageManager, String testObjectName, XUIConfigurationManager xManager) {
96 util.dbg.printInterfaces(xImageManager);
98 OXUIConfigurationListenerImpl configListener = new OXUIConfigurationListenerImpl();
99 param.put("XUIConfiguration.XUIConfigurationListenerImpl", configListener);
101 XInitialization xInit = UnoRuntime.queryInterface(XInitialization.class, xImageManager);
102 _XInitialization _xInit = new _XInitialization(param, xInit);
103 assertTrue(testObjectName + "::XInitialization.initialize", _xInit._initialize());
105 // xImageManager is already there, just write a test ;-)
106 _XImageManager _xImage = new _XImageManager(param, 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());
115 XTypeProvider xType = UnoRuntime.queryInterface(XTypeProvider.class, xImageManager);
116 _XTypeProvider _xType = new _XTypeProvider(param, xType);
117 assertTrue(testObjectName + "::XTypeProvider.getImplementationId", _xType._getImplementationId());
118 assertTrue(testObjectName + "::XTypeProvider.getTypes", _xType._getTypes());
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());
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 // System.out.println(testObjectName + "::XUIConfigPersistence.isReadOnly "+ _xUIConfigPersistence._isReadOnly());
131 assertTrue(testObjectName + "::XUIConfigPersistence.isReadOnly", _xUIConfigPersistence._isReadOnly());
132 assertTrue(testObjectName + "::XUIConfigPersistence.reload", _xUIConfigPersistence._reload());
133 assertTrue(testObjectName + "::XUIConfigPersistence.store", _xUIConfigPersistence._store());
134 assertTrue(testObjectName + "::XUIConfigPersistence.storeToStorage", _xUIConfigPersistence._storeToStorage());
136 XComponent xComp = UnoRuntime.queryInterface(XComponent.class, xImageManager);
137 _XComponent _xComp = new _XComponent(param, xComp);
138 _xComp.before();
139 assertTrue(testObjectName + "::XComponent.addEventListener", _xComp._addEventListener());
140 assertTrue(testObjectName + "::XComponent.removeEventListener", _xComp._removeEventListener());
141 assertTrue(testObjectName + "::XComponent.dispose", _xComp._dispose());
145 class OXUIConfigurationListenerImpl implements _XUIConfiguration.XUIConfigurationListenerImpl {
146 private boolean triggered = false;
148 public boolean actionWasTriggered() {
149 return triggered;
152 public void disposing(com.sun.star.lang.EventObject eventObject) {
153 triggered = true;
156 public void elementInserted(com.sun.star.ui.ConfigurationEvent configurationEvent) {
157 triggered = true;
160 public void elementRemoved(com.sun.star.ui.ConfigurationEvent configurationEvent) {
161 triggered = true;
164 public void elementReplaced(com.sun.star.ui.ConfigurationEvent configurationEvent) {
165 triggered = true;
168 public void fireEvent() {
169 // remove for real action:
170 triggered = !triggered;
173 public void reset() {
174 // remove comment for real function
175 //triggered = false;
180 private XMultiServiceFactory getMSF()
182 final XMultiServiceFactory xMSF1 = UnoRuntime.queryInterface(XMultiServiceFactory.class, connection.getComponentContext().getServiceManager());
183 return xMSF1;
186 // setup and close connections
187 @BeforeClass
188 public static void setUpConnection() throws Exception
190 System.out.println("setUpConnection()");
191 connection.setUp();
194 @AfterClass
195 public static void tearDownConnection()
196 throws InterruptedException, com.sun.star.uno.Exception
198 System.out.println("tearDownConnection()");
199 connection.tearDown();
201 private static final OfficeConnection connection = new OfficeConnection();