summaryrefslogtreecommitdiffstats
path: root/src/boost/libs/log/test/common
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
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')
-rw-r--r--src/boost/libs/log/test/common/attr_comparison.hpp60
-rw-r--r--src/boost/libs/log/test/common/char_definitions.hpp116
-rw-r--r--src/boost/libs/log/test/common/make_record.hpp32
-rw-r--r--src/boost/libs/log/test/common/test_sink.hpp92
4 files changed, 300 insertions, 0 deletions
diff --git a/src/boost/libs/log/test/common/attr_comparison.hpp b/src/boost/libs/log/test/common/attr_comparison.hpp
new file mode 100644
index 00000000..b4be4f48
--- /dev/null
+++ b/src/boost/libs/log/test/common/attr_comparison.hpp
@@ -0,0 +1,60 @@
+/*
+ * 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 attr_comparison.hpp
+ * \author Andrey Semashev
+ * \date 06.08.2010
+ *
+ * \brief This header contains tools for attribute comparison in attribute-related tests.
+ */
+
+#ifndef BOOST_LOG_TESTS_ATTR_COMPARISON_HPP_INCLUDED_
+#define BOOST_LOG_TESTS_ATTR_COMPARISON_HPP_INCLUDED_
+
+#include <ostream>
+#include <boost/log/attributes/attribute.hpp>
+
+class attribute_factory_helper :
+ public boost::log::attribute
+{
+ typedef boost::log::attribute base_type;
+
+public:
+ attribute_factory_helper(base_type const& that) : base_type(that)
+ {
+ }
+
+ impl* get_impl() const
+ {
+ return base_type::get_impl();
+ }
+};
+
+namespace boost {
+
+BOOST_LOG_OPEN_NAMESPACE
+
+inline bool operator== (attribute const& left, attribute const& right)
+{
+ return attribute_factory_helper(left).get_impl() == attribute_factory_helper(right).get_impl();
+}
+inline bool operator!= (attribute const& left, attribute const& right)
+{
+ return attribute_factory_helper(left).get_impl() != attribute_factory_helper(right).get_impl();
+}
+
+inline std::ostream& operator<< (std::ostream& strm, attribute const& val)
+{
+ strm << attribute_factory_helper(val).get_impl();
+ return strm;
+}
+
+BOOST_LOG_CLOSE_NAMESPACE // namespace log
+
+} // namespace boost
+
+#endif // BOOST_LOG_TESTS_ATTR_COMPARISON_HPP_INCLUDED_
diff --git a/src/boost/libs/log/test/common/char_definitions.hpp b/src/boost/libs/log/test/common/char_definitions.hpp
new file mode 100644
index 00000000..2cf0d664
--- /dev/null
+++ b/src/boost/libs/log/test/common/char_definitions.hpp
@@ -0,0 +1,116 @@
+/*
+ * 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 char_definitions.hpp
+ * \author Andrey Semashev
+ * \date 24.01.2009
+ *
+ * \brief This header contains common type definitions for character type dependent tests.
+ */
+
+#ifndef BOOST_LOG_TESTS_CHAR_DEFINITIONS_HPP_INCLUDED_
+#define BOOST_LOG_TESTS_CHAR_DEFINITIONS_HPP_INCLUDED_
+
+#include <string>
+#include <iostream>
+#include <boost/mpl/vector.hpp>
+
+namespace mpl = boost::mpl;
+
+typedef mpl::vector<
+#ifdef BOOST_LOG_USE_CHAR
+ char
+#endif
+#if defined(BOOST_LOG_USE_CHAR) && defined(BOOST_LOG_USE_WCHAR_T)
+ ,
+#endif
+#ifdef BOOST_LOG_USE_WCHAR_T
+ wchar_t
+#endif
+>::type char_types;
+
+template< typename >
+struct test_data;
+
+
+#ifdef BOOST_LOG_USE_CHAR
+
+template< >
+struct test_data< char >
+{
+ static const char* abc() { return "abc"; }
+ static const char* ABC() { return "ABC"; }
+ static const char* some_test_string() { return "some test string"; }
+ static const char* zero_to_five() { return "012345"; }
+ static const char* def() { return "def"; }
+ static const char* aaa() { return "aaa"; }
+ static const char* abcd() { return "abcd"; }
+ static const char* zz() { return "zz"; }
+ static const char* abcdefg0123456789() { return "abcdefg0123456789"; }
+
+ static const char* attr1() { return "attr1"; }
+ static const char* attr2() { return "attr2"; }
+ static const char* attr3() { return "attr3"; }
+ static const char* attr4() { return "attr4"; }
+
+ static const char* int_format1() { return "%08d"; }
+ static const char* fp_format1() { return "%06.3f"; }
+};
+
+//! The function compares two strings and prints them if they are not equal
+inline bool equal_strings(std::string const& left, std::string const& right)
+{
+ if (left != right)
+ {
+ std::cout << "Left: \"" << left << "\"\nRight: \"" << right << "\"" << std::endl;
+ return false;
+ }
+ else
+ return true;
+}
+
+#endif // BOOST_LOG_USE_CHAR
+
+#ifdef BOOST_LOG_USE_WCHAR_T
+
+template< >
+struct test_data< wchar_t >
+{
+ static const wchar_t* abc() { return L"abc"; }
+ static const wchar_t* ABC() { return L"ABC"; }
+ static const wchar_t* some_test_string() { return L"some test string"; }
+ static const wchar_t* zero_to_five() { return L"012345"; }
+ static const wchar_t* def() { return L"def"; }
+ static const wchar_t* aaa() { return L"aaa"; }
+ static const wchar_t* abcd() { return L"abcd"; }
+ static const wchar_t* zz() { return L"zz"; }
+ static const wchar_t* abcdefg0123456789() { return L"abcdefg0123456789"; }
+
+ static const char* attr1() { return "attr1"; }
+ static const char* attr2() { return "attr2"; }
+ static const char* attr3() { return "attr3"; }
+ static const char* attr4() { return "attr4"; }
+
+ static const wchar_t* int_format1() { return L"%08d"; }
+ static const wchar_t* fp_format1() { return L"%06.3f"; }
+};
+
+//! The function compares two strings and prints them if they are not equal
+inline bool equal_strings(std::wstring const& left, std::wstring const& right)
+{
+ if (left != right)
+ {
+ std::wcout << L"Left: \"" << left << L"\"\nRight: \"" << right << L"\"" << std::endl;
+ return false;
+ }
+ else
+ return true;
+}
+
+#endif // BOOST_LOG_USE_WCHAR_T
+
+#endif // BOOST_LOG_TESTS_CHAR_DEFINITIONS_HPP_INCLUDED_
diff --git a/src/boost/libs/log/test/common/make_record.hpp b/src/boost/libs/log/test/common/make_record.hpp
new file mode 100644
index 00000000..9d1f028d
--- /dev/null
+++ b/src/boost/libs/log/test/common/make_record.hpp
@@ -0,0 +1,32 @@
+/*
+ * 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 make_record.hpp
+ * \author Andrey Semashev
+ * \date 18.03.2009
+ *
+ * \brief This header contains a helper function make_record that creates a log record with the specified attributes.
+ */
+
+#ifndef BOOST_LOG_TESTS_MAKE_RECORD_HPP_INCLUDED_
+#define BOOST_LOG_TESTS_MAKE_RECORD_HPP_INCLUDED_
+
+#include <boost/move/utility_core.hpp>
+#include <boost/log/core.hpp>
+#include <boost/log/attributes/attribute_set.hpp>
+
+inline boost::log::record make_record(boost::log::attribute_set const& src_attrs = boost::log::attribute_set())
+{
+ return boost::log::core::get()->open_record(src_attrs);
+}
+
+inline boost::log::record_view make_record_view(boost::log::attribute_set const& src_attrs = boost::log::attribute_set())
+{
+ return make_record(src_attrs).lock();
+}
+
+#endif // BOOST_LOG_TESTS_MAKE_RECORD_HPP_INCLUDED_
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_