mirror of
https://github.com/openharmony/device_manager.git
synced 2026-07-18 08:14:26 -04:00
@@ -4,7 +4,7 @@
|
||||
* 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
|
||||
* 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,
|
||||
@@ -27,16 +27,20 @@
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
void DmDiscoveryManagerTest::SetUp() {
|
||||
void DmDiscoveryManagerTest::SetUp()
|
||||
{
|
||||
}
|
||||
|
||||
void DmDiscoveryManagerTest::TearDown() {
|
||||
void DmDiscoveryManagerTest::TearDown()
|
||||
{
|
||||
}
|
||||
|
||||
void DmDiscoveryManagerTest::SetUpTestCase() {
|
||||
void DmDiscoveryManagerTest::SetUpTestCase()
|
||||
{
|
||||
}
|
||||
|
||||
void DmDiscoveryManagerTest::TearDownTestCase() {
|
||||
void DmDiscoveryManagerTest::TearDownTestCase()
|
||||
{
|
||||
}
|
||||
|
||||
namespace {
|
||||
@@ -50,7 +54,8 @@ std::shared_ptr<DmDiscoveryManager> discoveryMgr_ = std::make_shared<DmDiscovery
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000GHSJK
|
||||
*/
|
||||
HWTEST_F(DmDiscoveryManagerTest, DmDiscoveryManager_001, testing::ext::TestSize.Level0) {
|
||||
HWTEST_F(DmDiscoveryManagerTest, DmDiscoveryManager_001, testing::ext::TestSize.Level0)
|
||||
{
|
||||
std::shared_ptr<DmDiscoveryManager> Test = std::make_shared<DmDiscoveryManager>(softbusConnector_, listener_);
|
||||
ASSERT_NE(Test, nullptr);
|
||||
}
|
||||
@@ -61,7 +66,7 @@ HWTEST_F(DmDiscoveryManagerTest, DmDiscoveryManager_001, testing::ext::TestSize.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000GHSJK
|
||||
*/
|
||||
HWTEST_F(DmDiscoveryManagerTest, DmDiscoveryManager_002, testing::ext::TestSize.Level0)
|
||||
HWTEST_F(DmDiscoveryManagerTest, DmDiscoveryManager_002, testing::ext::TestSize.Level0)
|
||||
{
|
||||
std::shared_ptr<DmDiscoveryManager> Test = std::make_shared<DmDiscoveryManager>(softbusConnector_, listener_);
|
||||
Test.reset();
|
||||
@@ -70,29 +75,29 @@ HWTEST_F(DmDiscoveryManagerTest, DmDiscoveryManager_002, testing::ext::TestSize.
|
||||
|
||||
/**
|
||||
* @tc.name:StartDeviceDiscovery_001
|
||||
* @tc.desc: keeping pkgame unchanged, call StartDeviceDiscovery twice
|
||||
* @tc.desc: keeping pkgame unchanged, call StartDeviceDiscovery twice
|
||||
* so that its discoveryQueue is not empty and return DM_DISCOVERY_REPEATED
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000GHSJK
|
||||
*/
|
||||
HWTEST_F(DmDiscoveryManagerTest, StartDeviceDiscovery_001, testing::ext::TestSize.Level0)
|
||||
HWTEST_F(DmDiscoveryManagerTest, StartDeviceDiscovery_001, testing::ext::TestSize.Level0)
|
||||
{
|
||||
std::string pkgName = "com.ohos.helloworld";
|
||||
DmSubscribeInfo subscribeInfo;
|
||||
const std::string extra;
|
||||
discoveryMgr_->StartDeviceDiscovery(pkgName, subscribeInfo, extra);
|
||||
int32_t ret = discoveryMgr_->StartDeviceDiscovery(pkgName, subscribeInfo, extra);
|
||||
EXPECT_EQ (ret, DM_DISCOVERY_REPEATED);
|
||||
EXPECT_EQ(ret, DM_DISCOVERY_REPEATED);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name:StartDeviceDiscovery_002
|
||||
* @tc.desc: pkgame changed, call StartDeviceDiscovery twice
|
||||
* @tc.desc: pkgame changed, call StartDeviceDiscovery twice
|
||||
* so that its discoveryQueue is not empty and return DM_DISCOVERY_REPEATED
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000GHSJK
|
||||
*/
|
||||
HWTEST_F(DmDiscoveryManagerTest, StartDeviceDiscovery_002, testing::ext::TestSize.Level0)
|
||||
HWTEST_F(DmDiscoveryManagerTest, StartDeviceDiscovery_002, testing::ext::TestSize.Level0)
|
||||
{
|
||||
std::string pkgName = "com.ohos.helloworld";
|
||||
std::string extra;
|
||||
@@ -110,7 +115,7 @@ HWTEST_F(DmDiscoveryManagerTest, StartDeviceDiscovery_002, testing::ext::TestSiz
|
||||
* @tc.require: AR000GHSJK
|
||||
*/
|
||||
// doing
|
||||
HWTEST_F(DmDiscoveryManagerTest, StopDeviceDiscovery_001, testing::ext::TestSize.Level0)
|
||||
HWTEST_F(DmDiscoveryManagerTest, StopDeviceDiscovery_001, testing::ext::TestSize.Level0)
|
||||
{
|
||||
std::string pkgName = "com.ohos.helloworld";
|
||||
const std::string extra;
|
||||
@@ -127,18 +132,19 @@ HWTEST_F(DmDiscoveryManagerTest, StopDeviceDiscovery_001, testing::ext::TestSize
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000GHSJK
|
||||
*/
|
||||
HWTEST_F(DmDiscoveryManagerTest, OnDeviceFound_001, testing::ext::TestSize.Level0)
|
||||
HWTEST_F(DmDiscoveryManagerTest, OnDeviceFound_001, testing::ext::TestSize.Level0)
|
||||
{
|
||||
std::string pkgName = "com.ohos.helloworld";
|
||||
uint16_t aaa = 11;
|
||||
DmDiscoveryContext context{ pkgName, "121110", aaa };
|
||||
DmDiscoveryContext context{pkgName, "121110", aaa};
|
||||
discoveryMgr_->discoveryContextMap_[pkgName] = context;
|
||||
sleep(1);
|
||||
DmDeviceInfo info;
|
||||
info.deviceId[0] = '\0';
|
||||
info.deviceName[0] = '\0';
|
||||
discoveryMgr_->OnDeviceFound(pkgName, info);
|
||||
std::shared_ptr<IpcNotifyDeviceFoundReq> pReq = std::static_pointer_cast<IpcNotifyDeviceFoundReq>(listener_->ipcServerListener_.req_);
|
||||
std::shared_ptr<IpcNotifyDeviceFoundReq> pReq =
|
||||
std::static_pointer_cast<IpcNotifyDeviceFoundReq>(listener_->ipcServerListener_.req_);
|
||||
int ret1 = discoveryMgr_->discoveryContextMap_.count(pkgName);
|
||||
EXPECT_EQ(ret1, 1);
|
||||
std ::string ret = pReq->GetPkgName();
|
||||
@@ -147,20 +153,21 @@ HWTEST_F(DmDiscoveryManagerTest, OnDeviceFound_001, testing::ext::TestSize.Level
|
||||
|
||||
/**
|
||||
* @tc.name: OnDeviceFound_002
|
||||
* @tc.desc: set pkgName not null and discoveryContextMap_ null and return
|
||||
* @tc.desc: set pkgName not null and discoveryContextMap_ null and return
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000GHSJK
|
||||
*/
|
||||
HWTEST_F(DmDiscoveryManagerTest, OnDeviceFound_002, testing::ext::TestSize.Level0)
|
||||
HWTEST_F(DmDiscoveryManagerTest, OnDeviceFound_002, testing::ext::TestSize.Level0)
|
||||
{
|
||||
std::string pkgName = "com.ohos.helloworld";
|
||||
DmDeviceInfo info;
|
||||
discoveryMgr_->OnDeviceFound(pkgName, info);
|
||||
int ret1 = discoveryMgr_->discoveryContextMap_.count(pkgName);
|
||||
EXPECT_EQ (ret1, 1);
|
||||
std::shared_ptr<IpcNotifyDeviceFoundReq> pReq = std::static_pointer_cast<IpcNotifyDeviceFoundReq>(listener_->ipcServerListener_.req_);
|
||||
EXPECT_EQ(ret1, 1);
|
||||
std::shared_ptr<IpcNotifyDeviceFoundReq> pReq =
|
||||
std::static_pointer_cast<IpcNotifyDeviceFoundReq>(listener_->ipcServerListener_.req_);
|
||||
std ::string ret = pReq->GetPkgName();
|
||||
EXPECT_EQ (ret, pkgName);
|
||||
EXPECT_EQ(ret, pkgName);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -169,15 +176,16 @@ HWTEST_F(DmDiscoveryManagerTest, OnDeviceFound_002, testing::ext::TestSize.Level
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000GHSJK
|
||||
*/
|
||||
HWTEST_F(DmDiscoveryManagerTest, OnDiscoveryFailed_001, testing::ext::TestSize.Level0)
|
||||
HWTEST_F(DmDiscoveryManagerTest, OnDiscoveryFailed_001, testing::ext::TestSize.Level0)
|
||||
{
|
||||
std::string pkgName = "com.ohos.helloworld";
|
||||
int32_t subscribeId = 1;
|
||||
int32_t failedReason = 3;
|
||||
discoveryMgr_->OnDiscoveryFailed(pkgName, subscribeId, failedReason);
|
||||
std::shared_ptr<IpcNotifyDiscoverResultReq> pReq = std::static_pointer_cast<IpcNotifyDiscoverResultReq>(listener_->ipcServerListener_.req_);
|
||||
std::shared_ptr<IpcNotifyDiscoverResultReq> pReq =
|
||||
std::static_pointer_cast<IpcNotifyDiscoverResultReq>(listener_->ipcServerListener_.req_);
|
||||
std ::string ret = pReq->GetPkgName();
|
||||
EXPECT_EQ (ret, pkgName);
|
||||
EXPECT_EQ(ret, pkgName);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -186,16 +194,18 @@ HWTEST_F(DmDiscoveryManagerTest, OnDiscoveryFailed_001, testing::ext::TestSize.L
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000GHSJK
|
||||
*/
|
||||
HWTEST_F(DmDiscoveryManagerTest, OnDiscoveryFailed_002, testing::ext::TestSize.Level0) {
|
||||
HWTEST_F(DmDiscoveryManagerTest, OnDiscoveryFailed_002, testing::ext::TestSize.Level0)
|
||||
{
|
||||
std::string pkgName;
|
||||
int32_t subscribeId = 1;
|
||||
int32_t failedReason = 3;
|
||||
discoveryMgr_->OnDiscoveryFailed(pkgName, subscribeId, failedReason);
|
||||
discoveryMgr_->OnDiscoveryFailed(pkgName, subscribeId, failedReason);
|
||||
int ret1 = discoveryMgr_->discoveryContextMap_.count(pkgName);
|
||||
EXPECT_EQ (ret1, 0);
|
||||
std::shared_ptr<IpcNotifyDiscoverResultReq> pReq = std::static_pointer_cast<IpcNotifyDiscoverResultReq>(listener_->ipcServerListener_.req_);
|
||||
EXPECT_EQ(ret1, 0);
|
||||
std::shared_ptr<IpcNotifyDiscoverResultReq> pReq =
|
||||
std::static_pointer_cast<IpcNotifyDiscoverResultReq>(listener_->ipcServerListener_.req_);
|
||||
std ::string ret = pReq->GetPkgName();
|
||||
EXPECT_EQ (ret, pkgName);
|
||||
EXPECT_EQ(ret, pkgName);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -204,14 +214,15 @@ HWTEST_F(DmDiscoveryManagerTest, OnDiscoveryFailed_002, testing::ext::TestSize.L
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000GHSJK
|
||||
*/
|
||||
HWTEST_F(DmDiscoveryManagerTest, OnDiscoverySuccess_001, testing::ext::TestSize.Level0)
|
||||
HWTEST_F(DmDiscoveryManagerTest, OnDiscoverySuccess_001, testing::ext::TestSize.Level0)
|
||||
{
|
||||
std::string pkgName = "com.ohos.helloworld";
|
||||
int32_t subscribeId = 1;
|
||||
discoveryMgr_->OnDiscoverySuccess(pkgName, subscribeId);
|
||||
std::shared_ptr<IpcNotifyDiscoverResultReq> pReq = std::static_pointer_cast<IpcNotifyDiscoverResultReq>(listener_->ipcServerListener_.req_);
|
||||
std::shared_ptr<IpcNotifyDiscoverResultReq> pReq =
|
||||
std::static_pointer_cast<IpcNotifyDiscoverResultReq>(listener_->ipcServerListener_.req_);
|
||||
std ::string ret = pReq->GetPkgName();
|
||||
EXPECT_EQ (ret, pkgName);
|
||||
EXPECT_EQ(ret, pkgName);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -220,16 +231,17 @@ HWTEST_F(DmDiscoveryManagerTest, OnDiscoverySuccess_001, testing::ext::TestSize.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000GHSJK
|
||||
*/
|
||||
HWTEST_F(DmDiscoveryManagerTest, OnDiscoverySuccess_002, testing::ext::TestSize.Level0)
|
||||
HWTEST_F(DmDiscoveryManagerTest, OnDiscoverySuccess_002, testing::ext::TestSize.Level0)
|
||||
{
|
||||
std::string pkgName ;
|
||||
std::string pkgName;
|
||||
int32_t subscribeId = 1;
|
||||
discoveryMgr_->OnDiscoverySuccess(pkgName, subscribeId);
|
||||
int ret1 = discoveryMgr_->discoveryContextMap_.count(pkgName);
|
||||
EXPECT_EQ (ret1, 1);
|
||||
std::shared_ptr<IpcNotifyDiscoverResultReq> pReq = std::static_pointer_cast<IpcNotifyDiscoverResultReq>(listener_->ipcServerListener_.req_);
|
||||
EXPECT_EQ(ret1, 1);
|
||||
std::shared_ptr<IpcNotifyDiscoverResultReq> pReq =
|
||||
std::static_pointer_cast<IpcNotifyDiscoverResultReq>(listener_->ipcServerListener_.req_);
|
||||
std ::string ret = pReq->GetPkgName();
|
||||
EXPECT_EQ (ret, pkgName);
|
||||
EXPECT_EQ(ret, pkgName);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -238,13 +250,13 @@ HWTEST_F(DmDiscoveryManagerTest, OnDiscoverySuccess_002, testing::ext::TestSize.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000GHSJK
|
||||
*/
|
||||
HWTEST_F(DmDiscoveryManagerTest, HandleDiscoveryTimeout_001, testing::ext::TestSize.Level0)
|
||||
HWTEST_F(DmDiscoveryManagerTest, HandleDiscoveryTimeout_001, testing::ext::TestSize.Level0)
|
||||
{
|
||||
std::string pkgName = "com.ohos.helloworld";
|
||||
discoveryMgr_->HandleDiscoveryTimeout() ;
|
||||
discoveryMgr_->HandleDiscoveryTimeout();
|
||||
int ret = discoveryMgr_->discoveryContextMap_.count(pkgName);
|
||||
EXPECT_EQ (ret, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
EXPECT_EQ(ret, 1);
|
||||
}
|
||||
} // namespace
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
|
||||
Reference in New Issue
Block a user