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