From a3ed479afd0b9d982fa2d7fda96db5a565a30d89 Mon Sep 17 00:00:00 2001 From: Martin Killenberg <martin.killenberg@desy.de> Date: Thu, 17 Aug 2017 17:30:43 +0200 Subject: [PATCH] extended test for CSAdapterEqFct, and fixed implementation for non 1:1 mappings. --- CMakeLists.txt | 2 ++ src/CSAdapterEqFct.cc | 42 +++++++++----------------------- tests/EqFctTest.xml | 9 +++++++ tests/src/testCSAdapterEqFct.cpp | 32 ++++++++++++++++++++++++ 4 files changed, 54 insertions(+), 31 deletions(-) create mode 100644 tests/EqFctTest.xml diff --git a/CMakeLists.txt b/CMakeLists.txt index e962d6f..6b0303b 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 a8dedd0..f416a05 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 0000000..1fc0a3e --- /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 ccc811f..e3959f1 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() -- GitLab