7 #define BOOST_TEST_DYN_LINK
8 #define BOOST_TEST_MODULE "Test module for cf3::Component"
10 #include <boost/test/unit_test.hpp>
12 #include <boost/foreach.hpp>
13 #include <boost/iterator.hpp>
27 using namespace boost;
34 BOOST_AUTO_TEST_SUITE( Component_TestSuite )
41 boost::shared_ptr<Component>
root = boost::static_pointer_cast<
Component>(allocate_component<Group>(
"root"));
43 BOOST_CHECK_EQUAL ( root->name() ,
"root" );
44 BOOST_CHECK_EQUAL ( root->uri().base_path().string() ,
"cpath:/" );
45 BOOST_CHECK_EQUAL ( root->uri().string() ,
"cpath:/" );
47 BOOST_CHECK_EQUAL ( root->properties().check(
"brief") , true );
48 BOOST_CHECK_EQUAL ( root->properties().check(
"description") , true );
51 boost::shared_ptr<Group> dir1 = allocate_component<Group>(
"dir1" );
53 BOOST_CHECK_EQUAL ( dir1->name() ,
"dir1" );
54 BOOST_CHECK_EQUAL ( dir1->uri().base_path().string() ,
"cpath:/" );
55 BOOST_CHECK_EQUAL ( dir1->uri().string() ,
"cpath:/" );
58 boost::shared_ptr<Link> lnk = allocate_component<Link>(
"lnk" );
60 BOOST_CHECK_EQUAL ( lnk->name() ,
"lnk" );
61 BOOST_CHECK_EQUAL ( lnk->uri().base_path().string() ,
"cpath:/" );
62 BOOST_CHECK_EQUAL ( lnk->uri().string() ,
"cpath:/" );
69 boost::shared_ptr<Component>
root = boost::static_pointer_cast<
Component>(allocate_component<Group>(
"root"));
71 boost::shared_ptr<Component> dir1 = allocate_component<Group>(
"dir1" );
72 boost::shared_ptr<Component> dir2 = allocate_component<Group>(
"dir2" );
74 root->add_component( dir1 );
75 dir1->add_component( dir2 );
77 BOOST_CHECK_EQUAL ( root->uri().string() ,
"cpath:/" );
78 BOOST_CHECK_EQUAL ( dir1->uri().string() ,
"cpath:/dir1" );
79 BOOST_CHECK_EQUAL ( dir2->uri().string() ,
"cpath:/dir1/dir2" );
86 boost::shared_ptr<Component>
root = boost::static_pointer_cast<
Component>(allocate_component<Group>(
"root"));
88 boost::shared_ptr<Component> dir1 = allocate_component<Group>(
"dir1" );
89 boost::shared_ptr<Component> lnk1 = allocate_component<Link>(
"lnk1" );
92 root->add_component( dir1 );
93 root->add_component( lnk1 );
96 boost::shared_ptr<Link> p_lnk1 = boost::dynamic_pointer_cast<
Link>(lnk1);
100 BOOST_CHECK_EQUAL (
follow_link(*root)->name(),
"root" );
101 BOOST_CHECK_EQUAL (
follow_link(*root)->uri().string(),
"cpath:/" );
104 BOOST_CHECK_EQUAL ( lnk1->name(),
"lnk1" );
105 BOOST_CHECK_EQUAL ( lnk1->uri().string(),
"cpath:/lnk1" );
108 BOOST_CHECK_EQUAL (
follow_link(*lnk1)->name(),
"dir1" );
109 BOOST_CHECK_EQUAL (
follow_link(*lnk1)->uri().string(),
"cpath:/dir1" );
117 boost::shared_ptr<Component>
root = boost::static_pointer_cast<
Component>(allocate_component<Group>(
"root"));
119 boost::shared_ptr<Component> dir1 = allocate_component<Group>(
"dir1" );
120 boost::shared_ptr<Component> dir2 = allocate_component<Group>(
"dir2" );
121 boost::shared_ptr<Component> dir3 = allocate_component<Group>(
"dir3" );
124 root->add_component( dir1 );
125 dir1->add_component( dir2 );
126 dir2->add_component( dir3 );
129 URI p0 (
"cpath:/dir1" );
130 dir2->complete_path( p0 );
131 BOOST_CHECK_EQUAL ( p0.
string(),
"cpath:/dir1" );
134 URI p10 (
"cpath:.." );
135 dir2->complete_path( p10 );
136 BOOST_CHECK_EQUAL ( p10.string(),
"cpath:/dir1" );
139 URI p11 (
"cpath:./" );
140 dir2->complete_path( p11 );
141 BOOST_CHECK_EQUAL ( p11.string(),
"cpath:/dir1/dir2" );
144 URI p12 (
"cpath:../../dir2" );
145 dir3->complete_path( p12 );
146 BOOST_CHECK_EQUAL ( p12.string(),
"cpath:/dir1/dir2" );
149 URI p2 (
"cpath:/dir1/dir2/../dir2" );
150 dir2->complete_path( p2 );
151 BOOST_CHECK_EQUAL ( p2.string(),
"cpath:/dir1/dir2" );
154 URI p3 (
"cpath:/dir1/../dir1/../dir1/dir2/../../dir1/dir2" );
155 dir2->complete_path( p3 );
156 BOOST_CHECK_EQUAL ( p3.string(),
"cpath:/dir1/dir2" );
159 URI p4 (
"cpath:/dir1/dir2/dir3/../../" );
160 dir2->complete_path( p4 );
161 BOOST_CHECK_EQUAL ( p4.string(),
"cpath:/dir1" );
169 boost::shared_ptr<Component>
root = boost::static_pointer_cast<
Component>(allocate_component<Group>(
"root"));
171 boost::shared_ptr<Component> dir1 = allocate_component<Group>(
"dir1" );
172 boost::shared_ptr<Component> dir2 = allocate_component<Group>(
"dir2" );
173 boost::shared_ptr<Component> dir21 = allocate_component<Group>(
"dir21" );
174 boost::shared_ptr<Component> dir22 = allocate_component<Group>(
"dir22" );
177 root->add_component( dir1 );
178 dir1->add_component( dir2 );
179 dir2->add_component( dir21 );
180 dir2->add_component( dir22 );
183 URI p0 (
"cpath:../dir21" );
185 BOOST_CHECK_EQUAL ( cp0->
uri().
string(),
"cpath:/dir1/dir2/dir21" );
188 URI p1 (
"cpath:/dir1" );
190 BOOST_CHECK_EQUAL ( cp1->
uri().
string(),
"cpath:/dir1" );
197 boost::shared_ptr<Component>
root = boost::static_pointer_cast<
Component>(allocate_component<Group>(
"root"));
199 boost::shared_ptr<Component> dir1 = allocate_component<Group>(
"dir1" );
200 boost::shared_ptr<Component> dir2 = allocate_component<Group>(
"dir2" );
203 root->add_component( dir1 );
204 dir1->add_component( dir2 );
206 BOOST_CHECK_EQUAL ( dir2->uri().string(),
"cpath:/dir1/dir2" );
208 dir2->move_to( *root );
210 BOOST_CHECK_EQUAL ( dir2->uri().string(),
"cpath:/dir2" );
218 boost::shared_ptr<Component>
root = allocate_component<Group> (
"Simulator" );
222 BOOST_CHECK_EQUAL ( proot->uri().string(),
"cpath:/" );
230 boost::shared_ptr<Component>
root = boost::static_pointer_cast<
Component>(allocate_component<Group>(
"root"));
243 boost::shared_ptr<Component>
root = allocate_component<Group> (
"croot" );
247 sf.set_option(
"name", common::class_name<std::string>(),
"MyMesh" );
248 sf.set_option(
"atype", common::class_name<std::string>(),
"MeshReader" );
249 sf.set_option(
"ctype", common::class_name<std::string>(),
"CGNS" );
260 boost::shared_ptr<Component>
root = allocate_component<Group> (
"Simulator" );
264 BOOST_CHECK_EQUAL ( c1->name(),
"c1" );
268 BOOST_CHECK_EQUAL ( c2->name(),
"c1_1" );
272 BOOST_CHECK_EQUAL ( c3->name(),
"c1_2" );
275 ExceptionManager::instance().ExceptionDumps =
false;
277 BOOST_CHECK_NO_THROW (c2->rename(
"c1_3"));
285 boost::shared_ptr<Component>
root = allocate_component<Group> (
"Simulator" );
300 BOOST_AUTO_TEST_SUITE_END()
302 std::string name(ComponentWrapper &self)
BOOST_AUTO_TEST_CASE(constructors)
bool is_null(T ptr)
predicate for comparison to nullptr
Safe pointer to an object. This is the supported method for referring to components.
external boost library namespace
Link & link_to(Component &lnkto)
Classes that implement the XML protocol for use in COOLFluiD.
URI uri() const
Construct the full path.
Holds the Component class, as well as the ComponentIterator class plus some functions related to comp...
ComponentReference< Component >::type find_component_recursively_with_name(Component &parent, StringConverter name)
ComponentReference< Component >::type find_component_with_name(Component &parent, StringConverter name)
Top-level namespace for coolfluid.
Base class for defining CF components.
Handle< Component > follow_link(const Handle< Component > &link_or_comp)
Follow links or return the component itself if it's not a link.
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.
Most basic kernel library.
std::string string() const
bool is_not_null(T ptr)
predicate for comparison to nullptr