[gxml] Fixed TDocument.ReadTypeFunc used on TDocument.read_doc()
- From: Daniel Espinosa Ortiz <despinosa src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gxml] Fixed TDocument.ReadTypeFunc used on TDocument.read_doc()
- Date: Thu, 24 Mar 2016 23:56:59 +0000 (UTC)
commit b0a42e4120a11c78868ece106b1677bd4b8eb771
Author: Daniel Espinosa <esodan gmail com>
Date: Thu Mar 24 11:00:07 2016 -0600
Fixed TDocument.ReadTypeFunc used on TDocument.read_doc()
gxml/TDocument.vala | 8 ++++++--
test/TDocumentTest.vala | 8 ++++----
test/TElementTest.vala | 44 ++++++++++++++++++++++++++++++++++++++++++++
test/t-read-test.xml | 14 ++++++++++++++
4 files changed, 68 insertions(+), 6 deletions(-)
---
diff --git a/gxml/TDocument.vala b/gxml/TDocument.vala
index 4dc8990..8fd8460 100644
--- a/gxml/TDocument.vala
+++ b/gxml/TDocument.vala
@@ -450,7 +450,6 @@ public class GXml.TDocument : GXml.TNode, GXml.Document
b.splice (istream, 0);
var tr = new TextReader.for_memory ((char[]) b.data, (int) b.get_data_size (), "/memory");
GXml.Node current = null;
- ReadType rt = ReadType.CONTINUE;
while (read_node (doc, tr, rtfunc) == ReadType.CONTINUE);
}
/**
@@ -487,7 +486,12 @@ public class GXml.TDocument : GXml.TNode, GXml.Document
GLib.message ("ReadNode: Element: "+tr.const_local_name ());
#endif
n = node.document.create_element (tr.const_local_name ());
- node.children.add (n);
+ ReadType nrt = ReadType.CONTINUE;
+ if (rntfunc != null) nrt = rntfunc (n, tr);
+ if (nrt == ReadType.NEXT)
+ tr.next ();
+ if (nrt == ReadType.CONTINUE)
+ node.children.add (n);
#if DEBUG
GLib.message ("ReadNode: next node:"+n.to_string ());
GLib.message ("ReadNode: next node attributes:"+(tr.has_attributes ()).to_string ());
diff --git a/test/TDocumentTest.vala b/test/TDocumentTest.vala
index 8549be2..8dc3d0e 100644
--- a/test/TDocumentTest.vala
+++ b/test/TDocumentTest.vala
@@ -438,7 +438,7 @@ class TDocumentTest : GXmlTest {
assert (d.root.name == "Sentences");
assert (d.root.attrs["audience"] != null);
assert (d.root.attrs["audience"].value == "All");
- assert (d.root.children.size == 6);
+ assert (d.root.children.size == 7);
var s1 = d.root.children[0];
assert (s1 != null);
assert (s1.name == "Sentence");
@@ -569,7 +569,7 @@ class TDocumentTest : GXmlTest {
GLib.message ("Node name:"+n.name);
}
#endif
- assert (d.root.children.size == 6);
+ assert (d.root.children.size == 7);
var p = (d.root.children[4]);
assert (p != null);
assert (p is GXml.ProcessingInstruction);
@@ -584,7 +584,7 @@ class TDocumentTest : GXmlTest {
assert (f.query_exists ());
var d = new TDocument.from_file (f);
TDocument.read_doc (d, f, null);
- assert (d.root.children.size == 6);
+ assert (d.root.children.size == 7);
var p = (d.root.children[5]);
assert (p != null);
assert (p is GXml.CDATA);
@@ -633,7 +633,7 @@ class TDocumentTest : GXmlTest {
assert (d.root.name == "Sentences");
assert (d.root.attrs["audience"] != null);
assert (d.root.attrs["audience"].value == "All");
- assert (d.root.children.size == 6);
+ assert (d.root.children.size == 7);
var s1 = d.root.children[0];
assert (s1 != null);
assert (s1.name == "Sentence");
diff --git a/test/TElementTest.vala b/test/TElementTest.vala
index df5263e..09fabd4 100644
--- a/test/TElementTest.vala
+++ b/test/TElementTest.vala
@@ -613,5 +613,49 @@ class TElementTest : GXmlTest {
assert (doc.root.attrs["attr"].parent != null);
assert (doc.root.attrs["attr"].parent.name == "root");
});
+ Test.add_func ("/gxml/t-element/readtype", () => {
+ try {
+ var file = GLib.File.new_for_path
(GXmlTestConfig.TEST_DIR+"/t-read-test.xml");
+ assert (file.query_exists ());
+ var d = new TDocument ();
+ TDocument.read_doc (d, file, null);
+ assert (d.root != null);
+ assert (d.root.children.size == 7);
+ var n = d.root.children[6];
+ assert (n != null);
+ assert (n.name == "ReadTop");
+ assert (n.children.size == 9);
+ var nc = n.children[3];
+ assert (nc != null);
+ assert (nc.name == "Read");
+ assert (nc.children.size == 2);
+ // Remove all
+ GLib.message ("Skiping nodes");
+ TDocument.ReadTypeFunc f1 = (node, tr)=>{
+ GLib.message ("ReadType check node: "+node.name);
+ if (node.name == "NoRead" || node.name == "NoReadChild") {
+ GLib.message ("Skiping node: "+node.name);
+ return TDocument.ReadType.NEXT;
+ }
+ return TDocument.ReadType.CONTINUE;
+ };
+ var d2 = new TDocument ();
+ TDocument.read_doc (d2, file, f1);
+ assert (d2.root != null);
+ assert (d2.root.children.size == 7);
+ var n2 = d2.root.children[6];
+ assert (n2 != null);
+ assert (n2.name == "ReadTop");
+ assert (n2.children.size == 4);
+ GLib.message (@"$d2");
+ var nc2 = n2.children[2];
+ assert (nc2 != null);
+ assert (nc2.name == "Read");
+ assert (nc2.children.size == 1);
+ } catch (GLib.Error e) {
+ GLib.message ("Error: "+e.message);
+ assert_not_reached ();
+ }
+ });
}
}
diff --git a/test/t-read-test.xml b/test/t-read-test.xml
index b5e6bb5..9aaa842 100644
--- a/test/t-read-test.xml
+++ b/test/t-read-test.xml
@@ -21,4 +21,18 @@
<b:Book gxml:name="Thor"/>
<?css href="http://www.gnome.org"?>
<![CDATA[<greeting>Hello, world!</greeting>]]>
+ <ReadTop>
+ <Read/>
+ <NoRead/>
+ <Read/>
+ <Read>
+ <ReadChild/>
+ <NoReadChild/>
+ </Read>
+ <NoRead/>
+ <NoRead/>
+ <NoRead/>
+ <NoRead/>
+ <Read/>
+ </ReadTop>
</Sentences>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]