Kelsidavis-WoWee/tests/test_opcode_table.cpp

119 lines
3.5 KiB
C++
Raw Normal View History

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
// OpcodeTable load from JSON, toWire/fromWire mapping
#include <catch_amalgamated.hpp>
#include "game/opcode_table.hpp"
#include <fstream>
#include <filesystem>
#include <cstdio>
using wowee::game::OpcodeTable;
using wowee::game::LogicalOpcode;
// Helper: write a temporary JSON file and return its path.
// Uses the executable's directory to avoid permission issues.
static std::string writeTempJson(const std::string& content) {
auto path = std::filesystem::temp_directory_path() / "wowee_test_opcodes.json";
std::ofstream f(path);
f << content;
f.close();
return path.string();
}
TEST_CASE("OpcodeTable loadFromJson basic mapping", "[opcode_table]") {
// CMSG_PING and SMSG_PONG are canonical opcodes present in the generated enum.
std::string json = R"({
"CMSG_PING": "0x1DC",
"SMSG_PONG": "0x1DD"
})";
auto path = writeTempJson(json);
OpcodeTable table;
REQUIRE(table.loadFromJson(path));
REQUIRE(table.size() == 2);
REQUIRE(table.hasOpcode(LogicalOpcode::CMSG_PING));
REQUIRE(table.toWire(LogicalOpcode::CMSG_PING) == 0x1DC);
REQUIRE(table.toWire(LogicalOpcode::SMSG_PONG) == 0x1DD);
std::remove(path.c_str());
}
TEST_CASE("OpcodeTable fromWire reverse lookup", "[opcode_table]") {
std::string json = R"({ "CMSG_PING": "0x1DC" })";
auto path = writeTempJson(json);
OpcodeTable table;
table.loadFromJson(path);
auto result = table.fromWire(0x1DC);
REQUIRE(result.has_value());
REQUIRE(*result == LogicalOpcode::CMSG_PING);
std::remove(path.c_str());
}
TEST_CASE("OpcodeTable unknown wire returns nullopt", "[opcode_table]") {
std::string json = R"({ "CMSG_PING": "0x1DC" })";
auto path = writeTempJson(json);
OpcodeTable table;
table.loadFromJson(path);
auto result = table.fromWire(0x9999);
REQUIRE_FALSE(result.has_value());
std::remove(path.c_str());
}
TEST_CASE("OpcodeTable unknown logical returns 0xFFFF", "[opcode_table]") {
std::string json = R"({ "CMSG_PING": "0x1DC" })";
auto path = writeTempJson(json);
OpcodeTable table;
table.loadFromJson(path);
// SMSG_AUTH_CHALLENGE should not be in this table
REQUIRE(table.toWire(LogicalOpcode::SMSG_AUTH_CHALLENGE) == 0xFFFF);
std::remove(path.c_str());
}
TEST_CASE("OpcodeTable loadFromJson nonexistent file", "[opcode_table]") {
OpcodeTable table;
REQUIRE_FALSE(table.loadFromJson("/nonexistent/path/opcodes.json"));
REQUIRE(table.size() == 0);
}
TEST_CASE("OpcodeTable logicalToName returns enum name", "[opcode_table]") {
const char* name = OpcodeTable::logicalToName(LogicalOpcode::CMSG_PING);
REQUIRE(name != nullptr);
REQUIRE(std::string(name) == "CMSG_PING");
}
TEST_CASE("OpcodeTable decimal wire values", "[opcode_table]") {
std::string json = R"({ "CMSG_PING": "476" })";
auto path = writeTempJson(json);
OpcodeTable table;
REQUIRE(table.loadFromJson(path));
REQUIRE(table.toWire(LogicalOpcode::CMSG_PING) == 476);
std::remove(path.c_str());
}
TEST_CASE("Global active opcode table", "[opcode_table]") {
OpcodeTable table;
std::string json = R"({ "CMSG_PING": "0x1DC" })";
auto path = writeTempJson(json);
table.loadFromJson(path);
wowee::game::setActiveOpcodeTable(&table);
REQUIRE(wowee::game::getActiveOpcodeTable() == &table);
REQUIRE(wowee::game::wireOpcode(LogicalOpcode::CMSG_PING) == 0x1DC);
// Reset
wowee::game::setActiveOpcodeTable(nullptr);
REQUIRE(wowee::game::wireOpcode(LogicalOpcode::CMSG_PING) == 0xFFFF);
std::remove(path.c_str());
}