[gxml] Post-serialization fixes and tests cases for SerializableHashMap



commit 3a888237194892adefee70ad67aadfc27bcdc70f
Author: Daniel Espinosa <esodan gmail com>
Date:   Wed Feb 24 13:46:30 2016 -0600

    Post-serialization fixes and tests cases for SerializableHashMap
    
    * Fixed abort deserialization if already serialized
    * Added test cases for post-serialization on SerializableHashMap

 gxml/SerializableGeeArrayList.vala   |    3 +-
 gxml/SerializableGeeHashMap.vala     |    1 +
 test/SerializableGeeHashMapTest.vala |   42 ++++++++++++++++++++++++++++++++-
 test/gxml-performance.vala           |    1 +
 4 files changed, 44 insertions(+), 3 deletions(-)
---
diff --git a/gxml/SerializableGeeArrayList.vala b/gxml/SerializableGeeArrayList.vala
index 6dfdd5f..7d1e4b1 100644
--- a/gxml/SerializableGeeArrayList.vala
+++ b/gxml/SerializableGeeArrayList.vala
@@ -52,7 +52,8 @@ public class GXml.SerializableArrayList<G> : Gee.ArrayList<G>, Serializable, Ser
     return true;
   }
   public virtual bool deserialize_children ()  throws GLib.Error {
-    if (!is_prepared ()) return false;
+    if (_deserialized) return false;
+    if (_node == null) return false;
     if (!element_type.is_a (typeof (GXml.Serializable))) {
       throw new SerializableError.UNSUPPORTED_TYPE_ERROR (_("%s: Value type '%s' is unsupported"), 
                                                     this.get_type ().name (), element_type.name ());
diff --git a/gxml/SerializableGeeHashMap.vala b/gxml/SerializableGeeHashMap.vala
index b239614..26750b2 100644
--- a/gxml/SerializableGeeHashMap.vala
+++ b/gxml/SerializableGeeHashMap.vala
@@ -52,6 +52,7 @@ public class GXml.SerializableHashMap<K,V> : Gee.HashMap<K,V>, Serializable, Ser
   }
   public virtual bool deserialize_children ()  throws GLib.Error {
     if (_deserialized) return false;
+    if (_node == null) return false;
     if (!(value_type.is_a (typeof (GXml.Serializable)) &&
         value_type.is_a (typeof (SerializableMapKey)))) {
       throw new SerializableError.UNSUPPORTED_TYPE_ERROR (_("%s: Value type '%s' is unsupported"), 
diff --git a/test/SerializableGeeHashMapTest.vala b/test/SerializableGeeHashMapTest.vala
index 6d966fa..0afa4d0 100644
--- a/test/SerializableGeeHashMapTest.vala
+++ b/test/SerializableGeeHashMapTest.vala
@@ -350,7 +350,7 @@ class SerializableGeeHashMapTest : GXmlTest
         Test.timer_start ();
         var d = new TwDocument ();
         var ce = new HCElement ();
-        for (int i = 0; i < 250000; i++) {
+        for (int i = 0; i < 125000; i++) {
           var e1 = new HElement ();
           e1.name = "1E"+i.to_string ();
           ce.elements1.set (e1.name, e1);
@@ -374,11 +374,13 @@ class SerializableGeeHashMapTest : GXmlTest
         Test.message ("Calling C1 deserialize_children()...");
         Test.timer_start ();
         cep.elements1.deserialize_children ();
+        assert (!cep.elements1.deserialize_children ());
         time = Test.timer_elapsed ();
         Test.minimized_result (time, "C1: Disable Deserialize Collection. Deserialized from NODE: %g 
seconds", time);
-        Test.message ("Calling C1 deserialize_children()...");
+        Test.message ("Calling C2 deserialize_children()...");
         Test.timer_start ();
         cep.elements2.deserialize_children ();
+        assert (!cep.elements2.deserialize_children ());
         time = Test.timer_elapsed ();
         Test.minimized_result (time, "C2: Disable Deserialize Collection. Deserialized from NODE: %g 
seconds", time);
       } catch (GLib.Error e) {
@@ -386,5 +388,41 @@ class SerializableGeeHashMapTest : GXmlTest
         assert_not_reached ();
       }
     });
+    Test.add_func ("/gxml/performance/hashmap/post-deserialization/enable",
+    () => {
+      try {
+        double time;
+        Test.message ("Starting generating document...");
+        Test.timer_start ();
+        var d = new TwDocument ();
+        var ce = new HCElement ();
+        for (int i = 0; i < 125000; i++) {
+          var e1 = new HElement ();
+          e1.name = "1E"+i.to_string ();
+          ce.elements1.set (e1.name, e1);
+          var e2 = new HElement ();
+          e2.name = "2E"+i.to_string ();
+          ce.elements2.set (e2.name, e2);
+        }
+        ce.serialize (d);
+        time = Test.timer_elapsed ();
+        Test.minimized_result (time, "Created document: %g seconds", time);
+        Test.message ("Starting deserializing document: Enable collection deserialization...");
+        Test.timer_start ();
+        var cep = new HCElement ();
+        cep.elements1.enable_deserialize = true;
+        cep.elements2.enable_deserialize = true;
+        cep.deserialize (d);
+        time = Test.timer_elapsed ();
+        Test.minimized_result (time, "Disable Deserialize Collection. Deserialized from doc: %g seconds", 
time);
+        assert (cep.elements1.is_prepared ());
+        assert (cep.elements2.is_prepared ());
+        assert (!cep.elements1.deserialize_children ());
+        assert (!cep.elements2.deserialize_children ());
+      } catch (GLib.Error e) {
+        GLib.message ("ERROR: "+e.message);
+        assert_not_reached ();
+      }
+    });
   }
 }
diff --git a/test/gxml-performance.vala b/test/gxml-performance.vala
index 12bd40c..e8c2c55 100644
--- a/test/gxml-performance.vala
+++ b/test/gxml-performance.vala
@@ -340,6 +340,7 @@ public class Performance
         Test.message ("Calling deserialize_children()...");
         Test.timer_start ();
         cep.elements.deserialize_children ();
+        assert (!cep.elements.deserialize_children ());
         time = Test.timer_elapsed ();
         Test.minimized_result (time, "Disable Deserialize Collection. Deserialized from NODE: %g seconds", 
time);
       } catch (GLib.Error e) {


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