diff --git a/unittest/controller/testThermalController.cpp b/unittest/controller/testThermalController.cpp index 468d8e2e..47826cb1 100644 --- a/unittest/controller/testThermalController.cpp +++ b/unittest/controller/testThermalController.cpp @@ -7,7 +7,7 @@ #include - +#include "../mocks/EventManagerMock.h" TEST_CASE("Thermal Controller", "[ThermalController]") { const object_id_t THERMAL_CONTROLLER_ID = 0x123; @@ -16,6 +16,10 @@ TEST_CASE("Thermal Controller", "[ThermalController]") { controller.initializeAfterTaskCreation(); + EventManagerMock* eventmanager = + ObjectManager::instance()->get(objects::EVENT_MANAGER); + REQUIRE(eventmanager->isEventInEventList(THERMAL_CONTROLLER_ID, HasModesIF::MODE_INFO) == false); + MessageQueueId_t controllerQueue = controller.getCommandQueue(); CommandMessage modeMessage; @@ -23,23 +27,21 @@ TEST_CASE("Thermal Controller", "[ThermalController]") { ModeMessage::setModeMessage(&modeMessage, ModeMessage::CMD_MODE_COMMAND, ControllerBase::MODE_NORMAL, HasModesIF::SUBMODE_NONE); - MessageQueueIF* commandQueue = QueueFactory::instance()->createMessageQueue( - 5, MessageQueueMessage::MAX_MESSAGE_SIZE); - - commandQueue->sendMessage(controllerQueue,&modeMessage); + MessageQueueIF* commandQueue = + QueueFactory::instance()->createMessageQueue(5, MessageQueueMessage::MAX_MESSAGE_SIZE); + + commandQueue->sendMessage(controllerQueue, &modeMessage); REQUIRE(controller.performOperation(0) == HasReturnvaluesIF::RETURN_OK); + eventmanager->clearEventList(); + thermalControllerDefinitions::ComponentTemperatures componentTemperatures(THERMAL_CONTROLLER_ID); componentTemperatures.read(); REQUIRE(componentTemperatures.rw == 0); - + componentTemperatures.commit(); - ExecutableObjectIF *eventmanager = ObjectManager::instance()->get(objects::EVENT_MANAGER); - eventmanager->performOperation(); - - QueueFactory::instance()->deleteMessageQueue(commandQueue); } \ No newline at end of file diff --git a/unittest/mocks/EventManagerMock.cpp b/unittest/mocks/EventManagerMock.cpp index d3b88a9b..6956c516 100644 --- a/unittest/mocks/EventManagerMock.cpp +++ b/unittest/mocks/EventManagerMock.cpp @@ -4,7 +4,6 @@ EventManagerMock::EventManagerMock() : EventManager(objects::EVENT_MANAGER) {} - ReturnValue_t EventManagerMock::performOperation(uint8_t opCode) { ReturnValue_t result = HasReturnvaluesIF::RETURN_OK; while (result == HasReturnvaluesIF::RETURN_OK) { @@ -12,7 +11,53 @@ ReturnValue_t EventManagerMock::performOperation(uint8_t opCode) { result = eventReportQueue->receiveMessage(&message); if (result == HasReturnvaluesIF::RETURN_OK) { notifyListeners(&message); + eventList.emplace_back(message); } } return HasReturnvaluesIF::RETURN_OK; +} + +const std::list* EventManagerMock::getEventList() { + // call performOperation() to get all events still in the message Queue into the list + this->performOperation(0); + return &eventList; +} + +void EventManagerMock::clearEventList() { // call performOperation() to get all events still in the + // message Queue into the list + this->performOperation(0); + eventList.clear(); +} + +bool EventManagerMock::isEventInEventList(object_id_t object, Event event) { + return isEventInEventList(object, event::getEventId(event)); +} + +bool EventManagerMock::isEventInEventList(object_id_t object, EventId_t eventId) { + // call performOperation() to get all events still in the message Queue into the list + this->performOperation(0); + for (auto iter = eventList.begin(); iter != eventList.end(); iter++) { + if ((iter->getReporter() == object) && (iter->getEventId() == eventId)) { + return true; + } + } + return false; +} + +bool EventManagerMock::isEventInEventList(object_id_t object, Event event, uint32_t parameter1, + uint32_t parameter2) { + return isEventInEventList(object, event::getEventId(event), parameter1, parameter2); +} + +bool EventManagerMock::isEventInEventList(object_id_t object, EventId_t eventId, + uint32_t parameter1, uint32_t parameter2) { + // call performOperation() to get all events still in the message Queue into the list + this->performOperation(0); + for (auto iter = eventList.begin(); iter != eventList.end(); iter++) { + if ((iter->getReporter() == object) && (iter->getEventId() == eventId) && + (iter->getParameter1() == parameter1) && (iter->getParameter2() == parameter2)) { + return true; + } + } + return false; } \ No newline at end of file diff --git a/unittest/mocks/EventManagerMock.h b/unittest/mocks/EventManagerMock.h index 3add4e89..84588a97 100644 --- a/unittest/mocks/EventManagerMock.h +++ b/unittest/mocks/EventManagerMock.h @@ -3,11 +3,25 @@ #include +#include + class EventManagerMock : public EventManager { public: EventManagerMock(); virtual ReturnValue_t performOperation(uint8_t opCode) override; + + const std::list* getEventList(); + void clearEventList(); + + bool isEventInEventList(object_id_t object, Event event); + bool isEventInEventList(object_id_t object, Event event, uint32_t parameter1, uint32_t parameter2); + + bool isEventInEventList(object_id_t object, EventId_t eventId); + bool isEventInEventList(object_id_t object, EventId_t eventId, uint32_t parameter1, uint32_t parameter2); + + private: + std::list eventList; }; #endif /* EVENTMANAGERMOCK_H_ */ \ No newline at end of file