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 EXPECT_EQ(3u, log.size()); | |
tzik
2013/05/27 10:55:45
The three EXPECT_TRUE below do not cause crash eve
calvinlo
2013/05/27 11:02:42
Done.
| |
47 EXPECT_TRUE(ContainsString("Info test message", log[0])); | |
48 EXPECT_TRUE(ContainsString("Warning test message", log[1])); | |
49 EXPECT_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 EXPECT_EQ(1u, log.size()); | |
tzik
2013/05/27 10:55:45
ditto.
calvinlo
2013/05/27 11:02:42
Done.
| |
59 EXPECT_TRUE(ContainsString("Error test message", log[0])); | |
60 } | |
61 | |
62 TEST_F(LoggerTest, TestClearLog) { | |
63 LogSampleEvents(); | |
64 EXPECT_EQ(3u, util::GetLogHistory().size()); | |
65 | |
66 util::ClearLog(); | |
67 EXPECT_EQ(0u, util::GetLogHistory().size()); | |
68 } | |
69 | |
70 | |
71 } // namespace sync_file_system | |
OLD | NEW |