Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_AutotestRunner.c
Go to the documentation of this file.
1
14sealed class SCR_TestRunner
15{
16 //------------------------------------------------------------------------------------------------
17 static bool ShouldCreate()
18 {
19 HandleCommandLineArguments();
20
21 bool shouldCreate = SCR_AutotestHarness.s_bIsRunning;
22 if (!shouldCreate)
23 {
24 return false;
25 }
26
27 Print("Creating: SCR_TestRunner", LogLevel.NORMAL);
28
29 return true;
30 }
31
32 //------------------------------------------------------------------------------------------------
33 private static void HandleCommandLineArguments()
34 {
35 bool autotestParamPresent = System.IsCLIParam("autotest");
36 if (!autotestParamPresent)
37 return;
38
39 string autotestConfigCLI;
40 System.GetCLIParam("autotest", autotestConfigCLI);
41
42 if (!autotestConfigCLI)
43 {
44 Debug.Error("Empty -autotest parameter value");
45 GetGame().RequestClose();
46 }
47
48 if (autotestConfigCLI.StartsWith("{"))
49 {
50 Resource configHolder = Resource.Load(autotestConfigCLI);
51 if (configHolder.IsValid())
52 {
53 SCR_AutotestGroup config = SCR_AutotestGroup.Cast(BaseContainerTools.CreateInstanceFromContainer(configHolder.GetResource().ToBaseContainer()));
54 if (config)
55 {
56 PrintFormat("CLI autotest config: %1", config, level: LogLevel.NORMAL);
57 SCR_AutotestHarness.Begin(config, true);
58 return;
59 }
60
61 PrintFormat("Specified resource is not of type SCR_AutotestGroup: %1", config, level: LogLevel.ERROR);
62 }
63 else
64 {
65 PrintFormat("Invalid resource path for autotest config: %1", autotestConfigCLI, level: LogLevel.ERROR);
66 }
67 }
68
69 if (autotestConfigCLI.ToType().IsInherited(SCR_AutotestSuiteBase))
70 {
71 PrintFormat("CLI autotest suite: %1", autotestConfigCLI, level: LogLevel.NORMAL);
72 SCR_AutotestSuiteBase testSuite = SCR_AutotestSuiteBase.Cast(autotestConfigCLI.ToType().Spawn());
73 SCR_AutotestHarness.Begin(testSuite, true);
74 return;
75 }
76
77 if (autotestConfigCLI.ToType().IsInherited(SCR_AutotestCaseBase))
78 {
79 PrintFormat("CLI autotest case: %1", autotestConfigCLI, level: LogLevel.NORMAL);
80 SCR_AutotestCaseBase testCase = SCR_AutotestCaseBase.Cast(autotestConfigCLI.ToType().Spawn());
81 SCR_AutotestHarness.Begin(testCase, true);
82 return;
83 }
84
85 Debug.Error(string.Format("Invalid -autotest parameter value: %1", autotestConfigCLI));
86 GetGame().RequestClose();
87 }
88
89 //------------------------------------------------------------------------------------------------
90 void OnUpdate(notnull Game game)
91 {
93 return;
94
95 if (GameStateTransitions.IsTransitionRequestedOrInProgress())
96 return;
97
98 if (!game.IsPreloadFinished())
99 return;
100
101#ifdef ENABLE_DIAG
102 if (DiagMenu.GetBool(SCR_DebugMenuID.DEBUGUI_AUTOTEST_PROGRESS, true))
103 SCR_AutotestDebugMenu.GetInstance().Update();
104#endif
105
106 // execute the tests
107 if (!SCR_AutotestHarness.Run())
108 return;
109
110 Print("SCR_TestRunner has finished running", LogLevel.NORMAL);
111
112 SCR_AutotestReport report = SCR_AutotestHarness.Finish();
113 report.WriteJUnitXML();
114 report.WriteFailedList();
115
116#ifdef ENABLE_DIAG
117 SCR_AutotestDebugMenu.Terminate();
118#endif
119
120 if (ShouldCloseGameAfterRun())
121 {
122 // GameStateTransitions.RequestGameTerminateTransition();
123 GetGame().RequestClose();
124 }
125 }
126
127 //------------------------------------------------------------------------------------------------
128 void Abort(notnull Game game)
129 {
130#ifdef WORKBENCH
131 // on game end is called two times when going back to EditorMode
132 // on the first call InPlayMode is true, false on second
133 if (!game.InPlayMode() && SCR_AutotestHarness.s_bIsRunning)
134 SCR_AutotestHarness.Finish(abort: true);
135#endif
136 }
137
138 //------------------------------------------------------------------------------------------------
139 private bool ShouldCloseGameAfterRun()
140 {
142 }
143}
ref DSGameConfig game
Definition DSConfig.c:81
SCR_DebugMenuID
This enum contains all IDs for DiagMenu entries added in script.
Definition DebugMenuID.c:4
ArmaReforgerScripted GetGame()
Definition game.c:1398
override void OnUpdate()
Definition Debug.c:13
Diagnostic and developer menu system.
Definition DiagMenu.c:18
Definition Game.c:8
Object holding reference to resource. In destructor release the resource.
Definition Resource.c:25
Collection of test suites.
static void Begin(SCR_AutotestGroup testGroup, bool autorun=false, bool verboseLog=false)
Configures the test runner to execute only the test suites present in the specified test group and in...
proto void Print(void var, LogLevel level=LogLevel.NORMAL)
Prints content of variable to console/log.
LogLevel
Enum with severity of the logging message.
Definition LogLevel.c:14
proto void PrintFormat(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, LogLevel level=LogLevel.NORMAL)