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 drafts.com.sun.star.script.framework.storage.XScriptStorageManager; 27 import drafts.com.sun.star.script.framework.storage.XScriptInfoAccess; 28 29 import java.util.Iterator; 30 import java.util.Collection; 31 32 import com.sun.star.uno.UnoRuntime; 33 import com.sun.star.lang.XMultiServiceFactory; 34 import com.sun.star.uno.XInterface; 35 import com.sun.star.ucb.XSimpleFileAccess; 36 import com.sun.star.uno.Exception; 37 38 import java.io.PrintWriter; 39 import lib.MultiMethodTest; 40 import lib.StatusException; 41 import lib.Parameters; 42 43 public class _XScriptStorageManager extends MultiMethodTest { 44 45 public XScriptStorageManager oObj = null; 46 47 /** 48 * Retrieves object relation. 49 */ before()50 public void before() throws StatusException { 51 } 52 _createScriptStorage()53 public void _createScriptStorage() { 54 boolean result = true; 55 56 Collection c = 57 (Collection) tEnv.getObjRelation("_createScriptStorage"); 58 59 if (c == null) { 60 tRes.tested("createScriptStorage()", false); 61 return; 62 } 63 64 Iterator tests = c.iterator(); 65 66 while (tests.hasNext()) { 67 Parameters testdata = (Parameters)tests.next(); 68 String expected = testdata.get("expected"); 69 String output = ""; 70 71 log.println(testdata.get("description")); 72 73 XSimpleFileAccess access = getXSimpleFileAccess(); 74 75 if (access == null) { 76 output = "Couldn't create XSimpleFileAccess"; 77 } 78 else { 79 try { 80 int id = oObj.createScriptStorage(access); 81 output = "success"; 82 } 83 catch (com.sun.star.uno.RuntimeException re) { 84 log.println("Exception from createScriptStorage: " + re); 85 output = "com.sun.star.uno.RuntimeException"; 86 } 87 } 88 log.println("expected: " + expected + ", output: " + output); 89 result &= output.equals(expected); 90 } 91 tRes.tested("createScriptStorage()", result); 92 } 93 _createScriptStorageWithURI()94 public void _createScriptStorageWithURI() { 95 boolean result = true; 96 97 Collection c = 98 (Collection) tEnv.getObjRelation("_createScriptStorageWithURI"); 99 100 if (c == null) { 101 tRes.tested("createScriptStorageWithURI()", false); 102 return; 103 } 104 105 Iterator tests = c.iterator(); 106 107 while (tests.hasNext()) { 108 Parameters testdata = (Parameters)tests.next(); 109 String expected = testdata.get("expected"); 110 String location = testdata.get("location"); 111 String output = ""; 112 113 log.println(testdata.get("description")); 114 115 String uri = util.utils.getFullTestURL(location); 116 XSimpleFileAccess access = getXSimpleFileAccess(); 117 118 try { 119 int id = oObj.createScriptStorageWithURI(access, uri); 120 121 XInterface ifc = (XInterface)oObj.getScriptStorage(id); 122 123 if (ifc == null) 124 output = "null"; 125 else { 126 Object info = UnoRuntime.queryInterface( 127 XScriptInfoAccess.class, ifc); 128 129 if (info == null) 130 output = "null"; 131 else 132 output = "XScriptInfoAccess.class"; 133 } 134 } 135 catch (com.sun.star.uno.RuntimeException re) { 136 log.println("Caught RuntimeException: " + re); 137 output = "com.sun.star.uno.RuntimeException"; 138 } 139 log.println("expected: " + expected + ", output: " + output); 140 result &= output.equals(expected); 141 } 142 143 tRes.tested("createScriptStorageWithURI()", result); 144 } 145 _getScriptStorage()146 public void _getScriptStorage() { 147 boolean result = true; 148 149 Collection c = 150 (Collection) tEnv.getObjRelation("_getScriptStorage"); 151 152 if (c == null) { 153 tRes.tested("getScriptStorage()", false); 154 return; 155 } 156 157 Iterator tests = c.iterator(); 158 159 while (tests.hasNext()) { 160 Parameters testdata = (Parameters)tests.next(); 161 String expected = testdata.get("expected"); 162 String location = testdata.get("location"); 163 String output = ""; 164 165 log.println(testdata.get("description")); 166 167 try { 168 int storageid = getStorageId(location); 169 170 XInterface ifc = (XInterface)oObj.getScriptStorage(storageid); 171 172 if (ifc == null) 173 output = "null"; 174 else { 175 Object info = UnoRuntime.queryInterface( 176 XScriptInfoAccess.class, ifc); 177 178 if (info == null) 179 output = "null"; 180 else 181 output = "XScriptInfoAccess.class"; 182 } 183 } 184 catch (com.sun.star.uno.RuntimeException re) { 185 log.println("Caught RuntimeException: " + re); 186 output = "com.sun.star.uno.RuntimeException"; 187 } 188 log.println("expected: " + expected + ", output: " + output); 189 result &= output.equals(expected); 190 } 191 tRes.tested("getScriptStorage()", result); 192 } 193 _refreshScriptStorage()194 public void _refreshScriptStorage() { 195 boolean result = true; 196 197 Collection c = 198 (Collection) tEnv.getObjRelation("_refreshScriptStorage"); 199 200 if (c == null) { 201 tRes.tested("refreshScriptStorage()", false); 202 return; 203 } 204 205 Iterator tests = c.iterator(); 206 207 while (tests.hasNext()) { 208 Parameters testdata = (Parameters)tests.next(); 209 String expected = testdata.get("expected"); 210 String location = testdata.get("location"); 211 String output = ""; 212 213 log.println(testdata.get("description")); 214 215 try { 216 String uri = util.utils.getFullTestURL(location); 217 log.println("calling refreshScriptStorage with URI: " + uri); 218 oObj.refreshScriptStorage(uri); 219 output = "success"; 220 } 221 catch (com.sun.star.uno.RuntimeException re) { 222 log.println("Caught RuntimeException: " + re); 223 output = "com.sun.star.uno.RuntimeException"; 224 } 225 log.println("expected: " + expected + ", output: " + output); 226 result &= output.equals(expected); 227 } 228 tRes.tested("refreshScriptStorage()", result); 229 } 230 getStorageId(String location)231 private int getStorageId(String location) { 232 233 if (location.equals("share")) 234 return 0; 235 236 if (location.equals("user")) 237 return 1; 238 239 String uri = util.utils.getFullTestURL(location); 240 241 XSimpleFileAccess access = getXSimpleFileAccess(); 242 if (access == null) 243 return -1; 244 245 return oObj.createScriptStorageWithURI(access, uri); 246 } 247 getXSimpleFileAccess()248 private XSimpleFileAccess getXSimpleFileAccess() { 249 XSimpleFileAccess access = null; 250 251 try { 252 Object fa = tParam.getMSF().createInstance( 253 "com.sun.star.ucb.SimpleFileAccess"); 254 255 access = (XSimpleFileAccess) 256 UnoRuntime.queryInterface(XSimpleFileAccess.class, fa); 257 } 258 catch (com.sun.star.uno.Exception e) { 259 return null; 260 } 261 return access; 262 } 263 } 264