]> git.draconx.ca Git - gob-dx.git/blob - src/test.gob
Release 2.0.9
[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
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 * testingobjfoo
128                 unref { if (VAR) g_object_unref (VAR); };
129         argument POINTER testingobjfoo objectlink;
130
131         classwide int foo = 20;
132         argument INT foo link;
133
134         public G:Object * testingobj2
135                 destroy {
136                         if(VAR)
137                                 g_object_unref(G_OBJECT(VAR));
138                 };
139         argument POINTER (type G:Object *) testingobj2 objectlink;
140         
141         argument POINTER (type GObject *) some_object
142                 set { /* set some_object */ }
143                 get { /* get some_object */
144                         ARG=NULL; };
145         argument (CONSTRUCT) LONG (type long) write_only_long
146                 set { /* set write_only_long */ };
147         argument POINTER (type char *) read_only_string
148                 get { /* get readonly_long */
149                         ARG = g_strdup("BLAH"); };
150
151         private char a_property;
152         property CHAR a_property
153                 (nick = _("Nick"),
154                  blurb = _("Blurb"),
155                  minimum = 'a',
156                  maximum = 'Z',
157                  default_value = 'C',
158                  export)
159                 set { self->_priv->a_property = g_value_get_char (VAL); }
160                 get { g_value_set_char (VAL, self->_priv->a_property); };
161
162         property OBJECT foobarblahllll1
163                 (nick = "xxxxxxx1",
164                  blurb = "yyyyyy",
165                  object_type = Gtk:Button)
166                 get { /* FOO1 */ };
167         property OBJECT foobarblahllll2
168                 (nick = "xxxxxxx2",
169                  blurb = "yyyyyy",
170                  object_type = G:Object)
171                 set { /* FOO2 */ };
172
173         private double dblnum;
174         property DOUBLE dblnum
175                 (nick = _("dblnum"),
176                  blurb = _("dblnum"),
177                  minimum = 0.1,
178                  maximum = 99.1,
179                  default_value = 0.3,
180                  flags = CONSTRUCT|CONSTRUCT_ONLY,
181                  export,
182                  link);
183
184         private char *b_property;
185         property STRING b_property
186                 (nick = _("Nick b"),
187                  blurb = _("Blurb b"),
188                  default_value = "default",
189                  type = char *,
190                  flags = CONSTRUCT,
191                  export,
192                  link);
193
194         private Test:Object *objectproperty;
195         property OBJECT objectproperty (nick   = "object",
196                                 blurb  = "obj property",
197                                 object_type = Test:Object,
198                                 link);
199
200         private Test:Enum enum_property;
201         property ENUM enum_property (nick   = "enumprop",
202                                 blurb  = "enumprop",
203                                 enum_type = Test:Enum,
204                                 link);
205
206         private Some:Flags flags_property;
207         property FLAGS flags_property (nick   = "flagsprop",
208                                 blurb  = "flagsprop",
209                                 flags_type = Some:Flags,
210                                 link);
211
212           private PackageBoxed prop;
213           property BOXED prop (nick="prop",
214                                blurb="prop",
215                                boxed_type=Package:Boxed,
216                                link);
217           /* testing old semantics */
218           private PackageBoxed prop2;
219           property BOXED prop2 (nick="prop2",
220                                blurb="prop2",
221                                boxed_type=PACKAGE_TYPE_BOXED,
222                                link);
223
224
225         private int j;
226         public GObject * h;
227         public char *bleh;
228         public double array[23][18];
229         protected unsigned long int wagawaga;
230         public int wagawaga_should_be_after_this_in_the_header;
231
232         init(object) {
233                 object->i=0;
234         }
235         class_init(klass);
236
237         /**
238          * new:
239          * @j: foo
240          *
241          * budliky budliky
242          *
243          * Returns: new object
244          */
245         public GObject * new(int j (check > 0)) {
246                 GObject *ret;
247                 ret = G_OBJECT (GET_NEW);
248
249                 SELF(ret)->_priv->j = j;
250
251                 return ret;
252         }
253         private int blah(self, G:Object * wid (check null type),
254                          int h (check > 0)) onerror -1 {
255                 g_object_set (G_OBJECT (self),
256                               TEST_OBJECT_PROP_I (99),
257                               NULL);
258                 return h;
259         }
260         /**
261          * bleh:
262          * @self: foo
263          * @wid: foo
264          * @h: foo
265          *
266          * budliky budliky 2
267          *
268          * Returns: new object
269          **/
270         signal last STRING (POINTER, INT)
271         char * bleh(self, G:Object * wid (check null type),
272                         int h (check > 0)) {
273                 return self_blah(self,wid,h) > 0 ? g_strdup ("foo") : g_strdup ("bar");
274         }
275
276         private
277         char *
278         test_handler (self, GObject *w, int h, gpointer data)
279         {
280                 data = w = NULL;
281                 h = 0;
282                         
283                 return NULL;
284         }
285
286         /**
287          * gtk_weird_button_bleh2:
288          * @self: foo
289          * @wid: foo
290          * @h: foo
291          *
292          * budliky budliky 3
293          *
294          * Returns: new object */
295         signal last INT (POINTER, INT)
296         int bleh2(self, const G:Object * wid (check null type),
297                         int h (check > 0)) {
298
299                 test_object_connect__bleh (self, self_test_handler, NULL);
300                 self_connect__bleh (self, self_test_handler, NULL);
301                 test_object_connect_after__bleh (self, self_test_handler, NULL);
302                 self_connect_after__bleh (self, self_test_handler, NULL);
303                 test_object_connect_data__bleh (self, self_test_handler, NULL, NULL, 0);
304                 self_connect_data__bleh (self, self_test_handler, NULL, NULL, 0);
305
306                 wid = NULL;
307                 h = 0;
308
309                 /* testing multiple marshaller support */
310                 return 0;
311         }
312         /* this should not get documented as it's nonstandard */
313         /**
314          * bloh:
315
316          ******/
317
318         /* Here we are testing how the gtk-doc extraction code error handeling
319            it should just ingore these */
320         /**
321           */
322
323         /** */
324         /**
325          *
326          * bubu
327          *********/
328         /**
329          *
330          * bubu
331          **zblunk*******/
332         /**
333          *
334          * bubu
335          *zblunk*******//**//**/
336         signal first NONE (NONE)
337         void bloh(self);
338         virtual void * bah(self, int h (check > 0)) onerror NULL defreturn 0 {
339                 self_beh(self,h);
340                 return NULL;
341         }
342         virtual int beh(self, int h (check > 0));
343         /*override(G:Object) void add(Gtk:Container * self (check null type),
344                                          Gtk:Widget * wid (check null type)) {
345                 PARENT_HANDLER(self,wid);
346         }*/
347         public int consttest(self, const gchar *text, ...)
348         {
349                 text = NULL;
350                 return 25;
351         }
352         public int consttest2(self, gchar const *text, ...)
353         {
354                 text = NULL;
355                 return 25;
356         }
357         public int consttest3(self, G:Object const *wid (check null type))
358         {
359                 wid = NULL;
360                 return 25;
361         }
362         public int consttest4(const self)
363         {
364                 return 25;
365         }
366         public int consttest5(self const)
367         {
368                 return 25;
369         }
370         virtual int consttest6(const self)
371         {
372                 return 25;
373         }
374         virtual int consttest7(self const)
375         {
376                 return 25;
377         }
378         public int consttest8(self)
379         {
380                 Self const *selfconst1, *selfconst2;
381                 selfconst1 = SELF_CONST(self);
382                 selfconst2 = TEST_OBJECT_CONST(self);
383                 return 25;
384         }
385         public int consttest9(const self, int i, double b)
386         {
387                 b = 0.0;
388                 i = 0;
389                 return 25;
390         }
391         public int consttest10(self const, int i, double b)
392         {
393                 b = 0.0;
394                 i = 0;
395                 return 25;
396         }
397         signal private first NONE (NONE)
398         void googlegoogle(self)
399         {
400                 puts("TEST1");
401                 self_googlegoogle2(self);
402         }
403         signal first private NONE (NONE)
404         void googlegoogle2(self)
405         {
406                 int array[5][8][9]={{{0}}};
407                 Self *foo = self;
408                 puts("TEST2");
409                 self_testprivvirtual(foo, array);
410         }
411         private signal first NONE (NONE)
412         void googlegoogle3(self)
413         {
414                 puts("TEST3");
415         }
416         protected signal first NONE (NONE)
417         void googlegoogle4(self)
418         {
419                 puts("TEST4");
420         }
421         protected signal first NONE (NONE)
422         void googlegoogle_const1(const self)
423         {
424                 puts("TEST4");
425         }
426         protected signal first NONE (NONE)
427         void googlegoogle_const2(self const)
428         {
429                 puts("TEST4");
430         }
431         virtual private
432         void testprivvirtual(self, int some_array[5][8][9])
433         {
434                 puts("TEST3");
435                 self_googlegoogle(self);
436                 if (some_array[0]) return;
437         }
438         private virtual
439         void testprivvirtual2(self, const int some_array[5][8][9])
440         {
441                 /* nothing here */
442                 if (some_array[0]) return;
443         }
444         public virtual
445         void testpublicvirtual(self, int const some_array[5][8][9])
446         {
447                 /* nothing here */
448                 if (some_array[0]) return;
449         }
450         protected virtual
451         void testprotectedvirtual(self, int some_array[5][8][9])
452         {
453                 /* nothing here */
454                 if (some_array[0]) return;
455         }
456         signal first NONE (POINTER, ENUM)
457         void testarrsignal(self, long arr[8], Buble:Enum foo)
458         {
459                 /* foo */
460                 arr[0] = 1;
461                 foo = BUBLE_KEIN;
462         }
463
464         /* testing empty func */
465         public void foofoofoo(self) {}
466         /* testing empty func 2 */
467         public void foofoofoo2(self);
468         /* testing empty func 3 */
469         public void foofoofoo3(self) {   }
470         /* testing empty func 4 */
471         public void foofoofoo4(self)
472         {
473         }
474
475 //      override (Gtk:Widget)
476 //      int event(Gtk:Widget *self (check null type),
477 //                GdkEvent *event (check null)) onerror FALSE
478 //      {
479 //              int ret;
480 //              /* some code */
481 //              ret = PARENT_HANDLER(self,event);
482 //              /* some code */
483 //              return ret;
484 //      }
485 //      override(Gtk:Container)
486 //      void
487 //      remove(Gtk:Container * self (check null type),
488 //             Gtk:Widget * wid (check null type));
489 //
490 //      override(Gtk:Object)
491 //      void
492 //      destroy(Gtk:Object * self (check null type))
493 //      {
494 //              /* foo bar */
495 //              PARENT_HANDLER(self);
496 //      }
497
498         protected
499         int foobar(self) {
500                 /* just an empty function */
501                 return 5;
502         }
503
504         signal last NONE(CHAR,UCHAR,BOOLEAN,INT,UINT,LONG,ULONG,FLOAT,DOUBLE,
505                          STRING,ENUM,POINTER,OBJECT)
506         void
507         testargs(self, gchar a, guchar b, gboolean c, gint d, guint e, glong f,
508                  gulong g, gfloat h, gdouble i, gchar * j, gint k,
509                  gpointer o, GObject *p)
510         {
511                 h = i = k = 0;
512                 a = b = c = d = e = f = g = 0;
513                 o = p = (GObject *)NULL;
514                 j = (char *)NULL;
515                 /* ugh, testing casting */
516         }
517
518         public signal (NO_HOOKS) last INT (INT)
519         int testflags(self, int w (check > 0)) defreturn -99 {
520                 /*foo*/
521                 return w;
522         }
523
524         /* testing NONE */
525         signal BOOLEAN (NONE)
526         gboolean
527         test_none_thing (self)
528         {
529                 return FALSE;
530         }
531
532         /* some more enum testing */
533         public BubleEnum buble;
534         property ENUM buble
535                 (nick = "Buble",
536                  blurb = "Buble",
537                  enum_type = Buble:Enum,
538                  default_value = BUBLE_STANDARD,
539                  link, export);
540
541         /* testing types */
542         public int t1;
543         public long int t2;
544         public int long t3;
545         public int long const t4;
546         public const int long t5;
547         public const char * const t6;
548         public char const * const t7;
549         public enum _gob__enum_t const * const t8;
550         public union _gob__union_t t9;
551         public union _gob__union_t * const * const * t10;
552         public struct _gob__struct_t * const * const * t11;
553         public const struct _gob__struct_t * const * const * t13;
554         public const enum _gob__enum_t * const * const * t14;
555         public enum _gob__enum_t t15;
556         public gchar const t16;
557         public const gchar * const t17;
558         public const gchar t18;
559
560         /* testing method with no arguments */
561         public void method_with_no_arguments (void)
562         {
563                 /* FOO */
564         }
565
566         /* testing calling the above method */
567         public void foo (self) {
568                 self_method_with_no_arguments ();
569         }
570
571         /* this is to test custom get_type */
572         /*public GtkType
573         get_type (void)
574         {
575                 static guint type = 0;
576
577                 if ( ! type) {
578                         static const GtkTypeInfo info = {
579                                 "GtkWeirdButton",
580                                 sizeof (GtkWeirdButton),
581                                 sizeof (GtkWeirdButtonClass),
582                                 (GtkClassInitFunc) gtk_weird_button_class_init,
583                                 (GtkObjectInitFunc) gtk_weird_button_init,
584                                 NULL,
585                                 NULL,
586                                 (GtkClassInitFunc) NULL
587                         };
588
589                         type = gtk_type_unique (gtk_button_get_type(), &info);
590                 }
591
592                 return type;
593         }*/
594
595
596         /* testing empty statements */
597         ;
598         ;
599         ;
600 }
601
602 %{
603
604 static void
605 jjjj(void)
606 {
607 }
608
609 void
610 bubu(void)
611 {
612         jjjj();
613 }
614
615 %}