[gxml] Fixed SerializableProperty property's nick name handle



commit b003ba730e8433fe2c4c15cc0cb8a5ace7fe2802
Author: Daniel Espinosa <esodan gmail com>
Date:   Fri Oct 2 23:19:34 2015 -0500

    Fixed SerializableProperty property's nick name handle

 gxml/SerializableProperty.vala         |   11 +++++++++--
 test/SerializablePropertyEnumTest.vala |   29 +++++++++++++++++++++++++++++
 2 files changed, 38 insertions(+), 2 deletions(-)
---
diff --git a/gxml/SerializableProperty.vala b/gxml/SerializableProperty.vala
index 8ae1130..ffe2d3a 100644
--- a/gxml/SerializableProperty.vala
+++ b/gxml/SerializableProperty.vala
@@ -84,7 +84,14 @@ public interface GXml.SerializableProperty : Object, Serializable
                                         throws GLib.Error
   {
     if (get_serializable_property_value () == null) return element;
-    ((GXml.Element) element).set_attr (prop.name, get_serializable_property_value ());
+    string name = "";
+    if (property_use_nick () &&
+        prop.get_nick () != null &&
+        prop.get_nick () != "")
+      name = prop.get_nick ();
+    else
+      name = prop.get_name ();
+    ((GXml.Element) element).set_attr (name, get_serializable_property_value ());
     return element;
   }
   /**
@@ -101,7 +108,7 @@ public interface GXml.SerializableProperty : Object, Serializable
     if (node is GXml.Element)
       attr = (GXml.Attribute) ((GXml.Element) node).attrs.get (get_serializable_property_name ());
     if (attr == null) return node;
-    if (attr.name == get_serializable_property_name ())
+    if (attr.name.down () == get_serializable_property_name ().down ())
       set_serializable_property_value (attr.value);
     return node;
   }
diff --git a/test/SerializablePropertyEnumTest.vala b/test/SerializablePropertyEnumTest.vala
index d1249a0..f52e595 100644
--- a/test/SerializablePropertyEnumTest.vala
+++ b/test/SerializablePropertyEnumTest.vala
@@ -47,6 +47,8 @@ class SerializablePropertyEnumTest : GXmlTest {
   public class EnumerationValues : SerializableObjectModel
   {
     public Enum values { get; set; default = new Enum ("values"); }
+    [Description(nick="OptionalValues", blurb="Optional values")]
+    public Enum optional_values { get; set; default = new Enum ("OptionalValues"); }
     public int  integer { get; set; default = 0; }
     public string name { get; set; }
     public override string node_name () { return "Enum"; }
@@ -138,5 +140,32 @@ class SerializablePropertyEnumTest : GXmlTest {
         assert_not_reached ();
       }
     });
+    Test.add_func ("/gxml/serializable/Enum/property_name",
+    () => {
+      try {
+        var e = new EnumerationValues ();
+        e.values.set_value (Enum.Values.AP);
+        var d1 = new xDocument ();
+        e.serialize (d1);
+        Test.message ("XML1: "+d1.to_string ());
+        var d2 = new xDocument.from_string ("""<?xml version="1.0"?>
+                       <Enum optionalvalues="SerExtension"/>""");
+        e.deserialize (d2);
+        assert (e.optional_values.get_value () == Enum.Values.SER_EXTENSION);
+        var d3 = new xDocument ();
+        e.serialize (d3);
+        Test.message ("XML2: "+d3.to_string ());
+        var d4 = new xDocument.from_string ("""<?xml version="1.0"?>
+                       <Enum OPTIONALVALUES="SERTHREE"/>""");
+        e.deserialize (d4);
+        assert (e.optional_values.get_value () == Enum.Values.SER_THREE);
+        var d5 = new xDocument ();
+        e.serialize (d5);
+        Test.message ("XML3: "+d5.to_string ());
+      } 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]