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 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
|
delegate void FooFunc ();
[CCode (has_target = false)]
delegate void BarFunc ();
class Foo : Object {
public signal void delegate_param_no_target (BarFunc f);
public signal void delegate_param_with_target (FooFunc f);
public signal void delegate_param_with_destroy (owned FooFunc f);
}
void no_target_cb (BarFunc f) {
f ();
}
void with_target_cb (FooFunc f) {
f ();
}
void with_destroy_cb (owned FooFunc f) {
f ();
}
bool success1 = false;
class Bar : Object {
Foo foo;
bool success2 = false;
bool success3 = false;
public Bar () {
foo = new Foo ();
}
public void test_no_target () {
foo.delegate_param_no_target.connect (no_target_cb);
foo.delegate_param_no_target (() => {
success1 = true;
});
assert (success1);
}
public void test_with_target () {
foo.delegate_param_with_target.connect (with_target_cb);
foo.delegate_param_with_target (() => {
assert (this.ref_count == 1);
success2 = true;
});
assert (this.ref_count == 1);
assert (success2);
}
public void test_with_destroy () {
foo.delegate_param_with_destroy.connect (with_destroy_cb);
foo.delegate_param_with_destroy (() => {
assert (this.ref_count == 2);
success3 = true;
});
assert (this.ref_count == 1);
assert (success3);
}
}
void main () {
var bar = new Bar ();
bar.test_no_target ();
bar.test_with_target ();
bar.test_with_destroy ();
}
|