summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/autocorrect/config.h6
-rw-r--r--tests/autocorrect/test.mk8
-rw-r--r--tests/autocorrect/test_autocorrect.cpp204
-rw-r--r--tests/test_common/test_driver.cpp10
-rw-r--r--tests/test_common/test_driver.hpp6
5 files changed, 223 insertions, 11 deletions
diff --git a/tests/autocorrect/config.h b/tests/autocorrect/config.h
new file mode 100644
index 0000000000..b68bf0c2d5
--- /dev/null
+++ b/tests/autocorrect/config.h
@@ -0,0 +1,6 @@
+// Copyright 2021 Christopher Courtney, aka Drashna Jael're (@drashna) <drashna@live.com>
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+#pragma once
+
+#include "test_common.h"
diff --git a/tests/autocorrect/test.mk b/tests/autocorrect/test.mk
new file mode 100644
index 0000000000..7b97d8cce3
--- /dev/null
+++ b/tests/autocorrect/test.mk
@@ -0,0 +1,8 @@
+# Copyright 2021 Christopher Courtney, aka Drashna Jael're (@drashna) <drashna@live.com>
+# SPDX-License-Identifier: GPL-2.0-or-later
+
+# --------------------------------------------------------------------------------
+# Keep this file, even if it is empty, as a marker that this folder contains tests
+# --------------------------------------------------------------------------------
+
+AUTOCORRECT_ENABLE = yes
diff --git a/tests/autocorrect/test_autocorrect.cpp b/tests/autocorrect/test_autocorrect.cpp
new file mode 100644
index 0000000000..509c1c9ea4
--- /dev/null
+++ b/tests/autocorrect/test_autocorrect.cpp
@@ -0,0 +1,204 @@
+// Copyright 2021 Christopher Courtney, aka Drashna Jael're (@drashna) <drashna@live.com>
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+#include "keycode.h"
+#include "test_common.hpp"
+
+using ::testing::_;
+using ::testing::AnyNumber;
+using ::testing::InSequence;
+
+class AutoCorrect : public TestFixture {
+ public:
+ void SetUp() override {
+ autocorrect_enable();
+ }
+ // Convenience function to tap `key`.
+ void TapKey(KeymapKey key) {
+ key.press();
+ run_one_scan_loop();
+ key.release();
+ run_one_scan_loop();
+ }
+
+ // Taps in order each key in `keys`.
+ template <typename... Ts>
+ void TapKeys(Ts... keys) {
+ for (KeymapKey key : {keys...}) {
+ TapKey(key);
+ }
+ }
+};
+
+// Test that verifies enable/disable/toggling works
+TEST_F(AutoCorrect, OnOffToggle) {
+ TestDriver driver;
+
+ EXPECT_EQ(autocorrect_is_enabled(), true);
+
+ autocorrect_disable();
+ EXPECT_EQ(autocorrect_is_enabled(), false);
+ autocorrect_disable();
+ EXPECT_EQ(autocorrect_is_enabled(), false);
+
+ autocorrect_enable();
+ EXPECT_EQ(autocorrect_is_enabled(), true);
+ autocorrect_enable();
+ EXPECT_EQ(autocorrect_is_enabled(), true);
+
+ autocorrect_toggle();
+ EXPECT_EQ(autocorrect_is_enabled(), false);
+ autocorrect_toggle();
+ EXPECT_EQ(autocorrect_is_enabled(), true);
+
+ testing::Mock::VerifyAndClearExpectations(&driver);
+}
+
+// Test that typing "fales" autocorrects to "false"
+TEST_F(AutoCorrect, fales_to_false_autocorrection) {
+ TestDriver driver;
+ auto key_f = KeymapKey(0, 0, 0, KC_F);
+ auto key_a = KeymapKey(0, 1, 0, KC_A);
+ auto key_l = KeymapKey(0, 2, 0, KC_L);
+ auto key_e = KeymapKey(0, 3, 0, KC_E);
+ auto key_s = KeymapKey(0, 4, 0, KC_S);
+
+ set_keymap({key_f, key_a, key_l, key_e, key_s});
+
+ // Allow any number of empty reports.
+ EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).Times(AnyNumber());
+ { // Expect the following reports in this order.
+ InSequence s;
+ EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_F)));
+ EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_A)));
+ EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_L)));
+ EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_E)));
+ EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_BACKSPACE)));
+ EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_S)));
+ EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_E)));
+ }
+
+ TapKeys(key_f, key_a, key_l, key_e, key_s);
+
+ testing::Mock::VerifyAndClearExpectations(&driver);
+}
+
+// Test that typing "fales" doesn't autocorrect if disabled
+TEST_F(AutoCorrect, fales_disabled_autocorrect) {
+ TestDriver driver;
+ auto key_f = KeymapKey(0, 0, 0, KC_F);
+ auto key_a = KeymapKey(0, 1, 0, KC_A);
+ auto key_l = KeymapKey(0, 2, 0, KC_L);
+ auto key_e = KeymapKey(0, 3, 0, KC_E);
+ auto key_s = KeymapKey(0, 4, 0, KC_S);
+
+ set_keymap({key_f, key_a, key_l, key_e, key_s});
+
+ // Allow any number of empty reports.
+ EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).Times(AnyNumber());
+ { // Expect the following reports in this order.
+ InSequence s;
+ EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_F)));
+ EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_A)));
+ EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_L)));
+ EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_E)));
+ EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_S)));
+ }
+
+ autocorrect_disable();
+ TapKeys(key_f, key_a, key_l, key_e, key_s);
+ autocorrect_enable();
+
+ testing::Mock::VerifyAndClearExpectations(&driver);
+}
+
+// Test that typing "falsify" doesn't autocorrect if disabled
+TEST_F(AutoCorrect, falsify_should_not_autocorrect) {
+ TestDriver driver;
+ auto key_f = KeymapKey(0, 0, 0, KC_F);
+ auto key_a = KeymapKey(0, 1, 0, KC_A);
+ auto key_l = KeymapKey(0, 2, 0, KC_L);
+ auto key_s = KeymapKey(0, 3, 0, KC_S);
+ auto key_i = KeymapKey(0, 4, 0, KC_I);
+ auto key_y = KeymapKey(0, 5, 0, KC_Y);
+
+ set_keymap({key_f, key_a, key_l, key_s, key_i, key_y});
+
+ // Allow any number of empty reports.
+ EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).Times(AnyNumber());
+ { // Expect the following reports in this order.
+ InSequence s;
+ EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_F)));
+ EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_A)));
+ EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_L)));
+ EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_S)));
+ EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_I)));
+ EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_F)));
+ EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_Y)));
+ }
+
+ TapKeys(key_f, key_a, key_l, key_s, key_i, key_f, key_y);
+
+ testing::Mock::VerifyAndClearExpectations(&driver);
+}
+
+// Test that typing "ture" autocorrect to "true"
+TEST_F(AutoCorrect, ture_to_true_autocorrect) {
+ TestDriver driver;
+ auto key_t_code = KeymapKey(0, 0, 0, KC_T);
+ auto key_r = KeymapKey(0, 1, 0, KC_R);
+ auto key_u = KeymapKey(0, 2, 0, KC_U);
+ auto key_e = KeymapKey(0, 3, 0, KC_E);
+ auto key_space = KeymapKey(0, 4, 0, KC_SPACE);
+
+ set_keymap({key_t_code, key_r, key_u, key_e, key_space});
+
+ // Allow any number of empty reports.
+ EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).Times(AnyNumber());
+ { // Expect the following reports in this order.
+ InSequence s;
+ EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_SPACE)));
+ EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_T)));
+ EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_U)));
+ EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_R)));
+ EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_BACKSPACE))).Times(2);
+ EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_R)));
+ EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_U)));
+ EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_E)));
+ }
+
+ TapKeys(key_space, key_t_code, key_u, key_r, key_e);
+
+ testing::Mock::VerifyAndClearExpectations(&driver);
+}
+
+// Test that typing "overture" does not autocorrect
+TEST_F(AutoCorrect, overture_should_not_autocorrect) {
+ TestDriver driver;
+ auto key_t_code = KeymapKey(0, 0, 0, KC_T);
+ auto key_r = KeymapKey(0, 1, 0, KC_R);
+ auto key_u = KeymapKey(0, 2, 0, KC_U);
+ auto key_e = KeymapKey(0, 3, 0, KC_E);
+ auto key_o = KeymapKey(0, 4, 0, KC_O);
+ auto key_v = KeymapKey(0, 5, 0, KC_V);
+
+ set_keymap({key_t_code, key_r, key_u, key_e, key_o, key_v});
+
+ // Allow any number of empty reports.
+ EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).Times(AnyNumber());
+ { // Expect the following reports in this order.
+ InSequence s;
+ EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_O)));
+ EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_V)));
+ EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_E)));
+ EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_R)));
+ EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_T)));
+ EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_U)));
+ EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_R)));
+ EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_E)));
+ }
+
+ TapKeys(key_o, key_v, key_e, key_r, key_t_code, key_u, key_r, key_e);
+
+ testing::Mock::VerifyAndClearExpectations(&driver);
+}
diff --git a/tests/test_common/test_driver.cpp b/tests/test_common/test_driver.cpp
index 86644ab6bd..7ecd4931ed 100644
--- a/tests/test_common/test_driver.cpp
+++ b/tests/test_common/test_driver.cpp
@@ -31,7 +31,7 @@ uint8_t hex_digit_to_keycode(uint8_t digit) {
}
} // namespace
-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_extra} {
host_set_driver(&m_driver);
m_this = this;
}
@@ -53,12 +53,8 @@ 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);
+void TestDriver::send_extra(uint8_t report_id, uint16_t data) {
+ m_this->send_extra_mock(report_id, data);
}
namespace internal {
diff --git a/tests/test_common/test_driver.hpp b/tests/test_common/test_driver.hpp
index b58cfd1ebc..666bfb1fba 100644
--- a/tests/test_common/test_driver.hpp
+++ b/tests/test_common/test_driver.hpp
@@ -32,15 +32,13 @@ class TestDriver {
MOCK_METHOD1(send_keyboard_mock, void(report_keyboard_t&));
MOCK_METHOD1(send_mouse_mock, void(report_mouse_t&));
- MOCK_METHOD1(send_system_mock, void(uint16_t));
- MOCK_METHOD1(send_consumer_mock, void(uint16_t));
+ MOCK_METHOD2(send_extra_mock, void(uint8_t, uint16_t));
private:
static uint8_t keyboard_leds(void);
static void send_keyboard(report_keyboard_t* report);
static void send_mouse(report_mouse_t* report);
- static void send_system(uint16_t data);
- static void send_consumer(uint16_t data);
+ static void send_extra(uint8_t report_id, uint16_t data);
host_driver_t m_driver;
uint8_t m_leds = 0;
static TestDriver* m_this;