[gxml] Fixes on GNode for Node.parent



commit 0fb12a8f535f948570c2ebbd0d9fc69053dd80dd
Author: Daniel Espinosa <esodan gmail com>
Date:   Fri Feb 19 15:26:44 2016 -0600

    Fixes on GNode for Node.parent

 NEWS                     |    7 +++++++
 configure.ac             |    2 +-
 gxml/GXmlNode.vala       |    7 ++++++-
 test/GAttributeTest.vala |   12 ++++++++++++
 test/GDocumentTest.vala  |    4 ++++
 test/GElementTest.vala   |    9 +++++++++
 6 files changed, 39 insertions(+), 2 deletions(-)
---
diff --git a/NEWS b/NEWS
index 9021b25..5d26193 100644
--- a/NEWS
+++ b/NEWS
@@ -1,4 +1,11 @@
 ===============
+Version 0.9.1
+===============
+
+* Added GXml.Node.parent property
+
+
+===============
 Version 0.9.0
 ===============
 
diff --git a/configure.ac b/configure.ac
index fe885b6..14bee7f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -12,7 +12,7 @@
 # Release Version
 m4_define([project_major_version], [0])
 m4_define([project_minor_version], [9])
-m4_define([project_micro_version], [0])
+m4_define([project_micro_version], [1])
 m4_define([project_nano_version], [0])
 
 # LT_VERSION
diff --git a/gxml/GXmlNode.vala b/gxml/GXmlNode.vala
index 16db24b..c219553 100644
--- a/gxml/GXmlNode.vala
+++ b/gxml/GXmlNode.vala
@@ -42,7 +42,12 @@ public abstract class GXml.GNode : Object, GXml.Node
   public virtual Gee.BidirList<GXml.Node> children { owned get { return new GListChildren (_doc, _node); } }
   public virtual Gee.List<GXml.Namespace> namespaces { owned get { return new GListNamespaces (_doc, _node); 
} }
   public virtual GXml.Document document { get { return _doc; } }
-  public virtual GXml.Node parent { owned get { return to_gnode (document as GDocument, _node->parent); } }
+  public virtual GXml.Node parent {
+    owned get {
+      if (_node == null) return null;
+      return to_gnode (document as GDocument, _node->parent);
+    }
+  }
   public virtual GXml.NodeType type_node {
     get {
       if (_node == null) return GXml.NodeType.X_UNKNOWN;
diff --git a/test/GAttributeTest.vala b/test/GAttributeTest.vala
index 58b98b6..bd8fe68 100644
--- a/test/GAttributeTest.vala
+++ b/test/GAttributeTest.vala
@@ -116,5 +116,17 @@ class GAttributeTest : GXmlTest {
                                assert_not_reached ();
                        }
                });
+               Test.add_func ("/gxml/tw-attribute/parent", () => {
+                       var doc = new GDocument ();
+                       var e = doc.create_element ("root");
+                       doc.children.add (e);
+                       var c = doc.create_element ("child");
+                       e.children.add (c);
+                       (e as GXml.Element).set_attr ("attr", "val");
+                       assert (doc.root != null);
+                       assert (doc.root.attrs["attr"] != null);
+                       assert (doc.root.attrs["attr"].parent != null);
+                       assert (doc.root.attrs["attr"].parent.name == "root");
+               });
        }
 }
diff --git a/test/GDocumentTest.vala b/test/GDocumentTest.vala
index e7e3671..effb0a1 100644
--- a/test/GDocumentTest.vala
+++ b/test/GDocumentTest.vala
@@ -321,5 +321,9 @@ class GDocumentTest : GXmlTest {
                                assert_not_reached ();
                        }
                });
+               Test.add_func ("/gxml/gdocument/parent", () => {
+                       var doc = new GDocument ();
+                       assert (doc.parent == null);
+               });
        }
 }
diff --git a/test/GElementTest.vala b/test/GElementTest.vala
index e7f5720..9029cb1 100644
--- a/test/GElementTest.vala
+++ b/test/GElementTest.vala
@@ -143,5 +143,14 @@ class GElementTest : GXmlTest  {
                                assert_not_reached ();
                        }
                });
+               Test.add_func ("/gxml/gelement/parent", () => {
+                       var doc = new GDocument.from_string ("<root><child/></root>");
+                       assert (doc.root != null);
+                       assert (doc.root.parent is GXml.Node);
+                       assert (doc.root.parent is GXml.Document);
+                       assert (doc.root.children[0] != null);
+                       assert (doc.root.children[0].parent != null);
+                       assert (doc.root.children[0].parent.name == "root");
+               });
        }
 }


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