Michal Vasko | f20ad11 | 2023-02-10 15:12:12 +0100 | [diff] [blame] | 1 | /** |
aPiecek | 023f83a | 2021-05-11 07:37:03 +0200 | [diff] [blame] | 2 | * @file test_hash_table.c |
Radek Krejci | aaf6d40 | 2018-09-20 15:14:47 +0200 | [diff] [blame] | 3 | * @author: Radek Krejci <rkrejci@cesnet.cz> |
| 4 | * @brief unit tests for functions from hash_table.c |
| 5 | * |
| 6 | * Copyright (c) 2018 CESNET, z.s.p.o. |
| 7 | * |
| 8 | * This source code is licensed under BSD 3-Clause License (the "License"). |
| 9 | * You may not use this file except in compliance with the License. |
| 10 | * You may obtain a copy of the License at |
| 11 | * |
| 12 | * https://opensource.org/licenses/BSD-3-Clause |
| 13 | */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 14 | #define _UTEST_MAIN_ |
| 15 | #include "utests.h" |
Radek Krejci | 535ea9f | 2020-05-29 16:01:05 +0200 | [diff] [blame] | 16 | |
Radek Krejci | ca376bd | 2020-06-11 16:04:06 +0200 | [diff] [blame] | 17 | #include <stdlib.h> |
Radek Krejci | aaf6d40 | 2018-09-20 15:14:47 +0200 | [diff] [blame] | 18 | |
Radek Krejci | 70593c1 | 2020-06-13 20:48:09 +0200 | [diff] [blame] | 19 | #include "hash_table.h" |
Michal Vasko | 8f702ee | 2024-02-20 15:44:24 +0100 | [diff] [blame] | 20 | #include "ly_common.h" |
Radek Krejci | 2d7a47b | 2019-05-16 13:34:10 +0200 | [diff] [blame] | 21 | |
Radek Krejci | aaf6d40 | 2018-09-20 15:14:47 +0200 | [diff] [blame] | 22 | static void |
| 23 | test_invalid_arguments(void **state) |
| 24 | { |
Radek Krejci | 011e4aa | 2020-09-04 15:22:31 +0200 | [diff] [blame] | 25 | assert_int_equal(LY_EINVAL, lydict_insert(NULL, NULL, 0, NULL)); |
Michal Vasko | 7a26677 | 2024-01-23 11:02:38 +0100 | [diff] [blame] | 26 | CHECK_LOG_LASTMSG("Invalid argument ctx (lydict_insert())."); |
Radek Krejci | aaf6d40 | 2018-09-20 15:14:47 +0200 | [diff] [blame] | 27 | |
Radek Krejci | 011e4aa | 2020-09-04 15:22:31 +0200 | [diff] [blame] | 28 | assert_int_equal(LY_EINVAL, lydict_insert_zc(NULL, NULL, NULL)); |
Michal Vasko | 7a26677 | 2024-01-23 11:02:38 +0100 | [diff] [blame] | 29 | CHECK_LOG_LASTMSG("Invalid argument ctx (lydict_insert_zc())."); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 30 | assert_int_equal(LY_EINVAL, lydict_insert_zc(UTEST_LYCTX, NULL, NULL)); |
Michal Vasko | 7a26677 | 2024-01-23 11:02:38 +0100 | [diff] [blame] | 31 | CHECK_LOG_CTX("Invalid argument str_p (lydict_insert_zc()).", NULL, 0); |
Radek Krejci | aaf6d40 | 2018-09-20 15:14:47 +0200 | [diff] [blame] | 32 | } |
| 33 | |
| 34 | static void |
| 35 | test_dict_hit(void **state) |
| 36 | { |
Radek Krejci | 011e4aa | 2020-09-04 15:22:31 +0200 | [diff] [blame] | 37 | const char *str1, *str2, *str3; |
Radek Krejci | aaf6d40 | 2018-09-20 15:14:47 +0200 | [diff] [blame] | 38 | |
| 39 | /* insert 2 strings, one of them repeatedly */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 40 | assert_int_equal(LY_SUCCESS, lydict_insert(UTEST_LYCTX, "test1", 0, &str1)); |
Radek Krejci | aaf6d40 | 2018-09-20 15:14:47 +0200 | [diff] [blame] | 41 | assert_non_null(str1); |
| 42 | /* via zerocopy we have to get the same pointer as provided */ |
| 43 | assert_non_null(str2 = strdup("test2")); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 44 | assert_int_equal(LY_SUCCESS, lydict_insert_zc(UTEST_LYCTX, (char *)str2, &str3)); |
Radek Krejci | 011e4aa | 2020-09-04 15:22:31 +0200 | [diff] [blame] | 45 | assert_ptr_equal(str2, str3); |
Radek Krejci | aaf6d40 | 2018-09-20 15:14:47 +0200 | [diff] [blame] | 46 | /* here we get the same pointer as in case the string was inserted first time */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 47 | assert_int_equal(LY_SUCCESS, lydict_insert(UTEST_LYCTX, "test1", 0, &str2)); |
Radek Krejci | aaf6d40 | 2018-09-20 15:14:47 +0200 | [diff] [blame] | 48 | assert_non_null(str2); |
| 49 | assert_ptr_equal(str1, str2); |
| 50 | |
| 51 | /* remove strings, but the repeatedly inserted only once */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 52 | lydict_remove(UTEST_LYCTX, "test1"); |
| 53 | lydict_remove(UTEST_LYCTX, "test2"); |
Radek Krejci | aaf6d40 | 2018-09-20 15:14:47 +0200 | [diff] [blame] | 54 | |
| 55 | /* destroy dictionary - should raise warning about data presence */ |
Radek Krejci | 90ed21e | 2021-04-12 14:47:46 +0200 | [diff] [blame] | 56 | ly_ctx_destroy(UTEST_LYCTX); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 57 | UTEST_LYCTX = NULL; |
Michal Vasko | 7a26677 | 2024-01-23 11:02:38 +0100 | [diff] [blame] | 58 | CHECK_LOG_LASTMSG("String \"test1\" not freed from the dictionary, refcount 1."); |
Radek Krejci | aaf6d40 | 2018-09-20 15:14:47 +0200 | [diff] [blame] | 59 | |
| 60 | #ifndef NDEBUG |
| 61 | /* cleanup */ |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 62 | free((char *)str1); |
Radek Krejci | aaf6d40 | 2018-09-20 15:14:47 +0200 | [diff] [blame] | 63 | #endif |
| 64 | } |
| 65 | |
Radek Krejci | 1deb5be | 2020-08-26 16:43:36 +0200 | [diff] [blame] | 66 | static uint8_t |
| 67 | ht_equal_clb(void *val1, void *val2, uint8_t mod, void *cb_data) |
Radek Krejci | 0ae092d | 2018-09-20 16:43:19 +0200 | [diff] [blame] | 68 | { |
| 69 | int *v1, *v2; |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 70 | |
Radek Krejci | 0ae092d | 2018-09-20 16:43:19 +0200 | [diff] [blame] | 71 | (void)mod; |
| 72 | (void)cb_data; |
| 73 | |
| 74 | v1 = (int *)val1; |
| 75 | v2 = (int *)val2; |
| 76 | |
| 77 | return *v1 == *v2; |
| 78 | } |
| 79 | |
| 80 | static void |
Michal Vasko | 7a26677 | 2024-01-23 11:02:38 +0100 | [diff] [blame] | 81 | test_ht_basic(void **UNUSED(state)) |
Radek Krejci | 0ae092d | 2018-09-20 16:43:19 +0200 | [diff] [blame] | 82 | { |
Radek Krejci | 0ae092d | 2018-09-20 16:43:19 +0200 | [diff] [blame] | 83 | uint32_t i; |
Michal Vasko | 8efac24 | 2023-03-30 08:24:56 +0200 | [diff] [blame] | 84 | struct ly_ht *ht; |
Radek Krejci | 0ae092d | 2018-09-20 16:43:19 +0200 | [diff] [blame] | 85 | |
| 86 | assert_non_null(ht = lyht_new(8, sizeof(int), ht_equal_clb, NULL, 0)); |
| 87 | |
| 88 | i = 2; |
Michal Vasko | da85903 | 2020-07-14 12:20:14 +0200 | [diff] [blame] | 89 | assert_int_equal(LY_ENOTFOUND, lyht_find(ht, &i, i, NULL)); |
Radek Krejci | 0ae092d | 2018-09-20 16:43:19 +0200 | [diff] [blame] | 90 | assert_int_equal(LY_SUCCESS, lyht_insert(ht, &i, i, NULL)); |
Michal Vasko | da85903 | 2020-07-14 12:20:14 +0200 | [diff] [blame] | 91 | assert_int_equal(LY_SUCCESS, lyht_find(ht, &i, i, NULL)); |
Radek Krejci | 0ae092d | 2018-09-20 16:43:19 +0200 | [diff] [blame] | 92 | assert_int_equal(LY_SUCCESS, lyht_remove(ht, &i, i)); |
Michal Vasko | da85903 | 2020-07-14 12:20:14 +0200 | [diff] [blame] | 93 | assert_int_equal(LY_ENOTFOUND, lyht_find(ht, &i, i, NULL)); |
Michal Vasko | 4a4c7ed | 2020-07-17 09:30:12 +0200 | [diff] [blame] | 94 | assert_int_equal(LY_ENOTFOUND, lyht_remove(ht, &i, i)); |
Michal Vasko | 7a26677 | 2024-01-23 11:02:38 +0100 | [diff] [blame] | 95 | CHECK_LOG_LASTMSG("Invalid argument hash (lyht_remove_with_resize_cb())."); |
Radek Krejci | 0ae092d | 2018-09-20 16:43:19 +0200 | [diff] [blame] | 96 | |
Michal Vasko | 77b7f90a | 2023-01-31 15:42:41 +0100 | [diff] [blame] | 97 | lyht_free(ht, NULL); |
Radek Krejci | 0ae092d | 2018-09-20 16:43:19 +0200 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | static void |
Michal Vasko | 7a26677 | 2024-01-23 11:02:38 +0100 | [diff] [blame] | 101 | test_ht_resize(void **UNUSED(state)) |
Radek Krejci | 0ae092d | 2018-09-20 16:43:19 +0200 | [diff] [blame] | 102 | { |
Radek Krejci | 0ae092d | 2018-09-20 16:43:19 +0200 | [diff] [blame] | 103 | uint32_t i; |
Michal Vasko | 8efac24 | 2023-03-30 08:24:56 +0200 | [diff] [blame] | 104 | struct ly_ht *ht; |
Radek Krejci | 0ae092d | 2018-09-20 16:43:19 +0200 | [diff] [blame] | 105 | |
| 106 | assert_non_null(ht = lyht_new(8, sizeof(int), ht_equal_clb, NULL, 1)); |
| 107 | assert_int_equal(8, ht->size); |
| 108 | |
| 109 | /* insert records into indexes 2-7 */ |
| 110 | for (i = 2; i < 8; ++i) { |
| 111 | assert_int_equal(LY_SUCCESS, lyht_insert(ht, &i, i, NULL)); |
| 112 | } |
| 113 | /* check that table resized */ |
| 114 | assert_int_equal(16, ht->size); |
| 115 | |
| 116 | /* check expected content of the table */ |
| 117 | for (i = 0; i < 16; ++i) { |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 118 | if ((i >= 2) && (i < 8)) { |
Radek Krejci | 0ae092d | 2018-09-20 16:43:19 +0200 | [diff] [blame] | 119 | /* inserted data on indexes 2-7 */ |
Olivier Matz | 6a669c1 | 2023-09-28 12:07:12 +0200 | [diff] [blame] | 120 | assert_int_not_equal(UINT32_MAX, ht->hlists[i].first); |
Olivier Matz | 75c0019 | 2023-09-21 14:35:12 +0200 | [diff] [blame] | 121 | assert_int_equal(LY_SUCCESS, lyht_find(ht, &i, i, NULL)); |
Radek Krejci | 0ae092d | 2018-09-20 16:43:19 +0200 | [diff] [blame] | 122 | } else { |
| 123 | /* nothing otherwise */ |
Olivier Matz | 6a669c1 | 2023-09-28 12:07:12 +0200 | [diff] [blame] | 124 | assert_int_equal(UINT32_MAX, ht->hlists[i].first); |
Olivier Matz | 75c0019 | 2023-09-21 14:35:12 +0200 | [diff] [blame] | 125 | assert_int_equal(LY_ENOTFOUND, lyht_find(ht, &i, i, NULL)); |
Radek Krejci | 0ae092d | 2018-09-20 16:43:19 +0200 | [diff] [blame] | 126 | } |
| 127 | } |
| 128 | |
| 129 | /* removing not present data should fail */ |
| 130 | for (i = 0; i < 2; ++i) { |
Michal Vasko | 4a4c7ed | 2020-07-17 09:30:12 +0200 | [diff] [blame] | 131 | assert_int_equal(LY_ENOTFOUND, lyht_remove(ht, &i, i)); |
Michal Vasko | 7a26677 | 2024-01-23 11:02:38 +0100 | [diff] [blame] | 132 | CHECK_LOG_LASTMSG("Invalid argument hash (lyht_remove_with_resize_cb())."); |
Radek Krejci | 0ae092d | 2018-09-20 16:43:19 +0200 | [diff] [blame] | 133 | } |
| 134 | /* removing present data, resize should happened |
| 135 | * when we are below 25% of the table filled, so with 3 records left */ |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 136 | for ( ; i < 5; ++i) { |
Radek Krejci | 0ae092d | 2018-09-20 16:43:19 +0200 | [diff] [blame] | 137 | assert_int_equal(LY_SUCCESS, lyht_remove(ht, &i, i)); |
| 138 | } |
| 139 | assert_int_equal(8, ht->size); |
| 140 | |
| 141 | /* remove the rest */ |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 142 | for ( ; i < 8; ++i) { |
Radek Krejci | 0ae092d | 2018-09-20 16:43:19 +0200 | [diff] [blame] | 143 | assert_int_equal(LY_SUCCESS, lyht_remove(ht, &i, i)); |
| 144 | } |
| 145 | |
| 146 | for (i = 0; i < 8; ++i) { |
Michal Vasko | da85903 | 2020-07-14 12:20:14 +0200 | [diff] [blame] | 147 | assert_int_equal(LY_ENOTFOUND, lyht_find(ht, &i, i, NULL)); |
Radek Krejci | 0ae092d | 2018-09-20 16:43:19 +0200 | [diff] [blame] | 148 | } |
| 149 | |
| 150 | /* cleanup */ |
Michal Vasko | 77b7f90a | 2023-01-31 15:42:41 +0100 | [diff] [blame] | 151 | lyht_free(ht, NULL); |
Radek Krejci | 0ae092d | 2018-09-20 16:43:19 +0200 | [diff] [blame] | 152 | } |
| 153 | |
Radek Krejci | 0ae092d | 2018-09-20 16:43:19 +0200 | [diff] [blame] | 154 | static void |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 155 | test_ht_collisions(void **UNUSED(state)) |
Radek Krejci | 0ae092d | 2018-09-20 16:43:19 +0200 | [diff] [blame] | 156 | { |
Radek Krejci | 0ae092d | 2018-09-20 16:43:19 +0200 | [diff] [blame] | 157 | #define GET_REC_INT(rec) (*((uint32_t *)&(rec)->val)) |
| 158 | |
| 159 | uint32_t i; |
Michal Vasko | 8efac24 | 2023-03-30 08:24:56 +0200 | [diff] [blame] | 160 | struct ly_ht_rec *rec; |
| 161 | struct ly_ht *ht; |
Olivier Matz | 75c0019 | 2023-09-21 14:35:12 +0200 | [diff] [blame] | 162 | uint32_t rec_idx; |
| 163 | int count; |
Radek Krejci | 0ae092d | 2018-09-20 16:43:19 +0200 | [diff] [blame] | 164 | |
| 165 | assert_non_null(ht = lyht_new(8, sizeof(int), ht_equal_clb, NULL, 1)); |
| 166 | |
| 167 | for (i = 2; i < 6; ++i) { |
| 168 | assert_int_equal(lyht_insert(ht, &i, 2, NULL), 0); |
| 169 | } |
| 170 | |
| 171 | /* check all records */ |
Olivier Matz | 75c0019 | 2023-09-21 14:35:12 +0200 | [diff] [blame] | 172 | for (i = 0; i < 8; ++i) { |
Olivier Matz | c0feb68 | 2023-09-21 08:53:59 +0200 | [diff] [blame] | 173 | if (i == 2) { |
Olivier Matz | 6a669c1 | 2023-09-28 12:07:12 +0200 | [diff] [blame] | 174 | assert_int_not_equal(UINT32_MAX, ht->hlists[i].first); |
Olivier Matz | c0feb68 | 2023-09-21 08:53:59 +0200 | [diff] [blame] | 175 | } else { |
Olivier Matz | 6a669c1 | 2023-09-28 12:07:12 +0200 | [diff] [blame] | 176 | assert_int_equal(UINT32_MAX, ht->hlists[i].first); |
Olivier Matz | c0feb68 | 2023-09-21 08:53:59 +0200 | [diff] [blame] | 177 | } |
Radek Krejci | 0ae092d | 2018-09-20 16:43:19 +0200 | [diff] [blame] | 178 | } |
Olivier Matz | 75c0019 | 2023-09-21 14:35:12 +0200 | [diff] [blame] | 179 | for (i = 0; i < 8; ++i) { |
Olivier Matz | c0feb68 | 2023-09-21 08:53:59 +0200 | [diff] [blame] | 180 | if ((i >= 2) && (i < 6)) { |
Olivier Matz | 75c0019 | 2023-09-21 14:35:12 +0200 | [diff] [blame] | 181 | assert_int_equal(LY_SUCCESS, lyht_find(ht, &i, 2, NULL)); |
Olivier Matz | c0feb68 | 2023-09-21 08:53:59 +0200 | [diff] [blame] | 182 | } else { |
Olivier Matz | 75c0019 | 2023-09-21 14:35:12 +0200 | [diff] [blame] | 183 | assert_int_equal(LY_ENOTFOUND, lyht_find(ht, &i, 2, NULL)); |
Olivier Matz | c0feb68 | 2023-09-21 08:53:59 +0200 | [diff] [blame] | 184 | } |
Radek Krejci | 0ae092d | 2018-09-20 16:43:19 +0200 | [diff] [blame] | 185 | } |
Olivier Matz | 6a669c1 | 2023-09-28 12:07:12 +0200 | [diff] [blame] | 186 | rec_idx = ht->hlists[2].first; |
Olivier Matz | 75c0019 | 2023-09-21 14:35:12 +0200 | [diff] [blame] | 187 | count = 0; |
| 188 | while (rec_idx != UINT32_MAX) { |
| 189 | rec = lyht_get_rec(ht->recs, ht->rec_size, rec_idx); |
| 190 | rec_idx = rec->next; |
| 191 | assert_int_equal(rec->hash, 2); |
| 192 | count++; |
Radek Krejci | 0ae092d | 2018-09-20 16:43:19 +0200 | [diff] [blame] | 193 | } |
Olivier Matz | 75c0019 | 2023-09-21 14:35:12 +0200 | [diff] [blame] | 194 | assert_int_equal(count, 4); |
Radek Krejci | 0ae092d | 2018-09-20 16:43:19 +0200 | [diff] [blame] | 195 | |
| 196 | i = 4; |
| 197 | assert_int_equal(lyht_remove(ht, &i, 2), 0); |
| 198 | |
| 199 | rec = lyht_get_rec(ht->recs, ht->rec_size, i); |
Radek Krejci | 0ae092d | 2018-09-20 16:43:19 +0200 | [diff] [blame] | 200 | |
| 201 | i = 2; |
| 202 | assert_int_equal(lyht_remove(ht, &i, 2), 0); |
| 203 | |
| 204 | /* check all records */ |
Olivier Matz | 75c0019 | 2023-09-21 14:35:12 +0200 | [diff] [blame] | 205 | for (i = 0; i < 8; ++i) { |
Olivier Matz | c0feb68 | 2023-09-21 08:53:59 +0200 | [diff] [blame] | 206 | if (i == 2) { |
Olivier Matz | 6a669c1 | 2023-09-28 12:07:12 +0200 | [diff] [blame] | 207 | assert_int_not_equal(UINT32_MAX, ht->hlists[i].first); |
Olivier Matz | c0feb68 | 2023-09-21 08:53:59 +0200 | [diff] [blame] | 208 | } else { |
Olivier Matz | 6a669c1 | 2023-09-28 12:07:12 +0200 | [diff] [blame] | 209 | assert_int_equal(UINT32_MAX, ht->hlists[i].first); |
Olivier Matz | c0feb68 | 2023-09-21 08:53:59 +0200 | [diff] [blame] | 210 | } |
Radek Krejci | 0ae092d | 2018-09-20 16:43:19 +0200 | [diff] [blame] | 211 | } |
Olivier Matz | 75c0019 | 2023-09-21 14:35:12 +0200 | [diff] [blame] | 212 | for (i = 0; i < 8; ++i) { |
Olivier Matz | c0feb68 | 2023-09-21 08:53:59 +0200 | [diff] [blame] | 213 | if ((i == 3) || (i == 5)) { |
Olivier Matz | 75c0019 | 2023-09-21 14:35:12 +0200 | [diff] [blame] | 214 | assert_int_equal(LY_SUCCESS, lyht_find(ht, &i, 2, NULL)); |
Olivier Matz | c0feb68 | 2023-09-21 08:53:59 +0200 | [diff] [blame] | 215 | } else { |
Olivier Matz | 75c0019 | 2023-09-21 14:35:12 +0200 | [diff] [blame] | 216 | assert_int_equal(LY_ENOTFOUND, lyht_find(ht, &i, 2, NULL)); |
Olivier Matz | c0feb68 | 2023-09-21 08:53:59 +0200 | [diff] [blame] | 217 | } |
Radek Krejci | 0ae092d | 2018-09-20 16:43:19 +0200 | [diff] [blame] | 218 | } |
Olivier Matz | 6a669c1 | 2023-09-28 12:07:12 +0200 | [diff] [blame] | 219 | rec_idx = ht->hlists[2].first; |
Olivier Matz | 75c0019 | 2023-09-21 14:35:12 +0200 | [diff] [blame] | 220 | count = 0; |
| 221 | while (rec_idx != UINT32_MAX) { |
| 222 | rec = lyht_get_rec(ht->recs, ht->rec_size, rec_idx); |
| 223 | rec_idx = rec->next; |
| 224 | assert_int_equal(rec->hash, 2); |
| 225 | count++; |
Radek Krejci | 0ae092d | 2018-09-20 16:43:19 +0200 | [diff] [blame] | 226 | } |
Olivier Matz | 75c0019 | 2023-09-21 14:35:12 +0200 | [diff] [blame] | 227 | assert_int_equal(count, 2); |
Radek Krejci | 0ae092d | 2018-09-20 16:43:19 +0200 | [diff] [blame] | 228 | |
Olivier Matz | 75c0019 | 2023-09-21 14:35:12 +0200 | [diff] [blame] | 229 | for (i = 0; i < 8; ++i) { |
Olivier Matz | c0feb68 | 2023-09-21 08:53:59 +0200 | [diff] [blame] | 230 | if ((i == 3) || (i == 5)) { |
Olivier Matz | 75c0019 | 2023-09-21 14:35:12 +0200 | [diff] [blame] | 231 | assert_int_equal(lyht_find(ht, &i, 2, NULL), LY_SUCCESS); |
Olivier Matz | c0feb68 | 2023-09-21 08:53:59 +0200 | [diff] [blame] | 232 | } else { |
Olivier Matz | 75c0019 | 2023-09-21 14:35:12 +0200 | [diff] [blame] | 233 | assert_int_equal(lyht_find(ht, &i, 2, NULL), LY_ENOTFOUND); |
Olivier Matz | c0feb68 | 2023-09-21 08:53:59 +0200 | [diff] [blame] | 234 | } |
Radek Krejci | 0ae092d | 2018-09-20 16:43:19 +0200 | [diff] [blame] | 235 | } |
| 236 | |
| 237 | i = 3; |
| 238 | assert_int_equal(lyht_remove(ht, &i, 2), 0); |
| 239 | i = 5; |
| 240 | assert_int_equal(lyht_remove(ht, &i, 2), 0); |
| 241 | |
| 242 | /* check all records */ |
Olivier Matz | 75c0019 | 2023-09-21 14:35:12 +0200 | [diff] [blame] | 243 | for (i = 0; i < 8; ++i) { |
Olivier Matz | 6a669c1 | 2023-09-28 12:07:12 +0200 | [diff] [blame] | 244 | assert_int_equal(UINT32_MAX, ht->hlists[i].first); |
Radek Krejci | 0ae092d | 2018-09-20 16:43:19 +0200 | [diff] [blame] | 245 | } |
| 246 | |
Michal Vasko | 77b7f90a | 2023-01-31 15:42:41 +0100 | [diff] [blame] | 247 | lyht_free(ht, NULL); |
Radek Krejci | 0ae092d | 2018-09-20 16:43:19 +0200 | [diff] [blame] | 248 | } |
| 249 | |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 250 | int |
| 251 | main(void) |
Radek Krejci | aaf6d40 | 2018-09-20 15:14:47 +0200 | [diff] [blame] | 252 | { |
| 253 | const struct CMUnitTest tests[] = { |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 254 | UTEST(test_invalid_arguments), |
| 255 | UTEST(test_dict_hit), |
| 256 | UTEST(test_ht_basic), |
| 257 | UTEST(test_ht_resize), |
| 258 | UTEST(test_ht_collisions), |
Radek Krejci | aaf6d40 | 2018-09-20 15:14:47 +0200 | [diff] [blame] | 259 | }; |
| 260 | |
| 261 | return cmocka_run_group_tests(tests, NULL, NULL); |
| 262 | } |