[gxml/serialization: 29/33] Serializable API change for GXml.Element content set



commit 05b08af321e753911ada2652c9dfadf1defdcb6d
Author: Daniel Espinosa <esodan gmail com>
Date:   Thu Dec 12 14:40:58 2013 -0600

    Serializable API change for GXml.Element content set
    
    * Serializable: added serialize_use_xml_node_value () for classes
      requiring to save its content to GXml.Element contents
    * Ported all implementations to new Serializable API
    * Found a bug in deseralize/serialize/deserealize Gee Containers,
      so added tests cases to reproduce it. Not Fixed Yet.

 gxml/NodeList.vala                       |    1 +
 gxml/Serializable.vala                   |   16 +++
 gxml/SerializableGeeArrayList.vala       |    4 +-
 gxml/SerializableGeeDualKeyMap.vala      |    1 +
 gxml/SerializableGeeHashMap.vala         |    1 +
 gxml/SerializableGeeTreeMap.vala         |    1 +
 gxml/SerializableJson.vala               |    3 +-
 gxml/SerializableObjectModel.vala        |   21 +++-
 test/SerializableGeeArrayListTest.vala   |    7 +-
 test/SerializableGeeCollectionsTest.vala |  184 ++++++++++++++++++++++++++++-
 test/SerializableGeeDualKeyMapTest.vala  |   39 +++++++
 test/SerializableGeeHashMapTest.vala     |   48 +++++++--
 test/SerializableObjectModelTest.vala    |   33 +++---
 13 files changed, 315 insertions(+), 44 deletions(-)
---
diff --git a/gxml/NodeList.vala b/gxml/NodeList.vala
index 56ce709..1a0811a 100644
--- a/gxml/NodeList.vala
+++ b/gxml/NodeList.vala
@@ -724,6 +724,7 @@ namespace GXml {
                public bool foreach (ForallFunc<Node> f) {
                        var r = this.get ();
                        bool ret = f(r);
+                       stdout.printf (@"GenericNodeListIterator: Continue = $((ret && this.next 
()).to_string ())\n");
                        if (ret && this.next ())
                                return true;
                        else
diff --git a/gxml/Serializable.vala b/gxml/Serializable.vala
index 80d7e27..1f79bd6 100644
--- a/gxml/Serializable.vala
+++ b/gxml/Serializable.vala
@@ -103,10 +103,26 @@ namespace GXml {
     /**
      * Used to add content in an { link GXml.Element}.
      *
+     * By default no contents is serialized/deseralized. Implementors must implement
+     * { link Serializable.serialize_use_xml_node_value} function returning
+     * { link true} in order to use this property.
+     *
+     * This property is ignored by default. Implementors must implement
+     * { link serialize_use_xml_node_value ()} to return { link true}.
+     *
      * This property is ignored on serialisation.
      */
     public abstract string?  serialized_xml_node_value { get; protected set; default = null; }
     /**
+     * Used to check { link GXml.Element}'s contents must be deseralized.
+     *
+     * By default no contents is serialized/deseralized. Implementors must implement
+     * this function returning { link true} in order to use { link serialized_xml_node_value}
+     * property's value in serialization to set { link Element}'s contents.
+     *
+     */
+    public abstract bool serialize_use_xml_node_value ();
+    /**
      * Defines the way to set Node name.
      */
     public abstract string node_name ();
diff --git a/gxml/SerializableGeeArrayList.vala b/gxml/SerializableGeeArrayList.vala
index 357c524..0dd1459 100644
--- a/gxml/SerializableGeeArrayList.vala
+++ b/gxml/SerializableGeeArrayList.vala
@@ -29,6 +29,7 @@ public class GXml.SerializableArrayList<G> : Gee.ArrayList<G>, Serializable
   public string? serialized_xml_node_value { get; protected set; default=null; }
   public GLib.HashTable<string,GXml.Node> unknown_serializable_property { get; protected set; }
 
+  public virtual bool serialize_use_xml_node_value () { return false; }
   public virtual bool property_use_nick () { return false; }
 
   public virtual string node_name ()
@@ -86,7 +87,8 @@ public class GXml.SerializableArrayList<G> : Gee.ArrayList<G>, Serializable
                               requires (node is Element)
   {
     if (element_type.is_a (typeof (Serializable))) {
-      foreach (G e in this) {
+      for (int i =0; i < size; i++) {
+       G e = get (i);
        ((GXml.Serializable) e).serialize (node);
       }
     }
diff --git a/gxml/SerializableGeeDualKeyMap.vala b/gxml/SerializableGeeDualKeyMap.vala
index c1c1536..cb9de0f 100644
--- a/gxml/SerializableGeeDualKeyMap.vala
+++ b/gxml/SerializableGeeDualKeyMap.vala
@@ -112,6 +112,7 @@ public class GXml.SerializableDualKeyMap<P,S,V> : Object, Serializable
   public string? serialized_xml_node_value { get; protected set; default=null; }
   public GLib.HashTable<string,GXml.Node> unknown_serializable_property { get; protected set; }
 
+  public virtual bool serialize_use_xml_node_value () { return false; }
   public virtual bool property_use_nick () { return false; }
 
   public virtual string node_name ()
diff --git a/gxml/SerializableGeeHashMap.vala b/gxml/SerializableGeeHashMap.vala
index b8544da..4ff1a12 100644
--- a/gxml/SerializableGeeHashMap.vala
+++ b/gxml/SerializableGeeHashMap.vala
@@ -28,6 +28,7 @@ public class GXml.SerializableHashMap<K,V> : Gee.HashMap<K,V>, Serializable
   public string? serialized_xml_node_value { get; protected set; default=null; }
   public GLib.HashTable<string,GXml.Node> unknown_serializable_property { get; protected set; }
 
+  public virtual bool serialize_use_xml_node_value () { return false; }
   public virtual bool property_use_nick () { return false; }
 
   public virtual string node_name ()
diff --git a/gxml/SerializableGeeTreeMap.vala b/gxml/SerializableGeeTreeMap.vala
index 13097a2..2ba8d99 100644
--- a/gxml/SerializableGeeTreeMap.vala
+++ b/gxml/SerializableGeeTreeMap.vala
@@ -28,6 +28,7 @@ public class GXml.SerializableTreeMap<K,V> : Gee.TreeMap<K,V>, Serializable
   public string? serialized_xml_node_value { get; protected set; default=null; }
   public GLib.HashTable<string,GXml.Node> unknown_serializable_property { get; protected set; }
 
+  public virtual bool serialize_use_xml_node_value () { return false; }
   public virtual bool property_use_nick () { return false; }
 
   public virtual string node_name ()
diff --git a/gxml/SerializableJson.vala b/gxml/SerializableJson.vala
index e164c84..b505e34 100644
--- a/gxml/SerializableJson.vala
+++ b/gxml/SerializableJson.vala
@@ -39,7 +39,8 @@ public class GXml.SerializableJson : GLib.Object, Serializable
   public HashTable<string,GLib.ParamSpec>  ignored_serializable_properties { get; protected set; }
   public HashTable<string,GXml.Node>    unknown_serializable_property { get; protected set; }
   public string?  serialized_xml_node_value { get; protected set; default = null; }
- 
+
+  public virtual bool serialize_use_xml_node_value () { return false; }
   public virtual string node_name () { return "Object"; }
   public virtual bool property_use_nick () { return false; }
 
diff --git a/gxml/SerializableObjectModel.vala b/gxml/SerializableObjectModel.vala
index 6f4131d..baa4907 100644
--- a/gxml/SerializableObjectModel.vala
+++ b/gxml/SerializableObjectModel.vala
@@ -28,6 +28,7 @@ public abstract class GXml.SerializableObjectModel : Object, Serializable
   public string? serialized_xml_node_value { get; protected set; default=null; }
   public GLib.HashTable<string,GXml.Node> unknown_serializable_property { get; protected set; }
 
+  public virtual bool serialize_use_xml_node_value () { return false; }
   public virtual bool property_use_nick () { return false; }
 
   public virtual string node_name ()
@@ -84,6 +85,7 @@ public abstract class GXml.SerializableObjectModel : Object, Serializable
 
   public GXml.Node? default_serialize (GXml.Node node) throws GLib.Error
   {
+    stdout.printf (@"$(get_type ().name ()): Serializing on node: $(node.node_name)\n");
     Document doc;
     if (node is Document)
       doc = (Document) node;
@@ -106,9 +108,14 @@ public abstract class GXml.SerializableObjectModel : Object, Serializable
       }
     }
         // Setting element content
-    if (serialized_xml_node_value != null) {
-      var t = doc.create_text_node (serialized_xml_node_value);
-      element.append_child (t);
+    if (serialize_use_xml_node_value ()) {
+      // Set un empty string if no value is set for node contents
+      string t = "";
+      if (serialized_xml_node_value != null)
+        t = serialized_xml_node_value;
+      var tn = doc.create_text_node (t);
+      stdout.printf (@"SETTING CONTENT FOR: $(get_type ().name ()): $(element.node_name): content '$t'\n");
+      element.append_child (tn);
     }
 
     node.append_child (element);
@@ -223,8 +230,12 @@ public abstract class GXml.SerializableObjectModel : Object, Serializable
     {
       foreach (Node n in element.child_nodes)
       {
-        if (n is Text)
-          serialized_xml_node_value = n.node_value;
+        if (n is Text) {
+          if (serialize_use_xml_node_value ()) {
+            serialized_xml_node_value = n.node_value;
+            stdout.printf (@"$(get_type ().name ()): NODE '$(element.node_name)' CONTENT 
'$(n.node_value)'\n");
+          }
+        }
         else if (n is Element)
           deserialize_property (n);
       }
diff --git a/test/SerializableGeeArrayListTest.vala b/test/SerializableGeeArrayListTest.vala
index ee2f85c..218add4 100644
--- a/test/SerializableGeeArrayListTest.vala
+++ b/test/SerializableGeeArrayListTest.vala
@@ -147,11 +147,8 @@ class SerializableGeeArrayListTest : GXmlTest
             assert_not_reached ();
           }
           if (e.name == "Wall") {
-            if (e.serialized_xml_node_value != "FAKE1") {
-              string nc = "";
-              if (e.serialized_xml_node_value != null)
-                nc = e.serialized_xml_node_value;
-              stdout.printf (@"ERROR: incorrect node content. Expected 'FAKE1', got: $(nc)");
+            if (e.serialized_xml_node_value != null) {
+              stdout.printf (@"ERROR: incorrect node '$(e.name)' content. Expected '', got: 
'$(e.serialized_xml_node_value)'");
               assert_not_reached ();
             }
           }
diff --git a/test/SerializableGeeCollectionsTest.vala b/test/SerializableGeeCollectionsTest.vala
index ecf2fac..9021275 100644
--- a/test/SerializableGeeCollectionsTest.vala
+++ b/test/SerializableGeeCollectionsTest.vala
@@ -5,13 +5,49 @@ using Gee;
 
 class SerializableGeeCollectionsTest : GXmlTest
 {
+  class Citizen : SerializableObjectModel
+  {
+    public string ctype { get; set; }
+    public string get_value () { return serialized_xml_node_value; }
+    public void set_value (string val) { serialized_xml_node_value = val; }
+    //Enable set Element content
+    public override bool serialize_use_xml_node_value () { return true; }
+    public override string to_string () { return @"Citizen: $ctype"; }
+    public override string node_name () { return "citizen"; }
+
+    public class Array : SerializableArrayList<Citizen> {}
+  }
+  class Asteroid : SerializableObjectModel
+  {
+    public int size { get; set; }
+    public Asteroid.with_size (int size) { this.size = size; }
+    public string get_value () { return serialized_xml_node_value; }
+    public void set_value (string val) { serialized_xml_node_value = val; }
+    public override string to_string () { return @"$size"; }
+    public override string node_name () { return "asteroid"; }
+    
+    public class Array : SerializableArrayList<Asteroid> {}
+  }
   class Planet : SerializableObjectModel, SerializableMapKey<string>
   {
     public string get_map_key () { return name; }
     public string name { get; set; }
+    public Citizen.Array citizens { get; set; }
     public Planet.named (string name) { this.name = name; }
     public override string node_name () { return "planet"; }
     public override string to_string () { return name; }
+    public override GXml.Node? deserialize (GXml.Node node)
+                                    throws GLib.Error
+                                    requires (node is GXml.Element)
+    {
+      Element element = (Element) node;
+      if (element.has_child_nodes ()) {
+        if (citizens == null)
+          citizens = new Citizen.Array ();
+        citizens.deserialize (element);
+      }
+      return default_deserialize (node);
+    }
 
     public class Collection : SerializableTreeMap<string,Planet> {}
   }
@@ -20,6 +56,7 @@ class SerializableGeeCollectionsTest : GXmlTest
     public string get_map_key () { return name; }
     public string name { get; set; }
     public Planet.Collection planets { get; set; }
+    public Asteroid.Array asteroids { get; set; }
     
     public Space.named (string name) { this.name = name; }
     
@@ -76,7 +113,7 @@ class SerializableGeeCollectionsTest : GXmlTest
   {
     public string model { get; set; }
     public string manufacturer { get; set; }
-    public Space.Collection tested { get; set; }
+    public Space.Collection spaces { get; set; }
 
     public SpaceShip.named (string manufacturer, string model)
     {
@@ -95,9 +132,9 @@ class SerializableGeeCollectionsTest : GXmlTest
     {
       Element element = (Element) node;
       if (element.has_child_nodes ()) {
-        if (tested == null)
-          tested = new Space.Collection ();
-        tested.deserialize (element);
+        if (spaces == null)
+          spaces = new Space.Collection ();
+        spaces.deserialize (element);
       }
       return default_deserialize (node);
     }
@@ -230,11 +267,11 @@ class SerializableGeeCollectionsTest : GXmlTest
           stdout.printf (@"ERROR: Ship MacToy/A1234 not found:\n$(doc)\n");
           assert_not_reached ();
         }
-        if (ship.tested.size != 1) {
-          stdout.printf (@"ERROR: Ship: incorrect size must be 1 got : $(ship.tested.size)\n$(doc)\n");
+        if (ship.spaces.size != 1) {
+          stdout.printf (@"ERROR: Ship: incorrect size must be 1 got : $(ship.spaces.size)\n$(doc)\n");
           assert_not_reached ();
         }
-        var space = ship tested  get ("Alpha Centaury");
+        var space = ship spaces  get ("Alpha Centaury");
         if (space == null) {
           stdout.printf (@"ERROR: Space Alpha Centaury not found:\n$(doc)\n");
           assert_not_reached ();
@@ -259,5 +296,138 @@ class SerializableGeeCollectionsTest : GXmlTest
         assert_not_reached ();
       }
     });
+    Test.add_func ("/gxml/serializable/convined_gee_containers/de-se-deserialize",
+    () => {
+      try {
+        var doc = new Document.from_string ("""<?xml version="1.0"?>
+<base name="AlphaOne" >
+  <chargezone name="A1-1">
+    <ship manufacturer="MacToy" model="A1234">
+      <space name="Alpha Centaury">
+        <planet name="Earth">
+          <citizen ctype="Human">1M</citizen>
+          <citizen ctype="Ghost">10M</citizen>
+        </planet>
+        <planet name="Platon" />
+      </space>
+      <space name="Galax">
+        <planet name="Saminon">
+          <citizen ctype="Humanes">100M</citizen>
+          <citizen ctype="Jeties">1000M</citizen>
+        </planet>
+        <planet name="Platon" />
+      </space>
+    </ship>
+    <ship manufacturer="Memphis" model="AB1">
+      <space name="Alpha Centaury">
+        <planet name="Earth">
+          <citizen ctype="Human">10000M</citizen>
+          <citizen ctype="Ghost">100000M</citizen>
+        </planet>
+        <planet name="Platon" />
+      </space>
+    </ship>
+  </chargezone>
+  <storage name="B4-A4">
+    <refaction manufacturer="MacToy" model="Fly045">
+      <ship manufacturer="MacToy" model="A1234" />
+      <ship manufacturer="MegaTrench" model="G045-1" />
+    </refaction>
+  </storage>
+</base>""");
+        var s = new SpaceBase ();
+        stdout.printf ("\nDeserializing doc\n");
+        s.deserialize (doc);
+        // Check First Deserialize iteration
+        if (s.charge_zone == null) {
+        stdout.printf (@"ERROR: (1de) No charge zone\n");
+          assert_not_reached ();
+        }
+        if (s.charge_zone.spaceships == null) {
+        stdout.printf (@"ERROR: (1de) No spaceships\n");
+          assert_not_reached ();
+        }
+        if (s.charge_zone.spaceships.size != 2) {
+        stdout.printf (@"ERROR: (1de) incorrect spaceships number. Expected 2, got 
$(s.charge_zone.spaceships.size)\n");
+          assert_not_reached ();
+        }
+        var s1 = s.charge_zone.spaceships.get ("MacToy", "A1234");
+        if (s1 == null) {
+        stdout.printf (@"ERROR: No spaceship MacToy/A1234 found\n");
+          assert_not_reached ();
+        }
+        if (s1.spaces == null) {
+        stdout.printf (@"ERROR: No spaces for spaceship MacToy/A1234 found\n");
+          assert_not_reached ();
+        }
+        if (s1.spaces.size != 2) {
+        stdout.printf (@"ERROR: Incorrect spaces size for spaceship MacToy/A1234. Expected 2, got: 
$(s1.spaces.size)\n");
+          assert_not_reached ();
+        }
+        // Check First serialize
+        stdout.printf ("\nSerializing to new doc\n");
+        var ndoc = new Document ();
+        s.serialize (ndoc);
+        stdout.printf (@"Seralized new doc:\n$ndoc\n");
+        assert_not_reached ();
+        // Check Second deserialize
+        stdout.printf ("\nDeserializing new doc\n");
+        var ns = new SpaceBase ();
+        ns.deserialize (ndoc);
+        //stdout.printf (@"$ndoc");
+        //assert_not_reached ();
+        if (ns.serialized_xml_node_value != null) {
+          stdout.printf (@"ERROR: wrong base node content, should be '' got: 
'$(ns.serialized_xml_node_value)''");
+          assert_not_reached ();
+        }
+        if (ns.charge_zone.spaceships.size != 2) {
+          stdout.printf (@"ERROR: wrong spaceships size. Expected 2, got: 
$(ns.charge_zone.spaceships.size)\n");
+          foreach (SpaceShip sh in ns.charge_zone.spaceships.values ()) {
+            stdout.printf (@"Ship: $(sh.manufacturer)\n");
+          }
+          stdout.printf (@"$ndoc");
+          assert_not_reached ();
+        }
+        var chip = ns.charge_zone.spaceships.get ("MacToy","A1234");
+        if (chip.spaces.size != 2) {
+          stdout.printf (@"ERROR: wrong spaces size. Expected 2, got: $(chip.spaces.size)");
+          assert_not_reached ();
+        }
+        // Check xml structure
+        if (ndoc.document_element == null) {
+          stdout.printf ("ERROR: No ROOT element\n");
+          assert_not_reached ();
+        }
+        if (ndoc.document_element.node_name != "base") {
+          stdout.printf ("ERROR: Bad ROOT name\n");
+          assert_not_reached ();
+        }
+        if (!ndoc.document_element.has_child_nodes ()) {
+          stdout.printf ("ERROR: No ROOT's child nodes\n");
+          assert_not_reached ();
+        }
+        int i = 0;
+        foreach (GXml.Node n in ndoc.document_element.child_nodes)
+        {
+          i++;
+          if (n is Text) { if (n.node_value != "") assert_not_reached (); }
+          if (n.node_name == "ChargeZone") {
+            foreach (GXml.Node cn in n.child_nodes)
+            {
+              if (n is Text) { if (n.node_value != "") assert_not_reached (); }
+              
+            }
+          }
+        }
+        if (i != 5) {
+          stdout.printf (@"ERROR: Bad ROOT child nodes. Expected 5, got $(i)\n");
+          assert_not_reached ();
+        }
+      }
+      catch (GLib.Error e) {
+        stdout.printf (@"ERROR: $(e.message)");
+        assert_not_reached ();
+      }
+    });
   }
 }
diff --git a/test/SerializableGeeDualKeyMapTest.vala b/test/SerializableGeeDualKeyMapTest.vala
index 3e98515..2d97690 100644
--- a/test/SerializableGeeDualKeyMapTest.vala
+++ b/test/SerializableGeeDualKeyMapTest.vala
@@ -129,8 +129,12 @@ class SerializableGeeDualKeyMapTest : GXmlTest
         bool found2 = false;
         bool found3 = false;
         bool found4 = false;
+        int nodes = 0;
+        int i = 0;
         foreach (GXml.Node n in root.child_nodes) {
+          nodes++;
           if (n is Element && n.node_name == "spaces") {
+            i++;
             var name = ((Element) n).get_attribute_node ("name");
             var owner = ((Element) n).get_attribute_node ("owner");
             if (name != null && owner != null) {
@@ -141,6 +145,15 @@ class SerializableGeeDualKeyMapTest : GXmlTest
             }
           }
         }
+        if (i != 4) {
+          stdout.printf (@"ERROR: Incorrect number of space nodes. Expected 4, got: $nodes\n$(doc)");
+          assert_not_reached ();
+        }
+        // Consider that root node contents have a valid GXml.Text one
+        if (nodes != 4) {
+          stdout.printf (@"ERROR: Incorrect number of nodes. Expected 5, got: $nodes\n$(doc)");
+          assert_not_reached ();
+        }
         if (!found1) {
           stdout.printf (@"ERROR: 'Big' / 'Floor' not found\n$(doc)");
           assert_not_reached ();
@@ -206,5 +219,31 @@ class SerializableGeeDualKeyMapTest : GXmlTest
         assert_not_reached ();
       }
     });
+    Test.add_func ("/gxml/serializable/serializable_dual_key_map/de-se-deserialize",
+    () => {
+      try {
+        var idoc = new Document.from_string ("""<?xml version="1.0"?>
+<root><spaces name="Small" owner="Wall"/><spaces name="Smallest" owner="Wall"/><spaces name="Big" 
owner="Floor"/><spaces name="Bigger" owner="Floor"/><spark /></root>""");
+        var ic = new SerializableDualKeyMap<string,string,Spaces> ();
+        ic.deserialize (idoc.document_element);
+        if (ic.size != 4) {
+          stdout.printf (@"ERROR: Incorrect size (1st deserialize). Expected 4, got: $(ic.size)\n$idoc\n");
+          assert_not_reached ();
+        }
+        var doc = new Document.from_string ("""<?xml version="1.0"?>
+<root />""");
+        ic.serialize (doc.document_element);
+        var c =  new SerializableDualKeyMap<string,string,Spaces> ();
+        c.deserialize (doc.document_element);
+        if (c.size != 4) {
+          stdout.printf (@"ERROR: Incorrect size. Expected 4, got: $(c.size)\n$doc\n");
+          assert_not_reached ();
+        }
+      }
+      catch (GLib.Error e) {
+        stdout.printf (@"ERROR: $(e.message)");
+        assert_not_reached ();
+      }
+    });
   }
 }
diff --git a/test/SerializableGeeHashMapTest.vala b/test/SerializableGeeHashMapTest.vala
index b6e9a97..be67b83 100644
--- a/test/SerializableGeeHashMapTest.vala
+++ b/test/SerializableGeeHashMapTest.vala
@@ -9,7 +9,13 @@ class SerializableGeeHashMapTest : GXmlTest
     public string name { get; set; }
     public Space.named (string name) { this.name = name; }
     public void set_value (string str) { serialized_xml_node_value = str; }
-    public string get_value () { return serialized_xml_node_value; }
+    public string get_value () {
+      if (serialized_xml_node_value == null)
+        serialized_xml_node_value = "";
+      return serialized_xml_node_value;
+    }
+    // Required when you want to use serialized_xml_node_value
+    public override bool serialize_use_xml_node_value () { return true; }
     public override string node_name () { return "space"; }
     public override string to_string () { return name; }
   }
@@ -267,40 +273,64 @@ class SerializableGeeHashMapTest : GXmlTest
         isc.serialize (doc);
         var sc = new SpaceContainer ();
         sc.deserialize (doc);
+        if (sc.storage == null) {
+          stdout.printf (@"ERROR: No storage found\n");
+          assert_not_reached ();
+        }
         if (sc.storage.size != 5) {
-          stdout.printf (@"ERROR: wrong storage size. Expected 5, got: $(sc.storage.size)");
+          stdout.printf (@"ERROR: wrong storage size. Expected 5, got: $(sc.storage.size)\n");
           assert_not_reached ();
         }
         int i = 0;
         foreach (Space s in sc.storage.values)
           i++;
         if (i != 5) {
-          stdout.printf (@"ERROR: wrong storage size counted. Expected 5, got: $(sc.storage.size)");
+          stdout.printf (@"ERROR: wrong storage size counted. Expected 5, got: $(sc.storage.size)\n");
           assert_not_reached ();
         }
         var s1 = sc.storage.get ("Big");
+        if (s1 == null) {
+          stdout.printf (@"ERROR: space 'Big' not found\n");
+          assert_not_reached ();
+        }
         if (s1.get_value () != "FAKE1") {
-          stdout.printf (@"ERROR: wrong s1 text. Expected 'FAKE1', got: $(s1.get_value ())");
+          stdout.printf (@"ERROR: wrong s1 text. Expected 'FAKE1', got: $(s1.get_value ())\n");
           assert_not_reached ();
         }
         var s2 = sc.storage.get ("Small");
-        if (s2.get_value () != null) {
-          stdout.printf (@"ERROR: wrong s2 text. Expected '', got: $(s2.get_value ())");
+        if (s2 == null) {
+          stdout.printf (@"ERROR: space 'Small' not found\n");
+          assert_not_reached ();
+        }
+        if (s2.get_value () != "") {
+          stdout.printf (@"ERROR: wrong s2 text. Expected '', got: '$(s2.get_value ())'\n");
           assert_not_reached ();
         }
         var s3 = sc.storage.get ("Yum1");
+        if (s3 == null) {
+          stdout.printf (@"ERROR: space 'Yum1' not found\n");
+          assert_not_reached ();
+        }
         if (s3.get_value () != "FAKE2") {
-          stdout.printf (@"ERROR: wrong s3 text. Expected 'FAKE2', got: $(s3.get_value ())");
+          stdout.printf (@"ERROR: wrong s3 text. Expected 'FAKE2', got: $(s3.get_value ())\n");
           assert_not_reached ();
         }
         var s4 = sc.storage.get ("Yum2");
+        if (s4 == null) {
+          stdout.printf (@"ERROR: space 'Yum2' not found\n");
+          assert_not_reached ();
+        }
         if (s4.get_value () != "FAKE3") {
-          stdout.printf (@"ERROR: wrong s4 text. Expected 'FAKE3', got: $(s4.get_value ())");
+          stdout.printf (@"ERROR: wrong s4 text. Expected 'FAKE3', got: $(s4.get_value ())\n");
           assert_not_reached ();
         }
         var s5 = sc.storage.get ("Yum3");
+        if (s5 == null) {
+          stdout.printf (@"ERROR: space 'Yum3' not found\n");
+          assert_not_reached ();
+        }
         if (s5.get_value () != "FAKE5") {
-          stdout.printf (@"ERROR: wrong s5 text. Expected 'FAKE5', got: $(s5.get_value ())");
+          stdout.printf (@"ERROR: wrong s5 text. Expected 'FAKE5', got: $(s5.get_value ())\n");
           assert_not_reached ();
         }
       } catch (GLib.Error e) {
diff --git a/test/SerializableObjectModelTest.vala b/test/SerializableObjectModelTest.vala
index e4a6bc2..2260b64 100644
--- a/test/SerializableObjectModelTest.vala
+++ b/test/SerializableObjectModelTest.vala
@@ -66,24 +66,23 @@ public class Manual : ObjectModel
 {
   public string document { get; set; }
   public int pages { get; set; }
-  public string contents {
-    get { return serialized_xml_node_value; }
-    set { serialized_xml_node_value = value; }
-  }
+  public string get_contents () { return serialized_xml_node_value; }
+  public void set_contents (string val) { serialized_xml_node_value = val; }
   
   public Manual ()
   {
     document = "MANUAL DOCUMENTATION";
     pages = 3;
-    contents = "TEXT INTO THE MANUAL DOCUMENT";
+    set_contents ("TEXT INTO THE MANUAL DOCUMENT");
     init_properties ();
     ignored_serializable_properties.set ("contents", get_class ().find_property ("contents"));
   }
   
   public override string to_string ()
   {
-    return base.to_string () + @"CONTENTS: { $contents }";
+    return base.to_string () + @"CONTENTS: { $(get_contents ())}";
   }
+  public override bool serialize_use_xml_node_value () { return true; }
 }
 
 public class Package : ObjectModel
@@ -349,15 +348,15 @@ class SerializableObjectModelTest : GXmlTest
 <manual document="Specification" pages="3">This is an Specification file</manual>""");
         manual.deserialize (doc);
         if (manual.document != "Specification") {
-          stdout.printf (@"ERROR MANUAL:  document: $(manual.document)\n");
+          stdout.printf (@"ERROR MANUAL:  Bad document value. Expected 'Specification', got: 
$(manual.document)\n");
           assert_not_reached ();
         }
         if (manual.pages != 3) {
-          stdout.printf (@"ERROR MANUAL:  pages: $(manual.pages)\n");
+          stdout.printf (@"ERROR MANUAL:  Bad pages value. Expected '3', got: $(manual.pages)\n");
           assert_not_reached ();
         }
-        if (manual.contents != "This is an Specification file") {
-          stdout.printf (@"ERROR MANUAL:  value: $(manual.contents)\n");
+        if (manual.get_contents () != "This is an Specification file") {
+          stdout.printf (@"ERROR MANUAL:  Bad Element content value. Expected 'This is an Specification 
file', got: $(manual.get_contents ())\n");
           assert_not_reached ();
         }
       }
@@ -411,8 +410,8 @@ class SerializableObjectModelTest : GXmlTest
           stdout.printf (@"ERROR PACKAGE: manual pages: $(package.manual.pages)\n");
           assert_not_reached ();
         }
-        if (package.manual.contents != "This is an Specification file") {
-          stdout.printf (@"ERROR PACKAGE: manual value: $(package.manual.contents)\n");
+        if (package.manual.get_contents () != "This is an Specification file") {
+          stdout.printf (@"ERROR PACKAGE: manual value: $(package.manual.get_contents ())\n");
           assert_not_reached ();
         }
         if (package.computer.manufacturer != "LanCorop") {
@@ -863,8 +862,10 @@ class SerializableObjectModelTest : GXmlTest
           assert_not_reached ();
         }
         // Consider that Element content text (actually none) is considered a GXml.Node
-        if (element.child_nodes.length != 2) {
-            stdout.printf (@"ERROR: UNKNOWN_ATTRIBUTE: SERIALIZATION: Too many child nodes 
$(element.child_nodes.length)");
+        // Because serialize_use_xml_node_value () returns false by default 'FAKE TEXT' is LOST
+        // on serialization
+        if (element.child_nodes.length != 1) {
+            stdout.printf (@"ERROR: UNKNOWN_ATTRIBUTE: SERIALIZATION: Too many child nodes. Expected 2, got 
$(element.child_nodes.length)\n");
             assert_not_reached ();
         }
         bool found = false;
@@ -1079,8 +1080,8 @@ class SerializableObjectModelTest : GXmlTest
       stdout.printf (@"ERROR MANUAL: pages: $(pages.node_value)\n");
       assert_not_reached ();
     }
-    if (element.content != manual.contents) {
-      stdout.printf (@"ERROR MANUAL: content: $(element.content)\n");
+    if (element.content != manual.get_contents ()) {
+      stdout.printf (@"ERROR MANUAL: content: Expected $(manual.get_contents ()): got: 
$(element.content)\n");
       assert_not_reached ();
     }
   }


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