pacemaker 2.1.4-dc6eb4362e
Scalable High-Availability cluster resource manager
pcmk__full_path_test.c
Go to the documentation of this file.
1/*
2 * Copyright 2020-2021 the Pacemaker project contributors
3 *
4 * The version control history for this file may have further details.
5 *
6 * This source code is licensed under the GNU Lesser General Public License
7 * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY.
8 */
9
10#include <crm_internal.h>
11
12#include <stdarg.h>
13#include <stddef.h>
14#include <stdint.h>
15#include <string.h>
16#include <stdlib.h>
17#include <setjmp.h>
18#include <cmocka.h>
19
20static void
21full_path(void **state)
22{
23 char *path = NULL;
24
25 path = pcmk__full_path("file", "/dir");
26 assert_int_equal(strcmp(path, "/dir/file"), 0);
27 free(path);
28
29 path = pcmk__full_path("/full/path", "/dir");
30 assert_int_equal(strcmp(path, "/full/path"), 0);
31 free(path);
32
33 path = pcmk__full_path("../relative/path", "/dir");
34 assert_int_equal(strcmp(path, "/dir/../relative/path"), 0);
35 free(path);
36}
37
38int
39main(int argc, char **argv)
40{
41 const struct CMUnitTest tests[] = {
42 cmocka_unit_test(full_path),
43 };
44
45 cmocka_set_message_output(CM_OUTPUT_TAP);
46 return cmocka_run_group_tests(tests, NULL, NULL);
47}
const char * path
Definition: cib.c:26
char * pcmk__full_path(const char *filename, const char *dirname)
Duplicate a file path, inserting a prefix if not absolute.
Definition: io.c:627
int main(int argc, char **argv)