Skip to content

Commit 8358588

Browse files
committed
DllMain test improved
1 parent 9868016 commit 8358588

17 files changed

+1204
-670
lines changed

src/runtests.bat

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,9 @@ ECHO [ RUNNING ] %tests_path%\vld_unload.exe
2727
ECHO -------------------------------------------------------------------------------
2828
!tests_path!\vld_unload.exe --gtest_output="xml:!tests_path!\vld_unload.exe.xml"
2929
ECHO -------------------------------------------------------------------------------
30-
ECHO [ RUNNING ] %tests_path%\vld_main.exe
30+
ECHO [ RUNNING ] %tests_path%\vld_main_test.exe
3131
ECHO -------------------------------------------------------------------------------
32-
!tests_path!\vld_main.exe
33-
if %errorlevel% neq 0 exit /b %errorlevel%
32+
!tests_path!\vld_main_test.exe --gtest_output="xml:!tests_path!\vld_main_test.exe.xml"
3433
ECHO -------------------------------------------------------------------------------
3534
EXIT /b 0
3635

src/tests/vld_main/vld_main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ int _tmain(int argc, _TCHAR* argv[])
3737
// _tmain exits but before VLDReportLeaks() is called internally by VLD and
3838
// therefore correctly report 8 leaks.
3939
// VLDReportLeaks(); // at this point should report 9 leaks;
40-
return VLDGetLeaksCount() == 9 ? 0 : -1;
40+
return VLDGetLeaksCount();
4141
}
4242

4343

@@ -54,5 +54,5 @@ int WINAPI _tWinMain(__in HINSTANCE hInstance,
5454
// _tWinMain exits but before VLDReportLeaks() is called internally by VLD and
5555
// therefore correctly report 8 leaks.
5656
// VLDReportLeaks(); // at this point should report 9 leaks;
57-
return VLDGetLeaksCount() == 9 ? 0 : -1;
57+
return VLDGetLeaksCount();
5858
}

src/tests/vld_main_test/stdafx.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// stdafx.cpp : source file that includes just the standard includes
2+
// vld_main.pch will be the pre-compiled header
3+
// stdafx.obj will contain the pre-compiled type information
4+
5+
#include "stdafx.h"
6+
7+
// TODO: reference any additional headers you need in STDAFX.H
8+
// and not in this file

src/tests/vld_main_test/stdafx.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// stdafx.h : include file for standard system include files,
2+
// or project specific include files that are used frequently, but
3+
// are changed infrequently
4+
//
5+
6+
#pragma once
7+
8+
#include "targetver.h"
9+
10+
#include <stdio.h>
11+
#include <tchar.h>
12+
13+
14+
15+
// TODO: reference additional headers your program requires here
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#pragma once
2+
3+
// Including SDKDDKVer.h defines the highest available Windows platform.
4+
5+
// If you wish to build your application for a previous Windows platform, include WinSDKVer.h and
6+
// set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h.
7+
8+
#include <SDKDDKVer.h>
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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

Comments
 (0)