[glib] Add some GHookList tests
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib] Add some GHookList tests
- Date: Sun, 9 Oct 2011 03:50:39 +0000 (UTC)
commit 30b320b61c34f953bf7b7bbc27d978c321fe1c4d
Author: Matthias Clasen <mclasen redhat com>
Date: Sat Oct 8 12:43:12 2011 -0400
Add some GHookList tests
glib/tests/Makefile.am | 3 ++
glib/tests/hook.c | 95 ++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 98 insertions(+), 0 deletions(-)
---
diff --git a/glib/tests/Makefile.am b/glib/tests/Makefile.am
index 96caa04..6a7aafe 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 0000000..5f139a8
--- /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 ();
+}
+
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]