Skip to content

Commit

Permalink
✅ (CoreInterruptIn): Add CoreInterruptIn_test
Browse files Browse the repository at this point in the history
  • Loading branch information
HPezz committed Jan 23, 2023
1 parent c9a7605 commit 28def88
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 0 deletions.
5 changes: 5 additions & 0 deletions drivers/CoreInterruptIn/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,8 @@ target_link_libraries(CoreInterruptIn
mbed-os
)

if(${CMAKE_PROJECT_NAME} STREQUAL "LekaOSUnitTests")
leka_unit_tests_sources(
tests/CoreInterruptIn_test.cpp
)
endif()
65 changes: 65 additions & 0 deletions drivers/CoreInterruptIn/tests/CoreInterruptIn_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// Leka - LekaOS
// Copyright 2023 APF France handicap
// SPDX-License-Identifier: Apache-2.0

#include "CoreInterruptIn.h"

#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "stubs/mbed/InterruptIn.h"

using namespace leka;
using ::testing::MockFunction;

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

CoreInterruptIn interrupt_in {NC};
};

TEST_F(CoreInterruptInTest, initialisation)
{
ASSERT_NE(&interrupt_in, nullptr);
}

TEST_F(CoreInterruptInTest, readPinDown)
{
auto expected_pin_down_value = 0;
auto pin_value = interrupt_in.read();

EXPECT_EQ(pin_value, expected_pin_down_value);
}

TEST_F(CoreInterruptInTest, readPinUp)
{
auto expected_pin_up_value = 1;
spy_InterruptIn_setValue(1);
auto pin_value = interrupt_in.read();

EXPECT_EQ(pin_value, expected_pin_up_value);
}

TEST_F(CoreInterruptInTest, onRise)
{
MockFunction<void()> mock_function {};
EXPECT_CALL(mock_function, Call).Times(1);

interrupt_in.onRise(mock_function.AsStdFunction());

auto on_rise_callback = spy_InterruptIn_getRiseCallback();
on_rise_callback();
}

TEST_F(CoreInterruptInTest, fall)
{
MockFunction<void()> mock_function {};
EXPECT_CALL(mock_function, Call).Times(1);

interrupt_in.onFall(mock_function.AsStdFunction());

auto on_fall_callback = spy_InterruptIn_getFallCallback();
on_fall_callback();
}
1 change: 1 addition & 0 deletions tests/unit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ leka_register_unit_tests_for_driver(CoreEventQueue)
leka_register_unit_tests_for_driver(CoreFlashMemory)
leka_register_unit_tests_for_driver(CoreHTS)
leka_register_unit_tests_for_driver(CoreI2C)
leka_register_unit_tests_for_driver(CoreInterruptIn)
leka_register_unit_tests_for_driver(CoreIMU)
leka_register_unit_tests_for_driver(CoreIOExpander)
leka_register_unit_tests_for_driver(CoreLED)
Expand Down

0 comments on commit 28def88

Please sign in to comment.