aboutsummaryrefslogtreecommitdiff
path: root/tests/glean/test.h
blob: 540faacdcb5595c77aa35ecf344dc2a64035e993 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
// BEGIN_COPYRIGHT -*- glean -*-
// 
// Copyright (C) 1999  Allen Akin   All Rights Reserved.
// 
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
// 
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the
// Software.
// 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
// KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
// WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL ALLEN AKIN BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
// AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
// OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
// 
// END_COPYRIGHT




// test.h:  Base class for all tests

// This class encapsulates base functionality used by all tests.  Some
// of this is fairly trivial (the test name, for example).  One of the
// most important nontrivial functions is the use of the constructor
// to build a linked list of test objects; this eliminates the need to
// maintain a separate table of tests.  This class also provides a
// flag for determining if a test has been run, which allows tests to
// invoke one another and make use of previous results without forcing
// tests to run multiple times.  Finally, it provides a basic
// framework for recording a vector of results (which typically will
// vary depending on the drawing surface configuration or the
// particular type of drawing surface used).

// It is possible to derive test classes directly from this class. 
// Most people will find it more convenient to use the BaseTest
// template class.  See tbase.h for more information.



#ifndef __test_h__
#define __test_h__

using namespace std;

#include <string>
#include <vector>
#include <fstream>

namespace GLEAN {

class Environment;		// Mutually-recursive and forward references.
class DrawingSurfaceConfig;

// Base class for a single test result.  A test may have many results
// (for example, one per drawing surface configuration), so in general
// individual tests will have a vector of these objects.
class Result {
public:
	virtual void put(ostream& s) const = 0;
	virtual bool get(istream& s) = 0;
	Result() { }
	virtual ~Result() { }
};

class Test {
    public:
	Test(const char* testName, const char *descrip);
	Test(const char* testName, const char *descrip, Test** prereqs);
	virtual ~Test();

	string name;		// Test name.  Should avoid characters
				// that aren't universally available in
				// filenames, since it might be used to
				// construct such names.

	string description;	// Verbose description of test.

	Test** prereqs;		// Pointer to array of prerequisite tests.
				// These will always be run before the
				// current test.
	
	bool hasRun;		// True if test has been run.

	Environment* env;	// Environment in which runs or comparisons
				// will be performed.

	virtual void run(Environment& env) = 0;	// Run test, save results.

	// Exceptions:
	struct Error { };	// Base class for all exceptions.

	static Test* testList;	// List of all test objects.  Built by
				// constructor Test::Test(...).

	Test* nextTest;		// Link to next test object.

	static int testCount;	// Count of elements in testList.
}; // class Test

} // namespace GLEAN

#endif // __test_h__