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