Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_AutotestTool.c
Go to the documentation of this file.
1#ifdef WORKBENCH
2[WorkbenchToolAttribute(
3 name: "Autotest Tool",
4 description: "",
5 awesomeFontCode: 0xF188
6)]
7class SCR_AutotestTool : WorldEditorTool
8{
9 [Attribute("", UIWidgets.ResourceNamePicker, category: "Test Selection", desc: "", params: "conf class=SCR_AutotestGroup")]
10 protected ResourceName m_sTestGroup;
11
12 [Attribute("", UIWidgets.EditBox, category: "Test Selection", desc: "Name of test case or test suite class to execute.")]
13 protected string m_sTestClass;
14
15 [Attribute("", UIWidgets.CheckBox, category: "New Process", desc: "Should the tests run in new process.")]
16 protected bool m_bRunInNewWindow;
17
18 [Attribute(SCR_AutotestHelper.GetDefaultLaunchParams(), UIWidgets.EditBoxMultiline, category: "New Process", desc: "Additional arguments the new process will launch with.")]
19 protected string m_bArguments;
20
21 protected ScriptEditor m_ScriptEditor = Workbench.GetModule(ScriptEditor);
22
23 //------------------------------------------------------------------------------------------------
24 [ButtonAttribute("Run group")]
25 protected void ButtonRunGroup()
26 {
27 PrintFormat("User requested test run: %1", m_sTestGroup, level: LogLevel.NORMAL);
28
29 SCR_AutotestGroup config = GetConfigByPath(m_sTestGroup);
30 if (!config)
31 {
32 Print("Invalid config", LogLevel.ERROR);
33 }
34
35 if (m_bRunInNewWindow)
36 {
37 RunNewProcess(m_sTestGroup);
38 return;
39 }
40
41 SCR_AutotestPlugin autotestPlugin = SCR_AutotestPlugin.Cast(m_ScriptEditor.GetPlugin(SCR_AutotestPlugin));
42 autotestPlugin.FocusWorldEditor();
43
44 autotestPlugin.RunConfig(config);
45 }
46
47 //------------------------------------------------------------------------------------------------
48 [ButtonAttribute("Run class")]
49 protected void ButtonRunClass()
50 {
51 if (m_bRunInNewWindow)
52 {
53 RunNewProcess(m_sTestClass);
54 return;
55 }
56
57 SCR_AutotestPlugin autotestPlugin = SCR_AutotestPlugin.Cast(m_ScriptEditor.GetPlugin(SCR_AutotestPlugin));
58 autotestPlugin.FocusWorldEditor();
59
60 autotestPlugin.RunClassName(m_sTestClass.Trim(), true);
61 }
62
63 //------------------------------------------------------------------------------------------------
64 protected SCR_AutotestGroup GetConfigByPath(ResourceName configName)
65 {
66 Resource configHolder = Resource.Load(configName);
67
68 return SCR_AutotestGroup.Cast(BaseContainerTools.CreateInstanceFromContainer(configHolder.GetResource().ToBaseContainer()));
69 }
70
71 //------------------------------------------------------------------------------------------------
72 protected void RunNewProcess(string autotestArg)
73 {
74 string cwd;
75 Workbench.GetCwd(cwd);
76
77 WorldEditor worldEditor = Workbench.GetModule(WorldEditor);
78 SCR_AutotestToolPlugin settings = SCR_AutotestToolPlugin.Cast(worldEditor.GetPlugin(SCR_AutotestToolPlugin));
79
80 string exePath = settings.GetExecutablePath();
81 if (!exePath)
82 {
83 Workbench.Dialog("Autotest Tool - Error", "Executable path not configured.\nPlugins > Settings > Autotest Tool");
84 return;
85 }
86
87 string exe = exePath;
88 string gproj = Workbench.GetCurrentGameProjectFile();
89
90 string cmd = string.Format("\"%1\" -gproj \"%2\"", exe, gproj);
91
92 string addonDirs = GetAddonsDirCLI();
93 cmd += string.Format(" -addonsDir %1", addonDirs);
94
95 string addons = GetAddonsCLI();
96 cmd += string.Format(" -addons %1", addons);
97
98 cmd += string.Format(" -autotest %1", autotestArg);
99
100 // user provided args
101 cmd += " " + m_bArguments;
102
103 Print("\nRunning command:\n" + cmd, LogLevel.NORMAL);
104 ProcessHandle handle = Workbench.RunProcess(cmd);
105 if (!handle)
106 Print("Autotest couldn't run. Check if your Executable or other settings are correct", LogLevel.ERROR);
107 }
108
109 //------------------------------------------------------------------------------------------------
110 protected string GetAddonsDirCLI()
111 {
112 string addonsDir;
113 array<string> addonsGUIDs = {};
114 GameProject.GetLoadedAddons(addonsGUIDs);
115
116 foreach (string GUID : addonsGUIDs)
117 {
118 if (!GameProject.IsVanillaAddon(GUID))
119 {
120 string addonPath = "$" + GameProject.GetAddonID(GUID) + ":";
121 string absPath;
122 if (Workbench.GetAbsolutePath(addonPath, absPath))
123 {
124 if (!addonsDir.IsEmpty())
125 addonsDir += ",";
126
127 addonsDir += absPath;
128 }
129 }
130 }
131
132 return "\"" + addonsDir + "\"";
133 }
134
135 //------------------------------------------------------------------------------------------------
136 protected string GetAddonsCLI()
137 {
138 string addonIDs;
139
140 array<string> addonsGUIDs = {};
141 GameProject.GetLoadedAddons(addonsGUIDs);
142
143 foreach (string GUID : addonsGUIDs)
144 {
145 if (!GameProject.IsVanillaAddon(GUID))
146 {
147 if (!addonIDs.IsEmpty())
148 addonIDs += ",";
149
150 addonIDs += GameProject.GetAddonID(GUID);
151 }
152 }
153
154 return addonIDs;
155 }
156}
157#endif
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
class WorkbenchDialog_AbortRetryIgnore ButtonAttribute("OK", true)
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)
SCR_FieldOfViewSettings Attribute