1*9356374aSAndroid Build Coastguard Worker // Copyright 2022 The Abseil Authors. 2*9356374aSAndroid Build Coastguard Worker // 3*9356374aSAndroid Build Coastguard Worker // Licensed under the Apache License, Version 2.0 (the "License"); 4*9356374aSAndroid Build Coastguard Worker // you may not use this file except in compliance with the License. 5*9356374aSAndroid Build Coastguard Worker // You may obtain a copy of the License at 6*9356374aSAndroid Build Coastguard Worker // 7*9356374aSAndroid Build Coastguard Worker // https://www.apache.org/licenses/LICENSE-2.0 8*9356374aSAndroid Build Coastguard Worker // 9*9356374aSAndroid Build Coastguard Worker // Unless required by applicable law or agreed to in writing, software 10*9356374aSAndroid Build Coastguard Worker // distributed under the License is distributed on an "AS IS" BASIS, 11*9356374aSAndroid Build Coastguard Worker // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12*9356374aSAndroid Build Coastguard Worker // See the License for the specific language governing permissions and 13*9356374aSAndroid Build Coastguard Worker // limitations under the License. 14*9356374aSAndroid Build Coastguard Worker // 15*9356374aSAndroid Build Coastguard Worker // ----------------------------------------------------------------------------- 16*9356374aSAndroid Build Coastguard Worker // File: log/internal/test_matchers.h 17*9356374aSAndroid Build Coastguard Worker // ----------------------------------------------------------------------------- 18*9356374aSAndroid Build Coastguard Worker // 19*9356374aSAndroid Build Coastguard Worker // This file declares Googletest's matchers used in the Abseil Logging library 20*9356374aSAndroid Build Coastguard Worker // unit tests. 21*9356374aSAndroid Build Coastguard Worker 22*9356374aSAndroid Build Coastguard Worker #ifndef ABSL_LOG_INTERNAL_TEST_MATCHERS_H_ 23*9356374aSAndroid Build Coastguard Worker #define ABSL_LOG_INTERNAL_TEST_MATCHERS_H_ 24*9356374aSAndroid Build Coastguard Worker 25*9356374aSAndroid Build Coastguard Worker #include <iosfwd> 26*9356374aSAndroid Build Coastguard Worker #include <sstream> 27*9356374aSAndroid Build Coastguard Worker #include <string> 28*9356374aSAndroid Build Coastguard Worker 29*9356374aSAndroid Build Coastguard Worker #include "gmock/gmock.h" 30*9356374aSAndroid Build Coastguard Worker #include "gtest/gtest.h" 31*9356374aSAndroid Build Coastguard Worker #include "absl/base/config.h" 32*9356374aSAndroid Build Coastguard Worker #include "absl/base/log_severity.h" 33*9356374aSAndroid Build Coastguard Worker #include "absl/log/internal/test_helpers.h" 34*9356374aSAndroid Build Coastguard Worker #include "absl/log/log_entry.h" 35*9356374aSAndroid Build Coastguard Worker #include "absl/strings/string_view.h" 36*9356374aSAndroid Build Coastguard Worker #include "absl/time/time.h" 37*9356374aSAndroid Build Coastguard Worker 38*9356374aSAndroid Build Coastguard Worker namespace absl { 39*9356374aSAndroid Build Coastguard Worker ABSL_NAMESPACE_BEGIN 40*9356374aSAndroid Build Coastguard Worker namespace log_internal { 41*9356374aSAndroid Build Coastguard Worker // In some configurations, Googletest's string matchers (e.g. 42*9356374aSAndroid Build Coastguard Worker // `::testing::EndsWith`) need help to match `absl::string_view`. 43*9356374aSAndroid Build Coastguard Worker ::testing::Matcher<absl::string_view> AsString( 44*9356374aSAndroid Build Coastguard Worker const ::testing::Matcher<const std::string&>& str_matcher); 45*9356374aSAndroid Build Coastguard Worker 46*9356374aSAndroid Build Coastguard Worker // These matchers correspond to the components of `absl::LogEntry`. 47*9356374aSAndroid Build Coastguard Worker ::testing::Matcher<const absl::LogEntry&> SourceFilename( 48*9356374aSAndroid Build Coastguard Worker const ::testing::Matcher<absl::string_view>& source_filename); 49*9356374aSAndroid Build Coastguard Worker ::testing::Matcher<const absl::LogEntry&> SourceBasename( 50*9356374aSAndroid Build Coastguard Worker const ::testing::Matcher<absl::string_view>& source_basename); 51*9356374aSAndroid Build Coastguard Worker // Be careful with this one; multi-line statements using `__LINE__` evaluate 52*9356374aSAndroid Build Coastguard Worker // differently on different platforms. In particular, the MSVC implementation 53*9356374aSAndroid Build Coastguard Worker // of `EXPECT_DEATH` returns the line number of the macro expansion to all lines 54*9356374aSAndroid Build Coastguard Worker // within the code block that's expected to die. 55*9356374aSAndroid Build Coastguard Worker ::testing::Matcher<const absl::LogEntry&> SourceLine( 56*9356374aSAndroid Build Coastguard Worker const ::testing::Matcher<int>& source_line); 57*9356374aSAndroid Build Coastguard Worker ::testing::Matcher<const absl::LogEntry&> Prefix( 58*9356374aSAndroid Build Coastguard Worker const ::testing::Matcher<bool>& prefix); 59*9356374aSAndroid Build Coastguard Worker ::testing::Matcher<const absl::LogEntry&> LogSeverity( 60*9356374aSAndroid Build Coastguard Worker const ::testing::Matcher<absl::LogSeverity>& log_severity); 61*9356374aSAndroid Build Coastguard Worker ::testing::Matcher<const absl::LogEntry&> Timestamp( 62*9356374aSAndroid Build Coastguard Worker const ::testing::Matcher<absl::Time>& timestamp); 63*9356374aSAndroid Build Coastguard Worker // Matches if the `LogEntry`'s timestamp falls after the instantiation of this 64*9356374aSAndroid Build Coastguard Worker // matcher and before its execution, as is normal when used with EXPECT_CALL. 65*9356374aSAndroid Build Coastguard Worker ::testing::Matcher<absl::Time> InMatchWindow(); 66*9356374aSAndroid Build Coastguard Worker ::testing::Matcher<const absl::LogEntry&> ThreadID( 67*9356374aSAndroid Build Coastguard Worker const ::testing::Matcher<absl::LogEntry::tid_t>&); 68*9356374aSAndroid Build Coastguard Worker ::testing::Matcher<const absl::LogEntry&> TextMessageWithPrefixAndNewline( 69*9356374aSAndroid Build Coastguard Worker const ::testing::Matcher<absl::string_view>& 70*9356374aSAndroid Build Coastguard Worker text_message_with_prefix_and_newline); 71*9356374aSAndroid Build Coastguard Worker ::testing::Matcher<const absl::LogEntry&> TextMessageWithPrefix( 72*9356374aSAndroid Build Coastguard Worker const ::testing::Matcher<absl::string_view>& text_message_with_prefix); 73*9356374aSAndroid Build Coastguard Worker ::testing::Matcher<const absl::LogEntry&> TextMessage( 74*9356374aSAndroid Build Coastguard Worker const ::testing::Matcher<absl::string_view>& text_message); 75*9356374aSAndroid Build Coastguard Worker ::testing::Matcher<const absl::LogEntry&> TextPrefix( 76*9356374aSAndroid Build Coastguard Worker const ::testing::Matcher<absl::string_view>& text_prefix); 77*9356374aSAndroid Build Coastguard Worker ::testing::Matcher<const absl::LogEntry&> Verbosity( 78*9356374aSAndroid Build Coastguard Worker const ::testing::Matcher<int>& verbosity); 79*9356374aSAndroid Build Coastguard Worker ::testing::Matcher<const absl::LogEntry&> Stacktrace( 80*9356374aSAndroid Build Coastguard Worker const ::testing::Matcher<absl::string_view>& stacktrace); 81*9356374aSAndroid Build Coastguard Worker // Behaves as `Eq(stream.str())`, but produces better failure messages. 82*9356374aSAndroid Build Coastguard Worker ::testing::Matcher<absl::string_view> MatchesOstream( 83*9356374aSAndroid Build Coastguard Worker const std::ostringstream& stream); 84*9356374aSAndroid Build Coastguard Worker ::testing::Matcher<const std::string&> DeathTestValidateExpectations(); 85*9356374aSAndroid Build Coastguard Worker 86*9356374aSAndroid Build Coastguard Worker ::testing::Matcher<const absl::LogEntry&> RawEncodedMessage( 87*9356374aSAndroid Build Coastguard Worker const ::testing::Matcher<absl::string_view>& raw_encoded_message); 88*9356374aSAndroid Build Coastguard Worker #define ENCODED_MESSAGE(message_matcher) ::testing::_ 89*9356374aSAndroid Build Coastguard Worker 90*9356374aSAndroid Build Coastguard Worker } // namespace log_internal 91*9356374aSAndroid Build Coastguard Worker ABSL_NAMESPACE_END 92*9356374aSAndroid Build Coastguard Worker } // namespace absl 93*9356374aSAndroid Build Coastguard Worker 94*9356374aSAndroid Build Coastguard Worker #endif // ABSL_LOG_INTERNAL_TEST_MATCHERS_H_ 95