Debian Codegraph @

testsuite/test-util.h

raw symbols SCIP
1 /* test-util.h
2 *
3 * Copyright 2026 Christian Hergert <[email protected]>
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but 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 Lesser General Public License
16 * along with this program; if not, see <http://www.gnu.org/licenses/>.
17 *
18 * SPDX-License-Identifier: LGPL-2.1-or-later
19 */
20
21 #pragma once
22
23 #include <libdex.h>
24
25 G_BEGIN_DECLS
26
27 static inline DexFuture *
28 _dex_test_runner_fiber (gpointer user_data)
29 {
30 GTestFunc func = (GTestFunc) G_CALLBACK (user_data);
31
32 func ();
33 return dex_future_new_true ();
34 }
35
36 static inline DexFuture *
37 _dex_test_runner_quit (DexFuture *future,
38 gpointer user_data)
39 {
40 g_main_loop_quit (user_data);
41 return dex_ref (future);
42 }
43
44 static inline void
45 _dex_test_runner (gconstpointer user_data)
46 {
47 GMainLoop *main_loop = g_main_loop_new (NULL, FALSE);
48
49 dex_init ();
50
51 dex_future_disown (dex_future_finally (dex_scheduler_spawn (NULL,
52 8 * 1024 * 1024,
53 _dex_test_runner_fiber,
54 (gpointer) user_data,
55 NULL),
56 _dex_test_runner_quit,
57 g_main_loop_ref (main_loop),
58 (GDestroyNotify) g_main_loop_unref));
59
60 g_main_loop_run (main_loop);
61 g_main_loop_unref (main_loop);
62 }
63
64 static inline void
65 _g_test_add_func (const char *path,
66 GTestFunc test_func)
67 {
68 g_test_add_data_func (path, test_func, _dex_test_runner);
69 }
70
71 G_END_DECLS