Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2049)

Unified Diff: chrome/common/multi_process_lock_unittest.cc

Issue 4721001: Add multi_process_lock to chrome/common (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: removed long name test as it tripped a NOTREACHED call. Created 10 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/common/multi_process_lock_unittest.cc
diff --git a/chrome/common/multi_process_lock_unittest.cc b/chrome/common/multi_process_lock_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..0743236691cca52028a52cceab1402c61a1de1b2
--- /dev/null
+++ b/chrome/common/multi_process_lock_unittest.cc
@@ -0,0 +1,48 @@
+// 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/scoped_ptr.h"
+#include "base/test/multiprocess_test.h"
+#include "chrome/common/multi_process_lock.h"
+#include "testing/multiprocess_func_list.h"
+
+static const char kMutexName[] = "shared_mutex_unittest";
+
+class MultiProcessLockTest : public base::MultiProcessTest {
+};
+
+TEST_F(MultiProcessLockTest, BasicCreationTest) {
+ // Test basic creation/destruction with no lock taken
+ scoped_ptr<MultiProcessLock> scoped(MultiProcessLock::Create(kMutexName));
+ scoped.reset(NULL);
+}
+
+TEST_F(MultiProcessLockTest, SimpleLock) {
+ scoped_ptr<MultiProcessLock> test_lock(MultiProcessLock::Create(kMutexName));
+ EXPECT_TRUE(test_lock->TryLock());
+ base::ProcessHandle handle = SpawnChild("MultiProcessLockTryFailMain", false);
+ ASSERT_TRUE(handle);
+ int exit_code = 0;
+ EXPECT_TRUE(base::WaitForExitCode(handle, &exit_code));
+ EXPECT_EQ(exit_code, 0);
+ test_lock->Unlock();
+ handle = SpawnChild("MultiProcessLockTrySucceedMain", false);
+ ASSERT_TRUE(handle);
+ EXPECT_TRUE(base::WaitForExitCode(handle, &exit_code));
+ EXPECT_EQ(exit_code, 0);
+}
+
+MULTIPROCESS_TEST_MAIN(MultiProcessLockTryFailMain) {
+ scoped_ptr<MultiProcessLock> test_lock(MultiProcessLock::Create(kMutexName));
+ EXPECT_FALSE(test_lock->TryLock());
+ return 0;
+}
+
+
+MULTIPROCESS_TEST_MAIN(MultiProcessLockTrySucceedMain) {
+ scoped_ptr<MultiProcessLock> test_lock(MultiProcessLock::Create(kMutexName));
+ EXPECT_TRUE(test_lock->TryLock());
+ return 0;
+}

Powered by Google App Engine
This is Rietveld 408576698