summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/basic/keymap.c26
-rw-r--r--tests/basic/test_keypress.cpp6
-rw-r--r--tests/basic/test_macro.cpp94
-rw-r--r--tests/test_common/keyboard_report_util.cpp62
-rw-r--r--tests/test_common/matrix.c32
-rw-r--r--tests/test_common/test_driver.cpp35
-rw-r--r--tests/test_common/test_fixture.cpp14
7 files changed, 98 insertions, 171 deletions
diff --git a/tests/basic/keymap.c b/tests/basic/keymap.c
index 5dd9aaeb6e..02b3cc961a 100644
--- a/tests/basic/keymap.c
+++ b/tests/basic/keymap.c
@@ -21,22 +21,24 @@
#define COMBO1 RSFT(LCTL(KC_O))
-const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
- [0] = {
- // 0 1 2 3 4 5 6 7 8 9
- {KC_A, KC_B, KC_NO, KC_LSFT, KC_RSFT, KC_LCTL, COMBO1, SFT_T(KC_P), M(0), KC_NO},
- {KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO},
- {KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO},
- {KC_C, KC_D, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO},
- },
+const uint16_t PROGMEM
+ keymaps[][MATRIX_ROWS][MATRIX_COLS] =
+ {
+ [0] =
+ {
+ // 0 1 2 3 4 5 6 7 8 9
+ {KC_A, KC_B, KC_NO, KC_LSFT, KC_RSFT, KC_LCTL, COMBO1, SFT_T(KC_P), M(0), KC_NO},
+ {KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO},
+ {KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO},
+ {KC_C, KC_D, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO},
+ },
};
const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt) {
if (record->event.pressed) {
- switch(id) {
- case 0:
- return MACRO(D(LSFT), T(H), U(LSFT), T(E), T(L), T(L), T(O), T(SPACE), W(100),
- D(LSFT), T(W), U(LSFT), I(10), T(O), T(R), T(L), T(D), D(LSFT), T(1), U(LSFT), END);
+ switch (id) {
+ case 0:
+ return MACRO(D(LSFT), T(H), U(LSFT), T(E), T(L), T(L), T(O), T(SPACE), W(100), D(LSFT), T(W), U(LSFT), I(10), T(O), T(R), T(L), T(D), D(LSFT), T(1), U(LSFT), END);
}
}
return MACRO_NONE;
diff --git a/tests/basic/test_keypress.cpp b/tests/basic/test_keypress.cpp
index 194b1745b1..e5247911cb 100644
--- a/tests/basic/test_keypress.cpp
+++ b/tests/basic/test_keypress.cpp
@@ -41,15 +41,15 @@ TEST_F(KeyPress, CorrectKeysAreReportedWhenTwoKeysArePressed) {
TestDriver driver;
press_key(1, 0);
press_key(0, 3);
- //Note that QMK only processes one key at a time
- //See issue #1476 for more information
+ // Note that QMK only processes one key at a time
+ // See issue #1476 for more information
EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_B)));
keyboard_task();
EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_B, KC_C)));
keyboard_task();
release_key(1, 0);
release_key(0, 3);
- //Note that the first key released is the first one in the matrix order
+ // Note that the first key released is the first one in the matrix order
EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_C)));
keyboard_task();
EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport()));
diff --git a/tests/basic/test_macro.cpp b/tests/basic/test_macro.cpp
index 80676d5153..a1fa317089 100644
--- a/tests/basic/test_macro.cpp
+++ b/tests/basic/test_macro.cpp
@@ -22,78 +22,50 @@ using testing::InvokeWithoutArgs;
class Macro : public TestFixture {};
-#define AT_TIME(t) WillOnce(InvokeWithoutArgs([current_time]() {EXPECT_EQ(timer_elapsed32(current_time), t);}))
+#define AT_TIME(t) WillOnce(InvokeWithoutArgs([current_time]() { EXPECT_EQ(timer_elapsed32(current_time), t); }))
TEST_F(Macro, PlayASimpleMacro) {
TestDriver driver;
InSequence s;
press_key(8, 0);
uint32_t current_time = timer_read32();
- EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT)))
- .AT_TIME(0);
- EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT, KC_H)))
- .AT_TIME(0);
- EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT)))
- .AT_TIME(0);
- EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport()))
- .AT_TIME(0);
- EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_E)))
- .AT_TIME(0);
+ EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT))).AT_TIME(0);
+ EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT, KC_H))).AT_TIME(0);
+ EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT))).AT_TIME(0);
+ EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).AT_TIME(0);
+ EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_E))).AT_TIME(0);
// The macro system could actually skip these empty keyboard reports
// it should be enough to just send a report with the next key down
- EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport()))
- .AT_TIME(0);
- EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_L)))
- .AT_TIME(0);
- EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport()))
- .AT_TIME(0);
- EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_L)))
- .AT_TIME(0);
- EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport()))
- .AT_TIME(0);
- EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_O)))
- .AT_TIME(0);
- EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport()))
- .AT_TIME(0);
- EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_SPACE)))
- .AT_TIME(0);
- EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport()))
- .AT_TIME(0);
- EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT)))
- .AT_TIME(100);
- EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT, KC_W)))
- .AT_TIME(100);
- EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT)))
- .AT_TIME(100);
- EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport()))
- .AT_TIME(100);
+ EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).AT_TIME(0);
+ EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_L))).AT_TIME(0);
+ EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).AT_TIME(0);
+ EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_L))).AT_TIME(0);
+ EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).AT_TIME(0);
+ EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_O))).AT_TIME(0);
+ EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).AT_TIME(0);
+ EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_SPACE))).AT_TIME(0);
+ EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).AT_TIME(0);
+ EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT))).AT_TIME(100);
+ EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT, KC_W))).AT_TIME(100);
+ EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT))).AT_TIME(100);
+ EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).AT_TIME(100);
EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_O)))
- // BUG: The timer should not really have advanced 10 ms here
- // See issue #1477
+ // BUG: The timer should not really have advanced 10 ms here
+ // See issue #1477
.AT_TIME(110);
EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport()))
- // BUG: The timer should not advance on both keydown and key-up
- // See issue #1477
+ // BUG: The timer should not advance on both keydown and key-up
+ // See issue #1477
.AT_TIME(120);
- EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_R)))
- .AT_TIME(130);
- EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport()))
- .AT_TIME(140);
- EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_L)))
- .AT_TIME(150);
- EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport()))
- .AT_TIME(160);
- EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_D)))
- .AT_TIME(170);
- EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport()))
- .AT_TIME(180);
- EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT)))
- .AT_TIME(190);
- EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT, KC_1)))
- .AT_TIME(200);
- EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT)))
- .AT_TIME(210);
- EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport()))
- .AT_TIME(220);
+ EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_R))).AT_TIME(130);
+ EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).AT_TIME(140);
+ EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_L))).AT_TIME(150);
+ EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).AT_TIME(160);
+ EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_D))).AT_TIME(170);
+ EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).AT_TIME(180);
+ EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT))).AT_TIME(190);
+ EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT, KC_1))).AT_TIME(200);
+ EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT))).AT_TIME(210);
+ EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).AT_TIME(220);
run_one_scan_loop();
} \ No newline at end of file
diff --git a/tests/test_common/keyboard_report_util.cpp b/tests/test_common/keyboard_report_util.cpp
index bf728b9a2a..245072c0ea 100644
--- a/tests/test_common/keyboard_report_util.cpp
+++ b/tests/test_common/keyboard_report_util.cpp
@@ -14,30 +14,29 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
- #include "keyboard_report_util.hpp"
- #include <vector>
- #include <algorithm>
- using namespace testing;
+#include "keyboard_report_util.hpp"
+#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]);
- }
+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;
- }
- }
+ }
+#endif
+ std::sort(result.begin(), result.end());
+ return result;
+}
+} // namespace
bool operator==(const report_keyboard_t& lhs, const report_keyboard_t& rhs) {
auto lhskeys = get_keys(lhs);
@@ -50,7 +49,7 @@ std::ostream& operator<<(std::ostream& stream, const report_keyboard_t& value) {
stream << "Mods: " << (uint32_t)value.mods << std::endl;
stream << "Keys: ";
// TODO: This should probably print friendly names for the keys
- for (uint32_t k: get_keys(value)) {
+ for (uint32_t k : get_keys(value)) {
stream << k << " ";
}
stream << std::endl;
@@ -59,24 +58,17 @@ std::ostream& operator<<(std::ostream& stream, const report_keyboard_t& value) {
KeyboardReportMatcher::KeyboardReportMatcher(const std::vector<uint8_t>& keys) {
memset(m_report.raw, 0, sizeof(m_report.raw));
- for (auto k: keys) {
+ for (auto k : keys) {
if (IS_MOD(k)) {
m_report.mods |= MOD_BIT(k);
- }
- else {
+ } else {
add_key_to_report(&m_report, k);
}
}
}
-bool KeyboardReportMatcher::MatchAndExplain(report_keyboard_t& report, MatchResultListener* listener) const {
- return m_report == report;
-}
+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::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
+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/matrix.c b/tests/test_common/matrix.c
index 4b501039b6..9a92a801c7 100644
--- a/tests/test_common/matrix.c
+++ b/tests/test_common/matrix.c
@@ -14,7 +14,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-
#include "matrix.h"
#include "test_matrix.h"
#include <string.h>
@@ -31,33 +30,18 @@ uint8_t matrix_scan(void) {
return 1;
}
-matrix_row_t matrix_get_row(uint8_t row) {
- return matrix[row];
-}
-
-void matrix_print(void) {
-
-}
-
-void matrix_init_kb(void) {
+matrix_row_t matrix_get_row(uint8_t row) { return matrix[row]; }
-}
+void matrix_print(void) {}
-void matrix_scan_kb(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 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 release_key(uint8_t col, uint8_t row) { matrix[row] &= ~(1 << col); }
-void clear_all_keys(void) {
- memset(matrix, 0, sizeof(matrix));
-}
+void clear_all_keys(void) { memset(matrix, 0, sizeof(matrix)); }
-void led_set(uint8_t usb_led) {
-}
+void led_set(uint8_t usb_led) {}
diff --git a/tests/test_common/test_driver.cpp b/tests/test_common/test_driver.cpp
index 5113099698..84e249d838 100644
--- a/tests/test_common/test_driver.cpp
+++ b/tests/test_common/test_driver.cpp
@@ -18,40 +18,19 @@
TestDriver* TestDriver::m_this = nullptr;
-TestDriver::TestDriver()
- : m_driver{
- &TestDriver::keyboard_leds,
- &TestDriver::send_keyboard,
- &TestDriver::send_mouse,
- &TestDriver::send_system,
- &TestDriver::send_consumer
- }
-{
+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;
-}
+TestDriver::~TestDriver() { m_this = nullptr; }
-uint8_t TestDriver::keyboard_leds(void) {
- return m_this->m_leds;
-}
+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_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_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_system(uint16_t data) {
- m_this->send_system_mock(data);
-}
-
-void TestDriver::send_consumer(uint16_t data) {
- m_this->send_consumer(data);
-}
+void TestDriver::send_consumer(uint16_t data) { m_this->send_consumer(data); }
diff --git a/tests/test_common/test_fixture.cpp b/tests/test_common/test_fixture.cpp
index d86681eeaa..8caf1fca4a 100644
--- a/tests/test_common/test_fixture.cpp
+++ b/tests/test_common/test_fixture.cpp
@@ -11,14 +11,14 @@ extern "C" {
}
extern "C" {
- void set_time(uint32_t t);
- void advance_time(uint32_t ms);
+void set_time(uint32_t t);
+void advance_time(uint32_t ms);
}
using testing::_;
using testing::AnyNumber;
-using testing::Return;
using testing::Between;
+using testing::Return;
void TestFixture::SetUpTestCase() {
TestDriver driver;
@@ -26,11 +26,9 @@ void TestFixture::SetUpTestCase() {
keyboard_init();
}
-void TestFixture::TearDownTestCase() {
-}
+void TestFixture::TearDownTestCase() {}
-TestFixture::TestFixture() {
-}
+TestFixture::TestFixture() {}
TestFixture::~TestFixture() {
TestDriver driver;
@@ -50,7 +48,7 @@ void TestFixture::run_one_scan_loop() {
}
void TestFixture::idle_for(unsigned time) {
- for (unsigned i=0; i<time; i++) {
+ for (unsigned i = 0; i < time; i++) {
run_one_scan_loop();
}
}