#Documentation # @brief Test for the DataStorage class and its associated classes (e.g. the predicate classes) # This method will be called once for each subclass of DataStorage
| 155 | //## @brief Test for the DataStorage class and its associated classes (e.g. the predicate classes) |
| 156 | //## This method will be called once for each subclass of DataStorage |
| 157 | void TestDataStorage(mitk::DataStorage *ds, std::string filename) |
| 158 | { |
| 159 | /* DataStorage valid? */ |
| 160 | MITK_TEST_CONDITION_REQUIRED(ds != nullptr, "DataStorage valid?"); |
| 161 | |
| 162 | // Take the ItkImageFile Reader for the .nrrd data format. |
| 163 | // (was previously pic which is now deprecated format) |
| 164 | mitk::Image::Pointer image = mitk::IOUtil::Load<mitk::Image>(filename); |
| 165 | |
| 166 | // create some DataNodes to fill the ds |
| 167 | mitk::DataNode::Pointer n1 = mitk::DataNode::New(); // node with image and name property |
| 168 | // mitk::Image::Pointer image = mitk::Image::New(); |
| 169 | // unsigned int imageDimensions[] = { 10, 10, 10, 10 }; |
| 170 | // mitk::PixelType pt(typeid(int)); |
| 171 | // image->Initialize( pt, 4, imageDimensions ); |
| 172 | n1->SetData(image); |
| 173 | n1->SetProperty("name", mitk::StringProperty::New("Node 1 - Image Node")); |
| 174 | mitk::DataStorage::SetOfObjects::Pointer parents1 = mitk::DataStorage::SetOfObjects::New(); |
| 175 | |
| 176 | mitk::DataNode::Pointer n2 = mitk::DataNode::New(); // node with surface and name and color properties |
| 177 | mitk::Surface::Pointer surface = mitk::Surface::New(); |
| 178 | n2->SetData(surface); |
| 179 | n2->SetProperty("name", mitk::StringProperty::New("Node 2 - Surface Node")); |
| 180 | mitk::Color color; |
| 181 | color.Set(1.0f, 1.0f, 0.0f); |
| 182 | n2->SetColor(color); |
| 183 | n2->SetProperty("Resection Proposal 1", mitk::GroupTagProperty::New()); |
| 184 | mitk::DataStorage::SetOfObjects::Pointer parents2 = mitk::DataStorage::SetOfObjects::New(); |
| 185 | parents2->InsertElement(0, n1); // n1 (image node) is source of n2 (surface node) |
| 186 | |
| 187 | mitk::DataNode::Pointer n3 = mitk::DataNode::New(); // node without data but with name property |
| 188 | n3->SetProperty("name", mitk::StringProperty::New("Node 3 - Empty Node")); |
| 189 | n3->SetProperty("Resection Proposal 1", mitk::GroupTagProperty::New()); |
| 190 | n3->SetProperty("Resection Proposal 2", mitk::GroupTagProperty::New()); |
| 191 | mitk::DataStorage::SetOfObjects::Pointer parents3 = mitk::DataStorage::SetOfObjects::New(); |
| 192 | parents3->InsertElement(0, n2); // n2 is source of n3 |
| 193 | |
| 194 | mitk::DataNode::Pointer n4 = mitk::DataNode::New(); // node without data but with color property |
| 195 | n4->SetColor(color); |
| 196 | n4->SetProperty("Resection Proposal 2", mitk::GroupTagProperty::New()); |
| 197 | mitk::DataStorage::SetOfObjects::Pointer parents4 = mitk::DataStorage::SetOfObjects::New(); |
| 198 | parents4->InsertElement(0, n2); |
| 199 | parents4->InsertElement(1, n3); // n2 and n3 are sources of n4 |
| 200 | |
| 201 | mitk::DataNode::Pointer n5 = mitk::DataNode::New(); // extra node |
| 202 | n5->SetProperty("name", mitk::StringProperty::New("Node 5")); |
| 203 | |
| 204 | try /* adding objects */ |
| 205 | { |
| 206 | /* Add an object */ |
| 207 | ds->Add(n1, parents1); |
| 208 | MITK_TEST_CONDITION_REQUIRED((ds->GetAll()->Size() == 1) && (ds->GetAll()->GetElement(0) == n1), |
| 209 | "Testing Adding a new object"); |
| 210 | |
| 211 | /* Check exception on adding the same object again */ |
| 212 | MITK_TEST_OUTPUT(<< "Check exception on adding the same object again: "); |
| 213 | MITK_TEST_FOR_EXCEPTION(std::exception, ds->Add(n1, parents1)); |
| 214 | MITK_TEST_CONDITION(ds->GetAll()->Size() == 1, "Test if object count is correct after exception"); |
no test coverage detected