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 package basicrunner; 24 25 import lib.TestResult; 26 import lib.TestEnvironment; 27 import lib.TestParameters; 28 import share.DescEntry; 29 import share.LogWriter; 30 31 import com.sun.star.lang.XMultiServiceFactory; 32 33 import com.sun.star.beans.PropertyValue; 34 35 36 /** 37 * The BASIC interface test 38 */ 39 public class BasicIfcTest { 40 /** The BasicHandler **/ 41 static BasicHandler oBasicHandler = null; 42 /** The result orf the test **/ 43 protected TestResult tRes; 44 /** the name of the test **/ 45 protected String testName; 46 47 /** Constructor with test name. 48 * @param name The name of the test. 49 */ BasicIfcTest(String name)50 public BasicIfcTest(String name) { 51 testName = name; 52 } 53 54 /** 55 * Let the test run. 56 * @param xTestedEntry Informaton about the interface to test. 57 * @param tEnv The environment of the test. 58 * @param tParam The test parameters. 59 * @return A result of the test. 60 */ run(DescEntry xTestedEntry, TestEnvironment tEnv, TestParameters tParam)61 public TestResult run(DescEntry xTestedEntry, TestEnvironment tEnv, 62 TestParameters tParam) { 63 64 String sResult = ""; 65 66 this.tRes = new TestResult(); 67 LogWriter log = xTestedEntry.Logger; 68 69 // Get Handler, that was created during object creation. 70 try { 71 oBasicHandler = (BasicHandler)tEnv.getObjRelation("BasicHandler"); 72 } catch (java.lang.NullPointerException e) { 73 log.println("No Component created"); 74 return null; 75 } 76 77 if (!oBasicHandler.isUptodate((XMultiServiceFactory)tParam.getMSF())) { 78 // If Handler uses old MSF (in case of Office's GPF) then don't test 79 // interface. 80 return null; 81 } 82 83 boolean objectWasCreated = ((Boolean)tEnv.getObjRelation("objectCreated")).booleanValue(); 84 85 if (objectWasCreated) { 86 oBasicHandler.setTestedInterface(this, log); 87 88 DescEntry methods[] = xTestedEntry.SubEntries; 89 90 String names[] = new String[methods.length + 1]; 91 boolean isOpt[] = new boolean[methods.length + 1]; 92 String other[] = new String[1]; 93 94 String aName = xTestedEntry.longName; 95 aName = aName.substring(aName.indexOf("::")+2); 96 int oldIndex = 0; 97 int index = aName.indexOf("::"); 98 names[0] = ""; 99 while(index!=-1) { 100 names[0] += aName.substring(oldIndex,index) + "."; 101 oldIndex=index+2; 102 index=aName.indexOf("::", oldIndex); 103 } 104 names[0] += aName.substring(oldIndex); 105 isOpt[0] = xTestedEntry.isOptional; 106 107 for (int i = 1; i < names.length; i++) { 108 names[i] = methods[i - 1].entryName; 109 isOpt[i] = methods[i - 1].isOptional; 110 } 111 112 // for reasons of compatibility with JSuite we change the first 113 // character of EntryType to upper case. 114 String eType = xTestedEntry.EntryType; 115 other[0] = eType.toUpperCase().charAt(0)+eType.substring(1); 116 117 Object params[] = {names, isOpt, other}; 118 119 try { 120 PropertyValue Res = oBasicHandler.perform("testInterface", params); 121 sResult = (String)Res.Value; 122 } catch (BasicException e) { 123 log.println(e.info); 124 sResult = "SKIPPED.FAILED"; 125 } 126 } else { // if object was not created... 127 sResult = "SKIPPED.FAILED"; 128 } 129 130 // now tRes has all substates: collect them 131 DescEntry[] subs = xTestedEntry.SubEntries; 132 for (int i = 0; i < subs.length ; i++) { 133 if (sResult.equals("SKIPPED.FAILED")) 134 subs[i].State = "SKIPPED.FAILED"; 135 else if (sResult.equals("SKIPPED.OK")) 136 subs[i].State = "SKIPPED.OK"; 137 else 138 if (tRes.getStatusFor(subs[i].entryName) == null) { 139 subs[i].State = "SKIPPED.FAILED"; 140 } else { 141 subs[i].State = tRes.getStatusFor( 142 subs[i].entryName).toString(); 143 } 144 } 145 146 xTestedEntry.State = sResult; 147 return null; 148 } 149 150 /** 151 * Set the result of the method that is tested. 152 * @param methodName The name of the method. 153 * @param bResult The result of the test. 154 */ methodTested(String methodName, boolean bResult)155 public void methodTested(String methodName, boolean bResult) { 156 tRes.tested(methodName, bResult); 157 } 158 159 /** 160 * @return The name of the interface or the service tested. 161 */ getTestedClassName()162 String getTestedClassName() { 163 return testName; 164 } 165 } 166