public static void test_async_reject() { efl.ILoop loop = efl.App.GetLoopMain(); test.ITesting obj = new test.Testing(); Task <eina.Value> task = obj.GetFutureAsync(); eina.Error sentError = 1337; obj.RejectPromise(sentError); loop.Iterate(); bool raised = false; try { eina.Value v = task.Result; } catch (AggregateException ae) { raised = true; ae.Handle((x) => { Test.Assert(x is efl.FutureException, "AggregateException must have been TaskCanceledException"); efl.FutureException ex = x as efl.FutureException; Test.AssertEquals(ex.Error, sentError); return(true); }); } Test.Assert(raised, "AggregateException must have been raised."); }
public static void test_simple_reject() { bool callbackCalled = false; eina.Error received_error = eina.Error.NO_ERROR; efl.ILoop loop = efl.App.GetLoopMain(); eina.Promise promise = new eina.Promise(); eina.Future future = new eina.Future(promise); future = future.Then((eina.Value value) => { callbackCalled = true; value.Get(out received_error); return(value); }); promise.Reject(eina.Error.EPERM); loop.Iterate(); Test.Assert(callbackCalled, "Future callback should have been called."); Test.AssertEquals(received_error, eina.Error.EPERM); Test.AssertRaises <ObjectDisposedException>(() => { promise.Resolve(null); }); Test.AssertRaises <ObjectDisposedException>(future.Cancel); }
public static void test_object_promise_cancel() { efl.ILoop loop = efl.App.GetLoopMain(); test.Testing obj = new test.Testing(); eina.Future future = obj.GetFuture(); bool callbackCalled = false; eina.Error receivedError = -1; eina.Error sentError = 120; future.Then((eina.Value value) => { callbackCalled = true; Test.AssertEquals(value.GetValueType(), eina.ValueType.Error); value.Get(out receivedError); return(value); }); obj.RejectPromise(sentError); loop.Iterate(); Test.Assert(callbackCalled, "Future callback must have been called."); Test.AssertEquals(receivedError, sentError); }
/// <summary>Construct a new exception from the eina.Error stored in the given eina.Value.</summary> public FutureException(eina.Value value) : base("Future failed.") { if (value.GetValueType() != eina.ValueType.Error) { throw new ArgumentException("FutureException must receive an eina.Value with eina.Error."); } eina.Error err; value.Get(out err); Error = err; }
public static void TestErrorSimple() { using (eina.Value v = new eina.Value(eina.ValueType.Error)) { eina.Error error = new eina.Error(eina.Error.NO_ERROR); Test.Assert(v.Set(error)); eina.Error x; Test.Assert(v.Get(out x)); Test.AssertEquals(error, x); } }
public static void event_with_error_payload() { test.ITesting obj = new test.Testing(); eina.Error received_error = 0; obj.EvtWithErrorEvt += (object sender, EvtWithErrorEvt_Args e) => { received_error = e.arg; }; eina.Error sent_error = -2001; obj.EmitEventWithError(sent_error); Test.AssertEquals(sent_error, received_error); }
public static void eina_error_return_from_inherited_virtual() { test.ITesting 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); }
// return eina_error public static void eina_error_return() { test.ITesting obj = new test.Testing(); 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); }
public static void test_simple_future_cancel() { bool callbackCalled = false; bool promiseCallbackCalled = false; eina.Error received_error = eina.Error.NO_ERROR; eina.Promise promise = new eina.Promise(() => { promiseCallbackCalled = true; }); eina.Future future = new eina.Future(promise); future = future.Then((eina.Value value) => { callbackCalled = true; value.Get(out received_error); return(value); }); future.Cancel(); Test.Assert(promiseCallbackCalled, "Promise cancel callback should have been called."); Test.Assert(callbackCalled, "Future callback should have been called."); Test.AssertEquals(received_error, eina.Error.ECANCELED); }
internal static extern void eina_promise_reject(IntPtr scheduler, eina.Error reason);
/// <summary> /// Rejects a promise. /// /// The future chain attached to this promise will be called with an eina.Value of type /// eina.ValueType.Error and payload eina.Error.ECANCELED. /// </summary> public void Reject(eina.Error reason) { SanityChecks(); eina_promise_reject(this.Handle, reason); this.Handle = IntPtr.Zero; }
public override void SetErrorRet(eina.Error err) { code = 2 * err; }