Invert over-long UTF-8 bool for readability.
Also actually assign a bool to it. I'd originally written a #define
and apparently forgot to fix the value. I'm a bit surprised that clang
didn't complain.
Bug: None
Test: ./tests/run-on-host.sh 64 --gtest_filter="uchar.*"
Test: ./tests/run-on-host.sh glibc --gtest_filter="uchar.*"
Test: ./tests/run-on-host.sh musl --gtest_filter="uchar.*"
Change-Id: Iac46bc9c48fd70853d5c447e812e25e617281d2b
diff --git a/tests/uchar_test.cpp b/tests/uchar_test.cpp
index 793a5b3..d7174bd 100644
--- a/tests/uchar_test.cpp
+++ b/tests/uchar_test.cpp
@@ -33,11 +33,11 @@
// excluded, so it has never supported them. Other implementations (at least
// as of glibc 2.36), do support those sequences.
#if defined(__ANDROID__) || defined(ANDROID_HOST_MUSL)
-constexpr bool kLibcSupportsLongUtf8Sequences = 0;
+constexpr bool kLibcRejectsOverLongUtf8Sequences = true;
#elif defined(__GLIBC__)
-constexpr bool kLibcSupportsLongUtf8Sequences = 1;
+constexpr bool kLibcRejectsOverLongUtf8Sequences = false;
#else
-#error kLibcSupportsLongUtf8Sequences must be configured for this platform
+#error kLibcRejectsOverLongUtf8Sequences must be configured for this platform
#endif
// C23 7.30.1 (for each `mbrtoc*` function) says:
@@ -196,14 +196,14 @@
char16_t out = u'\0';
errno = 0;
auto result = mbrtoc16(&out, "\xf8\xa1\xa2\xa3\xa4", 5, nullptr);
- if (kLibcSupportsLongUtf8Sequences) {
- EXPECT_EQ(5U, result);
- EXPECT_EQ(0, errno);
- EXPECT_EQ(u'\uf94a', out);
- } else {
+ if (kLibcRejectsOverLongUtf8Sequences) {
EXPECT_EQ(static_cast<size_t>(-1), result);
EXPECT_EQ(EILSEQ, errno);
EXPECT_EQ(u'\0', out);
+ } else {
+ EXPECT_EQ(5U, result);
+ EXPECT_EQ(0, errno);
+ EXPECT_EQ(u'\uf94a', out);
}
}
@@ -323,14 +323,14 @@
char32_t out = U'\0';
errno = 0;
auto result = mbrtoc32(&out, "\xf5\x80\x80\x80", 4, nullptr);
- if (kLibcSupportsLongUtf8Sequences) {
- EXPECT_EQ(4U, result);
- EXPECT_EQ(0, errno);
- EXPECT_EQ(U'\x140000', out);
- } else {
+ if (kLibcRejectsOverLongUtf8Sequences) {
EXPECT_EQ(static_cast<size_t>(-1), result);
EXPECT_EQ(EILSEQ, errno);
EXPECT_EQ(U'\0', out);
+ } else {
+ EXPECT_EQ(4U, result);
+ EXPECT_EQ(0, errno);
+ EXPECT_EQ(U'\x140000', out);
}
}