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

Implements class CLASS? More...

Include dependency graph for setvaluecommand.test.cpp:

Go to the source code of this file.

Classes

class  SetValueCommandTest
 

Functions

 TEST_F (SetValueCommandTest, setSameValueCommand)
 Set same item value through SetValueCommand command. More...
 
 TEST_F (SetValueCommandTest, setValueCommand)
 Set item value through SetValueCommand command. 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 setvaluecommand.test.cpp.

Function Documentation

◆ TEST_F() [1/2]

TEST_F ( SetValueCommandTest  ,
setSameValueCommand   
)

Set same item value through SetValueCommand command.

Definition at line 59 of file setvaluecommand.test.cpp.

60 {
61  SessionModel model;
62  const int role = ItemDataRole::DATA;
63 
64  // inserting single item
65  auto item = model.insertItem<SessionItem>();
66  QVariant expected(42.0);
67  item->setData(expected, role);
68 
69  // command to set same value
70  auto command = std::make_unique<SetValueCommand>(item, expected, role);
71 
72  // executing command
73  command->execute();
74  EXPECT_FALSE(std::get<bool>(command->result())); // value wasn't changed
75  EXPECT_EQ(model.data(item, role), expected);
76  EXPECT_EQ(command->isObsolete(), true);
77 
78  // undoing command which is in isObsolete state is not possible
79  EXPECT_THROW(command->undo(), std::runtime_error);
80 }
The main object representing an editable/displayable/serializable entity.
Definition: sessionitem.h:38
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
Variant data(SessionItem *item, int role) const
Returns the data for given item and role.
const int DATA
main data role
Definition: mvvm_types.h:30

References ModelView::ItemDataRole::DATA, ModelView::SessionModel::data(), and ModelView::SessionModel::insertItem().

Here is the call graph for this function:

◆ TEST_F() [2/2]

TEST_F ( SetValueCommandTest  ,
setValueCommand   
)

Set item value through SetValueCommand command.

Definition at line 32 of file setvaluecommand.test.cpp.

33 {
34  SessionModel model;
35  const int role = ItemDataRole::DATA;
36 
37  // inserting single item
38  auto item = model.insertItem<SessionItem>();
39  EXPECT_FALSE(model.data(item, role).isValid());
40 
41  QVariant expected(42.0);
42  auto command = std::make_unique<SetValueCommand>(item, expected, role);
43 
44  // executing command
45  command->execute();
46  EXPECT_TRUE(std::get<bool>(command->result())); // value was changed
47  EXPECT_EQ(command->isObsolete(), false);
48  EXPECT_EQ(model.data(item, role), expected);
49 
50  // undoing command
51  command->undo();
52  EXPECT_TRUE(std::get<bool>(command->result())); // value was changed
53  EXPECT_FALSE(model.data(item, role).isValid());
54  EXPECT_EQ(command->isObsolete(), false);
55 }

References ModelView::ItemDataRole::DATA, ModelView::SessionModel::data(), and ModelView::SessionModel::insertItem().

Here is the call graph for this function: