[gxml] Fixes to Unit Tests



commit 0a705dcf06c30f0408bee592bda4f370955eee58
Author: Daniel Espinosa <esodan gmail com>
Date:   Fri Jan 20 12:58:36 2017 -0600

    Fixes to Unit Tests

 gxml/GXmlNode.vala             |   16 +++---
 gxml/GomCollections.vala       |   12 ++--
 gxml/GomElement.vala           |    2 +-
 gxml/GomProperty.vala          |    4 +-
 test/GomDocumentTest.vala      |    5 ++-
 test/GomElementTest.vala       |   11 +++-
 test/GomSerializationTest.vala |  115 +++++++++++++++++++++++-----------------
 7 files changed, 98 insertions(+), 67 deletions(-)
---
diff --git a/gxml/GXmlNode.vala b/gxml/GXmlNode.vala
index 2614cd6..6007939 100644
--- a/gxml/GXmlNode.vala
+++ b/gxml/GXmlNode.vala
@@ -61,7 +61,8 @@ public abstract class GXml.GNode : Object,
   public virtual GXml.Document document { get { return _doc; } }
   public virtual GXml.Node parent {
     owned get {
-      if (_node == null) return null;
+      GXml.Node nullnode = null;
+      if (_node == null) return nullnode;
       return to_gnode (document as GDocument, _node->parent);
     }
   }
@@ -92,6 +93,7 @@ public abstract class GXml.GNode : Object,
   public Xml.Node* get_internal_node () { return _node; }
   // Static
   public static GXml.Node to_gnode (GXml.GDocument doc, Xml.Node *node) {
+    GXml.Node nullnode = null;
     var t = (GXml.NodeType) node->type;
     switch (t) {
       case GXml.NodeType.ELEMENT:
@@ -103,9 +105,9 @@ public abstract class GXml.GNode : Object,
       case GXml.NodeType.CDATA_SECTION:
         return new GCDATA (doc, node);
       case GXml.NodeType.ENTITY_REFERENCE:
-        return null;
+        return nullnode;
       case GXml.NodeType.ENTITY:
-        return null;
+        return nullnode;
       case GXml.NodeType.PROCESSING_INSTRUCTION:
         return new GProcessingInstruction (doc, node);
       case GXml.NodeType.COMMENT:
@@ -113,13 +115,13 @@ public abstract class GXml.GNode : Object,
       case GXml.NodeType.DOCUMENT:
         return new GDocument.from_doc (node->doc);
       case GXml.NodeType.DOCUMENT_TYPE:
-        return null;
+        return nullnode;
       case GXml.NodeType.DOCUMENT_FRAGMENT:
-        return null;
+        return nullnode;
       case GXml.NodeType.NOTATION:
-        return null;
+        return nullnode;
     }
-    return null;
+    return nullnode;
   }
   // DomNode Implementation
   public DomNode.NodeType node_type {
diff --git a/gxml/GomCollections.vala b/gxml/GomCollections.vala
index ee62328..43c60ff 100644
--- a/gxml/GomCollections.vala
+++ b/gxml/GomCollections.vala
@@ -97,7 +97,9 @@ public interface GXml.GomCollection : Object
   public abstract void initialize (GLib.Type t) throws GLib.Error;
   /**
    * Creates a new instance of {@link items_type}, with same
-   * {@link DomNode.owner_document} than {@link element}
+   * {@link DomNode.owner_document} than {@link element}. New instance
+   * is not set as a child of collection's {@link element}; to do so,
+   * use {@link append}
    *
    * Returns: a new instance object or null if type is not a {@link GomElement} or no parent has been set
    */
@@ -177,7 +179,6 @@ public abstract class GXml.BaseCollection : Object {
     construct set {
       if (value != null)
         _element = value;
-      assert (_element != null);
     }
   }
   /**
@@ -201,8 +202,8 @@ public abstract class GXml.BaseCollection : Object {
    * Implemenation classes, should initialize collection to hold a {@link GomElement}
    * derived type using {@link GomCollection.initialize}.
    */
-  public void initialize_element (GomElement element) throws GLib.Error {
-    _element = element;
+  public void initialize_element (GomElement e) throws GLib.Error {
+    _element = e;
     search ();
   }
 
@@ -226,7 +227,7 @@ public abstract class GXml.BaseCollection : Object {
     _element.append_child (node);
     if (_element.child_nodes.size == 0)
       throw new DomError.QUOTA_EXCEEDED_ERROR
-                (_("Invalid atempt to add a node with a different parent document"));
+                (_("Node element not appended as child of parent. No node added to collection"));
     var index = _element.child_nodes.size - 1;
     if (!validate_add (index, node)) return;
     _nodes_index.push_tail (index);
@@ -319,7 +320,6 @@ public class GXml.GomHashMap : GXml.BaseCollection, GXml.GomCollection {
   {
     initialize (items_type);
     _attribute_key = attribute_key;
-    search ();
   }
   /**
    * Returns an {@link DomElement} in the collection using a string key.
diff --git a/gxml/GomElement.vala b/gxml/GomElement.vala
index 929643a..4437d1d 100644
--- a/gxml/GomElement.vala
+++ b/gxml/GomElement.vala
@@ -415,7 +415,7 @@ public class GXml.GomElement : GomNode,
         if (nspn != (node as DomAttr).prefix
             && nsn != (node as DomAttr).namespace_uri)
           throw new DomError.NAMESPACE_ERROR
-                  (_("Trying to add an attribute with a non found namespace prefix"));
+                  (_("Trying to add an attribute with an undefined namespace prefix"));
         nspn = _element.lookup_prefix ((node as DomAttr).namespace_uri);
         nsn = _element.lookup_namespace_uri (nspn);
         if (nspn != (node as DomAttr).prefix
diff --git a/gxml/GomProperty.vala b/gxml/GomProperty.vala
index c7b8934..dae2d69 100644
--- a/gxml/GomProperty.vala
+++ b/gxml/GomProperty.vala
@@ -82,7 +82,7 @@ public abstract class GXml.GomBaseProperty : Object, GXml.GomProperty {
   /**
    * {@inheritDoc}
    */
-  public void initialize (string attribute_name) { _attribute_name =  attribute_name; }
+  public void initialize (string attribute_name) { message ("Type: "+this.get_type 
().name());_attribute_name =  attribute_name; }
   /**
    * Takes a string and check if it can be validated using
    * {@link validation_rule}.
@@ -216,7 +216,7 @@ public class GXml.GomBoolean : GomBaseProperty {
  * Enumeration is represented as a string, using its name, independent of
  * value possition in enumeration.
  */
-public class GXml.GomEnum : GomBaseProperty, GomProperty {
+public class GXml.GomEnum : GomBaseProperty {
   protected int _value = 0;
   protected Type _enum_type;
   public override string value {
diff --git a/test/GomDocumentTest.vala b/test/GomDocumentTest.vala
index 5039e96..5b917b7 100644
--- a/test/GomDocumentTest.vala
+++ b/test/GomDocumentTest.vala
@@ -80,7 +80,10 @@ class GomDocumentTest : GXmlTest {
                                s.append ("""<document_element />""");
                                var d = new GomDocument.from_string (s.str);
                                var parser = new XParser (d);
-                               Test.message ("Saving to file: "+f.get_uri ()+parser.write_string ());
+#if DEBUG
+                               message ("Saving to file: "+f.get_uri ());
+                               message ("XML:\n"+parser.write_string ());
+#endif
                                d.write_file (f);
                                assert (f.query_exists ());
                                var d2 = new GomDocument.from_file (f);
diff --git a/test/GomElementTest.vala b/test/GomElementTest.vala
index dedb4c4..c302a49 100644
--- a/test/GomElementTest.vala
+++ b/test/GomElementTest.vala
@@ -134,15 +134,22 @@ class GomElementTest : GXmlTest  {
                                assert (elem.get_attribute ("xola") == null);
                                assert (elem.attributes.size == 2);
                                try {
-                                       Test.message ("Documento:"+parser.write_string ());
+#if DEBUG
+                                       message ("Documento:"+parser.write_string ());
+#endif
                                        elem.set_attribute_ns ("http://www.gnome.org/GXml";, 
"gxml2:xola","Mexico");
                                        assert_not_reached ();
-                               } catch {}
+                               } catch (GLib.Error e) {
+                                       GLib.message ("Correctly Cough Error:"+e.message);
+                               }
+                               assert (elem != null);
+                               assert (elem.attributes != null);
                                assert (elem.attributes.size == 2);
                        } catch (GLib.Error e) {
                                GLib.message (e.message);
                                assert_not_reached ();
                        }
+                               assert_not_reached ();
                });
                Test.add_func ("/gxml/gom-element/content/add_aside_child_nodes", () =>{
                        try {
diff --git a/test/GomSerializationTest.vala b/test/GomSerializationTest.vala
index 8499791..e76bcc5 100644
--- a/test/GomSerializationTest.vala
+++ b/test/GomSerializationTest.vala
@@ -25,14 +25,14 @@ using GXml;
 // GOM Collection Definitions
 class GomName : GomElement
 {
-  construct { initialize ("Name");}
+  construct { try { initialize ("Name"); } catch { assert_not_reached (); } }
   public string get_name () { return this.text_content; }
   public void   set_name (string name) { this.text_content = name; }
 }
 
 class GomEmail : GomElement
 {
-  construct {  initialize ("Email"); }
+  construct {  try { initialize ("Email"); } catch { assert_not_reached (); } }
   public string get_mail () { return this.text_content; }
   public void   set_mail (string email) { text_content = email; }
 }
@@ -41,16 +41,17 @@ class GomAuthor : GomElement
 {
   public Name name { get; set; }
   public Email email { get; set; }
-  construct { initialize ("Author");}
+  construct { try { initialize ("Author"); } catch { assert_not_reached (); } }
   public class Array : GomArrayList {
-    construct { initialize (typeof (GomAuthor)); }
+    construct { try { initialize (typeof (GomAuthor)); }
+    catch { assert_not_reached (); } }
   }
 }
 
 class GomAuthors : GomElement
 {
   public string number { get; set; }
-  construct { initialize ("Authors"); }
+  construct { try { initialize ("Authors"); } catch { assert_not_reached (); } }
   public GomAuthor.Array array { get; set; }
 }
 
@@ -62,10 +63,13 @@ class GomInventory : GomElement
   public int row { get; set; }
   [Description (nick="::Inventory")]
   public string inventory { get; set; }
-  construct { initialize ("Inventory"); }
+  construct { try { initialize ("Inventory"); } catch { assert_not_reached (); } }
   // FIXME: Add DualKeyMap implementation to GOM
   public class DualKeyMap : GomHashMap {
-    construct { initialize_with_key (typeof (GomInventory), "number"); }
+    construct {
+      try { initialize_with_key (typeof (GomInventory), "number"); }
+      catch { assert_not_reached (); }
+    }
   }
 }
 
@@ -73,9 +77,12 @@ class GomCategory : GomElement
 {
   [Description (nick="::Name")]
   public string name { get; set; }
-  construct { initialize ("Category"); }
+  construct { try { initialize ("Category"); } catch { assert_not_reached (); } }
   public class Map : GomHashMap {
-    construct { initialize_with_key (typeof (GomInventory), "name"); }
+    construct {
+      try { initialize_with_key (typeof (GomInventory), "name");  }
+      catch { assert_not_reached (); }
+    }
   }
 }
 
@@ -86,9 +93,12 @@ class GomResume : GomElement
   public string chapter { get; set; }
   [Description (nick="::Text")]
   public string text { get; set; }
-  construct { initialize ("Resume"); }
+  construct { try { initialize ("Resume"); } catch { assert_not_reached (); } }
   public class Map : GomHashMap {
-    construct { initialize_with_key (typeof (GomInventory), "chapter"); }
+    construct {
+      try { initialize_with_key (typeof (GomInventory), "chapter"); }
+      catch { assert_not_reached (); }
+    }
   }
 }
 
@@ -104,20 +114,13 @@ class GomBook : GomElement
   public GomCategory.Map categories { get; set; }
   public GomResume.Map resumes { get; set; }
   construct {
-    initialize ("Book");
-    inventory_registers = Object.new (typeof (GomInventory.DualKeyMap),
-                                      "element", this)
-                                      as GomInventory.DualKeyMap;
-    categories = Object.new (typeof (GomCategory.Map),
-                                      "element", this)
-                                    as GomCategory.Map;
-    resumes = Object.new (typeof (GomResume.Map),
-                                      "element", this)
-                                    as GomResume.Map;
-    assert (this.local_name == "Book");
+    try { initialize ("Book"); } catch { assert_not_reached (); }
   }
   public class Array : GomArrayList {
-    construct { initialize (typeof (GomBook)); }
+    construct {
+      try { initialize (typeof (GomBook)); }
+      catch { assert_not_reached (); }
+    }
   }
 }
 
@@ -127,8 +130,7 @@ class GomBookStore : GomElement
   public string name { get; set; }
   public GomBook.Array books { get; set; }
   construct {
-    message ("Initialization of GomBookStore");
-    initialize ("BookStore");
+    try { initialize ("BookStore"); } catch { assert_not_reached (); }
   }
   public string to_string () {
     var parser = new XParser (this);
@@ -147,7 +149,7 @@ class GomSerializationTest : GXmlTest  {
   public class Book : GomElement {
     [Description (nick="::Name")]
     public string name { get; set; }
-    construct { initialize ("Book"); }
+    construct { try { initialize ("Book"); } catch { assert_not_reached (); } }
     public Book.document (DomDocument doc) {
       _document = doc;
     }
@@ -167,7 +169,7 @@ class GomSerializationTest : GXmlTest  {
     [Description (nick="::Model")]
     public string model { get; set; }
     public string ignore { get; set; } // ignored property
-    construct { initialize ("Computer"); }
+    construct { try { initialize ("Computer"); } catch { assert_not_reached (); } }
     public string to_string () {
       var parser = new XParser (this);
       string s = "";
@@ -187,7 +189,7 @@ class GomSerializationTest : GXmlTest  {
     public bool tax_free { get; set; }
     [Description (nick="::Month")]
     public Month month { get; set; }
-    construct { initialize ("Taxes"); }
+    construct { try { initialize ("Taxes"); } catch { assert_not_reached (); } }
     public string to_string () {
       var parser = new XParser (this);
       string s = "";
@@ -208,7 +210,10 @@ class GomSerializationTest : GXmlTest  {
     [Description (nick="::Year")]
     public int year { get; set; }
     public Book book { get; set; }
-    construct { initialize ("BookRegister"); }
+    construct {
+      try { initialize ("BookRegister"); }
+      catch { assert_not_reached (); }
+    }
     public BookRegister.document (DomDocument doc) {
       _document = doc;
     }
@@ -230,8 +235,7 @@ class GomSerializationTest : GXmlTest  {
     public Registers registers { get; set; }
     public Books books { get; set; }
     construct {
-      initialize ("BookStand");
-      registers = Object.new (typeof(Registers), "element", this) as Registers;
+      try { initialize ("BookStand"); } catch { assert_not_reached (); }
     }
     public string to_string () {
       var parser = new XParser (this);
@@ -247,18 +251,23 @@ class GomSerializationTest : GXmlTest  {
   }
 
   public class Registers : GomArrayList {
-    construct { initialize (typeof (BookRegister)); }
+    construct {
+      try { initialize (typeof (BookRegister)); }
+      catch { assert_not_reached (); }
+    }
   }
   public class Books : GomHashMap {
-    construct { initialize_with_key (typeof (Book), "name"); }
+    construct {
+      try { initialize_with_key (typeof (Book), "name"); }
+      catch { assert_not_reached (); }
+    }
   }
   public class BookStore : GomElement {
     [Description (nick="::Name")]
     public string name { get; set; }
     public Books books { get; set; }
     construct {
-      initialize ("BookStore");
-      books = Object.new (typeof (Books), "element", this) as Books;
+      try { assert_not_reached ();  initialize ("BookStore"); } catch { assert_not_reached (); }
     }
     public string to_string () {
       var parser = new XParser (this);
@@ -278,7 +287,7 @@ class GomSerializationTest : GXmlTest  {
     public Speed speed { get; set; }
     public TensionType tension_type { get; set; }
     public Tension tension { get; set; }
-    construct { initialize ("Motor"); }
+    construct { try { initialize ("Motor"); } catch { assert_not_reached (); } }
     public string to_string () {
       var parser = new XParser (this);
       string s = "";
@@ -295,21 +304,28 @@ class GomSerializationTest : GXmlTest  {
       DC
     }
     public class On : GomBoolean {
-      construct { initialize ("On"); }
+      construct { try { initialize ("On"); } catch { assert_not_reached (); } }
     }
     public class Torque : GomDouble {
-      construct { initialize ("Torque"); }
+      construct {
+        try { initialize ("Torque"); } catch { assert_not_reached (); }
+      }
     }
     public class Speed : GomFloat {
-      construct { initialize ("Speed"); }
+      construct {
+        try { initialize ("Speed"); } catch { assert_not_reached (); }
+      }
     }
     public class TensionType : GomEnum {
       construct {
-        initialize_enum ("Tension", typeof (TensionTypeEnum));
+        try { initialize_enum ("TensionType", typeof (TensionTypeEnum)); }
+        catch { assert_not_reached (); }
       }
     }
     public class Tension : GomInt {
-      construct { initialize ("Tension"); }
+      construct {
+        try { initialize ("Tension"); } catch { assert_not_reached (); }
+      }
     }
   }
   public static void add_tests () {
@@ -380,13 +396,16 @@ class GomSerializationTest : GXmlTest  {
       assert (s != null);
       GLib.message ("DOC:"+s);
       assert ("<BookStand Classification=\"Science\"/>" in s);
-      assert (bs.registers != null);
+      assert (bs.owner_document != null);
+      assert  (bs.registers == null);
+      bs.registers = new Registers ();
+      bs.registers.initialize_element (bs);
       s = bs.to_string ();
       assert (s != null);
       GLib.message ("DOC:"+s);
       assert ("<BookStand Classification=\"Science\"/>" in s);
       try {
-        var br = bs.registers.create_item () as BookRegister;
+        var br = new BookRegister ();
         bs.registers.append (br);
         assert_not_reached ();
       } catch {}
@@ -424,20 +443,18 @@ class GomSerializationTest : GXmlTest  {
       GLib.message ("DOC:"+s);
       assert ("<BookStore/>" in s);
       assert (bs.books == null);
-      var b = new Book ();
+      bs.books = new Books ();
+      bs.books.initialize_element (bs);
       s = bs.to_string ();
       assert (s != null);
       GLib.message ("DOC:"+s);
       assert ("<BookStore/>" in s);
+      var b = new Book ();
       try {
         bs.books.append (b);
         assert_not_reached ();
       } catch {}
       b = new Book.document (bs.owner_document);
-      try {
-        bs.books.append (b);
-        assert_not_reached ();
-      } catch {}
       b.name = "Title1";
       bs.books.append (b);
       s = bs.to_string ();
@@ -488,6 +505,8 @@ class GomSerializationTest : GXmlTest  {
       assert (s != null);
       GLib.message ("DOC:"+s);
       assert ("<Motor On=\"false\" Torque=\"0.0000\" Speed=\"0.0000\"/>" in s);
+      assert (m.tension_type == null);
+      message ("Initializing Motor.TensionType");
       m.tension_type = new Motor.TensionType ();
       s = m.to_string ();
       assert (s != null);


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