X-Git-Url: https://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=ccan%2Fstr%2Fbase32%2Ftest%2Frun-lower.c;fp=ccan%2Fstr%2Fbase32%2Ftest%2Frun-lower.c;h=5f64d64e7bfcc38bdcc95457b2dcca1027750e1b;hp=0000000000000000000000000000000000000000;hb=a8f32342d90676f9904b632706caab44313533dd;hpb=61aee192bcd814b3cb9073bc0280e4ef5cc45c7d diff --git a/ccan/str/base32/test/run-lower.c b/ccan/str/base32/test/run-lower.c new file mode 100644 index 00000000..5f64d64e --- /dev/null +++ b/ccan/str/base32/test/run-lower.c @@ -0,0 +1,38 @@ +#include +/* Include the C files directly. */ +#include +#include + +static void test(const char *data, const char *b32) +{ + char test[1000]; + + ok1(base32_str_size(strlen(data)) == strlen(b32) + 1); + ok1(base32_data_size(b32, strlen(b32)) == strlen(data)); + ok1(base32_encode(data, strlen(data), test, strlen(b32)+1)); + ok1(strcmp(test, b32) == 0); + test[strlen(data)] = '\0'; + ok1(base32_decode(b32, strlen(b32), test, strlen(data))); + ok1(strcmp(test, data) == 0); +} + +int main(void) +{ + /* This is how many tests you plan to run */ + plan_tests(8 * 6); + + base32_chars = "abcdefghijklmnopqrstuvwxyz234567="; + + /* Test vectors from RFC, but lower-case */ + test("", ""); + test("f", "my======"); + test("fo", "mzxq===="); + test("foo", "mzxw6==="); + test("foob", "mzxw6yq="); + test("fooba", "mzxw6ytb"); + test("r", "oi======"); + test("foobar", "mzxw6ytboi======"); + + /* This exits depending on whether all tests passed */ + return exit_status(); +}