@@ -40,16 +40,26 @@ class DynamicLoader : public ::testing::TestWithParam<bool> {
4040
4141TEST_P (DynamicLoader, LoaderTests)
4242{
43- HMODULE hmfcLib = RunLoaderTests (GetParam ()); // leaks 18
44- ASSERT_NE (0u , (UINT_PTR)hmfcLib);
45- int leaks = (int )VLDGetLeaksCount ();
43+ HMODULE hdynLib = LoadDynamicTests ();
44+ ASSERT_NE (0u , reinterpret_cast <UINT_PTR>(hdynLib));
45+ #ifdef STATIC_CRT // Toolset <= v100 use own heap
46+ VLDMarkAllLeaksAsReported ();
47+ RunLoaderTests (hdynLib, GetParam ()); // leaks 18
48+ int leaks = static_cast <int >(VLDGetLeaksCount ());
49+ FreeLibrary (hdynLib);
50+ #else
51+ // VLDMarkAllLeaksAsReported();
52+ RunLoaderTests (hdynLib, GetParam ()); // leaks 18
53+ FreeLibrary (hdynLib);
54+ int leaks = static_cast <int >(VLDGetLeaksCount ());
55+ #endif
4656 if (18 != leaks) VLDReportLeaks ();
4757 ASSERT_EQ (18 , leaks);
4858}
4959
5060TEST_P (DynamicLoader, MultithreadLoadingTests)
5161{
52- // Creates 64 threads that each leaks 18 allocations
62+ // Creates NUMTHREADS threads that each leaks 18 allocations
5363 DWORD start = GetTickCount ();
5464 RunLoaderLockTests (GetParam (), false );
5565 DWORD duration = GetTickCount () - start;
@@ -58,23 +68,38 @@ TEST_P(DynamicLoader, MultithreadLoadingTests)
5868 int leaks = (int )VLDGetLeaksCount ();
5969 duration = GetTickCount () - start;
6070 _tprintf (_T (" VLDGetLeaksCount took: %u ms\n " ), duration);
61- if (64 * 18 != leaks) VLDReportLeaks ();
62- ASSERT_EQ (64 * 18 , leaks);
71+ int correctLeaks = NUMTHREADS * 18 ;
72+ if (correctLeaks != leaks) VLDReportLeaks ();
73+ #ifdef STATIC_CRT // One leak from dll static allocation
74+ HMODULE hlib = LoadDynamicTests ();
75+ for (int i = 0 ; i < NUMTHREADS + 1 ; i++)
76+ FreeLibrary (hlib);
77+ #endif
78+ ASSERT_EQ (correctLeaks, leaks);
6379}
6480
6581TEST_P (DynamicLoader, MfcLoaderTests)
6682{
67- HMODULE hmfcLib = RunMFCLoaderTests (GetParam ()); // leaks 11
68- ASSERT_NE (0u , (UINT_PTR)hmfcLib);
83+ HMODULE hmfcLib = LoadMFCTests ();
84+ ASSERT_NE (0u , reinterpret_cast <UINT_PTR>(hmfcLib));
85+ #ifdef STATIC_CRT // Toolset <= v100 use own heap
86+ VLDMarkAllLeaksAsReported ();
87+ RunMFCLoaderTests (hmfcLib, GetParam ()); // leaks 11
88+ int leaks = (int )VLDGetLeaksCount ();
89+ FreeLibrary (hmfcLib);
90+ #else
91+ // VLDMarkAllLeaksAsReported();
92+ RunMFCLoaderTests (hmfcLib, GetParam ()); // leaks 11
6993 FreeLibrary (hmfcLib);
7094 int leaks = (int )VLDGetLeaksCount ();
95+ #endif
7196 if (11 != leaks) VLDReportLeaks ();
7297 ASSERT_EQ (11 , leaks);
7398}
7499
75100TEST_P (DynamicLoader, MfcMultithreadLoadingTests)
76101{
77- // Creates 64 threads that each leaks 11 allocations
102+ // Creates NUMTHREADS threads that each leaks 11 allocations
78103 DWORD start = GetTickCount ();
79104 RunLoaderLockTests (GetParam (), true );
80105 DWORD duration = GetTickCount () - start;
@@ -83,8 +108,13 @@ TEST_P(DynamicLoader, MfcMultithreadLoadingTests)
83108 int leaks = (int )VLDGetLeaksCount ();
84109 duration = GetTickCount () - start;
85110 _tprintf (_T (" VLDGetLeaksCount took: %u ms\n " ), duration);
86- if (64 * 11 != leaks) VLDReportLeaks ();
87- ASSERT_EQ (64 * 11 , leaks);
111+ if (NUMTHREADS * 11 != leaks) VLDReportLeaks ();
112+ #ifdef STATIC_CRT // One leak from dll static allocation
113+ HMODULE hlib = LoadMFCTests ();
114+ for (int i = 0 ; i < NUMTHREADS + 1 ; i++)
115+ FreeLibrary (hlib);
116+ #endif
117+ ASSERT_EQ (NUMTHREADS * 11 , leaks);
88118}
89119
90120INSTANTIATE_TEST_CASE_P (ResolveVal,
0 commit comments