pacemaker  2.1.9-49aab99839
Scalable High-Availability cluster resource manager
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 
16 static void
17 function_asserts(void **state)
18 {
21 }
22 
23 static void
24 function_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 
37 static void
38 full_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 
55 PCMK__UNIT_TEST(NULL, NULL,
56  cmocka_unit_test(function_asserts),
57  cmocka_unit_test(function_exits),
58  cmocka_unit_test(full_path))
#define PCMK__UNIT_TEST(group_setup, group_teardown,...)
External (OS/environmental) problem.
Definition: results.h:272
#define pcmk__assert_asserts(stmt)
char * pcmk__full_path(const char *filename, const char *dirname)
Duplicate a file path, inserting a prefix if not absolute.
Definition: io.c:634
#define pcmk__assert_exits(rc, stmt)
const char * path
Definition: cib.c:28
bool pcmk__mock_strdup
Definition: mock.c:450
char * __wrap_strdup(const char *s)
Definition: mock.c:453