summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2011-10-08 12:43:12 -0400
committerMatthias Clasen <mclasen@redhat.com>2011-10-08 19:02:06 -0400
commit30b320b61c34f953bf7b7bbc27d978c321fe1c4d (patch)
treea89d45126534ec8cbbbc424940be05d13a7ac2ce
parent6109db27aec99f456c5bbda27bd4afe851b5bcff (diff)
downloadglib-30b320b61c34f953bf7b7bbc27d978c321fe1c4d.tar.gz
Add some GHookList tests
-rw-r--r--glib/tests/Makefile.am3
-rw-r--r--glib/tests/hook.c95
2 files changed, 98 insertions, 0 deletions
diff --git a/glib/tests/Makefile.am b/glib/tests/Makefile.am
index 96caa04e1..6a7aafe4d 100644
--- a/glib/tests/Makefile.am
+++ b/glib/tests/Makefile.am
@@ -215,6 +215,9 @@ thread_LDADD = $(progs_ldadd)
TEST_PROGS += slice
slice_LDADD = $(progs_ldadd)
+TEST_PROGS += hook
+hook_LDADD = $(progs_ldadd)
+
if OS_UNIX
TEST_PROGS += unix
diff --git a/glib/tests/hook.c b/glib/tests/hook.c
new file mode 100644
index 000000000..5f139a85c
--- /dev/null
+++ b/glib/tests/hook.c
@@ -0,0 +1,95 @@
+/* Unit tests for hook lists
+ * Copyright (C) 2011 Red Hat, Inc.
+ *
+ * This work is provided "as is"; redistribution and modification
+ * in whole or in part, in any medium, physical or electronic is
+ * permitted without restriction.
+ *
+ * This work 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.
+ *
+ * In no event shall the authors 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.
+ *
+ * Author: Matthias Clasen
+ */
+
+#include "glib.h"
+
+static void
+hook_func (gpointer data)
+{
+}
+
+static void
+destroy (gpointer data)
+{
+}
+
+static void
+test_hook1 (void)
+{
+ GHookList *hl;
+ GHook *hook;
+ gulong id;
+ GHook *h;
+
+ hl = g_new (GHookList, 1);
+ g_hook_list_init (hl, sizeof (GHook));
+
+ hook = g_hook_alloc (hl);
+ hook->data = GINT_TO_POINTER(1);
+ hook->func = hook_func;
+ hook->flags = G_HOOK_FLAG_ACTIVE;
+ hook->destroy = destroy;
+ g_hook_append (hl, hook);
+ id = hook->hook_id;
+
+ h = g_hook_get (hl, id);
+ g_assert (h == hook);
+
+ h = hook = g_hook_alloc (hl);
+ hook->data = GINT_TO_POINTER(2);
+ hook->func = hook_func;
+ hook->flags = G_HOOK_FLAG_ACTIVE;
+ hook->destroy = destroy;
+ g_hook_prepend (hl, hook);
+
+ g_hook_destroy (hl, id);
+
+ hook = g_hook_alloc (hl);
+ hook->data = GINT_TO_POINTER(3);
+ hook->func = hook_func;
+ hook->flags = G_HOOK_FLAG_ACTIVE;
+ hook->destroy = destroy;
+ g_hook_insert_sorted (hl, hook, g_hook_compare_ids);
+
+ hook = g_hook_alloc (hl);
+ hook->data = GINT_TO_POINTER(4);
+ hook->func = hook_func;
+ hook->flags = G_HOOK_FLAG_ACTIVE;
+ hook->destroy = destroy;
+ g_hook_insert_before (hl, h, hook);
+
+ g_hook_list_invoke (hl, TRUE);
+
+ g_hook_list_clear (hl);
+ g_free (hl);
+}
+
+int main (int argc, char *argv[])
+{
+ g_test_init (&argc, &argv, NULL);
+
+ g_test_add_func ("/hook/test1", test_hook1);
+
+ return g_test_run ();
+}
+