[mutter] tests: Add duplicate color profile test case
- From: Marge Bot <marge-bot src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [mutter] tests: Add duplicate color profile test case
- Date: Thu, 15 Sep 2022 11:51:00 +0000 (UTC)
commit da04ae4ca579f37fd0311272aea362baa45c62a4
Author: Jonas Ã…dahl <jadahl gmail com>
Date: Tue Sep 13 18:28:41 2022 +0200
tests: Add duplicate color profile test case
This adds a copy of the calibration test profile and sets up a test to
first add it as a system profile, then setting up the XDG_DATA_HOME
directory so that the duplicate profile is detected, added, and later
discarded.
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2622>
src/backends/meta-color-manager-private.h | 1 +
src/backends/meta-color-store.c | 14 +++
src/backends/meta-color-store.h | 8 ++
src/tests/color-management-profile-conflict-test.c | 139 +++++++++++++++++++++
src/tests/meson.build | 5 +
src/tests/share/icc/vx239-calibrated.icc | Bin 0 -> 3068 bytes
6 files changed, 167 insertions(+)
---
diff --git a/src/backends/meta-color-manager-private.h b/src/backends/meta-color-manager-private.h
index 3e5e52360d..6a2a989aaa 100644
--- a/src/backends/meta-color-manager-private.h
+++ b/src/backends/meta-color-manager-private.h
@@ -31,6 +31,7 @@ struct _MetaColorManagerClass
CdClient * meta_color_manager_get_cd_client (MetaColorManager *color_manager);
+META_EXPORT_TEST
MetaColorStore * meta_color_manager_get_color_store (MetaColorManager *color_manager);
META_EXPORT_TEST
diff --git a/src/backends/meta-color-store.c b/src/backends/meta-color-store.c
index f8624274c1..c60fd21ff3 100644
--- a/src/backends/meta-color-store.c
+++ b/src/backends/meta-color-store.c
@@ -750,3 +750,17 @@ meta_color_store_ensure_colord_profile_finish (MetaColorStore *color_store,
return g_task_propagate_pointer (G_TASK (res), error);
}
+
+MetaColorProfile *
+meta_color_store_get_profile (MetaColorStore *color_store,
+ const char *profile_id)
+{
+ return g_hash_table_lookup (color_store->profiles, profile_id);
+}
+
+gboolean
+meta_color_store_has_pending_profiles (MetaColorStore *color_store)
+{
+ return (g_hash_table_size (color_store->pending_local_profiles) > 0 ||
+ g_hash_table_size (color_store->pending_device_profiles) > 0);
+}
diff --git a/src/backends/meta-color-store.h b/src/backends/meta-color-store.h
index 5634dae762..1ebd1762c1 100644
--- a/src/backends/meta-color-store.h
+++ b/src/backends/meta-color-store.h
@@ -23,6 +23,7 @@
#include <glib-object.h>
#include "backends/meta-backend-types.h"
+#include "core/util-private.h"
#define META_TYPE_COLOR_STORE (meta_color_store_get_type ())
G_DECLARE_FINAL_TYPE (MetaColorStore, meta_color_store,
@@ -51,4 +52,11 @@ MetaColorProfile * meta_color_store_ensure_colord_profile_finish (MetaColorStore
GAsyncResult *res,
GError **error);
+META_EXPORT_TEST
+MetaColorProfile * meta_color_store_get_profile (MetaColorStore *color_store,
+ const char *profile_id);
+
+META_EXPORT_TEST
+gboolean meta_color_store_has_pending_profiles (MetaColorStore *color_store);
+
#endif /* META_COLOR_STORE_H */
diff --git a/src/tests/color-management-profile-conflict-test.c
b/src/tests/color-management-profile-conflict-test.c
new file mode 100644
index 0000000000..d07ccc216a
--- /dev/null
+++ b/src/tests/color-management-profile-conflict-test.c
@@ -0,0 +1,139 @@
+/*
+ * Copyright (C) 2022 Red Hat
+ *
+ * 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 <fcntl.h>
+
+#include "backends/meta-color-manager-private.h"
+#include "backends/meta-color-profile.h"
+#include "backends/meta-color-store.h"
+#include "meta-test/meta-context-test.h"
+#include "tests/meta-monitor-test-utils.h"
+
+#define VX239_ICC_PROFILE_ID "icc-c5e479355c02452dd30c1256a154a8f4"
+
+static MetaContext *test_context;
+
+static GDBusProxy *
+get_colord_mock_proxy (void)
+{
+ GDBusProxy *proxy;
+ g_autoptr (GError) error = NULL;
+ g_autoptr (GVariant) ret = NULL;
+
+ proxy =
+ g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
+ G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START |
+ G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS,
+ NULL,
+ "org.freedesktop.ColorManager",
+ "/org/freedesktop/ColorManager",
+ "org.freedesktop.DBus.Mock",
+ NULL, &error);
+ if (!proxy)
+ {
+ g_error ("Failed to find mocked color manager system service, %s",
+ error->message);
+ }
+
+ return proxy;
+}
+
+static void
+add_colord_system_profile (const char *cd_profile_id,
+ const char *file_path)
+{
+ GDBusProxy *proxy;
+ g_autoptr (GError) error = NULL;
+ GVariantBuilder params_builder;
+
+ proxy = get_colord_mock_proxy ();
+
+ g_variant_builder_init (¶ms_builder, G_VARIANT_TYPE ("(ss)"));
+ g_variant_builder_add (¶ms_builder, "s", cd_profile_id);
+ g_variant_builder_add (¶ms_builder, "s", file_path);
+
+ if (!g_dbus_proxy_call_sync (proxy,
+ "AddSystemProfile",
+ g_variant_builder_end (¶ms_builder),
+ G_DBUS_CALL_FLAGS_NO_AUTO_START, -1, NULL,
+ &error))
+ g_error ("Failed to add system profile: %s", error->message);
+}
+
+static void
+meta_test_color_profile_conflicts (void)
+{
+ MetaBackend *backend = meta_context_get_backend (test_context);
+ MetaColorManager *color_manager =
+ meta_backend_get_color_manager (backend);
+ MetaColorStore *color_store;
+
+ while (!meta_color_manager_is_ready (color_manager))
+ g_main_context_iteration (NULL, TRUE);
+
+ color_store = meta_color_manager_get_color_store (color_manager);
+ while (meta_color_store_has_pending_profiles (color_store))
+ g_main_context_iteration (NULL, TRUE);
+
+ g_assert_null (meta_color_store_get_profile (color_store,
+ VX239_ICC_PROFILE_ID));
+}
+
+static void
+init_tests (void)
+{
+ g_test_add_func ("/color-manegement/profile/conflict",
+ meta_test_color_profile_conflicts);
+}
+
+int
+main (int argc, char **argv)
+{
+ g_autoptr (MetaContext) context = NULL;
+ g_autofree char *system_profile_path = NULL;
+ g_autofree char *data_home_path = NULL;
+
+ context = meta_create_test_context (META_CONTEXT_TEST_TYPE_HEADLESS,
+ META_CONTEXT_TEST_FLAG_NONE);
+
+ g_assert (meta_context_configure (context, &argc, &argv, NULL));
+
+ system_profile_path = g_test_build_filename (G_TEST_DIST,
+ "tests",
+ "icc-profiles",
+ "vx239-calibrated.icc",
+ NULL);
+ add_colord_system_profile (VX239_ICC_PROFILE_ID, system_profile_path);
+
+ data_home_path = g_test_build_filename (G_TEST_DIST,
+ "tests",
+ "share",
+ NULL);
+ g_setenv ("XDG_DATA_HOME", data_home_path, TRUE);
+
+ test_context = context;
+
+ init_tests ();
+
+ return meta_context_test_run_tests (META_CONTEXT_TEST (context),
+ META_TEST_RUN_FLAG_NONE);
+}
diff --git a/src/tests/meson.build b/src/tests/meson.build
index 74de095245..99efa984e9 100644
--- a/src/tests/meson.build
+++ b/src/tests/meson.build
@@ -239,6 +239,11 @@ test_cases += [
'suite': 'unit',
'sources': [ 'color-management-tests.c', ],
},
+ {
+ 'name': 'color-management-profile-conflict',
+ 'suite': 'unit',
+ 'sources': [ 'color-management-profile-conflict-test.c', ],
+ },
]
if have_native_tests
diff --git a/src/tests/share/icc/vx239-calibrated.icc b/src/tests/share/icc/vx239-calibrated.icc
new file mode 100644
index 0000000000..7c4ccd1f66
Binary files /dev/null and b/src/tests/share/icc/vx239-calibrated.icc differ
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]