pacemaker  2.1.7-0f7f88312f
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 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 
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 
32 static void
33 full_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 
50 PCMK__UNIT_TEST(NULL, NULL,
51  cmocka_unit_test(function_asserts),
52  cmocka_unit_test(full_path))
PCMK__UNIT_TEST(NULL, NULL, cmocka_unit_test(bad_input), cmocka_unit_test(not_found), cmocka_unit_test(find_attrB), cmocka_unit_test(find_attrA_matching))
#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
const char * path
Definition: cib.c:28
bool pcmk__mock_strdup
Definition: mock.c:403
char * __wrap_strdup(const char *s)
Definition: mock.c:406