diff --git a/bundle.json b/bundle.json index b3f9f233935caac12e1bbbcb5bd7492cf750bc1b..07590c28eb2d06d83be2428f0bc387077c461d02 100644 --- a/bundle.json +++ b/bundle.json @@ -50,8 +50,6 @@ "//foundation/distributedhardware/distributedscreen/screenhandler:distributed_screen_handler", "//foundation/distributedhardware/distributedscreen/services/screentransport/screensinktrans:distributed_screen_sinktrans", "//foundation/distributedhardware/distributedscreen/services/screentransport/screensourcetrans:distributed_screen_sourcetrans", - "//foundation/distributedhardware/distributedscreen/services/screenservice/sinkservice:distributed_screen_sink", - "//foundation/distributedhardware/distributedscreen/services/screenservice/sourceservice:distributed_screen_source", "//foundation/distributedhardware/distributedscreen/sa_profile:dscreen_sa_profile", "//foundation/distributedhardware/distributedscreen/sa_profile:dscreen.cfg" ], @@ -81,6 +79,7 @@ "//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/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", diff --git a/interfaces/innerkits/native_cpp/screen_sink/src/dscreen_sink_handler.cpp b/interfaces/innerkits/native_cpp/screen_sink/src/dscreen_sink_handler.cpp index 40390679c01d95c244769b5c2691e7d69b57a500..440e5537ca7b5778a2a58abdeb7c43f26eeb06fa 100644 --- a/interfaces/innerkits/native_cpp/screen_sink/src/dscreen_sink_handler.cpp +++ b/interfaces/innerkits/native_cpp/screen_sink/src/dscreen_sink_handler.cpp @@ -44,6 +44,7 @@ DScreenSinkHandler::~DScreenSinkHandler() int32_t DScreenSinkHandler::InitSink(const std::string ¶ms) { DHLOGD("InitSink"); + std::unique_lock lock(proxyMutex_); if (!dScreenSinkProxy_) { sptr samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); if (!samgr) { @@ -59,7 +60,6 @@ int32_t DScreenSinkHandler::InitSink(const std::string ¶ms) } } - std::unique_lock 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 ¶ms, const sptr &remoteObject) { DHLOGD("FinishStartSA"); - std::lock_guard lock(proxyMutex_); + std::unique_lock lock(proxyMutex_); remoteObject->AddDeathRecipient(sinkSvrRecipient_); dScreenSinkProxy_ = iface_cast(remoteObject); if ((!dScreenSinkProxy_) || (!dScreenSinkProxy_->AsObject())) { diff --git a/interfaces/innerkits/native_cpp/screen_source/src/callback/dscreen_source_load_callback.cpp b/interfaces/innerkits/native_cpp/screen_source/src/callback/dscreen_source_load_callback.cpp index 9c7cdcb45e4a004164424831e5361fb8668efcb2..bd7126119420458da48e64b2daf4ee7fa7800b3f 100644 --- a/interfaces/innerkits/native_cpp/screen_source/src/callback/dscreen_source_load_callback.cpp +++ b/interfaces/innerkits/native_cpp/screen_source/src/callback/dscreen_source_load_callback.cpp @@ -31,7 +31,6 @@ void DScreenSourceLoadCallback::OnLoadSystemAbilitySuccess( DHLOGE("remoteObject is nullptr"); return; } - DScreenSourceHandler::GetInstance().FinishStartSA(params_, remoteObject); } diff --git a/interfaces/innerkits/native_cpp/screen_source/src/dscreen_source_handler.cpp b/interfaces/innerkits/native_cpp/screen_source/src/dscreen_source_handler.cpp index a45b0502bf71df9f31998c0ad0016f90c54866ff..806d8e2f7b06d5a4a9b12b4e92740337bd18cfc0 100644 --- a/interfaces/innerkits/native_cpp/screen_source/src/dscreen_source_handler.cpp +++ b/interfaces/innerkits/native_cpp/screen_source/src/dscreen_source_handler.cpp @@ -49,7 +49,7 @@ DScreenSourceHandler::~DScreenSourceHandler() int32_t DScreenSourceHandler::InitSource(const std::string ¶ms) { DHLOGD("InitSource"); - + std::unique_lock lock(proxyMutex_); if (!dScreenSourceProxy_) { sptr samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); if (!samgr) { @@ -65,7 +65,6 @@ int32_t DScreenSourceHandler::InitSource(const std::string ¶ms) } } - std::unique_lock 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 ¶ms, const sptr &remoteObject) { DHLOGD("FinishStartSA"); - std::lock_guard lock(proxyMutex_); + std::unique_lock lock(proxyMutex_); remoteObject->AddDeathRecipient(sourceSvrRecipient_); dScreenSourceProxy_ = iface_cast(remoteObject); if ((!dScreenSourceProxy_) || (!dScreenSourceProxy_->AsObject())) { diff --git a/interfaces/innerkits/native_cpp/test/unittest/BUILD.gn b/interfaces/innerkits/native_cpp/test/unittest/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..6cc313b807b19832a17e19a63c1dbdfd447dc620 --- /dev/null +++ b/interfaces/innerkits/native_cpp/test/unittest/BUILD.gn @@ -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", + ] +} diff --git a/interfaces/innerkits/native_cpp/test/unittest/screensinktest/BUILD.gn b/interfaces/innerkits/native_cpp/test/unittest/screensinktest/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..7a36a109e75dca6b8104cdd6a4ae71b3948d7ae4 --- /dev/null +++ b/interfaces/innerkits/native_cpp/test/unittest/screensinktest/BUILD.gn @@ -0,0 +1,73 @@ +# 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 = [ + "${fwk_utils_path}:distributedhardwareutils", + "//foundation/communication/ipc/interfaces/innerkits/ipc_core:ipc_core", + "//foundation/distributedhardware/distributedscreen/interfaces/innerkits/native_cpp/screen_sink:distributed_screen_sink_sdk", + "//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", + "//third_party/googletest:gmock", + "//third_party/googletest:gtest_main", + "//utils/native/base:utils", + ] + + external_deps = [ + "dsoftbus_standard:softbus_client", + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_core", + "multimedia_media_standard:media_client", + "safwk:system_ability_fwk", + "samgr_standard:samgr_proxy", + ] +} + +group("screen_sink_test") { + testonly = true + deps = [ ":ScreenSinkTest" ] +} diff --git a/interfaces/innerkits/native_cpp/test/unittest/screensinktest/include/dscreen_sink_handler_test.h b/interfaces/innerkits/native_cpp/test/unittest/screensinktest/include/dscreen_sink_handler_test.h new file mode 100644 index 0000000000000000000000000000000000000000..4b58a49538a2ffeccda196b3189589164adf3b82 --- /dev/null +++ b/interfaces/innerkits/native_cpp/test/unittest/screensinktest/include/dscreen_sink_handler_test.h @@ -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 +#include + +#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 \ No newline at end of file diff --git a/interfaces/innerkits/native_cpp/test/unittest/screensinktest/src/dscreen_sink_handler_test.cpp b/interfaces/innerkits/native_cpp/test/unittest/screensinktest/src/dscreen_sink_handler_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..7fa8be8788f22923c77257c6ce9d87641d44a20d --- /dev/null +++ b/interfaces/innerkits/native_cpp/test/unittest/screensinktest/src/dscreen_sink_handler_test.cpp @@ -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); +} +} +} \ No newline at end of file diff --git a/interfaces/innerkits/native_cpp/test/unittest/screensourcetest/BUILD.gn b/interfaces/innerkits/native_cpp/test/unittest/screensourcetest/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..540b1a8e1f731959c36e11855ca7f601769498b2 --- /dev/null +++ b/interfaces/innerkits/native_cpp/test/unittest/screensourcetest/BUILD.gn @@ -0,0 +1,78 @@ +# 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/callback/dscreen_source_callback_test.cpp", + "${interfaces_path}/innerkits/native_cpp/test/unittest/screensourcetest/src/dscreen_source_handler_test.cpp", + ] + + configs = [ ":module_private_config" ] + + deps = [ + "${fwk_utils_path}:distributedhardwareutils", + "//foundation/communication/ipc/interfaces/innerkits/ipc_core:ipc_core", + "//foundation/distributedhardware/distributedscreen/interfaces/innerkits/native_cpp/screen_source:distributed_screen_source_sdk", + "//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", + "//third_party/googletest:gmock", + "//third_party/googletest:gtest_main", + "//utils/native/base:utils", + ] + + external_deps = [ + "dsoftbus_standard:softbus_client", + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_core", + "multimedia_media_standard:media_client", + "safwk:system_ability_fwk", + "samgr_standard:samgr_proxy", + ] +} + +group("screen_source_test") { + testonly = true + deps = [ ":ScreenSourceTest" ] +} diff --git a/interfaces/innerkits/native_cpp/test/unittest/screensourcetest/include/callback/dscreen_source_callback_test.h b/interfaces/innerkits/native_cpp/test/unittest/screensourcetest/include/callback/dscreen_source_callback_test.h new file mode 100644 index 0000000000000000000000000000000000000000..24f1e2d662db883a8ba27ca5259cf29d0fc0043e --- /dev/null +++ b/interfaces/innerkits/native_cpp/test/unittest/screensourcetest/include/callback/dscreen_source_callback_test.h @@ -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 + +#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_ = nullptr; +}; +} +} + +#endif \ No newline at end of file diff --git a/interfaces/innerkits/native_cpp/test/unittest/screensourcetest/include/dscreen_source_common.h b/interfaces/innerkits/native_cpp/test/unittest/screensourcetest/include/dscreen_source_common.h new file mode 100644 index 0000000000000000000000000000000000000000..823afec67d06d9127eb18201f74842f6ebd5ea6a --- /dev/null +++ b/interfaces/innerkits/native_cpp/test/unittest/screensourcetest/include/dscreen_source_common.h @@ -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 + +#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 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 \ No newline at end of file diff --git a/interfaces/innerkits/native_cpp/test/unittest/screensourcetest/include/dscreen_source_handler_test.h b/interfaces/innerkits/native_cpp/test/unittest/screensourcetest/include/dscreen_source_handler_test.h new file mode 100644 index 0000000000000000000000000000000000000000..8159566fbd6d4a44002845eb57c0e9002547b07f --- /dev/null +++ b/interfaces/innerkits/native_cpp/test/unittest/screensourcetest/include/dscreen_source_handler_test.h @@ -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 +#include + +#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 \ No newline at end of file diff --git a/interfaces/innerkits/native_cpp/test/unittest/screensourcetest/src/callback/dscreen_source_callback_test.cpp b/interfaces/innerkits/native_cpp/test/unittest/screensourcetest/src/callback/dscreen_source_callback_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..42af7b80786cf5dfd6be3061f4d1180a72bef9df --- /dev/null +++ b/interfaces/innerkits/native_cpp/test/unittest/screensourcetest/src/callback/dscreen_source_callback_test.cpp @@ -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 callback = std::make_shared(); + 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 callback = std::make_shared(); + 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 callback = std::make_shared(); + 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 callback = std::make_shared(); + 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 callback = std::make_shared(); + 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 callback = std::make_shared(); + dScreenSourceCallback_->PushUnregisterCallback(reqId, callback); + int32_t sizeFront = dScreenSourceCallback_->unregisterCallbackMap_.size(); + dScreenSourceCallback_->PopUnregisterCallback(reqId); + int32_t sizeEnd = dScreenSourceCallback_->unregisterCallbackMap_.size(); + EXPECT_GT(sizeFront, sizeEnd); +} +} +} \ No newline at end of file diff --git a/interfaces/innerkits/native_cpp/test/unittest/screensourcetest/src/dscreen_source_handler_test.cpp b/interfaces/innerkits/native_cpp/test/unittest/screensourcetest/src/dscreen_source_handler_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..66a4c38a1c4c00129a089c6f7c23a296e22f8ae1 --- /dev/null +++ b/interfaces/innerkits/native_cpp/test/unittest/screensourcetest/src/dscreen_source_handler_test.cpp @@ -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 callback = std::make_shared(); + 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 callback = std::make_shared(); + DScreenSourceHandler::GetInstance().dScreenSourceCallback_ = nullptr; + int32_t ret = DScreenSourceHandler::GetInstance().RegisterDistributedHardware(devId, dhId, param, callback); + EXPECT_EQ(ERR_DH_SCREEN_SA_SOURCEPCALLBACK_NOT_INIT, ret); +} +} +} \ No newline at end of file