1 /*
2 * Copyright (c) 2022 Meta
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7 #include <zephyr/ztest.h>
8 #include <zephyr/sys/hash_map.h>
9
10 #include "_main.h"
11
ZTEST(hash_map,test_get_true)12 ZTEST(hash_map, test_get_true)
13 {
14 int ret;
15 uint64_t value = 0x42;
16
17 zassert_true(sys_hashmap_is_empty(&map));
18 zassert_equal(1, sys_hashmap_insert(&map, 0, 0, NULL));
19 zassert_true(sys_hashmap_get(&map, 0, NULL));
20 zassert_true(sys_hashmap_get(&map, 0, &value));
21 zassert_equal(0, value);
22
23 for (size_t i = 1; i < MANY; ++i) {
24 ret = sys_hashmap_insert(&map, i, i, NULL);
25 zassert_equal(1, ret, "failed to insert (%zu, %zu): %d", i, i, ret);
26 }
27
28 for (size_t i = 0; i < MANY; ++i) {
29 zassert_true(sys_hashmap_get(&map, i, NULL));
30 }
31 }
32
ZTEST(hash_map,test_get_false)33 ZTEST(hash_map, test_get_false)
34 {
35 int ret;
36 uint64_t value = 0x42;
37
38 zassert_true(sys_hashmap_is_empty(&map));
39
40 zassert_false(sys_hashmap_get(&map, 73, &value));
41 zassert_equal(value, 0x42);
42
43 for (size_t i = 0; i < MANY; ++i) {
44 ret = sys_hashmap_insert(&map, i, i, NULL);
45 zassert_equal(1, ret, "failed to insert (%zu, %zu): %d", i, i, ret);
46 }
47
48 zassert_false(sys_hashmap_get(&map, 0x4242424242424242ULL, NULL));
49 }
50