ChimeraTK-cppext 01.05.02
Loading...
Searching...
No Matches
testEmpty.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"
9
10#include <thread>
11
12BOOST_AUTO_TEST_SUITE(testHasData)
13
14// test with a custom data type which is not known to the queue
15// we intentionally do not use a convenient standard-like interface to avoid
16// accidental usage of common operators etc.
18 constexpr static int undef = -987654321;
20 explicit MovableDataType(int value) : _value(value) {}
21 MovableDataType(MovableDataType&& other) : _value(other._value) { other._value = undef; }
23 _value = other._value;
24 other._value = undef;
25 return *this;
26 }
27 int value() { return _value; }
28
29 private:
30 int _value{undef};
31};
32constexpr int MovableDataType::undef;
33
34/*********************************************************************************************************************/
35
36BOOST_AUTO_TEST_CASE(multiThreaded) {
37 // test up to a queue length of 100, start with 1
38 for(size_t length = 1; length <= 100; ++length) {
40
41 // single value transport
42 {
43 BOOST_CHECK_TIMEOUT(q1.empty() == true);
44 std::thread sender([&q1, length] {
45 MovableDataType value(length + 42);
46 BOOST_CHECK_TS(q1.push(std::move(value)) == true);
48 }); // end sender thread
49 std::thread receiver([&q1] { BOOST_CHECK_TIMEOUT(q1.empty() == false); }); // end receiver thread
50 sender.join();
51 receiver.join();
52 BOOST_CHECK_TIMEOUT(q1.empty() == false);
53 q1.pop_wait();
54 BOOST_CHECK_TIMEOUT(q1.empty() == true);
55 }
56 }
57}
58
59/*********************************************************************************************************************/
60
61BOOST_AUTO_TEST_SUITE_END()
MovableDataType(MovableDataType &&other)
Definition testEmpty.cc:21
MovableDataType & operator=(MovableDataType &&other)
Definition testEmpty.cc:22
static constexpr int undef
Definition testEmpty.cc:18
MovableDataType(int value)
Definition testEmpty.cc:20
BOOST_AUTO_TEST_CASE(multiThreaded)
Definition testEmpty.cc:36
#define BOOST_CHECK_TIMEOUT(condition)
#define BOOST_CHECK_EQUAL_TS(a, b)
#define BOOST_CHECK_TS(condition)