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

Unified Diff: test/unittests/locked-queue-unittest.cc

Issue 1448283004: Add lock-based unbounded queue (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Moved to atomic handling for Node.next Created 5 years, 1 month 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 | « src/locked-queue-inl.h ('k') | test/unittests/unittests.gyp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/unittests/locked-queue-unittest.cc
diff --git a/test/unittests/locked-queue-unittest.cc b/test/unittests/locked-queue-unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..cc176d937f73e8f9f1bf724550a25f3e2fdff77b
--- /dev/null
+++ b/test/unittests/locked-queue-unittest.cc
@@ -0,0 +1,90 @@
+// Copyright 2015 the V8 project 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 "src/locked-queue-inl.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace {
+
+typedef int Record;
+
+} // namespace
+
+namespace v8 {
+namespace internal {
+
+TEST(LockedQueue, ConstructorEmpty) {
+ LockedQueue<Record> queue;
+ EXPECT_TRUE(queue.IsEmpty());
+}
+
+
+TEST(LockedQueue, SingleRecordEnqueueDequeue) {
+ LockedQueue<Record> queue;
+ EXPECT_TRUE(queue.IsEmpty());
+ queue.Enqueue(1);
+ EXPECT_FALSE(queue.IsEmpty());
+ Record a = -1;
+ bool success = queue.Dequeue(&a);
+ EXPECT_TRUE(success);
+ EXPECT_EQ(a, 1);
+ EXPECT_TRUE(queue.IsEmpty());
+}
+
+
+TEST(LockedQueue, Peek) {
+ LockedQueue<Record> queue;
+ EXPECT_TRUE(queue.IsEmpty());
+ queue.Enqueue(1);
+ EXPECT_FALSE(queue.IsEmpty());
+ Record a = -1;
+ bool success = queue.Peek(&a);
+ EXPECT_TRUE(success);
+ EXPECT_EQ(a, 1);
+ EXPECT_FALSE(queue.IsEmpty());
+ success = queue.Dequeue(&a);
+ EXPECT_TRUE(success);
+ EXPECT_EQ(a, 1);
+ EXPECT_TRUE(queue.IsEmpty());
+}
+
+
+TEST(LockedQueue, PeekOnEmpty) {
+ LockedQueue<Record> queue;
+ EXPECT_TRUE(queue.IsEmpty());
+ Record a = -1;
+ bool success = queue.Peek(&a);
+ EXPECT_FALSE(success);
+}
+
+
+TEST(LockedQueue, MultipleRecords) {
+ LockedQueue<Record> queue;
+ EXPECT_TRUE(queue.IsEmpty());
+ queue.Enqueue(1);
+ EXPECT_FALSE(queue.IsEmpty());
+ for (int i = 2; i <= 5; ++i) {
+ queue.Enqueue(i);
+ EXPECT_FALSE(queue.IsEmpty());
+ }
+ Record rec = 0;
+ for (int i = 1; i <= 4; ++i) {
+ EXPECT_FALSE(queue.IsEmpty());
+ queue.Dequeue(&rec);
+ EXPECT_EQ(i, rec);
+ }
+ for (int i = 6; i <= 12; ++i) {
+ queue.Enqueue(i);
+ EXPECT_FALSE(queue.IsEmpty());
+ }
+ for (int i = 5; i <= 12; ++i) {
+ EXPECT_FALSE(queue.IsEmpty());
+ queue.Dequeue(&rec);
+ EXPECT_EQ(i, rec);
+ }
+ EXPECT_TRUE(queue.IsEmpty());
+}
+
+} // namespace internal
+} // namespace v8
« no previous file with comments | « src/locked-queue-inl.h ('k') | test/unittests/unittests.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698