[evolution-data-server/gnome-3-8] LC_ADDRESS is a GNU extension. Treat it as such.



commit 0076314596c1c0315884a181b9ae9daa21d38840
Author: Matthew Barnes <mbarnes redhat com>
Date:   Wed Apr 17 10:37:13 2013 -0400

    LC_ADDRESS is a GNU extension. Treat it as such.
    
    Unconditional use of the GNU extension LC_ADDRESS causes compiler
    errors on non-GNU systems.
    
    In test cases, use LC_MESSAGES if LC_ADDRESS is unavailable.
    Also fail gracefully with a log message if setlocale() fails.
    
    (cherry picked from commit 6a440ebb07a846ba40920c746bfb846992d6133a)

 addressbook/libebook-contacts/e-book-query.c       |   9 +-
 tests/libebook-contacts/test-phone-number.c        |  19 +++-
 tests/libebook-contacts/test-query.c               | 107 ++++++++++++---------
 tests/libebook/client/test-client-custom-summary.c |   3 +
 4 files changed, 88 insertions(+), 50 deletions(-)
---
diff --git a/addressbook/libebook-contacts/e-book-query.c b/addressbook/libebook-contacts/e-book-query.c
index 0ec2e6d..2a8ecb1 100644
--- a/addressbook/libebook-contacts/e-book-query.c
+++ b/addressbook/libebook-contacts/e-book-query.c
@@ -200,7 +200,14 @@ e_book_query_not (EBookQuery *q,
 static const gchar *
 address_locale (void)
 {
-       const gchar *locale = setlocale (LC_ADDRESS, NULL);
+       const gchar *locale;
+
+#if defined (LC_ADDRESS)
+       /* LC_ADDRESS is a GNU extension. */
+       locale = setlocale (LC_ADDRESS, NULL);
+#else
+       locale = NULL;
+#endif
 
        if (locale == NULL || strcmp (locale, "C") == 0)
                locale = setlocale (LC_MESSAGES, NULL);
diff --git a/tests/libebook-contacts/test-phone-number.c b/tests/libebook-contacts/test-phone-number.c
index bfa74f1..ac1a9e4 100644
--- a/tests/libebook-contacts/test-phone-number.c
+++ b/tests/libebook-contacts/test-phone-number.c
@@ -26,6 +26,15 @@
 #include <libebook-contacts/libebook-contacts.h>
 #include <locale.h>
 
+/* Pick a locale category to set and test. */
+#ifdef LC_ADDRESS
+/* LC_ADDRESS is a GNU extension. */
+#define CATEGORY LC_ADDRESS
+#else
+/* Mimic the fallback branch in EBookQuery. */
+#define CATEGORY LC_MESSAGES
+#endif /* LC_ADDRESS */
+
 static const gchar *match_candidates[] = {
        "not-a-number",
        "+1-617-4663489", "617-4663489", "4663489",
@@ -342,7 +351,7 @@ test_country_code_for_region (void)
        GError *error = NULL;
        gint code;
 
-       g_assert_cmpstr (setlocale (LC_ADDRESS, NULL), ==, "en_US.UTF-8");
+       g_assert_cmpstr (setlocale (CATEGORY, NULL), ==, "en_US.UTF-8");
 
 #ifdef ENABLE_PHONENUMBER
 
@@ -381,7 +390,7 @@ test_default_region (void)
        GError *error = NULL;
        gchar *country;
 
-       g_assert_cmpstr (setlocale (LC_ADDRESS, NULL), ==, "en_US.UTF-8");
+       g_assert_cmpstr (setlocale (CATEGORY, NULL), ==, "en_US.UTF-8");
        country = e_phone_number_get_default_region (&error);
 
 #ifdef ENABLE_PHONENUMBER
@@ -408,7 +417,11 @@ main (gint argc,
 {
        size_t i, j;
 
-       setlocale (LC_ALL, "en_US.UTF-8");
+       if (setlocale (LC_ALL, "en_US.UTF-8") == NULL) {
+               g_message ("Failed to set locale to en_US.UTF-8");
+               g_message ("Skipping all /ebook-phone-number/* tests");
+               return 0;
+       }
 
        g_type_init ();
 
diff --git a/tests/libebook-contacts/test-query.c b/tests/libebook-contacts/test-query.c
index dff9520..41a21df 100644
--- a/tests/libebook-contacts/test-query.c
+++ b/tests/libebook-contacts/test-query.c
@@ -6,6 +6,15 @@
 #define QUERY_STRING1
 #define QUERY_STRING2
 
+/* Pick a locale category to set and test. */
+#ifdef LC_ADDRESS
+/* LC_ADDRESS is a GNU extension. */
+#define CATEGORY LC_ADDRESS
+#else
+/* Mimic the fallback branch in EBookQuery. */
+#define CATEGORY LC_MESSAGES
+#endif /* LC_ADDRESS */
+
 typedef struct {
        EBookQuery *query;
        gchar *locale;
@@ -37,7 +46,7 @@ test_query (gconstpointer data)
        EBookQuery *query;
        gchar *sexp;
 
-       setlocale (LC_ADDRESS, test->locale);
+       g_assert (setlocale (CATEGORY, test->locale) != NULL);
        sexp = e_book_query_to_string (test->query);
        normalize_space (sexp);
 
@@ -74,7 +83,7 @@ add_query_test (const gchar *path,
 {
        TestData *data = g_slice_new (TestData);
 
-       data->locale = g_strdup (setlocale (LC_ADDRESS, NULL));
+       data->locale = g_strdup (setlocale (CATEGORY, NULL));
        data->sexp = g_strdup (sexp);
        data->query = query;
 
@@ -90,8 +99,6 @@ main (gint argc,
        g_test_init (&argc, &argv, NULL);
        g_test_bug_base ("http://bugzilla.gnome.org/";);
 
-       setlocale (LC_ADDRESS, "en_US.UTF-8");
-
        add_query_test (
                "/libebook/test-query/sexp/all",
                e_book_query_any_field_contains (NULL),
@@ -166,49 +173,57 @@ main (gint argc,
                        "5423789"),
                "(endswith \"phone\" \"5423789\")");
 
-       add_query_test (
-               "/libebook/test-query/sexp/eqphone/us",
-               e_book_query_orv (
-                       e_book_query_field_test (
-                               E_CONTACT_TEL,
-                               E_BOOK_QUERY_EQUALS_PHONE_NUMBER,
-                               "+1-2215423789"),
-                       e_book_query_field_test (
-                               E_CONTACT_TEL,
-                               E_BOOK_QUERY_EQUALS_NATIONAL_PHONE_NUMBER,
-                               "2215423789"),
-                       e_book_query_field_test (
-                               E_CONTACT_TEL,
-                               E_BOOK_QUERY_EQUALS_SHORT_PHONE_NUMBER,
-                               "5423789"),
-                               NULL),
-               "(or (eqphone \"phone\" \"+1-2215423789\" \"en_US.UTF-8\")"
-               " (eqphone_national \"phone\" \"2215423789\" \"en_US.UTF-8\")"
-               " (eqphone_short \"phone\" \"5423789\" \"en_US.UTF-8\")"
-               " )");
-
-       setlocale (LC_ADDRESS, "en_GB.UTF-8");
+       if (setlocale (CATEGORY, "en_US.UTF-8") != NULL) {
+               add_query_test (
+                       "/libebook/test-query/sexp/eqphone/us",
+                       e_book_query_orv (
+                               e_book_query_field_test (
+                                       E_CONTACT_TEL,
+                                       E_BOOK_QUERY_EQUALS_PHONE_NUMBER,
+                                       "+1-2215423789"),
+                               e_book_query_field_test (
+                                       E_CONTACT_TEL,
+                                       E_BOOK_QUERY_EQUALS_NATIONAL_PHONE_NUMBER,
+                                       "2215423789"),
+                               e_book_query_field_test (
+                                       E_CONTACT_TEL,
+                                       E_BOOK_QUERY_EQUALS_SHORT_PHONE_NUMBER,
+                                       "5423789"),
+                                       NULL),
+                       "(or (eqphone \"phone\" \"+1-2215423789\" \"en_US.UTF-8\")"
+                       " (eqphone_national \"phone\" \"2215423789\" \"en_US.UTF-8\")"
+                       " (eqphone_short \"phone\" \"5423789\" \"en_US.UTF-8\")"
+                       " )");
+       } else {
+               g_message ("Failed to set locale to en_US.UTF-8");
+               g_message ("Skipping /libebook/test-query/sexp/eqphone/us");
+       }
 
-       add_query_test (
-               "/libebook/test-query/sexp/eqphone/gb",
-               e_book_query_orv (
-                       e_book_query_field_test (
-                               E_CONTACT_TEL,
-                               E_BOOK_QUERY_EQUALS_PHONE_NUMBER,
-                               "+1-2215423789"),
-                       e_book_query_field_test (
-                               E_CONTACT_TEL,
-                               E_BOOK_QUERY_EQUALS_NATIONAL_PHONE_NUMBER,
-                               "2215423789"),
-                       e_book_query_field_test (
-                               E_CONTACT_TEL,
-                               E_BOOK_QUERY_EQUALS_SHORT_PHONE_NUMBER,
-                               "5423789"),
-                       NULL),
-               "(or (eqphone \"phone\" \"+1-2215423789\" \"en_GB.UTF-8\")"
-               " (eqphone_national \"phone\" \"2215423789\" \"en_GB.UTF-8\")"
-               " (eqphone_short \"phone\" \"5423789\" \"en_GB.UTF-8\")"
-               " )");
+       if (setlocale (CATEGORY, "en_GB.UTF-8") != NULL) {
+               add_query_test (
+                       "/libebook/test-query/sexp/eqphone/gb",
+                       e_book_query_orv (
+                               e_book_query_field_test (
+                                       E_CONTACT_TEL,
+                                       E_BOOK_QUERY_EQUALS_PHONE_NUMBER,
+                                       "+1-2215423789"),
+                               e_book_query_field_test (
+                                       E_CONTACT_TEL,
+                                       E_BOOK_QUERY_EQUALS_NATIONAL_PHONE_NUMBER,
+                                       "2215423789"),
+                               e_book_query_field_test (
+                                       E_CONTACT_TEL,
+                                       E_BOOK_QUERY_EQUALS_SHORT_PHONE_NUMBER,
+                                       "5423789"),
+                               NULL),
+                       "(or (eqphone \"phone\" \"+1-2215423789\" \"en_GB.UTF-8\")"
+                       " (eqphone_national \"phone\" \"2215423789\" \"en_GB.UTF-8\")"
+                       " (eqphone_short \"phone\" \"5423789\" \"en_GB.UTF-8\")"
+                       " )");
+       } else {
+               g_message ("Failed to set locale to en_GB.UTF-8");
+               g_message ("Skipping /libebook/test-query/sexp/eqphone/gb");
+       }
 
        return g_test_run ();
 }
diff --git a/tests/libebook/client/test-client-custom-summary.c 
b/tests/libebook/client/test-client-custom-summary.c
index bf1add3..d63c31c 100644
--- a/tests/libebook/client/test-client-custom-summary.c
+++ b/tests/libebook/client/test-client-custom-summary.c
@@ -343,7 +343,10 @@ main (gint argc,
        g_setenv ("LC_ALL", "en_US.UTF-8", TRUE);
        setlocale (LC_ALL, "");
 
+#if defined (LC_ADDRESS)
+       /* LC_ADDRESS is a GNU extension. */
        g_assert_cmpstr (setlocale (LC_ADDRESS, NULL), ==, "en_US.UTF-8");
+#endif
 
        /* Test all queries in 8 different combinations specified by the 'suites'
         */


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