From: Christian Dywan Date: Wed, 4 Feb 2009 23:12:26 +0000 (+0100) Subject: Add an extension test X-Git-Url: https://spindle.queued.net/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f78a0472751f1db98593350e1f214a17f091eee6;p=midori Add an extension test --- diff --git a/tests/extensions.c b/tests/extensions.c new file mode 100644 index 00000000..c8b95e78 --- /dev/null +++ b/tests/extensions.c @@ -0,0 +1,101 @@ +/* + Copyright (C) 2009 Christian Dywan + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + See the file COPYING for the full license text. +*/ + +#if HAVE_CONFIG_H + #include +#endif + +#include "midori.h" + +#if GLIB_CHECK_VERSION(2, 16, 0) + +const gpointer magic = (gpointer)0xdeadbeef; + +static void +extension_activate_cb (MidoriExtension* extension, + MidoriApp* app) +{ + g_object_set_data (G_OBJECT (extension), "activated", magic); +} + +static void +extension_deactivate_cb (MidoriExtension* extension) +{ + g_object_set_data (G_OBJECT (extension), "deactivated", magic); +} + +static void +extension_create (void) +{ + MidoriExtension* extension; + + extension = g_object_new (MIDORI_TYPE_EXTENSION, NULL); + g_assert (!midori_extension_is_prepared (extension)); + g_object_set (extension, "name", "TestExtension", + "version", "1.0", NULL); + g_assert (!midori_extension_is_prepared (extension)); + g_object_set (extension, "description", "Nothing but a test.", + "authors", "John Doe", NULL); + /* FIXME: We should require to connect to "activate" + g_assert (!midori_extension_is_prepared (extension)); */ + g_signal_connect (extension, "activate", + G_CALLBACK (extension_activate_cb), NULL); + g_assert (midori_extension_is_prepared (extension)); + g_assert (!midori_extension_is_active (extension)); + g_signal_emit_by_name (extension, "activate", NULL); + g_assert (midori_extension_is_active (extension)); + g_assert (g_object_get_data (G_OBJECT (extension), "activated") == magic); + g_signal_connect (extension, "deactivate", + G_CALLBACK (extension_deactivate_cb), NULL); + midori_extension_deactivate (extension); + g_assert (!midori_extension_is_active (extension)); + g_assert (g_object_get_data (G_OBJECT (extension), "deactivated") == magic); +} + +static void +extension_settings (void) +{ + MidoriExtension* extension; + const gchar* lastname; + + extension = g_object_new (MIDORI_TYPE_EXTENSION, + "name", "TestExtension", + "version", "1.0", + "description", "Nothing but a test.", + "authors", "John Doe", + NULL); + midori_extension_install_string (extension, "lastname", "Thomas Mann"); + lastname = midori_extension_get_string (extension, "lastname"); + g_assert_cmpstr (lastname, ==, NULL); + g_signal_connect (extension, "activate", + G_CALLBACK (extension_activate_cb), NULL); + g_signal_emit_by_name (extension, "activate", NULL); + lastname = midori_extension_get_string (extension, "lastname"); + g_assert_cmpstr (lastname, ==, "Thomas Mann"); + midori_extension_set_string (extension, "lastname", "Theodor Fontane"); + lastname = midori_extension_get_string (extension, "lastname"); + g_assert_cmpstr (lastname, ==, "Theodor Fontane"); +} + +int +main (int argc, + char** argv) +{ + g_test_init (&argc, &argv, NULL); + gtk_init (&argc, &argv); + + g_test_add_func ("/extensions/create", extension_create); + g_test_add_func ("/extensions/settings", extension_settings); + + return g_test_run (); +} + +#endif