From 02018fb583812c17f267aab6d992357f3abdcfd0 Mon Sep 17 00:00:00 2001 From: Rodrigo Fernandes Date: Tue, 1 Oct 2013 22:13:00 +0100 Subject: [PATCH] Added 2 small tests Removed commented code answer-module also depends on boost_date-time --- CMakeLists.txt | 4 +-- include/answer/Module.hh | 1 - src/Module.cpp | 7 +----- src/Operation.cpp | 1 - tests/module/CMakeLists.txt | 17 +++++++++++++ tests/module/ModuleTest.cpp | 33 +++++++++++++++++++++++++ tests/registration/CMakeLists.txt | 17 +++++++++++++ tests/registration/RegistrationTest.cpp | 25 +++++++++++++++++++ 8 files changed, 94 insertions(+), 11 deletions(-) create mode 100644 tests/module/CMakeLists.txt create mode 100644 tests/module/ModuleTest.cpp create mode 100644 tests/registration/CMakeLists.txt create mode 100644 tests/registration/RegistrationTest.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 6fbf20b..b93e1b5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,7 +12,7 @@ list(APPEND CMAKE_CXX_FLAGS "-std=c++11 -pedantic -Wall") ###################### ##################################### # INCLUDES, SOURCE FILES AND CMAKE MODULES ########################################################### -find_package(Boost COMPONENTS serialization REQUIRED QUIET) +find_package(Boost COMPONENTS serialization date_time REQUIRED QUIET) include_directories ( include @@ -37,14 +37,12 @@ file (GLOB headersArchiveHH # TARGET GENERATION ########################################################### #Module support - add_library (${PROJECT_NAME}-module SHARED ${MODULE_SRC_FILES}) set_target_properties(${PROJECT_NAME}-module PROPERTIES VERSION ${PROJECT_VERSION} SOVERSION ${PROJECT_VERSION}) target_link_libraries (${PROJECT_NAME}-module ${Boost_LIBRARIES} ) -find_package(Boost COMPONENTS serialization date_time REQUIRED QUIET) #Library add_library (${PROJECT_NAME} SHARED ${ADAPTER_SRC_FILES}) diff --git a/include/answer/Module.hh b/include/answer/Module.hh index c6c0c0f..51db5f7 100644 --- a/include/answer/Module.hh +++ b/include/answer/Module.hh @@ -34,7 +34,6 @@ namespace answer{ public: static ModuleStore& Instance(); -// const StoreT& getStore() const; void registerModule(Module *const module); virtual FlowStatus inFlow(Context &context); diff --git a/src/Module.cpp b/src/Module.cpp index dbad712..0f2a8e3 100644 --- a/src/Module.cpp +++ b/src/Module.cpp @@ -12,15 +12,10 @@ ModuleStore& ModuleStore::Instance(){ return store; } -// const ModuleStore::StoreT& ModuleStore::getStore() const{ -// return _store; -// } - -void ModuleStore::registerModule(/*const string& name,*/ answer::Module*const module){ +void ModuleStore::registerModule(answer::Module*const module){ _store.push_back(module); } - Module::FlowStatus ModuleStore::inFlow(Context &context) { for (auto &module: _store){ diff --git a/src/Operation.cpp b/src/Operation.cpp index 0378e8f..a26e4b5 100644 --- a/src/Operation.cpp +++ b/src/Operation.cpp @@ -22,7 +22,6 @@ void OperationStore::registerOperation( const string& serviceName, const string& _map[serviceName + string("/") + filteredName] = move(webMethodHandle); } -//TODO: fix this OperationStore& OperationStore::Instance() { static OperationStore inst; return inst; diff --git a/tests/module/CMakeLists.txt b/tests/module/CMakeLists.txt new file mode 100644 index 0000000..b7601b7 --- /dev/null +++ b/tests/module/CMakeLists.txt @@ -0,0 +1,17 @@ +find_package(Boost COMPONENTS unit_test_framework REQUIRED QUIET) + +add_executable(moduleTest + ModuleTest.cpp +) + +include_directories( + ${Boost_INCLUDE_DIRS} +) + +target_link_libraries(moduleTest + ${Boost_LIBRARIES} + answer-module +) + +add_test(module moduleTest) + \ No newline at end of file diff --git a/tests/module/ModuleTest.cpp b/tests/module/ModuleTest.cpp new file mode 100644 index 0000000..a6dcf3c --- /dev/null +++ b/tests/module/ModuleTest.cpp @@ -0,0 +1,33 @@ +#define BOOST_TEST_MODULE ModuleTest +#include + +#include "answer/Module.hh" + +using namespace std; + +class TestModule: public answer::Module{ +public: + virtual FlowStatus inFlow ( answer::Context& context ); + virtual FlowStatus outFlow ( answer::Context& context ); + virtual FlowStatus outFlowFault ( answer::Context& context ); +}; + +answer::Module::FlowStatus TestModule::inFlow ( answer::Context& context ) { + return OK; +} + +answer::Module::FlowStatus TestModule::outFlow ( answer::Context& context ) { + return OK; +} + +answer::Module::FlowStatus TestModule::outFlowFault ( answer::Context& context ) { + return OK; +} + +ANSWER_REGISTER_MODULE(TestModule); + +BOOST_AUTO_TEST_CASE( module ) +{ + BOOST_CHECK(true); +} + diff --git a/tests/registration/CMakeLists.txt b/tests/registration/CMakeLists.txt new file mode 100644 index 0000000..adcbec4 --- /dev/null +++ b/tests/registration/CMakeLists.txt @@ -0,0 +1,17 @@ +find_package(Boost COMPONENTS unit_test_framework REQUIRED QUIET) + +add_executable(registrationTest + RegistrationTest.cpp +) + +include_directories( + ${Boost_INCLUDE_DIRS} +) + +target_link_libraries(registrationTest + ${Boost_LIBRARIES} + answer +) + +add_test(registration registrationTest) + \ No newline at end of file diff --git a/tests/registration/RegistrationTest.cpp b/tests/registration/RegistrationTest.cpp new file mode 100644 index 0000000..edfbb47 --- /dev/null +++ b/tests/registration/RegistrationTest.cpp @@ -0,0 +1,25 @@ +#define BOOST_TEST_MODULE SerializationTest +#include + +//Normally this is defined in the build file, it's usually the project name +#define ANSWER_SERVICE_NAME "SerializationTest" + +#include "answer/Operation.hh" + +using namespace std; + +class Operation{ +public: + int test(string X){ + return X.size(); + } +}; + +ANSWER_REGISTER_OPERATION(Operation::test); + +BOOST_AUTO_TEST_CASE( registration ) +{ + list operations = answer::OperationStore::Instance().operationList(); + BOOST_CHECK(operations.front() == string("SerializationTest/test")); +} +