1*cd519653SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*cd519653SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*cd519653SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*cd519653SAndrew Rist  * distributed with this work for additional information
6*cd519653SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*cd519653SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*cd519653SAndrew Rist  * "License"); you may not use this file except in compliance
9*cd519653SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*cd519653SAndrew Rist  *
11*cd519653SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*cd519653SAndrew Rist  *
13*cd519653SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*cd519653SAndrew Rist  * software distributed under the License is distributed on an
15*cd519653SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*cd519653SAndrew Rist  * KIND, either express or implied.  See the License for the
17*cd519653SAndrew Rist  * specific language governing permissions and limitations
18*cd519653SAndrew Rist  * under the License.
19*cd519653SAndrew Rist  *
20*cd519653SAndrew Rist  *************************************************************/
21*cd519653SAndrew Rist 
22*cd519653SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir package ifc.script.framework.storage;
25cdf0e10cSrcweir 
26cdf0e10cSrcweir import drafts.com.sun.star.script.framework.storage.XScriptStorageManager;
27cdf0e10cSrcweir import drafts.com.sun.star.script.framework.storage.XScriptInfoAccess;
28cdf0e10cSrcweir import drafts.com.sun.star.script.framework.storage.XScriptInfo;
29cdf0e10cSrcweir 
30cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime;
31cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory;
32cdf0e10cSrcweir import com.sun.star.uno.XInterface;
33cdf0e10cSrcweir import com.sun.star.ucb.XSimpleFileAccess;
34cdf0e10cSrcweir import com.sun.star.uno.Exception;
35cdf0e10cSrcweir import com.sun.star.beans.XPropertySet;
36cdf0e10cSrcweir 
37cdf0e10cSrcweir import java.util.Collection;
38cdf0e10cSrcweir import java.util.Iterator;
39cdf0e10cSrcweir 
40cdf0e10cSrcweir import java.io.PrintWriter;
41cdf0e10cSrcweir import lib.Parameters;
42cdf0e10cSrcweir import lib.MultiMethodTest;
43cdf0e10cSrcweir import lib.StatusException;
44cdf0e10cSrcweir 
45cdf0e10cSrcweir public class _XScriptInfo extends MultiMethodTest {
46cdf0e10cSrcweir 
47cdf0e10cSrcweir     public XScriptInfo oObj = null;
48cdf0e10cSrcweir 
49cdf0e10cSrcweir     /**
50cdf0e10cSrcweir     * Retrieves object relation.
51cdf0e10cSrcweir     */
before()52cdf0e10cSrcweir     public void before() throws StatusException {
53cdf0e10cSrcweir     }
54cdf0e10cSrcweir 
_getLogicalName()55cdf0e10cSrcweir     public void _getLogicalName() {
56cdf0e10cSrcweir         boolean result = true;
57cdf0e10cSrcweir 
58cdf0e10cSrcweir         Collection c =
59cdf0e10cSrcweir             (Collection) tEnv.getObjRelation("_getLogicalName");
60cdf0e10cSrcweir 
61cdf0e10cSrcweir         Iterator tests;
62cdf0e10cSrcweir 
63cdf0e10cSrcweir         if (c != null) {
64cdf0e10cSrcweir             tests = c.iterator();
65cdf0e10cSrcweir 
66cdf0e10cSrcweir             while (tests.hasNext()) {
67cdf0e10cSrcweir                 Parameters testdata = (Parameters)tests.next();
68cdf0e10cSrcweir                 String expected = testdata.get("expected");
69cdf0e10cSrcweir                 String output = "";
70cdf0e10cSrcweir 
71cdf0e10cSrcweir                 log.println(testdata.get("description"));
72cdf0e10cSrcweir 
73cdf0e10cSrcweir                 output = oObj.getLogicalName();
74cdf0e10cSrcweir 
75cdf0e10cSrcweir                 log.println("expected: " + expected + ", output: " + output);
76cdf0e10cSrcweir                 result &= output.equals(expected);
77cdf0e10cSrcweir             }
78cdf0e10cSrcweir         }
79cdf0e10cSrcweir         else {
80cdf0e10cSrcweir             result = false;
81cdf0e10cSrcweir         }
82cdf0e10cSrcweir 
83cdf0e10cSrcweir         tRes.tested("getLogicalName()", result);
84cdf0e10cSrcweir     }
85cdf0e10cSrcweir 
_getParcelURI()86cdf0e10cSrcweir     public void _getParcelURI() {
87cdf0e10cSrcweir         boolean result = true;
88cdf0e10cSrcweir 
89cdf0e10cSrcweir         Collection c =
90cdf0e10cSrcweir             (Collection) tEnv.getObjRelation("_getParcelURI");
91cdf0e10cSrcweir 
92cdf0e10cSrcweir         Iterator tests;
93cdf0e10cSrcweir 
94cdf0e10cSrcweir         if (c != null) {
95cdf0e10cSrcweir             tests = c.iterator();
96cdf0e10cSrcweir 
97cdf0e10cSrcweir             while (tests.hasNext()) {
98cdf0e10cSrcweir                 Parameters testdata = (Parameters)tests.next();
99cdf0e10cSrcweir                 String expected = testdata.get("expected");
100cdf0e10cSrcweir                 String output = "";
101cdf0e10cSrcweir 
102cdf0e10cSrcweir                 log.println(testdata.get("description"));
103cdf0e10cSrcweir 
104cdf0e10cSrcweir                 output = oObj.getParcelURI();
105cdf0e10cSrcweir 
106cdf0e10cSrcweir                 log.println("expected: " + expected + ", output: " + output);
107cdf0e10cSrcweir                 result &= output.endsWith(expected);
108cdf0e10cSrcweir             }
109cdf0e10cSrcweir         }
110cdf0e10cSrcweir         else {
111cdf0e10cSrcweir             result = false;
112cdf0e10cSrcweir         }
113cdf0e10cSrcweir         tRes.tested("getParcelURI()", result);
114cdf0e10cSrcweir     }
115cdf0e10cSrcweir 
_getLanguage()116cdf0e10cSrcweir     public void _getLanguage() {
117cdf0e10cSrcweir         boolean result = true;
118cdf0e10cSrcweir 
119cdf0e10cSrcweir         Collection c =
120cdf0e10cSrcweir             (Collection) tEnv.getObjRelation("_getLanguage");
121cdf0e10cSrcweir 
122cdf0e10cSrcweir         Iterator tests;
123cdf0e10cSrcweir 
124cdf0e10cSrcweir         if (c != null) {
125cdf0e10cSrcweir             tests = c.iterator();
126cdf0e10cSrcweir 
127cdf0e10cSrcweir             while (tests.hasNext()) {
128cdf0e10cSrcweir                 Parameters testdata = (Parameters)tests.next();
129cdf0e10cSrcweir                 String expected = testdata.get("expected");
130cdf0e10cSrcweir                 String output = "";
131cdf0e10cSrcweir 
132cdf0e10cSrcweir                 log.println(testdata.get("description"));
133cdf0e10cSrcweir 
134cdf0e10cSrcweir                 output = oObj.getLanguage();
135cdf0e10cSrcweir 
136cdf0e10cSrcweir                 log.println("expected: " + expected + ", output: " + output);
137cdf0e10cSrcweir                 result &= output.equals(expected);
138cdf0e10cSrcweir             }
139cdf0e10cSrcweir         }
140cdf0e10cSrcweir         else {
141cdf0e10cSrcweir             result = false;
142cdf0e10cSrcweir         }
143cdf0e10cSrcweir         tRes.tested("getLanguage()", result);
144cdf0e10cSrcweir     }
145cdf0e10cSrcweir 
_getFunctionName()146cdf0e10cSrcweir     public void _getFunctionName() {
147cdf0e10cSrcweir         boolean result = true;
148cdf0e10cSrcweir 
149cdf0e10cSrcweir         Collection c =
150cdf0e10cSrcweir             (Collection) tEnv.getObjRelation("_getFunctionName");
151cdf0e10cSrcweir 
152cdf0e10cSrcweir         Iterator tests;
153cdf0e10cSrcweir 
154cdf0e10cSrcweir         if (c != null) {
155cdf0e10cSrcweir             tests = c.iterator();
156cdf0e10cSrcweir 
157cdf0e10cSrcweir             while (tests.hasNext()) {
158cdf0e10cSrcweir                 Parameters testdata = (Parameters)tests.next();
159cdf0e10cSrcweir                 String expected = testdata.get("expected");
160cdf0e10cSrcweir                 String output = "";
161cdf0e10cSrcweir 
162cdf0e10cSrcweir                 log.println(testdata.get("description"));
163cdf0e10cSrcweir 
164cdf0e10cSrcweir                 output = oObj.getFunctionName();
165cdf0e10cSrcweir 
166cdf0e10cSrcweir                 log.println("expected: " + expected + ", output: " + output);
167cdf0e10cSrcweir                 result &= output.equals(expected);
168cdf0e10cSrcweir             }
169cdf0e10cSrcweir         }
170cdf0e10cSrcweir         else {
171cdf0e10cSrcweir             result = false;
172cdf0e10cSrcweir         }
173cdf0e10cSrcweir         tRes.tested("getFunctionName()", result);
174cdf0e10cSrcweir     }
175cdf0e10cSrcweir 
_getLanguageProperties()176cdf0e10cSrcweir     public void _getLanguageProperties() {
177cdf0e10cSrcweir         boolean result = true;
178cdf0e10cSrcweir 
179cdf0e10cSrcweir         Collection c =
180cdf0e10cSrcweir             (Collection) tEnv.getObjRelation("_getLanguageProperties");
181cdf0e10cSrcweir 
182cdf0e10cSrcweir         Iterator tests;
183cdf0e10cSrcweir 
184cdf0e10cSrcweir         if (c != null) {
185cdf0e10cSrcweir             tests = c.iterator();
186cdf0e10cSrcweir 
187cdf0e10cSrcweir             while (tests.hasNext()) {
188cdf0e10cSrcweir                 Parameters testdata = (Parameters)tests.next();
189cdf0e10cSrcweir                 String expected = testdata.get("expected");
190cdf0e10cSrcweir                 String output = "";
191cdf0e10cSrcweir 
192cdf0e10cSrcweir                 log.println(testdata.get("description"));
193cdf0e10cSrcweir 
194cdf0e10cSrcweir                 try {
195cdf0e10cSrcweir                     XPropertySet langProps = oObj.getLanguageProperties();
196cdf0e10cSrcweir                     output = (String)langProps.getPropertyValue("classpath");
197cdf0e10cSrcweir 
198cdf0e10cSrcweir                     if (output == null)
199cdf0e10cSrcweir                         output = "null";
200cdf0e10cSrcweir                 }
201cdf0e10cSrcweir                 catch( com.sun.star.uno.Exception e) {
202cdf0e10cSrcweir                     log.println("caught UNO Exception:" + e);
203cdf0e10cSrcweir                     output = "com.sun.star.uno.Exception";
204cdf0e10cSrcweir                 }
205cdf0e10cSrcweir 
206cdf0e10cSrcweir                 log.println("expected: " + expected + ", output: " + output);
207cdf0e10cSrcweir                 result &= output.equals(expected);
208cdf0e10cSrcweir             }
209cdf0e10cSrcweir         }
210cdf0e10cSrcweir         else {
211cdf0e10cSrcweir             result = false;
212cdf0e10cSrcweir         }
213cdf0e10cSrcweir         tRes.tested("getLanguageProperties()", true);
214cdf0e10cSrcweir     }
215cdf0e10cSrcweir 
_getFileSetNames()216cdf0e10cSrcweir     public void _getFileSetNames() {
217cdf0e10cSrcweir         boolean result = true;
218cdf0e10cSrcweir 
219cdf0e10cSrcweir         Collection c =
220cdf0e10cSrcweir             (Collection) tEnv.getObjRelation("_getFileSetNames");
221cdf0e10cSrcweir 
222cdf0e10cSrcweir         Iterator tests;
223cdf0e10cSrcweir 
224cdf0e10cSrcweir         if (c != null) {
225cdf0e10cSrcweir             tests = c.iterator();
226cdf0e10cSrcweir 
227cdf0e10cSrcweir             while (tests.hasNext()) {
228cdf0e10cSrcweir                 Parameters testdata = (Parameters)tests.next();
229cdf0e10cSrcweir                 String expected = testdata.get("expected");
230cdf0e10cSrcweir                 String output = "";
231cdf0e10cSrcweir 
232cdf0e10cSrcweir                 log.println(testdata.get("description"));
233cdf0e10cSrcweir 
234cdf0e10cSrcweir                 String[] fileSets = oObj.getFileSetNames();
235cdf0e10cSrcweir 
236cdf0e10cSrcweir                 if (fileSets == null)
237cdf0e10cSrcweir                     output = "null";
238cdf0e10cSrcweir                 else if (fileSets.length != 1)
239cdf0e10cSrcweir                     output = "WrongNumberOfFileSets";
240cdf0e10cSrcweir                 else
241cdf0e10cSrcweir                     output = fileSets[0];
242cdf0e10cSrcweir 
243cdf0e10cSrcweir                 log.println("expected: " + expected + ", output: " + output);
244cdf0e10cSrcweir                 result &= output.equals(expected);
245cdf0e10cSrcweir             }
246cdf0e10cSrcweir         }
247cdf0e10cSrcweir         else {
248cdf0e10cSrcweir             result = false;
249cdf0e10cSrcweir         }
250cdf0e10cSrcweir         tRes.tested("getFileSetNames()", result);
251cdf0e10cSrcweir     }
252cdf0e10cSrcweir 
_getFilesInFileSet()253cdf0e10cSrcweir     public void _getFilesInFileSet() {
254cdf0e10cSrcweir         boolean result = true;
255cdf0e10cSrcweir 
256cdf0e10cSrcweir         Collection c =
257cdf0e10cSrcweir             (Collection) tEnv.getObjRelation("_getFilesInFileSet");
258cdf0e10cSrcweir 
259cdf0e10cSrcweir         Iterator tests;
260cdf0e10cSrcweir 
261cdf0e10cSrcweir         if (c != null) {
262cdf0e10cSrcweir             tests = c.iterator();
263cdf0e10cSrcweir 
264cdf0e10cSrcweir             while (tests.hasNext()) {
265cdf0e10cSrcweir                 Parameters testdata = (Parameters)tests.next();
266cdf0e10cSrcweir                 String expected = testdata.get("expected");
267cdf0e10cSrcweir                 String output = "";
268cdf0e10cSrcweir 
269cdf0e10cSrcweir                 log.println(testdata.get("description"));
270cdf0e10cSrcweir 
271cdf0e10cSrcweir                 String[] filesInFileSet =
272cdf0e10cSrcweir                     oObj.getFilesInFileSet(oObj.getFileSetNames()[0]);
273cdf0e10cSrcweir 
274cdf0e10cSrcweir                 if (filesInFileSet == null)
275cdf0e10cSrcweir                     output = "null";
276cdf0e10cSrcweir                 else if (filesInFileSet.length != 1)
277cdf0e10cSrcweir                     output = "WrongNumberOfFilesInFileSet";
278cdf0e10cSrcweir                 else
279cdf0e10cSrcweir                     output = filesInFileSet[0];
280cdf0e10cSrcweir 
281cdf0e10cSrcweir                 log.println("expected: " + expected + ", output: " + output);
282cdf0e10cSrcweir                 result &= output.equals(expected);
283cdf0e10cSrcweir             }
284cdf0e10cSrcweir         }
285cdf0e10cSrcweir         else {
286cdf0e10cSrcweir             result = false;
287cdf0e10cSrcweir         }
288cdf0e10cSrcweir         tRes.tested("getFilesInFileSet()", result);
289cdf0e10cSrcweir     }
290cdf0e10cSrcweir 
_getDescription()291cdf0e10cSrcweir     public void _getDescription() {
292cdf0e10cSrcweir         boolean result = true;
293cdf0e10cSrcweir 
294cdf0e10cSrcweir         Collection c =
295cdf0e10cSrcweir             (Collection) tEnv.getObjRelation("_getDescription");
296cdf0e10cSrcweir 
297cdf0e10cSrcweir         Iterator tests;
298cdf0e10cSrcweir 
299cdf0e10cSrcweir         if (c != null) {
300cdf0e10cSrcweir             tests = c.iterator();
301cdf0e10cSrcweir 
302cdf0e10cSrcweir             while (tests.hasNext()) {
303cdf0e10cSrcweir                 Parameters testdata = (Parameters)tests.next();
304cdf0e10cSrcweir                 String expected = testdata.get("expected");
305cdf0e10cSrcweir                 String output = "";
306cdf0e10cSrcweir 
307cdf0e10cSrcweir                 log.println(testdata.get("description"));
308cdf0e10cSrcweir 
309cdf0e10cSrcweir                 output = oObj.getDescription();
310cdf0e10cSrcweir 
311cdf0e10cSrcweir                 if (output == null)
312cdf0e10cSrcweir                     output = "null";
313cdf0e10cSrcweir                 else if (output.length() == 0)
314cdf0e10cSrcweir                     output = "empty";
315cdf0e10cSrcweir 
316cdf0e10cSrcweir                 log.println("expected: [" + expected + "], output: [" +
317cdf0e10cSrcweir                     output + "]");
318cdf0e10cSrcweir                 result &= output.equals(expected);
319cdf0e10cSrcweir             }
320cdf0e10cSrcweir         }
321cdf0e10cSrcweir         else {
322cdf0e10cSrcweir             result = false;
323cdf0e10cSrcweir         }
324cdf0e10cSrcweir 
325cdf0e10cSrcweir         tRes.tested("getDescription()", result);
326cdf0e10cSrcweir     }
327cdf0e10cSrcweir }
328