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

Implements class CLASS? More...

Include dependency graph for project.test.cpp:

Go to the source code of this file.

Classes

class  ProjectTest
 Tests for Project class. More...
 

Functions

 TEST_F (ProjectTest, initialState)
 
 TEST_F (ProjectTest, loadModel)
 Testing loadModel. More...
 
 TEST_F (ProjectTest, saveModel)
 Testing saveModel. 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 project.test.cpp.

Function Documentation

◆ TEST_F() [1/3]

TEST_F ( ProjectTest  ,
initialState   
)

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

72 {
73  Project project(createContext());
74  EXPECT_TRUE(project.projectDir().empty());
75  EXPECT_FALSE(project.isModified());
76 }
Project represents content of all application models in a folder on disk.
Definition: project.h:28
@ project
selective copying for saving/loading the project (tags and data created by item, updated from JSON)

References ModelView::project.

◆ TEST_F() [2/3]

TEST_F ( ProjectTest  ,
loadModel   
)

Testing loadModel.

Definition at line 100 of file project.test.cpp.

101 {
102  Project project(createContext());
103 
104  auto item0 = sample_model->insertItem<PropertyItem>();
105  item0->setData(std::string("sample_model_item"));
106  auto item0_identifier = item0->identifier();
107 
108  auto item1 = material_model->insertItem<PropertyItem>();
109  item1->setData(std::string("material_model_item"));
110  auto item1_identifier = item1->identifier();
111 
112  // create project directory and save file
113  auto project_dir = createEmptyDir("Untitled2");
114 
115  EXPECT_TRUE(project.isModified());
116  project.save(project_dir);
117  EXPECT_FALSE(project.isModified());
118 
119  EXPECT_EQ(project.projectDir(), project_dir);
120 
121  // cleaning models
122  sample_model->clear();
123  material_model->clear();
124  EXPECT_EQ(sample_model->rootItem()->childrenCount(), 0);
125  EXPECT_EQ(material_model->rootItem()->childrenCount(), 0);
126  EXPECT_TRUE(project.isModified());
127 
128  // loading
129  project.load(project_dir);
130  EXPECT_EQ(sample_model->rootItem()->childrenCount(), 1);
131  EXPECT_EQ(material_model->rootItem()->childrenCount(), 1);
132 
133  // checking identifiers
134  EXPECT_EQ(sample_model->rootItem()->children()[0]->identifier(), item0_identifier);
135  EXPECT_EQ(material_model->rootItem()->children()[0]->identifier(), item1_identifier);
136 
137  EXPECT_EQ(project.projectDir(), project_dir);
138  EXPECT_FALSE(project.isModified());
139 }
Item to carry concrete editable entity (e.g.
Definition: propertyitem.h:27
bool setData(const T &value, int role=ItemDataRole::DATA, bool direct=false)
Sets data for a given role.
Definition: sessionitem.h:141

References ModelView::project, and ModelView::SessionItem::setData().

Here is the call graph for this function:

◆ TEST_F() [3/3]

TEST_F ( ProjectTest  ,
saveModel   
)

Testing saveModel.

Definition at line 80 of file project.test.cpp.

81 {
82  Project project(createContext());
83 
84  // create project directory and save file
85  auto project_dir = createEmptyDir("Untitled1");
86  project.save(project_dir);
87 
88  EXPECT_EQ(project.projectDir(), project_dir);
89  EXPECT_FALSE(project.isModified());
90 
91  auto sample_json = Utils::join(project_dir, get_json_filename(samplemodel_name));
92  EXPECT_TRUE(Utils::exists(sample_json));
93 
94  auto material_json = Utils::join(project_dir, get_json_filename(materialmodel_name));
95  EXPECT_TRUE(Utils::exists(material_json));
96 }
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::Utils::exists(), ModelView::Utils::join(), and ModelView::project.

Here is the call graph for this function: