1+ // vld_main.cpp : Defines the entry point for the console application.
2+ //
3+
4+ #include " stdafx.h"
5+ #include < Windows.h>
6+ #include < gtest/gtest.h>
7+ #include < string>
8+
9+ std::wstring dir;
10+
11+ TEST (TestWinMain, RunExe)
12+ {
13+ PROCESS_INFORMATION processInformation = { 0 };
14+ STARTUPINFO startupInfo = { 0 };
15+ startupInfo.cb = sizeof (startupInfo);
16+
17+ std::wstring exe = dir + _T (" vld_main.exe" );
18+
19+ // Create the process
20+ BOOL result = CreateProcess (exe.c_str (), NULL ,
21+ NULL , NULL , FALSE ,
22+ NORMAL_PRIORITY_CLASS | CREATE_NO_WINDOW,
23+ NULL , NULL , &startupInfo, &processInformation);
24+ EXPECT_NE (0 , result);
25+
26+ // Successfully created the process. Wait for it to finish.
27+ EXPECT_EQ (WAIT_OBJECT_0, WaitForSingleObject (processInformation.hProcess , INFINITE));
28+
29+ // Get the exit code.
30+ DWORD exitCode = 0 ;
31+ result = GetExitCodeProcess (processInformation.hProcess , &exitCode);
32+ EXPECT_NE (0 , result);
33+
34+ // Close the handles.
35+ CloseHandle (processInformation.hProcess );
36+ CloseHandle (processInformation.hThread );
37+ ASSERT_EQ (9 , exitCode);
38+ }
39+
40+ int _tmain (int argc, _TCHAR* argv[])
41+ {
42+ dir = argv[0 ];
43+ dir.resize (dir.find_last_of (_T (" \\ " )) + 1 );
44+ ::testing::InitGoogleTest (&argc, argv);
45+ return RUN_ALL_TESTS ();
46+ }
0 commit comments