diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 09:51:24 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 09:51:24 +0000 |
commit | f7548d6d28c313cf80e6f3ef89aed16a19815df1 (patch) | |
tree | a3f6f2a3f247293bee59ecd28e8cd8ceb6ca064a /src/director/test-user-directory.c | |
parent | Initial commit. (diff) | |
download | dovecot-f7548d6d28c313cf80e6f3ef89aed16a19815df1.tar.xz dovecot-f7548d6d28c313cf80e6f3ef89aed16a19815df1.zip |
Adding upstream version 1:2.3.19.1+dfsg1.upstream/1%2.3.19.1+dfsg1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/director/test-user-directory.c')
-rw-r--r-- | src/director/test-user-directory.c | 109 |
1 files changed, 109 insertions, 0 deletions
diff --git a/src/director/test-user-directory.c b/src/director/test-user-directory.c new file mode 100644 index 0000000..88f40a8 --- /dev/null +++ b/src/director/test-user-directory.c @@ -0,0 +1,109 @@ +/* Copyright (c) 2013-2018 Dovecot authors, see the included COPYING file */ + +#include "lib.h" +#include "ioloop.h" +#include "mail-user-hash.h" +#include "mail-host.h" +#include "test-common.h" + + +#define USER_DIR_TIMEOUT 1000000 + +bool mail_user_hash(const char *username ATTR_UNUSED, + const char *format ATTR_UNUSED, + unsigned int *hash_r, const char **error_r ATTR_UNUSED) +{ + *hash_r = 0; + return TRUE; +} + +static void +verify_user_directory(struct user_directory *dir, unsigned int user_count) +{ + struct user_directory_iter *iter; + struct user *user, *prev = NULL; + unsigned int prev_stamp = 0, iter_count = 0; + + iter = user_directory_iter_init(dir, FALSE); + while ((user = user_directory_iter_next(iter)) != NULL) { + test_assert(prev_stamp <= user->timestamp); + test_assert(user->prev == prev); + test_assert(prev == NULL || user->prev->next == user); + + iter_count++; + prev = user; + } + test_assert(prev == NULL || prev->next == NULL); + user_directory_iter_deinit(&iter); + test_assert(iter_count == user_count); +} + +static void test_user_directory_ascending(void) +{ + const unsigned int count = 100000; + struct user_directory *dir; + struct mail_host *host = t_new(struct mail_host, 1); + unsigned int i; + + test_begin("user directory ascending"); + dir = user_directory_init(NULL, USER_DIR_TIMEOUT, NULL); + (void)user_directory_add(dir, 1, host, ioloop_time + count+1); + + for (i = 0; i < count; i++) + (void)user_directory_add(dir, i+2, host, ioloop_time + i); + verify_user_directory(dir, count+1); + user_directory_deinit(&dir); + test_end(); +} + +static void test_user_directory_descending(void) +{ + const unsigned int count = 1000; + struct user_directory *dir; + struct mail_host *host = t_new(struct mail_host, 1); + unsigned int i; + + test_begin("user directory descending"); + dir = user_directory_init(NULL, USER_DIR_TIMEOUT, NULL); + + for (i = 0; i < count; i++) + (void)user_directory_add(dir, i+1, host, ioloop_time - i); + verify_user_directory(dir, count); + user_directory_deinit(&dir); + test_end(); +} + +static void test_user_directory_random(void) +{ + struct user_directory *dir; + struct mail_host *host = t_new(struct mail_host, 1); + time_t timestamp; + unsigned int i, count = i_rand_minmax(10000, 19999); + + test_begin("user directory random"); + dir = user_directory_init(NULL, USER_DIR_TIMEOUT, NULL); + for (i = 0; i < count; i++) { + if (i_rand_limit(10) == 0) + timestamp = ioloop_time; + else + timestamp = ioloop_time-i_rand_limit(100); + (void)user_directory_add(dir, i+1, host, timestamp); + } + verify_user_directory(dir, count); + user_directory_deinit(&dir); + test_end(); +} + +int main(void) +{ + static void (*const test_functions[])(void) = { + test_user_directory_ascending, + test_user_directory_descending, + test_user_directory_random, + NULL + }; + struct ioloop *ioloop = io_loop_create(); + int ret = test_run(test_functions); + io_loop_destroy(&ioloop); + return ret; +} |