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