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

Implements class CLASS? More...

Include dependency graph for jsonitemcopystrategy.test.cpp:

Go to the source code of this file.

Classes

class  JsonItemCopyStrategyTest
 

Functions

 TEST_F (JsonItemCopyStrategyTest, compoundItem)
 Saving/restoring CompoundItem. More...
 
 TEST_F (JsonItemCopyStrategyTest, customItem)
 Saving/restoring CustomItem. More...
 
 TEST_F (JsonItemCopyStrategyTest, 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 jsonitemcopystrategy.test.cpp.

Function Documentation

◆ TEST_F() [1/3]

TEST_F ( JsonItemCopyStrategyTest  ,
compoundItem   
)

Saving/restoring CompoundItem.

Definition at line 61 of file jsonitemcopystrategy.test.cpp.

62 {
63  auto strategy = createCopyStrategy();
64 
65  CompoundItem item;
66  auto property = item.addProperty("thickness", 42.0);
67 
68  auto copy = strategy->createCopy(&item);
69 
70  EXPECT_EQ(item.modelType(), copy->modelType());
71  EXPECT_EQ(copy->getItem("thickness")->data<double>(), property->data<double>());
72  EXPECT_FALSE(copy->getItem("thickness")->identifier() == property->identifier());
73  EXPECT_FALSE(item.identifier() == copy->identifier());
74 }
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
@ copy
full deep copying with item identifiers regenerated

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

Here is the call graph for this function:

◆ TEST_F() [2/3]

TEST_F ( JsonItemCopyStrategyTest  ,
customItem   
)

Saving/restoring CustomItem.

Definition at line 78 of file jsonitemcopystrategy.test.cpp.

79 {
80  auto strategy = createCopyStrategy();
81 
82  const std::string model_type(Constants::BaseType);
83 
84  // creating parent with one child
85  auto parent = std::make_unique<SessionItem>(model_type);
86  parent->setDisplayName("parent_name");
87  parent->registerTag(TagInfo::universalTag("defaultTag"), /*set_as_default*/ true);
88  auto child = new SessionItem(model_type);
89  child->setDisplayName("child_name");
90  parent->insertItem(child, TagRow::append());
91 
92  // creating copy
93  auto parent_copy = strategy->createCopy(parent.get());
94 
95  EXPECT_EQ(parent_copy->childrenCount(), 1);
96  EXPECT_EQ(parent_copy->modelType(), model_type);
97  EXPECT_EQ(parent_copy->displayName(), "parent_name");
98  EXPECT_EQ(parent_copy->itemTags()->defaultTag(), "defaultTag");
99  EXPECT_EQ(parent_copy->model(), nullptr);
100  EXPECT_FALSE(parent_copy->identifier() == parent->identifier());
101 
102  // checking child reconstruction
103  auto child_copy = parent_copy->getItem("defaultTag");
104  EXPECT_EQ(child_copy->parent(), parent_copy.get());
105  EXPECT_EQ(child_copy->childrenCount(), 0);
106  EXPECT_EQ(child_copy->modelType(), model_type);
107  EXPECT_EQ(child_copy->displayName(), "child_name");
108  EXPECT_EQ(child_copy->itemTags()->defaultTag(), "");
109  EXPECT_FALSE(child_copy->identifier() == child->identifier());
110 }
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 ( JsonItemCopyStrategyTest  ,
propertyItem   
)

Saving/restoring PropertyItem.

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

46 {
47  auto strategy = createCopyStrategy();
48 
49  PropertyItem item;
50  item.setData(42.0);
51 
52  auto copy = strategy->createCopy(&item);
53 
54  EXPECT_EQ(item.modelType(), copy->modelType());
55  EXPECT_EQ(item.data<QVariant>(), copy->data<QVariant>());
56  EXPECT_FALSE(item.identifier() == copy->identifier());
57 }
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::copy, ModelView::SessionItem::data(), ModelView::SessionItem::identifier(), ModelView::SessionItem::modelType(), and ModelView::SessionItem::setData().

Here is the call graph for this function: