ScummVM API documentation
testsuite.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef TESTBED_TESTSUITE_H
23 #define TESTBED_TESTSUITE_H
24 
25 #include "common/array.h"
26 #include "common/rect.h"
27 #include "common/scummsys.h"
28 #include "common/system.h"
29 #include "common/str.h"
30 #include "graphics/font.h"
31 
32 #include "graphics/fontman.h"
33 
34 #include "testbed/config-params.h"
35 
36 namespace Testbed {
37 
38 enum {
39  kColorBlack = 0,
40  kColorWhite = 1,
41  kColorCustom = 2,
42  kColorSpecial = 5
43 };
44 
45 enum OptionSelected {
46  kOptionLeft = 0,
47  kOptionRight = 1
48 };
49 
50 enum {
51  kEngineQuit = 0,
52  kSkipNext = 1,
53  kLoopNormal = 2,
54  // Event handling time,(in ms) used in parseEvent()
55  kEventHandlingTime = 50
56 };
57 
58 enum TestExitStatus {
59  kTestPassed = 0,
60  kTestSkipped,
61  kTestFailed
62 };
63 
64 typedef TestExitStatus (*InvokingFunction)();
65 
70 struct Test {
71  Test(Common::String name, InvokingFunction f, bool interactive) : featureName(name) {
72  driver = f;
73  enabled = true;
74  passed = false;
75  isInteractive = interactive;
76  }
78  InvokingFunction driver;
79  bool enabled;
80  bool passed;
82 };
83 
84 
90 class Testsuite {
91 public:
92  Testsuite();
93  virtual ~Testsuite();
94  int getNumTests() const { return _testsToExecute.size(); }
95  int getNumTestsPassed() const { return _numTestsPassed; }
96  int getNumTestsSkipped() const { return _numTestsSkipped; }
97  int getNumTestsFailed() const { return _numTestsExecuted - _numTestsPassed; }
98  void genReport() const;
99  bool isEnabled() const { return _isTsEnabled; }
100  virtual void enable(bool flag) {
101  _isTsEnabled = flag;
102  }
103  bool enableTest(const Common::String &testName, bool enable);
104  void reset();
105 
113  static bool handleInteractiveInput(const Common::String &textToDisplay, const char *opt1 = "Yes", const char *opt2 = "No", OptionSelected result = kOptionLeft);
114 
115  static void displayMessage(const Common::String &textToDisplay, const char *defaultButton = "OK");
116  static Common::Rect writeOnScreen(const Common::String &textToDisplay, const Common::Point &pt, bool flag = false);
117  static void clearScreen(const Common::Rect &rect);
118  static void clearEntireScreen() {
119  const int width = g_system->getWidth();
120  const int height = g_system->getHeight();
121  Common::Rect r(0, 0, width, height);
122  clearScreen(r);
123  }
124  static void clearScreen();
125  static void clearScreen(bool flag);
126 
134  void addTest(const Common::String &name, InvokingFunction f, bool isInteractive = true);
135 
139  virtual void prepare() {}
140 
145  virtual void execute();
146  static uint parseEvents();
147 
148  virtual const char *getName() const = 0;
149  virtual const char *getDescription() const = 0;
150 
151  static void logPrintf(MSVC_PRINTF const char *s, ...) GCC_PRINTF(1, 2);
152  static void logDetailedPrintf(MSVC_PRINTF const char *s, ...) GCC_PRINTF(1, 2);
153 
154  // Progress bar (Information Display) related methods.
164  Common::Point pt(0, 0);
165  // start from bottom
166  pt.y = g_system->getHeight();
167  // Will Contain 3 lines
168  pt.y -= (FontMan.getFontByUsage(ConfParams.getCurrentFontUsageType())->getFontHeight() * 3 + 15); // Buffer of 5 pixels per line
169  return pt;
170  }
171 
172  static uint getLineSeparation() {
173  return FontMan.getFontByUsage(ConfParams.getCurrentFontUsageType())->getFontHeight() + 5;
174  }
175 
176  static void updateStats(const char *prefix, const char *info, uint numTests, uint testNum, Common::Point pt);
177  const Common::Array<Test *>& getTestList() { return _testsToExecute; }
178  int getNumTestsEnabled();
179 
180 protected:
184  int _numTestsSkipped;
185  bool _isTsEnabled;
186 
187 private:
188 
192  uint _toQuit;
193 };
194 
195 } // End of namespace Testbed
196 
197 #endif // TESTBED_TESTSUITE_H
Definition: str.h:59
Definition: array.h:52
#define FontMan
Definition: fontman.h:127
Definition: rect.h:144
bool enabled
Decides whether or not this test is to be executed.
Definition: testsuite.h:79
Definition: cloud.h:30
InvokingFunction driver
Pointer to the function that will invoke this feature test.
Definition: testsuite.h:78
Definition: testsuite.h:70
int _numTestsPassed
Number of tests passed.
Definition: testsuite.h:182
virtual int16 getHeight()=0
OSystem * g_system
virtual void prepare()
Definition: testsuite.h:139
Definition: testsuite.h:90
int FORCEINLINE GCC_PRINTF(2, 0) int vsprintf_s(T(&dst)[N]
bool isInteractive
Decides if the test is interactive or not, An interactive testsuite may have non-interactive tests...
Definition: testsuite.h:81
const Common::String featureName
Name of feature to be tested.
Definition: testsuite.h:77
virtual int16 getWidth()=0
Definition: rect.h:45
static void static void static Common::Point getDisplayRegionCoordinates()
Definition: testsuite.h:163
int _numTestsExecuted
Number of tests executed.
Definition: testsuite.h:183
Common::Array< Test * > _testsToExecute
List of tests to be executed.
Definition: testsuite.h:181
int16 y
Definition: rect.h:47
bool passed
Collects and stores result of this feature test.
Definition: testsuite.h:80