diff --git a/src/tests/meson.build b/src/tests/meson.build index 8ffe2f9e1..8ee409e20 100644 --- a/src/tests/meson.build +++ b/src/tests/meson.build @@ -209,6 +209,20 @@ if have_native_tests install: have_installed_tests, install_dir: mutter_installed_tests_libexecdir, ) + + native_persistent_virtual_monitor = executable( + 'mutter-persistent-virtual-monitor', + sources: [ + 'native-persistent-virtual-monitor.c', + 'test-utils.c', + 'test-utils.h', + ], + include_directories: tests_includepath, + c_args: tests_c_args, + dependencies: [tests_deps], + install: have_installed_tests, + install_dir: mutter_installed_tests_libexecdir, + ) endif stacking_tests = [ @@ -292,4 +306,11 @@ if have_native_tests is_parallel: false, timeout: 60, ) + + test('native-persistent-virtual-monitor', native_persistent_virtual_monitor, + suite: ['core', 'mutter/native/persistent-virtual-monitor'], + env: test_env, + is_parallel: false, + timeout: 60, + ) endif diff --git a/src/tests/native-persistent-virtual-monitor.c b/src/tests/native-persistent-virtual-monitor.c new file mode 100644 index 000000000..26bb206d2 --- /dev/null +++ b/src/tests/native-persistent-virtual-monitor.c @@ -0,0 +1,106 @@ +/* + * Copyright (C) 2021 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + * + */ + +#include "config.h" + +#include "backends/meta-logical-monitor.h" +#include "backends/meta-monitor-manager-private.h" +#include "compositor/meta-plugin-manager.h" +#include "meta/main.h" +#include "meta/meta-backend.h" +#include "tests/test-utils.h" + +static gboolean +wait_for_paint (gpointer data) +{ + MetaBackend *backend = meta_get_backend (); + ClutterActor *stage = meta_backend_get_stage (backend); + MetaMonitorManager *monitor_manager = + meta_backend_get_monitor_manager (backend); + GMainLoop *loop; + GList *monitors; + GList *logical_monitors; + MetaLogicalMonitor *logical_monitor; + MetaRectangle layout; + + loop = g_main_loop_new (NULL, FALSE); + g_signal_connect_swapped (stage, "presented", + G_CALLBACK (g_main_loop_quit), + loop); + clutter_actor_queue_redraw (stage); + + monitors = meta_monitor_manager_get_monitors (monitor_manager); + g_assert_cmpint (g_list_length (monitors), ==, 1); + + logical_monitors = + meta_monitor_manager_get_logical_monitors (monitor_manager); + g_assert_cmpint (g_list_length (logical_monitors), ==, 1); + + logical_monitor = logical_monitors->data; + g_assert (meta_logical_monitor_get_monitors (logical_monitor)->data == + monitors->data); + + layout = meta_logical_monitor_get_layout (logical_monitor); + g_assert_cmpint (layout.x, ==, 0); + g_assert_cmpint (layout.y, ==, 0); + g_assert_cmpint (layout.width, ==, 800); + g_assert_cmpint (layout.height, ==, 600); + + g_main_loop_run (loop); + + meta_quit (META_EXIT_SUCCESS); + + return G_SOURCE_REMOVE; +} + +int +main (int argc, + char **argv) +{ + char *fake_args[] = { + NULL, + (char *) "--wayland", + (char *) "--headless", + (char *) "--virtual-monitor", + (char *) "800x600", + }; + char **fake_argv = fake_args; + int fake_argc = G_N_ELEMENTS (fake_args); + GOptionContext *ctx; + GError *error = NULL; + + test_init (&argc, &argv); + + fake_args[0] = argv[0]; + + ctx = meta_get_option_context (); + if (!g_option_context_parse (ctx, &fake_argc, &fake_argv, &error)) + g_error ("Failed to parse fake command line arguments: %s", error->message); + g_option_context_free (ctx); + + meta_plugin_manager_load (test_get_plugin_name ()); + + meta_init (); + meta_register_with_session (); + + g_idle_add (wait_for_paint, NULL); + + return meta_run (); +}