From afcc0853d8ec30f4c64c4f60fad443d6399e130e Mon Sep 17 00:00:00 2001 From: yangbiao59 Date: Wed, 16 Apr 2025 11:45:24 +0000 Subject: [PATCH] add dup_core test Signed-off-by: yangbiao59 --- interfaces/test/unittest/BUILD.gn | 1 + interfaces/test/unittest/js/BUILD.gn | 76 +++++++++++++++++++ .../mod_fs/properties/ani/dup_core_test.cpp | 71 +++++++++++++++++ 3 files changed, 148 insertions(+) create mode 100644 interfaces/test/unittest/js/BUILD.gn create mode 100644 interfaces/test/unittest/js/mod_fs/properties/ani/dup_core_test.cpp diff --git a/interfaces/test/unittest/BUILD.gn b/interfaces/test/unittest/BUILD.gn index 95f924b84..0a368ab16 100644 --- a/interfaces/test/unittest/BUILD.gn +++ b/interfaces/test/unittest/BUILD.gn @@ -16,6 +16,7 @@ group("unittest") { deps = [ "class_file:class_file_test", "filemgmt_libn_test:filemgmt_libn_test", + "js:js_test", "remote_uri:remote_uri_test", "task_signal:task_signal_test", ] diff --git a/interfaces/test/unittest/js/BUILD.gn b/interfaces/test/unittest/js/BUILD.gn new file mode 100644 index 000000000..0f84e7eef --- /dev/null +++ b/interfaces/test/unittest/js/BUILD.gn @@ -0,0 +1,76 @@ +# Copyright (C) 2025 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("dup_core_test") { + module_out_path = "file_api/file_api" + + sources = [ + "${src_path}/common/file_helper/fd_guard.cpp", + "${src_path}/mod_fs/properties/dup_core.cpp", + "${src_path}/mod_fs/class_file/file_instantiator.cpp", + "${src_path}/mod_fs/fs_utils.cpp", + "${src_path}/mod_fs/class_file/fs_file.cpp", + "dup_core_test.cpp", + ] + + include_dirs = [ + "${src_path}/mod_fs", + "${src_path}/mod_fs/properties", + "${src_path}/mod_fs/class_file", + "${src_path}/common/file_helper", + ] + + deps = [ + "${file_api_path}/interfaces/kits/js:build_kits_js", + "${file_api_path}/interfaces/kits/js:ani_file_api", + "${file_api_path}/interfaces/kits/native:remote_uri_native", + "${file_api_path}/interfaces/kits/rust:rust_file", + "${utils_path}/filemgmt_libhilog:filemgmt_libhilog", + "${utils_path}/filemgmt_libfs:filemgmt_libfs", + "${utils_path}/filemgmt_libn:filemgmt_libn", + "//third_party/googletest:gtest_main", + ] + + external_deps = [ + "ability_runtime:ability_manager", + "app_file_service:fileuri_native", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", + "c_utils:utils", + "data_share:datashare_common", + "data_share:datashare_consumer", + "dfs_service:distributed_file_daemon_kit_inner", + "dfs_service:libdistributedfileutils", + "hilog:libhilog", + "hisysevent:libhisysevent", + "ipc:ipc_core", + "libuv:uv", + "runtime_core:ani", + "runtime_core:libarkruntime", + "samgr:samgr_proxy", + ] + + defines = [ + "private=public" + ] +} + +group("js_test") { + testonly = true + deps = [ + ":dup_core_test" + ] +} \ No newline at end of file diff --git a/interfaces/test/unittest/js/mod_fs/properties/ani/dup_core_test.cpp b/interfaces/test/unittest/js/mod_fs/properties/ani/dup_core_test.cpp new file mode 100644 index 000000000..66ec65992 --- /dev/null +++ b/interfaces/test/unittest/js/mod_fs/properties/ani/dup_core_test.cpp @@ -0,0 +1,71 @@ +/* + * Copyright (C) 2025 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 "dup_core.h" +#include "fs_result.h" +#include "fs_utils.h" + +#include + +using namespace std; +using namespace OHOS; +using namespace testing::ext; + +namespace OHOS::FileManagement::ModuleFileIO { +class DupCoreTest : public testing::Test { +public: + static void SetUpTestCase(void); + static void TearDownTestCase(); + void SetUp(); + void TearDown(); +}; + +void DupCoreTest::SetUpTestCase(void) +{ + std::cout << "SetUpTestCase" << std::endl; +} + +void DupCoreTest::TearDownTestCase(void) +{ + std::cout << "TearDownTestCase" << std::endl; +} + +void DupCoreTest::SetUp(void) +{ + std::cout << "SetUp" << std::endl; +} + +void DupCoreTest::TearDown(void) +{ + std::cout << "TearDown" << std::endl; +} + +HWTEST_F(DupCoreTest, DoDup_001, TestSize.Level1) +{ + int32_t fd = -1; + auto res = DupCore::DoDup(fd); + + EXPECT_EQ(13900020, res.GetError().errno_); +} + +HWTEST_F(DupCoreTest, DoDup_002, TestSize.Level1) +{ + int32_t fd = 1; + auto res = DupCore::DoDup(fd); + + EXPECT_NE(13900020, res.GetError().errno_); +} + +} // namespace OHOS::FileManagement::ModuleFileIO -- Gitee