From 1ed13da86e7e46473cb048b5223a98cb2ebea1aa Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 18 May 2022 15:33:29 +0100 Subject: [PATCH 1/4] Factor out common initialization code in wxImageList tests No changes, just stop duplicating exactly the same initialization code for the tests with and without masks. --- tests/graphics/imagelist.cpp | 89 +++++++++++------------------------- 1 file changed, 26 insertions(+), 63 deletions(-) diff --git a/tests/graphics/imagelist.cpp b/tests/graphics/imagelist.cpp index ea62a8db65..83f3055d2d 100644 --- a/tests/graphics/imagelist.cpp +++ b/tests/graphics/imagelist.cpp @@ -51,14 +51,25 @@ static bool HasMaskOrAlpha(const wxBitmap& bmp) } // ---------------------------------------------------------------------------- -// tests +// test fixture // ---------------------------------------------------------------------------- -TEST_CASE("ImageList:WithMask", "[imagelist][withmask]") +class ImageListTestCase +{ +protected: + ImageListTestCase(); + + wxBitmap bmpRGB, bmpRGBA, bmpMask, + bmpRGBWithMask, bmpRGBAWithMask; + wxIcon ico; +}; + +ImageListTestCase::ImageListTestCase() + : bmpRGB(32, 32, 24), + bmpMask(32, 32, 1) { wxInitAllImageHandlers(); - wxBitmap bmpRGB(32, 32, 24); { wxMemoryDC mdc(bmpRGB); mdc.SetBackground(*wxBLUE_BRUSH); @@ -68,11 +79,9 @@ TEST_CASE("ImageList:WithMask", "[imagelist][withmask]") } REQUIRE(bmpRGB.IsOk()); - wxBitmap bmpRGBA; bmpRGBA.LoadFile("image/wx.png", wxBITMAP_TYPE_PNG); REQUIRE(bmpRGBA.IsOk()); - wxBitmap bmpMask(32, 32, 1); { wxMemoryDC mdc(bmpMask); #if wxUSE_GRAPHICS_CONTEXT @@ -86,15 +95,14 @@ TEST_CASE("ImageList:WithMask", "[imagelist][withmask]") mdc.DrawRectangle(0, 0, 16, 32); } - wxBitmap bmpRGBWithMask(bmpRGB); + bmpRGBWithMask = bmpRGB; bmpRGBWithMask.SetMask(new wxMask(bmpMask)); REQUIRE(bmpRGBWithMask.IsOk()); - wxBitmap bmpRGBAWithMask(bmpRGBA); + bmpRGBAWithMask = bmpRGBA; bmpRGBAWithMask.SetMask(new wxMask(bmpMask)); REQUIRE(bmpRGBAWithMask.IsOk()); - wxIcon ico; ico.LoadFile("image/wx.ico", wxBITMAP_TYPE_ICO); REQUIRE(ico.IsOk()); @@ -109,7 +117,15 @@ TEST_CASE("ImageList:WithMask", "[imagelist][withmask]") REQUIRE(bmpRGBAWithMask.HasAlpha() == true); REQUIRE(bmpRGBAWithMask.GetMask() != NULL); +} +// ---------------------------------------------------------------------------- +// tests +// ---------------------------------------------------------------------------- + +TEST_CASE_METHOD(ImageListTestCase, + "ImageList:WithMask", "[imagelist][withmask]") +{ wxImageList il(32, 32, true); SECTION("Add RGB image to list") @@ -454,62 +470,9 @@ TEST_CASE("ImageList:WithMask", "[imagelist][withmask]") } } -TEST_CASE("ImageList:NoMask", "[imagelist][nomask]") +TEST_CASE_METHOD(ImageListTestCase, + "ImageList:NoMask", "[imagelist][nomask]") { - wxInitAllImageHandlers(); - - wxBitmap bmpRGB(32, 32, 24); - { - wxMemoryDC mdc(bmpRGB); - mdc.SetBackground(*wxBLUE_BRUSH); - mdc.Clear(); - mdc.SetBrush(*wxRED_BRUSH); - mdc.DrawRectangle(4, 4, 24, 24); - } - REQUIRE(bmpRGB.IsOk()); - - wxBitmap bmpRGBA; - bmpRGBA.LoadFile("image/wx.png", wxBITMAP_TYPE_PNG); - REQUIRE(bmpRGBA.IsOk()); - - wxBitmap bmpMask(32, 32, 1); - { - wxMemoryDC mdc(bmpMask); -#if wxUSE_GRAPHICS_CONTEXT - wxGraphicsContext* gc = mdc.GetGraphicsContext(); - if ( gc ) - gc->SetAntialiasMode(wxANTIALIAS_NONE); -#endif //wxUSE_GRAPHICS_CONTEXT - mdc.SetBackground(*wxBLACK_BRUSH); - mdc.Clear(); - mdc.SetBrush(*wxWHITE_BRUSH); - mdc.DrawRectangle(0, 0, 16, 32); - } - - wxBitmap bmpRGBWithMask(bmpRGB); - bmpRGBWithMask.SetMask(new wxMask(bmpMask)); - REQUIRE(bmpRGBWithMask.IsOk()); - - wxBitmap bmpRGBAWithMask(bmpRGBA); - bmpRGBAWithMask.SetMask(new wxMask(bmpMask)); - REQUIRE(bmpRGBAWithMask.IsOk()); - - wxIcon ico; - ico.LoadFile("image/wx.ico", wxBITMAP_TYPE_ICO); - REQUIRE(ico.IsOk()); - - REQUIRE(bmpRGB.HasAlpha() == false); - REQUIRE(bmpRGB.GetMask() == NULL); - - REQUIRE(bmpRGBWithMask.HasAlpha() == false); - REQUIRE(bmpRGBWithMask.GetMask() != NULL); - - REQUIRE(bmpRGBA.HasAlpha() == true); - REQUIRE(bmpRGBA.GetMask() == NULL); - - REQUIRE(bmpRGBAWithMask.HasAlpha() == true); - REQUIRE(bmpRGBAWithMask.GetMask() != NULL); - wxImageList il(32, 32, false); SECTION("Add RGB image to list") From 2373b4ca24e115219364514b882d2ebca2ab7b6b Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 18 May 2022 15:40:55 +0100 Subject: [PATCH 2/4] Construct the test bitmaps directly in wxImageList test code Don't use external image files, this makes it simpler to run the test (it can be now done from any directory) and also experiment with it (e.g. by making the test image fully transparent or fully opaque). Remove the now unneeded .ico file but keep the .png one still used by another test. --- build/cmake/tests/gui/CMakeLists.txt | 1 - tests/graphics/imagelist.cpp | 14 ++++++++++---- tests/image/wx.ico | Bin 1078 -> 0 bytes 3 files changed, 10 insertions(+), 5 deletions(-) delete mode 100644 tests/image/wx.ico diff --git a/build/cmake/tests/gui/CMakeLists.txt b/build/cmake/tests/gui/CMakeLists.txt index a412248df5..9ed420cfaa 100644 --- a/build/cmake/tests/gui/CMakeLists.txt +++ b/build/cmake/tests/gui/CMakeLists.txt @@ -182,7 +182,6 @@ set(TEST_GUI_DATA image/paste_result_background_plus_overlay_transparent_border_semitransparent_square.png image/paste_result_no_background_square_over_circle.png image/wx.png - image/wx.ico image/toucan.png image/toucan_hue_0.538.png image/toucan_sat_-0.41.png diff --git a/tests/graphics/imagelist.cpp b/tests/graphics/imagelist.cpp index 83f3055d2d..a8795b562d 100644 --- a/tests/graphics/imagelist.cpp +++ b/tests/graphics/imagelist.cpp @@ -68,8 +68,6 @@ ImageListTestCase::ImageListTestCase() : bmpRGB(32, 32, 24), bmpMask(32, 32, 1) { - wxInitAllImageHandlers(); - { wxMemoryDC mdc(bmpRGB); mdc.SetBackground(*wxBLUE_BRUSH); @@ -79,7 +77,15 @@ ImageListTestCase::ImageListTestCase() } REQUIRE(bmpRGB.IsOk()); - bmpRGBA.LoadFile("image/wx.png", wxBITMAP_TYPE_PNG); + // Make a bitmap with some transparent and semi-transparent pixels. + wxImage imgWithAlpha(32, 32); + imgWithAlpha.SetAlpha(); + unsigned char* const alpha = imgWithAlpha.GetAlpha(); + for ( unsigned char* a = alpha; a < alpha + 32*32; ++a ) + *a = wxALPHA_OPAQUE; + alpha[0] = wxALPHA_TRANSPARENT; + alpha[1] = wxALPHA_OPAQUE / 2; + bmpRGBA = wxBitmap(imgWithAlpha); REQUIRE(bmpRGBA.IsOk()); { @@ -103,7 +109,7 @@ ImageListTestCase::ImageListTestCase() bmpRGBAWithMask.SetMask(new wxMask(bmpMask)); REQUIRE(bmpRGBAWithMask.IsOk()); - ico.LoadFile("image/wx.ico", wxBITMAP_TYPE_ICO); + ico.CopyFromBitmap(bmpRGBWithMask); REQUIRE(ico.IsOk()); REQUIRE(bmpRGB.HasAlpha() == false); diff --git a/tests/image/wx.ico b/tests/image/wx.ico deleted file mode 100644 index 435cca2471cd31bb825ff1e6eb180c1939a9eb4a..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1078 zcmc&zF%p6>5L_S)1H}g<-VtX@^EF=Zz9{mlQwW;#il~Wy%sJax^Jn}JGe|Bw=NmFB ge8aqPJmI~ud$Eb6)2}9ELOWr8V4xU|6W(XUPqgg+2mk;8 From 15705b3350b0bc3972fba554a3eaf9040bd9dea1 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 18 May 2022 15:49:03 +0100 Subject: [PATCH 3/4] Simplify bitmap size checks in wxImageList tests Also don't hardcode 32*32 size but make it a constant that could be changed later. --- tests/graphics/imagelist.cpp | 81 ++++++++++++++---------------------- 1 file changed, 31 insertions(+), 50 deletions(-) diff --git a/tests/graphics/imagelist.cpp b/tests/graphics/imagelist.cpp index a8795b562d..e543a1131f 100644 --- a/tests/graphics/imagelist.cpp +++ b/tests/graphics/imagelist.cpp @@ -59,14 +59,17 @@ class ImageListTestCase protected: ImageListTestCase(); + const wxSize BITMAP_SIZE; + wxBitmap bmpRGB, bmpRGBA, bmpMask, bmpRGBWithMask, bmpRGBAWithMask; wxIcon ico; }; ImageListTestCase::ImageListTestCase() - : bmpRGB(32, 32, 24), - bmpMask(32, 32, 1) + : BITMAP_SIZE(32, 32), + bmpRGB(BITMAP_SIZE, 24), + bmpMask(BITMAP_SIZE, 1) { { wxMemoryDC mdc(bmpRGB); @@ -78,10 +81,10 @@ ImageListTestCase::ImageListTestCase() REQUIRE(bmpRGB.IsOk()); // Make a bitmap with some transparent and semi-transparent pixels. - wxImage imgWithAlpha(32, 32); + wxImage imgWithAlpha(BITMAP_SIZE.x, BITMAP_SIZE.y); imgWithAlpha.SetAlpha(); unsigned char* const alpha = imgWithAlpha.GetAlpha(); - for ( unsigned char* a = alpha; a < alpha + 32*32; ++a ) + for ( unsigned char* a = alpha; a < alpha + BITMAP_SIZE.x*BITMAP_SIZE.y; ++a ) *a = wxALPHA_OPAQUE; alpha[0] = wxALPHA_TRANSPARENT; alpha[1] = wxALPHA_OPAQUE / 2; @@ -132,7 +135,7 @@ ImageListTestCase::ImageListTestCase() TEST_CASE_METHOD(ImageListTestCase, "ImageList:WithMask", "[imagelist][withmask]") { - wxImageList il(32, 32, true); + wxImageList il(BITMAP_SIZE.x, BITMAP_SIZE.y, true); SECTION("Add RGB image to list") { @@ -141,22 +144,19 @@ TEST_CASE_METHOD(ImageListTestCase, CHECK(il.GetImageCount() == 1); wxBitmap bmp1 = il.GetBitmap(idx); CHECK(HasNoRealAlpha(bmp1)); - CHECK(bmp1.GetWidth() == 32); - CHECK(bmp1.GetHeight() == 32); + CHECK(bmp1.GetSize() == BITMAP_SIZE); idx = il.Add(bmpRGBWithMask); CHECK(il.GetImageCount() == 2); wxBitmap bmp2 = il.GetBitmap(idx); CHECK(HasMaskOrAlpha(bmp2)); - CHECK(bmp2.GetWidth() == 32); - CHECK(bmp2.GetHeight() == 32); + CHECK(bmp2.GetSize() == BITMAP_SIZE); idx = il.Add(bmpRGB, *wxRED); CHECK(il.GetImageCount() == 3); wxBitmap bmp3 = il.GetBitmap(idx); CHECK(HasMaskOrAlpha(bmp3)); - CHECK(bmp3.GetWidth() == 32); - CHECK(bmp3.GetHeight() == 32); + CHECK(bmp3.GetSize() == BITMAP_SIZE); } SECTION("Add RGBA image to list") @@ -166,22 +166,19 @@ TEST_CASE_METHOD(ImageListTestCase, CHECK(il.GetImageCount() == 1); wxBitmap bmp1 = il.GetBitmap(idx); CHECK(HasMaskOrAlpha(bmp1)); - CHECK(bmp1.GetWidth() == 32); - CHECK(bmp1.GetHeight() == 32); + CHECK(bmp1.GetSize() == BITMAP_SIZE); idx = il.Add(bmpRGBAWithMask); CHECK(il.GetImageCount() == 2); wxBitmap bmp2 = il.GetBitmap(idx); CHECK(HasMaskOrAlpha(bmp2)); - CHECK(bmp2.GetWidth() == 32); - CHECK(bmp2.GetHeight() == 32); + CHECK(bmp2.GetSize() == BITMAP_SIZE); idx = il.Add(bmpRGBA, *wxRED); CHECK(il.GetImageCount() == 3); wxBitmap bmp3 = il.GetBitmap(idx); CHECK(HasMaskOrAlpha(bmp3)); - CHECK(bmp3.GetWidth() == 32); - CHECK(bmp3.GetHeight() == 32); + CHECK(bmp3.GetSize() == BITMAP_SIZE); } SECTION("Add icon to list") @@ -190,8 +187,7 @@ TEST_CASE_METHOD(ImageListTestCase, int idx = il.Add(ico); CHECK(il.GetImageCount() == 1); wxIcon icon1 = il.GetIcon(idx); - CHECK(icon1.GetWidth() == 32); - CHECK(icon1.GetHeight() == 32); + CHECK(icon1.GetSize() == BITMAP_SIZE); } SECTION("Replace with RGB image") @@ -207,13 +203,11 @@ TEST_CASE_METHOD(ImageListTestCase, wxBitmap bmp1 = il.GetBitmap(idx1); CHECK(HasMaskOrAlpha(bmp1)); - CHECK(bmp1.GetWidth() == 32); - CHECK(bmp1.GetHeight() == 32); + CHECK(bmp1.GetSize() == BITMAP_SIZE); wxBitmap bmp2 = il.GetBitmap(idx2); CHECK(HasMaskOrAlpha(bmp2)); - CHECK(bmp2.GetWidth() == 32); - CHECK(bmp2.GetHeight() == 32); + CHECK(bmp2.GetSize() == BITMAP_SIZE); } SECTION("Replace with RGBA image") @@ -229,13 +223,11 @@ TEST_CASE_METHOD(ImageListTestCase, wxBitmap bmp1 = il.GetBitmap(idx1); CHECK(HasMaskOrAlpha(bmp1)); - CHECK(bmp1.GetWidth() == 32); - CHECK(bmp1.GetHeight() == 32); + CHECK(bmp1.GetSize() == BITMAP_SIZE); wxBitmap bmp2 = il.GetBitmap(idx2); CHECK(HasMaskOrAlpha(bmp2)); - CHECK(bmp2.GetWidth() == 32); - CHECK(bmp2.GetHeight() == 32); + CHECK(bmp2.GetSize() == BITMAP_SIZE); } SECTION("Add images with incompatible sizes") @@ -479,7 +471,7 @@ TEST_CASE_METHOD(ImageListTestCase, TEST_CASE_METHOD(ImageListTestCase, "ImageList:NoMask", "[imagelist][nomask]") { - wxImageList il(32, 32, false); + wxImageList il(BITMAP_SIZE.x, BITMAP_SIZE.y, false); SECTION("Add RGB image to list") { @@ -489,22 +481,19 @@ TEST_CASE_METHOD(ImageListTestCase, wxBitmap bmp1 = il.GetBitmap(idx); CHECK(bmp1.HasAlpha() == false); CHECK(bmp1.GetMask() == NULL); - CHECK(bmp1.GetWidth() == 32); - CHECK(bmp1.GetHeight() == 32); + CHECK(bmp1.GetSize() == BITMAP_SIZE); idx = il.Add(bmpRGBWithMask); CHECK(il.GetImageCount() == 2); wxBitmap bmp2 = il.GetBitmap(idx); CHECK(HasMaskOrAlpha(bmp2)); - CHECK(bmp2.GetWidth() == 32); - CHECK(bmp2.GetHeight() == 32); + CHECK(bmp2.GetSize() == BITMAP_SIZE); idx = il.Add(bmpRGB, *wxRED); CHECK(il.GetImageCount() == 3); wxBitmap bmp3 = il.GetBitmap(idx); CHECK(HasMaskOrAlpha(bmp3)); - CHECK(bmp3.GetWidth() == 32); - CHECK(bmp3.GetHeight() == 32); + CHECK(bmp3.GetSize() == BITMAP_SIZE); } SECTION("Add RGBA image to list") @@ -515,22 +504,19 @@ TEST_CASE_METHOD(ImageListTestCase, wxBitmap bmp1 = il.GetBitmap(idx); CHECK(bmp1.HasAlpha() == true); CHECK(bmp1.GetMask() == NULL); - CHECK(bmp1.GetWidth() == 32); - CHECK(bmp1.GetHeight() == 32); + CHECK(bmp1.GetSize() == BITMAP_SIZE); idx = il.Add(bmpRGBAWithMask); CHECK(il.GetImageCount() == 2); wxBitmap bmp2 = il.GetBitmap(idx); CHECK(HasMaskOrAlpha(bmp2)); - CHECK(bmp2.GetWidth() == 32); - CHECK(bmp2.GetHeight() == 32); + CHECK(bmp2.GetSize() == BITMAP_SIZE); idx = il.Add(bmpRGBA, *wxRED); CHECK(il.GetImageCount() == 3); wxBitmap bmp3 = il.GetBitmap(idx); CHECK(HasMaskOrAlpha(bmp3)); - CHECK(bmp3.GetWidth() == 32); - CHECK(bmp3.GetHeight() == 32); + CHECK(bmp3.GetSize() == BITMAP_SIZE); } SECTION("Add icon to list") @@ -539,8 +525,7 @@ TEST_CASE_METHOD(ImageListTestCase, int idx = il.Add(ico); CHECK(il.GetImageCount() == 1); wxIcon icon1 = il.GetIcon(idx); - CHECK(icon1.GetWidth() == 32); - CHECK(icon1.GetHeight() == 32); + CHECK(icon1.GetSize() == BITMAP_SIZE); } SECTION("Replace with RGB image") @@ -557,13 +542,11 @@ TEST_CASE_METHOD(ImageListTestCase, wxBitmap bmp1 = il.GetBitmap(idx1); CHECK(bmp1.HasAlpha() == false); CHECK(bmp1.GetMask() == NULL); - CHECK(bmp1.GetWidth() == 32); - CHECK(bmp1.GetHeight() == 32); + CHECK(bmp1.GetSize() == BITMAP_SIZE); wxBitmap bmp2 = il.GetBitmap(idx2); CHECK(HasMaskOrAlpha(bmp2)); - CHECK(bmp2.GetWidth() == 32); - CHECK(bmp2.GetHeight() == 32); + CHECK(bmp2.GetSize() == BITMAP_SIZE); } SECTION("Replace with RGBA image") @@ -580,13 +563,11 @@ TEST_CASE_METHOD(ImageListTestCase, wxBitmap bmp1 = il.GetBitmap(idx1); CHECK(bmp1.HasAlpha() == true); CHECK(bmp1.GetMask() == NULL); - CHECK(bmp1.GetWidth() == 32); - CHECK(bmp1.GetHeight() == 32); + CHECK(bmp1.GetSize() == BITMAP_SIZE); wxBitmap bmp2 = il.GetBitmap(idx2); CHECK(HasMaskOrAlpha(bmp2)); - CHECK(bmp2.GetWidth() == 32); - CHECK(bmp2.GetHeight() == 32); + CHECK(bmp2.GetSize() == BITMAP_SIZE); } } From 8169464516e4a5aeff8df79817b0c1c23c4d5abc Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 23 May 2022 15:04:09 +0100 Subject: [PATCH 4/4] Suppress harmless MSVC warnings in atomic unit test The changes of 50bc3ceb04 (Get rid of CppUnit boilerplate in atomic unit test, 2022-05-11) resulted in warnings about possibly uninitialized variables in this test, so do initialize them for MSVC even if it isn't really necessary. --- tests/thread/atomic.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/thread/atomic.cpp b/tests/thread/atomic.cpp index 81c0672d7d..5ef98d532f 100644 --- a/tests/thread/atomic.cpp +++ b/tests/thread/atomic.cpp @@ -89,8 +89,8 @@ TEST_CASE("Atomic::ReturnValue", "[atomic]") TEST_CASE("Atomic::WithThreads", "[atomic]") { - int count; - ETestType testType; + int count wxDUMMY_INITIALIZE(0); + ETestType testType wxDUMMY_INITIALIZE(DecOnly); SECTION( "2 threads using inc and dec") { count = 2; testType = IncAndDecMixed; } SECTION("10 threads using inc and dec") { count = 10; testType = IncAndDecMixed; }