#include #include #include #include #include namespace helpers { tResult AddExistingObjectToFilterGraph(adtf::ucom::iobject_ptr& graph, char const* name, adtf::ucom::iobject_ptr& object, int init_order) { RETURN_IF_FAILED(object->SetName(name)); return graph->AddNamedGraphObject(object, init_order); } tResult AddNewObjectToFilterGraph(adtf::ucom::iobject_ptr& graph, char const* name, char const* cid, int init_order) { adtf::ucom::object_ptr object; RETURN_IF_FAILED(_runtime->CreateInstance(cid, object)); return AddExistingObjectToFilterGraph(graph, name, object, init_order); } std::string ToTimeString(tTimeStamp const tm) { const int64_t ms_total = tm / 1000; const int64_t ms = ms_total % 1000; const int64_t s_total = ms_total / 1000; const int64_t s = s_total % 60; const int64_t m_total = s_total / 60; const int64_t m = m_total % 60; const int64_t h_total = m_total / 60; const int64_t h = h_total % 24; std::stringstream msg; msg << "[" << std::setw(2) << std::setfill('0') << h; msg << ":" << std::setw(2) << std::setfill('0') << m; msg << ":" << std::setw(2) << std::setfill('0') << s; msg << "." << std::setw(3) << std::setfill('0') << ms; msg << "]"; return msg.str(); } } class SenderFilter : public adtf::filter::cFilter { public: ADTF_CLASS_ID_NAME(SenderFilter, "senderfilter.test.cid", "SenderFilter"); SenderFilter() { adtf::ucom::object_ptr pType = adtf::ucom::make_object_ptr>(); writer = CreateOutputPin("output", pType); } tResult Init(cFilterLevelmachine::tInitStage eStage) override { RETURN_IF_FAILED(adtf::filter::cFilter::Init(eStage)); switch (eStage) { case cFilterLevelmachine::tInitStage::StageNormal: { adtf::ucom::object_ptr pType = adtf::ucom::make_object_ptr>(); writer->SetType(pType); break; } default: break; } return ERR_NOERROR; } template tResult SendSample(tTimeStamp tmSample, T value) { adtf::ucom::object_ptr pType = adtf::ucom::make_object_ptr>(); RETURN_IF_FAILED(writer->SetType(pType)); adtf::streaming::output_sample_data oOutputData(tmSample); oOutputData = value; std::stringstream msg; msg << helpers::ToTimeString(tmSample) << " " << __FUNCTION__ << "(" << value << ")"; LOG_INFO(msg.str().c_str()); RETURN_IF_FAILED(writer->Write(oOutputData.Release())); return writer->ManualTrigger(); } private: adtf::streaming::ISampleWriter* writer = nullptr; }; class ReceiverFilter : public adtf::filter::cFilter { public: ADTF_CLASS_ID_NAME(ReceiverFilter, "receiverfilter.test.cid", "ReceiverFilter"); ReceiverFilter() { reader = CreateInputPin("input"); } tResult AcceptType(adtf::streaming::ISampleReader* pReader, const adtf::ucom::ant::iobject_ptr& pType) override { ++acceptTypeCallCount; return ERR_NOERROR; } tResult ProcessInput(adtf::base::flash::tNanoSeconds tmTrigger, adtf::streaming::flash::ISampleReader* pReader) override { ++receivedSampleCount; return ERR_NOERROR; } private: adtf::streaming::ISampleReader* reader = nullptr; public: int acceptTypeCallCount = 0; int receivedSampleCount = 0; }; struct MyTestSystem: adtf::system::testing::cTestSystem { MyTestSystem() { LoadPlugin("default_core_objects.adtfplugin"); LoadPlugin("adtf_kernel.adtfplugin"); CreateService(CID_ADTF_KERNEL, "kernel", adtf::base::tADTFRunLevel::RL_System); LoadPlugin("adtf_clock.adtfplugin"); CreateService(CID_ADTF_REFERENCE_CLOCK, "reference_clock", adtf::base::tADTFRunLevel::RL_System); _runtime->SetRunLevel(adtf::base::tADTFRunLevel::RL_Session); } ~MyTestSystem() { _runtime->SetRunLevel(adtf::base::tADTFRunLevel::RL_Shutdown); } }; TEST_CASE_METHOD(MyTestSystem, "Connect") { adtf::ucom::object_ptr sender = adtf::ucom::make_object_ptr(); adtf::ucom::object_ptr receiver = adtf::ucom::make_object_ptr(); adtf::ucom::object_ptr graph(adtf::ucom::make_object_ptr()); REQUIRE_OK(helpers::AddExistingObjectToFilterGraph(graph, "Sender", adtf::ucom::ucom_object_ptr_cast(sender), 0)); REQUIRE_OK(helpers::AddExistingObjectToFilterGraph(graph, "Receiver", adtf::ucom::ucom_object_ptr_cast(receiver), 1)); REQUIRE_OK(helpers::AddNewObjectToFilterGraph(graph, "Stream", "default_sample_stream.streaming.adtf.cid", 2)); REQUIRE_OK(graph->AddConnection("SendToStream", "Sender", "output", "Stream", "", 0, true)); REQUIRE_OK(graph->AddConnection("SendToReceiver", "Stream", "", "Receiver", "input", 0, true)); REQUIRE_OK(graph->SetState(adtf::streaming::IFilterGraph::tFilterGraphState::State_Constructed)); REQUIRE_OK(graph->SetState(adtf::streaming::IFilterGraph::tFilterGraphState::State_Initialized)); REQUIRE_OK(graph->SetState(adtf::streaming::IFilterGraph::tFilterGraphState::State_Ready)); REQUIRE_OK(_runtime->SetRunLevel(adtf::base::tADTFRunLevel::RL_FilterGraph)); REQUIRE_OK(graph->SetState(adtf::streaming::IFilterGraph::tFilterGraphState::State_Running)); REQUIRE_OK(_runtime->SetRunLevel(adtf::base::tADTFRunLevel::RL_Running)); REQUIRE(0 == receiver->receivedSampleCount); sender->SendSample(0, int64_t(42)); REQUIRE(0 == receiver->acceptTypeCallCount); REQUIRE(1 == receiver->receivedSampleCount); }