ADTF
Loading...
Searching...
No Matches
adtf::system::testing::cTestSystem Class Reference

#include <test_system.h>

Inherited by adtf::system::testing::giant::cSessionTestSystem.

Public Types

enum  tProtocolFamily { TCP_IPv4 , TCP_IPv6 , UDP_IPv4 , UDP_IPv6 }
 

Public Member Functions

 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, const std::string &strResources=ADTF_TESTING_MUTABLE_RESOURCES, const std::string &strResourcesOutputDirectory=ADTF_TESTING_BUILD_DIR)
 
 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, const std::string &strResources=ADTF_TESTING_MUTABLE_RESOURCES, const std::string &strResourcesOutputDirectory=ADTF_TESTING_BUILD_DIR)
 
 ~cTestSystem ()
 
void SetRunLevel (base::ant::tADTFRunLevel eRunlevel)
 
base::ant::tADTFRunLevel GetRunLevel () const
 
void LoadPlugin (const std::string &strPluginFileName, bool bCreateServices=true, base::ant::tADTFRunLevel nServicesRunlevel=base::tADTFRunLevel::RL_System)
 
ucom::ant::object_ptr< ucom::ant::IServiceCreateService (const std::string &strClassId, const std::string &strObjectId, base::ant::tADTFRunLevel nRunlevel=base::tADTFRunLevel::RL_System)
 
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)
 
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)
 
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)
 
std::string GetUrl () const
 
std::string GetMutableResourceDirectory () const
 

Static Public Member Functions

static void SetCurDirectory (const std::string &strRelativePath, const std::string &strTestSourceDirectory=ADTF_TESTING_SOURCE_DIR)
 
static void SetMacro (const std::string &strName, const std::string &strValue)
 
static uint16_t GetAvailablePort (tProtocolFamily eFamily, const std::string &strInterface={})
 
static std::string GetAvailableTestUrl ()
 

Protected Attributes

std::unique_ptr< cImplementation > m_pImplementation
 

Detailed Description

This class enables you to setup an ADTF System where you can test your filters and services.

This can be used in your test fixtures by subclassing and seting up the system in the constructor. Please have a look at the example tests that are provided:

Example Usage

class cMyTestSystem: public adtf::system::testing::cTestSystem
{
public:
cMyTestSystem()
{
LoadPlugin("adtf_clock.adtfplugin");
LoadPlugin("adtf_kernel.adtfplugin");
LoadPlugin("my_filter.adtfplugin");
SetRunLevel(adtf::base::tADTFRunLevel::RL_System);
}
};
Definition test_system.h:110
void SetRunLevel(base::ant::tADTFRunLevel eRunlevel)
void LoadPlugin(const std::string &strPluginFileName, bool bCreateServices=true, base::ant::tADTFRunLevel nServicesRunlevel=base::tADTFRunLevel::RL_System)
Note
Our adtf_add_catch_test() macro from mainpage_testing_pkg 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.

Constructor & Destructor Documentation

◆ cTestSystem() [1/2]

adtf::system::testing::giant::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,
const std::string & strResources = ADTF_TESTING_MUTABLE_RESOURCES,
const std::string & strResourcesOutputDirectory = ADTF_TESTING_BUILD_DIR )

Constructs a test system.

Parameters
[in]strUrlIf set the RPC object registry will be created and listen at the given URL.
[in]oPluginsA list of plugins that should be loaded. LoadPlugin() will be called for each.
[in]bCreateSessionManagerWhether or not to create a session manager.
[in]strAdtfDirectoryThe ADTF root directory. The default is a macro that can be set by the test environment.
[in]strPluginDirectoriesA ';' separated list of plugin directories. The default is a macro that can be set by the test environment.
[in]strResourcesA ';' separated list of mutable test resources. Can be directories and/or files. The listed inputs will be copied to strResourcesOutputDirectory.
[in]strResourcesOutputDirectoryThe root directory where the listed inputs from strResources will be copied to. A unique folder name will be attached to the path. Mind that this unique folder is temporary!

◆ cTestSystem() [2/2]

adtf::system::testing::giant::cTestSystem::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,
const std::string & strResources = ADTF_TESTING_MUTABLE_RESOURCES,
const std::string & strResourcesOutputDirectory = ADTF_TESTING_BUILD_DIR )

Constructs a test system.

Parameters
[in]strUrlIf set the RPC object registry will be created and listen at the given URL.
[in]oPluginsA list of plugins that should be loaded. LoadPlugin() will be called for each.
[in]bCreateSessionManagerWhether or not to create a session manager.
[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 ';' separated list of plugin directories. The default is a macro that can be set by the test environment.
[in]strResourcesA ';' separated list of mutable test resources. Can be directories and/or files. The listed inputs will be copied to strResourcesOutputDirectory.
[in]strResourcesOutputDirectoryThe root directory where the listed inputs from strResources will be copied to. A unique folder name will be attached to the path. Mind that this unique folder is temporary!

◆ ~cTestSystem()

adtf::system::testing::giant::cTestSystem::~cTestSystem ( )

Destructor. If test sources have been copied using the Constructor, they will be deleted here.

Member Function Documentation

◆ CreateService() [1/4]

ucom::ant::object_ptr< ucom::ant::IService > adtf::system::testing::giant::cTestSystem::CreateService ( 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.

Parameters
[in]strClassIdThe class id of the service.
[in]strObjectIdThe object name with which the instance is registered at the runtime.
[in]nRunlevelThe service will be initialized at the given runlevel.
[in]oPropertiesName value pairs that will be set at the services configuration interface.
Returns
A pointer to the service instance.
Exceptions
tResultif an error occurred.

◆ CreateService() [2/4]

ucom::ant::object_ptr< ucom::ant::IService > adtf::system::testing::giant::cTestSystem::CreateService ( const std::string & strClassId,
const std::string & strObjectId,
base::ant::tADTFRunLevel nRunlevel = base::tADTFRunLevel::RL_System )

Create a service instance.

Parameters
[in]strClassIdThe class id of the service.
[in]strObjectIdThe object name with which the instance is registered at the runtime.
[in]nRunlevelThe service will be initialized at the given runlevel.
Returns
A pointer to the service instance.
Exceptions
tResultif an error occurred.

◆ CreateService() [3/4]

ucom::ant::object_ptr< ucom::ant::IService > adtf::system::testing::giant::cTestSystem::CreateService ( 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.

Parameters
[in]strPluginFileNameThe plugin filename.
[in]strClassIdThe class id of the service.
[in]strObjectIdThe object name with which the instance is registered at the runtime.
[in]nRunlevelThe service will be initialized at the given runlevel.
[in]oPropertiesName value pairs that will be set at the services configuration interface.
Returns
A pointer to the service instance.
Exceptions
tResultif an error occurred.
See also
LoadPlugin().

◆ CreateService() [4/4]

ucom::ant::object_ptr< ucom::ant::IService > adtf::system::testing::giant::cTestSystem::CreateService ( 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.

Parameters
[in]strPluginFileNameThe plugin filename.
[in]strClassIdThe class id of the service.
[in]strObjectIdThe object name with which the instance is registered at the runtime.
[in]nRunlevelThe service will be initialized at the given runlevel.
Returns
A pointer to the service instance.
Exceptions
tResultif an error occurred.
See also
LoadPlugin().

◆ GetAvailablePort()

static uint16_t adtf::system::testing::giant::cTestSystem::GetAvailablePort ( tProtocolFamily eFamily,
const std::string & strInterface = {} )
static
Parameters
[in]eFamilyThe protocol family to retrieve a port for.
[in]strInterfaceThe interface on which the port will be used, empty -> loopback.
Returns
A port that is available and that can be bound by this process.

◆ GetAvailableTestUrl()

static std::string adtf::system::testing::giant::cTestSystem::GetAvailableTestUrl ( )
static
Returns
A unique URL that can be used to launch a session.

◆ GetMutableResourceDirectory()

std::string adtf::system::testing::giant::cTestSystem::GetMutableResourceDirectory ( ) const

Returns the path to the temporary directory that contains the test resources.

Returns
A std::string object containing the path to the created test resources directory. Is empty if nothing has been copied.

◆ GetRunLevel()

base::ant::tADTFRunLevel adtf::system::testing::giant::cTestSystem::GetRunLevel ( ) const

Helper function that returns the current runlevel.

Returns
The current runlevel.

◆ GetUrl()

std::string adtf::system::testing::giant::cTestSystem::GetUrl ( ) const
Returns
RPC URL passed to constructor in strUrl parameter, if any.

◆ LoadPlugin()

void adtf::system::testing::giant::cTestSystem::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.

Parameters
[in]strPluginFileNameThe file name of the plugin. Relative filenames will be resolved within the plugin directories set during construction.
[in]bCreateServicesWhether or not to create instances of services or not.
[in]nServicesRunlevelIf services are created, they will be initialized at the given runlevel.
Exceptions
tResultif an error occurred.

◆ SetCurDirectory()

static void adtf::system::testing::giant::cTestSystem::SetCurDirectory ( const std::string & strRelativePath,
const std::string & strTestSourceDirectory = ADTF_TESTING_SOURCE_DIR )
static

Helper function to change the current working directory relative to the source directory.

Parameters
[in]strRelativePathThe relative directory
[in]strTestSourceDirectoryThe source directory. The default is a macro that can be set by the test environment.

◆ SetMacro()

static void adtf::system::testing::giant::cTestSystem::SetMacro ( const std::string & strName,
const std::string & strValue )
static

Set a macro value.

Parameters
[in]strNameThe name of the macro.
[in]strValueThe value that the macro should resolve to.

◆ SetRunLevel()

void adtf::system::testing::giant::cTestSystem::SetRunLevel ( base::ant::tADTFRunLevel eRunlevel)

Helper function that changes the runlevel and throws errors via an exception.

Parameters
[in]eRunlevelThe desired runlevel.
Exceptions
tResultif an error occurred.

The documentation for this class was generated from the following file: