* tests: more gracefully deal with the case where there's no en_US.utf8 locale

This commit is contained in:
djcb
2012-03-08 00:11:31 +02:00
parent 0d3f1887da
commit 7fd81cc154
4 changed files with 86 additions and 43 deletions

View File

@ -1,6 +1,6 @@
/* -*- mode: c; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
**
** Copyright (C) 2008-2011 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
** Copyright (C) 2008-2012 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
**
** 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
@ -272,7 +272,8 @@ main (int argc, char *argv[])
int rv;
g_test_init (&argc, &argv, NULL);
setenv ("LC_ALL", "en_US.utf8", 1);
if (!set_en_us_utf8_locale())
return 0; /* don't error out... */
g_test_add_func ("/mu-cmd-cfind/test-mu-cfind-plain", test_mu_cfind_plain);
g_test_add_func ("/mu-cmd-cfind/test-mu-cfind-bbdb", test_mu_cfind_bbdb);
@ -295,4 +296,3 @@ main (int argc, char *argv[])
return rv;
}

View File

@ -754,7 +754,8 @@ main (int argc, char *argv[])
int rv;
g_test_init (&argc, &argv, NULL);
setenv ("LC_ALL", "en_US.utf8", 1);
if (!set_en_us_utf8_locale())
return 0; /* don't error out... */
g_test_add_func ("/mu-cmd/test-mu-index", test_mu_index);

View File

@ -1,5 +1,5 @@
/*
** Copyright (C) 2008-2010 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
** Copyright (C) 2008-2012 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
**
** 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
@ -28,6 +28,9 @@
#include <unistd.h>
#include <string.h>
#include <langinfo.h>
#include <locale.h>
#include "test-mu-common.h"
char*
@ -57,6 +60,24 @@ set_tz (const char* tz)
}
gboolean
set_en_us_utf8_locale (void)
{
setenv ("LC_ALL", "en_US.utf8", 1);
setlocale (LC_ALL, "en_US.utf8");
if (strcmp (nl_langinfo(CODESET), "UTF-8") != 0) {
g_print ("Note: Unit tests require the en_US.utf8 locale. "
"Ignoring test cases.");
return FALSE;
}
return TRUE;
}
void
black_hole (void)

View File

@ -1,5 +1,5 @@
/*
** Copyright (C) 2008-2010 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
** Copyright (C) 2008-2012 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
**
** 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
@ -31,10 +31,31 @@ G_BEGIN_DECLS
*/
char* test_mu_common_get_random_tmpdir (void);
/**
* set the output to /dev/null
*
*/
void black_hole (void);
/**
* set the timezone
*
* @param tz timezone
*
* @return the old timezone
*/
const char* set_tz (const char* tz);
/**
* switch the locale to en_US.utf8, return TRUE if it succeeds
*
* @return TRUE if the switch succeeds, FALSE otherwise
*/
gboolean set_en_us_utf8_locale (void);
G_END_DECLS
#endif /*__TEST_MU_COMMON_H__*/