[gxml] GomObject: Instantiable Properties first



commit 42729ea7baadd16df39fc679aeb52378c83dd793
Author: Daniel Espinosa <esodan gmail com>
Date:   Thu Oct 26 18:13:51 2017 -0500

    GomObject: Instantiable Properties first
    
    If you tag "::" at nick a non-instantiable property first
    than same name instantiatable property last will never be
    instantiated

 test/GomElementTest.vala |   39 +++++++++++++++++++++++++++++++++++++--
 1 files changed, 37 insertions(+), 2 deletions(-)
---
diff --git a/test/GomElementTest.vala b/test/GomElementTest.vala
index 3c640d2..ba7a8ce 100644
--- a/test/GomElementTest.vala
+++ b/test/GomElementTest.vala
@@ -42,12 +42,33 @@ class GomElementTest : GXmlTest  {
        }
        public class Top : GomElement {
                public NoInstantiatable inst {
-                       get { return inst_i; } set { inst_i = value as Instantiatable; } }
+                       get { return inst_i; } set { inst_i = value as Instantiatable; }
+               }
                public Instantiatable inst_i { get; set; }
                [Description (nick="::pq")]
                public Property pq { get; set; }
                construct { initialize ("Top"); }
        }
+       public class GProperty : GomString, Property {}
+       public class GTop : GomElement {
+               public NoInstantiatable inst { get; set; }
+               public Instantiatable inst_i {
+                       get { return inst as Instantiatable; }
+                       set { inst = value as NoInstantiatable; }
+               }
+               // Order Matters: Put first instantiatable properties
+               [Description (nick="::pq")]
+               public GProperty gpq {
+                       get { return pq as GProperty; }
+                       set { pq = value as Property; }
+               }
+               // Don't tag non-instantiatable properties
+               // Here works because an instantiatable property is placed first
+               // but will fail if you derive or implement a interferface
+               [Description (nick="::pq")]
+               public Property pq { get; set; }
+               construct { initialize ("Top"); }
+       }
        public static void add_tests () {
        Test.add_func ("/gxml/gom-element/read/namespace_uri", () => {
                        DomDocument doc = null;
@@ -430,7 +451,7 @@ class GomElementTest : GXmlTest  {
                    assert_not_reached ();
                  }
                });
-               Test.add_func ("/gxml/gom-element/no-instantiatable", () => {
+               Test.add_func ("/gxml/gom-element/no-instantiatable/avoid", () => {
                        try {
                                string str = """<Top pq="Qlt"><Instantiatable name="Nop"/></Top>""";
                                var t = new Top ();
@@ -442,5 +463,19 @@ class GomElementTest : GXmlTest  {
                    assert_not_reached ();
                  }
                });
+               Test.add_func ("/gxml/gom-element/no-instantiatable/set", () => {
+                       try {
+                               string str = """<Top pq="Qlt"><Instantiatable name="Nop"/></Top>""";
+                               var t = new GTop ();
+                               t.read_from_string (str);
+                               assert (t.inst != null);
+                               assert (t.inst.name == "Nop");
+                               assert (t.pq != null);
+                               assert (t.pq.value == "Qlt");
+                       } catch (GLib.Error e) {
+                   GLib.message ("Error: "+e.message);
+                   assert_not_reached ();
+                 }
+               });
        }
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]