diff options
author | Dmitriy Ivanov <dimitry@google.com> | 2014-09-02 09:45:40 -0700 |
---|---|---|
committer | Dmitriy Ivanov <dimitry@google.com> | 2014-09-02 09:45:40 -0700 |
commit | a4926058496c1c24c00ac07e42d45048dac7c487 (patch) | |
tree | 829a5e199cb60e89ab2f9be1e58281e7d3a9cc39 /linker/tests | |
parent | 5120bcf9f11951bffd8ac595c2b70252ed4a4958 (diff) | |
download | bionic-a4926058496c1c24c00ac07e42d45048dac7c487.zip bionic-a4926058496c1c24c00ac07e42d45048dac7c487.tar.gz bionic-a4926058496c1c24c00ac07e42d45048dac7c487.tar.bz2 |
Implement LinkedList::visit()
Change-Id: Ibd9d133dddf1f2e6e65660e3cd2dacafcc0c84d9
Diffstat (limited to 'linker/tests')
-rw-r--r-- | linker/tests/linked_list_test.cpp | 50 |
1 files changed, 43 insertions, 7 deletions
diff --git a/linker/tests/linked_list_test.cpp b/linker/tests/linked_list_test.cpp index 0483b84..a555edb 100644 --- a/linker/tests/linked_list_test.cpp +++ b/linker/tests/linked_list_test.cpp @@ -151,15 +151,15 @@ TEST(linked_list, copy_to_array) { memset(buf, 0, sizeof(buf)); ASSERT_EQ(4U, list.size()); ASSERT_EQ(2U, list.copy_to_array(buf, 2)); - ASSERT_EQ('a', *buf[0]); - ASSERT_EQ('b', *buf[1]); + ASSERT_STREQ("a", buf[0]); + ASSERT_STREQ("b", buf[1]); ASSERT_EQ(nullptr, buf[2]); ASSERT_EQ(4U, list.copy_to_array(buf, max_size)); - ASSERT_EQ('a', *buf[0]); - ASSERT_EQ('b', *buf[1]); - ASSERT_EQ('c', *buf[2]); - ASSERT_EQ('d', *buf[3]); + ASSERT_STREQ("a", buf[0]); + ASSERT_STREQ("b", buf[1]); + ASSERT_STREQ("c", buf[2]); + ASSERT_STREQ("d", buf[3]); ASSERT_EQ(nullptr, buf[4]); memset(buf, 0, sizeof(buf)); @@ -168,7 +168,7 @@ TEST(linked_list, copy_to_array) { }); ASSERT_EQ(1U, list.size()); ASSERT_EQ(1U, list.copy_to_array(buf, max_size)); - ASSERT_EQ('c', *buf[0]); + ASSERT_STREQ("c", buf[0]); ASSERT_EQ(nullptr, buf[1]); memset(buf, 0, sizeof(buf)); @@ -182,3 +182,39 @@ TEST(linked_list, copy_to_array) { ASSERT_EQ(nullptr, buf[0]); } +TEST(linked_list, test_visit) { + test_list_t list; + list.push_back("a"); + list.push_back("b"); + list.push_back("c"); + list.push_back("d"); + + int visits = 0; + std::stringstream ss; + bool result = list.visit([&](const char* c) { + ++visits; + ss << c; + return true; + }); + + ASSERT_TRUE(result); + ASSERT_EQ(4, visits); + ASSERT_EQ("abcd", ss.str()); + + visits = 0; + ss.str(std::string()); + + result = list.visit([&](const char* c) { + if (++visits == 3) { + return false; + } + + ss << c; + return true; + }); + + ASSERT_TRUE(!result); + ASSERT_EQ(3, visits); + ASSERT_EQ("ab", ss.str()); +} + |