From 94487cfe9a799dbd289f9b5c34ced20880f5d4ab Mon Sep 17 00:00:00 2001 From: "Dirk-Jan C. Binnema" Date: Wed, 1 Dec 2010 21:57:36 +0200 Subject: [PATCH] * add some simply unit tests for mu-runtime, mu-store --- src/mu-runtime.h | 2 +- src/mu-store.h | 16 ++++--- src/tests/Makefile.am | 8 ++++ src/tests/test-mu-runtime.c | 96 +++++++++++++++++++++++++++++++++++++ 4 files changed, 114 insertions(+), 8 deletions(-) create mode 100644 src/tests/test-mu-runtime.c diff --git a/src/mu-runtime.h b/src/mu-runtime.h index 0b1a85d1..cd1ad07a 100644 --- a/src/mu-runtime.h +++ b/src/mu-runtime.h @@ -20,7 +20,7 @@ #define __MU_RUNTIME_H__ #include -#include "mu-config.h" +#include G_BEGIN_DECLS diff --git a/src/mu-store.h b/src/mu-store.h index 4674531f..ff982b50 100644 --- a/src/mu-store.h +++ b/src/mu-store.h @@ -23,9 +23,9 @@ #include #include -#include "mu-result.h" -#include "mu-msg.h" -#include "mu-error.h" +#include +#include +#include G_BEGIN_DECLS @@ -41,7 +41,9 @@ typedef struct _MuStore MuStore; * * @return a new MuStore object, or NULL in case of error */ -MuStore* mu_store_new (const char* path, GError **err); +MuStore* mu_store_new (const char *path, GError **err) + G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT; + /** * destroy the MuStore object and free resources @@ -136,8 +138,8 @@ gboolean mu_store_contains_message (MuStore *store, * @param stamp a timestamp */ void mu_store_set_timestamp (MuStore *store, - const char* msgpath, - time_t stamp); + const char* msgpath, + time_t stamp); /** * get the timestamp for a directory @@ -148,7 +150,7 @@ void mu_store_set_timestamp (MuStore *store, * @return the timestamp, or 0 in case of error */ time_t mu_store_get_timestamp (MuStore *store, - const char* msgpath); + const char* msgpath); /** * call a function for each document in the database diff --git a/src/tests/Makefile.am b/src/tests/Makefile.am index 0b6cf550..627123de 100644 --- a/src/tests/Makefile.am +++ b/src/tests/Makefile.am @@ -64,6 +64,14 @@ TEST_PROGS += test-mu-msg test_mu_msg_SOURCES= test-mu-msg.c test_mu_msg_LDADD= libtestmucommon.la +TEST_PROGS += test-mu-runtime +test_mu_runtime_SOURCES= test-mu-runtime.c +test_mu_runtime_LDADD= libtestmucommon.la + +TEST_PROGS += test-mu-store +test_mu_store_SOURCES= test-mu-store.c dummy.cc +test_mu_store_LDADD= libtestmucommon.la + libtestmucommon_la_SOURCES= \ test-mu-common.c \ diff --git a/src/tests/test-mu-runtime.c b/src/tests/test-mu-runtime.c new file mode 100644 index 00000000..d46ee4f6 --- /dev/null +++ b/src/tests/test-mu-runtime.c @@ -0,0 +1,96 @@ +/* +** Copyright (C) 2008-2010 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. +** +*/ + +#if HAVE_CONFIG_H +#include "config.h" +#endif /*HAVE_CONFIG_H*/ + +#include +#include +#include +#include + +#include + +#include "test-mu-common.h" +#include "src/mu-runtime.h" + +static void +test_mu_runtime_init (void) +{ + gchar* tmpdir; + + tmpdir = test_mu_common_get_random_tmpdir(); + g_assert (tmpdir); + g_assert (mu_runtime_init (tmpdir) == TRUE); + mu_runtime_uninit (); + + g_assert (mu_runtime_init (tmpdir) == TRUE); + mu_runtime_uninit (); + + g_free (tmpdir); +} + + +static void +test_mu_runtime_data (void) +{ + gchar *homedir, *xdir, *bmfile; + + homedir = test_mu_common_get_random_tmpdir(); + g_assert (homedir); + + xdir = g_strdup_printf ("%s%c%s", homedir, + G_DIR_SEPARATOR, "xapian" ); + + bmfile = g_strdup_printf ("%s%c%s", homedir, + G_DIR_SEPARATOR, "bookmarks"); + + g_assert (mu_runtime_init (homedir) == TRUE); + + g_assert_cmpstr (homedir, ==, mu_runtime_mu_home_dir ()); + g_assert_cmpstr (xdir, ==, mu_runtime_xapian_dir ()); + g_assert_cmpstr (bmfile, ==, mu_runtime_bookmarks_file ()); + + mu_runtime_uninit (); + + g_free (homedir); + g_free (xdir); + g_free (bmfile); +} + + + +int +main (int argc, char *argv[]) +{ + g_test_init (&argc, &argv, NULL); + + /* mu_runtime_init/uninit */ + g_test_add_func ("/mu-runtime/mu-runtime-init", + test_mu_runtime_init); + g_test_add_func ("/mu-runtime/mu-runtime-data", + test_mu_runtime_data); + + g_log_set_handler (NULL, + G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL| G_LOG_FLAG_RECURSION, + (GLogFunc)black_hole, NULL); + + return g_test_run (); +}