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 enum WriteFlags {
65  kWriteNoFlag = 0,
66  kWriteRGBColors = (1 << 0),
67  kWriteDrawFrame = (1 << 1)
68 };
69 
70 typedef TestExitStatus (*InvokingFunction)();
71 
76 struct Test {
77  Test(Common::String name, InvokingFunction f, bool interactive) : featureName(name) {
78  driver = f;
79  enabled = true;
80  passed = false;
81  isInteractive = interactive;
82  }
84  InvokingFunction driver;
85  bool enabled;
86  bool passed;
88 };
89 
90 
96 class Testsuite {
97 public:
98  Testsuite();
99  virtual ~Testsuite();
100  int getNumTests() const { return _testsToExecute.size(); }
101  int getNumTestsPassed() const { return _numTestsPassed; }
102  int getNumTestsSkipped() const { return _numTestsSkipped; }
103  int getNumTestsFailed() const { return _numTestsExecuted - _numTestsPassed; }
104  void genReport() const;
105  bool isEnabled() const { return _isTsEnabled; }
106  virtual void enable(bool flag) {
107  _isTsEnabled = flag;
108  }
109  bool enableTest(const Common::String &testName, bool enable);
110  void reset();
111 
119  static bool handleInteractiveInput(const Common::String &textToDisplay, const char *opt1 = "Yes", const char *opt2 = "No", OptionSelected result = kOptionLeft);
120 
121  static void displayMessage(const Common::String &textToDisplay, const char *defaultButton = "OK");
122  static Common::Rect writeOnScreen(const Common::String &textToDisplay, const Common::Point &pt, WriteFlags flag = kWriteNoFlag);
123  static void clearScreen(const Common::Rect &rect);
124  static void clearEntireScreen() {
125  const int width = g_system->getWidth();
126  const int height = g_system->getHeight();
127  Common::Rect r(0, 0, width, height);
128  clearScreen(r);
129  }
130  static void clearScreen();
131  static void clearScreen(bool flag);
132 
140  void addTest(const Common::String &name, InvokingFunction f, bool isInteractive = true);
141 
145  virtual void prepare() {}
146 
151  virtual void execute();
152  static uint parseEvents();
153 
154  virtual const char *getName() const = 0;
155  virtual const char *getDescription() const = 0;
156 
157  static void logPrintf(MSVC_PRINTF const char *s, ...) GCC_PRINTF(1, 2);
158  static void logDetailedPrintf(MSVC_PRINTF const char *s, ...) GCC_PRINTF(1, 2);
159 
160  // Progress bar (Information Display) related methods.
170  Common::Point pt(0, 0);
171  // start from bottom
172  pt.y = g_system->getHeight();
173  // Will Contain 3 lines
174  pt.y -= (FontMan.getFontByUsage(ConfParams.getCurrentFontUsageType())->getFontHeight() * 3 + 15); // Buffer of 5 pixels per line
175  return pt;
176  }
177 
178  static uint getLineSeparation() {
179  return FontMan.getFontByUsage(ConfParams.getCurrentFontUsageType())->getFontHeight() + 5;
180  }
181 
182  static void updateStats(const char *prefix, const char *info, uint numTests, uint testNum, Common::Point pt);
183  const Common::Array<Test *>& getTestList() { return _testsToExecute; }
184  int getNumTestsEnabled();
185 
186 protected:
190  int _numTestsSkipped;
191  bool _isTsEnabled;
192 
193 private:
194 
198  uint _toQuit;
199 };
200 
201 } // End of namespace Testbed
202 
203 #endif // TESTBED_TESTSUITE_H
Definition: str.h:59
Definition: array.h:52
#define FontMan
Definition: fontman.h:135
Definition: rect.h:524
bool enabled
Decides whether or not this test is to be executed.
Definition: testsuite.h:85
Definition: cloud.h:30
InvokingFunction driver
Pointer to the function that will invoke this feature test.
Definition: testsuite.h:84
Definition: testsuite.h:76
int _numTestsPassed
Number of tests passed.
Definition: testsuite.h:188
virtual int16 getHeight()=0
OSystem * g_system
virtual void prepare()
Definition: testsuite.h:145
Definition: testsuite.h:96
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:87
const Common::String featureName
Name of feature to be tested.
Definition: testsuite.h:83
T y
Definition: rect.h:49
virtual int16 getWidth()=0
Definition: rect.h:144
static void static void static Common::Point getDisplayRegionCoordinates()
Definition: testsuite.h:169
int _numTestsExecuted
Number of tests executed.
Definition: testsuite.h:189
Common::Array< Test * > _testsToExecute
List of tests to be executed.
Definition: testsuite.h:187
bool passed
Collects and stores result of this feature test.
Definition: testsuite.h:86