COOLFluiD  Release kernel
COOLFluiD is a Collaborative Simulation Environment (CSE) focused on complex MultiPhysics simulations.
utest-signals.cpp
Go to the documentation of this file.
1 // Copyright (C) 2010-2013 von Karman Institute for Fluid Dynamics, Belgium
2 //
3 // This software is distributed under the terms of the
4 // GNU Lesser General Public License version 3 (LGPLv3).
5 // See doc/lgpl.txt and doc/gpl.txt for the license text.
6 
7 #define BOOST_TEST_DYN_LINK
8 #define BOOST_TEST_MODULE "Test module for CF signals"
9 
10 #include <boost/test/unit_test.hpp>
11 
12 #include "common/Signal.hpp"
13 #include "common/LibCommon.hpp"
14 #include "common/Builder.hpp"
15 #include "common/Log.hpp"
16 #include "common/OptionT.hpp"
17 #include "common/Group.hpp"
18 
20 
21 using namespace std;
22 using namespace boost;
23 using namespace cf3;
24 using namespace cf3::common;
25 using namespace cf3::common::XML;
26 
28 
29 
32 class CSmall : public Component
33 {
34 public: // functions
35 
38  CSmall ( const std::string& name ) : Component ( name )
39  {
40  this->regist_signal( "print_message" )
41  .description("prints")
42  .pretty_name("").connect ( boost::bind ( &CSmall::print_message, this, _1 ) );
43  }
44 
46  virtual ~CSmall() {}
47 
49  static std::string type_name () { return "CSmall"; }
50 
52  {
53  SignalFrame signal_frame;
54 
55  SignalOptions options;
56 
57  options.add( "Counter", 10 );
58 
59  signal_frame = options.create_frame("Target", "/", "/");
60 
61  receiver.call_signal( "print_message", signal_frame );
62  }
63 
65  {
66  SignalFrame signal_frame( "list_tree", uri(), receiver.uri());
67 
68  receiver.call_signal( "list_tree", signal_frame );
69 
70 // XmlOps::print_xml_node( *signal_frame.document() );
71  }
72 
74 
75 
77  void print_message ( SignalArgs& args )
78  {
79 // XmlParams p (xml);
80 
81  // CFinfo << "Component [" << name() << "] received counter [" << p.get_option<int>("Counter") << "]" << CFendl;
82  }
83 
85 
86 }; // CSmall
87 
89 
91 
93 {
96 
99 
100 };
101 
103 
104 BOOST_FIXTURE_TEST_SUITE( TestSignals_TestSuite, TestSignals_Fixture )
105 
106 
108 BOOST_AUTO_TEST_CASE( simple_signal )
109 {
110  boost::shared_ptr<Group> root = allocate_component<Group>("root");
111 
112  boost::shared_ptr<CSmall> small_1 ( allocate_component<CSmall> ( "small-1" ) );
113  boost::shared_ptr<CSmall> small_2 ( allocate_component<CSmall> ( "small-2" ) );
114 
115  root->add_component(small_1);
116  small_1->add_component(small_2);
117 
118  small_1->trigger_signal_print_message ( *small_2.get() );
119 
120  small_2->trigger_signal_list_tree( *root.get() );
121 }
122 
124 
125 BOOST_AUTO_TEST_SUITE_END()
126 
127 
virtual ~CSmall()
Virtual destructor.
Abstracts the use of XML when adding options to a signal frame.
std::string name(ComponentWrapper &self)
common::ComponentBuilder< CSmall, Component, LibCommon > CSmall_Builder
external boost library namespace
Helper class to create the Builder and place it in the factory.
Definition: Builder.hpp:212
TestSignals_Fixture()
common setup for each test case
Classes that implement the XML protocol for use in COOLFluiD.
Definition: Component.hpp:43
CSmall(const std::string &name)
URI uri() const
Construct the full path.
Definition: Component.cpp:248
STL namespace.
common::URI uri(ComponentWrapper &self)
tuple root
Definition: coolfluid.py:24
SignalFrame create_frame(const std::string &name=std::string(), const URI &sender=URI(), const URI &receiver=URI()) const
Creates a frame and puts the options in an "options" map.
void trigger_signal_list_tree(Component &receiver)
Manages a set of maps.
Definition: SignalFrame.hpp:31
static std::string type_name()
Get the class name.
BOOST_AUTO_TEST_CASE(simple_signal)
Top-level namespace for coolfluid.
Definition: Action.cpp:18
SignalRet call_signal(const SignalID &sname, SignalArgs &sinput)
Calls the signal by providing its name and input.
void trigger_signal_print_message(Component &receiver)
void print_message(SignalArgs &args)
creates a component from this component
SelectOptionType< T >::type & add(const std::string &name, const T &default_value=T())
Definition: OptionList.hpp:45
Base class for defining CF components.
Definition: Component.hpp:82
Most basic kernel library.
Definition: Action.cpp:19
~TestSignals_Fixture()
common tear-down for each test case
Send comments to:
COOLFluiD Web Admin