[gxml] Added tests for parent in xDocument
- From: Daniel Espinosa Ortiz <despinosa src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gxml] Added tests for parent in xDocument
- Date: Sat, 20 Feb 2016 17:36:06 +0000 (UTC)
commit d8d44c399f9ef75797ad6c3a70bab3a507f58ba3
Author: Daniel Espinosa <esodan gmail com>
Date: Thu Feb 18 21:47:31 2016 -0600
Added tests for parent in xDocument
gxml/libxml-Node.vala | 7 ++++++-
test/AttrTest.vala | 6 ++++++
test/DocumentTest.vala | 4 ++++
test/ElementTest.vala | 8 ++++++++
4 files changed, 24 insertions(+), 1 deletions(-)
---
diff --git a/gxml/libxml-Node.vala b/gxml/libxml-Node.vala
index 0c1c471..820c6d0 100644
--- a/gxml/libxml-Node.vala
+++ b/gxml/libxml-Node.vala
@@ -509,6 +509,11 @@ namespace GXml {
public GXml.NodeType type_node { get { return node_type; } }
public virtual string to_string () { return stringify (); }
public GXml.Document document { get { return this.owner_document; } }
- public virtual GXml.Node parent { owned get { return parent_node.ref () as GXml.Node; } }
+ public virtual GXml.Node parent {
+ owned get {
+ if (parent_node == null) return null;
+ return parent_node.ref () as GXml.Node;
+ }
+ }
}
}
diff --git a/test/AttrTest.vala b/test/AttrTest.vala
index 0b4fad3..b02e992 100644
--- a/test/AttrTest.vala
+++ b/test/AttrTest.vala
@@ -170,5 +170,11 @@ class AttrTest : GXmlTest {
attr.remove_child (attr.child_nodes.last ());
assert (attr.value == "");
});
+ Test.add_func ("/gxml/attribute/parent", () => {
+ var doc = new xDocument.from_string ("<root attr=\"val\"><child/></root>");
+ assert (doc.root != null);
+ assert (doc.root.attrs["attr"] != null);
+ assert (doc.root.attrs["attr"].parent == null);
+ });
}
}
diff --git a/test/DocumentTest.vala b/test/DocumentTest.vala
index e113b2d..5a02e0e 100644
--- a/test/DocumentTest.vala
+++ b/test/DocumentTest.vala
@@ -443,6 +443,10 @@ class DocumentTest : GXmlTest {
/* more thorough test exists in xElement, since right now
xDocument uses that one */
});
+ Test.add_func ("/gxml/document/parent", () => {
+ var doc = new xDocument ();
+ assert (doc.parent == null);
+ });
Test.add_func ("/gxml/document/to_string", () => {
xDocument doc = get_doc ();
assert (doc.to_string () == "<?xml version=\"1.0\"?>
diff --git a/test/ElementTest.vala b/test/ElementTest.vala
index e5a9c61..43caed0 100644
--- a/test/ElementTest.vala
+++ b/test/ElementTest.vala
@@ -454,5 +454,13 @@ class ElementTest : GXmlTest {
assert_not_reached ();
}
});
+ Test.add_func ("/gxml/element/parent", () => {
+ var doc = new xDocument.from_string ("<root><child/></root>");
+ assert (doc.root != null);
+ assert (doc.root.children[0] != null);
+ assert (doc.root.children[0].parent != null);
+ assert (doc.root.children[0].parent.name == "root");
+ assert (doc.root.parent == null);
+ });
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]