]>
Commit | Line | Data |
---|---|---|
53e1b683 | 1 | /* SPDX-License-Identifier: LGPL-2.1+ */ |
9341a4a1 DB |
2 | /*** |
3 | This file is part of systemd | |
4 | ||
5 | Copyright 2013 Daniel Buch | |
6 | ||
7 | systemd is free software; you can redistribute it and/or modify it | |
8 | under the terms of the GNU Lesser General Public License as published by | |
9 | the Free Software Foundation; either version 2.1 of the License, or | |
10 | (at your option) any later version. | |
11 | ||
12 | systemd is distributed in the hope that it will be useful, but | |
13 | WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 | Lesser General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU Lesser General Public License | |
18 | along with systemd; If not, see <http://www.gnu.org/licenses/>. | |
19 | ***/ | |
20 | ||
9341a4a1 | 21 | #include "hashmap.h" |
cf0fbc49 | 22 | #include "util.h" |
9341a4a1 | 23 | |
32a4456c MS |
24 | void test_hashmap_funcs(void); |
25 | void test_ordered_hashmap_funcs(void); | |
9341a4a1 | 26 | |
32a4456c | 27 | static void test_ordered_hashmap_next(void) { |
8f8a5213 MS |
28 | _cleanup_ordered_hashmap_free_ OrderedHashmap *m = NULL; |
29 | int i; | |
30 | ||
31 | assert_se(m = ordered_hashmap_new(NULL)); | |
32 | for (i = -2; i <= 2; i++) | |
33 | assert_se(ordered_hashmap_put(m, INT_TO_PTR(i), INT_TO_PTR(i+10)) == 1); | |
34 | for (i = -2; i <= 1; i++) | |
35 | assert_se(ordered_hashmap_next(m, INT_TO_PTR(i)) == INT_TO_PTR(i+11)); | |
36 | assert_se(!ordered_hashmap_next(m, INT_TO_PTR(2))); | |
37 | assert_se(!ordered_hashmap_next(NULL, INT_TO_PTR(1))); | |
38 | assert_se(!ordered_hashmap_next(m, INT_TO_PTR(3))); | |
d06b3a9d RC |
39 | } |
40 | ||
9341a4a1 | 41 | static void test_uint64_compare_func(void) { |
8097ab4f ZJS |
42 | const uint64_t a = 0x100, b = 0x101; |
43 | ||
44 | assert_se(uint64_compare_func(&a, &a) == 0); | |
45 | assert_se(uint64_compare_func(&a, &b) == -1); | |
46 | assert_se(uint64_compare_func(&b, &a) == 1); | |
9341a4a1 DB |
47 | } |
48 | ||
49 | static void test_trivial_compare_func(void) { | |
50 | assert_se(trivial_compare_func(INT_TO_PTR('a'), INT_TO_PTR('a')) == 0); | |
51 | assert_se(trivial_compare_func(INT_TO_PTR('a'), INT_TO_PTR('b')) == -1); | |
52 | assert_se(trivial_compare_func(INT_TO_PTR('b'), INT_TO_PTR('a')) == 1); | |
53 | } | |
54 | ||
55 | static void test_string_compare_func(void) { | |
4b3eff61 | 56 | assert_se(string_compare_func("fred", "wilma") != 0); |
9341a4a1 DB |
57 | assert_se(string_compare_func("fred", "fred") == 0); |
58 | } | |
59 | ||
45fa9e29 | 60 | int main(int argc, const char *argv[]) { |
32a4456c MS |
61 | test_hashmap_funcs(); |
62 | test_ordered_hashmap_funcs(); | |
63 | ||
64 | test_ordered_hashmap_next(); | |
9341a4a1 DB |
65 | test_uint64_compare_func(); |
66 | test_trivial_compare_func(); | |
67 | test_string_compare_func(); | |
68 | } |