diff --git a/test/unittest/BUILD.gn b/test/unittest/BUILD.gn index f844c853e8e6197dcf55e85c0d4287ceafa962f9..0ee39053616e5661d5ad7358d81d16c410a0d637 100644 --- a/test/unittest/BUILD.gn +++ b/test/unittest/BUILD.gn @@ -32,7 +32,6 @@ ohos_unittest("medialibrary_file_access_test") { include_dirs = [ "${ability_runtime_path}/interfaces/kits/native/appkit/ability_runtime/context", "${user_file_service_path}/interfaces/inner_api/file_access/include", - "//third_party/googletest/googlemock/include/gmock", "${access_token_path}/frameworks/accesstoken:accesstoken_communication_adapter_cxx/", ] @@ -42,7 +41,6 @@ ohos_unittest("medialibrary_file_access_test") { "${ability_runtime_path}/frameworks/native/ability/native:abilitykit_native", "${ability_runtime_path}/frameworks/native/appkit:app_context", "${user_file_service_path}/interfaces/inner_api/file_access:file_access_extension_ability_kit", - "//third_party/googletest:gmock_main", ] external_deps = [ @@ -57,6 +55,8 @@ ohos_unittest("medialibrary_file_access_test") { "access_token:libnativetoken", "access_token:libtoken_setproc", "c_utils:utils", + "googletest:gmock_main", + "googletest:gtest_main", "ipc:ipc_core", "ipc:rpc", "samgr:samgr_proxy", @@ -84,7 +84,6 @@ ohos_unittest("external_file_access_basic_test") { include_dirs = [ "${ability_runtime_path}/interfaces/kits/native/appkit/ability_runtime/context", - "//third_party/googletest/googlemock/include/gmock", "${user_file_service_path}/interfaces/inner_api/file_access/include", "${user_file_service_path}/services/native/file_access_service/include", ] @@ -96,7 +95,6 @@ ohos_unittest("external_file_access_basic_test") { "${ability_runtime_path}/frameworks/native/appkit:app_context", "${user_file_service_path}/interfaces/inner_api/file_access:file_access_extension_ability_kit", "${user_file_service_path}/services:file_access_service", - "//third_party/googletest:gmock_main", ] external_deps = [ @@ -112,6 +110,8 @@ ohos_unittest("external_file_access_basic_test") { "access_token:libtoken_setproc", "bundle_framework:appexecfwk_core", "c_utils:utils", + "googletest:gmock_main", + "googletest:gtest_main", "hilog:libhilog", "ipc:ipc_core", "ipc:rpc", @@ -139,7 +139,6 @@ ohos_unittest("external_file_access_management_test") { include_dirs = [ "${ability_runtime_path}/interfaces/kits/native/appkit/ability_runtime/context", - "//third_party/googletest/googlemock/include/gmock", "${user_file_service_path}/interfaces/inner_api/file_access/include", "${user_file_service_path}/services/native/file_access_service/include", ] @@ -151,7 +150,6 @@ ohos_unittest("external_file_access_management_test") { "${ability_runtime_path}/frameworks/native/appkit:app_context", "${user_file_service_path}/interfaces/inner_api/file_access:file_access_extension_ability_kit", "${user_file_service_path}/services:file_access_service", - "//third_party/googletest:gmock_main", ] external_deps = [ @@ -167,6 +165,8 @@ ohos_unittest("external_file_access_management_test") { "access_token:libtoken_setproc", "bundle_framework:appexecfwk_core", "c_utils:utils", + "googletest:gmock_main", + "googletest:gtest_main", "hilog:libhilog", "ipc:ipc_core", "ipc:rpc", @@ -190,7 +190,6 @@ ohos_unittest("external_file_access_notify_test") { include_dirs = [ "${ability_runtime_path}/interfaces/kits/native/appkit/ability_runtime/context", - "//third_party/googletest/googlemock/include/gmock", "${user_file_service_path}/interfaces/inner_api/file_access/include", "${user_file_service_path}/services/native/file_access_service/include", ] @@ -202,7 +201,6 @@ ohos_unittest("external_file_access_notify_test") { "${ability_runtime_path}/frameworks/native/appkit:app_context", "${user_file_service_path}/interfaces/inner_api/file_access:file_access_extension_ability_kit", "${user_file_service_path}/services:file_access_service", - "//third_party/googletest:gmock_main", ] external_deps = [ @@ -218,6 +216,8 @@ ohos_unittest("external_file_access_notify_test") { "access_token:libtoken_setproc", "bundle_framework:appexecfwk_core", "c_utils:utils", + "googletest:gmock_main", + "googletest:gtest_main", "hilog:libhilog", "ipc:ipc_core", "ipc:rpc", @@ -239,7 +239,6 @@ ohos_unittest("abnormal_file_access_test") { include_dirs = [ "${ability_runtime_path}/interfaces/kits/native/appkit/ability_runtime/context", - "//third_party/googletest/googlemock/include/gmock", "${user_file_service_path}/interfaces/inner_api/file_access/include", ] @@ -249,7 +248,6 @@ ohos_unittest("abnormal_file_access_test") { "${ability_runtime_path}/frameworks/native/ability/native:abilitykit_native", "${ability_runtime_path}/frameworks/native/appkit:app_context", "${user_file_service_path}/interfaces/inner_api/file_access:file_access_extension_ability_kit", - "//third_party/googletest:gmock_main", ] external_deps = [ @@ -265,6 +263,8 @@ ohos_unittest("abnormal_file_access_test") { "access_token:libtoken_setproc", "bundle_framework:appexecfwk_core", "c_utils:utils", + "googletest:gmock_main", + "googletest:gtest_main", "hilog:libhilog", "ipc:ipc_core", "samgr:samgr_proxy", @@ -289,7 +289,6 @@ ohos_unittest("file_access_ext_stub_impl_test") { "${user_file_service_path}/interfaces/inner_api/file_access/include", "${user_file_service_path}/interfaces/kits/js/src/common", "${user_file_service_path}/utils", - "//third_party/googletest/googlemock/include/gmock", "mock", ] @@ -298,8 +297,6 @@ ohos_unittest("file_access_ext_stub_impl_test") { "file_access_ext_stub_impl_test.cpp", ] - deps = [ "//third_party/googletest:gmock_main" ] - external_deps = [ "ability_base:zuri", "ability_runtime:app_context", @@ -307,6 +304,8 @@ ohos_unittest("file_access_ext_stub_impl_test") { "ability_runtime:napi_common", "ability_runtime:runtime", "c_utils:utils", + "googletest:gmock_main", + "googletest:gtest_main", "hilog:libhilog", "hitrace:hitrace_meter", "ipc:ipc_core", @@ -333,7 +332,6 @@ ohos_unittest("file_access_service_proxy_test") { "${user_file_service_path}/services/native/file_access_service/include", "${user_file_service_path}/interfaces/kits/js/src/common", "${user_file_service_path}/utils", - "//third_party/googletest/googlemock/include/gmock", "mock", ] @@ -344,17 +342,14 @@ ohos_unittest("file_access_service_proxy_test") { "mock/service_registry_mock.cpp", ] - deps = [ - "//third_party/googletest:gmock_main", - "//third_party/googletest:gtest_main", - ] - external_deps = [ "ability_base:want", "ability_base:zuri", "ability_runtime:ability_manager", "bundle_framework:appexecfwk_core", "c_utils:utils", + "googletest:gmock_main", + "googletest:gtest_main", "hilog:libhilog", "hitrace:hitrace_meter", "image_framework:image", @@ -388,7 +383,6 @@ ohos_unittest("js_file_access_ext_ability_test") { "${user_file_service_path}/interfaces/kits/js/src/common", "${user_file_service_path}/services/native/file_access_service/include", "${user_file_service_path}/utils", - "//third_party/googletest/googlemock/include/gmock", "mock", ] @@ -399,11 +393,7 @@ ohos_unittest("js_file_access_ext_ability_test") { "mock/js_native_api_mock.cpp", ] - deps = [ - "${user_file_service_path}/interfaces/inner_api/file_access:file_access_extension_ability_kit", - "//third_party/googletest:gmock_main", - "//third_party/googletest:gtest_main", - ] + deps = [ "${user_file_service_path}/interfaces/inner_api/file_access:file_access_extension_ability_kit" ] external_deps = [ "ability_base:want", @@ -415,6 +405,8 @@ ohos_unittest("js_file_access_ext_ability_test") { "access_token:libaccesstoken_sdk", "bundle_framework:appexecfwk_core", "c_utils:utils", + "googletest:gmock_main", + "googletest:gtest_main", "hilog:libhilog", "hitrace:hitrace_meter", "init:libbegetutil", diff --git a/test/unittest/file_access_service_proxy_test.cpp b/test/unittest/file_access_service_proxy_test.cpp index 72af1e088208df5470e974b45af85fa58184e543..8df02136e2f805918098b19bc82813eb8c36d73c 100644 --- a/test/unittest/file_access_service_proxy_test.cpp +++ b/test/unittest/file_access_service_proxy_test.cpp @@ -25,6 +25,7 @@ #include "file_access_service_mock.h" #include "if_system_ability_manager_mock.h" #include "iservice_registry.h" +#include "message_parcel_mock.h" int32_t OHOS::SystemAbilityLoadCallbackStub::OnRemoteRequest(unsigned int, OHOS::MessageParcel&, OHOS::MessageParcel&, OHOS::MessageOption&) @@ -53,25 +54,50 @@ public: MOCK_METHOD0(AsObject, sptr()); }; +class AbilityConnectionMock : public OHOS::AAFwk::IAbilityConnection { +public: + AbilityConnectionMock() = default; + ~AbilityConnectionMock() = default; +public: + void OnAbilityConnectDone(const AppExecFwk::ElementName&, const sptr&, int) override {} + void OnAbilityDisconnectDone(const AppExecFwk::ElementName&, int) override {} + MOCK_METHOD0(AsObject, sptr()); +}; + +class TestObject : public IRemoteBroker { +public: + DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.FileAccessFwk.TestObject"); +}; + +class RemoteObjectMock : public IRemoteStub { +public: + RemoteObjectMock() = default; + ~RemoteObjectMock() = default; +}; + class FileAccessServiceProxyTest : public testing::Test { public: static void SetUpTestCase(void) { Assistant::ins_ = insMoc; + MessageParcelMock::messageParcel = msg; SystemAbilityManagerClient::GetInstance().systemAbilityManager_ = sptr(samgr.get()); } static void TearDownTestCase() { insMoc = nullptr; + msg = nullptr; samgr = nullptr; impl = nullptr; Assistant::ins_ = nullptr; + MessageParcelMock::messageParcel = nullptr; SystemAbilityManagerClient::GetInstance().systemAbilityManager_ = nullptr; } void SetUp() {} void TearDown() {} public: static inline shared_ptr insMoc = make_shared(); + static inline shared_ptr msg = make_shared(); static inline sptr impl = sptr(new FileAccessServiceMock()); static inline shared_ptr samgr = make_shared(); }; @@ -170,33 +196,51 @@ HWTEST_F(FileAccessServiceProxyTest, file_access_service_proxy_OnChange_0000, te try { shared_ptr proxy = make_shared(impl); - Uri uri(""); - NotifyType notifyType = NotifyType::NOTIFY_ADD; - EXPECT_CALL(*insMoc, Bool()).WillOnce(Return(false)); - auto result = proxy->OnChange(uri, notifyType); + EXPECT_CALL(*msg, WriteInterfaceToken(_)).WillOnce(Return(false)); + auto result = proxy->OnChange(Uri(""), NotifyType::NOTIFY_ADD); EXPECT_EQ(result, E_IPCS); - EXPECT_CALL(*insMoc, Bool()).WillOnce(Return(true)).WillOnce(Return(false)); - result = proxy->OnChange(uri, notifyType); + + EXPECT_CALL(*msg, WriteInterfaceToken(_)).WillOnce(Return(true)); + EXPECT_CALL(*msg, WriteParcelable(_)).WillOnce(Return(false)); + result = proxy->OnChange(Uri(""), NotifyType::NOTIFY_ADD); EXPECT_EQ(result, E_IPCS); - EXPECT_CALL(*insMoc, Bool()).WillOnce(Return(true)).WillOnce(Return(true)).WillOnce(Return(false)); - result = proxy->OnChange(uri, notifyType); + + EXPECT_CALL(*msg, WriteInterfaceToken(_)).WillOnce(Return(true)); + EXPECT_CALL(*msg, WriteParcelable(_)).WillOnce(Return(true)); + EXPECT_CALL(*msg, WriteInt32(_)).WillOnce(Return(false)); + result = proxy->OnChange(Uri(""), NotifyType::NOTIFY_ADD); EXPECT_EQ(result, E_IPCS); - EXPECT_CALL(*insMoc, Bool()).WillOnce(Return(true)).WillOnce(Return(true)).WillOnce(Return(true)); + + EXPECT_CALL(*msg, WriteInterfaceToken(_)).WillOnce(Return(true)); + EXPECT_CALL(*msg, WriteParcelable(_)).WillOnce(Return(true)); + EXPECT_CALL(*msg, WriteInt32(_)).WillOnce(Return(true)); EXPECT_CALL(*impl, SendRequest(_, _, _, _)).WillOnce(Return(E_URIS)); - result = proxy->OnChange(uri, notifyType); + result = proxy->OnChange(Uri(""), NotifyType::NOTIFY_ADD); EXPECT_EQ(result, E_URIS); - EXPECT_CALL(*insMoc, Bool()).WillOnce(Return(true)).WillOnce(Return(true)).WillOnce(Return(true)) - .WillOnce(Return(false)); - EXPECT_CALL(*insMoc, Int()).WillOnce(Return(ERR_OK)); + + EXPECT_CALL(*msg, WriteInterfaceToken(_)).WillOnce(Return(true)); + EXPECT_CALL(*msg, WriteParcelable(_)).WillOnce(Return(true)); + EXPECT_CALL(*msg, WriteInt32(_)).WillOnce(Return(true)); EXPECT_CALL(*impl, SendRequest(_, _, _, _)).WillOnce(Return(ERR_OK)); - result = proxy->OnChange(uri, notifyType); - EXPECT_EQ(result, ERR_OK); - EXPECT_CALL(*insMoc, Bool()).WillOnce(Return(true)).WillOnce(Return(true)).WillOnce(Return(true)) - .WillOnce(Return(true)); - EXPECT_CALL(*insMoc, Int()).WillOnce(Return(E_IPCS)); + EXPECT_CALL(*msg, ReadInt32(_)).WillOnce(Return(false)); + result = proxy->OnChange(Uri(""), NotifyType::NOTIFY_ADD); + EXPECT_EQ(result, E_IPCS); + + EXPECT_CALL(*msg, WriteInterfaceToken(_)).WillOnce(Return(true)); + EXPECT_CALL(*msg, WriteParcelable(_)).WillOnce(Return(true)); + EXPECT_CALL(*msg, WriteInt32(_)).WillOnce(Return(true)); EXPECT_CALL(*impl, SendRequest(_, _, _, _)).WillOnce(Return(ERR_OK)); - result = proxy->OnChange(uri, notifyType); + EXPECT_CALL(*msg, ReadInt32(_)).WillOnce(Return(true)); + result = proxy->OnChange(Uri(""), NotifyType::NOTIFY_ADD); EXPECT_EQ(result, E_IPCS); + + EXPECT_CALL(*msg, WriteInterfaceToken(_)).WillOnce(Return(true)); + EXPECT_CALL(*msg, WriteParcelable(_)).WillOnce(Return(true)); + EXPECT_CALL(*msg, WriteInt32(_)).WillOnce(Return(true)); + EXPECT_CALL(*impl, SendRequest(_, _, _, _)).WillOnce(Return(ERR_OK)); + EXPECT_CALL(*msg, ReadInt32(_)).WillOnce(DoAll(SetArgReferee<0>(ERR_OK), Return(true))); + result = proxy->OnChange(Uri(""), NotifyType::NOTIFY_ADD); + EXPECT_EQ(result, ERR_OK); } catch (...) { GTEST_LOG_(ERROR) << "FileAccessServiceProxyTest occurs an exception."; } @@ -222,46 +266,146 @@ HWTEST_F(FileAccessServiceProxyTest, file_access_service_proxy_RegisterNotify_00 bool notifyForDescendants = false; shared_ptr info = nullptr; sptr observer = sptr(new IFileAccessObserverMock()); - EXPECT_CALL(*insMoc, Bool()).WillOnce(Return(false)); + EXPECT_CALL(*msg, WriteInterfaceToken(_)).WillOnce(Return(false)); auto result = proxy->RegisterNotify(uri, notifyForDescendants, observer, info); EXPECT_EQ(result, E_IPCS); - EXPECT_CALL(*insMoc, Bool()).WillOnce(Return(true)).WillOnce(Return(false)); + + EXPECT_CALL(*msg, WriteInterfaceToken(_)).WillOnce(Return(true)); + EXPECT_CALL(*msg, WriteParcelable(_)).WillOnce(Return(false)); result = proxy->RegisterNotify(uri, notifyForDescendants, observer, info); EXPECT_EQ(result, E_IPCS); - EXPECT_CALL(*insMoc, Bool()).WillOnce(Return(true)).WillOnce(Return(true)).WillOnce(Return(false)); + + sptr obs = nullptr; + EXPECT_CALL(*msg, WriteInterfaceToken(_)).WillOnce(Return(true)); + EXPECT_CALL(*msg, WriteParcelable(_)).WillOnce(Return(true)); + result = proxy->RegisterNotify(uri, notifyForDescendants, obs, info); + EXPECT_EQ(result, E_IPCS); + + EXPECT_CALL(*msg, WriteInterfaceToken(_)).WillOnce(Return(true)); + EXPECT_CALL(*msg, WriteParcelable(_)).WillOnce(Return(true)); EXPECT_CALL(*observer, AsObject()).WillOnce(Return(nullptr)); + EXPECT_CALL(*msg, WriteRemoteObject(An&>())).WillOnce(Return(false)); result = proxy->RegisterNotify(uri, notifyForDescendants, observer, info); EXPECT_EQ(result, E_IPCS); - EXPECT_CALL(*insMoc, Bool()).WillOnce(Return(true)).WillOnce(Return(true)).WillOnce(Return(true)) - .WillOnce(Return(false)); + + EXPECT_CALL(*msg, WriteInterfaceToken(_)).WillOnce(Return(true)); + EXPECT_CALL(*msg, WriteParcelable(_)).WillOnce(Return(true)); EXPECT_CALL(*observer, AsObject()).WillOnce(Return(nullptr)); + EXPECT_CALL(*msg, WriteRemoteObject(An&>())).WillOnce(Return(true)); + EXPECT_CALL(*msg, WriteBool(_)).WillOnce(Return(false)); result = proxy->RegisterNotify(uri, notifyForDescendants, observer, info); EXPECT_EQ(result, E_IPCS); - EXPECT_CALL(*insMoc, Bool()).WillOnce(Return(true)).WillOnce(Return(true)).WillOnce(Return(true)) - .WillOnce(Return(true)).WillOnce(Return(true)).WillOnce(Return(true)); + + EXPECT_CALL(*msg, WriteInterfaceToken(_)).WillOnce(Return(true)); + EXPECT_CALL(*msg, WriteParcelable(_)).WillOnce(Return(true)); EXPECT_CALL(*observer, AsObject()).WillOnce(Return(nullptr)); + EXPECT_CALL(*msg, WriteRemoteObject(An&>())).WillOnce(Return(true)); + EXPECT_CALL(*msg, WriteBool(_)).WillOnce(Return(true)); + result = proxy->RegisterNotify(uri, notifyForDescendants, observer, info); + EXPECT_EQ(result, E_GETINFO); + } catch (...) { + GTEST_LOG_(ERROR) << "FileAccessServiceProxyTest occurs an exception."; + } + GTEST_LOG_(INFO) << "FileAccessServiceProxyTest-end file_access_service_proxy_RegisterNotify_0000"; +} + +/** + * @tc.number: user_file_service_file_access_service_proxy_RegisterNotify_0100 + * @tc.name: file_access_service_proxy_RegisterNotify_0100 + * @tc.desc: Test function of RegisterNotify interface for ERROR. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 3 + * @tc.require: issuesI8Y05B + */ +HWTEST_F(FileAccessServiceProxyTest, file_access_service_proxy_RegisterNotify_0100, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "FileAccessServiceProxyTest-begin file_access_service_proxy_RegisterNotify_0100"; + try { + shared_ptr proxy = make_shared(impl); + + Uri uri(""); + bool notifyForDescendants = false; + shared_ptr info = make_shared(); + sptr observer = sptr(new IFileAccessObserverMock()); + EXPECT_CALL(*msg, WriteInterfaceToken(_)).WillOnce(Return(true)); + EXPECT_CALL(*msg, WriteParcelable(_)).WillOnce(Return(true)).WillOnce(Return(false)); + EXPECT_CALL(*observer, AsObject()).WillOnce(Return(nullptr)); + EXPECT_CALL(*msg, WriteRemoteObject(An&>())).WillOnce(Return(true)); + EXPECT_CALL(*msg, WriteBool(_)).WillOnce(Return(true)); + auto result = proxy->RegisterNotify(uri, notifyForDescendants, observer, info); + EXPECT_EQ(result, E_IPCS); + + EXPECT_CALL(*msg, WriteInterfaceToken(_)).WillOnce(Return(true)); + EXPECT_CALL(*msg, WriteParcelable(_)).WillOnce(Return(true)).WillOnce(Return(true)); + EXPECT_CALL(*observer, AsObject()).WillOnce(Return(nullptr)); + EXPECT_CALL(*msg, WriteRemoteObject(An&>())).WillOnce(Return(true)) + .WillOnce(Return(true)); + EXPECT_CALL(*msg, WriteBool(_)).WillOnce(Return(true)); EXPECT_CALL(*impl, SendRequest(_, _, _, _)).WillOnce(Return(E_URIS)); - shared_ptr info2 = make_shared(); - result = proxy->RegisterNotify(uri, notifyForDescendants, observer, info2); + result = proxy->RegisterNotify(uri, notifyForDescendants, observer, info); EXPECT_EQ(result, E_URIS); - EXPECT_CALL(*insMoc, Bool()).WillOnce(Return(true)).WillOnce(Return(true)).WillOnce(Return(true)) - .WillOnce(Return(true)).WillOnce(Return(true)).WillOnce(Return(true)).WillOnce(Return(true)); - EXPECT_CALL(*insMoc, Int()).WillOnce(Return(ERR_OK)); + + EXPECT_CALL(*msg, WriteInterfaceToken(_)).WillOnce(Return(true)); + EXPECT_CALL(*msg, WriteParcelable(_)).WillOnce(Return(true)).WillOnce(Return(true)); EXPECT_CALL(*observer, AsObject()).WillOnce(Return(nullptr)); + EXPECT_CALL(*msg, WriteRemoteObject(An&>())).WillOnce(Return(true)) + .WillOnce(Return(true)); + EXPECT_CALL(*msg, WriteBool(_)).WillOnce(Return(true)); EXPECT_CALL(*impl, SendRequest(_, _, _, _)).WillOnce(Return(ERR_OK)); - result = proxy->RegisterNotify(uri, notifyForDescendants, observer, info2); - EXPECT_EQ(result, ERR_OK); - EXPECT_CALL(*insMoc, Bool()).WillOnce(Return(true)).WillOnce(Return(true)).WillOnce(Return(true)) - .WillOnce(Return(true)).WillOnce(Return(true)).WillOnce(Return(true)).WillOnce(Return(true)); - EXPECT_CALL(*insMoc, Int()).WillOnce(Return(E_IPCS)); + EXPECT_CALL(*msg, ReadInt32(_)).WillOnce(Return(false)); + result = proxy->RegisterNotify(uri, notifyForDescendants, observer, info); + EXPECT_EQ(result, E_IPCS); + } catch (...) { + GTEST_LOG_(ERROR) << "FileAccessServiceProxyTest occurs an exception."; + } + GTEST_LOG_(INFO) << "FileAccessServiceProxyTest-end file_access_service_proxy_RegisterNotify_0100"; +} + +/** + * @tc.number: user_file_service_file_access_service_proxy_RegisterNotify_0200 + * @tc.name: file_access_service_proxy_RegisterNotify_0200 + * @tc.desc: Test function of RegisterNotify interface for ERROR. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 3 + * @tc.require: issuesI8Y05B + */ +HWTEST_F(FileAccessServiceProxyTest, file_access_service_proxy_RegisterNotify_0200, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "FileAccessServiceProxyTest-begin file_access_service_proxy_RegisterNotify_0100"; + try { + shared_ptr proxy = make_shared(impl); + + Uri uri(""); + bool notifyForDescendants = false; + shared_ptr info = make_shared(); + sptr observer = sptr(new IFileAccessObserverMock()); + EXPECT_CALL(*msg, WriteInterfaceToken(_)).WillOnce(Return(true)); + EXPECT_CALL(*msg, WriteParcelable(_)).WillOnce(Return(true)).WillOnce(Return(true)); EXPECT_CALL(*observer, AsObject()).WillOnce(Return(nullptr)); + EXPECT_CALL(*msg, WriteRemoteObject(An&>())).WillOnce(Return(true)) + .WillOnce(Return(true)); + EXPECT_CALL(*msg, WriteBool(_)).WillOnce(Return(true)); EXPECT_CALL(*impl, SendRequest(_, _, _, _)).WillOnce(Return(ERR_OK)); - result = proxy->RegisterNotify(uri, notifyForDescendants, observer, info2); + EXPECT_CALL(*msg, ReadInt32(_)).WillOnce(Return(true)); + auto result = proxy->RegisterNotify(uri, notifyForDescendants, observer, info); EXPECT_EQ(result, E_IPCS); + + EXPECT_CALL(*msg, WriteInterfaceToken(_)).WillOnce(Return(true)); + EXPECT_CALL(*msg, WriteParcelable(_)).WillOnce(Return(true)).WillOnce(Return(true)); + EXPECT_CALL(*observer, AsObject()).WillOnce(Return(nullptr)); + EXPECT_CALL(*msg, WriteRemoteObject(An&>())).WillOnce(Return(true)) + .WillOnce(Return(true)); + EXPECT_CALL(*msg, WriteBool(_)).WillOnce(Return(true)); + EXPECT_CALL(*impl, SendRequest(_, _, _, _)).WillOnce(Return(ERR_OK)); + EXPECT_CALL(*msg, ReadInt32(_)).WillOnce(DoAll(SetArgReferee<0>(ERR_OK), Return(true))); + result = proxy->RegisterNotify(uri, notifyForDescendants, observer, info); + EXPECT_EQ(result, ERR_OK); } catch (...) { GTEST_LOG_(ERROR) << "FileAccessServiceProxyTest occurs an exception."; } - GTEST_LOG_(INFO) << "FileAccessServiceProxyTest-end file_access_service_proxy_RegisterNotify_0000"; + GTEST_LOG_(INFO) << "FileAccessServiceProxyTest-end file_access_service_proxy_RegisterNotify_0200"; } /** @@ -284,16 +428,21 @@ HWTEST_F(FileAccessServiceProxyTest, file_access_service_proxy_UnregisterNotifyI EXPECT_CALL(*impl, SendRequest(_, _, _, _)).WillOnce(Return(E_URIS)); auto result = proxy->UnregisterNotifyInternal(data); EXPECT_EQ(result, E_URIS); + EXPECT_CALL(*impl, SendRequest(_, _, _, _)).WillOnce(Return(ERR_OK)); - EXPECT_CALL(*insMoc, Bool()).WillOnce(Return(false)); - EXPECT_CALL(*insMoc, Int()).WillOnce(Return(ERR_OK)); + EXPECT_CALL(*msg, ReadInt32(_)).WillOnce(Return(false)); result = proxy->UnregisterNotifyInternal(data); - EXPECT_EQ(result, ERR_OK); + EXPECT_EQ(result, E_IPCS); + EXPECT_CALL(*impl, SendRequest(_, _, _, _)).WillOnce(Return(ERR_OK)); - EXPECT_CALL(*insMoc, Bool()).WillOnce(Return(true)); - EXPECT_CALL(*insMoc, Int()).WillOnce(Return(E_IPCS)); + EXPECT_CALL(*msg, ReadInt32(_)).WillOnce(Return(true)); result = proxy->UnregisterNotifyInternal(data); EXPECT_EQ(result, E_IPCS); + + EXPECT_CALL(*impl, SendRequest(_, _, _, _)).WillOnce(Return(ERR_OK)); + EXPECT_CALL(*msg, ReadInt32(_)).WillOnce(DoAll(SetArgReferee<0>(ERR_OK), Return(true))); + result = proxy->UnregisterNotifyInternal(data); + EXPECT_EQ(result, ERR_OK); } catch (...) { GTEST_LOG_(ERROR) << "FileAccessServiceProxyTest occurs an exception."; } @@ -318,35 +467,301 @@ HWTEST_F(FileAccessServiceProxyTest, file_access_service_proxy_UnregisterNotify_ Uri uri(""); sptr observer = nullptr; shared_ptr info = nullptr; - EXPECT_CALL(*insMoc, Bool()).WillOnce(Return(false)); + EXPECT_CALL(*msg, WriteInterfaceToken(_)).WillOnce(Return(false)); auto result = proxy->UnregisterNotify(uri, observer, info); EXPECT_EQ(result, E_IPCS); - EXPECT_CALL(*insMoc, Bool()).WillOnce(Return(true)).WillOnce(Return(false)); + + EXPECT_CALL(*msg, WriteInterfaceToken(_)).WillOnce(Return(true)); + EXPECT_CALL(*msg, WriteParcelable(_)).WillOnce(Return(false)); result = proxy->UnregisterNotify(uri, observer, info); EXPECT_EQ(result, E_IPCS); - EXPECT_CALL(*insMoc, Bool()).WillOnce(Return(true)).WillOnce(Return(true)).WillOnce(Return(false)); + + EXPECT_CALL(*msg, WriteInterfaceToken(_)).WillOnce(Return(true)); + EXPECT_CALL(*msg, WriteParcelable(_)).WillOnce(Return(true)); + EXPECT_CALL(*msg, WriteBool(_)).WillOnce(Return(false)); result = proxy->UnregisterNotify(uri, observer, info); EXPECT_EQ(result, E_IPCS); + + EXPECT_CALL(*msg, WriteInterfaceToken(_)).WillOnce(Return(true)); + EXPECT_CALL(*msg, WriteParcelable(_)).WillOnce(Return(true)); + EXPECT_CALL(*msg, WriteBool(_)).WillOnce(Return(true)); + result = proxy->UnregisterNotify(uri, observer, info); + EXPECT_EQ(result, E_GETINFO); + observer = sptr(new IFileAccessObserverMock()); - EXPECT_CALL(*insMoc, Bool()).WillOnce(Return(true)).WillOnce(Return(true)).WillOnce(Return(false)); + EXPECT_CALL(*msg, WriteInterfaceToken(_)).WillOnce(Return(true)); + EXPECT_CALL(*msg, WriteParcelable(_)).WillOnce(Return(true)); + EXPECT_CALL(*msg, WriteBool(_)).WillOnce(Return(false)); result = proxy->UnregisterNotify(uri, observer, info); EXPECT_EQ(result, E_IPCS); - EXPECT_CALL(*insMoc, Bool()).WillOnce(Return(true)).WillOnce(Return(true)).WillOnce(Return(true)) - .WillOnce(Return(false)); + + EXPECT_CALL(*msg, WriteInterfaceToken(_)).WillOnce(Return(true)); + EXPECT_CALL(*msg, WriteParcelable(_)).WillOnce(Return(true)); + EXPECT_CALL(*msg, WriteBool(_)).WillOnce(Return(true)); EXPECT_CALL(*observer, AsObject()).WillOnce(Return(nullptr)); + EXPECT_CALL(*msg, WriteRemoteObject(An&>())).WillOnce(Return(false)); result = proxy->UnregisterNotify(uri, observer, info); EXPECT_EQ(result, E_IPCS); - EXPECT_CALL(*insMoc, Bool()).WillOnce(Return(true)).WillOnce(Return(true)).WillOnce(Return(true)) - .WillOnce(Return(false)); + + EXPECT_CALL(*msg, WriteInterfaceToken(_)).WillOnce(Return(true)); + EXPECT_CALL(*msg, WriteParcelable(_)).WillOnce(Return(true)); + EXPECT_CALL(*msg, WriteBool(_)).WillOnce(Return(true)); EXPECT_CALL(*observer, AsObject()).WillOnce(Return(nullptr)); + EXPECT_CALL(*msg, WriteRemoteObject(An&>())).WillOnce(Return(true)); result = proxy->UnregisterNotify(uri, observer, info); - EXPECT_EQ(result, E_IPCS); + EXPECT_EQ(result, E_GETINFO); } catch (...) { GTEST_LOG_(ERROR) << "FileAccessServiceProxyTest occurs an exception."; } GTEST_LOG_(INFO) << "FileAccessServiceProxyTest-end file_access_service_proxy_UnregisterNotify_0000"; } +/** + * @tc.number: user_file_service_file_access_service_proxy_ConnectFileExtAbility_0000 + * @tc.name: file_access_service_proxy_ConnectFileExtAbility_0000 + * @tc.desc: Test function of ConnectFileExtAbility interface for ERROR. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 3 + * @tc.require: issuesI8Y05B + */ +HWTEST_F(FileAccessServiceProxyTest, file_access_service_proxy_ConnectFileExtAbility_0000, + testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "FileAccessServiceProxyTest-begin file_access_service_proxy_ConnectFileExtAbility_0000"; + try { + shared_ptr proxy = make_shared(impl); + AAFwk::Want want; + sptr connection = nullptr; + + EXPECT_CALL(*msg, WriteInterfaceToken(_)).WillOnce(Return(false)); + auto result = proxy->ConnectFileExtAbility(want, connection); + EXPECT_EQ(result, E_IPCS); + + EXPECT_CALL(*msg, WriteInterfaceToken(_)).WillOnce(Return(true)); + EXPECT_CALL(*msg, WriteParcelable(_)).WillOnce(Return(false)); + result = proxy->ConnectFileExtAbility(want, connection); + EXPECT_EQ(result, E_IPCS); + + EXPECT_CALL(*msg, WriteInterfaceToken(_)).WillOnce(Return(true)); + EXPECT_CALL(*msg, WriteParcelable(_)).WillOnce(Return(true)); + result = proxy->ConnectFileExtAbility(want, connection); + EXPECT_EQ(result, E_GETINFO); + + connection = sptr(new AbilityConnectionMock()); + EXPECT_CALL(*msg, WriteInterfaceToken(_)).WillOnce(Return(true)); + EXPECT_CALL(*msg, WriteParcelable(_)).WillOnce(Return(true)); + EXPECT_CALL(*connection, AsObject()).WillOnce(Return(nullptr)); + result = proxy->ConnectFileExtAbility(want, connection); + EXPECT_EQ(result, E_GETINFO); + + auto obj = sptr(new (std::nothrow) RemoteObjectMock()); + EXPECT_CALL(*msg, WriteInterfaceToken(_)).WillOnce(Return(true)); + EXPECT_CALL(*msg, WriteParcelable(_)).WillOnce(Return(true)); + EXPECT_CALL(*connection, AsObject()).WillOnce(Return(obj)).WillOnce(Return(obj)); + EXPECT_CALL(*msg, WriteRemoteObject(An&>())).WillOnce(Return(false)); + result = proxy->ConnectFileExtAbility(want, connection); + EXPECT_EQ(result, E_IPCS); + } catch (...) { + GTEST_LOG_(ERROR) << "FileAccessServiceProxyTest occurs an exception."; + } + GTEST_LOG_(INFO) << "FileAccessServiceProxyTest-end file_access_service_proxy_ConnectFileExtAbility_0000"; +} + +/** + * @tc.number: user_file_service_file_access_service_proxy_ConnectFileExtAbility_0100 + * @tc.name: file_access_service_proxy_ConnectFileExtAbility_0100 + * @tc.desc: Test function of ConnectFileExtAbility interface for ERROR. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 3 + * @tc.require: issuesI8Y05B + */ +HWTEST_F(FileAccessServiceProxyTest, file_access_service_proxy_ConnectFileExtAbility_0100, + testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "FileAccessServiceProxyTest-begin file_access_service_proxy_ConnectFileExtAbility_0000"; + try { + shared_ptr proxy = make_shared(impl); + AAFwk::Want want; + sptr connection = sptr(new AbilityConnectionMock()); + auto obj = sptr(new (std::nothrow) RemoteObjectMock()); + + EXPECT_CALL(*msg, WriteInterfaceToken(_)).WillOnce(Return(true)); + EXPECT_CALL(*msg, WriteParcelable(_)).WillOnce(Return(true)); + EXPECT_CALL(*connection, AsObject()).WillOnce(Return(obj)).WillOnce(Return(nullptr)); + EXPECT_CALL(*msg, WriteRemoteObject(An&>())).WillOnce(Return(true)); + EXPECT_CALL(*impl, SendRequest(_, _, _, _)).WillOnce(Return(E_IPCS)); + auto result = proxy->ConnectFileExtAbility(want, connection); + EXPECT_EQ(result, E_IPCS); + + EXPECT_CALL(*msg, WriteInterfaceToken(_)).WillOnce(Return(true)); + EXPECT_CALL(*msg, WriteParcelable(_)).WillOnce(Return(true)); + EXPECT_CALL(*connection, AsObject()).WillOnce(Return(obj)).WillOnce(Return(nullptr)); + EXPECT_CALL(*msg, WriteRemoteObject(An&>())).WillOnce(Return(true)); + EXPECT_CALL(*impl, SendRequest(_, _, _, _)).WillOnce(Return(ERR_OK)); + EXPECT_CALL(*msg, ReadInt32(_)).WillOnce(DoAll(Return(false))); + result = proxy->ConnectFileExtAbility(want, connection); + EXPECT_EQ(result, E_IPCS); + + EXPECT_CALL(*msg, WriteInterfaceToken(_)).WillOnce(Return(true)); + EXPECT_CALL(*msg, WriteParcelable(_)).WillOnce(Return(true)); + EXPECT_CALL(*connection, AsObject()).WillOnce(Return(obj)).WillOnce(Return(nullptr)); + EXPECT_CALL(*msg, WriteRemoteObject(An&>())).WillOnce(Return(true)); + EXPECT_CALL(*impl, SendRequest(_, _, _, _)).WillOnce(Return(ERR_OK)); + EXPECT_CALL(*msg, ReadInt32(_)).WillOnce(DoAll(SetArgReferee<0>(E_IPCS), Return(true))); + result = proxy->ConnectFileExtAbility(want, connection); + EXPECT_EQ(result, E_IPCS); + + EXPECT_CALL(*msg, WriteInterfaceToken(_)).WillOnce(Return(true)); + EXPECT_CALL(*msg, WriteParcelable(_)).WillOnce(Return(true)); + EXPECT_CALL(*connection, AsObject()).WillOnce(Return(obj)).WillOnce(Return(nullptr)); + EXPECT_CALL(*msg, WriteRemoteObject(An&>())).WillOnce(Return(true)); + EXPECT_CALL(*impl, SendRequest(_, _, _, _)).WillOnce(Return(ERR_OK)); + EXPECT_CALL(*msg, ReadInt32(_)).WillOnce(DoAll(SetArgReferee<0>(ERR_OK), Return(true))); + result = proxy->ConnectFileExtAbility(want, connection); + EXPECT_EQ(result, ERR_OK); + } catch (...) { + GTEST_LOG_(ERROR) << "FileAccessServiceProxyTest occurs an exception."; + } + GTEST_LOG_(INFO) << "FileAccessServiceProxyTest-end file_access_service_proxy_ConnectFileExtAbility_0100"; +} + +/** + * @tc.number: user_file_service_file_access_service_proxy_DisConnectFileExtAbility_0000 + * @tc.name: file_access_service_proxy_DisConnectFileExtAbility_0000 + * @tc.desc: Test function of DisConnectFileExtAbility interface for ERROR. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 3 + * @tc.require: issuesI8Y05B + */ +HWTEST_F(FileAccessServiceProxyTest, file_access_service_proxy_DisConnectFileExtAbility_0000, + testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "FileAccessServiceProxyTest-begin file_access_service_proxy_DisConnectFileExtAbility_0000"; + try { + shared_ptr proxy = make_shared(impl); + sptr connection = nullptr; + + EXPECT_CALL(*msg, WriteInterfaceToken(_)).WillOnce(Return(false)); + auto result = proxy->DisConnectFileExtAbility(connection); + EXPECT_EQ(result, E_IPCS); + + EXPECT_CALL(*msg, WriteInterfaceToken(_)).WillOnce(Return(true)); + result = proxy->DisConnectFileExtAbility(connection); + EXPECT_EQ(result, E_GETINFO); + + connection = sptr(new AbilityConnectionMock()); + EXPECT_CALL(*msg, WriteInterfaceToken(_)).WillOnce(Return(true)); + EXPECT_CALL(*connection, AsObject()).WillOnce(Return(nullptr)); + result = proxy->DisConnectFileExtAbility(connection); + EXPECT_EQ(result, E_GETINFO); + + auto obj = sptr(new (std::nothrow) RemoteObjectMock()); + EXPECT_CALL(*msg, WriteInterfaceToken(_)).WillOnce(Return(true)); + EXPECT_CALL(*connection, AsObject()).WillOnce(Return(obj)).WillOnce(Return(nullptr)); + EXPECT_CALL(*msg, WriteRemoteObject(An&>())).WillOnce(Return(false)); + result = proxy->DisConnectFileExtAbility(connection); + EXPECT_EQ(result, E_IPCS); + + EXPECT_CALL(*msg, WriteInterfaceToken(_)).WillOnce(Return(true)); + EXPECT_CALL(*connection, AsObject()).WillOnce(Return(obj)).WillOnce(Return(nullptr)); + EXPECT_CALL(*msg, WriteRemoteObject(An&>())).WillOnce(Return(true)); + EXPECT_CALL(*impl, SendRequest(_, _, _, _)).WillOnce(Return(E_IPCS)); + result = proxy->DisConnectFileExtAbility(connection); + EXPECT_EQ(result, E_IPCS); + } catch (...) { + GTEST_LOG_(ERROR) << "FileAccessServiceProxyTest occurs an exception."; + } + GTEST_LOG_(INFO) << "FileAccessServiceProxyTest-end file_access_service_proxy_DisConnectFileExtAbility_0000"; +} + +/** + * @tc.number: user_file_service_file_access_service_proxy_DisConnectFileExtAbility_0100 + * @tc.name: file_access_service_proxy_DisConnectFileExtAbility_0100 + * @tc.desc: Test function of DisConnectFileExtAbility interface for ERROR. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 3 + * @tc.require: issuesI8Y05B + */ +HWTEST_F(FileAccessServiceProxyTest, file_access_service_proxy_DisConnectFileExtAbility_0100, + testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "FileAccessServiceProxyTest-begin file_access_service_proxy_DisConnectFileExtAbility_0100"; + try { + shared_ptr proxy = make_shared(impl); + sptr connection = sptr(new AbilityConnectionMock()); + auto obj = sptr(new (std::nothrow) RemoteObjectMock()); + + EXPECT_CALL(*msg, WriteInterfaceToken(_)).WillOnce(Return(true)); + EXPECT_CALL(*connection, AsObject()).WillOnce(Return(obj)).WillOnce(Return(nullptr)); + EXPECT_CALL(*msg, WriteRemoteObject(An&>())).WillOnce(Return(true)); + EXPECT_CALL(*impl, SendRequest(_, _, _, _)).WillOnce(Return(ERR_OK)); + EXPECT_CALL(*msg, ReadInt32(_)).WillOnce(DoAll(Return(false))); + auto result = proxy->DisConnectFileExtAbility(connection); + EXPECT_EQ(result, E_IPCS); + + EXPECT_CALL(*msg, WriteInterfaceToken(_)).WillOnce(Return(true)); + EXPECT_CALL(*connection, AsObject()).WillOnce(Return(obj)).WillOnce(Return(nullptr)); + EXPECT_CALL(*msg, WriteRemoteObject(An&>())).WillOnce(Return(true)); + EXPECT_CALL(*impl, SendRequest(_, _, _, _)).WillOnce(Return(ERR_OK)); + EXPECT_CALL(*msg, ReadInt32(_)).WillOnce(DoAll(SetArgReferee<0>(E_IPCS), Return(true))); + result = proxy->DisConnectFileExtAbility(connection); + EXPECT_EQ(result, E_IPCS); + + EXPECT_CALL(*msg, WriteInterfaceToken(_)).WillOnce(Return(true)); + EXPECT_CALL(*connection, AsObject()).WillOnce(Return(obj)).WillOnce(Return(nullptr)); + EXPECT_CALL(*msg, WriteRemoteObject(An&>())).WillOnce(Return(true)); + EXPECT_CALL(*impl, SendRequest(_, _, _, _)).WillOnce(Return(ERR_OK)); + EXPECT_CALL(*msg, ReadInt32(_)).WillOnce(DoAll(SetArgReferee<0>(ERR_OK), Return(true))); + result = proxy->DisConnectFileExtAbility(connection); + EXPECT_EQ(result, ERR_OK); + } catch (...) { + GTEST_LOG_(ERROR) << "FileAccessServiceProxyTest occurs an exception."; + } + GTEST_LOG_(INFO) << "FileAccessServiceProxyTest-end file_access_service_proxy_DisConnectFileExtAbility_0100"; +} + +/** + * @tc.number: user_file_service_file_access_service_proxy_UnregisterNotify_0100 + * @tc.name: file_access_service_proxy_UnregisterNotify_0100 + * @tc.desc: Test function of UnregisterNotify interface for ERROR. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 3 + * @tc.require: issuesI8Y05B + */ +HWTEST_F(FileAccessServiceProxyTest, file_access_service_proxy_UnregisterNotify_0100, + testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "FileAccessServiceProxyTest-begin file_access_service_proxy_UnregisterNotify_0100"; + try { + Uri uri(""); + sptr observer = nullptr; + shared_ptr proxy = make_shared(impl); + shared_ptr info = make_shared(); + + EXPECT_CALL(*msg, WriteInterfaceToken(_)).WillOnce(Return(true)); + EXPECT_CALL(*msg, WriteParcelable(_)).WillOnce(Return(true)).WillOnce(Return(false)); + EXPECT_CALL(*msg, WriteBool(_)).WillOnce(Return(true)); + auto result = proxy->UnregisterNotify(uri, observer, info); + EXPECT_EQ(result, E_IPCS); + + EXPECT_CALL(*msg, WriteInterfaceToken(_)).WillOnce(Return(true)); + EXPECT_CALL(*msg, WriteParcelable(_)).WillOnce(Return(true)).WillOnce(Return(true)); + EXPECT_CALL(*msg, WriteBool(_)).WillOnce(Return(true)); + EXPECT_CALL(*msg, WriteRemoteObject(An&>())).WillOnce(Return(true)); + EXPECT_CALL(*impl, SendRequest(_, _, _, _)).WillOnce(Return(E_IPCS)); + result = proxy->UnregisterNotify(uri, observer, info); + EXPECT_EQ(result, E_IPCS); + } catch (...) { + GTEST_LOG_(ERROR) << "FileAccessServiceProxyTest occurs an exception."; + } + GTEST_LOG_(INFO) << "FileAccessServiceProxyTest-end file_access_service_proxy_UnregisterNotify_0100"; +} + /** * @tc.number: user_file_service_file_access_service_proxy_GetExensionProxy_0000 * @tc.name: file_access_service_proxy_GetExensionProxy_0000 @@ -361,39 +776,52 @@ HWTEST_F(FileAccessServiceProxyTest, file_access_service_proxy_GetExensionProxy_ GTEST_LOG_(INFO) << "FileAccessServiceProxyTest-begin file_access_service_proxy_GetExensionProxy_0000"; try { shared_ptr proxy = make_shared(impl); - shared_ptr info = nullptr; sptr extensionProxy = nullptr; - EXPECT_CALL(*insMoc, Bool()).WillOnce(Return(false)); + + EXPECT_CALL(*msg, WriteInterfaceToken(_)).WillOnce(Return(false)); auto result = proxy->GetExtensionProxy(info, extensionProxy); EXPECT_EQ(result, E_IPCS); - EXPECT_CALL(*insMoc, Bool()).WillOnce(Return(true)); + + EXPECT_CALL(*msg, WriteInterfaceToken(_)).WillOnce(Return(true)); result = proxy->GetExtensionProxy(info, extensionProxy); EXPECT_EQ(result, E_GETINFO); + info = make_shared(); - EXPECT_CALL(*insMoc, Bool()).WillOnce(Return(true)).WillOnce(Return(false)); + EXPECT_CALL(*msg, WriteInterfaceToken(_)).WillOnce(Return(true)); + EXPECT_CALL(*msg, WriteParcelable(_)).WillOnce(Return(false)); result = proxy->GetExtensionProxy(info, extensionProxy); EXPECT_EQ(result, E_IPCS); - EXPECT_CALL(*insMoc, Bool()).WillOnce(Return(true)).WillOnce(Return(true)).WillOnce(Return(true)); + + EXPECT_CALL(*msg, WriteInterfaceToken(_)).WillOnce(Return(true)); + EXPECT_CALL(*msg, WriteParcelable(_)).WillOnce(Return(true)); + EXPECT_CALL(*msg, WriteRemoteObject(An&>())).WillOnce(Return(true)); EXPECT_CALL(*impl, SendRequest(_, _, _, _)).WillOnce(Return(E_URIS)); result = proxy->GetExtensionProxy(info, extensionProxy); EXPECT_EQ(result, E_URIS); - EXPECT_CALL(*insMoc, Bool()).WillOnce(Return(true)).WillOnce(Return(true)).WillOnce(Return(true)) - .WillOnce(Return(false)); - EXPECT_CALL(*insMoc, Int()).WillOnce(Return(ERR_OK)); + + EXPECT_CALL(*msg, WriteInterfaceToken(_)).WillOnce(Return(true)); + EXPECT_CALL(*msg, WriteParcelable(_)).WillOnce(Return(true)); + EXPECT_CALL(*msg, WriteRemoteObject(An&>())).WillOnce(Return(true)); EXPECT_CALL(*impl, SendRequest(_, _, _, _)).WillOnce(Return(ERR_OK)); + EXPECT_CALL(*msg, ReadInt32(_)).WillOnce(Return(false)); result = proxy->GetExtensionProxy(info, extensionProxy); - EXPECT_EQ(result, ERR_OK); - EXPECT_CALL(*insMoc, Bool()).WillOnce(Return(true)).WillOnce(Return(true)).WillOnce(Return(true)) - .WillOnce(Return(true)); - EXPECT_CALL(*insMoc, Int()).WillOnce(Return(E_IPCS)); + EXPECT_EQ(result, E_IPCS); + + EXPECT_CALL(*msg, WriteInterfaceToken(_)).WillOnce(Return(true)); + EXPECT_CALL(*msg, WriteParcelable(_)).WillOnce(Return(true)); + EXPECT_CALL(*msg, WriteRemoteObject(An&>())).WillOnce(Return(true)); EXPECT_CALL(*impl, SendRequest(_, _, _, _)).WillOnce(Return(ERR_OK)); + EXPECT_CALL(*msg, ReadInt32(_)).WillOnce(Return(true)); result = proxy->GetExtensionProxy(info, extensionProxy); EXPECT_EQ(result, E_IPCS); - EXPECT_CALL(*insMoc, Bool()).WillOnce(Return(true)).WillOnce(Return(true)).WillOnce(Return(true)) - .WillOnce(Return(true)); - EXPECT_CALL(*insMoc, Int()).WillOnce(Return(ERR_OK)); + + EXPECT_CALL(*msg, WriteInterfaceToken(_)).WillOnce(Return(true)); + EXPECT_CALL(*msg, WriteParcelable(_)).WillOnce(Return(true)); + EXPECT_CALL(*msg, WriteRemoteObject(An&>())).WillOnce(Return(true)); EXPECT_CALL(*impl, SendRequest(_, _, _, _)).WillOnce(Return(ERR_OK)); + EXPECT_CALL(*msg, ReadInt32(_)).WillOnce(DoAll(SetArgReferee<0>(ERR_OK), Return(true))); + EXPECT_CALL(*msg, ReadRemoteObject()).WillOnce(Return(nullptr)); result = proxy->GetExtensionProxy(info, extensionProxy); EXPECT_EQ(result, E_IPCS); } catch (...) { diff --git a/test/unittest/mock/message_parcel_mock.cpp b/test/unittest/mock/message_parcel_mock.cpp index 73951a204ee76a1f2311e8965a385e7d58a168e6..3036a04fb29f197d308fca0a36f7ad5da0432a22 100644 --- a/test/unittest/mock/message_parcel_mock.cpp +++ b/test/unittest/mock/message_parcel_mock.cpp @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -12,10 +12,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - -#include "assistant.h" -#include "message_parcel.h" -#include "hilog_wrapper.h" +#include "iremote_broker.h" +#include "message_parcel_mock.h" namespace OHOS { using namespace OHOS::FileAccessFwk; @@ -31,42 +29,91 @@ Parcelable::Parcelable(bool asRemote) bool MessageParcel::WriteInterfaceToken(std::u16string name) { - return Assistant::ins_->Bool(); + return UMessageParcel::messageParcel->WriteInterfaceToken(name); +} + +std::u16string MessageParcel::ReadInterfaceToken() +{ + return UMessageParcel::messageParcel->ReadInterfaceToken(); } bool Parcel::WriteParcelable(const Parcelable *object) { - return Assistant::ins_->Bool(); + return UMessageParcel::messageParcel->WriteParcelable(object); } bool Parcel::WriteInt32(int32_t value) { - return Assistant::ins_->Bool(); + return UMessageParcel::messageParcel->WriteInt32(value); } int32_t Parcel::ReadInt32() { - return Assistant::ins_->Bool(); + return UMessageParcel::messageParcel->ReadInt32(); } bool Parcel::ReadInt32(int32_t &value) { - value = Assistant::ins_->Int(); - return Assistant::ins_->Bool(); + return UMessageParcel::messageParcel->ReadInt32(value); } bool Parcel::WriteRemoteObject(const Parcelable *object) { - return Assistant::ins_->Bool(); + return UMessageParcel::messageParcel->WriteRemoteObject(object); } bool MessageParcel::WriteRemoteObject(const sptr &object) { - return Assistant::ins_->Bool(); + return UMessageParcel::messageParcel->WriteRemoteObject(object); +} + +sptr MessageParcel::ReadRemoteObject() +{ + return UMessageParcel::messageParcel->ReadRemoteObject(); +} + +bool Parcel::ReadBool() +{ + return UMessageParcel::messageParcel->ReadBool(); +} + +bool Parcel::ReadBool(bool &value) +{ + return UMessageParcel::messageParcel->ReadBool(value); } bool Parcel::WriteBool(bool value) { - return Assistant::ins_->Bool(); + return UMessageParcel::messageParcel->WriteBool(value); +} + +bool Parcel::WriteString(const std::string &value) +{ + return UMessageParcel::messageParcel->WriteString(value); +} + +bool Parcel::ReadString(std::string &value) +{ + return UMessageParcel::messageParcel->ReadString(value); +} + +bool Parcel::ReadStringVector(std::vector *value) +{ + return UMessageParcel::messageParcel->ReadStringVector(value); +} + +bool MessageParcel::WriteFileDescriptor(int fd) +{ + return UMessageParcel::messageParcel->WriteFileDescriptor(fd); +} + +int MessageParcel::ReadFileDescriptor() +{ + return UMessageParcel::messageParcel->ReadFileDescriptor(); +} + +bool Parcel::ReadUint32(uint32_t &value) +{ + return UMessageParcel::messageParcel->ReadUint32(value); } } // namespace OHOS \ No newline at end of file diff --git a/test/unittest/mock/message_parcel_mock.h b/test/unittest/mock/message_parcel_mock.h new file mode 100644 index 0000000000000000000000000000000000000000..9cff27dc73e8914135768bb7b5d10bc1b88e1f8b --- /dev/null +++ b/test/unittest/mock/message_parcel_mock.h @@ -0,0 +1,74 @@ +/* + * Copyright (C) 2024 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_FILEMGMT_UFS_MESSAGE_PARCEL_MOCK_H +#define OHOS_FILEMGMT_UFS_MESSAGE_PARCEL_MOCK_H + +#include +#include +#include + +#include "message_parcel.h" +#include "iremote_broker.h" + +namespace OHOS::FileAccessFwk { +class UMessageParcel { +public: + virtual ~UMessageParcel() = default; +public: + virtual bool WriteInterfaceToken(std::u16string name) = 0; + virtual std::u16string ReadInterfaceToken() = 0; + virtual bool WriteParcelable(const Parcelable *object) = 0; + virtual bool WriteInt32(int32_t value) = 0; + virtual int32_t ReadInt32() = 0; + virtual bool ReadInt32(int32_t &value) = 0; + virtual bool WriteRemoteObject(const Parcelable *object) = 0; + virtual bool WriteRemoteObject(const sptr &object) = 0; + virtual sptr ReadRemoteObject() = 0; + virtual bool ReadBool(); + virtual bool ReadBool(bool &value) = 0; + virtual bool WriteBool(bool value) = 0; + virtual bool WriteString(const std::string &value) = 0; + virtual bool WriteFileDescriptor(int fd) = 0; + virtual bool ReadString(std::string &value) = 0; + virtual int ReadFileDescriptor() = 0; + virtual bool ReadStringVector(std::vector *value) = 0; + virtual bool ReadUint32(uint32_t &value) = 0; +public: + static inline std::shared_ptr messageParcel = nullptr; +}; + +class MessageParcelMock : public UMessageParcel { +public: + MOCK_METHOD1(WriteInterfaceToken, bool(std::u16string name)); + MOCK_METHOD0(ReadInterfaceToken, std::u16string()); + MOCK_METHOD1(WriteParcelable, bool(const Parcelable *object)); + MOCK_METHOD1(WriteInt32, bool(int32_t value)); + MOCK_METHOD0(ReadInt32, int32_t()); + MOCK_METHOD1(ReadInt32, bool(int32_t &value)); + MOCK_METHOD1(WriteRemoteObject, bool(const Parcelable *object)); + MOCK_METHOD1(WriteRemoteObject, bool(const sptr &object)); + MOCK_METHOD0(ReadRemoteObject, sptr()); + MOCK_METHOD0(ReadBool, bool()); + MOCK_METHOD1(ReadBool, bool(bool &value)); + MOCK_METHOD1(WriteBool, bool(bool value)); + MOCK_METHOD1(WriteString, bool(const std::string &value)); + MOCK_METHOD1(WriteFileDescriptor, bool(int fd)); + MOCK_METHOD1(ReadString, bool(std::string &value)); + MOCK_METHOD0(ReadFileDescriptor, int()); + MOCK_METHOD1(ReadStringVector, bool(std::vector *value)); + MOCK_METHOD1(ReadUint32, bool(uint32_t &value)); +}; +} // namespace OHOS::FileAccessFwk +#endif // OHOS_FILEMGMT_UFS_MESSAGE_PARCEL_MOCK_H \ No newline at end of file