Files
WoWee/tests/test_inventory_sort.cpp
Kelsi 9e3d13c9dd fix(ui): add Sort Bags to combined window and mark special container slots
Share the backpack footer (Sort Bags + money) with the All Bags window, flag
quivers/ammo pouches/profession bags via Inventory::isBagSpecial so sorting
skips them, and tint/label their slots so restricted space isn't mistaken for
general-purpose slots. Also name container/quiver subclasses in tooltips.
2026-07-13 17:08:47 -07:00

80 lines
2.8 KiB
C++

#include "catch_amalgamated.hpp"
#include "game/inventory.hpp"
using namespace wowee::game;
namespace {
ItemDef makeItem(uint32_t id, ItemQuality quality, uint32_t stack = 1) {
ItemDef def;
def.itemId = id;
def.quality = quality;
def.stackCount = stack;
def.maxStack = 20;
return def;
}
} // namespace
TEST_CASE("sortBags orders backpack by quality then itemId", "[inventory]") {
Inventory inv;
inv.setBackpackSlot(0, makeItem(500, ItemQuality::COMMON));
inv.setBackpackSlot(3, makeItem(100, ItemQuality::RARE));
inv.setBackpackSlot(7, makeItem(200, ItemQuality::UNCOMMON));
inv.sortBags();
CHECK(inv.getBackpackSlot(0).item.itemId == 100); // rare first
CHECK(inv.getBackpackSlot(1).item.itemId == 200); // then uncommon
CHECK(inv.getBackpackSlot(2).item.itemId == 500); // then common
CHECK(inv.getBackpackSlot(3).empty());
}
TEST_CASE("sortBags skips special containers", "[inventory]") {
Inventory inv;
// Bag 0: quiver with arrows in slots 0 and 2
inv.setBagSize(0, 6);
inv.setBagSpecial(0, true);
inv.setBagSlot(0, 0, makeItem(2512, ItemQuality::COMMON, 200)); // arrows
inv.setBagSlot(0, 2, makeItem(2512, ItemQuality::COMMON, 50));
// Bag 1: normal bag with one item
inv.setBagSize(1, 4);
inv.setBagSlot(1, 3, makeItem(300, ItemQuality::EPIC));
// Backpack: one item so bag contents have room to move forward
inv.setBackpackSlot(5, makeItem(400, ItemQuality::COMMON));
inv.sortBags();
// Quiver contents untouched, including the gap between them
CHECK(inv.getBagSlot(0, 0).item.itemId == 2512);
CHECK(inv.getBagSlot(0, 0).item.stackCount == 200);
CHECK(inv.getBagSlot(0, 1).empty());
CHECK(inv.getBagSlot(0, 2).item.itemId == 2512);
CHECK(inv.getBagSlot(0, 2).item.stackCount == 50);
// Normal bag + backpack items pooled and sorted into the backpack
CHECK(inv.getBackpackSlot(0).item.itemId == 300); // epic first
CHECK(inv.getBackpackSlot(1).item.itemId == 400);
CHECK(inv.getBagSlot(1, 3).empty());
}
TEST_CASE("computeSortSwaps never addresses special containers", "[inventory]") {
Inventory inv;
inv.setBagSize(0, 6);
inv.setBagSpecial(0, true);
inv.setBagSlot(0, 0, makeItem(2512, ItemQuality::COMMON, 200));
inv.setBagSize(1, 4);
inv.setBagSlot(1, 0, makeItem(100, ItemQuality::RARE));
inv.setBackpackSlot(0, makeItem(500, ItemQuality::COMMON));
auto swaps = inv.computeSortSwaps();
// Wire address of bag 0 is FIRST_BAG_EQUIP_SLOT + 0 = 19
const uint8_t quiverBag = static_cast<uint8_t>(Inventory::FIRST_BAG_EQUIP_SLOT);
for (const auto& op : swaps) {
CHECK(op.srcBag != quiverBag);
CHECK(op.dstBag != quiverBag);
}
// The rare item from the normal bag should still be moved (sort not a no-op)
CHECK(!swaps.empty());
}