File: test_imp_codecvt.cpp

package info (click to toggle)
dolphin-emu 2603%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 69,040 kB
  • sloc: cpp: 442,137; ansic: 117,979; python: 6,438; sh: 2,387; asm: 726; makefile: 394; pascal: 257; javascript: 183; perl: 97; objc: 75; xml: 8
file content (40 lines) | stat: -rw-r--r-- 1,345 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40

#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);
  }
}