qmk_firmware

QMK firmware for my keyboards (Corne, Sweep Ferris) and trackball (Ploopy Adept)
Log | Files | Refs | Submodules | LICENSE

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 
     15 #include <iostream>
     16 
     17 #include "test_common.hpp"
     18 
     19 enum {
     20     MYMACRO1 = SAFE_RANGE,
     21     MYMACRO2,
     22 };
     23 
     24 // clang-format off
     25 extern "C" {
     26 
     27 KEYCODE_STRING_NAMES_KB(
     28     KEYCODE_STRING_NAME(MYMACRO1),
     29 );
     30 
     31 KEYCODE_STRING_NAMES_USER(
     32     KEYCODE_STRING_NAME(MYMACRO2),
     33     KEYCODE_STRING_NAME(KC_EXLM),
     34 );
     35 
     36 const keypos_t PROGMEM hand_swap_config[MATRIX_ROWS][MATRIX_COLS] = {
     37   {{9, 0}, {8, 0}, {7, 0}, {6, 0}, {5, 0}, {4, 0}, {3, 0}, {2, 0}, {1, 0}, {0, 0}},
     38   {{9, 1}, {8, 1}, {7, 1}, {6, 1}, {5, 1}, {4, 1}, {3, 1}, {2, 1}, {1, 1}, {0, 1}},
     39   {{9, 2}, {8, 2}, {7, 2}, {6, 2}, {5, 2}, {4, 2}, {3, 2}, {2, 2}, {1, 2}, {0, 2}},
     40   {{9, 3}, {8, 3}, {7, 3}, {6, 3}, {5, 3}, {4, 3}, {3, 3}, {2, 3}, {1, 3}, {0, 3}},
     41 };
     42 
     43 } // extern "C"
     44 // clang-format on
     45 
     46 class KeycodeStringTest : public TestFixture {};
     47 
     48 TEST_F(KeycodeStringTest, get_keycode_string) {
     49     struct TestParams {
     50         uint16_t    keycode;
     51         std::string expected;
     52     };
     53     for (const auto [keycode, expected] : std::vector<TestParams>({
     54              {KC_TRNS, "KC_TRNS"},
     55              {KC_ESC, "KC_ESC"},
     56              {KC_A, "KC_A"},
     57              {KC_Z, "KC_Z"},
     58              {KC_0, "KC_0"},
     59              {KC_9, "KC_9"},
     60              {KC_KP_0, "KC_KP_0"},
     61              {KC_KP_9, "KC_KP_9"},
     62              {KC_LBRC, "KC_LBRC"},
     63              {KC_NUHS, "KC_NUHS"},
     64              {KC_NUBS, "KC_NUBS"},
     65              {KC_CAPS, "KC_CAPS"},
     66              {DB_TOGG, "DB_TOGG"},
     67              {KC_LCTL, "KC_LCTL"},
     68              {KC_LSFT, "KC_LSFT"},
     69              {KC_RALT, "KC_RALT"},
     70              {KC_RGUI, "KC_RGUI"},
     71              {KC_UP, "KC_UP"},
     72              {KC_HYPR, "KC_HYPR"},
     73              {KC_MEH, "KC_MEH"},
     74              // F1-F24 keycodes.
     75              {KC_F1, "KC_F1"},
     76              {KC_F12, "KC_F12"},
     77              {KC_F13, "KC_F13"},
     78              {KC_F24, "KC_F24"},
     79              // Macro keycodes.
     80              {MC_0, "MC_0"},
     81              {MC_31, "MC_31"},
     82              // Keyboard range keycodes.
     83              {QK_KB_0, "QK_KB_0"},
     84              {QK_KB_31, "QK_KB_31"},
     85              // User range keycodes.
     86              {QK_USER_2, "QK_USER_2"},
     87              {QK_USER_31, "QK_USER_31"},
     88              // Modified keycodes.
     89              {KC_COLN, "S(KC_SCLN)"},
     90              {C(KC_PGUP), "C(KC_PGUP)"},
     91              {RALT(KC_BSPC), "RALT(KC_BSPC)"},
     92              // One-shot mods.
     93              {OSM(MOD_LSFT), "OSM(MOD_LSFT)"},
     94              {OSM(MOD_RGUI), "OSM(MOD_RGUI)"},
     95              {OSM(MOD_RCTL | MOD_RGUI), "OSM(0x19)"},
     96              // Layer switch keycodes.
     97              {DF(2), "DF(2)"},
     98              {PDF(12), "PDF(12)"},
     99              {MO(3), "MO(3)"},
    100              {TO(0), "TO(0)"},
    101              {TT(1), "TT(1)"},
    102              {TG(3), "TG(3)"},
    103              {OSL(3), "OSL(3)"},
    104              {LM(3, MOD_RALT), "LM(3,MOD_RALT)"},
    105              {LT(15, KC_QUOT), "LT(15,KC_QUOT)"},
    106              // Tap dance keycodes.
    107              {TD(0), "TD(0)"},
    108              {TD(31), "TD(31)"},
    109              // Mod-tap keycodes.
    110              {LSFT_T(KC_ENT), "LSFT_T(KC_ENT)"},
    111              {RCTL_T(KC_RGHT), "RCTL_T(KC_RGHT)"},
    112              {HYPR_T(KC_GRV), "HYPR_T(KC_GRV)"},
    113              {MEH_T(KC_EQL), "MEH_T(KC_EQL)"},
    114              {RSA_T(KC_LBRC), "MT(0x16,KC_LBRC)"},
    115              // Extrakey keycodes.
    116              {KC_WBAK, "KC_WBAK"},
    117              {KC_WFWD, "KC_WFWD"},
    118              {KC_WREF, "KC_WREF"},
    119              {KC_VOLU, "KC_VOLU"},
    120              {KC_VOLD, "KC_VOLD"},
    121              // Mouse Key keycodes.
    122              {MS_LEFT, "MS_LEFT"},
    123              {MS_RGHT, "MS_RGHT"},
    124              {MS_UP, "MS_UP"},
    125              {MS_WHLU, "MS_WHLU"},
    126              {MS_WHLD, "MS_WHLD"},
    127              {MS_BTN1, "MS_BTN1"},
    128              {MS_BTN8, "MS_BTN8"},
    129              // Swap Hands keycodes.
    130              {SH_MON, "SH_MON"},
    131              {SH_TOGG, "SH_TOGG"},
    132              {SH_T(KC_PSCR), "SH_T(KC_PSCR)"},
    133              // Secure keycodes.
    134              {SE_LOCK, "SE_LOCK"},
    135              {SE_UNLK, "SE_UNLK"},
    136              {SE_TOGG, "SE_TOGG"},
    137              {SE_REQ, "SE_REQ"},
    138              // Programmable button keycodes.
    139              {PB_1, "PB_1"},
    140              {PB_32, "PB_32"},
    141              // Magic button keycodes.
    142              {QK_MAGIC + 7, "QK_MAGIC+7"},
    143              // Quantum keycodes.
    144              {QK_LOCK, "QK_LOCK"},
    145              {QK_QUANTUM + 7, "QK_QUANTUM+7"},
    146              // Custom keycode names.
    147              {MYMACRO1, "MYMACRO1"},
    148              {MYMACRO2, "MYMACRO2"},
    149              {KC_EXLM, "KC_EXLM"},
    150          })) {
    151         EXPECT_EQ(get_keycode_string(keycode), expected) << "where keycode = 0x" << std::hex << keycode;
    152     }
    153 }