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.script.framework.storage; 25 26 import ifc.script.framework.ScriptingUtils; 27 28 import drafts.com.sun.star.script.framework.storage.XScriptInfoAccess; 29 import drafts.com.sun.star.script.framework.storage.XScriptInfo; 30 31 import com.sun.star.uno.UnoRuntime; 32 import com.sun.star.lang.XMultiServiceFactory; 33 import com.sun.star.uno.XInterface; 34 import com.sun.star.ucb.XSimpleFileAccess; 35 import com.sun.star.uno.Exception; 36 import com.sun.star.beans.XPropertySet; 37 38 import java.io.PrintWriter; 39 import lib.MultiMethodTest; 40 import lib.StatusException; 41 import lib.Parameters; 42 43 import java.util.Collection; 44 import java.util.Iterator; 45 46 public class _XScriptInfoAccess extends MultiMethodTest { 47 48 public XScriptInfoAccess oObj = null; 49 50 /** 51 * Retrieves object relation. 52 */ before()53 public void before() throws StatusException { 54 } 55 _getScriptLogicalNames()56 public void _getScriptLogicalNames() { 57 boolean result = true; 58 59 Collection c = 60 (Collection) tEnv.getObjRelation("_getScriptLogicalNames"); 61 62 Iterator tests; 63 64 if (c != null) { 65 tests = c.iterator(); 66 67 while (tests.hasNext()) { 68 result &= runGetScriptLogicalNamesTest((Parameters)tests.next()); 69 } 70 } 71 else { 72 result = false; 73 } 74 75 tRes.tested("getScriptLogicalNames()", result); 76 } 77 runGetScriptLogicalNamesTest(Parameters testdata)78 private boolean runGetScriptLogicalNamesTest(Parameters testdata) { 79 String description = testdata.get("description"); 80 String expected = testdata.get("expected"); 81 String output = ""; 82 83 log.println(testdata.get("description")); 84 85 // try { 86 log.println("In _XScriptInfoAccess.getScriptLogicalNames()"); 87 String[] logicalNames = oObj.getScriptLogicalNames(); 88 89 if (logicalNames == null) 90 output = "null"; 91 else if (logicalNames.length == 0) 92 output = "empty"; 93 else { 94 for (int i = 0; i < logicalNames.length; i++) { 95 if (logicalNames[i].equals(expected)) { 96 output = logicalNames[i]; 97 break; 98 } 99 } 100 } 101 // } 102 // catch (com.sun.star.uno.Exception e) { 103 // log.println("Caught UNO Exception :" + e); 104 // output = "com.sun.star.uno.Exception"; 105 // } 106 107 log.println("expected: " + expected + ", output: " + output); 108 if (output.equals(expected)) 109 return true; 110 else 111 return false; 112 } 113 _getImplementations()114 public void _getImplementations() { 115 boolean result = true; 116 117 Collection c = 118 (Collection) tEnv.getObjRelation("_getImplementations"); 119 120 Iterator tests; 121 122 if (c != null) { 123 tests = c.iterator(); 124 125 while (tests.hasNext()) { 126 result &= runGetImplementationsTest((Parameters)tests.next()); 127 } 128 } 129 else { 130 result = false; 131 } 132 133 tRes.tested("getImplementations()", result); 134 } 135 runGetImplementationsTest(Parameters testdata)136 private boolean runGetImplementationsTest(Parameters testdata) { 137 String description = testdata.get("description"); 138 String logicalname = testdata.get("logicalname"); 139 String expected = testdata.get("expected"); 140 String output = ""; 141 142 log.println(testdata.get("description")); 143 144 // performs a basic check to see if 1 match (XScriptInfo) is returned 145 // the XScriptInfo object is tested more completely in _XScriptInfo 146 // which is drive from ScriptInfo 147 148 try { 149 XScriptInfo[] impls = oObj.getImplementations(logicalname); 150 151 // should only be one match 152 if (impls == null) 153 output = "null"; 154 else if (impls.length == 0) 155 output = "empty"; 156 else 157 output = impls[0].getLogicalName(); 158 } 159 catch (com.sun.star.uno.Exception e) { 160 log.println("Caught UNO Exception:" + e); 161 output = "com.sun.star.uno.Exception"; 162 } 163 164 log.println("expected: " + expected + ", output: " + output); 165 if (output.equals(expected)) 166 return true; 167 else 168 return false; 169 } 170 _getAllImplementations()171 public void _getAllImplementations() { 172 boolean result = true; 173 174 Collection c = 175 (Collection) tEnv.getObjRelation("_getAllImplementations"); 176 177 Iterator tests; 178 179 if (c != null) { 180 tests = c.iterator(); 181 182 while (tests.hasNext()) { 183 result &= runGetAllImplementationsTest((Parameters)tests.next()); 184 } 185 } 186 else { 187 result = false; 188 } 189 190 tRes.tested("getAllImplementations()", result); 191 } 192 runGetAllImplementationsTest(Parameters testdata)193 private boolean runGetAllImplementationsTest(Parameters testdata) { 194 String description = testdata.get("description"); 195 String location = testdata.get("location"); 196 String expected = testdata.get("expected"); 197 String output = ""; 198 199 log.println(testdata.get("description")); 200 201 Object obj = ScriptingUtils.getDefault().getScriptStorage( 202 tParam.getMSF(), location); 203 204 XScriptInfoAccess access = (XScriptInfoAccess) 205 UnoRuntime.queryInterface(XScriptInfoAccess.class, obj); 206 207 XScriptInfo[] impls = access.getAllImplementations(); 208 209 if (impls == null || impls.length == 0) { 210 output = "empty"; 211 } 212 else { 213 for (int i = 0; i < impls.length - 1; i++) 214 output += impls[i].getLogicalName() + ","; 215 output += impls[impls.length - 1].getLogicalName(); 216 } 217 218 log.println("expected: " + expected + ", output: " + output); 219 if (output.equals(expected)) 220 return true; 221 else 222 return false; 223 } 224 } 225