pacemaker  2.1.7-0f7f88312f
Scalable High-Availability cluster resource manager
pcmk__new_common_args_test.c
Go to the documentation of this file.
1 /*
2  * Copyright 2023 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 
14 
15 #include "mock_private.h"
16 
17 #include <glib.h>
18 
19 static void
20 calloc_fails(void **state)
21 {
23  {
24  pcmk__mock_calloc = true; // calloc() will return NULL
25  expect_value(__wrap_calloc, nmemb, 1);
26  expect_value(__wrap_calloc, size, sizeof(pcmk__common_args_t));
27  pcmk__new_common_args("boring summary");
28  pcmk__mock_calloc = false; // Use real calloc()
29  }
30  );
31 }
32 
33 static void
34 strdup_fails(void **state)
35 {
37  {
38  pcmk__mock_strdup = true; // strdup() will return NULL
39  expect_string(__wrap_strdup, s, "boring summary");
40  pcmk__new_common_args("boring summary");
41  pcmk__mock_strdup = false; // Use the real strdup()
42  }
43  );
44 }
45 
46 static void
47 success(void **state)
48 {
49  pcmk__common_args_t *args = pcmk__new_common_args("boring summary");
50  assert_string_equal(args->summary, "boring summary");
51  assert_null(args->output_as_descr);
52  assert_false(args->version);
53  assert_false(args->quiet);
54  assert_int_equal(args->verbosity, 0);
55  assert_null(args->output_ty);
56  assert_null(args->output_dest);
57 }
58 
59 PCMK__UNIT_TEST(NULL, NULL,
60  cmocka_unit_test(calloc_fails),
61  cmocka_unit_test(strdup_fails),
62  cmocka_unit_test(success))
uint32_t size
Definition: cpg.c:49
pcmk__common_args_t * pcmk__new_common_args(const char *summary)
Definition: cmdline.c:28
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))
External (OS/environmental) problem.
Definition: results.h:261
#define pcmk__assert_exits(rc, stmt)
unsigned int verbosity
bool pcmk__mock_calloc
Definition: mock.c:68
bool pcmk__mock_strdup
Definition: mock.c:403
void * __wrap_calloc(size_t nmemb, size_t size)
Definition: mock.c:71
char * __wrap_strdup(const char *s)
Definition: mock.c:406