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
diff --git a/tests/search_test.cpp b/tests/search_test.cpp
index 1509199..8b8359d 100644
--- a/tests/search_test.cpp
+++ b/tests/search_test.cpp
@@ -114,6 +114,11 @@
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 @@
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);
+}