File: type-flags.c

package info (click to toggle)
gobject-introspection 1.74.0-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 68,092 kB
  • sloc: ansic: 524,161; xml: 32,098; python: 21,234; yacc: 1,707; perl: 1,411; sh: 1,044; lex: 499; cpp: 171; makefile: 77; lisp: 1
file content (88 lines) | stat: -rw-r--r-- 1,834 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// SPDX-License-Identifier: LGPL-2.1-or-later
// SPDX-FileCopyrightText: 2021  Emmanuele Bassi

#include <glib-object.h>

#define TEST_TYPE_FINAL (test_final_get_type())
G_DECLARE_FINAL_TYPE (TestFinal, test_final, TEST, FINAL, GObject)

struct _TestFinal
{
  GObject parent_instance;
};

struct _TestFinalClass
{
  GObjectClass parent_class;
};

G_DEFINE_FINAL_TYPE (TestFinal, test_final, G_TYPE_OBJECT)

static void
test_final_class_init (TestFinalClass *klass)
{
}

static void
test_final_init (TestFinal *self)
{
}

#define TEST_TYPE_FINAL2 (test_final2_get_type())
G_DECLARE_FINAL_TYPE (TestFinal2, test_final2, TEST, FINAL2, TestFinal)

struct _TestFinal2
{
  TestFinal parent_instance;
};

struct _TestFinal2Class
{
  TestFinalClass parent_class;
};

G_DEFINE_TYPE (TestFinal2, test_final2, TEST_TYPE_FINAL)

static void
test_final2_class_init (TestFinal2Class *klass)
{
}

static void
test_final2_init (TestFinal2 *self)
{
}

/* test_type_flags_final: Check that trying to derive from a final class
 * will result in a warning from the type system
 */
static void
test_type_flags_final (void)
{
  GType final2_type;

  /* This is the message we print out when registering the type */
  g_test_expect_message ("GLib-GObject", G_LOG_LEVEL_WARNING,
                         "*cannot derive*");

  /* This is the message when we fail to return from the GOnce init
   * block within the test_final2_get_type() function
   */
  g_test_expect_message ("GLib", G_LOG_LEVEL_CRITICAL,
                         "*g_once_init_leave: assertion*");

  final2_type = TEST_TYPE_FINAL2;
  g_assert_true (final2_type == G_TYPE_INVALID);

  g_test_assert_expected_messages ();
}

int
main (int argc, char *argv[])
{
  g_test_init (&argc, &argv, NULL);

  g_test_add_func ("/type/flags/final", test_type_flags_final);

  return g_test_run ();
}