/// <summary>Set a property value of a given property name. /// The caller must ensure to call at least efl_model_prop_list before being able to see/set properties. This function sets a new property value into given property name. Once the operation is completed the concrete implementation should raise <see cref="Efl.IModel.PropertiesChangedEvt"/> event in order to notify listeners of the new value of the property. /// /// If the model doesn't have the property then there are two possibilities, either raise an error or create the new property in model /// /// See <see cref="Efl.IModel.GetProperty"/>, <see cref="Efl.IModel.PropertiesChangedEvt"/></summary> /// <param name="property">Property name</param> /// <param name="value">Property value</param> /// <returns>Return an error in case the property could not be set, the value that was set otherwise.</returns> virtual public Eina.Future SetProperty(System.String property, Eina.Value value) { var _ret_var = Efl.IModelConcrete.NativeMethods.efl_model_property_set_ptr.Value.Delegate((IsGeneratedBindingClass ? this.NativeHandle : Efl.Eo.Globals.efl_super(this.NativeHandle, this.NativeClass)), property, value); Eina.Error.RaiseIfUnhandledException(); return(_ret_var); }
public static async Task Consume(Efl.Loop loop) { Task <Eina.Value> task = loop.IdleAsync(); Eina.Value v = await task; loop.Quit(v); }
/// <summary>A generic configuration value, referred to by name.</summary> /// <param name="name">Configuration option name.</param> /// <param name="value">Configuration option value. May be <c>null</c> if not found.</param> /// <returns><c>false</c> in case of error: value type was invalid, the config can't be changed, config does not exist...</returns> virtual public bool SetConfig(System.String name, Eina.Value value) { var _ret_var = Efl.IConfigNativeInherit.efl_config_set_ptr.Value.Delegate((inherited ? Efl.Eo.Globals.efl_super(this.NativeHandle, this.NativeClass) : this.NativeHandle), name, value); Eina.Error.RaiseIfUnhandledException(); return(_ret_var); }
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_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 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_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."); }
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_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(); }
private static Eina.Value config_get(System.IntPtr obj, System.IntPtr pd, System.String name) { Eina.Log.Debug("function efl_config_get was called"); Efl.Eo.IWrapper wrapper = Efl.Eo.Globals.PrivateDataGet(pd); if (wrapper != null) { Eina.Value _ret_var = default(Eina.Value); try { _ret_var = ((IConfig)wrapper).GetConfig(name); } catch (Exception e) { Eina.Log.Warning($"Callback error: {e.ToString()}"); Eina.Error.Set(Eina.Error.UNHANDLED_EXCEPTION); } return(_ret_var); } else { return(efl_config_get_ptr.Value.Delegate(Efl.Eo.Globals.efl_super(obj, Efl.Eo.Globals.efl_class_get(obj)), name)); } }
private static Eina.Value property_get(System.IntPtr obj, System.IntPtr pd, System.String property) { Eina.Log.Debug("function efl_model_property_get was called"); var ws = Efl.Eo.Globals.GetWrapperSupervisor(obj); if (ws != null) { Eina.Value _ret_var = default(Eina.Value); try { _ret_var = ((MonoModelInternalChild)ws.Target).GetProperty(property); } catch (Exception e) { Eina.Log.Warning($"Callback error: {e.ToString()}"); Eina.Error.Set(Eina.Error.UNHANDLED_EXCEPTION); } return(_ret_var); } else { return(efl_model_property_get_ptr.Value.Delegate(Efl.Eo.Globals.efl_super(obj, Efl.Eo.Globals.efl_class_get(obj)), property)); } }
public static void TestValueArrayOfSByte() { using (Eina.Value array = new Eina.Value(Eina.ValueType.Array, Eina.ValueType.SByte)) { 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((sbyte)array[0], 0); Test.AssertEquals((sbyte)array[1], 1); Test.AssertEquals((sbyte)array[2], 5); Test.AssertEquals((sbyte)array[3], 42); array[0] = 120; array[1] = -42; Test.AssertEquals(4, array.Count()); Test.AssertEquals((sbyte)array[0], 120); Test.AssertEquals((sbyte)array[1], -42); Test.AssertEquals((sbyte)array[2], 5); Test.AssertEquals((sbyte)array[3], 42); Test.AssertEquals("[120, -42, 5, 42]", array.ToString()); } }
private static Eina.Value config_get(System.IntPtr obj, System.IntPtr pd, System.String name) { Eina.Log.Debug("function efl_gesture_recognizer_config_get was called"); var ws = Efl.Eo.Globals.GetWrapperSupervisor(obj); if (ws != null) { Eina.Value _ret_var = default(Eina.Value); try { _ret_var = ((GestureRecognizer)ws.Target).GetConfig(name); } catch (Exception e) { Eina.Log.Warning($"Callback error: {e.ToString()}"); Eina.Error.Set(Eina.Error.UNHANDLED_EXCEPTION); } return(_ret_var); } else { return(efl_gesture_recognizer_config_get_ptr.Value.Delegate(Efl.Eo.Globals.efl_super(obj, Efl.Eo.Globals.efl_class_get(obj)), name)); } }
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.OptionalEmpty); // 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.OptionalEmpty); Test.Assert(a.Reset()); Test.Assert(a.OptionalEmpty); expected.Append(-42); Test.Assert(a.Set(expected)); Test.Assert(!a.OptionalEmpty); Eina.Value actual = null; Test.Assert(a.Get(out actual)); Test.AssertEquals(expected, actual); } }
public static void TestValueDispose() { Eina.Value v = new Eina.Value(Eina.ValueType.Int32); v.Dispose(); Test.AssertRaises <ObjectDisposedException>(() => v.ToString()); Test.AssertRaises <ObjectDisposedException>(() => v.Set(24)); }
public static void TestValueOptionalString() { using (Eina.Value a = new Eina.Value(Eina.ValueType.Int32)) { Test.Assert(!a.Optional); BoolRet dummy = () => a.OptionalEmpty; Test.AssertRaises <Eina.InvalidValueTypeException>(() => dummy()); } using (Eina.Value a = new Eina.Value(Eina.ValueType.Optional)) { Test.Assert(a.Optional); Test.Assert(a.OptionalEmpty); // By default, optional values are empty // Sets expectation string expected = "Hello, world!"; Test.Assert(a.Set(expected)); Test.Assert(a.Optional); Test.Assert(!a.OptionalEmpty); Test.Assert(a.Reset()); Test.Assert(a.OptionalEmpty); expected = "!dlrow olleH"; Test.Assert(a.Set(expected)); Test.Assert(!a.OptionalEmpty); string actual = String.Empty; Test.Assert(a.Get(out actual)); Test.AssertEquals(expected, actual); } }
internal Eina.Future ManagedCb(Efl.ViewModel view_model, System.String property, Eina.Value value) { var _ret_var = _cb(_cb_data, view_model, property, value); Eina.Error.RaiseIfUnhandledException(); return(_ret_var); }
public static void TestValueOptionalObject() { using (Eina.Value a = new Eina.Value(Eina.ValueType.Object)) { Test.Assert(!a.Optional); BoolRet dummy = () => a.OptionalEmpty; Test.AssertRaises <Eina.InvalidValueTypeException>(() => dummy()); } using (Eina.Value a = new Eina.Value(Eina.ValueType.Optional)) { Test.Assert(a.Optional); Test.Assert(a.OptionalEmpty); // By default, optional values are empty // Sets expectation Efl.Object expected = new Dummy.TestObject(); Test.Assert(a.Set(expected)); Test.Assert(a.Optional); Test.Assert(!a.OptionalEmpty); Test.Assert(a.Reset()); Test.Assert(a.OptionalEmpty); Test.Assert(a.Set(expected)); Test.Assert(!a.OptionalEmpty); Efl.Object received = null; Test.Assert(a.Get(out received)); Test.AssertEquals(expected, received); received.Dispose(); expected.Dispose(); } }
private static Eina.Future future_resolved(System.IntPtr obj, System.IntPtr pd, Eina.ValueNative result) { Eina.Log.Debug("function efl_loop_future_resolved was called"); var ws = Efl.Eo.Globals.GetWrapperSupervisor(obj); if (ws != null) { var _in_result = new Eina.Value(result); Eina.Future _ret_var = default(Eina.Future); try { _ret_var = ((LoopConsumer)ws.Target).FutureResolved(_in_result); } catch (Exception e) { Eina.Log.Warning($"Callback error: {e.ToString()}"); Eina.Error.Set(Eina.Error.UNHANDLED_EXCEPTION); } return(_ret_var); } else { return(efl_loop_future_resolved_ptr.Value.Delegate(Efl.Eo.Globals.efl_super(obj, Efl.Eo.Globals.efl_class_get(obj)), result)); } }
/// <summary>A generic configuration value, referred to by name.</summary> /// <param name="name">Configuration option name.</param> /// <param name="value">Configuration option value. May be <c>null</c> if not found.</param> /// <returns><c>false</c> in case of error: value type was invalid, the config can't be changed, config does not exist...</returns> public bool SetConfig(System.String name, Eina.Value value) { var _ret_var = Efl.IConfigConcrete.NativeMethods.efl_config_set_ptr.Value.Delegate(this.NativeHandle, name, value); Eina.Error.RaiseIfUnhandledException(); return(_ret_var); }
public static void TestValueArrayOfInt64s() { using (Eina.Value array = new Eina.Value(Eina.ValueType.Array, Eina.ValueType.Int64)) { Test.AssertEquals(0, array.Count()); Test.Assert(array.Append(0)); Test.AssertEquals(1, array.Count()); Test.Assert(array.Append(10000000000)); 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((long)array[0], 0); Test.AssertEquals((long)array[1], 10000000000); Test.AssertEquals((long)array[2], 5); Test.AssertEquals((long)array[3], 42); array[0] = 1984; array[1] = -42; Test.AssertEquals(4, array.Count()); Test.AssertEquals((long)array[0], 1984); Test.AssertEquals((long)array[1], -42); Test.AssertEquals((long)array[2], 5); Test.AssertEquals((long)array[3], 42); Test.AssertEquals("[1984, -42, 5, 42]", array.ToString()); } }
public static void TestValueArrayOfByte() { using (Eina.Value array = new Eina.Value(Eina.ValueType.Array, Eina.ValueType.Byte)) { 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((byte)array[0], 0); Test.AssertEquals((byte)array[1], 1); Test.AssertEquals((byte)array[2], 5); Test.AssertEquals((byte)array[3], 42); array[0] = 155; array[1] = 42; Test.AssertEquals(4, array.Count()); Test.AssertEquals((byte)array[0], 155); Test.AssertEquals((byte)array[1], 42); Test.AssertEquals((byte)array[2], 5); Test.AssertEquals((byte)array[3], 42); Test.AssertEquals("[155, 42, 5, 42]", array.ToString()); Test.AssertRaises <OverflowException>(() => array[0] = 123214); } }
/// <summary>Set a property value of a given property name. /// The caller must ensure to call at least efl_model_prop_list before being able to see/set properties. This function sets a new property value into given property name. Once the operation is completed the concrete implementation should raise <see cref="Efl.Model.PropertiesChangedEvt"/> event in order to notify listeners of the new value of the property. /// /// If the model doesn't have the property then there are two possibilities, either raise an error or create the new property in model /// /// See <see cref="Efl.Model.GetProperty"/>, <see cref="Efl.Model.PropertiesChangedEvt"/> /// 1.14</summary> /// <param name="property">Property name</param> /// <param name="value">Property value</param> /// <returns>Return an error in case the property could not be set, the value that was set otherwise.</returns> virtual public Eina.Future SetProperty(System.String property, Eina.Value value) { var _ret_var = Efl.ModelNativeInherit.efl_model_property_set_ptr.Value.Delegate((inherited ? Efl.Eo.Globals.efl_super(this.NativeHandle, this.NativeClass) : this.NativeHandle), property, value); Eina.Error.RaiseIfUnhandledException(); return(_ret_var); }
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 } }
/// <summary>A generic configuration value, referred to by name.</summary> /// <param name="name">Configuration option name.</param> /// <param name="value">Configuration option value. May be <c>null</c> if not found.</param> /// <returns><c>false</c> in case of error: value type was invalid, the config can't be changed, config does not exist...</returns> virtual public bool SetConfig(System.String name, Eina.Value value) { var _ret_var = Efl.IConfigConcrete.NativeMethods.efl_config_set_ptr.Value.Delegate((IsGeneratedBindingClass ? this.NativeHandle : Efl.Eo.Globals.efl_super(this.NativeHandle, this.NativeClass)), name, value); Eina.Error.RaiseIfUnhandledException(); return(_ret_var); }
public static void func_pointer_marshalling() { var obj = new Dummy.TestObject(); bool called = false; Eina.Strbuf buf = new Eina.Strbuf(); string argument = "Some String"; Eina.Value v = new Eina.Value(Eina.ValueType.String); v.Set(argument); string reference = new string(argument.ToCharArray().Reverse().ToArray()); obj.CallFormatCb(buf, v, (Eina.Strbuf ibuf, Eina.Value val) => { called = true; string str = null; val.Get(out str); buf.Append(new string(str.ToCharArray().Reverse().ToArray())); }); Test.Assert(called, "Callback was not called"); Test.AssertEquals(reference, buf.Steal()); v.Dispose(); buf.Dispose(); obj.Dispose(); }
public static void TestConversionFromToObject() { var source = new Holder { Number = 1984, Factor = 3.14, Name = "Orwell", Obj = new Dummy.TestObject(), }; { var prop = source.GetType().GetProperty("Name"); var v = new Eina.Value(prop.GetValue(source)); Test.AssertEquals(v.GetValueType(), Eina.ValueType.String); Test.AssertEquals((string)v, prop.GetValue(source)); Test.Assert(v.Set("New value")); prop.SetValue(source, v.Unwrap()); Test.AssertEquals(prop.GetValue(source), "New value"); } { var prop = source.GetType().GetProperty("Factor"); var v = new Eina.Value(prop.GetValue(source)); Test.AssertEquals(v.GetValueType(), Eina.ValueType.Double); Test.AssertAlmostEquals((double)v, (double)prop.GetValue(source)); Test.Assert(v.Set(2.78)); prop.SetValue(source, v.Unwrap()); Test.AssertEquals(prop.GetValue(source), 2.78); } { var prop = source.GetType().GetProperty("Number"); var v = new Eina.Value(prop.GetValue(source)); Test.AssertEquals(v.GetValueType(), Eina.ValueType.Int32); Test.AssertEquals((int)v, prop.GetValue(source)); Test.Assert(v.Set(2012)); prop.SetValue(source, v.Unwrap()); Test.AssertEquals(prop.GetValue(source), 2012); } { var prop = source.GetType().GetProperty("Obj"); var v = new Eina.Value(prop.GetValue(source)); Test.AssertEquals(v.GetValueType(), Eina.ValueType.Object); Test.AssertEquals((Efl.Object)v, prop.GetValue(source)); var newObj = new Dummy.TestObject(); Test.Assert(v.Set(newObj)); prop.SetValue(source, v.Unwrap()); Test.AssertEquals(prop.GetValue(source), newObj); newObj.Dispose(); } }
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 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 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]); } }