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

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

DEFINITIONS

This source file includes following definitions.
  1. empty_params
  2. key_not_in_table
  3. key_in_table
  4. main

   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 #include <crm/msg_xml.h>
  12 
  13 #include <stdarg.h>
  14 #include <stddef.h>
  15 #include <stdint.h>
  16 #include <setjmp.h>
  17 #include <cmocka.h>
  18 
  19 #include <glib.h>
  20 
  21 static void
  22 empty_params(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  23 {
  24     GHashTable *tbl = pcmk__strkey_table(free, free);
  25 
  26     assert_null(crm_meta_value(NULL, NULL));
  27     assert_null(crm_meta_value(tbl, NULL));
  28 
  29     g_hash_table_destroy(tbl);
  30 }
  31 
  32 static void
  33 key_not_in_table(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  34 {
  35     GHashTable *tbl = pcmk__strkey_table(free, free);
  36 
  37     assert_null(crm_meta_value(tbl, XML_RSC_ATTR_NOTIFY));
  38     assert_null(crm_meta_value(tbl, XML_RSC_ATTR_STICKINESS));
  39 
  40     g_hash_table_destroy(tbl);
  41 }
  42 
  43 static void
  44 key_in_table(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  45 {
  46     GHashTable *tbl = pcmk__strkey_table(free, free);
  47 
  48     g_hash_table_insert(tbl, crm_meta_name(XML_RSC_ATTR_NOTIFY), strdup("1"));
  49     g_hash_table_insert(tbl, crm_meta_name(XML_RSC_ATTR_STICKINESS), strdup("2"));
  50 
  51     assert_string_equal(crm_meta_value(tbl, XML_RSC_ATTR_NOTIFY), "1");
  52     assert_string_equal(crm_meta_value(tbl, XML_RSC_ATTR_STICKINESS), "2");
  53 
  54     g_hash_table_destroy(tbl);
  55 }
  56 
  57 int main(int argc, char **argv)
     /* [previous][next][first][last][top][bottom][index][help] */
  58 {
  59     const struct CMUnitTest tests[] = {
  60         cmocka_unit_test(empty_params),
  61         cmocka_unit_test(key_not_in_table),
  62         cmocka_unit_test(key_in_table),
  63     };
  64 
  65     cmocka_set_message_output(CM_OUTPUT_TAP);
  66     return cmocka_run_group_tests(tests, NULL, NULL);
  67 }

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