bump product version to 4.1.6.2
[LibreOffice.git] / qadevOOo / runner / lib / TestCase.java
bloba4895f13c4cec1f04ea9baa5a0d8d8f27af8d3f9
1 /*
2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 package lib;
21 import java.io.PrintWriter;
22 import lib.TestParameters;
24 /**
25 * <code>TestCase</code> represent a factory for <code>TestEnvironment</code>s
26 * creation and disposing for a given implementation object. The
27 * <code>TestEnvironment</code> contains an instance of the implementation
28 * object and all additional objects needed to perform tests on the object.
30 * <p>The <code>TestCase</code> provides four methods for its subclasses to
31 * define its functionality: <code>initialize()</code>, <code>cleanup()</code>,
32 * <code>createTestEnvironment()</code> and <code>disposeTestEnvironment()</code>.
33 * The first two are intended to initialize and cleanup common objects shared
34 * among all instances of <code>TestEnvironment</code> produced by the
35 * <code>TestCase</code>, and they are called at the beginning and at the end of
36 * the <code>TestCase</code> lifecycle accordingly.
38 * <p>The other two are intended to produce and dispose
39 * <code>TestEnvironment</code> instances. The
40 * <code>createTestEnvironment()</code> is called to create a
41 * <code>TestEnvironment</code> instance and the
42 * <code>disposeTestEnvironment()</code> is called when the instane is not used
43 * anymore.
45 * @see lib.TestEnvironment
47 public abstract class TestCase {
49 /**
50 * Specifies the PrintWriter to log information.
52 protected PrintWriter log;
54 /**
55 * Sets the log to write information during testing.
57 public void setLogWriter( PrintWriter log ) {
58 this.log = log;
61 /**
62 * Initializes the <code>TestCase</code>. Calls <code>initialize()</code>
63 * method.
65 * @param tParam test parameters.
67 public final void initializeTestCase( TestParameters tParam ) {
68 initialize( tParam, log );
71 /**
72 * Called while the <code>TestCase</code> initialization. In the
73 * implementation does nothing. Subclasses can override to initialize
74 * objects shared among all <code>TestEnvironment</code>s.
76 * @param tParam test parameters
77 * @param log writer to log information while testing
79 * @see #initializeTestCase
81 protected void initialize( TestParameters tParam, PrintWriter log ) {
85 /**
86 * Cleans up the <code>TestCase</code>. Calls <code>cleanup()</code>.
88 * @param tParam test parameters
90 public final void cleanupTestCase( TestParameters tParam ) {
91 cleanup( tParam, log );
94 /**
95 * Called while the <code>TestCase</code> cleanup. In the implementation
96 * does nothing. Subclasses can override to cleanup objects shared among
97 * all <code>TestEnvironment</code>s.
99 * @param tParam test parameters
100 * @param log writer to log information while testing
102 * @see #cleanupTestCase
104 protected void cleanup( TestParameters tParam, PrintWriter log ) {
108 * Creates a <code>TestEnvironment</code> containing an instance of the
109 * implementation object and related objects needed to perform test.
111 * @param tParam test parameters
113 * @return the created <code>TestEnvironment</code>
115 * @see #createTestEnvironment
116 * @see lib.TestEnvironment
118 public synchronized TestEnvironment getTestEnvironment( TestParameters tParam ) {
119 TestEnvironment tEnv = null;
120 try {
121 tEnv = createTestEnvironment( tParam, log );
122 System.out.println("Environment created");
123 if (tEnv != null) {
124 tEnv.setTestCase(this);
126 } catch (Exception e) {
127 String message = e.getMessage();
128 if (message == null)
129 message = e.toString();
130 System.out.println("Exception while getting Environment "+message);
131 e.printStackTrace();
132 cleanup(tParam, log);
134 return tEnv;
138 * Disposes the <code>TestEnvironment</code> when it is not needed anymore.
140 * @param tEnv the environment to dispose
141 * @param tParam test parameters
143 public synchronized void disposeTestEnvironment( TestEnvironment tEnv,
144 TestParameters tParam ) {
145 cleanup( tParam, log );
149 * Called to create an instance of <code>TestEnvironment</code> with an
150 * object to test and related objects. Subclasses should implement this
151 * method to provide the implementation and related objects. The method is
152 * called from <code>getTestEnvironment()</code>.
154 * @param tParam test parameters
155 * @param log writer to log information while testing
157 * @see TestEnvironment
158 * @see #getTestEnvironment
160 protected abstract TestEnvironment createTestEnvironment(
161 TestParameters tParam, PrintWriter log );
164 * @return the name of the object
166 public String getObjectName() {
167 String clName = this.getClass().getName();
168 return clName.substring( clName.lastIndexOf('.') + 1 );