Add POSIX-2008 fmemopen, open_memstream, and open_wmemstream.

Bug: 17164505
Change-Id: I59e28a08ff8b6ab632230b11a5807cfd5278aeb5
This commit is contained in:
Elliott Hughes
2014-08-20 16:10:49 -07:00
parent b6ed54076a
commit 6b841db2ba
8 changed files with 629 additions and 0 deletions

View File

@@ -489,3 +489,34 @@ 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
}