Kelsidavis-WoWee/tests/test_blp_loader.cpp
Paul e58f9b4b40 feat(animation): 452 named constants, 30-phase character animation state machine
Add animation_ids.hpp/cpp with all 452 WoW animation ID constants (anim::STAND,
anim::RUN, anim::FIRE_BOW, ... anim::FLY_BACKWARDS, etc.), nameFromId() O(1)
lookup, and flyVariant() compact 218-element ground→FLY_* resolver.

Expand AnimationController into a full state machine with 20+ named states:
spell cast (directed→omni→cast fallback chain, instant one-shot release),
hit reactions (WOUND/CRIT/DODGE/BLOCK/SHIELD_BLOCK), stun, wounded idle,
stealth animation substitution, loot, fishing channel, sit/sleep/kneel
down→loop→up transitions, sheathe/unsheathe combat enter/exit, ranged weapons
(BOW/GUN/CROSSBOW/THROWN with reload states), game object OPEN/CLOSE/DESTROY,
vehicle enter/exit, mount flight directionals (FLY_LEFT/RIGHT/UP/DOWN/BACKWARDS),
emote state variants, off-hand/pierce/dual-wield alternation, NPC
birth/spawn/drown/rise, sprint aura override, totem idle, NPC greeting/farewell.

Add spell_defines.hpp with SpellEffect (~45 constants) and SpellMissInfo
(12 constants) namespaces; replace all magic numbers in spell_handler.cpp.

Add GAMEOBJECT_BYTES_1 to update field table (all 4 expansion JSONs) and wire
GameObjectStateCallback. Add DBC cross-validation on world entry.

Expand tools/_ANIM_NAMES from ~35 to 452 entries in m2_viewer.py and
asset_pipeline_gui.py. Add tests/test_animation_ids.cpp.

Bug fixes included:
- Stand state 1 was animating READY_2H(27) — fixed to SITTING(97)
- Spell casts ended freeze-frame — add one-shot release animation
- NPC 2H swing probe chain missing ATTACK_2H_LOOSE (polearm/staff)
- Chair sits (states 2/4/5/6) incorrectly played floor-sit transition
- STOP(3) used for all spell casts — replaced with model-aware chain
2026-04-04 23:02:53 +03:00

92 lines
3.2 KiB
C++

// BLP loader tests: isValid, format names, invalid data handling
#include <catch_amalgamated.hpp>
#include "pipeline/blp_loader.hpp"
using wowee::pipeline::BLPLoader;
using wowee::pipeline::BLPImage;
using wowee::pipeline::BLPFormat;
using wowee::pipeline::BLPCompression;
TEST_CASE("BLPImage default is invalid", "[blp]") {
BLPImage img;
REQUIRE_FALSE(img.isValid());
REQUIRE(img.width == 0);
REQUIRE(img.height == 0);
REQUIRE(img.format == BLPFormat::UNKNOWN);
REQUIRE(img.compression == BLPCompression::NONE);
}
TEST_CASE("BLPImage isValid with data", "[blp]") {
BLPImage img;
img.width = 64;
img.height = 64;
img.data.resize(64 * 64 * 4, 0xFF); // RGBA
REQUIRE(img.isValid());
}
TEST_CASE("BLPImage isValid requires non-empty data", "[blp]") {
BLPImage img;
img.width = 64;
img.height = 64;
// data is empty
REQUIRE_FALSE(img.isValid());
}
TEST_CASE("BLPLoader::load empty data returns invalid", "[blp]") {
std::vector<uint8_t> empty;
auto img = BLPLoader::load(empty);
REQUIRE_FALSE(img.isValid());
}
TEST_CASE("BLPLoader::load too small data returns invalid", "[blp]") {
std::vector<uint8_t> tiny = {0x42, 0x4C, 0x50}; // BLP but truncated
auto img = BLPLoader::load(tiny);
REQUIRE_FALSE(img.isValid());
}
TEST_CASE("BLPLoader::load invalid magic returns invalid", "[blp]") {
// Provide enough bytes but with wrong magic
std::vector<uint8_t> bad(256, 0);
bad[0] = 'N'; bad[1] = 'O'; bad[2] = 'T'; bad[3] = '!';
auto img = BLPLoader::load(bad);
REQUIRE_FALSE(img.isValid());
}
TEST_CASE("BLPLoader getFormatName returns non-null", "[blp]") {
REQUIRE(BLPLoader::getFormatName(BLPFormat::UNKNOWN) != nullptr);
REQUIRE(BLPLoader::getFormatName(BLPFormat::BLP1) != nullptr);
REQUIRE(BLPLoader::getFormatName(BLPFormat::BLP2) != nullptr);
// Check that names are distinct
REQUIRE(std::string(BLPLoader::getFormatName(BLPFormat::BLP1)) !=
std::string(BLPLoader::getFormatName(BLPFormat::BLP2)));
}
TEST_CASE("BLPLoader getCompressionName returns non-null", "[blp]") {
REQUIRE(BLPLoader::getCompressionName(BLPCompression::NONE) != nullptr);
REQUIRE(BLPLoader::getCompressionName(BLPCompression::DXT1) != nullptr);
REQUIRE(BLPLoader::getCompressionName(BLPCompression::DXT3) != nullptr);
REQUIRE(BLPLoader::getCompressionName(BLPCompression::DXT5) != nullptr);
REQUIRE(BLPLoader::getCompressionName(BLPCompression::PALETTE) != nullptr);
REQUIRE(BLPLoader::getCompressionName(BLPCompression::ARGB8888) != nullptr);
// Check that DXT names differ
REQUIRE(std::string(BLPLoader::getCompressionName(BLPCompression::DXT1)) !=
std::string(BLPLoader::getCompressionName(BLPCompression::DXT5)));
}
TEST_CASE("BLPImage mipmap storage", "[blp]") {
BLPImage img;
img.width = 128;
img.height = 128;
img.data.resize(128 * 128 * 4, 0);
img.mipLevels = 3;
// Add mipmap data
img.mipmaps.push_back(std::vector<uint8_t>(64 * 64 * 4, 0));
img.mipmaps.push_back(std::vector<uint8_t>(32 * 32 * 4, 0));
img.mipmaps.push_back(std::vector<uint8_t>(16 * 16 * 4, 0));
REQUIRE(img.isValid());
REQUIRE(img.mipmaps.size() == 3);
}