[glom] tests_field_file_format: Set the locale and test several locales.



commit eca67c64f622a21ceb185039884250173e054934
Author: Murray Cumming <murrayc murrayc com>
Date:   Tue Dec 17 10:01:48 2013 +0100

    tests_field_file_format: Set the locale and test several locales.
    
    * Makefile_tests.am:
    * tests/test_field_file_format_in_locales.sh:
      Add a script that runs test_field_file_format in various locales,
      because GdaNumeric seems to be doing some locale-sensitive
      atof().
    * tests/test_field_file_format.cc: Use the current locale.

 Makefile_tests.am                          |   13 ++++++++-----
 tests/test_field_file_format.cc            |   18 ++++++++++++++++++
 tests/test_field_file_format_in_locales.sh |   27 +++++++++++++++++++++++++++
 3 files changed, 53 insertions(+), 5 deletions(-)
---
diff --git a/Makefile_tests.am b/Makefile_tests.am
index 08289b6..1fbc690 100644
--- a/Makefile_tests.am
+++ b/Makefile_tests.am
@@ -99,6 +99,7 @@ TESTS =       tests/test_document_load        \
        tests/test_selfhosting_sqlinjection \
        tests/test_conversions \
        tests/test_field_file_format \
+       tests/test_field_file_format_in_locales.sh \
        tests/test_xml_utils \
        tests/import/test_parsing \
        tests/import/test_signals \
@@ -114,7 +115,8 @@ dist_noinst_SCRIPTS = tests/test_dtd_file_validation.sh \
        tests/test_glade_toplevels_instantiation.sh \
        tests/test_glom_date_in_locales.sh.in \
        tests/test_selfhosting_new_from_example_in_locales.sh \
-       tests/test_document_load_and_save_all.sh
+       tests/test_document_load_and_save_all.sh \
+       tests/test_field_file_format_in_locales.sh
 
 #TESTS_ENVIRONMENT=which valgrind && valgrind --tool=memcheck --leak-check=full --leak-resolution=high 
--trace-children=yes --num-callers=30
 
@@ -379,14 +381,15 @@ TESTS += \
        tests/python/test_python_execute_script \
        tests/test_iso_codes
 
-# Note that test_glom_date_in_locales.sh requires us to have certain locales 
+# Note that the *_in_locales.sh tests require us to have certain locales 
 # installed and configured.
-# Also note: This is only in the UI tests because it use the glom executable,
-# and GtkApplication will not let us handle the command-line argument 
-# before initializing GTK+. See the comments in the code.
 
 # Some continuous-integration systems won't have an X server,
 # so they will want to disable these in configure.
+#
+# These are only in the UI tests because it use the glom executable,
+# and GtkApplication will not let us handle the command-line argument 
+# before initializing GTK+. See the comments in the code.
 if GLOM_ENABLE_UI_TESTS
 TESTS += \
        tests/test_glade_toplevels_instantiation.sh \
diff --git a/tests/test_field_file_format.cc b/tests/test_field_file_format.cc
index fa7878d..ec24c5b 100644
--- a/tests/test_field_file_format.cc
+++ b/tests/test_field_file_format.cc
@@ -49,6 +49,24 @@ static bool test_value(Glom::Field::glom_field_type field_type, const Gnome::Gda
 
 int main()
 {
+  // Set the locale for any streams to the user's current locale,
+  // We should not rely on the default locale of
+  // any streams (we should always do an explicit imbue()),
+  // but this is maybe a good default in case we forget.
+  try
+  {
+    std::locale::global(std::locale(""));
+  }
+  catch(const std::runtime_error& ex)
+  {
+    //This has been known to throw an exception at least once:
+    //https://bugzilla.gnome.org/show_bug.cgi?id=619445
+    //This should tell us what the problem is:
+    std::cerr << G_STRFUNC << ": exception from std::locale::global(std::locale(\"\")): " << ex.what() << 
std::endl;
+    std::cerr << G_STRFUNC << ":   This can happen if the locale is not properly installed or configured." 
<< std::endl;
+  }
+
+
   Glom::libglom_init();
 
   const Glib::ustring str = " Some value or other with a quote \" and leading space."; //Just to be awkward.
diff --git a/tests/test_field_file_format_in_locales.sh b/tests/test_field_file_format_in_locales.sh
new file mode 100755
index 0000000..e3ece7b
--- /dev/null
+++ b/tests/test_field_file_format_in_locales.sh
@@ -0,0 +1,27 @@
+#/bin/sh -e
+
+# This test checks that creating from examples works in non-English locales.
+# This would break if libgda uses locale-dependent code to convert between numbers
+# and internal text, for instance in GdaNumeric, as it has in the past.
+#
+# This test requires these locales to be installed and configured.
+# That might be a problem on some systems, so feel free to use a patch to edit this file or disable it 
altogether.
+#
+# These are chosen based on problems found previously,
+# and the ones with good translations shown here: http://l10n.gnome.org/module/glom/
+# TODO: Get a list from po/*.po ?
+#
+# On debian/Ubuntu do this: 
+#  sudo apt-get install language-pack-de language-pack-es language-pack-fi language-pack-fr language-pack-hu 
language-pack-it language-pack-pt language-pack-sl language-pack-da language-pack-cz language-pack-nb 
language-pack-se
+#
+# These are apparently not available on Fedora:  "da_DK.UTF-8" "cs_CZ.UTF-8" "nb_NO.UTF-8" "sv_SE.UTF-8"
+locales=("en_US.UTF-8" "en_GB.UTF-8" "en_CA.UTF-8" "de_DE.UTF-8" "es_ES.UTF-8" "fi_FI.UTF-8" "fr_FR.UTF-8" 
"hu_HU.UTF-8" "it_IT.UTF-8" "pt_PT.UTF-8" "pt_BR.UTF-8" "sl_SI.UTF-8" "da_DK.UTF-8" "cs_CZ.UTF-8" 
"nb_NO.UTF-8" "sv_SE.UTF-8")
+
+for x in "${locales[ ]}"
+do
+  echo testing with LANG and LANGUAGE="$x"
+  export LANG="$x"
+  export LANGUAGE="$x"
+  export LC_TIME="$x"
+  tests/test_field_file_format || exit 1
+done


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