1 /* Unit tests for utilities
2 * Copyright (C) 2010 Red Hat, Inc.
4 * This work is provided "as is"; redistribution and modification
5 * in whole or in part, in any medium, physical or electronic is
6 * permitted without restriction.
8 * This work is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12 * In no event shall the authors or contributors be liable for any
13 * direct, indirect, incidental, special, exemplary, or consequential
14 * damages (including, but not limited to, procurement of substitute
15 * goods or services; loss of use, data, or profits; or business
16 * interruption) however caused and on any theory of liability, whether
17 * in contract, strict liability, or tort (including negligence or
18 * otherwise) arising in any way out of the use of this software, even
19 * if advised of the possibility of such damage.
21 * Author: Matthias Clasen
29 strv_check (const gchar * const *strv, ...)
35 va_start (args, strv);
36 for (i = 0; strv[i]; i++)
38 s = va_arg (args, gchar*);
39 if (g_strcmp0 (strv[i], s) != 0)
52 test_language_names (void)
54 const gchar * const *names;
56 g_setenv ("LANGUAGE", "de:en_US", TRUE);
57 names = g_get_language_names ();
58 g_assert (strv_check (names, "de", "en_US", "en", "C", NULL));
60 g_setenv ("LANGUAGE", "tt_RU.UTF-8@iqtelif", TRUE);
61 names = g_get_language_names ();
62 g_assert (strv_check (names,
63 "tt_RU.UTF-8@iqtelif",
78 g_print ("(header %d.%d.%d library %d.%d.%d) ",
79 GLIB_MAJOR_VERSION, GLIB_MINOR_VERSION, GLIB_MICRO_VERSION,
80 glib_major_version, glib_minor_version, glib_micro_version);
82 g_assert (glib_check_version (GLIB_MAJOR_VERSION,
84 GLIB_MICRO_VERSION) == NULL);
85 g_assert (glib_check_version (GLIB_MAJOR_VERSION,
88 g_assert (glib_check_version (GLIB_MAJOR_VERSION - 1,
91 g_assert (glib_check_version (GLIB_MAJOR_VERSION + 1,
94 g_assert (glib_check_version (GLIB_MAJOR_VERSION,
95 GLIB_MINOR_VERSION + 1,
97 /* don't use + 1 here, since a +/-1 difference can
98 * happen due to post-release version bumps in git
100 g_assert (glib_check_version (GLIB_MAJOR_VERSION,
102 GLIB_MICRO_VERSION + 3) != NULL);
105 static const gchar *argv0;
110 const gchar *prgname;
111 const gchar *appname;
113 prgname = g_get_prgname ();
114 appname = g_get_application_name ();
115 g_assert_cmpstr (prgname, ==, argv0);
116 g_assert_cmpstr (appname, ==, prgname);
118 g_set_prgname ("prgname");
120 prgname = g_get_prgname ();
121 appname = g_get_application_name ();
122 g_assert_cmpstr (prgname, ==, "prgname");
123 g_assert_cmpstr (appname, ==, "prgname");
125 g_set_application_name ("appname");
127 prgname = g_get_prgname ();
128 appname = g_get_application_name ();
129 g_assert_cmpstr (prgname, ==, "prgname");
130 g_assert_cmpstr (appname, ==, "appname");
136 g_test_bug ("627969");
137 g_assert_cmpstr (g_get_tmp_dir (), !=, "");
146 /* for tmpdir test, need to do this early before g_get_any_init */
147 g_setenv ("TMPDIR", "", TRUE);
151 g_test_init (&argc, &argv, NULL);
152 g_test_bug_base ("http://bugzilla.gnome.org/");
154 g_test_add_func ("/utils/language-names", test_language_names);
155 g_test_add_func ("/utils/version", test_version);
156 g_test_add_func ("/utils/appname", test_appname);
157 g_test_add_func ("/utils/tmpdir", test_tmpdir);