TEST(LinkedBlockingQueue, MixedTest) { BlockingQueue *queue = new LinkedBlockingQueue(5); SuperObject *dummy1 = new DummyObject(1); ASSERT_TRUE(queue->offer(dummy1)); ASSERT_TRUE(queue->offer(new DummyObject(2))); ASSERT_TRUE(queue->offer(new DummyObject(3))); ASSERT_TRUE(queue->offer(new DummyObject(4))); ASSERT_TRUE(queue->add(new DummyObject(5))); ASSERT_EQ(5, queue->size()); SuperObject *tmp1 = queue->take(); ASSERT_EQ(dummy1, tmp1); ASSERT_EQ(4, queue->size()); delete tmp1; SuperObject *tmp2 = queue->peek(); ASSERT_EQ(4, queue->size()); ASSERT_TRUE(tmp2 != NULL); delete queue->take(); ASSERT_EQ(3, queue->size()); delete queue->take(); ASSERT_EQ(2, queue->size()); delete queue->take(); ASSERT_EQ(1, queue->size()); SuperObject *tmp3 = queue->poll(3); ASSERT_TRUE(tmp3 != NULL); if (tmp3 != NULL) { delete tmp3; } ASSERT_EQ(0, queue->size()); ASSERT_EQ(NULL, queue->poll(3)); ASSERT_EQ(NULL, queue->peek()); delete queue; }
TEST(LinkedBlockingQueue, PeekAndRemoveTest) { BlockingQueue *queue = new LinkedBlockingQueue(); SuperObject *dummy1 = new DummyObject(1); ASSERT_TRUE(queue->offer(dummy1)); ASSERT_EQ(dummy1, queue->peek()); ASSERT_TRUE(queue->contains(dummy1)); ASSERT_TRUE(queue->remove(dummy1)); ASSERT_FALSE(queue->remove(dummy1)); ASSERT_FALSE(queue->contains(dummy1)); ASSERT_EQ(0, queue->size()); delete queue; delete dummy1; }