1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
30 import lib
.MultiMethodTest
;
33 import com
.sun
.star
.frame
.DispatchDescriptor
;
34 import com
.sun
.star
.frame
.FrameSearchFlag
;
35 import com
.sun
.star
.frame
.XDispatch
;
36 import com
.sun
.star
.frame
.XDispatchProvider
;
37 import com
.sun
.star
.lang
.XMultiServiceFactory
;
38 import com
.sun
.star
.uno
.UnoRuntime
;
39 import com
.sun
.star
.util
.URL
;
40 import com
.sun
.star
.util
.XURLTransformer
;
43 * Testing <code>com.sun.star.frame.XDispatchProvider</code>
46 * <li><code> queryDispatch() </code></li>
47 * <li><code> queryDispatches() </code></li>
49 * This test needs the following object relations :
51 * <li> <code>'XDispatchProvider.URL'</code> (of type <code>String</code>):
52 * used to obtain unparsed url of DispatchProvider </li>
54 * Test is <b> NOT </b> multithread compilant. <p>
55 * @see com.sun.star.frame.XDispatchProvider
57 public class _XDispatchProvider
extends MultiMethodTest
{
58 public static XDispatchProvider oObj
= null;
59 private String dispatchUrl
= null ;
62 * Retrieves object relation.
64 public void before() {
65 dispatchUrl
= (String
) tEnv
.getObjRelation("XDispatchProvider.URL") ;
66 if (dispatchUrl
== null) {
67 dispatchUrl
= utils
.getFullTestDocName("index.html");
69 log
.println("Using URL: '" + dispatchUrl
+ "'");
73 * Test calls the method. <p>
74 * Has <b> OK </b> status if the method does not return null.
76 public void _queryDispatch() {
78 String frameName
= "_top";
80 url
.Complete
= dispatchUrl
;
82 XURLTransformer xParser
=(XURLTransformer
)
83 UnoRuntime
.queryInterface(XURLTransformer
.class,
84 ((XMultiServiceFactory
)tParam
.getMSF()).createInstance
85 ("com.sun.star.util.URLTransformer"));
86 // Because it's an in/out parameter we must use an array of
88 URL
[] aParseURL
= new URL
[1];
89 aParseURL
[0] = new URL();
90 aParseURL
[0].Complete
= dispatchUrl
;
91 xParser
.parseStrict(aParseURL
);
93 } catch (com
.sun
.star
.uno
.Exception e
) {
94 log
.println("Couldn't parse URL");
96 XDispatch xDispatch
= oObj
.queryDispatch(url
,
97 frameName
, FrameSearchFlag
.ALL
);
98 tRes
.tested("queryDispatch()", xDispatch
!= null);
102 * Before test calls the method, DispatchDescriptor sequence is defined.<p>
103 * Has <b> OK </b> status if the method does not return null, returned
104 * sequence length is equal to a number of DispatchDescriptors
105 * and returned sequence consists of non-null elements.
107 public void _queryDispatches() {
108 String name1
= "_self";
109 String name2
= "_top";
110 URL url1
= new URL();
111 URL url2
= new URL();
113 url1
.Complete
= dispatchUrl
;
114 url2
.Complete
= dispatchUrl
;
116 log
.println("Parsing URL");
117 XURLTransformer xParser
= (XURLTransformer
)
118 UnoRuntime
.queryInterface(XURLTransformer
.class,
119 ((XMultiServiceFactory
)tParam
.getMSF()).createInstance
120 ("com.sun.star.util.URLTransformer"));
121 // Because it's an in/out parameter we must use an array of
123 URL
[] aParseURL
= new URL
[1];
124 aParseURL
[0] = new URL();
125 aParseURL
[0].Complete
= dispatchUrl
;
126 xParser
.parseStrict(aParseURL
);
129 } catch (com
.sun
.star
.uno
.Exception e
) {
130 log
.println("Couldn't parse URL");
132 DispatchDescriptor descs
[] = new DispatchDescriptor
[] {
133 new DispatchDescriptor(url1
, name1
, FrameSearchFlag
.ALL
),
134 new DispatchDescriptor(url2
, name2
, FrameSearchFlag
.ALL
)
136 XDispatch
[] xDispatches
= oObj
.queryDispatches(descs
);
138 if (xDispatches
== null) {
139 log
.println("queryDispatches() returned null");
140 tRes
.tested("queryDispatches()", false);
144 if (xDispatches
.length
!= descs
.length
) {
145 log
.println("queryDispatches() returned "
147 + " amount of XDispatch instead of "
149 tRes
.tested("queryDispatches()", false);
153 for (int i
= 0; i
< xDispatches
.length
; i
++) {
154 if (xDispatches
[i
] == null) {
155 log
.println("queryDispatches() result contains"
157 tRes
.tested("queryDispatches()", false);
162 tRes
.tested("queryDispatches()", true);