This source file includes following definitions.
- null_args
- missing_key
- standard_usage
- conversion_errors
1
2
3
4
5
6
7
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_args(void **state)
18 {
19 GHashTable *tbl = pcmk__strkey_table(free, free);
20 guint result;
21
22 assert_int_equal(pcmk__guint_from_hash(NULL, "abc", 123, &result), EINVAL);
23 assert_int_equal(pcmk__guint_from_hash(tbl, NULL, 123, &result), EINVAL);
24
25 g_hash_table_destroy(tbl);
26 }
27
28 static void
29 missing_key(void **state)
30 {
31 GHashTable *tbl = pcmk__strkey_table(free, free);
32 guint result;
33
34 assert_int_equal(pcmk__guint_from_hash(tbl, "abc", 123, &result), pcmk_rc_ok);
35 assert_int_equal(result, 123);
36
37 g_hash_table_destroy(tbl);
38 }
39
40 static void
41 standard_usage(void **state)
42 {
43 GHashTable *tbl = pcmk__strkey_table(free, free);
44 guint result;
45
46 g_hash_table_insert(tbl, strdup("abc"), strdup("123"));
47
48 assert_int_equal(pcmk__guint_from_hash(tbl, "abc", 456, &result), pcmk_rc_ok);
49 assert_int_equal(result, 123);
50
51 g_hash_table_destroy(tbl);
52 }
53
54 static void
55 conversion_errors(void **state)
56 {
57 GHashTable *tbl = pcmk__strkey_table(free, free);
58 guint result;
59
60 g_hash_table_insert(tbl, strdup("negative"), strdup("-3"));
61 g_hash_table_insert(tbl, strdup("toobig"), strdup("20000000000000000"));
62
63 assert_int_equal(pcmk__guint_from_hash(tbl, "negative", 456, &result), ERANGE);
64 assert_int_equal(result, 456);
65
66 assert_int_equal(pcmk__guint_from_hash(tbl, "toobig", 456, &result), ERANGE);
67 assert_int_equal(result, 456);
68
69 g_hash_table_destroy(tbl);
70 }
71
72 PCMK__UNIT_TEST(NULL, NULL,
73 cmocka_unit_test(null_args),
74 cmocka_unit_test(missing_key),
75 cmocka_unit_test(standard_usage),
76 cmocka_unit_test(conversion_errors))