event_logger_unittest.cc 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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
  3. // found in the LICENSE file.
  4. #include "components/drive/event_logger.h"
  5. #include "testing/gtest/include/gtest/gtest.h"
  6. namespace drive {
  7. TEST(EventLoggerTest, BasicLogging) {
  8. EventLogger logger;
  9. logger.SetHistorySize(3); // At most 3 events are kept.
  10. EXPECT_EQ(0U, logger.GetHistory().size());
  11. logger.Log(logging::LOG_INFO, "first");
  12. logger.Log(logging::LOG_INFO, "%dnd", 2);
  13. logger.Log(logging::LOG_INFO, "third");
  14. // Events are recorded in the chronological order with sequential IDs.
  15. std::vector<EventLogger::Event> history = logger.GetHistory();
  16. ASSERT_EQ(3U, history.size());
  17. EXPECT_EQ(0, history[0].id);
  18. EXPECT_EQ("first", history[0].what);
  19. EXPECT_EQ(1, history[1].id);
  20. EXPECT_EQ("2nd", history[1].what);
  21. EXPECT_EQ(2, history[2].id);
  22. EXPECT_EQ("third", history[2].what);
  23. logger.Log(logging::LOG_INFO, "fourth");
  24. // It does not log events beyond the specified.
  25. history = logger.GetHistory();
  26. ASSERT_EQ(3U, history.size());
  27. // The oldest events is pushed out.
  28. EXPECT_EQ(1, history[0].id);
  29. EXPECT_EQ("2nd", history[0].what);
  30. EXPECT_EQ(2, history[1].id);
  31. EXPECT_EQ("third", history[1].what);
  32. EXPECT_EQ(3, history[2].id);
  33. EXPECT_EQ("fourth", history[2].what);
  34. }
  35. } // namespace drive