2015-09-22 03:13:31 -04:00
|
|
|
/* -*- 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/>.
|
|
|
|
*/
|
|
|
|
|
2016-12-05 05:38:43 -05:00
|
|
|
#include "config.h"
|
|
|
|
|
2015-09-22 03:13:31 -04:00
|
|
|
#include <glib.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include <meta/main.h>
|
|
|
|
#include <meta/util.h>
|
|
|
|
|
|
|
|
#include "compositor/meta-plugin-manager.h"
|
2017-02-07 21:32:33 -05:00
|
|
|
#include "core/boxes-private.h"
|
2016-12-05 05:38:43 -05:00
|
|
|
#include "core/main-private.h"
|
2018-07-09 12:42:19 -04:00
|
|
|
#include "tests/boxes-tests.h"
|
2016-12-05 05:38:43 -05:00
|
|
|
#include "tests/meta-backend-test.h"
|
2017-08-10 05:12:39 -04:00
|
|
|
#include "tests/monitor-config-migration-unit-tests.h"
|
2016-12-05 05:40:44 -05:00
|
|
|
#include "tests/monitor-unit-tests.h"
|
2017-01-12 03:20:04 -05:00
|
|
|
#include "tests/monitor-store-unit-tests.h"
|
2017-08-18 02:37:53 -04:00
|
|
|
#include "tests/test-utils.h"
|
2016-12-05 08:26:46 -05:00
|
|
|
#include "wayland/meta-wayland.h"
|
2015-09-22 03:13:31 -04:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2015-09-22 04:21:01 -04:00
|
|
|
typedef enum _MetaTestLaterScheduleFromLaterState
|
|
|
|
{
|
|
|
|
META_TEST_LATER_EXPECT_CALC_SHOWING,
|
|
|
|
META_TEST_LATER_EXPECT_SYNC_STACK,
|
|
|
|
META_TEST_LATER_EXPECT_BEFORE_REDRAW,
|
|
|
|
META_TEST_LATER_FINISHED,
|
|
|
|
} MetaTestLaterScheduleFromLaterState;
|
|
|
|
|
|
|
|
typedef struct _MetaTestLaterScheduleFromLaterData
|
|
|
|
{
|
|
|
|
GMainLoop *loop;
|
|
|
|
MetaTestLaterScheduleFromLaterState state;
|
|
|
|
} MetaTestLaterScheduleFromLaterData;
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
test_later_schedule_from_later_sync_stack_callback (gpointer user_data);
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
test_later_schedule_from_later_calc_showing_callback (gpointer user_data)
|
|
|
|
{
|
|
|
|
MetaTestLaterScheduleFromLaterData *data = user_data;
|
|
|
|
|
|
|
|
g_assert_cmpint (data->state, ==, META_TEST_LATER_EXPECT_CALC_SHOWING);
|
|
|
|
|
|
|
|
meta_later_add (META_LATER_SYNC_STACK,
|
|
|
|
test_later_schedule_from_later_sync_stack_callback,
|
|
|
|
data,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
data->state = META_TEST_LATER_EXPECT_SYNC_STACK;
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
test_later_schedule_from_later_sync_stack_callback (gpointer user_data)
|
|
|
|
{
|
|
|
|
MetaTestLaterScheduleFromLaterData *data = user_data;
|
|
|
|
|
|
|
|
g_assert_cmpint (data->state, ==, META_TEST_LATER_EXPECT_SYNC_STACK);
|
|
|
|
|
|
|
|
data->state = META_TEST_LATER_EXPECT_BEFORE_REDRAW;
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
test_later_schedule_from_later_before_redraw_callback (gpointer user_data)
|
|
|
|
{
|
|
|
|
MetaTestLaterScheduleFromLaterData *data = user_data;
|
|
|
|
|
|
|
|
g_assert_cmpint (data->state, ==, META_TEST_LATER_EXPECT_BEFORE_REDRAW);
|
|
|
|
data->state = META_TEST_LATER_FINISHED;
|
|
|
|
g_main_loop_quit (data->loop);
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_test_util_later_schedule_from_later (void)
|
|
|
|
{
|
|
|
|
MetaTestLaterScheduleFromLaterData data;
|
|
|
|
|
|
|
|
data.loop = g_main_loop_new (NULL, FALSE);
|
|
|
|
|
|
|
|
/* Test that scheduling a MetaLater with 'when' being later than the one being
|
|
|
|
* invoked causes it to be invoked before any callback with a later 'when'
|
|
|
|
* value being invoked.
|
|
|
|
*
|
|
|
|
* The first and last callback is queued here. The one to be invoked in
|
|
|
|
* between is invoked in test_later_schedule_from_later_calc_showing_callback.
|
|
|
|
*/
|
|
|
|
meta_later_add (META_LATER_CALC_SHOWING,
|
|
|
|
test_later_schedule_from_later_calc_showing_callback,
|
|
|
|
&data,
|
|
|
|
NULL);
|
|
|
|
meta_later_add (META_LATER_BEFORE_REDRAW,
|
|
|
|
test_later_schedule_from_later_before_redraw_callback,
|
|
|
|
&data,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
data.state = META_TEST_LATER_EXPECT_CALC_SHOWING;
|
|
|
|
|
|
|
|
g_main_loop_run (data.loop);
|
|
|
|
g_main_loop_unref (data.loop);
|
|
|
|
|
|
|
|
g_assert_cmpint (data.state, ==, META_TEST_LATER_FINISHED);
|
|
|
|
}
|
|
|
|
|
2017-02-07 21:32:33 -05:00
|
|
|
static void
|
2019-03-15 11:39:08 -04:00
|
|
|
meta_test_adjacent_to (void)
|
2017-02-07 21:32:33 -05:00
|
|
|
{
|
|
|
|
MetaRectangle base = { .x = 10, .y = 10, .width = 10, .height = 10 };
|
2019-03-15 11:39:08 -04:00
|
|
|
MetaRectangle adjacent[] = {
|
2017-02-07 21:32:33 -05:00
|
|
|
{ .x = 20, .y = 10, .width = 10, .height = 10 },
|
|
|
|
{ .x = 0, .y = 10, .width = 10, .height = 10 },
|
|
|
|
{ .x = 0, .y = 1, .width = 10, .height = 10 },
|
|
|
|
{ .x = 20, .y = 19, .width = 10, .height = 10 },
|
|
|
|
{ .x = 10, .y = 20, .width = 10, .height = 10 },
|
|
|
|
{ .x = 10, .y = 0, .width = 10, .height = 10 },
|
|
|
|
};
|
2019-03-15 11:39:08 -04:00
|
|
|
MetaRectangle not_adjacent[] = {
|
2017-02-07 21:32:33 -05:00
|
|
|
{ .x = 0, .y = 0, .width = 10, .height = 10 },
|
|
|
|
{ .x = 20, .y = 20, .width = 10, .height = 10 },
|
|
|
|
{ .x = 21, .y = 10, .width = 10, .height = 10 },
|
|
|
|
{ .x = 10, .y = 21, .width = 10, .height = 10 },
|
|
|
|
{ .x = 10, .y = 5, .width = 10, .height = 10 },
|
|
|
|
{ .x = 11, .y = 10, .width = 10, .height = 10 },
|
|
|
|
{ .x = 19, .y = 10, .width = 10, .height = 10 },
|
|
|
|
};
|
|
|
|
unsigned int i;
|
|
|
|
|
2019-03-15 11:39:08 -04:00
|
|
|
for (i = 0; i < G_N_ELEMENTS (adjacent); i++)
|
|
|
|
g_assert (meta_rectangle_is_adjacent_to (&base, &adjacent[i]));
|
2017-02-07 21:32:33 -05:00
|
|
|
|
2019-03-15 11:39:08 -04:00
|
|
|
for (i = 0; i < G_N_ELEMENTS (not_adjacent); i++)
|
|
|
|
g_assert (!meta_rectangle_is_adjacent_to (&base, ¬_adjacent[i]));
|
2017-02-07 21:32:33 -05:00
|
|
|
}
|
|
|
|
|
2015-09-22 03:13:31 -04:00
|
|
|
static gboolean
|
|
|
|
run_tests (gpointer data)
|
|
|
|
{
|
2017-02-24 05:10:52 -05:00
|
|
|
MetaBackend *backend = meta_get_backend ();
|
2017-04-21 04:40:51 -04:00
|
|
|
MetaSettings *settings = meta_backend_get_settings (backend);
|
2015-09-22 03:13:31 -04:00
|
|
|
gboolean ret;
|
|
|
|
|
2017-04-21 04:40:51 -04:00
|
|
|
meta_settings_override_experimental_features (settings);
|
2017-02-24 05:10:52 -05:00
|
|
|
|
2017-03-24 03:36:12 -04:00
|
|
|
meta_settings_enable_experimental_feature (
|
|
|
|
settings,
|
|
|
|
META_EXPERIMENTAL_FEATURE_SCALE_MONITOR_FRAMEBUFFER);
|
2017-02-24 05:10:52 -05:00
|
|
|
|
2017-08-18 02:37:53 -04:00
|
|
|
pre_run_monitor_tests ();
|
|
|
|
|
2015-09-22 03:13:31 -04:00
|
|
|
ret = g_test_run ();
|
|
|
|
|
2017-08-18 02:37:53 -04:00
|
|
|
finish_monitor_tests ();
|
|
|
|
|
2015-09-22 03:13:31 -04:00
|
|
|
meta_quit (ret != 0);
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
init_tests (int argc, char **argv)
|
|
|
|
{
|
|
|
|
g_test_add_func ("/util/meta-later/order", meta_test_util_later_order);
|
2015-09-22 04:21:01 -04:00
|
|
|
g_test_add_func ("/util/meta-later/schedule-from-later",
|
|
|
|
meta_test_util_later_schedule_from_later);
|
2016-12-05 05:40:44 -05:00
|
|
|
|
2019-03-15 11:39:08 -04:00
|
|
|
g_test_add_func ("/core/boxes/adjacent-to", meta_test_adjacent_to);
|
2017-02-07 21:32:33 -05:00
|
|
|
|
2017-01-12 03:20:04 -05:00
|
|
|
init_monitor_store_tests ();
|
2017-08-10 05:12:39 -04:00
|
|
|
init_monitor_config_migration_tests ();
|
2016-12-05 05:40:44 -05:00
|
|
|
init_monitor_tests ();
|
2018-07-09 12:42:19 -04:00
|
|
|
init_boxes_tests ();
|
2015-09-22 03:13:31 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main (int argc, char *argv[])
|
|
|
|
{
|
2018-07-16 10:40:31 -04:00
|
|
|
test_init (&argc, &argv);
|
2016-12-05 08:28:22 -05:00
|
|
|
init_tests (argc, argv);
|
|
|
|
|
2018-07-12 16:20:20 -04:00
|
|
|
meta_plugin_manager_load (test_get_plugin_name ());
|
2015-09-22 03:13:31 -04:00
|
|
|
|
2016-12-05 05:38:43 -05:00
|
|
|
meta_override_compositor_configuration (META_COMPOSITOR_TYPE_WAYLAND,
|
|
|
|
META_TYPE_BACKEND_TEST);
|
|
|
|
|
2015-09-22 03:13:31 -04:00
|
|
|
meta_init ();
|
|
|
|
meta_register_with_session ();
|
|
|
|
|
|
|
|
g_idle_add (run_tests, NULL);
|
|
|
|
|
|
|
|
return meta_run ();
|
|
|
|
}
|