Esempio n. 1
0
        public static void TestValueOptionalArrays()
        {
            using (Eina.Value a = new Eina.Value(Eina.ValueType.Optional))
                using (Eina.Value expected = new Eina.Value(Eina.ValueType.Array,
                                                            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);

                    Test.Assert(a.Reset());
                    Test.Assert(a.Set(expected));
                }
        }
Esempio n. 2
0
        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);
            }
        }
Esempio n. 3
0
        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();
            }
        }
Esempio n. 4
0
        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);
            }
        }
Esempio n. 5
0
        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);
            }
        }