Skip to content

Commit 1921356

Browse files
author
Sriya Pratipati
committed
added final test
1 parent 0694e91 commit 1921356

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

libc/test/src/wchar/mbstowcs_test.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,3 +115,20 @@ TEST_F(LlvmLibcMBSToWCSTest, NullDestination) {
115115
// Null destination should ignore len and read till end of string
116116
ASSERT_EQ(static_cast<int>(n), 4);
117117
}
118+
119+
TEST_F(LlvmLibcMBSToWCSTest, ErrnoChecks) {
120+
// Two laughing cat emojis and invalid 3rd mb char (3rd byte of it)
121+
const char *src =
122+
"\xf0\x9f\x98\xb9\xf0\x9f\x98\xb9\xf0\x9f\xf0\xb9\xf0\x9f\x98\xb9";
123+
wchar_t dest[5];
124+
// First two bytes are valid --> should not set errno
125+
size_t n = LIBC_NAMESPACE::mbstowcs(dest, src, 2);
126+
ASSERT_ERRNO_SUCCESS();
127+
ASSERT_EQ(static_cast<int>(n), 2);
128+
ASSERT_EQ(static_cast<int>(dest[0]), 128569);
129+
ASSERT_EQ(static_cast<int>(dest[1]), 128569);
130+
// Trying to read the 3rd byte should set errno
131+
n = LIBC_NAMESPACE::mbstowcs(dest, src, 2);
132+
ASSERT_ERRNO_EQ(EILSEQ);
133+
ASSERT_EQ(static_cast<int>(n), -1);
134+
}

0 commit comments

Comments
 (0)