Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
18 #include <mitkImage.h>
21 #include <mitkSurface.h>
22 
23 #include <mitkTestFixture.h>
24 #include <mitkTestingMacros.h>
25 
29 class QmitkDataStorageListModelTestSuite : public mitk::TestFixture
30 {
31  CPPUNIT_TEST_SUITE(QmitkDataStorageListModelTestSuite);
32  MITK_TEST(InstantiationTest);
33  MITK_TEST(FlexibleInputTest);
34  CPPUNIT_TEST_SUITE_END();
35 
37 
38 public:
39  void setUp() override
40  {
41  m_DataStorage = mitk::StandaloneDataStorage::New();
44  imageNode->SetData(image);
45 
48  surfaceNode->SetData(surface);
49 
50  m_DataStorage->Add(imageNode);
51  m_DataStorage->Add(surfaceNode);
52  }
53 
54  void tearDown() override {}
56  void InstantiationTest()
57  {
58  QmitkDataStorageListModel emptyModel;
59  CPPUNIT_ASSERT_EQUAL(0, emptyModel.rowCount());
60 
61  QmitkDataStorageListModel unfilteredModel(m_DataStorage);
62  CPPUNIT_ASSERT_EQUAL(2, unfilteredModel.rowCount());
63 
66  QmitkDataStorageListModel imageFilteredModel(m_DataStorage, imagePredicate.GetPointer());
67  CPPUNIT_ASSERT_EQUAL(1, imageFilteredModel.rowCount());
68  }
69 
74  void FlexibleInputTest()
75  {
77  CPPUNIT_ASSERT_EQUAL(0, model.rowCount());
78  CPPUNIT_ASSERT_EQUAL(std::size_t(0), model.GetDataNodes().size());
79 
82 
83  model.SetPredicate(imagePredicate.GetPointer());
84  CPPUNIT_ASSERT_EQUAL(0, model.rowCount());
85  CPPUNIT_ASSERT_EQUAL(std::size_t(0), model.GetDataNodes().size());
86 
87  model.SetDataStorage(m_DataStorage);
88  CPPUNIT_ASSERT_EQUAL(1, model.rowCount());
89  CPPUNIT_ASSERT_EQUAL(std::size_t(1), model.GetDataNodes().size());
90 
91  model.SetPredicate(nullptr);
92  CPPUNIT_ASSERT_EQUAL(2, model.rowCount());
93  CPPUNIT_ASSERT_EQUAL(std::size_t(2), model.GetDataNodes().size());
94 
95  model.SetDataStorage(nullptr);
96  CPPUNIT_ASSERT_EQUAL(0, model.rowCount());
97  CPPUNIT_ASSERT_EQUAL(std::size_t(0), model.GetDataNodes().size());
98  }
99 };
100 
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()
Test fixture for parameterized tests.
static Pointer New()
static Pointer New()
std::vector< mitk::DataNode * > GetDataNodes() const
Get all current data nodes.