diff options
Diffstat (limited to 'tests/search_test.cpp')
-rw-r--r-- | tests/search_test.cpp | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/tests/search_test.cpp b/tests/search_test.cpp index 1509199c9..8b8359d50 100644 --- a/tests/search_test.cpp +++ b/tests/search_test.cpp @@ -114,6 +114,11 @@ TEST(search, tfind_tsearch_twalk_tdestroy) { ASSERT_EQ(3U, g_free_calls); } +TEST(search, tdestroy_null) { + // It's okay to pass a null node, and your callback will not be called. + tdestroy(nullptr, nullptr); +} + struct pod_node { explicit pod_node(int i) : i(i) {} int i; @@ -285,3 +290,26 @@ TEST(search, hcreate_r_hsearch_r_hdestroy_r) { AssertEntry(e, "a", "B"); hdestroy_r(&h2); } + +TEST(search, hsearch_resizing) { + ASSERT_NE(0, hcreate(1)); + + std::vector<char*> entries; + // Add enough entries to ensure that we've had to resize. + for (char ch = ' '; ch <= '~'; ++ch) { + char* p; + asprintf(&p, "%c", ch); + ENTRY e; + e.data = e.key = p; + ASSERT_TRUE(hsearch(e, ENTER) != nullptr); + entries.push_back(p); + } + + // Check they're all there. + for (auto& p : entries) { + ENTRY* e = hsearch(ENTRY{.key = p, .data = nullptr}, FIND); + AssertEntry(e, p, p); + } + + for (auto& p : entries) free(p); +} |