7 #define BOOST_TEST_DYN_LINK
8 #define BOOST_TEST_MODULE "Test module for the ui CNode class"
12 #include <boost/assign/list_of.hpp>
14 #include "rapidxml/rapidxml.hpp"
54 static boost::shared_ptr< NRoot >
root = boost::dynamic_pointer_cast<
NRoot>(CNode::create_from_xml(doc->content->first_node(
"node")));
61 BOOST_AUTO_TEST_SUITE( uiCoreCNodeSuite )
69 ThreadManager::instance().tree();
71 AssertionManager::instance().AssertionDumps =
false;
72 AssertionManager::instance().AssertionThrows =
true;
73 ExceptionManager::instance().ExceptionDumps =
false;
74 ExceptionManager::instance().ExceptionOutputs =
false;
83 BOOST_CHECK_EQUAL( node.
component_type().toStdString(), std::string(
"MyNode") );
90 boost::shared_ptr<MyNode> node(
new MyNode(
"Node"));
91 boost::shared_ptr<NBrowser> browser(
new NBrowser());
92 boost::shared_ptr<NGeneric>
group(
new NGeneric(
"Group",
"MyType"));
93 boost::shared_ptr<NLink> link(
new NLink(
"Link"));
94 boost::shared_ptr<NLog> log(
new NLog());
95 boost::shared_ptr<NGeneric>
mesh(
new NGeneric(
"Mesh",
"MyType"));
96 boost::shared_ptr<NGeneric> method(
new NGeneric(
"Method",
"MyType"));
97 boost::shared_ptr<NRoot>
root(
new NRoot(
"Root"));
98 boost::shared_ptr<NTree> tree(
new NTree(root->handle<
NRoot>()));
100 BOOST_CHECK( browser->is_local_component() );
101 BOOST_CHECK( !group->is_local_component() );
102 BOOST_CHECK( !link->is_local_component() );
103 BOOST_CHECK( log->is_local_component() );
104 BOOST_CHECK( !mesh->is_local_component() );
105 BOOST_CHECK( !method->is_local_component() );
106 BOOST_CHECK( !root->is_local_component() );
107 BOOST_CHECK( node->is_local_component() );
108 BOOST_CHECK( tree->is_local_component() );
121 " <value key=\"properties\">"
123 " <value key=\"pi\" descr=\"Pi value\" is_option=\"true\">"
124 " <real>3.141592</real>"
126 " <value key=\"fakePi\" descr=\"Pi value in an unknown type\" is_option=\"true\">"
127 " <type>3.141592</type>"
141 " <value key=\"properties\">"
143 " <value key=\"prop\">"
144 " <string>Hello, World!</string>"
146 " <value key=\"anotherProp\" is_option=\"false\">"
147 " <bool>false</bool>"
149 " <value key=\"pi\" descr=\"Pi value\" is_option=\"true\">"
150 " <real>3.141592</real>"
169 BOOST_REQUIRE_NO_THROW( prop = node.
properties()[
"prop"] );
171 BOOST_CHECK_EQUAL(
any_type(prop), std::string(common::class_name<std::string>()) );
173 BOOST_CHECK_EQUAL( any_to_value<std::string>(prop), std::string(
"Hello, World!") );
179 BOOST_REQUIRE_NO_THROW( prop = node.
properties()[
"anotherProp"] );
191 BOOST_REQUIRE_NO_THROW(
Option & opt = node.
options()[
"pi"] );
209 " <value key=\"signals\">"
210 " <map key=\"my_signal1\" name=\"My signal 1\" descr=\"This is a 1st signal\" hidden=\"false\"/>"
211 " <map key=\"my_signal2\" name=\"My signal 2\" descr=\"This is a 2nd signal\" hidden=\"true\"/>"
212 " <map key=\"my_signal3\" name=\"My signal 3\" descr=\"This is a 3rd signal\"/>"
213 " <map key=\"my_signal4\" name=\"My signal 4\"/>"
214 " <map key=\"my_signal5\"/>"
221 int sigCount = list.size();
223 SignalFrame frame(sigs->content->first_node(
"node"));
228 BOOST_CHECK_EQUAL( list.size(), sigCount + 4 );
234 " <value key=\"signals\">"
240 SignalFrame frame2(sigs->content->first_node(
"node"));
246 BOOST_CHECK_EQUAL( list.size(), sigCount );
252 " <value key=\"signals\">"
258 SignalFrame frame3(sigs->content->first_node(
"node"));
271 BOOST_CHECK_EQUAL( node.
options().
value<
int>(
"theAnswer"),
int(42) );
272 BOOST_CHECK_EQUAL( node.
options().
value<
bool>(
"someBool"),
true );
273 BOOST_CHECK_EQUAL( node.
options().
value<std::string>(
"myString"), std::string(
"This is a string") );
274 BOOST_CHECK_EQUAL( node.
properties().
value<Real>(
"someProp"), Real(3.14) );
277 map[
"someBool"] = QVariant(
false).toString();
278 map[
"theAnswer"] = QString::number(-45782446);
280 BOOST_CHECK_EQUAL( node.
options().
value<
int>(
"theAnswer"),
int(-45782446) );
281 BOOST_CHECK_EQUAL( node.
options().
value<
bool>(
"someBool"),
false );
282 BOOST_CHECK_EQUAL( node.
options().
value<std::string>(
"myString"), std::string(
"This is a string") );
283 BOOST_CHECK_EQUAL( node.
properties().
value<Real>(
"someProp"), Real(3.14) );
286 map[
"someProp"] = QString::number(2.71);
291 map[
"optionThatDoesNotExist"] =
"Hello, World!";
296 map[
"theAnswer"] = QString::number(2.15467654);
304 boost::shared_ptr< MyNode > node(
new MyNode(
"MyNode") );
306 int itemCount = list.
store.size() + node->options().store.size();
308 PropertyList::PropertyStorage_t::iterator it = list.
begin();
310 node->list_properties( map );
312 BOOST_CHECK_EQUAL( itemCount, map.size() );
314 for( ; it != list.
end() ; ++it )
315 BOOST_CHECK( map.contains( it->first.c_str() ) );
328 BOOST_CHECK_EQUAL( options.size(), 3 );
341 BOOST_REQUIRE_NO_THROW(node = root->
get_child(
"Tools") );
349 boost::shared_ptr< NRoot >
root(
new NRoot(
"Root"));
350 boost::shared_ptr< NGeneric > node(
new NGeneric(
"Node",
"NGeneric"));
351 boost::shared_ptr< NLog > log(
new NLog() );
352 QSignalSpy rootSpy(root->notifier(), SIGNAL(child_count_changed()));
353 QSignalSpy nodeSpy(node->notifier(), SIGNAL(child_count_changed()));
355 BOOST_REQUIRE_NO_THROW( root->add_node(node));
357 BOOST_REQUIRE_NO_THROW( root->access_component(
"cpath:/Node")->handle<
NGeneric>() );
359 BOOST_CHECK_EQUAL(rootSpy.count(), 1);
361 BOOST_REQUIRE_NO_THROW( node->add_node(log) );
362 BOOST_REQUIRE_NO_THROW( node->access_component(
"cpath:/Node/" CLIENT_LOG)->handle<
NLog>() );
364 BOOST_CHECK_EQUAL(nodeSpy.count(), 1);
371 boost::shared_ptr< NRoot >
root(
new NRoot(
"Root"));
372 boost::shared_ptr< NGeneric > node(
new NGeneric(
"Node",
"NGeneric"));
373 boost::shared_ptr< NLog > log(
new NLog() );
376 root->add_node(node);
379 QSignalSpy rootSpy(root->notifier(), SIGNAL(child_count_changed()));
380 QSignalSpy nodeSpy(node->notifier(), SIGNAL(child_count_changed()));
382 BOOST_REQUIRE_NO_THROW( root->remove_node(
"Node"));
384 BOOST_CHECK_EQUAL( root->access_component(
"cpath:/Node").get(), nullComp);
386 BOOST_CHECK_EQUAL(rootSpy.count(), 1);
388 BOOST_REQUIRE_NO_THROW( node->remove_node(
CLIENT_LOG ) );
389 BOOST_CHECK_EQUAL( root->access_component(
"cpath:/Node/" CLIENT_LOG ).get(), nullComp );
391 BOOST_CHECK_EQUAL( nodeSpy.count(), 1 );
414 boost::shared_ptr< NRoot >
root(
new NRoot(
"Root"));
415 boost::shared_ptr< NLog > log(
new NLog());
416 boost::shared_ptr< NTree > tree(
new NTree(root->handle<
NRoot>()));
417 boost::shared_ptr< NGeneric > node1(
new NGeneric(
"Node1",
"NGeneric"));
418 boost::shared_ptr< NGeneric > node2(
new NGeneric(
"Node2",
"NGeneric"));
419 boost::shared_ptr< NGeneric > node3(
new NGeneric(
"Node3",
"NGeneric"));
420 boost::shared_ptr< NGeneric > node4(
new NGeneric(
"Node4",
"NGeneric"));
421 boost::shared_ptr< NGeneric > node5(
new NGeneric(
"Node5",
"NGeneric"));
424 root->add_node(node2);
425 root->add_node(node5);
427 log->add_node(node1);
429 node2->add_node(node3);
430 node2->add_node(tree);
431 node2->add_node(node4);
436 root->list_child_paths(list,
true,
true);
438 BOOST_CHECK_EQUAL( list.count(), 8);
441 BOOST_CHECK_EQUAL( list.at(0).toStdString(), std::string(
"/") );
442 BOOST_CHECK_EQUAL( list.at(1).toStdString(), std::string(
"/Log") );
443 BOOST_CHECK_EQUAL( list.at(2).toStdString(), std::string(
"/Log/Node1") );
444 BOOST_CHECK_EQUAL( list.at(3).toStdString(), std::string(
"/Node2") );
445 BOOST_CHECK_EQUAL( list.at(4).toStdString(), std::string(
"/Node2/Node3") );
446 BOOST_CHECK_EQUAL( list.at(5).toStdString(), std::string(
"/Node2/Tree") );
447 BOOST_CHECK_EQUAL( list.at(6).toStdString(), std::string(
"/Node2/Node4") );
448 BOOST_CHECK_EQUAL( list.at(7).toStdString(), std::string(
"/Node5") );
455 root->list_child_paths(list,
true,
false);
457 BOOST_CHECK_EQUAL( list.count(), 5);
459 BOOST_CHECK_EQUAL( list.at(0).toStdString(), std::string(
"/") );
460 BOOST_CHECK_EQUAL( list.at(1).toStdString(), std::string(
"/Node2") );
461 BOOST_CHECK_EQUAL( list.at(2).toStdString(), std::string(
"/Node2/Node3") );
462 BOOST_CHECK_EQUAL( list.at(3).toStdString(), std::string(
"/Node2/Node4") );
463 BOOST_CHECK_EQUAL( list.at(4).toStdString(), std::string(
"/Node5") );
470 root->list_child_paths(list,
false,
true);
472 BOOST_CHECK_EQUAL( list.count(), 4);
474 BOOST_CHECK_EQUAL( list.at(0).toStdString(), std::string(
"/") );
475 BOOST_CHECK_EQUAL( list.at(1).toStdString(), std::string(
"/Log") );
476 BOOST_CHECK_EQUAL( list.at(2).toStdString(), std::string(
"/Node2") );
477 BOOST_CHECK_EQUAL( list.at(3).toStdString(), std::string(
"/Node5") );
485 root->list_child_paths(list,
false,
false);
487 BOOST_CHECK_EQUAL( list.count(), 3);
489 BOOST_CHECK_EQUAL( list.at(0).toStdString(), std::string(
"/") );
490 BOOST_CHECK_EQUAL( list.at(1).toStdString(), std::string(
"/Node2") );
491 BOOST_CHECK_EQUAL( list.at(2).toStdString(), std::string(
"/Node5") );
498 node2->list_child_paths(list,
true,
true);
500 BOOST_CHECK_EQUAL( list.count(), 4);
503 BOOST_CHECK_EQUAL( list.at(0).toStdString(), std::string(
"/Node2") );
504 BOOST_CHECK_EQUAL( list.at(1).toStdString(), std::string(
"/Node2/Node3") );
505 BOOST_CHECK_EQUAL( list.at(2).toStdString(), std::string(
"/Node2/Tree") );
506 BOOST_CHECK_EQUAL( list.at(3).toStdString(), std::string(
"/Node2/Node4") );
511 BOOST_AUTO_TEST_SUITE_END()
Adds fonctionnalities to Property class.
std::string class_name_from_typeinfo(const std::type_info &info)
Client corresponding component for cf3::common::Link.
std::string any_type(const boost::any &value)
Gives the demangled type string of a boost::any value.
boost::shared_ptr< XmlDoc > parse_cstring(const char *str, std::size_t length)
QApplication * application()
Safe pointer to an object. This is the supported method for referring to components.
Common_TEMPLATE template bool any_to_value< bool >(const boost::any &)
Classes that implement the XML protocol for use in COOLFluiD.
Basic Classes for client-core library used by coolfluid-client application.
void set_properties(const common::SignalArgs &node)
QString component_type() const
Component that manages remote browsers. This class subclasses CNode class.
Handle< NRoot > makeTreeFromFile()
void set_signals(const common::SignalArgs &node)
PropertyList & properties()
TYPE value(const std::string &pname) const
Handle< Component > get_child(const std::string &name)
Top-level namespace for coolfluid.
const TYPE value(const std::string &opt_name) const
Get the value of the option with given name.
void modify_options(const QMap< QString, QString > &options)
Modifies options.
static boost::proto::terminal< ExpressionGroupTag >::type group
Use group(expr1, expr2, ..., exprN) to evaluate a group of expressions.
void list_signals(QList< ActionInfo > &actions)
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.
Handle< Component > handle()
Get a handle to the component.
BOOST_AUTO_TEST_CASE(init)
Base class for defining CF components.
void map(Field &field, Eigen::Map< Derived > &v, const Uint row_idx, const Uint var_idx)
void list_options(QList< boost::shared_ptr< common::Option > > &list)
Most basic kernel library.
PropertyStorage_t store
storage of options
boost::shared_ptr< XmlDoc > parse_file(const URI &file)