From eeb9299eee18eed2f03bc4bd2683fe22574501a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Wed, 8 Feb 2023 10:54:49 +0100 Subject: [PATCH] test-parse-util: add tests with explicit plus character I expected this to work, but our tests did not cover this explicitly. (cherry picked from commit 8eb491f4993c6080e9724c0359a87c64c460605e) (cherry picked from commit 7c0ac515c8094fd62c100477fa293aa31f97e2c4) (cherry picked from commit 36c35e765db478d5f72cdd70cd663baa865ad43a) --- src/test/test-parse-util.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/test/test-parse-util.c b/src/test/test-parse-util.c index daa547c793..a3875747a0 100644 --- a/src/test/test-parse-util.c +++ b/src/test/test-parse-util.c @@ -480,6 +480,14 @@ TEST(safe_atou16) { assert_se(r == 0); assert_se(l == 12345); + r = safe_atou16("+12345", &l); + assert_se(r == 0); + assert_se(l == 12345); + + r = safe_atou16(" +12345", &l); + assert_se(r == 0); + assert_se(l == 12345); + r = safe_atou16("123456", &l); assert_se(r == -ERANGE); @@ -514,6 +522,14 @@ TEST(safe_atoi16) { assert_se(r == 0); assert_se(l == -12345); + r = safe_atoi16("+12345", &l); + assert_se(r == 0); + assert_se(l == 12345); + + r = safe_atoi16(" +12345", &l); + assert_se(r == 0); + assert_se(l == 12345); + r = safe_atoi16("32767", &l); assert_se(r == 0); assert_se(l == 32767); @@ -703,6 +719,22 @@ TEST(safe_atoux64) { assert_se(r == 0); assert_se(l == 11603985); + r = safe_atoux64("+12345", &l); + assert_se(r == 0); + assert_se(l == 0x12345); + + r = safe_atoux64(" +12345", &l); + assert_se(r == 0); + assert_se(l == 0x12345); + + r = safe_atoux64("+0x12345", &l); + assert_se(r == 0); + assert_se(l == 0x12345); + + r = safe_atoux64("+0b11011", &l); + assert_se(r == 0); + assert_se(l == 11603985); + r = safe_atoux64("0o11011", &l); assert_se(r == -EINVAL);