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.
5 #include "chrome/browser/sync_file_system/logger.h"
6 #include "testing/gtest/include/gtest/gtest.h"
8 using drive::EventLogger
;
10 namespace sync_file_system
{
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");
21 bool ContainsString(std::string contains_string
, EventLogger::Event event
) {
22 return event
.what
.find(contains_string
) != std::string::npos
;
27 class LoggerTest
: public testing::Test
{
31 void SetUp() override
{
32 logging::SetMinLogLevel(logging::LOG_INFO
);
37 DISALLOW_COPY_AND_ASSIGN(LoggerTest
);
40 TEST_F(LoggerTest
, GetLogHistory
) {
43 const std::vector
<EventLogger::Event
> log
= util::GetLogHistory();
44 ASSERT_EQ(3u, log
.size());
45 EXPECT_TRUE(ContainsString("Info test message", log
[0]));
46 EXPECT_TRUE(ContainsString("Warning test message", log
[1]));
47 EXPECT_TRUE(ContainsString("Error test message", log
[2]));
50 TEST_F(LoggerTest
, ClearLog
) {
52 EXPECT_EQ(3u, util::GetLogHistory().size());
55 EXPECT_EQ(0u, util::GetLogHistory().size());
59 } // namespace sync_file_system