summaryrefslogtreecommitdiffstats
path: root/base/cancellation_flag_unittest.cc
diff options
context:
space:
mode:
authortimurrrr@chromium.org <timurrrr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-12-03 21:11:34 +0000
committertimurrrr@chromium.org <timurrrr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-12-03 21:11:34 +0000
commitbaeb22f54fafa2b8394a7ccd74536ed7ccc23c34 (patch)
treeb5bfb16f735a2fe506b9aecf7dd0b8dead9c7dc8 /base/cancellation_flag_unittest.cc
parent36f5c5604d898b06763e0104980300c788e4ea48 (diff)
downloadchromium_src-baeb22f54fafa2b8394a7ccd74536ed7ccc23c34.zip
chromium_src-baeb22f54fafa2b8394a7ccd74536ed7ccc23c34.tar.gz
chromium_src-baeb22f54fafa2b8394a7ccd74536ed7ccc23c34.tar.bz2
Rename AtomicFlag to CancelFlag, change its semantics a bit
Review URL: http://codereview.chromium.org/454025 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@33723 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/cancellation_flag_unittest.cc')
-rw-r--r--base/cancellation_flag_unittest.cc74
1 files changed, 74 insertions, 0 deletions
diff --git a/base/cancellation_flag_unittest.cc b/base/cancellation_flag_unittest.cc
new file mode 100644
index 0000000..ffc8cf0
--- /dev/null
+++ b/base/cancellation_flag_unittest.cc
@@ -0,0 +1,74 @@
+// Copyright (c) 2009 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.
+
+// Tests of CancellationFlag class.
+
+#include "base/cancellation_flag.h"
+
+#include "base/logging.h"
+#include "base/spin_wait.h"
+#include "base/time.h"
+#include "base/thread.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "testing/platform_test.h"
+
+using base::CancellationFlag;
+using base::TimeDelta;
+using base::Thread;
+
+namespace {
+
+//------------------------------------------------------------------------------
+// Define our test class.
+//------------------------------------------------------------------------------
+
+class CancelTask : public Task {
+ public:
+ explicit CancelTask(CancellationFlag* flag) : flag_(flag) {}
+ virtual void Run() {
+ ASSERT_DEBUG_DEATH(flag_->Set(), "");
+ }
+ private:
+ CancellationFlag* flag_;
+};
+
+TEST(CancellationFlagTest, SimpleSingleThreadedTest) {
+ CancellationFlag flag;
+ ASSERT_FALSE(flag.IsSet());
+ flag.Set();
+ ASSERT_TRUE(flag.IsSet());
+}
+
+TEST(CancellationFlagTest, DoubleSetTest) {
+ CancellationFlag flag;
+ ASSERT_FALSE(flag.IsSet());
+ flag.Set();
+ ASSERT_TRUE(flag.IsSet());
+ flag.Set();
+ ASSERT_TRUE(flag.IsSet());
+}
+
+#if defined(OS_WIN)
+#define DISABLED_ON_WIN(x) DISABLED_##x
+#else
+#define DISABLED_ON_WIN(x) x
+#endif
+
+// CancellationFlag should die on a DCHECK if Set() is called from
+// other thread.
+// This test isn't Windows-friendly yet since ASSERT_DEATH doesn't catch tests
+// failed on DCHECK. See http://crbug.com/24885 for the details.
+TEST(CancellationFlagTest, DISABLED_ON_WIN(SetOnDifferentThreadDeathTest)) {
+ // Checks that Set() can't be called from any other thread.
+ ::testing::FLAGS_gtest_death_test_style = "threadsafe";
+ Thread t("CancellationFlagTest.SetOnDifferentThreadDeathTest");
+ ASSERT_TRUE(t.Start());
+ ASSERT_TRUE(t.message_loop());
+ ASSERT_TRUE(t.IsRunning());
+
+ CancellationFlag flag;
+ t.message_loop()->PostTask(FROM_HERE, new CancelTask(&flag));
+}
+
+} // namespace