diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2021-09-29 21:13:20 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2021-09-29 21:13:20 +0100 |
commit | 72450991eeb435a5bc1fa74da31fc862bb431e4a (patch) | |
tree | 9d1a57ca0d454b86b384739149cced7c5fe7a467 /src/libmime/mime_string.cxx | |
parent | 63a6ecd9e685f87b1366e164a9a681005ae439a5 (diff) | |
download | rspamd-72450991eeb435a5bc1fa74da31fc862bb431e4a.tar.gz rspamd-72450991eeb435a5bc1fa74da31fc862bb431e4a.zip |
[Project] Add constant iterators
Diffstat (limited to 'src/libmime/mime_string.cxx')
-rw-r--r-- | src/libmime/mime_string.cxx | 38 |
1 files changed, 27 insertions, 11 deletions
diff --git a/src/libmime/mime_string.cxx b/src/libmime/mime_string.cxx index 1785e9188..96f829574 100644 --- a/src/libmime/mime_string.cxx +++ b/src/libmime/mime_string.cxx @@ -20,34 +20,35 @@ #include "unicode/uchar.h" TEST_SUITE("mime_string") { +using namespace rspamd::mime; TEST_CASE("mime_string unfiltered ctors") { SUBCASE("empty") { - rspamd::mime_string st; + mime_string st; CHECK(st.size() == 0); CHECK(st == ""); } SUBCASE("unfiltered valid") { - rspamd::mime_string st{std::string_view("abcd")}; + mime_string st{std::string_view("abcd")}; CHECK(st == "abcd"); } SUBCASE("unfiltered zero character") { - rspamd::mime_string st{"abc\0d", 5}; + mime_string st{"abc\0d", 5}; CHECK(st.has_zeroes()); CHECK(st == "abcd"); } SUBCASE("unfiltered invalid character - middle") { - rspamd::mime_string st{std::string("abc\234d")}; + mime_string st{std::string("abc\234d")}; CHECK(st.has_invalid()); CHECK(st == "abc\uFFFDd"); } SUBCASE("unfiltered invalid character - end") { - rspamd::mime_string st{std::string("abc\234")}; + mime_string st{std::string("abc\234")}; CHECK(st.has_invalid()); CHECK(st == "abc\uFFFD"); } SUBCASE("unfiltered invalid character - start") { - rspamd::mime_string st{std::string("\234abc")}; + mime_string st{std::string("\234abc")}; CHECK(st.has_invalid()); CHECK(st == "\uFFFDabc"); } @@ -68,32 +69,47 @@ TEST_CASE("mime_string filtered ctors") }; SUBCASE("empty") { - rspamd::mime_string st{std::string_view(""), tolower_filter}; + mime_string st{std::string_view(""), tolower_filter}; CHECK(st.size() == 0); CHECK(st == ""); } SUBCASE("filtered valid") { - rspamd::mime_string st{std::string("AbCdУ"), tolower_filter}; + mime_string st{std::string("AbCdУ"), tolower_filter}; CHECK(st == "abcdу"); } SUBCASE("filtered invalid + filtered") { - rspamd::mime_string st{std::string("abcd\234\1"), print_filter}; + mime_string st{std::string("abcd\234\1"), print_filter}; CHECK(st == "abcd\uFFFD"); } } TEST_CASE("mime_string assign") { SUBCASE("assign from valid") { - rspamd::mime_string st; + mime_string st; CHECK(st.assign_if_valid(std::string("test"))); CHECK(st == "test"); } SUBCASE("assign from invalid") { - rspamd::mime_string st; + mime_string st; CHECK(!st.assign_if_valid(std::string("test\234t"))); CHECK(st == ""); } } + +TEST_CASE("mime_string iterators") +{ + + SUBCASE("unfiltered iterator ascii") { + auto in = std::string("abcd"); + mime_string st{in}; + CHECK(st == "abcd"); + + int i = 0; + for (auto &&c : st) { + CHECK(c == in[i++]); + } + } +} }
\ No newline at end of file |