diff options
author | Ben Noordhuis <info@bnoordhuis.nl> | 2015-03-19 02:01:45 +0100 |
---|---|---|
committer | Ben Noordhuis <info@bnoordhuis.nl> | 2015-04-01 22:35:56 +0200 |
commit | 008078862ed0731f2d1e74fb4182b67a29b31589 (patch) | |
tree | 0da27d88397a3f3bdbe3e5f1db6a28a1b0f00dfd /test/cctest | |
parent | 382bd9d2e0173569e551be4fc2702696190f5c1a (diff) | |
download | node-new-008078862ed0731f2d1e74fb4182b67a29b31589.tar.gz |
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>
Diffstat (limited to 'test/cctest')
-rw-r--r-- | test/cctest/util.cc | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/test/cctest/util.cc b/test/cctest/util.cc new file mode 100644 index 0000000000..fe966d9b34 --- /dev/null +++ b/test/cctest/util.cc @@ -0,0 +1,58 @@ +#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()); +} |