diff --git a/src/test/test-parse-util.c b/src/test/test-parse-util.c index d08014100b6..9194772fca3 100644 --- a/src/test/test-parse-util.c +++ b/src/test/test-parse-util.c @@ -395,6 +395,9 @@ static void test_safe_atou16(void) { r = safe_atou16("junk", &l); assert_se(r == -EINVAL); + + r = safe_atou16("123x", &l); + assert_se(r == -EINVAL); } static void test_safe_atoi16(void) { @@ -425,6 +428,70 @@ static void test_safe_atoi16(void) { r = safe_atoi16("junk", &l); assert_se(r == -EINVAL); + + r = safe_atoi16("123x", &l); + assert_se(r == -EINVAL); +} + +static void test_safe_atou64(void) { + int r; + uint64_t l; + + r = safe_atou64("12345", &l); + assert_se(r == 0); + assert_se(l == 12345); + + r = safe_atou64(" 12345", &l); + assert_se(r == 0); + assert_se(l == 12345); + + r = safe_atou64("18446744073709551617", &l); + assert_se(r == -ERANGE); + + r = safe_atou64("-1", &l); + assert_se(r == -ERANGE); + + r = safe_atou64(" -1", &l); + assert_se(r == -ERANGE); + + r = safe_atou64("junk", &l); + assert_se(r == -EINVAL); + + r = safe_atou64("123x", &l); + assert_se(r == -EINVAL); +} + +static void test_safe_atoi64(void) { + int r; + int64_t l; + + r = safe_atoi64("-12345", &l); + assert_se(r == 0); + assert_se(l == -12345); + + r = safe_atoi64(" -12345", &l); + assert_se(r == 0); + assert_se(l == -12345); + + r = safe_atoi64("32767", &l); + assert_se(r == 0); + assert_se(l == 32767); + + r = safe_atoi64(" 32767", &l); + assert_se(r == 0); + assert_se(l == 32767); + + r = safe_atoi64("9223372036854775813", &l); + assert_se(r == -ERANGE); + + r = safe_atoi64("-9223372036854775813", &l); + assert_se(r == -ERANGE); + + r = safe_atoi64("junk", &l); + assert_se(r == -EINVAL); + + r = safe_atoi64("123x", &l); + assert_se(r == -EINVAL); } static void test_safe_atod(void) { @@ -538,6 +605,8 @@ int main(int argc, char *argv[]) { test_safe_atolli(); test_safe_atou16(); test_safe_atoi16(); + test_safe_atou64(); + test_safe_atoi64(); test_safe_atod(); test_parse_percent(); test_parse_percent_unbounded();