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