[gxml] GomObject: Added support for float and uint



commit 36270d884918c8a2779a3fe61dac6ef10225d785
Author: Daniel Espinosa <esodan gmail com>
Date:   Tue Jun 27 19:14:35 2017 -0500

    GomObject: Added support for float and uint

 gxml/GomObject.vala            |   11 +++++++-
 test/GomSerializationTest.vala |   54 ++++++++++++++++++++++++++++++++++++++-
 2 files changed, 62 insertions(+), 3 deletions(-)
---
diff --git a/gxml/GomObject.vala b/gxml/GomObject.vala
index 7a0736e..34ddb31 100644
--- a/gxml/GomObject.vala
+++ b/gxml/GomObject.vala
@@ -154,6 +154,9 @@ public interface GXml.GomObject : GLib.Object,
     if (prop.value_type.is_a (typeof (uint))) {
       return ((uint) v).to_string ();
     }
+    if (prop.value_type.is_a (typeof (float))) {
+      return ((float) v).to_string ();
+    }
     if (prop.value_type.is_a (typeof (double))) {
       return ((double) v).to_string ();
     }
@@ -241,7 +244,13 @@ public interface GXml.GomObject : GLib.Object,
       }
       if (prop.value_type.is_a (typeof (uint))) {
         uint iv = (uint) double.parse (val);
-        v.set_int ((int) iv);
+        v.set_uint ((int) iv);
+        set_property (prop.name, v);
+        return true;
+      }
+      if (prop.value_type.is_a (typeof (float))) {
+        double dv = double.parse (val);
+        v.set_float ((float) dv);
         set_property (prop.name, v);
         return true;
       }
diff --git a/test/GomSerializationTest.vala b/test/GomSerializationTest.vala
index f6a6c73..4475dc1 100644
--- a/test/GomSerializationTest.vala
+++ b/test/GomSerializationTest.vala
@@ -143,7 +143,7 @@ class GomCategory : GomElement
   construct { try { initialize ("Category"); } catch { assert_not_reached (); } }
   public class Map : GomHashMap {
     construct {
-      try { initialize_with_key (typeof (GomInventory), "name");  }
+      try { initialize_with_key (typeof (GomCategory), "name");  }
       catch { assert_not_reached (); }
     }
   }
@@ -159,7 +159,7 @@ class GomResume : GomElement
   construct { try { initialize ("Resume"); } catch { assert_not_reached (); } }
   public class Map : GomHashMap {
     construct {
-      try { initialize_with_key (typeof (GomInventory), "chapter"); }
+      try { initialize_with_key (typeof (GomResume), "chapter"); }
       catch { assert_not_reached (); }
     }
   }
@@ -197,6 +197,24 @@ class GomBookStore : GomElement
   }
 }
 
+class GomBasicTypes : GomElement {
+  [Description (nick="::text")]
+  public string text { get; set; }
+  [Description (nick="::integer")]
+  public int integer { get; set; }
+  [Description (nick="::realDouble")]
+  public double real_double { get; set; }
+  [Description (nick="::realFloat")]
+  public float real_float { get; set; }
+  [Description (nick="::unsignedInteger")]
+  public uint unsigned_integer { get; set; }
+  [Description (nick="::Boolean")]
+  public bool boolean { get; set; }
+  construct {
+    try { initialize ("GomBasicTypes"); } catch { assert_not_reached (); }
+  }
+}
+
 class GomSerializationTest : GXmlTest  {
   public class Book : GomElement {
     [Description (nick="::Name")]
@@ -1307,5 +1325,37 @@ class GomSerializationTest : GXmlTest  {
         assert_not_reached ();
       }
     });
+    Test.add_func ("/gxml/gom-serialization/basic-types",
+    () => {
+      try {
+        var bt = new GomBasicTypes ();
+        message (bt.write_string ());
+        bt.text = "Text";
+        bt.integer = -1;
+        bt.unsigned_integer = 1;
+        bt.real_float = (float) 1.1;
+        bt.real_double = 2.2;
+        message (bt.write_string ());
+        var bt2 = new GomBasicTypes ();
+        bt2.read_from_string (bt.write_string ());
+        assert (bt2.text == "Text");
+        assert (bt2.integer == -1);
+        assert (bt2.unsigned_integer == 1);
+        assert (bt2.real_float == (float) 1.1);
+        assert (bt2.real_double == 2.2);
+        bt2.real_double = 100.0;
+        assert (bt2.real_double == 100.0);
+        var bt3 = new GomBasicTypes ();
+        bt3.read_from_string (bt2.write_string ());
+        assert (bt3.text == "Text");
+        assert (bt3.integer == -1);
+        assert (bt3.unsigned_integer == 1);
+        assert (bt3.real_float == (float) 1.1);
+        assert (bt3.real_double == 100.0);
+      } catch (GLib.Error e) {
+        GLib.message ("ERROR: "+e.message);
+        assert_not_reached ();
+      }
+    });
   }
 }


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