Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: installer/src/installer-lib/test/process_test.cpp

Issue 6003395731128320: Only take into account processes that have our plugin loaded (Closed)
Patch Set: Created March 27, 2014, 3:29 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
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 exact_exe_name[] = L"installer-ca-tests.exe" ; 12 const wchar_t exact_exe_name[] = L"installer-ca-tests.exe" ;
13 const wchar_t mixedcase_exe_name[] = L"Installer-CA-Tests.exe" ; 13 const wchar_t mixedcase_exe_name[] = L"Installer-CA-Tests.exe" ;
14 const wchar_t * multiple_exe_names[] = { mixedcase_exe_name, L"non-matching-name " } ; 14 const wchar_t * multiple_exe_names[] = { mixedcase_exe_name, L"non-matching-name " } ;
15 const wchar_t * multiple_module_names[] = { L"kernel32.dll", L"non-matching-name " } ;
16 const wchar_t * non_existent_module_names[] = { L"non-matching-name" } ;
15 17
16 /** 18 /**
17 * Compare to our own process name, case-sensitive, no length limit 19 * Compare to our own process name, case-sensitive, no length limit
18 */ 20 */
19 struct our_process_by_name 21 struct our_process_by_name
20 : std::unary_function< PROCESSENTRY32W, bool > 22 : std::unary_function< PROCESSENTRY32W, bool >
21 { 23 {
22 bool operator()( const PROCESSENTRY32W & process ) 24 bool operator()( const PROCESSENTRY32W & process )
23 { 25 {
24 return 0 == wcscmp( process.szExeFile, exact_exe_name ) ; 26 return 0 == wcscmp( process.szExeFile, exact_exe_name ) ;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 return p ; 62 return p ;
61 } 63 }
62 64
63 PROCESSENTRY32 process_empty = process_with_name( L"" ) ; 65 PROCESSENTRY32 process_empty = process_with_name( L"" ) ;
64 PROCESSENTRY32 process_exact = process_with_name( exact_exe_name ) ; 66 PROCESSENTRY32 process_exact = process_with_name( exact_exe_name ) ;
65 PROCESSENTRY32 process_mixedcase = process_with_name( mixedcase_exe_name ) ; 67 PROCESSENTRY32 process_mixedcase = process_with_name( mixedcase_exe_name ) ;
66 PROCESSENTRY32 process_explorer = process_with_name( L"explorer.exe" ) ; 68 PROCESSENTRY32 process_explorer = process_with_name( L"explorer.exe" ) ;
67 PROCESSENTRY32 process_absent = process_with_name( L"no_such_name" ) ; 69 PROCESSENTRY32 process_absent = process_with_name( L"no_such_name" ) ;
68 70
69 exe_name_set multiple_name_set( multiple_exe_names, 2 ) ; 71 exe_name_set multiple_name_set( multiple_exe_names, 2 ) ;
72 exe_name_set multiple_name_set_modules( multiple_module_names, 2 ) ;
73 exe_name_set non_existent_name_set_modules( non_existent_module_names, 1 ) ;
70 process_by_any_exe_name_CI find_in_set( multiple_name_set ) ; 74 process_by_any_exe_name_CI find_in_set( multiple_name_set ) ;
75 process_by_any_exe_name_CI_w_ABP find_in_set_w_kernel32( multiple_name_set, mult iple_name_set_modules ) ;
76 process_by_any_exe_name_CI_w_ABP find_in_set_w_non_existent( multiple_name_set, non_existent_name_set_modules ) ;
71 77
72 TEST( exe_name_set, validate_setup ) 78 TEST( exe_name_set, validate_setup )
73 { 79 {
74 ASSERT_EQ( 2u, multiple_name_set.size() ) ; 80 ASSERT_EQ( 2u, multiple_name_set.size() ) ;
75 ASSERT_TRUE( multiple_name_set.find( mixedcase_exe_name ) != multiple_name_set .end() ) ; 81 ASSERT_TRUE( multiple_name_set.find( mixedcase_exe_name ) != multiple_name_set .end() ) ;
76 ASSERT_TRUE( multiple_name_set.find( exact_exe_name ) != multiple_name_set.end () ) ; 82 ASSERT_TRUE( multiple_name_set.find( exact_exe_name ) != multiple_name_set.end () ) ;
77 ASSERT_TRUE( multiple_name_set.find( L"" ) == multiple_name_set.end() ) ; 83 ASSERT_TRUE( multiple_name_set.find( L"" ) == multiple_name_set.end() ) ;
78 ASSERT_TRUE( multiple_name_set.find( L"not-in-list" ) == multiple_name_set.end () ) ; 84 ASSERT_TRUE( multiple_name_set.find( L"not-in-list" ) == multiple_name_set.end () ) ;
79 } 85 }
80 86
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 } 237 }
232 238
233 TEST( pid_set, find_our_process_in_set ) 239 TEST( pid_set, find_our_process_in_set )
234 { 240 {
235 std::set< DWORD > s ; 241 std::set< DWORD > s ;
236 initialize_process_set( s, find_in_set, copy_PID() ) ; 242 initialize_process_set( s, find_in_set, copy_PID() ) ;
237 size_t size( s.size() ) ; 243 size_t size( s.size() ) ;
238 EXPECT_EQ( size, 1u ); 244 EXPECT_EQ( size, 1u );
239 ASSERT_GE( size, 1u ); 245 ASSERT_GE( size, 1u );
240 } 246 }
247
248 TEST( pid_set, find_our_process_in_set_w_kernel32 )
249 {
250 std::set< DWORD > s ;
251 initialize_process_set( s, find_in_set_w_kernel32, copy_PID() ) ;
252 size_t size( s.size() ) ;
253 EXPECT_EQ( size, 1u );
254 ASSERT_GE( size, 1u );
255 }
256 TEST( pid_set, find_our_process_in_set_w_non_existant )
257 {
258 std::set< DWORD > s ;
259 initialize_process_set( s, find_in_set_w_non_existent, copy_PID() ) ;
260 size_t size( s.size() ) ;
261 EXPECT_EQ( size, 0u );
262 ASSERT_GE( size, 0u );
263 }
OLDNEW

Powered by Google App Engine
This is Rietveld