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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
|
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* $URL$
* $Id$
*/
#ifndef TESTBED_TESTSUITE_H
#define TESTBED_TESTSUITE_H
#include "common/system.h"
#include "common/str.h"
#include "common/array.h"
namespace Testbed {
enum {
kColorBlack = 0,
kColorWhite = 1,
kColorCustom = 2
};
enum OptionSelected {
kOptionLeft = 1,
kOptionRight = 0
};
enum {
kEngineQuit = 0,
kSkipNext = 1,
kLoopNormal = 2,
// Event handling time,(in ms) used in parseEvent()
kEventHandlingTime = 50
};
typedef bool (*InvokingFunction)();
/**
* This represents a feature to be tested
*/
struct Test {
Test(Common::String name, InvokingFunction f, bool interactive) : featureName(name) {
driver = f;
enabled = true;
passed = false;
isInteractive = interactive;
}
const Common::String featureName; ///< Name of feature to be tested
InvokingFunction driver; ///< Pointer to the function that will invoke this feature test
bool enabled; ///< Decides whether or not this test is to be executed
bool passed; ///< Collects and stores result of this feature test
bool isInteractive; ///< Decides if the test is interactive or not, An interactive testsuite may have non-interactive tests, hence this change.
};
/**
* The basic Testsuite class
* All the other testsuites would inherit it and override its virtual methods
*/
class Testsuite {
public:
Testsuite();
virtual ~Testsuite();
int getNumTests() const { return _testsToExecute.size(); }
int getNumTestsPassed() const { return _numTestsPassed; }
int getNumTestsFailed() const { return _numTestsExecuted - _numTestsPassed; }
void genReport() const;
bool isEnabled() const { return _isTsEnabled; }
virtual void enable(bool flag) {
_isTsEnabled = flag;
}
/**
* Prompts for User Input in form of "Yes" or "No" for interactive tests
* e.g: "Is this like you expect?" "Yes" or "No"
*
* @param textToDisplay Display text
* @return true if "Yes" false otherwise
*/
static bool handleInteractiveInput(const Common::String &textToDisplay, const char *opt1 = "Yes", const char *opt2 = "No", OptionSelected result = kOptionLeft);
static void displayMessage(const Common::String &textToDisplay, const char *defaultButton = "OK", const char *altButton = 0);
static Common::Rect writeOnScreen(const Common::String &textToDisplay, const Common::Point &pt, bool flag = false);
static void clearScreen(const Common::Rect &rect);
static void clearScreen();
static void clearScreen(bool flag);
/**
* Adds a test to the list of tests to be executed
*
* @param name the string description of the test, for display purposes
* @param f pointer to the function that invokes this test
* @param isInteractive decides if the test is to be executed in interactive mode/ default true
*/
void addTest(const Common::String &name, InvokingFunction f, bool isInteractive = true);
/**
* The driver function for the testsuite
* All code should go in here.
*/
virtual void execute();
static uint parseEvents();
virtual const char *getName() const = 0;
virtual const char *getDescription() const = 0;
static void logPrintf(const char *s, ...) GCC_PRINTF(1, 2);
static void logDetailedPrintf(const char *s, ...) GCC_PRINTF(1, 2);
/**
* Note: To enable logging, this function must be called once first.
*/
static void initLogging(const char *dirname, const char *filename, bool enable = true);
static void initLogging(bool enable = true);
static void setLogDir(const char *dirname);
static void setLogFile(const char *filename);
static void deleteWriteStream();
protected:
Common::Array<Test *> _testsToExecute; ///< List of tests to be executed
int _numTestsPassed; ///< Number of tests passed
int _numTestsExecuted; ///< Number of tests executed
bool _isTsEnabled;
public:
/**
* Static variable of this class that determines if the user initiated testing session is interactive or not.
* Used by various tests to respond accordingly
*/
static bool isSessionInteractive;
/**
* Used from the code to decide if the engine needs to exit
*/
static uint toQuit;
private:
/**
* Private variables related to logging files
*/
static Common::String _logDirectory;
static Common::String _logFilename;
static Common::WriteStream *_ws;
};
} // End of namespace Testbed
#endif // TESTBED_TESTSUITE_H
|