From f96c00aa66306ae3e8c232f4647c749303533325 Mon Sep 17 00:00:00 2001 From: wangpggg Date: Thu, 18 Jul 2024 16:35:51 +0800 Subject: [PATCH] update sptr pointer usage Signed-off-by: wangpeng --- .../src/file_access_service.cpp | 6 +- .../external_file_access_fuzzer.cpp | 5 +- .../externalfileaccessaccess_fuzzer.cpp | 5 +- .../externalfileaccesscreatefile_fuzzer.cpp | 5 +- .../externalfileaccessdelete_fuzzer.cpp | 5 +- ...cessgetfileinfofromrelativepath_fuzzer.cpp | 5 +- ...nalfileaccessgetfileinfofromuri_fuzzer.cpp | 5 +- .../externalfileaccessgetroots_fuzzer.cpp | 5 +- .../externalfileaccesslistfile_fuzzer.cpp | 5 +- .../externalfileaccessmkdir_fuzzer.cpp | 5 +- .../externalfileaccessmove_fuzzer.cpp | 5 +- .../externalfileaccessopenfile_fuzzer.cpp | 5 +- .../externalfileaccessrename_fuzzer.cpp | 5 +- .../externalfileaccessscanfile_fuzzer.cpp | 5 +- .../fileaccessserviceproxy_fuzzer.cpp | 2 +- .../medialibrary_file_access_fuzzer.cpp | 5 +- test/unittest/abnormal_file_access_test.cpp | 5 +- test/unittest/external_file_access_test.cpp | 12 ++-- test/unittest/external_notify_test.cpp | 69 ++++++++++--------- .../file_access_service_proxy_test.cpp | 4 +- .../medialibrary_file_access_test_basic.cpp | 9 +-- test/unittest/mock/service_registry_mock.cpp | 2 +- 22 files changed, 97 insertions(+), 82 deletions(-) diff --git a/services/native/file_access_service/src/file_access_service.cpp b/services/native/file_access_service/src/file_access_service.cpp index 46d204ac..063c8627 100644 --- a/services/native/file_access_service/src/file_access_service.cpp +++ b/services/native/file_access_service/src/file_access_service.cpp @@ -54,7 +54,7 @@ sptr FileAccessService::GetInstance() lock_guard lock(mutex_); if (instance_ == nullptr) { - instance_ = new FileAccessService(); + instance_ = sptr(new FileAccessService()); if (instance_ == nullptr) { HILOG_ERROR("GetInstance nullptr"); return instance_; @@ -136,10 +136,10 @@ void FileAccessService::Init() { InitTimer(); if (extensionDeathRecipient_ == nullptr) { - extensionDeathRecipient_ = new ExtensionDeathRecipient(); + extensionDeathRecipient_ = sptr(new ExtensionDeathRecipient()); } if (observerDeathRecipient_ == nullptr) { - observerDeathRecipient_ = new ObserverDeathRecipient(); + observerDeathRecipient_ = sptr(new ObserverDeathRecipient()); } } diff --git a/test/fuzztest/externalfileaccess_fuzzer/external_file_access_fuzzer.cpp b/test/fuzztest/externalfileaccess_fuzzer/external_file_access_fuzzer.cpp index 8dc8a282..46a7774f 100644 --- a/test/fuzztest/externalfileaccess_fuzzer/external_file_access_fuzzer.cpp +++ b/test/fuzztest/externalfileaccess_fuzzer/external_file_access_fuzzer.cpp @@ -41,12 +41,13 @@ const int UID_DEFAULT = 0; void SetNativeToken() { uint64_t tokenId; - const char **perms = new const char *[2]; + const char **perms = new const char *[3]; perms[0] = "ohos.permission.FILE_ACCESS_MANAGER"; perms[1] = "ohos.permission.GET_BUNDLE_INFO_PRIVILEGED"; + perms[2] = "ohos.permission.CONNECT_FILE_ACCESS_EXTENSION"; NativeTokenInfoParams infoInstance = { .dcapsNum = 0, - .permsNum = 2, + .permsNum = 3, .aclsNum = 0, .dcaps = nullptr, .perms = perms, diff --git a/test/fuzztest/externalfileaccessaccess_fuzzer/externalfileaccessaccess_fuzzer.cpp b/test/fuzztest/externalfileaccessaccess_fuzzer/externalfileaccessaccess_fuzzer.cpp index 48486941..18ce5d32 100644 --- a/test/fuzztest/externalfileaccessaccess_fuzzer/externalfileaccessaccess_fuzzer.cpp +++ b/test/fuzztest/externalfileaccessaccess_fuzzer/externalfileaccessaccess_fuzzer.cpp @@ -48,12 +48,13 @@ enum { void SetNativeToken() { uint64_t tokenId; - const char **perms = new const char *[2]; + const char **perms = new const char *[3]; perms[0] = "ohos.permission.FILE_ACCESS_MANAGER"; perms[1] = "ohos.permission.GET_BUNDLE_INFO_PRIVILEGED"; + perms[2] = "ohos.permission.CONNECT_FILE_ACCESS_EXTENSION"; NativeTokenInfoParams infoInstance = { .dcapsNum = 0, - .permsNum = 2, + .permsNum = 3, .aclsNum = 0, .dcaps = nullptr, .perms = perms, diff --git a/test/fuzztest/externalfileaccesscreatefile_fuzzer/externalfileaccesscreatefile_fuzzer.cpp b/test/fuzztest/externalfileaccesscreatefile_fuzzer/externalfileaccesscreatefile_fuzzer.cpp index 4c7d4c0b..c448bbf5 100644 --- a/test/fuzztest/externalfileaccesscreatefile_fuzzer/externalfileaccesscreatefile_fuzzer.cpp +++ b/test/fuzztest/externalfileaccesscreatefile_fuzzer/externalfileaccesscreatefile_fuzzer.cpp @@ -48,12 +48,13 @@ enum { void SetNativeToken() { uint64_t tokenId; - const char **perms = new const char *[2]; + const char **perms = new const char *[3]; perms[0] = "ohos.permission.FILE_ACCESS_MANAGER"; perms[1] = "ohos.permission.GET_BUNDLE_INFO_PRIVILEGED"; + perms[2] = "ohos.permission.CONNECT_FILE_ACCESS_EXTENSION"; NativeTokenInfoParams infoInstance = { .dcapsNum = 0, - .permsNum = 2, + .permsNum = 3, .aclsNum = 0, .dcaps = nullptr, .perms = perms, diff --git a/test/fuzztest/externalfileaccessdelete_fuzzer/externalfileaccessdelete_fuzzer.cpp b/test/fuzztest/externalfileaccessdelete_fuzzer/externalfileaccessdelete_fuzzer.cpp index 568e3fca..cbcdfa46 100644 --- a/test/fuzztest/externalfileaccessdelete_fuzzer/externalfileaccessdelete_fuzzer.cpp +++ b/test/fuzztest/externalfileaccessdelete_fuzzer/externalfileaccessdelete_fuzzer.cpp @@ -48,12 +48,13 @@ enum { void SetNativeToken() { uint64_t tokenId; - const char **perms = new const char *[2]; + const char **perms = new const char *[3]; perms[0] = "ohos.permission.FILE_ACCESS_MANAGER"; perms[1] = "ohos.permission.GET_BUNDLE_INFO_PRIVILEGED"; + perms[2] = "ohos.permission.CONNECT_FILE_ACCESS_EXTENSION"; NativeTokenInfoParams infoInstance = { .dcapsNum = 0, - .permsNum = 2, + .permsNum = 3, .aclsNum = 0, .dcaps = nullptr, .perms = perms, diff --git a/test/fuzztest/externalfileaccessgetfileinfofromrelativepath_fuzzer/externalfileaccessgetfileinfofromrelativepath_fuzzer.cpp b/test/fuzztest/externalfileaccessgetfileinfofromrelativepath_fuzzer/externalfileaccessgetfileinfofromrelativepath_fuzzer.cpp index 92a53e85..9c485975 100644 --- a/test/fuzztest/externalfileaccessgetfileinfofromrelativepath_fuzzer/externalfileaccessgetfileinfofromrelativepath_fuzzer.cpp +++ b/test/fuzztest/externalfileaccessgetfileinfofromrelativepath_fuzzer/externalfileaccessgetfileinfofromrelativepath_fuzzer.cpp @@ -48,12 +48,13 @@ enum { void SetNativeToken() { uint64_t tokenId; - const char **perms = new const char *[2]; + const char **perms = new const char *[3]; perms[0] = "ohos.permission.FILE_ACCESS_MANAGER"; perms[1] = "ohos.permission.GET_BUNDLE_INFO_PRIVILEGED"; + perms[2] = "ohos.permission.CONNECT_FILE_ACCESS_EXTENSION"; NativeTokenInfoParams infoInstance = { .dcapsNum = 0, - .permsNum = 2, + .permsNum = 3, .aclsNum = 0, .dcaps = nullptr, .perms = perms, diff --git a/test/fuzztest/externalfileaccessgetfileinfofromuri_fuzzer/externalfileaccessgetfileinfofromuri_fuzzer.cpp b/test/fuzztest/externalfileaccessgetfileinfofromuri_fuzzer/externalfileaccessgetfileinfofromuri_fuzzer.cpp index b1c345c2..3ac2b456 100644 --- a/test/fuzztest/externalfileaccessgetfileinfofromuri_fuzzer/externalfileaccessgetfileinfofromuri_fuzzer.cpp +++ b/test/fuzztest/externalfileaccessgetfileinfofromuri_fuzzer/externalfileaccessgetfileinfofromuri_fuzzer.cpp @@ -48,12 +48,13 @@ enum { void SetNativeToken() { uint64_t tokenId; - const char **perms = new const char *[2]; + const char **perms = new const char *[3]; perms[0] = "ohos.permission.FILE_ACCESS_MANAGER"; perms[1] = "ohos.permission.GET_BUNDLE_INFO_PRIVILEGED"; + perms[2] = "ohos.permission.CONNECT_FILE_ACCESS_EXTENSION"; NativeTokenInfoParams infoInstance = { .dcapsNum = 0, - .permsNum = 2, + .permsNum = 3, .aclsNum = 0, .dcaps = nullptr, .perms = perms, diff --git a/test/fuzztest/externalfileaccessgetroots_fuzzer/externalfileaccessgetroots_fuzzer.cpp b/test/fuzztest/externalfileaccessgetroots_fuzzer/externalfileaccessgetroots_fuzzer.cpp index 324caba1..8dc95df8 100644 --- a/test/fuzztest/externalfileaccessgetroots_fuzzer/externalfileaccessgetroots_fuzzer.cpp +++ b/test/fuzztest/externalfileaccessgetroots_fuzzer/externalfileaccessgetroots_fuzzer.cpp @@ -48,12 +48,13 @@ enum { void SetNativeToken() { uint64_t tokenId; - const char **perms = new const char *[2]; + const char **perms = new const char *[3]; perms[0] = "ohos.permission.FILE_ACCESS_MANAGER"; perms[1] = "ohos.permission.GET_BUNDLE_INFO_PRIVILEGED"; + perms[2] = "ohos.permission.CONNECT_FILE_ACCESS_EXTENSION"; NativeTokenInfoParams infoInstance = { .dcapsNum = 0, - .permsNum = 2, + .permsNum = 3, .aclsNum = 0, .dcaps = nullptr, .perms = perms, diff --git a/test/fuzztest/externalfileaccesslistfile_fuzzer/externalfileaccesslistfile_fuzzer.cpp b/test/fuzztest/externalfileaccesslistfile_fuzzer/externalfileaccesslistfile_fuzzer.cpp index bb48e0d2..6ed737e0 100644 --- a/test/fuzztest/externalfileaccesslistfile_fuzzer/externalfileaccesslistfile_fuzzer.cpp +++ b/test/fuzztest/externalfileaccesslistfile_fuzzer/externalfileaccesslistfile_fuzzer.cpp @@ -48,12 +48,13 @@ enum { void SetNativeToken() { uint64_t tokenId; - const char **perms = new const char *[2]; + const char **perms = new const char *[3]; perms[0] = "ohos.permission.FILE_ACCESS_MANAGER"; perms[1] = "ohos.permission.GET_BUNDLE_INFO_PRIVILEGED"; + perms[2] = "ohos.permission.CONNECT_FILE_ACCESS_EXTENSION"; NativeTokenInfoParams infoInstance = { .dcapsNum = 0, - .permsNum = 2, + .permsNum = 3, .aclsNum = 0, .dcaps = nullptr, .perms = perms, diff --git a/test/fuzztest/externalfileaccessmkdir_fuzzer/externalfileaccessmkdir_fuzzer.cpp b/test/fuzztest/externalfileaccessmkdir_fuzzer/externalfileaccessmkdir_fuzzer.cpp index fa7880c0..d3cfc9f0 100644 --- a/test/fuzztest/externalfileaccessmkdir_fuzzer/externalfileaccessmkdir_fuzzer.cpp +++ b/test/fuzztest/externalfileaccessmkdir_fuzzer/externalfileaccessmkdir_fuzzer.cpp @@ -48,12 +48,13 @@ enum { void SetNativeToken() { uint64_t tokenId; - const char **perms = new const char *[2]; + const char **perms = new const char *[3]; perms[0] = "ohos.permission.FILE_ACCESS_MANAGER"; perms[1] = "ohos.permission.GET_BUNDLE_INFO_PRIVILEGED"; + perms[2] = "ohos.permission.CONNECT_FILE_ACCESS_EXTENSION"; NativeTokenInfoParams infoInstance = { .dcapsNum = 0, - .permsNum = 2, + .permsNum = 3, .aclsNum = 0, .dcaps = nullptr, .perms = perms, diff --git a/test/fuzztest/externalfileaccessmove_fuzzer/externalfileaccessmove_fuzzer.cpp b/test/fuzztest/externalfileaccessmove_fuzzer/externalfileaccessmove_fuzzer.cpp index 2d1eea90..260a8f04 100644 --- a/test/fuzztest/externalfileaccessmove_fuzzer/externalfileaccessmove_fuzzer.cpp +++ b/test/fuzztest/externalfileaccessmove_fuzzer/externalfileaccessmove_fuzzer.cpp @@ -48,12 +48,13 @@ enum { void SetNativeToken() { uint64_t tokenId; - const char **perms = new const char *[2]; + const char **perms = new const char *[3]; perms[0] = "ohos.permission.FILE_ACCESS_MANAGER"; perms[1] = "ohos.permission.GET_BUNDLE_INFO_PRIVILEGED"; + perms[2] = "ohos.permission.CONNECT_FILE_ACCESS_EXTENSION"; NativeTokenInfoParams infoInstance = { .dcapsNum = 0, - .permsNum = 2, + .permsNum = 3, .aclsNum = 0, .dcaps = nullptr, .perms = perms, diff --git a/test/fuzztest/externalfileaccessopenfile_fuzzer/externalfileaccessopenfile_fuzzer.cpp b/test/fuzztest/externalfileaccessopenfile_fuzzer/externalfileaccessopenfile_fuzzer.cpp index 90af01bc..ccef60b2 100644 --- a/test/fuzztest/externalfileaccessopenfile_fuzzer/externalfileaccessopenfile_fuzzer.cpp +++ b/test/fuzztest/externalfileaccessopenfile_fuzzer/externalfileaccessopenfile_fuzzer.cpp @@ -48,12 +48,13 @@ enum { void SetNativeToken() { uint64_t tokenId; - const char **perms = new const char *[2]; + const char **perms = new const char *[3]; perms[0] = "ohos.permission.FILE_ACCESS_MANAGER"; perms[1] = "ohos.permission.GET_BUNDLE_INFO_PRIVILEGED"; + perms[2] = "ohos.permission.CONNECT_FILE_ACCESS_EXTENSION"; NativeTokenInfoParams infoInstance = { .dcapsNum = 0, - .permsNum = 2, + .permsNum = 3, .aclsNum = 0, .dcaps = nullptr, .perms = perms, diff --git a/test/fuzztest/externalfileaccessrename_fuzzer/externalfileaccessrename_fuzzer.cpp b/test/fuzztest/externalfileaccessrename_fuzzer/externalfileaccessrename_fuzzer.cpp index 9caa7d53..5c1a72d1 100644 --- a/test/fuzztest/externalfileaccessrename_fuzzer/externalfileaccessrename_fuzzer.cpp +++ b/test/fuzztest/externalfileaccessrename_fuzzer/externalfileaccessrename_fuzzer.cpp @@ -48,12 +48,13 @@ enum { void SetNativeToken() { uint64_t tokenId; - const char **perms = new const char *[2]; + const char **perms = new const char *[3]; perms[0] = "ohos.permission.FILE_ACCESS_MANAGER"; perms[1] = "ohos.permission.GET_BUNDLE_INFO_PRIVILEGED"; + perms[2] = "ohos.permission.CONNECT_FILE_ACCESS_EXTENSION"; NativeTokenInfoParams infoInstance = { .dcapsNum = 0, - .permsNum = 2, + .permsNum = 3, .aclsNum = 0, .dcaps = nullptr, .perms = perms, diff --git a/test/fuzztest/externalfileaccessscanfile_fuzzer/externalfileaccessscanfile_fuzzer.cpp b/test/fuzztest/externalfileaccessscanfile_fuzzer/externalfileaccessscanfile_fuzzer.cpp index 991a5f84..d85821a5 100644 --- a/test/fuzztest/externalfileaccessscanfile_fuzzer/externalfileaccessscanfile_fuzzer.cpp +++ b/test/fuzztest/externalfileaccessscanfile_fuzzer/externalfileaccessscanfile_fuzzer.cpp @@ -48,12 +48,13 @@ enum { void SetNativeToken() { uint64_t tokenId; - const char **perms = new const char *[2]; + const char **perms = new const char *[3]; perms[0] = "ohos.permission.FILE_ACCESS_MANAGER"; perms[1] = "ohos.permission.GET_BUNDLE_INFO_PRIVILEGED"; + perms[2] = "ohos.permission.CONNECT_FILE_ACCESS_EXTENSION"; NativeTokenInfoParams infoInstance = { .dcapsNum = 0, - .permsNum = 2, + .permsNum = 3, .aclsNum = 0, .dcaps = nullptr, .perms = perms, diff --git a/test/fuzztest/fileaccessserviceproxy_fuzzer/fileaccessserviceproxy_fuzzer.cpp b/test/fuzztest/fileaccessserviceproxy_fuzzer/fileaccessserviceproxy_fuzzer.cpp index a2f8c00d..039d075b 100644 --- a/test/fuzztest/fileaccessserviceproxy_fuzzer/fileaccessserviceproxy_fuzzer.cpp +++ b/test/fuzztest/fileaccessserviceproxy_fuzzer/fileaccessserviceproxy_fuzzer.cpp @@ -28,7 +28,7 @@ using namespace FileAccessFwk; SystemAbilityManagerClient& SystemAbilityManagerClient::GetInstance() { - static auto instance = new SystemAbilityManagerClient(); + static auto instance = std::make_shared(); return *instance; } diff --git a/test/fuzztest/medialibraryfileaccess_fuzzer/medialibrary_file_access_fuzzer.cpp b/test/fuzztest/medialibraryfileaccess_fuzzer/medialibrary_file_access_fuzzer.cpp index 52ce4e2d..f8d8e635 100644 --- a/test/fuzztest/medialibraryfileaccess_fuzzer/medialibrary_file_access_fuzzer.cpp +++ b/test/fuzztest/medialibraryfileaccess_fuzzer/medialibrary_file_access_fuzzer.cpp @@ -41,12 +41,13 @@ const int UID_DEFAULT = 0; void SetNativeToken() { uint64_t tokenId; - const char **perms = new const char *[2]; + const char **perms = new const char *[3]; perms[0] = "ohos.permission.FILE_ACCESS_MANAGER"; perms[1] = "ohos.permission.GET_BUNDLE_INFO_PRIVILEGED"; + perms[2] = "ohos.permission.CONNECT_FILE_ACCESS_EXTENSION"; NativeTokenInfoParams infoInstance = { .dcapsNum = 0, - .permsNum = 2, + .permsNum = 3, .aclsNum = 0, .dcaps = nullptr, .perms = perms, diff --git a/test/unittest/abnormal_file_access_test.cpp b/test/unittest/abnormal_file_access_test.cpp index 15dedcb6..fff3fd46 100755 --- a/test/unittest/abnormal_file_access_test.cpp +++ b/test/unittest/abnormal_file_access_test.cpp @@ -40,12 +40,13 @@ shared_ptr g_context = nullptr; static void SetNativeToken(bool isSystemApp) { uint64_t tokenId; - const char **perms = new const char *[2]; + const char **perms = new const char *[3]; perms[0] = "ohos.permission.FILE_ACCESS_MANAGER"; perms[1] = "ohos.permission.GET_BUNDLE_INFO_PRIVILEGED"; + perms[2] = "ohos.permission.CONNECT_FILE_ACCESS_EXTENSION"; NativeTokenInfoParams infoInstance = { .dcapsNum = 0, - .permsNum = 2, + .permsNum = 3, .aclsNum = 0, .dcaps = nullptr, .perms = perms, diff --git a/test/unittest/external_file_access_test.cpp b/test/unittest/external_file_access_test.cpp index 8695d627..64456883 100644 --- a/test/unittest/external_file_access_test.cpp +++ b/test/unittest/external_file_access_test.cpp @@ -36,20 +36,18 @@ static shared_ptr g_context = nullptr; void SetNativeToken() { uint64_t tokenId; - const char **perms = new const char *[2]; - if (perms == nullptr) { - return; - } + const char **perms = new const char *[3]; perms[0] = "ohos.permission.FILE_ACCESS_MANAGER"; perms[1] = "ohos.permission.GET_BUNDLE_INFO_PRIVILEGED"; + perms[2] = "ohos.permission.CONNECT_FILE_ACCESS_EXTENSION"; NativeTokenInfoParams infoInstance = { - .aplStr = "system_core", - .acls = nullptr, .dcapsNum = 0, - .permsNum = 2, + .permsNum = 3, .aclsNum = 0, .dcaps = nullptr, .perms = perms, + .acls = nullptr, + .aplStr = "system_core", }; infoInstance.processName = "SetUpTestCase"; diff --git a/test/unittest/external_notify_test.cpp b/test/unittest/external_notify_test.cpp index f37092a2..98a66b94 100644 --- a/test/unittest/external_notify_test.cpp +++ b/test/unittest/external_notify_test.cpp @@ -56,12 +56,13 @@ shared_ptr g_context = nullptr; void SetNativeToken() { uint64_t tokenId; - const char **perms = new const char *[2]; + const char **perms = new const char *[3]; perms[0] = "ohos.permission.FILE_ACCESS_MANAGER"; perms[1] = "ohos.permission.GET_BUNDLE_INFO_PRIVILEGED"; + perms[2] = "ohos.permission.CONNECT_FILE_ACCESS_EXTENSION"; NativeTokenInfoParams infoInstance = { .dcapsNum = 0, - .permsNum = 2, + .permsNum = 3, .aclsNum = 0, .dcaps = nullptr, .perms = perms, @@ -263,10 +264,10 @@ HWTEST_F(FileExtensionNotifyTest, external_file_access_notify_0000, testing::ext EXPECT_NE(g_fah, nullptr); int result = g_fah->GetRoots(info); EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK); - sptr myObserver1 = new (std::nothrow) MyObserver(); - sptr myObserver2 = new (std::nothrow) MyObserver(); - sptr myObserver3 = new (std::nothrow) MyObserver(); - sptr myObserver4 = new (std::nothrow) MyObserver(); + sptr myObserver1 = sptr(new (std::nothrow) MyObserver()); + sptr myObserver2 = sptr(new (std::nothrow) MyObserver()); + sptr myObserver3 = sptr(new (std::nothrow) MyObserver()); + sptr myObserver4 = sptr(new (std::nothrow) MyObserver()); Uri parentUri(info[1].uri); auto [newDirUriTest1, newDirUriTest2, newFileUri1, newFileUri2] = ReadyRegisterNotify00(parentUri, myObserver1, myObserver2, myObserver3, myObserver4); @@ -335,9 +336,9 @@ HWTEST_F(FileExtensionNotifyTest, external_file_access_notify_0001, testing::ext int result = g_fah->GetRoots(info); EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK); - sptr myObserver1 = new (std::nothrow) MyObserver(); - sptr myObserver2 = new (std::nothrow) MyObserver(); - sptr myObserver3 = new (std::nothrow) MyObserver(); + sptr myObserver1 = sptr(new (std::nothrow) MyObserver()); + sptr myObserver2 = sptr(new (std::nothrow) MyObserver()); + sptr myObserver3 = sptr(new (std::nothrow) MyObserver()); Uri parentUri(info[1].uri); auto [newFileUri1, newFileUri2, newFileUri3] = ReadyRegisterNotify01(parentUri, myObserver1, myObserver2, myObserver3); @@ -506,8 +507,8 @@ HWTEST_F(FileExtensionNotifyTest, external_file_access_notify_0003, testing::ext int result = g_fah->GetRoots(info); EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK); bool notifyForDescendants = true; - sptr myObserver1 = new (std::nothrow) MyObserver(); - sptr myObserver2 = new (std::nothrow) MyObserver(); + sptr myObserver1 = sptr(new (std::nothrow) MyObserver()); + sptr myObserver2 = sptr(new (std::nothrow) MyObserver()); Uri parentUri(info[1].uri); Uri newDirUriTest1(""); result = g_fah->Mkdir(parentUri, "uri_dir1", newDirUriTest1); @@ -584,7 +585,7 @@ HWTEST_F(FileExtensionNotifyTest, external_file_access_notify_0005, testing::ext EXPECT_NE(g_fah, nullptr); int result = g_fah->GetRoots(info); EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK); - sptr myObserver1 = new (std::nothrow) MyObserver(); + sptr myObserver1 = sptr(new (std::nothrow) MyObserver()); Uri parentUri(info[1].uri); auto [uri_dir, uri_dirSub1, uri_dirSub2, renameDirUri1] = ReadyRegisterNotify05(parentUri, myObserver1); if (g_notifyEvent != MOVED_TO) { @@ -637,7 +638,7 @@ HWTEST_F(FileExtensionNotifyTest, external_file_access_notify_0006, testing::ext int result = g_fah->GetRoots(info); EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK); bool notifyForDescendants = true; - sptr myObserver1 = new (std::nothrow) MyObserver(); + sptr myObserver1 = sptr(new (std::nothrow) MyObserver()); Uri parentUri(info[1].uri); Uri newFileUri1(""); result = g_fah->CreateFile(parentUri, "uri_file", newFileUri1); @@ -712,7 +713,7 @@ HWTEST_F(FileExtensionNotifyTest, external_file_access_notify_0008, testing::ext EXPECT_NE(g_fah, nullptr); int result = g_fah->GetRoots(info); EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK); - sptr myObserver1 = new (std::nothrow) MyObserver(); + sptr myObserver1 = sptr(new (std::nothrow) MyObserver()); Uri newFileUri1("*/&%"); bool notifyForDescendants = true; result = g_fah->RegisterNotify(newFileUri1, notifyForDescendants, myObserver1); @@ -743,7 +744,7 @@ HWTEST_F(FileExtensionNotifyTest, external_file_access_notify_0009, testing::ext int result = g_fah->GetRoots(info); EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK); bool notifyForDescendants = true; - sptr myObserver1 = new (std::nothrow) MyObserver(); + sptr myObserver1 = sptr(new (std::nothrow) MyObserver()); Uri parentUri(info[1].uri); Uri newFileUri1(""); result = g_fah->CreateFile(parentUri, "测试文件", newFileUri1); @@ -782,8 +783,8 @@ HWTEST_F(FileExtensionNotifyTest, external_file_access_notify_0010, testing::ext int result = g_fah->GetRoots(info); EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK); bool notifyForDescendants = true; - sptr myObserver1 = new (std::nothrow) MyObserver(); - sptr myObserver2 = new (std::nothrow) MyObserver(); + sptr myObserver1 = sptr(new (std::nothrow) MyObserver()); + sptr myObserver2 = sptr(new (std::nothrow) MyObserver()); Uri parentUri(info[1].uri); Uri newFileUri1(""); result = g_fah->CreateFile(parentUri, "uri_file1", newFileUri1); @@ -855,8 +856,8 @@ HWTEST_F(FileExtensionNotifyTest, external_file_access_notify_0011, testing::ext int result = g_fah->GetRoots(info); EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK); bool notifyForDescendants2 = false; - sptr myObserver1 = new (std::nothrow) TestObserver(); - sptr myObserver2 = new (std::nothrow) MyObserver(); + sptr myObserver1 = sptr(new (std::nothrow) TestObserver()); + sptr myObserver2 = sptr(new (std::nothrow) MyObserver()); Uri parentUri(info[1].uri); Uri newFileDir1(""); auto [newFileUri1, renameFileUri1] = @@ -936,7 +937,7 @@ HWTEST_F(FileExtensionNotifyTest, external_file_access_notify_00012, testing::ex Uri parentUri(info[1].uri); Uri newFileUri1(""); GTEST_LOG_(INFO) << parentUri.ToString(); - sptr myObserver1 = new (std::nothrow) MyObserver(); + sptr myObserver1 = sptr(new (std::nothrow) MyObserver()); for (int i = 0; i < INIT_THREADS_NUMBER; i++) { std::thread execthread1(RegisterDirNotify, parentUri, "WatcherTest", myObserver1.GetRefPtr()); execthread1.join(); @@ -966,7 +967,7 @@ HWTEST_F(FileExtensionNotifyTest, external_file_access_notify_00013, testing::ex EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK); Uri parentUri(info[1].uri); GTEST_LOG_(INFO) << parentUri.ToString(); - sptr myObserver1 = new (std::nothrow) MyObserver(); + sptr myObserver1 = sptr(new (std::nothrow) MyObserver()); std::thread execthread1(RegisterDirNotify, parentUri, "WatcherTest1", myObserver1.GetRefPtr()); execthread1.join(); std::thread execthread2(RegisterDirNotify, parentUri, "WatcherTest2", myObserver1.GetRefPtr()); @@ -998,9 +999,9 @@ HWTEST_F(FileExtensionNotifyTest, external_file_access_notify_00014, testing::ex EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK); Uri parentUri(info[1].uri); GTEST_LOG_(INFO) << parentUri.ToString(); - sptr myObserver1 = new (std::nothrow) MyObserver(); - sptr myObserver2 = new (std::nothrow) MyObserver(); - sptr myObserver3 = new (std::nothrow) MyObserver(); + sptr myObserver1 = sptr(new (std::nothrow) MyObserver()); + sptr myObserver2 = sptr(new (std::nothrow) MyObserver()); + sptr myObserver3 = sptr(new (std::nothrow) MyObserver()); std::thread execthread1(RegisterDirNotify, parentUri, "WatcherTest", myObserver1.GetRefPtr()); execthread1.join(); @@ -1035,9 +1036,9 @@ HWTEST_F(FileExtensionNotifyTest, external_file_access_notify_00015, testing::ex EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK); Uri parentUri(info[1].uri); GTEST_LOG_(INFO) << parentUri.ToString(); - sptr myObserver1 = new (std::nothrow) MyObserver(); - sptr myObserver2 = new (std::nothrow) MyObserver(); - sptr myObserver3 = new (std::nothrow) MyObserver(); + sptr myObserver1 = sptr(new (std::nothrow) MyObserver()); + sptr myObserver2 = sptr(new (std::nothrow) MyObserver()); + sptr myObserver3 = sptr(new (std::nothrow) MyObserver()); std::thread execthread1(RegisterDirNotify, parentUri, "WatcherTest1", myObserver1.GetRefPtr()); execthread1.join(); @@ -1069,9 +1070,9 @@ HWTEST_F(FileExtensionNotifyTest, external_file_access_notify_0016, testing::ext int result = g_fah->GetRoots(info); EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK); bool notifyForDescendants = true; - sptr myObserver1 = new (std::nothrow) MyObserver(); - sptr myObserver2 = new (std::nothrow) MyObserver(); - sptr myObserver3 = new (std::nothrow) MyObserver(); + sptr myObserver1 = sptr(new (std::nothrow) MyObserver()); + sptr myObserver2 = sptr(new (std::nothrow) MyObserver()); + sptr myObserver3 = sptr(new (std::nothrow) MyObserver()); Uri parentUri(info[1].uri); Uri newFileDir1(""); result = g_fah->Mkdir(parentUri, "uri_dir0016", newFileDir1); @@ -1114,7 +1115,7 @@ HWTEST_F(FileExtensionNotifyTest, external_file_access_notify_0017, testing::ext int result = g_fah->GetRoots(info); EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK); bool notifyForDescendants = true; - sptr myObserver1 = new (std::nothrow) MyObserver(); + sptr myObserver1 = sptr(new (std::nothrow) MyObserver()); Uri parentUri(info[1].uri); Uri newFileDir1(""); result = g_fah->Mkdir(parentUri, "uri_dir", newFileDir1); @@ -1158,7 +1159,7 @@ HWTEST_F(FileExtensionNotifyTest, external_file_access_notify_0018, testing::ext int result = g_fah->GetRoots(info); EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK); bool notifyForDescendants = true; - sptr myObserver1 = new (std::nothrow) TestObserver(); + sptr myObserver1 = sptr(new (std::nothrow) TestObserver()); Uri parentUri(info[1].uri); Uri newFileDir1(""); result = g_fah->Mkdir(parentUri, "uri_dir", newFileDir1); @@ -1202,7 +1203,7 @@ HWTEST_F(FileExtensionNotifyTest, external_file_access_notify_0019, testing::ext int result = g_fah->GetRoots(info); EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK); bool notifyForDescendants = true; - sptr myObserver1 = new (std::nothrow) TestObserver(); + sptr myObserver1 = sptr(new (std::nothrow) TestObserver()); Uri parentUri(info[1].uri); Uri newFileDir1(""); result = g_fah->Mkdir(parentUri, "uri_dir", newFileDir1); @@ -1246,7 +1247,7 @@ HWTEST_F(FileExtensionNotifyTest, external_file_access_notify_0020, testing::ext EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK); bool notifyForDescendants = true; - sptr myObserver1 = new (std::nothrow) MyObserver(); + sptr myObserver1 = sptr(new (std::nothrow) MyObserver()); Uri parentUri(info[1].uri); Uri newFileDir1(""); SetNativeToken("SetUpTestCase", perms, sizeof(perms) / sizeof(perms[0])); diff --git a/test/unittest/file_access_service_proxy_test.cpp b/test/unittest/file_access_service_proxy_test.cpp index fc8ec7cf..84467630 100644 --- a/test/unittest/file_access_service_proxy_test.cpp +++ b/test/unittest/file_access_service_proxy_test.cpp @@ -58,7 +58,7 @@ public: static void SetUpTestCase(void) { Assistant::ins_ = insMoc; - SystemAbilityManagerClient::GetInstance().systemAbilityManager_ = sptr(samgr); + SystemAbilityManagerClient::GetInstance().systemAbilityManager_ = sptr(samgr.get()); } static void TearDownTestCase() { @@ -73,7 +73,7 @@ public: public: static inline shared_ptr insMoc = make_shared(); static inline sptr impl = sptr(new FileAccessServiceMock()); - static inline ISystemAbilityManagerMock* samgr = new ISystemAbilityManagerMock(); + static inline shared_ptr samgr = make_shared(); }; /** diff --git a/test/unittest/medialibrary_file_access_test_basic.cpp b/test/unittest/medialibrary_file_access_test_basic.cpp index b31b0f3d..25c82ce4 100644 --- a/test/unittest/medialibrary_file_access_test_basic.cpp +++ b/test/unittest/medialibrary_file_access_test_basic.cpp @@ -43,17 +43,18 @@ const int UID_DEFAULT = 0; void SetNativeToken() { uint64_t tokenId; - const char **perms = new const char *[2]; + const char **perms = new const char *[3]; perms[0] = "ohos.permission.FILE_ACCESS_MANAGER"; perms[1] = "ohos.permission.GET_BUNDLE_INFO_PRIVILEGED"; + perms[2] = "ohos.permission.CONNECT_FILE_ACCESS_EXTENSION"; NativeTokenInfoParams infoInstance = { - .aplStr = "system_core", + .dcapsNum = 0, + .permsNum = 3, .aclsNum = 0, .dcaps = nullptr, - .dcapsNum = 0, - .permsNum = 2, .perms = perms, .acls = nullptr, + .aplStr = "system_core", }; infoInstance.processName = "SetUpTestCase"; diff --git a/test/unittest/mock/service_registry_mock.cpp b/test/unittest/mock/service_registry_mock.cpp index eecb89ed..00c82437 100644 --- a/test/unittest/mock/service_registry_mock.cpp +++ b/test/unittest/mock/service_registry_mock.cpp @@ -25,7 +25,7 @@ namespace OHOS { using namespace OHOS::FileAccessFwk; SystemAbilityManagerClient& SystemAbilityManagerClient::GetInstance() { - static auto instance = new SystemAbilityManagerClient(); + static auto instance = std::make_shared(); return *instance; } -- Gitee