[gxml] Added unit tests to SerializableDouble



commit 7c9028f84513ff4f91ce53d255393a88274cdf98
Author: Daniel Espinosa <esodan gmail com>
Date:   Tue Oct 6 14:54:01 2015 -0500

    Added unit tests to SerializableDouble

 gxml/SerializableDouble.vala |   81 ++++++++++++++++++++++++++++++++++++++++++
 test/GXmlTest.vala           |    1 +
 test/Makefile.am             |    1 +
 3 files changed, 83 insertions(+), 0 deletions(-)
---
diff --git a/gxml/SerializableDouble.vala b/gxml/SerializableDouble.vala
new file mode 100644
index 0000000..9683f1e
--- /dev/null
+++ b/gxml/SerializableDouble.vala
@@ -0,0 +1,81 @@
+/* -*- Mode: vala; indent-tabs-mode: nil; c-basic-offset: 2; tab-width: 2 -*- */
+/* SerializableInt.vala
+ *
+ * Copyright (C) 2015  Daniel Espinosa <esodan gmail com>
+ *
+ * This library 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 2.1 of the License, or (at your option) any later version.
+
+ * This library 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 library; if not, see <http://www.gnu.org/licenses/>.
+ *
+ * Authors:
+ *      Daniel Espinosa <esodan gmail com>
+ */
+
+using Gee;
+/**
+ * Represent any boolean property to be added as a { link GXml.Attr} to a { link GXml.Element}
+ *
+ */
+public class GXml.SerializableDouble : SerializableObjectModel, SerializableProperty
+{
+  private string _val = null;
+  private string _name = null;
+  private int _fraction = -1;
+  public SerializableDouble.with_name (string name) { _name = name; }
+  public int get_fraction () { return _fraction; }
+  public void set_fraction (int fraction) {
+    int v = fraction;
+    if (v < 0) _fraction = -1;
+    _fraction = v;
+  }
+  public double get_value () { return double.parse (_val); }
+  public void set_value (double val) { _val = val.to_string (); }
+  public string get_serializable_property_value () { return _val; }
+  public void set_serializable_property_value (string? val) {
+    if (val == null)
+      _val = val;
+    else
+      _val = double.parse (val).to_string ();
+  }
+  public string get_serializable_property_name () { return _name; }
+  public void set_serializable_property_name (string name) { _name = name; }
+  public override GXml.Node? serialize (GXml.Node node) throws GLib.Error
+  {
+    return default_serializable_property_serialize (node);
+  }
+  public override GXml.Node? serialize_property (GXml.Node element,
+                                        GLib.ParamSpec prop)
+                                        throws GLib.Error
+  {
+    return default_serializable_property_serialize_property (element, prop);
+  }
+  public override GXml.Node? deserialize (GXml.Node node)
+                                      throws GLib.Error
+  {
+    return default_serializable_property_deserialize (node);
+  }
+  public override bool deserialize_property (GXml.Node property_node)
+                                              throws GLib.Error
+  {
+    default_serializable_property_deserialize (property_node);
+    return true;
+  }
+  public override string to_string () {
+    if (_val != null) return (double.parse (_val)).to_string ();
+    return "";
+  }
+  public string format (string f)
+  {
+    if (_val != null) return f.printf (double.parse (_val));
+    return "";
+  }
+}
\ No newline at end of file
diff --git a/test/GXmlTest.vala b/test/GXmlTest.vala
index d0f5a19..64dac61 100644
--- a/test/GXmlTest.vala
+++ b/test/GXmlTest.vala
@@ -77,6 +77,7 @@ class GXmlTest {
                TwDocumentTest.add_tests ();
                TwProcessingInstructionTest.add_tests ();
                SerializablePropertyBoolTest.add_tests ();
+               SerializablePropertyDoubleTest.add_tests ();
                SerializablePropertyIntTest.add_tests ();
                SerializablePropertyValueListTest.add_tests ();
                SerializablePropertyEnumTest.add_tests ();
diff --git a/test/Makefile.am b/test/Makefile.am
index 66c4202..38f2b8a 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -39,6 +39,7 @@ sources = \
        EnumerationTest.vala \
        SerializableTest.vala \
        SerializablePropertyBoolTest.vala \
+       SerializablePropertyDoubleTest.vala \
        SerializablePropertyEnumTest.vala \
        SerializablePropertyIntTest.vala \
        SerializablePropertyValueListTest.vala \


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]