1 #include <errno.h> 2 #include <gtest/gtest.h> 3 #include <locale.h> 4 5 using namespace testing::ext; 6 7 class MultibyteMbrtowcTest : public testing::Test { SetUp()8 void SetUp() override {} TearDown()9 void TearDown() override {} 10 }; 11 12 constexpr int SIZE = 8; 13 constexpr int BUFFERSIZE = 4; 14 15 /** 16 * @tc.name: mbrtowc_001 17 * @tc.desc: This test verifies that in the C.UTF-8 character encoding environment, when using the mbrtowc function to 18 * convert an invalid multi byte sequence to a wide character, the function should return -1 and set errno to 19 * EILSEQ (invalid byte sequence). 20 * @tc.type: FUNC 21 */ 22 HWTEST_F(MultibyteMbrtowcTest, mbrtowc_001, TestSize.Level1) 23 { 24 const char* localeStr = setlocale(LC_CTYPE, "C.UTF-8"); 25 EXPECT_EQ(std::string("C.UTF-8"), std::string(localeStr)); 26 uselocale(LC_GLOBAL_LOCALE); 27 wchar_t out[SIZE] = {}; 28 errno = 0; 29 size_t ret = mbrtowc(out, "\xf5\x80\x80\x80", BUFFERSIZE, nullptr); 30 EXPECT_TRUE(static_cast<size_t>(-1) == ret); 31 EXPECT_TRUE(EILSEQ == errno); 32 }