1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: _XDispatchProvider.java,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
33 import lib
.MultiMethodTest
;
36 import com
.sun
.star
.frame
.DispatchDescriptor
;
37 import com
.sun
.star
.frame
.FrameSearchFlag
;
38 import com
.sun
.star
.frame
.XDispatch
;
39 import com
.sun
.star
.frame
.XDispatchProvider
;
40 import com
.sun
.star
.lang
.XMultiServiceFactory
;
41 import com
.sun
.star
.uno
.UnoRuntime
;
42 import com
.sun
.star
.util
.URL
;
43 import com
.sun
.star
.util
.XURLTransformer
;
46 * Testing <code>com.sun.star.frame.XDispatchProvider</code>
49 * <li><code> queryDispatch() </code></li>
50 * <li><code> queryDispatches() </code></li>
52 * This test needs the following object relations :
54 * <li> <code>'XDispatchProvider.URL'</code> (of type <code>String</code>):
55 * used to obtain unparsed url of DispatchProvider </li>
57 * Test is <b> NOT </b> multithread compilant. <p>
58 * @see com.sun.star.frame.XDispatchProvider
60 public class _XDispatchProvider
extends MultiMethodTest
{
61 public static XDispatchProvider oObj
= null;
62 private String dispatchUrl
= null ;
65 * Retrieves object relation.
67 public void before() {
68 dispatchUrl
= (String
) tEnv
.getObjRelation("XDispatchProvider.URL") ;
69 if (dispatchUrl
== null) {
70 dispatchUrl
= utils
.getFullTestDocName("index.html");
72 log
.println("Using URL: '" + dispatchUrl
+ "'");
76 * Test calls the method. <p>
77 * Has <b> OK </b> status if the method does not return null.
79 public void _queryDispatch() {
81 String frameName
= "_top";
83 url
.Complete
= dispatchUrl
;
85 XURLTransformer xParser
=(XURLTransformer
)
86 UnoRuntime
.queryInterface(XURLTransformer
.class,
87 ((XMultiServiceFactory
)tParam
.getMSF()).createInstance
88 ("com.sun.star.util.URLTransformer"));
89 // Because it's an in/out parameter we must use an array of
91 URL
[] aParseURL
= new URL
[1];
92 aParseURL
[0] = new URL();
93 aParseURL
[0].Complete
= dispatchUrl
;
94 xParser
.parseStrict(aParseURL
);
96 } catch (com
.sun
.star
.uno
.Exception e
) {
97 log
.println("Couldn't parse URL");
99 XDispatch xDispatch
= oObj
.queryDispatch(url
,
100 frameName
, FrameSearchFlag
.ALL
);
101 tRes
.tested("queryDispatch()", xDispatch
!= null);
105 * Before test calls the method, DispatchDescriptor sequence is defined.<p>
106 * Has <b> OK </b> status if the method does not return null, returned
107 * sequence length is equal to a number of DispatchDescriptors
108 * and returned sequence consists of non-null elements.
110 public void _queryDispatches() {
111 String name1
= "_self";
112 String name2
= "_top";
113 URL url1
= new URL();
114 URL url2
= new URL();
116 url1
.Complete
= dispatchUrl
;
117 url2
.Complete
= dispatchUrl
;
119 log
.println("Parsing URL");
120 XURLTransformer xParser
= (XURLTransformer
)
121 UnoRuntime
.queryInterface(XURLTransformer
.class,
122 ((XMultiServiceFactory
)tParam
.getMSF()).createInstance
123 ("com.sun.star.util.URLTransformer"));
124 // Because it's an in/out parameter we must use an array of
126 URL
[] aParseURL
= new URL
[1];
127 aParseURL
[0] = new URL();
128 aParseURL
[0].Complete
= dispatchUrl
;
129 xParser
.parseStrict(aParseURL
);
132 } catch (com
.sun
.star
.uno
.Exception e
) {
133 log
.println("Couldn't parse URL");
135 DispatchDescriptor descs
[] = new DispatchDescriptor
[] {
136 new DispatchDescriptor(url1
, name1
, FrameSearchFlag
.ALL
),
137 new DispatchDescriptor(url2
, name2
, FrameSearchFlag
.ALL
)
139 XDispatch
[] xDispatches
= oObj
.queryDispatches(descs
);
141 if (xDispatches
== null) {
142 log
.println("queryDispatches() returned null");
143 tRes
.tested("queryDispatches()", false);
147 if (xDispatches
.length
!= descs
.length
) {
148 log
.println("queryDispatches() returned "
150 + " amount of XDispatch instead of "
152 tRes
.tested("queryDispatches()", false);
156 for (int i
= 0; i
< xDispatches
.length
; i
++) {
157 if (xDispatches
[i
] == null) {
158 log
.println("queryDispatches() result contains"
160 tRes
.tested("queryDispatches()", false);
165 tRes
.tested("queryDispatches()", true);