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

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

DEFINITIONS

This source file includes following definitions.
  1. store_strs

   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 
  14 #include <glib.h>
  15 
  16 static void
  17 store_strs(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  18 {
  19     GHashTable *tbl = NULL;
  20 
  21     tbl = pcmk__strkey_table(free, free);
  22     assert_non_null(tbl);
  23 
  24     assert_true(g_hash_table_insert(tbl, strdup("key-abc"), strdup("val-abc")));
  25     assert_int_equal(g_hash_table_size(tbl), 1);
  26     assert_string_equal(g_hash_table_lookup(tbl, "key-abc"), "val-abc");
  27 
  28     assert_false(g_hash_table_insert(tbl, strdup("key-abc"), strdup("val-def")));
  29     assert_int_equal(g_hash_table_size(tbl), 1);
  30     assert_string_equal(g_hash_table_lookup(tbl, "key-abc"), "val-def");
  31 
  32     assert_true(g_hash_table_insert(tbl, strdup("key-ABC"), strdup("val-abc")));
  33     assert_int_equal(g_hash_table_size(tbl), 2);
  34     assert_string_equal(g_hash_table_lookup(tbl, "key-ABC"), "val-abc");
  35 
  36     g_hash_table_destroy(tbl);
  37 }
  38 
  39 PCMK__UNIT_TEST(NULL, NULL,
  40                 cmocka_unit_test(store_strs))

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