root/lib/common/tests/output/pcmk__output_and_clear_error_test.c

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

DEFINITIONS

This source file includes following definitions.
  1. fake_text_init
  2. fake_text_free_priv
  3. G_GNUC_PRINTF
  4. mk_fake_text_output
  5. setup
  6. teardown
  7. standard_usage

   1 /*
   2  * Copyright 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 Lesser General Public License
   7  * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY.
   8  */
   9 
  10 #include <crm_internal.h>
  11 
  12 #include <crm/common/unittest_internal.h>
  13 #include <crm/common/output_internal.h>
  14 
  15 #include <glib.h>
  16 
  17 static bool
  18 fake_text_init(pcmk__output_t *out) {
     /* [previous][next][first][last][top][bottom][index][help] */
  19     return true;
  20 }
  21 
  22 static void
  23 fake_text_free_priv(pcmk__output_t *out) {
     /* [previous][next][first][last][top][bottom][index][help] */
  24     /* This function intentionally left blank */
  25 }
  26 
  27 G_GNUC_PRINTF(2, 3)
     /* [previous][next][first][last][top][bottom][index][help] */
  28 static void
  29 fake_text_err(pcmk__output_t *out, const char *format, ...) {
  30     function_called();
  31 }
  32 
  33 static pcmk__output_t *
  34 mk_fake_text_output(char **argv) {
     /* [previous][next][first][last][top][bottom][index][help] */
  35     pcmk__output_t *retval = calloc(1, sizeof(pcmk__output_t));
  36 
  37     if (retval == NULL) {
  38         return NULL;
  39     }
  40 
  41     retval->fmt_name = "text";
  42     retval->init = fake_text_init;
  43     retval->free_priv = fake_text_free_priv;
  44 
  45     retval->register_message = pcmk__register_message;
  46     retval->message = pcmk__call_message;
  47 
  48     retval->err = fake_text_err;
  49 
  50     return retval;
  51 }
  52 
  53 static int
  54 setup(void **state) {
     /* [previous][next][first][last][top][bottom][index][help] */
  55     pcmk__register_format(NULL, "text", mk_fake_text_output, NULL);
  56     return 0;
  57 }
  58 
  59 static int
  60 teardown(void **state) {
     /* [previous][next][first][last][top][bottom][index][help] */
  61     pcmk__unregister_formats();
  62     return 0;
  63 }
  64 
  65 static void
  66 standard_usage(void **state) {
     /* [previous][next][first][last][top][bottom][index][help] */
  67     GError *error = NULL;
  68     pcmk__output_t *out = NULL;
  69 
  70     pcmk__output_new(&out, "text", NULL, NULL);
  71     g_set_error(&error, PCMK__RC_ERROR, pcmk_rc_bad_nvpair,
  72                 "some error message");
  73 
  74     expect_function_call(fake_text_err);
  75     pcmk__output_and_clear_error(error, out);
  76 
  77     pcmk__output_free(out);
  78     assert_null(error->message);
  79 }
  80 
  81 PCMK__UNIT_TEST(NULL, NULL,
  82                 cmocka_unit_test_setup_teardown(standard_usage, setup, teardown))

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