1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir package complex.dispatches; 28*cdf0e10cSrcweir 29*cdf0e10cSrcweir import com.sun.star.beans.PropertyValue; 30*cdf0e10cSrcweir import com.sun.star.frame.DispatchInformation; 31*cdf0e10cSrcweir import com.sun.star.frame.XComponentLoader; 32*cdf0e10cSrcweir import com.sun.star.frame.XDispatchInformationProvider; 33*cdf0e10cSrcweir import com.sun.star.frame.XDispatchProviderInterception; 34*cdf0e10cSrcweir import com.sun.star.frame.XDispatchProviderInterceptor; 35*cdf0e10cSrcweir import com.sun.star.frame.XFrame; 36*cdf0e10cSrcweir import com.sun.star.lang.XComponent; 37*cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory; 38*cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime; 39*cdf0e10cSrcweir import com.sun.star.util.XCloseable; 40*cdf0e10cSrcweir import complex.dispatches.Interceptor; 41*cdf0e10cSrcweir import java.util.HashMap; 42*cdf0e10cSrcweir 43*cdf0e10cSrcweir 44*cdf0e10cSrcweir 45*cdf0e10cSrcweir 46*cdf0e10cSrcweir 47*cdf0e10cSrcweir // ---------- junit imports ----------------- 48*cdf0e10cSrcweir import org.junit.After; 49*cdf0e10cSrcweir import org.junit.AfterClass; 50*cdf0e10cSrcweir import org.junit.Before; 51*cdf0e10cSrcweir import org.junit.BeforeClass; 52*cdf0e10cSrcweir import org.junit.Test; 53*cdf0e10cSrcweir import org.openoffice.test.OfficeConnection; 54*cdf0e10cSrcweir import static org.junit.Assert.*; 55*cdf0e10cSrcweir // ------------------------------------------ 56*cdf0e10cSrcweir 57*cdf0e10cSrcweir //----------------------------------------------- 58*cdf0e10cSrcweir /** @short Check the interface XDispatchInformationProvider 59*cdf0e10cSrcweir 60*cdf0e10cSrcweir @descr Because there exists more then one implementation of a dispatch 61*cdf0e10cSrcweir object, we have to test all these implementations ... 62*cdf0e10cSrcweir */ 63*cdf0e10cSrcweir public class checkdispatchapi 64*cdf0e10cSrcweir { 65*cdf0e10cSrcweir //------------------------------------------- 66*cdf0e10cSrcweir // some const 67*cdf0e10cSrcweir 68*cdf0e10cSrcweir //------------------------------------------- 69*cdf0e10cSrcweir // member 70*cdf0e10cSrcweir /** points to the global uno service manager. */ 71*cdf0e10cSrcweir private XMultiServiceFactory m_xMSF = null; 72*cdf0e10cSrcweir private connectivity.tools.HsqlDatabase db; 73*cdf0e10cSrcweir /** can be used to create new test frames. */ 74*cdf0e10cSrcweir private XFrame m_xDesktop = null; 75*cdf0e10cSrcweir /** provides XDispatchInformationProvider interface. */ 76*cdf0e10cSrcweir private XFrame m_xFrame = null; 77*cdf0e10cSrcweir 78*cdf0e10cSrcweir //------------------------------------------- 79*cdf0e10cSrcweir // test environment 80*cdf0e10cSrcweir //------------------------------------------- 81*cdf0e10cSrcweir /** @short A function to tell the framework, 82*cdf0e10cSrcweir which test functions are available. 83*cdf0e10cSrcweir 84*cdf0e10cSrcweir @return All test methods. 85*cdf0e10cSrcweir @todo Think about selection of tests from outside ... 86*cdf0e10cSrcweir */ 87*cdf0e10cSrcweir // public String[] getTestMethodNames() 88*cdf0e10cSrcweir // { 89*cdf0e10cSrcweir // return new String[] 90*cdf0e10cSrcweir // { 91*cdf0e10cSrcweir // "checkDispatchInfoOfWriter", 92*cdf0e10cSrcweir // "checkDispatchInfoOfCalc", 93*cdf0e10cSrcweir // "checkDispatchInfoOfDraw", 94*cdf0e10cSrcweir // "checkDispatchInfoOfImpress", 95*cdf0e10cSrcweir // "checkDispatchInfoOfMath", 96*cdf0e10cSrcweir // "checkDispatchInfoOfChart", 97*cdf0e10cSrcweir // "checkDispatchInfoOfBibliography", 98*cdf0e10cSrcweir // "checkDispatchInfoOfQueryDesign", 99*cdf0e10cSrcweir // "checkDispatchInfoOfTableDesign", 100*cdf0e10cSrcweir // "checkDispatchInfoOfFormGridView", 101*cdf0e10cSrcweir // "checkDispatchInfoOfDataSourceBrowser", 102*cdf0e10cSrcweir // "checkDispatchInfoOfRelationDesign", 103*cdf0e10cSrcweir // "checkDispatchInfoOfBasic", 104*cdf0e10cSrcweir // "checkDispatchInfoOfStartModule", 105*cdf0e10cSrcweir // "checkInterceptorLifeTime", 106*cdf0e10cSrcweir // "checkInterception" 107*cdf0e10cSrcweir // }; 108*cdf0e10cSrcweir // } 109*cdf0e10cSrcweir 110*cdf0e10cSrcweir //------------------------------------------- 111*cdf0e10cSrcweir /** @short Create the environment for following tests. 112*cdf0e10cSrcweir 113*cdf0e10cSrcweir @descr create an empty test frame, where we can load 114*cdf0e10cSrcweir different components inside. 115*cdf0e10cSrcweir */ 116*cdf0e10cSrcweir @Before public void before() 117*cdf0e10cSrcweir { 118*cdf0e10cSrcweir try 119*cdf0e10cSrcweir { 120*cdf0e10cSrcweir // get uno service manager from global test environment 121*cdf0e10cSrcweir m_xMSF = getMSF(); 122*cdf0e10cSrcweir 123*cdf0e10cSrcweir db = new connectivity.tools.HsqlDatabase(m_xMSF); 124*cdf0e10cSrcweir 125*cdf0e10cSrcweir // create desktop 126*cdf0e10cSrcweir m_xDesktop = UnoRuntime.queryInterface(XFrame.class, m_xMSF.createInstance("com.sun.star.frame.Desktop")); 127*cdf0e10cSrcweir 128*cdf0e10cSrcweir m_xFrame = impl_createNewFrame(); 129*cdf0e10cSrcweir } 130*cdf0e10cSrcweir catch (java.lang.Throwable ex) 131*cdf0e10cSrcweir { 132*cdf0e10cSrcweir fail("Cant initialize test environment."); 133*cdf0e10cSrcweir } 134*cdf0e10cSrcweir } 135*cdf0e10cSrcweir 136*cdf0e10cSrcweir //------------------------------------------- 137*cdf0e10cSrcweir /** @short close the environment. 138*cdf0e10cSrcweir */ 139*cdf0e10cSrcweir @After public void after() 140*cdf0e10cSrcweir { 141*cdf0e10cSrcweir db.close(); 142*cdf0e10cSrcweir impl_closeFrame(m_xFrame); 143*cdf0e10cSrcweir m_xFrame = null; 144*cdf0e10cSrcweir } 145*cdf0e10cSrcweir 146*cdf0e10cSrcweir //------------------------------------------- 147*cdf0e10cSrcweir @Test public void checkDispatchInfoOfWriter() 148*cdf0e10cSrcweir { 149*cdf0e10cSrcweir impl_checkDispatchInfoOfXXX("private:factory/swriter"); 150*cdf0e10cSrcweir } 151*cdf0e10cSrcweir 152*cdf0e10cSrcweir //------------------------------------------- 153*cdf0e10cSrcweir @Test public void checkDispatchInfoOfCalc() 154*cdf0e10cSrcweir { 155*cdf0e10cSrcweir impl_checkDispatchInfoOfXXX("private:factory/scalc"); 156*cdf0e10cSrcweir } 157*cdf0e10cSrcweir 158*cdf0e10cSrcweir //------------------------------------------- 159*cdf0e10cSrcweir @Test public void checkDispatchInfoOfDraw() 160*cdf0e10cSrcweir { 161*cdf0e10cSrcweir impl_checkDispatchInfoOfXXX("private:factory/sdraw"); 162*cdf0e10cSrcweir } 163*cdf0e10cSrcweir 164*cdf0e10cSrcweir //------------------------------------------- 165*cdf0e10cSrcweir @Test public void checkDispatchInfoOfImpress() 166*cdf0e10cSrcweir { 167*cdf0e10cSrcweir impl_checkDispatchInfoOfXXX("private:factory/simpress"); 168*cdf0e10cSrcweir } 169*cdf0e10cSrcweir 170*cdf0e10cSrcweir //------------------------------------------- 171*cdf0e10cSrcweir @Test public void checkDispatchInfoOfChart() 172*cdf0e10cSrcweir { 173*cdf0e10cSrcweir impl_checkDispatchInfoOfXXX("private:factory/schart"); 174*cdf0e10cSrcweir } 175*cdf0e10cSrcweir 176*cdf0e10cSrcweir //------------------------------------------- 177*cdf0e10cSrcweir @Test public void checkDispatchInfoOfMath() 178*cdf0e10cSrcweir { 179*cdf0e10cSrcweir impl_checkDispatchInfoOfXXX("private:factory/smath"); 180*cdf0e10cSrcweir } 181*cdf0e10cSrcweir 182*cdf0e10cSrcweir //------------------------------------------- 183*cdf0e10cSrcweir @Test public void checkDispatchInfoOfDataBase() 184*cdf0e10cSrcweir { 185*cdf0e10cSrcweir impl_checkDispatchInfoOfXXX("private:factory/sdatabase"); 186*cdf0e10cSrcweir } 187*cdf0e10cSrcweir 188*cdf0e10cSrcweir //------------------------------------------- 189*cdf0e10cSrcweir @Test public void checkDispatchInfoOfBibliography() 190*cdf0e10cSrcweir { 191*cdf0e10cSrcweir impl_checkDispatchInfoOfXXX(".component:Bibliography/View1"); 192*cdf0e10cSrcweir } 193*cdf0e10cSrcweir 194*cdf0e10cSrcweir //------------------------------------------- 195*cdf0e10cSrcweir @Test public void checkDispatchInfoOfQueryDesign() 196*cdf0e10cSrcweir { 197*cdf0e10cSrcweir callDatabaseDispatch(".component:DB/QueryDesign"); 198*cdf0e10cSrcweir } 199*cdf0e10cSrcweir 200*cdf0e10cSrcweir //------------------------------------------- 201*cdf0e10cSrcweir @Test public void checkDispatchInfoOfTableDesign() 202*cdf0e10cSrcweir { 203*cdf0e10cSrcweir callDatabaseDispatch(".component:DB/TableDesign"); 204*cdf0e10cSrcweir } 205*cdf0e10cSrcweir 206*cdf0e10cSrcweir //------------------------------------------- 207*cdf0e10cSrcweir @Test public void checkDispatchInfoOfFormGridView() 208*cdf0e10cSrcweir { 209*cdf0e10cSrcweir impl_checkDispatchInfoOfXXX(".component:DB/FormGridView"); 210*cdf0e10cSrcweir } 211*cdf0e10cSrcweir 212*cdf0e10cSrcweir //------------------------------------------- 213*cdf0e10cSrcweir @Test public void checkDispatchInfoOfDataSourceBrowser() 214*cdf0e10cSrcweir { 215*cdf0e10cSrcweir impl_checkDispatchInfoOfXXX(".component:DB/DataSourceBrowser"); 216*cdf0e10cSrcweir } 217*cdf0e10cSrcweir 218*cdf0e10cSrcweir //------------------------------------------- 219*cdf0e10cSrcweir @Test public void checkDispatchInfoOfRelationDesign() 220*cdf0e10cSrcweir { 221*cdf0e10cSrcweir callDatabaseDispatch(".component:DB/RelationDesign"); 222*cdf0e10cSrcweir } 223*cdf0e10cSrcweir //------------------------------------------- 224*cdf0e10cSrcweir 225*cdf0e10cSrcweir private void callDatabaseDispatch(String url) 226*cdf0e10cSrcweir { 227*cdf0e10cSrcweir try 228*cdf0e10cSrcweir { 229*cdf0e10cSrcweir final PropertyValue args = new PropertyValue(); 230*cdf0e10cSrcweir args.Name = "ActiveConnection"; 231*cdf0e10cSrcweir args.Value = (Object) db.defaultConnection(); 232*cdf0e10cSrcweir 233*cdf0e10cSrcweir XFrame xFrame = impl_createNewFrame(); 234*cdf0e10cSrcweir 235*cdf0e10cSrcweir impl_loadIntoFrame(xFrame, url, new PropertyValue[] 236*cdf0e10cSrcweir { 237*cdf0e10cSrcweir args 238*cdf0e10cSrcweir }); 239*cdf0e10cSrcweir impl_checkDispatchInfo(xFrame); 240*cdf0e10cSrcweir impl_closeFrame(xFrame); 241*cdf0e10cSrcweir } 242*cdf0e10cSrcweir catch (java.lang.Exception e) 243*cdf0e10cSrcweir { 244*cdf0e10cSrcweir } 245*cdf0e10cSrcweir } 246*cdf0e10cSrcweir 247*cdf0e10cSrcweir //------------------------------------------- 248*cdf0e10cSrcweir @Test public void checkDispatchInfoOfBasic() 249*cdf0e10cSrcweir { 250*cdf0e10cSrcweir Object aComponent = impl_createUNOComponent("com.sun.star.script.BasicIDE"); 251*cdf0e10cSrcweir impl_checkDispatchInfo(aComponent); 252*cdf0e10cSrcweir } 253*cdf0e10cSrcweir 254*cdf0e10cSrcweir //------------------------------------------- 255*cdf0e10cSrcweir @Test public void checkDispatchInfoOfStartModule() 256*cdf0e10cSrcweir { 257*cdf0e10cSrcweir Object aComponent = impl_createUNOComponent("com.sun.star.frame.StartModule"); 258*cdf0e10cSrcweir impl_checkDispatchInfo(aComponent); 259*cdf0e10cSrcweir } 260*cdf0e10cSrcweir 261*cdf0e10cSrcweir //------------------------------------------- 262*cdf0e10cSrcweir public void checkInterceptorLifeTime() 263*cdf0e10cSrcweir { 264*cdf0e10cSrcweir // Note: It's important for the following test, that aInterceptor will be hold alive by the uno reference 265*cdf0e10cSrcweir // xInterceptor. Otherwhise we cant check some internal states of aInterceptor at the end of this method, because 266*cdf0e10cSrcweir // it was already killed .-) 267*cdf0e10cSrcweir 268*cdf0e10cSrcweir Interceptor aInterceptor = new Interceptor(); 269*cdf0e10cSrcweir XDispatchProviderInterceptor xInterceptor = UnoRuntime.queryInterface(XDispatchProviderInterceptor.class, aInterceptor); 270*cdf0e10cSrcweir 271*cdf0e10cSrcweir XFrame xFrame = impl_createNewFrame(); 272*cdf0e10cSrcweir XDispatchProviderInterception xInterception = UnoRuntime.queryInterface(XDispatchProviderInterception.class, xFrame); 273*cdf0e10cSrcweir 274*cdf0e10cSrcweir xInterception.registerDispatchProviderInterceptor(xInterceptor); 275*cdf0e10cSrcweir impl_closeFrame(xFrame); 276*cdf0e10cSrcweir 277*cdf0e10cSrcweir int nRegCount = aInterceptor.getRegistrationCount(); 278*cdf0e10cSrcweir boolean bIsRegistered = aInterceptor.isRegistered(); 279*cdf0e10cSrcweir 280*cdf0e10cSrcweir System.out.println("registration count = " + nRegCount); 281*cdf0e10cSrcweir System.out.println("is registered ? = " + bIsRegistered); 282*cdf0e10cSrcweir 283*cdf0e10cSrcweir if (nRegCount < 1) 284*cdf0e10cSrcweir { 285*cdf0e10cSrcweir fail("Interceptor was never registered."); 286*cdf0e10cSrcweir } 287*cdf0e10cSrcweir 288*cdf0e10cSrcweir if (bIsRegistered) 289*cdf0e10cSrcweir { 290*cdf0e10cSrcweir fail("Interceptor was not deregistered automaticly on closing the corresponding frame."); 291*cdf0e10cSrcweir } 292*cdf0e10cSrcweir 293*cdf0e10cSrcweir System.out.println("Destruction of interception chain works as designed .-)"); 294*cdf0e10cSrcweir } 295*cdf0e10cSrcweir 296*cdf0e10cSrcweir //------------------------------------------- 297*cdf0e10cSrcweir public void checkInterception() 298*cdf0e10cSrcweir { 299*cdf0e10cSrcweir String[] lDisabledURLs = new String[1]; 300*cdf0e10cSrcweir lDisabledURLs[0] = ".uno:Open"; 301*cdf0e10cSrcweir 302*cdf0e10cSrcweir System.out.println("create and initialize interceptor ..."); 303*cdf0e10cSrcweir Interceptor aInterceptor = new Interceptor(); 304*cdf0e10cSrcweir aInterceptor.setURLs4URLs4Blocking(lDisabledURLs); 305*cdf0e10cSrcweir 306*cdf0e10cSrcweir XDispatchProviderInterceptor xInterceptor = UnoRuntime.queryInterface(XDispatchProviderInterceptor.class, aInterceptor); 307*cdf0e10cSrcweir 308*cdf0e10cSrcweir System.out.println("create and initialize frame ..."); 309*cdf0e10cSrcweir XFrame xFrame = impl_createNewFrame(); 310*cdf0e10cSrcweir impl_loadIntoFrame(xFrame, "private:factory/swriter", null); 311*cdf0e10cSrcweir 312*cdf0e10cSrcweir XDispatchProviderInterception xInterception = UnoRuntime.queryInterface(XDispatchProviderInterception.class, xFrame); 313*cdf0e10cSrcweir 314*cdf0e10cSrcweir System.out.println("register interceptor ..."); 315*cdf0e10cSrcweir xInterception.registerDispatchProviderInterceptor(xInterceptor); 316*cdf0e10cSrcweir 317*cdf0e10cSrcweir System.out.println("deregister interceptor ..."); 318*cdf0e10cSrcweir xInterception.releaseDispatchProviderInterceptor(xInterceptor); 319*cdf0e10cSrcweir } 320*cdf0e10cSrcweir 321*cdf0e10cSrcweir //------------------------------------------- 322*cdf0e10cSrcweir private void impl_checkDispatchInfoOfXXX(String sXXX) 323*cdf0e10cSrcweir { 324*cdf0e10cSrcweir XFrame xFrame = impl_createNewFrame(); 325*cdf0e10cSrcweir impl_loadIntoFrame(xFrame, sXXX, null); 326*cdf0e10cSrcweir impl_checkDispatchInfo(xFrame); 327*cdf0e10cSrcweir impl_closeFrame(xFrame); 328*cdf0e10cSrcweir } 329*cdf0e10cSrcweir 330*cdf0e10cSrcweir //------------------------------------------- 331*cdf0e10cSrcweir /** @short load an URL into the current test frame. 332*cdf0e10cSrcweir */ 333*cdf0e10cSrcweir private void impl_loadIntoFrame(XFrame xFrame, String sURL, PropertyValue args[]) 334*cdf0e10cSrcweir { 335*cdf0e10cSrcweir XComponentLoader xLoader = UnoRuntime.queryInterface(XComponentLoader.class, xFrame); 336*cdf0e10cSrcweir if (xLoader == null) 337*cdf0e10cSrcweir { 338*cdf0e10cSrcweir fail("Frame does not provide required interface XComponentLoader."); 339*cdf0e10cSrcweir } 340*cdf0e10cSrcweir 341*cdf0e10cSrcweir XComponent xDoc = null; 342*cdf0e10cSrcweir try 343*cdf0e10cSrcweir { 344*cdf0e10cSrcweir xDoc = xLoader.loadComponentFromURL(sURL, "_self", 0, args); 345*cdf0e10cSrcweir } 346*cdf0e10cSrcweir catch (java.lang.Throwable ex) 347*cdf0e10cSrcweir { 348*cdf0e10cSrcweir xDoc = null; 349*cdf0e10cSrcweir } 350*cdf0e10cSrcweir 351*cdf0e10cSrcweir if (xDoc == null) 352*cdf0e10cSrcweir { 353*cdf0e10cSrcweir fail("Could not load \"" + sURL + "\"."); 354*cdf0e10cSrcweir } 355*cdf0e10cSrcweir } 356*cdf0e10cSrcweir 357*cdf0e10cSrcweir //------------------------------------------- 358*cdf0e10cSrcweir /** @short create an uno implementation directly. 359*cdf0e10cSrcweir */ 360*cdf0e10cSrcweir private Object impl_createUNOComponent(String sName) 361*cdf0e10cSrcweir { 362*cdf0e10cSrcweir Object aComponent = null; 363*cdf0e10cSrcweir try 364*cdf0e10cSrcweir { 365*cdf0e10cSrcweir aComponent = m_xMSF.createInstance(sName); 366*cdf0e10cSrcweir } 367*cdf0e10cSrcweir catch (java.lang.Throwable ex) 368*cdf0e10cSrcweir { 369*cdf0e10cSrcweir aComponent = null; 370*cdf0e10cSrcweir } 371*cdf0e10cSrcweir 372*cdf0e10cSrcweir if (aComponent == null) 373*cdf0e10cSrcweir { 374*cdf0e10cSrcweir fail("Could not create UNO component \"" + sName + "\"."); 375*cdf0e10cSrcweir } 376*cdf0e10cSrcweir return aComponent; 377*cdf0e10cSrcweir } 378*cdf0e10cSrcweir 379*cdf0e10cSrcweir //------------------------------------------- 380*cdf0e10cSrcweir /** @short check the interface XDispatchInformationProvider 381*cdf0e10cSrcweir at the specified component. 382*cdf0e10cSrcweir */ 383*cdf0e10cSrcweir private void impl_checkDispatchInfo(Object aComponent) 384*cdf0e10cSrcweir { 385*cdf0e10cSrcweir XDispatchInformationProvider xInfoProvider = UnoRuntime.queryInterface(XDispatchInformationProvider.class, aComponent); 386*cdf0e10cSrcweir if (xInfoProvider == null) 387*cdf0e10cSrcweir { 388*cdf0e10cSrcweir // Warning 389*cdf0e10cSrcweir System.out.println("Warning:\tComponent does not provide the [optional!] interface XDispatchInformationProvider."); 390*cdf0e10cSrcweir return; 391*cdf0e10cSrcweir } 392*cdf0e10cSrcweir 393*cdf0e10cSrcweir try 394*cdf0e10cSrcweir { 395*cdf0e10cSrcweir short[] lGroups = xInfoProvider.getSupportedCommandGroups(); 396*cdf0e10cSrcweir int c1 = lGroups.length; 397*cdf0e10cSrcweir int i1 = 0; 398*cdf0e10cSrcweir for (i1 = 0; i1 < c1; ++i1) 399*cdf0e10cSrcweir { 400*cdf0e10cSrcweir short nGroup = lGroups[i1]; 401*cdf0e10cSrcweir DispatchInformation[] lInfos = xInfoProvider.getConfigurableDispatchInformation(nGroup); 402*cdf0e10cSrcweir int c2 = lInfos.length; 403*cdf0e10cSrcweir int i2 = 0; 404*cdf0e10cSrcweir 405*cdf0e10cSrcweir // check for empty lists 406*cdf0e10cSrcweir // Warning 407*cdf0e10cSrcweir if (lInfos.length < 1) 408*cdf0e10cSrcweir { 409*cdf0e10cSrcweir System.out.println("Warning:\tCould not get any DispatchInformation for group [" + nGroup + "]."); 410*cdf0e10cSrcweir } 411*cdf0e10cSrcweir 412*cdf0e10cSrcweir // check for duplicates (and by the way, if the info item match the requested group) 413*cdf0e10cSrcweir HashMap aCheckMap = new HashMap(c2); 414*cdf0e10cSrcweir for (i2 = 0; i2 < c2; ++i2) 415*cdf0e10cSrcweir { 416*cdf0e10cSrcweir DispatchInformation aInfo = lInfos[i2]; 417*cdf0e10cSrcweir if (aInfo.GroupId != nGroup) 418*cdf0e10cSrcweir { 419*cdf0e10cSrcweir // Error 420*cdf0e10cSrcweir fail("At least one DispatchInformation item does not match the requested group.\n\trequested group=[" + nGroup 421*cdf0e10cSrcweir + "] returned groupd=[" + aInfo.GroupId + "] command=\"" + aInfo.Command + "\""); // true => dont break this test 422*cdf0e10cSrcweir continue; 423*cdf0e10cSrcweir } 424*cdf0e10cSrcweir 425*cdf0e10cSrcweir if (aCheckMap.containsKey(aInfo.Command)) 426*cdf0e10cSrcweir { 427*cdf0e10cSrcweir // Error 428*cdf0e10cSrcweir fail("Found a duplicate item: group=[" + aInfo.GroupId + "] command=\"" + aInfo.Command + "\""); // true => dont break this test 429*cdf0e10cSrcweir continue; 430*cdf0e10cSrcweir } 431*cdf0e10cSrcweir 432*cdf0e10cSrcweir aCheckMap.put(aInfo.Command, aInfo.Command); 433*cdf0e10cSrcweir System.out.println("\t[" + aInfo.GroupId + "] \"" + aInfo.Command + "\""); 434*cdf0e10cSrcweir } 435*cdf0e10cSrcweir } 436*cdf0e10cSrcweir } 437*cdf0e10cSrcweir catch (java.lang.Throwable ex) 438*cdf0e10cSrcweir { 439*cdf0e10cSrcweir fail("Exception caught during using XDispatchInformationProvider."); 440*cdf0e10cSrcweir // ex.printStackTrace(); 441*cdf0e10cSrcweir } 442*cdf0e10cSrcweir } 443*cdf0e10cSrcweir 444*cdf0e10cSrcweir //------------------------------------------- 445*cdf0e10cSrcweir private synchronized XFrame impl_createNewFrame() 446*cdf0e10cSrcweir { 447*cdf0e10cSrcweir XFrame xFrame = null; 448*cdf0e10cSrcweir 449*cdf0e10cSrcweir try 450*cdf0e10cSrcweir { 451*cdf0e10cSrcweir xFrame = m_xDesktop.findFrame("_blank", 0); 452*cdf0e10cSrcweir xFrame.getContainerWindow().setVisible(true); 453*cdf0e10cSrcweir } 454*cdf0e10cSrcweir catch (java.lang.Throwable ex) 455*cdf0e10cSrcweir { 456*cdf0e10cSrcweir fail("Could not create the frame instance."); 457*cdf0e10cSrcweir } 458*cdf0e10cSrcweir 459*cdf0e10cSrcweir return xFrame; 460*cdf0e10cSrcweir } 461*cdf0e10cSrcweir 462*cdf0e10cSrcweir //------------------------------------------- 463*cdf0e10cSrcweir private synchronized void impl_closeFrame(XFrame xFrame) 464*cdf0e10cSrcweir { 465*cdf0e10cSrcweir XCloseable xClose = UnoRuntime.queryInterface(XCloseable.class, xFrame); 466*cdf0e10cSrcweir try 467*cdf0e10cSrcweir { 468*cdf0e10cSrcweir xClose.close(false); 469*cdf0e10cSrcweir } 470*cdf0e10cSrcweir catch (com.sun.star.util.CloseVetoException exVeto) 471*cdf0e10cSrcweir { 472*cdf0e10cSrcweir fail("Test frame couldn't be closed successfully."); 473*cdf0e10cSrcweir } 474*cdf0e10cSrcweir } 475*cdf0e10cSrcweir 476*cdf0e10cSrcweir private XMultiServiceFactory getMSF() 477*cdf0e10cSrcweir { 478*cdf0e10cSrcweir final XMultiServiceFactory xMSF1 = UnoRuntime.queryInterface(XMultiServiceFactory.class, connection.getComponentContext().getServiceManager()); 479*cdf0e10cSrcweir return xMSF1; 480*cdf0e10cSrcweir } 481*cdf0e10cSrcweir 482*cdf0e10cSrcweir // setup and close connections 483*cdf0e10cSrcweir @BeforeClass 484*cdf0e10cSrcweir public static void setUpConnection() throws Exception 485*cdf0e10cSrcweir { 486*cdf0e10cSrcweir System.out.println("setUpConnection()"); 487*cdf0e10cSrcweir connection.setUp(); 488*cdf0e10cSrcweir } 489*cdf0e10cSrcweir 490*cdf0e10cSrcweir @AfterClass 491*cdf0e10cSrcweir public static void tearDownConnection() 492*cdf0e10cSrcweir throws InterruptedException, com.sun.star.uno.Exception 493*cdf0e10cSrcweir { 494*cdf0e10cSrcweir System.out.println("tearDownConnection()"); 495*cdf0e10cSrcweir connection.tearDown(); 496*cdf0e10cSrcweir } 497*cdf0e10cSrcweir private static final OfficeConnection connection = new OfficeConnection(); 498*cdf0e10cSrcweir } 499