Check wxImageList validity in all of its methods

Some of wxImageList methods asserted when called on an invalid image
list while others just failed silently.

Assert in all of them now for consistency and to help detecting problems
in the code using invalid wxImageList objects.

Extend the documentation and the tests.
This commit is contained in:
Vadim Zeitlin 2022-11-26 19:52:09 +01:00
parent 7ad48bd045
commit 5c6bce627b
5 changed files with 48 additions and 8 deletions

View file

@ -609,11 +609,11 @@ TEST_CASE("ImageList:NegativeTests", "[imagelist][negative]")
CHECK(h == 0);
#endif
int idx = il.Add(bmp);
CHECK(idx == -1);
#ifdef __WXDEBUG__
CHECK_THROWS(il.Add(bmp));
REQUIRE_THROWS(il.GetImageCount());
#else
CHECK(il.Add(bmp) == -1);
CHECK(il.GetImageCount() == 0);
#endif
}
@ -644,23 +644,33 @@ TEST_CASE("ImageList:NegativeTests", "[imagelist][negative]")
CHECK(h == 0);
#endif
int idx = il.Add(bmp);
CHECK(idx == -1);
#ifdef __WXDEBUG__
CHECK_THROWS(il.Add(bmp));
REQUIRE_THROWS(il.GetImageCount());
#else
CHECK(il.Add(bmp) == -1);
CHECK(il.GetImageCount() == 0);
#endif
ok = il.Replace(0, bmp);
CHECK_FALSE(ok);
#ifdef __WXDEBUG__
CHECK_THROWS(il.Replace(0, bmp));
REQUIRE_THROWS(il.GetImageCount());
#else
CHECK_FALSE(il.Replace(0, bmp));
CHECK(il.GetImageCount() == 0);
#endif
}
SECTION("Add to invalid image list")
{
wxImageList il;
#ifdef __WXDEBUG__
CHECK_THROWS( il.Add(bmp) );
#else
CHECK( il.Add(bmp) == -1 );
#endif
}
SECTION("Invalid Get/Replace/Remove indices")
{
wxImageList il(32, 32, false);