[gxml] Added Unit Test for Serializable Float, Double and Int



commit e5cd6090b58898391c3845874a857f6c792339b5
Author: Daniel Espinosa <esodan gmail com>
Date:   Tue Oct 6 15:06:48 2015 -0500

    Added Unit Test for Serializable Float, Double and Int

 test/GXmlTest.vala                       |    1 +
 test/Makefile.am                         |    1 +
 test/SerializablePropertyDoubleTest.vala |  105 ++++++++++++++++++++++++++++++
 test/SerializablePropertyFloatTest.vala  |  105 ++++++++++++++++++++++++++++++
 test/SerializablePropertyIntTest.vala    |   99 ++++++++++++++++++++++++++++
 5 files changed, 311 insertions(+), 0 deletions(-)
---
diff --git a/test/GXmlTest.vala b/test/GXmlTest.vala
index 64dac61..df46144 100644
--- a/test/GXmlTest.vala
+++ b/test/GXmlTest.vala
@@ -78,6 +78,7 @@ class GXmlTest {
                TwProcessingInstructionTest.add_tests ();
                SerializablePropertyBoolTest.add_tests ();
                SerializablePropertyDoubleTest.add_tests ();
+               SerializablePropertyFloatTest.add_tests ();
                SerializablePropertyIntTest.add_tests ();
                SerializablePropertyValueListTest.add_tests ();
                SerializablePropertyEnumTest.add_tests ();
diff --git a/test/Makefile.am b/test/Makefile.am
index 38f2b8a..c9ffb37 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -40,6 +40,7 @@ sources = \
        SerializableTest.vala \
        SerializablePropertyBoolTest.vala \
        SerializablePropertyDoubleTest.vala \
+       SerializablePropertyFloatTest.vala \
        SerializablePropertyEnumTest.vala \
        SerializablePropertyIntTest.vala \
        SerializablePropertyValueListTest.vala \
diff --git a/test/SerializablePropertyDoubleTest.vala b/test/SerializablePropertyDoubleTest.vala
new file mode 100644
index 0000000..f5bb5c4
--- /dev/null
+++ b/test/SerializablePropertyDoubleTest.vala
@@ -0,0 +1,105 @@
+/* -*- Mode: vala; indent-tabs-mode: nil; tab-width: 2 -*- */
+/**
+ *
+ *  SerializablePropertyDoubleTest.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 SerializablePropertyDoubleTest : GXmlTest {
+  public class DoubleNode : SerializableObjectModel
+  {
+    [Description (nick="DoubleValue")]
+    public SerializableDouble  double_value { get; set; default = new SerializableDouble.with_name 
("DoubleValue"); }
+    public string name { get; set; }
+    public override string node_name () { return "DoubleNode"; }
+    public override string to_string () { return get_type ().name (); }
+  }
+  public static void add_tests () {
+    Test.add_func ("/gxml/serializable/Double/basic",
+    () => {
+      try {
+        var bn = new DoubleNode ();
+        var doc = new xDocument ();
+        bn.serialize (doc);
+        Test.message ("XML:\n"+doc.to_string ());
+        var element = doc.document_element;
+        var b = element.get_attribute_node ("DoubleValue");
+        assert (b == null);
+        var s = element.get_attribute_node ("name");
+        assert (s == null);
+      } catch (GLib.Error e) {
+        Test.message (@"ERROR: $(e.message)");
+        assert_not_reached ();
+      }
+    });
+    Test.add_func ("/gxml/serializable/Double/changes",
+    () => {
+      try {
+        var bn = new DoubleNode ();
+        var doc = new xDocument ();
+        bn.serialize (doc);
+        Test.message ("XML:\n"+doc.to_string ());
+        var element = doc.document_element;
+        var b = element.get_attribute_node ("DoubleValue");
+        assert (b == null);
+        var s = element.get_attribute_node ("name");
+        assert (s == null);
+        // Change values
+        // set to 233.014
+        bn.double_value.set_value (233.014);
+        var doc2 = new xDocument ();
+        bn.serialize (doc2);
+        Test.message ("XML2:\n"+doc2.to_string ());
+        var element2 = doc2.document_element;
+        var b2 = element2.get_attribute_node ("DoubleValue");
+        assert (b2 != null);
+        assert (bn.double_value.get_value () == 233.014);
+        Test.message ("Value in xml: "+b2.value);
+        Test.message ("Value in double class: "+bn.double_value.get_value ().to_string ());
+        Test.message ("Value in xml formated %3.3f".printf (double.parse (b2.value)));
+        Test.message ("%3.3f".printf (double.parse (b2.value)));
+        assert ("%3.3f".printf (double.parse (b2.value)) == "233.014");
+        assert (bn.double_value.format ("%3.3f") == "233.014");
+        // set to -1
+        bn.double_value.set_value (-1.013);
+        var doc3 = new xDocument ();
+        bn.serialize (doc3);
+        Test.message ("XML3:\n"+doc3.to_string ());
+        var element3 = doc3.document_element;
+        var b3 = element3.get_attribute_node ("DoubleValue");
+        assert (b3 != null);
+        assert ("%2.3f".printf (double.parse (b3.value)) == "-1.013");
+        // set to NULL/IGNORE
+        bn.double_value.set_serializable_property_value (null);
+        var doc4= new xDocument ();
+        bn.serialize (doc4);
+        Test.message ("XML3:\n"+doc4.to_string ());
+        var element4 = doc4.document_element;
+        var b4 = element4.get_attribute_node ("DoubleValue");
+        assert (b4 == null);
+      } catch (GLib.Error e) {
+        Test.message (@"ERROR: $(e.message)");
+        assert_not_reached ();
+      }
+    });
+  }
+}
diff --git a/test/SerializablePropertyFloatTest.vala b/test/SerializablePropertyFloatTest.vala
new file mode 100644
index 0000000..4d15b64
--- /dev/null
+++ b/test/SerializablePropertyFloatTest.vala
@@ -0,0 +1,105 @@
+/* -*- Mode: vala; indent-tabs-mode: nil; tab-width: 2 -*- */
+/**
+ *
+ *  SerializablePropertyFloatTest.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 SerializablePropertyFloatTest : GXmlTest {
+  public class FloatNode : SerializableObjectModel
+  {
+    [Description (nick="FloatValue")]
+    public SerializableFloat  float_value { get; set; default = new SerializableFloat ("FloatValue"); }
+    public string name { get; set; }
+    public override string node_name () { return "FloatNode"; }
+    public override string to_string () { return get_type ().name (); }
+  }
+  public static void add_tests () {
+    Test.add_func ("/gxml/serializable/Float/basic",
+    () => {
+      try {
+        var bn = new FloatNode ();
+        var doc = new xDocument ();
+        bn.serialize (doc);
+        Test.message ("XML:\n"+doc.to_string ());
+        var element = doc.document_element;
+        var b = element.get_attribute_node ("FloatValue");
+        assert (b == null);
+        var s = element.get_attribute_node ("name");
+        assert (s == null);
+      } catch (GLib.Error e) {
+        Test.message (@"ERROR: $(e.message)");
+        assert_not_reached ();
+      }
+    });
+    Test.add_func ("/gxml/serializable/Float/changes",
+    () => {
+      try {
+        var bn = new FloatNode ();
+        var doc = new xDocument ();
+        bn.serialize (doc);
+        Test.message ("XML:\n"+doc.to_string ());
+        var element = doc.document_element;
+        var b = element.get_attribute_node ("FloatValue");
+        assert (b == null);
+        var s = element.get_attribute_node ("name");
+        assert (s == null);
+        // Change values
+        // set to 233.014
+        bn.float_value.set_value ((float) 233.014);
+        var doc2 = new xDocument ();
+        bn.serialize (doc2);
+        Test.message ("XML2:\n"+doc2.to_string ());
+        var element2 = doc2.document_element;
+        var b2 = element2.get_attribute_node ("FloatValue");
+        assert (b2 != null);
+        assert (bn.float_value.get_value () == (float) 233.014);
+        Test.message ("Value in xml: "+b2.value);
+        Test.message ("Value in double class: "+bn.float_value.get_value ().to_string ());
+        Test.message ("Value in xml formated %3.3f".printf (double.parse (b2.value)));
+        Test.message ("%3.3f".printf (double.parse (b2.value)));
+        assert ("%3.3f".printf (double.parse (b2.value)) == "233.014");
+        assert (bn.float_value.format ("%3.3f") == "233.014");
+        // set to -1
+        bn.float_value.set_value ((float) (-1.013));
+        var doc3 = new xDocument ();
+        bn.serialize (doc3);
+        Test.message ("XML3:\n"+doc3.to_string ());
+        var element3 = doc3.document_element;
+        var b3 = element3.get_attribute_node ("FloatValue");
+        assert (b3 != null);
+        assert ("%2.3f".printf (double.parse (b3.value)) == "-1.013");
+        // set to NULL/IGNORE
+        bn.float_value.set_serializable_property_value (null);
+        var doc4= new xDocument ();
+        bn.serialize (doc4);
+        Test.message ("XML3:\n"+doc4.to_string ());
+        var element4 = doc4.document_element;
+        var b4 = element4.get_attribute_node ("FloatValue");
+        assert (b4 == null);
+      } catch (GLib.Error e) {
+        Test.message (@"ERROR: $(e.message)");
+        assert_not_reached ();
+      }
+    });
+  }
+}
diff --git a/test/SerializablePropertyIntTest.vala b/test/SerializablePropertyIntTest.vala
new file mode 100644
index 0000000..db7ce9b
--- /dev/null
+++ b/test/SerializablePropertyIntTest.vala
@@ -0,0 +1,99 @@
+/* -*- Mode: vala; indent-tabs-mode: nil; tab-width: 2 -*- */
+/**
+ *
+ *  SerializablePropertyIntTest.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 SerializablePropertyIntTest : GXmlTest {
+  public class IntNode : SerializableObjectModel
+  {
+    [Description (nick="IntegerValue")]
+    public SerializableInt  integer { get; set; default = new SerializableInt.with_name ("IntegerValue"); }
+    public string name { get; set; }
+    public override string node_name () { return "IntNode"; }
+    public override string to_string () { return get_type ().name (); }
+  }
+  public static void add_tests () {
+    Test.add_func ("/gxml/serializable/Int/basic",
+    () => {
+      try {
+        var bn = new IntNode ();
+        var doc = new xDocument ();
+        bn.serialize (doc);
+        Test.message ("XML:\n"+doc.to_string ());
+        var element = doc.document_element;
+        var b = element.get_attribute_node ("IntegerValue");
+        assert (b == null);
+        var s = element.get_attribute_node ("name");
+        assert (s == null);
+      } catch (GLib.Error e) {
+        Test.message (@"ERROR: $(e.message)");
+        assert_not_reached ();
+      }
+    });
+    Test.add_func ("/gxml/serializable/Int/changes",
+    () => {
+      try {
+        var bn = new IntNode ();
+        var doc = new xDocument ();
+        bn.serialize (doc);
+        Test.message ("XML:\n"+doc.to_string ());
+        var element = doc.document_element;
+        var b = element.get_attribute_node ("IntegerValue");
+        assert (b == null);
+        var s = element.get_attribute_node ("name");
+        assert (s == null);
+        // Change values
+        // set to 233
+        bn.integer.set_value (233);
+        var doc2 = new xDocument ();
+        bn.serialize (doc2);
+        Test.message ("XML2:\n"+doc2.to_string ());
+        var element2 = doc2.document_element;
+        var b2 = element2.get_attribute_node ("IntegerValue");
+        assert (b2 != null);
+        assert (b2.value == "233");
+        // set to -1
+        bn.integer.set_value (-1);
+        var doc3 = new xDocument ();
+        bn.serialize (doc3);
+        Test.message ("XML3:\n"+doc3.to_string ());
+        var element3 = doc3.document_element;
+        var b3 = element3.get_attribute_node ("IntegerValue");
+        assert (b3 != null);
+        assert (b3.value == "-1");
+        // set to NULL/IGNORE
+        bn.integer.set_serializable_property_value (null);
+        var doc4= new xDocument ();
+        bn.serialize (doc4);
+        Test.message ("XML3:\n"+doc4.to_string ());
+        var element4 = doc4.document_element;
+        var b4 = element4.get_attribute_node ("IntegerValue");
+        assert (b4 == 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]