33 m_ReferenceDS(reference),
35 m_HierarchyPassed(true),
37 m_PropertiesPassed(true),
38 m_MappersPassed(true),
39 m_InteractorsPassed(true),
52 DescribeHierarchyOfNodes(m_ReferenceDS, m_RefNodesByHierarchy);
53 DescribeHierarchyOfNodes(m_TestDS, m_TestNodesByHierarchy);
55 m_HierarchyPassed =
true;
57 m_PropertiesPassed =
true;
58 m_MappersPassed =
true;
59 m_InteractorsPassed =
true;
62 if (m_TestAspects & CMP_Hierarchy)
63 m_HierarchyPassed = CompareHierarchy(verbose);
65 if (m_TestAspects != CMP_Nothing)
66 CompareDataNodes(verbose);
68 if ((m_TestAspects & CMP_Data) && !m_DataPassed)
70 if ((m_TestAspects & CMP_Properties) && !m_PropertiesPassed)
72 if ((m_TestAspects & CMP_Mappers) && !m_MappersPassed)
74 if ((m_TestAspects & CMP_Interactors) && !m_InteractorsPassed)
80 return m_AspectsFailed == 0;
87 << (m_TestAspects & CMP_Hierarchy ? (m_HierarchyPassed ?
"pass" :
"fail") :
"skipped");
89 << (m_TestAspects & CMP_Data ? (m_DataPassed ?
"pass" :
"fail") :
"skipped");
91 << (m_TestAspects & CMP_Properties ? (m_PropertiesPassed ?
"pass" :
"fail") :
"skipped");
93 << (m_TestAspects & CMP_Mappers ? (m_MappersPassed ?
"pass" :
"fail") :
"skipped");
95 << (m_TestAspects & CMP_Interactors ? (m_InteractorsPassed ?
"pass" :
"fail") :
"skipped");
97 if (m_AspectsFailed == 0)
100 MITK_INFO <<
" Summary: " << m_AspectsFailed <<
" failures";
104 HierarchyDescriptorMap &result)
107 if (storage.IsNull())
111 for (
auto node : *allNodes)
113 std::string descriptor = GenerateHierarchyDescriptor(node, storage);
114 result.insert(std::make_pair(descriptor, node));
123 std::string thisDataDescriptor =
"nullptr";
126 thisDataDescriptor = data->GetNameOfClass();
128 std::string thisNodeName = node->GetName();
130 std::string thisNodesDescriptor = std::string(
"_") + thisDataDescriptor +
"_(" + thisNodeName +
")";
131 return thisNodesDescriptor;
137 std::string thisNodesDescriptor = GenerateNodeDescriptor(node);
139 storage->GetSources(node,
nullptr,
true);
142 std::vector<std::string> parentDescriptors;
144 for (
auto parent : *parents)
145 parentDescriptors.push_back(GenerateHierarchyDescriptor(parent, storage));
148 std::sort(parentDescriptors.begin(), parentDescriptors.end());
151 if (!parentDescriptors.empty())
153 thisNodesDescriptor +=
" <(";
154 for (
auto descriptor : parentDescriptors)
156 if (descriptor != parentDescriptors.front())
158 thisNodesDescriptor +=
" + ";
160 thisNodesDescriptor += descriptor;
162 thisNodesDescriptor +=
")";
165 return thisNodesDescriptor;
168 bool mitk::DataStorageCompare::CompareHierarchy(
bool verbose)
170 int numberOfMisMatches = 0;
177 for (
auto entry : m_RefNodesByHierarchy)
179 const std::string &key = entry.first;
182 unsigned int timesInReference = m_RefNodesByHierarchy.count(key);
183 unsigned int timesInTest = m_TestNodesByHierarchy.count(key);
185 if (timesInTest != timesInReference)
187 ++numberOfMisMatches;
190 MITK_WARN <<
"### Hierarchy mismatch problem";
191 MITK_WARN <<
" Reference storage has " << timesInReference <<
" node(s), test storage " << timesInTest;
192 MITK_WARN <<
" Node name '" << node->GetName() <<
"'";
193 MITK_WARN <<
" Reference hierarchy descriptor: " << key;
199 for (
auto entry : m_TestNodesByHierarchy)
201 const std::string &key = entry.first;
204 unsigned int timesInReference = m_RefNodesByHierarchy.count(key);
205 unsigned int timesInTest = m_TestNodesByHierarchy.count(key);
209 if (timesInTest > timesInReference)
211 ++numberOfMisMatches;
215 MITK_WARN <<
"### Hierarchy mismatch problem";
216 MITK_WARN <<
" Test storage has more nodes (" << timesInReference <<
") than reference storage ("
217 << timesInTest <<
")";
218 MITK_WARN <<
" Node name '" << node->GetName() <<
"'";
219 MITK_WARN <<
" Reference hierarchy descriptor: " << key;
227 if (verbose && numberOfMisMatches > 0)
229 MITK_WARN <<
"Dumping test storage because there were errors:";
230 for (
auto entry : m_TestNodesByHierarchy)
232 const std::string &key = entry.first;
234 MITK_WARN <<
" Test node '" << node->GetName() <<
"', hierarchy : " << key;
238 return numberOfMisMatches == 0;
243 if (reference ==
nullptr && test ==
nullptr)
246 if (reference ==
nullptr && test !=
nullptr)
249 MITK_WARN <<
" Reference node is nullptr, test node is not (type " << test->GetNameOfClass() <<
")";
253 if (reference !=
nullptr && test ==
nullptr)
256 MITK_WARN <<
" Test node is nullptr, reference node is not (type " << reference->GetNameOfClass() <<
")";
260 if (m_TestAspects & CMP_Data)
261 m_DataPassed &= IsDataEqual(reference->
GetData(), test->
GetData(), verbose);
263 if (m_TestAspects & CMP_Properties)
264 m_PropertiesPassed &= ArePropertyListsEqual(*reference, *test, verbose);
266 if (m_TestAspects & CMP_Mappers)
267 m_MappersPassed &= AreMappersEqual(*reference, *test, verbose);
272 return m_AspectsFailed == 0;
278 if (reference ==
nullptr && test ==
nullptr)
281 if (reference ==
nullptr && test !=
nullptr)
284 MITK_WARN <<
" Reference data is nullptr, test data is not (type " << test->GetNameOfClass() <<
")";
288 if (reference !=
nullptr && test ==
nullptr)
291 MITK_WARN <<
" Test data is nullptr, reference data is not (type " << reference->GetNameOfClass() <<
")";
296 if (reference->GetNameOfClass() != test->GetNameOfClass())
299 MITK_WARN <<
" Mismatch: Reference data is '" << reference->GetNameOfClass() <<
"', "
300 <<
"test data is '" << test->GetNameOfClass() <<
"'";
305 std::string ldapFilter = std::string(
"(basedata=") + reference->GetNameOfClass() +
"*)";
306 std::vector<us::ServiceReference<BaseDataCompare>> comparators =
308 if (comparators.empty())
311 MITK_ERROR <<
"Comparison error: no comparator for objects of type '" << reference->GetNameOfClass() <<
"'";
314 else if (comparators.size() > 1)
316 MITK_WARN <<
"Comparison warning: multiple comparisons possible for objects of type '"
317 << reference->GetNameOfClass() <<
"'. Using just one.";
324 MITK_ERROR <<
"Service lookup error, cannot get comparator for class " << reference->GetNameOfClass();
327 return comparator->AreEqual(reference, test, m_Eps, verbose);
329 catch (std::exception &e)
331 MITK_ERROR <<
"Exception during comparison: " << e.what();
336 bool mitk::DataStorageCompare::ArePropertyListsEqual(
const mitk::DataNode &reference,
343 refListNames.push_back(
"");
344 testListNames.push_back(
"");
348 if (refListNames.size() != testListNames.size())
350 for (
auto name : refListNames)
351 if (std::find(testListNames.begin(), testListNames.end(), name) == testListNames.end())
353 MITK_WARN <<
"Propertylist '" << name <<
"' from reference node (" << reference.
GetName()
354 <<
") not found in test node.";
358 for (
auto name : testListNames)
359 if (std::find(refListNames.begin(), refListNames.end(), name) == refListNames.end())
361 MITK_WARN <<
"Propertylist '" << name <<
"' did not exist in reference node (" << reference.
GetName()
362 <<
"), but is present in test node.";
371 for (
auto name : refListNames)
375 MITK_WARN <<
"Property mismatch while comparing propertylist '" << name <<
"'. See messages above.";
383 bool mitk::DataStorageCompare::ArePropertyListsEqual(
const mitk::PropertyList &reference,
391 for (
auto refEntry : *refMap)
393 std::string propertyKey = refEntry.first;
397 if (testProperty.IsNull())
400 MITK_WARN <<
"Property '" << propertyKey <<
"' not found in test, only in reference.";
405 if (!(*refProperty == *testProperty))
409 MITK_WARN <<
"Property '" << propertyKey <<
"' does not match original.";
410 MITK_WARN <<
"Reference was: " << refProperty->GetValueAsString();
411 MITK_WARN <<
"Test was:" << testProperty->GetValueAsString();
421 bool mitk::DataStorageCompare::AreMappersEqual(
const mitk::DataNode &reference,
430 if (refMapper2D ==
nullptr && testMapper2D ==
nullptr)
434 else if (refMapper2D !=
nullptr && testMapper2D ==
nullptr)
438 MITK_WARN <<
"Mapper for 2D was '" << refMapper2D->GetNameOfClass() <<
"' in reference, is 'nullptr"
439 <<
"' in test (DataNode '" << reference.
GetName() <<
"')";
443 else if (refMapper2D ==
nullptr && testMapper2D !=
nullptr)
447 MITK_WARN <<
"Mapper for 2D was 'nullptr"
448 <<
"' in reference, is '" << testMapper2D->GetNameOfClass() <<
"' in test (DataNode '"
449 << reference.
GetName() <<
"')";
453 else if (refMapper2D->GetNameOfClass() != testMapper2D->GetNameOfClass())
457 MITK_WARN <<
"Mapper for 2D was '" << refMapper2D->GetNameOfClass() <<
"' in reference, is '"
458 << testMapper2D->GetNameOfClass() <<
"' in test (DataNode '" << reference.
GetName() <<
"')";
466 if (refMapper3D ==
nullptr && testMapper3D ==
nullptr)
470 else if (refMapper3D !=
nullptr && testMapper3D ==
nullptr)
474 MITK_WARN <<
"Mapper for 3D was '" << refMapper3D->GetNameOfClass() <<
"' in reference, is 'nullptr"
475 <<
"' in test (DataNode '" << reference.
GetName() <<
"')";
479 else if (refMapper3D ==
nullptr && testMapper3D !=
nullptr)
483 MITK_WARN <<
"Mapper for 3D was 'nullptr"
484 <<
"' in reference, is '" << testMapper3D->GetNameOfClass() <<
"' in test (DataNode '"
485 << reference.
GetName() <<
"')";
489 else if (refMapper3D->GetNameOfClass() != testMapper3D->GetNameOfClass())
493 MITK_WARN <<
"Mapper for 3D was '" << refMapper3D->GetNameOfClass() <<
"' in reference, is '"
494 << testMapper3D->GetNameOfClass() <<
"' in test (DataNode '" << reference.
GetName() <<
"')";
502 bool mitk::DataStorageCompare::CompareDataNodes(
bool verbose)
504 int numberOfMisMatches = 0;
506 for (
auto entry : m_RefNodesByHierarchy)
508 const std::string &key = entry.first;
511 unsigned int timesInReference = m_RefNodesByHierarchy.count(key);
512 unsigned int timesInTest = m_TestNodesByHierarchy.count(key);
514 if (timesInReference == 1 && timesInTest == 1)
517 auto testEntry = m_TestNodesByHierarchy.find(key);
519 if (!AreNodesEqual(refNode, testNode, verbose))
521 ++numberOfMisMatches;
524 MITK_WARN <<
"### DataNode mismatch problem";
525 MITK_WARN <<
" Node '" << key <<
"' did not compare to equal (see warnings above).";
531 ++numberOfMisMatches;
534 MITK_WARN <<
"### DataNode mismatch problem";
535 MITK_WARN <<
" Reference storage has " << timesInReference <<
" node(s), test storage " << timesInTest;
536 MITK_WARN <<
" This does not match or we don't know how to figure out comparison partners";
541 return numberOfMisMatches == 0;
mitk::PropertyList * GetPropertyList(const mitk::BaseRenderer *renderer=nullptr) const
Get the PropertyList of the renderer. If renderer is NULL, the BaseRenderer-independent PropertyList ...
mitk::BaseProperty * GetProperty(const std::string &propertyKey) const
Get a property by its name.
Data management class that handles 'was created by' relations.
std::vector< MapOfPropertyLists::key_type > PropertyListKeyNames
Base of all data objects.
bool CompareVerbose()
Shorthand for Compare(true).
Follow Up Storage - Class to facilitate loading/accessing structured follow-up data.
bool GetName(std::string &nodeName, const mitk::BaseRenderer *renderer=nullptr, const char *propertyKey="name") const
Convenience access method for accessing the name of an object (instance of StringProperty with proper...
BaseData * GetData() const
Get the data object (instance of BaseData, e.g., an Image) managed by this DataNode.
itk::SmartPointer< Self > Pointer
Key-value list holding instances of BaseProperty.
DataStorageCompare(const DataStorage *reference, const DataStorage *test, Tests flags=CMP_All, double eps=mitk::eps)
Constructor taking reference and test DataStorage.
Base class of all mappers, Vtk as well as OpenGL mappers.
void * GetService(const ServiceReferenceBase &reference)
itk::SmartPointer< const Self > ConstPointer
PropertyListKeyNames GetPropertyListNames() const
The "names" used for (renderer-specific) PropertyLists in GetPropertyList(string).
std::map< std::string, BaseProperty::Pointer > PropertyMap
bool Compare(bool verbose=false)
Execute the comparison.
std::vector< ServiceReferenceU > GetServiceReferences(const std::string &clazz, const std::string &filter=std::string())
static void RegisterCoreEquals()
Register core type comparators that come with mitk::Equal() functions.
mitk::Mapper * GetMapper(MapperSlotId id) const
Tests
Flag describing the aspects of comparing two DataStorages.
MITKCORE_EXPORT const ScalarType eps
static ModuleContext * GetModuleContext()
Returns the module context of the calling module.
void Report()
Prints a small summary of what tests have been executed and which ones failed or passed.
Class for nodes of the DataTree.
const PropertyMap * GetMap() const