logo

qmk_firmware

custom branch of QMK firmware git clone https://anongit.hacktivis.me/git/qmk_firmware.git

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. #include "keyboard_report_util.hpp"
  16. #include "keycode.h"
  17. #include "test_common.hpp"
  18. #include "test_fixture.hpp"
  19. #include "test_keymap_key.hpp"
  20. using ::testing::_;
  21. using ::testing::AnyNumber;
  22. using ::testing::AnyOf;
  23. using ::testing::InSequence;
  24. extern "C" {
  25. enum unicode_names {
  26. ENDASH,
  27. EMDASH,
  28. DELTA_LOWERCASE,
  29. DELTA_UPPERCASE,
  30. };
  31. const uint32_t unicode_map[] PROGMEM = {
  32. [ENDASH] = 0x2013,
  33. [EMDASH] = 0x2014,
  34. [DELTA_LOWERCASE] = 0x03b4,
  35. [DELTA_UPPERCASE] = 0x0394,
  36. };
  37. #define U_DASH UP(ENDASH, EMDASH)
  38. #define U_DELTA UP(DELTA_LOWERCASE, DELTA_UPPERCASE)
  39. bool caps_word_press_user(uint16_t keycode) {
  40. switch (keycode) {
  41. // Keycodes that continue Caps Word, with shift applied.
  42. case U_DELTA:
  43. add_weak_mods(MOD_BIT(KC_LSFT)); // Apply shift to next key.
  44. return true;
  45. // Keycodes that continue Caps Word, without shifting.
  46. case U_DASH:
  47. return true;
  48. default:
  49. return false; // Deactivate Caps Word.
  50. }
  51. }
  52. } // extern "C"
  53. class CapsWord : public TestFixture {
  54. public:
  55. void SetUp() override {
  56. caps_word_off();
  57. }
  58. };
  59. // Tests that typing U_DELTA while Caps Word is on sends the uppercase Delta.
  60. TEST_F(CapsWord, ShiftedUnicodeMapKey) {
  61. TestDriver driver;
  62. KeymapKey key_delta(0, 0, 0, U_DELTA);
  63. KeymapKey key_spc(0, 1, 0, KC_SPC);
  64. set_keymap({key_delta, key_spc});
  65. // Allow any number of reports with no keys or only KC_LSFT and KC_LCTL.
  66. // clang-format off
  67. EXPECT_CALL(driver, send_keyboard_mock(AnyOf(
  68. KeyboardReport(),
  69. KeyboardReport(KC_LSFT),
  70. KeyboardReport(KC_LCTL, KC_LSFT))))
  71. .Times(AnyNumber());
  72. // clang-format on
  73. { // Expect: "Uppercase Delta, space, lowercase delta".
  74. InSequence s;
  75. EXPECT_UNICODE(driver, unicode_map[DELTA_UPPERCASE]);
  76. EXPECT_REPORT(driver, (KC_SPC));
  77. EXPECT_UNICODE(driver, unicode_map[DELTA_LOWERCASE]);
  78. }
  79. // Turn on Caps Word and tap "delta, space, delta".
  80. caps_word_on();
  81. tap_keys(key_delta, key_spc, key_delta);
  82. EXPECT_EQ(is_caps_word_on(), false);
  83. VERIFY_AND_CLEAR(driver);
  84. }
  85. // Tests typing U_ENDASH while Caps Word is on.
  86. TEST_F(CapsWord, UnshiftedUnicodeMapKey) {
  87. TestDriver driver;
  88. KeymapKey key_dash(0, 0, 0, U_DASH);
  89. set_keymap({key_dash});
  90. // Allow any number of reports with no keys or only KC_LSFT and KC_LCTL.
  91. // clang-format off
  92. EXPECT_CALL(driver, send_keyboard_mock(AnyOf(
  93. KeyboardReport(),
  94. KeyboardReport(KC_LSFT),
  95. KeyboardReport(KC_LCTL, KC_LSFT))))
  96. .Times(AnyNumber());
  97. // clang-format on
  98. EXPECT_UNICODE(driver, unicode_map[ENDASH]);
  99. // Turn on Caps Word and tap U_DASH key.
  100. caps_word_on();
  101. tap_key(key_dash);
  102. EXPECT_EQ(is_caps_word_on(), true);
  103. VERIFY_AND_CLEAR(driver);
  104. }