123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159 |
- #define TEST_SUITE_NAME "/lib/strutil"
- #include "tests/mctest.h"
- #include <inttypes.h>
- #include "lib/strutil.h"
- static void
- setup (void)
- {
- }
- static void
- teardown (void)
- {
- }
- static const struct parse_integer_test_ds
- {
- const char *haystack;
- uintmax_t expected_result;
- gboolean invalid;
- } parse_integer_test_ds[] =
- {
- {
-
- "99999999999999999999999999999999999999999999999999999999999999999999",
- 0,
- TRUE
- },
- {
- "x",
- 0,
- TRUE
- },
- {
- "9x",
- 0,
- TRUE
- },
- {
- "1",
- 1,
- FALSE
- },
- {
- "-1",
- 0,
- TRUE
- },
- {
- "1k",
- 1024,
- FALSE
- },
- {
- "1K",
- 1024,
- FALSE
- },
- {
- "1M",
- 1024 * 1024,
- FALSE
- },
- {
- "1m",
- 0,
- TRUE
- },
- {
- "64M",
- 64 * 1024 * 1024,
- FALSE
- },
- {
- "1G",
- 1 * 1024 * 1024 * 1024,
- FALSE
- }
- };
- START_PARAMETRIZED_TEST (parse_integer_test, parse_integer_test_ds)
- {
-
- uintmax_t actual_result;
- gboolean invalid = FALSE;
-
- actual_result = parse_integer (data->haystack, &invalid);
-
- ck_assert_msg (invalid == data->invalid && actual_result == data->expected_result,
- "actual ( %" PRIuMAX ") not equal to\nexpected (%" PRIuMAX ")",
- actual_result, data->expected_result);
- }
- END_PARAMETRIZED_TEST
- int
- main (void)
- {
- TCase *tc_core;
- tc_core = tcase_create ("Core");
- tcase_add_checked_fixture (tc_core, setup, teardown);
-
- mctest_add_parameterized_test (tc_core, parse_integer_test, parse_integer_test_ds);
-
- return mctest_run_all (tc_core);
- }
|