1 /* Unit tests for hook lists
2 * Copyright (C) 2011 Red Hat, Inc.
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.
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.
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.
21 * Author: Matthias Clasen
27 hook_func (gpointer data
)
32 destroy (gpointer data
)
44 hl
= g_new (GHookList
, 1);
45 g_hook_list_init (hl
, sizeof (GHook
));
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
);
55 h
= g_hook_get (hl
, id
);
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
);
65 g_hook_destroy (hl
, id
);
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
);
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
);
81 g_hook_list_invoke (hl
, TRUE
);
83 g_hook_list_clear (hl
);
87 int main (int argc
, char *argv
[])
89 g_test_init (&argc
, &argv
, NULL
);
91 g_test_add_func ("/hook/test1", test_hook1
);