diff options
| author | degasus <wickmarkus@web.de> | 2016-08-10 18:48:01 +0200 |
|---|---|---|
| committer | Léo Lam <leo@innovatetechnologi.es> | 2018-06-03 23:12:32 +0200 |
| commit | 7154bfd82559747681313531b5d53ab44bd88493 (patch) | |
| tree | e168ddb3cecce61270b12e8b9764a2ba3f6c458e /Source/UnitTests/Common/StringUtilTest.cpp | |
| parent | 83324fe77dced89c6369b75ecf91899078508e17 (diff) | |
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.
Diffstat (limited to 'Source/UnitTests/Common/StringUtilTest.cpp')
| -rw-r--r-- | Source/UnitTests/Common/StringUtilTest.cpp | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/Source/UnitTests/Common/StringUtilTest.cpp b/Source/UnitTests/Common/StringUtilTest.cpp index 39a0d44944..cae007fdbe 100644 --- a/Source/UnitTests/Common/StringUtilTest.cpp +++ b/Source/UnitTests/Common/StringUtilTest.cpp @@ -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}); +} |
