2 lib/vfs - vfs_path_t serialize/deserialize functions
4 Copyright (C) 2011-2024
5 Free Software Foundation, Inc.
8 Slava Zanko <slavazanko@gmail.com>, 2011, 2013
10 This file is part of the Midnight Commander.
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.
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.
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/>.
26 #define TEST_SUITE_NAME "/lib/vfs"
28 #include "tests/mctest.h"
31 #include "lib/charsets.h"
34 #include "lib/strutil.h"
35 #include "lib/vfs/xdirentry.h"
36 #include "lib/vfs/path.h"
38 #include "src/vfs/local/local.c"
40 static struct vfs_class vfs_test_ops1
, vfs_test_ops2
, vfs_test_ops3
;
42 /* --------------------------------------------------------------------------------------------- */
48 str_init_strings ("UTF-8");
52 vfs_setup_work_dir ();
54 vfs_init_class (&vfs_test_ops1
, "testfs1", VFSF_NOLINKS
| VFSF_REMOTE
, "test1");
55 vfs_register_class (&vfs_test_ops1
);
57 vfs_init_class (&vfs_test_ops2
, "testfs2", VFSF_UNKNOWN
, "test2");
58 vfs_register_class (&vfs_test_ops2
);
60 vfs_init_class (&vfs_test_ops3
, "testfs3", VFSF_UNKNOWN
, "test3");
61 vfs_register_class (&vfs_test_ops3
);
64 mc_global
.sysconfig_dir
= (char *) TEST_SHARE_DIR
;
65 load_codepages_list ();
69 /* --------------------------------------------------------------------------------------------- */
76 free_codepages_list ();
80 str_uninit_strings ();
83 /* --------------------------------------------------------------------------------------------- */
86 #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"
87 #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"
88 #define ETALON_SERIALIZED_PATH \
89 "g14:path-element-0" \
90 "p4:pathv12:/local/path/" \
91 "p10:class-namev7:localfs" \
92 "g14:path-element-1" \
93 "p4:pathv18:bla-bla/some/path/" \
94 "p10:class-namev7:testfs1" \
95 "p10:vfs_prefixv5:test1" \
97 "p8:passwordv4:pass" \
98 "p4:hostv9:some.host" \
100 "g14:path-element-2" \
101 "p4:pathv17:bla-bla/some/path" \
102 "p10:class-namev7:testfs2" \
103 "p8:encodingv6:KOI8-R" \
104 "p10:vfs_prefixv5:test2" \
105 "g14:path-element-3" \
106 "p4:pathv9:111/22/33" \
107 "p10:class-namev7:testfs3" \
108 "p10:vfs_prefixv5:test3"
110 #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"
111 #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"
112 #define ETALON_SERIALIZED_PATH \
113 "g14:path-element-0" \
114 "p4:pathv12:/local/path/" \
115 "p10:class-namev7:localfs" \
116 "g14:path-element-1" \
117 "p4:pathv18:bla-bla/some/path/" \
118 "p10:class-namev7:testfs1" \
119 "p10:vfs_prefixv5:test1" \
121 "p8:passwordv4:pass" \
122 "p4:hostv9:some.host" \
124 "g14:path-element-2" \
125 "p4:pathv17:bla-bla/some/path" \
126 "p10:class-namev7:testfs2" \
127 "p10:vfs_prefixv5:test2" \
128 "g14:path-element-3" \
129 "p4:pathv9:111/22/33" \
130 "p10:class-namev7:testfs3" \
131 "p10:vfs_prefixv5:test3"
135 START_TEST (test_path_serialize
)
140 char *serialized_vpath
;
141 GError
*error
= NULL
;
144 vpath
= vfs_path_from_str_flags (ETALON_PATH_STR
, VPF_USE_DEPRECATED_PARSER
);
145 serialized_vpath
= vfs_path_serialize (vpath
, &error
);
147 vfs_path_free (vpath
, TRUE
);
150 g_error_free (error
);
153 mctest_assert_ptr_ne (serialized_vpath
, NULL
);
154 mctest_assert_str_eq (serialized_vpath
, ETALON_SERIALIZED_PATH
);
160 /* --------------------------------------------------------------------------------------------- */
163 START_TEST (test_path_deserialize
)
168 GError
*error
= NULL
;
171 vpath
= vfs_path_deserialize (ETALON_SERIALIZED_PATH
, &error
);
174 mctest_assert_ptr_ne (vpath
, NULL
);
175 mctest_assert_str_eq (vfs_path_as_str (vpath
), ETALON_PATH_URL_STR
);
177 vfs_path_free (vpath
, TRUE
);
184 /* --------------------------------------------------------------------------------------------- */
191 tc_core
= tcase_create ("Core");
193 tcase_add_checked_fixture (tc_core
, setup
, teardown
);
195 /* Add new tests here: *************** */
196 tcase_add_test (tc_core
, test_path_serialize
);
197 tcase_add_test (tc_core
, test_path_deserialize
);
198 /* *********************************** */
200 return mctest_run_all (tc_core
);
203 /* --------------------------------------------------------------------------------------------- */