Add two new functions to check sequence return values. Also fixes a
[platform/upstream/gobject-introspection.git] / tests / parser / foo.c
1 #define FOO_SUCCESS_INT 0x1138
2
3 #include "foo-object.h"
4
5 typedef struct
6 {
7   int i;
8 } PrivateStruct;
9
10 void foo_private_function (FooObject *foo)
11 {
12
13 }
14
15 GType
16 foo_interface_get_type (void)
17 {
18   static GType object_type = 0;
19
20   if (!object_type)
21     {
22       object_type = g_type_register_static_simple (G_TYPE_INTERFACE,
23                                                    "FooInterface",
24                                                    sizeof (FooInterfaceIface),
25                                                    NULL, 0, NULL, 0);
26
27       g_type_interface_add_prerequisite (object_type, G_TYPE_OBJECT);
28     }
29
30   return object_type;
31 }
32
33
34 enum {
35   PROP_0,
36   PROP_STRING
37 };
38
39 enum {
40   SIGNAL,
41   LAST_SIGNAL
42 };
43
44 static guint foo_object_signals[LAST_SIGNAL] = { 0 };
45
46 G_DEFINE_TYPE (FooObject, foo_object, G_TYPE_OBJECT);
47
48 static void
49 foo_object_set_property (GObject         *object,
50                          guint            prop_id,
51                          const GValue    *value,
52                          GParamSpec      *pspec)
53 {
54   FooObject *foo = FOO_OBJECT (object);
55
56   switch (prop_id)
57     {
58     case PROP_STRING:
59       break;
60     default:
61       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
62       break;
63     }
64 }
65
66 static void
67 foo_object_get_property (GObject         *object,
68                          guint            prop_id,
69                          GValue          *value,
70                          GParamSpec      *pspec)
71 {
72   FooObject *foo = FOO_OBJECT (object);
73
74   switch (prop_id)
75     {
76     case PROP_STRING:
77       break;
78     default:
79       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
80       break;
81     }
82 }
83
84 static void
85 foo_object_class_init (FooObjectClass *klass)
86 {
87   GObjectClass *gobject_class;
88
89   gobject_class = G_OBJECT_CLASS (klass);
90
91   gobject_class->set_property = foo_object_set_property;
92   gobject_class->get_property = foo_object_get_property;
93
94   g_object_class_install_property (gobject_class,
95                                    PROP_STRING,
96                                    g_param_spec_string ("string",
97                                                         "String nick",
98                                                         "The String Property Blurb",
99                                                         NULL,
100                                                         G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
101   foo_object_signals[SIGNAL] =
102     g_signal_new ("signal",
103                   G_OBJECT_CLASS_TYPE (gobject_class),
104                   G_SIGNAL_RUN_LAST,
105                   0,
106                   NULL, NULL,
107                   (GSignalCMarshaller)g_cclosure_marshal_STRING__OBJECT_POINTER,
108                   G_TYPE_STRING, 2, G_TYPE_OBJECT, G_TYPE_POINTER);
109
110 }
111
112 static void
113 foo_object_init (FooObject *object)
114 {
115
116 }
117
118 /**
119  * foo_object_method:
120  * @object: a #GObject
121  *
122  * Return value: an int
123  **/
124 gint
125 foo_object_method (FooObject *object)
126 {
127         return 1;
128 }
129
130 UtilityObject*
131 foo_object_external_type (FooObject *object)
132 {
133
134 }
135
136 /**
137  * foo_object_out:
138  * @object: a #GObject
139  *
140  * This is a test for out arguments
141  *
142  * @outarg: (out): This is an argument test
143  * Return value: an int
144  */
145 gint
146 foo_object_in (FooObject *object, int *outarg)
147 {
148         return 1;
149 }
150
151 /**
152  * foo_object_in:
153  * @object: a #GObject
154  *
155  * This is a test for out arguments
156  *
157  * @outarg: (in): This is an argument test
158  * Return value: an int
159  */
160 gint
161 foo_object_out (FooObject *object, int *outarg)
162 {
163         return 1;
164 }
165
166
167 /**
168  * foo_object_inout:
169  * @object: a #GObject
170  *
171  * This is a test for out arguments
172  *
173  * @inoutarg: (inout): This is an argument test
174  * Return value: an int
175  */
176 gint
177 foo_object_inout (FooObject *object, int *inoutarg)
178 {
179         return 1;
180 }
181
182 /**
183  * foo_object_inout2:
184  * @object: a #GObject
185  *
186  * This is a second test for out arguments
187  *
188  * @inoutarg: (in) (out): This is an argument test
189  * Return value: an int
190  */
191 gint
192 foo_object_inout2 (FooObject *object, int *inoutarg)
193 {
194         return 1;
195 }
196
197
198 /**
199  * foo_object_inout3:
200  * @object: a #GObject
201  *
202  * This is a 3th test for out arguments
203  *
204  * @inoutarg: (in-out): This is an argument test
205  * Return value: an int
206  */
207 gint
208 foo_object_inout3 (FooObject *object, int *inoutarg)
209 {
210         return 1;
211 }
212
213 /**
214  * foo_object_calleeowns:
215  * @object: a #GObject
216  *
217  * This is a test for out arguments
218  *
219  * @toown: (callee-owns): a #GObject
220  * Return value: an int
221  */
222 gint
223 foo_object_calleeowns (FooObject *object, GObject *toown)
224 {
225         return 1;
226 }
227
228
229 /**
230  * foo_object_calleesowns:
231  * @object: a #GObject
232  *
233  * This is a test for out arguments
234  *
235  * @toown1: (callee-owns): a #GObject
236  * @toown2: (callee-owns): a #GObject
237  * Return value: an int
238  */
239 gint
240 foo_object_calleesowns (FooObject *object, GObject *toown1, GObject *toown2)
241 {
242         return 1;
243 }
244
245
246 /**
247  * foo_object_get_strings:
248  * @object: a #GObject
249  *
250  * This is a test for returning a list of strings
251  *
252  * Return value: (seq char* (callee-owns)) (caller-owns): list of strings
253  */
254 GList*
255 foo_object_get_strings (FooObject *object)
256 {
257   GList *list = NULL;
258   list = g_list_prepend (list, "foo");
259   list = g_list_prepend (list, "bar");
260   return list;
261 }
262
263 /**
264  * foo_object_get_objects:
265  * @object: a #GObject
266  *
267  * This is a test for returning a list of objects.
268  * The list itself should be freed, but not the internal objects,
269  * intentionally similar example to gtk_container_get_children
270  *
271  * Return value: (seq FooObject* (callee-owns)) (caller-owns): a list
272  *               of strings
273  */
274 GSList*
275 foo_object_get_objects (FooObject *object)
276 {
277   GSList *list = NULL;
278   list = g_slist_prepend (list, object);
279   return list;
280 }
281
282 /**
283  * foo_object_create_object:
284  * @object: a #GObject
285  *
286  * Test returning a caller-owned object
287  *
288  * Return value: (caller-owns): The object
289  **/
290 GObject*
291 foo_object_create_object (FooObject *object)
292 {
293         return g_object_ref (object);
294 }
295
296 G_DEFINE_TYPE (FooSubobject, foo_subobject, FOO_TYPE_OBJECT);
297
298 static void
299 foo_subobject_class_init (FooSubobjectClass *klass)
300 {
301
302 }
303
304 static void
305 foo_subobject_init (FooSubobject *object)
306 {
307
308 }
309
310 int foo_init (void)
311 {
312   return FOO_SUCCESS_INT;
313 }
314
315 int foo_init_argv (int argc, char **argv)
316 {
317   return FOO_SUCCESS_INT;
318 }
319
320 int foo_init_argv_address (int *argc, char ***argv)
321 {
322   return FOO_SUCCESS_INT;
323 }
324
325 GType
326 foo_enum_type_get_type (void)
327 {
328     static GType etype = 0;
329     if (G_UNLIKELY(etype == 0)) {
330         static const GEnumValue values[] = {
331             { FOO_ENUM_ALPHA, "FOO_ENUM_ALPHA", "alpha" },
332             { FOO_ENUM_BETA, "FOO_ENUM_BETA", "beta" },
333             { FOO_ENUM_DELTA, "FOO_ENUM_DELTA", "delta" },
334             { 0, NULL, NULL }
335         };
336         etype = g_enum_register_static (g_intern_static_string ("FooEnumType"), values);
337     }
338     return etype;
339 }
340
341 int foo_enum_method (FooEnumType foo_enum)
342 {
343   return 0;
344 }
345
346
347 GType
348 foo_flags_type_get_type (void)
349 {
350     static GType etype = 0;
351     if (G_UNLIKELY(etype == 0)) {
352         static const GFlagsValue values[] = {
353             { FOO_FLAGS_FIRST, "FOO_FLAGS_FIRST", "first" },
354             { FOO_FLAGS_SECOND, "FOO_FLAGS_SECOND", "second" },
355             { FOO_FLAGS_THIRD, "FOO_FLAGS_THIRD", "third" },
356             { 0, NULL, NULL }
357         };
358         etype = g_flags_register_static (g_intern_static_string ("FooFlagsType"), values);
359     }
360     return etype;
361 }
362
363 struct _FooBoxed
364 {
365   int private;
366 };
367
368
369 FooBoxed *
370 foo_boxed_copy (const FooBoxed *boxed)
371 {
372   return (FooBoxed *)g_memdup (boxed, sizeof (FooBoxed));
373 }
374
375 void
376 foo_boxed_free (FooBoxed *boxed)
377 {
378   g_slice_free (FooBoxed, boxed);
379 }
380
381
382 GType
383 foo_boxed_get_type (void)
384 {
385   static GType our_type = 0;
386   
387   if (our_type == 0)
388     our_type = g_boxed_type_register_static ("FooBoxed",
389                                              (GBoxedCopyFunc) foo_boxed_copy,
390                                              (GBoxedFreeFunc) foo_boxed_free);
391   return our_type;
392 }
393
394 FooBoxed *
395 foo_boxed_new (void)
396 {
397   return g_slice_new0 (FooBoxed);
398 }
399
400 void
401 foo_boxed_method (FooBoxed *boxed)
402 {
403
404 }