COOLFluiD  Release kernel
COOLFluiD is a Collaborative Simulation Environment (CSE) focused on complex MultiPhysics simulations.
utest-ui-core-property-model.cpp
Go to the documentation of this file.
1 // Copyright (C) 2010-2011 von Karman Institute for Fluid Dynamics, Belgium
2 //
3 // This software is distributed under the terms of the
4 // GNU Lesser General Public License version 3 (LGPLv3).
5 // See doc/lgpl.txt and doc/gpl.txt for the license text.
6 
7 #define BOOST_TEST_DYN_LINK
8 #define BOOST_TEST_MODULE "Test module for the ui PropertyModel class"
9 
10 #include "common/OptionURI.hpp"
11 #include "common/OptionT.hpp"
12 #include "common/OptionList.hpp"
13 #include "common/PropertyList.hpp"
14 
15 #include "ui/core/NTree.hpp"
18 #include "ui/core/TreeThread.hpp"
19 
20 #include "test/ui/MyNode.hpp"
22 
24 #include <boost/lexical_cast.hpp>
25 
26 using namespace cf3;
27 using namespace cf3::common;
28 using namespace cf3::ui::core;
29 using namespace cf3::ui::CoreTest;
30 
33 
34 BOOST_AUTO_TEST_SUITE( uiCorePropertyModelSuite )
35 
36 
39 {
40  application();
41 
42  TreeThread& tree = ThreadManager::instance().tree();
43 
48 
49  boost::shared_ptr< MyNode > node(new MyNode("MyAdditionalNode"));
50 
51  PropertyList& props = node->properties();
52  OptionList& opts = node->options();
53 
54  // we clear existing properties and add new ones to ensure the tests will pass
55  // even if properties of Component or CNode classes are modified.
56  props.store.clear();
57  opts.store.clear();
58 
59  opts.add("AnUriOption", URI("cpath:/"));
60  props.add("Euler", Real(2.71));
61  opts.add("MyString", std::string("Hello, World!"));
62  props.add("Pi", Real(3.14159));
63  opts.add("SomeBool", true);
64  opts.add("SomeInt", int(-2168454));
65  props.add("TheAnswer", Uint(42));
66 
67  BOOST_CHECK_EQUAL( props.store.size(), size_t(3));
68  BOOST_CHECK_EQUAL( opts.store.size(), size_t(4));
69 
70  // add the node to the tree
71  tree.root()->add_node( node );
72 
73  // set the node as the current index
74  NTree::global()->set_current_index( NTree::global()->index_from_path( node->uri() ) );
75 }
76 
78 
80 {
82  int role = Qt::DisplayRole;
83 
84  // 1. give an invalid index
85  BOOST_CHECK( !model.data(QModelIndex(), Qt::DisplayRole).isValid() );
86 
87  // 2. give a wrong role
88  BOOST_CHECK( !model.data( model.index(0, 0), Qt::DecorationRole).isValid() );
89 
90  // 3. everything is OK
91  BOOST_CHECK_EQUAL( model.data( model.index(0, 0), role ).toString().toStdString(), std::string("AnUriOption") );
92  BOOST_CHECK_EQUAL( model.data( model.index(0, 1), role ).toString().toStdString(), std::string("cpath:/") );
93 
94  BOOST_CHECK_EQUAL( model.data( model.index(1, 0), role ).toString().toStdString(), std::string("Euler") );
95  BOOST_CHECK_CLOSE( boost::lexical_cast<Real>(model.data( model.index(1, 1), role ).toString().toStdString()), 2.71, 1e-10 );
96 
97  BOOST_CHECK_EQUAL( model.data( model.index(2, 0), role ).toString().toStdString(), std::string("MyString") );
98  BOOST_CHECK_EQUAL( model.data( model.index(2, 1), role ).toString().toStdString(), std::string("Hello, World!") );
99 
100  BOOST_CHECK_EQUAL( model.data( model.index(3, 0), role ).toString().toStdString(), std::string("Pi") );
101  BOOST_CHECK_CLOSE( boost::lexical_cast<Real>(model.data( model.index(3, 1), role ).toString().toStdString()), 3.14159, 1e-10 );
102 
103  BOOST_CHECK_EQUAL( model.data( model.index(4, 0), role ).toString().toStdString(), std::string("SomeBool") );
104  BOOST_CHECK_EQUAL( model.data( model.index(4, 1), role ).toString().toStdString(), std::string("true") );
105 
106  BOOST_CHECK_EQUAL( model.data( model.index(5, 0), role ).toString().toStdString(), std::string("SomeInt") );
107  BOOST_CHECK_EQUAL( model.data( model.index(5, 1), role ).toString().toStdString(), std::string("-2168454") );
108 
109  BOOST_CHECK_EQUAL( model.data( model.index(6, 0), role ).toString().toStdString(), std::string("TheAnswer") );
110  BOOST_CHECK_EQUAL( model.data( model.index(6, 1), role ).toString().toStdString(), std::string("42") );
111 }
112 
114 
116 {
118 
119  // we first check everything is OK since we will consider later that
120  // index(0,0) returns a correct index
121 
122  // 1. everything is ok
123  BOOST_CHECK( model.index(0, 0).isValid() );
124  BOOST_CHECK( model.index(0, 1).isValid() );
125 
126  BOOST_CHECK( model.index(1, 0).isValid() );
127  BOOST_CHECK( model.index(1, 1).isValid() );
128 
129  BOOST_CHECK( model.index(2, 0).isValid() );
130  BOOST_CHECK( model.index(2, 1).isValid() );
131 
132  BOOST_CHECK( model.index(3, 0).isValid() );
133  BOOST_CHECK( model.index(3, 1).isValid() );
134 
135  BOOST_CHECK( model.index(4, 0).isValid() );
136  BOOST_CHECK( model.index(4, 1).isValid() );
137 
138  BOOST_CHECK( model.index(5, 0).isValid() );
139  BOOST_CHECK( model.index(5, 1).isValid() );
140 
141  BOOST_CHECK( model.index(6, 0).isValid() );
142  BOOST_CHECK( model.index(6, 1).isValid() );
143 
144  // 2. invalid row/column
145  BOOST_CHECK( !model.index(7, 0).isValid() );
146  BOOST_CHECK( !model.index(0, 2).isValid() );
147 
148  // 3. valid parent
149  BOOST_CHECK( !model.index(0, 0, model.index(0, 0) ).isValid() );
150 }
151 
153 
155 {
157 
158  // 1. invalid parent (should return the number of properties)
159  BOOST_CHECK_EQUAL( model.rowCount( QModelIndex() ), 7);
160 
161  // 2. valid parent (should return 0)
162  BOOST_CHECK_EQUAL( model.rowCount( model.index(0, 0) ), 0);
163 }
164 
166 
167 BOOST_AUTO_TEST_CASE( header_data )
168 {
170 
171  BOOST_CHECK_EQUAL(model.headerData(0, Qt::Horizontal).toString().toStdString(), std::string("Name"));
172  BOOST_CHECK_EQUAL(model.headerData(1, Qt::Horizontal).toString().toStdString(), std::string("Value"));
173 
174  BOOST_CHECK(!model.headerData(0, Qt::Vertical).isValid());
175  BOOST_CHECK(!model.headerData(0, Qt::Horizontal, Qt::DecorationRole).isValid());
176 }
177 
180 
181 BOOST_AUTO_TEST_SUITE_END()
182 
QApplication * application()
Definition: Application.hpp:11
bool AssertionThrows
assertions throw exceptions
Definition: Assertions.hpp:67
bool ExceptionOutputs
if exception contructor should output
Definition: Exception.hpp:32
static AssertionManager & instance()
Gets the instance of the manager.
Definition: Assertions.cpp:33
Basic Classes for client-core library used by coolfluid-client application.
Definition: CNode.cpp:57
bool AssertionDumps
assertions dump backtraces
Definition: Assertions.hpp:65
bool ExceptionDumps
if exception contructor should dump backtrace
Definition: Exception.hpp:34
PropertyList & add(const std::string &name, const boost::any &value)
adds a property to the list
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const
Implementation of QAbstractItemModel::rowCount().
Real e()
Definition of the Unit charge [C].
Definition: Consts.hpp:30
OptionStorage_t store
storage of options
Definition: OptionList.hpp:153
Manages the client root node.
Definition: TreeThread.hpp:37
BOOST_AUTO_TEST_CASE(init)
tuple model
Global confifuration.
virtual QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const
Gives header titles.
Top-level namespace for coolfluid.
Definition: Action.cpp:18
virtual QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const
Implementation of QAbstractItemModel::index().
static ExceptionManager & instance()
Gets the instance of the manager.
Definition: Exception.cpp:34
virtual QVariant data(const QModelIndex &index, int role) const
Destructor.
Handle< NRoot > root() const
Definition: TreeThread.hpp:59
unsigned int Uint
typedef for unsigned int
Definition: CF.hpp:90
SelectOptionType< T >::type & add(const std::string &name, const T &default_value=T())
Definition: OptionList.hpp:45
Most basic kernel library.
Definition: Action.cpp:19
PropertyStorage_t store
storage of options
Model that maintains properties for the node pointed by the index returned by NTree::global()->curren...
Send comments to:
COOLFluiD Web Admin