Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/sync_file_system/logger.h" | |
| 6 #include "testing/gtest/include/gtest/gtest.h" | |
| 7 | |
| 8 using google_apis::EventLogger; | |
| 9 | |
| 10 namespace sync_file_system { | |
| 11 | |
| 12 namespace { | |
| 13 | |
| 14 // Logs one event at each supported LogSeverity level. | |
| 15 void LogSampleEvents() { | |
| 16 util::Log(logging::LOG_INFO, FROM_HERE, "Info test message"); | |
| 17 util::Log(logging::LOG_WARNING, FROM_HERE, "Warning test message"); | |
| 18 util::Log(logging::LOG_ERROR, FROM_HERE, "Error test message"); | |
| 19 } | |
| 20 | |
| 21 bool ContainsString(std::string contains_string, EventLogger::Event event) { | |
| 22 return event.what.find(contains_string) != std::string::npos; | |
| 23 } | |
| 24 | |
| 25 } // namespace | |
| 26 | |
| 27 class LoggerTest : public testing::Test { | |
| 28 public: | |
| 29 LoggerTest() {} | |
| 30 | |
| 31 virtual void SetUp() OVERRIDE { | |
| 32 logging::SetMinLogLevel(logging::LOG_INFO); | |
| 33 util::ClearLog(); | |
| 34 } | |
| 35 | |
| 36 protected: | |
| 37 DISALLOW_COPY_AND_ASSIGN(LoggerTest); | |
| 38 }; | |
| 39 | |
| 40 TEST_F(LoggerTest, TestLogSeverityLevels) { | |
| 41 // Check that all messages are logged when log LogSeverity is set to INFO. | |
| 42 logging::SetMinLogLevel(logging::LOG_INFO); | |
| 43 LogSampleEvents(); | |
| 44 | |
| 45 const std::vector<EventLogger::Event> log = util::GetLogHistory(); | |
| 46 ASSERT_EQ(3u, log.size()); | |
| 47 ASSERT_TRUE(ContainsString("Info test message", log[0])); | |
|
tzik
2013/05/27 09:08:52
can be EXPECT_TRUE for this and two below?
calvinlo
2013/05/27 09:29:27
Done.
| |
| 48 ASSERT_TRUE(ContainsString("Warning test message", log[1])); | |
| 49 ASSERT_TRUE(ContainsString("Error test message", log[2])); | |
| 50 } | |
| 51 | |
| 52 TEST_F(LoggerTest, TestMinSeverityLevel) { | |
| 53 // Check that all messages are logged when log LogSeverity is set to ERROR. | |
| 54 logging::SetMinLogLevel(logging::LOG_ERROR); | |
| 55 LogSampleEvents(); | |
| 56 | |
| 57 const std::vector<EventLogger::Event> log = util::GetLogHistory(); | |
| 58 ASSERT_EQ(1u, log.size()); | |
| 59 ASSERT_TRUE(ContainsString("Error test message", log[0])); | |
|
tzik
2013/05/27 09:08:52
ditto for this ASSERT_TRUE
calvinlo
2013/05/27 09:29:27
Done.
| |
| 60 } | |
| 61 | |
| 62 TEST_F(LoggerTest, TestClearLog) { | |
| 63 LogSampleEvents(); | |
| 64 ASSERT_EQ(3u, util::GetLogHistory().size()); | |
|
tzik
2013/05/27 09:08:52
ditto for both of this ASSERT_EQ
calvinlo
2013/05/27 09:29:27
Done.
| |
| 65 | |
| 66 util::ClearLog(); | |
| 67 ASSERT_EQ(0u, util::GetLogHistory().size()); | |
| 68 } | |
| 69 | |
| 70 | |
| 71 } // namespace sync_file_system | |
| OLD | NEW |