mirror of
https://github.com/brl/mutter.git
synced 2024-11-27 18:40:40 -05:00
148 lines
3.7 KiB
C
148 lines
3.7 KiB
C
|
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
|
||
|
|
||
|
/*
|
||
|
* Copyright (C) 2015 Red Hat, Inc.
|
||
|
*
|
||
|
* This program is free software; you can redistribute it and/or
|
||
|
* modify it under the terms of the GNU General Public License as
|
||
|
* published by the Free Software Foundation; either version 2 of the
|
||
|
* License, or (at your option) any later version.
|
||
|
*
|
||
|
* This program is distributed in the hope that it will be useful, but
|
||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||
|
* General Public License for more details.
|
||
|
*
|
||
|
* You should have received a copy of the GNU General Public License
|
||
|
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||
|
*/
|
||
|
|
||
|
#include <glib.h>
|
||
|
#include <stdlib.h>
|
||
|
|
||
|
#include <meta/main.h>
|
||
|
#include <meta/util.h>
|
||
|
|
||
|
#include "compositor/meta-plugin-manager.h"
|
||
|
|
||
|
typedef struct _MetaTestLaterOrderCallbackData
|
||
|
{
|
||
|
GMainLoop *loop; /* Loop to terminate when done. */
|
||
|
int callback_num; /* Callback number integer. */
|
||
|
int *expected_callback_num; /* Pointer to the expected callback number. */
|
||
|
} MetaTestLaterOrderCallbackData;
|
||
|
|
||
|
static gboolean
|
||
|
test_later_order_callback (gpointer user_data)
|
||
|
{
|
||
|
MetaTestLaterOrderCallbackData *data = user_data;
|
||
|
|
||
|
g_assert_cmpint (data->callback_num, ==, *data->expected_callback_num);
|
||
|
|
||
|
if (*data->expected_callback_num == 0)
|
||
|
g_main_loop_quit (data->loop);
|
||
|
else
|
||
|
(*data->expected_callback_num)--;
|
||
|
|
||
|
return FALSE;
|
||
|
}
|
||
|
|
||
|
static void
|
||
|
meta_test_util_later_order (void)
|
||
|
{
|
||
|
GMainLoop *loop;
|
||
|
int expected_callback_num;
|
||
|
int i;
|
||
|
const int num_callbacks = 3;
|
||
|
MetaTestLaterOrderCallbackData callback_data[num_callbacks];
|
||
|
|
||
|
loop = g_main_loop_new (NULL, FALSE);
|
||
|
|
||
|
/* Schedule three BEFORE_DRAW callbacks each with its own number associated
|
||
|
* with it.
|
||
|
*/
|
||
|
for (i = 0; i < num_callbacks; i++)
|
||
|
{
|
||
|
callback_data[i] = (MetaTestLaterOrderCallbackData) {
|
||
|
.loop = loop,
|
||
|
.callback_num = i,
|
||
|
.expected_callback_num = &expected_callback_num,
|
||
|
};
|
||
|
meta_later_add (META_LATER_BEFORE_REDRAW,
|
||
|
test_later_order_callback,
|
||
|
&callback_data[i],
|
||
|
NULL);
|
||
|
}
|
||
|
|
||
|
/* Check that the callbacks are invoked in the opposite order that they were
|
||
|
* scheduled. Each callback will decrease the number by 1 after it checks the
|
||
|
* validity.
|
||
|
*/
|
||
|
expected_callback_num = num_callbacks - 1;
|
||
|
g_main_loop_run (loop);
|
||
|
g_assert_cmpint (expected_callback_num, ==, 0);
|
||
|
g_main_loop_unref (loop);
|
||
|
}
|
||
|
|
||
|
static gboolean
|
||
|
run_tests (gpointer data)
|
||
|
{
|
||
|
gboolean ret;
|
||
|
|
||
|
ret = g_test_run ();
|
||
|
|
||
|
meta_quit (ret != 0);
|
||
|
|
||
|
return FALSE;
|
||
|
}
|
||
|
|
||
|
static void
|
||
|
init_tests (int argc, char **argv)
|
||
|
{
|
||
|
g_test_init (&argc, &argv, NULL);
|
||
|
g_test_bug_base ("http://bugzilla.gnome.org/show_bug.cgi?id=");
|
||
|
|
||
|
g_test_add_func ("/util/meta-later/order", meta_test_util_later_order);
|
||
|
}
|
||
|
|
||
|
int
|
||
|
main (int argc, char *argv[])
|
||
|
{
|
||
|
GOptionContext *ctx;
|
||
|
GError *error = NULL;
|
||
|
|
||
|
ctx = g_option_context_new (NULL);
|
||
|
|
||
|
if (!g_option_context_parse (ctx,
|
||
|
&argc, &argv, &error))
|
||
|
{
|
||
|
g_printerr ("%s", error->message);
|
||
|
return 1;
|
||
|
}
|
||
|
|
||
|
g_option_context_free (ctx);
|
||
|
|
||
|
char *fake_args[] = { NULL, "--wayland" };
|
||
|
fake_args[0] = argv[0];
|
||
|
char **fake_argv = fake_args;
|
||
|
int fake_argc = 2;
|
||
|
|
||
|
ctx = meta_get_option_context ();
|
||
|
if (!g_option_context_parse (ctx, &fake_argc, &fake_argv, &error))
|
||
|
{
|
||
|
g_printerr ("mutter: %s\n", error->message);
|
||
|
exit (1);
|
||
|
}
|
||
|
g_option_context_free (ctx);
|
||
|
|
||
|
meta_plugin_manager_load ("default");
|
||
|
|
||
|
meta_init ();
|
||
|
meta_register_with_session ();
|
||
|
|
||
|
init_tests (argc, argv);
|
||
|
g_idle_add (run_tests, NULL);
|
||
|
|
||
|
return meta_run ();
|
||
|
}
|