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

Unified Diff: base/threading/non_thread_safe_unittest.cc

Issue 6599004: Modify ThreadChecker and NonThreadSafe so that their functionality is (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: update copyright year for new/moved files Created 9 years, 10 months 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
« no previous file with comments | « base/threading/non_thread_safe_impl.cc ('k') | base/threading/thread_checker.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/threading/non_thread_safe_unittest.cc
diff --git a/base/threading/non_thread_safe_unittest.cc b/base/threading/non_thread_safe_unittest.cc
index 7d158cf24950d7d4c002aa0d40c16ad43d08186c..b79a4f4934fa39a3905535be32de26ac5457b947 100644
--- a/base/threading/non_thread_safe_unittest.cc
+++ b/base/threading/non_thread_safe_unittest.cc
@@ -9,8 +9,6 @@
#include "base/threading/simple_thread.h"
#include "testing/gtest/include/gtest/gtest.h"
-#ifndef NDEBUG
-
namespace base {
// Simple class to exersice the basics of NonThreadSafe.
@@ -22,13 +20,16 @@ class NonThreadSafeClass : public NonThreadSafe {
// Verifies that it was called on the same thread as the constructor.
void DoStuff() {
- DCHECK(CalledOnValidThread());
+ CHECK(CalledOnValidThread());
}
void DetachFromThread() {
NonThreadSafe::DetachFromThread();
}
+ static void MethodOnDifferentThreadImpl();
+ static void DestructorOnDifferentThreadImpl();
+
private:
DISALLOW_COPY_AND_ASSIGN(NonThreadSafeClass);
};
@@ -94,37 +95,57 @@ TEST(NonThreadSafeTest, DetachThenDestructOnDifferentThread) {
delete_on_thread.Join();
}
-#if GTEST_HAS_DEATH_TEST
+#if GTEST_HAS_DEATH_TEST || NDEBUG
-TEST(NonThreadSafeDeathTest, MethodNotAllowedOnDifferentThread) {
- ASSERT_DEBUG_DEATH({
- scoped_ptr<NonThreadSafeClass> non_thread_safe_class(
- new NonThreadSafeClass);
+void NonThreadSafeClass::MethodOnDifferentThreadImpl() {
+ scoped_ptr<NonThreadSafeClass> non_thread_safe_class(
+ new NonThreadSafeClass);
- // Verify that DoStuff asserts when called on a different thread.
- CallDoStuffOnThread call_on_thread(non_thread_safe_class.get());
+ // Verify that DoStuff asserts in debug builds only when called
+ // on a different thread.
+ CallDoStuffOnThread call_on_thread(non_thread_safe_class.get());
- call_on_thread.Start();
- call_on_thread.Join();
- }, "");
+ call_on_thread.Start();
+ call_on_thread.Join();
}
-TEST(NonThreadSafeDeathTest, DestructorNotAllowedOnDifferentThread) {
+#ifndef NDEBUG
+TEST(NonThreadSafeDeathTest, MethodNotAllowedOnDifferentThreadInDebug) {
ASSERT_DEBUG_DEATH({
- scoped_ptr<NonThreadSafeClass> non_thread_safe_class(
- new NonThreadSafeClass);
+ NonThreadSafeClass::MethodOnDifferentThreadImpl();
+ }, "");
+}
+#else
+TEST(NonThreadSafeTest, MethodAllowedOnDifferentThreadInRelease) {
+ NonThreadSafeClass::MethodOnDifferentThreadImpl();
+}
+#endif // NDEBUG
- // Verify that the destructor asserts when called on a different thread.
- DeleteNonThreadSafeClassOnThread delete_on_thread(
- non_thread_safe_class.release());
+void NonThreadSafeClass::DestructorOnDifferentThreadImpl() {
+ scoped_ptr<NonThreadSafeClass> non_thread_safe_class(
+ new NonThreadSafeClass);
- delete_on_thread.Start();
- delete_on_thread.Join();
+ // Verify that the destructor asserts in debug builds only
+ // when called on a different thread.
+ DeleteNonThreadSafeClassOnThread delete_on_thread(
+ non_thread_safe_class.release());
+
+ delete_on_thread.Start();
+ delete_on_thread.Join();
+}
+
+#ifndef NDEBUG
+TEST(NonThreadSafeDeathTest, DestructorNotAllowedOnDifferentThreadInDebug) {
+ ASSERT_DEBUG_DEATH({
+ NonThreadSafeClass::DestructorOnDifferentThreadImpl();
}, "");
}
+#else
+TEST(NonThreadSafeTest, DestructorAllowedOnDifferentThreadInRelease) {
+ NonThreadSafeClass::DestructorOnDifferentThreadImpl();
+}
+#endif // NDEBUG
-#endif // GTEST_HAS_DEATH_TEST
+#endif // GTEST_HAS_DEATH_TEST || NDEBUG
} // namespace base
-
-#endif // NDEBUG
« no previous file with comments | « base/threading/non_thread_safe_impl.cc ('k') | base/threading/thread_checker.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698