root/lib/common/tests/utils/pcmk_hostname_test.c

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

DEFINITIONS

This source file includes following definitions.
  1. uname_succeeded_test
  2. uname_failed_test

   1 /*
   2  * Copyright 2021 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 
  14 #include "mock_private.h"
  15 
  16 #include <sys/utsname.h>
  17 
  18 static void
  19 uname_succeeded_test(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  20 {
  21     char *retval;
  22 
  23     // Set uname() return value and buf parameter node name
  24     pcmk__mock_uname = true;
  25 
  26     expect_any(__wrap_uname, buf);
  27     will_return(__wrap_uname, 0);
  28     will_return(__wrap_uname, "somename");
  29 
  30     retval = pcmk_hostname();
  31     assert_non_null(retval);
  32     assert_string_equal("somename", retval);
  33 
  34     free(retval);
  35 
  36     pcmk__mock_uname = false;
  37 }
  38 
  39 static void
  40 uname_failed_test(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  41 {
  42     // Set uname() return value and buf parameter node name
  43     pcmk__mock_uname = true;
  44 
  45     expect_any(__wrap_uname, buf);
  46     will_return(__wrap_uname, -1);
  47     will_return(__wrap_uname, NULL);
  48 
  49     assert_null(pcmk_hostname());
  50 
  51     pcmk__mock_uname = false;
  52 }
  53 
  54 PCMK__UNIT_TEST(NULL, NULL,
  55                 cmocka_unit_test(uname_succeeded_test),
  56                 cmocka_unit_test(uname_failed_test))

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