1/*
2 * Copyright (c) 2021 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 "gtest/gtest.h"
17
18#include "platform/time/include/time.h"
19#include "platform/time/include/time_elapser.h"
20#include "utils/log/aie_log.h"
21
22using namespace testing::ext;
23using namespace OHOS::AI;
24
25namespace {
26    const int SLEEP_TIME = 2000;
27    const int S_TO_MS = 1000; // milliseconds to seconds
28}
29
30class TimeTest : public testing::Test {
31public:
32    // SetUpTestCase:The preset action of the test suite is executed before the first TestCase
33    static void SetUpTestCase() {};
34
35    // TearDownTestCase:The test suite cleanup action is executed after the last TestCase
36    static void TearDownTestCase() {};
37
38    // SetUp:Execute before each test case
39    void SetUp() {};
40
41    // TearDown:Execute after each test case
42    void TearDown() {};
43};
44
45/**
46 * @tc.name: TimeTest001
47 * @tc.desc: Test StepSleepMs function.
48 * @tc.type: FUNC
49 * @tc.require: AR000F77OO
50 */
51HWTEST_F(TimeTest, TimeTest001, TestSize.Level1)
52{
53    time_t firstTime = GetCurTimeSec();
54    HILOGD("[Test]First time is %lld", firstTime);
55    StepSleepMs(SLEEP_TIME);
56    time_t curTime = GetCurTimeSec();
57    HILOGD("[Test]Second time is %lld", curTime);
58    ASSERT_EQ((curTime - firstTime)*S_TO_MS, SLEEP_TIME);
59}
60