diff --git a/frameworks/native/ability/native/continuation/remote_register_service/connect_callback_proxy.cpp b/frameworks/native/ability/native/continuation/remote_register_service/connect_callback_proxy.cpp index ea403af0acca8db7ab13a8dc9461d5463a4a3809..3f70e3bdc18dacf7b777bdf243226828b76a7b62 100644 --- a/frameworks/native/ability/native/continuation/remote_register_service/connect_callback_proxy.cpp +++ b/frameworks/native/ability/native/continuation/remote_register_service/connect_callback_proxy.cpp @@ -31,7 +31,7 @@ void ConnectCallbackProxy::Connect(const string &deviceId, const string &deviceT HILOG_INFO("%{public}s called begin", __func__); MessageParcel data; if (!data.WriteInterfaceToken(IConnectCallback::GetDescriptor()) || !data.WriteString(deviceId) || - data.WriteString(deviceType)) { + !data.WriteString(deviceType)) { HILOG_ERROR("%{public}s params is wrong", __func__); return; } diff --git a/interfaces/kits/native/ability/native/continuation/remote_register_service/connect_callback_proxy.h b/interfaces/kits/native/ability/native/continuation/remote_register_service/connect_callback_proxy.h index 3b40f9f150a92a611cecffacb803eb8745f8f8a6..9a5da62aa8bc1b66ac56be35263d2cf393d41dbc 100644 --- a/interfaces/kits/native/ability/native/continuation/remote_register_service/connect_callback_proxy.h +++ b/interfaces/kits/native/ability/native/continuation/remote_register_service/connect_callback_proxy.h @@ -28,6 +28,8 @@ namespace AppExecFwk { */ class ConnectCallbackProxy : public IRemoteProxy { public: + ConnectCallbackProxy(const sptr &object) : IRemoteProxy(object) {}; + virtual ~ConnectCallbackProxy() = default; /** * @brief Remote device sends connection request. * @param deviceId indicators id of connection device. diff --git a/test/unittest/continuation_test/BUILD.gn b/test/unittest/continuation_test/BUILD.gn index 4cc5c1b1839bca37246a48f917b321d54a16ffd4..23e644265f14b9a2b89293b8121fc10e19d23383 100644 --- a/test/unittest/continuation_test/BUILD.gn +++ b/test/unittest/continuation_test/BUILD.gn @@ -17,6 +17,10 @@ import("//foundation/ability/ability_runtime/ability_runtime.gni") group("unittest") { testonly = true deps = [ + "remote_register_service_test/connect_callback_proxy_test:unittest", + "remote_register_service_test/connect_callback_stub_test:unittest", + "remote_register_service_test/continuation_connector_test:unittest", + "remote_register_service_test/continuation_register_manager_test:unittest", "remote_register_service_test/remote_register_service_proxy_test:unittest", "remote_register_service_test/remote_register_service_stub_test:unittest", ] diff --git a/test/unittest/continuation_test/remote_register_service_test/connect_callback_proxy_test/BUILD.gn b/test/unittest/continuation_test/remote_register_service_test/connect_callback_proxy_test/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..4618db1a32b9af5edf298ea96ffa6fa40f18dfb5 --- /dev/null +++ b/test/unittest/continuation_test/remote_register_service_test/connect_callback_proxy_test/BUILD.gn @@ -0,0 +1,63 @@ +# 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/ability/ability_runtime/ability_runtime.gni") + +module_output_path = "ability_runtime/abilitymgr" + +config("coverage_flags") { + if (ability_runtime_feature_coverage) { + cflags = [ "--coverage" ] + ldflags = [ "--coverage" ] + } +} + +ohos_unittest("connect_callback_proxy_test") { + module_out_path = module_output_path + + include_dirs = [ + "${ability_runtime_path}/interfaces/kits/native/ability/native/continuation/remote_register_service", + "${ability_runtime_innerkits_path}/ability_manager/include/continuation", + "${ability_runtime_services_path}/common/include", + ] + + sources = [ "connect_callback_proxy_test.cpp" ] + + configs = [ ":coverage_flags" ] + cflags = [] + if (target_cpu == "arm") { + cflags += [ "-DBINDER_IPC_32BIT" ] + } + deps = [ + "//foundation/ability/ability_runtime/frameworks/native/ability/native:continuation_ipc", + "//third_party/googletest:gmock_main", + "//third_party/googletest:gtest_main", + ] + + external_deps = [ + "ability_base:want", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_core", + ] + + if (background_task_mgr_continuous_task_enable) { + external_deps += [ "background_task_mgr:bgtaskmgr_innerkits" ] + } +} + +group("unittest") { + testonly = true + deps = [ ":connect_callback_proxy_test" ] +} diff --git a/test/unittest/continuation_test/remote_register_service_test/connect_callback_proxy_test/connect_callback_proxy_test.cpp b/test/unittest/continuation_test/remote_register_service_test/connect_callback_proxy_test/connect_callback_proxy_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ada9b2f26229d08ed5ca8095f9cd980438884ae5 --- /dev/null +++ b/test/unittest/continuation_test/remote_register_service_test/connect_callback_proxy_test/connect_callback_proxy_test.cpp @@ -0,0 +1,160 @@ +/* + * 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 +#include +#include + +#define private public +#define protected public +#include "message_parcel.h" +#include "connect_callback_proxy.h" +#include "connect_callback_stub.h" +#undef private +#undef protected + +using namespace testing::ext; +using namespace testing; +using namespace std::chrono; + +namespace OHOS { +namespace AppExecFwk { +class ConnectCallbackProxyTest : public testing::Test { +public: + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp(); + void TearDown(); +}; + +void ConnectCallbackProxyTest::SetUpTestCase(void) +{} + +void ConnectCallbackProxyTest::TearDownTestCase(void) +{} + +void ConnectCallbackProxyTest::SetUp(void) +{} + +void ConnectCallbackProxyTest::TearDown(void) +{} + +class MockConnectCallback : public ConnectCallbackStub { +public: + MockConnectCallback() {}; + ~MockConnectCallback() {}; + + int SendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override + { + GTEST_LOG_(INFO) << "MockRegisterService::SendRequest called. return value " << returnCode_; + reply.WriteInt32(ERR_NONE); + flag = true; + return returnCode_; + } + + void Connect(const string &deviceId, const string &deviceType) override + { + GTEST_LOG_(INFO) << "MockRegisterService::Connect called."; + return; + } + + void Disconnect(const string &deviceId) override + { + GTEST_LOG_(INFO) << "MockRegisterService::Connect called."; + return; + } + + int32_t returnCode_ = ERR_NONE; + bool flag = false; +}; + +/** + * @tc.number: AppExecFwk_ConnectCallbackProxy_Connect_001 + * @tc.name: Connect + * @tc.desc: Pass in normal parameters, and the test program executes correctly without abnormal exit + */ +HWTEST_F(ConnectCallbackProxyTest, AppExecFwk_ConnectCallbackProxy_Connect_001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AppExecFwk_ConnectCallbackProxy_Connect_001 start."; + sptr object = new (std::nothrow) MockConnectCallback(); + sptr testProxy = new (std::nothrow) ConnectCallbackProxy(object); + EXPECT_TRUE(testProxy != nullptr); + EXPECT_TRUE(testProxy->remoteObject_ != nullptr); + std::string deviceId = "7001005458323933328a592135733900"; + std::string deviceType = "rk3568"; + EXPECT_FALSE(object->flag); + testProxy->Connect(deviceId, deviceType); + EXPECT_TRUE(object->flag); + GTEST_LOG_(INFO) << "AppExecFwk_ConnectCallbackProxy_Connect_001 end."; +} + +/** + * @tc.number: AppExecFwk_ConnectCallbackProxy_Disconnect_001 + * @tc.name: Disconnect + * @tc.desc: Pass in normal parameters, and the test program executes correctly without abnormal exit + */ +HWTEST_F(ConnectCallbackProxyTest, AppExecFwk_ConnectCallbackProxy_Disconnect_001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AppExecFwk_ConnectCallbackProxy_Disconnect_001 start."; + sptr object = new (std::nothrow) MockConnectCallback(); + sptr testProxy = new (std::nothrow) ConnectCallbackProxy(object); + EXPECT_TRUE(testProxy != nullptr); + EXPECT_TRUE(testProxy->remoteObject_ != nullptr); + std::string deviceId = "7001005458323933328a592135733900"; + EXPECT_FALSE(object->flag); + testProxy->Disconnect(deviceId); + EXPECT_TRUE(object->flag); + GTEST_LOG_(INFO) << "AppExecFwk_ConnectCallbackProxy_Disconnect_001 end."; +} + +/** + * @tc.number: AppExecFwk_ConnectCallbackProxy_RemoteRequest_001 + * @tc.name: RemoteRequest + * @tc.desc: Pass in normal parameters, and the test program executes correctly without abnormal exit + */ +HWTEST_F(ConnectCallbackProxyTest, AppExecFwk_ConnectCallbackProxy_RemoteRequest_001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AppExecFwk_ConnectCallbackProxy_RemoteRequest_001 start."; + sptr object = new (std::nothrow) MockConnectCallback(); + sptr testProxy = new (std::nothrow) ConnectCallbackProxy(object); + EXPECT_TRUE(testProxy != nullptr); + EXPECT_TRUE(testProxy->remoteObject_ != nullptr); + int commandDisconnect = 1; + MessageParcel data = {}; + EXPECT_FALSE(object->flag); + testProxy->RemoteRequest(data, commandDisconnect); + EXPECT_TRUE(object->flag); + GTEST_LOG_(INFO) << "AppExecFwk_ConnectCallbackProxy_RemoteRequest_001 end."; +} + +/** + * @tc.number: AppExecFwk_ConnectCallbackProxy_RemoteRequest_002 + * @tc.name: RemoteRequest + * @tc.desc: The incoming Remote() is nullptr, and the test program executes as expected without exiting abnormally + */ +HWTEST_F(ConnectCallbackProxyTest, AppExecFwk_ConnectCallbackProxy_RemoteRequest_002, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AppExecFwk_ConnectCallbackProxy_RemoteRequest_002 start."; + sptr object = nullptr; + sptr testProxy = new (std::nothrow) ConnectCallbackProxy(object); + EXPECT_TRUE(testProxy != nullptr); + int commandDisconnect = 1; + MessageParcel data = {}; + testProxy->RemoteRequest(data, commandDisconnect); + EXPECT_TRUE(testProxy->remoteObject_ == nullptr); + GTEST_LOG_(INFO) << "AppExecFwk_ConnectCallbackProxy_RemoteRequest_002 end."; +} +} // namespace AppExecFwk +} // namespace OHOS \ No newline at end of file diff --git a/test/unittest/continuation_test/remote_register_service_test/connect_callback_stub_test/BUILD.gn b/test/unittest/continuation_test/remote_register_service_test/connect_callback_stub_test/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..a5ec54d6eaa369d12e5d21a582deb810ba30dd22 --- /dev/null +++ b/test/unittest/continuation_test/remote_register_service_test/connect_callback_stub_test/BUILD.gn @@ -0,0 +1,63 @@ +# 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/ability/ability_runtime/ability_runtime.gni") + +module_output_path = "ability_runtime/abilitymgr" + +config("coverage_flags") { + if (ability_runtime_feature_coverage) { + cflags = [ "--coverage" ] + ldflags = [ "--coverage" ] + } +} + +ohos_unittest("connect_callback_stub_test") { + module_out_path = module_output_path + + include_dirs = [ + "${ability_runtime_path}/interfaces/kits/native/ability/native/continuation/remote_register_service", + "${ability_runtime_innerkits_path}/ability_manager/include/continuation", + "${ability_runtime_services_path}/common/include", + ] + + sources = [ "connect_callback_stub_test.cpp" ] + + configs = [ ":coverage_flags" ] + cflags = [] + if (target_cpu == "arm") { + cflags += [ "-DBINDER_IPC_32BIT" ] + } + deps = [ + "//foundation/ability/ability_runtime/frameworks/native/ability/native:continuation_ipc", + "//third_party/googletest:gmock_main", + "//third_party/googletest:gtest_main", + ] + + external_deps = [ + "ability_base:want", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_core", + ] + + if (background_task_mgr_continuous_task_enable) { + external_deps += [ "background_task_mgr:bgtaskmgr_innerkits" ] + } +} + +group("unittest") { + testonly = true + deps = [ ":connect_callback_stub_test" ] +} diff --git a/test/unittest/continuation_test/remote_register_service_test/connect_callback_stub_test/connect_callback_stub_test.cpp b/test/unittest/continuation_test/remote_register_service_test/connect_callback_stub_test/connect_callback_stub_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..30060629d01d2fb29f7ca7d4604b5d413f7d7df1 --- /dev/null +++ b/test/unittest/continuation_test/remote_register_service_test/connect_callback_stub_test/connect_callback_stub_test.cpp @@ -0,0 +1,207 @@ +/* + * 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 +#include +#include + +#define private public +#define protected public +#include "connect_callback_proxy.h" +#include "connect_callback_stub.h" +#undef private +#undef protected + +using namespace testing::ext; +using namespace testing; +using namespace std::chrono; + +namespace OHOS { +namespace AppExecFwk { +class ConnectCallbackStubTest : public testing::Test { +public: + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp(); + void TearDown(); +}; + +void ConnectCallbackStubTest::SetUpTestCase(void) +{} + +void ConnectCallbackStubTest::TearDownTestCase(void) +{} + +void ConnectCallbackStubTest::SetUp(void) +{} + +void ConnectCallbackStubTest::TearDown(void) +{} + +class MockConnectCallback : public ConnectCallbackStub { +public: + MockConnectCallback() {}; + ~MockConnectCallback() {}; + + sptr AsObject() override + { + if (!asObject_) { + return nullptr; + } + return this; + }; + + void Connect(const string &deviceId, const string &deviceType) override + { + return; + } + void Disconnect(const string &deviceId) override + { + return; + } + + int32_t returnCode_ = ERR_NONE; + bool asObject_ = true; +}; + +/** + * @tc.number: AppExecFwk_ConnectCallbackStub_ConnectInner_001 + * @tc.name: ConnectInner + * @tc.desc: Pass in normal parameters, and the test program executes correctly without abnormal exit + */ +HWTEST_F(ConnectCallbackStubTest, AppExecFwk_ConnectCallbackStub_ConnectInner_001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AppExecFwk_ConnectCallbackStub_ConnectInner_001 start."; + sptr object = new (std::nothrow) MockConnectCallback(); + EXPECT_TRUE(object != nullptr); + MessageParcel data = {}; + MessageParcel reply = {}; + EXPECT_EQ(object->ConnectInner(data, reply), OHOS::ERR_NONE); + GTEST_LOG_(INFO) << "AppExecFwk_ConnectCallbackStub_ConnectInner_001 end."; +} + +/** + * @tc.number: AppExecFwk_ConnectCallbackStub_DisconnectInner_001 + * @tc.name: DisconnectInner + * @tc.desc: Pass in normal parameters, and the test program executes correctly without abnormal exit + */ +HWTEST_F(ConnectCallbackStubTest, AppExecFwk_ConnectCallbackStub_DisconnectInner_001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AppExecFwk_ConnectCallbackStub_DisconnectInner_001 start."; + sptr object = new (std::nothrow) MockConnectCallback(); + EXPECT_TRUE(object != nullptr); + MessageParcel data = {}; + MessageParcel reply = {}; + EXPECT_EQ(object->DisconnectInner(data, reply), OHOS::ERR_NONE); + GTEST_LOG_(INFO) << "AppExecFwk_ConnectCallbackStub_DisconnectInner_001 end."; +} + +/** + * @tc.number: AppExecFwk_ConnectCallbackStub_OnRemoteRequest_001 + * @tc.name: OnRemoteRequest + * @tc.desc: Pass in normal parameters, and the test program executes correctly without abnormal exit + */ +HWTEST_F(ConnectCallbackStubTest, AppExecFwk_ConnectCallbackStub_OnRemoteRequest_001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AppExecFwk_ConnectCallbackStub_OnRemoteRequest_001 start."; + sptr object = new (std::nothrow) MockConnectCallback(); + EXPECT_TRUE(object != nullptr); + MessageParcel data; + MessageParcel reply; + MessageOption option; + EXPECT_TRUE(data.WriteInterfaceToken(u"ohos.appexecfwk.iconnectcallback")); + EXPECT_EQ(object->OnRemoteRequest(MockConnectCallback::COMMAND_CONNECT, data, reply, option), OHOS::ERR_NONE); + GTEST_LOG_(INFO) << "AppExecFwk_ConnectCallbackStub_OnRemoteRequest_001 end."; +} + +/** + * @tc.number: AppExecFwk_ConnectCallbackStub_OnRemoteRequest_002 + * @tc.name: OnRemoteRequest + * @tc.desc: Pass in normal parameters, and the test program executes correctly without abnormal exit + */ +HWTEST_F(ConnectCallbackStubTest, AppExecFwk_ConnectCallbackStub_OnRemoteRequest_002, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AppExecFwk_ConnectCallbackStub_OnRemoteRequest_002 start."; + sptr object = new (std::nothrow) MockConnectCallback(); + EXPECT_TRUE(object != nullptr); + MessageParcel data; + MessageParcel reply; + MessageOption option; + EXPECT_TRUE(data.WriteInterfaceToken(u"ohos.appexecfwk.iconnectcallback")); + EXPECT_EQ(object->OnRemoteRequest(MockConnectCallback::COMMAND_DISCONNECT, data, reply, option), OHOS::ERR_NONE); + GTEST_LOG_(INFO) << "AppExecFwk_ConnectCallbackStub_OnRemoteRequest_002 end."; +} + +/** + * @tc.number: AppExecFwk_ConnectCallbackStub_OnRemoteRequest_003 + * @tc.name: OnRemoteRequest + * @tc.desc: The passed in parameter toukenString is an abnormal value. The test program executes as + * expected and does not exit abnormally + */ +HWTEST_F(ConnectCallbackStubTest, AppExecFwk_ConnectCallbackStub_OnRemoteRequest_003, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AppExecFwk_ConnectCallbackStub_OnRemoteRequest_003 start."; + sptr object = new (std::nothrow) MockConnectCallback(); + EXPECT_TRUE(object != nullptr); + MessageParcel data; + MessageParcel reply; + MessageOption option; + EXPECT_TRUE(data.WriteInterfaceToken(u"123")); + EXPECT_EQ(object->OnRemoteRequest(MockConnectCallback::COMMAND_CONNECT, data, reply, option), + OHOS::ERR_INVALID_REPLY); + GTEST_LOG_(INFO) << "AppExecFwk_ConnectCallbackStub_OnRemoteRequest_003 end."; +} + +/** + * @tc.number: AppExecFwk_ConnectCallbackStub_OnRemoteRequest_004 + * @tc.name: OnRemoteRequest + * @tc.desc: The input parameter code is an abnormal value, and the test program executes as expected + * without exiting abnormally + */ +HWTEST_F(ConnectCallbackStubTest, AppExecFwk_ConnectCallbackStub_OnRemoteRequest_004, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AppExecFwk_ConnectCallbackStub_OnRemoteRequest_004 start."; + sptr object = new (std::nothrow) MockConnectCallback(); + EXPECT_TRUE(object != nullptr); + MessageParcel data; + MessageParcel reply; + MessageOption option; + EXPECT_TRUE(data.WriteInterfaceToken(u"ohos.appexecfwk.iconnectcallback")); + EXPECT_EQ(object->OnRemoteRequest(MockConnectCallback::COMMAND_DISCONNECT + 66, data, reply, option), + OHOS::IPC_STUB_UNKNOW_TRANS_ERR); + GTEST_LOG_(INFO) << "AppExecFwk_ConnectCallbackStub_OnRemoteRequest_004 end."; +} + +/** + * @tc.number: AppExecFwk_ConnectCallbackStub_OnRemoteRequest_005 + * @tc.name: OnRemoteRequest + * @tc.desc: The input parameter code is null ptr, and the test program executes as expected without exception + */ +HWTEST_F(ConnectCallbackStubTest, AppExecFwk_ConnectCallbackStub_OnRemoteRequest_005, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AppExecFwk_ConnectCallbackStub_OnRemoteRequest_005 start."; + sptr object = new (std::nothrow) MockConnectCallback(); + EXPECT_TRUE(object != nullptr); + MessageParcel data = {}; + MessageParcel reply = {}; + MessageOption option = {}; + EXPECT_TRUE(data.WriteInterfaceToken(u"ohos.appexecfwk.iconnectcallback")); + object->memberFuncMap_[MockConnectCallback::COMMAND_DISCONNECT + 1] = nullptr; + EXPECT_EQ(object->OnRemoteRequest(MockConnectCallback::COMMAND_DISCONNECT + 1, data, reply, option), + IPC_STUB_UNKNOW_TRANS_ERR); + GTEST_LOG_(INFO) << "AppExecFwk_ConnectCallbackStub_OnRemoteRequest_005 end."; +} +} // namespace AppExecFwk +} // namespace OHOS \ No newline at end of file diff --git a/test/unittest/continuation_test/remote_register_service_test/continuation_connector_test/BUILD.gn b/test/unittest/continuation_test/remote_register_service_test/continuation_connector_test/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..5de75636f0482024c86aa8c1942002aa897206d7 --- /dev/null +++ b/test/unittest/continuation_test/remote_register_service_test/continuation_connector_test/BUILD.gn @@ -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/ability/ability_runtime/ability_runtime.gni") + +module_output_path = "ability_runtime/abilitymgr" + +remote_register_path = "${ability_runtime_path}/frameworks/native/ability/native/continuation/remote_register_service" + +config("coverage_flags") { + if (ability_runtime_feature_coverage) { + cflags = [ "--coverage" ] + ldflags = [ "--coverage" ] + } +} + +ohos_unittest("continuation_connector_test") { + module_out_path = module_output_path + + include_dirs = [ + "${ability_runtime_path}/interfaces/kits/native/ability/native", + "${ability_runtime_path}/interfaces/kits/native/ability/native/continuation/remote_register_service", + "${ability_runtime_innerkits_path}/ability_manager/include/continuation", + "${ability_runtime_services_path}/common/include", + ] + + sources = [ + "${remote_register_path}/connect_callback_stub.cpp", + "${remote_register_path}/continuation_connector.cpp", + "${remote_register_path}/continuation_device_callback_proxy.cpp", + "${remote_register_path}/remote_register_service_stub.cpp", + "continuation_connector_test.cpp", + ] + + configs = [ ":coverage_flags" ] + cflags = [] + if (target_cpu == "arm") { + cflags += [ "-DBINDER_IPC_32BIT" ] + } + deps = [ + "${ability_runtime_native_path}/ability/native:abilitykit_native", + "//third_party/googletest:gmock_main", + "//third_party/googletest:gtest_main", + ] + + external_deps = [ + "ability_base:want", + "ability_runtime:ability_manager", + "c_utils:utils", + "eventhandler:libeventhandler", + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_core", + ] + + if (background_task_mgr_continuous_task_enable) { + external_deps += [ "background_task_mgr:bgtaskmgr_innerkits" ] + } +} + +group("unittest") { + testonly = true + deps = [ ":continuation_connector_test" ] +} diff --git a/test/unittest/continuation_test/remote_register_service_test/continuation_connector_test/continuation_connector_test.cpp b/test/unittest/continuation_test/remote_register_service_test/continuation_connector_test/continuation_connector_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..db57047e33c73e7ec023ca46a1d13ec47de5b7d5 --- /dev/null +++ b/test/unittest/continuation_test/remote_register_service_test/continuation_connector_test/continuation_connector_test.cpp @@ -0,0 +1,832 @@ +/* + * 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 +#include +#include + +#define private public +#define protected public +#include "ability.h" +#include "continuation_connector.h" +#include "remote_register_service_stub.h" +#undef private +#undef protected + +using namespace testing::ext; +using namespace testing; +using namespace std::chrono; + +namespace OHOS { +namespace AppExecFwk { +class ContinuationConnectorTest : public testing::Test { +public: + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp(); + void TearDown(); +}; + +void ContinuationConnectorTest::SetUpTestCase(void) +{} +void ContinuationConnectorTest::TearDownTestCase(void) +{} + +void ContinuationConnectorTest::SetUp(void) +{} + +void ContinuationConnectorTest::TearDown(void) +{} + +class MockRegisterService : public RemoteRegisterServiceStub { +public: + MockRegisterService() {}; + virtual ~MockRegisterService() {}; + + int SendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override + { + GTEST_LOG_(INFO) << "MockRegisterService::SendRequest called. return value " << returnCode_; + reply.WriteInt32(ERR_NONE); + return returnCode_; + } + + int Register(const std::string &bundleName, const sptr &token, const ExtraParams &extras, + const sptr &callback) override + { + return register_; + }; + bool Unregister(int registerToken) override + { + return unregister_; + }; + bool UpdateConnectStatus(int registerToken, const std::string &deviceId, int status) override + { + return updateConnectStatus_; + }; + bool ShowDeviceList(int registerToken, const ExtraParams &extras) override + { + return showDeviceList_; + }; + + sptr AsInterface() override + { + if (!asInterface_) { + return nullptr; + } + + return this; + } + + int32_t returnCode_ = ERR_NONE; + int32_t register_ = ERR_NONE; + bool unregister_ = true; + bool updateConnectStatus_ = true; + bool showDeviceList_ = true; + bool asInterface_ = true; +}; + +class MockRequest : public ContinuationRequest { +public: + MockRequest() {}; + virtual ~MockRequest() {}; + + void Execute() override + { + flag = true; + }; + + bool flag = false; +}; + +class MockContext : public Ability { +public: + MockContext() {}; + virtual ~MockContext() {}; + + ErrCode DisconnectAbility(const sptr &conn) override + { + GTEST_LOG_(INFO) << "Mock DisconnectAbility called."; + return ERR_OK; + } + + bool ConnectAbility(const Want &want, const sptr &conn) override + { + GTEST_LOG_(INFO) << "Mock ConnectAbility called."; + return true; + } +}; + +/* +* @tc.number: AppExecFwk_ContinuationConnector_GetInstance_001 +* @tc.name: GetInstance +* @tc.desc: Verify function GetInstance normal branch +*/ +HWTEST_F(ContinuationConnectorTest, AppExecFwk_ContinuationConnector_GetInstance_001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AppExecFwk_ContinuationConnector_GetInstance_001 start."; + std::shared_ptr ability = std::make_shared(); + EXPECT_TRUE(ability != nullptr); + EXPECT_TRUE(ContinuationConnector::instance_ == nullptr); + EXPECT_TRUE(ContinuationConnector::GetInstance(ability) != nullptr); + EXPECT_TRUE(ContinuationConnector::instance_ != nullptr); + ContinuationConnector::instance_.clear(); + ContinuationConnector::instance_ = nullptr; + GTEST_LOG_(INFO) << "AppExecFwk_ContinuationConnector_GetInstance_001 end."; +} + +/* +* @tc.number: AppExecFwk_ContinuationConnector_GetInstance_002 +* @tc.name: GetInstance +* @tc.desc: Verify function GetInstance normal branch +*/ +HWTEST_F(ContinuationConnectorTest, AppExecFwk_ContinuationConnector_GetInstance_002, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AppExecFwk_ContinuationConnector_GetInstance_002 start."; + std::shared_ptr ability = std::make_shared(); + EXPECT_TRUE(ability != nullptr); + EXPECT_TRUE(ContinuationConnector::GetInstance(ability) != nullptr); + EXPECT_TRUE(ContinuationConnector::instance_ != nullptr); + EXPECT_TRUE(ContinuationConnector::GetInstance(ability) != nullptr); + EXPECT_TRUE(ContinuationConnector::instance_ != nullptr); + ContinuationConnector::instance_.clear(); + ContinuationConnector::instance_ = nullptr; + GTEST_LOG_(INFO) << "AppExecFwk_ContinuationConnector_GetInstance_002 end."; +} + +/* +* @tc.number: AppExecFwk_ContinuationConnector_OnAbilityConnectDone_001 +* @tc.name: OnAbilityConnectDone +* @tc.desc: Verify function OnAbilityConnectDone normal branch +*/ +HWTEST_F(ContinuationConnectorTest, AppExecFwk_ContinuationConnector_OnAbilityConnectDone_001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AppExecFwk_ContinuationConnector_OnAbilityConnectDone_001 start."; + std::shared_ptr ability = std::make_shared(); + EXPECT_TRUE(ability != nullptr); + sptr object = new (std::nothrow) MockRegisterService(); + EXPECT_TRUE(object != nullptr); + auto mockRequest = std::make_shared(); + EXPECT_TRUE(mockRequest != nullptr); + EXPECT_FALSE(mockRequest->flag); + sptr testConnector = new (std::nothrow) ContinuationConnector(ability); + EXPECT_TRUE(testConnector != nullptr); + testConnector->continuationRequestList_.push_back(mockRequest); + AppExecFwk::ElementName element; + constexpr int32_t registerToken = 0; + testConnector->OnAbilityConnectDone(element, object, registerToken); + EXPECT_TRUE(mockRequest->flag); + testConnector.clear(); + testConnector = nullptr; + GTEST_LOG_(INFO) << "AppExecFwk_ContinuationConnector_OnAbilityConnectDone_001 end."; +} + +/* +* @tc.number: AppExecFwk_ContinuationConnector_OnAbilityConnectDone_002 +* @tc.name: OnAbilityConnectDone +* @tc.desc: Verify function OnAbilityConnectDone abnormal branch, parameter object is nullptr +*/ +HWTEST_F(ContinuationConnectorTest, AppExecFwk_ContinuationConnector_OnAbilityConnectDone_002, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AppExecFwk_ContinuationConnector_OnAbilityConnectDone_002 start."; + std::shared_ptr ability = std::make_shared(); + EXPECT_TRUE(ability != nullptr); + sptr object = nullptr; + EXPECT_TRUE(object == nullptr); + auto mockRequest = std::make_shared(); + EXPECT_TRUE(mockRequest != nullptr); + EXPECT_FALSE(mockRequest->flag); + sptr testConnector = new (std::nothrow) ContinuationConnector(ability); + EXPECT_TRUE(testConnector != nullptr); + testConnector->continuationRequestList_.push_back(mockRequest); + AppExecFwk::ElementName element; + constexpr int32_t registerToken = 0; + testConnector->OnAbilityConnectDone(element, object, registerToken); + EXPECT_FALSE(mockRequest->flag); + testConnector.clear(); + testConnector = nullptr; + GTEST_LOG_(INFO) << "AppExecFwk_ContinuationConnector_OnAbilityConnectDone_002 end."; +} + +/* +* @tc.number: AppExecFwk_ContinuationConnector_OnAbilityConnectDone_003 +* @tc.name: OnAbilityConnectDone +* @tc.desc: Verify function OnAbilityConnectDone abnormal branch, conversion registerService is nullptr +*/ +HWTEST_F(ContinuationConnectorTest, AppExecFwk_ContinuationConnector_OnAbilityConnectDone_003, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AppExecFwk_ContinuationConnector_OnAbilityConnectDone_003 start."; + std::shared_ptr ability = std::make_shared(); + EXPECT_TRUE(ability != nullptr); + sptr object = new (std::nothrow) MockRegisterService(); + EXPECT_TRUE(object != nullptr); + auto mockRequest = std::make_shared(); + EXPECT_TRUE(mockRequest != nullptr); + EXPECT_FALSE(mockRequest->flag); + sptr testConnector = new (std::nothrow) ContinuationConnector(ability); + EXPECT_TRUE(testConnector != nullptr); + testConnector->continuationRequestList_.push_back(mockRequest); + AppExecFwk::ElementName element; + constexpr int32_t registerToken = 0; + object->asInterface_ = false; + testConnector->OnAbilityConnectDone(element, object, registerToken); + EXPECT_FALSE(mockRequest->flag); + testConnector.clear(); + testConnector = nullptr; + GTEST_LOG_(INFO) << "AppExecFwk_ContinuationConnector_OnAbilityConnectDone_003 end."; +} + +/* +* @tc.number: AppExecFwk_ContinuationConnector_OnAbilityConnectDone_004 +* @tc.name: OnAbilityConnectDone +* @tc.desc: Verify function OnAbilityConnectDone normal branch, member variable requestList is empty +*/ +HWTEST_F(ContinuationConnectorTest, AppExecFwk_ContinuationConnector_OnAbilityConnectDone_004, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AppExecFwk_ContinuationConnector_OnAbilityConnectDone_004 start."; + std::shared_ptr ability = std::make_shared(); + EXPECT_TRUE(ability != nullptr); + sptr object = new (std::nothrow) MockRegisterService(); + EXPECT_TRUE(object != nullptr); + sptr testConnector = new (std::nothrow) ContinuationConnector(ability); + EXPECT_TRUE(testConnector != nullptr); + AppExecFwk::ElementName element; + constexpr int32_t registerToken = 0; + EXPECT_TRUE(testConnector->continuationRequestList_.size() == 0); + testConnector->OnAbilityConnectDone(element, object, registerToken); + EXPECT_TRUE(testConnector->continuationRequestList_.size() == 0); + testConnector.clear(); + testConnector = nullptr; + GTEST_LOG_(INFO) << "AppExecFwk_ContinuationConnector_OnAbilityConnectDone_004 end."; +} + +/* +* @tc.number: AppExecFwk_ContinuationConnector_OnAbilityDisconnectDone_001 +* @tc.name: OnAbilityDisconnectDone +* @tc.desc: Verify function OnAbilityDisconnectDone normal branch +*/ +HWTEST_F(ContinuationConnectorTest, AppExecFwk_ContinuationConnector_OnAbilityDisconnectDone_001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AppExecFwk_ContinuationConnector_OnAbilityDisconnectDone_001 start."; + std::shared_ptr ability = nullptr; + sptr testConnector = new (std::nothrow) ContinuationConnector(ability); + EXPECT_TRUE(testConnector != nullptr); + AppExecFwk::ElementName element; + constexpr int32_t registerToken = 0; + EXPECT_TRUE(testConnector->remoteRegisterService_ == nullptr); + testConnector->OnAbilityDisconnectDone(element, registerToken); + EXPECT_TRUE(testConnector->remoteRegisterService_ == nullptr); + testConnector.clear(); + testConnector = nullptr; + GTEST_LOG_(INFO) << "AppExecFwk_ContinuationConnector_OnAbilityDisconnectDone_001 end."; +} + +/* +* @tc.number: AppExecFwk_ContinuationConnector_OnAbilityDisconnectDone_002 +* @tc.name: OnAbilityDisconnectDone +* @tc.desc: Verify function OnAbilityDisconnectDone normal branch +*/ +HWTEST_F(ContinuationConnectorTest, AppExecFwk_ContinuationConnector_OnAbilityDisconnectDone_002, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AppExecFwk_ContinuationConnector_OnAbilityDisconnectDone_002 start."; + std::shared_ptr ability = nullptr; + sptr testConnector = new (std::nothrow) ContinuationConnector(ability); + EXPECT_TRUE(testConnector != nullptr); + sptr object = new (std::nothrow) MockRegisterService(); + EXPECT_TRUE(object != nullptr); + AppExecFwk::ElementName element; + constexpr int32_t registerToken = 0; + testConnector->remoteRegisterService_ = object; + EXPECT_TRUE(testConnector->remoteRegisterService_ != nullptr); + testConnector->OnAbilityDisconnectDone(element, registerToken); + EXPECT_TRUE(testConnector->remoteRegisterService_ == nullptr); + testConnector.clear(); + testConnector = nullptr; + GTEST_LOG_(INFO) << "AppExecFwk_ContinuationConnector_OnAbilityDisconnectDone_002 end."; +} + +/* +* @tc.number: AppExecFwk_ContinuationConnector_BindRemoteRegisterAbility_001 +* @tc.name: BindRemoteRegisterAbility +* @tc.desc: Verify function BindRemoteRegisterAbility normal branch +*/ +HWTEST_F(ContinuationConnectorTest, AppExecFwk_ContinuationConnector_BindRemoteRegisterAbility_001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AppExecFwk_ContinuationConnector_BindRemoteRegisterAbility_001 start."; + auto mockRequest = std::make_shared(); + EXPECT_TRUE(mockRequest != nullptr); + std::shared_ptr context = std::make_shared(); + EXPECT_TRUE(context != nullptr); + sptr testConnector = new (std::nothrow) ContinuationConnector(context); + EXPECT_TRUE(testConnector != nullptr); + testConnector->isConnected_.store(false); + EXPECT_FALSE(testConnector->isConnected_.load()); + testConnector->BindRemoteRegisterAbility(mockRequest); + EXPECT_TRUE(testConnector->continuationRequestList_.size() == 1); + testConnector.clear(); + testConnector = nullptr; + GTEST_LOG_(INFO) << "AppExecFwk_ContinuationConnector_BindRemoteRegisterAbility_001 end."; +} + +/* +* @tc.number: AppExecFwk_ContinuationConnector_BindRemoteRegisterAbility_002 +* @tc.name: BindRemoteRegisterAbility +* @tc.desc: Verify function BindRemoteRegisterAbility abnormal branch, member variable context_ is nullptr +*/ +HWTEST_F(ContinuationConnectorTest, AppExecFwk_ContinuationConnector_BindRemoteRegisterAbility_002, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AppExecFwk_ContinuationConnector_BindRemoteRegisterAbility_002 start."; + auto mockRequest = std::make_shared(); + EXPECT_TRUE(mockRequest != nullptr); + std::shared_ptr ability = nullptr; + sptr testConnector = new (std::nothrow) ContinuationConnector(ability); + EXPECT_TRUE(testConnector != nullptr); + testConnector->BindRemoteRegisterAbility(mockRequest); + EXPECT_TRUE(testConnector->continuationRequestList_.size() == 0); + testConnector.clear(); + testConnector = nullptr; + GTEST_LOG_(INFO) << "AppExecFwk_ContinuationConnector_BindRemoteRegisterAbility_002 end."; +} + +/* +* @tc.number: AppExecFwk_ContinuationConnector_BindRemoteRegisterAbility_003 +* @tc.name: BindRemoteRegisterAbility +* @tc.desc: Verify function BindRemoteRegisterAbility abnormal branch, parameter request is nullptr +*/ +HWTEST_F(ContinuationConnectorTest, AppExecFwk_ContinuationConnector_BindRemoteRegisterAbility_003, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AppExecFwk_ContinuationConnector_BindRemoteRegisterAbility_003 start."; + std::shared_ptr ability = std::make_shared(); + EXPECT_TRUE(ability != nullptr); + sptr testConnector = new (std::nothrow) ContinuationConnector(ability); + EXPECT_TRUE(testConnector != nullptr); + testConnector->BindRemoteRegisterAbility(nullptr); + EXPECT_TRUE(testConnector->continuationRequestList_.size() == 0); + testConnector.clear(); + testConnector = nullptr; + GTEST_LOG_(INFO) << "AppExecFwk_ContinuationConnector_BindRemoteRegisterAbility_003 end."; +} + +/* +* @tc.number: AppExecFwk_ContinuationConnector_BindRemoteRegisterAbility_004 +* @tc.name: BindRemoteRegisterAbility +* @tc.desc: Verify function BindRemoteRegisterAbility normal branch, member variable isConnected is true +*/ +HWTEST_F(ContinuationConnectorTest, AppExecFwk_ContinuationConnector_BindRemoteRegisterAbility_004, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AppExecFwk_ContinuationConnector_BindRemoteRegisterAbility_004 start."; + auto mockRequest = std::make_shared(); + EXPECT_TRUE(mockRequest != nullptr); + EXPECT_FALSE(mockRequest->flag); + std::shared_ptr ability = std::make_shared(); + EXPECT_TRUE(ability != nullptr); + sptr testConnector = new (std::nothrow) ContinuationConnector(ability); + EXPECT_TRUE(testConnector != nullptr); + testConnector->isConnected_.store(true); + EXPECT_TRUE(testConnector->isConnected_.load()); + testConnector->BindRemoteRegisterAbility(mockRequest); + EXPECT_TRUE(testConnector->continuationRequestList_.size() == 0); + EXPECT_TRUE(mockRequest->flag); + testConnector.clear(); + testConnector = nullptr; + GTEST_LOG_(INFO) << "AppExecFwk_ContinuationConnector_BindRemoteRegisterAbility_004 end."; +} + +/* +* @tc.number: AppExecFwk_ContinuationConnector_UnbindRemoteRegisterAbility_001 +* @tc.name: UnbindRemoteRegisterAbility +* @tc.desc: Verify function UnbindRemoteRegisterAbility normal branch +*/ +HWTEST_F(ContinuationConnectorTest, AppExecFwk_ContinuationConnector_UnbindRemoteRegisterAbility_001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AppExecFwk_ContinuationConnector_UnbindRemoteRegisterAbility_001 start."; + std::shared_ptr context = std::make_shared(); + EXPECT_TRUE(context != nullptr); + sptr testConnector = new (std::nothrow) ContinuationConnector(context); + EXPECT_TRUE(testConnector != nullptr); + testConnector->isConnected_.store(true); + EXPECT_TRUE(testConnector->isConnected_.load()); + testConnector->UnbindRemoteRegisterAbility(); + EXPECT_FALSE(testConnector->isConnected_.load()); + testConnector.clear(); + testConnector = nullptr; + GTEST_LOG_(INFO) << "AppExecFwk_ContinuationConnector_UnbindRemoteRegisterAbility_001 end."; +} + +/* +* @tc.number: AppExecFwk_ContinuationConnector_UnbindRemoteRegisterAbility_002 +* @tc.name: UnbindRemoteRegisterAbility +* @tc.desc: Verify function UnbindRemoteRegisterAbility abnormal branch, member varable context_ is nullptr +*/ +HWTEST_F(ContinuationConnectorTest, AppExecFwk_ContinuationConnector_UnbindRemoteRegisterAbility_002, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AppExecFwk_ContinuationConnector_UnbindRemoteRegisterAbility_002 start."; + std::shared_ptr context = nullptr; + EXPECT_TRUE(context == nullptr); + sptr testConnector = new (std::nothrow) ContinuationConnector(context); + EXPECT_TRUE(testConnector != nullptr); + testConnector->isConnected_.store(true); + EXPECT_TRUE(testConnector->isConnected_.load()); + testConnector->UnbindRemoteRegisterAbility(); + EXPECT_TRUE(testConnector->isConnected_.load()); + testConnector.clear(); + testConnector = nullptr; + GTEST_LOG_(INFO) << "AppExecFwk_ContinuationConnector_UnbindRemoteRegisterAbility_002 end."; +} + +/* +* @tc.number: AppExecFwk_ContinuationConnector_IsAbilityConnected_001 +* @tc.name: IsAbilityConnected +* @tc.desc: Verify function IsAbilityConnected normal branch +*/ +HWTEST_F(ContinuationConnectorTest, AppExecFwk_ContinuationConnector_IsAbilityConnected_001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AppExecFwk_ContinuationConnector_IsAbilityConnected_001 start."; + std::shared_ptr ability = nullptr; + sptr testConnector = new (std::nothrow) ContinuationConnector(ability); + EXPECT_TRUE(testConnector != nullptr); + testConnector->isConnected_.store(true); + EXPECT_TRUE(testConnector->IsAbilityConnected()); + testConnector.clear(); + testConnector = nullptr; + GTEST_LOG_(INFO) << "AppExecFwk_ContinuationConnector_IsAbilityConnected_001 end."; +} + +/* +* @tc.number: AppExecFwk_ContinuationConnector_IsAbilityConnected_002 +* @tc.name: IsAbilityConnected +* @tc.desc: Verify function IsAbilityConnected normal branch +*/ +HWTEST_F(ContinuationConnectorTest, AppExecFwk_ContinuationConnector_IsAbilityConnected_002, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AppExecFwk_ContinuationConnector_IsAbilityConnected_002 start."; + std::shared_ptr ability = nullptr; + sptr testConnector = new (std::nothrow) ContinuationConnector(ability); + EXPECT_TRUE(testConnector != nullptr); + testConnector->isConnected_.store(false); + EXPECT_FALSE(testConnector->IsAbilityConnected()); + testConnector.clear(); + testConnector = nullptr; + GTEST_LOG_(INFO) << "AppExecFwk_ContinuationConnector_IsAbilityConnected_002 end."; +} + +/* +* @tc.number: AppExecFwk_ContinuationConnector_Unregister_001 +* @tc.name: Unregister +* @tc.desc: Verify function Unregister normal branch +*/ +HWTEST_F(ContinuationConnectorTest, AppExecFwk_ContinuationConnector_Unregister_001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AppExecFwk_ContinuationConnector_Unregister_001 start."; + std::shared_ptr ability = nullptr; + sptr testConnector = new (std::nothrow) ContinuationConnector(ability); + EXPECT_TRUE(testConnector != nullptr); + sptr object = new (std::nothrow) MockRegisterService(); + EXPECT_TRUE(object != nullptr); + constexpr int32_t registerToken = 100; + object->unregister_ = true; + testConnector->remoteRegisterService_ = object; + EXPECT_TRUE(testConnector->remoteRegisterService_ != nullptr); + EXPECT_TRUE(testConnector->Unregister(registerToken)); + testConnector.clear(); + testConnector = nullptr; + GTEST_LOG_(INFO) << "AppExecFwk_ContinuationConnector_Unregister_001 end."; +} + +/* +* @tc.number: AppExecFwk_ContinuationConnector_Unregister_002 +* @tc.name: Unregister +* @tc.desc: Verify function Unregister normal branch +*/ +HWTEST_F(ContinuationConnectorTest, AppExecFwk_ContinuationConnector_Unregister_002, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AppExecFwk_ContinuationConnector_Unregister_002 start."; + std::shared_ptr ability = nullptr; + sptr testConnector = new (std::nothrow) ContinuationConnector(ability); + EXPECT_TRUE(testConnector != nullptr); + sptr object = new (std::nothrow) MockRegisterService(); + EXPECT_TRUE(object != nullptr); + constexpr int32_t registerToken = 100; + object->unregister_ = false; + testConnector->remoteRegisterService_ = object; + EXPECT_TRUE(testConnector->remoteRegisterService_ != nullptr); + EXPECT_FALSE(testConnector->Unregister(registerToken)); + testConnector.clear(); + testConnector = nullptr; + GTEST_LOG_(INFO) << "AppExecFwk_ContinuationConnector_Unregister_002 end."; +} + +/* + * Feature: AbilityManager + * Function: ContinuationConnector + * SubFunction: Unregister + * FunctionPoints: The parameter of function Unregister. + * EnvConditions: Can run ohos test framework + * CaseDescription: Verify function Unregister abnormal branch + */ +/* +* @tc.number: AppExecFwk_ContinuationConnector_Unregister_002 +* @tc.name: Unregister +* @tc.desc: Verify function Unregister abnormal branch, member variable remoteRegisterService_ is nullptr +*/ +HWTEST_F(ContinuationConnectorTest, AppExecFwk_ContinuationConnector_Unregister_003, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AppExecFwk_ContinuationConnector_Unregister_003 start."; + std::shared_ptr ability = nullptr; + sptr testConnector = new (std::nothrow) ContinuationConnector(ability); + EXPECT_TRUE(testConnector != nullptr); + constexpr int32_t registerToken = 100; + EXPECT_TRUE(testConnector->remoteRegisterService_ == nullptr); + EXPECT_FALSE(testConnector->Unregister(registerToken)); + testConnector.clear(); + testConnector = nullptr; + GTEST_LOG_(INFO) << "AppExecFwk_ContinuationConnector_Unregister_003 end."; +} + +/* +* @tc.number: AppExecFwk_ContinuationConnector_UpdateConnectStatus_001 +* @tc.name: UpdateConnectStatus +* @tc.desc: Verify function UpdateConnectStatus normal branch +*/ +HWTEST_F(ContinuationConnectorTest, AppExecFwk_ContinuationConnector_UpdateConnectStatus_001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AppExecFwk_ContinuationConnector_UpdateConnectStatus_001 start."; + std::shared_ptr ability = nullptr; + sptr testConnector = new (std::nothrow) ContinuationConnector(ability); + EXPECT_TRUE(testConnector != nullptr); + constexpr int32_t registerToken = 100; + constexpr int32_t stage = 1; + const std::string deviceId = "7001005458323933328a592135733900"; + sptr object = new (std::nothrow) MockRegisterService(); + EXPECT_TRUE(object != nullptr); + object->updateConnectStatus_ = true; + testConnector->remoteRegisterService_ = object; + EXPECT_TRUE(testConnector->remoteRegisterService_ != nullptr); + EXPECT_TRUE(testConnector->UpdateConnectStatus(registerToken, deviceId, stage)); + testConnector.clear(); + testConnector = nullptr; + GTEST_LOG_(INFO) << "AppExecFwk_ContinuationConnector_UpdateConnectStatus_001 end."; +} + +/* +* @tc.number: AppExecFwk_ContinuationConnector_UpdateConnectStatus_002 +* @tc.name: UpdateConnectStatus +* @tc.desc: Verify function UpdateConnectStatus normal branch +*/ +HWTEST_F(ContinuationConnectorTest, AppExecFwk_ContinuationConnector_UpdateConnectStatus_002, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AppExecFwk_ContinuationConnector_UpdateConnectStatus_002 start."; + std::shared_ptr ability = nullptr; + sptr testConnector = new (std::nothrow) ContinuationConnector(ability); + EXPECT_TRUE(testConnector != nullptr); + constexpr int32_t registerToken = 100; + constexpr int32_t stage = 1; + const std::string deviceId = "7001005458323933328a592135733900"; + sptr object = new (std::nothrow) MockRegisterService(); + EXPECT_TRUE(object != nullptr); + object->updateConnectStatus_ = false; + testConnector->remoteRegisterService_ = object; + EXPECT_TRUE(testConnector->remoteRegisterService_ != nullptr); + EXPECT_FALSE(testConnector->UpdateConnectStatus(registerToken, deviceId, stage)); + testConnector.clear(); + testConnector = nullptr; + GTEST_LOG_(INFO) << "AppExecFwk_ContinuationConnector_UpdateConnectStatus_002 end."; +} + +/* +* @tc.number: AppExecFwk_ContinuationConnector_UpdateConnectStatus_002 +* @tc.name: UpdateConnectStatus +* @tc.desc: Verify function UpdateConnectStatus abnormal branch, member variable remoteRegisterService_ is nullptr +*/ +HWTEST_F(ContinuationConnectorTest, AppExecFwk_ContinuationConnector_UpdateConnectStatus_003, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AppExecFwk_ContinuationConnector_UpdateConnectStatus_003 start."; + std::shared_ptr ability = nullptr; + sptr testConnector = new (std::nothrow) ContinuationConnector(ability); + EXPECT_TRUE(testConnector != nullptr); + constexpr int32_t registerToken = 100; + constexpr int32_t stage = 1; + const std::string deviceId = "7001005458323933328a592135733900"; + EXPECT_TRUE(testConnector->remoteRegisterService_ == nullptr); + EXPECT_FALSE(testConnector->UpdateConnectStatus(registerToken, deviceId, stage)); + testConnector.clear(); + testConnector = nullptr; + GTEST_LOG_(INFO) << "AppExecFwk_ContinuationConnector_UpdateConnectStatus_003 end."; +} + +/* +* @tc.number: AppExecFwk_ContinuationConnector_ShowDeviceList_001 +* @tc.name: ShowDeviceList +* @tc.desc: Verify function ShowDeviceList normal branch +*/ +HWTEST_F(ContinuationConnectorTest, AppExecFwk_ContinuationConnector_ShowDeviceList_001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AppExecFwk_ContinuationConnector_ShowDeviceList_001 start."; + std::shared_ptr ability = nullptr; + sptr testConnector = new (std::nothrow) ContinuationConnector(ability); + EXPECT_TRUE(testConnector != nullptr); + constexpr int32_t registerToken = 100; + const ExtraParams extra = {}; + sptr object = new (std::nothrow) MockRegisterService(); + EXPECT_TRUE(object != nullptr); + object->showDeviceList_ = true; + testConnector->remoteRegisterService_ = object; + EXPECT_TRUE(testConnector->remoteRegisterService_ != nullptr); + EXPECT_TRUE(testConnector->ShowDeviceList(registerToken, extra)); + testConnector.clear(); + testConnector = nullptr; + GTEST_LOG_(INFO) << "AppExecFwk_ContinuationConnector_ShowDeviceList_001 end."; +} + +/* +* @tc.number: AppExecFwk_ContinuationConnector_ShowDeviceList_002 +* @tc.name: ShowDeviceList +* @tc.desc: Verify function ShowDeviceList normal branch +*/ +HWTEST_F(ContinuationConnectorTest, AppExecFwk_ContinuationConnector_ShowDeviceList_002, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AppExecFwk_ContinuationConnector_ShowDeviceList_002 start."; + std::shared_ptr ability = nullptr; + sptr testConnector = new (std::nothrow) ContinuationConnector(ability); + EXPECT_TRUE(testConnector != nullptr); + constexpr int32_t registerToken = 100; + const ExtraParams extra = {}; + sptr object = new (std::nothrow) MockRegisterService(); + EXPECT_TRUE(object != nullptr); + object->showDeviceList_ = false; + testConnector->remoteRegisterService_ = object; + EXPECT_TRUE(testConnector->remoteRegisterService_ != nullptr); + EXPECT_FALSE(testConnector->ShowDeviceList(registerToken, extra)); + testConnector.clear(); + testConnector = nullptr; + GTEST_LOG_(INFO) << "AppExecFwk_ContinuationConnector_ShowDeviceList_002 end."; +} + +/* +* @tc.number: AppExecFwk_ContinuationConnector_ShowDeviceList_003 +* @tc.name: ShowDeviceList +* @tc.desc: Verify function ShowDeviceList abnormal branch, member variable remoteRegisterService_ is nullptr +*/ +HWTEST_F(ContinuationConnectorTest, AppExecFwk_ContinuationConnector_ShowDeviceList_003, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AppExecFwk_ContinuationConnector_ShowDeviceList_003 start."; + std::shared_ptr ability = nullptr; + sptr testConnector = new (std::nothrow) ContinuationConnector(ability); + EXPECT_TRUE(testConnector != nullptr); + constexpr int32_t registerToken = 100; + const ExtraParams extra = {}; + EXPECT_TRUE(testConnector->remoteRegisterService_ == nullptr); + EXPECT_FALSE(testConnector->ShowDeviceList(registerToken, extra)); + testConnector.clear(); + testConnector = nullptr; + GTEST_LOG_(INFO) << "AppExecFwk_ContinuationConnector_ShowDeviceList_003 end."; +} + +/* +* @tc.number: AppExecFwk_ContinuationConnector_Register_001 +* @tc.name: Register +* @tc.desc: Verify function Register normal branch +*/ +HWTEST_F(ContinuationConnectorTest, AppExecFwk_ContinuationConnector_Register_001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AppExecFwk_ContinuationConnector_Register_001 start."; + std::shared_ptr ability = std::make_shared(); + EXPECT_TRUE(ability != nullptr); + sptr testConnector = new (std::nothrow) ContinuationConnector(ability); + EXPECT_TRUE(testConnector != nullptr); + const std::string bundleName = "ABC"; + const ExtraParams extra = {}; + std::shared_ptr callback = nullptr; + sptr object = new (std::nothrow) MockRegisterService(); + EXPECT_TRUE(object != nullptr); + ability->token_ = object; + testConnector->remoteRegisterService_ = object; + EXPECT_TRUE(testConnector->remoteRegisterService_ != nullptr); + std::weak_ptr context = ability; + EXPECT_EQ(testConnector->Register(context, bundleName, extra, callback), ERR_NONE); + testConnector.clear(); + testConnector = nullptr; + GTEST_LOG_(INFO) << "AppExecFwk_ContinuationConnector_Register_001 end."; +} + +/* +* @tc.number: AppExecFwk_ContinuationConnector_Register_002 +* @tc.name: Register +* @tc.desc: Verify function Register abnormal branch, interface Register return error code +*/ +HWTEST_F(ContinuationConnectorTest, AppExecFwk_ContinuationConnector_Register_002, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AppExecFwk_ContinuationConnector_Register_002 start."; + std::shared_ptr ability = std::make_shared(); + EXPECT_TRUE(ability != nullptr); + sptr testConnector = new (std::nothrow) ContinuationConnector(ability); + EXPECT_TRUE(testConnector != nullptr); + const std::string bundleName = "ABC"; + const ExtraParams extra = {}; + std::shared_ptr callback = nullptr; + sptr object = new (std::nothrow) MockRegisterService(); + EXPECT_TRUE(object != nullptr); + ability->token_ = object; + object->register_ = ERR_NONE - 1; + testConnector->remoteRegisterService_ = object; + EXPECT_TRUE(testConnector->remoteRegisterService_ != nullptr); + std::weak_ptr context = ability; + EXPECT_EQ(testConnector->Register(context, bundleName, extra, callback), ERR_NONE - 1); + testConnector.clear(); + testConnector = nullptr; + GTEST_LOG_(INFO) << "AppExecFwk_ContinuationConnector_Register_002 end."; +} + +/* +* @tc.number: AppExecFwk_ContinuationConnector_Register_003 +* @tc.name: Register +* @tc.desc: Verify function Register abnormal branch, parameter context is nullptr +*/ +HWTEST_F(ContinuationConnectorTest, AppExecFwk_ContinuationConnector_Register_003, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AppExecFwk_ContinuationConnector_Register_003 start."; + std::shared_ptr ability = nullptr; + EXPECT_TRUE(ability == nullptr); + sptr testConnector = new (std::nothrow) ContinuationConnector(ability); + EXPECT_TRUE(testConnector != nullptr); + const std::string bundleName = "ABC"; + const ExtraParams extra = {}; + std::shared_ptr callback = nullptr; + sptr object = new (std::nothrow) MockRegisterService(); + EXPECT_TRUE(object != nullptr); + testConnector->remoteRegisterService_ = object; + EXPECT_TRUE(testConnector->remoteRegisterService_ != nullptr); + std::weak_ptr context = ability; + EXPECT_EQ(testConnector->Register(context, bundleName, extra, callback), -1); + testConnector.clear(); + testConnector = nullptr; + GTEST_LOG_(INFO) << "AppExecFwk_ContinuationConnector_Register_003 end."; +} + +/* +* @tc.number: AppExecFwk_ContinuationConnector_Register_004 +* @tc.name: Register +* @tc.desc: Verify function Register abnormal branch, member variable remoteRegisterService_ is nullptr +*/ +HWTEST_F(ContinuationConnectorTest, AppExecFwk_ContinuationConnector_Register_004, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AppExecFwk_ContinuationConnector_Register_004 start."; + std::shared_ptr ability = std::make_shared(); + EXPECT_TRUE(ability != nullptr); + sptr testConnector = new (std::nothrow) ContinuationConnector(ability); + EXPECT_TRUE(testConnector != nullptr); + const std::string bundleName = "ABC"; + const ExtraParams extra = {}; + std::shared_ptr callback = nullptr; + sptr object = new (std::nothrow) MockRegisterService(); + EXPECT_TRUE(object != nullptr); + ability->token_ = object; + EXPECT_TRUE(ability->token_ != nullptr); + testConnector->remoteRegisterService_ = nullptr; + EXPECT_TRUE(testConnector->remoteRegisterService_ == nullptr); + std::weak_ptr context = ability; + EXPECT_EQ(testConnector->Register(context, bundleName, extra, callback), -1); + testConnector.clear(); + testConnector = nullptr; + GTEST_LOG_(INFO) << "AppExecFwk_ContinuationConnector_Register_004 end."; +} + +/* +* @tc.number: AppExecFwk_ContinuationConnector_Register_005 +* @tc.name: Register +* @tc.desc: Verify function Register abnormal branch, obtained token is nullptr +*/ +HWTEST_F(ContinuationConnectorTest, AppExecFwk_ContinuationConnector_Register_005, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AppExecFwk_ContinuationConnector_Register_005 start."; + std::shared_ptr ability = std::make_shared(); + EXPECT_TRUE(ability != nullptr); + sptr testConnector = new (std::nothrow) ContinuationConnector(ability); + EXPECT_TRUE(testConnector != nullptr); + const std::string bundleName = "ABC"; + const ExtraParams extra = {}; + std::shared_ptr callback = nullptr; + sptr object = new (std::nothrow) MockRegisterService(); + EXPECT_TRUE(object != nullptr); + EXPECT_TRUE(ability->token_ == nullptr); + testConnector->remoteRegisterService_ = object; + EXPECT_TRUE(testConnector->remoteRegisterService_ != nullptr); + std::weak_ptr context = ability; + EXPECT_EQ(testConnector->Register(context, bundleName, extra, callback), -1); + testConnector.clear(); + testConnector = nullptr; + GTEST_LOG_(INFO) << "AppExecFwk_ContinuationConnector_Register_005 end."; +} +} // namespace AppExecFwk +} // namespace OHOS \ No newline at end of file diff --git a/test/unittest/continuation_test/remote_register_service_test/continuation_register_manager_test/BUILD.gn b/test/unittest/continuation_test/remote_register_service_test/continuation_register_manager_test/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..218e8b3e9a9611169bd7f3dbc579b9a842760a33 --- /dev/null +++ b/test/unittest/continuation_test/remote_register_service_test/continuation_register_manager_test/BUILD.gn @@ -0,0 +1,108 @@ +# 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/ability/ability_runtime/ability_runtime.gni") + +module_output_path = "ability_runtime/abilitymgr" + +remote_register_path = "${ability_runtime_path}/frameworks/native/ability/native/continuation/remote_register_service" + +config("coverage_flags") { + if (ability_runtime_feature_coverage) { + cflags = [ "--coverage" ] + ldflags = [ "--coverage" ] + } +} + +config("ability_config") { + visibility = [ ":*" ] + include_dirs = [ + "${ability_runtime_path}/interfaces/kits/native/ability/native", + "${ability_runtime_path}/interfaces/kits/native/ability/native/continuation/distributed", + "${ability_runtime_path}/interfaces/kits/native/ability/native/continuation/kits", + "${ability_runtime_path}/interfaces/kits/native/ability/native/continuation/remote_register_service", + "${ability_runtime_path}/interfaces/kits/native/ability/native/distributed_ability_runtime", + "${ability_runtime_path}/interfaces/kits/native/appkit/app", + "${ability_runtime_innerkits_path}/app_manager/include/appmgr", + "${ability_runtime_innerkits_path}/uri/include", + "${ability_runtime_services_path}/abilitymgr/include", + "${ability_runtime_path}/interfaces/kits/native/appkit/ability_runtime/app", + "${ability_runtime_path}/interfaces/kits/native/appkit/app", + "${form_fwk_path}/interfaces/kits/native/include", + "${ability_runtime_path}/interfaces/kits/native/appkit/app", + "//third_party/node/src", + "${ability_runtime_innerkits_path}/ability_manager/include/continuation", + "${ability_runtime_path}/interfaces/kits/native/appkit/app/task", + "${ability_runtime_napi_path}/inner/napi_common", + "${ability_runtime_napi_path}/featureAbility", + "//foundation/ability/ability_runtime/interfaces/kits/native/ability/native/continuation/kits", + ] + + cflags = [] + if (target_cpu == "arm") { + cflags += [ "-DBINDER_IPC_32BIT" ] + } + defines = [ "AMS_LOG_TAG = \"Ability\"" ] + if (target_cpu == "arm64") { + defines += [ "_ARM64_" ] + } + + if (ability_runtime_graphics) { + include_dirs += [ "${form_fwk_path}/interfaces/inner_api/include" ] + defines += [ "SUPPORT_GRAPHICS" ] + } +} + +ohos_unittest("continuation_register_manager_test") { + module_out_path = module_output_path + + sources = [ + "${remote_register_path}/continuation_register_manager.cpp", + "continuation_register_manager_test.cpp", + ] + + configs = [ + ":ability_config", + ":coverage_flags", + ] + cflags = [] + if (target_cpu == "arm") { + cflags += [ "-DBINDER_IPC_32BIT" ] + } + deps = [ + "${ability_runtime_innerkits_path}/ability_manager:ability_manager", + "${ability_runtime_native_path}/ability/native:abilitykit_native", + "//foundation/ability/ability_runtime/frameworks/native/ability/native:continuation_ipc", + "//third_party/googletest:gmock_main", + "//third_party/googletest:gtest_main", + ] + + external_deps = [ + "ability_base:want", + "ability_runtime:ability_manager", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_core", + "resource_management:global_resmgr", + ] + + if (background_task_mgr_continuous_task_enable) { + external_deps += [ "background_task_mgr:bgtaskmgr_innerkits" ] + } +} + +group("unittest") { + testonly = true + deps = [ ":continuation_register_manager_test" ] +} diff --git a/test/unittest/continuation_test/remote_register_service_test/continuation_register_manager_test/continuation_register_manager_test.cpp b/test/unittest/continuation_test/remote_register_service_test/continuation_register_manager_test/continuation_register_manager_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..309573d9327c8f72f28d501cfc483e993d8a2fa8 --- /dev/null +++ b/test/unittest/continuation_test/remote_register_service_test/continuation_register_manager_test/continuation_register_manager_test.cpp @@ -0,0 +1,339 @@ +/* + * 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 +#include +#include + +#define private public +#define protected public +#include "continuation_register_manager_proxy.h" +#include "continuation_register_manager.h" +#include "connect_callback_stub.h" +#include "continuation_connector.h" +#undef private +#undef protected +#include "bundle_mgr_interface.h" +#include "ability_manager_interface.h" +#include "iability_controller.h" +#include "pixel_map.h" +#include "ability_info.h" +#include "ability.h" +#include "request_callback.h" + +using namespace testing::ext; +using namespace testing; +using namespace std::chrono; + +namespace OHOS { +namespace AppExecFwk { +class ContinuationRegisterManagerTest : public testing::Test { +public: + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp(); + void TearDown(); +}; + +void ContinuationRegisterManagerTest::SetUpTestCase(void) +{} +void ContinuationRegisterManagerTest::TearDownTestCase(void) +{} + +void ContinuationRegisterManagerTest::SetUp(void) +{} + +void ContinuationRegisterManagerTest::TearDown(void) +{} + +class MockRequestCallback : public RequestCallback { +public: + MockRequestCallback() {}; + virtual ~MockRequestCallback() {}; + + virtual void OnResult(int result) + { + onResult_ = true; + }; + + bool onResult_ = false; +}; + +/* + * @tc.number : ContinuationRegisterManager_Register_001 + * @tc.name : Register + * @tc.desc : Verify that the Register interface is called normally + */ +HWTEST_F(ContinuationRegisterManagerTest, ContinuationRegisterManager_Register_001, TestSize.Level1) +{ + std::shared_ptr context = std::make_shared(); + auto continuationRegisterManager = std::make_shared(); + auto continuationRegisterManagerProxy = std::make_shared(context); + const std::string bundleName = ""; + ExtraParams parameter; + std::shared_ptr deviceCallback; + std::shared_ptr requestCallback = std::make_shared(); + continuationRegisterManagerProxy->continuatinConnector_ = new (std::nothrow) ContinuationConnector(context); + continuationRegisterManagerProxy->context_ = context; + continuationRegisterManagerProxy->applicationContext_ = context; + continuationRegisterManagerProxy->continuatinConnector_->isConnected_.store(true); + continuationRegisterManager->Init(continuationRegisterManagerProxy); + + EXPECT_FALSE(requestCallback->onResult_); + continuationRegisterManager->Register(bundleName, parameter, deviceCallback, requestCallback); + EXPECT_TRUE(requestCallback->onResult_); +} + +/* + * @tc.number : ContinuationRegisterManager_Register_002 + * @tc.name : Register + * @tc.desc : Verify that the Register interface is called normally + */ +HWTEST_F(ContinuationRegisterManagerTest, ContinuationRegisterManager_Register_002, TestSize.Level1) +{ + std::shared_ptr context = std::make_shared(); + auto continuationRegisterManager = std::make_shared(); + auto continuationRegisterManagerProxy = std::make_shared(context); + const std::string bundleName = ""; + ExtraParams parameter; + std::shared_ptr deviceCallback; + std::shared_ptr requestCallback = std::make_shared(); + continuationRegisterManagerProxy->continuatinConnector_ = new (std::nothrow) ContinuationConnector(context); + continuationRegisterManagerProxy->context_ = context; + continuationRegisterManagerProxy->applicationContext_ = context; + continuationRegisterManagerProxy->continuatinConnector_->isConnected_.store(true); + continuationRegisterManager->Init(nullptr); + + EXPECT_FALSE(requestCallback->onResult_); + continuationRegisterManager->Register(bundleName, parameter, deviceCallback, requestCallback); + EXPECT_FALSE(requestCallback->onResult_); +} + +/* + * @tc.number : ContinuationRegisterManager_Unregister_001 + * @tc.name : Unregister + * @tc.desc : Verify that the Unregister interface is called normally + */ +HWTEST_F(ContinuationRegisterManagerTest, ContinuationRegisterManager_Unregister_001, TestSize.Level1) +{ + std::shared_ptr context = std::make_shared(); + auto continuationRegisterManager = std::make_shared(); + auto continuationRegisterManagerProxy = std::make_shared(context); + constexpr int32_t token = 0; + std::shared_ptr requestCallback = std::make_shared(); + continuationRegisterManagerProxy->continuatinConnector_ = new (std::nothrow) ContinuationConnector(context); + continuationRegisterManagerProxy->context_ = context; + continuationRegisterManagerProxy->applicationContext_ = context; + continuationRegisterManagerProxy->continuatinConnector_->isConnected_.store(true); + continuationRegisterManager->Init(continuationRegisterManagerProxy); + + EXPECT_FALSE(requestCallback->onResult_); + continuationRegisterManager->Unregister(token, requestCallback); + EXPECT_TRUE(requestCallback->onResult_); +} + +/* + * @tc.number : ContinuationRegisterManager_Unregister_002 + * @tc.name : Unregister + * @tc.desc : Verify that the Unregister interface is called normally + */ +HWTEST_F(ContinuationRegisterManagerTest, ContinuationRegisterManager_Unregister_002, TestSize.Level1) +{ + std::shared_ptr context = std::make_shared(); + auto continuationRegisterManager = std::make_shared(); + auto continuationRegisterManagerProxy = std::make_shared(context); + constexpr int32_t token = 0; + std::shared_ptr requestCallback = std::make_shared(); + continuationRegisterManagerProxy->continuatinConnector_ = new (std::nothrow) ContinuationConnector(context); + continuationRegisterManagerProxy->context_ = context; + continuationRegisterManagerProxy->applicationContext_ = context; + continuationRegisterManagerProxy->continuatinConnector_->isConnected_.store(true); + continuationRegisterManager->Init(nullptr); + + EXPECT_FALSE(requestCallback->onResult_); + continuationRegisterManager->Unregister(token, requestCallback); + EXPECT_FALSE(requestCallback->onResult_); +} + +/* + * @tc.number : ContinuationRegisterManager_UpdateConnectStatus_001 + * @tc.name : UpdateConnectStatus + * @tc.desc : Verify that the UpdateConnectStatus interface is called normally + */ +HWTEST_F(ContinuationRegisterManagerTest, ContinuationRegisterManager_UpdateConnectStatus_001, TestSize.Level1) +{ + std::shared_ptr context = std::make_shared(); + auto continuationRegisterManager = std::make_shared(); + auto continuationRegisterManagerProxy = std::make_shared(context); + constexpr int32_t token = 0; + const std::string deviceId = ""; + constexpr int32_t status = 0; + std::shared_ptr requestCallback = std::make_shared(); + continuationRegisterManagerProxy->continuatinConnector_ = new (std::nothrow) ContinuationConnector(context); + continuationRegisterManagerProxy->context_ = context; + continuationRegisterManagerProxy->applicationContext_ = context; + continuationRegisterManagerProxy->continuatinConnector_->isConnected_.store(true); + continuationRegisterManager->Init(continuationRegisterManagerProxy); + + EXPECT_FALSE(requestCallback->onResult_); + continuationRegisterManager->UpdateConnectStatus(token, deviceId, status, requestCallback); + EXPECT_TRUE(requestCallback->onResult_); +} + +/* + * @tc.number : ContinuationRegisterManager_UpdateConnectStatus_002 + * @tc.name : UpdateConnectStatus + * @tc.desc : Verify that the UpdateConnectStatus interface is called normally + */ +HWTEST_F(ContinuationRegisterManagerTest, ContinuationRegisterManager_UpdateConnectStatus_002, TestSize.Level1) +{ + std::shared_ptr context = std::make_shared(); + auto continuationRegisterManager = std::make_shared(); + auto continuationRegisterManagerProxy = std::make_shared(context); + constexpr int32_t token = 0; + const std::string deviceId = ""; + constexpr int32_t status = 0; + std::shared_ptr requestCallback = std::make_shared(); + continuationRegisterManagerProxy->continuatinConnector_ = new (std::nothrow) ContinuationConnector(context); + continuationRegisterManagerProxy->context_ = context; + continuationRegisterManagerProxy->applicationContext_ = context; + continuationRegisterManagerProxy->continuatinConnector_->isConnected_.store(true); + continuationRegisterManager->Init(nullptr); + + EXPECT_FALSE(requestCallback->onResult_); + continuationRegisterManager->UpdateConnectStatus(token, deviceId, status, requestCallback); + EXPECT_FALSE(requestCallback->onResult_); +} + +/* + * @tc.number : ContinuationRegisterManager_ShowDeviceList_001 + * @tc.name : ShowDeviceList + * @tc.desc : Verify that the ShowDeviceList interface is called normally + */ +HWTEST_F(ContinuationRegisterManagerTest, ContinuationRegisterManager_ShowDeviceList_001, TestSize.Level1) +{ + std::shared_ptr context = std::make_shared(); + auto continuationRegisterManager = std::make_shared(); + auto continuationRegisterManagerProxy = std::make_shared(context); + constexpr int32_t token = 0; + ExtraParams parameter; + std::shared_ptr requestCallback = std::make_shared(); + continuationRegisterManagerProxy->continuatinConnector_ = new (std::nothrow) ContinuationConnector(context); + continuationRegisterManagerProxy->context_ = context; + continuationRegisterManagerProxy->applicationContext_ = context; + continuationRegisterManagerProxy->continuatinConnector_->isConnected_.store(true); + continuationRegisterManager->Init(continuationRegisterManagerProxy); + + EXPECT_FALSE(requestCallback->onResult_); + continuationRegisterManager->ShowDeviceList(token, parameter, requestCallback); + EXPECT_TRUE(requestCallback->onResult_); +} + +/* + * @tc.number : ContinuationRegisterManager_ShowDeviceList_002 + * @tc.name : ShowDeviceList + * @tc.desc : Verify that the ShowDeviceList interface is called normally + */ +HWTEST_F(ContinuationRegisterManagerTest, ContinuationRegisterManager_ShowDeviceList_002, TestSize.Level1) +{ + std::shared_ptr context = std::make_shared(); + auto continuationRegisterManager = std::make_shared(); + auto continuationRegisterManagerProxy = std::make_shared(context); + constexpr int32_t token = 0; + ExtraParams parameter; + std::shared_ptr requestCallback = std::make_shared(); + continuationRegisterManagerProxy->continuatinConnector_ = new (std::nothrow) ContinuationConnector(context); + continuationRegisterManagerProxy->context_ = context; + continuationRegisterManagerProxy->applicationContext_ = context; + continuationRegisterManagerProxy->continuatinConnector_->isConnected_.store(true); + continuationRegisterManager->Init(nullptr); + + EXPECT_FALSE(requestCallback->onResult_); + continuationRegisterManager->ShowDeviceList(token, parameter, requestCallback); + EXPECT_FALSE(requestCallback->onResult_); +} + +/* + * @tc.number : ContinuationRegisterManager_Disconnect_001 + * @tc.name : Disconnect + * @tc.desc : Verify that the Disconnect interface is called normally + */ +HWTEST_F(ContinuationRegisterManagerTest, ContinuationRegisterManager_Disconnect_001, TestSize.Level1) +{ + std::shared_ptr context = std::make_shared(); + auto continuationRegisterManager = std::make_shared(); + auto continuationRegisterManagerProxy = std::make_shared(context); + continuationRegisterManagerProxy->continuatinConnector_ = new (std::nothrow) ContinuationConnector(context); + continuationRegisterManager->Init(continuationRegisterManagerProxy); + continuationRegisterManagerProxy->continuatinConnector_->isConnected_.store(true); + + EXPECT_TRUE(continuationRegisterManagerProxy->continuatinConnector_->isConnected_.load()); + continuationRegisterManager->Disconnect(); + EXPECT_FALSE(continuationRegisterManagerProxy->continuatinConnector_->isConnected_.load()); +} + +/* + * @tc.number : ContinuationRegisterManager_Disconnect_002 + * @tc.name : Disconnect + * @tc.desc : Verify that the Disconnect interface is called normally + */ +HWTEST_F(ContinuationRegisterManagerTest, ContinuationRegisterManager_Disconnect_002, TestSize.Level1) +{ + std::shared_ptr context = std::make_shared(); + auto continuationRegisterManager = std::make_shared(); + auto continuationRegisterManagerProxy = std::make_shared(context); + continuationRegisterManagerProxy->continuatinConnector_ = nullptr; + continuationRegisterManager->Init(continuationRegisterManagerProxy); + + continuationRegisterManager->Disconnect(); + EXPECT_TRUE(true); +} + +/* + * @tc.number : ContinuationRegisterManager_Disconnect_003 + * @tc.name : Disconnect + * @tc.desc : Verify that the Disconnect interface is called normally + */ +HWTEST_F(ContinuationRegisterManagerTest, ContinuationRegisterManager_Disconnect_003, TestSize.Level1) +{ + std::shared_ptr context = std::make_shared(); + auto continuationRegisterManager = std::make_shared(); + auto continuationRegisterManagerProxy = std::make_shared(context); + continuationRegisterManagerProxy->continuatinConnector_ = new (std::nothrow) ContinuationConnector(context); + + EXPECT_FALSE(continuationRegisterManagerProxy->continuatinConnector_->isConnected_.load()); + continuationRegisterManagerProxy->continuatinConnector_->isConnected_.store(false); + continuationRegisterManager->Init(continuationRegisterManagerProxy); + + continuationRegisterManager->Disconnect(); + EXPECT_FALSE(continuationRegisterManagerProxy->continuatinConnector_->isConnected_.load()); +} + +/* + * @tc.number : ContinuationRegisterManager_Disconnect_004 + * @tc.name : Disconnect + * @tc.desc : Verify that the Disconnect interface is called normally + */ +HWTEST_F(ContinuationRegisterManagerTest, ContinuationRegisterManager_Disconnect_004, TestSize.Level1) +{ + auto continuationRegisterManager = std::make_shared(); + std::shared_ptr continuationRegisterManagerProxy; + continuationRegisterManager->Init(continuationRegisterManagerProxy); + + continuationRegisterManager->Disconnect(); + EXPECT_TRUE(true); +} +} // namespace AppExecFwk +} // namespace OHOS \ No newline at end of file