raw_logging_test.cc 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. // This test serves primarily as a compilation test for base/raw_logging.h.
  15. // Raw logging testing is covered by logging_unittest.cc, which is not as
  16. // portable as this test.
  17. #include "absl/base/internal/raw_logging.h"
  18. #include <tuple>
  19. #include "gtest/gtest.h"
  20. #include "absl/strings/str_cat.h"
  21. namespace {
  22. TEST(RawLoggingCompilationTest, Log) {
  23. ABSL_RAW_LOG(INFO, "RAW INFO: %d", 1);
  24. ABSL_RAW_LOG(INFO, "RAW INFO: %d %d", 1, 2);
  25. ABSL_RAW_LOG(INFO, "RAW INFO: %d %d %d", 1, 2, 3);
  26. ABSL_RAW_LOG(INFO, "RAW INFO: %d %d %d %d", 1, 2, 3, 4);
  27. ABSL_RAW_LOG(INFO, "RAW INFO: %d %d %d %d %d", 1, 2, 3, 4, 5);
  28. ABSL_RAW_LOG(WARNING, "RAW WARNING: %d", 1);
  29. ABSL_RAW_LOG(ERROR, "RAW ERROR: %d", 1);
  30. }
  31. TEST(RawLoggingCompilationTest, PassingCheck) {
  32. ABSL_RAW_CHECK(true, "RAW CHECK");
  33. }
  34. // Not all platforms support output from raw log, so we don't verify any
  35. // particular output for RAW check failures (expecting the empty string
  36. // accomplishes this). This test is primarily a compilation test, but we
  37. // are verifying process death when EXPECT_DEATH works for a platform.
  38. const char kExpectedDeathOutput[] = "";
  39. TEST(RawLoggingDeathTest, FailingCheck) {
  40. EXPECT_DEATH_IF_SUPPORTED(ABSL_RAW_CHECK(1 == 0, "explanation"),
  41. kExpectedDeathOutput);
  42. }
  43. TEST(RawLoggingDeathTest, LogFatal) {
  44. EXPECT_DEATH_IF_SUPPORTED(ABSL_RAW_LOG(FATAL, "my dog has fleas"),
  45. kExpectedDeathOutput);
  46. }
  47. TEST(InternalLog, CompilationTest) {
  48. ABSL_INTERNAL_LOG(INFO, "Internal Log");
  49. std::string log_msg = "Internal Log";
  50. ABSL_INTERNAL_LOG(INFO, log_msg);
  51. ABSL_INTERNAL_LOG(INFO, log_msg + " 2");
  52. float d = 1.1f;
  53. ABSL_INTERNAL_LOG(INFO, absl::StrCat("Internal log ", 3, " + ", d));
  54. }
  55. TEST(InternalLogDeathTest, FailingCheck) {
  56. EXPECT_DEATH_IF_SUPPORTED(ABSL_INTERNAL_CHECK(1 == 0, "explanation"),
  57. kExpectedDeathOutput);
  58. }
  59. TEST(InternalLogDeathTest, LogFatal) {
  60. EXPECT_DEATH_IF_SUPPORTED(ABSL_INTERNAL_LOG(FATAL, "my dog has fleas"),
  61. kExpectedDeathOutput);
  62. }
  63. } // namespace