update dev300-m58
[ooovba.git] / qadevOOo / runner / lib / TestCase.java
blob5d9ca489cc6a919e220e57708e878fddb8598809
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: TestCase.java,v $
10 * $Revision: 1.5 $
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 ************************************************************************/
31 package lib;
33 import java.io.PrintWriter;
35 import lib.TestParameters;
36 /**
37 * <code>TestCase</code> represent a factory for <code>TestEnvironment</code>s
38 * creation and disposing for a given implementation object. The
39 * <code>TestEnvironment</code> contains an instance of the implementation
40 * object and all additional objects needed to perform tests on the object.
42 * <p>The <code>TestCase</code> provides four methods for its subclasses to
43 * define its functionality: <code>initialize()</code>, <code>cleanup()</code>,
44 * <code>createTestEnvironment()</code> and <code>disposeTestEnvironment()</code>.
45 * The first two are intended to initialize and cleanup common objects shared
46 * among all instances of <code>TestEnvironment</code> produced by the
47 * <code>TestCase</code>, and they are called at the beginning and at the end of
48 * the <code>TestCase</code> lifecycle accordingly.
50 * <p>The other two are intended to produce and dispose
51 * <code>TestEnvironment</code> instances. The
52 * <code>createTestEnvironment()</code> is called to create a
53 * <code>TestEnvironment</code> instance and the
54 * <code>disposeTestEnvironment()</code> is called when the instane is not used
55 * anymore.
57 * @see lib.TestEnvironment
59 public abstract class TestCase {
61 /**
62 * Specifies the PrintWriter to log information.
64 public PrintWriter log;
66 //public static TestCase tCase;
68 /**
69 * Sets the log to write information during testing.
71 public void setLogWriter( PrintWriter log ) {
72 this.log = log;
75 /**
76 * Initializes the <code>TestCase</code>. Calls <code>initialize()</code>
77 * method.
79 * @param tParam test parameters.
81 public void initializeTestCase( TestParameters tParam ) {
82 initialize( tParam, log );
85 /**
86 * Called while the <code>TestCase</code> initialization. In the
87 * implementation does nothing. Subclasses can override to initialize
88 * objects shared among all <code>TestEnvironment</code>s.
90 * @param tParam test parameters
91 * @param log writer to log information while testing
93 * @see #initializeTestCase()
95 protected void initialize( TestParameters tParam, PrintWriter log ) {
99 /**
100 * Cleans up the <code>TestCase</code>. Calls <code>cleanup()</code>.
102 * @param tParam test parameters
104 public void cleanupTestCase( TestParameters tParam ) {
105 cleanup( tParam, log );
109 * Called while the <code>TestCase</code> cleanup. In the implementation
110 * does nothing. Subclasses can override to cleanup objects shared among
111 * all <code>TestEnvironment</code>s.
113 * @param tParam test parameters
114 * @param log writer to log information while testing
116 * @see #cleanupTestCase
118 protected void cleanup( TestParameters tParam, PrintWriter log ) {
122 * Creates a <code>TestEnvironment</code> containing an instance of the
123 * implementation object and related objects needed to perform test.
125 * @param tParam test parameters
127 * @return the created <code>TestEnvironment</code>
129 * @see #createTestEnvironment()
130 * @see lib.TestEnvironment
132 public synchronized TestEnvironment getTestEnvironment( TestParameters tParam ) {
133 TestEnvironment tEnv = null;
134 try {
135 tEnv = createTestEnvironment( tParam, log );
136 System.out.println("Environment created");
137 if (tEnv != null) {
138 tEnv.setTestCase(this);
140 } catch (Exception e) {
141 String message = e.getMessage();
142 if (message == null)
143 message = e.toString();
144 System.out.println("Exception while getting Environment "+message);
145 e.printStackTrace();
147 return tEnv;
151 * Disposes the <code>TestEnvironment</code> when it is not needed anymore.
152 * The method calls <code>cleanupTestEnvironment()</code>.
154 * @param tEnv the environment to dispose
155 * @param tParam test parameters
157 * @see #cleanupTestEnvironment()
159 public synchronized void disposeTestEnvironment( TestEnvironment tEnv,
160 TestParameters tParam ) {
161 cleanup( tParam, log );
165 * Called to create an instance of <code>TestEnvironment</code> with an
166 * object to test and related objects. Subclasses should implement this
167 * method to provide the implementation and related objects. The method is
168 * called from <code>getTestEnvironment()</code>.
170 * @param tParam test parameters
171 * @param log writer to log information while testing
173 * @see TestEnvironment
174 * @see #getTestEnvironment()
176 protected abstract TestEnvironment createTestEnvironment(
177 TestParameters tParam, PrintWriter log );
180 * Called while disposing a <code>TestEnvironment</code>. In the
181 * implementation does nothing. Subclasses can override to clean up
182 * the environments created by them.
184 * @param tParam test parameters
185 * @param tEnv the environment to cleanup
186 * @param log writer to log information while testing
188 * @see TestEnvironment
189 * @see #disposeTestEnvironment()
191 protected void cleanupTestEnvironment( TestParameters Param,
192 TestEnvironment tEnv, PrintWriter log ) {
196 * @return the name of the object
198 public String getObjectName() {
199 String clName = this.getClass().getName();
200 return clName.substring( clName.lastIndexOf('.') + 1 );