aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFelipe Magno de Almeida <felipe@expertisesolutions.com.br>2019-01-14 12:13:40 +0900
committerFelipe Magno de Almeida <felipe@expertisesolutions.com.br>2019-01-16 12:15:58 +0900
commit0b40feb00b67b8db958287d88b6365d562045437 (patch)
treeca759ed4ad2be4bca658a3181c77bda4b02ead6f
parentefl-mono: Add test for GC of parented objects (diff)
downloadefl-devs/felipealmeida/mono_model.tar.gz
efl-mono: Add function pointer with complex struct testdevs/felipealmeida/mono_model
-rw-r--r--src/tests/efl_mono/FunctionPointers.cs25
-rw-r--r--src/tests/efl_mono/dummy_test_object.eo22
-rw-r--r--src/tests/efl_mono/libefl_mono_native_test.c30
3 files changed, 77 insertions, 0 deletions
diff --git a/src/tests/efl_mono/FunctionPointers.cs b/src/tests/efl_mono/FunctionPointers.cs
index de363c86d6..ae3a1808fc 100644
--- a/src/tests/efl_mono/FunctionPointers.cs
+++ b/src/tests/efl_mono/FunctionPointers.cs
@@ -8,6 +8,7 @@ class TestFunctionPointers
{
static bool called = false;
+ static bool struct_called = false;
static int twice(int a)
{
@@ -83,6 +84,30 @@ class TestFunctionPointers
Test.AssertEquals(42 * 42, x);
}
+ static int struct_cb1(int a, Dummy.StructComplex s)
+ {
+ struct_called = true;
+ StructHelpers.checkStructComplex(s);
+ return a * 2;
+ }
+
+ public static void set_struct_callback_basic()
+ {
+ setup();
+ var obj = new Dummy.TestObject();
+ obj.SetStructCallback(struct_cb1);
+
+ Test.Assert(struct_called == false, "set_callback should not call the callback");
+
+ Dummy.StructComplex s = StructHelpers.structComplexWithValues();
+
+
+ int x = obj.CallStructCallback(42, s);
+
+ Test.Assert(struct_called, "call_callback must call a callback");
+ Test.AssertEquals(42 * 2, x);
+ }
+
class NoOverride : Dummy.TestObject {
}
public static void set_callback_inherited_no_override()
diff --git a/src/tests/efl_mono/dummy_test_object.eo b/src/tests/efl_mono/dummy_test_object.eo
index 4a6ea5fcc6..50aaed32e8 100644
--- a/src/tests/efl_mono/dummy_test_object.eo
+++ b/src/tests/efl_mono/dummy_test_object.eo
@@ -91,6 +91,14 @@ function Dummy.FormatCb {
}
};
+function Dummy.StructCb {
+ params {
+ a: int;
+ b: Dummy.StructComplex;
+ }
+ return: int;
+};
+
class Dummy.Test_Object extends Efl.Object implements Efl.Part, Dummy.Test_Iface, Dummy.Another_Iface {
parts {
@@ -1281,6 +1289,20 @@ class Dummy.Test_Object extends Efl.Object implements Efl.Part, Dummy.Test_Iface
/* Function Pointer */
+ set_struct_callback {
+ params {
+ cb: Dummy.StructCb;
+ }
+ }
+
+ call_struct_callback {
+ params {
+ a: int;
+ b: Dummy.StructComplex;
+ }
+ return: int;
+ }
+
set_callback {
params {
cb: Dummy.SimpleCb;
diff --git a/src/tests/efl_mono/libefl_mono_native_test.c b/src/tests/efl_mono/libefl_mono_native_test.c
index 576690bb86..8c5c1bdc1f 100644
--- a/src/tests/efl_mono/libefl_mono_native_test.c
+++ b/src/tests/efl_mono/libefl_mono_native_test.c
@@ -50,6 +50,9 @@ typedef struct Dummy_Test_Object_Data
Dummy_SimpleCb cb;
void *cb_data;
Eina_Free_Cb free_cb;
+ Dummy_StructCb structcb_cb;
+ void *structcb_cb_data;
+ Eina_Free_Cb structcb_free_cb;
Eina_Error error_code;
Eina_Value *stored_value;
Dummy_StructSimple stored_struct;
@@ -3125,6 +3128,33 @@ Eina_Iterator *_dummy_test_object_eina_iterator_obj_return_own(EINA_UNUSED Eo *o
// Callbacks and Function Pointers //
// //
+void _dummy_test_object_set_struct_callback(EINA_UNUSED Eo *obj, Dummy_Test_Object_Data *pd, void *cb_data, Dummy_StructCb cb, Eina_Free_Cb cb_free_cb)
+{
+ if (!pd)
+ {
+ EINA_LOG_ERR("Null private data");
+ return;
+ }
+
+ if (pd->structcb_free_cb)
+ pd->structcb_free_cb(pd->cb_data);
+
+ pd->structcb_cb = cb;
+ pd->structcb_cb_data = cb_data;
+ pd->structcb_free_cb = cb_free_cb;
+}
+
+int _dummy_test_object_call_struct_callback(EINA_UNUSED Eo *obj, Dummy_Test_Object_Data *pd, int a, Dummy_StructComplex b)
+{
+ if (!pd->structcb_cb)
+ {
+ EINA_LOG_ERR("Trying to call with no struct callback set");
+ return -1; // FIXME Maybe use Eina error when exceptions are supported?
+ }
+
+ return pd->structcb_cb(pd->structcb_cb_data, a, b);
+}
+
void _dummy_test_object_set_callback(EINA_UNUSED Eo *obj, Dummy_Test_Object_Data *pd, void *cb_data, Dummy_SimpleCb cb, Eina_Free_Cb cb_free_cb)
{
if (!pd)