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