Manual pages: mcmcdiffmceditmcview

root/tests/lib/mc_build_filename.c

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

DEFINITIONS

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

   1 /*
   2    lib - mc_build_filename() function testing
   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/strutil.h"
  31 #include "lib/util.h"
  32 
  33 /* --------------------------------------------------------------------------------------------- */
  34 
  35 static char *
  36 run_mc_build_filename (int iteration)
     /* [previous][next][first][last][top][bottom][index][help]  */
  37 {
  38     switch (iteration)
  39     {
  40     case 0:
  41         return mc_build_filename ("test", "path", (char *) NULL);
  42     case 1:
  43         return mc_build_filename ("/test", "path/", (char *) NULL);
  44     case 2:
  45         return mc_build_filename ("/test", "pa/th", (char *) NULL);
  46     case 3:
  47         return mc_build_filename ("/test", "#vfsprefix:", "path  ", (char *) NULL);
  48     case 4:
  49         return mc_build_filename ("/test", "vfsprefix://", "path  ", (char *) NULL);
  50     case 5:
  51         return mc_build_filename ("/test", "vfs/../prefix:///", "p\\///ath", (char *) NULL);
  52     case 6:
  53         return mc_build_filename ("/test", "path", "..", "/test", "path/", (char *) NULL);
  54     case 7:
  55         return mc_build_filename ("", "path", (char *) NULL);
  56     case 8:
  57         return mc_build_filename ("", "/path", (char *) NULL);
  58     case 9:
  59         return mc_build_filename ("path", "", (char *) NULL);
  60     case 10:
  61         return mc_build_filename ("/path", "", (char *) NULL);
  62     case 11:
  63         return mc_build_filename ("pa", "", "th", (char *) NULL);
  64     case 12:
  65         return mc_build_filename ("/pa", "", "/th", (char *) NULL);
  66     default:
  67         return NULL;
  68     }
  69 }
  70 
  71 /* @DataSource("test_mc_build_filename_ds") */
  72 static const struct test_mc_build_filename_ds
  73 {
  74     const char *expected_result;
  75 } test_mc_build_filename_ds[] = {
  76     { "test/path" },
  77     { "/test/path" },
  78     { "/test/pa/th" },
  79     { "/test/#vfsprefix:/path  " },
  80     { "/test/vfsprefix://path  " },
  81     { "/test/prefix://p\\/ath" },
  82     { "/test/test/path" },
  83     { "path" },
  84     { "path" },
  85     { "path" },
  86     { "/path" },
  87     { "pa/th" },
  88     { "/pa/th" },
  89 };
  90 
  91 /* @Test(dataSource = "test_mc_build_filename_ds") */
  92 START_PARAMETRIZED_TEST (test_mc_build_filename, test_mc_build_filename_ds)
     /* [previous][next][first][last][top][bottom][index][help]  */
  93 {
  94     // given
  95     char *actual_result;
  96 
  97     // when
  98     actual_result = run_mc_build_filename (_i);
  99 
 100     // then
 101     mctest_assert_str_eq (actual_result, data->expected_result);
 102 
 103     g_free (actual_result);
 104 }
 105 END_PARAMETRIZED_TEST
 106 
 107 /* --------------------------------------------------------------------------------------------- */
 108 
 109 int
 110 main (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 111 {
 112     TCase *tc_core;
 113 
 114     tc_core = tcase_create ("Core");
 115 
 116     // Add new tests here: ***************
 117     mctest_add_parameterized_test (tc_core, test_mc_build_filename, test_mc_build_filename_ds);
 118     // ***********************************
 119 
 120     return mctest_run_all (tc_core);
 121 }
 122 
 123 /* --------------------------------------------------------------------------------------------- */

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