[gxml] Added documentation and unit tests for deserialize to SerializableFloat



commit fec954bc89e27e722787ff3f33eaee91213312b0
Author: Daniel Espinosa <esodan gmail com>
Date:   Thu Oct 22 10:20:50 2015 -0500

    Added documentation and unit tests for deserialize to SerializableFloat

 gxml/SerializableFloat.vala             |   12 +++++++
 test/SerializablePropertyFloatTest.vala |   50 +++++++++++++++++++++++++++++++
 2 files changed, 62 insertions(+), 0 deletions(-)
---
diff --git a/gxml/SerializableFloat.vala b/gxml/SerializableFloat.vala
index bb53521..63e597d 100644
--- a/gxml/SerializableFloat.vala
+++ b/gxml/SerializableFloat.vala
@@ -22,6 +22,18 @@
 
 public class GXml.SerializableFloat : GXml.SerializableDouble
 {
+  /**
+   * Parse the stored value, from the XML property, to a { link int}. This parsing
+   * may is different from the actual stored string.
+   *
+   * The stored value, is parsed using { lilnk GLib.ascii_strtod} and then
+   * casted to an float before return, this make flexible on stored values
+   * in XML and parsed without errors, but they could defere from the value
+   * returned by this method.
+   */
   public new float get_value () { return (float) double.parse (_val); }
+  /**
+   * Given float number is parsed to string and then stored.
+   */
   public new void set_value (float val) { _val = val.to_string (); }
 }
\ No newline at end of file
diff --git a/test/SerializablePropertyFloatTest.vala b/test/SerializablePropertyFloatTest.vala
index f14aeea..f892509 100644
--- a/test/SerializablePropertyFloatTest.vala
+++ b/test/SerializablePropertyFloatTest.vala
@@ -103,5 +103,55 @@ class SerializablePropertyFloatTest : GXmlTest {
         assert_not_reached ();
       }
     });
+    Test.add_func ("/gxml/serializable/Float/deserialize",
+    () => {
+      try {
+        var doc1 = new xDocument.from_string ("""<?xml version="1.0"?>
+                       <FloatNode FloatValue="3.1416"/>""");
+        var f = new FloatNode ();
+        f.deserialize (doc1);
+        Test.message ("Actual value: "+f.float_value.get_serializable_property_value ());
+        assert (f.float_value.get_serializable_property_value () == "3.1416");
+        Test.message ("Actual value parse: "+f.float_value.get_value ().to_string ());
+        assert ("%2.4f".printf (f.float_value.get_value ()) == "%2.4f".printf (3.1416));
+      } catch (GLib.Error e) {
+        Test.message (@"ERROR: $(e.message)");
+        assert_not_reached ();
+      }
+    });
+    Test.add_func ("/gxml/serializable/Float/deserialize",
+    () => {
+      try {
+        var doc1 = new xDocument.from_string ("""<?xml version="1.0"?>
+                       <FloatNode FloatValue="3.1416"/>""");
+        var d = new FloatNode ();
+        d.deserialize (doc1);
+        Test.message ("Actual value: "+d.float_value.get_serializable_property_value ());
+        assert (d.float_value.get_serializable_property_value () == "3.1416");
+        Test.message ("Actual value parse: "+"%2.4f".printf (double.parse 
(d.float_value.get_serializable_property_value ())));
+        assert ("%2.4f".printf (double.parse (d.float_value.get_serializable_property_value ())) == 
"3.1416");
+        Test.message ("Value comparation: %2.4f".printf (d.float_value.get_value ()));
+        assert ("%2.4f".printf (d.float_value.get_value ()) == "%2.4f".printf (double.parse ("3.1416")));
+      } catch (GLib.Error e) {
+        Test.message (@"ERROR: $(e.message)");
+        assert_not_reached ();
+      }
+    });
+    Test.add_func ("/gxml/serializable/Float/deserialize/bad-value",
+    () => {
+      try {
+        var doc1 = new xDocument.from_string ("""<?xml version="1.0"?>
+                       <FloatNode FloatValue="a"/>""");
+        var d = new FloatNode ();
+        d.deserialize (doc1);
+        Test.message ("Actual value: "+d.float_value.get_serializable_property_value ());
+        assert (d.float_value.get_serializable_property_value () == "a");
+        Test.message ("Actual value parse: "+"%2.4f".printf (double.parse 
(d.float_value.get_serializable_property_value ())));
+        assert ("%2.4f".printf (double.parse (d.float_value.get_serializable_property_value ())) == 
"0.0000");
+      } 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]