Skip to content

Commit

Permalink
✅ (ut): CoreEventQueue - Add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ladislas committed May 4, 2022
1 parent 26a9bec commit 164eed3
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 0 deletions.
8 changes: 8 additions & 0 deletions drivers/CoreEventQueue/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,11 @@ target_sources(CoreEventQueue
)

target_link_libraries(CoreEventQueue mbed-os)

if (${CMAKE_PROJECT_NAME} STREQUAL "LekaOSUnitTests")

leka_unit_tests_sources(
tests/CoreEventQueue_test.cpp
)

endif()
72 changes: 72 additions & 0 deletions drivers/CoreEventQueue/tests/CoreEventQueue_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// Leka - LekaOS
// Copyright 2021 APF France handicap
// SPDX-License-Identifier: Apache-2.0

#include "CoreEventQueue.h"
#include <chrono>

#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "mocks/leka/EventQueue.h"

using namespace leka;
using namespace std::chrono;

using ::testing::MockFunction;

class CoreEventQueueTest : public ::testing::Test
{
protected:
// void SetUp() override {}
// void TearDown() override {}

CoreEventQueue event_queue {};

// ? Instantiation of mock::EventQueue is needed to setup the underlying stubs that will make the mock work
// ? correctly. Without it UT are failing
// TODO (@ladislas) - review mocks/stubs to remove the need of the object, replace with setup/teardown functions
mock::EventQueue _ {};
};

TEST_F(CoreEventQueueTest, initialisation)
{
ASSERT_NE(&event_queue, nullptr);
}

TEST_F(CoreEventQueueTest, dispatchForever)
{
event_queue.dispatch_forever();
}

TEST_F(CoreEventQueueTest, call)
{
MockFunction<void(void)> mock;
EXPECT_CALL(mock, Call()).Times(1);

event_queue.dispatch_forever();

event_queue.call(mock.AsStdFunction());
}

TEST_F(CoreEventQueueTest, callEvery)
{
MockFunction<void(void)> mock;
EXPECT_CALL(mock, Call()).Times(1);

event_queue.dispatch_forever();

event_queue.call_every(2s, mock.AsStdFunction());
}

TEST_F(CoreEventQueueTest, callMbedCallback)
{
MockFunction<void(void)> mock;

EXPECT_CALL(mock, Call()).Times(1);

auto func = [&] { mock.Call(); };

event_queue.dispatch_forever();

event_queue.callMbedCallback(mbed::callback(func));
}

0 comments on commit 164eed3

Please sign in to comment.