Manual pages: mcmcdiffmceditmcview

root/tests/src/filemanager/ext__exec_make_shell_string.c

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

DEFINITIONS

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

   1 /*
   2    src/filemanager - exec_make_shell_string() function testing
   3 
   4    Copyright (C) 2026
   5    Free Software Foundation, Inc.
   6 
   7    Written by:
   8    Manuel Einfalt <einfalt1@proton.me>, 2026
   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 #include "lib/global.h"
  30 #include "lib/vfs/path.h"
  31 #include "src/vfs/local/local.h"
  32 #include "lib/strutil.h"
  33 #include "src/filemanager/panel.h"
  34 
  35 MC_TESTABLE GString *exec_make_shell_string (const char *lc_data, const vfs_path_t *filename_vpath,
  36                                              GString **buffer);
  37 
  38 /* --------------------------------------------------------------------------------------------- */
  39 
  40 static struct test_paths
  41 {
  42     const char *lc_data;
  43     const char *path;
  44     const char *expected_buffer;
  45     const char *expected_ret;
  46 } test_paths[] = { { "/foo/bar/hello_world.c", "/does_not_appear", NULL, "/foo/bar/hello_world.c" },
  47                    { "%cd /tmp/file/with/a/longer/path/name/xyz.sock", "/never/used",
  48                      "/tmp/file/with/a/longer/path/name/xyz.sock", "" },
  49                    { "%f/utar://", "/path/to/foo.tar", NULL, "/path/to/foo.tar/utar://" },
  50                    { "%cd %f", "/path/to/directory", "/path/to/directory", "" },
  51                    { "%f%cd /dev", "/etc/mc", "/dev", "/etc/mc" },
  52                    { "%cd %f%view{ascii}/some/subdir", "/tmp", "/tmp/some/subdir", "" }
  53 
  54 };
  55 
  56 /* --------------------------------------------------------------------------------------------- */
  57 
  58 static void
  59 setup (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
  60 {
  61     str_init_strings (NULL);
  62     vfs_init ();
  63     vfs_init_localfs ();
  64 }
  65 
  66 /* --------------------------------------------------------------------------------------------- */
  67 
  68 START_PARAMETRIZED_TEST (shell_str_test, test_paths)
     /* [previous][next][first][last][top][bottom][index][help]  */
  69 {
  70     vfs_path_t *vpath;
  71     GString *gs;
  72     GString *buffer = NULL;
  73 
  74     vpath = vfs_path_from_str (data->path);
  75     gs = exec_make_shell_string (data->lc_data, vpath, &buffer);
  76     vfs_path_free (vpath, FALSE);
  77 
  78     if (buffer == NULL)
  79     {
  80         mctest_assert_null (data->expected_buffer);
  81     }
  82     else
  83     {
  84         mctest_assert_str_eq (buffer->str, data->expected_buffer);
  85     }
  86     mctest_assert_str_eq (gs->str, data->expected_ret);
  87 
  88     if (buffer != NULL)
  89         g_string_free (buffer, TRUE);
  90     g_string_free (gs, TRUE);
  91 }
  92 END_PARAMETRIZED_TEST
  93 
  94 /* --------------------------------------------------------------------------------------------- */
  95 
  96 int
  97 main (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
  98 {
  99     TCase *tc_core;
 100 
 101     tc_core = tcase_create ("Core");
 102     tcase_add_checked_fixture (tc_core, setup, NULL);
 103 
 104     // Add new tests here: ***************
 105     mctest_add_parameterized_test (tc_core, shell_str_test, test_paths);
 106     // ***********************************
 107 
 108     return mctest_run_all (tc_core);
 109 }
 110 
 111 /* --------------------------------------------------------------------------------------------- */

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