Browse Source

[Test] Fix unit tests

tags/3.6
Vsevolod Stakhov 1 year ago
parent
commit
0babcc489b
No account linked to committer's email address
2 changed files with 15 additions and 4 deletions
  1. 1
    1
      src/libserver/html/html.hxx
  2. 14
    3
      src/libserver/html/html_tests.cxx

+ 1
- 1
src/libserver/html/html.hxx View File

@@ -127,7 +127,7 @@ private:


auto html_tag_by_name(const std::string_view &name) -> std::optional<tag_id_t>;
auto html_process_input(rspamd_mempool_t *pool,
auto html_process_input(struct rspamd_task *task,
GByteArray *in,
GList **exceptions,
khash_t (rspamd_url_hash) *url_set,

+ 14
- 3
src/libserver/html/html_tests.cxx View File

@@ -16,6 +16,7 @@

#include "config.h"
#include "html.hxx"
#include "libserver/task.h"

#include <vector>
#include <fmt/core.h>
@@ -49,12 +50,15 @@ TEST_CASE("html parsing")
rspamd_url_init(NULL);
auto *pool = rspamd_mempool_new(rspamd_mempool_suggest_size(),
"html", 0);
struct rspamd_task fake_task;
memset(&fake_task, 0, sizeof(fake_task));
fake_task.task_pool = pool;

for (const auto &c : cases) {
SUBCASE((std::string("extract tags from: ") + c.first).c_str()) {
GByteArray *tmp = g_byte_array_sized_new(c.first.size());
g_byte_array_append(tmp, (const guint8 *) c.first.data(), c.first.size());
auto *hc = html_process_input(pool, tmp, nullptr, nullptr, nullptr, true);
auto *hc = html_process_input(&fake_task, tmp, nullptr, nullptr, nullptr, true);
CHECK(hc != nullptr);
auto dump = html_debug_structure(*hc);
CHECK(c.second == dump);
@@ -194,6 +198,9 @@ TEST_CASE("html text extraction")
rspamd_url_init(NULL);
auto *pool = rspamd_mempool_new(rspamd_mempool_suggest_size(),
"html", 0);
struct rspamd_task fake_task;
memset(&fake_task, 0, sizeof(fake_task));
fake_task.task_pool = pool;

auto replace_newlines = [](std::string &str) {
auto start_pos = 0;
@@ -208,7 +215,7 @@ TEST_CASE("html text extraction")
SUBCASE((fmt::format("html extraction case {}", i)).c_str()) {
GByteArray *tmp = g_byte_array_sized_new(c.first.size());
g_byte_array_append(tmp, (const guint8 *) c.first.data(), c.first.size());
auto *hc = html_process_input(pool, tmp, nullptr, nullptr, nullptr, true);
auto *hc = html_process_input(&fake_task, tmp, nullptr, nullptr, nullptr, true);
CHECK(hc != nullptr);
replace_newlines(hc->parsed);
auto expected = c.second;
@@ -241,6 +248,10 @@ TEST_CASE("html urls extraction")
rspamd_url_init(NULL);
auto *pool = rspamd_mempool_new(rspamd_mempool_suggest_size(),
"html", 0);
struct rspamd_task fake_task;
memset(&fake_task, 0, sizeof(fake_task));
fake_task.task_pool = pool;

auto i = 1;
for (const auto &c : cases) {
SUBCASE((fmt::format("html url extraction case {}", i)).c_str()) {
@@ -248,7 +259,7 @@ TEST_CASE("html urls extraction")
auto input = std::get<0>(c);
GByteArray *tmp = g_byte_array_sized_new(input.size());
g_byte_array_append(tmp, (const guint8 *)input.data(), input.size());
auto *hc = html_process_input(pool, tmp, nullptr, nullptr, purls, true);
auto *hc = html_process_input(&fake_task, tmp, nullptr, nullptr, purls, true);
CHECK(hc != nullptr);
auto &expected_text = std::get<2>(c);
if (expected_text.has_value()) {

Loading…
Cancel
Save