From af386824f24075c88a02f38bc188dc46fb950fd1 Mon Sep 17 00:00:00 2001 From: "Dirk-Jan C. Binnema" Date: Sun, 20 Dec 2020 15:52:31 +0200 Subject: [PATCH] contacts: remove some dead code --- .gitignore | 13 ++ lib/Makefile.am | 474 ++++++++++++++++++++-------------------- lib/mu-contacts.cc | 107 ++++++--- lib/mu-contacts.hh | 61 ------ lib/test-mu-contacts.cc | 108 --------- 5 files changed, 334 insertions(+), 429 deletions(-) delete mode 100644 lib/test-mu-contacts.cc diff --git a/.gitignore b/.gitignore index e430f93a..0a647293 100644 --- a/.gitignore +++ b/.gitignore @@ -127,3 +127,16 @@ compile_commands.json /lib/test-mu-tokenizer /lib/test-mu-parser /lib/test-mu-query-threader +/lib/test-contacts +/lib/test-flags +/lib/test-maildir +/lib/test-msg +/lib/test-msg-fields +/lib/test-query +/lib/test-store +/lib/test-threader +/mu/test-cmd +/mu/test-cmd-cfind +/mu/test-query +/mu/test-threads +/lib/test-threads diff --git a/lib/Makefile.am b/lib/Makefile.am index 62a1ed42..eee8c694 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -20,170 +20,176 @@ include $(top_srcdir)/gtest.mk SUBDIRS= utils index -TESTDEFS= \ - -DMU_TESTMAILDIR=\"${abs_srcdir}/testdir\" \ - -DMU_TESTMAILDIR2=\"${abs_srcdir}/testdir2\" \ - -DMU_TESTMAILDIR3=\"${abs_srcdir}/testdir3\" \ - -DMU_TESTMAILDIR4=\"${abs_srcdir}/testdir4\" \ - -DABS_CURDIR=\"${abs_builddir}\" \ - -DABS_SRCDIR=\"${abs_srcdir}\" +TESTDEFS= \ + -DMU_TESTMAILDIR=\"${abs_srcdir}/testdir\" \ + -DMU_TESTMAILDIR2=\"${abs_srcdir}/testdir2\" \ + -DMU_TESTMAILDIR3=\"${abs_srcdir}/testdir3\" \ + -DMU_TESTMAILDIR4=\"${abs_srcdir}/testdir4\" \ + -DABS_CURDIR=\"${abs_builddir}\" \ + -DABS_SRCDIR=\"${abs_srcdir}\" -AM_CFLAGS= \ - $(WARN_CFLAGS) \ - $(GMIME_CFLAGS) \ - $(GLIB_CFLAGS) \ - $(GUILE_CFLAGS) \ - $(ASAN_CFLAGS) \ - $(CODE_COVERAGE_CFLAGS) \ - $(TESTDEFS) \ - -Wno-format-nonliteral \ - -Wno-switch-enum \ - -Wno-deprecated-declarations \ - -Wno-inline +AM_CFLAGS= \ + $(WARN_CFLAGS) \ + $(GMIME_CFLAGS) \ + $(GLIB_CFLAGS) \ + $(GUILE_CFLAGS) \ + $(ASAN_CFLAGS) \ + $(CODE_COVERAGE_CFLAGS) \ + $(TESTDEFS) \ + -Wno-format-nonliteral \ + -Wno-switch-enum \ + -Wno-deprecated-declarations \ + -Wno-inline -AM_CXXFLAGS= \ - $(GMIME_CFLAGS) \ - $(GLIB_CFLAGS) \ - $(GUILE_CFLAGS) \ - $(WARN_CXXFLAGS) \ - $(XAPIAN_CXXFLAGS) \ - $(ASAN_CXXFLAGS) \ - $(CODE_COVERAGE_CFLAGS) \ - $(TESTDEFS) +AM_CXXFLAGS= \ + $(GMIME_CFLAGS) \ + $(GLIB_CFLAGS) \ + $(GUILE_CFLAGS) \ + $(WARN_CXXFLAGS) \ + $(XAPIAN_CXXFLAGS) \ + $(ASAN_CXXFLAGS) \ + $(CODE_COVERAGE_CFLAGS) \ + $(TESTDEFS) -AM_CPPFLAGS= \ - $(CODE_COVERAGE_CPPFLAGS) +AM_CPPFLAGS= \ + $(CODE_COVERAGE_CPPFLAGS) -noinst_LTLIBRARIES= \ - libmu.la +noinst_LTLIBRARIES= \ + libmu.la -libmu_la_SOURCES= \ - mu-bookmarks.cc \ - mu-bookmarks.hh \ - mu-contacts.cc \ - mu-contacts.hh \ - mu-data.hh \ - mu-parser.cc \ - mu-parser.hh \ - mu-query.cc \ - mu-query.hh \ - mu-query-results.hh \ - mu-query-match-deciders.cc \ - mu-query-match-deciders.hh \ - mu-query-threader.cc \ - mu-query-threader.hh \ - mu-runtime.cc \ - mu-runtime.hh \ - mu-script.cc \ - mu-script.hh \ - mu-server.cc \ - mu-server.hh \ - mu-store.cc \ - mu-store.hh \ - mu-tokenizer.cc \ - mu-tokenizer.hh \ - mu-tree.hh \ - mu-xapian.cc \ - mu-xapian.hh \ - mu-maildir.cc \ - mu-maildir.hh \ - mu-flags.cc \ - mu-flags.hh \ - mu-msg-crypto.cc \ - mu-msg-doc.cc \ - mu-msg-doc.hh \ - mu-msg-fields.c \ - mu-msg-fields.h \ - mu-msg-file.cc \ - mu-msg-file.hh \ - mu-msg-part.cc \ - mu-msg-part.hh \ - mu-msg-prio.c \ - mu-msg-prio.h \ - mu-msg-priv.hh \ - mu-msg-sexp.cc \ - mu-msg.cc \ - mu-msg.hh +libmu_la_SOURCES= \ + mu-bookmarks.cc \ + mu-bookmarks.hh \ + mu-contacts.cc \ + mu-contacts.hh \ + mu-data.hh \ + mu-parser.cc \ + mu-parser.hh \ + mu-query.cc \ + mu-query.hh \ + mu-query-results.hh \ + mu-query-match-deciders.cc \ + mu-query-match-deciders.hh \ + mu-query-threads.cc \ + mu-query-threads.hh \ + mu-runtime.cc \ + mu-runtime.hh \ + mu-script.cc \ + mu-script.hh \ + mu-server.cc \ + mu-server.hh \ + mu-store.cc \ + mu-store.hh \ + mu-tokenizer.cc \ + mu-tokenizer.hh \ + mu-tree.hh \ + mu-xapian.cc \ + mu-xapian.hh \ + mu-maildir.cc \ + mu-maildir.hh \ + mu-flags.cc \ + mu-flags.hh \ + mu-msg-crypto.cc \ + mu-msg-doc.cc \ + mu-msg-doc.hh \ + mu-msg-fields.c \ + mu-msg-fields.h \ + mu-msg-file.cc \ + mu-msg-file.hh \ + mu-msg-part.cc \ + mu-msg-part.hh \ + mu-msg-prio.c \ + mu-msg-prio.h \ + mu-msg-priv.hh \ + mu-msg-sexp.cc \ + mu-msg.cc \ + mu-msg.hh -libmu_la_LIBADD= \ - $(XAPIAN_LIBS) \ - $(GMIME_LIBS) \ - $(GLIB_LIBS) \ - $(GUILE_LIBS) \ - ${builddir}/index/libmu-index.la \ - $(CODE_COVERAGE_LIBS) +libmu_la_LIBADD= \ + $(XAPIAN_LIBS) \ + $(GMIME_LIBS) \ + $(GLIB_LIBS) \ + $(GUILE_LIBS) \ + ${builddir}/index/libmu-index.la \ + $(CODE_COVERAGE_LIBS) -libmu_la_LDFLAGS= \ - $(ASAN_LDFLAGS) +libmu_la_LDFLAGS= \ + $(ASAN_LDFLAGS) -noinst_PROGRAMS= \ - tokenize +noinst_PROGRAMS= \ + tokenize -tokenize_SOURCES= \ - tokenize.cc +tokenize_SOURCES= \ + tokenize.cc -tokenize_LDADD= \ - $(WARN_LDFLAGS) \ - libmu.la \ - utils/libmu-utils.la +tokenize_LDADD= \ + $(WARN_LDFLAGS) \ + libmu.la \ + utils/libmu-utils.la -EXTRA_DIST= \ - doxyfile.in +EXTRA_DIST= \ + doxyfile.in noinst_PROGRAMS+=$(TEST_PROGS) -noinst_LTLIBRARIES+= \ - libtestmucommon.la +noinst_LTLIBRARIES+= \ + libtestmucommon.la -TEST_PROGS += test-mu-maildir -test_mu_maildir_SOURCES= test-mu-maildir.cc -test_mu_maildir_LDADD= libtestmucommon.la +TEST_PROGS += test-maildir +test_maildir_SOURCES= test-mu-maildir.cc +test_maildir_LDADD= libtestmucommon.la -TEST_PROGS += test-mu-msg-fields -test_mu_msg_fields_SOURCES= test-mu-msg-fields.cc -test_mu_msg_fields_LDADD= libtestmucommon.la +TEST_PROGS += test-msg-fields +test_msg_fields_SOURCES= test-mu-msg-fields.cc +test_msg_fields_LDADD= libtestmucommon.la -TEST_PROGS += test-mu-msg -test_mu_msg_SOURCES= test-mu-msg.cc -test_mu_msg_LDADD= libtestmucommon.la +TEST_PROGS += test-msg +test_msg_SOURCES= test-mu-msg.cc +test_msg_LDADD= libtestmucommon.la -TEST_PROGS += test-mu-store -test_mu_store_SOURCES= test-mu-store.cc -test_mu_store_LDADD= libtestmucommon.la +TEST_PROGS += test-store +test_store_SOURCES= test-mu-store.cc +test_store_LDADD= libtestmucommon.la -TEST_PROGS += test-mu-query -test_mu_query_SOURCES= test-query.cc -test_mu_query_LDADD= libtestmucommon.la +TEST_PROGS += test-query +test_query_SOURCES= test-query.cc +test_query_LDADD= libtestmucommon.la -TEST_PROGS += test-mu-flags -test_mu_flags_SOURCES= test-mu-flags.cc -test_mu_flags_LDADD= libtestmucommon.la +TEST_PROGS += test-flags +test_flags_SOURCES= test-mu-flags.cc +test_flags_LDADD= libtestmucommon.la -TEST_PROGS += test-mu-contacts -test_mu_contacts_SOURCES= test-mu-contacts.cc -test_mu_contacts_LDADD= libtestmucommon.la +TEST_PROGS+=test-tokenizer +test_tokenizer_SOURCES=test-tokenizer.cc +test_tokenizer_LDADD=libtestmucommon.la -TEST_PROGS+=test-mu-tokenizer -test_mu_tokenizer_SOURCES=test-tokenizer.cc -test_mu_tokenizer_LDADD=libtestmucommon.la +TEST_PROGS+=test-threader +test_threader_SOURCES=mu-query-threader.cc +test_threader_LDADD=libtestmucommon.la +test_threader_CXXFLAGS=$(AM_CXXFLAGS) -DBUILD_TESTS -TEST_PROGS+=test-mu-threader -test_mu_threader_SOURCES=mu-query-threader.cc -test_mu_threader_LDADD=libtestmucommon.la -test_mu_threader_CXXFLAGS=$(AM_CXXFLAGS) -DBUILD_THREADER_TEST +TEST_PROGS+=test-threads +test_threads_SOURCES=mu-query-threads.cc +test_threads_LDADD=libtestmucommon.la +test_threads_CXXFLAGS=$(AM_CXXFLAGS) -DBUILD_TESTS -TEST_PROGS+=test-mu-parser -test_mu_parser_SOURCES=test-parser.cc -test_mu_parser_LDADD=libtestmucommon.la +TEST_PROGS += test-contacts +test_contacts_SOURCES= mu-contacts.cc +test_contacts_CXXFLAGS=$(AM_CXXFLAGS) -DBUILD_TESTS +test_contacts_LDADD= libtestmucommon.la -libtestmucommon_la_SOURCES= \ - test-mu-common.cc \ - test-mu-common.hh +TEST_PROGS+=test-parser +test_parser_SOURCES=test-parser.cc +test_parser_LDADD=libtestmucommon.la -libtestmucommon_la_LIBADD= \ - libmu.la \ - utils/libmu-utils.la +libtestmucommon_la_SOURCES= \ + test-mu-common.cc \ + test-mu-common.hh + +libtestmucommon_la_LIBADD= \ + libmu.la \ + utils/libmu-utils.la # note the question marks; make does not like files with ':', so we # use the (also supported) version with '!' instead. We could escape @@ -191,103 +197,105 @@ libtestmucommon_la_LIBADD= \ # test messages, the '.ignore' message should be ignored # when indexing -EXTRA_DIST+= \ - testdir/tmp/1220863087.12663.ignore \ - testdir/new/1220863087.12663_9.mindcrime \ - testdir/new/1220863087.12663_25.mindcrime \ - testdir/new/1220863087.12663_21.mindcrime \ - testdir/new/1220863087.12663_23.mindcrime \ - testdir/cur/1220863087.12663_5.mindcrime!2,S \ - testdir/cur/1220863087.12663_7.mindcrime!2,RS \ - testdir/cur/1220863087.12663_15.mindcrime!2,PS \ - testdir/cur/1220863087.12663_19.mindcrime!2,S \ - testdir/cur/1220863042.12663_1.mindcrime!2,S \ - testdir/cur/1220863060.12663_3.mindcrime!2,S \ - testdir/cur/1283599333.1840_11.cthulhu!2, \ - testdir/cur/1305664394.2171_402.cthulhu!2, \ - testdir/cur/1252168370_3.14675.cthulhu!2,S \ - testdir/cur/encrypted!2,S \ - testdir/cur/multimime!2,FS \ - testdir/cur/signed!2,S \ - testdir/cur/signed-encrypted!2,S \ - testdir/cur/special!2,Sabc \ - testdir/cur/multirecip!2,S \ - testdir2/bar/cur/mail1 \ - testdir2/bar/cur/mail2 \ - testdir2/bar/cur/mail3 \ - testdir2/bar/cur/mail4 \ - testdir2/bar/cur/mail5 \ - testdir2/bar/cur/181736.eml \ - testdir2/bar/cur/mail6 \ - testdir2/bar/tmp/.noindex \ - testdir2/bar/new/.noindex \ - testdir2/Foo/cur/mail5 \ - testdir2/Foo/cur/arto.eml \ - testdir2/Foo/cur/fraiche.eml \ - testdir2/Foo/tmp/.noindex \ - testdir2/Foo/new/.noindex \ - testdir2/wom_bat/cur/atomic \ - testdir2/wom_bat/cur/rfc822.1 \ - testdir2/wom_bat/cur/rfc822.2 \ - testdir3/cycle \ - testdir3/cycle/new/.noindex \ - testdir3/cycle/cur/rogue0 \ - testdir3/cycle/cur/cycle0 \ - testdir3/cycle/cur/cycle0.0 \ - testdir3/cycle/cur/cycle0.0.0 \ - testdir3/cycle/tmp/.noindex \ - testdir3/tree/new/.noindex \ - testdir3/tree/cur/child0.0 \ - testdir3/tree/cur/child4.0 \ - testdir3/tree/cur/root2 \ - testdir3/tree/cur/root1 \ - testdir3/tree/cur/child3.0.0.0.0 \ - testdir3/tree/cur/root0 \ - testdir3/tree/cur/child2.0.0 \ - testdir3/tree/cur/child0.1 \ - testdir3/tree/cur/child0.1.0 \ - testdir3/tree/cur/child4.1 \ - testdir3/tree/tmp/.noindex \ - testdir3/sort/1st-child-promotes-thread/cur/A \ - testdir3/sort/1st-child-promotes-thread/cur/B \ - testdir3/sort/1st-child-promotes-thread/cur/C \ - testdir3/sort/1st-child-promotes-thread/cur/D \ - testdir3/sort/2nd-child-promotes-thread/cur/A \ - testdir3/sort/2nd-child-promotes-thread/cur/B \ - testdir3/sort/2nd-child-promotes-thread/cur/C \ - testdir3/sort/2nd-child-promotes-thread/cur/D \ - testdir3/sort/2nd-child-promotes-thread/cur/E \ - testdir3/sort/child-does-not-promote-thread/cur/A \ - testdir3/sort/child-does-not-promote-thread/cur/X \ - testdir3/sort/child-does-not-promote-thread/cur/Y \ - testdir3/sort/child-does-not-promote-thread/cur/Z \ - testdir3/sort/grandchild-promotes-only-subthread/cur/A \ - testdir3/sort/grandchild-promotes-only-subthread/cur/B \ - testdir3/sort/grandchild-promotes-only-subthread/cur/C \ - testdir3/sort/grandchild-promotes-only-subthread/cur/D \ - testdir3/sort/grandchild-promotes-only-subthread/cur/E \ - testdir3/sort/grandchild-promotes-only-subthread/cur/F \ - testdir3/sort/grandchild-promotes-only-subthread/cur/G \ - testdir3/sort/grandchild-promotes-thread/cur/A \ - testdir3/sort/grandchild-promotes-thread/cur/B \ - testdir3/sort/grandchild-promotes-thread/cur/C \ - testdir3/sort/grandchild-promotes-thread/cur/D \ - testdir3/sort/grandchild-promotes-thread/cur/E \ - testdir4/1220863087.12663_19.mindcrime!2,S \ - testdir4/1220863042.12663_1.mindcrime!2,S \ - testdir4/1283599333.1840_11.cthulhu!2, \ - testdir4/1305664394.2171_402.cthulhu!2, \ - testdir4/1252168370_3.14675.cthulhu!2,S \ - testdir4/mail1 \ - testdir4/mail5 \ - testdir4/181736.eml \ - testdir4/encrypted!2,S \ - testdir4/multimime!2,FS \ - testdir4/signed!2,S \ - testdir4/signed-bad!2,S \ - testdir4/signed-encrypted!2,S \ - testdir4/special!2,Sabc +EXTRA_DIST+= \ + testdir/tmp/1220863087.12663.ignore \ + testdir/new/1220863087.12663_9.mindcrime \ + testdir/new/1220863087.12663_25.mindcrime \ + testdir/new/1220863087.12663_21.mindcrime \ + testdir/new/1220863087.12663_23.mindcrime \ + testdir/cur/1220863087.12663_5.mindcrime!2,S \ + testdir/cur/1220863087.12663_7.mindcrime!2,RS \ + testdir/cur/1220863087.12663_15.mindcrime!2,PS \ + testdir/cur/1220863087.12663_19.mindcrime!2,S \ + testdir/cur/1220863042.12663_1.mindcrime!2,S \ + testdir/cur/1220863060.12663_3.mindcrime!2,S \ + testdir/cur/1283599333.1840_11.cthulhu!2, \ + testdir/cur/1305664394.2171_402.cthulhu!2, \ + testdir/cur/1252168370_3.14675.cthulhu!2,S \ + testdir/cur/encrypted!2,S \ + testdir/cur/multimime!2,FS \ + testdir/cur/signed!2,S \ + testdir/cur/signed-encrypted!2,S \ + testdir/cur/special!2,Sabc \ + testdir/cur/multirecip!2,S \ + testdir2/bar/cur/mail1 \ + testdir2/bar/cur/mail2 \ + testdir2/bar/cur/mail3 \ + testdir2/bar/cur/mail4 \ + testdir2/bar/cur/mail5 \ + testdir2/bar/cur/181736.eml \ + testdir2/bar/cur/mail6 \ + testdir2/bar/tmp/.noindex \ + testdir2/bar/new/.noindex \ + testdir2/Foo/cur/mail5 \ + testdir2/Foo/cur/arto.eml \ + testdir2/Foo/cur/fraiche.eml \ + testdir2/Foo/tmp/.noindex \ + testdir2/Foo/new/.noindex \ + testdir2/wom_bat/cur/atomic \ + testdir2/wom_bat/cur/rfc822.1 \ + testdir2/wom_bat/cur/rfc822.2 \ + testdir3/cycle \ + testdir3/cycle/new/.noindex \ + testdir3/cycle/cur/rogue0 \ + testdir3/cycle/cur/cycle0 \ + testdir3/cycle/cur/cycle0.0 \ + testdir3/cycle/cur/cycle0.0.0 \ + testdir3/cycle/tmp/.noindex \ + testdir3/tree/new/.noindex \ + testdir3/tree/cur/child0.0 \ + testdir3/tree/cur/child4.0 \ + testdir3/tree/cur/root2 \ + testdir3/tree/cur/root1 \ + testdir3/tree/cur/child3.0.0.0.0 \ + testdir3/tree/cur/root0 \ + testdir3/tree/cur/child2.0.0 \ + testdir3/tree/cur/child0.1 \ + testdir3/tree/cur/child0.1.0 \ + testdir3/tree/cur/child4.1 \ + testdir3/tree/tmp/.noindex \ + testdir3/sort/1st-child-promotes-thread/cur/A \ + testdir3/sort/1st-child-promotes-thread/cur/B \ + testdir3/sort/1st-child-promotes-thread/cur/C \ + testdir3/sort/1st-child-promotes-thread/cur/D \ + testdir3/sort/2nd-child-promotes-thread/cur/A \ + testdir3/sort/2nd-child-promotes-thread/cur/B \ + testdir3/sort/2nd-child-promotes-thread/cur/C \ + testdir3/sort/2nd-child-promotes-thread/cur/D \ + testdir3/sort/2nd-child-promotes-thread/cur/E \ + testdir3/sort/child-does-not-promote-thread/cur/A \ + testdir3/sort/child-does-not-promote-thread/cur/X \ + testdir3/sort/child-does-not-promote-thread/cur/Y \ + testdir3/sort/child-does-not-promote-thread/cur/Z \ + testdir3/sort/grandchild-promotes-only-subthread/cur/A \ + testdir3/sort/grandchild-promotes-only-subthread/cur/B \ + testdir3/sort/grandchild-promotes-only-subthread/cur/C \ + testdir3/sort/grandchild-promotes-only-subthread/cur/D \ + testdir3/sort/grandchild-promotes-only-subthread/cur/E \ + testdir3/sort/grandchild-promotes-only-subthread/cur/F \ + testdir3/sort/grandchild-promotes-only-subthread/cur/G \ + testdir3/sort/grandchild-promotes-thread/cur/A \ + testdir3/sort/grandchild-promotes-thread/cur/B \ + testdir3/sort/grandchild-promotes-thread/cur/C \ + testdir3/sort/grandchild-promotes-thread/cur/D \ + testdir3/sort/grandchild-promotes-thread/cur/E \ + testdir4/1220863087.12663_19.mindcrime!2,S \ + testdir4/1220863042.12663_1.mindcrime!2,S \ + testdir4/1283599333.1840_11.cthulhu!2, \ + testdir4/1305664394.2171_402.cthulhu!2, \ + testdir4/1252168370_3.14675.cthulhu!2,S \ + testdir4/mail1 \ + testdir4/mail5 \ + testdir4/181736.eml \ + testdir4/encrypted!2,S \ + testdir4/multimime!2,FS \ + testdir4/signed!2,S \ + testdir4/signed-bad!2,S \ + testdir4/signed-encrypted!2,S \ + testdir4/special!2,Sabc TESTS=$(TEST_PROGS) +CLEANFILES=*.log *.trs *core* *vgdump* *.gcda *.gcno + include $(top_srcdir)/aminclude_static.am diff --git a/lib/mu-contacts.cc b/lib/mu-contacts.cc index 53f7054e..28c421ea 100644 --- a/lib/mu-contacts.cc +++ b/lib/mu-contacts.cc @@ -227,7 +227,6 @@ Contacts::add (ContactInfo&& ci) auto it = priv_->contacts_.find(ci.email); if (it == priv_->contacts_.end()) { // completely new contact - wash(ci.name); wash(ci.full_address); auto email{ci.email}; @@ -316,40 +315,94 @@ Contacts::is_personal(const std::string& addr) const } -/// C binding +#ifdef BUILD_TESTS +/* + * Tests. + * + */ -size_t -mu_contacts_count (const MuContacts *self) +#include "test-mu-common.hh" + +static void +test_mu_contacts_01() { - g_return_val_if_fail (self, 0); + Mu::Contacts contacts (""); - auto myself = reinterpret_cast(self); + g_assert_true (contacts.empty()); + g_assert_cmpuint (contacts.size(), ==, 0); - return myself->size(); + contacts.add(Mu::ContactInfo ("Foo ", + "foo.bar@example.com", "Foo", false, 12345)); + g_assert_false (contacts.empty()); + g_assert_cmpuint (contacts.size(), ==, 1); + + contacts.add(Mu::ContactInfo ("Cuux ", + "cuux@example.com", "Cuux", false, 54321)); + + g_assert_cmpuint (contacts.size(), ==, 2); + + contacts.add(Mu::ContactInfo ("foo.bar@example.com", + "foo.bar@example.com", "Foo", false, 77777)); + g_assert_cmpuint (contacts.size(), ==, 2); + + contacts.add(Mu::ContactInfo ("Foo.Bar@Example.Com", + "Foo.Bar@Example.Com", "Foo", false, 88888)); + g_assert_cmpuint (contacts.size(), ==, 2); + // note: replaces first. + + { + const auto info = contacts._find("bla@example.com"); + g_assert_false (info); + } + + { + const auto info = contacts._find("foo.BAR@example.com"); + g_assert_true (info); + + g_assert_cmpstr(info->email.c_str(), ==, "Foo.Bar@Example.Com"); + } + + contacts.clear(); + g_assert_true (contacts.empty()); + g_assert_cmpuint (contacts.size(), ==, 0); } -gboolean -mu_contacts_foreach (const MuContacts *self, MuContactsForeachFunc func, - gpointer user_data) +static void +test_mu_contacts_02() { - g_return_val_if_fail (self, FALSE); - g_return_val_if_fail (func, FALSE); + Mu::StringVec personal = { + "foo@example.com", + "bar@cuux.org", + "/bar-.*@fnorb.f./" + }; + Mu::Contacts contacts{"", personal}; - auto myself = reinterpret_cast(self); + g_assert_true (contacts.is_personal("foo@example.com")); + g_assert_true (contacts.is_personal("Bar@CuuX.orG")); + g_assert_true (contacts.is_personal("bar-123abc@fnorb.fi")); + g_assert_true (contacts.is_personal("bar-zzz@fnorb.fr")); - myself->for_each([&](const ContactInfo& ci) { - g_return_if_fail (!ci.email.empty()); - func(ci.full_address.c_str(), - ci.email.c_str(), - ci.name.empty() ? NULL : ci.name.c_str(), - ci.personal, - ci.last_seen, - ci.freq, - ci.tstamp, - user_data); - }); - - return TRUE; + g_assert_false (contacts.is_personal("foo@bar.com")); + g_assert_false (contacts.is_personal("BÂr@CuuX.orG")); + g_assert_false (contacts.is_personal("bar@fnorb.fi")); + g_assert_false (contacts.is_personal("bar-zzz@fnorb.xr")); } -struct _MuContacts : public Mu::Contacts {}; /**< c-compat */ + + +int +main (int argc, char *argv[]) +{ + g_test_init (&argc, &argv, NULL); + + g_test_add_func ("/mu-contacts/01", test_mu_contacts_01); + g_test_add_func ("/mu-contacts/02", test_mu_contacts_02); + + g_log_set_handler (NULL, + (GLogLevelFlags) + (G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL| G_LOG_FLAG_RECURSION), + (GLogFunc)black_hole, NULL); + + return g_test_run (); +} +#endif /*BUILD_TESTS*/ diff --git a/lib/mu-contacts.hh b/lib/mu-contacts.hh index 6eeaccd2..282d797b 100644 --- a/lib/mu-contacts.hh +++ b/lib/mu-contacts.hh @@ -22,12 +22,6 @@ #include #include - -struct _MuContacts; -typedef struct _MuContacts MuContacts; - -#ifdef __cplusplus - #include #include #include @@ -155,17 +149,6 @@ public: */ void for_each (const EachContactFunc& each_contact) const; - /** - * For C compatiblityy - * - * @return a MuContacts* referring to this. - */ - const MuContacts* mu_contacts() const { - return reinterpret_cast(this); - } - - - private: struct Private; std::unique_ptr priv_; @@ -173,48 +156,4 @@ private: } // namespace Mu -#endif /*__cplusplus*/ - -G_BEGIN_DECLS - - -/** - * return the number of contacts - * - * @param self a contacts object - * - * @return the number of contacts - */ -size_t mu_contacts_count (const MuContacts *self); - -/** - * Function called for mu_contacts_foreach; returns the e-mail address, name - * (which may be NULL) , whether the message is 'personal', the timestamp for - * the address (when it was last seen), and the frequency (in how many message - * did this contact participate) and the tstamp (last modification) - * - */ -typedef void (*MuContactsForeachFunc) (const char *full_address, - const char *email, const char *name, - gboolean personal, - time_t last_seen, unsigned freq, - gint64 tstamp, gpointer user_data); - -/** - * call a function for either each contact, or each contact satisfying - * a regular expression, - * - * @param self contacts object - * @param func callback function to be called for each - * @param user_data user data to pass to the callback - * - * @return TRUE if the function succeeded, or FALSE if the provide regular - * expression was invalid (and not NULL) - */ -gboolean mu_contacts_foreach (const MuContacts *self, - MuContactsForeachFunc func, - gpointer user_data); - -G_END_DECLS - #endif /* __MU_CONTACTS_HH__ */ diff --git a/lib/test-mu-contacts.cc b/lib/test-mu-contacts.cc deleted file mode 100644 index 58174317..00000000 --- a/lib/test-mu-contacts.cc +++ /dev/null @@ -1,108 +0,0 @@ -/* -** Copyright (C) 2019 Dirk-Jan C. Binnema -** -** 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 -** Free Software Foundation; either version 3, or (at your option) any -** later version. -** -** This program is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** GNU General Public License for more details. -** -** You should have received a copy of the GNU General Public License -** along with this program; if not, write to the Free Software Foundation, -** Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -** -*/ - - -#include "config.h" - -#include -#include "test-mu-common.hh" -#include "mu-contacts.hh" - -static void -test_mu_contacts_01() -{ - Mu::Contacts contacts (""); - - g_assert_true (contacts.empty()); - g_assert_cmpuint (contacts.size(), ==, 0); - - contacts.add(Mu::ContactInfo ("Foo ", - "foo.bar@example.com", "Foo", false, 12345)); - g_assert_false (contacts.empty()); - g_assert_cmpuint (contacts.size(), ==, 1); - - contacts.add(Mu::ContactInfo ("Cuux ", - "cuux@example.com", "Cuux", false, 54321)); - - g_assert_cmpuint (contacts.size(), ==, 2); - - contacts.add(Mu::ContactInfo ("foo.bar@example.com", - "foo.bar@example.com", "Foo", false, 77777)); - g_assert_cmpuint (contacts.size(), ==, 2); - - contacts.add(Mu::ContactInfo ("Foo.Bar@Example.Com", - "Foo.Bar@Example.Com", "Foo", false, 88888)); - g_assert_cmpuint (contacts.size(), ==, 2); - // note: replaces first. - - { - const auto info = contacts._find("bla@example.com"); - g_assert_false (info); - } - - { - const auto info = contacts._find("foo.BAR@example.com"); - g_assert_true (info); - - g_assert_cmpstr(info->email.c_str(), ==, "Foo.Bar@Example.Com"); - } - - contacts.clear(); - g_assert_true (contacts.empty()); - g_assert_cmpuint (contacts.size(), ==, 0); -} - -static void -test_mu_contacts_02() -{ - Mu::StringVec personal = { - "foo@example.com", - "bar@cuux.org", - "/bar-.*@fnorb.f./" - }; - Mu::Contacts contacts{"", personal}; - - g_assert_true (contacts.is_personal("foo@example.com")); - g_assert_true (contacts.is_personal("Bar@CuuX.orG")); - g_assert_true (contacts.is_personal("bar-123abc@fnorb.fi")); - g_assert_true (contacts.is_personal("bar-zzz@fnorb.fr")); - - g_assert_false (contacts.is_personal("foo@bar.com")); - g_assert_false (contacts.is_personal("BÂr@CuuX.orG")); - g_assert_false (contacts.is_personal("bar@fnorb.fi")); - g_assert_false (contacts.is_personal("bar-zzz@fnorb.xr")); -} - - - -int -main (int argc, char *argv[]) -{ - g_test_init (&argc, &argv, NULL); - - g_test_add_func ("/mu-contacts/01", test_mu_contacts_01); - g_test_add_func ("/mu-contacts/02", test_mu_contacts_02); - - g_log_set_handler (NULL, - (GLogLevelFlags) - (G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL| G_LOG_FLAG_RECURSION), - (GLogFunc)black_hole, NULL); - - return g_test_run (); -}