#ifndef ABSL_LOG_LOG_BASIC_TEST_IMPL_H_
#define ABSL_LOG_LOG_BASIC_TEST_IMPL_H_
#ifndef ABSL_TEST_LOG
#error ABSL_TEST_LOG must be defined for these tests to work.
#endif
#ifndef ABSL_TEST_DLOG
#error ABSL_TEST_DLOG must be defined for these tests to work.
#endif
#include <cerrno>
#include <sstream>
#include <string>
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "absl/base/internal/sysinfo.h"
#include "absl/base/log_severity.h"
#include "absl/log/globals.h"
#include "absl/log/internal/globals.h"
#include "absl/log/internal/test_actions.h"
#include "absl/log/internal/test_helpers.h"
#include "absl/log/internal/test_matchers.h"
#include "absl/log/log_entry.h"
#include "absl/log/scoped_mock_log.h"
namespace absl_log_internal {
#if GTEST_HAS_DEATH_TEST
DeathTestExpectedLogging;
DeathTestUnexpectedLogging;
DeathTestValidateExpectations;
DiedOfFatal;
DiedOfQFatal;
#endif
InMatchWindow;
LoggingEnabledAt;
LogSeverity;
Prefix;
SourceBasename;
SourceFilename;
SourceLine;
Stacktrace;
TextMessage;
ThreadID;
Timestamp;
Verbosity;
AnyNumber;
Eq;
IsEmpty;
IsTrue;
class BasicLogTest : public testing::TestWithParam<absl::LogSeverityAtLeast> { … };
std::string ThresholdName(
testing::TestParamInfo<absl::LogSeverityAtLeast> severity) { … }
INSTANTIATE_TEST_SUITE_P(…);
TEST_P(BasicLogTest, Info) { … }
TEST_P(BasicLogTest, Warning) { … }
TEST_P(BasicLogTest, Error) { … }
#if GTEST_HAS_DEATH_TEST
BasicLogDeathTest;
INSTANTIATE_TEST_SUITE_P(…);
TEST_P(BasicLogDeathTest, Fatal) { … }
TEST_P(BasicLogDeathTest, QFatal) { … }
#endif
#ifdef NDEBUG
TEST_P(BasicLogTest, DFatal) {
absl::log_internal::ScopedMinLogLevel scoped_min_log_level(GetParam());
absl::ScopedMockLog test_sink(absl::MockLogDefault::kDisallowUnexpected);
const int log_line = __LINE__ + 1;
auto do_log = [] { ABSL_TEST_LOG(DFATAL) << "hello world"; };
if (LoggingEnabledAt(absl::LogSeverity::kError)) {
EXPECT_CALL(
test_sink,
Send(AllOf(
SourceFilename(Eq(__FILE__)),
SourceBasename(Eq("log_basic_test_impl.inc")),
SourceLine(Eq(log_line)), Prefix(IsTrue()),
LogSeverity(Eq(absl::LogSeverity::kError)),
Timestamp(InMatchWindow()),
ThreadID(Eq(absl::base_internal::GetTID())),
TextMessage(Eq("hello world")),
Verbosity(Eq(absl::LogEntry::kNoVerbosityLevel)),
ENCODED_MESSAGE(MatchesEvent(
Eq(__FILE__), Eq(log_line), InMatchWindow(),
Eq(logging::proto::ERROR), Eq(absl::base_internal::GetTID()),
ElementsAre(EqualsProto(R"pb(literal: "hello world")pb")))),
Stacktrace(IsEmpty()))));
}
test_sink.StartCapturingLogs();
do_log();
}
#elif GTEST_HAS_DEATH_TEST
TEST_P(BasicLogDeathTest, DFatal) { … }
#endif
#ifndef NDEBUG
TEST_P(BasicLogTest, DFatalIsCancellable) { … }
#if GTEST_HAS_DEATH_TEST
TEST_P(BasicLogDeathTest, DLogFatalIsNotCancellable) { … }
#endif
#endif
TEST_P(BasicLogTest, Level) { … }
#if GTEST_HAS_DEATH_TEST
TEST_P(BasicLogDeathTest, Level) { … }
#endif
TEST_P(BasicLogTest, LevelClampsNegativeValues) { … }
TEST_P(BasicLogTest, LevelClampsLargeValues) { … }
TEST(ErrnoPreservationTest, InSeverityExpression) { … }
TEST(ErrnoPreservationTest, InStreamedExpression) { … }
TEST(ErrnoPreservationTest, AfterStatement) { … }
class UnusedVariableWarningCompileTest { … };
}
#endif