Skip to content

Commit

Permalink
Prevent duplicate metadata addition and enhance test coverage for mod…
Browse files Browse the repository at this point in the history
…el merging
  • Loading branch information
3dJan committed Oct 11, 2024
1 parent 11a8e6b commit 295f452
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
6 changes: 5 additions & 1 deletion Source/Model/Classes/NMR_ModelMetaDataGroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,11 @@ namespace NMR {
std::string sName;
std::string sValue;
PModelMetaData metaData = pSourceMetaDataGroup->getMetaData(nIndex);
addMetaData(metaData->getNameSpace(), metaData->getName(), metaData->getValue(), metaData->getType(), metaData->getPreserve());

// only add metadata, if the key does not exist yet
if (!hasMetaData(metaData->getKey())) {
addMetaData(metaData->getNameSpace(), metaData->getName(), metaData->getValue(), metaData->getType(), metaData->getPreserve());
}
}
}
}
28 changes: 26 additions & 2 deletions Tests/CPP_Bindings/Source/Volumetric.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1258,7 +1258,7 @@ namespace Lib3MF
auto const reader = sourceModel->QueryReader("3mf");
reader->ReadFromFile(InFolder + "SphereInACage.3mf");

auto sourcetModelFunctionCount = sourceModel->GetFunctions()->Count();
auto sourceModelFunctionCount = sourceModel->GetFunctions()->Count();

auto const targetModel = wrapper->CreateModel();

Expand All @@ -1268,7 +1268,31 @@ namespace Lib3MF
targetModel->MergeFromModel(sourceModel.get());

auto targetFunctionsIter = targetModel->GetFunctions();
EXPECT_EQ(targetFunctionsIter->Count(), sourcetModelFunctionCount + 1);
EXPECT_EQ(targetFunctionsIter->Count(), sourceModelFunctionCount + 1);
}

TEST_F(Volumetric,
Volumetric_Merge_FunctionsFromLoadedModelIntoLoadedTargetModel_FunctionCountIncreases)
{
// load the source model
auto const sourceModel = wrapper->CreateModel();
auto reader = sourceModel->QueryReader("3mf");
reader->SetStrictModeActive(true);
reader->ReadFromFile(InFolder + "SphereInACage.3mf");

auto sourceModelFunctionCount = sourceModel->GetFunctions()->Count();

auto const targetModel = wrapper->CreateModel();
auto targetReader = targetModel->QueryReader("3mf");
targetReader->SetStrictModeActive(true);

targetReader->ReadFromFile(InFolder + "template.3mf");
auto previousTargetFunctionCount = targetModel->GetFunctions()->Count();

EXPECT_NO_THROW(targetModel->MergeFromModel(sourceModel.get()));

auto targetFunctionsIter = targetModel->GetFunctions();
EXPECT_EQ(targetFunctionsIter->Count(), sourceModelFunctionCount + previousTargetFunctionCount);
}

} // namespace Lib3MF
Binary file added Tests/TestFiles/Volumetric/template.3mf
Binary file not shown.

0 comments on commit 295f452

Please sign in to comment.