diff options
author | Elliott Hughes <enh@google.com> | 2020-08-12 14:25:41 -0700 |
---|---|---|
committer | Elliott Hughes <enh@google.com> | 2020-08-12 15:52:14 -0700 |
commit | 7cebf835f310650f67b254295a685918681656fc (patch) | |
tree | daf485447fccb691750149c465b2c629adf6e305 /tests/search_test.cpp | |
parent | a4110def5cec22306313a34fff64b5810c9b1792 (diff) | |
download | bionic-7cebf835f310650f67b254295a685918681656fc.tar.gz |
Various coverage improvements.
Mostly from extra test cases, but also:
* Move the fgets size < 0 assertion into fgets.
* Use ELF aliases for strtoq/strtouq rather than duplicating code.
* Don't check uname() succeeded, since it can't fail.
Test: treehugger
Change-Id: I2e6b3b88b0a3eb16bd68be68b9bc9f40d8043291
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); +} |