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

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

DEFINITIONS

This source file includes following definitions.
  1. null_message_fn
  2. fake_text_init
  3. fake_text_free_priv
  4. mk_fake_text_output
  5. setup
  6. teardown
  7. no_messages
  8. messages

   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 static int
  16 null_message_fn(pcmk__output_t *out, va_list args) {
     /* [previous][next][first][last][top][bottom][index][help] */
  17     return pcmk_rc_ok;
  18 }
  19 
  20 static bool
  21 fake_text_init(pcmk__output_t *out) {
     /* [previous][next][first][last][top][bottom][index][help] */
  22     return true;
  23 }
  24 
  25 static void
  26 fake_text_free_priv(pcmk__output_t *out) {
     /* [previous][next][first][last][top][bottom][index][help] */
  27     function_called();
  28     /* This function intentionally left blank */
  29 }
  30 
  31 static pcmk__output_t *
  32 mk_fake_text_output(char **argv) {
     /* [previous][next][first][last][top][bottom][index][help] */
  33     pcmk__output_t *retval = calloc(1, sizeof(pcmk__output_t));
  34 
  35     if (retval == NULL) {
  36         return NULL;
  37     }
  38 
  39     retval->fmt_name = "text";
  40     retval->init = fake_text_init;
  41     retval->free_priv = fake_text_free_priv;
  42 
  43     retval->register_message = pcmk__register_message;
  44     retval->message = pcmk__call_message;
  45 
  46     return retval;
  47 }
  48 
  49 static int
  50 setup(void **state) {
     /* [previous][next][first][last][top][bottom][index][help] */
  51     pcmk__register_format(NULL, "text", mk_fake_text_output, NULL);
  52     return 0;
  53 }
  54 
  55 static int
  56 teardown(void **state) {
     /* [previous][next][first][last][top][bottom][index][help] */
  57     pcmk__unregister_formats();
  58     return 0;
  59 }
  60 
  61 static void
  62 no_messages(void **state) {
     /* [previous][next][first][last][top][bottom][index][help] */
  63     pcmk__output_t *out = NULL;
  64 
  65     pcmk__output_new(&out, "text", NULL, NULL);
  66 
  67     expect_function_call(fake_text_free_priv);
  68     pcmk__output_free(out);
  69 }
  70 
  71 static void
  72 messages(void **state) {
     /* [previous][next][first][last][top][bottom][index][help] */
  73     pcmk__output_t *out = NULL;
  74 
  75     pcmk__output_new(&out, "text", NULL, NULL);
  76     pcmk__register_message(out, "fake", null_message_fn);
  77 
  78     expect_function_call(fake_text_free_priv);
  79     pcmk__output_free(out);
  80 }
  81 
  82 PCMK__UNIT_TEST(NULL, NULL,
  83                 cmocka_unit_test_setup_teardown(no_messages, setup, teardown),
  84                 cmocka_unit_test_setup_teardown(messages, setup, teardown))

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