1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir package basicrunner; 28*cdf0e10cSrcweir 29*cdf0e10cSrcweir import lib.TestResult; 30*cdf0e10cSrcweir import lib.TestEnvironment; 31*cdf0e10cSrcweir import lib.TestParameters; 32*cdf0e10cSrcweir import share.DescEntry; 33*cdf0e10cSrcweir import share.LogWriter; 34*cdf0e10cSrcweir 35*cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory; 36*cdf0e10cSrcweir 37*cdf0e10cSrcweir import com.sun.star.beans.PropertyValue; 38*cdf0e10cSrcweir 39*cdf0e10cSrcweir 40*cdf0e10cSrcweir /** 41*cdf0e10cSrcweir * The BASIC interface test 42*cdf0e10cSrcweir */ 43*cdf0e10cSrcweir public class BasicIfcTest { 44*cdf0e10cSrcweir /** The BasicHandler **/ 45*cdf0e10cSrcweir static BasicHandler oBasicHandler = null; 46*cdf0e10cSrcweir /** The result orf the test **/ 47*cdf0e10cSrcweir protected TestResult tRes; 48*cdf0e10cSrcweir /** the name of the test **/ 49*cdf0e10cSrcweir protected String testName; 50*cdf0e10cSrcweir 51*cdf0e10cSrcweir /** Constructor with test name. 52*cdf0e10cSrcweir * @param name The name of the test. 53*cdf0e10cSrcweir */ 54*cdf0e10cSrcweir public BasicIfcTest(String name) { 55*cdf0e10cSrcweir testName = name; 56*cdf0e10cSrcweir } 57*cdf0e10cSrcweir 58*cdf0e10cSrcweir /** 59*cdf0e10cSrcweir * Let the test run. 60*cdf0e10cSrcweir * @param xTestedEntry Informaton about the interface to test. 61*cdf0e10cSrcweir * @param tEnv The environment of the test. 62*cdf0e10cSrcweir * @param tParam The test parameters. 63*cdf0e10cSrcweir * @return A result of the test. 64*cdf0e10cSrcweir */ 65*cdf0e10cSrcweir public TestResult run(DescEntry xTestedEntry, TestEnvironment tEnv, 66*cdf0e10cSrcweir TestParameters tParam) { 67*cdf0e10cSrcweir 68*cdf0e10cSrcweir String sResult = ""; 69*cdf0e10cSrcweir 70*cdf0e10cSrcweir this.tRes = new TestResult(); 71*cdf0e10cSrcweir LogWriter log = xTestedEntry.Logger; 72*cdf0e10cSrcweir 73*cdf0e10cSrcweir // Get Handler, that was created during object creation. 74*cdf0e10cSrcweir try { 75*cdf0e10cSrcweir oBasicHandler = (BasicHandler)tEnv.getObjRelation("BasicHandler"); 76*cdf0e10cSrcweir } catch (java.lang.NullPointerException e) { 77*cdf0e10cSrcweir log.println("No Component created"); 78*cdf0e10cSrcweir return null; 79*cdf0e10cSrcweir } 80*cdf0e10cSrcweir 81*cdf0e10cSrcweir if (!oBasicHandler.isUptodate((XMultiServiceFactory)tParam.getMSF())) { 82*cdf0e10cSrcweir // If Handler uses old MSF (in case of Office's GPF) then don't test 83*cdf0e10cSrcweir // interface. 84*cdf0e10cSrcweir return null; 85*cdf0e10cSrcweir } 86*cdf0e10cSrcweir 87*cdf0e10cSrcweir boolean objectWasCreated = ((Boolean)tEnv.getObjRelation("objectCreated")).booleanValue(); 88*cdf0e10cSrcweir 89*cdf0e10cSrcweir if (objectWasCreated) { 90*cdf0e10cSrcweir oBasicHandler.setTestedInterface(this, log); 91*cdf0e10cSrcweir 92*cdf0e10cSrcweir DescEntry methods[] = xTestedEntry.SubEntries; 93*cdf0e10cSrcweir 94*cdf0e10cSrcweir String names[] = new String[methods.length + 1]; 95*cdf0e10cSrcweir boolean isOpt[] = new boolean[methods.length + 1]; 96*cdf0e10cSrcweir String other[] = new String[1]; 97*cdf0e10cSrcweir 98*cdf0e10cSrcweir String aName = xTestedEntry.longName; 99*cdf0e10cSrcweir aName = aName.substring(aName.indexOf("::")+2); 100*cdf0e10cSrcweir int oldIndex = 0; 101*cdf0e10cSrcweir int index = aName.indexOf("::"); 102*cdf0e10cSrcweir names[0] = ""; 103*cdf0e10cSrcweir while(index!=-1) { 104*cdf0e10cSrcweir names[0] += aName.substring(oldIndex,index) + "."; 105*cdf0e10cSrcweir oldIndex=index+2; 106*cdf0e10cSrcweir index=aName.indexOf("::", oldIndex); 107*cdf0e10cSrcweir } 108*cdf0e10cSrcweir names[0] += aName.substring(oldIndex); 109*cdf0e10cSrcweir isOpt[0] = xTestedEntry.isOptional; 110*cdf0e10cSrcweir 111*cdf0e10cSrcweir for (int i = 1; i < names.length; i++) { 112*cdf0e10cSrcweir names[i] = methods[i - 1].entryName; 113*cdf0e10cSrcweir isOpt[i] = methods[i - 1].isOptional; 114*cdf0e10cSrcweir } 115*cdf0e10cSrcweir 116*cdf0e10cSrcweir // for reasons of compatibility with JSuite we change the first 117*cdf0e10cSrcweir // character of EntryType to upper case. 118*cdf0e10cSrcweir String eType = xTestedEntry.EntryType; 119*cdf0e10cSrcweir other[0] = eType.toUpperCase().charAt(0)+eType.substring(1); 120*cdf0e10cSrcweir 121*cdf0e10cSrcweir Object params[] = {names, isOpt, other}; 122*cdf0e10cSrcweir 123*cdf0e10cSrcweir try { 124*cdf0e10cSrcweir PropertyValue Res = oBasicHandler.perform("testInterface", params); 125*cdf0e10cSrcweir sResult = (String)Res.Value; 126*cdf0e10cSrcweir } catch (BasicException e) { 127*cdf0e10cSrcweir log.println(e.info); 128*cdf0e10cSrcweir sResult = "SKIPPED.FAILED"; 129*cdf0e10cSrcweir } 130*cdf0e10cSrcweir } else { // if object was not created... 131*cdf0e10cSrcweir sResult = "SKIPPED.FAILED"; 132*cdf0e10cSrcweir } 133*cdf0e10cSrcweir 134*cdf0e10cSrcweir // now tRes has all substates: collect them 135*cdf0e10cSrcweir DescEntry[] subs = xTestedEntry.SubEntries; 136*cdf0e10cSrcweir for (int i = 0; i < subs.length ; i++) { 137*cdf0e10cSrcweir if (sResult.equals("SKIPPED.FAILED")) 138*cdf0e10cSrcweir subs[i].State = "SKIPPED.FAILED"; 139*cdf0e10cSrcweir else if (sResult.equals("SKIPPED.OK")) 140*cdf0e10cSrcweir subs[i].State = "SKIPPED.OK"; 141*cdf0e10cSrcweir else 142*cdf0e10cSrcweir if (tRes.getStatusFor(subs[i].entryName) == null) { 143*cdf0e10cSrcweir subs[i].State = "SKIPPED.FAILED"; 144*cdf0e10cSrcweir } else { 145*cdf0e10cSrcweir subs[i].State = tRes.getStatusFor( 146*cdf0e10cSrcweir subs[i].entryName).toString(); 147*cdf0e10cSrcweir } 148*cdf0e10cSrcweir } 149*cdf0e10cSrcweir 150*cdf0e10cSrcweir xTestedEntry.State = sResult; 151*cdf0e10cSrcweir return null; 152*cdf0e10cSrcweir } 153*cdf0e10cSrcweir 154*cdf0e10cSrcweir /** 155*cdf0e10cSrcweir * Set the result of the method that is tested. 156*cdf0e10cSrcweir * @param methodName The name of the method. 157*cdf0e10cSrcweir * @param bResult The result of the test. 158*cdf0e10cSrcweir */ 159*cdf0e10cSrcweir public void methodTested(String methodName, boolean bResult) { 160*cdf0e10cSrcweir tRes.tested(methodName, bResult); 161*cdf0e10cSrcweir } 162*cdf0e10cSrcweir 163*cdf0e10cSrcweir /** 164*cdf0e10cSrcweir * @return The name of the interface or the service tested. 165*cdf0e10cSrcweir */ 166*cdf0e10cSrcweir String getTestedClassName() { 167*cdf0e10cSrcweir return testName; 168*cdf0e10cSrcweir } 169*cdf0e10cSrcweir } 170