Line data Source code
1 : // Copyright 2015 the V8 project 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 "src/locked-queue-inl.h"
6 : #include "testing/gtest/include/gtest/gtest.h"
7 :
8 : namespace {
9 :
10 : typedef int Record;
11 :
12 : } // namespace
13 :
14 : namespace v8 {
15 : namespace internal {
16 :
17 15443 : TEST(LockedQueue, ConstructorEmpty) {
18 2 : LockedQueue<Record> queue;
19 2 : EXPECT_TRUE(queue.IsEmpty());
20 1 : }
21 :
22 :
23 15443 : TEST(LockedQueue, SingleRecordEnqueueDequeue) {
24 2 : LockedQueue<Record> queue;
25 2 : EXPECT_TRUE(queue.IsEmpty());
26 1 : queue.Enqueue(1);
27 2 : EXPECT_FALSE(queue.IsEmpty());
28 1 : Record a = -1;
29 1 : bool success = queue.Dequeue(&a);
30 1 : EXPECT_TRUE(success);
31 2 : EXPECT_EQ(a, 1);
32 2 : EXPECT_TRUE(queue.IsEmpty());
33 1 : }
34 :
35 :
36 15443 : TEST(LockedQueue, Peek) {
37 2 : LockedQueue<Record> queue;
38 2 : EXPECT_TRUE(queue.IsEmpty());
39 1 : queue.Enqueue(1);
40 2 : EXPECT_FALSE(queue.IsEmpty());
41 1 : Record a = -1;
42 1 : bool success = queue.Peek(&a);
43 1 : EXPECT_TRUE(success);
44 2 : EXPECT_EQ(a, 1);
45 2 : EXPECT_FALSE(queue.IsEmpty());
46 1 : success = queue.Dequeue(&a);
47 1 : EXPECT_TRUE(success);
48 2 : EXPECT_EQ(a, 1);
49 2 : EXPECT_TRUE(queue.IsEmpty());
50 1 : }
51 :
52 :
53 15443 : TEST(LockedQueue, PeekOnEmpty) {
54 2 : LockedQueue<Record> queue;
55 2 : EXPECT_TRUE(queue.IsEmpty());
56 1 : Record a = -1;
57 1 : bool success = queue.Peek(&a);
58 2 : EXPECT_FALSE(success);
59 1 : }
60 :
61 :
62 15443 : TEST(LockedQueue, MultipleRecords) {
63 2 : LockedQueue<Record> queue;
64 2 : EXPECT_TRUE(queue.IsEmpty());
65 1 : queue.Enqueue(1);
66 2 : EXPECT_FALSE(queue.IsEmpty());
67 5 : for (int i = 2; i <= 5; ++i) {
68 4 : queue.Enqueue(i);
69 8 : EXPECT_FALSE(queue.IsEmpty());
70 : }
71 1 : Record rec = 0;
72 5 : for (int i = 1; i <= 4; ++i) {
73 8 : EXPECT_FALSE(queue.IsEmpty());
74 4 : queue.Dequeue(&rec);
75 4 : EXPECT_EQ(i, rec);
76 : }
77 8 : for (int i = 6; i <= 12; ++i) {
78 7 : queue.Enqueue(i);
79 14 : EXPECT_FALSE(queue.IsEmpty());
80 : }
81 9 : for (int i = 5; i <= 12; ++i) {
82 16 : EXPECT_FALSE(queue.IsEmpty());
83 8 : queue.Dequeue(&rec);
84 8 : EXPECT_EQ(i, rec);
85 : }
86 2 : EXPECT_TRUE(queue.IsEmpty());
87 1 : }
88 :
89 : } // namespace internal
90 9264 : } // namespace v8
|