Skip to content

Commit

Permalink
(Test) Restore Exportertest::FileContentVerification test.
Browse files Browse the repository at this point in the history
  • Loading branch information
kdesnos committed Jun 18, 2020
1 parent 9478969 commit 61fe981
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions test/exporterTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,3 +164,44 @@ TEST_F(ExporterTest, print) {

ASSERT_NO_THROW(dotExporter.print()) << "File export was executed without error.";
}

TEST_F(ExporterTest, FileContentVerification) {
// This Test checks the content of the exported file against a golden reference.
File::TPGGraphDotExporter dotExporter("exported_tpg.dot", *tpg);

dotExporter.print();

std::ifstream goldenRef(TESTS_DAT_PATH "exported_tpg_ref.dot");
ASSERT_TRUE(goldenRef.is_open()) << "Could not open golden reference. Check project configuration.";

std::ifstream exportedFile("exported_tpg.dot");
ASSERT_TRUE(exportedFile) << "Could not open exported dot file.";

// Check the file content line by line
// print diffs in the console and count number of printed line.
uint64_t nbDiffs = 0;
uint64_t lineNumber = 0;
while (!exportedFile.eof() && !goldenRef.eof()) {
std::string lineRef;
std::getline(goldenRef, lineRef);

std::string lineExport;
std::getline(exportedFile, lineExport);

if (lineRef != lineExport) {
nbDiffs++;
std::cout << "Diff at Line " << lineNumber << ":" << std::endl;
std::cout << "\tref: " << lineRef << std::endl;
std::cout << "\texp: " << lineExport << std::endl;
}

lineNumber++;
}

if (!exportedFile.eof() || !goldenRef.eof()) {
nbDiffs++;
std::cout << "Files have different length." << std::endl;
}

ASSERT_EQ(nbDiffs, 0) << "Differences between reference file and exported file were detected.";
}

0 comments on commit 61fe981

Please sign in to comment.