static void testItemToHeadgear (void) { inventory_t inv; const objDef_t *od; const invDef_t *container; item_t item; ResetInventoryList(); OBJZERO(inv); od = INVSH_GetItemByIDSilent("irgoggles"); CU_ASSERT_PTR_NOT_NULL_FATAL(od); container = INVSH_GetInventoryDefinitionByID("headgear"); CU_ASSERT_PTR_NOT_NULL_FATAL(container); item.t = od; item.m = NULL; item.a = 0; CU_ASSERT_FALSE(INVSH_ExistsInInventory(&inv, container, &item)); CU_ASSERT_PTR_NOT_NULL(i.AddToInventory(&i, &inv, &item, container, NONE, NONE, 1)); CU_ASSERT_TRUE(INVSH_ExistsInInventory(&inv, container, &item)); CU_ASSERT_PTR_NULL(i.AddToInventory(&i, &inv, &item, container, NONE, NONE, 1)); }
static void testItemAdd (void) { inventory_t inv; const objDef_t *od; item_t item; const invDef_t *container; ResetInventoryList(); OBJZERO(inv); od = INVSH_GetItemByIDSilent("assault"); CU_ASSERT_PTR_NOT_NULL(od); container = INVSH_GetInventoryDefinitionByID("right"); CU_ASSERT_PTR_NOT_NULL(container); item.t = od; item.m = NULL; item.a = 0; CU_ASSERT(INVSH_ExistsInInventory(&inv, container, &item) == false); CU_ASSERT_PTR_NOT_NULL(i.AddToInventory(&i, &inv, &item, container, NONE, NONE, 1)); CU_ASSERT(INVSH_ExistsInInventory(&inv, container, &item) == true); }
static void testItemMove (void) { Inventory inv; const objDef_t* od; const invDef_t* container, *containerTo; Item* addedItem; ResetInventoryList(); od = INVSH_GetItemByIDSilent("assault"); CU_ASSERT_PTR_NOT_NULL(od); container = INVSH_GetInventoryDefinitionByID("right"); CU_ASSERT_PTR_NOT_NULL(container); Item item(od); CU_ASSERT(inv.containsItem(container->id, &item) == false); addedItem = i.addToInventory(&inv, &item, container, NONE, NONE, 1); CU_ASSERT_PTR_NOT_NULL(addedItem); CU_ASSERT(inv.containsItem(container->id, &item) == true); containerTo = INVSH_GetInventoryDefinitionByID("backpack"); CU_ASSERT_PTR_NOT_NULL(containerTo); CU_ASSERT_EQUAL(IA_MOVE, i.moveInInventory(&inv, container, addedItem, containerTo, NONE, NONE, nullptr, nullptr)); CU_ASSERT(inv.containsItem(container->id, &item) == false); CU_ASSERT(inv.containsItem(containerTo->id, &item) == true); }
static void testItemDel (void) { Inventory inv; const objDef_t* od; const invDef_t* container; Item* addedItem; ResetInventoryList(); od = INVSH_GetItemByIDSilent("assault"); CU_ASSERT_PTR_NOT_NULL(od); container = INVSH_GetInventoryDefinitionByID("right"); CU_ASSERT_PTR_NOT_NULL(container); Item item(od); CU_ASSERT(inv.containsItem(container->id, &item) == false); addedItem = i.addToInventory(&inv, &item, container, NONE, NONE, 1); CU_ASSERT(inv.containsItem(container->id, &item) == true); CU_ASSERT(i.removeFromInventory(&inv, container, addedItem)); CU_ASSERT(inv.containsItem(container->id, &item) == false); }
static void testItemMassActions (void) { ResetInventoryList(); const objDef_t* od = INVSH_GetItemByIDSilent("assault"); CU_ASSERT_PTR_NOT_NULL_FATAL(od); const invDef_t* container = INVSH_GetInventoryDefinitionByID("right"); CU_ASSERT_PTR_NOT_NULL_FATAL(container); Inventory inv; bool addedItem = testAddSingle(&inv, od, container); CU_ASSERT(addedItem == true); /* second try should fail as the right container is a single container */ addedItem = testAddSingle(&inv, od, container); CU_ASSERT(addedItem == false); container = INVSH_GetInventoryDefinitionByID("left"); CU_ASSERT_PTR_NOT_NULL_FATAL(container); od = INVSH_GetItemByIDSilent("fraggrenade"); CU_ASSERT_PTR_NOT_NULL_FATAL(od); addedItem = testAddSingle(&inv, od, container); CU_ASSERT(addedItem == true); container = INVSH_GetInventoryDefinitionByID("equip"); CU_ASSERT_PTR_NOT_NULL_FATAL(container); for (int i = 0; i < csi.numODs; i++) { od = INVSH_GetItemByIDX(i); /* every item should be placable on the ground container and there should really be enough space */ addedItem = testAddSingle(&inv, od, container); CU_ASSERT(addedItem == true); addedItem = testAddSingle(&inv, od, container); CU_ASSERT(addedItem == true); addedItem = testAddSingle(&inv, od, container); CU_ASSERT(addedItem == true); for (int j = 0; j < od->numAmmos; j++) { addedItem = testAddSingle(&inv, od->ammos[j], container); CU_ASSERT(addedItem == true); addedItem = testAddSingle(&inv, od->ammos[j], container); CU_ASSERT(addedItem == true); addedItem = testAddSingle(&inv, od->ammos[j], container); CU_ASSERT(addedItem == true); addedItem = testAddSingle(&inv, od->ammos[j], container); CU_ASSERT(addedItem == true); addedItem = testAddSingle(&inv, od->ammos[j], container); CU_ASSERT(addedItem == true); addedItem = testAddSingle(&inv, od->ammos[j], container); CU_ASSERT(addedItem == true); } } }
static void ResetCampaignData (void) { const campaign_t *campaign; CL_ResetSinglePlayerData(); CL_ReadSinglePlayerData(); campaign = GetCampaign(); CL_ReadCampaignData(campaign); ResetInventoryList(); CL_UpdateCredits(MAX_CREDITS); MAP_Shutdown(); MAP_Init(campaign->map); }
void SetUp() { campaign_t* campaign; CP_ResetCampaignData(); CP_ParseCampaignData(); campaign = GetCampaign(); CP_ReadCampaignData(campaign); ResetInventoryList(); CP_UpdateCredits(MAX_CREDITS); GEO_Shutdown(); GEO_Init(campaign->map); ccs.curCampaign = campaign; }
static void testItemMove (void) { inventory_t inv; const objDef_t *od; item_t item; const invDef_t *container, *containerTo; invList_t *addedItem; ResetInventoryList(); OBJZERO(inv); OBJZERO(item); od = INVSH_GetItemByIDSilent("assault"); CU_ASSERT_PTR_NOT_NULL(od); container = INVSH_GetInventoryDefinitionByID("right"); CU_ASSERT_PTR_NOT_NULL(container); item.t = od; item.m = NULL; item.a = 0; CU_ASSERT(INVSH_ExistsInInventory(&inv, container, &item) == false); addedItem = i.AddToInventory(&i, &inv, &item, container, NONE, NONE, 1); CU_ASSERT_PTR_NOT_NULL(addedItem); CU_ASSERT(INVSH_ExistsInInventory(&inv, container, &item) == true); containerTo = INVSH_GetInventoryDefinitionByID("backpack"); CU_ASSERT_PTR_NOT_NULL(containerTo); CU_ASSERT_EQUAL(IA_MOVE, i.MoveInInventory(&i, &inv, container, addedItem, containerTo, NONE, NONE, NULL, NULL)); CU_ASSERT(INVSH_ExistsInInventory(&inv, container, &item) == false); CU_ASSERT(INVSH_ExistsInInventory(&inv, containerTo, &item) == true); }
static void testItemToHeadgear (void) { Inventory inv; const objDef_t* od; const invDef_t* container; ResetInventoryList(); od = INVSH_GetItemByIDSilent("irgoggles"); CU_ASSERT_PTR_NOT_NULL_FATAL(od); container = INVSH_GetInventoryDefinitionByID("headgear"); CU_ASSERT_PTR_NOT_NULL_FATAL(container); Item item(od); CU_ASSERT_FALSE(inv.containsItem(container->id, &item)); CU_ASSERT_PTR_NOT_NULL(i.addToInventory(&inv, &item, container, NONE, NONE, 1)); CU_ASSERT_TRUE(inv.containsItem(container->id, &item)); CU_ASSERT_PTR_NULL(i.addToInventory(&inv, &item, container, NONE, NONE, 1)); }
static void testItemReload (void) { inventory_t inv; const objDef_t *od, *ad; item_t item, ammo, ammoFrom; const invDef_t *container, *containerFrom; invList_t *addedItem; ResetInventoryList(); OBJZERO(inv); od = INVSH_GetItemByIDSilent("rpg"); CU_ASSERT_PTR_NOT_NULL(od); container = INVSH_GetInventoryDefinitionByID("right"); CU_ASSERT_PTR_NOT_NULL(container); item.t = od; item.m = NULL; item.a = 0; CU_ASSERT(INVSH_ExistsInInventory(&inv, container, &item) == false); addedItem = i.AddToInventory(&i, &inv, &item, container, NONE, NONE, 1); CU_ASSERT_PTR_NOT_NULL(addedItem); CU_ASSERT(INVSH_ExistsInInventory(&inv, container, &item) == true); ad = INVSH_GetItemByIDSilent("rpg_ammo"); CU_ASSERT_PTR_NOT_NULL(ad); ammo.t = ad; ammo.m = NULL; ammo.a = 0; containerFrom = INVSH_GetInventoryDefinitionByID("backpack"); CU_ASSERT_PTR_NOT_NULL(containerFrom); CU_ASSERT(INVSH_ExistsInInventory(&inv, containerFrom, &ammo) == false); addedItem = i.AddToInventory(&i, &inv, &ammo, containerFrom, NONE, NONE, 1); CU_ASSERT_PTR_NOT_NULL(addedItem); CU_ASSERT(INVSH_ExistsInInventory(&inv, containerFrom, &ammo) == true); CU_ASSERT_EQUAL(IA_RELOAD, i.MoveInInventory(&i, &inv, containerFrom, addedItem, container, NONE, NONE, NULL, NULL)); CU_ASSERT(INVSH_ExistsInInventory(&inv, containerFrom, &ammo) == false); item.m = ad; item.a = 1; CU_ASSERT(INVSH_ExistsInInventory(&inv, container, &item) == true); ad = INVSH_GetItemByIDSilent("rpg_incendiary_ammo"); CU_ASSERT_PTR_NOT_NULL(ad); ammoFrom.t = ad; ammoFrom.m = NULL; ammoFrom.a = 0; CU_ASSERT(INVSH_ExistsInInventory(&inv, containerFrom, &ammoFrom) == false); addedItem = i.AddToInventory(&i, &inv, &ammoFrom, containerFrom, NONE, NONE, 1); CU_ASSERT_PTR_NOT_NULL(addedItem); CU_ASSERT(INVSH_ExistsInInventory(&inv, containerFrom, &ammoFrom) == true); CU_ASSERT_EQUAL(IA_RELOAD_SWAP, i.MoveInInventory(&i, &inv, containerFrom, addedItem, container, NONE, NONE, NULL, NULL)); CU_ASSERT(INVSH_ExistsInInventory(&inv, containerFrom, &ammoFrom) == false); CU_ASSERT(INVSH_ExistsInInventory(&inv, containerFrom, &ammo) == true); item.m = ad; CU_ASSERT(INVSH_ExistsInInventory(&inv, container, &item) == true); }
static void testItemReload (void) { Inventory inv; const objDef_t* od, *ad; const invDef_t* container, *containerFrom; Item* addedItem; ResetInventoryList(); od = INVSH_GetItemByIDSilent("rpg"); CU_ASSERT_PTR_NOT_NULL(od); container = INVSH_GetInventoryDefinitionByID("right"); CU_ASSERT_PTR_NOT_NULL(container); Item item(od); CU_ASSERT(inv.containsItem(container->id, &item) == false); addedItem = i.addToInventory(&inv, &item, container, NONE, NONE, 1); CU_ASSERT_PTR_NOT_NULL(addedItem); CU_ASSERT(inv.containsItem(container->id, &item) == true); ad = INVSH_GetItemByIDSilent("rpg_ammo"); CU_ASSERT_PTR_NOT_NULL(ad); Item ammo(ad); containerFrom = INVSH_GetInventoryDefinitionByID("backpack"); CU_ASSERT_PTR_NOT_NULL(containerFrom); CU_ASSERT(inv.containsItem(containerFrom->id, &ammo) == false); addedItem = i.addToInventory(&inv, &ammo, containerFrom, NONE, NONE, 1); CU_ASSERT_PTR_NOT_NULL(addedItem); CU_ASSERT(inv.containsItem(containerFrom->id, &ammo) == true); CU_ASSERT_EQUAL(IA_RELOAD, i.moveInInventory(&inv, containerFrom, addedItem, container, NONE, NONE, nullptr, nullptr)); CU_ASSERT(inv.containsItem(containerFrom->id, &ammo) == false); item.setAmmoDef(ad); item.setAmmoLeft(1); CU_ASSERT(inv.containsItem(container->id, &item) == true); ad = INVSH_GetItemByIDSilent("rpg_incendiary_ammo"); CU_ASSERT_PTR_NOT_NULL(ad); Item ammoFrom(ad); CU_ASSERT(inv.containsItem(containerFrom->id, &ammoFrom) == false); addedItem = i.addToInventory(&inv, &ammoFrom, containerFrom, NONE, NONE, 1); CU_ASSERT_PTR_NOT_NULL(addedItem); CU_ASSERT(inv.containsItem(containerFrom->id, &ammoFrom) == true); CU_ASSERT_EQUAL(IA_RELOAD_SWAP, i.moveInInventory(&inv, containerFrom, addedItem, container, NONE, NONE, nullptr, nullptr)); CU_ASSERT(inv.containsItem(containerFrom->id, &ammoFrom) == false); CU_ASSERT(inv.containsItem(containerFrom->id, &ammo) == true); item.setAmmoDef(ad); CU_ASSERT(inv.containsItem(container->id, &item) == true); }