summaryrefslogtreecommitdiff
path: root/tests/lib
diff options
context:
space:
mode:
Diffstat (limited to 'tests/lib')
-rw-r--r--tests/lib/test_darr.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/tests/lib/test_darr.c b/tests/lib/test_darr.c
index 74aedac4b7..87f9e3e564 100644
--- a/tests/lib/test_darr.c
+++ b/tests/lib/test_darr.c
@@ -20,6 +20,8 @@
* [x] - darr_foreach_i
* [x] - darr_foreach_p
* [x] - darr_free
+ * [x] - darr_free_free
+ * [x] - darr_free_func
* [x] - darr_insert
* [ ] - darr_insertz
* [x] - darr_insert_n
@@ -318,6 +320,8 @@ static void test_string(void)
uint addlen = strlen(add);
char *da1 = NULL;
char *da2 = NULL;
+ const char **strings = NULL;
+ uint sum = 0;
assert(darr_strlen(da1) == 0);
@@ -412,6 +416,29 @@ static void test_string(void)
da1 = darr_in_strcatf(da1, "0123456789: %08x", 0xDEADBEEF);
assert(!strcmp("0123456789: deadbeef", da1));
darr_free(da1);
+
+ sum = 0;
+ *darr_append(strings) = "1";
+ *darr_append(strings) = "2";
+ *darr_append(strings) = "3";
+#define adder(x) (sum += atoi(x))
+ darr_free_func(strings, adder);
+ assert(sum == 6);
+ assert(strings == NULL);
+
+ sum = 0;
+ darr_free_func(strings, adder);
+ assert(sum == 0);
+ assert(strings == NULL);
+
+ *darr_append(strings) = NULL;
+ *darr_append(strings) = darr_strdup("2");
+ *darr_append(strings) = darr_strdup("3");
+ darr_free_free(strings);
+ assert(strings == NULL);
+
+ darr_free_free(strings);
+ assert(strings == NULL);
}
int main(int argc, char **argv)