public static void test_async_cancel() { Efl.Loop loop = Efl.App.AppMain; var obj = new Dummy.TestObject(); CancellationTokenSource cancelSrc = new CancellationTokenSource(); Task <Eina.Value> task = obj.GetFutureAsync(cancelSrc.Token); cancelSrc.Cancel(); loop.Iterate(); bool raised = false; try { Eina.Value v = task.Result; } catch (AggregateException ae) { raised = true; ae.Handle((x) => { Test.Assert(x is TaskCanceledException, "AggregateException must have been TaskCanceledException"); return(true); }); } Test.Assert(raised, "AggregateException must have been raised."); }
private static Efl.Loop loop_get(System.IntPtr obj, System.IntPtr pd) { Eina.Log.Debug("function efl_loop_get was called"); var ws = Efl.Eo.Globals.GetWrapperSupervisor(obj); if (ws != null) { Efl.Loop _ret_var = default(Efl.Loop); try { _ret_var = ((LoopConsumer)ws.Target).GetLoop(); } catch (Exception e) { Eina.Log.Warning($"Callback error: {e.ToString()}"); Eina.Error.Set(Eina.Error.UNHANDLED_EXCEPTION); } return(_ret_var); } else { return(efl_loop_get_ptr.Value.Delegate(Efl.Eo.Globals.efl_super(obj, Efl.Eo.Globals.efl_class_get(obj)))); } }
public static void test_simple_resolve() { bool callbackCalled = false; Eina.Value received_value = null; Efl.Loop loop = Efl.App.AppMain; Eina.Promise promise = new Eina.Promise(); Eina.Future future = new Eina.Future(promise); future = future.Then((Eina.Value value) => { callbackCalled = true; received_value = value; return(value); }); Eina.Value reference_value = new Eina.Value(Eina.ValueType.Int32); reference_value.Set(1984); promise.Resolve(reference_value); loop.Iterate(); Test.Assert(callbackCalled, "Future callback should have been called."); Test.AssertEquals(received_value, reference_value); }
public static void test_constructor_with_callback() { bool callbackCalled = false; Eina.Value received_value = null; Efl.Loop loop = Efl.App.AppMain; Eina.Promise promise = new Eina.Promise(); #pragma warning disable 0219 Eina.Future future = new Eina.Future(promise, (Eina.Value value) => { callbackCalled = true; received_value = value; return(value); }); #pragma warning restore 0219 Eina.Value reference_value = new Eina.Value(Eina.ValueType.Int32); reference_value.Set(1984); promise.Resolve(reference_value); loop.Iterate(); Test.Assert(callbackCalled, "Future callback should have been called."); Test.AssertEquals(received_value, reference_value); }
public static void test_simple_with_object() { bool callbackCalled = false; Eina.Value receivedValue = null; Efl.Loop loop = Efl.App.AppMain; Eina.Promise promise = new Eina.Promise(); Eina.Future future = new Eina.Future(promise); future = future.Then((Eina.Value value) => { callbackCalled = true; receivedValue = new Eina.Value(value); return(value); }); Eina.Value referenceValue = new Eina.Value(Eina.ValueType.Array, Eina.ValueType.Int32); referenceValue.Append(32); var tmp = new Eina.Value(referenceValue); promise.Resolve(tmp); loop.Iterate(); Test.Assert(callbackCalled, "Future callback should have been called."); Test.AssertEquals(receivedValue, referenceValue); tmp.Dispose(); referenceValue.Dispose(); promise.Dispose(); }
public static void test_object_promise() { Efl.Loop loop = Efl.App.AppMain; var obj = new Dummy.TestObject(); Eina.Future future = obj.GetFuture(); bool callbackCalled = false; int receivedValue = -1; int sentValue = 1984; future.Then((Eina.Value value) => { callbackCalled = true; Test.AssertEquals(value.GetValueType(), Eina.ValueType.Int32); value.Get(out receivedValue); return(value); }); obj.FulfillPromise(sentValue); loop.Iterate(); Test.Assert(callbackCalled, "Future callback must have been called."); Test.AssertEquals(receivedValue, sentValue); }
public static void test_object_promise_cancel() { Efl.Loop loop = Efl.App.AppMain; var obj = new Dummy.TestObject(); 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); }
public static void test_simple_task_run() { Efl.Loop loop = Efl.App.AppMain; Eina.Future future = loop.Idle(); bool callbackCalled = false; int ret_code = 1992; future.Then((Eina.Value value) => { callbackCalled = true; Eina.Value v = new Eina.Value(Eina.ValueType.Int32); v.Set(ret_code); loop.Quit(v); return(value); }); Eina.Value ret_value = loop.Begin(); Test.Assert(callbackCalled, "Future loop callback must have been called."); Test.AssertEquals(ret_value.GetValueType(), Eina.ValueType.Int32); int ret_from_value; Test.Assert(ret_value.Get(out ret_from_value)); Test.AssertEquals(ret_from_value, ret_code); }
public static async Task Consume(Efl.Loop loop) { Task <Eina.Value> task = loop.IdleAsync(); Eina.Value v = await task; loop.Quit(v); }
public static void test_simple_reject() { bool callbackCalled = false; Eina.Error received_error = Eina.Error.NO_ERROR; Efl.Loop loop = Efl.App.AppMain; 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_async_reject() { Efl.Loop loop = Efl.App.AppMain; var obj = new Dummy.TestObject(); 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_async() { Efl.Loop loop = Efl.App.AppMain; Task t = LoopConsumer.Consume(loop); loop.Begin(); Test.Assert(t.Wait(1000), "Task should have been completed in time."); }
public static void reflection_test() { Efl.Loop loop = Efl.App.AppMain; var model = CreateModel(loop); model.Dispose(); }
public static void easy_model_extraction() { Efl.Loop loop = Efl.App.AppMain; Task task = EasyModelExtractionAsync(loop); loop.Begin(); task.Wait(); }
public static void test_then_chain_array() { bool[] callbacksCalled = { false, false, false, false }; Eina.Value[] received_value = { null, null, null, null }; FutureCbGenerator genResolvedCb = (int i) => { return((Eina.Value value) => { callbacksCalled[i] = true; int x; value.Get(out x); value.Set(x + i); received_value[i] = value; return value; }); }; var cbs = new List <Eina.Future.ResolvedCb>(); for (int i = 0; i < 4; i++) { cbs.Add(genResolvedCb(i)); } Efl.Loop loop = Efl.App.AppMain; Eina.Promise promise = new Eina.Promise(); Eina.Future future = new Eina.Future(promise); future = future.Chain(cbs); Eina.Value reference_value = new Eina.Value(Eina.ValueType.Int32); reference_value.Set(0); promise.Resolve(reference_value); loop.Iterate(); int current_value = 0; for (int i = 0; i < 4; i++) { current_value += i; Test.Assert(callbacksCalled[i], $"Future chained callback {i} should have been called."); int received; received_value[i].Get(out received); Test.AssertEquals(received, current_value); } Test.AssertRaises <ObjectDisposedException>(() => { promise.Resolve(null); }); Test.AssertRaises <ObjectDisposedException>(future.Cancel); reference_value.Dispose(); promise.Dispose(); }
private static Efl.UserModel <VeggieViewModel> CreateModel(Efl.Loop loop) { Efl.UserModel <VeggieViewModel> veggies = new Efl.UserModel <VeggieViewModel>(loop); veggies.Add(new VeggieViewModel { Name = "Tomato", Type = "Fruit", Image = "tomato.png" }); veggies.Add(new VeggieViewModel { Name = "Romaine Lettuce", Type = "Vegetable", Image = "lettuce.png" }); veggies.Add(new VeggieViewModel { Name = "Zucchini", Type = "Vegetable", Image = "zucchini.png" }); return(veggies); }
public static void idle_event() { Efl.Loop loop = Efl.App.AppMain; loop.SetName("loop"); TestEoEvents listener = new TestEoEvents(); listener.loop = loop; loop.IdleEvt += listener.callback; Test.Assert(!listener.called); Test.Assert(!listener.correct_sender); Test.AssertEquals("loop", loop.GetName()); loop.Begin(); Test.Assert(listener.called); Test.Assert(listener.correct_sender); Test.AssertEquals("loop_called", loop.GetName()); }
internal static async Task EasyModelExtractionAsync(Efl.Loop loop) { var veggies = CreateModel(loop); var model = new Efl.GenericModel <VeggieViewModel>(veggies, loop); Test.AssertEquals(3, (int)model.GetChildrenCount()); VeggieViewModel r2 = await model.GetAtAsync(1); Test.AssertEquals(r2.Name, "Romaine Lettuce"); VeggieViewModel r = await model.GetAtAsync(0); Test.AssertEquals(r.Name, "Tomato"); loop.End(); }
static void Main(string[] args) { Efl.All.Init(); String border_path = "./src/examples/evas/resources/images/red.png"; if (args.Length >= 1) { border_path = args[0]; } Efl.Loop loop = new Efl.Loop(); TestMain t = new TestMain(border_path); loop.Begin(); Efl.All.Shutdown(); }
static void Main(string[] args) { Efl.All.Init(); var loop = new Efl.Loop(); var timer = new Efl.LoopTimer(loop, 1.0); TestMain listener = new TestMain(loop); Console.WriteLine("Starting MainLoop"); timer.TimerTickEvent += listener.on_tick; timer.TimerTickEvent += listener.another_callback; timer.TimerTickEvent -= listener.another_callback; loop.Begin(); Efl.All.Shutdown(); }
static void Main(string[] args) { Efl.All.Init(); Efl.Loop loop = new Efl.Loop(); EcoreEvas ecore_evas = new EcoreEvas(); Efl.Canvas.Object canvas = ecore_evas.canvas; canvas.SetVisible(true); Efl.Object parent = canvas.GetParent(); System.Diagnostics.Debug.Assert(parent.NativeHandle != IntPtr.Zero); Evas.Box box = new MyBox(canvas); Eina.Size2D size = new Eina.Size2D(); size.W = 320; size.H = 240; box.SetSize(size); box.SetVisible(true); Efl.Canvas.Rectangle rect = new Efl.Canvas.Rectangle(canvas); rect.SetColor(0, 0, 255, 255); size.W = 320; size.H = 120; rect.SetSize(size); rect.SetVisible(true); box.Append(rect); Efl.Canvas.Rectangle rect2 = new Efl.Canvas.Rectangle(canvas); rect2.SetColor(0, 255, 0, 255); rect2.SetSize(size); rect2.SetVisible(true); box.Append(rect2); loop.Begin(); Efl.All.Shutdown(); }
public static void test_async_fulfill() { Efl.Loop loop = Efl.App.AppMain; var obj = new Dummy.TestObject(); Task <Eina.Value> task = obj.GetFutureAsync(); int sentValue = 1337; obj.FulfillPromise(sentValue); loop.Iterate(); Eina.Value v = task.Result; Test.AssertEquals(v.GetValueType(), Eina.ValueType.Int32); int receivedValue; v.Get(out receivedValue); Test.AssertEquals(receivedValue, sentValue); }
/// <summary> /// Creates a new Promise with the given callback. /// /// Currently, creating a promise directly uses the Main Loop scheduler the source of notifications (i.e. the /// future callbacks will be called mainly from a loop iteration). /// </summary> public Promise(CancelCb cancelCb = null) { Efl.Loop loop = Efl.App.AppMain; // Should we be able to pass different schedulers? IntPtr scheduler = efl_loop_future_scheduler_get(loop.NativeHandle); IntPtr cb_data = IntPtr.Zero; // A safety clean callback to mark this wrapper as invalid CancelCb safetyCb = () => { Handle = IntPtr.Zero; if (cancelCb != null) { cancelCb(); } }; CleanupHandle = GCHandle.Alloc(safetyCb); cb_data = GCHandle.ToIntPtr(CleanupHandle); this.Handle = eina_promise_new(scheduler, NativeCancelCb, cb_data); }
static void Main(string[] args) { int color_index = 0; Efl.All.Init(); Efl.Loop loop = new Efl.Loop(); EcoreEvas ecore_evas = new EcoreEvas(); Efl.Canvas.Object canvas = ecore_evas.canvas; canvas.SetVisible(true); Efl.Object parent = canvas.GetParent(); System.Diagnostics.Debug.Assert(parent.NativeHandle != IntPtr.Zero); Efl.Canvas.Rectangle rect = new Efl.Canvas.Rectangle(canvas); rect.SetColor(colors[0, 0], colors[0, 1], colors[0, 2], 255); Eina.Size2D size = new Eina.Size2D(); size.W = 640; size.H = 480; rect.SetSize(size); rect.SetVisible(true); canvas.KeyDownEvt += (object sender, Efl.Input.InterfaceKeyDownEvt_Args e) => { color_index = (color_index + 1) % 3; Console.WriteLine("Key Down"); Console.WriteLine("Got key obj at {0}", e.arg.NativeHandle.ToString("X")); Console.WriteLine("Got key_get() == [{0}]", e.arg.GetKey()); rect.SetColor(colors[color_index, 0], colors[color_index, 1], colors[color_index, 2], 255); }; loop.Begin(); Efl.All.Shutdown(); }
static void Main(string[] args) { Efl.All.Init(); Efl.Loop loop = new Efl.Loop(); EcoreEvas ecore_evas = new EcoreEvas(); Eina.Size2D size = new Eina.Size2D(); Efl.Canvas.Object canvas = ecore_evas.canvas; canvas.SetVisible(true); Efl.Object parent = canvas.GetParent(); System.Diagnostics.Debug.Assert(parent.NativeHandle != IntPtr.Zero); Efl.Canvas.Rectangle bg = new Efl.Canvas.Rectangle(canvas); bg.SetColor(255, 255, 255, 255); size.W = WIDTH; size.H = HEIGHT; bg.SetSize(size); bg.SetVisible(true); string valid_path = args[0]; Evas.Image image = new Evas.Image(canvas); image.SetFile(valid_path, null); /* FIXME evas-image uses error handling code from * evas_object_image_load_error_get, which seems to be not available * Efl.image.load.State state = image.load_error_get(); */ // FIXME missing move Eina.Rect rect = new Eina.Rect(); rect.X = 0; rect.Y = 0; rect.W = WIDTH / 2; rect.H = HEIGHT / 2; image.SetFill(rect); size.W = WIDTH / 2; size.H = HEIGHT / 2; image.SetSize(size); image.SetVisible(true); rect = image.GetFill(); rect.Y -= 50; rect.W += 100; image.SetFill(rect); TestMain listener = new TestMain(image); // TODO handle key events in order to alter the image like the C // example. Meanwhile, just set some w fill /* EventListener callback = new EventListener(); */ /* bg.key_focus_set(true); */ /* bg.event_callback_priority_add(Evas.Callback_Type.Key_down, */ /* Efl.Callback_Priority.Default, */ /* callback, null); */ loop.Begin(); Efl.All.Shutdown(); }
static void Main(string[] args) { Efl.All.Init(); Efl.Loop loop = new Efl.Loop(); EcoreEvas ecore_evas = new EcoreEvas(); Eina.Size2D size = new Eina.Size2D(); Eina.Position2D pos = new Eina.Position2D(); Efl.Canvas.Object canvas = ecore_evas.canvas; canvas.SetVisible(true); Efl.Canvas.Rectangle bg = new Efl.Canvas.Rectangle(canvas); bg.SetColor(255, 255, 255, 255); pos.X = 0; pos.Y = 0; bg.SetPosition(pos); size.W = WIDTH; size.H = HEIGHT; bg.SetSize(size); bg.SetVisible(true); string path = args[0]; Evas.Image logo = new Evas.Image(canvas); logo.SetFillAuto(true); // TODO add preloaded support (depends on events) logo.SetFile(path, null); size.W = WIDTH / 2; size.H = HEIGHT / 2; logo.SetSize(size); // TODO add a bunch of key/mouse handlers logo.SetVisible(true); int[] pixels = new int[(WIDTH / 4) * (HEIGHT / 4)]; System.Random generator = new System.Random(); for (int i = 0; i < pixels.Length; i++) { pixels[i] = generator.Next(); } Evas.Image noise_img = new Evas.Image(canvas); size.W = WIDTH / 4; size.H = HEIGHT / 4; noise_img.SetSize(size); // FIXME Add a way to set the pixels. // noise_img.data_set(pixels); noise_img.SetFillAuto(true); pos.X = WIDTH * 5 / 8; pos.Y = HEIGHT / 8; noise_img.SetPosition(pos); noise_img.SetVisible(true); Console.WriteLine("Creating noise image with sizez %d, %d", WIDTH / 4, HEIGHT / 4); Efl.Canvas.Proxy proxy_img = new Efl.Canvas.Proxy(canvas); proxy_img.SetSource(noise_img); pos.X = WIDTH / 2; pos.Y = HEIGHT / 2; proxy_img.SetPosition(pos); size.W = WIDTH / 2; size.H = HEIGHT / 2; proxy_img.SetSize(size); proxy_img.SetVisible(true); loop.Begin(); }
public static void reflection_test() { Efl.Loop loop = Efl.App.AppMain; var veggies = CreateModel(loop); }
static void Main(string[] args) { Efl.All.Init(); Efl.Loop loop = new Efl.Loop(); EcoreEvas ecore_evas = new EcoreEvas(); Eina.Size2D size = new Eina.Size2D(); size.W = WIDTH; size.H = HEIGHT; Eina.Size2D hint = new Eina.Size2D(); Efl.Canvas.Object canvas = ecore_evas.canvas; canvas.SetVisible(true); Efl.Object parent = canvas.GetParent(); System.Diagnostics.Debug.Assert(parent.NativeHandle != IntPtr.Zero); Efl.Canvas.Rectangle bg = new Efl.Canvas.Rectangle(canvas); bg.SetColor(255, 255, 255, 255); bg.SetSize(size); bg.SetVisible(true); Evas.Table table = new Evas.Table(canvas); table.SetHomogeneous(Evas.ObjectTable.HomogeneousMode.None); table.SetPadding(0, 0); table.SetSize(size); table.SetVisible(true); Efl.Canvas.Rectangle rect = new Efl.Canvas.Rectangle(canvas); rect.SetColor(255, 0, 0, 255); hint.W = 100; hint.H = 50; rect.SetHintMin(hint); rect.SetVisible(true); table.Pack(rect, 1, 1, 2, 1); rect = new Efl.Canvas.Rectangle(canvas); rect.SetColor(0, 255, 0, 255); hint.W = 50; hint.H = 100; rect.SetHintMin(hint); rect.SetVisible(true); table.Pack(rect, 1, 2, 1, 2); rect = new Efl.Canvas.Rectangle(canvas); rect.SetColor(0, 0, 255, 255); hint.W = 50; hint.H = 50; rect.SetHintMin(hint); rect.SetVisible(true); table.Pack(rect, 2, 2, 1, 1); rect = new Efl.Canvas.Rectangle(canvas); rect.SetColor(255, 255, 0, 255); rect.SetHintMin(hint); rect.SetVisible(true); table.Pack(rect, 2, 3, 1, 1); loop.Begin(); Efl.All.Shutdown(); }
public TestMain(Efl.Loop loop) { this.loop = loop; this.count = 0; }