MCPcopy Create free account
hub / github.com/OpenApoc/OpenApoc / test

Method test

tests/test_unicode.cpp:31–87  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

29#endif
30
31 bool test() const
32 {
33 LogInfo("Testing string \"%s\"", u8string);
34 const auto num_codepoints = expected_codepoints.size();
35 UString string(u8string);
36 U32String string2;
37 auto u32str = to_u32string(string);
38 if (u32str.length() != num_codepoints)
39 {
40 LogError("String \"%s\" has unexpected length %zu , expected %zu", u8string,
41 string.length(), num_codepoints);
42 return false;
43 }
44
45 std::vector<char32_t> decoded_codepoints;
46
47 for (auto c : u32str)
48 decoded_codepoints.push_back(c);
49
50 if (decoded_codepoints.size() != num_codepoints)
51 {
52 LogError("String \"%s\" has unexpected iterated length %zu , expected %zu", u8string,
53 decoded_codepoints.size(), num_codepoints);
54 return false;
55 }
56
57 for (size_t i = 0; i < num_codepoints; i++)
58 {
59 if (expected_codepoints[i] != decoded_codepoints[i])
60 {
61 LogError(
62 "String \"%s\" has unexpected codepoint at index %zu - got 0x%x expected 0x%x",
63 u8string, i, static_cast<uint32_t>(decoded_codepoints[i]),
64 static_cast<uint32_t>(expected_codepoints[i]));
65 return false;
66 }
67 string2 += decoded_codepoints[i];
68 }
69
70 if (string != to_ustring(string2))
71 {
72 LogError(
73 "String \"%s\" compared false after utf8->unichar->utf8 conversion - got \"%s\"",
74 u8string, to_ustring(string2));
75
76 return false;
77 }
78
79 if (!test_32_8_roundtrip(u8string))
80 {
81 return false;
82 }
83
84 LogInfo("Looks good");
85
86 return true;
87 }
88};

Callers 1

mainFunction · 0.80

Calls 4

to_u32stringFunction · 0.85
to_ustringFunction · 0.85
test_32_8_roundtripFunction · 0.85
sizeMethod · 0.45

Tested by

no test coverage detected