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