abseil-cpp/absl/base/raw_logging_test.cc
Go to the documentation of this file.
1 // Copyright 2017 The Abseil Authors.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 // This test serves primarily as a compilation test for base/raw_logging.h.
16 // Raw logging testing is covered by logging_unittest.cc, which is not as
17 // portable as this test.
18 
19 #include "absl/base/internal/raw_logging.h"
20 
21 #include <tuple>
22 
23 #include "gtest/gtest.h"
24 #include "absl/strings/str_cat.h"
25 
26 namespace {
27 
28 TEST(RawLoggingCompilationTest, Log) {
29  ABSL_RAW_LOG(INFO, "RAW INFO: %d", 1);
30  ABSL_RAW_LOG(INFO, "RAW INFO: %d %d", 1, 2);
31  ABSL_RAW_LOG(INFO, "RAW INFO: %d %d %d", 1, 2, 3);
32  ABSL_RAW_LOG(INFO, "RAW INFO: %d %d %d %d", 1, 2, 3, 4);
33  ABSL_RAW_LOG(INFO, "RAW INFO: %d %d %d %d %d", 1, 2, 3, 4, 5);
34  ABSL_RAW_LOG(WARNING, "RAW WARNING: %d", 1);
35  ABSL_RAW_LOG(ERROR, "RAW ERROR: %d", 1);
36 }
37 
38 TEST(RawLoggingCompilationTest, PassingCheck) {
39  ABSL_RAW_CHECK(true, "RAW CHECK");
40 }
41 
42 // Not all platforms support output from raw log, so we don't verify any
43 // particular output for RAW check failures (expecting the empty string
44 // accomplishes this). This test is primarily a compilation test, but we
45 // are verifying process death when EXPECT_DEATH works for a platform.
46 const char kExpectedDeathOutput[] = "";
47 
48 TEST(RawLoggingDeathTest, FailingCheck) {
49  EXPECT_DEATH_IF_SUPPORTED(ABSL_RAW_CHECK(1 == 0, "explanation"),
50  kExpectedDeathOutput);
51 }
52 
53 TEST(RawLoggingDeathTest, LogFatal) {
54  EXPECT_DEATH_IF_SUPPORTED(ABSL_RAW_LOG(FATAL, "my dog has fleas"),
55  kExpectedDeathOutput);
56 }
57 
58 TEST(InternalLog, CompilationTest) {
59  ABSL_INTERNAL_LOG(INFO, "Internal Log");
60  std::string log_msg = "Internal Log";
61  ABSL_INTERNAL_LOG(INFO, log_msg);
62 
63  ABSL_INTERNAL_LOG(INFO, log_msg + " 2");
64 
65  float d = 1.1f;
66  ABSL_INTERNAL_LOG(INFO, absl::StrCat("Internal log ", 3, " + ", d));
67 }
68 
69 TEST(InternalLogDeathTest, FailingCheck) {
70  EXPECT_DEATH_IF_SUPPORTED(ABSL_INTERNAL_CHECK(1 == 0, "explanation"),
71  kExpectedDeathOutput);
72 }
73 
74 TEST(InternalLogDeathTest, LogFatal) {
76  kExpectedDeathOutput);
77 }
78 
79 } // namespace
ABSL_RAW_CHECK
#define ABSL_RAW_CHECK(condition, message)
Definition: abseil-cpp/absl/base/internal/raw_logging.h:59
absl::StrCat
std::string StrCat(const AlphaNum &a, const AlphaNum &b)
Definition: abseil-cpp/absl/strings/str_cat.cc:98
testing::internal::Log
GTEST_API_ void Log(LogSeverity severity, const std::string &message, int stack_frames_to_skip)
Definition: bloaty/third_party/googletest/googlemock/src/gmock-internal-utils.cc:149
ABSL_INTERNAL_CHECK
#define ABSL_INTERNAL_CHECK(condition, message)
Definition: abseil-cpp/absl/base/internal/raw_logging.h:85
testing::internal::string
::std::string string
Definition: bloaty/third_party/protobuf/third_party/googletest/googletest/include/gtest/internal/gtest-port.h:881
TEST
#define TEST(name, init_size,...)
Definition: arena_test.cc:75
python_utils.jobset.INFO
INFO
Definition: jobset.py:111
google::protobuf::WARNING
static const LogLevel WARNING
Definition: bloaty/third_party/protobuf/src/google/protobuf/testing/googletest.h:71
d
static const fe d
Definition: curve25519_tables.h:19
google::protobuf::ERROR
static const LogLevel ERROR
Definition: bloaty/third_party/protobuf/src/google/protobuf/testing/googletest.h:70
EXPECT_DEATH_IF_SUPPORTED
#define EXPECT_DEATH_IF_SUPPORTED(statement, regex)
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest-death-test.h:335
FATAL
#define FATAL(msg)
Definition: task.h:88
ABSL_INTERNAL_LOG
#define ABSL_INTERNAL_LOG(severity, message)
Definition: abseil-cpp/absl/base/internal/raw_logging.h:75
ABSL_RAW_LOG
#define ABSL_RAW_LOG(severity,...)
Definition: abseil-cpp/absl/base/internal/raw_logging.h:44


grpc
Author(s):
autogenerated on Fri May 16 2025 02:59:59