From da04ae4ca579f37fd0311272aea362baa45c62a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20=C3=85dahl?= Date: Tue, 13 Sep 2022 18:28:41 +0200 Subject: [PATCH] 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: --- src/backends/meta-color-manager-private.h | 1 + src/backends/meta-color-store.c | 14 ++ src/backends/meta-color-store.h | 8 + .../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(+) create mode 100644 src/tests/color-management-profile-conflict-test.c create mode 100644 src/tests/share/icc/vx239-calibrated.icc diff --git a/src/backends/meta-color-manager-private.h b/src/backends/meta-color-manager-private.h index 3e5e52360..6a2a989aa 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 f8624274c..c60fd21ff 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 5634dae76..1ebd1762c 100644 --- a/src/backends/meta-color-store.h +++ b/src/backends/meta-color-store.h @@ -23,6 +23,7 @@ #include #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 000000000..d07ccc216 --- /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 + +#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 74de09524..99efa984e 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 0000000000000000000000000000000000000000..7c4ccd1f664ba25b83398d02bcf3750c77114481 GIT binary patch literal 3068 zcmcguc{tQx7r#Sj3L!}$qqJw=Qg*Ur--Q}uW-ysWGh<05%DzO_Mk*?jLLw!F7KKP8 zZCZ$winqkCB=er3?RlTy@BQQbw+w2?q$1sOXy*r2~}7=*^VfeY=v5-(Saz2d^JaaYA_vf{Ee&Ybo9 z`>l$+J^~X%xVbfF(oOLBQe55|nQdyd=@%w2*(|WH1$an;ZsnN600B!omeH8GaNh83)jhNhaeMez-t7Bb1IKGJJe=cPbd8n!H6@zC1DayRgV!}#mGu^t-=CR!zdmRUYV~kUwbG=KOYo}YQ zd!0w|mLyMqF9UCJ@0VN8ZVSO1`e1!J2}gYciTWf7(tC2NU#0)?01kz-{X}3jwS)GV zAs1w`Ba&Ie8V}YA2@S2?iNeixCG2jE5ZP-T85?zV-$=AfjB%__TxfhuLTuu$BvP_T zige1rfitOrX)Ds6AIwNMPyd=xn(3RhIO}2dp&a}nWsU&nb#BMuro7f8y~nWmrUl8z z`%hXHUOJ^(Tv4KP=6b1p*|T$j72}nAs<_oVFTSgBynMFy>s9SKLVb8cbAKc2nO>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