Commit 77c50b69 authored by Jan Uhlík's avatar Jan Uhlík Committed by Ing. Jan Trávníček

Initial commit of the new graph algorithms.

parent 45d05ad8
This diff is collapsed.
-include makefile.conf
-include ../build.conf
-include ../makefile-library
LIBRARY:=alib2graph_algo
TESTBIN:=alib2test
LINK_LIBRARIES=alib2graph_data alib2xml alib2common alib2abstraction alib2measure alib2std
SYSTEM_LIBRARIES=xml2
SYSTEM_INCLUDE_PATHS=/usr/include/libxml2
TEST_LINK_LIBRARIES=alib2str
TEST_SYSTEM_LIBRARIES=
TEST_SYSTEM_INCLUDE_PATHS=
#include <tclap/CmdLine.h>
#include <cppunit/CompilerOutputter.h>
#include <cppunit/extensions/TestFactoryRegistry.h>
#include <cppunit/ui/text/TestRunner.h>
#include <cppunit/TestResultCollector.h>
#include <cppunit/TestResult.h>
#include <cppunit/XmlOutputter.h>
#include <cppunit/TestFailure.h>
#include <cppunit/SourceLine.h>
#include <cppunit/Exception.h>
#include <exception/CommonException.h>
CPPUNIT_NS_BEGIN
class CPPUNIT_API TestProgressListener : public TestListener {
public:
TestProgressListener();
virtual ~TestProgressListener();
void startTest(Test *test);
void addFailure(const TestFailure &failure);
void endTest(Test *test);
int getResult() const;
void printResults() const;
private:
TestProgressListener(const TestProgressListener &copy);
void operator=(const TestProgressListener &copy);
private:
int m_Failures;
int m_Tests;
int m_Assertions;
bool m_lastTestFailed;
};
TestProgressListener::TestProgressListener() : m_Failures(0), m_Tests(0), m_Assertions(0), m_lastTestFailed(false) {
}
TestProgressListener::~TestProgressListener() {
}
void TestProgressListener::startTest(Test *test) {
stdCOut() << test->getName() << ":" << "\n";
stdCOut().flush();
m_lastTestFailed = false;
m_Tests++;
}
void TestProgressListener::addFailure(const TestFailure &failure) {
stdCOut() << (failure.isError() ? "error" : "assertion") << " : " << failure.failedTestName() << " : "
<< failure.sourceLine().lineNumber() << "\n";
stdCOut() << "Exception " << failure.thrownException()->message().details();
m_lastTestFailed = true;
if (failure.isError()) m_Failures++; else m_Assertions++;
}
void TestProgressListener::endTest(Test *test) {
stdCOut() << "Result (" << test->getName() << ")";
stdCOut().flush();
if (!m_lastTestFailed)
stdCOut() << " : OK";
else
stdCOut() << " : Fail";
stdCOut() << "\n\n";
}
int TestProgressListener::getResult() const {
return m_Failures + m_Assertions;
}
void TestProgressListener::printResults() const {
stdCOut() << "Overal result: Tests: " << m_Tests << " Assertions: " << m_Assertions << " Failures: " << m_Failures
<< "\n";
}
CPPUNIT_NS_END
int main(int argc, char *argv[]) {
try {
TCLAP::CmdLine cmd("Main test binary.", ' ', "0.01");
TCLAP::MultiArg<std::string> testPathSegments("p", "path", "test path", false, "string");
cmd.add(testPathSegments);
cmd.parse(argc, argv);
CppUnit::TestResult controller;
CppUnit::TestResultCollector result;
controller.addListener(&result);
CppUnit::TestProgressListener progressListener;
controller.addListener(&progressListener);
CppUnit::Test *suite = NULL;
std::string testPath = "";
if (testPathSegments.getValue().size() == 0) {
// Get the top level suite from the registry
suite = CppUnit::TestFactoryRegistry::getRegistry().makeTest();
} else if (testPathSegments.getValue().size() == 1) {
suite = CppUnit::TestFactoryRegistry::getRegistry(testPathSegments.getValue()[0]).makeTest();
} else {
suite = CppUnit::TestFactoryRegistry::getRegistry(testPathSegments.getValue()[0]).makeTest();
bool first = true;
for (const std::string &path : testPathSegments.getValue()) {
if (first) {
first = false;
continue;
}
testPath += path + "/";
}
testPath.pop_back();
}
// Adds the test to the list of test to run
CppUnit::TextUi::TestRunner runner;
runner.addTest(suite);
// Change the default outputter to a compiler error format outputter
runner.setOutputter(new CppUnit::CompilerOutputter(&runner.result(), std::cerr));
// Run the tests.
runner.run(controller, testPath);
progressListener.printResults();
std::ofstream xmlFileResults("CppUnitTestResults.xml");
CppUnit::XmlOutputter xmlOut(&result, xmlFileResults);
xmlOut.write();
return progressListener.getResult();
} catch (const exception::CommonException &exception) {
std::cerr << exception.getCause() << std::endl;
return 1;
} catch (const TCLAP::ArgException &exception) {
std::cerr << exception.error() << std::endl;
return 2;
} catch (const std::exception &exception) {
std::cerr << "Exception caught: " << exception.what() << std::endl;
return 3;
} catch (...) {
std::cerr << "Unknown exception caught." << std::endl;
return 127;
}
}
EXECUTABLE:=aql2
LINK_LIBRARIES=alib2elgo alib2algo alib2aux alib2raw_cli_integration alib2raw alib2str_cli_integration alib2str alib2graph_data alib2data alib2dummy alib2cli alib2xml alib2common alib2abstraction alib2measure alib2std
LINK_LIBRARIES=alib2elgo alib2graph_algo alib2algo alib2aux alib2raw_cli_integration alib2raw alib2str_cli_integration alib2str alib2graph_data alib2data alib2dummy alib2cli alib2xml alib2common alib2abstraction alib2measure alib2std
SYSTEM_LIBRARIES=xml2 readline
SYSTEM_INCLUDE_PATHS=/usr/include/libxml2
......@@ -37,6 +37,7 @@ SUBDIRS_LIBS = alib2std \
alib2algo_experimental \
alib2elgo \
alib2graph_data \
alib2graph_algo \
SUBDIRS_BINS = aecho2 \
aarbology2 \
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment