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 } }
public static void TestIntSimple() { using (Eina.Value v = new Eina.Value(Eina.ValueType.Int32)) { Test.Assert(v.Set(32)); int x; Test.Assert(v.Get(out x)); Test.AssertEquals(32, x); Test.Assert(v.Set(-45)); Test.Assert(v.Get(out x)); Test.AssertEquals(-45, x); } }
public static void TestValueSetup() { using (Eina.Value v = new Eina.Value(Eina.ValueType.Int32)) { Test.Assert(v.Set(44)); int x = 0; Test.Assert(v.Get(out x)); Test.AssertEquals(44, x); v.Setup(Eina.ValueType.String); string str = "Hello"; Test.Assert(v.Get(out str)); Test.AssertNull(str); } }
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 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); } }
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(); } }
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 TestUIntSimple() { using (Eina.Value v = new Eina.Value(Eina.ValueType.Int32)) { Test.Assert(v.Set(0xdeadbeef)); uint x = 0; Test.Assert(v.Get(out x)); Test.AssertEquals(0xdeadbeef, x); } }
public static void TestSByteSimple() { using (Eina.Value v = new Eina.Value(Eina.ValueType.SByte)) { sbyte val = -45; Test.Assert(v.Set(val)); sbyte x; Test.Assert(v.Get(out x)); Test.AssertEquals(val, x); } }
public static void TestULongSimple() { using (Eina.Value v = new Eina.Value(Eina.ValueType.ULong)) { ulong val = 0xdeadbeef; Test.Assert(v.Set(val)); ulong x; Test.Assert(v.Get(out x)); Test.AssertEquals(val, x); } }
public static void TestFloatSimple() { using (Eina.Value v = new Eina.Value(Eina.ValueType.Float)) { float val = 1.609344f; Test.Assert(v.Set(val)); float x; Test.Assert(v.Get(out x)); Test.AssertAlmostEquals(val, x); } }
public static void TestStringSimple() { using (Eina.Value v = new Eina.Value(Eina.ValueType.String)) { string expected_str = "Hello"; Test.Assert(v.Set(expected_str)); string str = null; Test.Assert(v.Get(out str)); Test.AssertEquals(expected_str, str); } }
public static void TestByteSimple() { using (Eina.Value v = new Eina.Value(Eina.ValueType.Byte)) { byte val = 0xff; Test.Assert(v.Set(val)); byte x; Test.Assert(v.Get(out x)); Test.AssertEquals(val, x); } }
public static void TestDoubleSimple() { using (Eina.Value v = new Eina.Value(Eina.ValueType.Double)) { double val = 1.609344; Test.Assert(v.Set(val)); double x; Test.Assert(v.Get(out x)); Test.AssertAlmostEquals(val, x); } }
public static void TestShortSimple() { using (Eina.Value v = new Eina.Value(Eina.ValueType.Short)) { short val = -128; Test.Assert(v.Set(val)); short x; Test.Assert(v.Get(out x)); Test.AssertEquals(val, x); } }
public static void TestUShortSimple() { using (Eina.Value v = new Eina.Value(Eina.ValueType.UShort)) { ushort val = 0xff55; Test.Assert(v.Set(val)); ushort x; Test.Assert(v.Get(out x)); Test.AssertEquals(val, x); } }
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 TestObjectSimple() { using (Eina.Value v = new Eina.Value(Eina.ValueType.Object)) { var obj = new Dummy.TestObject(); Test.Assert(v.Set(obj)); Efl.Object target; Test.Assert(v.Get(out target)); Test.AssertEquals(target, obj); } }
public static void Formatter(Eina.Strbuf buf, Eina.Value val) { double ratio; if (val.Get(out ratio)) { buf.Append($"{(int)(ratio*100)}%"); } else { buf.Append("Error"); } }
public static void TestValueCopy() { Eina.Value v2 = null; int raw_val = 42; using (Eina.Value v = new Eina.Value(Eina.ValueType.Int32)) { Test.Assert(v.Set(raw_val)); v2 = new Eina.Value(v); } int rec_val; Test.Assert(v2.Get(out rec_val)); Test.AssertEquals(raw_val, rec_val); }
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); }
public static void TestValueOptionalUint() { 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 uint expected = 1984; Test.Assert(a.Set(expected)); Test.Assert(a.Optional); Test.Assert(!a.OptionalEmpty); Test.Assert(a.Reset()); Test.Assert(a.OptionalEmpty); expected = 0xdeadbeef; Test.Assert(a.Set(expected)); Test.Assert(!a.OptionalEmpty); uint actual = 0; Test.Assert(a.Get(out actual)); Test.AssertEquals(expected, actual); } }
public static void TestValueOptionalInt() { 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 int expected = 1984; Test.Assert(a.Set(expected)); Test.Assert(a.Optional); Test.Assert(!a.OptionalEmpty); Test.Assert(a.Reset()); Test.Assert(a.OptionalEmpty); expected = -4891; Test.Assert(a.Set(expected)); // Set() automatically infers the subtype from the argument. Test.Assert(!a.OptionalEmpty); int actual = 0; Test.Assert(a.Get(out actual)); Test.AssertEquals(expected, actual); } }