[libc-commits] [libc] 1d02a8b - [libc] fix string conversion tests for windows
Michael Jones via libc-commits
libc-commits at lists.llvm.org
Tue Aug 24 11:06:25 PDT 2021
Author: Michael Jones
Date: 2021-08-24T18:06:21Z
New Revision: 1d02a8bcd393ea9c50f0212797059888efc78002
URL: https://github.com/llvm/llvm-project/commit/1d02a8bcd393ea9c50f0212797059888efc78002
DIFF: https://github.com/llvm/llvm-project/commit/1d02a8bcd393ea9c50f0212797059888efc78002.diff
LOG: [libc] fix string conversion tests for windows
There were some copy paste errors as well as some oddities around how
windows handles the difference between long and long long types. This
change fixes those.
Reviewed By: sivachandra
Differential Revision: https://reviews.llvm.org/D108591
Added:
Modified:
libc/test/src/stdlib/strtol_test.cpp
libc/test/src/stdlib/strtoll_test.cpp
libc/test/src/stdlib/strtoul_test.cpp
libc/test/src/stdlib/strtoull_test.cpp
libc/utils/CPP/Limits.h
Removed:
################################################################################
diff --git a/libc/test/src/stdlib/strtol_test.cpp b/libc/test/src/stdlib/strtol_test.cpp
index 14a473537b398..c6633e58f4a04 100644
--- a/libc/test/src/stdlib/strtol_test.cpp
+++ b/libc/test/src/stdlib/strtol_test.cpp
@@ -12,6 +12,7 @@
#include <errno.h>
#include <limits.h>
+#include <stddef.h>
TEST(LlvmLibcStrToLTest, InvalidBase) {
const char *ten = "10";
@@ -27,7 +28,8 @@ TEST(LlvmLibcStrToLTest, CleanBaseTenDecode) {
errno = 0;
ASSERT_EQ(__llvm_libc::strtol(ten, &str_end, 10), 10l);
ASSERT_EQ(errno, 0);
- EXPECT_EQ(str_end - ten, 2l);
+ EXPECT_EQ(str_end - ten, ptr
diff _t(2));
+
errno = 0;
ASSERT_EQ(__llvm_libc::strtol(ten, nullptr, 10), 10l);
ASSERT_EQ(errno, 0);
@@ -36,39 +38,39 @@ TEST(LlvmLibcStrToLTest, CleanBaseTenDecode) {
errno = 0;
ASSERT_EQ(__llvm_libc::strtol(hundred, &str_end, 10), 100l);
ASSERT_EQ(errno, 0);
- EXPECT_EQ(str_end - hundred, 3l);
+ EXPECT_EQ(str_end - hundred, ptr
diff _t(3));
const char *negative = "-100";
errno = 0;
ASSERT_EQ(__llvm_libc::strtol(negative, &str_end, 10), -100l);
ASSERT_EQ(errno, 0);
- EXPECT_EQ(str_end - negative, 4l);
+ EXPECT_EQ(str_end - negative, ptr
diff _t(4));
const char *big_number = "123456789012345";
errno = 0;
ASSERT_EQ(__llvm_libc::strtol(big_number, &str_end, 10), 123456789012345l);
ASSERT_EQ(errno, 0);
- EXPECT_EQ(str_end - big_number, 15l);
+ EXPECT_EQ(str_end - big_number, ptr
diff _t(15));
const char *big_negative_number = "-123456789012345";
errno = 0;
ASSERT_EQ(__llvm_libc::strtol(big_negative_number, &str_end, 10),
-123456789012345l);
ASSERT_EQ(errno, 0);
- EXPECT_EQ(str_end - big_negative_number, 16l);
+ EXPECT_EQ(str_end - big_negative_number, ptr
diff _t(16));
const char *too_big_number = "123456789012345678901";
errno = 0;
ASSERT_EQ(__llvm_libc::strtol(too_big_number, &str_end, 10), LONG_MAX);
ASSERT_EQ(errno, ERANGE);
- EXPECT_EQ(str_end - too_big_number, 21l);
+ EXPECT_EQ(str_end - too_big_number, ptr
diff _t(21));
const char *too_big_negative_number = "-123456789012345678901";
errno = 0;
ASSERT_EQ(__llvm_libc::strtol(too_big_negative_number, &str_end, 10),
LONG_MIN);
ASSERT_EQ(errno, ERANGE);
- EXPECT_EQ(str_end - too_big_negative_number, 22l);
+ EXPECT_EQ(str_end - too_big_negative_number, ptr
diff _t(22));
const char *long_number_range_test =
"10000000000000000000000000000000000000000000000000";
@@ -76,7 +78,7 @@ TEST(LlvmLibcStrToLTest, CleanBaseTenDecode) {
ASSERT_EQ(__llvm_libc::strtol(long_number_range_test, &str_end, 10),
LONG_MAX);
ASSERT_EQ(errno, ERANGE);
- EXPECT_EQ(str_end - long_number_range_test, 50l);
+ EXPECT_EQ(str_end - long_number_range_test, ptr
diff _t(50));
}
TEST(LlvmLibcStrToLTest, MessyBaseTenDecode) {
@@ -86,61 +88,61 @@ TEST(LlvmLibcStrToLTest, MessyBaseTenDecode) {
errno = 0;
ASSERT_EQ(__llvm_libc::strtol(spaces_before, &str_end, 10), 10l);
ASSERT_EQ(errno, 0);
- EXPECT_EQ(str_end - spaces_before, 7l);
+ EXPECT_EQ(str_end - spaces_before, ptr
diff _t(7));
const char *spaces_after = "10 ";
errno = 0;
ASSERT_EQ(__llvm_libc::strtol(spaces_after, &str_end, 10), 10l);
ASSERT_EQ(errno, 0);
- EXPECT_EQ(str_end - spaces_after, 2l);
+ EXPECT_EQ(str_end - spaces_after, ptr
diff _t(2));
const char *word_before = "word10";
errno = 0;
ASSERT_EQ(__llvm_libc::strtol(word_before, &str_end, 10), 0l);
ASSERT_EQ(errno, 0);
- EXPECT_EQ(str_end - word_before, 0l);
+ EXPECT_EQ(str_end - word_before, ptr
diff _t(0));
const char *word_after = "10word";
errno = 0;
ASSERT_EQ(__llvm_libc::strtol(word_after, &str_end, 10), 10l);
ASSERT_EQ(errno, 0);
- EXPECT_EQ(str_end - word_after, 2l);
+ EXPECT_EQ(str_end - word_after, ptr
diff _t(2));
const char *two_numbers = "10 999";
errno = 0;
ASSERT_EQ(__llvm_libc::strtol(two_numbers, &str_end, 10), 10l);
ASSERT_EQ(errno, 0);
- EXPECT_EQ(str_end - two_numbers, 2l);
+ EXPECT_EQ(str_end - two_numbers, ptr
diff _t(2));
const char *two_signs = "--10 999";
errno = 0;
ASSERT_EQ(__llvm_libc::strtol(two_signs, &str_end, 10), 0l);
ASSERT_EQ(errno, 0);
- EXPECT_EQ(str_end - two_signs, 1l);
+ EXPECT_EQ(str_end - two_signs, ptr
diff _t(1));
const char *sign_before = "+2=4";
errno = 0;
ASSERT_EQ(__llvm_libc::strtol(sign_before, &str_end, 10), 2l);
ASSERT_EQ(errno, 0);
- EXPECT_EQ(str_end - sign_before, 2l);
+ EXPECT_EQ(str_end - sign_before, ptr
diff _t(2));
const char *sign_after = "2+2=4";
errno = 0;
ASSERT_EQ(__llvm_libc::strtol(sign_after, &str_end, 10), 2l);
ASSERT_EQ(errno, 0);
- EXPECT_EQ(str_end - sign_after, 1l);
+ EXPECT_EQ(str_end - sign_after, ptr
diff _t(1));
const char *tab_before = "\t10";
errno = 0;
ASSERT_EQ(__llvm_libc::strtol(tab_before, &str_end, 10), 10l);
ASSERT_EQ(errno, 0);
- EXPECT_EQ(str_end - tab_before, 3l);
+ EXPECT_EQ(str_end - tab_before, ptr
diff _t(3));
const char *all_together = "\t -12345and+67890";
errno = 0;
ASSERT_EQ(__llvm_libc::strtol(all_together, &str_end, 10), -12345l);
ASSERT_EQ(errno, 0);
- EXPECT_EQ(str_end - all_together, 9l);
+ EXPECT_EQ(str_end - all_together, ptr
diff _t(9));
}
static char int_to_b36_char(int input) {
@@ -250,13 +252,13 @@ TEST(LlvmLibcStrToLTest, CleanBaseSixteenDecode) {
errno = 0;
ASSERT_EQ(__llvm_libc::strtol(no_prefix, &str_end, 16), 0x123abcl);
ASSERT_EQ(errno, 0);
- EXPECT_EQ(str_end - no_prefix, 6l);
+ EXPECT_EQ(str_end - no_prefix, ptr
diff _t(6));
const char *yes_prefix = "0x456def";
errno = 0;
ASSERT_EQ(__llvm_libc::strtol(yes_prefix, &str_end, 16), 0x456defl);
ASSERT_EQ(errno, 0);
- EXPECT_EQ(str_end - yes_prefix, 8l);
+ EXPECT_EQ(str_end - yes_prefix, ptr
diff _t(8));
}
TEST(LlvmLibcStrToLTest, AutomaticBaseSelection) {
@@ -266,24 +268,24 @@ TEST(LlvmLibcStrToLTest, AutomaticBaseSelection) {
errno = 0;
ASSERT_EQ(__llvm_libc::strtol(base_ten, &str_end, 0), 12345l);
ASSERT_EQ(errno, 0);
- EXPECT_EQ(str_end - base_ten, 5l);
+ EXPECT_EQ(str_end - base_ten, ptr
diff _t(5));
const char *base_sixteen_no_prefix = "123abc";
errno = 0;
ASSERT_EQ(__llvm_libc::strtol(base_sixteen_no_prefix, &str_end, 0), 123l);
ASSERT_EQ(errno, 0);
- EXPECT_EQ(str_end - base_sixteen_no_prefix, 3l);
+ EXPECT_EQ(str_end - base_sixteen_no_prefix, ptr
diff _t(3));
const char *base_sixteen_with_prefix = "0x456def";
errno = 0;
ASSERT_EQ(__llvm_libc::strtol(base_sixteen_with_prefix, &str_end, 0),
0x456defl);
ASSERT_EQ(errno, 0);
- EXPECT_EQ(str_end - base_sixteen_with_prefix, 8l);
+ EXPECT_EQ(str_end - base_sixteen_with_prefix, ptr
diff _t(8));
const char *base_eight_with_prefix = "012345";
errno = 0;
ASSERT_EQ(__llvm_libc::strtol(base_eight_with_prefix, &str_end, 0), 012345l);
ASSERT_EQ(errno, 0);
- EXPECT_EQ(str_end - base_eight_with_prefix, 6l);
+ EXPECT_EQ(str_end - base_eight_with_prefix, ptr
diff _t(6));
}
diff --git a/libc/test/src/stdlib/strtoll_test.cpp b/libc/test/src/stdlib/strtoll_test.cpp
index ca5467182b7d6..1bb3c2a2638df 100644
--- a/libc/test/src/stdlib/strtoll_test.cpp
+++ b/libc/test/src/stdlib/strtoll_test.cpp
@@ -12,6 +12,7 @@
#include <errno.h>
#include <limits.h>
+#include <stddef.h>
TEST(LlvmLibcStrToLLTest, InvalidBase) {
const char *ten = "10";
@@ -27,7 +28,7 @@ TEST(LlvmLibcStrToLLTest, CleanBaseTenDecode) {
errno = 0;
ASSERT_EQ(__llvm_libc::strtoll(ten, &str_end, 10), 10ll);
ASSERT_EQ(errno, 0);
- EXPECT_EQ(str_end - ten, 2l);
+ EXPECT_EQ(str_end - ten, ptr
diff _t(2));
errno = 0;
ASSERT_EQ(__llvm_libc::strtoll(ten, nullptr, 10), 10ll);
ASSERT_EQ(errno, 0);
@@ -36,53 +37,53 @@ TEST(LlvmLibcStrToLLTest, CleanBaseTenDecode) {
errno = 0;
ASSERT_EQ(__llvm_libc::strtoll(hundred, &str_end, 10), 100ll);
ASSERT_EQ(errno, 0);
- EXPECT_EQ(str_end - hundred, 3l);
+ EXPECT_EQ(str_end - hundred, ptr
diff _t(3));
const char *negative = "-100";
errno = 0;
ASSERT_EQ(__llvm_libc::strtoll(negative, &str_end, 10), -100ll);
ASSERT_EQ(errno, 0);
- EXPECT_EQ(str_end - negative, 4l);
+ EXPECT_EQ(str_end - negative, ptr
diff _t(4));
const char *big_number = "123456789012345";
errno = 0;
ASSERT_EQ(__llvm_libc::strtoll(big_number, &str_end, 10), 123456789012345ll);
ASSERT_EQ(errno, 0);
- EXPECT_EQ(str_end - big_number, 15l);
+ EXPECT_EQ(str_end - big_number, ptr
diff _t(15));
const char *big_negative_number = "-123456789012345";
errno = 0;
ASSERT_EQ(__llvm_libc::strtoll(big_negative_number, &str_end, 10),
-123456789012345ll);
ASSERT_EQ(errno, 0);
- EXPECT_EQ(str_end - big_negative_number, 16l);
+ EXPECT_EQ(str_end - big_negative_number, ptr
diff _t(16));
const char *long_long_max_number = "9223372036854775807";
errno = 0;
ASSERT_EQ(__llvm_libc::strtoll(long_long_max_number, &str_end, 10),
9223372036854775807ll);
ASSERT_EQ(errno, 0);
- EXPECT_EQ(str_end - long_long_max_number, 19l);
+ EXPECT_EQ(str_end - long_long_max_number, ptr
diff _t(19));
const char *long_long_min_number = "-9223372036854775808";
errno = 0;
ASSERT_EQ(__llvm_libc::strtoll(long_long_min_number, &str_end, 10),
-9223372036854775807ll - 1ll);
ASSERT_EQ(errno, 0);
- EXPECT_EQ(str_end - long_long_min_number, 20l);
+ EXPECT_EQ(str_end - long_long_min_number, ptr
diff _t(20));
const char *too_big_number = "123456789012345678901";
errno = 0;
ASSERT_EQ(__llvm_libc::strtoll(too_big_number, &str_end, 10), LLONG_MAX);
ASSERT_EQ(errno, ERANGE);
- EXPECT_EQ(str_end - too_big_number, 21l);
+ EXPECT_EQ(str_end - too_big_number, ptr
diff _t(21));
const char *too_big_negative_number = "-123456789012345678901";
errno = 0;
ASSERT_EQ(__llvm_libc::strtoll(too_big_negative_number, &str_end, 10),
LLONG_MIN);
ASSERT_EQ(errno, ERANGE);
- EXPECT_EQ(str_end - too_big_negative_number, 22l);
+ EXPECT_EQ(str_end - too_big_negative_number, ptr
diff _t(22));
const char *long_number_range_test =
"10000000000000000000000000000000000000000000000000";
@@ -90,7 +91,7 @@ TEST(LlvmLibcStrToLLTest, CleanBaseTenDecode) {
ASSERT_EQ(__llvm_libc::strtoll(long_number_range_test, &str_end, 10),
LLONG_MAX);
ASSERT_EQ(errno, ERANGE);
- EXPECT_EQ(str_end - long_number_range_test, 50l);
+ EXPECT_EQ(str_end - long_number_range_test, ptr
diff _t(50));
const char *long_long_max_number_with_numbers_after =
"9223372036854775807123";
@@ -99,7 +100,9 @@ TEST(LlvmLibcStrToLLTest, CleanBaseTenDecode) {
&str_end, 10),
LLONG_MAX);
ASSERT_EQ(errno, ERANGE);
- EXPECT_EQ(str_end - long_long_max_number_with_numbers_after, 22l);
+ EXPECT_EQ(
+ static_cast<long long>(str_end - long_long_max_number_with_numbers_after),
+ 22ll);
}
TEST(LlvmLibcStrToLLTest, MessyBaseTenDecode) {
@@ -109,61 +112,61 @@ TEST(LlvmLibcStrToLLTest, MessyBaseTenDecode) {
errno = 0;
ASSERT_EQ(__llvm_libc::strtoll(spaces_before, &str_end, 10), 10ll);
ASSERT_EQ(errno, 0);
- EXPECT_EQ(str_end - spaces_before, 7l);
+ EXPECT_EQ(str_end - spaces_before, ptr
diff _t(7));
const char *spaces_after = "10 ";
errno = 0;
ASSERT_EQ(__llvm_libc::strtoll(spaces_after, &str_end, 10), 10ll);
ASSERT_EQ(errno, 0);
- EXPECT_EQ(str_end - spaces_after, 2l);
+ EXPECT_EQ(str_end - spaces_after, ptr
diff _t(2));
const char *word_before = "word10";
errno = 0;
ASSERT_EQ(__llvm_libc::strtoll(word_before, &str_end, 10), 0ll);
ASSERT_EQ(errno, 0);
- EXPECT_EQ(str_end - word_before, 0l);
+ EXPECT_EQ(str_end - word_before, ptr
diff _t(0));
const char *word_after = "10word";
errno = 0;
ASSERT_EQ(__llvm_libc::strtoll(word_after, &str_end, 10), 10ll);
ASSERT_EQ(errno, 0);
- EXPECT_EQ(str_end - word_after, 2l);
+ EXPECT_EQ(str_end - word_after, ptr
diff _t(2));
const char *two_numbers = "10 999";
errno = 0;
ASSERT_EQ(__llvm_libc::strtoll(two_numbers, &str_end, 10), 10ll);
ASSERT_EQ(errno, 0);
- EXPECT_EQ(str_end - two_numbers, 2l);
+ EXPECT_EQ(str_end - two_numbers, ptr
diff _t(2));
const char *two_signs = "--10 999";
errno = 0;
ASSERT_EQ(__llvm_libc::strtoll(two_signs, &str_end, 10), 0ll);
ASSERT_EQ(errno, 0);
- EXPECT_EQ(str_end - two_signs, 1l);
+ EXPECT_EQ(str_end - two_signs, ptr
diff _t(1));
const char *sign_before = "+2=4";
errno = 0;
ASSERT_EQ(__llvm_libc::strtoll(sign_before, &str_end, 10), 2ll);
ASSERT_EQ(errno, 0);
- EXPECT_EQ(str_end - sign_before, 2l);
+ EXPECT_EQ(str_end - sign_before, ptr
diff _t(2));
const char *sign_after = "2+2=4";
errno = 0;
ASSERT_EQ(__llvm_libc::strtoll(sign_after, &str_end, 10), 2ll);
ASSERT_EQ(errno, 0);
- EXPECT_EQ(str_end - sign_after, 1l);
+ EXPECT_EQ(str_end - sign_after, ptr
diff _t(1));
const char *tab_before = "\t10";
errno = 0;
ASSERT_EQ(__llvm_libc::strtoll(tab_before, &str_end, 10), 10ll);
ASSERT_EQ(errno, 0);
- EXPECT_EQ(str_end - tab_before, 3l);
+ EXPECT_EQ(str_end - tab_before, ptr
diff _t(3));
const char *all_together = "\t -12345and+67890";
errno = 0;
ASSERT_EQ(__llvm_libc::strtoll(all_together, &str_end, 10), -12345ll);
ASSERT_EQ(errno, 0);
- EXPECT_EQ(str_end - all_together, 9l);
+ EXPECT_EQ(str_end - all_together, ptr
diff _t(9));
}
static char int_to_b36_char(int input) {
@@ -274,13 +277,13 @@ TEST(LlvmLibcStrToLLTest, CleanBaseSixteenDecode) {
errno = 0;
ASSERT_EQ(__llvm_libc::strtoll(no_prefix, &str_end, 16), 0x123abcll);
ASSERT_EQ(errno, 0);
- EXPECT_EQ(str_end - no_prefix, 6l);
+ EXPECT_EQ(str_end - no_prefix, ptr
diff _t(6));
const char *yes_prefix = "0x456def";
errno = 0;
ASSERT_EQ(__llvm_libc::strtoll(yes_prefix, &str_end, 16), 0x456defll);
ASSERT_EQ(errno, 0);
- EXPECT_EQ(str_end - yes_prefix, 8l);
+ EXPECT_EQ(str_end - yes_prefix, ptr
diff _t(8));
}
TEST(LlvmLibcStrToLLTest, AutomaticBaseSelection) {
@@ -290,25 +293,25 @@ TEST(LlvmLibcStrToLLTest, AutomaticBaseSelection) {
errno = 0;
ASSERT_EQ(__llvm_libc::strtoll(base_ten, &str_end, 0), 12345ll);
ASSERT_EQ(errno, 0);
- EXPECT_EQ(str_end - base_ten, 5l);
+ EXPECT_EQ(str_end - base_ten, ptr
diff _t(5));
const char *base_sixteen_no_prefix = "123abc";
errno = 0;
ASSERT_EQ(__llvm_libc::strtoll(base_sixteen_no_prefix, &str_end, 0), 123ll);
ASSERT_EQ(errno, 0);
- EXPECT_EQ(str_end - base_sixteen_no_prefix, 3l);
+ EXPECT_EQ(str_end - base_sixteen_no_prefix, ptr
diff _t(3));
const char *base_sixteen_with_prefix = "0x456def";
errno = 0;
ASSERT_EQ(__llvm_libc::strtoll(base_sixteen_with_prefix, &str_end, 0),
0x456defll);
ASSERT_EQ(errno, 0);
- EXPECT_EQ(str_end - base_sixteen_with_prefix, 8l);
+ EXPECT_EQ(str_end - base_sixteen_with_prefix, ptr
diff _t(8));
const char *base_eight_with_prefix = "012345";
errno = 0;
ASSERT_EQ(__llvm_libc::strtoll(base_eight_with_prefix, &str_end, 0),
012345ll);
ASSERT_EQ(errno, 0);
- EXPECT_EQ(str_end - base_eight_with_prefix, 6l);
+ EXPECT_EQ(str_end - base_eight_with_prefix, ptr
diff _t(6));
}
diff --git a/libc/test/src/stdlib/strtoul_test.cpp b/libc/test/src/stdlib/strtoul_test.cpp
index cff208618f504..5b93832e36ae7 100644
--- a/libc/test/src/stdlib/strtoul_test.cpp
+++ b/libc/test/src/stdlib/strtoul_test.cpp
@@ -12,6 +12,7 @@
#include <errno.h>
#include <limits.h>
+#include <stddef.h>
TEST(LlvmLibcStrToULTest, InvalidBase) {
const char *ten = "10";
@@ -27,7 +28,7 @@ TEST(LlvmLibcStrToULTest, CleanBaseTenDecode) {
errno = 0;
ASSERT_EQ(__llvm_libc::strtoul(ten, &str_end, 10), 10ul);
ASSERT_EQ(errno, 0);
- EXPECT_EQ(str_end - ten, 2l);
+ EXPECT_EQ(str_end - ten, ptr
diff _t(2));
errno = 0;
ASSERT_EQ(__llvm_libc::strtoul(ten, nullptr, 10), 10ul);
ASSERT_EQ(errno, 0);
@@ -36,32 +37,32 @@ TEST(LlvmLibcStrToULTest, CleanBaseTenDecode) {
errno = 0;
ASSERT_EQ(__llvm_libc::strtoul(hundred, &str_end, 10), 100ul);
ASSERT_EQ(errno, 0);
- EXPECT_EQ(str_end - hundred, 3l);
+ EXPECT_EQ(str_end - hundred, ptr
diff _t(3));
const char *negative = "-100";
errno = 0;
ASSERT_EQ(__llvm_libc::strtoul(negative, &str_end, 10), -(100ul));
ASSERT_EQ(errno, 0);
- EXPECT_EQ(str_end - negative, 4l);
+ EXPECT_EQ(str_end - negative, ptr
diff _t(4));
const char *big_number = "123456789012345";
errno = 0;
ASSERT_EQ(__llvm_libc::strtoul(big_number, &str_end, 10), 123456789012345ul);
ASSERT_EQ(errno, 0);
- EXPECT_EQ(str_end - big_number, 15l);
+ EXPECT_EQ(str_end - big_number, ptr
diff _t(15));
const char *too_big_number = "123456789012345678901";
errno = 0;
ASSERT_EQ(__llvm_libc::strtoul(too_big_number, &str_end, 10), ULONG_MAX);
ASSERT_EQ(errno, ERANGE);
- EXPECT_EQ(str_end - too_big_number, 21l);
+ EXPECT_EQ(str_end - too_big_number, ptr
diff _t(21));
const char *too_big_negative_number = "-123456789012345678901";
errno = 0;
ASSERT_EQ(__llvm_libc::strtoul(too_big_negative_number, &str_end, 10),
ULONG_MAX);
ASSERT_EQ(errno, ERANGE);
- EXPECT_EQ(str_end - too_big_negative_number, 22l);
+ EXPECT_EQ(str_end - too_big_negative_number, ptr
diff _t(22));
const char *long_number_range_test =
"10000000000000000000000000000000000000000000000000";
@@ -69,7 +70,7 @@ TEST(LlvmLibcStrToULTest, CleanBaseTenDecode) {
ASSERT_EQ(__llvm_libc::strtoul(long_number_range_test, &str_end, 10),
ULONG_MAX);
ASSERT_EQ(errno, ERANGE);
- EXPECT_EQ(str_end - long_number_range_test, 50l);
+ EXPECT_EQ(str_end - long_number_range_test, ptr
diff _t(50));
}
TEST(LlvmLibcStrToULTest, MessyBaseTenDecode) {
@@ -79,61 +80,61 @@ TEST(LlvmLibcStrToULTest, MessyBaseTenDecode) {
errno = 0;
ASSERT_EQ(__llvm_libc::strtoul(spaces_before, &str_end, 10), 10ul);
ASSERT_EQ(errno, 0);
- EXPECT_EQ(str_end - spaces_before, 7l);
+ EXPECT_EQ(str_end - spaces_before, ptr
diff _t(7));
const char *spaces_after = "10 ";
errno = 0;
ASSERT_EQ(__llvm_libc::strtoul(spaces_after, &str_end, 10), 10ul);
ASSERT_EQ(errno, 0);
- EXPECT_EQ(str_end - spaces_after, 2l);
+ EXPECT_EQ(str_end - spaces_after, ptr
diff _t(2));
const char *word_before = "word10";
errno = 0;
ASSERT_EQ(__llvm_libc::strtoul(word_before, &str_end, 10), 0ul);
ASSERT_EQ(errno, 0);
- EXPECT_EQ(str_end - word_before, 0l);
+ EXPECT_EQ(str_end - word_before, ptr
diff _t(0));
const char *word_after = "10word";
errno = 0;
ASSERT_EQ(__llvm_libc::strtoul(word_after, &str_end, 10), 10ul);
ASSERT_EQ(errno, 0);
- EXPECT_EQ(str_end - word_after, 2l);
+ EXPECT_EQ(str_end - word_after, ptr
diff _t(2));
const char *two_numbers = "10 999";
errno = 0;
ASSERT_EQ(__llvm_libc::strtoul(two_numbers, &str_end, 10), 10ul);
ASSERT_EQ(errno, 0);
- EXPECT_EQ(str_end - two_numbers, 2l);
+ EXPECT_EQ(str_end - two_numbers, ptr
diff _t(2));
const char *two_signs = "--10 999";
errno = 0;
ASSERT_EQ(__llvm_libc::strtoul(two_signs, &str_end, 10), 0ul);
ASSERT_EQ(errno, 0);
- EXPECT_EQ(str_end - two_signs, 1l);
+ EXPECT_EQ(str_end - two_signs, ptr
diff _t(1));
const char *sign_before = "+2=4";
errno = 0;
ASSERT_EQ(__llvm_libc::strtoul(sign_before, &str_end, 10), 2ul);
ASSERT_EQ(errno, 0);
- EXPECT_EQ(str_end - sign_before, 2l);
+ EXPECT_EQ(str_end - sign_before, ptr
diff _t(2));
const char *sign_after = "2+2=4";
errno = 0;
ASSERT_EQ(__llvm_libc::strtoul(sign_after, &str_end, 10), 2ul);
ASSERT_EQ(errno, 0);
- EXPECT_EQ(str_end - sign_after, 1l);
+ EXPECT_EQ(str_end - sign_after, ptr
diff _t(1));
const char *tab_before = "\t10";
errno = 0;
ASSERT_EQ(__llvm_libc::strtoul(tab_before, &str_end, 10), 10ul);
ASSERT_EQ(errno, 0);
- EXPECT_EQ(str_end - tab_before, 3l);
+ EXPECT_EQ(str_end - tab_before, ptr
diff _t(3));
const char *all_together = "\t -12345and+67890";
errno = 0;
ASSERT_EQ(__llvm_libc::strtoul(all_together, &str_end, 10), -(12345ul));
ASSERT_EQ(errno, 0);
- EXPECT_EQ(str_end - all_together, 9l);
+ EXPECT_EQ(str_end - all_together, ptr
diff _t(9));
}
static char int_to_b36_char(int input) {
@@ -244,13 +245,13 @@ TEST(LlvmLibcStrToULTest, CleanBaseSixteenDecode) {
errno = 0;
ASSERT_EQ(__llvm_libc::strtoul(no_prefix, &str_end, 16), 0x123abcul);
ASSERT_EQ(errno, 0);
- EXPECT_EQ(str_end - no_prefix, 6l);
+ EXPECT_EQ(str_end - no_prefix, ptr
diff _t(6));
const char *yes_prefix = "0x456def";
errno = 0;
ASSERT_EQ(__llvm_libc::strtoul(yes_prefix, &str_end, 16), 0x456deful);
ASSERT_EQ(errno, 0);
- EXPECT_EQ(str_end - yes_prefix, 8l);
+ EXPECT_EQ(str_end - yes_prefix, ptr
diff _t(8));
}
TEST(LlvmLibcStrToULTest, AutomaticBaseSelection) {
@@ -260,25 +261,25 @@ TEST(LlvmLibcStrToULTest, AutomaticBaseSelection) {
errno = 0;
ASSERT_EQ(__llvm_libc::strtoul(base_ten, &str_end, 0), 12345ul);
ASSERT_EQ(errno, 0);
- EXPECT_EQ(str_end - base_ten, 5l);
+ EXPECT_EQ(str_end - base_ten, ptr
diff _t(5));
const char *base_sixteen_no_prefix = "123abc";
errno = 0;
ASSERT_EQ(__llvm_libc::strtoul(base_sixteen_no_prefix, &str_end, 0), 123ul);
ASSERT_EQ(errno, 0);
- EXPECT_EQ(str_end - base_sixteen_no_prefix, 3l);
+ EXPECT_EQ(str_end - base_sixteen_no_prefix, ptr
diff _t(3));
const char *base_sixteen_with_prefix = "0x456def";
errno = 0;
ASSERT_EQ(__llvm_libc::strtoul(base_sixteen_with_prefix, &str_end, 0),
0x456deful);
ASSERT_EQ(errno, 0);
- EXPECT_EQ(str_end - base_sixteen_with_prefix, 8l);
+ EXPECT_EQ(str_end - base_sixteen_with_prefix, ptr
diff _t(8));
const char *base_eight_with_prefix = "012345";
errno = 0;
ASSERT_EQ(__llvm_libc::strtoul(base_eight_with_prefix, &str_end, 0),
012345ul);
ASSERT_EQ(errno, 0);
- EXPECT_EQ(str_end - base_eight_with_prefix, 6l);
+ EXPECT_EQ(str_end - base_eight_with_prefix, ptr
diff _t(6));
}
diff --git a/libc/test/src/stdlib/strtoull_test.cpp b/libc/test/src/stdlib/strtoull_test.cpp
index e6b52c92432ab..a552042c816d9 100644
--- a/libc/test/src/stdlib/strtoull_test.cpp
+++ b/libc/test/src/stdlib/strtoull_test.cpp
@@ -12,6 +12,7 @@
#include <errno.h>
#include <limits.h>
+#include <stddef.h>
TEST(LlvmLibcStrToULLTest, InvalidBase) {
const char *ten = "10";
@@ -27,7 +28,7 @@ TEST(LlvmLibcStrToULLTest, CleanBaseTenDecode) {
errno = 0;
ASSERT_EQ(__llvm_libc::strtoull(ten, &str_end, 10), 10ull);
ASSERT_EQ(errno, 0);
- EXPECT_EQ(str_end - ten, 2l);
+ EXPECT_EQ(str_end - ten, ptr
diff _t(2));
errno = 0;
ASSERT_EQ(__llvm_libc::strtoull(ten, nullptr, 10), 10ull);
ASSERT_EQ(errno, 0);
@@ -36,40 +37,40 @@ TEST(LlvmLibcStrToULLTest, CleanBaseTenDecode) {
errno = 0;
ASSERT_EQ(__llvm_libc::strtoull(hundred, &str_end, 10), 100ull);
ASSERT_EQ(errno, 0);
- EXPECT_EQ(str_end - hundred, 3l);
+ EXPECT_EQ(str_end - hundred, ptr
diff _t(3));
const char *negative = "-100";
errno = 0;
ASSERT_EQ(__llvm_libc::strtoull(negative, &str_end, 10), -(100ull));
ASSERT_EQ(errno, 0);
- EXPECT_EQ(str_end - negative, 4l);
+ EXPECT_EQ(str_end - negative, ptr
diff _t(4));
const char *big_number = "123456789012345";
errno = 0;
ASSERT_EQ(__llvm_libc::strtoull(big_number, &str_end, 10),
123456789012345ull);
ASSERT_EQ(errno, 0);
- EXPECT_EQ(str_end - big_number, 15l);
+ EXPECT_EQ(str_end - big_number, ptr
diff _t(15));
const char *unsigned_long_long_max_number = "18446744073709551615";
errno = 0;
ASSERT_EQ(__llvm_libc::strtoull(unsigned_long_long_max_number, &str_end, 10),
18446744073709551615ull);
ASSERT_EQ(errno, 0);
- EXPECT_EQ(str_end - unsigned_long_long_max_number, 20l);
+ EXPECT_EQ(str_end - unsigned_long_long_max_number, ptr
diff _t(20));
const char *too_big_number = "123456789012345678901";
errno = 0;
ASSERT_EQ(__llvm_libc::strtoull(too_big_number, &str_end, 10), ULLONG_MAX);
ASSERT_EQ(errno, ERANGE);
- EXPECT_EQ(str_end - too_big_number, 21l);
+ EXPECT_EQ(str_end - too_big_number, ptr
diff _t(21));
const char *too_big_negative_number = "-123456789012345678901";
errno = 0;
ASSERT_EQ(__llvm_libc::strtoull(too_big_negative_number, &str_end, 10),
ULLONG_MAX);
ASSERT_EQ(errno, ERANGE);
- EXPECT_EQ(str_end - too_big_negative_number, 22l);
+ EXPECT_EQ(str_end - too_big_negative_number, ptr
diff _t(22));
const char *long_number_range_test =
"10000000000000000000000000000000000000000000000000";
@@ -77,7 +78,7 @@ TEST(LlvmLibcStrToULLTest, CleanBaseTenDecode) {
ASSERT_EQ(__llvm_libc::strtoull(long_number_range_test, &str_end, 10),
ULLONG_MAX);
ASSERT_EQ(errno, ERANGE);
- EXPECT_EQ(str_end - long_number_range_test, 50l);
+ EXPECT_EQ(str_end - long_number_range_test, ptr
diff _t(50));
}
TEST(LlvmLibcStrToULLTest, MessyBaseTenDecode) {
@@ -87,61 +88,61 @@ TEST(LlvmLibcStrToULLTest, MessyBaseTenDecode) {
errno = 0;
ASSERT_EQ(__llvm_libc::strtoull(spaces_before, &str_end, 10), 10ull);
ASSERT_EQ(errno, 0);
- EXPECT_EQ(str_end - spaces_before, 7l);
+ EXPECT_EQ(str_end - spaces_before, ptr
diff _t(7));
const char *spaces_after = "10 ";
errno = 0;
ASSERT_EQ(__llvm_libc::strtoull(spaces_after, &str_end, 10), 10ull);
ASSERT_EQ(errno, 0);
- EXPECT_EQ(str_end - spaces_after, 2l);
+ EXPECT_EQ(str_end - spaces_after, ptr
diff _t(2));
const char *word_before = "word10";
errno = 0;
ASSERT_EQ(__llvm_libc::strtoull(word_before, &str_end, 10), 0ull);
ASSERT_EQ(errno, 0);
- EXPECT_EQ(str_end - word_before, 0l);
+ EXPECT_EQ(str_end - word_before, ptr
diff _t(0));
const char *word_after = "10word";
errno = 0;
ASSERT_EQ(__llvm_libc::strtoull(word_after, &str_end, 10), 10ull);
ASSERT_EQ(errno, 0);
- EXPECT_EQ(str_end - word_after, 2l);
+ EXPECT_EQ(str_end - word_after, ptr
diff _t(2));
const char *two_numbers = "10 999";
errno = 0;
ASSERT_EQ(__llvm_libc::strtoull(two_numbers, &str_end, 10), 10ull);
ASSERT_EQ(errno, 0);
- EXPECT_EQ(str_end - two_numbers, 2l);
+ EXPECT_EQ(str_end - two_numbers, ptr
diff _t(2));
const char *two_signs = "--10 999";
errno = 0;
ASSERT_EQ(__llvm_libc::strtoull(two_signs, &str_end, 10), 0ull);
ASSERT_EQ(errno, 0);
- EXPECT_EQ(str_end - two_signs, 1l);
+ EXPECT_EQ(str_end - two_signs, ptr
diff _t(1));
const char *sign_before = "+2=4";
errno = 0;
ASSERT_EQ(__llvm_libc::strtoull(sign_before, &str_end, 10), 2ull);
ASSERT_EQ(errno, 0);
- EXPECT_EQ(str_end - sign_before, 2l);
+ EXPECT_EQ(str_end - sign_before, ptr
diff _t(2));
const char *sign_after = "2+2=4";
errno = 0;
ASSERT_EQ(__llvm_libc::strtoull(sign_after, &str_end, 10), 2ull);
ASSERT_EQ(errno, 0);
- EXPECT_EQ(str_end - sign_after, 1l);
+ EXPECT_EQ(str_end - sign_after, ptr
diff _t(1));
const char *tab_before = "\t10";
errno = 0;
ASSERT_EQ(__llvm_libc::strtoull(tab_before, &str_end, 10), 10ull);
ASSERT_EQ(errno, 0);
- EXPECT_EQ(str_end - tab_before, 3l);
+ EXPECT_EQ(str_end - tab_before, ptr
diff _t(3));
const char *all_together = "\t -12345and+67890";
errno = 0;
ASSERT_EQ(__llvm_libc::strtoull(all_together, &str_end, 10), -(12345ull));
ASSERT_EQ(errno, 0);
- EXPECT_EQ(str_end - all_together, 9l);
+ EXPECT_EQ(str_end - all_together, ptr
diff _t(9));
}
static char int_to_b36_char(int input) {
@@ -255,13 +256,13 @@ TEST(LlvmLibcStrToULLTest, CleanBaseSixteenDecode) {
errno = 0;
ASSERT_EQ(__llvm_libc::strtoull(no_prefix, &str_end, 16), 0x123abcull);
ASSERT_EQ(errno, 0);
- EXPECT_EQ(str_end - no_prefix, 6l);
+ EXPECT_EQ(str_end - no_prefix, ptr
diff _t(6));
const char *yes_prefix = "0x456def";
errno = 0;
ASSERT_EQ(__llvm_libc::strtoull(yes_prefix, &str_end, 16), 0x456defull);
ASSERT_EQ(errno, 0);
- EXPECT_EQ(str_end - yes_prefix, 8l);
+ EXPECT_EQ(str_end - yes_prefix, ptr
diff _t(8));
}
TEST(LlvmLibcStrToULLTest, AutomaticBaseSelection) {
@@ -271,25 +272,25 @@ TEST(LlvmLibcStrToULLTest, AutomaticBaseSelection) {
errno = 0;
ASSERT_EQ(__llvm_libc::strtoull(base_ten, &str_end, 0), 12345ull);
ASSERT_EQ(errno, 0);
- EXPECT_EQ(str_end - base_ten, 5l);
+ EXPECT_EQ(str_end - base_ten, ptr
diff _t(5));
const char *base_sixteen_no_prefix = "123abc";
errno = 0;
ASSERT_EQ(__llvm_libc::strtoull(base_sixteen_no_prefix, &str_end, 0), 123ull);
ASSERT_EQ(errno, 0);
- EXPECT_EQ(str_end - base_sixteen_no_prefix, 3l);
+ EXPECT_EQ(str_end - base_sixteen_no_prefix, ptr
diff _t(3));
const char *base_sixteen_with_prefix = "0x456def";
errno = 0;
ASSERT_EQ(__llvm_libc::strtoull(base_sixteen_with_prefix, &str_end, 0),
0x456defull);
ASSERT_EQ(errno, 0);
- EXPECT_EQ(str_end - base_sixteen_with_prefix, 8l);
+ EXPECT_EQ(str_end - base_sixteen_with_prefix, ptr
diff _t(8));
const char *base_eight_with_prefix = "012345";
errno = 0;
ASSERT_EQ(__llvm_libc::strtoull(base_eight_with_prefix, &str_end, 0),
012345ull);
ASSERT_EQ(errno, 0);
- EXPECT_EQ(str_end - base_eight_with_prefix, 6l);
+ EXPECT_EQ(str_end - base_eight_with_prefix, ptr
diff _t(6));
}
diff --git a/libc/utils/CPP/Limits.h b/libc/utils/CPP/Limits.h
index 1fb57d1f82cec..ac327b30ee71c 100644
--- a/libc/utils/CPP/Limits.h
+++ b/libc/utils/CPP/Limits.h
@@ -39,8 +39,8 @@ template <> class NumericLimits<long> {
};
template <> class NumericLimits<unsigned long> {
public:
- static constexpr long max() { return ULONG_MAX; }
- static constexpr long min() { return 0; }
+ static constexpr unsigned long max() { return ULONG_MAX; }
+ static constexpr unsigned long min() { return 0; }
};
template <> class NumericLimits<long long> {
public:
@@ -49,8 +49,8 @@ template <> class NumericLimits<long long> {
};
template <> class NumericLimits<unsigned long long> {
public:
- static constexpr long max() { return ULLONG_MAX; }
- static constexpr long min() { return 0; }
+ static constexpr unsigned long long max() { return ULLONG_MAX; }
+ static constexpr unsigned long long min() { return 0; }
};
} // namespace cpp
More information about the libc-commits
mailing list