X-Git-Url: https://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=ccan%2Fstr_talloc%2Ftest%2Frun.c;fp=ccan%2Fstr_talloc%2Ftest%2Frun.c;h=6da48bd0bc98f2c5fceb776012e08c5c1372b8b1;hp=0000000000000000000000000000000000000000;hb=9965fc25fcc92dc76d1cd4cf9595dc3dc9ebc586;hpb=963fa5ca9303d146d635e2fba04814f4f791c559 diff --git a/ccan/str_talloc/test/run.c b/ccan/str_talloc/test/run.c new file mode 100644 index 00000000..6da48bd0 --- /dev/null +++ b/ccan/str_talloc/test/run.c @@ -0,0 +1,52 @@ +#include "str_talloc/str_talloc.h" +#include +#include +#include "str_talloc/str_talloc.c" +#include "tap/tap.h" + +/* FIXME: ccanize */ +#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof(arr[0])) + +int main(int argc, char *argv[]) +{ + unsigned int i, j, n; + + plan_tests(19); + split = strsplit(NULL, "hello world", " ", &n); + ok1(n == 3); + ok1(streq(split[0], "hello")); + ok1(streq(split[1], "")); + ok1(streq(split[2], "world")); + ok1(split[3] == NULL); + talloc_free(split); + + split = strsplit(NULL, "hello world", " ", NULL); + ok1(streq(split[0], "hello")); + ok1(streq(split[1], "")); + ok1(streq(split[2], "world")); + ok1(split[3] == NULL); + talloc_free(split); + + split = strsplit(NULL, "hello world", "o ", NULL); + ok1(streq(split[0], "hell")); + ok1(streq(split[1], "")); + ok1(streq(split[2], "")); + ok1(streq(split[3], "w")); + ok1(streq(split[4], "rld")); + ok1(split[5] == NULL); + + ctx = split; + split = strsplit(ctx, "hello world", "o ", NULL); + ok1(talloc_parent(split) == ctx); + talloc_free(ctx); + + str = strjoin(NULL, substrings, ", "); + ok1(streq(str, "far, bar, baz, b, ba, z, ar, ")); + ctx = str; + str = strjoin(ctx, substrings, ""); + ok1(streq(str, "farbarbazbbazar")); + ok1(talloc_parent(str) == ctx); + talloc_free(ctx); + + return exit_status(); +}