| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "mojo/public/cpp/utility/mutex.h" | 5 #include "mojo/public/cpp/utility/mutex.h" |
| 6 | 6 |
| 7 #include <stdlib.h> // For |rand()|. | 7 #include <stdlib.h> // For |rand()|. |
| 8 #include <time.h> // For |nanosleep()| (defined by POSIX). | 8 #include <time.h> // For |nanosleep()| (defined by POSIX). |
| 9 | 9 |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 EXPECT_TRUE(thread.try_lock_succeeded()); | 218 EXPECT_TRUE(thread.try_lock_succeeded()); |
| 219 } | 219 } |
| 220 } | 220 } |
| 221 | 221 |
| 222 | 222 |
| 223 // Tests of assertions for Debug builds. | 223 // Tests of assertions for Debug builds. |
| 224 #if !defined(NDEBUG) | 224 #if !defined(NDEBUG) |
| 225 // Test |AssertHeld()| (which is an actual user API). | 225 // Test |AssertHeld()| (which is an actual user API). |
| 226 TEST(MutexTest, DebugAssertHeldFailure) { | 226 TEST(MutexTest, DebugAssertHeldFailure) { |
| 227 Mutex mutex; | 227 Mutex mutex; |
| 228 EXPECT_DEATH(mutex.AssertHeld(), ""); | 228 EXPECT_DEATH_IF_SUPPORTED(mutex.AssertHeld(), ""); |
| 229 } | 229 } |
| 230 | 230 |
| 231 // Test other consistency checks. | 231 // Test other consistency checks. |
| 232 TEST(MutexTest, DebugAssertionFailures) { | 232 TEST(MutexTest, DebugAssertionFailures) { |
| 233 // Unlock without lock held. | 233 // Unlock without lock held. |
| 234 EXPECT_DEATH({ | 234 EXPECT_DEATH_IF_SUPPORTED({ |
| 235 Mutex mutex; | 235 Mutex mutex; |
| 236 mutex.Unlock(); | 236 mutex.Unlock(); |
| 237 }, ""); | 237 }, ""); |
| 238 | 238 |
| 239 // Lock with lock held (on same thread). | 239 // Lock with lock held (on same thread). |
| 240 EXPECT_DEATH({ | 240 EXPECT_DEATH_IF_SUPPORTED({ |
| 241 Mutex mutex; | 241 Mutex mutex; |
| 242 mutex.Lock(); | 242 mutex.Lock(); |
| 243 mutex.Lock(); | 243 mutex.Lock(); |
| 244 }, ""); | 244 }, ""); |
| 245 | 245 |
| 246 // Try lock with lock held. | 246 // Try lock with lock held. |
| 247 EXPECT_DEATH({ | 247 EXPECT_DEATH_IF_SUPPORTED({ |
| 248 Mutex mutex; | 248 Mutex mutex; |
| 249 mutex.Lock(); | 249 mutex.Lock(); |
| 250 mutex.TryLock(); | 250 mutex.TryLock(); |
| 251 }, ""); | 251 }, ""); |
| 252 | 252 |
| 253 // Destroy lock with lock held. | 253 // Destroy lock with lock held. |
| 254 EXPECT_DEATH({ | 254 EXPECT_DEATH_IF_SUPPORTED({ |
| 255 Mutex mutex; | 255 Mutex mutex; |
| 256 mutex.Lock(); | 256 mutex.Lock(); |
| 257 }, ""); | 257 }, ""); |
| 258 } | 258 } |
| 259 #endif // !defined(NDEBUG) | 259 #endif // !defined(NDEBUG) |
| 260 | 260 |
| 261 } // namespace | 261 } // namespace |
| 262 } // namespace mojo | 262 } // namespace mojo |
| OLD | NEW |