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

Implements class CLASS? More...

Include dependency graph for jsontaginfoconverter.test.cpp:

Go to the source code of this file.

Classes

class  JsonTagInfoConverterTest
 Test convertion of TagInfo from/to QJsonObject. More...
 

Functions

 TEST_F (JsonTagInfoConverterTest, isItemTag)
 Checks if json object is correctly identified as representing TagInfo. More...
 
 TEST_F (JsonTagInfoConverterTest, tagInfoToFileAndBack)
 To file and back. More...
 
 TEST_F (JsonTagInfoConverterTest, tagInfoToJsonAndBack)
 From TagInfo to json and back. More...
 
 TEST_F (JsonTagInfoConverterTest, toJson)
 Creating QJsonArray from TagInfo. 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 jsontaginfoconverter.test.cpp.

Function Documentation

◆ TEST_F() [1/4]

TEST_F ( JsonTagInfoConverterTest  ,
isItemTag   
)

Checks if json object is correctly identified as representing TagInfo.

Definition at line 39 of file jsontaginfoconverter.test.cpp.

40 {
41  JsonTagInfoConverter converter;
42 
43  // valid json object representing DataRole
44  QJsonObject object;
45  object[JsonTagInfoConverter::nameKey] = QString::fromStdString("tag1");
46  object[JsonTagInfoConverter::minKey] = 0;
47  object[JsonTagInfoConverter::maxKey] = 1;
48  object[JsonTagInfoConverter::modelsKey] = QJsonArray();
49 
50  EXPECT_TRUE(converter.isTagInfo(object));
51 
52  // invalid (not fully constructed) json object which can't represent TagInfo
53  QJsonObject object2;
54  object2[JsonTagInfoConverter::minKey] = 42;
55  EXPECT_FALSE(converter.isTagInfo(object2));
56 }
Default converter between TagInfo and json object.
bool isTagInfo(const QJsonObject &object)
Returns true if given json object represents TagInfo object.

References ModelView::JsonTagInfoConverter::isTagInfo(), ModelView::JsonTagInfoConverter::maxKey, ModelView::JsonTagInfoConverter::minKey, ModelView::JsonTagInfoConverter::modelsKey, and ModelView::JsonTagInfoConverter::nameKey.

Here is the call graph for this function:

◆ TEST_F() [2/4]

TEST_F ( JsonTagInfoConverterTest  ,
tagInfoToFileAndBack   
)

To file and back.

Definition at line 90 of file jsontaginfoconverter.test.cpp.

91 {
92  const std::string tag_name("tag");
93  const std::string model_type("model");
94  JsonTagInfoConverter converter;
95 
96  TagInfo tag = TagInfo::propertyTag(tag_name, model_type);
97  auto object = converter.to_json(tag);
98 
99  // saving object to file
100  auto fileName = TestUtils::TestFileName(testDir(), "taginfo.json");
101  TestUtils::SaveJson(object, fileName);
102 
103  auto document = TestUtils::LoadJson(fileName);
104  TagInfo reco_tag = converter.from_json(document.object());
105 
106  EXPECT_EQ(reco_tag.name(), tag_name);
107  EXPECT_EQ(reco_tag.min(), 1);
108  EXPECT_EQ(reco_tag.max(), 1);
109  EXPECT_EQ(reco_tag.modelTypes(), std::vector<std::string>() = {model_type});
110 }
QJsonObject to_json(const TagInfo &tag) override
TagInfo from_json(const QJsonObject &object) override
Holds info about single tag for SessionItem.
Definition: taginfo.h:28
std::string name() const
Definition: taginfo.cpp:45
int max() const
Definition: taginfo.cpp:55
std::vector< std::string > modelTypes() const
Definition: taginfo.cpp:60
int min() const
Definition: taginfo.cpp:50
std::string model_type
Definition: types.h:23
std::string TestFileName(const std::string &test_sub_dir, const std::string &file_name)
Returns full path to the file in test directory.
Definition: test_utils.cpp:52
void SaveJson(const QJsonObject &object, const std::string &fileName)
Definition: test_utils.cpp:58
QJsonDocument LoadJson(const std::string &fileName)
Definition: test_utils.cpp:81

References ModelView::JsonTagInfoConverter::from_json(), TestUtils::LoadJson(), ModelView::TagInfo::max(), ModelView::TagInfo::min(), ModelView::TagInfo::modelTypes(), ModelView::TagInfo::name(), ModelView::TagInfo::propertyTag(), TestUtils::SaveJson(), TestUtils::TestFileName(), and ModelView::JsonTagInfoConverter::to_json().

Here is the call graph for this function:

◆ TEST_F() [3/4]

TEST_F ( JsonTagInfoConverterTest  ,
tagInfoToJsonAndBack   
)

From TagInfo to json and back.

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

74 {
75  JsonTagInfoConverter converter;
76 
77  TagInfo tag("tag", 0, 42, std::vector<std::string>() = {"aaa", "bbb"});
78  auto object = converter.to_json(tag);
79 
80  TagInfo reco_tag = converter.from_json(object);
81 
82  EXPECT_EQ(reco_tag.name(), tag.name());
83  EXPECT_EQ(reco_tag.min(), tag.min());
84  EXPECT_EQ(reco_tag.max(), tag.max());
85  EXPECT_EQ(reco_tag.modelTypes(), tag.modelTypes());
86 }

References ModelView::JsonTagInfoConverter::from_json(), ModelView::TagInfo::max(), ModelView::TagInfo::min(), ModelView::TagInfo::modelTypes(), ModelView::TagInfo::name(), and ModelView::JsonTagInfoConverter::to_json().

Here is the call graph for this function:

◆ TEST_F() [4/4]

TEST_F ( JsonTagInfoConverterTest  ,
toJson   
)

Creating QJsonArray from TagInfo.

Definition at line 60 of file jsontaginfoconverter.test.cpp.

61 {
62  JsonTagInfoConverter converter;
63 
64  TagInfo tag("tag1", 0, -1, std::vector<std::string>() = {});
65  auto object = converter.to_json(tag);
66 
67  // this object represents TagInfo
68  EXPECT_TRUE(converter.isTagInfo(object));
69 }

References ModelView::JsonTagInfoConverter::isTagInfo(), and ModelView::JsonTagInfoConverter::to_json().

Here is the call graph for this function: