BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
standarditemserialization.test.cpp File Reference

Implements class CLASS? More...

Include dependency graph for standarditemserialization.test.cpp:

Go to the source code of this file.

Classes

class  StandardItemsSerializationTest
 Testing serialization of ToyItems using json converters. More...
 

Functions

 TEST_F (StandardItemsSerializationTest, allItems)
 Checking that serialization works (not crashing) for all defined standard items. More...
 
 TEST_F (StandardItemsSerializationTest, GraphItemAndDataSerialization)
 Creating graph with data. It has to be identical after serialization. More...
 
 TEST_F (StandardItemsSerializationTest, graphViewPortItemSerialization)
 Creating viewport with one graph. Serializing and restoring the model. More...
 

Detailed Description

Implements class CLASS?

Homepage:\n http://www.bornagainproject.org
License:\n GNU General Public License v3 or higher (see COPYING)
Authors
Gennady Pospelov et al, Scientific Computing Group at MLZ (see CITATION, AUTHORS)

Definition in file standarditemserialization.test.cpp.

Function Documentation

◆ TEST_F() [1/3]

TEST_F ( StandardItemsSerializationTest  ,
allItems   
)

Checking that serialization works (not crashing) for all defined standard items.

Definition at line 35 of file standarditemserialization.test.cpp.

36 {
37  SessionModel model;
38  model.insertItem<ColorMapItem>();
40  model.insertItem<CompoundItem>();
41  model.insertItem<ContainerItem>();
42  model.insertItem<Data1DItem>();
43  model.insertItem<Data2DItem>();
45  model.insertItem<GraphItem>();
47  model.insertItem<LinkedItem>();
48  model.insertItem<PenItem>();
50  model.insertItem<PropertyItem>();
51  model.insertItem<SessionItem>();
52  model.insertItem<TextItem>();
53  model.insertItem<VectorItem>();
55 
56  auto modelCopy = Utils::CreateCopy(model);
57  EXPECT_EQ(model.rootItem()->childrenCount(), modelCopy->rootItem()->childrenCount());
58 }
Two-dimensional color map representation of Data2DItem.
Definition: colormapitem.h:28
Container with viewport and collection of ColorMapItem's to plot.
Complex item holding mixed SessionItem types (single properties and other CompountItems).
Definition: compounditem.h:28
Simple container to store any type of children.
Definition: containeritem.h:25
Represents one-dimensional data (axis and values).
Definition: data1ditem.h:30
Represents two-dimensional data (axes definition and 2d array of values).
Definition: data2ditem.h:29
Item to represent fixed bin axis.
Definition: axisitems.h:75
One-dimensional graph representation of Data1DItem.
Definition: graphitem.h:29
2D viewport specialized for showing multiple GraphItem's.
Item to store a persistent link to other arbitrary items.
Definition: linkeditem.h:30
Represents basics settings of QPen.
Item to represent pointwise axis.
Definition: axisitems.h:94
Item to carry concrete editable entity (e.g.
Definition: propertyitem.h:27
The main object representing an editable/displayable/serializable entity.
Definition: sessionitem.h:38
int childrenCount() const
Returns total number of children in all tags.
Main class to hold hierarchy of SessionItem objects.
Definition: sessionmodel.h:37
SessionItem * rootItem() const
Returns root item of the model.
T * insertItem(SessionItem *parent=nullptr, const TagRow &tagrow={})
Inserts item into given parent under given tagrow.
Definition: sessionmodel.h:104
Represent text item on plot.
Vector item with three x,y,z property items.
Definition: vectoritem.h:24
Item to represent viewport axis.
Definition: axisitems.h:43
std::unique_ptr< T > CreateCopy(const T &model)
Creates full deep copy of given model. All item's ID will be generated.
Definition: modelutils.h:81

References ModelView::SessionItem::childrenCount(), ModelView::Utils::CreateCopy(), ModelView::SessionModel::insertItem(), and ModelView::SessionModel::rootItem().

Here is the call graph for this function:

◆ TEST_F() [2/3]

TEST_F ( StandardItemsSerializationTest  ,
GraphItemAndDataSerialization   
)

Creating graph with data. It has to be identical after serialization.

Definition at line 62 of file standarditemserialization.test.cpp.

63 {
64  // preparing model, data item and graph pointing to it
65  SessionModel model;
66  auto graph_item = model.insertItem<GraphItem>();
67  auto data_item = model.insertItem<Data1DItem>();
68  const std::vector<double> expected_values = {1.0, 2.0, 3.0};
69  const std::vector<double> expected_centers = {0.5, 1.5, 2.5};
70  data_item->setAxis<FixedBinAxisItem>(3, 0.0, 3.0);
71  data_item->setValues(expected_values);
72  graph_item->setDataItem(data_item);
73 
74  // accessing copied items
75  auto modelClone = Utils::CreateClone(model);
76  EXPECT_EQ(model.rootItem()->childrenCount(), modelClone->rootItem()->childrenCount());
77 
78  auto graphClone = modelClone->topItem<GraphItem>();
79  auto dataClone = modelClone->topItem<Data1DItem>();
80 
81  // analyzing copies
82  EXPECT_EQ(graphClone->dataItem(), dataClone);
83  EXPECT_EQ(dataClone->binCenters(), expected_centers);
84  EXPECT_EQ(dataClone->binValues(), expected_values);
85 }
std::vector< double > binValues() const
Definition: graphitem.cpp:64
void setDataItem(const Data1DItem *item)
Sets link to the data item.
Definition: graphitem.cpp:34
std::vector< double > binCenters() const
Definition: graphitem.cpp:59
std::unique_ptr< T > CreateClone(const T &model)
Creates exact clone of given model. All item's ID will be preserved.
Definition: modelutils.h:90

References ModelView::GraphItem::binCenters(), ModelView::GraphItem::binValues(), ModelView::SessionItem::childrenCount(), ModelView::Utils::CreateClone(), ModelView::SessionModel::insertItem(), ModelView::SessionModel::rootItem(), and ModelView::GraphItem::setDataItem().

Here is the call graph for this function:

◆ TEST_F() [3/3]

TEST_F ( StandardItemsSerializationTest  ,
graphViewPortItemSerialization   
)

Creating viewport with one graph. Serializing and restoring the model.

Definition at line 89 of file standarditemserialization.test.cpp.

90 {
91  SessionModel model;
92  auto viewport_item = model.insertItem<GraphViewportItem>();
93  auto graph_item = model.insertItem<GraphItem>(viewport_item);
94  auto data_item = model.insertItem<Data1DItem>();
95 
96  const std::vector<double> expected_values = {1.0, 2.0, 3.0};
97  const std::vector<double> expected_centers = {0.5, 1.5, 2.5};
98  data_item->setAxis<FixedBinAxisItem>(3, 0.0, 3.0);
99  data_item->setValues(expected_values);
100 
101  graph_item->setDataItem(data_item);
102  EXPECT_EQ(viewport_item->graphItems().size(), 1);
103 
104  // updating viewport to graph
105  viewport_item->setViewportToContent();
106 
107  // accessing cloned items
108  auto modelClone = Utils::CreateClone(model);
109  EXPECT_EQ(model.rootItem()->childrenCount(), modelClone->rootItem()->childrenCount());
110  auto viewportCopy = modelClone->topItem<GraphViewportItem>();
111  ASSERT_EQ(viewportCopy->graphItems().size(), 1);
112  auto graphClone = viewportCopy->graphItems().at(0);
113  auto dataClone = modelClone->topItem<Data1DItem>();
114 
115  // analyzing clones
116  EXPECT_EQ(graphClone->dataItem(), dataClone);
117  EXPECT_EQ(graphClone->dataItem(), dataClone);
118  EXPECT_EQ(dataClone->binCenters(), expected_centers);
119  EXPECT_EQ(dataClone->binValues(), expected_values);
120 
121  EXPECT_DOUBLE_EQ(viewportCopy->xAxis()->property<double>(ViewportAxisItem::P_MIN),
122  expected_centers[0]);
123  EXPECT_DOUBLE_EQ(viewportCopy->xAxis()->property<double>(ViewportAxisItem::P_MAX),
124  expected_centers[2]);
125 }

References ModelView::SessionItem::childrenCount(), ModelView::Utils::CreateClone(), ModelView::SessionModel::insertItem(), ModelView::BasicAxisItem::P_MAX, ModelView::BasicAxisItem::P_MIN, and ModelView::SessionModel::rootItem().

Here is the call graph for this function: