* add some simply unit tests for mu-runtime, mu-store

This commit is contained in:
Dirk-Jan C. Binnema 2010-12-01 21:57:36 +02:00
parent 3560eecf3a
commit 94487cfe9a
4 changed files with 114 additions and 8 deletions

View File

@ -20,7 +20,7 @@
#define __MU_RUNTIME_H__
#include <glib.h>
#include "mu-config.h"
#include <mu-config.h>
G_BEGIN_DECLS

View File

@ -23,9 +23,9 @@
#include <glib.h>
#include <inttypes.h>
#include "mu-result.h"
#include "mu-msg.h"
#include "mu-error.h"
#include <mu-result.h>
#include <mu-msg.h>
#include <mu-error.h>
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

View File

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

View File

@ -0,0 +1,96 @@
/*
** Copyright (C) 2008-2010 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, 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 <glib.h>
#include <stdlib.h>
#include <unistd.h>
#include <time.h>
#include <locale.h>
#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 ();
}