1 /* lib/vfs - vfs_path_t serialize/deserialize functions
3 Copyright (C) 2011 Free Software Foundation, Inc.
6 Slava Zanko <slavazanko@gmail.com>, 2011
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Library General Public License
10 as published by the Free Software Foundation; either version 2 of
11 the License, or (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU Library General Public License for more details.
18 You should have received a copy of the GNU Library General Public
19 License along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 #define TEST_SUITE_NAME "/lib/vfs"
27 #include "lib/global.c"
30 #define HAVE_CHARSET 1
33 #include "lib/charsets.h"
35 #include "lib/strutil.h"
36 #include "lib/vfs/xdirentry.h"
37 #include "lib/vfs/path.h"
39 #include "src/vfs/local/local.c"
42 struct vfs_s_subclass test_subclass1
, test_subclass2
, test_subclass3
;
43 struct vfs_class vfs_test_ops1
, vfs_test_ops2
, vfs_test_ops3
;
49 str_init_strings (NULL
);
53 vfs_setup_work_dir ();
56 test_subclass1
.flags
= VFS_S_REMOTE
;
57 vfs_s_init_class (&vfs_test_ops1
, &test_subclass1
);
59 vfs_test_ops1
.name
= "testfs1";
60 vfs_test_ops1
.flags
= VFSF_NOLINKS
;
61 vfs_test_ops1
.prefix
= "test1:";
62 vfs_register_class (&vfs_test_ops1
);
64 vfs_s_init_class (&vfs_test_ops2
, &test_subclass2
);
65 vfs_test_ops2
.name
= "testfs2";
66 vfs_test_ops2
.prefix
= "test2:";
67 vfs_register_class (&vfs_test_ops2
);
69 vfs_s_init_class (&vfs_test_ops3
, &test_subclass3
);
70 vfs_test_ops3
.name
= "testfs3";
71 vfs_test_ops3
.prefix
= "test3:";
72 vfs_register_class (&vfs_test_ops3
);
74 mc_global
.sysconfig_dir
= (char *) TEST_SHARE_DIR
;
75 load_codepages_list ();
81 free_codepages_list ();
84 str_uninit_strings ();
87 /* --------------------------------------------------------------------------------------------- */
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_SERIALIZED_PATH "g14:path-element-0p4:pathv12:/local/path/p10:class-namev7:localfsp4:portv1:0" \
90 "g14:path-element-1p4:pathv18:bla-bla/some/path/p10:class-namev7:testfs1p11:raw_url_strv31:test1:user:pass@some.host:12345p4:portv1:0" \
91 "g14:path-element-2p4:pathv17:bla-bla/some/pathp10:class-namev7:testfs2p8:encodingv6:KOI8-Rp11:raw_url_strv6:test2:p4:portv1:0" \
92 "g14:path-element-3p4:pathv9:111/22/33p10:class-namev7:testfs3p11:raw_url_strv6:test3:p4:portv1:0"
94 START_TEST (test_path_serialize_deserialize
)
97 char *serialized_vpath
;
100 vpath
= vfs_path_from_str (ETALON_PATH_STR
);
101 serialized_vpath
= vfs_path_serialize (vpath
, &error
);
102 vfs_path_free (vpath
);
104 if (serialized_vpath
== NULL
)
106 fail ("serialized_vpath is NULL!\nError code is '%d'; error message is '%s'", error
->code
, error
->message
);
107 g_clear_error (&error
);
112 strcmp (serialized_vpath
, ETALON_SERIALIZED_PATH
) == 0,
113 "serialized_vpath (%s) doesn't equal to etalon (%s)", serialized_vpath
, ETALON_SERIALIZED_PATH
116 vpath
= vfs_path_deserialize (serialized_vpath
, &error
);
117 g_free (serialized_vpath
);
121 fail ("vpath is NULL!\nError code is '%d'; error message is '%s'", error
->code
, error
->message
);
122 g_clear_error (&error
);
126 serialized_vpath
= vfs_path_to_str (vpath
);
128 strcmp (serialized_vpath
, ETALON_PATH_STR
) == 0,
129 "\ndeserialized path (%s)\nnot equal to etalon (%s)", serialized_vpath
, ETALON_PATH_STR
131 vfs_path_free(vpath
);
132 g_free(serialized_vpath
);
137 /* --------------------------------------------------------------------------------------------- */
144 Suite
*s
= suite_create (TEST_SUITE_NAME
);
145 TCase
*tc_core
= tcase_create ("Core");
148 tcase_add_checked_fixture (tc_core
, setup
, teardown
);
150 /* Add new tests here: *************** */
151 tcase_add_test (tc_core
, test_path_serialize_deserialize
);
152 /* *********************************** */
154 suite_add_tcase (s
, tc_core
);
155 sr
= srunner_create (s
);
156 srunner_set_log (sr
, "path_serialize.log");
157 srunner_run_all (sr
, CK_NORMAL
);
158 number_failed
= srunner_ntests_failed (sr
);
160 return (number_failed
== 0) ? 0 : 1;
163 /* --------------------------------------------------------------------------------------------- */