From 51ff51c854176ff52185774f44a1db9cdd75f251 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20=C3=85dahl?= Date: Tue, 26 Jan 2021 17:42:51 +0100 Subject: [PATCH] tests: Add virtual monitor tests The testing currently done is: * Creating a virtual monitor succeeds and gets the right configuration * Painting a few times results in the expected output * Changing the content of the stage also changes the painted content accordingly * Destroying the virtual monitor works as expected Part-of: --- src/backends/meta-monitor-manager-private.h | 1 + src/backends/meta-monitor.h | 1 + src/backends/meta-virtual-monitor.h | 1 + src/tests/meson.build | 3 + src/tests/native-headless.c | 2 + src/tests/native-virtual-monitor.c | 135 ++++++++++++++++++ src/tests/native-virtual-monitor.h | 26 ++++ ...ds_native_virtual-monitor_create_0.ref.png | Bin 0 -> 3509 bytes ...ds_native_virtual-monitor_create_1.ref.png | Bin 0 -> 2610 bytes 9 files changed, 169 insertions(+) create mode 100644 src/tests/native-virtual-monitor.c create mode 100644 src/tests/native-virtual-monitor.h create mode 100644 src/tests/ref-tests/backends_native_virtual-monitor_create_0.ref.png create mode 100644 src/tests/ref-tests/backends_native_virtual-monitor_create_1.ref.png diff --git a/src/backends/meta-monitor-manager-private.h b/src/backends/meta-monitor-manager-private.h index 61bfead0f..e191b50d0 100644 --- a/src/backends/meta-monitor-manager-private.h +++ b/src/backends/meta-monitor-manager-private.h @@ -397,6 +397,7 @@ MetaVirtualMonitor * meta_monitor_manager_create_virtual_monitor (MetaMonitorMan const MetaVirtualMonitorInfo *info, GError **error); +META_EXPORT_TEST MetaMonitorConfigManager * meta_monitor_manager_get_config_manager (MetaMonitorManager *manager); diff --git a/src/backends/meta-monitor.h b/src/backends/meta-monitor.h index eceb645c2..341657ae3 100644 --- a/src/backends/meta-monitor.h +++ b/src/backends/meta-monitor.h @@ -65,6 +65,7 @@ typedef enum _MetaMonitorScalesConstraint } MetaMonitorScalesConstraint; #define META_TYPE_MONITOR (meta_monitor_get_type ()) +META_EXPORT_TEST G_DECLARE_DERIVABLE_TYPE (MetaMonitor, meta_monitor, META, MONITOR, GObject) struct _MetaMonitorClass diff --git a/src/backends/meta-virtual-monitor.h b/src/backends/meta-virtual-monitor.h index d1fd43356..2b733df9c 100644 --- a/src/backends/meta-virtual-monitor.h +++ b/src/backends/meta-virtual-monitor.h @@ -62,6 +62,7 @@ MetaCrtc * meta_virtual_monitor_get_crtc (MetaVirtualMonitor *virtual_monitor); MetaCrtcMode * meta_virtual_monitor_get_crtc_mode (MetaVirtualMonitor *virtual_monitor); +META_EXPORT_TEST MetaOutput * meta_virtual_monitor_get_output (MetaVirtualMonitor *virtual_monitor); G_DEFINE_AUTOPTR_CLEANUP_FUNC (MetaVirtualMonitorInfo, diff --git a/src/tests/meson.build b/src/tests/meson.build index 816ae9810..e570db8c6 100644 --- a/src/tests/meson.build +++ b/src/tests/meson.build @@ -166,8 +166,11 @@ if have_native_tests native_headless_tests = executable('mutter-native-headless-tests', sources: [ 'native-headless.c', + 'native-virtual-monitor.c', + 'native-virtual-monitor.h', 'test-utils.c', 'test-utils.h', + ref_test_sources, ], include_directories: tests_includepath, c_args: tests_c_args, diff --git a/src/tests/native-headless.c b/src/tests/native-headless.c index 4929fa221..1b3d4a26c 100644 --- a/src/tests/native-headless.c +++ b/src/tests/native-headless.c @@ -26,11 +26,13 @@ #include "core/main-private.h" #include "meta/main.h" #include "meta/meta-backend.h" +#include "tests/native-virtual-monitor.h" #include "tests/test-utils.h" static void init_tests (void) { + init_virtual_monitor_tests (); } static gboolean diff --git a/src/tests/native-virtual-monitor.c b/src/tests/native-virtual-monitor.c new file mode 100644 index 000000000..15fc78f88 --- /dev/null +++ b/src/tests/native-virtual-monitor.c @@ -0,0 +1,135 @@ +/* + * 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 "tests/native-virtual-monitor.h" + +#include "backends/meta-backend-private.h" +#include "backends/meta-logical-monitor.h" +#include "backends/meta-monitor-config-manager.h" +#include "backends/meta-virtual-monitor.h" +#include "backends/native/meta-renderer-native.h" +#include "tests/meta-ref-test.h" + +static void +meta_test_virtual_monitor_create (void) +{ + MetaBackend *backend = meta_get_backend (); + MetaMonitorManager *monitor_manager = meta_backend_get_monitor_manager (backend); + MetaMonitorConfigManager *config_manager = + meta_monitor_manager_get_config_manager (monitor_manager); + MetaRenderer *renderer = meta_backend_get_renderer (backend); + MetaVirtualMonitor *virtual_monitor; + g_autoptr (MetaVirtualMonitorInfo) monitor_info = NULL; + GError *error = NULL; + GList *monitors; + MetaMonitor *monitor; + MetaMonitorsConfig *monitors_config; + GList *logical_monitors; + GList *logical_monitor_monitors; + GList *views; + int i; + ClutterActor *actor; + + g_assert_null (meta_monitor_config_manager_get_current (config_manager)); + g_assert_null (meta_monitor_manager_get_logical_monitors (monitor_manager)); + g_assert_null (meta_monitor_manager_get_monitors (monitor_manager)); + g_assert_null (meta_renderer_get_views (renderer)); + + monitor_info = meta_virtual_monitor_info_new (80, 60, 60.0, + "MetaTestVendor", + "MetaVirtualMonitor", + "0x1234"); + virtual_monitor = meta_monitor_manager_create_virtual_monitor (monitor_manager, + monitor_info, + &error); + if (!virtual_monitor) + g_error ("Failed to create virtual monitor: %s", error->message); + + meta_monitor_manager_reload (monitor_manager); + + monitors = meta_monitor_manager_get_monitors (monitor_manager); + g_assert_cmpint (g_list_length (monitors), ==, 1); + monitor = META_MONITOR (monitors->data); + g_assert_cmpstr (meta_monitor_get_vendor (monitor), ==, "MetaTestVendor"); + g_assert_cmpstr (meta_monitor_get_product (monitor), ==, "MetaVirtualMonitor"); + g_assert_cmpstr (meta_monitor_get_serial (monitor), ==, "0x1234"); + g_assert (meta_monitor_get_main_output (monitor) == + meta_virtual_monitor_get_output (virtual_monitor)); + + monitors_config = meta_monitor_manager_ensure_configured (monitor_manager); + g_assert_nonnull (monitors_config); + g_assert_cmpint (g_list_length (monitors_config->logical_monitor_configs), + ==, + 1); + + g_assert_cmpint (g_list_length (monitors_config->disabled_monitor_specs), + ==, + 0); + + logical_monitors = + meta_monitor_manager_get_logical_monitors (monitor_manager); + g_assert_cmpint (g_list_length (logical_monitors), ==, 1); + logical_monitor_monitors = + meta_logical_monitor_get_monitors (logical_monitors->data); + g_assert_cmpint (g_list_length (logical_monitor_monitors), ==, 1); + g_assert (logical_monitor_monitors->data == monitor); + + views = meta_renderer_get_views (renderer); + g_assert_cmpint (g_list_length (views), ==, 1); + + for (i = 0; i < 5; i++) + { + meta_ref_test_verify_view (CLUTTER_STAGE_VIEW (views->data), + g_test_get_path (), 0, + meta_ref_test_determine_ref_test_flag ()); + } + + actor = clutter_actor_new (); + clutter_actor_set_position (actor, 10, 10); + clutter_actor_set_size (actor, 40, 40); + clutter_actor_set_background_color (actor, CLUTTER_COLOR_LightSkyBlue); + clutter_actor_add_child (meta_backend_get_stage (backend), actor); + + for (i = 0; i < 5; i++) + { + meta_ref_test_verify_view (CLUTTER_STAGE_VIEW (views->data), + g_test_get_path (), 1, + meta_ref_test_determine_ref_test_flag ()); + } + + g_object_unref (virtual_monitor); + meta_monitor_manager_reload (monitor_manager); + + g_assert_null (meta_monitor_manager_ensure_configured (monitor_manager)); + g_assert_null (meta_monitor_manager_get_logical_monitors (monitor_manager)); + g_assert_null (meta_monitor_manager_get_monitors (monitor_manager)); + g_assert_null (meta_renderer_get_views (renderer)); + + clutter_actor_destroy (actor); +} + +void +init_virtual_monitor_tests (void) +{ + g_test_add_func ("/backends/native/virtual-monitor/create", + meta_test_virtual_monitor_create); +} diff --git a/src/tests/native-virtual-monitor.h b/src/tests/native-virtual-monitor.h new file mode 100644 index 000000000..0c4c34f02 --- /dev/null +++ b/src/tests/native-virtual-monitor.h @@ -0,0 +1,26 @@ +/* + * 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. + * + */ + +#ifndef NATIVE_VIRTUAL_MONITOR_H +#define NATIVE_VIRTUAL_MONITOR_H + +void init_virtual_monitor_tests (void); + +#endif /* NATIVE_VIRTUAL_MONITOR_H */ diff --git a/src/tests/ref-tests/backends_native_virtual-monitor_create_0.ref.png b/src/tests/ref-tests/backends_native_virtual-monitor_create_0.ref.png new file mode 100644 index 0000000000000000000000000000000000000000..55ed4d9e0f6ba46531c0e3f21b020f21b7d73d9f GIT binary patch literal 3509 zcmV;m4NCHfP)c>qrU{b^JZs=wU)wo_yJ{G33*smbx3w3`UK2PD*nq+{VB5lvgQ)X?~aQNRZwMDLIPAT z&M|F_uUQ$Wn)3h*lHw(^{Iecb4%^zG(?f_xfN+woK5 zVVy>UeF4hO6+prfZQzzysG=5SzZ0h@hX8pymM|flGbcW`>hu?1ysaW$uW-h@bFeso zGj=mP9x}^M$B4Z$Xi&rCIlzgS!V&B1*!jNouwhmnXZrjm&|O@+PB7Hry&dpxxHm@E zxY29XqECM~X5wJ3{GT)!+lV^t!$IQU(}dTUe?nioP1Y%KvM&+$Pl4?4I?F}iGiQUq zS@~RbPG9xO&!XJ$5k=EkEs64x5Pq1~&N(ilJ&*(>^TyWBAd*5`$3_2Hp*FD6JJG4N zhD9+Z!4=wUAtCWWt~!giT+>t(5iH1w&H;(Ssp3-jHcZJ3=i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