aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authormax99x <max99x@gmail.com>2011-08-28 10:06:36 +0300
committermax99x <max99x@gmail.com>2011-08-28 10:06:36 +0300
commit19458449a6c3eca2f63bdaae134173a000a89ce0 (patch)
tree4a49fa7a4ba3459aadf724226bd00118c419bfd0 /tests
parent42e4d9cb7e37d1a79ac928852f8a34a6232e70d7 (diff)
Fixed negatives in strtod(); implemented strto[l/ul/ll/ull]().
Diffstat (limited to 'tests')
-rw-r--r--tests/parseInt/output.txt134
-rw-r--r--tests/parseInt/src.c64
-rw-r--r--tests/runner.py15
3 files changed, 210 insertions, 3 deletions
diff --git a/tests/parseInt/output.txt b/tests/parseInt/output.txt
new file mode 100644
index 00000000..f487db74
--- /dev/null
+++ b/tests/parseInt/output.txt
@@ -0,0 +1,134 @@
+strtol("-9223372036854775809") = -2147483648
+ERR 34
+strtoll("-9223372036854775809") = -9223372036854776000
+ERR 34
+strtoul("-9223372036854775809") = 4294967295
+ERR 34
+strtoull("-9223372036854775809") = 9223372036854774000
+
+strtol("-9223372036854775808") = -2147483648
+ERR 34
+strtoll("-9223372036854775808") = -9223372036854776000
+ERR 34
+strtoul("-9223372036854775808") = 4294967295
+ERR 34
+strtoull("-9223372036854775808") = 9223372036854774000
+
+strtol("-9223372036854775807") = -2147483648
+ERR 34
+strtoll("-9223372036854775807") = -9223372036854776000
+ERR 34
+strtoul("-9223372036854775807") = 4294967295
+ERR 34
+strtoull("-9223372036854775807") = 9223372036854774000
+
+strtol("-2147483649") = -2147483648
+ERR 34
+strtoll("-2147483649") = -2147483649
+strtoul("-2147483649") = 2147483647
+strtoull("-2147483649") = 18446744071562068000
+
+strtol("-2147483648") = -2147483648
+strtoll("-2147483648") = -2147483648
+strtoul("-2147483648") = 2147483648
+strtoull("-2147483648") = 18446744071562068000
+
+strtol("-2147483647") = -2147483647
+strtoll("-2147483647") = -2147483647
+strtoul("-2147483647") = 2147483649
+strtoull("-2147483647") = 18446744071562068000
+
+strtol("-5") = -5
+strtoll("-5") = -5
+strtoul("-5") = 4294967291
+strtoull("-5") = 18446744073709552000
+
+strtol("-1") = -1
+strtoll("-1") = -1
+strtoul("-1") = 4294967295
+strtoull("-1") = 18446744073709552000
+
+strtol("0") = 0
+strtoll("0") = 0
+strtoul("0") = 0
+strtoull("0") = 0
+
+strtol("1") = 1
+strtoll("1") = 1
+strtoul("1") = 1
+strtoull("1") = 1
+
+strtol("5") = 5
+strtoll("5") = 5
+strtoul("5") = 5
+strtoull("5") = 5
+
+strtol("2147483646") = 2147483646
+strtoll("2147483646") = 2147483646
+strtoul("2147483646") = 2147483646
+strtoull("2147483646") = 2147483646
+
+strtol("2147483647") = 2147483647
+strtoll("2147483647") = 2147483647
+strtoul("2147483647") = 2147483647
+strtoull("2147483647") = 2147483647
+
+strtol("2147483648") = 2147483647
+ERR 34
+strtoll("2147483648") = 2147483648
+strtoul("2147483648") = 2147483648
+strtoull("2147483648") = 2147483648
+
+strtol("4294967294") = 2147483647
+ERR 34
+strtoll("4294967294") = 4294967294
+strtoul("4294967294") = 4294967294
+strtoull("4294967294") = 4294967294
+
+strtol("4294967295") = 2147483647
+ERR 34
+strtoll("4294967295") = 4294967295
+strtoul("4294967295") = 4294967295
+strtoull("4294967295") = 4294967295
+
+strtol("4294967296") = 2147483647
+ERR 34
+strtoll("4294967296") = 4294967296
+strtoul("4294967296") = 4294967295
+ERR 34
+strtoull("4294967296") = 4294967296
+
+strtol("18446744073709551614") = 2147483647
+ERR 34
+strtoll("18446744073709551614") = 9223372036854776000
+ERR 34
+strtoul("18446744073709551614") = 4294967295
+ERR 34
+strtoull("18446744073709551614") = 18446744073709552000
+
+strtol("18446744073709551615") = 2147483647
+ERR 34
+strtoll("18446744073709551615") = 9223372036854776000
+ERR 34
+strtoul("18446744073709551615") = 4294967295
+ERR 34
+strtoull("18446744073709551615") = 18446744073709552000
+
+strtol("18446744073709551616") = 2147483647
+ERR 34
+strtoll("18446744073709551616") = 9223372036854776000
+ERR 34
+strtoul("18446744073709551616") = 4294967295
+ERR 34
+strtoull("18446744073709551616") = 18446744073709552000
+
+strtol("0x12", 0, 0) = 18
+strtol("0x12", 0, 10) = 0
+strtol("012", 0, 0) = 10
+strtol("012", 0, 10) = 12
+strtol("0y12", 0, 0) = 0
+strtol("hello", 0, 30) = 14167554
+strtol("hello", 0, 10) = 0
+strtol("not-a-number") = 0
+strtol(" 0x12end") = 302
+endptr - str = 7
diff --git a/tests/parseInt/src.c b/tests/parseInt/src.c
new file mode 100644
index 00000000..dde15410
--- /dev/null
+++ b/tests/parseInt/src.c
@@ -0,0 +1,64 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <errno.h>
+
+void check_error() {
+ if (errno) {
+ printf("ERR %d\n", errno);
+ errno = 0;
+ }
+}
+
+int main() {
+ char* test_values[] = {
+ "-9223372036854775809",
+ "-9223372036854775808",
+ "-9223372036854775807",
+ "-2147483649",
+ "-2147483648",
+ "-2147483647",
+ "-5",
+ "-1",
+ "0",
+ "1",
+ "5",
+ "2147483646",
+ "2147483647",
+ "2147483648",
+ "4294967294",
+ "4294967295",
+ "4294967296",
+ "18446744073709551614",
+ "18446744073709551615",
+ "18446744073709551616",
+ };
+
+ for (int i = 0; i < sizeof(test_values) / sizeof(test_values[0]); i++) {
+ printf("strtol(\"%s\") = %ld\n", test_values[i], strtol(test_values[i], 0, 0));
+ check_error();
+ printf("strtoll(\"%s\") = %lld\n", test_values[i], strtoll(test_values[i], 0, 0));
+ check_error();
+ printf("strtoul(\"%s\") = %lu\n", test_values[i], strtoul(test_values[i], 0, 0));
+ check_error();
+ printf("strtoull(\"%s\") = %llu\n", test_values[i], strtoull(test_values[i], 0, 0));
+ check_error();
+ printf("\n");
+ }
+
+ printf("strtol(\"0x12\", 0, 0) = %ld\n", strtol("0x12", 0, 0));
+ printf("strtol(\"0x12\", 0, 10) = %ld\n", strtol("0x12", 0, 10));
+ printf("strtol(\"012\", 0, 0) = %ld\n", strtol("012", 0, 0));
+ printf("strtol(\"012\", 0, 10) = %ld\n", strtol("012", 0, 10));
+ printf("strtol(\"0y12\", 0, 0) = %ld\n", strtol("0y12", 0, 0));
+ printf("strtol(\"hello\", 0, 30) = %ld\n", strtol("hello", 0, 30));
+ printf("strtol(\"hello\", 0, 10) = %ld\n", strtol("hello", 0, 10));
+ printf("strtol(\"not-a-number\") = %ld\n", strtol("not-a-number", 0, 0));
+
+ char str[] = " 0x12end";
+ char* endptr;
+ printf("strtol(\" 0x12end\") = %ld\n", strtol(str, &endptr, 0));
+ printf("endptr - str = %d\n", endptr - str);
+ check_error();
+
+ return 0;
+}
diff --git a/tests/runner.py b/tests/runner.py
index 9b7c8ec9..17efec06 100644
--- a/tests/runner.py
+++ b/tests/runner.py
@@ -2216,6 +2216,7 @@ if 'benchmark' not in sys.argv:
printf("%g\n", strtod("1.0", &endptr));
printf("%g\n", strtod("123", &endptr));
printf("%g\n", strtod("123.456", &endptr));
+ printf("%g\n", strtod("-123.456", &endptr));
printf("%g\n", strtod("1234567891234567890", &endptr));
printf("%g\n", strtod("1234567891234567890e+50", &endptr));
printf("%g\n", strtod("84e+220", &endptr));
@@ -2224,8 +2225,8 @@ if 'benchmark' not in sys.argv:
printf("%g\n", strtod("123e-250", &endptr));
printf("%g\n", strtod("123e-450", &endptr));
- char str[] = "12.34e56end";
- strtod(str, &endptr);
+ char str[] = " 12.34e56end";
+ printf("%g\n", strtod(str, &endptr));
printf("%d\n", endptr - str);
return 0;
}
@@ -2239,6 +2240,7 @@ if 'benchmark' not in sys.argv:
1
123
123.456
+ -123.456
1.23457e+18
1.23457e+68
8.4e+221
@@ -2246,10 +2248,17 @@ if 'benchmark' not in sys.argv:
1.23e-48
1.23e-248
0
- 8
+ 1.234e+57
+ 10
'''
self.do_test(src, re.sub(r'\n\s+', '\n', expected))
+ def test_parseInt(self):
+ if USE_TYPED_ARRAYS != 0: return self.skip() # Typed arrays truncate i64.
+ src = open(path_from_root('tests', 'parseInt', 'src.c'), 'r').read()
+ expected = open(path_from_root('tests', 'parseInt', 'output.txt'), 'r').read()
+ self.do_test(src, expected)
+
def test_printf(self):
if USE_TYPED_ARRAYS != 0: return self.skip() # Typed arrays truncate i64.
src = open(path_from_root('tests', 'printf', 'test.c'), 'r').read()