From: Robert Kessl Date: Tue, 22 Jul 2014 13:15:40 +0000 (+0200) Subject: xtypes: updated tests X-Git-Tag: v6.1~3^2~65 X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=147942cb4ee0520b08314c15420d6eebae5162b1;p=libucw.git xtypes: updated tests --- diff --git a/ucw/xtypes-test.c b/ucw/xtypes-test.c index 75e436b5..bd7411b1 100644 --- a/ucw/xtypes-test.c +++ b/ucw/xtypes-test.c @@ -19,7 +19,7 @@ static void test_size_correct(struct fastbuf *out) { - const char *size_strs[] = { + static const char *size_strs[] = { "4", "4KB", "4MB", @@ -28,7 +28,7 @@ static void test_size_correct(struct fastbuf *out) NULL }; - u64 size_parsed[] = { + static u64 size_parsed[] = { 4LLU, 4 * 1024LLU, 4 * 1024LLU * 1024LLU, @@ -42,10 +42,10 @@ static void test_size_correct(struct fastbuf *out) while(size_strs[i] != NULL) { u64 result; const char *parse_err = xt_size.parse(size_strs[i], &result, pool); - if(parse_err) { - abort(); - } + + ASSERT_MSG(parse_err == NULL, "Unexpected error in xt_size.parse"); ASSERT_MSG(size_parsed[i] == result, "xt_size.parse parsed an incorrect value."); + const char *result_str = xt_size.format(&result, i | SIZE_UNITS_FIXED, pool); bprintf(out, "%s %s\n", size_strs[i], result_str); @@ -57,7 +57,7 @@ static void test_size_correct(struct fastbuf *out) static void test_size_parse_errors(struct fastbuf *out) { - const char *size_strs[] = { + static const char *size_strs[] = { "1X", "KB", "\0", @@ -82,6 +82,38 @@ static void test_size_parse_errors(struct fastbuf *out) mp_delete(pool); } +static void test_bool_correct(struct fastbuf *out UNUSED) +{ + static const char *bool_strs[] = { + "0", + "1", + "false", + "true", + NULL + }; + + static bool bool_parsed[] = { + false, + true, + false, + true + }; + + struct mempool *pool = mp_new(4096); + uint i = 0; + + while(bool_strs[i] != NULL) { + bool result; + const char *err_str = xt_bool.parse(bool_strs[i], &result, pool); + ASSERT_MSG(err_str == NULL, "Unexpected error in xt_bool.parse."); + ASSERT_MSG(bool_parsed[i] == result, "xt_bool.parse parsed an incorrect value."); + bprintf(out, "%s %s\n", bool_strs[i], result ? "true" : "false"); + i++; + } + + mp_delete(pool); +} + int main(void) { struct fastbuf *out; @@ -89,7 +121,7 @@ int main(void) test_size_correct(out); test_size_parse_errors(out); - + test_bool_correct(out); bclose(out); return 0; diff --git a/ucw/xtypes-test.t b/ucw/xtypes-test.t new file mode 100644 index 00000000..41768fb9 --- /dev/null +++ b/ucw/xtypes-test.t @@ -0,0 +1,15 @@ +Run: ../obj/ucw/xtypes-test +Out <