ADTF  3.18.2
cSessionTestSystem

This class allows you to create a test system based on an ADTF session. More...

Inheritance diagram for cSessionTestSystem:
[legend]

Public Member Functions

 cSessionTestSystem (const std::string &strUrl="", const std::string &strAdtfDirectory=ADTF_TESTING_ADTF_DIR, const std::string &strPluginDirectories=ADTF_TESTING_PLUGIN_DIRECTORIES)
 Constructs a test system. More...
 
 cSessionTestSystem (const std::string &strUrl, bool bCreateLoggingService, const std::string &strAdtfDirectory=ADTF_TESTING_ADTF_DIR, const std::string &strPluginDirectories=ADTF_TESTING_PLUGIN_DIRECTORIES)
 Constructs a test system. More...
 
void SetEnvironmentFile (const std::string &strFileName)
 Set the adtfenvironment. More...
 
void CreateSession (const std::string &strFileName)
 Load and create a session. More...
 
void Exec (std::chrono::microseconds tmTimeout)
 Executes a session for a given amount of time. More...
 
void Exec (int8_t nInitialRunlevel, std::function< void()> fnStartup)
 Executes a session and call the a callback function when ready. More...
 
void ExecTest (int8_t nInitialRunlevel, std::function< void()> fnTest)
 Execute a session, call a test function and shutdown the session afterwards. More...
 
ucom::ant::object_ptr< services::ant::ISessionGetSession ()
 
ucom::ant::object_ptr< streaming::ant::IStreamingGraphGetStreamingGraph ()
 
ucom::ant::object_ptr< streaming::ant::IFilterGraphGetFilterGraph ()
 
ucom::ant::object_ptr< streaming::ant::INamedGraphObjectGetGraphObject (const std::string &name)
 Retrieve a graph object from the streaming/filter graph. More...
 
- Public Member Functions inherited from cTestSystem
 cTestSystem (const std::string &strUrl="", const std::vector< std::string > &oPlugins={}, bool bCreateSessionManager=false, const std::string &strAdtfDirectory=ADTF_TESTING_ADTF_DIR, const std::string &strPluginDirectories=ADTF_TESTING_PLUGIN_DIRECTORIES)
 Constructs a test system. More...
 
 cTestSystem (const std::string &strUrl, const std::vector< std::string > &oPlugins, bool bCreateSessionManager, bool bCreateLoggingService, const std::string &strAdtfDirectory=ADTF_TESTING_ADTF_DIR, const std::string &strPluginDirectories=ADTF_TESTING_PLUGIN_DIRECTORIES)
 Constructs a test system. More...
 
 ~cTestSystem ()
 Destructor.
 
void SetRunLevel (base::ant::tADTFRunLevel eRunlevel)
 Helper function that changes the runlevel and throws errors via an exception. More...
 
base::ant::tADTFRunLevel GetRunLevel () const
 Helper function that returns the current runlevel. More...
 
void LoadPlugin (const std::string &strPluginFileName, bool bCreateServices=true, base::ant::tADTFRunLevel nServicesRunlevel=base::tADTFRunLevel::RL_System)
 Load a plugin and optionally create instances of all found ADTF Service classes. More...
 
ucom::ant::object_ptr< ucom::ant::IServiceCreateService (const std::string &strClassId, const std::string &strObjectId, base::ant::tADTFRunLevel nRunlevel=base::tADTFRunLevel::RL_System)
 Create a service instance. More...
 
ucom::ant::object_ptr< ucom::ant::IServiceCreateService (const std::string &strPluginFileName, const std::string &strClassId, const std::string &strObjectId, base::ant::tADTFRunLevel nRunlevel=base::tADTFRunLevel::RL_System)
 Loads a plugin and creates a service instance. More...
 
ucom::ant::object_ptr< ucom::ant::IServiceCreateService (const std::string &strClassId, const std::string &strObjectId, base::ant::tADTFRunLevel nRunlevel, const std::map< std::string, std::string > &oProperties)
 Create a service instance with properties. More...
 
ucom::ant::object_ptr< ucom::ant::IServiceCreateService (const std::string &strPluginFileName, const std::string &strClassId, const std::string &strObjectId, base::ant::tADTFRunLevel nRunlevel, const std::map< std::string, std::string > &oProperties)
 Load a plugin and create a service instance with properties. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from cTestSystem
static void SetCurDirectory (const std::string &strRelativePath, const std::string &strTestSourceDirectory=ADTF_TESTING_SOURCE_DIR)
 Helper function to change the current working directory relative to the source directory. More...
 
static void SetMacro (const std::string &strName, const std::string &strValue)
 Set a macro value. More...
 
- Protected Attributes inherited from cTestSystem
std::unique_ptr< cImplementation > m_pImplementation
 

Detailed Description

This class allows you to create a test system based on an ADTF session.

Example Usage

class cMyTestSystem : public adtf::system::testing::cSessionTestSystem
{
public:
cMyTestSystem()
{
CreateSession("my_session.adtfsession");
}
};
void my_test_function()
{
cMyTestSystem oSystem;
auto pMyFilter = oSystem.GetGraphObject("filter_graph_name.my_filter");
adtf::filter::testing::cOutputRecorder oRecorder(pMyFilter, "output_pin");
oSystem.Exec(std::chrono::seconds(3));
auto oOutput = oRecorder.GetCurrentOutput();
if (oOutput.GetSamples().empty())
{
throw std::runtime_error("filter did not create samples");
}
}
Test Helper class that records triggers, types and samples created by a graph object.
This class allows you to create a test system based on an ADTF session.
Definition: test_system.h:244
void CreateSession(const std::string &strFileName)
Load and create a session.
void SetRunLevel(base::ant::tADTFRunLevel eRunlevel)
Helper function that changes the runlevel and throws errors via an exception.
@ RL_FilterGraph
The Filtergraph level.
Definition: adtf_runtime.h:34
Copyright © Audi Electronics Venture GmbH.
Copyright © Audi Electronics Venture GmbH.
Note
Our adtf_add_catch_test() macro from ADTF Testing SDK will define the ADTF_TESTING_ADTF_DIR and ADTF_TESTING_ADTF_DIR macros. If you use another testing framework make sure you either pass values directly to the constructor or add these definitions as well.

Definition at line 243 of file test_system.h.

Constructor & Destructor Documentation

◆ cSessionTestSystem() [1/2]

cSessionTestSystem ( const std::string &  strUrl = "",
const std::string &  strAdtfDirectory = ADTF_TESTING_ADTF_DIR,
const std::string &  strPluginDirectories = ADTF_TESTING_PLUGIN_DIRECTORIES 
)

Constructs a test system.

Parameters
[in]strUrlIf set the RPC object registry will be created and listen at the given URL.
[in]strAdtfDirectoryThe ADTF root directory. The default is a macro that can be set by the test environment.
[in]strPluginDirectoriesA ';' seperated list of plugin directories. The default is a macro that can be set by the test environment.

◆ cSessionTestSystem() [2/2]

cSessionTestSystem ( const std::string &  strUrl,
bool  bCreateLoggingService,
const std::string &  strAdtfDirectory = ADTF_TESTING_ADTF_DIR,
const std::string &  strPluginDirectories = ADTF_TESTING_PLUGIN_DIRECTORIES 
)

Constructs a test system.

Parameters
[in]strUrlIf set the RPC object registry will be created and listen at the given URL.
[in]bCreateLoggingServiceWhether or not to create a logging service.
[in]strAdtfDirectoryThe ADTF root directory. The default is a macro that can be set by the test environment.
[in]strPluginDirectoriesA ';' seperated list of plugin directories. The default is a macro that can be set by the test environment.

Member Function Documentation

◆ CreateSession()

void CreateSession ( const std::string &  strFileName)

Load and create a session.

This will create the system services. The filter graph is created when you change the runlevel to RL_FilterGraph.

Parameters
[in]strFileNameThe path to the .adtfsession file.
Exceptions
tResultif an error occurred.

◆ Exec() [1/2]

void Exec ( int8_t  nInitialRunlevel,
std::function< void()>  fnStartup 
)

Executes a session and call the a callback function when ready.

Parameters
[in]nInitialRunlevelChange to this runlevel before the callback is called.
[in]fnStartupThis callback will be called once the session is ready.
Exceptions
tResultif an error occurred.

◆ Exec() [2/2]

void Exec ( std::chrono::microseconds  tmTimeout)

Executes a session for a given amount of time.

This will look for an IApplication implementation and call its IApplication::Execute() and quit when the timeout is reached. If there is no IApplication, then the runlevel will be set to RL_Running and shutdown after the timeout.

Parameters
[in]tmTimeoutThe amount of time the session should be executed.
Exceptions
tResultif an error occurred.

◆ ExecTest()

void ExecTest ( int8_t  nInitialRunlevel,
std::function< void()>  fnTest 
)

Execute a session, call a test function and shutdown the session afterwards.

Parameters
[in]nInitialRunlevelChange to this runlevel before the callback is called.
[in]fnTestThe test callback function.
Exceptions
tResultif an error occurred (i.e. an exception was thrown).

◆ GetFilterGraph()

Returns
the filter graph.

◆ GetGraphObject()

ucom::ant::object_ptr<streaming::ant::INamedGraphObject> GetGraphObject ( const std::string &  name)

Retrieve a graph object from the streaming/filter graph.

Parameters
[in]nameThe full name of the object to retrieve.
Returns
A pointer to the graph object.
Exceptions
tResultif an error occurred.

◆ GetSession()

Returns
the current session object.

◆ GetStreamingGraph()

Returns
the streaming graph.

◆ SetEnvironmentFile()

void SetEnvironmentFile ( const std::string &  strFileName)

Set the adtfenvironment.

This will set the adtfenvironment of the test system. It must be called before CreateSession()

Parameters
[in]strFileNameThe path to the .adtfenvironment file.
Exceptions
tResultif an error occurred.