Add more structure constructor tests.
[piglit/hramrach.git] / tests / glean / test.cpp
blob02bd16c519a7f4a9b5d3d20ad185f23d4583888f
1 // BEGIN_COPYRIGHT -*- glean -*-
2 //
3 // Copyright (C) 1999 Allen Akin All Rights Reserved.
4 //
5 // Permission is hereby granted, free of charge, to any person
6 // obtaining a copy of this software and associated documentation
7 // files (the "Software"), to deal in the Software without
8 // restriction, including without limitation the rights to use,
9 // copy, modify, merge, publish, distribute, sublicense, and/or
10 // sell copies of the Software, and to permit persons to whom the
11 // Software is furnished to do so, subject to the following
12 // conditions:
13 //
14 // The above copyright notice and this permission notice shall be
15 // included in all copies or substantial portions of the
16 // Software.
17 //
18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
19 // KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
20 // WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
21 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL ALLEN AKIN BE
22 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
23 // AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
24 // OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25 // DEALINGS IN THE SOFTWARE.
26 //
27 // END_COPYRIGHT
32 // test.cpp: implementation of base class for tests
33 #ifdef __UNIX__
34 #include <unistd.h>
35 #endif
37 #include <iostream>
38 #include "dsconfig.h"
39 #include "dsfilt.h"
40 #include "dsurf.h"
41 #include "winsys.h"
42 #include "environ.h"
43 #include "rc.h"
44 #include "test.h"
46 namespace GLEAN {
48 ///////////////////////////////////////////////////////////////////////////////
49 // Class variables for automatic construction of list of all tests
50 ///////////////////////////////////////////////////////////////////////////////
51 Test* Test::testList; // Guaranteed initialized to zero at startup,
52 // before any constructors are invoked.
53 // (See discussion in section 10.4.9,
54 // page 252, of ``C++ Programming Language''
55 // (third edition).)
57 int Test::testCount; // Also initialized to zero.
59 ///////////////////////////////////////////////////////////////////////////////
60 // Constructor/Destructor:
61 ///////////////////////////////////////////////////////////////////////////////
62 Test::Test(const char* testName, const char *descrip):
63 name(testName), description(descrip) {
64 prereqs = 0;
65 hasRun = false;
66 nextTest = testList;
67 testList = this;
68 ++testCount;
69 } // Test::Test()
71 Test::Test(const char* testName, const char *descrip, Test** thePrereqs):
72 name(testName), description(descrip) {
73 prereqs = thePrereqs;
74 hasRun = false;
75 nextTest = testList;
76 testList = this;
77 ++testCount;
78 } // Test::Test()
80 Test::~Test() {
81 } // Test::~Test
83 ///////////////////////////////////////////////////////////////////////////////
84 // Stream opening utilities for results databases
85 ///////////////////////////////////////////////////////////////////////////////
87 Test::OutputStream::OutputStream(Test& t) {
88 s = new ofstream(t.env->resultFileName(t.name).c_str());
89 if (!*s)
90 throw Test::CantOpenResultsFile(t.name, t.env->options.db1Name);
91 } // Test::OutputStream::OutputStream
93 Test::OutputStream::~OutputStream() {
94 s->close();
95 delete s;
96 } // Test::OutputStream::~OutputStream
98 Test::OutputStream::operator ofstream& () {
99 return *s;
100 } // Test::OutputStream::operator ::ofstream&
102 Test::Input1Stream::Input1Stream(Test& t) {
103 s = new ifstream(t.env->resultFileName(
104 t.env->options.db1Name, t.name).c_str());
105 if (!*s)
106 throw Test::CantOpenResultsFile(t.name, t.env->options.db1Name);
107 } // Test::Input1Stream::Input1Stream
109 Test::Input1Stream::~Input1Stream() {
110 s->close();
111 delete s;
112 } // Test::Input1Stream::~Input1Stream
114 Test::Input1Stream::operator ifstream& () {
115 return *s;
116 } // Test::Input1Stream::operator ::ifstream&
118 Test::Input2Stream::Input2Stream(Test& t) {
119 s = new ifstream(t.env->resultFileName(
120 t.env->options.db2Name, t.name).c_str());
121 if (!*s)
122 throw Test::CantOpenResultsFile(t.name, t.env->options.db2Name);
123 } // Test::Input2Stream::Input2Stream
125 Test::Input2Stream::~Input2Stream() {
126 s->close();
127 delete s;
128 } // Test::Input2Stream::~Input2Stream
130 Test::Input2Stream::operator ifstream& () {
131 return *s;
132 } // Test::Input2Stream::operator ::ifstream&
134 } // namespace GLEAN