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