[gxml/gxml-0.8] More fixes for Bug 760568. Make sure compiles against Vala 0.26



commit ffc678e269771b68284d4c8984b4e27aa0595d4b
Author: Daniel Espinosa <esodan gmail com>
Date:   Mon May 2 10:42:16 2016 -0500

    More fixes for Bug 760568. Make sure compiles against Vala 0.26
    
    * For now on, we will be sure this package compiles against latest
      stable or LTS version distribution Debian/Ubuntu.
    
      This commit fixes make check under Debian 8.
    
    * For OSX this should fix remained errors for bug 760568

 NEWS                    |    3 +-
 gxml/xlibxml.c          |    4 +-
 test/DocumentTest.vala  |    2 +
 test/GDocumentTest.vala |  351 ++++++++++++++++++++
 test/GXmlTest.vala      |    2 +-
 test/TDocumentTest.vala |  837 +++++++++++++++++++++++++++++++++++++++++++++++
 test/test.xml           |   15 +
 7 files changed, 1210 insertions(+), 4 deletions(-)
---
diff --git a/NEWS b/NEWS
index b2a5a84..f234e0d 100644
--- a/NEWS
+++ b/NEWS
@@ -5,8 +5,7 @@ Version 0.8.4
 
 * Fixed OSX build (Bug #760568)
 * Fixed vapi installation
-
-
+* Fixed
 ===============
 Version 0.8.3
 ===============
diff --git a/gxml/xlibxml.c b/gxml/xlibxml.c
index c9c52ba..cd2416d 100644
--- a/gxml/xlibxml.c
+++ b/gxml/xlibxml.c
@@ -23,7 +23,7 @@
 
 void* gxml_doc_get_intsubset_entities (xmlDoc *doc)
 {
-  g_return_if_fail (doc != NULL);
+  g_return_val_if_fail (doc != NULL, NULL);
   return doc->intSubset->entities;
 }
 
@@ -40,11 +40,13 @@ gint gxml_validate_name (xmlChar* name, int space)
  */
 xmlErrorPtr gxml_parser_context_get_last_error (void* ctx)
 {
+  g_return_val_if_fail (ctx != NULL, NULL);
   return gxml_context_get_last_error (ctx);
 }
 
 xmlErrorPtr gxml_context_get_last_error (void* ctx)
 {
+  g_return_val_if_fail (ctx != NULL, NULL);
   return xmlCtxtGetLastError (ctx);
 }
 
diff --git a/test/DocumentTest.vala b/test/DocumentTest.vala
index 1dc6956..36a55c2 100644
--- a/test/DocumentTest.vala
+++ b/test/DocumentTest.vala
@@ -127,6 +127,8 @@ class DocumentTest : GXmlTest {
                        });
                Test.add_func ("/gxml/document/gfile/remote", () => {
                        try {
+                               var net = GLib.NetworkMonitor.get_default ();
+                               if (!net.network_available) return;
                                var rf = GLib.File.new_for_uri 
("https://git.gnome.org/browse/gxml/plain/gxml.doap";);
                                assert (rf.query_exists ());
                                var d = new xDocument.from_gfile (rf);
diff --git a/test/GDocumentTest.vala b/test/GDocumentTest.vala
new file mode 100644
index 0000000..669f640
--- /dev/null
+++ b/test/GDocumentTest.vala
@@ -0,0 +1,351 @@
+/* -*- Mode: vala; indent-tabs-mode: t; c-basic-offset: 2; tab-width: 2 -*- */
+/* Notation.vala
+ *
+ * Copyright (C) 2011-2013  Richard Schwarting <aquarichy gmail com>
+ * Copyright (C) 2011-2015  Daniel Espinosa <esodan gmail com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see <http://www.gnu.org/licenses/>.
+ *
+ * Authors:
+ *      Richard Schwarting <aquarichy gmail com>
+ *      Daniel Espinosa <esodan gmail com>
+ */
+
+using GXml;
+
+class GDocumentTest : GXmlTest {
+       public static void add_tests () {
+               Test.add_func ("/gxml/gdocument/construct_api", () => {
+                       try {
+                               var d = new GDocument ();
+                               var root = d.create_element ("root");
+                               d.children.add (root);
+                               assert (d.root != null);
+                               Test.message ("Root name: "+d.root.name);
+                               assert (d.root.name == "root");
+                               Test.message ("Root string: "+d.root.to_string ());
+                               assert (d.root.to_string () == "<root/>");
+                       } catch {assert_not_reached ();}
+               });
+               Test.add_func ("/gxml/gdocument/construct_from_path_error", () => {
+                               GDocument doc;
+                               try {
+                               GLib.Test.message ("invalid file...");
+                                       // file does not exist
+                                       doc = new GDocument.from_path ("/tmp/asdfjlkansdlfjl");
+                                       assert_not_reached ();
+                               } catch {}
+
+                               try {
+                                       // file exists, but is not XML (it's a directory!)
+                                       doc = new GDocument.from_path ("/tmp/");
+                                       assert_not_reached ();
+                               } catch  {}
+                               try {
+                                       doc = new GDocument.from_path ("test_invalid.xml");
+                                       assert_not_reached ();
+                               } catch {}
+                       });
+               Test.add_func ("/gxml/gdocument/construct_from_stream", () => {
+                               var fin = File.new_for_path (GXmlTestConfig.TEST_DIR + "/test.xml");
+                               assert (fin.query_exists ());
+                               try {
+                                       var instream = fin.read (null);
+                                       var doc = new GDocument.from_stream (instream);
+                                       assert (doc != null);
+                                       // TODO: CHECKS
+                               } catch (GLib.Error e) {
+                                       GLib.message ("%s", e.message);
+                                       assert_not_reached ();
+                               }
+                       });
+               Test.add_func ("/gxml/gdocument/gfile/local", () => {
+                       try {
+                               var f = GLib.File.new_for_path 
(GXmlTestConfig.TEST_SAVE_DIR+"/tw-test-file.xml");
+                               if (f.query_exists ()) f.delete ();
+                               var s = new GLib.StringBuilder ();
+                               s.append ("""<root />""");
+                               var d = new GDocument.from_string (s.str);
+                               Test.message ("Saving to file: "+f.get_uri ()+d.to_string ());
+                               d.save_as (f);
+                               assert (f.query_exists ());
+                               var d2 = new GDocument.from_file (f);
+                               assert (d2 != null);
+                               assert (d2.root != null);
+                               assert (d2.root.name == "root");
+                               f.delete ();
+                       } catch (GLib.Error e) {
+                               GLib.message ("Error: "+e.message);
+                               assert_not_reached ();
+                       }
+                       });
+               Test.add_func ("/gxml/gdocument/gfile/remote", () => {
+                       try {
+                               var net = GLib.NetworkMonitor.get_default ();
+                               if (!net.network_available) return;
+                               var rf = GLib.File.new_for_uri 
("https://git.gnome.org/browse/gxml/plain/gxml.doap";);
+                               assert (rf.query_exists ());
+                               var d = new GDocument.from_file (rf);
+                               assert (d != null);
+                               assert (d.root != null);
+                               assert (d.root.name == "Project");
+                               bool fname, fshordesc, fdescription, fhomepage;
+                               fname = fshordesc = fdescription = fhomepage = false;
+                               foreach (GXml.Node n in d.root.children) {
+                                       if (n.name == "name") fname = true;
+                                       if (n.name == "shortdesc") fshordesc = true;
+                                       if (n.name == "description") fdescription = true;
+                                       if (n.name == "homepage") fhomepage = true;
+                               }
+                               assert (fname);
+                               assert (fshordesc);
+                               assert (fdescription);
+                               assert (fhomepage);
+                               var f = GLib.File.new_for_path (GXmlTestConfig.TEST_SAVE_DIR+"/xml.doap");
+                               d.save_as (f);
+                               assert (f.query_exists ());
+                               f.delete ();
+                       } catch (GLib.Error e) {
+                               GLib.message ("Error: "+e.message);
+                               assert_not_reached ();
+                       }
+               });
+               Test.add_func ("/gxml/gdocument/construct_from_stream_error", () => {
+                               File fin;
+                               InputStream instream;
+                               FileIOStream iostream;
+                               GDocument doc;
+
+                               try {
+                                       fin = File.new_tmp ("gxml.XXXXXX", out iostream);
+                                       doc = new GDocument.from_stream (iostream.input_stream);
+                                       GLib.message ("Passed parse error stream");
+                                       assert_not_reached ();
+                               } catch  {}
+                       });
+               Test.add_func ("/gxml/gdocument/construct_from_string", () => {
+                       try {
+                               string xml;
+                               GDocument doc;
+                               GXml.Node root;
+
+                               xml = "<Fruits><Apple></Apple><Orange></Orange></Fruits>";
+                               doc = new GDocument.from_string (xml);
+                               assert (doc.root != null);
+                               root = doc.root;
+                               assert (root.name == "Fruits");
+                               assert (root.children.size == 2);
+                               var n1 = root.children.get (0);
+                               assert (n1 != null);
+                               assert (n1.name == "Apple");
+                       } catch { assert_not_reached (); }
+                       });
+               Test.add_func ("/gxml/gdocument/construct_from_string_no_root", () => {
+                       try {
+                               string xml;
+                               GDocument doc;
+                               GXml.Node root;
+
+                               xml = """<?xml version="1.0"?>""";
+                               doc = new GDocument.from_string (xml);
+                               assert_not_reached ();
+                       } catch {}
+                       });
+               Test.add_func ("/gxml/gdocument/construct_from_string_invalid", () => {
+                       try {
+                               string xml;
+                               GDocument doc;
+                               GXml.Node root;
+
+                               xml = "";
+                               doc = new GDocument.from_string (xml);
+                       } catch { assert_not_reached (); }
+                       });
+               Test.add_func ("/gxml/gdocument/save", () => {
+                               GDocument doc;
+                               int exit_status;
+
+                               try {
+                                       doc = new GDocument.from_string ("<root />");
+                                       var f = GLib.File.new_for_path 
(GXmlTestConfig.TEST_SAVE_DIR+"/test_out_path.xml");
+                                       doc.save_as (f);
+                                       assert (f.query_exists ());
+                                       f.delete ();
+                               } catch (GLib.Error e) {
+                                       Test.message ("%s", e.message);
+                                       assert_not_reached ();
+                               }
+                       });
+               Test.add_func ("/gxml/gdocument/save_error", () => {
+                               GDocument doc;
+
+                               try {
+                                       doc = new GDocument.from_string ("<root />");
+                                       doc.save_as (GLib.File.new_for_path ("/tmp/a/b/c/d/e/f/g/h/i"));
+                                       assert_not_reached ();
+                               } catch {}
+                       });
+
+               Test.add_func ("/gxml/gdocument/create_element", () => {
+                       try {
+                               GDocument doc = new GDocument.from_string ("<root />");
+                               GElement elem = null;
+
+                               elem = (GElement) doc.create_element ("Banana");
+                               assert (elem.tag_name == "Banana");
+                               assert (elem.tag_name != "banana");
+
+                               elem = (GElement) doc.create_element ("ØÏØÏدÏØÏ  ²øœ³¤ïØ£");
+                       } catch { assert_not_reached (); }
+               });
+               Test.add_func ("/gxml/gdocument/create_text_node", () => {
+                       try {
+                               GDocument doc = new GDocument.from_string ("<root />");
+                               Text text = (Text) doc.create_text ("Star of my dreams");
+
+                               assert (text.name == "#text");
+                               assert (text.value == "Star of my dreams");
+                       } catch { assert_not_reached (); }
+               });
+               Test.add_func ("/gxml/gdocument/create_comment", () => {
+                       try {
+                               GDocument doc = new GDocument.from_string ("<root />");
+                               Comment comment = (GXml.Comment) doc.create_comment ("Ever since the day we 
promised.");
+
+                               assert (comment.name == "#comment");
+                               assert (comment.str == "Ever since the day we promised.");
+                       } catch { assert_not_reached (); }
+               });
+               Test.add_func ("/gxml/gdocument/create_cdata_section", () => {
+                       try {
+                               GDocument doc = new GDocument.from_string ("<root />");
+                               CDATA cdata = (CDATA) doc.create_cdata ("put in real cdata");
+
+                               assert (cdata.name == "#cdata-section");
+                               assert (cdata.value == "put in real cdata");
+                       } catch { assert_not_reached (); }
+               });
+               Test.add_func ("/gxml/gdocument/create_processing_instruction", () => {
+                       try {
+                               GDocument doc = new GDocument.from_string ("<root />");
+                               ProcessingInstruction instruction = (ProcessingInstruction) doc.create_pi 
("target", "data");
+
+                               assert (instruction.name == "target");
+                               assert (instruction.target == "target");
+                               assert (instruction.data == "data");
+                               assert (instruction.value == "data");
+                       } catch { assert_not_reached (); }
+               });
+               Test.add_func ("/gxml/gdocument/create_attribute", () => {
+                       try {
+                               GDocument doc = new GDocument.from_string ("<root />");
+                               assert (doc.root != null);
+                               ((GElement) doc.root).set_attr ("attrname", "attrvalue");
+                               Test.message ("DOC:"+doc.to_string ());
+                               var attr = ((GElement) doc.root).get_attr ("attrname");
+                               Test.message ("Attr name: "+attr.name);
+                               Test.message ("Attr value: "+attr.value);
+                               assert (attr != null);
+                               assert (attr is GAttribute);
+                               assert (attr.name == "attrname");
+                               assert (attr.value == "attrvalue");
+                               //
+                               //Test.message ("DOC libxml2:"+doc.libxml_to_string ());
+                       } catch { assert_not_reached (); }
+               });
+               Test.add_func ("/gxml/gdocument/to_string/basic", () => {
+                       try {
+                               GDocument doc = new GDocument.from_string ("<?xml version=\"1.0\"?>
+<Sentences><Sentence lang=\"en\">I like the colour blue.</Sentence><Sentence lang=\"de\">Ich liebe die 
T&#xFC;r.</Sentence><Authors><Author><Name>Fred</Name><Email>fweasley hogwarts co 
uk</Email></Author><Author><Name>George</Name><Email>gweasley hogwarts co 
uk</Email></Author></Authors></Sentences>");
+                               string s1 = doc.to_string ();
+                               string[] cs1 = s1.split ("\n");
+                               Test.message (s1);
+                               assert (cs1[0] == "<?xml version=\"1.0\"?>");
+                               assert (cs1[1] == "<Sentences><Sentence lang=\"en\">I like the colour 
blue.</Sentence><Sentence lang=\"de\">Ich liebe die 
T&#xFC;r.</Sentence><Authors><Author><Name>Fred</Name><Email>fweasley hogwarts co 
uk</Email></Author><Author><Name>George</Name><Email>gweasley hogwarts co 
uk</Email></Author></Authors></Sentences>");
+                       } catch { assert_not_reached (); }
+               });
+               Test.add_func ("/gxml/gdocument/to_string/extended", () => {
+                       try {
+                               var d = new GDocument.from_path 
(GXmlTestConfig.TEST_DIR+"/gdocument-read.xml");
+                               Test.message (d.to_string ());
+                               assert (d.root != null);
+                               assert (d.root.name == "DataTypeTemplates");
+                               Test.message (d.root.children.size.to_string ());
+                               assert (d.root.children[0] is GXml.Text);
+                               assert (d.root.children[1] is GXml.Element);
+                               assert (d.root.children[2] is GXml.Text);
+                               assert (d.root.children[2].value == "\n");
+                               assert (d.root.children.size == 3);
+                               assert (d.root.children[1].name == "DAType");
+                               assert (d.root.children[1].children.size == 3);
+                               assert (d.root.children[1].children[1].name == "BDA");
+                               assert (d.root.children[1].children[1].children.size == 3);
+                               assert (d.root.children[1].children[1].children[1].name == "Val");
+                               assert (d.root.children[1].children[1].children[1].children.size == 1);
+                               assert (d.root.children[1].children[1].children[1].children[0] is GXml.Text);
+                               assert (d.root.children[1].children[1].children[1].children[0].value == 
"status_only");
+                       } catch (GLib.Error e) { GLib.message ("ERROR: "+e.message); assert_not_reached (); }
+               });
+               Test.add_func ("/gxml/gdocument/libxml_to_string", () => {
+                       try {
+                               GDocument doc = new GDocument.from_string ("<?xml version=\"1.0\"?>
+<Sentences><Sentence lang=\"en\">I like the colour blue.</Sentence><Sentence lang=\"de\">Ich liebe die 
T&#xFC;r.</Sentence><Authors><Author><Name>Fred</Name><Email>fweasley hogwarts co 
uk</Email></Author><Author><Name>George</Name><Email>gweasley hogwarts co 
uk</Email></Author></Authors></Sentences>");
+                               string s1 = doc.libxml_to_string ();
+                               string[] cs1 = s1.split ("\n");
+                               Test.message (s1);
+                               assert (cs1[0] == "<?xml version=\"1.0\"?>");
+                               assert (cs1[1] == "<Sentences><Sentence lang=\"en\">I like the colour 
blue.</Sentence><Sentence lang=\"de\">Ich liebe die 
T&#xFC;r.</Sentence><Authors><Author><Name>Fred</Name><Email>fweasley hogwarts co 
uk</Email></Author><Author><Name>George</Name><Email>gweasley hogwarts co 
uk</Email></Author></Authors></Sentences>");
+                       } catch { assert_not_reached (); }
+               });
+               Test.add_func ("/gxml/gdocument/namespace", () => {
+                       try {
+                               GDocument doc = new GDocument.from_string ("<root><child/></root>");
+                               doc.set_namespace ("http://www.gnome.org/GXml","gxml";);
+                               assert (doc.root != null);
+                               assert (doc.root.namespaces != null);
+                               assert (doc.root.namespaces.size == 1);
+                               assert (doc.root.namespaces[0].prefix == "gxml");
+                               assert (doc.root.namespaces[0].uri == "http://www.gnome.org/GXml";);
+                               assert (doc.root.children != null);
+                               assert (doc.root.children.size == 1);
+                               var c = doc.root.children[0];
+                               c.set_namespace ("http://www.gnome.org/GXml2","gxml2";);
+                               assert (c.namespaces != null);
+                               assert (c.namespaces.size == 1);
+                               assert (c.namespaces[0].prefix == "gxml2");
+                               assert (c.namespaces[0].uri == "http://www.gnome.org/GXml2";);
+                               (c as Element).set_attr ("gxml:prop","val");
+                               var p = (c as Element).get_attr ("gxml:prop");
+                               assert (p == null);
+                               Test.message ("ROOT: "+doc.root.to_string ());
+                               assert (doc.root.to_string () == "<root 
xmlns:gxml=\"http://www.gnome.org/GXml\";><child xmlns:gxml2=\"http://www.gnome.org/GXml2\"/></root>");
+                               (c as Element).set_ns_attr (doc.root.namespaces[0], "prop", "Ten");
+                               Test.message ("ROOT: "+doc.root.to_string ());
+                               assert (c.attrs.size == 1);
+                               var pt = c.attrs.get ("prop");
+                               assert (pt != null);
+                               var pt2 = (c as Element).get_ns_attr ("prop", doc.root.namespaces[0].uri);
+                               Test.message ("ROOT: "+doc.root.to_string ());
+                               assert (doc.root.to_string () == "<root 
xmlns:gxml=\"http://www.gnome.org/GXml\";><child xmlns:gxml2=\"http://www.gnome.org/GXml2\"; 
gxml:prop=\"Ten\"/></root>");
+                       } catch (GLib.Error e) {
+                               GLib.message ("ERROR: "+ e.message);
+                               assert_not_reached ();
+                       }
+               });
+               Test.add_func ("/gxml/gdocument/parent", () => {
+                       var doc = new GDocument ();
+                       assert (doc.parent == null);
+               });
+       }
+}
diff --git a/test/GXmlTest.vala b/test/GXmlTest.vala
index df46144..114d40a 100644
--- a/test/GXmlTest.vala
+++ b/test/GXmlTest.vala
@@ -92,7 +92,7 @@ class GXmlTest {
                xDocument doc = null;
                try {
                        doc = new xDocument.from_path (path != null ? path :
-                                                     get_test_dir () + "/test.xml");
+                                                     GXmlTest.get_test_dir () + "/test.xml");
                } catch (GXml.Error e) {
                        GLib.warning (e.message);
                        assert_not_reached ();
diff --git a/test/TDocumentTest.vala b/test/TDocumentTest.vala
new file mode 100644
index 0000000..aeea0ac
--- /dev/null
+++ b/test/TDocumentTest.vala
@@ -0,0 +1,837 @@
+/* -*- Mode: vala; indent-tabs-mode: t; c-basic-offset: 2; tab-width: 2 -*- */
+/* Notation.vala
+ *
+ * Copyright (C) 2011-2015  Daniel Espinosa <esodan gmail com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see <http://www.gnu.org/licenses/>.
+ *
+ * Authors:
+ *      Daniel Espinosa <esodan gmail com>
+ */
+
+using GXml;
+
+class TDocumentTest : GXmlTest {
+       public class TTestObject : SerializableObjectModel
+       {
+               public string name { get; set; }
+               public override string node_name () { return "Test"; }
+               public override string to_string () { return "TestNode"; }
+       }
+       public static void add_tests () {
+               Test.add_func ("/gxml/t-document", () => {
+                       try {
+                               var d = new TDocument ();
+                               assert (d.name == "#document");
+                               assert (d.root == null);
+                               assert (d.children != null);
+                               assert (d.attrs != null);
+                               assert (d.children.size == 0);
+                               assert (d.value == null);
+                       }
+                       catch (GLib.Error e) {
+#if DEBUG
+                               GLib.message (@"ERROR: $(e.message)");
+#endif
+                               assert_not_reached ();
+                       }
+               });
+               Test.add_func ("/gxml/t-document/root", () => {
+                       try {
+                               var d = new TDocument ();
+                               var e = d.create_element ("root");
+                               d.children.add (e);
+                               assert (d.children.size == 1);
+                               assert (d.root != null);
+                               assert (d.root.name == "root");
+                               assert (d.root.value == "");
+                       }
+                       catch (GLib.Error e) {
+#if DEBUG
+                               GLib.message (@"ERROR: $(e.message)");
+#endif
+                               assert_not_reached ();
+                       }
+               });
+               Test.add_func ("/gxml/t-document/save/root", () => {
+                               try {
+                                       var f = GLib.File.new_for_path 
(GXmlTestConfig.TEST_SAVE_DIR+"/t-test.xml");
+                                       if (f.query_exists ()) f.delete ();
+                                       var d = new TDocument.from_path 
(GXmlTestConfig.TEST_SAVE_DIR+"/t-test.xml");
+                                       var e = d.create_element ("root");
+                                       d.children.add (e);
+                                       assert (d.children.size == 1);
+                                       assert (d.root != null);
+                                       assert (d.root.name == "root");
+                                       assert (d.root.value == "");
+                                       GLib.Test.message ("Saving document to: "+f.get_path ());
+                                       assert (d.save ());
+                                       GLib.Test.message ("Reading saved document to: "+f.get_path ());
+                                       assert (f.query_exists ());
+                                       var istream = f.read ();
+                                       var ostream = new MemoryOutputStream.resizable ();
+                                       ostream.splice (istream, 0);
+                                       assert ("<?xml version=\"1.0\"?>" in ((string)ostream.data));
+                                       assert ("<root/>" in ((string)ostream.data));
+                               }
+                               catch (GLib.Error e) {
+#if DEBUG
+                                       GLib.message (@"ERROR: $(e.message)");
+#endif
+                                       assert_not_reached ();
+                               }
+                       });
+               Test.add_func ("/gxml/t-document/save/root/attribute", () => {
+                               try {
+                                       var f = GLib.File.new_for_path 
(GXmlTestConfig.TEST_SAVE_DIR+"/t-test.xml");
+                                       if (f.query_exists ()) f.delete ();
+                                       var d = new TDocument.from_path 
(GXmlTestConfig.TEST_SAVE_DIR+"/t-test.xml");
+                                       var e = d.create_element ("root");
+                                       d.children.add (e);
+                                       assert (d.children.size == 1);
+                                       assert (d.root != null);
+                                       assert (d.root.name == "root");
+                                       assert (d.root.value == "");
+                                       var root = (GXml.Element) d.root;
+                                       root.set_attr ("Pos","on");
+                                       var at1 = root.get_attr ("Pos");
+                                       assert (at1 != null);
+                                       assert (at1.value == "on");
+                                       root.set_attr ("tKm","1000");
+                                       var at2 = root.get_attr ("tKm");
+                                       assert (at2 != null);
+                                       assert (at2.value == "1000");
+                                       d.save ();
+                                       var istream = f.read ();
+                                       uint8[] buffer = new uint8[2048];
+                                       istream.read_all (buffer, null);
+                                       istream.close ();
+                                       assert ("<?xml version=\"1.0\"?>" in ((string)buffer));
+                                       assert ("<root" in ((string)buffer));
+                                       assert ("Pos=\"on\"" in ((string)buffer));
+                                       assert ("tKm=\"1000\"" in ((string)buffer));
+                               }
+                               catch (GLib.Error e) {
+#if DEBUG
+                                       GLib.message (@"ERROR: $(e.message)");
+#endif
+                                       assert_not_reached ();
+                               }
+                       });
+               Test.add_func ("/gxml/t-document/save/root/content", () => {
+                               try {
+                                       var f = GLib.File.new_for_path 
(GXmlTestConfig.TEST_SAVE_DIR+"/t-test.xml");
+                                       if (f.query_exists ()) f.delete ();
+                                       var d = new TDocument.from_path 
(GXmlTestConfig.TEST_SAVE_DIR+"/t-test.xml");
+                                       var e = d.create_element ("root");
+                                       d.children.add (e);
+                                       assert (d.children.size == 1);
+                                       assert (d.root != null);
+                                       assert (d.root.name == "root");
+                                       assert (d.root.value == "");
+                                       var root = (GXml.Element) d.root;
+                                       root.content = "GXml TDocument Test";
+                                       assert (root.children.size == 1);
+                                       assert (root.content == "GXml TDocument Test");
+                                       var t = root.children.get (0);
+                                       assert (t.value == "GXml TDocument Test");
+                                       assert (t is GXml.Text);
+                                       //GLib.message (@"$d");
+                                       d.save ();
+                                       var istream = f.read ();
+                                       uint8[] buffer = new uint8[2048];
+                                       istream.read_all (buffer, null);
+                                       istream.close ();
+                                       assert ("<?xml version=\"1.0\"?>" in ((string)buffer));
+                                       assert ("<root" in ((string)buffer));
+                                       assert (">GXml TDocument Test<" in ((string)buffer));
+                               }
+                               catch (GLib.Error e) {
+#if DEBUG
+                                       GLib.message (@"ERROR: $(e.message)");
+#endif
+                                       assert_not_reached ();
+                               }
+                       });
+               Test.add_func ("/gxml/t-document/save/root/children", () => {
+                               try {
+                                       var f = GLib.File.new_for_path 
(GXmlTestConfig.TEST_SAVE_DIR+"/t-test.xml");
+                                       if (f.query_exists ()) f.delete ();
+                                       var d = new TDocument.from_path 
(GXmlTestConfig.TEST_SAVE_DIR+"/t-test.xml");
+                                       var e = d.create_element ("root");
+                                       d.children.add (e);
+                                       assert (d.children.size == 1);
+                                       assert (d.root != null);
+                                       assert (d.root.name == "root");
+                                       assert (d.root.value == "");
+                                       var root = (GXml.Element) d.root;
+                                       var e1 = (GXml.Element) d.create_element ("child");
+                                       e1.set_attr ("name","Test1");
+                                       assert (e1.children.size == 0);
+                                       root.children.add (e1);
+                                       var e2 = (GXml.Element) d.create_element ("child");
+                                       e2.set_attr ("name","Test2");
+                                       assert (e2.children.size == 0);
+                                       root.children.add (e2);
+                                       assert (root.children.size == 2);
+                                       d.save ();
+                                       var istream = f.read ();
+                                       uint8[] buffer = new uint8[2048];
+                                       istream.read_all (buffer, null);
+                                       istream.close ();
+                                       assert ("<?xml version=\"1.0\"?>" in ((string)buffer));
+                                       assert ("<root>" in ((string)buffer));
+                                       assert ("</root>" in ((string)buffer));
+                                       assert ("<child name=\"Test1\"/>" in ((string)buffer));
+                                       assert ("<child name=\"Test2\"/>" in ((string)buffer));
+                               }
+                               catch (GLib.Error e) {
+#if DEBUG
+                                       GLib.message (@"ERROR: $(e.message)");
+#endif
+                                       assert_not_reached ();
+                               }
+                       });
+               Test.add_func ("/gxml/t-document/root/children-children", () => {
+#if DEBUG
+                               GLib.message (@"TDocument root children/children...");
+#endif
+                       try {
+#if DEBUG
+                               GLib.message (@"Checking file to save to...");
+#endif
+                               var f = GLib.File.new_for_path (GXmlTestConfig.TEST_SAVE_DIR+"/t-large.xml");
+                               if (f.query_exists ()) f.delete ();
+#if DEBUG
+                               GLib.message (@"Creating Document...");
+#endif
+                               var d = new TDocument.from_path (GXmlTestConfig.TEST_SAVE_DIR+"/t-large.xml");
+                               var e = d.create_element ("bookstore");
+                               d.children.add (e);
+                               assert (d.children.size == 1);
+                               assert (d.root != null);
+                               assert (d.root.name == "bookstore");
+                               assert (d.root.value == "");
+                               var r = (GXml.Element) d.root;
+                               r.set_attr ("name","The Great Book");
+#if DEBUG
+                               GLib.message (@"Creating chidls...");
+#endif
+                               for (int i = 0; i < 5000; i++){
+                                       var b = (GXml.Element) d.create_element ("book");
+                                       r.children.add (b);
+                                       var aths = (GXml.Element) d.create_element ("Authors");
+                                       b.children.add (aths);
+                                       var ath1 = (GXml.Element) d.create_element ("Author");
+                                       aths.children.add (ath1);
+                                       var name1 = (GXml.Element) d.create_element ("Name");
+                                       name1.content = "Fred";
+                                       ath1.children.add (name1);
+                                       var email1 = (GXml.Element) d.create_element ("Email");
+                                       email1.content = "fweasley hogwarts co uk";
+                                       ath1.children.add (email1);
+                                       var ath2 = (GXml.Element) d.create_element ("Author");
+                                       aths.children.add (ath2);
+                                       var name2 = (GXml.Element) d.create_element ("Name");
+                                       name2.content = "Greoge";
+                                       ath2.children.add (name2);
+                                       var email2 = (GXml.Element) d.create_element ("Email");
+                                       email2.content = "gweasley hogwarts co uk";
+                                       ath2.children.add (email2);
+                               }
+                               assert (d.root.children.size == 5000);
+                               foreach (GXml.Node n in d.root.children) {
+                                       assert (n.children.size == 1);
+                                       foreach (GXml.Node cn in n.children) {
+                                               assert (cn.children.size == 2);
+                                               foreach (GXml.Node ccn in cn.children) {
+                                                       assert (ccn.children.size == 2);
+                                               }
+                                       }
+                               }
+                       }
+                       catch (GLib.Error e) {
+                               GLib.message (@"ERROR: $(e.message)");
+                               assert_not_reached ();
+                       }
+               });
+               Test.add_func ("/gxml/t-document/save/children-children", () => {
+#if DEBUG
+                               GLib.message (@"TDocument root children/children...");
+#endif
+                       try {
+#if DEBUG
+                               GLib.message (@"Checking file to save to...");
+#endif
+                               var f = GLib.File.new_for_path (GXmlTestConfig.TEST_SAVE_DIR+"/t-large.xml");
+                               if (f.query_exists ()) f.delete ();
+#if DEBUG
+                               GLib.message (@"Creating Document...");
+#endif
+                               var d = new TDocument.from_path (GXmlTestConfig.TEST_SAVE_DIR+"/t-large.xml");
+                               var e = d.create_element ("bookstore");
+                               d.children.add (e);
+                               assert (d.children.size == 1);
+                               assert (d.root != null);
+                               assert (d.root.name == "bookstore");
+                               assert (d.root.value == "");
+                               var r = (GXml.Element) d.root;
+                               r.set_attr ("name","The Great Book");
+#if DEBUG
+                               GLib.message (@"Creating children...");
+#endif
+                               for (int i = 0; i < 30000; i++){
+                                       var b = (GXml.Element) d.create_element ("book");
+                                       r.children.add (b);
+                                       var aths = (GXml.Element) d.create_element ("Authors");
+                                       b.children.add (aths);
+                                       var ath1 = (GXml.Element) d.create_element ("Author");
+                                       aths.children.add (ath1);
+                                       var name1 = (GXml.Element) d.create_element ("Name");
+                                       name1.content = "Fred";
+                                       ath1.children.add (name1);
+                                       var email1 = (GXml.Element) d.create_element ("Email");
+                                       email1.content = "fweasley hogwarts co uk";
+                                       ath1.children.add (email1);
+                                       var ath2 = (GXml.Element) d.create_element ("Author");
+                                       aths.children.add (ath2);
+                                       var name2 = (GXml.Element) d.create_element ("Name");
+                                       name2.content = "Greoge";
+                                       ath2.children.add (name2);
+                                       var email2 = (GXml.Element) d.create_element ("Email");
+                                       email2.content = "gweasley hogwarts co uk";
+                                       ath2.children.add (email2);
+                               }
+                               assert (d.root.children.size == 30000);
+                               d.save ();
+                               GLib.Test.message ("Reading saved file...");
+                               var fr = GLib.File.new_for_path (GXmlTestConfig.TEST_SAVE_DIR+"/t-large.xml");
+                               assert (fr.query_exists ());
+                               var ostream = new MemoryOutputStream.resizable ();
+                               ostream.splice (fr.read (), GLib.OutputStreamSpliceFlags.NONE);
+                               assert ("<?xml version=\"1.0\"?>" in ((string)ostream.data));
+                               assert ("<bookstore name=\"The Great Book\">" in ((string)ostream.data));
+                               assert ("<book>" in ((string)ostream.data));
+                               assert ("<Authors>" in ((string)ostream.data));
+                               assert ("<Author>" in ((string)ostream.data));
+                               f.delete ();
+                       }
+                       catch (GLib.Error e) {
+#if DEBUG
+                               GLib.message (@"ERROR: $(e.message)");
+#endif
+                               assert_not_reached ();
+                       }
+               });
+               Test.add_func ("/gxml/t-document/save/backup", () => {
+                               try {
+                                       var f = GLib.File.new_for_path 
(GXmlTestConfig.TEST_SAVE_DIR+"/t-test.xml");
+                                       if (f.query_exists ()) f.delete ();
+                                       var ot = new TTestObject ();
+                                       ot.name = "test1";
+                                       var dt = new TDocument ();
+                                       ot.serialize (dt);
+                                       dt.save_as (f);
+                                       var d = new TDocument ();
+                                       var e = d.create_element ("root");
+                                       d.children.add (e);
+                                       assert (d.children.size == 1);
+                                       assert (d.root != null);
+                                       assert (d.root.name == "root");
+                                       assert (d.root.value == "");
+                                       d.save_as (f);
+                                       assert (f.query_exists ());
+                                       var bf = GLib.File.new_for_path 
(GXmlTestConfig.TEST_SAVE_DIR+"/t-test.xml~");
+                                       assert (bf.query_exists ());
+                                       var istream = f.read ();
+                                       var b = new MemoryOutputStream.resizable ();
+                                       b.splice (istream, 0);
+                                       assert ("<?xml version=\"1.0\"?>" in ((string)b.data));
+                                       assert ("<root/>" in ((string)b.data));
+                                       f.delete ();
+                                       bf.delete ();
+                               }
+                               catch (GLib.Error e) {
+#if DEBUG
+                                       GLib.message (@"ERROR: $(e.message)");
+#endif
+                                       assert_not_reached ();
+                               }
+                       });
+               Test.add_func ("/gxml/t-document/to_string", () => {
+                       var doc = new TDocument ();
+                       var r = doc.create_element ("root");
+                       doc.children.add (r);
+#if DEBUG
+                       GLib.message (@"$(doc)");
+#endif
+                       string str = doc.to_string ();
+                       assert ("<?xml version=\"1.0\"?>" in str);
+                       assert ("<root/>" in str);
+                       assert ("<root/>" in doc.to_string ());
+               });
+               Test.add_func ("/gxml/t-document/namespace", () => {
+                               try {
+                                       var doc = new TDocument ();
+                                       doc.children.add (doc.create_element ("root"));
+                                       doc.set_namespace ("http://www.gnome.org/GXml","gxml";);
+                                       Test.message ("ROOT: "+doc.to_string ());
+                                       assert (doc.root != null);
+                                       assert (doc.namespaces != null);
+                                       assert (doc.namespaces.size == 1);
+                                       assert (doc.namespaces[0].prefix == "gxml");
+                                       assert (doc.namespaces[0].uri == "http://www.gnome.org/GXml";);
+                                       doc.root.children.add (doc.create_element ("child"));
+                                       assert (doc.root.children != null);
+                                       assert (doc.root.children.size == 1);
+                                       var c = doc.root.children[0];
+                                       c.set_namespace ("http://www.gnome.org/GXml2","gxml2";);
+                                       assert (c.namespaces != null);
+                                       assert (c.namespaces.size == 1);
+                                       assert (c.namespaces[0].prefix == "gxml2");
+                                       assert (c.namespaces[0].uri == "http://www.gnome.org/GXml2";);
+                                       (c as Element).set_attr ("gxml:prop","val");
+                                       var p = (c as Element).get_attr ("gxml:prop");
+                                       assert (p == null);
+                                       Test.message ("ROOT: "+doc.to_string ());
+                                       string[] str = doc.to_string ().split("\n");
+                                       assert (str[1] == "<root 
xmlns:gxml=\"http://www.gnome.org/GXml\";><gxml2:child xmlns:gxml2=\"http://www.gnome.org/GXml2\"/></root>");
+                                       assert (doc.namespaces[0].prefix == "gxml");
+                                       (c as Element).set_ns_attr (doc.namespaces[0], "prop", "Ten");
+                                       Test.message ("ROOT: "+doc.root.to_string ());
+                                       assert (c.attrs.size == 1);
+                                       var pt = c.attrs.get ("gxml:prop");
+                                       assert (pt != null);
+                                       var pt2 = (c as Element).get_ns_attr ("prop", doc.namespaces[0].uri);
+                                       str = doc.to_string ().split("\n");
+                                       assert (str[1] == "<root 
xmlns:gxml=\"http://www.gnome.org/GXml\";><gxml2:child xmlns:gxml2=\"http://www.gnome.org/GXml2\"; 
gxml:prop=\"Ten\"/></root>");
+                               } catch (GLib.Error e) {
+                                       GLib.message ("ERROR: "+ e.message);
+                                       assert_not_reached ();
+                               }
+                       });
+               Test.add_func ("/gxml/t-document/parent", () => {
+                       var doc = new TDocument ();
+                       assert (doc.parent == null);
+               });
+               Test.add_func ("/gxml/t-document/read/basic", () => {
+                       try {
+                               var f = GLib.File.new_for_path (GXmlTestConfig.TEST_DIR+"/t-read-test.xml");
+                               assert (f.query_exists ());
+                               var d = new TDocument ();
+                               TDocument.read_doc (d, f, null);
+                               //GLib.message ("Doc:"+d.to_string ());
+                               assert (d.root != null);
+                               assert (d.root.name == "Sentences");
+                               assert (d.root.attrs["audience"] != null);
+                               assert (d.root.attrs["audience"].value == "All");
+                               assert (d.root.children.size == 7);
+                               var s1 = d.root.children[0];
+                               assert (s1 != null);
+                               assert (s1.name == "Sentence");
+                               var p1 = s1.attrs["lang"];
+                               assert (p1 != null);
+                               assert (p1.value == "en");
+                               assert (s1.children.size == 1);
+                               assert (s1.children[0] is GXml.Text);
+                               assert (s1.children[0].value == "I like the colour blue.");
+                               var s2 = d.root.children[1];
+                               assert (s2 != null);
+                               assert (s2.name == "Sentence");
+                               var p2 = s2.attrs["lang"];
+                               assert (p2 != null);
+                               assert (p2.value == "es");
+                               assert (s2.children.size == 1);
+                               assert (s2.children[0] is GXml.Text);
+                               assert (s2.children[0].value == "Español");
+                               var s3  = d.root.children[2];
+                               assert (s3 != null);
+                               assert (s3.name == "Authors");
+                               var p3 = s3.attrs["year"];
+                               assert (p3 != null);
+                               assert (p3.value == "2016");
+                               var p31 = s3.attrs["collection"];
+                               assert (p31 != null);
+                               assert (p31.value == "Back");
+                               assert (s3.children.size == 2);
+                               assert (s3.children[0] is GXml.Element);
+                               assert (s3.children[0].name == "Author");
+                               assert (s3.children[1].name == "Author");
+                               var a1 = s3.children[0];
+                               assert (a1 != null);
+                               assert (a1.name == "Author");
+                               assert (a1.children.size == 2);
+                               assert (a1.children[0].name == "Name");
+                               assert (a1.children[0].children.size == 1);
+                               assert (a1.children[0].children[0] is GXml.Text);
+                               assert (a1.children[0].children[0].value == "Fred");
+                               assert (a1.children[1].name == "Email");
+                               assert (a1.children[1].children.size == 1);
+                               assert (a1.children[1].children[0] is GXml.Text);
+                               assert (a1.children[1].children[0].value == "fweasley hogwarts co uk");
+                               var a2 = s3.children[1];
+                               assert (a2 != null);
+                               assert (a2.children.size == 3);
+                               assert (a2.children[1].name == "Name");
+                               assert (a2.children[1].children.size == 1);
+                               assert (a2.children[1].children[0] is GXml.Text);
+                               assert (a2.children[1].children[0].value == "George");
+                               assert (a2.children[2].name == "Email");
+                               assert (a2.children[2].children.size == 1);
+                               assert (a2.children[2].children[0] is GXml.Text);
+                               assert (a2.children[2].children[0].value == "gweasley hogwarts co uk");
+                       } catch (GLib.Error e) { GLib.message ("ERROR: "+e.message); assert_not_reached (); }
+               });
+               Test.add_func ("/gxml/t-document/read/namespace", () => {
+                       try {
+                               var f = GLib.File.new_for_path (GXmlTestConfig.TEST_DIR+"/t-read-test.xml");
+                               assert (f.query_exists ());
+                               var d = new TDocument.from_file (f);
+                               //GLib.message ("Doc:"+d.to_string ());
+                               assert (d.root != null);
+                               assert (d.root.name == "Sentences");
+                               assert (d.root.namespaces.size == 2);
+                               assert (d.root.namespaces[0].prefix == "gxml");
+                               assert (d.root.namespaces[0].uri == "http://wiki.gnome.org/GXml";);
+                               assert (d.root.namespaces[1].prefix == "b");
+                               assert (d.root.namespaces[1].uri == "http://book.org/schema";);
+                               var a = d.root.children[2];
+                               assert (a != null);
+                               assert (a.name == "Authors");
+                               assert (a.namespaces.size == 1);
+                               assert (a.namespaces[0].uri == "http://author.org";);
+                               assert (a.namespaces[0].prefix == "auth");
+                               assert (a.children[0] != null);
+                               var a1 = a.children[0];
+                               assert (a1 != null);
+                               assert (a1.name == "Author");
+                               var e = a1.children[1];
+                               assert (e != null);
+                               assert (e.name == "Email");
+                               assert (e.namespaces.size == 1);
+                               assert (e.namespaces[0].prefix == "gxml");
+                               assert (e.namespaces[0].uri == "http://wiki.gnome.org/GXml";);
+                               var b = d.root.children [3];
+                               assert (b != null);
+                               assert (b.name == "Book");
+                               assert (b.namespaces.size == 1);
+                               assert (b.namespaces[0].prefix == "b");
+                               assert (b.namespaces[0].uri == "http://book.org/schema";);
+                               var bp = b.attrs["gxml:name"];
+                               assert (bp != null);
+                               assert (bp.name == "name");
+                               assert (bp.namespaces.size == 1);
+                               assert (bp.namespaces[0].prefix == "gxml");
+                               assert (bp.namespaces[0].uri == "http://wiki.gnome.org/GXml";);
+                       } catch (GLib.Error e) { GLib.message ("ERROR: "+e.message); assert_not_reached (); }
+               });
+               Test.add_func ("/gxml/t-document/read/comment", () => {
+                       try {
+                               var f = GLib.File.new_for_path (GXmlTestConfig.TEST_DIR+"/t-read-test.xml");
+                               assert (f.query_exists ());
+                               var d = new TDocument.from_file (f);
+                               assert (d.children[0] is GXml.Comment);
+                               assert (d.children[0].value == " Top Level Comment ");
+                               var a = d.root.children[2];
+                               assert (a.name == "Authors");
+                               var a1 = a.children[1];
+                               assert (a1.name == "Author");
+                               assert (a1.children[0] is GXml.Comment);
+                               assert (a1.children[0].value == " Inner comment");
+                               //GLib.message ("Doc:"+d.to_string ());
+                       } catch (GLib.Error e) { GLib.message ("ERROR: "+e.message); assert_not_reached (); }
+               });
+               Test.add_func ("/gxml/t-document/read/pi", () => {
+                       try {
+                               var f = GLib.File.new_for_path (GXmlTestConfig.TEST_DIR+"/t-read-test.xml");
+                               assert (f.query_exists ());
+                               var d = new TDocument.from_file (f);
+                               TDocument.read_doc (d, f, null);
+                               assert (d.children[1] is GXml.ProcessingInstruction);
+                               assert ((d.children[1] as GXml.ProcessingInstruction).target == "target");
+                               assert (d.children[1].value == "Content in target id=\"something\"");
+#if DEBUG
+                               //GLib.message ("Children:"+d.root.children.size.to_string ());
+                               foreach (GXml.Node n in d.root.children) {
+                                       GLib.message ("Node name:"+n.name);
+                               }
+#endif
+                               assert (d.root.children.size == 7);
+                               var p = (d.root.children[4]);
+                               assert (p != null);
+                               assert (p is GXml.ProcessingInstruction);
+                               assert ((p as GXml.ProcessingInstruction).target == "css");
+                               assert ((p as GXml.ProcessingInstruction).value == 
"href=\"http://www.gnome.org\"";);
+                               //GLib.message ("Doc:"+d.to_string ());
+                       } catch (GLib.Error e) { GLib.message ("ERROR: "+e.message); assert_not_reached (); }
+               });
+               Test.add_func ("/gxml/t-document/read/cdata", () => {
+                       try {
+                               var f = GLib.File.new_for_path (GXmlTestConfig.TEST_DIR+"/t-read-test.xml");
+                               assert (f.query_exists ());
+                               var d = new TDocument.from_file (f);
+                               TDocument.read_doc (d, f, null);
+                               assert (d.root.children.size == 7);
+                               var p = (d.root.children[5]);
+                               assert (p != null);
+                               assert (p is GXml.CDATA);
+                               assert ((p as GXml.CDATA).str == "<greeting>Hello, world!</greeting>");
+                               //GLib.message ("Doc:"+d.to_string ());
+                       } catch (GLib.Error e) { GLib.message ("ERROR: "+e.message); assert_not_reached (); }
+               });
+               Test.add_func ("/gxml/t-document/read/uri", () => {
+                       try {
+                               var net = GLib.NetworkMonitor.get_default ();
+                               if (!net.network_available) return;
+                               var rf = GLib.File.new_for_uri 
("https://git.gnome.org/browse/gxml/plain/gxml.doap";);
+                               assert (rf.query_exists ());
+                               var d = new TDocument.from_uri (rf.get_uri ());
+                               assert (d != null);
+                               assert (d.root != null);
+                               assert (d.root.name == "Project");
+                               bool fname, fshordesc, fdescription, fhomepage;
+                               fname = fshordesc = fdescription = fhomepage = false;
+                               foreach (GXml.Node n in d.root.children) {
+                                       if (n.name == "name") fname = true;
+                                       if (n.name == "shortdesc") fshordesc = true;
+                                       if (n.name == "description") fdescription = true;
+                                       if (n.name == "homepage") fhomepage = true;
+                               }
+                               assert (fname);
+                               assert (fshordesc);
+                               assert (fdescription);
+                               assert (fhomepage);
+                               var f = GLib.File.new_for_path (GXmlTestConfig.TEST_SAVE_DIR+"/xml.doap");
+                               d.save_as (f);
+                               assert (f.query_exists ());
+                               f.delete ();
+                       } catch (GLib.Error e) {
+                               GLib.message ("Error: "+e.message);
+                               assert_not_reached ();
+                       }
+               });
+               Test.add_func ("/gxml/t-document/read/stream", () => {
+                       try {
+                               var f = GLib.File.new_for_path (GXmlTestConfig.TEST_DIR+"/t-read-test.xml");
+                               assert (f.query_exists ());
+                               var d = new TDocument.from_stream (f.read ());
+                               //GLib.message ("Doc:"+d.to_string ());
+                               assert (d.root != null);
+                               assert (d.root.name == "Sentences");
+                               assert (d.root.attrs["audience"] != null);
+                               assert (d.root.attrs["audience"].value == "All");
+                               assert (d.root.children.size == 7);
+                               var s1 = d.root.children[0];
+                               assert (s1 != null);
+                               assert (s1.name == "Sentence");
+                               var p1 = s1.attrs["lang"];
+                               assert (p1 != null);
+                               assert (p1.value == "en");
+                               assert (s1.children.size == 1);
+                               assert (s1.children[0] is GXml.Text);
+                               assert (s1.children[0].value == "I like the colour blue.");
+                               var s2 = d.root.children[1];
+                               assert (s2 != null);
+                               assert (s2.name == "Sentence");
+                               var p2 = s2.attrs["lang"];
+                               assert (p2 != null);
+                               assert (p2.value == "es");
+                               assert (s2.children.size == 1);
+                               assert (s2.children[0] is GXml.Text);
+                               assert (s2.children[0].value == "Español");
+                               var s3  = d.root.children[2];
+                               assert (s3 != null);
+                               assert (s3.name == "Authors");
+                               var p3 = s3.attrs["year"];
+                               assert (p3 != null);
+                               assert (p3.value == "2016");
+                               var p31 = s3.attrs["collection"];
+                               assert (p31 != null);
+                               assert (p31.value == "Back");
+                               assert (s3.children.size == 2);
+                               assert (s3.children[0] is GXml.Element);
+                               assert (s3.children[0].name == "Author");
+                               assert (s3.children[1].name == "Author");
+                               var a1 = s3.children[0];
+                               assert (a1 != null);
+                               assert (a1.name == "Author");
+                               assert (a1.children.size == 2);
+                               assert (a1.children[0].name == "Name");
+                               assert (a1.children[0].children.size == 1);
+                               assert (a1.children[0].children[0] is GXml.Text);
+                               assert (a1.children[0].children[0].value == "Fred");
+                               assert (a1.children[1].name == "Email");
+                               assert (a1.children[1].children.size == 1);
+                               assert (a1.children[1].children[0] is GXml.Text);
+                               assert (a1.children[1].children[0].value == "fweasley hogwarts co uk");
+                               var a2 = s3.children[1];
+                               assert (a2 != null);
+                               assert (a2.children.size == 3);
+                               assert (a2.children[1].name == "Name");
+                               assert (a2.children[1].children.size == 1);
+                               assert (a2.children[1].children[0] is GXml.Text);
+                               assert (a2.children[1].children[0].value == "George");
+                               assert (a2.children[2].name == "Email");
+                               assert (a2.children[2].children.size == 1);
+                               assert (a2.children[2].children[0] is GXml.Text);
+                               assert (a2.children[2].children[0].value == "gweasley hogwarts co uk");
+                       } catch (GLib.Error e) { GLib.message ("ERROR: "+e.message); assert_not_reached (); }
+               });
+               Test.add_func ("/gxml/t-document/read/string", () => {
+                       try {
+                               var f = GLib.File.new_for_path (GXmlTestConfig.TEST_DIR+"/t-read-test.xml");
+                               assert (f.query_exists ());
+                               var d = new TDocument.from_string ("<root><child v=\"1\">TEXT</child><doc 
year=\"2016\"><name>COMMUNICATIONS</name></doc></root>");
+                               assert (d.root != null);
+                               assert (d.root.name == "root");
+                               assert (d.root.children[0] != null);
+                               assert (d.root.children[0].name == "child");
+                               assert (d.root.children[0].children[0] is GXml.Text);
+                               assert (d.root.children[0].children[0].value == "TEXT");
+                               assert (d.root.children[1] != null);
+                               assert (d.root.children[1].name == "doc");
+                               assert (d.root.children[1].attrs["year"].value == "2016");
+                               assert (d.root.children[1].children[0] != null);
+                               assert (d.root.children[1].children[0].name == "name");
+                               assert (d.root.children[1].children[0].children[0] is GXml.Text);
+                               assert (d.root.children[1].children[0].children[0].value == "COMMUNICATIONS");
+                       } catch (GLib.Error e) { GLib.message ("ERROR: "+e.message); assert_not_reached (); }
+               });
+               Test.add_func ("/gxml/t-document/read/string/attrs", () => {
+                       try {
+                               var f = GLib.File.new_for_path (GXmlTestConfig.TEST_DIR+"/t-read-test.xml");
+                               assert (f.query_exists ());
+                               var d = new TDocument.from_string ("<root 
xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\";><child v=\"1\" xsi:v=\"VType\">TEXT</child><doc 
year=\"2016\"><name>COMMUNICATIONS</name></doc></root>");
+                               assert (d.root != null);
+                               assert (d.root.name == "root");
+                               assert (d.root.children[0] != null);
+                               assert (d.root.children[0].name == "child");
+                               GLib.message ("child attri: "+(d.root.children[0].attrs.size).to_string ());
+                               assert (d.root.children[0].attrs.size == 2);
+                               assert (d.root.children[0].attrs["v"] != null);
+                               assert (d.root.children[0].children[0] is GXml.Text);
+                               assert (d.root.children[0].children[0].value == "TEXT");
+                               assert (d.root.children[1] != null);
+                               assert (d.root.children[1].name == "doc");
+                               assert (d.root.children[1].attrs["year"].value == "2016");
+                               assert (d.root.children[1].children[0] != null);
+                               assert (d.root.children[1].children[0].name == "name");
+                               assert (d.root.children[1].children[0].children[0] is GXml.Text);
+                               assert (d.root.children[1].children[0].children[0].value == "COMMUNICATIONS");
+                       } catch (GLib.Error e) { GLib.message ("ERROR: "+e.message); assert_not_reached (); }
+               });
+               Test.add_func ("/gxml/t-document/readtype", () => {
+                       try {
+                               var file = GLib.File.new_for_path 
(GXmlTestConfig.TEST_DIR+"/t-read-test.xml");
+                               assert (file.query_exists ());
+                               var d = new TDocument.from_file (file);
+                               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);
+                               GLib.message ("from file");
+                               // Remove all unwanted
+                               TDocument.ReadTypeFunc f1 = (node, tr)=>{
+                                       Test.message ("ReadType check node: "+node.name);
+                                       if (node.name == "NoRead" || node.name == "NoReadChild") {
+                                               Test.message ("Skiping node: "+node.name);
+                                               return TDocument.ReadType.NEXT;
+                                       }
+                                       return TDocument.ReadType.CONTINUE;
+                               };
+                               var d2 = new TDocument.from_file_with_readtype_func (file, f1);
+                               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);
+                               Test.message (@"$d2");
+                               var nc2 = n2.children[2];
+                               assert (nc2 != null);
+                               assert (nc2.name == "Read");
+                               assert (nc2.children.size == 1);
+                               // Checking ReadType.STOP effect
+                               Test.message ("from path");
+                               TDocument.ReadTypeFunc f2 = (node, tr)=>{
+                                       Test.message ("ReadType check node: "+node.name);
+                                       if (node.name == "NoReadChild") {
+                                               Test.message ("Skiping node: "+node.name);
+                                               return TDocument.ReadType.STOP;
+                                       }
+                                       return TDocument.ReadType.CONTINUE;
+                               };
+                               var d3 = new TDocument.from_path_with_readtype_func (file.get_path (), f2);
+                               Test.message (@"$d3");
+                               assert (d3.root != null);
+                               assert (d3.root.children.size == 7);
+                               var n3 = d3.root.children[6];
+                               assert (n3 != null);
+                               assert (n3.name == "ReadTop");
+                               assert (n3.children.size == 4);
+                               var nc3 = n3.children[3];
+                               assert (nc3 != null);
+                               assert (nc3.name == "Read");
+                               assert (nc3.children.size == 1);
+                               // From URI
+                               GLib.message ("from uri");
+                               var d4 = new TDocument.from_uri_with_readtype_func (file.get_uri (), f2);
+                               Test.message (@"$d3");
+                               assert (d4.root != null);
+                               assert (d4.root.children.size == 7);
+                               var n4 = d4.root.children[6];
+                               assert (n4 != null);
+                               assert (n4.name == "ReadTop");
+                               assert (n4.children.size == 4);
+                               var nc4 = n4.children[3];
+                               assert (nc4 != null);
+                               assert (nc4.name == "Read");
+                               assert (nc4.children.size == 1);
+                               // From Stream
+                               GLib.message ("from stream");
+                               var file2 = GLib.File.new_for_path 
(GXmlTestConfig.TEST_DIR+"/t-read-test.xml");
+                               var d5 = new TDocument.from_stream_with_readtype_func (file2.read (), f1);
+                               assert (d5.root != null);
+                               assert (d5.root.children.size == 7);
+                               var n5 = d5.root.children[6];
+                               assert (n5 != null);
+                               assert (n5.name == "ReadTop");
+                               assert (n5.children.size == 4);
+                               Test.message (@"$d2");
+                               var nc5 = n5.children[2];
+                               assert (nc5 != null);
+                               assert (nc5.name == "Read");
+                               assert (nc5.children.size == 1);
+                               // From string
+                               GLib.message ("from string");
+                               var d6 = new TDocument.from_string_with_readtype_func 
("<root><Read/><NoRead/><NoRead/><Read/><NoRead/></root>", f1);
+                               assert (d6.root != null);
+                               assert (d6.root.children.size == 2);
+                               var n6 = d6.root.children[1];
+                               assert (n6 != null);
+                               assert (n6.name == "Read");
+                       } catch (GLib.Error e) {
+                               GLib.message ("Error: "+e.message);
+                               assert_not_reached ();
+                       }
+               });
+       }
+}
diff --git a/test/test.xml b/test/test.xml
new file mode 100644
index 0000000..9a0fa1b
--- /dev/null
+++ b/test/test.xml
@@ -0,0 +1,15 @@
+<?xml version="1.0"?>
+<Sentences>
+  <Sentence lang="en">I like the colour blue.</Sentence>
+  <Sentence lang="de">Ich liebe die T&#xFC;r.</Sentence>
+  <Authors>
+    <Author>
+      <Name>Fred</Name>
+      <Email>fweasley hogwarts co uk</Email>
+    </Author>
+    <Author>
+      <Name>George</Name>
+      <Email>gweasley hogwarts co uk</Email>
+    </Author>
+  </Authors>
+</Sentences>


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