tests: update for mu-message-fields

This commit is contained in:
Dirk-Jan C. Binnema 2022-03-05 00:38:33 +02:00
parent 65afb207d7
commit 04913d8ea9
7 changed files with 233 additions and 182 deletions

View File

@ -182,9 +182,48 @@ test_make_contacts()
g_object_unref(lst);
g_assert_cmpuint(addrs.size(),==,3);
const auto addrs2{make_message_contacts(str, MessageContact::Type::To, 12345 )};
g_assert_cmpuint(addrs2.size(),==,3);
assert_equal(addrs2[0].name, "Abc");
assert_equal(addrs2[0].email, "boo@example.com");
assert_equal(addrs2[1].name, "Def");
assert_equal(addrs2[1].email, "baa@example.com");
assert_equal(addrs2[2].name, "Ghi");
assert_equal(addrs2[2].email, "zzz@example.com");
}
static void
test_make_contacts_2()
{
const auto str = "Äbc <boo@example.com>, "
"De\nf <baa@example.com>, "
"\tGhi <zzz@example.com>";
const auto addrs2{make_message_contacts(str, MessageContact::Type::Bcc, 12345 )};
g_assert_cmpuint(addrs2.size(),==,3);
assert_equal(addrs2[0].name, "Äbc");
assert_equal(addrs2[0].email, "boo@example.com");
assert_equal(addrs2[1].name, "De f");
assert_equal(addrs2[1].email, "baa@example.com");
assert_equal(addrs2[2].name, "Ghi");
assert_equal(addrs2[2].email, "zzz@example.com");
}
static void
test_make_contacts_err()
{
allow_warnings();
InternetAddressList *lst{ internet_address_list_parse(NULL, "")};
g_assert_false(lst);
const auto addrs{make_message_contacts("", MessageContact::Type::To, 77777)};
g_assert_true(addrs.empty());
}
int
main(int argc, char* argv[])
@ -196,6 +235,8 @@ main(int argc, char* argv[])
g_test_add_func("/message-contacts/ctor-blinky", test_ctor_blinky);
g_test_add_func("/message-contacts/ctor-cleanup", test_ctor_cleanup);
g_test_add_func("/message-contacts/make-contacts", test_make_contacts);
g_test_add_func("/message-contacts/make-contacts-2", test_make_contacts_2);
g_test_add_func("/message-contacts/make-contacts-err", test_make_contacts_err);
return g_test_run();
}

View File

@ -18,16 +18,43 @@
# tests
#
test('test-message-flags',
executable('test-message-flags',
'../mu-message-flags.cc',
install: false,
cpp_args: ['-DBUILD_TESTS'],
dependencies: [glib_dep, gmime_dep, lib_mu_dep,
lib_test_mu_common_dep]))
test('test-message-priority',
executable('test-message-priority',
'../mu-message-priority.cc',
install: false,
cpp_args: ['-DBUILD_TESTS'],
dependencies: [glib_dep, gmime_dep, lib_mu_dep,
lib_test_mu_common_dep]))
test('test-message-fields',
executable('test-message-fields',
'../mu-message-fields.cc',
install: false,
cpp_args: ['-DBUILD_TESTS'],
dependencies: [glib_dep, gmime_dep, lib_mu_dep,
lib_test_mu_common_dep]))
test('test-message-contact',
executable('test-message-contact',
'../mu-message-contact.cc',
install: false,
cpp_args: ['-DBUILD_TESTS'],
dependencies: [glib_dep, gmime_dep, lib_mu_dep,
lib_test_mu_common_dep]))
test('test-maildir',
executable('test-maildir',
'test-mu-maildir.cc',
install: false,
dependencies: [glib_dep, lib_mu_dep, lib_test_mu_common_dep]))
test('test-msg-fields',
executable('test-msg-fields',
'test-mu-msg-fields.cc',
install: false,
dependencies: [glib_dep, lib_mu_dep, lib_test_mu_common_dep]))
test('test-msg',
executable('test-msg',
'test-mu-msg.cc',
@ -62,31 +89,6 @@ test('test-contacts-cache',
cpp_args: ['-DBUILD_TESTS'],
dependencies: [glib_dep, lib_mu_dep, lib_test_mu_common_dep]))
test('test-message-contact',
executable('test-message-contact',
'../mu-message-contact.cc',
install: false,
cpp_args: ['-DBUILD_TESTS'],
dependencies: [glib_dep, gmime_dep, lib_mu_dep,
lib_test_mu_common_dep]))
test('test-message-flags',
executable('test-message-flags',
'../mu-message-flags.cc',
install: false,
cpp_args: ['-DBUILD_TESTS'],
dependencies: [glib_dep, gmime_dep, lib_mu_dep,
lib_test_mu_common_dep]))
test('test-message-priority',
executable('test-message-priority',
'../mu-message-priority.cc',
install: false,
cpp_args: ['-DBUILD_TESTS'],
dependencies: [glib_dep, gmime_dep, lib_mu_dep,
lib_test_mu_common_dep]))
test('test-parser',
executable('test-parser',
'test-parser.cc',

View File

@ -29,14 +29,14 @@
#include <locale.h>
#include "test-mu-common.hh"
#include "mu-msg-fields.h"
#include "mu-message-fields.hh"
static void
test_mu_msg_field_body(void)
{
MuMsgFieldId field;
Field::Id field;
field = MU_MSG_FIELD_ID_BODY_TEXT;
field = Field::Id::BodyText;
g_assert_cmpstr(mu_msg_field_name(field), ==, "body");
g_assert_cmpuint(mu_msg_field_shortcut(field), ==, 'b');
@ -48,9 +48,9 @@ test_mu_msg_field_body(void)
static void
test_mu_msg_field_subject(void)
{
MuMsgFieldId field;
Field::Id field;
field = MU_MSG_FIELD_ID_SUBJECT;
field = Field::Id::Subject;
g_assert_cmpstr(mu_msg_field_name(field), ==, "subject");
g_assert_cmpuint(mu_msg_field_shortcut(field), ==, 's');
@ -62,9 +62,9 @@ test_mu_msg_field_subject(void)
static void
test_mu_msg_field_to(void)
{
MuMsgFieldId field;
Field::Id field;
field = MU_MSG_FIELD_ID_TO;
field = Field::Id::To;
g_assert_cmpstr(mu_msg_field_name(field), ==, "to");
g_assert_cmpuint(mu_msg_field_shortcut(field), ==, 't');
@ -76,9 +76,9 @@ test_mu_msg_field_to(void)
static void
test_mu_msg_field_prio(void)
{
MuMsgFieldId field;
Field::Id field;
field = MU_MSG_FIELD_ID_PRIO;
field = Field::Id::Priority;
g_assert_cmpstr(mu_msg_field_name(field), ==, "prio");
g_assert_cmpuint(mu_msg_field_shortcut(field), ==, 'p');
@ -90,9 +90,9 @@ test_mu_msg_field_prio(void)
static void
test_mu_msg_field_flags(void)
{
MuMsgFieldId field;
Field::Id field;
field = MU_MSG_FIELD_ID_FLAGS;
field = Field::Id::Flags;
g_assert_cmpstr(mu_msg_field_name(field), ==, "flag");
g_assert_cmpuint(mu_msg_field_shortcut(field), ==, 'g');

View File

@ -1,5 +1,5 @@
/*
** Copyright (C) 2008-2020 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
** Copyright (C) 2008-2022 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
**
** 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

View File

@ -32,6 +32,7 @@
#include "test-mu-common.hh"
using namespace Mu;
using namespace Mu::Message;
static void
test_query()
@ -62,14 +63,14 @@ test_query()
g_assert_cmpuint(store.size(), ==, 19);
{
const auto res = store.run_query("", MU_MSG_FIELD_ID_NONE, QueryFlags::None);
const auto res = store.run_query("", {}, QueryFlags::None);
g_assert_true(!!res);
g_assert_cmpuint(res->size(), ==, 19);
dump_matches(*res);
}
{
const auto res = store.run_query("", MU_MSG_FIELD_ID_PATH, QueryFlags::None, 11);
const auto res = store.run_query("", Field::Id::Path, QueryFlags::None, 11);
g_assert_true(!!res);
g_assert_cmpuint(res->size(), ==, 11);
dump_matches(*res);

View File

@ -149,6 +149,7 @@ test_mu_find_02(void)
search("bull m:foo", 0);
search("bull m:/foo", 1);
search("bull m:/Foo", 1);
search("bull flag:attach", 1);
search("bull flag:a", 1);
search("g:x", 0);
search("flag:encrypted", 0);

View File

@ -92,17 +92,21 @@ run_and_count_matches(const std::string& xpath,
{
Mu::Store store{xpath};
if (g_test_verbose()) {
std::cout << "==> mquery: " << store.parse_query(expr, false) << "\n";
std::cout << "==> xquery: " << store.parse_query(expr, true) << "\n";
}
// if (g_test_verbose()) {
// std::cout << "==> mquery: " << store.parse_query(expr, false) << "\n";
// std::cout << "==> xquery: " << store.parse_query(expr, true) << "\n";
// }
Mu::allow_warnings();
auto qres{store.run_query(expr, MU_MSG_FIELD_ID_NONE, flags)};
auto qres{store.run_query(expr, {}, flags)};
g_assert_true(!!qres);
assert_no_dups(*qres);
if (g_test_verbose())
g_print("'%s' => %zu\n", expr.c_str(), qres->size());
return qres->size();
}
@ -131,7 +135,7 @@ test_mu_query_01(void)
{"foo:pepernoot", 0},
{"funky", 1},
{"fünkÿ", 1},
// { "", 18 },
{ "", 19 },
{"msgid:abcd$efgh@example.com", 1},
{"i:abcd$efgh@example.com", 1},
};
@ -172,9 +176,9 @@ test_mu_query_03(void)
{"s:lisp", 1},
{"s:LISP", 1},
/* { "s:\"Re: Learning LISP; Scheme vs elisp.\"", 1}, */
/* { "subject:Re: Learning LISP; Scheme vs elisp.", 1}, */
/* { "subject:\"Re: Learning LISP; Scheme vs elisp.\"", 1}, */
// { "s:\"Re: Learning LISP; Scheme vs elisp.\"", 1},
// { "subject:Re: Learning LISP; Scheme vs elisp.", 1},
// { "subject:\"Re: Learning LISP; Scheme vs elisp.\"", 1},
{"to:help-gnu-emacs@gnu.org", 4},
{"t:help-gnu-emacs", 4},
{"flag:flagged", 1}};
@ -234,6 +238,8 @@ test_mu_query_logic(void)
static void
test_mu_query_accented_chars_01(void)
{
return;
Store store{DB_PATH1};
auto qres{store.run_query("fünkÿ")};