From 3f5a697086601e33f2d12f0281b4413e334a30fe Mon Sep 17 00:00:00 2001 From: ephphatha Date: Sat, 16 Apr 2022 10:09:24 +1000 Subject: [PATCH] Add tests for GetInventorySize --- Source/itemdat.h | 3 ++- test/inv_test.cpp | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/Source/itemdat.h b/Source/itemdat.h index 16241f362..c8785f933 100644 --- a/Source/itemdat.h +++ b/Source/itemdat.h @@ -65,7 +65,8 @@ enum _item_indexes : int16_t { // TODO defines all indexes in AllItemsList IDI_FULLNOTE, IDI_BROWNSUIT, IDI_GREYSUIT, - IDI_SORCERER_DIABLO = 166, + IDI_RUNEOFSTONE = 165, + IDI_SORCERER_DIABLO, IDI_LAST = IDI_SORCERER_DIABLO, IDI_NONE = -1, diff --git a/test/inv_test.cpp b/test/inv_test.cpp index 45989873e..ea8d2e9fb 100644 --- a/test/inv_test.cpp +++ b/test/inv_test.cpp @@ -224,3 +224,25 @@ TEST(Inv, RemoveScroll_belt) RemoveScroll(Players[MyPlayerId]); EXPECT_EQ(Players[MyPlayerId].SpdList[3]._itype, ItemType::None); } + +TEST(Inv, ItemSize) +{ + Item testItem {}; + + // Inventory sizes are currently determined by examining the sprite size + // rune of stone and grey suit are adjacent in the sprite list so provide an easy check for off-by-one errors + InitializeItem(testItem, IDI_RUNEOFSTONE); + EXPECT_EQ(GetInventorySize(testItem), Size(1, 1)); + InitializeItem(testItem, IDI_GREYSUIT); + EXPECT_EQ(GetInventorySize(testItem), Size(2, 2)); + + // auric amulet is the first used hellfire sprite, but there's multiple unused sprites before it in the list. + // unfortunately they're the same size so this is less valuable as a test. + InitializeItem(testItem, IDI_AURIC); + EXPECT_EQ(GetInventorySize(testItem), Size(1, 1)); + + // gold is the last diablo sprite, off by ones will end up loading a 1x1 unused sprite from hellfire but maybe + // this'll segfault if we make a mistake in the future? + InitializeItem(testItem, IDI_GOLD); + EXPECT_EQ(GetInventorySize(testItem), Size(1, 1)); +}