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-2024
   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 <http://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 /* *INDENT-OFF* */
  54 static const struct test_hotkey_equal_ds
  55 {
  56     const hotkey_t hotkey1;
  57     const hotkey_t hotkey2;
  58     gboolean expected_result;
  59 } test_hotkey_equal_ds[] =
  60 {
  61     /* 0 */
  62     {
  63         { .start = C ("abc"), .hotkey = NULL, .end = NULL },
  64         { .start = C ("abc"), .hotkey = NULL, .end = NULL },
  65         TRUE
  66     },
  67     /* 1 */
  68     {
  69         { .start = C (""), .hotkey = C (""), .end = C ("") },
  70         { .start = C (""), .hotkey = C (""), .end = C ("") },
  71         TRUE
  72     },
  73     /* 2 */
  74     {
  75         { .start = C ("abc"), .hotkey = C ("d"), .end = C ("efg") },
  76         { .start = C ("abc"), .hotkey = C ("d"), .end = C ("efg") },
  77         TRUE
  78     },
  79     /* 3 */
  80     {
  81         { .start = C ("abc"), .hotkey = NULL, .end = C ("efg") },
  82         { .start = C ("abc"), .hotkey = NULL, .end = C ("efg") },
  83         TRUE
  84     },
  85     /* 4 */
  86     {
  87         { .start = C ("abc"), .hotkey = C ("d"), .end = NULL },
  88         { .start = C ("abc"), .hotkey = C ("d"), .end = NULL },
  89         TRUE
  90     },
  91     /* 5 */
  92     {
  93         { .start = C ("abc"), .hotkey = C ("d"), .end = C ("efg") },
  94         { .start = C ("_bc"), .hotkey = C ("d"), .end = C ("efg") },
  95         FALSE
  96     },
  97     /* 6 */
  98     {
  99         { .start = C ("abc"), .hotkey = C ("d"), .end = C ("efg") },
 100         { .start = C ("abc"), .hotkey = C ("_"), .end = C ("efg") },
 101         FALSE
 102     },
 103     /* 7 */
 104     {
 105         { .start = C ("abc"), .hotkey = C ("d"), .end = C ("efg") },
 106         { .start = C ("abc"), .hotkey = C ("d"), .end = C ("_fg") },
 107         FALSE
 108     },
 109     /* 8 */
 110     {
 111         { .start = C ("abc"), .hotkey = C ("d"), .end = C ("efg") },
 112         { .start = C ("adc"), .hotkey = NULL,    .end = C ("efg") },
 113         FALSE
 114     },
 115     /* 9 */
 116     {
 117         { .start = C ("abc"), .hotkey = C ("d"), .end = C ("efg") },
 118         { .start = C ("abc"), .hotkey = C ("d"), .end = NULL      },
 119         FALSE
 120     },
 121     /* 10 */
 122     {
 123         { .start = C ("abc"), .hotkey = C ("d"), .end = C ("efg") },
 124         { .start = C ("abc"), .hotkey = NULL,    .end = NULL      },
 125         FALSE
 126     }
 127 };
 128 /* *INDENT-ON* */
 129 
 130 /* @Test(dataSource = "test_hotkey_equal_ds") */
 131 /* *INDENT-OFF* */
 132 START_PARAMETRIZED_TEST (test_hotkey_equal,
     /* [previous][next][first][last][top][bottom][index][help]  */
 133                          test_hotkey_equal_ds)
 134 /* *INDENT-ON* */
 135 {
 136     /* given */
 137     gboolean result;
 138 
 139     /* when */
 140     result = hotkey_equal (data->hotkey1, data->hotkey2);
 141 
 142     /* then */
 143     ck_assert_int_eq (result, data->expected_result);
 144 }
 145 /* *INDENT-OFF* */
 146 END_PARAMETRIZED_TEST
 147 /* *INDENT-ON* */
 148 
 149 /* --------------------------------------------------------------------------------------------- */
 150 
 151 int
 152 main (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 153 {
 154     TCase *tc_core;
 155 
 156     tc_core = tcase_create ("Core");
 157 
 158     tcase_add_checked_fixture (tc_core, setup, teardown);
 159 
 160     /* Add new tests here: *************** */
 161     mctest_add_parameterized_test (tc_core, test_hotkey_equal, test_hotkey_equal_ds);
 162     /* *********************************** */
 163 
 164     return mctest_run_all (tc_core);
 165 }
 166 
 167 /* --------------------------------------------------------------------------------------------- */

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