1 /**
2 * @file
3 * Test code for mutt_addr_write()
4 *
5 * @authors
6 * Copyright (C) 2019 Richard Russon <rich@flatcap.org>
7 * Copyright (C) 2019 Pietro Cerutti <gahr@gahr.ch>
8 *
9 * @copyright
10 * This program is free software: you can redistribute it and/or modify it under
11 * the terms of the GNU General Public License as published by the Free Software
12 * Foundation, either version 2 of the License, or (at your option) any later
13 * version.
14 *
15 * This program is distributed in the hope that it will be useful, but WITHOUT
16 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
18 * details.
19 *
20 * You should have received a copy of the GNU General Public License along with
21 * this program. If not, see <http://www.gnu.org/licenses/>.
22 */
23
24 #define TEST_NO_MAIN
25 #include "config.h"
26 #include "acutest.h"
27 #include "mutt/lib.h"
28 #include "address/lib.h"
29 #include "test_common.h"
30
test_mutt_addr_write(void)31 void test_mutt_addr_write(void)
32 {
33 // size_t mutt_addr_write(char *buf, size_t buflen, struct Address *addr, bool display);
34
35 {
36 struct Address addr = { 0 };
37 mutt_addr_write(NULL, 32, &addr, false);
38 TEST_CHECK_(1, "mutt_addr_write(NULL, 32, &addr, false)");
39 }
40
41 {
42 char buf[32] = { 0 };
43 mutt_addr_write(buf, sizeof(buf), NULL, false);
44 TEST_CHECK_(1, "mutt_addr_write(buf, sizeof(buf), NULL, false)");
45 }
46
47 { /* integration */
48 char buf[256] = { 0 };
49 char per[64] = "bobby bob";
50 char mbx[64] = "bob@bobsdomain";
51
52 struct Address addr = {
53 .personal = per,
54 .mailbox = mbx,
55 .group = 0,
56 .is_intl = 0,
57 .intl_checked = 0,
58 };
59
60 size_t len = mutt_addr_write(buf, sizeof(buf), &addr, false);
61
62 const char *expected = "bobby bob <bob@bobsdomain>";
63
64 TEST_CHECK_STR_EQ(expected, buf);
65 TEST_CHECK(len == strlen(expected));
66 }
67 }
68