summaryrefslogtreecommitdiff
path: root/src/tests/efl_mono
diff options
context:
space:
mode:
authorLauro Moura <lauromoura@expertisesolutions.com.br>2019-09-10 19:30:46 -0300
committerLauro Moura <lauromoura@expertisesolutions.com.br>2019-09-10 19:30:47 -0300
commitdfb856158c8ea37d9caa170a6794447ec18ecdd9 (patch)
tree7d9130fac1c8d4a46341192feb965d842279f2fc /src/tests/efl_mono
parentd1890f5eca0b439c902999716ed0a49634e848a1 (diff)
csharp: Skip non-public members from interfaces
Summary: Eolian allows non-public members in interfaces and mixins (usually @protected). As both kinds are converted to C# interfaces, this causes problem as non-public members are forbidden in C# interfaces. This commit changes eolian_mono by removing those members from the C# interfaces. If a generated class implements the interface, the method is generated as if it were a protected member of the class directly. For mixed properties like `Efl.Io.Reader.CanRead { get; set @protected; }`, the interface has only the public getter and the the implementing class has both the public getter and the protected setter. With this, C# devs won't be able to directly implement protected Eo methods from interfaces. (But this really does not make sense from the C# point of view). ref T7494 Reviewers: segfaultxavi, felipealmeida, YOhoho Reviewed By: YOhoho Subscribers: cedric, brunobelo, Jaehyun_Cho, #reviewers, woohyun, #committers Tags: #efl Maniphest Tasks: T7494 Differential Revision: https://phab.enlightenment.org/D9800
Diffstat (limited to 'src/tests/efl_mono')
-rw-r--r--src/tests/efl_mono/Eo.cs74
-rw-r--r--src/tests/efl_mono/dummy_interfaces.c2
-rw-r--r--src/tests/efl_mono/dummy_test_iface.eo31
-rw-r--r--src/tests/efl_mono/dummy_test_object.c12
-rw-r--r--src/tests/efl_mono/dummy_test_object.eo2
5 files changed, 121 insertions, 0 deletions
diff --git a/src/tests/efl_mono/Eo.cs b/src/tests/efl_mono/Eo.cs
index 56813b3..efb1faa 100644
--- a/src/tests/efl_mono/Eo.cs
+++ b/src/tests/efl_mono/Eo.cs
@@ -1,6 +1,7 @@
1using System; 1using System;
2using System.Linq; 2using System.Linq;
3using System.Collections.Generic; 3using System.Collections.Generic;
4using System.Reflection;
4 5
5namespace TestSuite 6namespace TestSuite
6{ 7{
@@ -533,4 +534,77 @@ class TestObjectDeletion
533 } 534 }
534} 535}
535 536
537class TestProtectedInterfaceMembers
538{
539
540 private class MyObject : Dummy.TestObject
541 {
542 public MyObject(Efl.Object parent = null) : base(parent)
543 {
544 }
545
546 protected override int MethodProtected(int x)
547 {
548 return x * x;
549 }
550 }
551
552 public static void test_protected_interface_in_generated_class_called_from_c()
553 {
554 var obj = new Dummy.TestObject();
555 Test.AssertEquals(obj.CallMethodProtected(42), -42);
556 }
557
558 public static void test_protected_interface_in_inherited_class_called_from_c()
559 {
560 var obj = new MyObject();
561 Test.AssertEquals(obj.CallMethodProtected(42), 42 * 42);
562 }
563
564 public static void test_interface_skipped_protected()
565 {
566 var type = typeof(Dummy.ITestIface);
567 var methods = type.GetMethods(BindingFlags.Public | BindingFlags.Instance);
568
569 // Fully protected property
570 Test.AssertNull(methods.SingleOrDefault(m => m.Name == "GetProtectedProp"));
571 Test.AssertNull(methods.SingleOrDefault(m => m.Name == "SetProtectedProp"));
572
573 // Partially protected property
574 Test.AssertNotNull(methods.SingleOrDefault(m => m.Name == "GetPublicGetterPrivateSetter"));
575 Test.AssertNull(methods.SingleOrDefault(m => m.Name == "SetPublicGetterPrivateSetter"));
576
577 var properties = type.GetProperties(BindingFlags.Public | BindingFlags.Instance);
578 Test.AssertNull(properties.SingleOrDefault(m => m.Name == "ProtectedProp"));
579 Test.AssertNotNull(properties.SingleOrDefault(m => m.Name == "PublicGetterPrivateSetter"));
580 }
581
582 public static void test_interface_skipped_protected_in_implementation()
583 {
584 var type = typeof(Dummy.TestObject);
585
586 // Fully protected property
587 var protected_methods = type.GetMethods(BindingFlags.NonPublic | BindingFlags.Instance).Where(m => m.IsFamily);
588 Test.AssertNotNull(protected_methods.SingleOrDefault(m => m.Name == "GetProtectedProp"));
589 Test.AssertNotNull(protected_methods.SingleOrDefault(m => m.Name == "SetProtectedProp"));
590
591 // Partially protected property
592 var public_methods = type.GetMethods(BindingFlags.Public | BindingFlags.Instance);
593 Test.AssertNotNull(public_methods.SingleOrDefault(m => m.Name == "GetPublicGetterPrivateSetter"));
594 Test.AssertNotNull(protected_methods.SingleOrDefault(m => m.Name == "SetPublicGetterPrivateSetter"));
595
596 var protected_properties = type.GetProperties(BindingFlags.NonPublic | BindingFlags.Instance);
597 var prop = protected_properties.SingleOrDefault(m => m.Name == "ProtectedProp");
598 Test.AssertNotNull(prop);
599 Test.Assert(prop.GetMethod.IsFamily);
600 Test.Assert(prop.SetMethod.IsFamily);
601
602 var public_properties = type.GetProperties(BindingFlags.Public | BindingFlags.Instance);
603 prop = public_properties.SingleOrDefault(m => m.Name == "PublicGetterPrivateSetter");
604 Test.AssertNotNull(prop);
605 Test.Assert(prop.GetMethod.IsPublic);
606 Test.Assert(prop.SetMethod.IsFamily);
607 }
608}
609
536} 610}
diff --git a/src/tests/efl_mono/dummy_interfaces.c b/src/tests/efl_mono/dummy_interfaces.c
index f4b3ca5..c60ec59 100644
--- a/src/tests/efl_mono/dummy_interfaces.c
+++ b/src/tests/efl_mono/dummy_interfaces.c
@@ -1,4 +1,6 @@
1// Include file for interfaces .eo.c files 1// Include file for interfaces .eo.c files
2#define DUMMY_TEST_IFACE_PROTECTED
3
2#include "libefl_mono_native_test.h" 4#include "libefl_mono_native_test.h"
3 5
4#include "dummy_test_iface.eo.c" 6#include "dummy_test_iface.eo.c"
diff --git a/src/tests/efl_mono/dummy_test_iface.eo b/src/tests/efl_mono/dummy_test_iface.eo
index 3ab37f5..068b135 100644
--- a/src/tests/efl_mono/dummy_test_iface.eo
+++ b/src/tests/efl_mono/dummy_test_iface.eo
@@ -10,6 +10,37 @@ interface Dummy.Test_Iface
10 data: int; 10 data: int;
11 } 11 }
12 } 12 }
13
14 method_protected @protected @const {
15 params {
16 @in x: int;
17 }
18 return: int;
19 }
20
21 call_method_protected @const {
22 params {
23 @in x: int;
24 }
25 return: int;
26 }
27
28 @property protected_prop @protected {
29 get {}
30 set {}
31 values {
32 data: int;
33 }
34 }
35
36 @property public_getter_private_setter {
37 get {}
38 set @protected {}
39 values {
40 data: int;
41 }
42 }
43
13 } 44 }
14 events { 45 events {
15 nonconflicted: void; 46 nonconflicted: void;
diff --git a/src/tests/efl_mono/dummy_test_object.c b/src/tests/efl_mono/dummy_test_object.c
index 6c32f80..a880dc4 100644
--- a/src/tests/efl_mono/dummy_test_object.c
+++ b/src/tests/efl_mono/dummy_test_object.c
@@ -1,4 +1,6 @@
1 1
2#define DUMMY_TEST_IFACE_PROTECTED
3
2#include "libefl_mono_native_test.h" 4#include "libefl_mono_native_test.h"
3 5
4typedef struct Dummy_Test_Object_Data 6typedef struct Dummy_Test_Object_Data
@@ -4704,6 +4706,16 @@ const Eina_Value_Type *_dummy_test_object_mirror_value_type(EINA_UNUSED const Eo
4704 return type; 4706 return type;
4705} 4707}
4706 4708
4709int _dummy_test_object_dummy_test_iface_method_protected(EINA_UNUSED const Eo *obj, EINA_UNUSED Dummy_Test_Object_Data *pd, int x)
4710{
4711 return -x;
4712}
4713
4714int _dummy_test_object_dummy_test_iface_call_method_protected(const Eo *obj, EINA_UNUSED Dummy_Test_Object_Data *pd, int x)
4715{
4716 return dummy_test_iface_method_protected(obj, x);
4717}
4718
4707// Inherit 4719// Inherit
4708int _dummy_inherit_helper_receive_dummy_and_call_int_out(Dummy_Test_Object *x) 4720int _dummy_inherit_helper_receive_dummy_and_call_int_out(Dummy_Test_Object *x)
4709{ 4721{
diff --git a/src/tests/efl_mono/dummy_test_object.eo b/src/tests/efl_mono/dummy_test_object.eo
index 2fa2c32..676b68a 100644
--- a/src/tests/efl_mono/dummy_test_object.eo
+++ b/src/tests/efl_mono/dummy_test_object.eo
@@ -1653,6 +1653,8 @@ class Dummy.Test_Object extends Efl.Object implements Dummy.Test_Iface {
1653 Efl.Object.provider_find; 1653 Efl.Object.provider_find;
1654 Dummy.Test_Iface.emit_nonconflicted; 1654 Dummy.Test_Iface.emit_nonconflicted;
1655 Dummy.Test_Iface.iface_prop { get; set; } 1655 Dummy.Test_Iface.iface_prop { get; set; }
1656 Dummy.Test_Iface.method_protected;
1657 Dummy.Test_Iface.call_method_protected;
1656 } 1658 }
1657 events { 1659 events {
1658 evt,with,string @hot: const(string); 1660 evt,with,string @hot: const(string);