1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 package ifc.frame; 25 26 import lib.MultiMethodTest; 27 import util.utils; 28 29 import com.sun.star.frame.DispatchDescriptor; 30 import com.sun.star.frame.FrameSearchFlag; 31 import com.sun.star.frame.XDispatch; 32 import com.sun.star.frame.XDispatchProvider; 33 import com.sun.star.lang.XMultiServiceFactory; 34 import com.sun.star.uno.UnoRuntime; 35 import com.sun.star.util.URL; 36 import com.sun.star.util.XURLTransformer; 37 38 /** 39 * Testing <code>com.sun.star.frame.XDispatchProvider</code> 40 * interface methods: 41 * <ul> 42 * <li><code> queryDispatch() </code></li> 43 * <li><code> queryDispatches() </code></li> 44 * </ul><p> 45 * This test needs the following object relations : 46 * <ul> 47 * <li> <code>'XDispatchProvider.URL'</code> (of type <code>String</code>): 48 * used to obtain unparsed url of DispatchProvider </li> 49 * </ul> <p> 50 * Test is <b> NOT </b> multithread compilant. <p> 51 * @see com.sun.star.frame.XDispatchProvider 52 */ 53 public class _XDispatchProvider extends MultiMethodTest { 54 public static XDispatchProvider oObj = null; 55 private String dispatchUrl = null ; 56 57 /** 58 * Retrieves object relation. 59 */ before()60 public void before() { 61 dispatchUrl = (String) tEnv.getObjRelation("XDispatchProvider.URL") ; 62 if (dispatchUrl == null) { 63 dispatchUrl = utils.getFullTestDocName("index.html"); 64 } 65 log.println("Using URL: '" + dispatchUrl + "'"); 66 } 67 68 /** 69 * Test calls the method. <p> 70 * Has <b> OK </b> status if the method does not return null. 71 */ _queryDispatch()72 public void _queryDispatch() { 73 URL url = new URL(); 74 String frameName = "_top"; 75 76 url.Complete = dispatchUrl; 77 try { 78 XURLTransformer xParser=(XURLTransformer) 79 UnoRuntime.queryInterface(XURLTransformer.class, 80 ((XMultiServiceFactory)tParam.getMSF()).createInstance 81 ("com.sun.star.util.URLTransformer")); 82 // Because it's an in/out parameter we must use an array of 83 // URL objects. 84 URL[] aParseURL = new URL[1]; 85 aParseURL[0] = new URL(); 86 aParseURL[0].Complete = dispatchUrl; 87 xParser.parseStrict(aParseURL); 88 url = aParseURL[0]; 89 } catch (com.sun.star.uno.Exception e) { 90 log.println("Couldn't parse URL"); 91 } 92 XDispatch xDispatch = oObj.queryDispatch(url, 93 frameName, FrameSearchFlag.ALL); 94 tRes.tested("queryDispatch()", xDispatch != null); 95 } 96 97 /** 98 * Before test calls the method, DispatchDescriptor sequence is defined.<p> 99 * Has <b> OK </b> status if the method does not return null, returned 100 * sequence length is equal to a number of DispatchDescriptors 101 * and returned sequence consists of non-null elements. 102 */ _queryDispatches()103 public void _queryDispatches() { 104 String name1 = "_self"; 105 String name2 = "_top"; 106 URL url1 = new URL(); 107 URL url2 = new URL(); 108 109 url1.Complete = dispatchUrl; 110 url2.Complete = dispatchUrl; 111 try { 112 log.println("Parsing URL"); 113 XURLTransformer xParser = (XURLTransformer) 114 UnoRuntime.queryInterface(XURLTransformer.class, 115 ((XMultiServiceFactory)tParam.getMSF()).createInstance 116 ("com.sun.star.util.URLTransformer")); 117 // Because it's an in/out parameter we must use an array of 118 // URL objects. 119 URL[] aParseURL = new URL[1]; 120 aParseURL[0] = new URL(); 121 aParseURL[0].Complete = dispatchUrl; 122 xParser.parseStrict(aParseURL); 123 url1 = aParseURL[0]; 124 url2 = aParseURL[0]; 125 } catch (com.sun.star.uno.Exception e) { 126 log.println("Couldn't parse URL"); 127 } 128 DispatchDescriptor descs[] = new DispatchDescriptor[] { 129 new DispatchDescriptor(url1, name1, FrameSearchFlag.ALL), 130 new DispatchDescriptor(url2, name2, FrameSearchFlag.ALL) 131 }; 132 XDispatch[] xDispatches = oObj.queryDispatches(descs); 133 134 if (xDispatches == null) { 135 log.println("queryDispatches() returned null"); 136 tRes.tested("queryDispatches()", false); 137 return; 138 } 139 140 if (xDispatches.length != descs.length) { 141 log.println("queryDispatches() returned " 142 + xDispatches.length 143 + " amount of XDispatch instead of " 144 + descs.length); 145 tRes.tested("queryDispatches()", false); 146 return; 147 } 148 149 for (int i = 0; i < xDispatches.length; i++) { 150 if (xDispatches[i] == null) { 151 log.println("queryDispatches() result contains" 152 + " null object"); 153 tRes.tested("queryDispatches()", false); 154 return; 155 } 156 } 157 158 tRes.tested("queryDispatches()", true); 159 return; 160 } 161 162 } 163 164