From 0312b6beef18a9ca07ca913de53444c3ae2985e6 Mon Sep 17 00:00:00 2001 From: Richard Russon Date: Wed, 29 May 2019 17:01:33 +0100 Subject: [PATCH] test: add shared list testing code --- test/Makefile.autosetup | 3 ++- test/list/common.c | 42 +++++++++++++++++++++++++++++++++++++++++ test/list/common.h | 31 ++++++++++++++++++++++++++++++ 3 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 test/list/common.c create mode 100644 test/list/common.h diff --git a/test/Makefile.autosetup b/test/Makefile.autosetup index e38c75e82..ec472c949 100644 --- a/test/Makefile.autosetup +++ b/test/Makefile.autosetup @@ -220,7 +220,8 @@ IDNA_OBJS = test/idna/mutt_idna_intl_to_local.o \ test/idna/mutt_idna_print_version.o \ test/idna/mutt_idna_to_ascii_lz.o -LIST_OBJS = test/list/mutt_list_clear.o \ +LIST_OBJS = test/list/common.o \ + test/list/mutt_list_clear.o \ test/list/mutt_list_compare.o \ test/list/mutt_list_find.o \ test/list/mutt_list_free.o \ diff --git a/test/list/common.c b/test/list/common.c new file mode 100644 index 000000000..3e0fba124 --- /dev/null +++ b/test/list/common.c @@ -0,0 +1,42 @@ +/** + * @file + * Shared Testing Code + * + * @authors + * Copyright (C) 2017-2018 Richard Russon + * + * @copyright + * This program is free software: you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free Software + * Foundation, either version 2 of the License, or (at your option) any later + * version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ + +#include "config.h" +#include +#include "mutt/mutt.h" + +struct ListHead test_list_create(const char *items[], bool copy) +{ + struct ListHead lh = STAILQ_HEAD_INITIALIZER(lh); + + for (size_t i = 0; items[i]; i++) + { + struct ListNode *np = mutt_mem_calloc(1, sizeof(struct ListNode)); + if (copy) + np->data = mutt_str_strdup(items[i]); + else + np->data = (char *) items[i]; + STAILQ_INSERT_TAIL(&lh, np, entries); + } + + return lh; +} diff --git a/test/list/common.h b/test/list/common.h new file mode 100644 index 000000000..6583b37d4 --- /dev/null +++ b/test/list/common.h @@ -0,0 +1,31 @@ +/** + * @file + * Shared Testing Code + * + * @authors + * Copyright (C) 2017-2018 Richard Russon + * + * @copyright + * This program is free software: you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free Software + * Foundation, either version 2 of the License, or (at your option) any later + * version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ + +#ifndef TEST_LIST_COMMON_H +#define TEST_LIST_COMMON_H + +#include +#include "mutt/mutt.h" + +struct ListHead test_list_create(const char *items[], bool copy); + +#endif /* TEST_LIST_COMMON_H */ -- 2.40.0