7 #define BOOST_TEST_DYN_LINK
8 #define BOOST_TEST_MODULE "Test module for the ui NLink class"
10 #include <QModelIndex>
29 Q_DECLARE_METATYPE(QModelIndex)
34 BOOST_AUTO_TEST_SUITE( uiCoreNLinkSuite )
42 ThreadManager::instance().tree();
54 boost::shared_ptr< NRoot >
root(
new NRoot(
"Root"));
55 boost::shared_ptr< NGeneric > target(
new NGeneric(
"Target",
"MyType"));
57 boost::shared_ptr< NLink > l1(
new NLink(
"Link1"));
58 boost::shared_ptr< NLink > l2(
new NLink(
"Link2"));
60 root->add_node(target);
63 l1->set_target_path(
"cpath:/Target");
65 BOOST_CHECK_EQUAL(l1->tool_tip().toStdString(), std::string(
"Target: /Target"));
66 BOOST_CHECK_EQUAL(l2->tool_tip().toStdString(), std::string(
"Target: <No target>"));
68 root->remove_node(
"Link1" );
69 root->remove_node(
"Target" );
76 boost::shared_ptr< NRoot >
root(
new NRoot(
"Root"));
77 boost::shared_ptr< NGeneric > target(
new NGeneric(
"Target",
"MyType"));
79 boost::shared_ptr< NLink > l1(
new NLink(
"Link1"));
80 boost::shared_ptr< NLink > l2(
new NLink(
"Link2"));
82 root->add_node(target);
85 l1->set_target_path(
"cpath:/Target");
87 BOOST_CHECK_EQUAL( l1->target_path().string(), std::string(
"cpath:/Target"));
88 BOOST_CHECK_EQUAL( l2->target_path().string(), std::string(
""));
90 root->remove_node(
"Link1" );
91 root->remove_node(
"Target" );
99 qRegisterMetaType<QModelIndex>(
"QModelIndex");
104 boost::shared_ptr< NGeneric > target(
new NGeneric(
"Target",
"MyType"));
105 boost::shared_ptr< NGeneric > wrongTargetParent(
new NGeneric(
"WrongTargetParent",
"MyType"));
106 boost::shared_ptr< NGeneric > wrongTarget(
new NGeneric(
"WrongTarget",
"MyType"));
107 wrongTargetParent->add_component(wrongTarget);
109 boost::shared_ptr< NLink > link(
new NLink(
"link"));
110 QSignalSpy spy(tree.
get(), SIGNAL(current_index_changed(QModelIndex,QModelIndex)));
118 BOOST_CHECK_THROW( link->go_to_target(frame) ,
ValueNotFound );
121 link->set_target_node(wrongTarget->handle<
NGeneric>());
122 BOOST_CHECK_THROW( link->go_to_target(frame) ,
ValueNotFound );
126 link->set_target_node(target->handle<
NGeneric>());
128 BOOST_REQUIRE_NO_THROW(link->go_to_target(frame));
130 BOOST_CHECK_EQUAL(spy.count(), 1);
133 BOOST_CHECK_EQUAL(qvariant_cast<QModelIndex>(spy.at(0).at(0)).internalPointer(), index.internalPointer());
144 boost::shared_ptr< NLink > link(
new NLink(
"link"));
149 BOOST_CHECK_THROW( link->set_target_path(
"cpath:/Unexisting/Component"),
InvalidURI );
152 BOOST_REQUIRE_NO_THROW( link->set_target_path(
"cpath:/UI/Log") );
153 BOOST_CHECK_EQUAL( link->target_path().string(), std::string(
"cpath:/UI/Log") );
163 boost::shared_ptr< NLink > link(
new NLink(
"link"));
164 boost::shared_ptr< NGeneric > target(
new NGeneric(
"Target",
"MyType"));
171 BOOST_CHECK_THROW( link->set_target_node( emptyTarget ),
FailedAssertion );
174 BOOST_REQUIRE_NO_THROW( link->set_target_node( target->handle<
NGeneric>() ) );
175 BOOST_CHECK_EQUAL( link->target_path().string(), std::string(
"cpath:/Target") );
178 tree->
tree_root()->remove_node(
"Target");
184 BOOST_AUTO_TEST_SUITE_END()
Client corresponding component for cf3::common::Link.
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.
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 ExceptionDumps
if exception contructor should dump backtrace
Handle< NRoot > tree_root() const
Gives the current root.
void set_current_index(const QModelIndex &newIndex)
Sets the current index.
Top-level namespace for coolfluid.
static ExceptionManager & instance()
Gets the instance of the manager.
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.
Client generic component.
Exception thrown when a string does not construct a valid path.
BOOST_AUTO_TEST_CASE(init)
Most basic kernel library.
void remove_node(const QString &node_name)
Removes a sub-node.
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.