[gxml] Added unit test for SerializableEnum
- From: Daniel Espinosa Ortiz <despinosa src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gxml] Added unit test for SerializableEnum
- Date: Tue, 29 Sep 2015 23:58:26 +0000 (UTC)
commit f9fcc521b09b78abecfe9212f5537fda8ac8c7c2
Author: Daniel Espinosa <esodan gmail com>
Date: Tue Sep 29 16:59:22 2015 -0500
Added unit test for SerializableEnum
test/GXmlTest.vala | 1 +
test/Makefile.am | 1 +
test/SerializablePropertyEnumTest.vala | 110 ++++++++++++++++++++++++++++++++
3 files changed, 112 insertions(+), 0 deletions(-)
---
diff --git a/test/GXmlTest.vala b/test/GXmlTest.vala
index 575ea01..1cd9eea 100644
--- a/test/GXmlTest.vala
+++ b/test/GXmlTest.vala
@@ -78,6 +78,7 @@ class GXmlTest {
TwProcessingInstructionTest.add_tests ();
SerializablePropertyBoolTest.add_tests ();
SerializablePropertyValueListTest.add_tests ();
+ SerializablePropertyEnumTest.add_tests ();
Test.run ();
diff --git a/test/Makefile.am b/test/Makefile.am
index 5082514..2dc061f 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -39,6 +39,7 @@ sources = \
EnumerationTest.vala \
SerializableTest.vala \
SerializablePropertyBoolTest.vala \
+ SerializablePropertyEnumTest.vala \
SerializablePropertyValueListTest.vala \
SerializationTest.vala \
SerializableObjectModelTest.vala \
diff --git a/test/SerializablePropertyEnumTest.vala b/test/SerializablePropertyEnumTest.vala
new file mode 100644
index 0000000..4fe4df1
--- /dev/null
+++ b/test/SerializablePropertyEnumTest.vala
@@ -0,0 +1,110 @@
+/* -*- Mode: vala; indent-tabs-mode: nil; tab-width: 2 -*- */
+/**
+ *
+ * SerializablePropertyEnumTest.vala
+ *
+ * Authors:
+ *
+ * Daniel Espinosa <esodan gmail com>
+ *
+ *
+ * Copyright (c) 2015 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 SerializablePropertyEnumTest : GXmlTest {
+ public class Enum : SerializableObjectModel
+ {
+ public SerializableEnum values { get; set; }
+ public int integer { get; set; default = 0; }
+ public string name { get; set; }
+ public override string node_name () { return "Enum"; }
+ public override string to_string () { return get_type ().name (); }
+ }
+ public static void add_tests () {
+ Test.add_func ("/gxml/serializable/Enum/basic",
+ () => {
+ try {
+ var e = new Enum ();
+ var doc = new xDocument ();
+ e.serialize (doc);
+ Test.message ("XML:\n"+doc.to_string ());
+ var element = doc.document_element;
+ var ee1 = element.get_attribute_node ("enumvalue");
+ assert (ee1 == null);
+ var s = element.get_attribute_node ("name");
+ assert (s == null);
+ var i = element.get_attribute_node ("integer");
+ assert (i.value == "0");
+ } catch (GLib.Error e) {
+ Test.message (@"ERROR: $(e.message)");
+ assert_not_reached ();
+ }
+ });/*
+ Test.add_func ("/gxml/serializable/ValueList/changes",
+ () => {
+ try {
+ var vl = new ValueList ();
+ vl.values = new SerializableValueList.with_name ("option");
+ var doc1 = new xDocument ();
+ vl.serialize (doc1);
+ Test.message ("XML1:\n"+doc1.to_string ());
+ var element1 = doc1.document_element;
+ var evl1 = element1.get_attribute_node ("option");
+ assert (evl1 == null);
+ var s1 = element1.get_attribute_node ("name");
+ assert (s1 == null);
+ var i1 = element1.get_attribute_node ("integer");
+ assert (i1.value == "0");
+ // Adding values
+ var v = vl.values.get_value_at (0);
+ assert (v == null);
+ vl.values.add_values ({"Temp1","Temp2"});
+ v = vl.values.get_value_at (0);
+ assert (v == "Temp1");
+ v = vl.values.get_value_at (1);
+ assert (v == "Temp2");
+ var doc2 = new xDocument ();
+ vl.serialize (doc2);
+ Test.message ("XML2:\n"+doc2.to_string ());
+ var element2 = doc2.document_element;
+ var evl2 = element2.get_attribute_node ("option");
+ assert (evl2 == null);
+ // Select a value
+ vl.values.select_value_at (1);
+ v = vl.values.get_serializable_property_value ();
+ assert (v == "Temp2");
+ var doc3 = new xDocument ();
+ vl.serialize (doc3);
+ Test.message ("XML3:\n"+doc3.to_string ());
+ var element3 = doc3.document_element;
+ var evl3 = element3.get_attribute_node ("option");
+ assert (evl3 != null);
+ assert (evl3.value == "Temp2");
+ // Set value to null/ignore
+ vl.values.set_serializable_property_value (null);
+ var doc4 = new xDocument ();
+ vl.serialize (doc4);
+ Test.message ("XML4:\n"+doc4.to_string ());
+ var element4 = doc4.document_element;
+ var evl4 = element4.get_attribute_node ("option");
+ assert (evl4 == null);
+ } 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]