From b19c6be769f21c2a8bfe53df4656ccf61c6e735c Mon Sep 17 00:00:00 2001 From: Mrognor Date: Thu, 5 Dec 2024 19:22:21 +0300 Subject: [PATCH] Fix bug --- Tests/MTests/GetLine.cpp | 15 +++++++++++++++ Tests/MTests/GetLine.h | 5 +++++ Tests/MTests/TestAssert.h | 1 + Tests/VaultRecordSetUnitTest.cpp | 12 ++++++------ Tests/VaultUnitTest.cpp | 12 ++++++------ 5 files changed, 33 insertions(+), 12 deletions(-) create mode 100644 Tests/MTests/GetLine.cpp create mode 100644 Tests/MTests/GetLine.h diff --git a/Tests/MTests/GetLine.cpp b/Tests/MTests/GetLine.cpp new file mode 100644 index 0000000..3f482ee --- /dev/null +++ b/Tests/MTests/GetLine.cpp @@ -0,0 +1,15 @@ +#include "GetLine.h" + +std::string GetLine(std::basic_istream> & inputStream) noexcept +{ +#if defined WIN32 || defined _WIN64 + std::string line; + getline(inputStream, line); + return line; +#else + std::string line; + getline(inputStream, line); + line.pop_back(); + return line; +#endif +} \ No newline at end of file diff --git a/Tests/MTests/GetLine.h b/Tests/MTests/GetLine.h new file mode 100644 index 0000000..e551c97 --- /dev/null +++ b/Tests/MTests/GetLine.h @@ -0,0 +1,5 @@ +#pragma once + +#include + +std::string GetLine(std::basic_istream> & inputStream) noexcept; \ No newline at end of file diff --git a/Tests/MTests/TestAssert.h b/Tests/MTests/TestAssert.h index cb65fdc..fbd09c8 100644 --- a/Tests/MTests/TestAssert.h +++ b/Tests/MTests/TestAssert.h @@ -1,5 +1,6 @@ #pragma once +#include "GetLine.h" #include "ColorizedPrint.h" #define TEST_ASSERT(expression, description) if (!(expression)) \ diff --git a/Tests/VaultRecordSetUnitTest.cpp b/Tests/VaultRecordSetUnitTest.cpp index a66e752..c5e5e6a 100644 --- a/Tests/VaultRecordSetUnitTest.cpp +++ b/Tests/VaultRecordSetUnitTest.cpp @@ -716,32 +716,32 @@ void VaultRecordSet_SaveToFile_Test() vrs.SaveToFile("VaultRecordSet_UnitTest_SaveToFile.csv"); ifile.open("VaultRecordSet_UnitTest_SaveToFile.csv"); - getline(ifile, line); + line = GetLine(ifile); TEST_ASSERT(line == "A,B,C,D", "Failed to save data in file"); - getline(ifile, line); + line = GetLine(ifile); TEST_ASSERT(line == "1,false,record2,0.753400", "Failed to save data in file") ifile.close(); vrs.SaveToFile("VaultRecordSet_UnitTest_SaveToFile.csv", {"A", "C", "B"}, ";"); ifile.open("VaultRecordSet_UnitTest_SaveToFile.csv"); - getline(ifile, line); + line = GetLine(ifile); TEST_ASSERT(line == "A;C;B", "Failed to save data in file"); - getline(ifile, line); + line = GetLine(ifile); TEST_ASSERT(line == "1;record2;false", "Failed to save data in file") ifile.close(); vrs.SaveToFile("VaultRecordSet_UnitTest_SaveToFile.csv", {}, "|", false); ifile.open("VaultRecordSet_UnitTest_SaveToFile.csv"); - getline(ifile, line); + line = GetLine(ifile); TEST_ASSERT(line == "1|false|record2|0.753400", "Failed to save data in file"); ifile.close(); vrs.SaveToFile("VaultRecordSet_UnitTest_SaveToFile.csv", {"A", "non_existed_key", "B"}, "|", false); ifile.open("VaultRecordSet_UnitTest_SaveToFile.csv"); - getline(ifile, line); + line = GetLine(ifile); TEST_ASSERT(line == "1||false", "Failed to save data in file"); } diff --git a/Tests/VaultUnitTest.cpp b/Tests/VaultUnitTest.cpp index 4628060..b6daacd 100644 --- a/Tests/VaultUnitTest.cpp +++ b/Tests/VaultUnitTest.cpp @@ -683,32 +683,32 @@ void Vault_SaveToFile_Test() vlt.SaveToFile("Vault_UnitTest_SaveToFile.csv"); ifile.open("Vault_UnitTest_SaveToFile.csv"); - getline(ifile, line); + line = GetLine(ifile); TEST_ASSERT(line == "A,B,C,D", "Failed to save data in file"); - getline(ifile, line); + line = GetLine(ifile); TEST_ASSERT(line == "0,true,record1,0.151000", "Failed to save data in file") ifile.close(); vlt.SaveToFile("Vault_UnitTest_SaveToFile.csv", {"A", "C", "B"}, ";"); ifile.open("Vault_UnitTest_SaveToFile.csv"); - getline(ifile, line); + line = GetLine(ifile); TEST_ASSERT(line == "A;C;B", "Failed to save data in file"); - getline(ifile, line); + line = GetLine(ifile); TEST_ASSERT(line == "0;record1;true", "Failed to save data in file") ifile.close(); vlt.SaveToFile("Vault_UnitTest_SaveToFile.csv", {}, "|", false); ifile.open("Vault_UnitTest_SaveToFile.csv"); - getline(ifile, line); + line = GetLine(ifile); TEST_ASSERT(line == "0|true|record1|0.151000", "Failed to save data in file"); ifile.close(); vlt.SaveToFile("Vault_UnitTest_SaveToFile.csv", {"A", "non_existed_key", "B"}, "|", false); ifile.open("Vault_UnitTest_SaveToFile.csv"); - getline(ifile, line); + line = GetLine(ifile); TEST_ASSERT(line == "0||true", "Failed to save data in file"); }