1 /* lib/vfs - vfs_path_t compare 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"
45 str_init_strings (NULL
);
49 vfs_setup_work_dir ();
51 mc_global
.sysconfig_dir
= (char *) TEST_SHARE_DIR
;
52 load_codepages_list ();
58 free_codepages_list ();
61 str_uninit_strings ();
64 /* --------------------------------------------------------------------------------------------- */
65 #define path_cmp_one_check(input1, input2, etalon_condition) {\
66 vpath1 = vfs_path_from_str (input1);\
67 vpath2 = vfs_path_from_str (input2);\
68 result = vfs_path_cmp (vpath1, vpath2);\
69 vfs_path_free (vpath1); \
70 vfs_path_free (vpath2); \
71 fail_unless ( result etalon_condition, "\ninput1: %s\ninput2: %s\nexpected: %d\nactual: %d\n",\
72 input1, input2, #etalon_condition, result); \
75 START_TEST (test_path_compare
)
77 vfs_path_t
*vpath1
, *vpath2
;
80 path_cmp_one_check ("/тестовый/путь", "/тестовый/путь", ==0);
82 path_cmp_one_check ("/#enc:KOI8-R/тестовый/путь", "/тестовый/путь", <0);
84 path_cmp_one_check ("/тестовый/путь", "/#enc:KOI8-R/тестовый/путь", >0);
86 path_cmp_one_check (NULL
, "/тестовый/путь", -1);
87 path_cmp_one_check ("/тестовый/путь", NULL
, -1);
88 path_cmp_one_check (NULL
, NULL
, -1);
92 /* --------------------------------------------------------------------------------------------- */
93 #undef path_cmp_one_check
95 #define path_cmp_one_check(input1, input2, len, etalon_condition) {\
96 vpath1 = vfs_path_from_str (input1);\
97 vpath2 = vfs_path_from_str (input2);\
98 result = vfs_path_ncmp (vpath1, vpath2, len);\
99 vfs_path_free (vpath1); \
100 vfs_path_free (vpath2); \
101 fail_unless ( result etalon_condition, "\ninput1: %s\ninput2: %s\nexpected: %d\nactual: %d\n",\
102 input1, input2, #etalon_condition, result); \
105 START_TEST (test_path_compare_len
)
107 vfs_path_t
*vpath1
, *vpath2
;
110 path_cmp_one_check ("/тестовый/путь", "/тестовый/путь", 10, ==0);
112 path_cmp_one_check ("/тест/овый/путь", "/тестовый/путь", 10, <0);
114 path_cmp_one_check ("/тестовый/путь", "/тест/овый/путь", 10, >0);
116 path_cmp_one_check ("/тест/овый/путь", "/тестовый/путь", 9, ==0);
118 path_cmp_one_check (NULL
, "/тестовый/путь", 0, <0);
119 path_cmp_one_check ("/тестовый/путь", NULL
, 0, <0);
120 path_cmp_one_check (NULL
, NULL
, 0, <0);
124 /* --------------------------------------------------------------------------------------------- */
131 Suite
*s
= suite_create (TEST_SUITE_NAME
);
132 TCase
*tc_core
= tcase_create ("Core");
135 tcase_add_checked_fixture (tc_core
, setup
, teardown
);
137 /* Add new tests here: *************** */
138 tcase_add_test (tc_core
, test_path_compare
);
139 tcase_add_test (tc_core
, test_path_compare_len
);
140 /* *********************************** */
142 suite_add_tcase (s
, tc_core
);
143 sr
= srunner_create (s
);
144 srunner_set_log (sr
, "path_cmp.log");
145 srunner_run_all (sr
, CK_NORMAL
);
146 number_failed
= srunner_ntests_failed (sr
);
148 return (number_failed
== 0) ? 0 : 1;
151 /* --------------------------------------------------------------------------------------------- */