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

Implements class CLASS? More...

Include dependency graph for projectmanagerdecorator.test.cpp:

Go to the source code of this file.

Classes

class  ProjectManagerDecoratorTest
 Tests for ProjectManager class. More...
 

Functions

 TEST_F (ProjectManagerDecoratorTest, initialState)
 Initial state of ProjectManager. Project created, and not-saved. More...
 
 TEST_F (ProjectManagerDecoratorTest, untitledEmptyCreateNew)
 Starting from new document (without project dir defined). More...
 
 TEST_F (ProjectManagerDecoratorTest, untitledEmptySaveAs)
 Starting from new document (without project dir defined). More...
 
 TEST_F (ProjectManagerDecoratorTest, untitledEmptySaveAsCancel)
 Starting from new document (without project dir defined). More...
 
 TEST_F (ProjectManagerDecoratorTest, untitledEmptySaveAsWrongDir)
 Starting from new document (without project dir defined). More...
 
 TEST_F (ProjectManagerDecoratorTest, untitledEmptySaveCurrentProject)
 Starting from new document (without project dir defined). More...
 
 TEST_F (ProjectManagerDecoratorTest, untitledModifiedOpenExisting)
 Untitled, modified document. 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 projectmanagerdecorator.test.cpp.

Function Documentation

◆ TEST_F() [1/7]

TEST_F ( ProjectManagerDecoratorTest  ,
initialState   
)

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

Definition at line 67 of file projectmanagerdecorator.test.cpp.

68 {
69  ProjectManagerDecorator manager(projectContext(), userContext());
70  EXPECT_TRUE(manager.currentProjectDir().empty());
71 }
Decorator for ProjectManager to provide interaction with the user on open/save-as requests.

References ModelView::ProjectManagerDecorator::currentProjectDir().

Here is the call graph for this function:

◆ TEST_F() [2/7]

TEST_F ( ProjectManagerDecoratorTest  ,
untitledEmptyCreateNew   
)

Starting from new document (without project dir defined).

Create new project in given directory.

Definition at line 76 of file projectmanagerdecorator.test.cpp.

77 {
78  const auto project_dir = createEmptyDir("Project_untitledEmptyCreateNew");
79 
80  ProjectManagerDecorator manager(projectContext(), userContext(project_dir, {}));
81  EXPECT_TRUE(manager.currentProjectDir().empty());
82 
83  // saving new project to 'project_dir' directory.
84  EXPECT_TRUE(manager.createNewProject());
85 
86  // checking that current projectDir has pointing to the right place
87  EXPECT_EQ(manager.currentProjectDir(), project_dir);
88 
89  // project directory should contain a json file with the model
90  auto model_json = Utils::join(project_dir, samplemodel_name + ".json");
91  EXPECT_TRUE(Utils::exists(model_json));
92 }
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::ProjectManagerDecorator::createNewProject(), ModelView::ProjectManagerDecorator::currentProjectDir(), ModelView::Utils::exists(), and ModelView::Utils::join().

Here is the call graph for this function:

◆ TEST_F() [3/7]

TEST_F ( ProjectManagerDecoratorTest  ,
untitledEmptySaveAs   
)

Starting from new document (without project dir defined).

Save under given name.

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

119 {
120  const auto project_dir = createEmptyDir("Project_untitledEmptySaveAs");
121 
122  ProjectManagerDecorator manager(projectContext(), userContext(project_dir, {}));
123  EXPECT_TRUE(manager.currentProjectDir().empty());
124 
125  // saving new project to "project_dir" directory.
126  EXPECT_TRUE(manager.saveProjectAs());
127 
128  // checking that current projectDir has pointing to the right place
129  EXPECT_EQ(manager.currentProjectDir(), project_dir);
130 
131  // project directory should contain a json file with the model
132  auto model_json = Utils::join(project_dir, samplemodel_name + ".json");
133  EXPECT_TRUE(Utils::exists(model_json));
134 }

References ModelView::ProjectManagerDecorator::currentProjectDir(), ModelView::Utils::exists(), ModelView::Utils::join(), and ModelView::ProjectManagerDecorator::saveProjectAs().

Here is the call graph for this function:

◆ TEST_F() [4/7]

TEST_F ( ProjectManagerDecoratorTest  ,
untitledEmptySaveAsCancel   
)

Starting from new document (without project dir defined).

Attempt to save under empty name, immitating the user canceled directory selection dialog.

Definition at line 139 of file projectmanagerdecorator.test.cpp.

140 {
141  ProjectManagerDecorator manager(projectContext(), userContext({}, {})); // immitates canceling
142  EXPECT_TRUE(manager.currentProjectDir().empty());
143 
144  // saving new project to "project_dir" directory.
145  EXPECT_FALSE(manager.saveProjectAs());
146  EXPECT_TRUE(manager.currentProjectDir().empty());
147 }

References ModelView::ProjectManagerDecorator::currentProjectDir(), and ModelView::ProjectManagerDecorator::saveProjectAs().

Here is the call graph for this function:

◆ TEST_F() [5/7]

TEST_F ( ProjectManagerDecoratorTest  ,
untitledEmptySaveAsWrongDir   
)

Starting from new document (without project dir defined).

Attempt to save in the non-existing directory.

Definition at line 152 of file projectmanagerdecorator.test.cpp.

153 {
154  ProjectManagerDecorator manager(projectContext(), userContext("non-existing", {}));
155 
156  // saving new project to "project_dir" directory.
157  EXPECT_FALSE(manager.saveProjectAs());
158  EXPECT_TRUE(manager.currentProjectDir().empty());
159 }

References ModelView::ProjectManagerDecorator::currentProjectDir(), and ModelView::ProjectManagerDecorator::saveProjectAs().

Here is the call graph for this function:

◆ TEST_F() [6/7]

TEST_F ( ProjectManagerDecoratorTest  ,
untitledEmptySaveCurrentProject   
)

Starting from new document (without project dir defined).

Saving project. Same behavior as SaveAs.

Definition at line 97 of file projectmanagerdecorator.test.cpp.

98 {
99  const auto project_dir = createEmptyDir("Project_untitledEmptySaveCurrentProject");
100 
101  ProjectManagerDecorator manager(projectContext(), userContext(project_dir, {}));
102  EXPECT_TRUE(manager.currentProjectDir().empty());
103 
104  // saving new project to 'project_dir' directory.
105  EXPECT_TRUE(manager.saveCurrentProject());
106 
107  // checking thaxt current projectDir has pointing to the right place
108  EXPECT_EQ(manager.currentProjectDir(), project_dir);
109 
110  // project directory should contain a json file with the model
111  auto model_json = Utils::join(project_dir, samplemodel_name + ".json");
112  EXPECT_TRUE(Utils::exists(model_json));
113 }

References ModelView::ProjectManagerDecorator::currentProjectDir(), ModelView::Utils::exists(), ModelView::Utils::join(), and ModelView::ProjectManagerDecorator::saveCurrentProject().

Here is the call graph for this function:

◆ TEST_F() [7/7]

TEST_F ( ProjectManagerDecoratorTest  ,
untitledModifiedOpenExisting   
)

Untitled, modified document.

Attempt to open existing project will lead to the dialog save/discard/cancel. As a result of whole exersize, existing project should be opened, previous project saved.

Definition at line 165 of file projectmanagerdecorator.test.cpp.

166 {
167  const auto existing_project_dir = createEmptyDir("Project_untitledModifiedOpenExisting1");
168  const auto unsaved_project_dir = createEmptyDir("Project_untitledModifiedOpenExisting2");
169 
170  // create "existing project"
171  {
172  ProjectManagerDecorator manager(projectContext(), userContext(existing_project_dir, {}));
173  manager.saveProjectAs();
174  }
175 
176  // preparing manager with untitled, unmodified project
177  auto open_dir = [&existing_project_dir]() -> std::string { return existing_project_dir; };
178  auto create_dir = [&unsaved_project_dir]() -> std::string { return unsaved_project_dir; };
179  auto result = SaveChangesAnswer::DISCARD;
180  auto ask_create = [&result]() {
181  result = SaveChangesAnswer::SAVE;
182  return SaveChangesAnswer::SAVE;
183  };
184  auto user_context = userContext({}, {});
185  user_context.m_create_dir_callback = create_dir;
186  user_context.m_select_dir_callback = open_dir;
187  user_context.m_answer_callback = ask_create;
188  ProjectManagerDecorator manager(projectContext(), user_context);
189 
190  // modifying untitled project
191  sample_model->insertItem<PropertyItem>();
192  EXPECT_TRUE(manager.isModified());
193  EXPECT_TRUE(manager.currentProjectDir().empty());
194 
195  // attempt to open existing project
196  manager.openExistingProject();
197 
198  // check if user was asked and his answer coincide with expectation
199  EXPECT_EQ(result, SaveChangesAnswer::SAVE);
200 
201  // check that previous project was saved
202  auto model_json = Utils::join(unsaved_project_dir, samplemodel_name + ".json");
203  EXPECT_TRUE(Utils::exists(model_json));
204 
205  // currently manager is pointing to existing project
206  EXPECT_FALSE(manager.isModified());
207  EXPECT_EQ(manager.currentProjectDir(), existing_project_dir);
208 }
Item to carry concrete editable entity (e.g.
Definition: propertyitem.h:27

References ModelView::ProjectManagerDecorator::currentProjectDir(), ModelView::DISCARD, ModelView::Utils::exists(), ModelView::ProjectManagerDecorator::isModified(), ModelView::Utils::join(), ModelView::ProjectManagerDecorator::openExistingProject(), ModelView::SAVE, and ModelView::ProjectManagerDecorator::saveProjectAs().

Here is the call graph for this function: