diff --git a/apps/openmw_test_suite/mwworld/test_store.cpp b/apps/openmw_test_suite/mwworld/test_store.cpp index f0916280de..16bfdd24a4 100644 --- a/apps/openmw_test_suite/mwworld/test_store.cpp +++ b/apps/openmw_test_suite/mwworld/test_store.cpp @@ -642,7 +642,7 @@ namespace } std::unique_ptr saveDialogueWithInfos( - const ESM::Dialogue& dialogue, std::span infos) + const ESM::Dialogue& dialogue, std::span infos, std::span deleted = {}) { auto stream = std::make_unique(); @@ -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 deleted = { 1 }; + loadEsmStore(0, saveDialogueWithInfos(data.mDialogue, data.mInfos, deleted), esmStore); + esmStore.setUp(); + + const ESM::Dialogue* dialogue = esmStore.get().search(ESM::RefId::stringRefId("dialogue")); + ASSERT_NE(dialogue, nullptr); + EXPECT_THAT(dialogue->mInfo, ElementsAre(HasIdEqualTo("info0"), HasIdEqualTo("info2"))); + } }