summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVitor Sousa <vitorsousa@expertisesolutions.com.br>2019-06-11 15:33:39 -0300
committerVitor Sousa <vitorsousa@expertisesolutions.com.br>2019-06-11 15:33:39 -0300
commit6e83ee95c18821d5b01b6560546430142876601e (patch)
tree5e0c88f62db7d6967330c8b1acfe642111d5a20a
parent2a99be2b520e07aac6a35bc1f75f2c6dc7eb7e6f (diff)
equality methods and some test stubsdevs/vitorsousa/csharp_stringshare_containers
-rw-r--r--src/bindings/mono/eina_mono/eina_common.cs80
-rw-r--r--src/tests/efl_mono/Eina.cs151
2 files changed, 230 insertions, 1 deletions
diff --git a/src/bindings/mono/eina_mono/eina_common.cs b/src/bindings/mono/eina_mono/eina_common.cs
index 1269aa9e5b..53a63783e5 100644
--- a/src/bindings/mono/eina_mono/eina_common.cs
+++ b/src/bindings/mono/eina_mono/eina_common.cs
@@ -196,7 +196,10 @@ public enum Ownership
196 Unmanaged 196 Unmanaged
197} 197}
198 198
199public class StringShare 199/// TODO: reword this \/ \/ \/ \/ \/ \/ \/
200/// Convert to a String the quickest possible.
201/// Implements Equality/Inequality methods just because they have standard System.Object implementations that would not signal a compilation fail. The intent is not to provide full string API.
202public class StringShare : IEquatable<StringShare>, IEquatable<string>
200{ 203{
201 public StringShare() 204 public StringShare()
202 { 205 {
@@ -211,19 +214,94 @@ public class StringShare
211 214
212 public static implicit operator string(StringShare ss) 215 public static implicit operator string(StringShare ss)
213 { 216 {
217 if (ss == null)
218 {
219 return null;
220 }
221
214 return ss.Str; 222 return ss.Str;
215 } 223 }
216 224
217 public static implicit operator StringShare(string s) 225 public static implicit operator StringShare(string s)
218 { 226 {
227 if (s == null)
228 {
229 return null;
230 }
231
219 return new StringShare(s); 232 return new StringShare(s);
220 } 233 }
221 234
235 public static bool operator==(StringShare ss1, StringShare ss2)
236 {
237 return ((string)ss1) == ((string)ss2);
238 }
239
240 public static bool operator==(StringShare ss, string s)
241 {
242 return ((string)ss) == s;
243 }
244
245 public static bool operator==(string s, StringShare ss)
246 {
247 return ss == s;
248 }
249
250 public static bool operator!=(StringShare ss1, StringShare ss2)
251 {
252 return !(ss1 == ss2);
253 }
254
255 public static bool operator!=(StringShare ss, string s)
256 {
257 return !(ss == s);
258 }
259
260 public static bool operator!=(string s, StringShare ss)
261 {
262 return !(ss == s);
263 }
264
222 public override string ToString() 265 public override string ToString()
223 { 266 {
224 return Str; 267 return Str;
225 } 268 }
226 269
270 public override int GetHashCode()
271 {
272 return Str == null ? 0 : Str.GetHashCode();
273 }
274
275 public override bool Equals(object other)
276 {
277 if (ReferenceEquals(null, other))
278 {
279 return false;
280 }
281
282 if (ReferenceEquals(this, other))
283 {
284 return true;
285 }
286
287 if (other.GetType() == typeof(string))
288 {
289 return this.Str == (string)other;
290 }
291
292 return other.GetType() == typeof(StringShare) && this == ((StringShare)other);
293 }
294
295 public bool Equals(StringShare other)
296 {
297 return this == other;
298 }
299
300 public bool Equals(string other)
301 {
302 return this.Str == other;
303 }
304
227 public void Set(string s) 305 public void Set(string s)
228 { 306 {
229 Str = s; 307 Str = s;
diff --git a/src/tests/efl_mono/Eina.cs b/src/tests/efl_mono/Eina.cs
index 1705c7ab83..dcd4d8b86e 100644
--- a/src/tests/efl_mono/Eina.cs
+++ b/src/tests/efl_mono/Eina.cs
@@ -492,6 +492,14 @@ class TestEinaArray
492 Test.AssertEquals("test string §éΨبÿツ", a[0]); 492 Test.AssertEquals("test string §éΨبÿツ", a[0]);
493 } 493 }
494 494
495 public static void push_stringshare()
496 {
497 var a = new Eina.Array<Eina.StringShare>();
498 Test.Assert(a.Handle != IntPtr.Zero);
499 Test.Assert(a.Push("test string §éΨبÿツ"));
500 Test.AssertEquals("test string §éΨبÿツ", a[0].Str);
501 }
502
495 public static void push_obj() 503 public static void push_obj()
496 { 504 {
497 var a = new Eina.Array<Dummy.Numberwrapper>(); 505 var a = new Eina.Array<Dummy.Numberwrapper>();
@@ -521,6 +529,15 @@ class TestEinaArray
521 Test.Assert(a.Count() == 0); 529 Test.Assert(a.Count() == 0);
522 } 530 }
523 531
532 public static void pop_stringshare()
533 {
534 var a = new Eina.Array<Eina.StringShare>();
535 Test.Assert(a.Handle != IntPtr.Zero);
536 Test.Assert(a.Push("test string"));
537 Test.Assert(a.Pop() == "test string");
538 Test.Assert(a.Count() == 0);
539 }
540
524 public static void pop_obj() 541 public static void pop_obj()
525 { 542 {
526 var a = new Eina.Array<Dummy.Numberwrapper>(); 543 var a = new Eina.Array<Dummy.Numberwrapper>();
@@ -558,6 +575,18 @@ class TestEinaArray
558 Test.Assert(a[0] == "abc"); 575 Test.Assert(a[0] == "abc");
559 } 576 }
560 577
578 public static void data_set_stringshare()
579 {
580 var a = new Eina.Array<Eina.StringShare>();
581 Test.Assert(a.Handle != IntPtr.Zero);
582 Test.Assert(a.Push("test string"));
583 Test.Assert(a[0] == "test string");
584 a.DataSet(0, "other string");
585 Test.Assert(a[0] == "other string");
586 a[0] = "abc";
587 Test.Assert(a[0] == "abc");
588 }
589
561 public static void data_set_obj() 590 public static void data_set_obj()
562 { 591 {
563 var a = new Eina.Array<Dummy.Numberwrapper>(); 592 var a = new Eina.Array<Dummy.Numberwrapper>();
@@ -617,6 +646,22 @@ class TestEinaArray
617 Test.Assert(a.Count() == 3); 646 Test.Assert(a.Count() == 3);
618 } 647 }
619 648
649 public static void count_stringshare()
650 {
651 var a = new Eina.Array<Eina.StringShare>();
652 Test.Assert(a.Handle != IntPtr.Zero);
653 Test.Assert(a.Count() == 0);
654 Test.Assert(a.Push("a"));
655 Test.Assert(a[0] == "a");
656 Test.Assert(a.Count() == 1);
657 Test.Assert(a.Push("b"));
658 Test.Assert(a[1] == "b");
659 Test.Assert(a.Count() == 2);
660 Test.Assert(a.Push("c"));
661 Test.Assert(a[2] == "c");
662 Test.Assert(a.Count() == 3);
663 }
664
620 public static void count_obj() 665 public static void count_obj()
621 { 666 {
622 var a = new Eina.Array<Dummy.Numberwrapper>(); 667 var a = new Eina.Array<Dummy.Numberwrapper>();
@@ -678,6 +723,22 @@ class TestEinaArray
678 Test.Assert(a.Length == 3); 723 Test.Assert(a.Length == 3);
679 } 724 }
680 725
726 public static void length_stringshare()
727 {
728 var a = new Eina.Array<Eina.Stringshare>();
729 Test.Assert(a.Handle != IntPtr.Zero);
730 Test.Assert(a.Length == 0);
731 Test.Assert(a.Push("a"));
732 Test.Assert(a[0] == "a");
733 Test.Assert(a.Length == 1);
734 Test.Assert(a.Push("b"));
735 Test.Assert(a[1] == "b");
736 Test.Assert(a.Length == 2);
737 Test.Assert(a.Push("c"));
738 Test.Assert(a[2] == "c");
739 Test.Assert(a.Length == 3);
740 }
741
681 public static void eina_array_as_ienumerable_int() 742 public static void eina_array_as_ienumerable_int()
682 { 743 {
683 var a = new Eina.Array<int>(); 744 var a = new Eina.Array<int>();
@@ -710,6 +771,22 @@ class TestEinaArray
710 } 771 }
711 } 772 }
712 773
774 public static void eina_array_as_ienumerable_stringshare()
775 {
776 var a = new Eina.Array<Eina.StringShare>();
777 Test.Assert(a.Handle != IntPtr.Zero);
778 Test.Assert(a.Push("X"));
779 Test.Assert(a.Push("XX"));
780 Test.Assert(a.Push("XXX"));
781
782 string cmp = "X";
783 foreach (string e in a)
784 {
785 Test.AssertEquals(cmp, e);
786 cmp = cmp + "X";
787 }
788 }
789
713 public static void eina_array_as_ienumerable_obj() 790 public static void eina_array_as_ienumerable_obj()
714 { 791 {
715 var a = new Dummy.Numberwrapper(); 792 var a = new Dummy.Numberwrapper();
@@ -888,6 +965,80 @@ class TestEinaArray
888 Test.Assert(arr.Handle == IntPtr.Zero); 965 Test.Assert(arr.Handle == IntPtr.Zero);
889 } 966 }
890 967
968 // Eina.Stringshare //
969 public static void test_eina_array_strshare_in()
970 {
971 var t = new Dummy.TestObject();
972 var arr = new Eina.Array<Eina.StringShare>();
973 arr.Append(base_seq_str);
974 Test.Assert(t.EinaArrayStrShareIn(arr));
975 Test.Assert(arr.Own);
976 Test.Assert(arr.ToArray().SequenceEqual(modified_seq_str));
977 arr.Dispose();
978 Test.Assert(arr.Handle == IntPtr.Zero);
979 }
980
981 public static void test_eina_array_strshare_in_own()
982 {
983 var t = new Dummy.TestObject();
984 var arr = new Eina.Array<Eina.StringShare>();
985 arr.Append(base_seq_str);
986 Test.Assert(t.EinaArrayStrShareInOwn(arr));
987 Test.Assert(!arr.Own);
988 Test.Assert(arr.ToArray().SequenceEqual(modified_seq_str));
989 arr.Dispose();
990 Test.Assert(arr.Handle == IntPtr.Zero);
991 Test.Assert(t.CheckEinaArrayStrShareInOwn());
992 }
993
994 public static void test_eina_array_strshare_out()
995 {
996 var t = new Dummy.TestObject();
997 Eina.Array<Eina.StringShare> arr;
998 Test.Assert(t.EinaArrayStrShareOut(out arr));
999 Test.Assert(!arr.Own);
1000 Test.Assert(arr.ToArray().SequenceEqual(base_seq_str));
1001 Test.Assert(arr.Append(append_seq_str));
1002 arr.Dispose();
1003 Test.Assert(arr.Handle == IntPtr.Zero);
1004 Test.Assert(t.CheckEinaArrayStrShareOut());
1005 }
1006
1007 public static void test_eina_array_strshare_out_own()
1008 {
1009 var t = new Dummy.TestObject();
1010 Eina.Array<Eina.StringShare> arr;
1011 Test.Assert(t.EinaArrayStrShareOutOwn(out arr));
1012 Test.Assert(arr.Own);
1013 Test.Assert(arr.ToArray().SequenceEqual(base_seq_str));
1014 Test.Assert(arr.Append(append_seq_str));
1015 arr.Dispose();
1016 Test.Assert(arr.Handle == IntPtr.Zero);
1017 }
1018
1019 public static void test_eina_array_strshare_return()
1020 {
1021 var t = new Dummy.TestObject();
1022 var arr = t.EinaArrayStrShareReturn();
1023 Test.Assert(!arr.Own);
1024 Test.Assert(arr.ToArray().SequenceEqual(base_seq_str));
1025 Test.Assert(arr.Append(append_seq_str));
1026 arr.Dispose();
1027 Test.Assert(arr.Handle == IntPtr.Zero);
1028 Test.Assert(t.CheckEinaArrayStrShareReturn());
1029 }
1030
1031 public static void test_eina_array_strshare_return_own()
1032 {
1033 var t = new Dummy.TestObject();
1034 var arr = t.EinaArrayStrShareReturnOwn();
1035 Test.Assert(arr.Own);
1036 Test.Assert(arr.ToArray().SequenceEqual(base_seq_str));
1037 Test.Assert(arr.Append(append_seq_str));
1038 arr.Dispose();
1039 Test.Assert(arr.Handle == IntPtr.Zero);
1040 }
1041
891 // Object // 1042 // Object //
892 1043
893 public static void test_eina_array_obj_in() 1044 public static void test_eina_array_obj_in()