Skip to content

Commit b15c98a

Browse files
committed
Create function in test harness to change button state.
1 parent 25c4e12 commit b15c98a

3 files changed

Lines changed: 22 additions & 7 deletions

File tree

test/hmi/test_dummies.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
#include "test_dummies.hpp"
2+
#include <Arduino-wrapper.h>
3+
#include <board_pins.hpp>
4+
#include <cassert>
25
#include <input_device_interface/debouncedIsr.hpp>
36
#include <iomanip>
47
#include <iostream>
8+
#include <iterator>
9+
10+
using namespace fakeit;
511

612
std::map<board::PinType, std::function<void(void)>> isr_collection;
713

@@ -24,3 +30,11 @@ std::function<void(void)> createDebouncer(const std::function<void(void)> handle
2430
{
2531
return handler;
2632
}
33+
34+
void changeButtonState(const board::PinType pin)
35+
{
36+
const auto isr = isr_collection.find(pin); // ISR we expect for that pin
37+
assert(isr != std::end(isr_collection)); // assert we found an ISR
38+
std::cout << "trigger ISR for pin " << static_cast<int>(pin) << std::endl;
39+
isr->second(); // trigger interrupt for button
40+
}

test/hmi/test_dummies.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,8 @@
44
#include <map>
55

66
extern std::map<board::PinType, std::function<void(void)>> isr_collection;
7+
8+
/**
9+
* Triggers a interrupt and sets the internal state.
10+
*/
11+
void changeButtonState(board::PinType pin);

test/hmi/test_hmi/test_hmi.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,10 @@ void test_Controller()
5858
Menu singleMenu(board::getDisplay());
5959
Presenter presenter(singleMenu, board::getStatusIndicators());
6060
ProcessHmiInputs processor(presenter, board::getKeypad());
61-
auto &task1 = std::begin(device::tasks)->second; // we are going to test for task 1
62-
const auto isrTask1 = isr_collection.find(board::button::pin::task1); // ISR we expect for task 1
63-
TEST_ASSERT_NOT_EQUAL(std::end(isr_collection), isrTask1); // assert we found an ISR for task 1 in the list
61+
auto &task1 = std::begin(device::tasks)->second; // we are going to test for task 1
6462

65-
std::cout << "trigger ISR for task 1: 'start task'" << std::endl;
6663
When(Method(ArduinoFake(), digitalRead).Using(board::button::pin::task1)).Return(LOW); // set task 1 button to low
67-
isrTask1->second(); // trigger interrupt for task 1 button
64+
changeButtonState(board::button::pin::task1);
6865

6966
// wait for the task to be running
7067
while (!task1.isRunning())
@@ -75,9 +72,8 @@ void test_Controller()
7572
constexpr int millisecondsToWait = 1000;
7673
std::this_thread::sleep_for(std::chrono::milliseconds(millisecondsToWait)); // wait a defined time
7774

78-
std::cout << "trigger ISR for task 1: 'stop task'" << std::endl;
7975
When(Method(ArduinoFake(), digitalRead).Using(board::button::pin::task1)).Return(LOW); // set task 1 button to low
80-
isrTask1->second(); // stop task
76+
changeButtonState(board::button::pin::task1); // stop task
8177

8278
// wait for the task to be stopped
8379
while (task1.isRunning())

0 commit comments

Comments
 (0)