Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-16 09:40:53

0001 // Copyright 2022 The Abseil Authors.
0002 //
0003 // Licensed under the Apache License, Version 2.0 (the "License");
0004 // you may not use this file except in compliance with the License.
0005 // You may obtain a copy of the License at
0006 //
0007 //      https://www.apache.org/licenses/LICENSE-2.0
0008 //
0009 // Unless required by applicable law or agreed to in writing, software
0010 // distributed under the License is distributed on an "AS IS" BASIS,
0011 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0012 // See the License for the specific language governing permissions and
0013 // limitations under the License.
0014 //
0015 // -----------------------------------------------------------------------------
0016 // File: log/internal/test_matchers.h
0017 // -----------------------------------------------------------------------------
0018 //
0019 // This file declares Googletest's matchers used in the Abseil Logging library
0020 // unit tests.
0021 
0022 #ifndef ABSL_LOG_INTERNAL_TEST_MATCHERS_H_
0023 #define ABSL_LOG_INTERNAL_TEST_MATCHERS_H_
0024 
0025 #include <iosfwd>
0026 #include <sstream>
0027 #include <string>
0028 
0029 #include "gmock/gmock.h"
0030 #include "gtest/gtest.h"
0031 #include "absl/base/config.h"
0032 #include "absl/base/log_severity.h"
0033 #include "absl/log/internal/test_helpers.h"
0034 #include "absl/log/log_entry.h"
0035 #include "absl/strings/string_view.h"
0036 #include "absl/time/time.h"
0037 
0038 namespace absl {
0039 ABSL_NAMESPACE_BEGIN
0040 namespace log_internal {
0041 // In some configurations, Googletest's string matchers (e.g.
0042 // `::testing::EndsWith`) need help to match `absl::string_view`.
0043 ::testing::Matcher<absl::string_view> AsString(
0044     const ::testing::Matcher<const std::string&>& str_matcher);
0045 
0046 // These matchers correspond to the components of `absl::LogEntry`.
0047 ::testing::Matcher<const absl::LogEntry&> SourceFilename(
0048     const ::testing::Matcher<absl::string_view>& source_filename);
0049 ::testing::Matcher<const absl::LogEntry&> SourceBasename(
0050     const ::testing::Matcher<absl::string_view>& source_basename);
0051 // Be careful with this one; multi-line statements using `__LINE__` evaluate
0052 // differently on different platforms.  In particular, the MSVC implementation
0053 // of `EXPECT_DEATH` returns the line number of the macro expansion to all lines
0054 // within the code block that's expected to die.
0055 ::testing::Matcher<const absl::LogEntry&> SourceLine(
0056     const ::testing::Matcher<int>& source_line);
0057 ::testing::Matcher<const absl::LogEntry&> Prefix(
0058     const ::testing::Matcher<bool>& prefix);
0059 ::testing::Matcher<const absl::LogEntry&> LogSeverity(
0060     const ::testing::Matcher<absl::LogSeverity>& log_severity);
0061 ::testing::Matcher<const absl::LogEntry&> Timestamp(
0062     const ::testing::Matcher<absl::Time>& timestamp);
0063 // Matches if the `LogEntry`'s timestamp falls after the instantiation of this
0064 // matcher and before its execution, as is normal when used with EXPECT_CALL.
0065 ::testing::Matcher<absl::Time> InMatchWindow();
0066 ::testing::Matcher<const absl::LogEntry&> ThreadID(
0067     const ::testing::Matcher<absl::LogEntry::tid_t>&);
0068 ::testing::Matcher<const absl::LogEntry&> TextMessageWithPrefixAndNewline(
0069     const ::testing::Matcher<absl::string_view>&
0070         text_message_with_prefix_and_newline);
0071 ::testing::Matcher<const absl::LogEntry&> TextMessageWithPrefix(
0072     const ::testing::Matcher<absl::string_view>& text_message_with_prefix);
0073 ::testing::Matcher<const absl::LogEntry&> TextMessage(
0074     const ::testing::Matcher<absl::string_view>& text_message);
0075 ::testing::Matcher<const absl::LogEntry&> TextPrefix(
0076     const ::testing::Matcher<absl::string_view>& text_prefix);
0077 ::testing::Matcher<const absl::LogEntry&> Verbosity(
0078     const ::testing::Matcher<int>& verbosity);
0079 ::testing::Matcher<const absl::LogEntry&> Stacktrace(
0080     const ::testing::Matcher<absl::string_view>& stacktrace);
0081 // Behaves as `Eq(stream.str())`, but produces better failure messages.
0082 ::testing::Matcher<absl::string_view> MatchesOstream(
0083     const std::ostringstream& stream);
0084 ::testing::Matcher<const std::string&> DeathTestValidateExpectations();
0085 
0086 ::testing::Matcher<const absl::LogEntry&> RawEncodedMessage(
0087     const ::testing::Matcher<absl::string_view>& raw_encoded_message);
0088 #define ENCODED_MESSAGE(message_matcher) ::testing::_
0089 
0090 }  // namespace log_internal
0091 ABSL_NAMESPACE_END
0092 }  // namespace absl
0093 
0094 #endif  // ABSL_LOG_INTERNAL_TEST_MATCHERS_H_