summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMatthew Barnes <mbarnes@redhat.com>2013-04-17 10:37:13 -0400
committerMatthew Barnes <mbarnes@redhat.com>2013-04-17 13:00:37 -0400
commit6a440ebb07a846ba40920c746bfb846992d6133a (patch)
treedfcd8d7af3811b42ae0663bef4e8af08ef46b500 /tests
parent0342aecbfda8bea93726c63873dd61011deaab50 (diff)
downloadevolution-data-server-6a440ebb07a846ba40920c746bfb846992d6133a.tar.gz
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.
Diffstat (limited to 'tests')
-rw-r--r--tests/libebook-contacts/test-phone-number.c19
-rw-r--r--tests/libebook-contacts/test-query.c107
-rw-r--r--tests/libebook/client/test-client-custom-summary.c3
3 files changed, 80 insertions, 49 deletions
diff --git a/tests/libebook-contacts/test-phone-number.c b/tests/libebook-contacts/test-phone-number.c
index bfa74f1ca..ac1a9e4d1 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 dff95201a..41a21df0f 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 bf1add349..d63c31ce1 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'
*/