// TestFramework.cc - // // // // #include "ErrorLogger/ELadministrator.h" #include "ErrorLogger/ELdestControl.h" #include "ErrorLogger/ELoutput.h" #include "ErrorLogger/ELstatistics.h" ZM_USING_NAMESPACE( zmel ) #include "ZMutility/iostream" USING( std::cout ) #include USING( std::string ) #include "TestFramework.h" #include "SampleEvent.h" #include "TestModule.h" #include "TestModuleA.h" #include "ZMutility/sstream" USING( std::ostringstream ) TestFramework::RunEventContext::RunEventContext( TestFramework &ff) : f(ff) { } ZM_COVARIANT_TYPE(ELcontextSupplier *, TestFramework::RunEventContext *) TestFramework::RunEventContext::clone() const { return new TestFramework::RunEventContext(*this); } // $$ 12:6 string TestFramework::RunEventContext::context() const{ ostringstream ev; ev << "\nRun " << f.getRun() << "; Event " << f.getEvent(); return ev.str(); } string TestFramework::RunEventContext::summaryContext() const{ // $$ 12:1 ostringstream ev; ev << f.getRun() << "/" << f.getEvent(); return ev.str(); } string TestFramework::RunEventContext::fullContext() const{ // $$ 12:2 ostringstream ev; ev << "\nExecuting event " << f.getEvent() << " of run number " << f.getRun() << "."; return ev.str(); } int main() { TestFramework framework; framework.setup(); framework.eventLoop(); return 0; } TestFramework::TestFramework():reContext(*this) { step = new TestModuleA(); } TestFramework::~TestFramework(){ delete step; } void TestFramework::setup(){ logger = ELadministrator::instance(); logger->setProcess(" Something "); logger->setContextSupplier( reContext ); logger->setAbortThreshold( ELhighestSeverity ); // $$ 14:2 logfile = logger->attach(ELoutput("Test.log")); logfile.suppressContext(); // $$ 24:5 logfile.setThreshold (ELzeroSeverity); part1log = logger->attach(ELoutput("part1.log")); part1log.useFullContext(); // $$ 24:6 part1log.setThreshold (ELsuccess); output = logger->attach(ELoutput(cout)); output.suppressTime(); // $$ 24:1 output.suppressModule(); // $$ 24:2 output.setThreshold (ELwarning); stats = logger->attach(ELstatistics (cout)); // $$ 9:13 stats.setThreshold (ELsuccess); // $$ 15:7 } void TestFramework::eventLoop(){ Event event; event.datum = 0; Events = 1; Runs = 1; errlog << "Initial ErrorLog"; // $$ 3:2 //Initial ErrorLog will have "unspecified" severity // because it is not in the form ErrorLog(sev,ID) //starting new ErrorLog without ending previous one errlog(ELsuccess, "Testing with specified severity & ID"); errlog << "initial datum= " << event.datum << endmsg; for (; Events <= 120; Events++){ step->invoke(event); if (Events%25==0){ stats.summary(logfile); // $$ 15:3 stats.summary(output); // $$ 15:4 stats.summary(part1log, "ELoutput puts up 40 characters of this title in the first line of the summary output."); // $$ 15:5 } } part1log.setThreshold(ELhighestSeverity); // $$ 9:4 stats.clearSummary(); // $$ 16:1 Runs = 2; for (Events=121; Events<=150; Events++) step->invoke(event); errlog(ELunspecified, "Information") << "***" << logger->severityCount(ELerror) << " Errors***"; // $$ 18:1 errlog(ELunspecified, "Information") << "***" << logger->severityCount(ELerror,ELunspecified) // $$ 18:2 << " Errors+Unspecifieds***" << endmsg; errlog(ELincidental, "Almost finished"); //this goes along with $$ 15:7 errlog(ELsuccess, "Finished Module"); //errlog not terminated $$ 3:3 //One final summary is sent to cout //because the threshold of stats is //ELsuccess and the last errlogs //will alter the information in stats $$ 15:6 } int TestFramework::getRun(){ return Runs; } int TestFramework::getEvent(){ return Events; } #include "TestModule.cc" #include "TestModuleA.cc"