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

Implements class CLASS? More...

Include dependency graph for compounditem.test.cpp:

Go to the source code of this file.

Classes

class  CompoundItemTest
 Test of CompountItem machinery (property children etc). More...
 

Functions

 TEST_F (CompoundItemTest, addBoolProperty)
 
 TEST_F (CompoundItemTest, addCharProperty)
 
 TEST_F (CompoundItemTest, addDoubleProperty)
 
 TEST_F (CompoundItemTest, addIntProperty)
 
 TEST_F (CompoundItemTest, addStringProperty)
 
 TEST_F (CompoundItemTest, children)
 Test all children method. More...
 
 TEST_F (CompoundItemTest, displayNameIndexAddition)
 Tests automatic index addition to default display name. More...
 
 TEST_F (CompoundItemTest, initialState)
 
 TEST_F (CompoundItemTest, itemAccess)
 
 TEST_F (CompoundItemTest, itemVectorAccess)
 
 TEST_F (CompoundItemTest, setBoolProperty)
 
 TEST_F (CompoundItemTest, setCharProperty)
 
 TEST_F (CompoundItemTest, setDoubleProperty)
 
 TEST_F (CompoundItemTest, setIntProperty)
 
 TEST_F (CompoundItemTest, setStringProperty)
 

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 compounditem.test.cpp.

Function Documentation

◆ TEST_F() [1/15]

TEST_F ( CompoundItemTest  ,
addBoolProperty   
)

Definition at line 154 of file compounditem.test.cpp.

155 {
156  CompoundItem item;
157 
158  const bool expected = true;
159  auto propertyItem = item.addProperty(property_name, expected);
160  EXPECT_TRUE(Utils::HasTag(item, property_name));
161 
162  EXPECT_EQ(propertyItem->modelType(), Constants::PropertyType);
163  EXPECT_TRUE(Utils::IsBoolVariant(propertyItem->data<QVariant>()));
164  EXPECT_EQ(propertyItem->data<bool>(), expected);
165 
166  EXPECT_FALSE(propertyItem->data<QVariant>(ItemDataRole::LIMITS).isValid());
167 }
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
const model_type PropertyType
Definition: mvvm_types.h:59
const int LIMITS
possibly limits on item's data
Definition: mvvm_types.h:33
MVVM_MODEL_EXPORT bool HasTag(const SessionItem &item, const std::string &tag)
Returns true if given item has registered tag.
Definition: itemutils.cpp:86
MVVM_MODEL_EXPORT bool IsBoolVariant(const Variant &variant)
Returns true in the case of double value based variant.

References ModelView::CompoundItem::addProperty(), ModelView::Utils::HasTag(), ModelView::Utils::IsBoolVariant(), ModelView::ItemDataRole::LIMITS, and ModelView::Constants::PropertyType.

Here is the call graph for this function:

◆ TEST_F() [2/15]

TEST_F ( CompoundItemTest  ,
addCharProperty   
)

Definition at line 102 of file compounditem.test.cpp.

103 {
104  CompoundItem item;
105 
106  auto propertyItem = item.addProperty(property_name, "abc");
107  EXPECT_TRUE(Utils::HasTag(item, property_name));
108 
109  EXPECT_EQ(propertyItem->modelType(), Constants::PropertyType);
110  EXPECT_TRUE(Utils::IsStdStringVariant(propertyItem->data<QVariant>()));
111  EXPECT_EQ(propertyItem->data<std::string>(), std::string("abc"));
112 
113  EXPECT_FALSE(propertyItem->data<QVariant>(ItemDataRole::LIMITS).isValid());
114 }
MVVM_MODEL_EXPORT bool IsStdStringVariant(const Variant &variant)
Returns true in the case of double value based variant.

References ModelView::CompoundItem::addProperty(), ModelView::Utils::HasTag(), ModelView::Utils::IsStdStringVariant(), ModelView::ItemDataRole::LIMITS, and ModelView::Constants::PropertyType.

Here is the call graph for this function:

◆ TEST_F() [3/15]

TEST_F ( CompoundItemTest  ,
addDoubleProperty   
)

Definition at line 69 of file compounditem.test.cpp.

70 {
71  CompoundItem item;
72 
73  const double expected = 42.1;
74  auto propertyItem = item.addProperty(property_name, expected);
75  EXPECT_TRUE(Utils::HasTag(item, property_name));
76 
77  EXPECT_EQ(propertyItem->modelType(), Constants::PropertyType);
78  EXPECT_TRUE(Utils::IsDoubleVariant(propertyItem->data<QVariant>()));
79  EXPECT_EQ(propertyItem->displayName(), property_name);
80  EXPECT_EQ(propertyItem->data<double>(), expected);
81 
82  EXPECT_TRUE(propertyItem->data<QVariant>(ItemDataRole::LIMITS).isValid());
83 
84  // limits should be "negative 'unlimited' by default
85  auto limits = propertyItem->data<RealLimits>(ItemDataRole::LIMITS);
86  EXPECT_FALSE(limits.hasLowerLimit());
87  EXPECT_FALSE(limits.hasUpperLimit());
88 }
Limits for double.
Definition: reallimits.h:25
MVVM_MODEL_EXPORT bool IsDoubleVariant(const Variant &variant)
Returns true in the case of double value based variant.

References ModelView::CompoundItem::addProperty(), ModelView::Utils::HasTag(), ModelView::Utils::IsDoubleVariant(), ModelView::ItemDataRole::LIMITS, and ModelView::Constants::PropertyType.

Here is the call graph for this function:

◆ TEST_F() [4/15]

TEST_F ( CompoundItemTest  ,
addIntProperty   
)

Definition at line 41 of file compounditem.test.cpp.

42 {
43  CompoundItem item;
44 
45  const int expected = 42;
46  auto propertyItem = item.addProperty(property_name, expected);
47  EXPECT_TRUE(Utils::HasTag(item, "name"));
48 
49  EXPECT_EQ(propertyItem->modelType(), Constants::PropertyType);
50  EXPECT_TRUE(Utils::IsIntVariant(propertyItem->data<QVariant>()));
51  EXPECT_EQ(propertyItem->displayName(), property_name);
52  EXPECT_EQ(propertyItem->data<int>(), expected);
53 
54  EXPECT_FALSE(propertyItem->data<QVariant>(ItemDataRole::LIMITS).isValid());
55 }
MVVM_MODEL_EXPORT bool IsIntVariant(const Variant &variant)
Returns true in the case of double value based variant.

References ModelView::CompoundItem::addProperty(), ModelView::Utils::HasTag(), ModelView::Utils::IsIntVariant(), ModelView::ItemDataRole::LIMITS, and ModelView::Constants::PropertyType.

Here is the call graph for this function:

◆ TEST_F() [5/15]

TEST_F ( CompoundItemTest  ,
addStringProperty   
)

Definition at line 128 of file compounditem.test.cpp.

129 {
130  CompoundItem item;
131 
132  auto propertyItem = item.addProperty(property_name, std::string("abc"));
133  EXPECT_TRUE(Utils::HasTag(item, property_name));
134 
135  EXPECT_EQ(propertyItem->modelType(), Constants::PropertyType);
136  EXPECT_TRUE(Utils::IsStdStringVariant(propertyItem->data<QVariant>()));
137  EXPECT_EQ(propertyItem->data<std::string>(), std::string("abc"));
138 
139  EXPECT_FALSE(propertyItem->data<QVariant>(ItemDataRole::LIMITS).isValid());
140 }

References ModelView::CompoundItem::addProperty(), ModelView::Utils::HasTag(), ModelView::Utils::IsStdStringVariant(), ModelView::ItemDataRole::LIMITS, and ModelView::Constants::PropertyType.

Here is the call graph for this function:

◆ TEST_F() [6/15]

TEST_F ( CompoundItemTest  ,
children   
)

Test all children method.

Property items are also children.

Definition at line 247 of file compounditem.test.cpp.

248 {
249  CompoundItem item;
250  EXPECT_TRUE(item.children().empty());
251  auto propertyItem = item.addProperty(property_name, false);
252  EXPECT_EQ(item.children(), std::vector<SessionItem*>({propertyItem}));
253 }
std::vector< SessionItem * > children() const
Returns vector of children formed from all chidlren from all tags.

References ModelView::CompoundItem::addProperty(), and ModelView::SessionItem::children().

Here is the call graph for this function:

◆ TEST_F() [7/15]

TEST_F ( CompoundItemTest  ,
displayNameIndexAddition   
)

Tests automatic index addition to default display name.

Definition at line 219 of file compounditem.test.cpp.

220 {
221  const std::string tag = "tag";
222 
223  // creating parent with one tag
224  SessionItem parent;
225  parent.registerTag(TagInfo::universalTag(tag));
226 
227  // inserting two children
228  auto child0 = new CompoundItem;
229  parent.insertItem(child0, TagRow::append(tag));
230  auto child1 = new CompoundItem;
231  parent.insertItem(child1, TagRow::append(tag));
232 
233  // Default display names of items of the same type should have indices
234  EXPECT_EQ(child0->displayName(), Constants::CompoundItemType + "0");
235  EXPECT_EQ(child1->displayName(), Constants::CompoundItemType + "1");
236 
237  // however, if children have custom display name, they should remain intact
238  child0->setDisplayName("Jekyll");
239  child1->setDisplayName("Hyde");
240  EXPECT_EQ(child0->displayName(), "Jekyll");
241  EXPECT_EQ(child1->displayName(), "Hyde");
242 }
The main object representing an editable/displayable/serializable entity.
Definition: sessionitem.h:38
void registerTag(const TagInfo &tagInfo, bool set_as_default=false)
Registers tag to hold items under given name.
bool insertItem(SessionItem *item, const TagRow &tagrow)
Insert item into given tag under the given row.
const model_type CompoundItemType
Definition: mvvm_types.h:48

References ModelView::TagRow::append(), ModelView::Constants::CompoundItemType, ModelView::SessionItem::insertItem(), ModelView::SessionItem::registerTag(), and ModelView::TagInfo::universalTag().

Here is the call graph for this function:

◆ TEST_F() [8/15]

TEST_F ( CompoundItemTest  ,
initialState   
)

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

36 {
37  CompoundItem item;
38  EXPECT_EQ(item.childrenCount(), 0);
39 }
int childrenCount() const
Returns total number of children in all tags.

References ModelView::SessionItem::childrenCount().

Here is the call graph for this function:

◆ TEST_F() [9/15]

TEST_F ( CompoundItemTest  ,
itemAccess   
)

Definition at line 181 of file compounditem.test.cpp.

182 {
183  const std::string tag = "tag";
184 
185  // creating parent with one tag
186  SessionItem parent;
187  parent.registerTag(TagInfo::universalTag(tag));
188 
189  // inserting two children
190  auto property = new PropertyItem;
191  parent.insertItem(property, {tag, 0});
192 
193  EXPECT_TRUE(parent.item<PropertyItem>(tag) == property);
194  EXPECT_THROW(parent.item<CompoundItem>(tag), std::runtime_error);
195 }
Item to carry concrete editable entity (e.g.
Definition: propertyitem.h:27
T * item(const std::string &tag) const
Returns first item under given tag casted to a specified type.
Definition: sessionitem.h:156

References ModelView::SessionItem::insertItem(), ModelView::SessionItem::item(), ModelView::SessionItem::registerTag(), and ModelView::TagInfo::universalTag().

Here is the call graph for this function:

◆ TEST_F() [10/15]

TEST_F ( CompoundItemTest  ,
itemVectorAccess   
)

Definition at line 197 of file compounditem.test.cpp.

198 {
199  const std::string tag = "tag";
200 
201  // creating parent with one tag
202  SessionItem parent;
203  parent.registerTag(TagInfo::universalTag(tag));
204 
205  // inserting two children
206  auto property1 = new PropertyItem;
207  auto property2 = new PropertyItem;
208  parent.insertItem(property1, TagRow::append(tag));
209  parent.insertItem(property2, TagRow::append(tag));
210 
211  auto items = parent.items<PropertyItem>(tag);
212  std::vector<PropertyItem*> expected = {property1, property2};
213  EXPECT_EQ(items, expected);
214  EXPECT_EQ(parent.items<CompoundItem>(tag).size(), 0);
215 }
std::vector< T * > items(const std::string &tag) const
Returns all items under given tag casted to specific type.
Definition: sessionitem.h:169

References ModelView::TagRow::append(), ModelView::SessionItem::insertItem(), ModelView::SessionItem::items(), ModelView::SessionItem::registerTag(), and ModelView::TagInfo::universalTag().

Here is the call graph for this function:

◆ TEST_F() [11/15]

TEST_F ( CompoundItemTest  ,
setBoolProperty   
)

Definition at line 169 of file compounditem.test.cpp.

170 {
171  CompoundItem item;
172  auto propertyItem = item.addProperty(property_name, false);
173 
174  const bool expected = true;
175  item.setProperty(property_name, expected);
176 
177  EXPECT_EQ(item.property<bool>(property_name), expected);
178  EXPECT_EQ(propertyItem->data<bool>(), expected);
179 }
T property(const std::string &tag) const
Returns data stored in property item.
Definition: sessionitem.h:181
void setProperty(const std::string &tag, const T &value)
Sets value to property item.
Definition: sessionitem.h:190

References ModelView::CompoundItem::addProperty(), ModelView::SessionItem::property(), and ModelView::SessionItem::setProperty().

Here is the call graph for this function:

◆ TEST_F() [12/15]

TEST_F ( CompoundItemTest  ,
setCharProperty   
)

Definition at line 116 of file compounditem.test.cpp.

117 {
118  CompoundItem item;
119  auto propertyItem = item.addProperty(property_name, "aaa");
120 
121  const char* expected{"bbb"};
122  item.setProperty(property_name, expected);
123 
124  EXPECT_EQ(item.property<std::string>(property_name), std::string(expected));
125  EXPECT_EQ(propertyItem->data<std::string>(), std::string(expected));
126 }

References ModelView::CompoundItem::addProperty(), ModelView::SessionItem::property(), and ModelView::SessionItem::setProperty().

Here is the call graph for this function:

◆ TEST_F() [13/15]

TEST_F ( CompoundItemTest  ,
setDoubleProperty   
)

Definition at line 90 of file compounditem.test.cpp.

91 {
92  CompoundItem item;
93  auto propertyItem = item.addProperty(property_name, 41.11);
94 
95  const double expected = 42.0;
96  item.setProperty(property_name, expected);
97 
98  EXPECT_EQ(item.property<double>(property_name), expected);
99  EXPECT_EQ(propertyItem->data<double>(), expected);
100 }

References ModelView::CompoundItem::addProperty(), ModelView::SessionItem::property(), and ModelView::SessionItem::setProperty().

Here is the call graph for this function:

◆ TEST_F() [14/15]

TEST_F ( CompoundItemTest  ,
setIntProperty   
)

Definition at line 57 of file compounditem.test.cpp.

58 {
59  CompoundItem item;
60  auto propertyItem = item.addProperty(property_name, 41);
61 
62  const int expected = 42;
63  item.setProperty(property_name, expected);
64 
65  EXPECT_EQ(item.property<int>(property_name), expected);
66  EXPECT_EQ(propertyItem->data<int>(), expected);
67 }

References ModelView::CompoundItem::addProperty(), ModelView::SessionItem::property(), and ModelView::SessionItem::setProperty().

Here is the call graph for this function:

◆ TEST_F() [15/15]

TEST_F ( CompoundItemTest  ,
setStringProperty   
)

Definition at line 142 of file compounditem.test.cpp.

143 {
144  CompoundItem item;
145  auto propertyItem = item.addProperty(property_name, std::string("aaa"));
146 
147  const std::string expected{"bbb"};
148  item.setProperty(property_name, expected);
149 
150  EXPECT_EQ(item.property<std::string>(property_name), expected);
151  EXPECT_EQ(propertyItem->data<std::string>(), expected);
152 }

References ModelView::CompoundItem::addProperty(), ModelView::SessionItem::property(), and ModelView::SessionItem::setProperty().

Here is the call graph for this function: