Get/Put item implementation + tests

This commit is contained in:
KimLS
2015-02-20 16:24:32 -08:00
parent 551c0ef368
commit 2d617f0ea7
8 changed files with 328 additions and 55 deletions
+1
View File
@@ -12,6 +12,7 @@ SET(tests_headers
fixed_memory_test.h
fixed_memory_variable_test.h
hextoi_32_64_test.h
inventory_test.h
ipc_mutex_test.h
memory_mapped_file_test.h
string_util_test.h
+180
View File
@@ -0,0 +1,180 @@
/* EQEMu: Everquest Server Emulator
Copyright (C) 2001-2015 EQEMu Development Team (http://eqemulator.net)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY except by those people which sell it, which
are required to give you total support for your newly bought product;
without even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef __EQEMU_TESTS_INVENTORY_H
#define __EQEMU_TESTS_INVENTORY_H
#include "cppunit/cpptest.h"
#include "../common/inventory.h"
#include <string.h>
class InventoryTest : public Test::Suite {
typedef void(InventoryTest::*TestFunction)(void);
public:
InventoryTest() {
InitContainer();
InitArmor();
InitAugment();
InitStackable();
InitInventory();
TEST_ADD(InventoryTest::InventoryVerifyInitialItemsTest);
}
~InventoryTest() {
}
void InitContainer() {
memset(&container, 0, sizeof(container));
strcpy(container.Name, "Backpack");
strcpy(container.IDFile, "IT64");
container.ID = 1000;
container.BagSize = 3;
container.BagSlots = 8;
container.BagType = 5;
container.BagWR = 50;
container.ItemClass = 1;
container.Classes = 65535U;
container.Focus.Effect = -1;
container.ItemType = 11;
container.NoDrop = 1;
container.NoRent = 1;
container.Races = 131071U;
container.Size = 3;
container.SkillModType = -1;
container.Click.Effect = -1;
container.Weight = 30;
container.StackSize = 1;
container.Proc.Effect = -1;
container.Worn.Effect = -1;
container.Scroll.Effect = -1;
}
void InitArmor() {
memset(&armor, 0, sizeof(armor));
strcpy(armor.Name, "Cloth Shirt");
strcpy(armor.IDFile, "IT64");
armor.ID = 1001;
armor.AC = 4;
armor.AugSlotType[0] = 7;
for(int i = 0; i < 6; ++i)
armor.AugSlotVisible[i] = 1;
armor.Size = 2;
armor.Slots = 131072;
armor.Classes = 65535U;
armor.Focus.Effect = -1;
armor.ItemType = 10;
armor.NoDrop = 1;
armor.NoRent = 1;
armor.Races = 131071U;
armor.SkillModType = -1;
armor.Click.Effect = -1;
armor.Weight = 8;
armor.StackSize = 1;
armor.Proc.Effect = -1;
armor.Worn.Effect = -1;
armor.Scroll.Effect = -1;
}
void InitAugment() {
memset(&augment, 0, sizeof(augment));
strcpy(augment.Name, "Cloth Augment");
strcpy(augment.IDFile, "IT64");
augment.ID = 1002;
augment.AWis = 10;
augment.AInt = 10;
augment.AugType = 64;
augment.Slots = 2072574;
augment.Classes = 65535U;
augment.Focus.Effect = -1;
augment.ItemType = 54;
augment.NoDrop = 1;
augment.NoRent = 1;
augment.Races = 131071U;
augment.SkillModType = -1;
augment.Click.Effect = -1;
augment.Weight = 5;
augment.StackSize = 1;
augment.Size = 1;
augment.Proc.Effect = -1;
augment.Worn.Effect = -1;
augment.Scroll.Effect = -1;
}
void InitStackable() {
memset(&stackable, 0, sizeof(stackable));
strcpy(stackable.Name, "Stackable Item");
strcpy(stackable.IDFile, "IT64");
stackable.ID = 1003;
stackable.Classes = 65535U;
stackable.Focus.Effect = -1;
stackable.ItemType = 54;
stackable.NoDrop = 1;
stackable.NoRent = 1;
stackable.Races = 131071U;
stackable.SkillModType = -1;
stackable.Click.Effect = -1;
stackable.Weight = 5;
stackable.StackSize = 100;
stackable.Stackable = 1;
stackable.Size = 1;
stackable.Proc.Effect = -1;
stackable.Worn.Effect = -1;
stackable.Scroll.Effect = -1;
}
void InitInventory()
{
std::shared_ptr<EQEmu::ItemInstance> bag(new EQEmu::ItemInstance(&container));
bag->PutItem(0, std::shared_ptr<EQEmu::ItemInstance>(new EQEmu::ItemInstance(&armor)));
bag->PutItem(1, std::shared_ptr<EQEmu::ItemInstance>(new EQEmu::ItemInstance(&augment)));
bag->PutItem(7, std::shared_ptr<EQEmu::ItemInstance>(new EQEmu::ItemInstance(&stackable, 45)));
inv.Put(0, 23, bag); //23 first inv slot
}
void InventoryVerifyInitialItemsTest()
{
auto m_bag = inv.Get(0, 23);
TEST_ASSERT(m_bag);
TEST_ASSERT(m_bag->GetItem());
TEST_ASSERT(m_bag->GetItem()->ID == 1000);
auto m_armor = m_bag->GetItem(0);
TEST_ASSERT(m_armor);
TEST_ASSERT(m_armor->GetItem());
TEST_ASSERT(m_armor->GetItem()->ID == 1001);
auto m_augment = m_bag->GetItem(1);
TEST_ASSERT(m_augment);
TEST_ASSERT(m_augment->GetItem());
TEST_ASSERT(m_augment->GetItem()->ID == 1002);
auto m_stackable = m_bag->GetItem(7);
TEST_ASSERT(m_stackable);
TEST_ASSERT(m_stackable->GetItem());
TEST_ASSERT(m_stackable->GetItem()->ID == 1003);
}
private:
EQEmu::Inventory inv;
ItemData container;
ItemData armor;
ItemData augment;
ItemData stackable;
};
#endif
+3 -1
View File
@@ -29,6 +29,7 @@
#include "string_util_test.h"
#include "data_verification_test.h"
#include "skills_util_test.h"
#include "inventory_test.h"
int main() {
try {
@@ -44,7 +45,8 @@ int main() {
tests.add(new StringUtilTest());
tests.add(new DataVerificationTest());
tests.add(new SkillsUtilsTest());
tests.run(*output, true);
tests.add(new InventoryTest());
tests.run(*output, false);
} catch(...) {
return -1;
}