BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
projectutils.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/projectutils.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 "folderbasedtest.h"
16 #include "google_test.h"
23 #include "mvvm/utils/fileutils.h"
24 #include "test_utils.h"
25 
26 using namespace ModelView;
27 
28 //! Tests of ProjectUtils namespace functions.
29 
31 public:
33  : FolderBasedTest("test_ProjectUtils")
34  , sample_model(std::make_unique<SessionModel>("SampleModel"))
35  {
36  }
37 
39 
40  std::vector<SessionModel*> models() const { return {sample_model.get()}; };
41 
43  {
44  ProjectContext result;
45  result.m_models_callback = [this]() { return models(); };
46  return result;
47  }
48 
49  std::unique_ptr<SessionModel> sample_model;
50 };
51 
53 
54 //! Testing helper structure.
55 
57 {
58  SessionModel model("TestModel");
59  EXPECT_EQ(std::string("testmodel.json"), ProjectUtils::SuggestFileName(model));
60 }
61 
63 {
64  auto project = ProjectUtils::CreateUntitledProject(createContext());
65  EXPECT_TRUE(project->projectDir().empty());
66 }
67 
69 {
70  auto project = ProjectUtils::CreateUntitledProject(createContext());
71 
72  // unmodified project without projectDir
73  EXPECT_EQ(ProjectUtils::ProjectWindowTitle(*project), "Untitled");
74 
75  sample_model->insertItem<PropertyItem>();
76  EXPECT_EQ(ProjectUtils::ProjectWindowTitle(*project), "*Untitled");
77 
78  // saving in a project directory
79  project->save(testPath());
80  EXPECT_EQ(ProjectUtils::ProjectWindowTitle(*project), testDir());
81 
82  // modifying
83  sample_model->insertItem<PropertyItem>();
84  EXPECT_EQ(ProjectUtils::ProjectWindowTitle(*project), "*" + testDir());
85 }
86 
88 {
89  auto project = ProjectUtils::CreateUntitledProject(createContext());
90 
91  // empty directory can't be a project directory
92  auto dirname = createEmptyDir("test_IsPossibleProjectDir");
93  EXPECT_FALSE(ProjectUtils::IsPossibleProjectDir(dirname));
94 
95  project->save(dirname);
96  EXPECT_TRUE(ProjectUtils::IsPossibleProjectDir(dirname));
97 }
Defines class CLASS?
Convenience class which creates a directory on disk for test content.
Item to carry concrete editable entity (e.g.
Definition: propertyitem.h:27
Main class to hold hierarchy of SessionItem objects.
Definition: sessionmodel.h:37
Tests of ProjectUtils namespace functions.
std::unique_ptr< SessionModel > sample_model
ProjectContext createContext()
std::vector< SessionModel * > models() const
Defines class CLASS?
Defines class CLASS?
Defines class CLASS?
MVVM_MODEL_EXPORT std::string SuggestFileName(const SessionModel &model)
Suggests file name which can be used to store json content of given model.
MVVM_MODEL_EXPORT std::unique_ptr< ProjectInterface > CreateUntitledProject(const ProjectContext &context)
Creates new untitled project.
MVVM_MODEL_EXPORT bool IsPossibleProjectDir(const std::string &project_dir)
Returns 'true' if given directory might be a project directory.
MVVM_MODEL_EXPORT std::string ProjectWindowTitle(const ProjectInterface &project)
Returns a MainWindow title for given project.
materialitems.h Collection of materials to populate MaterialModel.
@ project
selective copying for saving/loading the project (tags and data created by item, updated from JSON)
Definition: filesystem.h:81
Defines class CLASS?
Defines class CLASS?
Defines class CLASS?
TEST_F(ProjectUtilsTest, SuggestFileName)
Testing helper structure.
Defines class CLASS?
Defines class CLASS?
Provides necessary information for Project construction.
Definition: project_types.h:32
models_callback_t m_models_callback
Definition: project_types.h:42
Defines class CLASS?