TEST_F(GameTest, InventoryTempContainerLinks) { const char* mapName = "test_game"; ASSERT_NE(-1, FS_CheckFile("maps/%s.bsp", mapName)) << "Map resource '" << mapName << ".bsp' for test is missing."; SV_Map(true, mapName, nullptr); level.activeTeam = TEAM_ALIEN; /* first alien that should die and drop its inventory */ Actor* actor = G_EdictsGetNextLivingActorOfTeam(nullptr, TEAM_ALIEN); int nr = 0; const Container* cont = nullptr; while ((cont = actor->chr.inv.getNextCont(cont, true))) { if (cont->id == CID_ARMOUR || cont->id == CID_FLOOR) continue; nr += cont->countItems(); } ASSERT_TRUE(nr > 0) << "Could not find any items in the inventory of the actor"; ASSERT_TRUE(nullptr == actor->getFloor()); G_InventoryToFloor(actor); ASSERT_TRUE(nullptr != actor->getFloor()); ASSERT_EQ(G_GetFloorItemFromPos(actor->pos)->getFloor(), actor->getFloor()); nr = 0; cont = nullptr; while ((cont = actor->chr.inv.getNextCont(cont, true))) { if (cont->id == CID_ARMOUR || cont->id == CID_FLOOR) continue; nr += cont->countItems(); } ASSERT_EQ(0, nr); }
static void testInventoryTempContainerLinks (void) { const char *mapName = "test_game"; if (FS_CheckFile("maps/%s.bsp", mapName) != -1) { edict_t *ent; int nr; containerIndex_t container; const invList_t *ic; /* the other tests didn't call the server shutdown function to clean up */ OBJZERO(*sv); SV_Map(true, mapName, NULL); level.activeTeam = TEAM_ALIEN; /* first alien that should die and drop its inventory */ ent = G_EdictsGetNextLivingActorOfTeam(NULL, TEAM_ALIEN); nr = 0; for (container = 0; container < CID_MAX; container++) { if (container == CID_ARMOUR || container == CID_FLOOR) continue; for (ic = ent->getContainer(container); ic; ic = ic->getNext()) nr++; } CU_ASSERT_TRUE(nr > 0); CU_ASSERT_PTR_NULL(ent->getFloor()); G_InventoryToFloor(ent); CU_ASSERT_PTR_NOT_NULL(ent->getFloor()); CU_ASSERT_PTR_EQUAL(G_GetFloorItemFromPos(ent->pos)->getFloor(), ent->getFloor()); nr = 0; for (container = 0; container < CID_MAX; container++) { if (container == CID_ARMOUR || container == CID_FLOOR) continue; for (ic = ent->getContainer(container); ic; ic = ic->getNext()) nr++; } CU_ASSERT_EQUAL(nr, 0); SV_ShutdownGameProgs(); } else { UFO_CU_FAIL_MSG(va("Map resource '%s.bsp' for test is missing.", mapName)); } }