[gxml] * add XmlSerializableTest to test new XmlSerializable
- From: Richard Hans Schwarting <rschwart src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gxml] * add XmlSerializableTest to test new XmlSerializable
- Date: Mon, 18 Jun 2012 18:21:14 +0000 (UTC)
commit 58d685e6906dde407d75208bc4c640cd6d833f2c
Author: Richard Schwarting <aquarichy gmail com>
Date: Mon Jun 18 14:19:38 2012 -0400
* add XmlSerializableTest to test new XmlSerializable
test/GXmlTest.vala | 1 +
test/XmlSerializableTest.vala | 35 +++++++++++++++++++++++++++++++++++
2 files changed, 36 insertions(+), 0 deletions(-)
---
diff --git a/test/GXmlTest.vala b/test/GXmlTest.vala
index 44c450e..1f4dbcf 100644
--- a/test/GXmlTest.vala
+++ b/test/GXmlTest.vala
@@ -12,6 +12,7 @@ class GXmlTest {
TextTest.add_tests ();
CharacterDataTest.add_tests ();
ValaLibxml2Test.add_tests ();
+ XmlSerializableTest.add_tests ();
Test.run ();
return 1;
diff --git a/test/XmlSerializableTest.vala b/test/XmlSerializableTest.vala
new file mode 100644
index 0000000..df4f0d7
--- /dev/null
+++ b/test/XmlSerializableTest.vala
@@ -0,0 +1,35 @@
+/* -*- Mode: vala; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
+using GXmlDom;
+
+// TODO: if I don't subclass GLib.Object, a Vala class's object can't be serialised?
+public class Fruit : GLib.Object {
+ string colour;
+ int weight;
+ public string name;
+ public int age {
+ get { return weight; }
+ set { weight = value; }
+ }
+ public string to_string () {
+ return "Fruit: colour[%s] weight[%d] name[%s] age[%d]".printf(this.colour, this.weight, this.name, this.age);
+ }
+}
+
+class XmlSerializableTest : GXmlTest {
+ public static void add_tests () {
+ Test.add_func ("/gxml/domnode/xml_serializable", () => {
+ Fruit fruit = new Fruit ();
+ fruit.name = "fish";
+ fruit.age = 3;
+ // fruit.colour = "blue";
+ Serializer ser = new Serializer ();
+ ser.serialize_object (fruit);
+ });
+ Test.add_func ("/gxml/domnode/xml_deserializable", () => {
+ Document doc = new Document.from_string ("<Object otype=\"Fruit\"><Property pname=\"age\" ptype=\"gint\">3</Property></Object>");
+ Serializer ser = new Serializer ();
+ Fruit fruit = (Fruit)ser.deserialize_object (doc.document_element);
+ stdout.printf ("%s\n", fruit.to_string ());
+ });
+ }
+}
\ No newline at end of file
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]