Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "base/basictypes.h" | |
| 6 #include "base/shared_mutex.h" | |
| 7 #include "base/test/multiprocess_test.h" | |
| 8 #include "testing/multiprocess_func_list.h" | |
| 9 | |
| 10 namespace base { | |
| 11 | |
| 12 namespace { | |
| 13 const char kMutexName[] = "shared_mutex_unittest"; | |
|
agl
2010/11/08 23:57:49
just make it static for a single constant.
Mark Mentovai
2010/11/09 17:43:14
Don’t indent namespace contents.
dmac
2010/11/11 21:47:59
Done.
dmac
2010/11/11 21:47:59
Done.
| |
| 14 } | |
|
Mark Mentovai
2010/11/09 17:43:14
} // namespace
dmac
2010/11/11 21:47:59
Done.
| |
| 15 | |
| 16 class SharedMutexTest : public base::MultiProcessTest { | |
| 17 }; | |
| 18 | |
| 19 TEST_F(SharedMutexTest, SimpleLock) { | |
| 20 SharedMutex test_mutex(kMutexName); | |
| 21 EXPECT_TRUE(test_mutex.TryLock()); | |
| 22 base::ProcessHandle handle = SpawnChild("SharedMutexTryFailMain", false); | |
| 23 ASSERT_TRUE(handle); | |
| 24 int exit_code = 0; | |
| 25 EXPECT_TRUE(base::WaitForExitCode(handle, &exit_code)); | |
| 26 EXPECT_EQ(exit_code, 0); | |
| 27 test_mutex.Unlock(); | |
| 28 handle = SpawnChild("SharedMutexTrySucceedMain", false); | |
| 29 ASSERT_TRUE(handle); | |
| 30 EXPECT_TRUE(base::WaitForExitCode(handle, &exit_code)); | |
| 31 EXPECT_EQ(exit_code, 0); | |
| 32 } | |
| 33 | |
| 34 MULTIPROCESS_TEST_MAIN(SharedMutexTryFailMain) { | |
| 35 SharedMutex test_mutex(kMutexName); | |
| 36 EXPECT_FALSE(test_mutex.TryLock()); | |
| 37 return 0; | |
| 38 } | |
| 39 | |
| 40 | |
| 41 MULTIPROCESS_TEST_MAIN(SharedMutexTrySucceedMain) { | |
| 42 SharedMutex test_mutex(kMutexName); | |
| 43 EXPECT_TRUE(test_mutex.TryLock()); | |
| 44 return 0; | |
| 45 } | |
| 46 | |
| 47 } // namespace base | |
| OLD | NEW |