diff --git a/CMakeLists.txt b/CMakeLists.txt index e962d6f1aaeb8f20cffeafa1f75af167f708cb7e..6b0303b2fa28e026536cea80698da90aef55a68a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/src/CSAdapterEqFct.cc b/src/CSAdapterEqFct.cc index a8dedd0b54e7035664df99e27efb2f58dd6cf4c5..f416a0550cbccb060a7f3b269f6ea05fa5892384 100644 --- a/src/CSAdapterEqFct.cc +++ b/src/CSAdapterEqFct.cc @@ -1,6 +1,6 @@ #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 diff --git a/tests/EqFctTest.xml b/tests/EqFctTest.xml new file mode 100644 index 0000000000000000000000000000000000000000..1fc0a3eb84ec39bf23c90cbfa095e9503319b3b2 --- /dev/null +++ b/tests/EqFctTest.xml @@ -0,0 +1,9 @@ +<?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> diff --git a/tests/src/testCSAdapterEqFct.cpp b/tests/src/testCSAdapterEqFct.cpp index ccc811f0e29406e296e9f219bdfede6d5577d4b2..e3959f15852b04a49be8158e9aadcb86fceea5c0 100644 --- a/tests/src/testCSAdapterEqFct.cpp +++ b/tests/src/testCSAdapterEqFct.cpp @@ -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()