diff --git a/alib2gui/test-src/ModelBoxTest.cpp b/alib2gui/test-src/ModelBoxTest.cpp index 1cc210309fbd4974d2d61d6e5b2e46cf1ef3ed0a..4aab85c579f4f967612655e67178127d7b3f5deb 100644 --- a/alib2gui/test-src/ModelBoxTest.cpp +++ b/alib2gui/test-src/ModelBoxTest.cpp @@ -1,4 +1,4 @@ -#include "ModelBoxTest.h" +#include <catch2/catch.hpp> #include <Models/InputModelBox.hpp> #include <Models/OutputModelBox.hpp> @@ -6,122 +6,99 @@ #include <Algorithm/Registry.hpp> #include <Utils.hpp> -CPPUNIT_TEST_SUITE_NAMED_REGISTRATION ( ModelBoxTest, "model" ); -CPPUNIT_TEST_SUITE_REGISTRATION ( ModelBoxTest ); - -void ModelBoxTest::setUp ( ) { +TEST_CASE ( "ModelBox", "[unit][gui]" ) { Registry::initialize(); -} -void ModelBoxTest::tearDown ( ) { - Registry::deinitialize(); -} + auto input1 = std::make_unique<InputModelBox>(); + auto input2 = std::make_unique<InputModelBox>(); + auto output1 = std::make_unique<OutputModelBox>(); + auto output2 = std::make_unique<OutputModelBox>(); + auto alg = Registry::getAlgorithm("automaton::determinize::Determinize"); + auto algo = std::make_unique<AlgorithmModelBox>(alg); -void ModelBoxTest::modelBoxBasicProperties ( ) { - auto input = std::make_unique<InputModelBox>(); - auto output = std::make_unique<OutputModelBox>(); - auto algo = std::make_unique<AlgorithmModelBox>(Registry::getAlgorithm("automaton::determinize::Determinize")); + SECTION ( "Basic Properties" ) { + CHECK(input1->getMaxInputCount() == 0); + CHECK(input1->canHaveOutput()); - CPPUNIT_ASSERT(input->getMaxInputCount() == 0); - CPPUNIT_ASSERT(input->canHaveOutput()); + CHECK(output1->getMaxInputCount() == 1); + CHECK(output1->canHaveOutput() == false); - CPPUNIT_ASSERT(output->getMaxInputCount() == 1); - CPPUNIT_ASSERT(output->canHaveOutput() == false); + CHECK(algo->getMaxInputCount() == 1); + CHECK(algo->canHaveOutput()); - CPPUNIT_ASSERT(algo->getMaxInputCount() == 1); - CPPUNIT_ASSERT(algo->canHaveOutput()); + CHECK(input1->getType() == ModelType::Input); + CHECK(input1->getName() == "INPUT"); - CPPUNIT_ASSERT(input->getType() == ModelType::Input); - CPPUNIT_ASSERT(input->getName() == "INPUT"); + CHECK(output1->getType() == ModelType::Output); + CHECK(output1->getName() == "OUTPUT"); - CPPUNIT_ASSERT(output->getType() == ModelType::Output); - CPPUNIT_ASSERT(output->getName() == "OUTPUT"); + CHECK(algo->getType() == ModelType::Algorithm); + CHECK(algo->getName() == "Determinize"); - CPPUNIT_ASSERT(algo->getType() == ModelType::Algorithm); - CPPUNIT_ASSERT(algo->getName() == "Determinize"); + CHECK(algo->getAlgorithm() == Registry::getAlgorithm("automaton::determinize::Determinize")); + } - CPPUNIT_ASSERT(algo->getAlgorithm() == Registry::getAlgorithm("automaton::determinize::Determinize")); -} + SECTION ( "Connect Disconnect Basic" ) { + REQUIRE(output1->evaluate() == nullptr); -void ModelBoxTest::modelBoxConnectDisconnectBasic ( ) { - auto input = std::make_unique<InputModelBox>(); - auto output = std::make_unique<OutputModelBox>(); + input1->setAutomaton(Utils::generateRandomAutomaton()); - CPPUNIT_ASSERT(output->evaluate() == nullptr); + REQUIRE(output1->evaluate() == nullptr); - input->setAutomaton(Utils::generateRandomAutomaton()); + ModelBox::connect(input1.get(), output1.get(), 0); - CPPUNIT_ASSERT(output->evaluate() == nullptr); + CHECK(output1->evaluate() == input1->getAutomaton()); - ModelBox::connect(input.get(), output.get(), 0); + ModelBox::disconnect(input1.get(), output1.get(), 0); - CPPUNIT_ASSERT(output->evaluate() == input->getAutomaton()); + REQUIRE(output1->evaluate() == nullptr); + } - ModelBox::disconnect(input.get(), output.get(), 0); + SECTION ( "Connect Disconnect Multiple Outputs" ) { + REQUIRE(output1->evaluate() == nullptr); + REQUIRE(output2->evaluate() == nullptr); - CPPUNIT_ASSERT(output->evaluate() == nullptr); -} + input1->setAutomaton(Utils::generateRandomAutomaton()); -void ModelBoxTest::modelBoxConnectDisconnectMultipleFrom ( ) { - auto input = std::make_unique<InputModelBox>(); - auto output1 = std::make_unique<OutputModelBox>(); - auto output2 = std::make_unique<OutputModelBox>(); + CHECK(output1->evaluate() == nullptr); + CHECK(output2->evaluate() == nullptr); - CPPUNIT_ASSERT(output1->evaluate() == nullptr); - CPPUNIT_ASSERT(output2->evaluate() == nullptr); + ModelBox::connect(input1.get(), output1.get(), 0); - input->setAutomaton(Utils::generateRandomAutomaton()); + CHECK(output1->evaluate() == input1->getAutomaton()); + CHECK(output2->evaluate() == nullptr); - CPPUNIT_ASSERT(output1->evaluate() == nullptr); - CPPUNIT_ASSERT(output2->evaluate() == nullptr); + ModelBox::connect(input1.get(), output2.get(), 0); - ModelBox::connect(input.get(), output1.get(), 0); + CHECK(output1->evaluate() == input1->getAutomaton()); + CHECK(output2->evaluate() == input1->getAutomaton()); - CPPUNIT_ASSERT(output1->evaluate() == input->getAutomaton()); - CPPUNIT_ASSERT(output2->evaluate() == nullptr); + ModelBox::disconnect(input1.get(), output1.get(), 0); - ModelBox::connect(input.get(), output2.get(), 0); + CHECK(output1->evaluate() == nullptr); + CHECK(output2->evaluate() == input1->getAutomaton()); + } - CPPUNIT_ASSERT(output1->evaluate() == input->getAutomaton()); - CPPUNIT_ASSERT(output2->evaluate() == input->getAutomaton()); + SECTION ( "Connect Disconnect Multiple Inputs" ) { + REQUIRE(output1->evaluate() == nullptr); - ModelBox::disconnect(input.get(), output1.get(), 0); + ModelBox::connect(input1.get(), output1.get(), 0); + CHECK_THROWS_AS(ModelBox::connect(input2.get(), output1.get(), 0), std::runtime_error); + } - CPPUNIT_ASSERT(output1->evaluate() == nullptr); - CPPUNIT_ASSERT(output2->evaluate() == input->getAutomaton()); -} + SECTION ( "Connect Disconnect Multiple Existing" ) { + ModelBox::connect(input1.get(), output1.get(), 0); + ModelBox::disconnect(input1.get(), output1.get(), 0); + CHECK_NOTHROW(ModelBox::connect(input2.get(), output1.get(), 0)); + } -void ModelBoxTest::modelBoxConnectDisconnectMultipleTo ( ) { - auto input1 = std::make_unique<InputModelBox>(); - auto input2 = std::make_unique<InputModelBox>(); - auto output = std::make_unique<OutputModelBox>(); - - CPPUNIT_ASSERT(output->evaluate() == nullptr); + SECTION ( "Connect Disconnect Nonexistent Slot" ) { + CHECK_THROWS_AS(ModelBox::connect(input1.get(), output1.get(), 1), std::runtime_error); + } - ModelBox::connect(input1.get(), output.get(), 0); - CPPUNIT_ASSERT_THROW(ModelBox::connect(input2.get(), output.get(), 0), std::runtime_error); -} + SECTION ( "Connect Disconnect Nonexistent Connection" ) { + CHECK_THROWS_AS(ModelBox::disconnect(input1.get(), output1.get(), 0), std::runtime_error); + } -void ModelBoxTest::modelBoxConnectDisconnectMultipleExisting ( ) { - auto input1 = std::make_unique<InputModelBox>(); - auto input2 = std::make_unique<InputModelBox>(); - auto output = std::make_unique<OutputModelBox>(); - - ModelBox::connect(input1.get(), output.get(), 0); - ModelBox::disconnect(input1.get(), output.get(), 0); - CPPUNIT_ASSERT_NO_THROW(ModelBox::connect(input2.get(), output.get(), 0)); -} - -void ModelBoxTest::modelBoxConnectDisconnectNonexistentSlot ( ) { - auto input = std::make_unique<InputModelBox>(); - auto output = std::make_unique<OutputModelBox>(); - - CPPUNIT_ASSERT_THROW(ModelBox::connect(input.get(), output.get(), 1), std::runtime_error); -} - -void ModelBoxTest::modelBoxConnectDisconnectNonexistentConnection ( ) { - auto input = std::make_unique<InputModelBox>(); - auto output = std::make_unique<OutputModelBox>(); - - CPPUNIT_ASSERT_THROW(ModelBox::disconnect(input.get(), output.get(), 0), std::runtime_error); + Registry::deinitialize(); } diff --git a/alib2gui/test-src/ModelBoxTest.h b/alib2gui/test-src/ModelBoxTest.h deleted file mode 100644 index 0bd00720ea66717f578ee6c978c1ae9ea4932493..0000000000000000000000000000000000000000 --- a/alib2gui/test-src/ModelBoxTest.h +++ /dev/null @@ -1,31 +0,0 @@ -#ifndef MODEL_BOX_TEST_H_ -#define MODEL_BOX_TEST_H_ - -#include <cppunit/extensions/HelperMacros.h> - -class ModelBoxTest : public CppUnit::TestFixture -{ - CPPUNIT_TEST_SUITE( ModelBoxTest ); - CPPUNIT_TEST( modelBoxBasicProperties ); - CPPUNIT_TEST( modelBoxConnectDisconnectBasic ); - CPPUNIT_TEST( modelBoxConnectDisconnectMultipleFrom ); - CPPUNIT_TEST( modelBoxConnectDisconnectMultipleTo ); - CPPUNIT_TEST( modelBoxConnectDisconnectMultipleExisting ); - CPPUNIT_TEST( modelBoxConnectDisconnectNonexistentSlot ); - CPPUNIT_TEST( modelBoxConnectDisconnectNonexistentConnection ); - CPPUNIT_TEST_SUITE_END(); - -public: - void setUp(); - void tearDown(); - - void modelBoxBasicProperties ( ); - void modelBoxConnectDisconnectBasic ( ); - void modelBoxConnectDisconnectMultipleFrom ( ); - void modelBoxConnectDisconnectMultipleTo ( ); - void modelBoxConnectDisconnectMultipleExisting ( ); - void modelBoxConnectDisconnectNonexistentSlot ( ); - void modelBoxConnectDisconnectNonexistentConnection ( ); -}; - -#endif // MODEL_BOX_TEST_H_ diff --git a/alib2gui/test-src/RegistryTest.cpp b/alib2gui/test-src/RegistryTest.cpp index 83db28bc38788c0b68c1bdf24ba395c51a2daf14..3127eb763f7648c1781364c92379f0953d5625d9 100644 --- a/alib2gui/test-src/RegistryTest.cpp +++ b/alib2gui/test-src/RegistryTest.cpp @@ -1,53 +1,46 @@ -#include "RegistryTest.h" +#include <catch2/catch.hpp> #include <Algorithm/Registry.hpp> -CPPUNIT_TEST_SUITE_NAMED_REGISTRATION ( RegistryTest, "registry" ); -CPPUNIT_TEST_SUITE_REGISTRATION ( RegistryTest ); -void RegistryTest::setUp ( ) { -} - -void RegistryTest::tearDown ( ) { -} - -void RegistryTest::registryTest ( ) { - Registry::deinitialize(); +TEST_CASE ( "Registry", "[unit][gui][registry]" ) { + SECTION ( "Registry test" ) { + Registry::deinitialize(); - CPPUNIT_ASSERT(Registry::getAlgorithm("automaton::determinize::Determinize") == nullptr); + REQUIRE(Registry::getAlgorithm("automaton::determinize::Determinize") == nullptr); - Registry::initialize(); + Registry::initialize(); - auto* algo = Registry::getAlgorithm("automaton::determinize::Determinize"); - CPPUNIT_ASSERT(algo != nullptr); + auto* algo = Registry::getAlgorithm("automaton::determinize::Determinize"); + CHECK(algo != nullptr); - CPPUNIT_ASSERT(Registry::getAlgorithm("nonexistent_algorithm") == nullptr); -} - -void RegistryTest::algorithmTestBasic ( ) { - auto name = "automaton::determinize::Determinize"; + CHECK(Registry::getAlgorithm("nonexistent_algorithm") == nullptr); + } - auto* algo = Registry::getAlgorithm(name); + SECTION ( "Algorithm Test Basic" ) { + const std::string name = "automaton::determinize::Determinize"; + auto* algo = Registry::getAlgorithm(name); - CPPUNIT_ASSERT(algo->getFullName() == name); - CPPUNIT_ASSERT(algo->getPrettyName() == "Determinize"); + CHECK(algo->getFullName() == name); + CHECK(algo->getPrettyName() == "Determinize"); - const auto& groups = algo->getGroups(); - CPPUNIT_ASSERT(groups[0] == "automaton"); - CPPUNIT_ASSERT(groups[1] == "determinize"); + const auto& groups = algo->getGroups(); + CHECK(groups[0] == "automaton"); + CHECK(groups[1] == "determinize"); - CPPUNIT_ASSERT(algo->getInputCount() == 1); -} + CHECK(algo->getInputCount() == 1); + } -void RegistryTest::algorithmTestInputCount ( ) { - auto* algo = Registry::getAlgorithm("automaton::transform::AutomataConcatenation"); + SECTION ( "Algorithms Test Input Count" ) { + auto* algo = Registry::getAlgorithm("automaton::transform::AutomataConcatenation"); - CPPUNIT_ASSERT(algo != nullptr); - CPPUNIT_ASSERT(algo->getInputCount() == 2); -} + REQUIRE(algo != nullptr); + CHECK(algo->getInputCount() == 2); + } -void RegistryTest::algorithmTestPrettyName ( ) { - auto* algo = Registry::getAlgorithm("automaton::transform::AutomataConcatenationEpsilonTransition"); + SECTION ( "Algorithm Test Pretty Name" ) { + auto* algo = Registry::getAlgorithm("automaton::transform::AutomataConcatenationEpsilonTransition"); - CPPUNIT_ASSERT(algo != nullptr); - CPPUNIT_ASSERT(algo->getPrettyName() == u8"\u03B5-Concatenate"); + REQUIRE(algo != nullptr); + CHECK(algo->getPrettyName() == u8"\u03B5-Concatenate"); + } } diff --git a/alib2gui/test-src/RegistryTest.h b/alib2gui/test-src/RegistryTest.h deleted file mode 100644 index fee786a949e942e2e452e8f499b629cb4a4f4c48..0000000000000000000000000000000000000000 --- a/alib2gui/test-src/RegistryTest.h +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef REGISTRY_TEST_H_ -#define REGISTRY_TEST_H_ - -#include <cppunit/extensions/HelperMacros.h> - -class RegistryTest : public CppUnit::TestFixture -{ - CPPUNIT_TEST_SUITE( RegistryTest ); - CPPUNIT_TEST( registryTest ); - CPPUNIT_TEST( algorithmTestBasic ); - CPPUNIT_TEST( algorithmTestInputCount ); - CPPUNIT_TEST( algorithmTestPrettyName ); - CPPUNIT_TEST_SUITE_END(); - -public: - void setUp(); - void tearDown(); - - void registryTest ( ); - void algorithmTestBasic ( ); - void algorithmTestInputCount ( ); - void algorithmTestPrettyName ( ); -}; - -#endif // REGISTRY_TEST_H_ diff --git a/alib2gui/test-src/main.cpp b/alib2gui/test-src/main.cpp index adb58324a109835bfda91d246781668910521414..4ed06df1f7bea8cc18ee161389b9c3e2741b08a0 100644 --- a/alib2gui/test-src/main.cpp +++ b/alib2gui/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>