-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✅ (ut): CoreEventQueue - Add unit tests
- Loading branch information
Showing
2 changed files
with
80 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} |