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)); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 26 | CHECK_LOG("Invalid argument ctx (lydict_insert()).", NULL); |
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)); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 29 | CHECK_LOG("Invalid argument ctx (lydict_insert_zc()).", NULL); |
| 30 | assert_int_equal(LY_EINVAL, lydict_insert_zc(UTEST_LYCTX, NULL, NULL)); |
Michal Vasko | be27c91 | 2021-02-24 17:07:37 +0100 | [diff] [blame] | 31 | CHECK_LOG_CTX("Invalid argument str_p (lydict_insert_zc()).", NULL); |
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; |
| 58 | CHECK_LOG("String \"test1\" not freed from the dictionary, refcount 1", NULL); |
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 |
| 81 | test_ht_basic(void **state) |
| 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)); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 95 | CHECK_LOG("Invalid argument hash (lyht_remove_with_resize_cb()).", NULL); |
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 |
| 101 | test_ht_resize(void **state) |
| 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) { |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 131 | UTEST_LOG_CLEAN; |
Michal Vasko | 4a4c7ed | 2020-07-17 09:30:12 +0200 | [diff] [blame] | 132 | assert_int_equal(LY_ENOTFOUND, lyht_remove(ht, &i, i)); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 133 | CHECK_LOG("Invalid argument hash (lyht_remove_with_resize_cb()).", NULL); |
Radek Krejci | 0ae092d | 2018-09-20 16:43:19 +0200 | [diff] [blame] | 134 | } |
| 135 | /* removing present data, resize should happened |
| 136 | * 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] | 137 | for ( ; i < 5; ++i) { |
Radek Krejci | 0ae092d | 2018-09-20 16:43:19 +0200 | [diff] [blame] | 138 | assert_int_equal(LY_SUCCESS, lyht_remove(ht, &i, i)); |
| 139 | } |
| 140 | assert_int_equal(8, ht->size); |
| 141 | |
| 142 | /* remove the rest */ |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 143 | for ( ; i < 8; ++i) { |
Radek Krejci | 0ae092d | 2018-09-20 16:43:19 +0200 | [diff] [blame] | 144 | assert_int_equal(LY_SUCCESS, lyht_remove(ht, &i, i)); |
| 145 | } |
| 146 | |
| 147 | for (i = 0; i < 8; ++i) { |
Michal Vasko | da85903 | 2020-07-14 12:20:14 +0200 | [diff] [blame] | 148 | assert_int_equal(LY_ENOTFOUND, lyht_find(ht, &i, i, NULL)); |
Radek Krejci | 0ae092d | 2018-09-20 16:43:19 +0200 | [diff] [blame] | 149 | } |
| 150 | |
| 151 | /* cleanup */ |
Michal Vasko | 77b7f90a | 2023-01-31 15:42:41 +0100 | [diff] [blame] | 152 | lyht_free(ht, NULL); |
Radek Krejci | 0ae092d | 2018-09-20 16:43:19 +0200 | [diff] [blame] | 153 | } |
| 154 | |
Radek Krejci | 0ae092d | 2018-09-20 16:43:19 +0200 | [diff] [blame] | 155 | static void |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 156 | test_ht_collisions(void **UNUSED(state)) |
Radek Krejci | 0ae092d | 2018-09-20 16:43:19 +0200 | [diff] [blame] | 157 | { |
Radek Krejci | 0ae092d | 2018-09-20 16:43:19 +0200 | [diff] [blame] | 158 | #define GET_REC_INT(rec) (*((uint32_t *)&(rec)->val)) |
| 159 | |
| 160 | uint32_t i; |
Michal Vasko | 8efac24 | 2023-03-30 08:24:56 +0200 | [diff] [blame] | 161 | struct ly_ht_rec *rec; |
| 162 | struct ly_ht *ht; |
Olivier Matz | 75c0019 | 2023-09-21 14:35:12 +0200 | [diff] [blame] | 163 | uint32_t rec_idx; |
| 164 | int count; |
Radek Krejci | 0ae092d | 2018-09-20 16:43:19 +0200 | [diff] [blame] | 165 | |
| 166 | assert_non_null(ht = lyht_new(8, sizeof(int), ht_equal_clb, NULL, 1)); |
| 167 | |
| 168 | for (i = 2; i < 6; ++i) { |
| 169 | assert_int_equal(lyht_insert(ht, &i, 2, NULL), 0); |
| 170 | } |
| 171 | |
| 172 | /* check all records */ |
Olivier Matz | 75c0019 | 2023-09-21 14:35:12 +0200 | [diff] [blame] | 173 | for (i = 0; i < 8; ++i) { |
Olivier Matz | c0feb68 | 2023-09-21 08:53:59 +0200 | [diff] [blame] | 174 | if (i == 2) { |
Olivier Matz | 6a669c1 | 2023-09-28 12:07:12 +0200 | [diff] [blame] | 175 | assert_int_not_equal(UINT32_MAX, ht->hlists[i].first); |
Olivier Matz | c0feb68 | 2023-09-21 08:53:59 +0200 | [diff] [blame] | 176 | } else { |
Olivier Matz | 6a669c1 | 2023-09-28 12:07:12 +0200 | [diff] [blame] | 177 | assert_int_equal(UINT32_MAX, ht->hlists[i].first); |
Olivier Matz | c0feb68 | 2023-09-21 08:53:59 +0200 | [diff] [blame] | 178 | } |
Radek Krejci | 0ae092d | 2018-09-20 16:43:19 +0200 | [diff] [blame] | 179 | } |
Olivier Matz | 75c0019 | 2023-09-21 14:35:12 +0200 | [diff] [blame] | 180 | for (i = 0; i < 8; ++i) { |
Olivier Matz | c0feb68 | 2023-09-21 08:53:59 +0200 | [diff] [blame] | 181 | if ((i >= 2) && (i < 6)) { |
Olivier Matz | 75c0019 | 2023-09-21 14:35:12 +0200 | [diff] [blame] | 182 | assert_int_equal(LY_SUCCESS, lyht_find(ht, &i, 2, NULL)); |
Olivier Matz | c0feb68 | 2023-09-21 08:53:59 +0200 | [diff] [blame] | 183 | } else { |
Olivier Matz | 75c0019 | 2023-09-21 14:35:12 +0200 | [diff] [blame] | 184 | assert_int_equal(LY_ENOTFOUND, lyht_find(ht, &i, 2, NULL)); |
Olivier Matz | c0feb68 | 2023-09-21 08:53:59 +0200 | [diff] [blame] | 185 | } |
Radek Krejci | 0ae092d | 2018-09-20 16:43:19 +0200 | [diff] [blame] | 186 | } |
Olivier Matz | 6a669c1 | 2023-09-28 12:07:12 +0200 | [diff] [blame] | 187 | rec_idx = ht->hlists[2].first; |
Olivier Matz | 75c0019 | 2023-09-21 14:35:12 +0200 | [diff] [blame] | 188 | count = 0; |
| 189 | while (rec_idx != UINT32_MAX) { |
| 190 | rec = lyht_get_rec(ht->recs, ht->rec_size, rec_idx); |
| 191 | rec_idx = rec->next; |
| 192 | assert_int_equal(rec->hash, 2); |
| 193 | count++; |
Radek Krejci | 0ae092d | 2018-09-20 16:43:19 +0200 | [diff] [blame] | 194 | } |
Olivier Matz | 75c0019 | 2023-09-21 14:35:12 +0200 | [diff] [blame] | 195 | assert_int_equal(count, 4); |
Radek Krejci | 0ae092d | 2018-09-20 16:43:19 +0200 | [diff] [blame] | 196 | |
| 197 | i = 4; |
| 198 | assert_int_equal(lyht_remove(ht, &i, 2), 0); |
| 199 | |
| 200 | rec = lyht_get_rec(ht->recs, ht->rec_size, i); |
Radek Krejci | 0ae092d | 2018-09-20 16:43:19 +0200 | [diff] [blame] | 201 | |
| 202 | i = 2; |
| 203 | assert_int_equal(lyht_remove(ht, &i, 2), 0); |
| 204 | |
| 205 | /* check all records */ |
Olivier Matz | 75c0019 | 2023-09-21 14:35:12 +0200 | [diff] [blame] | 206 | for (i = 0; i < 8; ++i) { |
Olivier Matz | c0feb68 | 2023-09-21 08:53:59 +0200 | [diff] [blame] | 207 | if (i == 2) { |
Olivier Matz | 6a669c1 | 2023-09-28 12:07:12 +0200 | [diff] [blame] | 208 | assert_int_not_equal(UINT32_MAX, ht->hlists[i].first); |
Olivier Matz | c0feb68 | 2023-09-21 08:53:59 +0200 | [diff] [blame] | 209 | } else { |
Olivier Matz | 6a669c1 | 2023-09-28 12:07:12 +0200 | [diff] [blame] | 210 | assert_int_equal(UINT32_MAX, ht->hlists[i].first); |
Olivier Matz | c0feb68 | 2023-09-21 08:53:59 +0200 | [diff] [blame] | 211 | } |
Radek Krejci | 0ae092d | 2018-09-20 16:43:19 +0200 | [diff] [blame] | 212 | } |
Olivier Matz | 75c0019 | 2023-09-21 14:35:12 +0200 | [diff] [blame] | 213 | for (i = 0; i < 8; ++i) { |
Olivier Matz | c0feb68 | 2023-09-21 08:53:59 +0200 | [diff] [blame] | 214 | if ((i == 3) || (i == 5)) { |
Olivier Matz | 75c0019 | 2023-09-21 14:35:12 +0200 | [diff] [blame] | 215 | assert_int_equal(LY_SUCCESS, lyht_find(ht, &i, 2, NULL)); |
Olivier Matz | c0feb68 | 2023-09-21 08:53:59 +0200 | [diff] [blame] | 216 | } else { |
Olivier Matz | 75c0019 | 2023-09-21 14:35:12 +0200 | [diff] [blame] | 217 | assert_int_equal(LY_ENOTFOUND, lyht_find(ht, &i, 2, NULL)); |
Olivier Matz | c0feb68 | 2023-09-21 08:53:59 +0200 | [diff] [blame] | 218 | } |
Radek Krejci | 0ae092d | 2018-09-20 16:43:19 +0200 | [diff] [blame] | 219 | } |
Olivier Matz | 6a669c1 | 2023-09-28 12:07:12 +0200 | [diff] [blame] | 220 | rec_idx = ht->hlists[2].first; |
Olivier Matz | 75c0019 | 2023-09-21 14:35:12 +0200 | [diff] [blame] | 221 | count = 0; |
| 222 | while (rec_idx != UINT32_MAX) { |
| 223 | rec = lyht_get_rec(ht->recs, ht->rec_size, rec_idx); |
| 224 | rec_idx = rec->next; |
| 225 | assert_int_equal(rec->hash, 2); |
| 226 | count++; |
Radek Krejci | 0ae092d | 2018-09-20 16:43:19 +0200 | [diff] [blame] | 227 | } |
Olivier Matz | 75c0019 | 2023-09-21 14:35:12 +0200 | [diff] [blame] | 228 | assert_int_equal(count, 2); |
Radek Krejci | 0ae092d | 2018-09-20 16:43:19 +0200 | [diff] [blame] | 229 | |
Olivier Matz | 75c0019 | 2023-09-21 14:35:12 +0200 | [diff] [blame] | 230 | for (i = 0; i < 8; ++i) { |
Olivier Matz | c0feb68 | 2023-09-21 08:53:59 +0200 | [diff] [blame] | 231 | if ((i == 3) || (i == 5)) { |
Olivier Matz | 75c0019 | 2023-09-21 14:35:12 +0200 | [diff] [blame] | 232 | assert_int_equal(lyht_find(ht, &i, 2, NULL), LY_SUCCESS); |
Olivier Matz | c0feb68 | 2023-09-21 08:53:59 +0200 | [diff] [blame] | 233 | } else { |
Olivier Matz | 75c0019 | 2023-09-21 14:35:12 +0200 | [diff] [blame] | 234 | assert_int_equal(lyht_find(ht, &i, 2, NULL), LY_ENOTFOUND); |
Olivier Matz | c0feb68 | 2023-09-21 08:53:59 +0200 | [diff] [blame] | 235 | } |
Radek Krejci | 0ae092d | 2018-09-20 16:43:19 +0200 | [diff] [blame] | 236 | } |
| 237 | |
| 238 | i = 3; |
| 239 | assert_int_equal(lyht_remove(ht, &i, 2), 0); |
| 240 | i = 5; |
| 241 | assert_int_equal(lyht_remove(ht, &i, 2), 0); |
| 242 | |
| 243 | /* check all records */ |
Olivier Matz | 75c0019 | 2023-09-21 14:35:12 +0200 | [diff] [blame] | 244 | for (i = 0; i < 8; ++i) { |
Olivier Matz | 6a669c1 | 2023-09-28 12:07:12 +0200 | [diff] [blame] | 245 | assert_int_equal(UINT32_MAX, ht->hlists[i].first); |
Radek Krejci | 0ae092d | 2018-09-20 16:43:19 +0200 | [diff] [blame] | 246 | } |
| 247 | |
Michal Vasko | 77b7f90a | 2023-01-31 15:42:41 +0100 | [diff] [blame] | 248 | lyht_free(ht, NULL); |
Radek Krejci | 0ae092d | 2018-09-20 16:43:19 +0200 | [diff] [blame] | 249 | } |
| 250 | |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 251 | int |
| 252 | main(void) |
Radek Krejci | aaf6d40 | 2018-09-20 15:14:47 +0200 | [diff] [blame] | 253 | { |
| 254 | const struct CMUnitTest tests[] = { |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 255 | UTEST(test_invalid_arguments), |
| 256 | UTEST(test_dict_hit), |
| 257 | UTEST(test_ht_basic), |
| 258 | UTEST(test_ht_resize), |
| 259 | UTEST(test_ht_collisions), |
Radek Krejci | aaf6d40 | 2018-09-20 15:14:47 +0200 | [diff] [blame] | 260 | }; |
| 261 | |
| 262 | return cmocka_run_group_tests(tests, NULL, NULL); |
| 263 | } |