summaryrefslogtreecommitdiffstats
path: root/tests/basic
diff options
context:
space:
mode:
authorFred Sundvik <fsundvik@gmail.com>2017-06-18 23:49:38 +0300
committerFred Sundvik <fsundvik@gmail.com>2017-06-18 23:49:38 +0300
commit36f820be7e80bc8f1f5489373708356cf142c269 (patch)
treecf3561b80650e536a2c41f0e3bb4bc70635b6435 /tests/basic
parente85b1857968d4c0378b9778650c30b9d2bca3ea9 (diff)
Add a test fixture
It only initializes QMK once, and clears the matrix after each test.
Diffstat (limited to 'tests/basic')
-rw-r--r--tests/basic/test.cpp19
1 files changed, 6 insertions, 13 deletions
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();