Skip to content
Snippets Groups Projects
Commit a3ed479a authored by Martin Killenberg's avatar Martin Killenberg
Browse files

extended test for CSAdapterEqFct, and fixed implementation for non 1:1 mappings.

parent 2bd41407
No related branches found
No related tags found
No related merge requests found
......@@ -67,6 +67,8 @@ if(TESTING_IS_ENABLED)
file(GLOB XML_FILES variable ${CMAKE_SOURCE_DIR}/tests/variableTreeXml/*.xml)
file(COPY ${XML_FILES} DESTINATION ${PROJECT_BINARY_DIR}/variableTreeXml)
file(COPY ${CMAKE_SOURCE_DIR}/tests/EqFctTest.xml DESTINATION ${PROJECT_BINARY_DIR})
#The make coverage command is only available in debug mode
IF(CMAKE_BUILD_TYPE STREQUAL "Debug")
configure_file(cmake/Makefile.coverage.in ${PROJECT_BINARY_DIR}/Makefile.coverage @ONLY)
......
#include "CSAdapterEqFct.h"
#include "DoocsPVFactory.h"
#include "splitStringAtFirstSlash.h"
#include "VariableMapper.h"
namespace ChimeraTK{
......@@ -46,40 +46,20 @@ namespace ChimeraTK{
// We only need the factory inside this function
DoocsPVFactory factory(this, syncUtility_);
auto processVariablesInThisLocation = getProcessVariablesInThisLocation();
doocsProperties_.reserve( processVariablesInThisLocation.size() );
auto mappingForThisLocation = VariableMapper::getInstance().getPropertiesInLocation(fct_name());
doocsProperties_.reserve( mappingForThisLocation.size() );
// now create the doocs properties using the factory
for( auto chimeraTKVariable : processVariablesInThisLocation ){
doocsProperties_.push_back( factory.create( chimeraTKVariable ) );
// we also have to remember which chimeraTK variables we have to receive
if ( chimeraTKVariable->isReadable() ){
chimeraTKReceivers_.push_back(chimeraTKVariable);
}
}
}
std::vector < ChimeraTK::ProcessVariable::SharedPtr >
CSAdapterEqFct::getProcessVariablesInThisLocation(){
std::vector < ChimeraTK::ProcessVariable::SharedPtr > pvsInThisLocation;
auto allPVs = controlSystemPVManager_->getAllProcessVariables();
for (auto & pvNameAndPropertyDescrition : mappingForThisLocation){
auto pvName = pvNameAndPropertyDescrition.first;
// we just need the pv name, not the description yet. The factory does that for us.
auto chimeraTkVariable = controlSystemPVManager_->getProcessVariable(pvName);
for (auto pv : allPVs){
auto locationAndName = splitStringAtFirstSlash( pv->getName() );
if ( locationAndName.first == fct_name() ){
pvsInThisLocation.push_back( pv );
}else if(locationAndName.first == "" && emptyLocationVariablesHandled == false) {
pvsInThisLocation.push_back( pv );
doocsProperties_.push_back( factory.create( chimeraTkVariable ) );
// we also have to remember which chimeraTK variables we have to receive
if ( chimeraTkVariable->isReadable() ){
chimeraTKReceivers_.push_back(chimeraTkVariable);
}
}
// the first location to run this function is getting the PVs with empty location name
emptyLocationVariablesHandled = true;
return pvsInThisLocation;
}
}// namespace ChimeraTK
<?xml version="1.0" encoding="UTF-8"?>
<device_server xmlns="https://github.com/ChimeraTK/ControlSystemAdapter-DoocsAdapter">
<location name="test.TO_DEVICE">
<property source="/test/TO_DEVICE/INT" name="INT"/>
</location>
<location name="test.FROM_DEVICE">
<property source="/test/FROM_DEVICE/INT" name="INT"/>
</location>
</device_server>
......@@ -95,4 +95,36 @@ BOOST_AUTO_TEST_CASE( testCSAdapterEqFct ) {
BOOST_CHECK_EQUAL( doocsProperties["FROM_DEVICE.INT "]->value(), 15);
}
BOOST_AUTO_TEST_CASE( testWithMapping ) {
// This test is a bit redundant because the mapping is tested separately. Just to see that it
// works after integration.
// This is basically a stripped down copy of the test before, so we leave out all comments
// and just comment what is different.
DoocsAdapter doocsAdapter;
BusinessLogic businessLogic( doocsAdapter.getDevicePVManager() );
// Initialse the mapping with an xml file.
auto csManager = doocsAdapter.getControlSystemPVManager();
VariableMapper::getInstance().prepareOutput( "EqFctTest.xml", getAllVariableNames(csManager ) );
// in the mapping two locations are created
TestableCSAdapterEqFct toDeviceEqFct(42, csManager, "test.TO_DEVICE");
TestableCSAdapterEqFct fromDeviceEqFct(42, csManager, "test.FROM_DEVICE");
BOOST_REQUIRE( toDeviceEqFct.getDoocsProperties().size() == 1 );
BOOST_REQUIRE( fromDeviceEqFct.getDoocsProperties().size() == 1 );
// extract the two properties and check the name
std::map< std::string, D_int *> doocsProperties;
// both properties are called int, but are in different locations
D_int *doocsInt = dynamic_cast<D_int*>(toDeviceEqFct.getDoocsProperties()[0].get());
BOOST_REQUIRE( std::string(doocsInt->property_name()) == "INT ");
doocsInt = dynamic_cast<D_int*>(fromDeviceEqFct.getDoocsProperties()[0].get());
BOOST_REQUIRE( std::string(doocsInt->property_name()) == "INT ");
}
BOOST_AUTO_TEST_SUITE_END()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment