From 0bfe7eee761cabb2e3c8c13770c6220847f5a289 Mon Sep 17 00:00:00 2001 From: xuerunlong Date: Sun, 7 Apr 2024 18:39:22 +0800 Subject: [PATCH 1/5] =?UTF-8?q?tdd=E6=96=B0=E5=A2=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xuerunlong --- bundle.json | 2 +- interfaces/test/unittest/BUILD.gn | 4 +- interfaces/test/unittest/napi_test/BUILD.gn | 5 - interfaces/test/unittest/native_test/BUILD.gn | 78 ++++++++ .../native_test/environment_native_test.cpp | 58 ++++++ .../native_test/fileio_native_test.cpp | 71 +++++++ .../unittest/native_test/remote_uri_test.cpp | 176 ++++++++++++++++++ 7 files changed, 386 insertions(+), 8 deletions(-) create mode 100644 interfaces/test/unittest/native_test/BUILD.gn create mode 100644 interfaces/test/unittest/native_test/environment_native_test.cpp create mode 100644 interfaces/test/unittest/native_test/fileio_native_test.cpp create mode 100644 interfaces/test/unittest/native_test/remote_uri_test.cpp diff --git a/bundle.json b/bundle.json index 5edd58188..be8ea60a2 100644 --- a/bundle.json +++ b/bundle.json @@ -131,7 +131,7 @@ } ], "test": [ - "//foundation/filemanagement/file_api/interfaces/test/unittest:unittest" + "//foundation/filemanagement/file_api/interfaces/test/unittest:file_api_unit_test" ] } } diff --git a/interfaces/test/unittest/BUILD.gn b/interfaces/test/unittest/BUILD.gn index 9da141988..6917dd692 100644 --- a/interfaces/test/unittest/BUILD.gn +++ b/interfaces/test/unittest/BUILD.gn @@ -11,12 +11,12 @@ # See the License for the specific language governing permissions and # limitations under the License. -group("unittest") { +group("file_api_unit_test") { testonly = true deps = [ "class_file:class_file_test", "filemgmt_libn_test:filemgmt_libn_test", "napi_test:file_api_js_test", - "remote_uri:remote_uri_test", + "native_test:inner_kit_test", ] } diff --git a/interfaces/test/unittest/napi_test/BUILD.gn b/interfaces/test/unittest/napi_test/BUILD.gn index d0dbea092..3f12cc813 100644 --- a/interfaces/test/unittest/napi_test/BUILD.gn +++ b/interfaces/test/unittest/napi_test/BUILD.gn @@ -19,8 +19,3 @@ ohos_js_unittest("file_api_js_test") { hap_profile = "./config.json" certificate_profile = "./openharmony_sx.p7b" } - -group("unittest") { - testonly = true - deps = [ ":file_api_js_test" ] -} diff --git a/interfaces/test/unittest/native_test/BUILD.gn b/interfaces/test/unittest/native_test/BUILD.gn new file mode 100644 index 000000000..39191a6ce --- /dev/null +++ b/interfaces/test/unittest/native_test/BUILD.gn @@ -0,0 +1,78 @@ +# Copyright (c) 2022-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/file_api/file_api.gni") + +ohos_unittest("remote_uri_test") { + module_out_path = "filemanagement/file_api" + + resource_config_file = "../resource/ohos_test.xml" + + sources = [ "remote_uri_test.cpp" ] + + include_dirs = [ + "include", + "${file_api_path}/interfaces/kits/native/remote_uri", + ] + + deps = [ + "${file_api_path}/interfaces/kits/native:remote_uri_native", + "//third_party/googletest:gtest_main", + ] + + external_deps = [] +} + +ohos_unittest("environment_native_test") { + module_out_path = "filemanagement/file_api" + + resource_config_file = "../resource/ohos_test.xml" + + sources = [ "environment_native_test.cpp" ] + + include_dirs = [ "${file_api_path}/interfaces/kits/native/environment" ] + + deps = [ + "${file_api_path}/interfaces/kits/native:environment_native", + "//third_party/googletest:gtest_main", + ] + + external_deps = [] +} + +ohos_unittest("fileio_native_test") { + module_out_path = "filemanagement/file_api" + + resource_config_file = "../resource/ohos_test.xml" + + sources = [ "fileio_native_test.cpp" ] + + include_dirs = [ "${file_api_path}/interfaces/kits/native/fileio" ] + + deps = [ + "${file_api_path}/interfaces/kits/native:fileio_native", + "//third_party/googletest:gtest_main", + ] + + external_deps = [] +} + +group("inner_kit_test") { + testonly = true + deps = [ + ":environment_native_test", + ":fileio_native_test", + ":remote_uri_test", + ] +} diff --git a/interfaces/test/unittest/native_test/environment_native_test.cpp b/interfaces/test/unittest/native_test/environment_native_test.cpp new file mode 100644 index 000000000..c8ce94270 --- /dev/null +++ b/interfaces/test/unittest/native_test/environment_native_test.cpp @@ -0,0 +1,58 @@ +/* + * 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 "environment_native.h" + +namespace OHOS::FileManagement { +using namespace std; +const string READ_WRITE_DOWNLOAD_PERMISSION = "ohos.permission.READ_WRITE_DOWNLOAD_DIRECTORY"; +const string READ_WRITE_DESKTOP_PERMISSION = "ohos.permission.READ_WRITE_DESKTOP_DIRECTORY"; +const string READ_WRITE_DOCUMENTS_PERMISSION = "ohos.permission.READ_WRITE_DOCUMENTS_DIRECTORY"; +const string DWFAULT_PATH = "/storage/Users/currentUser/"; +class EnvironmentTest : public testing::Test { +public: + static void SetUpTestCase(void) {}; + static void TearDownTestCase() {}; + void SetUp() {}; + void TearDown() {}; +}; + +/** + * @tc.name: Environment_Native_GetUserDir_0000 + * @tc.desc: Test function of GetUserDir() interface for FAILED. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: AR000HG8M4 + */ +HWTEST_F(EnvironmentTest, Environment_Native_GetUserDir_0000, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "EnvironmentTest-begin Environment_Native_GetUserDir_0000"; + char *result = nullptr; + int ret = GetUserDir(const_cast(READ_WRITE_DOWNLOAD_PERMISSION.c_str()), &result); + EXPECT_LT(ret, 0); + ASSERT_TRUE(result != nullptr); + if (result != nullptr) { + GTEST_LOG_(INFO) << "Result path: " << result; + free(result); + } + GTEST_LOG_(INFO) << "EnvironmentTest-end Environment_Native_GetUserDir_0000"; +} + +} // namespace OHOS::FileManagement diff --git a/interfaces/test/unittest/native_test/fileio_native_test.cpp b/interfaces/test/unittest/native_test/fileio_native_test.cpp new file mode 100644 index 000000000..3f0612089 --- /dev/null +++ b/interfaces/test/unittest/native_test/fileio_native_test.cpp @@ -0,0 +1,71 @@ +/* + * 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 "fileio_native.h" + +namespace OHOS::FileManagement { +using namespace std; +class FileioNativeTest : public testing::Test { +public: + static void SetUpTestCase(void) {}; + static void TearDownTestCase() {}; + void SetUp() {}; + void TearDown() {}; +}; + +/** + * @tc.name: Fileio_Native_GetFileLocation_0000 + * @tc.desc: Test function of GetFileLocation() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: AR000HG8M4 + */ +HWTEST_F(FileioNativeTest, Fileio_Native_GetFileLocation_0000, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "FileioTest-begin Fileio_Native_GetFileLocation_0000"; + char uri[] = "file://docs/storage/Users/currentUser/fileio_native.txt"; + size_t uriLength = strlen(uri); + int *location = nullptr; + int ret = GetFileLocation(uri, static_cast(uriLength), location); + EXPECT_EQ(ret, -ENOENT); + + GTEST_LOG_(INFO) << "FileioTest-end Environment_Native_GetFileLocation_0000"; +} + +/** + * @tc.name: Fileio_Native_GetFileLocation_ExistsWithoutAttr_0001 + * @tc.desc: Test GetFileLocation() when the file exists without cloud location attribute set. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level: Level 1 + */ +HWTEST_F(FileioNativeTest, Fileio_Native_GetFileLocation_ExistsWithoutAttr_0001, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "FileioTest-begin Fileio_Native_GetFileLocation_0001"; + char uri[] = "/data/test/native_test.txt"; + size_t uriLength = strlen(uri); + int location; + int ret = GetFileLocation(uri, static_cast(uriLength), &location); + EXPECT_EQ(ret, 0); + + GTEST_LOG_(INFO) << "FileioTest-end Fileio_Native_GetFileLocation_0001"; +} + +} // namespace OHOS::FileManagement diff --git a/interfaces/test/unittest/native_test/remote_uri_test.cpp b/interfaces/test/unittest/native_test/remote_uri_test.cpp new file mode 100644 index 000000000..39d2951e2 --- /dev/null +++ b/interfaces/test/unittest/native_test/remote_uri_test.cpp @@ -0,0 +1,176 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include + +#include "remote_uri.h" + +namespace { + using namespace std; + using namespace OHOS::DistributedFS::ModuleRemoteUri; + + class RemoteUriTest : public testing::Test { + public: + static void SetUpTestCase(void) {}; + static void TearDownTestCase() {}; + void SetUp() {}; + void TearDown() {}; + }; + + /** + * @tc.name: Remote_uri_ConvertUri_0000 + * @tc.desc: Test function of ConvertUri() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: AR000HG8M4 + */ + HWTEST_F(RemoteUriTest, Remote_uri_ConvertUri_0000, testing::ext::TestSize.Level1) + { + GTEST_LOG_(INFO) << "RemoteUriTest-begin Remote_uri_ConvertUri_0000"; + int fd = 10; + string remoteUri = ""; + string expectUri = "datashare:////#fdFromBinder=10"; + int ret = RemoteUri::ConvertUri(fd, remoteUri); + EXPECT_TRUE(ret == 0); + EXPECT_TRUE(remoteUri == expectUri); + + fd = -1; + ret = RemoteUri::ConvertUri(fd, remoteUri); + EXPECT_TRUE(ret == -EINVAL); + GTEST_LOG_(INFO) << "RemoteUriTest-end Remote_uri_ConvertUri_0000"; + } + + /** + * @tc.name: Remote_uri_ConvertUri_0001 + * @tc.desc: Test function of ConvertUri() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: AR000HG8M4 + */ + HWTEST_F(RemoteUriTest, Remote_uri_ConvertUri_0001, testing::ext::TestSize.Level1) + { + GTEST_LOG_(INFO) << "RemoteUriTest-begin Remote_uri_ConvertUri_0001"; + const string fileStr = "/data/test/remote_uri_test.txt"; + int maxUriSize = 128; + vectorremoteUriRecords; + vectorfdRecords; + for (int i = 0; i < maxUriSize + 1; i++) { + int fd = open(fileStr.c_str(), O_RDWR); + string remoteUri = ""; + int ret = RemoteUri::ConvertUri(fd, remoteUri); + EXPECT_TRUE(ret == 0); + remoteUriRecords.emplace_back(remoteUri); + fdRecords.emplace_back(fd); + } + for (int i = 0; i < maxUriSize + 1; i++) { + int fd = 0; + bool ret = RemoteUri::IsRemoteUri(remoteUriRecords[i], fd); + EXPECT_TRUE(ret == true); + EXPECT_EQ(fd, fdRecords[i]); + } + GTEST_LOG_(INFO) << "RemoteUriTest-end Remote_uri_ConvertUri_0001"; + } + + /** + * @tc.name: Remote_uri_OpenRemoteUri_0002 + * @tc.desc: Test function of OpenRemoteUri() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: AR000HG8M4 + */ + HWTEST_F(RemoteUriTest, Remote_uri_OpenRemoteUri_0002, testing::ext::TestSize.Level1) + { + GTEST_LOG_(INFO) << "RemoteUriTest-begin Remote_uri_OpenRemoteUri_0002"; + string remoteUri = "datashar:////#fdFromBinder=10"; + int ret = RemoteUri::OpenRemoteUri(remoteUri); + EXPECT_TRUE(ret == -1); + GTEST_LOG_(INFO) << "RemoteUriTest-end Remote_uri_OpenRemoteUri_0002"; + } + + /** + * @tc.name: Remote_uri_OpenRemoteUri_0003 + * @tc.desc: Test function of OpenRemoteUri() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: AR000HG8M4 + */ + HWTEST_F(RemoteUriTest, Remote_uri_OpenRemoteUri_0003, testing::ext::TestSize.Level1) + { + GTEST_LOG_(INFO) << "RemoteUriTest-begin Remote_uri_OpenRemoteUri_0003"; + string remoteUri = "datashare:////fdFromBinder=10"; + int ret = RemoteUri::OpenRemoteUri(remoteUri); + EXPECT_TRUE(ret == -1); + GTEST_LOG_(INFO) << "RemoteUriTest-end Remote_uri_OpenRemoteUri_0003"; + } + + /** + * @tc.name: Remote_uri_OpenRemoteUri_0004 + * @tc.desc: Test function of OpenRemoteUri() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: AR000HG8M4 + */ + HWTEST_F(RemoteUriTest, Remote_uri_OpenRemoteUri_0004, testing::ext::TestSize.Level1) + { + GTEST_LOG_(INFO) << "RemoteUriTest-begin Remote_uri_OpenRemoteUri_0004"; + string remoteUri = "datashare:////#fdFromBinde=10"; + int ret = RemoteUri::OpenRemoteUri(remoteUri); + EXPECT_TRUE(ret == -1); + GTEST_LOG_(INFO) << "RemoteUriTest-end Remote_uri_OpenRemoteUri_0004"; + } + + /** + * @tc.name: Remote_uri_OpenRemoteUri_0005 + * @tc.desc: Test function of OpenRemoteUri() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: AR000HG8M4 + */ + HWTEST_F(RemoteUriTest, Remote_uri_OpenRemoteUri_0005, testing::ext::TestSize.Level1) + { + GTEST_LOG_(INFO) << "RemoteUriTest-begin Remote_uri_OpenRemoteUri0005"; + string remoteUri = "datashare:////#fdFromBinder=10abc"; + int ret = RemoteUri::OpenRemoteUri(remoteUri); + EXPECT_TRUE(ret == -1); + GTEST_LOG_(INFO) << "RemoteUriTest-end Remote_uri_OpenRemoteUri_0005"; + } + + /** + * @tc.name: Remote_uri_IsRemoteUri_006 + * @tc.desc: Test function of IsRemoteUri() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: AR000HG8M4 + */ + HWTEST_F(RemoteUriTest, Remote_uri_IsRemoteUri_006, testing::ext::TestSize.Level1) + { + GTEST_LOG_(INFO) << "RemoteUriTest-begin Remote_uri_IsRemoteUri_0006"; + string remoteUri = "datashare:////#fdFromBinder=10"; + int fd = 0; + (void)RemoteUri::IsRemoteUri(remoteUri, fd, O_RDWR); + EXPECT_TRUE(fd == -1); + GTEST_LOG_(INFO) << "RemoteUriTest-end Remote_uri_IsRemoteUri_0006"; + } +} -- Gitee From 9a2de14587367ab1b6bd6749643013d9f767a8d3 Mon Sep 17 00:00:00 2001 From: zhangzhiwei Date: Sun, 7 Apr 2024 20:29:50 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E4=BF=AE=E6=94=B9remote?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhangzhiwei --- .../unittest/native_test/remote_uri_test.cpp | 176 ------------------ 1 file changed, 176 deletions(-) delete mode 100644 interfaces/test/unittest/native_test/remote_uri_test.cpp diff --git a/interfaces/test/unittest/native_test/remote_uri_test.cpp b/interfaces/test/unittest/native_test/remote_uri_test.cpp deleted file mode 100644 index 39d2951e2..000000000 --- a/interfaces/test/unittest/native_test/remote_uri_test.cpp +++ /dev/null @@ -1,176 +0,0 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include - -#include "remote_uri.h" - -namespace { - using namespace std; - using namespace OHOS::DistributedFS::ModuleRemoteUri; - - class RemoteUriTest : public testing::Test { - public: - static void SetUpTestCase(void) {}; - static void TearDownTestCase() {}; - void SetUp() {}; - void TearDown() {}; - }; - - /** - * @tc.name: Remote_uri_ConvertUri_0000 - * @tc.desc: Test function of ConvertUri() interface for SUCCESS. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: AR000HG8M4 - */ - HWTEST_F(RemoteUriTest, Remote_uri_ConvertUri_0000, testing::ext::TestSize.Level1) - { - GTEST_LOG_(INFO) << "RemoteUriTest-begin Remote_uri_ConvertUri_0000"; - int fd = 10; - string remoteUri = ""; - string expectUri = "datashare:////#fdFromBinder=10"; - int ret = RemoteUri::ConvertUri(fd, remoteUri); - EXPECT_TRUE(ret == 0); - EXPECT_TRUE(remoteUri == expectUri); - - fd = -1; - ret = RemoteUri::ConvertUri(fd, remoteUri); - EXPECT_TRUE(ret == -EINVAL); - GTEST_LOG_(INFO) << "RemoteUriTest-end Remote_uri_ConvertUri_0000"; - } - - /** - * @tc.name: Remote_uri_ConvertUri_0001 - * @tc.desc: Test function of ConvertUri() interface for SUCCESS. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: AR000HG8M4 - */ - HWTEST_F(RemoteUriTest, Remote_uri_ConvertUri_0001, testing::ext::TestSize.Level1) - { - GTEST_LOG_(INFO) << "RemoteUriTest-begin Remote_uri_ConvertUri_0001"; - const string fileStr = "/data/test/remote_uri_test.txt"; - int maxUriSize = 128; - vectorremoteUriRecords; - vectorfdRecords; - for (int i = 0; i < maxUriSize + 1; i++) { - int fd = open(fileStr.c_str(), O_RDWR); - string remoteUri = ""; - int ret = RemoteUri::ConvertUri(fd, remoteUri); - EXPECT_TRUE(ret == 0); - remoteUriRecords.emplace_back(remoteUri); - fdRecords.emplace_back(fd); - } - for (int i = 0; i < maxUriSize + 1; i++) { - int fd = 0; - bool ret = RemoteUri::IsRemoteUri(remoteUriRecords[i], fd); - EXPECT_TRUE(ret == true); - EXPECT_EQ(fd, fdRecords[i]); - } - GTEST_LOG_(INFO) << "RemoteUriTest-end Remote_uri_ConvertUri_0001"; - } - - /** - * @tc.name: Remote_uri_OpenRemoteUri_0002 - * @tc.desc: Test function of OpenRemoteUri() interface for SUCCESS. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: AR000HG8M4 - */ - HWTEST_F(RemoteUriTest, Remote_uri_OpenRemoteUri_0002, testing::ext::TestSize.Level1) - { - GTEST_LOG_(INFO) << "RemoteUriTest-begin Remote_uri_OpenRemoteUri_0002"; - string remoteUri = "datashar:////#fdFromBinder=10"; - int ret = RemoteUri::OpenRemoteUri(remoteUri); - EXPECT_TRUE(ret == -1); - GTEST_LOG_(INFO) << "RemoteUriTest-end Remote_uri_OpenRemoteUri_0002"; - } - - /** - * @tc.name: Remote_uri_OpenRemoteUri_0003 - * @tc.desc: Test function of OpenRemoteUri() interface for SUCCESS. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: AR000HG8M4 - */ - HWTEST_F(RemoteUriTest, Remote_uri_OpenRemoteUri_0003, testing::ext::TestSize.Level1) - { - GTEST_LOG_(INFO) << "RemoteUriTest-begin Remote_uri_OpenRemoteUri_0003"; - string remoteUri = "datashare:////fdFromBinder=10"; - int ret = RemoteUri::OpenRemoteUri(remoteUri); - EXPECT_TRUE(ret == -1); - GTEST_LOG_(INFO) << "RemoteUriTest-end Remote_uri_OpenRemoteUri_0003"; - } - - /** - * @tc.name: Remote_uri_OpenRemoteUri_0004 - * @tc.desc: Test function of OpenRemoteUri() interface for SUCCESS. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: AR000HG8M4 - */ - HWTEST_F(RemoteUriTest, Remote_uri_OpenRemoteUri_0004, testing::ext::TestSize.Level1) - { - GTEST_LOG_(INFO) << "RemoteUriTest-begin Remote_uri_OpenRemoteUri_0004"; - string remoteUri = "datashare:////#fdFromBinde=10"; - int ret = RemoteUri::OpenRemoteUri(remoteUri); - EXPECT_TRUE(ret == -1); - GTEST_LOG_(INFO) << "RemoteUriTest-end Remote_uri_OpenRemoteUri_0004"; - } - - /** - * @tc.name: Remote_uri_OpenRemoteUri_0005 - * @tc.desc: Test function of OpenRemoteUri() interface for SUCCESS. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: AR000HG8M4 - */ - HWTEST_F(RemoteUriTest, Remote_uri_OpenRemoteUri_0005, testing::ext::TestSize.Level1) - { - GTEST_LOG_(INFO) << "RemoteUriTest-begin Remote_uri_OpenRemoteUri0005"; - string remoteUri = "datashare:////#fdFromBinder=10abc"; - int ret = RemoteUri::OpenRemoteUri(remoteUri); - EXPECT_TRUE(ret == -1); - GTEST_LOG_(INFO) << "RemoteUriTest-end Remote_uri_OpenRemoteUri_0005"; - } - - /** - * @tc.name: Remote_uri_IsRemoteUri_006 - * @tc.desc: Test function of IsRemoteUri() interface for SUCCESS. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: AR000HG8M4 - */ - HWTEST_F(RemoteUriTest, Remote_uri_IsRemoteUri_006, testing::ext::TestSize.Level1) - { - GTEST_LOG_(INFO) << "RemoteUriTest-begin Remote_uri_IsRemoteUri_0006"; - string remoteUri = "datashare:////#fdFromBinder=10"; - int fd = 0; - (void)RemoteUri::IsRemoteUri(remoteUri, fd, O_RDWR); - EXPECT_TRUE(fd == -1); - GTEST_LOG_(INFO) << "RemoteUriTest-end Remote_uri_IsRemoteUri_0006"; - } -} -- Gitee From d8127552c7fa34b0715144ccfaf9bff63e796900 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E6=99=BA=E4=BC=9F?= Date: Wed, 17 Apr 2024 15:54:26 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 张智伟 --- .../native/environment/environment_native.cpp | 3 +++ interfaces/test/unittest/native_test/BUILD.gn | 2 +- .../native_test/environment_native_test.cpp | 27 ++++++++++++++++--- .../native_test/fileio_native_test.cpp | 21 ++++++++++++++- .../remote_uri_test.cpp | 0 .../test/unittest/resource/ohos_test.xml | 5 ++++ 6 files changed, 52 insertions(+), 6 deletions(-) rename interfaces/test/unittest/{remote_uri => native_test}/remote_uri_test.cpp (100%) diff --git a/interfaces/kits/native/environment/environment_native.cpp b/interfaces/kits/native/environment/environment_native.cpp index 0869c6e3e..de68dd1aa 100644 --- a/interfaces/kits/native/environment/environment_native.cpp +++ b/interfaces/kits/native/environment/environment_native.cpp @@ -80,6 +80,9 @@ static int CheckInvalidAccess(const std::string &permission) int GetUserDir(char *permission, char **result) { + if (permission == nullptr) { + return -EINVAL; + } std::string perm(permission); int ret = CheckInvalidAccess(perm); if (ret != 0) { diff --git a/interfaces/test/unittest/native_test/BUILD.gn b/interfaces/test/unittest/native_test/BUILD.gn index 39191a6ce..3dd0e6827 100644 --- a/interfaces/test/unittest/native_test/BUILD.gn +++ b/interfaces/test/unittest/native_test/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2022-2024 Huawei Device Co., Ltd. +# 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 diff --git a/interfaces/test/unittest/native_test/environment_native_test.cpp b/interfaces/test/unittest/native_test/environment_native_test.cpp index c8ce94270..9d053bd7c 100644 --- a/interfaces/test/unittest/native_test/environment_native_test.cpp +++ b/interfaces/test/unittest/native_test/environment_native_test.cpp @@ -44,15 +44,34 @@ public: HWTEST_F(EnvironmentTest, Environment_Native_GetUserDir_0000, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "EnvironmentTest-begin Environment_Native_GetUserDir_0000"; - char *result = nullptr; - int ret = GetUserDir(const_cast(READ_WRITE_DOWNLOAD_PERMISSION.c_str()), &result); + char **result = nullptr; + int ret = GetUserDir(const_cast(READ_WRITE_DOWNLOAD_PERMISSION.c_str()), result); EXPECT_LT(ret, 0); ASSERT_TRUE(result != nullptr); if (result != nullptr) { - GTEST_LOG_(INFO) << "Result path: " << result; - free(result); + GTEST_LOG_(INFO) << "Result path: " << *result; + free(*result); } GTEST_LOG_(INFO) << "EnvironmentTest-end Environment_Native_GetUserDir_0000"; } +/** + * @tc.name: Environment_Native_GetUserDir_0001 + * @tc.desc: Test function of GetUserDir() interface for FAILED. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: AR000HG8M4 + */ +HWTEST_F(EnvironmentTest, Environment_Native_GetUserDir_0001, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "EnvironmentTest-begin Environment_Native_GetUserDir_0001"; + char **result = nullptr; + char *permission = nullptr; + int ret = GetUserDir(permission, result); + EXPECT_EQ(ret, -EINVAL); + EXPECT_TRUE(result == nullptr); + GTEST_LOG_(INFO) << "EnvironmentTest-end Environment_Native_GetUserDir_0001"; +} + } // namespace OHOS::FileManagement diff --git a/interfaces/test/unittest/native_test/fileio_native_test.cpp b/interfaces/test/unittest/native_test/fileio_native_test.cpp index 3f0612089..538279349 100644 --- a/interfaces/test/unittest/native_test/fileio_native_test.cpp +++ b/interfaces/test/unittest/native_test/fileio_native_test.cpp @@ -63,9 +63,28 @@ HWTEST_F(FileioNativeTest, Fileio_Native_GetFileLocation_ExistsWithoutAttr_0001, size_t uriLength = strlen(uri); int location; int ret = GetFileLocation(uri, static_cast(uriLength), &location); - EXPECT_EQ(ret, 0); + EXPECT_EQ(ret, -ENOENT); GTEST_LOG_(INFO) << "FileioTest-end Fileio_Native_GetFileLocation_0001"; } +/** + * @tc.name: Fileio_Native_GetFileLocation_ExistsWithoutAttr_0002 + * @tc.desc: Test GetFileLocation() when the file exists without cloud location attribute set. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level: Level 1 + */ +HWTEST_F(FileioNativeTest, Fileio_Native_GetFileLocation_ExistsWithoutAttr_0002, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "FileioTest-begin Fileio_Native_GetFileLocation_0002"; + char *uri = nullptr; + size_t uriLength = 0; + int location; + int ret = GetFileLocation(uri, static_cast(uriLength), &location); + EXPECT_EQ(ret, -ENOENT); + + GTEST_LOG_(INFO) << "FileioTest-end Fileio_Native_GetFileLocation_0002"; +} + } // namespace OHOS::FileManagement diff --git a/interfaces/test/unittest/remote_uri/remote_uri_test.cpp b/interfaces/test/unittest/native_test/remote_uri_test.cpp similarity index 100% rename from interfaces/test/unittest/remote_uri/remote_uri_test.cpp rename to interfaces/test/unittest/native_test/remote_uri_test.cpp diff --git a/interfaces/test/unittest/resource/ohos_test.xml b/interfaces/test/unittest/resource/ohos_test.xml index 658e8b285..b78e641c0 100644 --- a/interfaces/test/unittest/resource/ohos_test.xml +++ b/interfaces/test/unittest/resource/ohos_test.xml @@ -24,4 +24,9 @@