[PATCH 1/2] tests: add verbatim copies of Bionic tests for w/ctype

19 views
Skip to first unread message

Waldemar Kozaczuk

unread,
Aug 15, 2020, 12:21:37 AM8/15/20
to osv...@googlegroups.com, Waldemar Kozaczuk
Signed-off-by: Waldemar Kozaczuk <jwkoz...@gmail.com>
---
tests/tst-ctype.cc | 332 ++++++++++++++++++++++++++++++++++++++++++++
tests/tst-wctype.cc | 247 ++++++++++++++++++++++++++++++++
2 files changed, 579 insertions(+)
create mode 100644 tests/tst-ctype.cc
create mode 100644 tests/tst-wctype.cc

diff --git a/tests/tst-ctype.cc b/tests/tst-ctype.cc
new file mode 100644
index 00000000..826d39a9
--- /dev/null
+++ b/tests/tst-ctype.cc
@@ -0,0 +1,332 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <gtest/gtest.h>
+
+#include <ctype.h>
+
+// We test from -1 (EOF) to 0xff, because that's the range for which behavior
+// is actually defined. (It's explicitly undefined below or above that.) Most
+// of our routines are no longer table-based and behave correctly for the
+// entire int range, but that's not true of other C libraries that we might
+// want to compare against, nor of our isalnum(3) and ispunt(3).
+static constexpr int kMin = -1;
+static constexpr int kMax = 256;
+
+TEST(ctype, isalnum) {
+ for (int i = kMin; i < kMax; ++i) {
+ if ((i >= '0' && i <= '9') ||
+ (i >= 'A' && i <= 'Z') ||
+ (i >= 'a' && i <= 'z')) {
+ EXPECT_TRUE(isalnum(i)) << i;
+ } else {
+ EXPECT_FALSE(isalnum(i)) << i;
+ }
+ }
+}
+
+TEST(ctype, isalnum_l) {
+ for (int i = kMin; i < kMax; ++i) {
+ if ((i >= '0' && i <= '9') ||
+ (i >= 'A' && i <= 'Z') ||
+ (i >= 'a' && i <= 'z')) {
+ EXPECT_TRUE(isalnum_l(i, LC_GLOBAL_LOCALE)) << i;
+ } else {
+ EXPECT_FALSE(isalnum_l(i, LC_GLOBAL_LOCALE)) << i;
+ }
+ }
+}
+
+TEST(ctype, isalpha) {
+ for (int i = kMin; i < kMax; ++i) {
+ if ((i >= 'A' && i <= 'Z') ||
+ (i >= 'a' && i <= 'z')) {
+ EXPECT_TRUE(isalpha(i)) << i;
+ } else {
+ EXPECT_FALSE(isalpha(i)) << i;
+ }
+ }
+}
+
+TEST(ctype, isalpha_l) {
+ for (int i = kMin; i < kMax; ++i) {
+ if ((i >= 'A' && i <= 'Z') ||
+ (i >= 'a' && i <= 'z')) {
+ EXPECT_TRUE(isalpha_l(i, LC_GLOBAL_LOCALE)) << i;
+ } else {
+ EXPECT_FALSE(isalpha_l(i, LC_GLOBAL_LOCALE)) << i;
+ }
+ }
+}
+
+TEST(ctype, isascii) {
+ for (int i = kMin; i < kMax; ++i) {
+ if (i >= 0 && i <= 0x7f) {
+ EXPECT_TRUE(isascii(i)) << i;
+ } else {
+ EXPECT_FALSE(isascii(i)) << i;
+ }
+ }
+}
+
+TEST(ctype, isblank) {
+ for (int i = kMin; i < kMax; ++i) {
+ if (i == '\t' || i == ' ') {
+ EXPECT_TRUE(isblank(i)) << i;
+ } else {
+ EXPECT_FALSE(isblank(i)) << i;
+ }
+ }
+}
+
+TEST(ctype, isblank_l) {
+ for (int i = kMin; i < kMax; ++i) {
+ if (i == '\t' || i == ' ') {
+ EXPECT_TRUE(isblank_l(i, LC_GLOBAL_LOCALE)) << i;
+ } else {
+ EXPECT_FALSE(isblank_l(i, LC_GLOBAL_LOCALE)) << i;
+ }
+ }
+}
+
+TEST(ctype, iscntrl) {
+ for (int i = kMin; i < kMax; ++i) {
+ if ((i >= 0 && i < ' ') || i == 0x7f) {
+ EXPECT_TRUE(iscntrl(i)) << i;
+ } else {
+ EXPECT_FALSE(iscntrl(i)) << i;
+ }
+ }
+}
+
+TEST(ctype, iscntrl_l) {
+ for (int i = kMin; i < kMax; ++i) {
+ if ((i >= 0 && i < ' ') || i == 0x7f) {
+ EXPECT_TRUE(iscntrl_l(i, LC_GLOBAL_LOCALE)) << i;
+ } else {
+ EXPECT_FALSE(iscntrl_l(i, LC_GLOBAL_LOCALE)) << i;
+ }
+ }
+}
+
+TEST(ctype, isdigit) {
+ for (int i = kMin; i < kMax; ++i) {
+ if (i >= '0' && i <= '9') {
+ EXPECT_TRUE(isdigit(i)) << i;
+ } else {
+ EXPECT_FALSE(isdigit(i)) << i;
+ }
+ }
+}
+
+TEST(ctype, isdigit_l) {
+ for (int i = kMin; i < kMax; ++i) {
+ if (i >= '0' && i <= '9') {
+ EXPECT_TRUE(isdigit_l(i, LC_GLOBAL_LOCALE)) << i;
+ } else {
+ EXPECT_FALSE(isdigit_l(i, LC_GLOBAL_LOCALE)) << i;
+ }
+ }
+}
+
+TEST(ctype, isgraph) {
+ for (int i = kMin; i < kMax; ++i) {
+ if (i >= '!' && i <= '~') {
+ EXPECT_TRUE(isgraph(i)) << i;
+ } else {
+ EXPECT_FALSE(isgraph(i)) << i;
+ }
+ }
+}
+
+TEST(ctype, isgraph_l) {
+ for (int i = kMin; i < kMax; ++i) {
+ if (i >= '!' && i <= '~') {
+ EXPECT_TRUE(isgraph_l(i, LC_GLOBAL_LOCALE)) << i;
+ } else {
+ EXPECT_FALSE(isgraph_l(i, LC_GLOBAL_LOCALE)) << i;
+ }
+ }
+}
+
+TEST(ctype, islower) {
+ for (int i = kMin; i < kMax; ++i) {
+ if (i >= 'a' && i <= 'z') {
+ EXPECT_TRUE(islower(i)) << i;
+ } else {
+ EXPECT_FALSE(islower(i)) << i;
+ }
+ }
+}
+
+TEST(ctype, islower_l) {
+ for (int i = kMin; i < kMax; ++i) {
+ if (i >= 'a' && i <= 'z') {
+ EXPECT_TRUE(islower_l(i, LC_GLOBAL_LOCALE)) << i;
+ } else {
+ EXPECT_FALSE(islower_l(i, LC_GLOBAL_LOCALE)) << i;
+ }
+ }
+}
+
+TEST(ctype, isprint) {
+ for (int i = kMin; i < kMax; ++i) {
+ if (i >= ' ' && i <= '~') {
+ EXPECT_TRUE(isprint(i)) << i;
+ } else {
+ EXPECT_FALSE(isprint(i)) << i;
+ }
+ }
+}
+
+TEST(ctype, isprint_l) {
+ for (int i = kMin; i < kMax; ++i) {
+ if (i >= ' ' && i <= '~') {
+ EXPECT_TRUE(isprint_l(i, LC_GLOBAL_LOCALE)) << i;
+ } else {
+ EXPECT_FALSE(isprint_l(i, LC_GLOBAL_LOCALE)) << i;
+ }
+ }
+}
+
+TEST(ctype, ispunct) {
+ for (int i = kMin; i < kMax; ++i) {
+ if ((i >= '!' && i <= '/') ||
+ (i >= ':' && i <= '@') ||
+ (i >= '[' && i <= '`') ||
+ (i >= '{' && i <= '~')) {
+ EXPECT_TRUE(ispunct(i)) << i;
+ } else {
+ EXPECT_FALSE(ispunct(i)) << i;
+ }
+ }
+}
+
+TEST(ctype, ispunct_l) {
+ for (int i = kMin; i < kMax; ++i) {
+ if ((i >= '!' && i <= '/') ||
+ (i >= ':' && i <= '@') ||
+ (i >= '[' && i <= '`') ||
+ (i >= '{' && i <= '~')) {
+ EXPECT_TRUE(ispunct_l(i, LC_GLOBAL_LOCALE)) << i;
+ } else {
+ EXPECT_FALSE(ispunct_l(i, LC_GLOBAL_LOCALE)) << i;
+ }
+ }
+}
+
+TEST(ctype, isspace) {
+ for (int i = kMin; i < kMax; ++i) {
+ if ((i >= '\t' && i <= '\r') || i == ' ') {
+ EXPECT_TRUE(isspace(i)) << i;
+ } else {
+ EXPECT_FALSE(isspace(i)) << i;
+ }
+ }
+}
+
+TEST(ctype, isspace_l) {
+ for (int i = kMin; i < kMax; ++i) {
+ if ((i >= '\t' && i <= '\r') || i == ' ') {
+ EXPECT_TRUE(isspace_l(i, LC_GLOBAL_LOCALE)) << i;
+ } else {
+ EXPECT_FALSE(isspace_l(i, LC_GLOBAL_LOCALE)) << i;
+ }
+ }
+}
+
+TEST(ctype, isupper) {
+ for (int i = kMin; i < kMax; ++i) {
+ if (i >= 'A' && i <= 'Z') {
+ EXPECT_TRUE(isupper(i)) << i;
+ } else {
+ EXPECT_FALSE(isupper(i)) << i;
+ }
+ }
+}
+
+TEST(ctype, isupper_l) {
+ for (int i = kMin; i < kMax; ++i) {
+ if (i >= 'A' && i <= 'Z') {
+ EXPECT_TRUE(isupper_l(i, LC_GLOBAL_LOCALE)) << i;
+ } else {
+ EXPECT_FALSE(isupper_l(i, LC_GLOBAL_LOCALE)) << i;
+ }
+ }
+}
+
+TEST(ctype, isxdigit) {
+ for (int i = kMin; i < kMax; ++i) {
+ if ((i >= '0' && i <= '9') ||
+ (i >= 'A' && i <= 'F') ||
+ (i >= 'a' && i <= 'f')) {
+ EXPECT_TRUE(isxdigit(i)) << i;
+ } else {
+ EXPECT_FALSE(isxdigit(i)) << i;
+ }
+ }
+}
+
+TEST(ctype, isxdigit_l) {
+ for (int i = kMin; i < kMax; ++i) {
+ if ((i >= '0' && i <= '9') ||
+ (i >= 'A' && i <= 'F') ||
+ (i >= 'a' && i <= 'f')) {
+ EXPECT_TRUE(isxdigit_l(i, LC_GLOBAL_LOCALE)) << i;
+ } else {
+ EXPECT_FALSE(isxdigit_l(i, LC_GLOBAL_LOCALE)) << i;
+ }
+ }
+}
+
+TEST(ctype, toascii) {
+ EXPECT_EQ('a', toascii('a'));
+ EXPECT_EQ('a', toascii(0x80 | 'a'));
+}
+
+TEST(ctype, tolower) {
+ EXPECT_EQ('!', tolower('!'));
+ EXPECT_EQ('a', tolower('a'));
+ EXPECT_EQ('a', tolower('A'));
+}
+
+TEST(ctype, tolower_l) {
+ EXPECT_EQ('!', tolower_l('!', LC_GLOBAL_LOCALE));
+ EXPECT_EQ('a', tolower_l('a', LC_GLOBAL_LOCALE));
+ EXPECT_EQ('a', tolower_l('A', LC_GLOBAL_LOCALE));
+}
+
+TEST(ctype, _tolower) {
+ // _tolower may mangle characters for which isupper is false.
+ EXPECT_EQ('a', _tolower('A'));
+}
+
+TEST(ctype, toupper) {
+ EXPECT_EQ('!', toupper('!'));
+ EXPECT_EQ('A', toupper('a'));
+ EXPECT_EQ('A', toupper('A'));
+}
+
+TEST(ctype, toupper_l) {
+ EXPECT_EQ('!', toupper_l('!', LC_GLOBAL_LOCALE));
+ EXPECT_EQ('A', toupper_l('a', LC_GLOBAL_LOCALE));
+ EXPECT_EQ('A', toupper_l('A', LC_GLOBAL_LOCALE));
+}
+
+TEST(ctype, _toupper) {
+ // _toupper may mangle characters for which islower is false.
+ EXPECT_EQ('A', _toupper('a'));
+}
diff --git a/tests/tst-wctype.cc b/tests/tst-wctype.cc
new file mode 100644
index 00000000..85a46aa4
--- /dev/null
+++ b/tests/tst-wctype.cc
@@ -0,0 +1,247 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <wctype.h>
+
+#include <dlfcn.h>
+
+#include <gtest/gtest.h>
+
+#include "utils.h"
+
+class UtfLocale {
+ public:
+ UtfLocale() : l(newlocale(LC_ALL, "C.UTF-8", nullptr)) {}
+ ~UtfLocale() { freelocale(l); }
+ locale_t l;
+};
+
+static void TestIsWideFn(int fn(wint_t),
+ int fn_l(wint_t, locale_t),
+ const wchar_t* trues,
+ const wchar_t* falses) {
+ UtfLocale l;
+ for (const wchar_t* p = trues; *p; ++p) {
+ if (!have_dl() && *p > 0x7f) {
+ GTEST_LOG_(INFO) << "skipping unicode test " << *p;
+ continue;
+ }
+ EXPECT_TRUE(fn(*p)) << *p;
+ EXPECT_TRUE(fn_l(*p, l.l)) << *p;
+ }
+ for (const wchar_t* p = falses; *p; ++p) {
+ if (!have_dl() && *p > 0x7f) {
+ GTEST_LOG_(INFO) << "skipping unicode test " << *p;
+ continue;
+ }
+ EXPECT_FALSE(fn(*p)) << *p;
+ EXPECT_FALSE(fn_l(*p, l.l)) << *p;
+ }
+}
+
+TEST(wctype, iswalnum) {
+ TestIsWideFn(iswalnum, iswalnum_l, L"1aAÇçΔδ", L"! \b");
+}
+
+TEST(wctype, iswalpha) {
+ TestIsWideFn(iswalpha, iswalpha_l, L"aAÇçΔδ", L"1! \b");
+}
+
+TEST(wctype, iswblank) {
+ TestIsWideFn(iswblank, iswblank_l, L" \t", L"1aA!\bÇçΔδ");
+}
+
+TEST(wctype, iswcntrl) {
+ TestIsWideFn(iswcntrl, iswcntrl_l, L"\b\u009f", L"1aA! ÇçΔδ");
+}
+
+TEST(wctype, iswdigit) {
+ TestIsWideFn(iswdigit, iswdigit_l, L"1", L"aA! \bÇçΔδ");
+}
+
+TEST(wctype, iswgraph) {
+ TestIsWideFn(iswgraph, iswgraph_l, L"1aA!ÇçΔδ", L" \b");
+}
+
+TEST(wctype, iswlower) {
+ TestIsWideFn(iswlower, iswlower_l, L"açδ", L"1A! \bÇΔ");
+}
+
+TEST(wctype, iswprint) {
+ TestIsWideFn(iswprint, iswprint_l, L"1aA! ÇçΔδ", L"\b");
+}
+
+TEST(wctype, iswpunct) {
+ TestIsWideFn(iswpunct, iswpunct_l, L"!", L"1aA \bÇçΔδ");
+}
+
+TEST(wctype, iswspace) {
+ TestIsWideFn(iswspace, iswspace_l, L" \f\t", L"1aA!\bÇçΔδ");
+}
+
+TEST(wctype, iswupper) {
+ TestIsWideFn(iswupper, iswupper_l, L"AÇΔ", L"1a! \bçδ");
+}
+
+TEST(wctype, iswxdigit) {
+ TestIsWideFn(iswxdigit, iswxdigit_l, L"01aA", L"xg! \b");
+}
+
+TEST(wctype, towlower) {
+ EXPECT_EQ(WEOF, towlower(WEOF));
+ EXPECT_EQ(wint_t('!'), towlower(L'!'));
+ EXPECT_EQ(wint_t('a'), towlower(L'a'));
+ EXPECT_EQ(wint_t('a'), towlower(L'A'));
+ if (have_dl()) {
+ EXPECT_EQ(wint_t(L'ç'), towlower(L'ç'));
+ EXPECT_EQ(wint_t(L'ç'), towlower(L'Ç'));
+ EXPECT_EQ(wint_t(L'δ'), towlower(L'δ'));
+ EXPECT_EQ(wint_t(L'δ'), towlower(L'Δ'));
+ } else {
+ GTEST_SKIP() << "icu not available";
+ }
+}
+
+TEST(wctype, towlower_l) {
+ UtfLocale l;
+ EXPECT_EQ(WEOF, towlower(WEOF));
+ EXPECT_EQ(wint_t('!'), towlower_l(L'!', l.l));
+ EXPECT_EQ(wint_t('a'), towlower_l(L'a', l.l));
+ EXPECT_EQ(wint_t('a'), towlower_l(L'A', l.l));
+ if (have_dl()) {
+ EXPECT_EQ(wint_t(L'ç'), towlower_l(L'ç', l.l));
+ EXPECT_EQ(wint_t(L'ç'), towlower_l(L'Ç', l.l));
+ EXPECT_EQ(wint_t(L'δ'), towlower_l(L'δ', l.l));
+ EXPECT_EQ(wint_t(L'δ'), towlower_l(L'Δ', l.l));
+ } else {
+ GTEST_SKIP() << "icu not available";
+ }
+}
+
+TEST(wctype, towupper) {
+ EXPECT_EQ(WEOF, towupper(WEOF));
+ EXPECT_EQ(wint_t('!'), towupper(L'!'));
+ EXPECT_EQ(wint_t('A'), towupper(L'a'));
+ EXPECT_EQ(wint_t('A'), towupper(L'A'));
+ if (have_dl()) {
+ EXPECT_EQ(wint_t(L'Ç'), towupper(L'ç'));
+ EXPECT_EQ(wint_t(L'Ç'), towupper(L'Ç'));
+ EXPECT_EQ(wint_t(L'Δ'), towupper(L'δ'));
+ EXPECT_EQ(wint_t(L'Δ'), towupper(L'Δ'));
+ } else {
+ GTEST_SKIP() << "icu not available";
+ }
+}
+
+TEST(wctype, towupper_l) {
+ UtfLocale l;
+ EXPECT_EQ(WEOF, towupper_l(WEOF, l.l));
+ EXPECT_EQ(wint_t('!'), towupper_l(L'!', l.l));
+ EXPECT_EQ(wint_t('A'), towupper_l(L'a', l.l));
+ EXPECT_EQ(wint_t('A'), towupper_l(L'A', l.l));
+ if (have_dl()) {
+ EXPECT_EQ(wint_t(L'Ç'), towupper_l(L'ç', l.l));
+ EXPECT_EQ(wint_t(L'Ç'), towupper_l(L'Ç', l.l));
+ EXPECT_EQ(wint_t(L'Δ'), towupper_l(L'δ', l.l));
+ EXPECT_EQ(wint_t(L'Δ'), towupper_l(L'Δ', l.l));
+ } else {
+ GTEST_SKIP() << "icu not available";
+ }
+}
+
+TEST(wctype, wctype) {
+ EXPECT_TRUE(wctype("alnum") != 0);
+ EXPECT_TRUE(wctype("alpha") != 0);
+ EXPECT_TRUE(wctype("blank") != 0);
+ EXPECT_TRUE(wctype("cntrl") != 0);
+ EXPECT_TRUE(wctype("digit") != 0);
+ EXPECT_TRUE(wctype("graph") != 0);
+ EXPECT_TRUE(wctype("lower") != 0);
+ EXPECT_TRUE(wctype("print") != 0);
+ EXPECT_TRUE(wctype("punct") != 0);
+ EXPECT_TRUE(wctype("space") != 0);
+ EXPECT_TRUE(wctype("upper") != 0);
+ EXPECT_TRUE(wctype("xdigit") != 0);
+
+ EXPECT_TRUE(wctype("monkeys") == 0);
+}
+
+TEST(wctype, wctype_l) {
+ UtfLocale l;
+ EXPECT_TRUE(wctype_l("alnum", l.l) != 0);
+ EXPECT_TRUE(wctype_l("alpha", l.l) != 0);
+ EXPECT_TRUE(wctype_l("blank", l.l) != 0);
+ EXPECT_TRUE(wctype_l("cntrl", l.l) != 0);
+ EXPECT_TRUE(wctype_l("digit", l.l) != 0);
+ EXPECT_TRUE(wctype_l("graph", l.l) != 0);
+ EXPECT_TRUE(wctype_l("lower", l.l) != 0);
+ EXPECT_TRUE(wctype_l("print", l.l) != 0);
+ EXPECT_TRUE(wctype_l("punct", l.l) != 0);
+ EXPECT_TRUE(wctype_l("space", l.l) != 0);
+ EXPECT_TRUE(wctype_l("upper", l.l) != 0);
+ EXPECT_TRUE(wctype_l("xdigit", l.l) != 0);
+
+ EXPECT_TRUE(wctype_l("monkeys", l.l) == 0);
+}
+
+TEST(wctype, iswctype) {
+ EXPECT_TRUE(iswctype(L'a', wctype("alnum")));
+ EXPECT_TRUE(iswctype(L'1', wctype("alnum")));
+ EXPECT_FALSE(iswctype(L' ', wctype("alnum")));
+
+ EXPECT_EQ(0, iswctype(WEOF, wctype("alnum")));
+}
+
+TEST(wctype, iswctype_l) {
+ UtfLocale l;
+ EXPECT_TRUE(iswctype_l(L'a', wctype_l("alnum", l.l), l.l));
+ EXPECT_TRUE(iswctype_l(L'1', wctype_l("alnum", l.l), l.l));
+ EXPECT_FALSE(iswctype_l(L' ', wctype_l("alnum", l.l), l.l));
+
+ EXPECT_EQ(0, iswctype_l(WEOF, wctype_l("alnum", l.l), l.l));
+}
+
+TEST(wctype, towctrans) {
+ EXPECT_TRUE(wctrans("tolower") != nullptr);
+ EXPECT_TRUE(wctrans("toupper") != nullptr);
+
+ EXPECT_TRUE(wctrans("monkeys") == nullptr);
+}
+
+TEST(wctype, towctrans_l) {
+ UtfLocale l;
+ EXPECT_TRUE(wctrans_l("tolower", l.l) != nullptr);
+ EXPECT_TRUE(wctrans_l("toupper", l.l) != nullptr);
+
+ EXPECT_TRUE(wctrans_l("monkeys", l.l) == nullptr);
+}
+
+TEST(wctype, wctrans) {
+ EXPECT_EQ(wint_t('a'), towctrans(L'A', wctrans("tolower")));
+ EXPECT_EQ(WEOF, towctrans(WEOF, wctrans("tolower")));
+
+ EXPECT_EQ(wint_t('A'), towctrans(L'a', wctrans("toupper")));
+ EXPECT_EQ(WEOF, towctrans(WEOF, wctrans("toupper")));
+}
+
+TEST(wctype, wctrans_l) {
+ UtfLocale l;
+ EXPECT_EQ(wint_t('a'), towctrans_l(L'A', wctrans_l("tolower", l.l), l.l));
+ EXPECT_EQ(WEOF, towctrans_l(WEOF, wctrans_l("tolower", l.l), l.l));
+
+ EXPECT_EQ(wint_t('A'), towctrans_l(L'a', wctrans_l("toupper", l.l), l.l));
+ EXPECT_EQ(WEOF, towctrans_l(WEOF, wctrans_l("toupper", l.l), l.l));
+}
--
2.25.1

Waldemar Kozaczuk

unread,
Aug 15, 2020, 12:21:40 AM8/15/20
to osv...@googlegroups.com, Waldemar Kozaczuk
Signed-off-by: Waldemar Kozaczuk <jwkoz...@gmail.com>
---
modules/tests/Makefile | 2 +-
tests/tst-ctype.cc | 123 ++++++++++++++++++++++++-----------------
tests/tst-string.cc | 61 ++++++++++++++++++++
tests/tst-wctype.cc | 38 +++++++++++--
4 files changed, 166 insertions(+), 58 deletions(-)
create mode 100644 tests/tst-string.cc

diff --git a/modules/tests/Makefile b/modules/tests/Makefile
index c984cb65..78f215e6 100644
--- a/modules/tests/Makefile
+++ b/modules/tests/Makefile
@@ -246,7 +246,7 @@ common-boost-tests := tst-vfs.so tst-libc-locking.so misc-fs-stress.so \
tst-bsd-tcp1-zsndrcv.so tst-async.so tst-rcu-list.so tst-tcp-listen.so \
tst-poll.so tst-bitset-iter.so tst-timer-set.so tst-clock.so \
tst-rcu-hashtable.so tst-unordered-ring-mpsc.so \
- tst-seek.so
+ tst-seek.so tst-ctype.so tst-wctype.so tst-string.so

boost-tests := $(common-boost-tests)

diff --git a/tests/tst-ctype.cc b/tests/tst-ctype.cc
index 826d39a9..3f258aef 100644
--- a/tests/tst-ctype.cc
+++ b/tests/tst-ctype.cc
@@ -14,10 +14,31 @@
* limitations under the License.
*/

-#include <gtest/gtest.h>
+/*
+ * Copyright (C) 2020 Waldemar Kozaczuk
+ *
+ * This work is open source software, licensed under the terms of the
+ * BSD license as described in the LICENSE file in the top-level directory.
+ */
+
+// This file is a verbatim copy of tests/ctype_test.cpp from the bionic project
+// (https://android.googlesource.com/platform/bionic as of commit: 9c6d60d073db079a87fbeb5de3e72ac12838a480)
+// PLUS some minor tweaks (mostly macros) that adapt it to run with boost unit framework
+// instead of Google's test framework
+
+//#include <gtest/gtest.h>
+#define BOOST_TEST_MODULE tst-ctype
+
+#include <boost/test/unit_test.hpp>
+namespace utf = boost::unit_test;

#include <ctype.h>

+#define TEST(MODULE_NAME,TEST_NAME) BOOST_AUTO_TEST_CASE(MODULE_NAME##TEST_NAME)
+#define EXPECT_TRUE(EXP) BOOST_REQUIRE_MESSAGE(EXP, "Failed for " << i)
+#define EXPECT_FALSE(EXP) BOOST_REQUIRE_MESSAGE(!(EXP), "Failed for " << i)
+#define EXPECT_EQ(EXP1,EXP2) BOOST_CHECK_EQUAL(EXP1,EXP2)
+
// We test from -1 (EOF) to 0xff, because that's the range for which behavior
// is actually defined. (It's explicitly undefined below or above that.) Most
// of our routines are no longer table-based and behave correctly for the
@@ -31,9 +52,9 @@ TEST(ctype, isalnum) {
if ((i >= '0' && i <= '9') ||
(i >= 'A' && i <= 'Z') ||
(i >= 'a' && i <= 'z')) {
- EXPECT_TRUE(isalnum(i)) << i;
+ EXPECT_TRUE(isalnum(i));
} else {
- EXPECT_FALSE(isalnum(i)) << i;
+ EXPECT_FALSE(isalnum(i));
}
}
}
@@ -43,9 +64,9 @@ TEST(ctype, isalnum_l) {
if ((i >= '0' && i <= '9') ||
(i >= 'A' && i <= 'Z') ||
(i >= 'a' && i <= 'z')) {
- EXPECT_TRUE(isalnum_l(i, LC_GLOBAL_LOCALE)) << i;
+ EXPECT_TRUE(isalnum_l(i, LC_GLOBAL_LOCALE));
} else {
- EXPECT_FALSE(isalnum_l(i, LC_GLOBAL_LOCALE)) << i;
+ EXPECT_FALSE(isalnum_l(i, LC_GLOBAL_LOCALE));
}
}
}
@@ -54,9 +75,9 @@ TEST(ctype, isalpha) {
for (int i = kMin; i < kMax; ++i) {
if ((i >= 'A' && i <= 'Z') ||
(i >= 'a' && i <= 'z')) {
- EXPECT_TRUE(isalpha(i)) << i;
+ EXPECT_TRUE(isalpha(i));
} else {
- EXPECT_FALSE(isalpha(i)) << i;
+ EXPECT_FALSE(isalpha(i));
}
}
}
@@ -65,9 +86,9 @@ TEST(ctype, isalpha_l) {
for (int i = kMin; i < kMax; ++i) {
if ((i >= 'A' && i <= 'Z') ||
(i >= 'a' && i <= 'z')) {
- EXPECT_TRUE(isalpha_l(i, LC_GLOBAL_LOCALE)) << i;
+ EXPECT_TRUE(isalpha_l(i, LC_GLOBAL_LOCALE));
} else {
- EXPECT_FALSE(isalpha_l(i, LC_GLOBAL_LOCALE)) << i;
+ EXPECT_FALSE(isalpha_l(i, LC_GLOBAL_LOCALE));
}
}
}
@@ -75,9 +96,9 @@ TEST(ctype, isalpha_l) {
TEST(ctype, isascii) {
for (int i = kMin; i < kMax; ++i) {
if (i >= 0 && i <= 0x7f) {
- EXPECT_TRUE(isascii(i)) << i;
+ EXPECT_TRUE(isascii(i));
} else {
- EXPECT_FALSE(isascii(i)) << i;
+ EXPECT_FALSE(isascii(i));
}
}
}
@@ -85,9 +106,9 @@ TEST(ctype, isascii) {
TEST(ctype, isblank) {
for (int i = kMin; i < kMax; ++i) {
if (i == '\t' || i == ' ') {
- EXPECT_TRUE(isblank(i)) << i;
+ EXPECT_TRUE(isblank(i));
} else {
- EXPECT_FALSE(isblank(i)) << i;
+ EXPECT_FALSE(isblank(i));
}
}
}
@@ -95,9 +116,9 @@ TEST(ctype, isblank) {
TEST(ctype, isblank_l) {
for (int i = kMin; i < kMax; ++i) {
if (i == '\t' || i == ' ') {
- EXPECT_TRUE(isblank_l(i, LC_GLOBAL_LOCALE)) << i;
+ EXPECT_TRUE(isblank_l(i, LC_GLOBAL_LOCALE));
} else {
- EXPECT_FALSE(isblank_l(i, LC_GLOBAL_LOCALE)) << i;
+ EXPECT_FALSE(isblank_l(i, LC_GLOBAL_LOCALE));
}
}
}
@@ -105,9 +126,9 @@ TEST(ctype, isblank_l) {
TEST(ctype, iscntrl) {
for (int i = kMin; i < kMax; ++i) {
if ((i >= 0 && i < ' ') || i == 0x7f) {
- EXPECT_TRUE(iscntrl(i)) << i;
+ EXPECT_TRUE(iscntrl(i));
} else {
- EXPECT_FALSE(iscntrl(i)) << i;
+ EXPECT_FALSE(iscntrl(i));
}
}
}
@@ -115,9 +136,9 @@ TEST(ctype, iscntrl) {
TEST(ctype, iscntrl_l) {
for (int i = kMin; i < kMax; ++i) {
if ((i >= 0 && i < ' ') || i == 0x7f) {
- EXPECT_TRUE(iscntrl_l(i, LC_GLOBAL_LOCALE)) << i;
+ EXPECT_TRUE(iscntrl_l(i, LC_GLOBAL_LOCALE));
} else {
- EXPECT_FALSE(iscntrl_l(i, LC_GLOBAL_LOCALE)) << i;
+ EXPECT_FALSE(iscntrl_l(i, LC_GLOBAL_LOCALE));
}
}
}
@@ -125,9 +146,9 @@ TEST(ctype, iscntrl_l) {
TEST(ctype, isdigit) {
for (int i = kMin; i < kMax; ++i) {
if (i >= '0' && i <= '9') {
- EXPECT_TRUE(isdigit(i)) << i;
+ EXPECT_TRUE(isdigit(i));
} else {
- EXPECT_FALSE(isdigit(i)) << i;
+ EXPECT_FALSE(isdigit(i));
}
}
}
@@ -135,9 +156,9 @@ TEST(ctype, isdigit) {
TEST(ctype, isdigit_l) {
for (int i = kMin; i < kMax; ++i) {
if (i >= '0' && i <= '9') {
- EXPECT_TRUE(isdigit_l(i, LC_GLOBAL_LOCALE)) << i;
+ EXPECT_TRUE(isdigit_l(i, LC_GLOBAL_LOCALE));
} else {
- EXPECT_FALSE(isdigit_l(i, LC_GLOBAL_LOCALE)) << i;
+ EXPECT_FALSE(isdigit_l(i, LC_GLOBAL_LOCALE));
}
}
}
@@ -145,9 +166,9 @@ TEST(ctype, isdigit_l) {
TEST(ctype, isgraph) {
for (int i = kMin; i < kMax; ++i) {
if (i >= '!' && i <= '~') {
- EXPECT_TRUE(isgraph(i)) << i;
+ EXPECT_TRUE(isgraph(i));
} else {
- EXPECT_FALSE(isgraph(i)) << i;
+ EXPECT_FALSE(isgraph(i));
}
}
}
@@ -155,9 +176,9 @@ TEST(ctype, isgraph) {
TEST(ctype, isgraph_l) {
for (int i = kMin; i < kMax; ++i) {
if (i >= '!' && i <= '~') {
- EXPECT_TRUE(isgraph_l(i, LC_GLOBAL_LOCALE)) << i;
+ EXPECT_TRUE(isgraph_l(i, LC_GLOBAL_LOCALE));
} else {
- EXPECT_FALSE(isgraph_l(i, LC_GLOBAL_LOCALE)) << i;
+ EXPECT_FALSE(isgraph_l(i, LC_GLOBAL_LOCALE));
}
}
}
@@ -165,9 +186,9 @@ TEST(ctype, isgraph_l) {
TEST(ctype, islower) {
for (int i = kMin; i < kMax; ++i) {
if (i >= 'a' && i <= 'z') {
- EXPECT_TRUE(islower(i)) << i;
+ EXPECT_TRUE(islower(i));
} else {
- EXPECT_FALSE(islower(i)) << i;
+ EXPECT_FALSE(islower(i));
}
}
}
@@ -175,9 +196,9 @@ TEST(ctype, islower) {
TEST(ctype, islower_l) {
for (int i = kMin; i < kMax; ++i) {
if (i >= 'a' && i <= 'z') {
- EXPECT_TRUE(islower_l(i, LC_GLOBAL_LOCALE)) << i;
+ EXPECT_TRUE(islower_l(i, LC_GLOBAL_LOCALE));
} else {
- EXPECT_FALSE(islower_l(i, LC_GLOBAL_LOCALE)) << i;
+ EXPECT_FALSE(islower_l(i, LC_GLOBAL_LOCALE));
}
}
}
@@ -185,9 +206,9 @@ TEST(ctype, islower_l) {
TEST(ctype, isprint) {
for (int i = kMin; i < kMax; ++i) {
if (i >= ' ' && i <= '~') {
- EXPECT_TRUE(isprint(i)) << i;
+ EXPECT_TRUE(isprint(i));
} else {
- EXPECT_FALSE(isprint(i)) << i;
+ EXPECT_FALSE(isprint(i));
}
}
}
@@ -195,9 +216,9 @@ TEST(ctype, isprint) {
TEST(ctype, isprint_l) {
for (int i = kMin; i < kMax; ++i) {
if (i >= ' ' && i <= '~') {
- EXPECT_TRUE(isprint_l(i, LC_GLOBAL_LOCALE)) << i;
+ EXPECT_TRUE(isprint_l(i, LC_GLOBAL_LOCALE));
} else {
- EXPECT_FALSE(isprint_l(i, LC_GLOBAL_LOCALE)) << i;
+ EXPECT_FALSE(isprint_l(i, LC_GLOBAL_LOCALE));
}
}
}
@@ -208,9 +229,9 @@ TEST(ctype, ispunct) {
(i >= ':' && i <= '@') ||
(i >= '[' && i <= '`') ||
(i >= '{' && i <= '~')) {
- EXPECT_TRUE(ispunct(i)) << i;
+ EXPECT_TRUE(ispunct(i));
} else {
- EXPECT_FALSE(ispunct(i)) << i;
+ EXPECT_FALSE(ispunct(i));
}
}
}
@@ -221,9 +242,9 @@ TEST(ctype, ispunct_l) {
(i >= ':' && i <= '@') ||
(i >= '[' && i <= '`') ||
(i >= '{' && i <= '~')) {
- EXPECT_TRUE(ispunct_l(i, LC_GLOBAL_LOCALE)) << i;
+ EXPECT_TRUE(ispunct_l(i, LC_GLOBAL_LOCALE));
} else {
- EXPECT_FALSE(ispunct_l(i, LC_GLOBAL_LOCALE)) << i;
+ EXPECT_FALSE(ispunct_l(i, LC_GLOBAL_LOCALE));
}
}
}
@@ -231,9 +252,9 @@ TEST(ctype, ispunct_l) {
TEST(ctype, isspace) {
for (int i = kMin; i < kMax; ++i) {
if ((i >= '\t' && i <= '\r') || i == ' ') {
- EXPECT_TRUE(isspace(i)) << i;
+ EXPECT_TRUE(isspace(i));
} else {
- EXPECT_FALSE(isspace(i)) << i;
+ EXPECT_FALSE(isspace(i));
}
}
}
@@ -241,9 +262,9 @@ TEST(ctype, isspace) {
TEST(ctype, isspace_l) {
for (int i = kMin; i < kMax; ++i) {
if ((i >= '\t' && i <= '\r') || i == ' ') {
- EXPECT_TRUE(isspace_l(i, LC_GLOBAL_LOCALE)) << i;
+ EXPECT_TRUE(isspace_l(i, LC_GLOBAL_LOCALE));
} else {
- EXPECT_FALSE(isspace_l(i, LC_GLOBAL_LOCALE)) << i;
+ EXPECT_FALSE(isspace_l(i, LC_GLOBAL_LOCALE));
}
}
}
@@ -251,9 +272,9 @@ TEST(ctype, isspace_l) {
TEST(ctype, isupper) {
for (int i = kMin; i < kMax; ++i) {
if (i >= 'A' && i <= 'Z') {
- EXPECT_TRUE(isupper(i)) << i;
+ EXPECT_TRUE(isupper(i));
} else {
- EXPECT_FALSE(isupper(i)) << i;
+ EXPECT_FALSE(isupper(i));
}
}
}
@@ -261,9 +282,9 @@ TEST(ctype, isupper) {
TEST(ctype, isupper_l) {
for (int i = kMin; i < kMax; ++i) {
if (i >= 'A' && i <= 'Z') {
- EXPECT_TRUE(isupper_l(i, LC_GLOBAL_LOCALE)) << i;
+ EXPECT_TRUE(isupper_l(i, LC_GLOBAL_LOCALE));
} else {
- EXPECT_FALSE(isupper_l(i, LC_GLOBAL_LOCALE)) << i;
+ EXPECT_FALSE(isupper_l(i, LC_GLOBAL_LOCALE));
}
}
}
@@ -273,9 +294,9 @@ TEST(ctype, isxdigit) {
if ((i >= '0' && i <= '9') ||
(i >= 'A' && i <= 'F') ||
(i >= 'a' && i <= 'f')) {
- EXPECT_TRUE(isxdigit(i)) << i;
+ EXPECT_TRUE(isxdigit(i));
} else {
- EXPECT_FALSE(isxdigit(i)) << i;
+ EXPECT_FALSE(isxdigit(i));
}
}
}
@@ -285,9 +306,9 @@ TEST(ctype, isxdigit_l) {
if ((i >= '0' && i <= '9') ||
(i >= 'A' && i <= 'F') ||
(i >= 'a' && i <= 'f')) {
- EXPECT_TRUE(isxdigit_l(i, LC_GLOBAL_LOCALE)) << i;
+ EXPECT_TRUE(isxdigit_l(i, LC_GLOBAL_LOCALE));
} else {
- EXPECT_FALSE(isxdigit_l(i, LC_GLOBAL_LOCALE)) << i;
+ EXPECT_FALSE(isxdigit_l(i, LC_GLOBAL_LOCALE));
}
}
}
diff --git a/tests/tst-string.cc b/tests/tst-string.cc
new file mode 100644
index 00000000..f6ce1990
--- /dev/null
+++ b/tests/tst-string.cc
@@ -0,0 +1,61 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/*
+ * Copyright (C) 2020 Waldemar Kozaczuk
+ *
+ * This work is open source software, licensed under the terms of the
+ * BSD license as described in the LICENSE file in the top-level directory.
+ */
+
+// This test is based on tests/string_test.cpp from the bionic project
+// (https://android.googlesource.com/platform/bionic as of commit: 9c6d60d073db079a87fbeb5de3e72ac12838a480)
+// PLUS some minor tweaks (mostly macros) that adapt it to run with boost unit framework
+// instead of Google's test framework
+
+#define BOOST_TEST_MODULE tst-string
+
+#include <boost/test/unit_test.hpp>
+namespace utf = boost::unit_test;
+
+#define TEST(MODULE_NAME,TEST_NAME) BOOST_AUTO_TEST_CASE(MODULE_NAME##TEST_NAME)
+#define ASSERT_TRUE(EXP) BOOST_REQUIRE(EXP)
+#define ASSERT_GT(EXP1,EXP2) BOOST_REQUIRE((EXP1)>(EXP2))
+
+TEST(STRING_TEST, strxfrm_smoke) {
+ locale_t l(newlocale(LC_ALL, "C.UTF-8", nullptr));
+ const char* src1 = "aab";
+ char dst1[16] = {};
+ ASSERT_GT(strxfrm(dst1, src1, sizeof(dst1)), 0U);
+ ASSERT_GT(strxfrm_l(dst1, src1, sizeof(dst1), l), 0U);
+ const char* src2 = "aac";
+ char dst2[16] = {};
+ ASSERT_GT(strxfrm(dst2, src2, sizeof(dst2)), 0U);
+ ASSERT_GT(strxfrm_l(dst2, src2, sizeof(dst2), l), 0U);
+ ASSERT_TRUE(strcmp(dst1, dst2) < 0);
+ freelocale(l);
+}
+
+TEST(STRING_TEST, strcoll_smoke) {
+ locale_t l(newlocale(LC_ALL, "C.UTF-8", nullptr));
+ ASSERT_TRUE(strcoll("aab", "aac") < 0);
+ ASSERT_TRUE(strcoll_l("aab", "aac", l) < 0);
+ ASSERT_TRUE(strcoll("aab", "aab") == 0);
+ ASSERT_TRUE(strcoll_l("aab", "aab", l) == 0);
+ ASSERT_TRUE(strcoll("aac", "aab") > 0);
+ ASSERT_TRUE(strcoll_l("aac", "aab", l) > 0);
+ freelocale(l);
+}
diff --git a/tests/tst-wctype.cc b/tests/tst-wctype.cc
index 85a46aa4..9e6fc066 100644
--- a/tests/tst-wctype.cc
+++ b/tests/tst-wctype.cc
@@ -14,13 +14,39 @@
* limitations under the License.
*/

+/*
+ * Copyright (C) 2020 Waldemar Kozaczuk
+ *
+ * This work is open source software, licensed under the terms of the
+ * BSD license as described in the LICENSE file in the top-level directory.
+ */
+
+// This file is a verbatim copy of tests/ctype_test.cpp from the bionic project
+// (https://android.googlesource.com/platform/bionic as of commit: 9c6d60d073db079a87fbeb5de3e72ac12838a480)
+// PLUS some minor tweaks (mostly macros) that adapt it to run with boost unit framework
+// instead of Google's test framework
+
#include <wctype.h>

#include <dlfcn.h>

-#include <gtest/gtest.h>
+//#include <gtest/gtest.h>
+#define BOOST_TEST_MODULE tst-wctype
+
+#include <boost/test/unit_test.hpp>
+namespace utf = boost::unit_test;
+
+//#include "utils.h"
+#define have_dl() (true)

-#include "utils.h"
+#define TEST(MODULE_NAME,TEST_NAME) BOOST_AUTO_TEST_CASE(MODULE_NAME##TEST_NAME)
+#define EXPECT_TRUE(EXP) BOOST_REQUIRE(EXP)
+#define EXPECT_FALSE(EXP) BOOST_REQUIRE(!(EXP))
+#define EXPECT_TRUE_P(EXP,P) BOOST_REQUIRE_MESSAGE(EXP, "Failed for " << P)
+#define EXPECT_FALSE_P(EXP,P) BOOST_REQUIRE_MESSAGE(!(EXP), "Failed for " << P)
+#define EXPECT_EQ(EXP1,EXP2) BOOST_CHECK_EQUAL(EXP1,EXP2)
+#define GTEST_LOG_(I) std::cout
+#define GTEST_SKIP() std::cout

class UtfLocale {
public:
@@ -39,16 +65,16 @@ static void TestIsWideFn(int fn(wint_t),
GTEST_LOG_(INFO) << "skipping unicode test " << *p;
continue;
}
- EXPECT_TRUE(fn(*p)) << *p;
- EXPECT_TRUE(fn_l(*p, l.l)) << *p;
+ EXPECT_TRUE_P(fn(*p), *p);
+ EXPECT_TRUE_P(fn_l(*p, l.l), *p);
}
for (const wchar_t* p = falses; *p; ++p) {
if (!have_dl() && *p > 0x7f) {
GTEST_LOG_(INFO) << "skipping unicode test " << *p;
continue;
}
- EXPECT_FALSE(fn(*p)) << *p;
- EXPECT_FALSE(fn_l(*p, l.l)) << *p;
+ EXPECT_FALSE_P(fn(*p), *p);
+ EXPECT_FALSE_P(fn_l(*p, l.l), *p);
}
}

--
2.25.1

Commit Bot

unread,
Aug 20, 2020, 12:18:52 AM8/20/20
to osv...@googlegroups.com, Waldemar Kozaczuk
From: Waldemar Kozaczuk <jwkoz...@gmail.com>
Committer: Waldemar Kozaczuk <jwkoz...@gmail.com>
Branch: master

tests: add verbatim copies of Bionic tests for w/ctype

Signed-off-by: Waldemar Kozaczuk <jwkoz...@gmail.com>

---
diff --git a/tests/tst-ctype.cc b/tests/tst-ctype.cc
--- a/tests/tst-ctype.cc
+++ b/tests/tst-ctype.cc
@@ -0,0 +1,332 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+}
diff --git a/tests/tst-wctype.cc b/tests/tst-wctype.cc
--- a/tests/tst-wctype.cc
+++ b/tests/tst-wctype.cc
@@ -0,0 +1,247 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+

Commit Bot

unread,
Aug 20, 2020, 12:18:53 AM8/20/20
to osv...@googlegroups.com, Waldemar Kozaczuk
From: Waldemar Kozaczuk <jwkoz...@gmail.com>
Committer: Waldemar Kozaczuk <jwkoz...@gmail.com>
Branch: master

tests: adapted w/ctype tests to work with boost unittest and added tst-string

Signed-off-by: Waldemar Kozaczuk <jwkoz...@gmail.com>

---
diff --git a/modules/tests/Makefile b/modules/tests/Makefile
--- a/modules/tests/Makefile
+++ b/modules/tests/Makefile
@@ -246,7 +246,7 @@ common-boost-tests := tst-vfs.so tst-libc-locking.so misc-fs-stress.so \
tst-bsd-tcp1-zsndrcv.so tst-async.so tst-rcu-list.so tst-tcp-listen.so \
tst-poll.so tst-bitset-iter.so tst-timer-set.so tst-clock.so \
tst-rcu-hashtable.so tst-unordered-ring-mpsc.so \
- tst-seek.so
+ tst-seek.so tst-ctype.so tst-wctype.so tst-string.so

boost-tests := $(common-boost-tests)

diff --git a/tests/tst-ctype.cc b/tests/tst-ctype.cc
--- a/tests/tst-ctype.cc
+++ b/tests/tst-ctype.cc
@@ -14,10 +14,31 @@
* limitations under the License.
*/

-#include <gtest/gtest.h>
+/*
+ * Copyright (C) 2020 Waldemar Kozaczuk
+ *
+ * This work is open source software, licensed under the terms of the
+ * BSD license as described in the LICENSE file in the top-level directory.
+ */
+
+// This file is a verbatim copy of tests/ctype_test.cpp from the bionic project
+// (https://android.googlesource.com/platform/bionic as of commit: 9c6d60d073db079a87fbeb5de3e72ac12838a480)
+// PLUS some minor tweaks (mostly macros) that adapt it to run with boost unit framework
+// instead of Google's test framework
+
+//#include <gtest/gtest.h>
+#define BOOST_TEST_MODULE tst-ctype
+
+#include <boost/test/unit_test.hpp>
+namespace utf = boost::unit_test;

#include <ctype.h>

+#define TEST(MODULE_NAME,TEST_NAME) BOOST_AUTO_TEST_CASE(MODULE_NAME##TEST_NAME)
+#define EXPECT_TRUE(EXP) BOOST_REQUIRE_MESSAGE(EXP, "Failed for " << i)
+#define EXPECT_FALSE(EXP) BOOST_REQUIRE_MESSAGE(!(EXP), "Failed for " << i)
+#define EXPECT_EQ(EXP1,EXP2) BOOST_CHECK_EQUAL(EXP1,EXP2)
+
// We test from -1 (EOF) to 0xff, because that's the range for which behavior
// is actually defined. (It's explicitly undefined below or above that.) Most
// of our routines are no longer table-based and behave correctly for the
@@ -31,9 +52,9 @@ TEST(ctype, isalnum) {
if ((i >= '0' && i <= '9') ||
(i >= 'A' && i <= 'Z') ||
(i >= 'a' && i <= 'z')) {
- EXPECT_TRUE(isalnum(i)) << i;
+ EXPECT_TRUE(isalnum(i));
} else {
- EXPECT_FALSE(isalnum(i)) << i;
+ EXPECT_FALSE(isalnum(i));
}
}
}
@@ -43,9 +64,9 @@ TEST(ctype, isalnum_l) {
if ((i >= '0' && i <= '9') ||
(i >= 'A' && i <= 'Z') ||
(i >= 'a' && i <= 'z')) {
- EXPECT_TRUE(isalnum_l(i, LC_GLOBAL_LOCALE)) << i;
+ EXPECT_TRUE(isalnum_l(i, LC_GLOBAL_LOCALE));
} else {
- EXPECT_FALSE(isalnum_l(i, LC_GLOBAL_LOCALE)) << i;
+ EXPECT_FALSE(isalnum_l(i, LC_GLOBAL_LOCALE));
}
}
}
@@ -54,9 +75,9 @@ TEST(ctype, isalpha) {
for (int i = kMin; i < kMax; ++i) {
if ((i >= 'A' && i <= 'Z') ||
(i >= 'a' && i <= 'z')) {
- EXPECT_TRUE(isalpha(i)) << i;
+ EXPECT_TRUE(isalpha(i));
} else {
- EXPECT_FALSE(isalpha(i)) << i;
+ EXPECT_FALSE(isalpha(i));
}
}
}
@@ -65,139 +86,139 @@ TEST(ctype, isalpha_l) {
for (int i = kMin; i < kMax; ++i) {
if ((i >= 'A' && i <= 'Z') ||
(i >= 'a' && i <= 'z')) {
- EXPECT_TRUE(isalpha_l(i, LC_GLOBAL_LOCALE)) << i;
+ EXPECT_TRUE(isalpha_l(i, LC_GLOBAL_LOCALE));
} else {
- EXPECT_FALSE(isalpha_l(i, LC_GLOBAL_LOCALE)) << i;
+ EXPECT_FALSE(isalpha_l(i, LC_GLOBAL_LOCALE));
}
}
}

TEST(ctype, isascii) {
for (int i = kMin; i < kMax; ++i) {
if (i >= 0 && i <= 0x7f) {
- EXPECT_TRUE(isascii(i)) << i;
+ EXPECT_TRUE(isascii(i));
} else {
- EXPECT_FALSE(isascii(i)) << i;
+ EXPECT_FALSE(isascii(i));
}
}
}

TEST(ctype, isblank) {
for (int i = kMin; i < kMax; ++i) {
if (i == '\t' || i == ' ') {
- EXPECT_TRUE(isblank(i)) << i;
+ EXPECT_TRUE(isblank(i));
} else {
- EXPECT_FALSE(isblank(i)) << i;
+ EXPECT_FALSE(isblank(i));
}
}
}

TEST(ctype, isblank_l) {
for (int i = kMin; i < kMax; ++i) {
if (i == '\t' || i == ' ') {
- EXPECT_TRUE(isblank_l(i, LC_GLOBAL_LOCALE)) << i;
+ EXPECT_TRUE(isblank_l(i, LC_GLOBAL_LOCALE));
} else {
- EXPECT_FALSE(isblank_l(i, LC_GLOBAL_LOCALE)) << i;
+ EXPECT_FALSE(isblank_l(i, LC_GLOBAL_LOCALE));
}
}
}

TEST(ctype, iscntrl) {
for (int i = kMin; i < kMax; ++i) {
if ((i >= 0 && i < ' ') || i == 0x7f) {
- EXPECT_TRUE(iscntrl(i)) << i;
+ EXPECT_TRUE(iscntrl(i));
} else {
- EXPECT_FALSE(iscntrl(i)) << i;
+ EXPECT_FALSE(iscntrl(i));
}
}
}

TEST(ctype, iscntrl_l) {
for (int i = kMin; i < kMax; ++i) {
if ((i >= 0 && i < ' ') || i == 0x7f) {
- EXPECT_TRUE(iscntrl_l(i, LC_GLOBAL_LOCALE)) << i;
+ EXPECT_TRUE(iscntrl_l(i, LC_GLOBAL_LOCALE));
} else {
- EXPECT_FALSE(iscntrl_l(i, LC_GLOBAL_LOCALE)) << i;
+ EXPECT_FALSE(iscntrl_l(i, LC_GLOBAL_LOCALE));
}
}
}

TEST(ctype, isdigit) {
for (int i = kMin; i < kMax; ++i) {
if (i >= '0' && i <= '9') {
- EXPECT_TRUE(isdigit(i)) << i;
+ EXPECT_TRUE(isdigit(i));
} else {
- EXPECT_FALSE(isdigit(i)) << i;
+ EXPECT_FALSE(isdigit(i));
}
}
}

TEST(ctype, isdigit_l) {
for (int i = kMin; i < kMax; ++i) {
if (i >= '0' && i <= '9') {
- EXPECT_TRUE(isdigit_l(i, LC_GLOBAL_LOCALE)) << i;
+ EXPECT_TRUE(isdigit_l(i, LC_GLOBAL_LOCALE));
} else {
- EXPECT_FALSE(isdigit_l(i, LC_GLOBAL_LOCALE)) << i;
+ EXPECT_FALSE(isdigit_l(i, LC_GLOBAL_LOCALE));
}
}
}

TEST(ctype, isgraph) {
for (int i = kMin; i < kMax; ++i) {
if (i >= '!' && i <= '~') {
- EXPECT_TRUE(isgraph(i)) << i;
+ EXPECT_TRUE(isgraph(i));
} else {
- EXPECT_FALSE(isgraph(i)) << i;
+ EXPECT_FALSE(isgraph(i));
}
}
}

TEST(ctype, isgraph_l) {
for (int i = kMin; i < kMax; ++i) {
if (i >= '!' && i <= '~') {
- EXPECT_TRUE(isgraph_l(i, LC_GLOBAL_LOCALE)) << i;
+ EXPECT_TRUE(isgraph_l(i, LC_GLOBAL_LOCALE));
} else {
- EXPECT_FALSE(isgraph_l(i, LC_GLOBAL_LOCALE)) << i;
+ EXPECT_FALSE(isgraph_l(i, LC_GLOBAL_LOCALE));
}
}
}

TEST(ctype, islower) {
for (int i = kMin; i < kMax; ++i) {
if (i >= 'a' && i <= 'z') {
- EXPECT_TRUE(islower(i)) << i;
+ EXPECT_TRUE(islower(i));
} else {
- EXPECT_FALSE(islower(i)) << i;
+ EXPECT_FALSE(islower(i));
}
}
}

TEST(ctype, islower_l) {
for (int i = kMin; i < kMax; ++i) {
if (i >= 'a' && i <= 'z') {
- EXPECT_TRUE(islower_l(i, LC_GLOBAL_LOCALE)) << i;
+ EXPECT_TRUE(islower_l(i, LC_GLOBAL_LOCALE));
} else {
- EXPECT_FALSE(islower_l(i, LC_GLOBAL_LOCALE)) << i;
+ EXPECT_FALSE(islower_l(i, LC_GLOBAL_LOCALE));
}
}
}

TEST(ctype, isprint) {
for (int i = kMin; i < kMax; ++i) {
if (i >= ' ' && i <= '~') {
- EXPECT_TRUE(isprint(i)) << i;
+ EXPECT_TRUE(isprint(i));
} else {
- EXPECT_FALSE(isprint(i)) << i;
+ EXPECT_FALSE(isprint(i));
}
}
}

TEST(ctype, isprint_l) {
for (int i = kMin; i < kMax; ++i) {
if (i >= ' ' && i <= '~') {
- EXPECT_TRUE(isprint_l(i, LC_GLOBAL_LOCALE)) << i;
+ EXPECT_TRUE(isprint_l(i, LC_GLOBAL_LOCALE));
} else {
- EXPECT_FALSE(isprint_l(i, LC_GLOBAL_LOCALE)) << i;
+ EXPECT_FALSE(isprint_l(i, LC_GLOBAL_LOCALE));
}
}
}
@@ -208,9 +229,9 @@ TEST(ctype, ispunct) {
(i >= ':' && i <= '@') ||
(i >= '[' && i <= '`') ||
(i >= '{' && i <= '~')) {
- EXPECT_TRUE(ispunct(i)) << i;
+ EXPECT_TRUE(ispunct(i));
} else {
- EXPECT_FALSE(ispunct(i)) << i;
+ EXPECT_FALSE(ispunct(i));
}
}
}
@@ -221,49 +242,49 @@ TEST(ctype, ispunct_l) {
(i >= ':' && i <= '@') ||
(i >= '[' && i <= '`') ||
(i >= '{' && i <= '~')) {
- EXPECT_TRUE(ispunct_l(i, LC_GLOBAL_LOCALE)) << i;
+ EXPECT_TRUE(ispunct_l(i, LC_GLOBAL_LOCALE));
} else {
- EXPECT_FALSE(ispunct_l(i, LC_GLOBAL_LOCALE)) << i;
+ EXPECT_FALSE(ispunct_l(i, LC_GLOBAL_LOCALE));
}
}
}

TEST(ctype, isspace) {
for (int i = kMin; i < kMax; ++i) {
if ((i >= '\t' && i <= '\r') || i == ' ') {
- EXPECT_TRUE(isspace(i)) << i;
+ EXPECT_TRUE(isspace(i));
} else {
- EXPECT_FALSE(isspace(i)) << i;
+ EXPECT_FALSE(isspace(i));
}
}
}

TEST(ctype, isspace_l) {
for (int i = kMin; i < kMax; ++i) {
if ((i >= '\t' && i <= '\r') || i == ' ') {
- EXPECT_TRUE(isspace_l(i, LC_GLOBAL_LOCALE)) << i;
+ EXPECT_TRUE(isspace_l(i, LC_GLOBAL_LOCALE));
} else {
- EXPECT_FALSE(isspace_l(i, LC_GLOBAL_LOCALE)) << i;
+ EXPECT_FALSE(isspace_l(i, LC_GLOBAL_LOCALE));
}
}
}

TEST(ctype, isupper) {
for (int i = kMin; i < kMax; ++i) {
if (i >= 'A' && i <= 'Z') {
- EXPECT_TRUE(isupper(i)) << i;
+ EXPECT_TRUE(isupper(i));
} else {
- EXPECT_FALSE(isupper(i)) << i;
+ EXPECT_FALSE(isupper(i));
}
}
}

TEST(ctype, isupper_l) {
for (int i = kMin; i < kMax; ++i) {
if (i >= 'A' && i <= 'Z') {
- EXPECT_TRUE(isupper_l(i, LC_GLOBAL_LOCALE)) << i;
+ EXPECT_TRUE(isupper_l(i, LC_GLOBAL_LOCALE));
} else {
- EXPECT_FALSE(isupper_l(i, LC_GLOBAL_LOCALE)) << i;
+ EXPECT_FALSE(isupper_l(i, LC_GLOBAL_LOCALE));
}
}
}
@@ -273,9 +294,9 @@ TEST(ctype, isxdigit) {
if ((i >= '0' && i <= '9') ||
(i >= 'A' && i <= 'F') ||
(i >= 'a' && i <= 'f')) {
- EXPECT_TRUE(isxdigit(i)) << i;
+ EXPECT_TRUE(isxdigit(i));
} else {
- EXPECT_FALSE(isxdigit(i)) << i;
+ EXPECT_FALSE(isxdigit(i));
}
}
}
@@ -285,9 +306,9 @@ TEST(ctype, isxdigit_l) {
if ((i >= '0' && i <= '9') ||
(i >= 'A' && i <= 'F') ||
(i >= 'a' && i <= 'f')) {
- EXPECT_TRUE(isxdigit_l(i, LC_GLOBAL_LOCALE)) << i;
+ EXPECT_TRUE(isxdigit_l(i, LC_GLOBAL_LOCALE));
} else {
- EXPECT_FALSE(isxdigit_l(i, LC_GLOBAL_LOCALE)) << i;
+ EXPECT_FALSE(isxdigit_l(i, LC_GLOBAL_LOCALE));
}
}
}
diff --git a/tests/tst-string.cc b/tests/tst-string.cc
--- a/tests/tst-string.cc
+++ b/tests/tst-string.cc
@@ -0,0 +1,61 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/*
+}
diff --git a/tests/tst-wctype.cc b/tests/tst-wctype.cc
--- a/tests/tst-wctype.cc
+++ b/tests/tst-wctype.cc
@@ -14,13 +14,39 @@
* limitations under the License.
*/

+/*
GTEST_LOG_(INFO) << "skipping unicode test " << *p;
continue;
}
- EXPECT_TRUE(fn(*p)) << *p;
- EXPECT_TRUE(fn_l(*p, l.l)) << *p;
+ EXPECT_TRUE_P(fn(*p), *p);
+ EXPECT_TRUE_P(fn_l(*p, l.l), *p);
}
for (const wchar_t* p = falses; *p; ++p) {
if (!have_dl() && *p > 0x7f) {
GTEST_LOG_(INFO) << "skipping unicode test " << *p;

Nadav Har'El

unread,
Aug 20, 2020, 3:27:05 AM8/20/20
to Waldemar Kozaczuk, Osv Dev
Good, I'm happier about such copies instead of trying to download a huge project from which we only want a single file.
But can you please sent a followup patch which uses Bionic's copyright statement, and license, instead of your own
copyright statement - or both if you wish?

--
You received this message because you are subscribed to the Google Groups "OSv Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to osv-dev+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/osv-dev/000000000000ec379405ad476a16%40google.com.

Waldek Kozaczuk

unread,
Aug 20, 2020, 12:58:10 PM8/20/20
to OSv Development
The 1st of the 2-patch series adds sources with original Bionic license - https://github.com/cloudius-systems/osv/blob/master/tests/tst-ctype.cc. And the second one is just a patch with changes to the original source files where I added my extra license statement which was maybe unnecessary as the changes were mostly trivial.

We also already have a license file under licenses - https://github.com/cloudius-systems/osv/blob/master/licenses/bionic.txt.

BTW I am planning to send more Bionic-originated unit tests around stdio, time, string and locale.
Reply all
Reply to author
Forward
0 new messages