[gxml] Fixes on SerializableArrayList and Unit tests



commit f416a9593a3169f2200b8557328e51ae762bbcee
Author: Daniel Espinosa <esodan gmail com>
Date:   Wed May 6 22:14:41 2015 -0500

    Fixes on SerializableArrayList and Unit tests
    
    * Fixed a bug on SerializableArrayList deserializing nodes
    * Fixed /gxml/performance/tw-serialize

 gxml/SerializableGeeArrayList.vala |   14 +++++++++++-
 gxml/SerializableObjectModel.vala  |   21 ++++++++++++------
 test/gxml-performance.vala         |   40 ++++++++++++++++++++++++++++-------
 3 files changed, 59 insertions(+), 16 deletions(-)
---
diff --git a/gxml/SerializableGeeArrayList.vala b/gxml/SerializableGeeArrayList.vala
index 0ae57d0..faad648 100644
--- a/gxml/SerializableGeeArrayList.vala
+++ b/gxml/SerializableGeeArrayList.vala
@@ -125,11 +125,23 @@ public class GXml.SerializableArrayList<G> : Gee.ArrayList<G>, Serializable, Ser
                                                     this.get_type ().name (), element_type.name ());
     }
     if (node is Element) {
+#if DEBUG
+            GLib.message (@"Deserializing ArrayList on Element: $(node.name)");
+#endif
       foreach (GXml.Node n in node.childs) {
         if (n is Element) {
+#if DEBUG
+            GLib.message (@"Cheking Node $(n.name) on ArrayList in Element: $(node.name)");
+#endif
           var obj = (Serializable) Object.new (element_type);
-          if (n.name == ((Serializable) obj).node_name ()) {
+#if DEBUG
+            GLib.message (@"Creating a new Object to add: '$(obj.node_name ())' to Node: '$(node.name)'");
+#endif
+          if (n.name.down () == ((Serializable) obj).node_name ().down ()) {
             obj.deserialize (n);
+#if DEBUG
+            GLib.message (@"SerializableArrayList: Adding object: '$(obj.node_name ())' to Node: 
'$(node.name)'");
+#endif
             add (obj);
           }
         }
diff --git a/gxml/SerializableObjectModel.vala b/gxml/SerializableObjectModel.vala
index 87a1b1c..d73d264 100644
--- a/gxml/SerializableObjectModel.vala
+++ b/gxml/SerializableObjectModel.vala
@@ -235,13 +235,13 @@ public abstract class GXml.SerializableObjectModel : Object, Serializable
       element = (Element) doc.root;
     return_val_if_fail (element != null, null);
     if (node_name () == null) {
-      message (@"WARNING: Object type '$(get_type ().name ())' have no Node Name defined");
+      GLib.warning (@"WARNING: Object type '$(get_type ().name ())' have no Node Name defined");
       return null;
     }
-#if DEBUG
     if (element.name.down () != node_name ().down ()) {
       GLib.warning (@"Actual node's name is '$(element.name.down ())' expected '$(node_name ().down ())'");
     }
+#if DEBUG
     stdout.printf (@"Deserialize Node: $(element.name)\n");
     stdout.printf (@"Node is: $(element)\n\n");
     stdout.printf (@"Attributes in Node: $(element.name)\n");
@@ -250,14 +250,13 @@ public abstract class GXml.SerializableObjectModel : Object, Serializable
     {
       deserialize_property (attr);
     }
-#if DEBUG
-    stdout.printf (@"Elements Nodes in Node: $(element.name)\n");
-#endif
     if (element.childs.size > 0)
     {
       if (get_type ().is_a (typeof (SerializableContainer)))
       {
-//        stdout.printf (@"This is a Container: found a: $(get_type ().name ())\n");
+#if DEBUG
+        stdout.printf (@"This is a Container: found a: $(get_type ().name ())\n");
+#endif
         ((SerializableContainer) this).init_containers ();
       }
       var cnodes = new Gee.HashMap<string,ParamSpec> ();
@@ -278,6 +277,9 @@ public abstract class GXml.SerializableObjectModel : Object, Serializable
             }
         }
       }
+#if DEBUG
+    stdout.printf (@"Elements Nodes in Node: $(element.name)\n");
+#endif
       foreach (Node n in element.childs)
       {
         if (n is Text) {
@@ -320,13 +322,18 @@ public abstract class GXml.SerializableObjectModel : Object, Serializable
     if (prop == null) {
       // FIXME: Event emit
       if (get_enable_unknown_serializable_property ()) {
-//        stdout.printf (@"Adding node $(property_node.node_name) to $(get_type ().name ())\n");
+#if DEBUG
+    GLib.message (@"Adding unknown node $(property_node.name) to $(get_type ().name ())\n");
+#endif
         unknown_serializable_property.set (property_node.name, property_node);
       }
       return true;
     }
     if (prop.value_type.is_a (typeof (Serializable)))
     {
+#if DEBUG
+      GLib.message (@"'$(property_node.name)' Is Serializable: deserializing");
+#endif
       Value vobj = Value (typeof(Object));
       get_property (prop.name, ref vobj);
       if (vobj.get_object () == null) {
diff --git a/test/gxml-performance.vala b/test/gxml-performance.vala
index 69f5db0..717c396 100644
--- a/test/gxml-performance.vala
+++ b/test/gxml-performance.vala
@@ -42,19 +42,24 @@ class Author : SerializableObjectModel
   public class Array : SerializableArrayList<Author> {}
 }
 
+class Authors : SerializableContainer
+{
+  public string number { get; set; }
+  public Author.Array array { get; set; }
+  public override void init_containers ()
+  {
+    if (array == null)
+      array = new Author.Array ();
+  }
+  public override string to_string () { return @"$(get_type ().name ())"; }
+}
 
-
-class Book : SerializableContainer
+class Book : SerializableObjectModel
 {
   public string year { get; set; }
   public string isbn { get; set; }
   public Name   name { get; set; }
-  public Author.Array authors { get; set; }
-  public override void init_containers ()
-  {
-    if (authors == null)
-      authors = new Author.Array ();
-  }
+  public Authors authors { get; set; }
   public override string to_string () { return @"$(name.get_name ()), $(year)"; }
   public class Array : SerializableArrayList<Book> {}
 }
@@ -154,6 +159,25 @@ public class Performance
         bs.deserialize (d);
         time = Test.timer_elapsed ();
         Test.minimized_result (time, "standard deserialize/performance: %g seconds", time);
+        var author = new Author ();
+        GLib.message (@"Is Serializable $((author is Serializable).to_string ())");
+        assert (bs.name == "The Great Book");
+        assert (bs.books.size > 10);
+        var b = bs.books.first ();
+        assert (b != null);
+        assert (b.name != null);
+        assert (b.name.get_name () == "Book1");
+        assert (b.year == "2015");
+        assert (b.authors != null);
+        assert (b.authors.array != null);
+        GLib.message (@"Authors: $(b.authors.array.size.to_string ())");
+        assert (b.authors.array.size == 2);
+        var a = b.authors.array.first ();
+        assert (a != null);
+        assert (a.name != null);
+        assert (a.name.get_name () == "Fred");
+        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");
         bs.serialize (d2);


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