[gnome-builder] tests: port more tests to IdeApplication
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] tests: port more tests to IdeApplication
- Date: Thu, 14 Jan 2016 03:35:11 +0000 (UTC)
commit ed0ed095c4bcae1286377ccaf7bbbf893ad2d651
Author: Christian Hergert <chergert redhat com>
Date: Wed Jan 13 19:34:51 2016 -0800
tests: port more tests to IdeApplication
libide/ide.h | 1 +
tests/Makefile.am | 24 +--
tests/test-ide-indenter.c | 206 ++++--------
tests/test-ide-source-view.c | 783 ------------------------------------------
tests/test-slider.c | 112 ------
tests/test-vim.c | 134 ++++----
6 files changed, 138 insertions(+), 1122 deletions(-)
---
diff --git a/libide/ide.h b/libide/ide.h
index df2eb80..948fd8b 100644
--- a/libide/ide.h
+++ b/libide/ide.h
@@ -127,6 +127,7 @@ G_BEGIN_DECLS
#include "local/ide-local-device.h"
#include "search/ide-omni-search-row.h"
#include "util/ide-file-manager.h"
+#include "util/ide-gdk.h"
#include "util/ide-gtk.h"
#include "util/ide-line-reader.h"
#include "util/ide-list-inline.h"
diff --git a/tests/Makefile.am b/tests/Makefile.am
index d6d4dac..ecddf3a 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -64,6 +64,7 @@ TESTS_ENVIRONMENT= \
G_TEST_SRCDIR="$(abs_srcdir)" \
G_TEST_BUILDDIR="$(abs_builddir)" \
G_DEBUG=gc-friendly \
+ G_SETTINGS_BACKEND=memory \
GB_IN_TREE_PLUGINS=1 \
MALLOC_CHECK_=2 \
MALLOC_PERTURB_=$$(($${RANDOM:-256} % 256))
@@ -131,21 +132,8 @@ test_ide_vcs_uri_LDADD = $(tests_libs)
TESTS += test-vim
test_vim_SOURCES = test-vim.c
-test_vim_CFLAGS = \
- $(tests_cflags) \
- -I$(top_srcdir)/src/resources \
- -I$(top_builddir)/src/resources \
- $(NULL)
-test_vim_LDADD = \
- $(tests_libs) \
- $(top_builddir)/src/libgnome-builder.la \
- $(NULL)
-
-
-misc_programs += test-ide-source-view
-test_ide_source_view_SOURCES = test-ide-source-view.c
-test_ide_source_view_CFLAGS = $(tests_cflags)
-test_ide_source_view_LDADD = $(tests_libs)
+test_vim_CFLAGS = $(tests_cflags)
+test_vim_LDADD = $(tests_libs)
misc_programs += test-cpu-graph
@@ -160,12 +148,6 @@ test_fuzzy_CFLAGS = $(search_cflags)
test_fuzzy_LDADD = $(search_libs)
-misc_programs += test-slider
-test_slider_SOURCES = test-slider.c
-test_slider_CFLAGS = $(tests_cflags)
-test_slider_LDADD = $(tests_libs)
-
-
#TESTS += test-ide-ctags
#test_ide_ctags_SOURCES = test-ide-ctags.c
#test_ide_ctags_CFLAGS = $(tests_cflags)
diff --git a/tests/test-ide-indenter.c b/tests/test-ide-indenter.c
index 230f672..fc42951 100644
--- a/tests/test-ide-indenter.c
+++ b/tests/test-ide-indenter.c
@@ -20,172 +20,83 @@
#include <ide.h>
#include <string.h>
-#include "gb-plugins.h"
-#include "test-helper.h"
+#include "ide-application-tests.h"
typedef void (*IndentTestFunc) (IdeContext *context,
GtkWidget *widget);
-typedef struct
-{
+static void test_cindenter_basic_check (IdeContext *context,
+ GtkWidget *widget);
+
+struct {
+ const gchar *path;
IndentTestFunc func;
- gchar *path;
-} IndentTest;
+} indent_tests [] = {
+ { "test.c", test_cindenter_basic_check },
+ { NULL }
+};
static void
new_context_cb (GObject *object,
GAsyncResult *result,
gpointer user_data)
{
- IndentTest *test = user_data;
+ g_autoptr(GTask) task = user_data;
+ g_autoptr(IdeContext) context = NULL;
GtkWidget *window;
GtkWidget *widget;
IdeBuffer *buffer;
GtkSourceCompletion *completion;
- IdeContext *context;
IdeProject *project;
IdeFile *file;
GError *error = NULL;
- g_assert (test != NULL);
- g_assert (test->func != NULL);
- g_assert (test->path != NULL);
-
context = ide_context_new_finish (result, &error);
g_assert_no_error (error);
g_assert (context != NULL);
g_assert (IDE_IS_CONTEXT (context));
project = ide_context_get_project (context);
- file = ide_project_get_file_for_path (project, test->path);
- buffer = g_object_new (IDE_TYPE_BUFFER,
- "context", context,
- "file", file,
- NULL);
+ for (gint i = 0; indent_tests [i].path; i++)
+ {
+ file = ide_project_get_file_for_path (project, indent_tests [i].path);
- window = gtk_offscreen_window_new ();
- widget = g_object_new (IDE_TYPE_SOURCE_VIEW,
- "auto-indent", TRUE,
- "buffer", buffer,
- "visible", TRUE,
- NULL);
- gtk_container_add (GTK_CONTAINER (window), widget);
+ buffer = g_object_new (IDE_TYPE_BUFFER,
+ "context", context,
+ "file", file,
+ NULL);
- completion = gtk_source_view_get_completion (GTK_SOURCE_VIEW (widget));
- gtk_source_completion_block_interactive (completion);
+ window = gtk_offscreen_window_new ();
+ widget = g_object_new (IDE_TYPE_SOURCE_VIEW,
+ "auto-indent", TRUE,
+ "buffer", buffer,
+ "visible", TRUE,
+ NULL);
+ gtk_container_add (GTK_CONTAINER (window), widget);
- gtk_window_present (GTK_WINDOW (window));
+ completion = gtk_source_view_get_completion (GTK_SOURCE_VIEW (widget));
+ gtk_source_completion_block_interactive (completion);
- while (gtk_events_pending ())
- gtk_main_iteration ();
+ gtk_window_present (GTK_WINDOW (window));
- test->func (context, widget);
+ while (gtk_events_pending ())
+ gtk_main_iteration ();
+
+ indent_tests [i].func (context, widget);
#if 0
- ide_context_unload_async (context,
- NULL,
- (GAsyncReadyCallback)gtk_main_quit,
- NULL);
+ ide_context_unload_async (context,
+ NULL,
+ (GAsyncReadyCallback)gtk_main_quit,
+ NULL);
#else
- gtk_main_quit ();
+ gtk_main_quit ();
#endif
- g_object_unref (buffer);
- g_object_unref (file);
- g_free (test->path);
- g_free (test);
-}
-
-static void
-run_test (const gchar *path,
- IndentTestFunc func)
-{
- g_autoptr(GFile) project_file = NULL;
- IndentTest *test;
-
- test = g_new0 (IndentTest, 1);
- test->path = g_strdup (path);
- test->func = func;
-
- project_file = g_file_new_for_path (TEST_DATA_DIR"/project1/configure.ac");
- ide_context_new_async (project_file,
- NULL,
- new_context_cb,
- test);
-
- gtk_main ();
-}
-
-static GdkEventKey *
-synthesize_event (GtkTextView *text_view,
- gunichar ch)
-{
- GdkDisplay *display;
- GdkDeviceManager *device_manager;
- GdkDevice *client_pointer;
- GdkWindow *window;
- GdkEvent *ev;
- GdkKeymapKey *keys = NULL;
- gint n_keys = 0;
- gchar str[8] = { 0 };
-
- window = gtk_text_view_get_window (text_view, GTK_TEXT_WINDOW_TEXT);
- g_assert (window != NULL);
- g_assert (GDK_IS_WINDOW (window));
-
- g_unichar_to_utf8 (ch, str);
-
- ev = gdk_event_new (GDK_KEY_PRESS);
- ev->key.window = g_object_ref (window);
- ev->key.send_event = TRUE;
- ev->key.time = gtk_get_current_event_time ();
- ev->key.state = 0;
- ev->key.hardware_keycode = 0;
- ev->key.group = 0;
- ev->key.is_modifier = 0;
-
- switch (ch)
- {
- case '\n':
- ev->key.keyval = GDK_KEY_Return;
- ev->key.string = g_strdup ("\n");
- ev->key.length = 1;
- break;
-
- case '\e':
- ev->key.keyval = GDK_KEY_Escape;
- ev->key.string = g_strdup ("");
- ev->key.length = 0;
- break;
-
- default:
- ev->key.keyval = gdk_unicode_to_keyval (ch);
- ev->key.length = strlen (str);
- ev->key.string = g_strdup (str);
- break;
+ g_object_unref (buffer);
+ g_object_unref (file);
}
-
- gdk_keymap_get_entries_for_keyval (gdk_keymap_get_default (),
- ev->key.keyval,
- &keys,
- &n_keys);
-
- if (n_keys > 0)
- {
- ev->key.hardware_keycode = keys [0].keycode;
- ev->key.group = keys [0].group;
- if (keys [0].level == 1)
- ev->key.state |= GDK_SHIFT_MASK;
- g_free (keys);
- }
-
- display = gdk_window_get_display (ev->any.window);
- device_manager = gdk_display_get_device_manager (display);
- client_pointer = gdk_device_manager_get_client_pointer (device_manager);
- gdk_event_set_device (ev, gdk_device_get_associated_device (client_pointer));
-
- return &ev->key;
}
/*
@@ -202,12 +113,15 @@ assert_keypress_equal (GtkWidget *widget,
GtkTextBuffer *buffer;
GtkTextIter begin;
GtkTextIter end;
+ GdkWindow *window;
g_assert (GTK_IS_TEXT_VIEW (widget));
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (widget));
g_assert (GTK_IS_TEXT_BUFFER (buffer));
+ window = gtk_widget_get_window (GTK_WIDGET (text_view));
+
for (; *input_chars; input_chars = g_utf8_next_char (input_chars))
{
gunichar ch = g_utf8_get_char (input_chars);
@@ -216,7 +130,7 @@ assert_keypress_equal (GtkWidget *widget,
while (gtk_events_pending ())
gtk_main_iteration ();
- event = synthesize_event (text_view, ch);
+ event = ide_gdk_synthesize_event_key (window, ch);
gtk_main_do_event ((GdkEvent *)event);
gdk_event_free ((GdkEvent *)event);
}
@@ -230,8 +144,8 @@ assert_keypress_equal (GtkWidget *widget,
}
static void
-test_cindenter_basic_cb (IdeContext *context,
- GtkWidget *widget)
+test_cindenter_basic_check (IdeContext *context,
+ GtkWidget *widget)
{
g_object_set (widget,
"insert-matching-brace", TRUE,
@@ -247,18 +161,34 @@ test_cindenter_basic_cb (IdeContext *context,
}
static void
-test_cindenter_basic (void)
+test_cindenter_basic (GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
{
- test_helper_begin_test ();
+ g_autoptr(GFile) project_file = NULL;
+ GTask *task;
- run_test ("test.c", test_cindenter_basic_cb);
+ task = g_task_new (NULL, cancellable, callback, user_data);
+ project_file = g_file_new_for_path (TEST_DATA_DIR"/project1/configure.ac");
+ ide_context_new_async (project_file, NULL, new_context_cb, task);
}
gint
main (gint argc,
gchar *argv[])
{
- test_helper_init (&argc, &argv);
- g_test_add_func ("/Ide/CIndenter/basic", test_cindenter_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/CIndenter/basic", test_cindenter_basic, NULL);
+ ret = g_application_run (G_APPLICATION (app), argc, argv);
+ g_object_unref (app);
+
+ return ret;
}
diff --git a/tests/test-vim.c b/tests/test-vim.c
index 3cf2476..ba9b6e0 100644
--- a/tests/test-vim.c
+++ b/tests/test-vim.c
@@ -19,26 +19,42 @@
#include <ide.h>
#include <string.h>
-#include "gb-plugins.h"
-#include "gb-resources.h"
-#include "test-helper.h"
+#include "ide-application-tests.h"
#include "util/ide-gdk.h"
typedef void (*VimTestFunc) (IdeContext *context,
GtkWidget *widget);
-typedef struct
-{
+static void test_vim_basic_cb (IdeContext *context,
+ GtkWidget *widget);
+
+struct {
+ const gchar *path;
VimTestFunc func;
- gchar *path;
-} VimTest;
+} vim_tests [] = {
+ { "test.c", test_vim_basic_cb },
+ { NULL }
+};
+
+static void
+load_vim_css (void)
+{
+ GtkCssProvider *provider;
+
+ provider = gtk_css_provider_new ();
+ gtk_css_provider_load_from_resource (provider, "/org/gnome/builder/keybindings/vim.css");
+ gtk_style_context_add_provider_for_screen (gdk_screen_get_default (),
+ GTK_STYLE_PROVIDER (provider),
+ GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
+ g_clear_object (&provider);
+}
static void
new_context_cb (GObject *object,
GAsyncResult *result,
gpointer user_data)
{
- VimTest *test = user_data;
+ g_autoptr(GTask) test = user_data;
GtkWidget *window;
GtkWidget *widget;
IdeBuffer *buffer;
@@ -48,40 +64,40 @@ new_context_cb (GObject *object,
IdeFile *file;
GError *error = NULL;
- g_assert (test != NULL);
- g_assert (test->func != NULL);
- g_assert (test->path != NULL);
-
context = ide_context_new_finish (result, &error);
g_assert_no_error (error);
g_assert (context != NULL);
g_assert (IDE_IS_CONTEXT (context));
project = ide_context_get_project (context);
- file = ide_project_get_file_for_path (project, test->path);
- buffer = g_object_new (IDE_TYPE_BUFFER,
- "context", context,
- "file", file,
- NULL);
+ for (gint i = 0; vim_tests [i].path; i++)
+ {
+ file = ide_project_get_file_for_path (project, vim_tests [i].path);
- window = gtk_offscreen_window_new ();
- widget = g_object_new (IDE_TYPE_SOURCE_VIEW,
- "auto-indent", TRUE,
- "buffer", buffer,
- "visible", TRUE,
- NULL);
- gtk_container_add (GTK_CONTAINER (window), widget);
+ buffer = g_object_new (IDE_TYPE_BUFFER,
+ "context", context,
+ "file", file,
+ NULL);
- completion = gtk_source_view_get_completion (GTK_SOURCE_VIEW (widget));
- gtk_source_completion_block_interactive (completion);
+ window = gtk_offscreen_window_new ();
+ widget = g_object_new (IDE_TYPE_SOURCE_VIEW,
+ "auto-indent", TRUE,
+ "buffer", buffer,
+ "visible", TRUE,
+ NULL);
+ gtk_container_add (GTK_CONTAINER (window), widget);
- gtk_window_present (GTK_WINDOW (window));
+ completion = gtk_source_view_get_completion (GTK_SOURCE_VIEW (widget));
+ gtk_source_completion_block_interactive (completion);
- while (gtk_events_pending ())
- gtk_main_iteration ();
+ gtk_window_present (GTK_WINDOW (window));
- test->func (context, widget);
+ while (gtk_events_pending ())
+ gtk_main_iteration ();
+
+ vim_tests [i].func (context, widget);
+ }
#if 0
ide_context_unload_async (context,
@@ -91,31 +107,25 @@ new_context_cb (GObject *object,
#else
gtk_main_quit ();
#endif
-
- g_object_unref (buffer);
- g_object_unref (file);
- g_free (test->path);
- g_free (test);
}
static void
-run_test (const gchar *path,
- VimTestFunc func)
+test_vim_basic (GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
{
g_autoptr(GFile) project_file = NULL;
- VimTest *test;
+ GTask *task;
- test = g_new0 (VimTest, 1);
- test->path = g_strdup (path);
- test->func = func;
+ load_vim_css ();
+ task = g_task_new (NULL, cancellable, callback, user_data);
project_file = g_file_new_for_path (TEST_DATA_DIR"/project1/configure.ac");
ide_context_new_async (project_file,
NULL,
new_context_cb,
- test);
+ task);
- gtk_main ();
}
/*
@@ -187,34 +197,22 @@ test_vim_basic_cb (IdeContext *context,
#endif
}
-static void
-test_vim_basic (void)
+gint
+main (gint argc,
+ gchar *argv[])
{
- test_helper_begin_test ();
- run_test ("test.c", test_vim_basic_cb);
-}
+ IdeApplication *app;
+ gint ret;
-static void
-load_vim_css (void)
-{
- GtkCssProvider *provider;
+ g_test_init (&argc, &argv, NULL);
- g_resources_register (gb_get_resource ());
+ ide_log_init (TRUE, NULL);
+ ide_log_set_verbosity (4);
- provider = gtk_css_provider_new ();
- gtk_css_provider_load_from_resource (provider, "/org/gnome/builder/keybindings/vim.css");
- gtk_style_context_add_provider_for_screen (gdk_screen_get_default (),
- GTK_STYLE_PROVIDER (provider),
- GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
- g_clear_object (&provider);
-}
+ app = ide_application_new ();
+ ide_application_add_test (app, "/Ide/Vim/basic", test_vim_basic, NULL);
+ ret = g_application_run (G_APPLICATION (app), argc, argv);
+ g_object_unref (app);
-gint
-main (gint argc,
- gchar *argv[])
-{
- test_helper_init (&argc, &argv);
- load_vim_css ();
- g_test_add_func ("/Ide/Vim/basic", test_vim_basic);
- return g_test_run ();
+ return ret;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]