root/lib/common/tests/strings/pcmk__str_table_dup_test.c

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

DEFINITIONS

This source file includes following definitions.
  1. null_input_table
  2. empty_input_table
  3. regular_input_table

   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 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 <glib.h>
  15 
  16 static void
  17 null_input_table(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  18 {
  19     assert_null(pcmk__str_table_dup(NULL));
  20 }
  21 
  22 static void
  23 empty_input_table(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  24 {
  25     GHashTable *tbl = pcmk__strkey_table(free, free);
  26     GHashTable *copy = NULL;
  27 
  28     copy = pcmk__str_table_dup(tbl);
  29     assert_int_equal(g_hash_table_size(copy), 0);
  30 
  31     g_hash_table_destroy(tbl);
  32     g_hash_table_destroy(copy);
  33 }
  34 
  35 static void
  36 regular_input_table(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  37 {
  38     GHashTable *tbl = pcmk__strkey_table(free, free);
  39     GHashTable *copy = NULL;
  40 
  41     g_hash_table_insert(tbl, strdup("abc"), strdup("123"));
  42     g_hash_table_insert(tbl, strdup("def"), strdup("456"));
  43     g_hash_table_insert(tbl, strdup("ghi"), strdup("789"));
  44 
  45     copy = pcmk__str_table_dup(tbl);
  46     assert_int_equal(g_hash_table_size(copy), 3);
  47 
  48     assert_string_equal(g_hash_table_lookup(tbl, "abc"), "123");
  49     assert_string_equal(g_hash_table_lookup(tbl, "def"), "456");
  50     assert_string_equal(g_hash_table_lookup(tbl, "ghi"), "789");
  51 
  52     g_hash_table_destroy(tbl);
  53     g_hash_table_destroy(copy);
  54 }
  55 
  56 PCMK__UNIT_TEST(NULL, NULL,
  57                 cmocka_unit_test(null_input_table),
  58                 cmocka_unit_test(empty_input_table),
  59                 cmocka_unit_test(regular_input_table))

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