2017-11-23 16:53:28 -08:00
|
|
|
using System;
|
|
|
|
|
|
|
|
namespace TestSuite
|
|
|
|
{
|
|
|
|
|
|
|
|
class TestEoEvents
|
|
|
|
{
|
|
|
|
public bool called = false;
|
2017-12-06 16:03:55 -08:00
|
|
|
public bool correct_sender = false;
|
2017-11-23 16:53:28 -08:00
|
|
|
protected void callback(object sender, EventArgs e) {
|
|
|
|
called = true;
|
2017-12-06 16:03:55 -08:00
|
|
|
efl.Object obj = sender as efl.Object;
|
|
|
|
if (obj != null)
|
|
|
|
{
|
|
|
|
obj.SetName("loop_called");
|
|
|
|
correct_sender = true;
|
|
|
|
}
|
2017-11-23 16:53:28 -08:00
|
|
|
}
|
|
|
|
protected void another_callback(object sender, EventArgs e) { }
|
|
|
|
|
|
|
|
public static void callback_add_event()
|
|
|
|
{
|
|
|
|
efl.Loop loop = new efl.LoopConcrete();
|
2017-12-06 16:03:55 -08:00
|
|
|
loop.SetName("loop");
|
2017-11-23 16:53:28 -08:00
|
|
|
TestEoEvents listener = new TestEoEvents();
|
2018-04-16 08:36:51 -07:00
|
|
|
loop.CallbackAddEvt += listener.callback;
|
2017-11-23 16:53:28 -08:00
|
|
|
|
|
|
|
Test.Assert(!listener.called);
|
2017-12-06 16:03:55 -08:00
|
|
|
Test.Assert(!listener.correct_sender);
|
|
|
|
Test.AssertEquals("loop", loop.GetName());
|
2018-04-16 08:36:51 -07:00
|
|
|
loop.IdleEvt += listener.another_callback;
|
2017-11-23 16:53:28 -08:00
|
|
|
Test.Assert(listener.called);
|
2017-12-06 16:03:55 -08:00
|
|
|
Test.Assert(listener.correct_sender);
|
|
|
|
Test.AssertEquals("loop_called", loop.GetName());
|
2017-11-23 16:53:28 -08:00
|
|
|
}
|
2018-01-22 09:56:38 -08:00
|
|
|
|
|
|
|
public static void event_with_string_payload()
|
|
|
|
{
|
|
|
|
test.Testing obj = new test.TestingConcrete();
|
|
|
|
string received_string = null;
|
|
|
|
|
2018-04-16 08:36:51 -07:00
|
|
|
obj.EvtWithStringEvt += (object sender, test.EvtWithStringEvt_Args e) => {
|
2018-01-22 09:56:38 -08:00
|
|
|
received_string = e.arg;
|
|
|
|
};
|
|
|
|
|
|
|
|
obj.EmitEventWithString("Some args");
|
|
|
|
|
|
|
|
Test.AssertEquals("Some args", received_string);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void event_with_int_payload()
|
|
|
|
{
|
|
|
|
test.Testing obj = new test.TestingConcrete();
|
|
|
|
int received_int= 0;
|
|
|
|
|
2018-04-16 08:36:51 -07:00
|
|
|
obj.EvtWithIntEvt += (object sender, test.EvtWithIntEvt_Args e) => {
|
2018-01-22 09:56:38 -08:00
|
|
|
received_int = e.arg;
|
|
|
|
};
|
|
|
|
|
|
|
|
obj.EmitEventWithInt(-1984);
|
|
|
|
|
|
|
|
Test.AssertEquals(-1984, received_int);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void event_with_uint_payload()
|
|
|
|
{
|
|
|
|
test.Testing obj = new test.TestingConcrete();
|
|
|
|
uint received_uint = 0;
|
2018-04-16 08:36:51 -07:00
|
|
|
obj.EvtWithUintEvt += (object sender, test.EvtWithUintEvt_Args e) => {
|
2018-01-22 09:56:38 -08:00
|
|
|
received_uint = e.arg;
|
|
|
|
};
|
|
|
|
|
|
|
|
obj.EmitEventWithUint(0xbeef);
|
|
|
|
|
|
|
|
Test.AssertEquals<uint>(0xbeef, received_uint);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void event_with_float_payload()
|
|
|
|
{
|
|
|
|
test.Testing obj = new test.TestingConcrete();
|
|
|
|
float received_float= 0;
|
|
|
|
|
2018-04-16 08:36:51 -07:00
|
|
|
obj.EvtWithFloatEvt += (object sender, test.EvtWithFloatEvt_Args e) => {
|
2018-01-22 09:56:38 -08:00
|
|
|
received_float = e.arg;
|
|
|
|
};
|
|
|
|
|
|
|
|
obj.EmitEventWithFloat(3.14f);
|
|
|
|
|
|
|
|
Test.AssertEquals(3.14f, received_float);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void event_with_object_payload()
|
|
|
|
{
|
|
|
|
test.Testing obj = new test.TestingConcrete();
|
|
|
|
test.Testing received_obj = null;
|
|
|
|
|
2018-04-16 08:36:51 -07:00
|
|
|
obj.EvtWithObjEvt += (object sender, test.EvtWithObjEvt_Args e) => {
|
2018-01-22 09:56:38 -08:00
|
|
|
received_obj = e.arg;
|
|
|
|
};
|
|
|
|
|
|
|
|
test.Testing sent_obj = new test.TestingConcrete();
|
|
|
|
|
|
|
|
obj.EmitEventWithObj(sent_obj);
|
|
|
|
|
|
|
|
Test.AssertEquals(sent_obj, received_obj);
|
|
|
|
}
|
2017-11-23 16:53:28 -08:00
|
|
|
}
|
|
|
|
}
|