log_test_helpers_unittest.cc 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. // Copyright 2021 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 "ash/system/diagnostics/log_test_helpers.h"
  5. #include <string>
  6. #include <vector>
  7. #include "testing/gtest/include/gtest/gtest.h"
  8. namespace ash {
  9. namespace diagnostics {
  10. class LogHelpersTest : public testing::Test {
  11. public:
  12. LogHelpersTest() = default;
  13. ~LogHelpersTest() override = default;
  14. };
  15. TEST_F(LogHelpersTest, GetLogLineContents) {
  16. const std::string log_line = "02:26:18.766 - RoutineType::kMemory - Started";
  17. const std::vector<std::string> actual_log_lines =
  18. GetLogLineContents(log_line);
  19. ASSERT_EQ(3u, actual_log_lines.size());
  20. ASSERT_EQ("02:26:18.766", actual_log_lines[0]);
  21. ASSERT_EQ("RoutineType::kMemory", actual_log_lines[1]);
  22. ASSERT_EQ("Started", actual_log_lines[2]);
  23. const std::string log_line_no_separator =
  24. "02:26:18.766 RoutineType::kMemory Started";
  25. const std::vector<std::string> actual_log_lines_no_separator =
  26. GetLogLineContents(log_line_no_separator);
  27. ASSERT_EQ(1u, actual_log_lines_no_separator.size());
  28. ASSERT_EQ("02:26:18.766 RoutineType::kMemory Started",
  29. actual_log_lines_no_separator[0]);
  30. }
  31. TEST_F(LogHelpersTest, GetLogLines) {
  32. const std::string log_lines =
  33. "02:26:18.766 - RoutineType::kMemory - Started \n 02:26:18.766 - "
  34. "RoutineType::kMemory - Completed \n";
  35. const std::vector<std::string> actual_log_lines = GetLogLines(log_lines);
  36. ASSERT_EQ(2u, actual_log_lines.size());
  37. ASSERT_EQ("02:26:18.766 - RoutineType::kMemory - Started",
  38. actual_log_lines[0]);
  39. ASSERT_EQ("02:26:18.766 - RoutineType::kMemory - Completed",
  40. actual_log_lines[1]);
  41. const std::string log_lines_no_newline =
  42. "02:26:18.766 - RoutineType::kMemory - Started 02:26:18.766 - "
  43. "RoutineType::kMemory - Completed";
  44. const std::vector<std::string> actual_log_lines_no_newline =
  45. GetLogLines(log_lines_no_newline);
  46. ASSERT_EQ(1u, actual_log_lines_no_newline.size());
  47. ASSERT_EQ(
  48. "02:26:18.766 - RoutineType::kMemory - Started 02:26:18.766 - "
  49. "RoutineType::kMemory - Completed",
  50. actual_log_lines_no_newline[0]);
  51. }
  52. } // namespace diagnostics
  53. } // namespace ash