2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 import lib
.MultiMethodTest
;
24 import com
.sun
.star
.frame
.DispatchDescriptor
;
25 import com
.sun
.star
.frame
.FrameSearchFlag
;
26 import com
.sun
.star
.frame
.XDispatch
;
27 import com
.sun
.star
.frame
.XDispatchProvider
;
28 import com
.sun
.star
.uno
.UnoRuntime
;
29 import com
.sun
.star
.util
.URL
;
30 import com
.sun
.star
.util
.XURLTransformer
;
33 * Testing <code>com.sun.star.frame.XDispatchProvider</code>
36 * <li><code> queryDispatch() </code></li>
37 * <li><code> queryDispatches() </code></li>
39 * This test needs the following object relations :
41 * <li> <code>'XDispatchProvider.URL'</code> (of type <code>String</code>):
42 * used to obtain unparsed url of DispatchProvider </li>
44 * Test is <b> NOT </b> multithread compliant. <p>
45 * @see com.sun.star.frame.XDispatchProvider
47 public class _XDispatchProvider
extends MultiMethodTest
{
48 public static XDispatchProvider oObj
= null;
49 private String dispatchUrl
= null ;
52 * Retrieves object relation.
55 public void before() {
56 dispatchUrl
= (String
) tEnv
.getObjRelation("XDispatchProvider.URL") ;
57 if (dispatchUrl
== null) {
58 dispatchUrl
= utils
.getFullTestDocName("index.html");
60 log
.println("Using URL: '" + dispatchUrl
+ "'");
64 * Test calls the method. <p>
65 * Has <b> OK </b> status if the method does not return null.
67 public void _queryDispatch() {
69 String frameName
= "_top";
71 url
.Complete
= dispatchUrl
;
73 XURLTransformer xParser
=UnoRuntime
.queryInterface(XURLTransformer
.class,
74 tParam
.getMSF().createInstance
75 ("com.sun.star.util.URLTransformer"));
76 // Because it's an in/out parameter we must use an array of
78 URL
[] aParseURL
= new URL
[1];
79 aParseURL
[0] = new URL();
80 aParseURL
[0].Complete
= dispatchUrl
;
81 xParser
.parseStrict(aParseURL
);
83 } catch (com
.sun
.star
.uno
.Exception e
) {
84 log
.println("Couldn't parse URL");
86 XDispatch xDispatch
= oObj
.queryDispatch(url
,
87 frameName
, FrameSearchFlag
.ALL
);
88 tRes
.tested("queryDispatch()", xDispatch
!= null);
92 * Before test calls the method, DispatchDescriptor sequence is defined.<p>
93 * Has <b> OK </b> status if the method does not return null, returned
94 * sequence length is equal to a number of DispatchDescriptors
95 * and returned sequence consists of non-null elements.
97 public void _queryDispatches() {
98 String name1
= "_self";
99 String name2
= "_top";
100 URL url1
= new URL();
101 URL url2
= new URL();
103 url1
.Complete
= dispatchUrl
;
104 url2
.Complete
= dispatchUrl
;
106 log
.println("Parsing URL");
107 XURLTransformer xParser
= UnoRuntime
.queryInterface(XURLTransformer
.class,
108 tParam
.getMSF().createInstance
109 ("com.sun.star.util.URLTransformer"));
110 // Because it's an in/out parameter we must use an array of
112 URL
[] aParseURL
= new URL
[1];
113 aParseURL
[0] = new URL();
114 aParseURL
[0].Complete
= dispatchUrl
;
115 xParser
.parseStrict(aParseURL
);
118 } catch (com
.sun
.star
.uno
.Exception e
) {
119 log
.println("Couldn't parse URL");
121 DispatchDescriptor descs
[] = new DispatchDescriptor
[] {
122 new DispatchDescriptor(url1
, name1
, FrameSearchFlag
.ALL
),
123 new DispatchDescriptor(url2
, name2
, FrameSearchFlag
.ALL
)
125 XDispatch
[] xDispatches
= oObj
.queryDispatches(descs
);
127 if (xDispatches
== null) {
128 log
.println("queryDispatches() returned null");
129 tRes
.tested("queryDispatches()", false);
133 if (xDispatches
.length
!= descs
.length
) {
134 log
.println("queryDispatches() returned "
136 + " amount of XDispatch instead of "
138 tRes
.tested("queryDispatches()", false);
142 for (int i
= 0; i
< xDispatches
.length
; i
++) {
143 if (xDispatches
[i
] == null) {
144 log
.println("queryDispatches() result contains"
146 tRes
.tested("queryDispatches()", false);
151 tRes
.tested("queryDispatches()", true);