]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/log/test/run/sink_text_ipc_mq_backend.cpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / libs / log / test / run / sink_text_ipc_mq_backend.cpp
1 /*
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)
7 */
8 /*!
9 * \file sink_text_ipc_mq_backend.cpp
10 * \author Lingxi Li
11 * \author Andrey Semashev
12 * \date 19.10.2015
13 *
14 * \brief The test verifies that \c text_ipc_message_queue_backend works as expected.
15 */
16
17 #if !defined(BOOST_LOG_WITHOUT_IPC)
18
19 #define BOOST_TEST_MODULE sink_text_ipc_mq_backend
20
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>
27 #include <string>
28 #include "make_record.hpp"
29 #include "char_definitions.hpp"
30
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!";
35
36 // The test checks that `text_ipc_message_queue_backend` works.
37 BOOST_AUTO_TEST_CASE(text_ipc_message_queue_backend)
38 {
39 typedef boost::log::ipc::reliable_message_queue queue_t;
40 typedef boost::log::sinks::text_ipc_message_queue_backend< queue_t > backend_t;
41
42 // Do a remove in case if a previous test failed
43 queue_t::remove(ipc_queue_name);
44
45 backend_t backend;
46 BOOST_CHECK(!backend.is_open());
47
48 backend.message_queue().create(ipc_queue_name, capacity, block_size);
49 BOOST_CHECK(backend.is_open());
50
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);
54
55 std::string msg;
56 BOOST_CHECK(queue.try_receive(msg));
57 BOOST_CHECK(equal_strings(msg, message));
58 }
59
60 #else // !defined(BOOST_LOG_WITHOUT_IPC)
61
62 int main()
63 {
64 return 0;
65 }
66
67 #endif // !defined(BOOST_LOG_WITHOUT_IPC)