[gxml/serialization] Fixed deserealize booleans. Added Test case.
- From: Daniel Espinosa Ortiz <despinosa src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gxml/serialization] Fixed deserealize booleans. Added Test case.
- Date: Fri, 29 Nov 2013 03:29:46 +0000 (UTC)
commit 782bb6909f42defcd3998a4c3faea5d875cd29d6
Author: Daniel Espinosa <esodan gmail com>
Date: Thu Nov 28 21:28:20 2013 -0600
Fixed deserealize booleans. Added Test case.
gxml/Serializable.vala | 6 +--
test/GXmlTest.vala | 1 +
test/Makefile.am | 1 +
test/SerializableBasicTypesTest.vala | 77 ++++++++++++++++++++++++++++++++++
4 files changed, 80 insertions(+), 5 deletions(-)
---
diff --git a/gxml/Serializable.vala b/gxml/Serializable.vala
index 9276408..80d7e27 100644
--- a/gxml/Serializable.vala
+++ b/gxml/Serializable.vala
@@ -484,13 +484,9 @@ namespace GXml {
if (ret = uint64.try_parse (str, out val)) {
dest2.set_ulong ((ulong)val);
}
- } else if ((int)t == 20) { // gboolean
- bool val = (str == "TRUE");
- dest2.set_boolean (val); // TODO: huh, investigate why the type is gboolean and not bool coming out
but is going in
- ret = true;
} else if (t == typeof (bool)) {
bool val;
- if (ret = bool.try_parse (str, out val)) {
+ if (ret = bool.try_parse (str.down (), out val)) {
dest2.set_boolean (val);
}
} else if (t == typeof (float)) {
diff --git a/test/GXmlTest.vala b/test/GXmlTest.vala
index 638def0..0db3afe 100644
--- a/test/GXmlTest.vala
+++ b/test/GXmlTest.vala
@@ -42,6 +42,7 @@ class GXmlTest {
SerializableGeeDualKeyMapTest.add_tests ();
SerializableGeeArrayListTest.add_tests ();
SerializableGeeCollectionsTest.add_tests ();
+ SerializableBasicTypeTest.add_tests ();
Test.run ();
diff --git a/test/Makefile.am b/test/Makefile.am
index c1254ba..35cc5f3 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -42,6 +42,7 @@ gxml_test_SOURCES = \
SerializableGeeDualKeyMapTest.vala \
SerializableGeeArrayListTest.vala \
SerializableGeeCollectionsTest.vala \
+ SerializableBasicTypesTest.vala \
$(NULL)
gxml_test.vala.stamp: $(gxml_test_SOURCES)
diff --git a/test/SerializableBasicTypesTest.vala b/test/SerializableBasicTypesTest.vala
new file mode 100644
index 0000000..9a28418
--- /dev/null
+++ b/test/SerializableBasicTypesTest.vala
@@ -0,0 +1,77 @@
+/* -*- Mode: vala; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
+/**
+ *
+ * GXml.Serializable.BasicTypeTest
+ *
+ * Authors:
+ *
+ * Daniel Espinosa <esodan gmail com>
+ *
+ *
+ * Copyright (c) 2013 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;
+class SerializableBasicTypeTest : GXmlTest {
+ public class BasicType : SerializableObjectModel
+ {
+ public bool boolean { get; set; }
+ public override string node_name () { return "basictype"; }
+ public override string to_string () { return get_type ().name (); }
+ }
+ public static void add_tests () {
+ Test.add_func ("/gxml/serializable/basic_types/boolean",
+ () => {
+ try {
+ var bt = new BasicType ();
+ bt.boolean = true;
+ var doc = new Document ();
+ bt.serialize (doc);
+ var element = doc.document_element;
+ var b = element.get_attribute_node ("boolean");
+ if (b == null) {
+ stdout.printf (@"ERROR: No boolean exists\n");
+ assert_not_reached ();
+ }
+ if (b.node_value.down () != "true") {
+ stdout.printf (@"ERROR: Wrong boolean value. Expected true got: $(b.node_value.down ()) :
$(b.node_value)\n");
+ assert_not_reached ();
+ }
+ stdout.printf (@"\n$doc\n");
+ } catch (GLib.Error e) {
+ stdout.printf (@"ERROR: $(e.message)");
+ assert_not_reached ();
+ }
+ });
+ Test.add_func ("/gxml/serializable/basic_types/boolean",
+ () => {
+ try {
+ var bt = new BasicType ();
+ bt.boolean = true;
+ var doc = new Document.from_string ("""<?xml version="1.0"?>
+<basictype boolean="true"/>""");
+ bt.deserialize (doc);
+ if (bt.boolean != true) {
+ stdout.printf (@"ERROR: Wrong boolean value. Expected true got: $(bt.boolean)\n$doc\n");
+ assert_not_reached ();
+ }
+ stdout.printf (@"\n$doc\n");
+ } catch (GLib.Error e) {
+ stdout.printf (@"ERROR: $(e.message)");
+ assert_not_reached ();
+ }
+ });
+ }
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]