diff --git a/tests/game/PowerIndexBounds.cpp b/tests/game/PowerIndexBounds.cpp new file mode 100644 index 0000000000..671c0b529d --- /dev/null +++ b/tests/game/PowerIndexBounds.cpp @@ -0,0 +1,16 @@ +#include "tc_catch2.h" +#include "DB2Stores.h" +#include + +TEST_CASE("Class power lookup rejects out of range resource identifiers", "[PowerIndexBounds]") +{ + for (uint32 classId : { uint32(CLASS_WARRIOR), uint32(CLASS_HUNTER), uint32(CLASS_PRIEST), uint32(CLASS_SHAMAN) }) + { + CAPTURE(classId); + // REQUIRE stops the unfixed lookup before the much larger invalid indices. + REQUIRE(DB2Manager::GetPowerIndexByClass(Powers(MAX_POWERS), classId) == MAX_POWERS_PER_CLASS); + CHECK(DB2Manager::GetPowerIndexByClass(Powers(MAX_POWERS + 1), classId) == MAX_POWERS_PER_CLASS); + CHECK(DB2Manager::GetPowerIndexByClass(Powers(-1), classId) == MAX_POWERS_PER_CLASS); + CHECK(DB2Manager::GetPowerIndexByClass(Powers(std::numeric_limits::max()), classId) == MAX_POWERS_PER_CLASS); + } +}