Dayz Explorer 1.29.162510
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*/
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*/
80class 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/*
108class 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")]
131class 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")]
165class 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
196class BarTestSuite : TestSuite
197{
198 [Step(EStage.Setup)]
199 void A();
200}
201
202[Test("BarTestSuite")]
203class 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*/
class AutotestRunner m_Success
Collection and main interface of the Testing framework.
void Start()
Plays all elements this effects consists of.
Definition effect.c:157
enum ShapeType ErrorEx
string FailureText()
Text used for xml report output.
TestBase Managed Failure()
Return true of the result means failure.
bool IsRunning()
Definition tools.c:264
void Update()
Definition radialmenu.c:518