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 extern char buffer[BUF_1K];
  36 
  37 MC_TESTABLE GString *exec_make_shell_string (const char *lc_data, const vfs_path_t *filename_vpath);
  38 
  39 /* --------------------------------------------------------------------------------------------- */
  40 
  41 static struct test_paths
  42 {
  43     const char *lc_data;
  44     const char *path;
  45     const char *expected_buffer;
  46     const char *expected_ret;
  47 } test_paths[] = { { "/foo/bar/hello_world.c", "/does_not_appear", "", "/foo/bar/hello_world.c" },
  48                    { "%cd /tmp/file/with/a/longer/path/name/xyz.sock", "/never/used",
  49                      "/tmp/file/with/a/longer/path/name/xyz.sock", "" },
  50                    { "%f/utar://", "/path/to/foo.tar", "", "/path/to/foo.tar/utar://" },
  51                    { "%cd %f", "/path/to/directory", "/path/to/directory", "" },
  52                    { "%f%cd /dev", "/etc/mc", "/dev", "/etc/mc" },
  53                    { "%cd %f%view{ascii}/some/subdir", "/tmp", "/tmp/some/subdir", "" }
  54 
  55 };
  56 
  57 /* --------------------------------------------------------------------------------------------- */
  58 
  59 static void
  60 setup (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
  61 {
  62     str_init_strings (NULL);
  63     vfs_init ();
  64     vfs_init_localfs ();
  65 }
  66 
  67 /* --------------------------------------------------------------------------------------------- */
  68 
  69 START_PARAMETRIZED_TEST (shell_str_test, test_paths)
     /* [previous][next][first][last][top][bottom][index][help]  */
  70 {
  71     vfs_path_t *vpath;
  72     GString *gs;
  73 
  74     vpath = vfs_path_from_str (data->path);
  75     gs = exec_make_shell_string (data->lc_data, vpath);
  76     vfs_path_free (vpath, FALSE);
  77 
  78     mctest_assert_str_eq (buffer, data->expected_buffer);
  79     mctest_assert_str_eq (gs->str, data->expected_ret);
  80 
  81     g_string_free (gs, TRUE);
  82 }
  83 END_PARAMETRIZED_TEST
  84 
  85 /* --------------------------------------------------------------------------------------------- */
  86 
  87 int
  88 main (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
  89 {
  90     TCase *tc_core;
  91 
  92     tc_core = tcase_create ("Core");
  93     tcase_add_checked_fixture (tc_core, setup, NULL);
  94 
  95     // Add new tests here: ***************
  96     mctest_add_parameterized_test (tc_core, shell_str_test, test_paths);
  97     // ***********************************
  98 
  99     return mctest_run_all (tc_core);
 100 }
 101 
 102 /* --------------------------------------------------------------------------------------------- */

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