]> git.ozlabs.org Git - ccan/blobdiff - ccan/bytestring/test/run.c
bytestring: new module.
[ccan] / ccan / bytestring / test / run.c
diff --git a/ccan/bytestring/test/run.c b/ccan/bytestring/test/run.c
new file mode 100644 (file)
index 0000000..49c16a6
--- /dev/null
@@ -0,0 +1,35 @@
+#include <ccan/bytestring/bytestring.h>
+#include <ccan/tap/tap.h>
+
+#define TEST_STRING    "test string"
+#define TEST_STRING_2  "abc\0def"
+
+const char str1[] = TEST_STRING;
+const char *str2 = TEST_STRING;
+
+int main(void)
+{
+       struct bytestring bs, bs1, bs2, bs3, bs4;
+
+       /* This is how many tests you plan to run */
+       plan_tests(6);
+
+       bs = bytestring(str1, sizeof(str1) - 1);
+       ok1(bs.ptr == str1);
+       ok1(bs.len == (sizeof(str1) - 1));
+
+       bs1 = BYTESTRING(TEST_STRING);
+       ok1(bytestring_eq(bs, bs1));
+
+       bs2 = BYTESTRING(TEST_STRING_2);
+       ok1(bs2.len == 7);
+
+       bs3 = bytestring_from_string(str2);
+       ok1(bytestring_eq(bs3, bs));
+
+       bs4 = bytestring_from_string(TEST_STRING_2);
+       ok1(bs4.len == 3);
+
+       /* This exits depending on whether all tests passed */
+       return exit_status();
+}