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

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

DEFINITIONS

This source file includes following definitions.
  1. null_create_fn
  2. null_create_fn_2
  3. no_formats
  4. invalid_entries
  5. valid_entries
  6. duplicate_keys
  7. duplicate_values

   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 pcmk__output_t *
  16 null_create_fn(char **argv) {
     /* [previous][next][first][last][top][bottom][index][help] */
  17     return NULL;
  18 }
  19 
  20 static pcmk__output_t *
  21 null_create_fn_2(char **argv) {
     /* [previous][next][first][last][top][bottom][index][help] */
  22     return NULL;
  23 }
  24 
  25 static void
  26 no_formats(void **state) {
     /* [previous][next][first][last][top][bottom][index][help] */
  27     pcmk__register_formats(NULL, NULL);
  28     assert_null(pcmk__output_formatters());
  29 }
  30 
  31 static void
  32 invalid_entries(void **state) {
     /* [previous][next][first][last][top][bottom][index][help] */
  33     /* Here, we can only test that an empty name won't be added.  A NULL name is
  34      * the marker for the end of the format table.
  35      */
  36     pcmk__supported_format_t formats[] = {
  37         { "", null_create_fn, NULL },
  38         { NULL },
  39     };
  40 
  41     pcmk__assert_asserts(pcmk__register_formats(NULL, formats));
  42 }
  43 
  44 static void
  45 valid_entries(void **state) {
     /* [previous][next][first][last][top][bottom][index][help] */
  46     GHashTable *formatters = NULL;
  47 
  48     pcmk__supported_format_t formats[] = {
  49         { "fmt1", null_create_fn, NULL },
  50         { "fmt2", null_create_fn_2, NULL },
  51         { NULL },
  52     };
  53 
  54     pcmk__register_formats(NULL, formats);
  55 
  56     formatters = pcmk__output_formatters();
  57     assert_int_equal(g_hash_table_size(formatters), 2);
  58     assert_ptr_equal(g_hash_table_lookup(formatters, "fmt1"), null_create_fn);
  59     assert_ptr_equal(g_hash_table_lookup(formatters, "fmt2"), null_create_fn_2);
  60 
  61     pcmk__unregister_formats();
  62 }
  63 
  64 static void
  65 duplicate_keys(void **state) {
     /* [previous][next][first][last][top][bottom][index][help] */
  66     GHashTable *formatters = NULL;
  67 
  68     pcmk__supported_format_t formats[] = {
  69         { "fmt1", null_create_fn, NULL },
  70         { "fmt1", null_create_fn_2, NULL },
  71         { NULL },
  72     };
  73 
  74     pcmk__register_formats(NULL, formats);
  75 
  76     formatters = pcmk__output_formatters();
  77     assert_int_equal(g_hash_table_size(formatters), 1);
  78     assert_ptr_equal(g_hash_table_lookup(formatters, "fmt1"), null_create_fn_2);
  79 
  80     pcmk__unregister_formats();
  81 }
  82 
  83 static void
  84 duplicate_values(void **state) {
     /* [previous][next][first][last][top][bottom][index][help] */
  85     GHashTable *formatters = NULL;
  86 
  87     pcmk__supported_format_t formats[] = {
  88         { "fmt1", null_create_fn, NULL },
  89         { "fmt2", null_create_fn, NULL },
  90         { NULL },
  91     };
  92 
  93     pcmk__register_formats(NULL, formats);
  94 
  95     formatters = pcmk__output_formatters();
  96     assert_int_equal(g_hash_table_size(formatters), 2);
  97     assert_ptr_equal(g_hash_table_lookup(formatters, "fmt1"), null_create_fn);
  98     assert_ptr_equal(g_hash_table_lookup(formatters, "fmt2"), null_create_fn);
  99 
 100     pcmk__unregister_formats();
 101 }
 102 
 103 PCMK__UNIT_TEST(NULL, NULL,
 104                 cmocka_unit_test(no_formats),
 105                 cmocka_unit_test(invalid_entries),
 106                 cmocka_unit_test(valid_entries),
 107                 cmocka_unit_test(duplicate_keys),
 108                 cmocka_unit_test(duplicate_values))

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