efl_mono: Added test files for the C# bindings.

Buildsystem integration will come in a future commit.
This commit is contained in:
Lauro Moura 2017-11-23 21:53:28 -03:00
parent d93e9ff286
commit 345336c46d
17 changed files with 11406 additions and 0 deletions

1
src/tests/efl_mono/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/libefl_mono_test.dll

4267
src/tests/efl_mono/Eina.cs Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,447 @@
#if !WIN32
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;
using static EldbusTestUtil;
using static Test;
public static class EldbusTestUtil
{
public const string DBusBus = "org.freedesktop.DBus";
public const string DBusInterface = "org.freedesktop.DBus";
public const string DBusPath = "/org/freedesktop/DBus";
[return: MarshalAs(UnmanagedType.U1)] public delegate bool Ecore_Task_Cb(IntPtr data);
public static Ecore_Task_Cb GetEcoreLoopClose()
{
if (_ecore_loop_close == null)
_ecore_loop_close = new Ecore_Task_Cb(_ecore_loop_close_impl);
return _ecore_loop_close;
}
[DllImport(efl.Libs.Ecore)] public static extern IntPtr
ecore_timer_add(double _in, Ecore_Task_Cb func, IntPtr data);
[DllImport(efl.Libs.Ecore)] public static extern IntPtr
ecore_timer_del(IntPtr timer);
[DllImport(efl.Libs.Ecore)] public static extern void
ecore_main_loop_begin();
[DllImport(efl.Libs.Ecore)] public static extern void
ecore_main_loop_quit();
static private bool _ecore_loop_close_impl(IntPtr data)
{
ecore_main_loop_quit();
return false;
}
static private Ecore_Task_Cb _ecore_loop_close = null;
}
namespace TestSuite
{
class TestEldbusConnection
{
public static void eldbus_connection_new_session()
{
var conn = new eldbus.Connection(eldbus.Connection.Type.Session);
conn.Dispose();
}
public static void eldbus_connection_new_system()
{
var conn = new eldbus.Connection(eldbus.Connection.Type.System);
conn.Dispose();
}
public static void eldbus_connection_new_starter()
{
var conn = new eldbus.Connection(eldbus.Connection.Type.Starter);
conn.Dispose();
}
public static void eldbus_connection_new_private_session()
{
var conn = eldbus.Connection.GetPrivate(eldbus.Connection.Type.Session);
conn.Dispose();
}
public static void eldbus_connection_new_private_system()
{
var conn = eldbus.Connection.GetPrivate(eldbus.Connection.Type.System);
conn.Dispose();
}
public static void eldbus_connection_new_private_starter()
{
var conn = eldbus.Connection.GetPrivate(eldbus.Connection.Type.Starter);
conn.Dispose();
}
public static void eldbus_connection_get_unique_name()
{
var conn = new eldbus.Connection(eldbus.Connection.Type.Session);
Console.WriteLine(conn.GetUniqueName());
conn.Dispose();
}
}
class TestEldbusObject
{
public static void utc_eldbus_object_send_info_get_p()
{
var conn = new eldbus.Connection(eldbus.Connection.Type.System);
var obj = new eldbus.Object(conn, DBusBus, DBusPath);
string busFromObject = obj.GetBusName();
AssertEquals(DBusBus, busFromObject);
string pathFromObject = obj.GetPath();
AssertEquals(DBusPath, pathFromObject);
obj.Ref();
obj.Unref();
{
var connectionFromObj = obj.GetConnection();
Assert(conn.Handle == connectionFromObj.Handle);
connectionFromObj.Dispose();
}
IntPtr timeout = IntPtr.Zero;
int messageCapture = 0;
bool isSuccess = false;
eldbus.MessageDelegate objectMessageCb = delegate(eldbus.Message msg, eldbus.Pending p)
{
try
{
if (timeout != IntPtr.Zero)
{
ecore_timer_del(timeout);
timeout = IntPtr.Zero;
}
string errname;
string errmsg;
if (messageCapture == 5)
{
if (!msg.GetError(out errname, out errmsg))
{
string txt;
if (msg.Get(out txt))
{
if (!String.IsNullOrEmpty(txt))
isSuccess = true;
}
}
}
}
finally
{
ecore_main_loop_quit();
}
};
var methodName = "GetId";
var message = obj.NewMethodCall(DBusInterface, methodName);
eldbus.Pending pending = obj.Send(message, objectMessageCb, -1);
timeout = ecore_timer_add(2.0, GetEcoreLoopClose(), IntPtr.Zero);
Assert(timeout != IntPtr.Zero);
messageCapture = 5;
ecore_main_loop_begin();
Assert(isSuccess, $"Method {methodName} is not call");
message.Dispose();
obj.Dispose();
conn.Dispose();
}
public static void utc_eldbus_introspect_p()
{
var conn = new eldbus.Connection(eldbus.Connection.Type.System);
var obj = new eldbus.Object(conn, DBusBus, DBusPath);
IntPtr timeout = IntPtr.Zero;
int messageCapture = 0;
bool isSuccess = false;
eldbus.MessageDelegate objectMessageCb = delegate(eldbus.Message msg, eldbus.Pending p)
{
try
{
if (timeout != IntPtr.Zero)
{
ecore_timer_del(timeout);
timeout = IntPtr.Zero;
}
string errname;
string errmsg;
if (messageCapture == 5)
{
if (!msg.GetError(out errname, out errmsg))
{
string txt;
if (msg.Get(out txt))
{
if (!String.IsNullOrEmpty(txt))
isSuccess = true;
}
}
}
}
finally
{
ecore_main_loop_quit();
}
};
eldbus.Pending pending = obj.Introspect(objectMessageCb);
timeout = ecore_timer_add(2.0, GetEcoreLoopClose(), IntPtr.Zero);
Assert(timeout != IntPtr.Zero);
messageCapture = 5;
ecore_main_loop_begin();
Assert(isSuccess, "Method Introspect is not call");
obj.Dispose();
conn.Dispose();
}
}
class TestEldbusMessage
{
private static IntPtr timeout = IntPtr.Zero;
private static bool isSuccess = false;
private static void ActivableList(eldbus.MessageDelegate messageCb)
{
isSuccess = false;
var conn = new eldbus.Connection(eldbus.Connection.Type.System);
eldbus.Pending pending = conn.ActivableList(messageCb);
timeout = ecore_timer_add(2.0, GetEcoreLoopClose(), IntPtr.Zero);
Assert(timeout != IntPtr.Zero);
ecore_main_loop_begin();
Assert(isSuccess, "Method ListActivatableNames is not call");
conn.Dispose();
}
public static void utc_eldbus_message_iterator_activatable_list_p()
{
eldbus.MessageDelegate responseMessageCb = delegate(eldbus.Message msg, eldbus.Pending p)
{
try
{
if (timeout != IntPtr.Zero)
{
ecore_timer_del(timeout);
timeout = IntPtr.Zero;
}
string errname, errmsg;
if (msg.GetError(out errname, out errmsg))
{
return;
}
eldbus.MessageIterator iterMain = msg.GetMessageIterator();
string signature = iterMain.GetSignature();
if (String.IsNullOrEmpty(signature))
{
return;
}
eldbus.MessageIterator iterator;
iterMain.Get(out iterator, signature);
string bus_name;
bool isHasData = false;
while(iterator.GetAndNext(out bus_name))
{
if (String.IsNullOrEmpty(bus_name))
{
return;
}
isHasData = true;
}
isSuccess = isHasData;
}
finally
{
ecore_main_loop_quit();
}
};
ActivableList(responseMessageCb);
}
public static void utc_eldbus_message_info_data_get_p()
{
isSuccess = false;
var conn = new eldbus.Connection(eldbus.Connection.Type.System);
string methodName = "GetId";
eldbus.Message msg = eldbus.Message.NewMethodCall(DBusBus, DBusPath, DBusInterface, methodName);
string interfaceMsg = msg.GetInterface();
AssertEquals(DBusInterface, interfaceMsg);
string methodMsg = msg.GetMember();
AssertEquals(methodName, methodMsg);
string pathMsg = msg.GetPath();
AssertEquals(DBusPath, pathMsg);
eldbus.MessageDelegate messageMethodCb = delegate(eldbus.Message m, eldbus.Pending p)
{
try
{
if (timeout != IntPtr.Zero)
{
ecore_timer_del(timeout);
timeout = IntPtr.Zero;
}
string errname, errmsg;
if (!m.GetError(out errname, out errmsg))
{
string txt;
if (m.Get(out txt))
{
if (!String.IsNullOrEmpty(txt))
{
if (m.GetSender() == DBusBus &&
!String.IsNullOrEmpty(m.GetDestination()))
{
isSuccess = true;
}
}
}
}
}
finally
{
ecore_main_loop_quit();
}
};
const int timeoutSendMs = 1000;
eldbus.Pending pending = conn.Send(msg, messageMethodCb, timeoutSendMs);
timeout = ecore_timer_add(2.0, GetEcoreLoopClose(), IntPtr.Zero);
Assert(timeout != IntPtr.Zero);
ecore_main_loop_begin();
Assert(isSuccess, $"Method {methodName} is not call");
msg.Dispose();
conn.Dispose();
}
public static void utc_eldbus_message_ref_unref_p()
{
var conn = new eldbus.Connection(eldbus.Connection.Type.System);
eldbus.Message msg = eldbus.Message.NewMethodCall(DBusBus, DBusPath, DBusInterface, "GetId");
msg.Ref();
msg.Unref();
string pathMsg = msg.GetPath();
AssertEquals(DBusPath, pathMsg);
msg.Unref();
msg.Own = false;
msg.Dispose();
conn.Dispose();
}
public static void utc_eldbus_message_iter_next_p()
{
eldbus.MessageDelegate activatableListResponseCb = delegate(eldbus.Message msg, eldbus.Pending p)
{
try
{
if (timeout != IntPtr.Zero)
{
ecore_timer_del(timeout);
timeout = IntPtr.Zero;
}
string errname, errmsg;
if (msg.GetError(out errname, out errmsg))
{
return;
}
eldbus.MessageIterator iterMain = msg.GetMessageIterator();
string signature = iterMain.GetSignature();
if (String.IsNullOrEmpty(signature))
{
return;
}
eldbus.MessageIterator iterator;
iterMain.Get(out iterator, signature);
bool isHasData = false;
do
{
string busName;
iterator.Get(out busName);
if (String.IsNullOrEmpty(busName))
{
return;
}
isHasData = true;
} while (iterator.Next());
isSuccess = isHasData;
}
finally
{
ecore_main_loop_quit();
}
};
ActivableList(activatableListResponseCb);
}
}
}
#endif

194
src/tests/efl_mono/Eo.cs Normal file
View File

@ -0,0 +1,194 @@
using System;
namespace TestSuite
{
class TestEo
{
private class Derived : test.TestingInherit
{
}
//
// Test cases:
//
public static void return_same_object()
{
test.Testing testing = new test.TestingConcrete();
test.Testing o1 = testing.ReturnObject();
Test.Assert(o1.raw_handle != IntPtr.Zero);
Test.Assert(o1.raw_handle == testing.raw_handle);
test.Testing o2 = o1.ReturnObject();
Test.Assert(o2.raw_handle != IntPtr.Zero);
Test.Assert(o2.raw_handle == o1.raw_handle);
}
/* Commented out as adding the event listener seems to prevent it from being GC'd.
public static void destructor_really_frees()
{
bool delEventCalled = false;
{
test.Testing obj = new test.TestingConcrete();
obj.DEL += (object sender, EventArgs e) => { delEventCalled = true; };
}
System.GC.WaitForPendingFinalizers();
System.GC.Collect();
System.GC.WaitForPendingFinalizers();
System.GC.Collect();
System.GC.WaitForPendingFinalizers();
Test.Assert(delEventCalled, "DEL event not called");
} */
public static void dispose_really_frees()
{
bool delEventCalled = false;
{
test.Testing obj = new test.TestingConcrete();
obj.DEL += (object sender, EventArgs e) => { delEventCalled = true; };
((IDisposable)obj).Dispose();
}
Test.Assert(delEventCalled, "DEL event not called");
}
/* Commented out as adding the event listener seems to prevent it from being GC'd.
public static void derived_destructor_really_frees()
{
bool delEventCalled = false;
{
test.Testing obj = new Derived();
obj.DEL += (object sender, EventArgs e) => { delEventCalled = true; };
}
System.GC.WaitForPendingFinalizers();
System.GC.Collect();
System.GC.WaitForPendingFinalizers();
System.GC.Collect();
System.GC.WaitForPendingFinalizers();
Test.Assert(delEventCalled, "DEL event not called");
}
public static void derived_dispose_really_frees()
{
bool delEventCalled = false;
{
test.Testing obj = new Derived();
obj.DEL += (object sender, EventArgs e) => { delEventCalled = true; };
((IDisposable)obj).Dispose();
}
Test.Assert(delEventCalled, "DEL event not called");
}
*/
}
class MyLoop : efl.LoopInherit
{
public MyLoop() : base(null) { }
}
class TestEoInherit
{
public static void instantiate_inherited()
{
efl.Loop loop = new MyLoop();
Test.Assert(loop.raw_handle != System.IntPtr.Zero);
}
}
class TestEoNames
{
public static void name_getset()
{
test.Testing obj = new test.TestingConcrete();
string name = "Dummy";
obj.SetName(name);
Test.AssertEquals(name, obj.GetName());
}
}
class TestEoConstructingMethods
{
public static void constructing_method()
{
bool called = false;
string name = "Test object";
test.Testing obj = new test.TestingConcrete(null, (test.Testing a) => {
called = true;
Console.WriteLine("callback: obj raw_handle: {0:x}", a.raw_handle);
a.SetName(name);
});
Test.Assert(called);
Test.AssertEquals(name, obj.GetName());
}
private class Derived : test.TestingInherit
{
public Derived(test.Testing parent = null,
test.TestingInherit.ConstructingMethod cb = null) : base(parent, cb) {
}
}
public static void constructing_method_inherit()
{
bool called = false;
string name = "Another test object";
Derived obj = new Derived(null, (test.Testing a) => {
called = true;
a.SetComment(name);
});
Test.Assert(called);
Test.AssertEquals(name, obj.GetComment());
}
}
class TestEoParent
{
public static void basic_parent()
{
test.Testing parent = new test.TestingConcrete(null);
test.Testing child = new test.TestingConcrete(parent);
Test.AssertEquals(parent, child.GetParent());
test.Testing parent_retrieved = test.TestingConcrete.static_cast(child.GetParent());
Test.AssertEquals(parent, parent_retrieved);
}
public static void parent_inherited_class()
{
test.Numberwrapper parent = new test.NumberwrapperConcrete(null);
test.Testing child = new test.TestingConcrete(parent);
Test.AssertEquals(parent, child.GetParent());
test.Numberwrapper parent_retrieved = test.NumberwrapperConcrete.static_cast(child.GetParent());
Test.AssertEquals(parent, parent_retrieved);
}
private class Derived : test.TestingInherit
{
public Derived(test.Testing parent = null) : base (parent)
{
}
}
public static void basic_parent_managed_inherit()
{
test.Testing parent = new Derived(null);
test.Testing child = new Derived(parent);
Test.AssertEquals(parent, child.GetParent());
test.Testing parent_from_cast = test.TestingInherit.static_cast(child.GetParent());
Test.AssertEquals(parent, parent_from_cast);
}
}
}

View File

@ -0,0 +1,118 @@
using System;
namespace TestSuite
{
class TestEinaError
{
public static void basic_test()
{
eina.Error.Clear();
Test.AssertNotRaises<efl.EflException>(eina.Error.RaiseIfOccurred);
eina.Error.Set(eina.Error.ENOENT);
Test.AssertRaises<efl.EflException>(eina.Error.RaiseIfOccurred);
}
}
class TestEolianError
{
public static void global_eina_error()
{
test.Testing obj = new test.TestingConcrete();
Test.AssertRaises<efl.EflException>(() => obj.RaisesEinaError());
}
class Child : test.TestingInherit {
}
public static void global_eina_error_inherited()
{
test.Testing obj = new Child();
Test.AssertRaises<efl.EflException>(() => obj.RaisesEinaError());
}
class CustomException : Exception {
public CustomException(string msg): base(msg) {}
}
class Overrider : test.TestingInherit {
public override void ChildrenRaiseError() {
throw (new CustomException("Children error"));
}
}
public static void exception_raised_from_inherited_virtual()
{
test.Testing obj = new Overrider();
Test.AssertRaises<efl.EflException>(obj.CallChildrenRaiseError);
}
// return eina_error
public static void eina_error_return()
{
test.Testing obj = new test.TestingConcrete();
eina.Error expected = 42;
obj.SetErrorRet(expected);
eina.Error error = obj.ReturnsError();
Test.AssertEquals(expected, error);
expected = 0;
obj.SetErrorRet(expected);
error = obj.ReturnsError();
Test.AssertEquals(expected, error);
}
class ReturnOverride : test.TestingInherit {
eina.Error code;
public override void SetErrorRet(eina.Error err) {
code = 2 * err;
}
public override eina.Error ReturnsError()
{
return code;
}
}
public static void eina_error_return_from_inherited_virtual()
{
test.Testing obj = new ReturnOverride();
eina.Error expected = 42;
obj.SetErrorRet(expected);
eina.Error error = obj.ReturnsError();
Test.AssertEquals(new eina.Error(expected * 2), error);
expected = 0;
obj.SetErrorRet(expected);
error = obj.ReturnsError();
Test.AssertEquals(new eina.Error(expected * 2), error);
}
// events
class Listener
{
public bool called = false;
public void callback(object sender, EventArgs e) {
throw (new CustomException("Event exception"));
}
public void another_callback(object sender, EventArgs e) {}
}
public static void eina_error_event_raise_exception()
{
// An event whose managed delegate generates an exception
// must set an eina_error so it can be reported back to
// the managed code
efl.Loop loop = new efl.LoopConcrete();
Listener listener = new Listener();
loop.CALLBACK_ADD += listener.callback;
Test.AssertRaises<efl.EflException>(() => loop.IDLE += listener.another_callback);
}
}
}

View File

@ -0,0 +1,77 @@
using System;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;
public class MyBox : evas.BoxInherit
{
public MyBox(efl.Object parent) : base(parent) {}
[DllImport("evas")] static extern void evas_obj_box_layout_vertical(IntPtr obj, IntPtr data, IntPtr privdata);
[DllImport("evas")] static extern void evas_obj_box_layout_horizontal(IntPtr obj, IntPtr data, IntPtr privdata);
[DllImport("evas")] static extern void evas_object_box_layout_horizontal(IntPtr obj, IntPtr data, IntPtr privdata);
[DllImport("evas")] static extern IntPtr evas_object_evas_get(IntPtr obj);
[DllImport("evas")] static extern void evas_event_freeze(IntPtr obj);
[DllImport("evas")] static extern void evas_event_thaw(IntPtr obj);
override public void CalculateGroup()
{
IntPtr evas = evas_object_evas_get(raw_handle);
evas_event_freeze(evas);
eina.Log.Debug("called group_calculate");
// slayouting_set(true);
evas_obj_box_layout_vertical(raw_handle, IntPtr.Zero, IntPtr.Zero);
// layouting_set(false);
// children_changed_set(false);
evas_event_thaw(evas);
}
}
namespace TestSuite
{
class TestEvas
{
/* private static string ImagePath([CallerFilePath] string folder="") */
/* { */
/* return System.IO.Path.GetDirectoryName(folder); */
/* } */
/* public static void simple_layout() */
/* { */
/* // efl.Loop loop = new efl.LoopConcrete(); */
/* EcoreEvas ecore_evas = new EcoreEvas(); */
/* efl.canvas.Object canvas = ecore_evas.canvas; */
/* canvas.visible_set(true); */
/* efl.Object parent = canvas.parent_get(); */
/* Test.Assert(parent.raw_handle != IntPtr.Zero); */
/* efl.canvas.Rectangle rect = new efl.canvas.RectangleConcrete(canvas); */
/* rect.color_set(255, 255, 255, 255); */
/* rect.size_set(640, 480); */
/* rect.visible_set(true); */
/* evas.Box box = new MyBox(canvas); */
/* rect.size_set(320, 240); */
/* box.visible_set(true); */
/* efl.canvas.Image image1 = new efl.canvas.ImageConcrete(canvas); */
/* image1.file_set(ImagePath() + "/../../examples/elementary/sphere_hunter/score.jpg", ""); */
/* image1.hint_min_set(160, 240); */
/* image1.visible_set(true); */
/* efl.canvas.Image image2 = new efl.canvas.ImageConcrete(canvas); */
/* image2.file_set(ImagePath() + "/../../examples/evas/shooter/assets/images/bricks.jpg", ""); */
/* image2.hint_min_set(160, 120); */
/* image2.visible_set(true); */
/* box.append(image1); */
/* box.append(image2); */
/* // loop.begin(); */
/* } */
}
}

View File

@ -0,0 +1,26 @@
using System;
namespace TestSuite
{
class TestEoEvents
{
public bool called = false;
protected void callback(object sender, EventArgs e) {
called = true;
}
protected void another_callback(object sender, EventArgs e) { }
public static void callback_add_event()
{
efl.Loop loop = new efl.LoopConcrete();
TestEoEvents listener = new TestEoEvents();
loop.CALLBACK_ADD += listener.callback;
Test.Assert(!listener.called);
loop.IDLE += listener.another_callback;
Test.Assert(listener.called);
}
}
}

View File

@ -0,0 +1,196 @@
using System;
using System.Runtime.InteropServices;
namespace TestSuite
{
class TestFunctionPointers
{
static bool called = false;
static int twice(int a)
{
called = true;
return a * 2;
}
static int thrice(int a)
{
called = true;
return a * 3;
}
static void setup()
{
called = false;
}
public static void set_callback_basic()
{
setup();
test.Testing obj = new test.TestingConcrete();
obj.SetCallback(twice);
Test.Assert(called == false, "set_callback should not call the callback");
int x = obj.CallCallback(42);
Test.Assert(called, "call_callback must call a callback");
Test.AssertEquals(42 * 2, x);
}
public static void set_callback_with_lambda()
{
setup();
test.Testing obj = new test.TestingConcrete();
obj.SetCallback(y => {
called = true;
return y + 4;
});
Test.Assert(called == false, "set_callback should not call the callback");
int x = obj.CallCallback(37);
Test.Assert(called, "call_callback must call a callback");
Test.AssertEquals(37 + 4, x);
}
public static void replace_callback()
{
setup();
test.Testing obj = new test.TestingConcrete();
obj.SetCallback(twice);
Test.Assert(called == false, "set_callback should not call the callback");
int x = obj.CallCallback(42);
Test.Assert(called, "call_callback must call a callback");
Test.AssertEquals(42 * 2, x);
bool new_called = false;
obj.SetCallback(y => {
new_called = true;
return y * y;
});
Test.Assert(new_called == false, "set_callback should not call the callback");
x = obj.CallCallback(42);
Test.Assert(new_called, "call_callback must call a callback");
Test.AssertEquals(42 * 42, x);
}
class NoOverride : test.TestingInherit {
}
public static void set_callback_inherited_no_override()
{
setup();
NoOverride obj = new NoOverride();
obj.SetCallback(thrice);
Test.Assert(!called, "set_callback in virtual should not call the callback");
int x = obj.CallCallback(42);
Test.Assert(called, "call_callback must call a callback");
Test.AssertEquals(42 * 3, x);
}
class WithOverride : test.TestingInherit {
public bool set_called = false;
public bool invoke_called = false;
public test.SimpleCb cb = null;
public WithOverride() : base() {
}
public override void SetCallback(test.SimpleCb cb) {
set_called = true;
this.cb = cb;
}
public override int CallCallback(int a) {
invoke_called = true;
if (cb != null)
return cb(a);
eina.Log.Error("No callback set upon call_callback invocation");
return -1;
}
}
public static void set_callback_inherited_with_override()
{
setup();
WithOverride obj = new WithOverride();
obj.SetCallback(thrice);
Test.Assert(obj.set_called, "set_callback override must have been called");
Test.Assert(!obj.invoke_called, "invoke_callback must not have been called");
obj.set_called = false;
int x = obj.CallCallback(42);
Test.Assert(!obj.set_called, "set_callback override must not have been called");
Test.Assert(obj.invoke_called, "set_callback in virtual should not call the callback");
Test.Assert(called, "call_callback must call a callback");
Test.AssertEquals(42 * 3, x);
}
// These are needed due to issues calling methods on obj from the GC thread (where the
// free function is actually called)
[System.Runtime.InteropServices.DllImport("efl_mono_native_test")] static extern bool free_called_get();
[System.Runtime.InteropServices.DllImport("efl_mono_native_test")] static extern bool free_called_set(bool val);
public static void set_callback_inherited_called_from_c()
{
setup();
WithOverride obj = new WithOverride();
free_called_set(false);
obj.CallSetCallback();
Test.Assert(obj.set_called, "set_callback override must have been called");
Test.Assert(!obj.invoke_called, "invoke_callback must not have been called");
Test.Assert(!free_called_get(), "call_set_callback must not call the free callback");
obj.set_called = false;
int x = obj.CallCallback(42);
Test.Assert(!obj.set_called, "set_callback override must not have been called");
Test.Assert(obj.invoke_called, "set_callback in virtual should not call the callback");
Test.Assert(!free_called_get(), "call_callback must not call the free callback");
Test.AssertEquals(42 * 3, x);
setup();
obj.set_called = false;
obj.invoke_called = false;
free_called_set(false);
// Should release the handle to the wrapper allocated when calling set_callback from C.
obj.SetCallback(twice);
GC.Collect();
GC.WaitForPendingFinalizers();
Test.Assert(obj.set_called, "set_callback override must have been called");
Test.Assert(!obj.invoke_called, "invoke_callback must not have been called");
Test.Assert(free_called_get(), "free callback must have been called");
obj.set_called = false;
free_called_set(false);
x = obj.CallCallback(42);
Test.Assert(!obj.set_called, "set_callback override must not have been called");
Test.Assert(obj.invoke_called, "set_callback in virtual should not call the callback");
Test.Assert(!free_called_get(), "must not call old free_callback on new callback");
Test.Assert(called, "call_callback must call a callback");
Test.AssertEquals(42 * 2, x);
}
}
}

100
src/tests/efl_mono/Main.cs Normal file
View File

@ -0,0 +1,100 @@
using System;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;
using System.Reflection;
using System.Linq;
class TestMain
{
static Type[] GetTestCases(String name="")
{
return Assembly.GetExecutingAssembly().GetTypes().Where(t => String.Equals(t.Namespace, "TestSuite", StringComparison.Ordinal) &&
t.Name.StartsWith("Test") &&
t.Name.Contains(name)).ToArray();
}
static int Main(string[] args)
{
efl.All.Init();
bool pass = true;
String ckRunSuite = Environment.GetEnvironmentVariable("CK_RUN_SUITE");
String ckRunCase = Environment.GetEnvironmentVariable("CK_RUN_CASE");
if (ckRunSuite != null && !ckRunSuite.Equals("mono"))
return 0;
if (ckRunCase == null)
ckRunCase = String.Empty;
Console.WriteLine("[ START SUITE ] " + ckRunSuite);
var cases= GetTestCases(ckRunCase);
foreach(var testCase in cases)
{
var localTestCases = testCase.GetMethods(BindingFlags.Static | BindingFlags.Public);
var setUp = Array.Find(localTestCases, m => String.Equals(m.Name, "SetUp", StringComparison.Ordinal));
var tearDown = Array.Find(localTestCases, m => String.Equals(m.Name, "TearDown", StringComparison.Ordinal));
foreach(var localTestCase in localTestCases)
{
if (localTestCase == setUp || localTestCase == tearDown)
continue;
Console.WriteLine("[ RUN ] " + testCase.Name + "." + localTestCase.Name);
bool caseResult = true;
if (setUp != null)
{
try
{
setUp.Invoke(null, null);
}
catch (Exception e)
{
pass = false;
caseResult = false;
Console.WriteLine("[ ERROR ] SetUp fail: " + e.InnerException.ToString());
}
}
if (caseResult)
{
try
{
localTestCase.Invoke(null, null);
}
catch (Exception e)
{
pass = false;
caseResult = false;
Console.WriteLine("[ ERROR ] " + e.InnerException.ToString());
}
}
if (caseResult && tearDown != null)
{
try
{
tearDown.Invoke(null, null);
}
catch (Exception e)
{
pass = false;
caseResult = false;
Console.WriteLine("[ ERROR ] TearDown failed: " + e.InnerException.ToString());
}
}
Console.WriteLine("[ " + (caseResult ? "PASS" : "FAIL") + " ] " + testCase.Name + "." + localTestCase.Name);
}
}
Console.WriteLine("[ END SUITE ] " + ckRunSuite);
if (!pass)
return -1;
return 0;
}
}

View File

@ -0,0 +1,334 @@
using System;
namespace TestSuite {
class TestStrings
{
/* The managed call is still owner of the sent string */
public static void in_string()
{
{
test.Testing obj = new test.TestingConcrete();
String sent = "in_string";
String returned = obj.InString(sent);
Test.AssertEquals(sent, returned);
}
System.GC.Collect();
}
/* The managed call must not keep ownership of the C string after the
* call */
public static void in_own_string()
{
{
test.Testing obj = new test.TestingConcrete();
String sent = "in_own_string";
String returned = obj.InOwnString(sent);
Test.AssertEquals(sent, returned);
}
System.GC.Collect();
}
/* The managed call must not take ownership of the returned string */
public static void return_string()
{
{
test.Testing obj = new test.TestingConcrete();
Test.AssertEquals("string", obj.ReturnString());
}
System.GC.Collect();
}
/* The managed call is free to own the returned string */
public static void return_own_string()
{
{
test.Testing obj = new test.TestingConcrete();
Test.AssertEquals("own_string", obj.ReturnOwnString());
}
System.GC.Collect();
}
/* The managed call is *not* the owner of the string put in the out argument */
public static void out_string()
{
{
String str = String.Empty;
test.Testing obj = new test.TestingConcrete();
obj.OutString(out str);
Test.AssertEquals("out_string", str);
}
System.GC.Collect();
}
/* The managed call is the owner of the string in the out parameter */
public static void out_own_string()
{
{
String str = String.Empty;
test.Testing obj = new test.TestingConcrete();
obj.OutOwnString(out str);
Test.AssertEquals(str.ToString(), "out_own_string");
}
System.GC.Collect();
}
private class StringReturner : test.TestingInherit
{
public String received_in;
public String received_in_own;
public StringReturner() : base(null) {
received_in = String.Empty;
received_in_own = String.Empty;
}
public override String InString(String str)
{
received_in = str;
return String.Empty;
}
public override String InOwnString(String str)
{
/* Console.WriteLine("Called my own virtual"); */
received_in_own = str;
return String.Empty;
}
public override String ReturnString()
{
return "inherited";
}
public override String ReturnOwnString()
{
return "own_inherited";
}
public override void OutString(out String str)
{
str = "out_inherited";
}
public override void OutOwnString(out System.String str)
{
str = "out_own_inherited";
}
}
/* The managed wrapper must not take ownership of the in parameter */
public static void in_string_from_virtual()
{
StringReturner obj = new StringReturner();
/* for (int i = 0; i < 10000; i++) { */
String sent = "in_inherited";
obj.CallInString(sent);
Test.AssertEquals(sent, obj.received_in);
/* } */
System.GC.Collect();
}
/* The managed wrapper should take ownership of the in parameter */
public static void in_own_string_from_virtual()
{
StringReturner obj = new StringReturner();
/* for (int i = 0; i < 10000; i++) { */
String sent = "in_own_inherited";
obj.CallInOwnString(sent);
Test.AssertEquals(sent, obj.received_in_own);
/* } */
System.GC.Collect();
}
/* The managed wrapper still owns the returned C string. We need to cache it until
* some time in the future */
public static void return_string_from_virtual()
{
test.Testing obj = new StringReturner();
/* for (int i = 0; i < 10000; i ++) // Uncomment this to check for memory leaks. */
Test.AssertEquals("inherited", obj.CallReturnString());
System.GC.Collect();
}
/* The managed wrapper must surrender the ownership to the C after the virtual call. */
public static void return_own_string_from_virtual()
{
test.Testing obj = new StringReturner();
/* for (int i = 0; i < 10000; i ++) // Uncomment this to check for memory leaks. */
Test.AssertEquals("own_inherited", obj.CallReturnOwnString());
System.GC.Collect();
}
/* The managed wrapper still owns the C string after the call. Like return without own, we may
* need to cache it until some time in the future. */
public static void out_string_from_virtual()
{
test.Testing obj = new StringReturner();
/* for (int i = 0; i < 10000; i ++) // Uncomment this to check for memory leaks. */
Test.AssertEquals("out_inherited", obj.CallOutString());
System.GC.Collect();
}
/* The managed wrapper gives C the ownership of the filled out parameter */
public static void out_own_string_from_virtual()
{
test.Testing obj = new StringReturner();
/* for (int i = 0; i < 10000; i ++) // Uncomment this to check for memory leaks. */
Test.AssertEquals("out_own_inherited", obj.CallOutOwnString());
System.GC.Collect();
}
}
class TestStringshare
{
public static void in_stringshare()
{
{
test.Testing obj = new test.TestingConcrete();
String sent = "in_stringshare";
String returned = obj.InStringshare(sent);
Test.AssertEquals(sent, returned);
}
System.GC.Collect();
}
public static void in_own_stringshare()
{
{
test.Testing obj = new test.TestingConcrete();
String sent = "in_own_stringshare";
String returned = obj.InOwnStringshare(sent);
Test.AssertEquals(sent, returned);
}
System.GC.Collect();
}
public static void return_stringshare()
{
{
test.Testing obj = new test.TestingConcrete();
Test.AssertEquals("stringshare", obj.ReturnStringshare());
}
System.GC.Collect();
}
public static void return_own_stringshare()
{
{
test.Testing obj = new test.TestingConcrete();
Test.AssertEquals("own_stringshare", obj.ReturnOwnStringshare());
}
System.GC.Collect();
}
public static void out_stringshare()
{
{
String str = String.Empty;
test.Testing obj = new test.TestingConcrete();
obj.OutStringshare(out str);
Test.AssertEquals("out_stringshare", str);
}
System.GC.Collect();
}
public static void out_own_stringshare()
{
{
String str = String.Empty;
test.Testing obj = new test.TestingConcrete();
obj.OutOwnStringshare(out str);
Test.AssertEquals(str.ToString(), "out_own_stringshare");
}
System.GC.Collect();
}
private class StringshareReturner : test.TestingInherit
{
public String received_in;
public String received_in_own;
public StringshareReturner() : base(null) {
received_in = String.Empty;
received_in_own = String.Empty;
}
public override String InStringshare(String str)
{
received_in = str;
return String.Empty;
}
public override String InOwnStringshare(String str)
{
received_in_own = str;
return String.Empty;
}
public override String ReturnStringshare()
{
return "inherited";
}
public override String ReturnOwnStringshare()
{
return "own_inherited";
}
public override void OutStringshare(out String str)
{
str = "out_inherited";
}
public override void OutOwnStringshare(out System.String str)
{
str = "out_own_inherited";
}
}
public static void in_stringshare_from_virtual()
{
StringshareReturner obj = new StringshareReturner();
String sent = "in_inherited";
obj.CallInStringshare(sent);
Test.AssertEquals(sent, obj.received_in);
}
public static void in_own_stringshare_from_virtual()
{
StringshareReturner obj = new StringshareReturner();
String sent = "in_own_inherited";
obj.CallInOwnStringshare(sent);
Test.AssertEquals(sent, obj.received_in_own);
}
public static void return_stringshare_from_virtual()
{
test.Testing obj = new StringshareReturner();
// for (int i = 0; i < 1000000; i ++) // Uncomment this to check for memory leaks.
Test.AssertEquals("inherited", obj.CallReturnStringshare());
}
public static void return_own_stringshare_from_virtual()
{
test.Testing obj = new StringshareReturner();
// for (int i = 0; i < 1000000; i ++) // Uncomment this to check for memory leaks.
Test.AssertEquals("own_inherited", obj.CallReturnOwnStringshare());
}
public static void out_stringshare_from_virtual()
{
test.Testing obj = new StringshareReturner();
// for (int i = 0; i < 1000000; i ++) // Uncomment this to check for memory leaks.
Test.AssertEquals("out_inherited", obj.CallOutStringshare());
}
public static void out_own_stringshare_from_virtual()
{
test.Testing obj = new StringshareReturner();
// for (int i = 0; i < 1000000; i ++) // Uncomment this to check for memory leaks.
Test.AssertEquals("out_own_inherited", obj.CallOutOwnStringshare());
}
}
}

View File

@ -0,0 +1,191 @@
using System;
using System.Runtime.CompilerServices;
using System.Runtime.Serialization;
using System.Diagnostics.CodeAnalysis;
/// <summary>Exception for assertion failures.</summary>
[Serializable]
public class AssertionException : Exception
{
/// <summary> Default constructor.</summary>
public AssertionException() : base () { }
/// <summary> Most commonly used contructor.</summary>
public AssertionException(string msg) : base(msg) { }
/// <summary> Wraps an inner exception.</summary>
public AssertionException(string msg, Exception inner) : base(msg, inner) { }
/// <summary> Serializable constructor.</summary>
protected AssertionException(SerializationInfo info, StreamingContext context) : base(info, context) { }
}
/// <summary> Helper class for Mono EFL bindings tests.</summary>
public static class Test
{
/// <summary> Asserts a boolean condition.</summary>
public static void Assert(bool res, String msg = "Assertion failed",
[CallerLineNumber] int line = 0,
[CallerFilePath] string file = null,
[CallerMemberName] string member = null)
{
if (msg == null)
msg = "Assertion failed.";
if (file == null)
file = "(unknown file)";
if (member == null)
member = "(unknown member)";
if (!res)
throw new AssertionException($"Assertion failed: {file}:{line} ({member}) {msg}");
}
/// <summary> Asserts if expected is equal to actual, using expected.Equals(actual).</summary>
public static void AssertEquals<T>(T expected, T actual, String msg = null,
[CallerLineNumber] int line = 0,
[CallerFilePath] string file = null,
[CallerMemberName] string member = null)
{
if (file == null)
file = "(unknown file)";
if (member == null)
member = "(unknown member)";
if (expected == null)
throw new AssertionException($"{file}:{line} ({member}) Null expected value. Use AssertNull.");
if (!expected.Equals(actual)) {
if (msg == null || msg.Length == 0)
msg = $"Expected \"{expected}\", actual \"{actual}\"";
throw new AssertionException($"{file}:{line} ({member}) {msg}");
}
}
/// <summary> Asserts if expected is not equal to actual, using !expected.Equals(actual).</summary>
public static void AssertNotEquals<T>(T expected, T actual, String msg = null,
[CallerLineNumber] int line = 0,
[CallerFilePath] string file = null,
[CallerMemberName] string member = null)
{
if (file == null)
file = "(unknown file)";
if (member == null)
member = "(unknown member)";
if (expected == null)
throw new AssertionException($"{file}:{line} ({member}) Null expected value. Use AssertNull.");
if (expected.Equals(actual)) {
if (msg == null || msg.Length == 0)
msg = $"Expected \"{expected}\" shouldn't be equal to actual \"{actual}\"";
throw new AssertionException($"{file}:{line} ({member}) {msg}");
}
}
/// <summary> Asserts if actual is near enough of expected, using the optional tolerance (default 0.00001).</summary>
public static void AssertAlmostEquals(double expected, double actual, double tolerance=0.00001,
String msg = null,
[CallerLineNumber] int line = 0,
[CallerFilePath] string file = null,
[CallerMemberName] string member = null)
{
if (file == null)
file = "(unknown file)";
if (member == null)
member = "(unknown member)";
double difference = Math.Abs(expected - actual);
if (difference > tolerance) {
if (msg == null || msg.Length == 0)
msg = $"Expected \"{expected}\". Difference: \"{difference}\"";
throw new AssertionException($"{file}:{line} ({member}) {msg}");
}
}
/// <summary> Asserts if greater is greater than smaller , using greater.CompareTo(smaller) > 0.</summary>
public static void AssertGreaterThan<T>(T greater, T smaller, String msg = null,
[CallerLineNumber] int line = 0,
[CallerFilePath] string file = null,
[CallerMemberName] string member = null) where T : System.IComparable<T>
{
if (file == null)
file = "(unknown file)";
if (member == null)
member = "(unknown member)";
if (greater == null || smaller == null)
throw new AssertionException($"{file}:{line} ({member}) Null input value. Use AssertNull.");
if (greater.CompareTo(smaller) <= 0) {
if (msg == null || msg.Length == 0)
msg = $"Greater \"{greater}\" is not greater than smaller \"{smaller}\"";
throw new AssertionException($"{file}:{line} ({member}) {msg}");
}
}
/// <summary> Asserts if smaller is smaller than greater, using greater.CompareTo(smaller) &lt; 0.</summary>
public static void AssertLessThan<T>(T smaller, T greater, String msg = null,
[CallerLineNumber] int line = 0,
[CallerFilePath] string file = null,
[CallerMemberName] string member = null) where T : System.IComparable<T>
{
if (file == null)
file = "(unknown file)";
if (member == null)
member = "(unknown member)";
if (greater == null || smaller == null)
throw new AssertionException($"{file}:{line} ({member}) Null input value. Use AssertNull.");
if (smaller.CompareTo(greater) >= 0) {
if (msg == null || msg.Length == 0)
msg = $"Smaller \"{smaller}\" is not smaller than greater \"{greater}\"";
throw new AssertionException($"{file}:{line} ({member}) {msg}");
}
}
/// <summary> Asserts if op, when called, raises the exception T.</summary>
[SuppressMessage("Gendarme.Rules.Design.Generic", "AvoidMethodWithUnusedGenericTypeRule")]
public static void AssertRaises<T>(Action op, String msg = null,
[CallerLineNumber] int line = 0,
[CallerFilePath] string file = null,
[CallerMemberName] string member = null) where T: Exception
{
if (msg == null)
msg = "Exception not raised.";
if (file == null)
file = "(unknown file)";
if (member == null)
member = "(unknown member)";
if (op == null)
throw new AssertionException($"Assertion failed: {file}:{line} ({member}) Null operation.");
try {
op();
} catch (T) {
return;
}
throw new AssertionException($"Assertion failed: {file}:{line} ({member}) {msg}");
}
/// <summary> Asserts if op, when called, does not raise the exception T.</summary>
[SuppressMessage("Gendarme.Rules.Design.Generic", "AvoidMethodWithUnusedGenericTypeRule")]
public static void AssertNotRaises<T>(Action op, String msg = null,
[CallerLineNumber] int line = 0,
[CallerFilePath] string file = null,
[CallerMemberName] string member = null) where T: Exception
{
if (msg == null)
msg = "Exception raised.";
if (file == null)
file = "(unknown file)";
if (member == null)
member = "(unknown member)";
if (op == null)
throw new AssertionException($"Assertion failed: {file}:{line} ({member}) Null operation.");
try {
op();
} catch (T) {
throw new AssertionException($"Assertion failed: {file}:{line} ({member}) {msg}");
}
}
/// <summary> Asserts if the given reference is null.</summary>
public static void AssertNull(object reference, String msg = "Reference not null",
[CallerLineNumber] int line = 0,
[CallerFilePath] string file = null,
[CallerMemberName] string member = null)
{
if (reference != null)
throw new AssertionException($"Assertion failed: {file}:{line} ({member}) {msg}");
}
}

831
src/tests/efl_mono/Value.cs Normal file
View File

@ -0,0 +1,831 @@
#define CODE_ANALYSIS
#pragma warning disable 1591
using System;
using System.Diagnostics.CodeAnalysis;
namespace TestSuite {
[SuppressMessage("Gendarme.Rules.Portability", "DoNotHardcodePathsRule")]
public static class TestEinaValue {
public static void TestByteSimple()
{
using (eina.Value v = new eina.Value(eina.ValueType.Byte)) {
byte val = 0xff;
Test.Assert(v.Set(val));
byte x;
Test.Assert(v.Get(out x));
Test.AssertEquals(val, x);
}
}
public static void TestSByteSimple()
{
using (eina.Value v = new eina.Value(eina.ValueType.SByte)) {
sbyte val = -45;
Test.Assert(v.Set(val));
sbyte x;
Test.Assert(v.Get(out x));
Test.AssertEquals(val, x);
}
}
public static void TestShortSimple()
{
using (eina.Value v = new eina.Value(eina.ValueType.Short)) {
short val = -128;
Test.Assert(v.Set(val));
short x;
Test.Assert(v.Get(out x));
Test.AssertEquals(val, x);
}
}
public static void TestUShortSimple()
{
using (eina.Value v = new eina.Value(eina.ValueType.UShort)) {
ushort val = 0xff55;
Test.Assert(v.Set(val));
ushort x;
Test.Assert(v.Get(out x));
Test.AssertEquals(val, x);
}
}
public static void TestLongSimple()
{
using (eina.Value v = new eina.Value(eina.ValueType.Long)) {
long val = 0xdeadbeef;
Test.Assert(v.Set(val));
long x;
Test.Assert(v.Get(out x));
Test.AssertEquals(val, x);
}
}
public static void TestULongSimple()
{
using (eina.Value v = new eina.Value(eina.ValueType.ULong)) {
ulong val = 0xdeadbeef;
Test.Assert(v.Set(val));
ulong x;
Test.Assert(v.Get(out x));
Test.AssertEquals(val, x);
}
}
public static void TestFloatSimple()
{
using (eina.Value v = new eina.Value(eina.ValueType.Float)) {
float val = 1.609344f;
Test.Assert(v.Set(val));
float x;
Test.Assert(v.Get(out x));
Test.AssertAlmostEquals(val, x);
}
}
public static void TestDoubleSimple()
{
using (eina.Value v = new eina.Value(eina.ValueType.Double)) {
double val = 1.609344;
Test.Assert(v.Set(val));
double x;
Test.Assert(v.Get(out x));
Test.AssertAlmostEquals(val, x);
}
}
public static void TestIntSimple()
{
using (eina.Value v = new eina.Value(eina.ValueType.Int32)) {
Test.Assert(v.Set(32));
int x;
Test.Assert(v.Get(out x));
Test.AssertEquals(32, x);
Test.Assert(v.Set(-45));
Test.Assert(v.Get(out x));
Test.AssertEquals(-45, x);
}
}
public static void TestUIntSimple()
{
using (eina.Value v = new eina.Value(eina.ValueType.Int32)) {
Test.Assert(v.Set(0xdeadbeef));
uint x = 0;
Test.Assert(v.Get(out x));
Test.AssertEquals(0xdeadbeef, x);
}
}
public static void TestStringSimple()
{
using (eina.Value v = new eina.Value(eina.ValueType.String)) {
string expected_str = "Hello";
Test.Assert(v.Set(expected_str));
string str = null;
Test.Assert(v.Get(out str));
Test.AssertEquals(expected_str, str);
}
}
public static void TestSetWrongType()
{
using (eina.Value v = new eina.Value(eina.ValueType.String)) {
Test.AssertRaises<ArgumentException>(() => v.Set(42));
Test.AssertNotRaises<ArgumentException>(() => v.Set("Wumpus"));
Test.Assert(v.Setup(eina.ValueType.Int32));
Test.AssertRaises<ArgumentException>(() => v.Set("Wat?"));
Test.AssertNotRaises<ArgumentException>(() => v.Set(1984));
}
}
public static void TestValueSetup()
{
using (eina.Value v = new eina.Value(eina.ValueType.Int32)) {
Test.Assert(v.Set(44));
int x = 0;
Test.Assert(v.Get(out x));
Test.AssertEquals(44, x);
v.Setup(eina.ValueType.String);
string str = "Hello";
Test.Assert(v.Get(out str));
Test.AssertNull(str);
}
}
public static void TestValueDispose()
{
eina.Value v = new eina.Value(eina.ValueType.Int32);
v.Dispose();
Test.AssertRaises<ObjectDisposedException>(v.Flush);
Test.AssertRaises<ObjectDisposedException>(() => v.ToString());
Test.AssertRaises<ObjectDisposedException>(() => v.Set(24));
}
public static void TestValueFlush()
{
using (eina.Value v = new eina.Value(eina.ValueType.Int32)) {
Test.Assert(v.Set(44));
Test.Assert(!v.Flushed);
v.Flush();
Test.Assert(v.Flushed);
int x;
Test.AssertRaises<eina.ValueFlushedException>(() => v.Get(out x));
x = 42;
Test.AssertRaises<eina.ValueFlushedException>(() => v.Set(x));
v.Setup(eina.ValueType.String);
Test.AssertNotRaises<eina.ValueFlushedException>(() => v.Set("Hello, EFL"));
string y = String.Empty;
Test.AssertNotRaises<eina.ValueFlushedException>(() => v.Get(out y));
v.Flush();
Test.AssertRaises<eina.ValueFlushedException>(() => v.Get(out y));
v.Setup(eina.ValueType.Array, eina.ValueType.UInt32);
Test.AssertNotRaises<eina.ValueFlushedException>(() =>
v.Append(42));
v.Flush();
Test.AssertRaises<eina.ValueFlushedException>(() =>
v.Append(42));
Test.AssertRaises<eina.ValueFlushedException>(() => v.GetValueSubType());
}
}
private delegate bool BoolRet();
public static void TestValueOptionalInt()
{
using (eina.Value a = new eina.Value(eina.ValueType.Optional)) {
Test.Assert(a.Optional);
Test.Assert(a.Empty); // By default, optional values are empty
// Sets expectation
int expected = 1984;
Test.Assert(a.Set(expected));
Test.Assert(a.Optional);
Test.Assert(!a.Empty);
Test.Assert(a.Reset());
Test.Assert(a.Empty);
expected = -4891;
Test.Assert(a.Set(expected)); // Set() automatically infers the subtype from the argument.
Test.Assert(!a.Empty);
int actual = 0;
Test.Assert(a.Get(out actual));
Test.AssertEquals(expected, actual);
}
}
public static void TestValueOptionalUint()
{
using (eina.Value a = new eina.Value(eina.ValueType.Optional)) {
Test.Assert(a.Optional);
Test.Assert(a.Empty); // By default, optional values are empty
// Sets expectation
uint expected = 1984;
Test.Assert(a.Set(expected));
Test.Assert(a.Optional);
Test.Assert(!a.Empty);
Test.Assert(a.Reset());
Test.Assert(a.Empty);
expected = 0xdeadbeef;
Test.Assert(a.Set(expected));
Test.Assert(!a.Empty);
uint actual = 0;
Test.Assert(a.Get(out actual));
Test.AssertEquals(expected, actual);
}
}
public static void TestValueOptionalString()
{
using (eina.Value a = new eina.Value(eina.ValueType.Int32)) {
Test.Assert(!a.Optional);
BoolRet dummy = () => a.Empty;
Test.AssertRaises<eina.InvalidValueTypeException>(() => dummy());
}
using (eina.Value a = new eina.Value(eina.ValueType.Optional)) {
Test.Assert(a.Optional);
Test.Assert(a.Empty); // By default, optional values are empty
// Sets expectation
string expected = "Hello, world!";
Test.Assert(a.Set(expected));
Test.Assert(a.Optional);
Test.Assert(!a.Empty);
Test.Assert(a.Reset());
Test.Assert(a.Empty);
expected = "!dlrow olleH";
Test.Assert(a.Set(expected));
Test.Assert(!a.Empty);
string actual = String.Empty;
Test.Assert(a.Get(out actual));
Test.AssertEquals(expected, actual);
}
}
public static void TestValueOptionalArrays()
{
using (eina.Value a = new eina.Value(eina.ValueType.Optional))
using (eina.Value expected = new eina.Value(eina.ValueType.Array,
eina.ValueType.Int32))
{
Test.Assert(a.Optional);
Test.Assert(a.Empty); // By default, optional values are empty
// Sets expectation
Test.Assert(expected.Append(-1));
Test.Assert(expected.Append(0));
Test.Assert(expected.Append(2));
Test.Assert(a.Set(expected));
Test.Assert(a.Optional);
Test.Assert(!a.Empty);
Test.Assert(a.Reset());
Test.Assert(a.Empty);
expected.Append(-42);
Test.Assert(a.Set(expected));
Test.Assert(!a.Empty);
eina.Value actual = null;
Test.Assert(a.Get(out actual));
Test.AssertEquals(expected, actual);
Test.Assert(a.Reset());
Test.Assert(a.Set(expected));
}
}
public static void TestValueOptionalLists()
{
using (eina.Value a = new eina.Value(eina.ValueType.Optional))
using (eina.Value expected = new eina.Value(eina.ValueType.List,
eina.ValueType.Int32))
{
Test.Assert(a.Optional);
Test.Assert(a.Empty); // By default, optional values are empty
// Sets expectation
Test.Assert(expected.Append(-1));
Test.Assert(expected.Append(0));
Test.Assert(expected.Append(2));
Test.Assert(a.Set(expected));
Test.Assert(a.Optional);
Test.Assert(!a.Empty);
Test.Assert(a.Reset());
Test.Assert(a.Empty);
expected.Append(-42);
Test.Assert(a.Set(expected));
Test.Assert(!a.Empty);
eina.Value actual = null;
Test.Assert(a.Get(out actual));
Test.AssertEquals(expected, actual);
}
}
public static void TestValueCompareInts()
{
using (eina.Value a = new eina.Value(eina.ValueType.Int32))
using (eina.Value b = new eina.Value(eina.ValueType.Int32)) {
Test.Assert(a.Set(123));
Test.Assert(b.Set(123));
Test.AssertEquals(0, a.CompareTo(b));
Test.Assert(a.Set(-10));
Test.AssertLessThan(a, b);
Test.Assert(a.Set(123));
Test.Assert(b.Set(10));
Test.AssertGreaterThan(a, b);
}
}
public static void TestValueComparisonEquals()
{
using (eina.Value a = new eina.Value(eina.ValueType.Int32))
using (eina.Value b = new eina.Value(eina.ValueType.Int32))
using (eina.Value c = new eina.Value(eina.ValueType.Int32)) {
Test.Assert(a.Set(1));
Test.Assert(b.Set(1));
Test.Assert(c.Set(1));
Test.Assert(a.Equals(a), "A equals A");
Test.Assert(a.Equals(b) == b.Equals(a), "A equals B == B equals A");
Test.Assert(a.Equals(b) == b.Equals(c) == a.Equals(c));
Test.Assert(b.Set(0));
Test.Assert(a.Equals(b) == b.Equals(a), "A equals B == B equals A");
Test.Assert(a.Equals(null) == false, "A == null");
}
}
public static void TestValueComparisonOverloadEquals()
{
using (eina.Value a = new eina.Value(eina.ValueType.Int32))
using (eina.Value b = new eina.Value(eina.ValueType.Int32)) {
Test.Assert(a.Set(1));
Test.Assert(b.Set(1));
Test.Assert(a == b);
Test.Assert(!(a != b));
Test.Assert(b == a);
Test.Assert(!(b != a));
Test.Assert(b.Set(42));
Test.Assert(a != b);
Test.Assert(!(a == b));
Test.Assert(b != a);
Test.Assert(!(b == a));
Test.Assert(b.Set(42));
}
}
public static void TestValueComparisonOverloadLessMore()
{
using (eina.Value a = new eina.Value(eina.ValueType.Int32))
using (eina.Value b = new eina.Value(eina.ValueType.Int32)) {
Test.Assert(a.Set(1));
Test.Assert(b.Set(0));
Test.Assert(a > b);
Test.Assert(!(a < b));
Test.Assert(b < a);
Test.Assert(!(b > a));
}
}
public static void TestValueCompareStrings()
{
using (eina.Value a = new eina.Value(eina.ValueType.String))
using (eina.Value b = new eina.Value(eina.ValueType.String)) {
Test.Assert(a.Set("aaa"));
Test.Assert(b.Set("aaa"));
Test.AssertEquals(0, a.CompareTo(b));
Test.Assert(a.Set("abc"));
Test.Assert(b.Set("acd"));
Test.AssertLessThan(a, b);
Test.Assert(a.Set("acd"));
Test.Assert(b.Set("abc"));
Test.AssertGreaterThan(a, b);
}
}
public static void TestValueCompareArray()
{
using(eina.Value a = new eina.Value(eina.ValueType.Array, eina.ValueType.Int32))
using(eina.Value b = new eina.Value(eina.ValueType.Array, eina.ValueType.Int32)) {
Test.AssertEquals(a, b);
Test.Assert(a.Append(0));
Test.Assert(a.Append(1));
Test.Assert(a.Append(5));
Test.Assert(a.Append(42));
Test.Assert(b.Append(0));
Test.Assert(b.Append(1));
Test.Assert(b.Append(5));
Test.Assert(b.Append(42));
Test.AssertEquals(a, b);
a[0] = -1;
Test.Assert(!a.Equals(b));
Test.AssertLessThan(a, b);
a[0] = 10;
Test.AssertGreaterThan(a, b);
a[0] = 0;
Test.AssertEquals(a, b);
// bigger arrays are greater
Test.Assert(b.Append(0));
Test.AssertLessThan(a, b);
Test.Assert(a.Append(0));
Test.Assert(a.Append(0));
Test.AssertGreaterThan(a, b);
// bigger arrays are greater, unless an element says other wise
b[0] = 10;
Test.AssertGreaterThan(b, a);
}
}
public static void TestValueCompareList()
{
using(eina.Value a = new eina.Value(eina.ValueType.List, eina.ValueType.Int32))
using(eina.Value b = new eina.Value(eina.ValueType.List, eina.ValueType.Int32)) {
Test.AssertEquals(a, b);
Test.Assert(a.Append(0));
Test.Assert(a.Append(1));
Test.Assert(a.Append(5));
Test.Assert(a.Append(42));
Test.Assert(b.Append(0));
Test.Assert(b.Append(1));
Test.Assert(b.Append(5));
Test.Assert(b.Append(42));
Test.AssertEquals(a, b);
a[0] = -1;
Test.Assert(!a.Equals(b));
Test.AssertLessThan(a, b);
a[0] = 10;
Test.AssertGreaterThan(a, b);
a[0] = 0;
Test.AssertEquals(a, b);
// bigger arrays are greater
Test.Assert(b.Append(0));
Test.AssertLessThan(a, b);
Test.Assert(a.Append(0));
Test.Assert(a.Append(0));
Test.AssertGreaterThan(a, b);
// bigger arrays are greater, unless an element says other wise
b[0] = 10;
Test.AssertGreaterThan(b, a);
}
}
/* public static void TestValueCompareHash() */
/* { */
/* Test.Assert(false, "Implement me."); */
/* } */
public static void TestValueToString()
{
using(eina.Value a = new eina.Value(eina.ValueType.Int32)) {
int i = -12345;
string x = $"{i}";
Test.Assert(a.Set(i));
Test.AssertEquals(x, a.ToString());
uint u = 0xdeadbeef;
x = $"{u}";
Test.Assert(a.Setup(eina.ValueType.UInt32));
Test.Assert(a.Set(u));
Test.AssertEquals(x, a.ToString());
string s = "Hello, Johnny!";
x = s;
Test.Assert(a.Setup(eina.ValueType.String));
Test.Assert(a.Set(s));
Test.AssertEquals(x, a.ToString());
}
}
public static void TestValueConvertInt()
{
using(eina.Value from = new eina.Value(eina.ValueType.Int32))
using(eina.Value to = new eina.Value(eina.ValueType.UInt32)) {
int source = 0x7FFFFFFF;
uint target_uint;
int target_int;
string target_str;
string source_str = $"{source}";
Test.Assert(from.Set(source));
Test.Assert(from.ConvertTo(to));
Test.Assert(to.Get(out target_uint));
Test.AssertEquals(target_uint, (uint)source);
Test.Assert(to.Setup(eina.ValueType.Int32));
Test.Assert(from.ConvertTo(to));
Test.Assert(to.Get(out target_int));
Test.AssertEquals(target_int, source);
Test.Assert(to.Setup(eina.ValueType.String));
Test.Assert(from.ConvertTo(to));
Test.Assert(to.Get(out target_str));
Test.AssertEquals(target_str, source_str);
// FIXME Add tests for failing ConvertTo() calls when downcasting
// to smaller types
}
}
public static void TestValueConvertUInt()
{
using(eina.Value from = new eina.Value(eina.ValueType.UInt32))
using(eina.Value to = new eina.Value(eina.ValueType.UInt32)) {
uint source = 0xFFFFFFFF;
uint target_uint;
string target_str;
string source_str = $"{source}";
Test.Assert(from.Set(source));
Test.Assert(from.ConvertTo(to));
Test.Assert(to.Get(out target_uint));
Test.AssertEquals(target_uint, source);
Test.Assert(to.Setup(eina.ValueType.Int32));
Test.Assert(!from.ConvertTo(to));
Test.Assert(to.Setup(eina.ValueType.String));
Test.Assert(from.ConvertTo(to));
Test.Assert(to.Get(out target_str));
Test.AssertEquals(target_str, source_str);
// FIXME Add tests for failing ConvertTo() calls when downcasting
// to smaller types
}
}
public static void TestValueContainerConstructorWrongArgs()
{
Test.AssertRaises<ArgumentException>(() => {
using(eina.Value array = new eina.Value(eina.ValueType.String, eina.ValueType.String)) { }
});
}
public static void TestValueContainerWithNonContainerAccess()
{
using(eina.Value array = new eina.Value(eina.ValueType.Int32)) {
Test.AssertRaises<eina.InvalidValueTypeException>(() => array[0] = 1);
object val = null;
Test.AssertRaises<eina.InvalidValueTypeException>(() => val = array[0]);
}
}
public static void TestValueArray() {
using(eina.Value array = new eina.Value(eina.ValueType.Array, eina.ValueType.Int32)) {
Test.AssertEquals(0, array.Count());
Test.Assert(array.Append(0));
Test.AssertEquals(1, array.Count());
Test.Assert(array.Append(1));
Test.AssertEquals(2, array.Count());
Test.Assert(array.Append(5));
Test.AssertEquals(3, array.Count());
Test.Assert(array.Append(42));
Test.AssertEquals(4, array.Count());
Test.AssertEquals((int)array[0], 0);
Test.AssertEquals((int)array[1], 1);
Test.AssertEquals((int)array[2], 5);
Test.AssertEquals((int)array[3], 42);
array[0] = 1984;
array[1] = -42;
Test.AssertEquals(4, array.Count());
Test.AssertEquals((int)array[0], 1984);
Test.AssertEquals((int)array[1], -42);
Test.AssertEquals((int)array[2], 5);
Test.AssertEquals((int)array[3], 42);
Test.AssertEquals("[1984, -42, 5, 42]", array.ToString());
}
using(eina.Value array = new eina.Value(eina.ValueType.Array, eina.ValueType.UInt32)) {
Test.Assert(array.Append(2));
Test.AssertEquals((uint)array[0], (uint)2);
Test.AssertRaises<OverflowException>(() => array[0] = -1);
}
using(eina.Value array = new eina.Value(eina.ValueType.Array, eina.ValueType.String)) {
Test.Assert(array.Append("hello"));
Test.Assert(array.Append("world"));
Test.AssertEquals((string)array[0], "hello");
Test.AssertEquals((string)array[1], "world");
array[0] = "efl";
array[1] = "rocks";
Test.AssertEquals((string)array[0], "efl");
Test.AssertEquals((string)array[1], "rocks");
}
}
public static void TestArrayOutOfBounds() {
using(eina.Value array = new eina.Value(eina.ValueType.Array, eina.ValueType.Int32)) {
object placeholder = null;
Test.AssertRaises<System.ArgumentOutOfRangeException>(() => array[0] = 1);
Test.AssertRaises<System.ArgumentOutOfRangeException>(() => placeholder = array[0]);
Test.Assert(array.Append(0));
Test.AssertNotRaises<System.ArgumentOutOfRangeException>(() => array[0] = 1);
Test.AssertNotRaises<System.ArgumentOutOfRangeException>(() => placeholder = array[0]);
Test.AssertRaises<System.ArgumentOutOfRangeException>(() => array[1] = 1);
Test.AssertRaises<System.ArgumentOutOfRangeException>(() => placeholder = array[1]);
Test.Assert(array.Append(0));
Test.AssertNotRaises<System.ArgumentOutOfRangeException>(() => array[1] = 1);
Test.AssertNotRaises<System.ArgumentOutOfRangeException>(() => placeholder = array[1]);
}
}
public static void TestValueArraySubType() {
using(eina.Value array = new eina.Value(eina.ValueType.Array, eina.ValueType.Int32))
Test.AssertEquals(eina.ValueType.Int32, array.GetValueSubType());
using(eina.Value array = new eina.Value(eina.ValueType.Array, eina.ValueType.UInt32))
Test.AssertEquals(eina.ValueType.UInt32, array.GetValueSubType());
}
public static void TestValueArrayConvert() {
using(eina.Value array = new eina.Value(eina.ValueType.Array, eina.ValueType.Int32))
using(eina.Value other = new eina.Value(eina.ValueType.Int32)) {
other.Set(100);
other.ConvertTo(array);
Test.AssertEquals(100, (int)array[0]);
Test.AssertEquals("[100]", array.ToString());
}
}
public static void TestValueList() {
using(eina.Value list = new eina.Value(eina.ValueType.List, eina.ValueType.Int32)) {
Test.AssertEquals(0, list.Count());
Test.Assert(list.Append(0));
Test.AssertEquals(1, list.Count());
Test.Assert(list.Append(1));
Test.AssertEquals(2, list.Count());
Test.Assert(list.Append(5));
Test.AssertEquals(3, list.Count());
Test.Assert(list.Append(42));
Test.AssertEquals(4, list.Count());
Test.AssertEquals((int)list[0], 0);
Test.AssertEquals((int)list[1], 1);
Test.AssertEquals((int)list[2], 5);
Test.AssertEquals((int)list[3], 42);
list[0] = 1984;
list[1] = -42;
Test.AssertEquals(4, list.Count());
Test.AssertEquals((int)list[0], 1984);
Test.AssertEquals((int)list[1], -42);
Test.AssertEquals((int)list[2], 5);
Test.AssertEquals((int)list[3], 42);
Test.AssertEquals("[1984, -42, 5, 42]", list.ToString());
}
using(eina.Value list = new eina.Value(eina.ValueType.List, eina.ValueType.UInt32)) {
Test.Assert(list.Append(2));
Test.AssertEquals((uint)list[0], (uint)2);
Test.AssertRaises<OverflowException>(() => list[0] = -1);
}
using(eina.Value list = new eina.Value(eina.ValueType.List, eina.ValueType.String)) {
Test.Assert(list.Append("hello"));
Test.Assert(list.Append("world"));
Test.AssertEquals((string)list[0], "hello");
Test.AssertEquals((string)list[1], "world");
list[0] = "efl";
list[1] = "rocks";
Test.AssertEquals((string)list[0], "efl");
Test.AssertEquals((string)list[1], "rocks");
}
}
public static void TestListOutOfBounds() {
using(eina.Value list = new eina.Value(eina.ValueType.List, eina.ValueType.Int32)) {
object placeholder = null;
Test.AssertRaises<System.ArgumentOutOfRangeException>(() => list[0] = 1);
Test.AssertRaises<System.ArgumentOutOfRangeException>(() => placeholder = list[0]);
Test.Assert(list.Append(0));
Test.AssertNotRaises<System.ArgumentOutOfRangeException>(() => list[0] = 1);
Test.AssertNotRaises<System.ArgumentOutOfRangeException>(() => placeholder = list[0]);
Test.AssertRaises<System.ArgumentOutOfRangeException>(() => list[1] = 1);
Test.AssertRaises<System.ArgumentOutOfRangeException>(() => placeholder = list[1]);
Test.Assert(list.Append(0));
Test.AssertNotRaises<System.ArgumentOutOfRangeException>(() => list[1] = 1);
Test.AssertNotRaises<System.ArgumentOutOfRangeException>(() => placeholder = list[1]);
}
}
public static void TestValueListSubType() {
using(eina.Value list = new eina.Value(eina.ValueType.List, eina.ValueType.Int32))
Test.AssertEquals(eina.ValueType.Int32, list.GetValueSubType());
using(eina.Value list = new eina.Value(eina.ValueType.List, eina.ValueType.UInt32))
Test.AssertEquals(eina.ValueType.UInt32, list.GetValueSubType());
}
public static void TestValueListConvert() {
using(eina.Value list = new eina.Value(eina.ValueType.List, eina.ValueType.Int32))
using(eina.Value other = new eina.Value(eina.ValueType.Int32)) {
other.Set(100);
other.ConvertTo(list);
Test.AssertEquals(100, (int)list[0]);
Test.AssertEquals("[100]", list.ToString());
}
}
// FIXME Add remaining list tests
/* public static void TestValueHash() { */
/* Test.Assert(false, "Implement me."); */
/* } */
/* public static void TestValueTimeVal() { */
/* Test.Assert(false, "Implement me."); */
/* } */
/* public static void TestValueBlob() { */
/* Test.Assert(false, "Implement me."); */
/* } */
/* public static void TestValueStruct() { */
/* Test.Assert(false, "Implement me."); */
/* } */
/* public static void TestValueArrayOfStructs() { */
/* Test.Assert(false, "Implement me."); */
/* } */
/* public static void TestValueOptionalStructMembers() { */
/* Test.Assert(false, "Implement me."); */
/* } */
}
#pragma warning restore 1591
}

View File

@ -0,0 +1,115 @@
#define CODE_ANALYSIS
// Disable warning about missing docs when generating docs
#pragma warning disable 1591
using System;
namespace TestSuite {
public static class TestEinaValueEolian {
public static void TestEolianEinaValueInReturn()
{
test.Testing obj = new test.TestingConcrete();
using (eina.Value v = new eina.Value(eina.ValueType.Int32)) {
v.Set(42);
obj.SetValuePtr(v);
Test.AssertEquals(eina.ValueOwnership.Managed, v.Ownership);
eina.Value v_received = obj.GetValuePtrOwn();
Test.AssertEquals(eina.ValueOwnership.Managed, v_received.Ownership);
Test.AssertEquals(v, v_received);
v_received.Dispose();
}
}
public static void TestEolianEinaValueInOwn()
{
test.Testing obj = new test.TestingConcrete();
using (eina.Value v = new eina.Value(eina.ValueType.Int32)) {
v.Set(2001);
Test.AssertEquals(eina.ValueOwnership.Managed, v.Ownership);
obj.SetValuePtrOwn(v);
Test.AssertEquals(eina.ValueOwnership.Unmanaged, v.Ownership);
eina.Value v_received = obj.GetValuePtr();
Test.AssertEquals(eina.ValueOwnership.Unmanaged, v_received.Ownership);
Test.AssertEquals(v, v_received);
obj.ClearValue();
}
}
public static void TestEolianEinaValueOut()
{
test.Testing obj = new test.TestingConcrete();
using (eina.Value v = new eina.Value(eina.ValueType.String)) {
eina.Value v_out = null;
v.Set("hello!");
obj.SetValuePtr(v);
obj.OutValuePtr(out v_out);
Test.AssertEquals(v, v_out);
Test.AssertEquals(eina.ValueOwnership.Unmanaged, v_out.Ownership);
}
}
public static void TestEolianEinaValueOutOwn()
{
test.Testing obj = new test.TestingConcrete();
using (eina.Value v = new eina.Value(eina.ValueType.String)) {
eina.Value v_out = null;
v.Set("hello!");
obj.SetValuePtr(v);
obj.OutValuePtrOwn(out v_out);
Test.AssertEquals(v, v_out);
Test.AssertEquals(eina.ValueOwnership.Managed, v_out.Ownership);
}
}
public static void TestEolianEinaValueInReturnByValue()
{
test.Testing obj = new test.TestingConcrete();
using (eina.Value v = new eina.Value(eina.ValueType.Int32)) {
v.Set(42);
obj.SetValue(v);
Test.AssertEquals(eina.ValueOwnership.Managed, v.Ownership);
// Using get_value_ptr while get_value() is not supported.
eina.Value v_received = obj.GetValuePtrOwn();
Test.AssertEquals(eina.ValueOwnership.Managed, v_received.Ownership);
Test.AssertEquals(v, v_received);
v_received.Dispose();
}
}
public static void TestEolianEinaValueOutByValue()
{
test.Testing obj = new test.TestingConcrete();
using (eina.Value v = new eina.Value(eina.ValueType.String)) {
eina.Value v_out = null;
v.Set("hello!");
obj.SetValue(v);
obj.OutValue(out v_out);
Test.AssertEquals(v, v_out);
Test.AssertEquals(eina.ValueOwnership.Managed, v_out.Ownership);
}
}
}
#pragma warning restore 1591
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,5 @@
#!/bin/sh
echo $LD_LIBRARY_PATH
EINA_LOG_LEVEL=8 MONO_LOG_LEVEL=debug $MONO $MONO_BUILDPATH/src/tests/efl_mono/efl_mono.exe$EXEEXT

View File

@ -0,0 +1,13 @@
class Test.Numberwrapper (Efl.Object) {
methods {
@property number {
get {
}
set {
}
values {
n: int;
}
}
}
}

File diff suppressed because it is too large Load Diff