Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
B
brpc
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
brpc
Commits
568dba34
Commit
568dba34
authored
Jun 13, 2019
by
zhujiashun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
remove unnecessary comments & using DISABLE_* to disable corresponding UTs
parent
4233593d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
197 additions
and
212 deletions
+197
-212
time.cc
src/butil/time/time.cc
+0
-15
time_unittest.cc
test/time_unittest.cc
+197
-197
No files found.
src/butil/time/time.cc
View file @
568dba34
...
...
@@ -215,21 +215,6 @@ bool Time::FromStringInternal(const char* time_string,
// TODO(zhujiashun): after removing nspr, this function
// is left unimplemented.
return
false
;
// DCHECK((time_string != NULL) && (parsed_time != NULL));
// if (time_string[0] == '\0')
// return false;
// PRTime result_time = 0;
// PRStatus result = PR_ParseTimeString(time_string,
// is_local ? PR_FALSE : PR_TRUE,
// &result_time);
// if (PR_SUCCESS != result)
// return false;
// result_time += kTimeTToMicrosecondsOffset;
// *parsed_time = Time(result_time);
// return true;
}
// Local helper class to hold the conversion from Time to TickTime at the
...
...
test/time_unittest.cc
View file @
568dba34
...
...
@@ -162,203 +162,203 @@ TEST_F(TimeTest, LocalMidnight) {
}
// TODO(zhujiashun): Time::FromString is not implemented after removing nspr,
// so all tests
related to this function is commented out. Uncomment thos
e
//
tests once
Time::FromString is implemented.
// TEST_F(TimeTest,
ParseTimeTest1) {
//
time_t current_time = 0;
//
time(¤t_time);
//
//
const int BUFFER_SIZE = 64;
//
struct tm local_time;
//
memset(&local_time, 0, sizeof(local_time));
//
char time_buf[BUFFER_SIZE] = {0};
//
#if defined(OS_WIN)
//
localtime_s(&local_time, ¤t_time);
//
asctime_s(time_buf, arraysize(time_buf), &local_time);
//
#elif defined(OS_POSIX)
//
localtime_r(¤t_time, &local_time);
//
asctime_r(&local_time, time_buf);
//
#endif
//
//
Time parsed_time;
//
EXPECT_TRUE(Time::FromString(time_buf, &parsed_time));
//
EXPECT_EQ(current_time, parsed_time.ToTimeT());
//
}
//
// TEST_F(TimeTest,
DayOfWeekSunday) {
//
Time time;
//
EXPECT_TRUE(Time::FromString("Sun, 06 May 2012 12:00:00 GMT", &time));
//
Time::Exploded exploded;
//
time.UTCExplode(&exploded);
//
EXPECT_EQ(0, exploded.day_of_week);
//
}
//
// TEST_F(TimeTest,
DayOfWeekWednesday) {
//
Time time;
//
EXPECT_TRUE(Time::FromString("Wed, 09 May 2012 12:00:00 GMT", &time));
//
Time::Exploded exploded;
//
time.UTCExplode(&exploded);
//
EXPECT_EQ(3, exploded.day_of_week);
//
}
//
// TEST_F(TimeTest,
DayOfWeekSaturday) {
//
Time time;
//
EXPECT_TRUE(Time::FromString("Sat, 12 May 2012 12:00:00 GMT", &time));
//
Time::Exploded exploded;
//
time.UTCExplode(&exploded);
//
EXPECT_EQ(6, exploded.day_of_week);
//
}
//
// TEST_F(TimeTest,
ParseTimeTest2) {
//
Time parsed_time;
//
EXPECT_TRUE(Time::FromString("Mon, 15 Oct 2007 19:45:00 GMT", &parsed_time));
//
EXPECT_EQ(comparison_time_pdt_, parsed_time);
//
}
//
// TEST_F(TimeTest,
ParseTimeTest3) {
//
Time parsed_time;
//
EXPECT_TRUE(Time::FromString("15 Oct 07 12:45:00", &parsed_time));
//
EXPECT_EQ(comparison_time_local_, parsed_time);
//
}
//
// TEST_F(TimeTest,
ParseTimeTest4) {
//
Time parsed_time;
//
EXPECT_TRUE(Time::FromString("15 Oct 07 19:45 GMT", &parsed_time));
//
EXPECT_EQ(comparison_time_pdt_, parsed_time);
//
}
//
// TEST_F(TimeTest,
ParseTimeTest5) {
//
Time parsed_time;
//
EXPECT_TRUE(Time::FromString("Mon Oct 15 12:45 PDT 2007", &parsed_time));
//
EXPECT_EQ(comparison_time_pdt_, parsed_time);
//
}
//
// TEST_F(TimeTest,
ParseTimeTest6) {
//
Time parsed_time;
//
EXPECT_TRUE(Time::FromString("Monday, Oct 15, 2007 12:45 PM", &parsed_time));
//
EXPECT_EQ(comparison_time_local_, parsed_time);
//
}
//
// TEST_F(TimeTest,
ParseTimeTest7) {
//
Time parsed_time;
//
EXPECT_TRUE(Time::FromString("10/15/07 12:45:00 PM", &parsed_time));
//
EXPECT_EQ(comparison_time_local_, parsed_time);
//
}
//
// TEST_F(TimeTest,
ParseTimeTest8) {
//
Time parsed_time;
//
EXPECT_TRUE(Time::FromString("15-OCT-2007 12:45pm", &parsed_time));
//
EXPECT_EQ(comparison_time_local_, parsed_time);
//
}
//
// TEST_F(TimeTest,
ParseTimeTest9) {
//
Time parsed_time;
//
EXPECT_TRUE(Time::FromString("16 Oct 2007 4:45-JST (Tuesday)", &parsed_time));
//
EXPECT_EQ(comparison_time_pdt_, parsed_time);
//
}
//
// TEST_F(TimeTest,
ParseTimeTest10) {
//
Time parsed_time;
//
EXPECT_TRUE(Time::FromString("15/10/07 12:45", &parsed_time));
//
EXPECT_EQ(parsed_time, comparison_time_local_);
//
}
//
//
//
Test some of edge cases around epoch, etc.
// TEST_F(TimeTest,
ParseTimeTestEpoch0) {
//
Time parsed_time;
//
//
// time_t == epoch == 0
//
EXPECT_TRUE(Time::FromString("Thu Jan 01 01:00:00 +0100 1970",
//
&parsed_time));
//
EXPECT_EQ(0, parsed_time.ToTimeT());
//
EXPECT_TRUE(Time::FromString("Thu Jan 01 00:00:00 GMT 1970",
//
&parsed_time));
//
EXPECT_EQ(0, parsed_time.ToTimeT());
//
}
//
// TEST_F(TimeTest,
ParseTimeTestEpoch1) {
//
Time parsed_time;
//
//
// time_t == 1 second after epoch == 1
//
EXPECT_TRUE(Time::FromString("Thu Jan 01 01:00:01 +0100 1970",
//
&parsed_time));
//
EXPECT_EQ(1, parsed_time.ToTimeT());
//
EXPECT_TRUE(Time::FromString("Thu Jan 01 00:00:01 GMT 1970",
//
&parsed_time));
//
EXPECT_EQ(1, parsed_time.ToTimeT());
//
}
//
// TEST_F(TimeTest,
ParseTimeTestEpoch2) {
//
Time parsed_time;
//
//
// time_t == 2 seconds after epoch == 2
//
EXPECT_TRUE(Time::FromString("Thu Jan 01 01:00:02 +0100 1970",
//
&parsed_time));
//
EXPECT_EQ(2, parsed_time.ToTimeT());
//
EXPECT_TRUE(Time::FromString("Thu Jan 01 00:00:02 GMT 1970",
//
&parsed_time));
//
EXPECT_EQ(2, parsed_time.ToTimeT());
//
}
//
// TEST_F(TimeTest,
ParseTimeTestEpochNeg1) {
//
Time parsed_time;
//
//
// time_t == 1 second before epoch == -1
//
EXPECT_TRUE(Time::FromString("Thu Jan 01 00:59:59 +0100 1970",
//
&parsed_time));
//
EXPECT_EQ(-1, parsed_time.ToTimeT());
//
EXPECT_TRUE(Time::FromString("Wed Dec 31 23:59:59 GMT 1969",
//
&parsed_time));
//
EXPECT_EQ(-1, parsed_time.ToTimeT());
//
}
//
//
//
If time_t is 32 bits, a date after year 2038 will overflow time_t and
//
//
cause timegm() to return -1. The parsed time should not be 1 second
//
//
before epoch.
// TEST_F(TimeTest,
ParseTimeTestEpochNotNeg1) {
//
Time parsed_time;
//
//
EXPECT_TRUE(Time::FromString("Wed Dec 31 23:59:59 GMT 2100",
//
&parsed_time));
//
EXPECT_NE(-1, parsed_time.ToTimeT());
//
}
//
// TEST_F(TimeTest,
ParseTimeTestEpochNeg2) {
//
Time parsed_time;
//
//
// time_t == 2 seconds before epoch == -2
//
EXPECT_TRUE(Time::FromString("Thu Jan 01 00:59:58 +0100 1970",
//
&parsed_time));
//
EXPECT_EQ(-2, parsed_time.ToTimeT());
//
EXPECT_TRUE(Time::FromString("Wed Dec 31 23:59:58 GMT 1969",
//
&parsed_time));
//
EXPECT_EQ(-2, parsed_time.ToTimeT());
//
}
//
// TEST_F(TimeTest,
ParseTimeTestEpoch1960) {
//
Time parsed_time;
//
//
// time_t before Epoch, in 1960
//
EXPECT_TRUE(Time::FromString("Wed Jun 29 19:40:01 +0100 1960",
//
&parsed_time));
//
EXPECT_EQ(-299999999, parsed_time.ToTimeT());
//
EXPECT_TRUE(Time::FromString("Wed Jun 29 18:40:01 GMT 1960",
//
&parsed_time));
//
EXPECT_EQ(-299999999, parsed_time.ToTimeT());
//
EXPECT_TRUE(Time::FromString("Wed Jun 29 17:40:01 GMT 1960",
//
&parsed_time));
//
EXPECT_EQ(-300003599, parsed_time.ToTimeT());
//
}
//
// TEST_F(TimeTest,
ParseTimeTestEmpty) {
//
Time parsed_time;
//
EXPECT_FALSE(Time::FromString("", &parsed_time));
//
}
//
// TEST_F(TimeTest,
ParseTimeTestInvalidString) {
//
Time parsed_time;
//
EXPECT_FALSE(Time::FromString("Monday morning 2000", &parsed_time));
//
}
// so all tests
using this function is disabled. Enable those tests onc
e
// Time::FromString is implemented.
TEST_F
(
TimeTest
,
DISABLED_
ParseTimeTest1
)
{
time_t
current_time
=
0
;
time
(
&
current_time
);
const
int
BUFFER_SIZE
=
64
;
struct
tm
local_time
;
memset
(
&
local_time
,
0
,
sizeof
(
local_time
));
char
time_buf
[
BUFFER_SIZE
]
=
{
0
};
#if defined(OS_WIN)
localtime_s
(
&
local_time
,
&
current_time
);
asctime_s
(
time_buf
,
arraysize
(
time_buf
),
&
local_time
);
#elif defined(OS_POSIX)
localtime_r
(
&
current_time
,
&
local_time
);
asctime_r
(
&
local_time
,
time_buf
);
#endif
Time
parsed_time
;
EXPECT_TRUE
(
Time
::
FromString
(
time_buf
,
&
parsed_time
));
EXPECT_EQ
(
current_time
,
parsed_time
.
ToTimeT
());
}
TEST_F
(
TimeTest
,
DISABLED_
DayOfWeekSunday
)
{
Time
time
;
EXPECT_TRUE
(
Time
::
FromString
(
"Sun, 06 May 2012 12:00:00 GMT"
,
&
time
));
Time
::
Exploded
exploded
;
time
.
UTCExplode
(
&
exploded
);
EXPECT_EQ
(
0
,
exploded
.
day_of_week
);
}
TEST_F
(
TimeTest
,
DISABLED_
DayOfWeekWednesday
)
{
Time
time
;
EXPECT_TRUE
(
Time
::
FromString
(
"Wed, 09 May 2012 12:00:00 GMT"
,
&
time
));
Time
::
Exploded
exploded
;
time
.
UTCExplode
(
&
exploded
);
EXPECT_EQ
(
3
,
exploded
.
day_of_week
);
}
TEST_F
(
TimeTest
,
DISABLED_
DayOfWeekSaturday
)
{
Time
time
;
EXPECT_TRUE
(
Time
::
FromString
(
"Sat, 12 May 2012 12:00:00 GMT"
,
&
time
));
Time
::
Exploded
exploded
;
time
.
UTCExplode
(
&
exploded
);
EXPECT_EQ
(
6
,
exploded
.
day_of_week
);
}
TEST_F
(
TimeTest
,
DISABLED_
ParseTimeTest2
)
{
Time
parsed_time
;
EXPECT_TRUE
(
Time
::
FromString
(
"Mon, 15 Oct 2007 19:45:00 GMT"
,
&
parsed_time
));
EXPECT_EQ
(
comparison_time_pdt_
,
parsed_time
);
}
TEST_F
(
TimeTest
,
DISABLED_
ParseTimeTest3
)
{
Time
parsed_time
;
EXPECT_TRUE
(
Time
::
FromString
(
"15 Oct 07 12:45:00"
,
&
parsed_time
));
EXPECT_EQ
(
comparison_time_local_
,
parsed_time
);
}
TEST_F
(
TimeTest
,
DISABLED_
ParseTimeTest4
)
{
Time
parsed_time
;
EXPECT_TRUE
(
Time
::
FromString
(
"15 Oct 07 19:45 GMT"
,
&
parsed_time
));
EXPECT_EQ
(
comparison_time_pdt_
,
parsed_time
);
}
TEST_F
(
TimeTest
,
DISABLED_
ParseTimeTest5
)
{
Time
parsed_time
;
EXPECT_TRUE
(
Time
::
FromString
(
"Mon Oct 15 12:45 PDT 2007"
,
&
parsed_time
));
EXPECT_EQ
(
comparison_time_pdt_
,
parsed_time
);
}
TEST_F
(
TimeTest
,
DISABLED_
ParseTimeTest6
)
{
Time
parsed_time
;
EXPECT_TRUE
(
Time
::
FromString
(
"Monday, Oct 15, 2007 12:45 PM"
,
&
parsed_time
));
EXPECT_EQ
(
comparison_time_local_
,
parsed_time
);
}
TEST_F
(
TimeTest
,
DISABLED_
ParseTimeTest7
)
{
Time
parsed_time
;
EXPECT_TRUE
(
Time
::
FromString
(
"10/15/07 12:45:00 PM"
,
&
parsed_time
));
EXPECT_EQ
(
comparison_time_local_
,
parsed_time
);
}
TEST_F
(
TimeTest
,
DISABLED_
ParseTimeTest8
)
{
Time
parsed_time
;
EXPECT_TRUE
(
Time
::
FromString
(
"15-OCT-2007 12:45pm"
,
&
parsed_time
));
EXPECT_EQ
(
comparison_time_local_
,
parsed_time
);
}
TEST_F
(
TimeTest
,
DISABLED_
ParseTimeTest9
)
{
Time
parsed_time
;
EXPECT_TRUE
(
Time
::
FromString
(
"16 Oct 2007 4:45-JST (Tuesday)"
,
&
parsed_time
));
EXPECT_EQ
(
comparison_time_pdt_
,
parsed_time
);
}
TEST_F
(
TimeTest
,
DISABLED_
ParseTimeTest10
)
{
Time
parsed_time
;
EXPECT_TRUE
(
Time
::
FromString
(
"15/10/07 12:45"
,
&
parsed_time
));
EXPECT_EQ
(
parsed_time
,
comparison_time_local_
);
}
// Test some of edge cases around epoch, etc.
TEST_F
(
TimeTest
,
DISABLED_
ParseTimeTestEpoch0
)
{
Time
parsed_time
;
// time_t == epoch == 0
EXPECT_TRUE
(
Time
::
FromString
(
"Thu Jan 01 01:00:00 +0100 1970"
,
&
parsed_time
));
EXPECT_EQ
(
0
,
parsed_time
.
ToTimeT
());
EXPECT_TRUE
(
Time
::
FromString
(
"Thu Jan 01 00:00:00 GMT 1970"
,
&
parsed_time
));
EXPECT_EQ
(
0
,
parsed_time
.
ToTimeT
());
}
TEST_F
(
TimeTest
,
DISABLED_
ParseTimeTestEpoch1
)
{
Time
parsed_time
;
// time_t == 1 second after epoch == 1
EXPECT_TRUE
(
Time
::
FromString
(
"Thu Jan 01 01:00:01 +0100 1970"
,
&
parsed_time
));
EXPECT_EQ
(
1
,
parsed_time
.
ToTimeT
());
EXPECT_TRUE
(
Time
::
FromString
(
"Thu Jan 01 00:00:01 GMT 1970"
,
&
parsed_time
));
EXPECT_EQ
(
1
,
parsed_time
.
ToTimeT
());
}
TEST_F
(
TimeTest
,
DISABLED_
ParseTimeTestEpoch2
)
{
Time
parsed_time
;
// time_t == 2 seconds after epoch == 2
EXPECT_TRUE
(
Time
::
FromString
(
"Thu Jan 01 01:00:02 +0100 1970"
,
&
parsed_time
));
EXPECT_EQ
(
2
,
parsed_time
.
ToTimeT
());
EXPECT_TRUE
(
Time
::
FromString
(
"Thu Jan 01 00:00:02 GMT 1970"
,
&
parsed_time
));
EXPECT_EQ
(
2
,
parsed_time
.
ToTimeT
());
}
TEST_F
(
TimeTest
,
DISABLED_
ParseTimeTestEpochNeg1
)
{
Time
parsed_time
;
// time_t == 1 second before epoch == -1
EXPECT_TRUE
(
Time
::
FromString
(
"Thu Jan 01 00:59:59 +0100 1970"
,
&
parsed_time
));
EXPECT_EQ
(
-
1
,
parsed_time
.
ToTimeT
());
EXPECT_TRUE
(
Time
::
FromString
(
"Wed Dec 31 23:59:59 GMT 1969"
,
&
parsed_time
));
EXPECT_EQ
(
-
1
,
parsed_time
.
ToTimeT
());
}
// If time_t is 32 bits, a date after year 2038 will overflow time_t and
// cause timegm() to return -1. The parsed time should not be 1 second
// before epoch.
TEST_F
(
TimeTest
,
DISABLED_
ParseTimeTestEpochNotNeg1
)
{
Time
parsed_time
;
EXPECT_TRUE
(
Time
::
FromString
(
"Wed Dec 31 23:59:59 GMT 2100"
,
&
parsed_time
));
EXPECT_NE
(
-
1
,
parsed_time
.
ToTimeT
());
}
TEST_F
(
TimeTest
,
DISABLED_
ParseTimeTestEpochNeg2
)
{
Time
parsed_time
;
// time_t == 2 seconds before epoch == -2
EXPECT_TRUE
(
Time
::
FromString
(
"Thu Jan 01 00:59:58 +0100 1970"
,
&
parsed_time
));
EXPECT_EQ
(
-
2
,
parsed_time
.
ToTimeT
());
EXPECT_TRUE
(
Time
::
FromString
(
"Wed Dec 31 23:59:58 GMT 1969"
,
&
parsed_time
));
EXPECT_EQ
(
-
2
,
parsed_time
.
ToTimeT
());
}
TEST_F
(
TimeTest
,
DISABLED_
ParseTimeTestEpoch1960
)
{
Time
parsed_time
;
// time_t before Epoch, in 1960
EXPECT_TRUE
(
Time
::
FromString
(
"Wed Jun 29 19:40:01 +0100 1960"
,
&
parsed_time
));
EXPECT_EQ
(
-
299999999
,
parsed_time
.
ToTimeT
());
EXPECT_TRUE
(
Time
::
FromString
(
"Wed Jun 29 18:40:01 GMT 1960"
,
&
parsed_time
));
EXPECT_EQ
(
-
299999999
,
parsed_time
.
ToTimeT
());
EXPECT_TRUE
(
Time
::
FromString
(
"Wed Jun 29 17:40:01 GMT 1960"
,
&
parsed_time
));
EXPECT_EQ
(
-
300003599
,
parsed_time
.
ToTimeT
());
}
TEST_F
(
TimeTest
,
DISABLED_
ParseTimeTestEmpty
)
{
Time
parsed_time
;
EXPECT_FALSE
(
Time
::
FromString
(
""
,
&
parsed_time
));
}
TEST_F
(
TimeTest
,
DISABLED_
ParseTimeTestInvalidString
)
{
Time
parsed_time
;
EXPECT_FALSE
(
Time
::
FromString
(
"Monday morning 2000"
,
&
parsed_time
));
}
TEST_F
(
TimeTest
,
ExplodeBeforeUnixEpoch
)
{
static
const
int
kUnixEpochYear
=
1970
;
// In case this changes (ha!).
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment