| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
#include "asterisk.h" |
| 32 |
|
| 33 |
#include "asterisk/module.h" |
| 34 |
#include "asterisk/test.h" |
| 35 |
#include "asterisk/strings.h" |
| 36 |
#include "asterisk/logger.h" |
| 37 |
#include "asterisk/linkedlists.h" |
| 38 |
#include "asterisk/dlinkedlists.h" |
| 39 |
|
| 40 |
struct test_val { |
| 41 |
const char *name; |
| 42 |
AST_LIST_ENTRY(test_val) list; |
| 43 |
AST_DLLIST_ENTRY(test_val) dbl_list; |
| 44 |
}; |
| 45 |
|
| 46 |
static struct test_val a = { "A" }; |
| 47 |
static struct test_val b = { "B" }; |
| 48 |
static struct test_val c = { "C" }; |
| 49 |
static struct test_val d = { "D" }; |
| 50 |
|
| 51 |
AST_LIST_HEAD_NOLOCK(test_llist, test_val); |
| 52 |
AST_DLLIST_HEAD_NOLOCK(test_dbl_llist, test_val); |
| 53 |
|
| 54 |
static int list_expect(struct test_llist *test_list, const char *expect, struct ast_str **buf) |
| 55 |
{ |
| 56 |
struct test_val *i; |
| 57 |
|
| 58 |
ast_str_reset(*buf); |
| 59 |
AST_LIST_TRAVERSE(test_list, i, list) { |
| 60 |
ast_str_append(buf, 0, "%s", i->name); |
| 61 |
} |
| 62 |
|
| 63 |
return strcmp(expect, ast_str_buffer(*buf)); |
| 64 |
} |
| 65 |
|
| 66 |
static int dbl_list_expect_forward(struct test_dbl_llist *test_list, const char *expect, struct ast_str **buf) |
| 67 |
{ |
| 68 |
struct test_val *i; |
| 69 |
|
| 70 |
ast_str_reset(*buf); |
| 71 |
AST_DLLIST_TRAVERSE(test_list, i, dbl_list) { |
| 72 |
ast_str_append(buf, 0, "%s", i->name); |
| 73 |
} |
| 74 |
|
| 75 |
return strcmp(expect, ast_str_buffer(*buf)); |
| 76 |
} |
| 77 |
|
| 78 |
static int dbl_list_expect_reverse(struct test_dbl_llist *test_list, const char *expect, struct ast_str **buf) |
| 79 |
{ |
| 80 |
struct test_val *i; |
| 81 |
char *str; |
| 82 |
int len = strlen(expect); |
| 83 |
int idx; |
| 84 |
|
| 85 |
ast_str_reset(*buf); |
| 86 |
AST_DLLIST_TRAVERSE_BACKWARDS(test_list, i, dbl_list) { |
| 87 |
ast_str_append(buf, 0, "%s", i->name); |
| 88 |
} |
| 89 |
|
| 90 |
|
| 91 |
str = ast_str_buffer(*buf); |
| 92 |
if (len != strlen(str)) { |
| 93 |
return 1; |
| 94 |
} |
| 95 |
for (idx = 0; idx < len; ++idx) { |
| 96 |
if (expect[idx] != str[len - idx - 1]) { |
| 97 |
return 1; |
| 98 |
} |
| 99 |
} |
| 100 |
return 0; |
| 101 |
} |
| 102 |
|
| 103 |
#define MATCH_OR_FAIL(list, val, retbuf) \ |
| 104 |
if (list_expect(list, val, &retbuf)) { \ |
| 105 |
ast_test_status_update(test, "Expected: %s, Got: %s\n", val, ast_str_buffer(retbuf)); \ |
| 106 |
return AST_TEST_FAIL; \ |
| 107 |
} |
| 108 |
|
| 109 |
#define MATCH_OR_FAIL_DBL(list, val, retbuf) \ |
| 110 |
if (dbl_list_expect_forward(list, val, &retbuf)) { \ |
| 111 |
ast_test_status_update(test, "Expected: %s, Got: %s\n", val, ast_str_buffer(retbuf)); \ |
| 112 |
return AST_TEST_FAIL; \ |
| 113 |
} \ |
| 114 |
if (dbl_list_expect_reverse(list, val, &retbuf)) { \ |
| 115 |
ast_test_status_update(test, "Expected reverse of: %s, Got: %s\n", val, ast_str_buffer(retbuf)); \ |
| 116 |
return AST_TEST_FAIL; \ |
| 117 |
} |
| 118 |
|
| 119 |
#define ELEM_OR_FAIL(x,y) \ |
| 120 |
if ((x) != (y)) { \ |
| 121 |
ast_test_status_update(test, "Expected: %s, Got: %s\n", (x)->name, (y)->name); \ |
| 122 |
return AST_TEST_FAIL; \ |
| 123 |
} |
| 124 |
|
| 125 |
AST_TEST_DEFINE(single_ll_tests) |
| 126 |
{ |
| 127 |
RAII_VAR(struct ast_str *, buf, NULL, ast_free); |
| 128 |
struct test_llist test_list = { 0, }; |
| 129 |
struct test_llist other_list = { 0, }; |
| 130 |
struct test_val *bogus; |
| 131 |
|
| 132 |
switch (cmd) { |
| 133 |
case TEST_INIT: |
| 134 |
info->name = "ll_tests"; |
| 135 |
info->category = "/main/linkedlists/"; |
| 136 |
info->summary = "single linked list unit test"; |
| 137 |
info->description = |
| 138 |
"Test the single linked list API"; |
| 139 |
return AST_TEST_NOT_RUN; |
| 140 |
case TEST_EXECUTE: |
| 141 |
break; |
| 142 |
} |
| 143 |
|
| 144 |
if (!(buf = ast_str_create(16))) { |
| 145 |
return AST_TEST_FAIL; |
| 146 |
} |
| 147 |
|
| 148 |
if (!(bogus = ast_alloca(sizeof(*bogus)))) { |
| 149 |
return AST_TEST_FAIL; |
| 150 |
} |
| 151 |
memset(bogus, 0, sizeof(*bogus)); |
| 152 |
|
| 153 |
if (AST_LIST_REMOVE(&test_list, bogus, list)) { |
| 154 |
ast_test_status_update(test, "AST_LIST_REMOVE should safely return NULL for missing element from empty list\n"); |
| 155 |
return AST_TEST_FAIL; |
| 156 |
} |
| 157 |
|
| 158 |
|
| 159 |
AST_LIST_INSERT_HEAD(&test_list, &a, list); |
| 160 |
MATCH_OR_FAIL(&test_list, "A", buf); |
| 161 |
AST_LIST_INSERT_HEAD(&test_list, &b, list); |
| 162 |
MATCH_OR_FAIL(&test_list, "BA", buf); |
| 163 |
AST_LIST_REMOVE_HEAD(&test_list, list); |
| 164 |
MATCH_OR_FAIL(&test_list, "A", buf); |
| 165 |
AST_LIST_REMOVE_HEAD(&test_list, list); |
| 166 |
MATCH_OR_FAIL(&test_list, "", buf); |
| 167 |
if (AST_LIST_REMOVE_HEAD(&test_list, list)) { |
| 168 |
ast_test_status_update(test, "Somehow removed an item from the head of a list that didn't exist\n"); |
| 169 |
return AST_TEST_FAIL; |
| 170 |
} |
| 171 |
MATCH_OR_FAIL(&test_list, "", buf); |
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
if (!AST_LIST_EMPTY(&test_list)) { |
| 176 |
ast_test_status_update(test, "List should be empty\n"); |
| 177 |
return AST_TEST_FAIL; |
| 178 |
} |
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
AST_LIST_INSERT_TAIL(&test_list, &a, list); |
| 183 |
MATCH_OR_FAIL(&test_list, "A", buf); |
| 184 |
AST_LIST_INSERT_TAIL(&test_list, &b, list); |
| 185 |
MATCH_OR_FAIL(&test_list, "AB", buf); |
| 186 |
AST_LIST_INSERT_TAIL(&test_list, &c, list); |
| 187 |
MATCH_OR_FAIL(&test_list, "ABC", buf); |
| 188 |
AST_LIST_INSERT_TAIL(&test_list, &d, list); |
| 189 |
MATCH_OR_FAIL(&test_list, "ABCD", buf); |
| 190 |
if (AST_LIST_REMOVE(&test_list, bogus, list)) { |
| 191 |
ast_test_status_update(test, "AST_LIST_REMOVE should safely return NULL for missing element\n"); |
| 192 |
return AST_TEST_FAIL; |
| 193 |
} |
| 194 |
bogus = NULL; |
| 195 |
if (AST_LIST_REMOVE(&test_list, bogus, list)) { |
| 196 |
ast_test_status_update(test, "AST_LIST_REMOVE should safely return NULL for element set to NULL\n"); |
| 197 |
return AST_TEST_FAIL; |
| 198 |
} |
| 199 |
AST_LIST_REMOVE(&test_list, &b, list); |
| 200 |
MATCH_OR_FAIL(&test_list, "ACD", buf); |
| 201 |
AST_LIST_REMOVE(&test_list, &d, list); |
| 202 |
MATCH_OR_FAIL(&test_list, "AC", buf); |
| 203 |
AST_LIST_REMOVE(&test_list, &a, list); |
| 204 |
MATCH_OR_FAIL(&test_list, "C", buf); |
| 205 |
AST_LIST_REMOVE(&test_list, &c, list); |
| 206 |
MATCH_OR_FAIL(&test_list, "", buf); |
| 207 |
if (!AST_LIST_EMPTY(&test_list)) { |
| 208 |
ast_test_status_update(test, "List should be empty\n"); |
| 209 |
return AST_TEST_FAIL; |
| 210 |
} |
| 211 |
if (AST_LIST_REMOVE(&test_list, bogus, list)) { |
| 212 |
ast_test_status_update(test, "AST_LIST_REMOVE should safely return NULL asked to remove a NULL pointer from an empty list\n"); |
| 213 |
return AST_TEST_FAIL; |
| 214 |
} |
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
AST_LIST_INSERT_HEAD(&test_list, &a, list); |
| 219 |
MATCH_OR_FAIL(&test_list, "A", buf); |
| 220 |
AST_LIST_INSERT_TAIL(&test_list, &c, list); |
| 221 |
MATCH_OR_FAIL(&test_list, "AC", buf); |
| 222 |
AST_LIST_INSERT_AFTER(&test_list, &a, &b, list); |
| 223 |
MATCH_OR_FAIL(&test_list, "ABC", buf); |
| 224 |
AST_LIST_INSERT_AFTER(&test_list, &c, &d, list); |
| 225 |
MATCH_OR_FAIL(&test_list, "ABCD", buf); |
| 226 |
|
| 227 |
ELEM_OR_FAIL(AST_LIST_FIRST(&test_list), &a); |
| 228 |
ELEM_OR_FAIL(AST_LIST_LAST(&test_list), &d); |
| 229 |
ELEM_OR_FAIL(AST_LIST_NEXT(&a, list), &b); |
| 230 |
|
| 231 |
AST_LIST_TRAVERSE_SAFE_BEGIN(&test_list, bogus, list) { |
| 232 |
AST_LIST_REMOVE_CURRENT(list); |
| 233 |
} |
| 234 |
AST_LIST_TRAVERSE_SAFE_END; |
| 235 |
|
| 236 |
if (!AST_LIST_EMPTY(&test_list)) { |
| 237 |
ast_test_status_update(test, "List should be empty after traversing and removal. It wasn't.\n"); |
| 238 |
return AST_TEST_FAIL; |
| 239 |
} |
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
AST_LIST_INSERT_HEAD(&test_list, &a, list); |
| 244 |
MATCH_OR_FAIL(&test_list, "A", buf); |
| 245 |
AST_LIST_INSERT_TAIL(&test_list, &b, list); |
| 246 |
MATCH_OR_FAIL(&test_list, "AB", buf); |
| 247 |
AST_LIST_INSERT_HEAD(&other_list, &c, list); |
| 248 |
MATCH_OR_FAIL(&other_list, "C", buf); |
| 249 |
AST_LIST_INSERT_TAIL(&other_list, &d, list); |
| 250 |
MATCH_OR_FAIL(&other_list, "CD", buf); |
| 251 |
AST_LIST_APPEND_LIST(&test_list, &other_list, list); |
| 252 |
MATCH_OR_FAIL(&test_list, "ABCD", buf); |
| 253 |
MATCH_OR_FAIL(&other_list, "", buf); |
| 254 |
AST_LIST_TRAVERSE_SAFE_BEGIN(&test_list, bogus, list) { |
| 255 |
AST_LIST_REMOVE_CURRENT(list); |
| 256 |
} |
| 257 |
AST_LIST_TRAVERSE_SAFE_END; |
| 258 |
if (!AST_LIST_EMPTY(&test_list)) { |
| 259 |
ast_test_status_update(test, "List should be empty after traversing and removal. It wasn't.\n"); |
| 260 |
return AST_TEST_FAIL; |
| 261 |
} |
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
AST_LIST_INSERT_HEAD(&test_list, &a, list); |
| 266 |
MATCH_OR_FAIL(&test_list, "A", buf); |
| 267 |
AST_LIST_INSERT_TAIL(&test_list, &d, list); |
| 268 |
MATCH_OR_FAIL(&test_list, "AD", buf); |
| 269 |
AST_LIST_INSERT_HEAD(&other_list, &b, list); |
| 270 |
MATCH_OR_FAIL(&other_list, "B", buf); |
| 271 |
AST_LIST_INSERT_TAIL(&other_list, &c, list); |
| 272 |
MATCH_OR_FAIL(&other_list, "BC", buf); |
| 273 |
AST_LIST_INSERT_LIST_AFTER(&test_list, &other_list, &a, list); |
| 274 |
MATCH_OR_FAIL(&test_list, "ABCD", buf); |
| 275 |
MATCH_OR_FAIL(&other_list, "", buf); |
| 276 |
AST_LIST_TRAVERSE_SAFE_BEGIN(&test_list, bogus, list) { |
| 277 |
AST_LIST_REMOVE_CURRENT(list); |
| 278 |
} |
| 279 |
AST_LIST_TRAVERSE_SAFE_END; |
| 280 |
if (!AST_LIST_EMPTY(&test_list)) { |
| 281 |
ast_test_status_update(test, "List should be empty after traversing and removal. It wasn't.\n"); |
| 282 |
return AST_TEST_FAIL; |
| 283 |
} |
| 284 |
|
| 285 |
|
| 286 |
|
| 287 |
AST_LIST_INSERT_HEAD(&test_list, &a, list); |
| 288 |
MATCH_OR_FAIL(&test_list, "A", buf); |
| 289 |
AST_LIST_INSERT_TAIL(&test_list, &b, list); |
| 290 |
MATCH_OR_FAIL(&test_list, "AB", buf); |
| 291 |
AST_LIST_INSERT_HEAD(&other_list, &c, list); |
| 292 |
MATCH_OR_FAIL(&other_list, "C", buf); |
| 293 |
AST_LIST_INSERT_TAIL(&other_list, &d, list); |
| 294 |
MATCH_OR_FAIL(&other_list, "CD", buf); |
| 295 |
AST_LIST_INSERT_LIST_AFTER(&test_list, &other_list, &b, list); |
| 296 |
MATCH_OR_FAIL(&test_list, "ABCD", buf); |
| 297 |
MATCH_OR_FAIL(&other_list, "", buf); |
| 298 |
AST_LIST_TRAVERSE_SAFE_BEGIN(&test_list, bogus, list) { |
| 299 |
AST_LIST_REMOVE_CURRENT(list); |
| 300 |
} |
| 301 |
AST_LIST_TRAVERSE_SAFE_END; |
| 302 |
if (!AST_LIST_EMPTY(&test_list)) { |
| 303 |
ast_test_status_update(test, "List should be empty after traversing and removal. It wasn't.\n"); |
| 304 |
return AST_TEST_FAIL; |
| 305 |
} |
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
AST_LIST_INSERT_HEAD(&test_list, &a, list); |
| 310 |
MATCH_OR_FAIL(&test_list, "A", buf); |
| 311 |
AST_LIST_INSERT_TAIL(&test_list, &d, list); |
| 312 |
MATCH_OR_FAIL(&test_list, "AD", buf); |
| 313 |
AST_LIST_TRAVERSE_SAFE_BEGIN(&test_list, bogus, list) { |
| 314 |
if (bogus == &d) { |
| 315 |
AST_LIST_INSERT_BEFORE_CURRENT(&b, list); |
| 316 |
MATCH_OR_FAIL(&test_list, "ABD", buf); |
| 317 |
AST_LIST_INSERT_BEFORE_CURRENT(&c, list); |
| 318 |
MATCH_OR_FAIL(&test_list, "ABCD", buf); |
| 319 |
AST_LIST_REMOVE_CURRENT(list); |
| 320 |
MATCH_OR_FAIL(&test_list, "ABC", buf); |
| 321 |
} |
| 322 |
} |
| 323 |
AST_LIST_TRAVERSE_SAFE_END; |
| 324 |
MATCH_OR_FAIL(&test_list, "ABC", buf); |
| 325 |
AST_LIST_TRAVERSE_SAFE_BEGIN(&test_list, bogus, list) { |
| 326 |
AST_LIST_REMOVE_CURRENT(list); |
| 327 |
} |
| 328 |
AST_LIST_TRAVERSE_SAFE_END; |
| 329 |
if (!AST_LIST_EMPTY(&test_list)) { |
| 330 |
ast_test_status_update(test, "List should be empty after traversing and removal. It wasn't.\n"); |
| 331 |
return AST_TEST_FAIL; |
| 332 |
} |
| 333 |
|
| 334 |
return AST_TEST_PASS; |
| 335 |
} |
| 336 |
|
| 337 |
AST_TEST_DEFINE(double_ll_tests) |
| 338 |
{ |
| 339 |
RAII_VAR(struct ast_str *, buf, NULL, ast_free); |
| 340 |
struct test_dbl_llist test_list = { 0, }; |
| 341 |
struct test_dbl_llist other_list = { 0, }; |
| 342 |
struct test_val *bogus; |
| 343 |
|
| 344 |
switch (cmd) { |
| 345 |
case TEST_INIT: |
| 346 |
info->name = "double_ll_tests"; |
| 347 |
info->category = "/main/linkedlists/"; |
| 348 |
info->summary = "double linked list unit test"; |
| 349 |
info->description = |
| 350 |
"Test the double linked list API"; |
| 351 |
return AST_TEST_NOT_RUN; |
| 352 |
case TEST_EXECUTE: |
| 353 |
break; |
| 354 |
} |
| 355 |
|
| 356 |
if (!(buf = ast_str_create(16))) { |
| 357 |
return AST_TEST_FAIL; |
| 358 |
} |
| 359 |
|
| 360 |
bogus = ast_alloca(sizeof(*bogus)); |
| 361 |
|
| 362 |
if (AST_DLLIST_REMOVE_VERIFY(&test_list, bogus, dbl_list)) { |
| 363 |
ast_test_status_update(test, "AST_DLLIST_REMOVE_VERIFY should safely return NULL for missing element from empty list\n"); |
| 364 |
return AST_TEST_FAIL; |
| 365 |
} |
| 366 |
|
| 367 |
|
| 368 |
AST_DLLIST_INSERT_HEAD(&test_list, &a, dbl_list); |
| 369 |
MATCH_OR_FAIL_DBL(&test_list, "A", buf); |
| 370 |
AST_DLLIST_INSERT_HEAD(&test_list, &b, dbl_list); |
| 371 |
MATCH_OR_FAIL_DBL(&test_list, "BA", buf); |
| 372 |
AST_DLLIST_REMOVE_HEAD(&test_list, dbl_list); |
| 373 |
MATCH_OR_FAIL_DBL(&test_list, "A", buf); |
| 374 |
AST_DLLIST_REMOVE_HEAD(&test_list, dbl_list); |
| 375 |
MATCH_OR_FAIL_DBL(&test_list, "", buf); |
| 376 |
if (AST_DLLIST_REMOVE_HEAD(&test_list, dbl_list)) { |
| 377 |
ast_test_status_update(test, "Somehow removed an item from the head of a list that didn't exist\n"); |
| 378 |
return AST_TEST_FAIL; |
| 379 |
} |
| 380 |
MATCH_OR_FAIL_DBL(&test_list, "", buf); |
| 381 |
|
| 382 |
|
| 383 |
|
| 384 |
if (!AST_DLLIST_EMPTY(&test_list)) { |
| 385 |
ast_test_status_update(test, "List should be empty\n"); |
| 386 |
return AST_TEST_FAIL; |
| 387 |
} |
| 388 |
|
| 389 |
|
| 390 |
|
| 391 |
AST_DLLIST_INSERT_TAIL(&test_list, &a, dbl_list); |
| 392 |
MATCH_OR_FAIL_DBL(&test_list, "A", buf); |
| 393 |
AST_DLLIST_INSERT_TAIL(&test_list, &b, dbl_list); |
| 394 |
MATCH_OR_FAIL_DBL(&test_list, "AB", buf); |
| 395 |
AST_DLLIST_INSERT_TAIL(&test_list, &c, dbl_list); |
| 396 |
MATCH_OR_FAIL_DBL(&test_list, "ABC", buf); |
| 397 |
AST_DLLIST_INSERT_TAIL(&test_list, &d, dbl_list); |
| 398 |
MATCH_OR_FAIL_DBL(&test_list, "ABCD", buf); |
| 399 |
if (AST_DLLIST_REMOVE_VERIFY(&test_list, bogus, dbl_list)) { |
| 400 |
ast_test_status_update(test, "AST_DLLIST_REMOVE_VERIFY should safely return NULL for missing element\n"); |
| 401 |
return AST_TEST_FAIL; |
| 402 |
} |
| 403 |
bogus = NULL; |
| 404 |
if (AST_DLLIST_REMOVE_VERIFY(&test_list, bogus, dbl_list)) { |
| 405 |
ast_test_status_update(test, "AST_DLLIST_REMOVE_VERIFY should safely return NULL for element set to NULL\n"); |
| 406 |
return AST_TEST_FAIL; |
| 407 |
} |
| 408 |
AST_DLLIST_REMOVE(&test_list, &b, dbl_list); |
| 409 |
MATCH_OR_FAIL_DBL(&test_list, "ACD", buf); |
| 410 |
AST_DLLIST_REMOVE(&test_list, &d, dbl_list); |
| 411 |
MATCH_OR_FAIL_DBL(&test_list, "AC", buf); |
| 412 |
AST_DLLIST_REMOVE(&test_list, &a, dbl_list); |
| 413 |
MATCH_OR_FAIL_DBL(&test_list, "C", buf); |
| 414 |
AST_DLLIST_REMOVE(&test_list, &c, dbl_list); |
| 415 |
MATCH_OR_FAIL_DBL(&test_list, "", buf); |
| 416 |
if (!AST_DLLIST_EMPTY(&test_list)) { |
| 417 |
ast_test_status_update(test, "List should be empty\n"); |
| 418 |
return AST_TEST_FAIL; |
| 419 |
} |
| 420 |
if (AST_DLLIST_REMOVE_VERIFY(&test_list, bogus, dbl_list)) { |
| 421 |
ast_test_status_update(test, "AST_DLLIST_REMOVE_VERIFY should safely return NULL asked to remove a NULL pointer from an empty list\n"); |
| 422 |
return AST_TEST_FAIL; |
| 423 |
} |
| 424 |
|
| 425 |
|
| 426 |
|
| 427 |
AST_DLLIST_INSERT_HEAD(&test_list, &a, dbl_list); |
| 428 |
MATCH_OR_FAIL_DBL(&test_list, "A", buf); |
| 429 |
AST_DLLIST_INSERT_TAIL(&test_list, &c, dbl_list); |
| 430 |
MATCH_OR_FAIL_DBL(&test_list, "AC", buf); |
| 431 |
AST_DLLIST_INSERT_AFTER(&test_list, &a, &b, dbl_list); |
| 432 |
MATCH_OR_FAIL_DBL(&test_list, "ABC", buf); |
| 433 |
AST_DLLIST_INSERT_AFTER(&test_list, &c, &d, dbl_list); |
| 434 |
MATCH_OR_FAIL_DBL(&test_list, "ABCD", buf); |
| 435 |
AST_DLLIST_REMOVE_TAIL(&test_list, dbl_list); |
| 436 |
MATCH_OR_FAIL_DBL(&test_list, "ABC", buf); |
| 437 |
AST_DLLIST_REMOVE_TAIL(&test_list, dbl_list); |
| 438 |
MATCH_OR_FAIL_DBL(&test_list, "AB", buf); |
| 439 |
AST_DLLIST_INSERT_TAIL(&test_list, &d, dbl_list); |
| 440 |
MATCH_OR_FAIL_DBL(&test_list, "ABD", buf); |
| 441 |
AST_DLLIST_INSERT_BEFORE(&test_list, &d, &c, dbl_list); |
| 442 |
MATCH_OR_FAIL_DBL(&test_list, "ABCD", buf); |
| 443 |
AST_DLLIST_REMOVE_HEAD(&test_list, dbl_list); |
| 444 |
MATCH_OR_FAIL_DBL(&test_list, "BCD", buf); |
| 445 |
AST_DLLIST_INSERT_BEFORE(&test_list, &b, &a, dbl_list); |
| 446 |
MATCH_OR_FAIL_DBL(&test_list, "ABCD", buf); |
| 447 |
|
| 448 |
ELEM_OR_FAIL(AST_DLLIST_FIRST(&test_list), &a); |
| 449 |
ELEM_OR_FAIL(AST_DLLIST_LAST(&test_list), &d); |
| 450 |
ELEM_OR_FAIL(AST_DLLIST_NEXT(&a, dbl_list), &b); |
| 451 |
ELEM_OR_FAIL(AST_DLLIST_PREV(&b, dbl_list), &a); |
| 452 |
|
| 453 |
AST_DLLIST_TRAVERSE_SAFE_BEGIN(&test_list, bogus, dbl_list) { |
| 454 |
AST_DLLIST_REMOVE_CURRENT(dbl_list); |
| 455 |
} |
| 456 |
AST_DLLIST_TRAVERSE_SAFE_END; |
| 457 |
|
| 458 |
if (!AST_DLLIST_EMPTY(&test_list)) { |
| 459 |
ast_test_status_update(test, "List should be empty after traversing and removal. It wasn't.\n"); |
| 460 |
return AST_TEST_FAIL; |
| 461 |
} |
| 462 |
|
| 463 |
|
| 464 |
|
| 465 |
AST_DLLIST_INSERT_HEAD(&test_list, &a, dbl_list); |
| 466 |
MATCH_OR_FAIL_DBL(&test_list, "A", buf); |
| 467 |
AST_DLLIST_INSERT_TAIL(&test_list, &b, dbl_list); |
| 468 |
MATCH_OR_FAIL_DBL(&test_list, "AB", buf); |
| 469 |
AST_DLLIST_INSERT_HEAD(&other_list, &c, dbl_list); |
| 470 |
MATCH_OR_FAIL_DBL(&other_list, "C", buf); |
| 471 |
AST_DLLIST_INSERT_TAIL(&other_list, &d, dbl_list); |
| 472 |
MATCH_OR_FAIL_DBL(&other_list, "CD", buf); |
| 473 |
AST_DLLIST_APPEND_DLLIST(&test_list, &other_list, dbl_list); |
| 474 |
MATCH_OR_FAIL_DBL(&test_list, "ABCD", buf); |
| 475 |
MATCH_OR_FAIL_DBL(&other_list, "", buf); |
| 476 |
AST_DLLIST_TRAVERSE_SAFE_BEGIN(&test_list, bogus, dbl_list) { |
| 477 |
AST_DLLIST_REMOVE_CURRENT(dbl_list); |
| 478 |
} |
| 479 |
AST_DLLIST_TRAVERSE_SAFE_END; |
| 480 |
if (!AST_DLLIST_EMPTY(&test_list)) { |
| 481 |
ast_test_status_update(test, "List should be empty after traversing and removal. It wasn't.\n"); |
| 482 |
return AST_TEST_FAIL; |
| 483 |
} |
| 484 |
|
| 485 |
|
| 486 |
|
| 487 |
|
| 488 |
|
| 489 |
|
| 490 |
AST_DLLIST_INSERT_HEAD(&test_list, &a, dbl_list); |
| 491 |
MATCH_OR_FAIL_DBL(&test_list, "A", buf); |
| 492 |
AST_DLLIST_INSERT_TAIL(&test_list, &d, dbl_list); |
| 493 |
MATCH_OR_FAIL_DBL(&test_list, "AD", buf); |
| 494 |
AST_DLLIST_TRAVERSE_SAFE_BEGIN(&test_list, bogus, dbl_list) { |
| 495 |
if (bogus == &d) { |
| 496 |
AST_DLLIST_INSERT_BEFORE_CURRENT(&b, dbl_list); |
| 497 |
MATCH_OR_FAIL_DBL(&test_list, "ABD", buf); |
| 498 |
AST_DLLIST_INSERT_BEFORE_CURRENT(&c, dbl_list); |
| 499 |
MATCH_OR_FAIL_DBL(&test_list, "ABCD", buf); |
| 500 |
AST_DLLIST_REMOVE_CURRENT(dbl_list); |
| 501 |
MATCH_OR_FAIL_DBL(&test_list, "ABC", buf); |
| 502 |
} |
| 503 |
} |
| 504 |
AST_DLLIST_TRAVERSE_SAFE_END; |
| 505 |
MATCH_OR_FAIL_DBL(&test_list, "ABC", buf); |
| 506 |
AST_DLLIST_TRAVERSE_SAFE_BEGIN(&test_list, bogus, dbl_list) { |
| 507 |
AST_DLLIST_REMOVE_CURRENT(dbl_list); |
| 508 |
} |
| 509 |
AST_DLLIST_TRAVERSE_SAFE_END; |
| 510 |
if (!AST_DLLIST_EMPTY(&test_list)) { |
| 511 |
ast_test_status_update(test, "List should be empty after traversing and removal. It wasn't.\n"); |
| 512 |
return AST_TEST_FAIL; |
| 513 |
} |
| 514 |
|
| 515 |
AST_DLLIST_INSERT_HEAD(&test_list, &b, dbl_list); |
| 516 |
MATCH_OR_FAIL_DBL(&test_list, "B", buf); |
| 517 |
AST_DLLIST_INSERT_TAIL(&test_list, &d, dbl_list); |
| 518 |
MATCH_OR_FAIL_DBL(&test_list, "BD", buf); |
| 519 |
AST_DLLIST_TRAVERSE_SAFE_BEGIN(&test_list, bogus, dbl_list) { |
| 520 |
if (bogus == &b) { |
| 521 |
AST_DLLIST_INSERT_BEFORE_CURRENT(&a, dbl_list); |
| 522 |
MATCH_OR_FAIL_DBL(&test_list, "ABD", buf); |
| 523 |
AST_DLLIST_INSERT_AFTER_CURRENT(&c, dbl_list); |
| 524 |
MATCH_OR_FAIL_DBL(&test_list, "ABCD", buf); |
| 525 |
AST_DLLIST_REMOVE_CURRENT(dbl_list); |
| 526 |
MATCH_OR_FAIL_DBL(&test_list, "ACD", buf); |
| 527 |
} |
| 528 |
} |
| 529 |
AST_DLLIST_TRAVERSE_SAFE_END; |
| 530 |
MATCH_OR_FAIL_DBL(&test_list, "ACD", buf); |
| 531 |
AST_DLLIST_TRAVERSE_SAFE_BEGIN(&test_list, bogus, dbl_list) { |
| 532 |
AST_DLLIST_REMOVE_CURRENT(dbl_list); |
| 533 |
} |
| 534 |
AST_DLLIST_TRAVERSE_SAFE_END; |
| 535 |
if (!AST_DLLIST_EMPTY(&test_list)) { |
| 536 |
ast_test_status_update(test, "List should be empty after traversing and removal. It wasn't.\n"); |
| 537 |
return AST_TEST_FAIL; |
| 538 |
} |
| 539 |
|
| 540 |
AST_DLLIST_INSERT_HEAD(&test_list, &b, dbl_list); |
| 541 |
MATCH_OR_FAIL_DBL(&test_list, "B", buf); |
| 542 |
AST_DLLIST_TRAVERSE_SAFE_BEGIN(&test_list, bogus, dbl_list) { |
| 543 |
if (bogus == &b) { |
| 544 |
AST_DLLIST_INSERT_BEFORE_CURRENT(&a, dbl_list); |
| 545 |
MATCH_OR_FAIL_DBL(&test_list, "AB", buf); |
| 546 |
AST_DLLIST_INSERT_AFTER_CURRENT(&d, dbl_list); |
| 547 |
MATCH_OR_FAIL_DBL(&test_list, "ABD", buf); |
| 548 |
AST_DLLIST_INSERT_AFTER_CURRENT(&c, dbl_list); |
| 549 |
MATCH_OR_FAIL_DBL(&test_list, "ABCD", buf); |
| 550 |
AST_DLLIST_REMOVE_CURRENT(dbl_list); |
| 551 |
MATCH_OR_FAIL_DBL(&test_list, "ACD", buf); |
| 552 |
} |
| 553 |
} |
| 554 |
AST_DLLIST_TRAVERSE_SAFE_END; |
| 555 |
MATCH_OR_FAIL_DBL(&test_list, "ACD", buf); |
| 556 |
AST_DLLIST_TRAVERSE_SAFE_BEGIN(&test_list, bogus, dbl_list) { |
| 557 |
AST_DLLIST_REMOVE_CURRENT(dbl_list); |
| 558 |
} |
| 559 |
AST_DLLIST_TRAVERSE_SAFE_END; |
| 560 |
if (!AST_DLLIST_EMPTY(&test_list)) { |
| 561 |
ast_test_status_update(test, "List should be empty after traversing and removal. It wasn't.\n"); |
| 562 |
return AST_TEST_FAIL; |
| 563 |
} |
| 564 |
|
| 565 |
|
| 566 |
|
| 567 |
|
| 568 |
|
| 569 |
|
| 570 |
AST_DLLIST_INSERT_HEAD(&test_list, &a, dbl_list); |
| 571 |
MATCH_OR_FAIL_DBL(&test_list, "A", buf); |
| 572 |
AST_DLLIST_INSERT_TAIL(&test_list, &d, dbl_list); |
| 573 |
MATCH_OR_FAIL_DBL(&test_list, "AD", buf); |
| 574 |
AST_DLLIST_TRAVERSE_BACKWARDS_SAFE_BEGIN(&test_list, bogus, dbl_list) { |
| 575 |
if (bogus == &d) { |
| 576 |
AST_DLLIST_INSERT_BEFORE_CURRENT(&b, dbl_list); |
| 577 |
MATCH_OR_FAIL_DBL(&test_list, "ABD", buf); |
| 578 |
AST_DLLIST_INSERT_BEFORE_CURRENT(&c, dbl_list); |
| 579 |
MATCH_OR_FAIL_DBL(&test_list, "ABCD", buf); |
| 580 |
AST_DLLIST_REMOVE_CURRENT(dbl_list); |
| 581 |
MATCH_OR_FAIL_DBL(&test_list, "ABC", buf); |
| 582 |
} |
| 583 |
} |
| 584 |
AST_DLLIST_TRAVERSE_BACKWARDS_SAFE_END; |
| 585 |
MATCH_OR_FAIL_DBL(&test_list, "ABC", buf); |
| 586 |
AST_DLLIST_TRAVERSE_BACKWARDS_SAFE_BEGIN(&test_list, bogus, dbl_list) { |
| 587 |
AST_DLLIST_REMOVE_CURRENT(dbl_list); |
| 588 |
} |
| 589 |
AST_DLLIST_TRAVERSE_BACKWARDS_SAFE_END; |
| 590 |
if (!AST_DLLIST_EMPTY(&test_list)) { |
| 591 |
ast_test_status_update(test, "List should be empty after traversing and removal. It wasn't.\n"); |
| 592 |
return AST_TEST_FAIL; |
| 593 |
} |
| 594 |
|
| 595 |
AST_DLLIST_INSERT_HEAD(&test_list, &b, dbl_list); |
| 596 |
MATCH_OR_FAIL_DBL(&test_list, "B", buf); |
| 597 |
AST_DLLIST_INSERT_TAIL(&test_list, &d, dbl_list); |
| 598 |
MATCH_OR_FAIL_DBL(&test_list, "BD", buf); |
| 599 |
AST_DLLIST_TRAVERSE_BACKWARDS_SAFE_BEGIN(&test_list, bogus, dbl_list) { |
| 600 |
if (bogus == &b) { |
| 601 |
AST_DLLIST_INSERT_BEFORE_CURRENT(&a, dbl_list); |
| 602 |
MATCH_OR_FAIL_DBL(&test_list, "ABD", buf); |
| 603 |
AST_DLLIST_INSERT_AFTER_CURRENT(&c, dbl_list); |
| 604 |
MATCH_OR_FAIL_DBL(&test_list, "ABCD", buf); |
| 605 |
AST_DLLIST_REMOVE_CURRENT(dbl_list); |
| 606 |
MATCH_OR_FAIL_DBL(&test_list, "ACD", buf); |
| 607 |
} |
| 608 |
} |
| 609 |
AST_DLLIST_TRAVERSE_BACKWARDS_SAFE_END; |
| 610 |
MATCH_OR_FAIL_DBL(&test_list, "ACD", buf); |
| 611 |
AST_DLLIST_TRAVERSE_SAFE_BEGIN(&test_list, bogus, dbl_list) { |
| 612 |
AST_DLLIST_REMOVE_CURRENT(dbl_list); |
| 613 |
} |
| 614 |
AST_DLLIST_TRAVERSE_SAFE_END; |
| 615 |
if (!AST_DLLIST_EMPTY(&test_list)) { |
| 616 |
ast_test_status_update(test, "List should be empty after traversing and removal. It wasn't.\n"); |
| 617 |
return AST_TEST_FAIL; |
| 618 |
} |
| 619 |
|
| 620 |
AST_DLLIST_INSERT_HEAD(&test_list, &b, dbl_list); |
| 621 |
MATCH_OR_FAIL_DBL(&test_list, "B", buf); |
| 622 |
AST_DLLIST_TRAVERSE_BACKWARDS_SAFE_BEGIN(&test_list, bogus, dbl_list) { |
| 623 |
if (bogus == &b) { |
| 624 |
AST_DLLIST_INSERT_BEFORE_CURRENT(&a, dbl_list); |
| 625 |
MATCH_OR_FAIL_DBL(&test_list, "AB", buf); |
| 626 |
AST_DLLIST_INSERT_AFTER_CURRENT(&d, dbl_list); |
| 627 |
MATCH_OR_FAIL_DBL(&test_list, "ABD", buf); |
| 628 |
AST_DLLIST_INSERT_AFTER_CURRENT(&c, dbl_list); |
| 629 |
MATCH_OR_FAIL_DBL(&test_list, "ABCD", buf); |
| 630 |
AST_DLLIST_REMOVE_CURRENT(dbl_list); |
| 631 |
MATCH_OR_FAIL_DBL(&test_list, "ACD", buf); |
| 632 |
} |
| 633 |
} |
| 634 |
AST_DLLIST_TRAVERSE_BACKWARDS_SAFE_END; |
| 635 |
MATCH_OR_FAIL_DBL(&test_list, "ACD", buf); |
| 636 |
AST_DLLIST_TRAVERSE_SAFE_BEGIN(&test_list, bogus, dbl_list) { |
| 637 |
AST_DLLIST_REMOVE_CURRENT(dbl_list); |
| 638 |
} |
| 639 |
AST_DLLIST_TRAVERSE_SAFE_END; |
| 640 |
if (!AST_DLLIST_EMPTY(&test_list)) { |
| 641 |
ast_test_status_update(test, "List should be empty after traversing and removal. It wasn't.\n"); |
| 642 |
return AST_TEST_FAIL; |
| 643 |
} |
| 644 |
|
| 645 |
return AST_TEST_PASS; |
| 646 |
} |
| 647 |
|
| 648 |
static int unload_module(void) |
| 649 |
{ |
| 650 |
AST_TEST_UNREGISTER(single_ll_tests); |
| 651 |
AST_TEST_UNREGISTER(double_ll_tests); |
| 652 |
return 0; |
| 653 |
} |
| 654 |
|
| 655 |
static int load_module(void) |
| 656 |
{ |
| 657 |
AST_TEST_REGISTER(single_ll_tests); |
| 658 |
AST_TEST_REGISTER(double_ll_tests); |
| 659 |
return AST_MODULE_LOAD_SUCCESS; |
| 660 |
} |
| 661 |
|
| 662 |
AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Test Linked Lists"); |