[gxml] GXml.Serializable API changes. GXml.Node.copy fixes.



commit 8c7fdbcd49c6a324ca95aa546e7caeff2687b984
Author: Daniel Espinosa <esodan gmail com>
Date:   Fri May 8 14:34:05 2015 -0500

    GXml.Serializable API changes. GXml.Node.copy fixes.
    
    * Serializable.unknown_serializable_property renamed and type
      changed to Serializable.unknown_serializable_properties as Gee.Map
    
    * Added Serializable.unknown_serializable_nodes as Gee.Collection
    
    * All Serializable derived classes updated
    
    * Unknown attributes and nodes, are should be stored in a per-object
      TwDocument.root
    
    * Fixed long standing bug about Element.content, by always referencing
      GXml.Text to "built" it and store
    
    * SerializableObjectModel implement above Serializable requirements. All
      other classes just checked not to be affected by the change.
    
    * SerializableObjectModel stores all node's texts as GXml.Text nodes
      and added to childs.
    
    * GXml.Element requires all implementations should use GXml.Text internally
      for texts in node, but concatenate them when get its content
    
    * GXml.Node.copy() fixed Element content copy
    
    * TwDocument API change. Added TwDocument(), TwDocument.for_path() constructors.
      first one creates a tmp file by default.
    
    * Added TwDocument.save_to() to allows save a document to a different file
      without change internal file used by save()
    
    * First implementation of TwDocument.to_string(), not tested yet
    
    * Fixed GXml.Text.value
    
    * xElement.content, follows GXml.Element implemetation, using GXml.Text
      to store its content
    
    * Fixed Unit Test: /gxml/serializable/object_model/deserialize_unknown_property

 gxml/Node.vala                           |   40 +++++++++-
 gxml/Serializable.vala                   |    4 +-
 gxml/SerializableGeeArrayList.vala       |   10 +--
 gxml/SerializableGeeDualKeyMap.vala      |   10 +--
 gxml/SerializableGeeHashMap.vala         |   10 +--
 gxml/SerializableGeeTreeMap.vala         |   10 +--
 gxml/SerializableJson.vala               |   12 +---
 gxml/SerializableObjectModel.vala        |   64 ++++++++++------
 gxml/TwDocument.vala                     |   37 ++++++++-
 gxml/TwText.vala                         |    5 +
 gxml/libxml-Element.vala                 |   30 +++++---
 test/SerializableGeeArrayListTest.vala   |    4 +-
 test/SerializableGeeCollectionsTest.vala |    8 +-
 test/SerializableObjectModelTest.vala    |  128 ++++++++++++++++++++----------
 test/TwDocumentTest.vala                 |   14 ++--
 test/gxml-performance.vala               |    2 +-
 16 files changed, 245 insertions(+), 143 deletions(-)
---
diff --git a/gxml/Node.vala b/gxml/Node.vala
index db7ac5f..dc366b9 100644
--- a/gxml/Node.vala
+++ b/gxml/Node.vala
@@ -91,22 +91,56 @@ public interface GXml.Node : Object
    *
    * Just { link GXml.Element} objects are supported. For attributes, use
    * { link GXml.Element.set_attr} method, passing source's name and value as arguments.
+   *
+   * @param doc: a { link GXml.Document} owning destiny node
+   * @param node: a { link GXml.Element} to copy nodes to
+   * @param source: a { link GXml.Element} to copy nodes from, it could be holded by different { link 
GXml.Document}
    */
   public static bool copy (GXml.Document doc, GXml.Node node, GXml.Node source, bool deep)
   {
+#if DEBUG
+    GLib.message ("Copying GXml.Node");
+#endif
     if (node is GXml.Document) return false;
     if (source is GXml.Element && node is GXml.Element) {
-      ((GXml.Element) node).content = ((GXml.Element) source).content;
+#if DEBUG
+    GLib.message ("Copying source and destiny nodes are GXml.Elements... copying...");
+    GLib.message ("Copying source's attributes to destiny node");
+#endif
       foreach (GXml.Node p in source.attrs.values) {
         ((GXml.Element) node).set_attr (p.name, p.value); // TODO: Namespace
       }
-      if (!deep) return true;
-      foreach (Node c in node.childs) {
+#if DEBUG
+      GLib.message ("Copying source's child nodes to destiny node");
+#endif
+      foreach (Node c in source.childs) {
         if (c is Element) {
+          if (c.name == null) continue;
+#if DEBUG
+            GLib.message (@"Copying child Element node: $(c.name)");
+#endif
+          if (!deep){
+#if DEBUG
+            GLib.message (@"No deep copy was requested, skeeping node $(c.name)");
+#endif
+            continue;
+          }
           var e = doc.create_element (c.name); // TODO: Namespace
           node.childs.add (e);
           copy (doc, e, c, deep);
         }
+        if (c is Text) {
+          if (c.value == null) {
+            GLib.warning ("Text node with NULL string");
+            continue;
+          }
+          var t = doc.create_text (c.value);
+          node.childs.add (t);
+#if DEBUG
+          GLib.message (@"Copying source's Text node '$(source.name)' to destiny node with text: $(c.value) 
: Size= $(node.childs.size)");
+          GLib.message (@"Added Text: $(node.childs.get (node.childs.size - 1))");
+#endif
+        }
       }
     }
     return false;
diff --git a/gxml/Serializable.vala b/gxml/Serializable.vala
index 9437754..23d6b3b 100644
--- a/gxml/Serializable.vala
+++ b/gxml/Serializable.vala
@@ -83,7 +83,7 @@ namespace GXml {
      *
      * This property is ignored on serialisation.
      */
-    public abstract Gee.Map<string,GXml.Attribute>    unknown_serializable_property { get; protected set; }
+    public abstract Gee.Map<string,GXml.Attribute>    unknown_serializable_properties { get; }
 
     
     /**
@@ -105,7 +105,7 @@ namespace GXml {
      *
      * This property is ignored on serialisation.
      */
-    public abstract Gee.Collection<GXml.Node>    unknown_serializable_nodes { get; protected set; }
+    public abstract Gee.Collection<GXml.Node>    unknown_serializable_nodes { get; }
 
     /**
      * Used to add content in an { link GXml.Element}.
diff --git a/gxml/SerializableGeeArrayList.vala b/gxml/SerializableGeeArrayList.vala
index ab3e849..68ab79f 100644
--- a/gxml/SerializableGeeArrayList.vala
+++ b/gxml/SerializableGeeArrayList.vala
@@ -32,25 +32,17 @@ public class GXml.SerializableArrayList<G> : Gee.ArrayList<G>, Serializable, Ser
 {
   Gee.HashMap<string,GXml.Attribute> _unknown_serializable_property = new Gee.HashMap<string,GXml.Attribute> 
();
   Gee.ArrayList<GXml.Node> _unknown_serializable_nodes = new Gee.ArrayList<GXml.Node> ();
-  public Gee.Map<string,GXml.Attribute> unknown_serializable_property
+  public Gee.Map<string,GXml.Attribute> unknown_serializable_properties
   {
     get {
       return _unknown_serializable_property;
     }
-    protected set {
-      if (value is Gee.HashMap)
-        _unknown_serializable_property = (Gee.HashMap<string,GXml.Attribute>) value;
-    }
   }
   public Gee.Collection<GXml.Node> unknown_serializable_nodes
   {
     get {
       return _unknown_serializable_nodes;
     }
-    protected set {
-      if (value is Gee.ArrayList)
-        _unknown_serializable_nodes = (Gee.ArrayList<GXml.Node>) value;
-    }
   }
   protected ParamSpec[] properties { get; set; }
   public GLib.HashTable<string,GLib.ParamSpec> ignored_serializable_properties { get; protected set; }
diff --git a/gxml/SerializableGeeDualKeyMap.vala b/gxml/SerializableGeeDualKeyMap.vala
index ef67225..e210ae6 100644
--- a/gxml/SerializableGeeDualKeyMap.vala
+++ b/gxml/SerializableGeeDualKeyMap.vala
@@ -114,25 +114,17 @@ public class GXml.SerializableDualKeyMap<P,S,V> : Object, Serializable, Serializ
   // Serializable Interface
   Gee.HashMap<string,GXml.Attribute> _unknown_serializable_property = new Gee.HashMap<string,GXml.Attribute> 
();
   Gee.ArrayList<GXml.Node> _unknown_serializable_nodes = new Gee.ArrayList<GXml.Node> ();
-  public Gee.Map<string,GXml.Attribute> unknown_serializable_property
+  public Gee.Map<string,GXml.Attribute> unknown_serializable_properties
   {
     get {
       return _unknown_serializable_property;
     }
-    protected set {
-      if (value is Gee.HashMap)
-        _unknown_serializable_property = (Gee.HashMap<string,GXml.Attribute>) value;
-    }
   }
   public Gee.Collection<GXml.Node> unknown_serializable_nodes
   {
     get {
       return _unknown_serializable_nodes;
     }
-    protected set {
-      if (value is Gee.ArrayList)
-        _unknown_serializable_nodes = (Gee.ArrayList<GXml.Node>) value;
-    }
   }
   protected ParamSpec[] properties { get; set; }
   public GLib.HashTable<string,GLib.ParamSpec> ignored_serializable_properties { get; protected set; }
diff --git a/gxml/SerializableGeeHashMap.vala b/gxml/SerializableGeeHashMap.vala
index 92b294e..25eaa10 100644
--- a/gxml/SerializableGeeHashMap.vala
+++ b/gxml/SerializableGeeHashMap.vala
@@ -30,25 +30,17 @@ public class GXml.SerializableHashMap<K,V> : Gee.HashMap<K,V>, Serializable, Ser
 {
   Gee.HashMap<string,GXml.Attribute> _unknown_serializable_property = new Gee.HashMap<string,GXml.Attribute> 
();
   Gee.ArrayList<GXml.Node> _unknown_serializable_nodes = new Gee.ArrayList<GXml.Node> ();
-  public Gee.Map<string,GXml.Attribute> unknown_serializable_property
+  public Gee.Map<string,GXml.Attribute> unknown_serializable_properties
   {
     get {
       return _unknown_serializable_property;
     }
-    protected set {
-      if (value is Gee.HashMap)
-        _unknown_serializable_property = (Gee.HashMap<string,GXml.Attribute>) value;
-    }
   }
   public Gee.Collection<GXml.Node> unknown_serializable_nodes
   {
     get {
       return _unknown_serializable_nodes;
     }
-    protected set {
-      if (value is Gee.ArrayList)
-        _unknown_serializable_nodes = (Gee.ArrayList<GXml.Node>) value;
-    }
   }
   protected ParamSpec[] properties { get; set; }
   public GLib.HashTable<string,GLib.ParamSpec> ignored_serializable_properties { get; protected set; }
diff --git a/gxml/SerializableGeeTreeMap.vala b/gxml/SerializableGeeTreeMap.vala
index 6f627d2..c4bc0a2 100644
--- a/gxml/SerializableGeeTreeMap.vala
+++ b/gxml/SerializableGeeTreeMap.vala
@@ -30,25 +30,17 @@ public class GXml.SerializableTreeMap<K,V> : Gee.TreeMap<K,V>, Serializable, Ser
 {
   Gee.HashMap<string,GXml.Attribute> _unknown_serializable_property = new Gee.HashMap<string,GXml.Attribute> 
();
   Gee.ArrayList<GXml.Node> _unknown_serializable_nodes = new Gee.ArrayList<GXml.Node> ();
-  public Gee.Map<string,GXml.Attribute> unknown_serializable_property
+  public Gee.Map<string,GXml.Attribute> unknown_serializable_properties
   {
     get {
       return _unknown_serializable_property;
     }
-    protected set {
-      if (value is Gee.HashMap)
-        _unknown_serializable_property = (Gee.HashMap<string,GXml.Attribute>) value;
-    }
   }
   public Gee.Collection<GXml.Node> unknown_serializable_nodes
   {
     get {
       return _unknown_serializable_nodes;
     }
-    protected set {
-      if (value is Gee.ArrayList)
-        _unknown_serializable_nodes = (Gee.ArrayList<GXml.Node>) value;
-    }
   }
   protected ParamSpec[] properties { get; set; }
   public GLib.HashTable<string,GLib.ParamSpec> ignored_serializable_properties { get; protected set; }
diff --git a/gxml/SerializableJson.vala b/gxml/SerializableJson.vala
index 86c99e9..6f7a7db 100644
--- a/gxml/SerializableJson.vala
+++ b/gxml/SerializableJson.vala
@@ -73,25 +73,17 @@ public class GXml.SerializableJson : GLib.Object, GXml.Serializable
   public virtual string node_name () { return "Object"; }
   public virtual bool property_use_nick () { return false; }
 
-  public Gee.Map<string,GXml.Attribute> unknown_serializable_property
+  public Gee.Map<string,GXml.Attribute> unknown_serializable_properties
   {
     get {
       return _unknown_serializable_property;
     }
-    protected set {
-      if (value is Gee.HashMap)
-        _unknown_serializable_property = (Gee.HashMap<string,GXml.Attribute>) value;
-    }
   }
   public Gee.Collection<GXml.Node> unknown_serializable_nodes
   {
     get {
       return _unknown_serializable_nodes;
     }
-    protected set {
-      if (value is Gee.ArrayList)
-        _unknown_serializable_nodes = (Gee.ArrayList<GXml.Node>) value;
-    }
   }
 
   public virtual GLib.ParamSpec? find_property_spec (string property_name)
@@ -280,7 +272,7 @@ public class GXml.SerializableJson : GLib.Object, GXml.Serializable
 
       if (spec == null) {
         GLib.message ("Deserializing object of type '%s' claimed unknown property named '%s'\nXML [%s]", 
ptype, pname, property_node.stringify ());
-          unknown_serializable_property.set (property_node.node_name, (GXml.Attribute) property_node);
+          unknown_serializable_properties.set (property_node.node_name, (GXml.Attribute) property_node);
       }
       else {
         if (spec.value_type.is_a (typeof(Serializable)))
diff --git a/gxml/SerializableObjectModel.vala b/gxml/SerializableObjectModel.vala
index 399a46f..fa2648d 100644
--- a/gxml/SerializableObjectModel.vala
+++ b/gxml/SerializableObjectModel.vala
@@ -37,34 +37,39 @@ using Gee;
  */
 public abstract class GXml.SerializableObjectModel : Object, Serializable
 {
-  Gee.HashMap<string,GXml.Attribute> _unknown_serializable_property = new Gee.HashMap<string,GXml.Attribute> 
();
-  Gee.ArrayList<GXml.Node> _unknown_serializable_nodes = new Gee.ArrayList<GXml.Node> ();
+  // holds all unknown nodes
+  protected GXml.TwDocument _doc;
   /* Serializable interface properties */
   protected ParamSpec[] properties { get; set; }
   public GLib.HashTable<string,GLib.ParamSpec> ignored_serializable_properties { get; protected set; }
   public string? serialized_xml_node_value { get; protected set; default=null; }
   public virtual bool get_enable_unknown_serializable_property () { return false; }
-  public Gee.Map<string,GXml.Attribute> unknown_serializable_property
+  public Gee.Map<string,GXml.Attribute> unknown_serializable_properties
   {
     get {
-      return _unknown_serializable_property;
-    }
-    protected set {
-      if (value is Gee.HashMap)
-        _unknown_serializable_property = (Gee.HashMap<string,GXml.Attribute>) value;
+      return (Gee.Map<string,GXml.Attribute>) _doc.root.attrs;
     }
   }
   public Gee.Collection<GXml.Node> unknown_serializable_nodes
   {
     get {
-      return _unknown_serializable_nodes;
-    }
-    protected set {
-      if (value is Gee.ArrayList)
-        _unknown_serializable_nodes = (Gee.ArrayList<GXml.Node>) value;
+      return _doc.root.childs;
     }
   }
 
+  /**
+   * All unknown nodes, will be stored in a per-object { link GXml.Document}
+   * in its { link GXml.Element} root. Then, all unknown properties will be
+   * stored as properties in document's root and all unknown childs { link GXml.Node}
+   * as root's childs.
+   */
+  construct
+  {
+    _doc = new TwDocument ();
+    var r = _doc.create_element ("root");
+    _doc.childs.add (r);
+  }
+
   public virtual bool serialize_use_xml_node_value () { return false; }
   public virtual bool property_use_nick () { return false; }
 
@@ -141,23 +146,34 @@ public abstract class GXml.SerializableObjectModel : Object, Serializable
     }
     if (get_enable_unknown_serializable_property ()) {
         // Serializing unknown Attributes
-        foreach (GXml.Attribute attr in unknown_serializable_property.values) {
+        foreach (GXml.Attribute attr in unknown_serializable_properties.values) {
           element.set_attr (attr.name, attr.value); // TODO: Namespace
         }
         // Serializing unknown Nodes
         foreach (GXml.Node n in unknown_serializable_nodes) {
+#if DEBUG
+            GLib.message (@"Serializing Unknown NODE: $(n.name) to $(element.name)");
+#endif
           if (n is GXml.Element) {
+#if DEBUG
+            GLib.message (@"Serializing Unknown Element NODE: $(n.name) to $(element.name)");
+#endif
             var e = doc.create_element (n.name);
             GXml.Node.copy (node.document, e, n, true);
+#if DEBUG
+            GLib.message (@"Serialized Unknown Element NODE AS: $(e.to_string ())");
+#endif
             element.childs.add (e);
           }
           if (n is Text) {
-            // If no Element contents is recognized add contents
-            if (!serialize_use_xml_node_value ()) {
-              if (element.content == null)
-                element.content = "";
-              element.content += n.value;
-            }
+            if (n.value == null) GLib.warning ("Text node with NULL or none text");
+            if (n.value == "") continue;
+            var t = doc.create_text (n.value);
+            element.childs.add (t);
+#if DEBUG
+            GLib.message (@"Serializing Unknown Text Node: '$(n.value)' to '$(element.name)' : Size 
$(element.childs.size.to_string ())");
+            GLib.message (@"Added Text: $(element.childs.get (element.childs.size - 1))");
+#endif
           }
         }
     }
@@ -358,10 +374,12 @@ public abstract class GXml.SerializableObjectModel : Object, Serializable
 #if DEBUG
           GLib.message (@"Adding unknown attribute $(property_node.name) to $(get_type ().name ())\n");
 #endif
-          unknown_serializable_property.set (property_node.name, (GXml.Attribute) property_node);
+          ((GXml.Element)_doc.root).set_attr (property_node.name, property_node.value);
         }
-        if (property_node is GXml.Element) {
-          unknown_serializable_nodes.add (property_node);
+        else {
+          var e = _doc.create_element (property_node.name);
+          _doc.root.childs.add (e);
+          GXml.Node.copy (_doc, e, property_node, true);
 #if DEBUG
           GLib.message (@"Adding unknown node $(property_node.name) to $(get_type ().name ()): 
Size=$(unknown_serializable_nodes.size.to_string ())");
 #endif
diff --git a/gxml/TwDocument.vala b/gxml/TwDocument.vala
index 57cefb1..d17325b 100644
--- a/gxml/TwDocument.vala
+++ b/gxml/TwDocument.vala
@@ -24,8 +24,17 @@ using Xml;
 
 public class GXml.TwDocument : GXml.TwNode, GXml.Document
 {
+  protected FileIOStream _doc_iostream;
   GXml.Element _root = null;
-  public TwDocument (string file)
+  public TwDocument ()
+  {
+    try  {
+      file = GLib.File.new_tmp (null, out _doc_iostream);
+    } catch (GLib.Error e) {
+      GLib.warning ("Couldn't create temporaly file for TwDocument:"+e.message);
+    }
+  }
+  public TwDocument.for_path (string file)
   {
     var f = File.new_for_path (file);
     this.file = f;
@@ -77,9 +86,14 @@ public class GXml.TwDocument : GXml.TwNode, GXml.Document
     }
   }
   public bool save (GLib.Cancellable? cancellable = null)
+    throws GLib.Error
     requires (file != null)
   {
-    var tw = new Xml.TextWriter.filename (file.get_path ());
+    return save_to (file, cancellable);
+  }
+  public bool save_to (GLib.File f, GLib.Cancellable? cancellable = null)
+  {
+    var tw = new Xml.TextWriter.filename (f.get_path ());
     tw.start_document ();
     tw.set_indent (indent);
     // Root
@@ -176,4 +190,23 @@ public class GXml.TwDocument : GXml.TwNode, GXml.Document
         tw.flush ();
     }
   }
+  public override string to_string ()
+  {
+    GLib.message ("TwDocument: to_string ()");
+    try {
+      var f = GLib.File.new_tmp (null, null);
+      save_to (f);
+      uint8 buffer[10000];
+      var istream = f.read ();
+      istream.read (buffer);
+      istream.close ();
+      f.delete ();
+      return (string) buffer;
+    } catch (GLib.Error e) {
+#if DEBUG
+      GLib.message ("Error on stringify this TwDocuent: "+e.message);
+#endif
+    }
+    return "";
+  }
 }
diff --git a/gxml/TwText.vala b/gxml/TwText.vala
index 9a0f1f4..9ea5e56 100644
--- a/gxml/TwText.vala
+++ b/gxml/TwText.vala
@@ -31,6 +31,11 @@ public class GXml.TwText : GXml.TwNode, GXml.Text
     ((TwDocument) document).tw = ((TwDocument) d).tw;
     _str = text;
   }
+  // GXml.Node
+  public override string @value {
+    get { return _str; }
+    set { _str = value; }
+  }
   // GXml.Text
   public string str { get { return _str; } }
 }
diff --git a/gxml/libxml-Element.vala b/gxml/libxml-Element.vala
index bd64a4f..3f78e74 100644
--- a/gxml/libxml-Element.vala
+++ b/gxml/libxml-Element.vala
@@ -42,6 +42,8 @@ namespace GXml {
         * URL: [[http://www.w3.org/TR/DOM-Level-1/level-one-core.html#ID-745549614]]
         */
        public class xElement : BackedNode, GXml.Element {
+               string _content = null;
+       
                /* Public properties */
 
                // TODO: find out how to do double-spaces in Valadoc, so we can indent <img...
@@ -430,27 +432,35 @@ namespace GXml {
                 * {{{<shops>
                 *   <shop id="1">Eeylops Owl Emporium</shop>
                 *   <shop id="2">Obscurus Books</shop>
-                * </shops>}}} taking the
+                * </shops>}}}
+                * taking the
                 * node for the shop element with id 1 and using this
                 * method, you would get back "Eeylops Owl Emporiums".
                 * If you used it on the shops element, you'd get
                 * {{{Eeylops Owl EmporiumObscurus Books}}} with the
                 * XML tags omitted.
                 *
-                * Setting content replaces the xElement's children
-                * with a Text node containing `value`.
+                * This property search and contatenade all children { link GXml.Text}
+                * in the { link GXml.Node} and returns them, no mutter were they
+                * are in the tree of childs. When setting, this property creates a new
+                * { link GXml.Text} and add it to this { link GXml.Element}.
                 */
-               // TODO: add test
                public string content {
                        owned get {
-                               // <> in with stringifying child nodes would get escaped, here the content is 
preserved
-                               return base.node->get_content ();
+                               _content = null;
+                               foreach (xNode n in child_nodes) {
+                                       if (n is xText) {
+                                               if (_content == null) _content = "";
+                                               _content += n.value;
+                                       }
+                               }
+                               return _content;
                        }
                        set {
-                               // TODO: check impact on existing child nodes; they will be
-                               //       detached, right?
-                               // TODO: is XML in value interpreted or escaped?
-                               base.node->set_content (value);
+                               if (value != null && value != "") {
+                                       var t = owner_document.create_text_node (value);
+                                       this.append_child (t);
+                               }
                        }
                }
 
diff --git a/test/SerializableGeeArrayListTest.vala b/test/SerializableGeeArrayListTest.vala
index 6cdde4a..a9dd146 100644
--- a/test/SerializableGeeArrayListTest.vala
+++ b/test/SerializableGeeArrayListTest.vala
@@ -72,7 +72,7 @@ class SerializableGeeArrayListTest : GXmlTest
         var o2 = new AElement.named ("Small");
         c.add (o1);
         c.add (o2);
-        var doc = new TwDocument ("/tmp/diieiw81!");
+        var doc = new TwDocument ();
         var root = doc.create_element ("root");
         doc.childs.add (root);
         c.serialize (root);
@@ -145,7 +145,7 @@ class SerializableGeeArrayListTest : GXmlTest
         var iroot = idoc.document_element;
         var ic = new SerializableArrayList<AElement> ();
         ic.deserialize (iroot);
-        var doc = new TwDocument ("/tmp/diieiw81!");
+        var doc = new TwDocument ();
         var root = doc.create_element ("root");
         doc.childs.add (root);
         ic.serialize (root);
diff --git a/test/SerializableGeeCollectionsTest.vala b/test/SerializableGeeCollectionsTest.vala
index 8e4f7fc..ec0e556 100644
--- a/test/SerializableGeeCollectionsTest.vala
+++ b/test/SerializableGeeCollectionsTest.vala
@@ -485,13 +485,13 @@ class SerializableGeeCollectionsTest : GXmlTest
           stdout.printf (@"ERROR: No Refaction MacToy/Fly045 found!\n");
           assert_not_reached ();
         }
-        if (refaction.unknown_serializable_property == null) {
+        if (refaction.unknown_serializable_properties == null) {
           stdout.printf (@"ERROR: Refaction: No unknown properties/nodes found!\n");
           assert_not_reached ();
         }
-        if (refaction.unknown_serializable_property.size != 1) {
-          stdout.printf (@"ERROR: Refaction: Bad unknown properties/nodes number: found 
$(refaction.unknown_serializable_property.size)\n");
-          foreach (GXml.Node unk in refaction.unknown_serializable_property.values)
+        if (refaction.unknown_serializable_properties.size != 1) {
+          stdout.printf (@"ERROR: Refaction: Bad unknown properties/nodes number: found 
$(refaction.unknown_serializable_properties.size)\n");
+          foreach (GXml.Node unk in refaction.unknown_serializable_properties.values)
           {
             string unkv = "___NULL__";
             if (unk.value != null)
diff --git a/test/SerializableObjectModelTest.vala b/test/SerializableObjectModelTest.vala
index 3dbbbe6..f7c16c5 100644
--- a/test/SerializableObjectModelTest.vala
+++ b/test/SerializableObjectModelTest.vala
@@ -148,7 +148,7 @@ public class Package : ObjectModel
   public string unknown_to_string ()
   {
     string t = "";
-    foreach (GXml.Attribute node in unknown_serializable_property.values)
+    foreach (GXml.Attribute node in unknown_serializable_properties.values)
     {
       t+= node.to_string () ;
     }
@@ -818,17 +818,17 @@ class SerializableObjectModelTest : GXmlTest
                      try {
                        unknown_property.deserialize (doc);
 #if DEBUG
-                       foreach (GXml.Attribute a in unknown_property.unknown_serializable_property.values) {
+                       foreach (GXml.Attribute a in unknown_property.unknown_serializable_properties.values) 
{
                          GLib.message (@"Unknown Attribute: $(a.name) = $(a.value)");
                        }
                        foreach (GXml.Node un in unknown_property.unknown_serializable_nodes) {
                          GLib.message (@"Unknown Node: $(un.name) = $(un.to_string ())");
                        }
 #endif
-                       assert (unknown_property.unknown_serializable_property.size == 2);
-                       if (unknown_property.unknown_serializable_property.size != 2) {
-                         stdout.printf (@"ERROR: UNKNOWN_ATTRIBUTE: size 
$(unknown_property.unknown_serializable_property.size.to_string ())\n");
-                         foreach (GXml.Node un in unknown_property.unknown_serializable_property.values) {
+                       assert (unknown_property.unknown_serializable_properties.size == 2);
+                       if (unknown_property.unknown_serializable_properties.size != 2) {
+                         stdout.printf (@"ERROR: UNKNOWN_ATTRIBUTE: size 
$(unknown_property.unknown_serializable_properties.size.to_string ())\n");
+                         foreach (GXml.Node un in unknown_property.unknown_serializable_properties.values) {
                            string sv = "__NULL__";
                            if (un.value != null)
                              sv = un.value;
@@ -836,20 +836,20 @@ class SerializableObjectModelTest : GXmlTest
                          }
                          assert_not_reached ();
                        }
-                       if (!unknown_property.unknown_serializable_property.has_key ("ignore")) {
+                       if (!unknown_property.unknown_serializable_properties.has_key ("ignore")) {
                          stdout.printf (@"ERROR: UNKNOWN_ATTRIBUTE: ignore not found");
                          assert_not_reached ();
                        }
-                       var ignore = unknown_property.unknown_serializable_property.get ("ignore");
+                       var ignore = unknown_property.unknown_serializable_properties.get ("ignore");
                        if (!(ignore is Attr)) {
                          stdout.printf (@"ERROR: UNKNOWN_ATTRIBUTE: ignore is not an GXml.Attr");
                          assert_not_reached ();
                        }
-                       if (!unknown_property.unknown_serializable_property.has_key ("ignore2")) {
+                       if (!unknown_property.unknown_serializable_properties.has_key ("ignore2")) {
                          stdout.printf (@"ERROR: UNKNOWN_ATTRIBUTE: ignore not found");
                          assert_not_reached ();
                        }
-                       var ignore2 = unknown_property.unknown_serializable_property.get ("ignore2");
+                       var ignore2 = unknown_property.unknown_serializable_properties.get ("ignore2");
                        if (!(ignore2 is Attr)) {
                          stdout.printf (@"ERROR: UNKNOWN_ATTRIBUTE: ignore2 is not an GXml.Attr");
                          assert_not_reached ();
@@ -884,66 +884,108 @@ class SerializableObjectModelTest : GXmlTest
                    () => {
                      var doc = new xDocument.from_string ("""<?xml version="1.0"?>
                      <UnknownAttribute ignore="true" ignore2="test">
-                     <UnknownNode direction = "fordward">
-                     <UnknownChild t = "test">
-                     <UnknownChildTwo t = "test">
-                     SECOND FAKE TEXT
-                     </UnknownChildTwo>
-                     </UnknownChild>
-                     </UnknownNode>
-                     FAKE TEXT
-                     </UnknownAttribute>""");
+                      <UnknownNode direction = "fordward">
+                       <UnknownChild t = "test">
+                        <UnknownChildTwo t = "test">SECOND FAKE TEXT</UnknownChildTwo>
+                       </UnknownChild>
+                     </UnknownNode>FAKE TEXT</UnknownAttribute>""");
                      var unknown_property = new UnknownAttribute ();
                      try {
                        unknown_property.deserialize (doc);
-                       var doc2 = new xDocument ();
+                       var doc2 = (GXml.Document) new xDocument ();
+                       GLib.message ("Prepare to Serialize...");
                        unknown_property.serialize (doc2);
-                       if (doc2.document_element == null) {
+                       GLib.message ("After Serialize...");
+#if DEBUG
+                       GLib.message ("Serialized back document: \n"+doc2.to_string ());
+#endif
+                       if (doc2.root == null) {
                          stdout.printf (@"ERROR: UNKNOWN_ATTRIBUTE: SERIALIZATION: No Root xElement");
                          assert_not_reached ();
                        }
-                       xElement element = doc2.document_element;
-                       if (element.node_name.down () != "unknownattribute") {
-                         stdout.printf (@"ERROR: UNKNOWN_ATTRIBUTE: SERIALIZATION: Root xElement Bad name 
$(element.node_name.down ())");
+                       GXml.Element element = (GXml.Element) doc2.root;
+                       if (element.name.down () != "unknownattribute") {
+                         stdout.printf (@"ERROR: UNKNOWN_ATTRIBUTE: SERIALIZATION: Root xElement Bad name 
$(element.name.down ())");
                          assert_not_reached ();
                        }
-                       var ignore = element.get_attribute_node ("ignore");
+                       var ignore = element.attrs.get ("ignore");
                        if (ignore == null) {
                          stdout.printf (@"ERROR: UNKNOWN_ATTRIBUTE: SERIALIZATION: No attribute ignore");
                          assert_not_reached ();
                        }
-                       if (ignore.node_value != "true") {
-                         stdout.printf (@"ERROR: UNKNOWN_ATTRIBUTE: SERIALIZATION: Attribute ignore bad 
value $(ignore.node_value)");
+                       if (ignore.value != "true") {
+                         stdout.printf (@"ERROR: UNKNOWN_ATTRIBUTE: SERIALIZATION: Attribute ignore bad 
value $(ignore.value)");
                          assert_not_reached ();
                        }
-                       var ignore2 = element.get_attribute_node ("ignore2");
+                       var ignore2 = element.attrs.get ("ignore2");
                        if (ignore2 == null) {
                          stdout.printf (@"ERROR: UNKNOWN_ATTRIBUTE: SERIALIZATION: No attribute ignore");
                          assert_not_reached ();
                        }
-                       if (ignore2.node_value != "test") {
-                         stdout.printf (@"ERROR: UNKNOWN_ATTRIBUTE: SERIALIZATION: Attribute ignore2 bad 
value $(ignore2.node_value)");
+                       if (ignore2.value != "test") {
+                         stdout.printf (@"ERROR: UNKNOWN_ATTRIBUTE: SERIALIZATION: Attribute ignore2 bad 
value $(ignore2.value)");
                          assert_not_reached ();
                        }
-                       if (!element.has_child_nodes ()) {
+                       if (element.childs.size == 0) {
                          stdout.printf (@"ERROR: UNKNOWN_ATTRIBUTE: SERIALIZATION: No child nodes");
                          assert_not_reached ();
                        }
-                       if (element.child_nodes.length != 2) {
-                         stdout.printf (@"ERROR: UNKNOWN_ATTRIBUTE: SERIALIZATION: Too many child nodes. 
Expected 2, got $(element.child_nodes.length)\n");
-                         assert_not_reached ();
-                       }
+                       assert (element.childs.size == 2);
+                       var unkn = element.childs.get (0);
+                       assert (unkn != null);
+                       assert (unkn.name == "UnknownNode");
+                       int countechilds = 0;
+                       GXml.Node child = unkn;
+                       foreach (GXml.Node n in unkn.childs) {
+                         if (n is GXml.Element) countechilds++;
+                         if (n.name == "UnknownChild") child = n;
+                       }
+                       assert (countechilds == 1);
+                       var cunkn = child;
+                       assert (cunkn != null);
+                       assert (cunkn.name == "UnknownChild");
+                       assert (cunkn.attrs.size == 1);
+                       var ca = cunkn.attrs.get ("t");
+                       assert (ca != null);
+                       assert (ca.value == "test");
+                       countechilds = 0;
+                       foreach (GXml.Node cn in cunkn.childs) {
+                         if (cn is GXml.Element) countechilds++;
+                         if (cn.name == "UnknownChildTwo") child = cn;
+                       }
+                       assert (countechilds == 1);
+                       var scunkn = child;
+                       assert (scunkn != null);
+                       assert (scunkn.name == "UnknownChildTwo");
+                       var sca = scunkn.attrs.get ("t");
+                       assert (sca != null);
+                       assert (sca.value == "test");
                        bool found = false;
-                       foreach (GXml.xNode n in element.child_nodes) {
-                         if (n.node_name == "UnknownNode") {
+#if DEBUG
+                       GLib.message (@"Second unknown child. Childs nodes = $(scunkn.childs.size)");
+#endif
+                       foreach (GXml.Node tn in scunkn.childs) {
+                         assert (tn is GXml.Text);
+#if DEBUG
+                       GLib.message (@"Second unknown Text child = $(tn.value)");
+#endif
+                         if (tn.value == "SECOND FAKE TEXT") found = true;
+                       }
+                       assert (found);
+                       var tscunkn = cunkn.childs.get (0);
+                       assert (tscunkn is GXml.Text);
+                       assert (element.content == "FAKE TEXT");
+                       found = false;
+                       foreach (GXml.Node n in element.childs) {
+                         if (n.name == "UnknownNode") {
                            found = true;
-                           var direction = ((xElement) n).get_attribute_node ("direction");
+                           var direction = ((Element) n).attrs.get ("direction");
                            if (direction == null)  {
                              stdout.printf (@"ERROR: UNKNOWN_ATTRIBUTE: SERIALIZATION: UnknownNode No 
attribute direction");
                              assert_not_reached ();
                            }
-                           if (direction.node_value != "fordward") {
-                             stdout.printf (@"ERROR: UNKNOWN_ATTRIBUTE: SERIALIZATION: UnknownNode attribute 
direction bad value $(direction.node_value)");
+                           if (direction.value != "fordward") {
+                             stdout.printf (@"ERROR: UNKNOWN_ATTRIBUTE: SERIALIZATION: UnknownNode attribute 
direction bad value $(direction.value)");
                              assert_not_reached ();
                            }
                          }
@@ -975,7 +1017,7 @@ class SerializableObjectModelTest : GXmlTest
                        var ndoc = new xDocument ();
                        unknown_property.serialize (ndoc);
                        if (ndoc.document_element.child_nodes.size != 2) {
-                         stdout.printf (@"ERROR: Root incorrect child node number: found 
'$(doc.document_element.child_nodes.size)\n");
+                         stdout.printf (@"ERROR: Root incorrect child node number: found 
'$(doc.document_element.childs.size)\n");
                          foreach (GXml.xNode rn in ndoc.document_element.child_nodes) {
                            string nv = "__NULL__";
                            if (rn.node_value != null)
@@ -1042,8 +1084,8 @@ class SerializableObjectModelTest : GXmlTest
 UNKNOWN CONTENT
 </PACKAGE>""");
         p.deserialize (doc);
-        assert (p.unknown_serializable_property != null);
-        var ukattr = p.unknown_serializable_property.get ("Unknown");
+        assert (p.unknown_serializable_properties != null);
+        var ukattr = p.unknown_serializable_properties.get ("Unknown");
         assert (ukattr != null);
         assert (ukattr.name == "Unknown");
         assert (ukattr.value == "2/4.04");
diff --git a/test/TwDocumentTest.vala b/test/TwDocumentTest.vala
index 64d127b..5ba7ebb 100644
--- a/test/TwDocumentTest.vala
+++ b/test/TwDocumentTest.vala
@@ -30,7 +30,7 @@ class TwDocumentTest : GXmlTest {
                        try {
                                var f = GLib.File.new_for_path (GXmlTestConfig.TEST_SAVE_DIR+"/tw-test.xml");
                                if (f.query_exists ()) f.delete ();
-                               var d = new TwDocument (GXmlTestConfig.TEST_SAVE_DIR+"/tw-test.xml");
+                               var d = new TwDocument.for_path (GXmlTestConfig.TEST_SAVE_DIR+"/tw-test.xml");
                                var e = d.create_element ("root");
                                d.childs.add (e);
                                assert (d.childs.size == 1);
@@ -49,7 +49,7 @@ class TwDocumentTest : GXmlTest {
                                try {
                                        var f = GLib.File.new_for_path 
(GXmlTestConfig.TEST_SAVE_DIR+"/tw-test.xml");
                                        if (f.query_exists ()) f.delete ();
-                                       var d = new TwDocument (GXmlTestConfig.TEST_SAVE_DIR+"/tw-test.xml");
+                                       var d = new TwDocument.for_path 
(GXmlTestConfig.TEST_SAVE_DIR+"/tw-test.xml");
                                        var e = d.create_element ("root");
                                        d.childs.add (e);
                                        assert (d.childs.size == 1);
@@ -75,7 +75,7 @@ class TwDocumentTest : GXmlTest {
                                try {
                                        var f = GLib.File.new_for_path 
(GXmlTestConfig.TEST_SAVE_DIR+"/tw-test.xml");
                                        if (f.query_exists ()) f.delete ();
-                                       var d = new TwDocument (GXmlTestConfig.TEST_SAVE_DIR+"/tw-test.xml");
+                                       var d = new TwDocument.for_path 
(GXmlTestConfig.TEST_SAVE_DIR+"/tw-test.xml");
                                        var e = d.create_element ("root");
                                        d.childs.add (e);
                                        assert (d.childs.size == 1);
@@ -112,7 +112,7 @@ class TwDocumentTest : GXmlTest {
                                try {
                                        var f = GLib.File.new_for_path 
(GXmlTestConfig.TEST_SAVE_DIR+"/tw-test.xml");
                                        if (f.query_exists ()) f.delete ();
-                                       var d = new TwDocument (GXmlTestConfig.TEST_SAVE_DIR+"/tw-test.xml");
+                                       var d = new TwDocument.for_path 
(GXmlTestConfig.TEST_SAVE_DIR+"/tw-test.xml");
                                        var e = d.create_element ("root");
                                        d.childs.add (e);
                                        assert (d.childs.size == 1);
@@ -141,7 +141,7 @@ class TwDocumentTest : GXmlTest {
                                try {
                                        var f = GLib.File.new_for_path 
(GXmlTestConfig.TEST_SAVE_DIR+"/tw-test.xml");
                                        if (f.query_exists ()) f.delete ();
-                                       var d = new TwDocument (GXmlTestConfig.TEST_SAVE_DIR+"/tw-test.xml");
+                                       var d = new TwDocument.for_path 
(GXmlTestConfig.TEST_SAVE_DIR+"/tw-test.xml");
                                        var e = d.create_element ("root");
                                        d.childs.add (e);
                                        assert (d.childs.size == 1);
@@ -186,7 +186,7 @@ class TwDocumentTest : GXmlTest {
 #if DEBUG
                                GLib.message (@"Creating Document...");
 #endif
-                               var d = new TwDocument (GXmlTestConfig.TEST_SAVE_DIR+"/tw-large.xml");
+                               var d = new TwDocument.for_path 
(GXmlTestConfig.TEST_SAVE_DIR+"/tw-large.xml");
                                var e = d.create_element ("bookstore");
                                d.childs.add (e);
                                assert (d.childs.size == 1);
@@ -249,7 +249,7 @@ class TwDocumentTest : GXmlTest {
 #if DEBUG
                                GLib.message (@"Creating Document...");
 #endif
-                               var d = new TwDocument (GXmlTestConfig.TEST_SAVE_DIR+"/tw-large.xml");
+                               var d = new TwDocument.for_path 
(GXmlTestConfig.TEST_SAVE_DIR+"/tw-large.xml");
                                var e = d.create_element ("bookstore");
                                d.childs.add (e);
                                assert (d.childs.size == 1);
diff --git a/test/gxml-performance.vala b/test/gxml-performance.vala
index bdff794..1d28c63 100644
--- a/test/gxml-performance.vala
+++ b/test/gxml-performance.vala
@@ -218,7 +218,7 @@ public class Performance
         assert (a.email != null);
         assert (a.email.get_mail () == "fweasley hogwarts co uk");
         Test.timer_start ();
-        var d2 = new TwDocument (GXmlTest.get_test_dir () + "/test-large.xml");
+        var d2 = new TwDocument.for_path (GXmlTest.get_test_dir () + "/test-large.xml");
         bs.serialize (d2);
         time = Test.timer_elapsed ();
         Test.minimized_result (time, "TwDocument serialize/performance: %g seconds", time);



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