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_set.c |
Radek Krejci | e84f12f | 2018-09-18 14:11:50 +0200 | [diff] [blame] | 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 */ |
Michal Vasko | f9c0a67 | 2022-02-17 10:48:14 +0100 | [diff] [blame] | 50 | assert_int_equal(1, ly_set_contains(set, str, &index)); |
Radek Krejci | ba03a5a | 2020-08-27 14:40:41 +0200 | [diff] [blame] | 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 |
Michal Vasko | 7a26677 | 2024-01-23 11:02:38 +0100 | [diff] [blame] | 73 | test_inval(void **UNUSED(state)) |
Radek Krejci | e84f12f | 2018-09-18 14:11:50 +0200 | [diff] [blame] | 74 | { |
Michal Vasko | 7a26677 | 2024-01-23 11:02:38 +0100 | [diff] [blame] | 75 | struct ly_set set = {0}; |
Radek Krejci | e84f12f | 2018-09-18 14:11:50 +0200 | [diff] [blame] | 76 | |
Radek Krejci | ba03a5a | 2020-08-27 14:40:41 +0200 | [diff] [blame] | 77 | assert_int_equal(LY_EINVAL, ly_set_dup(NULL, NULL, NULL)); |
Michal Vasko | 7a26677 | 2024-01-23 11:02:38 +0100 | [diff] [blame] | 78 | CHECK_LOG_LASTMSG("Invalid argument set (ly_set_dup())."); |
Radek Krejci | e84f12f | 2018-09-18 14:11:50 +0200 | [diff] [blame] | 79 | |
Radek Krejci | ba03a5a | 2020-08-27 14:40:41 +0200 | [diff] [blame] | 80 | assert_int_equal(LY_EINVAL, ly_set_add(NULL, NULL, 0, NULL)); |
Michal Vasko | 7a26677 | 2024-01-23 11:02:38 +0100 | [diff] [blame] | 81 | CHECK_LOG_LASTMSG("Invalid argument set (ly_set_add())."); |
Radek Krejci | e84f12f | 2018-09-18 14:11:50 +0200 | [diff] [blame] | 82 | |
Radek Krejci | ba03a5a | 2020-08-27 14:40:41 +0200 | [diff] [blame] | 83 | assert_int_equal(LY_EINVAL, ly_set_merge(NULL, NULL, 0, NULL)); |
Michal Vasko | 7a26677 | 2024-01-23 11:02:38 +0100 | [diff] [blame] | 84 | CHECK_LOG_LASTMSG("Invalid argument trg (ly_set_merge())."); |
Radek Krejci | ba03a5a | 2020-08-27 14:40:41 +0200 | [diff] [blame] | 85 | assert_int_equal(LY_SUCCESS, ly_set_merge(&set, NULL, 0, NULL)); |
Radek Krejci | e84f12f | 2018-09-18 14:11:50 +0200 | [diff] [blame] | 86 | |
Radek Krejci | 820d226 | 2018-09-20 12:15:31 +0200 | [diff] [blame] | 87 | assert_int_equal(LY_EINVAL, ly_set_rm_index(NULL, 0, NULL)); |
Michal Vasko | 7a26677 | 2024-01-23 11:02:38 +0100 | [diff] [blame] | 88 | CHECK_LOG_LASTMSG("Invalid argument set (ly_set_rm_index())."); |
Radek Krejci | 820d226 | 2018-09-20 12:15:31 +0200 | [diff] [blame] | 89 | assert_int_equal(LY_EINVAL, ly_set_rm_index(&set, 1, NULL)); |
Michal Vasko | 7a26677 | 2024-01-23 11:02:38 +0100 | [diff] [blame] | 90 | CHECK_LOG_LASTMSG("Invalid argument index (ly_set_rm_index())."); |
Radek Krejci | e84f12f | 2018-09-18 14:11:50 +0200 | [diff] [blame] | 91 | |
Radek Krejci | 820d226 | 2018-09-20 12:15:31 +0200 | [diff] [blame] | 92 | assert_int_equal(LY_EINVAL, ly_set_rm(NULL, NULL, NULL)); |
Michal Vasko | 7a26677 | 2024-01-23 11:02:38 +0100 | [diff] [blame] | 93 | CHECK_LOG_LASTMSG("Invalid argument set (ly_set_rm())."); |
Radek Krejci | 820d226 | 2018-09-20 12:15:31 +0200 | [diff] [blame] | 94 | assert_int_equal(LY_EINVAL, ly_set_rm(&set, NULL, NULL)); |
Michal Vasko | 7a26677 | 2024-01-23 11:02:38 +0100 | [diff] [blame] | 95 | CHECK_LOG_LASTMSG("Invalid argument object (ly_set_rm())."); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 96 | assert_int_equal(LY_EINVAL, ly_set_rm(&set, &set, NULL)); |
Michal Vasko | 7a26677 | 2024-01-23 11:02:38 +0100 | [diff] [blame] | 97 | CHECK_LOG_LASTMSG("Invalid argument object (ly_set_rm())."); |
Radek Krejci | e84f12f | 2018-09-18 14:11:50 +0200 | [diff] [blame] | 98 | } |
| 99 | |
Radek Krejci | 519b043 | 2018-09-18 17:04:57 +0200 | [diff] [blame] | 100 | static void |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 101 | test_duplication(void **UNUSED(state)) |
Radek Krejci | 519b043 | 2018-09-18 17:04:57 +0200 | [diff] [blame] | 102 | { |
Radek Krejci | 519b043 | 2018-09-18 17:04:57 +0200 | [diff] [blame] | 103 | struct ly_set *orig, *new; |
| 104 | char *str; |
Radek Krejci | ba03a5a | 2020-08-27 14:40:41 +0200 | [diff] [blame] | 105 | uint32_t index; |
Radek Krejci | 519b043 | 2018-09-18 17:04:57 +0200 | [diff] [blame] | 106 | |
Radek Krejci | ba03a5a | 2020-08-27 14:40:41 +0200 | [diff] [blame] | 107 | assert_int_equal(LY_SUCCESS, ly_set_new(&orig)); |
Radek Krejci | 519b043 | 2018-09-18 17:04:57 +0200 | [diff] [blame] | 108 | assert_non_null(orig); |
| 109 | |
| 110 | /* add a testing object */ |
| 111 | str = strdup("test string"); |
| 112 | assert_non_null(str); |
Radek Krejci | ba03a5a | 2020-08-27 14:40:41 +0200 | [diff] [blame] | 113 | assert_int_equal(LY_SUCCESS, ly_set_add(orig, str, 0, &index)); |
| 114 | assert_int_equal(0, index); |
Radek Krejci | 519b043 | 2018-09-18 17:04:57 +0200 | [diff] [blame] | 115 | |
| 116 | /* 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] | 117 | assert_int_equal(LY_SUCCESS, ly_set_dup(orig, NULL, &new)); |
Radek Krejci | 519b043 | 2018-09-18 17:04:57 +0200 | [diff] [blame] | 118 | assert_non_null(new); |
| 119 | assert_ptr_not_equal(orig, new); |
| 120 | assert_int_equal(orig->count, new->count); |
| 121 | assert_ptr_equal(orig->objs[0], new->objs[0]); |
| 122 | |
| 123 | ly_set_free(new, NULL); |
| 124 | |
| 125 | /* duplicate the set - with duplicator, so the new set will point to a different buffer with the same content */ |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 126 | assert_int_equal(LY_SUCCESS, ly_set_dup(orig, (void *(*)(const void *))strdup, &new)); |
Radek Krejci | 519b043 | 2018-09-18 17:04:57 +0200 | [diff] [blame] | 127 | assert_non_null(new); |
| 128 | assert_ptr_not_equal(orig, new); |
| 129 | assert_int_equal(orig->count, new->count); |
| 130 | assert_ptr_not_equal(orig->objs[0], new->objs[0]); |
| 131 | assert_string_equal(orig->objs[0], new->objs[0]); |
| 132 | |
| 133 | /* cleanup */ |
| 134 | ly_set_free(new, free); |
| 135 | ly_set_free(orig, free); |
| 136 | } |
| 137 | |
| 138 | static void |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 139 | test_add(void **UNUSED(state)) |
Radek Krejci | 519b043 | 2018-09-18 17:04:57 +0200 | [diff] [blame] | 140 | { |
Radek Krejci | ba03a5a | 2020-08-27 14:40:41 +0200 | [diff] [blame] | 141 | uint32_t u, index; |
Radek Krejci | 519b043 | 2018-09-18 17:04:57 +0200 | [diff] [blame] | 142 | char *str = "test string"; |
| 143 | struct ly_set set; |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 144 | |
Radek Krejci | 519b043 | 2018-09-18 17:04:57 +0200 | [diff] [blame] | 145 | memset(&set, 0, sizeof set); |
| 146 | |
| 147 | /* add a testing object */ |
Radek Krejci | ba03a5a | 2020-08-27 14:40:41 +0200 | [diff] [blame] | 148 | assert_int_equal(LY_SUCCESS, ly_set_add(&set, str, 0, &index)); |
| 149 | assert_int_equal(0, index); |
Radek Krejci | 519b043 | 2018-09-18 17:04:57 +0200 | [diff] [blame] | 150 | |
| 151 | /* test avoiding data duplicities */ |
Radek Krejci | ba03a5a | 2020-08-27 14:40:41 +0200 | [diff] [blame] | 152 | assert_int_equal(LY_SUCCESS, ly_set_add(&set, str, 0, &index)); |
| 153 | assert_int_equal(0, index); |
Radek Krejci | 519b043 | 2018-09-18 17:04:57 +0200 | [diff] [blame] | 154 | assert_int_equal(1, set.count); |
Radek Krejci | 3d92e44 | 2020-10-12 12:48:13 +0200 | [diff] [blame] | 155 | assert_int_equal(LY_SUCCESS, ly_set_add(&set, str, 1, &index)); |
Radek Krejci | ba03a5a | 2020-08-27 14:40:41 +0200 | [diff] [blame] | 156 | assert_int_equal(1, index); |
Radek Krejci | 519b043 | 2018-09-18 17:04:57 +0200 | [diff] [blame] | 157 | assert_int_equal(2, set.count); |
| 158 | |
| 159 | /* test array resizing */ |
| 160 | u = set.size; |
Radek Krejci | ba03a5a | 2020-08-27 14:40:41 +0200 | [diff] [blame] | 161 | for (uint32_t expected_index = 2; expected_index <= u; ++expected_index) { |
Radek Krejci | 3d92e44 | 2020-10-12 12:48:13 +0200 | [diff] [blame] | 162 | assert_int_equal(LY_SUCCESS, ly_set_add(&set, str, 1, &index)); |
Radek Krejci | ba03a5a | 2020-08-27 14:40:41 +0200 | [diff] [blame] | 163 | assert_int_equal(expected_index, index); |
Radek Krejci | 519b043 | 2018-09-18 17:04:57 +0200 | [diff] [blame] | 164 | } |
| 165 | assert_true(u != set.size); |
| 166 | |
| 167 | /* cleanup */ |
| 168 | ly_set_erase(&set, NULL); |
| 169 | } |
| 170 | |
| 171 | static void |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 172 | test_merge(void **UNUSED(state)) |
Radek Krejci | 519b043 | 2018-09-18 17:04:57 +0200 | [diff] [blame] | 173 | { |
Radek Krejci | 519b043 | 2018-09-18 17:04:57 +0200 | [diff] [blame] | 174 | char *str1, *str2; |
| 175 | struct ly_set one, two; |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 176 | |
Radek Krejci | 519b043 | 2018-09-18 17:04:57 +0200 | [diff] [blame] | 177 | memset(&one, 0, sizeof one); |
| 178 | memset(&two, 0, sizeof two); |
| 179 | |
| 180 | str1 = strdup("string1"); |
| 181 | str2 = strdup("string2"); |
| 182 | |
| 183 | /* fill first set |
| 184 | * - 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] | 185 | assert_int_equal(LY_SUCCESS, ly_set_add(&one, str1, 0, NULL)); |
Radek Krejci | 519b043 | 2018-09-18 17:04:57 +0200 | [diff] [blame] | 186 | |
| 187 | /* fill second set */ |
Radek Krejci | ba03a5a | 2020-08-27 14:40:41 +0200 | [diff] [blame] | 188 | assert_int_equal(LY_SUCCESS, ly_set_add(&two, str1, 0, NULL)); |
| 189 | assert_int_equal(LY_SUCCESS, ly_set_add(&two, str2, 0, NULL)); |
Radek Krejci | 519b043 | 2018-09-18 17:04:57 +0200 | [diff] [blame] | 190 | |
| 191 | /* merge with checking duplicities - only one item is added into one; |
| 192 | * 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] | 193 | assert_int_equal(LY_SUCCESS, ly_set_merge(&one, &two, 0, NULL)); |
| 194 | assert_int_equal(2, one.count); |
Radek Krejci | 519b043 | 2018-09-18 17:04:57 +0200 | [diff] [blame] | 195 | assert_ptr_equal(one.objs[1], two.objs[1]); |
| 196 | |
| 197 | /* clean and re-fill one (now duplicating str1, to allow testing duplicator) */ |
| 198 | ly_set_clean(&one, NULL); |
Radek Krejci | ba03a5a | 2020-08-27 14:40:41 +0200 | [diff] [blame] | 199 | 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] | 200 | |
| 201 | /* merge without checking duplicities - two items are added into one; |
| 202 | * here also with duplicator */ |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 203 | assert_int_equal(LY_SUCCESS, ly_set_merge(&one, &two, 1, (void *(*)(const void *))strdup)); |
Radek Krejci | ba03a5a | 2020-08-27 14:40:41 +0200 | [diff] [blame] | 204 | assert_int_equal(3, one.count); |
Radek Krejci | 519b043 | 2018-09-18 17:04:57 +0200 | [diff] [blame] | 205 | assert_ptr_not_equal(one.objs[1], two.objs[0]); |
| 206 | assert_string_equal(one.objs[1], two.objs[0]); |
| 207 | |
| 208 | /* cleanup */ |
| 209 | ly_set_erase(&one, free); |
| 210 | ly_set_erase(&two, free); |
| 211 | } |
| 212 | |
| 213 | static void |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 214 | test_rm(void **UNUSED(state)) |
Radek Krejci | 519b043 | 2018-09-18 17:04:57 +0200 | [diff] [blame] | 215 | { |
Radek Krejci | 519b043 | 2018-09-18 17:04:57 +0200 | [diff] [blame] | 216 | char *str1, *str2, *str3; |
| 217 | struct ly_set set; |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 218 | |
Radek Krejci | 519b043 | 2018-09-18 17:04:57 +0200 | [diff] [blame] | 219 | memset(&set, 0, sizeof set); |
| 220 | |
| 221 | /* fill the set */ |
Radek Krejci | ba03a5a | 2020-08-27 14:40:41 +0200 | [diff] [blame] | 222 | assert_int_equal(LY_SUCCESS, ly_set_add(&set, "string1", 0, NULL)); |
| 223 | assert_int_equal(LY_SUCCESS, ly_set_add(&set, strdup("string2"), 0, NULL)); |
| 224 | assert_int_equal(LY_SUCCESS, ly_set_add(&set, "string3", 0, NULL)); |
Radek Krejci | 519b043 | 2018-09-18 17:04:57 +0200 | [diff] [blame] | 225 | |
| 226 | /* remove by index ... */ |
| 227 | /* ... in the middle ... */ |
Radek Krejci | 820d226 | 2018-09-20 12:15:31 +0200 | [diff] [blame] | 228 | assert_int_equal(LY_SUCCESS, ly_set_rm_index(&set, 1, free)); |
Radek Krejci | 519b043 | 2018-09-18 17:04:57 +0200 | [diff] [blame] | 229 | assert_int_equal(2, set.count); |
| 230 | assert_string_not_equal("string2", set.objs[0]); |
| 231 | assert_string_not_equal("string2", set.objs[1]); |
| 232 | /* ... last .. */ |
Radek Krejci | 820d226 | 2018-09-20 12:15:31 +0200 | [diff] [blame] | 233 | assert_int_equal(LY_SUCCESS, ly_set_rm_index(&set, 1, NULL)); |
Radek Krejci | 519b043 | 2018-09-18 17:04:57 +0200 | [diff] [blame] | 234 | assert_int_equal(1, set.count); |
| 235 | assert_string_not_equal("string3", set.objs[0]); |
| 236 | /* ... first .. */ |
Radek Krejci | 820d226 | 2018-09-20 12:15:31 +0200 | [diff] [blame] | 237 | assert_int_equal(LY_SUCCESS, ly_set_rm_index(&set, 0, NULL)); |
Radek Krejci | 519b043 | 2018-09-18 17:04:57 +0200 | [diff] [blame] | 238 | assert_int_equal(0, set.count); |
| 239 | |
| 240 | /* fill the set */ |
Radek Krejci | ba03a5a | 2020-08-27 14:40:41 +0200 | [diff] [blame] | 241 | assert_int_equal(LY_SUCCESS, ly_set_add(&set, str1 = "string1", 0, NULL)); |
| 242 | assert_int_equal(LY_SUCCESS, ly_set_add(&set, str2 = "string2", 0, NULL)); |
| 243 | 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] | 244 | |
| 245 | /* remove by pointer ... */ |
| 246 | /* ... in the middle ... */ |
Radek Krejci | 820d226 | 2018-09-20 12:15:31 +0200 | [diff] [blame] | 247 | assert_int_equal(LY_SUCCESS, ly_set_rm(&set, str2, NULL)); |
Radek Krejci | 519b043 | 2018-09-18 17:04:57 +0200 | [diff] [blame] | 248 | assert_int_equal(2, set.count); |
| 249 | assert_string_not_equal("string2", set.objs[0]); |
| 250 | assert_string_not_equal("string2", set.objs[1]); |
Radek Krejci | 820d226 | 2018-09-20 12:15:31 +0200 | [diff] [blame] | 251 | /* ... last (with destructor) .. */ |
| 252 | assert_int_equal(LY_SUCCESS, ly_set_rm(&set, str3, free)); |
Radek Krejci | 519b043 | 2018-09-18 17:04:57 +0200 | [diff] [blame] | 253 | assert_int_equal(1, set.count); |
| 254 | assert_string_not_equal("string3", set.objs[0]); |
| 255 | /* ... first .. */ |
Radek Krejci | 820d226 | 2018-09-20 12:15:31 +0200 | [diff] [blame] | 256 | assert_int_equal(LY_SUCCESS, ly_set_rm(&set, str1, NULL)); |
Radek Krejci | 519b043 | 2018-09-18 17:04:57 +0200 | [diff] [blame] | 257 | assert_int_equal(0, set.count); |
| 258 | |
| 259 | /* cleanup */ |
| 260 | ly_set_erase(&set, NULL); |
| 261 | } |
| 262 | |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 263 | int |
| 264 | main(void) |
Radek Krejci | e84f12f | 2018-09-18 14:11:50 +0200 | [diff] [blame] | 265 | { |
| 266 | const struct CMUnitTest tests[] = { |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 267 | UTEST(test_basics), |
| 268 | UTEST(test_duplication), |
| 269 | UTEST(test_add), |
| 270 | UTEST(test_merge), |
| 271 | UTEST(test_rm), |
| 272 | UTEST(test_inval), |
Radek Krejci | e84f12f | 2018-09-18 14:11:50 +0200 | [diff] [blame] | 273 | }; |
| 274 | |
| 275 | return cmocka_run_group_tests(tests, NULL, NULL); |
| 276 | } |