0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-30 23:43:09 +01:00
nodejs/test/cctest/util.cc
Ben Noordhuis 008078862e deps: check in gtest, add util unit test
Check in a gypified gtest and add a simple unit test to show that the
basic infrastructure is in place.

PR-URL: https://github.com/iojs/io.js/pull/1199
Refs: https://github.com/iojs/io.js/issues/1193
Reviewed-By: Fedor Indutny <fedor@indutny.com>
Reviewed-By: Johan Bergström <bugs@bergstroem.nu>
2015-04-01 22:35:56 +02:00

59 lines
1.3 KiB
C++

#include "util.h"
#include "util-inl.h"
#include "gtest/gtest.h"
TEST(UtilTest, ListHead) {
struct Item { node::ListNode<Item> node_; };
typedef node::ListHead<Item, &Item::node_> List;
List list;
EXPECT_TRUE(list.IsEmpty());
Item one;
EXPECT_TRUE(one.node_.IsEmpty());
list.PushBack(&one);
EXPECT_FALSE(list.IsEmpty());
EXPECT_FALSE(one.node_.IsEmpty());
{
List::Iterator it = list.begin();
EXPECT_NE(list.end(), it);
EXPECT_EQ(&one, *it);
++it;
EXPECT_FALSE(it != list.end()); // Iterator only implements != operator.
}
Item two;
list.PushBack(&two);
{
List::Iterator it = list.begin();
EXPECT_NE(list.end(), it);
EXPECT_EQ(&one, *it);
++it;
EXPECT_NE(list.end(), it);
EXPECT_EQ(&two, *it);
++it;
EXPECT_FALSE(it != list.end()); // Iterator only implements != operator.
}
EXPECT_EQ(&one, list.PopFront());
EXPECT_TRUE(one.node_.IsEmpty());
EXPECT_FALSE(list.IsEmpty());
{
List::Iterator it = list.begin();
EXPECT_NE(list.end(), it);
EXPECT_EQ(&two, *it);
++it;
EXPECT_FALSE(it != list.end()); // Iterator only implements != operator.
}
EXPECT_EQ(&two, list.PopFront());
EXPECT_TRUE(two.node_.IsEmpty());
EXPECT_TRUE(list.IsEmpty());
EXPECT_FALSE(list.begin() != list.end());
}