summaryrefslogtreecommitdiffstats
path: root/base/test/test_pending_task_unittest.cc
diff options
context:
space:
mode:
authormithro <mithro@mithis.com>2014-08-28 05:38:12 -0700
committerCommit bot <commit-bot@chromium.org>2014-08-28 12:39:30 +0000
commite120a88b850d51b1db67ea693652a8c855610fb6 (patch)
treee753de0df3a32f9b526dabd20d57f9cdf421f50e /base/test/test_pending_task_unittest.cc
parent287ca0fe18fdf242706025626cd1652f2daab6dc (diff)
downloadchromium_src-e120a88b850d51b1db67ea693652a8c855610fb6.zip
chromium_src-e120a88b850d51b1db67ea693652a8c855610fb6.tar.gz
chromium_src-e120a88b850d51b1db67ea693652a8c855610fb6.tar.bz2
Adding tracing and gtest pretty printing support to TestPendingTask.
These functions where invaluable when trying to debug and fix the cc::OrderedTestRunner as they let me easily inspect the tasks without having to fire up GDB. They should also be useful in development / testing of other task runners. Added a very simple test for ShouldRunBefore which shows this stuff working. If that test fails, the output looks like the following; ------------------------------------------------------------------------------- ../../base/test/test_pending_task_unittest.cc:49: Failure Value of: task_after.ShouldRunBefore(task_first) Actual: false Expected: true TestPendingTask( {"delay":2000,"nestability":"NESTABLE","post_time":0, "posting_function":"Unknown@Unknown:-1","run_at":2000} ).ShouldRunBefore(TestPendingTask( {"delay":1000,"nestability":"NESTABLE","post_time":0, "posting_function":"Unknown@Unknown:-1","run_at":1000}) ) ------------------------------------------------------------------------------- BUG=380889 Review URL: https://codereview.chromium.org/491743002 Cr-Commit-Position: refs/heads/master@{#292370}
Diffstat (limited to 'base/test/test_pending_task_unittest.cc')
-rw-r--r--base/test/test_pending_task_unittest.cc55
1 files changed, 55 insertions, 0 deletions
diff --git a/base/test/test_pending_task_unittest.cc b/base/test/test_pending_task_unittest.cc
new file mode 100644
index 0000000..4a6bd242
--- /dev/null
+++ b/base/test/test_pending_task_unittest.cc
@@ -0,0 +1,55 @@
+// Copyright (c) 2012 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/test/test_pending_task.h"
+
+#include "base/bind.h"
+#include "base/debug/trace_event.h"
+#include "testing/gmock/include/gmock/gmock.h"
+#include "testing/gtest/include/gtest/gtest-spi.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace {
+
+TEST(TestPendingTaskTest, TraceSupport) {
+ base::TestPendingTask task;
+
+ // Check that TestPendingTask can be sent to the trace subsystem.
+ TRACE_EVENT1("test", "TestPendingTask::TraceSupport", "task", task.AsValue());
+
+ // Just a basic check that the trace output has *something* in it.
+ EXPECT_THAT(task.AsValue()->ToString(), ::testing::HasSubstr("post_time"));
+}
+
+TEST(TestPendingTaskTest, ToString) {
+ base::TestPendingTask task;
+
+ // Just a basic check that ToString has *something* in it.
+ EXPECT_THAT(task.ToString(), ::testing::StartsWith("TestPendingTask("));
+}
+
+TEST(TestPendingTaskTest, GTestPrettyPrint) {
+ base::TestPendingTask task;
+
+ // Check that gtest is calling the TestPendingTask's PrintTo method.
+ EXPECT_THAT(::testing::PrintToString(task),
+ ::testing::StartsWith("TestPendingTask("));
+
+ // Check that pretty printing works with the gtest iostreams operator.
+ EXPECT_NONFATAL_FAILURE(EXPECT_TRUE(false) << task, "TestPendingTask(");
+}
+
+TEST(TestPendingTaskTest, ShouldRunBefore) {
+ base::TestPendingTask task_first;
+ task_first.delay = base::TimeDelta::FromMilliseconds(1);
+ base::TestPendingTask task_after;
+ task_after.delay = base::TimeDelta::FromMilliseconds(2);
+
+ EXPECT_FALSE(task_after.ShouldRunBefore(task_first))
+ << task_after << ".ShouldRunBefore(" << task_first << ")\n";
+ EXPECT_TRUE(task_first.ShouldRunBefore(task_after))
+ << task_first << ".ShouldRunBefore(" << task_after << ")\n";
+}
+
+} // namespace