[gxml] Added some more tests to SerializableEnum and Enumeration



commit b1f1f1702963e0967cbbd9dd1ee55ba80eb6365d
Author: Daniel Espinosa <esodan gmail com>
Date:   Wed Sep 30 23:16:57 2015 -0500

    Added some more tests to SerializableEnum and Enumeration

 gxml/Enumeration.vala                  |    2 +-
 gxml/Makefile.am                       |    4 +-
 gxml/SerializableEnum.vala             |    4 +-
 po/POTFILES.in                         |    2 +-
 test/EnumerationTest.vala              |   35 ++++++++++++++++++++++++++++---
 test/SerializablePropertyEnumTest.vala |   12 +++++++++++
 6 files changed, 49 insertions(+), 10 deletions(-)
---
diff --git a/gxml/Enumeration.vala b/gxml/Enumeration.vala
index c7bdb2c..77a63e6 100644
--- a/gxml/Enumeration.vala
+++ b/gxml/Enumeration.vala
@@ -125,7 +125,7 @@ namespace GXml {
                                        enumv = ev;
                        }
                        if (enumv == null)
-                               throw new EnumerationError.INVALID_TEXT ("text is not valid");
+                               throw new EnumerationError.INVALID_TEXT ("text can not been parsed to 
enumeration type:"+enumeration.name ());
                        return enumv;
                }
                /**
diff --git a/gxml/Makefile.am b/gxml/Makefile.am
index 629b7c7..7039dda 100644
--- a/gxml/Makefile.am
+++ b/gxml/Makefile.am
@@ -84,8 +84,8 @@ sources = \
 ### General Compilation flags
 AM_CPPFLAGS = \
        -include $(CONFIG_HEADER) \
-       -DPACKAGE_DATA_DIR=\""$(datadir)"\" \
-       -DPACKAGE_LOCALE_DIR=\""$(prefix)/$(DATADIRNAME)/locale"\" \
+       -DPACKAGE_DATA_DIR=\""$(pkgdatadir)"\" \
+       -DPACKAGE_LOCALE_DIR=\""$(localedir)"\" \
        -DPACKAGE_SRC_DIR=\""$(srcdir)"\" \
        -DG_LOG_DOMAIN=\"gxml\" \
        -I$(top_srcdir) \
diff --git a/gxml/SerializableEnum.vala b/gxml/SerializableEnum.vala
index 7ecea1c..5956934 100644
--- a/gxml/SerializableEnum.vala
+++ b/gxml/SerializableEnum.vala
@@ -69,10 +69,10 @@ public class GXml.SerializableEnum : SerializableObjectModel, SerializableProper
   public int to_integer () throws GLib.Error
   {
     if (_val == null)
-      throw new SerializableEnumError.INVALID_VALUE_ERROR (_("Value can't be parsed to a valid enumeration's 
value. Value is not set"));
+      throw new SerializableEnumError.INVALID_VALUE_ERROR ("Value can't be parsed to a valid enumeration's 
value. Value is not set");
     var e = Enumeration.parse (_enumtype, _val);
     if (e == null)
-      throw new SerializableEnumError.INVALID_VALUE_ERROR (_("Value can't be parsed to a valid enumeration's 
value"));
+      throw new SerializableEnumError.INVALID_VALUE_ERROR ("Value can't be parsed to a valid enumeration's 
value");
     return e.value;
   }
   public string get_serializable_property_value () { return _val; }
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 501bebd..4175df1 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -1,3 +1,3 @@
 # List of source files containing translatable strings.
 
-# src/lib.c
+gxml/SerializableEnum.c
\ No newline at end of file
diff --git a/test/EnumerationTest.vala b/test/EnumerationTest.vala
index b3b3912..f2353b8 100644
--- a/test/EnumerationTest.vala
+++ b/test/EnumerationTest.vala
@@ -39,6 +39,12 @@ class Options : ObjectModel
 {
   public string test { get; set; }
   public OptionsEnum options { get; set; }
+  public Values vals { get; set; }
+  public enum Values {
+    AP,
+    KP_VALUE,
+    EXTERNAL_VALUE_VISION
+  }
 }
 class SerializableEnumerationTest : GXmlTest
 {
@@ -186,10 +192,7 @@ class SerializableEnumerationTest : GXmlTest
                        var doc6 = new xDocument.from_string ("""<?xml version="1.0"?>
                        <options options="SELECTBEFORE"/>""");
                        options.deserialize (doc6);
-                       if (options.options != OptionsEnum.SelectBefore)  {
-                         stdout.printf (@"ERROR: Bad value to options property: 
$(options.options)\n$(doc6)");
-                         assert_not_reached ();
-                       }
+                       assert (options.options == OptionsEnum.SelectBefore);
                        var doc7 = new xDocument.from_string ("""<?xml version="1.0"?>
                        <options options="NORMAL_OPERATION"/>""");
                        options.deserialize (doc7);
@@ -211,5 +214,29 @@ class SerializableEnumerationTest : GXmlTest
                        assert_not_reached ();
                      }
                    });
+    Test.add_func ("/gxml/serializable/enumeration/parse", () => {
+      try {
+        var v1 = Enumeration.parse (typeof (Options.Values), "AP");
+        assert (v1.value == (int) Options.Values.AP);
+        var v2 = Enumeration.parse (typeof (Options.Values), "Ap");
+        assert (v2.value == (int) Options.Values.AP);
+        var v3 = Enumeration.parse (typeof (Options.Values), "ap");
+        assert (v3.value == (int) Options.Values.AP);
+        var v4 = Enumeration.parse (typeof (Options.Values), "KPVALUE");
+        assert (v4.value == (int) Options.Values.KP_VALUE);
+        var v5 = Enumeration.parse (typeof (Options.Values), "KpValue");
+        assert (v5.value == (int) Options.Values.KP_VALUE);
+        var v6 = Enumeration.parse (typeof (Options.Values), "kpvalue");
+        assert (v6.value == (int) Options.Values.KP_VALUE);
+        var v7 = Enumeration.parse (typeof (Options.Values), "EXTERNALVALUEVISION");
+        assert (v7.value == (int) Options.Values.EXTERNAL_VALUE_VISION);
+        var v8 = Enumeration.parse (typeof (Options.Values), "ExternalValueVision");
+        assert (v8.value == (int) Options.Values.EXTERNAL_VALUE_VISION);
+        var v9 = Enumeration.parse (typeof (Options.Values), "externalvaluevision");
+        assert (v9.value == (int) Options.Values.EXTERNAL_VALUE_VISION);
+      } catch (GLib.Error e) {
+        Test.message ("Parse error: "+e.message);
+      }
+    });
   }
 }
diff --git a/test/SerializablePropertyEnumTest.vala b/test/SerializablePropertyEnumTest.vala
index 634411b..d1249a0 100644
--- a/test/SerializablePropertyEnumTest.vala
+++ b/test/SerializablePropertyEnumTest.vala
@@ -40,6 +40,7 @@ class SerializablePropertyEnumTest : GXmlTest {
       SER_ONE,
       SER_TWO,
       SER_THREE,
+      AP,
       SER_EXTENSION
     }
   }
@@ -126,5 +127,16 @@ class SerializablePropertyEnumTest : GXmlTest {
         assert_not_reached ();
       }
     });
+    Test.add_func ("/gxml/serializable/Enum/string",
+    () => {
+      try {
+        var e = new EnumerationValues ();
+        e.values.set_string ("SERONE");
+        assert (e.values.get_value () == Enum.Values.SER_ONE);
+      } 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]