90 lines
2.4 KiB
C++
90 lines
2.4 KiB
C++
/*
|
|
* To change this license header, choose License Headers in Project Properties.
|
|
* To change this template file, choose Tools | Templates
|
|
* and open the template in the editor.
|
|
*/
|
|
|
|
/*
|
|
* File: newtestrunner.cpp
|
|
* Author: dev
|
|
*
|
|
* Created on 18.11.2015, 20:41:38
|
|
*/
|
|
|
|
// CppUnit site http://sourceforge.net/projects/cppunit/files
|
|
|
|
#include <cppunit/BriefTestProgressListener.h>
|
|
#include <cppunit/CompilerOutputter.h>
|
|
#include <cppunit/extensions/TestFactoryRegistry.h>
|
|
#include <cppunit/TestResult.h>
|
|
#include <cppunit/TestResultCollector.h>
|
|
#include <cppunit/TestRunner.h>
|
|
|
|
#include <cppunit/Test.h>
|
|
#include <cppunit/TestFailure.h>
|
|
#include <cppunit/portability/Stream.h>
|
|
|
|
class ProgressListener : public CPPUNIT_NS::TestListener {
|
|
public:
|
|
|
|
ProgressListener()
|
|
: m_lastTestFailed(false) {
|
|
}
|
|
|
|
~ProgressListener() {
|
|
}
|
|
|
|
void startTest(CPPUNIT_NS::Test *test) {
|
|
CPPUNIT_NS::stdCOut() << test->getName();
|
|
CPPUNIT_NS::stdCOut() << "\n";
|
|
CPPUNIT_NS::stdCOut().flush();
|
|
|
|
m_lastTestFailed = false;
|
|
}
|
|
|
|
void addFailure(const CPPUNIT_NS::TestFailure &failure) {
|
|
CPPUNIT_NS::stdCOut() << " : " << (failure.isError() ? "error" : "assertion");
|
|
m_lastTestFailed = true;
|
|
}
|
|
|
|
void endTest(CPPUNIT_NS::Test *test) {
|
|
if (!m_lastTestFailed)
|
|
CPPUNIT_NS::stdCOut() << " : OK";
|
|
CPPUNIT_NS::stdCOut() << "\n";
|
|
}
|
|
|
|
private:
|
|
/// Prevents the use of the copy constructor.
|
|
ProgressListener(const ProgressListener ©);
|
|
|
|
/// Prevents the use of the copy operator.
|
|
void operator=(const ProgressListener ©);
|
|
|
|
private:
|
|
bool m_lastTestFailed;
|
|
};
|
|
|
|
int main() {
|
|
// Create the event manager and test controller
|
|
CPPUNIT_NS::TestResult controller;
|
|
|
|
// Add a listener that colllects test result
|
|
CPPUNIT_NS::TestResultCollector result;
|
|
controller.addListener(&result);
|
|
|
|
// Add a listener that print dots as test run.
|
|
ProgressListener progress;
|
|
controller.addListener(&progress);
|
|
|
|
// Add the top suite to the test runner
|
|
CPPUNIT_NS::TestRunner runner;
|
|
runner.addTest(CPPUNIT_NS::TestFactoryRegistry::getRegistry().makeTest());
|
|
runner.run(controller);
|
|
|
|
// Print test in a compiler compatible format.
|
|
CPPUNIT_NS::CompilerOutputter outputter(&result, CPPUNIT_NS::stdCOut());
|
|
outputter.write();
|
|
|
|
return result.wasSuccessful() ? 0 : 1;
|
|
}
|