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-2024
   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 <http://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 /* *INDENT-OFF* */
  88 static const struct test_ftpfs_parse_long_list_ds
  89 {
  90     const char *name;
  91 } test_ftpfs_parse_long_list_ds[] =
  92 {
  93     { /* 0. Ticket #2841 */
  94         "aix"
  95     },
  96     { /* 1. Ticket #3174 */
  97         "ms"
  98     }
  99 };
 100 /* *INDENT-ON* */
 101 
 102 /* @Test(dataSource = "test_ftpfs_parse_long_list_ds") */
 103 /* *INDENT-OFF* */
 104 START_PARAMETRIZED_TEST (test_ftpfs_parse_long_list, test_ftpfs_parse_long_list_ds)
     /* [previous][next][first][last][top][bottom][index][help]  */
 105 /* *INDENT-ON* */
 106 {
 107     /* given */
 108     char *name;
 109     GSList *input, *parsed, *output;
 110     GSList *parsed_iter, *output_iter;
 111     int err_count;
 112 
 113     /* when */
 114     name = g_strdup_printf ("%s/%s_list.input", TEST_DATA_DIR, data->name);
 115     input = read_list (name);
 116     g_free (name);
 117     mctest_assert_not_null (input);
 118 
 119     name = g_strdup_printf ("%s/%s_list.output", TEST_DATA_DIR, data->name);
 120     output = read_list (name);
 121     g_free (name);
 122     mctest_assert_not_null (output);
 123 
 124     parsed = ftpfs_parse_long_list (me, super->root, input, &err_count);
 125 
 126     /* then */
 127     for (parsed_iter = parsed, output_iter = output;
 128          parsed_iter != NULL && output_iter != NULL;
 129          parsed_iter = g_slist_next (parsed_iter), output_iter = g_slist_next (output_iter))
 130         mctest_assert_str_eq (VFS_ENTRY (parsed_iter->data)->name, (char *) output_iter->data);
 131 
 132     mctest_assert_null (parsed_iter);
 133     mctest_assert_null (output_iter);
 134 
 135     for (parsed_iter = parsed, output_iter = output; parsed_iter != NULL;
 136          parsed_iter = g_slist_next (parsed_iter))
 137         vfs_s_free_entry (me, VFS_ENTRY (parsed_iter->data));
 138 
 139     g_slist_free (parsed);
 140 
 141     g_slist_free_full (input, g_free);
 142     g_slist_free_full (output, g_free);
 143 }
 144 /* *INDENT-OFF* */
 145 END_PARAMETRIZED_TEST
 146 /* *INDENT-ON* */
 147 
 148 /* --------------------------------------------------------------------------------------------- */
 149 
 150 int
 151 main (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 152 {
 153     TCase *tc_core;
 154 
 155     tc_core = tcase_create ("Core");
 156 
 157     tcase_add_checked_fixture (tc_core, setup, teardown);
 158 
 159     /* Add new tests here: *************** */
 160     mctest_add_parameterized_test (tc_core, test_ftpfs_parse_long_list,
 161                                    test_ftpfs_parse_long_list_ds);
 162     /* *********************************** */
 163 
 164     return mctest_run_all (tc_core);
 165 }
 166 
 167 /* --------------------------------------------------------------------------------------------- */

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