proxygen
HTTPTimeTest.cpp File Reference

Go to the source code of this file.

Functions

 TEST (HTTPTimeTests, InvalidTimeTest)
 
 TEST (HTTPTimeTests, ValidTimeTest)
 
 TEST (HTTPTimeTests, EqualTimeTest)
 
 TEST (HTTPTimeTests, ReallyOldTimeTest)
 
 TEST (HTTPTimeTests, TzToUnixTsTest)
 

Function Documentation

TEST ( HTTPTimeTests  ,
InvalidTimeTest   
)

Definition at line 15 of file HTTPTimeTest.cpp.

References EXPECT_FALSE, and proxygen::parseHTTPDateTime().

15  {
16  EXPECT_FALSE(parseHTTPDateTime("Hello, World").hasValue());
17  EXPECT_FALSE(parseHTTPDateTime("Sun, 33 Nov 1994 08:49:37 GMT").hasValue());
18  EXPECT_FALSE(parseHTTPDateTime("Sun, 06 Nov 1800").hasValue());
19 }
#define EXPECT_FALSE(condition)
Definition: gtest.h:1862
folly::Optional< int64_t > parseHTTPDateTime(const std::string &s)
Definition: HTTPTime.cpp:18
TEST ( HTTPTimeTests  ,
ValidTimeTest   
)

Definition at line 21 of file HTTPTimeTest.cpp.

References EXPECT_TRUE, and proxygen::parseHTTPDateTime().

21  {
22  // From http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.3
23  EXPECT_TRUE(parseHTTPDateTime("Sun, 06 Nov 1994 08:49:37 GMT").hasValue());
24  EXPECT_TRUE(parseHTTPDateTime("Sunday, 06-Nov-94 08:49:37 GMT").hasValue());
25  EXPECT_TRUE(parseHTTPDateTime("Sun Nov 6 08:49:37 1994").hasValue());
26 }
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
folly::Optional< int64_t > parseHTTPDateTime(const std::string &s)
Definition: HTTPTime.cpp:18
TEST ( HTTPTimeTests  ,
EqualTimeTest   
)

Definition at line 28 of file HTTPTimeTest.cpp.

References a, b, c, EXPECT_EQ, EXPECT_TRUE, and proxygen::parseHTTPDateTime().

28  {
29  auto a = parseHTTPDateTime("Thu, 07 Mar 2013 08:49:37 GMT");
30  EXPECT_TRUE(a.hasValue());
31  auto b = parseHTTPDateTime("Thursday, 07-Mar-13 08:49:37 GMT");
32  EXPECT_TRUE(b.hasValue());
33  auto c = parseHTTPDateTime("Thu Mar 7 08:49:37 2013");
34  EXPECT_TRUE(c.hasValue());
35 
36  EXPECT_EQ(a.value(), b.value());
37  EXPECT_EQ(a.value(), c.value());
38  EXPECT_EQ(b.value(), c.value());
39 }
char b
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
char a
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
folly::Optional< int64_t > parseHTTPDateTime(const std::string &s)
Definition: HTTPTime.cpp:18
char c
TEST ( HTTPTimeTests  ,
ReallyOldTimeTest   
)

Definition at line 41 of file HTTPTimeTest.cpp.

References a, b, c, EXPECT_LT, EXPECT_TRUE, and proxygen::parseHTTPDateTime().

41  {
42  auto a = parseHTTPDateTime("Thu, 07 Mar 1770 08:49:37 GMT");
43  EXPECT_TRUE(a.hasValue());
44  auto b = parseHTTPDateTime("Thu, 07 Mar 1771 08:49:37 GMT");
45  EXPECT_TRUE(b.hasValue());
46  auto c = parseHTTPDateTime("Thu, 07 Mar 1980 08:49:37 GMT");
47  EXPECT_TRUE(c.hasValue());
48 
49  EXPECT_LT(a, b);
50  EXPECT_LT(a, c);
51  EXPECT_LT(b, c);
52 }
char b
char a
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
#define EXPECT_LT(val1, val2)
Definition: gtest.h:1930
folly::Optional< int64_t > parseHTTPDateTime(const std::string &s)
Definition: HTTPTime.cpp:18
char c
TEST ( HTTPTimeTests  ,
TzToUnixTsTest   
)

Definition at line 54 of file HTTPTimeTest.cpp.

References a, b, c, EXPECT_EQ, EXPECT_FALSE, f, g(), h, i, k, m, and proxygen::parseHTTPDateTime().

54  {
55  auto a = parseHTTPDateTime("Wed, 13 Jun 2018 21:43:49 GMT");
56  EXPECT_EQ(a.value(), 1528926229);
57  auto b = parseHTTPDateTime("Wed, 31 Dec 1969 23:59:59 GMT");
58  EXPECT_EQ(b.value(), -1);
59  auto c = parseHTTPDateTime("Thu, 01 Jan 1970 00:00:00 GMT");
60  EXPECT_EQ(c.value(), 0);
61  auto d = parseHTTPDateTime("Thu, 01 Jan 1970 00:00:01 GMT");
62  EXPECT_EQ(d.value(), 1);
63 
64  auto e = parseHTTPDateTime("Wed, 13-Jun-18 21:43:49 GMT");
65  EXPECT_EQ(e.value(), 1528926229);
66  auto f = parseHTTPDateTime("Wed, 31-Dec-69 23:59:59 GMT");
67  EXPECT_EQ(f.value(), -1);
68  auto g = parseHTTPDateTime("Wed, 01-Jan-70 00:00:00 GMT");
69  EXPECT_EQ(g.value(), 0);
70  auto h = parseHTTPDateTime("Thu, 01-Jan-70 00:00:01 GMT");
71  EXPECT_EQ(h.value(), 1);
72 
73  auto i = parseHTTPDateTime("Wed Jun 13 21:43:49 2018");
74  EXPECT_EQ(i.value(), 1528926229);
75  auto j = parseHTTPDateTime("Wed Dec 31 23:59:59 1969");
76  EXPECT_EQ(j.value(), -1);
77  auto k = parseHTTPDateTime("Thu Jan 1 00:00:00 1970");
78  EXPECT_EQ(k.value(), 0);
79  auto l = parseHTTPDateTime("Thu Jan 1 00:00:01 1970");
80  EXPECT_EQ(l.value(), 1);
81 
82  auto m = parseHTTPDateTime("Tue, 19 Jan 2038 03:14:07 GMT");
83  EXPECT_EQ(m.value(), 2147483647);
84 
85  auto n = parseHTTPDateTime("Thu, 01 Jan 1970 00:00:01 PST");
86  EXPECT_FALSE(n.hasValue());
87  auto o = parseHTTPDateTime("Thu, 01 Jan 1970 00:00:01");
88  EXPECT_FALSE(o.hasValue());
89 }
*than *hazptr_holder h
Definition: Hazptr.h:116
auto f
char b
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
static map< string, int > m
char a
g_t g(f_t)
#define EXPECT_FALSE(condition)
Definition: gtest.h:1862
folly::Optional< int64_t > parseHTTPDateTime(const std::string &s)
Definition: HTTPTime.cpp:18
char c
KeyT k