1 /**
2 * @file
3 * Test code for rfc2047_decode()
4 *
5 * @authors
6 * Copyright (C) 2019 Richard Russon <rich@flatcap.org>
7 *
8 * @copyright
9 * This program is free software: you can redistribute it and/or modify it under
10 * the terms of the GNU General Public License as published by the Free Software
11 * Foundation, either version 2 of the License, or (at your option) any later
12 * version.
13 *
14 * This program is distributed in the hope that it will be useful, but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
17 * details.
18 *
19 * You should have received a copy of the GNU General Public License along with
20 * this program. If not, see <http://www.gnu.org/licenses/>.
21 */
22
23 #define TEST_NO_MAIN
24 #include "config.h"
25 #include "acutest.h"
26 #include "mutt/lib.h"
27 #include "address/lib.h"
28 #include "config/lib.h"
29 #include "email/lib.h"
30 #include "core/lib.h"
31 #include "common.h"
32 #include "test_common.h"
33
34 static struct ConfigDef Vars[] = {
35 // clang-format off
36 { "assumed_charset", DT_STRING, 0, 0, NULL, },
37 { "charset", DT_STRING|DT_NOT_EMPTY|DT_CHARSET_SINGLE, IP "utf-8", 0, NULL, },
38 { NULL },
39 // clang-format on
40 };
41
test_rfc2047_decode(void)42 void test_rfc2047_decode(void)
43 {
44 // void rfc2047_decode(char **pd);
45
46 NeoMutt = test_neomutt_create();
47 TEST_CHECK(cs_register_variables(NeoMutt->sub->cs, Vars, 0));
48
49 {
50 rfc2047_decode(NULL);
51 TEST_CHECK_(1, "rfc2047_decode(NULL)");
52 }
53
54 {
55 char *pd = NULL;
56 rfc2047_decode(&pd);
57 TEST_CHECK_(1, "rfc2047_decode(&pd)");
58 }
59
60 {
61 for (size_t i = 0; rfc2047_test_data[i].original; i++)
62 {
63 /* decode the original string */
64 char *s = mutt_str_dup(rfc2047_test_data[i].original);
65 rfc2047_decode(&s);
66 if (!TEST_CHECK(strcmp(s, rfc2047_test_data[i].decoded) == 0))
67 {
68 TEST_MSG("Iteration: %zu", i);
69 TEST_MSG("Expected : %s", rfc2047_test_data[i].decoded);
70 TEST_MSG("Actual : %s", s);
71 }
72 FREE(&s);
73
74 /* decode the encoded result */
75 s = mutt_str_dup(rfc2047_test_data[i].encoded);
76 rfc2047_decode(&s);
77 if (!TEST_CHECK(strcmp(s, rfc2047_test_data[i].decoded) == 0))
78 {
79 TEST_MSG("Iteration: %zu", i);
80 TEST_MSG("Expected : %s", rfc2047_test_data[i].decoded);
81 TEST_MSG("Actual : %s", s);
82 }
83 FREE(&s);
84 }
85 }
86
87 test_neomutt_destroy(&NeoMutt);
88 }
89