From 7c390c07eed79ee02fa23266ece8d0218672923e Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Sun, 13 Dec 2020 21:58:54 +0100 Subject: [PATCH] taken over unnittest folder from upstream --- unittest/core/CatchSetup.cpp | 11 +- unittest/internal/InternalUnitTester.h | 2 +- unittest/internal/UnittDefinitions.cpp | 2 +- unittest/internal/osal/IntTestMq.cpp | 9 +- unittest/internal/osal/IntTestMutex.cpp | 8 +- unittest/internal/osal/IntTestSemaphore.cpp | 9 +- .../serialize/IntTestSerialization.cpp | 9 +- .../internal/serialize/IntTestSerialization.h | 9 +- unittest/testcfg/CatchFactory.cpp | 60 ++++ unittest/testcfg/CatchFactory.h | 16 ++ unittest/testcfg/FSFWConfig.h | 2 +- unittest/testcfg/cdatapool/dataPoolInit.h | 2 +- unittest/testcfg/testcfg.mk | 1 + unittest/tests/action/TestActionHelper.cpp | 213 +++++++------- unittest/tests/action/TestActionHelper.h | 263 +++++++++--------- unittest/tests/container/RingBufferTest.cpp | 4 +- unittest/tests/container/TestArrayList.cpp | 5 +- unittest/tests/container/TestDynamicFifo.cpp | 6 +- unittest/tests/container/TestFifo.cpp | 6 +- .../tests/container/TestFixedArrayList.cpp | 4 +- unittest/tests/container/TestFixedMap.cpp | 4 +- .../container/TestFixedOrderedMultimap.cpp | 4 +- unittest/tests/osal/TestMessageQueue.cpp | 8 +- .../serialize/TestSerialBufferAdapter.cpp | 2 +- .../serialize/TestSerialLinkedPacket.cpp | 7 +- .../tests/serialize/TestSerialization.cpp | 2 +- 26 files changed, 376 insertions(+), 292 deletions(-) create mode 100644 unittest/testcfg/CatchFactory.cpp create mode 100644 unittest/testcfg/CatchFactory.h diff --git a/unittest/core/CatchSetup.cpp b/unittest/core/CatchSetup.cpp index 5749ecd1..cb5bd33e 100644 --- a/unittest/core/CatchSetup.cpp +++ b/unittest/core/CatchSetup.cpp @@ -1,8 +1,7 @@ #include "CatchDefinitions.h" +#include "CatchFactory.h" #include -#include - #ifdef GCOV #include @@ -11,15 +10,15 @@ #include "../../objectmanager/ObjectManager.h" #include "../../objectmanager/ObjectManagerIF.h" #include "../../storagemanager/StorageManagerIF.h" -#include "../../datapoolglob/GlobalDataPool.h" +#include "../../datapool/DataPool.h" #include "../../serviceinterface/ServiceInterfaceStream.h" /* Global instantiations normally done in main.cpp */ /* Initialize Data Pool */ -namespace glob { -GlobalDataPool dataPool(datapool::dataPoolInit); -} +//namespace glob { +DataPool dataPool(datapool::dataPoolInit); +//} namespace sif { diff --git a/unittest/internal/InternalUnitTester.h b/unittest/internal/InternalUnitTester.h index b301b923..d0b1c106 100644 --- a/unittest/internal/InternalUnitTester.h +++ b/unittest/internal/InternalUnitTester.h @@ -2,7 +2,7 @@ #define FRAMEWORK_TEST_UNITTESTCLASS_H_ #include "UnittDefinitions.h" -#include +#include "../../returnvalues/HasReturnvaluesIF.h" /** * @brief Can be used for internal testing, for example for hardware specific diff --git a/unittest/internal/UnittDefinitions.cpp b/unittest/internal/UnittDefinitions.cpp index 0bdbfcc7..6265e9fd 100644 --- a/unittest/internal/UnittDefinitions.cpp +++ b/unittest/internal/UnittDefinitions.cpp @@ -1,4 +1,4 @@ -#include +#include "UnittDefinitions.h" ReturnValue_t unitt::put_error(std::string errorId) { sif::error << "Unit Tester error: Failed at test ID " diff --git a/unittest/internal/osal/IntTestMq.cpp b/unittest/internal/osal/IntTestMq.cpp index 63016374..8d95f51e 100644 --- a/unittest/internal/osal/IntTestMq.cpp +++ b/unittest/internal/osal/IntTestMq.cpp @@ -1,7 +1,8 @@ -#include -#include -#include -#include +#include "IntTestMq.h" +#include "../UnittDefinitions.h" + +#include "../../ipc/MessageQueueIF.h" +#include "../../ipc/QueueFactory.h" #include diff --git a/unittest/internal/osal/IntTestMutex.cpp b/unittest/internal/osal/IntTestMutex.cpp index 3fd668df..01581347 100644 --- a/unittest/internal/osal/IntTestMutex.cpp +++ b/unittest/internal/osal/IntTestMutex.cpp @@ -1,10 +1,10 @@ #include "IntTestMutex.h" -#include -#include +#include "../../ipc/MutexFactory.h" +#include "../UnittDefinitions.h" #if defined(hosted) -#include +#include "../../osal/hosted/Mutex.h" #include #include #endif @@ -20,7 +20,7 @@ void testmutex::testMutex() { // timed_mutex from the C++ library specifies undefined behaviour if // the timed mutex is locked twice from the same thread. #if defined(hosted) - // hold on, this actually worked ? :-D This calls the function from + // This calls the function from // another thread and stores the returnvalue in a future. auto future = std::async(&MutexIF::lockMutex, mutex, 1); result = future.get(); diff --git a/unittest/internal/osal/IntTestSemaphore.cpp b/unittest/internal/osal/IntTestSemaphore.cpp index 534a6a6d..f260b6a5 100644 --- a/unittest/internal/osal/IntTestSemaphore.cpp +++ b/unittest/internal/osal/IntTestSemaphore.cpp @@ -1,8 +1,9 @@ #include "IntTestSemaphore.h" -#include -#include -#include -#include +#include "../UnittDefinitions.h" + +#include "../../tasks/SemaphoreFactory.h" +#include "../../serviceinterface/ServiceInterfaceStream.h" +#include "../../timemanager/Stopwatch.h" void testsemaph::testBinSemaph() { diff --git a/unittest/internal/serialize/IntTestSerialization.cpp b/unittest/internal/serialize/IntTestSerialization.cpp index 3f231a41..1e33ff33 100644 --- a/unittest/internal/serialize/IntTestSerialization.cpp +++ b/unittest/internal/serialize/IntTestSerialization.cpp @@ -1,8 +1,9 @@ #include "IntTestSerialization.h" -#include -#include -#include -#include +#include "../UnittDefinitions.h" +#include "../../serialize/SerializeElement.h" +#include "../../serialize/SerialBufferAdapter.h" +#include "../../serialize/SerializeIF.h" + #include using retval = HasReturnvaluesIF; diff --git a/unittest/internal/serialize/IntTestSerialization.h b/unittest/internal/serialize/IntTestSerialization.h index f8841b82..e8dbd35a 100644 --- a/unittest/internal/serialize/IntTestSerialization.h +++ b/unittest/internal/serialize/IntTestSerialization.h @@ -1,6 +1,7 @@ -#ifndef UNITTEST_INTERNAL_INTTESTSERIALIZATION_H_ -#define UNITTEST_INTERNAL_INTTESTSERIALIZATION_H_ -#include +#ifndef FSFW_UNITTEST_INTERNAL_INTTESTSERIALIZATION_H_ +#define FSFW_UNITTEST_INTERNAL_INTTESTSERIALIZATION_H_ + +#include "../../returnvalues/HasReturnvaluesIF.h" #include namespace testserialize { @@ -12,4 +13,4 @@ ReturnValue_t test_serial_buffer_adapter(); extern std::array test_array; } -#endif /* UNITTEST_INTERNAL_INTTESTSERIALIZATION_H_ */ +#endif /* FSFW_UNITTEST_INTERNAL_INTTESTSERIALIZATION_H_ */ diff --git a/unittest/testcfg/CatchFactory.cpp b/unittest/testcfg/CatchFactory.cpp new file mode 100644 index 00000000..c74a8126 --- /dev/null +++ b/unittest/testcfg/CatchFactory.cpp @@ -0,0 +1,60 @@ +#include "CatchFactory.h" + +#include +#include + +#include +#include +#include + +/** + * @brief Produces system objects. + * @details + * Build tasks by using SystemObject Interface (Interface). + * Header files of all tasks must be included + * Please note that an object has to implement the system object interface + * if the interface validity is checked or retrieved later by using the + * get(object_id) function from the ObjectManagerIF. + * + * Framework objects are created first. + * + * @ingroup init + */ +void Factory::produce(void) { + setStaticFrameworkObjectIds(); + new EventManager(objects::EVENT_MANAGER); + new HealthTable(objects::HEALTH_TABLE); + //new InternalErrorReporter(objects::INTERNAL_ERROR_REPORTER); + + { + static constexpr uint8_t NUMBER_OF_POOLS = 5; + const uint16_t element_sizes[NUMBER_OF_POOLS] = {16, 32, 64, 128, 1024}; + const uint16_t n_elements[NUMBER_OF_POOLS] = {100, 50, 25, 15, 5}; + new PoolManager(objects::TC_STORE, element_sizes, + n_elements); + } + + { + static constexpr uint8_t NUMBER_OF_POOLS = 5; + const uint16_t element_sizes[NUMBER_OF_POOLS] = {16, 32, 64, 128, 1024}; + const uint16_t n_elements[NUMBER_OF_POOLS] = {100, 50, 25, 15, 5}; + new PoolManager(objects::TM_STORE, element_sizes, + n_elements); + } + + { + static constexpr uint8_t NUMBER_OF_POOLS = 6; + const uint16_t element_sizes[NUMBER_OF_POOLS] = {32, 64, 512, + 1024, 2048, 4096}; + const uint16_t n_elements[NUMBER_OF_POOLS] = {200, 100, 50, 25, 15, 5}; + new PoolManager(objects::IPC_STORE, element_sizes, + n_elements); + } + +} + +void Factory::setStaticFrameworkObjectIds() { + +} + + diff --git a/unittest/testcfg/CatchFactory.h b/unittest/testcfg/CatchFactory.h new file mode 100644 index 00000000..84f9207e --- /dev/null +++ b/unittest/testcfg/CatchFactory.h @@ -0,0 +1,16 @@ +#ifndef FACTORY_H_ +#define FACTORY_H_ + +#include + +namespace Factory { + /** + * @brief Creates all SystemObject elements which are persistent + * during execution. + */ + void produce(); + void setStaticFrameworkObjectIds(); + +} + +#endif /* FACTORY_H_ */ diff --git a/unittest/testcfg/FSFWConfig.h b/unittest/testcfg/FSFWConfig.h index d3451985..4fb224c1 100644 --- a/unittest/testcfg/FSFWConfig.h +++ b/unittest/testcfg/FSFWConfig.h @@ -12,7 +12,7 @@ #define FSFW_REDUCED_PRINTOUT 0 //! Can be used to enable debugging printouts for developing the FSFW -#define FSFW_VERBOSE_PRINTOUT 0 +#define FSFW_DEBUGGING 0 //! Defines the FIFO depth of each commanding service base which //! also determines how many commands a CSB service can handle in one cycle diff --git a/unittest/testcfg/cdatapool/dataPoolInit.h b/unittest/testcfg/cdatapool/dataPoolInit.h index 23a3d01f..9425d767 100644 --- a/unittest/testcfg/cdatapool/dataPoolInit.h +++ b/unittest/testcfg/cdatapool/dataPoolInit.h @@ -1,7 +1,7 @@ #ifndef HOSTED_CONFIG_CDATAPOOL_DATAPOOLINIT_H_ #define HOSTED_CONFIG_CDATAPOOL_DATAPOOLINIT_H_ -#include +#include #include #include #include diff --git a/unittest/testcfg/testcfg.mk b/unittest/testcfg/testcfg.mk index 64fa87f6..31d3b60a 100644 --- a/unittest/testcfg/testcfg.mk +++ b/unittest/testcfg/testcfg.mk @@ -3,6 +3,7 @@ CXXSRC += $(wildcard $(CURRENTPATH)/ipc/*.cpp) CXXSRC += $(wildcard $(CURRENTPATH)/objects/*.cpp) CXXSRC += $(wildcard $(CURRENTPATH)/pollingsequence/*.cpp) CXXSRC += $(wildcard $(CURRENTPATH)/events/*.cpp) +CXXSRC += $(wildcard $(CURRENTPATH)/*.cpp) INCLUDES += $(CURRENTPATH) INCLUDES += $(CURRENTPATH)/objects diff --git a/unittest/tests/action/TestActionHelper.cpp b/unittest/tests/action/TestActionHelper.cpp index d5b2e467..944ad705 100644 --- a/unittest/tests/action/TestActionHelper.cpp +++ b/unittest/tests/action/TestActionHelper.cpp @@ -1,106 +1,107 @@ -//#include "TestActionHelper.h" -//#include -//#include -//#include -//#include "../../core/CatchDefinitions.h" -// -// -//TEST_CASE( "Action Helper" , "[ActionHelper]") { -// ActionHelperOwnerMockBase testDhMock; -// MessageQueueMockBase testMqMock; -// ActionHelper actionHelper = ActionHelper( -// &testDhMock, dynamic_cast(&testMqMock)); -// CommandMessage actionMessage; -// ActionId_t testActionId = 777; -// std::array testParams {1, 2, 3}; -// store_address_t paramAddress; -// StorageManagerIF *ipcStore = tglob::getIpcStoreHandle(); -// ipcStore->addData(¶mAddress, testParams.data(), 3); -// REQUIRE(actionHelper.initialize() == retval::CATCH_OK); -// -// SECTION ("Simple tests") { -// ActionMessage::setCommand(&actionMessage, testActionId, paramAddress); -// CHECK(not testDhMock.executeActionCalled); -// REQUIRE(actionHelper.handleActionMessage(&actionMessage) == retval::CATCH_OK); -// CHECK(testDhMock.executeActionCalled); -// // No message is sent if everything is alright. -// CHECK(not testMqMock.wasMessageSent()); -// store_address_t invalidAddress; -// ActionMessage::setCommand(&actionMessage, testActionId, invalidAddress); -// actionHelper.handleActionMessage(&actionMessage); -// CHECK(testMqMock.wasMessageSent()); -// const uint8_t* ptr = nullptr; -// size_t size = 0; -// REQUIRE(ipcStore->getData(paramAddress, &ptr, &size) == static_cast(StorageManagerIF::DATA_DOES_NOT_EXIST)); -// REQUIRE(ptr == nullptr); -// REQUIRE(size == 0); -// testDhMock.getBuffer(&ptr, &size); -// REQUIRE(size == 3); -// for(uint8_t i = 0; i<3;i++){ -// REQUIRE(ptr[i] == (i+1)); -// } -// testDhMock.clearBuffer(); -// } -// -// SECTION("Handle failures"){ -// actionMessage.setCommand(1234); -// REQUIRE(actionHelper.handleActionMessage(&actionMessage) == static_cast(CommandMessage::UNKNOWN_COMMAND)); -// CHECK(not testMqMock.wasMessageSent()); -// uint16_t step = 5; -// ReturnValue_t status = 0x1234; -// actionHelper.step(step, testMqMock.getId(), testActionId, status); -// step += 1; -// CHECK(testMqMock.wasMessageSent()); -// CommandMessage testMessage; -// REQUIRE(testMqMock.receiveMessage(&testMessage) == static_cast(HasReturnvaluesIF::RETURN_OK)); -// REQUIRE(testMessage.getCommand() == static_cast(ActionMessage::STEP_FAILED)); -// REQUIRE(testMessage.getParameter() == static_cast(testActionId)); -// uint32_t parameter2 = ((uint32_t)step << 16) | (uint32_t)status; -// REQUIRE(testMessage.getParameter2() == parameter2); -// REQUIRE(ActionMessage::getStep(&testMessage) == step); -// } -// -// SECTION("Handle finish"){ -// CHECK(not testMqMock.wasMessageSent()); -// ReturnValue_t status = 0x9876; -// actionHelper.finish(testMqMock.getId(), testActionId, status); -// CHECK(testMqMock.wasMessageSent()); -// CommandMessage testMessage; -// REQUIRE(testMqMock.receiveMessage(&testMessage) == static_cast(HasReturnvaluesIF::RETURN_OK)); -// REQUIRE(testMessage.getCommand() == static_cast(ActionMessage::COMPLETION_FAILED)); -// REQUIRE(ActionMessage::getActionId(&testMessage) == testActionId); -// REQUIRE(ActionMessage::getReturnCode(&testMessage) == static_cast(status)); -// } -// -// SECTION("Handle failed"){ -// store_address_t toLongParamAddress = StorageManagerIF::INVALID_ADDRESS; -// std::array toLongData = {5, 4, 3, 2, 1}; -// REQUIRE(ipcStore->addData(&toLongParamAddress, toLongData.data(), 5) == retval::CATCH_OK); -// ActionMessage::setCommand(&actionMessage, testActionId, toLongParamAddress); -// CHECK(not testDhMock.executeActionCalled); -// REQUIRE(actionHelper.handleActionMessage(&actionMessage) == retval::CATCH_OK); -// REQUIRE(ipcStore->getData(toLongParamAddress).first == static_cast(StorageManagerIF::DATA_DOES_NOT_EXIST)); -// CommandMessage testMessage; -// REQUIRE(testMqMock.receiveMessage(&testMessage) == static_cast(HasReturnvaluesIF::RETURN_OK)); -// REQUIRE(testMessage.getCommand() == static_cast(ActionMessage::STEP_FAILED)); -// REQUIRE(ActionMessage::getReturnCode(&testMessage) == 0xAFFE); -// REQUIRE(ActionMessage::getStep(&testMessage) == 0); -// REQUIRE(ActionMessage::getActionId(&testMessage) == testActionId); -// } -// -// SECTION("Missing IPC Data"){ -// ActionMessage::setCommand(&actionMessage, testActionId, StorageManagerIF::INVALID_ADDRESS); -// CHECK(not testDhMock.executeActionCalled); -// REQUIRE(actionHelper.handleActionMessage(&actionMessage) == retval::CATCH_OK); -// CommandMessage testMessage; -// REQUIRE(testMqMock.receiveMessage(&testMessage) == static_cast(HasReturnvaluesIF::RETURN_OK)); -// REQUIRE(testMessage.getCommand() == static_cast(ActionMessage::STEP_FAILED)); -// REQUIRE(ActionMessage::getReturnCode(&testMessage) == static_cast(StorageManagerIF::ILLEGAL_STORAGE_ID)); -// REQUIRE(ActionMessage::getStep(&testMessage) == 0); -// } -// -// -// SECTION("Data Reply"){ -// -// } -//} +#include "TestActionHelper.h" +#include +#include +#include +#include "../../core/CatchDefinitions.h" + + +TEST_CASE( "Action Helper" , "[ActionHelper]") { + ActionHelperOwnerMockBase testDhMock; + MessageQueueMockBase testMqMock; + ActionHelper actionHelper = ActionHelper( + &testDhMock, dynamic_cast(&testMqMock)); + CommandMessage actionMessage; + ActionId_t testActionId = 777; + std::array testParams {1, 2, 3}; + store_address_t paramAddress; + StorageManagerIF *ipcStore = tglob::getIpcStoreHandle(); + REQUIRE(ipcStore != nullptr); + ipcStore->addData(¶mAddress, testParams.data(), 3); + REQUIRE(actionHelper.initialize() == retval::CATCH_OK); + + SECTION ("Simple tests") { + ActionMessage::setCommand(&actionMessage, testActionId, paramAddress); + CHECK(not testDhMock.executeActionCalled); + REQUIRE(actionHelper.handleActionMessage(&actionMessage) == retval::CATCH_OK); + CHECK(testDhMock.executeActionCalled); + // No message is sent if everything is alright. + CHECK(not testMqMock.wasMessageSent()); + store_address_t invalidAddress; + ActionMessage::setCommand(&actionMessage, testActionId, invalidAddress); + actionHelper.handleActionMessage(&actionMessage); + CHECK(testMqMock.wasMessageSent()); + const uint8_t* ptr = nullptr; + size_t size = 0; + REQUIRE(ipcStore->getData(paramAddress, &ptr, &size) == static_cast(StorageManagerIF::DATA_DOES_NOT_EXIST)); + REQUIRE(ptr == nullptr); + REQUIRE(size == 0); + testDhMock.getBuffer(&ptr, &size); + REQUIRE(size == 3); + for(uint8_t i = 0; i<3;i++){ + REQUIRE(ptr[i] == (i+1)); + } + testDhMock.clearBuffer(); + } + + SECTION("Handle failures"){ + actionMessage.setCommand(1234); + REQUIRE(actionHelper.handleActionMessage(&actionMessage) == static_cast(CommandMessage::UNKNOWN_COMMAND)); + CHECK(not testMqMock.wasMessageSent()); + uint16_t step = 5; + ReturnValue_t status = 0x1234; + actionHelper.step(step, testMqMock.getId(), testActionId, status); + step += 1; + CHECK(testMqMock.wasMessageSent()); + CommandMessage testMessage; + REQUIRE(testMqMock.receiveMessage(&testMessage) == static_cast(HasReturnvaluesIF::RETURN_OK)); + REQUIRE(testMessage.getCommand() == static_cast(ActionMessage::STEP_FAILED)); + REQUIRE(testMessage.getParameter() == static_cast(testActionId)); + uint32_t parameter2 = ((uint32_t)step << 16) | (uint32_t)status; + REQUIRE(testMessage.getParameter2() == parameter2); + REQUIRE(ActionMessage::getStep(&testMessage) == step); + } + + SECTION("Handle finish"){ + CHECK(not testMqMock.wasMessageSent()); + ReturnValue_t status = 0x9876; + actionHelper.finish(testMqMock.getId(), testActionId, status); + CHECK(testMqMock.wasMessageSent()); + CommandMessage testMessage; + REQUIRE(testMqMock.receiveMessage(&testMessage) == static_cast(HasReturnvaluesIF::RETURN_OK)); + REQUIRE(testMessage.getCommand() == static_cast(ActionMessage::COMPLETION_FAILED)); + REQUIRE(ActionMessage::getActionId(&testMessage) == testActionId); + REQUIRE(ActionMessage::getReturnCode(&testMessage) == static_cast(status)); + } + + SECTION("Handle failed"){ + store_address_t toLongParamAddress = StorageManagerIF::INVALID_ADDRESS; + std::array toLongData = {5, 4, 3, 2, 1}; + REQUIRE(ipcStore->addData(&toLongParamAddress, toLongData.data(), 5) == retval::CATCH_OK); + ActionMessage::setCommand(&actionMessage, testActionId, toLongParamAddress); + CHECK(not testDhMock.executeActionCalled); + REQUIRE(actionHelper.handleActionMessage(&actionMessage) == retval::CATCH_OK); + REQUIRE(ipcStore->getData(toLongParamAddress).first == static_cast(StorageManagerIF::DATA_DOES_NOT_EXIST)); + CommandMessage testMessage; + REQUIRE(testMqMock.receiveMessage(&testMessage) == static_cast(HasReturnvaluesIF::RETURN_OK)); + REQUIRE(testMessage.getCommand() == static_cast(ActionMessage::STEP_FAILED)); + REQUIRE(ActionMessage::getReturnCode(&testMessage) == 0xAFFE); + REQUIRE(ActionMessage::getStep(&testMessage) == 0); + REQUIRE(ActionMessage::getActionId(&testMessage) == testActionId); + } + + SECTION("Missing IPC Data"){ + ActionMessage::setCommand(&actionMessage, testActionId, StorageManagerIF::INVALID_ADDRESS); + CHECK(not testDhMock.executeActionCalled); + REQUIRE(actionHelper.handleActionMessage(&actionMessage) == retval::CATCH_OK); + CommandMessage testMessage; + REQUIRE(testMqMock.receiveMessage(&testMessage) == static_cast(HasReturnvaluesIF::RETURN_OK)); + REQUIRE(testMessage.getCommand() == static_cast(ActionMessage::STEP_FAILED)); + REQUIRE(ActionMessage::getReturnCode(&testMessage) == static_cast(StorageManagerIF::ILLEGAL_STORAGE_ID)); + REQUIRE(ActionMessage::getStep(&testMessage) == 0); + } + + + SECTION("Data Reply"){ + + } +} diff --git a/unittest/tests/action/TestActionHelper.h b/unittest/tests/action/TestActionHelper.h index 9bc93d3e..4ba417eb 100644 --- a/unittest/tests/action/TestActionHelper.h +++ b/unittest/tests/action/TestActionHelper.h @@ -1,131 +1,132 @@ -//#ifndef UNITTEST_HOSTED_TESTACTIONHELPER_H_ -//#define UNITTEST_HOSTED_TESTACTIONHELPER_H_ -// -//#include -//#include -//#include -//#include -// -// -//class ActionHelperOwnerMockBase: public HasActionsIF { -//public: -// bool getCommandQueueCalled = false; -// bool executeActionCalled = false; -// static const size_t MAX_SIZE = 3; -// uint8_t buffer[MAX_SIZE] = {0, 0, 0}; -// size_t size = 0; -// -// MessageQueueId_t getCommandQueue() const override { -// return tconst::testQueueId; -// } -// -// ReturnValue_t executeAction(ActionId_t actionId, MessageQueueId_t commandedBy, -// const uint8_t* data, size_t size) override { -// executeActionCalled = true; -// if(size > MAX_SIZE){ -// return 0xAFFE; -// } -// this->size = size; -// memcpy(buffer, data, size); -// return HasReturnvaluesIF::RETURN_OK; -// } -// -// void clearBuffer(){ -// this->size = 0; -// for(size_t i = 0; isize; -// } -// if(ptr != nullptr){ -// *ptr = buffer; -// } -// } -//}; -// -// -//class MessageQueueMockBase: public MessageQueueIF { -//public: -// MessageQueueId_t myQueueId = 0; -// bool defaultDestSet = false; -// bool messageSent = false; -// -// -// -// bool wasMessageSent() { -// bool tempMessageSent = messageSent; -// messageSent = false; -// return tempMessageSent; -// } -// -// virtual ReturnValue_t reply( MessageQueueMessage* message ) { -// messageSent = true; -// lastMessage = (*message); -// return HasReturnvaluesIF::RETURN_OK; -// }; -// virtual ReturnValue_t receiveMessage(MessageQueueMessage* message, -// MessageQueueId_t *receivedFrom) { -// (*message) = lastMessage; -// lastMessage.clear(); -// return HasReturnvaluesIF::RETURN_OK; -// } -// virtual ReturnValue_t receiveMessage(MessageQueueMessage* message) { -// (*message) = lastMessage; -// lastMessage.clear(); -// return HasReturnvaluesIF::RETURN_OK; -// } -// virtual ReturnValue_t flush(uint32_t* count) { -// return HasReturnvaluesIF::RETURN_OK; -// } -// virtual MessageQueueId_t getLastPartner() const { -// return tconst::testQueueId; -// } -// virtual MessageQueueId_t getId() const { -// return tconst::testQueueId; -// } -// virtual ReturnValue_t sendMessageFrom( MessageQueueId_t sendTo, -// MessageQueueMessage* message, MessageQueueId_t sentFrom, -// bool ignoreFault = false ) { -// messageSent = true; -// lastMessage = (*message); -// return HasReturnvaluesIF::RETURN_OK; -// } -// virtual ReturnValue_t sendMessage( MessageQueueId_t sendTo, -// MessageQueueMessage* message, bool ignoreFault = false ) override { -// messageSent = true; -// lastMessage = (*message); -// return HasReturnvaluesIF::RETURN_OK; -// } -// virtual ReturnValue_t sendToDefaultFrom( MessageQueueMessage* message, -// MessageQueueId_t sentFrom, bool ignoreFault = false ) { -// messageSent = true; -// lastMessage = (*message); -// return HasReturnvaluesIF::RETURN_OK; -// } -// virtual ReturnValue_t sendToDefault( MessageQueueMessage* message ) { -// messageSent = true; -// lastMessage = (*message); -// return HasReturnvaluesIF::RETURN_OK; -// } -// virtual void setDefaultDestination(MessageQueueId_t defaultDestination) { -// myQueueId = defaultDestination; -// defaultDestSet = true; -// } -// -// virtual MessageQueueId_t getDefaultDestination() const { -// return myQueueId; -// } -// virtual bool isDefaultDestinationSet() const { -// return defaultDestSet; -// } -//private: -// MessageQueueMessage lastMessage; -// -//}; -// -// -//#endif /* UNITTEST_TESTFW_NEWTESTS_TESTACTIONHELPER_H_ */ +#ifndef UNITTEST_HOSTED_TESTACTIONHELPER_H_ +#define UNITTEST_HOSTED_TESTACTIONHELPER_H_ + +#include +#include +#include +#include + + +class ActionHelperOwnerMockBase: public HasActionsIF { +public: + bool getCommandQueueCalled = false; + bool executeActionCalled = false; + static const size_t MAX_SIZE = 3; + uint8_t buffer[MAX_SIZE] = {0, 0, 0}; + size_t size = 0; + + MessageQueueId_t getCommandQueue() const override { + return tconst::testQueueId; + } + + ReturnValue_t executeAction(ActionId_t actionId, MessageQueueId_t commandedBy, + const uint8_t* data, size_t size) override { + executeActionCalled = true; + if(size > MAX_SIZE){ + return 0xAFFE; + } + this->size = size; + memcpy(buffer, data, size); + return HasReturnvaluesIF::RETURN_OK; + } + + void clearBuffer(){ + this->size = 0; + for(size_t i = 0; isize; + } + if(ptr != nullptr){ + *ptr = buffer; + } + } +}; + + +class MessageQueueMockBase: public MessageQueueIF { +public: + MessageQueueId_t myQueueId = 0; + bool defaultDestSet = false; + bool messageSent = false; + + + + bool wasMessageSent() { + bool tempMessageSent = messageSent; + messageSent = false; + return tempMessageSent; + } + + virtual ReturnValue_t reply( MessageQueueMessageIF* message ) { + messageSent = true; + lastMessage = *(dynamic_cast(message)); + return HasReturnvaluesIF::RETURN_OK; + }; + virtual ReturnValue_t receiveMessage(MessageQueueMessageIF* message, + MessageQueueId_t *receivedFrom) { + (*message) = lastMessage; + lastMessage.clear(); + return HasReturnvaluesIF::RETURN_OK; + } + virtual ReturnValue_t receiveMessage(MessageQueueMessageIF* message) { + memcpy(message->getBuffer(), lastMessage.getBuffer(), + message->getMessageSize()); + lastMessage.clear(); + return HasReturnvaluesIF::RETURN_OK; + } + virtual ReturnValue_t flush(uint32_t* count) { + return HasReturnvaluesIF::RETURN_OK; + } + virtual MessageQueueId_t getLastPartner() const { + return tconst::testQueueId; + } + virtual MessageQueueId_t getId() const { + return tconst::testQueueId; + } + virtual ReturnValue_t sendMessageFrom( MessageQueueId_t sendTo, + MessageQueueMessageIF* message, MessageQueueId_t sentFrom, + bool ignoreFault = false ) { + messageSent = true; + lastMessage = *(dynamic_cast(message)); + return HasReturnvaluesIF::RETURN_OK; + } + virtual ReturnValue_t sendMessage( MessageQueueId_t sendTo, + MessageQueueMessageIF* message, bool ignoreFault = false ) override { + messageSent = true; + lastMessage = *(dynamic_cast(message)); + return HasReturnvaluesIF::RETURN_OK; + } + virtual ReturnValue_t sendToDefaultFrom( MessageQueueMessageIF* message, + MessageQueueId_t sentFrom, bool ignoreFault = false ) { + messageSent = true; + lastMessage = *(dynamic_cast(message)); + return HasReturnvaluesIF::RETURN_OK; + } + virtual ReturnValue_t sendToDefault( MessageQueueMessageIF* message ) { + messageSent = true; + lastMessage = *(dynamic_cast(message)); + return HasReturnvaluesIF::RETURN_OK; + } + virtual void setDefaultDestination(MessageQueueId_t defaultDestination) { + myQueueId = defaultDestination; + defaultDestSet = true; + } + + virtual MessageQueueId_t getDefaultDestination() const { + return myQueueId; + } + virtual bool isDefaultDestinationSet() const { + return defaultDestSet; + } +private: + MessageQueueMessage lastMessage; + +}; + + +#endif /* UNITTEST_TESTFW_NEWTESTS_TESTACTIONHELPER_H_ */ diff --git a/unittest/tests/container/RingBufferTest.cpp b/unittest/tests/container/RingBufferTest.cpp index 8b82d407..9c1c8a23 100644 --- a/unittest/tests/container/RingBufferTest.cpp +++ b/unittest/tests/container/RingBufferTest.cpp @@ -1,7 +1,7 @@ -#include -#include #include "../../core/CatchDefinitions.h" +#include "../../container/SimpleRingBuffer.h" +#include #include TEST_CASE("Ring Buffer Test" , "[RingBufferTest]") { diff --git a/unittest/tests/container/TestArrayList.cpp b/unittest/tests/container/TestArrayList.cpp index 914188cb..2f884276 100644 --- a/unittest/tests/container/TestArrayList.cpp +++ b/unittest/tests/container/TestArrayList.cpp @@ -1,5 +1,6 @@ -#include -#include +#include "../../container/ArrayList.h" +#include "../../returnvalues/HasReturnvaluesIF.h" + #include #include "../../core/CatchDefinitions.h" diff --git a/unittest/tests/container/TestDynamicFifo.cpp b/unittest/tests/container/TestDynamicFifo.cpp index 6c9b7415..bb19131e 100644 --- a/unittest/tests/container/TestDynamicFifo.cpp +++ b/unittest/tests/container/TestDynamicFifo.cpp @@ -1,7 +1,7 @@ -#include -#include -#include +#include "../../container/DynamicFIFO.h" +#include "../../container/FIFO.h" +#include "../../returnvalues/HasReturnvaluesIF.h" #include #include diff --git a/unittest/tests/container/TestFifo.cpp b/unittest/tests/container/TestFifo.cpp index 3775f424..bd727e00 100644 --- a/unittest/tests/container/TestFifo.cpp +++ b/unittest/tests/container/TestFifo.cpp @@ -1,7 +1,7 @@ -#include -#include -#include +#include "../../container/DynamicFIFO.h" +#include "../../container/FIFO.h" +#include "../../returnvalues/HasReturnvaluesIF.h" #include #include "../../core/CatchDefinitions.h" diff --git a/unittest/tests/container/TestFixedArrayList.cpp b/unittest/tests/container/TestFixedArrayList.cpp index 737932e3..5a1bd280 100644 --- a/unittest/tests/container/TestFixedArrayList.cpp +++ b/unittest/tests/container/TestFixedArrayList.cpp @@ -1,7 +1,7 @@ #include "../../core/CatchDefinitions.h" -#include -#include +#include "../../container/FixedArrayList.h" +#include "../../returnvalues/HasReturnvaluesIF.h" #include diff --git a/unittest/tests/container/TestFixedMap.cpp b/unittest/tests/container/TestFixedMap.cpp index 079062f0..da0c84e3 100644 --- a/unittest/tests/container/TestFixedMap.cpp +++ b/unittest/tests/container/TestFixedMap.cpp @@ -1,5 +1,5 @@ -#include -#include +#include "../../container/FixedMap.h" +#include "../../returnvalues/HasReturnvaluesIF.h" #include #include "../../core/CatchDefinitions.h" diff --git a/unittest/tests/container/TestFixedOrderedMultimap.cpp b/unittest/tests/container/TestFixedOrderedMultimap.cpp index 95194cb5..e625b559 100644 --- a/unittest/tests/container/TestFixedOrderedMultimap.cpp +++ b/unittest/tests/container/TestFixedOrderedMultimap.cpp @@ -1,5 +1,5 @@ -#include -#include +#include "../../container/FixedOrderedMultimap.h" +#include "../../returnvalues/HasReturnvaluesIF.h" #include #include "../../core/CatchDefinitions.h" diff --git a/unittest/tests/osal/TestMessageQueue.cpp b/unittest/tests/osal/TestMessageQueue.cpp index 8e59fa08..441d32e7 100644 --- a/unittest/tests/osal/TestMessageQueue.cpp +++ b/unittest/tests/osal/TestMessageQueue.cpp @@ -1,8 +1,8 @@ -#include -#include -#include "catch.hpp" +#include "../../ipc/MessageQueueIF.h" +#include "../../ipc/QueueFactory.h" +#include #include -#include "core/CatchDefinitions.h" +#include "../../core/CatchDefinitions.h" TEST_CASE("MessageQueue Basic Test","[TestMq]") { MessageQueueIF* testSenderMq = diff --git a/unittest/tests/serialize/TestSerialBufferAdapter.cpp b/unittest/tests/serialize/TestSerialBufferAdapter.cpp index 9919ed84..07cd3f9c 100644 --- a/unittest/tests/serialize/TestSerialBufferAdapter.cpp +++ b/unittest/tests/serialize/TestSerialBufferAdapter.cpp @@ -1,4 +1,4 @@ -#include +#include "../../serialize/SerialBufferAdapter.h" #include #include "../../core/CatchDefinitions.h" diff --git a/unittest/tests/serialize/TestSerialLinkedPacket.cpp b/unittest/tests/serialize/TestSerialLinkedPacket.cpp index 0a09e430..fbe48894 100644 --- a/unittest/tests/serialize/TestSerialLinkedPacket.cpp +++ b/unittest/tests/serialize/TestSerialLinkedPacket.cpp @@ -1,8 +1,9 @@ -#include +#include "TestSerialLinkedPacket.h" +#include "../../core/CatchDefinitions.h" + +#include "../../globalfunctions/arrayprinter.h" #include -#include "../../core/CatchDefinitions.h" -#include "TestSerialLinkedPacket.h" TEST_CASE("Serial Linked Packet" , "[SerLinkPacket]") { diff --git a/unittest/tests/serialize/TestSerialization.cpp b/unittest/tests/serialize/TestSerialization.cpp index 4c9ba181..6e31170a 100644 --- a/unittest/tests/serialize/TestSerialization.cpp +++ b/unittest/tests/serialize/TestSerialization.cpp @@ -1,4 +1,4 @@ -#include +#include "../../serialize/SerializeAdapter.h" #include "catch.hpp" #include