[gnome-builder] tests: Add tests for IdeSubprocessLauncher
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] tests: Add tests for IdeSubprocessLauncher
- Date: Tue, 15 Nov 2016 07:19:17 +0000 (UTC)
commit 188f58dc504ac63e6e7df22c23a8cf41ad9b5be2
Author: Matthew Leeds <mleeds redhat com>
Date: Tue Nov 8 17:40:24 2016 -0600
tests: Add tests for IdeSubprocessLauncher
https://bugzilla.gnome.org/show_bug.cgi?id=773764
tests/Makefile.am | 6 ++
tests/test-ide-subprocess-launcher.c | 106 ++++++++++++++++++++++++++++++++++
2 files changed, 112 insertions(+), 0 deletions(-)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index fb76ec0..e53af5e 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -135,6 +135,12 @@ test_ide_indenter_CFLAGS = $(tests_cflags)
test_ide_indenter_LDADD = $(tests_libs)
+TESTS += test-ide-subprocess-launcher
+test_ide_subprocess_launcher_SOURCES = test-ide-subprocess-launcher.c
+test_ide_subprocess_launcher_CFLAGS = $(tests_cflags)
+test_ide_subprocess_launcher_LDADD = $(tests_libs)
+test_ide_subprocess_launcher_LDFLAGS = $(tests_ldflags)
+
TESTS += test-ide-vcs-uri
test_ide_vcs_uri_SOURCES = test-ide-vcs-uri.c
test_ide_vcs_uri_CFLAGS = $(tests_cflags)
diff --git a/tests/test-ide-subprocess-launcher.c b/tests/test-ide-subprocess-launcher.c
new file mode 100644
index 0000000..d6e7910
--- /dev/null
+++ b/tests/test-ide-subprocess-launcher.c
@@ -0,0 +1,106 @@
+/* test-ide-subprocess-launcher.c
+ *
+ * Copyright (C) 2016 Christian Hergert <chergert redhat com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <ide.h>
+
+static void
+test_basic (void)
+{
+ g_autoptr(IdeSubprocessLauncher) launcher = NULL;
+ g_autoptr(IdeSubprocess) process = NULL;
+ g_autoptr(GError) error = NULL;
+
+ launcher = ide_subprocess_launcher_new (0);
+ g_assert (launcher != NULL);
+
+ ide_subprocess_launcher_push_argv (launcher, "true");
+
+ process = ide_subprocess_launcher_spawn (launcher, NULL, &error);
+ g_assert (process != NULL);
+ g_assert (error == NULL);
+ g_assert_cmpint (ide_subprocess_wait_check (process, NULL, &error), !=, 0);
+}
+
+static int
+check_args (IdeSubprocessLauncher *launcher,
+ gchar *argv0,
+ ...)
+{
+ va_list args;
+ const gchar * const * actual_argv;
+ guint num_args;
+ gchar *item;
+
+ g_assert (IDE_IS_SUBPROCESS_LAUNCHER (launcher));
+
+ actual_argv = ide_subprocess_launcher_get_argv (launcher);
+
+ if (actual_argv == NULL && argv0 == NULL)
+ return 1;
+ else if (actual_argv == NULL || argv0 == NULL)
+ return 0;
+
+ num_args = 0;
+ if (g_strcmp0 (argv0, actual_argv[num_args++]) != 0)
+ return 0;
+
+ va_start (args, argv0);
+ while (NULL != (item = va_arg (args, gchar *)))
+ {
+ const gchar *next_arg = NULL;
+ next_arg = actual_argv[num_args++];
+ if (g_strcmp0 (next_arg, item) != 0)
+ return 0;
+ }
+ va_end (args);
+
+ if (actual_argv[num_args] == NULL)
+ return 1;
+ else
+ return 0;
+}
+
+static void
+test_argv_manipulation (void)
+{
+ g_autoptr(IdeSubprocessLauncher) launcher = NULL;
+
+ launcher = ide_subprocess_launcher_new (0);
+ g_assert (launcher != NULL);
+
+ ide_subprocess_launcher_push_argv (launcher, "echo");
+ ide_subprocess_launcher_push_argv (launcher, "world");
+ ide_subprocess_launcher_insert_argv (launcher, 1, "hello");
+ g_assert_cmpint (check_args (launcher, "echo", "hello", "world", NULL), !=, 0);
+
+ ide_subprocess_launcher_replace_argv (launcher, 2, "universe");
+ g_assert_cmpint (check_args (launcher, "echo", "hello", "universe", NULL), !=, 0);
+
+ g_assert_cmpstr (ide_subprocess_launcher_pop_argv (launcher), ==, "universe");
+ g_assert_cmpint (check_args (launcher, "echo", "hello", NULL), !=, 0);
+}
+
+gint
+main (gint argc,
+ gchar *argv[])
+{
+ g_test_init (&argc, &argv, NULL);
+ g_test_add_func ("/Ide/SubprocessLauncher/basic", test_basic);
+ g_test_add_func ("/Ide/SubprocessLauncher/argv-manipulation", test_argv_manipulation);
+ return g_test_run ();
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]