]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test-parse-util: add tests with explicit plus character
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 8 Feb 2023 09:54:49 +0000 (10:54 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 8 Feb 2023 11:01:16 +0000 (12:01 +0100)
I expected this to work, but our tests did not cover this
explicitly.

src/test/test-parse-util.c

index 388d0fe3f7ef7c120289e8c4c02ed80432ef716e..c83e8fc6300cce311b873b2664f615e25c1efc94 100644 (file)
@@ -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);