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

Implements class CLASS? More...

Include dependency graph for projectmanager.test.cpp:

Go to the source code of this file.

Classes

class  ProjectManagerTest
 Tests for ProjectManager class. More...
 

Functions

 TEST_F (ProjectManagerTest, callback)
 
 TEST_F (ProjectManagerTest, initialState)
 Initial state of ProjectManager. Project created, and not-saved. More...
 
 TEST_F (ProjectManagerTest, titledModifiedSave)
 Saving of new project. More...
 
 TEST_F (ProjectManagerTest, titledUnmodifiedNew)
 Creating new project. More...
 
 TEST_F (ProjectManagerTest, untitledEmptyNew)
 Creating new project. More...
 
 TEST_F (ProjectManagerTest, untitledEmptySave)
 Saving of new project. More...
 
 TEST_F (ProjectManagerTest, untitledEmptySaveAs)
 Saving of new project. More...
 
 TEST_F (ProjectManagerTest, untitledModifiedNew)
 Creating new project. More...
 
 TEST_F (ProjectManagerTest, untitledModifiedSave)
 Saving of new project. More...
 
 TEST_F (ProjectManagerTest, untitledModifiedSaveAs)
 Saving of new project. 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 projectmanager.test.cpp.

Function Documentation

◆ TEST_F() [1/10]

TEST_F ( ProjectManagerTest  ,
callback   
)

Definition at line 223 of file projectmanager.test.cpp.

224 {
225  int project_modified_count{0};
226 
227  auto context = createContext();
228  context.m_modified_callback = [&project_modified_count]() { ++project_modified_count; };
229 
230  ProjectManager manager(context);
231 
232  EXPECT_EQ(project_modified_count, 0);
233 
234  // saving the project
235  const auto project_dir = createEmptyDir("Project_callback");
236  EXPECT_TRUE(manager.saveProjectAs(project_dir));
237  EXPECT_EQ(manager.currentProjectDir(), project_dir);
238  EXPECT_EQ(project_modified_count, 0);
239 
240  // modifying the model
241  sample_model->insertItem<PropertyItem>();
242  EXPECT_EQ(project_modified_count, 1);
243  EXPECT_TRUE(manager.isModified());
244 
245  // modifying the model second time
246  sample_model->insertItem<PropertyItem>();
247  EXPECT_EQ(project_modified_count, 1); // do not sum up
248  EXPECT_TRUE(manager.isModified());
249 
250  EXPECT_TRUE(manager.saveCurrentProject());
251  EXPECT_FALSE(manager.isModified());
252  EXPECT_EQ(project_modified_count, 1);
253 }
Responsible for handling new/save/save-as/close Project logic, where the Project represents a collect...
Item to carry concrete editable entity (e.g.
Definition: propertyitem.h:27

References ModelView::ProjectManager::currentProjectDir(), ModelView::ProjectManager::isModified(), ModelView::ProjectManager::saveCurrentProject(), and ModelView::ProjectManager::saveProjectAs().

Here is the call graph for this function:

◆ TEST_F() [2/10]

TEST_F ( ProjectManagerTest  ,
initialState   
)

Initial state of ProjectManager. Project created, and not-saved.

Definition at line 59 of file projectmanager.test.cpp.

60 {
61  ProjectManager manager(createContext());
62  EXPECT_TRUE(manager.currentProjectDir().empty());
63  EXPECT_FALSE(manager.isModified());
64 }

References ModelView::ProjectManager::currentProjectDir(), and ModelView::ProjectManager::isModified().

Here is the call graph for this function:

◆ TEST_F() [3/10]

TEST_F ( ProjectManagerTest  ,
titledModifiedSave   
)

Saving of new project.

Use titled+modified project as a starting point. Should succeed.

Definition at line 204 of file projectmanager.test.cpp.

205 {
206  ProjectManager manager(createContext());
207 
208  const auto project_dir = createEmptyDir("Project_titledModifiedSave");
209  EXPECT_TRUE(manager.saveProjectAs(project_dir));
210  EXPECT_EQ(manager.currentProjectDir(), project_dir);
211 
212  // modifying the model
213  sample_model->insertItem<PropertyItem>();
214 
215  EXPECT_TRUE(manager.saveCurrentProject());
216  EXPECT_FALSE(manager.isModified());
217 }

References ModelView::ProjectManager::currentProjectDir(), ModelView::ProjectManager::isModified(), ModelView::ProjectManager::saveCurrentProject(), and ModelView::ProjectManager::saveProjectAs().

Here is the call graph for this function:

◆ TEST_F() [4/10]

TEST_F ( ProjectManagerTest  ,
titledUnmodifiedNew   
)

Creating new project.

Use titled+unmodified project as a starting point. Should succeed, since old empty project doesn't need to be saved.

Definition at line 178 of file projectmanager.test.cpp.

179 {
180  ProjectManager manager(createContext());
181 
182  const auto project_dir = createEmptyDir("Project_titledUnmodifiedNew");
183  EXPECT_TRUE(manager.saveProjectAs(project_dir));
184  EXPECT_EQ(manager.currentProjectDir(), project_dir);
185 
186  const auto project_dir2 = createEmptyDir("Project_titledUnmodifiedNew2");
187  EXPECT_TRUE(manager.createNewProject(project_dir2));
188 
189  EXPECT_EQ(manager.currentProjectDir(), project_dir2);
190  EXPECT_FALSE(manager.isModified());
191 
192  // project directory should contain a json file with the model
193  auto model_json = Utils::join(project_dir2, samplemodel_name + ".json");
194  EXPECT_TRUE(Utils::exists(model_json));
195 }
bool exists(const QString &fileName)
Returns true if file exists.
std::string join(const std::vector< std::string > &joinable, const std::string &joint)
Returns string obtain by joining vector elements.
Definition: StringUtils.cpp:71

References ModelView::ProjectManager::createNewProject(), ModelView::ProjectManager::currentProjectDir(), ModelView::Utils::exists(), ModelView::ProjectManager::isModified(), ModelView::Utils::join(), and ModelView::ProjectManager::saveProjectAs().

Here is the call graph for this function:

◆ TEST_F() [5/10]

TEST_F ( ProjectManagerTest  ,
untitledEmptyNew   
)

Creating new project.

Use untitled+empty project as a starting point. Should succeed, since old empty project doesn't need to be saved.

Definition at line 73 of file projectmanager.test.cpp.

74 {
75  ProjectManager manager(createContext());
76 
77  const auto project_dir = createEmptyDir("Project_untitledEmptyNew");
78  EXPECT_TRUE(manager.createNewProject(project_dir));
79 
80  EXPECT_EQ(manager.currentProjectDir(), project_dir);
81  EXPECT_FALSE(manager.isModified());
82 
83  // project directory should contain a json file with the model
84  auto model_json = Utils::join(project_dir, samplemodel_name + ".json");
85  EXPECT_TRUE(Utils::exists(model_json));
86 }

References ModelView::ProjectManager::createNewProject(), ModelView::ProjectManager::currentProjectDir(), ModelView::Utils::exists(), ModelView::ProjectManager::isModified(), and ModelView::Utils::join().

Here is the call graph for this function:

◆ TEST_F() [6/10]

TEST_F ( ProjectManagerTest  ,
untitledEmptySave   
)

Saving of new project.

Use untitled+empty project as a starting point. Should fail since project directory is not defined.

Definition at line 91 of file projectmanager.test.cpp.

92 {
93  ProjectManager manager(createContext());
94  EXPECT_FALSE(manager.saveCurrentProject());
95  EXPECT_FALSE(manager.isModified());
96 }

References ModelView::ProjectManager::isModified(), and ModelView::ProjectManager::saveCurrentProject().

Here is the call graph for this function:

◆ TEST_F() [7/10]

TEST_F ( ProjectManagerTest  ,
untitledEmptySaveAs   
)

Saving of new project.

Use untitled+empty project as a starting point. Should be saved, file sould appear on disk.

Definition at line 101 of file projectmanager.test.cpp.

102 {
103  ProjectManager manager(createContext());
104 
105  const auto project_dir = createEmptyDir("Project_untitledEmptySaveAs");
106  EXPECT_TRUE(manager.saveProjectAs(project_dir));
107  EXPECT_FALSE(manager.isModified());
108 
109  // project directory should contain a json file with the model
110  auto model_json = Utils::join(project_dir, samplemodel_name + ".json");
111  EXPECT_TRUE(Utils::exists(model_json));
112 }

References ModelView::Utils::exists(), ModelView::ProjectManager::isModified(), ModelView::Utils::join(), and ModelView::ProjectManager::saveProjectAs().

Here is the call graph for this function:

◆ TEST_F() [8/10]

TEST_F ( ProjectManagerTest  ,
untitledModifiedNew   
)

Creating new project.

Use untitled+modified project as a starting point. Should fail, since modified old project will prevent creation of the new one.

Definition at line 121 of file projectmanager.test.cpp.

122 {
123  ProjectManager manager(createContext());
124 
125  // modifying the model
126  sample_model->insertItem<PropertyItem>();
127 
128  EXPECT_TRUE(manager.isModified());
129 
130  const auto project_dir = createEmptyDir("Project_untitledModifiedNew");
131  EXPECT_FALSE(manager.createNewProject(project_dir));
132 
133  EXPECT_TRUE(manager.currentProjectDir().empty());
134  EXPECT_TRUE(manager.isModified());
135 
136  // project directory should be empty
137  auto model_json = Utils::join(project_dir, samplemodel_name + ".json");
138  EXPECT_FALSE(Utils::exists(model_json));
139 }

References ModelView::ProjectManager::createNewProject(), ModelView::ProjectManager::currentProjectDir(), ModelView::Utils::exists(), ModelView::ProjectManager::isModified(), and ModelView::Utils::join().

Here is the call graph for this function:

◆ TEST_F() [9/10]

TEST_F ( ProjectManagerTest  ,
untitledModifiedSave   
)

Saving of new project.

Use untitled+modified project as a starting point. Should fail since project directory is not defined.

Definition at line 144 of file projectmanager.test.cpp.

145 {
146  ProjectManager manager(createContext());
147  // modifying the model
148  sample_model->insertItem<PropertyItem>();
149 
150  EXPECT_FALSE(manager.saveCurrentProject());
151  EXPECT_TRUE(manager.isModified());
152 }

References ModelView::ProjectManager::isModified(), and ModelView::ProjectManager::saveCurrentProject().

Here is the call graph for this function:

◆ TEST_F() [10/10]

TEST_F ( ProjectManagerTest  ,
untitledModifiedSaveAs   
)

Saving of new project.

Use untitled+empty project as a starting point. Should be saved, file sould appear on disk.

Definition at line 157 of file projectmanager.test.cpp.

158 {
159  ProjectManager manager(createContext());
160  sample_model->insertItem<PropertyItem>(); // modifying the model
161 
162  const auto project_dir = createEmptyDir("Project_untitledModifiedSaveAs");
163  EXPECT_TRUE(manager.saveProjectAs(project_dir));
164  EXPECT_FALSE(manager.isModified());
165 
166  // project directory should contain a json file with the model
167  auto model_json = Utils::join(project_dir, samplemodel_name + ".json");
168  EXPECT_TRUE(Utils::exists(model_json));
169 }

References ModelView::Utils::exists(), ModelView::ProjectManager::isModified(), ModelView::Utils::join(), and ModelView::ProjectManager::saveProjectAs().

Here is the call graph for this function: