1 /* Unit tests for GMainLoop
2 * Copyright (C) 2011 Red Hat, Inc
3 * Author: Matthias Clasen
5 * This work is provided "as is"; redistribution and modification
6 * in whole or in part, in any medium, physical or electronic is
7 * permitted without restriction.
9 * This work is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 * In no event shall the authors or contributors be liable for any
14 * direct, indirect, incidental, special, exemplary, or consequential
15 * damages (including, but not limited to, procurement of substitute
16 * goods or services; loss of use, data, or profits; or business
17 * interruption) however caused and on any theory of liability, whether
18 * in contract, strict liability, or tort (including negligence or
19 * otherwise) arising in any way out of the use of this software, even
20 * if advised of the possibility of such damage.
26 test_maincontext_basic (void)
33 ctx = g_main_context_new ();
35 g_assert (!g_main_context_pending (ctx));
36 g_assert (!g_main_context_iteration (ctx, FALSE));
38 source = g_source_new (&funcs, sizeof (GSource));
39 g_assert (g_source_get_priority (source) == G_PRIORITY_DEFAULT);
41 g_assert (!g_source_get_can_recurse (source));
42 g_assert (g_source_get_name (source) == NULL);
44 g_source_set_can_recurse (source, TRUE);
45 g_source_set_name (source, "d");
47 g_assert (g_source_get_can_recurse (source));
48 g_assert_cmpstr (g_source_get_name (source), ==, "d");
50 g_assert (g_main_context_find_source_by_user_data (ctx, NULL) == NULL);
51 g_assert (g_main_context_find_source_by_funcs_user_data (ctx, &funcs, NULL) == NULL);
53 id = g_source_attach (source, ctx);
54 g_assert_cmpint (g_source_get_id (source), ==, id);
55 g_assert (g_main_context_find_source_by_id (ctx, id) == source);
57 g_source_set_priority (source, G_PRIORITY_HIGH);
58 g_assert (g_source_get_priority (source) == G_PRIORITY_HIGH);
60 g_main_context_unref (ctx);
64 test_mainloop_basic (void)
69 loop = g_main_loop_new (NULL, FALSE);
71 g_assert (!g_main_loop_is_running (loop));
73 g_main_loop_ref (loop);
75 ctx = g_main_loop_get_context (loop);
76 g_assert (ctx == g_main_context_default ());
78 g_main_loop_unref (loop);
80 g_assert (g_main_depth () == 0);
84 main (int argc, char *argv[])
86 g_test_init (&argc, &argv, NULL);
88 g_test_add_func ("/maincontext/basic", test_maincontext_basic);
89 g_test_add_func ("/mainloop/basic", test_mainloop_basic);