[gxml/serialization] Moved Enumeration Tests to a file
- From: Daniel Espinosa Ortiz <despinosa src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gxml/serialization] Moved Enumeration Tests to a file
- Date: Wed, 29 Jan 2014 23:13:53 +0000 (UTC)
commit 30bad85e357a3e039fd2e844e7e5c9a718aa0e75
Author: Daniel Espinosa <esodan gmail com>
Date: Wed Jan 29 17:13:12 2014 -0600
Moved Enumeration Tests to a file
gxml/Enumeration.vala | 7 +-
gxml/Serializable.vala | 62 ++---------
gxml/SerializableJson.vala | 28 +++++
test/Makefile.am | 1 +
test/SerializableObjectModelTest.vala | 185 +--------------------------------
5 files changed, 49 insertions(+), 234 deletions(-)
---
diff --git a/gxml/Enumeration.vala b/gxml/Enumeration.vala
index 6c292f8..b86f957 100644
--- a/gxml/Enumeration.vala
+++ b/gxml/Enumeration.vala
@@ -1,4 +1,4 @@
-/* -*- Mode: vala; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
+/* -*- Mode: vala; indent-tabs-mode: t; c-basic-offset: 2; tab-width: 2 -*- */
/* Serializable.vala
*
+ Copyright (C) 2013 Daniel Espinosa <esodan gmail com>
@@ -131,6 +131,11 @@ namespace GXml {
EnumClass enumc = (EnumClass) enumeration.class_ref ();
return enumc.values;
}
+ /**
+ * Converts a string to a value in a { link GLib.EnumValue}
+ *
+ * Returns: a value in a { link GLib.EnumValue
+ */
}
public errordomain EnumerationError
{
diff --git a/gxml/Serializable.vala b/gxml/Serializable.vala
index 7ccaf91..2de41d8 100644
--- a/gxml/Serializable.vala
+++ b/gxml/Serializable.vala
@@ -13,7 +13,7 @@
* 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/>.
*
@@ -21,57 +21,15 @@
* Richard Schwarting <aquarichy gmail com>
* Daniel Espinosa <esodan gmail com>
*/
-
-
-/*
- Version 3: json-glib version
-
- PLAN:
- * add support for GObject Introspection to allow us to serialise non-property members
-
- json-glib
- * has functions to convert XML structures into Objects and vice versa
- * can convert simple objects automatically
- * richer objects need to implement interface
-
- json_serializable_real_serialize -> json_serialize_pspec
- * how do these get used with GInterfaces? are these default methods like with superclasses?
- * TODO: I don't think vala does multiple inheritance, so do we want GXml.Serializable to be an interface
or a superclass?
-
- json_serializable_default_{de,}serialize_property -> json_serializable_real_{de,}serialize
-
- json_serializable_{de,}serialize_property -> iface->{de,}serialize_property
- these all get init'd to -> json_serializable_real_{de,}serialize_property
- these all call -> json_{de,}serialize_pspec
-
- json_serializable_{find,list,get,set}_propert{y,ies} -> iface->{find,list,get,set}_propert{y,ies}
- these all get init'd to -> json_serializable_real_{find,list,get,set}_propert{y,ies}
- these all call -> g_object_{class,}_{find,list,get,set}_propert{y,ies}
- */
-
-using GXml;
-
namespace GXml {
/**
* Interface allowing implementors direct control over serialisation of properties and other data
- *
- * A class that implements this interface will still be passed
- * to { link GXml.Serialization.serialize_object} for
- * serialization. That function will check whether the object
- * implements { link GXml.Serializable} and will then prefer
- * overridden methods instead of standard ones. Most of the
- * methods for this interface can indicate (via return value)
- * that, for a given property, the standard serialization
- * approach should be used instead. Indeed, not all methods
- * need to be implemented, but some accompany one another and
- * should be implemented carefully, corresponding to one
- * another. You can also create virtual properties from
- * non-public property fields to enable their serialization.
- *
- * For an example, look in tests/XmlSerializableTest
*/
public interface Serializable : GLib.Object {
- protected abstract ParamSpec[] properties { get; set; }
+ /**
+ * Convenient property to store serializable properties
+ */
+ protected abstract ParamSpec[] properties { get; set; }
/**
* Store all properties to be ignored on serialization.
*
@@ -90,9 +48,13 @@ namespace GXml {
* call { link init_properties()} before add new propeties.
*/
public abstract HashTable<string,GLib.ParamSpec> ignored_serializable_properties { get; protected set; }
- /**
- *
- */
+ /**
+ * Return { link false} if you want ignore unknown properties and { link GXml.Node}'s
+ * not in your class definition.
+ *
+ * Take care, disabling this feature you can lost data on serialization, because any unknown
+ * property or element will be ignored.
+ */
public abstract bool get_enable_unknown_serializable_property ();
/**
* On deserialization stores any { link GXml.Node} not used on this
diff --git a/gxml/SerializableJson.vala b/gxml/SerializableJson.vala
index 095049a..376776a 100644
--- a/gxml/SerializableJson.vala
+++ b/gxml/SerializableJson.vala
@@ -22,6 +22,34 @@
* Daniel Espinosa <esodan gmail com>
*/
+
+/*
+ Version 3: json-glib version
+
+ PLAN:
+ * add support for GObject Introspection to allow us to serialise non-property members
+
+ json-glib
+ * has functions to convert XML structures into Objects and vice versa
+ * can convert simple objects automatically
+ * richer objects need to implement interface
+
+ json_serializable_real_serialize -> json_serialize_pspec
+ * how do these get used with GInterfaces? are these default methods like with superclasses?
+ * TODO: I don't think vala does multiple inheritance, so do we want GXml.Serializable to be an interface
or a superclass?
+
+ json_serializable_default_{de,}serialize_property -> json_serializable_real_{de,}serialize
+
+ json_serializable_{de,}serialize_property -> iface->{de,}serialize_property
+ these all get init'd to -> json_serializable_real_{de,}serialize_property
+ these all call -> json_{de,}serialize_pspec
+
+ json_serializable_{find,list,get,set}_propert{y,ies} -> iface->{find,list,get,set}_propert{y,ies}
+ these all get init'd to -> json_serializable_real_{find,list,get,set}_propert{y,ies}
+ these all call -> g_object_{class,}_{find,list,get,set}_propert{y,ies}
+ */
+
+
/**
* Serializes and deserializes { link GLib.Object}s to and from
* { link GXml.Node}.
diff --git a/test/Makefile.am b/test/Makefile.am
index b1bf663..5ce9369 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -35,6 +35,7 @@ gxml_test_SOURCES = \
NodeListTest.vala \
TextTest.vala \
ValaLibxml2Test.vala \
+ EnumerationTest.vala \
SerializableTest.vala \
SerializationTest.vala \
SerializableObjectModelTest.vala \
diff --git a/test/SerializableObjectModelTest.vala b/test/SerializableObjectModelTest.vala
index 9e3910f..3325464 100644
--- a/test/SerializableObjectModelTest.vala
+++ b/test/SerializableObjectModelTest.vala
@@ -1,14 +1,14 @@
/* -*- Mode: vala; indent-tabs-mode: nil; c-basic-offset: 2; tab-width: 2 -*- */
/**
*
- * GXml.Serializable.GeeCollectionsTest
+ * GXml.EnumerationTest.vala
*
* Authors:
*
* Daniel Espinosa <esodan gmail com>
*
*
- * Copyright (c) 2013-2014 Daniel Espinosa
+ * Copyright (c) 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
@@ -272,20 +272,6 @@ class UnknownAttribute : ObjectModel
public override bool get_enable_unknown_serializable_property () { return true; }
}
-public enum OptionsEnum
-{
- [Description (nick="SelectionOption")]
- SelectBefore,
- HoldOn,
- LeaveHeare,
- NORMAL_OPERATION
-}
-
-class Options : ObjectModel
-{
- public string test { get; set; }
- public OptionsEnum options { get; set; }
-}
class SerializableObjectModelTest : GXmlTest
{
public static void add_tests ()
@@ -958,173 +944,6 @@ class SerializableObjectModelTest : GXmlTest
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 ();
- }
- });
- 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 ();
- }
- });
- 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 ();
- }
- });
}
static void serialize_manual_check (Element element, Manual manual)
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]