root/tests/lib/x_basename.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 - x_basename() 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"
  27 
  28 #include "tests/mctest.h"
  29 
  30 #include <stdio.h>
  31 
  32 #include "lib/strutil.h"
  33 #include "lib/util.h"
  34 
  35 /* --------------------------------------------------------------------------------------------- */
  36 
  37 /* @Before */
  38 static void
  39 setup (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
  40 {
  41 }
  42 
  43 /* --------------------------------------------------------------------------------------------- */
  44 
  45 /* @After */
  46 static void
  47 teardown (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
  48 {
  49 }
  50 
  51 /* --------------------------------------------------------------------------------------------- */
  52 
  53 /* @DataSource("test_x_basename_ds") */
  54 static const struct test_x_basename_ds
  55 {
  56     const char *input_value;
  57     const char *expected_result;
  58 } test_x_basename_ds[] = {
  59     {
  60         "/test/path/test2/path2",
  61         "path2",
  62     },
  63     {
  64         "/test/path/test2/path2#vfsprefix",
  65         "path2#vfsprefix",
  66     },
  67     {
  68         "/test/path/test2/path2/vfsprefix://",
  69         "path2/vfsprefix://",
  70     },
  71     {
  72         "/test/path/test2/path2/vfsprefix://subdir",
  73         "subdir",
  74     },
  75     {
  76         "/test/path/test2/path2/vfsprefix://subdir/",
  77         "subdir/",
  78     },
  79     {
  80         "/test/path/test2/path2/vfsprefix://subdir/subdir2",
  81         "subdir2",
  82     },
  83     {
  84         "/test/path/test2/path2/vfsprefix:///",
  85         "/",
  86     },
  87 };
  88 
  89 /* @Test(dataSource = "test_x_basename_ds") */
  90 START_PARAMETRIZED_TEST (test_x_basename, test_x_basename_ds)
     /* [previous][next][first][last][top][bottom][index][help]  */
  91 {
  92     // given
  93     const char *actual_result;
  94 
  95     // when
  96     actual_result = x_basename (data->input_value);
  97 
  98     // then
  99     mctest_assert_str_eq (actual_result, data->expected_result);
 100 }
 101 END_PARAMETRIZED_TEST
 102 
 103 /* --------------------------------------------------------------------------------------------- */
 104 
 105 int
 106 main (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 107 {
 108     TCase *tc_core;
 109 
 110     tc_core = tcase_create ("Core");
 111 
 112     tcase_add_checked_fixture (tc_core, setup, teardown);
 113 
 114     // Add new tests here: ***************
 115     mctest_add_parameterized_test (tc_core, test_x_basename, test_x_basename_ds);
 116     // ***********************************
 117 
 118     return mctest_run_all (tc_core);
 119 }
 120 
 121 /* --------------------------------------------------------------------------------------------- */

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