/************************************************************************* * * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * Copyright 2000, 2010 Oracle and/or its affiliates. * * OpenOffice.org - a multi-platform office productivity suite * * This file is part of OpenOffice.org. * * OpenOffice.org is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License version 3 * only, as published by the Free Software Foundation. * * OpenOffice.org is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License version 3 for more details * (a copy is included in the LICENSE file that accompanied this code). * * You should have received a copy of the GNU Lesser General Public License * version 3 along with OpenOffice.org. If not, see * * for a copy of the LGPLv3 License. * ************************************************************************/ package complex.accelerators; // imports import com.sun.star.awt.*; import com.sun.star.beans.*; import com.sun.star.container.*; import com.sun.star.embed.*; import com.sun.star.lang.*; import com.sun.star.ui.*; import com.sun.star.uno.*; import com.sun.star.util.*; import complexlib.ComplexTestCase; import java.lang.*; import java.util.*; import helper.*; //----------------------------------------------- /** @short todo document me */ public class AcceleratorsConfigurationTest extends ComplexTestCase { /** points to the global uno service manager. */ private XMultiServiceFactory m_xSmgr = null; /** the accelerator configuration for testing. */ private XAcceleratorConfiguration m_xGlobalAccelCfg = null; private XAcceleratorConfiguration m_xModuleAccelCfg = null; private XAcceleratorConfiguration m_xDocumentAccelCfg = null; /** XCS/XCU based accelerator configuration. */ private XNameAccess m_xConfig = null; private XNameAccess m_xPrimaryKeys = null; private XNameAccess m_xSecondaryKeys = null; //------------------------------------------- // test environment //----------------------------------------------- /** @short todo document me */ public String[] getTestMethodNames() { return new String[] { "checkGlobalAccelCfg", "checkModuleAccelCfg", "checkDocumentAccelCfg" }; } //----------------------------------------------- /** @short Create the environment for following tests. */ public void before() throws java.lang.Exception { // get uno service manager from global test environment m_xSmgr = (XMultiServiceFactory)param.getMSF(); m_xGlobalAccelCfg = (XAcceleratorConfiguration)UnoRuntime.queryInterface( XAcceleratorConfiguration.class, m_xSmgr.createInstance("com.sun.star.ui.GlobalAcceleratorConfiguration")); m_xModuleAccelCfg = (XAcceleratorConfiguration)UnoRuntime.queryInterface( XAcceleratorConfiguration.class, m_xSmgr.createInstance("com.sun.star.ui.ModuleAcceleratorConfiguration")); m_xDocumentAccelCfg = (XAcceleratorConfiguration)UnoRuntime.queryInterface( XAcceleratorConfiguration.class, m_xSmgr.createInstance("com.sun.star.ui.DocumentAcceleratorConfiguration")); String sConfigPath = "org.openoffice.Office.Accelerators"; boolean bReadOnly = false; XNameAccess m_xConfig = openConfig(m_xSmgr, sConfigPath, bReadOnly); if (m_xConfig != null) { m_xPrimaryKeys = (XNameAccess)UnoRuntime.queryInterface(XNameAccess.class, m_xConfig.getByName("PrimaryKeys")); m_xSecondaryKeys = (XNameAccess)UnoRuntime.queryInterface(XNameAccess.class, m_xConfig.getByName("SecondaryKeys")); } } //------------------------------------------- /** @short close the environment. */ public void after() throws java.lang.Exception { m_xConfig = null; m_xGlobalAccelCfg = null; m_xModuleAccelCfg = null; m_xDocumentAccelCfg = null; m_xSmgr = null; } //------------------------------------------- /** @todo document me. */ public void checkGlobalAccelCfg() throws java.lang.Exception { log.println("\n---- check Global accelerator configuration: ----"); String[] sKeys; XNameAccess xPrimaryAccess = (XNameAccess)UnoRuntime.queryInterface(XNameAccess.class,m_xPrimaryKeys.getByName("Global")); XNameAccess xSecondaryAccess = (XNameAccess)UnoRuntime.queryInterface(XNameAccess.class, m_xSecondaryKeys.getByName("Global")); sKeys = new String[] { "A_MOD1" }; impl_checkGetKeyCommands(m_xGlobalAccelCfg, xPrimaryAccess, sKeys); sKeys = new String[] { "PASTE", "X_SHIFT" }; String[] sCommands = new String[] { ".uno:test", ".uno:test" }; impl_checkSetKeyCommands(m_xGlobalAccelCfg, xPrimaryAccess, xSecondaryAccess, sKeys, sCommands); sKeys = new String[] { "C_MOD1", "CUT" }; impl_checkRemoveKeyCommands(m_xGlobalAccelCfg, xPrimaryAccess, xSecondaryAccess, sKeys); String[] sCommandList = new String[] { ".uno:Paste", ".uno:CloseWin" }; impl_checkGetPreferredKeyEventsForCommandList(m_xGlobalAccelCfg, xPrimaryAccess, sCommandList); } //------------------------------------------- /** @todo document me. */ public void checkModuleAccelCfg() throws java.lang.Exception { String[] sModules = new String[] { "com.sun.star.frame.StartModule", "com.sun.star.drawing.DrawingDocument", "com.sun.star.presentation.PresentationDocument", "com.sun.star.sheet.SpreadsheetDocument", "com.sun.star.text.TextDocument", // add other modules here }; for (int i=0; i0) { log.println("** get command by " + sKeys[i] + " **"); String sCmdFromCache = new String(); // get a value using XAcceleratorConfiguration API String sCmdFromConfiguration = new String(); // get a value using configuration API // GET shortcuts/commands using XAcceleratorConfiguration API sCmdFromCache = xAccelCfg.getCommandByKeyEvent(convertShortcut2AWTKey(sKeys[i])); log.println(sKeys[i] + "-->" + sCmdFromCache + ", by XAcceleratorConfiguration API"); // GET shortcuts/commands using configuration API sCmdFromConfiguration = getCommandFromConfiguration(xAccess, sKeys[i]); log.println(sKeys[i] + "-->" + sCmdFromConfiguration + ", by configuration API"); assure("values are different by XAcceleratorConfiguration API and configuration API!", sCmdFromCache.equals(sCmdFromConfiguration)); String sLocale = "es"; setOfficeLocale(sLocale); sCmdFromConfiguration = getCommandFromConfiguration(xAccess, sKeys[i]); log.println(sKeys[i] + "-->" + sCmdFromConfiguration + ", by configuration API" + " for locale:"+ getOfficeLocale()); sLocale = "en-US"; setOfficeLocale(sLocale); //reset to default locale } else { log.println(sKeys[i] + " doesn't exist!"); } } } //------------------------------------------- /** @todo document me. */ private void impl_checkSetKeyCommands(XAcceleratorConfiguration xAccelCfg, XNameAccess xPrimaryAccess, XNameAccess xSecondaryAccess, String[] sKeys, String[] sCommands) throws java.lang.Exception { log.println("check setKeyCommands..."); for (int i=0; i