From 305749f049ceb73071febe2ac723dadff7b69dbc Mon Sep 17 00:00:00 2001 From: Lauro Moura Date: Mon, 11 Mar 2019 19:22:28 -0300 Subject: [PATCH] csharp: Fix event names with underscore. Summary: names like `focus_geometry,changed` shoud be converted to FocusGeometryChanged instead of Focus_geometryChanged. Fixes T7735 Test Plan: run tests Reviewers: vitor.sousa, felipealmeida, segfaultxavi Reviewed By: vitor.sousa Subscribers: cedric, #reviewers, #committers Tags: #efl Maniphest Tasks: T7735 Differential Revision: https://phab.enlightenment.org/D8301 --- .../eolian_mono/eolian/mono/name_helpers.hh | 2 +- src/bin/eolian_mono/eolian/mono/utils.hh | 22 ++++++++++++++----- src/tests/efl_mono/Events.cs | 21 ++++++++++++++++++ src/tests/efl_mono/dummy_test_object.eo | 4 ++++ src/tests/efl_mono/libefl_mono_native_test.c | 5 +++++ 5 files changed, 47 insertions(+), 7 deletions(-) diff --git a/src/bin/eolian_mono/eolian/mono/name_helpers.hh b/src/bin/eolian_mono/eolian/mono/name_helpers.hh index 5fc1f18d22..074fd4f7ed 100644 --- a/src/bin/eolian_mono/eolian/mono/name_helpers.hh +++ b/src/bin/eolian_mono/eolian/mono/name_helpers.hh @@ -402,7 +402,7 @@ inline std::string klass_get_full_name(T const& clsname) // Events inline std::string managed_event_name(std::string const& name) { - return utils::to_pascal_case(utils::split(name, ','), "") + "Evt"; + return utils::to_pascal_case(utils::split(name, "_,"), "") + "Evt"; } inline std::string managed_event_args_short_name(attributes::event_def const& evt) diff --git a/src/bin/eolian_mono/eolian/mono/utils.hh b/src/bin/eolian_mono/eolian/mono/utils.hh index cbea48afa3..392cb00f11 100644 --- a/src/bin/eolian_mono/eolian/mono/utils.hh +++ b/src/bin/eolian_mono/eolian/mono/utils.hh @@ -30,20 +30,30 @@ namespace eolian_mono { namespace utils { return ret; } - std::vector split(std::string const &input, char delim) + std::vector split(std::string const &input, std::string delims) { - std::stringstream ss(input); - std::string name; std::vector names; + size_t pos = 0; - while (std::getline(ss, name, delim)) + while(pos != std::string::npos) { - if (!name.empty()) - names.push_back(name); + size_t newpos = input.find_first_of(delims, pos); + names.push_back(input.substr(pos, newpos-pos)); + pos = newpos; + + if (pos != std::string::npos) + pos++; } + return names; } + std::vector split(std::string const &input, char delim) + { + return split(input, {1, delim}); + } + + std::string to_pascal_case(const std::vector &names, std::string const& delim="") { std::vector outv(names.size()); diff --git a/src/tests/efl_mono/Events.cs b/src/tests/efl_mono/Events.cs index 2cf881804b..2d6dedb8e9 100644 --- a/src/tests/efl_mono/Events.cs +++ b/src/tests/efl_mono/Events.cs @@ -253,4 +253,25 @@ class TestInterfaceEvents Test.Assert(another_called); } } + +class TestEventNaming +{ + // For events named line focus_geometry,changed + public static void test_event_naming() + { + var obj = new Dummy.TestObject(); + var test_called = false; + + EventHandler cb = (object sender, EventArgs e) => { + test_called = true; + }; + + obj.EvtWithUnderEvt += cb; + + obj.EmitEventWithUnder(); + + Test.Assert(test_called); + + } +} } diff --git a/src/tests/efl_mono/dummy_test_object.eo b/src/tests/efl_mono/dummy_test_object.eo index d0311e96ac..0d6ced8e62 100644 --- a/src/tests/efl_mono/dummy_test_object.eo +++ b/src/tests/efl_mono/dummy_test_object.eo @@ -1310,6 +1310,9 @@ class Dummy.Test_Object extends Efl.Object implements Dummy.Test_Iface, Dummy.An } } + emit_event_with_under { + } + append_to_strbuf { params { @in buf: strbuf; @@ -1406,5 +1409,6 @@ class Dummy.Test_Object extends Efl.Object implements Dummy.Test_Iface, Dummy.An evt,with,struct @hot: Dummy.StructSimple; evt,with,struct,complex @hot: Dummy.StructComplex; evt,with,list @hot: list; + evt_with,under @hot: void; } } diff --git a/src/tests/efl_mono/libefl_mono_native_test.c b/src/tests/efl_mono/libefl_mono_native_test.c index 8968e46801..11190c9124 100644 --- a/src/tests/efl_mono/libefl_mono_native_test.c +++ b/src/tests/efl_mono/libefl_mono_native_test.c @@ -3789,6 +3789,11 @@ void _dummy_test_object_emit_event_with_list(Eo *obj, EINA_UNUSED Dummy_Test_Obj efl_event_callback_legacy_call(obj, DUMMY_TEST_OBJECT_EVENT_EVT_WITH_LIST, data); } +void _dummy_test_object_emit_event_with_under(Eo *obj, EINA_UNUSED Dummy_Test_Object_Data *pd) +{ + efl_event_callback_legacy_call(obj, DUMMY_TEST_OBJECT_EVENT_EVT_WITH_UNDER, NULL); +} + void _dummy_test_object_append_to_strbuf(EINA_UNUSED Eo *obj, EINA_UNUSED Dummy_Test_Object_Data *pd, Eina_Strbuf *buf, const char *str) { eina_strbuf_append(buf, str);