Add test to ensure deleted DialInfos are removed

macos_ci_fix
elsid 1 year ago
parent d2f16774d9
commit 662991dda9
No known key found for this signature in database
GPG Key ID: 4DE04C198CBA7625

@ -642,7 +642,7 @@ namespace
}
std::unique_ptr<std::stringstream> saveDialogueWithInfos(
const ESM::Dialogue& dialogue, std::span<const ESM::DialInfo> infos)
const ESM::Dialogue& dialogue, std::span<const ESM::DialInfo> infos, std::span<const std::size_t> deleted = {})
{
auto stream = std::make_unique<std::stringstream>();
@ -654,10 +654,10 @@ namespace
dialogue.save(writer);
writer.endRecord(ESM::REC_DIAL);
for (const ESM::DialInfo& info : infos)
for (std::size_t i = 0; i < infos.size(); ++i)
{
writer.startRecord(ESM::REC_INFO);
info.save(writer);
infos[i].save(writer, std::find(deleted.begin(), deleted.end(), i) != deleted.end());
writer.endRecord(ESM::REC_INFO);
}
@ -861,4 +861,18 @@ namespace
EXPECT_THAT(dialogue->mInfo, ElementsAre(HasIdEqualTo("info1"), HasIdEqualTo("info2"), HasIdEqualTo("info0")));
EXPECT_EQ(dialogue->mInfo.begin()->mResponse, "test");
}
TEST(MWWorldStoreTest, setUpShouldRemoveDeletedDialogueInfos)
{
const DialogueData data = generateDialogueWithInfos(3);
MWWorld::ESMStore esmStore;
const std::array<std::size_t, 1> deleted = { 1 };
loadEsmStore(0, saveDialogueWithInfos(data.mDialogue, data.mInfos, deleted), esmStore);
esmStore.setUp();
const ESM::Dialogue* dialogue = esmStore.get<ESM::Dialogue>().search(ESM::RefId::stringRefId("dialogue"));
ASSERT_NE(dialogue, nullptr);
EXPECT_THAT(dialogue->mInfo, ElementsAre(HasIdEqualTo("info0"), HasIdEqualTo("info2")));
}
}

Loading…
Cancel
Save