BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
vectoritem.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/vectoritem.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 "google_test.h"
16 #include "mvvm/model/itemutils.h"
19 
20 using namespace ModelView;
21 
22 //! VectorItem tests.
23 
24 class VectorItemTest : public ::testing::Test {
25 public:
27 };
28 
30 
31 //! Initial state of item when it is created outside of model context.
32 
33 TEST_F(VectorItemTest, initialState)
34 {
35  VectorItem item;
36 
37  EXPECT_TRUE(Utils::IsSinglePropertyTag(item, VectorItem::P_X));
38  EXPECT_TRUE(Utils::IsSinglePropertyTag(item, VectorItem::P_Y));
39  EXPECT_TRUE(Utils::IsSinglePropertyTag(item, VectorItem::P_Z));
40 
41  EXPECT_FALSE(item.isEditable());
42 
43  EXPECT_EQ(item.property<double>(VectorItem::P_X), 0.0);
44  EXPECT_EQ(item.property<double>(VectorItem::P_Y), 0.0);
45  EXPECT_EQ(item.property<double>(VectorItem::P_Z), 0.0);
46 
47  // default label
48  EXPECT_EQ(item.data<std::string>(), "(0, 0, 0)");
49 }
50 
51 //! Initial state of item in model context
52 
53 TEST_F(VectorItemTest, initialStateFromModel)
54 {
55  SessionModel model;
56  auto item = model.insertItem<VectorItem>();
57 
58  EXPECT_EQ(item->property<double>(VectorItem::P_X), 0.0);
59  EXPECT_EQ(item->property<double>(VectorItem::P_Y), 0.0);
60  EXPECT_EQ(item->property<double>(VectorItem::P_Z), 0.0);
61 
62  // default label
63  EXPECT_EQ(item->data<std::string>(), "(0, 0, 0)");
64 
65  // changing vector component
66  item->setProperty(VectorItem::P_X, 1.0);
67  EXPECT_EQ(item->data<std::string>(), "(1, 0, 0)");
68 }
bool isEditable() const
Returns true if this item has editable flag set.
T data(int role=ItemDataRole::DATA) const
Returns data of given type T for given role.
Definition: sessionitem.h:148
T property(const std::string &tag) const
Returns data stored in property item.
Definition: sessionitem.h:181
Main class to hold hierarchy of SessionItem objects.
Definition: sessionmodel.h:37
T * insertItem(SessionItem *parent=nullptr, const TagRow &tagrow={})
Inserts item into given parent under given tagrow.
Definition: sessionmodel.h:104
Vector item with three x,y,z property items.
Definition: vectoritem.h:24
static const std::string P_X
Definition: vectoritem.h:26
static const std::string P_Z
Definition: vectoritem.h:28
static const std::string P_Y
Definition: vectoritem.h:27
VectorItem tests.
Defines class CLASS?
Defines class CLASS?
MVVM_MODEL_EXPORT bool IsSinglePropertyTag(const SessionItem &item, const std::string &tag)
Returns true if given item has registered tag, and it belongs to single property.
Definition: itemutils.cpp:91
materialitems.h Collection of materials to populate MaterialModel.
Defines class CLASS?
Defines class CLASS?
TEST_F(VectorItemTest, initialState)
Initial state of item when it is created outside of model context.