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

Side by Side Diff: base/task_scheduler/scheduler_unique_stack_unittest.cc

Issue 2068803002: Remove SchedulerUniqueStack (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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 unified diff | Download patch
« no previous file with comments | « base/task_scheduler/scheduler_unique_stack.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "base/task_scheduler/scheduler_unique_stack.h"
6
7 #include "base/task_scheduler/test_utils.h"
8 #include "testing/gtest/include/gtest/gtest.h"
9
10 namespace base {
11 namespace internal {
12
13 // Verify that Push() and Pop() add/remove values in FIFO order.
14 TEST(TaskSchedulerUniqueStackTest, PushPop) {
15 SchedulerUniqueStack<int> stack;
16 EXPECT_TRUE(stack.Empty());
17 EXPECT_EQ(0U, stack.Size());
18
19 stack.Push(1);
20 EXPECT_FALSE(stack.Empty());
21 EXPECT_EQ(1U, stack.Size());
22
23 stack.Push(2);
24 EXPECT_FALSE(stack.Empty());
25 EXPECT_EQ(2U, stack.Size());
26
27 stack.Push(3);
28 EXPECT_FALSE(stack.Empty());
29 EXPECT_EQ(3U, stack.Size());
30
31 EXPECT_EQ(3, stack.Pop());
32 EXPECT_FALSE(stack.Empty());
33 EXPECT_EQ(2U, stack.Size());
34
35 stack.Push(3);
36 EXPECT_FALSE(stack.Empty());
37 EXPECT_EQ(3U, stack.Size());
38
39 EXPECT_EQ(3, stack.Pop());
40 EXPECT_FALSE(stack.Empty());
41 EXPECT_EQ(2U, stack.Size());
42
43 EXPECT_EQ(2, stack.Pop());
44 EXPECT_FALSE(stack.Empty());
45 EXPECT_EQ(1U, stack.Size());
46
47 EXPECT_EQ(1, stack.Pop());
48 EXPECT_TRUE(stack.Empty());
49 EXPECT_EQ(0U, stack.Size());
50 }
51
52 // Verify that a value can be removed by Remove().
53 TEST(TaskSchedulerUniqueStackTest, Remove) {
54 SchedulerUniqueStack<int> stack;
55 EXPECT_TRUE(stack.Empty());
56 EXPECT_EQ(0U, stack.Size());
57
58 stack.Push(1);
59 EXPECT_FALSE(stack.Empty());
60 EXPECT_EQ(1U, stack.Size());
61
62 stack.Push(2);
63 EXPECT_FALSE(stack.Empty());
64 EXPECT_EQ(2U, stack.Size());
65
66 stack.Push(3);
67 EXPECT_FALSE(stack.Empty());
68 EXPECT_EQ(3U, stack.Size());
69
70 stack.Remove(2);
71 EXPECT_FALSE(stack.Empty());
72 EXPECT_EQ(2U, stack.Size());
73
74 EXPECT_EQ(3, stack.Pop());
75 EXPECT_FALSE(stack.Empty());
76 EXPECT_EQ(1U, stack.Size());
77
78 EXPECT_EQ(1, stack.Pop());
79 EXPECT_TRUE(stack.Empty());
80 EXPECT_EQ(0U, stack.Size());
81 }
82
83 // Verify that a value can be pushed again after it has been removed.
84 TEST(TaskSchedulerUniqueStackTest, PushAfterRemove) {
85 SchedulerUniqueStack<int> stack;
86 EXPECT_EQ(0U, stack.Size());
87 EXPECT_TRUE(stack.Empty());
88
89 stack.Push(5);
90 EXPECT_EQ(1U, stack.Size());
91 EXPECT_FALSE(stack.Empty());
92
93 stack.Remove(5);
94 EXPECT_EQ(0U, stack.Size());
95 EXPECT_TRUE(stack.Empty());
96
97 stack.Push(5);
98 EXPECT_EQ(1U, stack.Size());
99 EXPECT_FALSE(stack.Empty());
100 }
101
102 // Verify that Push() DCHECKs when a value is inserted twice.
103 TEST(TaskSchedulerUniqueStackTest, PushTwice) {
104 SchedulerUniqueStack<int> stack;
105 stack.Push(5);
106 EXPECT_DCHECK_DEATH({ stack.Push(5); }, "");
107 }
108
109 } // namespace internal
110 } // namespace base
OLDNEW
« no previous file with comments | « base/task_scheduler/scheduler_unique_stack.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698