From 7154bfd82559747681313531b5d53ab44bd88493 Mon Sep 17 00:00:00 2001 From: degasus Date: Wed, 10 Aug 2016 18:48:01 +0200 Subject: [PATCH] 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. --- Source/UnitTests/Common/StringUtilTest.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) 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 +static void DoRoundTripTest(const std::vector& 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({true, false}); + DoRoundTripTest({0, -1, 1, 123, -123, 123456789, -123456789}); + DoRoundTripTest({0u, 1u, 123u, 123456789u, 4023456789u}); + DoRoundTripTest({0.0f, 1.0f, -1.0f, -0.5f, 0.5f, -1e-3f, 1e-3f, 1e3f, -1e3f}); + DoRoundTripTest({0.0, 1.0, -1.0, -0.5, 0.5, -1e-3, 1e-3, 1e3, -1e3}); +}