raw_logging_test.cc
Go to the documentation of this file.
00001 // Copyright 2017 The Abseil Authors.
00002 //
00003 // Licensed under the Apache License, Version 2.0 (the "License");
00004 // you may not use this file except in compliance with the License.
00005 // You may obtain a copy of the License at
00006 //
00007 //      https://www.apache.org/licenses/LICENSE-2.0
00008 //
00009 // Unless required by applicable law or agreed to in writing, software
00010 // distributed under the License is distributed on an "AS IS" BASIS,
00011 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00012 // See the License for the specific language governing permissions and
00013 // limitations under the License.
00014 
00015 // This test serves primarily as a compilation test for base/raw_logging.h.
00016 // Raw logging testing is covered by logging_unittest.cc, which is not as
00017 // portable as this test.
00018 
00019 #include "absl/base/internal/raw_logging.h"
00020 
00021 #include <tuple>
00022 
00023 #include "gtest/gtest.h"
00024 #include "absl/strings/str_cat.h"
00025 
00026 namespace {
00027 
00028 TEST(RawLoggingCompilationTest, Log) {
00029   ABSL_RAW_LOG(INFO, "RAW INFO: %d", 1);
00030   ABSL_RAW_LOG(INFO, "RAW INFO: %d %d", 1, 2);
00031   ABSL_RAW_LOG(INFO, "RAW INFO: %d %d %d", 1, 2, 3);
00032   ABSL_RAW_LOG(INFO, "RAW INFO: %d %d %d %d", 1, 2, 3, 4);
00033   ABSL_RAW_LOG(INFO, "RAW INFO: %d %d %d %d %d", 1, 2, 3, 4, 5);
00034   ABSL_RAW_LOG(WARNING, "RAW WARNING: %d", 1);
00035   ABSL_RAW_LOG(ERROR, "RAW ERROR: %d", 1);
00036 }
00037 
00038 TEST(RawLoggingCompilationTest, PassingCheck) {
00039   ABSL_RAW_CHECK(true, "RAW CHECK");
00040 }
00041 
00042 // Not all platforms support output from raw log, so we don't verify any
00043 // particular output for RAW check failures (expecting the empty string
00044 // accomplishes this).  This test is primarily a compilation test, but we
00045 // are verifying process death when EXPECT_DEATH works for a platform.
00046 const char kExpectedDeathOutput[] = "";
00047 
00048 TEST(RawLoggingDeathTest, FailingCheck) {
00049   EXPECT_DEATH_IF_SUPPORTED(ABSL_RAW_CHECK(1 == 0, "explanation"),
00050                             kExpectedDeathOutput);
00051 }
00052 
00053 TEST(RawLoggingDeathTest, LogFatal) {
00054   EXPECT_DEATH_IF_SUPPORTED(ABSL_RAW_LOG(FATAL, "my dog has fleas"),
00055                             kExpectedDeathOutput);
00056 }
00057 
00058 TEST(InternalLog, CompilationTest) {
00059   ABSL_INTERNAL_LOG(INFO, "Internal Log");
00060   std::string log_msg = "Internal Log";
00061   ABSL_INTERNAL_LOG(INFO, log_msg);
00062 
00063   ABSL_INTERNAL_LOG(INFO, log_msg + " 2");
00064 
00065   float d = 1.1f;
00066   ABSL_INTERNAL_LOG(INFO, absl::StrCat("Internal log ", 3, " + ", d));
00067 }
00068 
00069 TEST(InternalLogDeathTest, FailingCheck) {
00070   EXPECT_DEATH_IF_SUPPORTED(ABSL_INTERNAL_CHECK(1 == 0, "explanation"),
00071                             kExpectedDeathOutput);
00072 }
00073 
00074 TEST(InternalLogDeathTest, LogFatal) {
00075   EXPECT_DEATH_IF_SUPPORTED(ABSL_INTERNAL_LOG(FATAL, "my dog has fleas"),
00076                             kExpectedDeathOutput);
00077 }
00078 
00079 }  // namespace


abseil_cpp
Author(s):
autogenerated on Wed Jun 19 2019 19:42:15