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

Implements class CLASS? More...

Include dependency graph for sessionitemcontainer.test.cpp:

Go to the source code of this file.

Classes

class  SessionItemContainerTest
 Tests for TestSessionItemContainer class. More...
 

Functions

 TEST_F (SessionItemContainerTest, canInsertItem)
 Checking ::canInsertItem. More...
 
 TEST_F (SessionItemContainerTest, canInsertItemForPropertyTag)
 Checking ::canInsertItem. More...
 
 TEST_F (SessionItemContainerTest, canTakeItem)
 Checking ::canTakeItem. More...
 
 TEST_F (SessionItemContainerTest, indexOfItem)
 Checking ::indexOfItem. More...
 
 TEST_F (SessionItemContainerTest, initialState)
 Initial state of emty SessionItemTag. More...
 
 TEST_F (SessionItemContainerTest, insertItem)
 Checking ::insertItem. More...
 
 TEST_F (SessionItemContainerTest, insertItemModelType)
 Checking ::insertItem when item has specific model type. More...
 
 TEST_F (SessionItemContainerTest, insertItemPropertyType)
 Checking ::insertItem when tag is related to property tag. More...
 
 TEST_F (SessionItemContainerTest, itemAt)
 Checking ::itemAt. More...
 
 TEST_F (SessionItemContainerTest, takeItem)
 Checking ::takeItem. More...
 
 TEST_F (SessionItemContainerTest, takeItemPropertyType)
 Checking ::takeItem when tag is related to property tag. 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 sessionitemcontainer.test.cpp.

Function Documentation

◆ TEST_F() [1/11]

TEST_F ( SessionItemContainerTest  ,
canInsertItem   
)

Checking ::canInsertItem.

Definition at line 239 of file sessionitemcontainer.test.cpp.

240 {
241  const std::string tag_name("tag");
242  const std::string model_type("model_a");
243 
244  SessionItemContainer tag(TagInfo::universalTag(tag_name));
245 
246  // inserting non-existing item
247  EXPECT_FALSE(tag.canInsertItem(nullptr, 0));
248 
249  // we should be allowed to insert valid child
250  auto child1 = std::make_unique<SessionItem>(model_type);
251  EXPECT_TRUE(tag.canInsertItem(child1.get(), 0));
252 
253  // wrong index is not allowed for insertion
254  EXPECT_FALSE(tag.canInsertItem(child1.get(), 1));
255  EXPECT_FALSE(tag.canInsertItem(child1.get(), -1));
256 
257  // inserting child
258  EXPECT_TRUE(tag.insertItem(child1.release(), tag.itemCount()));
259 
260  // can we insert second child?
261  auto child2 = std::make_unique<SessionItem>(model_type);
262  EXPECT_TRUE(tag.canInsertItem(child2.get(), 0));
263  EXPECT_TRUE(tag.canInsertItem(child2.get(), 1));
264  EXPECT_FALSE(tag.canInsertItem(child2.get(), 2));
265  EXPECT_FALSE(tag.canInsertItem(child2.get(), -1));
266 }
Holds collection of SessionItem objects related to the same tag.
std::string model_type
Definition: types.h:23

References ModelView::SessionItemContainer::canInsertItem(), ModelView::SessionItemContainer::insertItem(), ModelView::SessionItemContainer::itemCount(), and ModelView::TagInfo::universalTag().

Here is the call graph for this function:

◆ TEST_F() [2/11]

TEST_F ( SessionItemContainerTest  ,
canInsertItemForPropertyTag   
)

Checking ::canInsertItem.

Definition at line 270 of file sessionitemcontainer.test.cpp.

271 {
272  const std::string name("tag");
273  const std::string property_type("Property");
274 
275  SessionItemContainer tag(TagInfo::propertyTag(name, property_type));
276 
277  // we should be allowed to insert valid child
278  auto child1 = std::make_unique<SessionItem>(property_type);
279  EXPECT_TRUE(tag.canInsertItem(child1.get(), 0));
280 
281  // inserting child
282  EXPECT_TRUE(tag.insertItem(child1.release(), tag.itemCount()));
283 
284  // second property shouldn't be posible to insert because of exceeded maximum
285  auto child2 = std::make_unique<SessionItem>(property_type);
286  EXPECT_FALSE(tag.canInsertItem(child2.get(), 0));
287 }
QString const & name(EShape k)
Definition: particles.cpp:21

References ModelView::SessionItemContainer::canInsertItem(), ModelView::SessionItemContainer::insertItem(), ModelView::SessionItemContainer::itemCount(), RealSpace::Particles::name(), and ModelView::TagInfo::propertyTag().

Here is the call graph for this function:

◆ TEST_F() [3/11]

TEST_F ( SessionItemContainerTest  ,
canTakeItem   
)

Checking ::canTakeItem.

Definition at line 217 of file sessionitemcontainer.test.cpp.

218 {
219  const std::string tag_name("tag");
220  const std::string model_type("model_a");
221 
222  SessionItemContainer tag(TagInfo::universalTag(tag_name));
223 
224  // taking non existing items
225  EXPECT_FALSE(tag.canTakeItem(0));
226 
227  // inserting items
228  SessionItem* child1 = new SessionItem(model_type);
229  EXPECT_TRUE(tag.insertItem(child1, tag.itemCount()));
230  EXPECT_TRUE(tag.canTakeItem(0));
231 
232  // taking non existing items
233  EXPECT_FALSE(tag.canTakeItem(-1));
234  EXPECT_FALSE(tag.canTakeItem(tag.itemCount()));
235 }
The main object representing an editable/displayable/serializable entity.
Definition: sessionitem.h:38

References ModelView::SessionItemContainer::canTakeItem(), ModelView::SessionItemContainer::insertItem(), ModelView::SessionItemContainer::itemCount(), and ModelView::TagInfo::universalTag().

Here is the call graph for this function:

◆ TEST_F() [4/11]

TEST_F ( SessionItemContainerTest  ,
indexOfItem   
)

Checking ::indexOfItem.

Definition at line 136 of file sessionitemcontainer.test.cpp.

137 {
138  const std::string tag_name("tag");
139  const std::string model_type("model_a");
140 
141  SessionItemContainer tag(TagInfo::universalTag(tag_name));
142 
143  // index of two items
144  SessionItem* child1 = new SessionItem(model_type);
145  SessionItem* child2 = new SessionItem(model_type);
146  EXPECT_TRUE(tag.insertItem(child1, tag.itemCount()));
147  EXPECT_EQ(tag.indexOfItem(child1), 0);
148  EXPECT_TRUE(tag.insertItem(child2, tag.itemCount()));
149  EXPECT_EQ(tag.indexOfItem(child1), 0);
150  EXPECT_EQ(tag.indexOfItem(child2), 1);
151 
152  // not existing items
153  EXPECT_EQ(tag.indexOfItem(nullptr), -1);
154  auto child3 = std::make_unique<SessionItem>(model_type);
155  EXPECT_EQ(tag.indexOfItem(child3.get()), -1);
156 }

References ModelView::SessionItemContainer::indexOfItem(), ModelView::SessionItemContainer::insertItem(), ModelView::SessionItemContainer::itemCount(), and ModelView::TagInfo::universalTag().

Here is the call graph for this function:

◆ TEST_F() [5/11]

TEST_F ( SessionItemContainerTest  ,
initialState   
)

Initial state of emty SessionItemTag.

Definition at line 33 of file sessionitemcontainer.test.cpp.

34 {
35  const std::string name("tag");
36  SessionItemContainer tag(TagInfo::universalTag(name));
37 
38  EXPECT_EQ(tag.itemCount(), 0);
39  EXPECT_TRUE(tag.empty());
40  EXPECT_EQ(tag.name(), name);
41  EXPECT_EQ(tag.items(), std::vector<SessionItem*>());
42 }

References ModelView::SessionItemContainer::empty(), ModelView::SessionItemContainer::itemCount(), ModelView::SessionItemContainer::items(), ModelView::SessionItemContainer::name(), RealSpace::Particles::name(), and ModelView::TagInfo::universalTag().

Here is the call graph for this function:

◆ TEST_F() [6/11]

TEST_F ( SessionItemContainerTest  ,
insertItem   
)

Checking ::insertItem.

Definition at line 46 of file sessionitemcontainer.test.cpp.

47 {
48  const std::string tag_name("tag");
49  SessionItemContainer tag(TagInfo::universalTag(tag_name));
50 
51  // inserting non-existing item is not allowed
52  EXPECT_FALSE(tag.insertItem(nullptr, tag.itemCount()));
53  EXPECT_EQ(tag.itemCount(), 0);
54 
55  // insertion at the end
56  SessionItem* child1 = new SessionItem;
57  SessionItem* child2 = new SessionItem;
58  EXPECT_TRUE(tag.insertItem(child1, tag.itemCount()));
59  EXPECT_TRUE(tag.insertItem(child2, tag.itemCount()));
60  EXPECT_EQ(tag.itemCount(), 2);
61  EXPECT_FALSE(tag.empty());
62  std::vector<SessionItem*> expected = {child1, child2};
63  EXPECT_EQ(tag.items(), expected);
64 
65  // insertion at the beginning
66  SessionItem* child3 = new SessionItem;
67  EXPECT_TRUE(tag.insertItem(child3, 0));
68  expected = {child3, child1, child2};
69  EXPECT_EQ(tag.items(), expected);
70 
71  // insertion in between
72  SessionItem* child4 = new SessionItem;
73  EXPECT_TRUE(tag.insertItem(child4, 1));
74  expected = {child3, child4, child1, child2};
75  EXPECT_EQ(tag.items(), expected);
76 
77  // using index equal to number of items
78  SessionItem* child5 = new SessionItem;
79  EXPECT_TRUE(tag.insertItem(child5, tag.itemCount()));
80  expected = {child3, child4, child1, child2, child5};
81  EXPECT_EQ(tag.items(), expected);
82 
83  // insertion with wrong index
84  SessionItem* child6 = new SessionItem;
85  EXPECT_FALSE(tag.insertItem(child6, 42));
86  EXPECT_EQ(tag.items(), expected);
87  delete child6;
88 }

References ModelView::SessionItemContainer::empty(), ModelView::SessionItemContainer::insertItem(), ModelView::SessionItemContainer::itemCount(), ModelView::SessionItemContainer::items(), and ModelView::TagInfo::universalTag().

Here is the call graph for this function:

◆ TEST_F() [7/11]

TEST_F ( SessionItemContainerTest  ,
insertItemModelType   
)

Checking ::insertItem when item has specific model type.

Definition at line 92 of file sessionitemcontainer.test.cpp.

93 {
94  const std::string tag_name("tag");
95  const std::vector<std::string> model_types = {"model_a"};
96 
97  SessionItemContainer tag(TagInfo::universalTag(tag_name, model_types));
98 
99  // insertion of wrong model type is not allowed
100  SessionItem* child1 = new SessionItem("model_a");
101  SessionItem* child2 = new SessionItem("model_b");
102  EXPECT_TRUE(tag.insertItem(child1, tag.itemCount()));
103  EXPECT_FALSE(tag.insertItem(child2, tag.itemCount()));
104  delete child2;
105 
106  std::vector<SessionItem*> expected = {child1};
107  EXPECT_EQ(tag.items(), expected);
108 }

References ModelView::SessionItemContainer::insertItem(), ModelView::SessionItemContainer::itemCount(), ModelView::SessionItemContainer::items(), and ModelView::TagInfo::universalTag().

Here is the call graph for this function:

◆ TEST_F() [8/11]

TEST_F ( SessionItemContainerTest  ,
insertItemPropertyType   
)

Checking ::insertItem when tag is related to property tag.

Definition at line 112 of file sessionitemcontainer.test.cpp.

113 {
114  const std::string name("tag");
115  const std::string property_type("Property");
116 
117  SessionItemContainer tag(TagInfo::propertyTag(name, property_type));
118 
119  // insertion of second property item is not allowed (because of reached maximum)
120  SessionItem* child1 = new SessionItem(property_type);
121  SessionItem* child2 = new SessionItem(property_type);
122  EXPECT_TRUE(tag.insertItem(child1, tag.itemCount()));
123  EXPECT_FALSE(tag.insertItem(child2, tag.itemCount()));
124  delete child2;
125 
126  // insertion of wrong model type is not allowed
127  SessionItem* child3 = new SessionItem("another_model");
128  EXPECT_FALSE(tag.insertItem(child3, tag.itemCount()));
129  delete child3;
130  std::vector<SessionItem*> expected = {child1};
131  EXPECT_EQ(tag.items(), expected);
132 }

References ModelView::SessionItemContainer::insertItem(), ModelView::SessionItemContainer::itemCount(), ModelView::SessionItemContainer::items(), RealSpace::Particles::name(), and ModelView::TagInfo::propertyTag().

Here is the call graph for this function:

◆ TEST_F() [9/11]

TEST_F ( SessionItemContainerTest  ,
itemAt   
)

Checking ::itemAt.

Definition at line 160 of file sessionitemcontainer.test.cpp.

161 {
162  const std::string tag_name("tag");
163  const std::string model_type("model_a");
164 
165  SessionItemContainer tag(TagInfo::universalTag(tag_name));
166 
167  // items at given indices
168  SessionItem* child1 = new SessionItem(model_type);
169  SessionItem* child2 = new SessionItem(model_type);
170  EXPECT_TRUE(tag.insertItem(child1, tag.itemCount()));
171  EXPECT_TRUE(tag.insertItem(child2, tag.itemCount()));
172  EXPECT_EQ(tag.itemAt(0), child1);
173  EXPECT_EQ(tag.itemAt(1), child2);
174 
175  // non-existing indices
176  EXPECT_EQ(tag.itemAt(2), nullptr);
177  EXPECT_EQ(tag.itemAt(3), nullptr);
178  EXPECT_EQ(tag.itemAt(-1), nullptr);
179 }

References ModelView::SessionItemContainer::insertItem(), ModelView::SessionItemContainer::itemAt(), ModelView::SessionItemContainer::itemCount(), and ModelView::TagInfo::universalTag().

Here is the call graph for this function:

◆ TEST_F() [10/11]

TEST_F ( SessionItemContainerTest  ,
takeItem   
)

Checking ::takeItem.

Definition at line 183 of file sessionitemcontainer.test.cpp.

184 {
185  const std::string tag_name("tag");
186  const std::string model_type("model_a");
187 
188  SessionItemContainer tag(TagInfo::universalTag(tag_name));
189 
190  // taking non existing items
191  EXPECT_EQ(tag.takeItem(0), nullptr);
192 
193  // inserting items
194  SessionItem* child1 = new SessionItem(model_type);
195  SessionItem* child2 = new SessionItem(model_type);
196  SessionItem* child3 = new SessionItem(model_type);
197  EXPECT_TRUE(tag.insertItem(child1, tag.itemCount()));
198  EXPECT_TRUE(tag.insertItem(child2, tag.itemCount()));
199  EXPECT_TRUE(tag.insertItem(child3, tag.itemCount()));
200 
201  // taking item in between
202  auto taken2 = tag.takeItem(1);
203  EXPECT_EQ(child2, taken2);
204  delete taken2;
205 
206  // order of remaining children
207  std::vector<SessionItem*> expected = {child1, child3};
208  EXPECT_EQ(tag.items(), expected);
209 
210  // taking non existing items
211  EXPECT_EQ(tag.takeItem(-1), nullptr);
212  EXPECT_EQ(tag.takeItem(tag.itemCount()), nullptr);
213 }

References ModelView::SessionItemContainer::insertItem(), ModelView::SessionItemContainer::itemCount(), ModelView::SessionItemContainer::items(), ModelView::SessionItemContainer::takeItem(), and ModelView::TagInfo::universalTag().

Here is the call graph for this function:

◆ TEST_F() [11/11]

TEST_F ( SessionItemContainerTest  ,
takeItemPropertyType   
)

Checking ::takeItem when tag is related to property tag.

Definition at line 291 of file sessionitemcontainer.test.cpp.

292 {
293  const std::string name("tag");
294  const std::string property_type("Property");
295 
296  SessionItemContainer tag(TagInfo::propertyTag(name, property_type));
297 
298  // insertion of second property item is not allowed (because of reached maximum)
299  SessionItem* child1 = new SessionItem(property_type);
300  EXPECT_TRUE(tag.insertItem(child1, tag.itemCount()));
301 
302  // attempt to take property item
303  EXPECT_FALSE(tag.canTakeItem(0));
304  EXPECT_EQ(tag.takeItem(0), nullptr);
305 }

References ModelView::SessionItemContainer::canTakeItem(), ModelView::SessionItemContainer::insertItem(), ModelView::SessionItemContainer::itemCount(), RealSpace::Particles::name(), ModelView::TagInfo::propertyTag(), and ModelView::SessionItemContainer::takeItem().

Here is the call graph for this function: