Manual pages: mcmcdiffmceditmcview

root/tests/src/usermenu__test_condition.c

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

DEFINITIONS

This source file includes following definitions.
  1. setup
  2. teardown
  3. setup_charset
  4. teardown_charset
  5. START_PARAMETRIZED_TEST
  6. main

   1 /*
   2    src/usermenu - tests for usermenu
   3 
   4    Copyright (C) 2025
   5    Free Software Foundation, Inc.
   6 
   7    This file is part of the Midnight Commander.
   8 
   9    The Midnight Commander is free software: you can redistribute it
  10    and/or modify it under the terms of the GNU General Public License as
  11    published by the Free Software Foundation, either version 3 of the License,
  12    or (at your option) any later version.
  13 
  14    The Midnight Commander is distributed in the hope that it will be useful,
  15    but WITHOUT ANY WARRANTY; without even the implied warranty of
  16    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17    GNU General Public License for more details.
  18 
  19    You should have received a copy of the GNU General Public License
  20    along with this program.  If not, see <https://www.gnu.org/licenses/>.
  21  */
  22 
  23 #define TEST_SUITE_NAME "/src/usermenu"
  24 
  25 #include "tests/mctest.h"
  26 
  27 #include "lib/charsets.h"
  28 
  29 #include "src/usermenu.c"
  30 
  31 /* --------------------------------------------------------------------------------------------- */
  32 
  33 static void
  34 setup (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
  35 {
  36     easy_patterns = FALSE;
  37 
  38     current_panel = g_new0 (WPanel, 1);
  39     current_panel->dir.size = 4;
  40     current_panel->dir.len = current_panel->dir.size;
  41     current_panel->dir.list = g_new0 (file_entry_t, current_panel->dir.size);
  42 
  43     file_entry_t *list = current_panel->dir.list;
  44 
  45     list[0].fname = g_string_new ("file_without_spaces");
  46     list[1].fname = g_string_new ("file with spaces");
  47     list[2].fname = g_string_new ("file_without_spaces_utf8_local_chars_ä_ü_ö_ß_");
  48     list[3].fname = g_string_new ("file_without_spaces_utf8_nonlocal_chars_à_á_");
  49 }
  50 
  51 /* --------------------------------------------------------------------------------------------- */
  52 
  53 static void
  54 teardown (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
  55 {
  56     dir_list_free_list (&current_panel->dir);
  57     MC_PTR_FREE (current_panel);
  58 }
  59 
  60 /* --------------------------------------------------------------------------------------------- */
  61 
  62 static void
  63 setup_charset (const char *encoding, const gboolean utf8_display)
     /* [previous][next][first][last][top][bottom][index][help]  */
  64 {
  65     str_init_strings (encoding);
  66 
  67     mc_global.sysconfig_dir = (char *) TEST_SHARE_DIR;
  68     load_codepages_list ();
  69 
  70     cp_source = encoding;
  71     cp_display = encoding;
  72     mc_global.source_codepage = get_codepage_index (encoding);
  73     mc_global.display_codepage = get_codepage_index (encoding);
  74 
  75     mc_global.utf8_display = utf8_display;
  76 }
  77 
  78 /* --------------------------------------------------------------------------------------------- */
  79 
  80 static void
  81 teardown_charset (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
  82 {
  83     free_codepages_list ();
  84     str_uninit_strings ();
  85 }
  86 
  87 /* --------------------------------------------------------------------------------------------- */
  88 
  89 static const struct check_test_condition_ds
  90 {
  91     const char *encoding;
  92     gboolean utf8_display;
  93     int current_file;
  94     gboolean expected_value;
  95 } check_test_condition_ds[] = {
  96     // In fully UTF-8 environment, only file with real spaces should match
  97     { "UTF-8", TRUE, 0, FALSE },
  98     { "UTF-8", TRUE, 1, TRUE },
  99     { "UTF-8", TRUE, 2, FALSE },
 100     { "UTF-8", TRUE, 3, FALSE },
 101 
 102     // Last filename contains 0xa0 byte, which would be interpreted as a non-breaking space in
 103     // single-byte encodings
 104     { "KOI8-R", FALSE, 0, FALSE },
 105     { "KOI8-R", FALSE, 1, TRUE },
 106     { "KOI8-R", FALSE, 2, FALSE },
 107     { "KOI8-R", FALSE, 3, TRUE },
 108 };
 109 
 110 /* --------------------------------------------------------------------------------------------- */
 111 
 112 START_PARAMETRIZED_TEST (check_test_condition, check_test_condition_ds)
     /* [previous][next][first][last][top][bottom][index][help]  */
 113 {
 114     setup_charset (data->encoding, data->utf8_display);
 115     char *condition = g_strdup ("f [[:space:]] & t r");
 116 
 117     current_panel->current = data->current_file;
 118 
 119     gboolean result = FALSE;
 120     test_condition (NULL, condition, &result);
 121     ck_assert_int_eq (result, data->expected_value);
 122 
 123     g_free (condition);
 124     teardown_charset ();
 125 }
 126 END_PARAMETRIZED_TEST
 127 
 128 /* --------------------------------------------------------------------------------------------- */
 129 
 130 int
 131 main (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 132 {
 133     TCase *tc_core;
 134 
 135     tc_core = tcase_create ("Core");
 136 
 137     tcase_add_checked_fixture (tc_core, setup, teardown);
 138 
 139     // Add new tests here: ***************
 140     mctest_add_parameterized_test (tc_core, check_test_condition, check_test_condition_ds);
 141     // ***********************************
 142 
 143     return mctest_run_all (tc_core);
 144 }
 145 
 146 /* --------------------------------------------------------------------------------------------- */

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