Main Page
Related Pages
Modules
Namespaces
Classes
Files
Examples
File List
File Members
tests
service_port_test.cpp
Go to the documentation of this file.
1
2
#include <
TaskContext.hpp
>
3
#include <
InputPort.hpp
>
4
#include <
OutputPort.hpp
>
5
#include <
Service.hpp
>
6
#include <
ServiceRequester.hpp
>
7
8
#include "
unit.hpp
"
9
#include "
operations_fixture.hpp
"
10
11
struct
ServicePortFixture
{};
12
13
// Registers the suite into the 'registry'
14
BOOST_FIXTURE_TEST_SUITE
( ServicePortTestSuite,
ServicePortFixture
)
15
16
20
class
TestService
: public
Service
{
21
public
:
22
InputPort<int>
ip
;
23
InputPort<int>
ip2
;
24
OutputPort<int>
op
;
25
TestService
(
TaskContext
* owner = 0) :
Service
(
"portservice"
, owner)
26
{
27
addPort(
"ip"
,ip).
doc
(
"ip"
);
28
addPort(
"ip"
,ip2).doc(
"ip"
);
// overrides ip
29
addPort(
"op"
,op).doc(
"op"
);
30
}
31
};
32
33
class
TestEventService
:
public
Service
{
34
public
:
35
InputPort<int>
ip
;
36
InputPort<int>
ip2
;
37
OutputPort<int>
op
;
38
TestEventService
(
TaskContext
* owner = 0) :
Service
(
"portservice"
, owner)
39
{
40
addEventPort(
"ip"
,ip).
doc
(
"ip"
);
41
addEventPort(
"ip"
,ip2).doc(
"ip"
);
// overrides ip
42
addPort(
"op"
,op).doc(
"op"
);
43
}
44
};
45
46
BOOST_AUTO_TEST_CASE
(testAddPort)
47
{
48
TestService
* ts =
new
TestService
();
49
Service::shared_ptr
s( ts );
50
TaskContext
tc(
"tc"
);
51
52
tc.
provides
()->addService( s );
53
54
// check that last port is the real thing:
55
BOOST_CHECK( tc.
provides
(
"portservice"
)->getPort(
"ip"
) == &ts->
ip2
);
56
57
BOOST_CHECK( tc.
provides
(
"portservice"
)->getPort(
"op"
) == &ts->
op
);
58
}
59
60
BOOST_AUTO_TEST_CASE
(testAddPortWithOwner)
61
{
62
TaskContext
tc(
"tc"
);
63
TestService
* ts =
new
TestService
( &tc );
64
Service::shared_ptr
s( ts );
65
66
tc.
provides
()->addService( s );
67
68
// check that last port is the real thing:
69
BOOST_CHECK( tc.
provides
(
"portservice"
)->getPort(
"ip"
) == &ts->
ip2
);
70
71
BOOST_CHECK( tc.
provides
(
"portservice"
)->getPort(
"op"
) == &ts->
op
);
72
}
73
74
75
BOOST_AUTO_TEST_CASE
(testAddEventPort)
76
{
77
TestEventService
* ts =
new
TestEventService
();
78
Service::shared_ptr
s( ts );
79
TaskContext
tc(
"tc"
);
80
81
tc.
provides
()->addService( s );
82
83
// check that last port is the real thing:
84
BOOST_CHECK( tc.
provides
(
"portservice"
)->getPort(
"ip"
) == &ts->
ip2
);
85
86
BOOST_CHECK( tc.
provides
(
"portservice"
)->getPort(
"op"
) == &ts->
op
);
87
}
88
89
BOOST_AUTO_TEST_CASE
(testAddEventPortWithOwner)
90
{
91
TaskContext
tc(
"tc"
);
92
TestEventService
* ts =
new
TestEventService
(&tc);
93
Service::shared_ptr
s( ts );
94
95
tc.
provides
()->addService( s );
96
97
// check that last port is the real thing:
98
BOOST_CHECK( tc.
provides
(
"portservice"
)->getPort(
"ip"
) == &ts->
ip2
);
99
100
BOOST_CHECK( tc.
provides
(
"portservice"
)->getPort(
"op"
) == &ts->
op
);
101
}
102
103
104
#ifndef ORO_DISABLE_PORT_DATA_SCRIPTING
105
106
BOOST_AUTO_TEST_CASE
(testUsePort)
107
{
108
TestService
* ts =
new
TestService
();
109
// should work because TestService already adds itself to children... but this memleaks
110
Service::shared_ptr
s1 = ts->
provides
();
111
// should work as well because TestService inherits from enable_shared_from_raw :
112
Service::shared_ptr
s( ts );
113
TaskContext
tc(
"tc"
);
114
115
tc.
provides
()->addService( s );
116
117
ts->
ip2
.
connectTo
( &ts->
op
);
118
119
// use operation interface of port:
120
BOOST_REQUIRE( tc.
provides
()->hasService(
"portservice"
) );
121
BOOST_REQUIRE( tc.
provides
(
"portservice"
)->hasService(
"op"
) );
122
BOOST_REQUIRE( tc.
provides
(
"portservice"
)->provides(
"op"
)->hasOperation(
"write"
) );
123
124
OperationCaller<WriteStatus(int const&)>
write = tc.
provides
(
"portservice"
)->provides(
"op"
)->getOperation(
"write"
);
125
BOOST_CHECK( write.ready() );
126
BOOST_CHECK_EQUAL( write( 3 ),
WriteSuccess
);
127
128
int
result;
129
OperationCaller<FlowStatus(int&)>
read = tc.
provides
(
"portservice"
)->provides(
"ip"
)->getOperation(
"read"
);
130
BOOST_CHECK( read.
ready
() );
131
FlowStatus
fs = read( result );
132
BOOST_CHECK_EQUAL( result, 3);
133
BOOST_CHECK_EQUAL( fs,
NewData
);
134
}
135
136
BOOST_AUTO_TEST_CASE
(testUsePortWithOwner)
137
{
138
TaskContext
tc(
"tc"
);
139
TestService
* ts =
new
TestService
(&tc);
140
Service::shared_ptr
s( ts );
141
142
tc.
provides
()->addService( s );
143
144
ts->
ip2
.
connectTo
( &ts->
op
);
145
146
// use operation interface of port:
147
OperationCaller<void(int const&)>
write = tc.
provides
(
"portservice"
)->provides(
"op"
)->getOperation(
"write"
);
148
BOOST_CHECK( write.
ready
() );
149
write( 3 );
150
151
int
result;
152
OperationCaller<FlowStatus(int&)>
read = tc.
provides
(
"portservice"
)->provides(
"ip"
)->getOperation(
"read"
);
153
BOOST_CHECK( read.
ready
() );
154
FlowStatus
fs = read( result );
155
BOOST_CHECK_EQUAL( result, 3);
156
BOOST_CHECK_EQUAL( fs,
NewData
);
157
}
158
159
#endif
160
161
BOOST_AUTO_TEST_SUITE_END
()
BOOST_FIXTURE_TEST_SUITE
#define BOOST_FIXTURE_TEST_SUITE(suite_name, F)
Definition:
unit_test_suite.hpp:53
RTT::Service::provides
Service::shared_ptr provides()
Definition:
Service.cpp:113
RTT::TaskContext::provides
Service::shared_ptr provides()
Definition:
TaskContext.hpp:258
RTT::OperationCaller::ready
bool ready() const
Definition:
OperationCaller.hpp:326
WriteSuccess
Definition:
dataflow_performance_test.cpp:296
BOOST_AUTO_TEST_SUITE_END
#define BOOST_AUTO_TEST_SUITE_END()
Definition:
unit_test_suite.hpp:62
RTT::FlowStatus
FlowStatus
Definition:
FlowStatus.hpp:56
TestEventService::op
OutputPort< int > op
Definition:
service_port_test.cpp:37
RTT::InputPort< int >
TestEventService::ip
InputPort< int > ip
Definition:
service_port_test.cpp:35
RTT::NewData
Definition:
FlowStatus.hpp:56
RTT::Service::shared_ptr
boost::shared_ptr< Service > shared_ptr
Definition:
Service.hpp:101
RTT::Service
Definition:
Service.hpp:93
unit.hpp
TestService::op
OutputPort< int > op
Definition:
service_port_test.cpp:24
TestService::TestService
TestService(TaskContext *owner=0)
Definition:
service_port_test.cpp:25
RTT::OperationCaller
Definition:
OperationCaller.hpp:82
ServiceRequester.hpp
Service.hpp
OutputPort.hpp
BOOST_AUTO_TEST_CASE
BOOST_AUTO_TEST_CASE(testAddPort)
Definition:
service_port_test.cpp:46
RTT::Service::doc
const std::string & doc() const
Definition:
Service.hpp:144
TaskContext.hpp
RTT::base::InputPortInterface::connectTo
virtual bool connectTo(PortInterface *other, ConnPolicy const &policy)
Definition:
InputPortInterface.cpp:86
InputPort.hpp
TestEventService::TestEventService
TestEventService(TaskContext *owner=0)
Definition:
service_port_test.cpp:38
TestService::ip2
InputPort< int > ip2
Definition:
service_port_test.cpp:23
RTT::TaskContext
Definition:
TaskContext.hpp:93
RTT::OutputPort< int >
operations_fixture.hpp
ServicePortFixture
Definition:
service_port_test.cpp:11
TestEventService::ip2
InputPort< int > ip2
Definition:
service_port_test.cpp:36
TestService
Definition:
service_port_test.cpp:20
TestEventService
Definition:
service_port_test.cpp:33
TestService::ip
InputPort< int > ip
Definition:
service_port_test.cpp:22
rtt
Author(s): RTT Developers
autogenerated on Fri Oct 25 2019 03:59:35