blob: 7693e1a9e75b96924d37f34299a3074d3ac04f83 [file] [log] [blame]
Avi Drissman8ba1bad2022-09-13 19:22:361// Copyright 2012 The Chromium Authors
kinaba@chromium.org66db8ec02012-11-19 07:54:452// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
lukasza8acc4eb2015-07-20 20:57:205#include "components/drive/event_logger.h"
kinaba@chromium.org66db8ec02012-11-19 07:54:456
7#include "testing/gtest/include/gtest/gtest.h"
8
satorux@chromium.orge50af7652013-06-20 06:39:319namespace drive {
kinaba@chromium.org66db8ec02012-11-19 07:54:4510
satorux@chromium.org76de6d1c2013-04-19 03:50:1711TEST(EventLoggerTest, BasicLogging) {
satorux@chromium.org0cd6c7f2013-04-24 05:27:0212 EventLogger logger;
13 logger.SetHistorySize(3); // At most 3 events are kept.
14 EXPECT_EQ(0U, logger.GetHistory().size());
kinaba@chromium.org66db8ec02012-11-19 07:54:4515
Peter Boströme54f42cb2024-01-04 23:43:2216 logger.Log(logging::LOGGING_INFO, "first");
17 logger.Log(logging::LOGGING_INFO, "%dnd", 2);
18 logger.Log(logging::LOGGING_INFO, "third");
kinaba@chromium.org66db8ec02012-11-19 07:54:4519
20 // Events are recorded in the chronological order with sequential IDs.
satorux@chromium.org0cd6c7f2013-04-24 05:27:0221 std::vector<EventLogger::Event> history = logger.GetHistory();
22 ASSERT_EQ(3U, history.size());
23 EXPECT_EQ(0, history[0].id);
24 EXPECT_EQ("first", history[0].what);
25 EXPECT_EQ(1, history[1].id);
26 EXPECT_EQ("2nd", history[1].what);
27 EXPECT_EQ(2, history[2].id);
28 EXPECT_EQ("third", history[2].what);
kinaba@chromium.org66db8ec02012-11-19 07:54:4529
Peter Boströme54f42cb2024-01-04 23:43:2230 logger.Log(logging::LOGGING_INFO, "fourth");
kinaba@chromium.org66db8ec02012-11-19 07:54:4531 // It does not log events beyond the specified.
satorux@chromium.org0cd6c7f2013-04-24 05:27:0232 history = logger.GetHistory();
33 ASSERT_EQ(3U, history.size());
kinaba@chromium.org66db8ec02012-11-19 07:54:4534 // The oldest events is pushed out.
satorux@chromium.org0cd6c7f2013-04-24 05:27:0235 EXPECT_EQ(1, history[0].id);
36 EXPECT_EQ("2nd", history[0].what);
37 EXPECT_EQ(2, history[1].id);
38 EXPECT_EQ("third", history[1].what);
39 EXPECT_EQ(3, history[2].id);
40 EXPECT_EQ("fourth", history[2].what);
kinaba@chromium.org66db8ec02012-11-19 07:54:4541}
42
satorux@chromium.orge50af7652013-06-20 06:39:3143} // namespace drive