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