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

Unified Diff: base/task_scheduler/scheduler_unique_stack_unittest.cc

Issue 1906813003: TaskScheduler: TimeDelta instead of TimeTicks in Task's constructor. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@sched_2c_owned_delegate
Patch Set: rebase Created 4 years, 8 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
Index: base/task_scheduler/scheduler_unique_stack_unittest.cc
diff --git a/base/task_scheduler/scheduler_unique_stack_unittest.cc b/base/task_scheduler/scheduler_unique_stack_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..8ef72dd2000ecb398d18ed37da07d102c97a8e2c
--- /dev/null
+++ b/base/task_scheduler/scheduler_unique_stack_unittest.cc
@@ -0,0 +1,110 @@
+// Copyright 2016 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/task_scheduler/scheduler_unique_stack.h"
+
+#include "base/task_scheduler/test_utils.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace base {
+namespace internal {
+
+// Verify that Push() and Pop() add/remove values in FIFO order.
+TEST(TaskSchedulerUniqueStackTest, PushPop) {
+ SchedulerUniqueStack<int> stack;
+ EXPECT_TRUE(stack.Empty());
+ EXPECT_EQ(0U, stack.Size());
+
+ stack.Push(1);
+ EXPECT_FALSE(stack.Empty());
+ EXPECT_EQ(1U, stack.Size());
+
+ stack.Push(2);
+ EXPECT_FALSE(stack.Empty());
+ EXPECT_EQ(2U, stack.Size());
+
+ stack.Push(3);
+ EXPECT_FALSE(stack.Empty());
+ EXPECT_EQ(3U, stack.Size());
+
+ EXPECT_EQ(3, stack.Pop());
+ EXPECT_FALSE(stack.Empty());
+ EXPECT_EQ(2U, stack.Size());
+
+ stack.Push(3);
+ EXPECT_FALSE(stack.Empty());
+ EXPECT_EQ(3U, stack.Size());
+
+ EXPECT_EQ(3, stack.Pop());
+ EXPECT_FALSE(stack.Empty());
+ EXPECT_EQ(2U, stack.Size());
+
+ EXPECT_EQ(2, stack.Pop());
+ EXPECT_FALSE(stack.Empty());
+ EXPECT_EQ(1U, stack.Size());
+
+ EXPECT_EQ(1, stack.Pop());
+ EXPECT_TRUE(stack.Empty());
+ EXPECT_EQ(0U, stack.Size());
+}
+
+// Verify that a value can be removed by Remove().
+TEST(TaskSchedulerUniqueStackTest, Remove) {
+ SchedulerUniqueStack<int> stack;
+ EXPECT_TRUE(stack.Empty());
+ EXPECT_EQ(0U, stack.Size());
+
+ stack.Push(1);
+ EXPECT_FALSE(stack.Empty());
+ EXPECT_EQ(1U, stack.Size());
+
+ stack.Push(2);
+ EXPECT_FALSE(stack.Empty());
+ EXPECT_EQ(2U, stack.Size());
+
+ stack.Push(3);
+ EXPECT_FALSE(stack.Empty());
+ EXPECT_EQ(3U, stack.Size());
+
+ stack.Remove(2);
+ EXPECT_FALSE(stack.Empty());
+ EXPECT_EQ(2U, stack.Size());
+
+ EXPECT_EQ(3, stack.Pop());
+ EXPECT_FALSE(stack.Empty());
+ EXPECT_EQ(1U, stack.Size());
+
+ EXPECT_EQ(1, stack.Pop());
+ EXPECT_TRUE(stack.Empty());
+ EXPECT_EQ(0U, stack.Size());
+}
+
+// Verify that a value can be pushed again after it has been removed.
+TEST(TaskSchedulerUniqueStackTest, PushAfterRemove) {
+ SchedulerUniqueStack<int> stack;
+ EXPECT_EQ(0U, stack.Size());
+ EXPECT_TRUE(stack.Empty());
+
+ stack.Push(5);
+ EXPECT_EQ(1U, stack.Size());
+ EXPECT_FALSE(stack.Empty());
+
+ stack.Remove(5);
+ EXPECT_EQ(0U, stack.Size());
+ EXPECT_TRUE(stack.Empty());
+
+ stack.Push(5);
+ EXPECT_EQ(1U, stack.Size());
+ EXPECT_FALSE(stack.Empty());
+}
+
+// Verify that Push() DCHECKs when a value is inserted twice.
+TEST(TaskSchedulerUniqueStackTest, PushTwice) {
+ SchedulerUniqueStack<int> stack;
+ stack.Push(5);
+ EXPECT_DCHECK_DEATH({ stack.Push(5); }, "");
+}
+
+} // namespace internal
+} // namespace base
« no previous file with comments | « base/task_scheduler/scheduler_unique_stack.h ('k') | base/task_scheduler/scheduler_worker_thread_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698