[gnome-builder/wip/chergert/pipeline-merge: 36/76] tests: add test for IdeBuildPipeline



commit f99c92cd6cdf6a1d7245f3be23d1b89efff9b6eb
Author: Christian Hergert <chergert redhat com>
Date:   Fri Feb 3 13:52:32 2017 -0800

    tests: add test for IdeBuildPipeline

 tests/Makefile.am               |    4 +
 tests/test-ide-build-pipeline.c |  117 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 121 insertions(+), 0 deletions(-)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 9dc144c..6273991 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -120,6 +120,10 @@ test_ide_buffer_CFLAGS = $(tests_cflags)
 test_ide_buffer_LDADD = $(tests_libs)
 
 
+TESTS += test-ide-build-pipeline
+test_ide_build_pipeline_SOURCES = test-ide-build-pipeline.c
+test_ide_build_pipeline_CFLAGS = $(tests_cflags)
+test_ide_build_pipeline_LDADD = $(tests_libs)
 
 
 TESTS += test-ide-doap
diff --git a/tests/test-ide-build-pipeline.c b/tests/test-ide-build-pipeline.c
new file mode 100644
index 0000000..fafa554
--- /dev/null
+++ b/tests/test-ide-build-pipeline.c
@@ -0,0 +1,117 @@
+/* test-ide-build-pipeline.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>
+
+#include "application/ide-application-tests.h"
+
+static void
+execute_cb (GObject      *object,
+            GAsyncResult *result,
+            gpointer      user_data)
+{
+  IdeBuildPipeline *pipeline = (IdeBuildPipeline *)object;
+  g_autoptr(GError) error = NULL;
+  g_autoptr(GTask) task = user_data;
+  gint r;
+
+  g_assert (IDE_IS_BUILD_PIPELINE (pipeline));
+
+  r = ide_build_pipeline_execute_finish (pipeline, result, &error);
+  g_assert_no_error (error);
+  g_assert_cmpint (r, ==, TRUE);
+
+  g_task_return_boolean (task, TRUE);
+}
+
+static void
+context_loaded (GObject      *object,
+                GAsyncResult *result,
+                gpointer      user_data)
+{
+  g_autoptr(GTask) task = user_data;
+  g_autoptr(IdeContext) context = NULL;
+  g_autoptr(GError) error = NULL;
+  g_autoptr(IdeBuildPipeline) pipeline = NULL;
+  IdeConfigurationManager *config_manager;
+  IdeConfiguration *config;
+
+  context = ide_context_new_finish (result, &error);
+  g_assert_no_error (error);
+  g_assert (context != NULL);
+  g_assert (IDE_IS_CONTEXT (context));
+
+  config_manager = ide_context_get_configuration_manager (context);
+  g_assert (IDE_IS_CONFIGURATION_MANAGER (config_manager));
+
+  config = ide_configuration_manager_get_current (config_manager);
+  g_assert (IDE_IS_CONFIGURATION (config));
+
+  pipeline = g_object_new (IDE_TYPE_BUILD_PIPELINE,
+                           "context", context,
+                           "configuration", config,
+                           NULL);
+
+  ide_build_pipeline_request_phase (pipeline, IDE_BUILD_PHASE_BUILD);
+
+  ide_build_pipeline_execute_async (pipeline,
+                                    NULL,
+                                    execute_cb,
+                                    g_steal_pointer (&task));
+}
+
+static void
+test_build_pipeline (GCancellable        *cancellable,
+                     GAsyncReadyCallback  callback,
+                     gpointer             user_data)
+{
+  g_autoptr(GFile) project_file = NULL;
+  g_autofree gchar *path = NULL;
+  const gchar *srcdir = g_getenv ("G_TEST_SRCDIR");
+  g_autoptr(GTask) task = NULL;
+
+  task = g_task_new (NULL, cancellable, callback, user_data);
+
+  path = g_build_filename (srcdir, "data", "project1", NULL);
+  project_file = g_file_new_for_path (path);
+
+  ide_context_new_async (project_file,
+                         cancellable,
+                         context_loaded,
+                         g_steal_pointer (&task));
+}
+
+gint
+main (gint   argc,
+      gchar *argv[])
+{
+  IdeApplication *app;
+  gint ret;
+
+  g_test_init (&argc, &argv, NULL);
+
+  ide_log_init (TRUE, NULL);
+  ide_log_set_verbosity (4);
+
+  app = ide_application_new ();
+  ide_application_add_test (app, "/Ide/BuildPipeline/basic", test_build_pipeline, NULL);
+  ret = g_application_run (G_APPLICATION (app), argc, argv);
+  g_object_unref (app);
+
+  return ret;
+}


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