#include "HTMLTestReporter.h" #ifdef _MSC_VER # pragma warning(disable:4996) // shut the secure crt stuff up, ctime is used correctly here. #endif #include #include #include namespace CppTestHarness { void HTMLTestReporter::ReportFailure(char const* file, int const line, std::string const failure) { std::stringstream msg; msg << file << "(" << line << ") : " << failure; m_failureMessages.push_back(msg.str()); } void HTMLTestReporter::ReportSingleResult(const std::string& testName, bool failed) { ResultRecord r; r.testName = testName; r.failed = failed; //get reported failures and clear temp list r.failureMessages = m_failureMessages; m_failureMessages.clear(); m_results.push_back(r); } void HTMLTestReporter::ReportSummary(int const testCount, int const failureCount) { std::ostream& os = std::cout; //TODO: make all strings html safe os << ""; os << "\n"; os << "\n"; os << " Test Report\n"; os << "\n"; os << "\n"; std::time_t currtime; std::time(&currtime); os << "Test Report: " << std::ctime(&currtime) << "\n"; os << ""; os << testCount << " tests run.\n"; os << failureCount << " failed.\n"; os << ""; os << ""; //for each single test for (ResultList::iterator i = m_results.begin(); i != m_results.end(); ++i) { os << ""; os << "" << i->testName << ""; if (i->failed) os << "FAILED"; else os << "PASSED"; os << ""; if (i->failed) os << ""; for (MessageList::iterator j = i->failureMessages.begin(); j != i->failureMessages.end(); ++j) { os << ""<< *j << "\n"; } if (i->failed) os << ""; os << ""; } os << ""; os << ""; os << ""; } }
"; os << testCount << " tests run.\n"; os << failureCount << " failed.\n"; os << "
"<< *j << "