From 8095872bbcdfe59504fc91178858bfdc353d90f9 Mon Sep 17 00:00:00 2001 From: Pietro Cerutti Date: Sat, 18 May 2019 17:07:30 +0000 Subject: [PATCH] Add tests for mutt_addrlist_copy --- test/address/mutt_addrlist_copy.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/test/address/mutt_addrlist_copy.c b/test/address/mutt_addrlist_copy.c index f5f1f423b..4a9b3875e 100644 --- a/test/address/mutt_addrlist_copy.c +++ b/test/address/mutt_addrlist_copy.c @@ -22,6 +22,7 @@ #define TEST_NO_MAIN #include "acutest.h" +#include "common.h" #include "config.h" #include "mutt/mutt.h" #include "address/lib.h" @@ -41,4 +42,33 @@ void test_mutt_addrlist_copy(void) mutt_addrlist_copy(&al, NULL, false); TEST_CHECK_(1, "mutt_addrlist_copy(&al, NULL, false)"); } + + { + struct AddressList src = TAILQ_HEAD_INITIALIZER(src); + struct AddressList dst = TAILQ_HEAD_INITIALIZER(dst); + mutt_addrlist_copy(&dst, &src, false); + TEST_CHECK(TAILQ_EMPTY(&src)); + TEST_CHECK(TAILQ_EMPTY(&dst)); + } + + { + struct AddressList src = TAILQ_HEAD_INITIALIZER(src); + struct AddressList dst = TAILQ_HEAD_INITIALIZER(dst); + struct Address a1 = { .mailbox = "test@example.com" }; + struct Address a2 = { .mailbox = "john@doe.org" }; + struct Address a3 = { .mailbox = "the-who@stage.co.uk" }; + mutt_addrlist_append(&src, &a1); + mutt_addrlist_append(&src, &a2); + mutt_addrlist_append(&src, &a3); + mutt_addrlist_copy(&dst, &src, false); + TEST_CHECK(!TAILQ_EMPTY(&src)); + TEST_CHECK(!TAILQ_EMPTY(&dst)); + struct Address *adst = TAILQ_FIRST(&dst); + TEST_CHECK_STR_EQ(a1.mailbox, adst->mailbox); + adst = TAILQ_NEXT(adst, entries); + TEST_CHECK_STR_EQ(a2.mailbox, adst->mailbox); + adst = TAILQ_NEXT(adst, entries); + TEST_CHECK_STR_EQ(a3.mailbox, adst->mailbox); + mutt_addrlist_free_all(&dst); + } } -- 2.40.0