Home | History | Annotate | Download | only in cctest
      1 // Copyright 2010 the V8 project authors. All rights reserved.
      2 //
      3 // Tests of the unbound queue.
      4 
      5 #include "v8.h"
      6 #include "unbound-queue-inl.h"
      7 #include "cctest.h"
      8 
      9 using i::UnboundQueue;
     10 
     11 
     12 TEST(SingleRecord) {
     13   typedef int Record;
     14   UnboundQueue<Record> cq;
     15   CHECK(cq.IsEmpty());
     16   cq.Enqueue(1);
     17   CHECK(!cq.IsEmpty());
     18   Record rec = 0;
     19   cq.Dequeue(&rec);
     20   CHECK_EQ(1, rec);
     21   CHECK(cq.IsEmpty());
     22 }
     23 
     24 
     25 TEST(MultipleRecords) {
     26   typedef int Record;
     27   UnboundQueue<Record> cq;
     28   CHECK(cq.IsEmpty());
     29   cq.Enqueue(1);
     30   CHECK(!cq.IsEmpty());
     31   for (int i = 2; i <= 5; ++i) {
     32     cq.Enqueue(i);
     33     CHECK(!cq.IsEmpty());
     34   }
     35   Record rec = 0;
     36   for (int i = 1; i <= 4; ++i) {
     37     CHECK(!cq.IsEmpty());
     38     cq.Dequeue(&rec);
     39     CHECK_EQ(i, rec);
     40   }
     41   for (int i = 6; i <= 12; ++i) {
     42     cq.Enqueue(i);
     43     CHECK(!cq.IsEmpty());
     44   }
     45   for (int i = 5; i <= 12; ++i) {
     46     CHECK(!cq.IsEmpty());
     47     cq.Dequeue(&rec);
     48     CHECK_EQ(i, rec);
     49   }
     50   CHECK(cq.IsEmpty());
     51 }
     52 
     53