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

Unified Diff: base/sequence_checker_unittest.cc

Issue 2869893003: New Sequence/Thread checking API. (Closed)
Patch Set: fix tests in non-dcheck builds, need fixture can't use lambdas Created 3 years, 7 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/sequence_checker.h ('k') | base/threading/non_thread_safe.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/sequence_checker_unittest.cc
diff --git a/base/sequence_checker_unittest.cc b/base/sequence_checker_unittest.cc
index 41fd77be63ff7f053f8a6901b677903f6b05d4c3..215a1073a468f9783fb4d4b3de6f1b2c5d1213f5 100644
--- a/base/sequence_checker_unittest.cc
+++ b/base/sequence_checker_unittest.cc
@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "base/sequence_checker.h"
+
#include <stddef.h>
#include <memory>
@@ -12,9 +14,9 @@
#include "base/callback_forward.h"
#include "base/macros.h"
#include "base/message_loop/message_loop.h"
-#include "base/sequence_checker_impl.h"
#include "base/sequence_token.h"
#include "base/single_thread_task_runner.h"
+#include "base/test/gtest_util.h"
#include "base/test/sequenced_worker_pool_owner.h"
#include "base/threading/simple_thread.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -256,4 +258,54 @@ TEST_F(SequenceCheckerTest,
second_pool_owner.pool()->FlushForTesting();
}
+namespace {
+
+// This fixture is a helper for unit testing the sequence checker macros as it
+// is not possible to inline ExpectDeathOnOtherSequence() and
+// ExpectNoDeathOnOtherSequenceAfterDetach() as lambdas since binding
+// |Unretained(&my_sequence_checker)| wouldn't compile on non-dcheck builds
+// where it won't be defined.
+class SequenceCheckerMacroTest : public SequenceCheckerTest {
+ public:
+ SequenceCheckerMacroTest() = default;
+
+ void ExpectDeathOnOtherSequence() {
+#if DCHECK_IS_ON()
+ EXPECT_DCHECK_DEATH(
+ { DCHECK_CALLED_ON_VALID_SEQUENCE(my_sequence_checker_); });
+#else
+ // Happily no-ops on non-dcheck builds.
+ DCHECK_CALLED_ON_VALID_SEQUENCE(my_sequence_checker_);
+#endif
+ }
+
+ void ExpectNoDeathOnOtherSequenceAfterDetach() {
+ DCHECK_CALLED_ON_VALID_SEQUENCE(my_sequence_checker_);
+ }
+
+ protected:
+ SEQUENCE_CHECKER(my_sequence_checker_);
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(SequenceCheckerMacroTest);
+};
+
+} // namespace
+
+TEST_F(SequenceCheckerMacroTest, Macros) {
+ PostToSequencedWorkerPool(
+ Bind(&SequenceCheckerMacroTest::ExpectDeathOnOtherSequence,
+ Unretained(this)),
+ "A");
+ FlushSequencedWorkerPoolForTesting();
+
+ DETACH_FROM_SEQUENCE(my_sequence_checker_);
+
+ PostToSequencedWorkerPool(
+ Bind(&SequenceCheckerMacroTest::ExpectNoDeathOnOtherSequenceAfterDetach,
+ Unretained(this)),
+ "A");
+ FlushSequencedWorkerPoolForTesting();
+}
+
} // namespace base
« no previous file with comments | « base/sequence_checker.h ('k') | base/threading/non_thread_safe.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698