[gxml/serialization] Bug Fixes. API simplification for Serializable Containers.
- From: Daniel Espinosa Ortiz <despinosa src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gxml/serialization] Bug Fixes. API simplification for Serializable Containers.
- Date: Fri, 17 Jan 2014 00:42:22 +0000 (UTC)
commit 77db95897473360d12942d4f828ce9b40b3255ec
Author: Daniel Espinosa <esodan gmail com>
Date: Thu Jan 16 18:31:14 2014 -0600
Bug Fixes. API simplification for Serializable Containers.
* Simplified implementing GObjects having Serializable Gee
collections by adding SerializableContainer interface
and implementing se/deserialization in SerializableObjectModel
* Serializable Gee Collections now return default node_name
from its elements
* Fixed bugs on elements' content and unknown properties on
complex tree with sub-containers
* Fixed bug on unknown Text elements
* Fixes, new ones and improves to Unit Test
gxml/Makefile.am | 5 +-
gxml/SerializableContainer.vala | 27 +
gxml/SerializableGeeArrayList.vala | 11 +-
gxml/SerializableGeeDualKeyMap.vala | 29 +-
gxml/SerializableGeeHashMap.vala | 10 +-
gxml/SerializableGeeTreeMap.vala | 13 +-
gxml/SerializableObjectModel.vala | 57 +-
test/Makefile.am | 4 +-
test/SerializableBasicTypesTest.vala | 2 +-
test/SerializableGeeCollectionsTest.vala | 310 +++++--
test/SerializableGeeHashMapTest.vala | 26 +-
test/SerializableGeeTreeMapTest.vala | 30 +-
test/SerializableObjectModelTest.vala | 1615 +++++++++++++++---------------
13 files changed, 1190 insertions(+), 949 deletions(-)
---
diff --git a/gxml/Makefile.am b/gxml/Makefile.am
index 28f5677..08ce7bd 100644
--- a/gxml/Makefile.am
+++ b/gxml/Makefile.am
@@ -65,11 +65,12 @@ libgxml_la_SOURCES = \
SerializableGeeDualKeyMap.vala \
SerializableMapDualKey.vala \
SerializableGeeArrayList.vala \
+ $(NULL) \
+ SerializableContainer.vala \
XPathError.vala \
XPathExpression.vala \
XPathNSResolver.vala \
- XPathResult.vala \
- $(NULL)
+ XPathResult.vala
# TODO: do we want XPath files in own directory?
diff --git a/gxml/SerializableContainer.vala b/gxml/SerializableContainer.vala
new file mode 100644
index 0000000..5d6dd65
--- /dev/null
+++ b/gxml/SerializableContainer.vala
@@ -0,0 +1,27 @@
+/* -*- Mode: vala; indent-tabs-mode: nil; c-basic-offset: 0; tab-width: 2 -*- */
+/* ObjectModel.vala
+ *
+ * Copyright (C) 2014 Daniel Espinosa <esodan gmail com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see <http://www.gnu.org/licenses/>.
+ *
+ * Authors:
+ * Daniel Espinosa <esodan gmail com>
+ */
+
+public abstract class GXml.SerializableContainer : SerializableObjectModel
+{
+ /* Xom interface properties */
+ public abstract void init_containers ();
+}
diff --git a/gxml/SerializableGeeArrayList.vala b/gxml/SerializableGeeArrayList.vala
index 0e6bd80..6991de5 100644
--- a/gxml/SerializableGeeArrayList.vala
+++ b/gxml/SerializableGeeArrayList.vala
@@ -1,4 +1,4 @@
-/* -*- Mode: vala; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
+/* -*- Mode: vala; indent-tabs-mode: nil; c-basic-offset: 2; tab-width: 2 -*- */
/* SerializableGeeTreeModel.vala
*
* Copyright (C) 2013 Daniel Espinosa <esodan gmail com>
@@ -27,19 +27,16 @@ public class GXml.SerializableArrayList<G> : Gee.ArrayList<G>, Serializable
protected ParamSpec[] properties { get; set; }
public GLib.HashTable<string,GLib.ParamSpec> ignored_serializable_properties { get; protected set; }
public string? serialized_xml_node_value { get; protected set; default=null; }
- public bool get_enable_unknown_serializable_property () { return false; }
+
public GLib.HashTable<string,GXml.Node> unknown_serializable_property { get; protected set; }
+ public bool get_enable_unknown_serializable_property () { return false; }
public virtual bool serialize_use_xml_node_value () { return false; }
public virtual bool property_use_nick () { return false; }
public virtual string node_name ()
{
- return "";
- }
- public string default_node_name ()
- {
- return get_type().name().down();
+ return ((Serializable) Object.new (element_type)).node_name ();
}
public virtual GLib.ParamSpec? find_property_spec (string property_name)
diff --git a/gxml/SerializableGeeDualKeyMap.vala b/gxml/SerializableGeeDualKeyMap.vala
index 36bd836..54b6b10 100644
--- a/gxml/SerializableGeeDualKeyMap.vala
+++ b/gxml/SerializableGeeDualKeyMap.vala
@@ -1,4 +1,4 @@
-/* -*- Mode: vala; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
+/* -*- Mode: vala; indent-tabs-mode: nil; c-basic-offset: 2; tab-width: 2 -*- */
/* SerializableGeeTreeModel.vala
*
* Copyright (C) 2013 Daniel Espinosa <esodan gmail com>
@@ -110,19 +110,15 @@ public class GXml.SerializableDualKeyMap<P,S,V> : Object, Serializable
protected ParamSpec[] properties { get; set; }
public GLib.HashTable<string,GLib.ParamSpec> ignored_serializable_properties { get; protected set; }
public string? serialized_xml_node_value { get; protected set; default=null; }
- public bool get_enable_unknown_serializable_property () { return false; }
public GLib.HashTable<string,GXml.Node> unknown_serializable_property { get; protected set; }
+ public virtual bool get_enable_unknown_serializable_property () { return false; }
public virtual bool serialize_use_xml_node_value () { return false; }
public virtual bool property_use_nick () { return false; }
public virtual string node_name ()
{
- return "";
- }
- public string default_node_name ()
- {
- return get_type().name().down();
+ return ((Serializable) Object.new (value_type)).node_name ();
}
public virtual GLib.ParamSpec? find_property_spec (string property_name)
@@ -170,11 +166,9 @@ public class GXml.SerializableDualKeyMap<P,S,V> : Object, Serializable
throws GLib.Error
requires (node is Element)
{
- foreach (HashMap<S,V> h in storage.get_values ()) {
- foreach (V v in h.values) {
+ foreach (V v in values ()) {
if (v is Serializable)
((GXml.Serializable) v).serialize (node);;
- }
}
return node;
}
@@ -198,20 +192,19 @@ public class GXml.SerializableDualKeyMap<P,S,V> : Object, Serializable
}
public GXml.Node? default_deserialize (GXml.Node node)
throws GLib.Error
+ requires (node is Element)
{
if (!(value_type.is_a (typeof (GXml.Serializable)) &&
value_type.is_a (typeof (SerializableMapDualKey)))) {
throw new SerializableError.UNSUPPORTED_TYPE ("%s: Value type '%s' is unsupported",
this.get_type ().name (), value_type.name ());
}
- if (node is Element) {
- foreach (GXml.Node n in node.child_nodes) {
- if (n is Element) {
- var obj = (SerializableMapDualKey<P,S>) Object.new (value_type);
- if (n.node_name == ((Serializable) obj).node_name ()) {
- ((Serializable) obj).deserialize (n);
- @set (obj.get_map_primary_key (), obj.get_map_secondary_key (), obj);
- }
+ foreach (GXml.Node n in node.child_nodes) {
+ if (n is Element) {
+ var obj = (SerializableMapDualKey<P,S>) Object.new (value_type);
+ if (n.node_name == ((Serializable) obj).node_name ()) {
+ ((Serializable) obj).deserialize (n);
+ @set (obj.get_map_primary_key (), obj.get_map_secondary_key (), obj);
}
}
}
diff --git a/gxml/SerializableGeeHashMap.vala b/gxml/SerializableGeeHashMap.vala
index d478859..30d157e 100644
--- a/gxml/SerializableGeeHashMap.vala
+++ b/gxml/SerializableGeeHashMap.vala
@@ -1,4 +1,4 @@
-/* -*- Mode: vala; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
+/* -*- Mode: vala; indent-tabs-mode: nil; c-basic-offset: 2; tab-width: 2 -*- */
/* SerializableGeeTreeModel.vala
*
* Copyright (C) 2013 Daniel Espinosa <esodan gmail com>
@@ -26,19 +26,15 @@ public class GXml.SerializableHashMap<K,V> : Gee.HashMap<K,V>, Serializable
protected ParamSpec[] properties { get; set; }
public GLib.HashTable<string,GLib.ParamSpec> ignored_serializable_properties { get; protected set; }
public string? serialized_xml_node_value { get; protected set; default=null; }
- public bool get_enable_unknown_serializable_property () { return false; }
public GLib.HashTable<string,GXml.Node> unknown_serializable_property { get; protected set; }
+ public virtual bool get_enable_unknown_serializable_property () { return false; }
public virtual bool serialize_use_xml_node_value () { return false; }
public virtual bool property_use_nick () { return false; }
public virtual string node_name ()
{
- return "";
- }
- public string default_node_name ()
- {
- return get_type().name().down();
+ return ((Serializable) Object.new (value_type)).node_name ();
}
public virtual GLib.ParamSpec? find_property_spec (string property_name)
diff --git a/gxml/SerializableGeeTreeMap.vala b/gxml/SerializableGeeTreeMap.vala
index b6144f4..12cce8c 100644
--- a/gxml/SerializableGeeTreeMap.vala
+++ b/gxml/SerializableGeeTreeMap.vala
@@ -1,4 +1,4 @@
-/* -*- Mode: vala; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
+/* -*- Mode: vala; indent-tabs-mode: nil; c-basic-offset: 2; tab-width: 2 -*- */
/* SerializableGeeTreeModel.vala
*
* Copyright (C) 2013 Daniel Espinosa <esodan gmail com>
@@ -26,19 +26,18 @@ public class GXml.SerializableTreeMap<K,V> : Gee.TreeMap<K,V>, Serializable
protected ParamSpec[] properties { get; set; }
public GLib.HashTable<string,GLib.ParamSpec> ignored_serializable_properties { get; protected set; }
public string? serialized_xml_node_value { get; protected set; default=null; }
- public bool get_enable_unknown_serializable_property () { return false; }
public GLib.HashTable<string,GXml.Node> unknown_serializable_property { get; protected set; }
+ public bool get_enable_unknown_serializable_property () { return false; }
public virtual bool serialize_use_xml_node_value () { return false; }
public virtual bool property_use_nick () { return false; }
public virtual string node_name ()
{
- return "";
- }
- public string default_node_name ()
- {
- return get_type().name().down();
+ if (value_type.is_a (typeof (Serializable)))
+ return ((Serializable) Object.new (value_type)).node_name ();
+ else
+ return get_type ().name ();
}
public virtual GLib.ParamSpec? find_property_spec (string property_name)
diff --git a/gxml/SerializableObjectModel.vala b/gxml/SerializableObjectModel.vala
index 5651b6a..a03a08c 100644
--- a/gxml/SerializableObjectModel.vala
+++ b/gxml/SerializableObjectModel.vala
@@ -110,9 +110,13 @@ public abstract class GXml.SerializableObjectModel : Object, Serializable
var a = (Node) element.get_attribute_node (n.node_name);
n.copy (ref a);
}
+ if (n is Text) {
+ var tnode = doc.create_text_node (n.node_value);
+ element.append_child (tnode);
+ }
}
}
- // Setting element content
+ // Setting element content
if (serialize_use_xml_node_value ()) {
// Set un empty string if no value is set for node contents
string t = "";
@@ -216,7 +220,7 @@ public abstract class GXml.SerializableObjectModel : Object, Serializable
return_val_if_fail (element != null, null);
if (node_name () == null) {
message (@"WARNING: Object type '$(get_type ().name ())' have no Node Name defined");
- assert_not_reached ();
+ return null;
}
#if DEBUG
if (element.node_name.down () != node_name ().down ()) {
@@ -235,6 +239,33 @@ public abstract class GXml.SerializableObjectModel : Object, Serializable
#endif
if (element.has_child_nodes ())
{
+ if (get_type ().is_a (typeof (SerializableContainer)))
+ {
+// stdout.printf (@"This is a Container: found a: $(get_type ().name ())\n");
+ ((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 (SerializableTreeMap))
+ || spec.value_type.is_a (typeof (SerializableHashMap))
+ || spec.value_type.is_a (typeof (SerializableDualKeyMap))
+ || spec.value_type.is_a (typeof (SerializableArrayList))
+ )
+ {
+ 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");
+ }
+ }
+ }
+ }
foreach (Node n in element.child_nodes)
{
if (n is Text) {
@@ -243,10 +274,19 @@ public abstract class GXml.SerializableObjectModel : Object, Serializable
#if DEBUG
stdout.printf (@"$(get_type ().name ()): NODE '$(element.node_name)' CONTENT
'$(n.node_value)'\n");
#endif
+ } else {
+ if (get_enable_unknown_serializable_property ()) {
+ if (n.node_value._chomp () == n.node_value && n.node_value != "")
+ unknown_serializable_property.set (n.node_name, n);
+ }
}
}
- else if (n is Element)
+ if (n is Element && !cnodes.has_key (n.node_name)) {
+#if DEBUG
+ stdout.printf (@"$(get_type ().name ()): DESERIALIZING ELEMENT '$(n.node_name)'\n");
+#endif
deserialize_property (n);
+ }
}
}
return null;
@@ -267,8 +307,10 @@ public abstract class GXml.SerializableObjectModel : Object, Serializable
var prop = find_property_spec (property_node.node_name);
if (prop == null) {
// FIXME: Event emit
- if (!(property_node is Text))
+ if (get_enable_unknown_serializable_property ()) {
+// stdout.printf (@"Adding node $(property_node.node_name) to $(get_type ().name ())\n");
unknown_serializable_property.set (property_node.node_name, property_node);
+ }
return true;
}
if (prop.value_type.is_a (typeof (Serializable)))
@@ -315,11 +357,8 @@ public abstract class GXml.SerializableObjectModel : Object, Serializable
}
}
// Attribute can't be deseralized with standard methods. Up to the implementor.
- if (get_enable_unknown_serializable_property ()) {
- this.deserialize_unknown_property (property_node, prop);
- return true;
- }
- return false;
+ this.deserialize_unknown_property (property_node, prop);
+ return true;
}
public abstract string to_string ();
diff --git a/test/Makefile.am b/test/Makefile.am
index 307f386..dbe82da 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -44,10 +44,10 @@ gxml_test_SOURCES = \
SerializableGeeHashMapTest.vala \
SerializableGeeCollectionsTest.vala \
SerializableBasicTypesTest.vala \
+ $(NULL) \
XPathExpressionTest.vala \
XPathNSResolverTest.vala \
- XPathResultTest.vala \
- $(NULL)
+ XPathResultTest.vala
gxml_test.vala.stamp: $(gxml_test_SOURCES)
diff --git a/test/SerializableBasicTypesTest.vala b/test/SerializableBasicTypesTest.vala
index 9a28418..1bfeffe 100644
--- a/test/SerializableBasicTypesTest.vala
+++ b/test/SerializableBasicTypesTest.vala
@@ -1,4 +1,4 @@
-/* -*- Mode: vala; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
+/* -*- Mode: vala; indent-tabs-mode: nil; c-basic-offset: 2; tab-width: 2 -*- */
/**
*
* GXml.Serializable.BasicTypeTest
diff --git a/test/SerializableGeeCollectionsTest.vala b/test/SerializableGeeCollectionsTest.vala
index 5ecd0fd..32f69bd 100644
--- a/test/SerializableGeeCollectionsTest.vala
+++ b/test/SerializableGeeCollectionsTest.vala
@@ -1,8 +1,31 @@
+/* -*- Mode: vala; indent-tabs-mode: nil; c-basic-offset: 2; tab-width: 2 -*- */
+/**
+ *
+ * GXml.Serializable.GeeCollectionsTest
+ *
+ * Authors:
+ *
+ * Daniel Espinosa <esodan gmail com>
+ *
+ *
+ * Copyright (c) 2013-2014 Daniel Espinosa
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
using GXml;
using Gee;
-
-
class SerializableGeeCollectionsTest : GXmlTest
{
class Citizen : SerializableObjectModel
@@ -28,7 +51,7 @@ class SerializableGeeCollectionsTest : GXmlTest
public class Array : SerializableArrayList<Asteroid> {}
}
- class Planet : SerializableObjectModel, SerializableMapKey<string>
+ class Planet : SerializableContainer, SerializableMapKey<string>
{
public string get_map_key () { return name; }
public string name { get; set; }
@@ -36,22 +59,16 @@ class SerializableGeeCollectionsTest : GXmlTest
public Planet.named (string name) { this.name = name; }
public override string node_name () { return "planet"; }
public override string to_string () { return name; }
- public override GXml.Node? deserialize (GXml.Node node)
- throws GLib.Error
- requires (node is GXml.Element)
+
+ public override void init_containers ()
{
- Element element = (Element) node;
- if (element.has_child_nodes ()) {
- if (citizens == null)
- citizens = new Citizen.Array ();
- citizens.deserialize (element);
- }
- return default_deserialize (node);
+ if (citizens == null)
+ citizens = new Citizen.Array ();
}
public class Collection : SerializableTreeMap<string,Planet> {}
}
- class Space : SerializableObjectModel, SerializableMapKey<string>
+ class Space : SerializableContainer, SerializableMapKey<string>
{
public string get_map_key () { return name; }
public string name { get; set; }
@@ -62,22 +79,16 @@ class SerializableGeeCollectionsTest : GXmlTest
public override string node_name () { return "space"; }
public override string to_string () { return name; }
- public override GXml.Node? deserialize (GXml.Node node)
- throws GLib.Error
- requires (node is GXml.Element)
+ public override void init_containers ()
{
- Element element = (Element) node;
- if (element.has_child_nodes ()) {
- if (planets == null)
- planets = new Planet.Collection ();
- planets.deserialize (element);
- }
- return default_deserialize (node);
+ if (asteroids == null)
+ asteroids = new Asteroid.Array ();
+ if (planets == null)
+ planets = new Planet.Collection ();
}
-
public class Collection : SerializableTreeMap<string,Space> {}
}
- class Refaction : SerializableObjectModel, SerializableMapDualKey<string,string>
+ class Refaction : SerializableContainer, SerializableMapDualKey<string,string>
{
public string model { get; set; }
public string manufacturer { get; set; }
@@ -94,22 +105,17 @@ class SerializableGeeCollectionsTest : GXmlTest
public override string node_name () { return "refaction"; }
public override string to_string () { return model; }
- public override GXml.Node? deserialize (GXml.Node node)
- throws GLib.Error
- requires (node is GXml.Element)
+ public override bool get_enable_unknown_serializable_property () { return true; }
+
+ public override void init_containers ()
{
- Element element = (Element) node;
- if (element.has_child_nodes ()) {
- if (spaceships == null)
- spaceships = new SpaceShip.Collection ();
- spaceships.deserialize (element);
- }
- return default_deserialize (node);
+ if (spaceships == null)
+ spaceships = new SpaceShip.Collection ();
}
public class Collection : SerializableDualKeyMap<string,string,Refaction> {}
}
- class SpaceShip : SerializableObjectModel, SerializableMapDualKey<string,string>
+ class SpaceShip : SerializableContainer, SerializableMapDualKey<string,string>
{
public string model { get; set; }
public string manufacturer { get; set; }
@@ -123,63 +129,44 @@ class SerializableGeeCollectionsTest : GXmlTest
public string get_map_primary_key () { return manufacturer; }
public string get_map_secondary_key () { return model; }
-
+
public override string node_name () { return "ship"; }
public override string to_string () { return model; }
- public override GXml.Node? deserialize (GXml.Node node)
- throws GLib.Error
- requires (node is GXml.Element)
+ public override bool get_enable_unknown_serializable_property () { return true; }
+
+ public override void init_containers ()
{
- Element element = (Element) node;
- if (element.has_child_nodes ()) {
- if (spaces == null)
- spaces = new Space.Collection ();
- spaces.deserialize (element);
- }
- return default_deserialize (node);
+ if (spaces == null)
+ spaces = new Space.Collection ();
}
public class Collection : SerializableDualKeyMap<string,string,SpaceShip> {}
}
- class ChargeZone : SerializableObjectModel
+ class ChargeZone : SerializableContainer
{
public string name { get; set; }
public SpaceShip.Collection spaceships { get; set; }
public override string node_name () { return "ChargeZone"; }
public override string to_string () { return name; }
- public override GXml.Node? deserialize (GXml.Node node)
- throws GLib.Error
- requires (node is Element)
+ public override void init_containers ()
{
- var element = (Element) node;
- if (element.has_child_nodes ()) {
- if (spaceships == null)
- spaceships = new SpaceShip.Collection ();
- spaceships.deserialize (element);
- }
- return default_deserialize (node);
+ if (spaceships == null)
+ spaceships = new SpaceShip.Collection ();
}
}
- class Storage : SerializableObjectModel
+ class Storage : SerializableContainer
{
public string name { get; set; }
public Refaction.Collection refactions { get; set; }
public override string node_name () { return "storage"; }
public override string to_string () { return name; }
- public override GXml.Node? deserialize (GXml.Node node)
- throws GLib.Error
- requires (node is Element)
+ public override void init_containers ()
{
- var element = (Element) node;
- if (element.has_child_nodes ()) {
- if (refactions == null)
- refactions = new Refaction.Collection ();
- refactions.deserialize (element);
- }
- return default_deserialize (node);
+ if (refactions == null)
+ refactions = new Refaction.Collection ();
}
}
@@ -191,6 +178,7 @@ class SerializableGeeCollectionsTest : GXmlTest
public override string node_name () { return "base"; }
public override string to_string () { return name; }
}
+
public static void add_tests ()
{
Test.add_func ("/gxml/serializable/convined_gee_containers/deserialize",
@@ -420,5 +408,187 @@ class SerializableGeeCollectionsTest : GXmlTest
assert_not_reached ();
}
});
+ Test.add_func ("/gxml/serializable/convined_gee_containers/se-deserialize-unknowns",
+ () => {
+ try {
+ var org_doc = new Document.from_string ("""<?xml version="1.0"?>
+<base name="AlphaOne" >
+ <chargezone name="A1-1">
+ <ship manufacturer="MacToy" model="A1234">
+ <space name="Alpha Centaury">
+ <planet name="Earth">
+ <citizen ctype="Human">1M</citizen>
+ <citizen ctype="Ghost">10M</citizen>
+ </planet>
+ <planet name="Galiumt" />
+ </space>
+ <space name="Galax">
+ <planet name="Saminon">
+ <citizen ctype="Humanes">100M</citizen>
+ <citizen ctype="Jeties">1000M</citizen>
+ </planet>
+ <planet name="Keymanth" />
+ </space>
+ </ship>
+ <ship manufacturer="Memphis" model="AB1">
+ <space name="Proximity">
+ <planet name="Pluton">
+ <citizen ctype="Ork">10000M</citizen>
+ <citizen ctype="Gyk">100000M</citizen>
+ </planet>
+ <planet name="Mercury" />
+ </space>
+ </ship>
+ </chargezone>
+ <storage name="B4-A4">
+ <refaction manufacturer="MacToy" model="Fly045">
+ <ship manufacturer="MacToy" model="A1234" />
+ <ship manufacturer="MegaTrench" model="G045-1" unknown="UNKNOWN ATTR">TEST_TEXT</ship>
+ <UnknownAttribute name="nothing" />
+ </refaction>
+ </storage>
+</base>""");
+ var s = new SpaceBase ();
+ s.deserialize (org_doc);
+ if (s.charge_zone == null) {
+ stdout.printf (@"ERROR: No charge Zone for $(s.name)\n");
+ assert_not_reached ();
+ }
+ if (s.charge_zone.spaceships.size != 2) {
+ stdout.printf (@"ERROR: Bad SpaceShip size: $(s.charge_zone.spaceships.size)\n");
+ assert_not_reached ();
+ }
+ var mssh = s charge_zone spaceships get ("MacToy","A1234");
+ if (mssh == null) {
+ stdout.printf (@"ERROR: No spaceship MacToy/A1234\n");
+ assert_not_reached ();
+ }
+
+ if (s.storage == null) {
+ stdout.printf (@"ERROR: No storage\n");
+ assert_not_reached ();
+ }
+ if (mssh.spaces.size != 2) {
+ stdout.printf (@"ERROR: Bad spaces number for MacToy/A1234: $(mssh.spaces.size)\n");
+ assert_not_reached ();
+ }
+ if (s.storage == null) {
+ stdout.printf (@"ERROR: No storage\n");
+ assert_not_reached ();
+ }
+ if (s.storage.refactions.size != 1) {
+ stdout.printf (@"ERROR: Bad number of refactions: got $(s.storage.refactions.size)\n");
+ assert_not_reached ();
+ }
+ var refaction = s storage refactions get ("MacToy","Fly045");
+ if (refaction == null) {
+ stdout.printf (@"ERROR: No Refaction MacToy/Fly045 found!\n");
+ assert_not_reached ();
+ }
+ if (refaction.unknown_serializable_property == null) {
+ stdout.printf (@"ERROR: Refaction: No unknown properties/nodes found!\n");
+ assert_not_reached ();
+ }
+ if (refaction.unknown_serializable_property.size () != 1) {
+ stdout.printf (@"ERROR: Refaction: Bad unknown properties/nodes number: found
$(refaction.unknown_serializable_property.size ())\n");
+ foreach (GXml.Node unk in refaction.unknown_serializable_property.get_values ())
+ {
+ string unkv = "___NULL__";
+ if (unk.node_value != null)
+ unkv = unk.node_value;
+ stdout.printf (@"Unknown Node: $(unk.node_name) / value: '$(unkv)'");
+ }
+ assert_not_reached ();
+ }
+ var doc = new Document ();
+ s.serialize (doc);
+ if (doc.document_element.node_name != "base") {
+ stdout.printf (@"ERROR: bad root node name\n");
+ assert_not_reached ();
+ }
+ stdout.printf (@"$doc\n");
+ foreach (GXml.Node n in doc.document_element.child_nodes) {
+ if (n is Element) {
+ if (n.node_name == "ChargeZone") {
+
+ }
+ if (n.node_name == "storage") {
+ bool unkfound = false;
+ bool tfound = false;
+ bool attrfound = false;
+ foreach (GXml.Node sn in n.child_nodes) {
+ if (sn is Element) {
+ if (sn.node_name == "refaction") {
+ foreach (GXml.Node rn in sn.child_nodes) {
+ if (rn is Element) {
+ stdout.printf (@"Refaction current node: '$(rn.node_name)'\n");
+ if (rn.node_name == "ship") {
+ var atr = ((Element) rn).get_attribute_node ("manufacturer");
+ if (atr == null) {
+ stdout.printf (@"ERROR: No attribute manufacturer for Ship\n");
+ assert_not_reached ();
+ }
+ if (atr.node_value == "MegaTrench") {
+ var shanattr = ((Element) rn).get_attribute_node ("unknown");
+ if (shanattr != null) {
+ attrfound = true;
+ if (shanattr.node_value != "UNKNOWN ATTR") {
+ stdout.printf (@"ERROR: Invalid Text Node Value for ship MegaTrench:
$(shanattr.node_value)\n");
+ assert_not_reached ();
+ }
+ }
+ foreach (GXml.Node shn in rn.child_nodes) {
+ stdout.printf (@"Refaction: Ship MegaTrench: Node: $(shn.node_name)\n");
+ if (shn is Text) {
+ tfound = true;
+ if (shn.node_value != "TEST_TEXT") {
+ stdout.printf (@"ERROR: Invalid Text Node Value for ship MegaTrench:
$(shn.node_value)\n");
+ assert_not_reached ();
+ }
+ }
+ }
+ }
+ }
+ if (rn.node_name == "UnknownAttribute") {
+ unkfound = true;
+ var nattr = ((Element) rn).get_attribute_node ("name");
+ if (nattr == null) {
+ stdout.printf (@"ERROR: No Unknown Attribute Node with attribute name\n");
+ assert_not_reached ();
+ }
+ if (nattr.node_value != "nothing") {
+ stdout.printf (@"ERROR: Invalid unknown attribute node's attribute name value:
found $(nattr.node_value)\n");
+ assert_not_reached ();
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ if (!attrfound) {
+ stdout.printf (@"ERROR: No Unknown AttributeText found for ship MegaTrench\n");
+ assert_not_reached ();
+ }
+ if (!tfound) {
+ stdout.printf (@"ERROR: No Text Node Value found for ship MegaTrench\n");
+ assert_not_reached ();
+ }
+ if (!unkfound) {
+ stdout.printf (@"ERROR: No Unknown Attribute Node found for storage\n");
+ assert_not_reached ();
+ }
+ }
+ }
+ if (n is Text) {
+ stdout.printf (@"ROOT NODE VALUE: '$(n.node_value)'\n");
+ }
+ }
+ }
+ catch (GLib.Error e) {
+ stdout.printf (@"ERROR: $(e.message)");
+ assert_not_reached ();
+ }
+ });
}
}
diff --git a/test/SerializableGeeHashMapTest.vala b/test/SerializableGeeHashMapTest.vala
index be67b83..1fd5107 100644
--- a/test/SerializableGeeHashMapTest.vala
+++ b/test/SerializableGeeHashMapTest.vala
@@ -18,30 +18,20 @@ class SerializableGeeHashMapTest : GXmlTest
public override bool serialize_use_xml_node_value () { return true; }
public override string node_name () { return "space"; }
public override string to_string () { return name; }
+ public class Collection : SerializableHashMap<string,Space> {}
}
- class SpaceContainer : SerializableObjectModel
+ class SpaceContainer : SerializableContainer
{
public string owner { get; set; }
- public SpaceCollection storage { get; set; }
+ public Space.Collection storage { get; set; }
public override string node_name () { return "spacecontainer"; }
public override string to_string () { return owner; }
- public override GXml.Node? deserialize (GXml.Node node)
- throws GLib.Error
- {
- Element element;
- if (node is Document)
- element = ((Document) node).document_element;
- else
- element = (Element) node;
- if (element.has_child_nodes ()) {
- if (storage == null)
- storage = new SpaceCollection ();
- storage.deserialize (element);
- }
- return default_deserialize (node);
+ // SerializableContainer: Init containers
+ public override void init_containers () {
+ if (storage == null)
+ storage = new Space.Collection ();
}
- public class SpaceCollection : SerializableHashMap<string,Space> {}
}
public static void add_tests ()
@@ -211,7 +201,7 @@ class SerializableGeeHashMapTest : GXmlTest
var c = new SpaceContainer ();
var o1 = new Space.named ("Big");
var o2 = new Space.named ("Small");
- c.storage = new SpaceContainer.SpaceCollection ();
+ c.storage = new Space.Collection ();
c.storage.set (o1.name, o1);
c.storage.set (o2.name, o2);
var doc = new Document ();
diff --git a/test/SerializableGeeTreeMapTest.vala b/test/SerializableGeeTreeMapTest.vala
index d57d324..9a59f25 100644
--- a/test/SerializableGeeTreeMapTest.vala
+++ b/test/SerializableGeeTreeMapTest.vala
@@ -10,30 +10,20 @@ class SerializableGeeTreeMapTest : GXmlTest
public Space.named (string name) { this.name = name; }
public override string node_name () { return "space"; }
public override string to_string () { return name; }
+ public class Collection : SerializableTreeMap<string,Space> {}
}
- class SpaceContainer : SerializableObjectModel
+ class SpaceContainer : SerializableContainer
{
public string owner { get; set; }
- public SpaceCollection storage { get; set; }
+ public Space.Collection storage { get; set; }
public override string node_name () { return "spacecontainer"; }
public override string to_string () { return owner; }
- public override GXml.Node? deserialize (GXml.Node node)
- throws GLib.Error
- {
- Element element;
- if (node is Document)
- element = ((Document) node).document_element;
- else
- element = (Element) node;
- if (element.has_child_nodes ()) {
- if (storage == null)
- storage = new SpaceCollection ();
- storage.deserialize (element);
- }
- return default_deserialize (node);
+// SerializableContainer overrides
+ public override void init_containers () {
+ if (storage == null)
+ storage = new Space.Collection ();
}
- public class SpaceCollection : SerializableTreeMap<string,Space> {}
}
public static void add_tests ()
@@ -161,6 +151,10 @@ class SerializableGeeTreeMapTest : GXmlTest
stdout.printf (@"ERROR: owner must be 'Earth' got: $(c.owner)\n$(doc)\n");
assert_not_reached ();
}
+ if (c.storage == null) {
+ stdout.printf (@"ERROR: storage doesn't exist\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");
assert_not_reached ();
@@ -191,7 +185,7 @@ class SerializableGeeTreeMapTest : GXmlTest
var c = new SpaceContainer ();
var o1 = new Space.named ("Big");
var o2 = new Space.named ("Small");
- c.storage = new SpaceContainer.SpaceCollection ();
+ c.storage = new Space.Collection ();
c.storage.set (o1.name, o1);
c.storage.set (o2.name, o2);
var doc = new Document ();
diff --git a/test/SerializableObjectModelTest.vala b/test/SerializableObjectModelTest.vala
index b1010a3..693f6e5 100644
--- a/test/SerializableObjectModelTest.vala
+++ b/test/SerializableObjectModelTest.vala
@@ -1,6 +1,5 @@
using GXml;
using Gee;
-
const string XML_COMPUTER_FILE =
"""<?xml version="1.0"?>
<computer manufacturer="ThecnicalGroup" model="YH576G" cores="4" ghz="2.8"/>""";
@@ -19,15 +18,14 @@ const string XML_PACKAGE_FILE =
const string XML_PACKAGE_UNKNOWN_NODES_FILE =
"""<?xml version="1.0"?>
<PACKAGE source="Mexico/North" destiny="Brazil" Hope="2/4.04">
- <manual document="Sales Card" pages="1">Selling Card Specification</manual>
- <Computer manufacturer="BoxingLAN" model="J24-EX9" cores="32" ghz="1.8"/>
- <Box size="1" volume="33.15" units="cm3" />
+<manual document="Sales Card" pages="1">Selling Card Specification</manual>
+<Computer manufacturer="BoxingLAN" model="J24-EX9" cores="32" ghz="1.8"/>
+<Box size="1" volume="33.15" units="cm3" />
</PACKAGE>""";
const string XML_CPU_FILE =
"""<?xml version="1.0"?>
<cpu ghz="3.85" piles="1,2,3"/>""";
-
public class ObjectModel : SerializableObjectModel
{
public override string to_string ()
@@ -44,7 +42,6 @@ public class ObjectModel : SerializableObjectModel
return ret + "}";
}
}
-
public class Computer : ObjectModel
{
[Description (nick="Manufacturer")]
@@ -52,7 +49,7 @@ public class Computer : ObjectModel
public string model { get; set; }
public int cores { get; set; }
public float ghz { get; set; }
-
+
public Computer ()
{
manufacturer = "MexicanLaptop, Inc.";
@@ -68,14 +65,14 @@ public class Manual : ObjectModel
public int pages { get; set; }
public string get_contents () { return serialized_xml_node_value; }
public void set_contents (string val) { serialized_xml_node_value = val; }
-
+
public Manual ()
{
document = "MANUAL DOCUMENTATION";
pages = 3;
set_contents ("TEXT INTO THE MANUAL DOCUMENT");
}
-
+
public override string to_string ()
{
return base.to_string () + @"CONTENTS: { $(get_contents ())}";
@@ -117,7 +114,7 @@ public class Package : ObjectModel
((Serializable) this).deserialize_unknown_property.connect ( (element, prop) => {
//GLib.message (@"Deserializing Unknown Property: $(prop.name) | $(prop.get_nick ())");
if (element.node_name == "tag") {
- tags.append_val (((Element) element).content);
+ tags.append_val (((Element) element).content);
}
});
}
@@ -207,7 +204,7 @@ class Configuration : ObjectModel
public string device { get; set; }
public override string node_name () { return "Configuration"; }
public override bool property_use_nick () { return true; }
-
+
public Configuration ()
{
init_properties (); // initializing properties to be ignored by default
@@ -228,7 +225,7 @@ class Configuration : ObjectModel
n = (GXml.Node) (((GXml.Document) node).document_element);
else
n = node;
-
+
foreach (GXml.Node ns in n.namespace_definitions) {
//stdout.printf (@"Namespace = $(ns.node_value)");
if (ns.node_name == "om" && ns.node_value == "http://www.gnome.org/gxml/0.4")
@@ -264,807 +261,845 @@ class Options : ObjectModel
public string test { get; set; }
public OptionsEnum options { get; set; }
}
-
class SerializableObjectModelTest : GXmlTest
{
public static void add_tests ()
{
Test.add_func ("/gxml/serializable/object_model/serialize/simple_object",
- () => {
- try {
- var computer = new Computer ();
- var doc = new Document ();
- computer.serialize (doc);
- if (doc.document_element.tag_name.down () != "computer") {
- stdout.printf ("ERROR XML_COMPUTER: computer\n");
- assert_not_reached ();
- }
- var m = doc.document_element.get_attribute_node ("manufacturer");
- if (m == null) assert_not_reached ();
- if (m.node_value != "MexicanLaptop, Inc.") {
- stdout.printf ("ERROR XML_COMPUTER: manufacturer\n");
- assert_not_reached ();
- }
- var mod = doc.document_element.get_attribute_node ("model");
- if (mod == null) assert_not_reached ();
- if (mod.node_value != "LQ59678") {
- stdout.printf ("ERROR XML_COMPUTER: model\n");
- assert_not_reached ();
- }
- var c = doc.document_element.get_attribute_node ("cores");
- if (c == null) assert_not_reached ();
- if (c.node_value != "8") {
- stdout.printf ("ERROR XML_COMPUTER: cores val\n");
- assert_not_reached ();
- }
- var g = doc.document_element.get_attribute_node ("ghz");
- if (g == null) assert_not_reached ();
- if (double.parse (g.node_value) != (double) 3.5) {
- stdout.printf ("ERROR XML_COMPUTER: ghz val\n");
- assert_not_reached ();
- }
- }
- catch (GLib.Error e)
- {
- GLib.message (e.message);
- assert_not_reached ();
- }
- }
- );
+ () => {
+ try {
+ var computer = new Computer ();
+ var doc = new Document ();
+ computer.serialize (doc);
+ if (doc.document_element.tag_name.down () != "computer") {
+ stdout.printf ("ERROR XML_COMPUTER: computer\n");
+ assert_not_reached ();
+ }
+ var m = doc.document_element.get_attribute_node ("manufacturer");
+ if (m == null) assert_not_reached ();
+ if (m.node_value != "MexicanLaptop, Inc.") {
+ stdout.printf ("ERROR XML_COMPUTER: manufacturer\n");
+ assert_not_reached ();
+ }
+ var mod = doc.document_element.get_attribute_node ("model");
+ if (mod == null) assert_not_reached ();
+ if (mod.node_value != "LQ59678") {
+ stdout.printf ("ERROR XML_COMPUTER: model\n");
+ assert_not_reached ();
+ }
+ var c = doc.document_element.get_attribute_node ("cores");
+ if (c == null) assert_not_reached ();
+ if (c.node_value != "8") {
+ stdout.printf ("ERROR XML_COMPUTER: cores val\n");
+ assert_not_reached ();
+ }
+ var g = doc.document_element.get_attribute_node ("ghz");
+ if (g == null) assert_not_reached ();
+ if (double.parse (g.node_value) != (double) 3.5) {
+ stdout.printf ("ERROR XML_COMPUTER: ghz val\n");
+ assert_not_reached ();
+ }
+ }
+ catch (GLib.Error e)
+ {
+ GLib.message (e.message);
+ assert_not_reached ();
+ }
+ }
+ );
Test.add_func ("/gxml/serializable/object_model/deserialize_simple_object",
- () => {
- var computer = new Computer ();
- try {
- var doc = new Document.from_string (XML_COMPUTER_FILE);
- computer.deserialize (doc);
- if (computer.manufacturer != "ThecnicalGroup") {
- stdout.printf (@"ERROR XML_COMPUTER: manufacturer val: $(computer.manufacturer)\n");
- assert_not_reached ();
- }
- if (computer.model !="YH576G") {
- stdout.printf (@"ERROR XML_COMPUTER: model val: $(computer.model)\n");
- assert_not_reached ();
- }
- if (computer.cores != 4) {
- stdout.printf (@"ERROR XML_COMPUTER: cores val: $(computer.cores)\n");
- assert_not_reached ();
- }
- if (computer.ghz != (float) 2.8) {
- stdout.printf (@"ERROR XML_COMPUTER: ghz val: $(computer.ghz)\n");
- assert_not_reached ();
- }
- } catch (GLib.Error e)
- {
- GLib.message (@"GHz : $(computer.to_string ()) ERROR: $(e.message)");
- assert_not_reached ();
- }
- }
- );
+ () => {
+ var computer = new Computer ();
+ try {
+ var doc = new Document.from_string (XML_COMPUTER_FILE);
+ computer.deserialize (doc);
+ if (computer.manufacturer != "ThecnicalGroup") {
+ stdout.printf (@"ERROR XML_COMPUTER: manufacturer val: $(computer.manufacturer)\n");
+ assert_not_reached ();
+ }
+ if (computer.model !="YH576G") {
+ stdout.printf (@"ERROR XML_COMPUTER: model val: $(computer.model)\n");
+ assert_not_reached ();
+ }
+ if (computer.cores != 4) {
+ stdout.printf (@"ERROR XML_COMPUTER: cores val: $(computer.cores)\n");
+ assert_not_reached ();
+ }
+ if (computer.ghz != (float) 2.8) {
+ stdout.printf (@"ERROR XML_COMPUTER: ghz val: $(computer.ghz)\n");
+ assert_not_reached ();
+ }
+ } catch (GLib.Error e)
+ {
+ GLib.message (@"GHz : $(computer.to_string ()) ERROR: $(e.message)");
+ assert_not_reached ();
+ }
+ }
+ );
Test.add_func ("/gxml/serializable/object_model/deserialize_object_contents",
- () => {
- var manual = new Manual ();
- try {
- var doc = new Document.from_string ("""<?xml version="1.0"?>
-<manual document="Specification" pages="3">This is an Specification file</manual>""");
- manual.deserialize (doc);
- if (manual.document != "Specification") {
- stdout.printf (@"ERROR MANUAL: Bad document value. Expected 'Specification', got:
$(manual.document)\n");
- assert_not_reached ();
- }
- if (manual.pages != 3) {
- stdout.printf (@"ERROR MANUAL: Bad pages value. Expected '3', got: $(manual.pages)\n");
- assert_not_reached ();
- }
- if (manual.get_contents () != "This is an Specification file") {
- stdout.printf (@"ERROR MANUAL: Bad Element content value. Expected 'This is an Specification
file', got: $(manual.get_contents ())\n");
- assert_not_reached ();
- }
- }
- catch (GLib.Error e) {
- GLib.message (@"Error: $(e.message)");
- assert_not_reached ();
- }
- }
- );
+ () => {
+ var manual = new Manual ();
+ try {
+ var doc = new Document.from_string ("""<?xml version="1.0"?>
+ <manual document="Specification" pages="3">This is an Specification file</manual>""");
+ manual.deserialize (doc);
+ if (manual.document != "Specification") {
+ stdout.printf (@"ERROR MANUAL: Bad document value. Expected 'Specification', got:
$(manual.document)\n");
+ assert_not_reached ();
+ }
+ if (manual.pages != 3) {
+ stdout.printf (@"ERROR MANUAL: Bad pages value. Expected '3', got:
$(manual.pages)\n");
+ assert_not_reached ();
+ }
+ if (manual.get_contents () != "This is an Specification file") {
+ stdout.printf (@"ERROR MANUAL: Bad Element content value. Expected 'This is an
Specification file', got: $(manual.get_contents ())\n");
+ assert_not_reached ();
+ }
+ }
+ catch (GLib.Error e) {
+ GLib.message (@"Error: $(e.message)");
+ assert_not_reached ();
+ }
+ }
+ );
Test.add_func ("/gxml/serializable/object_model/serialize_object_contents",
- () => {
- var doc = new Document ();
- var manual = new Manual ();
- try {
- manual.serialize (doc);
- if (doc.document_element.node_name != "manual") {
- stdout.printf (@"ERROR MANUAL: Element: $(doc.document_element.node_name)\n");
- assert_not_reached ();
- }
- Element element = doc.document_element;
- serialize_manual_check (element, manual);
- } catch (GLib.Error e) {
- stdout.printf (@"$(e.message)");
- assert_not_reached ();
- }
- }
- );
+ () => {
+ var doc = new Document ();
+ var manual = new Manual ();
+ try {
+ manual.serialize (doc);
+ if (doc.document_element.node_name != "manual") {
+ stdout.printf (@"ERROR MANUAL: Element: $(doc.document_element.node_name)\n");
+ assert_not_reached ();
+ }
+ Element element = doc.document_element;
+ serialize_manual_check (element, manual);
+ } catch (GLib.Error e) {
+ stdout.printf (@"$(e.message)");
+ assert_not_reached ();
+ }
+ }
+ );
Test.add_func ("/gxml/serializable/object_model/deserialize_serializable_properties",
- () => {
- var package = new Package ();
- try {
- var doc = new Document.from_string (XML_PACKAGE_FILE);
- package.deserialize (doc);
- if (package.source != "Mexico/Central") {
- stdout.printf (@"ERROR PACKAGE: source: $(package.source)\n");
- assert_not_reached ();
- }
- if (package.destiny != "Japan") {
- stdout.printf (@"ERROR PACKAGE: destiny: $(package.destiny)\n");
- assert_not_reached ();
- }
- /*if (package.unknown_to_string () != "Unknown Properties: {\n}") {
- stdout.printf (@"ERROR PACKAGE: package unknown properties: $(package.unknown_to_string ())\n");
- assert_not_reached ();
- }*/
- if (package.manual.document != "Specification") {
- stdout.printf (@"ERROR PACKAGE: manual document: $(package.manual.document)\n");
- assert_not_reached ();
- }
- if (package.manual.pages != 3) {
- stdout.printf (@"ERROR PACKAGE: manual pages: $(package.manual.pages)\n");
- assert_not_reached ();
- }
- if (package.manual.get_contents () != "This is an Specification file") {
- stdout.printf (@"ERROR PACKAGE: manual value: $(package.manual.get_contents ())\n");
- assert_not_reached ();
- }
- if (package.computer.manufacturer != "LanCorop") {
- stdout.printf (@"ERROR PACKAGE: computer manufacturer: $(package.computer.manufacturer)\n");
- assert_not_reached ();
- }
- if (package.computer.model != "Lap39120") {
- stdout.printf (@"ERROR PACKAGE: computer model: $(package.computer.model)\n");
- assert_not_reached ();
- }
- if (package.computer.cores != 16) {
- stdout.printf (@"ERROR PACKAGE: computer cores: $(package.computer.cores)\n");
- assert_not_reached ();
- }
- if (package.computer.ghz != (float) 3.5) {
- stdout.printf (@"ERROR PACKAGE: computer ghz $(package.computer.ghz)\n");
- assert_not_reached ();
- }
- }
- catch (GLib.Error e) {
- GLib.message (@"Error: $(e.message)");
- assert_not_reached ();
- }
- }
- );
+ () => {
+ var package = new Package ();
+ try {
+ var doc = new Document.from_string (XML_PACKAGE_FILE);
+ package.deserialize (doc);
+ if (package.source != "Mexico/Central") {
+ stdout.printf (@"ERROR PACKAGE: source: $(package.source)\n");
+ assert_not_reached ();
+ }
+ if (package.destiny != "Japan") {
+ stdout.printf (@"ERROR PACKAGE: destiny: $(package.destiny)\n");
+ assert_not_reached ();
+ }
+ /*if (package.unknown_to_string () != "Unknown Properties: {\n}") {
+ stdout.printf (@"ERROR PACKAGE: package unknown properties:
$(package.unknown_to_string ())\n");
+ assert_not_reached ();
+ }*/
+ if (package.manual.document != "Specification") {
+ stdout.printf (@"ERROR PACKAGE: manual document: $(package.manual.document)\n");
+ assert_not_reached ();
+ }
+ if (package.manual.pages != 3) {
+ stdout.printf (@"ERROR PACKAGE: manual pages: $(package.manual.pages)\n");
+ assert_not_reached ();
+ }
+ if (package.manual.get_contents () != "This is an Specification file") {
+ stdout.printf (@"ERROR PACKAGE: manual value: $(package.manual.get_contents ())\n");
+ assert_not_reached ();
+ }
+ if (package.computer.manufacturer != "LanCorop") {
+ stdout.printf (@"ERROR PACKAGE: computer manufacturer:
$(package.computer.manufacturer)\n");
+ assert_not_reached ();
+ }
+ if (package.computer.model != "Lap39120") {
+ stdout.printf (@"ERROR PACKAGE: computer model: $(package.computer.model)\n");
+ assert_not_reached ();
+ }
+ if (package.computer.cores != 16) {
+ stdout.printf (@"ERROR PACKAGE: computer cores: $(package.computer.cores)\n");
+ assert_not_reached ();
+ }
+ if (package.computer.ghz != (float) 3.5) {
+ stdout.printf (@"ERROR PACKAGE: computer ghz $(package.computer.ghz)\n");
+ assert_not_reached ();
+ }
+ }
+ catch (GLib.Error e) {
+ GLib.message (@"Error: $(e.message)");
+ assert_not_reached ();
+ }
+ }
+ );
Test.add_func ("/gxml/serializable/object_model/serialize_serializable_properties",
- () => {
- var doc = new Document ();
- var package = new Package ();
- try {
- package.serialize (doc);
- if (doc.document_element.node_name != "package") {
- stdout.printf (@"ERROR MANUAL: Element: $(doc.document_element.node_name)\n");
- assert_not_reached ();
- }
- Element element = doc.document_element;
- var source = element.get_attribute_node ("source");
- if (source == null ) assert_not_reached ();
- if (source.node_value != "Mexico") {
- stdout.printf (@"ERROR PACKAGE: source: $(source.node_value)\n");
- assert_not_reached ();
- }
- var destiny = element.get_attribute_node ("destiny");
- if (destiny == null ) assert_not_reached ();
- if (destiny.node_value != "World") {
- stdout.printf (@"ERROR PACKAGE: source: $(destiny.node_value)\n");
- assert_not_reached ();
- }
- }
- catch (GLib.Error e) {
- GLib.message (@"Error: $(e.message)");
- assert_not_reached ();
- }
- }
- );
+ () => {
+ var doc = new Document ();
+ var package = new Package ();
+ try {
+ package.serialize (doc);
+ if (doc.document_element.node_name != "package") {
+ stdout.printf (@"ERROR MANUAL: Element: $(doc.document_element.node_name)\n");
+ assert_not_reached ();
+ }
+ Element element = doc.document_element;
+ var source = element.get_attribute_node ("source");
+ if (source == null ) assert_not_reached ();
+ if (source.node_value != "Mexico") {
+ stdout.printf (@"ERROR PACKAGE: source: $(source.node_value)\n");
+ assert_not_reached ();
+ }
+ var destiny = element.get_attribute_node ("destiny");
+ if (destiny == null ) assert_not_reached ();
+ if (destiny.node_value != "World") {
+ stdout.printf (@"ERROR PACKAGE: source: $(destiny.node_value)\n");
+ assert_not_reached ();
+ }
+ }
+ catch (GLib.Error e) {
+ GLib.message (@"Error: $(e.message)");
+ assert_not_reached ();
+ }
+ }
+ );
Test.add_func ("/gxml/serializable/object_model/deserialize_array_property",
- () => {
- var doc = new Document.from_string (XML_PACKAGE_FILE);
- var package = new Package ();
- try {
- package.deserialize (doc);
- if (package.tags.length != 3) {
- stdout.printf (@"ERROR PACKAGE: tags length: $(package.tags.length)");
- assert_not_reached ();
- }
- if (package.tags.index (0) != "Printer") {
- stdout.printf (@"ERROR PACKAGE: tags index 0: $(package.tags.index (0))");
- assert_not_reached ();
- }
- if (package.tags.index (1) != "Partner") {
- stdout.printf (@"ERROR PACKAGE: tags index 1: $(package.tags.index (1))");
- assert_not_reached ();
- }
- if (package.tags.index (2) != "Support") {
- stdout.printf (@"ERROR PACKAGE: tags index 0: $(package.tags.index (2))");
- assert_not_reached ();
- }
- }
- catch (GLib.Error e) {
- GLib.message (@"Error: $(e.message)");
- assert_not_reached ();
- }
- }
- );
+ () => {
+ var doc = new Document.from_string (XML_PACKAGE_FILE);
+ var package = new Package ();
+ try {
+ package.deserialize (doc);
+ if (package.tags.length != 3) {
+ stdout.printf (@"ERROR PACKAGE: tags length: $(package.tags.length)");
+ assert_not_reached ();
+ }
+ if (package.tags.index (0) != "Printer") {
+ stdout.printf (@"ERROR PACKAGE: tags index 0: $(package.tags.index (0))");
+ assert_not_reached ();
+ }
+ if (package.tags.index (1) != "Partner") {
+ stdout.printf (@"ERROR PACKAGE: tags index 1: $(package.tags.index (1))");
+ assert_not_reached ();
+ }
+ if (package.tags.index (2) != "Support") {
+ stdout.printf (@"ERROR PACKAGE: tags index 0: $(package.tags.index (2))");
+ assert_not_reached ();
+ }
+ }
+ catch (GLib.Error e) {
+ GLib.message (@"Error: $(e.message)");
+ assert_not_reached ();
+ }
+ }
+ );
Test.add_func ("/gxml/serializable/object_model/serialize_array_property",
- () => {
- var doc = new Document ();
- var package = new Package ();
- package.tags.append_val ("Computer");
- package.tags.append_val ("Customer");
- package.tags.append_val ("Sale");
- try {
- package.serialize (doc);
- //stdout.printf (@"$(doc)");
- if (doc.document_element.node_name != "package")
- assert_not_reached ();
- Element element = doc.document_element;
- bool com = false;
- bool cus = false;
- bool sal = false;
- foreach (GXml.Node n in element.child_nodes) {
- //stdout.printf (@"Found Element: $(n.node_name)");
- if (n.node_name == "tag") {
- //stdout.printf (@"Found: $(n.node_name)");
- if (((Element) n).content == "Computer")
- com = true;
- if (((Element) n).content == "Customer")
- cus = true;
- if (((Element) n).content == "Sale")
- sal = true;
- }
- }
- if (!com) {
- stdout.printf (@"ERROR PACKAGE tag Computer not found!");
- assert_not_reached ();
- }
- if (!cus) {
- stdout.printf (@"ERROR PACKAGE tag Customer not found!");
- assert_not_reached ();
- }
- if (!sal) {
- stdout.printf (@"ERROR PACKAGE tag Sale not found!");
- assert_not_reached ();
- }
- }
- catch (GLib.Error e) {
- GLib.message (@"Error: $(e.message)");
- assert_not_reached ();
- }
- }
- );
+ () => {
+ var doc = new Document ();
+ var package = new Package ();
+ package.tags.append_val ("Computer");
+ package.tags.append_val ("Customer");
+ package.tags.append_val ("Sale");
+ try {
+ package.serialize (doc);
+ //stdout.printf (@"$(doc)");
+ if (doc.document_element.node_name != "package")
+ assert_not_reached ();
+ Element element = doc.document_element;
+ bool com = false;
+ bool cus = false;
+ bool sal = false;
+ foreach (GXml.Node n in element.child_nodes) {
+ //stdout.printf (@"Found Element: $(n.node_name)");
+ if (n.node_name == "tag") {
+ //stdout.printf (@"Found: $(n.node_name)");
+ if (((Element) n).content == "Computer")
+ com = true;
+ if (((Element) n).content == "Customer")
+ cus = true;
+ if (((Element) n).content == "Sale")
+ sal = true;
+ }
+ }
+ if (!com) {
+ stdout.printf (@"ERROR PACKAGE tag Computer not found!");
+ assert_not_reached ();
+ }
+ if (!cus) {
+ stdout.printf (@"ERROR PACKAGE tag Customer not found!");
+ assert_not_reached ();
+ }
+ if (!sal) {
+ stdout.printf (@"ERROR PACKAGE tag Sale not found!");
+ assert_not_reached ();
+ }
+ }
+ catch (GLib.Error e) {
+ GLib.message (@"Error: $(e.message)");
+ assert_not_reached ();
+ }
+ }
+ );
Test.add_func ("/gxml/serializable/object_model/serialize_property_nick",
- () => {
- var doc = new Document ();
- var monitor = new Monitor ();
- try {
- monitor.resolution = "1204x720";
- monitor.ac_power = 120;
- monitor.dc_power = 125;
- monitor.serialize (doc);
- //stdout.printf (@"DOC: [$(doc)]");
- if (doc.document_element == null) {
- stdout.printf ("ERROR MONITOR: No root Element");
- assert_not_reached ();
- }
- Element element = doc.document_element;
- if (element.node_name != "monitor") {
- stdout.printf (@"ERROR MONITOR: root Element $(element.node_name)");
- assert_not_reached ();
- }
- var ac = element.get_attribute_node ("AcPower");
- if (ac == null) {
- stdout.printf (@"ERROR MONITOR: attribute AcPower not found");
- assert_not_reached ();
- }
- if (ac.node_value != "120") {
- stdout.printf (@"ERROR MONITOR: AcPower value $(ac.node_value)");
- assert_not_reached ();
- }
- var dc = element.get_attribute_node ("DcPower");
- if (dc == null) {
- stdout.printf (@"ERROR MONITOR: attribute DcPower not found");
- assert_not_reached ();
- }
- if (dc.node_value != "125") {
- stdout.printf (@"ERROR MONITOR: AcPower value $(dc.node_value)");
- assert_not_reached ();
- }
- var r = element.get_attribute_node ("resolution");
- if (r == null) {
- stdout.printf (@"ERROR MONITOR: attribute resolution not found");
- assert_not_reached ();
- }
- if (r.node_value != "1204x720") {
- stdout.printf (@"ERROR MONITOR: resolution value $(r.node_value)");
- assert_not_reached ();
- }
- }
- catch (GLib.Error e) {
- stdout.printf (@"Error: $(e.message)");
- assert_not_reached ();
- }
- }
- );
+ () => {
+ var doc = new Document ();
+ var monitor = new Monitor ();
+ try {
+ monitor.resolution = "1204x720";
+ monitor.ac_power = 120;
+ monitor.dc_power = 125;
+ monitor.serialize (doc);
+ //stdout.printf (@"DOC: [$(doc)]");
+ if (doc.document_element == null) {
+ stdout.printf ("ERROR MONITOR: No root Element");
+ assert_not_reached ();
+ }
+ Element element = doc.document_element;
+ if (element.node_name != "monitor") {
+ stdout.printf (@"ERROR MONITOR: root Element $(element.node_name)");
+ assert_not_reached ();
+ }
+ var ac = element.get_attribute_node ("AcPower");
+ if (ac == null) {
+ stdout.printf (@"ERROR MONITOR: attribute AcPower not found");
+ assert_not_reached ();
+ }
+ if (ac.node_value != "120") {
+ stdout.printf (@"ERROR MONITOR: AcPower value $(ac.node_value)");
+ assert_not_reached ();
+ }
+ var dc = element.get_attribute_node ("DcPower");
+ if (dc == null) {
+ stdout.printf (@"ERROR MONITOR: attribute DcPower not found");
+ assert_not_reached ();
+ }
+ if (dc.node_value != "125") {
+ stdout.printf (@"ERROR MONITOR: AcPower value $(dc.node_value)");
+ assert_not_reached ();
+ }
+ var r = element.get_attribute_node ("resolution");
+ if (r == null) {
+ stdout.printf (@"ERROR MONITOR: attribute resolution not found");
+ assert_not_reached ();
+ }
+ if (r.node_value != "1204x720") {
+ stdout.printf (@"ERROR MONITOR: resolution value $(r.node_value)");
+ assert_not_reached ();
+ }
+ }
+ catch (GLib.Error e) {
+ stdout.printf (@"Error: $(e.message)");
+ assert_not_reached ();
+ }
+ }
+ );
Test.add_func ("/gxml/serializable/object_model/override_transform_to_string",
- () => {
- var cpu = new Cpu ();
- cpu.ghz = (float) 3.85;
- cpu.piles.add (1);
- cpu.piles.add (2);
- cpu.piles.add (3);
- var doc = new Document ();
- try {
- cpu.serialize (doc);
- //stdout.printf (@"$doc");
- if (doc.document_element == null) {
- stdout.printf (@"ERROR CPU: no root element");
- assert_not_reached ();
- }
- if (doc.document_element.node_name != "cpu") {
- stdout.printf (@"ERROR CPU: root element $(doc.document_element.node_name)");
- assert_not_reached ();
- }
- var ghz = doc.document_element.get_attribute_node ("ghz");
- if (ghz == null) {
- stdout.printf (@"ERROR CPU: no attribute ghz");
- assert_not_reached ();
- }
- if (ghz.node_value != "3.85") {
- stdout.printf (@"ERROR CPU: ghz '$(ghz.node_value)'");
- assert_not_reached ();
- }
- var p = doc.document_element.get_attribute_node ("piles");
- if (p == null) {
- stdout.printf (@"ERROR CPU: no attribute piles");
- assert_not_reached ();
- }
- if (p.node_value != "1,2,3") {
- stdout.printf (@"ERROR CPU: piles '$(p.node_value)'");
- assert_not_reached ();
- }
- }
- catch (GLib.Error e) {
- stdout.printf (@"Error: $(e.message)");
- assert_not_reached ();
- }
- });
+ () => {
+ var cpu = new Cpu ();
+ cpu.ghz = (float) 3.85;
+ cpu.piles.add (1);
+ cpu.piles.add (2);
+ cpu.piles.add (3);
+ var doc = new Document ();
+ try {
+ cpu.serialize (doc);
+ //stdout.printf (@"$doc");
+ if (doc.document_element == null) {
+ stdout.printf (@"ERROR CPU: no root element");
+ assert_not_reached ();
+ }
+ if (doc.document_element.node_name != "cpu") {
+ stdout.printf (@"ERROR CPU: root element $(doc.document_element.node_name)");
+ assert_not_reached ();
+ }
+ var ghz = doc.document_element.get_attribute_node ("ghz");
+ if (ghz == null) {
+ stdout.printf (@"ERROR CPU: no attribute ghz");
+ assert_not_reached ();
+ }
+ if (ghz.node_value != "3.85") {
+ stdout.printf (@"ERROR CPU: ghz '$(ghz.node_value)'");
+ assert_not_reached ();
+ }
+ var p = doc.document_element.get_attribute_node ("piles");
+ if (p == null) {
+ stdout.printf (@"ERROR CPU: no attribute piles");
+ assert_not_reached ();
+ }
+ if (p.node_value != "1,2,3") {
+ stdout.printf (@"ERROR CPU: piles '$(p.node_value)'");
+ assert_not_reached ();
+ }
+ }
+ catch (GLib.Error e) {
+ stdout.printf (@"Error: $(e.message)");
+ assert_not_reached ();
+ }
+ });
Test.add_func ("/gxml/serializable/object_model/override_transform_from_string",
- () => {
- var cpu = new Cpu ();
- var doc = new Document.from_string (XML_CPU_FILE);
- try {
- cpu.deserialize (doc);
- //stdout.printf (@"$doc");
- if (cpu.ghz != (float) 3.85) {
- stdout.printf (@"ERROR CPU: ghz '$(cpu.ghz)'");
- assert_not_reached ();
- }
- if (cpu.piles.size != 3) {
- stdout.printf (@"ERROR CPU: piles size '$(cpu.piles.size)'");
- assert_not_reached ();
- }
- if (!cpu.piles.contains (1)) {
- stdout.printf (@"ERROR CPU: piles contains 1 '$(cpu.piles_to_string ())'");
- assert_not_reached ();
- }
- if (!cpu.piles.contains (2)) {
- stdout.printf (@"ERROR CPU: piles contains 2 '$(cpu.piles_to_string ())'");
- assert_not_reached ();
- }
- if (!cpu.piles.contains (3)) {
- stdout.printf (@"ERROR CPU: piles contains 3 '$(cpu.piles_to_string ())'");
- assert_not_reached ();
- }
- }
- catch (GLib.Error e) {
- stdout.printf (@"Error: $(e.message)");
- assert_not_reached ();
- }
- });
+ () => {
+ var cpu = new Cpu ();
+ var doc = new Document.from_string (XML_CPU_FILE);
+ try {
+ cpu.deserialize (doc);
+ //stdout.printf (@"$doc");
+ if (cpu.ghz != (float) 3.85) {
+ stdout.printf (@"ERROR CPU: ghz '$(cpu.ghz)'");
+ assert_not_reached ();
+ }
+ if (cpu.piles.size != 3) {
+ stdout.printf (@"ERROR CPU: piles size '$(cpu.piles.size)'");
+ assert_not_reached ();
+ }
+ if (!cpu.piles.contains (1)) {
+ stdout.printf (@"ERROR CPU: piles contains 1 '$(cpu.piles_to_string ())'");
+ assert_not_reached ();
+ }
+ if (!cpu.piles.contains (2)) {
+ stdout.printf (@"ERROR CPU: piles contains 2 '$(cpu.piles_to_string ())'");
+ assert_not_reached ();
+ }
+ if (!cpu.piles.contains (3)) {
+ stdout.printf (@"ERROR CPU: piles contains 3 '$(cpu.piles_to_string ())'");
+ assert_not_reached ();
+ }
+ }
+ catch (GLib.Error e) {
+ stdout.printf (@"Error: $(e.message)");
+ assert_not_reached ();
+ }
+ });
Test.add_func ("/gxml/serializable/object_model/override_serialize",
- () => {
- var doc = new Document ();
- var configuration = new Configuration ();
- configuration.device = "Controller";
- try {
- configuration.serialize (doc);
- //stdout.printf (@"DOC: $doc");
- if (doc.document_element == null) {
- stdout.printf ("DOC: No root element");
- assert_not_reached ();
- }
- Element element = doc.document_element;
- if (element.node_name != "Configuration") {
- stdout.printf (@"CONFIGURATION: Bad node name: $(element.node_name)");
- assert_not_reached ();
- }
- bool found = false;
- foreach (GXml.Node n in element.namespace_definitions)
- {
- if (n.node_name == "om" && n.node_value == "http://www.gnome.org/gxml/0.4")
- found = true;
- }
- if (!found) {
- stdout.printf (@"CONFIGURATION: No namespace found:");
- foreach (GXml.Node n in element.namespace_definitions) {
- stdout.printf (@"CONFIGURATION: Defined Namespace: $(n.node_name):$(n.node_value)");
- }
- assert_not_reached ();
- }
- }
- catch (GLib.Error e) {
- stdout.printf (@"Error: $(e.message)");
- assert_not_reached ();
- }
- });
+ () => {
+ var doc = new Document ();
+ var configuration = new Configuration ();
+ configuration.device = "Controller";
+ try {
+ configuration.serialize (doc);
+ //stdout.printf (@"DOC: $doc");
+ if (doc.document_element == null) {
+ stdout.printf ("DOC: No root element");
+ assert_not_reached ();
+ }
+ Element element = doc.document_element;
+ if (element.node_name != "Configuration") {
+ stdout.printf (@"CONFIGURATION: Bad node name: $(element.node_name)");
+ assert_not_reached ();
+ }
+ bool found = false;
+ foreach (GXml.Node n in element.namespace_definitions)
+ {
+ if (n.node_name == "om" && n.node_value == "http://www.gnome.org/gxml/0.4")
+ found = true;
+ }
+ if (!found) {
+ stdout.printf (@"CONFIGURATION: No namespace found:");
+ foreach (GXml.Node n in element.namespace_definitions) {
+ stdout.printf (@"CONFIGURATION: Defined Namespace:
$(n.node_name):$(n.node_value)");
+ }
+ assert_not_reached ();
+ }
+ }
+ catch (GLib.Error e) {
+ stdout.printf (@"Error: $(e.message)");
+ assert_not_reached ();
+ }
+ });
Test.add_func ("/gxml/serializable/object_model/override_deserialize",
- () => {
- var doc = new Document.from_string ("""<?xml version="1.0"?>
-<Configuration xmlns:om="http://www.gnome.org/gxml/0.4" device="Sampler"/>""");
- var configuration = new Configuration ();
- try {
- //stdout.printf (@"$doc");
- configuration.deserialize (doc);
- if (configuration.invalid == true) {
- stdout.printf ("CONFIGURATION: deserialize is INVALID\n");
- foreach (GXml.Node n in doc.document_element.namespace_definitions) {
- stdout.printf (@"CONFIGURATION: namespace: $(n.node_value)\n");
- }
- assert_not_reached ();
- }
- }
- catch (GLib.Error e) {
- stdout.printf (@"Error: $(e.message)");
- assert_not_reached ();
- }
- });
+ () => {
+ var doc = new Document.from_string ("""<?xml version="1.0"?>
+ <Configuration xmlns:om="http://www.gnome.org/gxml/0.4" device="Sampler"/>""");
+ var configuration = new Configuration ();
+ try {
+ //stdout.printf (@"$doc");
+ configuration.deserialize (doc);
+ if (configuration.invalid == true) {
+ stdout.printf ("CONFIGURATION: deserialize is INVALID\n");
+ foreach (GXml.Node n in doc.document_element.namespace_definitions) {
+ stdout.printf (@"CONFIGURATION: namespace: $(n.node_value)\n");
+ }
+ assert_not_reached ();
+ }
+ }
+ catch (GLib.Error e) {
+ stdout.printf (@"Error: $(e.message)");
+ assert_not_reached ();
+ }
+ });
Test.add_func ("/gxml/serializable/object_model/custome_node_name",
- () => {
- var doc = new Document.from_string ("""<?xml version="1.0"?><NodeName />""");
- var nodename = new NodeName ();
- try {
- nodename.deserialize (doc);
- }
- catch (GLib.Error e) {
- stdout.printf (@"Error: $(e.message)");
- assert_not_reached ();
- }
- });
+ () => {
+ var doc = new Document.from_string ("""<?xml version="1.0"?><NodeName />""");
+ var nodename = new NodeName ();
+ try {
+ nodename.deserialize (doc);
+ }
+ catch (GLib.Error e) {
+ stdout.printf (@"Error: $(e.message)");
+ assert_not_reached ();
+ }
+ });
Test.add_func ("/gxml/serializable/object_model/no_serialize_null_property",
- () => {
- var doc = new Document();
- var unknown_property = new UnknownAttribute (); // name is set to null
- try {
- unknown_property.serialize (doc);
- //stdout.printf (@"DOCUMENT: $doc"); assert_not_reached ();
- var name = doc.document_element.get_attribute_node ("name");
- if (name != null) {
- stdout.printf (@"ERROR: NULL ATTRIBUTE SERIALIZATION: name found $(name.node_name)");
- assert_not_reached ();
- }
- var array = doc.document_element.get_attribute_node ("array");
- if (array != null) {
- stdout.printf (@"ERROR: NULL ATTRIBUTE SERIALIZATION: array found $(array.node_name)");
- assert_not_reached ();
- }
- if (doc.document_element.has_child_nodes ()) {
- stdout.printf (@"ERROR: NULL ATTRIBUTE SERIALIZATION: Nodes found
$(doc.document_element.has_child_nodes ())");
- assert_not_reached ();
- }
- }
- catch (GLib.Error e) {
- stdout.printf (@"Error: $(e.message)");
- assert_not_reached ();
- }
- });
+ () => {
+ var doc = new Document();
+ var unknown_property = new UnknownAttribute (); // name is set to null
+ try {
+ unknown_property.serialize (doc);
+ //stdout.printf (@"DOCUMENT: $doc"); assert_not_reached ();
+ var name = doc.document_element.get_attribute_node ("name");
+ if (name != null) {
+ stdout.printf (@"ERROR: NULL ATTRIBUTE SERIALIZATION: name found
$(name.node_name)");
+ assert_not_reached ();
+ }
+ var array = doc.document_element.get_attribute_node ("array");
+ if (array != null) {
+ stdout.printf (@"ERROR: NULL ATTRIBUTE SERIALIZATION: array found
$(array.node_name)");
+ assert_not_reached ();
+ }
+ if (doc.document_element.has_child_nodes ()) {
+ stdout.printf (@"ERROR: NULL ATTRIBUTE SERIALIZATION: Nodes found
$(doc.document_element.has_child_nodes ())");
+ assert_not_reached ();
+ }
+ }
+ catch (GLib.Error e) {
+ stdout.printf (@"Error: $(e.message)");
+ assert_not_reached ();
+ }
+ });
Test.add_func ("/gxml/serializable/object_model/unknown_property",
- () => {
- var doc = new Document.from_string ("""<?xml version="1.0"?>
- <UnknownAttribute ignore="true" ignore2="test">
- <UnknownNode toignore = "true" />
- </UnknownAttribute>""");
- var unknown_property = new UnknownAttribute ();
- try {
- unknown_property.deserialize (doc);
- if (unknown_property.unknown_serializable_property.size () != 3) {
- stdout.printf (@"ERROR: UNKNOWN_ATTRIBUTE: size
$(unknown_property.unknown_serializable_property.size ().to_string ())\n");
- foreach (string s in unknown_property.unknown_serializable_property.get_keys ()) {
- stdout.printf (@"Saved unknown property: $(s)\n");
- }
- assert_not_reached ();
- }
- if (!unknown_property.unknown_serializable_property.contains ("ignore")) {
- stdout.printf (@"ERROR: UNKNOWN_ATTRIBUTE: ignore not found");
- assert_not_reached ();
- }
- var ignore = unknown_property.unknown_serializable_property.get ("ignore");
- if (!(ignore is Attr)) {
- stdout.printf (@"ERROR: UNKNOWN_ATTRIBUTE: ignore is not an GXml.Attr");
- assert_not_reached ();
- }
- if (!unknown_property.unknown_serializable_property.contains ("ignore2")) {
- stdout.printf (@"ERROR: UNKNOWN_ATTRIBUTE: ignore not found");
- assert_not_reached ();
- }
- var ignore2 = unknown_property.unknown_serializable_property.get ("ignore2");
- if (!(ignore2 is Attr)) {
- stdout.printf (@"ERROR: UNKNOWN_ATTRIBUTE: ignore2 is not an GXml.Attr");
- assert_not_reached ();
- }
- if (!unknown_property.unknown_serializable_property.contains ("UnknownNode")) {
- stdout.printf (@"ERROR: UNKNOWN_ATTRIBUTE: node UnknownNode not found");
- assert_not_reached ();
- }var unknown_node = unknown_property.unknown_serializable_property.get ("UnknownNode");
- if (!(unknown_node is Element)) {
- stdout.printf (@"ERROR: UNKNOWN_ATTRIBUTE: unknown node is not an GXml.Element");
- assert_not_reached ();
- }
- }
- catch (GLib.Error e) {
- stdout.printf (@"Error: $(e.message)");
- assert_not_reached ();
- }
- });
+ () => {
+ var doc = new Document.from_string ("""<?xml version="1.0"?>
+ <UnknownAttribute ignore="true" ignore2="test">
+ <UnknownNode toignore = "true" />TEXT
+ </UnknownAttribute>""");
+ var unknown_property = new UnknownAttribute ();
+ try {
+ unknown_property.deserialize (doc);
+ if (unknown_property.unknown_serializable_property.size () != 4) {
+ stdout.printf (@"ERROR: UNKNOWN_ATTRIBUTE: size
$(unknown_property.unknown_serializable_property.size ().to_string ())\n");
+ foreach (GXml.Node un in unknown_property.unknown_serializable_property.get_values
()) {
+ string sv = "__NULL__";
+ if (un.node_value != null)
+ sv = un.node_value;
+ stdout.printf (@"Saved unknown property: $(un.node_name) / '$(sv)'\n");
+ }
+ assert_not_reached ();
+ }
+ if (!unknown_property.unknown_serializable_property.contains ("ignore")) {
+ stdout.printf (@"ERROR: UNKNOWN_ATTRIBUTE: ignore not found");
+ assert_not_reached ();
+ }
+ var ignore = unknown_property.unknown_serializable_property.get ("ignore");
+ if (!(ignore is Attr)) {
+ stdout.printf (@"ERROR: UNKNOWN_ATTRIBUTE: ignore is not an GXml.Attr");
+ assert_not_reached ();
+ }
+ if (!unknown_property.unknown_serializable_property.contains ("ignore2")) {
+ stdout.printf (@"ERROR: UNKNOWN_ATTRIBUTE: ignore not found");
+ assert_not_reached ();
+ }
+ var ignore2 = unknown_property.unknown_serializable_property.get ("ignore2");
+ if (!(ignore2 is Attr)) {
+ stdout.printf (@"ERROR: UNKNOWN_ATTRIBUTE: ignore2 is not an GXml.Attr");
+ assert_not_reached ();
+ }
+ if (!unknown_property.unknown_serializable_property.contains ("UnknownNode")) {
+ stdout.printf (@"ERROR: UNKNOWN_ATTRIBUTE: node UnknownNode not found");
+ assert_not_reached ();
+ }var unknown_node = unknown_property.unknown_serializable_property.get
("UnknownNode");
+ if (!(unknown_node is Element)) {
+ stdout.printf (@"ERROR: UNKNOWN_ATTRIBUTE: unknown node is not an GXml.Element");
+ assert_not_reached ();
+ }
+ }
+ catch (GLib.Error e) {
+ stdout.printf (@"Error: $(e.message)");
+ assert_not_reached ();
+ }
+ });
Test.add_func ("/gxml/serializable/object_model/deserialize_unknown_property",
- () => {
- var doc = new Document.from_string ("""<?xml version="1.0"?>
- <UnknownAttribute ignore="true" ignore2="test">
- <UnknownNode direction = "fordward">
- SECOND FAKE TEXT
- </UnknownNode>
- FAKE TEXT
- </UnknownAttribute>""");
- var unknown_property = new UnknownAttribute ();
- try {
- unknown_property.deserialize (doc);
- var doc2 = new Document ();
- unknown_property.serialize (doc2);
- if (doc2.document_element == null) {
- stdout.printf (@"ERROR: UNKNOWN_ATTRIBUTE: SERIALIZATION: No Root Element");
- assert_not_reached ();
- }
- Element element = doc2.document_element;
- if (element.node_name.down () != "unknownattribute") {
- stdout.printf (@"ERROR: UNKNOWN_ATTRIBUTE: SERIALIZATION: Root Element Bad name
$(element.node_name.down ())");
- assert_not_reached ();
- }
- var ignore = element.get_attribute_node ("ignore");
- if (ignore == null) {
- stdout.printf (@"ERROR: UNKNOWN_ATTRIBUTE: SERIALIZATION: No attribute ignore");
- assert_not_reached ();
- }
- if (ignore.node_value != "true") {
- stdout.printf (@"ERROR: UNKNOWN_ATTRIBUTE: SERIALIZATION: Attribute ignore bad value
$(ignore.node_value)");
- assert_not_reached ();
- }
- var ignore2 = element.get_attribute_node ("ignore2");
- if (ignore2 == null) {
- stdout.printf (@"ERROR: UNKNOWN_ATTRIBUTE: SERIALIZATION: No attribute ignore");
- assert_not_reached ();
- }
- if (ignore2.node_value != "test") {
- stdout.printf (@"ERROR: UNKNOWN_ATTRIBUTE: SERIALIZATION: Attribute ignore2 bad value
$(ignore2.node_value)");
- assert_not_reached ();
- }
- if (!element.has_child_nodes ()) {
- stdout.printf (@"ERROR: UNKNOWN_ATTRIBUTE: SERIALIZATION: No child nodes");
- assert_not_reached ();
- }
- // Consider that Element content text (actually none) is considered a GXml.Node
- // Because serialize_use_xml_node_value () returns false by default 'FAKE TEXT' is LOST
- // on serialization
- if (element.child_nodes.length != 1) {
- stdout.printf (@"ERROR: UNKNOWN_ATTRIBUTE: SERIALIZATION: Too many child nodes. Expected 2, got
$(element.child_nodes.length)\n");
- assert_not_reached ();
- }
- bool found = false;
- foreach (GXml.Node n in element.child_nodes) {
- if (n.node_name == "UnknownNode") {
- found = true;
- var direction = ((Element) n).get_attribute_node ("direction");
- if (direction == null) {
- stdout.printf (@"ERROR: UNKNOWN_ATTRIBUTE: SERIALIZATION: UnknownNode No attribute direction");
- assert_not_reached ();
- }
- if (direction.node_value != "fordward") {
- stdout.printf (@"ERROR: UNKNOWN_ATTRIBUTE: SERIALIZATION: UnknownNode attribute direction bad
value $(direction.node_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 Document.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 ();
- }
- }
- catch (GLib.Error e) {
- stdout.printf (@"Error: $(e.message)");
- assert_not_reached ();
- }
- });
+ () => {
+ var doc = new Document.from_string ("""<?xml version="1.0"?>
+ <UnknownAttribute ignore="true" ignore2="test">
+ <UnknownNode direction = "fordward">
+ <UnknownChild t = "test">
+ <UnknownChildTwo t = "test">
+ SECOND FAKE TEXT
+ </UnknownChildTwo>
+ </UnknownChild>
+ </UnknownNode>
+ FAKE TEXT
+ </UnknownAttribute>""");
+ var unknown_property = new UnknownAttribute ();
+ try {
+ unknown_property.deserialize (doc);
+ var doc2 = new Document ();
+ unknown_property.serialize (doc2);
+ if (doc2.document_element == null) {
+ stdout.printf (@"ERROR: UNKNOWN_ATTRIBUTE: SERIALIZATION: No Root Element");
+ assert_not_reached ();
+ }
+ Element element = doc2.document_element;
+ if (element.node_name.down () != "unknownattribute") {
+ stdout.printf (@"ERROR: UNKNOWN_ATTRIBUTE: SERIALIZATION: Root Element Bad name
$(element.node_name.down ())");
+ assert_not_reached ();
+ }
+ var ignore = element.get_attribute_node ("ignore");
+ if (ignore == null) {
+ stdout.printf (@"ERROR: UNKNOWN_ATTRIBUTE: SERIALIZATION: No attribute ignore");
+ assert_not_reached ();
+ }
+ if (ignore.node_value != "true") {
+ stdout.printf (@"ERROR: UNKNOWN_ATTRIBUTE: SERIALIZATION: Attribute ignore bad
value $(ignore.node_value)");
+ assert_not_reached ();
+ }
+ var ignore2 = element.get_attribute_node ("ignore2");
+ if (ignore2 == null) {
+ stdout.printf (@"ERROR: UNKNOWN_ATTRIBUTE: SERIALIZATION: No attribute ignore");
+ assert_not_reached ();
+ }
+ if (ignore2.node_value != "test") {
+ stdout.printf (@"ERROR: UNKNOWN_ATTRIBUTE: SERIALIZATION: Attribute ignore2 bad
value $(ignore2.node_value)");
+ assert_not_reached ();
+ }
+ if (!element.has_child_nodes ()) {
+ stdout.printf (@"ERROR: UNKNOWN_ATTRIBUTE: SERIALIZATION: No child nodes");
+ assert_not_reached ();
+ }
+ if (element.child_nodes.length != 2) {
+ stdout.printf (@"ERROR: UNKNOWN_ATTRIBUTE: SERIALIZATION: Too many child nodes.
Expected 2, got $(element.child_nodes.length)\n");
+ assert_not_reached ();
+ }
+ bool found = false;
+ foreach (GXml.Node n in element.child_nodes) {
+ if (n.node_name == "UnknownNode") {
+ found = true;
+ var direction = ((Element) n).get_attribute_node ("direction");
+ if (direction == null) {
+ stdout.printf (@"ERROR: UNKNOWN_ATTRIBUTE: SERIALIZATION: UnknownNode No
attribute direction");
+ assert_not_reached ();
+ }
+ if (direction.node_value != "fordward") {
+ stdout.printf (@"ERROR: UNKNOWN_ATTRIBUTE: SERIALIZATION: UnknownNode attribute
direction bad value $(direction.node_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
Document.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 ();
+ }
+ }
+ catch (GLib.Error e) {
+ stdout.printf (@"Error: $(e.message)");
+ assert_not_reached ();
+ }
+ });
+ Test.add_func ("/gxml/serializable/object_model/serialize_unknown_property",
+ () => {
+ try {
+ var doc = new Document.from_string ("""<?xml version="1.0"?>
+ <UnknownAttribute ignore="true" ignore2="test">
+ <UnknownNode toignore = "true" />TEXT
+ </UnknownAttribute>""");
+ var unknown_property = new UnknownAttribute ();
+ unknown_property.deserialize (doc);
+ var ndoc = new Document ();
+ unknown_property.serialize (ndoc);
+ if (ndoc.document_element.child_nodes.size != 2) {
+ stdout.printf (@"ERROR: Root incorrect child node number: found
'$(doc.document_element.child_nodes.size)\n");
+ foreach (GXml.Node rn in ndoc.document_element.child_nodes) {
+ string nv = "__NULL__";
+ if (rn.node_value != null)
+ nv = rn.node_value;
+ stdout.printf (@"Node: $(rn.node_name) / Value: '$(nv)'\n");
+ }
+ stdout.printf (@"$(ndoc)\n");
+ assert_not_reached ();
+ }
+ foreach (GXml.Node n in ndoc.document_element.child_nodes) {
+ if (n is Text) {
+ if (n.node_value != "TEXT") {
+ stdout.printf (@"ERROR: Unknown Text Element not set: found
'$(n.node_value)\n");
+ assert_not_reached ();
+ }
+ }
+ }
+ } catch (GLib.Error e) {
+ stdout.printf (@"ERROR: $(e.message)\n");
+ assert_not_reached ();
+ }
+ });
Test.add_func ("/gxml/serializable/object_model/enumeration",
- () => {
- var e = new Options ();
- try {
- e.test = "t1";
- e.options = OptionsEnum.SelectBefore;
- string s = Enumeration.get_string (typeof (OptionsEnum), e.options);
- if (s != "OPTIONS_ENUM_SelectBefore") {
- stdout.printf (@"ERROR: Bad Enum stringification: $(s)");
- assert_not_reached ();
- }
- s = Enumeration.get_nick (typeof (OptionsEnum), e.options);
- if (s != "selectbefore") {
- stdout.printf (@"ERROR: Bad Enum nick name: $(s)");
- assert_not_reached ();
- }
- s = Enumeration.get_nick (typeof (OptionsEnum),OptionsEnum.NORMAL_OPERATION);
- if (s != "normal-operation") {
- stdout.printf (@"ERROR: Bad Enum nick name: $(s)");
- assert_not_reached ();
- }
- s = Enumeration.get_nick_camelcase (typeof (OptionsEnum),OptionsEnum.NORMAL_OPERATION);
- if (s != "NormalOperation") {
- stdout.printf (@"ERROR: Bad Enum nick name: $(s)");
- assert_not_reached ();
- }
- try {
- Enumeration.parse (typeof (OptionsEnum), "selectbefore");
- }
- catch (GLib.Error e) {
- stdout.printf (@"ERROR PARSING selectbefore: $(e.message)");
- assert_not_reached ();
- }
- try {
- Enumeration.parse (typeof (OptionsEnum), "normal-operation");
- }
- catch (GLib.Error e) {
- stdout.printf (@"ERROR PARSING normal-operation: $(e.message)");
- assert_not_reached ();
- }
- try {
- Enumeration.parse (typeof (OptionsEnum), "NormalOperation");
- }
- catch (GLib.Error e) {
- stdout.printf (@"ERROR PARSING NormalOperation: $(e.message)");
- assert_not_reached ();
- }
- var env = Enumeration.parse (typeof (OptionsEnum), "NormalOperation");
- Value v = Value (typeof (int));
- v.set_int (env.value);
- e.options = (OptionsEnum) v.get_int ();
- if (e.options != OptionsEnum.NORMAL_OPERATION) {
- stdout.printf (@"ERROR: setting NormalOperation: $(e.options)");
- assert_not_reached ();
- }
- }
- catch (GLib.Error e) {
- stdout.printf (@"Error: $(e.message)");
- assert_not_reached ();
- }
- });
+ () => {
+ var e = new Options ();
+ try {
+ e.test = "t1";
+ e.options = OptionsEnum.SelectBefore;
+ string s = Enumeration.get_string (typeof (OptionsEnum), e.options);
+ if (s != "OPTIONS_ENUM_SelectBefore") {
+ stdout.printf (@"ERROR: Bad Enum stringification: $(s)");
+ assert_not_reached ();
+ }
+ s = Enumeration.get_nick (typeof (OptionsEnum), e.options);
+ if (s != "selectbefore") {
+ stdout.printf (@"ERROR: Bad Enum nick name: $(s)");
+ assert_not_reached ();
+ }
+ s = Enumeration.get_nick (typeof (OptionsEnum),OptionsEnum.NORMAL_OPERATION);
+ if (s != "normal-operation") {
+ stdout.printf (@"ERROR: Bad Enum nick name: $(s)");
+ assert_not_reached ();
+ }
+ s = Enumeration.get_nick_camelcase (typeof
(OptionsEnum),OptionsEnum.NORMAL_OPERATION);
+ if (s != "NormalOperation") {
+ stdout.printf (@"ERROR: Bad Enum nick name: $(s)");
+ assert_not_reached ();
+ }
+ try {
+ Enumeration.parse (typeof (OptionsEnum), "selectbefore");
+ }
+ catch (GLib.Error e) {
+ stdout.printf (@"ERROR PARSING selectbefore: $(e.message)");
+ assert_not_reached ();
+ }
+ try {
+ Enumeration.parse (typeof (OptionsEnum), "normal-operation");
+ }
+ catch (GLib.Error e) {
+ stdout.printf (@"ERROR PARSING normal-operation: $(e.message)");
+ assert_not_reached ();
+ }
+ try {
+ Enumeration.parse (typeof (OptionsEnum), "NormalOperation");
+ }
+ catch (GLib.Error e) {
+ stdout.printf (@"ERROR PARSING NormalOperation: $(e.message)");
+ assert_not_reached ();
+ }
+ var env = Enumeration.parse (typeof (OptionsEnum), "NormalOperation");
+ Value v = Value (typeof (int));
+ v.set_int (env.value);
+ e.options = (OptionsEnum) v.get_int ();
+ if (e.options != OptionsEnum.NORMAL_OPERATION) {
+ stdout.printf (@"ERROR: setting NormalOperation: $(e.options)");
+ assert_not_reached ();
+ }
+ }
+ catch (GLib.Error e) {
+ stdout.printf (@"Error: $(e.message)");
+ assert_not_reached ();
+ }
+ });
Test.add_func ("/gxml/serializable/object_model/enumeration-serialize",
- () => {
- var doc = new Document ();
- var options = new Options ();
- options.options = OptionsEnum.NORMAL_OPERATION;
- try {
- options.serialize (doc);
- if (doc.document_element == null) {
- stdout.printf (@"ERROR: No root node found");
- assert_not_reached ();
- }
- if (doc.document_element.node_name != "options") {
- stdout.printf (@"ERROR: bad root name:\n$(doc)");
- assert_not_reached ();
- }
- Element element = doc.document_element;
- var op = element.get_attribute_node ("options");
- if (op == null) {
- stdout.printf (@"ERROR: attribute options not found:\n$(doc)");
- assert_not_reached ();
- }
- if (op.node_value != "NormalOperation") {
- stdout.printf (@"ERROR: attribute options value invalid: $(op.node_value)\n$(doc)");
- assert_not_reached ();
- }
- options.options = (OptionsEnum) (-1); // invaliding this property. Avoids serialize it.
- var doc2 = new Document ();
- options.serialize (doc2);
- var opts = doc2.document_element.get_attribute_node ("options");
- if (opts != null) {
- stdout.printf (@"ERROR: attribute options must not be present:\n$(doc)");
- assert_not_reached ();
- }
- }
- catch (GLib.Error e) {
- stdout.printf (@"Error: $(e.message)");
- assert_not_reached ();
- }
- });
+ () => {
+ var doc = new Document ();
+ var options = new Options ();
+ options.options = OptionsEnum.NORMAL_OPERATION;
+ try {
+ options.serialize (doc);
+ if (doc.document_element == null) {
+ stdout.printf (@"ERROR: No root node found");
+ assert_not_reached ();
+ }
+ if (doc.document_element.node_name != "options") {
+ stdout.printf (@"ERROR: bad root name:\n$(doc)");
+ assert_not_reached ();
+ }
+ Element element = doc.document_element;
+ var op = element.get_attribute_node ("options");
+ if (op == null) {
+ stdout.printf (@"ERROR: attribute options not found:\n$(doc)");
+ assert_not_reached ();
+ }
+ if (op.node_value != "NormalOperation") {
+ stdout.printf (@"ERROR: attribute options value invalid: $(op.node_value)\n$(doc)");
+ assert_not_reached ();
+ }
+ options.options = (OptionsEnum) (-1); // invaliding this property. Avoids serialize
it.
+ var doc2 = new Document ();
+ options.serialize (doc2);
+ var opts = doc2.document_element.get_attribute_node ("options");
+ if (opts != null) {
+ stdout.printf (@"ERROR: attribute options must not be present:\n$(doc)");
+ assert_not_reached ();
+ }
+ }
+ catch (GLib.Error e) {
+ stdout.printf (@"Error: $(e.message)");
+ assert_not_reached ();
+ }
+ });
Test.add_func ("/gxml/serializable/object_model/enumeration-deserialize",
- () => {
- var options = new Options ();
- try {
- var doc = new Document.from_string ("""<?xml version="1.0"?>
-<options options="NormalOperation"/>""");
- options.deserialize (doc);
- if (options.options != OptionsEnum.NORMAL_OPERATION) {
- stdout.printf (@"ERROR: Bad value to options property: $(options.options)\n$(doc)");
- assert_not_reached ();
- }
- var doc2 = new Document.from_string ("""<?xml version="1.0"?>
-<options options="normal-operation"/>""");
- options.deserialize (doc2);
- if (options.options != OptionsEnum.NORMAL_OPERATION) {
- stdout.printf (@"ERROR: Bad value to options property: $(options.options)\n$(doc2)");
- assert_not_reached ();
- }
- var doc3 = new Document.from_string ("""<?xml version="1.0"?>
-<options options="selectbefore"/>""");
- options.deserialize (doc3);
- if (options.options != OptionsEnum.SelectBefore) {
- stdout.printf (@"ERROR: Bad value to options property: $(options.options)\n$(doc3)");
- assert_not_reached ();
- }
- var doc4 = new Document.from_string ("""<?xml version="1.0"?>
-<options options="OPTIONS_ENUM_SelectBefore"/>""");
- options.deserialize (doc4);
- if (options.options != OptionsEnum.SelectBefore) {
- stdout.printf (@"ERROR: Bad value to options property: $(options.options)\n$(doc4)");
- assert_not_reached ();
- }
- var doc5 = new Document.from_string ("""<?xml version="1.0"?>
-<options options="SelectBefore"/>""");
- options.deserialize (doc5);
- if (options.options != OptionsEnum.SelectBefore) {
- stdout.printf (@"ERROR: Bad value to options property: $(options.options)\n$(doc5)");
- assert_not_reached ();
- }
- var doc6 = new Document.from_string ("""<?xml version="1.0"?>
-<options options="SELECTBEFORE"/>""");
- options.deserialize (doc6);
- if (options.options != OptionsEnum.SelectBefore) {
- stdout.printf (@"ERROR: Bad value to options property: $(options.options)\n$(doc6)");
- assert_not_reached ();
- }
- var doc7 = new Document.from_string ("""<?xml version="1.0"?>
-<options options="NORMAL_OPERATION"/>""");
- options.deserialize (doc7);
- if (options.options != OptionsEnum.SelectBefore) {
- stdout.printf (@"ERROR: Bad value to options property: $(options.options)\n$(doc7)");
- assert_not_reached ();
- }
- var op2 = new Options ();
- var doc8 = new Document.from_string ("""<?xml version="1.0"?>
-<options options="INVALID"/>""");
- op2.deserialize (doc8);
- if (op2.options != OptionsEnum.SelectBefore) {
- stdout.printf (@"ERROR: Bad value to options property: $(op2.options)\n$(doc8)");
- assert_not_reached ();
- }
- }
- catch (GLib.Error e) {
- stdout.printf (@"Error: $(e.message)");
- assert_not_reached ();
- }
- });
+ () => {
+ var options = new Options ();
+ try {
+ var doc = new Document.from_string ("""<?xml version="1.0"?>
+ <options options="NormalOperation"/>""");
+ options.deserialize (doc);
+ if (options.options != OptionsEnum.NORMAL_OPERATION) {
+ stdout.printf (@"ERROR: Bad value to options property: $(options.options)\n$(doc)");
+ assert_not_reached ();
+ }
+ var doc2 = new Document.from_string ("""<?xml version="1.0"?>
+ <options options="normal-operation"/>""");
+ options.deserialize (doc2);
+ if (options.options != OptionsEnum.NORMAL_OPERATION) {
+ stdout.printf (@"ERROR: Bad value to options property:
$(options.options)\n$(doc2)");
+ assert_not_reached ();
+ }
+ var doc3 = new Document.from_string ("""<?xml version="1.0"?>
+ <options options="selectbefore"/>""");
+ options.deserialize (doc3);
+ if (options.options != OptionsEnum.SelectBefore) {
+ stdout.printf (@"ERROR: Bad value to options property:
$(options.options)\n$(doc3)");
+ assert_not_reached ();
+ }
+ var doc4 = new Document.from_string ("""<?xml version="1.0"?>
+ <options options="OPTIONS_ENUM_SelectBefore"/>""");
+ options.deserialize (doc4);
+ if (options.options != OptionsEnum.SelectBefore) {
+ stdout.printf (@"ERROR: Bad value to options property:
$(options.options)\n$(doc4)");
+ assert_not_reached ();
+ }
+ var doc5 = new Document.from_string ("""<?xml version="1.0"?>
+ <options options="SelectBefore"/>""");
+ options.deserialize (doc5);
+ if (options.options != OptionsEnum.SelectBefore) {
+ stdout.printf (@"ERROR: Bad value to options property:
$(options.options)\n$(doc5)");
+ assert_not_reached ();
+ }
+ var doc6 = new Document.from_string ("""<?xml version="1.0"?>
+ <options options="SELECTBEFORE"/>""");
+ options.deserialize (doc6);
+ if (options.options != OptionsEnum.SelectBefore) {
+ stdout.printf (@"ERROR: Bad value to options property:
$(options.options)\n$(doc6)");
+ assert_not_reached ();
+ }
+ var doc7 = new Document.from_string ("""<?xml version="1.0"?>
+ <options options="NORMAL_OPERATION"/>""");
+ options.deserialize (doc7);
+ if (options.options != OptionsEnum.SelectBefore) {
+ stdout.printf (@"ERROR: Bad value to options property:
$(options.options)\n$(doc7)");
+ assert_not_reached ();
+ }
+ var op2 = new Options ();
+ var doc8 = new Document.from_string ("""<?xml version="1.0"?>
+ <options options="INVALID"/>""");
+ op2.deserialize (doc8);
+ if (op2.options != OptionsEnum.SelectBefore) {
+ stdout.printf (@"ERROR: Bad value to options property: $(op2.options)\n$(doc8)");
+ assert_not_reached ();
+ }
+ }
+ catch (GLib.Error e) {
+ stdout.printf (@"Error: $(e.message)");
+ assert_not_reached ();
+ }
+ });
}
static void serialize_manual_check (Element element, Manual manual)
{
@@ -1085,4 +1120,4 @@ class SerializableObjectModelTest : GXmlTest
assert_not_reached ();
}
}
-}
+}
\ No newline at end of file
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]