summaryrefslogtreecommitdiff
path: root/tests/objects/signals-struct-return.vala
blob: 4790d9d9d141e1c8ccff09643c96ba293e9b49aa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
struct Foo {
	public string s;
	public int i;
}

class Bar : Object {
	public signal Foo on_foo ();
	public signal Foo on_foo_with_arg (string s);
	public signal Foo? on_bar ();
	public signal Foo? on_bar_with_arg (string s);
}

void main () {
	{
		var bar = new Bar ();
		bar.on_foo.connect (() => {
			return { "foo", 23 };
		});
		bar.on_foo_with_arg.connect ((s) => {
			assert (s == "foo");
			return { "foo", 42 };
		});
		var foo = bar.on_foo ();
		assert (foo.s == "foo");
		assert (foo.i == 23);
		var foo2 = bar.on_foo_with_arg ("foo");
		assert (foo2.s == "foo");
		assert (foo2.i == 42);
	}
	{
		var bar = new Bar ();
		bar.on_bar.connect (() => {
			return { "bar", 42 };
		});
		bar.on_bar_with_arg.connect ((s) => {
			assert (s == "bar");
			return { "bar", 23 };
		});
		var foo = bar.on_bar ();
		assert (foo.s == "bar");
		assert (foo.i == 42);
		var foo2 = bar.on_bar_with_arg ("bar");
		assert (foo2.s == "bar");
		assert (foo2.i == 23);
	}
}