mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-02-10 06:29:00 +01:00
UnitTest: Add StringUtil ToString/TryParse test
Only a single one, but the main one for ini files: Check if the written values can be parsed again.
This commit is contained in:
parent
83324fe77d
commit
7154bfd825
@ -84,3 +84,24 @@ TEST(StringUtil, UTF8ToSHIFTJIS)
|
||||
EXPECT_STREQ(SHIFTJISToUTF8(UTF8ToSHIFTJIS(kirby_unicode)).c_str(), kirby_unicode.c_str());
|
||||
EXPECT_STREQ(UTF8ToSHIFTJIS(kirby_unicode).c_str(), kirby_sjis.c_str());
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
static void DoRoundTripTest(const std::vector<T>& data)
|
||||
{
|
||||
for (const T& e : data)
|
||||
{
|
||||
const std::string s = ValueToString(e);
|
||||
T out;
|
||||
EXPECT_TRUE(TryParse(s, &out));
|
||||
EXPECT_EQ(e, out);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(StringUtil, ToString_TryParse_Roundtrip)
|
||||
{
|
||||
DoRoundTripTest<bool>({true, false});
|
||||
DoRoundTripTest<int>({0, -1, 1, 123, -123, 123456789, -123456789});
|
||||
DoRoundTripTest<unsigned int>({0u, 1u, 123u, 123456789u, 4023456789u});
|
||||
DoRoundTripTest<float>({0.0f, 1.0f, -1.0f, -0.5f, 0.5f, -1e-3f, 1e-3f, 1e3f, -1e3f});
|
||||
DoRoundTripTest<double>({0.0, 1.0, -1.0, -0.5, 0.5, -1e-3, 1e-3, 1e3, -1e3});
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user