root/lib/common/tests/cmdline/pcmk__new_common_args_test.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. calloc_fails
  2. strdup_fails
  3. success

   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 
  12 #include <crm/common/unittest_internal.h>
  13 #include <crm/common/cmdline_internal.h>
  14 
  15 #include "mock_private.h"
  16 
  17 #include <glib.h>
  18 
  19 static void
  20 calloc_fails(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  21 {
  22     pcmk__assert_exits(CRM_EX_OSERR,
  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)
     /* [previous][next][first][last][top][bottom][index][help] */
  35 {
  36     pcmk__assert_exits(CRM_EX_OSERR,
  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)
     /* [previous][next][first][last][top][bottom][index][help] */
  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))

/* [previous][next][first][last][top][bottom][index][help] */