[gnome-builder] tests: port more tests
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] tests: port more tests
- Date: Thu, 14 Jan 2016 00:11:13 +0000 (UTC)
commit 1ca9aa9ba72c578ae97e54a014fc394b2bea03e1
Author: Christian Hergert <chergert redhat com>
Date: Wed Jan 13 16:11:05 2016 -0800
tests: port more tests
tests/Makefile.am | 22 +++----
tests/test-helper.c | 48 --------------
tests/test-helper.h | 27 --------
tests/test-ide-back-forward-list.c | 127 +++++++++++++++---------------------
tests/test-ide-context.c | 97 ++++++++++++++--------------
5 files changed, 110 insertions(+), 211 deletions(-)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 32532cd..d6d4dac 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -56,10 +56,6 @@ tests_ldflags = \
-export-dynamic \
$(NULL)
-test_files = \
- test-helper.c \
- test-helper.h
-
misc_programs =
TESTS_ENVIRONMENT= \
@@ -75,50 +71,50 @@ TESTS_ENVIRONMENT= \
LOG_COMPILER = $(top_srcdir)/build/autotools/tap-test
TESTS = test-ide-context
-test_ide_context_SOURCES = test-ide-context.c $(test_files)
+test_ide_context_SOURCES = test-ide-context.c
test_ide_context_CFLAGS = $(tests_cflags)
test_ide_context_LDADD = $(tests_libs)
test_ide_context_LDFLAGS = $(tests_ldflags)
TESTS += test-ide-back-forward-list
-test_ide_back_forward_list_SOURCES = test-ide-back-forward-list.c $(test_files)
+test_ide_back_forward_list_SOURCES = test-ide-back-forward-list.c
test_ide_back_forward_list_CFLAGS = $(tests_cflags)
test_ide_back_forward_list_LDADD = $(tests_libs)
TESTS += test-ide-buffer-manager
-test_ide_buffer_manager_SOURCES = test-ide-buffer-manager.c $(test_files)
+test_ide_buffer_manager_SOURCES = test-ide-buffer-manager.c
test_ide_buffer_manager_CFLAGS = $(tests_cflags)
test_ide_buffer_manager_LDADD = $(tests_libs)
TESTS += test-ide-buffer
-test_ide_buffer_SOURCES = test-ide-buffer.c $(test_files)
+test_ide_buffer_SOURCES = test-ide-buffer.c
test_ide_buffer_CFLAGS = $(tests_cflags)
test_ide_buffer_LDADD = $(tests_libs)
TESTS += test-ide-doap
-test_ide_doap_SOURCES = test-ide-doap.c $(test_files)
+test_ide_doap_SOURCES = test-ide-doap.c
test_ide_doap_CFLAGS = $(tests_cflags)
test_ide_doap_LDADD = $(tests_libs)
TESTS += test-ide-file-settings
-test_ide_file_settings_SOURCES = test-ide-file-settings.c $(test_files)
+test_ide_file_settings_SOURCES = test-ide-file-settings.c
test_ide_file_settings_CFLAGS = $(tests_cflags)
test_ide_file_settings_LDADD = $(tests_libs)
TESTS += test-ide-indenter
-test_ide_indenter_SOURCES = test-ide-indenter.c $(test_files)
+test_ide_indenter_SOURCES = test-ide-indenter.c
test_ide_indenter_CFLAGS = $(tests_cflags)
test_ide_indenter_LDADD = $(tests_libs)
TESTS += test-ide-vcs-uri
-test_ide_vcs_uri_SOURCES = test-ide-vcs-uri.c $(test_files)
+test_ide_vcs_uri_SOURCES = test-ide-vcs-uri.c
test_ide_vcs_uri_CFLAGS = $(tests_cflags)
test_ide_vcs_uri_LDADD = $(tests_libs)
@@ -134,7 +130,7 @@ test_ide_vcs_uri_LDADD = $(tests_libs)
TESTS += test-vim
-test_vim_SOURCES = test-vim.c $(test_files)
+test_vim_SOURCES = test-vim.c
test_vim_CFLAGS = \
$(tests_cflags) \
-I$(top_srcdir)/src/resources \
diff --git a/tests/test-ide-back-forward-list.c b/tests/test-ide-back-forward-list.c
index 685ad80..f76e172 100644
--- a/tests/test-ide-back-forward-list.c
+++ b/tests/test-ide-back-forward-list.c
@@ -17,10 +17,10 @@
*/
#include <glib.h>
+#include <stdlib.h>
#include <ide.h>
-#include "gb-plugins.h"
-#include "test-helper.h"
+#include "ide-application-tests.h"
typedef struct
{
@@ -31,65 +31,46 @@ typedef struct
} test_state_t;
static IdeBackForwardItem *
-parse_item (test_state_t *state,
- const gchar *str)
+parse_item (IdeContext *context,
+ const gchar *str)
{
IdeBackForwardItem *ret;
- IdeSourceLocation *location;
- IdeFile *file;
- gchar **parts;
- GFile *gfile;
+ IdeUri *uri;
+ GError *error = NULL;
- parts = g_strsplit (str, " ", 0);
-
- if (g_strv_length (parts) != 4)
- {
- g_strfreev (parts);
- return NULL;
- }
-
- gfile = g_file_new_for_path (parts [0]);
-
- file = g_object_new (IDE_TYPE_FILE,
- "context", state->context,
- "file", gfile,
- NULL);
-
- location = ide_source_location_new (file,
- atoi (parts[1]),
- atoi(parts[2]),
- atoi(parts[3]));
+ uri = ide_uri_new (str, 0, &error);
+ g_assert_no_error (error);
+ g_assert (uri != NULL);
ret = g_object_new (IDE_TYPE_BACK_FORWARD_ITEM,
- "context", state->context,
- "location", location,
+ "context", context,
+ "uri", uri,
NULL);
- g_clear_object (&gfile);
- g_clear_object (&file);
- g_strfreev (parts);
+ g_clear_pointer (&uri, ide_uri_unref);
return ret;
}
static void
-exercise1 (test_state_t *state,
- IdeBackForwardList *list)
+exercise1 (IdeBackForwardList *list)
{
+ IdeContext *context;
const gchar *items[] = {
- "test.c 10 10 100",
- "test.c 20 10 200",
- "test.h 0 0 0",
- "test.c 1 2 3",
- "test.h 1 2 3",
+ "file:///home/christian/Projects/gnome-builder/libide/template/ide-template-state.c#L120_43",
+ "file:///home/christian/Projects/gnome-builder/libide/template/ide-template.h#L35_0",
+ "file:///home/christian/Projects/gnome-builder/libide/template/ide-template-parser.h#L29_0",
+ "file:///home/christian/Projects/%20spaces/foo#L30_1",
};
gsize i;
+ context = ide_object_get_context (IDE_OBJECT (list));
+
for (i = 0; i < G_N_ELEMENTS (items); i++)
{
IdeBackForwardItem *item;
- item = parse_item (state, items [i]);
+ item = parse_item (context, items [i]);
ide_back_forward_list_push (list, item);
g_assert (item == ide_back_forward_list_get_current_item (list));
g_assert (!ide_back_forward_list_get_can_go_forward (list));
@@ -126,56 +107,54 @@ test_basic_cb (GObject *object,
GAsyncResult *result,
gpointer user_data)
{
- test_state_t *state = user_data;
+ IdeBackForwardList *list;
+ IdeContext *context;
+ g_autoptr(GTask) task = user_data;
+ GError *error = NULL;
- state->context = ide_context_new_finish (result, &state->error);
+ context = ide_context_new_finish (result, &error);
+ g_assert_no_error (error);
+ g_assert (context != NULL);
- if (state->context)
- {
- IdeBackForwardList *list;
+ list = ide_context_get_back_forward_list (context);
+ exercise1 (list);
- list = ide_context_get_back_forward_list (state->context);
- exercise1 (state, list);
- }
+ g_task_return_boolean (task, TRUE);
- g_main_loop_quit (state->main_loop);
+ g_object_unref (context);
}
static void
-test_basic (void)
+test_basic (GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
{
- test_state_t state = { 0 };
- GFile *project_file;
g_autofree gchar *path = NULL;
-
- test_helper_begin_test ();
+ GFile *project_file;
+ GTask *task;
path = g_build_filename (g_get_current_dir (), TEST_DATA_DIR, "project1", "configure.ac", NULL);
project_file = g_file_new_for_path (path);
-
- state.main_loop = g_main_loop_new (NULL, FALSE);
- state.cancellable = g_cancellable_new ();
-
- ide_context_new_async (project_file, state.cancellable,
- test_basic_cb, &state);
-
- g_main_loop_run (state.main_loop);
-
- g_assert_no_error (state.error);
- g_assert (IDE_IS_CONTEXT (state.context));
-
- g_main_loop_unref (state.main_loop);
- g_clear_object (&state.cancellable);
- g_clear_object (&state.context);
- g_clear_object (&project_file);
- g_clear_error (&state.error);
+ task = g_task_new (NULL, cancellable, callback, user_data);
+ ide_context_new_async (project_file, cancellable, test_basic_cb, task);
}
gint
main (gint argc,
gchar *argv[])
{
- test_helper_init (&argc, &argv);
- g_test_add_func ("/Ide/BackForwardList/basic", test_basic);
- return g_test_run ();
+ 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/BackForwardList/basic", test_basic, NULL);
+ ret = g_application_run (G_APPLICATION (app), argc, argv);
+ g_object_unref (app);
+
+ return ret;
}
diff --git a/tests/test-ide-context.c b/tests/test-ide-context.c
index e7a92c4..9f8d7be 100644
--- a/tests/test-ide-context.c
+++ b/tests/test-ide-context.c
@@ -18,76 +18,75 @@
#include <ide.h>
-#include "test-helper.h"
-
-typedef struct
-{
- GMainLoop *main_loop;
- IdeContext *context;
- GCancellable *cancellable;
- GError *error;
-} test_new_async_state;
+#include "ide-application-tests.h"
static void
test_new_async_cb1 (GObject *object,
GAsyncResult *result,
gpointer user_data)
{
- test_new_async_state *state = user_data;
- state->context = ide_context_new_finish (result, &state->error);
- g_main_loop_quit (state->main_loop);
+ const gchar *root_build_dir;
+ g_autoptr(GTask) task = user_data;
+ g_autoptr(IdeContext) context = NULL;
+ IdeVcs *vcs;
+ IdeBuildSystem *bs;
+ GError *error = NULL;
+
+ context = ide_context_new_finish (result, &error);
+ g_assert_no_error (error);
+ g_assert (context != NULL);
+
+ bs = ide_context_get_build_system (context);
+ g_assert_cmpstr (G_OBJECT_TYPE_NAME (bs), ==, "IdeAutotoolsBuildSystem");
+
+ vcs = ide_context_get_vcs (context);
+ g_assert_cmpstr (G_OBJECT_TYPE_NAME (vcs), ==, "IdeGitVcs");
+
+ root_build_dir = ide_context_get_root_build_dir (context);
+ g_print ("%s\n", root_build_dir);
+ g_assert (g_str_has_suffix (root_build_dir, "/libide/builds"));
+
+ g_task_return_boolean (task, TRUE);
}
static void
-test_new_async (void)
+test_new_async (GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
{
- test_new_async_state state = { 0 };
- IdeBuildSystem *bs;
- IdeVcs *vcs;
- GFile *project_file;
- const gchar *root_build_dir;
- const gchar *builddir;
g_autofree gchar *path = NULL;
-
- test_helper_begin_test ();
+ g_autoptr(GFile) project_file = NULL;
+ const gchar *builddir;
+ GTask *task;
builddir = g_getenv ("G_TEST_BUILDDIR");
+ task = g_task_new (NULL, cancellable, callback, user_data);
path = g_build_filename (builddir, "data", "project1", "configure.ac", NULL);
project_file = g_file_new_for_path (path);
- state.main_loop = g_main_loop_new (NULL, FALSE);
- state.cancellable = g_cancellable_new ();
-
- ide_context_new_async (project_file, state.cancellable,
- test_new_async_cb1, &state);
-
- g_main_loop_run (state.main_loop);
-
- g_assert_no_error (state.error);
- g_assert (state.context);
-
- bs = ide_context_get_build_system (state.context);
- g_assert_cmpstr (G_OBJECT_TYPE_NAME (bs), ==, "IdeAutotoolsBuildSystem");
-
- vcs = ide_context_get_vcs (state.context);
- g_assert_cmpstr (G_OBJECT_TYPE_NAME (vcs), ==, "IdeGitVcs");
-
- root_build_dir = ide_context_get_root_build_dir (state.context);
- g_assert (g_str_has_suffix (root_build_dir, "/libide/builds"));
-
- g_clear_object (&state.cancellable);
- g_clear_object (&state.context);
- g_clear_error (&state.error);
- g_main_loop_unref (state.main_loop);
- g_clear_object (&project_file);
+ ide_context_new_async (project_file,
+ cancellable,
+ test_new_async_cb1,
+ task);
}
gint
main (gint argc,
gchar *argv[])
{
- test_helper_init (&argc, &argv);
- g_test_add_func ("/Ide/Context/new_async", test_new_async);
- return g_test_run ();
+ 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/Context/new_async", test_new_async, 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]