summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile2
-rw-r--r--build_full_test.mk30
-rw-r--r--build_keyboard.mk137
-rw-r--r--build_test.mk10
-rw-r--r--common.mk9
-rw-r--r--common_features.mk153
-rw-r--r--testlist.mk4
-rw-r--r--tests/basic/config.h24
-rw-r--r--tests/basic/rules.mk16
-rw-r--r--tests/basic/test.cpp60
-rw-r--r--tests/test_common/keyboard_report_util.cpp76
-rw-r--r--tests/test_common/keyboard_report_util.h39
-rw-r--r--tests/test_common/matrix.c60
-rw-r--r--tests/test_common/test_driver.cpp57
-rw-r--r--tests/test_common/test_driver.h48
-rw-r--r--tests/test_common/test_fixture.cpp36
-rw-r--r--tests/test_common/test_fixture.h28
-rw-r--r--tests/test_common/test_matrix.h32
-rw-r--r--tmk_core/common.mk7
-rw-r--r--tmk_core/common/action_util.c204
-rw-r--r--tmk_core/common/action_util.h16
-rw-r--r--tmk_core/common/eeprom.h2
-rw-r--r--tmk_core/common/progmem.h2
-rw-r--r--tmk_core/common/report.c207
-rw-r--r--tmk_core/common/report.h14
-rw-r--r--tmk_core/common/test/bootloader.c19
-rw-r--r--tmk_core/common/test/eeprom.c98
-rw-r--r--tmk_core/common/test/suspend.c17
-rw-r--r--tmk_core/common/test/timer.c30
-rw-r--r--tmk_core/common/wait.h9
30 files changed, 1095 insertions, 351 deletions
diff --git a/Makefile b/Makefile
index 6a93692bf6..f789409b7e 100644
--- a/Makefile
+++ b/Makefile
@@ -419,7 +419,7 @@ define BUILD_TEST
MAKE_TARGET := $2
COMMAND := $1
MAKE_CMD := $$(MAKE) -r -R -C $(ROOT_DIR) -f build_test.mk $$(MAKE_TARGET)
- MAKE_VARS := TEST=$$(TEST_NAME)
+ MAKE_VARS := TEST=$$(TEST_NAME) FULL_TESTS=$$(FULL_TESTS)
MAKE_MSG := $$(MSG_MAKE_TEST)
$$(eval $$(call BUILD))
ifneq ($$(MAKE_TARGET),clean)
diff --git a/build_full_test.mk b/build_full_test.mk
new file mode 100644
index 0000000000..bfd89174de
--- /dev/null
+++ b/build_full_test.mk
@@ -0,0 +1,30 @@
+# Copyright 2017 Fred Sundvik
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+#include $(TMK_PATH)/protocol.mk
+
+TEST_PATH=tests/$(TEST)
+
+$(TEST)_SRC= \
+ $(TEST_PATH)/test.cpp \
+ $(TMK_COMMON_SRC) \
+ $(QUANTUM_SRC) \
+ tests/test_common/matrix.c \
+ tests/test_common/test_driver.cpp \
+ tests/test_common/keyboard_report_util.cpp \
+ tests/test_common/test_fixture.cpp
+$(TEST)_DEFS=$(TMK_COMMON_DEFS)
+$(TEST)_CONFIG=$(TEST_PATH)/config.h
+VPATH+=$(TOP_DIR)/tests/test_common
diff --git a/build_keyboard.mk b/build_keyboard.mk
index 36eab3a9e5..3ec389ac9f 100644
--- a/build_keyboard.mk
+++ b/build_keyboard.mk
@@ -31,8 +31,6 @@ $(error MASTER does not have a valid value(left/right))
endif
endif
-
-
KEYBOARD_PATH := keyboards/$(KEYBOARD)
KEYBOARD_C := $(KEYBOARD_PATH)/$(KEYBOARD).c
@@ -42,7 +40,6 @@ else
$(error "$(KEYBOARD_C)" does not exist)
endif
-
ifneq ($(SUBPROJECT),)
SUBPROJECT_PATH := keyboards/$(KEYBOARD)/$(SUBPROJECT)
SUBPROJECT_C := $(SUBPROJECT_PATH)/$(SUBPROJECT).c
@@ -118,141 +115,12 @@ endif
# # project specific files
SRC += $(KEYBOARD_C) \
$(KEYMAP_C) \
- $(QUANTUM_DIR)/quantum.c \
- $(QUANTUM_DIR)/keymap_common.c \
- $(QUANTUM_DIR)/keycode_config.c \
- $(QUANTUM_DIR)/process_keycode/process_leader.c
+ $(QUANTUM_SRC)
ifneq ($(SUBPROJECT),)
SRC += $(SUBPROJECT_C)
endif
-ifndef CUSTOM_MATRIX
- SRC += $(QUANTUM_DIR)/matrix.c
-endif
-
-ifeq ($(strip $(API_SYSEX_ENABLE)), yes)
- OPT_DEFS += -DAPI_SYSEX_ENABLE
- SRC += $(QUANTUM_DIR)/api/api_sysex.c
- OPT_DEFS += -DAPI_ENABLE
- SRC += $(QUANTUM_DIR)/api.c
- MIDI_ENABLE=yes
-endif
-
-MUSIC_ENABLE := 0
-
-ifeq ($(strip $(AUDIO_ENABLE)), yes)
- OPT_DEFS += -DAUDIO_ENABLE
- MUSIC_ENABLE := 1
- SRC += $(QUANTUM_DIR)/process_keycode/process_audio.c
- SRC += $(QUANTUM_DIR)/audio/audio.c
- SRC += $(QUANTUM_DIR)/audio/voices.c
- SRC += $(QUANTUM_DIR)/audio/luts.c
-endif
-
-ifeq ($(strip $(MIDI_ENABLE)), yes)
- OPT_DEFS += -DMIDI_ENABLE
- MUSIC_ENABLE := 1
- SRC += $(QUANTUM_DIR)/process_keycode/process_midi.c
-endif
-
-ifeq ($(MUSIC_ENABLE), 1)
- SRC += $(QUANTUM_DIR)/process_keycode/process_music.c
-endif
-
-ifeq ($(strip $(COMBO_ENABLE)), yes)
- OPT_DEFS += -DCOMBO_ENABLE
- SRC += $(QUANTUM_DIR)/process_keycode/process_combo.c
-endif
-
-ifeq ($(strip $(VIRTSER_ENABLE)), yes)
- OPT_DEFS += -DVIRTSER_ENABLE
-endif
-
-ifeq ($(strip $(FAUXCLICKY_ENABLE)), yes)
- OPT_DEFS += -DFAUXCLICKY_ENABLE
- SRC += $(QUANTUM_DIR)/fauxclicky.c
-endif
-
-ifeq ($(strip $(UCIS_ENABLE)), yes)
- OPT_DEFS += -DUCIS_ENABLE
- UNICODE_COMMON = yes
- SRC += $(QUANTUM_DIR)/process_keycode/process_ucis.c
-endif
-
-ifeq ($(strip $(UNICODEMAP_ENABLE)), yes)
- OPT_DEFS += -DUNICODEMAP_ENABLE
- UNICODE_COMMON = yes
- SRC += $(QUANTUM_DIR)/process_keycode/process_unicodemap.c
-endif
-
-ifeq ($(strip $(UNICODE_ENABLE)), yes)
- OPT_DEFS += -DUNICODE_ENABLE
- UNICODE_COMMON = yes
- SRC += $(QUANTUM_DIR)/process_keycode/process_unicode.c
-endif
-
-ifeq ($(strip $(UNICODE_COMMON)), yes)
- SRC += $(QUANTUM_DIR)/process_keycode/process_unicode_common.c
-endif
-
-ifeq ($(strip $(RGBLIGHT_ENABLE)), yes)
- OPT_DEFS += -DRGBLIGHT_ENABLE
- SRC += $(QUANTUM_DIR)/light_ws2812.c
- SRC += $(QUANTUM_DIR)/rgblight.c
- CIE1931_CURVE = yes
- LED_BREATHING_TABLE = yes
-endif
-
-ifeq ($(strip $(TAP_DANCE_ENABLE)), yes)
- OPT_DEFS += -DTAP_DANCE_ENABLE
- SRC += $(QUANTUM_DIR)/process_keycode/process_tap_dance.c
-endif
-
-ifeq ($(strip $(PRINTING_ENABLE)), yes)
- OPT_DEFS += -DPRINTING_ENABLE
- SRC += $(QUANTUM_DIR)/process_keycode/process_printer.c
- SRC += $(TMK_DIR)/protocol/serial_uart.c
-endif
-
-ifeq ($(strip $(SERIAL_LINK_ENABLE)), yes)
- SRC += $(patsubst $(QUANTUM_PATH)/%,%,$(SERIAL_SRC))
- OPT_DEFS += $(SERIAL_DEFS)
- VAPTH += $(SERIAL_PATH)
-endif
-
-ifneq ($(strip $(VARIABLE_TRACE)),)
- SRC += $(QUANTUM_DIR)/variable_trace.c
- OPT_DEFS += -DNUM_TRACED_VARIABLES=$(strip $(VARIABLE_TRACE))
-ifneq ($(strip $(MAX_VARIABLE_TRACE_SIZE)),)
- OPT_DEFS += -DMAX_VARIABLE_TRACE_SIZE=$(strip $(MAX_VARIABLE_TRACE_SIZE))
-endif
-endif
-
-ifeq ($(strip $(LCD_ENABLE)), yes)
- CIE1931_CURVE = yes
-endif
-
-ifeq ($(strip $(BACKLIGHT_ENABLE)), yes)
- ifeq ($(strip $(VISUALIZER_ENABLE)), yes)
- CIE1931_CURVE = yes
- endif
-endif
-
-ifeq ($(strip $(CIE1931_CURVE)), yes)
- OPT_DEFS += -DUSE_CIE1931_CURVE
- LED_TABLES = yes
-endif
-
-ifeq ($(strip $(LED_BREATHING_TABLE)), yes)
- OPT_DEFS += -DUSE_LED_BREATHING_TABLE
- LED_TABLES = yes
-endif
-
-ifeq ($(strip $(LED_TABLES)), yes)
- SRC += $(QUANTUM_DIR)/led_tables.c
-endif
-
# Optimize size but this may cause error "relocation truncated to fit"
#EXTRALDFLAGS = -Wl,--relax
@@ -264,9 +132,10 @@ endif
VPATH += $(KEYBOARD_PATH)
VPATH += $(COMMON_VPATH)
+include common_features.mk
include $(TMK_PATH)/protocol.mk
-
include $(TMK_PATH)/common.mk
+
SRC += $(TMK_COMMON_SRC)
OPT_DEFS += $(TMK_COMMON_DEFS)
EXTRALDFLAGS += $(TMK_COMMON_LDFLAGS)
diff --git a/build_test.mk b/build_test.mk
index ee15a45726..cac2cba509 100644
--- a/build_test.mk
+++ b/build_test.mk
@@ -40,13 +40,23 @@ VPATH +=\
all: elf
VPATH += $(COMMON_VPATH)
+PLATFORM:=TEST
+ifneq ($(filter $(FULL_TESTS),$(TEST)),)
+include tests/$(TEST)/rules.mk
+endif
+
+include common_features.mk
include $(TMK_PATH)/common.mk
include $(QUANTUM_PATH)/serial_link/tests/rules.mk
+ifneq ($(filter $(FULL_TESTS),$(TEST)),)
+include build_full_test.mk
+endif
$(TEST_OBJ)/$(TEST)_SRC := $($(TEST)_SRC)
$(TEST_OBJ)/$(TEST)_INC := $($(TEST)_INC) $(VPATH) $(GTEST_INC)
$(TEST_OBJ)/$(TEST)_DEFS := $($(TEST)_DEFS)
+$(TEST_OBJ)/$(TEST)_CONFIG := $($(TEST)_CONFIG)
include $(TMK_PATH)/native.mk
include $(TMK_PATH)/rules.mk
diff --git a/common.mk b/common.mk
index c4b9394a24..f87c209341 100644
--- a/common.mk
+++ b/common.mk
@@ -11,17 +11,10 @@ QUANTUM_PATH = $(TOP_DIR)/$(QUANTUM_DIR)
BUILD_DIR := $(TOP_DIR)/.build
-SERIAL_DIR := $(QUANTUM_DIR)/serial_link
-SERIAL_PATH := $(QUANTUM_PATH)/serial_link
-SERIAL_SRC := $(wildcard $(SERIAL_PATH)/protocol/*.c)
-SERIAL_SRC += $(wildcard $(SERIAL_PATH)/system/*.c)
-SERIAL_DEFS += -DSERIAL_LINK_ENABLE
-
COMMON_VPATH := $(TOP_DIR)
COMMON_VPATH += $(TMK_PATH)
COMMON_VPATH += $(QUANTUM_PATH)
COMMON_VPATH += $(QUANTUM_PATH)/keymap_extras
COMMON_VPATH += $(QUANTUM_PATH)/audio
COMMON_VPATH += $(QUANTUM_PATH)/process_keycode
-COMMON_VPATH += $(QUANTUM_PATH)/api
-COMMON_VPATH += $(SERIAL_PATH) \ No newline at end of file
+COMMON_VPATH += $(QUANTUM_PATH)/api \ No newline at end of file
diff --git a/common_features.mk b/common_features.mk
new file mode 100644
index 0000000000..f5e7af01fa
--- /dev/null
+++ b/common_features.mk
@@ -0,0 +1,153 @@
+# Copyright 2017 Fred Sundvik
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+SERIAL_DIR := $(QUANTUM_DIR)/serial_link
+SERIAL_PATH := $(QUANTUM_PATH)/serial_link
+SERIAL_SRC := $(wildcard $(SERIAL_PATH)/protocol/*.c)
+SERIAL_SRC += $(wildcard $(SERIAL_PATH)/system/*.c)
+SERIAL_DEFS += -DSERIAL_LINK_ENABLE
+COMMON_VPATH += $(SERIAL_PATH)
+
+ifeq ($(strip $(API_SYSEX_ENABLE)), yes)
+ OPT_DEFS += -DAPI_SYSEX_ENABLE
+ SRC += $(QUANTUM_DIR)/api/api_sysex.c
+ OPT_DEFS += -DAPI_ENABLE
+ SRC += $(QUANTUM_DIR)/api.c
+ MIDI_ENABLE=yes
+endif
+
+MUSIC_ENABLE := 0
+
+ifeq ($(strip $(AUDIO_ENABLE)), yes)
+ OPT_DEFS += -DAUDIO_ENABLE
+ MUSIC_ENABLE := 1
+ SRC += $(QUANTUM_DIR)/process_keycode/process_audio.c
+ SRC += $(QUANTUM_DIR)/audio/audio.c
+ SRC += $(QUANTUM_DIR)/audio/voices.c
+ SRC += $(QUANTUM_DIR)/audio/luts.c
+endif
+
+ifeq ($(strip $(MIDI_ENABLE)), yes)
+ OPT_DEFS += -DMIDI_ENABLE
+ MUSIC_ENABLE := 1
+ SRC += $(QUANTUM_DIR)/process_keycode/process_midi.c
+endif
+
+ifeq ($(MUSIC_ENABLE), 1)
+ SRC += $(QUANTUM_DIR)/process_keycode/process_music.c
+endif
+
+ifeq ($(strip $(COMBO_ENABLE)), yes)
+ OPT_DEFS += -DCOMBO_ENABLE
+ SRC += $(QUANTUM_DIR)/process_keycode/process_combo.c
+endif
+
+ifeq ($(strip $(VIRTSER_ENABLE)), yes)
+ OPT_DEFS += -DVIRTSER_ENABLE
+endif
+
+ifeq ($(strip $(FAUXCLICKY_ENABLE)), yes)
+ OPT_DEFS += -DFAUXCLICKY_ENABLE
+ SRC += $(QUANTUM_DIR)/fauxclicky.c
+endif
+
+ifeq ($(strip $(UCIS_ENABLE)), yes)
+ OPT_DEFS += -DUCIS_ENABLE
+ UNICODE_COMMON = yes
+ SRC += $(QUANTUM_DIR)/process_keycode/process_ucis.c
+endif
+
+ifeq ($(strip $(UNICODEMAP_ENABLE)), yes)
+ OPT_DEFS += -DUNICODEMAP_ENABLE
+ UNICODE_COMMON = yes
+ SRC += $(QUANTUM_DIR)/process_keycode/process_unicodemap.c
+endif
+
+ifeq ($(strip $(UNICODE_ENABLE)), yes)
+ OPT_DEFS += -DUNICODE_ENABLE
+ UNICODE_COMMON = yes
+ SRC += $(QUANTUM_DIR)/process_keycode/process_unicode.c
+endif
+
+ifeq ($(strip $(UNICODE_COMMON)), yes)
+ SRC += $(QUANTUM_DIR)/process_keycode/process_unicode_common.c
+endif
+
+ifeq ($(strip $(RGBLIGHT_ENABLE)), yes)
+ OPT_DEFS += -DRGBLIGHT_ENABLE
+ SRC += $(QUANTUM_DIR)/light_ws2812.c
+ SRC += $(QUANTUM_DIR)/rgblight.c
+ CIE1931_CURVE = yes
+ LED_BREATHING_TABLE = yes
+endif
+
+ifeq ($(strip $(TAP_DANCE_ENABLE)), yes)
+ OPT_DEFS += -DTAP_DANCE_ENABLE
+ SRC += $(QUANTUM_DIR)/process_keycode/process_tap_dance.c
+endif
+
+ifeq ($(strip $(PRINTING_ENABLE)), yes)
+ OPT_DEFS += -DPRINTING_ENABLE
+ SRC += $(QUANTUM_DIR)/process_keycode/process_printer.c
+ SRC += $(TMK_DIR)/protocol/serial_uart.c
+endif
+
+ifeq ($(strip $(SERIAL_LINK_ENABLE)), yes)
+ SRC += $(patsubst $(QUANTUM_PATH)/%,%,$(SERIAL_SRC))
+ OPT_DEFS += $(SERIAL_DEFS)
+ VAPTH += $(SERIAL_PATH)
+endif
+
+ifneq ($(strip $(VARIABLE_TRACE)),)
+ SRC += $(QUANTUM_DIR)/variable_trace.c
+ OPT_DEFS += -DNUM_TRACED_VARIABLES=$(strip $(VARIABLE_TRACE))
+ifneq ($(strip $(MAX_VARIABLE_TRACE_SIZE)),)
+ OPT_DEFS += -DMAX_VARIABLE_TRACE_SIZE=$(strip $(MAX_VARIABLE_TRACE_SIZE))
+endif
+endif
+
+ifeq ($(strip $(LCD_ENABLE)), yes)
+ CIE1931_CURVE = yes
+endif
+
+ifeq ($(strip $(BACKLIGHT_ENABLE)), yes)
+ ifeq ($(strip $(VISUALIZER_ENABLE)), yes)
+ CIE1931_CURVE = yes
+ endif
+endif
+
+ifeq ($(strip $(CIE1931_CURVE)), yes)
+ OPT_DEFS += -DUSE_CIE1931_CURVE
+ LED_TABLES = yes
+endif
+
+ifeq ($(strip $(LED_BREATHING_TABLE)), yes)
+ OPT_DEFS += -DUSE_LED_BREATHING_TABLE
+ LED_TABLES = yes
+endif
+
+ifeq ($(strip $(LED_TABLES)), yes)
+ SRC += $(QUANTUM_DIR)/led_tables.c
+endif
+
+QUANTUM_SRC:= \
+ $(QUANTUM_DIR)/quantum.c \
+ $(QUANTUM_DIR)/keymap_common.c \
+ $(QUANTUM_DIR)/keycode_config.c \
+ $(QUANTUM_DIR)/process_keycode/process_leader.c
+
+ifndef CUSTOM_MATRIX
+ QUANTUM_SRC += $(QUANTUM_DIR)/matrix.c
+endif \ No newline at end of file
diff --git a/testlist.mk b/testlist.mk
index 1884d6d3f6..d949fb3eae 100644
--- a/testlist.mk
+++ b/testlist.mk
@@ -1,3 +1,6 @@
+TEST_LIST = $(notdir $(patsubst %/rules.mk,%,$(wildcard $(ROOT_DIR)/tests/*/rules.mk)))
+FULL_TESTS := $(TEST_LIST)
+
include $(ROOT_DIR)/quantum/serial_link/tests/testlist.mk
define VALIDATE_TEST_LIST
@@ -10,4 +13,5 @@ define VALIDATE_TEST_LIST
endif
endef
+
$(eval $(call VALIDATE_TEST_LIST,$(firstword $(TEST_LIST)),$(wordlist 2,9999,$(TEST_LIST)))) \ No newline at end of file
diff --git a/tests/basic/config.h b/tests/basic/config.h
new file mode 100644
index 0000000000..4da8d04253
--- /dev/null
+++ b/tests/basic/config.h
@@ -0,0 +1,24 @@
+/* Copyright 2017 Fred Sundvik
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef TESTS_BASIC_CONFIG_H_
+#define TESTS_BASIC_CONFIG_H_
+
+#define MATRIX_ROWS 2
+#define MATRIX_COLS 2
+
+
+#endif /* TESTS_BASIC_CONFIG_H_ */
diff --git a/tests/basic/rules.mk b/tests/basic/rules.mk
new file mode 100644
index 0000000000..8a906807cf
--- /dev/null
+++ b/tests/basic/rules.mk
@@ -0,0 +1,16 @@
+# Copyright 2017 Fred Sundvik
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+CUSTOM_MATRIX=yes \ No newline at end of file
diff --git a/tests/basic/test.cpp b/tests/basic/test.cpp
new file mode 100644
index 0000000000..1bd5c2762d
--- /dev/null
+++ b/tests/basic/test.cpp
@@ -0,0 +1,60 @@
+/* Copyright 2017 Fred Sundvik
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "gtest/gtest.h"
+#include "gmock/gmock.h"
+
+#include "quantum.h"
+#include "test_driver.h"
+#include "test_matrix.h"
+#include "keyboard_report_util.h"
+#include "test_fixture.h"
+
+using testing::_;
+using testing::Return;
+
+const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
+ [0] = {
+ {KC_A, KC_B},
+ {KC_C, KC_D}
+ },
+};
+
+class KeyPress : public TestFixture {};
+
+TEST_F(KeyPress, SendKeyboardIsNotCalledWhenNoKeyIsPressed) {
+ TestDriver driver;
+ EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0);
+ keyboard_task();
+}
+
+TEST_F(KeyPress, CorrectKeyIsReportedWhenPressed) {
+ TestDriver driver;
+ press_key(0, 0);
+ EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_A)));
+ keyboard_task();
+}
+
+TEST_F(KeyPress, CorrectKeysAreReportedWhenTwoKeysArePressed) {
+ TestDriver driver;
+ press_key(1, 0);
+ press_key(0, 1);
+ //Note that QMK only processes one key at a time
+ EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_B)));
+ keyboard_task();
+ EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_B, KC_C)));
+ keyboard_task();
+}
diff --git a/tests/test_common/keyboard_report_util.cpp b/tests/test_common/keyboard_report_util.cpp
new file mode 100644
index 0000000000..aca4433dd6
--- /dev/null
+++ b/tests/test_common/keyboard_report_util.cpp
@@ -0,0 +1,76 @@
+/* Copyright 2017 Fred Sundvik
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+ #include "keyboard_report_util.h"
+ #include <vector>
+ #include <algorithm>
+ using namespace testing;
+
+ namespace
+ {
+ std::vector<uint8_t> get_keys(const report_keyboard_t& report) {
+ std::vector<uint8_t> result;
+ #if defined(NKRO_ENABLE)
+ #error NKRO support not implemented yet
+ #elif defined(USB_6KRO_ENABLE)
+ #error 6KRO support not implemented yet
+ #else
+ for(size_t i=0; i<KEYBOARD_REPORT_KEYS; i++) {
+ if (report.keys[i]) {
+ result.emplace_back(report.keys[i]);
+ }
+ }
+ #endif
+ std::sort(result.begin(), result.end());
+ return result;
+ }
+ }
+
+bool operator==(const report_keyboard_t& lhs, const report_keyboard_t& rhs) {
+ auto lhskeys = get_keys(lhs);
+ auto rhskeys = get_keys(rhs);
+ return lhs.mods == rhs.mods && lhskeys == rhskeys;
+}
+
+std::ostream& operator<<(std::ostream& stream, const report_keyboard_t& value) {
+ stream << "Keyboard report:" << std::endl;
+ stream << "Mods: " << value.mods << std::endl;
+ // TODO: This should probably print friendly names for the keys
+ for (uint32_t k: get_keys(value)) {
+ stream << k << std::endl;
+ }
+ return stream;
+}
+
+KeyboardReportMatcher::KeyboardReportMatcher(const std::vector<uint8_t>& keys) {
+ // TODO: Support modifiers
+ memset(m_report.raw, 0, sizeof(m_report.raw));
+ for (auto k: keys) {
+ add_key_to_report(&m_report, k);
+ }
+}
+
+bool KeyboardReportMatcher::MatchAndExplain(report_keyboard_t& report, MatchResultListener* listener) const {
+ return m_report == report;
+}
+
+void KeyboardReportMatcher::DescribeTo(::std::ostream* os) const {
+ *os << "is equal to " << m_report;
+}
+
+void KeyboardReportMatcher::DescribeNegationTo(::std::ostream* os) const {
+ *os << "is not equal to " << m_report;
+} \ No newline at end of file
diff --git a/tests/test_common/keyboard_report_util.h b/tests/test_common/keyboard_report_util.h
new file mode 100644
index 0000000000..48543c2053
--- /dev/null
+++ b/tests/test_common/keyboard_report_util.h
@@ -0,0 +1,39 @@
+/* Copyright 2017 Fred Sundvik
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#pragma once
+#include "report.h"
+#include <ostream>
+#include "gmock/gmock.h"
+
+bool operator==(const report_keyboard_t& lhs, const report_keyboard_t& rhs);
+std::ostream& operator<<(std::ostream& stream, const report_keyboard_t& value);
+
+class KeyboardReportMatcher : public testing::MatcherInterface<report_keyboard_t&> {
+ public:
+ KeyboardReportMatcher(const std::vector<uint8_t>& keys);
+ virtual bool MatchAndExplain(report_keyboard_t& report, testing::MatchResultListener* listener) const override;
+ virtual void DescribeTo(::std::ostream* os) const override;
+ virtual void DescribeNegationTo(::std::ostream* os) const override;
+private:
+ report_keyboard_t m_report;
+};
+
+
+template<typename... Ts>
+inline testing::Matcher<report_keyboard_t&> KeyboardReport(Ts... keys) {
+ return testing::MakeMatcher(new KeyboardReportMatcher(std::vector<uint8_t>({keys...})));
+} \ No newline at end of file
diff --git a/tests/test_common/matrix.c b/tests/test_common/matrix.c
new file mode 100644
index 0000000000..0d9fa68b04
--- /dev/null
+++ b/tests/test_common/matrix.c
@@ -0,0 +1,60 @@
+/* Copyright 2017 Fred Sundvik
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#include "matrix.h"
+#include "test_matrix.h"
+#include <string.h>
+
+static matrix_row_t matrix[MATRIX_ROWS] = {};
+
+void matrix_init(void) {
+ clear_all_keys();
+ matrix_init_quantum();
+}
+
+uint8_t matrix_scan(void) {
+ matrix_scan_quantum();
+ return 1;
+}
+
+matrix_row_t matrix_get_row(uint8_t row) {
+ return matrix[row];
+}
+
+void matrix_print(void) {
+
+}
+
+void matrix_init_kb(void) {
+
+}
+
+void matrix_scan_kb(void) {
+
+}
+
+void press_key(uint8_t col, uint8_t row) {
+ matrix[row] |= 1 << col;
+}
+
+void release_key(uint8_t col, uint8_t row) {
+ matrix[row] &= ~(1 << col);
+}
+
+void clear_all_keys(void) {
+ memset(matrix, 0, sizeof(matrix));
+}
diff --git a/tests/test_common/test_driver.cpp b/tests/test_common/test_driver.cpp
new file mode 100644
index 0000000000..feb80563a1
--- /dev/null
+++ b/tests/test_common/test_driver.cpp
@@ -0,0 +1,57 @@
+/* Copyright 2017 Fred Sundvik
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "test_driver.h"
+
+TestDriver* TestDriver::m_this = nullptr;
+
+TestDriver::TestDriver()
+ : m_driver{
+ &TestDriver::keyboard_leds,
+ &TestDriver::send_keyboard,
+ &TestDriver::send_mouse,
+ &TestDriver::send_system,
+ &TestDriver::send_consumer
+ }
+{
+ host_set_driver(&m_driver);
+ m_this = this;
+}
+
+TestDriver::~TestDriver() {
+ m_this = nullptr;
+}
+
+uint8_t TestDriver::keyboard_leds(void) {
+ return m_this->m_leds;
+}
+
+void TestDriver::send_keyboard(report_keyboard_t* report) {
+ m_this->send_keyboard_mock(*report);
+
+}
+
+void TestDriver::send_mouse(report_mouse_t* report) {
+ m_this->send_mouse_mock(*report);
+}
+
+void TestDriver::send_system(uint16_t data) {
+ m_this->send_system_mock(data);
+}
+
+void TestDriver::send_consumer(uint16_t data) {
+ m_this->send_consumer(data);
+}
diff --git a/tests/test_common/test_driver.h b/tests/test_common/test_driver.h
new file mode 100644
index 0000000000..0123fd539b
--- /dev/null
+++ b/tests/test_common/test_driver.h
@@ -0,0 +1,48 @@
+/* Copyright 2017 Fred Sundvik
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef TESTS_TEST_COMMON_TEST_DRIVER_H_
+#define TESTS_TEST_COMMON_TEST_DRIVER_H_
+
+#include "gmock/gmock.h"
+#include <stdint.h>
+#include "host.h"
+#include "keyboard_report_util.h"
+
+
+class TestDriver {
+public:
+ TestDriver();
+ ~TestDriver();
+ void set_leds(uint8_t leds