Dayz
Build 1.29.163047, Scripts Rev. 123548
Dayz Code Explorer by Zeroy
Toggle main menu visibility
Loading...
Searching...
No Matches
autotestrunner.c
Go to the documentation of this file.
1
/*
2
This class is just a convenience wrapper for using the actual TestHarness.
3
*/
4
class
AutotestRunner
5
{
6
private
static
bool
m_IsRunning
;
7
private
static
bool
m_IsDone
;
8
9
static
bool
IsRunning
()
10
{
11
return
m_IsRunning
;
12
}
13
14
static
bool
IsDone
()
15
{
16
return
m_IsDone
;
17
}
18
19
static
void
Start
()
20
{
21
if
(
m_IsRunning
)
22
{
23
ErrorEx
(
"TestAutotest already running!"
);
24
return
;
25
}
26
27
AutoTestFixture
.
SetWorldName
();
28
29
// Enabled suites from JSON config provided on CLI (autotest param)
30
set<string> enabledSuites =
new
set<string>();
31
enabledSuites =
AutotestConfigHandler
.
GetSuites
();
32
33
// Iterate through all suites and activate 'enabled' ones (list to be provided by config?)
34
int
numSuites =
TestHarness
.
GetNSuites
();
35
if
(numSuites == 0)
36
{
37
AutoTestFixture
.
LogRPT
(
"No TestSuites to run."
);
38
m_IsDone
=
true
;
39
return
;
40
}
41
42
for
(
int
i = 0; i < numSuites; ++i)
43
{
44
TestSuite suite =
TestHarness
.
GetSuite
(i);
45
bool
isEnabled = enabledSuites.Find(suite.GetName()) != -1 && suite.IsEnabled();
46
suite.SetEnabled(isEnabled);
47
//AutoTestFixture.LogRPT(string.Format("Suite '%1' activation state set to: %2", suite.GetName(), isEnabled));
48
}
49
50
// Start running active TestSuite
51
m_IsRunning
=
true
;
52
TestHarness
.
Begin
();
53
}
54
55
static
void
Update
(
float
deltaTime)
56
{
57
if
(!
m_IsRunning
)
58
return
;
59
60
if
(!
TestHarness
.
Finished
())
61
{
62
bool
isDone =
TestHarness
.
Run
();
63
if
(isDone)
64
{
65
string
errorMessage;
66
if
(!
AutoTestFixture
.
SaveXMLReport
(
TestHarness
.
Report
(), errorMessage))
67
AutoTestFixture
.
LogRPT
(errorMessage);
68
69
TestHarness
.
End
();
70
m_IsRunning
=
false
;
71
m_IsDone
=
true
;
72
}
73
}
74
}
75
}
76
77
/*
78
Script wrapper for TestResultBase that allows script provided kind and message in elegant way.
79
*/
80
class
CustomResult
: TestResultBase
81
{
82
private
bool
m_Success
;
83
private
string
m_FailureText
;
84
private
string
m_FailureKind
;
85
86
override
bool
Failure
()
87
{
88
return
!
m_Success
;
89
}
90
91
// string FailureTextNativeFormat(string type, string userTxt);
92
// That will return the formatted string
93
override
string
FailureText
()
94
{
95
return
string
.
Format
(
"<failure type=\"%1\">%2</failure>"
,
m_FailureKind
,
m_FailureText
);
96
}
97
98
void
CustomResult
(
bool
success,
string
text =
"User provided error!"
,
string
kind =
"Failure"
)
99
{
100
m_Success
= success;
101
m_FailureText
= text;
102
m_FailureKind
= kind;
103
}
104
}
105
106
/* Suite is a collection of tests. */
107
/*
108
class FooTestSuite : TestSuite
109
{
110
// !!!
111
// Be careful, if you leave the suite empty - no error is given and it will just ommit everything.
112
// !!!
113
114
[Step(EStage.Setup)]
115
void FooSetup()
116
{
117
Print("FooTestSuite is setting up... Tests can commence now..");
118
}
119
120
[Step(EStage.TearDown)]
121
void FooFinish()
122
{
123
Print("FooTestSuite is finishing up ... Tests are done..");
124
}
125
}
126
*/
127
128
/* Test is registered within suite via the usage of the Test attribute. */
129
/*
130
[Test("FooTestSuite")]
131
class FooTest1 : TestBase
132
{
133
private int m_Value;
134
private const int k_TargetValue = 10;
135
136
[Step(EStage.Setup)]
137
void Setup()
138
{
139
m_Value = k_TargetValue;
140
}
141
142
[Step(EStage.Main)]
143
void Main()
144
{
145
if ( m_Value != k_TargetValue )
146
{
147
SetResult( new CustomResult(false, string.Format("Expected value: %1, Actual value: %2", k_TargetValue, m_Value)) );
148
}
149
else
150
{
151
SetResult( new CustomResult(true, "Successfull!") );
152
}
153
}
154
155
[Step(EStage.TearDown)]
156
void Cleanup()
157
{
158
m_Value = 0;
159
}
160
}
161
162
/* Test is registered within suite via the usage of the Test attribute. */
163
/*
164
[Test("FooTestSuite")]
165
class FooTest2 : TestBase
166
{
167
private int m_Value;
168
private const int k_TargetValue = 10;
169
170
[Step(EStage.Setup)]
171
void Setup()
172
{
173
m_Value = 11; // intentionally wrong
174
}
175
176
[Step(EStage.Main)]
177
void Main()
178
{
179
if ( m_Value != k_TargetValue )
180
{
181
SetResult( new CustomResult(false, string.Format("Expected value: %1, Actual value: %2", k_TargetValue, m_Value)) );
182
}
183
else
184
{
185
SetResult( new CustomResult(true, "Successfull!") );
186
}
187
}
188
189
[Step(EStage.TearDown)]
190
void Cleanup()
191
{
192
m_Value = 0;
193
}
194
}
195
196
class BarTestSuite : TestSuite
197
{
198
[Step(EStage.Setup)]
199
void A();
200
}
201
202
[Test("BarTestSuite")]
203
class BarTest1 : TestBase
204
{
205
[Step(EStage.Setup)]
206
void Setup();
207
208
[Step(EStage.Main)]
209
void Main()
210
{
211
SetResult( new CustomResult(true, "Successfull!") );
212
}
213
214
[Step(EStage.TearDown)]
215
void Cleanup();
216
}
217
*/
m_Success
class AutotestRunner m_Success
m_FailureText
string m_FailureText
Definition
autotestrunner.c:83
m_FailureKind
string m_FailureKind
Definition
autotestrunner.c:84
CustomResult
void CustomResult(bool success, string text="User provided error!", string kind="Failure")
Definition
autotestrunner.c:98
AutoTestFixture
Definition
autotestfixture.c:2
AutoTestFixture::SaveXMLReport
static bool SaveXMLReport(string data, out string errorMessage)
Definition
autotestfixture.c:8
AutoTestFixture::LogRPT
static void LogRPT(string message)
Definition
autotestfixture.c:49
AutoTestFixture::SetWorldName
static void SetWorldName()
Definition
autotestfixture.c:35
AutotestConfigHandler
Definition
autotestconfighandler.c:2
AutotestConfigHandler::GetSuites
static set< string > GetSuites()
Definition
autotestconfighandler.c:17
AutotestRunner
Definition
autotestrunner.c:5
AutotestRunner::Update
static void Update(float deltaTime)
Definition
autotestrunner.c:55
AutotestRunner::m_IsRunning
static bool m_IsRunning
Definition
autotestrunner.c:6
AutotestRunner::IsDone
static bool IsDone()
Definition
autotestrunner.c:14
AutotestRunner::Start
static void Start()
Definition
autotestrunner.c:19
AutotestRunner::IsRunning
static bool IsRunning()
Definition
autotestrunner.c:9
AutotestRunner::m_IsDone
static bool m_IsDone
Definition
autotestrunner.c:7
TestHarness
Collection and main interface of the Testing framework.
Definition
testingframework.c:138
TestHarness::End
proto static native void End()
Finalizes the testing process.
TestHarness::Run
proto static native bool Run()
Starts the testing process. Returns true when all tests have finished. If some of them are still in p...
TestHarness::GetNSuites
proto static native int GetNSuites()
Returns number of test suites.
TestHarness::Finished
proto static native bool Finished()
Returns true when all tests and suites finished.
TestHarness::Begin
proto static native void Begin()
Starts up the testing process and initializes the structures.
TestHarness::GetSuite
proto static native TestSuite GetSuite(int handle)
Returns a test suite.
TestHarness::Report
static proto string Report()
Generates a xml report.
ErrorEx
enum ShapeType ErrorEx
FailureText
string FailureText()
Text used for xml report output.
Definition
testingframework.c:206
Failure
TestBase Managed Failure()
Base class for test results. This way you report back to the system. More complex failure types with ...
Definition
testingframework.c:204
string::Format
static proto string Format(string fmt, void param1=NULL, void param2=NULL, void param3=NULL, void param4=NULL, void param5=NULL, void param6=NULL, void param7=NULL, void param8=NULL, void param9=NULL)
Gets n-th character from string.
Games
Dayz
scripts
3_game
autotest
autotestrunner.c
Generated by
1.17.0