[gxml] Fixes on SerializableDualKeyMap



commit 5b66d4b637e5cf9b74a4a1c3d2b3aded44d6644c
Author: Daniel Espinosa <esodan gmail com>
Date:   Thu May 7 13:00:11 2015 -0500

    Fixes on SerializableDualKeyMap
    
    * Supports node lowercase nodes' name
    * Replaces test-large.xml.in by test-large.xml
    * Added Unit Test for SerializableArrayList and SerializableDualKeyMap
      for lowercase node's name

 configure.ac                               |    1 -
 gxml/SerializableGeeArrayList.vala         |    4 +-
 gxml/SerializableGeeDualKeyMap.vala        |   14 ++++++++-
 test/Makefile.am                           |    1 +
 test/SerializableGeeArrayListTest.vala     |   29 +++++++++++++++++
 test/SerializableGeeDualKeyMapTest.vala    |   30 ++++++++++++++++++
 test/gxml-performance.vala                 |   22 ++++++++++++-
 test/test-collection.xml                   |   46 ++++++++++++++++++++++++++++
 test/{test-large.xml.in => test-large.xml} |    0
 9 files changed, 141 insertions(+), 6 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index cb5f720..5cd8bde 100644
--- a/configure.ac
+++ b/configure.ac
@@ -282,7 +282,6 @@ gxml/gxml-0.6.pc
 gxml/Makefile
 test/Makefile
 test/test.xml
-test/test-large.xml
 test/test_invalid.xml
 test/test_out_path_expected.xml
 test/test_out_stream_expected.xml
diff --git a/gxml/SerializableGeeArrayList.vala b/gxml/SerializableGeeArrayList.vala
index c02d34f..35c527d 100644
--- a/gxml/SerializableGeeArrayList.vala
+++ b/gxml/SerializableGeeArrayList.vala
@@ -135,12 +135,12 @@ public class GXml.SerializableArrayList<G> : Gee.ArrayList<G>, Serializable, Ser
 #endif
           var obj = (Serializable) Object.new (element_type);
 #if DEBUG
-            GLib.message (@"Creating a new Object to add: '$(obj.node_name ())' to Node: '$(node.name)'");
+            GLib.message (@"Creating a new Object to add: '$(obj.node_name ())' from 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)'");
+            GLib.message (@"SerializableArrayList: Adding object: '$(obj.node_name ())' from Node: 
'$(node.name)'");
 #endif
             add (obj);
           }
diff --git a/gxml/SerializableGeeDualKeyMap.vala b/gxml/SerializableGeeDualKeyMap.vala
index 68ec52c..f6306c8 100644
--- a/gxml/SerializableGeeDualKeyMap.vala
+++ b/gxml/SerializableGeeDualKeyMap.vala
@@ -200,6 +200,9 @@ public class GXml.SerializableDualKeyMap<P,S,V> : Object, Serializable, Serializ
                     throws GLib.Error
                     requires (node is Element)
   {
+#if DEBUG
+            GLib.message (@"Deserializing DualKeyMap on Element: $(node.name)");
+#endif
     if (!(value_type.is_a (typeof (GXml.Serializable)) &&
         value_type.is_a (typeof (SerializableMapDualKey)))) {
       throw new SerializableError.UNSUPPORTED_TYPE_ERROR ("%s: Value type '%s' is unsupported", 
@@ -208,9 +211,18 @@ public class GXml.SerializableDualKeyMap<P,S,V> : Object, Serializable, Serializ
     foreach (GXml.Node n in node.childs) {
       if (n is Element) {
         var obj = (SerializableMapDualKey<P,S>) Object.new (value_type);
-        if (n.name == ((Serializable) obj).node_name ()) {
+#if DEBUG
+            GLib.message (@"Creating a new Object to add: '$(((Serializable)obj).node_name ())' from Node: 
'$(node.name)'");
+#endif
+        if (n.name.down () == ((Serializable) obj).node_name ().down ()) {
           ((Serializable) obj).deserialize (n);
+#if DEBUG
+            GLib.message (@"SerializableDualKeyMap: Setting object: '$(((Serializable)obj).node_name ())' 
from Node: '$(node.name)'");
+#endif
           @set (obj.get_map_primary_key (), obj.get_map_secondary_key (), obj);
+#if DEBUG
+            GLib.message (@"SerializableDualKeyMap: Size = '$(this.size)'");
+#endif
         }
       }
     }
diff --git a/test/Makefile.am b/test/Makefile.am
index 1501996..07a4362 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -106,6 +106,7 @@ DISTCLEANFILES = _serialization_test_*.xml
 
 EXTRA_DIST += \
        $(sources) \
+       test-large.xml \
        test_invalid.xml \
        test_with_ns.xml \
        test_out_path_expected.xml \
diff --git a/test/SerializableGeeArrayListTest.vala b/test/SerializableGeeArrayListTest.vala
index b93e20b..6cdde4a 100644
--- a/test/SerializableGeeArrayListTest.vala
+++ b/test/SerializableGeeArrayListTest.vala
@@ -174,5 +174,34 @@ class SerializableGeeArrayListTest : GXmlTest
         assert_not_reached ();
       }
     });
+    Test.add_func ("/gxml/serializable/serializable_array_list/deserialize-node-names",
+    () => {
+      try {
+        var d = new xDocument.from_path (GXmlTestConfig.TEST_DIR + "/test-collection.xml");
+        var bs = new BookStore ();
+        bs.deserialize (d);
+        assert (bs.name == "The Great Book");
+        assert (bs.books.size == 3);
+        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);
+        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");
+      } catch (GLib.Error e) {
+#if DEBUG
+        GLib.message ("ERROR: "+e.message);
+#endif
+        assert_not_reached ();
+      }
+    });
   }
 }
diff --git a/test/SerializableGeeDualKeyMapTest.vala b/test/SerializableGeeDualKeyMapTest.vala
index 0baf80d..e62d2d4 100644
--- a/test/SerializableGeeDualKeyMapTest.vala
+++ b/test/SerializableGeeDualKeyMapTest.vala
@@ -267,5 +267,35 @@ class SerializableGeeDualKeyMapTest : GXmlTest
         assert_not_reached ();
       }
     });
+    Test.add_func ("/gxml/serializable/serializable_dual_key_map/deserialize-node-names",
+    () => {
+      try {
+        var d = new xDocument.from_path (GXmlTestConfig.TEST_DIR + "/test-collection.xml");
+        var bs = new BookStore ();
+        bs.deserialize (d);
+        assert (bs.name == "The Great Book");
+        assert (bs.books.size == 3);
+        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);
+        assert (b.authors.array.size == 2);
+        assert (b.inventory_registers != null);
+        assert (b.inventory_registers.size == 4);
+        var ir = b.inventory_registers.get (1,"K001");
+        assert (ir != null);
+        assert (ir.number == 1);
+        assert (ir.inventory == "K001");
+        assert (ir.row == 5);
+      } catch (GLib.Error e) {
+#if DEBUG
+        GLib.message ("ERROR: "+e.message);
+#endif
+        assert_not_reached ();
+      }
+    });
   }
 }
diff --git a/test/gxml-performance.vala b/test/gxml-performance.vala
index a30f39d..722bedf 100644
--- a/test/gxml-performance.vala
+++ b/test/gxml-performance.vala
@@ -54,13 +54,30 @@ class Authors : SerializableContainer
   public override string to_string () { return @"$(get_type ().name ())"; }
 }
 
-class Book : SerializableObjectModel
+class Inventory : SerializableObjectModel, SerializableMapDualKey<int,string>
+{
+  public int number { get; set; }
+  public int row { get; set; }
+  public string inventory { get; set; }
+  public int get_map_primary_key  () { return number; }
+  public string get_map_secondary_key () { return inventory; }
+  public override string to_string () { return @"||$(number.to_string ())|$(row.to_string 
())|$(inventory)||"; }
+  public class DualKeyMap : SerializableDualKeyMap<int, string, Inventory> {}
+}
+
+class Book : SerializableContainer
 {
   public string year { get; set; }
   public string isbn { get; set; }
   public Name   name { get; set; }
   public Authors authors { get; set; }
+  public Inventory.DualKeyMap inventory_registers { get; set; }
   public override string to_string () { return @"$(name.get_name ()), $(year)"; }
+  public override void init_containers ()
+  {
+    if (inventory_registers == null)
+      inventory_registers = new Inventory.DualKeyMap ();
+  }
   public class Array : SerializableArrayList<Book> {}
 }
 
@@ -146,7 +163,8 @@ public class Performance
 #endif
         assert_not_reached ();
       }
-    });Test.add_func ("/gxml/performance/tw-serialize",
+    });
+    Test.add_func ("/gxml/performance/tw-serialize",
     () => {
       try {
         double time;
diff --git a/test/test-collection.xml b/test/test-collection.xml
new file mode 100644
index 0000000..5e16b21
--- /dev/null
+++ b/test/test-collection.xml
@@ -0,0 +1,46 @@
+<?xml version="1.0"?>
+<bookstore name="The Great Book">
+ <book year="2015" isbn="ISBN0000000">
+  <name>Book1</name>
+  <authors>
+   <author>
+    <name>Fred</name>
+    <email>fweasley hogwarts co uk</email>
+   </author>
+   <author>
+    <name>George</name>
+    <email>gweasley hogwarts co uk</email>
+   </author>
+  </authors>
+  <inventory number="1" row="5" inventory="K001"/>
+  <inventory number="1" row="5" inventory="K002"/>
+  <inventory number="1" row="5" inventory="K003"/>
+  <inventory number="1" row="5" inventory="K004"/>
+ </book>
+ <book year="2015" isbn="ISBN0000001">
+  <name>Book2</name>
+  <authors>
+   <author>
+    <name>Fred</name>
+    <email>fweasley hogwarts co uk</email>
+   </author>
+   <author>
+    <name>George</name>
+    <email>gweasley hogwarts co uk</email>
+   </author>
+  </authors>
+ </book>
+ <book year="2014" isbn="ISBN0000000">
+  <name>Book3</name>
+  <authors>
+   <author>
+    <name>Fred</name>
+    <email>fweasley hogwarts co uk</email>
+   </author>
+   <author>
+    <name>George</name>
+    <email>gweasley hogwarts co uk</email>
+   </author>
+  </authors>
+ </book>
+</bookstore>
diff --git a/test/test-large.xml.in b/test/test-large.xml
similarity index 100%
rename from test/test-large.xml.in
rename to test/test-large.xml


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