Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Debugging graphic tests in roottest #1153

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions graphics/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# TODO: massive failures hit on Linux, untested on Windows
if (CMAKE_SYSTEM_NAME MATCHES Darwin)
if (NOT MSVC)

# Folders for generated files
set(BUILD_DIR ${CMAKE_CURRENT_BINARY_DIR})
Expand Down Expand Up @@ -179,10 +178,7 @@ foreach(TEST_DESCRIPTION ${TEST_DESCRIPTIONS})
# EXEC node Test_JsRoot.js ${macro} ${BUILD_DIR})

elseif(${test_type} STREQUAL "a")
# TODO The JSON comparison has an extremely high failure rate. It is disabled for now
# but has to be re-enabled
#foreach (X "j" "o" "p")
foreach (X "o" "p")
foreach (X "j" "o" "p")
ROOTTEST_ADD_TEST(${macro}_${X}
MACRO testGraphics.C
MACROARG \"${macro}\",\"${X}\",\"${macro_folder}\",\"${BUILD_DIR}\")
Expand Down
Binary file modified graphics/json_ref/AtlasExample.json.zip
Binary file not shown.
Binary file modified graphics/json_ref/BreitWigner.json.zip
Binary file not shown.
Binary file modified graphics/json_ref/CrystalBall.json.zip
Binary file not shown.
Binary file modified graphics/json_ref/DynamicSlice.json.zip
Binary file not shown.
Binary file modified graphics/json_ref/Fibonacci.json.zip
Binary file not shown.
Binary file modified graphics/json_ref/GammaFun.json.zip
Binary file not shown.
Binary file modified graphics/json_ref/NormalizeHistogram.json.zip
Binary file not shown.
Binary file modified graphics/json_ref/TSVDUnfoldExample.json.zip
Binary file not shown.
Binary file modified graphics/json_ref/ZoomHistogram.json.zip
Binary file not shown.
Binary file modified graphics/json_ref/analyze.json.zip
Binary file not shown.
Binary file modified graphics/json_ref/annotation3d.json.zip
Binary file not shown.
Binary file modified graphics/json_ref/approx.json.zip
Binary file not shown.
Binary file modified graphics/json_ref/archi.json.zip
Binary file not shown.
Binary file modified graphics/json_ref/arrows.json.zip
Binary file not shown.
Binary file modified graphics/json_ref/basic3d.json.zip
Binary file not shown.
Binary file modified graphics/json_ref/candledecay.json.zip
Binary file not shown.
Binary file modified graphics/json_ref/candleplot.json.zip
Binary file not shown.
Binary file modified graphics/json_ref/candleplotstack.json.zip
Binary file not shown.
Binary file modified graphics/json_ref/candleplotwhiskers.json.zip
Binary file not shown.
Binary file modified graphics/json_ref/candlescaled.json.zip
Binary file not shown.
Binary file modified graphics/json_ref/canvas.json.zip
Binary file not shown.
Binary file modified graphics/json_ref/chi2test.json.zip
Binary file not shown.
Binary file modified graphics/json_ref/compile.json.zip
Binary file not shown.
Binary file modified graphics/json_ref/crown.json.zip
Binary file not shown.
Binary file modified graphics/json_ref/ellipse.json.zip
Binary file not shown.
Binary file modified graphics/json_ref/eval.json.zip
Binary file not shown.
Binary file modified graphics/json_ref/event.json.zip
Binary file not shown.
Binary file modified graphics/json_ref/exclusiongraph.json.zip
Binary file not shown.
Binary file modified graphics/json_ref/exclusiongraph2.json.zip
Binary file not shown.
Binary file modified graphics/json_ref/feynman.json.zip
Binary file not shown.
Binary file modified graphics/json_ref/fillhistosauto2p.json.zip
Binary file not shown.
Binary file modified graphics/json_ref/fillrandom.json.zip
Binary file not shown.
Binary file modified graphics/json_ref/first.json.zip
Binary file not shown.
Binary file modified graphics/json_ref/formula1.json.zip
Binary file not shown.
Binary file modified graphics/json_ref/framework.json.zip
Binary file not shown.
Binary file modified graphics/json_ref/gaussian_ratio_plot.json.zip
Binary file not shown.
Binary file modified graphics/json_ref/gaxis.json.zip
Binary file not shown.
Binary file modified graphics/json_ref/gaxis3.json.zip
Binary file not shown.
Binary file modified graphics/json_ref/gerrors.json.zip
Binary file not shown.
Binary file modified graphics/json_ref/gerrors2.json.zip
Binary file not shown.
Binary file modified graphics/json_ref/gmultierrors.json.zip
Binary file not shown.
Binary file modified graphics/json_ref/graph.json.zip
Binary file not shown.
Binary file modified graphics/json_ref/graph2derrorsfit.json.zip
Binary file not shown.
Binary file modified graphics/json_ref/graphApply.json.zip
Binary file not shown.
Binary file modified graphics/json_ref/graphShade.json.zip
Binary file not shown.
Binary file modified graphics/json_ref/graphpolar.json.zip
Binary file not shown.
Binary file modified graphics/json_ref/graphpolar2.json.zip
Binary file not shown.
Binary file modified graphics/json_ref/graphpolar3.json.zip
Binary file not shown.
Binary file modified graphics/json_ref/graphreverse.json.zip
Binary file not shown.
Binary file modified graphics/json_ref/greyscale.json.zip
Binary file not shown.
Binary file modified graphics/json_ref/h2_cut.json.zip
Binary file not shown.
Binary file modified graphics/json_ref/h2proj.json.zip
Binary file not shown.
Binary file modified graphics/json_ref/histpalettecolor.json.zip
Binary file not shown.
Binary file modified graphics/json_ref/hksimple.json.zip
Binary file not shown.
Binary file modified graphics/json_ref/hlGraph1.json.zip
Binary file not shown.
Binary file modified graphics/json_ref/hlHisto1.json.zip
Binary file not shown.
Binary file modified graphics/json_ref/hlHisto2.json.zip
Binary file not shown.
Binary file removed graphics/json_ref/hlHisto4.json.zip
Binary file not shown.
Binary file modified graphics/json_ref/hlabels1.json.zip
Binary file not shown.
Binary file modified graphics/json_ref/hlquantiles.json.zip
Binary file not shown.
Binary file modified graphics/json_ref/hstack.json.zip
Binary file not shown.
Binary file modified graphics/json_ref/labels1.json.zip
Binary file not shown.
Binary file modified graphics/json_ref/labels2.json.zip
Binary file not shown.
Binary file modified graphics/json_ref/latex.json.zip
Binary file not shown.
Binary file modified graphics/json_ref/latex2.json.zip
Binary file not shown.
Binary file modified graphics/json_ref/latex3.json.zip
Binary file not shown.
Binary file modified graphics/json_ref/latex4.json.zip
Binary file not shown.
Binary file modified graphics/json_ref/latex5.json.zip
Binary file not shown.
Binary file modified graphics/json_ref/legendautoplaced.json.zip
Binary file not shown.
Binary file modified graphics/json_ref/logscales.json.zip
Binary file not shown.
Binary file modified graphics/json_ref/markerwarning.json.zip
Binary file not shown.
Binary file modified graphics/json_ref/mass_spectrum.json.zip
Binary file not shown.
Binary file modified graphics/json_ref/mathBeta.json.zip
Binary file not shown.
Binary file modified graphics/json_ref/mathGammaNormal.json.zip
Binary file not shown.
Binary file modified graphics/json_ref/mathLaplace.json.zip
Binary file not shown.
Binary file modified graphics/json_ref/mathStudent.json.zip
Binary file not shown.
Binary file modified graphics/json_ref/mathcoreCDF.json.zip
Binary file not shown.
Binary file modified graphics/json_ref/mathcoreStatFunc.json.zip
Binary file not shown.
Binary file modified graphics/json_ref/movepalette.json.zip
Binary file not shown.
Binary file modified graphics/json_ref/multicolor.json.zip
Binary file not shown.
Binary file modified graphics/json_ref/multigraph.json.zip
Binary file not shown.
Binary file modified graphics/json_ref/normalDist.json.zip
Binary file not shown.
Binary file modified graphics/json_ref/pavetext.json.zip
Binary file not shown.
Binary file modified graphics/json_ref/piechart.json.zip
Binary file not shown.
Binary file modified graphics/json_ref/quantiles.json.zip
Binary file not shown.
Binary file modified graphics/json_ref/quarks.json.zip
Binary file not shown.
Binary file modified graphics/json_ref/ratioplot1.json.zip
Binary file not shown.
Binary file modified graphics/json_ref/ratioplot2.json.zip
Binary file not shown.
Binary file modified graphics/json_ref/ratioplot3.json.zip
Binary file not shown.
Binary file modified graphics/json_ref/ratioplot4.json.zip
Binary file not shown.
Binary file modified graphics/json_ref/ratioplot5.json.zip
Binary file not shown.
Binary file modified graphics/json_ref/ratioplot6.json.zip
Binary file not shown.
Binary file modified graphics/json_ref/ratioplotOld.json.zip
Binary file not shown.
Binary file modified graphics/json_ref/rebin.json.zip
Binary file not shown.
Binary file modified graphics/json_ref/reverseaxis.json.zip
Binary file not shown.
Binary file modified graphics/json_ref/scatter.json.zip
Binary file not shown.
Binary file modified graphics/json_ref/schroedinger_hydrogen.json.zip
Binary file not shown.
Binary file removed graphics/json_ref/statsEditing.json.zip
Binary file not shown.
Binary file modified graphics/json_ref/surfaces.json.zip
Binary file not shown.
Binary file modified graphics/json_ref/testSmooth.json.zip
Binary file not shown.
Binary file modified graphics/json_ref/th2polyBoxes.json.zip
Binary file not shown.
Binary file modified graphics/json_ref/th2polyEurope.json.zip
Binary file not shown.
Binary file modified graphics/json_ref/th2polyHoneycomb.json.zip
Binary file not shown.
Binary file modified graphics/json_ref/th2polyUSA.json.zip
Binary file not shown.
Binary file modified graphics/json_ref/timeonaxis.json.zip
Binary file not shown.
Binary file modified graphics/json_ref/timeonaxis2.json.zip
Binary file not shown.
Binary file modified graphics/json_ref/timeonaxis3.json.zip
Binary file not shown.
Binary file modified graphics/json_ref/tmathtext.json.zip
Binary file not shown.
Binary file modified graphics/json_ref/tmathtext2.json.zip
Binary file not shown.
Binary file removed graphics/json_ref/transpad.json.zip
Binary file not shown.
Binary file modified graphics/json_ref/transparency.json.zip
Binary file not shown.
Binary file modified graphics/json_ref/triangles.json.zip
Binary file not shown.
Binary file modified graphics/json_ref/twoscales.json.zip
Binary file not shown.
Binary file modified graphics/json_ref/vavilov.json.zip
Binary file not shown.
Binary file modified graphics/json_ref/waves.json.zip
Binary file not shown.
Binary file modified graphics/json_ref/xyplot.json.zip
Binary file not shown.
Binary file modified graphics/json_ref/zdemo.json.zip
Binary file not shown.
Binary file modified graphics/json_ref/zones.json.zip
Binary file not shown.
137 changes: 73 additions & 64 deletions graphics/testGraphics.C
Original file line number Diff line number Diff line change
Expand Up @@ -21,55 +21,18 @@
#include "TLatex.h"
#include <TSystem.h>

#include <string>
#include <fstream>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <cstdio>
#include <cstdlib>
#include <fstream>
#include <iostream>
#include <regex>
#include <stdexcept>
#include <string>
#include <sstream>
#include <tuple>

// FUNCTION DECLARATIONS

// JSON Preprocessing
std::string preprocessJSONContent(const std::string& jsonString);

// JSON Comparison
bool compare_json(const TString& jsonOutput, const std::string& ref_filename, const std::string& macroName);

// JSON Test
int test_json(TCanvas* c1, const std::string& macroName, const std::string& builddir);

// File Content Reading
std::string readFileToString(const std::string& filePath);

// SVG Preprocessing
std::string preprocessSVGContent(const std::string& svgContent);

// SVG Comparison
bool compareSVGFiles(const std::string& filePath1, const std::string& filePath2);

// SVG Test
int test_svg(TCanvas* c1, const std::string& macroName, const std::string& builddir);

// PDF Preprocessing
std::string preprocessPDFContent(const std::string& pdfString);

// PDF Comparison
bool comparePDFFiles(const std::string& filePath1, const std::string& filePath2);

// PDF Test
int test_pdf(TCanvas* c1, const std::string& macroName, const std::string& builddir);

// Root Test
int testGraphics(const std::string& macroName, const std::string& test_type, const std::string& macro_folder, const std::string& builddir);

// MAIN FUNCTION
int main(int argc, char** argv);

// FUNCTION DEFINITIONS
//---------------------HELPER--------------------------------------------------------------
// Function to read file content into a string
std::string readFileToString(const std::string& filePath) {
Expand All @@ -82,6 +45,39 @@ std::string readFileToString(const std::string& filePath) {
return buffer.str();
}

std::vector<std::string> splitString(const std::string &str, const char delimiter = '\n')
{
auto lines = std::vector<std::string>{};
lines.reserve(128);
auto strAsStream = std::stringstream{str};

for (std::string line; std::getline(strAsStream, line, delimiter);) {
lines.emplace_back(line);
}

return lines;
}

void printSideBySide(const std::string &str1, const std::string &str2)
{
auto lines1 = splitString(str1);
auto lines2 = splitString(str2);
unsigned int idx1 = 0;
unsigned int idx2 = 0;
for (auto [idx1, idx2] = std::tuple<unsigned int, unsigned int>{0, 0};
idx1 != lines1.size() || idx2 != lines2.size();) {
auto &line1 = lines1[idx1];
auto &line2 = lines2[idx2];
if (line1 != line2) {
std::cout << idx1 << ", " << idx2 << ": " << line1 << " <-> " << line2 << std::endl;
}
if (idx1 < lines1.size())
++idx1;
if (idx2 < lines2.size())
++idx2;
}
}

//---------------------JSON----------------------------------------------------------------
std::string preprocessJSONContent(const std::string& jsonString) {
std::string result = jsonString;
Expand Down Expand Up @@ -122,7 +118,10 @@ bool compare_json(const TString& jsonOutput, const std::string& ref_filename, co
std::cerr << "Length of produced JSON after adjustments: " << jsonOutput.Length() << std::endl;
std::cerr << "Length of reference JSON after adjustments: " << refBuffer.str().length() << std::endl;

return produced_json == reference_json;
const auto areEqual = produced_json == reference_json;
if (!areEqual) printSideBySide(produced_json, reference_json);

return areEqual;
}

int test_json(TCanvas* c1, const std::string& macroName, const std::string& builddir) {
Expand All @@ -133,31 +132,36 @@ int test_json(TCanvas* c1, const std::string& macroName, const std::string& buil
std::string ref_filename = "./json_ref/" + macroName + ".json";
std::string jsonFilePath = builddir + "/json_pro/" + macroName + "_pro.json";

// Save generated Json file
std::ofstream jsonFile(jsonFilePath);
if (jsonFile.is_open()) {
jsonFile << jsonOutput.Data();
jsonFile.close();
FileStat_t fstat;
if (1 == gSystem->GetPathInfo(ref_filename.c_str(), fstat)) {
std::cout << "Reference JSON file not found. Saving generated JSON file as reference." << std::endl;
// Save the generated JSON file as reference
std::ofstream jsonFile(ref_filename);
if (jsonFile.is_open()) {
jsonFile << jsonOutput.Data();
jsonFile.close();
return 1;
} else {
std::cerr << "Error: Unable to open file for writing: " << ref_filename << std::endl;
return 1;
}
} else {
std::cerr << "Error: Unable to open file for writing" << std::endl;
return 1;
// Save the generated JSON file
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this part:it would simply write confusing output disguised as references.

std::ofstream jsonFile(jsonFilePath);
if (jsonFile.is_open()) {
jsonFile << jsonOutput.Data();
jsonFile.close();
} else {
std::cerr << "Error: Unable to open file for writing: " << jsonFilePath << std::endl;
return 1;
}
}

// Compare the created JSON to the reference JSON
if (compare_json(jsonOutput, ref_filename, macroName)) {
std::cout << "JSON test passed for " << macroName << std::endl;
} else {
std::cerr << "JSON test failed for " << macroName << std::endl;

// // Overwrite the reference JSON file with the produced one
// std::ofstream refFile(ref_filename);
// if (refFile.is_open()) {
// refFile << jsonOutput.Data();
// refFile.close();
// std::cerr << "Reference JSON file updated for " << macroName << std::endl;
// } else {
// std::cerr << "Error: Unable to open reference file for writing" << std::endl;
// }
return 1;
}
return 0;
Expand Down Expand Up @@ -192,7 +196,10 @@ bool compareSVGFiles(const std::string& filePath1, const std::string& filePath2)
std::cerr << "Length of produced SVG after adjustments: " << content1.length() << std::endl;
std::cerr << "Length of reference SVG after adjustments: " << content2.length() << std::endl;

return content1 == content2;
const auto areEqual = content1 == content2;
if (!areEqual) printSideBySide(content1, content2);

return areEqual;

} catch (const std::exception& e) {
std::cerr << "Error: " << e.what() << std::endl;
Expand Down Expand Up @@ -250,7 +257,6 @@ bool comparePDFFiles(const std::string& filePath1, const std::string& filePath2)
try {
std::string content1 = readFileToString(filePath1);
std::string content2 = readFileToString(filePath2);
//std::cout << content1 << std::endl;

content1 = preprocessPDFContent(content1);
content2 = preprocessPDFContent(content2);
Expand All @@ -259,7 +265,10 @@ bool comparePDFFiles(const std::string& filePath1, const std::string& filePath2)
std::cerr << "Length of produced PDF after adjustments: " << content1.length() << std::endl;
std::cerr << "Length of reference PDF after adjustments: " << content2.length() << std::endl;

return content1 == content2;
const auto areEqual = content1 == content2;
if (!areEqual) printSideBySide(content1, content2);

return areEqual;

} catch (const std::exception& e) {
std::cerr << "Error: " << e.what() << std::endl;
Expand Down