BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
colormapviewportitem.test.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // qt-mvvm: Model-view-view-model framework for large GUI applications
4 //
5 //! @file mvvm/tests/testmodel/colormapviewportitem.test.cpp
6 //! @brief Implements class CLASS?
7 //!
8 //! @homepage http://www.bornagainproject.org
9 //! @license GNU General Public License v3 or higher (see COPYING)
10 //! @copyright Forschungszentrum Jülich GmbH 2020
11 //! @authors Gennady Pospelov et al, Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************************************
14 
15 #include "google_test.h"
16 #include "mockwidgets.h"
22 
23 using namespace ModelView;
24 using ::testing::_;
25 
26 //! Testing ColorMapViewportItem.
27 
28 class ColorMapViewportItemTest : public ::testing::Test {
29 public:
31 };
32 
34 
35 //! Initial state.
36 
38 {
39  ColorMapViewportItem viewport;
40  EXPECT_EQ(viewport.xAxis()->modelType(), Constants::ViewportAxisItemType);
41  EXPECT_EQ(viewport.yAxis()->modelType(), Constants::ViewportAxisItemType);
42  EXPECT_EQ(viewport.zAxis()->modelType(), Constants::ViewportAxisItemType);
43  EXPECT_EQ(viewport.items<ColorMapItem>(ColorMapViewportItem::T_ITEMS).size(), 0);
44 }
45 
46 //! Update on unitialized viewport.
47 
48 TEST_F(ColorMapViewportItemTest, uninitializedViewportUpdate)
49 {
50  SessionModel model;
51 
52  auto viewport_item = model.insertItem<ColorMapViewportItem>();
53 
54  viewport_item->setViewportToContent();
55 
56  // x-axis of viewport should be set Data2DItem
57  auto [xmin, xmax] = viewport_item->xAxis()->range();
58  EXPECT_DOUBLE_EQ(xmin, 0.0);
59  EXPECT_DOUBLE_EQ(xmax, 1.0);
60 
61  // y-axis of viewport should be set Data2DItem
62  auto [ymin, ymax] = viewport_item->yAxis()->range();
63  EXPECT_DOUBLE_EQ(ymin, 0.0);
64  EXPECT_DOUBLE_EQ(ymax, 1.0);
65 
66  // z-axis of viewport should be set to min/max content
67  auto [zmin, zmax] = viewport_item->zAxis()->range();
68  EXPECT_DOUBLE_EQ(zmin, 0.0);
69  EXPECT_DOUBLE_EQ(zmax, 1.0);
70 }
71 
72 //! Add graph to viewport.
73 
75 {
76  SessionModel model;
77 
78  auto viewport_item = model.insertItem<ColorMapViewportItem>();
79  auto colormap_item = model.insertItem<ColorMapItem>(viewport_item);
80  auto data_item = model.insertItem<Data2DItem>();
81 
82  data_item->setAxes(FixedBinAxisItem::create(2, 0.0, 2.0),
83  FixedBinAxisItem::create(3, 0.0, 3.0));
84  const std::vector<double> expected_content = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0};
85  data_item->setContent(expected_content);
86 
87  colormap_item->setDataItem(data_item);
88  EXPECT_EQ(viewport_item->items<ColorMapItem>(ColorMapViewportItem::T_ITEMS).size(), 1);
89 
90  // updating viewport to graph
91  viewport_item->setViewportToContent();
92 
93  // x-axis of viewport should be set Data2DItem
94  auto [xmin, xmax] = viewport_item->xAxis()->range();
95  EXPECT_DOUBLE_EQ(xmin, 0.0);
96  EXPECT_DOUBLE_EQ(xmax, 2.0);
97 
98  // y-axis of viewport should be set Data2DItem
99  auto [ymin, ymax] = viewport_item->yAxis()->range();
100  EXPECT_DOUBLE_EQ(ymin, 0.0);
101  EXPECT_DOUBLE_EQ(ymax, 3.0);
102 
103  // z-axis of viewport should be set to min/max content
104  auto [zmin, zmax] = viewport_item->zAxis()->range();
105  EXPECT_DOUBLE_EQ(zmin, 1.0);
106  EXPECT_DOUBLE_EQ(zmax, 6.0);
107 }
108 
109 //! Check signaling on set data item.
110 
112 {
113  SessionModel model;
114  auto viewport_item = model.insertItem<ColorMapViewportItem>();
115 
116  MockWidgetForItem widget(viewport_item);
117 
118  const TagRow expected_tagrow{ViewportItem::T_ITEMS, 0};
119  EXPECT_CALL(widget, onDataChange(_, _)).Times(0);
120  EXPECT_CALL(widget, onPropertyChange(_, _)).Times(0);
121  EXPECT_CALL(widget, onChildPropertyChange(_, _)).Times(0);
122  EXPECT_CALL(widget, onItemInserted(viewport_item, expected_tagrow)).Times(1);
123  EXPECT_CALL(widget, onAboutToRemoveItem(_, _)).Times(0);
124 
125  // triggering action
126  model.insertItem<ColorMapItem>(viewport_item);
127 }
128 
129 //! Check signaling on set data item.
130 
132 {
133  SessionModel model;
134  auto viewport_item = model.insertItem<ColorMapViewportItem>();
135 
136  // setting upda tata item
137  auto data_item = model.insertItem<Data2DItem>();
138 
139  data_item->setAxes(FixedBinAxisItem::create(2, 0.0, 2.0),
140  FixedBinAxisItem::create(3, 0.0, 3.0));
141  const std::vector<double> expected_content = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0};
142  data_item->setContent(expected_content);
143 
144  // inserting graph item
145  auto colormap_item = model.insertItem<ColorMapItem>(viewport_item);
146 
147  MockWidgetForItem widget(viewport_item);
148 
149  EXPECT_CALL(widget, onDataChange(_, _)).Times(0);
150  EXPECT_CALL(widget, onPropertyChange(_, _)).Times(0);
151  EXPECT_CALL(widget, onChildPropertyChange(colormap_item, ColorMapItem::P_LINK)).Times(1);
152  EXPECT_CALL(widget, onItemInserted(_, _)).Times(0);
153  EXPECT_CALL(widget, onAboutToRemoveItem(_, _)).Times(0);
154 
155  // triggering action
156  colormap_item->setDataItem(data_item);
157 }
Defines class CLASS?
Testing ColorMapViewportItem.
Mock widget to test ItemMapper functionality.
Definition: mockwidgets.h:36
Two-dimensional color map representation of Data2DItem.
Definition: colormapitem.h:28
static const std::string P_LINK
Definition: colormapitem.h:30
Container with viewport and collection of ColorMapItem's to plot.
ViewportAxisItem * zAxis() const
void setViewportToContent() override
Sets range of x,y window to show all data.
Represents two-dimensional data (axes definition and 2d array of values).
Definition: data2ditem.h:29
static std::unique_ptr< FixedBinAxisItem > create(int nbins, double xmin, double xmax)
Definition: axisitems.cpp:81
std::vector< T * > items(const std::string &tag) const
Returns all items under given tag casted to specific type.
Definition: sessionitem.h:169
model_type modelType() const
Returns item's model type.
Definition: sessionitem.cpp:80
Main class to hold hierarchy of SessionItem objects.
Definition: sessionmodel.h:37
T * insertItem(SessionItem *parent=nullptr, const TagRow &tagrow={})
Inserts item into given parent under given tagrow.
Definition: sessionmodel.h:104
Aggregate to hold (tag, row) information for SessionModel.
Definition: tagrow.h:25
ViewportAxisItem * xAxis() const
static const std::string T_ITEMS
Definition: viewportitem.h:31
ViewportAxisItem * yAxis() const
Defines class CLASS?
Defines class CLASS?
TEST_F(ColorMapViewportItemTest, initialState)
Initial state.
Defines class CLASS?
Defines class CLASS?
Defines class CLASS?
const model_type ViewportAxisItemType
Definition: mvvm_types.h:62
materialitems.h Collection of materials to populate MaterialModel.
Defines class CLASS?