From 62c4b64a4ddad892e3baa830f065999ec39d0bc1 Mon Sep 17 00:00:00 2001 From: "Dirk-Jan C. Binnema" Date: Sun, 10 Dec 2006 18:00:09 +0000 Subject: [PATCH] * all: - add "check"-based automated testing framework - make tests and documentation configurable pmo-trunk-r530 --- Makefile.am | 15 ++-- configure.ac | 62 ++++++++++++-- tests/Makefile.am | 94 +++++++++++---------- tests/check_folder-transfer.c | 187 +++++++++++++++++++++++++++++++++++++++++ tests/check_modest-conf.c | 77 +++++++++++++++++ tests/check_update-account.c | 132 +++++++++++++++++++++++++++++ tests/folder-transfer.c | 187 ----------------------------------------- tests/update-account.c | 120 -------------------------- 8 files changed, 512 insertions(+), 362 deletions(-) create mode 100644 tests/check_folder-transfer.c create mode 100644 tests/check_modest-conf.c create mode 100644 tests/check_update-account.c delete mode 100644 tests/folder-transfer.c delete mode 100644 tests/update-account.c diff --git a/Makefile.am b/Makefile.am index d1bcb0f..aa69844 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,13 +1,18 @@ # # Makefile.am for modest -# Time-stamp: <2006-04-22 16:29:00 (djcb)> +# Time-stamp: <2006-12-10 12:55:27 (djcb)> # -SUBDIRS= src tests po docs +SUBDIRS= src po + +if BUILD_TESTS +SUBDIRS += tests +endif + +if BUILD_DOCS +SUBDIRS += docs +endif EXTRA_DIST= config.rpath config.rpath mkinstalldirs \ autogen.sh TODO COPYING intltool-extract.in intltool-merge.in \ intltool-update.in - -CFLAGS=\ - -Wall diff --git a/configure.ac b/configure.ac index dfef1a0..56b919b 100644 --- a/configure.ac +++ b/configure.ac @@ -1,7 +1,8 @@ dnl configure.ac for modest -dnl Time-stamp: <2006-11-28 17:26:13 (djcb)> +dnl Time-stamp: <2006-12-10 12:52:34 (djcb)> dnl written by Dirk-Jan C. Binnema + AC_INIT([modest],[0.0.1],[http://maemo.org]) AC_CONFIG_HEADERS([config.h]) @@ -26,20 +27,22 @@ fi AC_SUBST(prefix) AC_PROG_CC -AM_PROG_CC_C_O AM_PROG_CC_STDC AC_HEADER_STDC AC_PROG_LIBTOOL -# check for perl -AC_CHECK_PROG([perl]) -GTK_DOC_CHECK([1.0]) + + dnl # GLib/Gobject/Gtk/Gconf => mandatory PKG_CHECK_MODULES(MODEST_GSTUFF,glib-2.0 >= 2.6 gobject-2.0 gtk+-2.0 >= 2.6 gconf-2.0 libgtkhtml-3.8 libglade-2.0 libtinymail-1.0 libtinymail-camel-1.0 libtinymailui-1.0 libtinymailui-gtk-1.0) AC_SUBST(MODEST_GSTUFF_CFLAGS) AC_SUBST(MODEST_GSTUFF_LIBS) + + + + dnl dnl now, determine what to build AC_MSG_NOTICE([Determining what platform to build]) PKG_CHECK_MODULES(MODEST_LIBTINYMAIL_MAEMO,libosso,[with_platform=maemo],true) @@ -71,6 +74,49 @@ fi dnl 1==>gtk, 2==>maemo AC_SUBST(MODEST_PLATFORM_ID) + + + + +dnl ## setup the testing framework (ie., make check) +build_tests=false +AC_ARG_ENABLE(tests, +AC_HELP_STRING([--enable-tests], + [Build tests (no, yes)]), +[case "${enableval}" in + yes) + build_tests=true ;; + *) build_tests=false ;; +esac],[build_tests=false]) +AM_CONDITIONAL(BUILD_TESTS, test x$build_tests = xtrue) + +dnl ## is the check package installed? +if test x$build_tests = xtrue; then + PKG_CHECK_MODULES(CHECK, check >= 0.9.4 glib-2.0) +fi + + + + + +dnl ## do we want documentation (gtk-doc) +build_docs=false +AC_ARG_ENABLE(docs, +AC_HELP_STRING([--enable-docs], + [Build documentation (yes, no)]), +[case "${enableval}" in + yes) + build_docs=true ;; + *) build_docs=false ;; +esac],[build_docs=false]) +AM_CONDITIONAL(BUILD_DOCS, test x$build_docs = xtrue) + +dnl ## is the check package installed? +GTK_DOC_CHECK([1.0]) + + + + AC_OUTPUT([ po/Makefile.in Makefile @@ -83,10 +129,16 @@ docs/reference/Makefile tests/Makefile ]) + + + + echo echo "modest configure results" echo "-----------------------------------" echo "Platform : $with_platform" +echo "Build tests : $build_tests" +echo "Build docs : $build_docs" echo "" echo "NOTE: you should do a 'make clean' after changing platform (--with-platform=)" echo "" diff --git a/tests/Makefile.am b/tests/Makefile.am index ffb3f42..15cc3e2 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -1,4 +1,24 @@ +# +# Makefile.am +# + +MAINTAINERCLEANFILES = Makefile.in + +TESTS_ENVIRONMENT = top_builddir=$(top_builddir) + +TESTS = \ + check_folder-xfer \ + check_update-account \ + check_modest-conf + +noinst_PROGRAMS= \ + check_folder-xfer \ + check_update-account \ + check_modest-conf + + INCLUDES=\ + @CHECK_CFLAGS@ \ $(MODEST_GSTUFF_CFLAGS)\ $(MODEST_LIBTINYMAIL_GNOME_DESKTOP_CFLAGS) \ $(MODEST_LIBTINYMAIL_MAEMO_CFLAGS) \ @@ -6,51 +26,35 @@ INCLUDES=\ -I${top_srcdir}/src \ -DPREFIX=\"@prefix@\" \ -DMODESTLOCALEDIR=\""$(modestlocaledir)"\" +objects=\ + @CHECK_LIBS@ \ + $(MODEST_GSTUFF_LIBS) \ + $(MODEST_LIBTINYMAIL_GNOME_DESKTOP_LIBS) \ + $(MODEST_LIBTINYMAIL_MAEMO_LIBS) \ + ${top_srcdir}/src/$(MODEST_PLATFORM)/libmodest-ui.la \ + ${top_srcdir}/src/widgets/libmodest-widgets.la \ + ${top_srcdir}/src/modest-account-mgr.o \ + ${top_srcdir}/src/modest-tny-platform-factory.o \ + ${top_srcdir}/src/modest-conf.o \ + ${top_srcdir}/src/modest-protocol-mgr.o \ + ${top_srcdir}/src/modest-formatter.o \ + ${top_srcdir}/src/modest-pair.o \ + ${top_srcdir}/src/modest-marshal.o \ + ${top_srcdir}/src/modest-tny-account-store.o \ + ${top_srcdir}/src/modest-mail-operation-queue.o \ + ${top_srcdir}/src/modest-mail-operation.o \ + ${top_srcdir}/src/modest-tny-msg-actions.o \ + ${top_srcdir}/src/modest-text-utils.o -bin_PROGRAMS=\ - folder-xfer\ - update-account -folder_xfer_SOURCES=\ - folder-transfer.c +check_folder_xfer_SOURCES=\ + check_folder-transfer.c +check_folder_xfer_LDADD = $(objects) -folder_xfer_LDADD = \ - $(MODEST_GSTUFF_LIBS) \ - $(MODEST_LIBTINYMAIL_GNOME_DESKTOP_LIBS) \ - $(MODEST_LIBTINYMAIL_MAEMO_LIBS) \ - ${top_srcdir}/src/$(MODEST_PLATFORM)/libmodest-ui.la \ - ${top_srcdir}/src/widgets/libmodest-widgets.la \ - ${top_srcdir}/src/modest-account-mgr.o \ - ${top_srcdir}/src/modest-tny-platform-factory.o \ - ${top_srcdir}/src/modest-conf.o \ - ${top_srcdir}/src/modest-protocol-mgr.o \ - ${top_srcdir}/src/modest-formatter.o \ - ${top_srcdir}/src/modest-pair.o \ - ${top_srcdir}/src/modest-marshal.o \ - ${top_srcdir}/src/modest-tny-account-store.o \ - ${top_srcdir}/src/modest-mail-operation-queue.o \ - ${top_srcdir}/src/modest-mail-operation.o \ - ${top_srcdir}/src/modest-tny-msg-actions.o \ - ${top_srcdir}/src/modest-text-utils.o - -update_account_SOURCES=\ - update-account.c - -update_account_LDADD = \ - $(MODEST_GSTUFF_LIBS) \ - $(MODEST_LIBTINYMAIL_GNOME_DESKTOP_LIBS) \ - $(MODEST_LIBTINYMAIL_MAEMO_LIBS) \ - ${top_srcdir}/src/$(MODEST_PLATFORM)/libmodest-ui.la \ - ${top_srcdir}/src/widgets/libmodest-widgets.la \ - ${top_srcdir}/src/modest-account-mgr.o \ - ${top_srcdir}/src/modest-tny-platform-factory.o \ - ${top_srcdir}/src/modest-conf.o \ - ${top_srcdir}/src/modest-protocol-mgr.o \ - ${top_srcdir}/src/modest-formatter.o \ - ${top_srcdir}/src/modest-pair.o \ - ${top_srcdir}/src/modest-marshal.o \ - ${top_srcdir}/src/modest-tny-account-store.o \ - ${top_srcdir}/src/modest-mail-operation-queue.o \ - ${top_srcdir}/src/modest-mail-operation.o \ - ${top_srcdir}/src/modest-tny-msg-actions.o \ - ${top_srcdir}/src/modest-text-utils.o +check_update_account_SOURCES=\ + check_update-account.c +check_update_account_LDADD = $(objects) + +check_modest_conf_SOURCES=\ + check_modest-conf.c +check_modest_conf_LDADD = $(objects) diff --git a/tests/check_folder-transfer.c b/tests/check_folder-transfer.c new file mode 100644 index 0000000..80822bb --- /dev/null +++ b/tests/check_folder-transfer.c @@ -0,0 +1,187 @@ +/* Copyright (c) 2006, Nokia Corporation + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the Nokia Corporation nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + + +#include +#include + +static gchar *cachedir=NULL; +static gboolean move=FALSE; +static const gchar *src_name = NULL; +static const gchar *dst_name = NULL; + +static void +find_folders (TnyFolderStore *store, TnyFolderStoreQuery *query, + TnyFolder **folder_src, TnyFolder **folder_dst) +{ + TnyIterator *iter; + TnyList *folders; + + if ((*folder_src != NULL) && (*folder_dst != NULL)) + return; + + folders = tny_simple_list_new (); + tny_folder_store_get_folders (store, folders, query, NULL); + iter = tny_list_create_iterator (folders); + + while (!tny_iterator_is_done (iter) && (!*folder_src || !*folder_dst)) + { + TnyFolderStore *folder = (TnyFolderStore*) tny_iterator_get_current (iter); + const gchar *folder_name = NULL; + + folder_name = tny_folder_get_name (TNY_FOLDER (folder)); + + if (strcmp (folder_name, src_name) == 0) + *folder_src = g_object_ref (folder); + + if (!strcmp (folder_name, dst_name)) + *folder_dst = g_object_ref (folder); + + find_folders (folder, query, folder_src, folder_dst); + + g_object_unref (G_OBJECT (folder)); + + tny_iterator_next (iter); + } + + g_object_unref (G_OBJECT (iter)); + g_object_unref (G_OBJECT (folders)); +} + +static const GOptionEntry options[] = { + { "from", 'f', 0, G_OPTION_ARG_STRING, &src_name, + "Source folder", NULL}, + { "to", 't', 0, G_OPTION_ARG_STRING, &dst_name, + "Destination folder", NULL}, + { "cachedir", 'c', 0, G_OPTION_ARG_STRING, &cachedir, + "Cache directory", NULL }, + { "move", 'm', 0, G_OPTION_ARG_NONE, &move, + "Move the messages instead of copy them", NULL }, + { NULL } +}; + +int +main (int argc, char **argv) +{ + GOptionContext *context; + TnyList *accounts, *src_headers; + TnyStoreAccount *account; + TnyIterator *iter; + TnyFolder *folder_src = NULL, *folder_dst = NULL; + TnyPlatformFactory *fact = NULL; + ModestAccountMgr *acc_mgr = NULL; + ModestMailOperation *mail_op = NULL; + TnyAccountStore *account_store = NULL; + guint src_num_headers = 0, dst_num_headers = 0; + GError *err; + + g_type_init (); + + context = g_option_context_new ("Test"); + g_option_context_add_main_entries (context, options, "Modest"); + if (!g_option_context_parse (context, &argc, &argv, &err)) { + g_printerr ("Error in command line parameter(s): '%s', exiting\n", + err ? err->message : ""); + return 0; + } + g_option_context_free (context); + + fact = TNY_PLATFORM_FACTORY (modest_tny_platform_factory_get_instance ()); + acc_mgr = MODEST_ACCOUNT_MGR (modest_tny_platform_factory_get_modest_account_mgr_instance (fact)); + account_store = tny_platform_factory_new_account_store (fact); + + if (cachedir) + g_print ("Using %s as cache directory\n", cachedir); + + if (!src_name || !dst_name) { + g_printerr ("Error in command line parameter(s), specify source and target folders\n"); + return 0; + } + + /* Get accounts */ + accounts = tny_simple_list_new (); + + tny_account_store_get_accounts (account_store, accounts, + TNY_ACCOUNT_STORE_STORE_ACCOUNTS); + + iter = tny_list_create_iterator (accounts); + account = (TnyStoreAccount*) tny_iterator_get_current (iter); + + g_object_unref (G_OBJECT (iter)); + g_object_unref (G_OBJECT (accounts)); + + /* Find the two folders */ + find_folders (TNY_FOLDER_STORE (account), NULL, + &folder_src, &folder_dst); + + if (!folder_src || !folder_dst) + goto cleanup; + + /* Refresh folders */ + tny_folder_refresh (folder_src, NULL); + src_num_headers = tny_folder_get_all_count (folder_src); + + tny_folder_refresh (folder_dst, NULL); + dst_num_headers = tny_folder_get_all_count (folder_dst); + + /* Get all the headers of the source & target folder */ + src_headers = tny_simple_list_new (); + tny_folder_get_headers (folder_src, src_headers, TRUE, NULL); + + mail_op = modest_mail_operation_new (); + + if (move) + modest_mail_operation_move_folder (mail_op, + folder_src, + TNY_FOLDER_STORE (folder_dst)); + else + modest_mail_operation_copy_folder (mail_op, + folder_src, + TNY_FOLDER_STORE (folder_dst)); + + g_object_unref (G_OBJECT (src_headers)); + g_object_unref (G_OBJECT (mail_op)); + + cleanup: + g_object_unref (account); + + return 0; +} diff --git a/tests/check_modest-conf.c b/tests/check_modest-conf.c new file mode 100644 index 0000000..687405e --- /dev/null +++ b/tests/check_modest-conf.c @@ -0,0 +1,77 @@ +/* Copyright (c) 2006, Nokia Corporation + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the Nokia Corporation nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include + + + +START_TEST (test_modest_conf_new) +{ + ModestConf *conf = modest_conf_new (); + fail_unless (MODEST_IS_CONF(conf), + "modest_conf_new should return a valid" + " ModestConf instance"); + g_object_unref (conf); +} +END_TEST + + + +static Suite* +modest_conf_suite (void) +{ + Suite *suite = suite_create ("ModestConf"); + + TCase *tc_core = tcase_create ("core"); + tcase_add_test (tc_core, test_modest_conf_new); + + suite_add_tcase (suite, tc_core); + + return suite; +} + +int +main () +{ + SRunner *srunner; + Suite *suite; + int failures; + + g_type_init(); + + suite = modest_conf_suite (); + srunner = srunner_create (suite); + + srunner_run_all (srunner, CK_NORMAL); + failures = srunner_ntests_failed (srunner); + srunner_free (srunner); + + return failures; +} diff --git a/tests/check_update-account.c b/tests/check_update-account.c new file mode 100644 index 0000000..87b3862 --- /dev/null +++ b/tests/check_update-account.c @@ -0,0 +1,132 @@ +/* Copyright (c) 2006, Nokia Corporation + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the Nokia Corporation nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include "modest-tny-platform-factory.h" +#include "modest-account-mgr.h" +#include "modest-mail-operation.h" +#include "modest-mail-operation-queue.h" + +GMainLoop *main_loop; + +static void +on_progress_changed (ModestMailOperation *mail_op, gpointer user_data) +{ + ModestMailOperationStatus status; + ModestMailOperationQueue *queue = NULL; + + g_print ("Refreshed %d of %d\n", + modest_mail_operation_get_task_done (mail_op), + modest_mail_operation_get_task_total (mail_op)); + + if (modest_mail_operation_is_finished (mail_op)) { + queue = MODEST_MAIL_OPERATION_QUEUE (user_data); + modest_mail_operation_queue_remove (queue, mail_op); + g_main_loop_quit (main_loop); + } +} + +static gboolean +func (gpointer_data) +{ + TnyStoreAccount *account; + TnyIterator *iter; + TnyPlatformFactory *fact = NULL; + ModestAccountMgr *acc_mgr = NULL; + ModestMailOperation *mail_op = NULL; + ModestMailOperationQueue *queue = NULL; + TnyAccountStore *account_store = NULL; + TnyList *accounts; + + fact = TNY_PLATFORM_FACTORY (modest_tny_platform_factory_get_instance ()); + acc_mgr = MODEST_ACCOUNT_MGR (modest_tny_platform_factory_get_modest_account_mgr_instance (fact)); + account_store = tny_platform_factory_new_account_store (fact); + + /* Get accounts */ + accounts = tny_simple_list_new (); + + tny_account_store_get_accounts (account_store, accounts, + TNY_ACCOUNT_STORE_STORE_ACCOUNTS); + + iter = tny_list_create_iterator (accounts); + account = TNY_STORE_ACCOUNT (tny_iterator_get_current (iter)); + + g_object_unref (G_OBJECT (iter)); + g_object_unref (G_OBJECT (accounts)); + + queue = modest_mail_operation_queue_get_instance (); + mail_op = modest_mail_operation_new (); + + g_signal_connect (G_OBJECT (mail_op), "progress_changed", + G_CALLBACK (on_progress_changed), queue); + + if (modest_mail_operation_update_account (mail_op, account)) + modest_mail_operation_queue_add (queue, mail_op); + + g_object_unref (G_OBJECT (mail_op)); + + return FALSE; +} + +static void +quit (gpointer data) +{ + _exit (0); +} + + + +int +main (int argc, char **argv) +{ + guint id; + + g_type_init (); + g_thread_init(NULL); + + main_loop = g_main_loop_new (NULL, FALSE); + id = g_timeout_add(1000, func, main_loop); + + g_timeout_add (5000, quit, main_loop); /* quit after 5 seconds */ + + g_main_loop_run(main_loop); + + return 0; +} diff --git a/tests/folder-transfer.c b/tests/folder-transfer.c deleted file mode 100644 index d61f844..0000000 --- a/tests/folder-transfer.c +++ /dev/null @@ -1,187 +0,0 @@ -/* Copyright (c) 2006, Nokia Corporation - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of the Nokia Corporation nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS - * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A - * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER - * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - - -#include -#include - -static gchar *cachedir=NULL; -static gboolean move=FALSE; -static const gchar *src_name = NULL; -static const gchar *dst_name = NULL; - -static void -find_folders (TnyFolderStore *store, TnyFolderStoreQuery *query, - TnyFolder **folder_src, TnyFolder **folder_dst) -{ - TnyIterator *iter; - TnyList *folders; - - if ((*folder_src != NULL) && (*folder_dst != NULL)) - return; - - folders = tny_simple_list_new (); - tny_folder_store_get_folders (store, folders, query, NULL); - iter = tny_list_create_iterator (folders); - - while (!tny_iterator_is_done (iter) && (!*folder_src || !*folder_dst)) - { - TnyFolderStore *folder = (TnyFolderStore*) tny_iterator_get_current (iter); - const gchar *folder_name = NULL; - - folder_name = tny_folder_get_name (TNY_FOLDER (folder)); - - if (strcmp (folder_name, src_name) == 0) - *folder_src = g_object_ref (folder); - - if (!strcmp (folder_name, dst_name)) - *folder_dst = g_object_ref (folder); - - find_folders (folder, query, folder_src, folder_dst); - - g_object_unref (G_OBJECT (folder)); - - tny_iterator_next (iter); - } - - g_object_unref (G_OBJECT (iter)); - g_object_unref (G_OBJECT (folders)); -} - -static const GOptionEntry options[] = { - { "from", 'f', 0, G_OPTION_ARG_STRING, &src_name, - "Source folder", NULL}, - { "to", 't', 0, G_OPTION_ARG_STRING, &dst_name, - "Destination folder", NULL}, - { "cachedir", 'c', 0, G_OPTION_ARG_STRING, &cachedir, - "Cache directory", NULL }, - { "move", 'm', 0, G_OPTION_ARG_NONE, &move, - "Move the messages instead of copy them", NULL }, - { NULL } -}; - -int -main (int argc, char **argv) -{ - GOptionContext *context; - TnyList *accounts, *src_headers; - TnyStoreAccount *account; - TnyIterator *iter; - TnyFolder *folder_src = NULL, *folder_dst = NULL; - TnyPlatformFactory *fact = NULL; - ModestAccountMgr *acc_mgr = NULL; - ModestMailOperation *mail_op = NULL; - TnyAccountStore *account_store = NULL; - guint src_num_headers = 0, dst_num_headers = 0; - GError *err; - - g_type_init (); - - context = g_option_context_new ("Test"); - g_option_context_add_main_entries (context, options, "Modest"); - if (!g_option_context_parse (context, &argc, &argv, &err)) { - g_printerr ("Error in command line parameter(s): '%s', exiting\n", - err ? err->message : ""); - return 1; - } - g_option_context_free (context); - - fact = TNY_PLATFORM_FACTORY (modest_tny_platform_factory_get_instance ()); - acc_mgr = MODEST_ACCOUNT_MGR (modest_tny_platform_factory_get_modest_account_mgr_instance (fact)); - account_store = tny_platform_factory_new_account_store (fact); - - if (cachedir) - g_print ("Using %s as cache directory\n", cachedir); - - if (!src_name || !dst_name) { - g_printerr ("Error in command line parameter(s), specify source and target folders\n"); - return 1; - } - - /* Get accounts */ - accounts = tny_simple_list_new (); - - tny_account_store_get_accounts (account_store, accounts, - TNY_ACCOUNT_STORE_STORE_ACCOUNTS); - - iter = tny_list_create_iterator (accounts); - account = (TnyStoreAccount*) tny_iterator_get_current (iter); - - g_object_unref (G_OBJECT (iter)); - g_object_unref (G_OBJECT (accounts)); - - /* Find the two folders */ - find_folders (TNY_FOLDER_STORE (account), NULL, - &folder_src, &folder_dst); - - if (!folder_src || !folder_dst) - goto cleanup; - - /* Refresh folders */ - tny_folder_refresh (folder_src, NULL); - src_num_headers = tny_folder_get_all_count (folder_src); - - tny_folder_refresh (folder_dst, NULL); - dst_num_headers = tny_folder_get_all_count (folder_dst); - - /* Get all the headers of the source & target folder */ - src_headers = tny_simple_list_new (); - tny_folder_get_headers (folder_src, src_headers, TRUE, NULL); - - mail_op = modest_mail_operation_new (); - - if (move) - modest_mail_operation_move_folder (mail_op, - folder_src, - TNY_FOLDER_STORE (folder_dst)); - else - modest_mail_operation_copy_folder (mail_op, - folder_src, - TNY_FOLDER_STORE (folder_dst)); - - g_object_unref (G_OBJECT (src_headers)); - g_object_unref (G_OBJECT (mail_op)); - - cleanup: - g_object_unref (account); - - return 0; -} diff --git a/tests/update-account.c b/tests/update-account.c deleted file mode 100644 index d868806..0000000 --- a/tests/update-account.c +++ /dev/null @@ -1,120 +0,0 @@ -/* Copyright (c) 2006, Nokia Corporation - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of the Nokia Corporation nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS - * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A - * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER - * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -#include "modest-tny-platform-factory.h" -#include "modest-account-mgr.h" -#include "modest-mail-operation.h" -#include "modest-mail-operation-queue.h" - -GMainLoop *main_loop; - -static void -on_progress_changed (ModestMailOperation *mail_op, gpointer user_data) -{ - ModestMailOperationStatus status; - ModestMailOperationQueue *queue = NULL; - - g_print ("Refreshed %d of %d\n", - modest_mail_operation_get_task_done (mail_op), - modest_mail_operation_get_task_total (mail_op)); - - if (modest_mail_operation_is_finished (mail_op)) { - queue = MODEST_MAIL_OPERATION_QUEUE (user_data); - modest_mail_operation_queue_remove (queue, mail_op); - g_main_loop_quit (main_loop); - } -} - -static gboolean -func (gpointer_data) -{ - TnyStoreAccount *account; - TnyIterator *iter; - TnyPlatformFactory *fact = NULL; - ModestAccountMgr *acc_mgr = NULL; - ModestMailOperation *mail_op = NULL; - ModestMailOperationQueue *queue = NULL; - TnyAccountStore *account_store = NULL; - TnyList *accounts; - - fact = TNY_PLATFORM_FACTORY (modest_tny_platform_factory_get_instance ()); - acc_mgr = MODEST_ACCOUNT_MGR (modest_tny_platform_factory_get_modest_account_mgr_instance (fact)); - account_store = tny_platform_factory_new_account_store (fact); - - /* Get accounts */ - accounts = tny_simple_list_new (); - - tny_account_store_get_accounts (account_store, accounts, - TNY_ACCOUNT_STORE_STORE_ACCOUNTS); - - iter = tny_list_create_iterator (accounts); - account = TNY_STORE_ACCOUNT (tny_iterator_get_current (iter)); - - g_object_unref (G_OBJECT (iter)); - g_object_unref (G_OBJECT (accounts)); - - queue = modest_mail_operation_queue_get_instance (); - mail_op = modest_mail_operation_new (); - - g_signal_connect (G_OBJECT (mail_op), "progress_changed", - G_CALLBACK (on_progress_changed), queue); - - if (modest_mail_operation_update_account (mail_op, account)) - modest_mail_operation_queue_add (queue, mail_op); - - g_object_unref (G_OBJECT (mail_op)); - - return FALSE; -} - -int -main (int argc, char **argv) -{ - guint id; - - g_type_init (); - g_thread_init(NULL); - - main_loop = g_main_loop_new (NULL, FALSE); - id = g_timeout_add(1000, func, main_loop); - g_main_loop_run(main_loop); - - return 0; -} -- 1.7.9.5