1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 package basicrunner; 28 29 import lib.TestCase; 30 import lib.TestParameters; 31 import lib.TestEnvironment; 32 import share.DescEntry; 33 import share.LogWriter; 34 35 import com.sun.star.uno.XInterface; 36 37 import java.io.PrintWriter; 38 39 import com.sun.star.beans.PropertyValue; 40 41 42 /** 43 * The basic test case. 44 */ 45 public class BasicTestCase extends TestCase { 46 47 /** 48 * Specifies the PrintWriter to log information. 49 */ 50 public PrintWriter oLog; 51 52 /** The name of the test object **/ 53 protected String objName; 54 /** The implementation name of the test object **/ 55 protected String implName; 56 /** A BasicHandler **/ 57 static BasicHandler oBasicHandler = null; 58 59 /** 60 * Constructor with the entry which is to test. 61 * @param entry The description entry. 62 */ 63 public BasicTestCase(DescEntry entry) { 64 this.objName = entry.entryName; 65 this.implName = entry.longName; 66 } 67 68 69 /** 70 * Initialize the test case. 71 * The BasicHandler is talken from the test parameters and several 72 * parameters are initialized. 73 * @param tParam The test parameters. 74 * @param pLog A log writer. 75 */ 76 protected void initialize(TestParameters tParam, PrintWriter pLog) { 77 // Create Handler ONLY here. If SOffice crashes, 78 // no new Handler will be created until new object's initialization. 79 this.oLog = pLog; 80 LogWriter log = (LogWriter)pLog; 81 oBasicHandler = BasicHandlerProvider.getHandler(tParam, log); 82 try { 83 oBasicHandler.perform("setValue", 84 "cBASPath = \"" + tParam.get("BASICRESPTH") + "/\""); 85 oBasicHandler.perform("setValue", 86 "cTestDocsDir = \"" + tParam.get("DOCPTH") + "/\""); 87 oBasicHandler.perform("setValue", 88 "CNCSTR = \"" + tParam.get("CNCSTR") + "\""); 89 if (tParam.get("soapi.test.hidewindows") != null) { 90 oBasicHandler.perform("setValue", 91 "soapi_test_hidewindows = true"); 92 } else { 93 oBasicHandler.perform("setValue", 94 "soapi_test_hidewindows = false"); 95 } 96 //this parameters are used by testcases of db-driver components 97 oBasicHandler.perform("setValue", "dbaseUrl = \"sdbc:dbase:" + 98 tParam.get("dbase.url") + "\""); 99 oBasicHandler.perform("setValue", "flatUrl = \"sdbc:flat:" + 100 tParam.get("flat.url") + "\""); 101 oBasicHandler.perform("setValue", "calcUrl = \"sdbc:calc:" + 102 tParam.get("calc.url") + "\""); 103 oBasicHandler.perform("setValue", "odbcUrl = \"sdbc:odbc:" + 104 tParam.get("odbc.url") + "\""); 105 oBasicHandler.perform("setValue", "jdbcUrl = \"jdbc:" + 106 tParam.get("jdbc.url") + "\""); 107 oBasicHandler.perform("setValue", "jdbcUser = \"" + 108 tParam.get("jdbc.user") + "\""); 109 oBasicHandler.perform("setValue", "jdbcPassword = \"" + 110 tParam.get("jdbc.password") + "\""); 111 oBasicHandler.perform("setValue", "adabasUrl = \"sdbc:adabas:" + 112 tParam.get("adabas.url") + "\""); 113 oBasicHandler.perform("setValue", "adabasUser = \"" + 114 tParam.get("adabas.user") + "\""); 115 oBasicHandler.perform("setValue", "adabasPassword = \"" + 116 tParam.get("adabas.password") + "\""); 117 oBasicHandler.perform("setValue", "adoUrl = \"sdbc:ado:" + 118 tParam.get("ado.url") + "\""); 119 oBasicHandler.perform("setValue", "mozabUrl = \"sdbc:address:" + 120 tParam.get("mozab.url") + "\""); 121 } catch (BasicException e) { 122 log.println(e.info); 123 throw new RuntimeException(e.info); 124 } 125 } 126 127 /** 128 * Create the environment for the test. This is done by BASIC. 129 * @param tParam The test parameters. 130 * @param log A log writer. 131 * @return The test environment 132 */ 133 protected TestEnvironment createTestEnvironment(TestParameters tParam, 134 PrintWriter log) { 135 136 PropertyValue Res; 137 boolean bObjectWasCreated = false; 138 139 try { 140 oBasicHandler.perform("setValue", 141 "cObjectImplementationName = \"" + implName + "\""); 142 Res = oBasicHandler.perform("createObject", objName); 143 bObjectWasCreated = ((Boolean)Res.Value).booleanValue(); 144 145 if (!bObjectWasCreated) { 146 log.println("Couldn't create object"); 147 throw new RuntimeException("Couldn't create object"); 148 } 149 150 } catch (BasicException e) { 151 log.println(e.info); 152 bObjectWasCreated = false; 153 throw new RuntimeException(e.info); 154 } 155 156 TestEnvironment tEnv = new TestEnvironment(new XInterface(){}); 157 tEnv.addObjRelation("objectCreated", new Boolean(bObjectWasCreated)); 158 tEnv.addObjRelation("BasicHandler", oBasicHandler); 159 return tEnv; 160 } 161 162 /** 163 * BASIC is told to dispose the test object. 164 * @param tParam The test parameters. 165 */ 166 167 public void cleanupTestCase(TestParameters tParam) { 168 PropertyValue Res; 169 oLog.println("Cleaning up testcase"); 170 try { 171 Res = oBasicHandler.perform("disposeObject", objName); 172 } catch (BasicException e) { 173 oLog.println(e.info); 174 throw new RuntimeException(e.info); 175 } 176 } 177 178 } 179