From d15181fa499f0e15abf3427219332852e2356569 Mon Sep 17 00:00:00 2001 From: mutouyun Date: Sun, 30 Oct 2022 16:15:33 +0800 Subject: [PATCH] fix: [imp] codecvt in win --- test/test_imp_codecvt.cpp | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/test/test_imp_codecvt.cpp b/test/test_imp_codecvt.cpp index 2e8c8e4..b7e887e 100644 --- a/test/test_imp_codecvt.cpp +++ b/test/test_imp_codecvt.cpp @@ -5,27 +5,22 @@ #include "gtest/gtest.h" #include "libimp/codecvt.h" -#include "libimp/countof.h" TEST(codecvt, cvt_cstr) { - char const *utf8 = "hello world, " - "\xe4\xbd\xa0\xe5\xa5\xbd\xef\xbc" - "\x8c\xe3\x81\x93\xe3\x82\x93\xe3" - "\x81\xab\xe3\x81\xa1\xe3\x81\xaf"; - char16_t const utf16[] = u"hello world, " - "\u4f60\u597d\uff0c\u3053\u3093\u306b\u3061\u306f"; + char const utf8[] = "hello world, 你好,こんにちは"; + wchar_t const utf16[] = L"hello world, 你好,こんにちは"; { - auto cvt_len = imp::cvt_cstr(utf8, std::strlen(utf8), (char16_t *)nullptr, 0); + auto cvt_len = imp::cvt_cstr(utf8, std::strlen(utf8), (wchar_t *)nullptr, 0); EXPECT_NE(cvt_len, 0); - std::u16string wstr(cvt_len, L'\0'); + std::wstring wstr(cvt_len, L'\0'); EXPECT_EQ(imp::cvt_cstr(utf8, std::strlen(utf8), &wstr[0], wstr.size()), cvt_len); EXPECT_EQ(wstr, utf16); } { - auto cvt_len = imp::cvt_cstr(utf16, imp::countof(utf16) - 1, (char *)nullptr, 0); + auto cvt_len = imp::cvt_cstr(utf16, std::wcslen(utf16), (char *)nullptr, 0); EXPECT_NE(cvt_len, 0); std::string str(cvt_len, '\0'); - EXPECT_EQ(imp::cvt_cstr(utf16, imp::countof(utf16) - 1, &str[0], str.size()), cvt_len); + EXPECT_EQ(imp::cvt_cstr(utf16, std::wcslen(utf16), &str[0], str.size()), cvt_len); EXPECT_EQ(str, utf8); } { @@ -36,9 +31,9 @@ TEST(codecvt, cvt_cstr) { EXPECT_EQ(str, utf8); } { - auto cvt_len = imp::cvt_cstr(utf16, imp::countof(utf16) - 1, (char16_t *)nullptr, 0); - EXPECT_EQ(cvt_len, imp::countof(utf16) - 1); - std::u16string wstr(cvt_len, u'\0'); + auto cvt_len = imp::cvt_cstr(utf16, std::wcslen(utf16), (wchar_t *)nullptr, 0); + EXPECT_EQ(cvt_len, std::wcslen(utf16)); + std::wstring wstr(cvt_len, u'\0'); EXPECT_EQ(imp::cvt_cstr(utf16, cvt_len, &wstr[0], wstr.size()), cvt_len); EXPECT_EQ(wstr, utf16); }