diff --git a/CMakeLists.txt b/CMakeLists.txt index ac74452..de3bd9b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 0.1) +cmake_minimum_required(VERSION 3.8) project("cpp_systematic_testing" CXX) set(CMAKE_CXX_STANDARD 17) diff --git a/include/systematic_testing.h b/include/systematic_testing.h index 1e3f3c4..ef86d99 100644 --- a/include/systematic_testing.h +++ b/include/systematic_testing.h @@ -5,7 +5,9 @@ #define SYSTEMATIC_TESTING_H #include +#include #include +#include #include #include #include @@ -21,10 +23,24 @@ #include #include -#ifdef SYSTEST_EXPORT -# define SYSTEST_API __declspec(dllexport) -#else -# define SYSTEST_API __declspec(dllimport) +#ifdef __linux__ +# ifdef SYSTEST_EXPORT +# define SYSTEST_API __attribute__((visibility("default"))) +# else +# define SYSTEST_API +# endif +#elif _WIN32 +# ifdef SYSTEST_EXPORT +# define SYSTEST_API __declspec(dllexport) +# else +# define SYSTEST_API __declspec(dllimport) +# endif +#else +# ifdef SYSTEST_EXPORT +# define SYSTEST_API +# else +# define SYSTEST_API +# endif #endif namespace SystematicTesting @@ -289,7 +305,7 @@ namespace SystematicTesting { private: // Give private access to the test engine. - friend class TestEngine; + friend class SystematicTesting::TestEngine; public: // Returns the number of iterations performed. @@ -666,7 +682,7 @@ namespace SystematicTesting { private: // Give private access to the test engine. - friend class TestEngine; + friend class SystematicTesting::TestEngine; // The creation sequence vector of this operation. std::vector m_creation_seq; diff --git a/test/controlled_task.h b/test/controlled_task.h index 5183d99..e5c15de 100644 --- a/test/controlled_task.h +++ b/test/controlled_task.h @@ -15,60 +15,57 @@ using namespace std::chrono_literals; using namespace SystematicTesting; -namespace +template +class ControlledTaskBase { - template - class ControlledTaskBase +public: + explicit ControlledTaskBase(std::function func) : + m_test_engine(GetTestEngine()), + m_thread(), + m_func(func), + m_result(std::nullopt) { - public: - explicit ControlledTaskBase(std::function func) : - m_test_engine(GetTestEngine()), - m_thread(), - m_func(func), - m_result(std::nullopt) - { - - } + + } - virtual ~ControlledTaskBase() + virtual ~ControlledTaskBase() + { + if (m_thread->joinable()) { - if (m_thread->joinable()) - { - m_thread->join(); - } + m_thread->join(); } + } - void start() + void start() + { + size_t op_id = m_test_engine->create_next_operation().value(); + m_thread = std::make_unique([this, op_id]() { - size_t op_id = m_test_engine->create_next_operation().value(); - m_thread = std::make_unique([this, op_id]() - { - m_test_engine->start_operation(op_id); - execute(m_func, op_id); - m_test_engine->complete_current_operation(); - }); - - m_test_engine->schedule_next_operation(); - } + m_test_engine->start_operation(op_id); + execute(m_func, op_id); + m_test_engine->complete_current_operation(); + }); - void wait() - { - m_test_engine->pause_operation_until_condition([this]() { - return m_result.has_value(); - }); - } + m_test_engine->schedule_next_operation(); + } + + void wait() + { + m_test_engine->pause_operation_until_condition([this]() { + return m_result.has_value(); + }); + } - protected: - std::optional m_result; +protected: + std::optional m_result; - virtual void execute(std::function& func, size_t op_id) = 0; + virtual void execute(std::function& func, size_t op_id) = 0; - private: - TestEngine* m_test_engine; - std::unique_ptr m_thread; - std::function m_func; - }; -} +private: + TestEngine* m_test_engine; + std::unique_ptr m_thread; + std::function m_func; +}; template class ControlledTask final : public ControlledTaskBase