[gxml] GomHashThreeMap: Fixed implementation



commit 132421b2c7042fed6382b0ccc888a0e25508a260
Author: Daniel Espinosa <esodan gmail com>
Date:   Sun Apr 9 23:03:45 2017 -0500

    GomHashThreeMap: Fixed implementation
    
    Fixed implementation with unit tests.

 gxml/GomCollections.vala       |   23 ++++++++++++-----
 test/GomSerializationTest.vala |   50 +++++++++++++++++++++++++++++++++++++++-
 2 files changed, 65 insertions(+), 8 deletions(-)
---
diff --git a/gxml/GomCollections.vala b/gxml/GomCollections.vala
index 87c124e..53e1b57 100644
--- a/gxml/GomCollections.vala
+++ b/gxml/GomCollections.vala
@@ -640,9 +640,18 @@ public class GXml.GomHashPairedMap : GXml.BaseCollection, GXml.GomCollection {
  * its value has precedence over this method.
  */
 public interface GXml.MappeableElementThreeKey : Object, DomElement {
-  public abstract string get_map_primary_key ();
-  public abstract string get_map_secondary_key ();
-  public abstract string get_map_third_key ();
+  /**
+   * Returns primary key of collection.
+   */
+  public abstract string get_map_pkey ();
+  /**
+   * Returns secundary key of collection.
+   */
+  public abstract string get_map_skey ();
+  /**
+   * Returns third key of collection.
+   */
+  public abstract string get_map_tkey ();
 }
 
 /**
@@ -861,7 +870,7 @@ public class GXml.GomHashThreeMap : GXml.BaseCollection, GXml.GomCollection {
       pkey = (element as DomElement).get_attribute (attribute_primary_key);
       skey = (element as DomElement).get_attribute (attribute_secondary_key);
       tkey = (element as DomElement).get_attribute (attribute_third_key);
-      if (pkey == null || skey == null || skey == null) {
+      if (pkey == null || skey == null || tkey == null) {
         pkey = (element as DomElement).get_attribute (attribute_primary_key.down ());
         skey = (element as DomElement).get_attribute (attribute_secondary_key.down ());
         tkey = (element as DomElement).get_attribute (attribute_third_key.down ());
@@ -869,9 +878,9 @@ public class GXml.GomHashThreeMap : GXml.BaseCollection, GXml.GomCollection {
     } else {
       if (items_type.is_a (typeof(MappeableElementThreeKey))) {
         if (!(element is MappeableElementThreeKey)) return false;
-        pkey = ((MappeableElementThreeKey) element).get_map_primary_key ();
-        skey = ((MappeableElementThreeKey) element).get_map_secondary_key ();
-        tkey = ((MappeableElementThreeKey) element).get_map_third_key ();
+        pkey = ((MappeableElementThreeKey) element).get_map_pkey ();
+        skey = ((MappeableElementThreeKey) element).get_map_skey ();
+        tkey = ((MappeableElementThreeKey) element).get_map_tkey ();
       }
     }
     if (pkey == null || skey == null || tkey == null) return false;
diff --git a/test/GomSerializationTest.vala b/test/GomSerializationTest.vala
index f9c11cf..1369601 100644
--- a/test/GomSerializationTest.vala
+++ b/test/GomSerializationTest.vala
@@ -233,7 +233,9 @@ class GomSerializationTest : GXmlTest  {
       if (book == null) return "";
       return book.name;
     }
-    public string get_map_third_key () { return cover; }
+    public string get_map_pkey () { return get_map_primary_key (); }
+    public string get_map_skey () { return get_map_secondary_key (); }
+    public string get_map_tkey () { return cover; }
     public Book create_book (string name) {
       return Object.new (typeof (Book),
                         "owner-document", this.owner_document,
@@ -255,6 +257,7 @@ class GomSerializationTest : GXmlTest  {
   public class BookStand : GomElement {
     HashRegisters _hashmap_registers = null;
     HashPairRegisters _hashpair_registers = null;
+    HashThreeRegisters _hashthree_registers = null;
     [Description (nick="::Classification")]
     public string classification { get; set; default = "Science"; }
     public Dimension dimension_x { get; set; }
@@ -285,6 +288,17 @@ class GomSerializationTest : GXmlTest  {
         _hashpair_registers = value;
       }
     }
+    public HashThreeRegisters hashthree_registers {
+      get {
+        if (_hashthree_registers == null)
+          _hashthree_registers = Object.new (typeof (HashThreeRegisters),"element",this)
+                              as HashThreeRegisters;
+        return _hashthree_registers;
+      }
+      set {
+        _hashthree_registers = value;
+      }
+    }
     public Books books { get; set; }
     construct {
       try { initialize ("BookStand"); } catch { assert_not_reached (); }
@@ -339,6 +353,12 @@ class GomSerializationTest : GXmlTest  {
       catch { assert_not_reached (); }
     }
   }
+  public class HashThreeRegisters : GomHashThreeMap {
+    construct {
+      try { initialize (typeof (BookRegister)); }
+      catch { assert_not_reached (); }
+    }
+  }
   public class Books : GomHashMap {
     construct {
       try { initialize_with_key (typeof (Book), "Name"); }
@@ -748,6 +768,34 @@ class GomSerializationTest : GXmlTest  {
       assert_not_reached ();
     }
     });
+    Test.add_func ("/gxml/gom-serialization/write/mappeablethreekey", () => {
+    try {
+      var bs = new BookStand ();
+      assert (bs.hashthree_registers != null);
+      var br = bs.hashthree_registers.create_item () as BookRegister;
+      var book = br.create_book ("Book1");
+      assert (book.name == "Book1");
+      br.book = book;
+      br.year = 2017;
+      br.cover = "SYSTEMS";
+      assert (br.get_map_pkey () == "2017");
+      assert (br.get_map_skey () == "Book1");
+      assert (br.cover == "SYSTEMS");
+      assert (br.get_map_tkey () == "SYSTEMS");
+      assert (bs.hashthree_registers.length == 0);
+      bs.hashthree_registers.append (br);
+      assert (bs.hashthree_registers.length == 1);
+      var b1 = bs.hashthree_registers.get ("2017","Book1", "SYSTEMS") as BookRegister;
+      assert (b1 != null);
+      assert (b1.year == 2017);
+      assert (b1.book != null);
+      assert (b1.book.name == "Book1");
+      assert (b1.cover == "SYSTEMS");
+    } catch (GLib.Error e) {
+      GLib.message ("Error: "+e.message);
+      assert_not_reached ();
+    }
+    });
     Test.add_func ("/gxml/gom-serialization/write/gom-property", () => {
       var m = new Motor ();
       string s = m.to_string ();


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