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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « net/der/encode_values.cc ('k') | net/net.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2015 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
5 #include "base/time/time.h"
6 #include "net/der/encode_values.h"
7 #include "testing/gtest/include/gtest/gtest.h"
8
9 namespace net {
10 namespace der {
11 namespace test {
12
13 TEST(EncodeValuesTest, EncodeTimeAsGeneralizedTime) {
14 // Fri, 24 Jun 2016 17:04:54 GMT
15 base::Time time =
16 base::Time::UnixEpoch() + base::TimeDelta::FromSeconds(1466787894);
17 GeneralizedTime generalized_time;
18 ASSERT_TRUE(EncodeTimeAsGeneralizedTime(time, &generalized_time));
19 EXPECT_EQ(2016, generalized_time.year);
20 EXPECT_EQ(6, generalized_time.month);
21 EXPECT_EQ(24, generalized_time.day);
22 EXPECT_EQ(17, generalized_time.hours);
23 EXPECT_EQ(4, generalized_time.minutes);
24 EXPECT_EQ(54, generalized_time.seconds);
25 }
26
27 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.
28 // Thu, 1 Jan 1570 00:00:00 GMT
29 base::Time::Exploded exploded;
30 exploded.year = 1570;
31 exploded.month = 1;
32 exploded.day_of_week = 5;
33 exploded.hour = 0;
34 exploded.minute = 0;
35 exploded.second = 0;
36 exploded.millisecond = 0;
37 base::Time time;
38 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.
39 GeneralizedTime generalized_time;
40 ASSERT_TRUE(EncodeTimeAsGeneralizedTime(time, &generalized_time));
41 EXPECT_EQ(1570, generalized_time.year);
42 EXPECT_EQ(1, generalized_time.month);
43 EXPECT_EQ(1, generalized_time.day);
44 EXPECT_EQ(0, generalized_time.hours);
45 EXPECT_EQ(0, generalized_time.minutes);
46 EXPECT_EQ(0, generalized_time.seconds);
47 }
48 }
49
50 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.
51 // Sat, 1 Jan 2039 00:00:00 GMT
52 base::Time::Exploded exploded;
53 exploded.year = 2039;
54 exploded.month = 1;
55 exploded.day_of_week = 7;
56 exploded.hour = 0;
57 exploded.minute = 0;
58 exploded.second = 0;
59 exploded.millisecond = 0;
60 base::Time time;
61 if (base::Time::FromUTCExploded(exploded, &time)) {
62 GeneralizedTime generalized_time;
63 ASSERT_TRUE(EncodeTimeAsGeneralizedTime(time, &generalized_time));
64 EXPECT_EQ(2039, generalized_time.year);
65 EXPECT_EQ(1, generalized_time.month);
66 EXPECT_EQ(1, generalized_time.day);
67 EXPECT_EQ(0, generalized_time.hours);
68 EXPECT_EQ(0, generalized_time.minutes);
69 EXPECT_EQ(0, generalized_time.seconds);
70 }
71 }
72
73 } // namespace test
74
75 } // namespace der
76
77 } // namespace net
OLDNEW
« 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