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

Implements class CLASS? More...

Include dependency graph for modelhaschangedcontroller.test.cpp:

Go to the source code of this file.

Classes

class  ModelHasChangedControllerTest
 Tests for ModelHasChangedController class. More...
 

Functions

 TEST_F (ModelHasChangedControllerTest, callback)
 Tests callback functioning. More...
 
 TEST_F (ModelHasChangedControllerTest, dataChanged)
 Tests if controller sees item data change. More...
 
 TEST_F (ModelHasChangedControllerTest, initialState)
 Tests initial state of the controller. More...
 
 TEST_F (ModelHasChangedControllerTest, insertItem)
 Tests if controller 'sees' item insertion. More...
 
 TEST_F (ModelHasChangedControllerTest, modelReset)
 Tests if controller sees model reset. More...
 
 TEST_F (ModelHasChangedControllerTest, removeItem)
 Tests if controller sees item insertion. More...
 
 TEST_F (ModelHasChangedControllerTest, timeOfLife)
 Tests callback functioning. 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 modelhaschangedcontroller.test.cpp.

Function Documentation

◆ TEST_F() [1/7]

TEST_F ( ModelHasChangedControllerTest  ,
callback   
)

Tests callback functioning.

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

100 {
101  int change_count{0};
102  auto on_change = [&change_count]() { change_count++; };
103 
104  SessionModel model;
105  ModelHasChangedController controller(&model, on_change);
106 
107  model.insertItem<PropertyItem>();
108  EXPECT_TRUE(controller.hasChanged());
109  EXPECT_EQ(change_count, 1);
110 
111  controller.resetChanged();
112  EXPECT_FALSE(controller.hasChanged());
113  EXPECT_EQ(change_count, 1);
114 }
Item to carry concrete editable entity (e.g.
Definition: propertyitem.h:27
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::ModelHasChangedController::hasChanged(), ModelView::SessionModel::insertItem(), and ModelView::ModelHasChangedController::resetChanged().

Here is the call graph for this function:

◆ TEST_F() [2/7]

TEST_F ( ModelHasChangedControllerTest  ,
dataChanged   
)

Tests if controller sees item data change.

Definition at line 71 of file modelhaschangedcontroller.test.cpp.

72 {
73  SessionModel model;
74  auto item = model.insertItem<PropertyItem>();
75 
76  ModelHasChangedController controller(&model);
77  EXPECT_FALSE(controller.hasChanged());
78 
79  item->setData(42.0);
80  EXPECT_TRUE(controller.hasChanged());
81 }

References ModelView::SessionModel::insertItem().

Here is the call graph for this function:

◆ TEST_F() [3/7]

TEST_F ( ModelHasChangedControllerTest  ,
initialState   
)

Tests initial state of the controller.

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

34 {
35  SessionModel model;
36  ModelHasChangedController controller(&model);
37  EXPECT_FALSE(controller.hasChanged());
38 }

References ModelView::ModelHasChangedController::hasChanged().

Here is the call graph for this function:

◆ TEST_F() [4/7]

TEST_F ( ModelHasChangedControllerTest  ,
insertItem   
)

Tests if controller 'sees' item insertion.

Definition at line 42 of file modelhaschangedcontroller.test.cpp.

43 {
44  SessionModel model;
45  ModelHasChangedController controller(&model);
46 
47  model.insertItem<PropertyItem>();
48  EXPECT_TRUE(controller.hasChanged());
49 
50  controller.resetChanged();
51  EXPECT_FALSE(controller.hasChanged());
52 }

References ModelView::ModelHasChangedController::hasChanged(), ModelView::SessionModel::insertItem(), and ModelView::ModelHasChangedController::resetChanged().

Here is the call graph for this function:

◆ TEST_F() [5/7]

TEST_F ( ModelHasChangedControllerTest  ,
modelReset   
)

Tests if controller sees model reset.

Definition at line 85 of file modelhaschangedcontroller.test.cpp.

86 {
87  SessionModel model;
88  model.insertItem<PropertyItem>();
89 
90  ModelHasChangedController controller(&model);
91  EXPECT_FALSE(controller.hasChanged());
92 
93  model.clear();
94  EXPECT_TRUE(controller.hasChanged());
95 }
void clear(std::function< void(SessionItem *)> callback={})
Removes all items from the model.

References ModelView::SessionModel::clear(), and ModelView::SessionModel::insertItem().

Here is the call graph for this function:

◆ TEST_F() [6/7]

TEST_F ( ModelHasChangedControllerTest  ,
removeItem   
)

Tests if controller sees item insertion.

Definition at line 56 of file modelhaschangedcontroller.test.cpp.

57 {
58  SessionModel model;
59  model.insertItem<PropertyItem>();
60 
61  ModelHasChangedController controller(&model);
62  EXPECT_FALSE(controller.hasChanged());
63 
64  model.removeItem(model.rootItem(), {"", 0});
65 
66  EXPECT_TRUE(controller.hasChanged());
67 }
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(), and ModelView::SessionModel::rootItem().

Here is the call graph for this function:

◆ TEST_F() [7/7]

TEST_F ( ModelHasChangedControllerTest  ,
timeOfLife   
)

Tests callback functioning.

Definition at line 118 of file modelhaschangedcontroller.test.cpp.

119 {
120  int change_count{0};
121  auto on_change = [&change_count]() { change_count++; };
122 
123  SessionModel model;
124  auto controller = std::make_unique<ModelHasChangedController>(&model, on_change);
125 
126  // change the model, check controller
127  model.insertItem<PropertyItem>();
128  EXPECT_TRUE(controller->hasChanged());
129  EXPECT_EQ(change_count, 1);
130 
131  // remove controller, change the model
132  controller.reset();
133  model.insertItem<PropertyItem>();
134  EXPECT_EQ(change_count, 1);
135 }

References ModelView::SessionModel::insertItem().

Here is the call graph for this function: