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

Implements class CLASS? More...

Include dependency graph for itemlistener.test.cpp:

Go to the source code of this file.

Classes

class  ItemListenerTest
 Testing ItemListener. More...
 
class  ItemListenerTest::TestController
 

Functions

 TEST_F (ItemListenerTest, controllerDeletedBeforeItem)
 Checks that controller can be deleted before item. More...
 
 TEST_F (ItemListenerTest, initialState)
 Initial state. More...
 
 TEST_F (ItemListenerTest, itemDeletedBeforeController)
 Check that controller aware of item deletion. More...
 
 TEST_F (ItemListenerTest, unsubscribeScenario)
 Checks unsubscribe scenario. 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 itemlistener.test.cpp.

Function Documentation

◆ TEST_F() [1/4]

TEST_F ( ItemListenerTest  ,
controllerDeletedBeforeItem   
)

Checks that controller can be deleted before item.

Definition at line 99 of file itemlistener.test.cpp.

100 {
101  SessionModel model;
102  auto item = model.insertItem<PropertyItem>();
103 
104  auto controller = std::make_unique<TestController>();
105  controller->setItem(item);
106  EXPECT_EQ(controller->currentItem(), item);
107 
108  controller.reset();
109  item->setData(42.0);
110 }
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
Main class to hold hierarchy of SessionItem objects.
Definition: sessionmodel.h:37
T * insertItem(SessionItem *parent=nullptr, const TagRow &tagrow={})
Inserts item into given parent under given tagrow.
Definition: sessionmodel.h:104

References ModelView::SessionModel::insertItem(), and ModelView::SessionItem::setData().

Here is the call graph for this function:

◆ TEST_F() [2/4]

TEST_F ( ItemListenerTest  ,
initialState   
)

Initial state.

Definition at line 49 of file itemlistener.test.cpp.

50 {
51  TestController controller;
52  EXPECT_EQ(controller.currentItem(), nullptr);
53 }

◆ TEST_F() [3/4]

TEST_F ( ItemListenerTest  ,
itemDeletedBeforeController   
)

Check that controller aware of item deletion.

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

58 {
59  SessionModel model;
60  auto item = model.insertItem<PropertyItem>();
61 
62  auto controller = std::make_unique<TestController>();
63  controller->setItem(item);
64  item->setData(42.0);
65 
66  EXPECT_EQ(controller->currentItem(), item);
67  EXPECT_EQ(controller->ondata_change_call_count, 1);
68 
69  model.removeItem(model.rootItem(), {"", 0});
70  EXPECT_EQ(controller->currentItem(), nullptr);
71 }
SessionItem * rootItem() const
Returns root item of the model.
void removeItem(SessionItem *parent, const TagRow &tagrow)
Removes given row from parent.

References ModelView::SessionModel::insertItem(), ModelView::SessionModel::removeItem(), ModelView::SessionModel::rootItem(), and ModelView::SessionItem::setData().

Here is the call graph for this function:

◆ TEST_F() [4/4]

TEST_F ( ItemListenerTest  ,
unsubscribeScenario   
)

Checks unsubscribe scenario.

Definition at line 75 of file itemlistener.test.cpp.

76 {
77  SessionModel model;
78  auto item = model.insertItem<PropertyItem>();
79 
80  auto controller = std::make_unique<TestController>();
81  controller->setItem(item);
82  item->setData(42.0);
83 
84  EXPECT_EQ(controller->currentItem(), item);
85  EXPECT_EQ(controller->ondata_change_call_count, 1);
86  EXPECT_EQ(controller->on_unsubscribe_call_count, 0);
87 
88  // setting item to nullptr
89  controller->setItem(nullptr);
90  EXPECT_EQ(controller->currentItem(), nullptr);
91  EXPECT_EQ(controller->on_unsubscribe_call_count, 1);
92  // change in data shouldn't lead to update
93  item->setData(45.0);
94  EXPECT_EQ(controller->ondata_change_call_count, 1);
95 }

References ModelView::SessionModel::insertItem(), and ModelView::SessionItem::setData().

Here is the call graph for this function: