From 36f820be7e80bc8f1f5489373708356cf142c269 Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Sun, 18 Jun 2017 23:49:38 +0300 Subject: Add a test fixture It only initializes QMK once, and clears the matrix after each test. --- tests/basic/test.cpp | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) (limited to 'tests/basic') diff --git a/tests/basic/test.cpp b/tests/basic/test.cpp index 398063fcaa..26a09585ca 100644 --- a/tests/basic/test.cpp +++ b/tests/basic/test.cpp @@ -18,10 +18,10 @@ #include "gmock/gmock.h" #include "quantum.h" -#include "keyboard.h" #include "test_driver.h" #include "test_matrix.h" #include "keyboard_report_util.h" +#include "test_fixture.h" using testing::_; using testing::Return; @@ -33,35 +33,28 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { }, }; -TEST(KeyPress, SendKeyboardIsNotCalledWhenNoKeyIsPressed) { +class KeyPress : public TestFixture {}; + +TEST_F(KeyPress, SendKeyboardIsNotCalledWhenNoKeyIsPressed) { TestDriver driver; - EXPECT_CALL(driver, send_keyboard_mock(_)); - keyboard_init(); EXPECT_CALL(driver, keyboard_leds_mock()).WillRepeatedly(Return(0)); EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); keyboard_task(); } -TEST(KeyPress, CorrectKeyIsReportedWhenPressed) { +TEST_F(KeyPress, CorrectKeyIsReportedWhenPressed) { TestDriver driver; - EXPECT_CALL(driver, send_keyboard_mock(_)); - keyboard_init(); press_key(0, 0); EXPECT_CALL(driver, keyboard_leds_mock()).WillRepeatedly(Return(0)); EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_A))); keyboard_task(); } -TEST(KeyPress, CorrectKeysAreReportedWhenTwoKeysArePressed) { +TEST_F(KeyPress, CorrectKeysAreReportedWhenTwoKeysArePressed) { TestDriver driver; - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); - keyboard_init(); press_key(1, 0); press_key(0, 1); EXPECT_CALL(driver, keyboard_leds_mock()).WillRepeatedly(Return(0)); - //TODO: This is a left-over from the previous test and need to be fixed - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); - keyboard_task(); //Note that QMK only processes one key at a time EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_B))); keyboard_task(); -- cgit v1.2.3