]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/test/test/framework-ts/logger-for-tests.hpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / libs / test / test / framework-ts / logger-for-tests.hpp
1 // (C) Copyright Raffi Enficiaud 2017.
2 // Distributed under the Boost Software License, Version 1.0.
3 // (See accompanying file LICENSE_1_0.txt or copy at
4 // http://www.boost.org/LICENSE_1_0.txt)
5
6 // See http://www.boost.org/libs/test for the library home page.
7 //
8 // tests Unit Test Framework logging facilities against
9 // pattern file
10 // ***************************************************************************
11
12
13 #ifndef BOOST_TEST_TESTS_LOGGER_FOR_TESTS_HPP__
14 #define BOOST_TEST_TESTS_LOGGER_FOR_TESTS_HPP__
15
16 #include <boost/test/tools/output_test_stream.hpp>
17 #include <boost/test/utils/algorithm.hpp>
18
19 using namespace boost::unit_test;
20 using boost::test_tools::output_test_stream;
21
22 class output_test_stream_for_loggers : public output_test_stream {
23
24 std::string const source_filename;
25 std::string const basename;
26
27 public:
28 explicit output_test_stream_for_loggers(
29 boost::unit_test::const_string pattern_file_name = boost::unit_test::const_string(),
30 bool match_or_save = true,
31 bool text_or_binary = true,
32 const std::string& source_filename_ = __FILE__)
33 : output_test_stream(pattern_file_name, match_or_save, text_or_binary)
34 , source_filename(source_filename_)
35 , basename(get_basename(source_filename_))
36 {}
37
38 static std::string normalize_path(const std::string &str) {
39 const std::string to_look_for[] = {"\\"};
40 const std::string to_replace[] = {"/"};
41 return utils::replace_all_occurrences_of(
42 str,
43 to_look_for, to_look_for + sizeof(to_look_for)/sizeof(to_look_for[0]),
44 to_replace, to_replace + sizeof(to_replace)/sizeof(to_replace[0])
45 );
46 }
47
48 static std::string get_basename(const std::string &source_filename) {
49 std::string basename = normalize_path(source_filename);
50 std::string::size_type basename_pos = basename.rfind('/');
51 if(basename_pos != std::string::npos) {
52 basename = basename.substr(basename_pos+1);
53 }
54 return basename;
55 }
56
57 virtual std::string get_stream_string_representation() const {
58 std::string current_string = output_test_stream::get_stream_string_representation();
59
60 std::string pathname_fixes;
61 {
62 const std::string to_look_for[] = {normalize_path(source_filename)};
63 const std::string to_replace[] = {"xxx/" + basename };
64 pathname_fixes = utils::replace_all_occurrences_of(
65 current_string,
66 to_look_for, to_look_for + sizeof(to_look_for)/sizeof(to_look_for[0]),
67 to_replace, to_replace + sizeof(to_replace)/sizeof(to_replace[0])
68 );
69 }
70
71 std::string other_vars_fixes;
72 {
73 const std::string to_look_for[] = {"time=\"*\"",
74 basename + "(*):",
75 "unknown location(*):",
76 "; testing time: *us\n", // removing this is far more easier than adding a testing time
77 "; testing time: *ms\n",
78 "<TestingTime>*</TestingTime>",
79 "condition 2>3 is not satisfied\n",
80 "condition 2>3 is not satisfied]",
81 };
82
83 const std::string to_replace[] = {"time=\"0.1234\"",
84 basename + ":*:" ,
85 "unknown location:*:",
86 "\n",
87 "\n",
88 "<TestingTime>ZZZ</TestingTime>",
89 "condition 2>3 is not satisfied [2 <= 3]\n",
90 "condition 2>3 is not satisfied [2 <= 3]]",
91 };
92
93 other_vars_fixes = utils::replace_all_occurrences_with_wildcards(
94 pathname_fixes,
95 to_look_for, to_look_for + sizeof(to_look_for)/sizeof(to_look_for[0]),
96 to_replace, to_replace + sizeof(to_replace)/sizeof(to_replace[0])
97 );
98 }
99
100 return other_vars_fixes;
101 }
102
103 };
104
105 #endif /* BOOST_TEST_TESTS_LOGGER_FOR_TESTS_HPP__ */