summaryrefslogtreecommitdiff
path: root/tests/girwriter/girtest.vala
blob: 1125bfa1cb9a75fca48be794b145f1f625adce57 (plain)
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
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
[CCode (gir_namespace = "GirTest", gir_version = "1.0")]
namespace GirTest {
	public struct BoxedStruct {
		public int field_name;
		internal int internal_field_name;

		public BoxedStruct () {
		}

		public BoxedStruct.foo (int param1, int param2) {
			field_name = param1;
			internal_field_name = param2;
		}

		public void inv () {
		}

		public BoxedStruct ret () {
			return this;
		}
	}

	[CCode (has_type_id = false)]
	public struct Struct {
		public int field_name;
		internal int internal_field_name;

		public Struct () {
		}

		public Struct.foo (int param1, int param2) {
			field_name = param1;
			internal_field_name = param2;
		}

		public void inv () {
		}

		public Struct ret () {
			return this;
		}
	}

	[GIR (visible = false)]
	public struct SkippedStruct {
		public int field_name;
	}

	[GIR (name = "RenamedStruct")]
	public struct NamedStruct {
		public int field_name;
	}

	public const int CONSTANT_NUMBER = 42;
	public const string CONSTANT_STRING = "const ♥ utf8";
	[GIR (name = "RENAMED_CONSTANT")]
	public const int NAMED_CONSTANT = 23;

	public const bool TRUE_LITERAL = true;
	public const bool FALSE_LITERAL = false;
	public const char CHAR_LITERAL = 'y';
	public const double REAL_LITERAL = 3.1415;
	public const float FLOAT_LITERAL = -3.1415f;
	public const int INTEGER_LITERAL = -42;

	public enum EnumTest {
		VALUE1,
		VALUE2,
		VALUE3 = 4711
	}

	[Flags]
	public enum FlagsTest {
		VALUE1,
		VALUE2,
		VALUE3
	}

	[CCode (has_type_id = false)]
	public enum PlainEnumTest {
		VALUE1,
		VALUE2,
		VALUE3 = 4711
	}

	[GIR (visible = false)]
	public enum SkippedEnum {
		VALUE1
	}

	[GIR (visible = false)]
	[Flags]
	public enum SkippedFlags {
		VALUE1
	}

	[GIR (name = "RenamedEnumeration")]
	public enum NamedEnumeration {
		VALUE1
	}

	[GIR (name = "RenamedBitfield")]
	[Flags]
	public enum NamedBitfield {
		VALUE1
	}

	public errordomain ErrorTest {
		FAILED,
		SMELLY,
		FISHY = 23
	}

	[CCode (has_type_id = false)]
	public errordomain PlainErrorTest {
		FAILED,
		SMELLY,
		FISHY = 23
	}

	[GIR (name = "RenamedError")]
	public errordomain NamedError {
		FAILED
	}

	public interface InterfaceTest : Object {
		public abstract int property { get; construct set; }
		internal abstract string internal_property { get; set; }
		public virtual void int8_in (int8 param) {
		}
		public virtual async void coroutine_async () {
		}
		public virtual void method_valist (int param, va_list vargs) {
		}
		[GIR (visible = false)]
		public virtual async void skipped_coroutine_method (int param) {
		}
		internal virtual void internal_method () {
		}
		[NoWrapper]
		public virtual void no_wrapper_method () {
		}
		[NoWrapper]
		public virtual async void no_wrapper_method_async () {
		}
		public virtual void method_implicit_params (int[] param1, owned DelegateTest param2) {
		}
		[HasEmitter]
		public signal void some_signal (int param);
		public static void static_method () {
		}
	}

	[GIR (visible = false)]
	public interface SkippedInterface {
	}

	[GIR (name = "RenamedInterface")]
	public interface NamedInterface : Object {
	}

	public delegate bool DelegateTest (void* a, void* b);

	public delegate bool DelegateErrorTest () throws ErrorTest;

	public delegate bool DelegateGenericsTest<G,T> (G g, T? t);

	[GIR (visible = false)]
	public delegate void SkippedDelegate ();

	[GIR (name = "RenamedDelegate")]
	public delegate void NamedDelegate ();

	public class TypeTest {
		public string some_property { get; set; }
	}

	public class SubTypeTest : TypeTest {
		public string[] array_field;
		public DelegateTest delegate_field;
	}

	public class ObjectTest : Object {
		private static ObjectTest global_instance = new ObjectTest ();

		internal static int internal_global_field = 4711;

		public signal void some_signal (int param);

		[GIR (visible = false)]
		public signal void skipped_signal (int param);

		public int field = 42;

		internal int internal_field = 23;

		public int fixed_array_field[23];

		public string? nullable_field;

		public string some_property { get; construct set; }

		public string write_only_property { set; }

		public string construct_only_property { construct; }

		internal string internal_property { get; set; }

		[GIR (visible = false)]
		public string skipped_property { get; construct set; }

		public ObjectTest () {
		}
		public ObjectTest.with_int (int param) {
			field = param;
		}
		public ObjectTest.may_fail (int param) throws ErrorTest {
			field = param;
		}
		public ObjectTest.newv (int param, ...) {
			field = param;
		}
		public ObjectTest.new_valist (int param, va_list vargs) {
			field = param;
		}
		public static void full_inout (ref ObjectTest obj) {
			assert (obj.field == 42);
			obj = new ObjectTest ();
		}
		public static void full_out (out ObjectTest obj) {
			obj = new ObjectTest ();
		}
		public static ObjectTest full_return () {
			return new ObjectTest ();
		}
		public static void none_inout (ref unowned ObjectTest obj) {
			assert (obj.field == 42);
			obj = global_instance;
		}
		public static void none_out (out unowned ObjectTest obj) {
			obj = global_instance;
		}
		public static unowned ObjectTest none_return () {
			return global_instance;
		}

		public static void static_method () {
		}

		public virtual void method_with_default_impl (int8 param) {
		}

		internal virtual void internal_method_with_default_impl (int8 param) {
		}

		public void int8_in (int8 param) {
		}

		public void int8_out (out int8 param) {
			param = 42;
		}

		public void method () {
		}

		public void method_varargs (int param, ...) {
		}

		public void method_valist (int param, va_list vargs) {
		}

		public void array_in (int[] array) {
		}

		public void array_inout (ref int[] array) {
			assert (array.length > 0);
			array = new int[8];
		}

		public void array_out (out int[] array) {
			array = new int[8];
		}

		public int[] array_return () {
			return new int[8];
		}

		public void int_in_int_in_array_out (int param1, int param2, out int[] array) {
			array = new int[8];
		}

		public int[] int_in_int_in_array_return (int param1, int param2) {
			return new int[8];
		}

		public void string_array_out (out string[] array) {
			array = { "foo" };
		}

		public string[] string_array_return () {
			return { "foo" };
		}

		public void none_in () {
		}

		public DelegateTest delegate_return () {
			return (val1, val2) => { return (void*)val1 == (void*)val2; };
		}

		public DelegateTest delegate_return_int_in_array_out (int i1, out int[] a) {
			a = new int[8];
			return delegate_return ();
		}

		public int[] array_return_int_in_delegate_out (int i1, out DelegateTest d) {
			d = delegate_return ();
			return new int[8];
		}

		public EqualFunc<string> simple_delegate_return () {
			return str_equal;
		}

		public (unowned string)[] container_return () {
			return { "foo", "bar" };
		}

		public GenericArray<unowned string>? generic_array_container_return () {
			return null;
		}

		public async void coroutine_async () {
		}

		public virtual async void coroutine_virtual_async () {
		}

		public virtual async void coroutine_method_throw (int i1, out int o1) throws ErrorTest {
			o1 = i1;
		}

		public void simple_throw () throws ErrorTest {
		}

		public virtual void method_throw () throws ErrorTest {
		}

		public void method_with_default (int i = Priority.HIGH) {
		}

		public virtual signal void signal_with_default_handlder (int i1) {
		}

		[GIR (visible = false)]
		public void skipped_method () {
		}

		[NoWrapper]
		public virtual void no_wrapper_method () {
		}

		[NoWrapper]
		public virtual async void no_wrapper_method_async () {
		}

		public virtual void method_implicit_params (int[] param1, owned DelegateTest param2) {
		}
	}

	public abstract class AbstractObjectTest : Object {
		public abstract void method_int8_in (int8 param);

		public abstract void method_int8_inout (ref int8 param);

		public abstract void method_int8_out (out int8 param);

		public abstract void method_throw () throws ErrorTest;

		public abstract void method_valist (int param, va_list vargs);

		[GIR (visible = false)]
		public abstract async void skipped_coroutine_method (int param);

		internal abstract void internal_method (int8 param);

		[NoWrapper]
		public abstract void no_wrapper_method ();

		[NoWrapper]
		public abstract async void no_wrapper_method_async ();

		public abstract void method_implicit_params (int[] param1, owned DelegateTest param2);
	}

	public sealed class SealedObjectTest : Object {
	}

	public interface PrerequisiteTest : InterfaceTest {
	}

	public class ImplementionTest : Object, InterfaceTest {
		public int property { get; construct set; }
		internal string internal_property { get; set; }
	}

	[Compact]
	public class CompactClass {
		public string s;
		public int i;
	}

	[GIR (visible = false)]
	public class SkippedClass {
	}

	[Version (deprecated = true, deprecated_since = "0.1.2", since = "0.1.0")]
	public class DeprecatedClassTest {
	}

	[GIR (name = "RenamedClass")]
	public class NamedClass {
	}

	[GIR (name = "RenamedCompactClass")]
	[Compact]
	public class NamedCompactClass {
		public string s;
		public int i;
	}

	public class GenericsTest<G,T> {
		public GenericsTest (owned DelegateTest cb) {
		}

		public GenericsTest.typed (owned DelegateGenericsTest<G,T> cb) {
		}

		public void method (T? param) {
		}
	}

	public class GenericsObjectTest<G,T> : Object {
		public void method<K> (K[] param) {
		}
	}

	namespace Nested {
		public void function () {
		}
	}

	public NamedClass use_renamed_class (NamedClass param) {
		return param;
	}
	public unowned NamedCompactClass use_renamed_compact_class (NamedCompactClass param) {
		return param;
	}
	public NamedInterface use_renamed_interface (NamedInterface param) {
		return param;
	}
	public NamedStruct? use_renamed_struct (NamedStruct param) {
		return param;
	}
	public NamedEnumeration use_renamed_enumeration (NamedEnumeration param) {
		return param;
	}
	public NamedBitfield use_renamed_flags (NamedBitfield param) {
		return param;
	}
	public unowned NamedDelegate use_renamed_delegate (NamedDelegate param) {
		return param;
	}
	public NamedError use_renamed_error (NamedError param) {
		return param;
	}
}

public enum InvalidEnum {
	VALUE
}

public errordomain InvalidError {
	FAILED
}

public class InvalidClass {
}

public interface InvalidIface {
}

public struct InvalidStruct {
	public int i;
}

public delegate void InvalidFunc ();

public const int INVALID_CONST = 0;

public int invalid_field;

public void invalid_method () {
}