tests/clutter: Always use stage from backend
This removes all occurrences of creating a custom stage from the tests, making them always use the one from MetaBackend. This will allow for further cleanups. https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1364
This commit is contained in:
@ -4,6 +4,8 @@
|
||||
#include <glib-object.h>
|
||||
#include <clutter/clutter.h>
|
||||
|
||||
#include "compositor/meta-plugin-manager.h"
|
||||
|
||||
typedef struct {
|
||||
gpointer dummy_field;
|
||||
} ClutterTestEnvironment;
|
||||
@ -26,25 +28,30 @@ log_func (const gchar *log_domain,
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/*
|
||||
* clutter_test_init:
|
||||
* @argc: (inout): number of arguments in @argv
|
||||
* @argv: (inout) (array length=argc) (nullable): array of arguments
|
||||
*
|
||||
* Initializes the Clutter test environment.
|
||||
*
|
||||
* Since: 1.18
|
||||
*/
|
||||
void
|
||||
clutter_test_init (int *argc,
|
||||
char ***argv)
|
||||
static const char *
|
||||
test_get_plugin_name (void)
|
||||
{
|
||||
const char *display = g_getenv ("DISPLAY");
|
||||
const char *name;
|
||||
|
||||
name = g_getenv ("MUTTER_TEST_PLUGIN_PATH");
|
||||
if (name)
|
||||
return name;
|
||||
else
|
||||
return "libdefault";
|
||||
}
|
||||
|
||||
static void
|
||||
init_common_pre (void)
|
||||
{
|
||||
const char *display;
|
||||
|
||||
if (G_UNLIKELY (test_environ != NULL))
|
||||
g_error ("Attempting to initialize the test suite more than once, "
|
||||
"aborting...\n");
|
||||
|
||||
meta_plugin_manager_load (test_get_plugin_name ());
|
||||
meta_test_init ();
|
||||
|
||||
display = g_getenv ("DISPLAY");
|
||||
if (!display || *display == '\0')
|
||||
{
|
||||
@ -57,15 +64,53 @@ clutter_test_init (int *argc,
|
||||
* rate, and run the master clock using a 60 fps timer instead.
|
||||
*/
|
||||
_clutter_set_sync_to_vblank (FALSE);
|
||||
}
|
||||
|
||||
/* perform the actual initialization */
|
||||
g_assert (clutter_init (NULL, NULL) == CLUTTER_INIT_SUCCESS);
|
||||
|
||||
static void
|
||||
init_common_post (int *argc,
|
||||
char ***argv)
|
||||
{
|
||||
g_test_init (argc, argv, NULL);
|
||||
g_test_bug_base ("https://bugzilla.gnome.org/show_bug.cgi?id=%s");
|
||||
|
||||
/* our global state, accessible from each test unit */
|
||||
test_environ = g_new0 (ClutterTestEnvironment, 1);
|
||||
|
||||
meta_start ();
|
||||
}
|
||||
|
||||
/*
|
||||
* clutter_test_init:
|
||||
* @argc: (inout): number of arguments in @argv
|
||||
* @argv: (inout) (array length=argc) (nullable): array of arguments
|
||||
*
|
||||
* Initializes the Clutter test environment.
|
||||
*
|
||||
* Since: 1.18
|
||||
*/
|
||||
void
|
||||
clutter_test_init (int *argc,
|
||||
char ***argv)
|
||||
{
|
||||
init_common_pre ();
|
||||
g_assert (clutter_init (NULL, NULL) == CLUTTER_INIT_SUCCESS);
|
||||
init_common_post (argc, argv);
|
||||
}
|
||||
|
||||
void
|
||||
clutter_test_init_with_args (int *argc,
|
||||
char ***argv,
|
||||
const char *parameter_string,
|
||||
GOptionEntry *entries,
|
||||
const char *translation_domain)
|
||||
{
|
||||
init_common_pre ();
|
||||
g_assert (clutter_init_with_args (argc, argv,
|
||||
parameter_string,
|
||||
entries,
|
||||
translation_domain,
|
||||
NULL) == CLUTTER_INIT_SUCCESS);
|
||||
init_common_post (argc, argv);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -91,17 +136,39 @@ typedef struct {
|
||||
GDestroyNotify test_notify;
|
||||
} ClutterTestData;
|
||||
|
||||
static gboolean
|
||||
list_equal_unsorted (GList *list_a,
|
||||
GList *list_b)
|
||||
{
|
||||
GList *l_a;
|
||||
GList *l_b;
|
||||
|
||||
for (l_a = list_a, l_b = list_b;
|
||||
l_a && l_b;
|
||||
l_a = l_a->next, l_b = l_b->next)
|
||||
{
|
||||
if (l_a->data != l_b->data)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return !l_a && !l_b;
|
||||
}
|
||||
|
||||
static void
|
||||
clutter_test_func_wrapper (gconstpointer data_)
|
||||
{
|
||||
const ClutterTestData *data = data_;
|
||||
ClutterActor *stage;
|
||||
GList *pre_stage_children;
|
||||
GList *post_stage_children;
|
||||
|
||||
g_test_log_set_fatal_handler (log_func, NULL);
|
||||
|
||||
/* ensure that the previous test state has been cleaned up */
|
||||
stage = clutter_test_get_stage ();
|
||||
g_assert_false (clutter_actor_is_mapped (stage));
|
||||
clutter_actor_hide (stage);
|
||||
|
||||
pre_stage_children = clutter_actor_get_children (stage);
|
||||
|
||||
if (data->test_data != NULL)
|
||||
{
|
||||
@ -119,7 +186,13 @@ clutter_test_func_wrapper (gconstpointer data_)
|
||||
if (data->test_notify != NULL)
|
||||
data->test_notify (data->test_data);
|
||||
|
||||
clutter_actor_remove_all_children (stage);
|
||||
post_stage_children = clutter_actor_get_children (stage);
|
||||
|
||||
g_assert_true (list_equal_unsorted (pre_stage_children, post_stage_children));
|
||||
|
||||
g_list_free (pre_stage_children);
|
||||
g_list_free (post_stage_children);
|
||||
|
||||
clutter_actor_hide (stage);
|
||||
}
|
||||
|
||||
@ -244,6 +317,18 @@ clutter_test_run (void)
|
||||
return res;
|
||||
}
|
||||
|
||||
void
|
||||
clutter_test_main (void)
|
||||
{
|
||||
meta_run_main_loop ();
|
||||
}
|
||||
|
||||
void
|
||||
clutter_test_quit (void)
|
||||
{
|
||||
meta_quit (META_EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
ClutterActor *stage;
|
||||
|
||||
|
Reference in New Issue
Block a user