1
|
#include <adtffiltersdk/adtf_filtersdk.h>
|
2
|
#include <adtfsystemsdk/services/kernel_intf.h>
|
3
|
#include <adtfsystemsdk/testing/test_system.h>
|
4
|
#include <adtftesting/adtf_testing.h>
|
5
|
#include <iomanip>
|
6
|
|
7
|
namespace helpers
|
8
|
{
|
9
|
tResult AddExistingObjectToFilterGraph(adtf::ucom::iobject_ptr<adtf::streaming::cFilterGraph>& graph, char const* name, adtf::ucom::iobject_ptr<adtf::streaming::INamedGraphObject>& object, int init_order)
|
10
|
{
|
11
|
RETURN_IF_FAILED(object->SetName(name));
|
12
|
return graph->AddNamedGraphObject(object, init_order);
|
13
|
}
|
14
|
|
15
|
tResult AddNewObjectToFilterGraph(adtf::ucom::iobject_ptr<adtf::streaming::cFilterGraph>& graph, char const* name, char const* cid, int init_order)
|
16
|
{
|
17
|
adtf::ucom::object_ptr<adtf::streaming::INamedGraphObject> object;
|
18
|
RETURN_IF_FAILED(_runtime->CreateInstance(cid, object));
|
19
|
return AddExistingObjectToFilterGraph(graph, name, object, init_order);
|
20
|
}
|
21
|
|
22
|
std::string ToTimeString(tTimeStamp const tm)
|
23
|
{
|
24
|
const int64_t ms_total = tm / 1000;
|
25
|
const int64_t ms = ms_total % 1000;
|
26
|
const int64_t s_total = ms_total / 1000;
|
27
|
const int64_t s = s_total % 60;
|
28
|
const int64_t m_total = s_total / 60;
|
29
|
const int64_t m = m_total % 60;
|
30
|
const int64_t h_total = m_total / 60;
|
31
|
const int64_t h = h_total % 24;
|
32
|
std::stringstream msg;
|
33
|
msg << "[" << std::setw(2) << std::setfill('0') << h;
|
34
|
msg << ":" << std::setw(2) << std::setfill('0') << m;
|
35
|
msg << ":" << std::setw(2) << std::setfill('0') << s;
|
36
|
msg << "." << std::setw(3) << std::setfill('0') << ms;
|
37
|
msg << "]";
|
38
|
return msg.str();
|
39
|
}
|
40
|
}
|
41
|
|
42
|
class SenderFilter : public adtf::filter::cFilter
|
43
|
{
|
44
|
public:
|
45
|
ADTF_CLASS_ID_NAME(SenderFilter,
|
46
|
"senderfilter.test.cid",
|
47
|
"SenderFilter");
|
48
|
|
49
|
SenderFilter()
|
50
|
{
|
51
|
adtf::ucom::object_ptr<adtf::streaming::IStreamType> pType = adtf::ucom::make_object_ptr<adtf::streaming::stream_type_plain<tInt16>>();
|
52
|
writer = CreateOutputPin("output", pType);
|
53
|
}
|
54
|
|
55
|
tResult Init(cFilterLevelmachine::tInitStage eStage) override
|
56
|
{
|
57
|
RETURN_IF_FAILED(adtf::filter::cFilter::Init(eStage));
|
58
|
|
59
|
switch (eStage)
|
60
|
{
|
61
|
case cFilterLevelmachine::tInitStage::StageNormal:
|
62
|
{
|
63
|
adtf::ucom::object_ptr<adtf::streaming::IStreamType> pType = adtf::ucom::make_object_ptr<adtf::streaming::stream_type_plain<tInt32>>();
|
64
|
writer->SetType(pType);
|
65
|
break;
|
66
|
}
|
67
|
default:
|
68
|
break;
|
69
|
}
|
70
|
return ERR_NOERROR;
|
71
|
}
|
72
|
|
73
|
template<typename T>
|
74
|
tResult SendSample(tTimeStamp tmSample, T value)
|
75
|
{
|
76
|
adtf::ucom::object_ptr<adtf::streaming::IStreamType> pType = adtf::ucom::make_object_ptr<adtf::streaming::stream_type_plain<tInt64>>();
|
77
|
RETURN_IF_FAILED(writer->SetType(pType));
|
78
|
adtf::streaming::output_sample_data<T> oOutputData(tmSample);
|
79
|
oOutputData = value;
|
80
|
std::stringstream msg;
|
81
|
msg << helpers::ToTimeString(tmSample) << " " << __FUNCTION__ << "(" << value << ")";
|
82
|
LOG_INFO(msg.str().c_str());
|
83
|
RETURN_IF_FAILED(writer->Write(oOutputData.Release()));
|
84
|
return writer->ManualTrigger();
|
85
|
}
|
86
|
|
87
|
private:
|
88
|
adtf::streaming::ISampleWriter* writer = nullptr;
|
89
|
};
|
90
|
|
91
|
class ReceiverFilter : public adtf::filter::cFilter
|
92
|
{
|
93
|
public:
|
94
|
ADTF_CLASS_ID_NAME(ReceiverFilter,
|
95
|
"receiverfilter.test.cid",
|
96
|
"ReceiverFilter");
|
97
|
|
98
|
ReceiverFilter()
|
99
|
{
|
100
|
reader = CreateInputPin("input");
|
101
|
}
|
102
|
|
103
|
tResult AcceptType(adtf::streaming::ISampleReader* pReader,
|
104
|
const adtf::ucom::ant::iobject_ptr<const adtf::streaming::IStreamType>& pType) override
|
105
|
{
|
106
|
++acceptTypeCallCount;
|
107
|
return ERR_NOERROR;
|
108
|
}
|
109
|
|
110
|
tResult ProcessInput(adtf::base::flash::tNanoSeconds tmTrigger,
|
111
|
adtf::streaming::flash::ISampleReader* pReader) override
|
112
|
{
|
113
|
++receivedSampleCount;
|
114
|
return ERR_NOERROR;
|
115
|
}
|
116
|
|
117
|
private:
|
118
|
adtf::streaming::ISampleReader* reader = nullptr;
|
119
|
|
120
|
public:
|
121
|
int acceptTypeCallCount = 0;
|
122
|
int receivedSampleCount = 0;
|
123
|
};
|
124
|
|
125
|
struct MyTestSystem: adtf::system::testing::cTestSystem
|
126
|
{
|
127
|
MyTestSystem()
|
128
|
{
|
129
|
LoadPlugin("default_core_objects.adtfplugin");
|
130
|
LoadPlugin("adtf_kernel.adtfplugin");
|
131
|
CreateService(CID_ADTF_KERNEL,
|
132
|
"kernel",
|
133
|
adtf::base::tADTFRunLevel::RL_System);
|
134
|
LoadPlugin("adtf_clock.adtfplugin");
|
135
|
CreateService(CID_ADTF_REFERENCE_CLOCK,
|
136
|
"reference_clock",
|
137
|
adtf::base::tADTFRunLevel::RL_System);
|
138
|
_runtime->SetRunLevel(adtf::base::tADTFRunLevel::RL_Session);
|
139
|
}
|
140
|
|
141
|
~MyTestSystem()
|
142
|
{
|
143
|
_runtime->SetRunLevel(adtf::base::tADTFRunLevel::RL_Shutdown);
|
144
|
}
|
145
|
};
|
146
|
|
147
|
TEST_CASE_METHOD(MyTestSystem, "Connect")
|
148
|
{
|
149
|
adtf::ucom::object_ptr<SenderFilter> sender = adtf::ucom::make_object_ptr<SenderFilter>();
|
150
|
adtf::ucom::object_ptr<ReceiverFilter> receiver = adtf::ucom::make_object_ptr<ReceiverFilter>();
|
151
|
|
152
|
adtf::ucom::object_ptr<adtf::streaming::cFilterGraph> graph(adtf::ucom::make_object_ptr<adtf::streaming::cFilterGraph>());
|
153
|
REQUIRE_OK(helpers::AddExistingObjectToFilterGraph(graph, "Sender", adtf::ucom::ucom_object_ptr_cast<adtf::streaming::INamedGraphObject>(sender), 0));
|
154
|
REQUIRE_OK(helpers::AddExistingObjectToFilterGraph(graph, "Receiver", adtf::ucom::ucom_object_ptr_cast<adtf::streaming::INamedGraphObject>(receiver), 1));
|
155
|
REQUIRE_OK(helpers::AddNewObjectToFilterGraph(graph, "Stream", "default_sample_stream.streaming.adtf.cid", 2));
|
156
|
REQUIRE_OK(graph->AddConnection("SendToStream", "Sender", "output", "Stream", "", 0, true));
|
157
|
REQUIRE_OK(graph->AddConnection("SendToReceiver", "Stream", "", "Receiver", "input", 0, true));
|
158
|
REQUIRE_OK(graph->SetState(adtf::streaming::IFilterGraph::tFilterGraphState::State_Constructed));
|
159
|
REQUIRE_OK(graph->SetState(adtf::streaming::IFilterGraph::tFilterGraphState::State_Initialized));
|
160
|
REQUIRE_OK(graph->SetState(adtf::streaming::IFilterGraph::tFilterGraphState::State_Ready));
|
161
|
REQUIRE_OK(_runtime->SetRunLevel(adtf::base::tADTFRunLevel::RL_FilterGraph));
|
162
|
|
163
|
REQUIRE_OK(graph->SetState(adtf::streaming::IFilterGraph::tFilterGraphState::State_Running));
|
164
|
REQUIRE_OK(_runtime->SetRunLevel(adtf::base::tADTFRunLevel::RL_Running));
|
165
|
|
166
|
REQUIRE(0 == receiver->receivedSampleCount);
|
167
|
|
168
|
sender->SendSample(0, int64_t(42));
|
169
|
|
170
|
REQUIRE(0 == receiver->acceptTypeCallCount);
|
171
|
REQUIRE(1 == receiver->receivedSampleCount);
|
172
|
}
|