mirror of
https://github.com/openharmony/device_manager.git
synced 2026-08-27 03:21:19 -04:00
76e87cf437
Signed-off-by: wangyb0625 <wangyibo38@huawei.com>
158 lines
4.1 KiB
C++
158 lines
4.1 KiB
C++
/*
|
|
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
|
|
#include <iostream>
|
|
#include <string>
|
|
#include <unistd.h>
|
|
|
|
#include "dm_constants.h"
|
|
#include "dm_timer.h"
|
|
#include "UTTest_dm_timer.h"
|
|
|
|
namespace OHOS {
|
|
namespace DistributedHardware {
|
|
void TimeHeapTest::SetUp()
|
|
{
|
|
}
|
|
|
|
void TimeHeapTest::TearDown()
|
|
{
|
|
}
|
|
|
|
void TimeHeapTest::SetUpTestCase()
|
|
{
|
|
}
|
|
|
|
void TimeHeapTest::TearDownTestCase()
|
|
{
|
|
}
|
|
|
|
namespace {
|
|
static void TimeOut(std::string timerName) {}
|
|
|
|
/**
|
|
* @tc.name: TimeHeapTest::StartTimer_001
|
|
* @tc.desc: Timeout event trigger
|
|
* @tc.type: FUNC
|
|
* @tc.require: AR000GHSJK
|
|
*/
|
|
HWTEST_F(TimeHeapTest, StartTimer_001, testing::ext::TestSize.Level0)
|
|
{
|
|
std::string name = AUTHENTICATE_TIMEOUT_TASK;
|
|
int32_t timeout = 10;
|
|
|
|
std::shared_ptr<DmTimer> timer = std::make_shared<DmTimer>();
|
|
int32_t ret = timer->StartTimer("", timeout, TimeOut);
|
|
EXPECT_EQ(ERR_DM_INPUT_PARA_INVALID, ret);
|
|
|
|
ret = timer->StartTimer(AUTHENTICATE_TIMEOUT_TASK, 400, TimeOut);
|
|
EXPECT_EQ(ERR_DM_INPUT_PARA_INVALID, ret);
|
|
|
|
ret = timer->StartTimer(AUTHENTICATE_TIMEOUT_TASK, -20, TimeOut);
|
|
EXPECT_EQ(ERR_DM_INPUT_PARA_INVALID, ret);
|
|
|
|
ret = timer->StartTimer(AUTHENTICATE_TIMEOUT_TASK, timeout, nullptr);
|
|
EXPECT_EQ(ERR_DM_INPUT_PARA_INVALID, ret);
|
|
}
|
|
|
|
/**
|
|
* @tc.name: TimeHeapTest::StartTimer_002
|
|
* @tc.desc: Timeout event trigger
|
|
* @tc.type: FUNC
|
|
* @tc.require: AR000GHSJK
|
|
*/
|
|
HWTEST_F(TimeHeapTest, StartTimer_002, testing::ext::TestSize.Level0)
|
|
{
|
|
std::string name = AUTHENTICATE_TIMEOUT_TASK;
|
|
std::string name2 = "test2"
|
|
int32_t timeOut = 10;
|
|
int32_t timeOut2 = 40;
|
|
std::shared_ptr<DmTimer> timer = std::make_shared<DmTimer>();
|
|
int32_t ret = timer->StartTimer(name, timeOut, TimeOut);
|
|
EXPECT_EQ(DM_OK, ret);
|
|
|
|
ret = timer->StartTimer(name2, timeOut2, TimeOut);
|
|
EXPECT_EQ(DM_OK, ret);
|
|
}
|
|
|
|
/**
|
|
* @tc.name: TimeHeapTest::DeleteTimer_001
|
|
* @tc.desc: Timeout event trigger
|
|
* @tc.type: FUNC
|
|
* @tc.require: AR000GHSJK
|
|
*/
|
|
HWTEST_F(TimeHeapTest, DeleteTimer_001, testing::ext::TestSize.Level0)
|
|
{
|
|
std::shared_ptr<DmTimer> timer = std::make_shared<DmTimer>();
|
|
int32_t ret = timer->DeleteTimer("");
|
|
EXPECT_EQ(ERR_DM_INPUT_PARA_INVALID, ret);
|
|
|
|
ret = timer->DeleteTimer(name);
|
|
EXPECT_EQ(ERR_DM_INPUT_PARA_INVALID, ret);
|
|
}
|
|
|
|
/**
|
|
* @tc.name: TimeHeapTest::DeleteTimer_002
|
|
* @tc.desc: Timeout event trigger
|
|
* @tc.type: FUNC
|
|
* @tc.require: AR000GHSJK
|
|
*/
|
|
HWTEST_F(TimeHeapTest, DeleteTimer_002, testing::ext::TestSize.Level0)
|
|
{
|
|
std::string name = AUTHENTICATE_TIMEOUT_TASK;
|
|
int32_t timeOut = 10;
|
|
std::shared_ptr<DmTimer> timer = std::make_shared<DmTimer>();
|
|
timer->StartTimer(name, timeOut, TimeOut);
|
|
ret = timer->DeleteTimer(name);
|
|
EXPECT_EQ(DM_OK, ret);
|
|
}
|
|
|
|
/**
|
|
* @tc.name: TimeHeapTest::DeleteAll_001
|
|
* @tc.desc: Timeout event trigger
|
|
* @tc.type: FUNC
|
|
* @tc.require: AR000GHSJK
|
|
*/
|
|
HWTEST_F(TimeHeapTest, DeleteAll_001, testing::ext::TestSize.Level0)
|
|
{
|
|
std::string name = AUTHENTICATE_TIMEOUT_TASK;
|
|
int32_t timeOut = 10;
|
|
std::shared_ptr<DmTimer> timer = std::make_shared<DmTimer>();
|
|
timer->DeleteAll();
|
|
EXPECT_EQ(DM_OK, ret);
|
|
|
|
timer->StartTimer(name, timeOut, TimeOut);
|
|
timer->DeleteAll();
|
|
EXPECT_EQ(DM_OK, ret);
|
|
}
|
|
|
|
/**
|
|
* @tc.name: TimeHeapTest::TimerRunning_001
|
|
* @tc.desc: Timeout event trigger
|
|
* @tc.type: FUNC
|
|
* @tc.require: AR000GHSJK
|
|
*/
|
|
HWTEST_F(TimeHeapTest, TimerRunning_001, testing::ext::TestSize.Level0)
|
|
{
|
|
std::string name = AUTHENTICATE_TIMEOUT_TASK;
|
|
int32_t timeOut = 10;
|
|
std::shared_ptr<DmTimer> timer = std::make_shared<DmTimer>();
|
|
timer->TimerRunning();
|
|
EXPECT_EQ(DM_OK, ret);
|
|
}
|
|
}
|
|
}
|
|
}
|