Add test for g_get_language_names

This commit is contained in:
Matthias Clasen 2010-05-08 20:58:10 -04:00
parent e8bc8c6cbf
commit c13c36e3b9
2 changed files with 87 additions and 0 deletions

View File

@ -53,6 +53,9 @@ gvariant_LDADD = $(progs_ldadd)
TEST_PROGS += mem-overflow
mem_overflow_LDADD = $(progs_ldadd)
TEST_PROGS += utils
utils_LDADD = $(progs_ldadd)
if OS_UNIX
# some testing of gtester funcitonality

84
glib/tests/utils.c Normal file
View File

@ -0,0 +1,84 @@
/* Unit tests for utilities
* Copyright (C) 2010 Red Hat, Inc.
*
* This work is provided "as is"; redistribution and modification
* in whole or in part, in any medium, physical or electronic is
* permitted without restriction.
*
* This work is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* In no event shall the authors or contributors be liable for any
* direct, indirect, incidental, special, exemplary, or consequential
* damages (including, but not limited to, procurement of substitute
* goods or services; loss of use, data, or profits; or business
* interruption) however caused and on any theory of liability, whether
* in contract, strict liability, or tort (including negligence or
* otherwise) arising in any way out of the use of this software, even
* if advised of the possibility of such damage.
*
* Author: Matthias Clasen
*/
#include "glib.h"
#include <stdarg.h>
static gboolean
strv_check (const gchar * const *strv, ...)
{
va_list args;
gchar *s;
gint i;
va_start (args, strv);
for (i = 0; strv[i]; i++)
{
s = va_arg (args, gchar*);
if (g_strcmp0 (strv[i], s) != 0)
{
va_end (args);
return FALSE;
}
}
va_end (args);
return TRUE;
}
static void
test_language_names (void)
{
const gchar * const *names;
g_setenv ("LANGUAGE", "de:en_US", TRUE);
names = g_get_language_names ();
g_assert (strv_check (names, "de", "en_US", "en", "C", NULL));
g_setenv ("LANGUAGE", "tt_RU.UTF-8@iqtelif", TRUE);
names = g_get_language_names ();
g_assert (strv_check (names,
"tt_RU.UTF-8@iqtelif",
"tt_RU@iqtelif",
"tt.UTF-8@iqtelif",
"tt@iqtelif",
"tt_RU.UTF-8",
"tt_RU",
"tt.UTF-8",
"tt",
"C",
NULL));
}
int
main (int argc,
char *argv[])
{
g_test_init (&argc, &argv, NULL);
g_test_add_func ("/utils/language-names", test_language_names);
return g_test_run();
}