From 511b0c9661c44da9670153127178d11eb359907b Mon Sep 17 00:00:00 2001 From: Andy Cedilnik Date: Fri, 8 Aug 2003 18:28:03 -0400 Subject: [PATCH] ENH: Add regression images support --- Source/cmCTest.cxx | 149 ++++++++++++++++++++++++++++++++++++++++++--- Source/cmCTest.h | 5 +- 2 files changed, 146 insertions(+), 8 deletions(-) diff --git a/Source/cmCTest.cxx b/Source/cmCTest.cxx index 37a0420b0..8624d887c 100644 --- a/Source/cmCTest.cxx +++ b/Source/cmCTest.cxx @@ -1632,10 +1632,12 @@ void cmCTest::ProcessDirectory(std::vector &passed, int firstTest = 1; long line = 0; + +#define SPACE_REGEX "[ \t\r\n]" cmsys::RegularExpression ireg(this->m_IncludeRegExp.c_str()); cmsys::RegularExpression ereg(this->m_ExcludeRegExp.c_str()); - cmsys::RegularExpression dartStuff("([\t\n ]*[\t ]*[\n]*)"); + cmsys::RegularExpression dartStuff("()"); bool parseError; while ( fin ) @@ -1756,8 +1758,9 @@ void cmCTest::ProcessDirectory(std::vector &passed, { if (dartStuff.find(output.c_str())) { - cmSystemTools::ReplaceString(output, - dartStuff.match(1).c_str(),""); + std::string res = dartStuff.match(1); + cmSystemTools::ReplaceString(output, res.c_str(),""); + cres.m_RegressionImages = this->GenerateRegressionImages(res); } if (output != "" && m_Verbose) { @@ -1771,10 +1774,12 @@ void cmCTest::ProcessDirectory(std::vector &passed, fprintf(stderr," Passed\n"); if (output != "") { + std::cout << "Before dart check" << std::endl; if (dartStuff.find(output.c_str())) { - cmSystemTools::ReplaceString(output, - dartStuff.match(1).c_str(),""); + std::string res = dartStuff.match(1); + cmSystemTools::ReplaceString(output, res.c_str(),""); + cres.m_RegressionImages = this->GenerateRegressionImages(res); } if (output != "" && m_Verbose) { @@ -1855,7 +1860,7 @@ int cmCTest::TestDirectory() std::cerr << "Cannot create testing XML file" << std::endl; return 1; } - this->GenerateDartOutput(ofs); + this->GenerateDartTestOutput(ofs); } return int(failed.size()); @@ -1983,7 +1988,7 @@ std::string cmCTest::GetSubmitResultsPrefix() return name; } -void cmCTest::GenerateDartOutput(std::ostream& os) +void cmCTest::GenerateDartTestOutput(std::ostream& os) { if ( !m_DartMode ) { @@ -2026,6 +2031,7 @@ void cmCTest::GenerateDartOutput(std::ostream& os) << "CHILDSTATUS" << "\n" << "\t\t\t" << result->m_ReturnValue << "" << std::endl; + os << result->m_RegressionImages; } os << "\t\t\t" @@ -2116,6 +2122,135 @@ std::string cmCTest::GetTestModelString() return "Experimental"; } +std::string cmCTest::GenerateRegressionImages(const std::string& xml) +{ + cmsys::RegularExpression twoattributes( + "([^<]*)"); + cmsys::RegularExpression threeattributes( + "([^<]*)"); + cmsys::RegularExpression fourattributes( + "([^<]*)"); + cmsys::RegularExpression measurementfile( + "([^<]*)"); + + cmOStringStream ostr; + bool done = false; + std::string cxml = xml; + while ( ! done ) + { + if ( twoattributes.find(cxml) ) + { + ostr + << "\t\t\t" << twoattributes.match(5) + << "" + << std::endl; + cxml.erase(twoattributes.start(), twoattributes.end() - twoattributes.start()); + } + else if ( threeattributes.find(cxml) ) + { + ostr + << "\t\t\t" << threeattributes.match(7) + << "" + << std::endl; + cxml.erase(threeattributes.start(), threeattributes.end() - threeattributes.start()); + } + else if ( fourattributes.find(cxml) ) + { + ostr + << "\t\t\t" << fourattributes.match(9) + << "" + << std::endl; + cxml.erase(fourattributes.start(), fourattributes.end() - fourattributes.start()); + } + else if ( measurementfile.find(cxml) ) + { + const std::string& filename = measurementfile.match(5); + if ( cmSystemTools::FileExists(filename.c_str()) ) + { + long len = cmSystemTools::FileLength(filename.c_str()); + std::ifstream ifs(filename.c_str(), std::ios::in +#ifdef _WIN32 + | std::ios::binary +#endif + ); + unsigned char *file_buffer = new unsigned char [ len + 1 ]; + ifs.read(reinterpret_cast(file_buffer), len); + unsigned char *encoded_buffer = new unsigned char [ static_cast(len * 1.5 + 1) ]; + + unsigned long rlen = cmsysBase64_Encode(file_buffer, len, encoded_buffer, 1); + unsigned long cc; + + ostr + << "\t\t\t" << std::endl << "\t\t\t\t"; + for ( cc = 0; cc < rlen; cc ++ ) + { + ostr << encoded_buffer[cc]; + if ( cc % 60 == 0 && cc ) + { + ostr << std::endl; + } + } + ostr + << "" << std::endl << "\t\t\t" + << std::endl; + delete [] file_buffer; + delete [] encoded_buffer; + } + else + { + int idx = 4; + if ( measurementfile.match(1) == "name" ) + { + idx = 2; + } + ostr + << "\t\t\tFile " << filename << " not found" + << std::endl; + } + cxml.erase(measurementfile.start(), measurementfile.end() - measurementfile.start()); + } + else + { + done = true; + } + } + return ostr.str(); +} + bool cmCTest::RunMakeCommand(const char* command, std::string* output, int* retVal, const char* dir, bool verbose, int timeout, std::ofstream& ofs) { diff --git a/Source/cmCTest.h b/Source/cmCTest.h index e70983c23..fe26f5b60 100644 --- a/Source/cmCTest.h +++ b/Source/cmCTest.h @@ -150,6 +150,7 @@ private: int m_ReturnValue; std::string m_CompletionStatus; std::string m_Output; + std::string m_RegressionImages; }; struct cmCTestBuildErrorWarning @@ -215,7 +216,7 @@ private: /** * Generate the Dart compatible output */ - void GenerateDartOutput(std::ostream& os); + void GenerateDartTestOutput(std::ostream& os); void GenerateDartBuildOutput(std::ostream& os, std::vector); @@ -226,6 +227,8 @@ private: bool RunMakeCommand(const char* command, std::string* output, int* retVal, const char* dir, bool verbose, int timeout, std::ofstream& ofs); + + std::string GenerateRegressionImages(const std::string& xml); }; #endif