Simplify subprocesses in tests
[platform/upstream/glib.git] / glib / tests / hook.c
1 /* Unit tests for hook lists
2  * Copyright (C) 2011 Red Hat, Inc.
3  *
4  * This work is provided "as is"; redistribution and modification
5  * in whole or in part, in any medium, physical or electronic is
6  * permitted without restriction.
7  *
8  * This work is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11  *
12  * In no event shall the authors or contributors be liable for any
13  * direct, indirect, incidental, special, exemplary, or consequential
14  * damages (including, but not limited to, procurement of substitute
15  * goods or services; loss of use, data, or profits; or business
16  * interruption) however caused and on any theory of liability, whether
17  * in contract, strict liability, or tort (including negligence or
18  * otherwise) arising in any way out of the use of this software, even
19  * if advised of the possibility of such damage.
20  *
21  * Author: Matthias Clasen
22  */
23
24 #include "glib.h"
25
26 static void
27 hook_func (gpointer data)
28 {
29 }
30
31 static void
32 destroy (gpointer data)
33 {
34 }
35
36 static void
37 test_hook1 (void)
38 {
39   GHookList *hl;
40   GHook *hook;
41   gulong id;
42   GHook *h;
43
44   hl = g_new (GHookList, 1);
45   g_hook_list_init (hl, sizeof (GHook));
46
47   hook = g_hook_alloc (hl);
48   hook->data = GINT_TO_POINTER(1);
49   hook->func = hook_func;
50   hook->flags = G_HOOK_FLAG_ACTIVE;
51   hook->destroy = destroy;
52   g_hook_append (hl, hook);
53   id = hook->hook_id;
54
55   h = g_hook_get (hl, id);
56   g_assert (h == hook);
57
58   h = hook = g_hook_alloc (hl);
59   hook->data = GINT_TO_POINTER(2);
60   hook->func = hook_func;
61   hook->flags = G_HOOK_FLAG_ACTIVE;
62   hook->destroy = destroy;
63   g_hook_prepend (hl, hook);
64
65   g_hook_destroy (hl, id);
66
67   hook = g_hook_alloc (hl);
68   hook->data = GINT_TO_POINTER(3);
69   hook->func = hook_func;
70   hook->flags = G_HOOK_FLAG_ACTIVE;
71   hook->destroy = destroy;
72   g_hook_insert_sorted (hl, hook, g_hook_compare_ids);
73
74   hook = g_hook_alloc (hl);
75   hook->data = GINT_TO_POINTER(4);
76   hook->func = hook_func;
77   hook->flags = G_HOOK_FLAG_ACTIVE;
78   hook->destroy = destroy;
79   g_hook_insert_before (hl, h, hook);
80
81   g_hook_list_invoke (hl, TRUE);
82
83   g_hook_list_clear (hl);
84   g_free (hl);
85 }
86
87 int main (int argc, char *argv[])
88 {
89   g_test_init (&argc, &argv, NULL);
90
91   g_test_add_func ("/hook/test1", test_hook1);
92
93   return g_test_run ();
94 }
95