1 // Copyright 2015, Tobias Hermann and the FunctionalPlus contributors. 2 // https://github.com/Dobiasd/FunctionalPlus 3 // Distributed under the Boost Software License, Version 1.0. 4 // (See accompanying file LICENSE_1_0.txt or copy at 5 // http://www.boost.org/LICENSE_1_0.txt) 6 7 #include <doctest/doctest.h> 8 #include <fplus/fplus.hpp> 9 10 TEST_CASE("queue_test - full") 11 { 12 using namespace fplus; 13 using namespace std::chrono_literals; 14 15 queue<int> q; 16 __anond661717a0102null17 std::thread producer([&q] { 18 q.push(1); 19 q.push(2); 20 std::this_thread::sleep_for(400ms); 21 q.push(3); 22 q.push(4); 23 std::this_thread::sleep_for(400ms); 24 q.push(5); 25 std::this_thread::sleep_for(400ms); 26 q.push(6); 27 }); 28 __anond661717a0202null29 std::thread consumer([&q] { 30 std::this_thread::sleep_for(200ms); 31 REQUIRE_EQ(q.pop(), fplus::just(1)); 32 REQUIRE_EQ(q.pop(), fplus::just(2)); 33 REQUIRE_EQ(q.pop(), fplus::nothing<int>()); 34 std::this_thread::sleep_for(400ms); 35 REQUIRE_EQ(q.pop_all(), std::vector<int>({3, 4})); 36 REQUIRE_EQ(q.pop_all(), std::vector<int>({})); 37 REQUIRE_EQ(q.wait_and_pop_all(), std::vector<int>({5})); 38 REQUIRE_EQ(q.wait_for_and_pop_all(200000), std::vector<int>({})); 39 REQUIRE_EQ(q.wait_for_and_pop_all(400000), std::vector<int>({6})); 40 REQUIRE_EQ(q.wait_for_and_pop_all(200000), std::vector<int>({})); 41 }); 42 43 producer.join(); 44 consumer.join(); 45 } 46