aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam Cozzette <acozzette@gmail.com>2018-01-08 10:41:54 -0800
committerGitHub <noreply@github.com>2018-01-08 10:41:54 -0800
commitb77aa8011d450e314690e430ede85d4ab20abaf3 (patch)
tree3888235830633b72dce35a6165efee7c80b5cb78
parentd4afdba83d19fded7822324a7f8e68648d296260 (diff)
parent091eeb1261ebe6bc557ae9b353d37108c8149568 (diff)
downloadprotobuf-b77aa8011d450e314690e430ede85d4ab20abaf3.tar.gz
protobuf-b77aa8011d450e314690e430ede85d4ab20abaf3.tar.bz2
protobuf-b77aa8011d450e314690e430ede85d4ab20abaf3.zip
Merge pull request #4148 from datacompboy/patch-2
Add more tests to time_test
-rw-r--r--src/google/protobuf/stubs/time_test.cc53
1 files changed, 53 insertions, 0 deletions
diff --git a/src/google/protobuf/stubs/time_test.cc b/src/google/protobuf/stubs/time_test.cc
index 59e9d1c7..53da9480 100644
--- a/src/google/protobuf/stubs/time_test.cc
+++ b/src/google/protobuf/stubs/time_test.cc
@@ -149,6 +149,59 @@ TEST(DateTimeTest, LeapYear) {
CreateTimestamp(2400, 3, 1) - CreateTimestamp(2400, 2, 29));
}
+TEST(DateTimeTest, WrongDays) {
+ int64 seconds;
+ DateTime time;
+ time.hour = 0;
+ time.minute = 0;
+ time.second = 0;
+ time.month = 2;
+
+ // Non-leap year.
+ time.year = 2015;
+ time.day = 29;
+ ASSERT_FALSE(DateTimeToSeconds(time, &seconds));
+
+ // Leap year.
+ time.year = 2016;
+ time.day = 29;
+ ASSERT_TRUE(DateTimeToSeconds(time, &seconds));
+ time.day = 30;
+ ASSERT_FALSE(DateTimeToSeconds(time, &seconds));
+
+ // Non-leap year.
+ time.year = 2100;
+ time.day = 29;
+ ASSERT_FALSE(DateTimeToSeconds(time, &seconds));
+
+ // Leap year.
+ time.year = 2400;
+ time.day = 29;
+ ASSERT_TRUE(DateTimeToSeconds(time, &seconds));
+ time.day = 30;
+ ASSERT_FALSE(DateTimeToSeconds(time, &seconds));
+
+ // Non-february
+ time.year = 2015;
+ time.month = 1;
+ time.day = 0;
+ ASSERT_FALSE(DateTimeToSeconds(time, &seconds));
+ time.day = 1;
+ ASSERT_TRUE(DateTimeToSeconds(time, &seconds));
+ time.day = 31;
+ ASSERT_TRUE(DateTimeToSeconds(time, &seconds));
+ time.day = 32;
+ ASSERT_FALSE(DateTimeToSeconds(time, &seconds));
+
+ // Bad month
+ time.year = 2015;
+ time.month = 0;
+ time.day = 1;
+ ASSERT_FALSE(DateTimeToSeconds(time, &seconds));
+ time.month = 13;
+ ASSERT_FALSE(DateTimeToSeconds(time, &seconds));
+}
+
TEST(DateTimeTest, StringFormat) {
DateTime start, end;
start.year = 1;