spectrum2/tests/libtransport/main.cpp

80 lines
2.3 KiB
C++
Raw Permalink Normal View History

2011-08-21 13:41:23 +02:00
#include "main.h"
#include <cppunit/CompilerOutputter.h>
#include <cppunit/extensions/TestFactoryRegistry.h>
#include <cppunit/TestResult.h>
#include <cppunit/TestResultCollector.h>
#include <cppunit/TestRunner.h>
#include <cppunit/BriefTestProgressListener.h>
2012-03-21 16:31:51 +01:00
#ifdef WITH_LOG4CXX
2011-08-25 11:24:03 +02:00
#include "log4cxx/logger.h"
#include "log4cxx/fileappender.h"
#include "log4cxx/patternlayout.h"
#include "log4cxx/propertyconfigurator.h"
2017-06-14 19:40:45 +03:00
using namespace log4cxx;
#endif
2011-08-25 11:24:03 +02:00
#include "transport/protocol.pb.h"
#include "transport/HTTPRequest.h"
2011-08-25 11:24:03 +02:00
2011-08-21 13:41:23 +02:00
int main (int argc, char* argv[])
{
2012-03-21 16:31:51 +01:00
#ifdef WITH_LOG4CXX
2011-08-25 11:24:03 +02:00
LoggerPtr root = Logger::getRootLogger();
2013-02-13 14:49:03 +04:00
#ifndef _MSC_VER
2011-08-25 11:24:03 +02:00
root->addAppender(new FileAppender(new PatternLayout("%d %-5p %c: %m%n"), "libtransport_test.log", false));
2013-02-13 14:49:03 +04:00
#else
root->addAppender(new FileAppender(new PatternLayout(L"%d %-5p %c: %m%n"), L"libtransport_test.log", false));
#endif
2012-03-21 16:31:51 +01:00
#endif
2011-08-25 11:24:03 +02:00
std::vector<std::string> testsToRun;
for (int i = 1; i < argc; ++i) {
std::string param(argv[i]);
testsToRun.push_back(param);
}
if (testsToRun.empty()) {
testsToRun.push_back("");
}
Transport::HTTPRequest::globalInit();
2011-08-21 13:41:23 +02:00
// informs test-listener about testresults
CPPUNIT_NS :: TestResult testresult;
// register listener for collecting the test-results
CPPUNIT_NS :: TestResultCollector collectedresults;
testresult.addListener (&collectedresults);
// register listener for per-test progress output
CPPUNIT_NS :: BriefTestProgressListener progress;
testresult.addListener (&progress);
// insert test-suite at test-runner by registry
CPPUNIT_NS :: TestRunner testrunner;
testrunner.addTest (CPPUNIT_NS :: TestFactoryRegistry :: getRegistry ().makeTest ());
for (std::vector<std::string>::const_iterator i = testsToRun.begin(); i != testsToRun.end(); ++i) {
try {
testrunner.run(testresult, *i);
}
catch (const std::exception& e) {
google::protobuf::ShutdownProtobufLibrary();
Transport::HTTPRequest::globalCleanup();
std::cerr << "Error: " << e.what() << std::endl;
return -1;
}
}
2011-08-21 13:41:23 +02:00
// output results in compiler-format
CPPUNIT_NS :: CompilerOutputter compileroutputter (&collectedresults, std::cerr);
compileroutputter.write ();
google::protobuf::ShutdownProtobufLibrary();
Transport::HTTPRequest::globalCleanup();
2011-08-21 13:41:23 +02:00
// return 0 if tests were successful
return collectedresults.wasSuccessful () ? 0 : 1;
}