From 510a845315b49ab8dd11c909cb314f789956a3e0 Mon Sep 17 00:00:00 2001 From: Martin Killenberg <martin.killenberg@desy.de> Date: Tue, 5 Sep 2017 15:27:23 +0200 Subject: [PATCH] added missing file for tests --- tests/include/serverBasedTestTools.h | 48 ++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 tests/include/serverBasedTestTools.h diff --git a/tests/include/serverBasedTestTools.h b/tests/include/serverBasedTestTools.h new file mode 100644 index 0000000..e73fd61 --- /dev/null +++ b/tests/include/serverBasedTestTools.h @@ -0,0 +1,48 @@ +#ifndef SERVER_BASED_TEST_TOOLS_H +#define SERVER_BASED_TEST_TOOLS_H + +#include <eq_fct.h> +#include "basenameFromAddress.h" + +// these constants don't exist in DOOCS, although they should. We define them here for better code readability +static const int ACCESS_RO = 0; // read only +static const int ACCESS_RW = 1; // read/write + +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); + + auto propertyName = ChimeraTK::basenameFromAddress(propertyAddress); + DOOCS_T * property = dynamic_cast<DOOCS_T *>(eqFct->find_property(propertyName)); + BOOST_REQUIRE_MESSAGE(property, "Could not find property " + propertyName + " (address "<< propertyAddress <<"), or property has unexpected type."); + + checkHistory(property, expected_has_history); + + std::stringstream errorMessage; + errorMessage << "Access rights not correct for '" << propertyAddress << "': access word is " + << property->get_access() << ", expected " << (expected_is_writeable?ACCESS_RW:ACCESS_RO); + if (expected_is_writeable){ + BOOST_CHECK_MESSAGE( property->get_access() == ACCESS_RW , errorMessage.str()); + }else{ + BOOST_CHECK( property->get_access() == ACCESS_RO ); + } +} + +#endif // SERVER_BASED_TEST_TOOLS_H -- GitLab