[gxml/serialization: 32/33] Sync pkg checks with Gee 0.8. Fixes on NodeList port Gee.Collection
- From: Daniel Espinosa Ortiz <despinosa src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gxml/serialization: 32/33] Sync pkg checks with Gee 0.8. Fixes on NodeList port Gee.Collection
- Date: Fri, 20 Dec 2013 21:33:36 +0000 (UTC)
commit 438826f9e239540981619340b1609222beaa1567
Author: Daniel Espinosa <esodan gmail com>
Date: Thu Dec 19 13:40:07 2013 -0600
Sync pkg checks with Gee 0.8. Fixes on NodeList port Gee.Collection
* Requires GLib 2.32, Vala 0.20, Gee 0.10.5
* Unit Test pass
* Node Unit Test improvements
* Added some Element Unit Tests
configure.ac | 6 +++---
gxml/NodeList.vala | 34 ++++++++++++++++++++++------------
test/ElementTest.vala | 48 +++++++++++++++++++++++++++++++++++++++++++++++-
test/NodeTest.vala | 19 +++++++++++++------
4 files changed, 85 insertions(+), 22 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 9c65274..44e9b3b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -107,9 +107,9 @@ AC_SUBST([API_VERSION])
# TODO: what do we do about libvala's versioning? set it back to -0.18 and see what happens when we
upgraded from Fedora 18 to 19
-GLIB_REQUIRED=2.16.0
-VALA_REQUIRED=0.16.0
-GEE_REQUIRED=0.7.0
+GLIB_REQUIRED=2.32.0
+VALA_REQUIRED=0.20.0
+GEE_REQUIRED=0.10.5
LIBXML_REQUIRED=2.7
GIO_MODULES="gio-2.0 >= 2.16"
VALADOC_REQUIRED=0.3.1
diff --git a/gxml/NodeList.vala b/gxml/NodeList.vala
index f33856a..1efc7a8 100644
--- a/gxml/NodeList.vala
+++ b/gxml/NodeList.vala
@@ -259,14 +259,20 @@ namespace GXml {
public override bool remove (Node item) { return false; }
public override bool read_only { get { return true; } }
public override int size {
- get {
- int len = 0;
- for (Xml.Node *cur = head; cur != null; cur = cur->next) {
- len++;
+ get {
+ if (head != null) {
+ //GLib.warning ("At NodeChildNodeList: get_size");
+ int len = 1;
+ var cur = head;
+ while (cur->next != null) {
+ cur = cur->next;
+ len++;
+ }
+ return len;
+ }
+ return 0;
+ }
}
- return len;
- }
- }
public override Gee.Iterator<Node> iterator () {
return new NodeListIterator (this);
}
@@ -285,11 +291,15 @@ namespace GXml {
}
return this.owner.lookup_node (cur); // TODO :check for nulls?
}
- public new Node @get (int n) {
- Xml.Node *cur = head;
- for (int i = 0; i < n && cur != null; i++) {
- cur = cur->next;
- }
+ public new Node @get (int n)
+ requires (head != null)
+ {
+ Xml.Node *cur = head;
+ int i = 0;
+ while (cur->next != null && i != n) {
+ cur = cur->next;
+ i++;
+ }
return this.owner.lookup_node (cur);
}
public Node item (ulong idx) { return get ((int) idx); }
diff --git a/test/ElementTest.vala b/test/ElementTest.vala
index 8795af0..025e1b2 100644
--- a/test/ElementTest.vala
+++ b/test/ElementTest.vala
@@ -366,7 +366,7 @@ class ElementTest : GXmlTest {
// STUB
});
- Test.add_func ("/gxml/element/to_string", () => {
+ Test.add_func ("/gxml/element/to_string", () =>{
Document doc, doc2;
Element elem = get_elem_new_doc ("country", out doc);
elem.append_child (elem.owner_document.create_text_node ("New Zealand"));
@@ -386,5 +386,51 @@ class ElementTest : GXmlTest {
// TODO: want to test with format on and off
});
+ Test.add_func ("/gxml/element/content/set", () =>{
+ var doc = new Document ();
+ var root = doc.create_element ("root");
+ doc.append_child (root);
+ root.content = "TEXT1";
+ string d = """<?xml version="1.0"?>
+<root>TEXT1</root>
+""";
+ if (doc.to_string () != d) {
+ stdout.printf (@"Element content error. Expected '$d'\ngot '$(doc)'\n");
+ assert_not_reached ();
+ }
+ });
+ Test.add_func ("/gxml/element/content/overwrite_child_nodes", () =>{
+ var doc = new Document ();
+ var root = doc.create_element ("root");
+ doc.append_child (root);
+ var n = doc.create_element ("child");
+ root.append_child (n);
+ // This will remove all child nodes
+ root.content = "TEXT1";
+ string d = """<?xml version="1.0"?>
+<root>TEXT1</root>
+""";
+ if (doc.to_string () != d) {
+ stdout.printf (@"Element content error. Expected '$d'\ngot '$(doc)'\n");
+ assert_not_reached ();
+ }
+ });
+ Test.add_func ("/gxml/element/content/keep_child_nodes", () =>{
+ var doc = new Document ();
+ var root = doc.create_element ("root");
+ doc.append_child (root);
+ var n = doc.create_element ("child");
+ root.append_child (n);
+ // This will remove all child nodes
+ var t = doc.create_text_node ("TEXT1");
+ root.append_child (t);
+ string d = """<?xml version="1.0"?>
+<root><child/>TEXT1</root>
+""";
+ if (doc.to_string () != d) {
+ stdout.printf (@"Element content error. Expected\n'$d'\ngot\n'$(doc)'\n");
+ assert_not_reached ();
+ }
+ });
}
}
diff --git a/test/NodeTest.vala b/test/NodeTest.vala
index 06730b0..86ce766 100644
--- a/test/NodeTest.vala
+++ b/test/NodeTest.vala
@@ -153,22 +153,22 @@ class NodeTest : GXmlTest {
Document doc = get_doc ();
GXml.Node parent = get_elem ("Molly", doc);
if (parent == null) {
- stdout.printf (@"Parent child Molly not found\n");
+ stdout.printf (@"Parent child Molly not created\n");
assert_not_reached ();
}
GXml.Node child_0 = get_elem ("Percy", doc);
if (child_0 == null) {
- stdout.printf (@"Child_0 Percy not found\n");
+ stdout.printf (@"Child_0 Percy not created\n");
assert_not_reached ();
}
GXml.Node child_1 = get_elem ("Ron", doc);
if (child_1 == null) {
- stdout.printf (@"Child Ron not found\n");
+ stdout.printf (@"Child Ron not created\n");
assert_not_reached ();
}
GXml.Node child_2 = get_elem ("Ginnie", doc);
if (child_2 == null) {
- stdout.printf (@"Child Ginnie not found\n");
+ stdout.printf (@"Child Ginnie not created\n");
assert_not_reached ();
}
if (parent.child_nodes.length != 0) {
@@ -182,11 +182,18 @@ class NodeTest : GXmlTest {
stdout.printf (@"ChildNode: wrong length. Expected 0 got
$(parent.child_nodes.length)\n");
assert_not_reached ();
}
- if (parent child_nodes get (0) != child_0) {
+ var c0 = parent child_nodes get (0);
+ if (c0.node_name != child_0.node_name) {
stdout.printf (@"ChildNode: wrong child 0.\n");
assert_not_reached ();
}
- if (parent child_nodes get (2) != child_2) {
+ var c1 = parent child_nodes get (1);
+ if (c1.node_name != child_1.node_name) {
+ stdout.printf (@"ChildNode: wrong child 1.\n");
+ assert_not_reached ();
+ }
+ var c2 = parent child_nodes get (2);
+ if (c2.node_name != child_2.node_name) {
stdout.printf (@"ChildNode: wrong child 2.\n");
assert_not_reached ();
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]