From 420725bcd0ce4f580e7aa98a0c7a6b3c8ff49e6d Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Sun, 20 Jun 2021 12:24:45 +0100 Subject: [PATCH] [Test] Rework some tests to subcases --- src/libserver/css/css_parser.cxx | 18 +++++++++++------- src/libserver/css/css_value.cxx | 12 +++++++----- src/libserver/html/html_entities.cxx | 2 +- test/rspamd_cxx_unit_utils.hxx | 12 +++++++----- 4 files changed, 26 insertions(+), 18 deletions(-) diff --git a/src/libserver/css/css_parser.cxx b/src/libserver/css/css_parser.cxx index bac5a72eb..bcff14f75 100644 --- a/src/libserver/css/css_parser.cxx +++ b/src/libserver/css/css_parser.cxx @@ -860,17 +860,21 @@ TEST_SUITE("css") { rspamd_mempool_t *pool = rspamd_mempool_new(rspamd_mempool_suggest_size(), "css", 0); for (const auto &c : cases) { - CHECK(parse_css(pool, c, nullptr).value().get() != nullptr); + SUBCASE((std::string("parse css: ") + c).c_str()) { + CHECK(parse_css(pool, c, nullptr).value().get() != nullptr); + } } /* We now merge all styles together */ - std::shared_ptr merged; - for (const auto &c : cases) { - auto ret = parse_css(pool, c, std::move(merged)); - merged.swap(ret.value()); - } + SUBCASE("merged css parse") { + std::shared_ptr merged; + for (const auto &c : cases) { + auto ret = parse_css(pool, c, std::move(merged)); + merged.swap(ret.value()); + } - CHECK(merged.get() != nullptr); + CHECK(merged.get() != nullptr); + } rspamd_mempool_delete(pool); } diff --git a/src/libserver/css/css_value.cxx b/src/libserver/css/css_value.cxx index 87d6ceb85..6988ea993 100644 --- a/src/libserver/css/css_value.cxx +++ b/src/libserver/css/css_value.cxx @@ -388,11 +388,13 @@ TEST_SUITE("css") { }; for (const auto &p : hex_tests) { - auto col_parsed = css_value::maybe_color_from_hex(p.first); - //CHECK_UNARY(col_parsed); - //CHECK_UNARY(col_parsed.value().to_color()); - auto final_col = col_parsed.value().to_color().value(); - CHECK(final_col == p.second); + SUBCASE((std::string("parse hex color: ") + p.first).c_str()) { + auto col_parsed = css_value::maybe_color_from_hex(p.first); + //CHECK_UNARY(col_parsed); + //CHECK_UNARY(col_parsed.value().to_color()); + auto final_col = col_parsed.value().to_color().value(); + CHECK(final_col == p.second); + } } } TEST_CASE("css colors strings") { diff --git a/src/libserver/html/html_entities.cxx b/src/libserver/html/html_entities.cxx index 1d72574b3..2cc3c11f5 100644 --- a/src/libserver/html/html_entities.cxx +++ b/src/libserver/html/html_entities.cxx @@ -2578,7 +2578,7 @@ TEST_SUITE("html") { }; for (const auto &c : cases) { - SUBCASE(c.first.c_str()) { + SUBCASE(("decode entities: " + c.first).c_str()) { auto *cpy = new char[c.first.size()]; memcpy(cpy, c.first.data(), c.first.size()); auto nlen = decode_html_entitles_inplace(cpy, c.first.size(), true); diff --git a/test/rspamd_cxx_unit_utils.hxx b/test/rspamd_cxx_unit_utils.hxx index f5c532ff5..0cd229a4f 100644 --- a/test/rspamd_cxx_unit_utils.hxx +++ b/test/rspamd_cxx_unit_utils.hxx @@ -42,11 +42,13 @@ TEST_CASE("rspamd_strip_smtp_comments_inplace") { }; for (const auto &c : cases) { - auto *cpy = new char[c.first.size()]; - memcpy(cpy, c.first.data(), c.first.size()); - auto nlen = rspamd_strip_smtp_comments_inplace(cpy, c.first.size()); - CHECK(std::string{cpy,nlen} == c.second); - delete[] cpy; + SUBCASE (("strip comments in " + c.first).c_str()) { + auto *cpy = new char[c.first.size()]; + memcpy(cpy, c.first.data(), c.first.size()); + auto nlen = rspamd_strip_smtp_comments_inplace(cpy, c.first.size()); + CHECK(std::string{cpy, nlen} == c.second); + delete[] cpy; + } } } -- 2.39.5