10485dae0Sopenharmony_ci/* 20485dae0Sopenharmony_ci * Copyright (c) 2021 Huawei Device Co., Ltd. 30485dae0Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 40485dae0Sopenharmony_ci * you may not use this file except in compliance with the License. 50485dae0Sopenharmony_ci * You may obtain a copy of the License at 60485dae0Sopenharmony_ci * 70485dae0Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 80485dae0Sopenharmony_ci * 90485dae0Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 100485dae0Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 110485dae0Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 120485dae0Sopenharmony_ci * See the License for the specific language governing permissions and 130485dae0Sopenharmony_ci * limitations under the License. 140485dae0Sopenharmony_ci */ 150485dae0Sopenharmony_ci 160485dae0Sopenharmony_ci#include "gtest/gtest.h" 170485dae0Sopenharmony_ci 180485dae0Sopenharmony_ci#include "platform/time/include/time.h" 190485dae0Sopenharmony_ci#include "platform/time/include/time_elapser.h" 200485dae0Sopenharmony_ci#include "utils/log/aie_log.h" 210485dae0Sopenharmony_ci 220485dae0Sopenharmony_ciusing namespace testing::ext; 230485dae0Sopenharmony_ciusing namespace OHOS::AI; 240485dae0Sopenharmony_ci 250485dae0Sopenharmony_cinamespace { 260485dae0Sopenharmony_ci const int SLEEP_TIME = 2000; 270485dae0Sopenharmony_ci const int S_TO_MS = 1000; // milliseconds to seconds 280485dae0Sopenharmony_ci} 290485dae0Sopenharmony_ci 300485dae0Sopenharmony_ciclass TimeTest : public testing::Test { 310485dae0Sopenharmony_cipublic: 320485dae0Sopenharmony_ci // SetUpTestCase:The preset action of the test suite is executed before the first TestCase 330485dae0Sopenharmony_ci static void SetUpTestCase() {}; 340485dae0Sopenharmony_ci 350485dae0Sopenharmony_ci // TearDownTestCase:The test suite cleanup action is executed after the last TestCase 360485dae0Sopenharmony_ci static void TearDownTestCase() {}; 370485dae0Sopenharmony_ci 380485dae0Sopenharmony_ci // SetUp:Execute before each test case 390485dae0Sopenharmony_ci void SetUp() {}; 400485dae0Sopenharmony_ci 410485dae0Sopenharmony_ci // TearDown:Execute after each test case 420485dae0Sopenharmony_ci void TearDown() {}; 430485dae0Sopenharmony_ci}; 440485dae0Sopenharmony_ci 450485dae0Sopenharmony_ci/** 460485dae0Sopenharmony_ci * @tc.name: TimeTest001 470485dae0Sopenharmony_ci * @tc.desc: Test StepSleepMs function. 480485dae0Sopenharmony_ci * @tc.type: FUNC 490485dae0Sopenharmony_ci * @tc.require: AR000F77OO 500485dae0Sopenharmony_ci */ 510485dae0Sopenharmony_ciHWTEST_F(TimeTest, TimeTest001, TestSize.Level1) 520485dae0Sopenharmony_ci{ 530485dae0Sopenharmony_ci time_t firstTime = GetCurTimeSec(); 540485dae0Sopenharmony_ci HILOGD("[Test]First time is %lld", firstTime); 550485dae0Sopenharmony_ci StepSleepMs(SLEEP_TIME); 560485dae0Sopenharmony_ci time_t curTime = GetCurTimeSec(); 570485dae0Sopenharmony_ci HILOGD("[Test]Second time is %lld", curTime); 580485dae0Sopenharmony_ci ASSERT_EQ((curTime - firstTime)*S_TO_MS, SLEEP_TIME); 590485dae0Sopenharmony_ci} 60