BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
toyitemsserialization.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/testintegration/toyitemsserialization.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 "mvvm/model/modelutils.h"
18 #include "toyitems.h"
19 #include "toymodel.h"
20 #include <QJsonObject>
21 
22 using namespace ModelView;
23 using namespace ToyItems;
24 
25 //! Testing serialization of ToyItems using json converters.
26 
27 class ToyItemsSerializationTest : public ::testing::Test {
28 public:
30 };
31 
33 
34 //! Checking ShapeGroupItem in a model.
35 //! Serialization/deserelization should give an item identical to original.
36 
37 TEST_F(ToyItemsSerializationTest, defaultShapeGroupItemInModel)
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 }
51 
52 //! Checking ShapeGroupItem in a model.
53 //! Serialization/deserelization should give an item identical to original.
54 
55 TEST_F(ToyItemsSerializationTest, modifiedShapeGroupItemInModel)
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 }
77 
78 //! Insert all supported items in a model and check that after serialization
79 
81 {
82  SampleModel model;
91 
92  auto modelCopy = Utils::CreateCopy(model);
93  EXPECT_EQ(model.rootItem()->childrenCount(), modelCopy->rootItem()->childrenCount());
94 }
static const QString P_RADIUS
void setCurrentType(const std::string &model_type)
Sets item corresponding to given model type.
Definition: groupitem.cpp:58
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
Testing serialization of ToyItems using json converters.
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
Defines class CLASS?
Defines class CLASS?
Defines class CLASS?
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
materialitems.h Collection of materials to populate MaterialModel.
const ModelView::model_type AnysoPyramidItemType
Definition: toyitems.h:37
Collection of toy items and models for testing purposes.
Definition: toyitems.h:26
Defines class CLASS?
TEST_F(ToyItemsSerializationTest, defaultShapeGroupItemInModel)
Checking ShapeGroupItem in a model.
Defines class CLASS?