diff --git a/tests/Makefile.in b/tests/Makefile.in index f99b4761e1..3d0e621afc 100644 --- a/tests/Makefile.in +++ b/tests/Makefile.in @@ -188,6 +188,7 @@ TEST_GUI_OBJECTS = \ test_gui_coords.o \ test_gui_graphmatrix.o \ test_gui_graphpath.o \ + test_gui_imagelist.o \ test_gui_config.o \ test_gui_auitest.o \ test_gui_bitmapcomboboxtest.o \ @@ -548,7 +549,7 @@ data: data-images: @mkdir -p image - @for f in horse_grey.bmp horse_grey_flipped.bmp horse_rle4.bmp horse_rle4_flipped.bmp horse_rle8.bmp horse_rle8_flipped.bmp horse_bicubic_50x50.png horse_bicubic_100x100.png horse_bicubic_150x150.png horse_bicubic_300x300.png horse_bilinear_50x50.png horse_bilinear_100x100.png horse_bilinear_150x150.png horse_bilinear_300x300.png horse_box_average_50x50.png horse_box_average_100x100.png horse_box_average_150x150.png horse_box_average_300x300.png cross_bicubic_256x256.png cross_bilinear_256x256.png cross_box_average_256x256.png cross_nearest_neighb_256x256.png paste_input_background.png paste_input_black.png paste_input_overlay_transparent_border_opaque_square.png paste_input_overlay_transparent_border_semitransparent_circle.png paste_input_overlay_transparent_border_semitransparent_square.png paste_result_background_plus_circle_plus_square.png paste_result_background_plus_overlay_transparent_border_opaque_square.png paste_result_background_plus_overlay_transparent_border_semitransparent_square.png paste_result_no_background_square_over_circle.png; do \ + @for f in horse_grey.bmp horse_grey_flipped.bmp horse_rle4.bmp horse_rle4_flipped.bmp horse_rle8.bmp horse_rle8_flipped.bmp horse_bicubic_50x50.png horse_bicubic_100x100.png horse_bicubic_150x150.png horse_bicubic_300x300.png horse_bilinear_50x50.png horse_bilinear_100x100.png horse_bilinear_150x150.png horse_bilinear_300x300.png horse_box_average_50x50.png horse_box_average_100x100.png horse_box_average_150x150.png horse_box_average_300x300.png cross_bicubic_256x256.png cross_bilinear_256x256.png cross_box_average_256x256.png cross_nearest_neighb_256x256.png paste_input_background.png paste_input_black.png paste_input_overlay_transparent_border_opaque_square.png paste_input_overlay_transparent_border_semitransparent_circle.png paste_input_overlay_transparent_border_semitransparent_square.png paste_result_background_plus_circle_plus_square.png paste_result_background_plus_overlay_transparent_border_opaque_square.png paste_result_background_plus_overlay_transparent_border_semitransparent_square.png paste_result_no_background_square_over_circle.png wx.png wx.ico; do \ if test ! -f image/$$f -a ! -d image/$$f ; \ then x=yep ; \ else x=`find $(srcdir)/image/$$f -newer image/$$f -print` ; \ @@ -909,6 +910,9 @@ test_gui_graphmatrix.o: $(srcdir)/graphics/graphmatrix.cpp $(TEST_GUI_ODEP) test_gui_graphpath.o: $(srcdir)/graphics/graphpath.cpp $(TEST_GUI_ODEP) $(CXXC) -c -o $@ $(TEST_GUI_CXXFLAGS) $(srcdir)/graphics/graphpath.cpp +test_gui_imagelist.o: $(srcdir)/graphics/imagelist.cpp $(TEST_GUI_ODEP) + $(CXXC) -c -o $@ $(TEST_GUI_CXXFLAGS) $(srcdir)/graphics/imagelist.cpp + test_gui_config.o: $(srcdir)/config/config.cpp $(TEST_GUI_ODEP) $(CXXC) -c -o $@ $(TEST_GUI_CXXFLAGS) $(srcdir)/config/config.cpp diff --git a/tests/graphics/imagelist.cpp b/tests/graphics/imagelist.cpp new file mode 100644 index 0000000000..57bdefbf14 --- /dev/null +++ b/tests/graphics/imagelist.cpp @@ -0,0 +1,243 @@ +/////////////////////////////////////////////////////////////////////////////// +// Name: tests/graphics/imagelist.cpp +// Purpose: image list unit tests +// Author: Artur Wieczorek +// Created: 2021-01-11 +// Copyright: (c) 2021 wxWidgets development team +/////////////////////////////////////////////////////////////////////////////// + +// ---------------------------------------------------------------------------- +// headers +// ---------------------------------------------------------------------------- + +#include "testprec.h" + + +#include "wx/bitmap.h" +#include "wx/graphics.h" +#include "wx/icon.h" +#include "wx/imaglist.h" + +#include "wx/dcmemory.h" + +// ---------------------------------------------------------------------------- +// tests +// ---------------------------------------------------------------------------- + +TEST_CASE("ImageList:WithMask", "[imagelist][withmask]") +{ + 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, true); + + SECTION("Add RGB image to list") + { + il.RemoveAll(); + int idx = il.Add(bmpRGB); + CHECK(il.GetImageCount() == 1); + wxBitmap bmp1 = il.GetBitmap(idx); + CHECK(bmp1.HasAlpha() == false); + CHECK(bmp1.GetMask() != NULL); + CHECK(bmp1.GetWidth() == 32); + CHECK(bmp1.GetHeight() == 32); + + idx = il.Add(bmpRGBWithMask); + CHECK(il.GetImageCount() == 2); + wxBitmap bmp2 = il.GetBitmap(idx); + CHECK(bmp2.HasAlpha() == false); + CHECK(bmp2.GetMask() != NULL); + CHECK(bmp2.GetWidth() == 32); + CHECK(bmp2.GetHeight() == 32); + } + + SECTION("Add RGBA image to list") + { + il.RemoveAll(); + int idx = il.Add(bmpRGBA); + CHECK(il.GetImageCount() == 1); + wxBitmap bmp1 = il.GetBitmap(idx); + CHECK(bmp1.HasAlpha() == false); + CHECK(bmp1.GetMask() != NULL); + CHECK(bmp1.GetWidth() == 32); + CHECK(bmp1.GetHeight() == 32); + + idx = il.Add(bmpRGBAWithMask); + CHECK(il.GetImageCount() == 2); + wxBitmap bmp2 = il.GetBitmap(idx); + CHECK(bmp2.HasAlpha() == false); + CHECK(bmp2.GetMask() != NULL); + CHECK(bmp2.GetWidth() == 32); + CHECK(bmp2.GetHeight() == 32); + } + + SECTION("Add icon to list") + { + il.RemoveAll(); + int idx = il.Add(ico); + CHECK(il.GetImageCount() == 1); + wxIcon icon1 = il.GetIcon(idx); + CHECK(icon1.GetWidth() == 32); + CHECK(icon1.GetHeight() == 32); + } +} + +TEST_CASE("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") + { + il.RemoveAll(); + int idx = il.Add(bmpRGB); + CHECK(il.GetImageCount() == 1); + wxBitmap bmp1 = il.GetBitmap(idx); + CHECK(bmp1.HasAlpha() == false); + CHECK(bmp1.GetMask() == NULL); + CHECK(bmp1.GetWidth() == 32); + CHECK(bmp1.GetHeight() == 32); + + idx = il.Add(bmpRGBWithMask); + CHECK(il.GetImageCount() == 2); + wxBitmap bmp2 = il.GetBitmap(idx); + CHECK(bmp2.HasAlpha() == true); + CHECK(bmp2.GetMask() == NULL); + CHECK(bmp2.GetWidth() == 32); + CHECK(bmp2.GetHeight() == 32); + } + + SECTION("Add RGBA image to list") + { + il.RemoveAll(); + int idx = il.Add(bmpRGBA); + CHECK(il.GetImageCount() == 1); + wxBitmap bmp1 = il.GetBitmap(idx); + CHECK(bmp1.HasAlpha() == true); + CHECK(bmp1.GetMask() == NULL); + CHECK(bmp1.GetWidth() == 32); + CHECK(bmp1.GetHeight() == 32); + + idx = il.Add(bmpRGBAWithMask); + CHECK(il.GetImageCount() == 2); + wxBitmap bmp2 = il.GetBitmap(idx); + CHECK(bmp2.HasAlpha() == true); + CHECK(bmp2.GetMask() == NULL); + CHECK(bmp2.GetWidth() == 32); + CHECK(bmp2.GetHeight() == 32); + } + + SECTION("Add icon to list") + { + il.RemoveAll(); + int idx = il.Add(ico); + CHECK(il.GetImageCount() == 1); + wxIcon icon1 = il.GetIcon(idx); + CHECK(icon1.GetWidth() == 32); + CHECK(icon1.GetHeight() == 32); + } +} diff --git a/tests/image/wx.ico b/tests/image/wx.ico new file mode 100644 index 0000000000..435cca2471 Binary files /dev/null and b/tests/image/wx.ico differ diff --git a/tests/image/wx.png b/tests/image/wx.png new file mode 100644 index 0000000000..4a0a502497 Binary files /dev/null and b/tests/image/wx.png differ diff --git a/tests/makefile.gcc b/tests/makefile.gcc index 4ba87cfaf9..4c1b269f2e 100644 --- a/tests/makefile.gcc +++ b/tests/makefile.gcc @@ -164,6 +164,7 @@ TEST_GUI_OBJECTS = \ $(OBJS)\test_gui_coords.o \ $(OBJS)\test_gui_graphmatrix.o \ $(OBJS)\test_gui_graphpath.o \ + $(OBJS)\test_gui_imagelist.o \ $(OBJS)\test_gui_config.o \ $(OBJS)\test_gui_auitest.o \ $(OBJS)\test_gui_bitmapcomboboxtest.o \ @@ -550,7 +551,7 @@ data: data-images: if not exist image mkdir image - for %%f in (horse_grey.bmp horse_grey_flipped.bmp horse_rle4.bmp horse_rle4_flipped.bmp horse_rle8.bmp horse_rle8_flipped.bmp horse_bicubic_50x50.png horse_bicubic_100x100.png horse_bicubic_150x150.png horse_bicubic_300x300.png horse_bilinear_50x50.png horse_bilinear_100x100.png horse_bilinear_150x150.png horse_bilinear_300x300.png horse_box_average_50x50.png horse_box_average_100x100.png horse_box_average_150x150.png horse_box_average_300x300.png cross_bicubic_256x256.png cross_bilinear_256x256.png cross_box_average_256x256.png cross_nearest_neighb_256x256.png paste_input_background.png paste_input_black.png paste_input_overlay_transparent_border_opaque_square.png paste_input_overlay_transparent_border_semitransparent_circle.png paste_input_overlay_transparent_border_semitransparent_square.png paste_result_background_plus_circle_plus_square.png paste_result_background_plus_overlay_transparent_border_opaque_square.png paste_result_background_plus_overlay_transparent_border_semitransparent_square.png paste_result_no_background_square_over_circle.png) do if not exist image\%%f copy .\image\%%f image + for %%f in (horse_grey.bmp horse_grey_flipped.bmp horse_rle4.bmp horse_rle4_flipped.bmp horse_rle8.bmp horse_rle8_flipped.bmp horse_bicubic_50x50.png horse_bicubic_100x100.png horse_bicubic_150x150.png horse_bicubic_300x300.png horse_bilinear_50x50.png horse_bilinear_100x100.png horse_bilinear_150x150.png horse_bilinear_300x300.png horse_box_average_50x50.png horse_box_average_100x100.png horse_box_average_150x150.png horse_box_average_300x300.png cross_bicubic_256x256.png cross_bilinear_256x256.png cross_box_average_256x256.png cross_nearest_neighb_256x256.png paste_input_background.png paste_input_black.png paste_input_overlay_transparent_border_opaque_square.png paste_input_overlay_transparent_border_semitransparent_circle.png paste_input_overlay_transparent_border_semitransparent_square.png paste_result_background_plus_circle_plus_square.png paste_result_background_plus_overlay_transparent_border_opaque_square.png paste_result_background_plus_overlay_transparent_border_semitransparent_square.png paste_result_no_background_square_over_circle.png wx.png wx.ico) do if not exist image\%%f copy .\image\%%f image fr: if not exist $(OBJS)\intl\fr mkdir $(OBJS)\intl\fr @@ -896,6 +897,9 @@ $(OBJS)\test_gui_graphmatrix.o: ./graphics/graphmatrix.cpp $(OBJS)\test_gui_graphpath.o: ./graphics/graphpath.cpp $(CXX) -c -o $@ $(TEST_GUI_CXXFLAGS) $(CPPDEPS) $< +$(OBJS)\test_gui_imagelist.o: ./graphics/imagelist.cpp + $(CXX) -c -o $@ $(TEST_GUI_CXXFLAGS) $(CPPDEPS) $< + $(OBJS)\test_gui_config.o: ./config/config.cpp $(CXX) -c -o $@ $(TEST_GUI_CXXFLAGS) $(CPPDEPS) $< diff --git a/tests/makefile.vc b/tests/makefile.vc index c5652c9a21..75a60a9972 100644 --- a/tests/makefile.vc +++ b/tests/makefile.vc @@ -180,6 +180,7 @@ TEST_GUI_OBJECTS = \ $(OBJS)\test_gui_coords.obj \ $(OBJS)\test_gui_graphmatrix.obj \ $(OBJS)\test_gui_graphpath.obj \ + $(OBJS)\test_gui_imagelist.obj \ $(OBJS)\test_gui_config.obj \ $(OBJS)\test_gui_auitest.obj \ $(OBJS)\test_gui_bitmapcomboboxtest.obj \ @@ -984,7 +985,7 @@ data: data-images: if not exist image mkdir image - for %f in (horse_grey.bmp horse_grey_flipped.bmp horse_rle4.bmp horse_rle4_flipped.bmp horse_rle8.bmp horse_rle8_flipped.bmp horse_bicubic_50x50.png horse_bicubic_100x100.png horse_bicubic_150x150.png horse_bicubic_300x300.png horse_bilinear_50x50.png horse_bilinear_100x100.png horse_bilinear_150x150.png horse_bilinear_300x300.png horse_box_average_50x50.png horse_box_average_100x100.png horse_box_average_150x150.png horse_box_average_300x300.png cross_bicubic_256x256.png cross_bilinear_256x256.png cross_box_average_256x256.png cross_nearest_neighb_256x256.png paste_input_background.png paste_input_black.png paste_input_overlay_transparent_border_opaque_square.png paste_input_overlay_transparent_border_semitransparent_circle.png paste_input_overlay_transparent_border_semitransparent_square.png paste_result_background_plus_circle_plus_square.png paste_result_background_plus_overlay_transparent_border_opaque_square.png paste_result_background_plus_overlay_transparent_border_semitransparent_square.png paste_result_no_background_square_over_circle.png) do if not exist image\%f copy .\image\%f image + for %f in (horse_grey.bmp horse_grey_flipped.bmp horse_rle4.bmp horse_rle4_flipped.bmp horse_rle8.bmp horse_rle8_flipped.bmp horse_bicubic_50x50.png horse_bicubic_100x100.png horse_bicubic_150x150.png horse_bicubic_300x300.png horse_bilinear_50x50.png horse_bilinear_100x100.png horse_bilinear_150x150.png horse_bilinear_300x300.png horse_box_average_50x50.png horse_box_average_100x100.png horse_box_average_150x150.png horse_box_average_300x300.png cross_bicubic_256x256.png cross_bilinear_256x256.png cross_box_average_256x256.png cross_nearest_neighb_256x256.png paste_input_background.png paste_input_black.png paste_input_overlay_transparent_border_opaque_square.png paste_input_overlay_transparent_border_semitransparent_circle.png paste_input_overlay_transparent_border_semitransparent_square.png paste_result_background_plus_circle_plus_square.png paste_result_background_plus_overlay_transparent_border_opaque_square.png paste_result_background_plus_overlay_transparent_border_semitransparent_square.png paste_result_no_background_square_over_circle.png wx.png wx.ico) do if not exist image\%f copy .\image\%f image fr: if not exist $(OBJS)\intl\fr mkdir $(OBJS)\intl\fr @@ -1330,6 +1331,9 @@ $(OBJS)\test_gui_graphmatrix.obj: .\graphics\graphmatrix.cpp $(OBJS)\test_gui_graphpath.obj: .\graphics\graphpath.cpp $(CXX) /c /nologo /TP /Fo$@ $(TEST_GUI_CXXFLAGS) .\graphics\graphpath.cpp +$(OBJS)\test_gui_imagelist.obj: .\graphics\imagelist.cpp + $(CXX) /c /nologo /TP /Fo$@ $(TEST_GUI_CXXFLAGS) .\graphics\imagelist.cpp + $(OBJS)\test_gui_config.obj: .\config\config.cpp $(CXX) /c /nologo /TP /Fo$@ $(TEST_GUI_CXXFLAGS) .\config\config.cpp diff --git a/tests/test.bkl b/tests/test.bkl index 0aa49e95cd..fae9cf2741 100644 --- a/tests/test.bkl +++ b/tests/test.bkl @@ -184,6 +184,7 @@ graphics/coords.cpp graphics/graphmatrix.cpp graphics/graphpath.cpp + graphics/imagelist.cpp config/config.cpp controls/auitest.cpp controls/bitmapcomboboxtest.cpp @@ -370,6 +371,9 @@ paste_result_background_plus_overlay_transparent_border_opaque_square.png paste_result_background_plus_overlay_transparent_border_semitransparent_square.png paste_result_no_background_square_over_circle.png + + wx.png + wx.ico diff --git a/tests/test_gui.vcxproj b/tests/test_gui.vcxproj index 7032b4ce33..4f3b74f828 100644 --- a/tests/test_gui.vcxproj +++ b/tests/test_gui.vcxproj @@ -552,6 +552,7 @@ + @@ -585,4 +586,4 @@ - + \ No newline at end of file diff --git a/tests/test_gui.vcxproj.filters b/tests/test_gui.vcxproj.filters index 0eede89fd6..4745342ec7 100644 --- a/tests/test_gui.vcxproj.filters +++ b/tests/test_gui.vcxproj.filters @@ -308,6 +308,9 @@ Source Files + + Source Files + diff --git a/tests/test_vc7_test_gui.vcproj b/tests/test_vc7_test_gui.vcproj index ec237145b5..d9b85333e6 100644 --- a/tests/test_vc7_test_gui.vcproj +++ b/tests/test_vc7_test_gui.vcproj @@ -457,6 +457,9 @@ + + diff --git a/tests/test_vc8_test_gui.vcproj b/tests/test_vc8_test_gui.vcproj index dd1700c187..8ca2296c17 100644 --- a/tests/test_vc8_test_gui.vcproj +++ b/tests/test_vc8_test_gui.vcproj @@ -1078,6 +1078,10 @@ RelativePath=".\image\image.cpp" > + + diff --git a/tests/test_vc9_test_gui.vcproj b/tests/test_vc9_test_gui.vcproj index ff01099d23..64697d8977 100644 --- a/tests/test_vc9_test_gui.vcproj +++ b/tests/test_vc9_test_gui.vcproj @@ -1050,6 +1050,10 @@ RelativePath=".\image\image.cpp" > + +