pacemaker 2.1.5-a3f44794f94
Scalable High-Availability cluster resource manager
pcmk__full_path_test.c
Go to the documentation of this file.
1/*
2 * Copyright 2020-2022 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
13
14#include "mock_private.h"
15
16static void
17function_asserts(void **state)
18{
21
23 {
24 pcmk__mock_strdup = true; // strdup() will return NULL
25 expect_string(__wrap_strdup, s, "/full/path");
26 pcmk__full_path("/full/path", "/dir");
27 pcmk__mock_strdup = false; // Use real strdup()
28 }
29 );
30}
31
32static void
33full_path(void **state)
34{
35 char *path = NULL;
36
37 path = pcmk__full_path("file", "/dir");
38 assert_int_equal(strcmp(path, "/dir/file"), 0);
39 free(path);
40
41 path = pcmk__full_path("/full/path", "/dir");
42 assert_int_equal(strcmp(path, "/full/path"), 0);
43 free(path);
44
45 path = pcmk__full_path("../relative/path", "/dir");
46 assert_int_equal(strcmp(path, "/dir/../relative/path"), 0);
47 free(path);
48}
49
50PCMK__UNIT_TEST(NULL, NULL,
51 cmocka_unit_test(function_asserts),
52 cmocka_unit_test(full_path))
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:628
char * __wrap_strdup(const char *s)
Definition: mock.c:382
bool pcmk__mock_strdup
Definition: mock.c:379
#define pcmk__assert_asserts(stmt)
#define PCMK__UNIT_TEST(group_setup, group_teardown,...)