DayZ 1.27
DayZ Explorer by KGB
 
Загрузка...
Поиск...
Не найдено
AutotestRunner.c
См. документацию.
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
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;
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
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
string m_FailureText
Определения AutotestRunner.c:83
string m_FailureKind
Определения AutotestRunner.c:84
void CustomResult(bool success, string text="User provided error!", string kind="Failure")
Определения AutotestRunner.c:98
static void LogRPT(string message)
Определения AutoTestFixture.c:49
static void SetWorldName()
Определения AutoTestFixture.c:35
static bool SaveXMLReport(string data, out string errorMessage)
Определения AutoTestFixture.c:8
Определения AutoTestFixture.c:2
static set< string > GetSuites()
Определения AutotestConfigHandler.c:17
static void Start()
Определения AutotestRunner.c:19
static bool IsRunning()
Определения AutotestRunner.c:9
static bool m_IsRunning
Определения AutotestRunner.c:6
static bool IsDone()
Определения AutotestRunner.c:14
static void Update(float deltaTime)
Определения AutotestRunner.c:55
static bool m_IsDone
Определения AutotestRunner.c:7
Определения AutotestRunner.c:5
proto static native bool Finished()
Returns true when all tests and suites finished.
proto static native TestSuite GetSuite(int handle)
Returns a test suite.
proto static native void End()
Finalizes the testing process.
proto static native int GetNSuites()
Returns number of test suites.
static proto string Report()
Generates a xml report.
proto static native bool Run()
proto static native void Begin()
Starts up the testing process and initializes the structures.
Collection and main interface of the Testing framework.
Определения TestingFramework.c:138
enum ShapeType ErrorEx
string FailureText()
Text used for xml report output.
Определения TestingFramework.c:206
TestBase Managed Failure()
Return true of the result means failure.
Определения TestingFramework.c:204
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.