Skip to content

Commit 8e71a02

Browse files
committed
Added additional test.
1 parent b15c98a commit 8e71a02

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

test/hmi/test_keyState/test_keyState.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
1+
#include "../test_dummies.hpp"
12
#include <Arduino-wrapper.h>
3+
#include <board_pins.hpp>
24
#include <input_device_interface/Keypad.hpp>
5+
#include <iostream>
36
#include <unity.h>
47

58
using namespace fakeit;
69

10+
static void dummyCallback(const KeyId id)
11+
{
12+
std::cout << "dummy callback has been called with key " << id << std::endl;
13+
}
14+
715
void setUp(void)
816
{
17+
isr_collection.clear();
918
}
1019

1120
void tearDown(void)
@@ -18,6 +27,22 @@ void test_default_inactive()
1827
TEST_ASSERT_FALSE(keypad.isKeyPressed(KeyId::TASK1));
1928
}
2029

30+
void test_switch_on_off()
31+
{
32+
Keypad keypad;
33+
keypad.setCallback(dummyCallback);
34+
35+
// set & test "active"
36+
When(Method(ArduinoFake(), digitalRead).Using(board::button::pin::task1)).Return(LOW); // set task 1 button to low
37+
changeButtonState(board::button::pin::task1); // stop task
38+
TEST_ASSERT_TRUE(keypad.isKeyPressed(KeyId::TASK1));
39+
40+
// set & test "inactive"
41+
When(Method(ArduinoFake(), digitalRead).Using(board::button::pin::task1)).Return(HIGH); // set task 1 button to high
42+
changeButtonState(board::button::pin::task1); // stop task
43+
TEST_ASSERT_FALSE(keypad.isKeyPressed(KeyId::TASK1));
44+
}
45+
2146
int main()
2247
{
2348
// irrelevant test doubles
@@ -26,6 +51,7 @@ int main()
2651
UNITY_BEGIN();
2752

2853
RUN_TEST(test_default_inactive);
54+
RUN_TEST(test_switch_on_off);
2955

3056
return UNITY_END();
3157
}

0 commit comments

Comments
 (0)