time_serialization_unittest.cc 913 B

12345678910111213141516171819202122232425
  1. // Copyright 2017 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/ntp_snippets/time_serialization.h"
  5. #include <vector>
  6. #include "testing/gmock/include/gmock/gmock.h"
  7. #include "testing/gtest/include/gtest/gtest.h"
  8. namespace ntp_snippets {
  9. TEST(TimeSerializationTest, TimeSerialization) {
  10. std::vector<base::Time> values_to_test = {base::Time::Min(), base::Time(),
  11. base::Time() + base::Hours(1),
  12. base::Time::Max()};
  13. for (const base::Time& value : values_to_test) {
  14. EXPECT_EQ(SerializeTime(value), value.ToInternalValue());
  15. EXPECT_EQ(base::Time::FromInternalValue(SerializeTime(value)), value);
  16. EXPECT_EQ(DeserializeTime(SerializeTime(value)), value);
  17. }
  18. }
  19. } // namespace ntp_snippets