nss_util_unittest.cc 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // Copyright (c) 2011 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 "crypto/nss_util.h"
  5. #include <prtime.h>
  6. #include "base/time/time.h"
  7. #include "testing/gtest/include/gtest/gtest.h"
  8. namespace crypto {
  9. TEST(NSSUtilTest, PRTimeConversion) {
  10. EXPECT_EQ(base::Time::UnixEpoch(), PRTimeToBaseTime(0));
  11. EXPECT_EQ(0, BaseTimeToPRTime(base::Time::UnixEpoch()));
  12. PRExplodedTime prxtime;
  13. prxtime.tm_params.tp_gmt_offset = 0;
  14. prxtime.tm_params.tp_dst_offset = 0;
  15. base::Time::Exploded exploded;
  16. exploded.year = prxtime.tm_year = 2011;
  17. exploded.month = 12;
  18. prxtime.tm_month = 11;
  19. // PRExplodedTime::tm_wday is a smaller type than Exploded::day_of_week, so
  20. // assigning the two in this order instead of the reverse avoids potential
  21. // warnings about type downcasting.
  22. exploded.day_of_week = prxtime.tm_wday = 0; // Should be unused.
  23. exploded.day_of_month = prxtime.tm_mday = 10;
  24. exploded.hour = prxtime.tm_hour = 2;
  25. exploded.minute = prxtime.tm_min = 52;
  26. exploded.second = prxtime.tm_sec = 19;
  27. exploded.millisecond = 342;
  28. prxtime.tm_usec = 342000;
  29. PRTime pr_time = PR_ImplodeTime(&prxtime);
  30. base::Time base_time;
  31. EXPECT_TRUE(base::Time::FromUTCExploded(exploded, &base_time));
  32. EXPECT_EQ(base_time, PRTimeToBaseTime(pr_time));
  33. EXPECT_EQ(pr_time, BaseTimeToPRTime(base_time));
  34. }
  35. } // namespace crypto