diff --git a/test/unittest/BUILD.gn b/test/unittest/BUILD.gn index 1683754ed827831f3b58b898447b8b22d2b06648..5ed9c054c4860b6d3ebb67afd1c1879505081a16 100644 --- a/test/unittest/BUILD.gn +++ b/test/unittest/BUILD.gn @@ -16,6 +16,7 @@ group("unittest") { deps = [ "file_permission_native:file_permission_test", "file_share_native:file_share_test", + "file_share_ndk_test:unittest", "file_uri_native:file_uri_test", "file_uri_ndk_test:file_uri_ndk_test", "js_file_uri_test:FileUriTest", diff --git a/test/unittest/file_share_ndk_test/BUILD.gn b/test/unittest/file_share_ndk_test/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..75128bd0b0da90becbaf11378c2467913364f0fd --- /dev/null +++ b/test/unittest/file_share_ndk_test/BUILD.gn @@ -0,0 +1,23 @@ +# Copyright (C) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +import("//build/test.gni") + +#################################group######################################### +group("unittest") { + testonly = true + deps = [ + "file_share_nopermission_test:file_share_no_permission_ndk_test", + "file_share_permission_test:file_share_permission_ndk_test", + ] +} +############################################################################### diff --git a/test/unittest/file_share_ndk_test/file_share_nopermission_test/BUILD.gn b/test/unittest/file_share_ndk_test/file_share_nopermission_test/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..c457873de15762d8045f228e3fb539df96e4d1a4 --- /dev/null +++ b/test/unittest/file_share_ndk_test/file_share_nopermission_test/BUILD.gn @@ -0,0 +1,40 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/test.gni") +import("//foundation/filemanagement/app_file_service/app_file_service.gni") + +ohos_unittest("file_share_no_permission_ndk_test") { + module_out_path = "filemanagement/app_file_service" + include_dirs = [ + "include", + "${app_file_service_path}/interfaces/kits/ndk/fileshare/include", + "//third_party/googletest/include", + ] + + sources = [ "file_share_nopermission_test.cpp" ] + external_deps = [ + "ability_base:zuri", + "c_utils:utils", + "file_api:filemgmt_libn", + "hilog:libhilog", + "init:libbegetutil", + ] + + deps = [ + "${app_file_service_path}/interfaces/innerkits/native:fileshare_native", + "${app_file_service_path}/interfaces/kits/ndk/fileshare/src:ohfileshare", + "//third_party/googletest:gmock_main", + "//third_party/googletest:gtest_main", + ] +} diff --git a/test/unittest/file_share_ndk_test/file_share_nopermission_test/file_share_nopermission_test.cpp b/test/unittest/file_share_ndk_test/file_share_nopermission_test/file_share_nopermission_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f0eb77e7deaecc0d4f3d2bf470163530df6829d9 --- /dev/null +++ b/test/unittest/file_share_ndk_test/file_share_nopermission_test/file_share_nopermission_test.cpp @@ -0,0 +1,213 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include + +#include "common_func.h" +#include "error_code.h" +#include "oh_file_share.h" +#include "parameter.h" + +using namespace testing::ext; +using namespace OHOS::AppFileService; +namespace { +const std::string FILE_MANAGER_FULL_MOUNT_ENABLE_PARAMETER_STR = "const.filemanager.full_mount.enable"; +} // namespace + +static bool CheckFileManagerFullMountEnable() +{ + char value[] = "false"; + int retSystem = GetParameter(FILE_MANAGER_FULL_MOUNT_ENABLE_PARAMETER_STR.c_str(), "false", value, sizeof(value)); + if (retSystem > 0 && !std::strcmp(value, "true")) { + return true; + } + GTEST_LOG_(INFO) << "Not supporting all mounts"; + return false; +} + +namespace OHOS::AppFileService::ModuleFileShareNoPermission { + +class NDKFileShareNoPermissionTest : public testing::Test { +public: + static void SetUpTestCase(void) {}; + static void TearDownTestCase(void) {}; + void SetUp() {}; + void TearDown() {}; +}; + +/** + * @tc.name: OH_FileShare_PersistPermission_test + * @tc.desc: Test function of OH_FileShare_PersistPermission() interface for no permission. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: + */ +HWTEST_F(NDKFileShareNoPermissionTest, OH_FileShare_PersistPermission_test, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "OH_FileShare_PersistPermission_test start"; + char policyUriChar[] = "file://com.example.filesharea/storage"; + FileShare_PolicyInfo policy = {.uri = policyUriChar, + .length = sizeof(policyUriChar) - 1, + .operationMode = + FileShare_OperationMode::READ_MODE | FileShare_OperationMode::WRITE_MODE}; + FileShare_PolicyInfo policies[] = {policy}; + unsigned int policiesNum = sizeof(policies) / sizeof(policies[0]); + FileShare_PolicyErrorResult *result = nullptr; + unsigned int resultNum; + FileManagement_ErrCode ret = OH_FileShare_PersistPermission(policies, policiesNum, &result, &resultNum); + if (!CheckFileManagerFullMountEnable()) { + EXPECT_EQ(ret, E_DEVICE_NOT_SUPPORT); + } else { + EXPECT_EQ(ret, E_PERMISSION); + } + if (result != nullptr) { + OH_FileShare_ReleasePolicyErrorResult(result, resultNum); + } + GTEST_LOG_(INFO) << "OH_FileShare_PersistPermission_test end"; +} + +/** + * @tc.name: OH_FileShare_RevokePermission_test + * @tc.desc: Test function of OH_FileShare_RevokePermission() interface for no permission. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: + */ +HWTEST_F(NDKFileShareNoPermissionTest, OH_FileShare_RevokePermission_test, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "OH_FileShare_RevokePermission_test start"; + char policyUriChar[] = "file://com.example.filesharea/storage"; + FileShare_PolicyInfo policy = {.uri = policyUriChar, + .length = sizeof(policyUriChar) - 1, + .operationMode = + FileShare_OperationMode::READ_MODE | FileShare_OperationMode::WRITE_MODE}; + FileShare_PolicyInfo policies[] = {policy}; + unsigned int policiesNum = sizeof(policies) / sizeof(policies[0]); + FileShare_PolicyErrorResult *result = nullptr; + unsigned int resultNum; + FileManagement_ErrCode ret = OH_FileShare_RevokePermission(policies, policiesNum, &result, &resultNum); + if (!CheckFileManagerFullMountEnable()) { + EXPECT_EQ(ret, E_DEVICE_NOT_SUPPORT); + } else { + EXPECT_EQ(ret, E_PERMISSION); + } + if (result != nullptr) { + OH_FileShare_ReleasePolicyErrorResult(result, resultNum); + } + GTEST_LOG_(INFO) << "OH_FileShare_RevokePermission_test end"; +} + +/** + * @tc.name: OH_FileShare_ActivatePermission_test + * @tc.desc: Test function of OH_FileShare_ActivatePermission() interface for no permission. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: + */ +HWTEST_F(NDKFileShareNoPermissionTest, OH_FileShare_ActivatePermission_test, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "OH_FileShare_ActivatePermission_test start"; + char policyUriChar[] = "file://com.example.filesharea/storage"; + FileShare_PolicyInfo policy = {.uri = policyUriChar, + .length = sizeof(policyUriChar) - 1, + .operationMode = + FileShare_OperationMode::READ_MODE | FileShare_OperationMode::WRITE_MODE}; + FileShare_PolicyInfo policies[] = {policy}; + unsigned int policiesNum = sizeof(policies) / sizeof(policies[0]); + FileShare_PolicyErrorResult *result = nullptr; + unsigned int resultNum; + FileManagement_ErrCode ret = OH_FileShare_ActivatePermission(policies, policiesNum, &result, &resultNum); + if (!CheckFileManagerFullMountEnable()) { + EXPECT_EQ(ret, E_DEVICE_NOT_SUPPORT); + } else { + EXPECT_EQ(ret, E_PERMISSION); + } + if (result != nullptr) { + OH_FileShare_ReleasePolicyErrorResult(result, resultNum); + } + GTEST_LOG_(INFO) << "OH_FileShare_ActivatePermission_test end"; +} + +/** + * @tc.name: OH_FileShare_DeactivatePermission_test + * @tc.desc: Test function of OH_FileShare_DeactivatePermission() interface for no permission. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: + */ +HWTEST_F(NDKFileShareNoPermissionTest, OH_FileShare_DeactivatePermission_test, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "OH_FileShare_DeactivatePermission_test start"; + char policyUriChar[] = "file://com.example.filesharea/storage"; + FileShare_PolicyInfo policy = {.uri = policyUriChar, + .length = sizeof(policyUriChar) - 1, + .operationMode = + FileShare_OperationMode::READ_MODE | FileShare_OperationMode::WRITE_MODE}; + FileShare_PolicyInfo policies[] = {policy}; + unsigned int policiesNum = sizeof(policies) / sizeof(policies[0]); + FileShare_PolicyErrorResult *result = nullptr; + unsigned int resultNum; + FileManagement_ErrCode ret = OH_FileShare_DeactivatePermission(policies, policiesNum, &result, &resultNum); + if (!CheckFileManagerFullMountEnable()) { + EXPECT_EQ(ret, E_DEVICE_NOT_SUPPORT); + } else { + EXPECT_EQ(ret, E_PERMISSION); + } + if (result != nullptr) { + OH_FileShare_ReleasePolicyErrorResult(result, resultNum); + } + GTEST_LOG_(INFO) << "OH_FileShare_DeactivatePermission_test end"; +} + +/** + * @tc.name: OH_FileShare_CheckPersistentPermission_test + * @tc.desc: Test function of OH_FileShare_CheckPersistentPermission() interface for no permission. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: + */ +HWTEST_F(NDKFileShareNoPermissionTest, OH_FileShare_CheckPersistentPermission_test, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "OH_FileShare_CheckPersistentPermission_test start"; + char policyUriChar[] = "file://com.example.filesharea/storage"; + FileShare_PolicyInfo policy = {.uri = policyUriChar, + .length = sizeof(policyUriChar) - 1, + .operationMode = + FileShare_OperationMode::READ_MODE | FileShare_OperationMode::WRITE_MODE}; + FileShare_PolicyInfo policies[] = {policy}; + unsigned int policiesNum = sizeof(policies) / sizeof(policies[0]); + bool *result = nullptr; + unsigned int resultNum; + FileManagement_ErrCode ret = OH_FileShare_CheckPersistentPermission(policies, policiesNum, &result, &resultNum); + if (!CheckFileManagerFullMountEnable()) { + EXPECT_EQ(ret, E_DEVICE_NOT_SUPPORT); + } else { + EXPECT_EQ(ret, E_PERMISSION); + } + if (result != nullptr) { + free(result); + } + GTEST_LOG_(INFO) << "OH_FileShare_CheckPersistentPermission_test end"; +} + +} // namespace OHOS::AppFileService::ModuleFileShareNoPermission \ No newline at end of file diff --git a/test/unittest/file_share_ndk_test/file_share_permission_test/BUILD.gn b/test/unittest/file_share_ndk_test/file_share_permission_test/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..bbff7f9519c4f1e9cac4c83d00b9a63d0600771b --- /dev/null +++ b/test/unittest/file_share_ndk_test/file_share_permission_test/BUILD.gn @@ -0,0 +1,46 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/test.gni") +import("//foundation/filemanagement/app_file_service/app_file_service.gni") + +ohos_unittest("file_share_permission_ndk_test") { + module_out_path = "filemanagement/app_file_service" + include_dirs = [ + "include", + "${app_file_service_path}/interfaces/kits/ndk/fileshare/include", + "//third_party/googletest/include", + ] + resource_config_file = "../../resource/ohos_test.xml" + sources = [ "file_share_permission_test.cpp" ] + external_deps = [ + "ability_base:base", + "ability_base:want", + "ability_base:zuri", + "access_token:libaccesstoken_sdk", + "access_token:libnativetoken", + "access_token:libtoken_setproc", + "c_utils:utils", + "common_event_service:cesfwk_innerkits", + "hilog:libhilog", + "init:libbegetutil", + "ipc:ipc_core", + "samgr:samgr_proxy", + ] + deps = [ + "${app_file_service_path}/interfaces/innerkits/native:fileshare_native", + "${app_file_service_path}/interfaces/kits/ndk/fileshare/src:ohfileshare", + "//third_party/googletest:gmock_main", + "//third_party/googletest:gtest_main", + ] +} diff --git a/test/unittest/file_share_ndk_test/file_share_permission_test/file_share_permission_test.cpp b/test/unittest/file_share_ndk_test/file_share_permission_test/file_share_permission_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..eea2273097773681c50337f70b4ecaf70fa177ea --- /dev/null +++ b/test/unittest/file_share_ndk_test/file_share_permission_test/file_share_permission_test.cpp @@ -0,0 +1,844 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +#include +#include +#include +#include +#include +#include + +#include "access_token_error.h" +#include "accesstoken_kit.h" +#include "common_func.h" +#include "error_code.h" +#include "ipc_skeleton.h" +#include "log.h" +#include "oh_file_share.h" +#include "parameter.h" +#include "sandbox_helper.h" +#include "uri.h" + +#include "nativetoken_kit.h" +#include "permission_def.h" +#include "permission_state_full.h" +#include "token_setproc.h" + +using namespace testing::ext; +using namespace OHOS::AppFileService; +using namespace OHOS::Security::AccessToken; +namespace { +const std::string FILE_MANAGER_FULL_MOUNT_ENABLE_PARAMETER_STR = "const.filemanager.full_mount.enable"; +const unsigned int SET_ZERO = 0; +} // namespace + +namespace OHOS::AppFileService::ModuleFileSharePermission { + +void GrantNativePermission() +{ + const char **perms = new const char *[1]; + perms[0] = "ohos.permission.FILE_ACCESS_PERSIST"; + TokenInfoParams infoInstance = { + .dcapsNum = 0, + .permsNum = 1, + .aclsNum = 0, + .dcaps = nullptr, + .perms = perms, + .acls = nullptr, + .processName = "app_file_service", + .aplStr = "system_core", + }; + uint64_t tokenId = GetAccessTokenId(&infoInstance); + SetSelfTokenID(tokenId); + AccessTokenKit::ReloadNativeTokenInfo(); + delete[] perms; +} + +static bool CheckFileManagerFullMountEnable() +{ + char value[] = "false"; + int retSystem = GetParameter(FILE_MANAGER_FULL_MOUNT_ENABLE_PARAMETER_STR.c_str(), "false", value, sizeof(value)); + if (retSystem > 0 && !std::strcmp(value, "true")) { + return true; + } + GTEST_LOG_(INFO) << "Not supporting all mounts"; + return false; +} + +class NDKFileSharePermissionTest : public testing::Test { +public: + static void SetUpTestCase(void); + static void TearDownTestCase(void) {}; + void SetUp() {}; + void TearDown() {}; +}; + +void NDKFileSharePermissionTest::SetUpTestCase() +{ + GrantNativePermission(); +} + +/** + * @tc.name: OH_FileShare_PersistPermission_test_001 + * @tc.desc: Test function of OH_FileShare_PersistPermission() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: + */ +HWTEST_F(NDKFileSharePermissionTest, OH_FileShare_PersistPermission_test_001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "OH_FileShare_PersistPermission_test_001 start"; + char policyUriChar[] = "file://com.example.filesharea/data/storage/el2/base/PersistPermission.txt"; + FileShare_PolicyInfo policy = {.uri = policyUriChar, + .length = sizeof(policyUriChar) - 1, + .operationMode = + FileShare_OperationMode::READ_MODE | FileShare_OperationMode::WRITE_MODE}; + FileShare_PolicyInfo policies[] = {policy}; + unsigned int policiesNum = sizeof(policies) / sizeof(policies[0]); + FileShare_PolicyErrorResult *result = nullptr; + unsigned int resultNum; + FileManagement_ErrCode ret = OH_FileShare_PersistPermission(policies, policiesNum, &result, &resultNum); + if (!CheckFileManagerFullMountEnable()) { + EXPECT_EQ(ret, E_DEVICE_NOT_SUPPORT); + } else { + EXPECT_EQ(ret, E_NO_ERROR); + } + OH_FileShare_ReleasePolicyErrorResult(result, resultNum); + GTEST_LOG_(INFO) << "OH_FileShare_PersistPermission_test_001 end"; +} + +/** + * @tc.name: OH_FileShare_PersistPermission_test_002 + * @tc.desc: Test function of OH_FileShare_PersistPermission() interface for invalid path. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: + */ +HWTEST_F(NDKFileSharePermissionTest, OH_FileShare_PersistPermission_test_002, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "OH_FileShare_PersistPermission_test_002 start"; + char policyUriChar[] = "file://com.example.filesharea/data/storage/fileShare02.txt"; + FileShare_PolicyInfo policy = {.uri = policyUriChar, + .length = sizeof(policyUriChar) - 1, + .operationMode = + FileShare_OperationMode::READ_MODE | FileShare_OperationMode::WRITE_MODE}; + FileShare_PolicyInfo policies[] = {policy}; + unsigned int policiesNum = sizeof(policies) / sizeof(policies[0]); + FileShare_PolicyErrorResult *result = nullptr; + unsigned int resultNum; + FileManagement_ErrCode ret = OH_FileShare_PersistPermission(policies, policiesNum, &result, &resultNum); + if (!CheckFileManagerFullMountEnable()) { + EXPECT_EQ(ret, E_DEVICE_NOT_SUPPORT); + } else { + EXPECT_EQ(ret, E_EPERM); + if (result != nullptr) { + EXPECT_EQ(INVALID_PATH, result[0].code); + } else { + EXPECT_FALSE(true); + } + } + OH_FileShare_ReleasePolicyErrorResult(result, resultNum); + GTEST_LOG_(INFO) << "OH_FileShare_PersistPermission_test_002 end"; +} + +/** + * @tc.name: OH_FileShare_PersistPermission_test_003 + * @tc.desc: Test function of OH_FileShare_PersistPermission() interface for err params. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: + */ +HWTEST_F(NDKFileSharePermissionTest, OH_FileShare_PersistPermission_test_003, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "OH_FileShare_PersistPermission_test_003 start"; + FileShare_PolicyInfo *policies = nullptr; + unsigned int policiesNum = SET_ZERO; + FileShare_PolicyErrorResult *result = nullptr; + unsigned int resultNum; + FileManagement_ErrCode ret = OH_FileShare_PersistPermission(policies, policiesNum, &result, &resultNum); + if (!CheckFileManagerFullMountEnable()) { + EXPECT_EQ(ret, E_DEVICE_NOT_SUPPORT); + } else { + EXPECT_EQ(ret, E_PARAMS); + } + OH_FileShare_ReleasePolicyErrorResult(result, resultNum); + GTEST_LOG_(INFO) << "OH_FileShare_PersistPermission_test_003 end"; +} + +/** + * @tc.name: OH_FileShare_PersistPermission_test_004 + * @tc.desc: Test function of OH_FileShare_PersistPermission() interface for eperm. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: + */ +HWTEST_F(NDKFileSharePermissionTest, OH_FileShare_PersistPermission_test_004, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "OH_FileShare_PersistPermission_test_004 start"; + char policyUriCharA[] = "file://com.example.filesharea/data/storage/el2/base/PersistPermission.txt"; + char policyUriCharB[] = "file://com.example.filesharea/data/storage/fileShare04.txt"; + FileShare_PolicyInfo policyA = {.uri = policyUriCharA, + .length = sizeof(policyUriCharA) - 1, + .operationMode = + FileShare_OperationMode::READ_MODE | FileShare_OperationMode::WRITE_MODE}; + FileShare_PolicyInfo policyB = {.uri = policyUriCharB, + .length = sizeof(policyUriCharB) - 1, + .operationMode = + FileShare_OperationMode::READ_MODE | FileShare_OperationMode::WRITE_MODE}; + FileShare_PolicyInfo policies[] = {policyA, policyB}; + unsigned int policiesNum = sizeof(policies) / sizeof(policies[0]); + FileShare_PolicyErrorResult *result = nullptr; + unsigned int resultNum; + FileManagement_ErrCode ret = OH_FileShare_PersistPermission(policies, policiesNum, &result, &resultNum); + if (!CheckFileManagerFullMountEnable()) { + EXPECT_EQ(ret, E_DEVICE_NOT_SUPPORT); + } else { + EXPECT_EQ(ret, E_EPERM); + if (result != nullptr) { + EXPECT_EQ(INVALID_PATH, result[0].code); + } else { + EXPECT_FALSE(true); + } + } + OH_FileShare_ReleasePolicyErrorResult(result, resultNum); + GTEST_LOG_(INFO) << "OH_FileShare_PersistPermission_test_004 end"; +} + +/** + * @tc.name: OH_FileShare_RevokePermission_test_001 + * @tc.desc: Test function of OH_FileShare_RevokePermission() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: + */ +HWTEST_F(NDKFileSharePermissionTest, OH_FileShare_RevokePermission_test_001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "OH_FileShare_RevokePermission_test_001 start"; + char policyUriChar[] = "file://com.example.filesharea/data/storage/el2/base/RevokePermission.txt"; + FileShare_PolicyInfo policy = {.uri = policyUriChar, + .length = sizeof(policyUriChar) - 1, + .operationMode = + FileShare_OperationMode::READ_MODE | FileShare_OperationMode::WRITE_MODE}; + FileShare_PolicyInfo policies[] = {policy}; + unsigned int policiesNum = sizeof(policies) / sizeof(policies[0]); + FileShare_PolicyErrorResult *result = nullptr; + unsigned int resultNum; + FileManagement_ErrCode retPersist = OH_FileShare_PersistPermission(policies, policiesNum, &result, &resultNum); + if (!CheckFileManagerFullMountEnable()) { + EXPECT_EQ(retPersist, E_DEVICE_NOT_SUPPORT); + } else { + EXPECT_EQ(retPersist, E_NO_ERROR); + } + OH_FileShare_ReleasePolicyErrorResult(result, resultNum); + FileManagement_ErrCode ret = OH_FileShare_RevokePermission(policies, policiesNum, &result, &resultNum); + if (!CheckFileManagerFullMountEnable()) { + EXPECT_EQ(ret, E_DEVICE_NOT_SUPPORT); + } else { + EXPECT_EQ(ret, E_NO_ERROR); + } + OH_FileShare_ReleasePolicyErrorResult(result, resultNum); + GTEST_LOG_(INFO) << "OH_FileShare_RevokePermission_test_001 end"; +} + +/** + * @tc.name: OH_FileShare_RevokePermission_test_002 + * @tc.desc: Test function of OH_FileShare_RevokePermission() interface for invalid path. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: + */ +HWTEST_F(NDKFileSharePermissionTest, OH_FileShare_RevokePermission_test_002, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "OH_FileShare_RevokePermission_test_002 start"; + char policyUriChar[] = "file://com.example.filesharea/data/storage/fileShare02.txt"; + FileShare_PolicyInfo policy = {.uri = policyUriChar, + .length = sizeof(policyUriChar) - 1, + .operationMode = + FileShare_OperationMode::READ_MODE | FileShare_OperationMode::WRITE_MODE}; + FileShare_PolicyInfo policies[] = {policy}; + unsigned int policiesNum = sizeof(policies) / sizeof(policies[0]); + FileShare_PolicyErrorResult *result = nullptr; + unsigned int resultNum; + FileManagement_ErrCode ret = OH_FileShare_RevokePermission(policies, policiesNum, &result, &resultNum); + if (!CheckFileManagerFullMountEnable()) { + EXPECT_EQ(ret, E_DEVICE_NOT_SUPPORT); + } else { + EXPECT_EQ(ret, E_EPERM); + if (result != nullptr) { + EXPECT_EQ(INVALID_PATH, result[0].code); + } else { + EXPECT_FALSE(true); + } + } + OH_FileShare_ReleasePolicyErrorResult(result, resultNum); + GTEST_LOG_(INFO) << "OH_FileShare_RevokePermission_test_002 end"; +} + +/** + * @tc.name: OH_FileShare_RevokePermission_test_003 + * @tc.desc: Test function of OH_FileShare_RevokePermission() interface for err params. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: + */ +HWTEST_F(NDKFileSharePermissionTest, OH_FileShare_RevokePermission_test_003, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "OH_FileShare_RevokePermission_test_003 start"; + FileShare_PolicyInfo *policies = nullptr; + unsigned int policiesNum = SET_ZERO; + FileShare_PolicyErrorResult *result = nullptr; + unsigned int resultNum; + FileManagement_ErrCode ret = OH_FileShare_RevokePermission(policies, policiesNum, &result, &resultNum); + if (!CheckFileManagerFullMountEnable()) { + EXPECT_EQ(ret, E_DEVICE_NOT_SUPPORT); + } else { + EXPECT_EQ(ret, E_PARAMS); + } + OH_FileShare_ReleasePolicyErrorResult(result, resultNum); + GTEST_LOG_(INFO) << "OH_FileShare_RevokePermission_test_003 end"; +} + +/** + * @tc.name: OH_FileShare_RevokePermission_test_004 + * @tc.desc: Test function of OH_FileShare_RevokePermission() interface for eperm. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: + */ +HWTEST_F(NDKFileSharePermissionTest, OH_FileShare_RevokePermission_test_004, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "OH_FileShare_RevokePermission_test_004 start"; + char policyUriCharA[] = "file://com.example.filesharea/data/storage/el2/base/RevokePermission.txt"; + FileShare_PolicyInfo policyA = {.uri = policyUriCharA, + .length = sizeof(policyUriCharA) - 1, + .operationMode = + FileShare_OperationMode::READ_MODE | FileShare_OperationMode::WRITE_MODE}; + FileShare_PolicyInfo policiesA[] = {policyA}; + unsigned int policiesNumA = sizeof(policiesA) / sizeof(policiesA[0]); + FileShare_PolicyErrorResult *result = nullptr; + unsigned int resultNum; + FileManagement_ErrCode retPersist = OH_FileShare_PersistPermission(policiesA, policiesNumA, &result, &resultNum); + if (!CheckFileManagerFullMountEnable()) { + EXPECT_EQ(retPersist, E_DEVICE_NOT_SUPPORT); + } else { + EXPECT_EQ(retPersist, E_NO_ERROR); + } + OH_FileShare_ReleasePolicyErrorResult(result, resultNum); + char policyUriCharB[] = "file://com.example.filesharea/data/storage/fileShare04.txt"; + FileShare_PolicyInfo policyB = {.uri = policyUriCharB, + .length = sizeof(policyUriCharB) - 1, + .operationMode = + FileShare_OperationMode::READ_MODE | FileShare_OperationMode::WRITE_MODE}; + FileShare_PolicyInfo policies[] = {policyA, policyB}; + unsigned int policiesNum = sizeof(policies) / sizeof(policies[0]); + FileManagement_ErrCode ret = OH_FileShare_RevokePermission(policies, policiesNum, &result, &resultNum); + if (!CheckFileManagerFullMountEnable()) { + EXPECT_EQ(ret, E_DEVICE_NOT_SUPPORT); + } else { + EXPECT_EQ(ret, E_EPERM); + if (result != nullptr) { + EXPECT_EQ(INVALID_PATH, result[0].code); + } else { + EXPECT_FALSE(true); + } + } + OH_FileShare_ReleasePolicyErrorResult(result, resultNum); + GTEST_LOG_(INFO) << "OH_FileShare_RevokePermission_test_004 end"; +} + +/** + * @tc.name: OH_FileShare_ActivatePermission_test_001 + * @tc.desc: Test function of OH_FileShare_ActivatePermission() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: + */ +HWTEST_F(NDKFileSharePermissionTest, OH_FileShare_ActivatePermission_test_001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "OH_FileShare_ActivatePermission_test_001 start"; + char policyUriChar[] = "file://com.example.filesharea/data/storage/el2/base/ActivatePermission.txt"; + FileShare_PolicyInfo policy = {.uri = policyUriChar, + .length = sizeof(policyUriChar) - 1, + .operationMode = + FileShare_OperationMode::READ_MODE | FileShare_OperationMode::WRITE_MODE}; + FileShare_PolicyInfo policies[] = {policy}; + unsigned int policiesNum = sizeof(policies) / sizeof(policies[0]); + FileShare_PolicyErrorResult *result = nullptr; + unsigned int resultNum; + FileManagement_ErrCode retPersist = OH_FileShare_PersistPermission(policies, policiesNum, &result, &resultNum); + if (!CheckFileManagerFullMountEnable()) { + EXPECT_EQ(retPersist, E_DEVICE_NOT_SUPPORT); + } else { + EXPECT_EQ(retPersist, E_NO_ERROR); + } + OH_FileShare_ReleasePolicyErrorResult(result, resultNum); + FileManagement_ErrCode ret = OH_FileShare_ActivatePermission(policies, policiesNum, &result, &resultNum); + if (!CheckFileManagerFullMountEnable()) { + EXPECT_EQ(ret, E_DEVICE_NOT_SUPPORT); + } else { + EXPECT_EQ(ret, E_NO_ERROR); + } + OH_FileShare_ReleasePolicyErrorResult(result, resultNum); + GTEST_LOG_(INFO) << "OH_FileShare_ActivatePermission_test_001 end"; +} + +/** + * @tc.name: OH_FileShare_ActivatePermission_test_002 + * @tc.desc: Test function of OH_FileShare_ActivatePermission() interface for invalid path. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: + */ +HWTEST_F(NDKFileSharePermissionTest, OH_FileShare_ActivatePermission_test_002, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "OH_FileShare_ActivatePermission_test_002 start"; + char policyUriChar[] = "file://com.example.filesharea/data/storage/fileShare02.txt"; + FileShare_PolicyInfo policy = {.uri = policyUriChar, + .length = sizeof(policyUriChar) - 1, + .operationMode = + FileShare_OperationMode::READ_MODE | FileShare_OperationMode::WRITE_MODE}; + FileShare_PolicyInfo policies[] = {policy}; + unsigned int policiesNum = sizeof(policies) / sizeof(policies[0]); + FileShare_PolicyErrorResult *result = nullptr; + unsigned int resultNum; + FileManagement_ErrCode ret = OH_FileShare_ActivatePermission(policies, policiesNum, &result, &resultNum); + if (!CheckFileManagerFullMountEnable()) { + EXPECT_EQ(ret, E_DEVICE_NOT_SUPPORT); + } else { + EXPECT_EQ(ret, E_EPERM); + if (result != nullptr) { + EXPECT_EQ(INVALID_PATH, result[0].code); + } else { + EXPECT_FALSE(true); + } + } + OH_FileShare_ReleasePolicyErrorResult(result, resultNum); + GTEST_LOG_(INFO) << "OH_FileShare_ActivatePermission_test_002 end"; +} + +/** + * @tc.name: OH_FileShare_ActivatePermission_test_003 + * @tc.desc: Test function of OH_FileShare_ActivatePermission() interface for err params. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: + */ +HWTEST_F(NDKFileSharePermissionTest, OH_FileShare_ActivatePermission_test_003, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "OH_FileShare_ActivatePermission_test_003 start"; + FileShare_PolicyInfo *policies = nullptr; + unsigned int policiesNum = SET_ZERO; + FileShare_PolicyErrorResult *result = nullptr; + unsigned int resultNum; + FileManagement_ErrCode ret = OH_FileShare_ActivatePermission(policies, policiesNum, &result, &resultNum); + if (!CheckFileManagerFullMountEnable()) { + EXPECT_EQ(ret, E_DEVICE_NOT_SUPPORT); + } else { + EXPECT_EQ(ret, E_PARAMS); + } + OH_FileShare_ReleasePolicyErrorResult(result, resultNum); + GTEST_LOG_(INFO) << "OH_FileShare_ActivatePermission_test_003 end"; +} + +/** + * @tc.name: OH_FileShare_ActivatePermission_test_004 + * @tc.desc: Test function of OH_FileShare_ActivatePermission() interface for eperm. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: + */ +HWTEST_F(NDKFileSharePermissionTest, OH_FileShare_ActivatePermission_test_004, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "OH_FileShare_ActivatePermission_test_004 start"; + char policyUriCharA[] = "file://com.example.filesharea/data/storage/el2/base/ActivatePermission.txt"; + FileShare_PolicyInfo policyA = {.uri = policyUriCharA, + .length = sizeof(policyUriCharA) - 1, + .operationMode = + FileShare_OperationMode::READ_MODE | FileShare_OperationMode::WRITE_MODE}; + FileShare_PolicyInfo policiesA[] = {policyA}; + unsigned int policiesNumA = sizeof(policiesA) / sizeof(policiesA[0]); + FileShare_PolicyErrorResult *result = nullptr; + unsigned int resultNum; + FileManagement_ErrCode retPersist = OH_FileShare_PersistPermission(policiesA, policiesNumA, &result, &resultNum); + if (!CheckFileManagerFullMountEnable()) { + EXPECT_EQ(retPersist, E_DEVICE_NOT_SUPPORT); + } else { + EXPECT_EQ(retPersist, E_NO_ERROR); + } + OH_FileShare_ReleasePolicyErrorResult(result, resultNum); + char policyUriCharB[] = "file://com.example.filesharea/data/storage/fileShare04.txt"; + FileShare_PolicyInfo policyB = {.uri = policyUriCharB, + .length = sizeof(policyUriCharB) - 1, + .operationMode = + FileShare_OperationMode::READ_MODE | FileShare_OperationMode::WRITE_MODE}; + FileShare_PolicyInfo policies[] = {policyA, policyB}; + unsigned int policiesNum = sizeof(policies) / sizeof(policies[0]); + FileManagement_ErrCode ret = OH_FileShare_ActivatePermission(policies, policiesNum, &result, &resultNum); + if (!CheckFileManagerFullMountEnable()) { + EXPECT_EQ(ret, E_DEVICE_NOT_SUPPORT); + } else { + EXPECT_EQ(ret, E_EPERM); + if (result != nullptr) { + EXPECT_EQ(INVALID_PATH, result[0].code); + } else { + EXPECT_FALSE(true); + } + } + OH_FileShare_ReleasePolicyErrorResult(result, resultNum); + GTEST_LOG_(INFO) << "OH_FileShare_ActivatePermission_test_004 end"; +} + +/** + * @tc.name: OH_FileShare_DeactivatePermission_test_001 + * @tc.desc: Test function of OH_FileShare_DeactivatePermission() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: + */ +HWTEST_F(NDKFileSharePermissionTest, OH_FileShare_DeactivatePermission_test_001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "OH_FileShare_DeactivatePermission_test_001 start"; + char policyUriChar[] = "file://com.example.filesharea/data/storage/el2/base/DeactivatePermission.txt"; + FileShare_PolicyInfo policy = {.uri = policyUriChar, + .length = sizeof(policyUriChar) - 1, + .operationMode = + FileShare_OperationMode::READ_MODE | FileShare_OperationMode::WRITE_MODE}; + FileShare_PolicyInfo policies[] = {policy}; + unsigned int policiesNum = sizeof(policies) / sizeof(policies[0]); + FileShare_PolicyErrorResult *result = nullptr; + unsigned int resultNum; + FileManagement_ErrCode retPersist = OH_FileShare_PersistPermission(policies, policiesNum, &result, &resultNum); + if (!CheckFileManagerFullMountEnable()) { + EXPECT_EQ(retPersist, E_DEVICE_NOT_SUPPORT); + } else { + EXPECT_EQ(retPersist, E_NO_ERROR); + } + OH_FileShare_ReleasePolicyErrorResult(result, resultNum); + FileManagement_ErrCode retActivate = OH_FileShare_ActivatePermission(policies, policiesNum, &result, &resultNum); + if (!CheckFileManagerFullMountEnable()) { + EXPECT_EQ(retActivate, E_DEVICE_NOT_SUPPORT); + } else { + EXPECT_EQ(retActivate, E_NO_ERROR); + } + OH_FileShare_ReleasePolicyErrorResult(result, resultNum); + FileManagement_ErrCode ret = OH_FileShare_DeactivatePermission(policies, policiesNum, &result, &resultNum); + if (!CheckFileManagerFullMountEnable()) { + EXPECT_EQ(ret, E_DEVICE_NOT_SUPPORT); + } else { + EXPECT_EQ(ret, E_NO_ERROR); + } + OH_FileShare_ReleasePolicyErrorResult(result, resultNum); + GTEST_LOG_(INFO) << "OH_FileShare_DeactivatePermission_test_001 end"; +} + +/** + * @tc.name: OH_FileShare_DeactivatePermission_test_002 + * @tc.desc: Test function of OH_FileShare_DeactivatePermission() interface for invalid path. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: + */ +HWTEST_F(NDKFileSharePermissionTest, OH_FileShare_DeactivatePermission_test_002, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "OH_FileShare_DeactivatePermission_test_002 start"; + char policyUriChar[] = "file://com.example.filesharea/data/storage/fileShare02.txt"; + + FileShare_PolicyInfo policy = {.uri = policyUriChar, + .length = sizeof(policyUriChar) - 1, + .operationMode = + FileShare_OperationMode::READ_MODE | FileShare_OperationMode::WRITE_MODE}; + FileShare_PolicyInfo policies[] = {policy}; + unsigned int policiesNum = sizeof(policies) / sizeof(policies[0]); + FileShare_PolicyErrorResult *result = nullptr; + unsigned int resultNum; + FileManagement_ErrCode ret = OH_FileShare_DeactivatePermission(policies, policiesNum, &result, &resultNum); + if (!CheckFileManagerFullMountEnable()) { + EXPECT_EQ(ret, E_DEVICE_NOT_SUPPORT); + } else { + EXPECT_EQ(ret, E_EPERM); + if (result != nullptr) { + EXPECT_EQ(INVALID_PATH, result[0].code); + } else { + EXPECT_FALSE(true); + } + } + OH_FileShare_ReleasePolicyErrorResult(result, resultNum); + GTEST_LOG_(INFO) << "OH_FileShare_DeactivatePermission_test_002 end"; +} + +/** + * @tc.name: OH_FileShare_DeactivatePermission_test_003 + * @tc.desc: Test function of OH_FileShare_DeactivatePermission() interface for err params. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: + */ +HWTEST_F(NDKFileSharePermissionTest, OH_FileShare_DeactivatePermission_test_003, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "OH_FileShare_DeactivatePermission_test_003 start"; + FileShare_PolicyInfo *policies = nullptr; + unsigned int policiesNum = SET_ZERO; + FileShare_PolicyErrorResult *result = nullptr; + unsigned int resultNum; + FileManagement_ErrCode ret = OH_FileShare_DeactivatePermission(policies, policiesNum, &result, &resultNum); + if (!CheckFileManagerFullMountEnable()) { + EXPECT_EQ(ret, E_DEVICE_NOT_SUPPORT); + } else { + EXPECT_EQ(ret, E_PARAMS); + } + OH_FileShare_ReleasePolicyErrorResult(result, resultNum); + GTEST_LOG_(INFO) << "OH_FileShare_DeactivatePermission_test_003 end"; +} + +/** + * @tc.name: OH_FileShare_DeactivatePermission_test_004 + * @tc.desc: Test function of OH_FileShare_DeactivatePermission() interface for eperm. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: + */ +HWTEST_F(NDKFileSharePermissionTest, OH_FileShare_DeactivatePermission_test_004, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "OH_FileShare_DeactivatePermission_test_004 start"; + char policyUriCharA[] = "file://com.example.filesharea/data/storage/el2/base/DeactivatePermission.txt"; + FileShare_PolicyInfo policyA = {.uri = policyUriCharA, + .length = sizeof(policyUriCharA) - 1, + .operationMode = + FileShare_OperationMode::READ_MODE | FileShare_OperationMode::WRITE_MODE}; + FileShare_PolicyInfo policiesA[] = {policyA}; + unsigned int policiesNumA = sizeof(policiesA) / sizeof(policiesA[0]); + FileShare_PolicyErrorResult *result = nullptr; + unsigned int resultNum; + FileManagement_ErrCode retPersist = OH_FileShare_PersistPermission(policiesA, policiesNumA, &result, &resultNum); + if (!CheckFileManagerFullMountEnable()) { + EXPECT_EQ(retPersist, E_DEVICE_NOT_SUPPORT); + } else { + EXPECT_EQ(retPersist, E_NO_ERROR); + } + OH_FileShare_ReleasePolicyErrorResult(result, resultNum); + FileManagement_ErrCode retActivate = OH_FileShare_ActivatePermission(policiesA, policiesNumA, &result, &resultNum); + if (!CheckFileManagerFullMountEnable()) { + EXPECT_EQ(retActivate, E_DEVICE_NOT_SUPPORT); + } else { + EXPECT_EQ(retActivate, E_NO_ERROR); + } + OH_FileShare_ReleasePolicyErrorResult(result, resultNum); + char policyUriCharB[] = "file://com.example.filesharea/data/storage/fileShare04.txt"; + FileShare_PolicyInfo policyB = {.uri = policyUriCharB, + .length = sizeof(policyUriCharB) - 1, + .operationMode = + FileShare_OperationMode::READ_MODE | FileShare_OperationMode::WRITE_MODE}; + FileShare_PolicyInfo policies[] = {policyA, policyB}; + unsigned int policiesNum = sizeof(policies) / sizeof(policies[0]); + FileManagement_ErrCode ret = OH_FileShare_DeactivatePermission(policies, policiesNum, &result, &resultNum); + if (!CheckFileManagerFullMountEnable()) { + EXPECT_EQ(ret, E_DEVICE_NOT_SUPPORT); + } else { + EXPECT_EQ(ret, E_EPERM); + if (result != nullptr) { + EXPECT_EQ(INVALID_PATH, result[0].code); + } else { + EXPECT_FALSE(true); + } + } + OH_FileShare_ReleasePolicyErrorResult(result, resultNum); + GTEST_LOG_(INFO) << "OH_FileShare_DeactivatePermission_test_004 end"; +} + +/** + * @tc.name: OH_FileShare_CheckPersistentPermission_test_001 + * @tc.desc: Test function of OH_FileShare_CheckPersistentPermission() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: + */ +HWTEST_F(NDKFileSharePermissionTest, OH_FileShare_CheckPersistentPermission_test_001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "OH_FileShare_CheckPersistentPermission_test_001 start"; + char policyUriChar[] = "file://com.example.filesharea/data/storage/el2/base/CheckPersistentPermission.txt"; + FileShare_PolicyInfo policy = {.uri = policyUriChar, + .length = sizeof(policyUriChar) - 1, + .operationMode = + FileShare_OperationMode::READ_MODE | FileShare_OperationMode::WRITE_MODE}; + FileShare_PolicyInfo policies[] = {policy}; + unsigned int policiesNum = sizeof(policies) / sizeof(policies[0]); + FileShare_PolicyErrorResult *resultPersist = nullptr; + unsigned int resultPersistNum; + FileManagement_ErrCode retPersist = + OH_FileShare_PersistPermission(policies, policiesNum, &resultPersist, &resultPersistNum); + if (!CheckFileManagerFullMountEnable()) { + EXPECT_EQ(retPersist, E_DEVICE_NOT_SUPPORT); + } else { + EXPECT_EQ(retPersist, E_NO_ERROR); + } + OH_FileShare_ReleasePolicyErrorResult(resultPersist, resultPersistNum); + bool *result = nullptr; + unsigned int resultNum; + FileManagement_ErrCode ret = OH_FileShare_CheckPersistentPermission(policies, policiesNum, &result, &resultNum); + if (!CheckFileManagerFullMountEnable()) { + EXPECT_EQ(ret, E_DEVICE_NOT_SUPPORT); + } else { + EXPECT_EQ(ret, E_NO_ERROR); + if (result != nullptr) { + EXPECT_EQ(result[0], true); + } else { + EXPECT_FALSE(true); + } + } + if (result != nullptr) { + free(result); + } + GTEST_LOG_(INFO) << "OH_FileShare_CheckPersistentPermission_test_001 end"; +} + +/** + * @tc.name: OH_FileShare_CheckPersistentPermission_test_002 + * @tc.desc: Test function of OH_FileShare_CheckPersistentPermission() interface for invalid path. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: + */ +HWTEST_F(NDKFileSharePermissionTest, OH_FileShare_CheckPersistentPermission_test_002, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "OH_FileShare_CheckPersistentPermission_test_002 start"; + char policyUriChar[] = "file://com.example.filesharea/data/storage/fileShare02.txt"; + FileShare_PolicyInfo policy = {.uri = policyUriChar, + .length = sizeof(policyUriChar) - 1, + .operationMode = + FileShare_OperationMode::READ_MODE | FileShare_OperationMode::WRITE_MODE}; + FileShare_PolicyInfo policies[] = {policy}; + unsigned int policiesNum = sizeof(policies) / sizeof(policies[0]); + bool *result = nullptr; + unsigned int resultNum; + FileManagement_ErrCode ret = OH_FileShare_CheckPersistentPermission(policies, policiesNum, &result, &resultNum); + if (!CheckFileManagerFullMountEnable()) { + EXPECT_EQ(ret, E_DEVICE_NOT_SUPPORT); + } else { + EXPECT_EQ(ret, E_NO_ERROR); + if (result != nullptr) { + EXPECT_EQ(result[0], false); + } else { + EXPECT_FALSE(true); + } + } + if (result != nullptr) { + free(result); + } + GTEST_LOG_(INFO) << "OH_FileShare_CheckPersistentPermission_test_002 end"; +} + +/** + * @tc.name: OH_FileShare_CheckPersistentPermission_test_003 + * @tc.desc: Test function of OH_FileShare_CheckPersistentPermission() interface for err params. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: + */ +HWTEST_F(NDKFileSharePermissionTest, OH_FileShare_CheckPersistentPermission_test_003, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "OH_FileShare_CheckPersistentPermission_test_003 start"; + FileShare_PolicyInfo *policies = nullptr; + unsigned int policiesNum = SET_ZERO; + bool *result = nullptr; + unsigned int resultNum; + FileManagement_ErrCode ret = OH_FileShare_CheckPersistentPermission(policies, policiesNum, &result, &resultNum); + if (!CheckFileManagerFullMountEnable()) { + EXPECT_EQ(ret, E_DEVICE_NOT_SUPPORT); + } else { + EXPECT_EQ(ret, E_PARAMS); + } + if (result != nullptr) { + free(result); + } + GTEST_LOG_(INFO) << "OH_FileShare_CheckPersistentPermission_test_003 end"; +} + +/** + * @tc.name: OH_FileShare_CheckPersistentPermission_test_004 + * @tc.desc: Test function of OH_FileShare_CheckPersistentPermission() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: + */ +HWTEST_F(NDKFileSharePermissionTest, OH_FileShare_CheckPersistentPermission_test_004, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "OH_FileShare_CheckPersistentPermission_test_004 start"; + char policyUriCharA[] = "file://com.example.filesharea/data/storage/el2/base/CheckPersistentPermission.txt"; + FileShare_PolicyInfo policyA = {.uri = policyUriCharA, + .length = sizeof(policyUriCharA) - 1, + .operationMode = + FileShare_OperationMode::READ_MODE | FileShare_OperationMode::WRITE_MODE}; + FileShare_PolicyInfo policiesA[] = {policyA}; + unsigned int policiesNumA = sizeof(policiesA) / sizeof(policiesA[0]); + FileShare_PolicyErrorResult *resultPersist = nullptr; + unsigned int resultPersistNum; + FileManagement_ErrCode retPersist = + OH_FileShare_PersistPermission(policiesA, policiesNumA, &resultPersist, &resultPersistNum); + if (!CheckFileManagerFullMountEnable()) { + EXPECT_EQ(retPersist, E_DEVICE_NOT_SUPPORT); + } else { + EXPECT_EQ(retPersist, E_NO_ERROR); + } + OH_FileShare_ReleasePolicyErrorResult(resultPersist, resultPersistNum); + char policyUriCharB[] = "file://com.example.filesharea/data/storage/fileShare04.txt"; + FileShare_PolicyInfo policyB = {.uri = policyUriCharB, + .length = sizeof(policyUriCharB) - 1, + .operationMode = + FileShare_OperationMode::READ_MODE | FileShare_OperationMode::WRITE_MODE}; + FileShare_PolicyInfo policies[] = {policyA, policyB}; + unsigned int policiesNum = sizeof(policies) / sizeof(policies[0]); + bool *result = nullptr; + unsigned int resultNum; + FileManagement_ErrCode ret = OH_FileShare_CheckPersistentPermission(policies, policiesNum, &result, &resultNum); + if (!CheckFileManagerFullMountEnable()) { + EXPECT_EQ(ret, E_DEVICE_NOT_SUPPORT); + } else { + EXPECT_EQ(ret, E_NO_ERROR); + if (result != nullptr && resultNum == 2) { + EXPECT_EQ(result[0], true); + EXPECT_EQ(result[1], false); + } else { + EXPECT_FALSE(true); + } + } + if (result != nullptr) { + free(result); + } + GTEST_LOG_(INFO) << "OH_FileShare_CheckPersistentPermission_test_004 end"; +} +} // namespace OHOS::AppFileService::ModuleFileSharePermission diff --git a/test/unittest/resource/ActivatePermission.txt b/test/unittest/resource/ActivatePermission.txt new file mode 100644 index 0000000000000000000000000000000000000000..0426b9e5c97be51f89e4f5205598082a8eaeb3f7 --- /dev/null +++ b/test/unittest/resource/ActivatePermission.txt @@ -0,0 +1,13 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +ActivatePermission.txt diff --git a/test/unittest/resource/CheckPersistentPermission.txt b/test/unittest/resource/CheckPersistentPermission.txt new file mode 100644 index 0000000000000000000000000000000000000000..ab15164bdc265347a437a667416efddc0bc276ce --- /dev/null +++ b/test/unittest/resource/CheckPersistentPermission.txt @@ -0,0 +1,13 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +DeactivatePermission.txt diff --git a/test/unittest/resource/DeactivatePermission.txt b/test/unittest/resource/DeactivatePermission.txt new file mode 100644 index 0000000000000000000000000000000000000000..ab15164bdc265347a437a667416efddc0bc276ce --- /dev/null +++ b/test/unittest/resource/DeactivatePermission.txt @@ -0,0 +1,13 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +DeactivatePermission.txt diff --git a/test/unittest/resource/PersistPermission.txt b/test/unittest/resource/PersistPermission.txt new file mode 100644 index 0000000000000000000000000000000000000000..bc54a60d88fd21fded473598483dfeaa222c06ff --- /dev/null +++ b/test/unittest/resource/PersistPermission.txt @@ -0,0 +1,13 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +PersistPermission.txt diff --git a/test/unittest/resource/RevokePermission.txt b/test/unittest/resource/RevokePermission.txt new file mode 100644 index 0000000000000000000000000000000000000000..fb46d05bec650b13cb59c6ac4fe1b7072772817a --- /dev/null +++ b/test/unittest/resource/RevokePermission.txt @@ -0,0 +1,13 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +RevokePermission.txt diff --git a/test/unittest/resource/ohos_test.xml b/test/unittest/resource/ohos_test.xml index decd650866e23d5518826e511253ec623eabd205..998456e022b36b35d4421f14688232ce4d90e9ee 100644 --- a/test/unittest/resource/ohos_test.xml +++ b/test/unittest/resource/ohos_test.xml @@ -49,4 +49,13 @@