pacemaker 3.0.1-16e74fc4da
Scalable High-Availability cluster resource manager
Loading...
Searching...
No Matches
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
19static void
20calloc_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
33static void
34strdup_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
46static void
47success(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
59PCMK__UNIT_TEST(NULL, NULL,
60 cmocka_unit_test(calloc_fails),
61 cmocka_unit_test(strdup_fails),
62 cmocka_unit_test(success))
pcmk__common_args_t * pcmk__new_common_args(const char *summary)
Definition cmdline.c:28
uint32_t size
Definition cpg.c:4
char * __wrap_strdup(const char *s)
Definition mock.c:452
bool pcmk__mock_calloc
Definition mock.c:89
bool pcmk__mock_strdup
Definition mock.c:449
void * __wrap_calloc(size_t nmemb, size_t size)
Definition mock.c:92
@ CRM_EX_OSERR
External (OS/environmental) problem.
Definition results.h:254
#define pcmk__assert_exits(rc, stmt)
#define PCMK__UNIT_TEST(group_setup, group_teardown,...)