Add tests of wxImageList

This is a basic test set.
This commit is contained in:
Artur Wieczorek
2021-01-12 17:58:51 +01:00
parent 838e45fd9b
commit 030664c148
12 changed files with 278 additions and 4 deletions

View File

@@ -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

View File

@@ -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);
}
}

BIN
tests/image/wx.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

BIN
tests/image/wx.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

View File

@@ -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) $<

View File

@@ -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

View File

@@ -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
</files>
</wx-data>

View File

@@ -552,6 +552,7 @@
<ClCompile Include="graphics\graphpath.cpp" />
<ClCompile Include="graphics\colour.cpp" />
<ClCompile Include="graphics\ellipsization.cpp" />
<ClCompile Include="graphics\imagelist.cpp" />
<ClCompile Include="graphics\measuring.cpp" />
<ClCompile Include="html\htmlparser.cpp" />
<ClCompile Include="html\htmlwindow.cpp" />
@@ -585,4 +586,4 @@
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
</Project>

View File

@@ -308,6 +308,9 @@
<ClCompile Include="controls\auitest.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="graphics\imagelist.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="..\samples\sample.rc">

View File

@@ -457,6 +457,9 @@
<File
RelativePath=".\image\image.cpp">
</File>
<File
RelativePath=".\graphics\imagelist.cpp">
</File>
<File
RelativePath=".\controls\itemcontainertest.cpp">
</File>

View File

@@ -1078,6 +1078,10 @@
RelativePath=".\image\image.cpp"
>
</File>
<File
RelativePath=".\graphics\imagelist.cpp"
>
</File>
<File
RelativePath=".\controls\itemcontainertest.cpp"
>

View File

@@ -1050,6 +1050,10 @@
RelativePath=".\image\image.cpp"
>
</File>
<File
RelativePath=".\graphics\imagelist.cpp"
>
</File>
<File
RelativePath=".\controls\itemcontainertest.cpp"
>