1 : // Copyright 2014 Google Inc. All Rights Reserved.
2 : //
3 : // Licensed under the Apache License, Version 2.0 (the "License");
4 : // you may not use this file except in compliance with the License.
5 : // You may obtain a copy of the License at
6 : //
7 : // http://www.apache.org/licenses/LICENSE-2.0
8 : //
9 : // Unless required by applicable law or agreed to in writing, software
10 : // distributed under the License is distributed on an "AS IS" BASIS,
11 : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 : // See the License for the specific language governing permissions and
13 : // limitations under the License.
14 :
15 : #include "syzygy/kasko/waitable_timer_impl.h"
16 :
17 : #include <windows.h>
18 :
19 : #include "base/memory/scoped_ptr.h"
20 : #include "base/time/time.h"
21 : #include "gtest/gtest.h"
22 :
23 : namespace kasko {
24 :
25 E : TEST(WaitableTimerImplTest, BasicTest) {
26 E : base::Time start = base::Time::Now();
27 : scoped_ptr<WaitableTimer> instance =
28 E : WaitableTimerImpl::Create(base::TimeDelta::FromMilliseconds(100));
29 E : ASSERT_TRUE(instance);
30 E : instance->Start();
31 : // Wait up to 5000 ms.
32 E : ASSERT_EQ(WAIT_OBJECT_0, ::WaitForSingleObject(instance->GetHANDLE(), 5000));
33 E : EXPECT_LT(50, (base::Time::Now() - start).InMilliseconds());
34 E : EXPECT_GT(500, (base::Time::Now() - start).InMilliseconds());
35 E : }
36 :
37 : } // namespace kasko
|