177 void TestMutexesCreated() |
177 void TestMutexesCreated() |
178 { |
178 { |
179 test.Next(_L("Test mutexes have been created")); |
179 test.Next(_L("Test mutexes have been created")); |
180 |
180 |
181 TFullName name; |
181 TFullName name; |
182 TFindMutex find; |
182 |
183 for (TInt i = 0 ; i < KObjectCount ; ++i) |
183 for (TInt i = 0 ; i < KObjectCount ; ++i) |
184 { |
184 { |
185 test(find.Next(name) == KErrNone); |
185 TFindMutex find(MutexName(i)); |
186 test.Printf(_L(" %02d: found handle %08x\n"), i, find.Handle()); |
186 test(find.Next(name) == KErrNone); |
187 test(name == MutexName(i)); |
187 test.Printf(_L(" %02d: found handle %08x\n"), i, find.Handle()); |
188 } |
188 } |
189 test(find.Next(name) == KErrNotFound); |
|
190 } |
189 } |
191 |
190 |
192 void TestMutexesDeleted() |
191 void TestMutexesDeleted() |
193 { |
192 { |
194 test.Next(_L("Test mutexes deleted")); |
193 test.Next(_L("Test mutexes deleted")); |
195 |
194 |
196 TFindMutex find; |
195 TFullName name; |
197 TFullName name; |
196 |
198 test(find.Next(name) == KErrNotFound); |
197 for (TInt i = 0 ; i < KObjectCount ; ++i) |
199 } |
198 { |
|
199 TFindMutex find(MutexName(i)); |
|
200 test(find.Next(name) == KErrNotFound); |
|
201 } |
|
202 } |
|
203 |
200 |
204 |
201 void TestFindSpecificMutex() |
205 void TestFindSpecificMutex() |
202 { |
206 { |
203 test.Next(_L("Test finding specific mutexes")); |
207 test.Next(_L("Test finding specific mutexes")); |
204 |
208 |
273 { |
277 { |
274 test.Next(_L("Test finding mutexes when the last found object has been deleted")); |
278 test.Next(_L("Test finding mutexes when the last found object has been deleted")); |
275 |
279 |
276 // Find and delete even mutexes |
280 // Find and delete even mutexes |
277 TFullName name; |
281 TFullName name; |
278 TFindMutex find2(KDoubleMatch); |
|
279 TInt i; |
282 TInt i; |
280 for (i = 0 ; i < KObjectCount ; i += 2) |
283 for (i = 0 ; i < KObjectCount ; i += 2) |
281 { |
284 { |
|
285 TFindMutex find2(MutexName(i)); |
282 test(find2.Next(name) == KErrNone); |
286 test(find2.Next(name) == KErrNone); |
283 test.Printf(_L(" %02d: found handle %08x\n"), i, find2.Handle()); |
287 test.Printf(_L(" %02d: found handle %08x\n"), i, find2.Handle()); |
284 test(name == MutexName(i)); |
|
285 Mutexes[i].Close(); |
288 Mutexes[i].Close(); |
286 RMutex mutex; |
289 RMutex mutex; |
287 test(mutex.Open(find2) == KErrNotFound); |
290 test(mutex.Open(find2) == KErrNotFound); |
288 } |
291 } |
289 test(find2.Next(name) == KErrNotFound); |
|
290 |
292 |
291 // Check odd mutexes remaining |
293 // Check odd mutexes remaining |
292 TFindMutex find; |
|
293 for (i = 1 ; i < KObjectCount ; i += 2) |
294 for (i = 1 ; i < KObjectCount ; i += 2) |
294 { |
295 { |
295 test(find.Next(name) == KErrNone); |
296 TFindMutex find(MutexName(i)); |
296 test(name == MutexName(i)); |
297 test(find.Next(name) == KErrNone); |
297 } |
298 } |
298 test(find2.Next(name) == KErrNotFound); |
|
299 } |
299 } |
300 |
300 |
301 void TestFindAndDeleteMutex2() |
301 void TestFindAndDeleteMutex2() |
302 { |
302 { |
303 test.Next(_L("Test finding mutexes when the last found object has moved in the container")); |
303 test.Next(_L("Test finding mutexes when the last found object has moved in the container")); |
304 |
304 |
305 // Find even mutexes and delete odd |
305 // Find even mutexes and delete odd |
306 TFullName name; |
306 TFullName name; |
307 TFindMutex find2(KDoubleMatch); |
|
308 TInt i; |
307 TInt i; |
309 for (i = 0 ; i < KObjectCount ; i += 2) |
308 for (i = 0 ; i < KObjectCount ; i += 2) |
310 { |
309 { |
|
310 TFindMutex find2(MutexName(i)); |
311 test(find2.Next(name) == KErrNone); |
311 test(find2.Next(name) == KErrNone); |
312 test.Printf(_L(" %02d: found handle %08x\n"), i, find2.Handle()); |
312 test.Printf(_L(" %02d: found handle %08x\n"), i, find2.Handle()); |
313 test(name == MutexName(i)); |
|
314 Mutexes[(i+KObjectCount-1)%KObjectCount].Close(); // -1%n = -1 or n-1, unspecified |
313 Mutexes[(i+KObjectCount-1)%KObjectCount].Close(); // -1%n = -1 or n-1, unspecified |
315 RMutex mutex; |
314 RMutex mutex; |
316 test(mutex.Open(find2) == KErrNone); |
315 test(mutex.Open(find2) == KErrNone); |
317 test(mutex.Name() == MutexName(i)); |
316 test(mutex.Name() == MutexName(i)); |
318 mutex.Close(); |
317 mutex.Close(); |
319 } |
318 } |
320 test(find2.Next(name) == KErrNotFound); |
|
321 |
319 |
322 // Check even mutexes remaining |
320 // Check even mutexes remaining |
323 TFindMutex find; |
|
324 for (i = 0 ; i < KObjectCount ; i += 2) |
321 for (i = 0 ; i < KObjectCount ; i += 2) |
325 { |
322 { |
326 test(find.Next(name) == KErrNone); |
323 TFindMutex find(MutexName(i)); |
327 test(name == MutexName(i)); |
324 test(find.Next(name) == KErrNone); |
328 } |
325 } |
329 test(find2.Next(name) == KErrNotFound); |
326 |
330 } |
327 } |
331 |
328 |
332 void TestFindWithCreation() |
329 void TestFindWithCreation() |
333 { |
330 { |
334 test.Next(_L("Test finding mutexes interleaved with creation")); |
331 test.Next(_L("Test finding mutexes interleaved with creation")); |
335 |
332 |
336 TFullName name; |
333 TFullName name; |
337 TFindMutex find; |
|
338 |
334 |
339 for (TInt i = 0 ; i < KObjectCount ; ++i) |
335 for (TInt i = 0 ; i < KObjectCount ; ++i) |
340 { |
336 { |
341 test(Mutexes[i].CreateGlobal(MutexName(i)) == KErrNone); |
337 test(Mutexes[i].CreateGlobal(MutexName(i)) == KErrNone); |
342 test(find.Next(name) == KErrNone); |
338 TFindMutex find(MutexName(i)); |
343 test.Printf(_L(" %02d: found handle %08x\n"), i, find.Handle()); |
339 test(find.Next(name) == KErrNone); |
344 test(name == MutexName(i)); |
340 test.Printf(_L(" %02d: found handle %08x\n"), i, find.Handle()); |
345 RMutex mutex; |
341 RMutex mutex; |
346 test(mutex.Open(find) == KErrNone); |
342 test(mutex.Open(find) == KErrNone); |
347 test(mutex.Name() == MutexName(i)); |
343 test(mutex.Name() == MutexName(i)); |
348 mutex.Close(); |
344 mutex.Close(); |
349 } |
345 } |
350 test(find.Next(name) == KErrNotFound); |
|
351 } |
346 } |
352 |
347 |
353 void TestFindWithCreation2() |
348 void TestFindWithCreation2() |
354 { |
349 { |
355 test.Next(_L("Test finding mutexes interleaved with creation and deletion")); |
350 test.Next(_L("Test finding mutexes interleaved with creation and deletion")); |
356 |
351 |
357 TFullName name; |
352 TFullName name; |
358 TFindMutex find; |
|
359 |
353 |
360 for (TInt i = 0 ; i < KObjectCount ; ++i) |
354 for (TInt i = 0 ; i < KObjectCount ; ++i) |
361 { |
355 { |
362 RMutex mutex; |
356 RMutex mutex; |
363 test(mutex.CreateGlobal(MutexName(0)) == KErrNone); |
357 test(mutex.CreateGlobal(MutexName(0)) == KErrNone); |
364 test(find.Next(name) == KErrNone); |
358 TFindMutex find(MutexName(0)); |
365 test.Printf(_L(" %02d: found handle %08x\n"), i, find.Handle()); |
359 test(find.Next(name) == KErrNone); |
366 test(name == MutexName(0)); |
360 test(name == MutexName(0)); |
|
361 test.Printf(_L(" %02d: found handle %08x\n"), i, find.Handle()); |
367 mutex.Close(); |
362 mutex.Close(); |
368 RMutex mutex2; |
363 |
369 test(mutex2.Open(find) == KErrNotFound); |
364 TFindMutex find2(MutexName(0)); |
370 } |
365 test(find2.Next(name) == KErrNotFound); |
371 test(find.Next(name) == KErrNotFound); |
366 } |
372 } |
367 } |
373 |
368 |
374 void TestFindHandleOutOfRange() |
369 void TestFindHandleOutOfRange() |
375 { |
370 { |
376 test.Next(_L("Test finding mutexes when find handle index is off the end of container's array")); |
371 test.Next(_L("Test finding mutexes when find handle index is off the end of container's array")); |
377 |
372 |
378 TFullName name; |
373 TFullName name; |
379 TFindMutex find; |
374 |
380 for (TInt i = 0 ; i < KObjectCount ; ++i) |
375 for (TInt i = 0 ; i < KObjectCount ; ++i) |
381 { |
376 { |
382 test(find.Next(name) == KErrNone); |
377 TFindMutex find(MutexName(i)); |
383 test.Printf(_L(" %02d: found handle %08x\n"), i, find.Handle()); |
378 test(find.Next(name) == KErrNone); |
384 test(name == MutexName(i)); |
379 test.Printf(_L(" %02d: found handle %08x\n"), i, find.Handle()); |
385 RMutex mutex; |
380 RMutex mutex; |
386 test(mutex.Open(find) == KErrNone); |
381 test(mutex.Open(find) == KErrNone); |
387 test(mutex.Name() == MutexName(i)); |
382 test(mutex.Name() == MutexName(i)); |
388 mutex.Close(); |
383 mutex.Close(); |
389 |
384 |