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

refactoring the test to prepare testing for history and writeability

parent 73e9d0df
No related branches found
No related tags found
No related merge requests found
#ifndef _DOOCS_ADAPTER_BASENAME_FROM_ADDRESS_
#define _DOOCS_ADAPTER_BASENAME_FROM_ADDRESS_
namespace ChimeraTK {
/** Find the last slash and return the subsring behind it.
*/
inline std::string basenameFromAddress(std::string const & doocsAddress) {
// find first slash
auto slashPosition = doocsAddress.rfind("/");
// no slash found: return the whole string
if(slashPosition == std::string::npos){
return doocsAddress;
}
return doocsAddress.substr( slashPosition+1 );
}
}// namespace ChimeraTK
#endif // _DOOCS_ADAPTER_BASENAME_FROM_ADDRESS_
......@@ -19,12 +19,37 @@
<import directory="myStuff">/SHORT</import>
</location>
<!-- Set the default for has_history to false in one location -->
<location name="USHORT">
<has_history>false</has_history>
<!-- Turn the history back on for one property, although the default is off.-->
<property source="TO_DEVICE_SCALAR">
<has_history>true</has_history>
</property>
<!-- all imported properties will have the history turned off -->
<import>/USHORT</import>
</location>
<!-- Set the default for is_writeable to false in one location.
Intentionally use another location than for the has_history test to avoid missing
confusion in the parser (e.g. is_writeable allways acts on both, has_history has no effec,
but it's not seen because it's always tested together) -->
<location name="UCHAR">
<is_writeable>false</is_writeable>
<!-- Turn the history back on for one property, although the default is off.-->
<property source="TO_DEVICE_SCALAR">
<is_writeable>true</is_writeable>
</property>
<!-- all imported properties will have the history turned off -->
<import>/USHORT</import>
</location>
<location name="DOUBLE">
<!-- test renaming a scalar-->
<!-- Also tests relative variable names. The input must be in a directory which is identical
top the ocation name, '/DOUBLE' in this case -->
<property source="DATA_TYPE_CONSTANT" name="RENAMED_CONSTANT">
<!-- test turning off the history (on by default) -->
<!-- test turning off the history (no special default set per location, on by default) -->
<has_history>false</has_history>
</property>
<!-- Test adding a scalar from another directory than the one imported. -->
......
......@@ -6,6 +6,7 @@
#include <ChimeraTK/ControlSystemAdapter/Testing/ReferenceTestApplication.h>
#include <doocs-server-test-helper/doocsServerTestHelper.h>
#include <thread>
#include "basenameFromAddress.h"
ReferenceTestApplication referenceTestApplication("serverTestRenameImport");
......@@ -25,6 +26,38 @@ using namespace ChimeraTK;
// int8_t, uint8_t,
// float, double> simple_test_types;
template<class DOOCS_T>
void checkHistory(DOOCS_T * property, bool expected_has_history){
bool has_history = property->get_histPointer();
BOOST_CHECK_MESSAGE( has_history == expected_has_history, "History on/off wrong for "+ property->basename() +". Should be " + (expected_has_history?"true":"false"));
}
template<>
void checkHistory(D_spectrum * /*property*/, bool){
// nothing to do, spectra don't have history
}
template<class DOOCS_T>
void checkDoocsProperty(std::string const & propertyAddress, bool expected_has_history = true, bool expected_is_writeable =true){
// copied from DoocsServerTestHelper::doocsGet
EqAdr ad;
EqData ed, res;
// obtain location pointer
ad.adr(propertyAddress.c_str());
EqFct *eqFct = eq_get(&ad);
BOOST_REQUIRE_MESSAGE( eqFct, "Could not get location for property "+propertyAddress);
std::cout << "propertyAddress " << propertyAddress << std::endl;
auto propertyName = basenameFromAddress(propertyAddress);
std::cout << "eqFct->find_property(" << propertyName<< ") " << eqFct->find_property(propertyName) << std::endl;
// Note: try splitting the property name at the last slash
DOOCS_T * property = dynamic_cast<DOOCS_T *>(eqFct->find_property(propertyName));
BOOST_REQUIRE_MESSAGE(property, "Could not find property" + propertyName);
checkHistory(property, expected_has_history);
}
/// Check that all expected variables are there.
void testVariableExistence(){
// run update once to make sure the server is up and running
......@@ -35,42 +68,46 @@ void testVariableExistence(){
for (auto const location : { "CHAR", "UCHAR", "UINT", "USHORT"} ){
for (auto const property : { "CONSTANT_ARRAY", "FROM_DEVICE_ARRAY", "TO_DEVICE_ARRAY "} ){
// if this throws the property does not exist. we should always be able to read"
BOOST_CHECK_NO_THROW( DoocsServerTestHelper::doocsGetArray<int>( (std::string("//")+location+"/"+ property).c_str() ));
checkDoocsProperty<D_spectrum>( std::string("//")+location+"/"+ property);
}
for (auto const property : { "DATA_TYPE_CONSTANT", "FROM_DEVICE_SCALAR", "TO_DEVICE_SCALAR"} ){
// if this throws the property does not exist. we should always be able to read"
BOOST_CHECK_NO_THROW( DoocsServerTestHelper::doocsGet<int>( (std::string("//")+location+"/"+ property).c_str() ));
checkDoocsProperty<D_int>( (std::string("//")+location+"/"+ property).c_str());
}
}
BOOST_CHECK_NO_THROW( DoocsServerTestHelper::doocsGetArray<int>("//MY_RENAMED_INTEGER_LOCATION/RENAMED.CONST_ARRAY") );
BOOST_CHECK_NO_THROW( DoocsServerTestHelper::doocsGetArray<int>("//MY_RENAMED_INTEGER_LOCATION/FROM_DEVICE_ARRAY") );
BOOST_CHECK_NO_THROW( DoocsServerTestHelper::doocsGetArray<int>("//MY_RENAMED_INTEGER_LOCATION/TO_DEVICE_ARRAY") );
checkDoocsProperty<D_spectrum>("//MY_RENAMED_INTEGER_LOCATION/RENAMED.CONST_ARRAY");
checkDoocsProperty<D_spectrum>("//MY_RENAMED_INTEGER_LOCATION/FROM_DEVICE_ARRAY", true );
checkDoocsProperty<D_spectrum>("//MY_RENAMED_INTEGER_LOCATION/TO_DEVICE_ARRAY", true );
checkDoocsProperty<D_spectrum>("//MY_RENAMED_INTEGER_LOCATION/DATA_TYPE_CONSTANT", true );
BOOST_CHECK( DoocsServerTestHelper::doocsGet<int>("//MY_RENAMED_INTEGER_LOCATION/DATA_TYPE_CONSTANT") == -4);
BOOST_CHECK_NO_THROW( DoocsServerTestHelper::doocsGet<int>("//MY_RENAMED_INTEGER_LOCATION/FROM_DEVICE_SCALAR") );
BOOST_CHECK_NO_THROW( DoocsServerTestHelper::doocsGet<int>("//MY_RENAMED_INTEGER_LOCATION/TO_DEVICE_SCALAR") );
checkDoocsProperty<D_int>("//MY_RENAMED_INTEGER_LOCATION/FROM_DEVICE_SCALAR");
checkDoocsProperty<D_int>("//MY_RENAMED_INTEGER_LOCATION/TO_DEVICE_SCALAR");
BOOST_CHECK_NO_THROW( DoocsServerTestHelper::doocsGetArray<int>("//SHORT/myStuff.CONSTANT_ARRAY") );
BOOST_CHECK_NO_THROW( DoocsServerTestHelper::doocsGetArray<int>("//SHORT/myStuff.FROM_DEVICE_ARRAY") );
BOOST_CHECK_NO_THROW( DoocsServerTestHelper::doocsGetArray<int>("//SHORT/myStuff.TO_DEVICE_ARRAY") );
checkDoocsProperty<D_spectrum>("//SHORT/myStuff.CONSTANT_ARRAY", true );
checkDoocsProperty<D_spectrum>("//SHORT/myStuff.FROM_DEVICE_ARRAY", true );
checkDoocsProperty<D_spectrum>("//SHORT/myStuff.TO_DEVICE_ARRAY", true );
checkDoocsProperty<D_int>("//SHORT/myStuff.DATA_TYEP_CONSTANT");
BOOST_CHECK( DoocsServerTestHelper::doocsGet<int>("//SHORT/myStuff.DATA_TYPE_CONSTANT") == -2);
BOOST_CHECK_NO_THROW( DoocsServerTestHelper::doocsGet<int>("//SHORT/myStuff.FROM_DEVICE_SCALAR") );
checkDoocsProperty<D_int>("//SHORT/myStuff.FROM_DEVICE_SCALAR");
BOOST_CHECK_NO_THROW( DoocsServerTestHelper::doocsGet<int>("//CHERRY_PICKED/TO_DEVICE_SHORT") );
checkDoocsProperty<D_int>("//CHERRY_PICKED/TO_DEVICE_SHORT");
BOOST_CHECK_NO_THROW( DoocsServerTestHelper::doocsGetArray<int>("//DOUBLE/CONSTANT_ARRAY") );
BOOST_CHECK_NO_THROW( DoocsServerTestHelper::doocsGetArray<int>("//DOUBLE/FROM_DEVICE_ARRAY") );
BOOST_CHECK_NO_THROW( DoocsServerTestHelper::doocsGetArray<int>("//DOUBLE/TO_DEVICE_ARRAY") );
checkDoocsProperty<D_spectrum>("//DOUBLE/CONSTANT_ARRAY", true );
checkDoocsProperty<D_spectrum>("//DOUBLE/FROM_DEVICE_ARRAY", true );
checkDoocsProperty<D_spectrum>("//DOUBLE/TO_DEVICE_ARRAY", true );
checkDoocsProperty<D_int>("//DOUBLE/RENAMED_CONSTANT");
BOOST_CHECK( DoocsServerTestHelper::doocsGet<double>("//DOUBLE/RENAMED_CONSTANT") == 1./8.);
BOOST_CHECK_NO_THROW( DoocsServerTestHelper::doocsGet<int>("//DOUBLE/FROM_DEVICE_SCALAR") );
BOOST_CHECK_NO_THROW( DoocsServerTestHelper::doocsGet<int>("//DOUBLE/DOUBLE.TO_DEVICE_SCALAR") );
BOOST_CHECK_NO_THROW( DoocsServerTestHelper::doocsGet<int>("//DOUBLE/I_AM_A_FLOAT_SCALAR") );
checkDoocsProperty<D_int>("//DOUBLE/FROM_DEVICE_SCALAR");
checkDoocsProperty<D_int>("//DOUBLE/DOUBLE.TO_DEVICE_SCALAR");
checkDoocsProperty<D_int>("//DOUBLE/I_AM_A_FLOAT_SCALAR");
// we moved one float scalar to the double location, so we cannot check for it in the loop above
BOOST_CHECK_NO_THROW( DoocsServerTestHelper::doocsGetArray<int>("//FLOAT/CONSTANT_ARRAY") );
BOOST_CHECK_NO_THROW( DoocsServerTestHelper::doocsGetArray<int>("//FLOAT/FROM_DEVICE_ARRAY") );
BOOST_CHECK_NO_THROW( DoocsServerTestHelper::doocsGetArray<int>("//FLOAT/TO_DEVICE_ARRAY") );
checkDoocsProperty<D_spectrum>("//FLOAT/CONSTANT_ARRAY", true );
checkDoocsProperty<D_spectrum>("//FLOAT/FROM_DEVICE_ARRAY", true );
checkDoocsProperty<D_spectrum>("//FLOAT/TO_DEVICE_ARRAY", true );
checkDoocsProperty<D_spectrum>("//FLOAT/DATA_TYPE_CONSTANT", true );
BOOST_CHECK( DoocsServerTestHelper::doocsGet<float>("//FLOAT/DATA_TYPE_CONSTANT") == 1./4.);
BOOST_CHECK_NO_THROW( DoocsServerTestHelper::doocsGet<int>("//FLOAT/FROM_DEVICE_SCALAR") );
checkDoocsProperty<D_int>("//FLOAT/FROM_DEVICE_SCALAR");
}
// due to the doocs server thread you can only have one test suite
......@@ -81,7 +118,7 @@ public:
doocsServerThread(eq_server, argc, argv)
{
doocsServerThread.detach();
add( BOOST_TEST_CASE( &testVariableExistence ) );
add( BOOST_TEST_CASE(&testVariableExistence) );
}
protected:
......
// Define a name for the test module.
#define BOOST_TEST_MODULE BasenameFromAddressTest
// Only after defining the name include the unit test header.
#include <boost/test/included/unit_test.hpp>
#include "basenameFromAddress.h"
using namespace boost::unit_test_framework;
using namespace ChimeraTK;
BOOST_AUTO_TEST_SUITE( BasenameFromAddressTestSuite )
BOOST_AUTO_TEST_CASE( testSpitting ) {
BOOST_CHECK(basenameFromAddress("//LOCATION/PROPERTY.NAME") == "PROPERTY.NAME");
BOOST_CHECK(basenameFromAddress("PROPERTY.NAME") == "PROPERTY.NAME");
BOOST_CHECK(basenameFromAddress("/PROPERTY.NAME") == "PROPERTY.NAME");
BOOST_CHECK(basenameFromAddress("//PROPERTY.NAME/") == "");
}
BOOST_AUTO_TEST_SUITE_END()
<?xml version="1.0" encoding="UTF-8"?>
<device_server xmlns="https://github.com/ChimeraTK/ControlSystemAdapter-DoocsAdapter">
<location name="B">
<property source="c/de"/>
</location>
<location name="DIRECT">
<property source="/A/b/do"/>
<property source="INT"/>
</location>
</device_server>
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