Manual pages: mcmcdiffmceditmcview

root/tests/lib/util__keycode_to_cntrl.c

/* [previous][next][first][last][top][bottom][index][help]  */

DEFINITIONS

This source file includes following definitions.
  1. START_PARAMETRIZED_TEST
  2. main

   1 /*
   2    lib - keycode_to_cntrl() function testing
   3 
   4    Copyright (C) 2026
   5    Free Software Foundation, Inc.
   6 
   7    Written by:
   8    Manuel Einfalt <einfalt1@proton.me>, 2026
   9 
  10    This file is part of the Midnight Commander.
  11 
  12    The Midnight Commander is free software: you can redistribute it
  13    and/or modify it under the terms of the GNU General Public License as
  14    published by the Free Software Foundation, either version 3 of the License,
  15    or (at your option) any later version.
  16 
  17    The Midnight Commander is distributed in the hope that it will be useful,
  18    but WITHOUT ANY WARRANTY; without even the implied warranty of
  19    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20    GNU General Public License for more details.
  21 
  22    You should have received a copy of the GNU General Public License
  23    along with this program.  If not, see <https://www.gnu.org/licenses/>.
  24  */
  25 
  26 #define TEST_SUITE_NAME "/lib"
  27 
  28 #include "tests/mctest.h"
  29 #include "lib/util.h"
  30 #include "lib/tty/key.h"
  31 
  32 /* --------------------------------------------------------------------------------------------- */
  33 
  34 static const struct test_keycodes
  35 {
  36     int keycode;
  37     int expected_return;
  38 } test_keycodes[] = { { '@', 0 },
  39                       { '`', -1 },
  40                       { KEY_M_CTRL | 0, 0 },
  41                       { 'A', 1 },
  42                       { 'a', 1 },
  43                       { KEY_M_CTRL | 1, 1 },
  44                       { 'B', 2 },
  45                       { 'b', 2 },
  46                       { KEY_M_CTRL | 2, 2 },
  47                       { 'C', 3 },
  48                       { 'c', 3 },
  49                       { KEY_M_CTRL | 3, 3 },
  50                       { 'D', 4 },
  51                       { 'd', 4 },
  52                       { KEY_M_CTRL | 4, 4 },
  53                       { 'E', 5 },
  54                       { 'e', 5 },
  55                       { KEY_M_CTRL | 5, 5 },
  56                       { 'F', 6 },
  57                       { 'f', 6 },
  58                       { KEY_M_CTRL | 6, 6 },
  59                       { 'G', 7 },
  60                       { 'g', 7 },
  61                       { KEY_M_CTRL | 7, 7 },
  62                       { 'H', 8 },
  63                       { 'h', 8 },
  64                       { KEY_M_CTRL | 8, 8 },
  65                       { 'I', 9 },
  66                       { 'i', 9 },
  67                       { KEY_M_CTRL | 9, 9 },
  68                       { 'J', 10 },
  69                       { 'j', 10 },
  70                       { KEY_M_CTRL | 10, 10 },
  71                       { 'K', 11 },
  72                       { 'k', 11 },
  73                       { KEY_M_CTRL | 11, 11 },
  74                       { 'L', 12 },
  75                       { 'l', 12 },
  76                       { KEY_M_CTRL | 12, 12 },
  77                       { 'M', 13 },
  78                       { 'm', 13 },
  79                       { KEY_M_CTRL | 13, 13 },
  80                       { 'N', 14 },
  81                       { 'n', 14 },
  82                       { KEY_M_CTRL | 14, 14 },
  83                       { 'O', 15 },
  84                       { 'o', 15 },
  85                       { KEY_M_CTRL | 15, 15 },
  86                       { 'P', 16 },
  87                       { 'p', 16 },
  88                       { KEY_M_CTRL | 16, 16 },
  89                       { 'Q', 17 },
  90                       { 'q', 17 },
  91                       { KEY_M_CTRL | 17, 17 },
  92                       { 'R', 18 },
  93                       { 'r', 18 },
  94                       { KEY_M_CTRL | 18, 18 },
  95                       { 'S', 19 },
  96                       { 's', 19 },
  97                       { KEY_M_CTRL | 19, 19 },
  98                       { 'T', 20 },
  99                       { 't', 20 },
 100                       { KEY_M_CTRL | 20, 20 },
 101                       { 'U', 21 },
 102                       { 'u', 21 },
 103                       { KEY_M_CTRL | 21, 21 },
 104                       { 'V', 22 },
 105                       { 'v', 22 },
 106                       { KEY_M_CTRL | 22, 22 },
 107                       { 'W', 23 },
 108                       { 'w', 23 },
 109                       { KEY_M_CTRL | 23, 23 },
 110                       { 'X', 24 },
 111                       { 'x', 24 },
 112                       { KEY_M_CTRL | 24, 24 },
 113                       { 'Y', 25 },
 114                       { 'y', 25 },
 115                       { KEY_M_CTRL | 25, 25 },
 116                       { 'Z', 26 },
 117                       { 'z', 26 },
 118                       { KEY_M_CTRL | 26, 26 },
 119                       { '[', 27 },
 120                       { KEY_M_CTRL | 27, 27 },
 121                       { '\\', 28 },
 122                       { KEY_M_CTRL | 28, 28 },
 123                       { ']', 29 },
 124                       { KEY_M_CTRL | 29, 29 },
 125                       { '^', 30 },
 126                       { KEY_M_CTRL | 30, 30 },
 127                       { '_', 31 },
 128                       { KEY_M_CTRL | 31, 31 },
 129 
 130                       // Invalid ASCII-inputs:
 131                       { '~', -1 },
 132                       { '}', -1 },
 133                       { '|', -1 },
 134                       { '{', -1 },
 135 
 136                       /*
 137                        * Invalid inputs are non-ASCII or other special keys.
 138                        * These have bits set outside of 0x7f and KEY_M_CTRL.
 139                        */
 140                       { 0x5000, -1 },
 141                       { 128, -1 },
 142                       { 0x0507, -1 } };
 143 
 144 START_PARAMETRIZED_TEST (keycode_test, test_keycodes)
     /* [previous][next][first][last][top][bottom][index][help]  */
 145 {
 146     const int actual_result = keycode_to_cntrl (data->keycode);
 147     mctest_assert_true (actual_result == data->expected_return);
 148 }
 149 END_PARAMETRIZED_TEST
 150 
 151 /* --------------------------------------------------------------------------------------------- */
 152 
 153 int
 154 main (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 155 {
 156     TCase *tc_core;
 157 
 158     tc_core = tcase_create ("Core");
 159 
 160     // Add new tests here: ***************
 161     mctest_add_parameterized_test (tc_core, keycode_test, test_keycodes);
 162     // ***********************************
 163 
 164     return mctest_run_all (tc_core);
 165 }
 166 
 167 /* --------------------------------------------------------------------------------------------- */

/* [previous][next][first][last][top][bottom][index][help]  */