add UT test.

Signed-off-by: wangwenjun <wangwenjun33@huawei.com>
This commit is contained in:
wangwenjun
2022-05-09 14:56:06 +08:00
parent e2409d9324
commit 099b366a3f
14 changed files with 700 additions and 6 deletions
+2
View File
@@ -81,6 +81,8 @@
"//foundation/distributedhardware/distributedscreen/services/screentransport/test/unittest:screen_transport_test",
"//foundation/distributedhardware/distributedscreen/services/softbusadapter/test/unittest:SoftBusAdapterTest",
"//foundation/distributedhardware/distributedscreen/services/common/test/unittest:service_common_test",
"//foundation/distributedhardware/distributedscreen/services/screenservice/test/unittest:screen_service_test",
"//foundation/distributedhardware/distributedscreen/interfaces/innerkits/native_cpp/test/unittest:screen_interface_test",
"//foundation/distributedhardware/distributedscreen/screenhandler/test/fuzztest:fuzztest",
"//foundation/distributedhardware/distributedscreen/interfaces/innerkits/native_cpp/test/fuzztest:fuzztest",
"//foundation/distributedhardware/distributedscreen/services/softbusadapter/test/fuzztest:fuzztest",
@@ -44,6 +44,7 @@ DScreenSinkHandler::~DScreenSinkHandler()
int32_t DScreenSinkHandler::InitSink(const std::string &params)
{
DHLOGD("InitSink");
std::unique_lock<std::mutex> lock(proxyMutex_);
if (!dScreenSinkProxy_) {
sptr<ISystemAbilityManager> samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
if (!samgr) {
@@ -59,7 +60,6 @@ int32_t DScreenSinkHandler::InitSink(const std::string &params)
}
}
std::unique_lock<std::mutex> lock(proxyMutex_);
auto waitStatus = proxyConVar_.wait_for(lock, std::chrono::milliseconds(SCREEN_LOADSA_TIMEOUT_MS),
[this]() { return dScreenSinkProxy_ != nullptr; });
if (!waitStatus) {
@@ -74,7 +74,7 @@ void DScreenSinkHandler::FinishStartSA(const std::string &params,
const sptr<IRemoteObject> &remoteObject)
{
DHLOGD("FinishStartSA");
std::lock_guard<std::mutex> lock(proxyMutex_);
std::unique_lock<std::mutex> lock(proxyMutex_);
remoteObject->AddDeathRecipient(sinkSvrRecipient_);
dScreenSinkProxy_ = iface_cast<IDScreenSink>(remoteObject);
if ((!dScreenSinkProxy_) || (!dScreenSinkProxy_->AsObject())) {
@@ -31,7 +31,6 @@ void DScreenSourceLoadCallback::OnLoadSystemAbilitySuccess(
DHLOGE("remoteObject is nullptr");
return;
}
DScreenSourceHandler::GetInstance().FinishStartSA(params_, remoteObject);
}
@@ -49,7 +49,7 @@ DScreenSourceHandler::~DScreenSourceHandler()
int32_t DScreenSourceHandler::InitSource(const std::string &params)
{
DHLOGD("InitSource");
std::unique_lock<std::mutex> lock(proxyMutex_);
if (!dScreenSourceProxy_) {
sptr<ISystemAbilityManager> samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
if (!samgr) {
@@ -65,7 +65,6 @@ int32_t DScreenSourceHandler::InitSource(const std::string &params)
}
}
std::unique_lock<std::mutex> lock(proxyMutex_);
auto waitStatus = proxyConVar_.wait_for(lock, std::chrono::milliseconds(SCREEN_LOADSA_TIMEOUT_MS),
[this]() { return (dScreenSourceProxy_ != nullptr); });
if (!waitStatus) {
@@ -80,7 +79,7 @@ void DScreenSourceHandler::FinishStartSA(const std::string &params,
const sptr<IRemoteObject> &remoteObject)
{
DHLOGD("FinishStartSA");
std::lock_guard<std::mutex> lock(proxyMutex_);
std::unique_lock<std::mutex> lock(proxyMutex_);
remoteObject->AddDeathRecipient(sourceSvrRecipient_);
dScreenSourceProxy_ = iface_cast<IDScreenSource>(remoteObject);
if ((!dScreenSourceProxy_) || (!dScreenSourceProxy_->AsObject())) {
@@ -0,0 +1,20 @@
# 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.
group("screen_interface_test") {
testonly = true
deps = [
"screensinktest:screen_sink_test",
"screensourcetest:screen_source_test",
]
}
@@ -0,0 +1,74 @@
# 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.
import("//build/test.gni")
import("//foundation/distributedhardware/distributedscreen/distributedscreen.gni")
module_out_path = "distributed_screen/source_trans_test"
config("module_private_config") {
visibility = [ ":*" ]
include_dirs = [
"//third_party/json/include",
"//foundation/graphic/standard/interfaces/innerkits/surface",
"${fwk_common_path}/utils/include",
"${fwk_utils_path}/include",
]
include_dirs += [
"./include",
"${services_path}/screentransport/test/unittest/screentranstestutils/include",
"${common_path}/include",
"${services_path}/common/databuffer/include",
"${services_path}/common/screen_channel/include",
"${services_path}/common/utils/include",
"${interfaces_path}/innerkits/native_cpp/screen_sink/include",
"${interfaces_path}/innerkits/native_cpp/test/unittest/screensinktest/include",
"//foundation/communication/ipc/interfaces/innerkits/ipc_core/include",
]
}
## UnitTest ScreenSinkTest
ohos_unittest("ScreenSinkTest") {
module_out_path = module_out_path
sources = [
"${interfaces_path}/innerkits/native_cpp/test/unittest/screensinktest/src/dscreen_sink_handler_test.cpp",
]
configs = [ ":module_private_config" ]
deps = [
"//third_party/googletest:gmock",
"//third_party/googletest:gtest_main",
"${fwk_utils_path}:distributedhardwareutils",
"//utils/native/base:utils",
"//foundation/distributedhardware/distributedscreen/interfaces/innerkits/native_cpp/screen_sink:distributed_screen_sink_sdk",
"//foundation/communication/ipc/interfaces/innerkits/ipc_core:ipc_core",
"//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy",
]
external_deps = [
"dsoftbus_standard:softbus_client",
"hiviewdfx_hilog_native:libhilog",
"multimedia_media_standard:media_client",
"ipc:ipc_core",
"safwk:system_ability_fwk",
"samgr_standard:samgr_proxy",
]
}
group("screen_sink_test") {
testonly = true
deps = [ ":ScreenSinkTest" ]
}
@@ -0,0 +1,41 @@
/*
* 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.
*/
#ifndef DSCREEN_SINK_HANDLER_TEST_H
#define DSCREEN_SINK_HANDLER_TEST_H
#include <gtest/gtest.h>
#include <memory>
#include "dscreen_constants.h"
#include "dscreen_errcode.h"
#include "dscreen_log.h"
#include "dscreen_sink_handler.h"
#include "if_system_ability_manager.h"
#include "iservice_registry.h"
namespace OHOS {
namespace DistributedHardware {
class DScreenSinkHandlerTest : public testing::Test {
public:
static void SetUpTestCase(void);
static void TearDownTestCase(void);
void SetUp();
void TearDown();
};
}
}
#endif
@@ -0,0 +1,54 @@
/*
* 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.
*/
#define private public
#include "dscreen_sink_handler_test.h"
#undef private
using namespace testing;
using namespace testing::ext;
namespace OHOS {
namespace DistributedHardware {
void DScreenSinkHandlerTest::SetUpTestCase(void) {}
void DScreenSinkHandlerTest::TearDownTestCase(void) {}
void DScreenSinkHandlerTest::SetUp(void)
{
DScreenSinkHandler::GetInstance().InitSink("DScreenSinkHandlerTest");
}
void DScreenSinkHandlerTest::TearDown(void)
{
DScreenSinkHandler::GetInstance().ReleaseSink();
}
/**
* @tc.name: LocalHardware_001
* @tc.desc: Verify the SubscribeLocalHardware function.
* @tc.type: FUNC
* @tc.require: Issue Number
*/
HWTEST_F(DScreenSinkHandlerTest, LocalHardware_001, TestSize.Level1)
{
const std::string dhId = "DScreenSinkHandlerTest";
const std::string param = "DScreenSinkHandlerTest";
int32_t ret = DScreenSinkHandler::GetInstance().SubscribeLocalHardware(dhId, param);
EXPECT_EQ(DH_SUCCESS, ret);
ret = DScreenSinkHandler::GetInstance().UnsubscribeLocalHardware(dhId);
EXPECT_EQ(DH_SUCCESS, ret);
}
}
}
@@ -0,0 +1,77 @@
# 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.
import("//build/test.gni")
import("//foundation/distributedhardware/distributedscreen/distributedscreen.gni")
module_out_path = "distributed_screen/source_trans_test"
config("module_private_config") {
visibility = [ ":*" ]
include_dirs = [
"//third_party/json/include",
"//foundation/graphic/standard/interfaces/innerkits/surface",
"${fwk_common_path}/utils/include",
"${fwk_utils_path}/include",
]
include_dirs += [
"./include",
"${services_path}/screentransport/test/unittest/screentranstestutils/include",
"${common_path}/include",
"${services_path}/common/databuffer/include",
"${services_path}/common/screen_channel/include",
"${services_path}/common/utils/include",
"${interfaces_path}/innerkits/native_cpp/screen_source/include",
"${interfaces_path}/innerkits/native_cpp/screen_source/include/callback",
"${interfaces_path}/innerkits/native_cpp/test/unittest/screensourcetest/include",
"${interfaces_path}/innerkits/native_cpp/test/unittest/screensourcetest/include/callback",
"//foundation/communication/ipc/interfaces/innerkits/ipc_core/include",
]
}
## UnitTest ScreenSourceTest
ohos_unittest("ScreenSourceTest") {
module_out_path = module_out_path
sources = [
"${interfaces_path}/innerkits/native_cpp/test/unittest/screensourcetest/src/dscreen_source_handler_test.cpp",
"${interfaces_path}/innerkits/native_cpp/test/unittest/screensourcetest/src/callback/dscreen_source_callback_test.cpp",
]
configs = [ ":module_private_config" ]
deps = [
"//third_party/googletest:gmock",
"//third_party/googletest:gtest_main",
"${fwk_utils_path}:distributedhardwareutils",
"//utils/native/base:utils",
"//foundation/distributedhardware/distributedscreen/interfaces/innerkits/native_cpp/screen_source:distributed_screen_source_sdk",
"//foundation/communication/ipc/interfaces/innerkits/ipc_core:ipc_core",
"//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy",
]
external_deps = [
"dsoftbus_standard:softbus_client",
"hiviewdfx_hilog_native:libhilog",
"multimedia_media_standard:media_client",
"ipc:ipc_core",
"safwk:system_ability_fwk",
"samgr_standard:samgr_proxy",
]
}
group("screen_source_test") {
testonly = true
deps = [ ":ScreenSourceTest" ]
}
@@ -0,0 +1,39 @@
/*
* 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.
*/
#ifndef OHOS_DSCREEN_SOURCE_CALLBACK_TEST_H
#define OHOS_DSCREEN_SOURCE_CALLBACK_TEST_H
#include <gtest/gtest.h>
#include "dscreen_errcode.h"
#include "dscreen_source_callback.h"
#include "dscreen_source_common.h"
namespace OHOS {
namespace DistributedHardware {
class DScreenSourceCallbackTest : public testing::Test {
public:
static void SetUpTestCase(void);
static void TearDownTestCase(void);
void SetUp();
void TearDown();
sptr<DScreenSourceCallback> dScreenSourceCallback_ = nullptr;
};
}
}
#endif
@@ -0,0 +1,93 @@
/*
* 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.
*/
#ifndef OHOS_DSCREEN_COMMON_H
#define OHOS_DSCREEN_COMMON_H
#include <string>
#include "dscreen_source_callback.h"
#include "dscreen_source_callback_stub.h"
#include "dscreen_source_handler.h"
#include "dscreen_source_proxy.h"
#include "idscreen_source_callback.h"
namespace OHOS {
namespace DistributedHardware {
class DScreenSourceCallbackStubVTest : public DScreenSourceCallbackStub {
public:
~DScreenSourceCallbackStubVTest() {}
int32_t OnNotifyRegResultInner(MessageParcel &data, MessageParcel &reply,
MessageOption &option)
{
return 0;
}
int32_t OnNotifyUnregResultInner(MessageParcel &data, MessageParcel &reply,
MessageOption &option)
{
return 0;
}
};
class IDScreenSourceCallbackTest : public IDScreenSourceCallback {
public:
~IDScreenSourceCallbackTest() {}
sptr<IRemoteObject> AsObject()
{
return nullptr;
}
int32_t OnNotifyRegResult(const std::string &devId, const std::string &dhId,
const std::string &reqId, int32_t status, const std::string &data)
{
return 0;
}
int32_t OnNotifyUnregResult(const std::string &devId, const std::string &dhId,
const std::string &reqId, int32_t status, const std::string &data)
{
return 0;
}
};
class RegisterCallbackTest : public RegisterCallback {
public:
RegisterCallbackTest() = default;
virtual ~RegisterCallbackTest() = default;
int32_t OnRegisterResult(const std::string &uuid, const std::string &dhId, int32_t status,
const std::string &data)
{
return 0;
}
};
class UnregisterCallbackTest : public UnregisterCallback {
public:
UnregisterCallbackTest() = default;
virtual ~UnregisterCallbackTest() = default;
int32_t OnUnregisterResult(const std::string &uuid, const std::string &dhId, int32_t status,
const std::string &data)
{
return 0;
}
};
}
}
#endif
@@ -0,0 +1,38 @@
/*
* 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.
*/
#ifndef OHOS_DSCREEN_SOURCE_HANDLER_TEST_H
#define OHOS_DSCREEN_SOURCE_HANDLER_TEST_H
#include <gtest/gtest.h>
#include <memory>
#include "dscreen_errcode.h"
#include "dscreen_source_common.h"
#include "dscreen_source_handler.h"
namespace OHOS {
namespace DistributedHardware {
class DScreenSourceHandlerTest : public testing::Test {
public:
static void SetUpTestCase(void);
static void TearDownTestCase(void);
void SetUp();
void TearDown();
};
}
}
#endif
@@ -0,0 +1,182 @@
/*
* 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.
*/
#define private public
#include "dscreen_source_callback_test.h"
#undef private
using namespace testing;
using namespace testing::ext;
namespace OHOS {
namespace DistributedHardware {
void DScreenSourceCallbackTest::SetUpTestCase(void) {}
void DScreenSourceCallbackTest::TearDownTestCase(void) {}
void DScreenSourceCallbackTest::SetUp(void)
{
dScreenSourceCallback_ = new DScreenSourceCallback();
}
void DScreenSourceCallbackTest::TearDown(void)
{
dScreenSourceCallback_ = nullptr;
}
/**
* @tc.name: OnNotifyRegResult_001
* @tc.desc: Verify the OnNotifyRegResult function.
* @tc.type: FUNC
* @tc.require: Issue Number
*/
HWTEST_F(DScreenSourceCallbackTest, OnNotifyRegResult_001, TestSize.Level1)
{
const std::string devId = "devId";
const std::string dhId = "dhId";
const std::string reqId = "reqIdReg";
int32_t status = 0;
const std::string data = "data";
std::shared_ptr<RegisterCallback> callback = std::make_shared<RegisterCallbackTest>();
dScreenSourceCallback_->PushRegRegisterCallback(reqId, callback);
int32_t ret = dScreenSourceCallback_->OnNotifyRegResult(devId, dhId, reqId, status, data);
dScreenSourceCallback_->PopRegRegisterCallback(reqId);
EXPECT_EQ(DH_SUCCESS, ret);
}
/**
* @tc.name: OnNotifyRegResult_002
* @tc.desc: Verify the OnNotifyRegResult function.
* @tc.type: FUNC
* @tc.require: Issue Number
*/
HWTEST_F(DScreenSourceCallbackTest, OnNotifyRegResult_002, TestSize.Level1)
{
const std::string devId = "devId";
const std::string dhId = "dhId";
const std::string reqId = "reqId";
int32_t status = 0;
const std::string data = "data";
int32_t ret = dScreenSourceCallback_->OnNotifyRegResult(devId, dhId, reqId, status, data);
EXPECT_EQ(ERR_DH_SCREEN_SA_REGISTERCALLBACK_NOT_FOUND, ret);
}
/**
* @tc.name: OnNotifyUnregResult_001
* @tc.desc: Verify the OnNotifyUnregResult function.
* @tc.type: FUNC
* @tc.require: Issue Number
*/
HWTEST_F(DScreenSourceCallbackTest, OnNotifyUnregResult_001, TestSize.Level1)
{
const std::string devId = "devId";
const std::string dhId = "dhId";
const std::string reqId = "reqIdUnreg";
int32_t status = 0;
const std::string data = "data";
std::shared_ptr<UnregisterCallback> callback = std::make_shared<UnregisterCallbackTest>();
dScreenSourceCallback_->PushUnregisterCallback(reqId, callback);
int32_t ret = dScreenSourceCallback_->OnNotifyUnregResult(devId, dhId, reqId, status, data);
dScreenSourceCallback_->PopUnregisterCallback(reqId);
EXPECT_EQ(DH_SUCCESS, ret);
}
/**
* @tc.name: OnNotifyUnregResult_002
* @tc.desc: Verify the OnNotifyUnregResult function.
* @tc.type: FUNC
* @tc.require: Issue Number
*/
HWTEST_F(DScreenSourceCallbackTest, OnNotifyUnregResult_002, TestSize.Level1)
{
const std::string devId = "devId";
const std::string dhId = "dhId";
const std::string reqId = "reqId";
int32_t status = 0;
const std::string data = "data";
int32_t ret = dScreenSourceCallback_->OnNotifyUnregResult(devId, dhId, reqId, status, data);
EXPECT_EQ(ERR_DH_SCREEN_SA_UNREGISTERCALLBACK_NOT_FOUND, ret);
}
/**
* @tc.name: PushRegRegisterCallback_001
* @tc.desc: Verify the PushRegRegisterCallback function.
* @tc.type: FUNC
* @tc.require: Issue Number
*/
HWTEST_F(DScreenSourceCallbackTest, PushRegRegisterCallback_001, TestSize.Level1)
{
const std::string reqId = "reqIdReg";
std::shared_ptr<RegisterCallback> callback = std::make_shared<RegisterCallbackTest>();
int32_t sizeFront = dScreenSourceCallback_->registerCallbackMap_.size();
dScreenSourceCallback_->PushRegRegisterCallback(reqId, callback);
int32_t sizeEnd = dScreenSourceCallback_->registerCallbackMap_.size();
dScreenSourceCallback_->PopRegRegisterCallback(reqId);
EXPECT_GT(sizeEnd, sizeFront);
}
/**
* @tc.name: PopRegRegisterCallback_001
* @tc.desc: Verify the PopRegRegisterCallback function.
* @tc.type: FUNC
* @tc.require: Issue Number
*/
HWTEST_F(DScreenSourceCallbackTest, PopRegRegisterCallback_001, TestSize.Level1)
{
const std::string reqId = "reqId";
std::shared_ptr<RegisterCallback> callback = std::make_shared<RegisterCallbackTest>();
dScreenSourceCallback_->PushRegRegisterCallback(reqId, callback);
int32_t sizeFront = dScreenSourceCallback_->registerCallbackMap_.size();
dScreenSourceCallback_->PopRegRegisterCallback(reqId);
int32_t sizeEnd = dScreenSourceCallback_->registerCallbackMap_.size();
EXPECT_GT(sizeFront, sizeEnd);
}
/**
* @tc.name: PushRegRegisterCallback_001
* @tc.desc: Verify the PushRegRegisterCallback function.
* @tc.type: FUNC
* @tc.require: Issue Number
*/
HWTEST_F(DScreenSourceCallbackTest, PushUnregRegisterCallback_001, TestSize.Level1)
{
const std::string reqId = "reqIdUnreg";
std::shared_ptr<UnregisterCallback> callback = std::make_shared<UnregisterCallbackTest>();
int32_t sizeFront = dScreenSourceCallback_->unregisterCallbackMap_.size();
dScreenSourceCallback_->PushUnregisterCallback(reqId, callback);
int32_t sizeEnd = dScreenSourceCallback_->unregisterCallbackMap_.size();
dScreenSourceCallback_->PopUnregisterCallback(reqId);
EXPECT_GT(sizeEnd, sizeFront);
}
/**
* @tc.name: PopRegRegisterCallback_001
* @tc.desc: Verify the PopRegRegisterCallback function.
* @tc.type: FUNC
* @tc.require: Issue Number
*/
HWTEST_F(DScreenSourceCallbackTest, PopUnregRegisterCallback_001, TestSize.Level1)
{
const std::string reqId = "reqId";
std::shared_ptr<UnregisterCallback> callback = std::make_shared<UnregisterCallbackTest>();
dScreenSourceCallback_->PushUnregisterCallback(reqId, callback);
int32_t sizeFront = dScreenSourceCallback_->unregisterCallbackMap_.size();
dScreenSourceCallback_->PopUnregisterCallback(reqId);
int32_t sizeEnd = dScreenSourceCallback_->unregisterCallbackMap_.size();
EXPECT_GT(sizeFront, sizeEnd);
}
}
}
@@ -0,0 +1,76 @@
/*
* 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.
*/
#define private public
#include "dscreen_source_handler_test.h"
#undef private
using namespace testing;
using namespace testing::ext;
namespace OHOS {
namespace DistributedHardware {
void DScreenSourceHandlerTest::SetUpTestCase(void)
{
DScreenSourceHandler::GetInstance().InitSource("DScreenSourceHandlerTest");
}
void DScreenSourceHandlerTest::TearDownTestCase(void)
{
DScreenSourceHandler::GetInstance().ReleaseSource();
}
void DScreenSourceHandlerTest::SetUp(void) {}
void DScreenSourceHandlerTest::TearDown(void) {}
/**
* @tc.name: RegisterDistributedHardware_001
* @tc.desc: Verify the RegisterDistributedHardware function.
* @tc.type: FUNC
* @tc.require: Issue Number
*/
HWTEST_F(DScreenSourceHandlerTest, RegisterDistributedHardware_001, TestSize.Level1)
{
const std::string devId = "devId";
const std::string dhId = "dhId";
EnableParam param;
param.version = "1";
param.attrs = "attrs";
std::shared_ptr<RegisterCallback> callback = std::make_shared<RegisterCallbackTest>();
int32_t ret = DScreenSourceHandler::GetInstance().RegisterDistributedHardware(devId, dhId, param, callback);
EXPECT_EQ(DH_SUCCESS, ret);
}
/**
* @tc.name: RegisterDistributedHardware_002
* @tc.desc: Verify the RegisterDistributedHardware function.
* @tc.type: FUNC
* @tc.require: Issue Number
*/
HWTEST_F(DScreenSourceHandlerTest, RegisterDistributedHardware_002, TestSize.Level1)
{
const std::string devId = "devId";
const std::string dhId = "dhId";
EnableParam param;
param.version = "1";
param.attrs = "attrs";
std::shared_ptr<RegisterCallback> callback = std::make_shared<RegisterCallbackTest>();
DScreenSourceHandler::GetInstance().dScreenSourceCallback_ = nullptr;
int32_t ret = DScreenSourceHandler::GetInstance().RegisterDistributedHardware(devId, dhId, param, callback);
EXPECT_EQ(ERR_DH_SCREEN_SA_SOURCEPCALLBACK_NOT_INIT, ret);
}
}
}