[glom] Add a test that resaves (temporarily) all examples and checks the result.



commit ae46add8e81c41f9e924553ed70908f65f6a304a
Author: Murray Cumming <murrayc murrayc com>
Date:   Tue Dec 6 22:45:01 2011 +0100

    Add a test that resaves (temporarily) all examples and checks the result.
    
    	* Makefile_tests.am:
    	* tests/test_document_load_and_save.cc: Load a file and save it,
    	then check the saved file against the DTD.
    	* tests/test_document_load_and_save_all.sh: Run that test on all
    	example files.
    	* glom/glom_document.dtd: data_layout_notebook: Mention trans_set,
    	so that this test succeeds.

 ChangeLog                                |   12 +++
 Makefile_tests.am                        |    9 ++-
 glom/glom_document.dtd                   |    2 +-
 tests/test_document_load_and_save.cc     |  126 ++++++++++++++++++++++++++++++
 tests/test_document_load_and_save_all.sh |    6 ++
 5 files changed, 153 insertions(+), 2 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index d9fec6a..0a99355 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,17 @@
 2011-12-06  Murray Cumming  <murrayc murrayc com>
 
+	Add a test that resaves (temporarily) all examples and checks the result.
+
+	* Makefile_tests.am:
+	* tests/test_document_load_and_save.cc: Load a file and save it, 
+	then check the saved file against the DTD.
+	* tests/test_document_load_and_save_all.sh: Run that test on all
+	example files.
+	* glom/glom_document.dtd: data_layout_notebook: Mention trans_set, 
+	so that this test succeeds.
+
+2011-12-06  Murray Cumming  <murrayc murrayc com>
+
 	Use EXIT_* instead of 0 and -1.
 
 	* glom/test_pyembed.cc:
diff --git a/Makefile_tests.am b/Makefile_tests.am
index b8e62ca..700b550 100644
--- a/Makefile_tests.am
+++ b/Makefile_tests.am
@@ -24,6 +24,7 @@ check_PROGRAMS =						\
 	glom/libglom/test_sharedptr_layoutitem		\
 	tests/test_document_load			\
 	tests/test_document_load_and_change		\
+	tests/test_document_load_and_save		\
 	tests/test_document_load_translations		\
 	tests/test_document_change			\
 	tests/test_document_autosave			\
@@ -49,6 +50,7 @@ check_PROGRAMS =						\
 
 TESTS =	tests/test_document_load	\
 	tests/test_document_load_and_change	\
+	tests/test_document_load_and_save_all.sh \
 	tests/test_document_load_translations	\
 	tests/test_document_change	\
 	tests/test_document_autosave	\
@@ -82,7 +84,8 @@ dist_noinst_SCRIPTS = tests/test_dtd_file_validation.sh \
 	tests/test_glade_file_validation.sh \
 	tests/test_xslt_file_validation.sh \
 	tests/test_glade_toplevels_instantiation.sh \
-	tests/test_glom_date_in_locales.sh
+	tests/test_glom_date_in_locales.sh \
+	tests/test_document_load_and_save_all.sh
 
 #TESTS_ENVIRONMENT=which valgrind && valgrind --tool=memcheck --leak-check=full --leak-resolution=high --trace-children=yes --num-callers=30
 
@@ -110,6 +113,10 @@ tests_test_document_load_and_change_SOURCES = tests/test_document_load_and_chang
 tests_test_document_load_and_change_LDADD = $(tests_ldadd)
 tests_test_document_load_and_change_CPPFLAGS = $(tests_cppflags)
 
+tests_test_document_load_and_save_SOURCES = tests/test_document_load_and_save.cc
+tests_test_document_load_and_save_LDADD = $(tests_ldadd)
+tests_test_document_load_and_save_CPPFLAGS = $(tests_cppflags)
+
 tests_test_document_load_translations_SOURCES = tests/test_document_load_translations.cc
 tests_test_document_load_translations_LDADD = $(tests_ldadd)
 tests_test_document_load_translations_CPPFLAGS = $(tests_cppflags)
diff --git a/glom/glom_document.dtd b/glom/glom_document.dtd
index e035376..bfd1f14 100644
--- a/glom/glom_document.dtd
+++ b/glom/glom_document.dtd
@@ -225,7 +225,7 @@ TODO: Should we specify the presence of child text nodes in the ELEMENT somehow?
 
 <!-- A data_layout_notebook is the tabbed display of tables in the details view. -->
 
-    <!ELEMENT data_layout_notebook (data_layout_group*, data_layout_portal*)>
+    <!ELEMENT data_layout_notebook (trans_set?, data_layout_group*, data_layout_portal*)>
     <!ATTLIST data_layout_notebook
         name CDATA #REQUIRED
         columns_count CDATA #IMPLIED
diff --git a/tests/test_document_load_and_save.cc b/tests/test_document_load_and_save.cc
new file mode 100644
index 0000000..ae7d49a
--- /dev/null
+++ b/tests/test_document_load_and_save.cc
@@ -0,0 +1,126 @@
+/* Glom
+ *
+ * Copyright (C) 2010 Openismus GmbH
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 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
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+71 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include <libglom/document/document.h>
+#include <libglom/init.h>
+#include <libglom/utils.h>
+#include <glibmm/convert.h>
+#include <glibmm/miscutils.h>
+
+#include <iostream>
+
+
+static bool validate_glom_file(const Glib::ustring& uri, const std::string& dtd_filepath)
+{
+  std::string filepath;
+
+  try
+  {
+    filepath = Glib::filename_from_uri(uri);
+  }
+  catch(const Glib::ConvertError& ex)
+  {
+    std::cerr << G_STRFUNC << ": Could not convert uri to filepath: " << ex.what();
+    return false;
+  }
+
+  try
+  {
+    xmlpp::DomParser parser;
+    //parser.set_validate();
+    parser.set_substitute_entities(); //We just want the text to be resolved/unescaped automatically.
+    parser.parse_file(filepath);
+    if(!parser)
+      return false;
+
+    xmlpp::DtdValidator validator(dtd_filepath);
+    validator.validate(parser.get_document());
+  }
+  catch(const xmlpp::validity_error& ex)
+  {
+    std::cerr << "Exception caught while validating file: " << ex.what() << std::endl;
+    std::cerr << "  uri: " << uri << std::endl;
+    return false;
+  }
+  catch(const xmlpp::parse_error& ex)
+  {
+    std::cerr << "Exception caught while validating file: " << ex.what() << std::endl;
+    std::cerr << "  uri: " << uri << std::endl;
+    return false;
+  }
+
+  return true;
+}
+
+int main(int argc, char* argv[])
+{
+  Glom::libglom_init();
+
+  if(argc <= 2 )
+  {
+    std::cerr << "Usage: test_document_load_and_save filepath dtd_filepath" << std::endl;
+    return EXIT_FAILURE;
+  }
+
+  //Get a URI (file://something) from the filepath:
+  Glib::RefPtr<Gio::File> file = Gio::File::create_for_commandline_arg(argv[1]);
+  const Glib::ustring uri = file->get_uri();
+
+  const std::string dtd_filepath = argv[2];
+
+  //Validate the original document, though the test_dtd_file_validation.sh test does this anyway:
+  if(!validate_glom_file(uri, dtd_filepath))
+    return EXIT_FAILURE;
+  
+
+  // Load the document:
+  Glom::Document document;
+  document.set_file_uri(uri);
+  int failure_code = 0;
+  const bool loaded = document.load(failure_code);
+  //std::cout << "Document load result=" << test << std::endl;
+
+  if(!loaded)
+  {
+    std::cerr << "Document::load() failed with failure_code=" << failure_code << std::endl;
+    return EXIT_FAILURE;
+  }
+
+  // Save the document:
+  document.set_allow_autosave(false);
+  const Glib::ustring temp_uri = 
+    Glom::Utils::get_temp_file_uri("testglom_document", ".glom");
+  document.set_file_uri(temp_uri);
+  document.set_modified(); //TODO: Let save() succeed without this.
+  const bool saved = document.save();
+  if(!saved)
+  {
+    std::cerr << "Document::save() failed." << std::endl;
+    return EXIT_FAILURE;
+  }
+
+  //Validate the saved document:
+  if(!validate_glom_file(temp_uri, dtd_filepath))
+    return EXIT_FAILURE;
+
+  Glom::libglom_deinit();
+
+  return EXIT_SUCCESS;
+}
diff --git a/tests/test_document_load_and_save_all.sh b/tests/test_document_load_and_save_all.sh
new file mode 100755
index 0000000..11c94ad
--- /dev/null
+++ b/tests/test_document_load_and_save_all.sh
@@ -0,0 +1,6 @@
+#/bin/sh -e
+
+for x in $(find ${srcdir}/examples/ -name "*.glom")
+do
+  tests/test_document_load_and_save $x ${srcdir}/glom/glom_document.dtd || exit 1
+done



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