summaryrefslogtreecommitdiffstats
path: root/src/boost/libs/log/test/common/test_sink.hpp
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 18:24:20 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 18:24:20 +0000
commit483eb2f56657e8e7f419ab1a4fab8dce9ade8609 (patch)
treee5d88d25d870d5dedacb6bbdbe2a966086a0a5cf /src/boost/libs/log/test/common/test_sink.hpp
parentInitial commit. (diff)
downloadceph-upstream.tar.xz
ceph-upstream.zip
Adding upstream version 14.2.21.upstream/14.2.21upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/boost/libs/log/test/common/test_sink.hpp')
-rw-r--r--src/boost/libs/log/test/common/test_sink.hpp92
1 files changed, 92 insertions, 0 deletions
diff --git a/src/boost/libs/log/test/common/test_sink.hpp b/src/boost/libs/log/test/common/test_sink.hpp
new file mode 100644
index 00000000..da88830e
--- /dev/null
+++ b/src/boost/libs/log/test/common/test_sink.hpp
@@ -0,0 +1,92 @@
+/*
+ * Copyright Andrey Semashev 2007 - 2015.
+ * Distributed under the Boost Software License, Version 1.0.
+ * (See accompanying file LICENSE_1_0.txt or copy at
+ * http://www.boost.org/LICENSE_1_0.txt)
+ */
+/*!
+ * \file test_sink.hpp
+ * \author Andrey Semashev
+ * \date 18.03.2009
+ *
+ * \brief This header contains a test sink frontend that is used through various tests.
+ */
+
+#ifndef BOOST_LOG_TESTS_TEST_SINK_HPP_INCLUDED_
+#define BOOST_LOG_TESTS_TEST_SINK_HPP_INCLUDED_
+
+#include <cstddef>
+#include <map>
+#include <boost/log/core/record_view.hpp>
+#include <boost/log/attributes/attribute_name.hpp>
+#include <boost/log/attributes/attribute_value_set.hpp>
+#include <boost/log/sinks/sink.hpp>
+#include <boost/log/expressions/filter.hpp>
+
+//! A sink implementation for testing purpose
+struct test_sink :
+ public boost::log::sinks::sink
+{
+public:
+ typedef boost::log::attribute_value_set attribute_values;
+ typedef boost::log::record_view record_type;
+ typedef boost::log::filter filter_type;
+ typedef attribute_values::key_type key_type;
+
+ struct key_type_order
+ {
+ typedef bool result_type;
+
+ result_type operator() (key_type const& left, key_type const& right) const
+ {
+ return left.id() < right.id();
+ }
+ };
+
+ typedef std::map< key_type, std::size_t, key_type_order > attr_counters_map;
+
+public:
+ filter_type m_Filter;
+ attr_counters_map m_Consumed;
+ std::size_t m_RecordCounter;
+
+public:
+ test_sink() : boost::log::sinks::sink(false), m_RecordCounter(0) {}
+
+ void set_filter(filter_type const& f)
+ {
+ m_Filter = f;
+ }
+
+ void reset_filter()
+ {
+ m_Filter.reset();
+ }
+
+ bool will_consume(attribute_values const& attributes)
+ {
+ return m_Filter(attributes);
+ }
+
+ void consume(record_type const& record)
+ {
+ ++m_RecordCounter;
+ attribute_values::const_iterator
+ it = record.attribute_values().begin(),
+ end = record.attribute_values().end();
+ for (; it != end; ++it)
+ ++m_Consumed[it->first];
+ }
+
+ void flush()
+ {
+ }
+
+ void clear()
+ {
+ m_RecordCounter = 0;
+ m_Consumed.clear();
+ }
+};
+
+#endif // BOOST_LOG_TESTS_TEST_SINK_HPP_INCLUDED_