7 #define BOOST_TEST_DYN_LINK
8 #define BOOST_TEST_MODULE "Test module for CF log level filter"
10 #include <boost/test/unit_test.hpp>
11 #include <boost/bind.hpp>
12 #include <boost/function.hpp>
13 #include <boost/foreach.hpp>
14 #include <boost/assign/std/vector.hpp>
15 #include <boost/date_time/gregorian/gregorian.hpp>
16 #include <boost/date_time/posix_time/posix_time.hpp>
35 using namespace boost;
47 typedef boost::shared_ptr<MyC>
Ptr;
65 options().add (
"OptBool",
false ).description(
"bool option");
66 options().add (
"OptInt", -5 ).description(
"int option");
67 options().add (
"OptUInt", 10u ).description(
"Uint option");
68 options().add (
"OptReal", 0.0 ).description(
"real option");
69 options().add (
"OptStr", std::string(
"LOLO") ).description(
"string option");
70 options().add (
"OptURI",
URI(
"cpath:/lolo") ).description(
"URI option");
74 def += 1,2,3,4,5,6,7,8,9;
75 options().add(
"VecInt", def ).description(
"vector ints option");
78 std::vector< std::string > defs;
79 defs +=
"lolo",
"koko";
80 options().add(
"VecStr", defs ).description(
"vector strs option");;
84 options()[
"OptInt"].link_to( &m_i );
86 options().link_to_parameter (
"OptStr", &m_str );
88 options()[
"OptBool"].attach_trigger( boost::bind ( &
MyC::config_bool,
this ) );
89 options()[
"OptInt"].attach_trigger ( boost::bind ( &
MyC::config_int,
this ) );
90 options()[
"OptStr"].attach_trigger ( boost::bind ( &
MyC::config_str,
this ) );
92 options()[
"OptURI"].attach_trigger ( boost::bind ( &
MyC::config_uri,
this ) );
94 std::vector<int> vi = options().value< std::vector<int> >(
"VecInt");
99 .description(
"component option");
100 options().link_to_parameter (
"OptC", &m_component_lnk );
102 opt2->description(
"component option");
103 options().add(opt2).link_to( &m_component_lnk2 ).mark_basic();
105 Option& opt3 = options().add(
"OptC3",m_component);
113 BOOST_CHECK(options().value<bool>(
"OptBool") == boost::any_cast<bool>(options().option(
"OptBool").value()));
118 BOOST_CHECK(options().value<int>(
"OptInt") == boost::any_cast<int>(options().option(
"OptInt").value()));
123 BOOST_CHECK(options().value<std::string>(
"OptStr") == boost::any_cast<std::string>(options().option(
"OptStr").value()));
128 BOOST_CHECK(options().value< std::vector<int> >(
"VecInt") == boost::any_cast< std::vector<int> >(options().option(
"VecInt").value()));
133 BOOST_CHECK(options().value<URI>(
"OptURI") == boost::any_cast<URI>(options().option(
"OptURI").value()));
139 BOOST_AUTO_TEST_SUITE( Config_TestSuite )
145 boost::gregorian::date today = boost::gregorian::day_clock::local_day();
146 boost::posix_time::ptime now = boost::posix_time::second_clock::local_time();
150 boost::shared_ptr<MyC> pm ( allocate_component<MyC>(
"LOLO") );
161 boost::gregorian::date today = boost::gregorian::day_clock::local_day();
162 boost::posix_time::ptime now = boost::posix_time::second_clock::local_time();
164 CFinfo <<
"starting [" << today <<
"] [" << now <<
"]" <<
CFendl;
167 boost::shared_ptr<MyC> pm ( allocate_component<MyC>(
"LOLO") );
170 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
171 "<cfxml version=\"1.0\">"
174 " <value key=\"options\">"
177 "<value key=\"OptBool\"> <bool> 1 </bool> </value>"
178 "<value key=\"OptInt\" > <integer> -156 </integer> </value>"
179 "<value key=\"OptUInt\" > <unsigned> 134 </unsigned> </value>"
180 "<value key=\"OptReal\" > <real> 6.4564E+5 </real> </value>"
181 "<value key=\"OptStr\" > <string> lolo </string> </value>"
183 "<ignore> popo </ignore>"
185 "<value key=\"OptPath\"> <path> /opt/path </path> </value>"
187 "<value key=\"OptDate\"> <date> 2010-05-24 </date> </value>"
189 "<value key=\"OptData\" > <data> PEKBpYGlmYFCPA== </data> </value>"
191 "<map key=\"OptList\" desc=\"sub set\" mode=\"advanced\" >"
192 " <value key=\"mi\"> <integer> 2 </integer> </value>"
193 " <value key=\"mr\"> <real> 8 </real> </value>"
194 " <value key=\"mb\"> <bool> 1 </bool> </value>"
197 "<array key=\"VecInt\" type=\"integer\" size=\"3\" delimiter=\" ; \" > 2 ; 8 ; 9</array>"
199 "<array key=\"VecStr\" type=\"string\" size=\"2\" delimiter=\" ; \">aabbcc ; ddeeff</array>"
210 XmlNode doc = Protocol::goto_doc_node(*xml.get());
211 SignalFrame frame( Protocol::first_frame_node( doc ) );
215 pm->signal_configure( frame );
217 BOOST_CHECK ( pm->options().value<
bool>(
"OptBool") );
218 BOOST_CHECK_EQUAL ( pm->options().option(
"OptBool").value_str() ,
"true" );
220 BOOST_CHECK_EQUAL ( pm->options().value<
int>(
"OptInt"), -156 );
221 BOOST_CHECK_EQUAL ( pm->options().option(
"OptInt").value_str() ,
"-156" );
223 BOOST_CHECK_EQUAL ( pm->options().value<
Uint>(
"OptUInt"), (
Uint) 134 );
224 BOOST_CHECK_EQUAL ( pm->options().option(
"OptUInt").value_str() ,
"134" );
226 BOOST_CHECK_EQUAL ( pm->options().value<Real>(
"OptReal"), 6.4564E+5 );
229 BOOST_CHECK_EQUAL ( pm->options().value<std::string>(
"OptStr"),
"lolo" );
230 BOOST_CHECK_EQUAL ( pm->options().option(
"OptStr").value_str(),
"lolo" );
232 std::vector<int> vecint(3);
236 BOOST_CHECK ( pm->options().value<std::vector<int> >(
"VecInt") == vecint);
238 std::vector<std::string> vecstr(2);
241 BOOST_CHECK ( pm->options().value<std::vector<std::string> >(
"VecStr") == vecstr);
253 boost::shared_ptr<Group>
root = allocate_component<Group>(
"root");
258 component1->
options().
set(
"MyRelativeFriend",
URI(
"cpath:../component2"));
259 component1->options().set(
"MyAbsoluteFriend",
URI(
"cpath:/component2"));
262 URI absolute_friend_path = component1->options().value<
URI>(
"MyAbsoluteFriend");
263 Handle<CConcrete1> absolute_friend(component1->access_component(absolute_friend_path));
264 BOOST_CHECK_EQUAL(absolute_friend->name(),
"component2");
266 URI relative_friend_path = component1->options().value<
URI>(
"MyRelativeFriend");
267 Handle<CConcrete1> relative_friend(component1->access_component(relative_friend_path));
268 BOOST_CHECK_EQUAL(relative_friend->name(),
"component2");
283 BOOST_CHECK( component1->
comp() == component2 );
298 BOOST_AUTO_TEST_SUITE_END()
300 Adds fonctionnalities to Property class.
Handle< CConcrete1 > m_component_lnk
#define CFinfo
these are always defined
std::string name(ComponentWrapper &self)
const Handle< CConcrete1 > & comp()
external boost library namespace
MyC(const std::string &name)
boost::shared_ptr< XmlDoc > parse_string(const std::string &str)
static string type_name()
boost::shared_ptr< MyC > Ptr
Uniform Resource Identifier (see http://en.wikipedia.org/wiki/Uniform_Resource_Identifier) ...
Top-level namespace for coolfluid.
const TYPE value(const std::string &opt_name) const
Get the value of the option with given name.
Handle< CConcrete1 > m_component
virtual std::string value_str() const =0
BOOST_AUTO_TEST_CASE(add_options_to)
unsigned int Uint
typedef for unsigned int
Handle< CConcrete1 > m_component_lnk2
Option & description(const std::string &description)
Sets the option description.
external library used for XML parsing
Base class for defining CF components.
boost::shared_ptr< MyC const > CosntPtr
void set(const std::string &pname, const boost::any &val)
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.