Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 <windows.h> | 5 #include <windows.h> |
| 6 #include <mmsystem.h> | 6 #include <mmsystem.h> |
| 7 #include <process.h> | 7 #include <process.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <cmath> | 10 #include <cmath> |
| 11 #include <limits> | 11 #include <limits> |
| 12 #include <vector> | 12 #include <vector> |
| 13 | 13 |
| 14 #include "base/threading/platform_thread.h" | 14 #include "base/threading/platform_thread.h" |
| 15 #include "base/time/time.h" | 15 #include "base/time/time.h" |
| 16 #include "base/win/registry.h" | 16 #include "base/win/registry.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 18 | 18 |
| 19 namespace base { | 19 namespace base { |
| 20 namespace { | 20 namespace { |
| 21 | 21 |
| 22 // For TimeDelta::ConstexprInitialization | |
| 23 constexpr int kExpectedDeltaInMilliseconds = 10; | |
| 24 constexpr TimeDelta kConstexprTimeDelta = | |
| 25 TimeDelta::FromMilliseconds(kExpectedDeltaInMilliseconds); | |
| 26 | |
| 22 class MockTimeTicks : public TimeTicks { | 27 class MockTimeTicks : public TimeTicks { |
| 23 public: | 28 public: |
| 24 static DWORD Ticker() { | 29 static DWORD Ticker() { |
| 25 return static_cast<int>(InterlockedIncrement(&ticker_)); | 30 return static_cast<int>(InterlockedIncrement(&ticker_)); |
| 26 } | 31 } |
| 27 | 32 |
| 28 static void InstallTicker() { | 33 static void InstallTicker() { |
| 29 old_tick_function_ = SetMockTickFunction(&Ticker); | 34 old_tick_function_ = SetMockTickFunction(&Ticker); |
| 30 ticker_ = -5; | 35 ticker_ = -5; |
| 31 } | 36 } |
| (...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 283 const double converted_microseconds_since_origin = | 288 const double converted_microseconds_since_origin = |
| 284 static_cast<double>((converted_value - TimeTicks()).InMicroseconds()); | 289 static_cast<double>((converted_value - TimeTicks()).InMicroseconds()); |
| 285 EXPECT_NEAR(expected_microseconds_since_origin, | 290 EXPECT_NEAR(expected_microseconds_since_origin, |
| 286 converted_microseconds_since_origin, | 291 converted_microseconds_since_origin, |
| 287 1.0) | 292 1.0) |
| 288 << "ticks=" << ticks << ", to be converted via logic path: " | 293 << "ticks=" << ticks << ", to be converted via logic path: " |
| 289 << (ticks < Time::kQPCOverflowThreshold ? "FAST" : "SAFE"); | 294 << (ticks < Time::kQPCOverflowThreshold ? "FAST" : "SAFE"); |
| 290 } | 295 } |
| 291 } | 296 } |
| 292 | 297 |
| 298 TEST(TimeDelta, ConstexprInitialization) { | |
| 299 // Make sure that TimeDelta works around crbug.com/635974 | |
| 300 EXPECT_EQ(kExpectedDeltaInMilliseconds, kConstexprTimeDelta.InMilliseconds()); | |
|
Jeffrey Yasskin
2016/08/12 23:07:44
You're testing a bug in constexpr variables, so yo
| |
| 301 } | |
| 302 | |
| 293 } // namespace base | 303 } // namespace base |
| OLD | NEW |