BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
TestToyParticleItem.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/testviewmodel/TestToyParticleItem.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 #include "toyitems.h"
20 #include "toymodel.h"
21 #include <QSignalSpy>
22 
23 using namespace ModelView;
24 
25 //! Tests of toy MultiLayer in the context of model and viewmodel.
26 
27 class ToyParticleItemTest : public ::testing::Test {
28 public:
30 };
31 
33 
34 //! Initial state.
35 
37 {
41 }
42 
44 {
46  auto particle = model.insertItem<ToyItems::ParticleItem>();
47 
48  EXPECT_EQ(Utils::TopLevelItems(*model.rootItem()), std::vector<SessionItem*>({particle}));
49  EXPECT_EQ(Utils::TopLevelItems(*particle), std::vector<SessionItem*>{});
50 }
51 
53 {
55  auto particle = model.insertItem<ToyItems::ParticleItem>();
56 
57  EXPECT_EQ(Utils::TopLevelItems(*model.rootItem()), std::vector<SessionItem*>({particle}));
58 
59  EXPECT_EQ(Utils::SinglePropertyItems(*model.rootItem()), std::vector<SessionItem*>{});
60  std::vector<SessionItem*> expected = {particle->getItem(ToyItems::ParticleItem::P_POSITION),
61  particle->getItem(ToyItems::ParticleItem::P_SHAPES)};
62  EXPECT_EQ(Utils::SinglePropertyItems(*particle), expected);
63 }
TEST_F(ToyParticleItemTest, initialState)
Initial state.
SessionItem * rootItem() const
Returns root item of the model.
T * insertItem(SessionItem *parent=nullptr, const TagRow &tagrow={})
Inserts item into given parent under given tagrow.
Definition: sessionmodel.h:104
Represents a particle, with a position, and a selection of possible shapes.
Definition: toyitems.h:62
static const std::string P_SHAPES
Definition: toyitems.h:65
static const std::string P_POSITION
Definition: toyitems.h:64
Tests of toy MultiLayer in the context of model and viewmodel.
Defines class CLASS?
Defines class CLASS?
Defines class CLASS?
MVVM_MODEL_EXPORT std::vector< SessionItem * > SinglePropertyItems(const SessionItem &item)
Returns vector of children representing property items.
Definition: itemutils.cpp:122
MVVM_MODEL_EXPORT std::vector< SessionItem * > TopLevelItems(const SessionItem &item)
Returns vector of children representing top level items.
Definition: itemutils.cpp:113
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?
Defines class CLASS?