From 61fe98165ad9c1536fb48946f60ef91d671d4f9a Mon Sep 17 00:00:00 2001 From: kdesnos Date: Thu, 18 Jun 2020 08:40:56 +0200 Subject: [PATCH] (Test) Restore Exportertest::FileContentVerification test. --- test/exporterTest.cpp | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/test/exporterTest.cpp b/test/exporterTest.cpp index e567e3a5..f5da5fcd 100644 --- a/test/exporterTest.cpp +++ b/test/exporterTest.cpp @@ -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."; +}