summaryrefslogtreecommitdiffstats
path: root/tests/wchar_test.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/wchar_test.cpp')
-rw-r--r--tests/wchar_test.cpp193
1 files changed, 188 insertions, 5 deletions
diff --git a/tests/wchar_test.cpp b/tests/wchar_test.cpp
index d02c4bf..e86d56d 100644
--- a/tests/wchar_test.cpp
+++ b/tests/wchar_test.cpp
@@ -22,6 +22,8 @@
#include <stdint.h>
#include <wchar.h>
+#define NUM_WCHARS(num_bytes) (num_bytes/sizeof(wchar_t))
+
TEST(wchar, sizeof_wchar_t) {
EXPECT_EQ(4U, sizeof(wchar_t));
EXPECT_EQ(4U, sizeof(wint_t));
@@ -232,6 +234,11 @@ TEST(wchar, wcsstr) {
ASSERT_EQ(NULL, wcsstr(haystack, bad_needle));
}
+TEST(wchar, wcsstr_80199) {
+ // https://code.google.com/p/android/issues/detail?id=80199
+ ASSERT_TRUE(wcsstr(L"romrom", L"rom") != NULL);
+}
+
TEST(wchar, mbtowc) {
wchar_t out[8];
@@ -343,7 +350,7 @@ void test_mbsrtowcs(mbstate_t* ps) {
// Check that valid has advanced to the next unread character.
ASSERT_EQ('e', *valid);
- wmemset(out, L'x', sizeof(out) / sizeof(wchar_t));
+ wmemset(out, L'x', NUM_WCHARS(sizeof(out)));
ASSERT_EQ(2U, mbsrtowcs(out, &valid, 4, ps));
ASSERT_EQ(L'e', out[0]);
ASSERT_EQ(L'f', out[1]);
@@ -450,17 +457,85 @@ TEST(wchar, wcsftime) {
EXPECT_STREQ(L"Sun Mar 10 00:00:00 2100", buf);
}
-TEST(wchar, wmemmove) {
+TEST(wchar, wmemmove_smoke) {
const wchar_t const_wstr[] = L"This is a test of something or other.....";
- wchar_t* wstr = new wchar_t[sizeof(const_wstr)];
+ wchar_t wstr[NUM_WCHARS(sizeof(const_wstr))];
- wmemmove(wstr, const_wstr, sizeof(const_wstr)/sizeof(wchar_t));
+ EXPECT_EQ(wstr, wmemmove(wstr, const_wstr, NUM_WCHARS(sizeof(const_wstr))));
EXPECT_STREQ(const_wstr, wstr);
- wmemmove(wstr+5, wstr, sizeof(const_wstr)/sizeof(wchar_t) - 6);
+ EXPECT_EQ(wstr+5, wmemmove(wstr+5, wstr, NUM_WCHARS(sizeof(const_wstr)) - 6));
EXPECT_STREQ(L"This This is a test of something or other", wstr);
}
+TEST(wchar, wmemcpy_smoke) {
+ const wchar_t src[] = L"Source string";
+ wchar_t dst[NUM_WCHARS(sizeof(src))];
+
+ EXPECT_EQ(dst, wmemcpy(dst, src, NUM_WCHARS(sizeof(src))));
+ EXPECT_STREQ(dst, src);
+}
+
+TEST(wchar, wcpcpy_smoke) {
+ const wchar_t src[] = L"Source string";
+ wchar_t dst[NUM_WCHARS(sizeof(src))];
+
+ EXPECT_EQ(dst + NUM_WCHARS(sizeof(src)) - 1, wcpcpy(dst, src));
+ EXPECT_STREQ(dst, src);
+}
+
+TEST(wchar, wcpncpy_smoke) {
+ const wchar_t src[] = L"Source string";
+ wchar_t dst[NUM_WCHARS(sizeof(src)) + 5];
+
+ size_t src_len = NUM_WCHARS(sizeof(src)) - 1;
+ EXPECT_EQ(dst + src_len, wcpncpy(dst, src, src_len + 1));
+ EXPECT_STREQ(dst, src);
+
+ EXPECT_EQ(dst + 6, wcpncpy(dst, src, 6));
+ dst[6] = L'\0';
+ EXPECT_STREQ(dst, L"Source");
+
+ wmemset(dst, L'x', NUM_WCHARS(sizeof(dst)));
+ EXPECT_EQ(dst + src_len, wcpncpy(dst, src, src_len + 4));
+ EXPECT_STREQ(dst, src);
+ EXPECT_EQ(dst[src_len], L'\0');
+ EXPECT_EQ(dst[src_len+1], L'\0');
+ EXPECT_EQ(dst[src_len+2], L'\0');
+ EXPECT_EQ(dst[src_len+3], L'\0');
+ EXPECT_EQ(dst[src_len+4], L'x');
+}
+
+TEST(wchar, wcscpy_smoke) {
+ const wchar_t src[] = L"Source string";
+ wchar_t dst[NUM_WCHARS(sizeof(src))];
+
+ EXPECT_EQ(dst, wcscpy(dst, src));
+ EXPECT_STREQ(src, dst);
+}
+
+TEST(wchar, wcsncpy_smoke) {
+ const wchar_t src[] = L"Source string";
+ wchar_t dst[NUM_WCHARS(sizeof(src)) + 5];
+
+ size_t src_len = NUM_WCHARS(sizeof(src)) - 1;
+ EXPECT_EQ(dst, wcsncpy(dst, src, src_len + 1));
+ EXPECT_STREQ(dst, src);
+
+ EXPECT_EQ(dst, wcsncpy(dst, src, 6));
+ dst[6] = L'\0';
+ EXPECT_STREQ(dst, L"Source");
+
+ wmemset(dst, L'x', NUM_WCHARS(sizeof(dst)));
+ EXPECT_EQ(dst, wcsncpy(dst, src, src_len + 4));
+ EXPECT_STREQ(dst, src);
+ EXPECT_EQ(dst[src_len], L'\0');
+ EXPECT_EQ(dst[src_len+1], L'\0');
+ EXPECT_EQ(dst[src_len+2], L'\0');
+ EXPECT_EQ(dst[src_len+3], L'\0');
+ EXPECT_EQ(dst[src_len+4], L'x');
+}
+
TEST(wchar, mbrtowc_15439554) {
// http://b/15439554
ASSERT_STREQ("C.UTF-8", setlocale(LC_CTYPE, "C.UTF-8"));
@@ -489,3 +564,111 @@ TEST(wchar, mbrtowc_15439554) {
EXPECT_EQ(4U, n);
EXPECT_EQ(L'𤭢', wc);
}
+
+TEST(wchar, open_wmemstream) {
+ wchar_t* p = nullptr;
+ size_t size = 0;
+ FILE* fp = open_wmemstream(&p, &size);
+ ASSERT_NE(EOF, fputws(L"hello, world!", fp));
+ fclose(fp);
+
+ ASSERT_STREQ(L"hello, world!", p);
+ ASSERT_EQ(wcslen(L"hello, world!"), size);
+ free(p);
+}
+
+TEST(stdio, open_wmemstream_EINVAL) {
+#if defined(__BIONIC__)
+ wchar_t* p;
+ size_t size;
+
+ // Invalid buffer.
+ errno = 0;
+ ASSERT_EQ(nullptr, open_wmemstream(nullptr, &size));
+ ASSERT_EQ(EINVAL, errno);
+
+ // Invalid size.
+ errno = 0;
+ ASSERT_EQ(nullptr, open_wmemstream(&p, nullptr));
+ ASSERT_EQ(EINVAL, errno);
+#else
+ GTEST_LOG_(INFO) << "This test does nothing.\n";
+#endif
+}
+
+TEST(wchar, wcstol_EINVAL) {
+ errno = 0;
+ wcstol(L"123", NULL, -1);
+ ASSERT_EQ(EINVAL, errno);
+ errno = 0;
+ wcstol(L"123", NULL, 1);
+ ASSERT_EQ(EINVAL, errno);
+ errno = 0;
+ wcstol(L"123", NULL, 37);
+ ASSERT_EQ(EINVAL, errno);
+}
+
+TEST(wchar, wcstoll_EINVAL) {
+ errno = 0;
+ wcstoll(L"123", NULL, -1);
+ ASSERT_EQ(EINVAL, errno);
+ errno = 0;
+ wcstoll(L"123", NULL, 1);
+ ASSERT_EQ(EINVAL, errno);
+ errno = 0;
+ wcstoll(L"123", NULL, 37);
+ ASSERT_EQ(EINVAL, errno);
+}
+
+TEST(wchar, wcstoul_EINVAL) {
+ errno = 0;
+ wcstoul(L"123", NULL, -1);
+ ASSERT_EQ(EINVAL, errno);
+ errno = 0;
+ wcstoul(L"123", NULL, 1);
+ ASSERT_EQ(EINVAL, errno);
+ errno = 0;
+ wcstoul(L"123", NULL, 37);
+ ASSERT_EQ(EINVAL, errno);
+}
+
+TEST(wchar, wcstoull_EINVAL) {
+ errno = 0;
+ wcstoull(L"123", NULL, -1);
+ ASSERT_EQ(EINVAL, errno);
+ errno = 0;
+ wcstoull(L"123", NULL, 1);
+ ASSERT_EQ(EINVAL, errno);
+ errno = 0;
+ wcstoull(L"123", NULL, 37);
+ ASSERT_EQ(EINVAL, errno);
+}
+
+TEST(wchar, wcstoll_l_EINVAL) {
+ errno = 0;
+ wcstoll_l(L"123", NULL, -1, LC_GLOBAL_LOCALE);
+ ASSERT_EQ(EINVAL, errno);
+ errno = 0;
+ wcstoll_l(L"123", NULL, 1, LC_GLOBAL_LOCALE);
+ ASSERT_EQ(EINVAL, errno);
+ errno = 0;
+ wcstoll_l(L"123", NULL, 37, LC_GLOBAL_LOCALE);
+ ASSERT_EQ(EINVAL, errno);
+}
+
+TEST(wchar, wcstoull_l_EINVAL) {
+ errno = 0;
+ wcstoull_l(L"123", NULL, -1, LC_GLOBAL_LOCALE);
+ ASSERT_EQ(EINVAL, errno);
+ errno = 0;
+ wcstoull_l(L"123", NULL, 1, LC_GLOBAL_LOCALE);
+ ASSERT_EQ(EINVAL, errno);
+ errno = 0;
+ wcstoull_l(L"123", NULL, 37, LC_GLOBAL_LOCALE);
+ ASSERT_EQ(EINVAL, errno);
+}
+
+TEST(wchar, wmempcpy) {
+ wchar_t dst[6];
+ ASSERT_EQ(&dst[4], wmempcpy(dst, L"hello", 4));
+}