diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-15 17:36:47 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-15 17:36:47 +0000 |
commit | 0441d265f2bb9da249c7abf333f0f771fadb4ab5 (patch) | |
tree | 3f3789daa2f6db22da6e55e92bee0062a7d613fe /src/lib/test-aqueue.c | |
parent | Initial commit. (diff) | |
download | dovecot-0441d265f2bb9da249c7abf333f0f771fadb4ab5.tar.xz dovecot-0441d265f2bb9da249c7abf333f0f771fadb4ab5.zip |
Adding upstream version 1:2.3.21+dfsg1.upstream/1%2.3.21+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/lib/test-aqueue.c')
-rw-r--r-- | src/lib/test-aqueue.c | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/src/lib/test-aqueue.c b/src/lib/test-aqueue.c new file mode 100644 index 0000000..0ff03ac --- /dev/null +++ b/src/lib/test-aqueue.c @@ -0,0 +1,73 @@ +/* Copyright (c) 2007-2018 Dovecot authors, see the included COPYING file */ + +#include "test-lib.h" +#include "array.h" +#include "aqueue.h" + +static bool aqueue_is_ok(struct aqueue *aqueue, unsigned int deleted_n) +{ + const unsigned int *p; + unsigned int n, i, count; + + count = aqueue_count(aqueue); + for (i = 0, n = 1; i < count; i++, n++) { + p = array_idx_i(aqueue->arr, aqueue_idx(aqueue, i)); + if (i == deleted_n) + n++; + if (*p != n) + return FALSE; + } + return TRUE; +} + +static const unsigned int aqueue_input[] = { 1, 2, 3, 4, 5, 6 }; +static const char *test_aqueue2(unsigned int initial_size) +{ + ARRAY(unsigned int) aqueue_array; + unsigned int i, j, k; + + for (i = 0; i < N_ELEMENTS(aqueue_input); i++) { + for (k = 0; k < N_ELEMENTS(aqueue_input); k++) { + struct aqueue *aqueue; + + t_array_init(&aqueue_array, initial_size); + aqueue = aqueue_init(&aqueue_array.arr); + aqueue->head = aqueue->tail = initial_size - 1; + for (j = 0; j < k; j++) { + aqueue_append(aqueue, &aqueue_input[j]); + if (aqueue_count(aqueue) != j + 1) { + return t_strdup_printf("Wrong count after append %u vs %u)", + aqueue_count(aqueue), j + 1); + } + if (!aqueue_is_ok(aqueue, UINT_MAX)) + return "Invalid data after append"; + } + + if (k != 0 && i < k) { + aqueue_delete(aqueue, i); + if (aqueue_count(aqueue) != k - 1) + return "Wrong count after delete"; + if (!aqueue_is_ok(aqueue, i)) + return "Invalid data after delete"; + } + aqueue_clear(aqueue); + if (aqueue_count(aqueue) != 0) + return "aqueue_clear() broken"; + aqueue_deinit(&aqueue); + } + } + return NULL; +} + +void test_aqueue(void) +{ + unsigned int i; + const char *reason = NULL; + + for (i = 1; i <= N_ELEMENTS(aqueue_input) + 1 && reason == NULL; i++) { + T_BEGIN { + reason = test_aqueue2(i); + } T_END; + } + test_out_reason("aqueue", reason == NULL, reason); +} |