| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 <process.h> | 6 #include <process.h> |
| 7 | 7 |
| 8 #include "base/time.h" | 8 #include "base/time.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 | 10 |
| 11 namespace { | 11 namespace { |
| 12 | 12 |
| 13 class MockTimeTicks : public TimeTicks { | 13 class MockTimeTicks : public TimeTicks { |
| 14 public: | 14 public: |
| 15 static int Ticker() { | 15 static DWORD __stdcall Ticker() { |
| 16 return static_cast<int>(InterlockedIncrement(&ticker_)); | 16 return static_cast<int>(InterlockedIncrement(&ticker_)); |
| 17 } | 17 } |
| 18 | 18 |
| 19 static void InstallTicker() { | 19 static void InstallTicker() { |
| 20 old_tick_function_ = tick_function_; | 20 old_tick_function_ = SetMockTickFunction(&Ticker); |
| 21 tick_function_ = reinterpret_cast<TickFunction>(&Ticker); | |
| 22 ticker_ = -5; | 21 ticker_ = -5; |
| 23 } | 22 } |
| 24 | 23 |
| 25 static void UninstallTicker() { | 24 static void UninstallTicker() { |
| 26 tick_function_ = old_tick_function_; | 25 SetMockTickFunction(old_tick_function_); |
| 27 } | 26 } |
| 28 | 27 |
| 29 private: | 28 private: |
| 30 static volatile LONG ticker_; | 29 static volatile LONG ticker_; |
| 31 static TickFunction old_tick_function_; | 30 static TickFunctionType old_tick_function_; |
| 32 }; | 31 }; |
| 33 | 32 |
| 34 volatile LONG MockTimeTicks::ticker_; | 33 volatile LONG MockTimeTicks::ticker_; |
| 35 MockTimeTicks::TickFunction MockTimeTicks::old_tick_function_; | 34 MockTimeTicks::TickFunctionType MockTimeTicks::old_tick_function_; |
| 36 | 35 |
| 37 HANDLE g_rollover_test_start; | 36 HANDLE g_rollover_test_start; |
| 38 | 37 |
| 39 unsigned __stdcall RolloverTestThreadMain(void* param) { | 38 unsigned __stdcall RolloverTestThreadMain(void* param) { |
| 40 int64 counter = reinterpret_cast<int64>(param); | 39 int64 counter = reinterpret_cast<int64>(param); |
| 41 DWORD rv = WaitForSingleObject(g_rollover_test_start, INFINITE); | 40 DWORD rv = WaitForSingleObject(g_rollover_test_start, INFINITE); |
| 42 EXPECT_EQ(rv, WAIT_OBJECT_0); | 41 EXPECT_EQ(rv, WAIT_OBJECT_0); |
| 43 | 42 |
| 44 TimeTicks last = TimeTicks::Now(); | 43 TimeTicks last = TimeTicks::Now(); |
| 45 for (int index = 0; index < counter; index++) { | 44 for (int index = 0; index < counter; index++) { |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 DWORD rv = WaitForSingleObject(threads[index], INFINITE); | 92 DWORD rv = WaitForSingleObject(threads[index], INFINITE); |
| 94 EXPECT_EQ(rv, WAIT_OBJECT_0); | 93 EXPECT_EQ(rv, WAIT_OBJECT_0); |
| 95 } | 94 } |
| 96 | 95 |
| 97 CloseHandle(g_rollover_test_start); | 96 CloseHandle(g_rollover_test_start); |
| 98 | 97 |
| 99 // Teardown | 98 // Teardown |
| 100 MockTimeTicks::UninstallTicker(); | 99 MockTimeTicks::UninstallTicker(); |
| 101 } | 100 } |
| 102 } | 101 } |
| OLD | NEW |