From 0f9844f7f88c201920b9f70b98911f61a730c776 Mon Sep 17 00:00:00 2001 From: Richard Russon Date: Wed, 1 May 2019 16:01:24 +0100 Subject: [PATCH] test: move address tests --- test/Makefile.autosetup | 3 +- test/address.c | 115 ----------------------- test/address/common.h | 37 ++++++++ test/address/mutt_addr_for_display.c | 20 ++++ test/address/mutt_addr_mbox_to_udomain.c | 36 +++++++ test/address/mutt_addr_write_single.c | 22 +++++ test/main.c | 1 - 7 files changed, 116 insertions(+), 118 deletions(-) delete mode 100644 test/address.c create mode 100644 test/address/common.h diff --git a/test/Makefile.autosetup b/test/Makefile.autosetup index 510af3b2d..3d03db138 100644 --- a/test/Makefile.autosetup +++ b/test/Makefile.autosetup @@ -1,6 +1,5 @@ TEST_OBJS = test/main.o \ - test/buffer.o \ - test/address.o + test/buffer.o ADDRESS_OBJS = test/address/main.o \ test/address/mutt_addr_append.o \ diff --git a/test/address.c b/test/address.c deleted file mode 100644 index c0acfa18d..000000000 --- a/test/address.c +++ /dev/null @@ -1,115 +0,0 @@ -/** - * @file - * Test code for the Address object - * - * @authors - * Copyright (C) 2018 Simon Symeonidis - * - * @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 . - */ - -#define TEST_NO_MAIN -#include "acutest.h" -#include "address/lib.h" -#include "mutt/memory.h" -#include - -#define TEST_CHECK_STR_EQ(expected, actual) \ - do \ - { \ - if (!TEST_CHECK(strcmp(expected, actual) == 0)) \ - { \ - TEST_MSG("Expected: %s", expected); \ - TEST_MSG("Actual : %s", actual); \ - } \ - } while (false) - -void test_addr_mbox_to_udomain(void) -{ - { /* edge cases */ - char *user = NULL; - char *domain = NULL; - - if (!TEST_CHECK(mutt_addr_mbox_to_udomain("bobnodomain@", &user, &domain) == -1) || - !TEST_CHECK(mutt_addr_mbox_to_udomain("bobnodomain", &user, &domain) == -1) || - !TEST_CHECK(mutt_addr_mbox_to_udomain("@nobobohnoez", &user, &domain) == -1) || - !TEST_CHECK(mutt_addr_mbox_to_udomain("", &user, &domain) == -1)) - { - TEST_MSG("bad return"); - } - } - - { /* common */ - int ret = 0; - const char *str = "bob@bobsdomain"; - - char *user = NULL; - char *domain = NULL; - ret = mutt_addr_mbox_to_udomain(str, &user, &domain); - - if (!TEST_CHECK(ret == 0)) - { - TEST_MSG("bad return"); - TEST_MSG("Expected: %d", 0); - TEST_MSG("Actual : %d", ret); - } - - TEST_CHECK_STR_EQ("bob", user); - TEST_CHECK_STR_EQ("bobsdomain", domain); - - FREE(&user); - FREE(&domain); - } - - { /* integration */ - char buf[256] = { 0 }; - char per[64] = "bobby bob"; - char mbx[64] = "bob@bobsdomain"; - - struct Address addr = { - .personal = per, - .mailbox = mbx, - .group = 0, - .next = NULL, - .is_intl = 0, - .intl_checked = 0, - }; - - mutt_addr_write_single(buf, sizeof(buf), &addr, false); - - const char *expected = "bobby bob "; - - TEST_CHECK_STR_EQ(expected, buf); - } - - { /* integration */ - char per[64] = "bobby bob"; - char mbx[64] = "bob@bobsdomain"; - - struct Address addr = { - .personal = per, - .mailbox = mbx, - .group = 0, - .next = NULL, - .is_intl = 0, - .intl_checked = 0, - }; - - const char *expected = "bob@bobsdomain"; - const char *actual = mutt_addr_for_display(&addr); - - TEST_CHECK_STR_EQ(expected, actual); - } -} diff --git a/test/address/common.h b/test/address/common.h new file mode 100644 index 000000000..1c01e1d44 --- /dev/null +++ b/test/address/common.h @@ -0,0 +1,37 @@ +/** + * @file + * Test code for the Address object + * + * @authors + * Copyright (C) 2018 Simon Symeonidis + * + * @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 . + */ + +#define TEST_NO_MAIN +#include "acutest.h" +#include +#include "mutt/memory.h" +#include "address/lib.h" + +#define TEST_CHECK_STR_EQ(expected, actual) \ + do \ + { \ + if (!TEST_CHECK(strcmp(expected, actual) == 0)) \ + { \ + TEST_MSG("Expected: %s", expected); \ + TEST_MSG("Actual : %s", actual); \ + } \ + } while (false) diff --git a/test/address/mutt_addr_for_display.c b/test/address/mutt_addr_for_display.c index 71004d666..2f8cc7fb6 100644 --- a/test/address/mutt_addr_for_display.c +++ b/test/address/mutt_addr_for_display.c @@ -25,6 +25,7 @@ #include "config.h" #include "mutt/mutt.h" #include "address/lib.h" +#include "common.h" void test_mutt_addr_for_display(void) { @@ -33,4 +34,23 @@ void test_mutt_addr_for_display(void) { TEST_CHECK(!mutt_addr_for_display(NULL)); } + + { /* integration */ + char per[64] = "bobby bob"; + char mbx[64] = "bob@bobsdomain"; + + struct Address addr = { + .personal = per, + .mailbox = mbx, + .group = 0, + .next = NULL, + .is_intl = 0, + .intl_checked = 0, + }; + + const char *expected = "bob@bobsdomain"; + const char *actual = mutt_addr_for_display(&addr); + + TEST_CHECK_STR_EQ(expected, actual); + } } diff --git a/test/address/mutt_addr_mbox_to_udomain.c b/test/address/mutt_addr_mbox_to_udomain.c index eac5b7c7d..d8e1df328 100644 --- a/test/address/mutt_addr_mbox_to_udomain.c +++ b/test/address/mutt_addr_mbox_to_udomain.c @@ -25,6 +25,7 @@ #include "config.h" #include "mutt/mutt.h" #include "address/lib.h" +#include "common.h" void test_mutt_addr_mbox_to_udomain(void) { @@ -45,4 +46,39 @@ void test_mutt_addr_mbox_to_udomain(void) char *user = NULL; TEST_CHECK(mutt_addr_mbox_to_udomain("apple", &user, NULL) == -1); } + + { /* edge cases */ + char *user = NULL; + char *domain = NULL; + + if (!TEST_CHECK(mutt_addr_mbox_to_udomain("bobnodomain@", &user, &domain) == -1) || + !TEST_CHECK(mutt_addr_mbox_to_udomain("bobnodomain", &user, &domain) == -1) || + !TEST_CHECK(mutt_addr_mbox_to_udomain("@nobobohnoez", &user, &domain) == -1) || + !TEST_CHECK(mutt_addr_mbox_to_udomain("", &user, &domain) == -1)) + { + TEST_MSG("bad return"); + } + } + + { /* common */ + int ret = 0; + const char *str = "bob@bobsdomain"; + + char *user = NULL; + char *domain = NULL; + ret = mutt_addr_mbox_to_udomain(str, &user, &domain); + + if (!TEST_CHECK(ret == 0)) + { + TEST_MSG("bad return"); + TEST_MSG("Expected: %d", 0); + TEST_MSG("Actual : %d", ret); + } + + TEST_CHECK_STR_EQ("bob", user); + TEST_CHECK_STR_EQ("bobsdomain", domain); + + FREE(&user); + FREE(&domain); + } } diff --git a/test/address/mutt_addr_write_single.c b/test/address/mutt_addr_write_single.c index 09cc0a0f7..af90391ca 100644 --- a/test/address/mutt_addr_write_single.c +++ b/test/address/mutt_addr_write_single.c @@ -25,6 +25,7 @@ #include "config.h" #include "mutt/mutt.h" #include "address/lib.h" +#include "common.h" void test_mutt_addr_write_single(void) { @@ -41,4 +42,25 @@ void test_mutt_addr_write_single(void) mutt_addr_write_single(buf, sizeof(buf), NULL, false); TEST_CHECK_(1, "mutt_addr_write_single(buf, sizeof(buf), NULL, false)"); } + + { /* integration */ + char buf[256] = { 0 }; + char per[64] = "bobby bob"; + char mbx[64] = "bob@bobsdomain"; + + struct Address addr = { + .personal = per, + .mailbox = mbx, + .group = 0, + .next = NULL, + .is_intl = 0, + .intl_checked = 0, + }; + + mutt_addr_write_single(buf, sizeof(buf), &addr, false); + + const char *expected = "bobby bob "; + + TEST_CHECK_STR_EQ(expected, buf); + } } diff --git a/test/main.c b/test/main.c index 43209aaa6..d5ba2eec7 100644 --- a/test/main.c +++ b/test/main.c @@ -26,7 +26,6 @@ * Add your test cases to this list. *****************************************************************************/ #define NEOMUTT_TEST_LIST \ - NEOMUTT_TEST_ITEM(test_addr_mbox_to_udomain) \ NEOMUTT_TEST_ITEM(test_mutt_buffer_concat_path) \ /****************************************************************************** -- 2.40.0