From eaf41d9bcebf4ebf9ede38c42f7c2957f6024504 Mon Sep 17 00:00:00 2001 From: Lauro Moura Date: Mon, 22 Jan 2018 14:56:38 -0300 Subject: [PATCH] eolian_mono: Fix event argument for strings --- src/bin/eolian_mono/eolian/mono/klass.hh | 4 ++ src/tests/efl_mono/Events.cs | 71 ++++++++++++++++++++ src/tests/efl_mono/libefl_mono_native_test.c | 27 ++++++++ src/tests/efl_mono/test_testing.eo | 33 +++++++++ 4 files changed, 135 insertions(+) diff --git a/src/bin/eolian_mono/eolian/mono/klass.hh b/src/bin/eolian_mono/eolian/mono/klass.hh index 8657faf573..003f59f746 100644 --- a/src/bin/eolian_mono/eolian/mono/klass.hh +++ b/src/bin/eolian_mono/eolian/mono/klass.hh @@ -116,6 +116,10 @@ struct get_event_args_visitor typedef std::string result_type; std::string operator()(grammar::attributes::regular_type_def const&) const { + if (arg_type == "string") + { + return "eina.StringConversion.NativeUtf8ToManagedString(evt.Info)"; + } return "(" + arg_type + ")Marshal.PtrToStructure(evt.Info, typeof(" + arg_type + "))"; } std::string operator()(grammar::attributes::klass_name const&) const diff --git a/src/tests/efl_mono/Events.cs b/src/tests/efl_mono/Events.cs index 5719745a76..c0e9146bfa 100644 --- a/src/tests/efl_mono/Events.cs +++ b/src/tests/efl_mono/Events.cs @@ -33,5 +33,76 @@ class TestEoEvents Test.Assert(listener.correct_sender); Test.AssertEquals("loop_called", loop.GetName()); } + + public static void event_with_string_payload() + { + test.Testing obj = new test.TestingConcrete(); + string received_string = null; + + obj.EVT_WITH_STRING += (object sender, test.EVT_WITH_STRING_Args e) => { + received_string = e.arg; + }; + + obj.EmitEventWithString("Some args"); + + Test.AssertEquals("Some args", received_string); + } + + public static void event_with_int_payload() + { + test.Testing obj = new test.TestingConcrete(); + int received_int= 0; + + obj.EVT_WITH_INT += (object sender, test.EVT_WITH_INT_Args e) => { + received_int = e.arg; + }; + + obj.EmitEventWithInt(-1984); + + Test.AssertEquals(-1984, received_int); + } + + public static void event_with_uint_payload() + { + test.Testing obj = new test.TestingConcrete(); + uint received_uint = 0; + obj.EVT_WITH_UINT += (object sender, test.EVT_WITH_UINT_Args e) => { + received_uint = e.arg; + }; + + obj.EmitEventWithUint(0xbeef); + + Test.AssertEquals(0xbeef, received_uint); + } + + public static void event_with_float_payload() + { + test.Testing obj = new test.TestingConcrete(); + float received_float= 0; + + obj.EVT_WITH_FLOAT += (object sender, test.EVT_WITH_FLOAT_Args e) => { + received_float = e.arg; + }; + + obj.EmitEventWithFloat(3.14f); + + Test.AssertEquals(3.14f, received_float); + } + + public static void event_with_object_payload() + { + test.Testing obj = new test.TestingConcrete(); + test.Testing received_obj = null; + + obj.EVT_WITH_OBJ += (object sender, test.EVT_WITH_OBJ_Args e) => { + received_obj = e.arg; + }; + + test.Testing sent_obj = new test.TestingConcrete(); + + obj.EmitEventWithObj(sent_obj); + + Test.AssertEquals(sent_obj, received_obj); + } } } diff --git a/src/tests/efl_mono/libefl_mono_native_test.c b/src/tests/efl_mono/libefl_mono_native_test.c index f9b50dce26..e3543fc20b 100644 --- a/src/tests/efl_mono/libefl_mono_native_test.c +++ b/src/tests/efl_mono/libefl_mono_native_test.c @@ -3669,6 +3669,33 @@ void _test_testing_out_value(EINA_UNUSED Eo *obj, Test_Testing_Data *pd, Eina_Va *value = *pd->stored_value; } +void _test_testing_emit_event_with_string(Eo *obj, EINA_UNUSED Test_Testing_Data *pd, const char *data) +{ + char *ptr = strdup(data); + efl_event_callback_legacy_call(obj, TEST_TESTING_EVENT_EVT_WITH_STRING, ptr); + free(ptr); +} + +void _test_testing_emit_event_with_int(Eo *obj, EINA_UNUSED Test_Testing_Data *pd, int data) +{ + efl_event_callback_legacy_call(obj, TEST_TESTING_EVENT_EVT_WITH_INT, &data); +} + +void _test_testing_emit_event_with_uint(Eo *obj, EINA_UNUSED Test_Testing_Data *pd, unsigned int data) +{ + efl_event_callback_legacy_call(obj, TEST_TESTING_EVENT_EVT_WITH_UINT, &data); +} + +void _test_testing_emit_event_with_float(Eo *obj, EINA_UNUSED Test_Testing_Data *pd, float data) +{ + efl_event_callback_legacy_call(obj, TEST_TESTING_EVENT_EVT_WITH_FLOAT, &data); +} + +void _test_testing_emit_event_with_obj(Eo *obj, EINA_UNUSED Test_Testing_Data *pd, Eo *data) +{ + efl_event_callback_legacy_call(obj, TEST_TESTING_EVENT_EVT_WITH_OBJ, data); +} + #include "test_testing.eo.c" #include "test_numberwrapper.eo.c" diff --git a/src/tests/efl_mono/test_testing.eo b/src/tests/efl_mono/test_testing.eo index fec5f901f9..a65b4db8da 100644 --- a/src/tests/efl_mono/test_testing.eo +++ b/src/tests/efl_mono/test_testing.eo @@ -1455,9 +1455,42 @@ class Test.Testing (Efl.Object) { // struct_complex_ptr_return_own { // return: ptr(Test.StructComplex) @owned; // } + + emit_event_with_string { + params { + @in data: string; + } + } + emit_event_with_int { + params { + @in data: int; + } + } + emit_event_with_uint { + params { + @in data: uint; + } + } + emit_event_with_float { + params { + @in data: float; + } + } + emit_event_with_obj { + params { + @in data: Test.Testing; + } + } } implements { class.constructor; class.destructor; } + events { + evt,with,string @hot: string; + evt,with,int @hot: int; + evt,with,uint @hot: uint; + evt,with,float @hot: float; + evt,with,obj @hot: Test.Testing; + } }