2023-08-22 02:35:14 +00:00
|
|
|
/*
|
2024-03-21 12:50:12 +00:00
|
|
|
* Copyright (c) 2023-2024 Huawei Device Co., Ltd.
|
2023-08-22 02:35:14 +00:00
|
|
|
* 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 <cstdio>
|
|
|
|
#include <thread>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include <gtest/gtest.h>
|
|
|
|
#include <nlohmann/json.hpp>
|
|
|
|
|
|
|
|
#include "accesstoken_kit.h"
|
|
|
|
#include "context_impl.h"
|
|
|
|
#include "file_access_framework_errno.h"
|
|
|
|
#include "file_access_observer_common.h"
|
|
|
|
#include "iservice_registry.h"
|
|
|
|
#include "iobserver_callback.h"
|
|
|
|
#include "nativetoken_kit.h"
|
|
|
|
#include "observer_callback_stub.h"
|
|
|
|
#include "token_setproc.h"
|
|
|
|
|
|
|
|
#define private public
|
|
|
|
#include "file_access_helper.h"
|
|
|
|
#undef private
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
using namespace std;
|
|
|
|
using namespace OHOS;
|
|
|
|
using namespace FileAccessFwk;
|
|
|
|
using json = nlohmann::json;
|
|
|
|
const int ABILITY_ID = 5003;
|
|
|
|
const int INIT_THREADS_NUMBER = 4;
|
|
|
|
shared_ptr<FileAccessHelper> g_fah = nullptr;
|
|
|
|
int g_notifyEvent = -1;
|
|
|
|
int g_notifyFlag = -1;
|
|
|
|
string g_notifyUri = "";
|
2023-10-20 07:25:27 +00:00
|
|
|
vector<string> g_notifyUris;
|
|
|
|
const int SLEEP_TIME = 600 * 1000;
|
2023-08-22 02:35:14 +00:00
|
|
|
const int UID_TRANSFORM_TMP = 20000000;
|
|
|
|
const int UID_DEFAULT = 0;
|
2024-03-21 12:50:12 +00:00
|
|
|
const uint64_t SYSTEM_APP_MASK = (static_cast<uint64_t>(1) << 32); // 1: Base number, 32: Left shifted bit numbers
|
|
|
|
|
2023-08-22 02:35:14 +00:00
|
|
|
shared_ptr<OHOS::AbilityRuntime::Context> g_context = nullptr;
|
|
|
|
|
|
|
|
void SetNativeToken()
|
|
|
|
{
|
|
|
|
uint64_t tokenId;
|
2024-07-26 08:22:39 +00:00
|
|
|
const char *perms[] = {
|
|
|
|
"ohos.permission.FILE_ACCESS_MANAGER",
|
|
|
|
"ohos.permission.GET_BUNDLE_INFO_PRIVILEGED",
|
|
|
|
"ohos.permission.CONNECT_FILE_ACCESS_EXTENSION"
|
|
|
|
};
|
2023-08-22 02:35:14 +00:00
|
|
|
NativeTokenInfoParams infoInstance = {
|
|
|
|
.dcapsNum = 0,
|
2024-07-18 08:35:51 +00:00
|
|
|
.permsNum = 3,
|
2023-08-22 02:35:14 +00:00
|
|
|
.aclsNum = 0,
|
|
|
|
.dcaps = nullptr,
|
|
|
|
.perms = perms,
|
|
|
|
.acls = nullptr,
|
|
|
|
.aplStr = "system_core",
|
|
|
|
};
|
|
|
|
|
|
|
|
infoInstance.processName = "SetUpTestCase";
|
|
|
|
tokenId = GetAccessTokenId(&infoInstance);
|
|
|
|
const uint64_t systemAppMask = (static_cast<uint64_t>(1) << 32);
|
|
|
|
tokenId |= systemAppMask;
|
|
|
|
SetSelfTokenID(tokenId);
|
|
|
|
OHOS::Security::AccessToken::AccessTokenKit::ReloadNativeTokenInfo();
|
|
|
|
}
|
|
|
|
|
2024-03-21 12:50:12 +00:00
|
|
|
void SetNativeToken(const char* processName, const char*perms[], int32_t permsNum)
|
|
|
|
{
|
|
|
|
uint64_t tokenId;
|
|
|
|
NativeTokenInfoParams infoInstance = {
|
|
|
|
.dcapsNum = 0,
|
|
|
|
.permsNum = permsNum,
|
|
|
|
.aclsNum = 0,
|
|
|
|
.dcaps = nullptr,
|
|
|
|
.perms = perms,
|
|
|
|
.acls = nullptr,
|
|
|
|
.aplStr = "system_core",
|
|
|
|
};
|
|
|
|
tokenId = GetAccessTokenId(&infoInstance);
|
|
|
|
const uint64_t systemAppMask = SYSTEM_APP_MASK;
|
|
|
|
tokenId |= systemAppMask;
|
|
|
|
SetSelfTokenID(tokenId);
|
|
|
|
OHOS::Security::AccessToken::AccessTokenKit::ReloadNativeTokenInfo();
|
|
|
|
}
|
|
|
|
|
2023-08-22 02:35:14 +00:00
|
|
|
class FileExtensionNotifyTest : public testing::Test {
|
|
|
|
public:
|
|
|
|
static void SetUpTestCase(void)
|
|
|
|
{
|
|
|
|
cout << "FileExtensionNotifyTest code test" << endl;
|
|
|
|
SetNativeToken();
|
|
|
|
auto saManager = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
|
2024-07-06 08:01:52 +00:00
|
|
|
if (saManager == nullptr) {
|
|
|
|
return;
|
|
|
|
}
|
2023-08-22 02:35:14 +00:00
|
|
|
auto remoteObj = saManager->GetSystemAbility(ABILITY_ID);
|
|
|
|
g_context = make_shared<OHOS::AbilityRuntime::ContextImpl>();
|
|
|
|
g_context->SetToken(remoteObj);
|
|
|
|
AAFwk::Want want;
|
|
|
|
vector<AAFwk::Want> wantVec;
|
|
|
|
setuid(UID_TRANSFORM_TMP);
|
|
|
|
int ret = FileAccessHelper::GetRegisteredFileAccessExtAbilityInfo(wantVec);
|
|
|
|
EXPECT_EQ(ret, OHOS::FileAccessFwk::ERR_OK);
|
|
|
|
bool sus = false;
|
|
|
|
for (size_t i = 0; i < wantVec.size(); i++) {
|
|
|
|
auto element = wantVec[i].GetElement();
|
|
|
|
if (element.GetBundleName() == "com.ohos.UserFile.ExternalFileManager" &&
|
|
|
|
element.GetAbilityName() == "FileExtensionAbility") {
|
|
|
|
want = wantVec[i];
|
|
|
|
sus = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
EXPECT_TRUE(sus);
|
|
|
|
vector<AAFwk::Want> wants{want};
|
|
|
|
g_fah = FileAccessHelper::Creator(remoteObj, wants);
|
|
|
|
if (g_fah == nullptr) {
|
|
|
|
GTEST_LOG_(ERROR) << "external_file_access_test g_fah is nullptr";
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
setuid(UID_DEFAULT);
|
|
|
|
}
|
|
|
|
static void TearDownTestCase()
|
|
|
|
{
|
2024-07-06 08:01:52 +00:00
|
|
|
if (g_fah) {
|
|
|
|
g_fah->Release();
|
|
|
|
}
|
2023-08-22 02:35:14 +00:00
|
|
|
g_fah = nullptr;
|
|
|
|
};
|
|
|
|
void SetUp(){};
|
|
|
|
void TearDown(){};
|
|
|
|
};
|
|
|
|
|
|
|
|
class MyObserver : public ObserverCallbackStub {
|
|
|
|
public:
|
|
|
|
MyObserver() {};
|
|
|
|
virtual ~MyObserver() = default;
|
|
|
|
void OnChange(NotifyMessage ¬ifyMessage) override;
|
|
|
|
};
|
|
|
|
|
2023-10-07 08:56:09 +00:00
|
|
|
void MyObserver::OnChange(NotifyMessage ¬ifyMessage)
|
2023-08-22 02:35:14 +00:00
|
|
|
{
|
|
|
|
g_notifyEvent = static_cast<int>(notifyMessage.notifyType_);
|
|
|
|
std::string notifyUri = notifyMessage.uris_[0];
|
|
|
|
g_notifyUri = notifyUri;
|
2023-10-20 07:25:27 +00:00
|
|
|
GTEST_LOG_(INFO) << "enter notify uri =" + notifyUri + " type =" + std::to_string(g_notifyEvent) +" uri size" +
|
|
|
|
std::to_string(notifyMessage.uris_.size());
|
2023-08-22 02:35:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
class TestObserver : public ObserverCallbackStub {
|
|
|
|
public:
|
|
|
|
TestObserver() {};
|
|
|
|
virtual ~TestObserver() = default;
|
|
|
|
void OnChange(NotifyMessage ¬ifyMessage) override;
|
|
|
|
};
|
|
|
|
|
2023-10-10 10:24:15 +00:00
|
|
|
void TestObserver::OnChange(NotifyMessage ¬ifyMessage)
|
2023-08-22 02:35:14 +00:00
|
|
|
{
|
|
|
|
g_notifyFlag = static_cast<int>(notifyMessage.notifyType_);
|
|
|
|
std::string notifyUri = notifyMessage.uris_[0];
|
2023-10-20 07:25:27 +00:00
|
|
|
g_notifyUris = notifyMessage.uris_;
|
2023-08-22 02:35:14 +00:00
|
|
|
GTEST_LOG_(INFO) << "enter TestObserver uri =" + notifyUri + "type =" + std::to_string(g_notifyFlag);
|
|
|
|
}
|
|
|
|
|
2024-02-28 07:39:14 +00:00
|
|
|
static tuple<Uri, Uri, Uri, Uri> ReadyRegisterNotify00(Uri& parentUri,
|
|
|
|
sptr<IFileAccessObserver>& myObserver1,
|
|
|
|
sptr<IFileAccessObserver>& myObserver2,
|
|
|
|
sptr<IFileAccessObserver>& myObserver3,
|
|
|
|
sptr<IFileAccessObserver>& myObserver4)
|
|
|
|
{
|
|
|
|
bool notifyForDescendants = false;
|
|
|
|
Uri newDirUriTest1("");
|
2024-07-06 08:01:52 +00:00
|
|
|
EXPECT_NE(g_fah, nullptr);
|
2024-02-28 07:39:14 +00:00
|
|
|
int result = g_fah->Mkdir(parentUri, "uri_dir1", newDirUriTest1);
|
|
|
|
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
|
|
|
Uri newDirUriTest2("");
|
|
|
|
result = g_fah->Mkdir(parentUri, "uri_dir2", newDirUriTest2);
|
|
|
|
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
|
|
|
Uri newFileUri1("");
|
|
|
|
result = g_fah->CreateFile(parentUri, "uri_file1", newFileUri1);
|
|
|
|
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
|
|
|
GTEST_LOG_(INFO) << newFileUri1.ToString();
|
|
|
|
Uri newFileUri2("");
|
|
|
|
result = g_fah->CreateFile(parentUri, "uri_file2", newFileUri2);
|
|
|
|
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
|
|
|
|
|
|
|
result = g_fah->RegisterNotify(newDirUriTest1, true, myObserver1);
|
|
|
|
EXPECT_GE(result, OHOS::FileAccessFwk::ERR_OK);
|
|
|
|
result = g_fah->RegisterNotify(newDirUriTest2, notifyForDescendants, myObserver2);
|
|
|
|
EXPECT_GE(result, OHOS::FileAccessFwk::ERR_OK);
|
|
|
|
result = g_fah->RegisterNotify(newFileUri1, notifyForDescendants, myObserver3);
|
|
|
|
EXPECT_GE(result, OHOS::FileAccessFwk::ERR_OK);
|
|
|
|
result = g_fah->RegisterNotify(newFileUri2, notifyForDescendants, myObserver4);
|
|
|
|
EXPECT_GE(result, OHOS::FileAccessFwk::ERR_OK);
|
|
|
|
|
|
|
|
return {newDirUriTest1, newDirUriTest2, newFileUri1, newFileUri2};
|
|
|
|
}
|
|
|
|
|
|
|
|
static tuple<Uri, Uri> TriggerNotify00(Uri& newDirUriTest1, Uri& newDirUriTest2, Uri& newFileUri1, Uri& newFileUri2)
|
|
|
|
{
|
|
|
|
Uri testUri("");
|
2024-07-06 08:01:52 +00:00
|
|
|
EXPECT_NE(g_fah, nullptr);
|
2024-02-28 07:39:14 +00:00
|
|
|
int result = g_fah->CreateFile(newDirUriTest1, "testUri", testUri);
|
|
|
|
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
|
|
|
usleep(SLEEP_TIME);
|
|
|
|
EXPECT_EQ(g_notifyEvent, ADD_EVENT);
|
|
|
|
EXPECT_EQ(g_notifyUri, testUri.ToString());
|
|
|
|
Uri renameDirUri1("");
|
|
|
|
result = g_fah->Rename(newDirUriTest1, "testDir", renameDirUri1);
|
|
|
|
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
|
|
|
usleep(SLEEP_TIME);
|
|
|
|
EXPECT_EQ(g_notifyEvent, MOVED_SELF);
|
|
|
|
EXPECT_EQ(g_notifyUri, newDirUriTest1.ToString());
|
|
|
|
result = g_fah->Delete(newDirUriTest2);
|
|
|
|
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
|
|
|
usleep(SLEEP_TIME);
|
2024-10-14 08:37:08 +00:00
|
|
|
EXPECT_EQ(g_notifyEvent, MOVED_SELF);
|
2024-02-28 07:39:14 +00:00
|
|
|
EXPECT_EQ(g_notifyUri, newDirUriTest2.ToString());
|
|
|
|
|
|
|
|
Uri renameUri1("");
|
|
|
|
result = g_fah->Rename(newFileUri1, "renameUri1", renameUri1);
|
|
|
|
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
|
|
|
usleep(SLEEP_TIME);
|
|
|
|
EXPECT_EQ(g_notifyEvent, MOVED_SELF);
|
|
|
|
EXPECT_EQ(g_notifyUri, newFileUri1.ToString());
|
|
|
|
result = g_fah->Delete(newFileUri2);
|
|
|
|
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
|
|
|
usleep(SLEEP_TIME);
|
2024-10-14 08:37:08 +00:00
|
|
|
EXPECT_EQ(g_notifyEvent, MOVED_SELF);
|
2024-02-28 07:39:14 +00:00
|
|
|
EXPECT_EQ(g_notifyUri, newFileUri2.ToString());
|
|
|
|
|
|
|
|
return {renameDirUri1, renameUri1};
|
|
|
|
}
|
|
|
|
|
2023-08-22 02:35:14 +00:00
|
|
|
/**
|
|
|
|
* @tc.number: user_file_service_external_file_access_notify_0000
|
|
|
|
* @tc.name: external_file_access_notify_0000
|
|
|
|
* @tc.desc: Test function of RegisterNotify and UnregisterNotify interface for SUCCESS.
|
|
|
|
* @tc.size: MEDIUM
|
|
|
|
* @tc.type: FUNC
|
|
|
|
* @tc.level Level 1
|
|
|
|
* @tc.require: SR000H0386
|
|
|
|
*/
|
|
|
|
HWTEST_F(FileExtensionNotifyTest, external_file_access_notify_0000, testing::ext::TestSize.Level1)
|
|
|
|
{
|
|
|
|
GTEST_LOG_(INFO) << "FileExtensionNotifyTest-begin external_file_access_notify_0000";
|
|
|
|
try {
|
|
|
|
vector<RootInfo> info;
|
2024-07-06 08:01:52 +00:00
|
|
|
EXPECT_NE(g_fah, nullptr);
|
2023-08-22 02:35:14 +00:00
|
|
|
int result = g_fah->GetRoots(info);
|
|
|
|
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
2024-07-18 08:35:51 +00:00
|
|
|
sptr<IFileAccessObserver> myObserver1 = sptr(new (std::nothrow) MyObserver());
|
|
|
|
sptr<IFileAccessObserver> myObserver2 = sptr(new (std::nothrow) MyObserver());
|
|
|
|
sptr<IFileAccessObserver> myObserver3 = sptr(new (std::nothrow) MyObserver());
|
|
|
|
sptr<IFileAccessObserver> myObserver4 = sptr(new (std::nothrow) MyObserver());
|
2024-10-14 08:37:08 +00:00
|
|
|
Uri parentUri(info[0].uri);
|
2024-02-28 07:39:14 +00:00
|
|
|
auto [newDirUriTest1, newDirUriTest2, newFileUri1, newFileUri2] =
|
|
|
|
ReadyRegisterNotify00(parentUri, myObserver1, myObserver2, myObserver3, myObserver4);
|
2023-08-22 02:35:14 +00:00
|
|
|
|
2024-02-28 07:39:14 +00:00
|
|
|
auto [renameDirUri1, renameUri1] = TriggerNotify00(newDirUriTest1, newDirUriTest2, newFileUri1, newFileUri2);
|
2023-08-22 02:35:14 +00:00
|
|
|
|
|
|
|
sleep(1);
|
|
|
|
result = g_fah->UnregisterNotify(newDirUriTest1, myObserver1);
|
|
|
|
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
|
|
|
result = g_fah->UnregisterNotify(newDirUriTest2, myObserver2);
|
|
|
|
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
|
|
|
result = g_fah->UnregisterNotify(newFileUri1, myObserver3);
|
|
|
|
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
|
|
|
result = g_fah->UnregisterNotify(newFileUri2, myObserver4);
|
|
|
|
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
|
|
|
result = g_fah->Delete(renameDirUri1);
|
|
|
|
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
|
|
|
result = g_fah->Delete(renameUri1);
|
|
|
|
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
|
|
|
} catch (...) {
|
|
|
|
GTEST_LOG_(ERROR) << "external_file_access_notify_0000 occurs an exception.";
|
|
|
|
}
|
|
|
|
GTEST_LOG_(INFO) << "FileExtensionNotifyTest-end external_file_access_notify_0000";
|
|
|
|
}
|
|
|
|
|
2024-02-28 07:39:14 +00:00
|
|
|
static tuple<Uri, Uri, Uri> ReadyRegisterNotify01(Uri& parentUri, sptr<IFileAccessObserver> myObserver1,
|
|
|
|
sptr<IFileAccessObserver> myObserver2, sptr<IFileAccessObserver> myObserver3)
|
|
|
|
{
|
|
|
|
bool notifyForDescendants1 = true;
|
|
|
|
bool notifyForDescendants2 = false;
|
|
|
|
Uri newFileUri1("");
|
2024-07-06 08:01:52 +00:00
|
|
|
EXPECT_NE(g_fah, nullptr);
|
2024-02-28 07:39:14 +00:00
|
|
|
int result = g_fah->CreateFile(parentUri, "uri_file1", newFileUri1);
|
|
|
|
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
|
|
|
Uri newFileUri2("");
|
|
|
|
result = g_fah->CreateFile(parentUri, "uri_file2", newFileUri2);
|
|
|
|
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
|
|
|
Uri newFileUri3("");
|
|
|
|
result = g_fah->CreateFile(parentUri, "uri_file3", newFileUri3);
|
|
|
|
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
|
|
|
|
|
|
|
result = g_fah->RegisterNotify(newFileUri1, notifyForDescendants1, myObserver1);
|
|
|
|
EXPECT_GE(result, OHOS::FileAccessFwk::ERR_OK);
|
|
|
|
result = g_fah->RegisterNotify(newFileUri2, notifyForDescendants1, myObserver2);
|
|
|
|
EXPECT_GE(result, OHOS::FileAccessFwk::ERR_OK);
|
|
|
|
result = g_fah->RegisterNotify(newFileUri3, notifyForDescendants2, myObserver3);
|
|
|
|
EXPECT_GE(result, OHOS::FileAccessFwk::ERR_OK);
|
|
|
|
return {newFileUri1, newFileUri2, newFileUri3};
|
|
|
|
}
|
|
|
|
|
2023-08-22 02:35:14 +00:00
|
|
|
/**
|
|
|
|
* @tc.number: user_file_service_external_file_access_notify_0001
|
|
|
|
* @tc.name: external_file_access_notify_0001
|
|
|
|
* @tc.desc: Test function of RegisterNotify and UnregisterNotify interface for SUCCESS.
|
|
|
|
* @tc.size: MEDIUM
|
|
|
|
* @tc.type: FUNC
|
|
|
|
* @tc.level Level 1
|
|
|
|
* @tc.require: SR000H0386
|
|
|
|
*/
|
|
|
|
HWTEST_F(FileExtensionNotifyTest, external_file_access_notify_0001, testing::ext::TestSize.Level1)
|
|
|
|
{
|
|
|
|
GTEST_LOG_(INFO) << "FileExtensionNotifyTest-begin external_file_access_notify_0001";
|
|
|
|
try {
|
|
|
|
vector<RootInfo> info;
|
2024-07-06 08:01:52 +00:00
|
|
|
EXPECT_NE(g_fah, nullptr);
|
2023-08-22 02:35:14 +00:00
|
|
|
int result = g_fah->GetRoots(info);
|
|
|
|
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
2024-02-28 07:39:14 +00:00
|
|
|
|
2024-07-18 08:35:51 +00:00
|
|
|
sptr<IFileAccessObserver> myObserver1 = sptr(new (std::nothrow) MyObserver());
|
|
|
|
sptr<IFileAccessObserver> myObserver2 = sptr(new (std::nothrow) MyObserver());
|
|
|
|
sptr<IFileAccessObserver> myObserver3 = sptr(new (std::nothrow) MyObserver());
|
2024-10-14 08:37:08 +00:00
|
|
|
Uri parentUri(info[0].uri);
|
2024-02-28 07:39:14 +00:00
|
|
|
auto [newFileUri1, newFileUri2, newFileUri3] =
|
|
|
|
ReadyRegisterNotify01(parentUri, myObserver1, myObserver2, myObserver3);
|
2023-08-22 02:35:14 +00:00
|
|
|
|
2023-10-20 07:25:27 +00:00
|
|
|
Uri renameFileUri1("");
|
|
|
|
result = g_fah->Rename(newFileUri1, "renamefile", renameFileUri1);
|
|
|
|
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
|
|
|
usleep(SLEEP_TIME);
|
|
|
|
EXPECT_EQ(g_notifyEvent, MOVED_SELF);
|
|
|
|
EXPECT_EQ(g_notifyUri, newFileUri1.ToString());
|
2024-03-21 12:50:12 +00:00
|
|
|
|
2023-10-20 07:25:27 +00:00
|
|
|
result = g_fah->Delete(newFileUri2);
|
|
|
|
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
|
|
|
usleep(SLEEP_TIME);
|
2024-10-14 08:37:08 +00:00
|
|
|
EXPECT_EQ(g_notifyEvent, MOVED_SELF);
|
2023-10-20 07:25:27 +00:00
|
|
|
EXPECT_EQ(g_notifyUri, newFileUri2.ToString());
|
|
|
|
result = g_fah->Delete(newFileUri3);
|
|
|
|
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
|
|
|
usleep(SLEEP_TIME);
|
2024-10-14 08:37:08 +00:00
|
|
|
EXPECT_EQ(g_notifyEvent, MOVED_SELF);
|
2023-10-20 07:25:27 +00:00
|
|
|
EXPECT_EQ(g_notifyUri, newFileUri3.ToString());
|
|
|
|
|
|
|
|
sleep(1);
|
|
|
|
result = g_fah->UnregisterNotify(newFileUri1, myObserver1);
|
|
|
|
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
|
|
|
result = g_fah->UnregisterNotify(newFileUri2, myObserver2);
|
|
|
|
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
|
|
|
result = g_fah->UnregisterNotify(newFileUri3, myObserver3);
|
|
|
|
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
|
|
|
result = g_fah->Delete(renameFileUri1);
|
|
|
|
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
2023-08-22 02:35:14 +00:00
|
|
|
} catch (...) {
|
|
|
|
GTEST_LOG_(ERROR) << "external_file_access_notify_0001 occurs an exception.";
|
|
|
|
}
|
|
|
|
GTEST_LOG_(INFO) << "FileExtensionNotifyTest-end external_file_access_notify_0001";
|
|
|
|
}
|
|
|
|
|
2024-02-28 07:39:14 +00:00
|
|
|
static tuple<Uri, Uri, Uri, Uri> ReadyRegisterNotify02(Uri& parentUri)
|
|
|
|
{
|
|
|
|
Uri newDirUriTest1("");
|
2024-07-06 08:01:52 +00:00
|
|
|
EXPECT_NE(g_fah, nullptr);
|
2024-02-28 07:39:14 +00:00
|
|
|
int result = g_fah->Mkdir(parentUri, "uri_dir1", newDirUriTest1);
|
|
|
|
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
|
|
|
Uri newDirUriTest2("");
|
|
|
|
result = g_fah->Mkdir(parentUri, "uri_dir2", newDirUriTest2);
|
|
|
|
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
|
|
|
Uri newFileUri1("");
|
|
|
|
result = g_fah->CreateFile(parentUri, "uri_file1", newFileUri1);
|
|
|
|
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
|
|
|
Uri newFileUri2("");
|
|
|
|
result = g_fah->CreateFile(parentUri, "uri_file2", newFileUri2);
|
|
|
|
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
|
|
|
|
|
|
|
return {newDirUriTest1, newDirUriTest2, newFileUri1, newFileUri2};
|
|
|
|
}
|
|
|
|
|
|
|
|
static tuple<Uri, Uri> TriggerNotify02(Uri& newDirUriTest1, Uri& newDirUriTest2, Uri& newFileUri1, Uri& newFileUri2)
|
|
|
|
{
|
|
|
|
const int tm = 2;
|
|
|
|
Uri testFile("");
|
2024-07-06 08:01:52 +00:00
|
|
|
EXPECT_NE(g_fah, nullptr);
|
2024-02-28 07:39:14 +00:00
|
|
|
int result = g_fah->CreateFile(newDirUriTest1, "test_file", testFile);
|
|
|
|
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
|
|
|
usleep(SLEEP_TIME);
|
|
|
|
Uri renameDirUri1("");
|
|
|
|
result = g_fah->Rename(newDirUriTest1, "renameDir", renameDirUri1);
|
|
|
|
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
|
|
|
usleep(SLEEP_TIME);
|
|
|
|
EXPECT_EQ(g_notifyEvent, MOVED_SELF);
|
|
|
|
EXPECT_EQ(g_notifyUri, newDirUriTest1.ToString());
|
|
|
|
result = g_fah->Delete(newDirUriTest2);
|
|
|
|
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
|
|
|
usleep(SLEEP_TIME);
|
2024-10-14 08:37:08 +00:00
|
|
|
EXPECT_EQ(g_notifyEvent, MOVED_SELF);
|
2024-02-28 07:39:14 +00:00
|
|
|
EXPECT_EQ(g_notifyUri, newDirUriTest2.ToString());
|
|
|
|
Uri renameFileUri1("");
|
|
|
|
result = g_fah->Rename(newFileUri1, "renamefile", renameFileUri1);
|
|
|
|
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
|
|
|
usleep(SLEEP_TIME);
|
|
|
|
EXPECT_EQ(g_notifyEvent, MOVED_SELF);
|
|
|
|
EXPECT_EQ(g_notifyUri, newFileUri1.ToString());
|
|
|
|
result = g_fah->Delete(newFileUri2);
|
|
|
|
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
|
|
|
usleep(SLEEP_TIME);
|
2024-10-14 08:37:08 +00:00
|
|
|
EXPECT_EQ(g_notifyEvent, MOVED_SELF);
|
2024-02-28 07:39:14 +00:00
|
|
|
EXPECT_EQ(g_notifyUri, newFileUri2.ToString());
|
|
|
|
sleep(tm);
|
|
|
|
return {renameDirUri1, renameFileUri1};
|
|
|
|
}
|
2023-08-22 02:35:14 +00:00
|
|
|
/**
|
|
|
|
* @tc.number: user_file_service_external_file_access_notify_0002
|
|
|
|
* @tc.name: external_file_access_notify_0002
|
|
|
|
* @tc.desc: Test function of RegisterNotify and UnregisterNotify interface for SUCCESS.
|
|
|
|
* @tc.size: MEDIUM
|
|
|
|
* @tc.type: FUNC
|
|
|
|
* @tc.level Level 1
|
|
|
|
* @tc.require: SR000H0386
|
|
|
|
*/
|
|
|
|
HWTEST_F(FileExtensionNotifyTest, external_file_access_notify_0002, testing::ext::TestSize.Level1)
|
|
|
|
{
|
|
|
|
GTEST_LOG_(INFO) << "FileExtensionNotifyTest-begin external_file_access_notify_0002";
|
|
|
|
try {
|
|
|
|
vector<RootInfo> info;
|
2024-07-06 08:01:52 +00:00
|
|
|
EXPECT_NE(g_fah, nullptr);
|
2023-08-22 02:35:14 +00:00
|
|
|
int result = g_fah->GetRoots(info);
|
|
|
|
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
|
|
|
bool notifyForDescendants = true;
|
2024-02-28 07:39:14 +00:00
|
|
|
vector<sptr<IFileAccessObserver>> observers;
|
|
|
|
const int len = 12;
|
|
|
|
const int group = 3;
|
|
|
|
for (int i = 0; i < len; i++) {
|
|
|
|
observers.emplace_back(new (std::nothrow) MyObserver());
|
|
|
|
}
|
2024-10-14 08:37:08 +00:00
|
|
|
Uri parentUri(info[0].uri);
|
2024-02-28 07:39:14 +00:00
|
|
|
auto [newDirUriTest1, newDirUriTest2, newFileUri1, newFileUri2] = ReadyRegisterNotify02(parentUri);
|
2023-08-22 02:35:14 +00:00
|
|
|
|
2024-02-28 07:39:14 +00:00
|
|
|
for (int i = 0; i < group; i++) {
|
|
|
|
result = g_fah->RegisterNotify(newDirUriTest1, notifyForDescendants, observers[i]);
|
|
|
|
EXPECT_GE(result, OHOS::FileAccessFwk::ERR_OK);
|
|
|
|
result = g_fah->RegisterNotify(newDirUriTest2, notifyForDescendants, observers[3 + i]);
|
|
|
|
EXPECT_GE(result, OHOS::FileAccessFwk::ERR_OK);
|
|
|
|
result = g_fah->RegisterNotify(newFileUri1, notifyForDescendants, observers[6 + i]);
|
|
|
|
EXPECT_GE(result, OHOS::FileAccessFwk::ERR_OK);
|
|
|
|
result = g_fah->RegisterNotify(newFileUri2, notifyForDescendants, observers[9 + i]);
|
|
|
|
EXPECT_GE(result, OHOS::FileAccessFwk::ERR_OK);
|
|
|
|
}
|
2023-08-22 02:35:14 +00:00
|
|
|
|
2024-02-28 07:39:14 +00:00
|
|
|
auto [renameDirUri1, renameFileUri1] =
|
|
|
|
TriggerNotify02(newDirUriTest1, newDirUriTest2, newFileUri1, newFileUri2);
|
2023-08-22 02:35:14 +00:00
|
|
|
|
2024-02-28 07:39:14 +00:00
|
|
|
for (int i = 0; i < group; i++) {
|
|
|
|
result = g_fah->UnregisterNotify(newDirUriTest1, observers[i]);
|
|
|
|
EXPECT_GE(result, OHOS::FileAccessFwk::ERR_OK);
|
|
|
|
result = g_fah->UnregisterNotify(newDirUriTest2, observers[3 + i]);
|
|
|
|
EXPECT_GE(result, OHOS::FileAccessFwk::ERR_OK);
|
|
|
|
result = g_fah->UnregisterNotify(newFileUri1, observers[6 + i]);
|
|
|
|
EXPECT_GE(result, OHOS::FileAccessFwk::ERR_OK);
|
|
|
|
result = g_fah->UnregisterNotify(newFileUri2, observers[9 + i]);
|
|
|
|
EXPECT_GE(result, OHOS::FileAccessFwk::ERR_OK);
|
|
|
|
}
|
2023-08-22 02:35:14 +00:00
|
|
|
result = g_fah->Delete(renameDirUri1);
|
|
|
|
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
|
|
|
result = g_fah->Delete(renameFileUri1);
|
|
|
|
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
|
|
|
} catch (...) {
|
|
|
|
GTEST_LOG_(ERROR) << "external_file_access_notify_0002 occurs an exception.";
|
|
|
|
}
|
|
|
|
GTEST_LOG_(INFO) << "FileExtensionNotifyTest-end external_file_access_notify_0002";
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @tc.number: user_file_service_external_file_access_notify_0003
|
|
|
|
* @tc.name: external_file_access_notify_0003
|
|
|
|
* @tc.desc: Test function of RegisterNotify and UnregisterNotify interface for SUCCESS.
|
|
|
|
* @tc.size: MEDIUM
|
|
|
|
* @tc.type: FUNC
|
|
|
|
* @tc.level Level 1
|
|
|
|
* @tc.require: SR000H0386
|
|
|
|
*/
|
|
|
|
HWTEST_F(FileExtensionNotifyTest, external_file_access_notify_0003, testing::ext::TestSize.Level1)
|
|
|
|
{
|
|
|
|
GTEST_LOG_(INFO) << "FileExtensionNotifyTest-begin external_file_access_notify_0003";
|
|
|
|
try {
|
|
|
|
vector<RootInfo> info;
|
2024-07-06 08:01:52 +00:00
|
|
|
EXPECT_NE(g_fah, nullptr);
|
2023-08-22 02:35:14 +00:00
|
|
|
int result = g_fah->GetRoots(info);
|
|
|
|
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
|
|
|
bool notifyForDescendants = true;
|
2024-07-18 08:35:51 +00:00
|
|
|
sptr<IFileAccessObserver> myObserver1 = sptr(new (std::nothrow) MyObserver());
|
|
|
|
sptr<IFileAccessObserver> myObserver2 = sptr(new (std::nothrow) MyObserver());
|
2024-10-14 08:37:08 +00:00
|
|
|
Uri parentUri(info[0].uri);
|
2023-10-20 07:25:27 +00:00
|
|
|
Uri newDirUriTest1("");
|
|
|
|
result = g_fah->Mkdir(parentUri, "uri_dir1", newDirUriTest1);
|
|
|
|
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
|
|
|
Uri newFileUri1("");
|
|
|
|
result = g_fah->CreateFile(parentUri, "uri_file1", newFileUri1);
|
|
|
|
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
|
|
|
result = g_fah->RegisterNotify(newDirUriTest1, notifyForDescendants, myObserver1);
|
|
|
|
EXPECT_GE(result, OHOS::FileAccessFwk::ERR_OK);
|
|
|
|
result = g_fah->RegisterNotify(newDirUriTest1, notifyForDescendants, myObserver1);
|
|
|
|
EXPECT_GE(result, OHOS::FileAccessFwk::ERR_OK);
|
2023-08-22 02:35:14 +00:00
|
|
|
|
2023-10-20 07:25:27 +00:00
|
|
|
result = g_fah->RegisterNotify(newFileUri1, notifyForDescendants, myObserver2);
|
|
|
|
EXPECT_GE(result, OHOS::FileAccessFwk::ERR_OK);
|
|
|
|
result = g_fah->RegisterNotify(newFileUri1, notifyForDescendants, myObserver2);
|
|
|
|
EXPECT_GE(result, OHOS::FileAccessFwk::ERR_OK);
|
|
|
|
result = g_fah->UnregisterNotify(newDirUriTest1);
|
|
|
|
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
|
|
|
result = g_fah->UnregisterNotify(newFileUri1);
|
|
|
|
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
|
|
|
result = g_fah->Delete(newDirUriTest1);
|
|
|
|
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
|
|
|
result = g_fah->Delete(newFileUri1);
|
|
|
|
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
2023-08-22 02:35:14 +00:00
|
|
|
} catch (...) {
|
|
|
|
GTEST_LOG_(ERROR) << "external_file_access_notify_0003 occurs an exception.";
|
|
|
|
}
|
|
|
|
GTEST_LOG_(INFO) << "FileExtensionNotifyTest-end external_file_access_notify_0003";
|
|
|
|
}
|
|
|
|
|
2024-02-28 07:39:14 +00:00
|
|
|
static tuple<Uri, Uri, Uri, Uri> ReadyRegisterNotify05(Uri& parentUri, sptr<IFileAccessObserver>& myObserver1)
|
|
|
|
{
|
|
|
|
bool notifyForDescendants = true;
|
|
|
|
Uri uri_dir("");
|
2024-07-06 08:01:52 +00:00
|
|
|
EXPECT_NE(g_fah, nullptr);
|
2024-02-28 07:39:14 +00:00
|
|
|
int result = g_fah->Mkdir(parentUri, "uri_dir123", uri_dir);
|
|
|
|
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
|
|
|
Uri uri_dirSub1("");
|
|
|
|
result = g_fah->Mkdir(uri_dir, "uri_dirSub1", uri_dirSub1);
|
|
|
|
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
|
|
|
result = g_fah->RegisterNotify(uri_dir, notifyForDescendants, myObserver1);
|
|
|
|
EXPECT_GE(result, OHOS::FileAccessFwk::ERR_OK);
|
|
|
|
result = g_fah->RegisterNotify(uri_dirSub1, notifyForDescendants, myObserver1);
|
|
|
|
EXPECT_GE(result, OHOS::FileAccessFwk::ERR_OK);
|
|
|
|
Uri uri_dirSub2("");
|
|
|
|
result = g_fah->Mkdir(uri_dir, "uri_dirSub2", uri_dirSub2);
|
|
|
|
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
|
|
|
usleep(SLEEP_TIME);
|
|
|
|
EXPECT_EQ(g_notifyEvent, ADD_EVENT);
|
|
|
|
EXPECT_EQ(g_notifyUri, uri_dirSub2.ToString());
|
|
|
|
result = g_fah->RegisterNotify(uri_dirSub2, notifyForDescendants, myObserver1);
|
|
|
|
EXPECT_GE(result, OHOS::FileAccessFwk::ERR_OK);
|
|
|
|
Uri renameDirUri1("");
|
|
|
|
result = g_fah->Rename(uri_dirSub2, "renameDir1", renameDirUri1);
|
|
|
|
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
|
|
|
usleep(SLEEP_TIME);
|
|
|
|
return {uri_dir, uri_dirSub1, uri_dirSub2, renameDirUri1};
|
|
|
|
}
|
|
|
|
|
2023-08-22 02:35:14 +00:00
|
|
|
/**
|
|
|
|
* @tc.number: user_file_service_external_file_access_notify_0005
|
|
|
|
* @tc.name: external_file_access_notify_0005
|
|
|
|
* @tc.desc: Test function of RegisterNotify and UnregisterNotify interface for SUCCESS.
|
|
|
|
* @tc.size: MEDIUM
|
|
|
|
* @tc.type: FUNC
|
|
|
|
* @tc.level Level 1
|
|
|
|
* @tc.require: SR000H0386
|
|
|
|
*/
|
|
|
|
HWTEST_F(FileExtensionNotifyTest, external_file_access_notify_0005, testing::ext::TestSize.Level1)
|
|
|
|
{
|
|
|
|
GTEST_LOG_(INFO) << "FileExtensionNotifyTest-begin external_file_access_notify_0005";
|
|
|
|
try {
|
|
|
|
vector<RootInfo> info;
|
2024-07-06 08:01:52 +00:00
|
|
|
EXPECT_NE(g_fah, nullptr);
|
2023-08-22 02:35:14 +00:00
|
|
|
int result = g_fah->GetRoots(info);
|
|
|
|
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
2024-07-18 08:35:51 +00:00
|
|
|
sptr<IFileAccessObserver> myObserver1 = sptr(new (std::nothrow) MyObserver());
|
2024-10-14 08:37:08 +00:00
|
|
|
Uri parentUri(info[0].uri);
|
2024-02-28 07:39:14 +00:00
|
|
|
auto [uri_dir, uri_dirSub1, uri_dirSub2, renameDirUri1] = ReadyRegisterNotify05(parentUri, myObserver1);
|
2023-10-20 07:25:27 +00:00
|
|
|
if (g_notifyEvent != MOVED_TO) {
|
|
|
|
if (g_notifyEvent != MOVED_SELF) {
|
|
|
|
EXPECT_EQ(g_notifyEvent, MOVED_FROM);
|
|
|
|
EXPECT_EQ(g_notifyUri, uri_dirSub2.ToString());
|
2023-08-22 02:35:14 +00:00
|
|
|
} else {
|
2023-10-20 07:25:27 +00:00
|
|
|
EXPECT_EQ(g_notifyEvent, MOVED_SELF);
|
|
|
|
EXPECT_EQ(g_notifyUri, uri_dirSub2.ToString());
|
2023-08-22 02:35:14 +00:00
|
|
|
}
|
2023-10-20 07:25:27 +00:00
|
|
|
} else {
|
|
|
|
EXPECT_EQ(g_notifyEvent, MOVED_TO);
|
|
|
|
EXPECT_EQ(g_notifyUri, renameDirUri1.ToString());
|
2023-08-22 02:35:14 +00:00
|
|
|
}
|
2023-10-20 07:25:27 +00:00
|
|
|
result = g_fah->Delete(uri_dirSub1);
|
|
|
|
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
|
|
|
usleep(SLEEP_TIME);
|
2024-11-06 10:31:11 +00:00
|
|
|
EXPECT_TRUE(g_notifyEvent == MOVED_FROM || g_notifyEvent == MOVED_SELF);
|
2023-10-20 07:25:27 +00:00
|
|
|
EXPECT_EQ(g_notifyUri, uri_dirSub1.ToString());
|
|
|
|
|
|
|
|
sleep(2);
|
|
|
|
result = g_fah->UnregisterNotify(uri_dir, myObserver1);
|
|
|
|
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
|
|
|
result = g_fah->Delete(renameDirUri1);
|
|
|
|
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
|
|
|
result = g_fah->Delete(uri_dir);
|
|
|
|
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
|
|
|
sleep(1);
|
2023-08-22 02:35:14 +00:00
|
|
|
} catch (...) {
|
|
|
|
GTEST_LOG_(ERROR) << "external_file_access_notify_0005 occurs an exception.";
|
|
|
|
}
|
|
|
|
GTEST_LOG_(INFO) << "FileExtensionNotifyTest-end external_file_access_notify_0005";
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @tc.number: user_file_service_external_file_access_notify_0006
|
|
|
|
* @tc.name: external_file_access_notify_0006
|
|
|
|
* @tc.desc: Duplicate UnregisterNotify failed.
|
|
|
|
* @tc.size: MEDIUM
|
|
|
|
* @tc.type: FUNC
|
|
|
|
* @tc.level Level 1
|
|
|
|
* @tc.require: SR000H0386
|
|
|
|
*/
|
|
|
|
HWTEST_F(FileExtensionNotifyTest, external_file_access_notify_0006, testing::ext::TestSize.Level1)
|
|
|
|
{
|
|
|
|
GTEST_LOG_(INFO) << "FileExtensionNotifyTest-begin external_file_access_notify_0006";
|
|
|
|
try {
|
|
|
|
vector<RootInfo> info;
|
2024-07-06 08:01:52 +00:00
|
|
|
EXPECT_NE(g_fah, nullptr);
|
2023-08-22 02:35:14 +00:00
|
|
|
int result = g_fah->GetRoots(info);
|
|
|
|
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
|
|
|
bool notifyForDescendants = true;
|
2024-07-18 08:35:51 +00:00
|
|
|
sptr<IFileAccessObserver> myObserver1 = sptr(new (std::nothrow) MyObserver());
|
2024-10-14 08:37:08 +00:00
|
|
|
Uri parentUri(info[0].uri);
|
2023-10-20 07:25:27 +00:00
|
|
|
Uri newFileUri1("");
|
|
|
|
result = g_fah->CreateFile(parentUri, "uri_file", newFileUri1);
|
|
|
|
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
|
|
|
result = g_fah->RegisterNotify(newFileUri1, notifyForDescendants, myObserver1);
|
|
|
|
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
|
|
|
result = g_fah->Delete(newFileUri1);
|
|
|
|
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
|
|
|
usleep(SLEEP_TIME);
|
2024-10-14 08:37:08 +00:00
|
|
|
EXPECT_EQ(g_notifyEvent, MOVED_SELF);
|
2023-10-20 07:25:27 +00:00
|
|
|
EXPECT_EQ(g_notifyUri, newFileUri1.ToString());
|
|
|
|
sleep(1);
|
|
|
|
result = g_fah->UnregisterNotify(newFileUri1, myObserver1);
|
|
|
|
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
|
|
|
result = g_fah->UnregisterNotify(newFileUri1, myObserver1);
|
|
|
|
EXPECT_NE(result, OHOS::FileAccessFwk::ERR_OK);
|
2023-08-22 02:35:14 +00:00
|
|
|
} catch (...) {
|
|
|
|
GTEST_LOG_(ERROR) << "external_file_access_notify_0006 occurs an exception.";
|
|
|
|
}
|
|
|
|
GTEST_LOG_(INFO) << "FileExtensionNotifyTest-end external_file_access_notify_0006";
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @tc.number: user_file_service_external_file_access_notify_0007
|
|
|
|
* @tc.name: external_file_access_notify_0007
|
|
|
|
* @tc.desc: Test function of RegisterNotify and UnregisterNotify failed when callback is Invalid.
|
|
|
|
* @tc.size: MEDIUM
|
|
|
|
* @tc.type: FUNC
|
|
|
|
* @tc.level Level 1
|
|
|
|
* @tc.require: SR000H0386
|
|
|
|
*/
|
|
|
|
HWTEST_F(FileExtensionNotifyTest, external_file_access_notify_0007, testing::ext::TestSize.Level1)
|
|
|
|
{
|
|
|
|
GTEST_LOG_(INFO) << "FileExtensionNotifyTest-begin external_file_access_notify_0007";
|
|
|
|
try {
|
|
|
|
vector<RootInfo> info;
|
2024-07-06 08:01:52 +00:00
|
|
|
EXPECT_NE(g_fah, nullptr);
|
2023-08-22 02:35:14 +00:00
|
|
|
int result = g_fah->GetRoots(info);
|
|
|
|
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
|
|
|
sptr<IFileAccessObserver> myObserver1 = nullptr;
|
|
|
|
bool notifyForDescendants = true;
|
2024-10-14 08:37:08 +00:00
|
|
|
Uri parentUri(info[0].uri);
|
2023-10-20 07:25:27 +00:00
|
|
|
Uri newFileUri1("");
|
|
|
|
result = g_fah->CreateFile(parentUri, "uri_file007", newFileUri1);
|
|
|
|
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
|
|
|
result = g_fah->RegisterNotify(newFileUri1, notifyForDescendants, myObserver1);
|
|
|
|
EXPECT_NE(result, OHOS::FileAccessFwk::ERR_OK);
|
|
|
|
result = g_fah->UnregisterNotify(newFileUri1, myObserver1);
|
|
|
|
EXPECT_NE(result, OHOS::FileAccessFwk::ERR_OK);
|
|
|
|
result = g_fah->Delete(newFileUri1);
|
|
|
|
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
2023-08-22 02:35:14 +00:00
|
|
|
} catch (...) {
|
|
|
|
GTEST_LOG_(ERROR) << "external_file_access_notify_0007 occurs an exception.";
|
|
|
|
}
|
|
|
|
GTEST_LOG_(INFO) << "FileExtensionNotifyTest-end external_file_access_notify_0007";
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @tc.number: user_file_service_external_file_access_notify_0008
|
|
|
|
* @tc.name: external_file_access_notify_0008
|
|
|
|
* @tc.desc: Test function of UnregisterNotify failed when uri is Invalid.
|
|
|
|
* @tc.size: MEDIUM
|
|
|
|
* @tc.type: FUNC
|
|
|
|
* @tc.level Level 1
|
|
|
|
* @tc.require: SR000H0386
|
|
|
|
*/
|
|
|
|
HWTEST_F(FileExtensionNotifyTest, external_file_access_notify_0008, testing::ext::TestSize.Level1)
|
|
|
|
{
|
|
|
|
GTEST_LOG_(INFO) << "FileExtensionNotifyTest-begin external_file_access_notify_0008";
|
|
|
|
try {
|
|
|
|
vector<RootInfo> info;
|
2024-07-06 08:01:52 +00:00
|
|
|
EXPECT_NE(g_fah, nullptr);
|
2023-08-22 02:35:14 +00:00
|
|
|
int result = g_fah->GetRoots(info);
|
|
|
|
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
2024-07-18 08:35:51 +00:00
|
|
|
sptr<IFileAccessObserver> myObserver1 = sptr(new (std::nothrow) MyObserver());
|
2023-08-22 02:35:14 +00:00
|
|
|
Uri newFileUri1("*/&%");
|
|
|
|
bool notifyForDescendants = true;
|
|
|
|
result = g_fah->RegisterNotify(newFileUri1, notifyForDescendants, myObserver1);
|
|
|
|
EXPECT_NE(result, OHOS::FileAccessFwk::ERR_OK);
|
|
|
|
result = g_fah->UnregisterNotify(newFileUri1, myObserver1);
|
|
|
|
EXPECT_NE(result, OHOS::FileAccessFwk::ERR_OK);
|
|
|
|
} catch (...) {
|
|
|
|
GTEST_LOG_(ERROR) << "external_file_access_notify_0008 occurs an exception.";
|
|
|
|
}
|
|
|
|
GTEST_LOG_(INFO) << "FileExtensionNotifyTest-end external_file_access_notify_0008";
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2024-02-28 07:39:14 +00:00
|
|
|
* @tc.number: user_file_service_external_file_access_notify_0009
|
2023-08-22 02:35:14 +00:00
|
|
|
* @tc.name: external_file_access_notify_0009
|
|
|
|
* @tc.desc: Test function of RegisterNotify and UnregisterNotify interface for SUCCESS when the file is Chinese name.
|
|
|
|
* @tc.size: MEDIUM
|
|
|
|
* @tc.type: FUNC
|
|
|
|
* @tc.level Level 1
|
|
|
|
* @tc.require: SR000H0386
|
|
|
|
*/
|
|
|
|
HWTEST_F(FileExtensionNotifyTest, external_file_access_notify_0009, testing::ext::TestSize.Level1)
|
|
|
|
{
|
|
|
|
GTEST_LOG_(INFO) << "FileExtensionNotifyTest-begin external_file_access_notify_0009";
|
|
|
|
try {
|
|
|
|
vector<RootInfo> info;
|
2024-07-06 08:01:52 +00:00
|
|
|
EXPECT_NE(g_fah, nullptr);
|
2023-08-22 02:35:14 +00:00
|
|
|
int result = g_fah->GetRoots(info);
|
|
|
|
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
|
|
|
bool notifyForDescendants = true;
|
2024-07-18 08:35:51 +00:00
|
|
|
sptr<IFileAccessObserver> myObserver1 = sptr(new (std::nothrow) MyObserver());
|
2024-10-14 08:37:08 +00:00
|
|
|
Uri parentUri(info[0].uri);
|
2023-10-20 07:25:27 +00:00
|
|
|
Uri newFileUri1("");
|
|
|
|
result = g_fah->CreateFile(parentUri, "测试文件", newFileUri1);
|
|
|
|
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
|
|
|
result = g_fah->RegisterNotify(newFileUri1, notifyForDescendants, myObserver1);
|
|
|
|
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
|
|
|
result = g_fah->Delete(newFileUri1);
|
|
|
|
usleep(SLEEP_TIME);
|
2024-10-14 08:37:08 +00:00
|
|
|
EXPECT_EQ(g_notifyEvent, MOVED_SELF);
|
2023-10-20 07:25:27 +00:00
|
|
|
EXPECT_EQ(g_notifyUri, newFileUri1.ToString());
|
|
|
|
sleep(1);
|
|
|
|
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
|
|
|
result = g_fah->UnregisterNotify(newFileUri1, myObserver1);
|
|
|
|
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
2023-08-22 02:35:14 +00:00
|
|
|
} catch (...) {
|
|
|
|
GTEST_LOG_(ERROR) << "external_file_access_notify_0009 occurs an exception.";
|
|
|
|
}
|
|
|
|
GTEST_LOG_(INFO) << "FileExtensionNotifyTest-end external_file_access_notify_0009";
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @tc.number: user_file_service_external_file_access_notify_0010
|
|
|
|
* @tc.name: external_file_access_notify_0010
|
|
|
|
* @tc.desc: Test function of UnregisterNotify interface for failed when the Uri and callback do not match.
|
|
|
|
* @tc.size: MEDIUM
|
|
|
|
* @tc.type: FUNC
|
|
|
|
* @tc.level Level 1
|
|
|
|
* @tc.require: SR000H0386
|
|
|
|
*/
|
|
|
|
HWTEST_F(FileExtensionNotifyTest, external_file_access_notify_0010, testing::ext::TestSize.Level1)
|
|
|
|
{
|
|
|
|
GTEST_LOG_(INFO) << "FileExtensionNotifyTest-begin external_file_access_notify_0010";
|
|
|
|
try {
|
|
|
|
vector<RootInfo> info;
|
2024-07-06 08:01:52 +00:00
|
|
|
EXPECT_NE(g_fah, nullptr);
|
2023-08-22 02:35:14 +00:00
|
|
|
int result = g_fah->GetRoots(info);
|
|
|
|
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
|
|
|
bool notifyForDescendants = true;
|
2024-07-18 08:35:51 +00:00
|
|
|
sptr<IFileAccessObserver> myObserver1 = sptr(new (std::nothrow) MyObserver());
|
|
|
|
sptr<IFileAccessObserver> myObserver2 = sptr(new (std::nothrow) MyObserver());
|
2024-10-14 08:37:08 +00:00
|
|
|
Uri parentUri(info[0].uri);
|
2023-10-20 07:25:27 +00:00
|
|
|
Uri newFileUri1("");
|
|
|
|
result = g_fah->CreateFile(parentUri, "uri_file1", newFileUri1);
|
|
|
|
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
|
|
|
Uri newFileUri2("");
|
|
|
|
result = g_fah->CreateFile(parentUri, "uri_file2", newFileUri2);
|
|
|
|
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
|
|
|
result = g_fah->RegisterNotify(newFileUri1, notifyForDescendants, myObserver1);
|
|
|
|
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
|
|
|
result = g_fah->RegisterNotify(newFileUri2, notifyForDescendants, myObserver2);
|
|
|
|
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
2023-08-22 02:35:14 +00:00
|
|
|
|
2023-10-20 07:25:27 +00:00
|
|
|
result = g_fah->UnregisterNotify(newFileUri1, myObserver2);
|
|
|
|
EXPECT_NE(result, OHOS::FileAccessFwk::ERR_OK);
|
|
|
|
result = g_fah->UnregisterNotify(newFileUri1, myObserver1);
|
|
|
|
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
|
|
|
result = g_fah->UnregisterNotify(newFileUri2, myObserver2);
|
|
|
|
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
|
|
|
result = g_fah->Delete(newFileUri1);
|
|
|
|
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
|
|
|
result = g_fah->Delete(newFileUri2);
|
|
|
|
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
2023-08-22 02:35:14 +00:00
|
|
|
} catch (...) {
|
|
|
|
GTEST_LOG_(ERROR) << "external_file_access_notify_0010 occurs an exception.";
|
|
|
|
}
|
|
|
|
GTEST_LOG_(INFO) << "FileExtensionNotifyTest-end external_file_access_notify_0010";
|
|
|
|
}
|
|
|
|
|
2024-02-28 07:39:14 +00:00
|
|
|
static tuple<Uri, Uri> ReadyRegisterNotify11(Uri& parentUri, Uri &newFileDir1, sptr<IFileAccessObserver>& myObserver1,
|
|
|
|
sptr<IFileAccessObserver>& myObserver2)
|
|
|
|
{
|
|
|
|
const int tm = SLEEP_TIME * 2;
|
|
|
|
bool notifyForDescendants1 = true;
|
2024-07-06 08:01:52 +00:00
|
|
|
EXPECT_NE(g_fah, nullptr);
|
2024-02-28 07:39:14 +00:00
|
|
|
int result = g_fah->Mkdir(parentUri, "uri_dir11", newFileDir1);
|
|
|
|
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
|
|
|
Uri newFileUri1("");
|
|
|
|
result = g_fah->CreateFile(newFileDir1, "uri_file11", newFileUri1);
|
|
|
|
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
|
|
|
sleep(1);
|
|
|
|
result = g_fah->RegisterNotify(newFileDir1, notifyForDescendants1, myObserver1);
|
|
|
|
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
|
|
|
result = g_fah->RegisterNotify(newFileUri1, notifyForDescendants1, myObserver2);
|
|
|
|
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
|
|
|
Uri renameFileUri1("");
|
|
|
|
result = g_fah->Rename(newFileUri1, "renamefile1", renameFileUri1);
|
|
|
|
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
|
|
|
usleep(tm);
|
|
|
|
|
|
|
|
return {newFileUri1, renameFileUri1};
|
|
|
|
}
|
|
|
|
|
2023-08-22 02:35:14 +00:00
|
|
|
/**
|
|
|
|
* @tc.number: user_file_service_external_file_access_notify_0011
|
|
|
|
* @tc.name: external_file_access_notify_0011
|
|
|
|
* @tc.desc: Test function of RegisterNotify interface for SUCCESS when set the notifyForDescendants to true and
|
|
|
|
* @tc.desc: then set to false
|
|
|
|
* @tc.size: MEDIUM
|
|
|
|
* @tc.type: FUNC
|
|
|
|
* @tc.level Level 1
|
|
|
|
* @tc.require: SR000H0386
|
|
|
|
*/
|
|
|
|
HWTEST_F(FileExtensionNotifyTest, external_file_access_notify_0011, testing::ext::TestSize.Level1)
|
|
|
|
{
|
|
|
|
GTEST_LOG_(INFO) << "FileExtensionNotifyTest-begin external_file_access_notify_0011";
|
|
|
|
try {
|
|
|
|
vector<RootInfo> info;
|
2024-07-06 08:01:52 +00:00
|
|
|
EXPECT_NE(g_fah, nullptr);
|
2023-08-22 02:35:14 +00:00
|
|
|
int result = g_fah->GetRoots(info);
|
|
|
|
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
|
|
|
bool notifyForDescendants2 = false;
|
2024-07-18 08:35:51 +00:00
|
|
|
sptr<IFileAccessObserver> myObserver1 = sptr(new (std::nothrow) TestObserver());
|
|
|
|
sptr<IFileAccessObserver> myObserver2 = sptr(new (std::nothrow) MyObserver());
|
2024-10-14 08:37:08 +00:00
|
|
|
Uri parentUri(info[0].uri);
|
2023-10-20 07:25:27 +00:00
|
|
|
Uri newFileDir1("");
|
2024-02-28 07:39:14 +00:00
|
|
|
auto [newFileUri1, renameFileUri1] =
|
|
|
|
ReadyRegisterNotify11(parentUri, newFileDir1, myObserver1, myObserver2);
|
2023-10-20 07:25:27 +00:00
|
|
|
usleep(SLEEP_TIME * 2);
|
|
|
|
if (g_notifyEvent != MOVED_TO) {
|
|
|
|
if (g_notifyEvent != MOVED_SELF) {
|
|
|
|
EXPECT_EQ(g_notifyEvent, MOVED_FROM);
|
|
|
|
EXPECT_EQ(g_notifyUri, newFileUri1.ToString());
|
2023-08-22 02:35:14 +00:00
|
|
|
} else {
|
2023-10-20 07:25:27 +00:00
|
|
|
EXPECT_EQ(g_notifyEvent, MOVED_SELF);
|
|
|
|
EXPECT_EQ(g_notifyUri, newFileUri1.ToString());
|
2023-08-22 02:35:14 +00:00
|
|
|
}
|
2023-10-20 07:25:27 +00:00
|
|
|
} else {
|
|
|
|
EXPECT_EQ(g_notifyEvent, MOVED_TO);
|
|
|
|
EXPECT_EQ(g_notifyUri, renameFileUri1.ToString());
|
2023-08-22 02:35:14 +00:00
|
|
|
}
|
2023-10-20 07:25:27 +00:00
|
|
|
result = g_fah->RegisterNotify(newFileDir1, notifyForDescendants2, myObserver1);
|
|
|
|
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
|
|
|
sleep(2);
|
|
|
|
result = g_fah->Delete(renameFileUri1);
|
|
|
|
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
|
|
|
usleep(SLEEP_TIME);
|
2024-10-14 08:37:08 +00:00
|
|
|
EXPECT_EQ(g_notifyEvent, MOVED_SELF);
|
2023-10-20 07:25:27 +00:00
|
|
|
EXPECT_EQ(g_notifyUri, newFileUri1.ToString());
|
2024-10-14 08:37:08 +00:00
|
|
|
EXPECT_NE(g_notifyFlag, MOVED_SELF);
|
2023-10-20 07:25:27 +00:00
|
|
|
|
|
|
|
sleep(1);
|
|
|
|
result = g_fah->UnregisterNotify(newFileDir1, myObserver1);
|
|
|
|
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
|
|
|
result = g_fah->UnregisterNotify(newFileUri1, myObserver2);
|
|
|
|
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
|
|
|
result = g_fah->Delete(newFileDir1);
|
|
|
|
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
2023-08-22 02:35:14 +00:00
|
|
|
} catch (...) {
|
|
|
|
GTEST_LOG_(ERROR) << "external_file_access_notify_0011 occurs an exception.";
|
|
|
|
}
|
|
|
|
GTEST_LOG_(INFO) << "FileExtensionNotifyTest-end external_file_access_notify_0011";
|
|
|
|
}
|
|
|
|
|
|
|
|
static void RegisterDirNotify(Uri parentUri, std::string dirName, IFileAccessObserver *observer)
|
|
|
|
{
|
|
|
|
Uri newDirUriTest("");
|
|
|
|
bool notifyForDescendants = true;
|
2024-07-06 08:01:52 +00:00
|
|
|
EXPECT_NE(g_fah, nullptr);
|
2023-08-22 02:35:14 +00:00
|
|
|
int result = g_fah->Mkdir(parentUri, dirName, newDirUriTest);
|
|
|
|
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
|
|
|
sptr<IFileAccessObserver> myObserver(observer);
|
|
|
|
result = g_fah->RegisterNotify(newDirUriTest, notifyForDescendants, myObserver);
|
|
|
|
EXPECT_GE(result, OHOS::FileAccessFwk::ERR_OK);
|
|
|
|
result = g_fah->Delete(newDirUriTest);
|
|
|
|
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
|
|
|
usleep(SLEEP_TIME);
|
2024-10-14 08:37:08 +00:00
|
|
|
EXPECT_EQ(g_notifyEvent, MOVED_SELF);
|
2023-08-22 02:35:14 +00:00
|
|
|
EXPECT_EQ(g_notifyUri, newDirUriTest.ToString());
|
|
|
|
sleep(2);
|
2023-10-13 04:57:57 +00:00
|
|
|
g_fah->UnregisterNotify(newDirUriTest, myObserver);
|
2023-08-22 02:35:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @tc.number: user_file_service_external_file_access_notify_0012
|
|
|
|
* @tc.name: external_file_access_notify_0012
|
|
|
|
* @tc.desc: Test function of RegisterNotify and UnregisterNotify interface for SUCCESS which Concurrent.
|
|
|
|
* @tc.size: MEDIUM
|
|
|
|
* @tc.type: FUNC
|
|
|
|
* @tc.level Level 1
|
|
|
|
* @tc.require: SR000H0386
|
|
|
|
*/
|
|
|
|
HWTEST_F(FileExtensionNotifyTest, external_file_access_notify_00012, testing::ext::TestSize.Level1)
|
|
|
|
{
|
|
|
|
GTEST_LOG_(INFO) << "FileExtensionNotifyTest-begin external_file_access_notify_00012";
|
|
|
|
try {
|
|
|
|
vector<RootInfo> info;
|
2024-07-06 08:01:52 +00:00
|
|
|
EXPECT_NE(g_fah, nullptr);
|
2023-08-22 02:35:14 +00:00
|
|
|
int result = g_fah->GetRoots(info);
|
|
|
|
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
2024-10-14 08:37:08 +00:00
|
|
|
Uri parentUri(info[0].uri);
|
2023-08-22 02:35:14 +00:00
|
|
|
Uri newFileUri1("");
|
|
|
|
GTEST_LOG_(INFO) << parentUri.ToString();
|
2024-07-18 08:35:51 +00:00
|
|
|
sptr<IFileAccessObserver> myObserver1 = sptr(new (std::nothrow) MyObserver());
|
2023-08-22 02:35:14 +00:00
|
|
|
for (int i = 0; i < INIT_THREADS_NUMBER; i++) {
|
|
|
|
std::thread execthread1(RegisterDirNotify, parentUri, "WatcherTest", myObserver1.GetRefPtr());
|
|
|
|
execthread1.join();
|
|
|
|
}
|
|
|
|
} catch (...) {
|
|
|
|
GTEST_LOG_(ERROR) << "external_file_access_notify_00012 occurs an exception.";
|
|
|
|
}
|
|
|
|
GTEST_LOG_(INFO) << "FileExtensionNotifyTest-end external_file_access_notify_00012";
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @tc.number: user_file_service_external_file_access_notify_0013
|
|
|
|
* @tc.name: external_file_access_notify_0013
|
|
|
|
* @tc.desc: Test function of RegisterNotify and UnregisterNotify interface for SUCCESS which Concurrent.
|
|
|
|
* @tc.size: MEDIUM
|
|
|
|
* @tc.type: FUNC
|
|
|
|
* @tc.level Level 1
|
|
|
|
* @tc.require: SR000H0386
|
|
|
|
*/
|
|
|
|
HWTEST_F(FileExtensionNotifyTest, external_file_access_notify_00013, testing::ext::TestSize.Level1)
|
|
|
|
{
|
|
|
|
GTEST_LOG_(INFO) << "FileExtensionNotifyTest-begin external_file_access_notify_00013";
|
|
|
|
try {
|
|
|
|
vector<RootInfo> info;
|
2024-07-06 08:01:52 +00:00
|
|
|
EXPECT_NE(g_fah, nullptr);
|
2023-08-22 02:35:14 +00:00
|
|
|
int result = g_fah->GetRoots(info);
|
|
|
|
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
2024-10-14 08:37:08 +00:00
|
|
|
Uri parentUri(info[0].uri);
|
2023-08-22 02:35:14 +00:00
|
|
|
GTEST_LOG_(INFO) << parentUri.ToString();
|
2024-07-18 08:35:51 +00:00
|
|
|
sptr<IFileAccessObserver> myObserver1 = sptr(new (std::nothrow) MyObserver());
|
2023-08-22 02:35:14 +00:00
|
|
|
std::thread execthread1(RegisterDirNotify, parentUri, "WatcherTest1", myObserver1.GetRefPtr());
|
|
|
|
execthread1.join();
|
|
|
|
std::thread execthread2(RegisterDirNotify, parentUri, "WatcherTest2", myObserver1.GetRefPtr());
|
|
|
|
execthread2.join();
|
|
|
|
std::thread execthread3(RegisterDirNotify, parentUri, "WatcherTest3", myObserver1.GetRefPtr());
|
|
|
|
execthread3.join();
|
|
|
|
} catch (...) {
|
|
|
|
GTEST_LOG_(ERROR) << "external_file_access_notify_00013 occurs an exception.";
|
|
|
|
}
|
|
|
|
GTEST_LOG_(INFO) << "FileExtensionNotifyTest-end external_file_access_notify_00013";
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @tc.number: user_file_service_external_file_access_notify_0014
|
|
|
|
* @tc.name: external_file_access_notify_0014
|
|
|
|
* @tc.desc: Test function of RegisterNotify and UnregisterNotify interface for SUCCESS which Concurrent.
|
|
|
|
* @tc.size: MEDIUM
|
|
|
|
* @tc.type: FUNC
|
|
|
|
* @tc.level Level 1
|
|
|
|
* @tc.require: SR000H0386
|
|
|
|
*/
|
|
|
|
HWTEST_F(FileExtensionNotifyTest, external_file_access_notify_00014, testing::ext::TestSize.Level1)
|
|
|
|
{
|
|
|
|
GTEST_LOG_(INFO) << "FileExtensionNotifyTest-begin external_file_access_notify_00014";
|
|
|
|
try {
|
|
|
|
vector<RootInfo> info;
|
2024-07-06 08:01:52 +00:00
|
|
|
EXPECT_NE(g_fah, nullptr);
|
2023-08-22 02:35:14 +00:00
|
|
|
int result = g_fah->GetRoots(info);
|
|
|
|
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
2024-10-14 08:37:08 +00:00
|
|
|
Uri parentUri(info[0].uri);
|
2023-08-22 02:35:14 +00:00
|
|
|
GTEST_LOG_(INFO) << parentUri.ToString();
|
2024-07-18 08:35:51 +00:00
|
|
|
sptr<IFileAccessObserver> myObserver1 = sptr(new (std::nothrow) MyObserver());
|
|
|
|
sptr<IFileAccessObserver> myObserver2 = sptr(new (std::nothrow) MyObserver());
|
|
|
|
sptr<IFileAccessObserver> myObserver3 = sptr(new (std::nothrow) MyObserver());
|
2023-08-22 02:35:14 +00:00
|
|
|
|
|
|
|
std::thread execthread1(RegisterDirNotify, parentUri, "WatcherTest", myObserver1.GetRefPtr());
|
|
|
|
execthread1.join();
|
|
|
|
sleep(1);
|
|
|
|
std::thread execthread2(RegisterDirNotify, parentUri, "WatcherTest", myObserver2.GetRefPtr());
|
|
|
|
execthread2.join();
|
|
|
|
sleep(1);
|
|
|
|
std::thread execthread3(RegisterDirNotify, parentUri, "WatcherTest", myObserver3.GetRefPtr());
|
|
|
|
execthread3.join();
|
|
|
|
} catch (...) {
|
|
|
|
GTEST_LOG_(ERROR) << "external_file_access_notify_00014 occurs an exception.";
|
|
|
|
}
|
|
|
|
GTEST_LOG_(INFO) << "FileExtensionNotifyTest-end external_file_access_notify_00014";
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @tc.number: user_file_service_external_file_access_notify_0015
|
|
|
|
* @tc.name: external_file_access_notify_0015
|
|
|
|
* @tc.desc: Test function of RegisterNotify and UnregisterNotify interface for SUCCESS which Concurrent.
|
|
|
|
* @tc.size: MEDIUM
|
|
|
|
* @tc.type: FUNC
|
|
|
|
* @tc.level Level 1
|
|
|
|
* @tc.require: SR000H0386
|
|
|
|
*/
|
|
|
|
HWTEST_F(FileExtensionNotifyTest, external_file_access_notify_00015, testing::ext::TestSize.Level1)
|
|
|
|
{
|
|
|
|
GTEST_LOG_(INFO) << "FileExtensionNotifyTest-begin external_file_access_notify_00015";
|
|
|
|
try {
|
|
|
|
vector<RootInfo> info;
|
2024-07-06 08:01:52 +00:00
|
|
|
EXPECT_NE(g_fah, nullptr);
|
2023-08-22 02:35:14 +00:00
|
|
|
int result = g_fah->GetRoots(info);
|
|
|
|
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
2024-10-14 08:37:08 +00:00
|
|
|
Uri parentUri(info[0].uri);
|
2023-08-22 02:35:14 +00:00
|
|
|
GTEST_LOG_(INFO) << parentUri.ToString();
|
2024-07-18 08:35:51 +00:00
|
|
|
sptr<IFileAccessObserver> myObserver1 = sptr(new (std::nothrow) MyObserver());
|
|
|
|
sptr<IFileAccessObserver> myObserver2 = sptr(new (std::nothrow) MyObserver());
|
|
|
|
sptr<IFileAccessObserver> myObserver3 = sptr(new (std::nothrow) MyObserver());
|
2023-08-22 02:35:14 +00:00
|
|
|
|
|
|
|
std::thread execthread1(RegisterDirNotify, parentUri, "WatcherTest1", myObserver1.GetRefPtr());
|
|
|
|
execthread1.join();
|
|
|
|
std::thread execthread2(RegisterDirNotify, parentUri, "WatcherTest2", myObserver2.GetRefPtr());
|
|
|
|
execthread2.join();
|
|
|
|
std::thread execthread3(RegisterDirNotify, parentUri, "WatcherTest3", myObserver3.GetRefPtr());
|
|
|
|
execthread3.join();
|
|
|
|
} catch (...) {
|
|
|
|
GTEST_LOG_(ERROR) << "external_file_access_notify_00015 occurs an exception.";
|
|
|
|
}
|
|
|
|
GTEST_LOG_(INFO) << "FileExtensionNotifyTest-end external_file_access_notify_00015";
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @tc.number: user_file_service_external_file_access_notify_0016
|
|
|
|
* @tc.name: external_file_access_notify_0016
|
|
|
|
* @tc.desc: Test UnregisterNotify all callbacks related to the current uri
|
|
|
|
* @tc.size: MEDIUM
|
|
|
|
* @tc.type: FUNC
|
|
|
|
* @tc.level Level 1
|
|
|
|
* @tc.require: SR000H0386
|
|
|
|
*/
|
|
|
|
HWTEST_F(FileExtensionNotifyTest, external_file_access_notify_0016, testing::ext::TestSize.Level1)
|
|
|
|
{
|
|
|
|
GTEST_LOG_(INFO) << "FileExtensionNotifyTest-begin external_file_access_notify_0016";
|
|
|
|
try {
|
|
|
|
vector<RootInfo> info;
|
2024-07-06 08:01:52 +00:00
|
|
|
EXPECT_NE(g_fah, nullptr);
|
2023-08-22 02:35:14 +00:00
|
|
|
int result = g_fah->GetRoots(info);
|
|
|
|
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
|
|
|
bool notifyForDescendants = true;
|
2024-07-18 08:35:51 +00:00
|
|
|
sptr<IFileAccessObserver> myObserver1 = sptr(new (std::nothrow) MyObserver());
|
|
|
|
sptr<IFileAccessObserver> myObserver2 = sptr(new (std::nothrow) MyObserver());
|
|
|
|
sptr<IFileAccessObserver> myObserver3 = sptr(new (std::nothrow) MyObserver());
|
2024-10-14 08:37:08 +00:00
|
|
|
Uri parentUri(info[0].uri);
|
2023-10-20 07:25:27 +00:00
|
|
|
Uri newFileDir1("");
|
|
|
|
result = g_fah->Mkdir(parentUri, "uri_dir0016", newFileDir1);
|
|
|
|
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
|
|
|
result = g_fah->RegisterNotify(newFileDir1, notifyForDescendants, myObserver1);
|
|
|
|
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
|
|
|
result = g_fah->RegisterNotify(newFileDir1, notifyForDescendants, myObserver2);
|
|
|
|
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
|
|
|
result = g_fah->RegisterNotify(newFileDir1, notifyForDescendants, myObserver3);
|
|
|
|
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
|
|
|
|
|
|
|
result = g_fah->UnregisterNotify(newFileDir1);
|
|
|
|
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
|
|
|
result = g_fah->UnregisterNotify(newFileDir1, myObserver1);
|
|
|
|
EXPECT_NE(result, OHOS::FileAccessFwk::ERR_OK);
|
|
|
|
|
|
|
|
result = g_fah->Delete(newFileDir1);
|
|
|
|
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
|
|
|
} catch (...) {
|
|
|
|
GTEST_LOG_(ERROR) << "external_file_access_notify_0016 occurs an exception.";
|
|
|
|
}
|
|
|
|
GTEST_LOG_(INFO) << "FileExtensionNotifyTest-end external_file_access_notify_0016";
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @tc.number: user_file_service_external_file_access_notify_0017
|
|
|
|
* @tc.name: external_file_access_notify_0017
|
|
|
|
* @tc.desc: Test event changes exceeding 500ms trigger callback
|
|
|
|
* @tc.size: MEDIUM
|
|
|
|
* @tc.type: FUNC
|
|
|
|
* @tc.level Level 1
|
|
|
|
* @tc.require: SR000H0386
|
|
|
|
*/
|
|
|
|
HWTEST_F(FileExtensionNotifyTest, external_file_access_notify_0017, testing::ext::TestSize.Level1)
|
|
|
|
{
|
|
|
|
GTEST_LOG_(INFO) << "FileExtensionNotifyTest-begin external_file_access_notify_0017";
|
|
|
|
try {
|
|
|
|
vector<RootInfo> info;
|
2024-07-06 08:01:52 +00:00
|
|
|
EXPECT_NE(g_fah, nullptr);
|
2023-10-20 07:25:27 +00:00
|
|
|
int result = g_fah->GetRoots(info);
|
|
|
|
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
|
|
|
bool notifyForDescendants = true;
|
2024-07-18 08:35:51 +00:00
|
|
|
sptr<IFileAccessObserver> myObserver1 = sptr(new (std::nothrow) MyObserver());
|
2024-10-14 08:37:08 +00:00
|
|
|
Uri parentUri(info[0].uri);
|
2023-10-20 07:25:27 +00:00
|
|
|
Uri newFileDir1("");
|
|
|
|
result = g_fah->Mkdir(parentUri, "uri_dir", newFileDir1);
|
|
|
|
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
|
|
|
result = g_fah->RegisterNotify(newFileDir1, notifyForDescendants, myObserver1);
|
|
|
|
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
|
|
|
Uri fileUri("");
|
|
|
|
result = g_fah->CreateFile(newFileDir1, "uri_file", fileUri);
|
|
|
|
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
|
|
|
usleep(SLEEP_TIME);
|
|
|
|
EXPECT_EQ(g_notifyEvent, ADD_EVENT);
|
|
|
|
|
|
|
|
result = g_fah->UnregisterNotify(newFileDir1, myObserver1);
|
|
|
|
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
2023-08-22 02:35:14 +00:00
|
|
|
|
2023-10-20 07:25:27 +00:00
|
|
|
result = g_fah->Delete(newFileDir1);
|
|
|
|
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
|
|
|
} catch (...) {
|
|
|
|
GTEST_LOG_(ERROR) << "external_file_access_notify_0017 occurs an exception.";
|
|
|
|
}
|
|
|
|
GTEST_LOG_(INFO) << "FileExtensionNotifyTest-end external_file_access_notify_0017";
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @tc.number: user_file_service_external_file_access_notify_0018
|
|
|
|
* @tc.name: external_file_access_notify_0018
|
|
|
|
* @tc.desc: Test event changes More than 32 notifications callback
|
|
|
|
* @tc.size: MEDIUM
|
|
|
|
* @tc.type: FUNC
|
|
|
|
* @tc.level Level 1
|
|
|
|
* @tc.require: SR000H0386
|
|
|
|
*/
|
|
|
|
HWTEST_F(FileExtensionNotifyTest, external_file_access_notify_0018, testing::ext::TestSize.Level1)
|
|
|
|
{
|
|
|
|
GTEST_LOG_(INFO) << "FileExtensionNotifyTest-begin external_file_access_notify_0018";
|
|
|
|
try {
|
|
|
|
vector<RootInfo> info;
|
2024-07-06 08:01:52 +00:00
|
|
|
EXPECT_NE(g_fah, nullptr);
|
2023-10-20 07:25:27 +00:00
|
|
|
int result = g_fah->GetRoots(info);
|
|
|
|
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
|
|
|
bool notifyForDescendants = true;
|
2024-07-18 08:35:51 +00:00
|
|
|
sptr<IFileAccessObserver> myObserver1 = sptr(new (std::nothrow) TestObserver());
|
2024-10-14 08:37:08 +00:00
|
|
|
Uri parentUri(info[0].uri);
|
2023-10-20 07:25:27 +00:00
|
|
|
Uri newFileDir1("");
|
|
|
|
result = g_fah->Mkdir(parentUri, "uri_dir", newFileDir1);
|
|
|
|
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
|
|
|
result = g_fah->RegisterNotify(newFileDir1, notifyForDescendants, myObserver1);
|
|
|
|
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
|
|
|
Uri fileUri("");
|
|
|
|
for (int i = 0; i < 64; i++) {
|
|
|
|
result = g_fah->CreateFile(newFileDir1, "uri_file" + to_string(i), fileUri);
|
2023-08-22 02:35:14 +00:00
|
|
|
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
2023-10-20 07:25:27 +00:00
|
|
|
}
|
|
|
|
sleep(1);
|
|
|
|
EXPECT_LE(g_notifyUris.size(), 32);
|
|
|
|
g_notifyUris.clear();
|
|
|
|
result = g_fah->UnregisterNotify(newFileDir1, myObserver1);
|
|
|
|
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
2023-08-22 02:35:14 +00:00
|
|
|
|
2023-10-20 07:25:27 +00:00
|
|
|
result = g_fah->Delete(newFileDir1);
|
|
|
|
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
|
|
|
} catch (...) {
|
|
|
|
GTEST_LOG_(ERROR) << "external_file_access_notify_0018 occurs an exception.";
|
|
|
|
}
|
|
|
|
GTEST_LOG_(INFO) << "FileExtensionNotifyTest-end external_file_access_notify_0018";
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @tc.number: user_file_service_external_file_access_notify_0019
|
|
|
|
* @tc.name: external_file_access_notify_0019
|
|
|
|
* @tc.desc: Test event changes More than one notifications callback
|
|
|
|
* @tc.size: MEDIUM
|
|
|
|
* @tc.type: FUNC
|
|
|
|
* @tc.level Level 1
|
|
|
|
* @tc.require: SR000H0386
|
|
|
|
*/
|
|
|
|
HWTEST_F(FileExtensionNotifyTest, external_file_access_notify_0019, testing::ext::TestSize.Level1)
|
|
|
|
{
|
|
|
|
GTEST_LOG_(INFO) << "FileExtensionNotifyTest-begin external_file_access_notify_0019";
|
|
|
|
try {
|
|
|
|
vector<RootInfo> info;
|
2024-07-06 08:01:52 +00:00
|
|
|
EXPECT_NE(g_fah, nullptr);
|
2023-10-20 07:25:27 +00:00
|
|
|
int result = g_fah->GetRoots(info);
|
|
|
|
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
|
|
|
bool notifyForDescendants = true;
|
2024-07-18 08:35:51 +00:00
|
|
|
sptr<IFileAccessObserver> myObserver1 = sptr(new (std::nothrow) TestObserver());
|
2024-10-14 08:37:08 +00:00
|
|
|
Uri parentUri(info[0].uri);
|
2023-10-20 07:25:27 +00:00
|
|
|
Uri newFileDir1("");
|
|
|
|
result = g_fah->Mkdir(parentUri, "uri_dir", newFileDir1);
|
|
|
|
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
|
|
|
result = g_fah->RegisterNotify(newFileDir1, notifyForDescendants, myObserver1);
|
|
|
|
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
|
|
|
Uri fileUri("");
|
|
|
|
for (int i = 0; i < 10; i++) {
|
|
|
|
result = g_fah->CreateFile(newFileDir1, "uri_file" + to_string(i), fileUri);
|
2023-08-22 02:35:14 +00:00
|
|
|
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
|
|
|
}
|
2023-10-20 07:25:27 +00:00
|
|
|
usleep(SLEEP_TIME);
|
|
|
|
EXPECT_GT(g_notifyUris.size(), 1);
|
|
|
|
g_notifyUris.clear();
|
|
|
|
result = g_fah->UnregisterNotify(newFileDir1, myObserver1);
|
|
|
|
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
|
|
|
|
|
|
|
result = g_fah->Delete(newFileDir1);
|
|
|
|
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
2023-08-22 02:35:14 +00:00
|
|
|
} catch (...) {
|
2023-10-20 07:25:27 +00:00
|
|
|
GTEST_LOG_(ERROR) << "external_file_access_notify_0019 occurs an exception.";
|
2023-08-22 02:35:14 +00:00
|
|
|
}
|
2023-10-20 07:25:27 +00:00
|
|
|
GTEST_LOG_(INFO) << "FileExtensionNotifyTest-end external_file_access_notify_0019";
|
2023-08-22 02:35:14 +00:00
|
|
|
}
|
2024-03-21 12:50:12 +00:00
|
|
|
|
|
|
|
HWTEST_F(FileExtensionNotifyTest, external_file_access_notify_0020, testing::ext::TestSize.Level1)
|
|
|
|
{
|
|
|
|
GTEST_LOG_(INFO) << "FileExtensionNotifyTest-begin external_file_access_notify_0020";
|
|
|
|
try {
|
|
|
|
g_notifyEvent = -1;
|
|
|
|
vector<RootInfo> info;
|
|
|
|
const char* perms[] = {
|
|
|
|
"ohos.permission.GET_BUNDLE_INFO_PRIVILEGED"
|
|
|
|
};
|
|
|
|
SetNativeToken("SetUpTestCase", perms, sizeof(perms) / sizeof(perms[0]));
|
2024-07-06 08:01:52 +00:00
|
|
|
EXPECT_NE(g_fah, nullptr);
|
2024-03-21 12:50:12 +00:00
|
|
|
int result = g_fah->GetRoots(info);
|
|
|
|
EXPECT_EQ(result, OHOS::FileAccessFwk::E_PERMISSION);
|
|
|
|
SetNativeToken();
|
|
|
|
result = g_fah->GetRoots(info);
|
|
|
|
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
|
|
|
|
|
|
|
bool notifyForDescendants = true;
|
2024-07-18 08:35:51 +00:00
|
|
|
sptr<IFileAccessObserver> myObserver1 = sptr(new (std::nothrow) MyObserver());
|
2024-10-14 08:37:08 +00:00
|
|
|
Uri parentUri(info[0].uri);
|
2024-03-21 12:50:12 +00:00
|
|
|
Uri newFileDir1("");
|
|
|
|
SetNativeToken("SetUpTestCase", perms, sizeof(perms) / sizeof(perms[0]));
|
|
|
|
result = g_fah->Mkdir(parentUri, "uri_dir", newFileDir1);
|
|
|
|
EXPECT_EQ(result, OHOS::FileAccessFwk::E_PERMISSION);
|
|
|
|
SetNativeToken();
|
|
|
|
result = g_fah->Mkdir(parentUri, "uri_dir", newFileDir1);
|
|
|
|
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
|
|
|
|
|
|
|
SetNativeToken("SetUpTestCase", perms, sizeof(perms) / sizeof(perms[0]));
|
|
|
|
result = g_fah->RegisterNotify(newFileDir1, notifyForDescendants, myObserver1);
|
|
|
|
EXPECT_EQ(result, OHOS::FileAccessFwk::E_PERMISSION);
|
|
|
|
|
|
|
|
result = g_fah->UnregisterNotify(newFileDir1, myObserver1);
|
|
|
|
EXPECT_EQ(result, OHOS::FileAccessFwk::E_PERMISSION);
|
|
|
|
|
|
|
|
result = g_fah->Delete(newFileDir1);
|
|
|
|
EXPECT_EQ(result, OHOS::FileAccessFwk::E_PERMISSION);
|
|
|
|
|
|
|
|
SetNativeToken();
|
|
|
|
result = g_fah->Delete(newFileDir1);
|
|
|
|
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
|
|
|
|
|
|
|
} catch (...) {
|
|
|
|
GTEST_LOG_(ERROR) << "external_file_access_notify_0020 occurs an exception.";
|
|
|
|
}
|
|
|
|
GTEST_LOG_(INFO) << "FileExtensionNotifyTest-end external_file_access_notify_0020";
|
|
|
|
}
|
2024-02-28 07:39:14 +00:00
|
|
|
} // namespace
|