summaryrefslogtreecommitdiff
path: root/src/tests/efl_mono/Eo.cs
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/Eo.cs
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/Eo.cs')
-rw-r--r--src/tests/efl_mono/Eo.cs74
1 files changed, 74 insertions, 0 deletions
diff --git a/src/tests/efl_mono/Eo.cs b/src/tests/efl_mono/Eo.cs
index 56813b3f87..efb1faa306 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}