* tests: more gracefully deal with the case where there's no en_US.utf8 locale
This commit is contained in:
@ -1,6 +1,6 @@
|
|||||||
/* -*- mode: c; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
|
/* -*- 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
|
** 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
|
** under the terms of the GNU General Public License as published by the
|
||||||
@ -14,8 +14,8 @@
|
|||||||
**
|
**
|
||||||
** You should have received a copy of the GNU General Public License
|
** You should have received a copy of the GNU General Public License
|
||||||
** along with this program; if not, write to the Free Software Foundation,
|
** along with this program; if not, write to the Free Software Foundation,
|
||||||
** Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
** Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
**
|
**
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#if HAVE_CONFIG_H
|
#if HAVE_CONFIG_H
|
||||||
@ -38,16 +38,16 @@ static gchar*
|
|||||||
fill_contacts_cache (void)
|
fill_contacts_cache (void)
|
||||||
{
|
{
|
||||||
gchar *cmdline, *tmpdir;
|
gchar *cmdline, *tmpdir;
|
||||||
|
|
||||||
tmpdir = test_mu_common_get_random_tmpdir();
|
tmpdir = test_mu_common_get_random_tmpdir();
|
||||||
cmdline = g_strdup_printf ("%s index --muhome=%s --maildir=%s"
|
cmdline = g_strdup_printf ("%s index --muhome=%s --maildir=%s"
|
||||||
" --quiet",
|
" --quiet",
|
||||||
MU_PROGRAM, tmpdir, MU_TESTMAILDIR);
|
MU_PROGRAM, tmpdir, MU_TESTMAILDIR);
|
||||||
|
|
||||||
g_assert (g_spawn_command_line_sync (cmdline, NULL, NULL,
|
g_assert (g_spawn_command_line_sync (cmdline, NULL, NULL,
|
||||||
NULL, NULL));
|
NULL, NULL));
|
||||||
g_free (cmdline);
|
g_free (cmdline);
|
||||||
|
|
||||||
return tmpdir;
|
return tmpdir;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -56,14 +56,14 @@ static void
|
|||||||
test_mu_cfind_plain (void)
|
test_mu_cfind_plain (void)
|
||||||
{
|
{
|
||||||
gchar *muhome, *cmdline, *output, *erroutput;
|
gchar *muhome, *cmdline, *output, *erroutput;
|
||||||
|
|
||||||
muhome = fill_contacts_cache ();
|
muhome = fill_contacts_cache ();
|
||||||
g_assert (muhome != NULL);
|
g_assert (muhome != NULL);
|
||||||
|
|
||||||
cmdline = g_strdup_printf ("%s cfind --muhome=%s --format=plain "
|
cmdline = g_strdup_printf ("%s cfind --muhome=%s --format=plain "
|
||||||
"'testmu\\.xxx?'",
|
"'testmu\\.xxx?'",
|
||||||
MU_PROGRAM, muhome);
|
MU_PROGRAM, muhome);
|
||||||
|
|
||||||
output = erroutput = NULL;
|
output = erroutput = NULL;
|
||||||
g_assert (g_spawn_command_line_sync (cmdline, &output, &erroutput,
|
g_assert (g_spawn_command_line_sync (cmdline, &output, &erroutput,
|
||||||
NULL, NULL));
|
NULL, NULL));
|
||||||
@ -86,20 +86,20 @@ test_mu_cfind_bbdb (void)
|
|||||||
struct tm *tmtoday;
|
struct tm *tmtoday;
|
||||||
time_t now;
|
time_t now;
|
||||||
const char *old_tz;
|
const char *old_tz;
|
||||||
|
|
||||||
muhome = fill_contacts_cache ();
|
muhome = fill_contacts_cache ();
|
||||||
g_assert (muhome != NULL);
|
g_assert (muhome != NULL);
|
||||||
|
|
||||||
old_tz = set_tz ("Europe/Helsinki");
|
old_tz = set_tz ("Europe/Helsinki");
|
||||||
|
|
||||||
cmdline = g_strdup_printf ("%s cfind --muhome=%s --format=bbdb "
|
cmdline = g_strdup_printf ("%s cfind --muhome=%s --format=bbdb "
|
||||||
"'testmu\\.xxx?'",
|
"'testmu\\.xxx?'",
|
||||||
MU_PROGRAM, muhome);
|
MU_PROGRAM, muhome);
|
||||||
|
|
||||||
output = erroutput = NULL;
|
output = erroutput = NULL;
|
||||||
g_assert (g_spawn_command_line_sync (cmdline, &output, &erroutput,
|
g_assert (g_spawn_command_line_sync (cmdline, &output, &erroutput,
|
||||||
NULL, NULL));
|
NULL, NULL));
|
||||||
|
|
||||||
frm = ";; -*-coding: utf-8-emacs;-*-\n"
|
frm = ";; -*-coding: utf-8-emacs;-*-\n"
|
||||||
";;; file-version: 6\n"
|
";;; file-version: 6\n"
|
||||||
"[\"Helmut\" \"Kröger\" nil nil nil nil (\"hk@testmu.xxx\") "
|
"[\"Helmut\" \"Kröger\" nil nil nil nil (\"hk@testmu.xxx\") "
|
||||||
@ -112,10 +112,10 @@ test_mu_cfind_bbdb (void)
|
|||||||
now = time(NULL);
|
now = time(NULL);
|
||||||
tmtoday = localtime(&now);
|
tmtoday = localtime(&now);
|
||||||
strftime(today,sizeof(today),"%Y-%m-%d", tmtoday);
|
strftime(today,sizeof(today),"%Y-%m-%d", tmtoday);
|
||||||
expected = g_strdup_printf (frm, today, today);
|
expected = g_strdup_printf (frm, today, today);
|
||||||
|
|
||||||
/* g_print ("\n%s\n", output); */
|
/* g_print ("\n%s\n", output); */
|
||||||
|
|
||||||
g_assert_cmpstr (output, ==, expected);
|
g_assert_cmpstr (output, ==, expected);
|
||||||
|
|
||||||
g_free (cmdline);
|
g_free (cmdline);
|
||||||
@ -132,14 +132,14 @@ static void
|
|||||||
test_mu_cfind_wl (void)
|
test_mu_cfind_wl (void)
|
||||||
{
|
{
|
||||||
gchar *muhome, *cmdline, *output, *erroutput;
|
gchar *muhome, *cmdline, *output, *erroutput;
|
||||||
|
|
||||||
muhome = fill_contacts_cache ();
|
muhome = fill_contacts_cache ();
|
||||||
g_assert (muhome != NULL);
|
g_assert (muhome != NULL);
|
||||||
|
|
||||||
cmdline = g_strdup_printf ("%s cfind --muhome=%s --format=wl "
|
cmdline = g_strdup_printf ("%s cfind --muhome=%s --format=wl "
|
||||||
"'testmu\\.xxx?'",
|
"'testmu\\.xxx?'",
|
||||||
MU_PROGRAM, muhome);
|
MU_PROGRAM, muhome);
|
||||||
|
|
||||||
output = erroutput = NULL;
|
output = erroutput = NULL;
|
||||||
g_assert (g_spawn_command_line_sync (cmdline, &output, &erroutput,
|
g_assert (g_spawn_command_line_sync (cmdline, &output, &erroutput,
|
||||||
NULL, NULL));
|
NULL, NULL));
|
||||||
@ -158,14 +158,14 @@ static void
|
|||||||
test_mu_cfind_mutt_alias (void)
|
test_mu_cfind_mutt_alias (void)
|
||||||
{
|
{
|
||||||
gchar *muhome, *cmdline, *output, *erroutput;
|
gchar *muhome, *cmdline, *output, *erroutput;
|
||||||
|
|
||||||
muhome = fill_contacts_cache ();
|
muhome = fill_contacts_cache ();
|
||||||
g_assert (muhome != NULL);
|
g_assert (muhome != NULL);
|
||||||
|
|
||||||
cmdline = g_strdup_printf ("%s cfind --muhome=%s --format=mutt-alias "
|
cmdline = g_strdup_printf ("%s cfind --muhome=%s --format=mutt-alias "
|
||||||
"'testmu\\.xxx?'",
|
"'testmu\\.xxx?'",
|
||||||
MU_PROGRAM, muhome);
|
MU_PROGRAM, muhome);
|
||||||
|
|
||||||
output = erroutput = NULL;
|
output = erroutput = NULL;
|
||||||
g_assert (g_spawn_command_line_sync (cmdline, &output, &erroutput,
|
g_assert (g_spawn_command_line_sync (cmdline, &output, &erroutput,
|
||||||
NULL, NULL));
|
NULL, NULL));
|
||||||
@ -183,21 +183,21 @@ static void
|
|||||||
test_mu_cfind_mutt_ab (void)
|
test_mu_cfind_mutt_ab (void)
|
||||||
{
|
{
|
||||||
gchar *muhome, *cmdline, *output, *erroutput;
|
gchar *muhome, *cmdline, *output, *erroutput;
|
||||||
|
|
||||||
muhome = fill_contacts_cache ();
|
muhome = fill_contacts_cache ();
|
||||||
g_assert (muhome != NULL);
|
g_assert (muhome != NULL);
|
||||||
|
|
||||||
cmdline = g_strdup_printf ("%s cfind --muhome=%s --format=mutt-ab "
|
cmdline = g_strdup_printf ("%s cfind --muhome=%s --format=mutt-ab "
|
||||||
"'testmu\\.xxx?'",
|
"'testmu\\.xxx?'",
|
||||||
MU_PROGRAM, muhome);
|
MU_PROGRAM, muhome);
|
||||||
|
|
||||||
output = erroutput = NULL;
|
output = erroutput = NULL;
|
||||||
g_assert (g_spawn_command_line_sync (cmdline, &output, &erroutput,
|
g_assert (g_spawn_command_line_sync (cmdline, &output, &erroutput,
|
||||||
NULL, NULL));
|
NULL, NULL));
|
||||||
g_assert_cmpstr (output,
|
g_assert_cmpstr (output,
|
||||||
==,
|
==,
|
||||||
"Matching addresses in the mu database:\n"
|
"Matching addresses in the mu database:\n"
|
||||||
"hk@testmu.xxx\tHelmut Kröger\t\n"
|
"hk@testmu.xxx\tHelmut Kröger\t\n"
|
||||||
"testmu@testmu.xx\tMü\t\n");
|
"testmu@testmu.xx\tMü\t\n");
|
||||||
g_free (cmdline);
|
g_free (cmdline);
|
||||||
g_free (muhome);
|
g_free (muhome);
|
||||||
@ -210,14 +210,14 @@ static void
|
|||||||
test_mu_cfind_org_contact (void)
|
test_mu_cfind_org_contact (void)
|
||||||
{
|
{
|
||||||
gchar *muhome, *cmdline, *output, *erroutput;
|
gchar *muhome, *cmdline, *output, *erroutput;
|
||||||
|
|
||||||
muhome = fill_contacts_cache ();
|
muhome = fill_contacts_cache ();
|
||||||
g_assert (muhome != NULL);
|
g_assert (muhome != NULL);
|
||||||
|
|
||||||
cmdline = g_strdup_printf ("%s cfind --muhome=%s --format=org-contact "
|
cmdline = g_strdup_printf ("%s cfind --muhome=%s --format=org-contact "
|
||||||
"'testmu\\.xxx?'",
|
"'testmu\\.xxx?'",
|
||||||
MU_PROGRAM, muhome);
|
MU_PROGRAM, muhome);
|
||||||
|
|
||||||
output = erroutput = NULL;
|
output = erroutput = NULL;
|
||||||
g_assert (g_spawn_command_line_sync (cmdline, &output, &erroutput,
|
g_assert (g_spawn_command_line_sync (cmdline, &output, &erroutput,
|
||||||
NULL, NULL));
|
NULL, NULL));
|
||||||
@ -244,14 +244,14 @@ static void
|
|||||||
test_mu_cfind_csv (void)
|
test_mu_cfind_csv (void)
|
||||||
{
|
{
|
||||||
gchar *muhome, *cmdline, *output, *erroutput;
|
gchar *muhome, *cmdline, *output, *erroutput;
|
||||||
|
|
||||||
muhome = fill_contacts_cache ();
|
muhome = fill_contacts_cache ();
|
||||||
g_assert (muhome != NULL);
|
g_assert (muhome != NULL);
|
||||||
|
|
||||||
cmdline = g_strdup_printf ("%s cfind --muhome=%s --format=csv "
|
cmdline = g_strdup_printf ("%s cfind --muhome=%s --format=csv "
|
||||||
"'testmu\\.xxx?'",
|
"'testmu\\.xxx?'",
|
||||||
MU_PROGRAM, muhome);
|
MU_PROGRAM, muhome);
|
||||||
|
|
||||||
output = erroutput = NULL;
|
output = erroutput = NULL;
|
||||||
g_assert (g_spawn_command_line_sync (cmdline, &output, &erroutput,
|
g_assert (g_spawn_command_line_sync (cmdline, &output, &erroutput,
|
||||||
NULL, NULL));
|
NULL, NULL));
|
||||||
@ -272,8 +272,9 @@ main (int argc, char *argv[])
|
|||||||
int rv;
|
int rv;
|
||||||
g_test_init (&argc, &argv, NULL);
|
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-plain", test_mu_cfind_plain);
|
||||||
g_test_add_func ("/mu-cmd-cfind/test-mu-cfind-bbdb", test_mu_cfind_bbdb);
|
g_test_add_func ("/mu-cmd-cfind/test-mu-cfind-bbdb", test_mu_cfind_bbdb);
|
||||||
g_test_add_func ("/mu-cmd-cfind/test-mu-cfind-wl", test_mu_cfind_wl);
|
g_test_add_func ("/mu-cmd-cfind/test-mu-cfind-wl", test_mu_cfind_wl);
|
||||||
@ -285,7 +286,7 @@ main (int argc, char *argv[])
|
|||||||
test_mu_cfind_org_contact);
|
test_mu_cfind_org_contact);
|
||||||
g_test_add_func ("/mu-cmd-cfind/test-mu-cfind-csv",
|
g_test_add_func ("/mu-cmd-cfind/test-mu-cfind-csv",
|
||||||
test_mu_cfind_csv);
|
test_mu_cfind_csv);
|
||||||
|
|
||||||
g_log_set_handler (NULL,
|
g_log_set_handler (NULL,
|
||||||
G_LOG_LEVEL_MASK | G_LOG_LEVEL_WARNING|
|
G_LOG_LEVEL_MASK | G_LOG_LEVEL_WARNING|
|
||||||
G_LOG_FLAG_FATAL| G_LOG_FLAG_RECURSION,
|
G_LOG_FLAG_FATAL| G_LOG_FLAG_RECURSION,
|
||||||
@ -295,4 +296,3 @@ main (int argc, char *argv[])
|
|||||||
|
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -754,7 +754,8 @@ main (int argc, char *argv[])
|
|||||||
int rv;
|
int rv;
|
||||||
g_test_init (&argc, &argv, NULL);
|
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);
|
g_test_add_func ("/mu-cmd/test-mu-index", test_mu_index);
|
||||||
|
|
||||||
|
|||||||
@ -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
|
** 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
|
** under the terms of the GNU General Public License as published by the
|
||||||
@ -13,8 +13,8 @@
|
|||||||
**
|
**
|
||||||
** You should have received a copy of the GNU General Public License
|
** You should have received a copy of the GNU General Public License
|
||||||
** along with this program; if not, write to the Free Software Foundation,
|
** along with this program; if not, write to the Free Software Foundation,
|
||||||
** Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
** Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
**
|
**
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#if HAVE_CONFIG_H
|
#if HAVE_CONFIG_H
|
||||||
@ -28,6 +28,9 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
#include <langinfo.h>
|
||||||
|
#include <locale.h>
|
||||||
|
|
||||||
#include "test-mu-common.h"
|
#include "test-mu-common.h"
|
||||||
|
|
||||||
char*
|
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
|
void
|
||||||
black_hole (void)
|
black_hole (void)
|
||||||
|
|||||||
@ -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
|
** 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
|
** under the terms of the GNU General Public License as published by the
|
||||||
@ -13,8 +13,8 @@
|
|||||||
**
|
**
|
||||||
** You should have received a copy of the GNU General Public License
|
** You should have received a copy of the GNU General Public License
|
||||||
** along with this program; if not, write to the Free Software Foundation,
|
** along with this program; if not, write to the Free Software Foundation,
|
||||||
** Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
** Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
**
|
**
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef __TEST_MU_COMMON_H__
|
#ifndef __TEST_MU_COMMON_H__
|
||||||
@ -24,17 +24,38 @@
|
|||||||
|
|
||||||
G_BEGIN_DECLS
|
G_BEGIN_DECLS
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get a dir name for a random temporary directory to do tests
|
* get a dir name for a random temporary directory to do tests
|
||||||
*
|
*
|
||||||
* @return a random dir name, g_free when it's no longer needed
|
* @return a random dir name, g_free when it's no longer needed
|
||||||
*/
|
*/
|
||||||
char* test_mu_common_get_random_tmpdir (void);
|
char* test_mu_common_get_random_tmpdir (void);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* set the output to /dev/null
|
||||||
|
*
|
||||||
|
*/
|
||||||
void black_hole (void);
|
void black_hole (void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* set the timezone
|
||||||
|
*
|
||||||
|
* @param tz timezone
|
||||||
|
*
|
||||||
|
* @return the old timezone
|
||||||
|
*/
|
||||||
const char* set_tz (const char* tz);
|
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
|
G_END_DECLS
|
||||||
|
|
||||||
#endif /*__TEST_MU_COMMON_H__*/
|
#endif /*__TEST_MU_COMMON_H__*/
|
||||||
|
|||||||
Reference in New Issue
Block a user