]> git.ozlabs.org Git - ccan/blobdiff - ccan/tal/test/run-count.c
tal: add tal_count() and length properties for arrays.
[ccan] / ccan / tal / test / run-count.c
diff --git a/ccan/tal/test/run-count.c b/ccan/tal/test/run-count.c
new file mode 100644 (file)
index 0000000..0b64b88
--- /dev/null
@@ -0,0 +1,33 @@
+#include <ccan/tal/tal.h>
+#include <ccan/tal/tal.c>
+#include <ccan/tap/tap.h>
+
+int main(void)
+{
+       char *p1, *p2;
+
+       plan_tests(12);
+
+       p1 = tal(NULL, char);
+       ok1(p1);
+       ok1(tal_count(p1) == 0);
+
+       p2 = tal_arr(p1, char, 1);
+       ok1(p2);
+       ok1(tal_count(p2) == 1);
+       ok1(tal_resize(&p2, 2));
+       ok1(tal_count(p2) == 2);
+       ok1(tal_check(NULL, NULL));
+       tal_free(p2);
+
+       p2 = tal_arrz(p1, char, 7);
+       ok1(p2);
+       ok1(tal_count(p2) == 7);
+       ok1(tal_resize(&p2, 0));
+       ok1(tal_count(p2) == 0);
+       ok1(tal_check(NULL, NULL));
+       tal_free(p2);
+       tal_free(p1);
+
+       return exit_status();
+}