From 12150c1ca72a766bf638b5d8679f9542281d3b61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20=C3=85dahl?= Date: Mon, 5 Dec 2016 18:40:44 +0800 Subject: [PATCH] tests: Add basic monitor configuration tests The added test checks that two monitors are lied out on a row next to each other. https://bugzilla.gnome.org/show_bug.cgi?id=777732 --- src/Makefile-tests.am | 2 + src/tests/monitor-unit-tests.c | 68 ++++++++++++++++++++++++++++++++++ src/tests/monitor-unit-tests.h | 25 +++++++++++++ src/tests/unit-tests.c | 3 ++ 4 files changed, 98 insertions(+) create mode 100644 src/tests/monitor-unit-tests.c create mode 100644 src/tests/monitor-unit-tests.h diff --git a/src/Makefile-tests.am b/src/Makefile-tests.am index 3c5793d4d..a82f81483 100644 --- a/src/Makefile-tests.am +++ b/src/Makefile-tests.am @@ -38,6 +38,8 @@ mutter_test_unit_tests_SOURCES = \ tests/meta-backend-test.h \ tests/meta-monitor-manager-test.c \ tests/meta-monitor-manager-test.h \ + tests/monitor-unit-tests.c \ + tests/monitor-unit-tests.h \ $(NULL) mutter_test_unit_tests_LDADD = $(MUTTER_LIBS) libmutter.la diff --git a/src/tests/monitor-unit-tests.c b/src/tests/monitor-unit-tests.c new file mode 100644 index 000000000..3aa71878a --- /dev/null +++ b/src/tests/monitor-unit-tests.c @@ -0,0 +1,68 @@ +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ + +/* + * Copyright (C) 2016 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 . + */ + +#include "config.h" + +#include "tests/monitor-unit-tests.h" + +#include "backends/meta-backend-private.h" + +static void +meta_test_monitor_linear_config (void) +{ + MetaBackend *backend = meta_get_backend (); + MetaMonitorManager *monitor_manager = + meta_backend_get_monitor_manager (backend); + GList *logical_monitors, *l; + int n_logical_monitors, i; + MetaRectangle expected_rects[] = { + { .x = 0, .y = 0, .width = 1024, .height = 768 }, + { .x = 1024, .y = 0, .width = 1024, .height = 768 }, + }; + + g_assert (monitor_manager->screen_width == 1024 * 2); + g_assert (monitor_manager->screen_height == 768); + g_assert (monitor_manager->n_outputs == 2); + g_assert (monitor_manager->n_crtcs == 2); + + n_logical_monitors = + meta_monitor_manager_get_num_logical_monitors (monitor_manager); + g_assert (n_logical_monitors == 2); + + logical_monitors = + meta_monitor_manager_get_logical_monitors (monitor_manager); + i = 0; + for (l = logical_monitors; l; l = l->next) + { + MetaLogicalMonitor *logical_monitor = l->data; + + g_assert (logical_monitor->rect.x == expected_rects[i].x); + g_assert (logical_monitor->rect.y == expected_rects[i].y); + g_assert (logical_monitor->rect.width == expected_rects[i].width); + g_assert (logical_monitor->rect.height == expected_rects[i].height); + i++; + } +} + +void +init_monitor_tests (void) +{ + g_test_add_func ("/backends/monitor/linear-config", + meta_test_monitor_linear_config); +} diff --git a/src/tests/monitor-unit-tests.h b/src/tests/monitor-unit-tests.h new file mode 100644 index 000000000..a98f9d5c4 --- /dev/null +++ b/src/tests/monitor-unit-tests.h @@ -0,0 +1,25 @@ +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ + +/* + * Copyright (C) 2016 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 . + */ + +#ifndef MONITOR_UNIT_TESTS_H +#define MONITOR_UNIT_TESTS_H + +void init_monitor_tests (void); + +#endif /* MONITOR_UNIT_TESTS_H */ diff --git a/src/tests/unit-tests.c b/src/tests/unit-tests.c index 4a6d10149..8f7f83fbb 100644 --- a/src/tests/unit-tests.c +++ b/src/tests/unit-tests.c @@ -28,6 +28,7 @@ #include "compositor/meta-plugin-manager.h" #include "core/main-private.h" #include "tests/meta-backend-test.h" +#include "tests/monitor-unit-tests.h" typedef struct _MetaTestLaterOrderCallbackData { @@ -198,6 +199,8 @@ init_tests (int argc, char **argv) g_test_add_func ("/util/meta-later/order", meta_test_util_later_order); g_test_add_func ("/util/meta-later/schedule-from-later", meta_test_util_later_schedule_from_later); + + init_monitor_tests (); } int