2 * Copyright (C) - 2013 Raphaƫl Beamonte <raphael.beamonte@gmail.com>
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by as
6 * published by the Free Software Foundation; only version 2 of the License.
8 * This program is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * You should have received a copy of the GNU General Public License along with
14 * this program; if not, write to the Free Software Foundation, Inc., 51
15 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 #include <src/common/utils.h>
28 int lttng_opt_quiet
= 1;
29 int lttng_opt_verbose
= 3;
31 struct valid_test_input
{
33 char *expected_result
;
36 /* Valid test cases */
37 static struct valid_test_input valid_tests_inputs
[] = {
38 { "/a/b/c/d/./e", "/a/b/c/d/e" },
39 { "/a/b/c/d/../e", "/a/b/c/e" },
40 { "/a/b/../c/d/../e", "/a/c/e" },
41 { "/a/b/../../c/./d/./e", "/c/d/e" },
42 { "/a/b/../../c/d/../../e", "/e" },
43 { "/a/b/c/d/../../../../e", "/e" },
44 { "/./a/b/c/d/./e", "/a/b/c/d/e" },
48 static const int num_valid_tests
=
49 sizeof(valid_tests_inputs
) / sizeof(valid_tests_inputs
[0]);
51 /* Invalid test cases */
52 static char *invalid_tests_inputs
[] = {
55 "/a/b/c/d/../../../../../e",
57 static const int num_invalid_tests
=
58 sizeof(invalid_tests_inputs
) / sizeof(invalid_tests_inputs
[0]);
60 static void test_utils_resolve_relative(void)
65 /* Test valid cases */
66 for (i
= 0; i
< num_valid_tests
; i
++) {
68 sprintf(name
, "valid test case: %s", valid_tests_inputs
[i
].input
);
70 result
= utils_resolve_relative(valid_tests_inputs
[i
].input
);
71 ok(strcmp(result
, valid_tests_inputs
[i
].expected_result
) == 0, name
);
76 /* Test invalid cases */
77 for (i
= 0; i
< num_invalid_tests
; i
++) {
79 sprintf(name
, "invalid test case: %s", invalid_tests_inputs
[i
]);
81 result
= utils_resolve_relative(invalid_tests_inputs
[i
]);
85 ok(result
== NULL
, name
);
89 int main(int argc
, char **argv
)
91 plan_tests(num_valid_tests
+ num_invalid_tests
);
93 diag("utils_resolve_relative tests");
95 test_utils_resolve_relative();