commit f883479c0b091d0f65d48430dfe7205d54e623ac
parent a68625773cbd82ba0f38d563aba336d5668b2e43
Author: Roberto E. Vargas Caballero <k0ga@shike2.net>
Date: Thu, 30 Apr 2026 22:41:01 +0200
libc/tests: Add 0087-strtoll
Diffstat:
3 files changed, 78 insertions(+), 0 deletions(-)
diff --git a/tests/libc/execute/.gitignore b/tests/libc/execute/.gitignore
@@ -85,3 +85,4 @@ test.log
0084-strtof
0085-strtold
0086-strtol
+0087-stroll
diff --git a/tests/libc/execute/0087-stroll.c b/tests/libc/execute/0087-stroll.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)
+{
+ long long n;
+ char buf[64], *endp;
+
+ errno = 0;
+ n = strtoll("1024", NULL, 10);
+ assert(n == 1024 && errno == 0);
+
+ n = strtoll("1024", &endp, 10);
+ assert(n == 1024 && errno == 0 && *endp == '\0');
+
+ n = strtoll("1000", &endp, 10);
+ assert(n == 1000 && errno == 0 && *endp == '\0');
+
+ n = strtoll("1000", &endp, 8);
+ assert(n == 512 && errno == 0 && *endp == '\0');
+
+ n = strtoll("1000", &endp, 16);
+ assert(n == 4096 && errno == 0 && *endp == '\0');
+
+ n = strtoll("1000", &endp, 0);
+ assert(n == 1000 && errno == 0 && *endp == '\0');
+
+ n = strtoll("0x1000", &endp, 0);
+ assert(n == 4096 && errno == 0 && *endp == '\0');
+
+ n = strtoll("01000", &endp, 0);
+ assert(n == 512 && errno == 0 && *endp == '\0');
+
+ n = strtoll(" +1a", &endp, 0);
+ assert(n == 1 && errno == 0 && *endp == 'a');
+
+ n = strtoll(" -1a", &endp, 0);
+ assert(n == -1 && errno == 0 && *endp == 'a');
+
+ sprintf(buf, "%lld", LLONG_MAX);
+ n = strtoll(buf, NULL, 10);
+ assert(n == LLONG_MAX && errno == 0);
+
+ sprintf(buf, "%lld", LLONG_MIN);
+ n = strtoll(buf, NULL, 10);
+ assert(n == LLONG_MIN && errno == 0);
+
+ n = strtoll("9999999999999999999999999", NULL, 10);
+ assert(n == LLONG_MAX && errno == ERANGE);
+
+ errno = 0;
+ n = strtoll("-999999999999999999999999", NULL, 10);
+ assert(n == LLONG_MIN && 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
@@ -83,3 +83,4 @@
0084-strtof [TODO]
0085-strtold [TODO]
0086-strtol
+0087-stroll