[gxml] Fixing GOM Unit Tests: Processing Instruction



commit eca7525325ce3354812f8043182a939c0f1ddc8f
Author: Daniel Espinosa <esodan gmail com>
Date:   Sun Oct 30 22:05:23 2016 -0600

    Fixing GOM Unit Tests: Processing Instruction
    
    Unit tests don't pass due to segfault on Processing Instruction
    access to target attribute

 gxml/DomEvents.vala       |    2 +-
 gxml/DomNode.vala         |    2 +-
 gxml/GXmlDomEvents.vala   |    4 ++--
 gxml/GomDocument.vala     |    2 ++
 gxml/GomNode.vala         |    4 +++-
 gxml/GomText.vala         |   25 ++++++++++++++-----------
 gxml/Node.vala            |    4 ++--
 gxml/XParser.vala         |   15 +++++++--------
 test/GomDocumentTest.vala |   12 ++++++++----
 9 files changed, 40 insertions(+), 30 deletions(-)
---
diff --git a/gxml/DomEvents.vala b/gxml/DomEvents.vala
index 7da2b2f..8aa7c40 100644
--- a/gxml/DomEvents.vala
+++ b/gxml/DomEvents.vala
@@ -32,7 +32,7 @@ public interface GXml.DomEventListener : GLib.Object {
 
 public interface GXml.DomEvent : GLib.Object {
   public abstract string etype { get; }
-  public abstract DomEventTarget? target { get; }
+  public abstract DomEventTarget? event_target { get; }
   public abstract DomEventTarget? current_target { get; }
   public abstract bool bubbles { get; }
   public abstract bool cancelable { get; }
diff --git a/gxml/DomNode.vala b/gxml/DomNode.vala
index b16f307..127abb4 100644
--- a/gxml/DomNode.vala
+++ b/gxml/DomNode.vala
@@ -152,7 +152,7 @@ public interface GXml.DomNode : GLib.Object, GXml.DomEventTarget {
           }
 #if DEBUG
           GLib.message (@"Copying source's Text node '$(source.node_name)' to destiny node with text: 
$(c.node_value) : Size= $(node.child_nodes.size)");
-          GLib.message (@"Added Text: $(node.child_nodes.get (node.child_nodes.size - 1))");
+          GLib.message (@"Added Text: $(node.child_nodes.get (node.child_nodes.size - 1).node_value)");
 #endif
         }
       }
diff --git a/gxml/GXmlDomEvents.vala b/gxml/GXmlDomEvents.vala
index c0f893a..f457425 100644
--- a/gxml/GXmlDomEvents.vala
+++ b/gxml/GXmlDomEvents.vala
@@ -22,12 +22,12 @@
 
 public class GXml.GDomEvent : Object, GXml.DomEvent {
        protected string _etype;
-       protected DomEventTarget _target;
+       protected DomEventTarget _event_target;
        protected DomEventTarget _current_target;
        protected bool _bubbles;
        protected bool _cancelable;
        public string etype { get { return _etype; } }
-       public DomEventTarget? target { get { return _target; } }
+       public DomEventTarget? event_target { get { return _event_target; } }
        public DomEventTarget? current_target { get { return _current_target; } }
        public bool bubbles { get { return _bubbles; } }
        public bool cancelable { get { return _cancelable; } }
diff --git a/gxml/GomDocument.vala b/gxml/GomDocument.vala
index 07232e4..f5933af 100644
--- a/gxml/GomDocument.vala
+++ b/gxml/GomDocument.vala
@@ -276,6 +276,8 @@ public class GXml.GomDocumentFragment : GXml.GomNode,
 {
   public GomDocumentFragment (DomDocument doc) {
     _document = doc;
+    _node_type = DomNode.NodeType.DOCUMENT_FRAGMENT_NODE;
+    _local_name = "#document-fragment";
   }
   // DomParentNode
   public new DomHTMLCollection children {
diff --git a/gxml/GomNode.vala b/gxml/GomNode.vala
index d043972..9022012 100644
--- a/gxml/GomNode.vala
+++ b/gxml/GomNode.vala
@@ -32,6 +32,7 @@ public class GXml.GomNode : Object,
   protected string _base_uri;
   protected string _node_value;
   protected DomNode.NodeType _node_type;
+  protected GomNodeList _child_nodes;
   public DomNode.NodeType node_type { get { return _node_type; } }
   public string node_name {
     owned get {
@@ -55,7 +56,6 @@ public class GXml.GomNode : Object,
       return null;
     }
   }
-  protected GomNodeList _child_nodes = new GomNodeList ();
   public DomNodeList child_nodes { owned get { return _child_nodes as DomNodeList; } }
   public DomNode? first_child {
     owned get {
@@ -123,6 +123,8 @@ public class GXml.GomNode : Object,
     _node_type = DomNode.NodeType.INVALID;
     _base_uri = null;
     _node_value = null;
+    _child_nodes = new GomNodeList ();
+    GLib.message ("PI");
   }
 
   public bool has_child_nodes () { return (_child_nodes.size > 0); }
diff --git a/gxml/GomText.vala b/gxml/GomText.vala
index 6133a01..91987ac 100644
--- a/gxml/GomText.vala
+++ b/gxml/GomText.vala
@@ -27,9 +27,13 @@ public class GXml.GomCharacterData : GomNode,
                           DomChildNode,
                           DomCharacterData
 {
-  protected string _data;
   // DomCharacterData
-  public string data { owned get { return _data; } set { _data = value; } }
+  public string data { owned get { return _node_value; } set { _node_value = value; } }
+
+  construct {
+    _node_value = "";
+    GLib.message ("PI: construct");
+  }
   // DomNonDocumentTypeChildNode
   public DomElement? previous_element_sibling {
     get {
@@ -70,28 +74,27 @@ public class GXml.GomText : GomCharacterData,
 {
   construct {
     _node_type = DomNode.NodeType.TEXT_NODE;
-    _local_name = "#TEXT";
+    _local_name = "#text";
   }
 
   public GomText (DomDocument doc, string data) {
     _document = doc;
-    _data = data;
+    _node_value = data;
   }
 }
 public class GXml.GomProcessingInstruction : GomCharacterData,
                                             DomProcessingInstruction
 {
-  protected string _target = null;
   // DomProcessingInstruction
-  public string target { owned get { return _target; } }
+  public string target { owned get { return _local_name; } }
   construct {
     _node_type = DomNode.NodeType.PROCESSING_INSTRUCTION_NODE;
-    _local_name = "#PROCESSING_INSTRUCTION";
   }
   public GomProcessingInstruction (DomDocument doc, string target, string data) {
     _document = doc;
-    _target = target;
-    _data = data;
+    _node_value = data;
+    GLib.message ("PI: Initialized");
+    _local_name = target;
   }
 }
 
@@ -100,10 +103,10 @@ public class GXml.GomComment : GomCharacterData,
 {
   construct {
     _node_type = DomNode.NodeType.COMMENT_NODE;
-    _local_name = "#COMMENT";
+    _local_name = "#comment";
   }
   public GomComment (DomDocument doc, string data) {
     _document = doc;
-    _data = data;
+    _node_value = data;
   }
 }
diff --git a/gxml/Node.vala b/gxml/Node.vala
index 269af41..d05f13a 100644
--- a/gxml/Node.vala
+++ b/gxml/Node.vala
@@ -205,8 +205,8 @@ public interface GXml.Node : Object
           var t = doc.create_text (c.value);
           node.children_nodes.add (t);
 #if DEBUG
-          GLib.message (@"Copying source's Text node '$(source.name)' to destiny node with text: $(c.value) 
: Size= $(node.childs.size)");
-          GLib.message (@"Added Text: $(node.childs.get (node.childs.size - 1))");
+          GLib.message (@"Copying source's Text node '$(source.name)' to destiny node with text: $(c.value) 
: Size= $(node.children_nodes.size)");
+          GLib.message (@"Added Text: $(node.children_nodes.get (node.children_nodes.size - 1))");
 #endif
         }
       }
diff --git a/gxml/XParser.vala b/gxml/XParser.vala
index eb8df3e..f7f707b 100644
--- a/gxml/XParser.vala
+++ b/gxml/XParser.vala
@@ -89,7 +89,7 @@ public class GXml.XParser : Object, GXml.Parser {
     case Xml.ReaderType.ELEMENT:
       bool isempty = (tr.is_empty_element () == 1);
 #if DEBUG
-      if (isempty) GLib.message ("Is Empty node:"+node.name);
+      if (isempty) GLib.message ("Is Empty node:"+node.node_name);
       GLib.message ("ReadNode: Element: "+tr.const_local_name ());
 #endif
       if (isempty) {
@@ -293,13 +293,12 @@ public class GXml.XParser : Object, GXml.Parser {
   {
     int size = 0;
 #if DEBUG
-    GLib.message (@"Starting Node: start Node: '$(node.name)'");
+    GLib.message (@"Starting Node: start Node: '$(node.node_name)'");
 #endif
     if (node is GXml.DomElement) {
 #if DEBUG
-      GLib.message (@"Starting Element... '$(node.name)'");
-      GLib.message (@"Element Document is Null... '$((node.document == null).to_string ())'");
-      GLib.message (@"Namespaces in Element... '$(node.namespaces.size)'");
+      GLib.message (@"Starting Element... '$(node.node_name)'");
+      GLib.message (@"Element Document is Null... '$((node.owner_document == null).to_string ())'");
 #endif
       if ((node as DomElement).prefix != null || (node as DomElement).namespace_uri != null)
         tw.start_element_ns ((node as DomElement).prefix, (node as DomElement).local_name, (node as 
DomElement).node_name);
@@ -307,7 +306,7 @@ public class GXml.XParser : Object, GXml.Parser {
         tw.start_element (node.node_name);
     foreach (GXml.DomNode attr in (node as DomElement).attributes.values) {
 #if DEBUG
-        GLib.message (@"Starting Element '$(node.node_name)': write attribute '$(attr.loca_name)'");
+        GLib.message (@"Starting Element '$(node.node_name)': write attribute '$((attr as 
DomAttr).local_name)'");
 #endif
       if ((attr as DomAttr).prefix != null)
         size += tw.write_attribute_ns ((attr as DomAttr).prefix,
@@ -330,7 +329,7 @@ public class GXml.XParser : Object, GXml.Parser {
 #endif
       if (n is GXml.DomElement) {
 #if DEBUG
-      GLib.message (@"Starting Child Element: writting Node '$(n.name)'");
+      GLib.message (@"Starting Child Element: writting Node '$(n.node_name)'");
 #endif
         start_node (n);
         size += tw.end_element ();
@@ -353,7 +352,7 @@ public class GXml.XParser : Object, GXml.Parser {
       }
       if (n is GXml.DomProcessingInstruction) {
   #if DEBUG
-      GLib.message (@"Starting Child Element: writting ProcessingInstruction '$(n.value)'");
+      GLib.message (@"Starting Child Element: writting ProcessingInstruction '$(n.node_value)'");
   #endif
         size += Xmlx.text_writer_write_pi (tw, (n as DomProcessingInstruction).target,
                                           (n as DomProcessingInstruction).data);
diff --git a/test/GomDocumentTest.vala b/test/GomDocumentTest.vala
index ae77513..98f556c 100644
--- a/test/GomDocumentTest.vala
+++ b/test/GomDocumentTest.vala
@@ -233,12 +233,16 @@ class GomDocumentTest : GXmlTest {
                Test.add_func ("/gxml/gom-document/create_processing_instruction", () => {
                        try {
                                DomDocument doc = new GDocument.from_string ("<document_element />");
-                               DomProcessingInstruction instruction = (DomProcessingInstruction) 
doc.create_processing_instruction ("target", "data");
-
+                               DomProcessingInstruction instruction = doc.create_processing_instruction 
("target", "data");
+                               assert (instruction is DomProcessingInstruction);
                                assert (instruction.node_name == "target");
-                               assert (instruction.target == "target");
-                               assert (instruction.data == "data");
                                assert (instruction.node_value == "data");
+                               GLib.message ("Target:"+instruction.node_name);
+                               GLib.message ("Dat:"+instruction.node_value);
+                               assert (instruction.data == "data");
+                               assert (instruction.target != null);
+                               assert (instruction.target == "target");
+                               assert_not_reached ();
                        } catch { assert_not_reached (); }
                });
                Test.add_func ("/gxml/gom-document/create_attribute", () => {


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