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

Implements class CLASS? More...

Include dependency graph for itemcatalogue.test.cpp:

Go to the source code of this file.

Classes

class  ItemCatalogueTest
 Testing ItemCatalogue construction. More...
 

Functions

 TEST_F (ItemCatalogueTest, addItem)
 
 TEST_F (ItemCatalogueTest, addLabeledItem)
 
 TEST_F (ItemCatalogueTest, assignmentOperator)
 
 TEST_F (ItemCatalogueTest, contains)
 
 TEST_F (ItemCatalogueTest, copyConstructor)
 
 TEST_F (ItemCatalogueTest, defaultItemCatalogue)
 
 TEST_F (ItemCatalogueTest, initialState)
 
 TEST_F (ItemCatalogueTest, merge)
 

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 itemcatalogue.test.cpp.

Function Documentation

◆ TEST_F() [1/8]

TEST_F ( ItemCatalogueTest  ,
addItem   
)

Definition at line 41 of file itemcatalogue.test.cpp.

42 {
43  ItemCatalogue catalogue;
44 
45  catalogue.registerItem<PropertyItem>();
46 
47  EXPECT_EQ(catalogue.itemCount(), 1);
48 
49  auto item = catalogue.create(Constants::PropertyType);
50  EXPECT_TRUE(dynamic_cast<PropertyItem*>(item.get()) != nullptr);
51 
52  // registration of second item is not allowed
53  EXPECT_THROW(catalogue.registerItem<PropertyItem>(), std::runtime_error);
54 
55  // item was not registered, creation not allowed
56  EXPECT_THROW(catalogue.create("non-registered"), std::runtime_error);
57 
58  // checking model types and labels
59  EXPECT_EQ(catalogue.modelTypes(), std::vector<std::string>({"Property"}));
60  EXPECT_EQ(catalogue.labels(), std::vector<std::string>({""}));
61 }
Catalogue for item constructions.
Definition: itemcatalogue.h:30
std::vector< std::string > modelTypes() const
void registerItem(const std::string &label={})
Definition: itemcatalogue.h:60
std::vector< std::string > labels() const
std::unique_ptr< SessionItem > create(const std::string &modelType) const
Item to carry concrete editable entity (e.g.
Definition: propertyitem.h:27
const model_type PropertyType
Definition: mvvm_types.h:59

References ModelView::ItemCatalogue::create(), ModelView::ItemCatalogue::itemCount(), ModelView::ItemCatalogue::labels(), ModelView::ItemCatalogue::modelTypes(), ModelView::Constants::PropertyType, and ModelView::ItemCatalogue::registerItem().

Here is the call graph for this function:

◆ TEST_F() [2/8]

TEST_F ( ItemCatalogueTest  ,
addLabeledItem   
)

Definition at line 134 of file itemcatalogue.test.cpp.

135 {
136  ItemCatalogue catalogue;
137  catalogue.registerItem<PropertyItem>("property");
138  catalogue.registerItem<VectorItem>("vector item");
139 
140  // checking model types and labels
141  EXPECT_EQ(catalogue.modelTypes(), std::vector<std::string>({"Property", "Vector"}));
142  EXPECT_EQ(catalogue.labels(), std::vector<std::string>({"property", "vector item"}));
143 }
Vector item with three x,y,z property items.
Definition: vectoritem.h:24

References ModelView::ItemCatalogue::labels(), ModelView::ItemCatalogue::modelTypes(), and ModelView::ItemCatalogue::registerItem().

Here is the call graph for this function:

◆ TEST_F() [3/8]

TEST_F ( ItemCatalogueTest  ,
assignmentOperator   
)

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

92 {
93  ItemCatalogue catalogue;
94  catalogue.registerItem<PropertyItem>();
95 
97  copy = catalogue;
98 
99  // creation of item using first catalogue
100  auto item = catalogue.create(Constants::PropertyType);
101  EXPECT_TRUE(dynamic_cast<PropertyItem*>(item.get()) != nullptr);
102 
103  // creation of item using catalogue copy
104  item = copy.create(Constants::PropertyType);
105  EXPECT_TRUE(dynamic_cast<PropertyItem*>(item.get()) != nullptr);
106 }
@ copy
full deep copying with item identifiers regenerated

References ModelView::copy, ModelView::ItemCatalogue::create(), ModelView::Constants::PropertyType, and ModelView::ItemCatalogue::registerItem().

Here is the call graph for this function:

◆ TEST_F() [4/8]

TEST_F ( ItemCatalogueTest  ,
contains   
)

Definition at line 108 of file itemcatalogue.test.cpp.

109 {
110  ItemCatalogue catalogue;
111  catalogue.registerItem<PropertyItem>();
112 
113  EXPECT_TRUE(catalogue.contains(Constants::PropertyType));
114  EXPECT_FALSE(catalogue.contains(Constants::VectorItemType));
115 }
bool contains(const std::string &modelType) const
const model_type VectorItemType
Definition: mvvm_types.h:61

References ModelView::ItemCatalogue::contains(), ModelView::Constants::PropertyType, ModelView::ItemCatalogue::registerItem(), and ModelView::Constants::VectorItemType.

Here is the call graph for this function:

◆ TEST_F() [5/8]

TEST_F ( ItemCatalogueTest  ,
copyConstructor   
)

Definition at line 63 of file itemcatalogue.test.cpp.

64 {
65  ItemCatalogue catalogue;
66  catalogue.registerItem<PropertyItem>();
67 
68  ItemCatalogue copy(catalogue);
69 
70  // creation of item using first catalogue
71  auto item = catalogue.create(Constants::PropertyType);
72  EXPECT_TRUE(dynamic_cast<PropertyItem*>(item.get()) != nullptr);
73 
74  // creation of item using catalogue copy
75  item = copy.create(Constants::PropertyType);
76  EXPECT_TRUE(dynamic_cast<PropertyItem*>(item.get()) != nullptr);
77 
78  // checking model types and labels in new catalogue
79  EXPECT_EQ(copy.modelTypes(), std::vector<std::string>({"Property"}));
80  EXPECT_EQ(copy.labels(), std::vector<std::string>({""}));
81 
82  // adding item to first catalogue but not the second
83  catalogue.registerItem<VectorItem>();
84  item = catalogue.create(Constants::VectorItemType);
85  EXPECT_TRUE(dynamic_cast<VectorItem*>(item.get()) != nullptr);
86 
87  // copy of catalogue knows nothing about new VectorType
88  EXPECT_THROW(copy.create(Constants::VectorItemType), std::runtime_error);
89 }

References ModelView::copy, ModelView::ItemCatalogue::create(), ModelView::Constants::PropertyType, ModelView::ItemCatalogue::registerItem(), and ModelView::Constants::VectorItemType.

Here is the call graph for this function:

◆ TEST_F() [6/8]

TEST_F ( ItemCatalogueTest  ,
defaultItemCatalogue   
)

Definition at line 117 of file itemcatalogue.test.cpp.

118 {
119  auto catalogue = CreateStandardItemCatalogue();
120 
121  auto item = catalogue->create(Constants::BaseType);
122  EXPECT_TRUE(dynamic_cast<SessionItem*>(item.get()) != nullptr);
123 
124  item = catalogue->create(Constants::PropertyType);
125  EXPECT_TRUE(dynamic_cast<PropertyItem*>(item.get()) != nullptr);
126 
127  item = catalogue->create(Constants::VectorItemType);
128  EXPECT_TRUE(dynamic_cast<VectorItem*>(item.get()) != nullptr);
129 
130  item = catalogue->create(Constants::CompoundItemType);
131  EXPECT_TRUE(dynamic_cast<CompoundItem*>(item.get()) != nullptr);
132 }
Complex item holding mixed SessionItem types (single properties and other CompountItems).
Definition: compounditem.h:28
The main object representing an editable/displayable/serializable entity.
Definition: sessionitem.h:38
const model_type BaseType
Definition: mvvm_types.h:45
const model_type CompoundItemType
Definition: mvvm_types.h:48
MVVM_MODEL_EXPORT std::unique_ptr< ItemCatalogue > CreateStandardItemCatalogue()
Creates a catalog of items supported by SessionModel out-of-the-box.

References ModelView::Constants::BaseType, ModelView::Constants::CompoundItemType, ModelView::CreateStandardItemCatalogue(), ModelView::Constants::PropertyType, and ModelView::Constants::VectorItemType.

Here is the call graph for this function:

◆ TEST_F() [7/8]

TEST_F ( ItemCatalogueTest  ,
initialState   
)

Definition at line 33 of file itemcatalogue.test.cpp.

34 {
35  ItemCatalogue catalogue;
36  EXPECT_EQ(catalogue.itemCount(), 0);
37  EXPECT_EQ(catalogue.modelTypes(), std::vector<std::string>({}));
38  EXPECT_EQ(catalogue.labels(), std::vector<std::string>({}));
39 }

References ModelView::ItemCatalogue::itemCount(), ModelView::ItemCatalogue::labels(), and ModelView::ItemCatalogue::modelTypes().

Here is the call graph for this function:

◆ TEST_F() [8/8]

TEST_F ( ItemCatalogueTest  ,
merge   
)

Definition at line 145 of file itemcatalogue.test.cpp.

146 {
147  ItemCatalogue catalogue1;
148  catalogue1.registerItem<PropertyItem>("property");
149  catalogue1.registerItem<VectorItem>("vector");
150 
151  ItemCatalogue catalogue2;
152  catalogue2.registerItem<CompoundItem>("compound");
153 
154  // adding two catalogue together
155  catalogue1.merge(catalogue2);
156 
157  std::vector<std::string> expected_models = {Constants::PropertyType, Constants::VectorItemType,
159  std::vector<std::string> expected_labels = {"property", "vector", "compound"};
160 
161  EXPECT_EQ(catalogue1.modelTypes(), expected_models);
162  EXPECT_EQ(catalogue1.labels(), expected_labels);
163 
164  auto item = catalogue1.create(Constants::VectorItemType);
165  EXPECT_TRUE(dynamic_cast<VectorItem*>(item.get()) != nullptr);
166 
167  // duplications is not allowed
168  EXPECT_THROW(catalogue1.merge(catalogue2), std::runtime_error);
169 }
void merge(const ItemCatalogue &other)
Adds content of other catalogue to this.

References ModelView::Constants::CompoundItemType, ModelView::ItemCatalogue::create(), ModelView::ItemCatalogue::labels(), ModelView::ItemCatalogue::merge(), ModelView::ItemCatalogue::modelTypes(), ModelView::Constants::PropertyType, ModelView::ItemCatalogue::registerItem(), and ModelView::Constants::VectorItemType.

Here is the call graph for this function: