1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-21 08:23:53 +00:00

Merge branch 'fix_remove_deleted_info' into 'master'

Use original RefId to remove info from InfoOrder (#7397)

Closes #7397

See merge request OpenMW/openmw!3102
This commit is contained in:
psi29a 2023-06-03 08:17:03 +00:00
commit 7910f5baed
2 changed files with 26 additions and 1 deletions

View file

@ -80,7 +80,7 @@ void CSMWorld::InfoCollection::load(
if (base)
{
infoOrders.at(dialogue.mId).removeInfo(id);
infoOrders.at(dialogue.mId).removeInfo(info.mId);
removeRows(index, 1);
return;
}

View file

@ -129,6 +129,11 @@ namespace CSMWorld
saveAndLoadDialogueWithInfos(data.mDialogue, data.mInfos, base, infoCollection, infoOrder);
}
MATCHER_P(InfoId, v, "")
{
return arg.mId == v;
}
TEST(CSMWorldInfoCollectionTest, loadShouldAddRecord)
{
ESM::Dialogue dialogue;
@ -152,6 +157,9 @@ namespace CSMWorld
EXPECT_EQ(record.mBase.mTopicId, dialogue.mId);
EXPECT_EQ(record.mBase.mOriginalId, info.mId);
EXPECT_EQ(record.mBase.mId, ESM::RefId::stringRefId("dialogue#info0"));
ASSERT_THAT(infoOrder, ElementsAre(Key(dialogue.mId)));
EXPECT_THAT(infoOrder.find(dialogue.mId)->second.getOrderedInfo(), ElementsAre(InfoId(info.mId)));
}
TEST(CSMWorldInfoCollectionTest, loadShouldAddRecordAndMarkModifiedOnlyWhenNotBase)
@ -177,6 +185,9 @@ namespace CSMWorld
EXPECT_EQ(record.mModified.mTopicId, dialogue.mId);
EXPECT_EQ(record.mModified.mOriginalId, info.mId);
EXPECT_EQ(record.mModified.mId, ESM::RefId::stringRefId("dialogue#info0"));
ASSERT_THAT(infoOrder, ElementsAre(Key(dialogue.mId)));
EXPECT_THAT(infoOrder.find(dialogue.mId)->second.getOrderedInfo(), ElementsAre(InfoId(info.mId)));
}
TEST(CSMWorldInfoCollectionTest, loadShouldUpdateRecord)
@ -204,6 +215,9 @@ namespace CSMWorld
const Record<Info>& record = collection.getRecord(0);
ASSERT_EQ(record.mState, RecordBase::State_BaseOnly);
EXPECT_EQ(record.mBase.mActor, ESM::RefId::stringRefId("newActor"));
ASSERT_THAT(infoOrder, ElementsAre(Key(dialogue.mId)));
EXPECT_THAT(infoOrder.find(dialogue.mId)->second.getOrderedInfo(), ElementsAre(InfoId(info.mId)));
}
TEST(CSMWorldInfoCollectionTest, loadShouldUpdateRecordAndMarkModifiedWhenNotBase)
@ -231,6 +245,9 @@ namespace CSMWorld
const Record<Info>& record = collection.getRecord(0);
ASSERT_EQ(record.mState, RecordBase::State_Modified);
EXPECT_EQ(record.mModified.mActor, ESM::RefId::stringRefId("newActor"));
ASSERT_THAT(infoOrder, ElementsAre(Key(dialogue.mId)));
EXPECT_THAT(infoOrder.find(dialogue.mId)->second.getOrderedInfo(), ElementsAre(InfoId(info.mId)));
}
TEST(CSMWorldInfoCollectionTest, loadShouldSkipAbsentDeletedRecord)
@ -251,6 +268,8 @@ namespace CSMWorld
saveAndLoadDialogueWithInfos(dialogue, std::array{ info }, base, collection, infoOrder);
EXPECT_EQ(collection.getSize(), 0);
ASSERT_THAT(infoOrder, ElementsAre());
}
TEST(CSMWorldInfoCollectionTest, loadShouldRemovePresentDeletedBaseRecord)
@ -275,6 +294,9 @@ namespace CSMWorld
saveAndLoadDialogueWithInfos(dialogue, std::array{ info }, base, collection, infoOrder);
EXPECT_EQ(collection.getSize(), 0);
ASSERT_THAT(infoOrder, ElementsAre(Key(dialogue.mId)));
EXPECT_THAT(infoOrder.find(dialogue.mId)->second.getOrderedInfo(), ElementsAre());
}
TEST(CSMWorldInfoCollectionTest, loadShouldMarkAsDeletedNotBaseRecord)
@ -301,6 +323,9 @@ namespace CSMWorld
EXPECT_EQ(collection.getSize(), 1);
EXPECT_EQ(
collection.getRecord(ESM::RefId::stringRefId("dialogue#info0")).mState, RecordBase::State_Deleted);
ASSERT_THAT(infoOrder, ElementsAre(Key(dialogue.mId)));
EXPECT_THAT(infoOrder.find(dialogue.mId)->second.getOrderedInfo(), ElementsAre(InfoId(info.mValue.mId)));
}
TEST(CSMWorldInfoCollectionTest, sortShouldOrderRecordsBasedOnPrevAndNext)