///////////////////////////////////////////////////////////////////////////////// // // Copyright (C) 2011-2012 Statoil ASA, Ceetron AS // // ResInsight is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY // WARRANTY; without even the implied warranty of MERCHANTABILITY or // FITNESS FOR A PARTICULAR PURPOSE. // // See the GNU General Public License at // for more details. // ///////////////////////////////////////////////////////////////////////////////// #include "RiaImageCompareReporter.h" #include #include #include RiaImageCompareReporter::RiaImageCompareReporter(void) { m_showOriginal = true; m_showGenerated = true; m_showInteractiveDiff = false; } RiaImageCompareReporter::~RiaImageCompareReporter(void) { } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void RiaImageCompareReporter::addImageDirectoryComparisonSet(const std::string& title, const std::string& baseImageDir, const std::string& newImagesDir, const std::string& diffImagesDir) { m_directorySets.push_back(DirSet(title, baseImageDir, newImagesDir, diffImagesDir)); } std::string removeCommonStart(const std::string& mask, const std::string& filename) { size_t i; for (i = 0; i < mask.size() && i < filename.size(); ++i) { if (mask[i] != filename[i]) break; } return filename.substr(i); } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void RiaImageCompareReporter::generateHTMLReport(const std::string& fileName) { if (m_directorySets.size() == 0) return; std::ofstream output(fileName.c_str()); if (!output) { std::cout << "Trouble opening test report file: " << fileName; return; } std::string html; html += "\n"; html += "\n"; html += "Regression-Test Report\n"; if (m_showInteractiveDiff) { html += cssString(); } html += "\n"; html += "\n"; html += "\n"; html += "\n"; for (size_t dsIdx = 0; dsIdx < m_directorySets.size(); ++dsIdx) { std::vector baseImageNames = getPngFilesInDirectory(m_directorySets[dsIdx].m_baseImageDir); html += "\n"; html += " \n"; html += " \n"; html += " \n"; std::string baseImageFolder = removeCommonStart(fileName, m_directorySets[dsIdx].m_baseImageDir ); std::string genImageFolder = removeCommonStart(fileName, m_directorySets[dsIdx].m_newImagesDir ); std::string diffImageFolder = removeCommonStart(fileName, m_directorySets[dsIdx].m_diffImagesDir); for (size_t fIdx = 0; fIdx < baseImageNames.size(); ++fIdx) { html += " \n"; html += " \n"; html += " \n"; html += " \n"; if (m_showOriginal) { html += " \n"; } if (m_showGenerated) { html += " \n"; } if (m_showInteractiveDiff) { html += " \n"; } html += " \n"; html += " \n"; // A little air between images html += " \n"; } html += "
" + m_directorySets[dsIdx].m_title + "
" + baseImageNames[fIdx] + "
\"" \""
\""
\n"; html += "\n"; } output << html; } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void RiaImageCompareReporter::showInteractiveOnly() { m_showOriginal = false; m_showGenerated = false; m_showInteractiveDiff = true; } //-------------------------------------------------------------------------------------------------- /// Retuns the names of the *.png files in a directory. The names are without path, but with extention //-------------------------------------------------------------------------------------------------- std::vector RiaImageCompareReporter::getPngFilesInDirectory(const std::string& searchPath) { QDir searchDir(QString::fromStdString(searchPath)); searchDir.setFilter(QDir::Files); //QStringList filter; //filter.append("*.png"); //searchDir.setNameFilters(filter); QStringList imageFiles = searchDir.entryList(); std::vector fileNames; for (int i = 0; i < imageFiles.size(); ++i) { fileNames.push_back(imageFiles[i].toStdString()); } return fileNames; } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- std::string RiaImageCompareReporter::cssString() const { std::string html; html += ""; return html; }