[glib] Add test for g_get_language_names



commit c13c36e3b9db500e30055e616ffa52672281fc49
Author: Matthias Clasen <mclasen redhat com>
Date:   Sat May 8 20:58:10 2010 -0400

    Add test for g_get_language_names

 glib/tests/Makefile.am |    3 ++
 glib/tests/utils.c     |   84 ++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 87 insertions(+), 0 deletions(-)
---
diff --git a/glib/tests/Makefile.am b/glib/tests/Makefile.am
index 1b0d940..f619189 100644
--- a/glib/tests/Makefile.am
+++ b/glib/tests/Makefile.am
@@ -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
index 0000000..7613d03
--- /dev/null
+++ b/glib/tests/utils.c
@@ -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();
+}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]