[gxml] SerializableObjectModel optimizations
- From: Daniel Espinosa Ortiz <despinosa src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gxml] SerializableObjectModel optimizations
- Date: Mon, 22 Feb 2016 19:15:49 +0000 (UTC)
commit bd52c2ddbcb311979f66e227b0d76496545f20a4
Author: Daniel Espinosa <esodan gmail com>
Date: Mon Feb 22 13:12:21 2016 -0600
SerializableObjectModel optimizations
* No more per object TwDocument to copy to unknown nodes
* Unknown attributes and nodes are detected from original GXml.Node
* Implementation requires collections are not null, in order to locate
node_name() and avoid this nodes as uknowns
gxml/Node.vala | 4 +-
gxml/SerializableGeeHashMap.vala | 2 +-
gxml/SerializableObjectModel.vala | 228 ++++++++++++++------------
gxml/TwNode.vala | 1 +
test/SerializableGeeCollections-Tw-Test.vala | 8 +-
test/SerializableGeeCollectionsTest.vala | 14 ++-
test/SerializableGeeHashMapTest.vala | 40 +++---
test/SerializableObjectModelTest.vala | 191 ++++++----------------
8 files changed, 209 insertions(+), 279 deletions(-)
---
diff --git a/gxml/Node.vala b/gxml/Node.vala
index 50fd78f..52119d2 100644
--- a/gxml/Node.vala
+++ b/gxml/Node.vala
@@ -161,7 +161,7 @@ public interface GXml.Node : Object
#if DEBUG
GLib.message ("Copying source's child nodes to destiny node");
#endif
- foreach (Node c in source.childs) {
+ foreach (Node c in source.children) {
if (c is Element) {
if (c.name == null) continue;
#if DEBUG
@@ -185,7 +185,7 @@ public interface GXml.Node : Object
continue;
}
var t = doc.create_text (c.value);
- node.childs.add (t);
+ node.children.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))");
diff --git a/gxml/SerializableGeeHashMap.vala b/gxml/SerializableGeeHashMap.vala
index 76837cc..b6fe8a6 100644
--- a/gxml/SerializableGeeHashMap.vala
+++ b/gxml/SerializableGeeHashMap.vala
@@ -116,7 +116,7 @@ public class GXml.SerializableHashMap<K,V> : Gee.HashMap<K,V>, Serializable, Ser
foreach (GXml.Node n in node.children) {
if (n is Element) {
#if DEBUG
- stdout.printf (@"Node $(node.name) for type '$(get_type ().name ())'\n");
+ GLib.message (@"Node $(node.name) for type '$(get_type ().name ())'\n");
#endif
var obj = Object.new (value_type);
if (n.name.down () == ((Serializable) obj).node_name ().down ()) {
diff --git a/gxml/SerializableObjectModel.vala b/gxml/SerializableObjectModel.vala
index aadf4dd..f15a2c5 100644
--- a/gxml/SerializableObjectModel.vala
+++ b/gxml/SerializableObjectModel.vala
@@ -38,12 +38,13 @@ using Gee;
public abstract class GXml.SerializableObjectModel : Object, Serializable
{
construct { Init.init (); }
- // holds all unknown nodes
- protected GXml.TwDocument _doc = null;
+ GXml.Text text_node = null;
+ // To find unknown nodes
+ protected GXml.Node _node = null;
/* Serializable interface properties */
protected ParamSpec[] properties { get; set; }
public GLib.HashTable<string,GLib.ParamSpec> ignored_serializable_properties { get; protected set; }
- public string? serialized_xml_node_value { owned get; protected set; default=null; }
+ public string? serialized_xml_node_value { owned get ; protected set; default = null; }
public virtual bool get_enable_unknown_serializable_property () { return false; }
/**
* All unknown nodes, will be stored in a per-object { link GXml.Document}
@@ -54,42 +55,74 @@ public abstract class GXml.SerializableObjectModel : Object, Serializable
public Gee.Map<string,GXml.Attribute> unknown_serializable_properties
{
owned get {
+ var m = new HashMap<string,GXml.Attribute> ();
+ if (_node == null) return m;
#if DEBUG
- GLib.message ("Getting unknown_serializable_nodes");
- if (_doc != null)
- if (_doc.root != null)
- GLib.message ("Doc is not NULL and Root Attributes is NULL:"+(_doc.root.attrs == null).to_string
());
- else
- GLib.message ("Doc is not NULL but Root IS NULL");
+ GLib.message ("Searching unknown attributes");
+#endif
+ var props = list_serializable_properties ();
+ bool found = false;
+ foreach (GXml.Node a in _node.attrs.values) {
+#if DEBUG
+ GLib.message ("Checking Node attribute: "+a.name);
+#endif
+ found = false;
+ for (int i = 0; i < props.length; i++) {
+ var p = props[i];
+#if DEBUG
+ GLib.message ("Comparing Object Property: "+p.get_name ());
+#endif
+ if (a.name.down () == p.get_name ().down ()
+ || a.name.down () == p.get_nick ().down ())
+ found = true;
+ }
+ if (!found) {
+#if DEBUG
+ GLib.message ("Found attribute: "+a.name);
#endif
- if (_doc == null) init_unknown_doc ();
- return _doc.root.attrs as Gee.Map<string,GXml.Attribute>;
+ m.set (a.name, a as GXml.Attribute);
+ }
+ }
+
+ return m;
}
}
public Gee.Collection<GXml.Node> unknown_serializable_nodes
{
owned get {
-#if DEBUG
- GLib.message ("Getting unknown_serializable_nodes");
- if (_doc != null)
- if (_doc.root != null)
- GLib.message ("Doc is not NULL and Root Children is NULL:"+(_doc.root.children == null).to_string
());
+ var l = new ArrayList<GXml.Node> ();
+ if (_node == null) return l;
+ var oprops = list_serializable_properties ();
+ string[] props = {};
+ foreach (GLib.ParamSpec op in oprops) {
+ if (op.value_type.is_a (typeof (SerializableCollection))) {
+ Value v = Value (op.value_type);
+ get_property (op.get_name (), ref v);
+ Object obj = v.get_object ();
+ if (obj != null) {
+ props += (obj as Serializable).node_name ();
+ continue;
+ }
+ }
+ if (property_use_nick ())
+ props += op.get_nick ().down ();
else
- GLib.message ("Doc is not NULL but Root IS NULL");
-#endif
- if (_doc == null) init_unknown_doc ();
- return _doc.root.children;
- }
- }
-
- private void init_unknown_doc ()
- {
- _doc = new TwDocument ();
- try {
- var r = _doc.create_element ("root");
- _doc.children.add (r);
+ props += op.get_name ().down ();
+ }
+ bool found = false;
+ foreach (GXml.Node n in _node.children) {
+ if (n is GXml.Text) {
+ if (serialize_use_xml_node_value ()) continue;
+ }
+ found = false;
+ foreach (string p in props) {
+ if (n.name.down () == p)
+ found = true;
+ }
+ if (!found) l.add (n);
+ }
+ return l;
}
- catch { assert_not_reached (); }
}
public virtual bool serialize_use_xml_node_value () { return false; }
@@ -148,7 +181,7 @@ public abstract class GXml.SerializableObjectModel : Object, Serializable
// Serializing unknown Nodes
foreach (GXml.Node n in unknown_serializable_nodes) {
#if DEBUG
- GLib.message (@"Serializing Unknown NODE: $(n.name) to $(element.name)");
+ GLib.message (@"Serializing Unknown NODE: $(n.name):'$(n.value)' to $(element.name)");
#endif
if (n is GXml.Element) {
#if DEBUG
@@ -161,30 +194,28 @@ public abstract class GXml.SerializableObjectModel : Object, Serializable
#endif
element.children.add (e);
}
- if (n is Text) {
- if (n.value == null) GLib.warning (_("Text node with NULL or none text"));
+ if (n is Text && !serialize_use_xml_node_value ()) {
if (n.value == "") continue;
- var t = doc.create_text (n.value);
+ var t = doc.create_text (n.value._strip ());
element.children.add (t);
#if DEBUG
- GLib.message (@"Serializing Unknown Text Node: '$(n.value)' to '$(element.name)' : Size
$(element.children.size.to_string ())");
- GLib.message (@"Added Text: $(element.children.get (element.children.size - 1))");
+ GLib.message (@"Serialized Unknown Text Node: '$(n.value)' to '$(element.name)' : Size
$(element.children.size.to_string ())");
#endif
}
}
}
// Setting element content
if (serialize_use_xml_node_value ()) {
- // Set un empty string if no value is set for node contents
- string t = "";
#if DEBUG
- stdout.printf (@"SET CONTENT FOR: $(get_type ().name ()): $(element.name)\n");
+ GLib.message (@"SET TEXT NODE FOR: $(get_type ().name ()): $(element.name)\n");
#endif
+ string txt = "";
if (serialized_xml_node_value != null)
- t = serialized_xml_node_value;
- element.content = t;
+ txt = serialized_xml_node_value;
+ var t = doc.create_text (txt);
+ element.children.add (t);
#if DEBUG
- stdout.printf (@"SET CONTENT FOR: $(get_type ().name ()): $(element.name): content '$t'\n");
+ GLib.message (@"SET TEXT CHILD NODE FOR: $(get_type ().name ()): $(element.name): TEXT NODE '$txt'\n");
#endif
}
return element;
@@ -291,69 +322,61 @@ public abstract class GXml.SerializableObjectModel : Object, Serializable
GLib.warning (_("Actual node's name is '%s' expected '%s'").printf (element.name.down (),node_name
().down ()));
}
#if DEBUG
- stdout.printf (@"Deserialize Node: $(element.name)\n");
- stdout.printf (@"Node is: $(element)\n\n");
- stdout.printf (@"Attributes in Node: $(element.name)\n");
+ GLib.message (@"Deserialize Node: $(element.name)\n");
+ GLib.message (@"Node is: $(element)\n\n");
+ GLib.message (@"Attributes in Node: $(element.name)\n");
#endif
foreach (GXml.Node attr in element.attrs.values)
{
deserialize_property (attr);
}
- if (element.children.size > 0)
+ if (get_type ().is_a (typeof (SerializableContainer)))
{
- if (get_type ().is_a (typeof (SerializableContainer)))
- {
#if DEBUG
- stdout.printf (@"This is a Container: found a: $(get_type ().name ())\n");
+ GLib.message (@"This is a Container: found a: $(get_type ().name ())\n");
#endif
- ((SerializableContainer) this).init_containers ();
- }
- var cnodes = new Gee.HashMap<string,ParamSpec> ();
- foreach (ParamSpec spec in list_serializable_properties ())
+ ((SerializableContainer) this).init_containers ();
+ }
+ var cnodes = new Gee.HashMap<string,ParamSpec> ();
+ foreach (ParamSpec spec in list_serializable_properties ())
+ {
+ if (spec.value_type.is_a (typeof (Serializable)))
{
- if (spec.value_type.is_a (typeof (Serializable)))
- {
- if (spec.value_type.is_a (typeof (SerializableCollection)))
- {
- Value vo = Value (spec.value_type);
- get_property (spec.name, ref vo);
- var objv = vo.get_object ();
- if (objv != null) {
- ((Serializable) objv).deserialize (element);
- cnodes set (((Serializable) objv).node_name (), spec);
-// stdout.printf (@"Added Key for container node as: $(((Serializable) objv).node_name
())\n");
- }
+ if (spec.value_type.is_a (typeof (SerializableCollection)))
+ {
+ Value vo = Value (spec.value_type);
+ get_property (spec.name, ref vo);
+ var objv = vo.get_object ();
+ if (objv != null) {
+ ((Serializable) objv).deserialize (element);
+ cnodes set (((Serializable) objv).node_name (), spec);
+// GLib.message (@"Added Key for container node as: $(((Serializable) objv).node_name ())\n");
}
- }
+ }
}
+ }
#if DEBUG
- stdout.printf (@"Elements Nodes in Node: $(element.name)\n");
+ GLib.message (@"Elements Nodes in Node: $(element.name)\n");
#endif
- foreach (Node n in element.children)
- {
- if (n is Text) {
- if (serialize_use_xml_node_value ()) {
- serialized_xml_node_value = n.value;
+ foreach (Node n in element.children) {
#if DEBUG
- GLib.message (@"$(get_type ().name ()): NODE '$(element.name)' CONTENT '$(n.value)'\n");
+ GLib.message ("Node name is NULL?"+(n.name == null).to_string ());
+ if (n.name != null)
+ GLib.message ("Was a Serializable Container node name? "+cnodes.has_key (n.name).to_string ());
#endif
- } else {
- if (get_enable_unknown_serializable_property ()) {
- GLib.message (@"Adding unknown Text node with value: $(n.value)");
- if (n.value._chomp () == n.value && n.value != "") {
- var t = _doc.create_text (n.value);
- _doc.root.children.add (t);
- }
- }
- }
- }
- if (n is GXml.Element && !cnodes.has_key (n.name)) {
+ if (n.name == null) {
+ GLib.warning ("Child node name is null");
+ continue;
+ }
#if DEBUG
- stdout.printf (@"$(get_type ().name ()): DESERIALIZING ELEMENT '$(n.name)'\n");
+ GLib.message ("Checking for Element type? "+(n is GXml.Element).to_string ());
#endif
- deserialize_property (n);
- }
- }
+ if (cnodes.has_key (n.name)) continue;
+#if DEBUG
+ GLib.message ("Before Deserialize Node");
+ GLib.message (@"$(get_type ().name ()): DESERIALIZING Node type: $(n.get_type ().name ()) Name:
'$(n.name)':'$(n.value)'");
+#endif
+ deserialize_property (n);
}
return null;
}
@@ -367,36 +390,27 @@ public abstract class GXml.SerializableObjectModel : Object, Serializable
throws GLib.Error
{
#if DEBUG
- stdout.printf (@"Deserialize Property Node: $(property_node.name)\n");
+ GLib.message (@"Deserialize Property Node: $(property_node.name)\n");
#endif
bool ret = false;
var prop = find_property_spec (property_node.name);
if (prop == null) {
- // FIXME: Event emit
- if (get_enable_unknown_serializable_property ()) {
- if (_doc == null) init_unknown_doc ();
- if (property_node is GXml.Attribute) {
#if DEBUG
- GLib.message (@"Adding unknown attribute $(property_node.name) to $(get_type ().name ())
Size=$(unknown_serializable_properties.size.to_string ())\n");
+ GLib.message (@"Is unknown property or Text content...");
#endif
- ((GXml.Element)_doc.root).set_attr (property_node.name, property_node.value);
- }
- else {
- var e = _doc.create_element (property_node.name);
- _doc.root.children.add (e);
- GXml.Node.copy (_doc, e, property_node, true);
-#if DEBUG
- GLib.message (@"Adding unknown node $(property_node.name) to $(get_type ().name ()):
Size=$(unknown_serializable_nodes.size.to_string ())");
-#endif
- }
- }
+ if (property_node is GXml.Text && serialize_use_xml_node_value ())
+ serialized_xml_node_value = property_node.value;
+ if (get_enable_unknown_serializable_property ())
+ if (_node == null)
+ _node = property_node.parent;
#if DEBUG
- GLib.message (@"Finishing deserialize unknown node/property $(property_node.name) to $(get_type
().name ())");
+ GLib.message (@"Finishing deserialize unknown/Text node/property $(property_node.name) to $(get_type
().name ())");
#endif
return true;
}
#if DEBUG
- GLib.message (@"Checking if $(property_node.name) of type $(prop.value_type.name ()) is
Serializable");
+ GLib.message ("Is known property... deserializing");
+ GLib.message (@"Checking if $(property_node.name) of type $(prop.value_type.name ()) is Serializable");
#endif
if (prop.value_type.is_a (typeof (Serializable)) || prop.value_type.is_a (typeof (SerializableProperty)))
{
diff --git a/gxml/TwNode.vala b/gxml/TwNode.vala
index cd92dae..d48a423 100644
--- a/gxml/TwNode.vala
+++ b/gxml/TwNode.vala
@@ -87,6 +87,7 @@ public abstract class GXml.TwNode : Object, GXml.Node
public override bool add (GXml.Node item) {
#if DEBUG
+ GLib.message ("Is TwNode: "+(item is TwNode).to_string ());
GLib.message ("Setting new parent to TwNode: "+item.name);
#endif
(item as GXml.TwNode).set_parent (_parent);
diff --git a/test/SerializableGeeCollections-Tw-Test.vala b/test/SerializableGeeCollections-Tw-Test.vala
index 67c69f1..198e8be 100644
--- a/test/SerializableGeeCollections-Tw-Test.vala
+++ b/test/SerializableGeeCollections-Tw-Test.vala
@@ -247,7 +247,7 @@ class SerializableGeeCollectionsTwTest : GXmlTest
fmactoy = true;
assert (sh.attrs.get ("manufacturer").value == "MacToy");
assert (sh.attrs.get ("model").value == "A1234");
- assert (sh.children.size == 2);
+ assert (sh.children.size == 5); // 2 nodes 3 texts (identation)
bool falphac = false;
bool fgalax = false;
foreach (GXml.Node s in sh.children){
@@ -317,7 +317,7 @@ class SerializableGeeCollectionsTwTest : GXmlTest
assert (sh.name == "ship");
assert (sh.attrs.get ("manufacturer").value == "Memphis");
assert (sh.attrs.get ("model").value == "AB1");
- assert (sh.children.size == 1);
+ assert (sh.children.size == 3); // 1 node 3 texts (identation)
bool fbetac = false;
foreach (GXml.Node s in sh.children){
if (s.name == "space" && s.attrs.get ("name").value == "Beta Centaury") {
@@ -369,7 +369,7 @@ class SerializableGeeCollectionsTwTest : GXmlTest
assert (r.name == "refaction");
assert (r.attrs.get ("manufacturer").value == "MacToy");
assert (r.attrs.get ("model").value == "Fly045");
- assert (r.children.size == 2);
+ assert (r.children.size == 5); // 2 nodes 3 texts (identation)
bool frmactoy = false;
bool frmega = false;
foreach (GXml.Node rsh in r.children) {
@@ -459,7 +459,7 @@ class SerializableGeeCollectionsTwTest : GXmlTest
assert (refaction != null);
assert (refaction.unknown_serializable_properties != null);
assert (refaction.unknown_serializable_properties.size == 0);
- assert (refaction.unknown_serializable_nodes.size == 1);
+ assert (refaction.unknown_serializable_nodes.size == 5); // 1 node 4 texts (identation)
var doc = new TwDocument ();
s.serialize (doc);
assert (doc.root.name == "base");
diff --git a/test/SerializableGeeCollectionsTest.vala b/test/SerializableGeeCollectionsTest.vala
index 02743f7..54fd95a 100644
--- a/test/SerializableGeeCollectionsTest.vala
+++ b/test/SerializableGeeCollectionsTest.vala
@@ -482,9 +482,17 @@ class SerializableGeeCollectionsTest : GXmlTest
stdout.printf (@"ERROR: No Refaction MacToy/Fly045 found!\n");
assert_not_reached ();
}
- assert (refaction.unknown_serializable_properties != null);
- assert (refaction.unknown_serializable_properties.size == 0);
- assert (refaction.unknown_serializable_nodes.size == 1);
+ var ups = refaction.unknown_serializable_properties;
+ assert (ups != null);
+ assert (ups.size == 0);
+ var uns = refaction.unknown_serializable_nodes;
+#if DEBUG
+ GLib.message (@"Unknown nodes: $(uns.size.to_string ())");
+ foreach (GXml.Node n in uns) {
+ GLib.message ("Uknown node: "+n.name);
+ }
+#endif
+ assert (uns.size == 5); // 4 texts 1 node
var doc = new GDocument ();
s.serialize (doc);
if (doc.root.name != "base") {
diff --git a/test/SerializableGeeHashMapTest.vala b/test/SerializableGeeHashMapTest.vala
index c842cc7..3ccff5d 100644
--- a/test/SerializableGeeHashMapTest.vala
+++ b/test/SerializableGeeHashMapTest.vala
@@ -76,11 +76,11 @@ class SerializableGeeHashMapTest : GXmlTest
if (o.name == "Small") found2 = true;
}
if (!found1) {
- stdout.printf (@"Big is not found\n");
+ GLib.message (@"Big is not found\n");
assert_not_reached ();
}
if (!found2) {
- stdout.printf (@"Small is not found\n");
+ GLib.message (@"Small is not found\n");
assert_not_reached ();
}
found1 = found2 = false;
@@ -89,16 +89,16 @@ class SerializableGeeHashMapTest : GXmlTest
if ((c get (k)).name == "Small") found2 = true;
}
if (!found1) {
- stdout.printf (@"Big key value is not found\n");
+ GLib.message (@"Big key value is not found\n");
assert_not_reached ();
}
if (!found2) {
- stdout.printf (@"Small key value is not found\n");
+ GLib.message (@"Small key value is not found\n");
assert_not_reached ();
}
}
catch (GLib.Error e) {
- stdout.printf (@"ERROR: $(e.message)");
+ GLib.message (@"ERROR: $(e.message)");
}
});
Test.add_func ("/gxml/serializable/serializable_hash_map/serialize",
@@ -129,7 +129,7 @@ class SerializableGeeHashMapTest : GXmlTest
foreach (GXml.Node nd in n.children) {
if (nd is Text) {
if (nd.value != "FAKE TEXT") {
- stdout.printf (@"ERROR: node content don't much. Expected 'FAKE TEXT', got:
$(nd.value)\n$(doc)\n");
+ GLib.message (@"ERROR: node content don't much. Expected 'FAKE TEXT', got:
$(nd.value)\n$(doc)\n");
assert_not_reached ();
}
}
@@ -138,16 +138,16 @@ class SerializableGeeHashMapTest : GXmlTest
}
}
if (!found1) {
- stdout.printf (@"ERROR: Big space node is not found\n$(doc)\n");
+ GLib.message (@"ERROR: Big space node is not found\n$(doc)\n");
assert_not_reached ();
}
if (!found2) {
- stdout.printf (@"ERROR: Small space node is not found\n$(doc)\n");
+ GLib.message (@"ERROR: Small space node is not found\n$(doc)\n");
assert_not_reached ();
}
}
catch (GLib.Error e) {
- stdout.printf (@"ERROR: $(e.message)");
+ GLib.message (@"ERROR: $(e.message)");
assert_not_reached ();
}
});
@@ -159,7 +159,7 @@ class SerializableGeeHashMapTest : GXmlTest
var c = new SerializableHashMap<string,Space> ();
c.deserialize (doc.root);
if (c.size != 2) {
- stdout.printf (@"ERROR: incorrect size must be 2 got: $(c.size)\n");
+ GLib.message (@"ERROR: incorrect size must be 2 got: $(c.size)\n");
assert_not_reached ();
}
bool found1 = false;
@@ -169,16 +169,16 @@ class SerializableGeeHashMapTest : GXmlTest
if ((c get (k)).name == "Small") found2 = true;
}
if (!found1) {
- stdout.printf (@"ERROR: Big key value is not found\n");
+ GLib.message (@"ERROR: Big key value is not found\n");
assert_not_reached ();
}
if (!found2) {
- stdout.printf (@"ERROR: Small key value is not found\n");
+ GLib.message (@"ERROR: Small key value is not found\n");
assert_not_reached ();
}
}
catch (GLib.Error e) {
- stdout.printf (@"ERROR: $(e.message)");
+ GLib.message (@"ERROR: $(e.message)");
assert_not_reached ();
}
});
@@ -190,11 +190,11 @@ class SerializableGeeHashMapTest : GXmlTest
var c = new SpaceContainer ();
c.deserialize (doc);
if (c.owner != "Earth") {
- stdout.printf (@"ERROR: owner must be 'Earth' got: $(c.owner)\n$(doc)\n");
+ GLib.message (@"ERROR: owner must be 'Earth' got: $(c.owner)\n$(doc)\n");
assert_not_reached ();
}
if (c.storage.size != 2) {
- stdout.printf (@"ERROR: Size must be 2 got: $(c.storage.size)\n$(doc)\n");
+ GLib.message (@"ERROR: Size must be 2 got: $(c.storage.size)\n$(doc)\n");
assert_not_reached ();
}
bool found1 = false;
@@ -204,16 +204,16 @@ class SerializableGeeHashMapTest : GXmlTest
if ((c storage get (k)).name == "Small") found2 = true;
}
if (!found1) {
- stdout.printf (@"ERROR: Big key value is not found\n");
+ GLib.message (@"ERROR: Big key value is not found\n");
assert_not_reached ();
}
if (!found2) {
- stdout.printf (@"ERROR: Small key value is not found\n");
+ GLib.message (@"ERROR: Small key value is not found\n");
assert_not_reached ();
}
}
catch (GLib.Error e) {
- stdout.printf (@"ERROR: $(e.message)");
+ GLib.message (@"ERROR: $(e.message)");
assert_not_reached ();
}
});
@@ -247,7 +247,7 @@ class SerializableGeeHashMapTest : GXmlTest
assert (found2);
}
catch (GLib.Error e) {
- stdout.printf (@"ERROR: $(e.message)");
+ GLib.message (@"ERROR: $(e.message)");
assert_not_reached ();
}
});
@@ -292,7 +292,7 @@ class SerializableGeeHashMapTest : GXmlTest
assert (s5 != null);
assert (s5.get_value () == "FAKE5");
} catch (GLib.Error e) {
- stdout.printf (@"ERROR: $(e.message)");
+ GLib.message (@"ERROR: $(e.message)");
assert_not_reached ();
}
});
diff --git a/test/SerializableObjectModelTest.vala b/test/SerializableObjectModelTest.vala
index 9de12b0..14582be 100644
--- a/test/SerializableObjectModelTest.vala
+++ b/test/SerializableObjectModelTest.vala
@@ -408,10 +408,8 @@ class SerializableObjectModelTest : GXmlTest
var manual = new Manual ();
try {
manual.serialize (doc);
- if (doc.root.name != "manual") {
- stdout.printf (@"ERROR MANUAL: GElement: $(doc.root.name)\n");
- assert_not_reached ();
- }
+ assert (doc.root != null);
+ assert (doc.root.name == "manual");
var element = doc.root as GElement;
serialize_manual_check (element, manual);
} catch (GLib.Error e) {
@@ -835,27 +833,20 @@ class SerializableObjectModelTest : GXmlTest
try {
unknown_property.deserialize (doc);
#if DEBUG
+ GLib.message ("Checking unknown attributes...");
foreach (GXml.Attribute a in unknown_property.unknown_serializable_properties.values)
{
GLib.message (@"Unknown Attribute: $(a.name) = $(a.value)");
}
+ GLib.message ("Checking unknown nodes...");
foreach (GXml.Node un in unknown_property.unknown_serializable_nodes) {
GLib.message (@"Unknown Node: $(un.name) = $(un.to_string ())");
}
#endif
- assert (unknown_property.unknown_serializable_properties.size == 2);
- if (unknown_property.unknown_serializable_properties.size != 2) {
- stdout.printf (@"ERROR: UNKNOWN_ATTRIBUTE: size
$(unknown_property.unknown_serializable_properties.size.to_string ())\n");
- foreach (GXml.Node un in unknown_property.unknown_serializable_properties.values) {
- string sv = "__NULL__";
- if (un.value != null)
- sv = un.value;
- stdout.printf (@"Saved unknown property: $(un.name) / '$(sv)'\n");
- }
- assert_not_reached ();
- }
- var ignore = unknown_property.unknown_serializable_properties.get ("ignore");
+ var ukp = unknown_property.unknown_serializable_properties;
+ assert (ukp.size == 2);
+ var ignore = ukp.get ("ignore");
assert (ignore != null);
- var ignore2 = unknown_property.unknown_serializable_properties.get ("ignore2");
+ var ignore2 = ukp.get ("ignore2");
assert (ignore2 != null);
#if DEBUG
GLib.message (@"Unknown nodes = $(unknown_property.unknown_serializable_nodes.size)");
@@ -892,125 +883,45 @@ class SerializableObjectModelTest : GXmlTest
<UnknownChildTwo t = "test">SECOND FAKE TEXT</UnknownChildTwo>
</UnknownChild>
</UnknownNode>FAKE TEXT</UnknownAttribute>""");
+ assert (doc.root.name == "UnknownAttribute");
+ assert (doc.root.children.size == 3);
+ assert (doc.root.children[1].name == "UnknownNode");
+ assert (doc.root.children[2].value == "FAKE TEXT");
+ assert (doc.root.children[1].children.size == 3);
+ assert (doc.root.children[1].children[1].name == "UnknownChild");
+ assert (doc.root.children[1].children[1].children.size == 3);
+ assert (doc.root.children[1].children[1].children[1].name == "UnknownChildTwo");
+ assert (doc.root.children[1].children[1].children[1].children.size == 1);
+ assert (doc.root.children[1].children[1].children[1].children[0] is GXml.Text);
+ assert (doc.root.children[1].children[1].children[1].children[0].value == "SECOND FAKE
TEXT");
var unknown_property = new UnknownAttribute ();
try {
unknown_property.deserialize (doc);
- var doc2 = (GXml.Document) new GDocument ();
+ var doc2 = new GDocument ();
#if DEBUG
- GLib.message ("Prepare to Serialize...");
-#endif
+ GLib.message ("Unknown nodes:");
unknown_property.serialize (doc2);
-#if DEBUG
- GLib.message ("After Serialize...");
- GLib.message ("Serialized back document: \n"+doc2.to_string ());
-#endif
- if (doc2.root == null) {
- stdout.printf (@"ERROR: UNKNOWN_ATTRIBUTE: SERIALIZATION: No Root GElement");
- assert_not_reached ();
- }
- GXml.Element element = (GXml.Element) doc2.root;
- if (element.name.down () != "unknownattribute") {
- stdout.printf (@"ERROR: UNKNOWN_ATTRIBUTE: SERIALIZATION: Root GElement Bad name
$(element.name.down ())");
- assert_not_reached ();
- }
- var ignore = element.attrs.get ("ignore");
- if (ignore == null) {
- stdout.printf (@"ERROR: UNKNOWN_ATTRIBUTE: SERIALIZATION: No attribute ignore");
- assert_not_reached ();
- }
- if (ignore.value != "true") {
- stdout.printf (@"ERROR: UNKNOWN_ATTRIBUTE: SERIALIZATION: Attribute ignore bad
value $(ignore.value)");
- assert_not_reached ();
- }
- var ignore2 = element.attrs.get ("ignore2");
- if (ignore2 == null) {
- stdout.printf (@"ERROR: UNKNOWN_ATTRIBUTE: SERIALIZATION: No attribute ignore");
- assert_not_reached ();
- }
- if (ignore2.value != "test") {
- stdout.printf (@"ERROR: UNKNOWN_ATTRIBUTE: SERIALIZATION: Attribute ignore2 bad
value $(ignore2.value)");
- assert_not_reached ();
- }
- if (element.children.size == 0) {
- stdout.printf (@"ERROR: UNKNOWN_ATTRIBUTE: SERIALIZATION: No child nodes");
- assert_not_reached ();
+ foreach (GXml.Node n in unknown_property.unknown_serializable_nodes) {
+ GLib.message (@"Unknown node: '$(n.name)'");
}
- assert (element.children.size == 2);
- var unkn = element.children.get (0);
- assert (unkn != null);
- assert (unkn.name == "UnknownNode");
- int countechilds = 0;
- GXml.Node child = unkn;
- foreach (GXml.Node n in unkn.children) {
- if (n is GXml.Element) countechilds++;
- if (n.name == "UnknownChild") child = n;
- }
- assert (countechilds == 1);
- var cunkn = child;
- assert (cunkn != null);
- assert (cunkn.name == "UnknownChild");
- assert (cunkn.attrs.size == 1);
- var ca = cunkn.attrs.get ("t");
- assert (ca != null);
- assert (ca.value == "test");
- countechilds = 0;
- foreach (GXml.Node cn in cunkn.children) {
- if (cn is GXml.Element) countechilds++;
- if (cn.name == "UnknownChildTwo") child = cn;
- }
- assert (countechilds == 1);
- var scunkn = child;
- assert (scunkn != null);
- assert (scunkn.name == "UnknownChildTwo");
- var sca = scunkn.attrs.get ("t");
- assert (sca != null);
- assert (sca.value == "test");
- bool found = false;
-#if DEBUG
- GLib.message (@"Second unknown child. Childs nodes = $(scunkn.children.size)");
+ GLib.message ("Prepare to Serialize...");
#endif
- foreach (GXml.Node tn in scunkn.children) {
- assert (tn is GXml.Text);
#if DEBUG
- GLib.message (@"Second unknown Text child = $(tn.value)");
+ GLib.message ("After Serialize...");
+ GLib.message ("Serialized back document: \n"+doc2.libxml_to_string ());
#endif
- if (tn.value == "SECOND FAKE TEXT") found = true;
- }
- assert (found);
- var tscunkn = cunkn.children.get (0);
- assert (tscunkn is GXml.Text);
- bool ctf = false;
- foreach (GXml.Node pnt in element.children) {
- if (pnt is GXml.Text) {
- if (pnt.value == "FAKE TEXT")
- ctf = true;
- }
- }
- assert (ctf);
- found = false;
- foreach (GXml.Node n in element.children) {
- if (n.name == "UnknownNode") {
- found = true;
- var direction = ((Element) n).attrs.get ("direction");
- if (direction == null) {
- stdout.printf (@"ERROR: UNKNOWN_ATTRIBUTE: SERIALIZATION: UnknownNode No
attribute direction");
- assert_not_reached ();
- }
- if (direction.value != "fordward") {
- stdout.printf (@"ERROR: UNKNOWN_ATTRIBUTE: SERIALIZATION: UnknownNode attribute
direction bad value $(direction.value)");
- assert_not_reached ();
- }
- }
- }
- if (!found) {
- stdout.printf (@"ERROR: UNKNOWN_ATTRIBUTE: SERIALIZATION: UnknownNode No not
found");
- assert_not_reached ();
- }
- // TODO: serialized_xml_node_value have more text than expected, may be a bug in
GDocument.to_string ()
- if (unknown_property.serialized_xml_node_value == "FAKE TEXT") {
- stdout.printf (@"ERROR: UNKNOWN_ATTRIBUTE: SERIALIZATION: Bad UnknownAttribute
node's content text $(unknown_property.serialized_xml_node_value)");
- assert_not_reached ();
- }
+ assert (doc2.root != null);
+ assert (doc.root.name == "UnknownAttribute");
+ assert (doc2.root.children.size == 3);
+ assert (doc2.root.children[1].name == "UnknownNode");
+ assert (doc2.root.children[2].value == "FAKE TEXT");
+ assert (doc2.root.children[1].children.size == 3);
+ assert (doc2.root.children[1].children[1].name == "UnknownChild");
+ assert (doc2.root.children[1].children[1].children.size == 3);
+ assert (doc2.root.children[1].children[1].children[1].name == "UnknownChildTwo");
+ assert (doc2.root.children[1].children[1].children[1].children.size == 1);
+ assert (doc2.root.children[1].children[1].children[1].children[0] is GXml.Text);
+ assert (doc2.root.children[1].children[1].children[1].children[0].value == "SECOND
FAKE TEXT");
}
catch (GLib.Error e) {
stdout.printf (@"Error: $(e.message)");
@@ -1108,23 +1019,19 @@ UNKNOWN CONTENT
}
});
}
- static void serialize_manual_check (GElement element, Manual manual)
- {
+ static void serialize_manual_check (GElement element, Manual manual) {
var document = element.get_attr ("document");
- if (document == null) assert_not_reached ();
- if (document.value != manual.document) {
- stdout.printf (@"ERROR MANUAL: document: $(document.value)\n");
- assert_not_reached ();
- }
+ assert (document != null);
+ assert (document.value == manual.document);
var pages = element.get_attr ("pages");
- if (pages == null) assert_not_reached ();
- if (int.parse (pages.value) != manual.pages) {
- stdout.printf (@"ERROR MANUAL: pages: $(pages.value)\n");
- assert_not_reached ();
- }
- if (element.content != manual.get_contents ()) {
- stdout.printf (@"ERROR MANUAL: content: Expected $(manual.get_contents ()): got:
$(element.content)\n");
- assert_not_reached ();
+ assert (pages != null);
+ assert (int.parse (pages.value) == manual.pages);
+ bool found = false;
+ foreach (GXml.Node n in element.children) {
+ if (n is GXml.Text)
+ if (n.value == manual.get_contents ()) found = true;
}
+ assert (found);
}
}
+
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]