diff options
author | Elliott Hughes <enh@google.com> | 2014-04-29 14:46:56 -0700 |
---|---|---|
committer | Elliott Hughes <enh@google.com> | 2014-04-29 14:53:11 -0700 |
commit | 3d7a0d9b08ecab054b2dff8332507644de3690b0 (patch) | |
tree | b6c4f27e3abdd6590a452c978048ae21d934da09 /tests | |
parent | 07bab525e24725aaacd71e7cc63dfc31d48ba8a7 (diff) | |
download | bionic-3d7a0d9b08ecab054b2dff8332507644de3690b0.zip bionic-3d7a0d9b08ecab054b2dff8332507644de3690b0.tar.gz bionic-3d7a0d9b08ecab054b2dff8332507644de3690b0.tar.bz2 |
Switch to the OpenBSD wcsto* functions.
This replaces a partial set of non-functional functions with a complete
set of functions, all of which actually work.
This requires us to implement mbsnrtowcs and wcsnrtombs which completes
the set of what we need for libc++.
The mbsnrtowcs is basically a copy & paste of wcsnrtombs, but I'm going
to go straight to looking at using the OpenBSD UTF-8 implementation rather
than keep polishing our home-grown turd.
(This patch also opportunistically switches us over to upstream btowc,
mbrlen, and wctob, since they're all trivially expressed in terms of
other functions.)
Change-Id: I0f81443840de0f1aa73b96f0b51988976793a323
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Android.mk | 2 | ||||
-rw-r--r-- | tests/unistd_test.cpp | 2 | ||||
-rw-r--r-- | tests/wchar_test.cpp | 54 |
3 files changed, 56 insertions, 2 deletions
diff --git a/tests/Android.mk b/tests/Android.mk index 0014af6..e7acc8b 100644 --- a/tests/Android.mk +++ b/tests/Android.mk @@ -38,6 +38,8 @@ test_cflags = \ -Werror \ -fno-builtin \ +test_cflags += -D__STDC_LIMIT_MACROS # For glibc. + libBionicStandardTests_src_files := \ buffer_tests.cpp \ ctype_test.cpp \ diff --git a/tests/unistd_test.cpp b/tests/unistd_test.cpp index f56b767..ce0beba 100644 --- a/tests/unistd_test.cpp +++ b/tests/unistd_test.cpp @@ -18,8 +18,6 @@ #include "ScopedSignalHandler.h" #include "TemporaryFile.h" -#define __STDC_LIMIT_MACROS // For glibc. - #include <errno.h> #include <fcntl.h> #include <stdint.h> diff --git a/tests/wchar_test.cpp b/tests/wchar_test.cpp index 3c38f1f..f6c2683 100644 --- a/tests/wchar_test.cpp +++ b/tests/wchar_test.cpp @@ -18,6 +18,7 @@ #include <errno.h> #include <limits.h> +#include <stdint.h> #include <wchar.h> TEST(wchar, sizeof_wchar_t) { @@ -212,3 +213,56 @@ TEST(wchar, mbrtowc) { ASSERT_EQ(0U, mbrtowc(NULL, NULL, 0, NULL)); } + +TEST(wchar, wcstod) { + ASSERT_DOUBLE_EQ(1.23, wcstod(L"1.23", NULL)); +} + +TEST(wchar, wcstof) { + ASSERT_FLOAT_EQ(1.23f, wcstof(L"1.23", NULL)); +} + +TEST(wchar, wcstol) { + ASSERT_EQ(123L, wcstol(L"123", NULL, 0)); +} + +TEST(wchar, wcstoll) { + ASSERT_EQ(123LL, wcstol(L"123", NULL, 0)); +} + +TEST(wchar, wcstold) { + ASSERT_DOUBLE_EQ(1.23L, wcstold(L"1.23", NULL)); +} + +TEST(wchar, wcstoul) { + ASSERT_EQ(123UL, wcstoul(L"123", NULL, 0)); +} + +TEST(wchar, wcstoull) { + ASSERT_EQ(123ULL, wcstoul(L"123", NULL, 0)); +} + +TEST(wchar, mbsnrtowcs) { + wchar_t dst[128]; + const char* s = "hello, world!"; + const char* src; + + memset(dst, 0, sizeof(dst)); + src = s; + ASSERT_EQ(0U, mbsnrtowcs(dst, &src, 0, 0, NULL)); + + memset(dst, 0, sizeof(dst)); + src = s; + ASSERT_EQ(2U, mbsnrtowcs(dst, &src, 2, 123, NULL)); // glibc chokes on SIZE_MAX here. + ASSERT_EQ(L'h', dst[0]); + ASSERT_EQ(L'e', dst[1]); + ASSERT_EQ(&s[2], src); + + memset(dst, 0, sizeof(dst)); + src = s; + ASSERT_EQ(3U, mbsnrtowcs(dst, &src, SIZE_MAX, 3, NULL)); + ASSERT_EQ(L'h', dst[0]); + ASSERT_EQ(L'e', dst[1]); + ASSERT_EQ(L'l', dst[2]); + ASSERT_EQ(&s[3], src); +} |