summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVitor Sousa <vitorsousasilva@gmail.com>2017-06-28 16:48:53 -0300
committerFelipe Magno de Almeida <felipe@expertisesolutions.com.br>2017-07-13 18:34:55 -0300
commitc7147ebf8dafe6efde45be641e31d47845de0244 (patch)
tree33e8261f11f86179a717f9476eea077086858967
parent4f7b463d5a8fdb02da61d5bb9c66a6531dac5d24 (diff)
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>
76 void NativeFreeInplace(IntPtr nat); 76 void NativeFreeInplace(IntPtr nat);
77 void ResidueFreeInplace(IntPtr nat); 77 void ResidueFreeInplace(IntPtr nat);
78 T NativeToManaged(IntPtr nat); 78 T NativeToManaged(IntPtr nat);
79 T NativeToManagedRef(IntPtr nat);
79 T NativeToManagedInlistNode(IntPtr nat); 80 T NativeToManagedInlistNode(IntPtr nat);
80 T NativeToManagedInplace(IntPtr nat); 81 T NativeToManagedInplace(IntPtr nat);
81 IntPtr EinaCompareCb(); 82 IntPtr EinaCompareCb();
@@ -165,6 +166,11 @@ public class StringElementTraits<T> : IBaseElementTraits<T>
165 return (T)(object)Marshal.PtrToStringAuto(nat); 166 return (T)(object)Marshal.PtrToStringAuto(nat);
166 } 167 }
167 168
169 public T NativeToManagedRef(IntPtr nat)
170 {
171 return NativeToManaged(nat);
172 }
173
168 public T NativeToManagedInlistNode(IntPtr nat) 174 public T NativeToManagedInlistNode(IntPtr nat)
169 { 175 {
170 if (nat == IntPtr.Zero) 176 if (nat == IntPtr.Zero)
@@ -293,6 +299,13 @@ public class EflObjectElementTraits<T> : IBaseElementTraits<T>
293 return (T) Activator.CreateInstance(concreteType, efl.eo.Globals.efl_ref(nat)); 299 return (T) Activator.CreateInstance(concreteType, efl.eo.Globals.efl_ref(nat));
294 } 300 }
295 301
302 public T NativeToManagedRef(IntPtr nat)
303 {
304 if (nat == IntPtr.Zero)
305 return default(T);
306 return NativeToManaged(intPtrTraits.NativeToManaged(nat));
307 }
308
296 public T NativeToManagedInlistNode(IntPtr nat) 309 public T NativeToManagedInlistNode(IntPtr nat)
297 { 310 {
298 if (nat == IntPtr.Zero) 311 if (nat == IntPtr.Zero)
@@ -397,6 +410,11 @@ public abstract class PrimitiveElementTraits<T>
397 return w.Val; 410 return w.Val;
398 } 411 }
399 412
413 public T NativeToManagedRef(IntPtr nat)
414 {
415 return NativeToManaged(nat);
416 }
417
400 public T NativeToManagedInlistNode(IntPtr nat) 418 public T NativeToManagedInlistNode(IntPtr nat)
401 { 419 {
402 if (nat == IntPtr.Zero) 420 if (nat == IntPtr.Zero)
@@ -626,6 +644,11 @@ public static class TraitFunctions
626 return GetTypeTraits<T>().NativeToManaged(nat); 644 return GetTypeTraits<T>().NativeToManaged(nat);
627 } 645 }
628 646
647 public static T NativeToManagedRef<T>(IntPtr nat)
648 {
649 return GetTypeTraits<T>().NativeToManagedRef(nat);
650 }
651
629 public static T NativeToManagedInlistNode<T>(IntPtr nat) 652 public static T NativeToManagedInlistNode<T>(IntPtr nat)
630 { 653 {
631 return GetTypeTraits<T>().NativeToManagedInlistNode(nat); 654 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
373 public IEnumerator<KeyValuePair<TKey, TValue>> GetEnumerator() 373 public IEnumerator<KeyValuePair<TKey, TValue>> GetEnumerator()
374 { 374 {
375 IntPtr itr = eina_hash_iterator_tuple_new(Handle); 375 IntPtr itr = eina_hash_iterator_tuple_new(Handle);
376 for (IntPtr tuplePtr; !eina_iterator_next(itr, out tuplePtr);) 376 for (IntPtr tuplePtr; eina_iterator_next(itr, out tuplePtr);)
377 { 377 {
378 var tuple = Marshal.PtrToStructure<eina.HashTupleNative>(tuplePtr); 378 var tuple = Marshal.PtrToStructure<eina.HashTupleNative>(tuplePtr);
379 var key = NativeToManaged<TKey>(tuple.key); 379 var key = NativeToManagedRef<TKey>(tuple.key);
380 var val = NativeToManaged<TValue>(tuple.data); 380 var val = NativeToManaged<TValue>(tuple.data);
381 yield return new KeyValuePair<TKey, TValue>(key, val); 381 yield return new KeyValuePair<TKey, TValue>(key, val);
382 } 382 }
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 @@
1using System; 1using System;
2using System.Collections.Generic;
2using System.Linq; 3using System.Linq;
3using System.Runtime.InteropServices; 4using System.Runtime.InteropServices;
4using System.Runtime.CompilerServices; 5using System.Runtime.CompilerServices;
@@ -2838,12 +2839,164 @@ class TestEinaHash
2838 public static void data_set_int() 2839 public static void data_set_int()
2839 { 2840 {
2840 var hsh = new eina.Hash<int, int>(); 2841 var hsh = new eina.Hash<int, int>();
2842 Test.Assert(hsh.Count == 0);
2843
2841 hsh[88] = 888; 2844 hsh[88] = 888;
2842 Test.Assert(hsh[88] == 888); 2845 Test.Assert(hsh[88] == 888);
2846 Test.Assert(hsh.Count == 1);
2847
2843 hsh[44] = 444; 2848 hsh[44] = 444;
2844 Test.Assert(hsh[44] == 444); 2849 Test.Assert(hsh[44] == 444);
2850 Test.Assert(hsh.Count == 2);
2851
2845 hsh[22] = 222; 2852 hsh[22] = 222;
2846 Test.Assert(hsh[22] == 222); 2853 Test.Assert(hsh[22] == 222);
2854 Test.Assert(hsh.Count == 3);
2855
2856 hsh.Dispose();
2857 }
2858
2859 public static void data_set_str()
2860 {
2861 var hsh = new eina.Hash<string, string>();
2862 Test.Assert(hsh.Count == 0);
2863
2864 hsh["aa"] = "aaa";
2865 Test.Assert(hsh["aa"] == "aaa");
2866 Test.Assert(hsh.Count == 1);
2867
2868 hsh["bb"] = "bbb";
2869 Test.Assert(hsh["bb"] == "bbb");
2870 Test.Assert(hsh.Count == 2);
2871
2872 hsh["cc"] = "ccc";
2873 Test.Assert(hsh["cc"] == "ccc");
2874 Test.Assert(hsh.Count == 3);
2875
2876 hsh.Dispose();
2877 }
2878
2879 public static void data_set_obj()
2880 {
2881 var hsh = new eina.Hash<test.Numberwrapper, test.Numberwrapper>();
2882 Test.Assert(hsh.Count == 0);
2883
2884 var a = NW(22);
2885 var aa = NW(222);
2886 var b = NW(44);
2887 var bb = NW(444);
2888 var c = NW(88);
2889 var cc = NW(888);
2890
2891 hsh[a] = aa;
2892 Test.Assert(hsh[a].raw_handle == aa.raw_handle);
2893 Test.Assert(hsh[a].number_get() == aa.number_get());
2894 Test.Assert(hsh.Count == 1);
2895
2896 hsh[b] = bb;
2897 Test.Assert(hsh[b].raw_handle == bb.raw_handle);
2898 Test.Assert(hsh[b].number_get() == bb.number_get());
2899 Test.Assert(hsh.Count == 2);
2900
2901 hsh[c] = cc;
2902 Test.Assert(hsh[c].raw_handle == cc.raw_handle);
2903 Test.Assert(hsh[c].number_get() == cc.number_get());
2904
2905 Test.Assert(hsh.Count == 3);
2906
2907 hsh.Dispose();
2908 }
2909
2910 public static void eina_hash_as_ienumerable_int()
2911 {
2912 var hsh = new eina.Hash<int, int>();
2913 var dct = new Dictionary<int, int>();
2914
2915 hsh[88] = 888;
2916 hsh[44] = 444;
2917 hsh[22] = 222;
2918
2919 dct[88] = 888;
2920 dct[44] = 444;
2921 dct[22] = 222;
2922
2923 int count = 0;
2924
2925 foreach (KeyValuePair<int, int> kvp in hsh)
2926 {
2927 Test.Assert(dct[kvp.Key] == kvp.Value);
2928 dct.Remove(kvp.Key);
2929 ++count;
2930 }
2931
2932 Test.AssertEquals(count, 3);
2933 Test.AssertEquals(dct.Count, 0);
2934
2935 hsh.Dispose();
2936 }
2937
2938 public static void eina_hash_as_ienumerable_str()
2939 {
2940 var hsh = new eina.Hash<string, string>();
2941 var dct = new Dictionary<string, string>();
2942
2943 hsh["aa"] = "aaa";
2944 hsh["bb"] = "bbb";
2945 hsh["cc"] = "ccc";
2946
2947 dct["aa"] = "aaa";
2948 dct["bb"] = "bbb";
2949 dct["cc"] = "ccc";
2950
2951 int count = 0;
2952
2953 foreach (KeyValuePair<string, string> kvp in hsh)
2954 {
2955 Test.Assert(dct[kvp.Key] == kvp.Value);
2956 dct.Remove(kvp.Key);
2957 ++count;
2958 }
2959
2960 Test.AssertEquals(count, 3);
2961 Test.AssertEquals(dct.Count, 0);
2962
2963 hsh.Dispose();
2964 }
2965
2966 public static void eina_hash_as_ienumerable_obj()
2967 {
2968 var hsh = new eina.Hash<test.Numberwrapper, test.Numberwrapper>();
2969 var dct = new Dictionary<int, test.Numberwrapper>();
2970
2971 var a = NW(22);
2972 var aa = NW(222);
2973 var b = NW(44);
2974 var bb = NW(444);
2975 var c = NW(88);
2976 var cc = NW(888);
2977
2978 hsh[a] = aa;
2979 hsh[b] = bb;
2980 hsh[c] = cc;
2981
2982 dct[a.number_get()] = aa;
2983 dct[b.number_get()] = bb;
2984 dct[c.number_get()] = cc;
2985
2986 int count = 0;
2987
2988 foreach (KeyValuePair<test.Numberwrapper, test.Numberwrapper> kvp in hsh)
2989 {
2990 Test.Assert(dct[kvp.Key.number_get()].raw_handle == kvp.Value.raw_handle);
2991 Test.Assert(dct[kvp.Key.number_get()].number_get() == kvp.Value.number_get());
2992 dct.Remove(kvp.Key.number_get());
2993 ++count;
2994 }
2995
2996 Test.AssertEquals(count, 3);
2997 Test.AssertEquals(dct.Count, 0);
2998
2999 hsh.Dispose();
2847 } 3000 }
2848 3001
2849 // // 3002 // //
@@ -3141,6 +3294,8 @@ class TestEinaHash
3141 3294
3142class TestEinaIterator 3295class TestEinaIterator
3143{ 3296{
3297 // Array //
3298
3144 public static void eina_array_int_empty_iterator() 3299 public static void eina_array_int_empty_iterator()
3145 { 3300 {
3146 var arr = new eina.Array<int>(); 3301 var arr = new eina.Array<int>();
@@ -3227,6 +3382,35 @@ class TestEinaIterator
3227 Test.Assert(entered); 3382 Test.Assert(entered);
3228 } 3383 }
3229 3384
3385 // Inarray
3386
3387 public static void eina_inarray_int_empty_iterator()
3388 {
3389 var arr = new eina.Inarray<int>();
3390 var itr = arr.GetIterator();
3391 bool entered = false;
3392 foreach (int e in itr)
3393 {
3394 entered = true;
3395 }
3396 Test.Assert(!entered);
3397 }
3398
3399 public static void eina_inarray_int_filled_iterator()
3400 {
3401 var arr = new eina.Inarray<int>();
3402 arr.Append(base_seq_int);
3403 var itr = arr.GetIterator();
3404 bool entered = false;
3405 var i = 0;
3406 foreach (int e in itr)
3407 {
3408 entered = true;
3409 Test.Assert(e == base_seq_int[i]);
3410 ++i;
3411 }
3412 Test.Assert(entered);
3413 }
3230 3414
3231// // // 3415// // //
3232// // Code Generation 3416// // Code Generation