summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVitor Sousa <vitorsousasilva@gmail.com>2017-06-28 16:48:53 -0300
committerVitor Sousa <vitorsousasilva@gmail.com>2017-06-28 16:48:53 -0300
commitfb531d34a98a272ee600cb4a91f3b0dde49e433a (patch)
treef631b71722c42b74fcb3f3365d0d5d857c2a20d0
parent16b0854780c84d8c353df212c9aed84a4223dfd0 (diff)
downloadefl-fb531d34a98a272ee600cb4a91f3b0dde49e433a.tar.gz
eina_mono: fix eina.Hash.GetEnumerator and add more tests
-rw-r--r--src/bindings/mono/eina_mono/eina_container_common.cs23
-rw-r--r--src/bindings/mono/eina_mono/eina_hash.cs4
-rw-r--r--src/tests/efl_mono/Eina.cs184
3 files changed, 209 insertions, 2 deletions
diff --git a/src/bindings/mono/eina_mono/eina_container_common.cs b/src/bindings/mono/eina_mono/eina_container_common.cs
index baaf3b920b..0f78d7adb0 100644
--- a/src/bindings/mono/eina_mono/eina_container_common.cs
+++ b/src/bindings/mono/eina_mono/eina_container_common.cs
@@ -76,6 +76,7 @@ public interface IBaseElementTraits<T>
void NativeFreeInplace(IntPtr nat);
void ResidueFreeInplace(IntPtr nat);
T NativeToManaged(IntPtr nat);
+ T NativeToManagedRef(IntPtr nat);
T NativeToManagedInlistNode(IntPtr nat);
T NativeToManagedInplace(IntPtr nat);
IntPtr EinaCompareCb();
@@ -165,6 +166,11 @@ public class StringElementTraits<T> : IBaseElementTraits<T>
return (T)(object)Marshal.PtrToStringAuto(nat);
}
+ public T NativeToManagedRef(IntPtr nat)
+ {
+ return NativeToManaged(nat);
+ }
+
public T NativeToManagedInlistNode(IntPtr nat)
{
if (nat == IntPtr.Zero)
@@ -293,6 +299,13 @@ public class EflObjectElementTraits<T> : IBaseElementTraits<T>
return (T) Activator.CreateInstance(concreteType, efl.eo.Globals.efl_ref(nat));
}
+ public T NativeToManagedRef(IntPtr nat)
+ {
+ if (nat == IntPtr.Zero)
+ return default(T);
+ return NativeToManaged(intPtrTraits.NativeToManaged(nat));
+ }
+
public T NativeToManagedInlistNode(IntPtr nat)
{
if (nat == IntPtr.Zero)
@@ -397,6 +410,11 @@ public abstract class PrimitiveElementTraits<T>
return w.Val;
}
+ public T NativeToManagedRef(IntPtr nat)
+ {
+ return NativeToManaged(nat);
+ }
+
public T NativeToManagedInlistNode(IntPtr nat)
{
if (nat == IntPtr.Zero)
@@ -626,6 +644,11 @@ public static class TraitFunctions
return GetTypeTraits<T>().NativeToManaged(nat);
}
+ public static T NativeToManagedRef<T>(IntPtr nat)
+ {
+ return GetTypeTraits<T>().NativeToManagedRef(nat);
+ }
+
public static T NativeToManagedInlistNode<T>(IntPtr nat)
{
return GetTypeTraits<T>().NativeToManagedInlistNode(nat);
diff --git a/src/bindings/mono/eina_mono/eina_hash.cs b/src/bindings/mono/eina_mono/eina_hash.cs
index 48b0d4e867..e63a89df24 100644
--- a/src/bindings/mono/eina_mono/eina_hash.cs
+++ b/src/bindings/mono/eina_mono/eina_hash.cs
@@ -373,10 +373,10 @@ public class Hash<TKey, TValue> : IEnumerable<KeyValuePair<TKey, TValue>>, IDi
public IEnumerator<KeyValuePair<TKey, TValue>> GetEnumerator()
{
IntPtr itr = eina_hash_iterator_tuple_new(Handle);
- for (IntPtr tuplePtr; !eina_iterator_next(itr, out tuplePtr);)
+ for (IntPtr tuplePtr; eina_iterator_next(itr, out tuplePtr);)
{
var tuple = Marshal.PtrToStructure<eina.HashTupleNative>(tuplePtr);
- var key = NativeToManaged<TKey>(tuple.key);
+ var key = NativeToManagedRef<TKey>(tuple.key);
var val = NativeToManaged<TValue>(tuple.data);
yield return new KeyValuePair<TKey, TValue>(key, val);
}
diff --git a/src/tests/efl_mono/Eina.cs b/src/tests/efl_mono/Eina.cs
index 46bc65be56..2a0b972f56 100644
--- a/src/tests/efl_mono/Eina.cs
+++ b/src/tests/efl_mono/Eina.cs
@@ -1,4 +1,5 @@
using System;
+using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;
@@ -2838,12 +2839,164 @@ class TestEinaHash
public static void data_set_int()
{
var hsh = new eina.Hash<int, int>();
+ Test.Assert(hsh.Count == 0);
+
hsh[88] = 888;
Test.Assert(hsh[88] == 888);
+ Test.Assert(hsh.Count == 1);
+
hsh[44] = 444;
Test.Assert(hsh[44] == 444);
+ Test.Assert(hsh.Count == 2);
+
hsh[22] = 222;
Test.Assert(hsh[22] == 222);
+ Test.Assert(hsh.Count == 3);
+
+ hsh.Dispose();
+ }
+
+ public static void data_set_str()
+ {
+ var hsh = new eina.Hash<string, string>();
+ Test.Assert(hsh.Count == 0);
+
+ hsh["aa"] = "aaa";
+ Test.Assert(hsh["aa"] == "aaa");
+ Test.Assert(hsh.Count == 1);
+
+ hsh["bb"] = "bbb";
+ Test.Assert(hsh["bb"] == "bbb");
+ Test.Assert(hsh.Count == 2);
+
+ hsh["cc"] = "ccc";
+ Test.Assert(hsh["cc"] == "ccc");
+ Test.Assert(hsh.Count == 3);
+
+ hsh.Dispose();
+ }
+
+ public static void data_set_obj()
+ {
+ var hsh = new eina.Hash<test.Numberwrapper, test.Numberwrapper>();
+ Test.Assert(hsh.Count == 0);
+
+ var a = NW(22);
+ var aa = NW(222);
+ var b = NW(44);
+ var bb = NW(444);
+ var c = NW(88);
+ var cc = NW(888);
+
+ hsh[a] = aa;
+ Test.Assert(hsh[a].raw_handle == aa.raw_handle);
+ Test.Assert(hsh[a].number_get() == aa.number_get());
+ Test.Assert(hsh.Count == 1);
+
+ hsh[b] = bb;
+ Test.Assert(hsh[b].raw_handle == bb.raw_handle);
+ Test.Assert(hsh[b].number_get() == bb.number_get());
+ Test.Assert(hsh.Count == 2);
+
+ hsh[c] = cc;
+ Test.Assert(hsh[c].raw_handle == cc.raw_handle);
+ Test.Assert(hsh[c].number_get() == cc.number_get());
+
+ Test.Assert(hsh.Count == 3);
+
+ hsh.Dispose();
+ }
+
+ public static void eina_hash_as_ienumerable_int()
+ {
+ var hsh = new eina.Hash<int, int>();
+ var dct = new Dictionary<int, int>();
+
+ hsh[88] = 888;
+ hsh[44] = 444;
+ hsh[22] = 222;
+
+ dct[88] = 888;
+ dct[44] = 444;
+ dct[22] = 222;
+
+ int count = 0;
+
+ foreach (KeyValuePair<int, int> kvp in hsh)
+ {
+ Test.Assert(dct[kvp.Key] == kvp.Value);
+ dct.Remove(kvp.Key);
+ ++count;
+ }
+
+ Test.AssertEquals(count, 3);
+ Test.AssertEquals(dct.Count, 0);
+
+ hsh.Dispose();
+ }
+
+ public static void eina_hash_as_ienumerable_str()
+ {
+ var hsh = new eina.Hash<string, string>();
+ var dct = new Dictionary<string, string>();
+
+ hsh["aa"] = "aaa";
+ hsh["bb"] = "bbb";
+ hsh["cc"] = "ccc";
+
+ dct["aa"] = "aaa";
+ dct["bb"] = "bbb";
+ dct["cc"] = "ccc";
+
+ int count = 0;
+
+ foreach (KeyValuePair<string, string> kvp in hsh)
+ {
+ Test.Assert(dct[kvp.Key] == kvp.Value);
+ dct.Remove(kvp.Key);
+ ++count;
+ }
+
+ Test.AssertEquals(count, 3);
+ Test.AssertEquals(dct.Count, 0);
+
+ hsh.Dispose();
+ }
+
+ public static void eina_hash_as_ienumerable_obj()
+ {
+ var hsh = new eina.Hash<test.Numberwrapper, test.Numberwrapper>();
+ var dct = new Dictionary<int, test.Numberwrapper>();
+
+ var a = NW(22);
+ var aa = NW(222);
+ var b = NW(44);
+ var bb = NW(444);
+ var c = NW(88);
+ var cc = NW(888);
+
+ hsh[a] = aa;
+ hsh[b] = bb;
+ hsh[c] = cc;
+
+ dct[a.number_get()] = aa;
+ dct[b.number_get()] = bb;
+ dct[c.number_get()] = cc;
+
+ int count = 0;
+
+ foreach (KeyValuePair<test.Numberwrapper, test.Numberwrapper> kvp in hsh)
+ {
+ Test.Assert(dct[kvp.Key.number_get()].raw_handle == kvp.Value.raw_handle);
+ Test.Assert(dct[kvp.Key.number_get()].number_get() == kvp.Value.number_get());
+ dct.Remove(kvp.Key.number_get());
+ ++count;
+ }
+
+ Test.AssertEquals(count, 3);
+ Test.AssertEquals(dct.Count, 0);
+
+ hsh.Dispose();
}
// //
@@ -3141,6 +3294,8 @@ class TestEinaHash
class TestEinaIterator
{
+ // Array //
+
public static void eina_array_int_empty_iterator()
{
var arr = new eina.Array<int>();
@@ -3227,6 +3382,35 @@ class TestEinaIterator
Test.Assert(entered);
}
+ // Inarray
+
+ public static void eina_inarray_int_empty_iterator()
+ {
+ var arr = new eina.Inarray<int>();
+ var itr = arr.GetIterator();
+ bool entered = false;
+ foreach (int e in itr)
+ {
+ entered = true;
+ }
+ Test.Assert(!entered);
+ }
+
+ public static void eina_inarray_int_filled_iterator()
+ {
+ var arr = new eina.Inarray<int>();
+ arr.Append(base_seq_int);
+ var itr = arr.GetIterator();
+ bool entered = false;
+ var i = 0;
+ foreach (int e in itr)
+ {
+ entered = true;
+ Test.Assert(e == base_seq_int[i]);
+ ++i;
+ }
+ Test.Assert(entered);
+ }
// // //
// // Code Generation