diff options
author | Lauro Moura <lauromoura@expertisesolutions.com.br> | 2019-01-03 00:52:28 -0300 |
---|---|---|
committer | Lauro Moura <lauromoura@expertisesolutions.com.br> | 2019-01-03 18:39:33 -0300 |
commit | 93819494bad269b808ba1f18b125112edd2011f9 (patch) | |
tree | a37d68e9263d458ce1fcc8fb96a89770bc0b106a | |
parent | 22bca5aa9bc10f18256b592f2f8a602a578a6fc8 (diff) | |
download | efl-93819494bad269b808ba1f18b125112edd2011f9.tar.gz |
efl-mono: Share test data among other files.
Summary: Will make easier running/compiling tests in isolation.
Reviewers: segfaultxavi, felipealmeida
Subscribers: cedric, #reviewers, #committers
Tags: #efl
Differential Revision: https://phab.enlightenment.org/D7538
-rw-r--r-- | src/tests/efl_mono/Eina.cs | 277 | ||||
-rw-r--r-- | src/tests/efl_mono/EinaTestData.cs | 283 | ||||
-rw-r--r-- | src/tests/efl_mono/StructHelpers.cs | 235 | ||||
-rw-r--r-- | src/tests/efl_mono/Structs.cs | 223 | ||||
-rw-r--r-- | src/tests/efl_mono/meson.build | 2 |
5 files changed, 522 insertions, 498 deletions
diff --git a/src/tests/efl_mono/Eina.cs b/src/tests/efl_mono/Eina.cs index 119659b923..db42b23d7f 100644 --- a/src/tests/efl_mono/Eina.cs +++ b/src/tests/efl_mono/Eina.cs @@ -7,283 +7,6 @@ using System.Runtime.CompilerServices; using EinaTestData; using static EinaTestData.BaseData; -namespace EinaTestData -{ - -class BaseSequence -{ - public static byte[] Values() - { - return new byte[3]{0x0,0x2A,0x42}; - } -} - -public static class BaseData -{ - public static readonly int[] base_seq_int = {0x0,0x2A,0x42}; - public static readonly int[] append_seq_int = {42,43,33}; - public static readonly int[] modified_seq_int = {0x0,0x2A,0x42,42,43,33}; - - public static readonly string[] base_seq_str = {"0x0","0x2A","0x42"}; - public static readonly string[] append_seq_str = {"42","43","33"}; - public static readonly string[] modified_seq_str = {"0x0","0x2A","0x42","42","43","33"}; - - public static Dummy.Numberwrapper NW(int n) - { - var nw = new Dummy.Numberwrapper(); - nw.SetNumber(n); - return nw; - } - - public static Dummy.Numberwrapper[] BaseSeqObj() - { - var a = new Dummy.Numberwrapper(); - var b = new Dummy.Numberwrapper(); - var c = new Dummy.Numberwrapper(); - a.SetNumber(0x0); - b.SetNumber(0x2A); - c.SetNumber(0x42); - return new Dummy.Numberwrapper[]{a,b,c}; - } - - public static Dummy.Numberwrapper[] AppendSeqObj() - { - var a = new Dummy.Numberwrapper(); - var b = new Dummy.Numberwrapper(); - var c = new Dummy.Numberwrapper(); - a.SetNumber(42); - b.SetNumber(43); - c.SetNumber(33); - return new Dummy.Numberwrapper[]{a,b,c}; - } - - public static Dummy.Numberwrapper[] ModifiedSeqObj() - { - var a = new Dummy.Numberwrapper(); - var b = new Dummy.Numberwrapper(); - var c = new Dummy.Numberwrapper(); - var d = new Dummy.Numberwrapper(); - var e = new Dummy.Numberwrapper(); - var f = new Dummy.Numberwrapper(); - a.SetNumber(0x0); - b.SetNumber(0x2A); - c.SetNumber(0x42); - d.SetNumber(42); - e.SetNumber(43); - f.SetNumber(33); - return new Dummy.Numberwrapper[]{a,b,c,d,e,f}; - } - - public static void NumberwrapperSequenceAssertEqual( - Dummy.Numberwrapper[] a - , Dummy.Numberwrapper[] b - , [CallerLineNumber] int line = 0 - , [CallerFilePath] string file = null - , [CallerMemberName] string member = null) - { - Test.Assert(a.Length == b.Length, "Different lenght", line, file, member); - for (int i = 0; i < a.Length; ++i) - { - int av = a[i].GetNumber(); - int bv = b[i].GetNumber(); - Test.Assert(av == bv, $"Different values for element [{i}]: {av} == {bv}", line, file, member); - } - } -} - -class NativeInheritImpl : Dummy.TestObject -{ - public NativeInheritImpl(Efl.Object parent = null) : base(parent) {} - - public bool slice_in_flag = false; - public bool rw_slice_in_flag = false; - public bool slice_out_flag = false; - public bool rw_slice_out_flag = false; - public bool binbuf_in_flag = false; - public bool binbuf_in_own_flag = false; - public bool binbuf_out_flag = false; - public bool binbuf_out_own_flag = false; - public bool binbuf_return_flag = false; - public bool binbuf_return_own_flag = false; - - override public bool EinaSliceIn(Eina.Slice slice) - { - slice_in_flag = true; - return slice.GetBytes().SequenceEqual(BaseSequence.Values()); - } - - override public bool EinaRwSliceIn(Eina.RwSlice slice) - { - rw_slice_in_flag = true; - return slice.GetBytes().SequenceEqual(BaseSequence.Values()); - } - - private byte[] slice_out_seq = null; - private GCHandle slice_out_pinned; - override public bool EinaSliceOut(ref Eina.Slice slice) - { - slice_out_flag = true; - - slice_out_seq = (byte[]) BaseSequence.Values(); - slice_out_pinned = GCHandle.Alloc(slice_out_seq, GCHandleType.Pinned); - IntPtr ptr = slice_out_pinned.AddrOfPinnedObject(); - - slice.Mem = ptr; - slice.Len = (UIntPtr) slice_out_seq.Length; - - return true; - } - - private byte[] rw_slice_out_seq = null; - private GCHandle rw_slice_out_pinned; - override public bool EinaRwSliceOut(ref Eina.RwSlice slice) - { - rw_slice_out_flag = true; - - rw_slice_out_seq = (byte[]) BaseSequence.Values(); - rw_slice_out_pinned = GCHandle.Alloc(rw_slice_out_seq, GCHandleType.Pinned); - IntPtr ptr = rw_slice_out_pinned.AddrOfPinnedObject(); - - slice.Mem = ptr; - slice.Len = (UIntPtr) rw_slice_out_seq.Length; - - return true; - } - - // // - // - override public bool EinaBinbufIn(Eina.Binbuf binbuf) - { - binbuf_in_flag = true; - - bool r = binbuf.GetBytes().SequenceEqual(BaseSequence.Values()); - r = r && !binbuf.Own; - - binbuf.Insert(42, 0); - binbuf.Insert(43, 0); - binbuf.Append(33); - - binbuf.Dispose(); - - return r; - } - - private Eina.Binbuf binbuf_in_own_binbuf = null; - override public bool EinaBinbufInOwn(Eina.Binbuf binbuf) - { - binbuf_in_own_flag = true; - - bool r = binbuf.GetBytes().SequenceEqual(BaseSequence.Values()); - r = r && binbuf.Own; - - binbuf.Insert(42, 0); - binbuf.Insert(43, 0); - binbuf.Append(33); - - binbuf_in_own_binbuf = binbuf; - - return r; - } - public bool binbuf_in_own_still_usable() - { - bool r = binbuf_in_own_binbuf.GetBytes().SequenceEqual(new byte[]{43,42,0x0,0x2A,0x42,33}); - r = r && binbuf_in_own_binbuf.Own; - - binbuf_in_own_binbuf.Dispose(); - binbuf_in_own_binbuf = null; - - return r; - } - - private Eina.Binbuf binbuf_out_binbuf = null; - override public bool EinaBinbufOut(out Eina.Binbuf binbuf) - { - binbuf_out_flag = true; - - binbuf = new Eina.Binbuf(); - binbuf.Append(33); - - binbuf_out_binbuf = binbuf; - - return true; - } - public bool binbuf_out_still_usable() - { - bool r = binbuf_out_binbuf.GetBytes().SequenceEqual(BaseSequence.Values()); - r = r && binbuf_out_binbuf.Own; - - binbuf_out_binbuf.Dispose(); - binbuf_out_binbuf = null; - - return r; - } - - private Eina.Binbuf binbuf_out_own_binbuf = null; - override public bool EinaBinbufOutOwn(out Eina.Binbuf binbuf) - { - binbuf_out_own_flag = true; - - binbuf = new Eina.Binbuf(); - binbuf.Append(33); - - binbuf_out_own_binbuf = binbuf; - - return true; - } - public bool binbuf_out_own_no_longer_own() - { - bool r = !binbuf_out_own_binbuf.Own; - binbuf_out_own_binbuf.Dispose(); - binbuf_out_own_binbuf = null; - return r; - } - - private Eina.Binbuf binbuf_return_binbuf = null; - override public Eina.Binbuf EinaBinbufReturn() - { - binbuf_return_flag = true; - - var binbuf = new Eina.Binbuf(); - binbuf.Append(33); - - binbuf_return_binbuf = binbuf; - - return binbuf; - } - public bool binbuf_return_still_usable() - { - bool r = binbuf_return_binbuf.GetBytes().SequenceEqual(BaseSequence.Values()); - r = r && binbuf_return_binbuf.Own; - - binbuf_return_binbuf.Dispose(); - binbuf_return_binbuf = null; - - return r; - } - - private Eina.Binbuf binbuf_return_own_binbuf = null; - override public Eina.Binbuf EinaBinbufReturnOwn() - { - binbuf_return_own_flag = true; - - var binbuf = new Eina.Binbuf(); - binbuf.Append(33); - - binbuf_return_own_binbuf = binbuf; - - return binbuf; - } - public bool binbuf_return_own_no_longer_own() - { - bool r = !binbuf_return_own_binbuf.Own; - binbuf_return_own_binbuf.Dispose(); - binbuf_return_own_binbuf = null; - return r; - } -} - -} // EinaTestData - namespace TestSuite { diff --git a/src/tests/efl_mono/EinaTestData.cs b/src/tests/efl_mono/EinaTestData.cs new file mode 100644 index 0000000000..c4272a8ca2 --- /dev/null +++ b/src/tests/efl_mono/EinaTestData.cs @@ -0,0 +1,283 @@ +using System; +using System.Linq; +using System.Runtime.InteropServices; +using System.Runtime.CompilerServices; + +namespace EinaTestData +{ + +class BaseSequence +{ + public static byte[] Values() + { + return new byte[3]{0x0,0x2A,0x42}; + } +} + +public static class BaseData +{ + public static readonly int[] base_seq_int = {0x0,0x2A,0x42}; + public static readonly int[] append_seq_int = {42,43,33}; + public static readonly int[] modified_seq_int = {0x0,0x2A,0x42,42,43,33}; + + public static readonly string[] base_seq_str = {"0x0","0x2A","0x42"}; + public static readonly string[] append_seq_str = {"42","43","33"}; + public static readonly string[] modified_seq_str = {"0x0","0x2A","0x42","42","43","33"}; + + public static Dummy.Numberwrapper NW(int n) + { + var nw = new Dummy.Numberwrapper(); + nw.SetNumber(n); + return nw; + } + + public static Dummy.Numberwrapper[] BaseSeqObj() + { + var a = new Dummy.Numberwrapper(); + var b = new Dummy.Numberwrapper(); + var c = new Dummy.Numberwrapper(); + a.SetNumber(0x0); + b.SetNumber(0x2A); + c.SetNumber(0x42); + return new Dummy.Numberwrapper[]{a,b,c}; + } + + public static Dummy.Numberwrapper[] AppendSeqObj() + { + var a = new Dummy.Numberwrapper(); + var b = new Dummy.Numberwrapper(); + var c = new Dummy.Numberwrapper(); + a.SetNumber(42); + b.SetNumber(43); + c.SetNumber(33); + return new Dummy.Numberwrapper[]{a,b,c}; + } + + public static Dummy.Numberwrapper[] ModifiedSeqObj() + { + var a = new Dummy.Numberwrapper(); + var b = new Dummy.Numberwrapper(); + var c = new Dummy.Numberwrapper(); + var d = new Dummy.Numberwrapper(); + var e = new Dummy.Numberwrapper(); + var f = new Dummy.Numberwrapper(); + a.SetNumber(0x0); + b.SetNumber(0x2A); + c.SetNumber(0x42); + d.SetNumber(42); + e.SetNumber(43); + f.SetNumber(33); + return new Dummy.Numberwrapper[]{a,b,c,d,e,f}; + } + + public static void NumberwrapperSequenceAssertEqual( + Dummy.Numberwrapper[] a + , Dummy.Numberwrapper[] b + , [CallerLineNumber] int line = 0 + , [CallerFilePath] string file = null + , [CallerMemberName] string member = null) + { + Test.Assert(a.Length == b.Length, "Different lenght", line, file, member); + for (int i = 0; i < a.Length; ++i) + { + int av = a[i].GetNumber(); + int bv = b[i].GetNumber(); + Test.Assert(av == bv, $"Different values for element [{i}]: {av} == {bv}", line, file, member); + } + } +} + +class NativeInheritImpl : Dummy.TestObject +{ + public NativeInheritImpl(Efl.Object parent = null) : base(parent) {} + + public bool slice_in_flag = false; + public bool rw_slice_in_flag = false; + public bool slice_out_flag = false; + public bool rw_slice_out_flag = false; + public bool binbuf_in_flag = false; + public bool binbuf_in_own_flag = false; + public bool binbuf_out_flag = false; + public bool binbuf_out_own_flag = false; + public bool binbuf_return_flag = false; + public bool binbuf_return_own_flag = false; + + override public bool EinaSliceIn(Eina.Slice slice) + { + slice_in_flag = true; + return slice.GetBytes().SequenceEqual(BaseSequence.Values()); + } + + override public bool EinaRwSliceIn(Eina.RwSlice slice) + { + rw_slice_in_flag = true; + return slice.GetBytes().SequenceEqual(BaseSequence.Values()); + } + + private byte[] slice_out_seq = null; + private GCHandle slice_out_pinned; + override public bool EinaSliceOut(ref Eina.Slice slice) + { + slice_out_flag = true; + + slice_out_seq = (byte[]) BaseSequence.Values(); + slice_out_pinned = GCHandle.Alloc(slice_out_seq, GCHandleType.Pinned); + IntPtr ptr = slice_out_pinned.AddrOfPinnedObject(); + + slice.Mem = ptr; + slice.Len = (UIntPtr) slice_out_seq.Length; + + return true; + } + + private byte[] rw_slice_out_seq = null; + private GCHandle rw_slice_out_pinned; + override public bool EinaRwSliceOut(ref Eina.RwSlice slice) + { + rw_slice_out_flag = true; + + rw_slice_out_seq = (byte[]) BaseSequence.Values(); + rw_slice_out_pinned = GCHandle.Alloc(rw_slice_out_seq, GCHandleType.Pinned); + IntPtr ptr = rw_slice_out_pinned.AddrOfPinnedObject(); + + slice.Mem = ptr; + slice.Len = (UIntPtr) rw_slice_out_seq.Length; + + return true; + } + + // // + // + override public bool EinaBinbufIn(Eina.Binbuf binbuf) + { + binbuf_in_flag = true; + + bool r = binbuf.GetBytes().SequenceEqual(BaseSequence.Values()); + r = r && !binbuf.Own; + + binbuf.Insert(42, 0); + binbuf.Insert(43, 0); + binbuf.Append(33); + + binbuf.Dispose(); + + return r; + } + + private Eina.Binbuf binbuf_in_own_binbuf = null; + override public bool EinaBinbufInOwn(Eina.Binbuf binbuf) + { + binbuf_in_own_flag = true; + + bool r = binbuf.GetBytes().SequenceEqual(BaseSequence.Values()); + r = r && binbuf.Own; + + binbuf.Insert(42, 0); + binbuf.Insert(43, 0); + binbuf.Append(33); + + binbuf_in_own_binbuf = binbuf; + + return r; + } + public bool binbuf_in_own_still_usable() + { + bool r = binbuf_in_own_binbuf.GetBytes().SequenceEqual(new byte[]{43,42,0x0,0x2A,0x42,33}); + r = r && binbuf_in_own_binbuf.Own; + + binbuf_in_own_binbuf.Dispose(); + binbuf_in_own_binbuf = null; + + return r; + } + + private Eina.Binbuf binbuf_out_binbuf = null; + override public bool EinaBinbufOut(out Eina.Binbuf binbuf) + { + binbuf_out_flag = true; + + binbuf = new Eina.Binbuf(); + binbuf.Append(33); + + binbuf_out_binbuf = binbuf; + + return true; + } + public bool binbuf_out_still_usable() + { + bool r = binbuf_out_binbuf.GetBytes().SequenceEqual(BaseSequence.Values()); + r = r && binbuf_out_binbuf.Own; + + binbuf_out_binbuf.Dispose(); + binbuf_out_binbuf = null; + + return r; + } + + private Eina.Binbuf binbuf_out_own_binbuf = null; + override public bool EinaBinbufOutOwn(out Eina.Binbuf binbuf) + { + binbuf_out_own_flag = true; + + binbuf = new Eina.Binbuf(); + binbuf.Append(33); + + binbuf_out_own_binbuf = binbuf; + + return true; + } + public bool binbuf_out_own_no_longer_own() + { + bool r = !binbuf_out_own_binbuf.Own; + binbuf_out_own_binbuf.Dispose(); + binbuf_out_own_binbuf = null; + return r; + } + + private Eina.Binbuf binbuf_return_binbuf = null; + override public Eina.Binbuf EinaBinbufReturn() + { + binbuf_return_flag = true; + + var binbuf = new Eina.Binbuf(); + binbuf.Append(33); + + binbuf_return_binbuf = binbuf; + + return binbuf; + } + public bool binbuf_return_still_usable() + { + bool r = binbuf_return_binbuf.GetBytes().SequenceEqual(BaseSequence.Values()); + r = r && binbuf_return_binbuf.Own; + + binbuf_return_binbuf.Dispose(); + binbuf_return_binbuf = null; + + return r; + } + + private Eina.Binbuf binbuf_return_own_binbuf = null; + override public Eina.Binbuf EinaBinbufReturnOwn() + { + binbuf_return_own_flag = true; + + var binbuf = new Eina.Binbuf(); + binbuf.Append(33); + + binbuf_return_own_binbuf = binbuf; + + return binbuf; + } + public bool binbuf_return_own_no_longer_own() + { + bool r = !binbuf_return_own_binbuf.Own; + binbuf_return_own_binbuf.Dispose(); + binbuf_return_own_binbuf = null; + return r; + } +} + +} // EinaTestData + + diff --git a/src/tests/efl_mono/StructHelpers.cs b/src/tests/efl_mono/StructHelpers.cs new file mode 100644 index 0000000000..1b05a072fc --- /dev/null +++ b/src/tests/efl_mono/StructHelpers.cs @@ -0,0 +1,235 @@ +using System; +using System.Linq; +using System.Runtime.InteropServices; + +using static EinaTestData.BaseData; + +namespace TestSuite +{ + +internal class StructHelpers +{ + // Auxiliary function // + + internal static Dummy.StructSimple structSimpleWithValues() + { + var simple = new Dummy.StructSimple(); + + simple.Fbyte = (sbyte)-126; + simple.Fubyte = (byte) 254u; + simple.Fchar = '~'; + simple.Fshort = (short) -32766; + simple.Fushort = (ushort) 65534u; + simple.Fint = -32766; + simple.Fuint = 65534u; + simple.Flong = -2147483646; + simple.Fulong = 4294967294u; + simple.Fllong = -9223372036854775806; + simple.Fullong = 18446744073709551614u; + simple.Fint8 = (sbyte) -126; + simple.Fuint8 = (byte) 254u; + simple.Fint16 = (short) -32766; + simple.Fuint16 = (ushort) 65534u; + simple.Fint32 = -2147483646; + simple.Fuint32 = 4294967294u; + simple.Fint64 = -9223372036854775806; + simple.Fuint64 = 18446744073709551614u; + simple.Fssize = -2147483646; + simple.Fsize = 4294967294u; + simple.Fintptr = (IntPtr) 0xFE; + simple.Fptrdiff = -2147483646; + simple.Ffloat = -16777216.0f; + simple.Fdouble = -9007199254740992.0; + simple.Fbool = true; + simple.Fvoid_ptr = (IntPtr) 0xFE; + simple.Fenum = Dummy.SampleEnum.V2; + simple.Fstring = "test/string"; + simple.Fmstring = "test/mstring"; + simple.Fstringshare = "test/stringshare"; + + return simple; + } + + internal static void checkStructSimple(Dummy.StructSimple simple) + { + Test.Assert(simple.Fbyte == (sbyte) -126); + Test.Assert(simple.Fubyte == (byte) 254u); + Test.Assert(simple.Fchar == '~'); + Test.Assert(simple.Fshort == (short) -32766); + Test.Assert(simple.Fushort == (ushort) 65534u); + Test.Assert(simple.Fint == -32766); + Test.Assert(simple.Fuint == 65534u); + Test.Assert(simple.Flong == -2147483646); + Test.Assert(simple.Fulong == 4294967294u); + Test.Assert(simple.Fllong == -9223372036854775806); + Test.Assert(simple.Fullong == 18446744073709551614u); + Test.Assert(simple.Fint8 == (sbyte) -126); + Test.Assert(simple.Fuint8 == (byte) 254u); + Test.Assert(simple.Fint16 == (short) -32766); + Test.Assert(simple.Fuint16 == (ushort) 65534u); + Test.Assert(simple.Fint32 == -2147483646); + Test.Assert(simple.Fuint32 == 4294967294u); + Test.Assert(simple.Fint64 == -9223372036854775806); + Test.Assert(simple.Fuint64 == 18446744073709551614u); + Test.Assert(simple.Fssize == -2147483646); + Test.Assert(simple.Fsize == 4294967294u); + Test.Assert(simple.Fintptr == (IntPtr) 0xFE); + Test.Assert(simple.Fptrdiff == -2147483646); + Test.Assert(simple.Ffloat == -16777216.0f); + Test.Assert(simple.Fdouble == -9007199254740992.0); + Test.Assert(simple.Fbool == true); + Test.Assert(simple.Fvoid_ptr == (IntPtr) 0xFE); + Test.Assert(simple.Fenum == Dummy.SampleEnum.V2); + Test.Assert(simple.Fstring == "test/string"); + Test.Assert(simple.Fmstring == "test/mstring"); + Test.Assert(simple.Fstringshare == "test/stringshare"); + } + + internal static void checkZeroedStructSimple(Dummy.StructSimple simple) + { + Test.Assert(simple.Fbyte == 0); + Test.Assert(simple.Fubyte == 0); + Test.Assert(simple.Fchar == '\0'); + Test.Assert(simple.Fshort == 0); + Test.Assert(simple.Fushort == 0); + Test.Assert(simple.Fint == 0); + Test.Assert(simple.Fuint == 0); + Test.Assert(simple.Flong == 0); + Test.Assert(simple.Fulong == 0); + Test.Assert(simple.Fllong == 0); + Test.Assert(simple.Fullong == 0); + Test.Assert(simple.Fint8 == 0); + Test.Assert(simple.Fuint8 == 0); + Test.Assert(simple.Fint16 == 0); + Test.Assert(simple.Fuint16 == 0); + Test.Assert(simple.Fint32 == 0); + Test.Assert(simple.Fuint32 == 0); + Test.Assert(simple.Fint64 == 0); + Test.Assert(simple.Fuint64 == 0); + Test.Assert(simple.Fssize == 0); + Test.Assert(simple.Fsize == 0); + Test.Assert(simple.Fintptr == IntPtr.Zero); + Test.Assert(simple.Fptrdiff == 0); + Test.Assert(simple.Ffloat == 0); + Test.Assert(simple.Fdouble == 0); + Test.Assert(simple.Fbool == false); + Test.Assert(simple.Fvoid_ptr == IntPtr.Zero); + Test.Assert(simple.Fenum == Dummy.SampleEnum.V0); + Test.Assert(simple.Fstring == null); + Test.Assert(simple.Fmstring == null); + Test.Assert(simple.Fstringshare == null); + } + + internal static Dummy.StructComplex structComplexWithValues() + { + var complex = new Dummy.StructComplex(); + + complex.Farray = new Eina.Array<int>(); + complex.Farray.Push(0x0); + complex.Farray.Push(0x2A); + complex.Farray.Push(0x42); + + complex.Finarray = new Eina.Inarray<int>(); + complex.Finarray.Push(0x0); + complex.Finarray.Push(0x2A); + complex.Finarray.Push(0x42); + + + complex.Flist = new Eina.List<string>(); + complex.Flist.Append("0x0"); + complex.Flist.Append("0x2A"); + complex.Flist.Append("0x42"); + + complex.Finlist = new Eina.Inlist<int>(); + complex.Finlist.Append(0x0); + complex.Finlist.Append(0x2A); + complex.Finlist.Append(0x42); + + complex.Fhash = new Eina.Hash<string, string>(); + complex.Fhash["aa"] = "aaa"; + complex.Fhash["bb"] = "bbb"; + complex.Fhash["cc"] = "ccc"; + + complex.Fiterator = complex.Farray.GetIterator(); + + complex.Fany_value = new Eina.Value(Eina.ValueType.Double); + complex.Fany_value.Set(-9007199254740992.0); + + complex.Fany_value_ptr = new Eina.Value(Eina.ValueType.String); + complex.Fany_value_ptr.Set("abc"); + + complex.Fbinbuf = new Eina.Binbuf(); + complex.Fbinbuf.Append(126); + + complex.Fslice.Length = 1; + complex.Fslice.Mem = Eina.MemoryNative.Alloc(1); + Marshal.WriteByte(complex.Fslice.Mem, 125); + + complex.Fobj = new Dummy.Numberwrapper(); + complex.Fobj.SetNumber(42); + + return complex; + } + + internal static void checkStructComplex(Dummy.StructComplex complex) + { + Test.Assert(complex.Farray.ToArray().SequenceEqual(base_seq_int)); + + Test.Assert(complex.Finarray.ToArray().SequenceEqual(base_seq_int)); + + Test.Assert(complex.Flist.ToArray().SequenceEqual(base_seq_str)); + + Test.Assert(complex.Finlist.ToArray().SequenceEqual(base_seq_int)); + + Test.Assert(complex.Fhash["aa"] == "aaa"); + Test.Assert(complex.Fhash["bb"] == "bbb"); + Test.Assert(complex.Fhash["cc"] == "ccc"); + + int idx = 0; + foreach (int e in complex.Fiterator) + { + Test.Assert(e == base_seq_int[idx]); + ++idx; + } + + double double_val = 0; + Test.Assert(complex.Fany_value.Get(out double_val)); + Test.Assert(double_val == -9007199254740992.0); + + string str_val = null; + Test.Assert(complex.Fany_value_ptr.Get(out str_val)); + Test.Assert(str_val == "abc"); + + Test.Assert(complex.Fbinbuf.Length == 1); + Test.Assert(complex.Fbinbuf.GetBytes()[0] == 126); + + Test.Assert(complex.Fslice.Length == 1); + Test.Assert(complex.Fslice.GetBytes()[0] == 125); + + Test.Assert(complex.Fobj != null); + Test.Assert(complex.Fobj.GetNumber() == 42); + } + + + internal static void checkZeroedStructComplex(Dummy.StructComplex complex) + { + Test.Assert(complex.Farray == null); + Test.Assert(complex.Finarray == null); + Test.Assert(complex.Flist == null); + Test.Assert(complex.Finlist == null); + Test.Assert(complex.Fhash == null); + Test.Assert(complex.Fiterator == null); + Test.Assert(complex.Fany_value == null); + Test.Assert(complex.Fany_value_ptr == null); + Test.Assert(complex.Fbinbuf == null); + + Test.Assert(complex.Fslice.Length == 0); + Test.Assert(complex.Fslice.Mem == IntPtr.Zero); + + Test.Assert(complex.Fobj == null); + } + + +} + +} diff --git a/src/tests/efl_mono/Structs.cs b/src/tests/efl_mono/Structs.cs index d2bb464c85..71246b3198 100644 --- a/src/tests/efl_mono/Structs.cs +++ b/src/tests/efl_mono/Structs.cs @@ -3,232 +3,13 @@ using System.Runtime.InteropServices; using System.Linq; using static EinaTestData.BaseData; +using static TestSuite.StructHelpers; namespace TestSuite { -class TestStructs +internal class TestStructs { - // Auxiliary function // - - private static Dummy.StructSimple structSimpleWithValues() - { - var simple = new Dummy.StructSimple(); - - simple.Fbyte = (sbyte)-126; - simple.Fubyte = (byte) 254u; - simple.Fchar = '~'; - simple.Fshort = (short) -32766; - simple.Fushort = (ushort) 65534u; - simple.Fint = -32766; - simple.Fuint = 65534u; - simple.Flong = -2147483646; - simple.Fulong = 4294967294u; - simple.Fllong = -9223372036854775806; - simple.Fullong = 18446744073709551614u; - simple.Fint8 = (sbyte) -126; - simple.Fuint8 = (byte) 254u; - simple.Fint16 = (short) -32766; - simple.Fuint16 = (ushort) 65534u; - simple.Fint32 = -2147483646; - simple.Fuint32 = 4294967294u; - simple.Fint64 = -9223372036854775806; - simple.Fuint64 = 18446744073709551614u; - simple.Fssize = -2147483646; - simple.Fsize = 4294967294u; - simple.Fintptr = (IntPtr) 0xFE; - simple.Fptrdiff = -2147483646; - simple.Ffloat = -16777216.0f; - simple.Fdouble = -9007199254740992.0; - simple.Fbool = true; - simple.Fvoid_ptr = (IntPtr) 0xFE; - simple.Fenum = Dummy.SampleEnum.V2; - simple.Fstring = "test/string"; - simple.Fmstring = "test/mstring"; - simple.Fstringshare = "test/stringshare"; - - return simple; - } - - private static void checkStructSimple(Dummy.StructSimple simple) - { - Test.Assert(simple.Fbyte == (sbyte) -126); - Test.Assert(simple.Fubyte == (byte) 254u); - Test.Assert(simple.Fchar == '~'); - Test.Assert(simple.Fshort == (short) -32766); - Test.Assert(simple.Fushort == (ushort) 65534u); - Test.Assert(simple.Fint == -32766); - Test.Assert(simple.Fuint == 65534u); - Test.Assert(simple.Flong == -2147483646); - Test.Assert(simple.Fulong == 4294967294u); - Test.Assert(simple.Fllong == -9223372036854775806); - Test.Assert(simple.Fullong == 18446744073709551614u); - Test.Assert(simple.Fint8 == (sbyte) -126); - Test.Assert(simple.Fuint8 == (byte) 254u); - Test.Assert(simple.Fint16 == (short) -32766); - Test.Assert(simple.Fuint16 == (ushort) 65534u); - Test.Assert(simple.Fint32 == -2147483646); - Test.Assert(simple.Fuint32 == 4294967294u); - Test.Assert(simple.Fint64 == -9223372036854775806); - Test.Assert(simple.Fuint64 == 18446744073709551614u); - Test.Assert(simple.Fssize == -2147483646); - Test.Assert(simple.Fsize == 4294967294u); - Test.Assert(simple.Fintptr == (IntPtr) 0xFE); - Test.Assert(simple.Fptrdiff == -2147483646); - Test.Assert(simple.Ffloat == -16777216.0f); - Test.Assert(simple.Fdouble == -9007199254740992.0); - Test.Assert(simple.Fbool == true); - Test.Assert(simple.Fvoid_ptr == (IntPtr) 0xFE); - Test.Assert(simple.Fenum == Dummy.SampleEnum.V2); - Test.Assert(simple.Fstring == "test/string"); - Test.Assert(simple.Fmstring == "test/mstring"); - Test.Assert(simple.Fstringshare == "test/stringshare"); - } - - private static void checkZeroedStructSimple(Dummy.StructSimple simple) - { - Test.Assert(simple.Fbyte == 0); - Test.Assert(simple.Fubyte == 0); - Test.Assert(simple.Fchar == '\0'); - Test.Assert(simple.Fshort == 0); - Test.Assert(simple.Fushort == 0); - Test.Assert(simple.Fint == 0); - Test.Assert(simple.Fuint == 0); - Test.Assert(simple.Flong == 0); - Test.Assert(simple.Fulong == 0); - Test.Assert(simple.Fllong == 0); - Test.Assert(simple.Fullong == 0); - Test.Assert(simple.Fint8 == 0); - Test.Assert(simple.Fuint8 == 0); - Test.Assert(simple.Fint16 == 0); - Test.Assert(simple.Fuint16 == 0); - Test.Assert(simple.Fint32 == 0); - Test.Assert(simple.Fuint32 == 0); - Test.Assert(simple.Fint64 == 0); - Test.Assert(simple.Fuint64 == 0); - Test.Assert(simple.Fssize == 0); - Test.Assert(simple.Fsize == 0); - Test.Assert(simple.Fintptr == IntPtr.Zero); - Test.Assert(simple.Fptrdiff == 0); - Test.Assert(simple.Ffloat == 0); - Test.Assert(simple.Fdouble == 0); - Test.Assert(simple.Fbool == false); - Test.Assert(simple.Fvoid_ptr == IntPtr.Zero); - Test.Assert(simple.Fenum == Dummy.SampleEnum.V0); - Test.Assert(simple.Fstring == null); - Test.Assert(simple.Fmstring == null); - Test.Assert(simple.Fstringshare == null); - } - - private static Dummy.StructComplex structComplexWithValues() - { - var complex = new Dummy.StructComplex(); - - complex.Farray = new Eina.Array<int>(); - complex.Farray.Push(0x0); - complex.Farray.Push(0x2A); - complex.Farray.Push(0x42); - - complex.Finarray = new Eina.Inarray<int>(); - complex.Finarray.Push(0x0); - complex.Finarray.Push(0x2A); - complex.Finarray.Push(0x42); - - - complex.Flist = new Eina.List<string>(); - complex.Flist.Append("0x0"); - complex.Flist.Append("0x2A"); - complex.Flist.Append("0x42"); - - complex.Finlist = new Eina.Inlist<int>(); - complex.Finlist.Append(0x0); - complex.Finlist.Append(0x2A); - complex.Finlist.Append(0x42); - - complex.Fhash = new Eina.Hash<string, string>(); - complex.Fhash["aa"] = "aaa"; - complex.Fhash["bb"] = "bbb"; - complex.Fhash["cc"] = "ccc"; - - complex.Fiterator = complex.Farray.GetIterator(); - - complex.Fany_value = new Eina.Value(Eina.ValueType.Double); - complex.Fany_value.Set(-9007199254740992.0); - - complex.Fany_value_ptr = new Eina.Value(Eina.ValueType.String); - complex.Fany_value_ptr.Set("abc"); - - complex.Fbinbuf = new Eina.Binbuf(); - complex.Fbinbuf.Append(126); - - complex.Fslice.Length = 1; - complex.Fslice.Mem = Eina.MemoryNative.Alloc(1); - Marshal.WriteByte(complex.Fslice.Mem, 125); - - complex.Fobj = new Dummy.Numberwrapper(); - complex.Fobj.SetNumber(42); - - return complex; - } - - private static void checkStructComplex(Dummy.StructComplex complex) - { - Test.Assert(complex.Farray.ToArray().SequenceEqual(base_seq_int)); - - Test.Assert(complex.Finarray.ToArray().SequenceEqual(base_seq_int)); - - Test.Assert(complex.Flist.ToArray().SequenceEqual(base_seq_str)); - - Test.Assert(complex.Finlist.ToArray().SequenceEqual(base_seq_int)); - - Test.Assert(complex.Fhash["aa"] == "aaa"); - Test.Assert(complex.Fhash["bb"] == "bbb"); - Test.Assert(complex.Fhash["cc"] == "ccc"); - - int idx = 0; - foreach (int e in complex.Fiterator) - { - Test.Assert(e == base_seq_int[idx]); - ++idx; - } - - double double_val = 0; - Test.Assert(complex.Fany_value.Get(out double_val)); - Test.Assert(double_val == -9007199254740992.0); - - string str_val = null; - Test.Assert(complex.Fany_value_ptr.Get(out str_val)); - Test.Assert(str_val == "abc"); - - Test.Assert(complex.Fbinbuf.Length == 1); - Test.Assert(complex.Fbinbuf.GetBytes()[0] == 126); - - Test.Assert(complex.Fslice.Length == 1); - Test.Assert(complex.Fslice.GetBytes()[0] == 125); - - Test.Assert(complex.Fobj != null); - Test.Assert(complex.Fobj.GetNumber() == 42); - } - - - private static void checkZeroedStructComplex(Dummy.StructComplex complex) - { - Test.Assert(complex.Farray == null); - Test.Assert(complex.Finarray == null); - Test.Assert(complex.Flist == null); - Test.Assert(complex.Finlist == null); - Test.Assert(complex.Fhash == null); - Test.Assert(complex.Fiterator == null); - Test.Assert(complex.Fany_value == null); - Test.Assert(complex.Fany_value_ptr == null); - Test.Assert(complex.Fbinbuf == null); - - Test.Assert(complex.Fslice.Length == 0); - Test.Assert(complex.Fslice.Mem == IntPtr.Zero); - - Test.Assert(complex.Fobj == null); - } - // Test cases // // Default initialization (C# side) diff --git a/src/tests/efl_mono/meson.build b/src/tests/efl_mono/meson.build index f901152b54..25541996e1 100644 --- a/src/tests/efl_mono/meson.build +++ b/src/tests/efl_mono/meson.build @@ -39,6 +39,8 @@ efl_mono_test = library('efl_mono_test', efl_mono_src = [ 'Main.cs', 'TestUtils.cs', + 'EinaTestData.cs', + 'StructHelpers.cs', 'BasicDirection.cs', 'Eina.cs', 'Eldbus.cs', |