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-2020
   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 <http://www.gnu.org/licenses/>.
  24  */
  25 
  26 #define TEST_SUITE_NAME "/lib/vfs"
  27 
  28 #include "tests/mctest.h"
  29 
  30 #ifdef HAVE_CHARSET
  31 #include "lib/charsets.h"
  32 #endif
  33 
  34 #include "lib/strutil.h"
  35 #include "lib/vfs/xdirentry.h"
  36 #include "lib/vfs/path.h"
  37 
  38 #include "src/vfs/local/local.c"
  39 
  40 static struct vfs_class vfs_test_ops1, vfs_test_ops2, vfs_test_ops3;
  41 
  42 /* --------------------------------------------------------------------------------------------- */
  43 
  44 /* @Before */
  45 static void
  46 setup (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
  47 {
  48     mc_global.timer = mc_timer_new ();
  49     str_init_strings (NULL);
  50 
  51     vfs_init ();
  52     vfs_init_localfs ();
  53     vfs_setup_work_dir ();
  54 
  55     vfs_init_class (&vfs_test_ops1, "testfs1", VFSF_NOLINKS | VFSF_REMOTE, "test1");
  56     vfs_register_class (&vfs_test_ops1);
  57 
  58     vfs_init_class (&vfs_test_ops2, "testfs2", VFSF_UNKNOWN, "test2");
  59     vfs_register_class (&vfs_test_ops2);
  60 
  61     vfs_init_class (&vfs_test_ops3, "testfs3", VFSF_UNKNOWN, "test3");
  62     vfs_register_class (&vfs_test_ops3);
  63 
  64     mc_global.sysconfig_dir = (char *) TEST_SHARE_DIR;
  65 #ifdef HAVE_CHARSET
  66     load_codepages_list ();
  67 #endif
  68 }
  69 
  70 /* --------------------------------------------------------------------------------------------- */
  71 
  72 /* @After */
  73 static void
  74 teardown (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
  75 {
  76 #ifdef HAVE_CHARSET
  77     free_codepages_list ();
  78 #endif
  79 
  80     vfs_shut ();
  81     str_uninit_strings ();
  82     mc_timer_destroy (mc_global.timer);
  83 }
  84 
  85 /* --------------------------------------------------------------------------------------------- */
  86 
  87 #ifdef HAVE_CHARSET
  88 #define ETALON_PATH_STR "/local/path/#test1:user:pass@some.host:12345/bla-bla/some/path/#test2/#enc:KOI8-R/bla-bla/some/path#test3/111/22/33"
  89 #define ETALON_PATH_URL_STR "/local/path/test1://user:pass@some.host:12345/bla-bla/some/path/test2://#enc:KOI8-R/bla-bla/some/path/test3://111/22/33"
  90 #define ETALON_SERIALIZED_PATH \
  91     "g14:path-element-0" \
  92         "p4:pathv12:/local/path/" \
  93         "p10:class-namev7:localfs" \
  94     "g14:path-element-1" \
  95         "p4:pathv18:bla-bla/some/path/" \
  96         "p10:class-namev7:testfs1" \
  97         "p10:vfs_prefixv5:test1" \
  98         "p4:userv4:user" \
  99         "p8:passwordv4:pass" \
 100         "p4:hostv9:some.host" \
 101         "p4:portv5:12345" \
 102     "g14:path-element-2" \
 103         "p4:pathv17:bla-bla/some/path" \
 104         "p10:class-namev7:testfs2" \
 105         "p8:encodingv6:KOI8-R" \
 106         "p10:vfs_prefixv5:test2" \
 107     "g14:path-element-3" \
 108         "p4:pathv9:111/22/33" \
 109         "p10:class-namev7:testfs3" \
 110         "p10:vfs_prefixv5:test3"
 111 #else
 112 #define ETALON_PATH_STR "/local/path/#test1:user:pass@some.host:12345/bla-bla/some/path/#test2/bla-bla/some/path#test3/111/22/33"
 113 #define ETALON_PATH_URL_STR "/local/path/test1://user:pass@some.host:12345/bla-bla/some/path/test2://bla-bla/some/path/test3://111/22/33"
 114 #define ETALON_SERIALIZED_PATH \
 115     "g14:path-element-0" \
 116         "p4:pathv12:/local/path/" \
 117         "p10:class-namev7:localfs" \
 118     "g14:path-element-1" \
 119         "p4:pathv18:bla-bla/some/path/" \
 120         "p10:class-namev7:testfs1" \
 121         "p10:vfs_prefixv5:test1" \
 122         "p4:userv4:user" \
 123         "p8:passwordv4:pass" \
 124         "p4:hostv9:some.host" \
 125         "p4:portv5:12345" \
 126     "g14:path-element-2" \
 127         "p4:pathv17:bla-bla/some/path" \
 128         "p10:class-namev7:testfs2" \
 129         "p10:vfs_prefixv5:test2" \
 130     "g14:path-element-3" \
 131         "p4:pathv9:111/22/33" \
 132         "p10:class-namev7:testfs3" \
 133         "p10:vfs_prefixv5:test3"
 134 #endif
 135 
 136 /* *INDENT-OFF* */
 137 START_TEST (test_path_serialize)
     /* [previous][next][first][last][top][bottom][index][help]  */
 138 /* *INDENT-ON* */
 139 {
 140     /* given */
 141     vfs_path_t *vpath;
 142     char *serialized_vpath;
 143     GError *error = NULL;
 144 
 145     /* when */
 146     vpath = vfs_path_from_str_flags (ETALON_PATH_STR, VPF_USE_DEPRECATED_PARSER);
 147     serialized_vpath = vfs_path_serialize (vpath, &error);
 148 
 149     vfs_path_free (vpath);
 150 
 151     if (error != NULL)
 152         g_error_free (error);
 153 
 154     /* then */
 155     mctest_assert_ptr_ne (serialized_vpath, NULL);
 156     mctest_assert_str_eq (serialized_vpath, ETALON_SERIALIZED_PATH);
 157 }
 158 /* *INDENT-OFF* */
 159 END_TEST
 160 /* *INDENT-ON* */
 161 
 162 /* --------------------------------------------------------------------------------------------- */
 163 
 164 /* *INDENT-OFF* */
 165 START_TEST (test_path_deserialize)
     /* [previous][next][first][last][top][bottom][index][help]  */
 166 /* *INDENT-ON* */
 167 {
 168     /* given */
 169     vfs_path_t *vpath;
 170     GError *error = NULL;
 171 
 172     /* when */
 173     vpath = vfs_path_deserialize (ETALON_SERIALIZED_PATH, &error);
 174 
 175     /* then */
 176     mctest_assert_ptr_ne (vpath, NULL);
 177     mctest_assert_str_eq (vfs_path_as_str (vpath), ETALON_PATH_URL_STR);
 178 
 179     vfs_path_free (vpath);
 180 
 181 }
 182 /* *INDENT-OFF* */
 183 END_TEST
 184 /* *INDENT-ON* */
 185 
 186 /* --------------------------------------------------------------------------------------------- */
 187 
 188 int
 189 main (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 190 {
 191     int number_failed;
 192 
 193     Suite *s = suite_create (TEST_SUITE_NAME);
 194     TCase *tc_core = tcase_create ("Core");
 195     SRunner *sr;
 196 
 197     tcase_add_checked_fixture (tc_core, setup, teardown);
 198 
 199     /* Add new tests here: *************** */
 200     tcase_add_test (tc_core, test_path_serialize);
 201     tcase_add_test (tc_core, test_path_deserialize);
 202     /* *********************************** */
 203 
 204     suite_add_tcase (s, tc_core);
 205     sr = srunner_create (s);
 206     srunner_set_log (sr, "path_serialize.log");
 207     srunner_run_all (sr, CK_ENV);
 208     number_failed = srunner_ntests_failed (sr);
 209     srunner_free (sr);
 210     return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
 211 }
 212 
 213 /* --------------------------------------------------------------------------------------------- */

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