summaryrefslogtreecommitdiff
path: root/src/tests/efl_mono/Structs.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/tests/efl_mono/Structs.cs')
-rw-r--r--src/tests/efl_mono/Structs.cs118
1 files changed, 118 insertions, 0 deletions
diff --git a/src/tests/efl_mono/Structs.cs b/src/tests/efl_mono/Structs.cs
index e5640ab..d546298 100644
--- a/src/tests/efl_mono/Structs.cs
+++ b/src/tests/efl_mono/Structs.cs
@@ -1,3 +1,18 @@
1/*
2 * Copyright 2019 by its authors. See AUTHORS.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
1using System; 16using System;
2using System.Runtime.InteropServices; 17using System.Runtime.InteropServices;
3using System.Linq; 18using System.Linq;
@@ -47,6 +62,7 @@ internal class TestStructs
47 var t = new Dummy.TestObject(); 62 var t = new Dummy.TestObject();
48 bool r = t.StructSimpleIn(simple); 63 bool r = t.StructSimpleIn(simple);
49 Test.Assert(r, "Function returned false"); 64 Test.Assert(r, "Function returned false");
65 t.Dispose();
50 } 66 }
51 67
52 /* 68 /*
@@ -80,6 +96,7 @@ internal class TestStructs
80 bool r = t.StructSimpleOut(out simple); 96 bool r = t.StructSimpleOut(out simple);
81 Test.Assert(r, "Function returned false"); 97 Test.Assert(r, "Function returned false");
82 checkStructSimple(simple); 98 checkStructSimple(simple);
99 t.Dispose();
83 } 100 }
84 101
85 /* 102 /*
@@ -107,6 +124,7 @@ internal class TestStructs
107 var t = new Dummy.TestObject(); 124 var t = new Dummy.TestObject();
108 var simple = t.StructSimpleReturn(); 125 var simple = t.StructSimpleReturn();
109 checkStructSimple(simple); 126 checkStructSimple(simple);
127 t.Dispose();
110 } 128 }
111 129
112 /* 130 /*
@@ -221,6 +239,7 @@ internal class TestStructs
221 t.CallStructSimpleIn(simple); 239 t.CallStructSimpleIn(simple);
222 Test.Assert(t.called); 240 Test.Assert(t.called);
223 Test.AssertEquals(simple.Fstring, t.received.Fstring); 241 Test.AssertEquals(simple.Fstring, t.received.Fstring);
242 t.Dispose();
224 } 243 }
225 244
226 /* 245 /*
@@ -254,6 +273,7 @@ internal class TestStructs
254 t.CallStructSimpleOut(out simple); 273 t.CallStructSimpleOut(out simple);
255 Test.Assert(t.called, "override was not called"); 274 Test.Assert(t.called, "override was not called");
256 Test.AssertEquals("Virtual Struct Out", simple.Fstring); 275 Test.AssertEquals("Virtual Struct Out", simple.Fstring);
276 t.Dispose();
257 } 277 }
258 278
259 /* 279 /*
@@ -282,6 +302,7 @@ internal class TestStructs
282 Dummy.StructSimple simple = t.CallStructSimpleReturn(); 302 Dummy.StructSimple simple = t.CallStructSimpleReturn();
283 Test.Assert(t.called, "override was not called"); 303 Test.Assert(t.called, "override was not called");
284 Test.AssertEquals("Virtual Struct Return", simple.Fstring); 304 Test.AssertEquals("Virtual Struct Return", simple.Fstring);
305 t.Dispose();
285 } 306 }
286 307
287 /* 308 /*
@@ -310,6 +331,7 @@ internal class TestStructs
310 var t = new Dummy.TestObject(); 331 var t = new Dummy.TestObject();
311 bool r = t.StructComplexIn(complex); 332 bool r = t.StructComplexIn(complex);
312 Test.Assert(r, "Function returned false"); 333 Test.Assert(r, "Function returned false");
334 t.Dispose();
313 } 335 }
314 336
315 // public static void complex_ptr_in() 337 // public static void complex_ptr_in()
@@ -327,6 +349,7 @@ internal class TestStructs
327 bool r = t.StructComplexOut(out complex); 349 bool r = t.StructComplexOut(out complex);
328 Test.Assert(r, "Function returned false"); 350 Test.Assert(r, "Function returned false");
329 checkStructComplex(complex); 351 checkStructComplex(complex);
352 t.Dispose();
330 } 353 }
331 354
332 // public static void complex_ptr_out() 355 // public static void complex_ptr_out()
@@ -342,6 +365,7 @@ internal class TestStructs
342 var t = new Dummy.TestObject(); 365 var t = new Dummy.TestObject();
343 var complex = t.StructComplexReturn(); 366 var complex = t.StructComplexReturn();
344 checkStructComplex(complex); 367 checkStructComplex(complex);
368 t.Dispose();
345 } 369 }
346#endif 370#endif
347 // public static void complex_ptr_return() 371 // public static void complex_ptr_return()
@@ -353,4 +377,98 @@ internal class TestStructs
353 // } 377 // }
354} 378}
355 379
380internal class TestStructEquality
381{
382 static Dummy.StructSimple a = new Dummy.StructSimple(1, 2, (char)3, 4, Fstring: "", Fmstring: "", Fstringshare: "");
383 static Dummy.StructSimple b = new Dummy.StructSimple(1, 2, (char)3, 4, Fstring: "", Fmstring: "", Fstringshare: "");
384
385 static Dummy.StructSimple c = new Dummy.StructSimple(4, 3, (char)2, 1, Fstring: "", Fmstring: "", Fstringshare: "");
386
387 // to check if we differ on a single struct field
388 static Dummy.StructSimple singleDifferentField = new Dummy.StructSimple(1, 2, (char)3, 5, Fstring: "", Fmstring: "", Fstringshare: "");
389
390 public static void test_equals()
391 {
392 Test.AssertEquals(a, b);
393 Test.AssertNotEquals(a, c);
394 Test.AssertNotEquals(a, singleDifferentField);
395 }
396
397 public static void test_equals_different_types()
398 {
399 Test.Assert(!(a.Equals(new Object())));
400 }
401
402 public static void test_equatable()
403 {
404 Test.Assert(((IEquatable<Dummy.StructSimple>)a).Equals(b));
405 Test.Assert(!((IEquatable<Dummy.StructSimple>)a).Equals(c));
406 Test.Assert(!((IEquatable<Dummy.StructSimple>)a).Equals(singleDifferentField));
407 }
408
409 public static void test_equality_operators()
410 {
411 Test.Assert(a == b);
412 Test.Assert(a != c);
413 Test.Assert(a != singleDifferentField);
414 }
415
416 public static void test_hash_code()
417 {
418 Test.AssertEquals(a.GetHashCode(), b.GetHashCode());
419 Test.AssertNotEquals(a.GetHashCode(), c.GetHashCode());
420 Test.AssertNotEquals(a.GetHashCode(), singleDifferentField.GetHashCode());
421 }
422
423#if !MONO
424 public static void test_deconstruct() {
425 var p = new Eina.Position2D(1, 2);
426 var (x, y) = p;
427
428 Test.AssertEquals(x, 1);
429 Test.AssertEquals(y, 2);
430 }
431#endif
432}
433
434internal class TestStructTuples
435{
436 private static Eina.Position2D simulate_position_usage(Eina.Position2D p) {
437 return p;
438 }
439
440 public static void test_same_type_fields_assign_conversion() {
441 Eina.Position2D p = (1, 2);
442 Test.AssertEquals(p.X, 1);
443 Test.AssertEquals(p.Y, 2);
444 }
445
446 public static void test_same_type_fields_call_conversion() {
447 var p = simulate_position_usage((1, 2));
448 Test.AssertEquals(p.X, 1);
449 Test.AssertEquals(p.Y, 2);
450 }
451
452 public static void test_different_type_fields_assign_conversion() {
453 Efl.Ui.FormatValue v = (1, "Format");
454 Test.AssertEquals(v.Value, 1);
455 Test.AssertEquals(v.Text, "Format");
456 }
457
458#if EFL_BETA
459 public static void test_complex_fields_assign_conversion() {
460 var pos = new Eina.Position2D(1, 2);
461 var action = Efl.Ui.SelectionAction.Unknown;
462 var format = Efl.Ui.SelectionFormat.None;
463 var item = null as Efl.Canvas.Vg.Object;
464
465 Efl.Dnd.DragPos attr = (pos, action, format, item);
466 Test.AssertEquals(attr.Pos, pos);
467 Test.AssertEquals(attr.Action, action);
468 Test.AssertEquals(attr.Format, format);
469 Test.AssertEquals(attr.Item, item);
470 }
471#endif
472}
473
356} 474}