diff --git a/configure.ac b/configure.ac index 72e7bfb2..2b840ee9 100644 --- a/configure.ac +++ b/configure.ac @@ -255,6 +255,7 @@ mu/Makefile mu/tests/Makefile lib/Makefile lib/doxyfile +lib/utils/Makefile lib/parser/Makefile lib/tests/Makefile mu4e/Makefile diff --git a/lib/Makefile.am b/lib/Makefile.am index d36d9093..d80fbd88 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -18,7 +18,7 @@ include $(top_srcdir)/gtest.mk # enforce compiling guile (optionally) first,then this dir first # before decending into tests/ -SUBDIRS= parser . tests +SUBDIRS= utils parser . tests if HAVE_JSON_GLIB json_srcs= \ @@ -66,14 +66,10 @@ libmu_la_SOURCES= \ mu-contacts.hh \ mu-container.c \ mu-container.h \ - mu-date.c \ - mu-date.h \ mu-flags.h \ mu-flags.c \ mu-index.c \ mu-index.h \ - mu-log.c \ - mu-log.h \ mu-maildir.c \ mu-maildir.h \ mu-msg-crypto.c \ @@ -103,12 +99,8 @@ libmu_la_SOURCES= \ mu-script.h \ mu-store.cc \ mu-store.hh \ - mu-str.c \ - mu-str.h \ mu-threader.c \ - mu-threader.h \ - mu-util.c \ - mu-util.h + mu-threader.h libmu_la_LIBADD= \ $(XAPIAN_LIBS) \ @@ -116,6 +108,7 @@ libmu_la_LIBADD= \ $(GLIB_LIBS) \ $(GUILE_LIBS) \ $(JSON_GLIB_LIBS) \ + ${builddir}/utils/libmu-utils.la \ ${builddir}/parser/libmuxparser.la libmu_la_LDFLAGS= \ diff --git a/lib/utils/Makefile.am b/lib/utils/Makefile.am new file mode 100644 index 00000000..20f6727d --- /dev/null +++ b/lib/utils/Makefile.am @@ -0,0 +1,69 @@ +## 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 of the License, 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 $(top_srcdir)/gtest.mk + +AM_CFLAGS= \ + $(WARN_CFLAGS) \ + $(GLIB_CFLAGS) \ + $(ASAN_CFLAGS) \ + -DMU_TESTMAILDIR=\"${abs_top_srcdir}/lib/tests/testdir\" \ + -DMU_TESTMAILDIR2=\"${abs_top_srcdir}/lib/tests/testdir2\" \ + -Wno-format-nonliteral \ + -Wno-switch-enum \ + -Wno-deprecated-declarations \ + -Wno-inline + +AM_CXXFLAGS= \ + $(WARN_CXXFLAGS) \ + $(GLIB_CFLAGS) \ + $(ASAN_CXXFLAGS) + +noinst_LTLIBRARIES= \ + libmu-utils.la + +libmu_utils_la_SOURCES= \ + mu-date.c \ + mu-date.h \ + mu-log.c \ + mu-log.h \ + mu-str.c \ + mu-str.h \ + mu-util.c \ + mu-util.h + +libmu_utils_la_LIBADD= \ + $(GLIB_LIBS) + +libmu_utils_la_LDFLAGS= \ + $(ASAN_LDFLAGS) + +noinst_PROGRAMS= \ + $(TEST_PROGS) + +TEST_PROGS+= \ + test-mu-util +test_mu_util_SOURCES= \ + test-mu-util.c +test_mu_util_LDADD= \ + libmu-utils.la + +TEST_PROGS+= \ + test-mu-str +test_mu_str_SOURCES= \ + test-mu-str.c +test_mu_str_LDADD= \ + libmu-utils.la diff --git a/lib/mu-date.c b/lib/utils/mu-date.c similarity index 100% rename from lib/mu-date.c rename to lib/utils/mu-date.c diff --git a/lib/mu-date.h b/lib/utils/mu-date.h similarity index 100% rename from lib/mu-date.h rename to lib/utils/mu-date.h diff --git a/lib/mu-log.c b/lib/utils/mu-log.c similarity index 100% rename from lib/mu-log.c rename to lib/utils/mu-log.c diff --git a/lib/mu-log.h b/lib/utils/mu-log.h similarity index 100% rename from lib/mu-log.h rename to lib/utils/mu-log.h diff --git a/lib/mu-str.c b/lib/utils/mu-str.c similarity index 98% rename from lib/mu-str.c rename to lib/utils/mu-str.c index fdb58178..9d338771 100644 --- a/lib/mu-str.c +++ b/lib/utils/mu-str.c @@ -37,25 +37,14 @@ const char* mu_str_size_s (size_t s) { - static char buf[32]; - -#ifdef HAVE_GLIB216 - char *tmp; + static char buf[32]; + char *tmp; tmp = g_format_size_for_display ((goffset)s); strncpy (buf, tmp, sizeof(buf)); buf[sizeof(buf) -1] = '\0'; /* just in case */ g_free (tmp); -#else - if (s >= 1000 * 1000) - g_snprintf(buf, sizeof(buf), "%.1f MB", - (double)s/(1000*1000)); - else - g_snprintf(buf, sizeof(buf), "%.1f kB", (double)s/(1000)); -#endif /*HAVE_GLIB216*/ - - return buf; } diff --git a/lib/mu-str.h b/lib/utils/mu-str.h similarity index 100% rename from lib/mu-str.h rename to lib/utils/mu-str.h diff --git a/lib/mu-util.c b/lib/utils/mu-util.c similarity index 100% rename from lib/mu-util.c rename to lib/utils/mu-util.c diff --git a/lib/mu-util.h b/lib/utils/mu-util.h similarity index 100% rename from lib/mu-util.h rename to lib/utils/mu-util.h diff --git a/lib/tests/test-mu-str.c b/lib/utils/test-mu-str.c similarity index 90% rename from lib/tests/test-mu-str.c rename to lib/utils/test-mu-str.c index cf3906c4..ecba8fbf 100644 --- a/lib/tests/test-mu-str.c +++ b/lib/utils/test-mu-str.c @@ -45,15 +45,13 @@ test_mu_str_size_01 (void) lc = localeconv(); - tmp2 = g_strdup_printf ("0%s0 kB", lc->decimal_point); - g_assert_cmpstr (mu_str_size_s (0), ==, tmp2); + g_assert_cmpstr (mu_str_size_s (0), ==, "0 bytes"); + + tmp2 = g_strdup_printf ("97%s7 KB", lc->decimal_point); + g_assert_cmpstr (mu_str_size_s (100000), ==, tmp2); g_free (tmp2); - tmp2 = g_strdup_printf ("100%s0 kB", lc->decimal_point); - g_assert_cmpstr (mu_str_size_s (100000), ==, tmp2); - g_free (tmp2); - - tmp2 = g_strdup_printf ("1%s1 MB", lc->decimal_point); + tmp2 = g_strdup_printf ("1%s0 MB", lc->decimal_point); g_assert_cmpstr (mu_str_size_s (1100*1000), ==, tmp2); g_free (tmp2); } @@ -271,28 +269,6 @@ test_mu_str_to_list_strip (void) } -static void -test_mu_str_subject_normalize (void) -{ - int i; - - struct { - const char *src, *exp; - } tests[] = { - { "test123", "test123" }, - { "Re:test123", "test123" }, - { "Re: Fwd: test123", "test123" }, - { "Re[3]: Fwd: test123", "test123" }, - { "operation: mindcrime", "operation: mindcrime" }, /*...*/ - { "", "" } - }; - - for (i = 0; i != G_N_ELEMENTS(tests); ++i) - g_assert_cmpstr (mu_str_subject_normalize (tests[i].src), ==, - tests[i].exp); -} - - static void test_mu_str_replace (void) { @@ -383,9 +359,6 @@ main (int argc, char *argv[]) g_test_add_func ("/mu-str/mu-str-esc-to-list", test_mu_str_esc_to_list); - g_test_add_func ("/mu-str/mu_str_subject_normalize", - test_mu_str_subject_normalize); - g_test_add_func ("/mu-str/mu_str_remove_ctrl_in_place", test_mu_str_remove_ctrl_in_place); diff --git a/lib/tests/test-mu-util.c b/lib/utils/test-mu-util.c similarity index 100% rename from lib/tests/test-mu-util.c rename to lib/utils/test-mu-util.c diff --git a/mu/tests/test-mu-cmd.c b/mu/tests/test-mu-cmd.c index 870236d0..3163c2a6 100644 --- a/mu/tests/test-mu-cmd.c +++ b/mu/tests/test-mu-cmd.c @@ -348,9 +348,9 @@ test_mu_extract_01 (void) g_assert_cmpstr (output, ==, "MIME-parts in this message:\n" - " 1 text/plain [] (0.0 kB)\n" - " 2 sittingbull.jpg image/jpeg [inline] (23.9 kB)\n" - " 3 custer.jpg image/jpeg [inline] (21.6 kB)\n"); + " 1 text/plain [] (27 bytes)\n" + " 2 sittingbull.jpg image/jpeg [inline] (23.3 KB)\n" + " 3 custer.jpg image/jpeg [inline] (21.1 KB)\n"); /* we expect zero lines of error output */ g_assert_cmpuint (newlines_in_output(erroutput),==,0);