[tepl] amtk: testsuite: test-utils



commit c1ceb400093b63227b38872695b72f23efb508af
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Thu Jul 13 15:38:31 2017 +0200

    amtk: testsuite: test-utils
    
    Start to put the unit tests of Amtk in a subdir, to better separate
    concerns.

 configure.ac                |    2 +-
 testsuite/Makefile.am       |    4 ++
 testsuite/amtk/test-utils.c |   92 +++++++++++++++++++++++++++++++++++++++++++
 testsuite/test-utils.c      |   62 -----------------------------
 4 files changed, 97 insertions(+), 63 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 579c41a..8b5f10f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -60,7 +60,7 @@ AC_CONFIG_HEADER([config.h])
 AC_CONFIG_MACRO_DIR([m4])
 
 # gnu strictness to generate the INSTALL file
-AM_INIT_AUTOMAKE([1.14 tar-ustar dist-xz no-dist-gzip gnu -Wno-portability])
+AM_INIT_AUTOMAKE([1.14 tar-ustar dist-xz no-dist-gzip gnu subdir-objects -Wno-portability])
 
 m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
 
diff --git a/testsuite/Makefile.am b/testsuite/Makefile.am
index a43c836..46f9325 100644
--- a/testsuite/Makefile.am
+++ b/testsuite/Makefile.am
@@ -18,12 +18,16 @@ AM_CPPFLAGS =                       \
 AM_LDFLAGS = $(WARN_LDFLAGS)
 
 LDADD = $(top_builddir)/tepl/libtepl-core.la   \
+       $(top_builddir)/amtk/libamtk.la         \
        $(DEP_LIBS)
 
 noinst_PROGRAMS = $(UNIT_TEST_PROGS)
 TESTS = $(UNIT_TEST_PROGS)
 UNIT_TEST_PROGS =
 
+UNIT_TEST_PROGS += amtk-test-utils
+amtk_test_utils_SOURCES = amtk/test-utils.c
+
 UNIT_TEST_PROGS += test-action-info-store
 test_action_info_store_SOURCES = test-action-info-store.c
 
diff --git a/testsuite/amtk/test-utils.c b/testsuite/amtk/test-utils.c
new file mode 100644
index 0000000..f590ef9
--- /dev/null
+++ b/testsuite/amtk/test-utils.c
@@ -0,0 +1,92 @@
+/*
+ * This file is part of Amtk - Actions, Menus and Toolbars Kit
+ *
+ * Copyright 2017 - Sébastien Wilmet <swilmet gnome org>
+ *
+ * Amtk is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the
+ * Free Software Foundation; either version 2.1 of the License, or (at your
+ * option) any later version.
+ *
+ * Amtk 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.  See the GNU Lesser General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "amtk/amtk-utils.h"
+
+static void
+check_strv_equal (const gchar * const *strv1,
+                 const gchar * const *strv2)
+{
+       gint i;
+
+       if (strv1 == NULL || strv2 == NULL)
+       {
+               g_assert (strv1 == NULL && strv2 == NULL);
+               return;
+       }
+
+       for (i = 0; strv1[i] != NULL && strv2[i] != NULL; i++)
+       {
+               g_assert_cmpstr (strv1[i], ==, strv2[i]);
+       }
+
+       g_assert (strv1[i] == NULL);
+       g_assert (strv2[i] == NULL);
+}
+
+static void
+test_strv_copy (void)
+{
+       const gchar *stack_strv_empty[] = { NULL };
+       const gchar *stack_strv_nonempty[] = { "a", "b", NULL };
+       GPtrArray *ptr_array;
+       gchar **heap_strv;
+       gchar **strv_copy;
+
+       /* NULL */
+       strv_copy = _amtk_utils_strv_copy (NULL);
+       g_assert (strv_copy == NULL);
+
+       /* Empty */
+       strv_copy = _amtk_utils_strv_copy (stack_strv_empty);
+       check_strv_equal (stack_strv_empty, (const gchar * const *)strv_copy);
+       g_strfreev (strv_copy);
+
+       /* Non-empty */
+       strv_copy = _amtk_utils_strv_copy (stack_strv_nonempty);
+       check_strv_equal (stack_strv_nonempty, (const gchar * const *)strv_copy);
+       g_strfreev (strv_copy);
+
+       /* Created from a GPtrArray */
+       ptr_array = g_ptr_array_new ();
+       g_ptr_array_add (ptr_array, g_strdup (""));
+       g_ptr_array_add (ptr_array, g_strdup ("non-empty"));
+       g_ptr_array_add (ptr_array, g_strdup ("bathory"));
+       g_ptr_array_add (ptr_array, NULL);
+
+       heap_strv = (gchar **)g_ptr_array_free (ptr_array, FALSE);
+
+       strv_copy = _amtk_utils_strv_copy ((const gchar * const *)heap_strv);
+       check_strv_equal ((const gchar * const *)heap_strv,
+                         (const gchar * const *)strv_copy);
+       g_strfreev (strv_copy);
+
+       g_strfreev (heap_strv);
+}
+
+int
+main (int    argc,
+      char **argv)
+{
+       g_test_init (&argc, &argv, NULL);
+
+       g_test_add_func ("/utils/strv-copy", test_strv_copy);
+
+       return g_test_run ();
+}
diff --git a/testsuite/test-utils.c b/testsuite/test-utils.c
index a5324cf..84921a9 100644
--- a/testsuite/test-utils.c
+++ b/testsuite/test-utils.c
@@ -92,67 +92,6 @@ test_get_fallback_basename_for_display (void)
        g_free (basename);
 }
 
-static void
-check_strv_equal (const gchar * const *strv1,
-                 const gchar * const *strv2)
-{
-       gint i;
-
-       if (strv1 == NULL || strv2 == NULL)
-       {
-               g_assert (strv1 == NULL && strv2 == NULL);
-               return;
-       }
-
-       for (i = 0; strv1[i] != NULL && strv2[i] != NULL; i++)
-       {
-               g_assert_cmpstr (strv1[i], ==, strv2[i]);
-       }
-
-       g_assert (strv1[i] == NULL);
-       g_assert (strv2[i] == NULL);
-}
-
-static void
-test_strv_copy (void)
-{
-       const gchar *stack_strv_empty[] = { NULL };
-       const gchar *stack_strv_nonempty[] = { "a", "b", NULL };
-       GPtrArray *ptr_array;
-       gchar **heap_strv;
-       gchar **strv_copy;
-
-       /* NULL */
-       strv_copy = _tepl_utils_strv_copy (NULL);
-       g_assert (strv_copy == NULL);
-
-       /* Empty */
-       strv_copy = _tepl_utils_strv_copy (stack_strv_empty);
-       check_strv_equal (stack_strv_empty, (const gchar * const *)strv_copy);
-       g_strfreev (strv_copy);
-
-       /* Non-empty */
-       strv_copy = _tepl_utils_strv_copy (stack_strv_nonempty);
-       check_strv_equal (stack_strv_nonempty, (const gchar * const *)strv_copy);
-       g_strfreev (strv_copy);
-
-       /* Created from a GPtrArray */
-       ptr_array = g_ptr_array_new ();
-       g_ptr_array_add (ptr_array, g_strdup (""));
-       g_ptr_array_add (ptr_array, g_strdup ("non-empty"));
-       g_ptr_array_add (ptr_array, g_strdup ("bathory"));
-       g_ptr_array_add (ptr_array, NULL);
-
-       heap_strv = (gchar **)g_ptr_array_free (ptr_array, FALSE);
-
-       strv_copy = _tepl_utils_strv_copy ((const gchar * const *)heap_strv);
-       check_strv_equal ((const gchar * const *)heap_strv,
-                         (const gchar * const *)strv_copy);
-       g_strfreev (strv_copy);
-
-       g_strfreev (heap_strv);
-}
-
 gint
 main (gint    argc,
       gchar **argv)
@@ -162,7 +101,6 @@ main (gint    argc,
        g_test_add_func ("/utils/replace-home-dir-with-tilde", test_replace_home_dir_with_tilde);
        g_test_add_func ("/utils/decode-uri", test_decode_uri);
        g_test_add_func ("/utils/get-fallback-basename-for-display", test_get_fallback_basename_for_display);
-       g_test_add_func ("/utils/strv-copy", test_strv_copy);
 
        return g_test_run ();
 }


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