ChimeraTK-cppext 01.05.02
Loading...
Searching...
No Matches
testSwap.cc
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Deutsches Elektronen-Synchrotron DESY, MSK, ChimeraTK Project <chimeratk-support@desy.de>
2// SPDX-License-Identifier: LGPL-3.0-or-later
3#define BOOST_TEST_MODULE test_future_queue
4#include <boost/test/included/unit_test.hpp>
5using namespace boost::unit_test_framework;
6
7#include "future_queue.hpp"
8
9BOOST_AUTO_TEST_SUITE(testSwap)
10
11/*********************************************************************************************************************/
12
14 std::vector<int> a{4, 5, 6};
15 std::vector<int> b{9, 8, 7, 6, 5, 4, 3, 2, 1, 0};
16 std::vector<int> c{1, 2, 3, 4, 5, 6};
17
19
20 movingQueue.push(std::move(a));
21 BOOST_CHECK_EQUAL(a.size(), 0);
22
23 movingQueue.push(std::move(b));
24 BOOST_CHECK_EQUAL(b.size(), 0);
25
26 movingQueue.pop(c);
27 BOOST_CHECK_EQUAL(c.size(), 3);
28 BOOST_CHECK(c == std::vector<int>({4, 5, 6}));
29
30 movingQueue.pop(a);
31 BOOST_CHECK_EQUAL(a.size(), 10);
32 BOOST_CHECK(a == std::vector<int>({9, 8, 7, 6, 5, 4, 3, 2, 1, 0}));
33
34 movingQueue.push(std::move(a));
35 BOOST_CHECK_EQUAL(a.size(), 0);
36
37 movingQueue.push(std::move(c));
38 BOOST_CHECK_EQUAL(c.size(), 0);
39}
40
41/*********************************************************************************************************************/
42
43BOOST_AUTO_TEST_CASE(testSwapping) {
44 std::vector<int> a_orig{4, 5, 6};
45 std::vector<int> b_orig{9, 8, 7, 6, 5, 4, 3, 2, 1, 0};
46 std::vector<int> c_orig{1, 2, 3, 4, 5, 6};
47 std::vector<int> d_orig{42, 120};
48
49 std::vector<int> a = a_orig;
50 std::vector<int> b = b_orig;
51 std::vector<int> c = c_orig;
52
53 cppext::future_queue<std::vector<int>, cppext::SWAP_DATA> swappingQueue(2); // size of 2 means 3 internal buffers
54
55 swappingQueue.push(std::move(a));
56 BOOST_CHECK_EQUAL(a.size(), 0);
57
58 swappingQueue.push(std::move(b));
59 BOOST_CHECK_EQUAL(b.size(), 0);
60
61 swappingQueue.pop(c); // pop first internal buffer, which is then holding content of c_orig
62 BOOST_CHECK(c == a_orig);
63
64 a = d_orig;
65 swappingQueue.pop(a); // pop second internal buffer, which is then holding the
66 // content of d_orig
67 BOOST_CHECK(a == b_orig);
68
69 swappingQueue.push(std::move(a));
70 BOOST_CHECK_EQUAL(a.size(),
71 0); // this is coming from the 3rd internal buffer which was not yet used
72
73 swappingQueue.push(std::move(b));
74 BOOST_CHECK(b == c_orig);
75
76 swappingQueue.pop();
77
78 swappingQueue.push(std::move(c));
79 BOOST_CHECK(c == d_orig);
80}
81
82/*********************************************************************************************************************/
83
84BOOST_AUTO_TEST_SUITE_END()
Feature tag for future_queue: use std::swap to store and retreive data to/from the queue.
BOOST_AUTO_TEST_CASE(testMoving)
Definition testSwap.cc:13