Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Note: this test tests LOG_V and LOG_E since all other logs are expressed | 5 // Note: this test tests LOG_V and LOG_E since all other logs are expressed |
| 6 // in forms of them. LOG is also tested for good measure. | 6 // in forms of them. LOG is also tested for good measure. |
| 7 // Also note that we are only allowed to call InitLogging() twice so the test | 7 // Also note that we are only allowed to call InitLogging() twice so the test |
| 8 // cases are more dense than normal. | 8 // cases are more dense than normal. |
| 9 | 9 |
| 10 // We must include Chromium headers before including the overrides header | 10 // We must include Chromium headers before including the overrides header |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 69 return false; | 69 return false; |
| 70 } | 70 } |
| 71 EXPECT_TRUE(VLOG_IS_ON(verbosity_level)); | 71 EXPECT_TRUE(VLOG_IS_ON(verbosity_level)); |
| 72 EXPECT_FALSE(VLOG_IS_ON(verbosity_level + 1)); | 72 EXPECT_FALSE(VLOG_IS_ON(verbosity_level + 1)); |
| 73 return true; | 73 return true; |
| 74 } | 74 } |
| 75 | 75 |
| 76 TEST(LibjingleLogTest, DefaultConfiguration) { | 76 TEST(LibjingleLogTest, DefaultConfiguration) { |
| 77 ASSERT_TRUE(Initialize(kDefaultVerbosity)); | 77 ASSERT_TRUE(Initialize(kDefaultVerbosity)); |
| 78 | 78 |
| 79 // In the default configuration nothing should be logged. | 79 // In the default configuration only warnings and errors should be logged. |
| 80 LOG_V(rtc::LS_ERROR) << AsString(rtc::LS_ERROR); | 80 LOG_V(rtc::LS_ERROR) << AsString(rtc::LS_ERROR); |
| 81 LOG_V(rtc::LS_WARNING) << AsString(rtc::LS_WARNING); | 81 LOG_V(rtc::LS_WARNING) << AsString(rtc::LS_WARNING); |
| 82 LOG_V(rtc::LS_INFO) << AsString(rtc::LS_INFO); | 82 LOG_V(rtc::LS_INFO) << AsString(rtc::LS_INFO); |
| 83 LOG_V(rtc::LS_VERBOSE) << AsString(rtc::LS_VERBOSE); | 83 LOG_V(rtc::LS_VERBOSE) << AsString(rtc::LS_VERBOSE); |
| 84 LOG_V(rtc::LS_SENSITIVE) << AsString(rtc::LS_SENSITIVE); | 84 LOG_V(rtc::LS_SENSITIVE) << AsString(rtc::LS_SENSITIVE); |
| 85 | 85 |
| 86 // Read file to string. | 86 // Read file to string. |
| 87 base::FilePath file_path(log_file_name); | 87 base::FilePath file_path(log_file_name); |
| 88 std::string contents_of_file; | 88 std::string contents_of_file; |
| 89 base::ReadFileToString(file_path, &contents_of_file); | 89 base::ReadFileToString(file_path, &contents_of_file); |
| 90 | 90 |
| 91 // Make sure string contains the expected values. | 91 // Make sure string contains the expected values. |
| 92 EXPECT_FALSE(ContainsString(contents_of_file, AsString(rtc::LS_ERROR))); | 92 EXPECT_TRUE(ContainsString(contents_of_file, AsString(rtc::LS_ERROR))); |
| 93 EXPECT_FALSE(ContainsString(contents_of_file, | 93 EXPECT_TRUE(ContainsString(contents_of_file, AsString(rtc::LS_WARNING))); |
| 94 AsString(rtc::LS_WARNING))); | |
| 95 EXPECT_FALSE(ContainsString(contents_of_file, AsString(rtc::LS_INFO))); | 94 EXPECT_FALSE(ContainsString(contents_of_file, AsString(rtc::LS_INFO))); |
| 96 EXPECT_FALSE(ContainsString(contents_of_file, | 95 EXPECT_FALSE(ContainsString(contents_of_file, |
| 97 AsString(rtc::LS_VERBOSE))); | 96 AsString(rtc::LS_VERBOSE))); |
| 98 EXPECT_FALSE(ContainsString(contents_of_file, | 97 EXPECT_FALSE(ContainsString(contents_of_file, |
| 99 AsString(rtc::LS_SENSITIVE))); | 98 AsString(rtc::LS_SENSITIVE))); |
| 100 } | 99 } |
| 101 | 100 |
| 102 TEST(LibjingleLogTest, InfoConfiguration) { | 101 TEST(LibjingleLogTest, InfoConfiguration) { |
| 103 ASSERT_TRUE(Initialize(rtc::LS_INFO)); | 102 ASSERT_TRUE(Initialize(0)); // 0 == Chrome's 'info' level. |
|
tommi (sloooow) - chröme
2015/05/14 02:27:23
rtc::LS_INFO was incorrect since rtc::LS_INFO == 3
| |
| 104 | 103 |
| 105 // In this configuration everything lower or equal to LS_INFO should be | 104 // In this configuration everything lower or equal to LS_INFO should be |
| 106 // logged. | 105 // logged. |
| 107 LOG_V(rtc::LS_ERROR) << AsString(rtc::LS_ERROR); | 106 LOG_V(rtc::LS_ERROR) << AsString(rtc::LS_ERROR); |
| 108 LOG_V(rtc::LS_WARNING) << AsString(rtc::LS_WARNING); | 107 LOG_V(rtc::LS_WARNING) << AsString(rtc::LS_WARNING); |
| 109 LOG_V(rtc::LS_INFO) << AsString(rtc::LS_INFO); | 108 LOG_V(rtc::LS_INFO) << AsString(rtc::LS_INFO); |
| 110 LOG_V(rtc::LS_VERBOSE) << AsString(rtc::LS_VERBOSE); | 109 LOG_V(rtc::LS_VERBOSE) << AsString(rtc::LS_VERBOSE); |
| 111 LOG_V(rtc::LS_SENSITIVE) << AsString(rtc::LS_SENSITIVE); | 110 LOG_V(rtc::LS_SENSITIVE) << AsString(rtc::LS_SENSITIVE); |
| 112 | 111 |
| 113 // Read file to string. | 112 // Read file to string. |
| 114 base::FilePath file_path(log_file_name); | 113 base::FilePath file_path(log_file_name); |
| 115 std::string contents_of_file; | 114 std::string contents_of_file; |
| 116 base::ReadFileToString(file_path, &contents_of_file); | 115 base::ReadFileToString(file_path, &contents_of_file); |
| 117 | 116 |
| 118 // Make sure string contains the expected values. | 117 // Make sure string contains the expected values. |
| 119 EXPECT_TRUE(ContainsString(contents_of_file, AsString(rtc::LS_ERROR))); | 118 EXPECT_TRUE(ContainsString(contents_of_file, AsString(rtc::LS_ERROR))); |
| 120 EXPECT_TRUE(ContainsString(contents_of_file, | 119 EXPECT_TRUE(ContainsString(contents_of_file, |
| 121 AsString(rtc::LS_WARNING))); | 120 AsString(rtc::LS_WARNING))); |
| 122 EXPECT_TRUE(ContainsString(contents_of_file, AsString(rtc::LS_INFO))); | 121 EXPECT_FALSE(ContainsString(contents_of_file, AsString(rtc::LS_INFO))); |
| 123 EXPECT_FALSE(ContainsString(contents_of_file, | 122 EXPECT_FALSE(ContainsString(contents_of_file, |
| 124 AsString(rtc::LS_VERBOSE))); | 123 AsString(rtc::LS_VERBOSE))); |
| 125 EXPECT_FALSE(ContainsString(contents_of_file, | 124 EXPECT_FALSE(ContainsString(contents_of_file, |
| 126 AsString(rtc::LS_SENSITIVE))); | 125 AsString(rtc::LS_SENSITIVE))); |
| 127 | 126 |
| 128 // Also check that the log is proper. | 127 // Also check that the log is proper. |
| 129 EXPECT_TRUE(ContainsString(contents_of_file, "logging_unittest.cc")); | 128 EXPECT_TRUE(ContainsString(contents_of_file, "logging_unittest.cc")); |
| 130 EXPECT_FALSE(ContainsString(contents_of_file, "logging.h")); | 129 EXPECT_FALSE(ContainsString(contents_of_file, "logging.h")); |
| 131 EXPECT_FALSE(ContainsString(contents_of_file, "logging.cc")); | 130 EXPECT_FALSE(ContainsString(contents_of_file, "logging.cc")); |
| 132 } | 131 } |
| 133 | 132 |
| 134 TEST(LibjingleLogTest, LogEverythingConfiguration) { | 133 TEST(LibjingleLogTest, LogEverythingConfiguration) { |
| 135 ASSERT_TRUE(Initialize(rtc::LS_SENSITIVE)); | 134 ASSERT_TRUE(Initialize(2)); // verbosity at level 2 allows LS_SENSITIVE. |
|
tommi (sloooow) - chröme
2015/05/14 02:27:23
This was also incorrect since LS_SENSITIVE==5
| |
| 136 | 135 |
| 137 // In this configuration everything should be logged. | 136 // In this configuration everything should be logged. |
| 138 LOG_V(rtc::LS_ERROR) << AsString(rtc::LS_ERROR); | 137 LOG_V(rtc::LS_ERROR) << AsString(rtc::LS_ERROR); |
| 139 LOG_V(rtc::LS_WARNING) << AsString(rtc::LS_WARNING); | 138 LOG_V(rtc::LS_WARNING) << AsString(rtc::LS_WARNING); |
| 140 LOG(LS_INFO) << AsString(rtc::LS_INFO); | 139 LOG(LS_INFO) << AsString(rtc::LS_INFO); |
| 141 static const int kFakeError = 1; | 140 static const int kFakeError = 1; |
| 142 LOG_E(LS_INFO, EN, kFakeError) << "LOG_E(" << AsString(rtc::LS_INFO) << | 141 LOG_E(LS_INFO, EN, kFakeError) << "LOG_E(" << AsString(rtc::LS_INFO) << |
| 143 ")"; | 142 ")"; |
| 144 LOG_V(rtc::LS_VERBOSE) << AsString(rtc::LS_VERBOSE); | 143 LOG_V(rtc::LS_VERBOSE) << AsString(rtc::LS_VERBOSE); |
| 145 LOG_V(rtc::LS_SENSITIVE) << AsString(rtc::LS_SENSITIVE); | 144 LOG_V(rtc::LS_SENSITIVE) << AsString(rtc::LS_SENSITIVE); |
| 146 | 145 |
| 147 // Read file to string. | 146 // Read file to string. |
| 148 base::FilePath file_path(log_file_name); | 147 base::FilePath file_path(log_file_name); |
| 149 std::string contents_of_file; | 148 std::string contents_of_file; |
| 150 base::ReadFileToString(file_path, &contents_of_file); | 149 base::ReadFileToString(file_path, &contents_of_file); |
| 151 | 150 |
| 152 // Make sure string contains the expected values. | 151 // Make sure string contains the expected values. |
| 153 EXPECT_TRUE(ContainsString(contents_of_file, AsString(rtc::LS_ERROR))); | 152 EXPECT_TRUE(ContainsString(contents_of_file, AsString(rtc::LS_ERROR))); |
| 154 EXPECT_TRUE(ContainsString(contents_of_file, | 153 EXPECT_TRUE(ContainsString(contents_of_file, |
| 155 AsString(rtc::LS_WARNING))); | 154 AsString(rtc::LS_WARNING))); |
| 156 EXPECT_TRUE(ContainsString(contents_of_file, AsString(rtc::LS_INFO))); | 155 EXPECT_TRUE(ContainsString(contents_of_file, AsString(rtc::LS_INFO))); |
| 157 // LOG_E | 156 // LOG_E |
| 158 EXPECT_TRUE(ContainsString(contents_of_file, strerror(kFakeError))); | 157 EXPECT_TRUE(ContainsString(contents_of_file, strerror(kFakeError))); |
| 159 EXPECT_TRUE(ContainsString(contents_of_file, | 158 EXPECT_TRUE(ContainsString(contents_of_file, |
| 160 AsString(rtc::LS_VERBOSE))); | 159 AsString(rtc::LS_VERBOSE))); |
| 161 EXPECT_TRUE(ContainsString(contents_of_file, | 160 EXPECT_TRUE(ContainsString(contents_of_file, |
| 162 AsString(rtc::LS_SENSITIVE))); | 161 AsString(rtc::LS_SENSITIVE))); |
| 163 } | 162 } |
| OLD | NEW |