]> git.draconx.ca Git - gob-dx.git/blob - src/test.gob
Build with libtool.
[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                 (
172                  name="a-property",
173                  nick = _("Nick"),
174                  blurb = _("Blurb"),
175                  minimum = 'a',
176                  maximum = 'Z',
177                  default_value = 'C',
178                  export)
179                 set { self->_priv->a_property = g_value_get_char (VAL); }
180                 get { g_value_set_char (VAL, self->_priv->a_property); };
181
182         property OBJECT foobarblahllll1
183                 (nick = "xxxxxxx1",
184                  blurb = "yyyyyy",
185                  object_type = Gtk:Button)
186                 get { /* FOO1 */ };
187         property OBJECT foobarblahllll2
188                 (nick = "xxxxxxx2",
189                  blurb = "yyyyyy",
190                  object_type = G:Object)
191                 set { /* FOO2 */ };
192
193         private double dblnum;
194         property DOUBLE dblnum
195                 (nick = _("dblnum"),
196                  blurb = _("dblnum"),
197                  minimum = 0.1,
198                  maximum = 99.1,
199                  default_value = 0.3,
200                  flags = CONSTRUCT|CONSTRUCT_ONLY,
201                  export,
202                  link);
203
204         private char *b_property;
205         property STRING b_property
206                 (nick = _("Nick b"),
207                  blurb = _("Blurb b"),
208                  default_value = "default",
209                  type = char *,
210                  flags = CONSTRUCT,
211                  export,
212                  link);
213
214         private Test:Object *objectproperty;
215         property OBJECT objectproperty (nick   = "object",
216                                 blurb  = "obj property",
217                                 object_type = Test:Object,
218                                 link);
219
220         private Test:Enum enum_property;
221         property ENUM enum_property (nick   = "enumprop",
222                                 blurb  = "enumprop",
223                                 enum_type = Test:Enum,
224                                 link);
225
226         private Some:Flags flags_property;
227         property FLAGS flags_property (nick   = "flagsprop",
228                                 blurb  = "flagsprop",
229                                 flags_type = Some:Flags,
230                                 link);
231
232           private PackageBoxed prop;
233           property BOXED prop (nick="prop",
234                                blurb="prop",
235                                boxed_type=Package:Boxed,
236                                link);
237           /* testing old semantics */
238           private PackageBoxed prop2;
239           property BOXED prop2 (nick="prop2",
240                                blurb="prop2",
241                                boxed_type=PACKAGE_TYPE_BOXED,
242                                link);
243
244         private char ov_prop;
245         property CHAR ov_prop
246                 (export,
247                  override)
248                 set { self->_priv->ov_prop = g_value_get_char (VAL); }
249                 get { g_value_set_char (VAL, self->_priv->ov_prop); };
250
251
252         private int j;
253         public GObject * h;
254         public char *bleh;
255         public double array[23][18];
256         protected unsigned long int wagawaga;
257         public int wagawaga_should_be_after_this_in_the_header;
258
259         init(object) {
260                 object->i=0;
261         }
262         class_init(klass) {
263                 /*IN CLASS INIT  */
264         }
265
266         /**
267          * new:
268          * @j: foo
269          *
270          * budliky budliky
271          *
272          * Returns: new object
273          */
274         public GObject * new(int j (check > 0)) {
275                 GObject *ret;
276                 ret = G_OBJECT (GET_NEW);
277
278                 SELF(ret)->_priv->j = j;
279
280                 return ret;
281         }
282         private int blah(self, G:Object * wid (check null type),
283                          int h (check > 0)) onerror -1 {
284                 g_object_set (G_OBJECT (self),
285                               TEST_OBJECT_PROP_I (99),
286                               NULL);
287                 return h;
288         }
289         /**
290          * bleh:
291          * @self: foo
292          * @wid: foo
293          * @h: foo
294          *
295          * budliky budliky 2
296          *
297          * Returns: new object
298          **/
299         signal last STRING "bleh-signal" (POINTER, INT)
300         char * bleh(self, G:Object * wid (check null type),
301                         int h (check > 0)) {
302                 return self_blah(self,wid,h) > 0 ? g_strdup ("foo") : g_strdup ("bar");
303         }
304
305         constructor(self) {
306                 /* constructor stuff */
307         }
308
309         dispose(self) {
310                 /* dispose stuff */
311         }
312
313         finalize(self) {
314                 /* finalize stuff */
315         }
316
317         private
318         char *
319         test_handler (self, GObject *w, int h, gpointer data)
320         {
321                 data = w = NULL;
322                 h = 0;
323                         
324                 return NULL;
325         }
326
327         /**
328          * gtk_weird_button_bleh2:
329          * @self: foo
330          * @wid: foo
331          * @h: foo
332          *
333          * budliky budliky 3
334          *
335          * Returns: new object */
336         signal last INT (POINTER, INT)
337         int bleh2(self, const G:Object * wid (check null type),
338                         int h (check > 0)) {
339
340                 test_object_connect__bleh (self, self_test_handler, NULL);
341                 self_connect__bleh (self, self_test_handler, NULL);
342                 test_object_connect_after__bleh (self, self_test_handler, NULL);
343                 self_connect_after__bleh (self, self_test_handler, NULL);
344                 test_object_connect_data__bleh (self, self_test_handler, NULL, NULL, 0);
345                 self_connect_data__bleh (self, self_test_handler, NULL, NULL, 0);
346
347                 wid = NULL;
348                 h = 0;
349
350                 /* testing multiple marshaller support */
351                 return 0;
352         }
353         /* this should not get documented as it's nonstandard */
354         /**
355          * bloh:
356
357          ******/
358
359         /* Here we are testing how the gtk-doc extraction code error handeling
360            it should just ingore these */
361         /**
362           */
363
364         /** */
365         /**
366          *
367          * bubu
368          *********/
369         /**
370          *
371          * bubu
372          **zblunk*******/
373         /**
374          *
375          * bubu
376          *zblunk*******//**//**/
377         signal first NONE (NONE)
378         void bloh(self);
379         virtual void * bah(self, int h (check > 0)) onerror NULL defreturn 0 {
380                 self_beh(self,h);
381                 return NULL;
382         }
383         virtual int beh(self, int h (check > 0));
384         override(Gtk:Container)
385         void add(Gtk:Container * self (check null type),
386                  Gtk:Widget * wid (check null type)) {
387                 PARENT_HANDLER(self,wid);
388         }
389
390         override(G:Object)
391         void dispatch_properties_changed (G:Object      *object,
392                                           guint    n_pspecs,
393                                           GParamSpec  **pspecs)
394         {
395                 object = NULL;
396                 n_pspecs = 0;
397                 pspecs = NULL;
398                 /* EKI! */
399         }
400
401         public int consttest(self, const gchar *text, ...)
402         {
403                 text = NULL;
404                 return 25;
405         }
406         public int consttest2(self, gchar const *text, ...)
407         {
408                 text = NULL;
409                 return 25;
410         }
411         public int consttest3(self, G:Object const *wid (check null type))
412         {
413                 wid = NULL;
414                 return 25;
415         }
416         public int consttest4(const self)
417         {
418                 return 25;
419         }
420         public int consttest5(self const)
421         {
422                 return 25;
423         }
424         virtual int consttest6(const self)
425         {
426                 return 25;
427         }
428         virtual int consttest7(self const)
429         {
430                 return 25;
431         }
432         public int consttest8(self)
433         {
434                 Self const *selfconst1, *selfconst2;
435                 selfconst1 = SELF_CONST(self);
436                 selfconst2 = TEST_OBJECT_CONST(self);
437                 return 25;
438         }
439         public int consttest9(const self, int i, double b)
440         {
441                 b = 0.0;
442                 i = 0;
443                 return 25;
444         }
445         public int consttest10(self const, int i, double b)
446         {
447                 b = 0.0;
448                 i = 0;
449                 return 25;
450         }
451         public gchar *funcattrtest(self, const char *format (check null), ...)
452                 attr {G_GNUC_PRINTF (2, 3)}
453         {
454                 gchar *result;
455
456                 va_list ap;
457                 va_start(ap, format);
458                 result = g_strdup_vprintf (format, ap);
459                 va_end(ap);
460                 return result;
461         }
462         private gchar *funcattrtest2(self, const char *format, ...)
463                 attr {G_GNUC_SCANF(2,3)}
464         {
465                 gchar *nonsense = NULL;
466                 format = format;
467                 return nonsense;
468         }
469         protected gchar *funcattrtest3(self, const char *format)
470                 attr {G_GNUC_FORMAT (2)}
471         {
472                 gchar *nonsense = NULL;
473                 format = format;
474                 return nonsense;                
475         }
476         private char *funcattrtest4(self, const char *format, ...)
477                 attr {G_GNUC_PRINTF(2,3)}
478                 onerror NULL
479         {
480                 gchar *nonsense = NULL;
481                 format = format;
482                 return nonsense;                
483         }
484         protected char * funcattrtest5(self, const char *format, ...)
485                 onerror NULL
486                 attr {G_GNUC_PRINTF(2,3)}
487         {
488                 gchar *nonsense = NULL;
489                 format = format;
490                 return nonsense;                
491         }
492         public char * funcattrtest6(self, const char *format, ...)
493                 attr {G_GNUC_PRINTF(2,3)}
494                 onerror NULL 
495         {
496                 gchar *nonsense = NULL;
497                 format = format;
498                 return nonsense;                
499         }
500         // Note that the parser should accept defreturn with function
501         // attributes as well, but this may not be a good thing since
502         // it probably doesn't make sense, so we don't test it.
503         signal private first NONE (NONE)
504         void googlegoogle(self)
505         {
506                 puts("TEST1");
507                 self_googlegoogle2(self);
508         }
509         signal first private NONE (NONE)
510         void googlegoogle2(self)
511         {
512                 int array[5][8][9]={{{0}}};
513                 Self *foo = self;
514                 puts("TEST2");
515                 self_testprivvirtual(foo, array);
516         }
517         private signal first NONE (NONE)
518         void googlegoogle3(self)
519         {
520                 puts("TEST3");
521         }
522         protected signal first NONE (NONE)
523         void googlegoogle4(self)
524         {
525                 puts("TEST4");
526         }
527         protected signal first NONE (NONE)
528         void googlegoogle_const1(const self)
529         {
530                 puts("TEST4");
531         }
532         protected signal first NONE (NONE)
533         void googlegoogle_const2(self const)
534         {
535                 puts("TEST4");
536         }
537         virtual private
538         void testprivvirtual(self, int some_array[5][8][9])
539         {
540                 puts("TEST3");
541                 self_googlegoogle(self);
542                 if (some_array[0]) return;
543         }
544         private virtual
545         void testprivvirtual2(self, const int some_array[5][8][9])
546         {
547                 /* nothing here */
548                 if (some_array[0]) return;
549         }
550         public virtual
551         void testpublicvirtual(self, int const some_array[5][8][9])
552         {
553                 /* nothing here */
554                 if (some_array[0]) return;
555         }
556         protected virtual
557         void testprotectedvirtual(self, int some_array[5][8][9])
558         {
559                 /* nothing here */
560                 if (some_array[0]) return;
561         }
562         signal first NONE (POINTER, ENUM)
563         void testarrsignal(self, long arr[8], Buble:Enum foo)
564         {
565                 /* foo */
566                 arr[0] = 1;
567                 foo = BUBLE_KEIN;
568         }
569
570         /* testing empty func */
571         public void foofoofoo(self) {}
572         /* testing empty func 2 */
573         public void foofoofoo2(self);
574         /* testing empty func 3 */
575         public void foofoofoo3(self) {   }
576         /* testing empty func 4 */
577         public void foofoofoo4(self)
578         {
579         }
580
581 //      override (Gtk:Widget)
582 //      int event(Gtk:Widget *self (check null type),
583 //                GdkEvent *event (check null)) onerror FALSE
584 //      {
585 //              int ret;
586 //              /* some code */
587 //              ret = PARENT_HANDLER(self,event);
588 //              /* some code */
589 //              return ret;
590 //      }
591 //      override(Gtk:Container)
592 //      void
593 //      remove(Gtk:Container * self (check null type),
594 //             Gtk:Widget * wid (check null type));
595 //
596 //      override(Gtk:Object)
597 //      void
598 //      destroy(Gtk:Object * self (check null type))
599 //      {
600 //              /* foo bar */
601 //              PARENT_HANDLER(self);
602 //      }
603
604         protected
605         int foobar(self) {
606                 /* just an empty function */
607                 return 5;
608         }
609
610         signal last NONE(CHAR,UCHAR,BOOLEAN,INT,UINT,LONG,ULONG,FLOAT,DOUBLE,
611                          STRING,ENUM,POINTER,OBJECT)
612         void
613         testargs(self, gchar a, guchar b, gboolean c, gint d, guint e, glong f,
614                  gulong g, gfloat h, gdouble i, gchar * j, gint k,
615                  gpointer o, GObject *p)
616         {
617                 h = i = k = 0;
618                 a = b = c = d = e = f = g = 0;
619                 o = p = (GObject *)NULL;
620                 j = (char *)NULL;
621                 /* ugh, testing casting */
622         }
623
624         public signal (NO_HOOKS) last INT (INT)
625         int testflags(self, int w (check > 0)) defreturn -99 {
626                 /*foo*/
627                 return w;
628         }
629
630         /* testing NONE */
631         signal BOOLEAN (NONE)
632         gboolean
633         test_none_thing (self)
634         {
635                 return FALSE;
636         }
637
638         /* some more enum testing */
639         public BubleEnum buble;
640         property ENUM buble
641                 (nick = "Buble",
642                  blurb = "Buble",
643                  enum_type = Buble:Enum,
644                  default_value = BUBLE_STANDARD,
645                  link, export);
646
647         /* testing types */
648         public int t1;
649         public long int t2;
650         public int long t3;
651         public int long const t4;
652         public const int long t5;
653         public const char * const t6;
654         public char const * const t7;
655         public enum _gob__enum_t const * const t8;
656         public union _gob__union_t t9;
657         public union _gob__union_t * const * const * t10;
658         public struct _gob__struct_t * const * const * t11;
659         public const struct _gob__struct_t * const * const * t13;
660         public const enum _gob__enum_t * const * const * t14;
661         public enum _gob__enum_t t15;
662         public gchar const t16;
663         public const gchar * const t17;
664         public const gchar t18;
665
666         /* testing method with no arguments */
667         public void method_with_no_arguments (void)
668         {
669                 /* FOO */
670         }
671
672         /* testing calling the above method */
673         public void foo (self) {
674                 self_method_with_no_arguments ();
675         }
676
677         /* this is to test custom get_type */
678         /*public GtkType
679         get_type (void)
680         {
681                 static guint type = 0;
682
683                 if ( ! type) {
684                         static const GtkTypeInfo info = {
685                                 "GtkWeirdButton",
686                                 sizeof (GtkWeirdButton),
687                                 sizeof (GtkWeirdButtonClass),
688                                 (GtkClassInitFunc) gtk_weird_button_class_init,
689                                 (GtkObjectInitFunc) gtk_weird_button_init,
690                                 NULL,
691                                 NULL,
692                                 (GtkClassInitFunc) NULL
693                         };
694
695                         type = gtk_type_unique (gtk_button_get_type(), &info);
696                 }
697
698                 return type;
699         }*/
700
701
702         /* testing empty statements */
703         ;
704         ;
705         ;
706 }
707
708 %{
709
710 static void
711 jjjj(void)
712 {
713 }
714
715 void
716 bubu(void)
717 {
718         jjjj();
719 }
720
721 %}