Debian Codegraph @

testsuite/test-test.c

raw symbols SCIP
1 /* test-test.c
2 *
3 * Copyright 2026 Christian Hergert
4 *
5 * This library is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU Lesser General Public License as
7 * published by the Free Software Foundation; either version 2.1 of the
8 * License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * SPDX-License-Identifier: LGPL-2.1-or-later
19 */
20
21 #include "config.h"
22
23 #include <libdex.h>
24
25 static gboolean did_flush;
26
27 static gboolean
28 mark_flushed_cb (gpointer user_data)
29 {
30 did_flush = TRUE;
31
32 return G_SOURCE_REMOVE;
33 }
34
35 static gboolean
36 resolve_cb (gpointer user_data)
37 {
38 DexPromise *promise = user_data;
39
40 dex_promise_resolve_boolean (promise, TRUE);
41 dex_unref (promise);
42
43 return G_SOURCE_REMOVE;
44 }
45
46 static void
47 test_test_add_func (void)
48 {
49 GError * error = NULL;
50 DexPromise * promise = NULL;
51
52 g_assert_true (DEX_IS_SCHEDULER (dex_scheduler_get_thread_default ()));
53
54 promise = dex_promise_new ();
55 g_idle_add (resolve_cb, dex_ref (promise));
56
57 g_assert_true (dex_await (dex_ref (promise), &error));
58 g_assert_no_error (error);
59
60 g_idle_add (mark_flushed_cb, NULL);
61 }
62
63 static void
64 test_test_add_func_flushed (void)
65 {
66 g_assert_true (did_flush);
67 }
68
69 int
70 main (int argc,
71 char *argv[])
72 {
73 dex_init ();
74 g_test_init (&argc, &argv, NULL);
75 dex_test_add_func ("/Dex/TestSuite/Test/add_func", test_test_add_func);
76 g_test_add_func ("/Dex/TestSuite/Test/add_func/flushed", test_test_add_func_flushed);
77 return g_test_run ();
78 }