]> git.draconx.ca Git - gob-dx.git/blob - src/test.gob
Release 2.0.11
[gob-dx.git] / src / test.gob
1 /* this is a TEST file, it's VERY VERY ugly, it's just supposed to test
2    the parser of gob and somewhat test some output as well, you can
3    look in here to see a whole array of different syntax options, but
4    don't expect this to be an easy to read file */
5
6 requires 1.99.0
7
8 %at{
9 /* ALL TOP */
10 %}
11
12 %headertop{
13 /* this should go on the very top of the header */
14
15 %}
16 %ht{
17 /* this should go on the very top of the header as well */
18 %}
19 %ph{
20 /* this should go into the private header */
21 %}
22 %privateheader{
23 /* this should go into the private header as well*/
24 %}
25
26
27 %{
28 #include <stdio.h>
29 #include <gtk/gtk.h>
30 /* the next line is not mandatory, but if gob finds an include in one of
31    the %{ %} sections above the class definitions, it will not put it in
32    the file itself.  So you can this way select where the include file is
33    at */
34 #include "test-object.h"
35 #include "test-object-private.h"
36
37 /* this is to test if the lexer won't get confused by requires inside
38    some c code
39 requires 99.99.99
40 */
41
42 static void jjjj(void);
43
44 #define _(x) x
45 %}
46
47 %h{
48 enum _gob__enum_t {
49         BUDLIKY, BUDLIKY2
50 };
51
52 struct _gob__struct_t {
53         int i, x, y, z;
54 };
55 union _gob__union_t {
56         int i, x, y, z;
57 };
58 void bubu(void);
59
60 /* Fake boxed */
61 #define PACKAGE_TYPE_BOXED 1
62 typedef void * PackageBoxed;
63
64 %}
65 %header{
66 /* this should be in the header, just under bubu prototype */
67 #define TEST_ARRAY 5
68 %}
69
70 enum LAME_CLIENT {
71         IS_CONNECTED,
72         NONE = 9,
73         LAST
74 } Test:Enum;
75
76 flags BUGA_BUGA {
77         ONE,
78         TWO,
79         MANY,
80 } Some:Flags;
81
82 error TEST_OBJECT_ERROR {
83         BAD_THIS,
84         BAD_THAT
85 } Test:Object:Error;
86
87 enum BUBLE {
88         KEIN = 0,
89         STANDARD,
90         STANDARD_RO,
91         KOMPLETT,
92         ALT
93 } Buble:Enum;
94
95 class Test:Object from /*G:Object*/ Gtk:Container
96         (interface Gtk:Tree:Model)
97         /* We can add more interfaces by adding more lines like the above */
98         /* Note that there must exist a GtkTreeModelIface structure */
99 {
100
101         /* function implemented for the Gtk:Tree:Model interface */
102         interface Gtk:Tree:Model
103         private GtkTreeModelFlags
104         get_flags (Gtk:Tree:Model *self (check null type))
105         {
106                 /* FOO */
107                 return (GtkTreeModelFlags)0;
108         }
109
110
111
112         public int test_array[TEST_ARRAY];
113         public int i;
114         argument INT i set { self->i = ARG; } get { ARG = self->i; } ;
115
116         public int testing = 1;
117         argument INT testing link;
118
119         public char * testingstring = {g_strdup("test")}
120                 destroywith g_free;
121         argument POINTER testingstring stringlink;
122
123         public Test:Object * testingobj
124                 unrefwith g_object_unref;
125         argument POINTER testingobj objectlink;
126
127         public Test:Object * testingobjllll
128                 unrefwith gtk_widget_destroy;
129         argument POINTER testingobjllll objectlink;
130
131         public Test:Object * testingobjfoo
132                 unref { if (VAR) g_object_unref (VAR); };
133         argument POINTER testingobjfoo objectlink;
134
135         classwide int foo = 20;
136         argument INT foo link;
137
138         public G:Object * testingobj2
139                 destroy {
140                         if(VAR)
141                                 g_object_unref(G_OBJECT(VAR));
142                 };
143         argument POINTER (type G:Object *) testingobj2 objectlink;
144         
145         argument POINTER (type GObject *) some_object
146                 set { /* set some_object */ }
147                 get { /* get some_object */
148                         ARG=NULL; };
149         argument (CONSTRUCT) LONG (type long) write_only_long
150                 set { /* set write_only_long */ };
151         argument POINTER (type char *) read_only_string
152                 get { /* get readonly_long */
153                         ARG = g_strdup("BLAH"); };
154
155         private char a_property;
156         property CHAR a_property
157                 (nick = _("Nick"),
158                  blurb = _("Blurb"),
159                  minimum = 'a',
160                  maximum = 'Z',
161                  default_value = 'C',
162                  export)
163                 set { self->_priv->a_property = g_value_get_char (VAL); }
164                 get { g_value_set_char (VAL, self->_priv->a_property); };
165
166         property OBJECT foobarblahllll1
167                 (nick = "xxxxxxx1",
168                  blurb = "yyyyyy",
169                  object_type = Gtk:Button)
170                 get { /* FOO1 */ };
171         property OBJECT foobarblahllll2
172                 (nick = "xxxxxxx2",
173                  blurb = "yyyyyy",
174                  object_type = G:Object)
175                 set { /* FOO2 */ };
176
177         private double dblnum;
178         property DOUBLE dblnum
179                 (nick = _("dblnum"),
180                  blurb = _("dblnum"),
181                  minimum = 0.1,
182                  maximum = 99.1,
183                  default_value = 0.3,
184                  flags = CONSTRUCT|CONSTRUCT_ONLY,
185                  export,
186                  link);
187
188         private char *b_property;
189         property STRING b_property
190                 (nick = _("Nick b"),
191                  blurb = _("Blurb b"),
192                  default_value = "default",
193                  type = char *,
194                  flags = CONSTRUCT,
195                  export,
196                  link);
197
198         private Test:Object *objectproperty;
199         property OBJECT objectproperty (nick   = "object",
200                                 blurb  = "obj property",
201                                 object_type = Test:Object,
202                                 link);
203
204         private Test:Enum enum_property;
205         property ENUM enum_property (nick   = "enumprop",
206                                 blurb  = "enumprop",
207                                 enum_type = Test:Enum,
208                                 link);
209
210         private Some:Flags flags_property;
211         property FLAGS flags_property (nick   = "flagsprop",
212                                 blurb  = "flagsprop",
213                                 flags_type = Some:Flags,
214                                 link);
215
216           private PackageBoxed prop;
217           property BOXED prop (nick="prop",
218                                blurb="prop",
219                                boxed_type=Package:Boxed,
220                                link);
221           /* testing old semantics */
222           private PackageBoxed prop2;
223           property BOXED prop2 (nick="prop2",
224                                blurb="prop2",
225                                boxed_type=PACKAGE_TYPE_BOXED,
226                                link);
227
228         private char ov_prop;
229         property CHAR ov_prop
230                 (export,
231                  override)
232                 set { self->_priv->ov_prop = g_value_get_char (VAL); }
233                 get { g_value_set_char (VAL, self->_priv->ov_prop); };
234
235
236         private int j;
237         public GObject * h;
238         public char *bleh;
239         public double array[23][18];
240         protected unsigned long int wagawaga;
241         public int wagawaga_should_be_after_this_in_the_header;
242
243         init(object) {
244                 object->i=0;
245         }
246         class_init(klass);
247
248         /**
249          * new:
250          * @j: foo
251          *
252          * budliky budliky
253          *
254          * Returns: new object
255          */
256         public GObject * new(int j (check > 0)) {
257                 GObject *ret;
258                 ret = G_OBJECT (GET_NEW);
259
260                 SELF(ret)->_priv->j = j;
261
262                 return ret;
263         }
264         private int blah(self, G:Object * wid (check null type),
265                          int h (check > 0)) onerror -1 {
266                 g_object_set (G_OBJECT (self),
267                               TEST_OBJECT_PROP_I (99),
268                               NULL);
269                 return h;
270         }
271         /**
272          * bleh:
273          * @self: foo
274          * @wid: foo
275          * @h: foo
276          *
277          * budliky budliky 2
278          *
279          * Returns: new object
280          **/
281         signal last STRING (POINTER, INT)
282         char * bleh(self, G:Object * wid (check null type),
283                         int h (check > 0)) {
284                 return self_blah(self,wid,h) > 0 ? g_strdup ("foo") : g_strdup ("bar");
285         }
286
287         private
288         char *
289         test_handler (self, GObject *w, int h, gpointer data)
290         {
291                 data = w = NULL;
292                 h = 0;
293                         
294                 return NULL;
295         }
296
297         /**
298          * gtk_weird_button_bleh2:
299          * @self: foo
300          * @wid: foo
301          * @h: foo
302          *
303          * budliky budliky 3
304          *
305          * Returns: new object */
306         signal last INT (POINTER, INT)
307         int bleh2(self, const G:Object * wid (check null type),
308                         int h (check > 0)) {
309
310                 test_object_connect__bleh (self, self_test_handler, NULL);
311                 self_connect__bleh (self, self_test_handler, NULL);
312                 test_object_connect_after__bleh (self, self_test_handler, NULL);
313                 self_connect_after__bleh (self, self_test_handler, NULL);
314                 test_object_connect_data__bleh (self, self_test_handler, NULL, NULL, 0);
315                 self_connect_data__bleh (self, self_test_handler, NULL, NULL, 0);
316
317                 wid = NULL;
318                 h = 0;
319
320                 /* testing multiple marshaller support */
321                 return 0;
322         }
323         /* this should not get documented as it's nonstandard */
324         /**
325          * bloh:
326
327          ******/
328
329         /* Here we are testing how the gtk-doc extraction code error handeling
330            it should just ingore these */
331         /**
332           */
333
334         /** */
335         /**
336          *
337          * bubu
338          *********/
339         /**
340          *
341          * bubu
342          **zblunk*******/
343         /**
344          *
345          * bubu
346          *zblunk*******//**//**/
347         signal first NONE (NONE)
348         void bloh(self);
349         virtual void * bah(self, int h (check > 0)) onerror NULL defreturn 0 {
350                 self_beh(self,h);
351                 return NULL;
352         }
353         virtual int beh(self, int h (check > 0));
354         override(Gtk:Container)
355         void add(Gtk:Container * self (check null type),
356                  Gtk:Widget * wid (check null type)) {
357                 PARENT_HANDLER(self,wid);
358         }
359
360         override(G:Object)
361         void dispatch_properties_changed (G:Object      *object,
362                                           guint    n_pspecs,
363                                           GParamSpec  **pspecs)
364         {
365                 object = NULL;
366                 n_pspecs = 0;
367                 pspecs = NULL;
368                 /* EKI! */
369         }
370
371         public int consttest(self, const gchar *text, ...)
372         {
373                 text = NULL;
374                 return 25;
375         }
376         public int consttest2(self, gchar const *text, ...)
377         {
378                 text = NULL;
379                 return 25;
380         }
381         public int consttest3(self, G:Object const *wid (check null type))
382         {
383                 wid = NULL;
384                 return 25;
385         }
386         public int consttest4(const self)
387         {
388                 return 25;
389         }
390         public int consttest5(self const)
391         {
392                 return 25;
393         }
394         virtual int consttest6(const self)
395         {
396                 return 25;
397         }
398         virtual int consttest7(self const)
399         {
400                 return 25;
401         }
402         public int consttest8(self)
403         {
404                 Self const *selfconst1, *selfconst2;
405                 selfconst1 = SELF_CONST(self);
406                 selfconst2 = TEST_OBJECT_CONST(self);
407                 return 25;
408         }
409         public int consttest9(const self, int i, double b)
410         {
411                 b = 0.0;
412                 i = 0;
413                 return 25;
414         }
415         public int consttest10(self const, int i, double b)
416         {
417                 b = 0.0;
418                 i = 0;
419                 return 25;
420         }
421         signal private first NONE (NONE)
422         void googlegoogle(self)
423         {
424                 puts("TEST1");
425                 self_googlegoogle2(self);
426         }
427         signal first private NONE (NONE)
428         void googlegoogle2(self)
429         {
430                 int array[5][8][9]={{{0}}};
431                 Self *foo = self;
432                 puts("TEST2");
433                 self_testprivvirtual(foo, array);
434         }
435         private signal first NONE (NONE)
436         void googlegoogle3(self)
437         {
438                 puts("TEST3");
439         }
440         protected signal first NONE (NONE)
441         void googlegoogle4(self)
442         {
443                 puts("TEST4");
444         }
445         protected signal first NONE (NONE)
446         void googlegoogle_const1(const self)
447         {
448                 puts("TEST4");
449         }
450         protected signal first NONE (NONE)
451         void googlegoogle_const2(self const)
452         {
453                 puts("TEST4");
454         }
455         virtual private
456         void testprivvirtual(self, int some_array[5][8][9])
457         {
458                 puts("TEST3");
459                 self_googlegoogle(self);
460                 if (some_array[0]) return;
461         }
462         private virtual
463         void testprivvirtual2(self, const int some_array[5][8][9])
464         {
465                 /* nothing here */
466                 if (some_array[0]) return;
467         }
468         public virtual
469         void testpublicvirtual(self, int const some_array[5][8][9])
470         {
471                 /* nothing here */
472                 if (some_array[0]) return;
473         }
474         protected virtual
475         void testprotectedvirtual(self, int some_array[5][8][9])
476         {
477                 /* nothing here */
478                 if (some_array[0]) return;
479         }
480         signal first NONE (POINTER, ENUM)
481         void testarrsignal(self, long arr[8], Buble:Enum foo)
482         {
483                 /* foo */
484                 arr[0] = 1;
485                 foo = BUBLE_KEIN;
486         }
487
488         /* testing empty func */
489         public void foofoofoo(self) {}
490         /* testing empty func 2 */
491         public void foofoofoo2(self);
492         /* testing empty func 3 */
493         public void foofoofoo3(self) {   }
494         /* testing empty func 4 */
495         public void foofoofoo4(self)
496         {
497         }
498
499 //      override (Gtk:Widget)
500 //      int event(Gtk:Widget *self (check null type),
501 //                GdkEvent *event (check null)) onerror FALSE
502 //      {
503 //              int ret;
504 //              /* some code */
505 //              ret = PARENT_HANDLER(self,event);
506 //              /* some code */
507 //              return ret;
508 //      }
509 //      override(Gtk:Container)
510 //      void
511 //      remove(Gtk:Container * self (check null type),
512 //             Gtk:Widget * wid (check null type));
513 //
514 //      override(Gtk:Object)
515 //      void
516 //      destroy(Gtk:Object * self (check null type))
517 //      {
518 //              /* foo bar */
519 //              PARENT_HANDLER(self);
520 //      }
521
522         protected
523         int foobar(self) {
524                 /* just an empty function */
525                 return 5;
526         }
527
528         signal last NONE(CHAR,UCHAR,BOOLEAN,INT,UINT,LONG,ULONG,FLOAT,DOUBLE,
529                          STRING,ENUM,POINTER,OBJECT)
530         void
531         testargs(self, gchar a, guchar b, gboolean c, gint d, guint e, glong f,
532                  gulong g, gfloat h, gdouble i, gchar * j, gint k,
533                  gpointer o, GObject *p)
534         {
535                 h = i = k = 0;
536                 a = b = c = d = e = f = g = 0;
537                 o = p = (GObject *)NULL;
538                 j = (char *)NULL;
539                 /* ugh, testing casting */
540         }
541
542         public signal (NO_HOOKS) last INT (INT)
543         int testflags(self, int w (check > 0)) defreturn -99 {
544                 /*foo*/
545                 return w;
546         }
547
548         /* testing NONE */
549         signal BOOLEAN (NONE)
550         gboolean
551         test_none_thing (self)
552         {
553                 return FALSE;
554         }
555
556         /* some more enum testing */
557         public BubleEnum buble;
558         property ENUM buble
559                 (nick = "Buble",
560                  blurb = "Buble",
561                  enum_type = Buble:Enum,
562                  default_value = BUBLE_STANDARD,
563                  link, export);
564
565         /* testing types */
566         public int t1;
567         public long int t2;
568         public int long t3;
569         public int long const t4;
570         public const int long t5;
571         public const char * const t6;
572         public char const * const t7;
573         public enum _gob__enum_t const * const t8;
574         public union _gob__union_t t9;
575         public union _gob__union_t * const * const * t10;
576         public struct _gob__struct_t * const * const * t11;
577         public const struct _gob__struct_t * const * const * t13;
578         public const enum _gob__enum_t * const * const * t14;
579         public enum _gob__enum_t t15;
580         public gchar const t16;
581         public const gchar * const t17;
582         public const gchar t18;
583
584         /* testing method with no arguments */
585         public void method_with_no_arguments (void)
586         {
587                 /* FOO */
588         }
589
590         /* testing calling the above method */
591         public void foo (self) {
592                 self_method_with_no_arguments ();
593         }
594
595         /* this is to test custom get_type */
596         /*public GtkType
597         get_type (void)
598         {
599                 static guint type = 0;
600
601                 if ( ! type) {
602                         static const GtkTypeInfo info = {
603                                 "GtkWeirdButton",
604                                 sizeof (GtkWeirdButton),
605                                 sizeof (GtkWeirdButtonClass),
606                                 (GtkClassInitFunc) gtk_weird_button_class_init,
607                                 (GtkObjectInitFunc) gtk_weird_button_init,
608                                 NULL,
609                                 NULL,
610                                 (GtkClassInitFunc) NULL
611                         };
612
613                         type = gtk_type_unique (gtk_button_get_type(), &info);
614                 }
615
616                 return type;
617         }*/
618
619
620         /* testing empty statements */
621         ;
622         ;
623         ;
624 }
625
626 %{
627
628 static void
629 jjjj(void)
630 {
631 }
632
633 void
634 bubu(void)
635 {
636         jjjj();
637 }
638
639 %}