pacemaker 2.1.4-dc6eb4362e
Scalable High-Availability cluster resource manager
pcmk__strikey_table_test.c
Go to the documentation of this file.
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 <stdarg.h>
13#include <stddef.h>
14#include <stdint.h>
15#include <setjmp.h>
16#include <cmocka.h>
17
18#include <glib.h>
19
20static void
21store_strs(void **state)
22{
23 GHashTable *tbl = NULL;
24
25 tbl = pcmk__strikey_table(free, free);
26 assert_non_null(tbl);
27
28 assert_true(g_hash_table_insert(tbl, strdup("key-abc"), strdup("val-abc")));
29 assert_int_equal(g_hash_table_size(tbl), 1);
30 assert_string_equal(g_hash_table_lookup(tbl, "key-abc"), "val-abc");
31
32 assert_false(g_hash_table_insert(tbl, strdup("key-abc"), strdup("val-def")));
33 assert_int_equal(g_hash_table_size(tbl), 1);
34 assert_string_equal(g_hash_table_lookup(tbl, "key-abc"), "val-def");
35
36 assert_false(g_hash_table_insert(tbl, strdup("key-ABC"), strdup("val-ABC")));
37 assert_int_equal(g_hash_table_size(tbl), 1);
38 assert_string_equal(g_hash_table_lookup(tbl, "key-ABC"), "val-ABC");
39
40 g_hash_table_destroy(tbl);
41}
42
43int main(int argc, char **argv) {
44 const struct CMUnitTest tests[] = {
45 cmocka_unit_test(store_strs),
46 };
47
48 cmocka_set_message_output(CM_OUTPUT_TAP);
49 return cmocka_run_group_tests(tests, NULL, NULL);
50}
int main(int argc, char **argv)
GHashTable * pcmk__strikey_table(GDestroyNotify key_destroy_func, GDestroyNotify value_destroy_func)
Definition: strings.c:649