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.TestCase;
26 import lib.TestParameters;
27 import lib.TestEnvironment;
28 import share.DescEntry;
29 import share.LogWriter;
30 
31 import com.sun.star.uno.XInterface;
32 
33 import java.io.PrintWriter;
34 
35 import com.sun.star.beans.PropertyValue;
36 
37 
38 /**
39  * The basic test case.
40  */
41 public class BasicTestCase extends TestCase {
42 
43     /**
44      * Specifies the PrintWriter to log information.
45      */
46     public PrintWriter oLog;
47 
48     /** The name of the test object **/
49     protected String objName;
50     /** The implementation name of the test object **/
51     protected String implName;
52     /** A BasicHandler **/
53     static BasicHandler oBasicHandler = null;
54 
55     /**
56      * Constructor with the entry which is to test.
57      * @param entry The description entry.
58      */
59     public BasicTestCase(DescEntry entry) {
60         this.objName = entry.entryName;
61         this.implName = entry.longName;
62     }
63 
64 
65     /**
66      * Initialize the test case.
67      * The BasicHandler is talken from the test parameters and several
68      * parameters are initialized.
69      * @param tParam The test parameters.
70      * @param pLog A log writer.
71      */
72     protected void initialize(TestParameters tParam, PrintWriter pLog) {
73         // Create Handler ONLY here. If SOffice crashes,
74         // no new Handler will be created until new object's initialization.
75         this.oLog = pLog;
76         LogWriter log = (LogWriter)pLog;
77         oBasicHandler = BasicHandlerProvider.getHandler(tParam, log);
78         try {
79             oBasicHandler.perform("setValue",
80                         "cBASPath = \"" + tParam.get("BASICRESPTH") + "/\"");
81             oBasicHandler.perform("setValue",
82                         "cTestDocsDir = \"" + tParam.get("DOCPTH") + "/\"");
83             oBasicHandler.perform("setValue",
84                         "CNCSTR = \"" + tParam.get("CNCSTR") + "\"");
85             if (tParam.get("soapi.test.hidewindows") != null) {
86               oBasicHandler.perform("setValue",
87                         "soapi_test_hidewindows = true");
88             } else {
89               oBasicHandler.perform("setValue",
90                         "soapi_test_hidewindows = false");
91             }
92             //this parameters are used by testcases of db-driver components
93             oBasicHandler.perform("setValue", "dbaseUrl = \"sdbc:dbase:" +
94                 tParam.get("dbase.url") + "\"");
95             oBasicHandler.perform("setValue", "flatUrl = \"sdbc:flat:" +
96                 tParam.get("flat.url") + "\"");
97             oBasicHandler.perform("setValue", "calcUrl = \"sdbc:calc:" +
98                 tParam.get("calc.url") + "\"");
99             oBasicHandler.perform("setValue", "odbcUrl = \"sdbc:odbc:" +
100                 tParam.get("odbc.url") + "\"");
101             oBasicHandler.perform("setValue", "jdbcUrl = \"jdbc:" +
102                 tParam.get("jdbc.url") + "\"");
103             oBasicHandler.perform("setValue", "jdbcUser = \"" +
104                 tParam.get("jdbc.user") + "\"");
105             oBasicHandler.perform("setValue", "jdbcPassword = \"" +
106                 tParam.get("jdbc.password") + "\"");
107             oBasicHandler.perform("setValue", "adabasUrl = \"sdbc:adabas:" +
108                 tParam.get("adabas.url") + "\"");
109             oBasicHandler.perform("setValue", "adabasUser = \"" +
110                 tParam.get("adabas.user") + "\"");
111             oBasicHandler.perform("setValue", "adabasPassword = \"" +
112                 tParam.get("adabas.password") + "\"");
113             oBasicHandler.perform("setValue", "adoUrl = \"sdbc:ado:" +
114                 tParam.get("ado.url") + "\"");
115             oBasicHandler.perform("setValue", "mozabUrl = \"sdbc:address:" +
116                 tParam.get("mozab.url") + "\"");
117         } catch (BasicException e) {
118             log.println(e.info);
119             throw new RuntimeException(e.info);
120         }
121     }
122 
123     /**
124      * Create the environment for the test. This is done by BASIC.
125      * @param tParam The test parameters.
126      * @param log A log writer.
127      * @return The test environment
128      */
129     protected TestEnvironment createTestEnvironment(TestParameters tParam,
130                                                           PrintWriter log) {
131 
132         PropertyValue Res;
133         boolean bObjectWasCreated = false;
134 
135         try {
136             oBasicHandler.perform("setValue",
137                         "cObjectImplementationName = \"" + implName + "\"");
138             Res = oBasicHandler.perform("createObject", objName);
139             bObjectWasCreated = ((Boolean)Res.Value).booleanValue();
140 
141             if (!bObjectWasCreated) {
142                 log.println("Couldn't create object");
143                 throw new RuntimeException("Couldn't create object");
144             }
145 
146         } catch (BasicException e) {
147             log.println(e.info);
148             bObjectWasCreated = false;
149             throw new RuntimeException(e.info);
150         }
151 
152         TestEnvironment tEnv = new TestEnvironment(new XInterface(){});
153         tEnv.addObjRelation("objectCreated", new Boolean(bObjectWasCreated));
154         tEnv.addObjRelation("BasicHandler", oBasicHandler);
155         return tEnv;
156     }
157 
158     /**
159      * BASIC is told to dispose the test object.
160      * @param tParam The test parameters.
161      */
162 
163     public void cleanupTestCase(TestParameters tParam) {
164         PropertyValue Res;
165         oLog.println("Cleaning up testcase");
166         try {
167             Res = oBasicHandler.perform("disposeObject", objName);
168         } catch (BasicException e) {
169             oLog.println(e.info);
170             throw new RuntimeException(e.info);
171         }
172     }
173 
174 }
175