Skip to content

Commit

Permalink
UnitTest: Add StringUtil ToString/TryParse test
Browse files Browse the repository at this point in the history
Only a single one, but the main one for ini files:
Check if the written values can be parsed again.
  • Loading branch information
degasus authored and leoetlino committed Jun 3, 2018
1 parent 83324fe commit 7154bfd
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions Source/UnitTests/Common/StringUtilTest.cpp
Expand Up @@ -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});
}

0 comments on commit 7154bfd

Please sign in to comment.