1 /*
2 * Copyright (C) 2022 Huawei Device Co., Ltd.
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
16 #include "relative_timer_test.h"
17
18 #include <chrono>
19 #include <future>
20
21 #include "relative_timer.h"
22
23 namespace OHOS {
24 namespace UserIam {
25 namespace UserAuth {
26 using namespace testing;
27 using namespace testing::ext;
28
SetUpTestCase()29 void RelativeTimerTest::SetUpTestCase()
30 {
31 }
32
TearDownTestCase()33 void RelativeTimerTest::TearDownTestCase()
34 {
35 }
36
SetUp()37 void RelativeTimerTest::SetUp()
38 {
39 }
40
TearDown()41 void RelativeTimerTest::TearDown()
42 {
43 }
44
45 HWTEST_F(RelativeTimerTest, RelativeTimerTest, TestSize.Level0)
46 {
47 using namespace std::chrono;
48 std::promise<void> ensure;
49
50 auto &timer = RelativeTimer::GetInstance();
51 const time_point<system_clock> start = system_clock::now();
__anond03b9b700102() 52 (void)timer.Register([&ensure]() { ensure.set_value(); }, 565);
53 ensure.get_future().get();
54 time_point<system_clock> finish = system_clock::now();
55 auto cost = duration_cast<milliseconds>(finish - start).count();
56 EXPECT_GT(cost, 560);
57 EXPECT_LT(cost, 700);
58 }
59 } // namespace UserAuth
60 } // namespace UserIam
61 } // namespace OHOS
62