BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
projectchangecontroller.test.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // qt-mvvm: Model-view-view-model framework for large GUI applications
4 //
5 //! @file mvvm/tests/testmodel/projectchangecontroller.test.cpp
6 //! @brief Implements class CLASS?
7 //!
8 //! @homepage http://www.bornagainproject.org
9 //! @license GNU General Public License v3 or higher (see COPYING)
10 //! @copyright Forschungszentrum Jülich GmbH 2020
11 //! @authors Gennady Pospelov et al, Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************************************
14 
15 #include "google_test.h"
19 
20 using namespace ModelView;
21 
22 //! Tests for ProjectChangeController class.
23 
24 class ProjectChangeControllerTest : public ::testing::Test {
25 public:
27 };
28 
30 
32 {
33  SessionModel sample_model("SampleModel");
34  SessionModel material_model("MaterialModel");
35  std::vector<SessionModel*> models = {&sample_model, &material_model};
36 
37  ProjectChangedController controller(models);
38  EXPECT_FALSE(controller.hasChanged());
39 }
40 
42 {
43  SessionModel sample_model("SampleModel");
44  SessionModel material_model("MaterialModel");
45  std::vector<SessionModel*> models = {&sample_model, &material_model};
46 
47  ProjectChangedController controller(models);
48 
49  sample_model.insertItem<PropertyItem>();
50  material_model.insertItem<PropertyItem>();
51 
52  EXPECT_TRUE(controller.hasChanged());
53 
54  controller.resetChanged();
55  EXPECT_FALSE(controller.hasChanged());
56 }
57 
59 {
60  int model_changed_count{0};
61 
62  SessionModel sample_model("SampleModel");
63  SessionModel material_model("MaterialModel");
64  std::vector<SessionModel*> models = {&sample_model, &material_model};
65 
66  auto on_model_changed = [&model_changed_count]() { ++model_changed_count; };
67  ProjectChangedController controller(models, on_model_changed);
68 
69  // changing first model
70  sample_model.insertItem<PropertyItem>();
71  EXPECT_TRUE(controller.hasChanged());
72  EXPECT_EQ(model_changed_count, 1);
73 
74  // changing second model
75  material_model.insertItem<PropertyItem>();
76  EXPECT_TRUE(controller.hasChanged());
77  EXPECT_EQ(model_changed_count, 1); // controller reports only once
78 
79  controller.resetChanged();
80  EXPECT_FALSE(controller.hasChanged());
81 }
bool hasChanged() const
Returns true if the change in the models has been registered since the last call of resetChanged.
void resetChanged()
Reset controller to initial state, pretending that no changes has been registered.
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
Tests for ProjectChangeController class.
Defines class CLASS?
materialitems.h Collection of materials to populate MaterialModel.
Defines class CLASS?
TEST_F(ProjectChangeControllerTest, initialState)
Defines class CLASS?
Defines class CLASS?