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.runtime; 25 26 import java.util.HashMap; 27 import java.util.Iterator; 28 import java.util.Collection; 29 30 import drafts.com.sun.star.script.framework.runtime.XScriptNameResolver; 31 import drafts.com.sun.star.script.framework.storage.XScriptInfo; 32 import drafts.com.sun.star.script.framework.storage.XScriptStorageManager; 33 34 import com.sun.star.lang.XMultiServiceFactory; 35 import com.sun.star.ucb.XSimpleFileAccess; 36 import com.sun.star.beans.XPropertySet; 37 import com.sun.star.uno.XComponentContext; 38 import com.sun.star.uno.UnoRuntime; 39 import com.sun.star.uno.XInterface; 40 41 import lib.MultiMethodTest; 42 import lib.StatusException; 43 import lib.Parameters; 44 45 public class _XScriptNameResolver extends MultiMethodTest { 46 47 public XScriptNameResolver oObj = null; 48 private XScriptStorageManager storageManager = null; 49 50 /** 51 * Retrieves object relation. 52 */ before()53 public void before() throws StatusException { 54 } 55 _resolve()56 public void _resolve() { 57 boolean result = true; 58 59 Collection c = 60 (Collection) tEnv.getObjRelation("_resolve"); 61 62 Iterator tests; 63 64 if (c != null) { 65 tests = c.iterator(); 66 67 while (tests.hasNext()) { 68 result &= runResolveTest((Parameters)tests.next()); 69 } 70 } 71 else { 72 result = false; 73 } 74 75 tRes.tested("resolve()", result); 76 } 77 runResolveTest(Parameters data)78 private boolean runResolveTest(Parameters data) { 79 String description = data.get("description"); 80 String location = data.get("location"); 81 String logicalname = data.get("logicalname"); 82 String expected = data.get("expected"); 83 String output = ""; 84 85 int storageId = getStorageId(location); 86 87 log.println(description + ": " + logicalname); 88 89 HashMap map = new HashMap(); 90 map.put("SCRIPTING_DOC_STORAGE_ID", new Integer(storageId)); 91 map.put("SCRIPTING_DOC_URI", util.utils.getFullTestURL(location)); 92 93 Parameters params = new Parameters(map); 94 Object[] args = new Object[] {params}; 95 96 try { 97 XInterface ifc = (XInterface) oObj.resolve(logicalname, args); 98 99 if (ifc == null) 100 output = "null"; 101 else if (UnoRuntime.queryInterface(XScriptInfo.class, ifc) == null) 102 output = "null"; 103 else 104 output = "XScriptInfo.class"; 105 } 106 catch (com.sun.star.lang.IllegalArgumentException iae) { 107 log.println("caught IllegalArgumentException: " + iae); 108 output = "com.sun.star.lang.IllegalArgumentException"; 109 } 110 catch (com.sun.star.script.CannotConvertException cce) { 111 log.println("caught CannotConvertException: " + cce); 112 output = "com.sun.star.script.CannotConvertException"; 113 } 114 catch (com.sun.star.uno.RuntimeException re) { 115 log.println("caught RuntimeException: " + re); 116 output = "com.sun.star.uno.RuntimeException"; 117 } 118 119 log.println("expected: " + expected + ", output: " + output); 120 if (output.equals(expected)) 121 return true; 122 else 123 return false; 124 } 125 getStorageId(String location)126 private int getStorageId(String location) { 127 128 if (location.equals("share")) 129 return 0; 130 131 if (location.equals("user")) 132 return 1; 133 134 XSimpleFileAccess access = null; 135 String uri = util.utils.getFullTestURL(location); 136 137 if (storageManager == null) { 138 try { 139 XPropertySet xProp = (XPropertySet)UnoRuntime.queryInterface( 140 XPropertySet.class, tParam.getMSF()); 141 142 XComponentContext xContext = (XComponentContext) 143 UnoRuntime.queryInterface(XComponentContext.class, 144 xProp.getPropertyValue("DefaultContext")); 145 146 XInterface ifc = (XInterface) 147 xContext.getValueByName("/singletons/drafts.com.sun.star." + 148 "script.framework.storage.theScriptStorageManager"); 149 150 storageManager = (XScriptStorageManager) 151 UnoRuntime.queryInterface(XScriptStorageManager.class, ifc); 152 } 153 catch( Exception e ) { 154 return -1; 155 } 156 } 157 158 access = getXSimpleFileAccess(); 159 if (access == null) 160 return -1; 161 162 int id = storageManager.createScriptStorageWithURI(access, uri); 163 164 return id; 165 } 166 getXSimpleFileAccess()167 private XSimpleFileAccess getXSimpleFileAccess() { 168 XSimpleFileAccess access = null; 169 170 try { 171 Object fa = tParam.getMSF().createInstance( 172 "com.sun.star.ucb.SimpleFileAccess"); 173 174 access = (XSimpleFileAccess) 175 UnoRuntime.queryInterface(XSimpleFileAccess.class, fa); 176 } 177 catch (com.sun.star.uno.Exception e) { 178 return null; 179 } 180 return access; 181 } 182 } 183