girparser: Fix unowned keyword in metadata types
[vala-lang.git] / tests / objects / signals.vala
blob3a07d99f44937bfde92b625da679ac371b8a0f0e
1 using GLib;
3 class Maman.Foo : Object {
4 public signal void activated (bool b);
6 public void do_action (bool b) {
7 activated (b);
11 class Maman.Bar : Object {
12 void activated (Foo foo, bool b) {
13 if (b) {
14 stdout.printf (" BAD");
15 } else {
16 stdout.printf (" 5");
20 public void run () {
21 stdout.printf (" 2");
23 var foo = new Foo ();
25 foo.activated.connect ((foo, b) => {
26 if (b) {
27 stdout.printf (" 8");
28 } else {
29 stdout.printf (" 4");
31 });
33 foo.activated.connect (activated);
35 stdout.printf (" 3");
37 foo.do_action (false);
39 stdout.printf (" 6");
41 foo.activated.disconnect (activated);
43 stdout.printf (" 7");
45 foo.do_action (true);
47 stdout.printf (" 9");
50 public static int main () {
51 stdout.printf ("Signal Test: 1");
53 var bar = new Bar ();
54 bar.run ();
56 stdout.printf (" 10\n");
58 stdout.printf ("User Signal Test: 1");
60 var user_bar = new UserBar ();
61 user_bar.run ();
63 stdout.printf (" 6\n");
65 stdout.printf ("Signal Return Test: 1");
67 var return_bar = new ReturnBar ();
68 return_bar.run ();
70 stdout.printf (" 8\n");
72 return 0;
76 class Maman.UserFoo : Object {
77 public signal void activated (int i1, int i2);
79 public void do_action () {
80 activated (6, -2);
84 class Maman.UserBar : Object {
85 public void run () {
86 stdout.printf (" 2");
88 var foo = new UserFoo ();
90 foo.activated.connect ((foo, i1, i2) => {
91 stdout.printf (" %d", i1 + i2);
92 });
94 stdout.printf (" 3");
96 foo.do_action ();
98 stdout.printf (" 5");
102 class Maman.ReturnFoo : Object {
103 public signal int int_activated (int arg);
104 public signal string string_activated (string arg);
107 class Maman.ReturnBar : Object {
108 public void run () {
109 stdout.printf (" 2");
111 var foo = new ReturnFoo ();
113 foo.int_activated.connect ((foo, arg) => {
114 stdout.printf (" %d", arg);
115 return arg + 1;
118 foo.string_activated.connect ((foo, arg) => {
119 stdout.printf (arg);
120 return " 6";
123 stdout.printf (" %d", foo.int_activated (3));
125 stdout.printf (foo.string_activated (" 5"));
127 stdout.printf (" 7");
131 void main () {
132 Maman.Bar.main ();