Manual pages: mcmcdiffmceditmcview

root/tests/lib/vfs/path_serialize.c

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

DEFINITIONS

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

   1 /*
   2    lib/vfs - vfs_path_t serialize/deserialize functions
   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/vfs"
  27 
  28 #include "tests/mctest.h"
  29 
  30 #include "lib/charsets.h"
  31 #include "lib/strutil.h"
  32 #include "lib/vfs/xdirentry.h"
  33 #include "lib/vfs/path.h"
  34 
  35 #include "src/vfs/local/local.c"
  36 
  37 static struct vfs_class vfs_test_ops1, vfs_test_ops2, vfs_test_ops3;
  38 
  39 /* --------------------------------------------------------------------------------------------- */
  40 
  41 /* @Before */
  42 static void
  43 setup (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
  44 {
  45     str_init_strings ("UTF-8");
  46 
  47     vfs_init ();
  48     vfs_init_localfs ();
  49     vfs_setup_work_dir ();
  50 
  51     vfs_init_class (&vfs_test_ops1, "testfs1", VFSF_NOLINKS | VFSF_REMOTE, "test1");
  52     vfs_register_class (&vfs_test_ops1);
  53 
  54     vfs_init_class (&vfs_test_ops2, "testfs2", VFSF_UNKNOWN, "test2");
  55     vfs_register_class (&vfs_test_ops2);
  56 
  57     vfs_init_class (&vfs_test_ops3, "testfs3", VFSF_UNKNOWN, "test3");
  58     vfs_register_class (&vfs_test_ops3);
  59 
  60     mc_global.sysconfig_dir = (char *) TEST_SHARE_DIR;
  61     load_codepages_list ();
  62 }
  63 
  64 /* --------------------------------------------------------------------------------------------- */
  65 
  66 /* @After */
  67 static void
  68 teardown (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
  69 {
  70     free_codepages_list ();
  71     vfs_shut ();
  72     str_uninit_strings ();
  73 }
  74 
  75 /* --------------------------------------------------------------------------------------------- */
  76 
  77 #define ETALON_PATH_STR                                                                            \
  78     "/local/path/#test1:user:pass@some.host:12345/bla-bla/some/path/#test2/#enc:KOI8-R/"           \
  79     "bla-bla/some/path#test3/111/22/33"
  80 #define ETALON_PATH_URL_STR                                                                        \
  81     "/local/path/test1://user:pass@some.host:12345/bla-bla/some/path/test2://#enc:KOI8-R/"         \
  82     "bla-bla/some/path/test3://111/22/33"
  83 #define ETALON_SERIALIZED_PATH                                                                     \
  84     "g14:path-element-0"                                                                           \
  85     "p4:pathv12:/local/path/"                                                                      \
  86     "p10:class-namev7:localfs"                                                                     \
  87     "g14:path-element-1"                                                                           \
  88     "p4:pathv18:bla-bla/some/path/"                                                                \
  89     "p10:class-namev7:testfs1"                                                                     \
  90     "p10:vfs_prefixv5:test1"                                                                       \
  91     "p4:userv4:user"                                                                               \
  92     "p8:passwordv4:pass"                                                                           \
  93     "p4:hostv9:some.host"                                                                          \
  94     "p4:portv5:12345"                                                                              \
  95     "g14:path-element-2"                                                                           \
  96     "p4:pathv17:bla-bla/some/path"                                                                 \
  97     "p10:class-namev7:testfs2"                                                                     \
  98     "p8:encodingv6:KOI8-R"                                                                         \
  99     "p10:vfs_prefixv5:test2"                                                                       \
 100     "g14:path-element-3"                                                                           \
 101     "p4:pathv9:111/22/33"                                                                          \
 102     "p10:class-namev7:testfs3"                                                                     \
 103     "p10:vfs_prefixv5:test3"
 104 
 105 START_TEST (test_path_serialize)
     /* [previous][next][first][last][top][bottom][index][help]  */
 106 {
 107     // given
 108     vfs_path_t *vpath;
 109     char *serialized_vpath;
 110     GError *error = NULL;
 111 
 112     // when
 113     vpath = vfs_path_from_str_flags (ETALON_PATH_STR, VPF_USE_DEPRECATED_PARSER);
 114     serialized_vpath = vfs_path_serialize (vpath, &error);
 115 
 116     vfs_path_free (vpath, TRUE);
 117 
 118     if (error != NULL)
 119         g_error_free (error);
 120 
 121     // then
 122     mctest_assert_ptr_ne (serialized_vpath, NULL);
 123     mctest_assert_str_eq (serialized_vpath, ETALON_SERIALIZED_PATH);
 124 }
 125 END_TEST
 126 
 127 /* --------------------------------------------------------------------------------------------- */
 128 
 129 START_TEST (test_path_deserialize)
     /* [previous][next][first][last][top][bottom][index][help]  */
 130 {
 131     // given
 132     vfs_path_t *vpath;
 133     GError *error = NULL;
 134 
 135     // when
 136     vpath = vfs_path_deserialize (ETALON_SERIALIZED_PATH, &error);
 137 
 138     // then
 139     mctest_assert_ptr_ne (vpath, NULL);
 140     mctest_assert_str_eq (vfs_path_as_str (vpath), ETALON_PATH_URL_STR);
 141 
 142     vfs_path_free (vpath, TRUE);
 143 }
 144 END_TEST
 145 
 146 /* --------------------------------------------------------------------------------------------- */
 147 
 148 int
 149 main (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 150 {
 151     TCase *tc_core;
 152 
 153     tc_core = tcase_create ("Core");
 154 
 155     tcase_add_checked_fixture (tc_core, setup, teardown);
 156 
 157     // Add new tests here: ***************
 158     tcase_add_test (tc_core, test_path_serialize);
 159     tcase_add_test (tc_core, test_path_deserialize);
 160     // ***********************************
 161 
 162     return mctest_run_all (tc_core);
 163 }
 164 
 165 /* --------------------------------------------------------------------------------------------- */

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