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

Implements class CLASS? More...

Include dependency graph for jsonitembackupstrategy.test.cpp:

Go to the source code of this file.

Classes

class  JsonItemBackupStrategyTest
 

Functions

 TEST_F (JsonItemBackupStrategyTest, compoundItem)
 Saving/restoring CompoundItem. More...
 
 TEST_F (JsonItemBackupStrategyTest, customItem)
 Saving/restoring CustomItem. More...
 
 TEST_F (JsonItemBackupStrategyTest, propertyItem)
 Saving/restoring PropertyItem. 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 jsonitembackupstrategy.test.cpp.

Function Documentation

◆ TEST_F() [1/3]

TEST_F ( JsonItemBackupStrategyTest  ,
compoundItem   
)

Saving/restoring CompoundItem.

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

63 {
64  auto strategy = createBackupStrategy();
65 
66  CompoundItem item;
67  auto property = item.addProperty("thickness", 42.0);
68 
69  strategy->saveItem(&item);
70  auto restored = strategy->restoreItem();
71 
72  EXPECT_EQ(item.modelType(), restored->modelType());
73  EXPECT_EQ(item.identifier(), restored->identifier());
74  EXPECT_EQ(restored->getItem("thickness")->data<double>(), property->data<double>());
75  EXPECT_EQ(restored->getItem("thickness")->identifier(), property->identifier());
76 }
Complex item holding mixed SessionItem types (single properties and other CompountItems).
Definition: compounditem.h:28
T * addProperty(const std::string &name)
Adds property item of given type.
Definition: compounditem.h:43
std::string identifier() const
Returns unique identifier.
Definition: sessionitem.cpp:87
model_type modelType() const
Returns item's model type.
Definition: sessionitem.cpp:80

References ModelView::CompoundItem::addProperty(), ModelView::SessionItem::identifier(), and ModelView::SessionItem::modelType().

Here is the call graph for this function:

◆ TEST_F() [2/3]

TEST_F ( JsonItemBackupStrategyTest  ,
customItem   
)

Saving/restoring CustomItem.

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

81 {
82  auto strategy = createBackupStrategy();
83 
84  const std::string model_type(Constants::BaseType);
85 
86  // creating parent with one child
87  auto parent = std::make_unique<SessionItem>(model_type);
88  parent->setDisplayName("parent_name");
89  parent->registerTag(TagInfo::universalTag("defaultTag"), /*set_as_default*/ true);
90  auto child = new SessionItem(model_type);
91  child->setDisplayName("child_name");
92  parent->insertItem(child, TagRow::append());
93 
94  // creating copy
95  strategy->saveItem(parent.get());
96  auto reco_parent = strategy->restoreItem();
97 
98  EXPECT_EQ(reco_parent->childrenCount(), 1);
99  EXPECT_EQ(reco_parent->modelType(), model_type);
100  EXPECT_EQ(reco_parent->displayName(), "parent_name");
101  EXPECT_EQ(reco_parent->identifier(), parent->identifier());
102  EXPECT_EQ(reco_parent->itemTags()->defaultTag(), "defaultTag");
103  EXPECT_EQ(reco_parent->model(), nullptr);
104 
105  // checking child reconstruction
106  auto reco_child = reco_parent->getItem("defaultTag");
107  EXPECT_EQ(reco_child->parent(), reco_parent.get());
108  EXPECT_EQ(reco_child->childrenCount(), 0);
109  EXPECT_EQ(reco_child->modelType(), model_type);
110  EXPECT_EQ(reco_child->displayName(), "child_name");
111  EXPECT_EQ(reco_child->identifier(), child->identifier());
112  EXPECT_EQ(reco_child->itemTags()->defaultTag(), "");
113 }
The main object representing an editable/displayable/serializable entity.
Definition: sessionitem.h:38
const model_type BaseType
Definition: mvvm_types.h:45
std::string model_type
Definition: types.h:23

References ModelView::TagRow::append(), ModelView::Constants::BaseType, and ModelView::TagInfo::universalTag().

Here is the call graph for this function:

◆ TEST_F() [3/3]

TEST_F ( JsonItemBackupStrategyTest  ,
propertyItem   
)

Saving/restoring PropertyItem.

Definition at line 45 of file jsonitembackupstrategy.test.cpp.

46 {
47  auto strategy = createBackupStrategy();
48 
49  PropertyItem item;
50  item.setData(42.0);
51 
52  strategy->saveItem(&item);
53  auto restored = strategy->restoreItem();
54 
55  EXPECT_EQ(item.modelType(), restored->modelType());
56  EXPECT_EQ(item.identifier(), restored->identifier());
57  EXPECT_EQ(item.data<QVariant>(), restored->data<QVariant>());
58 }
Item to carry concrete editable entity (e.g.
Definition: propertyitem.h:27
bool setData(const T &value, int role=ItemDataRole::DATA, bool direct=false)
Sets data for a given role.
Definition: sessionitem.h:141
T data(int role=ItemDataRole::DATA) const
Returns data of given type T for given role.
Definition: sessionitem.h:148

References ModelView::SessionItem::data(), ModelView::SessionItem::identifier(), ModelView::SessionItem::modelType(), and ModelView::SessionItem::setData().

Here is the call graph for this function: