[gxml] GomHashMap: Added Unit Tests



commit d1bcb2ff79b7c84822a19cbc3852a3931bcf3940
Author: Daniel Espinosa <esodan gmail com>
Date:   Mon Nov 7 21:57:10 2016 -0600

    GomHashMap: Added Unit Tests

 test/GomSerializationTest.vala |   41 ++++++++++++++++++++++++++++++++++++++++
 1 files changed, 41 insertions(+), 0 deletions(-)
---
diff --git a/test/GomSerializationTest.vala b/test/GomSerializationTest.vala
index 61b222f..8bc1fa3 100644
--- a/test/GomSerializationTest.vala
+++ b/test/GomSerializationTest.vala
@@ -87,6 +87,7 @@ class GomSerializationTest : GXmlTest  {
     [Description (nick="::Classification")]
     public string classification { get; set; default = "Science"; }
     public Registers registers { get; set; }
+    public Books books { get; set; }
     construct {
       _local_name = "BookStand";
     }
@@ -104,6 +105,17 @@ class GomSerializationTest : GXmlTest  {
         _items_name = t.local_name;
       }
     }
+    public class Books : GomHashMap {
+      public Books.initialize (BookStand stand) {
+        _element = stand;
+      }
+      construct {
+        var t = new Book ();
+        _items_type = typeof (Book);
+        _items_name = t.local_name;
+        _attribute_key = "name";
+      }
+    }
   }
   public class BookStore : GomElement {
     public GomHashMap books { get; set; }
@@ -419,5 +431,34 @@ class GomSerializationTest : GXmlTest  {
       assert ((bs.registers.get_item (1) as BookRegister).year == 2010);
       assert ((bs.registers.get_item (2) as BookRegister).year == 2000);
     });
+    Test.add_func ("/gxml/gom-serialization/read/property-hashmap", () => {
+      var bs = new BookStand ();
+      string s = bs.to_string ();
+      GLib.message ("doc:"+s);
+      assert ("<BookStand Classification=\"Science\"/>" in s);
+      var parser = new XParser (bs);
+      parser.read_string ("<BookStand Classification=\"Science\"><Book name=\"Title1\"/><Book 
name=\"Title2\"/><Test/><Book name=\"Title3\"/></BookStand>", null);
+      //assert (bs.registers == null);
+      assert (bs.books != null);
+      s = bs.to_string ();
+      GLib.message ("doc:"+s);
+      GLib.message ("Books: "+bs.books.length.to_string ());
+      assert (bs.books.length == 3);
+      assert (bs.books.nodes_index.peek_nth (0) == 0);
+      assert (bs.books.nodes_index.peek_nth (1) == 1);
+      assert (bs.books.nodes_index.peek_nth (2) == 3);
+      assert (bs.books.get_item (0) != null);
+      assert (bs.books.get_item (0) is DomElement);
+      assert (bs.books.get_item (0) is Book);
+      assert (bs.books.get_item (1) != null);
+      assert (bs.books.get_item (1) is DomElement);
+      assert (bs.books.get_item (1) is Book);
+      assert (bs.books.get_item (2) != null);
+      assert (bs.books.get_item (2) is DomElement);
+      assert (bs.books.get_item (2) is Book);
+      assert ((bs.books.get_item (0) as Book).name == "Title1");
+      assert ((bs.books.get_item (1) as Book).name == "Title2");
+      assert ((bs.books.get_item (2) as Book).name == "Title3");
+    });
   }
 }


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