summaryrefslogtreecommitdiff
path: root/src/tests/efl_mono/Eo.cs
diff options
context:
space:
mode:
authorLauro Moura <lauromoura@expertisesolutions.com.br>2018-11-29 21:04:37 -0200
committerVitor Sousa <vitorsousa@expertisesolutions.com.br>2018-11-29 21:29:48 -0200
commit3623753c1d6b893955a1c31e8559a2312f674192 (patch)
treee862682ff92d34ce4ebf44c95efa24ba3a57fe7a /src/tests/efl_mono/Eo.cs
parenteec7bc458eee333fd7237a3bd43e8c2c884f21ca (diff)
csharp: Change to new class API.
Summary: As discussed in T7204: - Eo Interfaces/mixins -> C# Interfaces with concrete class implementations - Eo Regular/Abstracts -> Proper C# classes - Added some new generators and helper methods. - Refactored the class generator, splitting into helper methods Eo handles now are stored only in the "root" class in any given inheritance tree (generally, Efl.Object), and accessible to each child. Methods also are defined in a single place instead of repeatedly generated in everyfile, reducing the size of the generated .dll from 30MB to around 4.5MB. Mixins are generated as C# interfaces but any regular class it inherits from is lost, as we can't have interfaces inheriting from regular classes. This will be dealt with in a later commit. Summary of API Changes: - Merged Inherit/Concrete classes. (These suffixes disappear from regular classes). - Interface still have implementations with 'Concrete' suffix for when they are returned from methods. - Removed 'I' from interface names. - Removed interfaces for regular/abstract Eo classes. - Concrete classes for interfaces/mixins hold the event argument struct. - Removed '_' from classes, enums, structs, etc, as indicated in C# naming conventions. - Namespaces are now Camel.Cased. - Renamed IWrapper's raw_handle/raw_klass to NativeHandle/NativeClass Also renamed the test classes as after the namespace change, the test namespace Test can conflict with the helper Test namespace. (And use more meaningful names than Test.Testing...) Also Fixes T7336 by removing a deprecated example and adding efl_loop_timer_example to build system. Fixes T7451 by hiding the class_get DllImports and renaming the IWrapper fields. The native handlers are used in the manual binding. Still need to work: - As there are still some events names clashing (e.g. Efl.Ui.Bg with "resize" from Efl.Gfx.Entity and Efl.Gfx.Image), Events are currently declared on the interface and implemented "namespaced" in the classes, requiring the cast to the interface to access the event. - The Mixin Conundrum. Mixin inheritance will be dealt in a future commit. Depends on D7260 Reviewers: segfaultxavi, vitor.sousa, felipealmeida, Jaehyun_Cho Reviewed By: vitor.sousa Subscribers: cedric, #reviewers, #committers Tags: #efl Maniphest Tasks: T7451, T7336 Differential Revision: https://phab.enlightenment.org/D7262
Diffstat (limited to 'src/tests/efl_mono/Eo.cs')
-rw-r--r--src/tests/efl_mono/Eo.cs131
1 files changed, 84 insertions, 47 deletions
diff --git a/src/tests/efl_mono/Eo.cs b/src/tests/efl_mono/Eo.cs
index 5b88f57464..535c309e1c 100644
--- a/src/tests/efl_mono/Eo.cs
+++ b/src/tests/efl_mono/Eo.cs
@@ -6,7 +6,7 @@ namespace TestSuite
6 6
7class TestEo 7class TestEo
8{ 8{
9 private class Derived : test.TestingInherit 9 private class Derived : Dummy.TestObject
10 { 10 {
11 } 11 }
12 12
@@ -15,21 +15,20 @@ class TestEo
15 // 15 //
16 public static void return_same_object() 16 public static void return_same_object()
17 { 17 {
18 test.ITesting testing = new test.Testing(); 18 var testing = new Dummy.TestObject();
19 test.ITesting o1 = testing.ReturnObject(); 19 var o1 = testing.ReturnObject();
20 Test.Assert(o1.raw_handle != IntPtr.Zero); 20 Test.Assert(o1.NativeHandle != IntPtr.Zero);
21 Test.Assert(o1.raw_handle == testing.raw_handle); 21 Test.Assert(o1.NativeHandle == testing.NativeHandle);
22 test.ITesting o2 = o1.ReturnObject(); 22 var o2 = o1.ReturnObject();
23 Test.Assert(o2.raw_handle != IntPtr.Zero); 23 Test.Assert(o2.NativeHandle != IntPtr.Zero);
24 Test.Assert(o2.raw_handle == o1.raw_handle); 24 Test.Assert(o2.NativeHandle == o1.NativeHandle);
25 } 25 }
26
27 /* Commented out as adding the event listener seems to prevent it from being GC'd. 26 /* Commented out as adding the event listener seems to prevent it from being GC'd.
28 public static void destructor_really_frees() 27 public static void destructor_really_frees()
29 { 28 {
30 bool delEventCalled = false; 29 bool delEventCalled = false;
31 { 30 {
32 test.ITesting obj = new test.Testing(); 31 var obj = new Dummy.TestObject();
33 obj.DEL += (object sender, EventArgs e) => { delEventCalled = true; }; 32 obj.DEL += (object sender, EventArgs e) => { delEventCalled = true; };
34 } 33 }
35 34
@@ -46,8 +45,10 @@ class TestEo
46 { 45 {
47 bool delEventCalled = false; 46 bool delEventCalled = false;
48 { 47 {
49 test.ITesting obj = new test.Testing(); 48 var obj = new Dummy.TestObject();
49 Eina.Log.Error($"Created object 0x{obj.NativeHandle.ToInt64():x}");
50 obj.DelEvt += (object sender, EventArgs e) => { delEventCalled = true; }; 50 obj.DelEvt += (object sender, EventArgs e) => { delEventCalled = true; };
51 Eina.Log.Error($"Will dispose object 0x{obj.NativeHandle.ToInt64():x}");
51 ((IDisposable)obj).Dispose(); 52 ((IDisposable)obj).Dispose();
52 } 53 }
53 54
@@ -59,7 +60,7 @@ class TestEo
59 { 60 {
60 bool delEventCalled = false; 61 bool delEventCalled = false;
61 { 62 {
62 test.ITesting obj = new Derived(); 63 var obj = new Derived();
63 obj.DEL += (object sender, EventArgs e) => { delEventCalled = true; }; 64 obj.DEL += (object sender, EventArgs e) => { delEventCalled = true; };
64 } 65 }
65 66
@@ -76,7 +77,7 @@ class TestEo
76 { 77 {
77 bool delEventCalled = false; 78 bool delEventCalled = false;
78 { 79 {
79 test.ITesting obj = new Derived(); 80 var obj = new Derived();
80 obj.DEL += (object sender, EventArgs e) => { delEventCalled = true; }; 81 obj.DEL += (object sender, EventArgs e) => { delEventCalled = true; };
81 ((IDisposable)obj).Dispose(); 82 ((IDisposable)obj).Dispose();
82 } 83 }
@@ -86,7 +87,8 @@ class TestEo
86 */ 87 */
87} 88}
88 89
89class MyLoop : efl.LoopInherit 90
91class MyLoop : Efl.Loop
90{ 92{
91 public MyLoop() : base(null) { } 93 public MyLoop() : base(null) { }
92} 94}
@@ -95,8 +97,8 @@ class TestEoInherit
95{ 97{
96 public static void instantiate_inherited() 98 public static void instantiate_inherited()
97 { 99 {
98 efl.ILoop loop = new MyLoop(); 100 Efl.Loop loop = new MyLoop();
99 Test.Assert(loop.raw_handle != System.IntPtr.Zero); 101 Test.Assert(loop.NativeHandle != System.IntPtr.Zero);
100 } 102 }
101} 103}
102 104
@@ -104,7 +106,7 @@ class TestEoNames
104{ 106{
105 public static void name_getset() 107 public static void name_getset()
106 { 108 {
107 test.ITesting obj = new test.Testing(); 109 var obj = new Dummy.TestObject();
108 110
109 string name = "Dummy"; 111 string name = "Dummy";
110 obj.SetName(name); 112 obj.SetName(name);
@@ -118,9 +120,9 @@ class TestEoConstructingMethods
118 { 120 {
119 bool called = false; 121 bool called = false;
120 string name = "Test object"; 122 string name = "Test object";
121 test.ITesting obj = new test.Testing(null, (test.ITesting a) => { 123 var obj = new Dummy.TestObject(null, (Dummy.TestObject a) => {
122 called = true; 124 called = true;
123 Console.WriteLine("callback: obj raw_handle: {0:x}", a.raw_handle); 125 Console.WriteLine("callback: obj NativeHandle: {0:x}", a.NativeHandle);
124 a.SetName(name); 126 a.SetName(name);
125 }); 127 });
126 128
@@ -128,10 +130,10 @@ class TestEoConstructingMethods
128 Test.AssertEquals(name, obj.GetName()); 130 Test.AssertEquals(name, obj.GetName());
129 } 131 }
130 132
131 private class Derived : test.TestingInherit 133 private class Derived : Dummy.TestObject
132 { 134 {
133 public Derived(test.ITesting parent = null, 135 public Derived(Dummy.TestObject parent = null,
134 test.TestingInherit.ConstructingMethod cb = null) : base(parent, cb) { 136 Dummy.TestObject.ConstructingMethod cb = null) : base(parent, cb) {
135 } 137 }
136 } 138 }
137 139
@@ -139,7 +141,7 @@ class TestEoConstructingMethods
139 { 141 {
140 bool called = false; 142 bool called = false;
141 string name = "Another test object"; 143 string name = "Another test object";
142 Derived obj = new Derived(null, (test.ITesting a) => { 144 Derived obj = new Derived(null, (Dummy.TestObject a) => {
143 called = true; 145 called = true;
144 a.SetComment(name); 146 a.SetComment(name);
145 }); 147 });
@@ -153,41 +155,41 @@ class TestEoParent
153{ 155{
154 public static void basic_parent() 156 public static void basic_parent()
155 { 157 {
156 test.ITesting parent = new test.Testing(null); 158 var parent = new Dummy.TestObject(null);
157 test.ITesting child = new test.Testing(parent); 159 var child = new Dummy.TestObject(parent);
158 160
159 Test.AssertEquals(parent, child.GetParent()); 161 Test.AssertEquals(parent, child.GetParent());
160 162
161 test.ITesting parent_retrieved = test.Testing.static_cast(child.GetParent()); 163 var parent_retrieved = Dummy.TestObject.static_cast(child.GetParent());
162 Test.AssertEquals(parent, parent_retrieved); 164 Test.AssertEquals(parent, parent_retrieved);
163 } 165 }
164 166
165 public static void parent_inherited_class() 167 public static void parent_inherited_class()
166 { 168 {
167 test.INumberwrapper parent = new test.Numberwrapper(null); 169 Dummy.Numberwrapper parent = new Dummy.Numberwrapper(null);
168 test.ITesting child = new test.Testing(parent); 170 var child = new Dummy.TestObject(parent);
169 171
170 Test.AssertEquals(parent, child.GetParent()); 172 Test.AssertEquals(parent, child.GetParent());
171 173
172 test.INumberwrapper parent_retrieved = test.Numberwrapper.static_cast(child.GetParent()); 174 Dummy.Numberwrapper parent_retrieved = Dummy.Numberwrapper.static_cast(child.GetParent());
173 Test.AssertEquals(parent, parent_retrieved); 175 Test.AssertEquals(parent, parent_retrieved);
174 } 176 }
175 177
176 private class Derived : test.TestingInherit 178 private class Derived : Dummy.TestObject
177 { 179 {
178 public Derived(test.ITesting parent = null) : base (parent) 180 public Derived(Dummy.TestObject parent = null) : base (parent)
179 { 181 {
180 } 182 }
181 } 183 }
182 184
183 public static void basic_parent_managed_inherit() 185 public static void basic_parent_managed_inherit()
184 { 186 {
185 test.ITesting parent = new Derived(null); 187 var parent = new Derived(null);
186 test.ITesting child = new Derived(parent); 188 var child = new Derived(parent);
187 189
188 Test.AssertEquals(parent, child.GetParent()); 190 Test.AssertEquals(parent, child.GetParent());
189 191
190 test.ITesting parent_from_cast = test.Testing.static_cast(child.GetParent()); 192 var parent_from_cast = Dummy.TestObject.static_cast(child.GetParent());
191 Test.AssertEquals(parent, parent_from_cast); 193 Test.AssertEquals(parent, parent_from_cast);
192 } 194 }
193} 195}
@@ -197,15 +199,15 @@ class TestKlassMethods
197 public static void basic_class_method() 199 public static void basic_class_method()
198 { 200 {
199 int reference = 0xbeef; 201 int reference = 0xbeef;
200 test.Testing.SetKlassProp(reference); 202 Dummy.TestObject.SetKlassProp(reference);
201 Test.AssertEquals(reference, test.Testing.GetKlassProp()); 203 Test.AssertEquals(reference, Dummy.TestObject.GetKlassProp());
202 } 204 }
203 205
204 public static void inherited_class_method() 206 public static void inherited_class_method()
205 { 207 {
206 int reference = 0xdead; 208 int reference = 0xdead;
207 test.Child.SetKlassProp(reference); 209 Dummy.Child.SetKlassProp(reference);
208 Test.AssertEquals(reference, test.Child.GetKlassProp()); 210 Test.AssertEquals(reference, Dummy.Child.GetKlassProp());
209 } 211 }
210} 212}
211 213
@@ -213,13 +215,13 @@ class TestTypedefs
213{ 215{
214 public static void basic_typedef_test() 216 public static void basic_typedef_test()
215 { 217 {
216 test.ITesting obj = new test.Testing(); 218 var obj = new Dummy.TestObject();
217 test.MyInt input = 1900; 219 Dummy.MyInt input = 1900;
218 test.MyInt receiver; 220 Dummy.MyInt receiver;
219 221
220 int ret = obj.BypassTypedef(input, out receiver); 222 int ret = obj.BypassTypedef(input, out receiver);
221 223
222 Test.AssertEquals((test.MyInt)ret, input); 224 Test.AssertEquals((Dummy.MyInt)ret, input);
223 Test.AssertEquals(receiver, input); 225 Test.AssertEquals(receiver, input);
224 226
225 } 227 }
@@ -229,13 +231,13 @@ class TestEoAccessors
229{ 231{
230 public static void basic_eo_accessors() 232 public static void basic_eo_accessors()
231 { 233 {
232 test.ITesting obj = new test.Testing(); 234 var obj = new Dummy.TestObject();
233 eina.List<int> lst = new eina.List<int>(); 235 Eina.List<int> lst = new Eina.List<int>();
234 lst.Append(4); 236 lst.Append(4);
235 lst.Append(3); 237 lst.Append(3);
236 lst.Append(2); 238 lst.Append(2);
237 lst.Append(5); 239 lst.Append(5);
238 eina.Accessor<int> acc = obj.CloneAccessor(lst.GetAccessor()); 240 Eina.Accessor<int> acc = obj.CloneAccessor(lst.GetAccessor());
239 241
240 var zipped = acc.Zip(lst, (first, second) => new Tuple<int, int>(first, second)); 242 var zipped = acc.Zip(lst, (first, second) => new Tuple<int, int>(first, second));
241 243
@@ -248,10 +250,10 @@ class TestEoAccessors
248 250
249class TestEoFinalize 251class TestEoFinalize
250{ 252{
251 public sealed class Inherit : efl.ObjectInherit 253 public sealed class Inherit : Efl.Object
252 { 254 {
253 public bool finalizeCalled = false; 255 public bool finalizeCalled = false;
254 public override efl.IObject FinalizeAdd() 256 public override Efl.Object FinalizeAdd()
255 { 257 {
256 finalizeCalled = true; 258 finalizeCalled = true;
257 return this; 259 return this;
@@ -266,4 +268,39 @@ class TestEoFinalize
266 } 268 }
267} 269}
268 270
271class TestEoMultipleChildClasses
272{
273
274 public sealed class FirstChild : Efl.Object
275 {
276 public int receivedValue = 0;
277 public override Efl.Object FinalizeAdd()
278 {
279 receivedValue = 1;
280 return this;
281 }
282 }
283
284 public sealed class SecondChild : Efl.Object
285 {
286 public int receivedValue = 0;
287 public override Efl.Object FinalizeAdd()
288 {
289 receivedValue = 2;
290 return this;
291 }
292 }
293
294 public static void test_multiple_child_classes()
295 {
296 FirstChild obj = new FirstChild();
297 Test.AssertEquals(1, obj.receivedValue);
298 SecondChild obj2 = new SecondChild();
299 Test.AssertEquals(2, obj2.receivedValue);
300
301 obj = new FirstChild();
302 Test.AssertEquals(1, obj.receivedValue);
303 }
304}
305
269} 306}