[gxml] GomElement: Removing redundant DomNode interface



commit ae6c3a3ebafaaded801f63c44c3adc46777b17ed
Author: Daniel Espinosa <esodan gmail com>
Date:   Sun Oct 30 09:09:03 2016 -0600

    GomElement: Removing redundant DomNode interface
    
    If DomNode is declared as implemented interface,
    access to parent GomNode implementation methods
    creates an infinite loop

 gxml/GomElement.vala      |    1 -
 gxml/GomNode.vala         |   29 ++++++++++++++++++++---------
 test/GXmlTest.vala        |    1 +
 test/GomDocumentTest.vala |   18 +++++++++++-------
 4 files changed, 32 insertions(+), 17 deletions(-)
---
diff --git a/gxml/GomElement.vala b/gxml/GomElement.vala
index 03eafdd..c6e42d4 100644
--- a/gxml/GomElement.vala
+++ b/gxml/GomElement.vala
@@ -27,7 +27,6 @@ using Gee;
  * transparently as {@link DomElement} in a XML tree.
  */
 public class GXml.GomElement : GomNode,
-                              DomNode,
                               DomChildNode,
                               DomNonDocumentTypeChildNode,
                               DomParentNode,
diff --git a/gxml/GomNode.vala b/gxml/GomNode.vala
index 3b9cd34..d043972 100644
--- a/gxml/GomNode.vala
+++ b/gxml/GomNode.vala
@@ -27,18 +27,21 @@ public class GXml.GomNode : Object,
                             DomEventTarget,
                             DomNode {
 // DomNode
-  protected string _local_name = "";
-  protected string _prefix = null;
-  protected DomNode.NodeType _node_type = DomNode.NodeType.INVALID;
+  protected string _local_name;
+  protected string _prefix;
+  protected string _base_uri;
+  protected string _node_value;
+  protected DomNode.NodeType _node_type;
   public DomNode.NodeType node_type { get { return _node_type; } }
   public string node_name {
     owned get {
+      if (_local_name == null) return "NO NAME";
+      GLib.message ("GomNode: node_name");
       if (_prefix == null) return _local_name;
       return _prefix+":"+_local_name;
     }
   }
 
-  protected string _base_uri = null;
   public string? base_uri { get { return _base_uri; } }
 
   protected GXml.DomDocument _document;
@@ -91,11 +94,11 @@ public class GXml.GomNode : Object,
     }
   }
 
-  protected string _node_value = null;
-       public string? node_value { owned get { return _node_value; } set { _node_value = value; } }
-       public string? text_content {
-         owned get {
-           string t = null;
+  public string? node_value { owned get { return _node_value; } set { _node_value = value; } }
+
+  public string? text_content {
+    owned get {
+      string t = null;
       foreach (GXml.DomNode n in child_nodes) {
         if (n is GXml.DomText) {
           if (t == null) t = n.node_value;
@@ -114,6 +117,14 @@ public class GXml.GomNode : Object,
     }
   }
 
+  construct {
+    _local_name = "";
+    _prefix = null;
+    _node_type = DomNode.NodeType.INVALID;
+    _base_uri = null;
+    _node_value = null;
+  }
+
   public bool has_child_nodes () { return (_child_nodes.size > 0); }
   public void normalize () {
     try {
diff --git a/test/GXmlTest.vala b/test/GXmlTest.vala
index 6f29a10..2f7c86a 100644
--- a/test/GXmlTest.vala
+++ b/test/GXmlTest.vala
@@ -61,6 +61,7 @@ class GXmlTest {
                HtmlDocumentTest.add_tests ();
                DomGDocumentTest.add_tests ();
                XPathTest.add_tests ();
+               GomDocumentTest.add_tests ();
 
                Test.run ();
 
diff --git a/test/GomDocumentTest.vala b/test/GomDocumentTest.vala
index 155cc27..ae77513 100644
--- a/test/GomDocumentTest.vala
+++ b/test/GomDocumentTest.vala
@@ -26,14 +26,18 @@ class GomDocumentTest : GXmlTest {
        public static void add_tests () {
                Test.add_func ("/gxml/gom-document/construct_api", () => {
                        try {
-                               var d = new GomDocument ();
-                               var document_element = d.create_element ("document_element");
-                               d.child_nodes.add (document_element);
+                               DomDocument d = new GomDocument ();
+                               DomElement r = d.create_element ("root");
+                               assert (r is DomElement);
+                               assert (r.local_name == "root");
+                               assert (r.tag_name == "root");
+                               assert (r.node_type == DomNode.NodeType.ELEMENT_NODE);
+                               assert (r.node_name == "root");
+                               d.child_nodes.add (r);
                                assert (d.document_element != null);
-                               Test.message ("document_element name: "+d.document_element.node_name);
-                               assert (d.document_element.node_name == "document_element");
-                               //Test.message ("document_element string: "+d.document_element.to_string ());
-                               //assert (d.document_element.to_string () == "<document_element/>");
+                               assert (d.document_element.node_name == "root");
+                               //Test.message ("r string: "+d.document_element.to_string ());
+                               //assert (d.document_element.to_string () == "<root/>");
                        } catch {assert_not_reached ();}
                });
                Test.add_func ("/gxml/gom-document/construct_from_path_error", () => {


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