root/tests/lib/name_quote.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. START_PARAMETRIZED_TEST
  5. main

   1 /*
   2    lib - Quote file names
   3 
   4    Copyright (C) 2011-2025
   5    Free Software Foundation, Inc.
   6 
   7    Written by:
   8    Slava Zanko <slavazanko@gmail.com>, 2011, 2013
   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/util"
  27 
  28 #include "tests/mctest.h"
  29 
  30 #include "lib/util.h"
  31 
  32 /* --------------------------------------------------------------------------------------------- */
  33 
  34 /* @Before */
  35 static void
  36 setup (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
  37 {
  38 }
  39 
  40 /* @After */
  41 static void
  42 teardown (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
  43 {
  44 }
  45 
  46 /* --------------------------------------------------------------------------------------------- */
  47 
  48 /* @DataSource("data_source1") */
  49 static const struct data_source1
  50 {
  51     gboolean input_quote_percent;
  52     const char *input_string;
  53 
  54     const char *expected_string;
  55 } data_source1[] = {
  56     { TRUE, "%%", "%%%%" },
  57     { FALSE, "%%", "%%" },
  58 };
  59 
  60 /* @Test(dataSource = "data_source1") */
  61 START_PARAMETRIZED_TEST (quote_percent_test, data_source1)
     /* [previous][next][first][last][top][bottom][index][help]  */
  62 {
  63     // given
  64     char *actual_string;
  65 
  66     // when
  67     actual_string = name_quote (data->input_string, data->input_quote_percent);
  68 
  69     // then
  70     mctest_assert_str_eq (actual_string, data->expected_string);
  71 
  72     g_free (actual_string);
  73 }
  74 END_PARAMETRIZED_TEST
  75 
  76 /* --------------------------------------------------------------------------------------------- */
  77 
  78 /* @DataSource("data_source2") */
  79 static const struct data_source2
  80 {
  81     const char *input_string;
  82 
  83     const char *expected_string;
  84 } data_source2[] = {
  85     { "", NULL },
  86     { "-", "./-" },
  87     { "blabla-", "blabla-" },
  88     { "\r\n\t", "\\\r\\\n\\\t" },
  89     { "'\\\";?|[]{}<>`!$&*()", "\\'\\\\\\\"\\;\\?\\|\\[\\]\\{\\}\\<\\>\\`\\!\\$\\&\\*\\(\\)" },
  90     { "a b c ", "a\\ b\\ c\\ " },
  91     { "#", "\\#" },
  92     { "blabla#", "blabla#" },
  93     { "~", "\\~" },
  94     { "blabla~", "blabla~" },
  95     {
  96         NULL,
  97         NULL,
  98     },
  99 };
 100 
 101 /* @Test(dataSource = "data_source2") */
 102 START_PARAMETRIZED_TEST (name_quote_test, data_source2)
     /* [previous][next][first][last][top][bottom][index][help]  */
 103 {
 104     // given
 105     char *actual_string;
 106 
 107     // when
 108     actual_string = name_quote (data->input_string, FALSE);
 109 
 110     // then
 111     mctest_assert_str_eq (actual_string, data->expected_string);
 112 
 113     g_free (actual_string);
 114 }
 115 END_PARAMETRIZED_TEST
 116 
 117 /* --------------------------------------------------------------------------------------------- */
 118 
 119 int
 120 main (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 121 {
 122     TCase *tc_core;
 123 
 124     tc_core = tcase_create ("Core");
 125 
 126     tcase_add_checked_fixture (tc_core, setup, teardown);
 127 
 128     // Add new tests here: ***************
 129     mctest_add_parameterized_test (tc_core, quote_percent_test, data_source1);
 130     mctest_add_parameterized_test (tc_core, name_quote_test, data_source2);
 131     // ***********************************
 132 
 133     return mctest_run_all (tc_core);
 134 }
 135 
 136 /* --------------------------------------------------------------------------------------------- */

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