179a732c7Sopenharmony_ci/* 279a732c7Sopenharmony_ci * Copyright (c) 2022 Huawei Device Co., Ltd. 379a732c7Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 479a732c7Sopenharmony_ci * you may not use this file except in compliance with the License. 579a732c7Sopenharmony_ci * You may obtain a copy of the License at 679a732c7Sopenharmony_ci * 779a732c7Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 879a732c7Sopenharmony_ci * 979a732c7Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 1079a732c7Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 1179a732c7Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1279a732c7Sopenharmony_ci * See the License for the specific language governing permissions and 1379a732c7Sopenharmony_ci * limitations under the License. 1479a732c7Sopenharmony_ci */ 1579a732c7Sopenharmony_ci 1679a732c7Sopenharmony_ci#include <iostream> 1779a732c7Sopenharmony_ci#include <string> 1879a732c7Sopenharmony_ci#include <unistd.h> 1979a732c7Sopenharmony_ci 2079a732c7Sopenharmony_ci#include "dm_constants.h" 2179a732c7Sopenharmony_ci#include "dm_timer.h" 2279a732c7Sopenharmony_ci#include "UTTest_dm_timer.h" 2379a732c7Sopenharmony_ci 2479a732c7Sopenharmony_cinamespace OHOS { 2579a732c7Sopenharmony_cinamespace DistributedHardware { 2679a732c7Sopenharmony_civoid TimeHeapTest::SetUp() 2779a732c7Sopenharmony_ci{ 2879a732c7Sopenharmony_ci} 2979a732c7Sopenharmony_ci 3079a732c7Sopenharmony_civoid TimeHeapTest::TearDown() 3179a732c7Sopenharmony_ci{ 3279a732c7Sopenharmony_ci} 3379a732c7Sopenharmony_ci 3479a732c7Sopenharmony_civoid TimeHeapTest::SetUpTestCase() 3579a732c7Sopenharmony_ci{ 3679a732c7Sopenharmony_ci} 3779a732c7Sopenharmony_ci 3879a732c7Sopenharmony_civoid TimeHeapTest::TearDownTestCase() 3979a732c7Sopenharmony_ci{ 4079a732c7Sopenharmony_ci} 4179a732c7Sopenharmony_ci 4279a732c7Sopenharmony_cinamespace { 4379a732c7Sopenharmony_cistatic void TimeOut(std::string timerName) {} 4479a732c7Sopenharmony_ci 4579a732c7Sopenharmony_ci/** 4679a732c7Sopenharmony_ci * @tc.name: TimeHeapTest::StartTimer_001 4779a732c7Sopenharmony_ci * @tc.desc: Timeout event trigger 4879a732c7Sopenharmony_ci * @tc.type: FUNC 4979a732c7Sopenharmony_ci * @tc.require: AR000GHSJK 5079a732c7Sopenharmony_ci */ 5179a732c7Sopenharmony_ciHWTEST_F(TimeHeapTest, StartTimer_001, testing::ext::TestSize.Level0) 5279a732c7Sopenharmony_ci{ 5379a732c7Sopenharmony_ci std::string name = std::string(AUTHENTICATE_TIMEOUT_TASK); 5479a732c7Sopenharmony_ci int32_t timeout = 10; 5579a732c7Sopenharmony_ci 5679a732c7Sopenharmony_ci std::shared_ptr<DmTimer> timer = std::make_shared<DmTimer>(); 5779a732c7Sopenharmony_ci int32_t ret = timer->StartTimer("", timeout, TimeOut); 5879a732c7Sopenharmony_ci EXPECT_EQ(ERR_DM_INPUT_PARA_INVALID, ret); 5979a732c7Sopenharmony_ci 6079a732c7Sopenharmony_ci ret = timer->StartTimer(std::string(AUTHENTICATE_TIMEOUT_TASK), 400, TimeOut); 6179a732c7Sopenharmony_ci EXPECT_EQ(ERR_DM_INPUT_PARA_INVALID, ret); 6279a732c7Sopenharmony_ci 6379a732c7Sopenharmony_ci ret = timer->StartTimer(std::string(AUTHENTICATE_TIMEOUT_TASK), -20, TimeOut); 6479a732c7Sopenharmony_ci EXPECT_EQ(ERR_DM_INPUT_PARA_INVALID, ret); 6579a732c7Sopenharmony_ci 6679a732c7Sopenharmony_ci ret = timer->StartTimer(std::string(AUTHENTICATE_TIMEOUT_TASK), timeout, nullptr); 6779a732c7Sopenharmony_ci EXPECT_EQ(ERR_DM_INPUT_PARA_INVALID, ret); 6879a732c7Sopenharmony_ci} 6979a732c7Sopenharmony_ci 7079a732c7Sopenharmony_ci/** 7179a732c7Sopenharmony_ci * @tc.name: TimeHeapTest::StartTimer_002 7279a732c7Sopenharmony_ci * @tc.desc: Timeout event trigger 7379a732c7Sopenharmony_ci * @tc.type: FUNC 7479a732c7Sopenharmony_ci * @tc.require: AR000GHSJK 7579a732c7Sopenharmony_ci */ 7679a732c7Sopenharmony_ciHWTEST_F(TimeHeapTest, StartTimer_002, testing::ext::TestSize.Level0) 7779a732c7Sopenharmony_ci{ 7879a732c7Sopenharmony_ci std::string name = std::string(AUTHENTICATE_TIMEOUT_TASK); 7979a732c7Sopenharmony_ci std::string name2 = "test2"; 8079a732c7Sopenharmony_ci int32_t timeOut = 10; 8179a732c7Sopenharmony_ci int32_t timeOut2 = 40; 8279a732c7Sopenharmony_ci std::shared_ptr<DmTimer> timer = std::make_shared<DmTimer>(); 8379a732c7Sopenharmony_ci int32_t ret = timer->StartTimer(name, timeOut, TimeOut); 8479a732c7Sopenharmony_ci EXPECT_EQ(DM_OK, ret); 8579a732c7Sopenharmony_ci 8679a732c7Sopenharmony_ci ret = timer->StartTimer(name2, timeOut2, TimeOut); 8779a732c7Sopenharmony_ci EXPECT_EQ(DM_OK, ret); 8879a732c7Sopenharmony_ci} 8979a732c7Sopenharmony_ci 9079a732c7Sopenharmony_ci/** 9179a732c7Sopenharmony_ci * @tc.name: TimeHeapTest::DeleteTimer_001 9279a732c7Sopenharmony_ci * @tc.desc: Timeout event trigger 9379a732c7Sopenharmony_ci * @tc.type: FUNC 9479a732c7Sopenharmony_ci * @tc.require: AR000GHSJK 9579a732c7Sopenharmony_ci */ 9679a732c7Sopenharmony_ciHWTEST_F(TimeHeapTest, DeleteTimer_001, testing::ext::TestSize.Level0) 9779a732c7Sopenharmony_ci{ 9879a732c7Sopenharmony_ci std::string name = std::string(AUTHENTICATE_TIMEOUT_TASK); 9979a732c7Sopenharmony_ci std::shared_ptr<DmTimer> timer = std::make_shared<DmTimer>(); 10079a732c7Sopenharmony_ci int32_t ret = timer->DeleteTimer(""); 10179a732c7Sopenharmony_ci EXPECT_EQ(ERR_DM_INPUT_PARA_INVALID, ret); 10279a732c7Sopenharmony_ci 10379a732c7Sopenharmony_ci ret = timer->DeleteTimer(name); 10479a732c7Sopenharmony_ci EXPECT_EQ(ERR_DM_FAILED, ret); 10579a732c7Sopenharmony_ci} 10679a732c7Sopenharmony_ci 10779a732c7Sopenharmony_ci/** 10879a732c7Sopenharmony_ci * @tc.name: TimeHeapTest::DeleteTimer_002 10979a732c7Sopenharmony_ci * @tc.desc: Timeout event trigger 11079a732c7Sopenharmony_ci * @tc.type: FUNC 11179a732c7Sopenharmony_ci * @tc.require: AR000GHSJK 11279a732c7Sopenharmony_ci */ 11379a732c7Sopenharmony_ciHWTEST_F(TimeHeapTest, DeleteTimer_002, testing::ext::TestSize.Level0) 11479a732c7Sopenharmony_ci{ 11579a732c7Sopenharmony_ci std::string name = std::string(AUTHENTICATE_TIMEOUT_TASK); 11679a732c7Sopenharmony_ci int32_t timeOut = 10; 11779a732c7Sopenharmony_ci std::shared_ptr<DmTimer> timer = std::make_shared<DmTimer>(); 11879a732c7Sopenharmony_ci timer->StartTimer(name, timeOut, TimeOut); 11979a732c7Sopenharmony_ci int32_t ret = timer->DeleteTimer(name); 12079a732c7Sopenharmony_ci EXPECT_EQ(DM_OK, ret); 12179a732c7Sopenharmony_ci} 12279a732c7Sopenharmony_ci 12379a732c7Sopenharmony_ci/** 12479a732c7Sopenharmony_ci * @tc.name: TimeHeapTest::DeleteAll_001 12579a732c7Sopenharmony_ci * @tc.desc: Timeout event trigger 12679a732c7Sopenharmony_ci * @tc.type: FUNC 12779a732c7Sopenharmony_ci * @tc.require: AR000GHSJK 12879a732c7Sopenharmony_ci */ 12979a732c7Sopenharmony_ciHWTEST_F(TimeHeapTest, DeleteAll_001, testing::ext::TestSize.Level0) 13079a732c7Sopenharmony_ci{ 13179a732c7Sopenharmony_ci std::string name = std::string(AUTHENTICATE_TIMEOUT_TASK); 13279a732c7Sopenharmony_ci int32_t timeOut = 10; 13379a732c7Sopenharmony_ci std::shared_ptr<DmTimer> timer = std::make_shared<DmTimer>(); 13479a732c7Sopenharmony_ci int32_t ret = timer->DeleteAll(); 13579a732c7Sopenharmony_ci EXPECT_EQ(DM_OK, ret); 13679a732c7Sopenharmony_ci 13779a732c7Sopenharmony_ci timer->StartTimer(name, timeOut, TimeOut); 13879a732c7Sopenharmony_ci ret = timer->DeleteAll(); 13979a732c7Sopenharmony_ci EXPECT_EQ(DM_OK, ret); 14079a732c7Sopenharmony_ci} 14179a732c7Sopenharmony_ci} 14279a732c7Sopenharmony_ci} 14379a732c7Sopenharmony_ci} 144