chromium/third_party/abseil-cpp/absl/log/log_basic_test_impl.inc

//
// Copyright 2022 The Abseil Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// The testcases in this file are expected to pass or be skipped with any value
// of ABSL_MIN_LOG_LEVEL

#ifndef ABSL_LOG_LOG_BASIC_TEST_IMPL_H_
#define ABSL_LOG_LOG_BASIC_TEST_IMPL_H_

// Verify that both sets of macros behave identically by parameterizing the
// entire test file.
#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) {}

// Tests that using a variable/parameter in a logging statement suppresses
// unused-variable/parameter warnings.
// -----------------------------------------------------------------------
class UnusedVariableWarningCompileTest {};

}  // namespace absl_log_internal

#endif  // ABSL_LOG_LOG_BASIC_TEST_IMPL_H_