| 1 |
/* |
| 2 |
* Copyright (C) 2015 Red Hat, Inc. |
| 3 |
* SPDX-License-Identifier: LGPL-2.1-or-later |
| 4 |
*/ |
| 5 |
|
| 6 |
#include "config.h" |
| 7 |
|
| 8 |
#include "cockpithash.h" |
| 9 |
|
| 10 |
#include "testlib/cockpittest.h" |
| 11 |
|
| 12 |
static void |
| 13 |
test_case_hash (void) |
| 14 |
{ |
| 15 |
GHashTable *table; |
| 16 |
|
| 17 |
table = g_hash_table_new_full (cockpit_str_case_hash, cockpit_str_case_equal, g_free, g_free); |
| 18 |
|
| 19 |
/* Case insensitive keys */ |
| 20 |
g_hash_table_insert (table, g_strdup ("Blah"), g_strdup ("value")); |
| 21 |
g_hash_table_insert (table, g_strdup ("blah"), g_strdup ("another")); |
| 22 |
g_hash_table_insert (table, g_strdup ("Different"), g_strdup ("One")); |
| 23 |
|
| 24 |
g_assert_cmpstr (g_hash_table_lookup (table, "BLAH"), ==, "another"); |
| 25 |
g_assert_cmpstr (g_hash_table_lookup (table, "differeNT"), ==, "One"); |
| 26 |
|
| 27 |
g_hash_table_destroy (table); |
| 28 |
} |
| 29 |
|
| 30 |
int |
| 31 |
main (int argc, |
| 32 |
char *argv[]) |
| 33 |
{ |
| 34 |
cockpit_test_init (&argc, &argv); |
| 35 |
|
| 36 |
g_test_add_func ("/hash/case-hash", test_case_hash); |
| 37 |
|
| 38 |
return g_test_run (); |
| 39 |
} |