pacemaker 3.0.1-16e74fc4da
Scalable High-Availability cluster resource manager
Loading...
Searching...
No Matches
pcmk__full_path_test.c
Go to the documentation of this file.
1/*
2 * Copyright 2020-2024 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 General Public License version 2
7 * or later (GPLv2+) 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}
22
23static void
24function_exits(void **state)
25{
28 {
29 pcmk__mock_strdup = true; // strdup() will return NULL
30 expect_string(__wrap_strdup, s, "/full/path");
31 pcmk__full_path("/full/path", "/dir");
32 pcmk__mock_strdup = false; // Use real strdup()
33 }
34 );
35}
36
37static void
38full_path(void **state)
39{
40 char *path = NULL;
41
42 path = pcmk__full_path("file", "/dir");
43 assert_int_equal(strcmp(path, "/dir/file"), 0);
44 free(path);
45
46 path = pcmk__full_path("/full/path", "/dir");
47 assert_int_equal(strcmp(path, "/full/path"), 0);
48 free(path);
49
50 path = pcmk__full_path("../relative/path", "/dir");
51 assert_int_equal(strcmp(path, "/dir/../relative/path"), 0);
52 free(path);
53}
54
55PCMK__UNIT_TEST(NULL, NULL,
56 cmocka_unit_test(function_asserts),
57 cmocka_unit_test(function_exits),
58 cmocka_unit_test(full_path))
const char * path
Definition cib.c:28
char * pcmk__full_path(const char *filename, const char *dirname)
Duplicate a file path, inserting a prefix if not absolute.
Definition io.c:631
char * __wrap_strdup(const char *s)
Definition mock.c:452
bool pcmk__mock_strdup
Definition mock.c:449
@ CRM_EX_OSERR
External (OS/environmental) problem.
Definition results.h:254
#define pcmk__assert_exits(rc, stmt)
#define pcmk__assert_asserts(stmt)
#define PCMK__UNIT_TEST(group_setup, group_teardown,...)