ADTF  3.13.0
Test for Demo Data Trigger Plugin
Description
This examples test the Demo Data Trigger Plugin
Location
./src/examples/src/adtf/filters/standard_filters/data_triggered_filter/test/
Build Environment
To see how to set up the build environment have a look at ADTF CMake Environment
this implementation shows:
Implementation
#include "../demo_data_trigger_function.h"
{
cMyTestSystem()
{
LoadPlugin("demo_data_triggered_filter.adtfplugin");
}
};
adtf::ucom::object_ptr<adtf::streaming::IFilter> create_filter(cSimpleDataCalculator::tOperator eOperator)
{
REQUIRE_OK(_runtime->CreateInstance("demo_data_trigger.filter.adtf.cid", pFilter));
auto pConfiguration = adtf::ucom::ucom_cast<adtf::base::IConfiguration*>(pFilter.Get());
adtf::base::set_property_by_path<tUInt32>(*pConfiguration, "calculator_function/operator", eOperator);
return pFilter;
}
tVoid test_calculation(cSimpleDataCalculator::tOperator eOperator, tFloat32 fExpectedResult)
{
auto pFilter = create_filter(eOperator);
adtf::filter::testing::cOutputRecorder oOutput(pFilter, "out");
oWriter1.Write<tFloat32>(4.0, tTrue);
oWriter2.Write<tFloat32>(2.0, tTrue);
auto oOutputSamples = oOutput.GetCurrentOutput().GetSamples();
REQUIRE(oOutputSamples.size() == 1);
REQUIRE(adtf::streaming::sample_data<tFloat32>(oOutputSamples.back()) == Approx(fExpectedResult));
}
TEST_CASE_METHOD(cMyTestSystem, "Test Addition")
{
test_calculation(cSimpleDataCalculator::tOperator::ePLUS, 6.0);
}
TEST_CASE_METHOD(cMyTestSystem, "Test Substraction")
{
test_calculation(cSimpleDataCalculator::tOperator::eMINUS, 2.0);
}
TEST_CASE_METHOD(cMyTestSystem, "Test Multiplication")
{
test_calculation(cSimpleDataCalculator::tOperator::eMULTI, 8.0);
}
TEST_CASE_METHOD(cMyTestSystem, "Test Division")
{
test_calculation(cSimpleDataCalculator::tOperator::eDIVIDE, 2.0);
}
TEST_CASE_METHOD(cMyTestSystem, "Test Invalid Operator")
{
auto pFilter = create_filter(static_cast<cSimpleDataCalculator::tOperator>(cSimpleDataCalculator::tOperator::eDIVIDE + 1));
REQUIRE(ERR_INVALID_ARG == pFilter->SetState(adtf::streaming::IFilter::tFilterState::State_Running));
}

Copyright © Audi Electronics Venture GmbH. All rights reserved. (Generated on Tue Sep 28 2021 by doxygen 1.8.14)