forked from enlightenment/efl
c#: Implement IList to Eina.Array.
ref T8488 Reviewed-by: Felipe Magno de Almeida <felipe@expertisesolutions.com.br> Differential Revision: https://phab.enlightenment.org/D10785
This commit is contained in:
parent
c49880076c
commit
47407478e8
|
@ -209,7 +209,7 @@ public abstract class Application
|
|||
if (evt.arg.Initialization)
|
||||
{
|
||||
var evtArgv = evt.arg.Argv;
|
||||
int n = evtArgv.Length;
|
||||
int n = evtArgv.Count;
|
||||
var argv = new string[n];
|
||||
for (int i = 0; i < n; ++i)
|
||||
{
|
||||
|
|
|
@ -36,8 +36,9 @@ public static class ArrayNativeFunctions
|
|||
eina_array_free(IntPtr array);
|
||||
[DllImport(efl.Libs.Eina)] internal static extern void
|
||||
eina_array_flush(IntPtr array);
|
||||
public delegate bool KeepCb(IntPtr data, IntPtr gdata);
|
||||
[DllImport(efl.Libs.Eina)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool
|
||||
eina_array_remove(IntPtr array, IntPtr keep, IntPtr gdata);
|
||||
eina_array_remove(IntPtr array, KeepCb keep, IntPtr gdata);
|
||||
[DllImport(efl.Libs.Eina)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool
|
||||
eina_array_push(IntPtr array, IntPtr data);
|
||||
|
||||
|
@ -45,6 +46,10 @@ public static class ArrayNativeFunctions
|
|||
eina_array_iterator_new(IntPtr array);
|
||||
[DllImport(efl.Libs.Eina)] internal static extern IntPtr
|
||||
eina_array_accessor_new(IntPtr array);
|
||||
[DllImport(efl.Libs.Eina)] [return: MarshalAs(UnmanagedType.U1)]
|
||||
internal static extern bool
|
||||
eina_array_find(IntPtr array, IntPtr data,
|
||||
uint out_idx);
|
||||
|
||||
[DllImport(efl.Libs.CustomExports)] internal static extern void
|
||||
eina_array_clean_custom_export_mono(IntPtr array);
|
||||
|
@ -61,6 +66,8 @@ public static class ArrayNativeFunctions
|
|||
|
||||
[DllImport(efl.Libs.CustomExports)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool
|
||||
eina_array_foreach_custom_export_mono(IntPtr array, IntPtr cb, IntPtr fdata);
|
||||
[DllImport(efl.Libs.CustomExports)] internal static extern void
|
||||
eina_array_insert_at_custom_export_mono(IntPtr array, uint index, IntPtr data);
|
||||
}
|
||||
|
||||
/// <summary>A container of contiguous allocated elements.
|
||||
|
@ -68,30 +75,42 @@ public static class ArrayNativeFunctions
|
|||
/// </summary>
|
||||
[SuppressMessage("Microsoft.Naming", "CA1710:IdentifiersShouldHaveCorrectSuffix",
|
||||
Justification="This is a generalized container mapping the native one.")]
|
||||
public class Array<T> : IEnumerable<T>, IDisposable
|
||||
public class Array<T> : IList<T>, IEnumerable<T>, IDisposable
|
||||
{
|
||||
public const uint DefaultStep = 32;
|
||||
|
||||
/// <summary>Pointer to the native buffer.</summary>
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
public IntPtr Handle {get;set;} = IntPtr.Zero;
|
||||
public IntPtr Handle { get; set; } = IntPtr.Zero;
|
||||
|
||||
/// <summary>Whether this wrapper owns the native buffer.
|
||||
/// <para>Since EFL 1.23.</para>
|
||||
/// </summary>
|
||||
public bool Own {get;set;}
|
||||
internal bool Own { get; set; }
|
||||
|
||||
/// <summary>Who is in charge of releasing the resources wrapped by
|
||||
/// this instance.
|
||||
/// <para>Since EFL 1.23.</para>
|
||||
/// </summary>
|
||||
public bool OwnContent {get;set;}
|
||||
/// <summary> Length of the array.
|
||||
/// <para>Since EFL 1.23.</para>
|
||||
internal bool OwnContent { get; set; }
|
||||
|
||||
/// <summary> Gets the number of elements contained in the <see cref="Array{T}" />.
|
||||
/// <para>Since EFL 1.24.</para>
|
||||
/// </summary>
|
||||
public int Length
|
||||
public int Count
|
||||
{
|
||||
get { return Count(); }
|
||||
get => (int)eina_array_count_custom_export_mono(Handle);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the <see cref="Array" /> is read-only.
|
||||
/// <para>Since EFL 1.24.</para>
|
||||
///<para>
|
||||
/// It's the negative of <see cref="OwnContent" />.
|
||||
///</para>
|
||||
/// </summary>
|
||||
public bool IsReadOnly { get => !OwnContent; }
|
||||
|
||||
private void InitNew(uint step)
|
||||
{
|
||||
Handle = eina_array_new(step);
|
||||
|
@ -104,23 +123,62 @@ public class Array<T> : IEnumerable<T>, IDisposable
|
|||
}
|
||||
|
||||
internal bool InternalPush(IntPtr ele)
|
||||
{
|
||||
return eina_array_push_custom_export_mono(Handle, ele);
|
||||
}
|
||||
=> eina_array_push_custom_export_mono(Handle, ele);
|
||||
|
||||
internal IntPtr InternalPop()
|
||||
{
|
||||
return eina_array_pop_custom_export_mono(Handle);
|
||||
}
|
||||
=> eina_array_pop_custom_export_mono(Handle);
|
||||
|
||||
internal IntPtr InternalDataGet(int idx)
|
||||
{
|
||||
return eina_array_data_get_custom_export_mono(Handle, (uint)idx); // TODO: Check bounds ???
|
||||
}
|
||||
=> eina_array_data_get_custom_export_mono(Handle, CheckBounds(idx));
|
||||
|
||||
internal void InternalDataSet(int idx, IntPtr ele)
|
||||
=> eina_array_data_set_custom_export_mono(Handle, CheckBounds(idx), ele);
|
||||
|
||||
private uint CheckBounds(int idx)
|
||||
{
|
||||
eina_array_data_set_custom_export_mono(Handle, (uint)idx, ele); // TODO: Check bounds ???
|
||||
if (!(0 <= idx && idx < Count))
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(idx), $"{nameof(idx)} is out of bounds.");
|
||||
}
|
||||
|
||||
return (uint)idx;
|
||||
}
|
||||
|
||||
private U LoopingThrough<U>(T val, Func<int, U> f1, Func<U> f2)
|
||||
{
|
||||
for (int i = 0, count = Count; i < count; ++i)
|
||||
{
|
||||
if (NativeToManaged<T>(InternalDataGet(i)).Equals(val))
|
||||
{
|
||||
return f1(i);
|
||||
}
|
||||
}
|
||||
|
||||
return f2();
|
||||
}
|
||||
|
||||
private void CheckOwnerships()
|
||||
{
|
||||
if ((Own == false) && (OwnContent == true))
|
||||
{
|
||||
throw new InvalidOperationException(nameof(Own) + "/" + nameof(OwnContent));
|
||||
}
|
||||
}
|
||||
|
||||
private void RequireWritable()
|
||||
{
|
||||
if (IsReadOnly)
|
||||
{
|
||||
throw new NotSupportedException("This object's instance is read only.");
|
||||
}
|
||||
}
|
||||
|
||||
private void DeleteData(IntPtr ele)
|
||||
{
|
||||
if (OwnContent)
|
||||
{
|
||||
NativeFree<T>(ele);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -156,6 +214,7 @@ public class Array<T> : IEnumerable<T>, IDisposable
|
|||
$"{nameof(Handle)} can't be null");
|
||||
Own = own;
|
||||
OwnContent = own;
|
||||
CheckOwnerships();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -173,6 +232,7 @@ public class Array<T> : IEnumerable<T>, IDisposable
|
|||
$"{nameof(Handle)} can't be null");
|
||||
Own = own;
|
||||
OwnContent = ownContent;
|
||||
CheckOwnerships();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -197,15 +257,17 @@ public class Array<T> : IEnumerable<T>, IDisposable
|
|||
return;
|
||||
}
|
||||
|
||||
if (Own && OwnContent)
|
||||
for (int len = (int)eina_array_count_custom_export_mono(h),
|
||||
i = 0; i < len; ++i)
|
||||
{
|
||||
int len = (int)eina_array_count_custom_export_mono(h);
|
||||
for (int i = 0; i < len; ++i)
|
||||
if (!OwnContent)
|
||||
{
|
||||
NativeFree<T>(eina_array_data_get_custom_export_mono(h, (uint)i));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
DeleteData(eina_array_data_get_custom_export_mono(h, (uint)i));
|
||||
}
|
||||
|
||||
if (Own)
|
||||
{
|
||||
if (disposing)
|
||||
|
@ -236,27 +298,16 @@ public class Array<T> : IEnumerable<T>, IDisposable
|
|||
Dispose();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Releases the native array.
|
||||
/// <para>Since EFL 1.23.</para>
|
||||
/// </summary>
|
||||
/// <returns>The native array.</returns>
|
||||
public IntPtr Release()
|
||||
{
|
||||
IntPtr h = Handle;
|
||||
Handle = IntPtr.Zero;
|
||||
return h;
|
||||
}
|
||||
|
||||
private void FreeElementsIfOwned()
|
||||
{
|
||||
if (OwnContent)
|
||||
if (IsReadOnly)
|
||||
{
|
||||
int len = Length;
|
||||
for (int i = 0; i < len; ++i)
|
||||
{
|
||||
NativeFree<T>(InternalDataGet(i));
|
||||
}
|
||||
throw new NotSupportedException("This object's instance is read only.");
|
||||
}
|
||||
|
||||
for (int i = 0, count = Count; i < count; ++i)
|
||||
{
|
||||
DeleteData(InternalDataGet(i));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -279,26 +330,18 @@ public class Array<T> : IEnumerable<T>, IDisposable
|
|||
eina_array_flush(Handle);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the number of elements in an array.
|
||||
/// <para>Since EFL 1.23.</para>
|
||||
/// </summary>
|
||||
/// <returns>The number of elements.</returns>
|
||||
public int Count()
|
||||
{
|
||||
return (int)eina_array_count_custom_export_mono(Handle);
|
||||
}
|
||||
|
||||
public void SetOwnership(bool ownAll)
|
||||
internal void SetOwnership(bool ownAll)
|
||||
{
|
||||
Own = ownAll;
|
||||
OwnContent = ownAll;
|
||||
CheckOwnerships();
|
||||
}
|
||||
|
||||
public void SetOwnership(bool own, bool ownContent)
|
||||
internal void SetOwnership(bool own, bool ownContent)
|
||||
{
|
||||
Own = own;
|
||||
OwnContent = ownContent;
|
||||
CheckOwnerships();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -308,6 +351,8 @@ public class Array<T> : IEnumerable<T>, IDisposable
|
|||
/// <param name="val">The value of the element to be inserted.</param>
|
||||
public bool Push(T val)
|
||||
{
|
||||
RequireWritable();
|
||||
|
||||
IntPtr ele = ManagedToNativeAlloc(val);
|
||||
var r = InternalPush(ele);
|
||||
if (!r)
|
||||
|
@ -334,11 +379,13 @@ public class Array<T> : IEnumerable<T>, IDisposable
|
|||
/// <returns>The element at the end position.</returns>
|
||||
public T Pop()
|
||||
{
|
||||
RequireWritable();
|
||||
|
||||
IntPtr ele = InternalPop();
|
||||
var r = NativeToManaged<T>(ele);
|
||||
if (OwnContent && ele != IntPtr.Zero)
|
||||
if (ele != IntPtr.Zero)
|
||||
{
|
||||
NativeFree<T>(ele);
|
||||
DeleteData(ele);
|
||||
}
|
||||
|
||||
return r;
|
||||
|
@ -351,10 +398,7 @@ public class Array<T> : IEnumerable<T>, IDisposable
|
|||
/// <param name="idx">The position of the desired element.</param>
|
||||
/// <returns>The element at the specified position</returns>
|
||||
public T DataGet(int idx)
|
||||
{
|
||||
IntPtr ele = InternalDataGet(idx);
|
||||
return NativeToManaged<T>(ele);
|
||||
}
|
||||
=> NativeToManaged<T>(InternalDataGet(idx));
|
||||
|
||||
/// <summary>
|
||||
/// Returns the element of the array at the specified position.
|
||||
|
@ -363,9 +407,8 @@ public class Array<T> : IEnumerable<T>, IDisposable
|
|||
/// <param name="idx">The position of the desired element.</param>
|
||||
/// <returns>The element at the specified position</returns>
|
||||
public T At(int idx)
|
||||
{
|
||||
return DataGet(idx);
|
||||
}
|
||||
=> DataGet(idx);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Replaces the element at the specified position.
|
||||
|
@ -373,16 +416,17 @@ public class Array<T> : IEnumerable<T>, IDisposable
|
|||
/// </summary>
|
||||
/// <param name="idx">The position of the desired element.</param>
|
||||
/// <param name="val">The value of the element to be inserted.</param>
|
||||
public void DataSet(int idx, T val)
|
||||
internal void DataSet(int idx, T val)
|
||||
{
|
||||
IntPtr ele = InternalDataGet(idx); // TODO: check bondaries ??
|
||||
if (OwnContent && ele != IntPtr.Zero)
|
||||
RequireWritable();
|
||||
|
||||
IntPtr ele = InternalDataGet(idx);
|
||||
if (ele != IntPtr.Zero)
|
||||
{
|
||||
NativeFree<T>(ele);
|
||||
DeleteData(ele);
|
||||
}
|
||||
|
||||
ele = ManagedToNativeAlloc(val);
|
||||
InternalDataSet(idx, ele);
|
||||
InternalDataSet(idx, ManagedToNativeAlloc(val));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -408,7 +452,7 @@ public class Array<T> : IEnumerable<T>, IDisposable
|
|||
/// <returns>A array</returns>
|
||||
public T[] ToArray()
|
||||
{
|
||||
int len = Length;
|
||||
int len = Count;
|
||||
var managed = new T[len];
|
||||
for (int i = 0; i < len; ++i)
|
||||
{
|
||||
|
@ -440,17 +484,14 @@ public class Array<T> : IEnumerable<T>, IDisposable
|
|||
/// <para>Since EFL 1.23.</para>
|
||||
/// </summary>
|
||||
public Eina.Iterator<T> GetIterator()
|
||||
{
|
||||
return new Eina.Iterator<T>(eina_array_iterator_new(Handle), true);
|
||||
}
|
||||
=> new Eina.Iterator<T>(eina_array_iterator_new(Handle), true);
|
||||
|
||||
/// <summary> Gets an Enumerator for this Array.
|
||||
/// <para>Since EFL 1.23.</para>
|
||||
/// </summary>
|
||||
public IEnumerator<T> GetEnumerator()
|
||||
{
|
||||
int len = Length;
|
||||
for (int i = 0; i < len; ++i)
|
||||
for (int i = 0, count = Count; i < count; ++i)
|
||||
{
|
||||
yield return DataGet(i);
|
||||
}
|
||||
|
@ -460,16 +501,113 @@ public class Array<T> : IEnumerable<T>, IDisposable
|
|||
/// <para>Since EFL 1.23.</para>
|
||||
/// </summary>
|
||||
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
|
||||
{
|
||||
return this.GetEnumerator();
|
||||
}
|
||||
=> this.GetEnumerator();
|
||||
|
||||
/// <summary> Gets an Accessor for this Array.
|
||||
/// <para>Since EFL 1.23.</para>
|
||||
/// </summary>
|
||||
public Eina.Accessor<T> GetAccessor()
|
||||
=> new Eina.Accessor<T>(eina_array_accessor_new(Handle), Ownership.Managed);
|
||||
|
||||
/// <summary>
|
||||
/// Removes the first occurrence of a specific object.
|
||||
/// <para>Since EFL 1.24.</para>
|
||||
/// </summary>
|
||||
/// <param name="val">The object to remove.</param>
|
||||
public bool Remove(T val)
|
||||
=> LoopingThrough(val,
|
||||
(i) =>
|
||||
{
|
||||
RemoveAt(i);
|
||||
return true;
|
||||
}, () => false);
|
||||
|
||||
/// <summary>
|
||||
/// Adds an item.
|
||||
/// <para>Since EFL 1.24.</para>
|
||||
/// </summary>
|
||||
/// <param name="val">The object to add.</param>
|
||||
public void Add(T val) => Push(val);
|
||||
|
||||
/// <summary>
|
||||
/// Removes all items.
|
||||
/// <para>Since EFL 1.24.</para>
|
||||
/// </summary>
|
||||
public void Clear() => Clean();
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether the <see cref="Array{T}" /> contains a specific value.
|
||||
/// <para>Since EFL 1.24.</para>
|
||||
/// </summary>
|
||||
/// <param name="val">The object to locate.</param>
|
||||
public bool Contains(T val)
|
||||
=> LoopingThrough(val, (i) => true, () => false);
|
||||
|
||||
/// <summary>
|
||||
/// Copies the elements of the <see cref="Array{T}" /> to an
|
||||
/// <see cref="Array" />, starting at a particular <see cref="Array" /> index.
|
||||
/// <para>Since EFL 1.24.</para>
|
||||
/// </summary>
|
||||
/// <param name="array">The one-dimensional <see cref="Array" /> that is the
|
||||
/// destination of the elements copied from <see cref="Array{T}" />.
|
||||
/// The <see cref="Array" /> must have zero-based indexing.</param>
|
||||
/// <param name="arrayIndex">The zero-based index in array at which copying
|
||||
/// begins.</param>
|
||||
public void CopyTo(T[] array, int arrayIndex)
|
||||
=> ToArray().CopyTo(array, arrayIndex);
|
||||
|
||||
/// <summary>
|
||||
/// Determines the index of a specific item.
|
||||
/// <para>Since EFL 1.24.</para>
|
||||
/// </summary>
|
||||
/// <param name="val">The object to locate.</param>
|
||||
public int IndexOf(T val)
|
||||
=> LoopingThrough(val, (i) => i, () => -1);
|
||||
|
||||
/// <summary>
|
||||
/// Inserts an item to the <see cref="Array{T}" /> at the specified index.
|
||||
/// <para>Since EFL 1.24.</para>
|
||||
/// </summary>
|
||||
/// <param name="index">The zero-based index at which item should be inserted.</param>
|
||||
/// <param name="val">The object to insert.</param>
|
||||
public void Insert(int index, T val)
|
||||
{
|
||||
return new Eina.Accessor<T>(eina_array_accessor_new(Handle), Ownership.Managed);
|
||||
RequireWritable();
|
||||
|
||||
if (index < 0)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(index), $"{nameof(index)} cannot be negative.");
|
||||
}
|
||||
|
||||
if (Count < index)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(index), $"{nameof(index)} is greater than {nameof(Count)} + 1.");
|
||||
}
|
||||
|
||||
if (index == Count)
|
||||
{
|
||||
Push(val);
|
||||
return;
|
||||
}
|
||||
|
||||
eina_array_insert_at_custom_export_mono(Handle, (uint)index,
|
||||
ManagedToNativeAlloc(val));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes the <see cref="Array{T}" /> item at the specified index.
|
||||
/// <para>Since EFL 1.24.</para>
|
||||
/// </summary>
|
||||
/// <param name="index">The zero-based index of the item to remove.</param>
|
||||
public void RemoveAt(int index)
|
||||
{
|
||||
RequireWritable();
|
||||
|
||||
var ele = InternalDataGet(index);
|
||||
DeleteData(ele);
|
||||
eina_array_remove(Handle, (data,gdata)
|
||||
=> ele != data,
|
||||
IntPtr.Zero);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -294,6 +294,17 @@ EAPI Eina_Bool eina_array_foreach_custom_export_mono(Eina_Array *array, Eina_Eac
|
|||
return eina_array_foreach(array, cb, fdata);
|
||||
}
|
||||
|
||||
EAPI void eina_array_insert_at_custom_export_mono(Eina_Array* array, unsigned int index, void* const data)
|
||||
{
|
||||
eina_array_push(array, data);
|
||||
for (unsigned int i = eina_array_count(array) - 1; i > index; --i)
|
||||
{
|
||||
void* tmp = eina_array_data_get(array, i);
|
||||
eina_array_data_set(array, i, eina_array_data_get(array, i - 1));
|
||||
eina_array_data_set(array, i - 1, tmp);
|
||||
}
|
||||
}
|
||||
|
||||
// List //
|
||||
|
||||
EAPI Eina_List *eina_list_last_custom_export_mono(const Eina_List *list)
|
||||
|
|
|
@ -0,0 +1,189 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace TestSuite
|
||||
{
|
||||
|
||||
class TestArray
|
||||
{
|
||||
public static void TestAdd()
|
||||
{
|
||||
IList<int> array = new Eina.Array<int>();
|
||||
Test.AssertEquals(array.Count, 0);
|
||||
array.Add(1);
|
||||
Test.AssertEquals(array.Count, 1);
|
||||
array.Add(2);
|
||||
Test.AssertEquals(array.Count, 2);
|
||||
}
|
||||
|
||||
public static void TestRemoveAt()
|
||||
{
|
||||
IList<int> array = new Eina.Array<int>();
|
||||
Test.AssertEquals(array.Count, 0);
|
||||
array.Add(1);
|
||||
Test.AssertEquals(array.Count, 1);
|
||||
Test.AssertEquals(array[0], 1);
|
||||
array.RemoveAt(0);
|
||||
Test.AssertEquals(array.Count, 0);
|
||||
array.Add(1);
|
||||
array.Add(0);
|
||||
array.Add(1);
|
||||
Test.AssertEquals(array.Count, 3);
|
||||
Test.AssertEquals(array[2], 1);
|
||||
array.RemoveAt(2);
|
||||
Test.AssertEquals(array.Count, 2);
|
||||
Test.AssertEquals(array[0], 1);
|
||||
}
|
||||
|
||||
public static void TestRemove()
|
||||
{
|
||||
IList<int> array = new Eina.Array<int>();
|
||||
Test.Assert(!array.Remove(0));
|
||||
Test.AssertEquals(array.Count, 0);
|
||||
array.Add(1);
|
||||
Test.AssertEquals(array.Count, 1);
|
||||
Test.Assert(array.Remove(1));
|
||||
Test.AssertEquals(array.Count, 0);
|
||||
array.Add(1);
|
||||
array.Add(1);
|
||||
Test.AssertEquals(array.Count, 2);
|
||||
Test.Assert(array.Remove(1));
|
||||
Test.AssertEquals(array.Count, 1);
|
||||
array.Add(0);
|
||||
array.Add(1);
|
||||
Test.AssertEquals(array[1], 0);
|
||||
Test.AssertEquals(array.Count, 3);
|
||||
Test.Assert(!array.Remove(2));
|
||||
Test.Assert(array.Remove(1));
|
||||
Test.AssertEquals(array[1], 1);
|
||||
Test.AssertEquals(array.Count, 2);
|
||||
}
|
||||
|
||||
public static void TestContains()
|
||||
{
|
||||
IList<int> array = new Eina.Array<int>();
|
||||
Test.AssertEquals(array.Count, 0);
|
||||
Test.Assert(!array.Contains(0));
|
||||
array.Add(0);
|
||||
Test.Assert(array.Contains(0));
|
||||
Test.Assert(array.Remove(0));
|
||||
Test.Assert(!array.Contains(0));
|
||||
array.Add(1);
|
||||
array.Add(0);
|
||||
Test.Assert(array.Contains(0));
|
||||
}
|
||||
|
||||
public static void TestClear()
|
||||
{
|
||||
IList<int> array = new Eina.Array<int>();
|
||||
Test.AssertEquals(array.Count, 0);
|
||||
array.Clear();
|
||||
Test.AssertEquals(array.Count, 0);
|
||||
array.Add(0);
|
||||
Test.AssertEquals(array.Count, 1);
|
||||
array.Clear();
|
||||
Test.AssertEquals(array.Count, 0);
|
||||
array.Add(0);
|
||||
array.Add(0);
|
||||
Test.AssertEquals(array.Count, 2);
|
||||
array.Clear();
|
||||
Test.AssertEquals(array.Count, 0);
|
||||
array.Add(0);
|
||||
array.Add(0);
|
||||
Test.AssertEquals(array.Count, 2);
|
||||
Test.Assert(array.Remove(0));
|
||||
Test.AssertEquals(array.Count, 1);
|
||||
array.Clear();
|
||||
Test.AssertEquals(array.Count, 0);
|
||||
}
|
||||
|
||||
public static void TestInsert()
|
||||
{
|
||||
IList<int> array = new Eina.Array<int>();
|
||||
array.Add(99);
|
||||
Test.AssertEquals(array.Count, 1);
|
||||
array.Insert(0, 6);
|
||||
Test.AssertEquals(array.Count, 2);
|
||||
Test.AssertEquals(array[0], 6);
|
||||
array.Insert(1, 5);
|
||||
Test.AssertEquals(array.Count, 3);
|
||||
Test.AssertEquals(array[1], 5);
|
||||
array.Insert(1, 10);
|
||||
Test.AssertEquals(array.Count, 4);
|
||||
Test.AssertEquals(array[1], 10);
|
||||
array.RemoveAt(1);
|
||||
Test.AssertEquals(array.Count, 3);
|
||||
Test.AssertEquals(array[1], 5);
|
||||
array.Insert(1, 42);
|
||||
Test.AssertEquals(array.Count, 4);
|
||||
Test.AssertEquals(array[1], 42);
|
||||
}
|
||||
|
||||
public static void TestIndexOf()
|
||||
{
|
||||
IList<int> array = new Eina.Array<int>();
|
||||
Test.AssertEquals(array.Count, 0);
|
||||
array.Add(1);
|
||||
Test.AssertEquals(array.Count, 1);
|
||||
Test.AssertEquals(0, array.IndexOf(1));
|
||||
array.Insert(0, 0);
|
||||
Test.AssertEquals(array.Count, 2);
|
||||
Test.AssertEquals(0, array.IndexOf(0));
|
||||
Test.AssertEquals(1, array.IndexOf(1));
|
||||
array.Insert(0, 1);
|
||||
Test.AssertEquals(array.Count, 3);
|
||||
Test.AssertEquals(0, array.IndexOf(1));
|
||||
Test.AssertEquals(1, array.IndexOf(0));
|
||||
array.Insert(0, 1);
|
||||
Test.AssertEquals(array.Count, 4);
|
||||
Test.AssertEquals(0, array.IndexOf(1));
|
||||
Test.AssertEquals(2, array.IndexOf(0));
|
||||
}
|
||||
|
||||
public static void TestCopyTo()
|
||||
{
|
||||
IList<int> array = new Eina.Array<int>();
|
||||
Test.AssertEquals(array.Count, 0);
|
||||
int[] random = {4, 40, 10, 42, 99};
|
||||
array.Add(43);
|
||||
array.Insert(0, 1);
|
||||
array.Insert(1, 50);
|
||||
Test.AssertEquals(array.Count, 3);
|
||||
Array.ForEach(random, (n) => array.Add(n));
|
||||
Test.AssertEquals(array.Count, 8);
|
||||
int[] expected = {1, 50, 43, 4, 40, 10, 42, 99};
|
||||
var result = new int[expected.Length];
|
||||
array.CopyTo(result, 0);
|
||||
for (int i = 0; i < expected.Length; ++i)
|
||||
{
|
||||
Test.AssertEquals(expected[i], result[i]);
|
||||
}
|
||||
}
|
||||
|
||||
public static void TestIdxOutBounds()
|
||||
{
|
||||
var array = new Eina.Array<int>();
|
||||
array.Add(4);
|
||||
Test.AssertRaises<ArgumentOutOfRangeException>(()=>array.At(1));
|
||||
Test.AssertRaises<ArgumentOutOfRangeException>(()=>array.At(-1));
|
||||
Test.AssertNotRaises<ArgumentOutOfRangeException>
|
||||
(()=>array.At(array.IndexOf(4)));
|
||||
}
|
||||
|
||||
public static void TestIsReadOnly()
|
||||
{
|
||||
var array = new Eina.Array<int>();
|
||||
int[] tmp = {1, 3, 2, 6 ,5};
|
||||
array.Append(tmp);
|
||||
Test.AssertEquals(array.Count, 5);
|
||||
array.SetOwnership(false);
|
||||
Test.AssertRaises<NotSupportedException>(() => array.Add(4));
|
||||
Test.AssertRaises<NotSupportedException>(() => array.Push(6));
|
||||
Test.AssertRaises<NotSupportedException>(() => array.Append(tmp));
|
||||
Test.AssertEquals(array.Count, 5);
|
||||
Test.AssertRaises<NotSupportedException>(() => array.DataSet(2, 4));
|
||||
Test.Assert(array.ToArray().SequenceEqual(tmp));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -787,16 +787,16 @@ class TestEinaArray
|
|||
{
|
||||
var a = new Eina.Array<int>();
|
||||
Test.Assert(a.Handle != IntPtr.Zero);
|
||||
Test.Assert(a.Length == 0);
|
||||
Test.Assert(a.Count == 0);
|
||||
Test.Assert(a.Push(88));
|
||||
Test.Assert(a[0] == 88);
|
||||
Test.Assert(a.Length == 1);
|
||||
Test.Assert(a.Count == 1);
|
||||
Test.Assert(a.Push(44));
|
||||
Test.Assert(a[1] == 44);
|
||||
Test.Assert(a.Length == 2);
|
||||
Test.Assert(a.Count == 2);
|
||||
Test.Assert(a.Push(22));
|
||||
Test.Assert(a[2] == 22);
|
||||
Test.Assert(a.Length == 3);
|
||||
Test.Assert(a.Count == 3);
|
||||
a.Dispose();
|
||||
}
|
||||
|
||||
|
@ -804,16 +804,16 @@ class TestEinaArray
|
|||
{
|
||||
var a = new Eina.Array<string>();
|
||||
Test.Assert(a.Handle != IntPtr.Zero);
|
||||
Test.Assert(a.Length == 0);
|
||||
Test.Assert(a.Count == 0);
|
||||
Test.Assert(a.Push("a"));
|
||||
Test.Assert(a[0] == "a");
|
||||
Test.Assert(a.Length == 1);
|
||||
Test.Assert(a.Count == 1);
|
||||
Test.Assert(a.Push("b"));
|
||||
Test.Assert(a[1] == "b");
|
||||
Test.Assert(a.Length == 2);
|
||||
Test.Assert(a.Count == 2);
|
||||
Test.Assert(a.Push("c"));
|
||||
Test.Assert(a[2] == "c");
|
||||
Test.Assert(a.Length == 3);
|
||||
Test.Assert(a.Count == 3);
|
||||
a.Dispose();
|
||||
}
|
||||
|
||||
|
@ -821,16 +821,16 @@ class TestEinaArray
|
|||
{
|
||||
var a = new Eina.Array<Eina.Stringshare>();
|
||||
Test.Assert(a.Handle != IntPtr.Zero);
|
||||
Test.Assert(a.Length == 0);
|
||||
Test.Assert(a.Count == 0);
|
||||
Test.Assert(a.Push("a"));
|
||||
Test.Assert(a[0] == "a");
|
||||
Test.Assert(a.Length == 1);
|
||||
Test.Assert(a.Count == 1);
|
||||
Test.Assert(a.Push("b"));
|
||||
Test.Assert(a[1] == "b");
|
||||
Test.Assert(a.Length == 2);
|
||||
Test.Assert(a.Count == 2);
|
||||
Test.Assert(a.Push("c"));
|
||||
Test.Assert(a[2] == "c");
|
||||
Test.Assert(a.Length == 3);
|
||||
Test.Assert(a.Count == 3);
|
||||
a.Dispose();
|
||||
}
|
||||
|
||||
|
@ -951,7 +951,7 @@ class TestEinaArray
|
|||
Test.Assert(t.EinaArrayIntOut(out arr));
|
||||
Test.Assert(!arr.Own);
|
||||
Test.Assert(arr.ToArray().SequenceEqual(base_seq_int));
|
||||
Test.Assert(arr.Append(append_seq_int));
|
||||
Test.AssertRaises<NotSupportedException>(() => arr.Append(append_seq_int));
|
||||
arr.Dispose();
|
||||
Test.Assert(arr.Handle == IntPtr.Zero);
|
||||
Test.Assert(t.CheckEinaArrayIntOut());
|
||||
|
@ -976,8 +976,9 @@ class TestEinaArray
|
|||
var t = new Dummy.TestObject();
|
||||
var arr = t.EinaArrayIntReturn();
|
||||
Test.Assert(!arr.Own);
|
||||
Test.Assert(!arr.OwnContent);
|
||||
Test.Assert(arr.ToArray().SequenceEqual(base_seq_int));
|
||||
Test.Assert(arr.Append(append_seq_int));
|
||||
Test.AssertRaises<NotSupportedException>(() => arr.Append(append_seq_int));
|
||||
arr.Dispose();
|
||||
Test.Assert(arr.Handle == IntPtr.Zero);
|
||||
Test.Assert(t.CheckEinaArrayIntReturn());
|
||||
|
@ -1031,7 +1032,7 @@ class TestEinaArray
|
|||
Test.Assert(t.EinaArrayStrOut(out arr));
|
||||
Test.Assert(!arr.Own);
|
||||
Test.Assert(arr.ToArray().SequenceEqual(base_seq_str));
|
||||
Test.Assert(arr.Append(append_seq_str));
|
||||
Test.AssertRaises<NotSupportedException>(() => arr.Append(append_seq_str));
|
||||
arr.Dispose();
|
||||
Test.Assert(arr.Handle == IntPtr.Zero);
|
||||
Test.Assert(t.CheckEinaArrayStrOut());
|
||||
|
@ -1057,7 +1058,7 @@ class TestEinaArray
|
|||
var arr = t.EinaArrayStrReturn();
|
||||
Test.Assert(!arr.Own);
|
||||
Test.Assert(arr.ToArray().SequenceEqual(base_seq_str));
|
||||
Test.Assert(arr.Append(append_seq_str));
|
||||
Test.AssertRaises<NotSupportedException>(() => arr.Append(append_seq_str));
|
||||
arr.Dispose();
|
||||
Test.Assert(arr.Handle == IntPtr.Zero);
|
||||
Test.Assert(t.CheckEinaArrayStrReturn());
|
||||
|
@ -1111,7 +1112,7 @@ class TestEinaArray
|
|||
Test.Assert(t.EinaArrayStrshareOut(out arr));
|
||||
Test.Assert(!arr.Own);
|
||||
Test.Assert(arr.ToArray().SequenceEqual(base_seq_strshare));
|
||||
Test.Assert(arr.Append(append_seq_strshare));
|
||||
Test.AssertRaises<NotSupportedException>(() => arr.Append(append_seq_strshare));
|
||||
arr.Dispose();
|
||||
Test.Assert(arr.Handle == IntPtr.Zero);
|
||||
Test.Assert(t.CheckEinaArrayStrshareOut());
|
||||
|
@ -1137,7 +1138,7 @@ class TestEinaArray
|
|||
var arr = t.EinaArrayStrshareReturn();
|
||||
Test.Assert(!arr.Own);
|
||||
Test.Assert(arr.ToArray().SequenceEqual(base_seq_strshare));
|
||||
Test.Assert(arr.Append(append_seq_strshare));
|
||||
Test.AssertRaises<NotSupportedException>(() => arr.Append(append_seq_strshare));
|
||||
arr.Dispose();
|
||||
Test.Assert(arr.Handle == IntPtr.Zero);
|
||||
Test.Assert(t.CheckEinaArrayStrshareReturn());
|
||||
|
@ -1192,7 +1193,7 @@ class TestEinaArray
|
|||
Test.Assert(t.EinaArrayObjOut(out arr));
|
||||
Test.Assert(!arr.Own);
|
||||
NumberwrapperSequenceAssertEqual(arr.ToArray(), BaseSeqObj());
|
||||
Test.Assert(arr.Append(AppendSeqObj()));
|
||||
Test.AssertRaises<NotSupportedException>(() => arr.Append(AppendSeqObj()));
|
||||
arr.Dispose();
|
||||
Test.Assert(arr.Handle == IntPtr.Zero);
|
||||
Test.Assert(t.CheckEinaArrayObjOut());
|
||||
|
@ -1218,7 +1219,7 @@ class TestEinaArray
|
|||
var arr = t.EinaArrayObjReturn();
|
||||
Test.Assert(!arr.Own);
|
||||
NumberwrapperSequenceAssertEqual(arr.ToArray(), BaseSeqObj());
|
||||
Test.Assert(arr.Append(AppendSeqObj()));
|
||||
Test.AssertRaises<NotSupportedException>(() => arr.Append(AppendSeqObj()));
|
||||
arr.Dispose();
|
||||
Test.Assert(arr.Handle == IntPtr.Zero);
|
||||
Test.Assert(t.CheckEinaArrayObjReturn());
|
||||
|
@ -1246,7 +1247,7 @@ class TestEinaArray
|
|||
var b = t.EinaArrayObjReturnIn(a);
|
||||
NumberwrapperSequenceAssertEqual(a.ToArray(), b.ToArray());
|
||||
NumberwrapperSequenceAssertEqual(a.ToArray(), BaseSeqObj());
|
||||
int len = a.Length;
|
||||
int len = a.Count;
|
||||
for (int i=0; i < len; ++i)
|
||||
{
|
||||
Test.Assert(a[i].NativeHandle == b[i].NativeHandle);
|
||||
|
|
|
@ -239,7 +239,7 @@ class TestEoEvents
|
|||
|
||||
obj.EmitEventWithArray(sent);
|
||||
|
||||
Test.AssertEquals(sent.Length, received.Length);
|
||||
Test.AssertEquals(sent.Count, received.Count);
|
||||
var pairs = sent.Zip(received, (string sentItem, string receivedItem) => new { Sent = sentItem, Received = receivedItem } );
|
||||
foreach (var pair in pairs)
|
||||
{
|
||||
|
|
|
@ -579,7 +579,7 @@ Eina_Bool _dummy_test_object_check_eina_array_int_out(EINA_UNUSED Eo *obj, EINA_
|
|||
{
|
||||
if (!_array_int_out_to_check) return EINA_FALSE;
|
||||
|
||||
Eina_Bool r = _array_int_equal(_array_int_out_to_check, modified_seq_int, modified_seq_int_size);
|
||||
Eina_Bool r = _array_int_equal(_array_int_out_to_check, base_seq_int, base_seq_int_size);
|
||||
|
||||
unsigned int i;
|
||||
int *ele;
|
||||
|
@ -617,7 +617,7 @@ Eina_Bool _dummy_test_object_check_eina_array_int_return(EINA_UNUSED Eo *obj, EI
|
|||
{
|
||||
if (!_array_int_return_to_check) return EINA_FALSE;
|
||||
|
||||
Eina_Bool r = _array_int_equal(_array_int_return_to_check, modified_seq_int, modified_seq_int_size);
|
||||
Eina_Bool r = _array_int_equal(_array_int_return_to_check, base_seq_int, base_seq_int_size);
|
||||
|
||||
unsigned int i;
|
||||
int *ele;
|
||||
|
@ -707,7 +707,7 @@ Eina_Bool _dummy_test_object_check_eina_array_str_out(EINA_UNUSED Eo *obj, EINA_
|
|||
{
|
||||
if (!_array_str_out_to_check) return EINA_FALSE;
|
||||
|
||||
Eina_Bool r = _array_str_equal(_array_str_out_to_check, modified_seq_str, modified_seq_str_size);
|
||||
Eina_Bool r = _array_str_equal(_array_str_out_to_check, base_seq_str, base_seq_str_size);
|
||||
|
||||
unsigned int i;
|
||||
char *ele;
|
||||
|
@ -745,7 +745,7 @@ Eina_Bool _dummy_test_object_check_eina_array_str_return(EINA_UNUSED Eo *obj, EI
|
|||
{
|
||||
if (!_array_str_return_to_check) return EINA_FALSE;
|
||||
|
||||
Eina_Bool r = _array_str_equal(_array_str_return_to_check, modified_seq_str, modified_seq_str_size);
|
||||
Eina_Bool r = _array_str_equal(_array_str_return_to_check, base_seq_str,base_seq_str_size);
|
||||
|
||||
unsigned int i;
|
||||
char *ele;
|
||||
|
@ -840,7 +840,7 @@ Eina_Bool _dummy_test_object_check_eina_array_strshare_out(EINA_UNUSED Eo *obj,
|
|||
{
|
||||
if (!_array_strshare_out_to_check) return EINA_FALSE;
|
||||
|
||||
Eina_Bool r = _array_strshare_equal(_array_strshare_out_to_check, modified_seq_str, modified_seq_str_size);
|
||||
Eina_Bool r = _array_strshare_equal(_array_strshare_out_to_check, base_seq_str, base_seq_str_size);
|
||||
|
||||
unsigned int i;
|
||||
Eina_Stringshare *ele;
|
||||
|
@ -878,7 +878,7 @@ Eina_Bool _dummy_test_object_check_eina_array_strshare_return(EINA_UNUSED Eo *ob
|
|||
{
|
||||
if (!_array_strshare_return_to_check) return EINA_FALSE;
|
||||
|
||||
Eina_Bool r = _array_strshare_equal(_array_strshare_return_to_check, modified_seq_str, modified_seq_str_size);
|
||||
Eina_Bool r = _array_strshare_equal(_array_strshare_return_to_check, base_seq_str, base_seq_str_size);
|
||||
|
||||
unsigned int i;
|
||||
Eina_Stringshare *ele;
|
||||
|
@ -974,7 +974,7 @@ Eina_Bool _dummy_test_object_check_eina_array_obj_out(EINA_UNUSED Eo *obj, EINA_
|
|||
{
|
||||
if (!_array_obj_out_to_check) return EINA_FALSE;
|
||||
|
||||
Eina_Bool r = _array_obj_equal(_array_obj_out_to_check, modified_seq_obj, modified_seq_obj_size);
|
||||
Eina_Bool r = _array_obj_equal(_array_obj_out_to_check, base_seq_obj, base_seq_obj_size);
|
||||
if (!r) return r;
|
||||
|
||||
unsigned int i;
|
||||
|
@ -1013,7 +1013,7 @@ Eina_Bool _dummy_test_object_check_eina_array_obj_return(EINA_UNUSED Eo *obj, EI
|
|||
{
|
||||
if (!_array_obj_return_to_check) return EINA_FALSE;
|
||||
|
||||
Eina_Bool r = _array_obj_equal(_array_obj_return_to_check, modified_seq_obj, modified_seq_obj_size);
|
||||
Eina_Bool r = _array_obj_equal(_array_obj_return_to_check, base_seq_obj, base_seq_obj_size);
|
||||
if (!r) return r;
|
||||
|
||||
unsigned int i;
|
||||
|
|
|
@ -83,6 +83,7 @@ efl_mono_src = [
|
|||
'Inheritance.cs',
|
||||
'Hash.cs',
|
||||
'List.cs',
|
||||
'Array.cs',
|
||||
]
|
||||
|
||||
if get_option('dotnet')
|
||||
|
|
Loading…
Reference in New Issue