diff --git a/alib2elgo/test-src/automaton/simplify/efficient/trimTest.cpp b/alib2elgo/test-src/automaton/simplify/efficient/trimTest.cpp index 45de5928ae2002c52eaa1d7531c77c3509f6d369..3f2ca8754d320abeb6af93ff932b93e199b95a5a 100644 --- a/alib2elgo/test-src/automaton/simplify/efficient/trimTest.cpp +++ b/alib2elgo/test-src/automaton/simplify/efficient/trimTest.cpp @@ -1,20 +1,12 @@ +#include <catch2/catch.hpp> + #include <list> -#include "trimTest.h" #include "automaton/simplify/Trim.h" - #include "automaton/FSM/DFA.h" -CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( trimTest, "automaton" ); -CPPUNIT_TEST_SUITE_REGISTRATION( trimTest ); - -void trimTest::setUp() { -} - -void trimTest::tearDown() { -} -void trimTest::testTrimAutomaton() { +TEST_CASE ( "Trim automaton", "[unit][automaton][elgo]" ) { automaton::DFA < > automaton(DefaultStateType(1)); automaton.addState(DefaultStateType(1)); @@ -31,5 +23,5 @@ void trimTest::testTrimAutomaton() { automaton::DFA < > trimed = automaton::simplify::Trim::trim(automaton); - CPPUNIT_ASSERT(trimed.getStates().size() == 2); + CHECK ( trimed.getStates().size() == 2 ); } diff --git a/alib2elgo/test-src/automaton/simplify/efficient/trimTest.h b/alib2elgo/test-src/automaton/simplify/efficient/trimTest.h deleted file mode 100644 index e885da2a9573778dc76200b6ff6679999a988299..0000000000000000000000000000000000000000 --- a/alib2elgo/test-src/automaton/simplify/efficient/trimTest.h +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef TRIM_TEST_H_ -#define TRIM_TEST_H_ - -#include <cppunit/extensions/HelperMacros.h> - -class trimTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE( trimTest ); - CPPUNIT_TEST( testTrimAutomaton ); - CPPUNIT_TEST_SUITE_END(); - -public: - void setUp(); - void tearDown(); - - void testTrimAutomaton(); -}; - -#endif // TRIM_TEST_H_ diff --git a/alib2elgo/test-src/main.cpp b/alib2elgo/test-src/main.cpp index adb58324a109835bfda91d246781668910521414..4ed06df1f7bea8cc18ee161389b9c3e2741b08a0 100644 --- a/alib2elgo/test-src/main.cpp +++ b/alib2elgo/test-src/main.cpp @@ -1,166 +1,2 @@ -#include <version.hpp> - -#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/Test.h> -#include <cppunit/TestFailure.h> -#include <cppunit/portability/Stream.h> -#include <cppunit/TestListener.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 © ); - - void operator =( const TestProgressListener © ); - -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.", ' ', ALIB_VERSION_INFO); - - 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; - } -} +#define CATCH_CONFIG_MAIN +#include <catch2/catch.hpp>