cpp-ipc/test/imp/test_imp_codecvt.cpp
木头云 b35de5a154 fix(test): Update test.h include paths after master rebase
After rebasing onto master, test.h was moved to test/archive/.
Updated include paths in test subdirectories:
- test/imp/*.cpp: "test.h" -> "../archive/test.h"
- test/mem/*.cpp: "test.h" -> "../archive/test.h"
- test/concur/*.cpp: "test.h" -> "../archive/test.h"

This ensures all test files can properly find the test header
after the directory reorganization in master branch.
2025-12-03 08:28:37 +00:00

41 lines
1.3 KiB
C++

#include <string>
#include <cstring>
#include "../archive/test.h"
#include "libipc/imp/codecvt.h"
TEST(codecvt, cvt_cstr) {
char const utf8[] = "hello world, 你好,こんにちは";
wchar_t const utf16[] = L"hello world, 你好,こんにちは";
{
auto cvt_len = ipc::cvt_cstr(utf8, std::strlen(utf8), (wchar_t *)nullptr, 0);
EXPECT_NE(cvt_len, 0);
std::wstring wstr(cvt_len, L'\0');
EXPECT_EQ(ipc::cvt_cstr(utf8, std::strlen(utf8), &wstr[0], wstr.size()), cvt_len);
EXPECT_EQ(wstr, utf16);
}
{
auto cvt_len = ipc::cvt_cstr(utf16, std::wcslen(utf16), (char *)nullptr, 0);
EXPECT_NE(cvt_len, 0);
std::string str(cvt_len, '\0');
EXPECT_EQ(ipc::cvt_cstr(utf16, std::wcslen(utf16), &str[0], str.size()), cvt_len);
EXPECT_EQ(str, utf8);
}
{
auto cvt_len = ipc::cvt_cstr(utf8, std::strlen(utf8), (char *)nullptr, 0);
EXPECT_EQ(cvt_len, std::strlen(utf8));
std::string str(cvt_len, '\0');
EXPECT_EQ(ipc::cvt_cstr(utf8, cvt_len, &str[0], str.size()), cvt_len);
EXPECT_EQ(str, utf8);
}
{
auto cvt_len = ipc::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(ipc::cvt_cstr(utf16, cvt_len, &wstr[0], wstr.size()), cvt_len);
EXPECT_EQ(wstr, utf16);
}
}