1*ef39d40dSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*ef39d40dSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*ef39d40dSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*ef39d40dSAndrew Rist  * distributed with this work for additional information
6*ef39d40dSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*ef39d40dSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*ef39d40dSAndrew Rist  * "License"); you may not use this file except in compliance
9*ef39d40dSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*ef39d40dSAndrew Rist  *
11*ef39d40dSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*ef39d40dSAndrew Rist  *
13*ef39d40dSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*ef39d40dSAndrew Rist  * software distributed under the License is distributed on an
15*ef39d40dSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*ef39d40dSAndrew Rist  * KIND, either express or implied.  See the License for the
17*ef39d40dSAndrew Rist  * specific language governing permissions and limitations
18*ef39d40dSAndrew Rist  * under the License.
19*ef39d40dSAndrew Rist  *
20*ef39d40dSAndrew Rist  *************************************************************/
21*ef39d40dSAndrew Rist 
22*ef39d40dSAndrew Rist 
23cdf0e10cSrcweir package basicrunner;
24cdf0e10cSrcweir 
25cdf0e10cSrcweir import lib.TestResult;
26cdf0e10cSrcweir import lib.TestEnvironment;
27cdf0e10cSrcweir import lib.TestParameters;
28cdf0e10cSrcweir import share.DescEntry;
29cdf0e10cSrcweir import share.LogWriter;
30cdf0e10cSrcweir 
31cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory;
32cdf0e10cSrcweir 
33cdf0e10cSrcweir import com.sun.star.beans.PropertyValue;
34cdf0e10cSrcweir 
35cdf0e10cSrcweir 
36cdf0e10cSrcweir /**
37cdf0e10cSrcweir  * The BASIC interface test
38cdf0e10cSrcweir  */
39cdf0e10cSrcweir public class BasicIfcTest {
40cdf0e10cSrcweir     /** The BasicHandler **/
41cdf0e10cSrcweir     static BasicHandler oBasicHandler = null;
42cdf0e10cSrcweir     /** The result orf the test **/
43cdf0e10cSrcweir     protected TestResult tRes;
44cdf0e10cSrcweir     /** the name of the test **/
45cdf0e10cSrcweir     protected String testName;
46cdf0e10cSrcweir 
47cdf0e10cSrcweir     /** Constructor with test name.
48cdf0e10cSrcweir      * @param name The name of the test.
49cdf0e10cSrcweir      */
BasicIfcTest(String name)50cdf0e10cSrcweir     public BasicIfcTest(String name) {
51cdf0e10cSrcweir         testName = name;
52cdf0e10cSrcweir     }
53cdf0e10cSrcweir 
54cdf0e10cSrcweir     /**
55cdf0e10cSrcweir      * Let the test run.
56cdf0e10cSrcweir      * @param xTestedEntry Informaton about the interface to test.
57cdf0e10cSrcweir      * @param tEnv The environment of the test.
58cdf0e10cSrcweir      * @param tParam The test parameters.
59cdf0e10cSrcweir      * @return A result of the test.
60cdf0e10cSrcweir      */
run(DescEntry xTestedEntry, TestEnvironment tEnv, TestParameters tParam)61cdf0e10cSrcweir     public TestResult run(DescEntry xTestedEntry, TestEnvironment tEnv,
62cdf0e10cSrcweir             TestParameters tParam) {
63cdf0e10cSrcweir 
64cdf0e10cSrcweir         String sResult = "";
65cdf0e10cSrcweir 
66cdf0e10cSrcweir         this.tRes = new TestResult();
67cdf0e10cSrcweir         LogWriter log = xTestedEntry.Logger;
68cdf0e10cSrcweir 
69cdf0e10cSrcweir         // Get Handler, that was created during object creation.
70cdf0e10cSrcweir         try {
71cdf0e10cSrcweir             oBasicHandler = (BasicHandler)tEnv.getObjRelation("BasicHandler");
72cdf0e10cSrcweir         } catch (java.lang.NullPointerException e) {
73cdf0e10cSrcweir             log.println("No Component created");
74cdf0e10cSrcweir             return null;
75cdf0e10cSrcweir         }
76cdf0e10cSrcweir 
77cdf0e10cSrcweir         if (!oBasicHandler.isUptodate((XMultiServiceFactory)tParam.getMSF())) {
78cdf0e10cSrcweir             // If Handler uses old MSF (in case of Office's GPF) then don't test
79cdf0e10cSrcweir             // interface.
80cdf0e10cSrcweir             return null;
81cdf0e10cSrcweir         }
82cdf0e10cSrcweir 
83cdf0e10cSrcweir         boolean objectWasCreated = ((Boolean)tEnv.getObjRelation("objectCreated")).booleanValue();
84cdf0e10cSrcweir 
85cdf0e10cSrcweir         if (objectWasCreated) {
86cdf0e10cSrcweir             oBasicHandler.setTestedInterface(this, log);
87cdf0e10cSrcweir 
88cdf0e10cSrcweir             DescEntry methods[] = xTestedEntry.SubEntries;
89cdf0e10cSrcweir 
90cdf0e10cSrcweir             String  names[] = new String[methods.length + 1];
91cdf0e10cSrcweir             boolean isOpt[] = new boolean[methods.length + 1];
92cdf0e10cSrcweir             String other[] = new String[1];
93cdf0e10cSrcweir 
94cdf0e10cSrcweir             String aName = xTestedEntry.longName;
95cdf0e10cSrcweir             aName = aName.substring(aName.indexOf("::")+2);
96cdf0e10cSrcweir             int oldIndex = 0;
97cdf0e10cSrcweir             int index = aName.indexOf("::");
98cdf0e10cSrcweir             names[0] = "";
99cdf0e10cSrcweir             while(index!=-1) {
100cdf0e10cSrcweir                 names[0] += aName.substring(oldIndex,index) + ".";
101cdf0e10cSrcweir                 oldIndex=index+2;
102cdf0e10cSrcweir                 index=aName.indexOf("::", oldIndex);
103cdf0e10cSrcweir             }
104cdf0e10cSrcweir             names[0] += aName.substring(oldIndex);
105cdf0e10cSrcweir             isOpt[0] = xTestedEntry.isOptional;
106cdf0e10cSrcweir 
107cdf0e10cSrcweir             for (int i = 1; i < names.length; i++) {
108cdf0e10cSrcweir                 names[i] = methods[i - 1].entryName;
109cdf0e10cSrcweir                 isOpt[i] = methods[i - 1].isOptional;
110cdf0e10cSrcweir             }
111cdf0e10cSrcweir 
112cdf0e10cSrcweir             // for reasons of compatibility with JSuite we change the first
113cdf0e10cSrcweir             // character of EntryType to upper case.
114cdf0e10cSrcweir             String eType = xTestedEntry.EntryType;
115cdf0e10cSrcweir             other[0] = eType.toUpperCase().charAt(0)+eType.substring(1);
116cdf0e10cSrcweir 
117cdf0e10cSrcweir             Object params[] = {names, isOpt, other};
118cdf0e10cSrcweir 
119cdf0e10cSrcweir             try {
120cdf0e10cSrcweir                 PropertyValue Res = oBasicHandler.perform("testInterface", params);
121cdf0e10cSrcweir                 sResult = (String)Res.Value;
122cdf0e10cSrcweir             } catch (BasicException e) {
123cdf0e10cSrcweir                 log.println(e.info);
124cdf0e10cSrcweir                 sResult = "SKIPPED.FAILED";
125cdf0e10cSrcweir             }
126cdf0e10cSrcweir         } else { // if object was not created...
127cdf0e10cSrcweir             sResult = "SKIPPED.FAILED";
128cdf0e10cSrcweir         }
129cdf0e10cSrcweir 
130cdf0e10cSrcweir         // now tRes has all substates: collect them
131cdf0e10cSrcweir         DescEntry[] subs = xTestedEntry.SubEntries;
132cdf0e10cSrcweir         for (int i = 0; i < subs.length ; i++) {
133cdf0e10cSrcweir             if (sResult.equals("SKIPPED.FAILED"))
134cdf0e10cSrcweir                 subs[i].State = "SKIPPED.FAILED";
135cdf0e10cSrcweir             else if (sResult.equals("SKIPPED.OK"))
136cdf0e10cSrcweir                 subs[i].State = "SKIPPED.OK";
137cdf0e10cSrcweir             else
138cdf0e10cSrcweir                 if (tRes.getStatusFor(subs[i].entryName) == null) {
139cdf0e10cSrcweir                     subs[i].State = "SKIPPED.FAILED";
140cdf0e10cSrcweir                 } else {
141cdf0e10cSrcweir                     subs[i].State = tRes.getStatusFor(
142cdf0e10cSrcweir                                                 subs[i].entryName).toString();
143cdf0e10cSrcweir                 }
144cdf0e10cSrcweir         }
145cdf0e10cSrcweir 
146cdf0e10cSrcweir         xTestedEntry.State = sResult;
147cdf0e10cSrcweir         return null;
148cdf0e10cSrcweir     }
149cdf0e10cSrcweir 
150cdf0e10cSrcweir     /**
151cdf0e10cSrcweir      * Set the result of the method that is tested.
152cdf0e10cSrcweir      * @param methodName The name of the method.
153cdf0e10cSrcweir      * @param bResult The result of the test.
154cdf0e10cSrcweir      */
methodTested(String methodName, boolean bResult)155cdf0e10cSrcweir     public void methodTested(String methodName, boolean bResult) {
156cdf0e10cSrcweir         tRes.tested(methodName, bResult);
157cdf0e10cSrcweir     }
158cdf0e10cSrcweir 
159cdf0e10cSrcweir     /**
160cdf0e10cSrcweir      * @return The name of the interface or the service tested.
161cdf0e10cSrcweir      */
getTestedClassName()162cdf0e10cSrcweir     String getTestedClassName() {
163cdf0e10cSrcweir         return testName;
164cdf0e10cSrcweir     }
165cdf0e10cSrcweir }
166