ChimeraTK-cppext 01.05.02
Loading...
Searching...
No Matches
testFront.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(testFront)
10
11// test with a custom data type which is not known to the queue
12// we intentionally do not use a convenient standard-like interface to avoid
13// accidental usage of common operators etc.
14struct MovableDataType {
15 constexpr static int undef = -987654321;
17 explicit MovableDataType(int value) : _value(value) {}
18 MovableDataType(MovableDataType&& other) : _value(other._value) { other._value = undef; }
20 _value = other._value;
21 other._value = undef;
22 return *this;
23 }
24 int value() const { return _value; }
25
26 private:
27 int _value{undef};
28};
29constexpr int MovableDataType::undef;
30
31/*********************************************************************************************************************/
32
33BOOST_AUTO_TEST_CASE(singleThreaded) {
34 // test up to a queue length of 100, start with 1
35 for(size_t length = 1; length <= 100; ++length) {
37
38 { // in combination with discarding pop()
39 for(size_t n = 0; n < length; ++n) {
40 MovableDataType value(length + n + 120);
41 BOOST_CHECK(q1.push(std::move(value)) == true);
42 BOOST_CHECK_EQUAL(value.value(), MovableDataType::undef);
43 }
44 for(size_t n = 0; n < length; ++n) {
45 BOOST_CHECK(q1.empty() == false);
46 BOOST_CHECK_EQUAL(q1.front().value(), length + n + 120);
47 q1.pop();
48 }
49 }
50
51 { // in combination with discarding pop_wait()
52 for(size_t n = 0; n < length; ++n) {
53 MovableDataType value(length + n - 120);
54 BOOST_CHECK(q1.push(std::move(value)) == true);
55 BOOST_CHECK_EQUAL(value.value(), MovableDataType::undef);
56 }
57 for(size_t n = 0; n < length; ++n) {
58 BOOST_CHECK(q1.empty() == false);
59 BOOST_CHECK_EQUAL(q1.front().value(), length + n - 120);
60 q1.pop_wait();
61 }
62 }
63 }
64}
65
66/*********************************************************************************************************************/
67
68BOOST_AUTO_TEST_SUITE_END()
MovableDataType(MovableDataType &&other)
Definition testFront.cc:18
MovableDataType & operator=(MovableDataType &&other)
Definition testFront.cc:19
static constexpr int undef
Definition testEmpty.cc:18
MovableDataType(int value)
Definition testFront.cc:17
int value() const
Definition testFront.cc:24
BOOST_AUTO_TEST_CASE(singleThreaded)
Definition testFront.cc:33