Dayz Explorer 1.28.160049
Loading...
Searching...
No Matches
testingframework.c
Go to the documentation of this file.
1
94//-----------------------------------------------------------------------------
96class Test
97{
98 string Suite;
99
100 int TimeoutS;
101 int TimeoutMs;
102 int SortOrder;
103
105 void Test(string suite, int timeoutS = 0, int timeoutMs = 0, int sortOrder = 0)
106 {
107 Suite = suite;
108 TimeoutS = timeoutS;
109 TimeoutMs = timeoutMs;
110 SortOrder = sortOrder;
111 }
112}
113
114//-----------------------------------------------------------------------------
116enum EStage
117{
120 TearDown
121}
122
123//-----------------------------------------------------------------------------
125class Step
126{
127 EStage Stage;
128
129 void Step(EStage stage = EStage.Main)
130 {
131 Stage = stage;
132 }
133}
134
135//-----------------------------------------------------------------------------
138{
141 proto native static bool Run();
143 proto static string Report();
145 proto native static int GetNSuites();
147 proto native static TestSuite GetSuite(int handle);
149 proto native static TestSuite ActiveSuite();
151 proto native static bool Finished();
153 proto native static void Begin();
155 proto native static void End();
156}
157
158//-----------------------------------------------------------------------------
160class TestSuite : Managed
161{
164 proto native void SetResult(TestResultBase res);
166 proto native int GetNTests();
168 proto native TestBase GetTest(int handle);
170 proto native void SetEnabled(bool val);
172 proto native bool IsEnabled();
174 proto string GetName();
176 protected void OnInit();
177}
178
179//-----------------------------------------------------------------------------
182{
185 proto native void SetResult(TestResultBase res);
187 proto native TestResultBase GetResult();
189 proto native void SetEnabled(bool val);
191 proto native bool IsEnabled();
193 proto string GetName();
194}
195
196//-----------------------------------------------------------------------------
201class TestResultBase : Managed
202{
204 bool Failure() { return NativeFailure(); }
206 string FailureText() { return NativeFailureText(); }
207
208 // Script forwarding to cpp. Otherwise the script overloading wouldn't be able
209 // to call the native base implementation.
210 // ----------------- vvv -----------------
211 proto native bool NativeFailure();
212 proto native string NativeFailureText();
213 // ----------------- ^^^ -----------------
214}
215
220//-----------------------------------------------------------------------------
221// EXAMPLES
222//-----------------------------------------------------------------------------
223/*
224//-----------------------------------------------------------------------------
226class TestBoolResult : TestResultBase
227{
228 bool Value;
229
230 void TestBoolResult(bool val) { Value = val; }
231
232 override bool Failure() { return !Value; }
233
234 override string FailureText()
235 {
236 // junit kind of error report. (simple)
237 return "<failure type=\"BoolResult\">Failed</failure>";
238 }
239}
240
241//-----------------------------------------------------------------------------
242class MyHarness : TestHarness
243{
244}
245
246//-----------------------------------------------------------------------------
247class MyTestSuite : TestSuite
248{
249 int cnt;
250
251 [Step(EStage.Setup)]
252 void Prep()
253 {
254 Print("MyTestSuite::Prep");
255 cnt = 3;
256 }
257
258 [Step(EStage.Setup)]
259 bool Count()
260 {
261 --cnt;
262 Print("MyTestSuite::Count: cnt=" + cnt);
263 return cnt == 0;
264 }
265
266 [Step(EStage.TearDown)]
267 bool CountUp()
268 {
269 ++cnt;
270 Print("MyTestSuite::CountUp: cnt=" + cnt);
271 return cnt == 10;
272 }
273}
274
275//-----------------------------------------------------------------------------
276[Test("MyTestSuite")]
277TestResultBase MyTest()
278{
279 Print("MyFuncTest");
280 return new TestBoolResult(true);
281}
282
283//-----------------------------------------------------------------------------
284[Test("MyTestSuite")]
285class MyAsyncTest : TestBase
286{
287 int counter;
288
289 [Step(EStage.Main)]
290 void Set()
291 {
292 counter = 10;
293 }
294
295 [Step(EStage.Main)]
296 bool Pool()
297 {
298 Print("AsyncTest::Pool::counter=" + counter);
299
300 if(counter == 0)
301 {
302 Print("AsyncTest::Pool::Result");
303 SetResult(new TestBoolResult(false));
304 return true;
305 }
306
307 Print("AsyncTest::Pool::Progress");
308
309 counter--;
310 return false;
311 }
312}
313*/
TODO doc.
Definition enscript.c:118
Test base class.
Collection and main interface of the Testing framework.
Attribute used for tests annotation and assignment to Suites.
void SetEnabled()
prevents insider adding in the wrong position, HOTFIX
proto native bool IsEnabled()
Enabled flag getter.
void OnInit()
Callback for user defined initialization. Called for all suites during TestHarness....
Definition freezestate.c:81
class Test Stage
Attribute which marks a method as part of the testing process.
proto native int GetNTests()
Returns the number for tests within this suite.
TestHarness Managed SetResult(TestResultBase res)
Collection of tests.
string FailureText()
Text used for xml report output.
void Step(EStage stage=EStage.Main)
class Test Setup
Stage definition used in conjunction with Step attribute.
class Test Main
proto native TestBase GetTest(int handle)
Returns a test.
proto native string NativeFailureText()
TestBase Managed Failure()
Return true of the result means failure.
proto native bool NativeFailure()