17
using System.Runtime.InteropServices;
22
class TestFunctionPointers
25
static bool called = false;
27
static int twice(int a)
33
static int thrice(int a)
44
public static void set_callback_basic()
47
var obj = new Dummy.TestObject();
48
obj.SetCallback(twice);
50
Test.Assert(called == false, "set_callback should not call the callback");
52
int x = obj.CallCallback(42);
54
Test.Assert(called, "call_callback must call a callback");
55
Test.AssertEquals(42 * 2, x);
59
public static void set_callback_with_lambda()
63
var obj = new Dummy.TestObject();
64
obj.SetCallback(y => {
69
Test.Assert(called == false, "set_callback should not call the callback");
71
int x = obj.CallCallback(37);
73
Test.Assert(called, "call_callback must call a callback");
74
Test.AssertEquals(37 + 4, x);
78
public static void replace_callback()
82
var obj = new Dummy.TestObject();
83
obj.SetCallback(twice);
84
Test.Assert(called == false, "set_callback should not call the callback");
86
int x = obj.CallCallback(42);
87
Test.Assert(called, "call_callback must call a callback");
88
Test.AssertEquals(42 * 2, x);
90
bool new_called = false;
91
obj.SetCallback(y => {
96
Test.Assert(new_called == false, "set_callback should not call the callback");
98
x = obj.CallCallback(42);
99
Test.Assert(new_called, "call_callback must call a callback");
100
Test.AssertEquals(42 * 42, x);
104
class NoOverride : Dummy.TestObject {
106
public static void set_callback_inherited_no_override()
109
NoOverride obj = new NoOverride();
110
obj.SetCallback(thrice);
112
Test.Assert(!called, "set_callback in virtual should not call the callback");
114
int x = obj.CallCallback(42);
116
Test.Assert(called, "call_callback must call a callback");
117
Test.AssertEquals(42 * 3, x);
121
class WithOverride : Dummy.TestObject {
122
public bool set_called = false;
123
public bool invoke_called = false;
124
public Dummy.SimpleCb cb = null;
126
public WithOverride() : base() {
129
public override void SetCallback(Dummy.SimpleCb cb) {
133
public override int CallCallback(int a) {
134
invoke_called = true;
137
Eina.Log.Error("No callback set upon call_callback invocation");
141
public static void set_callback_inherited_with_override()
144
WithOverride obj = new WithOverride();
145
obj.SetCallback(thrice);
147
Test.Assert(obj.set_called, "set_callback override must have been called");
148
Test.Assert(!obj.invoke_called, "invoke_callback must not have been called");
150
obj.set_called = false;
151
int x = obj.CallCallback(42);
153
Test.Assert(!obj.set_called, "set_callback override must not have been called");
154
Test.Assert(obj.invoke_called, "set_callback in virtual should not call the callback");
156
Test.Assert(called, "call_callback must call a callback");
157
Test.AssertEquals(42 * 3, x);
163
[System.Runtime.InteropServices.DllImport("efl_mono_native_test")] static extern bool free_called_get();
164
[System.Runtime.InteropServices.DllImport("efl_mono_native_test")] static extern bool free_called_set(bool val);
166
public static void set_callback_inherited_called_from_c()
169
WithOverride obj = new WithOverride();
170
free_called_set(false);
171
obj.CallSetCallback();
173
Test.Assert(obj.set_called, "set_callback override must have been called");
174
Test.Assert(!obj.invoke_called, "invoke_callback must not have been called");
175
Test.Assert(!free_called_get(), "call_set_callback must not call the free callback");
177
obj.set_called = false;
178
int x = obj.CallCallback(42);
180
Test.Assert(!obj.set_called, "set_callback override must not have been called");
181
Test.Assert(obj.invoke_called, "set_callback in virtual should not call the callback");
182
Test.Assert(!free_called_get(), "call_callback must not call the free callback");
184
Test.AssertEquals(42 * 3, x);
187
obj.set_called = false;
188
obj.invoke_called = false;
189
free_called_set(false);
192
obj.SetCallback(twice);
194
Test.CollectAndIterate(300, 10);
196
Test.Assert(obj.set_called, "set_callback override must have been called");
197
Test.Assert(!obj.invoke_called, "invoke_callback must not have been called");
198
Test.Assert(free_called_get(), "free callback must have been called");
200
obj.set_called = false;
201
free_called_set(false);
202
x = obj.CallCallback(42);
204
Test.Assert(!obj.set_called, "set_callback override must not have been called");
205
Test.Assert(obj.invoke_called, "set_callback in virtual should not call the callback");
206
Test.Assert(!free_called_get(), "must not call old free_callback on new callback");
208
Test.Assert(called, "call_callback must call a callback");
209
Test.AssertEquals(42 * 2, x);