Medical Imaging Interaction Toolkit  2018.4.99-389bf124
Medical Imaging Interaction Toolkit
QmitkDataStorageListModelTest.cpp
Go to the documentation of this file.
1 /*============================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
14 #include <mitkImage.h>
17 #include <mitkSurface.h>
18 
19 #include <mitkTestFixture.h>
20 #include <mitkTestingMacros.h>
21 
25 class QmitkDataStorageListModelTestSuite : public mitk::TestFixture
26 {
27  CPPUNIT_TEST_SUITE(QmitkDataStorageListModelTestSuite);
28  MITK_TEST(InstantiationTest);
29  MITK_TEST(FlexibleInputTest);
30  CPPUNIT_TEST_SUITE_END();
31 
33 
34 public:
35  void setUp() override
36  {
37  m_DataStorage = mitk::StandaloneDataStorage::New();
40  imageNode->SetData(image);
41 
44  surfaceNode->SetData(surface);
45 
46  m_DataStorage->Add(imageNode);
47  m_DataStorage->Add(surfaceNode);
48  }
49 
50  void tearDown() override {}
52  void InstantiationTest()
53  {
54  QmitkDataStorageListModel emptyModel;
55  CPPUNIT_ASSERT_EQUAL(0, emptyModel.rowCount());
56 
57  QmitkDataStorageListModel unfilteredModel(m_DataStorage);
58  CPPUNIT_ASSERT_EQUAL(2, unfilteredModel.rowCount());
59 
62  QmitkDataStorageListModel imageFilteredModel(m_DataStorage, imagePredicate.GetPointer());
63  CPPUNIT_ASSERT_EQUAL(1, imageFilteredModel.rowCount());
64  }
65 
70  void FlexibleInputTest()
71  {
73  CPPUNIT_ASSERT_EQUAL(0, model.rowCount());
74  CPPUNIT_ASSERT_EQUAL(std::size_t(0), model.GetDataNodes().size());
75 
78 
79  model.SetPredicate(imagePredicate.GetPointer());
80  CPPUNIT_ASSERT_EQUAL(0, model.rowCount());
81  CPPUNIT_ASSERT_EQUAL(std::size_t(0), model.GetDataNodes().size());
82 
83  model.SetDataStorage(m_DataStorage);
84  CPPUNIT_ASSERT_EQUAL(1, model.rowCount());
85  CPPUNIT_ASSERT_EQUAL(std::size_t(1), model.GetDataNodes().size());
86 
87  model.SetPredicate(nullptr);
88  CPPUNIT_ASSERT_EQUAL(2, model.rowCount());
89  CPPUNIT_ASSERT_EQUAL(std::size_t(2), model.GetDataNodes().size());
90 
91  model.SetDataStorage(nullptr);
92  CPPUNIT_ASSERT_EQUAL(0, model.rowCount());
93  CPPUNIT_ASSERT_EQUAL(std::size_t(0), model.GetDataNodes().size());
94  }
95 };
96 
MITK_TEST_SUITE_REGISTRATION(mitkImageToItk)
int rowCount(const QModelIndex &parent=QModelIndex()) const override
Implements QAbstractListModel.
#define MITK_TEST(TESTMETHOD)
Adds a test to the current test suite.
void SetPredicate(mitk::NodePredicateBase *pred)
Change the filter predicate.
void SetDataStorage(mitk::DataStorage::Pointer dataStorage)
Change the data storage to represent.
mitk::DataStorage::Pointer m_DataStorage
static Pointer New()
std::vector< mitk::DataNode * > GetDataNodes() const
Get all current data nodes.
Test fixture for parameterized tests.
mitk::Image::Pointer image
static Pointer New()
static Pointer New()