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      */
BasicTestCase(DescEntry entry)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      */
initialize(TestParameters tParam, PrintWriter pLog)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         } catch (BasicException e) {
116             log.println(e.info);
117             throw new RuntimeException(e.info);
118         }
119     }
120 
121     /**
122      * Create the environment for the test. This is done by BASIC.
123      * @param tParam The test parameters.
124      * @param log A log writer.
125      * @return The test environment
126      */
createTestEnvironment(TestParameters tParam, PrintWriter log)127     protected TestEnvironment createTestEnvironment(TestParameters tParam,
128                                                           PrintWriter log) {
129 
130         PropertyValue Res;
131         boolean bObjectWasCreated = false;
132 
133         try {
134             oBasicHandler.perform("setValue",
135                         "cObjectImplementationName = \"" + implName + "\"");
136             Res = oBasicHandler.perform("createObject", objName);
137             bObjectWasCreated = ((Boolean)Res.Value).booleanValue();
138 
139             if (!bObjectWasCreated) {
140                 log.println("Couldn't create object");
141                 throw new RuntimeException("Couldn't create object");
142             }
143 
144         } catch (BasicException e) {
145             log.println(e.info);
146             bObjectWasCreated = false;
147             throw new RuntimeException(e.info);
148         }
149 
150         TestEnvironment tEnv = new TestEnvironment(new XInterface(){});
151         tEnv.addObjRelation("objectCreated", new Boolean(bObjectWasCreated));
152         tEnv.addObjRelation("BasicHandler", oBasicHandler);
153         return tEnv;
154     }
155 
156     /**
157      * BASIC is told to dispose the test object.
158      * @param tParam The test parameters.
159      */
160 
cleanupTestCase(TestParameters tParam)161     public void cleanupTestCase(TestParameters tParam) {
162         PropertyValue Res;
163         oLog.println("Cleaning up testcase");
164         try {
165             Res = oBasicHandler.perform("disposeObject", objName);
166         } catch (BasicException e) {
167             oLog.println(e.info);
168             throw new RuntimeException(e.info);
169         }
170     }
171 
172 }
173