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

Implements class CLASS? More...

Include dependency graph for toyitemsserialization.test.cpp:

Go to the source code of this file.

Classes

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

Functions

 TEST_F (ToyItemsSerializationTest, allItemsInAModel)
 Insert all supported items in a model and check that after serialization. More...
 
 TEST_F (ToyItemsSerializationTest, defaultShapeGroupItemInModel)
 Checking ShapeGroupItem in a model. More...
 
 TEST_F (ToyItemsSerializationTest, modifiedShapeGroupItemInModel)
 Checking ShapeGroupItem in a 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 toyitemsserialization.test.cpp.

Function Documentation

◆ TEST_F() [1/3]

TEST_F ( ToyItemsSerializationTest  ,
allItemsInAModel   
)

Insert all supported items in a model and check that after serialization.

Definition at line 80 of file toyitemsserialization.test.cpp.

81 {
82  SampleModel model;
91 
92  auto modelCopy = Utils::CreateCopy(model);
93  EXPECT_EQ(model.rootItem()->childrenCount(), modelCopy->rootItem()->childrenCount());
94 }
int childrenCount() const
Returns total number of children in all tags.
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
Represents an anysotropical pyramid.
Definition: toyitems.h:107
Represents a cylindrical shape.
Definition: toyitems.h:88
Represents a lattice.
Definition: toyitems.h:72
Represents a layer, with thickness and color, and possibly populated with particles.
Definition: toyitems.h:52
Represents multilayer with collection of layers.
Definition: toyitems.h:44
Represents a particle, with a position, and a selection of possible shapes.
Definition: toyitems.h:62
Represents a group item holding a collection of shapes.
Definition: toyitems.h:119
Represents a shpere.
Definition: toyitems.h:98
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 ( ToyItemsSerializationTest  ,
defaultShapeGroupItemInModel   
)

Checking ShapeGroupItem in a model.

Serialization/deserelization should give an item identical to original.

Definition at line 37 of file toyitemsserialization.test.cpp.

38 {
39  // model with single group item
40  SampleModel model;
41  auto group = model.insertItem<ShapeGroupItem>();
42 
43  // copy of model
44  auto modelCopy = Utils::CreateCopy(model);
45  auto groupCopy = modelCopy->topItem<ShapeGroupItem>();
46 
47  // basic properties in copied item should be the same
48  EXPECT_EQ(group->currentIndex(), groupCopy->currentIndex());
49  EXPECT_EQ(group->currentItem()->modelType(), groupCopy->currentItem()->modelType());
50 }

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

Here is the call graph for this function:

◆ TEST_F() [3/3]

TEST_F ( ToyItemsSerializationTest  ,
modifiedShapeGroupItemInModel   
)

Checking ShapeGroupItem in a model.

Serialization/deserelization should give an item identical to original.

Definition at line 55 of file toyitemsserialization.test.cpp.

56 {
57  SampleModel model;
58  auto group = model.insertItem<ShapeGroupItem>();
59 
60  // modifying group item
62  group->children().at(0)->setProperty(CylinderItem::P_RADIUS, 42.0);
63  group->children().at(1)->setProperty(SphereItem::P_RADIUS, 43.0);
64  group->children().at(2)->setProperty(AnysoPyramidItem::P_LENGTH, 44.0);
65 
66  // creating copy
67  auto modelCopy = Utils::CreateCopy(model);
68  auto groupCopy = modelCopy->topItem<ShapeGroupItem>();
69 
70  // checking properties of
71  EXPECT_EQ(groupCopy->currentIndex(), group->currentIndex());
72  EXPECT_EQ(groupCopy->currentItem()->modelType(), group->currentItem()->modelType());
73  EXPECT_EQ(groupCopy->children().at(0)->property<double>(CylinderItem::P_RADIUS), 42.0);
74  EXPECT_EQ(groupCopy->children().at(1)->property<double>(SphereItem::P_RADIUS), 43.0);
75  EXPECT_EQ(groupCopy->children().at(2)->property<double>(AnysoPyramidItem::P_LENGTH), 44.0);
76 }
static const QString P_RADIUS
void setCurrentType(const std::string &model_type)
Sets item corresponding to given model type.
Definition: groupitem.cpp:58
const ModelView::model_type AnysoPyramidItemType
Definition: toyitems.h:37

References ToyItems::Constants::AnysoPyramidItemType, ModelView::Utils::CreateCopy(), ModelView::SessionModel::insertItem(), CylinderItem::P_RADIUS, and ModelView::GroupItem::setCurrentType().

Here is the call graph for this function: