From a7391693b23273dd58163cef1af3cb88f4690b13 Mon Sep 17 00:00:00 2001 From: Christian Dywan Date: Thu, 16 Jul 2009 23:49:10 +0200 Subject: [PATCH] Implement support for extension_test() to unit test extensions Any extension can provide an extension_test() function that is executed after g_test_init. Test functions should make use of g_test_add_func and friends to integrate with other tests. --- tests/extensions.c | 66 +++++++++++++++++++++++++++++++++++++++++++++ tests/wscript_build | 1 + 2 files changed, 67 insertions(+) diff --git a/tests/extensions.c b/tests/extensions.c index e71a353d..372eccf8 100644 --- a/tests/extensions.c +++ b/tests/extensions.c @@ -167,15 +167,81 @@ extension_settings (void) midori_extension_deactivate (extension); } +static void +extension_activate (gconstpointer data) +{ + MidoriApp* app = midori_app_new (); + MidoriExtension* extension = MIDORI_EXTENSION (data); + /* g_signal_emit_by_name (extension, "activate", app); + midori_extension_deactivate (extension); */ + g_object_unref (app); +} + +static void +load_extensions (void) +{ + if (g_module_supported ()) + { + GDir* extension_dir = g_dir_open (EXTENSION_PATH, 0, NULL); + if (extension_dir != NULL) + { + const gchar* filename; + + while ((filename = g_dir_read_name (extension_dir))) + { + gchar* fullname; + GModule* module; + typedef MidoriExtension* (*extension_init_func)(void); + extension_init_func extension_init; + + /* Ignore files which don't have the correct suffix */ + if (!g_str_has_suffix (filename, G_MODULE_SUFFIX)) + continue; + + fullname = g_build_filename (EXTENSION_PATH, filename, NULL); + module = g_module_open (fullname, G_MODULE_BIND_LOCAL); + g_free (fullname); + + if (module && g_module_symbol (module, "extension_init", + (gpointer) &extension_init)) + { + guint length; + gchar* name; + gchar* path; + typedef MidoriExtension* (*extension_test_func)(const gchar* path); + extension_test_func extension_test; + + if (g_str_has_prefix (filename, "lib")) + filename = &filename[3]; + length = strlen (filename); + name = g_strdup (filename); + name[length - strlen (G_MODULE_SUFFIX) - 1] = '\0'; + path = g_strconcat ("/extensions/", name, "/activate", NULL); + g_free (name); + g_test_add_data_func (path, extension_init (), extension_activate); + g_free (path); + if (g_module_symbol (module, "extension_test", + (gpointer) &extension_test)) + extension_test (path); + } + } + g_dir_close (extension_dir); + } + } +} + int main (int argc, char** argv) { g_test_init (&argc, &argv, NULL); gtk_init_check (&argc, &argv); + if (!g_thread_supported ()) g_thread_init (NULL); g_test_add_func ("/extensions/create", extension_create); g_test_add_func ("/extensions/settings", extension_settings); + load_extensions (); + return g_test_run (); } diff --git a/tests/wscript_build b/tests/wscript_build index 6d315f14..946ebbb6 100644 --- a/tests/wscript_build +++ b/tests/wscript_build @@ -26,6 +26,7 @@ for test in tests: obj = bld.new_task_gen ('cc', 'program') obj.target = 'test-' + target obj.includes = '.. ../midori ../panels' + obj.cflags = ['-DEXTENSION_PATH="' + os.path.abspath ('_build_/default/extensions') + '"'] obj.source = source obj.uselib = 'UNIQUE LIBSOUP GIO GTK SQLITE WEBKIT LIBXML' obj.uselib_local = 'panels'