4#include <ChimeraTK/SupportedUserTypes.h>
6#include <tango/idl/tango.h>
7#define BOOST_TEST_DYN_LINK
8#define BOOST_TEST_MODULE testUnifiedBackendTest
12#include <ChimeraTK/UnifiedBackendTest.h>
14#include <tango/tango.h>
16#include <boost/filesystem.hpp>
17#include <boost/process.hpp>
18#include <boost/test/unit_test.hpp>
24using namespace boost::unit_test_framework;
31template<
typename DERIVED>
33 DERIVED*
derived{
static_cast<DERIVED*
>(
this)};
44 .enableTestCatalogue()
45 .disableForceDataLossWrite()
46 .disableAsyncReadInconsistency()
47 .disableSwitchReadOnly()
48 .disableSwitchWriteOnly();
62template<
typename DERIVED>
68 template<
typename UserType>
70 return {{ChimeraTK::numericToUserType<UserType>(
static_cast<typename DERIVED::minimumUserType
>(
71 derived->template getRemoteValue<typename DERIVED::minimumUserType>()[0][0] +
derived->increment))}};
74 template<
typename UserType>
76 auto v = ChimeraTK::numericToUserType<UserType>(
derived->getValue());
81 auto v =
derived->template generateValue<typename DERIVED::minimumUserType>()[0][0];
86template<
typename DERIVED>
91 template<
typename UserType>
93 auto v = ChimeraTK::numericToUserType<UserType>(
derived->getValue());
98 auto v =
derived->template generateValue<typename DERIVED::minimumUserType>()[0][0];
105template<
typename DERIVED>
110 template<
typename UserType>
112 auto curval =
derived->template getRemoteValue<typename DERIVED::minimumUserType>()[0];
113 std::vector<UserType> val;
114 for(
size_t i = 0; i <
derived->nElementsPerChannel(); ++i) {
115 val.push_back(ChimeraTK::numericToUserType<UserType>(curval[i] + (i + 1) *
derived->increment));
120 template<
typename UserType>
122 std::vector<UserType> val;
123 for(
size_t i = 0; i <
derived->nElementsPerChannel(); ++i) {
124 val.push_back(ChimeraTK::numericToUserType<UserType>(
derived->getValue(i)));
129 template<
typename REMOTE_TYPE>
131 auto val =
derived->template generateValue<typename DERIVED::minimumUserType>()[0];
132 for(
size_t i = 0; i <
derived->nElementsPerChannel(); ++i) {
133 derived->setValue(i, ChimeraTK::userTypeToUserType<REMOTE_TYPE, typename DERIVED::minimumUserType>(val[i]));
141 std::string
path() {
return "IntScalar"; }
149 auto attr = Tango::DeviceAttribute(attrName, v);
154 Tango::DevLong value;
164 std::string
path() {
return "IntRoScalar"; }
174 auto attr = Tango::DeviceAttribute(
path, v);
179 Tango::DevLong value;
189 std::string
path() {
return "IntWoScalar"; }
199 auto attr = Tango::DeviceAttribute(
path, v);
204 Tango::DevLong value;
214 std::string
path() {
return "BooleanScalar"; }
225 auto attr = Tango::DeviceAttribute(
path,
bool(v));
228 catch(CORBA::Exception& ex) {
229 Tango::Except::print_exception(ex);
235 Tango::DevBoolean value;
241 catch(CORBA::Exception& ex) {
242 Tango::Except::print_exception(ex);
251 std::string
path() {
return "BooleanRoScalar"; }
263 auto attr = Tango::DeviceAttribute(
path,
bool(v));
268 Tango::DevBoolean value;
278 std::string
path() {
return "BooleanWoScalar"; }
290 auto attr = Tango::DeviceAttribute(
path,
bool(v));
295 Tango::DevBoolean value;
305 std::string
path() {
return "StringScalar"; }
315 auto attr = Tango::DeviceAttribute(
path, v);
319 template<
typename UserType>
337std::vector<std::vector<std::string>> RegSomeString::generateValue<std::string>() {
339 return {{
"This is a string: " + std::to_string(someValue)}};
343 std::string
path() {
return "IntSpectrum"; }
355 std::vector<Tango::DevLong> values(10, {});
363 auto attr = Tango::DeviceAttribute(
path, values);
366 catch(CORBA::Exception& ex) {
367 Tango::Except::print_exception(ex);
378 std::vector<Tango::DevLong> values;
388 std::string
path() {
return "StringSpectrum"; }
390 std::string
readPath() {
return "StringSpectrum"; }
400 std::vector<std::string> values;
409 auto attr = Tango::DeviceAttribute(
path, values);
419 std::vector<std::string> values;
425 template<
typename UserType>
434std::vector<std::vector<std::string>> RegSomeStringArray::generateValue<std::string>() {
435 std::vector<std::string> value;
438 std::vector<std::string> val;
439 for(
size_t i = 0; i < derived->nElementsPerChannel(); ++i) {
440 val.push_back(
"This is a string " + std::to_string(someValue + (i + 1)));
449 std::string
path() {
return "BooleanSpectrum"; }
451 std::string
readPath() {
return "BooleanSpectrum"; }
461 std::vector<Tango::DevBoolean> values;
465 catch(Tango::DevFailed& ex) {
466 Tango::Except::print_exception(ex);
475 auto attr = Tango::DeviceAttribute(
path, values);
485 std::vector<Tango::DevBoolean> values;
491 template<
typename UserType>
500std::vector<std::vector<ChimeraTK::Boolean>> RegSomeBooleanArray::generateValue<ChimeraTK::Boolean>() {
501 std::vector<ChimeraTK::Boolean> value;
504 std::vector<ChimeraTK::Boolean> val;
505 val.reserve(derived->nElementsPerChannel());
506 for(
size_t i = 0; i < derived->nElementsPerChannel(); ++i) {
507 val.emplace_back((i % 2) == 1);
515 auto ubt = ChimeraTK::UnifiedBackendTest<>()
517 .addRegister<RegSomeRoInt>()
519 .addRegister<RegSomeBool>()
521 .addRegister<RegSomeWoBool>()
523 .addRegister<RegSomeIntArray>()
525 .addRegister<RegSomeBooleanArray>();
static constexpr auto capabilities
void setForceRuntimeError(bool enable, size_t)
std::nullptr_t rawUserType
ChimeraTK::AccessModeFlags supportedFlags()
size_t nRuntimeErrorCases()
size_t writeQueueLength()
void setRemoteValueImpl()
std::vector< std::vector< UserType > > getRemoteValue()
std::vector< std::vector< UserType > > generateValue()
void setValue(minimumUserType v)
minimumUserType getValue()
ChimeraTK::Boolean minimumUserType
ChimeraTK::Boolean getValue(int i)
size_t nElementsPerChannel()
void setValue(int i, bool v)
ChimeraTK::Boolean minimumUserType
std::vector< std::vector< UserType > > generateValue()
Tango::DevLong getValue(int i)
void setValue(int i, Tango::DevLong v)
size_t nElementsPerChannel()
minimumUserType getValue()
void setValue(minimumUserType v)
void setValue(minimumUserType v)
static constexpr auto capabilities
minimumUserType getValue()
ChimeraTK::Boolean minimumUserType
void setValue(minimumUserType v)
minimumUserType getValue()
static constexpr auto capabilities
std::string minimumUserType
std::string getValue(int i)
size_t nElementsPerChannel()
std::vector< std::vector< UserType > > generateValue()
void setValue(int i, std::string v)
std::string minimumUserType
minimumUserType getValue()
std::vector< std::vector< UserType > > generateValue()
void setValue(minimumUserType v)
ChimeraTK::Boolean minimumUserType
static constexpr auto capabilities
minimumUserType getValue()
void setValue(minimumUserType v)
static constexpr auto capabilities
void setValue(minimumUserType v)
minimumUserType getValue()
size_t nElementsPerChannel()
std::vector< std::vector< UserType > > generateValue()
std::vector< std::vector< UserType > > getRemoteValue()
std::vector< std::vector< UserType > > getRemoteValue()
size_t nElementsPerChannel()
void stop()
Shut down the Tango server.
static TangoServerLauncher * self
std::shared_ptr< Tango::DeviceProxy > remoteProxy
BOOST_GLOBAL_FIXTURE(TangoServerLauncher)
BOOST_AUTO_TEST_CASE(unifiedBackendTest)