// test_thread_queue.cpp // // Unit tests for the thread_queue class in the Paho MQTT C++ library. // /******************************************************************************* * Copyright (c) 2022 Frank Pagliughi * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * and Eclipse Distribution License v1.0 which accompany this distribution. * * The Eclipse Public License is available at * http://www.eclipse.org/legal/epl-v10.html * and the Eclipse Distribution License is available at * http://www.eclipse.org/org/documents/edl-v10.php. * * Contributors: * Frank Pagliughi - Initial implementation *******************************************************************************/ #define UNIT_TESTS #include "catch2/catch.hpp" #include "mqtt/types.h" #include "mqtt/thread_queue.h" #include #include #include #include using namespace mqtt; using namespace std::chrono; TEST_CASE("que put/get", "[thread_queue]") { thread_queue que; que.put(1); que.put(2); REQUIRE(que.get() == 1); que.put(3); REQUIRE(que.get() == 2); REQUIRE(que.get() == 3); } TEST_CASE("que mt put/get", "[thread_queue]") { thread_queue que; const size_t N = 1000000; const size_t N_THR = 2; auto producer = [&que]() { string s; for (size_t i=0; i<512; ++i) s.push_back('a' + i%26); for (size_t i=0; i producers; std::vector> consumers; for (size_t i=0; i