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