test_caps_word_unicodemap.cpp (3632B)
1 // Copyright 2022 Google LLC 2 // 3 // This program is free software: you can redistribute it and/or modify 4 // it under the terms of the GNU General Public License as published by 5 // the Free Software Foundation, either version 2 of the License, or 6 // (at your option) any later version. 7 // 8 // This program is distributed in the hope that it will be useful, 9 // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 // GNU General Public License for more details. 12 // 13 // You should have received a copy of the GNU General Public License 14 // along with this program. If not, see <http://www.gnu.org/licenses/>. 15 16 #include "keyboard_report_util.hpp" 17 #include "keycode.h" 18 #include "test_common.hpp" 19 #include "test_fixture.hpp" 20 #include "test_keymap_key.hpp" 21 22 using ::testing::_; 23 using ::testing::AnyNumber; 24 using ::testing::AnyOf; 25 using ::testing::InSequence; 26 27 extern "C" { 28 enum unicode_names { 29 ENDASH, 30 EMDASH, 31 DELTA_LOWERCASE, 32 DELTA_UPPERCASE, 33 }; 34 35 const uint32_t unicode_map[] PROGMEM = { 36 [ENDASH] = 0x2013, 37 [EMDASH] = 0x2014, 38 [DELTA_LOWERCASE] = 0x03b4, 39 [DELTA_UPPERCASE] = 0x0394, 40 }; 41 42 #define U_DASH UP(ENDASH, EMDASH) 43 #define U_DELTA UP(DELTA_LOWERCASE, DELTA_UPPERCASE) 44 45 bool caps_word_press_user(uint16_t keycode) { 46 switch (keycode) { 47 // Keycodes that continue Caps Word, with shift applied. 48 case U_DELTA: 49 add_weak_mods(MOD_BIT(KC_LSFT)); // Apply shift to next key. 50 return true; 51 52 // Keycodes that continue Caps Word, without shifting. 53 case U_DASH: 54 return true; 55 56 default: 57 return false; // Deactivate Caps Word. 58 } 59 } 60 } // extern "C" 61 62 class CapsWord : public TestFixture { 63 public: 64 void SetUp() override { 65 caps_word_off(); 66 } 67 }; 68 69 // Tests that typing U_DELTA while Caps Word is on sends the uppercase Delta. 70 TEST_F(CapsWord, ShiftedUnicodeMapKey) { 71 TestDriver driver; 72 KeymapKey key_delta(0, 0, 0, U_DELTA); 73 KeymapKey key_spc(0, 1, 0, KC_SPC); 74 set_keymap({key_delta, key_spc}); 75 76 // Allow any number of reports with no keys or only KC_LSFT and KC_LCTL. 77 // clang-format off 78 EXPECT_CALL(driver, send_keyboard_mock(AnyOf( 79 KeyboardReport(), 80 KeyboardReport(KC_LSFT), 81 KeyboardReport(KC_LCTL, KC_LSFT)))) 82 .Times(AnyNumber()); 83 // clang-format on 84 { // Expect: "Uppercase Delta, space, lowercase delta". 85 InSequence s; 86 EXPECT_UNICODE(driver, unicode_map[DELTA_UPPERCASE]); 87 EXPECT_REPORT(driver, (KC_SPC)); 88 EXPECT_UNICODE(driver, unicode_map[DELTA_LOWERCASE]); 89 } 90 91 // Turn on Caps Word and tap "delta, space, delta". 92 caps_word_on(); 93 tap_keys(key_delta, key_spc, key_delta); 94 95 EXPECT_EQ(is_caps_word_on(), false); 96 VERIFY_AND_CLEAR(driver); 97 } 98 99 // Tests typing U_ENDASH while Caps Word is on. 100 TEST_F(CapsWord, UnshiftedUnicodeMapKey) { 101 TestDriver driver; 102 KeymapKey key_dash(0, 0, 0, U_DASH); 103 set_keymap({key_dash}); 104 105 // Allow any number of reports with no keys or only KC_LSFT and KC_LCTL. 106 // clang-format off 107 EXPECT_CALL(driver, send_keyboard_mock(AnyOf( 108 KeyboardReport(), 109 KeyboardReport(KC_LSFT), 110 KeyboardReport(KC_LCTL, KC_LSFT)))) 111 .Times(AnyNumber()); 112 // clang-format on 113 EXPECT_UNICODE(driver, unicode_map[ENDASH]); 114 115 // Turn on Caps Word and tap U_DASH key. 116 caps_word_on(); 117 tap_key(key_dash); 118 119 EXPECT_EQ(is_caps_word_on(), true); 120 VERIFY_AND_CLEAR(driver); 121 }