From 1ffa089f7f46a1a7e9889792a626c74c4e0b58fb Mon Sep 17 00:00:00 2001 From: Pekka Paalanen Date: Thu, 16 Apr 2026 15:13:13 +0300 Subject: [PATCH] tests/color-management-protocol: move parametric_cases Move all the parametric_cases definitions just above the TEST_P() using them, to be close to the code that needs them. While the diff might look odd, this is really just moving the one big block of code verbatim. Signed-off-by: Pekka Paalanen --- tests/color-management-protocol-test.c | 742 ++++++++++++------------- 1 file changed, 371 insertions(+), 371 deletions(-) diff --git a/tests/color-management-protocol-test.c b/tests/color-management-protocol-test.c index 2b749b94d..82a040ef1 100644 --- a/tests/color-management-protocol-test.c +++ b/tests/color-management-protocol-test.c @@ -35,6 +35,377 @@ #include "color-manager-client.h" #include "lcms_util.h" +static char srgb_icc_profile_path[500] = "\0"; + +const struct lcms_pipeline pipeline_sRGB = { + .color_space = "sRGB", + .prim_output = { + .Red = { 0.640, 0.330, 1.0 }, + .Green = { 0.300, 0.600, 1.0 }, + .Blue = { 0.150, 0.060, 1.0 } + }, + .pre_fn = TRANSFER_FN_SRGB, + .mat = WESTON_MAT3F_IDENTITY, + .post_fn = TRANSFER_FN_SRGB_INVERSE +}; + +static void +build_sRGB_icc_profile(const char *filename) +{ + cmsHPROFILE profile; + double vcgt_exponents[COLOR_CHAN_NUM] = { 0.0 }; + bool saved; + + profile = build_lcms_matrix_shaper_profile_output(NULL, &pipeline_sRGB, + vcgt_exponents); + test_assert_ptr_not_null(profile); + + saved = cmsSaveProfileToFile(profile, filename); + test_assert_true(saved); + + cmsCloseProfile(profile); +} + +static struct color_manager_client * +color_manager_get(struct client *client) +{ + struct color_manager_client *cm = client_get_color_manager(client, 1); + + /* Weston supports all color features. */ + test_assert_u32_eq(cm->supported_features, + (1 << WP_COLOR_MANAGER_V1_FEATURE_ICC_V2_V4) | + (1 << WP_COLOR_MANAGER_V1_FEATURE_PARAMETRIC) | + (1 << WP_COLOR_MANAGER_V1_FEATURE_SET_PRIMARIES) | + (1 << WP_COLOR_MANAGER_V1_FEATURE_SET_LUMINANCES) | + (1 << WP_COLOR_MANAGER_V1_FEATURE_SET_TF_POWER) | + (1 << WP_COLOR_MANAGER_V1_FEATURE_SET_MASTERING_DISPLAY_PRIMARIES) | + (1 << WP_COLOR_MANAGER_V1_FEATURE_EXTENDED_TARGET_VOLUME)); + + /* Weston supports all rendering intents. */ + test_assert_u32_eq(cm->supported_rendering_intents, + (1 << WP_COLOR_MANAGER_V1_RENDER_INTENT_PERCEPTUAL) | + (1 << WP_COLOR_MANAGER_V1_RENDER_INTENT_RELATIVE) | + /* (1 << WP_COLOR_MANAGER_V1_RENDER_INTENT_SATURATION) | */ + (1 << WP_COLOR_MANAGER_V1_RENDER_INTENT_ABSOLUTE) | + (1 << WP_COLOR_MANAGER_V1_RENDER_INTENT_RELATIVE_BPC)); + + /* Weston supports all primaries. */ + test_assert_u32_eq(cm->supported_primaries, + (1 << WP_COLOR_MANAGER_V1_PRIMARIES_SRGB) | + (1 << WP_COLOR_MANAGER_V1_PRIMARIES_PAL_M) | + (1 << WP_COLOR_MANAGER_V1_PRIMARIES_PAL) | + (1 << WP_COLOR_MANAGER_V1_PRIMARIES_NTSC) | + (1 << WP_COLOR_MANAGER_V1_PRIMARIES_GENERIC_FILM) | + (1 << WP_COLOR_MANAGER_V1_PRIMARIES_BT2020) | + (1 << WP_COLOR_MANAGER_V1_PRIMARIES_CIE1931_XYZ) | + (1 << WP_COLOR_MANAGER_V1_PRIMARIES_DCI_P3) | + (1 << WP_COLOR_MANAGER_V1_PRIMARIES_DISPLAY_P3) | + (1 << WP_COLOR_MANAGER_V1_PRIMARIES_ADOBE_RGB)); + + /* Weston supports only a few transfer functions, and we make use of + * them in our tests. */ + test_assert_u32_eq(cm->supported_tf, + (1 << WP_COLOR_MANAGER_V1_TRANSFER_FUNCTION_GAMMA22) | + (1 << WP_COLOR_MANAGER_V1_TRANSFER_FUNCTION_GAMMA28) | + (1 << WP_COLOR_MANAGER_V1_TRANSFER_FUNCTION_EXT_LINEAR) | + (1 << WP_COLOR_MANAGER_V1_TRANSFER_FUNCTION_ST2084_PQ)); + + test_assert_true(cm->init_done); + + return cm; +} + +static enum test_result_code +fixture_setup(struct weston_test_harness *harness) +{ + struct compositor_setup setup; + + compositor_setup_defaults(&setup); + setup.renderer = WESTON_RENDERER_GL; + setup.shell = SHELL_TEST_DESKTOP; + setup.refresh = HIGHEST_OUTPUT_REFRESH; /* create_client_and_test_surface() */ + setup.logging_scopes = "log,color-lcms-profiles"; + + /* Create the sRGB ICC profile. We do that only once for this test + * program. */ + if (strlen(srgb_icc_profile_path) == 0) { + char *tmp; + + tmp = output_filename_for_test_program(THIS_TEST_NAME, + NULL, "icm"); + test_assert_int_lt(strlen(tmp), ARRAY_LENGTH(srgb_icc_profile_path)); + strcpy(srgb_icc_profile_path, tmp); + free(tmp); + + build_sRGB_icc_profile(srgb_icc_profile_path); + } + + weston_ini_setup(&setup, + cfgln("[core]"), + cfgln("color-management=true")); + + return weston_test_harness_execute_as_client(harness, &setup); +} +DECLARE_FIXTURE_SETUP(fixture_setup); + + +TEST(create_image_description_before_setting_icc_file) +{ + struct client *client; + struct color_manager_client *cm; + struct wp_image_description_creator_icc_v1 *image_descr_creator_icc; + struct wp_image_description_v1 *image_desc; + + client = create_client_and_test_surface(100, 100, 100, 100); + cm = color_manager_get(client); + + image_descr_creator_icc = + wp_color_manager_v1_create_icc_creator(cm->manager_proxy); + + /* Try creating image description based on ICC profile but without + * setting the ICC file, what should fail. + * + * We expect a protocol error from unknown object, because the + * image_descr_creator_icc wl_proxy will get destroyed with the create + * call below. It is a destructor request. */ + image_desc = wp_image_description_creator_icc_v1_create(image_descr_creator_icc); + expect_protocol_error(client, NULL, + WP_IMAGE_DESCRIPTION_CREATOR_ICC_V1_ERROR_INCOMPLETE_SET); + + wp_image_description_v1_destroy(image_desc); + client_destroy(client); + + return RESULT_OK; +} + +TEST(set_unreadable_icc_fd) +{ + struct client *client; + struct color_manager_client *cm; + struct wp_image_description_creator_icc_v1 *image_descr_creator_icc; + int32_t icc_fd; + struct stat st; + + client = create_client_and_test_surface(100, 100, 100, 100); + cm = color_manager_get(client); + + image_descr_creator_icc = + wp_color_manager_v1_create_icc_creator(cm->manager_proxy); + + /* The file is being open with WRITE, not READ permission. So the + * compositor should complain. */ + icc_fd = open(srgb_icc_profile_path, O_WRONLY); + test_assert_s32_ge(icc_fd, 0); + test_assert_int_eq(fstat(icc_fd, &st), 0); + + /* Try setting the bad ICC file fd, it should fail. */ + wp_image_description_creator_icc_v1_set_icc_file(image_descr_creator_icc, + icc_fd, 0, st.st_size); + expect_protocol_error(client, &wp_image_description_creator_icc_v1_interface, + WP_IMAGE_DESCRIPTION_CREATOR_ICC_V1_ERROR_BAD_FD); + + close(icc_fd); + wp_image_description_creator_icc_v1_destroy(image_descr_creator_icc); + client_destroy(client); + + return RESULT_OK; +} + +TEST(set_bad_icc_size_zero) +{ + struct client *client; + struct color_manager_client *cm; + struct wp_image_description_creator_icc_v1 *image_descr_creator_icc; + int32_t icc_fd; + + client = create_client_and_test_surface(100, 100, 100, 100); + cm = color_manager_get(client); + + image_descr_creator_icc = + wp_color_manager_v1_create_icc_creator(cm->manager_proxy); + + icc_fd = open(srgb_icc_profile_path, O_RDONLY); + test_assert_s32_ge(icc_fd, 0); + + /* Try setting ICC file with a bad size, it should fail. */ + wp_image_description_creator_icc_v1_set_icc_file(image_descr_creator_icc, + icc_fd, 0, 0); + expect_protocol_error(client, &wp_image_description_creator_icc_v1_interface, + WP_IMAGE_DESCRIPTION_CREATOR_ICC_V1_ERROR_BAD_SIZE); + + close(icc_fd); + wp_image_description_creator_icc_v1_destroy(image_descr_creator_icc); + client_destroy(client); + + return RESULT_OK; +} + +TEST(set_bad_icc_non_seekable) +{ + struct client *client; + struct color_manager_client *cm; + struct wp_image_description_creator_icc_v1 *image_descr_creator_icc; + int32_t fds[2]; + + client = create_client_and_test_surface(100, 100, 100, 100); + cm = color_manager_get(client); + + image_descr_creator_icc = + wp_color_manager_v1_create_icc_creator(cm->manager_proxy); + + /* We need a non-seekable file, and pipes are non-seekable. */ + test_assert_int_ge(pipe(fds), 0); + + /* Pretend that it has a valid size of 1024 bytes. That still should + * fail because the fd is non-seekable. */ + wp_image_description_creator_icc_v1_set_icc_file(image_descr_creator_icc, + fds[0], 0, 1024); + expect_protocol_error(client, &wp_image_description_creator_icc_v1_interface, + WP_IMAGE_DESCRIPTION_CREATOR_ICC_V1_ERROR_BAD_FD); + + close(fds[0]); + close(fds[1]); + wp_image_description_creator_icc_v1_destroy(image_descr_creator_icc); + client_destroy(client); + + return RESULT_OK; +} + +TEST(set_icc_twice) +{ + struct client *client; + struct color_manager_client *cm; + struct wp_image_description_creator_icc_v1 *image_descr_creator_icc; + int32_t icc_fd; + struct stat st; + + client = create_client_and_test_surface(100, 100, 100, 100); + cm = color_manager_get(client); + + image_descr_creator_icc = + wp_color_manager_v1_create_icc_creator(cm->manager_proxy); + + icc_fd = open(srgb_icc_profile_path, O_RDONLY); + test_assert_s32_ge(icc_fd, 0); + test_assert_int_eq(fstat(icc_fd, &st), 0); + + wp_image_description_creator_icc_v1_set_icc_file(image_descr_creator_icc, + icc_fd, 0, st.st_size); + client_roundtrip(client); + + /* Set the ICC again, what should fail. */ + wp_image_description_creator_icc_v1_set_icc_file(image_descr_creator_icc, + icc_fd, 0, st.st_size); + expect_protocol_error(client, &wp_image_description_creator_icc_v1_interface, + WP_IMAGE_DESCRIPTION_CREATOR_ICC_V1_ERROR_ALREADY_SET); + + close(icc_fd); + wp_image_description_creator_icc_v1_destroy(image_descr_creator_icc); + client_destroy(client); + + return RESULT_OK; +} + +TEST(create_icc_image_description_no_info) +{ + struct client *client; + struct color_manager_client *cm; + struct image_description *image_descr; + struct wp_image_description_info_v1 *proxy; + + client = create_client_and_test_surface(100, 100, 100, 100); + cm = color_manager_get(client); + + /* Create image description based on ICC profile */ + image_descr = image_description_create_for_icc(cm, srgb_icc_profile_path); + image_description_wait_until_ready(client, image_descr); + + /* Get image description information, and that should fail. Images + * descriptions that we create do not accept this request. */ + proxy = wp_image_description_v1_get_information(image_descr->proxy); + expect_protocol_error(client, &wp_image_description_v1_interface, + WP_IMAGE_DESCRIPTION_V1_ERROR_NO_INFORMATION); + + wp_image_description_info_v1_destroy(proxy); + image_description_destroy(image_descr); + client_destroy(client); + + return RESULT_OK; +} + +TEST(get_surface_twice_bad) +{ + struct client *client; + struct color_manager_client *cm; + struct wp_color_management_surface_v1 *cm_surface[2]; + + client = create_client_and_test_surface(100, 100, 100, 100); + cm = color_manager_get(client); + + cm_surface[0] = wp_color_manager_v1_get_surface(cm->manager_proxy, client->surface->wl_surface); + cm_surface[1] = wp_color_manager_v1_get_surface(cm->manager_proxy, client->surface->wl_surface); + + expect_protocol_error(client, &wp_color_manager_v1_interface, + WP_COLOR_MANAGER_V1_ERROR_SURFACE_EXISTS); + + wp_color_management_surface_v1_destroy(cm_surface[1]); + wp_color_management_surface_v1_destroy(cm_surface[0]); + client_destroy(client); + + return RESULT_OK; +} + +TEST(get_surface_twice_good) +{ + struct client *client; + struct color_manager_client *cm; + struct wp_color_management_surface_v1 *cm_surface; + + client = create_client_and_test_surface(100, 100, 100, 100); + cm = color_manager_get(client); + + cm_surface = wp_color_manager_v1_get_surface(cm->manager_proxy, client->surface->wl_surface); + wp_color_management_surface_v1_destroy(cm_surface); + cm_surface = wp_color_manager_v1_get_surface(cm->manager_proxy, client->surface->wl_surface); + wp_color_management_surface_v1_destroy(cm_surface); + client_roundtrip(client); + client_destroy(client); + + return RESULT_OK; +} + +TEST(set_surface_image_description) +{ + struct client *client; + struct color_manager_client *cm; + struct image_description *image_descr; + struct wp_color_management_surface_v1 *cm_surface; + + client = create_client_and_test_surface(100, 100, 100, 100); + cm = color_manager_get(client); + + cm_surface = wp_color_manager_v1_get_surface(cm->manager_proxy, client->surface->wl_surface); + + /* Create image description based on ICC profile */ + image_descr = image_description_create_for_icc(cm, srgb_icc_profile_path); + image_description_wait_until_ready(client, image_descr); + + /* Set surface image description */ + wp_color_management_surface_v1_set_image_description(cm_surface, + image_descr->proxy, + WP_COLOR_MANAGER_V1_RENDER_INTENT_PERCEPTUAL); + wl_surface_attach(client->surface->wl_surface, client->surface->buffer->proxy, 0, 0); + wl_surface_damage(client->surface->wl_surface, 0, 0, 1000, 1000); + wl_surface_commit(client->surface->wl_surface); + client_roundtrip(client); + + wp_color_management_surface_v1_destroy(cm_surface); + image_description_destroy(image_descr); + client_destroy(client); + + return RESULT_OK; +} + #define NOT_SET -99 #define BAD_ENUM 99999 @@ -418,377 +789,6 @@ static const struct parametric_case parametric_cases[] = { }, }; -static char srgb_icc_profile_path[500] = "\0"; - -const struct lcms_pipeline pipeline_sRGB = { - .color_space = "sRGB", - .prim_output = { - .Red = { 0.640, 0.330, 1.0 }, - .Green = { 0.300, 0.600, 1.0 }, - .Blue = { 0.150, 0.060, 1.0 } - }, - .pre_fn = TRANSFER_FN_SRGB, - .mat = WESTON_MAT3F_IDENTITY, - .post_fn = TRANSFER_FN_SRGB_INVERSE -}; - -static void -build_sRGB_icc_profile(const char *filename) -{ - cmsHPROFILE profile; - double vcgt_exponents[COLOR_CHAN_NUM] = { 0.0 }; - bool saved; - - profile = build_lcms_matrix_shaper_profile_output(NULL, &pipeline_sRGB, - vcgt_exponents); - test_assert_ptr_not_null(profile); - - saved = cmsSaveProfileToFile(profile, filename); - test_assert_true(saved); - - cmsCloseProfile(profile); -} - -static struct color_manager_client * -color_manager_get(struct client *client) -{ - struct color_manager_client *cm = client_get_color_manager(client, 1); - - /* Weston supports all color features. */ - test_assert_u32_eq(cm->supported_features, - (1 << WP_COLOR_MANAGER_V1_FEATURE_ICC_V2_V4) | - (1 << WP_COLOR_MANAGER_V1_FEATURE_PARAMETRIC) | - (1 << WP_COLOR_MANAGER_V1_FEATURE_SET_PRIMARIES) | - (1 << WP_COLOR_MANAGER_V1_FEATURE_SET_LUMINANCES) | - (1 << WP_COLOR_MANAGER_V1_FEATURE_SET_TF_POWER) | - (1 << WP_COLOR_MANAGER_V1_FEATURE_SET_MASTERING_DISPLAY_PRIMARIES) | - (1 << WP_COLOR_MANAGER_V1_FEATURE_EXTENDED_TARGET_VOLUME)); - - /* Weston supports all rendering intents. */ - test_assert_u32_eq(cm->supported_rendering_intents, - (1 << WP_COLOR_MANAGER_V1_RENDER_INTENT_PERCEPTUAL) | - (1 << WP_COLOR_MANAGER_V1_RENDER_INTENT_RELATIVE) | - /* (1 << WP_COLOR_MANAGER_V1_RENDER_INTENT_SATURATION) | */ - (1 << WP_COLOR_MANAGER_V1_RENDER_INTENT_ABSOLUTE) | - (1 << WP_COLOR_MANAGER_V1_RENDER_INTENT_RELATIVE_BPC)); - - /* Weston supports all primaries. */ - test_assert_u32_eq(cm->supported_primaries, - (1 << WP_COLOR_MANAGER_V1_PRIMARIES_SRGB) | - (1 << WP_COLOR_MANAGER_V1_PRIMARIES_PAL_M) | - (1 << WP_COLOR_MANAGER_V1_PRIMARIES_PAL) | - (1 << WP_COLOR_MANAGER_V1_PRIMARIES_NTSC) | - (1 << WP_COLOR_MANAGER_V1_PRIMARIES_GENERIC_FILM) | - (1 << WP_COLOR_MANAGER_V1_PRIMARIES_BT2020) | - (1 << WP_COLOR_MANAGER_V1_PRIMARIES_CIE1931_XYZ) | - (1 << WP_COLOR_MANAGER_V1_PRIMARIES_DCI_P3) | - (1 << WP_COLOR_MANAGER_V1_PRIMARIES_DISPLAY_P3) | - (1 << WP_COLOR_MANAGER_V1_PRIMARIES_ADOBE_RGB)); - - /* Weston supports only a few transfer functions, and we make use of - * them in our tests. */ - test_assert_u32_eq(cm->supported_tf, - (1 << WP_COLOR_MANAGER_V1_TRANSFER_FUNCTION_GAMMA22) | - (1 << WP_COLOR_MANAGER_V1_TRANSFER_FUNCTION_GAMMA28) | - (1 << WP_COLOR_MANAGER_V1_TRANSFER_FUNCTION_EXT_LINEAR) | - (1 << WP_COLOR_MANAGER_V1_TRANSFER_FUNCTION_ST2084_PQ)); - - test_assert_true(cm->init_done); - - return cm; -} - -static enum test_result_code -fixture_setup(struct weston_test_harness *harness) -{ - struct compositor_setup setup; - - compositor_setup_defaults(&setup); - setup.renderer = WESTON_RENDERER_GL; - setup.shell = SHELL_TEST_DESKTOP; - setup.refresh = HIGHEST_OUTPUT_REFRESH; /* create_client_and_test_surface() */ - setup.logging_scopes = "log,color-lcms-profiles"; - - /* Create the sRGB ICC profile. We do that only once for this test - * program. */ - if (strlen(srgb_icc_profile_path) == 0) { - char *tmp; - - tmp = output_filename_for_test_program(THIS_TEST_NAME, - NULL, "icm"); - test_assert_int_lt(strlen(tmp), ARRAY_LENGTH(srgb_icc_profile_path)); - strcpy(srgb_icc_profile_path, tmp); - free(tmp); - - build_sRGB_icc_profile(srgb_icc_profile_path); - } - - weston_ini_setup(&setup, - cfgln("[core]"), - cfgln("color-management=true")); - - return weston_test_harness_execute_as_client(harness, &setup); -} -DECLARE_FIXTURE_SETUP(fixture_setup); - - -TEST(create_image_description_before_setting_icc_file) -{ - struct client *client; - struct color_manager_client *cm; - struct wp_image_description_creator_icc_v1 *image_descr_creator_icc; - struct wp_image_description_v1 *image_desc; - - client = create_client_and_test_surface(100, 100, 100, 100); - cm = color_manager_get(client); - - image_descr_creator_icc = - wp_color_manager_v1_create_icc_creator(cm->manager_proxy); - - /* Try creating image description based on ICC profile but without - * setting the ICC file, what should fail. - * - * We expect a protocol error from unknown object, because the - * image_descr_creator_icc wl_proxy will get destroyed with the create - * call below. It is a destructor request. */ - image_desc = wp_image_description_creator_icc_v1_create(image_descr_creator_icc); - expect_protocol_error(client, NULL, - WP_IMAGE_DESCRIPTION_CREATOR_ICC_V1_ERROR_INCOMPLETE_SET); - - wp_image_description_v1_destroy(image_desc); - client_destroy(client); - - return RESULT_OK; -} - -TEST(set_unreadable_icc_fd) -{ - struct client *client; - struct color_manager_client *cm; - struct wp_image_description_creator_icc_v1 *image_descr_creator_icc; - int32_t icc_fd; - struct stat st; - - client = create_client_and_test_surface(100, 100, 100, 100); - cm = color_manager_get(client); - - image_descr_creator_icc = - wp_color_manager_v1_create_icc_creator(cm->manager_proxy); - - /* The file is being open with WRITE, not READ permission. So the - * compositor should complain. */ - icc_fd = open(srgb_icc_profile_path, O_WRONLY); - test_assert_s32_ge(icc_fd, 0); - test_assert_int_eq(fstat(icc_fd, &st), 0); - - /* Try setting the bad ICC file fd, it should fail. */ - wp_image_description_creator_icc_v1_set_icc_file(image_descr_creator_icc, - icc_fd, 0, st.st_size); - expect_protocol_error(client, &wp_image_description_creator_icc_v1_interface, - WP_IMAGE_DESCRIPTION_CREATOR_ICC_V1_ERROR_BAD_FD); - - close(icc_fd); - wp_image_description_creator_icc_v1_destroy(image_descr_creator_icc); - client_destroy(client); - - return RESULT_OK; -} - -TEST(set_bad_icc_size_zero) -{ - struct client *client; - struct color_manager_client *cm; - struct wp_image_description_creator_icc_v1 *image_descr_creator_icc; - int32_t icc_fd; - - client = create_client_and_test_surface(100, 100, 100, 100); - cm = color_manager_get(client); - - image_descr_creator_icc = - wp_color_manager_v1_create_icc_creator(cm->manager_proxy); - - icc_fd = open(srgb_icc_profile_path, O_RDONLY); - test_assert_s32_ge(icc_fd, 0); - - /* Try setting ICC file with a bad size, it should fail. */ - wp_image_description_creator_icc_v1_set_icc_file(image_descr_creator_icc, - icc_fd, 0, 0); - expect_protocol_error(client, &wp_image_description_creator_icc_v1_interface, - WP_IMAGE_DESCRIPTION_CREATOR_ICC_V1_ERROR_BAD_SIZE); - - close(icc_fd); - wp_image_description_creator_icc_v1_destroy(image_descr_creator_icc); - client_destroy(client); - - return RESULT_OK; -} - -TEST(set_bad_icc_non_seekable) -{ - struct client *client; - struct color_manager_client *cm; - struct wp_image_description_creator_icc_v1 *image_descr_creator_icc; - int32_t fds[2]; - - client = create_client_and_test_surface(100, 100, 100, 100); - cm = color_manager_get(client); - - image_descr_creator_icc = - wp_color_manager_v1_create_icc_creator(cm->manager_proxy); - - /* We need a non-seekable file, and pipes are non-seekable. */ - test_assert_int_ge(pipe(fds), 0); - - /* Pretend that it has a valid size of 1024 bytes. That still should - * fail because the fd is non-seekable. */ - wp_image_description_creator_icc_v1_set_icc_file(image_descr_creator_icc, - fds[0], 0, 1024); - expect_protocol_error(client, &wp_image_description_creator_icc_v1_interface, - WP_IMAGE_DESCRIPTION_CREATOR_ICC_V1_ERROR_BAD_FD); - - close(fds[0]); - close(fds[1]); - wp_image_description_creator_icc_v1_destroy(image_descr_creator_icc); - client_destroy(client); - - return RESULT_OK; -} - -TEST(set_icc_twice) -{ - struct client *client; - struct color_manager_client *cm; - struct wp_image_description_creator_icc_v1 *image_descr_creator_icc; - int32_t icc_fd; - struct stat st; - - client = create_client_and_test_surface(100, 100, 100, 100); - cm = color_manager_get(client); - - image_descr_creator_icc = - wp_color_manager_v1_create_icc_creator(cm->manager_proxy); - - icc_fd = open(srgb_icc_profile_path, O_RDONLY); - test_assert_s32_ge(icc_fd, 0); - test_assert_int_eq(fstat(icc_fd, &st), 0); - - wp_image_description_creator_icc_v1_set_icc_file(image_descr_creator_icc, - icc_fd, 0, st.st_size); - client_roundtrip(client); - - /* Set the ICC again, what should fail. */ - wp_image_description_creator_icc_v1_set_icc_file(image_descr_creator_icc, - icc_fd, 0, st.st_size); - expect_protocol_error(client, &wp_image_description_creator_icc_v1_interface, - WP_IMAGE_DESCRIPTION_CREATOR_ICC_V1_ERROR_ALREADY_SET); - - close(icc_fd); - wp_image_description_creator_icc_v1_destroy(image_descr_creator_icc); - client_destroy(client); - - return RESULT_OK; -} - -TEST(create_icc_image_description_no_info) -{ - struct client *client; - struct color_manager_client *cm; - struct image_description *image_descr; - struct wp_image_description_info_v1 *proxy; - - client = create_client_and_test_surface(100, 100, 100, 100); - cm = color_manager_get(client); - - /* Create image description based on ICC profile */ - image_descr = image_description_create_for_icc(cm, srgb_icc_profile_path); - image_description_wait_until_ready(client, image_descr); - - /* Get image description information, and that should fail. Images - * descriptions that we create do not accept this request. */ - proxy = wp_image_description_v1_get_information(image_descr->proxy); - expect_protocol_error(client, &wp_image_description_v1_interface, - WP_IMAGE_DESCRIPTION_V1_ERROR_NO_INFORMATION); - - wp_image_description_info_v1_destroy(proxy); - image_description_destroy(image_descr); - client_destroy(client); - - return RESULT_OK; -} - -TEST(get_surface_twice_bad) -{ - struct client *client; - struct color_manager_client *cm; - struct wp_color_management_surface_v1 *cm_surface[2]; - - client = create_client_and_test_surface(100, 100, 100, 100); - cm = color_manager_get(client); - - cm_surface[0] = wp_color_manager_v1_get_surface(cm->manager_proxy, client->surface->wl_surface); - cm_surface[1] = wp_color_manager_v1_get_surface(cm->manager_proxy, client->surface->wl_surface); - - expect_protocol_error(client, &wp_color_manager_v1_interface, - WP_COLOR_MANAGER_V1_ERROR_SURFACE_EXISTS); - - wp_color_management_surface_v1_destroy(cm_surface[1]); - wp_color_management_surface_v1_destroy(cm_surface[0]); - client_destroy(client); - - return RESULT_OK; -} - -TEST(get_surface_twice_good) -{ - struct client *client; - struct color_manager_client *cm; - struct wp_color_management_surface_v1 *cm_surface; - - client = create_client_and_test_surface(100, 100, 100, 100); - cm = color_manager_get(client); - - cm_surface = wp_color_manager_v1_get_surface(cm->manager_proxy, client->surface->wl_surface); - wp_color_management_surface_v1_destroy(cm_surface); - cm_surface = wp_color_manager_v1_get_surface(cm->manager_proxy, client->surface->wl_surface); - wp_color_management_surface_v1_destroy(cm_surface); - client_roundtrip(client); - client_destroy(client); - - return RESULT_OK; -} - -TEST(set_surface_image_description) -{ - struct client *client; - struct color_manager_client *cm; - struct image_description *image_descr; - struct wp_color_management_surface_v1 *cm_surface; - - client = create_client_and_test_surface(100, 100, 100, 100); - cm = color_manager_get(client); - - cm_surface = wp_color_manager_v1_get_surface(cm->manager_proxy, client->surface->wl_surface); - - /* Create image description based on ICC profile */ - image_descr = image_description_create_for_icc(cm, srgb_icc_profile_path); - image_description_wait_until_ready(client, image_descr); - - /* Set surface image description */ - wp_color_management_surface_v1_set_image_description(cm_surface, - image_descr->proxy, - WP_COLOR_MANAGER_V1_RENDER_INTENT_PERCEPTUAL); - wl_surface_attach(client->surface->wl_surface, client->surface->buffer->proxy, 0, 0); - wl_surface_damage(client->surface->wl_surface, 0, 0, 1000, 1000); - wl_surface_commit(client->surface->wl_surface); - client_roundtrip(client); - - wp_color_management_surface_v1_destroy(cm_surface); - image_description_destroy(image_descr); - client_destroy(client); - - return RESULT_OK; -} - TEST_P(create_parametric_image_description, parametric_cases) { struct client *client;