Chromium Code Reviews| Index: base/shared_mutex_unittest.cc |
| diff --git a/base/shared_mutex_unittest.cc b/base/shared_mutex_unittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..f546e89af4c84b314683e604cf45a5125aefc69d |
| --- /dev/null |
| +++ b/base/shared_mutex_unittest.cc |
| @@ -0,0 +1,47 @@ |
| +// Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "base/basictypes.h" |
| +#include "base/shared_mutex.h" |
| +#include "base/test/multiprocess_test.h" |
| +#include "testing/multiprocess_func_list.h" |
| + |
| +namespace base { |
| + |
| +namespace { |
| + 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.
|
| +} |
|
Mark Mentovai
2010/11/09 17:43:14
} // namespace
dmac
2010/11/11 21:47:59
Done.
|
| + |
| +class SharedMutexTest : public base::MultiProcessTest { |
| +}; |
| + |
| +TEST_F(SharedMutexTest, SimpleLock) { |
| + SharedMutex test_mutex(kMutexName); |
| + EXPECT_TRUE(test_mutex.TryLock()); |
| + base::ProcessHandle handle = SpawnChild("SharedMutexTryFailMain", false); |
| + ASSERT_TRUE(handle); |
| + int exit_code = 0; |
| + EXPECT_TRUE(base::WaitForExitCode(handle, &exit_code)); |
| + EXPECT_EQ(exit_code, 0); |
| + test_mutex.Unlock(); |
| + handle = SpawnChild("SharedMutexTrySucceedMain", false); |
| + ASSERT_TRUE(handle); |
| + EXPECT_TRUE(base::WaitForExitCode(handle, &exit_code)); |
| + EXPECT_EQ(exit_code, 0); |
| +} |
| + |
| +MULTIPROCESS_TEST_MAIN(SharedMutexTryFailMain) { |
| + SharedMutex test_mutex(kMutexName); |
| + EXPECT_FALSE(test_mutex.TryLock()); |
| + return 0; |
| +} |
| + |
| + |
| +MULTIPROCESS_TEST_MAIN(SharedMutexTrySucceedMain) { |
| + SharedMutex test_mutex(kMutexName); |
| + EXPECT_TRUE(test_mutex.TryLock()); |
| + return 0; |
| +} |
| + |
| +} // namespace base |