Skip to content

Commit 6dd793b

Browse files
committed
Now using mspaint.exe as default executable to start/stop while running tests. This is better than using calc.exe since calc.exe is a stub/sandbox application to start CalculatorApp.exe. When launching calc.exe, we are unable to properly detect the process id of CAlculatorApp.exe.
Follow up to 319f594.
1 parent 10800f6 commit 6dd793b

File tree

3 files changed

+121
-18
lines changed

3 files changed

+121
-18
lines changed

src/tests/TestActionExecute.cpp

Lines changed: 104 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
#include "Workspace.h"
3232
#include "QuickLoader.h"
3333
#include "ArgumentsHandler.h"
34+
#include "SaUtils.h"
35+
3436
#include "rapidassist/testing.h"
3537
#include "rapidassist/filesystem_utf8.h"
3638
#include "rapidassist/user.h"
@@ -39,6 +41,7 @@
3941
#include "rapidassist/process.h"
4042
#include "rapidassist/cli.h"
4143
#include "rapidassist/random.h"
44+
#include "rapidassist/errors.h"
4245

4346
#ifndef WIN32_LEAN_AND_MEAN
4447
#define WIN32_LEAN_AND_MEAN 1
@@ -212,6 +215,104 @@ namespace shellanything
212215
return false;
213216
}
214217

218+
void KillShellAnythingArgumentsDebuggerProcess()
219+
{
220+
printf("Killing all arguments.debugger.window.exe processes...\n");
221+
222+
if (ra::environment::IsConfigurationDebug())
223+
system("cmd.exe /c taskkill /IM arguments.debugger.window-d.exe >NUL 2>NUL");
224+
else
225+
system("cmd.exe /c taskkill /IM arguments.debugger.window.exe >NUL 2>NUL");
226+
227+
ra::timing::Millisleep(1000);
228+
229+
printf("killed.\n");
230+
}
231+
232+
bool StartShellAnythingArgumentsDebuggerProcess(ra::process::processid_t& pId)
233+
{
234+
printf("Starting arguments.debugger.window.exe...\n");
235+
236+
// Build path of arguments.debugger.window.exe
237+
std::string current_process_dir = ra::process::GetCurrentProcessDir();
238+
std::string process_path;
239+
if (ra::environment::IsConfigurationDebug())
240+
process_path = current_process_dir + "\\arguments.debugger.window-d.exe";
241+
else
242+
process_path = current_process_dir + "\\arguments.debugger.window.exe";
243+
244+
// Assert that file exists
245+
if (!ra::filesystem::FileExists(process_path.c_str()))
246+
{
247+
printf("Start process failed. File not found: '%s'.\n", process_path.c_str());
248+
return false;
249+
}
250+
251+
// Start the actual process
252+
ra::process::processid_t tmp_pid = ra::process::StartProcess(process_path, current_process_dir.c_str());
253+
254+
// Asser created properly
255+
if (tmp_pid == 0)
256+
{
257+
ra::errors::errorcode_t last_error = ra::errors::GetLastErrorCode();
258+
std::string error_desc = ra::errors::GetErrorCodeDescription(last_error);
259+
260+
printf("Start process failed. Error code %s, %s.\n", ToHexString(last_error).c_str(), error_desc.c_str());
261+
return false;
262+
}
263+
264+
ra::timing::Millisleep(2000);
265+
266+
printf("started.\n");
267+
pId = tmp_pid;
268+
return true;
269+
}
270+
271+
void KillMsPaintProcess()
272+
{
273+
printf("Killing all mspaint.exe processes...\n");
274+
275+
system("cmd.exe /c taskkill /IM mspaint.exe >NUL 2>NUL");
276+
ra::timing::Millisleep(1000);
277+
278+
printf("killed.\n");
279+
}
280+
281+
bool StartMsPaintProcess(ra::process::processid_t& pId)
282+
{
283+
printf("Starting mspaint.exe...\n");
284+
285+
// Build path of arguments.debugger.window.exe
286+
std::string current_process_dir = ra::process::GetCurrentProcessDir();
287+
std::string process_path = "C:\\Windows\\System32\\mspaint.exe";
288+
289+
// Assert that file exists
290+
if (!ra::filesystem::FileExists(process_path.c_str()))
291+
{
292+
printf("Start process failed. File not found: '%s'.\n", process_path.c_str());
293+
return false;
294+
}
295+
296+
// Start the actual process
297+
ra::process::processid_t tmp_pid = ra::process::StartProcess(process_path, current_process_dir.c_str());
298+
299+
// Asser created properly
300+
if (tmp_pid == 0)
301+
{
302+
ra::errors::errorcode_t last_error = ra::errors::GetLastErrorCode();
303+
std::string error_desc = ra::errors::GetErrorCodeDescription(last_error);
304+
305+
printf("Start process failed. Error code %s, %s.\n", ToHexString(last_error).c_str(), error_desc.c_str());
306+
return false;
307+
}
308+
309+
ra::timing::Millisleep(2000);
310+
311+
printf("started.\n");
312+
pId = tmp_pid;
313+
return true;
314+
}
315+
215316
namespace FindProcessWindows
216317
{
217318
static const uint32_t ERROR_PROCESS_NOT_FOUND = (uint32_t)-1;
@@ -296,7 +397,7 @@ namespace shellanything
296397

297398
//Execute the action
298399
ActionExecute ae;
299-
ae.SetPath("C:\\Windows\\System32\\calc.exe");
400+
ae.SetPath("C:\\Windows\\System32\\mspaint.exe");
300401
ae.SetBaseDir("");
301402
ae.SetArguments("");
302403

@@ -305,7 +406,7 @@ namespace shellanything
305406

306407
//Cleanup
307408
ra::timing::Millisleep(500);
308-
KillCalculatorProcess();
409+
KillMsPaintProcess();
309410
}
310411
//--------------------------------------------------------------------------------------------------
311412
TEST_F(TestActionExecute, testBaseDir)
@@ -324,7 +425,7 @@ namespace shellanything
324425

325426
//Execute the action
326427
ActionExecute ae;
327-
ae.SetPath("calc.exe");
428+
ae.SetPath("mspaint.exe");
328429
ae.SetBaseDir("C:\\Windows\\System32");
329430
ae.SetArguments("");
330431

src/tests/TestPlugins.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,10 @@ namespace shellanything
4545
{
4646
namespace test
4747
{
48-
extern void KillCalculatorProcess();
49-
extern bool StartCalculatorProcess(ra::process::processid_t& pId);
48+
//extern void KillCalculatorProcess();
49+
//extern bool StartCalculatorProcess(ra::process::processid_t& pId);
50+
extern void KillMsPaintProcess();
51+
extern bool StartMsPaintProcess(ra::process::processid_t& pId);
5052

5153
static const ConfigFile* INVALID_CONFIGURATION = NULL;
5254

@@ -209,8 +211,8 @@ namespace shellanything
209211

210212
TRACE_LINE;
211213

212-
//Kill all instances of calc.exe
213-
KillCalculatorProcess();
214+
//Kill all instances of mspaint.exe
215+
KillMsPaintProcess();
214216

215217
TRACE_LINE;
216218

@@ -247,9 +249,9 @@ namespace shellanything
247249

248250
TRACE_LINE;
249251

250-
//Start calc
252+
//Start mspaint
251253
ra::process::processid_t pId = 0;
252-
ASSERT_TRUE( StartCalculatorProcess(pId) );
254+
ASSERT_TRUE( StartMsPaintProcess(pId) );
253255

254256
TRACE_LINE;
255257

@@ -304,7 +306,7 @@ namespace shellanything
304306
TRACE_LINE;
305307

306308
//Cleanup
307-
KillCalculatorProcess();
309+
KillMsPaintProcess();
308310
ASSERT_TRUE(workspace.Cleanup()) << "Failed deleting workspace directory '" << workspace.GetBaseDirectory() << "'.";
309311

310312
TRACE_LINE;

src/tests/test_files/TestPlugins.testProcess.xml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,28 +14,28 @@
1414
</plugins>
1515
<shell>
1616

17-
<menu name="Terminate Calc (by filename)">
18-
<visibility process_filename="CalculatorApp.exe" />
17+
<menu name="Terminate MsPaint (by filename)">
18+
<visibility process_filename="mspaint.exe" />
1919
<actions>
20-
<terminateprocess filename="CalculatorApp.exe" />
20+
<terminateprocess filename="mspaint.exe" />
2121
</actions>
2222
</menu>
2323

24-
<menu name="Terminate Calc (by pid)">
24+
<menu name="Terminate MsPaint (by pid)">
2525
<visibility process_pid="${sa_plugin_process.pid}" />
2626
<actions>
2727
<terminateprocess pid="${sa_plugin_process.pid}" />
2828
</actions>
2929
</menu>
3030

31-
<menu name="Kill Calc (by filename)">
32-
<visibility process_filename="CalculatorApp.exe" />
31+
<menu name="Kill MsPaint (by filename)">
32+
<visibility process_filename="mspaint.exe" />
3333
<actions>
34-
<killprocess filename="CalculatorApp.exe" />
34+
<killprocess filename="mspaint.exe" />
3535
</actions>
3636
</menu>
3737

38-
<menu name="Kill Calc (by pid)">
38+
<menu name="Kill MsPaint (by pid)">
3939
<visibility process_pid="${sa_plugin_process.pid}" />
4040
<actions>
4141
<killprocess pid="${sa_plugin_process.pid}" />

0 commit comments

Comments
 (0)