New unit tests: Folder and some Folder
- From: "Øystein Gisnås" <oystein gisnas net>
- To: tinymail-devel-list gnome org
- Subject: New unit tests: Folder and some Folder
- Date: Sat, 16 Dec 2006 14:33:43 +0100
I've added some unit tests. Mostly for FolderStore, but also some for Folder.
Take a look at the refresh_async test for example. That's a test of a
callback function.
Let me know if you want me to commit.
Cheers,
Øystein
Index: libtinymail-test/tny-folder-test.c
===================================================================
--- libtinymail-test/tny-folder-test.c (revisjon 1319)
+++ libtinymail-test/tny-folder-test.c (arbeidskopi)
@@ -37,6 +37,7 @@
static TnyStoreAccount *account;
static TnyIterator *aiter;
static gchar *str;
+static gboolean callback_completed = FALSE;
typedef void (*performer) (TnyFolder *folder);
@@ -108,10 +109,10 @@
/* TODO:
test signal folder inserted and folders_reloaded (hard to test)
- test methods get_folders, get_message,
- test properties name, account, folder_type
- test properties unread_count
- test methods set_subscribed with get_subscribed
+ test methods add_msg, get_msg, get_msg_async,
+ test transfer_msgs, transfer_msgs_async, copy
+ test is_subscribed with unsubscribed folder
+ test get_folder_type with INBOX
test async method refresh_async (hard to test)
*/
@@ -213,6 +214,96 @@
}
END_TEST
+START_TEST (tny_folder_test_properties)
+{
+ GError *err;
+ gint count;
+
+ if (iface == NULL)
+ {
+ g_warning ("Test cannot continue (are you online?)");
+ return;
+ }
+
+ fail_unless (strcmp (tny_folder_get_id (iface), "INBOX/tny-folder-iface-test") == 0, "Folder had wrong ID property");
+ err = NULL;
+ tny_folder_refresh (iface, &err);
+ fail_unless (err == NULL, "Error refreshing folder");
+ fail_unless (tny_folder_get_all_count (iface) > 0, "Message count too small");
+ fail_unless (tny_folder_get_unread_count (iface) == 2, "Unread count is wrong");
+ fail_unless (tny_folder_is_subscribed (iface), "Subscription property should be set");
+ fail_unless (tny_folder_get_account (iface) == account, "Property account has wrong value");
+ fail_unless (tny_folder_get_folder_type (iface) == TNY_FOLDER_TYPE_NORMAL, "Folder is not the right type");
+}
+END_TEST
+
+START_TEST (tny_folder_test_name)
+{
+ const gchar *name = "tny-folder-iface-test";
+ const gchar *temp_name = "tny-folder-iface-test_temp";
+ GError *err;
+
+ if (iface == NULL)
+ {
+ g_warning ("Test cannot continue (are you online?)");
+ return;
+ }
+
+ fail_unless (strcmp (tny_folder_get_name (iface), name) == 0, "Folder had wrong name property");
+ err = NULL;
+ tny_folder_set_name (iface, temp_name, &err);
+ fail_unless (err == NULL, "An error occured while renaming folder");
+ fail_unless (strcmp (tny_folder_get_name (iface), temp_name) == 0, "Folder had wrong name property");
+ err = NULL;
+ tny_folder_set_name (iface, name, &err);
+ fail_unless (err == NULL, "An error occured while renaming folder");
+ fail_unless (strcmp (tny_folder_get_name (iface), name) == 0, "Folder had wrong name property");
+}
+END_TEST
+
+static void
+refresh_progress (TnyFolder *folder, const gchar *what, gint status, gpointer user_data)
+{
+ g_print (".");
+}
+
+static void
+folder_refreshed (TnyFolder *folder, gboolean cancelled, GError **err, gpointer user_data)
+{
+ g_print ("done\n");
+ fail_unless (!cancelled, "Async refresh cancelled");
+ callback_completed = TRUE;
+ gtk_main_quit ();
+}
+
+static gboolean
+timeout (gpointer data)
+{
+ g_print ("timeout\n");
+ gtk_main_quit ();
+ return FALSE;
+}
+
+START_TEST (tny_folder_test_refresh_async)
+{
+ GError *err;
+
+ if (iface == NULL)
+ {
+ g_warning ("Test cannot continue (are you online?)");
+ return;
+ }
+
+ err = NULL;
+ g_print ("Refreshing folder..");
+ tny_folder_refresh_async (iface, folder_refreshed, refresh_progress, &err);
+ g_timeout_add (1000*6, timeout, NULL);
+ gtk_main ();
+ fail_unless (callback_completed, "Refresh callback was never called");
+ fail_unless (tny_folder_get_unread_count (iface) == 2, "Message count not updated");
+}
+END_TEST
+
Suite *
create_tny_folder_suite (void)
{
@@ -220,14 +311,33 @@
Suite *s = suite_create ("Folder");
tc = tcase_create ("Get Headers Sync");
+ tcase_set_timeout (tc, 5);
tcase_add_checked_fixture (tc, tny_folder_test_setup, tny_folder_test_teardown);
tcase_add_test (tc, tny_folder_test_get_headers_sync);
suite_add_tcase (s, tc);
tc = tcase_create ("Remove Message");
+ tcase_set_timeout (tc, 5);
tcase_add_checked_fixture (tc, tny_folder_test_setup, tny_folder_test_teardown);
tcase_add_test (tc, tny_folder_test_remove_message);
suite_add_tcase (s, tc);
+ tc = tcase_create ("Properties");
+ tcase_add_checked_fixture (tc, tny_folder_test_setup, tny_folder_test_teardown);
+ tcase_add_test (tc, tny_folder_test_properties);
+ suite_add_tcase (s, tc);
+
+ tc = tcase_create ("Name");
+ tcase_set_timeout (tc, 15);
+ tcase_add_checked_fixture (tc, tny_folder_test_setup, tny_folder_test_teardown);
+ tcase_add_test (tc, tny_folder_test_name);
+ suite_add_tcase (s, tc);
+
+ tc = tcase_create ("Refresh");
+ tcase_set_timeout (tc, 10);
+ tcase_add_checked_fixture (tc, tny_folder_test_setup, tny_folder_test_teardown);
+ tcase_add_test (tc, tny_folder_test_refresh_async);
+ suite_add_tcase (s, tc);
+
return s;
}
Index: libtinymail-test/check_libtinymail_main.c
===================================================================
--- libtinymail-test/check_libtinymail_main.c (revisjon 1319)
+++ libtinymail-test/check_libtinymail_main.c (arbeidskopi)
@@ -11,13 +11,15 @@
gtk_init (NULL, NULL); /* Why doesn't this require gtk CFLAGS&LIBS? */
g_thread_init (NULL);
- sr = srunner_create ((Suite *) create_tny_list_suite ());
- srunner_add_suite (sr, (Suite *) create_tny_folder_suite ());
- srunner_add_suite (sr, (Suite *) create_tny_folder_store_query_suite ());
+ sr = srunner_create (NULL);
srunner_add_suite (sr, (Suite *) create_tny_account_store_suite ());
srunner_add_suite (sr, (Suite *) create_tny_account_suite ());
srunner_add_suite (sr, (Suite *) create_tny_device_suite ());
+ srunner_add_suite (sr, (Suite *) create_tny_folder_store_query_suite ());
+ srunner_add_suite (sr, (Suite *) create_tny_folder_store_suite ());
+ srunner_add_suite (sr, (Suite *) create_tny_folder_suite ());
srunner_add_suite (sr, (Suite *) create_tny_header_suite ());
+ srunner_add_suite (sr, (Suite *) create_tny_list_suite ());
srunner_add_suite (sr, (Suite *) create_tny_mime_part_suite ());
srunner_add_suite (sr, (Suite *) create_tny_msg_suite ());
srunner_add_suite (sr, (Suite *) create_tny_stream_suite ());
Index: libtinymail-test/check_libtinymail.h
===================================================================
--- libtinymail-test/check_libtinymail.h (revisjon 1319)
+++ libtinymail-test/check_libtinymail.h (arbeidskopi)
@@ -5,13 +5,13 @@
#include <glib.h>
#include <check.h>
-Suite *create_tny_list_suite (void);
-Suite *create_tny_folder_suite (void);
-Suite *create_tny_folder_store_query_suite (void);
Suite *create_tny_account_store_suite (void);
Suite *create_tny_account_suite (void);
Suite *create_tny_device_suite (void);
+Suite *create_tny_folder_store_query_suite (void);
+Suite *create_tny_folder_suite (void);
Suite *create_tny_header_suite (void);
+Suite *create_tny_list_suite (void);
Suite *create_tny_mime_part_suite (void);
Suite *create_tny_msg_suite (void);
Suite *create_tny_stream_suite (void);
Index: libtinymail-test/Makefile.am
===================================================================
--- libtinymail-test/Makefile.am (revisjon 1319)
+++ libtinymail-test/Makefile.am (arbeidskopi)
@@ -43,13 +43,14 @@
tny-test-object.c \
tny-test-stream.h \
tny-test-stream.c \
- tny-list-test.c \
- tny-folder-test.c \
- tny-folder-store-query-test.c \
tny-account-store-test.c \
tny-account-test.c \
tny-device-test.c \
+ tny-folder-store-query-test.c \
+ tny-folder-store-test.c \
+ tny-folder-test.c \
tny-header-test.c \
+ tny-list-test.c \
tny-mime-part-test.c \
tny-msg-test.c \
tny-platform-factory-test.c \
Index: libtinymail-test/tny-folder-store-test.c
===================================================================
--- libtinymail-test/tny-folder-store-test.c (revisjon 0)
+++ libtinymail-test/tny-folder-store-test.c (revisjon 0)
@@ -0,0 +1,201 @@
+/* tinymail - Tiny Mail unit test
+ * Copyright (C) 2006 �ystein Gisnås <oystein gisnas net>
+ *
+ * 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 2 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 self program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include "check_libtinymail.h"
+
+#include <tny-folder.h>
+#include <tny-camel-folder.h>
+#include <tny-folder-store.h>
+#include <tny-list.h>
+#include <tny-iterator.h>
+#include <tny-simple-list.h>
+#include <tny-account-store.h>
+#include <tny-store-account.h>
+#include <tny-folder.h>
+#include <tny-camel-header.h>
+
+#include <account-store.h>
+
+static TnyFolderStore *account;
+
+static void
+tny_folder_store_test_setup (void)
+{
+ TnyIterator *aiter;
+ TnyList *accounts = tny_simple_list_new ();
+ TnyAccountStore *account_store = tny_test_account_store_new (TRUE, NULL);
+ tny_account_store_get_accounts (account_store, accounts, TNY_ACCOUNT_STORE_STORE_ACCOUNTS);
+ g_object_unref (account_store);
+ aiter = tny_list_create_iterator (accounts);
+ tny_iterator_first (aiter);
+ account = TNY_FOLDER_STORE (tny_iterator_get_current (aiter));
+ g_object_unref (aiter);
+ g_object_unref (accounts);
+}
+
+static void
+tny_folder_store_test_teardown (void)
+{
+ g_object_unref (G_OBJECT (account));
+}
+
+START_TEST (tny_folder_store_test_get_folders)
+{
+ TnyList *folders;
+ GError *err = NULL;
+
+ if (account == NULL)
+ {
+ g_warning ("Test cannot continue (are you online?)");
+ return;
+ }
+
+ /* Test server has only one root folder */
+ folders = tny_simple_list_new ();
+ tny_folder_store_get_folders (account, folders, NULL, NULL);
+ fail_unless (tny_list_get_length (folders) == 1, "There should be only one root folder");
+ g_object_unref (G_OBJECT (folders));
+
+ /* Make sure errors are set - invalid URL*/
+ folders = tny_simple_list_new ();
+ tny_account_set_url_string (TNY_ACCOUNT (account), "trigger://error");
+ tny_folder_store_get_folders (account, folders, NULL, &err);
+ fail_unless (err != NULL, "An error should be set when the account is invalid");
+
+ g_object_unref (G_OBJECT (folders));
+}
+END_TEST
+
+static void
+callback (TnyFolderStore *self, TnyList *list, GError **err, gpointer user_data)
+{
+ TnyFolder *folder;
+ TnyIterator *iter = tny_list_create_iterator (list);
+
+ fail_unless (tny_list_get_length (list) == 1, "Did not find one root folder as expected in callback"); folder = TNY_FOLDER (tny_iterator_get_current (iter));
+ fail_unless (strcmp (tny_folder_get_id (folder), "INBOX") == 0, "Did not find INBOX");
+ g_object_unref (G_OBJECT (iter));
+ g_object_unref (G_OBJECT (folder));
+ gtk_main_quit ();
+}
+
+static gboolean
+timeout (gpointer data)
+{
+ gtk_main_quit ();
+ return FALSE;
+}
+
+START_TEST (tny_folder_store_test_get_folders_async)
+{
+ TnyList *folders;
+
+ if (account == NULL)
+ {
+ g_warning ("Test cannot continue (are you online?)");
+ return;
+ }
+
+ folders = tny_simple_list_new ();
+ tny_folder_store_get_folders_async (account, folders, callback, NULL, NULL);
+ g_timeout_add (1000*4, timeout, NULL);
+ gtk_main ();
+ fail_unless (tny_list_get_length (folders) == 1, "Did not find one root folder as expected");
+
+ g_object_unref (G_OBJECT (folders));
+}
+END_TEST
+
+TnyFolderStore *
+get_inbox ()
+{
+ TnyList *folders = tny_simple_list_new ();
+ TnyIterator *iter;
+ TnyFolder *folder;
+
+ tny_folder_store_get_folders (account, folders, NULL, NULL);
+ fail_unless (tny_list_get_length (folders) == 1, "Asserted that there was only one root folder");
+ iter = tny_list_create_iterator (TNY_LIST (folders));
+ folder = TNY_FOLDER (tny_iterator_get_current (iter));
+
+ g_object_unref (G_OBJECT (iter));
+ g_object_unref (G_OBJECT (folders));
+
+ return (TnyFolderStore *) folder;
+}
+
+/* It might be an idea to refactor remove_folder into a separate test case */
+/* in case the folder exists. We will never get rid of it the way it is now. */
+START_TEST (tny_folder_store_test_create_remove_folder)
+{
+ GError *err;
+ TnyFolderStore *inbox;
+ TnyFolder *new_folder;
+ const gchar *new_folder_name = "tny-folder-store-test_temp-folder";
+ gchar *str;
+
+ /* Make sure errors are set - cannot add folder to root */
+ err = NULL;
+ tny_folder_store_create_folder (account, "tny-folder-store-test_temp-folder", &err);
+ fail_unless (err != NULL, "Expected an error when trying to create a top level folder");
+
+ /* Create a folder under Inbox. Hopefully we're able to remove it later. */
+ inbox = get_inbox();
+ err = NULL;
+ new_folder = tny_folder_store_create_folder (inbox, new_folder_name, &err);
+ if (err != NULL)
+ fail (g_strdup_printf ("The attempt to create folder %s in %s failed. Error message: %s\n", new_folder_name, tny_folder_get_name (TNY_FOLDER (inbox)), err->message));
+ fail_unless (strcmp (tny_folder_get_name (new_folder), new_folder_name) == 0, "A new folder was not created. Did it already exist?");
+
+ /* Attempt to remove the new folder */
+ err = NULL;
+ tny_folder_store_remove_folder (inbox, new_folder, &err);
+ if (err != NULL)
+ fail (g_strdup_printf ("Could not remove folder %s from %s. Error message: %s\n", new_folder_name, tny_folder_get_name (TNY_FOLDER (inbox)), err->message));
+ fail_unless (tny_folder_get_id (new_folder) == NULL, "The folder ID of a removed folder was still set after removal");
+
+ g_object_unref (G_OBJECT (new_folder));
+ g_object_unref (G_OBJECT (inbox));
+}
+END_TEST
+
+Suite *
+create_tny_folder_store_suite (void)
+{
+ TCase *tc = NULL;
+ Suite *s = suite_create ("Folder Store");
+
+ tc = tcase_create ("Get Folders");
+ tcase_add_checked_fixture (tc, tny_folder_store_test_setup, tny_folder_store_test_teardown);
+ tcase_add_test (tc, tny_folder_store_test_get_folders);
+ suite_add_tcase (s, tc);
+
+ tc = tcase_create ("Get Folders Async");
+ tcase_set_timeout (tc, 5);
+ tcase_add_checked_fixture (tc, tny_folder_store_test_setup, tny_folder_store_test_teardown);
+ tcase_add_test (tc, tny_folder_store_test_get_folders_async);
+ suite_add_tcase (s, tc);
+
+ tc = tcase_create ("Create and Remove Folder");
+ tcase_set_timeout (tc, 10);
+ tcase_add_checked_fixture (tc, tny_folder_store_test_setup, tny_folder_store_test_teardown);
+ tcase_add_test (tc, tny_folder_store_test_create_remove_folder);
+ suite_add_tcase (s, tc);
+
+ return s;
+}
Index: libtinymail-test/tny-folder-store-query-test.c
===================================================================
--- libtinymail-test/tny-folder-store-query-test.c (revisjon 1319)
+++ libtinymail-test/tny-folder-store-query-test.c (arbeidskopi)
@@ -75,8 +75,7 @@
return;
}
-START_TEST (
-tny_folder_store_query_test_match_on_name)
+START_TEST (tny_folder_store_query_test_match_on_name)
{
TnyFolderStoreQuery *query = NULL;
TnyList *folders = NULL, *subfolders;
@@ -124,8 +123,7 @@
}
END_TEST
-START_TEST (
-tny_folder_store_query_test_match_on_id)
+START_TEST (tny_folder_store_query_test_match_on_id)
{
TnyFolderStoreQuery *query = NULL;
TnyList *folders = NULL, *subfolders;
@@ -171,8 +169,7 @@
END_TEST
-START_TEST (
-tny_folder_store_query_test_match_subscribed)
+START_TEST (tny_folder_store_query_test_match_subscribed)
{
TnyFolderStoreQuery *query = NULL;
TnyList *folders = NULL, *subfolders;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]