[gxml] SerializableProperty and SerializableValueList fixes
- From: Daniel Espinosa Ortiz <despinosa src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gxml] SerializableProperty and SerializableValueList fixes
- Date: Sun, 25 Oct 2015 01:28:04 +0000 (UTC)
commit 6893f7a84970f980336606354534ef354403e2d9
Author: Daniel Espinosa <esodan gmail com>
Date: Fri Oct 23 10:09:58 2015 -0500
SerializableProperty and SerializableValueList fixes
* SerializableProperty Added checks to serialize only on GXml.Element
* Added unit tests for SerializableValueList
configure.ac | 2 +-
gxml/SerializableProperty.vala | 4 ++
test/SerializablePropertyValueListTest.vala | 68 ++++++++++++++++++++++++++-
3 files changed, 72 insertions(+), 2 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 8407a92..46a6349 100644
--- a/configure.ac
+++ b/configure.ac
@@ -12,7 +12,7 @@
# Release Version
m4_define([project_major_version], [0])
m4_define([project_minor_version], [7])
-m4_define([project_micro_version], [3])
+m4_define([project_micro_version], [4])
m4_define([project_nano_version], [0])
# LT_VERSION
diff --git a/gxml/SerializableProperty.vala b/gxml/SerializableProperty.vala
index 865abff..6c94f58 100644
--- a/gxml/SerializableProperty.vala
+++ b/gxml/SerializableProperty.vala
@@ -98,6 +98,10 @@ public interface GXml.SerializableProperty : Object, Serializable
else
name = prop.get_name ();
Test.message ("Property to set:"+name+" - with value: "+get_serializable_property_value ());
+ if (!(element is GXml.Element)) {
+ GLib.warning ("Trying to serialize to a non GXmlElement!");
+ return element;
+ }
((GXml.Element) element).set_attr (name, get_serializable_property_value ());
return element;
}
diff --git a/test/SerializablePropertyValueListTest.vala b/test/SerializablePropertyValueListTest.vala
index df7f939..a0b0472 100644
--- a/test/SerializablePropertyValueListTest.vala
+++ b/test/SerializablePropertyValueListTest.vala
@@ -25,9 +25,26 @@
*/
using GXml;
class SerializablePropertyValueListTest : GXmlTest {
+ public class Values : SerializableValueList
+ {
+ construct {
+ _vals = {"Val1","Val2"};
+ }
+ public void select (Enum v)
+ {
+ select_value_at ((int) v);
+ }
+ public string get_string () { return get_serializable_property_value (); }
+ public void set_string (string str) { set_serializable_property_value (str); }
+ public enum Enum
+ {
+ VAL1, VAL2
+ }
+ }
public class ValueList : SerializableObjectModel
{
public SerializableValueList values { get; set; }
+ public Values vals { get; set; }
public int integer { get; set; default = 0; }
public string name { get; set; }
public override string node_name () { return "ValueList"; }
@@ -42,8 +59,10 @@ class SerializablePropertyValueListTest : GXmlTest {
vl.serialize (doc);
Test.message ("XML:\n"+doc.to_string ());
var element = doc.document_element;
- var evl1 = element.get_attribute_node ("boolean");
+ var evl1 = element.get_attribute_node ("values");
assert (evl1 == null);
+ var evl2 = element.get_attribute_node ("vals");
+ assert (evl2 == null);
var s = element.get_attribute_node ("name");
assert (s == null);
var i = element.get_attribute_node ("integer");
@@ -178,5 +197,52 @@ class SerializablePropertyValueListTest : GXmlTest {
assert_not_reached ();
}
});
+ Test.add_func ("/gxml/serializable/ValueList/fixed/basic",
+ () => {
+ var v = new ValueList ();
+ v.vals = new Values ();
+ assert (v.vals != null);
+ assert (v.vals.get_value_at (0) == "Val1");
+ assert (v.vals.get_value_at (1) == "Val2");
+ assert (v.vals.get_serializable_property_value () == null);
+ v.vals.select_value_at (0);
+ assert (v.vals.get_serializable_property_value () == "Val1");
+ v.vals.select_value_at (1);
+ assert (v.vals.get_serializable_property_value () == "Val2");
+ v.vals.select_value_at (Values.Enum.VAL1);
+ assert (v.vals.get_serializable_property_value () == "Val1");
+ v.vals.select_value_at (Values.Enum.VAL2);
+ assert (v.vals.get_serializable_property_value () == "Val2");
+ v.vals.select (Values.Enum.VAL1);
+ assert (v.vals.get_string () == "Val1");
+ assert (v.vals.get_string () == "Val1");
+ assert (v.vals.is_value ());
+ v.vals.set_string ("K1");
+ assert (v.vals.get_string () == "K1");
+ assert (!v.vals.is_value ());
+ });
+ Test.add_func ("/gxml/serializable/ValueList/fixed/serialize",
+ () => {
+ try {
+ var vl = new ValueList ();
+ vl.vals = new Values ();
+ vl.vals.select_value_at (Values.Enum.VAL1);
+ var doc = new xDocument ();
+ vl.serialize (doc);
+ Test.message ("XML:\n"+doc.to_string ());
+ var element = doc.document_element;
+ var s = element.get_attribute_node ("name");
+ assert (s == null);
+ var i = element.attrs.get ("integer");
+ assert (i.value == "0");
+ var evl1 = element.attrs.get ("vals");
+ assert (evl1 != null);
+ assert (evl1.value != null);
+ assert (evl1.value == "Val1");
+ } catch (GLib.Error e) {
+ Test.message (@"ERROR: $(e.message)");
+ assert_not_reached ();
+ }
+ });
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]