1 /* GLib testing framework examples and tests
2 *
3 * Copyright © 2019 Endless Mobile, Inc.
4 *
5 * SPDX-License-Identifier: LGPL-2.1-or-later
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General
18 * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
19 *
20 * Author: Philip Withnall <withnall@endlessm.com>
21 */
22
23 #include "config.h"
24
25 /* We want to distinguish between messages originating from libglib
26 * and messages originating from this program.
27 */
28 #undef G_LOG_DOMAIN
29 #define G_LOG_DOMAIN "testing"
30
31 #include <glib.h>
32 #include <glib-object.h>
33 #include <locale.h>
34 #include <stdlib.h>
35
36 static void
37 test_assert_finalize_object_subprocess_bad (void)
38 {
39 GObject *obj = g_object_new (G_TYPE_OBJECT, NULL);
40 g_object_ref (obj);
41
42 /* This should emit an assertion failure. */
43 g_assert_finalize_object (obj);
44
45 g_object_unref (obj);
46
47 exit (0);
48 }
49
50 static void
51 test_assert_finalize_object (void)
52 {
53 GObject *obj = g_object_new (G_TYPE_OBJECT, NULL);
54
55 g_assert_finalize_object (obj);
56
57 g_test_trap_subprocess ("/assert/finalize_object/subprocess/bad", 0,
58 G_TEST_SUBPROCESS_DEFAULT);
59 g_test_trap_assert_failed ();
60 g_test_trap_assert_stderr ("*g_assert_finalize_object:*'weak_pointer' should be NULL*");
61 }
62
63 int
64 main (int argc,
65 char *argv[])
66 {
67 g_test_init (&argc, &argv, NULL);
68
69 g_test_add_func ("/assert/finalize_object", test_assert_finalize_object);
70 g_test_add_func ("/assert/finalize_object/subprocess/bad",
71 test_assert_finalize_object_subprocess_bad);
72
73 return g_test_run ();
74 }