4 #define BOOST_TEST_DYN_LINK
5 #define BOOST_TEST_MODULE SubdeviceBackendUnifiedTest
6 #include <boost/test/unit_test.hpp>
7 using namespace boost::unit_test_framework;
16 BOOST_AUTO_TEST_SUITE(SubdeviceBackendUnifiedTestSuite)
20 static std::string
cdd(
"(ExceptionDummy:1?map=SubdeviceTarget.map)");
21 static auto target = boost::dynamic_pointer_cast<ExceptionDummy>(BackendFactory::getInstance().createBackend(
cdd));
25 template<
typename Register>
34 static constexpr
auto capabilities =
39 template<
typename UserType>
41 std::vector<UserType> v;
42 for(
size_t i = 0; i < this->nElementsPerChannel(); ++i) {
43 assert(i + this->address() / 4 < 10);
44 typename Register::minimumUserType e = acc[i + this->address() / 4] + this->increment * (i + 1);
45 auto limited = this->limitGenerated(e);
46 v.push_back(
raw ? this->toRaw(limited) : limited);
53 template<
typename Type>
56 for(
size_t i = 0; i < this->nElementsPerChannel(); ++i) {
57 assert(i + this->address() / 4 < 10);
58 auto rawVal = acc[i + this->address() / 4];
59 v.push_back((
raw ? rawVal : this->fromRaw(rawVal)));
65 auto v = generateValue<typename Register::minimumUserType>()[0];
66 for(
size_t i = 0; i < this->nElementsPerChannel(); ++i) {
67 assert(i + this->address() / 4 < 10);
68 acc[i + this->address() / 4] = this->toRaw(v[i]);
73 target->throwExceptionRead = enable;
74 target->throwExceptionWrite = enable;
75 target->throwExceptionOpen = enable;
83 assert(target !=
nullptr);
84 data.setWriteCallback([
this] { this->writeCallback(); });
85 area.setWriteCallback([
this] { this->writeCallback(); });
92 size_t lastAddress{32};
93 std::vector<uint32_t> currentValue{std::vector<uint32_t>(lastAddress)};
95 std::vector<std::vector<uint32_t>> currentAreaValue{lastAddress, std::vector<uint32_t>(areaSize)};
101 if(useStatus) status = 1;
102 if(address >= lastAddress) {
103 std::cout <<
"Error: address (" << address <<
") >= lastAddress (" << lastAddress <<
")!" << std::endl;
105 BOOST_REQUIRE(address < lastAddress);
107 currentValue[address] = data;
110 assert(area.getNumberOfElements() == areaSize);
111 for(
size_t i = 0; i < areaSize; ++i) {
112 currentAreaValue[address][i] = area[i];
116 if(useStatus) status = 0;
123 template<
typename Register>
132 static constexpr
auto capabilities =
135 template<
typename Type>
138 for(
size_t i = 0; i < this->nElementsPerChannel(); ++i) {
147 typename Register::minimumUserType e = this->fromRaw(cv) + this->increment * (i + 1);
148 auto limited = this->limitGenerated(e);
149 v.push_back(
raw ? this->toRaw(limited) : limited);
154 template<
typename Type>
157 for(
size_t i = 0; i < this->nElementsPerChannel(); ++i) {
165 v.push_back(
raw ? rawValue : this->fromRaw(rawValue));
171 auto v = generateValue<typename Register::minimumUserType>()[0];
172 for(
size_t i = 0; i < this->nElementsPerChannel(); ++i) {
174 core.
currentValue[i + this->address()] = this->toRaw(v[i]);
183 target->throwExceptionRead = enable;
184 target->throwExceptionWrite = enable;
185 target->throwExceptionOpen = enable;
192 std::string
path() {
return "/APP.0/MY_REGISTER1"; }
195 uint32_t
toRaw(uint32_t v) {
return v; }
198 uint32_t increment = 7;
206 std::string
path() {
return "/APP.0/MY_AREA1"; }
209 uint32_t
toRaw(
float v) {
return v * 65536.F; }
210 float fromRaw(uint32_t v) {
return v / 65536.F; }
212 while(e > 32768.
F) e -= 65535.F;
213 while(e < -32767.
F) e += 65535.F;
216 float increment = 666. / 65536.;
224 std::string
path() {
return "/APP.0/THE_AREA_1"; }
227 uint32_t
toRaw(uint32_t v) {
return v; }
230 uint32_t increment = 17;
238 std::string
path() {
return "/APP.0/THE_AREA_2"; }
241 uint32_t
toRaw(
float v) {
return v * 65536.F; }
242 float fromRaw(uint32_t v) {
return v / 65536.F; }
244 while(e > 32768.
F) e -= 65535.F;
245 while(e < -32767.
F) e += 65535.F;
248 float increment = 42. / 65536.;
258 "(subdevice?type=area&device=" +
cdd +
"&area=APP.0.THE_AREA&map=Subdevice.map)");
262 "(subdevice?type=3regs&device=" +
cdd +
263 "&address=APP.1.ADDRESS&data=APP.1.DATA&status=APP.1.STATUS&map=Subdevice.map)");
268 "(subdevice?type=2regs&device=" +
cdd +
"&address=APP.1.ADDRESS&data=APP.1.DATA&sleep=1000&map=Subdevice.map)");
275 "(subdevice?type=3regs&device=" +
cdd +
276 "&address=APP.1.ADDRESS&data=APP.0.THE_AREA&status=APP.1.STATUS&map=SubdeviceMuxedArea.map)");
281 BOOST_AUTO_TEST_SUITE_END()