1 /* GLib testing framework examples and tests
2 *
3 * Copyright © 2019 Endless Mobile, Inc.
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
16 * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
17 *
18 * Author: Philip Withnall <withnall@endlessm.com>
19 */
20
21 #include "config.h"
22
23 /* We want to distinguish between messages originating from libglib
24 * and messages originating from this program.
25 */
26 #undef G_LOG_DOMAIN
27 #define G_LOG_DOMAIN "testing"
28
29 #include <glib.h>
30 #include <glib-object.h>
31 #include <locale.h>
32 #include <stdlib.h>
33
34 static void
test_assert_finalize_object_subprocess_bad(void)35 test_assert_finalize_object_subprocess_bad (void)
36 {
37 GObject *obj = g_object_new (G_TYPE_OBJECT, NULL);
38 g_object_ref (obj);
39
40 /* This should emit an assertion failure. */
41 g_assert_finalize_object (obj);
42
43 g_object_unref (obj);
44
45 exit (0);
46 }
47
48 static void
test_assert_finalize_object(void)49 test_assert_finalize_object (void)
50 {
51 GObject *obj = g_object_new (G_TYPE_OBJECT, NULL);
52
53 g_assert_finalize_object (obj);
54
55 g_test_trap_subprocess ("/assert/finalize_object/subprocess/bad", 0, 0);
56 g_test_trap_assert_failed ();
57 g_test_trap_assert_stderr ("*g_assert_finalize_object:*'weak_pointer' should be NULL*");
58 }
59
60 int
main(int argc,char * argv[])61 main (int argc,
62 char *argv[])
63 {
64 g_test_init (&argc, &argv, NULL);
65
66 g_test_add_func ("/assert/finalize_object", test_assert_finalize_object);
67 g_test_add_func ("/assert/finalize_object/subprocess/bad",
68 test_assert_finalize_object_subprocess_bad);
69
70 return g_test_run ();
71 }
72