7 #define BOOST_TEST_DYN_LINK
8 #define BOOST_TEST_MODULE "Test module for the ui NTree class"
10 #include <QModelIndex>
13 #include "rapidxml/rapidxml.hpp"
42 Q_DECLARE_METATYPE(QModelIndex)
48 static boost::shared_ptr< NRoot >
root = boost::dynamic_pointer_cast<
NRoot>(CNode::create_from_xml(doc->content->first_node(
"node")));
49 return root->handle<NRoot>();
55 BOOST_AUTO_TEST_SUITE( uiCoreNBrowserSuite )
63 ThreadManager::instance().tree();
75 NTree t(ThreadManager::instance().tree().
root());
83 BOOST_CHECK(t2.
tree_root().get() !=
nullptr);
90 NTree t(ThreadManager::instance().tree().
root());
91 boost::shared_ptr< NRoot > newRoot(
new NRoot(
"Root"));
92 QSignalSpy spy(&t, SIGNAL(layoutChanged()));
94 newRoot->create_component<
Link>(
"link");
103 BOOST_CHECK_EQUAL(spy.count(), 1);
109 BOOST_CHECK_EQUAL( t.
tree_root()->count_children(), std::size_t(5));
117 qRegisterMetaType<QModelIndex>(
"QModelIndex");
119 NTree t(ThreadManager::instance().tree().
root());
121 QSignalSpy spy(&t, SIGNAL(current_index_changed(QModelIndex,QModelIndex)));
131 BOOST_CHECK_EQUAL(spy.count(), 1);
134 arguments = spy.takeFirst();
135 BOOST_CHECK_EQUAL(qvariant_cast<QModelIndex>(arguments.at(0)).internalPointer(), t.
current_index().internalPointer());
136 BOOST_CHECK_EQUAL(qvariant_cast<QModelIndex>(arguments.at(1)).internalPointer(), index.internalPointer());
145 BOOST_CHECK_EQUAL(spy.count(), 0);
154 BOOST_CHECK_EQUAL(spy.count(), 1);
157 arguments = spy.takeFirst();
158 BOOST_CHECK_EQUAL(qvariant_cast<QModelIndex>(arguments.at(0)).internalPointer(), QModelIndex().internalPointer());
159 BOOST_CHECK_EQUAL(qvariant_cast<QModelIndex>(arguments.at(1)).internalPointer(), index.internalPointer());
166 NTree t(ThreadManager::instance().tree().
root());
167 QModelIndex rootIndex = t.
index(0, 0);
185 NTree t(ThreadManager::instance().tree().
root());
186 QModelIndex rootIndex = t.
index(0, 0);
189 BOOST_CHECK_EQUAL( t.
node_path( QModelIndex() ).toStdString(), std::string() );
192 BOOST_CHECK_EQUAL( t.
node_path( rootIndex ).toStdString(), std::string(
"Root/") );
195 BOOST_CHECK_EQUAL( t.
node_path( t.
index(0, 0, rootIndex) ).toStdString(), std::string(
"Root/UI/") );
202 NTree t(ThreadManager::instance().tree().
root());
203 QModelIndex rootIndex = t.
index(0, 0);
212 BOOST_CHECK_EQUAL( t.
pathFromIndex( t.
index(0, 0, rootIndex) ).
string(), std::string(
"cpath:/UI") );
220 NTree t(ThreadManager::instance().tree().
root());
221 boost::shared_ptr< MyNode > node(
new MyNode(
"UselessNode"));
231 BOOST_CHECK_EQUAL(options.count(), 0);
236 options.append( boost::shared_ptr<Option>(
new OptionT<bool>(
"opt1",
true)) );
237 options.append( boost::shared_ptr<Option>(
new OptionT<int>(
"opt2", 42)) );
241 BOOST_CHECK_EQUAL(options.count(), 0);
250 BOOST_CHECK(index.isValid());
255 BOOST_CHECK_EQUAL(options.count(), 3);
257 t.
tree_root()->remove_component(node->name());
264 NTree t(ThreadManager::instance().tree().
root());
265 QSignalSpy spy(&t, SIGNAL(advanced_mode_changed(
bool)));
281 BOOST_CHECK_EQUAL(spy.count(), 1);
284 arguments = spy.takeFirst();
285 BOOST_CHECK_EQUAL(arguments.at(0).toBool(),
true);
294 BOOST_CHECK_EQUAL(spy.count(), 1);
297 arguments = spy.takeFirst();
298 BOOST_CHECK_EQUAL(arguments.at(0).toBool(),
false);
305 NTree t(ThreadManager::instance().tree().
root());
306 QModelIndex index = t.
index(0, 0);
307 QModelIndex anotherIndex = t.
index(0, 0, index);
319 NTree t(ThreadManager::instance().tree().
root());
323 BOOST_CHECK(log_node.
get() ==
nullptr);
327 BOOST_REQUIRE_EQUAL(log_node.get(), NLog::global().get());
331 BOOST_CHECK_EQUAL(log_node->uri().path(), std::string(
CLIENT_LOG_PATH));
334 BOOST_REQUIRE_EQUAL(root.
get(), ThreadManager::instance().
tree().root().get());
343 NTree t(ThreadManager::instance().tree().
root());
344 QModelIndex rootIndex = t.
index(0, 0);
345 QModelIndex index = t.
index(0, 0, rootIndex);
352 BOOST_CHECK( foundRootIndex.isValid() );
353 BOOST_CHECK_EQUAL( foundRootIndex.internalPointer(), rootIndex.internalPointer() );
357 BOOST_CHECK( foundIndex.isValid() );
358 BOOST_CHECK_EQUAL( foundIndex.internalPointer(), index.internalPointer() );
362 BOOST_CHECK( !badIndex.isValid() );
366 BOOST_CHECK( !badIndexBis.isValid() );
376 NTree t(ThreadManager::instance().tree().
root());
378 QModelIndex logScndCol = t.
index(logIndex.row(), 1, logIndex.parent());
383 BOOST_CHECK( !t.
data(QModelIndex(), Qt::DisplayRole).isValid() );
389 BOOST_CHECK( !t.
data(logIndex, Qt::DisplayRole).isValid() );
390 BOOST_CHECK( !t.
data(logIndex, Qt::ToolTip).isValid() );
391 BOOST_CHECK( !t.
data(logScndCol, Qt::DisplayRole).isValid() );
392 BOOST_CHECK( !t.
data(logScndCol, Qt::ToolTip).isValid() );
400 QVariant logName = t.
data(logIndex, Qt::DisplayRole);
401 QVariant logToolTip = t.
data(logIndex, Qt::ToolTipRole);
402 QVariant logToolTipScndCol = t.
data(logScndCol, Qt::ToolTipRole);
405 BOOST_CHECK_EQUAL( logName.toString().toStdString(), std::string(
CLIENT_LOG) );
406 BOOST_CHECK_EQUAL( logToolTip.toString().toStdString(),
NLog().
tool_tip().toStdString() );
407 BOOST_CHECK_EQUAL( logToolTipScndCol.toString().toStdString(),
NLog().
tool_tip().toStdString() );
414 NTree t(ThreadManager::instance().tree().
root());
415 QModelIndex index = t.
index(0, 0);
418 BOOST_CHECK( index.isValid() );
421 BOOST_CHECK( t.
index(0, 1).isValid() );
424 BOOST_CHECK( t.
index(0, 0, index).isValid() );
427 BOOST_CHECK( !t.
index(12, 0, index).isValid() );
434 NTree t(ThreadManager::instance().tree().
root());
435 QModelIndex rootIndex = t.
index(0, 0);
436 QModelIndex childIndex = t.
index(0, 0, rootIndex);
438 BOOST_CHECK( !t.
parent(rootIndex).isValid() );
439 BOOST_CHECK_EQUAL( t.
parent(childIndex).internalPointer(), rootIndex.internalPointer() );
446 NTree t(ThreadManager::instance().tree().
root());
447 TreeThread & tree = ThreadManager::instance().tree();
450 BOOST_CHECK_EQUAL(t.
rowCount(t.
index(0, 0)), (
int) tree.
root()->count_children());
458 NTree t(ThreadManager::instance().tree().
root());
460 BOOST_CHECK_EQUAL(t.
headerData(0, Qt::Horizontal).toString().toStdString(), std::string(
"Name"));
461 BOOST_CHECK_EQUAL(t.
headerData(1, Qt::Horizontal).toString().toStdString(), std::string(
"Type"));
463 BOOST_CHECK(!t.
headerData(0, Qt::Vertical).isValid());
464 BOOST_CHECK(!t.
headerData(0, Qt::Horizontal, Qt::DecorationRole).isValid());
471 NTree t(ThreadManager::instance().tree().
root());
472 QSignalSpy spy(&t, SIGNAL(layoutChanged()));
480 BOOST_CHECK_EQUAL(spy.count(), 1);
488 boost::shared_ptr< NGeneric > node(
new NGeneric(
"ThisNodeShouldDisappear",
"MyType"));
492 boost::shared_ptr<Component> newRoot = allocate_component<Group>(
"Root");
494 newRoot->create_component<
Link>(
"Environment");
511 BOOST_CHECK_NO_THROW( root->
get_child(
"Environment") );
512 BOOST_CHECK_NO_THROW( root->
get_child(
"Tools") );
517 BOOST_CHECK_NO_THROW( uidir = root->
get_child(
"UI") );
518 BOOST_CHECK_NO_THROW( uidir->get_child(
"Browsers") );
519 BOOST_CHECK_NO_THROW( uidir->get_child(
"Log") );
520 BOOST_CHECK_NO_THROW( uidir->get_child(
"Plugins") );
521 BOOST_CHECK_NO_THROW( uidir->get_child(
"Tree") );
528 NTree t(ThreadManager::instance().tree().
root());
529 QSignalSpy spy(&t, SIGNAL(dataChanged(QModelIndex,QModelIndex)));
535 BOOST_CHECK_EQUAL( spy.count(), 0 );
539 BOOST_CHECK_EQUAL( spy.count(), 1 );
540 args = spy.takeFirst();
541 BOOST_CHECK_EQUAL( qvariant_cast<QModelIndex>(args.at(0)).internalPointer(), index.internalPointer() );
542 BOOST_CHECK_EQUAL( qvariant_cast<QModelIndex>(args.at(1)).internalPointer(), index.internalPointer() );
549 NTree t(ThreadManager::instance().tree().
root());
550 boost::shared_ptr< NGeneric > node(
new NGeneric(
"MyNode",
"MyType"));
555 t.
tree_root()->get_child(
"UI")->get_child(
"Log")->handle<
NLog>()->add_node( node );
562 BOOST_CHECK( !t.
node_matches(QModelIndex(), QRegExp(
"(nothing)")));
567 BOOST_CHECK( !t.
node_matches(rootIndex, QRegExp(
"Tree", Qt::CaseSensitive)) );
575 BOOST_CHECK( !t.
node_matches(rootIndex, QRegExp(
"tree", Qt::CaseSensitive)) );
577 BOOST_CHECK( t.
node_matches(rootIndex, QRegExp(
"tree", Qt::CaseInsensitive)) );
579 BOOST_CHECK( t.
node_matches(rootIndex, QRegExp(
"Tree", Qt::CaseSensitive)) );
585 BOOST_CHECK( !t.
node_matches(rootIndex, QRegExp(
"mynode", Qt::CaseSensitive)) );
587 BOOST_CHECK( t.
node_matches(rootIndex, QRegExp(
"mynode", Qt::CaseInsensitive)) );
589 BOOST_CHECK( t.
node_matches(rootIndex, QRegExp(
"MyNode", Qt::CaseSensitive)) );
596 NTree t(ThreadManager::instance().tree().
root());
597 boost::shared_ptr< NGeneric > node(
new NGeneric(
"Node",
"MyType"));
598 boost::shared_ptr< MyNode > myNode(
new MyNode(
"AnotherNode"));
635 myNode->mark_basic();
645 BOOST_AUTO_TEST_SUITE_END()
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const
Implementation of QAbstractItemModel::rowCount().
virtual QVariant data(const QModelIndex &index, int role) const
Implementation of QAbstractItemModel::data().
QApplication * application()
Safe pointer to an object. This is the supported method for referring to components.
virtual QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const
Implementation of QAbstractItemModel::index().
bool AssertionThrows
assertions throw exceptions
bool ExceptionOutputs
if exception contructor should output
static AssertionManager & instance()
Gets the instance of the manager.
void add_node(boost::shared_ptr< CNode > node)
Adds a sub-node.
void signal_list_tree(SignalArgs &args) const
lists the sub components and puts them on the xml_tree
Classes that implement the XML protocol for use in COOLFluiD.
Basic Classes for client-core library used by coolfluid-client application.
bool AssertionDumps
assertions dump backtraces
bool is_debug_mode_enabled() const
Indicates whether the debug mode is activated or not.
URI uri() const
Construct the full path.
bool ExceptionDumps
if exception contructor should dump backtrace
Handle< CNode > node_by_path(const cf3::common::URI &path) const
Retrieves a node from its path.
virtual QModelIndex parent(const QModelIndex &child) const
Implementation of QAbstractItemModel::parent()->
void set_advanced_mode(bool advanceMode)
Set advanced mode.
Handles a CNode component in the tree.
bool node_matches(const QModelIndex &index, const QRegExp ®ex) const
Checks whether a node name or one of its children matches a provided regular expression.
Handle< Component > get_child_checked(const std::string &name)
Handle< NRoot > tree_root() const
Gives the current root.
bool is_advanced_mode() const
Indicates whether advanced mode is activated or not.
QString node_path(const QModelIndex &index) const
Retrieves a node path.
void set_current_index(const QModelIndex &newIndex)
Sets the current index.
void set_tree_root(Handle< NRoot > node)
Replaces the current component tree.
bool are_from_same_node(const QModelIndex &left, const QModelIndex &right) const
Checks whether two indexes point to the same node.
void list_tree_reply(cf3::common::SignalArgs &node)
Signal called when the tree needs to be updated.
Manages the client root node.
Component for grouping other components.
virtual QString tool_tip() const
Gives the text to put on a tool tip.
Handle< Component > get_child(const std::string &name)
Top-level namespace for coolfluid.
Handle< NRoot > makeTreeFromFile()
std::string tree(bool basic_mode=false, Uint depth=0, Uint recursion_level=0) const
static ExceptionManager & instance()
Gets the instance of the manager.
QModelIndex current_index() const
Gives the current index.
SignalFrame get_reply() const
Handle< NRoot > root() const
void options_changed(const cf3::common::URI &path)
cf3::common::URI pathFromIndex(const QModelIndex &index) const
Gives the path of the provided index.
BOOST_AUTO_TEST_CASE(init)
Client root. This class is wrapper for cf3::common::Root class on the client side. A NRoot object may never have any child. Add them to the internal Root componenent instead. It can be obtained by calling root() method.
bool check_index_visible(const QModelIndex &index) const
Checks whether a nodeis visible or not.
Client generic component.
void set_debug_mode_enabled(bool debugMode)
Set the debug mode.
virtual QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const
Gives header titles.
void list_node_options(const QModelIndex &index, QList< boost::shared_ptr< cf3::common::Option > > &options, bool *ok=nullptr) const
Gets node options.
Handle< Component > create_component(const std::string &name, const std::string &builder)
Build a (sub)component of this component using the extended type_name of the component.
cf3::common::URI current_path() const
Gives the path of the current index.
Most basic kernel library.
std::string string() const
T * get() const
Raw pointer to the stored value, or null if there is none.
QModelIndex index_from_path(const cf3::common::URI &path) const
Retrieves a node index from its path.
boost::shared_ptr< XmlDoc > parse_file(const URI &file)