Add an extension test
This commit is contained in:
parent
b4ba0888bf
commit
f78a047275
1 changed files with 101 additions and 0 deletions
101
tests/extensions.c
Normal file
101
tests/extensions.c
Normal file
|
@ -0,0 +1,101 @@
|
|||
/*
|
||||
Copyright (C) 2009 Christian Dywan <christian@twotoasts.de>
|
||||
|
||||
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 <config.h>
|
||||
#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
|
Loading…
Reference in a new issue