Add test for g_get_language_names
authorMatthias Clasen <mclasen@redhat.com>
Sun, 9 May 2010 00:58:10 +0000 (20:58 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Sun, 9 May 2010 00:58:10 +0000 (20:58 -0400)
glib/tests/Makefile.am
glib/tests/utils.c [new file with mode: 0644]

index 1b0d940..f619189 100644 (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
diff --git a/glib/tests/utils.c b/glib/tests/utils.c
new file mode 100644 (file)
index 0000000..7613d03
--- /dev/null
@@ -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();
+}