[kazehakase-svn] [3734] test signals.

Back to archive index

svnno****@sourc***** svnno****@sourc*****
Wed Feb 18 11:11:59 JST 2009


Revision: 3734
          http://svn.sourceforge.jp/view?root=kazehakase&view=rev&rev=3734
Author:   ikezoe
Date:     2009-02-18 11:11:59 +0900 (Wed, 18 Feb 2009)

Log Message:
-----------
test signals.

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

Modified: kazehakase/trunk/test/test-bookmark-folder.c
===================================================================
--- kazehakase/trunk/test/test-bookmark-folder.c	2009-02-18 01:51:44 UTC (rev 3733)
+++ kazehakase/trunk/test/test-bookmark-folder.c	2009-02-18 02:11:59 UTC (rev 3734)
@@ -23,15 +23,94 @@
 static KzBookmarkFolder *folder;
 static KzBookmark *child;
 static KzBookmark *another_child;
+static KzBookmark *actual_child;
+static KzBookmark *actual_sibling;
+
 static GList *children;
 
+static gint n_insert_child_received;
+static gint n_remove_child_received;
+
+static void 
+cb_insert_child (KzBookmarkFolder *folder,
+                 KzBookmark *child,
+                 KzBookmark *sibling,
+                 gpointer data)
+{
+    n_insert_child_received++;
+
+    if (actual_child)
+        g_object_unref(actual_child);
+        
+    actual_child = g_object_ref(child);
+
+    if (actual_sibling) {
+        g_object_unref(actual_sibling);
+        actual_sibling = NULL;
+    }
+    if (sibling)
+        actual_sibling = g_object_ref(sibling);
+}
+
+static void 
+cb_remove_child (KzBookmarkFolder *folder,
+                 KzBookmark *child,
+                 gpointer data)
+{
+    n_remove_child_received++;
+
+    if (actual_child) {
+        g_object_unref(actual_child);
+        actual_child = NULL;
+    }
+    actual_child = g_object_ref(child);
+}
+
+static void
+connect_signals (void)
+{
+    g_signal_connect(folder, "insert-child",
+                     G_CALLBACK(cb_insert_child), NULL);
+    g_signal_connect(folder, "remove-child",
+                     G_CALLBACK(cb_remove_child), NULL);
+}
+
+static gboolean
+cb_check_emitted (gpointer data)
+{
+    gboolean *emitted = data;
+
+    *emitted = TRUE;
+    return FALSE;
+}
+
+static void
+wait_signal (gint *n_signals, gint count)
+{
+    gboolean timeout_emitted = FALSE;
+    guint timeout_id;
+
+    timeout_id = g_timeout_add_seconds(1, cb_check_emitted, &timeout_emitted);
+    while (!timeout_emitted && *n_signals < count)
+        g_main_context_iteration(NULL, TRUE);
+
+    g_source_remove(timeout_id);
+
+    cut_assert_false(timeout_emitted, "timeout");
+}
+
 void
 setup (void)
 {
     folder =  NULL;
     child = NULL;
     another_child = NULL;
+    actual_child = NULL;
+    actual_sibling = NULL;
     children = NULL;
+
+    n_insert_child_received = 0;
+    n_remove_child_received = 0;
 }
 
 void
@@ -45,6 +124,10 @@
         g_list_free(children);
     if (another_child)
         g_object_unref(another_child);
+    if (actual_child)
+        g_object_unref(actual_child);
+    if (actual_sibling)
+        g_object_unref(actual_sibling);
 }
 
 void
@@ -52,6 +135,8 @@
 {
     folder = KZ_BOOKMARK_FOLDER(kz_bookmark_folder_new("Test Folder"));
     cut_assert(folder);
+
+    connect_signals();
     cut_assert_true(kz_bookmark_is_folder(folder));
 }
 
@@ -99,12 +184,15 @@
     child = kz_bookmark_new_with_attrs("Title", "URI", "Description");
     kz_bookmark_folder_append(folder, child);
 
+    wait_signal(&n_insert_child_received, 1);
     cut_assert_true(kz_bookmark_folder_has_children(folder));
 
     children = kz_bookmark_folder_get_children(folder);
     cut_assert_equal_int(1, g_list_length(children));
 
     cut_assert_equal_pointer(children->data, child);
+    cut_assert_equal_pointer(child, actual_child);
+    cut_assert_null(actual_sibling);
 }
 
 void
@@ -115,10 +203,13 @@
     another_child = kz_bookmark_new_with_attrs("Title", "Another URI", "Description");
     kz_bookmark_folder_prepend(folder, another_child);
 
+    wait_signal(&n_insert_child_received, 1);
     children = kz_bookmark_folder_get_children(folder);
     cut_assert_equal_int(2, g_list_length(children));
 
     cut_assert_equal_pointer(children->data, another_child);
+    cut_assert_equal_pointer(another_child, actual_child);
+    cut_assert_null(actual_sibling);
 }
 
 void
@@ -131,10 +222,14 @@
     another_child = kz_bookmark_new_with_attrs("Title", "URI", "Description");
     kz_bookmark_folder_insert_before(folder, another_child, child);
 
+    wait_signal(&n_insert_child_received, 1);
     children = kz_bookmark_folder_get_children(folder);
     cut_assert_equal_int(2, g_list_length(children));
 
     cut_assert_equal_pointer(children->data, another_child);
+
+    cut_assert_equal_pointer(another_child, actual_child);
+    cut_assert_equal_pointer(child, actual_sibling);
 }
 
 void
@@ -143,7 +238,10 @@
     cut_trace(test_append());
 
     kz_bookmark_folder_remove(folder, child);
+    wait_signal(&n_remove_child_received, 1);
+
     cut_assert_false(kz_bookmark_folder_has_children(folder));
+    cut_assert_equal_pointer(child, actual_child);
 }
 
 void
@@ -152,7 +250,10 @@
     cut_trace(test_prepend());
 
     kz_bookmark_folder_remove_all(folder);
+    wait_signal(&n_remove_child_received, 2);
+
     cut_assert_false(kz_bookmark_folder_has_children(folder));
+    cut_assert_equal_pointer(another_child, actual_child);
 }
 
 void




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