[kazehakase-svn] [3580] more tests.

Back to archive index

svnno****@sourc***** svnno****@sourc*****
Tue Jan 27 08:51:26 JST 2009


Revision: 3580
          http://svn.sourceforge.jp/view?root=kazehakase&view=rev&rev=3580
Author:   ikezoe
Date:     2009-01-27 08:51:26 +0900 (Tue, 27 Jan 2009)

Log Message:
-----------
more tests.

Modified Paths:
--------------
    kazehakase/trunk/test/test-bookmark-file.c

Modified: kazehakase/trunk/test/test-bookmark-file.c
===================================================================
--- kazehakase/trunk/test/test-bookmark-file.c	2009-01-26 23:46:19 UTC (rev 3579)
+++ kazehakase/trunk/test/test-bookmark-file.c	2009-01-26 23:51:26 UTC (rev 3580)
@@ -11,16 +11,26 @@
 void test_xmlrpc_user (void);
 void test_xmlrpc_pass (void);
 void test_load (void);
+void test_load_start (void);
 
 static KzBookmarkFile *file;
 static KzBookmark *expected;
 static gchar *file_path;
 
+static gint n_load_start_received;
+static gint n_load_completed_received;
+static gint n_load_error_received;
+
 void
 setup (void)
 {
     file =  NULL;
     expected = NULL;
+
+    n_load_start_received = 0;
+    n_load_completed_received = 0;
+    n_load_error_received = 0;
+
     file_path = g_build_filename(kz_test_get_base_dir(),
                                  "fixtures", "bookmarks.xml",
                                  NULL);
@@ -131,6 +141,81 @@
     kz_assert_equal_bookmark(expected, KZ_BOOKMARK(file));
 }
 
+static gboolean
+cb_check_emitted (gpointer data)
+{
+    gboolean *emitted = data;
+
+    *emitted = TRUE;
+    return FALSE;
+}
+
+static void
+wait_signal (void)
+{
+    gboolean timeout_emitted = FALSE;
+    gboolean idle_emitted = FALSE;
+    guint timeout_id, idle_id;
+
+    idle_id = g_idle_add_full(G_PRIORITY_DEFAULT,
+                              cb_check_emitted, &idle_emitted, NULL);
+
+    timeout_id = g_timeout_add_seconds(1, cb_check_emitted, &timeout_emitted);
+    while (!timeout_emitted && !idle_emitted) {
+        g_main_context_iteration(NULL, TRUE);
+    }
+
+    g_source_remove(idle_id);
+    g_source_remove(timeout_id);
+
+    cut_assert_false(timeout_emitted, "timeout");
+}
+
+static void 
+cb_load_start (KzBookmarkFile *bookmark_file, gpointer data)
+{
+    n_load_start_received++;
+}
+
+static void 
+cb_load_completed (KzBookmarkFile *bookmark_file, gpointer data)
+{
+    n_load_completed_received++;
+}
+
+static void 
+cb_load_error (KzBookmarkFile *bookmark_file, gpointer data)
+{
+    n_load_error_received++;
+}
+
+static void
+setup_signals (void)
+{
+    g_signal_connect(file, "load-start",
+                     G_CALLBACK(cb_load_start), NULL);
+    g_signal_connect(file, "load-completed",
+                     G_CALLBACK(cb_load_completed), NULL);
+    g_signal_connect(file, "error",
+                     G_CALLBACK(cb_load_error), NULL);
+
+}
+
+void
+test_load_start (void)
+{
+    cut_trace(test_new());
+
+    setup_signals();
+    cut_assert_true(kz_bookmark_file_load_start(file));
+
+    wait_signal();
+
+    cut_assert_equal_int(1, n_load_start_received);
+    cut_assert_equal_int(1, n_load_completed_received);
+    cut_assert_equal_int(0, n_load_error_received);
+}
+
 /*
 vi:ts=4:nowrap:ai:expandtab:sw=4
 */



More information about the Kazehakase-cvs mailing list
Back to archive index