Allow tests to work with CRLF test data

This commit is contained in:
Ted John 2020-02-02 15:35:41 +00:00
parent 1dc7bc2466
commit 5dbd3c7c0c
3 changed files with 34 additions and 4 deletions

View File

@ -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

View File

@ -8,6 +8,7 @@
*****************************************************************************/
#include "TestData.h"
#include "helpers/StringHelpers.hpp"
#include <gtest/gtest.h>
#include <openrct2/core/Crypt.h>
@ -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();

View File

@ -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;
}