chromium/third_party/abseil-cpp/absl/log/log_macro_hygiene_test.cc

//
// 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.

#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "absl/base/attributes.h"
#include "absl/base/log_severity.h"
#include "absl/log/log.h"
#include "absl/log/scoped_mock_log.h"

namespace {
_;
Eq;

namespace not_absl {

class Dummy {};

// This line tests that local definitions of INFO, WARNING, ERROR, and
// etc don't shadow the global ones used by the logging macros.  If
// they do, the LOG() calls in the tests won't compile, catching the
// bug.
const Dummy INFO, WARNING, ERROR, FATAL, NUM_SEVERITIES;

// These makes sure that the uses of same-named types in the
// implementation of the logging macros are fully qualified.
class string {};
class vector {};
class LogMessage {};
class LogMessageFatal {};
class LogMessageQuietlyFatal {};
class LogMessageVoidify {};
class LogSink {};
class NullStream {};
class NullStreamFatal {};

}  // namespace not_absl

usingnamespacenot_absl;  // NOLINT

// Tests for LOG(LEVEL(()).

TEST(LogHygieneTest, WorksForQualifiedSeverity) {}

TEST(LogHygieneTest, WorksWithAlternativeINFOSymbol) {}

TEST(LogHygieneTest, WorksWithAlternativeWARNINGSymbol) {}

TEST(LogHygieneTest, WorksWithAlternativeERRORSymbol) {}

TEST(LogHygieneTest, WorksWithAlternativeLEVELSymbol) {}

#define INFO
#ifdef NDEBUG
constexpr bool IsOptimized = false;
#else
constexpr bool IsOptimized =;
#endif

TEST(LogHygieneTest, WorksWithINFODefined) {}

#undef INFO

#define _INFO
TEST(LogHygieneTest, WorksWithUnderscoreINFODefined) {}
#undef _INFO

TEST(LogHygieneTest, ExpressionEvaluationInLEVELSeverity) {}

TEST(LogHygieneTest, ExpressionEvaluationInStreamedMessage) {}

// Tests that macros are usable in unbraced switch statements.
// -----------------------------------------------------------

class UnbracedSwitchCompileTest {};

}  // namespace