2 * Copyright Lingxi Li 2015.
3 * Copyright Andrey Semashev 2016.
4 * Distributed under the Boost Software License, Version 1.0.
5 * (See accompanying file LICENSE_1_0.txt or copy at
6 * http://www.boost.org/LICENSE_1_0.txt)
9 * \file sink_text_ipc_mq_backend.cpp
11 * \author Andrey Semashev
14 * \brief The test verifies that \c text_ipc_message_queue_backend works as expected.
17 #if !defined(BOOST_LOG_WITHOUT_IPC)
19 #define BOOST_TEST_MODULE sink_text_ipc_mq_backend
21 #include <boost/log/sinks/text_ipc_message_queue_backend.hpp>
22 #include <boost/log/utility/ipc/reliable_message_queue.hpp>
23 #include <boost/log/utility/ipc/object_name.hpp>
24 #include <boost/log/utility/open_mode.hpp>
25 #include <boost/log/core/record_view.hpp>
26 #include <boost/test/unit_test.hpp>
28 #include "make_record.hpp"
29 #include "char_definitions.hpp"
31 const boost::log::ipc::object_name
ipc_queue_name(boost::log::ipc::object_name::session
, "boost_log_test_text_ipc_mq_backend");
32 const unsigned int capacity
= 512;
33 const unsigned int block_size
= 1024;
34 const char message
[] = "Hello, world!";
36 // The test checks that `text_ipc_message_queue_backend` works.
37 BOOST_AUTO_TEST_CASE(text_ipc_message_queue_backend
)
39 typedef boost::log::ipc::reliable_message_queue queue_t
;
40 typedef boost::log::sinks::text_ipc_message_queue_backend
< queue_t
> backend_t
;
42 // Do a remove in case if a previous test failed
43 queue_t::remove(ipc_queue_name
);
46 BOOST_CHECK(!backend
.is_open());
48 backend
.message_queue().create(ipc_queue_name
, capacity
, block_size
);
49 BOOST_CHECK(backend
.is_open());
51 queue_t
queue(boost::log::open_mode::open_only
, ipc_queue_name
);
52 boost::log::record_view rec
= make_record_view();
53 backend
.consume(rec
, message
);
56 BOOST_CHECK(queue
.try_receive(msg
));
57 BOOST_CHECK(equal_strings(msg
, message
));
60 #else // !defined(BOOST_LOG_WITHOUT_IPC)
67 #endif // !defined(BOOST_LOG_WITHOUT_IPC)