COOLFluiD  Release kernel
COOLFluiD is a Collaborative Simulation Environment (CSE) focused on complex MultiPhysics simulations.
utest-action-director.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 ActionDirector"
9 
10 #include <iostream>
11 
12 #include <boost/test/unit_test.hpp>
13 
14 #include "common/CF.hpp"
16 #include "common/Core.hpp"
17 #include "common/Foreach.hpp"
18 #include "common/URI.hpp"
19 
20 using namespace cf3;
21 using namespace cf3::common;
22 
24 
25 BOOST_AUTO_TEST_SUITE( ActionDirectorSuite )
26 
27 
31 {
32  typedef boost::shared_ptr<SetIntegerAction> Ptr;
33  typedef boost::shared_ptr<SetIntegerAction const> ConstPtr;
34  SetIntegerAction(const std::string& name) : Action(name) {}
35  static std::string type_name () { return "SetIntegerAction"; }
36  virtual void execute()
37  {
38  ++value;
39  }
40 
41  static Uint value;
42 };
43 
45 
46 BOOST_AUTO_TEST_CASE(ActionDirectorBasic)
47 {
49  Handle<ActionDirector> director = root.create_component<ActionDirector>("director");
50  Handle<SetIntegerAction> test_action = director->create_component<SetIntegerAction>("testaction");
51 
52  director->execute();
53  BOOST_CHECK_EQUAL(test_action->value, 1);
54 }
55 
56 BOOST_AUTO_TEST_CASE(ActionDirectorAppend)
57 {
59 
60  Handle<ActionDirector> director(root.get_child("director"));
61  Handle<SetIntegerAction> test_action2 = director->create_component<SetIntegerAction>("testaction2");
62 
63  BOOST_CHECK_EQUAL(test_action2->value, 1);
64  director->execute();
65  BOOST_CHECK_EQUAL(test_action2->value, 3);
66 }
67 
68 BOOST_AUTO_TEST_CASE(ActionDirectorStream)
69 {
71 
72  Handle<ActionDirector> director(root.get_child("director"));
73 
74  boost::shared_ptr<SetIntegerAction> test_action3_shared = allocate_component<SetIntegerAction>("testaction3");
75  Handle<SetIntegerAction> test_action3_handle(test_action3_shared);
76  SetIntegerAction& test_action3_ref = *test_action3_handle;
77 
78  // Overloaded shift-left operator for easy chaining of actions
79  *director << test_action3_shared << test_action3_handle << test_action3_ref;
80 
81  BOOST_CHECK_EQUAL(test_action3_handle->value, 3);
82  director->execute();
83  BOOST_CHECK_EQUAL(test_action3_handle->value, 8);
84 }
85 
87 
88 BOOST_AUTO_TEST_SUITE_END()
89 
90 
std::string name(ComponentWrapper &self)
Safe pointer to an object. This is the supported method for referring to components.
Definition: Handle.hpp:39
boost::shared_ptr< SetIntegerAction const > ConstPtr
BOOST_AUTO_TEST_CASE(ActionDirectorBasic)
static std::string type_name()
tuple root
Definition: coolfluid.py:24
SetIntegerAction(const std::string &name)
Uniform Resource Identifier (see http://en.wikipedia.org/wiki/Uniform_Resource_Identifier) ...
virtual void execute()
execute the action
Handle< Component > get_child(const std::string &name)
Definition: Component.cpp:441
Action that sets an integer, for testing purposes.
Top-level namespace for coolfluid.
Definition: Action.cpp:18
Component that executes an action. Implementation of the IAction interface as a component, exposing the execute function as a signal.
Definition: Action.hpp:21
common::Component & root() const
Gives the default root component.
Definition: Core.cpp:145
unsigned int Uint
typedef for unsigned int
Definition: CF.hpp:90
coolfluid3 header, included almost everywhere
boost::shared_ptr< SetIntegerAction > Ptr
static Core & instance()
Definition: Core.cpp:37
virtual void execute()
Execute all active child actions.
Base class for defining CF components.
Definition: Component.hpp:82
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.
Definition: Component.cpp:568
Most basic kernel library.
Definition: Action.cpp:19
Send comments to:
COOLFluiD Web Admin