diff options
author | Vsevolod Stakhov <vsevolod@rspamd.com> | 2024-11-18 16:37:39 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@rspamd.com> | 2024-11-18 16:37:39 +0000 |
commit | 16f5221d71b3a25412412fc353a9d0a660783c7e (patch) | |
tree | 31a75479c72f6e2a93ceb0c2d0410478b61aa78e | |
parent | f286abaac361de836a276172ce9e46e4c058b75d (diff) | |
download | rspamd-16f5221d71b3a25412412fc353a9d0a660783c7e.tar.gz rspamd-16f5221d71b3a25412412fc353a9d0a660783c7e.zip |
[Test] Rework tests structure
-rw-r--r-- | test/rspamd_cxx_unit_rfc2047.hxx | 30 |
1 files changed, 24 insertions, 6 deletions
diff --git a/test/rspamd_cxx_unit_rfc2047.hxx b/test/rspamd_cxx_unit_rfc2047.hxx index 25afd15d5..cdd37d882 100644 --- a/test/rspamd_cxx_unit_rfc2047.hxx +++ b/test/rspamd_cxx_unit_rfc2047.hxx @@ -21,6 +21,7 @@ #include "doctest/doctest.h" #include <string> +#include <vector> #include "libutil/mem_pool.h" #include "libmime/mime_headers.h" @@ -28,12 +29,29 @@ TEST_SUITE("rfc2047 encode") { TEST_CASE("rspamd_mime_header_encode handles ASCII-only input") { - const char *input = "Hello World"; - char *output_cstr = rspamd_mime_header_encode(input, strlen(input), false); - std::string output(output_cstr); - std::string expected_output = "Hello World"; - CHECK(output == expected_output); - g_free(output_cstr); + rspamd_mempool_t *pool = rspamd_mempool_new(rspamd_mempool_suggest_size(), "rfc2047", 0); + std::vector<std::pair<std::string, std::string>> cases = { + {"Hello World", "Hello World"}, + {"Hello Мир", "Hello =?UTF-8?Q?=D0=9C=D0=B8=D1=80?="}}; + + for (const auto &c: cases) { + SUBCASE(c.first.c_str()) + { + gboolean invalid_utf = FALSE; + const char *input = c.first.c_str(); + char *output_cstr = rspamd_mime_header_encode(input, strlen(input), false); + std::string output(output_cstr); + std::string expected_output = c.second; + CHECK(output == expected_output); + char *decoded_cstr = rspamd_mime_header_decode(pool, output_cstr, strlen(output_cstr), &invalid_utf); + std::string decoded(decoded_cstr); + CHECK(invalid_utf == FALSE); + CHECK(decoded == input); + g_free(output_cstr); + } + } + + rspamd_mempool_delete(pool); } TEST_CASE("rspamd_mime_header_encode handles input with non-ASCII characters") |