lib: split out utils to lib/utils

This commit is contained in:
Dirk-Jan C. Binnema 2019-12-16 21:44:03 +02:00
parent 3e2acda310
commit e5337e7658
14 changed files with 83 additions and 58 deletions

View File

@ -255,6 +255,7 @@ mu/Makefile
mu/tests/Makefile
lib/Makefile
lib/doxyfile
lib/utils/Makefile
lib/parser/Makefile
lib/tests/Makefile
mu4e/Makefile

View File

@ -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= \

69
lib/utils/Makefile.am Normal file
View File

@ -0,0 +1,69 @@
## Copyright (C) 2019 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 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

View File

@ -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;
}

View File

@ -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);

View File

@ -348,9 +348,9 @@ test_mu_extract_01 (void)
g_assert_cmpstr (output,
==,
"MIME-parts in this message:\n"
" 1 <none> text/plain [<none>] (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 <none> text/plain [<none>] (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);