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 //------------------------------------------------------- |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 | 177 |
178 //------------------------------------------------------- | 178 //------------------------------------------------------- |
179 // Single-snapshot version of initializers | 179 // Single-snapshot version of initializers |
180 //------------------------------------------------------- | 180 //------------------------------------------------------- |
181 /** | 181 /** |
182 * Single-snapshot version of initialize_process_list, for testing. | 182 * Single-snapshot version of initialize_process_list, for testing. |
183 */ | 183 */ |
184 template< class T, class Admittance, class Extractor > | 184 template< class T, class Admittance, class Extractor > |
185 void initialize_process_list( std::vector< T > & v, Admittance admit = Admittanc
e(), Extractor extract = Extractor() ) | 185 void initialize_process_list( std::vector< T > & v, Admittance admit = Admittanc
e(), Extractor extract = Extractor() ) |
186 { | 186 { |
187 initialize_process_list( v, Snapshot(), admit, extract ) ; | 187 initialize_process_list( v, Process_Snapshot(), admit, extract ) ; |
188 } | 188 } |
189 | 189 |
190 /** | 190 /** |
191 * Single-snapshot version of initialize_process_set, for testing. | 191 * Single-snapshot version of initialize_process_set, for testing. |
192 */ | 192 */ |
193 template< class T, class Admittance, class Extractor > | 193 template< class T, class Admittance, class Extractor > |
194 void initialize_process_set( std::set< T > & s, Admittance admit = Admittance(),
Extractor extract = Extractor() ) | 194 void initialize_process_set( std::set< T > & s, Admittance admit = Admittance(),
Extractor extract = Extractor() ) |
195 { | 195 { |
196 initialize_process_set( s, Snapshot(), admit, extract ) ; | 196 initialize_process_set( s, Process_Snapshot(), admit, extract ) ; |
197 } | 197 } |
198 | 198 |
199 //------------------------------------------------------- | 199 //------------------------------------------------------- |
200 // TESTS with snapshots | 200 // TESTS with snapshots |
201 //------------------------------------------------------- | 201 //------------------------------------------------------- |
202 /** | 202 /** |
203 * Construction test ensures that we don't throw and that at least one process s
hows up. | 203 * Construction test ensures that we don't throw and that at least one process s
hows up. |
204 */ | 204 */ |
205 TEST( Process_List_Test, construct_vector ) | 205 TEST( Process_List_Test, construct_vector ) |
206 { | 206 { |
207 std::vector< PROCESSENTRY32W > v ; | 207 std::vector< PROCESSENTRY32W > v ; |
208 initialize_process_list( v, every_process(), copy_all() ) ; | 208 initialize_process_list( v, every_process(), copy_all() ) ; |
209 ASSERT_GE( v.size(), 1u ); | 209 ASSERT_GE( v.size(), 1u ); |
210 } | 210 } |
211 | 211 |
212 /** | 212 /** |
213 * The only process we are really guaranteed to have is this test process itself
. | 213 * The only process we are really guaranteed to have is this test process itself
. |
214 */ | 214 */ |
215 TEST( Process_List_Test, find_our_process ) | 215 TEST( Process_List_Test, find_our_process ) |
216 { | 216 { |
217 std::vector< PROCESSENTRY32W > v ; | 217 std::vector< PROCESSENTRY32W > v ; |
218 initialize_process_list( v, our_process_by_name(), copy_all() ) ; | 218 initialize_process_list( v, our_process_by_name(), copy_all() ) ; |
219 unsigned int size( v.size() ); | 219 size_t size( v.size() ); |
220 EXPECT_EQ( 1u, size ); // Please, don't run multiple test executables simul
taneously | 220 EXPECT_EQ( 1u, size ); // Please, don't run multiple test executables simul
taneously |
221 ASSERT_GE( 1u, size ); | 221 ASSERT_GE( 1u, size ); |
222 } | 222 } |
223 | 223 |
224 /** | 224 /** |
225 * The only process we are really guaranteed to have is this test process itself
. | 225 * The only process we are really guaranteed to have is this test process itself
. |
226 * This test uses same one used in Process_Closer | 226 * This test uses same one used in Process_Closer |
227 */ | 227 */ |
228 TEST( Process_List_Test, find_our_process_CI_generic ) | 228 TEST( Process_List_Test, find_our_process_CI_generic ) |
229 { | 229 { |
230 std::vector< PROCESSENTRY32W > v ; | 230 std::vector< PROCESSENTRY32W > v ; |
231 initialize_process_list( v, process_by_name_CI( mixedcase_exe_name ), copy_all
() ) ; | 231 initialize_process_list( v, process_by_name_CI( mixedcase_exe_name ), copy_all
() ) ; |
232 unsigned int size( v.size() ); | 232 size_t size( v.size() ); |
233 EXPECT_EQ( 1u, size ); // Please, don't run multiple test executables simul
taneously | 233 EXPECT_EQ( 1u, size ); // Please, don't run multiple test executables simul
taneously |
234 ASSERT_GE( 1u, size ); | 234 ASSERT_GE( 1u, size ); |
235 } | 235 } |
236 | 236 |
237 /** | 237 /** |
238 * The only process we are really guaranteed to have is this test process itself
. | 238 * The only process we are really guaranteed to have is this test process itself
. |
239 * This test uses the generic filter function. | 239 * This test uses the generic filter function. |
240 */ | 240 */ |
241 TEST( Process_List_Test, find_our_process_CI_as_used ) | 241 TEST( Process_List_Test, find_our_process_CI_as_used ) |
242 { | 242 { |
243 std::vector< PROCESSENTRY32W > v ; | 243 std::vector< PROCESSENTRY32W > v ; |
244 initialize_process_list( v, process_by_any_file_name_CI( file_name_set( multip
le_exe_names ) ), copy_all() ) ; | 244 initialize_process_list( v, process_by_any_file_name_CI( file_name_set( multip
le_exe_names ) ), copy_all() ) ; |
245 unsigned int size( v.size() ); | 245 size_t size( v.size() ); |
246 EXPECT_EQ( 1u, size ); // Please, don't run multiple test executables simul
taneously | 246 EXPECT_EQ( 1u, size ); // Please, don't run multiple test executables simul
taneously |
247 ASSERT_GE( 1u, size ); | 247 ASSERT_GE( 1u, size ); |
248 } | 248 } |
249 | 249 |
250 /** | 250 /** |
251 * Locate the PID of our process. | 251 * Locate the PID of our process. |
252 */ | 252 */ |
253 TEST( Process_List_Test, find_our_PID ) | 253 TEST( Process_List_Test, find_our_PID ) |
254 { | 254 { |
255 std::vector< DWORD > v ; | 255 std::vector< DWORD > v ; |
256 initialize_process_list( v, our_process_by_name(), copy_PID() ) ; | 256 initialize_process_list( v, our_process_by_name(), copy_PID() ) ; |
257 unsigned int size( v.size() ); | 257 size_t size( v.size() ); |
258 EXPECT_EQ( size, 1u ); // Please, don't run multiple test executables simul
taneously | 258 EXPECT_EQ( size, 1u ); // Please, don't run multiple test executables simul
taneously |
259 ASSERT_GE( size, 1u ); | 259 ASSERT_GE( size, 1u ); |
260 } | 260 } |
261 | 261 |
262 /** | 262 /** |
263 * Locate the PID of our process using the | 263 * Locate the PID of our process using the |
264 */ | 264 */ |
265 TEST( Process_List_Test, find_our_process_in_set ) | 265 TEST( Process_List_Test, find_our_process_in_set ) |
266 { | 266 { |
267 std::vector< DWORD > v ; | 267 std::vector< DWORD > v ; |
268 initialize_process_list( v, find_in_set, copy_PID() ) ; | 268 initialize_process_list( v, find_in_set, copy_PID() ) ; |
269 unsigned int size( v.size() ); | 269 size_t size( v.size() ); |
270 EXPECT_EQ( size, 1u ); // Please, don't run multiple test executables simul
taneously | 270 EXPECT_EQ( size, 1u ); // Please, don't run multiple test executables simul
taneously |
271 ASSERT_GE( size, 1u ); | 271 ASSERT_GE( size, 1u ); |
272 } | 272 } |
273 | 273 |
274 //------------------------------------------------------- | 274 //------------------------------------------------------- |
275 // TESTS for process ID sets | 275 // TESTS for process ID sets |
276 //------------------------------------------------------- | 276 //------------------------------------------------------- |
277 /* | 277 /* |
278 * Can't use copy_all without a definition for "less< PROCESSENTRY32W >". | 278 * Can't use copy_all without a definition for "less< PROCESSENTRY32W >". |
279 * Thus all tests only use copy_PID | 279 * Thus all tests only use copy_PID |
(...skipping 27 matching lines...) Expand all Loading... |
307 ASSERT_GE( size, 1u ); | 307 ASSERT_GE( size, 1u ); |
308 } | 308 } |
309 TEST( pid_set, find_our_process_in_set_w_non_existant ) | 309 TEST( pid_set, find_our_process_in_set_w_non_existant ) |
310 { | 310 { |
311 std::set< DWORD > s ; | 311 std::set< DWORD > s ; |
312 initialize_process_set( s, find_in_set_w_non_existent, copy_PID() ) ; | 312 initialize_process_set( s, find_in_set_w_non_existent, copy_PID() ) ; |
313 size_t size( s.size() ) ; | 313 size_t size( s.size() ) ; |
314 EXPECT_EQ( size, 0u ); | 314 EXPECT_EQ( size, 0u ); |
315 ASSERT_GE( size, 0u ); | 315 ASSERT_GE( size, 0u ); |
316 } | 316 } |
OLD | NEW |