Radek Krejci | e84f12f | 2018-09-18 14:11:50 +0200 | [diff] [blame] | 1 | /* |
| 2 | * @file set.c |
| 3 | * @author: Radek Krejci <rkrejci@cesnet.cz> |
| 4 | * @brief unit tests for functions from set.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 Krejci | f8dc59a | 2020-11-25 13:47:44 +0100 | [diff] [blame] | 14 | #define _POSIX_C_SOURCE 200809L /* strdup */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 15 | #define _UTEST_MAIN_ |
| 16 | #include "utests.h" |
Radek Krejci | e84f12f | 2018-09-18 14:11:50 +0200 | [diff] [blame] | 17 | |
Radek Krejci | 535ea9f | 2020-05-29 16:01:05 +0200 | [diff] [blame] | 18 | #include <stdlib.h> |
Radek Krejci | e84f12f | 2018-09-18 14:11:50 +0200 | [diff] [blame] | 19 | #include <string.h> |
| 20 | |
Radek Krejci | 70593c1 | 2020-06-13 20:48:09 +0200 | [diff] [blame] | 21 | #include "set.h" |
Radek Krejci | e84f12f | 2018-09-18 14:11:50 +0200 | [diff] [blame] | 22 | |
Radek Krejci | e84f12f | 2018-09-18 14:11:50 +0200 | [diff] [blame] | 23 | static void |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 24 | test_basics(void **UNUSED(state)) |
Radek Krejci | e84f12f | 2018-09-18 14:11:50 +0200 | [diff] [blame] | 25 | { |
Radek Krejci | e84f12f | 2018-09-18 14:11:50 +0200 | [diff] [blame] | 26 | struct ly_set *set; |
| 27 | char *str; |
| 28 | unsigned int u; |
| 29 | void *ptr; |
Radek Krejci | ba03a5a | 2020-08-27 14:40:41 +0200 | [diff] [blame] | 30 | uint32_t index; |
Radek Krejci | e84f12f | 2018-09-18 14:11:50 +0200 | [diff] [blame] | 31 | |
| 32 | /* creation - everything is empty */ |
Radek Krejci | ba03a5a | 2020-08-27 14:40:41 +0200 | [diff] [blame] | 33 | assert_int_equal(LY_SUCCESS, ly_set_new(&set)); |
Radek Krejci | e84f12f | 2018-09-18 14:11:50 +0200 | [diff] [blame] | 34 | assert_non_null(set); |
| 35 | assert_int_equal(0, set->count); |
| 36 | assert_int_equal(0, set->size); |
| 37 | assert_null(set->objs); |
| 38 | |
| 39 | /* add a testing object */ |
| 40 | str = strdup("test string"); |
| 41 | assert_non_null(str); |
| 42 | |
Radek Krejci | ba03a5a | 2020-08-27 14:40:41 +0200 | [diff] [blame] | 43 | assert_int_equal(LY_SUCCESS, ly_set_add(set, str, 0, NULL)); |
Radek Krejci | e84f12f | 2018-09-18 14:11:50 +0200 | [diff] [blame] | 44 | assert_int_not_equal(0, set->size); |
| 45 | assert_int_equal(1, set->count); |
| 46 | assert_non_null(set->objs); |
| 47 | assert_non_null(set->objs[0]); |
| 48 | |
| 49 | /* check the presence of the testing data */ |
Radek Krejci | ba03a5a | 2020-08-27 14:40:41 +0200 | [diff] [blame] | 50 | assert_int_not_equal(0, ly_set_contains(set, str, &index)); |
| 51 | assert_int_equal(0, index); |
| 52 | assert_int_equal(0, ly_set_contains(set, str - 1, NULL)); |
Radek Krejci | e84f12f | 2018-09-18 14:11:50 +0200 | [diff] [blame] | 53 | |
| 54 | /* remove data, but keep the set */ |
| 55 | u = set->size; |
| 56 | ptr = set->objs; |
| 57 | ly_set_clean(set, free); |
| 58 | assert_int_equal(0, set->count); |
| 59 | assert_int_equal(u, set->size); |
| 60 | assert_ptr_equal(ptr, set->objs); |
| 61 | |
| 62 | /* remove buffer, but keep the set object */ |
| 63 | ly_set_erase(set, NULL); |
| 64 | assert_int_equal(0, set->count); |
| 65 | assert_int_equal(0, set->size); |
| 66 | assert_ptr_equal(NULL, set->objs); |
| 67 | |
| 68 | /* final cleanup */ |
| 69 | ly_set_free(set, NULL); |
| 70 | } |
| 71 | |
| 72 | static void |
| 73 | test_inval(void **state) |
| 74 | { |
| 75 | struct ly_set set; |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 76 | |
Radek Krejci | e84f12f | 2018-09-18 14:11:50 +0200 | [diff] [blame] | 77 | memset(&set, 0, sizeof set); |
| 78 | |
| 79 | ly_set_clean(NULL, NULL); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 80 | CHECK_LOG(NULL, NULL); |
Radek Krejci | e84f12f | 2018-09-18 14:11:50 +0200 | [diff] [blame] | 81 | |
| 82 | ly_set_erase(NULL, NULL); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 83 | CHECK_LOG(NULL, NULL); |
Radek Krejci | e84f12f | 2018-09-18 14:11:50 +0200 | [diff] [blame] | 84 | |
| 85 | ly_set_free(NULL, NULL); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 86 | CHECK_LOG(NULL, NULL); |
Radek Krejci | e84f12f | 2018-09-18 14:11:50 +0200 | [diff] [blame] | 87 | |
Radek Krejci | ba03a5a | 2020-08-27 14:40:41 +0200 | [diff] [blame] | 88 | assert_int_equal(LY_EINVAL, ly_set_dup(NULL, NULL, NULL)); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 89 | CHECK_LOG("Invalid argument set (ly_set_dup()).", NULL); |
Radek Krejci | e84f12f | 2018-09-18 14:11:50 +0200 | [diff] [blame] | 90 | |
Radek Krejci | ba03a5a | 2020-08-27 14:40:41 +0200 | [diff] [blame] | 91 | assert_int_equal(LY_EINVAL, ly_set_add(NULL, NULL, 0, NULL)); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 92 | CHECK_LOG("Invalid argument set (ly_set_add()).", NULL); |
Radek Krejci | e84f12f | 2018-09-18 14:11:50 +0200 | [diff] [blame] | 93 | |
Radek Krejci | ba03a5a | 2020-08-27 14:40:41 +0200 | [diff] [blame] | 94 | assert_int_equal(LY_EINVAL, ly_set_merge(NULL, NULL, 0, NULL)); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 95 | CHECK_LOG("Invalid argument trg (ly_set_merge()).", NULL); |
Radek Krejci | ba03a5a | 2020-08-27 14:40:41 +0200 | [diff] [blame] | 96 | assert_int_equal(LY_SUCCESS, ly_set_merge(&set, NULL, 0, NULL)); |
Radek Krejci | e84f12f | 2018-09-18 14:11:50 +0200 | [diff] [blame] | 97 | |
Radek Krejci | 820d226 | 2018-09-20 12:15:31 +0200 | [diff] [blame] | 98 | assert_int_equal(LY_EINVAL, ly_set_rm_index(NULL, 0, NULL)); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 99 | CHECK_LOG("Invalid argument set (ly_set_rm_index()).", NULL); |
Radek Krejci | 820d226 | 2018-09-20 12:15:31 +0200 | [diff] [blame] | 100 | assert_int_equal(LY_EINVAL, ly_set_rm_index(&set, 1, NULL)); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 101 | CHECK_LOG("Invalid argument index (ly_set_rm_index()).", NULL); |
Radek Krejci | e84f12f | 2018-09-18 14:11:50 +0200 | [diff] [blame] | 102 | |
Radek Krejci | 820d226 | 2018-09-20 12:15:31 +0200 | [diff] [blame] | 103 | assert_int_equal(LY_EINVAL, ly_set_rm(NULL, NULL, NULL)); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 104 | CHECK_LOG("Invalid argument set (ly_set_rm()).", NULL); |
Radek Krejci | 820d226 | 2018-09-20 12:15:31 +0200 | [diff] [blame] | 105 | assert_int_equal(LY_EINVAL, ly_set_rm(&set, NULL, NULL)); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 106 | CHECK_LOG("Invalid argument object (ly_set_rm()).", NULL); |
| 107 | assert_int_equal(LY_EINVAL, ly_set_rm(&set, &set, NULL)); |
| 108 | CHECK_LOG("Invalid argument object (ly_set_rm()).", NULL); |
Radek Krejci | e84f12f | 2018-09-18 14:11:50 +0200 | [diff] [blame] | 109 | } |
| 110 | |
Radek Krejci | 519b043 | 2018-09-18 17:04:57 +0200 | [diff] [blame] | 111 | static void |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 112 | test_duplication(void **UNUSED(state)) |
Radek Krejci | 519b043 | 2018-09-18 17:04:57 +0200 | [diff] [blame] | 113 | { |
Radek Krejci | 519b043 | 2018-09-18 17:04:57 +0200 | [diff] [blame] | 114 | struct ly_set *orig, *new; |
| 115 | char *str; |
Radek Krejci | ba03a5a | 2020-08-27 14:40:41 +0200 | [diff] [blame] | 116 | uint32_t index; |
Radek Krejci | 519b043 | 2018-09-18 17:04:57 +0200 | [diff] [blame] | 117 | |
Radek Krejci | ba03a5a | 2020-08-27 14:40:41 +0200 | [diff] [blame] | 118 | assert_int_equal(LY_SUCCESS, ly_set_new(&orig)); |
Radek Krejci | 519b043 | 2018-09-18 17:04:57 +0200 | [diff] [blame] | 119 | assert_non_null(orig); |
| 120 | |
| 121 | /* add a testing object */ |
| 122 | str = strdup("test string"); |
| 123 | assert_non_null(str); |
Radek Krejci | ba03a5a | 2020-08-27 14:40:41 +0200 | [diff] [blame] | 124 | assert_int_equal(LY_SUCCESS, ly_set_add(orig, str, 0, &index)); |
| 125 | assert_int_equal(0, index); |
Radek Krejci | 519b043 | 2018-09-18 17:04:57 +0200 | [diff] [blame] | 126 | |
| 127 | /* duplicate the set - without duplicator, so the new set will point to the same string */ |
Radek Krejci | ba03a5a | 2020-08-27 14:40:41 +0200 | [diff] [blame] | 128 | assert_int_equal(LY_SUCCESS, ly_set_dup(orig, NULL, &new)); |
Radek Krejci | 519b043 | 2018-09-18 17:04:57 +0200 | [diff] [blame] | 129 | assert_non_null(new); |
| 130 | assert_ptr_not_equal(orig, new); |
| 131 | assert_int_equal(orig->count, new->count); |
| 132 | assert_ptr_equal(orig->objs[0], new->objs[0]); |
| 133 | |
| 134 | ly_set_free(new, NULL); |
| 135 | |
| 136 | /* duplicate the set - with duplicator, so the new set will point to a different buffer with the same content */ |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 137 | assert_int_equal(LY_SUCCESS, ly_set_dup(orig, (void *(*)(void *))strdup, &new)); |
Radek Krejci | 519b043 | 2018-09-18 17:04:57 +0200 | [diff] [blame] | 138 | assert_non_null(new); |
| 139 | assert_ptr_not_equal(orig, new); |
| 140 | assert_int_equal(orig->count, new->count); |
| 141 | assert_ptr_not_equal(orig->objs[0], new->objs[0]); |
| 142 | assert_string_equal(orig->objs[0], new->objs[0]); |
| 143 | |
| 144 | /* cleanup */ |
| 145 | ly_set_free(new, free); |
| 146 | ly_set_free(orig, free); |
| 147 | } |
| 148 | |
| 149 | static void |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 150 | test_add(void **UNUSED(state)) |
Radek Krejci | 519b043 | 2018-09-18 17:04:57 +0200 | [diff] [blame] | 151 | { |
Radek Krejci | ba03a5a | 2020-08-27 14:40:41 +0200 | [diff] [blame] | 152 | uint32_t u, index; |
Radek Krejci | 519b043 | 2018-09-18 17:04:57 +0200 | [diff] [blame] | 153 | char *str = "test string"; |
| 154 | struct ly_set set; |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 155 | |
Radek Krejci | 519b043 | 2018-09-18 17:04:57 +0200 | [diff] [blame] | 156 | memset(&set, 0, sizeof set); |
| 157 | |
| 158 | /* add a testing object */ |
Radek Krejci | ba03a5a | 2020-08-27 14:40:41 +0200 | [diff] [blame] | 159 | assert_int_equal(LY_SUCCESS, ly_set_add(&set, str, 0, &index)); |
| 160 | assert_int_equal(0, index); |
Radek Krejci | 519b043 | 2018-09-18 17:04:57 +0200 | [diff] [blame] | 161 | |
| 162 | /* test avoiding data duplicities */ |
Radek Krejci | ba03a5a | 2020-08-27 14:40:41 +0200 | [diff] [blame] | 163 | assert_int_equal(LY_SUCCESS, ly_set_add(&set, str, 0, &index)); |
| 164 | assert_int_equal(0, index); |
Radek Krejci | 519b043 | 2018-09-18 17:04:57 +0200 | [diff] [blame] | 165 | assert_int_equal(1, set.count); |
Radek Krejci | 3d92e44 | 2020-10-12 12:48:13 +0200 | [diff] [blame] | 166 | assert_int_equal(LY_SUCCESS, ly_set_add(&set, str, 1, &index)); |
Radek Krejci | ba03a5a | 2020-08-27 14:40:41 +0200 | [diff] [blame] | 167 | assert_int_equal(1, index); |
Radek Krejci | 519b043 | 2018-09-18 17:04:57 +0200 | [diff] [blame] | 168 | assert_int_equal(2, set.count); |
| 169 | |
| 170 | /* test array resizing */ |
| 171 | u = set.size; |
Radek Krejci | ba03a5a | 2020-08-27 14:40:41 +0200 | [diff] [blame] | 172 | for (uint32_t expected_index = 2; expected_index <= u; ++expected_index) { |
Radek Krejci | 3d92e44 | 2020-10-12 12:48:13 +0200 | [diff] [blame] | 173 | assert_int_equal(LY_SUCCESS, ly_set_add(&set, str, 1, &index)); |
Radek Krejci | ba03a5a | 2020-08-27 14:40:41 +0200 | [diff] [blame] | 174 | assert_int_equal(expected_index, index); |
Radek Krejci | 519b043 | 2018-09-18 17:04:57 +0200 | [diff] [blame] | 175 | } |
| 176 | assert_true(u != set.size); |
| 177 | |
| 178 | /* cleanup */ |
| 179 | ly_set_erase(&set, NULL); |
| 180 | } |
| 181 | |
| 182 | static void |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 183 | test_merge(void **UNUSED(state)) |
Radek Krejci | 519b043 | 2018-09-18 17:04:57 +0200 | [diff] [blame] | 184 | { |
Radek Krejci | 519b043 | 2018-09-18 17:04:57 +0200 | [diff] [blame] | 185 | char *str1, *str2; |
| 186 | struct ly_set one, two; |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 187 | |
Radek Krejci | 519b043 | 2018-09-18 17:04:57 +0200 | [diff] [blame] | 188 | memset(&one, 0, sizeof one); |
| 189 | memset(&two, 0, sizeof two); |
| 190 | |
| 191 | str1 = strdup("string1"); |
| 192 | str2 = strdup("string2"); |
| 193 | |
| 194 | /* fill first set |
| 195 | * - str1 is the same as in two, so it must not be freed! */ |
Radek Krejci | ba03a5a | 2020-08-27 14:40:41 +0200 | [diff] [blame] | 196 | assert_int_equal(LY_SUCCESS, ly_set_add(&one, str1, 0, NULL)); |
Radek Krejci | 519b043 | 2018-09-18 17:04:57 +0200 | [diff] [blame] | 197 | |
| 198 | /* fill second set */ |
Radek Krejci | ba03a5a | 2020-08-27 14:40:41 +0200 | [diff] [blame] | 199 | assert_int_equal(LY_SUCCESS, ly_set_add(&two, str1, 0, NULL)); |
| 200 | assert_int_equal(LY_SUCCESS, ly_set_add(&two, str2, 0, NULL)); |
Radek Krejci | 519b043 | 2018-09-18 17:04:57 +0200 | [diff] [blame] | 201 | |
| 202 | /* merge with checking duplicities - only one item is added into one; |
| 203 | * also without duplicating data, so it must not be freed at the end */ |
Radek Krejci | ba03a5a | 2020-08-27 14:40:41 +0200 | [diff] [blame] | 204 | assert_int_equal(LY_SUCCESS, ly_set_merge(&one, &two, 0, NULL)); |
| 205 | assert_int_equal(2, one.count); |
Radek Krejci | 519b043 | 2018-09-18 17:04:57 +0200 | [diff] [blame] | 206 | assert_ptr_equal(one.objs[1], two.objs[1]); |
| 207 | |
| 208 | /* clean and re-fill one (now duplicating str1, to allow testing duplicator) */ |
| 209 | ly_set_clean(&one, NULL); |
Radek Krejci | ba03a5a | 2020-08-27 14:40:41 +0200 | [diff] [blame] | 210 | assert_int_equal(LY_SUCCESS, ly_set_add(&one, strdup(str1), 0, NULL)); |
Radek Krejci | 519b043 | 2018-09-18 17:04:57 +0200 | [diff] [blame] | 211 | |
| 212 | /* merge without checking duplicities - two items are added into one; |
| 213 | * here also with duplicator */ |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 214 | assert_int_equal(LY_SUCCESS, ly_set_merge(&one, &two, 1, (void *(*)(void *))strdup)); |
Radek Krejci | ba03a5a | 2020-08-27 14:40:41 +0200 | [diff] [blame] | 215 | assert_int_equal(3, one.count); |
Radek Krejci | 519b043 | 2018-09-18 17:04:57 +0200 | [diff] [blame] | 216 | assert_ptr_not_equal(one.objs[1], two.objs[0]); |
| 217 | assert_string_equal(one.objs[1], two.objs[0]); |
| 218 | |
| 219 | /* cleanup */ |
| 220 | ly_set_erase(&one, free); |
| 221 | ly_set_erase(&two, free); |
| 222 | } |
| 223 | |
| 224 | static void |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 225 | test_rm(void **UNUSED(state)) |
Radek Krejci | 519b043 | 2018-09-18 17:04:57 +0200 | [diff] [blame] | 226 | { |
Radek Krejci | 519b043 | 2018-09-18 17:04:57 +0200 | [diff] [blame] | 227 | char *str1, *str2, *str3; |
| 228 | struct ly_set set; |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 229 | |
Radek Krejci | 519b043 | 2018-09-18 17:04:57 +0200 | [diff] [blame] | 230 | memset(&set, 0, sizeof set); |
| 231 | |
| 232 | /* fill the set */ |
Radek Krejci | ba03a5a | 2020-08-27 14:40:41 +0200 | [diff] [blame] | 233 | assert_int_equal(LY_SUCCESS, ly_set_add(&set, "string1", 0, NULL)); |
| 234 | assert_int_equal(LY_SUCCESS, ly_set_add(&set, strdup("string2"), 0, NULL)); |
| 235 | assert_int_equal(LY_SUCCESS, ly_set_add(&set, "string3", 0, NULL)); |
Radek Krejci | 519b043 | 2018-09-18 17:04:57 +0200 | [diff] [blame] | 236 | |
| 237 | /* remove by index ... */ |
| 238 | /* ... in the middle ... */ |
Radek Krejci | 820d226 | 2018-09-20 12:15:31 +0200 | [diff] [blame] | 239 | assert_int_equal(LY_SUCCESS, ly_set_rm_index(&set, 1, free)); |
Radek Krejci | 519b043 | 2018-09-18 17:04:57 +0200 | [diff] [blame] | 240 | assert_int_equal(2, set.count); |
| 241 | assert_string_not_equal("string2", set.objs[0]); |
| 242 | assert_string_not_equal("string2", set.objs[1]); |
| 243 | /* ... last .. */ |
Radek Krejci | 820d226 | 2018-09-20 12:15:31 +0200 | [diff] [blame] | 244 | assert_int_equal(LY_SUCCESS, ly_set_rm_index(&set, 1, NULL)); |
Radek Krejci | 519b043 | 2018-09-18 17:04:57 +0200 | [diff] [blame] | 245 | assert_int_equal(1, set.count); |
| 246 | assert_string_not_equal("string3", set.objs[0]); |
| 247 | /* ... first .. */ |
Radek Krejci | 820d226 | 2018-09-20 12:15:31 +0200 | [diff] [blame] | 248 | assert_int_equal(LY_SUCCESS, ly_set_rm_index(&set, 0, NULL)); |
Radek Krejci | 519b043 | 2018-09-18 17:04:57 +0200 | [diff] [blame] | 249 | assert_int_equal(0, set.count); |
| 250 | |
| 251 | /* fill the set */ |
Radek Krejci | ba03a5a | 2020-08-27 14:40:41 +0200 | [diff] [blame] | 252 | assert_int_equal(LY_SUCCESS, ly_set_add(&set, str1 = "string1", 0, NULL)); |
| 253 | assert_int_equal(LY_SUCCESS, ly_set_add(&set, str2 = "string2", 0, NULL)); |
| 254 | assert_int_equal(LY_SUCCESS, ly_set_add(&set, str3 = strdup("string3"), 0, NULL)); |
Radek Krejci | 519b043 | 2018-09-18 17:04:57 +0200 | [diff] [blame] | 255 | |
| 256 | /* remove by pointer ... */ |
| 257 | /* ... in the middle ... */ |
Radek Krejci | 820d226 | 2018-09-20 12:15:31 +0200 | [diff] [blame] | 258 | assert_int_equal(LY_SUCCESS, ly_set_rm(&set, str2, NULL)); |
Radek Krejci | 519b043 | 2018-09-18 17:04:57 +0200 | [diff] [blame] | 259 | assert_int_equal(2, set.count); |
| 260 | assert_string_not_equal("string2", set.objs[0]); |
| 261 | assert_string_not_equal("string2", set.objs[1]); |
Radek Krejci | 820d226 | 2018-09-20 12:15:31 +0200 | [diff] [blame] | 262 | /* ... last (with destructor) .. */ |
| 263 | assert_int_equal(LY_SUCCESS, ly_set_rm(&set, str3, free)); |
Radek Krejci | 519b043 | 2018-09-18 17:04:57 +0200 | [diff] [blame] | 264 | assert_int_equal(1, set.count); |
| 265 | assert_string_not_equal("string3", set.objs[0]); |
| 266 | /* ... first .. */ |
Radek Krejci | 820d226 | 2018-09-20 12:15:31 +0200 | [diff] [blame] | 267 | assert_int_equal(LY_SUCCESS, ly_set_rm(&set, str1, NULL)); |
Radek Krejci | 519b043 | 2018-09-18 17:04:57 +0200 | [diff] [blame] | 268 | assert_int_equal(0, set.count); |
| 269 | |
| 270 | /* cleanup */ |
| 271 | ly_set_erase(&set, NULL); |
| 272 | } |
| 273 | |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 274 | int |
| 275 | main(void) |
Radek Krejci | e84f12f | 2018-09-18 14:11:50 +0200 | [diff] [blame] | 276 | { |
| 277 | const struct CMUnitTest tests[] = { |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 278 | UTEST(test_basics), |
| 279 | UTEST(test_duplication), |
| 280 | UTEST(test_add), |
| 281 | UTEST(test_merge), |
| 282 | UTEST(test_rm), |
| 283 | UTEST(test_inval), |
Radek Krejci | e84f12f | 2018-09-18 14:11:50 +0200 | [diff] [blame] | 284 | }; |
| 285 | |
| 286 | return cmocka_run_group_tests(tests, NULL, NULL); |
| 287 | } |