logo

qmk_firmware

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

test_keycode_string.cpp (5215B)


  1. // Copyright 2025 Google LLC
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // https://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #include <iostream>
  15. #include "test_common.hpp"
  16. enum {
  17. MYMACRO1 = SAFE_RANGE,
  18. MYMACRO2,
  19. };
  20. // clang-format off
  21. extern "C" {
  22. KEYCODE_STRING_NAMES_KB(
  23. KEYCODE_STRING_NAME(MYMACRO1),
  24. );
  25. KEYCODE_STRING_NAMES_USER(
  26. KEYCODE_STRING_NAME(MYMACRO2),
  27. KEYCODE_STRING_NAME(KC_EXLM),
  28. );
  29. const keypos_t PROGMEM hand_swap_config[MATRIX_ROWS][MATRIX_COLS] = {
  30. {{9, 0}, {8, 0}, {7, 0}, {6, 0}, {5, 0}, {4, 0}, {3, 0}, {2, 0}, {1, 0}, {0, 0}},
  31. {{9, 1}, {8, 1}, {7, 1}, {6, 1}, {5, 1}, {4, 1}, {3, 1}, {2, 1}, {1, 1}, {0, 1}},
  32. {{9, 2}, {8, 2}, {7, 2}, {6, 2}, {5, 2}, {4, 2}, {3, 2}, {2, 2}, {1, 2}, {0, 2}},
  33. {{9, 3}, {8, 3}, {7, 3}, {6, 3}, {5, 3}, {4, 3}, {3, 3}, {2, 3}, {1, 3}, {0, 3}},
  34. };
  35. } // extern "C"
  36. // clang-format on
  37. class KeycodeStringTest : public TestFixture {};
  38. TEST_F(KeycodeStringTest, get_keycode_string) {
  39. struct TestParams {
  40. uint16_t keycode;
  41. std::string expected;
  42. };
  43. for (const auto [keycode, expected] : std::vector<TestParams>({
  44. {KC_TRNS, "KC_TRNS"},
  45. {KC_ESC, "KC_ESC"},
  46. {KC_A, "KC_A"},
  47. {KC_Z, "KC_Z"},
  48. {KC_0, "KC_0"},
  49. {KC_9, "KC_9"},
  50. {KC_KP_0, "KC_KP_0"},
  51. {KC_KP_9, "KC_KP_9"},
  52. {KC_LBRC, "KC_LBRC"},
  53. {KC_NUHS, "KC_NUHS"},
  54. {KC_NUBS, "KC_NUBS"},
  55. {KC_CAPS, "KC_CAPS"},
  56. {DB_TOGG, "DB_TOGG"},
  57. {KC_LCTL, "KC_LCTL"},
  58. {KC_LSFT, "KC_LSFT"},
  59. {KC_RALT, "KC_RALT"},
  60. {KC_RGUI, "KC_RGUI"},
  61. {KC_UP, "KC_UP"},
  62. {KC_HYPR, "KC_HYPR"},
  63. {KC_MEH, "KC_MEH"},
  64. // F1-F24 keycodes.
  65. {KC_F1, "KC_F1"},
  66. {KC_F12, "KC_F12"},
  67. {KC_F13, "KC_F13"},
  68. {KC_F24, "KC_F24"},
  69. // Macro keycodes.
  70. {MC_0, "MC_0"},
  71. {MC_31, "MC_31"},
  72. // Keyboard range keycodes.
  73. {QK_KB_0, "QK_KB_0"},
  74. {QK_KB_31, "QK_KB_31"},
  75. // User range keycodes.
  76. {QK_USER_2, "QK_USER_2"},
  77. {QK_USER_31, "QK_USER_31"},
  78. // Modified keycodes.
  79. {KC_COLN, "S(KC_SCLN)"},
  80. {C(KC_PGUP), "C(KC_PGUP)"},
  81. {RALT(KC_BSPC), "RALT(KC_BSPC)"},
  82. // One-shot mods.
  83. {OSM(MOD_LSFT), "OSM(MOD_LSFT)"},
  84. {OSM(MOD_RGUI), "OSM(MOD_RGUI)"},
  85. {OSM(MOD_RCTL | MOD_RGUI), "OSM(0x19)"},
  86. // Layer switch keycodes.
  87. {DF(2), "DF(2)"},
  88. {PDF(12), "PDF(12)"},
  89. {MO(3), "MO(3)"},
  90. {TO(0), "TO(0)"},
  91. {TT(1), "TT(1)"},
  92. {TG(3), "TG(3)"},
  93. {OSL(3), "OSL(3)"},
  94. {LM(3, MOD_RALT), "LM(3,MOD_RALT)"},
  95. {LT(15, KC_QUOT), "LT(15,KC_QUOT)"},
  96. // Tap dance keycodes.
  97. {TD(0), "TD(0)"},
  98. {TD(31), "TD(31)"},
  99. // Mod-tap keycodes.
  100. {LSFT_T(KC_ENT), "LSFT_T(KC_ENT)"},
  101. {RCTL_T(KC_RGHT), "RCTL_T(KC_RGHT)"},
  102. {HYPR_T(KC_GRV), "HYPR_T(KC_GRV)"},
  103. {MEH_T(KC_EQL), "MEH_T(KC_EQL)"},
  104. {RSA_T(KC_LBRC), "MT(0x16,KC_LBRC)"},
  105. // Extrakey keycodes.
  106. {KC_WBAK, "KC_WBAK"},
  107. {KC_WFWD, "KC_WFWD"},
  108. {KC_WREF, "KC_WREF"},
  109. {KC_VOLU, "KC_VOLU"},
  110. {KC_VOLD, "KC_VOLD"},
  111. // Mouse Key keycodes.
  112. {MS_LEFT, "MS_LEFT"},
  113. {MS_RGHT, "MS_RGHT"},
  114. {MS_UP, "MS_UP"},
  115. {MS_WHLU, "MS_WHLU"},
  116. {MS_WHLD, "MS_WHLD"},
  117. {MS_BTN1, "MS_BTN1"},
  118. {MS_BTN8, "MS_BTN8"},
  119. // Swap Hands keycodes.
  120. {SH_MON, "SH_MON"},
  121. {SH_TOGG, "SH_TOGG"},
  122. {SH_T(KC_PSCR), "SH_T(KC_PSCR)"},
  123. // Secure keycodes.
  124. {SE_LOCK, "SE_LOCK"},
  125. {SE_UNLK, "SE_UNLK"},
  126. {SE_TOGG, "SE_TOGG"},
  127. {SE_REQ, "SE_REQ"},
  128. // Programmable button keycodes.
  129. {PB_1, "PB_1"},
  130. {PB_32, "PB_32"},
  131. // Magic button keycodes.
  132. {QK_MAGIC + 7, "QK_MAGIC+7"},
  133. // Quantum keycodes.
  134. {QK_LOCK, "QK_LOCK"},
  135. {QK_QUANTUM + 7, "QK_QUANTUM+7"},
  136. // Custom keycode names.
  137. {MYMACRO1, "MYMACRO1"},
  138. {MYMACRO2, "MYMACRO2"},
  139. {KC_EXLM, "KC_EXLM"},
  140. })) {
  141. EXPECT_EQ(get_keycode_string(keycode), expected) << "where keycode = 0x" << std::hex << keycode;
  142. }
  143. }