tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

raw_logging_test.cc (2811B)


      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, LogWithNulls) {
     39  ABSL_RAW_LOG(INFO, "RAW INFO: %s%c%s", "Hello", 0, "World");
     40 }
     41 
     42 TEST(RawLoggingCompilationTest, PassingCheck) {
     43  ABSL_RAW_CHECK(true, "RAW CHECK");
     44 }
     45 
     46 // Not all platforms support output from raw log, so we don't verify any
     47 // particular output for RAW check failures (expecting the empty string
     48 // accomplishes this).  This test is primarily a compilation test, but we
     49 // are verifying process death when EXPECT_DEATH works for a platform.
     50 const char kExpectedDeathOutput[] = "";
     51 
     52 TEST(RawLoggingDeathTest, FailingCheck) {
     53  EXPECT_DEATH_IF_SUPPORTED(ABSL_RAW_CHECK(1 == 0, "explanation"),
     54                            kExpectedDeathOutput);
     55 }
     56 
     57 TEST(RawLoggingDeathTest, LogFatal) {
     58  EXPECT_DEATH_IF_SUPPORTED(ABSL_RAW_LOG(FATAL, "my dog has fleas"),
     59                            kExpectedDeathOutput);
     60 }
     61 
     62 TEST(InternalLog, CompilationTest) {
     63  ABSL_INTERNAL_LOG(INFO, "Internal Log");
     64  std::string log_msg = "Internal Log";
     65  ABSL_INTERNAL_LOG(INFO, log_msg);
     66 
     67  ABSL_INTERNAL_LOG(INFO, log_msg + " 2");
     68 
     69  float d = 1.1f;
     70  ABSL_INTERNAL_LOG(INFO, absl::StrCat("Internal log ", 3, " + ", d));
     71 }
     72 
     73 TEST(InternalLogDeathTest, FailingCheck) {
     74  EXPECT_DEATH_IF_SUPPORTED(ABSL_INTERNAL_CHECK(1 == 0, "explanation"),
     75                            kExpectedDeathOutput);
     76 }
     77 
     78 TEST(InternalLogDeathTest, LogFatal) {
     79  EXPECT_DEATH_IF_SUPPORTED(ABSL_INTERNAL_LOG(FATAL, "my dog has fleas"),
     80                            kExpectedDeathOutput);
     81 }
     82 
     83 }  // namespace