Changeset View
Changeset View
Standalone View
Standalone View
source/ps/tests/test_CStr.h
/* Copyright (C) 2010 Wildfire Games. | /* Copyright (C) 2017 Wildfire Games. | ||||
* This file is part of 0 A.D. | * This file is part of 0 A.D. | ||||
* | * | ||||
* 0 A.D. is free software: you can redistribute it and/or modify | * 0 A.D. is free software: you can redistribute it and/or modify | ||||
* it under the terms of the GNU General Public License as published by | * it under the terms of the GNU General Public License as published by | ||||
* the Free Software Foundation, either version 2 of the License, or | * the Free Software Foundation, either version 2 of the License, or | ||||
* (at your option) any later version. | * (at your option) any later version. | ||||
* | * | ||||
* 0 A.D. is distributed in the hope that it will be useful, | * 0 A.D. is distributed in the hope that it will be useful, | ||||
▲ Show 20 Lines • Show All 60 Lines • ▼ Show 20 Lines | for (size_t i = 0; i < ARRAY_SIZE(tests); ++i) | ||||
CStrW str_utf16 (tests[i].utf16); | CStrW str_utf16 (tests[i].utf16); | ||||
CStrW str_utf8to16 = str_utf8.FromUTF8(); | CStrW str_utf8to16 = str_utf8.FromUTF8(); | ||||
TS_ASSERT_EQUALS(str_utf16.length(), str_utf8to16.length()); | TS_ASSERT_EQUALS(str_utf16.length(), str_utf8to16.length()); | ||||
TS_ASSERT_SAME_DATA(str_utf8to16.data(), str_utf16.data(), str_utf16.length()*sizeof(wchar_t)); | TS_ASSERT_SAME_DATA(str_utf8to16.data(), str_utf16.data(), str_utf16.length()*sizeof(wchar_t)); | ||||
} | } | ||||
} | } | ||||
template <typename T> | |||||
void roundtrip(const T& str) | |||||
{ | |||||
size_t len = str.GetSerializedLength(); | |||||
u8* buf = new u8[len+1]; | |||||
buf[len] = '!'; | |||||
TS_ASSERT_EQUALS(str.Serialize(buf) - (buf+len), 0); | |||||
TS_ASSERT_EQUALS(buf[len], '!'); | |||||
T str2; | |||||
TS_ASSERT_EQUALS(str2.Deserialize(buf, buf+len) - (buf+len), 0); | |||||
TS_ASSERT_EQUALS(str2.length(), str.length()); | |||||
TS_ASSERT_EQUALS(str2, str); | |||||
T str3; | |||||
TS_ASSERT_EQUALS(str3.Deserialize(buf, buf+len+256) - (buf+len), 0); | |||||
TS_ASSERT_EQUALS(str3.length(), str.length()); | |||||
TS_ASSERT_EQUALS(str3, str); | |||||
delete[] buf; | |||||
} | |||||
void test_serialize_8() | |||||
{ | |||||
CStr8 str1("hello"); | |||||
roundtrip(str1); | |||||
CStr8 str2 = str1; | |||||
str2[3] = '\0'; | |||||
roundtrip(str2); | |||||
} | |||||
leper: If you remove these I'd have expecte something similar in the new tests. | |||||
Not Done Inline ActionsThe serialization / deserialization of strings is already tested in the tests for net messages. echotangoecho: The serialization / deserialization of strings is already tested in the tests for net messages. | |||||
void test_parse() | void test_parse() | ||||
{ | { | ||||
// Parsing should be independent of locale ("," vs "."), | // Parsing should be independent of locale ("," vs "."), | ||||
// because GTK+ can change the locale when we're running Atlas. | // because GTK+ can change the locale when we're running Atlas. | ||||
// (If the host system doesn't have the locale we're using for this test | // (If the host system doesn't have the locale we're using for this test | ||||
// then it'll just stick with the default, which is fine) | // then it'll just stick with the default, which is fine) | ||||
char* old = setlocale(LC_NUMERIC, NULL); | char* old = setlocale(LC_NUMERIC, NULL); | ||||
setlocale(LC_NUMERIC, "fr_FR.UTF-8"); | setlocale(LC_NUMERIC, "fr_FR.UTF-8"); | ||||
Show All 28 Lines |
Wildfire Games · Phabricator
If you remove these I'd have expecte something similar in the new tests.