root/tests/src/vfs/ftpfs/ftpfs_parse_long_list.c

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

DEFINITIONS

This source file includes following definitions.
  1. setup
  2. teardown
  3. read_list
  4. START_PARAMETRIZED_TEST
  5. main

   1 /* src/vfs/ftpfs - tests for ftpfs_parse_long_list() function.
   2 
   3    Copyright (C) 2021-2025
   4    Free Software Foundation, Inc.
   5 
   6    Written by:
   7    Andrew Borodin <aborodin@vmail.ru>, 2021
   8 
   9    This file is part of the Midnight Commander.
  10 
  11    The Midnight Commander is free software: you can redistribute it
  12    and/or modify it under the terms of the GNU General Public License as
  13    published by the Free Software Foundation, either version 3 of the License,
  14    or (at your option) any later version.
  15 
  16    The Midnight Commander is distributed in the hope that it will be useful,
  17    but WITHOUT ANY WARRANTY; without even the implied warranty of
  18    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  19    GNU General Public License for more details.
  20 
  21    You should have received a copy of the GNU General Public License
  22    along with this program.  If not, see <https://www.gnu.org/licenses/>.
  23  */
  24 
  25 #define TEST_SUITE_NAME "/src/vfs/ftpfs"
  26 
  27 #include "tests/mctest.h"
  28 
  29 #include <stdio.h>
  30 
  31 #include "direntry.c"
  32 #include "src/vfs/ftpfs/ftpfs_parse_ls.c"
  33 
  34 /* --------------------------------------------------------------------------------------------- */
  35 
  36 static struct vfs_s_subclass ftpfs_subclass;
  37 static struct vfs_class *me = VFS_CLASS (&ftpfs_subclass);
  38 
  39 static struct vfs_s_super *super;
  40 
  41 /* --------------------------------------------------------------------------------------------- */
  42 
  43 /* @Before */
  44 static void
  45 setup (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
  46 {
  47     vfs_init_subclass (&ftpfs_subclass, "ftpfs", VFSF_NOLINKS | VFSF_REMOTE | VFSF_USETMP, "ftp");
  48 
  49     super = vfs_s_new_super (me);
  50     super->name = g_strdup (PATH_SEP_STR);
  51     super->root = vfs_s_new_inode (me, super, vfs_s_default_stat (me, S_IFDIR | 0755));
  52 }
  53 
  54 /* --------------------------------------------------------------------------------------------- */
  55 
  56 /* @After */
  57 static void
  58 teardown (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
  59 {
  60     vfs_s_free_super (me, super);
  61 }
  62 
  63 /* --------------------------------------------------------------------------------------------- */
  64 
  65 static GSList *
  66 read_list (const char *fname)
     /* [previous][next][first][last][top][bottom][index][help]  */
  67 {
  68     FILE *f;
  69     char buf[BUF_MEDIUM];
  70     GSList *ret = NULL;
  71 
  72     f = fopen (fname, "r");
  73     if (f == NULL)
  74         return NULL;
  75 
  76     while (fgets (buf, sizeof (buf), f) != NULL)
  77         ret = g_slist_prepend (ret, g_strdup (buf));
  78 
  79     fclose (f);
  80 
  81     return ret;
  82 }
  83 
  84 /* --------------------------------------------------------------------------------------------- */
  85 
  86 /* @DataSource("test_ftpfs_parse_long_list_ds") */
  87 static const struct test_ftpfs_parse_long_list_ds
  88 {
  89     const char *name;
  90 } test_ftpfs_parse_long_list_ds[] = {
  91     { "aix" },  // 0. Ticket #2841
  92     { "ms" },   // 1. Ticket #3174
  93 };
  94 
  95 /* @Test(dataSource = "test_ftpfs_parse_long_list_ds") */
  96 START_PARAMETRIZED_TEST (test_ftpfs_parse_long_list, test_ftpfs_parse_long_list_ds)
     /* [previous][next][first][last][top][bottom][index][help]  */
  97 {
  98     // given
  99     char *name;
 100     GSList *input, *parsed, *output;
 101     GSList *parsed_iter, *output_iter;
 102     int err_count;
 103 
 104     // when
 105     name = g_strdup_printf ("%s/%s_list.input", TEST_DATA_DIR, data->name);
 106     input = read_list (name);
 107     g_free (name);
 108     mctest_assert_not_null (input);
 109 
 110     name = g_strdup_printf ("%s/%s_list.output", TEST_DATA_DIR, data->name);
 111     output = read_list (name);
 112     g_free (name);
 113     mctest_assert_not_null (output);
 114 
 115     parsed = ftpfs_parse_long_list (me, super->root, input, &err_count);
 116 
 117     // then
 118     for (parsed_iter = parsed, output_iter = output; parsed_iter != NULL && output_iter != NULL;
 119          parsed_iter = g_slist_next (parsed_iter), output_iter = g_slist_next (output_iter))
 120         mctest_assert_str_eq (VFS_ENTRY (parsed_iter->data)->name, (char *) output_iter->data);
 121 
 122     mctest_assert_null (parsed_iter);
 123     mctest_assert_null (output_iter);
 124 
 125     for (parsed_iter = parsed, output_iter = output; parsed_iter != NULL;
 126          parsed_iter = g_slist_next (parsed_iter))
 127         vfs_s_free_entry (me, VFS_ENTRY (parsed_iter->data));
 128 
 129     g_slist_free (parsed);
 130 
 131     g_slist_free_full (input, g_free);
 132     g_slist_free_full (output, g_free);
 133 }
 134 END_PARAMETRIZED_TEST
 135 
 136 /* --------------------------------------------------------------------------------------------- */
 137 
 138 int
 139 main (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 140 {
 141     TCase *tc_core;
 142 
 143     tc_core = tcase_create ("Core");
 144 
 145     tcase_add_checked_fixture (tc_core, setup, teardown);
 146 
 147     // Add new tests here: ***************
 148     mctest_add_parameterized_test (tc_core, test_ftpfs_parse_long_list,
 149                                    test_ftpfs_parse_long_list_ds);
 150     // ***********************************
 151 
 152     return mctest_run_all (tc_core);
 153 }
 154 
 155 /* --------------------------------------------------------------------------------------------- */

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