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