[gxml/serialization] Build fixes for GXml 0.4



commit 438754176dc7c77e8f3c321c96a45125354a3cd3
Author: Daniel Espinosa <esodan gmail com>
Date:   Sat Feb 1 03:43:47 2014 -0600

    Build fixes for GXml 0.4

 gxml/Makefile.am          |   10 +--
 test/EnumerationTest.vala |  215 +++++++++++++++++++++++++++++++++++++++++++++
 test/GXmlTest.vala        |    1 +
 test/Makefile.am          |    4 +-
 4 files changed, 219 insertions(+), 11 deletions(-)
---
diff --git a/gxml/Makefile.am b/gxml/Makefile.am
index edd0623..40e62e7 100644
--- a/gxml/Makefile.am
+++ b/gxml/Makefile.am
@@ -67,18 +67,10 @@ libgxml_0_4_la_SOURCES = \
        SerializableGeeArrayList.vala \
        SerializableContainer.vala
 
-# TODO: do we want XPath files in own directory?
-
 gxml_0_4_la_vala.stamp: $(libgxml_0_4_la_SOURCES)
 
-
-# libgxml_la_SOURCES = \
-#      gxml.vala.stamp \
-#      $(libgxml_la_VALASOURCES:.vala=.c) \
-#      $(NULL)
-
 # library flags
-libgxml__0_4_la_VALAFLAGS = \
+VALAFLAGS = \
        $(AM_VALAFLAGS) \
        $(ERROR_VALAFLAGS) \
        --gir=GXml-$(API_VERSION).gir \
diff --git a/test/EnumerationTest.vala b/test/EnumerationTest.vala
new file mode 100644
index 0000000..4b689e4
--- /dev/null
+++ b/test/EnumerationTest.vala
@@ -0,0 +1,215 @@
+/* -*- Mode: vala; indent-tabs-mode: nil; c-basic-offset: 2; tab-width: 2 -*- */
+/**
+ *
+ *  GXml.EnumerationTest
+ *
+ *  Authors:
+ *
+ *       Daniel Espinosa <esodan gmail com>
+ *
+ *
+ *  Copyright (c) 2013-2014 Daniel Espinosa
+ *
+ *  This program 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 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program 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 program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+using GXml;
+using Gee;
+
+public enum OptionsEnum
+{
+  [Description (nick="SelectionOption")]
+  SelectBefore,
+  HoldOn,
+  LeaveHeare,
+  NORMAL_OPERATION
+}
+
+class Options : ObjectModel
+{
+  public string test { get; set; }
+  public OptionsEnum options { get; set; }
+}
+class SerializableEnumerationTest : GXmlTest
+{
+  public static void add_tests ()
+  {
+    Test.add_func ("/gxml/serializable/enumeration",
+                   () => {
+                     var e = new Options ();
+                     try {
+                       e.test = "t1";
+                       e.options = OptionsEnum.SelectBefore;
+                       string s = Enumeration.get_string (typeof (OptionsEnum), e.options);
+                       if (s != "OPTIONS_ENUM_SelectBefore") {
+                         stdout.printf (@"ERROR: Bad Enum stringification: $(s)");
+                         assert_not_reached ();
+                       }
+                       s = Enumeration.get_nick (typeof (OptionsEnum), e.options);
+                       if (s != "selectbefore") {
+                         stdout.printf (@"ERROR: Bad Enum nick name: $(s)");
+                         assert_not_reached ();
+                       }
+                       s = Enumeration.get_nick (typeof (OptionsEnum),OptionsEnum.NORMAL_OPERATION);
+                       if (s != "normal-operation") {
+                         stdout.printf (@"ERROR: Bad Enum nick name: $(s)");
+                         assert_not_reached ();
+                       }
+                       s = Enumeration.get_nick_camelcase (typeof 
(OptionsEnum),OptionsEnum.NORMAL_OPERATION);
+                       if (s != "NormalOperation") {
+                         stdout.printf (@"ERROR: Bad Enum nick name: $(s)");
+                         assert_not_reached ();
+                       }
+                       try {
+                         Enumeration.parse (typeof (OptionsEnum), "selectbefore");
+                       }
+                       catch (GLib.Error e) {
+                         stdout.printf (@"ERROR PARSING selectbefore: $(e.message)");
+                         assert_not_reached ();
+                       }
+                       try {
+                         Enumeration.parse (typeof (OptionsEnum), "normal-operation");
+                       }
+                       catch (GLib.Error e) {
+                         stdout.printf (@"ERROR PARSING normal-operation: $(e.message)");
+                         assert_not_reached ();
+                       }
+                       try {
+                         Enumeration.parse (typeof (OptionsEnum), "NormalOperation");
+                       }
+                       catch (GLib.Error e) {
+                         stdout.printf (@"ERROR PARSING NormalOperation: $(e.message)");
+                         assert_not_reached ();
+                       }
+                       var env = Enumeration.parse (typeof (OptionsEnum), "NormalOperation");
+                       Value v = Value (typeof (int));
+                       v.set_int (env.value);
+                       e.options = (OptionsEnum) v.get_int ();
+                       if (e.options != OptionsEnum.NORMAL_OPERATION) {
+                         stdout.printf (@"ERROR: setting NormalOperation: $(e.options)");
+                         assert_not_reached ();
+                       }
+                     }
+                     catch (GLib.Error e) {
+                       stdout.printf (@"Error: $(e.message)");
+                       assert_not_reached ();
+                     }
+                   });
+    Test.add_func ("/gxml/serializable/enumeration-serialize",
+                   () => {
+                     var doc = new Document ();
+                     var options = new Options ();
+                     options.options = OptionsEnum.NORMAL_OPERATION;
+                     try {
+                       options.serialize (doc);
+                       if (doc.document_element == null)  {
+                         stdout.printf (@"ERROR: No root node found");
+                         assert_not_reached ();
+                       }
+                       if (doc.document_element.node_name != "options") {
+                         stdout.printf (@"ERROR: bad root name:\n$(doc)");
+                         assert_not_reached ();
+                       }
+                       Element element = doc.document_element;
+                       var op = element.get_attribute_node ("options");
+                       if (op == null) {
+                         stdout.printf (@"ERROR: attribute options not found:\n$(doc)");
+                         assert_not_reached ();
+                       }
+                       if (op.node_value != "NormalOperation") {
+                         stdout.printf (@"ERROR: attribute options value invalid: $(op.node_value)\n$(doc)");
+                         assert_not_reached ();
+                       }
+                       options.options = (OptionsEnum) (-1); // invaliding this property. Avoids serialize 
it.
+                       var doc2 = new Document ();
+                       options.serialize (doc2);
+                       var opts = doc2.document_element.get_attribute_node ("options");
+                       if (opts != null) {
+                         stdout.printf (@"ERROR: attribute options must not be present:\n$(doc)");
+                         assert_not_reached ();
+                       }
+                     }
+                     catch (GLib.Error e) {
+                       stdout.printf (@"Error: $(e.message)");
+                       assert_not_reached ();
+                     }
+                   });
+    Test.add_func ("/gxml/serializable/enumeration-deserialize",
+                   () => {
+                     var options = new Options ();
+                     try {
+                       var doc = new Document.from_string ("""<?xml version="1.0"?>
+                       <options options="NormalOperation"/>""");
+                       options.deserialize (doc);
+                       if (options.options != OptionsEnum.NORMAL_OPERATION)  {
+                         stdout.printf (@"ERROR: Bad value to options property: $(options.options)\n$(doc)");
+                         assert_not_reached ();
+                       }
+                       var doc2 = new Document.from_string ("""<?xml version="1.0"?>
+                       <options options="normal-operation"/>""");
+                       options.deserialize (doc2);
+                       if (options.options != OptionsEnum.NORMAL_OPERATION)  {
+                         stdout.printf (@"ERROR: Bad value to options property: 
$(options.options)\n$(doc2)");
+                         assert_not_reached ();
+                       }
+                       var doc3 = new Document.from_string ("""<?xml version="1.0"?>
+                       <options options="selectbefore"/>""");
+                       options.deserialize (doc3);
+                       if (options.options != OptionsEnum.SelectBefore)  {
+                         stdout.printf (@"ERROR: Bad value to options property: 
$(options.options)\n$(doc3)");
+                         assert_not_reached ();
+                       }
+                       var doc4 = new Document.from_string ("""<?xml version="1.0"?>
+                       <options options="OPTIONS_ENUM_SelectBefore"/>""");
+                       options.deserialize (doc4);
+                       if (options.options != OptionsEnum.SelectBefore)  {
+                         stdout.printf (@"ERROR: Bad value to options property: 
$(options.options)\n$(doc4)");
+                         assert_not_reached ();
+                       }
+                       var doc5 = new Document.from_string ("""<?xml version="1.0"?>
+                       <options options="SelectBefore"/>""");
+                       options.deserialize (doc5);
+                       if (options.options != OptionsEnum.SelectBefore)  {
+                         stdout.printf (@"ERROR: Bad value to options property: 
$(options.options)\n$(doc5)");
+                         assert_not_reached ();
+                       }
+                       var doc6 = new Document.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 ();
+                       }
+                       var doc7 = new Document.from_string ("""<?xml version="1.0"?>
+                       <options options="NORMAL_OPERATION"/>""");
+                       options.deserialize (doc7);
+                       if (options.options != OptionsEnum.SelectBefore)  {
+                         stdout.printf (@"ERROR: Bad value to options property: 
$(options.options)\n$(doc7)");
+                         assert_not_reached ();
+                       }
+                       var op2 = new Options ();
+                       var doc8 = new Document.from_string ("""<?xml version="1.0"?>
+                       <options options="INVALID"/>""");
+                       op2.deserialize (doc8);
+                       if (op2.options != OptionsEnum.SelectBefore)  {
+                         stdout.printf (@"ERROR: Bad value to options property: $(op2.options)\n$(doc8)");
+                         assert_not_reached ();
+                       }
+                     }
+                     catch (GLib.Error e) {
+                       stdout.printf (@"Error: $(e.message)");
+                       assert_not_reached ();
+                     }
+                   });
+  }
+}
\ No newline at end of file
diff --git a/test/GXmlTest.vala b/test/GXmlTest.vala
index bd2ceea..148eafa 100644
--- a/test/GXmlTest.vala
+++ b/test/GXmlTest.vala
@@ -44,6 +44,7 @@ class GXmlTest {
                SerializableGeeArrayListTest.add_tests ();
                SerializableGeeCollectionsTest.add_tests ();
                SerializableBasicTypeTest.add_tests ();
+               SerializableEnumerationTest.add_tests ();
 
                Test.run ();
 
diff --git a/test/Makefile.am b/test/Makefile.am
index 5ce9369..50a00bf 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -59,7 +59,7 @@ gxml_test_VALAFLAGS = \
        --pkg gio-2.0 \
        --pkg gee-0.8 \
        --pkg posix \
-       --pkg gxml \
+       --pkg gxml-0.4 \
        --pkg libxml-2.0 \
        -X -DTEST_DIR=$(top_srcdir)/test \
        $(NULL)
@@ -71,7 +71,7 @@ gxml_test_LDADD = \
        $(GXML_LIBS) \
        $(LIBXML_LIBS) \
        $(GIO_LIBS) \
-       -L$(top_srcdir)/gxml -lgxml \
+       -L$(top_srcdir)/gxml -lgxml-0.4 \
        $(NULL)
 
 gxml_test_LDFLAGS = $(AM_LDFLAGS)


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