| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/threading/non_thread_safe.h" | 5 #include "base/threading/non_thread_safe.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 // Verify that DoStuff asserts in debug builds only when called | 106 // Verify that DoStuff asserts in debug builds only when called |
| 107 // on a different thread. | 107 // on a different thread. |
| 108 CallDoStuffOnThread call_on_thread(non_thread_safe_class.get()); | 108 CallDoStuffOnThread call_on_thread(non_thread_safe_class.get()); |
| 109 | 109 |
| 110 call_on_thread.Start(); | 110 call_on_thread.Start(); |
| 111 call_on_thread.Join(); | 111 call_on_thread.Join(); |
| 112 } | 112 } |
| 113 | 113 |
| 114 #if DCHECK_IS_ON() | 114 #if DCHECK_IS_ON() |
| 115 TEST(NonThreadSafeDeathTest, MethodNotAllowedOnDifferentThreadInDebug) { | 115 TEST(NonThreadSafeDeathTest, MethodNotAllowedOnDifferentThreadInDebug) { |
| 116 ASSERT_DCHECK_DEATH({ NonThreadSafeClass::MethodOnDifferentThreadImpl(); }, | 116 ASSERT_DCHECK_DEATH({ NonThreadSafeClass::MethodOnDifferentThreadImpl(); }); |
| 117 ""); | |
| 118 } | 117 } |
| 119 #else | 118 #else |
| 120 TEST(NonThreadSafeTest, MethodAllowedOnDifferentThreadInRelease) { | 119 TEST(NonThreadSafeTest, MethodAllowedOnDifferentThreadInRelease) { |
| 121 NonThreadSafeClass::MethodOnDifferentThreadImpl(); | 120 NonThreadSafeClass::MethodOnDifferentThreadImpl(); |
| 122 } | 121 } |
| 123 #endif // DCHECK_IS_ON() | 122 #endif // DCHECK_IS_ON() |
| 124 | 123 |
| 125 void NonThreadSafeClass::DestructorOnDifferentThreadImpl() { | 124 void NonThreadSafeClass::DestructorOnDifferentThreadImpl() { |
| 126 std::unique_ptr<NonThreadSafeClass> non_thread_safe_class( | 125 std::unique_ptr<NonThreadSafeClass> non_thread_safe_class( |
| 127 new NonThreadSafeClass); | 126 new NonThreadSafeClass); |
| 128 | 127 |
| 129 // Verify that the destructor asserts in debug builds only | 128 // Verify that the destructor asserts in debug builds only |
| 130 // when called on a different thread. | 129 // when called on a different thread. |
| 131 DeleteNonThreadSafeClassOnThread delete_on_thread( | 130 DeleteNonThreadSafeClassOnThread delete_on_thread( |
| 132 non_thread_safe_class.release()); | 131 non_thread_safe_class.release()); |
| 133 | 132 |
| 134 delete_on_thread.Start(); | 133 delete_on_thread.Start(); |
| 135 delete_on_thread.Join(); | 134 delete_on_thread.Join(); |
| 136 } | 135 } |
| 137 | 136 |
| 138 #if DCHECK_IS_ON() | 137 #if DCHECK_IS_ON() |
| 139 TEST(NonThreadSafeDeathTest, DestructorNotAllowedOnDifferentThreadInDebug) { | 138 TEST(NonThreadSafeDeathTest, DestructorNotAllowedOnDifferentThreadInDebug) { |
| 140 ASSERT_DCHECK_DEATH( | 139 ASSERT_DCHECK_DEATH( |
| 141 { NonThreadSafeClass::DestructorOnDifferentThreadImpl(); }, ""); | 140 { NonThreadSafeClass::DestructorOnDifferentThreadImpl(); }); |
| 142 } | 141 } |
| 143 #else | 142 #else |
| 144 TEST(NonThreadSafeTest, DestructorAllowedOnDifferentThreadInRelease) { | 143 TEST(NonThreadSafeTest, DestructorAllowedOnDifferentThreadInRelease) { |
| 145 NonThreadSafeClass::DestructorOnDifferentThreadImpl(); | 144 NonThreadSafeClass::DestructorOnDifferentThreadImpl(); |
| 146 } | 145 } |
| 147 #endif // DCHECK_IS_ON() | 146 #endif // DCHECK_IS_ON() |
| 148 | 147 |
| 149 } // namespace base | 148 } // namespace base |
| OLD | NEW |