From 2ed4e6bee4ee7659405862f5ff311429c44338f5 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 19 Dec 2022 01:19:06 +0100 Subject: [PATCH] Improve wxImage::ChangeColours test code Use a helper function to both make it shorter and provide more information in case of a check failure: now the output will include the name of the file, comparing with which failed, allowing to immediately see which test failed. --- tests/image/image.cpp | 39 +++++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/tests/image/image.cpp b/tests/image/image.cpp index 14da358f13..ee5cbc4caf 100644 --- a/tests/image/image.cpp +++ b/tests/image/image.cpp @@ -2276,6 +2276,21 @@ TEST_CASE("wxImage::PNM", "[image][pnm]") #endif } +namespace +{ + +inline ImageRGBMatcher RGBSimilarToFile(const char* name) +{ + INFO("Loading file from " << name); + + wxImage expected; + REQUIRE(expected.LoadFile(name)); + + return ImageRGBMatcher(expected, 1); +} + +} // anonymous namespace + TEST_CASE("wxImage::ChangeColours", "[image]") { wxImage original; @@ -2286,43 +2301,35 @@ TEST_CASE("wxImage::ChangeColours", "[image]") test = original; test.RotateHue(0.538); - REQUIRE(expected.LoadFile("image/toucan_hue_0.538.png", wxBITMAP_TYPE_PNG)); - CHECK_THAT(test, RGBSimilarTo(expected, 1)); + CHECK_THAT(test, RGBSimilarToFile("image/toucan_hue_0.538.png")); test = original; test.ChangeSaturation(-0.41); - REQUIRE(expected.LoadFile("image/toucan_sat_-0.41.png", wxBITMAP_TYPE_PNG)); - CHECK_THAT(test, RGBSimilarTo(expected, 1)); + CHECK_THAT(test, RGBSimilarToFile("image/toucan_sat_-0.41.png")); test = original; test.ChangeBrightness(-0.259); - REQUIRE(expected.LoadFile("image/toucan_bright_-0.259.png", wxBITMAP_TYPE_PNG)); - CHECK_THAT(test, RGBSimilarTo(expected, 1)); + CHECK_THAT(test, RGBSimilarToFile("image/toucan_bright_-0.259.png")); test = original; test.ChangeHSV(0.538, -0.41, -0.259); - REQUIRE(expected.LoadFile("image/toucan_hsv_0.538_-0.41_-0.259.png", wxBITMAP_TYPE_PNG)); - CHECK_THAT(test, RGBSimilarTo(expected, 1)); + CHECK_THAT(test, RGBSimilarToFile("image/toucan_hsv_0.538_-0.41_-0.259.png")); test = original; test = test.ChangeLightness(46); - REQUIRE(expected.LoadFile("image/toucan_light_46.png", wxBITMAP_TYPE_PNG)); - CHECK_THAT(test, RGBSimilarTo(expected, 1)); + CHECK_THAT(test, RGBSimilarToFile("image/toucan_light_46.png")); test = original; test = test.ConvertToDisabled(240); - REQUIRE(expected.LoadFile("image/toucan_dis_240.png", wxBITMAP_TYPE_PNG)); - CHECK_THAT(test, RGBSimilarTo(expected, 1)); + CHECK_THAT(test, RGBSimilarToFile("image/toucan_dis_240.png")); test = original; test = test.ConvertToGreyscale(); - REQUIRE(expected.LoadFile("image/toucan_grey.png", wxBITMAP_TYPE_PNG)); - CHECK_THAT(test, RGBSimilarTo(expected, 1)); + CHECK_THAT(test, RGBSimilarToFile("image/toucan_grey.png")); test = original; test = test.ConvertToMono(255, 255, 255); - REQUIRE(expected.LoadFile("image/toucan_mono_255_255_255.png", wxBITMAP_TYPE_PNG)); - CHECK_THAT(test, RGBSimilarTo(expected, 1)); + CHECK_THAT(test, RGBSimilarToFile("image/toucan_mono_255_255_255.png")); } TEST_CASE("wxImage::SizeLimits", "[image]")