aboutsummaryrefslogtreecommitdiffstats
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
parentDON'T LAND csharp: fix stringshare usage in eina containers (diff)
downloadefl-devs/vitorsousa/csharp_stringshare_containers.tar.gz
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
Unmanaged
}
-public class StringShare
+/// TODO: reword this \/ \/ \/ \/ \/ \/ \/
+/// Convert to a String the quickest possible.
+/// 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.
+public class StringShare : IEquatable<StringShare>, IEquatable<string>
{
public StringShare()
{
@@ -211,19 +214,94 @@ public class StringShare
public static implicit operator string(StringShare ss)
{
+ if (ss == null)
+ {
+ return null;
+ }
+
return ss.Str;
}
public static implicit operator StringShare(string s)
{
+ if (s == null)
+ {
+ return null;
+ }
+
return new StringShare(s);
}
+ public static bool operator==(StringShare ss1, StringShare ss2)
+ {
+ return ((string)ss1) == ((string)ss2);
+ }
+
+ public static bool operator==(StringShare ss, string s)
+ {
+ return ((string)ss) == s;
+ }
+
+ public static bool operator==(string s, StringShare ss)
+ {
+ return ss == s;
+ }
+
+ public static bool operator!=(StringShare ss1, StringShare ss2)
+ {
+ return !(ss1 == ss2);
+ }
+
+ public static bool operator!=(StringShare ss, string s)
+ {
+ return !(ss == s);
+ }
+
+ public static bool operator!=(string s, StringShare ss)
+ {
+ return !(ss == s);
+ }
+
public override string ToString()
{
return Str;
}
+ public override int GetHashCode()
+ {
+ return Str == null ? 0 : Str.GetHashCode();
+ }
+
+ public override bool Equals(object other)
+ {
+ if (ReferenceEquals(null, other))
+ {
+ return false;
+ }
+
+ if (ReferenceEquals(this, other))
+ {
+ return true;
+ }
+
+ if (other.GetType() == typeof(string))
+ {
+ return this.Str == (string)other;
+ }
+
+ return other.GetType() == typeof(StringShare) && this == ((StringShare)other);
+ }
+
+ public bool Equals(StringShare other)
+ {
+ return this == other;
+ }
+
+ public bool Equals(string other)
+ {
+ return this.Str == other;
+ }
+
public void Set(string s)
{
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
Test.AssertEquals("test string §éΨبÿツ", a[0]);
}
+ public static void push_stringshare()
+ {
+ var a = new Eina.Array<Eina.StringShare>();
+ Test.Assert(a.Handle != IntPtr.Zero);
+ Test.Assert(a.Push("test string §éΨبÿツ"));
+ Test.AssertEquals("test string §éΨبÿツ", a[0].Str);
+ }
+
public static void push_obj()
{
var a = new Eina.Array<Dummy.Numberwrapper>();
@@ -521,6 +529,15 @@ class TestEinaArray
Test.Assert(a.Count() == 0);
}
+ public static void pop_stringshare()
+ {
+ var a = new Eina.Array<Eina.StringShare>();
+ Test.Assert(a.Handle != IntPtr.Zero);
+ Test.Assert(a.Push("test string"));
+ Test.Assert(a.Pop() == "test string");
+ Test.Assert(a.Count() == 0);
+ }
+
public static void pop_obj()
{
var a = new Eina.Array<Dummy.Numberwrapper>();
@@ -558,6 +575,18 @@ class TestEinaArray
Test.Assert(a[0] == "abc");
}
+ public static void data_set_stringshare()
+ {
+ var a = new Eina.Array<Eina.StringShare>();
+ Test.Assert(a.Handle != IntPtr.Zero);
+ Test.Assert(a.Push("test string"));
+ Test.Assert(a[0] == "test string");
+ a.DataSet(0, "other string");
+ Test.Assert(a[0] == "other string");
+ a[0] = "abc";
+ Test.Assert(a[0] == "abc");
+ }
+
public static void data_set_obj()
{
var a = new Eina.Array<Dummy.Numberwrapper>();
@@ -617,6 +646,22 @@ class TestEinaArray
Test.Assert(a.Count() == 3);
}
+ public static void count_stringshare()
+ {
+ var a = new Eina.Array<Eina.StringShare>();
+ Test.Assert(a.Handle != IntPtr.Zero);
+ Test.Assert(a.Count() == 0);
+ Test.Assert(a.Push("a"));
+ Test.Assert(a[0] == "a");
+ Test.Assert(a.Count() == 1);
+ Test.Assert(a.Push("b"));
+ Test.Assert(a[1] == "b");
+ Test.Assert(a.Count() == 2);
+ Test.Assert(a.Push("c"));
+ Test.Assert(a[2] == "c");
+ Test.Assert(a.Count() == 3);
+ }
+
public static void count_obj()
{
var a = new Eina.Array<Dummy.Numberwrapper>();
@@ -678,6 +723,22 @@ class TestEinaArray
Test.Assert(a.Length == 3);
}
+ public static void length_stringshare()
+ {
+ var a = new Eina.Array<Eina.Stringshare>();
+ Test.Assert(a.Handle != IntPtr.Zero);
+ Test.Assert(a.Length == 0);
+ Test.Assert(a.Push("a"));
+ Test.Assert(a[0] == "a");
+ Test.Assert(a.Length == 1);
+ Test.Assert(a.Push("b"));
+ Test.Assert(a[1] == "b");
+ Test.Assert(a.Length == 2);
+ Test.Assert(a.Push("c"));
+ Test.Assert(a[2] == "c");
+ Test.Assert(a.Length == 3);
+ }
+
public static void eina_array_as_ienumerable_int()
{
var a = new Eina.Array<int>();
@@ -710,6 +771,22 @@ class TestEinaArray
}
}
+ public static void eina_array_as_ienumerable_stringshare()
+ {
+ var a = new Eina.Array<Eina.StringShare>();
+ Test.Assert(a.Handle != IntPtr.Zero);
+ Test.Assert(a.Push("X"));
+ Test.Assert(a.Push("XX"));
+ Test.Assert(a.Push("XXX"));
+
+ string cmp = "X";
+ foreach (string e in a)
+ {
+ Test.AssertEquals(cmp, e);
+ cmp = cmp + "X";
+ }
+ }
+
public static void eina_array_as_ienumerable_obj()
{
var a = new Dummy.Numberwrapper();
@@ -888,6 +965,80 @@ class TestEinaArray
Test.Assert(arr.Handle == IntPtr.Zero);
}
+ // Eina.Stringshare //
+ public static void test_eina_array_strshare_in()
+ {
+ var t = new Dummy.TestObject();
+ var arr = new Eina.Array<Eina.StringShare>();
+ arr.Append(base_seq_str);
+ Test.Assert(t.EinaArrayStrShareIn(arr));
+ Test.Assert(arr.Own);
+ Test.Assert(arr.ToArray().SequenceEqual(modified_seq_str));
+ arr.Dispose();
+ Test.Assert(arr.Handle == IntPtr.Zero);
+ }
+
+ public static void test_eina_array_strshare_in_own()
+ {
+ var t = new Dummy.TestObject();
+ var arr = new Eina.Array<Eina.StringShare>();
+ arr.Append(base_seq_str);
+ Test.Assert(t.EinaArrayStrShareInOwn(arr));
+ Test.Assert(!arr.Own);
+ Test.Assert(arr.ToArray().SequenceEqual(modified_seq_str));
+ arr.Dispose();
+ Test.Assert(arr.Handle == IntPtr.Zero);
+ Test.Assert(t.CheckEinaArrayStrShareInOwn());
+ }
+
+ public static void test_eina_array_strshare_out()
+ {
+ var t = new Dummy.TestObject();
+ Eina.Array<Eina.StringShare> arr;
+ Test.Assert(t.EinaArrayStrShareOut(out arr));
+ Test.Assert(!arr.Own);
+ Test.Assert(arr.ToArray().SequenceEqual(base_seq_str));
+ Test.Assert(arr.Append(append_seq_str));
+ arr.Dispose();
+ Test.Assert(arr.Handle == IntPtr.Zero);
+ Test.Assert(t.CheckEinaArrayStrShareOut());
+ }
+
+ public static void test_eina_array_strshare_out_own()
+ {
+ var t = new Dummy.TestObject();
+ Eina.Array<Eina.StringShare> arr;
+ Test.Assert(t.EinaArrayStrShareOutOwn(out arr));
+ Test.Assert(arr.Own);
+ Test.Assert(arr.ToArray().SequenceEqual(base_seq_str));
+ Test.Assert(arr.Append(append_seq_str));
+ arr.Dispose();
+ Test.Assert(arr.Handle == IntPtr.Zero);
+ }
+
+ public static void test_eina_array_strshare_return()
+ {
+ var t = new Dummy.TestObject();
+ var arr = t.EinaArrayStrShareReturn();
+ Test.Assert(!arr.Own);
+ Test.Assert(arr.ToArray().SequenceEqual(base_seq_str));
+ Test.Assert(arr.Append(append_seq_str));
+ arr.Dispose();
+ Test.Assert(arr.Handle == IntPtr.Zero);
+ Test.Assert(t.CheckEinaArrayStrShareReturn());
+ }
+
+ public static void test_eina_array_strshare_return_own()
+ {
+ var t = new Dummy.TestObject();
+ var arr = t.EinaArrayStrShareReturnOwn();
+ Test.Assert(arr.Own);
+ Test.Assert(arr.ToArray().SequenceEqual(base_seq_str));
+ Test.Assert(arr.Append(append_seq_str));
+ arr.Dispose();
+ Test.Assert(arr.Handle == IntPtr.Zero);
+ }
+
// Object //
public static void test_eina_array_obj_in()