Brian Carlstrom | cd74c4b | 2012-01-23 13:21:00 -0800 | [diff] [blame^] | 1 | // Copyright 2012 Google Inc. All Rights Reserved. |
| 2 | |
| 3 | #include "mutex.h" |
| 4 | |
| 5 | #include "gtest/gtest.h" |
| 6 | |
| 7 | namespace art { |
| 8 | |
| 9 | TEST(Mutex, LockUnlock) { |
| 10 | Mutex mu("test mutex"); |
| 11 | mu.AssertDepth(0U); |
| 12 | mu.Lock(); |
| 13 | mu.AssertDepth(1U); |
| 14 | mu.Unlock(); |
| 15 | mu.AssertDepth(0U); |
| 16 | } |
| 17 | |
| 18 | TEST(Mutex, TryLockUnlock) { |
| 19 | Mutex mu("test mutex"); |
| 20 | mu.AssertDepth(0U); |
| 21 | mu.TryLock(); |
| 22 | mu.AssertDepth(1U); |
| 23 | mu.Unlock(); |
| 24 | mu.AssertDepth(0U); |
| 25 | } |
| 26 | |
| 27 | TEST(Mutex, RecursiveLockUnlock) { |
| 28 | Mutex mu("test mutex"); |
| 29 | mu.AssertDepth(0U); |
| 30 | mu.Lock(); |
| 31 | mu.AssertDepth(1U); |
| 32 | mu.Lock(); |
| 33 | mu.AssertDepth(2U); |
| 34 | mu.Unlock(); |
| 35 | mu.AssertDepth(1U); |
| 36 | mu.Unlock(); |
| 37 | mu.AssertDepth(0U); |
| 38 | } |
| 39 | |
| 40 | TEST(Mutex, RecursiveTryLockUnlock) { |
| 41 | Mutex mu("test mutex"); |
| 42 | mu.AssertDepth(0U); |
| 43 | mu.TryLock(); |
| 44 | mu.AssertDepth(1U); |
| 45 | mu.TryLock(); |
| 46 | mu.AssertDepth(2U); |
| 47 | mu.Unlock(); |
| 48 | mu.AssertDepth(1U); |
| 49 | mu.Unlock(); |
| 50 | mu.AssertDepth(0U); |
| 51 | } |
| 52 | |
| 53 | } // namespace art |