| OLD | NEW | 
|---|
| 1 #include <gtest/gtest.h> | 1 #include <gtest/gtest.h> | 
| 2 #include "../process.h" | 2 #include "../process.h" | 
| 3 #include <functional> | 3 #include <functional> | 
| 4 | 4 | 
| 5 // Turn off warnings for string copies | 5 // Turn off warnings for string copies | 
| 6 #pragma warning( disable : 4996 ) | 6 #pragma warning( disable : 4996 ) | 
| 7 | 7 | 
| 8 //------------------------------------------------------- | 8 //------------------------------------------------------- | 
| 9 // Comparison objects | 9 // Comparison objects | 
| 10 //------------------------------------------------------- | 10 //------------------------------------------------------- | 
| 11 | 11 | 
| 12 const wchar_t * multiple_module_names[] = { L"kernel32.dll", L"non-matching-name
     " } ; |  | 
| 13 const wchar_t * non_existent_module_names[] = { L"non-matching-name" } ; |  | 
| 14 |  | 
| 15 const wchar_t exact_exe_name[] = L"installer-ca-tests.exe" ; | 12 const wchar_t exact_exe_name[] = L"installer-ca-tests.exe" ; | 
| 16 const std::wstring exact_exe_string( exact_exe_name ) ; | 13 const std::wstring exact_exe_string( exact_exe_name ) ; | 
| 17 const wstring_ci exact_exe_string_ci( exact_exe_name ) ; | 14 const wstring_ci exact_exe_string_ci( exact_exe_name ) ; | 
| 18 | 15 | 
| 19 const wchar_t mixedcase_exe_name[] = L"Installer-CA-Tests.exe" ; | 16 const wchar_t mixedcase_exe_name[] = L"Installer-CA-Tests.exe" ; | 
| 20 const wstring_ci mixedcase_exe_string_ci( mixedcase_exe_name ) ; | 17 const wstring_ci mixedcase_exe_string_ci( mixedcase_exe_name ) ; | 
| 21 | 18 | 
| 22 const wchar_t unknown_name[] = L"non-matching-name" ; | 19 const wchar_t unknown_name[] = L"non-matching-name" ; | 
| 23 const wchar_t * multiple_exe_names[] = { mixedcase_exe_name, unknown_name } ; | 20 const wchar_t * multiple_exe_names[] = { mixedcase_exe_name, unknown_name } ; | 
| 24 | 21 | 
| (...skipping 14 matching lines...) Expand all  Loading... | 
| 39  */ | 36  */ | 
| 40 struct our_process_by_name_CI | 37 struct our_process_by_name_CI | 
| 41   : std::unary_function< PROCESSENTRY32W, bool > | 38   : std::unary_function< PROCESSENTRY32W, bool > | 
| 42 { | 39 { | 
| 43   bool operator()( const PROCESSENTRY32W & process ) | 40   bool operator()( const PROCESSENTRY32W & process ) | 
| 44   { | 41   { | 
| 45     return wstring_ci( process.szExeFile ) == mixedcase_exe_string_ci ; | 42     return wstring_ci( process.szExeFile ) == mixedcase_exe_string_ci ; | 
| 46   } ; | 43   } ; | 
| 47 } ; | 44 } ; | 
| 48 | 45 | 
| 49 |  | 
| 50 struct our_process_by_name_subclassed |  | 
| 51   : public process_by_any_exe_not_immersive |  | 
| 52 { |  | 
| 53   our_process_by_name_subclassed() |  | 
| 54     : process_by_any_exe_not_immersive( file_name_set( multiple_exe_names )) |  | 
| 55   {} |  | 
| 56 } ; |  | 
| 57 |  | 
| 58 |  | 
| 59 //------------------------------------------------------- | 46 //------------------------------------------------------- | 
| 60 //------------------------------------------------------- | 47 //------------------------------------------------------- | 
| 61 /** | 48 /** | 
| 62  * Filter by process name. Comparison is case-insensitive. | 49  * Filter by process name. Comparison is case-insensitive. | 
| 63  */ | 50  */ | 
| 64 class process_by_any_file_name_CI | 51 class process_by_any_file_name_CI | 
| 65   : public std::unary_function< PROCESSENTRY32W, bool > | 52   : public std::unary_function< PROCESSENTRY32W, bool > | 
| 66 { | 53 { | 
| 67   const file_name_set & names ; | 54   const file_name_set & names ; | 
| 68 public: | 55 public: | 
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 103   return p ; | 90   return p ; | 
| 104 } | 91 } | 
| 105 | 92 | 
| 106 PROCESSENTRY32 process_empty = process_with_name( L"" ) ; | 93 PROCESSENTRY32 process_empty = process_with_name( L"" ) ; | 
| 107 PROCESSENTRY32 process_exact = process_with_name( exact_exe_name ) ; | 94 PROCESSENTRY32 process_exact = process_with_name( exact_exe_name ) ; | 
| 108 PROCESSENTRY32 process_mixedcase = process_with_name( mixedcase_exe_name ) ; | 95 PROCESSENTRY32 process_mixedcase = process_with_name( mixedcase_exe_name ) ; | 
| 109 PROCESSENTRY32 process_explorer = process_with_name( L"explorer.exe" ) ; | 96 PROCESSENTRY32 process_explorer = process_with_name( L"explorer.exe" ) ; | 
| 110 PROCESSENTRY32 process_absent = process_with_name( L"no_such_name" ) ; | 97 PROCESSENTRY32 process_absent = process_with_name( L"no_such_name" ) ; | 
| 111 | 98 | 
| 112 file_name_set multiple_name_set( multiple_exe_names ) ; | 99 file_name_set multiple_name_set( multiple_exe_names ) ; | 
| 113 file_name_set multiple_name_set_modules( multiple_module_names ) ; |  | 
| 114 file_name_set non_existent_name_set_modules( non_existent_module_names ) ; |  | 
| 115 process_by_any_file_name_CI find_in_set( multiple_name_set ) ; | 100 process_by_any_file_name_CI find_in_set( multiple_name_set ) ; | 
|  | 101 process_by_any_exe_not_immersive find_in_set_not_immersive( multiple_name_set ) 
     ; | 
|  | 102 | 
| 116 | 103 | 
| 117 TEST( file_name_set, validate_setup ) | 104 TEST( file_name_set, validate_setup ) | 
| 118 { | 105 { | 
| 119   ASSERT_EQ( 2u, multiple_name_set.size() ) ; | 106   ASSERT_EQ( 2u, multiple_name_set.size() ) ; | 
| 120   ASSERT_TRUE( multiple_name_set.find( exact_exe_string_ci ) != multiple_name_se
     t.end() ) ; | 107   ASSERT_TRUE( multiple_name_set.find( exact_exe_string_ci ) != multiple_name_se
     t.end() ) ; | 
| 121   ASSERT_TRUE( multiple_name_set.find( mixedcase_exe_string_ci ) != multiple_nam
     e_set.end() ) ; | 108   ASSERT_TRUE( multiple_name_set.find( mixedcase_exe_string_ci ) != multiple_nam
     e_set.end() ) ; | 
| 122   ASSERT_TRUE( multiple_name_set.find( L"" ) == multiple_name_set.end() ) ; | 109   ASSERT_TRUE( multiple_name_set.find( L"" ) == multiple_name_set.end() ) ; | 
| 123   ASSERT_TRUE( multiple_name_set.find( L"not-in-list" ) == multiple_name_set.end
     () ) ; | 110   ASSERT_TRUE( multiple_name_set.find( L"not-in-list" ) == multiple_name_set.end
     () ) ; | 
| 124 } | 111 } | 
| 125 | 112 | 
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 287   ASSERT_GE( s.size(), 1u ); | 274   ASSERT_GE( s.size(), 1u ); | 
| 288 } | 275 } | 
| 289 | 276 | 
| 290 TEST( pid_set, find_our_process_in_set ) | 277 TEST( pid_set, find_our_process_in_set ) | 
| 291 { | 278 { | 
| 292   std::set< DWORD > s ; | 279   std::set< DWORD > s ; | 
| 293   initialize_process_set( s, find_in_set, copy_PID() ) ; | 280   initialize_process_set( s, find_in_set, copy_PID() ) ; | 
| 294   size_t size( s.size() ) ; | 281   size_t size( s.size() ) ; | 
| 295   EXPECT_EQ( size, 1u ); | 282   EXPECT_EQ( size, 1u ); | 
| 296   ASSERT_GE( size, 1u ); | 283   ASSERT_GE( size, 1u ); | 
|  | 284 } | 
|  | 285 | 
|  | 286 TEST( pid_set, find_our_process_in_set_not_immersive ) | 
|  | 287 { | 
|  | 288   std::set< DWORD > s ; | 
|  | 289   initialize_process_set( s, find_in_set_not_immersive, copy_PID() ) ; | 
|  | 290   size_t size( s.size() ) ; | 
|  | 291   EXPECT_EQ( size, 1u ); | 
|  | 292   ASSERT_GE( size, 1u ); | 
| 297 } | 293 } | 
| OLD | NEW | 
|---|