[gxml] Added unit tests for SerializableValueList
- From: Daniel Espinosa Ortiz <despinosa src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gxml] Added unit tests for SerializableValueList
- Date: Tue, 29 Sep 2015 21:36:31 +0000 (UTC)
commit 57929fbd8a9b51d612e72978cf53bcc4686e37d0
Author: Daniel Espinosa <esodan gmail com>
Date: Sat Sep 26 19:26:32 2015 -0700
Added unit tests for SerializableValueList
gxml/SerializableValueList.vala | 14 +++-
test/GXmlTest.vala | 1 +
test/Makefile.am | 1 +
test/SerializablePropertyBoolTest.vala | 2 +-
test/SerializablePropertyValueListTest.vala | 110 +++++++++++++++++++++++++++
5 files changed, 123 insertions(+), 5 deletions(-)
---
diff --git a/gxml/SerializableValueList.vala b/gxml/SerializableValueList.vala
index 966ddf3..e052d97 100644
--- a/gxml/SerializableValueList.vala
+++ b/gxml/SerializableValueList.vala
@@ -36,17 +36,23 @@ public class GXml.SerializableValueList : SerializableObjectModel, SerializableP
private string _name = null;
private ArrayList<string> _values = null;
public SerializableValueList.with_name (string name) { _name = name; }
- public void add_value (string val)
+ public void add_values (string[] vals)
{
if (_values == null) _values = new ArrayList<string> ();
- _values.add (val);
+ for (int i = 0; i < vals.length; i++) {
+ _values.add (vals[i]);
+ }
}
- public string get_value (int index)
- requires (index >= 0)
+ public string? get_value_at (int index)
{
if (_values == null) return null;
+ if (index < 0 || index >= _values.size) return null;
return _values.get (index);
}
+ public void select_value_at (int index)
+ {
+ _val = get_value_at (index);
+ }
public string[] get_values () { return _values.to_array (); }
public string get_serializable_property_value () { return _val; }
public void set_serializable_property_value (string? val) { _val = val; }
diff --git a/test/GXmlTest.vala b/test/GXmlTest.vala
index d188d58..575ea01 100644
--- a/test/GXmlTest.vala
+++ b/test/GXmlTest.vala
@@ -77,6 +77,7 @@ class GXmlTest {
TwDocumentTest.add_tests ();
TwProcessingInstructionTest.add_tests ();
SerializablePropertyBoolTest.add_tests ();
+ SerializablePropertyValueListTest.add_tests ();
Test.run ();
diff --git a/test/Makefile.am b/test/Makefile.am
index a9031dd..5082514 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -39,6 +39,7 @@ sources = \
EnumerationTest.vala \
SerializableTest.vala \
SerializablePropertyBoolTest.vala \
+ SerializablePropertyValueListTest.vala \
SerializationTest.vala \
SerializableObjectModelTest.vala \
SerializableObjectModel-Tw-Test.vala \
diff --git a/test/SerializablePropertyBoolTest.vala b/test/SerializablePropertyBoolTest.vala
index cc59e1f..641399c 100644
--- a/test/SerializablePropertyBoolTest.vala
+++ b/test/SerializablePropertyBoolTest.vala
@@ -1,7 +1,7 @@
/* -*- Mode: vala; indent-tabs-mode: nil; tab-width: 2 -*- */
/**
*
- * GXml.Serializable.BasicTypeTest
+ * SerializablePropertyBoolTest.vala
*
* Authors:
*
diff --git a/test/SerializablePropertyValueListTest.vala b/test/SerializablePropertyValueListTest.vala
new file mode 100644
index 0000000..a5f8bec
--- /dev/null
+++ b/test/SerializablePropertyValueListTest.vala
@@ -0,0 +1,110 @@
+/* -*- Mode: vala; indent-tabs-mode: nil; tab-width: 2 -*- */
+/**
+ *
+ * SerializablePropertyValueListTest.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 SerializablePropertyValueListTest : GXmlTest {
+ public class ValueList : SerializableObjectModel
+ {
+ public SerializableValueList values { get; set; }
+ public int integer { get; set; default = 0; }
+ public string name { get; set; }
+ public override string node_name () { return "ValueList"; }
+ public override string to_string () { return get_type ().name (); }
+ }
+ public static void add_tests () {
+ Test.add_func ("/gxml/serializable/ValueList/basic",
+ () => {
+ try {
+ var vl = new ValueList ();
+ var doc = new xDocument ();
+ vl.serialize (doc);
+ Test.message ("XML:\n"+doc.to_string ());
+ var element = doc.document_element;
+ var evl1 = element.get_attribute_node ("boolean");
+ assert (evl1 == 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]