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 import drafts.com.sun.star.script.framework.storage.XScriptInfo;
29 
30 import com.sun.star.uno.UnoRuntime;
31 import com.sun.star.lang.XMultiServiceFactory;
32 import com.sun.star.uno.XInterface;
33 import com.sun.star.ucb.XSimpleFileAccess;
34 import com.sun.star.uno.Exception;
35 import com.sun.star.beans.XPropertySet;
36 
37 import java.util.Collection;
38 import java.util.Iterator;
39 
40 import java.io.PrintWriter;
41 import lib.Parameters;
42 import lib.MultiMethodTest;
43 import lib.StatusException;
44 
45 public class _XScriptInfo extends MultiMethodTest {
46 
47     public XScriptInfo oObj = null;
48 
49     /**
50     * Retrieves object relation.
51     */
before()52     public void before() throws StatusException {
53     }
54 
_getLogicalName()55     public void _getLogicalName() {
56         boolean result = true;
57 
58         Collection c =
59             (Collection) tEnv.getObjRelation("_getLogicalName");
60 
61         Iterator tests;
62 
63         if (c != null) {
64             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                 output = oObj.getLogicalName();
74 
75                 log.println("expected: " + expected + ", output: " + output);
76                 result &= output.equals(expected);
77             }
78         }
79         else {
80             result = false;
81         }
82 
83         tRes.tested("getLogicalName()", result);
84     }
85 
_getParcelURI()86     public void _getParcelURI() {
87         boolean result = true;
88 
89         Collection c =
90             (Collection) tEnv.getObjRelation("_getParcelURI");
91 
92         Iterator tests;
93 
94         if (c != null) {
95             tests = c.iterator();
96 
97             while (tests.hasNext()) {
98                 Parameters testdata = (Parameters)tests.next();
99                 String expected = testdata.get("expected");
100                 String output = "";
101 
102                 log.println(testdata.get("description"));
103 
104                 output = oObj.getParcelURI();
105 
106                 log.println("expected: " + expected + ", output: " + output);
107                 result &= output.endsWith(expected);
108             }
109         }
110         else {
111             result = false;
112         }
113         tRes.tested("getParcelURI()", result);
114     }
115 
_getLanguage()116     public void _getLanguage() {
117         boolean result = true;
118 
119         Collection c =
120             (Collection) tEnv.getObjRelation("_getLanguage");
121 
122         Iterator tests;
123 
124         if (c != null) {
125             tests = c.iterator();
126 
127             while (tests.hasNext()) {
128                 Parameters testdata = (Parameters)tests.next();
129                 String expected = testdata.get("expected");
130                 String output = "";
131 
132                 log.println(testdata.get("description"));
133 
134                 output = oObj.getLanguage();
135 
136                 log.println("expected: " + expected + ", output: " + output);
137                 result &= output.equals(expected);
138             }
139         }
140         else {
141             result = false;
142         }
143         tRes.tested("getLanguage()", result);
144     }
145 
_getFunctionName()146     public void _getFunctionName() {
147         boolean result = true;
148 
149         Collection c =
150             (Collection) tEnv.getObjRelation("_getFunctionName");
151 
152         Iterator tests;
153 
154         if (c != null) {
155             tests = c.iterator();
156 
157             while (tests.hasNext()) {
158                 Parameters testdata = (Parameters)tests.next();
159                 String expected = testdata.get("expected");
160                 String output = "";
161 
162                 log.println(testdata.get("description"));
163 
164                 output = oObj.getFunctionName();
165 
166                 log.println("expected: " + expected + ", output: " + output);
167                 result &= output.equals(expected);
168             }
169         }
170         else {
171             result = false;
172         }
173         tRes.tested("getFunctionName()", result);
174     }
175 
_getLanguageProperties()176     public void _getLanguageProperties() {
177         boolean result = true;
178 
179         Collection c =
180             (Collection) tEnv.getObjRelation("_getLanguageProperties");
181 
182         Iterator tests;
183 
184         if (c != null) {
185             tests = c.iterator();
186 
187             while (tests.hasNext()) {
188                 Parameters testdata = (Parameters)tests.next();
189                 String expected = testdata.get("expected");
190                 String output = "";
191 
192                 log.println(testdata.get("description"));
193 
194                 try {
195                     XPropertySet langProps = oObj.getLanguageProperties();
196                     output = (String)langProps.getPropertyValue("classpath");
197 
198                     if (output == null)
199                         output = "null";
200                 }
201                 catch( com.sun.star.uno.Exception e) {
202                     log.println("caught UNO Exception:" + e);
203                     output = "com.sun.star.uno.Exception";
204                 }
205 
206                 log.println("expected: " + expected + ", output: " + output);
207                 result &= output.equals(expected);
208             }
209         }
210         else {
211             result = false;
212         }
213         tRes.tested("getLanguageProperties()", true);
214     }
215 
_getFileSetNames()216     public void _getFileSetNames() {
217         boolean result = true;
218 
219         Collection c =
220             (Collection) tEnv.getObjRelation("_getFileSetNames");
221 
222         Iterator tests;
223 
224         if (c != null) {
225             tests = c.iterator();
226 
227             while (tests.hasNext()) {
228                 Parameters testdata = (Parameters)tests.next();
229                 String expected = testdata.get("expected");
230                 String output = "";
231 
232                 log.println(testdata.get("description"));
233 
234                 String[] fileSets = oObj.getFileSetNames();
235 
236                 if (fileSets == null)
237                     output = "null";
238                 else if (fileSets.length != 1)
239                     output = "WrongNumberOfFileSets";
240                 else
241                     output = fileSets[0];
242 
243                 log.println("expected: " + expected + ", output: " + output);
244                 result &= output.equals(expected);
245             }
246         }
247         else {
248             result = false;
249         }
250         tRes.tested("getFileSetNames()", result);
251     }
252 
_getFilesInFileSet()253     public void _getFilesInFileSet() {
254         boolean result = true;
255 
256         Collection c =
257             (Collection) tEnv.getObjRelation("_getFilesInFileSet");
258 
259         Iterator tests;
260 
261         if (c != null) {
262             tests = c.iterator();
263 
264             while (tests.hasNext()) {
265                 Parameters testdata = (Parameters)tests.next();
266                 String expected = testdata.get("expected");
267                 String output = "";
268 
269                 log.println(testdata.get("description"));
270 
271                 String[] filesInFileSet =
272                     oObj.getFilesInFileSet(oObj.getFileSetNames()[0]);
273 
274                 if (filesInFileSet == null)
275                     output = "null";
276                 else if (filesInFileSet.length != 1)
277                     output = "WrongNumberOfFilesInFileSet";
278                 else
279                     output = filesInFileSet[0];
280 
281                 log.println("expected: " + expected + ", output: " + output);
282                 result &= output.equals(expected);
283             }
284         }
285         else {
286             result = false;
287         }
288         tRes.tested("getFilesInFileSet()", result);
289     }
290 
_getDescription()291     public void _getDescription() {
292         boolean result = true;
293 
294         Collection c =
295             (Collection) tEnv.getObjRelation("_getDescription");
296 
297         Iterator tests;
298 
299         if (c != null) {
300             tests = c.iterator();
301 
302             while (tests.hasNext()) {
303                 Parameters testdata = (Parameters)tests.next();
304                 String expected = testdata.get("expected");
305                 String output = "";
306 
307                 log.println(testdata.get("description"));
308 
309                 output = oObj.getDescription();
310 
311                 if (output == null)
312                     output = "null";
313                 else if (output.length() == 0)
314                     output = "empty";
315 
316                 log.println("expected: [" + expected + "], output: [" +
317                     output + "]");
318                 result &= output.equals(expected);
319             }
320         }
321         else {
322             result = false;
323         }
324 
325         tRes.tested("getDescription()", result);
326     }
327 }
328