*/
void rfc2047_encode(char **pd, const char *specials, int col, const char *charsets)
{
- if (!C_Charset || !*pd)
+ if (!C_Charset || !pd || !*pd)
return;
if (!charsets || !*charsets)
TEST_OBJS = test/main.o \
test/buffer.o \
test/md5.o \
- test/rfc2047.o \
test/address.o \
test/url.o
test/regex/mutt_replacelist_remove.o
RFC2047_OBJS = test/rfc2047/main.o \
+ test/rfc2047/common.o \
test/rfc2047/rfc2047_decode_addrlist.o \
test/rfc2047/rfc2047_decode.o \
test/rfc2047/rfc2047_decode_envelope.o \
* Add your test cases to this list.
*****************************************************************************/
#define NEOMUTT_TEST_LIST \
- NEOMUTT_TEST_ITEM(test_rfc2047) \
NEOMUTT_TEST_ITEM(test_md5) \
NEOMUTT_TEST_ITEM(test_md5_ctx) \
NEOMUTT_TEST_ITEM(test_md5_ctx_bytes) \
/**
* @file
- * Test code for RFC2047 Encoding
+ * Common code for RFC2047 tests
*
* @authors
* Copyright (C) 2018 Pietro Cerutti <gahr@gahr.ch>
#define TEST_NO_MAIN
#include "acutest.h"
-
-#include "mutt/charset.h"
-#include "mutt/memory.h"
-#include "mutt/string2.h"
-#include "email/rfc2047.h"
-
+#include "config.h"
#include <locale.h>
+#include "mutt/mutt.h"
+#include "email/lib.h"
+#include "common.h"
-static const struct
-{
- const char *original; /* the string as received in the original email */
- const char *decoded; /* the expected plain-text string */
- const char *encoded; /* the string as it's encoded by NeoMutt */
-} test_data[] =
- /* clang-format off */
+// clang-format off
+const struct Rfc2047TestData test_data[] =
{
{
/* The string is split in the middle of a multi-byte sequence */
"=?UTF-8?Q?Sicherheitsl=C3=BCcke in praktisch allen IT-Systemen?="
, "Sicherheitslücke in praktisch allen IT-Systemen"
, "=?utf-8?Q?Sicherheitsl=C3=BCcke?= in praktisch allen IT-Systemen"
- }
+ },
+ { NULL, NULL, NULL },
};
-/* clang-format on */
-
-void test_rfc2047(void)
-{
- if (!TEST_CHECK((setlocale(LC_ALL, "en_US.UTF-8") != NULL) ||
- (setlocale(LC_ALL, "C.UTF-8") != NULL)))
- {
- TEST_MSG("Cannot set locale to (en_US|C).UTF-8");
- return;
- }
-
- C_Charset = "utf-8";
-
- for (size_t i = 0; i < mutt_array_size(test_data); ++i)
- {
- /* decode the original string */
- char *s = mutt_str_strdup(test_data[i].original);
- rfc2047_decode(&s);
- if (!TEST_CHECK(strcmp(s, test_data[i].decoded) == 0))
- {
- TEST_MSG("Iteration: %zu", i);
- TEST_MSG("Expected : %s", test_data[i].decoded);
- TEST_MSG("Actual : %s", s);
- }
- FREE(&s);
-
- /* encode the expected result */
- s = mutt_str_strdup(test_data[i].decoded);
- rfc2047_encode(&s, NULL, 0, "utf-8");
- if (!TEST_CHECK(strcmp(s, test_data[i].encoded) == 0))
- {
- TEST_MSG("Iteration: %zu", i);
- TEST_MSG("Expected : %s", test_data[i].encoded);
- TEST_MSG("Actual : %s", s);
- }
- FREE(&s);
+// clang-format on
- /* decode the encoded result */
- s = mutt_str_strdup(test_data[i].encoded);
- rfc2047_decode(&s);
- if (!TEST_CHECK(strcmp(s, test_data[i].decoded) == 0))
- {
- TEST_MSG("Iteration: %zu", i);
- TEST_MSG("Expected : %s", test_data[i].decoded);
- TEST_MSG("Actual : %s", s);
- }
- FREE(&s);
- }
-}
--- /dev/null
+/**
+ * @file
+ * Common code for RFC2047 tests
+ *
+ * @authors
+ * Copyright (C) 2018 Pietro Cerutti <gahr@gahr.ch>
+ *
+ * @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 <http://www.gnu.org/licenses/>.
+ */
+
+#define TEST_NO_MAIN
+#include "acutest.h"
+#include <locale.h>
+#include "mutt/mutt.h"
+#include "email/lib.h"
+
+struct Rfc2047TestData
+{
+ const char *original; // the string as received in the original email
+ const char *decoded; // the expected plain-text string
+ const char *encoded; // the string as it's encoded by NeoMutt
+};
+
+extern const struct Rfc2047TestData test_data[];
+
#include "mutt/mutt.h"
#include "email/lib.h"
#include "address/lib.h"
+#include "common.h"
void test_rfc2047_decode(void)
{
// void rfc2047_decode(char **pd);
+ if (!TEST_CHECK((setlocale(LC_ALL, "en_US.UTF-8") != NULL) ||
+ (setlocale(LC_ALL, "C.UTF-8") != NULL)))
+ {
+ TEST_MSG("Cannot set locale to (en_US|C).UTF-8");
+ return;
+ }
+
+ C_Charset = "utf-8";
+
{
rfc2047_decode(NULL);
TEST_CHECK_(1, "rfc2047_decode(NULL)");
rfc2047_decode(&pd);
TEST_CHECK_(1, "rfc2047_decode(&pd)");
}
+
+ {
+ for (size_t i = 0; test_data[i].original; i++)
+ {
+ /* decode the original string */
+ char *s = mutt_str_strdup(test_data[i].original);
+ rfc2047_decode(&s);
+ if (!TEST_CHECK(strcmp(s, test_data[i].decoded) == 0))
+ {
+ TEST_MSG("Iteration: %zu", i);
+ TEST_MSG("Expected : %s", test_data[i].decoded);
+ TEST_MSG("Actual : %s", s);
+ }
+ FREE(&s);
+
+ /* decode the encoded result */
+ s = mutt_str_strdup(test_data[i].encoded);
+ rfc2047_decode(&s);
+ if (!TEST_CHECK(strcmp(s, test_data[i].decoded) == 0))
+ {
+ TEST_MSG("Iteration: %zu", i);
+ TEST_MSG("Expected : %s", test_data[i].decoded);
+ TEST_MSG("Actual : %s", s);
+ }
+ FREE(&s);
+ }
+ }
}
#include "mutt/mutt.h"
#include "email/lib.h"
#include "address/lib.h"
+#include "common.h"
void test_rfc2047_encode(void)
{
// void rfc2047_encode(char **pd, const char *specials, int col, const char *charsets);
+ if (!TEST_CHECK((setlocale(LC_ALL, "en_US.UTF-8") != NULL) ||
+ (setlocale(LC_ALL, "C.UTF-8") != NULL)))
+ {
+ TEST_MSG("Cannot set locale to (en_US|C).UTF-8");
+ return;
+ }
+
+ C_Charset = "utf-8";
+
{
rfc2047_encode(NULL, AddressSpecials, 0, "apple");
TEST_CHECK_(1, "rfc2047_encode(NULL, AddressSpecials, 0, \"apple\")");
rfc2047_encode(&pd, AddressSpecials, 0, NULL);
TEST_CHECK_(1, "rfc2047_encode(&pd, AddressSpecials, 0, NULL)");
}
+
+ {
+ for (size_t i = 0; test_data[i].decoded; i++)
+ {
+ /* encode the expected result */
+ char *s = mutt_str_strdup(test_data[i].decoded);
+ rfc2047_encode(&s, NULL, 0, "utf-8");
+ if (!TEST_CHECK(strcmp(s, test_data[i].encoded) == 0))
+ {
+ TEST_MSG("Iteration: %zu", i);
+ TEST_MSG("Expected : %s", test_data[i].encoded);
+ TEST_MSG("Actual : %s", s);
+ }
+ FREE(&s);
+ }
+ }
}