Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2068)

Unified Diff: net/der/encode_values_unittest.cc

Issue 2144693002: Reland of Add CheckOCSPDateValid() to net/cert/internal (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use base::Time::Exploded Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/der/encode_values.cc ('k') | net/net.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/der/encode_values_unittest.cc
diff --git a/net/der/encode_values_unittest.cc b/net/der/encode_values_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..43633722bd1ecea9aee2b692720510fa3136d8a5
--- /dev/null
+++ b/net/der/encode_values_unittest.cc
@@ -0,0 +1,77 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/time/time.h"
+#include "net/der/encode_values.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace net {
+namespace der {
+namespace test {
+
+TEST(EncodeValuesTest, EncodeTimeAsGeneralizedTime) {
+ // Fri, 24 Jun 2016 17:04:54 GMT
+ base::Time time =
+ base::Time::UnixEpoch() + base::TimeDelta::FromSeconds(1466787894);
+ GeneralizedTime generalized_time;
+ ASSERT_TRUE(EncodeTimeAsGeneralizedTime(time, &generalized_time));
+ EXPECT_EQ(2016, generalized_time.year);
+ EXPECT_EQ(6, generalized_time.month);
+ EXPECT_EQ(24, generalized_time.day);
+ EXPECT_EQ(17, generalized_time.hours);
+ EXPECT_EQ(4, generalized_time.minutes);
+ EXPECT_EQ(54, generalized_time.seconds);
+}
+
+TEST(EncodeValuesTest, EncodeTimeFromBeforeWindows) {
Ryan Sleevi 2016/07/13 01:17:18 More documentation needed. // Although the ASN.1
dadrian 2016/07/13 02:38:34 Done.
+ // Thu, 1 Jan 1570 00:00:00 GMT
+ base::Time::Exploded exploded;
+ exploded.year = 1570;
+ exploded.month = 1;
+ exploded.day_of_week = 5;
+ exploded.hour = 0;
+ exploded.minute = 0;
+ exploded.second = 0;
+ exploded.millisecond = 0;
+ base::Time time;
+ if (base::Time::FromUTCExploded(exploded, &time)) {
Ryan Sleevi 2016/07/13 01:17:18 Short-circuit and return early if (!base::Time::F
dadrian 2016/07/13 02:38:34 Done.
+ GeneralizedTime generalized_time;
+ ASSERT_TRUE(EncodeTimeAsGeneralizedTime(time, &generalized_time));
+ EXPECT_EQ(1570, generalized_time.year);
+ EXPECT_EQ(1, generalized_time.month);
+ EXPECT_EQ(1, generalized_time.day);
+ EXPECT_EQ(0, generalized_time.hours);
+ EXPECT_EQ(0, generalized_time.minutes);
+ EXPECT_EQ(0, generalized_time.seconds);
+ }
+}
+
+TEST(EncodeValuesTest, EncodeTimeAfterTimeTMax) {
Ryan Sleevi 2016/07/13 01:17:18 same comments re docs & short-circuit
dadrian 2016/07/13 02:38:34 Done.
+ // Sat, 1 Jan 2039 00:00:00 GMT
+ base::Time::Exploded exploded;
+ exploded.year = 2039;
+ exploded.month = 1;
+ exploded.day_of_week = 7;
+ exploded.hour = 0;
+ exploded.minute = 0;
+ exploded.second = 0;
+ exploded.millisecond = 0;
+ base::Time time;
+ if (base::Time::FromUTCExploded(exploded, &time)) {
+ GeneralizedTime generalized_time;
+ ASSERT_TRUE(EncodeTimeAsGeneralizedTime(time, &generalized_time));
+ EXPECT_EQ(2039, generalized_time.year);
+ EXPECT_EQ(1, generalized_time.month);
+ EXPECT_EQ(1, generalized_time.day);
+ EXPECT_EQ(0, generalized_time.hours);
+ EXPECT_EQ(0, generalized_time.minutes);
+ EXPECT_EQ(0, generalized_time.seconds);
+ }
+}
+
+} // namespace test
+
+} // namespace der
+
+} // namespace net
« no previous file with comments | « net/der/encode_values.cc ('k') | net/net.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698