diff --git a/bundle.json b/bundle.json index 5edd5818810f9bd4239904b77197715d9e612d43..be8ea60a253402158c9509627727516aa4470b6c 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 9da1419887cd3713d8e8f66cd7f96935a562def0..6917dd692f461895355821a28aa3fc3707b56159 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 old mode 100644 new mode 100755 index d0dbea092a180fc3e1186c50ad25448b58189bc2..3f12cc8130cc515bf75dd60d00ce0ec6724fb6f8 --- 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/remote_uri/BUILD.gn b/interfaces/test/unittest/native_test/BUILD.gn similarity index 50% rename from interfaces/test/unittest/remote_uri/BUILD.gn rename to interfaces/test/unittest/native_test/BUILD.gn index b3031520924f371592cf28a6e1826c1cd13f867b..39191a6cef6917d486ab45977c533edc37f60382 100644 --- a/interfaces/test/unittest/remote_uri/BUILD.gn +++ b/interfaces/test/unittest/native_test/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2022-2023 Huawei Device Co., Ltd. +# 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 @@ -31,10 +31,48 @@ ohos_unittest("remote_uri_test") { "//third_party/googletest:gtest_main", ] - external_deps = [ - "access_token:libaccesstoken_sdk", - "c_utils:utils", - "c_utils:utilsbase", - "ipc:ipc_core", + 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 0000000000000000000000000000000000000000..c8ce94270a171ee03d64eb579d04ba8b5326e526 --- /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 0000000000000000000000000000000000000000..3f06120893194d35b1527e9e100d25a6a858cb3d --- /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/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