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

Side by Side Diff: base/time/time_unittest.cc

Issue 27472003: android: fix base::Time::FromLocalExploded() crash. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use new code paths on all platforms. Created 7 years, 2 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 | « base/time/time_posix.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/time/time.h" 5 #include "base/time/time.h"
6 6
7 #include <time.h> 7 #include <time.h>
8 8
9 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 #include "base/logging.h"
11 #include "base/strings/stringprintf.h"
10 #include "base/threading/platform_thread.h" 12 #include "base/threading/platform_thread.h"
11 #include "build/build_config.h" 13 #include "build/build_config.h"
12 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
13 15
14 using base::Time; 16 using base::Time;
15 using base::TimeDelta; 17 using base::TimeDelta;
16 using base::TimeTicks; 18 using base::TimeTicks;
17 19
18 // Specialized test fixture allowing time strings without timezones to be 20 // Specialized test fixture allowing time strings without timezones to be
19 // tested by comparing them to a known time in the local zone. 21 // tested by comparing them to a known time in the local zone.
(...skipping 514 matching lines...) Expand 10 before | Expand all | Expand 10 after
534 } 536 }
535 537
536 #if defined(OS_MACOSX) 538 #if defined(OS_MACOSX)
537 TEST_F(TimeTest, TimeTOverflow) { 539 TEST_F(TimeTest, TimeTOverflow) {
538 Time t = Time::FromInternalValue(std::numeric_limits<int64>::max() - 1); 540 Time t = Time::FromInternalValue(std::numeric_limits<int64>::max() - 1);
539 EXPECT_FALSE(t.is_max()); 541 EXPECT_FALSE(t.is_max());
540 EXPECT_EQ(std::numeric_limits<time_t>::max(), t.ToTimeT()); 542 EXPECT_EQ(std::numeric_limits<time_t>::max(), t.ToTimeT());
541 } 543 }
542 #endif 544 #endif
543 545
546 #if defined(OS_ANDROID)
547 TEST_F(TimeTest, FromLocalExplodedCrashOnAndroid) {
jar (doing other things) 2013/10/21 18:15:20 nit: IMO, you should have "similar" tests on all p
548 // This crashed inside Time:: FromLocalExploded() on Android 4.1.2.
549 // See http://crbug.com/287821
550 Time::Exploded midnight = {2013, // year
551 10, // month
552 0, // day_of_week
553 13, // day_of_month
554 0, // hour
555 0, // minute
556 0, // second
557 };
558 // The string passed to putenv() must be a char* and the documentation states
559 // that it 'becomes part of the environment', so use a static buffer.
560 static char buffer[] = "TZ=America/Santiago";
561 putenv(buffer);
562 tzset();
563 Time t = Time::FromLocalExploded(midnight);
564 EXPECT_EQ(1381633200, t.ToTimeT());
565 }
566 #endif // OS_ANDROID
567
544 TEST(TimeTicks, Deltas) { 568 TEST(TimeTicks, Deltas) {
545 for (int index = 0; index < 50; index++) { 569 for (int index = 0; index < 50; index++) {
546 TimeTicks ticks_start = TimeTicks::Now(); 570 TimeTicks ticks_start = TimeTicks::Now();
547 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(10)); 571 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(10));
548 TimeTicks ticks_stop = TimeTicks::Now(); 572 TimeTicks ticks_stop = TimeTicks::Now();
549 TimeDelta delta = ticks_stop - ticks_start; 573 TimeDelta delta = ticks_stop - ticks_start;
550 // Note: Although we asked for a 10ms sleep, if the 574 // Note: Although we asked for a 10ms sleep, if the
551 // time clock has a finer granularity than the Sleep() 575 // time clock has a finer granularity than the Sleep()
552 // clock, it is quite possible to wakeup early. Here 576 // clock, it is quite possible to wakeup early. Here
553 // is how that works: 577 // is how that works:
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
682 exploded.minute = 0; 706 exploded.minute = 0;
683 exploded.second = 0; 707 exploded.second = 0;
684 exploded.millisecond = 0; 708 exploded.millisecond = 0;
685 Time t = Time::FromUTCExploded(exploded); 709 Time t = Time::FromUTCExploded(exploded);
686 // Unix 1970 epoch. 710 // Unix 1970 epoch.
687 EXPECT_EQ(GG_INT64_C(11644473600000000), t.ToInternalValue()); 711 EXPECT_EQ(GG_INT64_C(11644473600000000), t.ToInternalValue());
688 712
689 // We can't test 1601 epoch, since the system time functions on Linux 713 // We can't test 1601 epoch, since the system time functions on Linux
690 // only compute years starting from 1900. 714 // only compute years starting from 1900.
691 } 715 }
OLDNEW
« no previous file with comments | « base/time/time_posix.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698