[gnome-builder] tests: make context test more extensible
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] tests: make context test more extensible
- Date: Wed, 24 Jan 2018 04:29:03 +0000 (UTC)
commit 06e9337b4d5154da469136252c4ff179899c1bb9
Author: Christian Hergert <chergert redhat com>
Date: Tue Jan 23 20:19:05 2018 -0800
tests: make context test more extensible
We want to test more things, but the initializatoin makes things annoying.
So this lets us simplify that annoying part.
src/tests/test-ide-context.c | 57 +++++++++++++++++++++++++++++++-------------
1 file changed, 41 insertions(+), 16 deletions(-)
---
diff --git a/src/tests/test-ide-context.c b/src/tests/test-ide-context.c
index c57b45155..8f89dcd62 100644
--- a/src/tests/test-ide-context.c
+++ b/src/tests/test-ide-context.c
@@ -19,9 +19,11 @@
#include <ide.h>
#include "application/ide-application-tests.h"
-
#include "../plugins/gnome-builder-plugins.h"
+typedef gboolean (*TestCallback) (IdeContext *context,
+ GError **error);
+
static void
test_new_async_cb1 (GObject *object,
GAsyncResult *result,
@@ -29,9 +31,10 @@ test_new_async_cb1 (GObject *object,
{
g_autoptr(GTask) task = user_data;
g_autoptr(IdeContext) context = NULL;
- IdeVcs *vcs;
+ g_autoptr(GError) error = NULL;
+ TestCallback callback;
IdeBuildSystem *bs;
- GError *error = NULL;
+ IdeVcs *vcs;
context = ide_context_new_finish (result, &error);
g_assert_no_error (error);
@@ -43,35 +46,54 @@ test_new_async_cb1 (GObject *object,
vcs = ide_context_get_vcs (context);
g_assert_cmpstr (G_OBJECT_TYPE_NAME (vcs), ==, "IdeDirectoryVcs");
+ callback = g_task_get_task_data (task);
+
+ if (callback != NULL)
+ {
+ gboolean r = callback (context, &error);
+ g_assert_no_error (error);
+ g_assert_true (r);
+ }
+
g_task_return_boolean (task, TRUE);
}
static void
-test_new_async (GCancellable *cancellable,
- GAsyncReadyCallback callback,
- gpointer user_data)
+test_with_callback (TestCallback test_func,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
{
g_autofree gchar *path = NULL;
g_autoptr(GFile) project_file = NULL;
GTask *task;
+ /* user_data is a function callback or NULL, to
+ * execute after loading */
task = g_task_new (NULL, cancellable, callback, user_data);
+ g_task_set_task_data (task, test_func, NULL);
path = g_build_filename (TEST_DATA_DIR, "project1", "configure.ac", NULL);
project_file = g_file_new_for_path (path);
+ ide_context_new_async (project_file, cancellable, test_new_async_cb1, task);
+}
- ide_context_new_async (project_file,
- cancellable,
- test_new_async_cb1,
- task);
+#define ADD_TEST_FUNC(name, func) \
+static void \
+test_##name (GCancellable *cancellable, \
+ GAsyncReadyCallback callback, \
+ gpointer user_data) \
+{ \
+ test_with_callback (func, cancellable, callback, user_data); \
}
+ADD_TEST_FUNC (new_async, NULL)
+#undef ADD_TEST_FUNC
gint
main (gint argc,
gchar *argv[])
{
static const gchar *required_plugins[] = { "autotools-plugin", "directory-plugin", NULL };
- IdeApplication *app;
- gint ret;
+ g_autoptr(IdeApplication) app = NULL;
g_test_init (&argc, &argv, NULL);
@@ -79,10 +101,13 @@ main (gint argc,
ide_log_set_verbosity (4);
app = ide_application_new ();
- ide_application_add_test (app, "/Ide/Context/new_async", test_new_async, NULL, required_plugins);
+
+#define ADD_TEST_FUNC(name) \
+ ide_application_add_test (app, "/Ide/Context/"#name, test_##name, NULL, required_plugins);
+ADD_TEST_FUNC(new_async)
+#undef ADD_TEST_FUNC
+
gnome_builder_plugins_init ();
- ret = g_application_run (G_APPLICATION (app), argc, argv);
- g_object_unref (app);
- return ret;
+ return g_application_run (G_APPLICATION (app), argc, argv);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]