Medical Imaging Interaction Toolkit  2018.4.99-389bf124
Medical Imaging Interaction Toolkit
mitkChartExampleTest.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 
13 // qt
14 #include <QApplication>
15 
16 // mitk chart
18 
19 // mitk core
21 #include <mitkTestFixture.h>
22 #include <mitkTestingMacros.h>
23 #include <mitkPropertyNameHelper.h>
24 
25 // std includes
26 #include <string>
27 
28 class mitkChartExampleTestSuite : public mitk::TestFixture
29 {
30  QApplication a();
31  CPPUNIT_TEST_SUITE(mitkChartExampleTestSuite);
32  MITK_TEST(AddingDataTest);
33  MITK_TEST(CheckingDataTest);
34  MITK_TEST(ClearingDataTest);
35  CPPUNIT_TEST_SUITE_END();
36 
37 private:
38 
40 
41 public:
42 
43  void setUp() override
44  {
45  helper = new mitk::ChartExampleTestHelper;
46  }
47 
48  void tearDown() override
49  {
50  delete helper;
51  }
52 
53  void AddingDataTest()
54  {
55  MITK_INFO << "=== AddingDataTest start ===";
56  AddNewData();
57  CheckData();
58  ClearData();
59  MITK_INFO << "=== AddingDataTest end ===";
60  }
61 
62  void CheckingDataTest()
63  {
64  MITK_INFO << "=== CheckingDataTest start ===";
65  CheckData();
66  MITK_INFO << "=== CheckingDataTest end ===";
67  }
68 
69  void ClearingDataTest()
70  {
71  MITK_INFO << "=== ClearingDataTest start ===";
72  ClearData();
73  MITK_INFO << "=== ClearingDataTest end ===";
74  }
75 
76 
77  void AddNewData()
78  {
79  MITK_INFO << "=== AddNewData";
80 
81  // Adding data
82  //size_t size;
83  for (size_t i = 1; i < 6; i++)
84  {
85  //helper.Add(i);
86  //size = helper.qmitkChartWidget.ReturnSizeOfMemory();
87  //CPPUNIT_ASSERT_MESSAGE("Data storage does not contain the right amount of items!", size == i);
88  }
89  }
90 
91  void CheckData()
92  {
93  auto myDataOne = helper->GetDataOne();
94 
95  auto xDataOne = myDataOne->GetXData();
96  auto yDataOne = myDataOne->GetYData();
97  auto labelOne = myDataOne->GetLabel();
98  auto typeOne = myDataOne->GetChartType();
99  auto colorOne = myDataOne->GetColor();
100  auto styleOne = myDataOne->GetLineStyle();
101 
102  auto dataToCheckOne = helper->qmitkChartWidget.GetDataElementByLabel(labelOne.toString().toStdString());
103 
104  CPPUNIT_ASSERT_MESSAGE("Dataset one was not saved correctly", dataToCheckOne->GetXData() == xDataOne &&
105  dataToCheckOne->GetYData() == yDataOne &&
106  dataToCheckOne->GetLabel() == labelOne &&
107  dataToCheckOne->GetChartType() == typeOne &&
108  dataToCheckOne->GetColor() == colorOne &&
109  dataToCheckOne->GetLineStyle() == styleOne);
110 
111  auto myDataTwo = helper->GetDataTwo();
112 
113  auto xDataTwo = myDataTwo->GetXData();
114  auto yDataTwo = myDataTwo->GetYData();
115  auto labelTwo = myDataTwo->GetLabel();
116  auto typeTwo = myDataTwo->GetChartType();
117  auto colorTwo = myDataTwo->GetColor();
118  auto styleTwo = myDataTwo->GetLineStyle();
119 
120  auto dataToCheckTwo = helper->qmitkChartWidget.GetDataElementByLabel(labelTwo.toString().toStdString());
121 
122  CPPUNIT_ASSERT_MESSAGE("Dataset two was not saved correctly", dataToCheckTwo->GetXData() == xDataTwo &&
123  dataToCheckTwo->GetYData() == yDataTwo &&
124  dataToCheckTwo->GetLabel() == labelTwo &&
125  dataToCheckTwo->GetChartType() == typeTwo &&
126  dataToCheckTwo->GetColor() == colorTwo &&
127  dataToCheckTwo->GetLineStyle() == styleTwo);
128 
129  auto myDataThree = helper->GetDataThree();
130 
131  auto xDataThree = myDataThree->GetXData();
132  auto yDataThree = myDataThree->GetYData();
133  auto labelThree = myDataThree->GetLabel();
134  auto typeThree = myDataThree->GetChartType();
135  auto colorThree = myDataThree->GetColor();
136  auto styleThree = myDataThree->GetLineStyle();
137 
138  auto dataToCheckThree = helper->qmitkChartWidget.GetDataElementByLabel(labelThree.toString().toStdString());
139 
140  CPPUNIT_ASSERT_MESSAGE("Dataset three was not saved correctly", dataToCheckThree->GetXData() == xDataThree &&
141  dataToCheckThree->GetYData() == yDataThree &&
142  dataToCheckThree->GetLabel() == labelThree &&
143  dataToCheckThree->GetChartType() == typeThree &&
144  dataToCheckThree->GetColor() == colorThree &&
145  dataToCheckThree->GetLineStyle() == styleThree);
146 
147  auto myDataFour = helper->GetDataFour();
148 
149  auto xDataFour = myDataFour->GetXData();
150  auto yDataFour = myDataFour->GetYData();
151  auto labelFour = myDataFour->GetLabel();
152  auto typeFour = myDataFour->GetChartType();
153  auto colorFour = myDataFour->GetColor();
154  auto styleFour = myDataFour->GetLineStyle();
155 
156  auto dataToCheckFour = helper->qmitkChartWidget.GetDataElementByLabel(labelFour.toString().toStdString());
157 
158  CPPUNIT_ASSERT_MESSAGE("Dataset one was not saved correctly", dataToCheckFour->GetXData() == xDataFour &&
159  dataToCheckFour->GetYData() == yDataFour &&
160  dataToCheckFour->GetLabel() == labelFour &&
161  dataToCheckFour->GetChartType() == typeFour &&
162  dataToCheckFour->GetColor() == colorFour &&
163  dataToCheckFour->GetLineStyle() == styleFour);
164 
165  auto myDataFive = helper->GetDataFive();
166 
167  auto xDataFive = myDataFive->GetXData();
168  auto yDataFive = myDataFive->GetYData();
169  auto labelFive = myDataFive->GetLabel();
170  auto typeFive = myDataFive->GetChartType();
171  auto colorFive = myDataFive->GetColor();
172  auto styleFive = myDataFive->GetLineStyle();
173 
174  auto dataToCheckFive = helper->qmitkChartWidget.GetDataElementByLabel(labelFive.toString().toStdString());
175 
176  CPPUNIT_ASSERT_MESSAGE("Dataset one was not saved correctly", dataToCheckFive->GetXData() == xDataFive &&
177  dataToCheckFive->GetYData() == yDataFive &&
178  dataToCheckFive->GetLabel() == labelFive &&
179  dataToCheckFive->GetChartType() == typeFive &&
180  dataToCheckFive->GetColor() == colorFive &&
181  dataToCheckFive->GetLineStyle() == styleFive);
182  }
183 
184  void ClearData()
185  {
186  MITK_INFO << "=== ClearData";
187 
188  // Claering data
190  helper.qmitkChartWidget.Clear();
191  //int size = helper.qmitkChartWidget.ReturnSizeOfMemory();
192  //CPPUNIT_ASSERT_MESSAGE("Data storage was not cleared completly!", size == 0);
193  }
194 };
195 
196 MITK_TEST_SUITE_REGISTRATION(mitkChartExample)
MITK_TEST_SUITE_REGISTRATION(mitkImageToItk)
#define MITK_INFO
Definition: mitkLogMacros.h:18
QmitkChartxyData * GetDataElementByLabel(const std::string &label) const
#define MITK_TEST(TESTMETHOD)
Adds a test to the current test suite.
void Clear()
Clears all data inside and resets the widget.
std::unique_ptr< QmitkChartxyData > GetDataOne()
Test fixture for parameterized tests.
std::unique_ptr< QmitkChartxyData > GetDataTwo()
std::unique_ptr< QmitkChartxyData > GetDataFive()
std::unique_ptr< QmitkChartxyData > GetDataThree()
std::unique_ptr< QmitkChartxyData > GetDataFour()