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

Implements class CLASS? More...

Include dependency graph for sessionitem.test.cpp:

Go to the source code of this file.

Classes

class  SessionItemTest
 

Functions

 TEST_F (SessionItemTest, appearance)
 Checks item appearance (enabled/disabled and editable/readonly). More...
 
 TEST_F (SessionItemTest, defaultTag)
 Item registration in a pool. More...
 
 TEST_F (SessionItemTest, displayName)
 Display role. More...
 
 TEST_F (SessionItemTest, editorType)
 Checks item's editor type. More...
 
 TEST_F (SessionItemTest, hasData)
 
 TEST_F (SessionItemTest, initialState)
 
 TEST_F (SessionItemTest, insertChildren)
 Simple children insert. More...
 
 TEST_F (SessionItemTest, insertItem)
 Simple child insert. More...
 
 TEST_F (SessionItemTest, itemsInTag)
 
 TEST_F (SessionItemTest, modelType)
 
 TEST_F (SessionItemTest, registerDefaultTag)
 Registering tag and setting it as default. More...
 
 TEST_F (SessionItemTest, registerItem)
 Item registration in a pool. More...
 
 TEST_F (SessionItemTest, registerTag)
 Registering tags. More...
 
 TEST_F (SessionItemTest, setBoolData)
 
 TEST_F (SessionItemTest, setData)
 Validating ::setData and appearance of roles. More...
 
 TEST_F (SessionItemTest, setDataAndImplicitConversion)
 Validating ::setData in the context of implicit conversion. More...
 
 TEST_F (SessionItemTest, setDoubleData)
 
 TEST_F (SessionItemTest, setIntData)
 
 TEST_F (SessionItemTest, setStringData)
 
 TEST_F (SessionItemTest, singleTagAndItems)
 Insert and take tagged items. More...
 
 TEST_F (SessionItemTest, tag)
 Testing method ::tag. More...
 
 TEST_F (SessionItemTest, tagModelTypes)
 Inserting and removing items when tag has limits. More...
 
 TEST_F (SessionItemTest, tagRow)
 Checks row of item in its tag. More...
 
 TEST_F (SessionItemTest, tagRowOfItem)
 Checks row of item in its tag. More...
 
 TEST_F (SessionItemTest, tagWithLimits)
 Inserting and removing items when tag has limits. More...
 
 TEST_F (SessionItemTest, takeItem)
 Removing (taking) item from parent. More...
 
 TEST_F (SessionItemTest, tooltip)
 Checks item tooltip. More...
 
 TEST_F (SessionItemTest, twoTagsAndItems)
 Insert and take tagged items when two tags are present. More...
 
 TEST_F (SessionItemTest, variantMismatch)
 Attempt to set the different Variant to already existing role. 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 sessionitem.test.cpp.

Function Documentation

◆ TEST_F() [1/29]

TEST_F ( SessionItemTest  ,
appearance   
)

Checks item appearance (enabled/disabled and editable/readonly).

Definition at line 647 of file sessionitem.test.cpp.

648 {
649  SessionItem item("Model");
650 
651  // there shouldn't be any data
652  auto variant = item.data<QVariant>(ItemDataRole::APPEARANCE);
653  EXPECT_FALSE(variant.isValid());
654 
655  // default status
656  EXPECT_TRUE(item.isEnabled());
657  EXPECT_TRUE(item.isEditable());
658 
659  // disabling item
660  item.setEnabled(false);
661  EXPECT_FALSE(item.isEnabled());
662  EXPECT_TRUE(item.isEditable());
663 
664  // data should be there now
665  variant = item.data<QVariant>(ItemDataRole::APPEARANCE);
666  EXPECT_TRUE(variant.isValid());
667 
668  // making it readonly
669  item.setEditable(false);
670  EXPECT_FALSE(item.isEnabled());
671  EXPECT_FALSE(item.isEditable());
672 }
The main object representing an editable/displayable/serializable entity.
Definition: sessionitem.h:38
const int APPEARANCE
appearance flag
Definition: mvvm_types.h:32

References ModelView::ItemDataRole::APPEARANCE, ModelView::SessionItem::data(), ModelView::SessionItem::isEditable(), ModelView::SessionItem::isEnabled(), ModelView::SessionItem::setEditable(), and ModelView::SessionItem::setEnabled().

Here is the call graph for this function:

◆ TEST_F() [2/29]

TEST_F ( SessionItemTest  ,
defaultTag   
)

Item registration in a pool.

Definition at line 228 of file sessionitem.test.cpp.

229 {
230  SessionItem item;
231  EXPECT_EQ(item.itemTags()->defaultTag(), std::string());
232  EXPECT_FALSE(Utils::HasTag(item, "defaultTag"));
233 }
std::string defaultTag() const
Returns the name of the default tag.
SessionItemTags * itemTags()
Returns pointer to internal collection of tag-registered items (non-const version).
MVVM_MODEL_EXPORT bool HasTag(const SessionItem &item, const std::string &tag)
Returns true if given item has registered tag.
Definition: itemutils.cpp:86

References ModelView::SessionItemTags::defaultTag(), ModelView::Utils::HasTag(), and ModelView::SessionItem::itemTags().

Here is the call graph for this function:

◆ TEST_F() [3/29]

TEST_F ( SessionItemTest  ,
displayName   
)

Display role.

Definition at line 164 of file sessionitem.test.cpp.

165 {
166  SessionItem item("Property");
167  QVariant data(42.0);
168  EXPECT_TRUE(item.setData(data));
169 
170  // default display name coincide with model type
171  EXPECT_EQ(item.displayName(), "Property");
172 
173  // checking setter
174  item.setDisplayName("width");
175  EXPECT_EQ(item.displayName(), "width");
176  EXPECT_EQ(item.data<double>(), 42.0);
177 }

References ModelView::SessionItem::data(), ModelView::SessionItem::displayName(), ModelView::SessionItem::setData(), and ModelView::SessionItem::setDisplayName().

Here is the call graph for this function:

◆ TEST_F() [4/29]

TEST_F ( SessionItemTest  ,
editorType   
)

Checks item's editor type.

Definition at line 690 of file sessionitem.test.cpp.

691 {
692  SessionItem item("Model");
693 
694  EXPECT_EQ(item.editorType(), "");
695  EXPECT_FALSE(item.hasData(ItemDataRole::EDITORTYPE));
696 
697  EXPECT_EQ(item.setEditorType("abc"), &item);
698  EXPECT_TRUE(item.hasData(ItemDataRole::EDITORTYPE));
699  EXPECT_EQ(item.editorType(), "abc");
700 }
const int EDITORTYPE
type of custom editor for the data role
Definition: mvvm_types.h:35

References ModelView::ItemDataRole::EDITORTYPE, ModelView::SessionItem::editorType(), ModelView::SessionItem::hasData(), and ModelView::SessionItem::setEditorType().

Here is the call graph for this function:

◆ TEST_F() [5/29]

TEST_F ( SessionItemTest  ,
hasData   
)

Definition at line 110 of file sessionitem.test.cpp.

111 {
112  SessionItem item;
113 
114  EXPECT_FALSE(item.hasData());
115  EXPECT_TRUE(item.hasData(ItemDataRole::IDENTIFIER));
116  EXPECT_FALSE(item.hasData(ItemDataRole::DATA));
117  EXPECT_TRUE(item.hasData(ItemDataRole::DISPLAY));
118  EXPECT_FALSE(item.hasData(ItemDataRole::APPEARANCE));
119  EXPECT_FALSE(item.hasData(ItemDataRole::LIMITS));
120  EXPECT_FALSE(item.hasData(ItemDataRole::TOOLTIP));
121  EXPECT_FALSE(item.hasData(ItemDataRole::EDITORTYPE));
122 
123  item.setData(42.0);
124  EXPECT_TRUE(item.hasData());
125 }
bool hasData(int role=ItemDataRole::DATA) const
Returns true if item has data on board with given role.
bool setData(const T &value, int role=ItemDataRole::DATA, bool direct=false)
Sets data for a given role.
Definition: sessionitem.h:141
const int TOOLTIP
tooltip for item's data
Definition: mvvm_types.h:34
const int DATA
main data role
Definition: mvvm_types.h:30
const int LIMITS
possibly limits on item's data
Definition: mvvm_types.h:33
const int DISPLAY
display name
Definition: mvvm_types.h:31
const int IDENTIFIER
unique identifier
Definition: mvvm_types.h:29

References ModelView::ItemDataRole::APPEARANCE, ModelView::ItemDataRole::DATA, ModelView::ItemDataRole::DISPLAY, ModelView::ItemDataRole::EDITORTYPE, ModelView::SessionItem::hasData(), ModelView::ItemDataRole::IDENTIFIER, ModelView::ItemDataRole::LIMITS, ModelView::SessionItem::setData(), and ModelView::ItemDataRole::TOOLTIP.

Here is the call graph for this function:

◆ TEST_F() [6/29]

TEST_F ( SessionItemTest  ,
initialState   
)

Definition at line 36 of file sessionitem.test.cpp.

37 {
38  SessionItem item;
39  const int role = ItemDataRole::DATA;
40 
41  EXPECT_EQ(item.model(), nullptr);
42  EXPECT_EQ(item.parent(), nullptr);
43  EXPECT_EQ(item.childrenCount(), 0);
44  EXPECT_FALSE(item.data<QVariant>(role).isValid());
45  EXPECT_TRUE(item.children().empty());
46  EXPECT_EQ(item.modelType(), Constants::BaseType);
47  EXPECT_EQ(item.displayName(), Constants::BaseType);
48 
49  // Initially item has already an identifier defined.
50  std::vector<int> expected_roles = {ItemDataRole::IDENTIFIER, ItemDataRole::DISPLAY};
51  EXPECT_EQ(item.itemData()->roles(), expected_roles);
52 
53  // Identifier is not zero
54  EXPECT_FALSE(item.identifier().empty());
55 }
std::vector< int > roles() const
std::string identifier() const
Returns unique identifier.
Definition: sessionitem.cpp:87
SessionItem * parent() const
Returns parent item. Will return nullptr if item doesn't have a parent.
SessionModel * model() const
Returns the model to which given item belongs to.
int childrenCount() const
Returns total number of children in all tags.
T data(int role=ItemDataRole::DATA) const
Returns data of given type T for given role.
Definition: sessionitem.h:148
std::vector< SessionItem * > children() const
Returns vector of children formed from all chidlren from all tags.
SessionItemData * itemData()
Returns pointer to item's data container (non-const version).
virtual std::string displayName() const
Returns display name.
Definition: sessionitem.cpp:94
model_type modelType() const
Returns item's model type.
Definition: sessionitem.cpp:80
const model_type BaseType
Definition: mvvm_types.h:45

References ModelView::Constants::BaseType, ModelView::SessionItem::children(), ModelView::SessionItem::childrenCount(), ModelView::ItemDataRole::DATA, ModelView::SessionItem::data(), ModelView::ItemDataRole::DISPLAY, ModelView::SessionItem::displayName(), ModelView::ItemDataRole::IDENTIFIER, ModelView::SessionItem::identifier(), ModelView::SessionItem::itemData(), ModelView::SessionItem::model(), ModelView::SessionItem::modelType(), ModelView::SessionItem::parent(), and ModelView::SessionItemData::roles().

Here is the call graph for this function:

◆ TEST_F() [7/29]

TEST_F ( SessionItemTest  ,
insertChildren   
)

Simple children insert.

Definition at line 288 of file sessionitem.test.cpp.

289 {
290  auto parent = std::make_unique<SessionItem>();
291  parent->registerTag(TagInfo::universalTag("defaultTag"), /*set_as_default*/ true);
292 
293  auto child1 = new SessionItem;
294  auto child2 = new SessionItem;
295  auto child3 = new SessionItem;
296  auto child4 = new SessionItem;
297 
298  // inserting two items
299  parent->insertItem(child1, TagRow::append());
300  parent->insertItem(child2, TagRow::append());
301  EXPECT_EQ(Utils::IndexOfChild(parent.get(), child1), 0);
302  EXPECT_EQ(Utils::IndexOfChild(parent.get(), child2), 1);
303  EXPECT_EQ(parent->getItem("", 0), child1);
304  EXPECT_EQ(parent->getItem("", 1), child2);
305  std::vector<SessionItem*> expected = {child1, child2};
306  EXPECT_EQ(parent->children(), expected);
307 
308  // inserting third item between two others
309  parent->insertItem(child3, {"", 1});
310  expected = {child1, child3, child2};
311  EXPECT_EQ(parent->children(), expected);
312  EXPECT_EQ(Utils::IndexOfChild(parent.get(), child1), 0);
313  EXPECT_EQ(Utils::IndexOfChild(parent.get(), child2), 2);
314  EXPECT_EQ(Utils::IndexOfChild(parent.get(), child3), 1);
315  EXPECT_EQ(parent->getItem("", 0), child1);
316  EXPECT_EQ(parent->getItem("", 1), child3);
317  EXPECT_EQ(parent->getItem("", 2), child2);
318  EXPECT_EQ(parent->getItem("", 3), nullptr);
319 
320  // inserting forth item using index equal to number of items
321  parent->insertItem(child4, {"", parent->childrenCount()});
322 
323  // checking parents
324  EXPECT_EQ(child1->parent(), parent.get());
325  EXPECT_EQ(child2->parent(), parent.get());
326  EXPECT_EQ(child3->parent(), parent.get());
327  EXPECT_EQ(child4->parent(), parent.get());
328 
329  // attempt to insert same item twice
330  EXPECT_THROW(parent->insertItem(child2, TagRow::append()), std::runtime_error);
331 
332  // attempt to insert item using out of scope index
333  auto child5 = std::make_unique<SessionItem>();
334  EXPECT_FALSE(parent->insertItem(child5.get(), {"", parent->childrenCount() + 1}));
335 }
bool insertItem(SessionItem *item, const TagRow &tagrow)
Insert item into given tag under the given row.
MVVM_MODEL_EXPORT int IndexOfChild(const SessionItem *parent, const SessionItem *child)
Returns index in children array corresponding to given child.
Definition: itemutils.cpp:81

References ModelView::TagRow::append(), ModelView::Utils::IndexOfChild(), ModelView::SessionItem::insertItem(), and ModelView::TagInfo::universalTag().

Here is the call graph for this function:

◆ TEST_F() [8/29]

TEST_F ( SessionItemTest  ,
insertItem   
)

Simple child insert.

Definition at line 261 of file sessionitem.test.cpp.

262 {
263  auto parent = std::make_unique<SessionItem>();
264  parent->registerTag(TagInfo::universalTag("defaultTag"), /*set_as_default*/ true);
265 
266  std::unique_ptr<SessionItem> child(new SessionItem);
267 
268  // empty parent
269  EXPECT_EQ(parent->childrenCount(), 0);
270  EXPECT_EQ(Utils::IndexOfChild(parent.get(), nullptr), -1);
271  EXPECT_EQ(Utils::IndexOfChild(parent.get(), child.get()), -1);
272  EXPECT_EQ(parent->getItem("", 0), nullptr);
273  EXPECT_EQ(parent->getItem("", -1), nullptr);
274  EXPECT_EQ(parent->getItem("", 10), nullptr);
275 
276  // inserting child
277  auto p_child = child.release();
278  parent->insertItem(p_child, {"", 0});
279  EXPECT_EQ(parent->childrenCount(), 1);
280  EXPECT_EQ(Utils::IndexOfChild(parent.get(), p_child), 0);
281  EXPECT_EQ(parent->children()[0], p_child);
282  EXPECT_EQ(parent->getItem("", 0), p_child);
283  EXPECT_EQ(p_child->parent(), parent.get());
284 }

References ModelView::Utils::IndexOfChild(), and ModelView::TagInfo::universalTag().

Here is the call graph for this function:

◆ TEST_F() [9/29]

TEST_F ( SessionItemTest  ,
itemsInTag   
)

Definition at line 702 of file sessionitem.test.cpp.

703 {
704  const std::string tag1 = "tag1";
705  const std::string tag2 = "tag2";
706 
707  // creating parent with one tag
708  auto parent = std::make_unique<SessionItem>();
709  parent->registerTag(TagInfo::universalTag(tag1));
710  parent->registerTag(TagInfo::universalTag(tag2));
711 
712  // inserting two children
713  auto child_t1_a = new SessionItem;
714  auto child_t2_a = new SessionItem;
715  auto child_t2_b = new SessionItem;
716  parent->insertItem(child_t1_a, {tag1, -1});
717  parent->insertItem(child_t2_a, {tag2, -1});
718  parent->insertItem(child_t2_b, {tag2, -1});
719 
720  EXPECT_EQ(parent->itemCount(tag1), 1);
721  EXPECT_EQ(parent->itemCount(tag2), 2);
722 }

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

Here is the call graph for this function:

◆ TEST_F() [10/29]

TEST_F ( SessionItemTest  ,
modelType   
)

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

58 {
59  SessionItem item2("Layer");
60  EXPECT_EQ(item2.modelType(), "Layer");
61 }

References ModelView::SessionItem::modelType().

Here is the call graph for this function:

◆ TEST_F() [11/29]

TEST_F ( SessionItemTest  ,
registerDefaultTag   
)

Registering tag and setting it as default.

Definition at line 252 of file sessionitem.test.cpp.

253 {
254  SessionItem item;
255  item.registerTag(TagInfo::universalTag("tagname"), /*set_as_default*/ true);
256  EXPECT_EQ(item.itemTags()->defaultTag(), "tagname");
257 }
void registerTag(const TagInfo &tagInfo, bool set_as_default=false)
Registers tag to hold items under given name.

References ModelView::SessionItemTags::defaultTag(), ModelView::SessionItem::itemTags(), ModelView::SessionItem::registerTag(), and ModelView::TagInfo::universalTag().

Here is the call graph for this function:

◆ TEST_F() [12/29]

TEST_F ( SessionItemTest  ,
registerItem   
)

Item registration in a pool.

Definition at line 205 of file sessionitem.test.cpp.

206 {
207  auto item = std::make_unique<SessionItem>();
208  auto item_id = item->identifier();
209  EXPECT_EQ(item->itemData()->roles().size(), 2u);
210 
211  std::shared_ptr<ItemPool> pool;
212 
213  // creating pool
214  pool.reset(new ItemPool);
215  pool->register_item(item.get(), item_id);
216  // registration shouldn't change item identifier
217  EXPECT_EQ(item->identifier(), item_id);
218 
219  // registration key should coincide with item identifier
220  auto key = pool->key_for_item(item.get());
221  std::vector<int> expected_roles = {ItemDataRole::IDENTIFIER, ItemDataRole::DISPLAY};
222  EXPECT_EQ(item->itemData()->roles(), expected_roles);
223  EXPECT_EQ(item_id, key);
224 }
Provides registration of SessionItem pointers and their unique identifiers in global memory pool.
Definition: itempool.h:29

References ModelView::ItemDataRole::DISPLAY, and ModelView::ItemDataRole::IDENTIFIER.

◆ TEST_F() [13/29]

TEST_F ( SessionItemTest  ,
registerTag   
)

Registering tags.

Definition at line 237 of file sessionitem.test.cpp.

238 {
239  SessionItem item;
240  item.registerTag(TagInfo::universalTag("tagname"));
241  EXPECT_TRUE(Utils::HasTag(item, "tagname"));
242 
243  // registering of tag with same name forbidden
244  EXPECT_THROW(item.registerTag(TagInfo::universalTag("tagname")), std::runtime_error);
245 
246  // registering empty tag is forbidden
247  EXPECT_THROW(item.registerTag(TagInfo::universalTag("")), std::runtime_error);
248 }

References ModelView::Utils::HasTag(), ModelView::SessionItem::registerTag(), and ModelView::TagInfo::universalTag().

Here is the call graph for this function:

◆ TEST_F() [14/29]

TEST_F ( SessionItemTest  ,
setBoolData   
)

Definition at line 143 of file sessionitem.test.cpp.

144 {
145  SessionItem item;
146  const bool expected_true = true;
147  EXPECT_TRUE(item.setData(expected_true));
148  EXPECT_EQ(item.data<bool>(), expected_true);
149  const bool expected_false = false;
150  EXPECT_TRUE(item.setData(expected_false));
151  EXPECT_EQ(item.data<bool>(), expected_false);
152 }

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

Here is the call graph for this function:

◆ TEST_F() [15/29]

TEST_F ( SessionItemTest  ,
setData   
)

Validating ::setData and appearance of roles.

Definition at line 65 of file sessionitem.test.cpp.

66 {
67  SessionItem item;
68  const int role = ItemDataRole::DATA;
69 
70  EXPECT_FALSE(item.data<QVariant>(role).isValid());
71 
72  QVariant expected(42.0);
73  EXPECT_TRUE(item.setData(expected, role));
74 
75  std::vector<int> expected_roles = {ItemDataRole::IDENTIFIER, ItemDataRole::DISPLAY,
77  EXPECT_EQ(item.itemData()->roles(), expected_roles);
78  EXPECT_EQ(item.data<QVariant>(role), expected);
79 
80  // setting another value
81  EXPECT_TRUE(item.setData(43.0, role));
82  EXPECT_EQ(item.itemData()->roles(), expected_roles);
83  EXPECT_EQ(item.data<QVariant>(role), QVariant::fromValue(43.0));
84 
85  // setting same value
86  EXPECT_FALSE(item.setData(43.0, role));
87  EXPECT_EQ(item.itemData()->roles(), expected_roles);
88  EXPECT_EQ(item.data<QVariant>(role), QVariant::fromValue(43.0));
89 }

References ModelView::ItemDataRole::DATA, ModelView::SessionItem::data(), ModelView::ItemDataRole::DISPLAY, ModelView::ItemDataRole::IDENTIFIER, ModelView::SessionItem::itemData(), ModelView::SessionItemData::roles(), and ModelView::SessionItem::setData().

Here is the call graph for this function:

◆ TEST_F() [16/29]

TEST_F ( SessionItemTest  ,
setDataAndImplicitConversion   
)

Validating ::setData in the context of implicit conversion.

Definition at line 93 of file sessionitem.test.cpp.

94 {
95  {
96  SessionItem item;
97  const int role = ItemDataRole::DATA;
98  EXPECT_TRUE(item.setData(43.0, ItemDataRole::DATA));
99  EXPECT_EQ(item.data<QVariant>(role).typeName(), Constants::double_type_name);
100  }
101 
102  {
103  SessionItem item;
104  const int role = ItemDataRole::DATA;
105  EXPECT_TRUE(item.setData(43, ItemDataRole::DATA));
106  EXPECT_EQ(item.data<QVariant>(role).typeName(), Constants::int_type_name);
107  }
108 }
const std::string double_type_name
const std::string int_type_name

References ModelView::ItemDataRole::DATA, ModelView::SessionItem::data(), ModelView::Constants::double_type_name, ModelView::Constants::int_type_name, and ModelView::SessionItem::setData().

Here is the call graph for this function:

◆ TEST_F() [17/29]

TEST_F ( SessionItemTest  ,
setDoubleData   
)

Definition at line 127 of file sessionitem.test.cpp.

128 {
129  SessionItem item;
130  const double expected = 42.0;
131  EXPECT_TRUE(item.setData(expected));
132  EXPECT_EQ(item.data<double>(), expected);
133 }

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

Here is the call graph for this function:

◆ TEST_F() [18/29]

TEST_F ( SessionItemTest  ,
setIntData   
)

Definition at line 135 of file sessionitem.test.cpp.

136 {
137  SessionItem item;
138  const int expected = 42;
139  EXPECT_TRUE(item.setData(expected));
140  EXPECT_EQ(item.data<int>(), expected);
141 }

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

Here is the call graph for this function:

◆ TEST_F() [19/29]

TEST_F ( SessionItemTest  ,
setStringData   
)

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

155 {
156  SessionItem item;
157  const std::string expected{"abc"};
158  EXPECT_TRUE(item.setData(expected));
159  EXPECT_EQ(item.data<std::string>(), expected);
160 }

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

Here is the call graph for this function:

◆ TEST_F() [20/29]

TEST_F ( SessionItemTest  ,
singleTagAndItems   
)

Insert and take tagged items.

Definition at line 370 of file sessionitem.test.cpp.

371 {
372  const std::string tag1 = "tag1";
373 
374  // creating parent with one tag
375  auto parent = std::make_unique<SessionItem>();
376  parent->registerTag(TagInfo::universalTag(tag1));
377  EXPECT_TRUE(Utils::HasTag(*parent, tag1));
378 
379  // inserting two children
380  auto child1 = new SessionItem;
381  auto child2 = new SessionItem;
382  parent->insertItem(child1, {tag1, -1});
383  parent->insertItem(child2, {tag1, -1});
384 
385  // testing result of insertion via non-tag interface
386  std::vector<SessionItem*> expected = {child1, child2};
387  EXPECT_EQ(parent->children(), expected);
388  EXPECT_EQ(Utils::IndexOfChild(parent.get(), child1), 0);
389  EXPECT_EQ(Utils::IndexOfChild(parent.get(), child2), 1);
390 
391  // testing single item access via tag interface
392  EXPECT_EQ(parent->getItem(tag1), child1);
393  EXPECT_EQ(parent->getItem(tag1, 0), child1);
394  EXPECT_EQ(parent->getItem(tag1, 1), child2);
395  EXPECT_EQ(parent->getItem(tag1, 2), nullptr); // wrong row
396 
397  // access to multiple items via tags interface
398  EXPECT_EQ(parent->getItems(tag1), expected);
399 
400  // removing first item
401  delete parent->takeItem({tag1, 0});
402  EXPECT_EQ(parent->getItems(tag1), std::vector<SessionItem*>() = {child2});
403  // removing second item
404  delete parent->takeItem({tag1, 0});
405  EXPECT_EQ(parent->getItems(tag1), std::vector<SessionItem*>() = {});
406 
407  // removing from already empty container
408  EXPECT_EQ(parent->takeItem({tag1, 0}), nullptr);
409 }

References ModelView::Utils::HasTag(), ModelView::Utils::IndexOfChild(), ModelView::SessionItem::insertItem(), and ModelView::TagInfo::universalTag().

Here is the call graph for this function:

◆ TEST_F() [21/29]

TEST_F ( SessionItemTest  ,
tag   
)

Testing method ::tag.

Definition at line 539 of file sessionitem.test.cpp.

540 {
541  const std::string tag1 = "tag1";
542  const std::string tag2 = "tag2";
543 
544  // creating parent with one tag
545  auto parent = std::make_unique<SessionItem>();
546  parent->registerTag(TagInfo::universalTag(tag1));
547  parent->registerTag(TagInfo::universalTag(tag2));
548 
549  // inserting two children
550  auto child_t1_a = new SessionItem;
551  auto child_t1_b = new SessionItem;
552  auto child_t2_a = new SessionItem;
553  auto child_t2_b = new SessionItem;
554  auto child_t2_c = new SessionItem;
555  parent->insertItem(child_t2_a, {tag2, -1});
556  parent->insertItem(child_t2_c, {tag2, -1});
557  parent->insertItem(child_t1_a, {tag1, -1});
558  parent->insertItem(child_t1_b, {tag1, -1});
559  parent->insertItem(child_t2_b, {tag2, 1}); // between child_t2_a and child_t2_c
560 
561  EXPECT_EQ(child_t1_a->tagRow().tag, "tag1");
562  EXPECT_EQ(child_t1_b->tagRow().tag, "tag1");
563  EXPECT_EQ(child_t2_a->tagRow().tag, "tag2");
564  EXPECT_EQ(child_t2_b->tagRow().tag, "tag2");
565  EXPECT_EQ(child_t2_c->tagRow().tag, "tag2");
566 
567  SessionItem parentless_item;
568  EXPECT_EQ(parentless_item.tagRow().tag, "");
569 }
TagRow tagRow() const
Returns TagRow of this item under which it is accessible through its parent.
std::string tag
Definition: tagrow.h:27

References ModelView::SessionItem::insertItem(), ModelView::TagRow::tag, ModelView::SessionItem::tagRow(), and ModelView::TagInfo::universalTag().

Here is the call graph for this function:

◆ TEST_F() [22/29]

TEST_F ( SessionItemTest  ,
tagModelTypes   
)

Inserting and removing items when tag has limits.

Definition at line 504 of file sessionitem.test.cpp.

505 {
506  const std::string tag1 = "tag1";
507  const std::string tag2 = "tag2";
508  const std::string modelType1 = "ModelType1";
509  const std::string modelType2 = "ModelType2";
510  const std::string modelType3 = "ModelType3";
511  const std::string modelType4 = "ModelType4";
512 
513  auto parent = std::make_unique<SessionItem>();
514  parent->registerTag(
515  TagInfo(tag1, 0, -1, std::vector<std::string>() = {modelType1, modelType2}));
516  parent->registerTag(TagInfo(tag2, 0, -1, std::vector<std::string>() = {modelType3}));
517 
518  auto item1 = new SessionItem(modelType1);
519  auto item2 = new SessionItem(modelType2);
520  auto item3 = new SessionItem(modelType3);
521 
522  // attempt to add item not intended for tag
523  EXPECT_FALSE(parent->insertItem(item1, {tag2, -1}));
524  EXPECT_FALSE(parent->insertItem(item3, {tag1, -1}));
525 
526  // normal insert to appropriate tag
527  parent->insertItem(item3, {tag2, -1});
528  parent->insertItem(item1, {tag1, -1});
529  parent->insertItem(item2, {tag1, -1});
530 
531  std::vector<SessionItem*> expected = {item1, item2};
532  EXPECT_EQ(parent->getItems(tag1), expected);
533  expected = {item3};
534  EXPECT_EQ(parent->getItems(tag2), expected);
535 }
Holds info about single tag for SessionItem.
Definition: taginfo.h:28

◆ TEST_F() [23/29]

TEST_F ( SessionItemTest  ,
tagRow   
)

Checks row of item in its tag.

Definition at line 573 of file sessionitem.test.cpp.

574 {
575  const std::string tag1 = "tag1";
576  const std::string tag2 = "tag2";
577 
578  // creating parent with one tag
579  auto parent = std::make_unique<SessionItem>();
580  parent->registerTag(TagInfo::universalTag(tag1));
581  parent->registerTag(TagInfo::universalTag(tag2));
582 
583  // inserting two children
584  auto child_t1_a = new SessionItem;
585  auto child_t1_b = new SessionItem;
586  auto child_t2_a = new SessionItem;
587  auto child_t2_b = new SessionItem;
588  auto child_t2_c = new SessionItem;
589  parent->insertItem(child_t2_a, {tag2, -1}); // 0
590  parent->insertItem(child_t2_c, {tag2, -1}); // 2
591  parent->insertItem(child_t1_a, {tag1, -1}); // 0
592  parent->insertItem(child_t1_b, {tag1, -1}); // 1
593  parent->insertItem(child_t2_b, {tag2, 1}); // 1 between child_t2_a and child_t2_c
594 
595  EXPECT_EQ(child_t1_a->tagRow().row, 0);
596  EXPECT_EQ(child_t1_b->tagRow().row, 1);
597  EXPECT_EQ(child_t2_a->tagRow().row, 0);
598  EXPECT_EQ(child_t2_b->tagRow().row, 1);
599  EXPECT_EQ(child_t2_c->tagRow().row, 2);
600 
601  EXPECT_EQ(child_t1_a->tagRow().tag, "tag1");
602  EXPECT_EQ(child_t1_b->tagRow().tag, "tag1");
603  EXPECT_EQ(child_t2_a->tagRow().tag, "tag2");
604  EXPECT_EQ(child_t2_b->tagRow().tag, "tag2");
605  EXPECT_EQ(child_t2_c->tagRow().tag, "tag2");
606 }

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

Here is the call graph for this function:

◆ TEST_F() [24/29]

TEST_F ( SessionItemTest  ,
tagRowOfItem   
)

Checks row of item in its tag.

Definition at line 610 of file sessionitem.test.cpp.

611 {
612  const std::string tag1 = "tag1";
613  const std::string tag2 = "tag2";
614 
615  // creating parent with one tag
616  auto parent = std::make_unique<SessionItem>();
617  parent->registerTag(TagInfo::universalTag(tag1));
618  parent->registerTag(TagInfo::universalTag(tag2));
619 
620  // inserting two children
621  auto child_t1_a = new SessionItem;
622  auto child_t1_b = new SessionItem;
623  auto child_t2_a = new SessionItem;
624  auto child_t2_b = new SessionItem;
625  auto child_t2_c = new SessionItem;
626  parent->insertItem(child_t2_a, {tag2, -1}); // 0
627  parent->insertItem(child_t2_c, {tag2, -1}); // 2
628  parent->insertItem(child_t1_a, {tag1, -1}); // 0
629  parent->insertItem(child_t1_b, {tag1, -1}); // 1
630  parent->insertItem(child_t2_b, {tag2, 1}); // 1 between child_t2_a and child_t2_c
631 
632  EXPECT_EQ(parent->tagRowOfItem(child_t1_a).row, 0);
633  EXPECT_EQ(parent->tagRowOfItem(child_t1_b).row, 1);
634  EXPECT_EQ(parent->tagRowOfItem(child_t2_a).row, 0);
635  EXPECT_EQ(parent->tagRowOfItem(child_t2_b).row, 1);
636  EXPECT_EQ(parent->tagRowOfItem(child_t2_c).row, 2);
637 
638  EXPECT_EQ(parent->tagRowOfItem(child_t1_a).tag, "tag1");
639  EXPECT_EQ(parent->tagRowOfItem(child_t1_b).tag, "tag1");
640  EXPECT_EQ(parent->tagRowOfItem(child_t2_a).tag, "tag2");
641  EXPECT_EQ(parent->tagRowOfItem(child_t2_b).tag, "tag2");
642  EXPECT_EQ(parent->tagRowOfItem(child_t2_c).tag, "tag2");
643 }

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

Here is the call graph for this function:

◆ TEST_F() [25/29]

TEST_F ( SessionItemTest  ,
tagWithLimits   
)

Inserting and removing items when tag has limits.

Definition at line 471 of file sessionitem.test.cpp.

472 {
473  const std::string tag1 = "tag1";
474  const int maxItems = 3;
475  auto parent = std::make_unique<SessionItem>();
476  parent->registerTag(TagInfo(tag1, 0, maxItems, std::vector<std::string>() = {}));
477 
478  // placing maximu allowed number of items
479  std::vector<SessionItem*> expected;
480  for (int i = 0; i < maxItems; ++i) {
481  auto child = new SessionItem;
482  expected.push_back(child);
483  EXPECT_TRUE(parent->insertItem(child, {tag1, -1}));
484  }
485  EXPECT_EQ(parent->getItems(tag1), expected);
486 
487  // no room for extra item
488  auto extra = new SessionItem;
489  EXPECT_FALSE(parent->insertItem(extra, {tag1, -1}));
490 
491  // removing first element
492  delete parent->takeItem({tag1, 0});
493  expected.erase(expected.begin());
494  EXPECT_EQ(parent->getItems(tag1), expected);
495 
496  // adding extra item
497  parent->insertItem(extra, {tag1, -1});
498  expected.push_back(extra);
499  EXPECT_EQ(parent->getItems(tag1), expected);
500 }

◆ TEST_F() [26/29]

TEST_F ( SessionItemTest  ,
takeItem   
)

Removing (taking) item from parent.

Definition at line 339 of file sessionitem.test.cpp.

340 {
341  auto parent = std::make_unique<SessionItem>();
342  parent->registerTag(TagInfo::universalTag("defaultTag"), /*set_as_default*/ true);
343 
344  auto child1 = new SessionItem;
345  auto child2 = new SessionItem;
346  auto child3 = new SessionItem;
347 
348  // inserting items
349  parent->insertItem(child1, TagRow::append());
350  parent->insertItem(child2, TagRow::append());
351  parent->insertItem(child3, TagRow::append());
352 
353  EXPECT_EQ(parent->childrenCount(), 3);
354 
355  // taking non-existing rows
356  EXPECT_EQ(parent->takeItem({"", -1}), nullptr);
357  EXPECT_EQ(parent->takeItem({"", parent->childrenCount()}), nullptr);
358 
359  // taking first row
360  auto taken = parent->takeItem({"", 0});
361  EXPECT_EQ(taken->parent(), nullptr);
362  std::vector<SessionItem*> expected = {child2, child3};
363  EXPECT_EQ(parent->children(), expected);
364 
365  delete taken;
366 }

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

Here is the call graph for this function:

◆ TEST_F() [27/29]

TEST_F ( SessionItemTest  ,
tooltip   
)

Checks item tooltip.

Definition at line 676 of file sessionitem.test.cpp.

677 {
678  SessionItem item("Model");
679 
680  EXPECT_EQ(item.toolTip(), "");
681  EXPECT_FALSE(item.hasData(ItemDataRole::TOOLTIP));
682 
683  EXPECT_EQ(item.setToolTip("abc"), &item);
684  EXPECT_TRUE(item.hasData(ItemDataRole::TOOLTIP));
685  EXPECT_EQ(item.toolTip(), "abc");
686 }

References ModelView::SessionItem::hasData(), ModelView::SessionItem::setToolTip(), ModelView::ItemDataRole::TOOLTIP, and ModelView::SessionItem::toolTip().

Here is the call graph for this function:

◆ TEST_F() [28/29]

TEST_F ( SessionItemTest  ,
twoTagsAndItems   
)

Insert and take tagged items when two tags are present.

Definition at line 413 of file sessionitem.test.cpp.

414 {
415  const std::string tag1 = "tag1";
416  const std::string tag2 = "tag2";
417 
418  // creating parent with one tag
419  auto parent = std::make_unique<SessionItem>();
420  parent->registerTag(TagInfo::universalTag(tag1));
421  parent->registerTag(TagInfo::universalTag(tag2));
422  EXPECT_TRUE(Utils::HasTag(*parent, tag1));
423  EXPECT_TRUE(Utils::HasTag(*parent, tag2));
424 
425  // inserting two children
426  auto child_t1_a = new SessionItem;
427  auto child_t1_b = new SessionItem;
428  auto child_t2_a = new SessionItem;
429  auto child_t2_b = new SessionItem;
430  auto child_t2_c = new SessionItem;
431  parent->insertItem(child_t2_a, {tag2, -1});
432  parent->insertItem(child_t2_c, {tag2, -1});
433 
434  parent->insertItem(child_t1_a, {tag1, -1});
435  parent->insertItem(child_t1_b, {tag1, -1});
436 
437  parent->insertItem(child_t2_b, {tag2, 1}); // between child_t2_a and child_t2_c
438 
439  // testing item access via non-tag interface
440  std::vector<SessionItem*> expected = {child_t1_a, child_t1_b, child_t2_a, child_t2_b,
441  child_t2_c};
442  EXPECT_EQ(parent->children(), expected);
443  EXPECT_EQ(Utils::IndexOfChild(parent.get(), child_t1_a), 0);
444  EXPECT_EQ(Utils::IndexOfChild(parent.get(), child_t2_c), 4);
445 
446  // testing single item access via tag interface
447  EXPECT_EQ(parent->getItem(tag1), child_t1_a);
448  EXPECT_EQ(parent->getItem(tag1, 0), child_t1_a);
449  EXPECT_EQ(parent->getItem(tag1, 1), child_t1_b);
450  EXPECT_EQ(parent->getItem(tag2, 0), child_t2_a);
451  EXPECT_EQ(parent->getItem(tag2, 1), child_t2_b);
452  EXPECT_EQ(parent->getItem(tag2, 2), child_t2_c);
453  EXPECT_EQ(parent->getItem(tag2, 3), nullptr); // no items with such row
454 
455  // access to multiple items via tags interface
456  expected = {child_t1_a, child_t1_b};
457  EXPECT_EQ(parent->getItems(tag1), expected);
458  expected = {child_t2_a, child_t2_b, child_t2_c};
459  EXPECT_EQ(parent->getItems(tag2), expected);
460 
461  // removing item from the middle of tag2
462  delete parent->takeItem({tag2, 1});
463  expected = {child_t1_a, child_t1_b};
464  EXPECT_EQ(parent->getItems(tag1), expected);
465  expected = {child_t2_a, child_t2_c};
466  EXPECT_EQ(parent->getItems(tag2), expected);
467 }

References ModelView::Utils::HasTag(), ModelView::Utils::IndexOfChild(), ModelView::SessionItem::insertItem(), and ModelView::TagInfo::universalTag().

Here is the call graph for this function:

◆ TEST_F() [29/29]

TEST_F ( SessionItemTest  ,
variantMismatch   
)

Attempt to set the different Variant to already existing role.

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

182 {
183  SessionItem item;
184  const int role = ItemDataRole::DATA;
185  QVariant expected(42.0);
186 
187  // setting data for the first time
188  EXPECT_TRUE(item.setData(expected, role));
189 
190  std::vector<int> expected_roles = {ItemDataRole::IDENTIFIER, ItemDataRole::DISPLAY,
192  EXPECT_EQ(item.itemData()->roles(), expected_roles);
193  EXPECT_EQ(item.data<QVariant>(role), expected);
194 
195  // attempt to rewrite variant with another type
196  EXPECT_THROW(item.setData(std::string("abc"), role), std::runtime_error);
197 
198  // removing value by passing invalid variant
199  EXPECT_NO_THROW(item.setData(QVariant(), role));
200  EXPECT_EQ(item.itemData()->roles().size(), 2);
201 }

References ModelView::ItemDataRole::DATA, ModelView::SessionItem::data(), ModelView::ItemDataRole::DISPLAY, ModelView::ItemDataRole::IDENTIFIER, ModelView::SessionItem::itemData(), ModelView::SessionItemData::roles(), and ModelView::SessionItem::setData().

Here is the call graph for this function: