commit 93f02dd35b1cd55e620f244bff9d0e4cb71e656c
parent f883479c0b091d0f65d48430dfe7205d54e623ac
Author: Roberto E. Vargas Caballero <k0ga@shike2.net>
Date: Thu, 30 Apr 2026 23:07:07 +0200
tests/libc: Add 0088-strtoul
Diffstat:
3 files changed, 78 insertions(+), 0 deletions(-)
diff --git a/tests/libc/execute/.gitignore b/tests/libc/execute/.gitignore
@@ -86,3 +86,4 @@ test.log
0085-strtold
0086-strtol
0087-stroll
+0088-stroul
diff --git a/tests/libc/execute/0088-stroul.c b/tests/libc/execute/0088-stroul.c
@@ -0,0 +1,76 @@
+#include <assert.h>
+#include <errno.h>
+#include <limits.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+/*
+output:
+testing
+done
+end:
+*/
+
+
+int
+test(void)
+{
+ unsigned long n;
+ char buf[64], *endp;
+
+ errno = 0;
+ n = strtoul("1024", NULL, 10);
+ assert(n == 1024 && errno == 0);
+
+ n = strtoul("1024", &endp, 10);
+ assert(n == 1024 && errno == 0 && *endp == '\0');
+
+ n = strtoul("1000", &endp, 10);
+ assert(n == 1000 && errno == 0 && *endp == '\0');
+
+ n = strtoul("1000", &endp, 8);
+ assert(n == 512 && errno == 0 && *endp == '\0');
+
+ n = strtoul("1000", &endp, 16);
+ assert(n == 4096 && errno == 0 && *endp == '\0');
+
+ n = strtoul("1000", &endp, 0);
+ assert(n == 1000 && errno == 0 && *endp == '\0');
+
+ n = strtoul("0x1000", &endp, 0);
+ assert(n == 4096 && errno == 0 && *endp == '\0');
+
+ n = strtoul("01000", &endp, 0);
+ assert(n == 512 && errno == 0 && *endp == '\0');
+
+ n = strtoul(" +1a", &endp, 0);
+ assert(n == 1 && errno == 0 && *endp == 'a');
+
+ n = strtoul(" -1a", &endp, 0);
+ assert(n == -1 && errno == 0 && *endp == 'a');
+
+ sprintf(buf, "%lu", ULONG_MAX);
+ n = strtoul(buf, NULL, 10);
+ assert(n == ULONG_MAX && errno == 0);
+
+ sprintf(buf, "%ld", LONG_MIN);
+ n = strtoul(buf, NULL, 10);
+ assert(n == LONG_MIN && errno == 0);
+
+ n = strtoul("9999999999999999999999999", NULL, 10);
+ assert(n == ULONG_MAX && errno == ERANGE);
+
+ errno = 0;
+ n = strtoul("-999999999999999999999999", NULL, 10);
+ assert(n == ULONG_MAX && errno == ERANGE);
+}
+
+int
+main(void)
+{
+ puts("testing");
+ test();
+ puts("done");
+
+ return 0;
+}
diff --git a/tests/libc/execute/libc-tests.lst b/tests/libc/execute/libc-tests.lst
@@ -84,3 +84,4 @@
0085-strtold [TODO]
0086-strtol
0087-stroll
+0088-stroul