4 #define BOOST_TEST_DYN_LINK
5 #define BOOST_TEST_MODULE ScalarRegisterAccessorTest
6 #include <boost/test/unit_test.hpp>
7 using namespace boost::unit_test_framework;
15 #include <unordered_map>
17 #include <boost/bind/bind.hpp>
18 #include <boost/function.hpp>
19 #include <boost/lambda/lambda.hpp>
20 #include <boost/make_shared.hpp>
25 using namespace boost::unit_test_framework;
32 std::cout <<
"testCreation" << std::endl;
36 boost::shared_ptr<DummyBackend> backend =
37 boost::dynamic_pointer_cast<DummyBackend>(BackendFactory::getInstance().createBackend(
"DUMMYD2"));
38 BOOST_CHECK(backend != NULL);
42 BOOST_CHECK(intRegisterDisconnected.
isInitialised() ==
false);
57 std::cout <<
"testRegisterAccessor" << std::endl;
61 boost::shared_ptr<DummyBackend> backend =
62 boost::dynamic_pointer_cast<DummyBackend>(BackendFactory::getInstance().createBackend(
"DUMMYD2"));
63 BOOST_CHECK(backend != NULL);
77 BOOST_CHECK(accessor == 5);
78 BOOST_CHECK(
int(accessor) == 5);
79 BOOST_CHECK(2 * accessor == 10);
80 BOOST_CHECK(accessor + 2 == 7);
82 BOOST_CHECK(accessor == 5);
84 BOOST_CHECK(accessor == -654);
89 BOOST_CHECK(dummy == -666);
92 BOOST_CHECK(dummy == 222);
97 BOOST_CHECK(accessor == 223);
98 BOOST_CHECK(copy == 223);
99 BOOST_CHECK(dummy == 222);
101 BOOST_CHECK(dummy == 223);
103 BOOST_CHECK(accessor == 3);
105 BOOST_CHECK(dummy == 3);
110 BOOST_CHECK(accessor == 2);
111 BOOST_CHECK(copy == 2);
112 BOOST_CHECK(dummy == 3);
114 BOOST_CHECK(dummy == 2);
116 BOOST_CHECK(accessor == 42);
118 BOOST_CHECK(dummy == 42);
121 int oldValue = accessor++;
123 BOOST_CHECK(accessor == 43);
124 BOOST_CHECK(copy == 43);
125 BOOST_CHECK(oldValue == 42);
126 BOOST_CHECK(dummy == 42);
128 BOOST_CHECK(dummy == 43);
132 oldValue = accessor--;
134 BOOST_CHECK(accessor == 119);
135 BOOST_CHECK(copy == 119);
136 BOOST_CHECK(oldValue == 120);
137 BOOST_CHECK(dummy == 43);
139 BOOST_CHECK(dummy == 119);
147 BOOST_CHECK(dummy == 4711);
168 std::cout <<
"testFloatRegisterAccessor" << std::endl;
172 boost::shared_ptr<DummyBackend> backend =
173 boost::dynamic_pointer_cast<DummyBackend>(BackendFactory::getInstance().createBackend(
"DUMMYD2"));
174 BOOST_CHECK(backend != NULL);
184 float requiredVal = dummy;
185 BOOST_CHECK_CLOSE(requiredVal, 5.3, 1);
188 float val = accessor;
190 BOOST_CHECK_CLOSE(val, requiredVal, 0.01);
191 BOOST_CHECK_CLOSE(
float(accessor), requiredVal, 0.01);
192 BOOST_CHECK_CLOSE(2. * accessor, 2 * requiredVal, 0.01);
193 BOOST_CHECK_CLOSE(accessor + 2, 2 + requiredVal, 0.01);
195 BOOST_CHECK_CLOSE(
float(accessor), requiredVal, 0.01);
197 BOOST_CHECK_CLOSE(
float(accessor), 0, 0.01);
202 BOOST_CHECK_CLOSE(
float(dummy), 0, 0.01);
205 BOOST_CHECK_CLOSE(
float(dummy), 10.3125, 0.01);
215 std::cout <<
"testWordOffset" << std::endl;
219 boost::shared_ptr<DummyBackend> backend =
220 boost::dynamic_pointer_cast<DummyBackend>(BackendFactory::getInstance().createBackend(
"DUMMYD2"));
221 BOOST_CHECK(backend != NULL);
231 BOOST_CHECK(accessor ==
static_cast<int>(3.5 * (1 << 5)));
237 BOOST_CHECK(dummy == 3.53125);
246 std::cout <<
"testUniqueID" << std::endl;
256 BOOST_CHECK(accessor1.
getId() == accessor1.
getId());
257 BOOST_CHECK(!(accessor1.
getId() != accessor1.
getId()));
258 BOOST_CHECK(accessor2.getId() == accessor2.getId());
259 BOOST_CHECK(!(accessor2.getId() != accessor2.getId()));
260 BOOST_CHECK(accessor1.
getId() != accessor2.getId());
261 BOOST_CHECK(!(accessor1.
getId() == accessor2.getId()));
262 BOOST_CHECK(accessor2.getId() != accessor1.
getId());
263 BOOST_CHECK(!(accessor2.getId() == accessor1.
getId()));
267 accessor1Copied.
replace(accessor1);
268 BOOST_CHECK(accessor1Copied.
getId() == accessor1.
getId());
269 BOOST_CHECK(accessor1Copied.
getId() != accessor2.getId());
271 accessor2Copied.
replace(accessor2);
272 BOOST_CHECK(accessor2Copied.
getId() == accessor2.getId());
273 BOOST_CHECK(accessor2Copied.
getId() != accessor1.
getId());
277 BOOST_CHECK(accessor1a.
getId() == accessor1a.
getId());
278 BOOST_CHECK(accessor1.
getId() != accessor1a.
getId());
279 BOOST_CHECK(accessor2.getId() != accessor1a.
getId());
283 BOOST_CHECK(myId != myId);
284 myId = accessor1.
getId();
285 BOOST_CHECK(myId == accessor1.
getId());
286 BOOST_CHECK(myId == accessor1Copied.
getId());
287 BOOST_CHECK(myId != accessor2.getId());
288 BOOST_CHECK(myId != accessor1a.
getId());
291 std::unordered_map<TransferElementID, std::string> map1;
292 map1.insert({myId,
"SomeTest"});
293 BOOST_CHECK(map1[accessor1.
getId()] ==
"SomeTest");
296 std::unordered_map<std::string, TransferElementID> map2;
297 map2.insert({
"AnotherTest", myId});
298 BOOST_CHECK(map2[
"AnotherTest"] == accessor1.
getId());
301 std::map<TransferElementID, std::string> map3;
302 map3.insert({myId,
"SomeTest"});
303 BOOST_CHECK(map3[accessor1.
getId()] ==
"SomeTest");
306 std::unordered_map<std::string, TransferElementID> map4;
307 map4.insert({
"AnotherTest", myId});
308 BOOST_CHECK(map4[
"AnotherTest"] == accessor1.
getId());
311 std::vector<TransferElementID> vector;
312 vector.push_back(myId);
313 BOOST_CHECK(vector[0] == accessor1.
getId());
321 std::cout <<
"testWriteIfDifferent" << std::endl;
325 device.
open(
"(WriteCountingDummy?map=goodMapFile.map)");
326 auto backend = boost::dynamic_pointer_cast<WriteCountingBackend>(
327 BackendFactory::getInstance().createBackend(
"(WriteCountingDummy?map=goodMapFile.map)"));
328 BOOST_CHECK(backend != NULL);
342 size_t counterBefore = backend->writeCount;
344 size_t counterAfter = backend->writeCount;
345 BOOST_CHECK(counterBefore == counterAfter);
348 counterBefore = backend->writeCount;
350 counterAfter = backend->writeCount;
351 BOOST_CHECK(counterAfter == counterBefore + 1);
354 counterBefore = backend->writeCount;
356 counterAfter = backend->writeCount;
357 BOOST_CHECK(counterAfter == counterBefore);
360 counterBefore = backend->writeCount;
362 counterAfter = backend->writeCount;
363 BOOST_CHECK(counterAfter == counterBefore + 1);
366 counterBefore = backend->writeCount;
368 counterAfter = backend->writeCount;
369 BOOST_CHECK(counterAfter == counterBefore + 1);
372 counterBefore = backend->writeCount;
374 counterAfter = backend->writeCount;
375 BOOST_CHECK(counterAfter == counterBefore + 1);
379 counterBefore = backend->writeCount;
385 counterAfter = backend->writeCount;
386 BOOST_CHECK(counterBefore != counterAfter);