Skip to content

Commit

Permalink
Fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
mrognor committed Dec 5, 2024
1 parent f7bdc4e commit 0378a64
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 12 deletions.
15 changes: 15 additions & 0 deletions Tests/MTests/GetLine.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include "GetLine.h"

std::string GetLine(std::basic_istream<char, std::char_traits<char>> & 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
}
5 changes: 5 additions & 0 deletions Tests/MTests/GetLine.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#pragma once

#include <fstream>

std::string GetLine(std::basic_istream<char, std::char_traits<char>> & inputStream) noexcept;
1 change: 1 addition & 0 deletions Tests/MTests/TestAssert.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include "GetLine.h"
#include "ColorizedPrint.h"

#define TEST_ASSERT(expression, description) if (!(expression)) \
Expand Down
12 changes: 6 additions & 6 deletions Tests/VaultRecordSetUnitTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}

Expand Down
12 changes: 6 additions & 6 deletions Tests/VaultUnitTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}

Expand Down

0 comments on commit 0378a64

Please sign in to comment.