public static void test_add_remove_event() { test.ITesting obj = new test.Testing(); bool called = true; EventHandler <test.Testing.EvtWithIntEvt_Args> evtCb = (object sender, EvtWithIntEvt_Args e) => { called = true; }; obj.EvtWithIntEvt += evtCb; obj.EmitEventWithInt(42); Test.Assert(called); called = false; obj.EvtWithIntEvt -= evtCb; obj.EmitEventWithInt(42); Test.Assert(!called); }
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 test.ITesting obj = new test.Testing(); Listener listener = new Listener(); obj.EvtWithIntEvt += listener.callback; Test.AssertRaises <efl.EflException>(() => { obj.EmitEventWithInt(2); }); }
public static void event_with_int_payload() { test.ITesting obj = new test.Testing(); int received_int = 0; obj.EvtWithIntEvt += (object sender, EvtWithIntEvt_Args e) => { received_int = e.arg; }; obj.EmitEventWithInt(-1984); Test.AssertEquals(-1984, received_int); }
public static void event_in_init_callback() { int received = 0; int sent = 42; test.ITesting obj = new test.Testing(null, (test.ITesting t) => { t.EvtWithIntEvt += (object sender, EvtWithIntEvt_Args e) => { received = e.arg; }; }); obj.EmitEventWithInt(sent); Test.AssertEquals(sent, received); }