Beispiel #1
0
        public void TestRegister4()
        {
            // this should register successfully
            var testEnum4GType = typeof(TestEnum4).GetGType();

            Assert.That(testEnum4GType, Is.Not.EqualTo(GType.Invalid),
                        "Failed to register an enum");

            // make sure the type is not re-registed.
            Assert.That(testEnum4GType, Is.EqualTo(typeof(TestEnum4).GetGType()));

            // a couple more GType checks
            Assert.That((Type)testEnum4GType, Is.EqualTo(typeof(TestEnum4)));
            Assert.That(testEnum4GType.IsA(GType.Enum), Is.True);

            // make sure that we set the typename, value name and value nick
            Assert.That(testEnum4GType.Name, Is.EqualTo("GISharp-Core-Test-GObject-EnumTests+TestEnum4"));
            using (var enum4TypeClass = (EnumClass)TypeClass.Get(testEnum4GType)) {
                var value = GISharp.GObject.Enum.GetValue(enum4TypeClass, 1);
                Assert.That(value.Value, Is.EqualTo((int)TestEnum4.One));
                var valueName = GMarshal.Utf8PtrToString(value.ValueName);
                Assert.That(valueName, Is.EqualTo("One"));
                var valueNick = GMarshal.Utf8PtrToString(value.ValueNick);
                Assert.That(valueNick, Is.EqualTo("One"));
            }

            Utility.AssertNoGLibLog();
        }
Beispiel #2
0
        public void TestPropertyComponentModelAttributes()
        {
            // check that ComponentModel attributes map to ParamSpec
            using (var baseObj = new TestObjectPropertiesBase())
                using (var baseObjClass = (ObjectClass)TypeClass.Get(baseObj.GetGType()))
                    using (var basePspec = baseObjClass.FindProperty("bool-value")) {
                        Assert.That(basePspec.Name, Is.EqualTo(TestObjectPropertiesBase.BoolValuePropertyName));
                        Assert.That(basePspec.Nick, Is.EqualTo(TestObjectPropertiesBase.BoolValuePropertyNick));
                        Assert.That(basePspec.Blurb, Is.EqualTo(TestObjectPropertiesBase.BoolValuePropertyBlurb));
                        Assert.That(basePspec.DefaultValue.Get(),
                                    Is.EqualTo(TestObjectPropertiesBase.BoolValuePropertyDefaultValue));
                    }

            // The subclass will inherit the values of the parent class.
            // If the subclass tries to declare an attribute again, it will
            // be ignored as is the case with DefaultValueAttribute here.
            using (var subObj = new TestObjectPropertiesSubclass())
                using (var subObjClass = (ObjectClass)TypeClass.Get(subObj.GetGType()))
                    using (var subPspec = subObjClass.FindProperty("bool-value")) {
                        Assert.That(subPspec.Name, Is.EqualTo(TestObjectPropertiesBase.BoolValuePropertyName));
                        Assert.That(subPspec.Nick, Is.EqualTo(TestObjectPropertiesBase.BoolValuePropertyNick));
                        Assert.That(subPspec.Blurb, Is.EqualTo(TestObjectPropertiesBase.BoolValuePropertyBlurb));
                        Assert.That(subPspec.DefaultValue.Get(),
                                    Is.EqualTo(TestObjectPropertiesBase.BoolValuePropertyDefaultValue));
                    }

            Utility.AssertNoGLibLog();
        }
Beispiel #3
0
        public void TestRegister1()
        {
            // invalid because TestEnum1 does not have [GType] attribute so it
            // gets registered as a boxed type instead of as an enum type.
            var testEnum1GType = typeof(TestEnum1).GetGType();

            Assert.That(() => (EnumClass)TypeClass.Get(testEnum1GType),
                        Throws.ArgumentException);

            Utility.AssertNoGLibLog();
        }
Beispiel #4
0
        public void TestSubclassPropertyOverride()
        {
            using (var obj = new TestObjectPropertiesSubclass()) {
                // the new keyword does not override a property, just hides it...

                Assume.That(obj.IntValue, Is.EqualTo(0));
                obj.SetProperty(nameof(obj.IntValue), 1);
                Assert.That(obj.IntValue, Is.EqualTo(1));

                Assert.That(((TestObjectPropertiesBase)obj).IntValue, Is.EqualTo(0));

                using (var baseObjClass = (ObjectClass)TypeClass.Get(typeof(TestObjectPropertiesBase).GetGType()))
                    using (var subclassObjClass = (ObjectClass)TypeClass.Get(typeof(TestObjectPropertiesSubclass).GetGType())) {
                        using (var baseIntValueProp = baseObjClass.FindProperty(nameof(obj.IntValue)))
                            using (var subclassIntValueProp = subclassObjClass.FindProperty(nameof(obj.IntValue))) {
                                // ...so ParamSpecs should not be the same
                                Assert.That(baseIntValueProp.Handle, Is.Not.EqualTo(subclassIntValueProp.Handle));
                            }

                        // But the override keyword replaces property...

                        Assume.That(obj.BoolValue, Is.False);
                        obj.SetProperty("bool-value", true);
                        Assert.That(obj.BoolValue, Is.True);

                        Assert.That(((TestObjectPropertiesBase)obj).BoolValue, Is.True);

                        using (var baseBoolValueProp = baseObjClass.FindProperty("bool-value"))
                            using (var subclassBoolValueProp = subclassObjClass.FindProperty("bool-value")) {
                                // ...so ParamSpecs should be the same
                                Assert.That(baseBoolValueProp.Handle, Is.EqualTo(subclassBoolValueProp.Handle));
                            }
                    }
            }

            Utility.AssertNoGLibLog();
        }
Beispiel #5
0
        public void TestRegister5()
        {
            // make sure that we can override name and nick with attributes
            var testEnum5GType = typeof(TestEnum5).GetGType();

            Assert.That(testEnum5GType.Name, Is.EqualTo("TestEnum5GTypeName"));
            using (var enum5TypeClass = (EnumClass)TypeClass.Get(testEnum5GType)) {
                var value1 = GISharp.GObject.Enum.GetValue(enum5TypeClass, 1);
                Assert.That(value1.Value, Is.EqualTo((int)TestEnum5.One));
                var value1Name = GMarshal.Utf8PtrToString(value1.ValueName);
                Assert.That(value1Name, Is.EqualTo("test_enum_5_value_one"));
                var value1Nick = GMarshal.Utf8PtrToString(value1.ValueNick);
                Assert.That(value1Nick, Is.EqualTo("One"));

                var value2 = GISharp.GObject.Enum.GetValue(enum5TypeClass, 2);
                Assert.That(value2.Value, Is.EqualTo((int)TestEnum5.Two));
                var value2Name = GMarshal.Utf8PtrToString(value2.ValueName);
                Assert.That(value2Name, Is.EqualTo("Two"));
                var value2Nick = GMarshal.Utf8PtrToString(value2.ValueNick);
                Assert.That(value2Nick, Is.EqualTo("test_enum_5_value_two"));
            }

            Utility.AssertNoGLibLog();
        }
Beispiel #6
0
        public void TestRegister5()
        {
            // make sure that we can override name and nick with attributes
            var testFlags5GType = typeof(TestFlags5).GetGType();

            Assert.That(testFlags5GType.Name, Is.EqualTo("TestFlags5GTypeName"));
            using (var flags5TypeClass = (FlagsClass)TypeClass.Get(testFlags5GType)) {
                var value1 = Flags.GetFirstValue(flags5TypeClass, 1);
                Assert.That(value1.Value, Is.EqualTo((int)TestFlags5.One));
                var value1Name = GMarshal.Utf8PtrToString(value1.ValueName);
                Assert.That(value1Name, Is.EqualTo("test_flags_5_value_one"));
                var value1Nick = GMarshal.Utf8PtrToString(value1.ValueNick);
                Assert.That(value1Nick, Is.EqualTo("One"));

                var value2 = Flags.GetFirstValue(flags5TypeClass, 2);
                Assert.That(value2.Value, Is.EqualTo((int)TestFlags5.Two));
                var value2Name = GMarshal.Utf8PtrToString(value2.ValueName);
                Assert.That(value2Name, Is.EqualTo("Two"));
                var value2Nick = GMarshal.Utf8PtrToString(value2.ValueNick);
                Assert.That(value2Nick, Is.EqualTo("test_flags_5_value_two"));
            }

            Utility.AssertNoGLibLog();
        }