diff options
| author | Stefan Kerkmann <karlk90@pm.me> | 2025-03-21 08:47:22 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-03-21 08:47:22 +0100 |
| commit | c9d62ddc78e879053241202b288d0129073b07dc (patch) | |
| tree | 1e58dcea290874bf8af5ea7ca797fe3515885488 /tests/test_common/keycode_util.cpp | |
| parent | d603fb09139a5a55e1efd910a3989e38f138446f (diff) | |
[Core] use `keycode_string` in unit tests (#25042)
* tests: use keycode_string feature
With a proper keycode to string implementation in qmk there is no need
to use the unit tests only implementation anymore.
Signed-off-by: Stefan Kerkmann <karlk90@pm.me>
* tests: remove keycode_util feature
This feature is no longer used as we switched the tests to the
keycode string implementation.
Signed-off-by: Stefan Kerkmann <karlk90@pm.me>
Diffstat (limited to 'tests/test_common/keycode_util.cpp')
| -rw-r--r-- | tests/test_common/keycode_util.cpp | 130 |
1 files changed, 0 insertions, 130 deletions
diff --git a/tests/test_common/keycode_util.cpp b/tests/test_common/keycode_util.cpp deleted file mode 100644 index 539cab819a..0000000000 --- a/tests/test_common/keycode_util.cpp +++ /dev/null | |||
| @@ -1,130 +0,0 @@ | |||
| 1 | #include "keycode_util.hpp" | ||
| 2 | #include <cstdint> | ||
| 3 | extern "C" { | ||
| 4 | #include "action_code.h" | ||
| 5 | #include "keycode.h" | ||
| 6 | #include "quantum_keycodes.h" | ||
| 7 | #include "util.h" | ||
| 8 | } | ||
| 9 | #include <string> | ||
| 10 | #include <iomanip> | ||
| 11 | #include <map> | ||
| 12 | |||
| 13 | extern std::map<uint16_t, std::string> KEYCODE_ID_TABLE; | ||
| 14 | |||
| 15 | std::string get_mods(uint8_t mods) { | ||
| 16 | std::stringstream s; | ||
| 17 | if ((mods & MOD_RCTL) == MOD_RCTL) { | ||
| 18 | s << XSTR(MOD_RCTL) << " | "; | ||
| 19 | } else if ((mods & MOD_LCTL) == MOD_LCTL) { | ||
| 20 | s << XSTR(MOD_LCTL) << " | "; | ||
| 21 | } | ||
| 22 | |||
| 23 | if ((mods & MOD_RSFT) == MOD_RSFT) { | ||
| 24 | s << XSTR(MOD_RSFT) << " | "; | ||
| 25 | } else if ((mods & MOD_LSFT) == MOD_LSFT) { | ||
| 26 | s << XSTR(MOD_LSFT) << " | "; | ||
| 27 | } | ||
| 28 | |||
| 29 | if ((mods & MOD_RALT) == MOD_RALT) { | ||
| 30 | s << XSTR(MOD_RALT) << " | "; | ||
| 31 | } else if ((mods & MOD_LALT) == MOD_LALT) { | ||
| 32 | s << XSTR(MOD_LALT) << " | "; | ||
| 33 | } | ||
| 34 | |||
| 35 | if ((mods & MOD_RGUI) == MOD_RGUI) { | ||
| 36 | s << XSTR(MOD_RGUI) << " | "; | ||
| 37 | } else if ((mods & MOD_LGUI) == MOD_LGUI) { | ||
| 38 | s << XSTR(MOD_LGUI) << " | "; | ||
| 39 | } | ||
| 40 | |||
| 41 | auto _mods = s.str(); | ||
| 42 | |||
| 43 | if (_mods.size()) { | ||
| 44 | _mods.resize(_mods.size() - 3); | ||
| 45 | } | ||
| 46 | |||
| 47 | return std::string(_mods); | ||
| 48 | } | ||
| 49 | |||
| 50 | std::string get_qk_mods(uint16_t keycode) { | ||
| 51 | std::stringstream s; | ||
| 52 | if ((keycode & QK_RCTL) == QK_RCTL) { | ||
| 53 | s << XSTR(QK_RCTL) << " | "; | ||
| 54 | } else if ((keycode & QK_LCTL) == QK_LCTL) { | ||
| 55 | s << XSTR(QK_LCTL) << " | "; | ||
| 56 | } | ||
| 57 | |||
| 58 | if ((keycode & QK_RSFT) == QK_RSFT) { | ||
| 59 | s << XSTR(QK_RSFT) << " | "; | ||
| 60 | } else if ((keycode & QK_LSFT) == QK_LSFT) { | ||
| 61 | s << XSTR(QK_LSFT) << " | "; | ||
| 62 | } | ||
| 63 | |||
| 64 | if ((keycode & QK_RALT) == QK_RALT) { | ||
| 65 | s << XSTR(QK_RALT) << " | "; | ||
| 66 | } else if ((keycode & QK_LALT) == QK_LALT) { | ||
| 67 | s << XSTR(QK_LALT) << " | "; | ||
| 68 | } | ||
| 69 | |||
| 70 | if ((keycode & QK_RGUI) == QK_RGUI) { | ||
| 71 | s << XSTR(QK_RGUI) << " | "; | ||
| 72 | } else if ((keycode & QK_LGUI) == QK_LGUI) { | ||
| 73 | s << XSTR(QK_LGUI) << " | "; | ||
| 74 | } | ||
| 75 | |||
| 76 | auto _mods = s.str(); | ||
| 77 | |||
| 78 | if (_mods.size()) { | ||
| 79 | _mods.resize(_mods.size() - 3); | ||
| 80 | } | ||
| 81 | |||
| 82 | return std::string(_mods); | ||
| 83 | } | ||
| 84 | |||
| 85 | std::string generate_identifier(uint16_t kc) { | ||
| 86 | std::stringstream s; | ||
| 87 | if (IS_QK_MOD_TAP(kc)) { | ||
| 88 | s << "MT(" << get_mods(QK_MOD_TAP_GET_MODS(kc)) << ", " << KEYCODE_ID_TABLE.at(kc & 0xFF) << ")"; | ||
| 89 | } else if (IS_QK_LAYER_TAP(kc)) { | ||
| 90 | s << "LT(" << +QK_LAYER_TAP_GET_LAYER(kc) << ", " << KEYCODE_ID_TABLE.at(kc & 0xFF) << ")"; | ||
| 91 | } else if (IS_QK_TO(kc)) { | ||
| 92 | s << "TO(" << +QK_TO_GET_LAYER(kc) << ")"; | ||
| 93 | } else if (IS_QK_MOMENTARY(kc)) { | ||
| 94 | s << "MO(" << +QK_MOMENTARY_GET_LAYER(kc) << ")"; | ||
| 95 | } else if (IS_QK_DEF_LAYER(kc)) { | ||
| 96 | s << "DF(" << +QK_DEF_LAYER_GET_LAYER(kc) << ")"; | ||
| 97 | } else if (IS_QK_PERSISTENT_DEF_LAYER(kc)) { | ||
| 98 | s << "PDF(" << +QK_PERSISTENT_DEF_LAYER_GET_LAYER(kc) << ")"; | ||
| 99 | } else if (IS_QK_TOGGLE_LAYER(kc)) { | ||
| 100 | s << "TG(" << +QK_TOGGLE_LAYER_GET_LAYER(kc) << ")"; | ||
| 101 | } else if (IS_QK_LAYER_TAP_TOGGLE(kc)) { | ||
| 102 | s << "TT(" << +QK_LAYER_TAP_TOGGLE_GET_LAYER(kc) << ")"; | ||
| 103 | } else if (IS_QK_ONE_SHOT_LAYER(kc)) { | ||
| 104 | s << "OSL(" << +QK_ONE_SHOT_LAYER_GET_LAYER(kc) << ")"; | ||
| 105 | } else if (IS_QK_LAYER_MOD(kc)) { | ||
| 106 | s << "LM(" << +QK_LAYER_MOD_GET_LAYER(kc) << ", " << get_mods(QK_LAYER_MOD_GET_MODS(kc)) << ")"; | ||
| 107 | } else if (IS_QK_ONE_SHOT_MOD(kc)) { | ||
| 108 | s << "OSM(" << get_mods(QK_ONE_SHOT_MOD_GET_MODS(kc)) << ")"; | ||
| 109 | } else if (IS_QK_MODS(kc)) { | ||
| 110 | s << "QK_MODS(" << KEYCODE_ID_TABLE.at(QK_MODS_GET_BASIC_KEYCODE(kc)) << ", " << get_qk_mods(kc) << ")"; | ||
| 111 | } else if (IS_QK_TAP_DANCE(kc)) { | ||
| 112 | s << "TD(" << +(kc & 0xFF) << ")"; | ||
| 113 | } else { | ||
| 114 | // Fallback - we didn't found any matching keycode, generate the hex representation. | ||
| 115 | s << "unknown keycode: 0x" << std::hex << kc << ". Add conversion to " << XSTR(generate_identifier); | ||
| 116 | } | ||
| 117 | |||
| 118 | return std::string(s.str()); | ||
| 119 | } | ||
| 120 | |||
| 121 | std::string get_keycode_identifier_or_default(uint16_t keycode) { | ||
| 122 | auto identifier = KEYCODE_ID_TABLE.find(keycode); | ||
| 123 | if (identifier != KEYCODE_ID_TABLE.end()) { | ||
| 124 | return identifier->second; | ||
| 125 | } | ||
| 126 | |||
| 127 | KEYCODE_ID_TABLE[keycode] = generate_identifier(keycode); | ||
| 128 | |||
| 129 | return KEYCODE_ID_TABLE[keycode]; | ||
| 130 | } | ||
