00001 #include "SummaryManager.h"
00002 #include "SummaryWriter.h"
00003 #include "SctData/TestResult.h"
00004 #include "Sct/SctNames.h"
00005 #include "Sct/IoExceptions.h"
00006 #include "Sct/LogicErrors.h"
00007 #include <sstream>
00008 #include <iomanip>
00009 #include <cstdlib>
00010 #include <boost/date_time/posix_time/posix_time.hpp>
00011
00012 using namespace Sct;
00013 using namespace boost;
00014 using namespace std;
00015
00016 namespace SctData {
00017 namespace TestSummary{
00018 using boost::shared_ptr;
00019
00020 SummaryManager::SummaryManager() {}
00021
00022 SummaryManager::~SummaryManager() {}
00023
00024 SummaryManager& SummaryManager::instance() throw () {
00025 static SummaryManager bertha;
00026 return bertha;
00027 }
00028
00029 string SummaryManager::write(const TestResult& t) throw(IoError, LogicError) {
00030 ostringstream oss;
00031 write(t, oss);
00032 return oss.str();
00033 }
00034
00035 void SummaryManager::write(const TestResult& t, ostream& stream) throw(IoError, LogicError) {
00036 shared_ptr<const SummaryWriter> writer = getWriter(t.getClassName());
00037 writer->writeHeader(t, stream);
00038 writer->write(t, stream);
00039 }
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051 shared_ptr<const SummaryWriter> SummaryManager::getWriter(const string& classname) const throw(Sct::LogicError) {
00052 WriterMap::const_iterator it = theMap.find(classname);
00053 if ( it == theMap.end() ){
00054 cerr << "SummaryManager::getWriter no writer for " << classname << endl;
00055 cerr << "known writers:" << endl ;
00056 for (WriterMap::const_iterator it = theMap.begin(); it != theMap.end(); ++it){
00057 cerr << (*it).first << endl;
00058 }
00059 throw InvalidArgumentError( string("SummaryManager::getWriter no writer for ") + classname, __FILE__, __LINE__ );
00060 } else {
00061 return (*it).second ;
00062 }
00063 }
00064
00065 bool SummaryManager::addWriter(const string& testname, shared_ptr<SummaryWriter> writer) throw(Sct::LogicError) {
00066 if (theMap.find(testname) == theMap.end() ){
00067 theMap[testname] = writer;
00068 return true;
00069 }
00070 return false;
00071 }
00072
00073 }
00074 }