3 #define BOOST_TEST_DYN_LINK
4 #define BOOST_TEST_MODULE OneDRegisterAccessorTest
5 #include <boost/test/unit_test.hpp>
6 using namespace boost::unit_test_framework;
15 #include <boost/bind/bind.hpp>
16 #include <boost/date_time/posix_time/posix_time.hpp>
17 #include <boost/function.hpp>
18 #include <boost/lambda/lambda.hpp>
19 #include <boost/make_shared.hpp>
24 using namespace boost::unit_test_framework;
32 device.
open(
"(WriteCountingDummy?map=goodMapFile.map)");
41 std::cout <<
"testRegisterAccessor" << std::endl;
45 BOOST_CHECK(intRegister.
isReadOnly() ==
false);
53 device.
write<
int>(
"APP0/MODULE0", std::vector<int>({5, -77, 99}));
55 BOOST_CHECK(intRegister[0] == 5);
56 BOOST_CHECK(intRegister[1] == -77);
57 BOOST_CHECK(intRegister[2] == 99);
60 intRegister[0] = -666;
64 BOOST_CHECK(
device.
read<
int>(
"APP0/MODULE0", 3) == std::vector<int>({-666, 999, 222}));
67 int* ptr = intRegister.
data();
68 BOOST_CHECK(ptr[0] = -666);
69 BOOST_CHECK(ptr[1] = 999);
70 BOOST_CHECK(ptr[2] = 222);
74 BOOST_CHECK(intRegister[0] = 123);
75 BOOST_CHECK(intRegister[1] = 456);
76 BOOST_CHECK(intRegister[2] = 789);
81 *it = 1000 * (ic + 1);
85 BOOST_CHECK(
device.
read<
int>(
"APP0/MODULE0", 3) == std::vector<int>({1000, 2000, 3000}));
94 BOOST_CHECK(
device.
read<
int>(
"APP0/MODULE0", 3) == std::vector<int>({999, 666, 333}));
97 device.
write(
"APP0/MODULE0", std::vector<int>({1234, 2468, 3702}));
102 BOOST_CHECK(*it == 1234 * (ic + 1));
108 BOOST_CHECK(*it == 1234 * (3 - ic));
113 std::vector<int> x(3);
118 BOOST_CHECK(x[0] == 1234);
119 BOOST_CHECK(x[1] == 2468);
120 BOOST_CHECK(x[2] == 3702);
121 BOOST_CHECK(intRegister[0] == 11);
122 BOOST_CHECK(intRegister[1] == 22);
123 BOOST_CHECK(intRegister[2] == 33);
130 device.
write(
"APP0/MODULE0", std::vector<int>({-120, 2468}));
131 floatRegister.
read();
132 BOOST_CHECK(floatRegister[0] == -120. / 8.);
135 floatRegister[0] = 42. / 8.;
136 floatRegister.
write();
137 BOOST_CHECK(
device.
read<
int>(
"APP0/MODULE0", 2) == std::vector<int>({42, 2468}));
143 std::cout <<
"testWriteIfDifferent" << std::endl;
148 auto backend = boost::dynamic_pointer_cast<WriteCountingBackend>(
device.
getBackend());
149 BOOST_CHECK(backend != NULL);
153 accessor = {501, 502, 503};
155 size_t counterBefore = backend->writeCount;
157 size_t counterAfter = backend->writeCount;
158 BOOST_CHECK(counterBefore == counterAfter);
161 counterBefore = backend->writeCount;
163 counterAfter = backend->writeCount;
164 BOOST_CHECK(counterAfter == counterBefore + 1);
167 counterBefore = backend->writeCount;
169 counterAfter = backend->writeCount;
170 BOOST_CHECK(counterAfter == counterBefore);
173 counterBefore = backend->writeCount;
175 counterAfter = backend->writeCount;
176 BOOST_CHECK(counterAfter == counterBefore + 1);
179 counterBefore = backend->writeCount;
181 counterAfter = backend->writeCount;
182 BOOST_CHECK(counterAfter == counterBefore + 1);
185 counterBefore = backend->writeCount;
187 counterAfter = backend->writeCount;
188 BOOST_CHECK(counterAfter == counterBefore + 1);