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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
|
/*
* Copyright 2022 Simon McVittie
* SPDX-License-Identifier: LGPL-2.1-or-later
*/
#include <glib-object.h>
#include <glib.h>
typedef struct
{
GObject parent;
int normal;
int normal_construct;
int deprecated;
int deprecated_construct;
} MyObject;
typedef struct
{
GObjectClass parent;
} MyObjectClass;
typedef enum
{
PROP_0,
PROP_NORMAL,
PROP_NORMAL_CONSTRUCT,
PROP_DEPRECATED,
PROP_DEPRECATED_CONSTRUCT,
N_PROPS
} Property;
static GParamSpec *props[N_PROPS] = { NULL };
static GType my_object_get_type (void);
G_DEFINE_TYPE (MyObject, my_object, G_TYPE_OBJECT);
static void
my_object_init (MyObject *self)
{
}
static void
my_object_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *param_spec)
{
MyObject *self = (MyObject *) object;
switch ((Property) prop_id)
{
case PROP_NORMAL:
self->normal = g_value_get_int (value);
break;
case PROP_NORMAL_CONSTRUCT:
self->normal_construct = g_value_get_int (value);
break;
case PROP_DEPRECATED:
self->deprecated = g_value_get_int (value);
break;
case PROP_DEPRECATED_CONSTRUCT:
self->deprecated_construct = g_value_get_int (value);
break;
case PROP_0:
case N_PROPS:
default:
g_assert_not_reached ();
}
}
static void
my_object_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *param_spec)
{
MyObject *self = (MyObject *) object;
switch ((Property) prop_id)
{
case PROP_NORMAL:
g_value_set_int (value, self->normal);
break;
case PROP_NORMAL_CONSTRUCT:
g_value_set_int (value, self->normal_construct);
break;
case PROP_DEPRECATED:
g_value_set_int (value, self->deprecated);
break;
case PROP_DEPRECATED_CONSTRUCT:
g_value_set_int (value, self->deprecated_construct);
break;
case PROP_0:
case N_PROPS:
default:
g_assert_not_reached ();
}
}
static void
my_object_class_init (MyObjectClass *cls)
{
GObjectClass *object_class = G_OBJECT_CLASS (cls);
props[PROP_NORMAL] = g_param_spec_int ("normal", NULL, NULL,
G_MININT, G_MAXINT, -1,
(G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS));
props[PROP_NORMAL_CONSTRUCT] = g_param_spec_int ("normal-construct", NULL, NULL,
G_MININT, G_MAXINT, -1,
(G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS |
G_PARAM_CONSTRUCT));
props[PROP_DEPRECATED] = g_param_spec_int ("deprecated", NULL, NULL,
G_MININT, G_MAXINT, -1,
(G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS |
G_PARAM_DEPRECATED));
props[PROP_DEPRECATED_CONSTRUCT] = g_param_spec_int ("deprecated-construct", NULL, NULL,
G_MININT, G_MAXINT, -1,
(G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS |
G_PARAM_CONSTRUCT |
G_PARAM_DEPRECATED));
object_class->get_property = my_object_get_property;
object_class->set_property = my_object_set_property;
g_object_class_install_properties (object_class, N_PROPS, props);
}
static void
test_construct (void)
{
if (g_test_subprocess ())
{
MyObject *o;
/* Don't crash on deprecation warnings, so we can see all of them */
g_log_set_always_fatal (G_LOG_FATAL_MASK);
g_log_set_fatal_mask ("GLib-GObject", G_LOG_FATAL_MASK);
o = g_object_new (my_object_get_type (),
"normal", 1,
"normal-construct", 2,
"deprecated", 3,
"deprecated-construct", 4,
NULL);
g_printerr ("Constructed object");
g_assert_cmpint (o->normal, ==, 1);
g_assert_cmpint (o->normal_construct, ==, 2);
g_assert_cmpint (o->deprecated, ==, 3);
g_assert_cmpint (o->deprecated_construct, ==, 4);
g_clear_object (&o);
return;
}
g_test_trap_subprocess (NULL, 0, G_TEST_SUBPROCESS_DEFAULT);
g_test_trap_assert_stderr ("*The property MyObject:deprecated-construct is deprecated*");
g_test_trap_assert_stderr ("*The property MyObject:deprecated is deprecated*");
g_test_trap_assert_stderr_unmatched ("*The property MyObject:normal*");
g_test_trap_assert_passed ();
}
static void
test_def_construct (void)
{
if (g_test_subprocess ())
{
MyObject *o;
/* Don't crash on deprecation warnings, so we can see all of them */
g_log_set_always_fatal (G_LOG_FATAL_MASK);
g_log_set_fatal_mask ("GLib-GObject", G_LOG_FATAL_MASK);
o = g_object_new (my_object_get_type (),
NULL);
g_printerr ("Constructed object");
g_assert_cmpint (o->normal, ==, 0);
g_assert_cmpint (o->normal_construct, ==, -1);
g_assert_cmpint (o->deprecated, ==, 0);
g_assert_cmpint (o->deprecated_construct, ==, -1);
g_clear_object (&o);
return;
}
g_test_bug ("https://gitlab.gnome.org/GNOME/glib/-/issues/2748");
g_test_trap_subprocess (NULL, 0, G_TEST_SUBPROCESS_DEFAULT);
g_test_trap_assert_stderr_unmatched ("*The property MyObject:deprecated*");
g_test_trap_assert_stderr_unmatched ("*The property MyObject:normal*");
g_test_trap_assert_passed ();
}
static void
test_set (void)
{
if (g_test_subprocess ())
{
MyObject *o;
/* Don't crash on deprecation warnings, so we can see all of them */
g_log_set_always_fatal (G_LOG_FATAL_MASK);
g_log_set_fatal_mask ("GLib-GObject", G_LOG_FATAL_MASK);
o = g_object_new (my_object_get_type (),
NULL);
g_printerr ("Constructed object");
g_assert_cmpint (o->normal, ==, 0);
g_assert_cmpint (o->normal_construct, ==, -1);
g_assert_cmpint (o->deprecated, ==, 0);
g_assert_cmpint (o->deprecated_construct, ==, -1);
g_object_set (o,
"normal", 1,
"normal-construct", 2,
"deprecated", 3,
"deprecated-construct", 4,
NULL);
g_printerr ("Set properties");
g_assert_cmpint (o->normal, ==, 1);
g_assert_cmpint (o->normal_construct, ==, 2);
g_assert_cmpint (o->deprecated, ==, 3);
g_assert_cmpint (o->deprecated_construct, ==, 4);
g_clear_object (&o);
return;
}
g_test_bug ("https://gitlab.gnome.org/GNOME/glib/-/issues/2748");
g_test_trap_subprocess (NULL, 0, G_TEST_SUBPROCESS_DEFAULT);
g_test_trap_assert_stderr ("*The property MyObject:deprecated-construct is deprecated*");
g_test_trap_assert_stderr ("*The property MyObject:deprecated is deprecated*");
g_test_trap_assert_stderr_unmatched ("*The property MyObject:normal*");
g_test_trap_assert_passed ();
}
int
main (int argc, char *argv[])
{
g_test_init (&argc, &argv, NULL);
g_setenv ("G_ENABLE_DIAGNOSTIC", "1", TRUE);
g_test_set_nonfatal_assertions ();
g_test_add_func ("/deprecated-properties/construct", test_construct);
g_test_add_func ("/deprecated-properties/default-construct", test_def_construct);
g_test_add_func ("/deprecated-properties/set", test_set);
return g_test_run ();
}
|