aboutsummaryrefslogtreecommitdiff
path: root/lib/util/test
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2023-08-31 13:40:46 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2023-08-31 13:40:46 +0200
commit035433e913872bc9c99fb19cd5b2eec1463ccdec (patch)
tree3c66bbf8953db9a12256b7ecced5033e3bdb3f2a /lib/util/test
parent3a0ee386184093a130d6c61c3eeb1d5a65bdd167 (diff)
Document decimal integer parsing helpers, add an octal variant
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib/util/test')
-rw-r--r--lib/util/test/parse_int.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/lib/util/test/parse_int.c b/lib/util/test/parse_int.c
index 2bd5a7c..cf6a69f 100644
--- a/lib/util/test/parse_int.c
+++ b/lib/util/test/parse_int.c
@@ -74,5 +74,46 @@ int main(int argc, char **argv)
ret = parse_int("-1234", -1, NULL, -1000, 1000, &s_out);
TEST_EQUAL_I(ret, SQFS_ERROR_OUT_OF_BOUNDS);
+ /**** octal version *****/
+
+ /* must begin with a digit */
+ ret = parse_uint_oct("a1234", -1, &diff, 0, 0, &out);
+ TEST_EQUAL_I(ret, SQFS_ERROR_CORRUPTED);
+
+ /* can end with a non-digit... */
+ ret = parse_uint_oct("1234a", -1, &diff, 0, 0, &out);
+ TEST_EQUAL_I(ret, 0);
+ TEST_EQUAL_UI(out, 01234);
+ TEST_EQUAL_UI(diff, 4);
+
+ /* ...unless diff is NULL */
+ ret = parse_uint_oct("1234a", -1, NULL, 0, 0, &out);
+ TEST_EQUAL_I(ret, SQFS_ERROR_CORRUPTED);
+
+ /* numeric overflow is cought */
+ ret = parse_uint_oct("2000000000000000000000", -1, NULL, 0, 0, &out);
+ TEST_EQUAL_I(ret, SQFS_ERROR_OVERFLOW);
+
+ /* buffer length is adherered to */
+ ret = parse_uint_oct("2000000000000000000000", 5, NULL, 0, 0, &out);
+ TEST_EQUAL_I(ret, 0);
+ TEST_EQUAL_UI(out, 020000);
+
+ ret = parse_uint_oct("2000000000000000000000", 5, &diff, 0, 0, &out);
+ TEST_EQUAL_I(ret, 0);
+ TEST_EQUAL_UI(diff, 5);
+ TEST_EQUAL_UI(out, 020000);
+
+ /* if vmin/vmax differ, check the range */
+ ret = parse_uint_oct("1234", -1, NULL, 0, 01000, &out);
+ TEST_EQUAL_I(ret, SQFS_ERROR_OUT_OF_BOUNDS);
+
+ ret = parse_uint_oct("1234", -1, NULL, 0, 02000, &out);
+ TEST_EQUAL_I(ret, 0);
+ TEST_EQUAL_UI(out, 01234);
+
+ ret = parse_uint_oct("1234", -1, NULL, 02000, 03000, &out);
+ TEST_EQUAL_I(ret, SQFS_ERROR_OUT_OF_BOUNDS);
+
return EXIT_SUCCESS;
}