[gxml/serialization] Added unit test for override Serializable.transform_to_string()
- From: Daniel Espinosa Ortiz <despinosa src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gxml/serialization] Added unit test for override Serializable.transform_to_string()
- Date: Tue, 29 Oct 2013 05:10:06 +0000 (UTC)
commit 962bb342947141fe442871e60ea777ca5d1129ef
Author: Daniel Espinosa <esodan gmail com>
Date: Mon Oct 28 23:08:46 2013 -0600
Added unit test for override Serializable.transform_to_string()
test/SerializableObjectModelTest.vala | 46 +++++++++++++++++++++++++++++++++
1 files changed, 46 insertions(+), 0 deletions(-)
---
diff --git a/test/SerializableObjectModelTest.vala b/test/SerializableObjectModelTest.vala
index b2cffb9..5c48aed 100644
--- a/test/SerializableObjectModelTest.vala
+++ b/test/SerializableObjectModelTest.vala
@@ -165,6 +165,20 @@ public class Monitor : ObjectModel
}
+public class Cpu : ObjectModel
+{
+ public float ghz { get; set; default = (float) 0.0; }
+ public override bool transform_to_string (GLib.Value val, ref string str)
+ {
+ if (val.type ().is_a (typeof (float))) {
+ str = "%.2f".printf (val.get_float ());
+ return true;
+ }
+ return false;
+ }
+}
+
+
class SerializableObjectModelTest : GXmlTest
{
public static void add_tests ()
@@ -495,6 +509,38 @@ class SerializableObjectModelTest : GXmlTest
}
}
);
+ Test.add_func ("/gxml/serializable/object_model/override_transform_to_string",
+ () => {
+ var cpu = new Cpu ();
+ cpu.ghz = (float) 3.85;
+ var doc = new Document ();
+ cpu.serialize (doc);
+ stdout.printf (@"DOC: $doc");
+ try {
+ cpu.serialize (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 ();
+ }
+ }
+ catch (GLib.Error e) {
+ stdout.printf (@"Error: $(e.message)");
+ assert_not_reached ();
+ }
+ });
}
static void serialize_manual_check (Element element, Manual manual)
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]