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

Implements class CLASS? More...

Include dependency graph for modellistener.test.cpp:

Go to the source code of this file.

Classes

class  ModelListenerTest
 Tests of ModelListener class. More...
 
class  ModelListenerTest::TestListener
 

Functions

 TEST_F (ModelListenerTest, initialState)
 Initial state. More...
 
 TEST_F (ModelListenerTest, listenerDeletedBeforeTheModel)
 Checks that the listenerr can be deleted before the model. More...
 
 TEST_F (ModelListenerTest, modelDeletedBeforeListener)
 Check that controller aware of item deletion. More...
 
 TEST_F (ModelListenerTest, onDataChange)
 

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

Function Documentation

◆ TEST_F() [1/4]

TEST_F ( ModelListenerTest  ,
initialState   
)

Initial state.

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

42 {
43  SessionModel model;
44  TestListener listener(&model);
45  EXPECT_EQ(listener.model(), &model);
46 }
Main class to hold hierarchy of SessionItem objects.
Definition: sessionmodel.h:37

◆ TEST_F() [2/4]

TEST_F ( ModelListenerTest  ,
listenerDeletedBeforeTheModel   
)

Checks that the listenerr can be deleted before the model.

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

79 {
80  // create model and its listener
81  auto model = std::make_unique<SessionModel>();
82  auto listener = std::make_unique<TestListener>(model.get());
83 
84  // assign to data-changed event
85  int counter{0};
86  auto on_data_change = [&counter](SessionItem*, int) { counter++; };
87  listener->setOnDataChange(on_data_change);
88 
89  // changing the data and checking the listener
90  auto item = model->insertItem<PropertyItem>();
91  item->setData(42.0);
92  EXPECT_EQ(counter, 1);
93 
94  // deleting the listener and trying to change the data again
95  listener.reset();
96  item->setData(43.0);
97  EXPECT_EQ(counter, 1);
98 }
Item to carry concrete editable entity (e.g.
Definition: propertyitem.h:27
The main object representing an editable/displayable/serializable entity.
Definition: sessionitem.h:38
bool setData(const T &value, int role=ItemDataRole::DATA, bool direct=false)
Sets data for a given role.
Definition: sessionitem.h:141

References ModelView::SessionItem::setData().

Here is the call graph for this function:

◆ TEST_F() [3/4]

TEST_F ( ModelListenerTest  ,
modelDeletedBeforeListener   
)

Check that controller aware of item deletion.

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

66 {
67  auto model = std::make_unique<SessionModel>();
68  auto listener = std::make_unique<TestListener>(model.get());
69 
70  EXPECT_EQ(listener->model(), model.get());
71 
72  model.reset();
73  EXPECT_EQ(listener->model(), nullptr);
74 }

◆ TEST_F() [4/4]

TEST_F ( ModelListenerTest  ,
onDataChange   
)

Definition at line 48 of file modellistener.test.cpp.

49 {
50  auto model = std::make_unique<SessionModel>();
51  auto listener = std::make_unique<TestListener>(model.get());
52 
53  int counter{0};
54  auto on_data_change = [&counter](SessionItem*, int) { counter++; };
55  listener->setOnDataChange(on_data_change);
56 
57  auto item = model->insertItem<PropertyItem>();
58  item->setData(42.0);
59 
60  EXPECT_EQ(counter, 1);
61 }

References ModelView::SessionItem::setData().

Here is the call graph for this function: