root/tests/lib/widget/hotkey_equal.c

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

DEFINITIONS

This source file includes following definitions.
  1. setup
  2. teardown
  3. START_PARAMETRIZED_TEST
  4. main

   1 /*
   2    lib/widget - tests for hotkey comparison
   3 
   4    Copyright (C) 2019-2025
   5    Free Software Foundation, Inc.
   6 
   7    Written by:
   8    Andrew Borodin <aborodin@vmail.ru>, 2019
   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/widget"
  27 
  28 #include "tests/mctest.h"
  29 
  30 #include "lib/widget.h"
  31 
  32 #define C(x) ((char *) x)
  33 
  34 /* --------------------------------------------------------------------------------------------- */
  35 
  36 /* @Before */
  37 static void
  38 setup (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
  39 {
  40 }
  41 
  42 /* --------------------------------------------------------------------------------------------- */
  43 
  44 /* @After */
  45 static void
  46 teardown (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
  47 {
  48 }
  49 
  50 /* --------------------------------------------------------------------------------------------- */
  51 
  52 /* @DataSource("test_hotkey_equal_ds") */
  53 static const struct test_hotkey_equal_ds
  54 {
  55     const hotkey_t hotkey1;
  56     const hotkey_t hotkey2;
  57     gboolean expected_result;
  58 } test_hotkey_equal_ds[] = {
  59     {
  60         // 0
  61         { .start = C ("abc"), .hotkey = NULL, .end = NULL },
  62         { .start = C ("abc"), .hotkey = NULL, .end = NULL },
  63         TRUE,
  64     },
  65     {
  66         // 1
  67         { .start = C (""), .hotkey = C (""), .end = C ("") },
  68         { .start = C (""), .hotkey = C (""), .end = C ("") },
  69         TRUE,
  70     },
  71     {
  72         // 2
  73         { .start = C ("abc"), .hotkey = C ("d"), .end = C ("efg") },
  74         { .start = C ("abc"), .hotkey = C ("d"), .end = C ("efg") },
  75         TRUE,
  76     },
  77     {
  78         // 3
  79         { .start = C ("abc"), .hotkey = NULL, .end = C ("efg") },
  80         { .start = C ("abc"), .hotkey = NULL, .end = C ("efg") },
  81         TRUE,
  82     },
  83     {
  84         // 4
  85         { .start = C ("abc"), .hotkey = C ("d"), .end = NULL },
  86         { .start = C ("abc"), .hotkey = C ("d"), .end = NULL },
  87         TRUE,
  88     },
  89     {
  90         // 5
  91         { .start = C ("abc"), .hotkey = C ("d"), .end = C ("efg") },
  92         { .start = C ("_bc"), .hotkey = C ("d"), .end = C ("efg") },
  93         FALSE,
  94     },
  95     {
  96         // 6
  97         { .start = C ("abc"), .hotkey = C ("d"), .end = C ("efg") },
  98         { .start = C ("abc"), .hotkey = C ("_"), .end = C ("efg") },
  99         FALSE,
 100     },
 101     {
 102         // 7
 103         { .start = C ("abc"), .hotkey = C ("d"), .end = C ("efg") },
 104         { .start = C ("abc"), .hotkey = C ("d"), .end = C ("_fg") },
 105         FALSE,
 106     },
 107     {
 108         // 8
 109         { .start = C ("abc"), .hotkey = C ("d"), .end = C ("efg") },
 110         { .start = C ("adc"), .hotkey = NULL, .end = C ("efg") },
 111         FALSE,
 112     },
 113     {
 114         // 9
 115         { .start = C ("abc"), .hotkey = C ("d"), .end = C ("efg") },
 116         { .start = C ("abc"), .hotkey = C ("d"), .end = NULL },
 117         FALSE,
 118     },
 119     {
 120         // 10
 121         { .start = C ("abc"), .hotkey = C ("d"), .end = C ("efg") },
 122         { .start = C ("abc"), .hotkey = NULL, .end = NULL },
 123         FALSE,
 124     },
 125 };
 126 
 127 /* @Test(dataSource = "test_hotkey_equal_ds") */
 128 START_PARAMETRIZED_TEST (test_hotkey_equal, test_hotkey_equal_ds)
     /* [previous][next][first][last][top][bottom][index][help]  */
 129 {
 130     // given
 131     gboolean result;
 132 
 133     // when
 134     result = hotkey_equal (data->hotkey1, data->hotkey2);
 135 
 136     // then
 137     ck_assert_int_eq (result, data->expected_result);
 138 }
 139 END_PARAMETRIZED_TEST
 140 
 141 /* --------------------------------------------------------------------------------------------- */
 142 
 143 int
 144 main (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 145 {
 146     TCase *tc_core;
 147 
 148     tc_core = tcase_create ("Core");
 149 
 150     tcase_add_checked_fixture (tc_core, setup, teardown);
 151 
 152     // Add new tests here: ***************
 153     mctest_add_parameterized_test (tc_core, test_hotkey_equal, test_hotkey_equal_ds);
 154     // ***********************************
 155 
 156     return mctest_run_all (tc_core);
 157 }
 158 
 159 /* --------------------------------------------------------------------------------------------- */

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