Version 3.6.0.4, tag libreoffice-3.6.0.4
[LibreOffice.git] / qadevOOo / runner / lib / TestCase.java
blob6b8b960c3014c0b63288819ba7db31879cb7aad6
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
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.
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).
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.
26 ************************************************************************/
28 package lib;
30 import java.io.PrintWriter;
32 import lib.TestParameters;
33 /**
34 * <code>TestCase</code> represent a factory for <code>TestEnvironment</code>s
35 * creation and disposing for a given implementation object. The
36 * <code>TestEnvironment</code> contains an instance of the implementation
37 * object and all additional objects needed to perform tests on the object.
39 * <p>The <code>TestCase</code> provides four methods for its subclasses to
40 * define its functionality: <code>initialize()</code>, <code>cleanup()</code>,
41 * <code>createTestEnvironment()</code> and <code>disposeTestEnvironment()</code>.
42 * The first two are intended to initialize and cleanup common objects shared
43 * among all instances of <code>TestEnvironment</code> produced by the
44 * <code>TestCase</code>, and they are called at the beginning and at the end of
45 * the <code>TestCase</code> lifecycle accordingly.
47 * <p>The other two are intended to produce and dispose
48 * <code>TestEnvironment</code> instances. The
49 * <code>createTestEnvironment()</code> is called to create a
50 * <code>TestEnvironment</code> instance and the
51 * <code>disposeTestEnvironment()</code> is called when the instane is not used
52 * anymore.
54 * @see lib.TestEnvironment
56 public abstract class TestCase {
58 /**
59 * Specifies the PrintWriter to log information.
61 public PrintWriter log;
63 //public static TestCase tCase;
65 /**
66 * Sets the log to write information during testing.
68 public void setLogWriter( PrintWriter log ) {
69 this.log = log;
72 /**
73 * Initializes the <code>TestCase</code>. Calls <code>initialize()</code>
74 * method.
76 * @param tParam test parameters.
78 public void initializeTestCase( TestParameters tParam ) {
79 initialize( tParam, log );
82 /**
83 * Called while the <code>TestCase</code> initialization. In the
84 * implementation does nothing. Subclasses can override to initialize
85 * objects shared among all <code>TestEnvironment</code>s.
87 * @param tParam test parameters
88 * @param log writer to log information while testing
90 * @see #initializeTestCase()
92 protected void initialize( TestParameters tParam, PrintWriter log ) {
96 /**
97 * Cleans up the <code>TestCase</code>. Calls <code>cleanup()</code>.
99 * @param tParam test parameters
101 public void cleanupTestCase( TestParameters tParam ) {
102 cleanup( tParam, log );
106 * Called while the <code>TestCase</code> cleanup. In the implementation
107 * does nothing. Subclasses can override to cleanup objects shared among
108 * all <code>TestEnvironment</code>s.
110 * @param tParam test parameters
111 * @param log writer to log information while testing
113 * @see #cleanupTestCase
115 protected void cleanup( TestParameters tParam, PrintWriter log ) {
119 * Creates a <code>TestEnvironment</code> containing an instance of the
120 * implementation object and related objects needed to perform test.
122 * @param tParam test parameters
124 * @return the created <code>TestEnvironment</code>
126 * @see #createTestEnvironment()
127 * @see lib.TestEnvironment
129 public synchronized TestEnvironment getTestEnvironment( TestParameters tParam ) {
130 TestEnvironment tEnv = null;
131 try {
132 tEnv = createTestEnvironment( tParam, log );
133 System.out.println("Environment created");
134 if (tEnv != null) {
135 tEnv.setTestCase(this);
137 } catch (Exception e) {
138 String message = e.getMessage();
139 if (message == null)
140 message = e.toString();
141 System.out.println("Exception while getting Environment "+message);
142 e.printStackTrace();
143 cleanup(tParam, log);
145 return tEnv;
149 * Disposes the <code>TestEnvironment</code> when it is not needed anymore.
151 * @param tEnv the environment to dispose
152 * @param tParam test parameters
154 public synchronized void disposeTestEnvironment( TestEnvironment tEnv,
155 TestParameters tParam ) {
156 cleanup( tParam, log );
160 * Called to create an instance of <code>TestEnvironment</code> with an
161 * object to test and related objects. Subclasses should implement this
162 * method to provide the implementation and related objects. The method is
163 * called from <code>getTestEnvironment()</code>.
165 * @param tParam test parameters
166 * @param log writer to log information while testing
168 * @see TestEnvironment
169 * @see #getTestEnvironment()
171 protected abstract TestEnvironment createTestEnvironment(
172 TestParameters tParam, PrintWriter log );
175 * @return the name of the object
177 public String getObjectName() {
178 String clName = this.getClass().getName();
179 return clName.substring( clName.lastIndexOf('.') + 1 );