diff --git a/src/Makefile-tests.am b/src/Makefile-tests.am
index 56b16186d..c0d282eb1 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-config-migration-unit-tests.c \
+ tests/monitor-config-migration-unit-tests.h \
tests/monitor-store-unit-tests.c \
tests/monitor-store-unit-tests.h \
tests/monitor-test-utils.c \
diff --git a/src/tests/migration/basic-new.xml b/src/tests/migration/basic-new.xml
new file mode 100644
index 000000000..569d1e7cd
--- /dev/null
+++ b/src/tests/migration/basic-new.xml
@@ -0,0 +1,78 @@
+
+
+
+
+ 0
+ 0
+
+
+ HDMI-1
+ DEL
+ DELL P2415Q
+ GTTPW67P0WFB
+
+
+ 3840
+ 2160
+ 29.981103897094727
+
+
+
+
+ 3840
+ 0
+ yes
+
+
+ eDP-1
+ AUO
+ 0x123d
+ 0x00000000
+
+
+ 1920
+ 1080
+ 60.049972534179688
+
+
+
+
+
+
+
+ 1920
+ 0
+
+
+ DP-2
+ ACI
+ VX239
+ ECLMRS004144
+
+
+ 1920
+ 1080
+ 60
+
+
+
+
+ 0
+ 0
+ yes
+
+
+ eDP-1
+ AUO
+ 0x123d
+ 0x00000000
+
+
+ 1920
+ 1080
+ 60.049468994140625
+
+
+
+
+
diff --git a/src/tests/migration/basic-old.xml b/src/tests/migration/basic-old.xml
new file mode 100644
index 000000000..c47dc55c1
--- /dev/null
+++ b/src/tests/migration/basic-old.xml
@@ -0,0 +1,72 @@
+
+
+ no
+
+
+
+
+ no
+
+
+
+
diff --git a/src/tests/migration/rotated-new-finished.xml b/src/tests/migration/rotated-new-finished.xml
new file mode 100644
index 000000000..ad8d614eb
--- /dev/null
+++ b/src/tests/migration/rotated-new-finished.xml
@@ -0,0 +1,27 @@
+
+
+
+ 0
+ 0
+ 1
+ yes
+
+ right
+ no
+
+
+
+ DP-1
+ MetaProduct's Inc.
+ MetaMonitor
+ 0x123456
+
+
+ 800
+ 600
+ 60
+
+
+
+
+
diff --git a/src/tests/migration/rotated-new.xml b/src/tests/migration/rotated-new.xml
new file mode 100644
index 000000000..f8de70beb
--- /dev/null
+++ b/src/tests/migration/rotated-new.xml
@@ -0,0 +1,27 @@
+
+
+
+
+ 0
+ 0
+ yes
+
+ right
+ no
+
+
+
+ DP-1
+ MetaProduct's Inc.
+ MetaMonitor
+ 0x123456
+
+
+ 800
+ 600
+ 60
+
+
+
+
+
diff --git a/src/tests/migration/rotated-old.xml b/src/tests/migration/rotated-old.xml
new file mode 100644
index 000000000..cf48ef7b9
--- /dev/null
+++ b/src/tests/migration/rotated-old.xml
@@ -0,0 +1,21 @@
+
+
+ no
+
+
+
diff --git a/src/tests/migration/tiled-new.xml b/src/tests/migration/tiled-new.xml
new file mode 100644
index 000000000..9fe285ac8
--- /dev/null
+++ b/src/tests/migration/tiled-new.xml
@@ -0,0 +1,23 @@
+
+
+
+
+ 0
+ 0
+ yes
+
+
+ DP-1
+ DEL
+ DELL P2415Q
+ GTTPW67P0WFB
+
+
+ 3840
+ 2160
+ 60
+
+
+
+
+
diff --git a/src/tests/migration/tiled-old.xml b/src/tests/migration/tiled-old.xml
new file mode 100644
index 000000000..8235b31e3
--- /dev/null
+++ b/src/tests/migration/tiled-old.xml
@@ -0,0 +1,37 @@
+
+
+ no
+
+
+
+
diff --git a/src/tests/monitor-config-migration-unit-tests.c b/src/tests/monitor-config-migration-unit-tests.c
new file mode 100644
index 000000000..08d788c31
--- /dev/null
+++ b/src/tests/monitor-config-migration-unit-tests.c
@@ -0,0 +1,112 @@
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
+
+/*
+ * Copyright (C) 2017 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-config-migration-unit-tests.h"
+
+#include
+#include
+
+#include "backends/meta-backend-private.h"
+#include "backends/meta-monitor-config-manager.h"
+#include "backends/meta-monitor-config-store.h"
+#include "backends/meta-monitor-manager-private.h"
+#include "backends/meta-monitor-config-migration.h"
+#include "tests/monitor-test-utils.h"
+
+static void
+test_migration (const char *old_config,
+ const char *new_config)
+{
+ MetaBackend *backend = meta_get_backend ();
+ MetaMonitorManager *monitor_manager =
+ meta_backend_get_monitor_manager (backend);
+ MetaMonitorConfigManager *config_manager = monitor_manager->config_manager;
+ MetaMonitorConfigStore *config_store =
+ meta_monitor_config_manager_get_store (config_manager);
+ GError *error = NULL;
+ const char *old_config_path;
+ g_autoptr (GFile) old_config_file = NULL;
+ g_autofree char *migrated_path = NULL;
+ const char *expected_path;
+ g_autofree char *migrated_data = NULL;
+ g_autofree char *expected_data = NULL;
+ g_autoptr (GFile) migrated_file = NULL;
+
+ migrated_path = g_build_filename (g_get_tmp_dir (),
+ "test-migrated-monitors.xml",
+ NULL);
+ if (!meta_monitor_config_store_set_custom (config_store, "/dev/null",
+ migrated_path,
+ &error))
+ g_error ("Failed to set custom config store: %s", error->message);
+
+ old_config_path = g_test_get_filename (G_TEST_DIST, "tests", "migration",
+ old_config, NULL);
+ old_config_file = g_file_new_for_path (old_config_path);
+ if (!meta_migrate_old_monitors_config (config_store,
+ old_config_file,
+ &error))
+ g_error ("Failed to migrate config: %s", error->message);
+
+ expected_path = g_test_get_filename (G_TEST_DIST, "tests", "migration",
+ new_config, NULL);
+
+ expected_data = read_file (expected_path);
+ migrated_data = read_file (migrated_path);
+
+ g_assert_nonnull (expected_data);
+ g_assert_nonnull (migrated_data);
+
+ g_assert (strcmp (expected_data, migrated_data) == 0);
+
+ migrated_file = g_file_new_for_path (migrated_path);
+ if (!g_file_delete (migrated_file, NULL, &error))
+ g_error ("Failed to remove test data output file: %s", error->message);
+}
+
+static void
+meta_test_monitor_config_migration_basic (void)
+{
+ test_migration ("basic-old.xml", "basic-new.xml");
+}
+
+static void
+meta_test_monitor_config_migration_rotated (void)
+{
+ test_migration ("rotated-old.xml", "rotated-new.xml");
+}
+
+static void
+meta_test_monitor_config_migration_tiled (void)
+{
+ test_migration ("tiled-old.xml", "tiled-new.xml");
+}
+
+void
+init_monitor_config_migration_tests (void)
+{
+ g_test_add_func ("/backends/monitor-config-migration/basic",
+ meta_test_monitor_config_migration_basic);
+ g_test_add_func ("/backends/monitor-config-migration/rotated",
+ meta_test_monitor_config_migration_rotated);
+ g_test_add_func ("/backends/monitor-config-migration/tiled",
+ meta_test_monitor_config_migration_tiled);
+}
diff --git a/src/tests/monitor-config-migration-unit-tests.h b/src/tests/monitor-config-migration-unit-tests.h
new file mode 100644
index 000000000..a8d18de9a
--- /dev/null
+++ b/src/tests/monitor-config-migration-unit-tests.h
@@ -0,0 +1,25 @@
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
+
+/*
+ * Copyright (C) 2017 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_CONFIG_MIGRATION_UNIT_TESTS_H
+#define MONITOR_CONFIG_MIGRATION_UNIT_TESTS_H
+
+void init_monitor_config_migration_tests (void);
+
+#endif /* MONITOR_CONFIG_MIGRATION_UNIT_TESTS_H */
diff --git a/src/tests/monitor-test-utils.c b/src/tests/monitor-test-utils.c
index b063a552d..548815691 100644
--- a/src/tests/monitor-test-utils.c
+++ b/src/tests/monitor-test-utils.c
@@ -46,3 +46,36 @@ set_custom_monitor_config (const char *filename)
&error))
g_error ("Failed to set custom config: %s", error->message);
}
+
+char *
+read_file (const char *file_path)
+{
+ g_autoptr (GFile) file = NULL;
+ g_autoptr (GFileInputStream) input_stream = NULL;
+ g_autoptr (GFileInfo) file_info = NULL;
+ goffset file_size;
+ gsize bytes_read;
+ g_autofree char *buffer = NULL;
+ GError *error = NULL;
+
+ file = g_file_new_for_path (file_path);
+ input_stream = g_file_read (file, NULL, &error);
+ if (!input_stream)
+ g_error ("Failed to read migrated config file: %s", error->message);
+
+ file_info = g_file_input_stream_query_info (input_stream,
+ G_FILE_ATTRIBUTE_STANDARD_SIZE,
+ NULL, &error);
+ if (!file_info)
+ g_error ("Failed to read file info: %s", error->message);
+
+ file_size = g_file_info_get_size (file_info);
+ buffer = g_malloc0 (file_size + 1);
+
+ if (!g_input_stream_read_all (G_INPUT_STREAM (input_stream),
+ buffer, file_size, &bytes_read, NULL, &error))
+ g_error ("Failed to read file content: %s", error->message);
+ g_assert_cmpint ((goffset) bytes_read, ==, file_size);
+
+ return g_steal_pointer (&buffer);
+}
diff --git a/src/tests/monitor-test-utils.h b/src/tests/monitor-test-utils.h
index c71f1708e..4b9b3f0c7 100644
--- a/src/tests/monitor-test-utils.h
+++ b/src/tests/monitor-test-utils.h
@@ -26,4 +26,6 @@ gboolean is_using_monitor_config_manager (void);
void set_custom_monitor_config (const char *filename);
+char * read_file (const char *file_path);
+
#endif /* MONITOR_TEST_UTILS_H */
diff --git a/src/tests/monitor-unit-tests.c b/src/tests/monitor-unit-tests.c
index d931b2106..bf4e944f9 100644
--- a/src/tests/monitor-unit-tests.c
+++ b/src/tests/monitor-unit-tests.c
@@ -24,6 +24,8 @@
#include "backends/meta-backend-private.h"
#include "backends/meta-logical-monitor.h"
#include "backends/meta-monitor.h"
+#include "backends/meta-monitor-config-migration.h"
+#include "backends/meta-monitor-config-store.h"
#include "tests/meta-monitor-manager-test.h"
#include "tests/monitor-test-utils.h"
@@ -4650,6 +4652,146 @@ meta_test_monitor_custom_interlaced_config (void)
check_monitor_configuration (&test_case);
}
+static void
+meta_test_monitor_migrated_rotated (void)
+{
+ MonitorTestCase test_case = {
+ .setup = {
+ .modes = {
+ {
+ .width = 800,
+ .height = 600,
+ .refresh_rate = 60.0
+ }
+ },
+ .n_modes = 1,
+ .outputs = {
+ {
+ .crtc = -1,
+ .modes = { 0 },
+ .n_modes = 1,
+ .preferred_mode = 0,
+ .possible_crtcs = { 0 },
+ .n_possible_crtcs = 1,
+ .width_mm = 222,
+ .height_mm = 125
+ }
+ },
+ .n_outputs = 1,
+ .crtcs = {
+ {
+ .current_mode = -1
+ }
+ },
+ .n_crtcs = 1
+ },
+
+ .expect = {
+ .monitors = {
+ {
+ .outputs = { 0 },
+ .n_outputs = 1,
+ .modes = {
+ {
+ .width = 800,
+ .height = 600,
+ .refresh_rate = 60.0,
+ .crtc_modes = {
+ {
+ .output = 0,
+ .crtc_mode = 0
+ }
+ }
+ }
+ },
+ .n_modes = 1,
+ .current_mode = 0,
+ .width_mm = 222,
+ .height_mm = 125
+ }
+ },
+ .n_monitors = 1,
+ .logical_monitors = {
+ {
+ .monitors = { 0 },
+ .n_monitors = 1,
+ .layout = { .x = 0, .y = 0, .width = 600, .height = 800 },
+ .scale = 1,
+ .transform = META_MONITOR_TRANSFORM_270
+ },
+ },
+ .n_logical_monitors = 1,
+ .primary_logical_monitor = 0,
+ .n_outputs = 1,
+ .crtcs = {
+ {
+ .current_mode = 0,
+ }
+ },
+ .n_crtcs = 1,
+ .screen_width = 600,
+ .screen_height = 800,
+ }
+ };
+ MetaMonitorTestSetup *test_setup;
+ MetaBackend *backend = meta_get_backend ();
+ MetaMonitorManager *monitor_manager =
+ meta_backend_get_monitor_manager (backend);
+ MetaMonitorConfigManager *config_manager = monitor_manager->config_manager;
+ MetaMonitorConfigStore *config_store =
+ meta_monitor_config_manager_get_store (config_manager);
+ g_autofree char *migrated_path = NULL;
+ const char *old_config_path;
+ g_autoptr (GFile) old_config_file = NULL;
+ GError *error = NULL;
+ const char *expected_path;
+ g_autofree char *migrated_data = NULL;
+ g_autofree char *expected_data = NULL;
+ g_autoptr (GFile) migrated_file = NULL;
+
+ test_setup = create_monitor_test_setup (&test_case,
+ MONITOR_TEST_FLAG_NONE);
+
+ migrated_path = g_build_filename (g_get_tmp_dir (),
+ "test-finished-migrated-monitors.xml",
+ NULL);
+ if (!meta_monitor_config_store_set_custom (config_store,
+ "/dev/null",
+ migrated_path,
+ &error))
+ g_error ("Failed to set custom config store files: %s", error->message);
+
+ old_config_path = g_test_get_filename (G_TEST_DIST,
+ "tests", "migration",
+ "rotated-old.xml",
+ NULL);
+ old_config_file = g_file_new_for_path (old_config_path);
+ if (!meta_migrate_old_monitors_config (config_store,
+ old_config_file,
+ &error))
+ g_error ("Failed to migrated config: %s", error->message);
+
+ emulate_hotplug (test_setup);
+
+ check_monitor_configuration (&test_case);
+
+ expected_path = g_test_get_filename (G_TEST_DIST,
+ "tests", "migration",
+ "rotated-new-finished.xml",
+ NULL);
+ expected_data = read_file (expected_path);
+ migrated_data = read_file (migrated_path);
+
+ g_assert_nonnull (expected_data);
+ g_assert_nonnull (migrated_data);
+
+ g_assert (strcmp (expected_data, migrated_data) == 0);
+
+ migrated_file = g_file_new_for_path (migrated_path);
+ if (!g_file_delete (migrated_file, NULL, &error))
+ g_error ("Failed to remove test data output file: %s", error->message);
+}
+
void
init_monitor_tests (void)
{
@@ -4720,4 +4862,7 @@ init_monitor_tests (void)
meta_test_monitor_custom_second_rotated_nonnative_config);
g_test_add_func ("/backends/monitor/custom/interlaced-config",
meta_test_monitor_custom_interlaced_config);
+
+ g_test_add_func ("/backends/monitor/migrated/rotated",
+ meta_test_monitor_migrated_rotated);
}
diff --git a/src/tests/unit-tests.c b/src/tests/unit-tests.c
index fe0b71bea..36915f4b5 100644
--- a/src/tests/unit-tests.c
+++ b/src/tests/unit-tests.c
@@ -29,6 +29,7 @@
#include "core/boxes-private.h"
#include "core/main-private.h"
#include "tests/meta-backend-test.h"
+#include "tests/monitor-config-migration-unit-tests.h"
#include "tests/monitor-unit-tests.h"
#include "tests/monitor-store-unit-tests.h"
#include "wayland/meta-wayland.h"
@@ -244,6 +245,7 @@ init_tests (int argc, char **argv)
g_test_add_func ("/core/boxes/adjecent-to", meta_test_adjecent_to);
init_monitor_store_tests ();
+ init_monitor_config_migration_tests ();
init_monitor_tests ();
}