From 5dbd3c7c0cfad7e28f69ea3f8a59073de167fe65 Mon Sep 17 00:00:00 2001 From: Ted John Date: Sun, 2 Feb 2020 15:35:41 +0000 Subject: [PATCH] Allow tests to work with CRLF test data --- scripts/run-tests | 3 --- test/tests/CryptTests.cpp | 3 ++- test/tests/helpers/StringHelpers.hpp | 32 ++++++++++++++++++++++++++++ 3 files changed, 34 insertions(+), 4 deletions(-) diff --git a/scripts/run-tests b/scripts/run-tests index 821984a066..bb9908c1f6 100755 --- a/scripts/run-tests +++ b/scripts/run-tests @@ -10,9 +10,6 @@ echo -e "\033[0;36mBuilding OpenRCT2 repository indexes...\033[0m" ./openrct2 scan-objects if [[ "$OSTYPE" == "cygwin" || "$OSTYPE" == "msys" ]]; then - # Ensure test data uses LF - dos2unix testdata/keys/* - # Now run all the tests echo -e "\033[0;36mRunning OpenRCT2 tests...\033[0m" ./tests --gtest_output=xml:../artifacts/test-results.xml diff --git a/test/tests/CryptTests.cpp b/test/tests/CryptTests.cpp index c08581a63a..90314ee674 100644 --- a/test/tests/CryptTests.cpp +++ b/test/tests/CryptTests.cpp @@ -8,6 +8,7 @@ *****************************************************************************/ #include "TestData.h" +#include "helpers/StringHelpers.hpp" #include #include @@ -153,7 +154,7 @@ TEST_F(CryptTests, RSA_VerifyWithPublic) TEST_F(CryptTests, RSAKey_GetPublic) { - auto inPem = File::ReadAllText(GetTestPublicKeyPath()); + auto inPem = NormaliseLineEndings(File::ReadAllText(GetTestPublicKeyPath())); auto publicKey = Crypt::CreateRSAKey(); publicKey->SetPublic(inPem); auto outPem = publicKey->GetPublic(); diff --git a/test/tests/helpers/StringHelpers.hpp b/test/tests/helpers/StringHelpers.hpp index 14a6c59edc..aa8d50979f 100644 --- a/test/tests/helpers/StringHelpers.hpp +++ b/test/tests/helpers/StringHelpers.hpp @@ -24,3 +24,35 @@ inline std::string StringFromHex(const std::string_view& input) } return result; } + +inline std::string NormaliseLineEndings(const std::string_view& input) +{ + std::string result; + result.reserve(input.size()); + auto ignoreNextNewLine = false; + for (auto c : input) + { + if (c == '\r') + { + ignoreNextNewLine = true; + result.push_back('\n'); + } + else if (c == '\n') + { + if (ignoreNextNewLine) + { + ignoreNextNewLine = false; + } + else + { + result.push_back('\n'); + } + } + else + { + ignoreNextNewLine = false; + result.push_back(c); + } + } + return result; +}