diff --git a/storage/storagefileioerrorjstest/BUILD.gn b/storage/storagefileioerrorjstest/BUILD.gn index 45c6755b4807d1e940654266a3189e089d73cfe4..33b0f324f974b62cff614045b0a1054722c37801 100644 --- a/storage/storagefileioerrorjstest/BUILD.gn +++ b/storage/storagefileioerrorjstest/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (C) 2023 Huawei Device Co., Ltd. +# Copyright (C) 2021 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 @@ -10,13 +10,26 @@ # 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("//test/xts/tools/build/suite.gni") -ohos_js_app_suite("storagefileioerror_js_test") { - test_hap = true - testonly = true +ohos_js_hap_suite("storagefileioerror_js_test") { + hap_profile = "./src/main/config.json" + deps = [ + ":storagefileioerror_js_assets", + ":storagefileioerror_js_resources", + ] + certificate_profile = "./signature/openharmony_sx.p7b" hap_name = "ActsStorageFileIoErrorJsTest" subsystem_name = "filemanagement" part_name = "file_api" - certificate_profile = "./signature/openharmony_sx.p7b" +} +ohos_js_assets("storagefileioerror_js_assets") { + js2abc = true + hap_profile = "./src/main/config.json" + source_dir = "./src/main/js" +} +ohos_resources("storagefileioerror_js_resources") { + sources = [ "./src/main/resources" ] + hap_profile = "./src/main/config.json" } diff --git a/storage/storagefileioerrorjstest/Test.json b/storage/storagefileioerrorjstest/Test.json index e4dd3f20d24fdd78f0586ce5edf53e0466a2dd7a..e51d814fdfdad6ee7f407f12b23fb0c48c0dfb1e 100644 --- a/storage/storagefileioerrorjstest/Test.json +++ b/storage/storagefileioerrorjstest/Test.json @@ -5,7 +5,7 @@ "test-timeout": "60000", "shell-timeout": "60000", "bundle-name": "ohos.acts.storage.fileioerror", - "package-name": "ohos.acts.storage.fileioerror_test" + "package-name": "ohos.acts.storage.fileioerror" }, "kits": [ { diff --git a/storage/storagefileioerrorjstest/build-profile.json5 b/storage/storagefileioerrorjstest/build-profile.json5 deleted file mode 100644 index 9d88c5ddf735cf82aeb8c32e359153c49fdeb49c..0000000000000000000000000000000000000000 --- a/storage/storagefileioerrorjstest/build-profile.json5 +++ /dev/null @@ -1,43 +0,0 @@ -/** - * Copyright (c) 2023 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. - */ - -{ - "app": { - "signingConfigs": [ - ], - "compileSdkVersion": 10, - "compatibleSdkVersion": 10, - "products": [ - { - "name": "default", - "signingConfig": "default" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] -} \ No newline at end of file diff --git a/storage/storagefileioerrorjstest/entry/build-profile.json5 b/storage/storagefileioerrorjstest/entry/build-profile.json5 deleted file mode 100644 index a6a17e6971173aacea7b75d9ae897a80d335dc0b..0000000000000000000000000000000000000000 --- a/storage/storagefileioerrorjstest/entry/build-profile.json5 +++ /dev/null @@ -1,27 +0,0 @@ -/** - * Copyright (c) 2023 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. - */ -{ - "apiType": 'faMode', - "buildOption": { - }, - "targets": [ - { - "name": "default", - }, - { - "name": "ohosTest", - } - ] -} \ No newline at end of file diff --git a/storage/storagefileioerrorjstest/entry/hvigorfile.ts b/storage/storagefileioerrorjstest/entry/hvigorfile.ts deleted file mode 100644 index ec27aa45d8977eac23d7a5af6850d1a1e958ab0f..0000000000000000000000000000000000000000 --- a/storage/storagefileioerrorjstest/entry/hvigorfile.ts +++ /dev/null @@ -1,17 +0,0 @@ -/** - * Copyright (c) 2023 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. - */ - -// Script for compiling build behavior. It is built in the build plug-in and cannot be modified currently. -export { legacyHapTasks } from '@ohos/hvigor-ohos-plugin'; diff --git a/storage/storagefileioerrorjstest/entry/oh-package.json5 b/storage/storagefileioerrorjstest/entry/oh-package.json5 deleted file mode 100644 index a1aa90658bd01247cb284e026dc37a1242004f16..0000000000000000000000000000000000000000 --- a/storage/storagefileioerrorjstest/entry/oh-package.json5 +++ /dev/null @@ -1,25 +0,0 @@ -/** - * Copyright (c) 2023 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. - */ - -{ - "license": "", - "devDependencies": {}, - "author": "", - "name": "entry", - "description": "Please describe the basic information.", - "main": "", - "version": "1.0.0", - "dependencies": {} -} diff --git a/storage/storagefileioerrorjstest/entry/src/main/config.json b/storage/storagefileioerrorjstest/entry/src/main/config.json deleted file mode 100644 index 0f1f1b3f7347e2e44d242541cd47f3176230c28e..0000000000000000000000000000000000000000 --- a/storage/storagefileioerrorjstest/entry/src/main/config.json +++ /dev/null @@ -1,65 +0,0 @@ -{ - "app":{ - "bundleName":"ohos.acts.storage.fileioerror", - "vendor":"example", - "version":{ - "code":1000000, - "name":"1.0.0" - } - }, - "deviceConfig":{ - - }, - "module":{ - "package":"ohos.acts.storage.fileioerror", - "name":".entry", - "mainAbility":".MainAbility", - "deviceType": [ - "tablet", - "default" - ], - "distro":{ - "deliveryWithInstall":true, - "installationFree":true, - "moduleName":"entry", - "moduleType":"entry" - }, - "abilities":[ - { - "description":"$string:MainAbility_desc", - "formsEnabled":false, - "icon":"$media:icon", - "label":"$string:MainAbility_label", - "launchType":"standard", - "name":".MainAbility", - "orientation":"unspecified", - "skills":[ - { - "actions":[ - "action.system.home" - ], - "entities":[ - "entity.system.home" - ] - } - ], - "srcLanguage":"js", - "srcPath":"MainAbility", - "type":"page", - "visible":true - } - ], - "js":[ - { - "name":".MainAbility", - "pages":[ - "pages/index/index" - ], - "window":{ - "autoDesignWidth":false, - "designWidth":720 - } - } - ] - } -} \ No newline at end of file diff --git a/storage/storagefileioerrorjstest/entry/src/main/js/MainAbility/pages/index/index.css b/storage/storagefileioerrorjstest/entry/src/main/js/MainAbility/pages/index/index.css deleted file mode 100644 index a711febae0b34889547cd72fbe5f8cc3e0bd043c..0000000000000000000000000000000000000000 --- a/storage/storagefileioerrorjstest/entry/src/main/js/MainAbility/pages/index/index.css +++ /dev/null @@ -1,60 +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. - */ -.container { - flex-direction: column; - justify-content: center; - align-items: center; - width: 100%; - height: 100%; -} - -.title { - font-size: 40px; - color: #000000; - opacity: 0.9; -} - -@media screen and (device-type: tablet) and (orientation: landscape) { - .title { - font-size: 100px; - } -} - -@media screen and (device-type: wearable) { - .title { - font-size: 28px; - color: #FFFFFF; - } -} - -@media screen and (device-type: tv) { - .container { - background-image: url("/common/images/Wallpaper.png"); - background-size: cover; - background-repeat: no-repeat; - background-position: center; - } - - .title { - font-size: 100px; - color: #FFFFFF; - } -} - -@media screen and (device-type: phone) and (orientation: landscape) { - .title { - font-size: 60px; - } -} diff --git a/storage/storagefileioerrorjstest/entry/src/main/js/MainAbility/pages/index/index.hml b/storage/storagefileioerrorjstest/entry/src/main/js/MainAbility/pages/index/index.hml deleted file mode 100644 index 95bd1e877b3fa9f5f4e4dc0ff608591b540d116d..0000000000000000000000000000000000000000 --- a/storage/storagefileioerrorjstest/entry/src/main/js/MainAbility/pages/index/index.hml +++ /dev/null @@ -1,19 +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. - */ -
- - {{ $t('strings.hello') }} {{ title }} - -
diff --git a/storage/storagefileioerrorjstest/entry/src/ohosTest/config.json b/storage/storagefileioerrorjstest/entry/src/ohosTest/config.json deleted file mode 100644 index 33a4b7c377f96dd64291879b99b96c63263fb6c9..0000000000000000000000000000000000000000 --- a/storage/storagefileioerrorjstest/entry/src/ohosTest/config.json +++ /dev/null @@ -1,69 +0,0 @@ -{ - "app":{ - "bundleName":"ohos.acts.storage.fileioerror", - "vendor":"example", - "version":{ - "code":1000000, - "name":"1.0.0" - } - }, - "deviceConfig":{ - - }, - "module":{ - "package":"ohos.acts.storage.fileioerror_test", - "name":".entry_test", - "mainAbility":".TestAbility", - "deviceType": [ - "tablet", - "default" - ], - "testRunner":{ - "name":"OpenHarmonyTestRunner", - "srcPath":"TestRunner" - }, - "distro":{ - "deliveryWithInstall":true, - "installationFree":true, - "moduleName":"entry_test", - "moduleType":"feature" - }, - "abilities":[ - { - "description":"$string:TestAbility_desc", - "formsEnabled":false, - "icon":"$media:icon", - "label":"$string:TestAbility_label", - "launchType":"standard", - "name":".TestAbility", - "orientation":"unspecified", - "skills":[ - { - "actions":[ - "action.system.home" - ], - "entities":[ - "entity.system.home" - ] - } - ], - "srcLanguage":"js", - "srcPath":"TestAbility", - "type":"page", - "visible":true - } - ], - "js":[ - { - "name":".TestAbility", - "pages":[ - "pages/index/index" - ], - "window":{ - "autoDesignWidth":false, - "designWidth":720 - } - } - ] - } -} \ No newline at end of file diff --git a/storage/storagefileioerrorjstest/entry/src/ohosTest/resources/base/element/string.json b/storage/storagefileioerrorjstest/entry/src/ohosTest/resources/base/element/string.json deleted file mode 100644 index 5bdb90000e71dc63c7cfa55cb919ef7473472fc1..0000000000000000000000000000000000000000 --- a/storage/storagefileioerrorjstest/entry/src/ohosTest/resources/base/element/string.json +++ /dev/null @@ -1,28 +0,0 @@ -{ - "string": [ - { - "name": "app_name", - "value": "storagefileioerrorjstest" - }, - { - "name": "mainability_description", - "value": "JS_Phone_Empty Feature Ability" - }, - { - "name": "MainAbility_desc", - "value": "description" - }, - { - "name": "MainAbility_label", - "value": "label" - }, - { - "name": "TestAbility_desc", - "value": "description" - }, - { - "name": "TestAbility_label", - "value": "label" - } - ] -} \ No newline at end of file diff --git a/storage/storagefileioerrorjstest/hvigor/hvigor-config.json5 b/storage/storagefileioerrorjstest/hvigor/hvigor-config.json5 deleted file mode 100644 index d1ed6c3c0cb895265a376515209a0575aeb7d898..0000000000000000000000000000000000000000 --- a/storage/storagefileioerrorjstest/hvigor/hvigor-config.json5 +++ /dev/null @@ -1,20 +0,0 @@ -/** - * Copyright (c) 2023 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. - */ -{ - "hvigorVersion": "2.0.0", - "dependencies": { - "@ohos/hvigor-ohos-plugin": "2.0.0" - } -} diff --git a/storage/storagefileioerrorjstest/hvigor/hvigor-wrapper.js b/storage/storagefileioerrorjstest/hvigor/hvigor-wrapper.js deleted file mode 100644 index 2507619ca768432ff3fb806441f29eff47a4c4f0..0000000000000000000000000000000000000000 --- a/storage/storagefileioerrorjstest/hvigor/hvigor-wrapper.js +++ /dev/null @@ -1,16 +0,0 @@ -/** - * Copyright (c) 2023 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. - */ -"use strict";var e=require("fs"),t=require("path"),n=require("os"),r=require("crypto"),u=require("child_process"),o=require("constants"),i=require("stream"),s=require("util"),c=require("assert"),a=require("tty"),l=require("zlib"),f=require("net");function d(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var D=d(e),p=d(t),E=d(n),m=d(r),h=d(u),y=d(o),C=d(i),F=d(s),g=d(c),A=d(a),v=d(l),S=d(f),w="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},O={},b={},_={},B=w&&w.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(_,"__esModule",{value:!0}),_.isMac=_.isLinux=_.isWindows=void 0;const P=B(E.default),k="Windows_NT",x="Linux",N="Darwin";_.isWindows=function(){return P.default.type()===k},_.isLinux=function(){return P.default.type()===x},_.isMac=function(){return P.default.type()===N};var I={},T=w&&w.__createBinding||(Object.create?function(e,t,n,r){void 0===r&&(r=n);var u=Object.getOwnPropertyDescriptor(t,n);u&&!("get"in u?!t.__esModule:u.writable||u.configurable)||(u={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,r,u)}:function(e,t,n,r){void 0===r&&(r=n),e[r]=t[n]}),R=w&&w.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),M=w&&w.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var n in e)"default"!==n&&Object.prototype.hasOwnProperty.call(e,n)&&T(t,e,n);return R(t,e),t};Object.defineProperty(I,"__esModule",{value:!0}),I.hash=void 0;const L=M(m.default);I.hash=function(e,t="md5"){return L.createHash(t).update(e,"utf-8").digest("hex")},function(e){var t=w&&w.__createBinding||(Object.create?function(e,t,n,r){void 0===r&&(r=n);var u=Object.getOwnPropertyDescriptor(t,n);u&&!("get"in u?!t.__esModule:u.writable||u.configurable)||(u={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,r,u)}:function(e,t,n,r){void 0===r&&(r=n),e[r]=t[n]}),n=w&&w.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),r=w&&w.__importStar||function(e){if(e&&e.__esModule)return e;var r={};if(null!=e)for(var u in e)"default"!==u&&Object.prototype.hasOwnProperty.call(e,u)&&t(r,e,u);return n(r,e),r};Object.defineProperty(e,"__esModule",{value:!0}),e.HVIGOR_BOOT_JS_FILE_PATH=e.HVIGOR_PROJECT_DEPENDENCY_PACKAGE_JSON_PATH=e.HVIGOR_PROJECT_DEPENDENCIES_HOME=e.HVIGOR_PROJECT_WRAPPER_HOME=e.HVIGOR_PROJECT_NAME=e.HVIGOR_PROJECT_ROOT_DIR=e.HVIGOR_PROJECT_CACHES_HOME=e.HVIGOR_PNPM_STORE_PATH=e.HVIGOR_WRAPPER_PNPM_SCRIPT_PATH=e.HVIGOR_WRAPPER_TOOLS_HOME=e.HVIGOR_USER_HOME=e.DEFAULT_PACKAGE_JSON=e.DEFAULT_HVIGOR_CONFIG_JSON_FILE_NAME=e.PNPM=e.HVIGOR=e.NPM_TOOL=e.PNPM_TOOL=e.HVIGOR_ENGINE_PACKAGE_NAME=void 0;const u=r(p.default),o=r(E.default),i=_,s=I;e.HVIGOR_ENGINE_PACKAGE_NAME="@ohos/hvigor",e.PNPM_TOOL=(0,i.isWindows)()?"pnpm.cmd":"pnpm",e.NPM_TOOL=(0,i.isWindows)()?"npm.cmd":"npm",e.HVIGOR="hvigor",e.PNPM="pnpm",e.DEFAULT_HVIGOR_CONFIG_JSON_FILE_NAME="hvigor-config.json5",e.DEFAULT_PACKAGE_JSON="package.json",e.HVIGOR_USER_HOME=u.resolve(o.homedir(),".hvigor"),e.HVIGOR_WRAPPER_TOOLS_HOME=u.resolve(e.HVIGOR_USER_HOME,"wrapper","tools"),e.HVIGOR_WRAPPER_PNPM_SCRIPT_PATH=u.resolve(e.HVIGOR_WRAPPER_TOOLS_HOME,"node_modules",".bin",e.PNPM_TOOL),e.HVIGOR_PNPM_STORE_PATH=u.resolve(e.HVIGOR_USER_HOME,"caches"),e.HVIGOR_PROJECT_CACHES_HOME=u.resolve(e.HVIGOR_USER_HOME,"project_caches"),e.HVIGOR_PROJECT_ROOT_DIR=process.cwd(),e.HVIGOR_PROJECT_NAME=u.basename((0,s.hash)(e.HVIGOR_PROJECT_ROOT_DIR)),e.HVIGOR_PROJECT_WRAPPER_HOME=u.resolve(e.HVIGOR_PROJECT_ROOT_DIR,e.HVIGOR),e.HVIGOR_PROJECT_DEPENDENCIES_HOME=u.resolve(e.HVIGOR_PROJECT_CACHES_HOME,e.HVIGOR_PROJECT_NAME,"workspace"),e.HVIGOR_PROJECT_DEPENDENCY_PACKAGE_JSON_PATH=u.resolve(e.HVIGOR_PROJECT_DEPENDENCIES_HOME,e.DEFAULT_PACKAGE_JSON),e.HVIGOR_BOOT_JS_FILE_PATH=u.resolve(e.HVIGOR_PROJECT_DEPENDENCIES_HOME,"node_modules","@ohos","hvigor","bin","hvigor.js")}(b);var j={},$={};Object.defineProperty($,"__esModule",{value:!0}),$.logInfoPrintConsole=$.logErrorAndExit=void 0,$.logErrorAndExit=function(e){e instanceof Error?console.error(e.message):console.error(e),process.exit(-1)},$.logInfoPrintConsole=function(e){console.log(e)};var H=w&&w.__createBinding||(Object.create?function(e,t,n,r){void 0===r&&(r=n);var u=Object.getOwnPropertyDescriptor(t,n);u&&!("get"in u?!t.__esModule:u.writable||u.configurable)||(u={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,r,u)}:function(e,t,n,r){void 0===r&&(r=n),e[r]=t[n]}),J=w&&w.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),G=w&&w.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var n in e)"default"!==n&&Object.prototype.hasOwnProperty.call(e,n)&&H(t,e,n);return J(t,e),t},V=w&&w.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(j,"__esModule",{value:!0}),j.isFileExists=j.offlinePluginConversion=j.executeCommand=j.getNpmPath=j.hasNpmPackInPaths=void 0;const U=h.default,W=G(p.default),z=b,K=$,q=V(D.default);j.hasNpmPackInPaths=function(e,t){try{return require.resolve(e,{paths:[...t]}),!0}catch(e){return!1}},j.getNpmPath=function(){const e=process.execPath;return W.join(W.dirname(e),z.NPM_TOOL)},j.executeCommand=function(e,t,n){0!==(0,U.spawnSync)(e,t,n).status&&(0,K.logErrorAndExit)(`Error: ${e} ${t} execute failed.See above for details.`)},j.offlinePluginConversion=function(e,t){return t.startsWith("file:")||t.endsWith(".tgz")?W.resolve(e,z.HVIGOR,t.replace("file:","")):t},j.isFileExists=function(e){return q.default.existsSync(e)&&q.default.statSync(e).isFile()},function(e){var t=w&&w.__createBinding||(Object.create?function(e,t,n,r){void 0===r&&(r=n);var u=Object.getOwnPropertyDescriptor(t,n);u&&!("get"in u?!t.__esModule:u.writable||u.configurable)||(u={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,r,u)}:function(e,t,n,r){void 0===r&&(r=n),e[r]=t[n]}),n=w&&w.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),r=w&&w.__importStar||function(e){if(e&&e.__esModule)return e;var r={};if(null!=e)for(var u in e)"default"!==u&&Object.prototype.hasOwnProperty.call(e,u)&&t(r,e,u);return n(r,e),r},u=w&&w.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(e,"__esModule",{value:!0}),e.executeInstallPnpm=e.isPnpmAvailable=e.environmentHandler=e.checkNpmConifg=e.PNPM_VERSION=void 0;const o=r(D.default),i=b,s=j,c=r(p.default),a=$,l=h.default,f=u(E.default);e.PNPM_VERSION="7.30.0",e.checkNpmConifg=function(){const e=c.resolve(i.HVIGOR_PROJECT_ROOT_DIR,".npmrc"),t=c.resolve(f.default.homedir(),".npmrc");if((0,s.isFileExists)(e)||(0,s.isFileExists)(t))return;const n=(0,s.getNpmPath)(),r=(0,l.spawnSync)(n,["config","get","prefix"],{cwd:i.HVIGOR_PROJECT_ROOT_DIR});if(0!==r.status||!r.stdout)return void(0,a.logErrorAndExit)("Error: The hvigor depends on the npmrc file. Configure the npmrc file first.");const u=c.resolve(`${r.stdout}`.replace(/[\r\n]/gi,""),".npmrc");(0,s.isFileExists)(u)||(0,a.logErrorAndExit)("Error: The hvigor depends on the npmrc file. Configure the npmrc file first.")},e.environmentHandler=function(){process.env["npm_config_update-notifier"]="false"},e.isPnpmAvailable=function(){return!!o.existsSync(i.HVIGOR_WRAPPER_PNPM_SCRIPT_PATH)&&(0,s.hasNpmPackInPaths)("pnpm",[i.HVIGOR_WRAPPER_TOOLS_HOME])},e.executeInstallPnpm=function(){(0,a.logInfoPrintConsole)(`Installing pnpm@${e.PNPM_VERSION}...`);const t=(0,s.getNpmPath)();!function(){const t=c.resolve(i.HVIGOR_WRAPPER_TOOLS_HOME,i.DEFAULT_PACKAGE_JSON);try{o.existsSync(i.HVIGOR_WRAPPER_TOOLS_HOME)||o.mkdirSync(i.HVIGOR_WRAPPER_TOOLS_HOME,{recursive:!0});const n={dependencies:{}};n.dependencies[i.PNPM]=e.PNPM_VERSION,o.writeFileSync(t,JSON.stringify(n))}catch(e){(0,a.logErrorAndExit)(`Error: EPERM: operation not permitted,create ${t} failed.`)}}(),(0,s.executeCommand)(t,["install","pnpm"],{cwd:i.HVIGOR_WRAPPER_TOOLS_HOME,stdio:["inherit","inherit","inherit"],env:process.env}),(0,a.logInfoPrintConsole)("Pnpm install success.")}}(O);var Y={},X={},Z={},Q={};Object.defineProperty(Q,"__esModule",{value:!0}),Q.Unicode=void 0;class ee{}Q.Unicode=ee,ee.Space_Separator=/[\u1680\u2000-\u200A\u202F\u205F\u3000]/,ee.ID_Start=/[\xAA\xB5\xBA\xC0-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0370-\u0374\u0376\u0377\u037A-\u037D\u037F\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u048A-\u052F\u0531-\u0556\u0559\u0561-\u0587\u05D0-\u05EA\u05F0-\u05F2\u0620-\u064A\u066E\u066F\u0671-\u06D3\u06D5\u06E5\u06E6\u06EE\u06EF\u06FA-\u06FC\u06FF\u0710\u0712-\u072F\u074D-\u07A5\u07B1\u07CA-\u07EA\u07F4\u07F5\u07FA\u0800-\u0815\u081A\u0824\u0828\u0840-\u0858\u0860-\u086A\u08A0-\u08B4\u08B6-\u08BD\u0904-\u0939\u093D\u0950\u0958-\u0961\u0971-\u0980\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BD\u09CE\u09DC\u09DD\u09DF-\u09E1\u09F0\u09F1\u09FC\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A59-\u0A5C\u0A5E\u0A72-\u0A74\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABD\u0AD0\u0AE0\u0AE1\u0AF9\u0B05-\u0B0C\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3D\u0B5C\u0B5D\u0B5F-\u0B61\u0B71\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BD0\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C39\u0C3D\u0C58-\u0C5A\u0C60\u0C61\u0C80\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBD\u0CDE\u0CE0\u0CE1\u0CF1\u0CF2\u0D05-\u0D0C\u0D0E-\u0D10\u0D12-\u0D3A\u0D3D\u0D4E\u0D54-\u0D56\u0D5F-\u0D61\u0D7A-\u0D7F\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0E01-\u0E30\u0E32\u0E33\u0E40-\u0E46\u0E81\u0E82\u0E84\u0E87\u0E88\u0E8A\u0E8D\u0E94-\u0E97\u0E99-\u0E9F\u0EA1-\u0EA3\u0EA5\u0EA7\u0EAA\u0EAB\u0EAD-\u0EB0\u0EB2\u0EB3\u0EBD\u0EC0-\u0EC4\u0EC6\u0EDC-\u0EDF\u0F00\u0F40-\u0F47\u0F49-\u0F6C\u0F88-\u0F8C\u1000-\u102A\u103F\u1050-\u1055\u105A-\u105D\u1061\u1065\u1066\u106E-\u1070\u1075-\u1081\u108E\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FC-\u1248\u124A-\u124D\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310\u1312-\u1315\u1318-\u135A\u1380-\u138F\u13A0-\u13F5\u13F8-\u13FD\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u16EE-\u16F8\u1700-\u170C\u170E-\u1711\u1720-\u1731\u1740-\u1751\u1760-\u176C\u176E-\u1770\u1780-\u17B3\u17D7\u17DC\u1820-\u1877\u1880-\u1884\u1887-\u18A8\u18AA\u18B0-\u18F5\u1900-\u191E\u1950-\u196D\u1970-\u1974\u1980-\u19AB\u19B0-\u19C9\u1A00-\u1A16\u1A20-\u1A54\u1AA7\u1B05-\u1B33\u1B45-\u1B4B\u1B83-\u1BA0\u1BAE\u1BAF\u1BBA-\u1BE5\u1C00-\u1C23\u1C4D-\u1C4F\u1C5A-\u1C7D\u1C80-\u1C88\u1CE9-\u1CEC\u1CEE-\u1CF1\u1CF5\u1CF6\u1D00-\u1DBF\u1E00-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u2071\u207F\u2090-\u209C\u2102\u2107\u210A-\u2113\u2115\u2119-\u211D\u2124\u2126\u2128\u212A-\u212D\u212F-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2160-\u2188\u2C00-\u2C2E\u2C30-\u2C5E\u2C60-\u2CE4\u2CEB-\u2CEE\u2CF2\u2CF3\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D80-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u2E2F\u3005-\u3007\u3021-\u3029\u3031-\u3035\u3038-\u303C\u3041-\u3096\u309D-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312E\u3131-\u318E\u31A0-\u31BA\u31F0-\u31FF\u3400-\u4DB5\u4E00-\u9FEA\uA000-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA61F\uA62A\uA62B\uA640-\uA66E\uA67F-\uA69D\uA6A0-\uA6EF\uA717-\uA71F\uA722-\uA788\uA78B-\uA7AE\uA7B0-\uA7B7\uA7F7-\uA801\uA803-\uA805\uA807-\uA80A\uA80C-\uA822\uA840-\uA873\uA882-\uA8B3\uA8F2-\uA8F7\uA8FB\uA8FD\uA90A-\uA925\uA930-\uA946\uA960-\uA97C\uA984-\uA9B2\uA9CF\uA9E0-\uA9E4\uA9E6-\uA9EF\uA9FA-\uA9FE\uAA00-\uAA28\uAA40-\uAA42\uAA44-\uAA4B\uAA60-\uAA76\uAA7A\uAA7E-\uAAAF\uAAB1\uAAB5\uAAB6\uAAB9-\uAABD\uAAC0\uAAC2\uAADB-\uAADD\uAAE0-\uAAEA\uAAF2-\uAAF4\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uAB30-\uAB5A\uAB5C-\uAB65\uAB70-\uABE2\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D\uFB1F-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE70-\uFE74\uFE76-\uFEFC\uFF21-\uFF3A\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC]|\uD800[\uDC00-\uDC0B\uDC0D-\uDC26\uDC28-\uDC3A\uDC3C\uDC3D\uDC3F-\uDC4D\uDC50-\uDC5D\uDC80-\uDCFA\uDD40-\uDD74\uDE80-\uDE9C\uDEA0-\uDED0\uDF00-\uDF1F\uDF2D-\uDF4A\uDF50-\uDF75\uDF80-\uDF9D\uDFA0-\uDFC3\uDFC8-\uDFCF\uDFD1-\uDFD5]|\uD801[\uDC00-\uDC9D\uDCB0-\uDCD3\uDCD8-\uDCFB\uDD00-\uDD27\uDD30-\uDD63\uDE00-\uDF36\uDF40-\uDF55\uDF60-\uDF67]|\uD802[\uDC00-\uDC05\uDC08\uDC0A-\uDC35\uDC37\uDC38\uDC3C\uDC3F-\uDC55\uDC60-\uDC76\uDC80-\uDC9E\uDCE0-\uDCF2\uDCF4\uDCF5\uDD00-\uDD15\uDD20-\uDD39\uDD80-\uDDB7\uDDBE\uDDBF\uDE00\uDE10-\uDE13\uDE15-\uDE17\uDE19-\uDE33\uDE60-\uDE7C\uDE80-\uDE9C\uDEC0-\uDEC7\uDEC9-\uDEE4\uDF00-\uDF35\uDF40-\uDF55\uDF60-\uDF72\uDF80-\uDF91]|\uD803[\uDC00-\uDC48\uDC80-\uDCB2\uDCC0-\uDCF2]|\uD804[\uDC03-\uDC37\uDC83-\uDCAF\uDCD0-\uDCE8\uDD03-\uDD26\uDD50-\uDD72\uDD76\uDD83-\uDDB2\uDDC1-\uDDC4\uDDDA\uDDDC\uDE00-\uDE11\uDE13-\uDE2B\uDE80-\uDE86\uDE88\uDE8A-\uDE8D\uDE8F-\uDE9D\uDE9F-\uDEA8\uDEB0-\uDEDE\uDF05-\uDF0C\uDF0F\uDF10\uDF13-\uDF28\uDF2A-\uDF30\uDF32\uDF33\uDF35-\uDF39\uDF3D\uDF50\uDF5D-\uDF61]|\uD805[\uDC00-\uDC34\uDC47-\uDC4A\uDC80-\uDCAF\uDCC4\uDCC5\uDCC7\uDD80-\uDDAE\uDDD8-\uDDDB\uDE00-\uDE2F\uDE44\uDE80-\uDEAA\uDF00-\uDF19]|\uD806[\uDCA0-\uDCDF\uDCFF\uDE00\uDE0B-\uDE32\uDE3A\uDE50\uDE5C-\uDE83\uDE86-\uDE89\uDEC0-\uDEF8]|\uD807[\uDC00-\uDC08\uDC0A-\uDC2E\uDC40\uDC72-\uDC8F\uDD00-\uDD06\uDD08\uDD09\uDD0B-\uDD30\uDD46]|\uD808[\uDC00-\uDF99]|\uD809[\uDC00-\uDC6E\uDC80-\uDD43]|[\uD80C\uD81C-\uD820\uD840-\uD868\uD86A-\uD86C\uD86F-\uD872\uD874-\uD879][\uDC00-\uDFFF]|\uD80D[\uDC00-\uDC2E]|\uD811[\uDC00-\uDE46]|\uD81A[\uDC00-\uDE38\uDE40-\uDE5E\uDED0-\uDEED\uDF00-\uDF2F\uDF40-\uDF43\uDF63-\uDF77\uDF7D-\uDF8F]|\uD81B[\uDF00-\uDF44\uDF50\uDF93-\uDF9F\uDFE0\uDFE1]|\uD821[\uDC00-\uDFEC]|\uD822[\uDC00-\uDEF2]|\uD82C[\uDC00-\uDD1E\uDD70-\uDEFB]|\uD82F[\uDC00-\uDC6A\uDC70-\uDC7C\uDC80-\uDC88\uDC90-\uDC99]|\uD835[\uDC00-\uDC54\uDC56-\uDC9C\uDC9E\uDC9F\uDCA2\uDCA5\uDCA6\uDCA9-\uDCAC\uDCAE-\uDCB9\uDCBB\uDCBD-\uDCC3\uDCC5-\uDD05\uDD07-\uDD0A\uDD0D-\uDD14\uDD16-\uDD1C\uDD1E-\uDD39\uDD3B-\uDD3E\uDD40-\uDD44\uDD46\uDD4A-\uDD50\uDD52-\uDEA5\uDEA8-\uDEC0\uDEC2-\uDEDA\uDEDC-\uDEFA\uDEFC-\uDF14\uDF16-\uDF34\uDF36-\uDF4E\uDF50-\uDF6E\uDF70-\uDF88\uDF8A-\uDFA8\uDFAA-\uDFC2\uDFC4-\uDFCB]|\uD83A[\uDC00-\uDCC4\uDD00-\uDD43]|\uD83B[\uDE00-\uDE03\uDE05-\uDE1F\uDE21\uDE22\uDE24\uDE27\uDE29-\uDE32\uDE34-\uDE37\uDE39\uDE3B\uDE42\uDE47\uDE49\uDE4B\uDE4D-\uDE4F\uDE51\uDE52\uDE54\uDE57\uDE59\uDE5B\uDE5D\uDE5F\uDE61\uDE62\uDE64\uDE67-\uDE6A\uDE6C-\uDE72\uDE74-\uDE77\uDE79-\uDE7C\uDE7E\uDE80-\uDE89\uDE8B-\uDE9B\uDEA1-\uDEA3\uDEA5-\uDEA9\uDEAB-\uDEBB]|\uD869[\uDC00-\uDED6\uDF00-\uDFFF]|\uD86D[\uDC00-\uDF34\uDF40-\uDFFF]|\uD86E[\uDC00-\uDC1D\uDC20-\uDFFF]|\uD873[\uDC00-\uDEA1\uDEB0-\uDFFF]|\uD87A[\uDC00-\uDFE0]|\uD87E[\uDC00-\uDE1D]/,ee.ID_Continue=/[\xAA\xB5\xBA\xC0-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0300-\u0374\u0376\u0377\u037A-\u037D\u037F\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u0483-\u0487\u048A-\u052F\u0531-\u0556\u0559\u0561-\u0587\u0591-\u05BD\u05BF\u05C1\u05C2\u05C4\u05C5\u05C7\u05D0-\u05EA\u05F0-\u05F2\u0610-\u061A\u0620-\u0669\u066E-\u06D3\u06D5-\u06DC\u06DF-\u06E8\u06EA-\u06FC\u06FF\u0710-\u074A\u074D-\u07B1\u07C0-\u07F5\u07FA\u0800-\u082D\u0840-\u085B\u0860-\u086A\u08A0-\u08B4\u08B6-\u08BD\u08D4-\u08E1\u08E3-\u0963\u0966-\u096F\u0971-\u0983\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BC-\u09C4\u09C7\u09C8\u09CB-\u09CE\u09D7\u09DC\u09DD\u09DF-\u09E3\u09E6-\u09F1\u09FC\u0A01-\u0A03\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A3C\u0A3E-\u0A42\u0A47\u0A48\u0A4B-\u0A4D\u0A51\u0A59-\u0A5C\u0A5E\u0A66-\u0A75\u0A81-\u0A83\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABC-\u0AC5\u0AC7-\u0AC9\u0ACB-\u0ACD\u0AD0\u0AE0-\u0AE3\u0AE6-\u0AEF\u0AF9-\u0AFF\u0B01-\u0B03\u0B05-\u0B0C\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3C-\u0B44\u0B47\u0B48\u0B4B-\u0B4D\u0B56\u0B57\u0B5C\u0B5D\u0B5F-\u0B63\u0B66-\u0B6F\u0B71\u0B82\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BBE-\u0BC2\u0BC6-\u0BC8\u0BCA-\u0BCD\u0BD0\u0BD7\u0BE6-\u0BEF\u0C00-\u0C03\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C39\u0C3D-\u0C44\u0C46-\u0C48\u0C4A-\u0C4D\u0C55\u0C56\u0C58-\u0C5A\u0C60-\u0C63\u0C66-\u0C6F\u0C80-\u0C83\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBC-\u0CC4\u0CC6-\u0CC8\u0CCA-\u0CCD\u0CD5\u0CD6\u0CDE\u0CE0-\u0CE3\u0CE6-\u0CEF\u0CF1\u0CF2\u0D00-\u0D03\u0D05-\u0D0C\u0D0E-\u0D10\u0D12-\u0D44\u0D46-\u0D48\u0D4A-\u0D4E\u0D54-\u0D57\u0D5F-\u0D63\u0D66-\u0D6F\u0D7A-\u0D7F\u0D82\u0D83\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0DCA\u0DCF-\u0DD4\u0DD6\u0DD8-\u0DDF\u0DE6-\u0DEF\u0DF2\u0DF3\u0E01-\u0E3A\u0E40-\u0E4E\u0E50-\u0E59\u0E81\u0E82\u0E84\u0E87\u0E88\u0E8A\u0E8D\u0E94-\u0E97\u0E99-\u0E9F\u0EA1-\u0EA3\u0EA5\u0EA7\u0EAA\u0EAB\u0EAD-\u0EB9\u0EBB-\u0EBD\u0EC0-\u0EC4\u0EC6\u0EC8-\u0ECD\u0ED0-\u0ED9\u0EDC-\u0EDF\u0F00\u0F18\u0F19\u0F20-\u0F29\u0F35\u0F37\u0F39\u0F3E-\u0F47\u0F49-\u0F6C\u0F71-\u0F84\u0F86-\u0F97\u0F99-\u0FBC\u0FC6\u1000-\u1049\u1050-\u109D\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FC-\u1248\u124A-\u124D\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310\u1312-\u1315\u1318-\u135A\u135D-\u135F\u1380-\u138F\u13A0-\u13F5\u13F8-\u13FD\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u16EE-\u16F8\u1700-\u170C\u170E-\u1714\u1720-\u1734\u1740-\u1753\u1760-\u176C\u176E-\u1770\u1772\u1773\u1780-\u17D3\u17D7\u17DC\u17DD\u17E0-\u17E9\u180B-\u180D\u1810-\u1819\u1820-\u1877\u1880-\u18AA\u18B0-\u18F5\u1900-\u191E\u1920-\u192B\u1930-\u193B\u1946-\u196D\u1970-\u1974\u1980-\u19AB\u19B0-\u19C9\u19D0-\u19D9\u1A00-\u1A1B\u1A20-\u1A5E\u1A60-\u1A7C\u1A7F-\u1A89\u1A90-\u1A99\u1AA7\u1AB0-\u1ABD\u1B00-\u1B4B\u1B50-\u1B59\u1B6B-\u1B73\u1B80-\u1BF3\u1C00-\u1C37\u1C40-\u1C49\u1C4D-\u1C7D\u1C80-\u1C88\u1CD0-\u1CD2\u1CD4-\u1CF9\u1D00-\u1DF9\u1DFB-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u203F\u2040\u2054\u2071\u207F\u2090-\u209C\u20D0-\u20DC\u20E1\u20E5-\u20F0\u2102\u2107\u210A-\u2113\u2115\u2119-\u211D\u2124\u2126\u2128\u212A-\u212D\u212F-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2160-\u2188\u2C00-\u2C2E\u2C30-\u2C5E\u2C60-\u2CE4\u2CEB-\u2CF3\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D7F-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u2DE0-\u2DFF\u2E2F\u3005-\u3007\u3021-\u302F\u3031-\u3035\u3038-\u303C\u3041-\u3096\u3099\u309A\u309D-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312E\u3131-\u318E\u31A0-\u31BA\u31F0-\u31FF\u3400-\u4DB5\u4E00-\u9FEA\uA000-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA62B\uA640-\uA66F\uA674-\uA67D\uA67F-\uA6F1\uA717-\uA71F\uA722-\uA788\uA78B-\uA7AE\uA7B0-\uA7B7\uA7F7-\uA827\uA840-\uA873\uA880-\uA8C5\uA8D0-\uA8D9\uA8E0-\uA8F7\uA8FB\uA8FD\uA900-\uA92D\uA930-\uA953\uA960-\uA97C\uA980-\uA9C0\uA9CF-\uA9D9\uA9E0-\uA9FE\uAA00-\uAA36\uAA40-\uAA4D\uAA50-\uAA59\uAA60-\uAA76\uAA7A-\uAAC2\uAADB-\uAADD\uAAE0-\uAAEF\uAAF2-\uAAF6\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uAB30-\uAB5A\uAB5C-\uAB65\uAB70-\uABEA\uABEC\uABED\uABF0-\uABF9\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE00-\uFE0F\uFE20-\uFE2F\uFE33\uFE34\uFE4D-\uFE4F\uFE70-\uFE74\uFE76-\uFEFC\uFF10-\uFF19\uFF21-\uFF3A\uFF3F\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC]|\uD800[\uDC00-\uDC0B\uDC0D-\uDC26\uDC28-\uDC3A\uDC3C\uDC3D\uDC3F-\uDC4D\uDC50-\uDC5D\uDC80-\uDCFA\uDD40-\uDD74\uDDFD\uDE80-\uDE9C\uDEA0-\uDED0\uDEE0\uDF00-\uDF1F\uDF2D-\uDF4A\uDF50-\uDF7A\uDF80-\uDF9D\uDFA0-\uDFC3\uDFC8-\uDFCF\uDFD1-\uDFD5]|\uD801[\uDC00-\uDC9D\uDCA0-\uDCA9\uDCB0-\uDCD3\uDCD8-\uDCFB\uDD00-\uDD27\uDD30-\uDD63\uDE00-\uDF36\uDF40-\uDF55\uDF60-\uDF67]|\uD802[\uDC00-\uDC05\uDC08\uDC0A-\uDC35\uDC37\uDC38\uDC3C\uDC3F-\uDC55\uDC60-\uDC76\uDC80-\uDC9E\uDCE0-\uDCF2\uDCF4\uDCF5\uDD00-\uDD15\uDD20-\uDD39\uDD80-\uDDB7\uDDBE\uDDBF\uDE00-\uDE03\uDE05\uDE06\uDE0C-\uDE13\uDE15-\uDE17\uDE19-\uDE33\uDE38-\uDE3A\uDE3F\uDE60-\uDE7C\uDE80-\uDE9C\uDEC0-\uDEC7\uDEC9-\uDEE6\uDF00-\uDF35\uDF40-\uDF55\uDF60-\uDF72\uDF80-\uDF91]|\uD803[\uDC00-\uDC48\uDC80-\uDCB2\uDCC0-\uDCF2]|\uD804[\uDC00-\uDC46\uDC66-\uDC6F\uDC7F-\uDCBA\uDCD0-\uDCE8\uDCF0-\uDCF9\uDD00-\uDD34\uDD36-\uDD3F\uDD50-\uDD73\uDD76\uDD80-\uDDC4\uDDCA-\uDDCC\uDDD0-\uDDDA\uDDDC\uDE00-\uDE11\uDE13-\uDE37\uDE3E\uDE80-\uDE86\uDE88\uDE8A-\uDE8D\uDE8F-\uDE9D\uDE9F-\uDEA8\uDEB0-\uDEEA\uDEF0-\uDEF9\uDF00-\uDF03\uDF05-\uDF0C\uDF0F\uDF10\uDF13-\uDF28\uDF2A-\uDF30\uDF32\uDF33\uDF35-\uDF39\uDF3C-\uDF44\uDF47\uDF48\uDF4B-\uDF4D\uDF50\uDF57\uDF5D-\uDF63\uDF66-\uDF6C\uDF70-\uDF74]|\uD805[\uDC00-\uDC4A\uDC50-\uDC59\uDC80-\uDCC5\uDCC7\uDCD0-\uDCD9\uDD80-\uDDB5\uDDB8-\uDDC0\uDDD8-\uDDDD\uDE00-\uDE40\uDE44\uDE50-\uDE59\uDE80-\uDEB7\uDEC0-\uDEC9\uDF00-\uDF19\uDF1D-\uDF2B\uDF30-\uDF39]|\uD806[\uDCA0-\uDCE9\uDCFF\uDE00-\uDE3E\uDE47\uDE50-\uDE83\uDE86-\uDE99\uDEC0-\uDEF8]|\uD807[\uDC00-\uDC08\uDC0A-\uDC36\uDC38-\uDC40\uDC50-\uDC59\uDC72-\uDC8F\uDC92-\uDCA7\uDCA9-\uDCB6\uDD00-\uDD06\uDD08\uDD09\uDD0B-\uDD36\uDD3A\uDD3C\uDD3D\uDD3F-\uDD47\uDD50-\uDD59]|\uD808[\uDC00-\uDF99]|\uD809[\uDC00-\uDC6E\uDC80-\uDD43]|[\uD80C\uD81C-\uD820\uD840-\uD868\uD86A-\uD86C\uD86F-\uD872\uD874-\uD879][\uDC00-\uDFFF]|\uD80D[\uDC00-\uDC2E]|\uD811[\uDC00-\uDE46]|\uD81A[\uDC00-\uDE38\uDE40-\uDE5E\uDE60-\uDE69\uDED0-\uDEED\uDEF0-\uDEF4\uDF00-\uDF36\uDF40-\uDF43\uDF50-\uDF59\uDF63-\uDF77\uDF7D-\uDF8F]|\uD81B[\uDF00-\uDF44\uDF50-\uDF7E\uDF8F-\uDF9F\uDFE0\uDFE1]|\uD821[\uDC00-\uDFEC]|\uD822[\uDC00-\uDEF2]|\uD82C[\uDC00-\uDD1E\uDD70-\uDEFB]|\uD82F[\uDC00-\uDC6A\uDC70-\uDC7C\uDC80-\uDC88\uDC90-\uDC99\uDC9D\uDC9E]|\uD834[\uDD65-\uDD69\uDD6D-\uDD72\uDD7B-\uDD82\uDD85-\uDD8B\uDDAA-\uDDAD\uDE42-\uDE44]|\uD835[\uDC00-\uDC54\uDC56-\uDC9C\uDC9E\uDC9F\uDCA2\uDCA5\uDCA6\uDCA9-\uDCAC\uDCAE-\uDCB9\uDCBB\uDCBD-\uDCC3\uDCC5-\uDD05\uDD07-\uDD0A\uDD0D-\uDD14\uDD16-\uDD1C\uDD1E-\uDD39\uDD3B-\uDD3E\uDD40-\uDD44\uDD46\uDD4A-\uDD50\uDD52-\uDEA5\uDEA8-\uDEC0\uDEC2-\uDEDA\uDEDC-\uDEFA\uDEFC-\uDF14\uDF16-\uDF34\uDF36-\uDF4E\uDF50-\uDF6E\uDF70-\uDF88\uDF8A-\uDFA8\uDFAA-\uDFC2\uDFC4-\uDFCB\uDFCE-\uDFFF]|\uD836[\uDE00-\uDE36\uDE3B-\uDE6C\uDE75\uDE84\uDE9B-\uDE9F\uDEA1-\uDEAF]|\uD838[\uDC00-\uDC06\uDC08-\uDC18\uDC1B-\uDC21\uDC23\uDC24\uDC26-\uDC2A]|\uD83A[\uDC00-\uDCC4\uDCD0-\uDCD6\uDD00-\uDD4A\uDD50-\uDD59]|\uD83B[\uDE00-\uDE03\uDE05-\uDE1F\uDE21\uDE22\uDE24\uDE27\uDE29-\uDE32\uDE34-\uDE37\uDE39\uDE3B\uDE42\uDE47\uDE49\uDE4B\uDE4D-\uDE4F\uDE51\uDE52\uDE54\uDE57\uDE59\uDE5B\uDE5D\uDE5F\uDE61\uDE62\uDE64\uDE67-\uDE6A\uDE6C-\uDE72\uDE74-\uDE77\uDE79-\uDE7C\uDE7E\uDE80-\uDE89\uDE8B-\uDE9B\uDEA1-\uDEA3\uDEA5-\uDEA9\uDEAB-\uDEBB]|\uD869[\uDC00-\uDED6\uDF00-\uDFFF]|\uD86D[\uDC00-\uDF34\uDF40-\uDFFF]|\uD86E[\uDC00-\uDC1D\uDC20-\uDFFF]|\uD873[\uDC00-\uDEA1\uDEB0-\uDFFF]|\uD87A[\uDC00-\uDFE0]|\uD87E[\uDC00-\uDE1D]|\uDB40[\uDD00-\uDDEF]/,Object.defineProperty(Z,"__esModule",{value:!0}),Z.JudgeUtil=void 0;const te=Q;Z.JudgeUtil=class{static isIgnoreChar(e){return"string"==typeof e&&("\t"===e||"\v"===e||"\f"===e||" "===e||" "===e||"\ufeff"===e||"\n"===e||"\r"===e||"\u2028"===e||"\u2029"===e)}static isSpaceSeparator(e){return"string"==typeof e&&te.Unicode.Space_Separator.test(e)}static isIdStartChar(e){return"string"==typeof e&&(e>="a"&&e<="z"||e>="A"&&e<="Z"||"$"===e||"_"===e||te.Unicode.ID_Start.test(e))}static isIdContinueChar(e){return"string"==typeof e&&(e>="a"&&e<="z"||e>="A"&&e<="Z"||e>="0"&&e<="9"||"$"===e||"_"===e||"‌"===e||"‍"===e||te.Unicode.ID_Continue.test(e))}static isDigitWithoutZero(e){return/[1-9]/.test(e)}static isDigit(e){return"string"==typeof e&&/[0-9]/.test(e)}static isHexDigit(e){return"string"==typeof e&&/[0-9A-Fa-f]/.test(e)}};var ne={},re={fromCallback:function(e){return Object.defineProperty((function(...t){if("function"!=typeof t[t.length-1])return new Promise(((n,r)=>{e.call(this,...t,((e,t)=>null!=e?r(e):n(t)))}));e.apply(this,t)}),"name",{value:e.name})},fromPromise:function(e){return Object.defineProperty((function(...t){const n=t[t.length-1];if("function"!=typeof n)return e.apply(this,t);e.apply(this,t.slice(0,-1)).then((e=>n(null,e)),n)}),"name",{value:e.name})}},ue=y.default,oe=process.cwd,ie=null,se=process.env.GRACEFUL_FS_PLATFORM||process.platform;process.cwd=function(){return ie||(ie=oe.call(process)),ie};try{process.cwd()}catch(e){}if("function"==typeof process.chdir){var ce=process.chdir;process.chdir=function(e){ie=null,ce.call(process,e)},Object.setPrototypeOf&&Object.setPrototypeOf(process.chdir,ce)}var ae=function(e){ue.hasOwnProperty("O_SYMLINK")&&process.version.match(/^v0\.6\.[0-2]|^v0\.5\./)&&function(e){e.lchmod=function(t,n,r){e.open(t,ue.O_WRONLY|ue.O_SYMLINK,n,(function(t,u){t?r&&r(t):e.fchmod(u,n,(function(t){e.close(u,(function(e){r&&r(t||e)}))}))}))},e.lchmodSync=function(t,n){var r,u=e.openSync(t,ue.O_WRONLY|ue.O_SYMLINK,n),o=!0;try{r=e.fchmodSync(u,n),o=!1}finally{if(o)try{e.closeSync(u)}catch(e){}else e.closeSync(u)}return r}}(e);e.lutimes||function(e){ue.hasOwnProperty("O_SYMLINK")&&e.futimes?(e.lutimes=function(t,n,r,u){e.open(t,ue.O_SYMLINK,(function(t,o){t?u&&u(t):e.futimes(o,n,r,(function(t){e.close(o,(function(e){u&&u(t||e)}))}))}))},e.lutimesSync=function(t,n,r){var u,o=e.openSync(t,ue.O_SYMLINK),i=!0;try{u=e.futimesSync(o,n,r),i=!1}finally{if(i)try{e.closeSync(o)}catch(e){}else e.closeSync(o)}return u}):e.futimes&&(e.lutimes=function(e,t,n,r){r&&process.nextTick(r)},e.lutimesSync=function(){})}(e);e.chown=r(e.chown),e.fchown=r(e.fchown),e.lchown=r(e.lchown),e.chmod=t(e.chmod),e.fchmod=t(e.fchmod),e.lchmod=t(e.lchmod),e.chownSync=u(e.chownSync),e.fchownSync=u(e.fchownSync),e.lchownSync=u(e.lchownSync),e.chmodSync=n(e.chmodSync),e.fchmodSync=n(e.fchmodSync),e.lchmodSync=n(e.lchmodSync),e.stat=o(e.stat),e.fstat=o(e.fstat),e.lstat=o(e.lstat),e.statSync=i(e.statSync),e.fstatSync=i(e.fstatSync),e.lstatSync=i(e.lstatSync),e.chmod&&!e.lchmod&&(e.lchmod=function(e,t,n){n&&process.nextTick(n)},e.lchmodSync=function(){});e.chown&&!e.lchown&&(e.lchown=function(e,t,n,r){r&&process.nextTick(r)},e.lchownSync=function(){});"win32"===se&&(e.rename="function"!=typeof e.rename?e.rename:function(t){function n(n,r,u){var o=Date.now(),i=0;t(n,r,(function s(c){if(c&&("EACCES"===c.code||"EPERM"===c.code||"EBUSY"===c.code)&&Date.now()-o<6e4)return setTimeout((function(){e.stat(r,(function(e,o){e&&"ENOENT"===e.code?t(n,r,s):u(c)}))}),i),void(i<100&&(i+=10));u&&u(c)}))}return Object.setPrototypeOf&&Object.setPrototypeOf(n,t),n}(e.rename));function t(t){return t?function(n,r,u){return t.call(e,n,r,(function(e){s(e)&&(e=null),u&&u.apply(this,arguments)}))}:t}function n(t){return t?function(n,r){try{return t.call(e,n,r)}catch(e){if(!s(e))throw e}}:t}function r(t){return t?function(n,r,u,o){return t.call(e,n,r,u,(function(e){s(e)&&(e=null),o&&o.apply(this,arguments)}))}:t}function u(t){return t?function(n,r,u){try{return t.call(e,n,r,u)}catch(e){if(!s(e))throw e}}:t}function o(t){return t?function(n,r,u){function o(e,t){t&&(t.uid<0&&(t.uid+=4294967296),t.gid<0&&(t.gid+=4294967296)),u&&u.apply(this,arguments)}return"function"==typeof r&&(u=r,r=null),r?t.call(e,n,r,o):t.call(e,n,o)}:t}function i(t){return t?function(n,r){var u=r?t.call(e,n,r):t.call(e,n);return u&&(u.uid<0&&(u.uid+=4294967296),u.gid<0&&(u.gid+=4294967296)),u}:t}function s(e){return!e||("ENOSYS"===e.code||!(process.getuid&&0===process.getuid()||"EINVAL"!==e.code&&"EPERM"!==e.code))}e.read="function"!=typeof e.read?e.read:function(t){function n(n,r,u,o,i,s){var c;if(s&&"function"==typeof s){var a=0;c=function(l,f,d){if(l&&"EAGAIN"===l.code&&a<10)return a++,t.call(e,n,r,u,o,i,c);s.apply(this,arguments)}}return t.call(e,n,r,u,o,i,c)}return Object.setPrototypeOf&&Object.setPrototypeOf(n,t),n}(e.read),e.readSync="function"!=typeof e.readSync?e.readSync:(c=e.readSync,function(t,n,r,u,o){for(var i=0;;)try{return c.call(e,t,n,r,u,o)}catch(e){if("EAGAIN"===e.code&&i<10){i++;continue}throw e}});var c};var le=C.default.Stream,fe=function(e){return{ReadStream:function t(n,r){if(!(this instanceof t))return new t(n,r);le.call(this);var u=this;this.path=n,this.fd=null,this.readable=!0,this.paused=!1,this.flags="r",this.mode=438,this.bufferSize=65536,r=r||{};for(var o=Object.keys(r),i=0,s=o.length;ithis.end)throw new Error("start must be <= end");this.pos=this.start}if(null!==this.fd)return void process.nextTick((function(){u._read()}));e.open(this.path,this.flags,this.mode,(function(e,t){if(e)return u.emit("error",e),void(u.readable=!1);u.fd=t,u.emit("open",t),u._read()}))},WriteStream:function t(n,r){if(!(this instanceof t))return new t(n,r);le.call(this),this.path=n,this.fd=null,this.writable=!0,this.flags="w",this.encoding="binary",this.mode=438,this.bytesWritten=0,r=r||{};for(var u=Object.keys(r),o=0,i=u.length;o= zero");this.pos=this.start}this.busy=!1,this._queue=[],null===this.fd&&(this._open=e.open,this._queue.push([this._open,this.path,this.flags,this.mode,void 0]),this.flush())}}};var de=function(e){if(null===e||"object"!=typeof e)return e;if(e instanceof Object)var t={__proto__:De(e)};else t=Object.create(null);return Object.getOwnPropertyNames(e).forEach((function(n){Object.defineProperty(t,n,Object.getOwnPropertyDescriptor(e,n))})),t},De=Object.getPrototypeOf||function(e){return e.__proto__};var pe,Ee,me=D.default,he=ae,ye=fe,Ce=de,Fe=F.default;function ge(e,t){Object.defineProperty(e,pe,{get:function(){return t}})}"function"==typeof Symbol&&"function"==typeof Symbol.for?(pe=Symbol.for("graceful-fs.queue"),Ee=Symbol.for("graceful-fs.previous")):(pe="___graceful-fs.queue",Ee="___graceful-fs.previous");var Ae=function(){};if(Fe.debuglog?Ae=Fe.debuglog("gfs4"):/\bgfs4\b/i.test(process.env.NODE_DEBUG||"")&&(Ae=function(){var e=Fe.format.apply(Fe,arguments);e="GFS4: "+e.split(/\n/).join("\nGFS4: "),console.error(e)}),!me[pe]){var ve=w[pe]||[];ge(me,ve),me.close=function(e){function t(t,n){return e.call(me,t,(function(e){e||_e(),"function"==typeof n&&n.apply(this,arguments)}))}return Object.defineProperty(t,Ee,{value:e}),t}(me.close),me.closeSync=function(e){function t(t){e.apply(me,arguments),_e()}return Object.defineProperty(t,Ee,{value:e}),t}(me.closeSync),/\bgfs4\b/i.test(process.env.NODE_DEBUG||"")&&process.on("exit",(function(){Ae(me[pe]),g.default.equal(me[pe].length,0)}))}w[pe]||ge(w,me[pe]);var Se,we=Oe(Ce(me));function Oe(e){he(e),e.gracefulify=Oe,e.createReadStream=function(t,n){return new e.ReadStream(t,n)},e.createWriteStream=function(t,n){return new e.WriteStream(t,n)};var t=e.readFile;e.readFile=function(e,n,r){"function"==typeof n&&(r=n,n=null);return function e(n,r,u,o){return t(n,r,(function(t){!t||"EMFILE"!==t.code&&"ENFILE"!==t.code?"function"==typeof u&&u.apply(this,arguments):be([e,[n,r,u],t,o||Date.now(),Date.now()])}))}(e,n,r)};var n=e.writeFile;e.writeFile=function(e,t,r,u){"function"==typeof r&&(u=r,r=null);return function e(t,r,u,o,i){return n(t,r,u,(function(n){!n||"EMFILE"!==n.code&&"ENFILE"!==n.code?"function"==typeof o&&o.apply(this,arguments):be([e,[t,r,u,o],n,i||Date.now(),Date.now()])}))}(e,t,r,u)};var r=e.appendFile;r&&(e.appendFile=function(e,t,n,u){"function"==typeof n&&(u=n,n=null);return function e(t,n,u,o,i){return r(t,n,u,(function(r){!r||"EMFILE"!==r.code&&"ENFILE"!==r.code?"function"==typeof o&&o.apply(this,arguments):be([e,[t,n,u,o],r,i||Date.now(),Date.now()])}))}(e,t,n,u)});var u=e.copyFile;u&&(e.copyFile=function(e,t,n,r){"function"==typeof n&&(r=n,n=0);return function e(t,n,r,o,i){return u(t,n,r,(function(u){!u||"EMFILE"!==u.code&&"ENFILE"!==u.code?"function"==typeof o&&o.apply(this,arguments):be([e,[t,n,r,o],u,i||Date.now(),Date.now()])}))}(e,t,n,r)});var o=e.readdir;e.readdir=function(e,t,n){"function"==typeof t&&(n=t,t=null);var r=i.test(process.version)?function(e,t,n,r){return o(e,u(e,t,n,r))}:function(e,t,n,r){return o(e,t,u(e,t,n,r))};return r(e,t,n);function u(e,t,n,u){return function(o,i){!o||"EMFILE"!==o.code&&"ENFILE"!==o.code?(i&&i.sort&&i.sort(),"function"==typeof n&&n.call(this,o,i)):be([r,[e,t,n],o,u||Date.now(),Date.now()])}}};var i=/^v[0-5]\./;if("v0.8"===process.version.substr(0,4)){var s=ye(e);d=s.ReadStream,D=s.WriteStream}var c=e.ReadStream;c&&(d.prototype=Object.create(c.prototype),d.prototype.open=function(){var e=this;E(e.path,e.flags,e.mode,(function(t,n){t?(e.autoClose&&e.destroy(),e.emit("error",t)):(e.fd=n,e.emit("open",n),e.read())}))});var a=e.WriteStream;a&&(D.prototype=Object.create(a.prototype),D.prototype.open=function(){var e=this;E(e.path,e.flags,e.mode,(function(t,n){t?(e.destroy(),e.emit("error",t)):(e.fd=n,e.emit("open",n))}))}),Object.defineProperty(e,"ReadStream",{get:function(){return d},set:function(e){d=e},enumerable:!0,configurable:!0}),Object.defineProperty(e,"WriteStream",{get:function(){return D},set:function(e){D=e},enumerable:!0,configurable:!0});var l=d;Object.defineProperty(e,"FileReadStream",{get:function(){return l},set:function(e){l=e},enumerable:!0,configurable:!0});var f=D;function d(e,t){return this instanceof d?(c.apply(this,arguments),this):d.apply(Object.create(d.prototype),arguments)}function D(e,t){return this instanceof D?(a.apply(this,arguments),this):D.apply(Object.create(D.prototype),arguments)}Object.defineProperty(e,"FileWriteStream",{get:function(){return f},set:function(e){f=e},enumerable:!0,configurable:!0});var p=e.open;function E(e,t,n,r){return"function"==typeof n&&(r=n,n=null),function e(t,n,r,u,o){return p(t,n,r,(function(i,s){!i||"EMFILE"!==i.code&&"ENFILE"!==i.code?"function"==typeof u&&u.apply(this,arguments):be([e,[t,n,r,u],i,o||Date.now(),Date.now()])}))}(e,t,n,r)}return e.open=E,e}function be(e){Ae("ENQUEUE",e[0].name,e[1]),me[pe].push(e),Be()}function _e(){for(var e=Date.now(),t=0;t2&&(me[pe][t][3]=e,me[pe][t][4]=e);Be()}function Be(){if(clearTimeout(Se),Se=void 0,0!==me[pe].length){var e=me[pe].shift(),t=e[0],n=e[1],r=e[2],u=e[3],o=e[4];if(void 0===u)Ae("RETRY",t.name,n),t.apply(null,n);else if(Date.now()-u>=6e4){Ae("TIMEOUT",t.name,n);var i=n.pop();"function"==typeof i&&i.call(null,r)}else{var s=Date.now()-o,c=Math.max(o-u,1);s>=Math.min(1.2*c,100)?(Ae("RETRY",t.name,n),t.apply(null,n.concat([u]))):me[pe].push(e)}void 0===Se&&(Se=setTimeout(Be,0))}}process.env.TEST_GRACEFUL_FS_GLOBAL_PATCH&&!me.__patched&&(we=Oe(me),me.__patched=!0),function(e){const t=re.fromCallback,n=we,r=["access","appendFile","chmod","chown","close","copyFile","fchmod","fchown","fdatasync","fstat","fsync","ftruncate","futimes","lchmod","lchown","link","lstat","mkdir","mkdtemp","open","opendir","readdir","readFile","readlink","realpath","rename","rm","rmdir","stat","symlink","truncate","unlink","utimes","writeFile"].filter((e=>"function"==typeof n[e]));Object.assign(e,n),r.forEach((r=>{e[r]=t(n[r])})),e.realpath.native=t(n.realpath.native),e.exists=function(e,t){return"function"==typeof t?n.exists(e,t):new Promise((t=>n.exists(e,t)))},e.read=function(e,t,r,u,o,i){return"function"==typeof i?n.read(e,t,r,u,o,i):new Promise(((i,s)=>{n.read(e,t,r,u,o,((e,t,n)=>{if(e)return s(e);i({bytesRead:t,buffer:n})}))}))},e.write=function(e,t,...r){return"function"==typeof r[r.length-1]?n.write(e,t,...r):new Promise(((u,o)=>{n.write(e,t,...r,((e,t,n)=>{if(e)return o(e);u({bytesWritten:t,buffer:n})}))}))},"function"==typeof n.writev&&(e.writev=function(e,t,...r){return"function"==typeof r[r.length-1]?n.writev(e,t,...r):new Promise(((u,o)=>{n.writev(e,t,...r,((e,t,n)=>{if(e)return o(e);u({bytesWritten:t,buffers:n})}))}))})}(ne);var Pe={},ke={};const xe=p.default;ke.checkPath=function(e){if("win32"===process.platform){if(/[<>:"|?*]/.test(e.replace(xe.parse(e).root,""))){const t=new Error(`Path contains invalid characters: ${e}`);throw t.code="EINVAL",t}}};const Ne=ne,{checkPath:Ie}=ke,Te=e=>"number"==typeof e?e:{mode:511,...e}.mode;Pe.makeDir=async(e,t)=>(Ie(e),Ne.mkdir(e,{mode:Te(t),recursive:!0})),Pe.makeDirSync=(e,t)=>(Ie(e),Ne.mkdirSync(e,{mode:Te(t),recursive:!0}));const Re=re.fromPromise,{makeDir:Me,makeDirSync:Le}=Pe,je=Re(Me);var $e={mkdirs:je,mkdirsSync:Le,mkdirp:je,mkdirpSync:Le,ensureDir:je,ensureDirSync:Le};const He=re.fromPromise,Je=ne;var Ge={pathExists:He((function(e){return Je.access(e).then((()=>!0)).catch((()=>!1))})),pathExistsSync:Je.existsSync};const Ve=we;var Ue=function(e,t,n,r){Ve.open(e,"r+",((e,u)=>{if(e)return r(e);Ve.futimes(u,t,n,(e=>{Ve.close(u,(t=>{r&&r(e||t)}))}))}))},We=function(e,t,n){const r=Ve.openSync(e,"r+");return Ve.futimesSync(r,t,n),Ve.closeSync(r)};const ze=ne,Ke=p.default,qe=F.default;function Ye(e,t,n){const r=n.dereference?e=>ze.stat(e,{bigint:!0}):e=>ze.lstat(e,{bigint:!0});return Promise.all([r(e),r(t).catch((e=>{if("ENOENT"===e.code)return null;throw e}))]).then((([e,t])=>({srcStat:e,destStat:t})))}function Xe(e,t){return t.ino&&t.dev&&t.ino===e.ino&&t.dev===e.dev}function Ze(e,t){const n=Ke.resolve(e).split(Ke.sep).filter((e=>e)),r=Ke.resolve(t).split(Ke.sep).filter((e=>e));return n.reduce(((e,t,n)=>e&&r[n]===t),!0)}function Qe(e,t,n){return`Cannot ${n} '${e}' to a subdirectory of itself, '${t}'.`}var et={checkPaths:function(e,t,n,r,u){qe.callbackify(Ye)(e,t,r,((r,o)=>{if(r)return u(r);const{srcStat:i,destStat:s}=o;if(s){if(Xe(i,s)){const r=Ke.basename(e),o=Ke.basename(t);return"move"===n&&r!==o&&r.toLowerCase()===o.toLowerCase()?u(null,{srcStat:i,destStat:s,isChangingCase:!0}):u(new Error("Source and destination must not be the same."))}if(i.isDirectory()&&!s.isDirectory())return u(new Error(`Cannot overwrite non-directory '${t}' with directory '${e}'.`));if(!i.isDirectory()&&s.isDirectory())return u(new Error(`Cannot overwrite directory '${t}' with non-directory '${e}'.`))}return i.isDirectory()&&Ze(e,t)?u(new Error(Qe(e,t,n))):u(null,{srcStat:i,destStat:s})}))},checkPathsSync:function(e,t,n,r){const{srcStat:u,destStat:o}=function(e,t,n){let r;const u=n.dereference?e=>ze.statSync(e,{bigint:!0}):e=>ze.lstatSync(e,{bigint:!0}),o=u(e);try{r=u(t)}catch(e){if("ENOENT"===e.code)return{srcStat:o,destStat:null};throw e}return{srcStat:o,destStat:r}}(e,t,r);if(o){if(Xe(u,o)){const r=Ke.basename(e),i=Ke.basename(t);if("move"===n&&r!==i&&r.toLowerCase()===i.toLowerCase())return{srcStat:u,destStat:o,isChangingCase:!0};throw new Error("Source and destination must not be the same.")}if(u.isDirectory()&&!o.isDirectory())throw new Error(`Cannot overwrite non-directory '${t}' with directory '${e}'.`);if(!u.isDirectory()&&o.isDirectory())throw new Error(`Cannot overwrite directory '${t}' with non-directory '${e}'.`)}if(u.isDirectory()&&Ze(e,t))throw new Error(Qe(e,t,n));return{srcStat:u,destStat:o}},checkParentPaths:function e(t,n,r,u,o){const i=Ke.resolve(Ke.dirname(t)),s=Ke.resolve(Ke.dirname(r));if(s===i||s===Ke.parse(s).root)return o();ze.stat(s,{bigint:!0},((i,c)=>i?"ENOENT"===i.code?o():o(i):Xe(n,c)?o(new Error(Qe(t,r,u))):e(t,n,s,u,o)))},checkParentPathsSync:function e(t,n,r,u){const o=Ke.resolve(Ke.dirname(t)),i=Ke.resolve(Ke.dirname(r));if(i===o||i===Ke.parse(i).root)return;let s;try{s=ze.statSync(i,{bigint:!0})}catch(e){if("ENOENT"===e.code)return;throw e}if(Xe(n,s))throw new Error(Qe(t,r,u));return e(t,n,i,u)},isSrcSubdir:Ze,areIdentical:Xe};const tt=we,nt=p.default,rt=$e.mkdirs,ut=Ge.pathExists,ot=Ue,it=et;function st(e,t,n,r,u){const o=nt.dirname(n);ut(o,((i,s)=>i?u(i):s?at(e,t,n,r,u):void rt(o,(o=>o?u(o):at(e,t,n,r,u)))))}function ct(e,t,n,r,u,o){Promise.resolve(u.filter(n,r)).then((i=>i?e(t,n,r,u,o):o()),(e=>o(e)))}function at(e,t,n,r,u){(r.dereference?tt.stat:tt.lstat)(t,((o,i)=>o?u(o):i.isDirectory()?function(e,t,n,r,u,o){return t?Dt(n,r,u,o):function(e,t,n,r,u){tt.mkdir(n,(o=>{if(o)return u(o);Dt(t,n,r,(t=>t?u(t):dt(n,e,u)))}))}(e.mode,n,r,u,o)}(i,e,t,n,r,u):i.isFile()||i.isCharacterDevice()||i.isBlockDevice()?function(e,t,n,r,u,o){return t?function(e,t,n,r,u){if(!r.overwrite)return r.errorOnExist?u(new Error(`'${n}' already exists`)):u();tt.unlink(n,(o=>o?u(o):lt(e,t,n,r,u)))}(e,n,r,u,o):lt(e,n,r,u,o)}(i,e,t,n,r,u):i.isSymbolicLink()?function(e,t,n,r,u){tt.readlink(t,((t,o)=>t?u(t):(r.dereference&&(o=nt.resolve(process.cwd(),o)),e?void tt.readlink(n,((t,i)=>t?"EINVAL"===t.code||"UNKNOWN"===t.code?tt.symlink(o,n,u):u(t):(r.dereference&&(i=nt.resolve(process.cwd(),i)),it.isSrcSubdir(o,i)?u(new Error(`Cannot copy '${o}' to a subdirectory of itself, '${i}'.`)):e.isDirectory()&&it.isSrcSubdir(i,o)?u(new Error(`Cannot overwrite '${i}' with '${o}'.`)):function(e,t,n){tt.unlink(t,(r=>r?n(r):tt.symlink(e,t,n)))}(o,n,u)))):tt.symlink(o,n,u))))}(e,t,n,r,u):i.isSocket()?u(new Error(`Cannot copy a socket file: ${t}`)):i.isFIFO()?u(new Error(`Cannot copy a FIFO pipe: ${t}`)):u(new Error(`Unknown file: ${t}`))))}function lt(e,t,n,r,u){tt.copyFile(t,n,(o=>o?u(o):r.preserveTimestamps?function(e,t,n,r){if(function(e){return 0==(128&e)}(e))return function(e,t,n){return dt(e,128|t,n)}(n,e,(u=>u?r(u):ft(e,t,n,r)));return ft(e,t,n,r)}(e.mode,t,n,u):dt(n,e.mode,u)))}function ft(e,t,n,r){!function(e,t,n){tt.stat(e,((e,r)=>e?n(e):ot(t,r.atime,r.mtime,n)))}(t,n,(t=>t?r(t):dt(n,e,r)))}function dt(e,t,n){return tt.chmod(e,t,n)}function Dt(e,t,n,r){tt.readdir(e,((u,o)=>u?r(u):pt(o,e,t,n,r)))}function pt(e,t,n,r,u){const o=e.pop();return o?function(e,t,n,r,u,o){const i=nt.join(n,t),s=nt.join(r,t);it.checkPaths(i,s,"copy",u,((t,c)=>{if(t)return o(t);const{destStat:a}=c;!function(e,t,n,r,u){r.filter?ct(at,e,t,n,r,u):at(e,t,n,r,u)}(a,i,s,u,(t=>t?o(t):pt(e,n,r,u,o)))}))}(e,o,t,n,r,u):u()}var Et=function(e,t,n,r){"function"!=typeof n||r?"function"==typeof n&&(n={filter:n}):(r=n,n={}),r=r||function(){},(n=n||{}).clobber=!("clobber"in n)||!!n.clobber,n.overwrite="overwrite"in n?!!n.overwrite:n.clobber,n.preserveTimestamps&&"ia32"===process.arch&&console.warn("fs-extra: Using the preserveTimestamps option in 32-bit node is not recommended;\n\n see https://github.com/jprichardson/node-fs-extra/issues/269"),it.checkPaths(e,t,"copy",n,((u,o)=>{if(u)return r(u);const{srcStat:i,destStat:s}=o;it.checkParentPaths(e,i,t,"copy",(u=>u?r(u):n.filter?ct(st,s,e,t,n,r):st(s,e,t,n,r)))}))};const mt=we,ht=p.default,yt=$e.mkdirsSync,Ct=We,Ft=et;function gt(e,t,n,r){const u=(r.dereference?mt.statSync:mt.lstatSync)(t);if(u.isDirectory())return function(e,t,n,r,u){return t?St(n,r,u):function(e,t,n,r){return mt.mkdirSync(n),St(t,n,r),vt(n,e)}(e.mode,n,r,u)}(u,e,t,n,r);if(u.isFile()||u.isCharacterDevice()||u.isBlockDevice())return function(e,t,n,r,u){return t?function(e,t,n,r){if(r.overwrite)return mt.unlinkSync(n),At(e,t,n,r);if(r.errorOnExist)throw new Error(`'${n}' already exists`)}(e,n,r,u):At(e,n,r,u)}(u,e,t,n,r);if(u.isSymbolicLink())return function(e,t,n,r){let u=mt.readlinkSync(t);r.dereference&&(u=ht.resolve(process.cwd(),u));if(e){let e;try{e=mt.readlinkSync(n)}catch(e){if("EINVAL"===e.code||"UNKNOWN"===e.code)return mt.symlinkSync(u,n);throw e}if(r.dereference&&(e=ht.resolve(process.cwd(),e)),Ft.isSrcSubdir(u,e))throw new Error(`Cannot copy '${u}' to a subdirectory of itself, '${e}'.`);if(mt.statSync(n).isDirectory()&&Ft.isSrcSubdir(e,u))throw new Error(`Cannot overwrite '${e}' with '${u}'.`);return function(e,t){return mt.unlinkSync(t),mt.symlinkSync(e,t)}(u,n)}return mt.symlinkSync(u,n)}(e,t,n,r);if(u.isSocket())throw new Error(`Cannot copy a socket file: ${t}`);if(u.isFIFO())throw new Error(`Cannot copy a FIFO pipe: ${t}`);throw new Error(`Unknown file: ${t}`)}function At(e,t,n,r){return mt.copyFileSync(t,n),r.preserveTimestamps&&function(e,t,n){(function(e){return 0==(128&e)})(e)&&function(e,t){vt(e,128|t)}(n,e);(function(e,t){const n=mt.statSync(e);Ct(t,n.atime,n.mtime)})(t,n)}(e.mode,t,n),vt(n,e.mode)}function vt(e,t){return mt.chmodSync(e,t)}function St(e,t,n){mt.readdirSync(e).forEach((r=>function(e,t,n,r){const u=ht.join(t,e),o=ht.join(n,e),{destStat:i}=Ft.checkPathsSync(u,o,"copy",r);return function(e,t,n,r){if(!r.filter||r.filter(t,n))return gt(e,t,n,r)}(i,u,o,r)}(r,e,t,n)))}var wt=function(e,t,n){"function"==typeof n&&(n={filter:n}),(n=n||{}).clobber=!("clobber"in n)||!!n.clobber,n.overwrite="overwrite"in n?!!n.overwrite:n.clobber,n.preserveTimestamps&&"ia32"===process.arch&&console.warn("fs-extra: Using the preserveTimestamps option in 32-bit node is not recommended;\n\n see https://github.com/jprichardson/node-fs-extra/issues/269");const{srcStat:r,destStat:u}=Ft.checkPathsSync(e,t,"copy",n);return Ft.checkParentPathsSync(e,r,t,"copy"),function(e,t,n,r){if(r.filter&&!r.filter(t,n))return;const u=ht.dirname(n);mt.existsSync(u)||yt(u);return gt(e,t,n,r)}(u,e,t,n)};var Ot={copy:(0,re.fromCallback)(Et),copySync:wt};const bt=we,_t=p.default,Bt=g.default,Pt="win32"===process.platform;function kt(e){["unlink","chmod","stat","lstat","rmdir","readdir"].forEach((t=>{e[t]=e[t]||bt[t],e[t+="Sync"]=e[t]||bt[t]})),e.maxBusyTries=e.maxBusyTries||3}function xt(e,t,n){let r=0;"function"==typeof t&&(n=t,t={}),Bt(e,"rimraf: missing path"),Bt.strictEqual(typeof e,"string","rimraf: path should be a string"),Bt.strictEqual(typeof n,"function","rimraf: callback function required"),Bt(t,"rimraf: invalid options argument provided"),Bt.strictEqual(typeof t,"object","rimraf: options should be object"),kt(t),Nt(e,t,(function u(o){if(o){if(("EBUSY"===o.code||"ENOTEMPTY"===o.code||"EPERM"===o.code)&&rNt(e,t,u)),100*r)}"ENOENT"===o.code&&(o=null)}n(o)}))}function Nt(e,t,n){Bt(e),Bt(t),Bt("function"==typeof n),t.lstat(e,((r,u)=>r&&"ENOENT"===r.code?n(null):r&&"EPERM"===r.code&&Pt?It(e,t,r,n):u&&u.isDirectory()?Rt(e,t,r,n):void t.unlink(e,(r=>{if(r){if("ENOENT"===r.code)return n(null);if("EPERM"===r.code)return Pt?It(e,t,r,n):Rt(e,t,r,n);if("EISDIR"===r.code)return Rt(e,t,r,n)}return n(r)}))))}function It(e,t,n,r){Bt(e),Bt(t),Bt("function"==typeof r),t.chmod(e,438,(u=>{u?r("ENOENT"===u.code?null:n):t.stat(e,((u,o)=>{u?r("ENOENT"===u.code?null:n):o.isDirectory()?Rt(e,t,n,r):t.unlink(e,r)}))}))}function Tt(e,t,n){let r;Bt(e),Bt(t);try{t.chmodSync(e,438)}catch(e){if("ENOENT"===e.code)return;throw n}try{r=t.statSync(e)}catch(e){if("ENOENT"===e.code)return;throw n}r.isDirectory()?Lt(e,t,n):t.unlinkSync(e)}function Rt(e,t,n,r){Bt(e),Bt(t),Bt("function"==typeof r),t.rmdir(e,(u=>{!u||"ENOTEMPTY"!==u.code&&"EEXIST"!==u.code&&"EPERM"!==u.code?u&&"ENOTDIR"===u.code?r(n):r(u):function(e,t,n){Bt(e),Bt(t),Bt("function"==typeof n),t.readdir(e,((r,u)=>{if(r)return n(r);let o,i=u.length;if(0===i)return t.rmdir(e,n);u.forEach((r=>{xt(_t.join(e,r),t,(r=>{if(!o)return r?n(o=r):void(0==--i&&t.rmdir(e,n))}))}))}))}(e,t,r)}))}function Mt(e,t){let n;kt(t=t||{}),Bt(e,"rimraf: missing path"),Bt.strictEqual(typeof e,"string","rimraf: path should be a string"),Bt(t,"rimraf: missing options"),Bt.strictEqual(typeof t,"object","rimraf: options should be object");try{n=t.lstatSync(e)}catch(n){if("ENOENT"===n.code)return;"EPERM"===n.code&&Pt&&Tt(e,t,n)}try{n&&n.isDirectory()?Lt(e,t,null):t.unlinkSync(e)}catch(n){if("ENOENT"===n.code)return;if("EPERM"===n.code)return Pt?Tt(e,t,n):Lt(e,t,n);if("EISDIR"!==n.code)throw n;Lt(e,t,n)}}function Lt(e,t,n){Bt(e),Bt(t);try{t.rmdirSync(e)}catch(r){if("ENOTDIR"===r.code)throw n;if("ENOTEMPTY"===r.code||"EEXIST"===r.code||"EPERM"===r.code)!function(e,t){if(Bt(e),Bt(t),t.readdirSync(e).forEach((n=>Mt(_t.join(e,n),t))),!Pt){return t.rmdirSync(e,t)}{const n=Date.now();do{try{return t.rmdirSync(e,t)}catch{}}while(Date.now()-n<500)}}(e,t);else if("ENOENT"!==r.code)throw r}}var jt=xt;xt.sync=Mt;const $t=we,Ht=re.fromCallback,Jt=jt;var Gt={remove:Ht((function(e,t){if($t.rm)return $t.rm(e,{recursive:!0,force:!0},t);Jt(e,t)})),removeSync:function(e){if($t.rmSync)return $t.rmSync(e,{recursive:!0,force:!0});Jt.sync(e)}};const Vt=re.fromPromise,Ut=ne,Wt=p.default,zt=$e,Kt=Gt,qt=Vt((async function(e){let t;try{t=await Ut.readdir(e)}catch{return zt.mkdirs(e)}return Promise.all(t.map((t=>Kt.remove(Wt.join(e,t)))))}));function Yt(e){let t;try{t=Ut.readdirSync(e)}catch{return zt.mkdirsSync(e)}t.forEach((t=>{t=Wt.join(e,t),Kt.removeSync(t)}))}var Xt={emptyDirSync:Yt,emptydirSync:Yt,emptyDir:qt,emptydir:qt};const Zt=re.fromCallback,Qt=p.default,en=we,tn=$e;var nn={createFile:Zt((function(e,t){function n(){en.writeFile(e,"",(e=>{if(e)return t(e);t()}))}en.stat(e,((r,u)=>{if(!r&&u.isFile())return t();const o=Qt.dirname(e);en.stat(o,((e,r)=>{if(e)return"ENOENT"===e.code?tn.mkdirs(o,(e=>{if(e)return t(e);n()})):t(e);r.isDirectory()?n():en.readdir(o,(e=>{if(e)return t(e)}))}))}))})),createFileSync:function(e){let t;try{t=en.statSync(e)}catch{}if(t&&t.isFile())return;const n=Qt.dirname(e);try{en.statSync(n).isDirectory()||en.readdirSync(n)}catch(e){if(!e||"ENOENT"!==e.code)throw e;tn.mkdirsSync(n)}en.writeFileSync(e,"")}};const rn=re.fromCallback,un=p.default,on=we,sn=$e,cn=Ge.pathExists,{areIdentical:an}=et;var ln={createLink:rn((function(e,t,n){function r(e,t){on.link(e,t,(e=>{if(e)return n(e);n(null)}))}on.lstat(t,((u,o)=>{on.lstat(e,((u,i)=>{if(u)return u.message=u.message.replace("lstat","ensureLink"),n(u);if(o&&an(i,o))return n(null);const s=un.dirname(t);cn(s,((u,o)=>u?n(u):o?r(e,t):void sn.mkdirs(s,(u=>{if(u)return n(u);r(e,t)}))))}))}))})),createLinkSync:function(e,t){let n;try{n=on.lstatSync(t)}catch{}try{const t=on.lstatSync(e);if(n&&an(t,n))return}catch(e){throw e.message=e.message.replace("lstat","ensureLink"),e}const r=un.dirname(t);return on.existsSync(r)||sn.mkdirsSync(r),on.linkSync(e,t)}};const fn=p.default,dn=we,Dn=Ge.pathExists;var pn={symlinkPaths:function(e,t,n){if(fn.isAbsolute(e))return dn.lstat(e,(t=>t?(t.message=t.message.replace("lstat","ensureSymlink"),n(t)):n(null,{toCwd:e,toDst:e})));{const r=fn.dirname(t),u=fn.join(r,e);return Dn(u,((t,o)=>t?n(t):o?n(null,{toCwd:u,toDst:e}):dn.lstat(e,(t=>t?(t.message=t.message.replace("lstat","ensureSymlink"),n(t)):n(null,{toCwd:e,toDst:fn.relative(r,e)})))))}},symlinkPathsSync:function(e,t){let n;if(fn.isAbsolute(e)){if(n=dn.existsSync(e),!n)throw new Error("absolute srcpath does not exist");return{toCwd:e,toDst:e}}{const r=fn.dirname(t),u=fn.join(r,e);if(n=dn.existsSync(u),n)return{toCwd:u,toDst:e};if(n=dn.existsSync(e),!n)throw new Error("relative srcpath does not exist");return{toCwd:e,toDst:fn.relative(r,e)}}}};const En=we;var mn={symlinkType:function(e,t,n){if(n="function"==typeof t?t:n,t="function"!=typeof t&&t)return n(null,t);En.lstat(e,((e,r)=>{if(e)return n(null,"file");t=r&&r.isDirectory()?"dir":"file",n(null,t)}))},symlinkTypeSync:function(e,t){let n;if(t)return t;try{n=En.lstatSync(e)}catch{return"file"}return n&&n.isDirectory()?"dir":"file"}};const hn=re.fromCallback,yn=p.default,Cn=ne,Fn=$e.mkdirs,gn=$e.mkdirsSync,An=pn.symlinkPaths,vn=pn.symlinkPathsSync,Sn=mn.symlinkType,wn=mn.symlinkTypeSync,On=Ge.pathExists,{areIdentical:bn}=et;function _n(e,t,n,r){An(e,t,((u,o)=>{if(u)return r(u);e=o.toDst,Sn(o.toCwd,n,((n,u)=>{if(n)return r(n);const o=yn.dirname(t);On(o,((n,i)=>n?r(n):i?Cn.symlink(e,t,u,r):void Fn(o,(n=>{if(n)return r(n);Cn.symlink(e,t,u,r)}))))}))}))}var Bn={createSymlink:hn((function(e,t,n,r){r="function"==typeof n?n:r,n="function"!=typeof n&&n,Cn.lstat(t,((u,o)=>{!u&&o.isSymbolicLink()?Promise.all([Cn.stat(e),Cn.stat(t)]).then((([u,o])=>{if(bn(u,o))return r(null);_n(e,t,n,r)})):_n(e,t,n,r)}))})),createSymlinkSync:function(e,t,n){let r;try{r=Cn.lstatSync(t)}catch{}if(r&&r.isSymbolicLink()){const n=Cn.statSync(e),r=Cn.statSync(t);if(bn(n,r))return}const u=vn(e,t);e=u.toDst,n=wn(u.toCwd,n);const o=yn.dirname(t);return Cn.existsSync(o)||gn(o),Cn.symlinkSync(e,t,n)}};const{createFile:Pn,createFileSync:kn}=nn,{createLink:xn,createLinkSync:Nn}=ln,{createSymlink:In,createSymlinkSync:Tn}=Bn;var Rn={createFile:Pn,createFileSync:kn,ensureFile:Pn,ensureFileSync:kn,createLink:xn,createLinkSync:Nn,ensureLink:xn,ensureLinkSync:Nn,createSymlink:In,createSymlinkSync:Tn,ensureSymlink:In,ensureSymlinkSync:Tn};var Mn={stringify:function(e,{EOL:t="\n",finalEOL:n=!0,replacer:r=null,spaces:u}={}){const o=n?t:"";return JSON.stringify(e,r,u).replace(/\n/g,t)+o},stripBom:function(e){return Buffer.isBuffer(e)&&(e=e.toString("utf8")),e.replace(/^\uFEFF/,"")}};let Ln;try{Ln=we}catch(e){Ln=D.default}const jn=re,{stringify:$n,stripBom:Hn}=Mn;const Jn=jn.fromPromise((async function(e,t={}){"string"==typeof t&&(t={encoding:t});const n=t.fs||Ln,r=!("throws"in t)||t.throws;let u,o=await jn.fromCallback(n.readFile)(e,t);o=Hn(o);try{u=JSON.parse(o,t?t.reviver:null)}catch(t){if(r)throw t.message=`${e}: ${t.message}`,t;return null}return u}));const Gn=jn.fromPromise((async function(e,t,n={}){const r=n.fs||Ln,u=$n(t,n);await jn.fromCallback(r.writeFile)(e,u,n)}));const Vn={readFile:Jn,readFileSync:function(e,t={}){"string"==typeof t&&(t={encoding:t});const n=t.fs||Ln,r=!("throws"in t)||t.throws;try{let r=n.readFileSync(e,t);return r=Hn(r),JSON.parse(r,t.reviver)}catch(t){if(r)throw t.message=`${e}: ${t.message}`,t;return null}},writeFile:Gn,writeFileSync:function(e,t,n={}){const r=n.fs||Ln,u=$n(t,n);return r.writeFileSync(e,u,n)}};var Un={readJson:Vn.readFile,readJsonSync:Vn.readFileSync,writeJson:Vn.writeFile,writeJsonSync:Vn.writeFileSync};const Wn=re.fromCallback,zn=we,Kn=p.default,qn=$e,Yn=Ge.pathExists;var Xn={outputFile:Wn((function(e,t,n,r){"function"==typeof n&&(r=n,n="utf8");const u=Kn.dirname(e);Yn(u,((o,i)=>o?r(o):i?zn.writeFile(e,t,n,r):void qn.mkdirs(u,(u=>{if(u)return r(u);zn.writeFile(e,t,n,r)}))))})),outputFileSync:function(e,...t){const n=Kn.dirname(e);if(zn.existsSync(n))return zn.writeFileSync(e,...t);qn.mkdirsSync(n),zn.writeFileSync(e,...t)}};const{stringify:Zn}=Mn,{outputFile:Qn}=Xn;var er=async function(e,t,n={}){const r=Zn(t,n);await Qn(e,r,n)};const{stringify:tr}=Mn,{outputFileSync:nr}=Xn;var rr=function(e,t,n){const r=tr(t,n);nr(e,r,n)};const ur=re.fromPromise,or=Un;or.outputJson=ur(er),or.outputJsonSync=rr,or.outputJSON=or.outputJson,or.outputJSONSync=or.outputJsonSync,or.writeJSON=or.writeJson,or.writeJSONSync=or.writeJsonSync,or.readJSON=or.readJson,or.readJSONSync=or.readJsonSync;var ir=or;const sr=we,cr=p.default,ar=Ot.copy,lr=Gt.remove,fr=$e.mkdirp,dr=Ge.pathExists,Dr=et;function pr(e,t,n,r,u){return r?Er(e,t,n,u):n?lr(t,(r=>r?u(r):Er(e,t,n,u))):void dr(t,((r,o)=>r?u(r):o?u(new Error("dest already exists.")):Er(e,t,n,u)))}function Er(e,t,n,r){sr.rename(e,t,(u=>u?"EXDEV"!==u.code?r(u):function(e,t,n,r){const u={overwrite:n,errorOnExist:!0};ar(e,t,u,(t=>t?r(t):lr(e,r)))}(e,t,n,r):r()))}var mr=function(e,t,n,r){"function"==typeof n&&(r=n,n={});const u=n.overwrite||n.clobber||!1;Dr.checkPaths(e,t,"move",n,((n,o)=>{if(n)return r(n);const{srcStat:i,isChangingCase:s=!1}=o;Dr.checkParentPaths(e,i,t,"move",(n=>n?r(n):function(e){const t=cr.dirname(e);return cr.parse(t).root===t}(t)?pr(e,t,u,s,r):void fr(cr.dirname(t),(n=>n?r(n):pr(e,t,u,s,r)))))}))};const hr=we,yr=p.default,Cr=Ot.copySync,Fr=Gt.removeSync,gr=$e.mkdirpSync,Ar=et;function vr(e,t,n){try{hr.renameSync(e,t)}catch(r){if("EXDEV"!==r.code)throw r;return function(e,t,n){const r={overwrite:n,errorOnExist:!0};return Cr(e,t,r),Fr(e)}(e,t,n)}}var Sr=function(e,t,n){const r=(n=n||{}).overwrite||n.clobber||!1,{srcStat:u,isChangingCase:o=!1}=Ar.checkPathsSync(e,t,"move",n);return Ar.checkParentPathsSync(e,u,t,"move"),function(e){const t=yr.dirname(e);return yr.parse(t).root===t}(t)||gr(yr.dirname(t)),function(e,t,n,r){if(r)return vr(e,t,n);if(n)return Fr(t),vr(e,t,n);if(hr.existsSync(t))throw new Error("dest already exists.");return vr(e,t,n)}(e,t,r,o)};var wr,Or,br,_r,Br,Pr={move:(0,re.fromCallback)(mr),moveSync:Sr},kr={...ne,...Ot,...Xt,...Rn,...ir,...$e,...Pr,...Xn,...Ge,...Gt},xr={},Nr={exports:{}},Ir={exports:{}};function Tr(){if(Or)return wr;Or=1;var e=1e3,t=60*e,n=60*t,r=24*n,u=7*r,o=365.25*r;function i(e,t,n,r){var u=t>=1.5*n;return Math.round(e/n)+" "+r+(u?"s":"")}return wr=function(s,c){c=c||{};var a=typeof s;if("string"===a&&s.length>0)return function(i){if((i=String(i)).length>100)return;var s=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(i);if(!s)return;var c=parseFloat(s[1]);switch((s[2]||"ms").toLowerCase()){case"years":case"year":case"yrs":case"yr":case"y":return c*o;case"weeks":case"week":case"w":return c*u;case"days":case"day":case"d":return c*r;case"hours":case"hour":case"hrs":case"hr":case"h":return c*n;case"minutes":case"minute":case"mins":case"min":case"m":return c*t;case"seconds":case"second":case"secs":case"sec":case"s":return c*e;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return c;default:return}}(s);if("number"===a&&isFinite(s))return c.long?function(u){var o=Math.abs(u);if(o>=r)return i(u,o,r,"day");if(o>=n)return i(u,o,n,"hour");if(o>=t)return i(u,o,t,"minute");if(o>=e)return i(u,o,e,"second");return u+" ms"}(s):function(u){var o=Math.abs(u);if(o>=r)return Math.round(u/r)+"d";if(o>=n)return Math.round(u/n)+"h";if(o>=t)return Math.round(u/t)+"m";if(o>=e)return Math.round(u/e)+"s";return u+"ms"}(s);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(s))}}function Rr(){if(_r)return br;return _r=1,br=function(e){function t(e){let r,u,o,i=null;function s(...e){if(!s.enabled)return;const n=s,u=Number(new Date),o=u-(r||u);n.diff=o,n.prev=r,n.curr=u,r=u,e[0]=t.coerce(e[0]),"string"!=typeof e[0]&&e.unshift("%O");let i=0;e[0]=e[0].replace(/%([a-zA-Z%])/g,((r,u)=>{if("%%"===r)return"%";i++;const o=t.formatters[u];if("function"==typeof o){const t=e[i];r=o.call(n,t),e.splice(i,1),i--}return r})),t.formatArgs.call(n,e);(n.log||t.log).apply(n,e)}return s.namespace=e,s.useColors=t.useColors(),s.color=t.selectColor(e),s.extend=n,s.destroy=t.destroy,Object.defineProperty(s,"enabled",{enumerable:!0,configurable:!1,get:()=>null!==i?i:(u!==t.namespaces&&(u=t.namespaces,o=t.enabled(e)),o),set:e=>{i=e}}),"function"==typeof t.init&&t.init(s),s}function n(e,n){const r=t(this.namespace+(void 0===n?":":n)+e);return r.log=this.log,r}function r(e){return e.toString().substring(2,e.toString().length-2).replace(/\.\*\?$/,"*")}return t.debug=t,t.default=t,t.coerce=function(e){if(e instanceof Error)return e.stack||e.message;return e},t.disable=function(){const e=[...t.names.map(r),...t.skips.map(r).map((e=>"-"+e))].join(",");return t.enable(""),e},t.enable=function(e){let n;t.save(e),t.namespaces=e,t.names=[],t.skips=[];const r=("string"==typeof e?e:"").split(/[\s,]+/),u=r.length;for(n=0;n{t[n]=e[n]})),t.names=[],t.skips=[],t.formatters={},t.selectColor=function(e){let n=0;for(let t=0;t{const n=e.startsWith("-")?"":1===e.length?"-":"--",r=t.indexOf(n+e),u=t.indexOf("--");return-1!==r&&(-1===u||r{}),"Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."),t.colors=[6,2,3,4,5,1];try{const e=function(){if($r)return jr;$r=1;const e=E.default,t=A.default,n=Vr(),{env:r}=process;let u;function o(e){return 0!==e&&{level:e,hasBasic:!0,has256:e>=2,has16m:e>=3}}function i(t,o){if(0===u)return 0;if(n("color=16m")||n("color=full")||n("color=truecolor"))return 3;if(n("color=256"))return 2;if(t&&!o&&void 0===u)return 0;const i=u||0;if("dumb"===r.TERM)return i;if("win32"===process.platform){const t=e.release().split(".");return Number(t[0])>=10&&Number(t[2])>=10586?Number(t[2])>=14931?3:2:1}if("CI"in r)return["TRAVIS","CIRCLECI","APPVEYOR","GITLAB_CI","GITHUB_ACTIONS","BUILDKITE"].some((e=>e in r))||"codeship"===r.CI_NAME?1:i;if("TEAMCITY_VERSION"in r)return/^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(r.TEAMCITY_VERSION)?1:0;if("truecolor"===r.COLORTERM)return 3;if("TERM_PROGRAM"in r){const e=parseInt((r.TERM_PROGRAM_VERSION||"").split(".")[0],10);switch(r.TERM_PROGRAM){case"iTerm.app":return e>=3?3:2;case"Apple_Terminal":return 2}}return/-256(color)?$/i.test(r.TERM)?2:/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(r.TERM)||"COLORTERM"in r?1:i}return n("no-color")||n("no-colors")||n("color=false")||n("color=never")?u=0:(n("color")||n("colors")||n("color=true")||n("color=always"))&&(u=1),"FORCE_COLOR"in r&&(u="true"===r.FORCE_COLOR?1:"false"===r.FORCE_COLOR?0:0===r.FORCE_COLOR.length?1:Math.min(parseInt(r.FORCE_COLOR,10),3)),jr={supportsColor:function(e){return o(i(e,e&&e.isTTY))},stdout:o(i(!0,t.isatty(1))),stderr:o(i(!0,t.isatty(2)))}}();e&&(e.stderr||e).level>=2&&(t.colors=[20,21,26,27,32,33,38,39,40,41,42,43,44,45,56,57,62,63,68,69,74,75,76,77,78,79,80,81,92,93,98,99,112,113,128,129,134,135,148,149,160,161,162,163,164,165,166,167,168,169,170,171,172,173,178,179,184,185,196,197,198,199,200,201,202,203,204,205,206,207,208,209,214,215,220,221])}catch(e){}t.inspectOpts=Object.keys(process.env).filter((e=>/^debug_/i.test(e))).reduce(((e,t)=>{const n=t.substring(6).toLowerCase().replace(/_([a-z])/g,((e,t)=>t.toUpperCase()));let r=process.env[t];return r=!!/^(yes|on|true|enabled)$/i.test(r)||!/^(no|off|false|disabled)$/i.test(r)&&("null"===r?null:Number(r)),e[n]=r,e}),{}),e.exports=Rr()(t);const{formatters:u}=e.exports;u.o=function(e){return this.inspectOpts.colors=this.useColors,r.inspect(e,this.inspectOpts).split("\n").map((e=>e.trim())).join(" ")},u.O=function(e){return this.inspectOpts.colors=this.useColors,r.inspect(e,this.inspectOpts)}}(Gr,Gr.exports)),Gr.exports}Jr=Nr,"undefined"==typeof process||"renderer"===process.type||!0===process.browser||process.__nwjs?Jr.exports=(Br||(Br=1,function(e,t){t.formatArgs=function(t){if(t[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+t[0]+(this.useColors?"%c ":" ")+"+"+e.exports.humanize(this.diff),!this.useColors)return;const n="color: "+this.color;t.splice(1,0,n,"color: inherit");let r=0,u=0;t[0].replace(/%[a-zA-Z%]/g,(e=>{"%%"!==e&&(r++,"%c"===e&&(u=r))})),t.splice(u,0,n)},t.save=function(e){try{e?t.storage.setItem("debug",e):t.storage.removeItem("debug")}catch(e){}},t.load=function(){let e;try{e=t.storage.getItem("debug")}catch(e){}return!e&&"undefined"!=typeof process&&"env"in process&&(e=process.env.DEBUG),e},t.useColors=function(){return!("undefined"==typeof window||!window.process||"renderer"!==window.process.type&&!window.process.__nwjs)||("undefined"==typeof navigator||!navigator.userAgent||!navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/))&&("undefined"!=typeof document&&document.documentElement&&document.documentElement.style&&document.documentElement.style.WebkitAppearance||"undefined"!=typeof window&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)&&parseInt(RegExp.$1,10)>=31||"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/))},t.storage=function(){try{return localStorage}catch(e){}}(),t.destroy=(()=>{let e=!1;return()=>{e||(e=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),t.colors=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"],t.log=console.debug||console.log||(()=>{}),e.exports=Rr()(t);const{formatters:n}=e.exports;n.j=function(e){try{return JSON.stringify(e)}catch(e){return"[UnexpectedJSONParseError]: "+e.message}}}(Ir,Ir.exports)),Ir.exports):Jr.exports=Ur();var Wr=function(e){return(e=e||{}).circles?function(e){var t=[],n=[];return e.proto?function e(u){if("object"!=typeof u||null===u)return u;if(u instanceof Date)return new Date(u);if(Array.isArray(u))return r(u,e);if(u instanceof Map)return new Map(r(Array.from(u),e));if(u instanceof Set)return new Set(r(Array.from(u),e));var o={};for(var i in t.push(u),n.push(o),u){var s=u[i];if("object"!=typeof s||null===s)o[i]=s;else if(s instanceof Date)o[i]=new Date(s);else if(s instanceof Map)o[i]=new Map(r(Array.from(s),e));else if(s instanceof Set)o[i]=new Set(r(Array.from(s),e));else if(ArrayBuffer.isView(s))o[i]=zr(s);else{var c=t.indexOf(s);o[i]=-1!==c?n[c]:e(s)}}return t.pop(),n.pop(),o}:function e(u){if("object"!=typeof u||null===u)return u;if(u instanceof Date)return new Date(u);if(Array.isArray(u))return r(u,e);if(u instanceof Map)return new Map(r(Array.from(u),e));if(u instanceof Set)return new Set(r(Array.from(u),e));var o={};for(var i in t.push(u),n.push(o),u)if(!1!==Object.hasOwnProperty.call(u,i)){var s=u[i];if("object"!=typeof s||null===s)o[i]=s;else if(s instanceof Date)o[i]=new Date(s);else if(s instanceof Map)o[i]=new Map(r(Array.from(s),e));else if(s instanceof Set)o[i]=new Set(r(Array.from(s),e));else if(ArrayBuffer.isView(s))o[i]=zr(s);else{var c=t.indexOf(s);o[i]=-1!==c?n[c]:e(s)}}return t.pop(),n.pop(),o};function r(e,r){for(var u=Object.keys(e),o=new Array(u.length),i=0;i!e,Qr=e=>e&&"object"==typeof e&&!Array.isArray(e),eu=(e,t,n)=>{(Array.isArray(t)?t:[t]).forEach((t=>{if(t)throw new Error(`Problem with log4js configuration: (${Kr.inspect(e,{depth:5})}) - ${n}`)}))};var tu={configure:e=>{qr("New configuration to be validated: ",e),eu(e,Zr(Qr(e)),"must be an object."),qr(`Calling pre-processing listeners (${Yr.length})`),Yr.forEach((t=>t(e))),qr("Configuration pre-processing finished."),qr(`Calling configuration listeners (${Xr.length})`),Xr.forEach((t=>t(e))),qr("Configuration finished.")},addListener:e=>{Xr.push(e),qr(`Added listener, now ${Xr.length} listeners`)},addPreProcessingListener:e=>{Yr.push(e),qr(`Added pre-processing listener, now ${Yr.length} listeners`)},throwExceptionIf:eu,anObject:Qr,anInteger:e=>e&&"number"==typeof e&&Number.isInteger(e),validIdentifier:e=>/^[A-Za-z][A-Za-z0-9_]*$/g.test(e),not:Zr},nu={exports:{}};!function(e){function t(e,t){for(var n=e.toString();n.length-1?s:c,l=n(u.getHours()),f=n(u.getMinutes()),d=n(u.getSeconds()),D=t(u.getMilliseconds(),3),p=function(e){var t=Math.abs(e),n=String(Math.floor(t/60)),r=String(t%60);return n=("0"+n).slice(-2),r=("0"+r).slice(-2),0===e?"Z":(e<0?"+":"-")+n+":"+r}(u.getTimezoneOffset());return r.replace(/dd/g,o).replace(/MM/g,i).replace(/y{1,4}/g,a).replace(/hh/g,l).replace(/mm/g,f).replace(/ss/g,d).replace(/SSS/g,D).replace(/O/g,p)}function u(e,t,n,r){e["set"+(r?"":"UTC")+t](n)}e.exports=r,e.exports.asString=r,e.exports.parse=function(t,n,r){if(!t)throw new Error("pattern must be supplied");return function(t,n,r){var o=t.indexOf("O")<0,i=!1,s=[{pattern:/y{1,4}/,regexp:"\\d{1,4}",fn:function(e,t){u(e,"FullYear",t,o)}},{pattern:/MM/,regexp:"\\d{1,2}",fn:function(e,t){u(e,"Month",t-1,o),e.getMonth()!==t-1&&(i=!0)}},{pattern:/dd/,regexp:"\\d{1,2}",fn:function(e,t){i&&u(e,"Month",e.getMonth()-1,o),u(e,"Date",t,o)}},{pattern:/hh/,regexp:"\\d{1,2}",fn:function(e,t){u(e,"Hours",t,o)}},{pattern:/mm/,regexp:"\\d\\d",fn:function(e,t){u(e,"Minutes",t,o)}},{pattern:/ss/,regexp:"\\d\\d",fn:function(e,t){u(e,"Seconds",t,o)}},{pattern:/SSS/,regexp:"\\d\\d\\d",fn:function(e,t){u(e,"Milliseconds",t,o)}},{pattern:/O/,regexp:"[+-]\\d{1,2}:?\\d{2}?|Z",fn:function(e,t){t="Z"===t?0:t.replace(":","");var n=Math.abs(t),r=(t>0?-1:1)*(n%100+60*Math.floor(n/100));e.setUTCMinutes(e.getUTCMinutes()+r)}}],c=s.reduce((function(e,t){return t.pattern.test(e.regexp)?(t.index=e.regexp.match(t.pattern).index,e.regexp=e.regexp.replace(t.pattern,"("+t.regexp+")")):t.index=-1,e}),{regexp:t,index:[]}),a=s.filter((function(e){return e.index>-1}));a.sort((function(e,t){return e.index-t.index}));var l=new RegExp(c.regexp).exec(n);if(l){var f=r||e.exports.now();return a.forEach((function(e,t){e.fn(f,l[t+1])})),f}throw new Error("String '"+n+"' could not be parsed as '"+t+"'")}(t,n,r)},e.exports.now=function(){return new Date},e.exports.ISO8601_FORMAT="yyyy-MM-ddThh:mm:ss.SSS",e.exports.ISO8601_WITH_TZ_OFFSET_FORMAT="yyyy-MM-ddThh:mm:ss.SSSO",e.exports.DATETIME_FORMAT="dd MM yyyy hh:mm:ss.SSS",e.exports.ABSOLUTETIME_FORMAT="hh:mm:ss.SSS"}(nu);const ru=nu.exports,uu=E.default,ou=F.default,iu=p.default,su={bold:[1,22],italic:[3,23],underline:[4,24],inverse:[7,27],white:[37,39],grey:[90,39],black:[90,39],blue:[34,39],cyan:[36,39],green:[32,39],magenta:[35,39],red:[91,39],yellow:[33,39]};function cu(e){return e?`[${su[e][0]}m`:""}function au(e){return e?`[${su[e][1]}m`:""}function lu(e,t){return n=ou.format("[%s] [%s] %s - ",ru.asString(e.startTime),e.level.toString(),e.categoryName),cu(r=t)+n+au(r);var n,r}function fu(e){return lu(e)+ou.format(...e.data)}function du(e){return lu(e,e.level.colour)+ou.format(...e.data)}function Du(e){return ou.format(...e.data)}function pu(e){return e.data[0]}function Eu(e,t){const n=/%(-?[0-9]+)?(\.?-?[0-9]+)?([[\]cdhmnprzxXyflos%])(\{([^}]+)\})?|([^%]+)/;function r(e){return e&&e.pid?e.pid.toString():process.pid.toString()}e=e||"%r %p %c - %m%n";const u={c:function(e,t){let n=e.categoryName;if(t){const e=parseInt(t,10),r=n.split(".");ee&&(n=r.slice(-e).join(iu.sep))}return n},l:function(e){return e.lineNumber?`${e.lineNumber}`:""},o:function(e){return e.columnNumber?`${e.columnNumber}`:""},s:function(e){return e.callStack||""}};function o(e,t,n){return u[e](t,n)}function i(e,t,n){let r=e;return r=function(e,t){let n;return e?(n=parseInt(e.substr(1),10),n>0?t.slice(0,n):t.slice(n)):t}(t,r),r=function(e,t){let n;if(e)if("-"===e.charAt(0))for(n=parseInt(e.substr(1),10);t.lengthDu,basic:()=>fu,colored:()=>du,coloured:()=>du,pattern:e=>Eu(e&&e.pattern,e&&e.tokens),dummy:()=>pu};var hu={basicLayout:fu,messagePassThroughLayout:Du,patternLayout:Eu,colouredLayout:du,coloredLayout:du,dummyLayout:pu,addLayout(e,t){mu[e]=t},layout:(e,t)=>mu[e]&&mu[e](t)};const yu=tu,Cu=["white","grey","black","blue","cyan","green","magenta","red","yellow"];class Fu{constructor(e,t,n){this.level=e,this.levelStr=t,this.colour=n}toString(){return this.levelStr}static getLevel(e,t){return e?e instanceof Fu?e:(e instanceof Object&&e.levelStr&&(e=e.levelStr),Fu[e.toString().toUpperCase()]||t):t}static addLevels(e){if(e){Object.keys(e).forEach((t=>{const n=t.toUpperCase();Fu[n]=new Fu(e[t].value,n,e[t].colour);const r=Fu.levels.findIndex((e=>e.levelStr===n));r>-1?Fu.levels[r]=Fu[n]:Fu.levels.push(Fu[n])})),Fu.levels.sort(((e,t)=>e.level-t.level))}}isLessThanOrEqualTo(e){return"string"==typeof e&&(e=Fu.getLevel(e)),this.level<=e.level}isGreaterThanOrEqualTo(e){return"string"==typeof e&&(e=Fu.getLevel(e)),this.level>=e.level}isEqualTo(e){return"string"==typeof e&&(e=Fu.getLevel(e)),this.level===e.level}}Fu.levels=[],Fu.addLevels({ALL:{value:Number.MIN_VALUE,colour:"grey"},TRACE:{value:5e3,colour:"blue"},DEBUG:{value:1e4,colour:"cyan"},INFO:{value:2e4,colour:"green"},WARN:{value:3e4,colour:"yellow"},ERROR:{value:4e4,colour:"red"},FATAL:{value:5e4,colour:"magenta"},MARK:{value:9007199254740992,colour:"grey"},OFF:{value:Number.MAX_VALUE,colour:"grey"}}),yu.addListener((e=>{const t=e.levels;if(t){yu.throwExceptionIf(e,yu.not(yu.anObject(t)),"levels must be an object");Object.keys(t).forEach((n=>{yu.throwExceptionIf(e,yu.not(yu.validIdentifier(n)),`level name "${n}" is not a valid identifier (must start with a letter, only contain A-Z,a-z,0-9,_)`),yu.throwExceptionIf(e,yu.not(yu.anObject(t[n])),`level "${n}" must be an object`),yu.throwExceptionIf(e,yu.not(t[n].value),`level "${n}" must have a 'value' property`),yu.throwExceptionIf(e,yu.not(yu.anInteger(t[n].value)),`level "${n}".value must have an integer value`),yu.throwExceptionIf(e,yu.not(t[n].colour),`level "${n}" must have a 'colour' property`),yu.throwExceptionIf(e,yu.not(Cu.indexOf(t[n].colour)>-1),`level "${n}".colour must be one of ${Cu.join(", ")}`)}))}})),yu.addListener((e=>{Fu.addLevels(e.levels)}));var gu=Fu,Au={exports:{}},vu={};/*! (c) 2020 Andrea Giammarchi */ -const{parse:Su,stringify:wu}=JSON,{keys:Ou}=Object,bu=String,_u="string",Bu={},Pu="object",ku=(e,t)=>t,xu=e=>e instanceof bu?bu(e):e,Nu=(e,t)=>typeof t===_u?new bu(t):t,Iu=(e,t,n,r)=>{const u=[];for(let o=Ou(n),{length:i}=o,s=0;s{const r=bu(t.push(n)-1);return e.set(n,r),r},Ru=(e,t)=>{const n=Su(e,Nu).map(xu),r=n[0],u=t||ku,o=typeof r===Pu&&r?Iu(n,new Set,r,u):r;return u.call({"":o},"",o)};vu.parse=Ru;const Mu=(e,t,n)=>{const r=t&&typeof t===Pu?(e,n)=>""===e||-1Su(Mu(e));vu.fromJSON=e=>Ru(wu(e));const Lu=vu,ju=gu;class $u{constructor(e,t,n,r,u){this.startTime=new Date,this.categoryName=e,this.data=n,this.level=t,this.context=Object.assign({},r),this.pid=process.pid,u&&(this.functionName=u.functionName,this.fileName=u.fileName,this.lineNumber=u.lineNumber,this.columnNumber=u.columnNumber,this.callStack=u.callStack)}serialise(){const e=this.data.map((e=>(e&&e.message&&e.stack&&(e=Object.assign({message:e.message,stack:e.stack},e)),e)));return this.data=e,Lu.stringify(this)}static deserialise(e){let t;try{const n=Lu.parse(e);n.data=n.data.map((e=>{if(e&&e.message&&e.stack){const t=new Error(e);Object.keys(e).forEach((n=>{t[n]=e[n]})),e=t}return e})),t=new $u(n.categoryName,ju.getLevel(n.level.levelStr),n.data,n.context),t.startTime=new Date(n.startTime),t.pid=n.pid,t.cluster=n.cluster}catch(n){t=new $u("log4js",ju.ERROR,["Unable to parse log:",e,"because: ",n])}return t}}var Hu=$u;const Ju=Nr.exports("log4js:clustering"),Gu=Hu,Vu=tu;let Uu=!1,Wu=null;try{Wu=require("cluster")}catch(e){Ju("cluster module not present"),Uu=!0}const zu=[];let Ku=!1,qu="NODE_APP_INSTANCE";const Yu=()=>Ku&&"0"===process.env[qu],Xu=()=>Uu||Wu.isMaster||Yu(),Zu=e=>{zu.forEach((t=>t(e)))},Qu=(e,t)=>{if(Ju("cluster message received from worker ",e,": ",t),e.topic&&e.data&&(t=e,e=void 0),t&&t.topic&&"log4js:message"===t.topic){Ju("received message: ",t.data);const e=Gu.deserialise(t.data);Zu(e)}};Uu||Vu.addListener((e=>{zu.length=0,({pm2:Ku,disableClustering:Uu,pm2InstanceVar:qu="NODE_APP_INSTANCE"}=e),Ju(`clustering disabled ? ${Uu}`),Ju(`cluster.isMaster ? ${Wu&&Wu.isMaster}`),Ju(`pm2 enabled ? ${Ku}`),Ju(`pm2InstanceVar = ${qu}`),Ju(`process.env[${qu}] = ${process.env[qu]}`),Ku&&process.removeListener("message",Qu),Wu&&Wu.removeListener&&Wu.removeListener("message",Qu),Uu||e.disableClustering?Ju("Not listening for cluster messages, because clustering disabled."):Yu()?(Ju("listening for PM2 broadcast messages"),process.on("message",Qu)):Wu.isMaster?(Ju("listening for cluster messages"),Wu.on("message",Qu)):Ju("not listening for messages, because we are not a master process")}));var eo={onlyOnMaster:(e,t)=>Xu()?e():t,isMaster:Xu,send:e=>{Xu()?Zu(e):(Ku||(e.cluster={workerId:Wu.worker.id,worker:process.pid}),process.send({topic:"log4js:message",data:e.serialise()}))},onMessage:e=>{zu.push(e)}},to={};function no(e){if("number"==typeof e&&Number.isInteger(e))return e;const t={K:1024,M:1048576,G:1073741824},n=Object.keys(t),r=e.substr(e.length-1).toLocaleUpperCase(),u=e.substring(0,e.length-1).trim();if(n.indexOf(r)<0||!Number.isInteger(Number(u)))throw Error(`maxLogSize: "${e}" is invalid`);return u*t[r]}function ro(e){return function(e,t){const n=Object.assign({},t);return Object.keys(e).forEach((r=>{n[r]&&(n[r]=e[r](t[r]))})),n}({maxLogSize:no},e)}const uo={file:ro,fileSync:ro};to.modifyConfig=e=>uo[e.type]?uo[e.type](e):e;var oo={};const io=console.log.bind(console);oo.configure=function(e,t){let n=t.colouredLayout;return e.layout&&(n=t.layout(e.layout.type,e.layout)),function(e,t){return n=>{io(e(n,t))}}(n,e.timezoneOffset)};var so={};so.configure=function(e,t){let n=t.colouredLayout;return e.layout&&(n=t.layout(e.layout.type,e.layout)),function(e,t){return n=>{process.stdout.write(`${e(n,t)}\n`)}}(n,e.timezoneOffset)};var co={};co.configure=function(e,t){let n=t.colouredLayout;return e.layout&&(n=t.layout(e.layout.type,e.layout)),function(e,t){return n=>{process.stderr.write(`${e(n,t)}\n`)}}(n,e.timezoneOffset)};var ao={};ao.configure=function(e,t,n,r){const u=n(e.appender);return function(e,t,n,r){const u=r.getLevel(e),o=r.getLevel(t,r.FATAL);return e=>{const t=e.level;t.isGreaterThanOrEqualTo(u)&&t.isLessThanOrEqualTo(o)&&n(e)}}(e.level,e.maxLevel,u,r)};var lo={};const fo=Nr.exports("log4js:categoryFilter");lo.configure=function(e,t,n){const r=n(e.appender);return function(e,t){return"string"==typeof e&&(e=[e]),n=>{fo(`Checking ${n.categoryName} against ${e}`),-1===e.indexOf(n.categoryName)&&(fo("Not excluded, sending to appender"),t(n))}}(e.exclude,r)};var Do={};const po=Nr.exports("log4js:noLogFilter");Do.configure=function(e,t,n){const r=n(e.appender);return function(e,t){return n=>{po(`Checking data: ${n.data} against filters: ${e}`),"string"==typeof e&&(e=[e]),e=e.filter((e=>null!=e&&""!==e));const r=new RegExp(e.join("|"),"i");(0===e.length||n.data.findIndex((e=>r.test(e)))<0)&&(po("Not excluded, sending to appender"),t(n))}}(e.exclude,r)};var Eo={},mo={exports:{}},ho={},yo={fromCallback:function(e){return Object.defineProperty((function(){if("function"!=typeof arguments[arguments.length-1])return new Promise(((t,n)=>{arguments[arguments.length]=(e,r)=>{if(e)return n(e);t(r)},arguments.length++,e.apply(this,arguments)}));e.apply(this,arguments)}),"name",{value:e.name})},fromPromise:function(e){return Object.defineProperty((function(){const t=arguments[arguments.length-1];if("function"!=typeof t)return e.apply(this,arguments);e.apply(this,arguments).then((e=>t(null,e)),t)}),"name",{value:e.name})}};!function(e){const t=yo.fromCallback,n=we,r=["access","appendFile","chmod","chown","close","copyFile","fchmod","fchown","fdatasync","fstat","fsync","ftruncate","futimes","lchown","lchmod","link","lstat","mkdir","mkdtemp","open","readFile","readdir","readlink","realpath","rename","rmdir","stat","symlink","truncate","unlink","utimes","writeFile"].filter((e=>"function"==typeof n[e]));Object.keys(n).forEach((t=>{"promises"!==t&&(e[t]=n[t])})),r.forEach((r=>{e[r]=t(n[r])})),e.exists=function(e,t){return"function"==typeof t?n.exists(e,t):new Promise((t=>n.exists(e,t)))},e.read=function(e,t,r,u,o,i){return"function"==typeof i?n.read(e,t,r,u,o,i):new Promise(((i,s)=>{n.read(e,t,r,u,o,((e,t,n)=>{if(e)return s(e);i({bytesRead:t,buffer:n})}))}))},e.write=function(e,t,...r){return"function"==typeof r[r.length-1]?n.write(e,t,...r):new Promise(((u,o)=>{n.write(e,t,...r,((e,t,n)=>{if(e)return o(e);u({bytesWritten:t,buffer:n})}))}))},"function"==typeof n.realpath.native&&(e.realpath.native=t(n.realpath.native))}(ho);const Co=p.default;function Fo(e){return(e=Co.normalize(Co.resolve(e)).split(Co.sep)).length>0?e[0]:null}const go=/[<>:"|?*]/;var Ao=function(e){const t=Fo(e);return e=e.replace(t,""),go.test(e)};const vo=we,So=p.default,wo=Ao,Oo=parseInt("0777",8);var bo=function e(t,n,r,u){if("function"==typeof n?(r=n,n={}):n&&"object"==typeof n||(n={mode:n}),"win32"===process.platform&&wo(t)){const e=new Error(t+" contains invalid WIN32 path characters.");return e.code="EINVAL",r(e)}let o=n.mode;const i=n.fs||vo;void 0===o&&(o=Oo&~process.umask()),u||(u=null),r=r||function(){},t=So.resolve(t),i.mkdir(t,o,(o=>{if(!o)return r(null,u=u||t);if("ENOENT"===o.code){if(So.dirname(t)===t)return r(o);e(So.dirname(t),n,((u,o)=>{u?r(u,o):e(t,n,r,o)}))}else i.stat(t,((e,t)=>{e||!t.isDirectory()?r(o,u):r(null,u)}))}))};const _o=we,Bo=p.default,Po=Ao,ko=parseInt("0777",8);var xo=function e(t,n,r){n&&"object"==typeof n||(n={mode:n});let u=n.mode;const o=n.fs||_o;if("win32"===process.platform&&Po(t)){const e=new Error(t+" contains invalid WIN32 path characters.");throw e.code="EINVAL",e}void 0===u&&(u=ko&~process.umask()),r||(r=null),t=Bo.resolve(t);try{o.mkdirSync(t,u),r=r||t}catch(u){if("ENOENT"===u.code){if(Bo.dirname(t)===t)throw u;r=e(Bo.dirname(t),n,r),e(t,n,r)}else{let e;try{e=o.statSync(t)}catch(e){throw u}if(!e.isDirectory())throw u}}return r};const No=(0,yo.fromCallback)(bo);var Io={mkdirs:No,mkdirsSync:xo,mkdirp:No,mkdirpSync:xo,ensureDir:No,ensureDirSync:xo};const To=we;E.default,p.default;var Ro=function(e,t,n,r){To.open(e,"r+",((e,u)=>{if(e)return r(e);To.futimes(u,t,n,(e=>{To.close(u,(t=>{r&&r(e||t)}))}))}))},Mo=function(e,t,n){const r=To.openSync(e,"r+");return To.futimesSync(r,t,n),To.closeSync(r)};const Lo=we,jo=p.default,$o=10,Ho=5,Jo=0,Go=process.versions.node.split("."),Vo=Number.parseInt(Go[0],10),Uo=Number.parseInt(Go[1],10),Wo=Number.parseInt(Go[2],10);function zo(){if(Vo>$o)return!0;if(Vo===$o){if(Uo>Ho)return!0;if(Uo===Ho&&Wo>=Jo)return!0}return!1}function Ko(e,t){const n=jo.resolve(e).split(jo.sep).filter((e=>e)),r=jo.resolve(t).split(jo.sep).filter((e=>e));return n.reduce(((e,t,n)=>e&&r[n]===t),!0)}function qo(e,t,n){return`Cannot ${n} '${e}' to a subdirectory of itself, '${t}'.`}var Yo,Xo,Zo={checkPaths:function(e,t,n,r){!function(e,t,n){zo()?Lo.stat(e,{bigint:!0},((e,r)=>{if(e)return n(e);Lo.stat(t,{bigint:!0},((e,t)=>e?"ENOENT"===e.code?n(null,{srcStat:r,destStat:null}):n(e):n(null,{srcStat:r,destStat:t})))})):Lo.stat(e,((e,r)=>{if(e)return n(e);Lo.stat(t,((e,t)=>e?"ENOENT"===e.code?n(null,{srcStat:r,destStat:null}):n(e):n(null,{srcStat:r,destStat:t})))}))}(e,t,((u,o)=>{if(u)return r(u);const{srcStat:i,destStat:s}=o;return s&&s.ino&&s.dev&&s.ino===i.ino&&s.dev===i.dev?r(new Error("Source and destination must not be the same.")):i.isDirectory()&&Ko(e,t)?r(new Error(qo(e,t,n))):r(null,{srcStat:i,destStat:s})}))},checkPathsSync:function(e,t,n){const{srcStat:r,destStat:u}=function(e,t){let n,r;n=zo()?Lo.statSync(e,{bigint:!0}):Lo.statSync(e);try{r=zo()?Lo.statSync(t,{bigint:!0}):Lo.statSync(t)}catch(e){if("ENOENT"===e.code)return{srcStat:n,destStat:null};throw e}return{srcStat:n,destStat:r}}(e,t);if(u&&u.ino&&u.dev&&u.ino===r.ino&&u.dev===r.dev)throw new Error("Source and destination must not be the same.");if(r.isDirectory()&&Ko(e,t))throw new Error(qo(e,t,n));return{srcStat:r,destStat:u}},checkParentPaths:function e(t,n,r,u,o){const i=jo.resolve(jo.dirname(t)),s=jo.resolve(jo.dirname(r));if(s===i||s===jo.parse(s).root)return o();zo()?Lo.stat(s,{bigint:!0},((i,c)=>i?"ENOENT"===i.code?o():o(i):c.ino&&c.dev&&c.ino===n.ino&&c.dev===n.dev?o(new Error(qo(t,r,u))):e(t,n,s,u,o))):Lo.stat(s,((i,c)=>i?"ENOENT"===i.code?o():o(i):c.ino&&c.dev&&c.ino===n.ino&&c.dev===n.dev?o(new Error(qo(t,r,u))):e(t,n,s,u,o)))},checkParentPathsSync:function e(t,n,r,u){const o=jo.resolve(jo.dirname(t)),i=jo.resolve(jo.dirname(r));if(i===o||i===jo.parse(i).root)return;let s;try{s=zo()?Lo.statSync(i,{bigint:!0}):Lo.statSync(i)}catch(e){if("ENOENT"===e.code)return;throw e}if(s.ino&&s.dev&&s.ino===n.ino&&s.dev===n.dev)throw new Error(qo(t,r,u));return e(t,n,i,u)},isSrcSubdir:Ko};const Qo=we,ei=p.default,ti=Io.mkdirsSync,ni=Mo,ri=Zo;function ui(e,t,n,r){if(!r.filter||r.filter(t,n))return function(e,t,n,r){const u=r.dereference?Qo.statSync:Qo.lstatSync,o=u(t);if(o.isDirectory())return function(e,t,n,r,u){if(!t)return function(e,t,n,r){return Qo.mkdirSync(n),ii(t,n,r),Qo.chmodSync(n,e.mode)}(e,n,r,u);if(t&&!t.isDirectory())throw new Error(`Cannot overwrite non-directory '${r}' with directory '${n}'.`);return ii(n,r,u)}(o,e,t,n,r);if(o.isFile()||o.isCharacterDevice()||o.isBlockDevice())return function(e,t,n,r,u){return t?function(e,t,n,r){if(r.overwrite)return Qo.unlinkSync(n),oi(e,t,n,r);if(r.errorOnExist)throw new Error(`'${n}' already exists`)}(e,n,r,u):oi(e,n,r,u)}(o,e,t,n,r);if(o.isSymbolicLink())return function(e,t,n,r){let u=Qo.readlinkSync(t);r.dereference&&(u=ei.resolve(process.cwd(),u));if(e){let e;try{e=Qo.readlinkSync(n)}catch(e){if("EINVAL"===e.code||"UNKNOWN"===e.code)return Qo.symlinkSync(u,n);throw e}if(r.dereference&&(e=ei.resolve(process.cwd(),e)),ri.isSrcSubdir(u,e))throw new Error(`Cannot copy '${u}' to a subdirectory of itself, '${e}'.`);if(Qo.statSync(n).isDirectory()&&ri.isSrcSubdir(e,u))throw new Error(`Cannot overwrite '${e}' with '${u}'.`);return function(e,t){return Qo.unlinkSync(t),Qo.symlinkSync(e,t)}(u,n)}return Qo.symlinkSync(u,n)}(e,t,n,r)}(e,t,n,r)}function oi(e,t,n,r){return"function"==typeof Qo.copyFileSync?(Qo.copyFileSync(t,n),Qo.chmodSync(n,e.mode),r.preserveTimestamps?ni(n,e.atime,e.mtime):void 0):function(e,t,n,r){const u=65536,o=(Xo?Yo:(Xo=1,Yo=function(e){if("function"==typeof Buffer.allocUnsafe)try{return Buffer.allocUnsafe(e)}catch(t){return new Buffer(e)}return new Buffer(e)}))(u),i=Qo.openSync(t,"r"),s=Qo.openSync(n,"w",e.mode);let c=0;for(;cfunction(e,t,n,r){const u=ei.join(t,e),o=ei.join(n,e),{destStat:i}=ri.checkPathsSync(u,o,"copy");return ui(i,u,o,r)}(r,e,t,n)))}var si=function(e,t,n){"function"==typeof n&&(n={filter:n}),(n=n||{}).clobber=!("clobber"in n)||!!n.clobber,n.overwrite="overwrite"in n?!!n.overwrite:n.clobber,n.preserveTimestamps&&"ia32"===process.arch&&console.warn("fs-extra: Using the preserveTimestamps option in 32-bit node is not recommended;\n\n see https://github.com/jprichardson/node-fs-extra/issues/269");const{srcStat:r,destStat:u}=ri.checkPathsSync(e,t,"copy");return ri.checkParentPathsSync(e,r,t,"copy"),function(e,t,n,r){if(r.filter&&!r.filter(t,n))return;const u=ei.dirname(n);Qo.existsSync(u)||ti(u);return ui(e,t,n,r)}(u,e,t,n)},ci={copySync:si};const ai=yo.fromPromise,li=ho;var fi={pathExists:ai((function(e){return li.access(e).then((()=>!0)).catch((()=>!1))})),pathExistsSync:li.existsSync};const di=we,Di=p.default,pi=Io.mkdirs,Ei=fi.pathExists,mi=Ro,hi=Zo;function yi(e,t,n,r,u){const o=Di.dirname(n);Ei(o,((i,s)=>i?u(i):s?Fi(e,t,n,r,u):void pi(o,(o=>o?u(o):Fi(e,t,n,r,u)))))}function Ci(e,t,n,r,u,o){Promise.resolve(u.filter(n,r)).then((i=>i?e(t,n,r,u,o):o()),(e=>o(e)))}function Fi(e,t,n,r,u){return r.filter?Ci(gi,e,t,n,r,u):gi(e,t,n,r,u)}function gi(e,t,n,r,u){(r.dereference?di.stat:di.lstat)(t,((o,i)=>o?u(o):i.isDirectory()?function(e,t,n,r,u,o){if(!t)return function(e,t,n,r,u){di.mkdir(n,(o=>{if(o)return u(o);Si(t,n,r,(t=>t?u(t):di.chmod(n,e.mode,u)))}))}(e,n,r,u,o);if(t&&!t.isDirectory())return o(new Error(`Cannot overwrite non-directory '${r}' with directory '${n}'.`));return Si(n,r,u,o)}(i,e,t,n,r,u):i.isFile()||i.isCharacterDevice()||i.isBlockDevice()?function(e,t,n,r,u,o){return t?function(e,t,n,r,u){if(!r.overwrite)return r.errorOnExist?u(new Error(`'${n}' already exists`)):u();di.unlink(n,(o=>o?u(o):Ai(e,t,n,r,u)))}(e,n,r,u,o):Ai(e,n,r,u,o)}(i,e,t,n,r,u):i.isSymbolicLink()?function(e,t,n,r,u){di.readlink(t,((t,o)=>t?u(t):(r.dereference&&(o=Di.resolve(process.cwd(),o)),e?void di.readlink(n,((t,i)=>t?"EINVAL"===t.code||"UNKNOWN"===t.code?di.symlink(o,n,u):u(t):(r.dereference&&(i=Di.resolve(process.cwd(),i)),hi.isSrcSubdir(o,i)?u(new Error(`Cannot copy '${o}' to a subdirectory of itself, '${i}'.`)):e.isDirectory()&&hi.isSrcSubdir(i,o)?u(new Error(`Cannot overwrite '${i}' with '${o}'.`)):function(e,t,n){di.unlink(t,(r=>r?n(r):di.symlink(e,t,n)))}(o,n,u)))):di.symlink(o,n,u))))}(e,t,n,r,u):void 0))}function Ai(e,t,n,r,u){return"function"==typeof di.copyFile?di.copyFile(t,n,(t=>t?u(t):vi(e,n,r,u))):function(e,t,n,r,u){const o=di.createReadStream(t);o.on("error",(e=>u(e))).once("open",(()=>{const t=di.createWriteStream(n,{mode:e.mode});t.on("error",(e=>u(e))).on("open",(()=>o.pipe(t))).once("close",(()=>vi(e,n,r,u)))}))}(e,t,n,r,u)}function vi(e,t,n,r){di.chmod(t,e.mode,(u=>u?r(u):n.preserveTimestamps?mi(t,e.atime,e.mtime,r):r()))}function Si(e,t,n,r){di.readdir(e,((u,o)=>u?r(u):wi(o,e,t,n,r)))}function wi(e,t,n,r,u){const o=e.pop();return o?function(e,t,n,r,u,o){const i=Di.join(n,t),s=Di.join(r,t);hi.checkPaths(i,s,"copy",((t,c)=>{if(t)return o(t);const{destStat:a}=c;Fi(a,i,s,u,(t=>t?o(t):wi(e,n,r,u,o)))}))}(e,o,t,n,r,u):u()}var Oi=function(e,t,n,r){"function"!=typeof n||r?"function"==typeof n&&(n={filter:n}):(r=n,n={}),r=r||function(){},(n=n||{}).clobber=!("clobber"in n)||!!n.clobber,n.overwrite="overwrite"in n?!!n.overwrite:n.clobber,n.preserveTimestamps&&"ia32"===process.arch&&console.warn("fs-extra: Using the preserveTimestamps option in 32-bit node is not recommended;\n\n see https://github.com/jprichardson/node-fs-extra/issues/269"),hi.checkPaths(e,t,"copy",((u,o)=>{if(u)return r(u);const{srcStat:i,destStat:s}=o;hi.checkParentPaths(e,i,t,"copy",(u=>u?r(u):n.filter?Ci(yi,s,e,t,n,r):yi(s,e,t,n,r)))}))};var bi={copy:(0,yo.fromCallback)(Oi)};const _i=we,Bi=p.default,Pi=g.default,ki="win32"===process.platform;function xi(e){["unlink","chmod","stat","lstat","rmdir","readdir"].forEach((t=>{e[t]=e[t]||_i[t],e[t+="Sync"]=e[t]||_i[t]})),e.maxBusyTries=e.maxBusyTries||3}function Ni(e,t,n){let r=0;"function"==typeof t&&(n=t,t={}),Pi(e,"rimraf: missing path"),Pi.strictEqual(typeof e,"string","rimraf: path should be a string"),Pi.strictEqual(typeof n,"function","rimraf: callback function required"),Pi(t,"rimraf: invalid options argument provided"),Pi.strictEqual(typeof t,"object","rimraf: options should be object"),xi(t),Ii(e,t,(function u(o){if(o){if(("EBUSY"===o.code||"ENOTEMPTY"===o.code||"EPERM"===o.code)&&rIi(e,t,u)),100*r)}"ENOENT"===o.code&&(o=null)}n(o)}))}function Ii(e,t,n){Pi(e),Pi(t),Pi("function"==typeof n),t.lstat(e,((r,u)=>r&&"ENOENT"===r.code?n(null):r&&"EPERM"===r.code&&ki?Ti(e,t,r,n):u&&u.isDirectory()?Mi(e,t,r,n):void t.unlink(e,(r=>{if(r){if("ENOENT"===r.code)return n(null);if("EPERM"===r.code)return ki?Ti(e,t,r,n):Mi(e,t,r,n);if("EISDIR"===r.code)return Mi(e,t,r,n)}return n(r)}))))}function Ti(e,t,n,r){Pi(e),Pi(t),Pi("function"==typeof r),n&&Pi(n instanceof Error),t.chmod(e,438,(u=>{u?r("ENOENT"===u.code?null:n):t.stat(e,((u,o)=>{u?r("ENOENT"===u.code?null:n):o.isDirectory()?Mi(e,t,n,r):t.unlink(e,r)}))}))}function Ri(e,t,n){let r;Pi(e),Pi(t),n&&Pi(n instanceof Error);try{t.chmodSync(e,438)}catch(e){if("ENOENT"===e.code)return;throw n}try{r=t.statSync(e)}catch(e){if("ENOENT"===e.code)return;throw n}r.isDirectory()?ji(e,t,n):t.unlinkSync(e)}function Mi(e,t,n,r){Pi(e),Pi(t),n&&Pi(n instanceof Error),Pi("function"==typeof r),t.rmdir(e,(u=>{!u||"ENOTEMPTY"!==u.code&&"EEXIST"!==u.code&&"EPERM"!==u.code?u&&"ENOTDIR"===u.code?r(n):r(u):function(e,t,n){Pi(e),Pi(t),Pi("function"==typeof n),t.readdir(e,((r,u)=>{if(r)return n(r);let o,i=u.length;if(0===i)return t.rmdir(e,n);u.forEach((r=>{Ni(Bi.join(e,r),t,(r=>{if(!o)return r?n(o=r):void(0==--i&&t.rmdir(e,n))}))}))}))}(e,t,r)}))}function Li(e,t){let n;xi(t=t||{}),Pi(e,"rimraf: missing path"),Pi.strictEqual(typeof e,"string","rimraf: path should be a string"),Pi(t,"rimraf: missing options"),Pi.strictEqual(typeof t,"object","rimraf: options should be object");try{n=t.lstatSync(e)}catch(n){if("ENOENT"===n.code)return;"EPERM"===n.code&&ki&&Ri(e,t,n)}try{n&&n.isDirectory()?ji(e,t,null):t.unlinkSync(e)}catch(n){if("ENOENT"===n.code)return;if("EPERM"===n.code)return ki?Ri(e,t,n):ji(e,t,n);if("EISDIR"!==n.code)throw n;ji(e,t,n)}}function ji(e,t,n){Pi(e),Pi(t),n&&Pi(n instanceof Error);try{t.rmdirSync(e)}catch(r){if("ENOTDIR"===r.code)throw n;if("ENOTEMPTY"===r.code||"EEXIST"===r.code||"EPERM"===r.code)!function(e,t){if(Pi(e),Pi(t),t.readdirSync(e).forEach((n=>Li(Bi.join(e,n),t))),!ki){return t.rmdirSync(e,t)}{const n=Date.now();do{try{return t.rmdirSync(e,t)}catch(e){}}while(Date.now()-n<500)}}(e,t);else if("ENOENT"!==r.code)throw r}}var $i=Ni;Ni.sync=Li;const Hi=$i;var Ji={remove:(0,yo.fromCallback)(Hi),removeSync:Hi.sync};const Gi=yo.fromCallback,Vi=we,Ui=p.default,Wi=Io,zi=Ji,Ki=Gi((function(e,t){t=t||function(){},Vi.readdir(e,((n,r)=>{if(n)return Wi.mkdirs(e,t);r=r.map((t=>Ui.join(e,t))),function e(){const n=r.pop();if(!n)return t();zi.remove(n,(n=>{if(n)return t(n);e()}))}()}))}));function qi(e){let t;try{t=Vi.readdirSync(e)}catch(t){return Wi.mkdirsSync(e)}t.forEach((t=>{t=Ui.join(e,t),zi.removeSync(t)}))}var Yi={emptyDirSync:qi,emptydirSync:qi,emptyDir:Ki,emptydir:Ki};const Xi=yo.fromCallback,Zi=p.default,Qi=we,es=Io,ts=fi.pathExists;var ns={createFile:Xi((function(e,t){function n(){Qi.writeFile(e,"",(e=>{if(e)return t(e);t()}))}Qi.stat(e,((r,u)=>{if(!r&&u.isFile())return t();const o=Zi.dirname(e);ts(o,((e,r)=>e?t(e):r?n():void es.mkdirs(o,(e=>{if(e)return t(e);n()}))))}))})),createFileSync:function(e){let t;try{t=Qi.statSync(e)}catch(e){}if(t&&t.isFile())return;const n=Zi.dirname(e);Qi.existsSync(n)||es.mkdirsSync(n),Qi.writeFileSync(e,"")}};const rs=yo.fromCallback,us=p.default,os=we,is=Io,ss=fi.pathExists;var cs={createLink:rs((function(e,t,n){function r(e,t){os.link(e,t,(e=>{if(e)return n(e);n(null)}))}ss(t,((u,o)=>u?n(u):o?n(null):void os.lstat(e,(u=>{if(u)return u.message=u.message.replace("lstat","ensureLink"),n(u);const o=us.dirname(t);ss(o,((u,i)=>u?n(u):i?r(e,t):void is.mkdirs(o,(u=>{if(u)return n(u);r(e,t)}))))}))))})),createLinkSync:function(e,t){if(os.existsSync(t))return;try{os.lstatSync(e)}catch(e){throw e.message=e.message.replace("lstat","ensureLink"),e}const n=us.dirname(t);return os.existsSync(n)||is.mkdirsSync(n),os.linkSync(e,t)}};const as=p.default,ls=we,fs=fi.pathExists;var ds={symlinkPaths:function(e,t,n){if(as.isAbsolute(e))return ls.lstat(e,(t=>t?(t.message=t.message.replace("lstat","ensureSymlink"),n(t)):n(null,{toCwd:e,toDst:e})));{const r=as.dirname(t),u=as.join(r,e);return fs(u,((t,o)=>t?n(t):o?n(null,{toCwd:u,toDst:e}):ls.lstat(e,(t=>t?(t.message=t.message.replace("lstat","ensureSymlink"),n(t)):n(null,{toCwd:e,toDst:as.relative(r,e)})))))}},symlinkPathsSync:function(e,t){let n;if(as.isAbsolute(e)){if(n=ls.existsSync(e),!n)throw new Error("absolute srcpath does not exist");return{toCwd:e,toDst:e}}{const r=as.dirname(t),u=as.join(r,e);if(n=ls.existsSync(u),n)return{toCwd:u,toDst:e};if(n=ls.existsSync(e),!n)throw new Error("relative srcpath does not exist");return{toCwd:e,toDst:as.relative(r,e)}}}};const Ds=we;var ps={symlinkType:function(e,t,n){if(n="function"==typeof t?t:n,t="function"!=typeof t&&t)return n(null,t);Ds.lstat(e,((e,r)=>{if(e)return n(null,"file");t=r&&r.isDirectory()?"dir":"file",n(null,t)}))},symlinkTypeSync:function(e,t){let n;if(t)return t;try{n=Ds.lstatSync(e)}catch(e){return"file"}return n&&n.isDirectory()?"dir":"file"}};const Es=yo.fromCallback,ms=p.default,hs=we,ys=Io.mkdirs,Cs=Io.mkdirsSync,Fs=ds.symlinkPaths,gs=ds.symlinkPathsSync,As=ps.symlinkType,vs=ps.symlinkTypeSync,Ss=fi.pathExists;var ws={createSymlink:Es((function(e,t,n,r){r="function"==typeof n?n:r,n="function"!=typeof n&&n,Ss(t,((u,o)=>u?r(u):o?r(null):void Fs(e,t,((u,o)=>{if(u)return r(u);e=o.toDst,As(o.toCwd,n,((n,u)=>{if(n)return r(n);const o=ms.dirname(t);Ss(o,((n,i)=>n?r(n):i?hs.symlink(e,t,u,r):void ys(o,(n=>{if(n)return r(n);hs.symlink(e,t,u,r)}))))}))}))))})),createSymlinkSync:function(e,t,n){if(hs.existsSync(t))return;const r=gs(e,t);e=r.toDst,n=vs(r.toCwd,n);const u=ms.dirname(t);return hs.existsSync(u)||Cs(u),hs.symlinkSync(e,t,n)}};var Os,bs={createFile:ns.createFile,createFileSync:ns.createFileSync,ensureFile:ns.createFile,ensureFileSync:ns.createFileSync,createLink:cs.createLink,createLinkSync:cs.createLinkSync,ensureLink:cs.createLink,ensureLinkSync:cs.createLinkSync,createSymlink:ws.createSymlink,createSymlinkSync:ws.createSymlinkSync,ensureSymlink:ws.createSymlink,ensureSymlinkSync:ws.createSymlinkSync};try{Os=we}catch(e){Os=D.default}function _s(e,t){var n,r="\n";return"object"==typeof t&&null!==t&&(t.spaces&&(n=t.spaces),t.EOL&&(r=t.EOL)),JSON.stringify(e,t?t.replacer:null,n).replace(/\n/g,r)+r}function Bs(e){return Buffer.isBuffer(e)&&(e=e.toString("utf8")),e=e.replace(/^\uFEFF/,"")}var Ps={readFile:function(e,t,n){null==n&&(n=t,t={}),"string"==typeof t&&(t={encoding:t});var r=(t=t||{}).fs||Os,u=!0;"throws"in t&&(u=t.throws),r.readFile(e,t,(function(r,o){if(r)return n(r);var i;o=Bs(o);try{i=JSON.parse(o,t?t.reviver:null)}catch(t){return u?(t.message=e+": "+t.message,n(t)):n(null,null)}n(null,i)}))},readFileSync:function(e,t){"string"==typeof(t=t||{})&&(t={encoding:t});var n=t.fs||Os,r=!0;"throws"in t&&(r=t.throws);try{var u=n.readFileSync(e,t);return u=Bs(u),JSON.parse(u,t.reviver)}catch(t){if(r)throw t.message=e+": "+t.message,t;return null}},writeFile:function(e,t,n,r){null==r&&(r=n,n={});var u=(n=n||{}).fs||Os,o="";try{o=_s(t,n)}catch(e){return void(r&&r(e,null))}u.writeFile(e,o,n,r)},writeFileSync:function(e,t,n){var r=(n=n||{}).fs||Os,u=_s(t,n);return r.writeFileSync(e,u,n)}},ks=Ps;const xs=yo.fromCallback,Ns=ks;var Is={readJson:xs(Ns.readFile),readJsonSync:Ns.readFileSync,writeJson:xs(Ns.writeFile),writeJsonSync:Ns.writeFileSync};const Ts=p.default,Rs=Io,Ms=fi.pathExists,Ls=Is;var js=function(e,t,n,r){"function"==typeof n&&(r=n,n={});const u=Ts.dirname(e);Ms(u,((o,i)=>o?r(o):i?Ls.writeJson(e,t,n,r):void Rs.mkdirs(u,(u=>{if(u)return r(u);Ls.writeJson(e,t,n,r)}))))};const $s=we,Hs=p.default,Js=Io,Gs=Is;var Vs=function(e,t,n){const r=Hs.dirname(e);$s.existsSync(r)||Js.mkdirsSync(r),Gs.writeJsonSync(e,t,n)};const Us=yo.fromCallback,Ws=Is;Ws.outputJson=Us(js),Ws.outputJsonSync=Vs,Ws.outputJSON=Ws.outputJson,Ws.outputJSONSync=Ws.outputJsonSync,Ws.writeJSON=Ws.writeJson,Ws.writeJSONSync=Ws.writeJsonSync,Ws.readJSON=Ws.readJson,Ws.readJSONSync=Ws.readJsonSync;var zs=Ws;const Ks=we,qs=p.default,Ys=ci.copySync,Xs=Ji.removeSync,Zs=Io.mkdirpSync,Qs=Zo;function ec(e,t,n){try{Ks.renameSync(e,t)}catch(r){if("EXDEV"!==r.code)throw r;return function(e,t,n){const r={overwrite:n,errorOnExist:!0};return Ys(e,t,r),Xs(e)}(e,t,n)}}var tc=function(e,t,n){const r=(n=n||{}).overwrite||n.clobber||!1,{srcStat:u}=Qs.checkPathsSync(e,t,"move");return Qs.checkParentPathsSync(e,u,t,"move"),Zs(qs.dirname(t)),function(e,t,n){if(n)return Xs(t),ec(e,t,n);if(Ks.existsSync(t))throw new Error("dest already exists.");return ec(e,t,n)}(e,t,r)},nc={moveSync:tc};const rc=we,uc=p.default,oc=bi.copy,ic=Ji.remove,sc=Io.mkdirp,cc=fi.pathExists,ac=Zo;function lc(e,t,n,r){rc.rename(e,t,(u=>u?"EXDEV"!==u.code?r(u):function(e,t,n,r){const u={overwrite:n,errorOnExist:!0};oc(e,t,u,(t=>t?r(t):ic(e,r)))}(e,t,n,r):r()))}var fc=function(e,t,n,r){"function"==typeof n&&(r=n,n={});const u=n.overwrite||n.clobber||!1;ac.checkPaths(e,t,"move",((n,o)=>{if(n)return r(n);const{srcStat:i}=o;ac.checkParentPaths(e,i,t,"move",(n=>{if(n)return r(n);sc(uc.dirname(t),(n=>n?r(n):function(e,t,n,r){if(n)return ic(t,(u=>u?r(u):lc(e,t,n,r)));cc(t,((u,o)=>u?r(u):o?r(new Error("dest already exists.")):lc(e,t,n,r)))}(e,t,u,r)))}))}))};var dc={move:(0,yo.fromCallback)(fc)};const Dc=yo.fromCallback,pc=we,Ec=p.default,mc=Io,hc=fi.pathExists;var yc={outputFile:Dc((function(e,t,n,r){"function"==typeof n&&(r=n,n="utf8");const u=Ec.dirname(e);hc(u,((o,i)=>o?r(o):i?pc.writeFile(e,t,n,r):void mc.mkdirs(u,(u=>{if(u)return r(u);pc.writeFile(e,t,n,r)}))))})),outputFileSync:function(e,...t){const n=Ec.dirname(e);if(pc.existsSync(n))return pc.writeFileSync(e,...t);mc.mkdirsSync(n),pc.writeFileSync(e,...t)}};!function(e){e.exports=Object.assign({},ho,ci,bi,Yi,bs,zs,Io,nc,dc,yc,fi,Ji);const t=D.default;Object.getOwnPropertyDescriptor(t,"promises")&&Object.defineProperty(e.exports,"promises",{get:()=>t.promises})}(mo);const Cc=Nr.exports("streamroller:fileNameFormatter"),Fc=p.default;const gc=Nr.exports("streamroller:fileNameParser"),Ac=nu.exports;const vc=Nr.exports("streamroller:moveAndMaybeCompressFile"),Sc=mo.exports,wc=v.default;var Oc=async(e,t,n)=>{if(n=function(e){const t={mode:parseInt("0600",8),compress:!1},n=Object.assign({},t,e);return vc(`_parseOption: moveAndMaybeCompressFile called with option=${JSON.stringify(n)}`),n}(n),e!==t){if(await Sc.pathExists(e))if(vc(`moveAndMaybeCompressFile: moving file from ${e} to ${t} ${n.compress?"with":"without"} compress`),n.compress)await new Promise(((r,u)=>{let o=!1;const i=Sc.createWriteStream(t,{mode:n.mode,flags:"wx"}).on("open",(()=>{o=!0;const t=Sc.createReadStream(e).on("open",(()=>{t.pipe(wc.createGzip()).pipe(i)})).on("error",(t=>{vc(`moveAndMaybeCompressFile: error reading ${e}`,t),i.destroy(t)}))})).on("finish",(()=>{vc(`moveAndMaybeCompressFile: finished compressing ${t}, deleting ${e}`),Sc.unlink(e).then(r).catch((t=>{vc(`moveAndMaybeCompressFile: error deleting ${e}, truncating instead`,t),Sc.truncate(e).then(r).catch((t=>{vc(`moveAndMaybeCompressFile: error truncating ${e}`,t),u(t)}))}))})).on("error",(e=>{o?(vc(`moveAndMaybeCompressFile: error writing ${t}, deleting`,e),Sc.unlink(t).then((()=>{u(e)})).catch((e=>{vc(`moveAndMaybeCompressFile: error deleting ${t}`,e),u(e)}))):(vc(`moveAndMaybeCompressFile: error creating ${t}`,e),u(e))}))})).catch((()=>{}));else{vc(`moveAndMaybeCompressFile: renaming ${e} to ${t}`);try{await Sc.move(e,t,{overwrite:!0})}catch(n){if(vc(`moveAndMaybeCompressFile: error renaming ${e} to ${t}`,n),"ENOENT"!==n.code){vc("moveAndMaybeCompressFile: trying copy+truncate instead");try{await Sc.copy(e,t,{overwrite:!0}),await Sc.truncate(e)}catch(e){vc("moveAndMaybeCompressFile: error copy+truncate",e)}}}}}else vc("moveAndMaybeCompressFile: source and target are the same, not doing anything")};const bc=Nr.exports("streamroller:RollingFileWriteStream"),_c=mo.exports,Bc=p.default,Pc=E.default,kc=()=>new Date,xc=nu.exports,{Writable:Nc}=C.default,Ic=({file:e,keepFileExt:t,needsIndex:n,alwaysIncludeDate:r,compress:u,fileNameSep:o})=>{let i=o||".";const s=Fc.join(e.dir,e.name),c=t=>t+e.ext,a=(e,t,r)=>!n&&r||!t?e:e+i+t,l=(e,t,n)=>(t>0||r)&&n?e+i+n:e,f=(e,t)=>t&&u?e+".gz":e,d=t?[l,a,c,f]:[c,l,a,f];return({date:e,index:t})=>(Cc(`_formatFileName: date=${e}, index=${t}`),d.reduce(((n,r)=>r(n,t,e)),s))},Tc=({file:e,keepFileExt:t,pattern:n,fileNameSep:r})=>{let u=r||".";const o="__NOT_MATCHING__";let i=[(e,t)=>e.endsWith(".gz")?(gc("it is gzipped"),t.isCompressed=!0,e.slice(0,-1*".gz".length)):e,t?t=>t.startsWith(e.name)&&t.endsWith(e.ext)?(gc("it starts and ends with the right things"),t.slice(e.name.length+1,-1*e.ext.length)):o:t=>t.startsWith(e.base)?(gc("it starts with the right things"),t.slice(e.base.length+1)):o,n?(e,t)=>{const r=e.split(u);let o=r[r.length-1];gc("items: ",r,", indexStr: ",o);let i=e;void 0!==o&&o.match(/^\d+$/)?(i=e.slice(0,-1*(o.length+1)),gc(`dateStr is ${i}`),n&&!i&&(i=o,o="0")):o="0";try{const r=Ac.parse(n,i,new Date(0,0));return Ac.asString(n,r)!==i?e:(t.index=parseInt(o,10),t.date=i,t.timestamp=r.getTime(),"")}catch(t){return gc(`Problem parsing ${i} as ${n}, error was: `,t),e}}:(e,t)=>e.match(/^\d+$/)?(gc("it has an index"),t.index=parseInt(e,10),""):e];return e=>{let t={filename:e,index:0,isCompressed:!1};return i.reduce(((e,n)=>n(e,t)),e)?null:t}},Rc=Oc;var Mc=class extends Nc{constructor(e,t){if(bc(`constructor: creating RollingFileWriteStream. path=${e}`),"string"!=typeof e||0===e.length)throw new Error(`Invalid filename: ${e}`);if(e.endsWith(Bc.sep))throw new Error(`Filename is a directory: ${e}`);0===e.indexOf(`~${Bc.sep}`)&&(e=e.replace("~",Pc.homedir())),super(t),this.options=this._parseOption(t),this.fileObject=Bc.parse(e),""===this.fileObject.dir&&(this.fileObject=Bc.parse(Bc.join(process.cwd(),e))),this.fileFormatter=Ic({file:this.fileObject,alwaysIncludeDate:this.options.alwaysIncludePattern,needsIndex:this.options.maxSize 0`)}else delete n.maxSize;if(n.numBackups||0===n.numBackups){if(n.numBackups<0)throw new Error(`options.numBackups (${n.numBackups}) should be >= 0`);if(n.numBackups>=Number.MAX_SAFE_INTEGER)throw new Error(`options.numBackups (${n.numBackups}) should be < Number.MAX_SAFE_INTEGER`);n.numToKeep=n.numBackups+1}else if(n.numToKeep<=0)throw new Error(`options.numToKeep (${n.numToKeep}) should be > 0`);return bc(`_parseOption: creating stream with option=${JSON.stringify(n)}`),n}_final(e){this.currentFileStream.end("",this.options.encoding,e)}_write(e,t,n){this._shouldRoll().then((()=>{bc(`_write: writing chunk. file=${this.currentFileStream.path} state=${JSON.stringify(this.state)} chunk=${e}`),this.currentFileStream.write(e,t,(t=>{this.state.currentSize+=e.length,n(t)}))}))}async _shouldRoll(){(this._dateChanged()||this._tooBig())&&(bc(`_shouldRoll: rolling because dateChanged? ${this._dateChanged()} or tooBig? ${this._tooBig()}`),await this._roll())}_dateChanged(){return this.state.currentDate&&this.state.currentDate!==xc(this.options.pattern,kc())}_tooBig(){return this.state.currentSize>=this.options.maxSize}_roll(){return bc("_roll: closing the current stream"),new Promise(((e,t)=>{this.currentFileStream.end("",this.options.encoding,(()=>{this._moveOldFiles().then(e).catch(t)}))}))}async _moveOldFiles(){const e=await this._getExistingFiles();for(let t=(this.state.currentDate?e.filter((e=>e.date===this.state.currentDate)):e).length;t>=0;t--){bc(`_moveOldFiles: i = ${t}`);const e=this.fileFormatter({date:this.state.currentDate,index:t}),n=this.fileFormatter({date:this.state.currentDate,index:t+1}),r={compress:this.options.compress&&0===t,mode:this.options.mode};await Rc(e,n,r)}this.state.currentSize=0,this.state.currentDate=this.state.currentDate?xc(this.options.pattern,kc()):null,bc(`_moveOldFiles: finished rolling files. state=${JSON.stringify(this.state)}`),this._renewWriteStream(),await new Promise(((e,t)=>{this.currentFileStream.write("","utf8",(()=>{this._clean().then(e).catch(t)}))}))}async _getExistingFiles(){const e=await _c.readdir(this.fileObject.dir).catch((()=>[]));bc(`_getExistingFiles: files=${e}`);const t=e.map((e=>this.fileNameParser(e))).filter((e=>e)),n=e=>(e.timestamp?e.timestamp:kc().getTime())-e.index;return t.sort(((e,t)=>n(e)-n(t))),t}_renewWriteStream(){const e=this.fileFormatter({date:this.state.currentDate,index:0}),t=e=>{try{return _c.mkdirSync(e,{recursive:!0})}catch(n){if("ENOENT"===n.code)return t(Bc.dirname(e)),t(e);if("EEXIST"!==n.code&&"EROFS"!==n.code)throw n;try{if(_c.statSync(e).isDirectory())return e;throw n}catch(e){throw n}}};t(this.fileObject.dir);const n={flags:this.options.flags,encoding:this.options.encoding,mode:this.options.mode};var r,u;_c.appendFileSync(e,"",(r={...n},u="flags",r["flag"]=r[u],delete r[u],r)),this.currentFileStream=_c.createWriteStream(e,n),this.currentFileStream.on("error",(e=>{this.emit("error",e)}))}async _clean(){const e=await this._getExistingFiles();if(bc(`_clean: numToKeep = ${this.options.numToKeep}, existingFiles = ${e.length}`),bc("_clean: existing files are: ",e),this._tooManyFiles(e.length)){const n=e.slice(0,e.length-this.options.numToKeep).map((e=>Bc.format({dir:this.fileObject.dir,base:e.filename})));await(t=n,bc(`deleteFiles: files to delete: ${t}`),Promise.all(t.map((e=>_c.unlink(e).catch((t=>{bc(`deleteFiles: error when unlinking ${e}, ignoring. Error was ${t}`)}))))))}var t}_tooManyFiles(e){return this.options.numToKeep>0&&e>this.options.numToKeep}};const Lc=Mc;var jc=class extends Lc{constructor(e,t,n,r){r||(r={}),t&&(r.maxSize=t),r.numBackups||0===r.numBackups||(n||0===n||(n=1),r.numBackups=n),super(e,r),this.backups=r.numBackups,this.size=this.options.maxSize}get theStream(){return this.currentFileStream}};const $c=Mc;var Hc={RollingFileWriteStream:Mc,RollingFileStream:jc,DateRollingFileStream:class extends $c{constructor(e,t,n){t&&"object"==typeof t&&(n=t,t=null),n||(n={}),t||(t="yyyy-MM-dd"),n.pattern=t,n.numBackups||0===n.numBackups?n.daysToKeep=n.numBackups:(n.daysToKeep||0===n.daysToKeep?process.emitWarning("options.daysToKeep is deprecated due to the confusion it causes when used together with file size rolling. Please use options.numBackups instead.","DeprecationWarning","streamroller-DEP0001"):n.daysToKeep=1,n.numBackups=n.daysToKeep),super(e,n),this.mode=this.options.mode}get theStream(){return this.currentFileStream}}};const Jc=Nr.exports("log4js:file"),Gc=p.default,Vc=Hc,Uc=E.default.EOL;let Wc=!1;const zc=new Set;function Kc(){zc.forEach((e=>{e.sighupHandler()}))}function qc(e,t,n,r){const u=new Vc.RollingFileStream(e,t,n,r);return u.on("error",(t=>{console.error("log4js.fileAppender - Writing to file %s, error happened ",e,t)})),u.on("drain",(()=>{process.emit("log4js:pause",!1)})),u}Eo.configure=function(e,t){let n=t.basicLayout;return e.layout&&(n=t.layout(e.layout.type,e.layout)),e.mode=e.mode||384,function(e,t,n,r,u,o){e=Gc.normalize(e),Jc("Creating file appender (",e,", ",n,", ",r=r||0===r?r:5,", ",u,", ",o,")");let i=qc(e,n,r,u);const s=function(e){if(i.writable){if(!0===u.removeColor){const t=/\x1b[[0-9;]*m/g;e.data=e.data.map((e=>"string"==typeof e?e.replace(t,""):e))}i.write(t(e,o)+Uc,"utf8")||process.emit("log4js:pause",!0)}};return s.reopen=function(){i.end((()=>{i=qc(e,n,r,u)}))},s.sighupHandler=function(){Jc("SIGHUP handler called."),s.reopen()},s.shutdown=function(e){zc.delete(s),0===zc.size&&Wc&&(process.removeListener("SIGHUP",Kc),Wc=!1),i.end("","utf-8",e)},zc.add(s),Wc||(process.on("SIGHUP",Kc),Wc=!0),s}(e.filename,n,e.maxLogSize,e.backups,e,e.timezoneOffset)};var Yc={};const Xc=Hc,Zc=E.default.EOL;function Qc(e,t,n,r,u){r.maxSize=r.maxLogSize;const o=function(e,t,n){const r=new Xc.DateRollingFileStream(e,t,n);return r.on("error",(t=>{console.error("log4js.dateFileAppender - Writing to file %s, error happened ",e,t)})),r.on("drain",(()=>{process.emit("log4js:pause",!1)})),r}(e,t,r),i=function(e){o.writable&&(o.write(n(e,u)+Zc,"utf8")||process.emit("log4js:pause",!0))};return i.shutdown=function(e){o.end("","utf-8",e)},i}Yc.configure=function(e,t){let n=t.basicLayout;return e.layout&&(n=t.layout(e.layout.type,e.layout)),e.alwaysIncludePattern||(e.alwaysIncludePattern=!1),e.mode=e.mode||384,Qc(e.filename,e.pattern,n,e,e.timezoneOffset)};var ea={};const ta=Nr.exports("log4js:fileSync"),na=p.default,ra=D.default,ua=E.default.EOL||"\n";function oa(e,t){if(ra.existsSync(e))return;const n=ra.openSync(e,t.flags,t.mode);ra.closeSync(n)}class ia{constructor(e,t,n,r){ta("In RollingFileStream"),function(){if(!e||!t||t<=0)throw new Error("You must specify a filename and file size")}(),this.filename=e,this.size=t,this.backups=n,this.options=r,this.currentSize=0,this.currentSize=function(e){let t=0;try{t=ra.statSync(e).size}catch(t){oa(e,r)}return t}(this.filename)}shouldRoll(){return ta("should roll with current size %d, and max size %d",this.currentSize,this.size),this.currentSize>=this.size}roll(e){const t=this,n=new RegExp(`^${na.basename(e)}`);function r(e){return n.test(e)}function u(t){return parseInt(t.substring(`${na.basename(e)}.`.length),10)||0}function o(e,t){return u(e)>u(t)?1:u(e) ${e}.${r+1}`),ra.renameSync(na.join(na.dirname(e),n),`${e}.${r+1}`)}}ta("Rolling, rolling, rolling"),ta("Renaming the old files"),ra.readdirSync(na.dirname(e)).filter(r).sort(o).reverse().forEach(i)}write(e,t){const n=this;ta("in write"),this.shouldRoll()&&(this.currentSize=0,this.roll(this.filename)),ta("writing the chunk to the file"),n.currentSize+=e.length,ra.appendFileSync(n.filename,e)}}ea.configure=function(e,t){let n=t.basicLayout;e.layout&&(n=t.layout(e.layout.type,e.layout));const r={flags:e.flags||"a",encoding:e.encoding||"utf8",mode:e.mode||384};return function(e,t,n,r,u,o){ta("fileSync appender created");const i=function(e,t,n){let r;var u;return t?r=new ia(e,t,n,o):(oa(u=e,o),r={write(e){ra.appendFileSync(u,e)}}),r}(e=na.normalize(e),n,r=r||0===r?r:5);return e=>{i.write(t(e,u)+ua)}}(e.filename,n,e.maxLogSize,e.backups,e.timezoneOffset,r)};var sa={};const ca=Nr.exports("log4js:tcp"),aa=S.default;sa.configure=function(e,t){ca(`configure with config = ${e}`);let n=function(e){return e.serialise()};return e.layout&&(n=t.layout(e.layout.type,e.layout)),function(e,t){let n=!1;const r=[];let u,o=3,i="__LOG4JS__";function s(e){ca("Writing log event to socket"),n=u.write(`${t(e)}${i}`,"utf8")}function c(){let e;for(ca("emptying buffer");e=r.shift();)s(e)}function a(e){n?s(e):(ca("buffering log event because it cannot write at the moment"),r.push(e))}return function t(){ca(`appender creating socket to ${e.host||"localhost"}:${e.port||5e3}`),i=`${e.endMsg||"__LOG4JS__"}`,u=aa.createConnection(e.port||5e3,e.host||"localhost"),u.on("connect",(()=>{ca("socket connected"),c(),n=!0})),u.on("drain",(()=>{ca("drain event received, emptying buffer"),n=!0,c()})),u.on("timeout",u.end.bind(u)),u.on("error",(e=>{ca("connection error",e),n=!1,c()})),u.on("close",t)}(),a.shutdown=function(e){ca("shutdown called"),r.length&&o?(ca("buffer has items, waiting 100ms to empty"),o-=1,setTimeout((()=>{a.shutdown(e)}),100)):(u.removeAllListeners("close"),u.end(e))},a}(e,n)};const la=p.default,fa=Nr.exports("log4js:appenders"),da=tu,Da=eo,pa=gu,Ea=hu,ma=to,ha=new Map;ha.set("console",oo),ha.set("stdout",so),ha.set("stderr",co),ha.set("logLevelFilter",ao),ha.set("categoryFilter",lo),ha.set("noLogFilter",Do),ha.set("file",Eo),ha.set("dateFile",Yc),ha.set("fileSync",ea),ha.set("tcp",sa);const ya=new Map,Ca=(e,t)=>{fa("Loading module from ",e);try{return require(e)}catch(n){return void da.throwExceptionIf(t,"MODULE_NOT_FOUND"!==n.code,`appender "${e}" could not be loaded (error was: ${n})`)}},Fa=new Set,ga=(e,t)=>{if(ya.has(e))return ya.get(e);if(!t.appenders[e])return!1;if(Fa.has(e))throw new Error(`Dependency loop detected for appender ${e}.`);Fa.add(e),fa(`Creating appender ${e}`);const n=Aa(e,t);return Fa.delete(e),ya.set(e,n),n},Aa=(e,t)=>{const n=t.appenders[e],r=n.type.configure?n.type:((e,t)=>ha.get(e)||Ca(`./${e}`,t)||Ca(e,t)||require.main&&Ca(la.join(la.dirname(require.main.filename),e),t)||Ca(la.join(process.cwd(),e),t))(n.type,t);return da.throwExceptionIf(t,da.not(r),`appender "${e}" is not valid (type "${n.type}" could not be found)`),r.appender&&fa(`DEPRECATION: Appender ${n.type} exports an appender function.`),r.shutdown&&fa(`DEPRECATION: Appender ${n.type} exports a shutdown function.`),fa(`${e}: clustering.isMaster ? ${Da.isMaster()}`),fa(`${e}: appenderModule is ${F.default.inspect(r)}`),Da.onlyOnMaster((()=>(fa(`calling appenderModule.configure for ${e} / ${n.type}`),r.configure(ma.modifyConfig(n),Ea,(e=>ga(e,t)),pa))),(()=>{}))},va=e=>{ya.clear(),Fa.clear();const t=[];Object.values(e.categories).forEach((e=>{t.push(...e.appenders)})),Object.keys(e.appenders).forEach((n=>{(t.includes(n)||"tcp-server"===e.appenders[n].type)&&ga(n,e)}))},Sa=()=>{va({appenders:{out:{type:"stdout"}},categories:{default:{appenders:["out"],level:"trace"}}})};Sa(),da.addListener((e=>{da.throwExceptionIf(e,da.not(da.anObject(e.appenders)),'must have a property "appenders" of type object.');const t=Object.keys(e.appenders);da.throwExceptionIf(e,da.not(t.length),"must define at least one appender."),t.forEach((t=>{da.throwExceptionIf(e,da.not(e.appenders[t].type),`appender "${t}" is not valid (must be an object with property "type")`)}))})),da.addListener(va),Au.exports=ya,Au.exports.init=Sa;var wa={exports:{}};!function(e){const t=Nr.exports("log4js:categories"),n=tu,r=gu,u=Au.exports,o=new Map;function i(e,t,n){if(!1===t.inherit)return;const r=n.lastIndexOf(".");if(r<0)return;const u=n.substring(0,r);let o=e.categories[u];o||(o={inherit:!0,appenders:[]}),i(e,o,u),!e.categories[u]&&o.appenders&&o.appenders.length&&o.level&&(e.categories[u]=o),t.appenders=t.appenders||[],t.level=t.level||o.level,o.appenders.forEach((e=>{t.appenders.includes(e)||t.appenders.push(e)})),t.parent=o}function s(e){if(!e.categories)return;Object.keys(e.categories).forEach((t=>{const n=e.categories[t];i(e,n,t)}))}n.addPreProcessingListener((e=>s(e))),n.addListener((e=>{n.throwExceptionIf(e,n.not(n.anObject(e.categories)),'must have a property "categories" of type object.');const t=Object.keys(e.categories);n.throwExceptionIf(e,n.not(t.length),"must define at least one category."),t.forEach((t=>{const o=e.categories[t];n.throwExceptionIf(e,[n.not(o.appenders),n.not(o.level)],`category "${t}" is not valid (must be an object with properties "appenders" and "level")`),n.throwExceptionIf(e,n.not(Array.isArray(o.appenders)),`category "${t}" is not valid (appenders must be an array of appender names)`),n.throwExceptionIf(e,n.not(o.appenders.length),`category "${t}" is not valid (appenders must contain at least one appender name)`),Object.prototype.hasOwnProperty.call(o,"enableCallStack")&&n.throwExceptionIf(e,"boolean"!=typeof o.enableCallStack,`category "${t}" is not valid (enableCallStack must be boolean type)`),o.appenders.forEach((r=>{n.throwExceptionIf(e,n.not(u.get(r)),`category "${t}" is not valid (appender "${r}" is not defined)`)})),n.throwExceptionIf(e,n.not(r.getLevel(o.level)),`category "${t}" is not valid (level "${o.level}" not recognised; valid levels are ${r.levels.join(", ")})`)})),n.throwExceptionIf(e,n.not(e.categories.default),'must define a "default" category.')}));const c=e=>{o.clear();Object.keys(e.categories).forEach((n=>{const i=e.categories[n],s=[];i.appenders.forEach((e=>{s.push(u.get(e)),t(`Creating category ${n}`),o.set(n,{appenders:s,level:r.getLevel(i.level),enableCallStack:i.enableCallStack||!1})}))}))},a=()=>{c({categories:{default:{appenders:["out"],level:"OFF"}}})};a(),n.addListener(c);const l=e=>(t(`configForCategory: searching for config for ${e}`),o.has(e)?(t(`configForCategory: ${e} exists in config, returning it`),o.get(e)):e.indexOf(".")>0?(t(`configForCategory: ${e} has hierarchy, searching for parents`),l(e.substring(0,e.lastIndexOf(".")))):(t("configForCategory: returning config for default category"),l("default")));e.exports=o,e.exports=Object.assign(e.exports,{appendersForCategory:e=>l(e).appenders,getLevelForCategory:e=>l(e).level,setLevelForCategory:(e,n)=>{let r=o.get(e);if(t(`setLevelForCategory: found ${r} for ${e}`),!r){const n=l(e);t(`setLevelForCategory: no config found for category, found ${n} for parents of ${e}`),r={appenders:n.appenders}}r.level=n,o.set(e,r)},getEnableCallStackForCategory:e=>!0===l(e).enableCallStack,setEnableCallStackForCategory:(e,t)=>{l(e).enableCallStack=t},init:a})}(wa);const Oa=Nr.exports("log4js:logger"),ba=Hu,_a=gu,Ba=eo,Pa=wa.exports,ka=tu,xa=/at (?:(.+)\s+\()?(?:(.+?):(\d+)(?::(\d+))?|([^)]+))\)?/;function Na(e,t=4){const n=e.stack.split("\n").slice(t),r=xa.exec(n[0]);return r&&6===r.length?{functionName:r[1],fileName:r[2],lineNumber:parseInt(r[3],10),columnNumber:parseInt(r[4],10),callStack:n.join("\n")}:null}class Ia{constructor(e){if(!e)throw new Error("No category provided.");this.category=e,this.context={},this.parseCallStack=Na,Oa(`Logger created (${this.category}, ${this.level})`)}get level(){return _a.getLevel(Pa.getLevelForCategory(this.category),_a.TRACE)}set level(e){Pa.setLevelForCategory(this.category,_a.getLevel(e,this.level))}get useCallStack(){return Pa.getEnableCallStackForCategory(this.category)}set useCallStack(e){Pa.setEnableCallStackForCategory(this.category,!0===e)}log(e,...t){let n=_a.getLevel(e);n||(this._log(_a.WARN,"log4js:logger.log: invalid value for log-level as first parameter given: ",e),n=_a.INFO),this.isLevelEnabled(n)&&this._log(n,t)}isLevelEnabled(e){return this.level.isLessThanOrEqualTo(e)}_log(e,t){Oa(`sending log data (${e}) to appenders`);const n=new ba(this.category,e,t,this.context,this.useCallStack&&this.parseCallStack(new Error));Ba.send(n)}addContext(e,t){this.context[e]=t}removeContext(e){delete this.context[e]}clearContext(){this.context={}}setParseCallStackFunction(e){this.parseCallStack=e}}function Ta(e){const t=_a.getLevel(e),n=t.toString().toLowerCase().replace(/_([a-z])/g,(e=>e[1].toUpperCase())),r=n[0].toUpperCase()+n.slice(1);Ia.prototype[`is${r}Enabled`]=function(){return this.isLevelEnabled(t)},Ia.prototype[n]=function(...e){this.log(t,...e)}}_a.levels.forEach(Ta),ka.addListener((()=>{_a.levels.forEach(Ta)}));var Ra=Ia;const Ma=gu;function La(e){return e.originalUrl||e.url}function ja(e,t){for(let n=0;ne.source?e.source:e));t=new RegExp(n.join("|"))}return t}(t.nolog);return(e,i,s)=>{if(e._logging)return s();if(o&&o.test(e.originalUrl))return s();if(n.isLevelEnabled(r)||"auto"===t.level){const o=new Date,{writeHead:s}=i;e._logging=!0,i.writeHead=(e,t)=>{i.writeHead=s,i.writeHead(e,t),i.__statusCode=e,i.__headers=t||{}},i.on("finish",(()=>{i.responseTime=new Date-o,i.statusCode&&"auto"===t.level&&(r=Ma.INFO,i.statusCode>=300&&(r=Ma.WARN),i.statusCode>=400&&(r=Ma.ERROR)),r=function(e,t,n){let r=t;if(n){const t=n.find((t=>{let n=!1;return n=t.from&&t.to?e>=t.from&&e<=t.to:-1!==t.codes.indexOf(e),n}));t&&(r=Ma.getLevel(t.level,r))}return r}(i.statusCode,r,t.statusRules);const s=function(e,t,n){const r=[];return r.push({token:":url",replacement:La(e)}),r.push({token:":protocol",replacement:e.protocol}),r.push({token:":hostname",replacement:e.hostname}),r.push({token:":method",replacement:e.method}),r.push({token:":status",replacement:t.__statusCode||t.statusCode}),r.push({token:":response-time",replacement:t.responseTime}),r.push({token:":date",replacement:(new Date).toUTCString()}),r.push({token:":referrer",replacement:e.headers.referer||e.headers.referrer||""}),r.push({token:":http-version",replacement:`${e.httpVersionMajor}.${e.httpVersionMinor}`}),r.push({token:":remote-addr",replacement:e.headers["x-forwarded-for"]||e.ip||e._remoteAddress||e.socket&&(e.socket.remoteAddress||e.socket.socket&&e.socket.socket.remoteAddress)}),r.push({token:":user-agent",replacement:e.headers["user-agent"]}),r.push({token:":content-length",replacement:t.getHeader("content-length")||t.__headers&&t.__headers["Content-Length"]||"-"}),r.push({token:/:req\[([^\]]+)]/g,replacement:(t,n)=>e.headers[n.toLowerCase()]}),r.push({token:/:res\[([^\]]+)]/g,replacement:(e,n)=>t.getHeader(n.toLowerCase())||t.__headers&&t.__headers[n]}),(e=>{const t=e.concat();for(let e=0;eja(e,s)));t&&n.log(r,t)}else n.log(r,ja(u,s));t.context&&n.removeContext("res")}))}return s()}},nl=Va;let rl=!1;function ul(e){if(!rl)return;Ua("Received log event ",e);Za.appendersForCategory(e.categoryName).forEach((t=>{t(e)}))}function ol(e){rl&&il();let t=e;return"string"==typeof t&&(t=function(e){Ua(`Loading configuration from ${e}`);try{return JSON.parse(Wa.readFileSync(e,"utf8"))}catch(t){throw new Error(`Problem reading config from file "${e}". Error was ${t.message}`,t)}}(e)),Ua(`Configuration is ${t}`),Ka.configure(za(t)),el.onMessage(ul),rl=!0,sl}function il(e){Ua("Shutdown called. Disabling all log writing."),rl=!1;const t=Array.from(Xa.values());Xa.init(),Za.init();const n=t.reduceRight(((e,t)=>t.shutdown?e+1:e),0);if(0===n)return Ua("No appenders with shutdown functions found."),void 0!==e&&e();let r,u=0;function o(t){r=r||t,u+=1,Ua(`Appender shutdowns complete: ${u} / ${n}`),u>=n&&(Ua("All shutdown functions completed."),e&&e(r))}return Ua(`Found ${n} appenders with shutdown functions.`),t.filter((e=>e.shutdown)).forEach((e=>e.shutdown(o))),null}const sl={getLogger:function(e){return rl||ol(process.env.LOG4JS_CONFIG||{appenders:{out:{type:"stdout"}},categories:{default:{appenders:["out"],level:"OFF"}}}),new Qa(e||"default")},configure:ol,shutdown:il,connectLogger:tl,levels:Ya,addLayout:qa.addLayout,recording:function(){return nl}};var cl=sl,al={};Object.defineProperty(al,"__esModule",{value:!0}),al.levelMap=al.getLevel=al.setCategoriesLevel=al.getConfiguration=al.setConfiguration=void 0;const ll=cl;let fl={appenders:{debug:{type:"stdout",layout:{type:"pattern",pattern:"[%d] > hvigor %p %c %[%m%]"}},info:{type:"stdout",layout:{type:"pattern",pattern:"[%d] > hvigor %[%m%]"}},"no-pattern-info":{type:"stdout",layout:{type:"pattern",pattern:"%m"}},wrong:{type:"stderr",layout:{type:"pattern",pattern:"[%d] > hvigor %[%p: %m%]"}},"just-debug":{type:"logLevelFilter",appender:"debug",level:"debug",maxLevel:"debug"},"just-info":{type:"logLevelFilter",appender:"info",level:"info",maxLevel:"info"},"just-wrong":{type:"logLevelFilter",appender:"wrong",level:"warn",maxLevel:"error"}},categories:{default:{appenders:["just-debug","just-info","just-wrong"],level:"debug"},"no-pattern-info":{appenders:["no-pattern-info"],level:"info"}}};al.setConfiguration=e=>{fl=e};al.getConfiguration=()=>fl;let dl=ll.levels.DEBUG;al.setCategoriesLevel=(e,t)=>{dl=e;const n=fl.categories;for(const r in n)(null==t?void 0:t.includes(r))||Object.prototype.hasOwnProperty.call(n,r)&&(n[r].level=e.levelStr)};al.getLevel=()=>dl,al.levelMap=new Map([["ALL",ll.levels.ALL],["MARK",ll.levels.MARK],["TRACE",ll.levels.TRACE],["DEBUG",ll.levels.DEBUG],["INFO",ll.levels.INFO],["WARN",ll.levels.WARN],["ERROR",ll.levels.ERROR],["FATAL",ll.levels.FATAL],["OFF",ll.levels.OFF]]);var Dl=w&&w.__createBinding||(Object.create?function(e,t,n,r){void 0===r&&(r=n);var u=Object.getOwnPropertyDescriptor(t,n);u&&!("get"in u?!t.__esModule:u.writable||u.configurable)||(u={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,r,u)}:function(e,t,n,r){void 0===r&&(r=n),e[r]=t[n]}),pl=w&&w.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),El=w&&w.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var n in e)"default"!==n&&Object.prototype.hasOwnProperty.call(e,n)&&Dl(t,e,n);return pl(t,e),t};Object.defineProperty(xr,"__esModule",{value:!0}),xr.evaluateLogLevel=xr.HvigorLogger=void 0;const ml=El(cl),hl=cl,yl=El(F.default),Cl=al;class Fl{constructor(e){ml.configure((0,Cl.getConfiguration)()),this._logger=ml.getLogger(e),this._logger.level=(0,Cl.getLevel)()}static getLogger(e){return new Fl(e)}log(e,...t){this._logger.log(e,...t)}debug(e,...t){this._logger.debug(e,...t)}info(e,...t){this._logger.info(e,...t)}warn(e,...t){void 0!==e&&""!==e&&this._logger.warn(e,...t)}error(e,...t){this._logger.error(e,...t)}_printTaskExecuteInfo(e,t){this.info(`Finished :${e}... after ${t}`)}_printFailedTaskInfo(e){this.error(`Failed :${e}... `)}_printDisabledTaskInfo(e){this.info(`Disabled :${e}... `)}_printUpToDateTaskInfo(e){this.info(`UP-TO-DATE :${e}... `)}errorMessageExit(e,...t){throw new Error(yl.format(e,...t))}errorExit(e,t,...n){t&&this._logger.error(t,n),this._logger.error(e.stack)}setLevel(e,t){(0,Cl.setCategoriesLevel)(e,t),ml.shutdown(),ml.configure((0,Cl.getConfiguration)())}getLevel(){return this._logger.level}configure(e){const t=(0,Cl.getConfiguration)(),n={appenders:{...t.appenders,...e.appenders},categories:{...t.categories,...e.categories}};(0,Cl.setConfiguration)(n),ml.shutdown(),ml.configure(n)}}xr.HvigorLogger=Fl,xr.evaluateLogLevel=function(e,t){t.debug?e.setLevel(hl.levels.DEBUG):t.warn?e.setLevel(hl.levels.WARN):t.error?e.setLevel(hl.levels.ERROR):e.setLevel(hl.levels.INFO)};var gl=w&&w.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(X,"__esModule",{value:!0}),X.parseJsonText=X.parseJsonFile=void 0;const Al=Z,vl=gl(kr),Sl=gl(p.default),wl=gl(E.default),Ol=xr.HvigorLogger.getLogger("parse-json-util");var bl;!function(e){e[e.Char=0]="Char",e[e.EOF=1]="EOF",e[e.Identifier=2]="Identifier"}(bl||(bl={}));let _l,Bl,Pl,kl,xl,Nl,Il="start",Tl=[],Rl=0,Ml=1,Ll=0,jl=!1,$l="default",Hl="'",Jl=1;function Gl(e,t=!1){Bl=String(e),Il="start",Tl=[],Rl=0,Ml=1,Ll=0,kl=void 0,jl=t;do{_l=Vl(),Xl[Il]()}while("eof"!==_l.type);return kl}function Vl(){for($l="default",xl="",Hl="'",Jl=1;;){Nl=Ul();const e=zl[$l]();if(e)return e}}function Ul(){if(Bl[Rl])return String.fromCodePoint(Bl.codePointAt(Rl))}function Wl(){const e=Ul();return"\n"===e?(Ml++,Ll=0):e?Ll+=e.length:Ll++,e&&(Rl+=e.length),e}X.parseJsonFile=function(e,t=!1,n="utf-8"){const r=vl.default.readFileSync(Sl.default.resolve(e),{encoding:n});try{return Gl(r,t)}catch(t){if(t instanceof SyntaxError){const n=t.message.split("at");2===n.length&&Ol.errorMessageExit(`${n[0].trim()}${wl.default.EOL}\t at ${e}:${n[1].trim()}`)}Ol.errorMessageExit(`${e} is not in valid JSON/JSON5 format.`)}},X.parseJsonText=Gl;const zl={default(){switch(Nl){case"/":return Wl(),void($l="comment");case void 0:return Wl(),Kl("eof")}if(!Al.JudgeUtil.isIgnoreChar(Nl)&&!Al.JudgeUtil.isSpaceSeparator(Nl))return zl[Il]();Wl()},start(){$l="value"},beforePropertyName(){switch(Nl){case"$":case"_":return xl=Wl(),void($l="identifierName");case"\\":return Wl(),void($l="identifierNameStartEscape");case"}":return Kl("punctuator",Wl());case'"':case"'":return Hl=Nl,Wl(),void($l="string")}if(Al.JudgeUtil.isIdStartChar(Nl))return xl+=Wl(),void($l="identifierName");throw tf(bl.Char,Wl())},afterPropertyName(){if(":"===Nl)return Kl("punctuator",Wl());throw tf(bl.Char,Wl())},beforePropertyValue(){$l="value"},afterPropertyValue(){switch(Nl){case",":case"}":return Kl("punctuator",Wl())}throw tf(bl.Char,Wl())},beforeArrayValue(){if("]"===Nl)return Kl("punctuator",Wl());$l="value"},afterArrayValue(){switch(Nl){case",":case"]":return Kl("punctuator",Wl())}throw tf(bl.Char,Wl())},end(){throw tf(bl.Char,Wl())},comment(){switch(Nl){case"*":return Wl(),void($l="multiLineComment");case"/":return Wl(),void($l="singleLineComment")}throw tf(bl.Char,Wl())},multiLineComment(){switch(Nl){case"*":return Wl(),void($l="multiLineCommentAsterisk");case void 0:throw tf(bl.Char,Wl())}Wl()},multiLineCommentAsterisk(){switch(Nl){case"*":return void Wl();case"/":return Wl(),void($l="default");case void 0:throw tf(bl.Char,Wl())}Wl(),$l="multiLineComment"},singleLineComment(){switch(Nl){case"\n":case"\r":case"\u2028":case"\u2029":return Wl(),void($l="default");case void 0:return Wl(),Kl("eof")}Wl()},value(){switch(Nl){case"{":case"[":return Kl("punctuator",Wl());case"n":return Wl(),ql("ull"),Kl("null",null);case"t":return Wl(),ql("rue"),Kl("boolean",!0);case"f":return Wl(),ql("alse"),Kl("boolean",!1);case"-":case"+":return"-"===Wl()&&(Jl=-1),void($l="numerical");case".":case"0":case"I":case"N":return void($l="numerical");case'"':case"'":return Hl=Nl,Wl(),xl="",void($l="string")}if(void 0===Nl||!Al.JudgeUtil.isDigitWithoutZero(Nl))throw tf(bl.Char,Wl());$l="numerical"},numerical(){switch(Nl){case".":return xl=Wl(),void($l="decimalPointLeading");case"0":return xl=Wl(),void($l="zero");case"I":return Wl(),ql("nfinity"),Kl("numeric",Jl*(1/0));case"N":return Wl(),ql("aN"),Kl("numeric",NaN)}if(void 0!==Nl&&Al.JudgeUtil.isDigitWithoutZero(Nl))return xl=Wl(),void($l="decimalInteger");throw tf(bl.Char,Wl())},zero(){switch(Nl){case".":case"e":case"E":return void($l="decimal");case"x":case"X":return xl+=Wl(),void($l="hexadecimal")}return Kl("numeric",0)},decimalInteger(){switch(Nl){case".":case"e":case"E":return void($l="decimal")}if(!Al.JudgeUtil.isDigit(Nl))return Kl("numeric",Jl*Number(xl));xl+=Wl()},decimal(){switch(Nl){case".":xl+=Wl(),$l="decimalFraction";break;case"e":case"E":xl+=Wl(),$l="decimalExponent"}},decimalPointLeading(){if(Al.JudgeUtil.isDigit(Nl))return xl+=Wl(),void($l="decimalFraction");throw tf(bl.Char,Wl())},decimalFraction(){switch(Nl){case"e":case"E":return xl+=Wl(),void($l="decimalExponent")}if(!Al.JudgeUtil.isDigit(Nl))return Kl("numeric",Jl*Number(xl));xl+=Wl()},decimalExponent(){switch(Nl){case"+":case"-":return xl+=Wl(),void($l="decimalExponentSign")}if(Al.JudgeUtil.isDigit(Nl))return xl+=Wl(),void($l="decimalExponentInteger");throw tf(bl.Char,Wl())},decimalExponentSign(){if(Al.JudgeUtil.isDigit(Nl))return xl+=Wl(),void($l="decimalExponentInteger");throw tf(bl.Char,Wl())},decimalExponentInteger(){if(!Al.JudgeUtil.isDigit(Nl))return Kl("numeric",Jl*Number(xl));xl+=Wl()},hexadecimal(){if(Al.JudgeUtil.isHexDigit(Nl))return xl+=Wl(),void($l="hexadecimalInteger");throw tf(bl.Char,Wl())},hexadecimalInteger(){if(!Al.JudgeUtil.isHexDigit(Nl))return Kl("numeric",Jl*Number(xl));xl+=Wl()},identifierNameStartEscape(){if("u"!==Nl)throw tf(bl.Char,Wl());Wl();const e=Yl();switch(e){case"$":case"_":break;default:if(!Al.JudgeUtil.isIdStartChar(e))throw tf(bl.Identifier)}xl+=e,$l="identifierName"},identifierName(){switch(Nl){case"$":case"_":case"‌":case"‍":return void(xl+=Wl());case"\\":return Wl(),void($l="identifierNameEscape")}if(!Al.JudgeUtil.isIdContinueChar(Nl))return Kl("identifier",xl);xl+=Wl()},identifierNameEscape(){if("u"!==Nl)throw tf(bl.Char,Wl());Wl();const e=Yl();switch(e){case"$":case"_":case"‌":case"‍":break;default:if(!Al.JudgeUtil.isIdContinueChar(e))throw tf(bl.Identifier)}xl+=e,$l="identifierName"},string(){switch(Nl){case"\\":return Wl(),void(xl+=function(){const e=Ul(),t=function(){switch(Ul()){case"b":return Wl(),"\b";case"f":return Wl(),"\f";case"n":return Wl(),"\n";case"r":return Wl(),"\r";case"t":return Wl(),"\t";case"v":return Wl(),"\v"}return}();if(t)return t;switch(e){case"0":if(Wl(),Al.JudgeUtil.isDigit(Ul()))throw tf(bl.Char,Wl());return"\0";case"x":return Wl(),function(){let e="",t=Ul();if(!Al.JudgeUtil.isHexDigit(t))throw tf(bl.Char,Wl());if(e+=Wl(),t=Ul(),!Al.JudgeUtil.isHexDigit(t))throw tf(bl.Char,Wl());return e+=Wl(),String.fromCodePoint(parseInt(e,16))}();case"u":return Wl(),Yl();case"\n":case"\u2028":case"\u2029":return Wl(),"";case"\r":return Wl(),"\n"===Ul()&&Wl(),""}if(void 0===e||Al.JudgeUtil.isDigitWithoutZero(e))throw tf(bl.Char,Wl());return Wl()}());case'"':case"'":if(Nl===Hl){const e=Kl("string",xl);return Wl(),e}return void(xl+=Wl());case"\n":case"\r":case void 0:throw tf(bl.Char,Wl());case"\u2028":case"\u2029":!function(e){Ol.warn(`JSON5: '${ef(e)}' in strings is not valid ECMAScript; consider escaping.`)}(Nl)}xl+=Wl()}};function Kl(e,t){return{type:e,value:t,line:Ml,column:Ll}}function ql(e){for(const t of e){if(Ul()!==t)throw tf(bl.Char,Wl());Wl()}}function Yl(){let e="",t=4;for(;t-- >0;){const t=Ul();if(!Al.JudgeUtil.isHexDigit(t))throw tf(bl.Char,Wl());e+=Wl()}return String.fromCodePoint(parseInt(e,16))}const Xl={start(){if("eof"===_l.type)throw tf(bl.EOF);Zl()},beforePropertyName(){switch(_l.type){case"identifier":case"string":return Pl=_l.value,void(Il="afterPropertyName");case"punctuator":return void Ql();case"eof":throw tf(bl.EOF)}},afterPropertyName(){if("eof"===_l.type)throw tf(bl.EOF);Il="beforePropertyValue"},beforePropertyValue(){if("eof"===_l.type)throw tf(bl.EOF);Zl()},afterPropertyValue(){if("eof"===_l.type)throw tf(bl.EOF);switch(_l.value){case",":return void(Il="beforePropertyName");case"}":Ql()}},beforeArrayValue(){if("eof"===_l.type)throw tf(bl.EOF);"punctuator"!==_l.type||"]"!==_l.value?Zl():Ql()},afterArrayValue(){if("eof"===_l.type)throw tf(bl.EOF);switch(_l.value){case",":return void(Il="beforeArrayValue");case"]":Ql()}},end(){}};function Zl(){const e=function(){let e;switch(_l.type){case"punctuator":switch(_l.value){case"{":e={};break;case"[":e=[]}break;case"null":case"boolean":case"numeric":case"string":e=_l.value}return e}();if(jl&&"object"==typeof e&&(e._line=Ml,e._column=Ll),void 0===kl)kl=e;else{const t=Tl[Tl.length-1];Array.isArray(t)?jl&&"object"!=typeof e?t.push({value:e,_line:Ml,_column:Ll}):t.push(e):t[Pl]=jl&&"object"!=typeof e?{value:e,_line:Ml,_column:Ll}:e}!function(e){if(e&&"object"==typeof e)Tl.push(e),Il=Array.isArray(e)?"beforeArrayValue":"beforePropertyName";else{const e=Tl[Tl.length-1];Il=e?Array.isArray(e)?"afterArrayValue":"afterPropertyValue":"end"}}(e)}function Ql(){Tl.pop();const e=Tl[Tl.length-1];Il=e?Array.isArray(e)?"afterArrayValue":"afterPropertyValue":"end"}function ef(e){const t={"'":"\\'",'"':'\\"',"\\":"\\\\","\b":"\\b","\f":"\\f","\n":"\\n","\r":"\\r","\t":"\\t","\v":"\\v","\0":"\\0","\u2028":"\\u2028","\u2029":"\\u2029"};if(t[e])return t[e];if(e<" "){const t=e.charCodeAt(0).toString(16);return`\\x${`00${t}`.substring(t.length)}`}return e}function tf(e,t){let n="";switch(e){case bl.Char:n=void 0===t?`JSON5: invalid end of input at ${Ml}:${Ll}`:`JSON5: invalid character '${ef(t)}' at ${Ml}:${Ll}`;break;case bl.EOF:n=`JSON5: invalid end of input at ${Ml}:${Ll}`;break;case bl.Identifier:Ll-=5,n=`JSON5: invalid identifier character at ${Ml}:${Ll}`}const r=new nf(n);return r.lineNumber=Ml,r.columnNumber=Ll,r}class nf extends SyntaxError{}var rf=w&&w.__createBinding||(Object.create?function(e,t,n,r){void 0===r&&(r=n);var u=Object.getOwnPropertyDescriptor(t,n);u&&!("get"in u?!t.__esModule:u.writable||u.configurable)||(u={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,r,u)}:function(e,t,n,r){void 0===r&&(r=n),e[r]=t[n]}),uf=w&&w.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),of=w&&w.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var n in e)"default"!==n&&Object.prototype.hasOwnProperty.call(e,n)&&rf(t,e,n);return uf(t,e),t};Object.defineProperty(Y,"__esModule",{value:!0});var sf=Y.cleanWorkSpace=Ff=Y.executeInstallHvigor=yf=Y.isHvigorInstalled=mf=Y.isAllDependenciesInstalled=void 0;const cf=of(D.default),af=of(p.default),lf=b,ff=j,df=$,Df=X;let pf,Ef;var mf=Y.isAllDependenciesInstalled=function(){function e(e){const t=null==e?void 0:e.dependencies;return void 0===t?0:Object.getOwnPropertyNames(t).length}if(pf=gf(),Ef=Af(),e(pf)+1!==e(Ef))return!1;for(const e in null==pf?void 0:pf.dependencies)if(!(0,ff.hasNpmPackInPaths)(e,[lf.HVIGOR_PROJECT_DEPENDENCIES_HOME])||!hf(e,pf,Ef))return!1;return!0};function hf(e,t,n){return void 0!==n.dependencies&&(0,ff.offlinePluginConversion)(lf.HVIGOR_PROJECT_ROOT_DIR,t.dependencies[e])===n.dependencies[e]}var yf=Y.isHvigorInstalled=function(){return pf=gf(),Ef=Af(),(0,ff.hasNpmPackInPaths)(lf.HVIGOR_ENGINE_PACKAGE_NAME,[lf.HVIGOR_PROJECT_DEPENDENCIES_HOME])&&(0,ff.offlinePluginConversion)(lf.HVIGOR_PROJECT_ROOT_DIR,pf.hvigorVersion)===Ef.dependencies[lf.HVIGOR_ENGINE_PACKAGE_NAME]};const Cf={cwd:lf.HVIGOR_PROJECT_DEPENDENCIES_HOME,stdio:["inherit","inherit","inherit"]};var Ff=Y.executeInstallHvigor=function(){(0,df.logInfoPrintConsole)("Hvigor installing...");const e={dependencies:{}};e.dependencies[lf.HVIGOR_ENGINE_PACKAGE_NAME]=(0,ff.offlinePluginConversion)(lf.HVIGOR_PROJECT_ROOT_DIR,pf.hvigorVersion);try{cf.mkdirSync(lf.HVIGOR_PROJECT_DEPENDENCIES_HOME,{recursive:!0});const t=af.resolve(lf.HVIGOR_PROJECT_DEPENDENCIES_HOME,lf.DEFAULT_PACKAGE_JSON);cf.writeFileSync(t,JSON.stringify(e))}catch(e){(0,df.logErrorAndExit)(e)}!function(){const e=["config","set","store-dir",lf.HVIGOR_PNPM_STORE_PATH];(0,ff.executeCommand)(lf.HVIGOR_WRAPPER_PNPM_SCRIPT_PATH,e,Cf)}(),(0,ff.executeCommand)(lf.HVIGOR_WRAPPER_PNPM_SCRIPT_PATH,["install"],Cf)};function gf(){const e=af.resolve(lf.HVIGOR_PROJECT_WRAPPER_HOME,lf.DEFAULT_HVIGOR_CONFIG_JSON_FILE_NAME);return cf.existsSync(e)||(0,df.logErrorAndExit)(`Error: Hvigor config file ${e} does not exist.`),(0,Df.parseJsonFile)(e)}function Af(){return cf.existsSync(lf.HVIGOR_PROJECT_DEPENDENCY_PACKAGE_JSON_PATH)?(0,Df.parseJsonFile)(lf.HVIGOR_PROJECT_DEPENDENCY_PACKAGE_JSON_PATH):{dependencies:{}}}sf=Y.cleanWorkSpace=function(){if((0,df.logInfoPrintConsole)("Hvigor cleaning..."),!cf.existsSync(lf.HVIGOR_PROJECT_DEPENDENCIES_HOME))return;const e=cf.readdirSync(lf.HVIGOR_PROJECT_DEPENDENCIES_HOME);if(e&&0!==e.length){cf.existsSync(lf.HVIGOR_BOOT_JS_FILE_PATH)&&(0,ff.executeCommand)(process.argv[0],[lf.HVIGOR_BOOT_JS_FILE_PATH,"--stop-daemon"],{});try{e.forEach((e=>{cf.rmSync(af.resolve(lf.HVIGOR_PROJECT_DEPENDENCIES_HOME,e),{recursive:!0})}))}catch(e){(0,df.logErrorAndExit)(`The hvigor build tool cannot be installed. Please manually clear the workspace directory and synchronize the project again.\n\n Workspace Path: ${lf.HVIGOR_PROJECT_DEPENDENCIES_HOME}.`)}}};var vf={},Sf=w&&w.__createBinding||(Object.create?function(e,t,n,r){void 0===r&&(r=n);var u=Object.getOwnPropertyDescriptor(t,n);u&&!("get"in u?!t.__esModule:u.writable||u.configurable)||(u={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,r,u)}:function(e,t,n,r){void 0===r&&(r=n),e[r]=t[n]}),wf=w&&w.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),Of=w&&w.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var n in e)"default"!==n&&Object.prototype.hasOwnProperty.call(e,n)&&Sf(t,e,n);return wf(t,e),t};Object.defineProperty(vf,"__esModule",{value:!0});var bf=vf.executeBuild=void 0;const _f=b,Bf=Of(D.default),Pf=Of(p.default),kf=$;bf=vf.executeBuild=function(){const e=Pf.resolve(_f.HVIGOR_PROJECT_DEPENDENCIES_HOME,"node_modules","@ohos","hvigor","bin","hvigor.js");try{const t=Bf.realpathSync(e);require(t)}catch(t){(0,kf.logErrorAndExit)(`Error: ENOENT: no such file ${e},delete ${_f.HVIGOR_PROJECT_DEPENDENCIES_HOME} and retry.`)}},function(){if(O.checkNpmConifg(),O.environmentHandler(),O.isPnpmAvailable()||O.executeInstallPnpm(),yf()&&mf())bf();else{sf();try{Ff()}catch(e){return void sf()}bf()}}(); \ No newline at end of file diff --git a/storage/storagefileioerrorjstest/hvigorfile.ts b/storage/storagefileioerrorjstest/hvigorfile.ts deleted file mode 100644 index 0b9c10fc3ade5a54609b2d639f808ca7c25a611a..0000000000000000000000000000000000000000 --- a/storage/storagefileioerrorjstest/hvigorfile.ts +++ /dev/null @@ -1,16 +0,0 @@ -/** - * Copyright (c) 2023 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. - */ -// Script for compiling build behavior. It is built in the build plug-in and cannot be modified currently. -export { legacyAppTasks } from '@ohos/hvigor-ohos-plugin'; \ No newline at end of file diff --git a/storage/storagefileioerrorjstest/hvigorw b/storage/storagefileioerrorjstest/hvigorw deleted file mode 100755 index b4d7760e72934718fc616fcef2806a1c7f04ba34..0000000000000000000000000000000000000000 --- a/storage/storagefileioerrorjstest/hvigorw +++ /dev/null @@ -1,61 +0,0 @@ -# Copyright (c) 2023 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. - -#!/bin/bash - -# ---------------------------------------------------------------------------- -# Hvigor startup script, version 1.0.0 -# -# Required ENV vars: -# ------------------ -# NODE_HOME - location of a Node home dir -# or -# Add /usr/local/nodejs/bin to the PATH environment variable -# ---------------------------------------------------------------------------- - -HVIGOR_APP_HOME=$(dirname $(readlink -f $0)) -HVIGOR_WRAPPER_SCRIPT=${HVIGOR_APP_HOME}/hvigor/hvigor-wrapper.js -warn() { - echo "" - echo -e "\033[1;33m`date '+[%Y-%m-%d %H:%M:%S]'`$@\033[0m" -} - -error() { - echo "" - echo -e "\033[1;31m`date '+[%Y-%m-%d %H:%M:%S]'`$@\033[0m" -} - -fail() { - error "$@" - exit 1 -} - -# Determine node to start hvigor wrapper script -if [ -n "${NODE_HOME}" ];then - EXECUTABLE_NODE="${NODE_HOME}/bin/node" - if [ ! -x "$EXECUTABLE_NODE" ];then - fail "ERROR: NODE_HOME is set to an invalid directory,check $NODE_HOME\n\nPlease set NODE_HOME in your environment to the location where your nodejs installed" - fi -else - EXECUTABLE_NODE="node" - which ${EXECUTABLE_NODE} > /dev/null 2>&1 || fail "ERROR: NODE_HOME is not set and not 'node' command found in your path" -fi - -# Check hvigor wrapper script -if [ ! -r "$HVIGOR_WRAPPER_SCRIPT" ];then - fail "ERROR: Couldn't find hvigor/hvigor-wrapper.js in ${HVIGOR_APP_HOME}" -fi - -# start hvigor-wrapper script -exec "${EXECUTABLE_NODE}" \ - "${HVIGOR_WRAPPER_SCRIPT}" "$@" diff --git a/storage/storagefileioerrorjstest/hvigorw.bat b/storage/storagefileioerrorjstest/hvigorw.bat deleted file mode 100644 index a9cc1302dc821de7f9f82c3327673a730945ec7d..0000000000000000000000000000000000000000 --- a/storage/storagefileioerrorjstest/hvigorw.bat +++ /dev/null @@ -1,70 +0,0 @@ -@rem Copyright (C) 2023 Huawei Device Co., Ltd. -@rem Licensed under the Apache License, Version 2.0 (the "License"); -@rem you may not use this file except in compliance with the License. -@rem You may obtain a copy of the License at -@rem -@rem http://www.apache.org/licenses/LICENSE-2.0 -@rem -@rem Unless required by applicable law or agreed to in writing, software -@rem distributed under the License is distributed on an "AS IS" BASIS, -@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -@rem See the License for the specific language governing permissions and -@rem limitations under the License. - -@if "%DEBUG%" == "" @echo off -@rem ########################################################################## -@rem -@rem Hvigor startup script for Windows -@rem -@rem ########################################################################## - -@rem Set local scope for the variables with windows NT shell -if "%OS%"=="Windows_NT" setlocal - -set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. -set APP_BASE_NAME=%~n0 -set APP_HOME=%DIRNAME% - -@rem Resolve any "." and ".." in APP_HOME to make it shorter. -for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi - -set WRAPPER_MODULE_PATH=%APP_HOME%\hvigor\hvigor-wrapper.js -set NODE_EXE=node.exe - -goto start - -:start -@rem Find node.exe -if defined NODE_HOME goto findNodeFromNodeHome - -%NODE_EXE% --version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto execute - -echo. -echo ERROR: NODE_HOME is not set and no 'node' command could be found in your PATH. -echo. -echo Please set the NODE_HOME variable in your environment to match the -echo location of your NodeJs installation. - -goto fail - -:findNodeFromNodeHome -set NODE_HOME=%NODE_HOME:"=% -set NODE_EXE_PATH=%NODE_HOME%/%NODE_EXE% - -if exist "%NODE_EXE_PATH%" goto execute -echo. -echo ERROR: NODE_HOME is not set and no 'node' command could be found in your PATH. -echo. -echo Please set the NODE_HOME variable in your environment to match the -echo location of your NodeJs installation. - -goto fail - -:execute -@rem Execute hvigor -"%NODE_EXE%" %WRAPPER_MODULE_PATH% %* - -:fail -exit /b 1 diff --git a/storage/storagefileioerrorjstest/oh-package.json5 b/storage/storagefileioerrorjstest/oh-package.json5 deleted file mode 100644 index 1a98aac1810691829d1f9908395de4863cb0623d..0000000000000000000000000000000000000000 --- a/storage/storagefileioerrorjstest/oh-package.json5 +++ /dev/null @@ -1,26 +0,0 @@ -/** - * Copyright (c) 2023 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. - */ -{ - "license": "", - "devDependencies": { - "@ohos/hypium": "1.0.6" - }, - "author": "", - "name": "myapplication454434", - "description": "Please describe the basic information.", - "main": "", - "version": "1.0.0", - "dependencies": {} -} diff --git a/storage/storagefileioerrorjstest/src/main/config.json b/storage/storagefileioerrorjstest/src/main/config.json new file mode 100644 index 0000000000000000000000000000000000000000..175382cfd790aa34fe21e9d302784477fd71e4ff --- /dev/null +++ b/storage/storagefileioerrorjstest/src/main/config.json @@ -0,0 +1,96 @@ +{ + "app": { + "bundleName": "ohos.acts.storage.fileioerror", + "vendor": "example", + "version": { + "code": 1000000, + "name": "1.0.0" + }, + "apiVersion": { + "compatible": 4, + "target": 5 + } + }, + "deviceConfig": {}, + "module": { + "package": "ohos.acts.storage.fileioerror", + "name": ".entry", + "deviceType": [ + "tablet", + "default", + "phone" + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "entry", + "moduleType": "entry", + "installationFree": true + }, + "abilities": [ + { + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ], + "orientation": "unspecified", + "formsEnabled": false, + "name": ".MainAbility", + "srcLanguage": "js", + "srcPath": "MainAbility", + "icon": "$media:icon", + "description": "$string:MainAbility_desc", + "label": "$string:MainAbility_label", + "type": "page", + "visible": true, + "launchType": "standard" + }, + { + "orientation": "unspecified", + "formsEnabled": false, + "name": ".TestAbility", + "srcLanguage": "js", + "srcPath": "TestAbility", + "icon": "$media:icon", + "description": "$string:TestAbility_desc", + "label": "$string:TestAbility_label", + "type": "page", + "visible": true, + "launchType": "standard" + } + ], + "js": [ + { + "pages": [ + "pages/index/index" + ], + "name": "default", + "window": { + "designWidth": 720, + "autoDesignWidth": false + } + }, + { + "pages": [ + "pages/index/index" + ], + "name": ".TestAbility", + "window": { + "designWidth": 720, + "autoDesignWidth": false + } + } + ], + "testRunner": { + "name": "OpenHarmonyTestRunner", + "srcPath": "TestRunner" + }, + "mainAbility": ".MainAbility", + "srcPath": "" + } +} \ No newline at end of file diff --git a/storage/storagefileioerrorjstest/entry/src/main/js/MainAbility/pages/index/index.js b/storage/storagefileioerrorjstest/src/main/js/MainAbility/app.js similarity index 70% rename from storage/storagefileioerrorjstest/entry/src/main/js/MainAbility/pages/index/index.js rename to storage/storagefileioerrorjstest/src/main/js/MainAbility/app.js index f086298302bd6362b079bf99cf40dfa1e00d85e9..60ee141c8dbd251c763b7b74552b5a133a774d6a 100644 --- a/storage/storagefileioerrorjstest/entry/src/main/js/MainAbility/pages/index/index.js +++ b/storage/storagefileioerrorjstest/src/main/js/MainAbility/app.js @@ -1,22 +1,23 @@ -/** - * Copyright (c) 2023 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. - */ -export default { - data: { - title: "" - }, - onInit() { - this.title = this.$t('strings.world'); - } -} +/* + * Copyright (C) 2021 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. + */ + +export default { + onCreate() { + console.info('ohos.acts.distributeddatamgr.distributedfile onCreate'); + }, + onDestroy() { + console.info('ohos.acts.distributeddatamgr.distributedfile onCreate'); + } +}; diff --git a/storage/storagefileioerrorjstest/entry/src/main/js/MainAbility/i18n/en-US.json b/storage/storagefileioerrorjstest/src/main/js/MainAbility/i18n/en-US.json similarity index 61% rename from storage/storagefileioerrorjstest/entry/src/main/js/MainAbility/i18n/en-US.json rename to storage/storagefileioerrorjstest/src/main/js/MainAbility/i18n/en-US.json index a4c13dcbdc39c537073f638393d7726ac9a5cdc4..ead52ed2e09ec82aaf7aa9f4e714ed39ea88308e 100644 --- a/storage/storagefileioerrorjstest/entry/src/main/js/MainAbility/i18n/en-US.json +++ b/storage/storagefileioerrorjstest/src/main/js/MainAbility/i18n/en-US.json @@ -1,6 +1,6 @@ -{ - "strings": { - "hello": "Hello", - "world": "World" - } +{ + "strings": { + "hello": "Hello", + "world": "Test" + } } \ No newline at end of file diff --git a/storage/storagefileiojstest/entry/src/main/js/MainAbility/i18n/zh-CN.json b/storage/storagefileioerrorjstest/src/main/js/MainAbility/i18n/zh-CN.json similarity index 61% rename from storage/storagefileiojstest/entry/src/main/js/MainAbility/i18n/zh-CN.json rename to storage/storagefileioerrorjstest/src/main/js/MainAbility/i18n/zh-CN.json index b1c02368f72f929e4375a43170444de95dcc5984..3f48f2585b24a8fe4a745e8ee2972a9e991a7803 100644 --- a/storage/storagefileiojstest/entry/src/main/js/MainAbility/i18n/zh-CN.json +++ b/storage/storagefileioerrorjstest/src/main/js/MainAbility/i18n/zh-CN.json @@ -1,6 +1,6 @@ -{ - "strings": { - "hello": "您好", - "world": "世界" - } +{ + "strings": { + "hello": "您好", + "world": "测试" + } } \ No newline at end of file diff --git a/storage/storagefileioerrorjstest/src/main/js/MainAbility/pages/index/index.css b/storage/storagefileioerrorjstest/src/main/js/MainAbility/pages/index/index.css new file mode 100644 index 0000000000000000000000000000000000000000..6fda792753f2e15f22b529c7b90a82185b2770bf --- /dev/null +++ b/storage/storagefileioerrorjstest/src/main/js/MainAbility/pages/index/index.css @@ -0,0 +1,9 @@ +.container { + flex-direction: column; + justify-content: center; + align-items: center; +} + +.title { + font-size: 100px; +} diff --git a/storage/storagefileioerrorjstest/entry/src/ohosTest/js/TestAbility/pages/index/index.hml b/storage/storagefileioerrorjstest/src/main/js/MainAbility/pages/index/index.hml similarity index 100% rename from storage/storagefileioerrorjstest/entry/src/ohosTest/js/TestAbility/pages/index/index.hml rename to storage/storagefileioerrorjstest/src/main/js/MainAbility/pages/index/index.hml diff --git a/storage/storagefileiojstest/entry/src/main/js/MainAbility/app.js b/storage/storagefileioerrorjstest/src/main/js/MainAbility/pages/index/index.js similarity index 59% rename from storage/storagefileiojstest/entry/src/main/js/MainAbility/app.js rename to storage/storagefileioerrorjstest/src/main/js/MainAbility/pages/index/index.js index 8c9a4fce93b5e76779bdf446c49269a5a51db98a..4df0bbc73cf1a507dd28af650ba2c5d76ace16e3 100644 --- a/storage/storagefileiojstest/entry/src/main/js/MainAbility/app.js +++ b/storage/storagefileioerrorjstest/src/main/js/MainAbility/pages/index/index.js @@ -1,5 +1,5 @@ -/** - * Copyright (c) 2023 Huawei Device Co., Ltd. +/* + * Copyright (C) 2021 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 @@ -12,15 +12,23 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import hilog from '@ohos.hilog'; -export default { - onCreate() { - hilog.info(0x0000, 'testTag', '%{public}s', 'Application onCreate'); - }, - onDestroy() { - hilog.info(0x0000, 'testTag', '%{public}s', 'Application onDestroy'); - }, -} + +import app from '@system.app' +const injectRef = Object.getPrototypeOf(global) || global +injectRef.regeneratorRuntime = require('@babel/runtime/regenerator') +export default { + data: { + title: '' + }, + onInit() { + this.title = this.$t('strings.world'); + }, + onShow() { + console.info('onShow finish') + }, + onReady() { + }, +} \ No newline at end of file diff --git a/storage/storagefileioerrorjstest/entry/src/ohosTest/js/TestAbility/app.js b/storage/storagefileioerrorjstest/src/main/js/TestAbility/app.js similarity index 62% rename from storage/storagefileioerrorjstest/entry/src/ohosTest/js/TestAbility/app.js rename to storage/storagefileioerrorjstest/src/main/js/TestAbility/app.js index 469c4f1380182e0dccb04f17eb95d9b503a56d29..cdc31f3dcf031e2f6a7665d9653e53bb649e21c5 100644 --- a/storage/storagefileioerrorjstest/entry/src/ohosTest/js/TestAbility/app.js +++ b/storage/storagefileioerrorjstest/src/main/js/TestAbility/app.js @@ -1,5 +1,5 @@ -/** - * Copyright (c) 2023 Huawei Device Co., Ltd. +/* + * 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 @@ -12,22 +12,20 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import hilog from '@ohos.hilog'; -import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry'; -import { Hypium } from '@ohos/hypium'; -import testsuite from '../test/List.test'; + +import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry' +import { Hypium } from '@ohos/hypium' +import testsuite from '../test/List.test' export default { onCreate() { - hilog.info(0x0000, 'testTag', '%{public}s', 'TestApplication onCreate'); + console.info('TestApplication onCreate') var abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() var abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() - hilog.info(0x0000, 'testTag', '%{public}s', 'start run testcase!!!'); + console.info('start run testcase!!!') Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite) }, onDestroy() { - hilog.info(0x0000, 'testTag', '%{public}s', 'TestApplication onDestroy'); + console.info("TestApplication onDestroy"); } }; - - diff --git a/storage/storagefileiojstest/entry/src/ohosTest/js/TestAbility/i18n/en-US.json b/storage/storagefileioerrorjstest/src/main/js/TestAbility/i18n/en-US.json similarity index 100% rename from storage/storagefileiojstest/entry/src/ohosTest/js/TestAbility/i18n/en-US.json rename to storage/storagefileioerrorjstest/src/main/js/TestAbility/i18n/en-US.json diff --git a/storage/storagefileiojstest/entry/src/ohosTest/js/TestAbility/i18n/zh-CN.json b/storage/storagefileioerrorjstest/src/main/js/TestAbility/i18n/zh-CN.json similarity index 100% rename from storage/storagefileiojstest/entry/src/ohosTest/js/TestAbility/i18n/zh-CN.json rename to storage/storagefileioerrorjstest/src/main/js/TestAbility/i18n/zh-CN.json diff --git a/storage/storagefileioerrorjstest/entry/src/ohosTest/js/TestAbility/pages/index/index.css b/storage/storagefileioerrorjstest/src/main/js/TestAbility/pages/index/index.css similarity index 100% rename from storage/storagefileioerrorjstest/entry/src/ohosTest/js/TestAbility/pages/index/index.css rename to storage/storagefileioerrorjstest/src/main/js/TestAbility/pages/index/index.css diff --git a/storage/storagefileiojstest/entry/src/ohosTest/js/TestAbility/pages/index/index.hml b/storage/storagefileioerrorjstest/src/main/js/TestAbility/pages/index/index.hml similarity index 100% rename from storage/storagefileiojstest/entry/src/ohosTest/js/TestAbility/pages/index/index.hml rename to storage/storagefileioerrorjstest/src/main/js/TestAbility/pages/index/index.hml diff --git a/storage/storagefileiojstest/entry/src/ohosTest/js/TestAbility/pages/index/index.js b/storage/storagefileioerrorjstest/src/main/js/TestAbility/pages/index/index.js similarity index 90% rename from storage/storagefileiojstest/entry/src/ohosTest/js/TestAbility/pages/index/index.js rename to storage/storagefileioerrorjstest/src/main/js/TestAbility/pages/index/index.js index 8a238972a7b1d40b723b9c38fafc56a83bb294d9..88b083a7f6b979019d6a2c5ad20b19c5fd43286b 100644 --- a/storage/storagefileiojstest/entry/src/ohosTest/js/TestAbility/pages/index/index.js +++ b/storage/storagefileioerrorjstest/src/main/js/TestAbility/pages/index/index.js @@ -1,5 +1,5 @@ -/** - * Copyright (c) 2023 Huawei Device Co., Ltd. +/* + * 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 diff --git a/storage/storagefileiojstest/entry/src/ohosTest/js/TestRunner/OpenHarmonyTestRunner.js b/storage/storagefileioerrorjstest/src/main/js/TestRunner/OpenHarmonyTestRunner.js similarity index 51% rename from storage/storagefileiojstest/entry/src/ohosTest/js/TestRunner/OpenHarmonyTestRunner.js rename to storage/storagefileioerrorjstest/src/main/js/TestRunner/OpenHarmonyTestRunner.js index 03ccc5b691574b1d5bc46adefc08d9ddfc4a1f5c..c5fa8620ca77d381f20b65a903b833e6e3378c97 100644 --- a/storage/storagefileiojstest/entry/src/ohosTest/js/TestRunner/OpenHarmonyTestRunner.js +++ b/storage/storagefileioerrorjstest/src/main/js/TestRunner/OpenHarmonyTestRunner.js @@ -1,41 +1,59 @@ -/** - * Copyright (c) 2023 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 hilog from '@ohos.hilog'; -import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry'; - - export default { - onPrepare() { - hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner OnPrepare'); - }, - onRun() { - hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner onRun run'); - var abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() - var abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() - - var testAbilityName = abilityDelegatorArguments.parameters['-p'] + '.TestAbility' - var cmd = 'aa start -d 0 -a ' + testAbilityName + ' -b ' + abilityDelegatorArguments.bundleName - var debug = abilityDelegatorArguments.parameters["-D"] - if (debug == 'true') - { - cmd += ' -D' - } - hilog.info(0x0000, 'testTag', 'cmd : %{public}s', cmd); - abilityDelegator.executeShellCommand(cmd, (err, data) => { - hilog.info(0x0000, 'testTag', 'executeShellCommand : err : %{public}s', JSON.stringify(err) ?? ''); - hilog.info(0x0000, 'testTag', 'executeShellCommand : data : %{public}s', data.stdResult ?? ''); - hilog.info(0x0000, 'testTag', 'executeShellCommand : data : %{public}s', data.exitCode ?? ''); - }) - } -}; \ No newline at end of file +/* + * 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. + */ + +import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry' + +function translateParamsToString(parameters) { + const keySet = new Set([ + '-s class', '-s notClass', '-s suite', '-s itName', + '-s level', '-s testType', '-s size', '-s timeout', + '-s package', '-s dryRun' + ]) + let targetParams = ''; + for (const key in parameters) { + if (keySet.has(key)) { + targetParams += ' ' + key + ' ' + parameters[key] + } + } + return targetParams.trim() +} + + export default { + onPrepare() { + console.info('OpenHarmonyTestRunner OnPrepare') + }, + onRun() { + console.log('OpenHarmonyTestRunner onRun run') + var abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() + var abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() + + var testAbilityName = abilityDelegatorArguments.parameters['-p'] + '.TestAbility' + + var cmd = 'aa start -d 0 -a ' + testAbilityName + ' -b ' + abilityDelegatorArguments.bundleName + cmd += ' ' + translateParamsToString(abilityDelegatorArguments.parameters) + var debug = abilityDelegatorArguments.parameters["-D"] + console.info('debug value : '+debug) + if (debug == 'true') + { + cmd += ' -D' + } + console.info('cmd : '+cmd) + abilityDelegator.executeShellCommand(cmd, (err, data) => { + console.info('executeShellCommand : err : ' + JSON.stringify(err)); + console.info('executeShellCommand : data : ' + data.stdResult); + console.info('executeShellCommand : data : ' + data.exitCode); + }) + } +}; diff --git a/storage/storagefileioerrorjstest/entry/src/ohosTest/js/test/Common.js b/storage/storagefileioerrorjstest/src/main/js/test/Common.js similarity index 86% rename from storage/storagefileioerrorjstest/entry/src/ohosTest/js/test/Common.js rename to storage/storagefileioerrorjstest/src/main/js/test/Common.js index 6dd8ec0ba16bc48074191aabfb9cc6a080d473a8..d8b4fe782fc1f50cfcaa0e47f484f58dd4ef9df5 100644 --- a/storage/storagefileioerrorjstest/entry/src/ohosTest/js/test/Common.js +++ b/storage/storagefileioerrorjstest/src/main/js/test/Common.js @@ -1,13 +1,13 @@ -/** - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); +/* + * Copyright (C) 2021 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, + * 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. diff --git a/storage/storagefileioerrorjstest/entry/src/ohosTest/js/test/FileIOError.test.js b/storage/storagefileioerrorjstest/src/main/js/test/FileIOError.test.js similarity index 93% rename from storage/storagefileioerrorjstest/entry/src/ohosTest/js/test/FileIOError.test.js rename to storage/storagefileioerrorjstest/src/main/js/test/FileIOError.test.js index ffbd76886abc8a35d56600a115e3896c810fdfdc..e0b6dad8596f57677cdf2c41e2b61b7223d5bd38 100644 --- a/storage/storagefileioerrorjstest/entry/src/ohosTest/js/test/FileIOError.test.js +++ b/storage/storagefileioerrorjstest/src/main/js/test/FileIOError.test.js @@ -1,13 +1,13 @@ -/** - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); +/* + * Copyright (C) 2021 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, + * 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. diff --git a/storage/storagefileioerrorjstest/entry/src/ohosTest/js/test/List.test.js b/storage/storagefileioerrorjstest/src/main/js/test/List.test.js similarity index 90% rename from storage/storagefileioerrorjstest/entry/src/ohosTest/js/test/List.test.js rename to storage/storagefileioerrorjstest/src/main/js/test/List.test.js index 4c58014fbeefa42634c84830dfa794449725b197..665ffda956aef7ab97eefaec1b57ab11bdb0604b 100644 --- a/storage/storagefileioerrorjstest/entry/src/ohosTest/js/test/List.test.js +++ b/storage/storagefileioerrorjstest/src/main/js/test/List.test.js @@ -1,5 +1,5 @@ -/** - * Copyright (c) 2023 Huawei Device Co., Ltd. +/* + * Copyright (C) 2021 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/storage/storagefileioerrorjstest/entry/src/main/resources/base/element/string.json b/storage/storagefileioerrorjstest/src/main/resources/base/element/string.json similarity index 100% rename from storage/storagefileioerrorjstest/entry/src/main/resources/base/element/string.json rename to storage/storagefileioerrorjstest/src/main/resources/base/element/string.json diff --git a/storage/storagefileioerrorjstest/entry/src/main/resources/base/media/icon.png b/storage/storagefileioerrorjstest/src/main/resources/base/media/icon.png similarity index 100% rename from storage/storagefileioerrorjstest/entry/src/main/resources/base/media/icon.png rename to storage/storagefileioerrorjstest/src/main/resources/base/media/icon.png diff --git a/storage/storagefileiojstest/BUILD.gn b/storage/storagefileiojstest/BUILD.gn index 4637eb2f467ba69ae32cf3c7f9ea7803dca2957b..5202a26dc379e57679edefb3c38c25e88883dd7e 100644 --- a/storage/storagefileiojstest/BUILD.gn +++ b/storage/storagefileiojstest/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (C) 2023 Huawei Device Co., Ltd. +# Copyright (C) 2021 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 @@ -13,11 +13,23 @@ import("//test/xts/tools/build/suite.gni") -ohos_js_app_suite("storagefileio_js_test") { - test_hap = true - testonly = true +ohos_js_hap_suite("storagefileio_js_test") { + hap_profile = "./src/main/config.json" + deps = [ + ":storagefileio_js_assets", + ":storagefileio_js_resources", + ] + certificate_profile = "./signature/openharmony_sx.p7b" hap_name = "ActsStorageFileIoJSTest" subsystem_name = "filemanagement" part_name = "file_api" - certificate_profile = "./signature/openharmony_sx.p7b" +} +ohos_js_assets("storagefileio_js_assets") { + js2abc = true + hap_profile = "./src/main/config.json" + source_dir = "./src/main/js" +} +ohos_resources("storagefileio_js_resources") { + sources = [ "./src/main/resources" ] + hap_profile = "./src/main/config.json" } diff --git a/storage/storagefileiojstest/Test.json b/storage/storagefileiojstest/Test.json index b33687052918997eaf6c914546dac74acb1f8760..b0a0edc17c4ae32b7e47522f0e78a1a1567f738b 100644 --- a/storage/storagefileiojstest/Test.json +++ b/storage/storagefileiojstest/Test.json @@ -1,17 +1,17 @@ -{ - "description": "Configuration for storage fileio Tests", - "driver": { - "type": "OHJSUnitTest", - "test-timeout": "600000", - "shell-timeout": "600000", - "bundle-name": "ohos.acts.storage.fileio", - "package-name": "ohos.acts.storage.fileio_test" - }, - "kits": [ - { - "test-file-name": ["ActsStorageFileIoJSTest.hap"], - "type": "AppInstallKit", - "cleanup-apps": true - } - ] +{ + "description": "Configuration for storage fileio Tests", + "driver": { + "type": "OHJSUnitTest", + "test-timeout": "600000", + "shell-timeout": "600000", + "bundle-name": "ohos.acts.storage.fileio", + "package-name": "ohos.acts.storage.fileio" + }, + "kits": [ + { + "test-file-name": ["ActsStorageFileIoJSTest.hap"], + "type": "AppInstallKit", + "cleanup-apps": true + } + ] } \ No newline at end of file diff --git a/storage/storagefileiojstest/build-profile.json5 b/storage/storagefileiojstest/build-profile.json5 deleted file mode 100644 index 7715cddc0112e0e0c8e40623b77ff67b82731829..0000000000000000000000000000000000000000 --- a/storage/storagefileiojstest/build-profile.json5 +++ /dev/null @@ -1,42 +0,0 @@ -/** - * Copyright (c) 2023 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. - */ -{ - "app": { - "signingConfigs": [ - ], - "compileSdkVersion": 10, - "compatibleSdkVersion": 10, - "products": [ - { - "name": "default", - "signingConfig": "default" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] -} \ No newline at end of file diff --git a/storage/storagefileiojstest/entry/build-profile.json5 b/storage/storagefileiojstest/entry/build-profile.json5 deleted file mode 100644 index a6a17e6971173aacea7b75d9ae897a80d335dc0b..0000000000000000000000000000000000000000 --- a/storage/storagefileiojstest/entry/build-profile.json5 +++ /dev/null @@ -1,27 +0,0 @@ -/** - * Copyright (c) 2023 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. - */ -{ - "apiType": 'faMode', - "buildOption": { - }, - "targets": [ - { - "name": "default", - }, - { - "name": "ohosTest", - } - ] -} \ No newline at end of file diff --git a/storage/storagefileiojstest/entry/hvigorfile.ts b/storage/storagefileiojstest/entry/hvigorfile.ts deleted file mode 100644 index 89d831db3f5a6431ef4f9078128ad61b6ae36c48..0000000000000000000000000000000000000000 --- a/storage/storagefileiojstest/entry/hvigorfile.ts +++ /dev/null @@ -1,16 +0,0 @@ -/** - * Copyright (c) 2023 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. - */ -// Script for compiling build behavior. It is built in the build plug-in and cannot be modified currently. -export { legacyHapTasks } from '@ohos/hvigor-ohos-plugin'; diff --git a/storage/storagefileiojstest/entry/oh-package.json5 b/storage/storagefileiojstest/entry/oh-package.json5 deleted file mode 100644 index 75ca1d70feb1c490379299fe342058a2a7183388..0000000000000000000000000000000000000000 --- a/storage/storagefileiojstest/entry/oh-package.json5 +++ /dev/null @@ -1,24 +0,0 @@ -/** - * Copyright (c) 2023 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. - */ -{ - "license": "", - "devDependencies": {}, - "author": "", - "name": "entry", - "description": "Please describe the basic information.", - "main": "", - "version": "1.0.0", - "dependencies": {} -} diff --git a/storage/storagefileiojstest/entry/src/main/config.json b/storage/storagefileiojstest/entry/src/main/config.json deleted file mode 100644 index 2cc6aa89a06b90beae2bd19c3d474c57ae47420e..0000000000000000000000000000000000000000 --- a/storage/storagefileiojstest/entry/src/main/config.json +++ /dev/null @@ -1,65 +0,0 @@ -{ - "app":{ - "bundleName":"ohos.acts.storage.fileio", - "vendor":"example", - "version":{ - "code":1000000, - "name":"1.0.0" - } - }, - "deviceConfig":{ - - }, - "module":{ - "package":"ohos.acts.storage.fileio", - "name":".entry", - "mainAbility":".MainAbility", - "deviceType": [ - "tablet", - "default" - ], - "distro":{ - "deliveryWithInstall":true, - "installationFree":true, - "moduleName":"entry", - "moduleType":"entry" - }, - "abilities":[ - { - "description":"$string:MainAbility_desc", - "formsEnabled":false, - "icon":"$media:icon", - "label":"$string:MainAbility_label", - "launchType":"standard", - "name":".MainAbility", - "orientation":"unspecified", - "skills":[ - { - "actions":[ - "action.system.home" - ], - "entities":[ - "entity.system.home" - ] - } - ], - "srcLanguage":"js", - "srcPath":"MainAbility", - "type":"page", - "visible":true - } - ], - "js":[ - { - "name":".MainAbility", - "pages":[ - "pages/index/index" - ], - "window":{ - "autoDesignWidth":false, - "designWidth":720 - } - } - ] - } -} \ No newline at end of file diff --git a/storage/storagefileiojstest/entry/src/main/js/MainAbility/pages/index/index.css b/storage/storagefileiojstest/entry/src/main/js/MainAbility/pages/index/index.css deleted file mode 100644 index a711febae0b34889547cd72fbe5f8cc3e0bd043c..0000000000000000000000000000000000000000 --- a/storage/storagefileiojstest/entry/src/main/js/MainAbility/pages/index/index.css +++ /dev/null @@ -1,60 +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. - */ -.container { - flex-direction: column; - justify-content: center; - align-items: center; - width: 100%; - height: 100%; -} - -.title { - font-size: 40px; - color: #000000; - opacity: 0.9; -} - -@media screen and (device-type: tablet) and (orientation: landscape) { - .title { - font-size: 100px; - } -} - -@media screen and (device-type: wearable) { - .title { - font-size: 28px; - color: #FFFFFF; - } -} - -@media screen and (device-type: tv) { - .container { - background-image: url("/common/images/Wallpaper.png"); - background-size: cover; - background-repeat: no-repeat; - background-position: center; - } - - .title { - font-size: 100px; - color: #FFFFFF; - } -} - -@media screen and (device-type: phone) and (orientation: landscape) { - .title { - font-size: 60px; - } -} diff --git a/storage/storagefileiojstest/entry/src/main/js/MainAbility/pages/index/index.hml b/storage/storagefileiojstest/entry/src/main/js/MainAbility/pages/index/index.hml deleted file mode 100644 index 95bd1e877b3fa9f5f4e4dc0ff608591b540d116d..0000000000000000000000000000000000000000 --- a/storage/storagefileiojstest/entry/src/main/js/MainAbility/pages/index/index.hml +++ /dev/null @@ -1,19 +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. - */ -
- - {{ $t('strings.hello') }} {{ title }} - -
diff --git a/storage/storagefileiojstest/entry/src/main/resources/base/media/icon.png b/storage/storagefileiojstest/entry/src/main/resources/base/media/icon.png deleted file mode 100644 index ce307a8827bd75456441ceb57d530e4c8d45d36c..0000000000000000000000000000000000000000 Binary files a/storage/storagefileiojstest/entry/src/main/resources/base/media/icon.png and /dev/null differ diff --git a/storage/storagefileiojstest/entry/src/ohosTest/config.json b/storage/storagefileiojstest/entry/src/ohosTest/config.json deleted file mode 100644 index db2f4233d66973c6cae90391b7aa7cf38a51575a..0000000000000000000000000000000000000000 --- a/storage/storagefileiojstest/entry/src/ohosTest/config.json +++ /dev/null @@ -1,69 +0,0 @@ -{ - "app":{ - "bundleName":"ohos.acts.storage.fileio", - "vendor":"example", - "version":{ - "code":1000000, - "name":"1.0.0" - } - }, - "deviceConfig":{ - - }, - "module":{ - "package":"ohos.acts.storage.fileio_test", - "name":".entry_test", - "mainAbility":".TestAbility", - "deviceType": [ - "tablet", - "default" - ], - "testRunner":{ - "name":"OpenHarmonyTestRunner", - "srcPath":"TestRunner" - }, - "distro":{ - "deliveryWithInstall":true, - "installationFree":true, - "moduleName":"entry_test", - "moduleType":"feature" - }, - "abilities":[ - { - "description":"$string:TestAbility_desc", - "formsEnabled":false, - "icon":"$media:icon", - "label":"$string:TestAbility_label", - "launchType":"standard", - "name":".TestAbility", - "orientation":"unspecified", - "skills":[ - { - "actions":[ - "action.system.home" - ], - "entities":[ - "entity.system.home" - ] - } - ], - "srcLanguage":"js", - "srcPath":"TestAbility", - "type":"page", - "visible":true - } - ], - "js":[ - { - "name":".TestAbility", - "pages":[ - "pages/index/index" - ], - "window":{ - "autoDesignWidth":false, - "designWidth":720 - } - } - ] - } -} \ No newline at end of file diff --git a/storage/storagefileiojstest/entry/src/ohosTest/resources/base/element/string.json b/storage/storagefileiojstest/entry/src/ohosTest/resources/base/element/string.json deleted file mode 100644 index b3bdc98af5bc1ce516cfd0a8780ecfb80db93154..0000000000000000000000000000000000000000 --- a/storage/storagefileiojstest/entry/src/ohosTest/resources/base/element/string.json +++ /dev/null @@ -1,28 +0,0 @@ -{ - "string": [ - { - "name": "app_name", - "value": "storagefileiojstest" - }, - { - "name": "mainability_description", - "value": "JS_Phone_Empty Feature Ability" - }, - { - "name": "MainAbility_desc", - "value": "description" - }, - { - "name": "MainAbility_label", - "value": "label" - }, - { - "name": "TestAbility_desc", - "value": "description" - }, - { - "name": "TestAbility_label", - "value": "label" - } - ] -} diff --git a/storage/storagefileiojstest/entry/src/ohosTest/resources/base/media/icon.png b/storage/storagefileiojstest/entry/src/ohosTest/resources/base/media/icon.png deleted file mode 100644 index ce307a8827bd75456441ceb57d530e4c8d45d36c..0000000000000000000000000000000000000000 Binary files a/storage/storagefileiojstest/entry/src/ohosTest/resources/base/media/icon.png and /dev/null differ diff --git a/storage/storagefileiojstest/hvigor/hvigor-config.json5 b/storage/storagefileiojstest/hvigor/hvigor-config.json5 deleted file mode 100644 index d1ed6c3c0cb895265a376515209a0575aeb7d898..0000000000000000000000000000000000000000 --- a/storage/storagefileiojstest/hvigor/hvigor-config.json5 +++ /dev/null @@ -1,20 +0,0 @@ -/** - * Copyright (c) 2023 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. - */ -{ - "hvigorVersion": "2.0.0", - "dependencies": { - "@ohos/hvigor-ohos-plugin": "2.0.0" - } -} diff --git a/storage/storagefileiojstest/hvigor/hvigor-wrapper.js b/storage/storagefileiojstest/hvigor/hvigor-wrapper.js deleted file mode 100644 index 2507619ca768432ff3fb806441f29eff47a4c4f0..0000000000000000000000000000000000000000 --- a/storage/storagefileiojstest/hvigor/hvigor-wrapper.js +++ /dev/null @@ -1,16 +0,0 @@ -/** - * Copyright (c) 2023 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. - */ -"use strict";var e=require("fs"),t=require("path"),n=require("os"),r=require("crypto"),u=require("child_process"),o=require("constants"),i=require("stream"),s=require("util"),c=require("assert"),a=require("tty"),l=require("zlib"),f=require("net");function d(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var D=d(e),p=d(t),E=d(n),m=d(r),h=d(u),y=d(o),C=d(i),F=d(s),g=d(c),A=d(a),v=d(l),S=d(f),w="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},O={},b={},_={},B=w&&w.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(_,"__esModule",{value:!0}),_.isMac=_.isLinux=_.isWindows=void 0;const P=B(E.default),k="Windows_NT",x="Linux",N="Darwin";_.isWindows=function(){return P.default.type()===k},_.isLinux=function(){return P.default.type()===x},_.isMac=function(){return P.default.type()===N};var I={},T=w&&w.__createBinding||(Object.create?function(e,t,n,r){void 0===r&&(r=n);var u=Object.getOwnPropertyDescriptor(t,n);u&&!("get"in u?!t.__esModule:u.writable||u.configurable)||(u={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,r,u)}:function(e,t,n,r){void 0===r&&(r=n),e[r]=t[n]}),R=w&&w.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),M=w&&w.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var n in e)"default"!==n&&Object.prototype.hasOwnProperty.call(e,n)&&T(t,e,n);return R(t,e),t};Object.defineProperty(I,"__esModule",{value:!0}),I.hash=void 0;const L=M(m.default);I.hash=function(e,t="md5"){return L.createHash(t).update(e,"utf-8").digest("hex")},function(e){var t=w&&w.__createBinding||(Object.create?function(e,t,n,r){void 0===r&&(r=n);var u=Object.getOwnPropertyDescriptor(t,n);u&&!("get"in u?!t.__esModule:u.writable||u.configurable)||(u={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,r,u)}:function(e,t,n,r){void 0===r&&(r=n),e[r]=t[n]}),n=w&&w.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),r=w&&w.__importStar||function(e){if(e&&e.__esModule)return e;var r={};if(null!=e)for(var u in e)"default"!==u&&Object.prototype.hasOwnProperty.call(e,u)&&t(r,e,u);return n(r,e),r};Object.defineProperty(e,"__esModule",{value:!0}),e.HVIGOR_BOOT_JS_FILE_PATH=e.HVIGOR_PROJECT_DEPENDENCY_PACKAGE_JSON_PATH=e.HVIGOR_PROJECT_DEPENDENCIES_HOME=e.HVIGOR_PROJECT_WRAPPER_HOME=e.HVIGOR_PROJECT_NAME=e.HVIGOR_PROJECT_ROOT_DIR=e.HVIGOR_PROJECT_CACHES_HOME=e.HVIGOR_PNPM_STORE_PATH=e.HVIGOR_WRAPPER_PNPM_SCRIPT_PATH=e.HVIGOR_WRAPPER_TOOLS_HOME=e.HVIGOR_USER_HOME=e.DEFAULT_PACKAGE_JSON=e.DEFAULT_HVIGOR_CONFIG_JSON_FILE_NAME=e.PNPM=e.HVIGOR=e.NPM_TOOL=e.PNPM_TOOL=e.HVIGOR_ENGINE_PACKAGE_NAME=void 0;const u=r(p.default),o=r(E.default),i=_,s=I;e.HVIGOR_ENGINE_PACKAGE_NAME="@ohos/hvigor",e.PNPM_TOOL=(0,i.isWindows)()?"pnpm.cmd":"pnpm",e.NPM_TOOL=(0,i.isWindows)()?"npm.cmd":"npm",e.HVIGOR="hvigor",e.PNPM="pnpm",e.DEFAULT_HVIGOR_CONFIG_JSON_FILE_NAME="hvigor-config.json5",e.DEFAULT_PACKAGE_JSON="package.json",e.HVIGOR_USER_HOME=u.resolve(o.homedir(),".hvigor"),e.HVIGOR_WRAPPER_TOOLS_HOME=u.resolve(e.HVIGOR_USER_HOME,"wrapper","tools"),e.HVIGOR_WRAPPER_PNPM_SCRIPT_PATH=u.resolve(e.HVIGOR_WRAPPER_TOOLS_HOME,"node_modules",".bin",e.PNPM_TOOL),e.HVIGOR_PNPM_STORE_PATH=u.resolve(e.HVIGOR_USER_HOME,"caches"),e.HVIGOR_PROJECT_CACHES_HOME=u.resolve(e.HVIGOR_USER_HOME,"project_caches"),e.HVIGOR_PROJECT_ROOT_DIR=process.cwd(),e.HVIGOR_PROJECT_NAME=u.basename((0,s.hash)(e.HVIGOR_PROJECT_ROOT_DIR)),e.HVIGOR_PROJECT_WRAPPER_HOME=u.resolve(e.HVIGOR_PROJECT_ROOT_DIR,e.HVIGOR),e.HVIGOR_PROJECT_DEPENDENCIES_HOME=u.resolve(e.HVIGOR_PROJECT_CACHES_HOME,e.HVIGOR_PROJECT_NAME,"workspace"),e.HVIGOR_PROJECT_DEPENDENCY_PACKAGE_JSON_PATH=u.resolve(e.HVIGOR_PROJECT_DEPENDENCIES_HOME,e.DEFAULT_PACKAGE_JSON),e.HVIGOR_BOOT_JS_FILE_PATH=u.resolve(e.HVIGOR_PROJECT_DEPENDENCIES_HOME,"node_modules","@ohos","hvigor","bin","hvigor.js")}(b);var j={},$={};Object.defineProperty($,"__esModule",{value:!0}),$.logInfoPrintConsole=$.logErrorAndExit=void 0,$.logErrorAndExit=function(e){e instanceof Error?console.error(e.message):console.error(e),process.exit(-1)},$.logInfoPrintConsole=function(e){console.log(e)};var H=w&&w.__createBinding||(Object.create?function(e,t,n,r){void 0===r&&(r=n);var u=Object.getOwnPropertyDescriptor(t,n);u&&!("get"in u?!t.__esModule:u.writable||u.configurable)||(u={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,r,u)}:function(e,t,n,r){void 0===r&&(r=n),e[r]=t[n]}),J=w&&w.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),G=w&&w.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var n in e)"default"!==n&&Object.prototype.hasOwnProperty.call(e,n)&&H(t,e,n);return J(t,e),t},V=w&&w.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(j,"__esModule",{value:!0}),j.isFileExists=j.offlinePluginConversion=j.executeCommand=j.getNpmPath=j.hasNpmPackInPaths=void 0;const U=h.default,W=G(p.default),z=b,K=$,q=V(D.default);j.hasNpmPackInPaths=function(e,t){try{return require.resolve(e,{paths:[...t]}),!0}catch(e){return!1}},j.getNpmPath=function(){const e=process.execPath;return W.join(W.dirname(e),z.NPM_TOOL)},j.executeCommand=function(e,t,n){0!==(0,U.spawnSync)(e,t,n).status&&(0,K.logErrorAndExit)(`Error: ${e} ${t} execute failed.See above for details.`)},j.offlinePluginConversion=function(e,t){return t.startsWith("file:")||t.endsWith(".tgz")?W.resolve(e,z.HVIGOR,t.replace("file:","")):t},j.isFileExists=function(e){return q.default.existsSync(e)&&q.default.statSync(e).isFile()},function(e){var t=w&&w.__createBinding||(Object.create?function(e,t,n,r){void 0===r&&(r=n);var u=Object.getOwnPropertyDescriptor(t,n);u&&!("get"in u?!t.__esModule:u.writable||u.configurable)||(u={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,r,u)}:function(e,t,n,r){void 0===r&&(r=n),e[r]=t[n]}),n=w&&w.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),r=w&&w.__importStar||function(e){if(e&&e.__esModule)return e;var r={};if(null!=e)for(var u in e)"default"!==u&&Object.prototype.hasOwnProperty.call(e,u)&&t(r,e,u);return n(r,e),r},u=w&&w.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(e,"__esModule",{value:!0}),e.executeInstallPnpm=e.isPnpmAvailable=e.environmentHandler=e.checkNpmConifg=e.PNPM_VERSION=void 0;const o=r(D.default),i=b,s=j,c=r(p.default),a=$,l=h.default,f=u(E.default);e.PNPM_VERSION="7.30.0",e.checkNpmConifg=function(){const e=c.resolve(i.HVIGOR_PROJECT_ROOT_DIR,".npmrc"),t=c.resolve(f.default.homedir(),".npmrc");if((0,s.isFileExists)(e)||(0,s.isFileExists)(t))return;const n=(0,s.getNpmPath)(),r=(0,l.spawnSync)(n,["config","get","prefix"],{cwd:i.HVIGOR_PROJECT_ROOT_DIR});if(0!==r.status||!r.stdout)return void(0,a.logErrorAndExit)("Error: The hvigor depends on the npmrc file. Configure the npmrc file first.");const u=c.resolve(`${r.stdout}`.replace(/[\r\n]/gi,""),".npmrc");(0,s.isFileExists)(u)||(0,a.logErrorAndExit)("Error: The hvigor depends on the npmrc file. Configure the npmrc file first.")},e.environmentHandler=function(){process.env["npm_config_update-notifier"]="false"},e.isPnpmAvailable=function(){return!!o.existsSync(i.HVIGOR_WRAPPER_PNPM_SCRIPT_PATH)&&(0,s.hasNpmPackInPaths)("pnpm",[i.HVIGOR_WRAPPER_TOOLS_HOME])},e.executeInstallPnpm=function(){(0,a.logInfoPrintConsole)(`Installing pnpm@${e.PNPM_VERSION}...`);const t=(0,s.getNpmPath)();!function(){const t=c.resolve(i.HVIGOR_WRAPPER_TOOLS_HOME,i.DEFAULT_PACKAGE_JSON);try{o.existsSync(i.HVIGOR_WRAPPER_TOOLS_HOME)||o.mkdirSync(i.HVIGOR_WRAPPER_TOOLS_HOME,{recursive:!0});const n={dependencies:{}};n.dependencies[i.PNPM]=e.PNPM_VERSION,o.writeFileSync(t,JSON.stringify(n))}catch(e){(0,a.logErrorAndExit)(`Error: EPERM: operation not permitted,create ${t} failed.`)}}(),(0,s.executeCommand)(t,["install","pnpm"],{cwd:i.HVIGOR_WRAPPER_TOOLS_HOME,stdio:["inherit","inherit","inherit"],env:process.env}),(0,a.logInfoPrintConsole)("Pnpm install success.")}}(O);var Y={},X={},Z={},Q={};Object.defineProperty(Q,"__esModule",{value:!0}),Q.Unicode=void 0;class ee{}Q.Unicode=ee,ee.Space_Separator=/[\u1680\u2000-\u200A\u202F\u205F\u3000]/,ee.ID_Start=/[\xAA\xB5\xBA\xC0-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0370-\u0374\u0376\u0377\u037A-\u037D\u037F\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u048A-\u052F\u0531-\u0556\u0559\u0561-\u0587\u05D0-\u05EA\u05F0-\u05F2\u0620-\u064A\u066E\u066F\u0671-\u06D3\u06D5\u06E5\u06E6\u06EE\u06EF\u06FA-\u06FC\u06FF\u0710\u0712-\u072F\u074D-\u07A5\u07B1\u07CA-\u07EA\u07F4\u07F5\u07FA\u0800-\u0815\u081A\u0824\u0828\u0840-\u0858\u0860-\u086A\u08A0-\u08B4\u08B6-\u08BD\u0904-\u0939\u093D\u0950\u0958-\u0961\u0971-\u0980\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BD\u09CE\u09DC\u09DD\u09DF-\u09E1\u09F0\u09F1\u09FC\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A59-\u0A5C\u0A5E\u0A72-\u0A74\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABD\u0AD0\u0AE0\u0AE1\u0AF9\u0B05-\u0B0C\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3D\u0B5C\u0B5D\u0B5F-\u0B61\u0B71\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BD0\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C39\u0C3D\u0C58-\u0C5A\u0C60\u0C61\u0C80\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBD\u0CDE\u0CE0\u0CE1\u0CF1\u0CF2\u0D05-\u0D0C\u0D0E-\u0D10\u0D12-\u0D3A\u0D3D\u0D4E\u0D54-\u0D56\u0D5F-\u0D61\u0D7A-\u0D7F\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0E01-\u0E30\u0E32\u0E33\u0E40-\u0E46\u0E81\u0E82\u0E84\u0E87\u0E88\u0E8A\u0E8D\u0E94-\u0E97\u0E99-\u0E9F\u0EA1-\u0EA3\u0EA5\u0EA7\u0EAA\u0EAB\u0EAD-\u0EB0\u0EB2\u0EB3\u0EBD\u0EC0-\u0EC4\u0EC6\u0EDC-\u0EDF\u0F00\u0F40-\u0F47\u0F49-\u0F6C\u0F88-\u0F8C\u1000-\u102A\u103F\u1050-\u1055\u105A-\u105D\u1061\u1065\u1066\u106E-\u1070\u1075-\u1081\u108E\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FC-\u1248\u124A-\u124D\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310\u1312-\u1315\u1318-\u135A\u1380-\u138F\u13A0-\u13F5\u13F8-\u13FD\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u16EE-\u16F8\u1700-\u170C\u170E-\u1711\u1720-\u1731\u1740-\u1751\u1760-\u176C\u176E-\u1770\u1780-\u17B3\u17D7\u17DC\u1820-\u1877\u1880-\u1884\u1887-\u18A8\u18AA\u18B0-\u18F5\u1900-\u191E\u1950-\u196D\u1970-\u1974\u1980-\u19AB\u19B0-\u19C9\u1A00-\u1A16\u1A20-\u1A54\u1AA7\u1B05-\u1B33\u1B45-\u1B4B\u1B83-\u1BA0\u1BAE\u1BAF\u1BBA-\u1BE5\u1C00-\u1C23\u1C4D-\u1C4F\u1C5A-\u1C7D\u1C80-\u1C88\u1CE9-\u1CEC\u1CEE-\u1CF1\u1CF5\u1CF6\u1D00-\u1DBF\u1E00-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u2071\u207F\u2090-\u209C\u2102\u2107\u210A-\u2113\u2115\u2119-\u211D\u2124\u2126\u2128\u212A-\u212D\u212F-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2160-\u2188\u2C00-\u2C2E\u2C30-\u2C5E\u2C60-\u2CE4\u2CEB-\u2CEE\u2CF2\u2CF3\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D80-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u2E2F\u3005-\u3007\u3021-\u3029\u3031-\u3035\u3038-\u303C\u3041-\u3096\u309D-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312E\u3131-\u318E\u31A0-\u31BA\u31F0-\u31FF\u3400-\u4DB5\u4E00-\u9FEA\uA000-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA61F\uA62A\uA62B\uA640-\uA66E\uA67F-\uA69D\uA6A0-\uA6EF\uA717-\uA71F\uA722-\uA788\uA78B-\uA7AE\uA7B0-\uA7B7\uA7F7-\uA801\uA803-\uA805\uA807-\uA80A\uA80C-\uA822\uA840-\uA873\uA882-\uA8B3\uA8F2-\uA8F7\uA8FB\uA8FD\uA90A-\uA925\uA930-\uA946\uA960-\uA97C\uA984-\uA9B2\uA9CF\uA9E0-\uA9E4\uA9E6-\uA9EF\uA9FA-\uA9FE\uAA00-\uAA28\uAA40-\uAA42\uAA44-\uAA4B\uAA60-\uAA76\uAA7A\uAA7E-\uAAAF\uAAB1\uAAB5\uAAB6\uAAB9-\uAABD\uAAC0\uAAC2\uAADB-\uAADD\uAAE0-\uAAEA\uAAF2-\uAAF4\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uAB30-\uAB5A\uAB5C-\uAB65\uAB70-\uABE2\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D\uFB1F-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE70-\uFE74\uFE76-\uFEFC\uFF21-\uFF3A\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC]|\uD800[\uDC00-\uDC0B\uDC0D-\uDC26\uDC28-\uDC3A\uDC3C\uDC3D\uDC3F-\uDC4D\uDC50-\uDC5D\uDC80-\uDCFA\uDD40-\uDD74\uDE80-\uDE9C\uDEA0-\uDED0\uDF00-\uDF1F\uDF2D-\uDF4A\uDF50-\uDF75\uDF80-\uDF9D\uDFA0-\uDFC3\uDFC8-\uDFCF\uDFD1-\uDFD5]|\uD801[\uDC00-\uDC9D\uDCB0-\uDCD3\uDCD8-\uDCFB\uDD00-\uDD27\uDD30-\uDD63\uDE00-\uDF36\uDF40-\uDF55\uDF60-\uDF67]|\uD802[\uDC00-\uDC05\uDC08\uDC0A-\uDC35\uDC37\uDC38\uDC3C\uDC3F-\uDC55\uDC60-\uDC76\uDC80-\uDC9E\uDCE0-\uDCF2\uDCF4\uDCF5\uDD00-\uDD15\uDD20-\uDD39\uDD80-\uDDB7\uDDBE\uDDBF\uDE00\uDE10-\uDE13\uDE15-\uDE17\uDE19-\uDE33\uDE60-\uDE7C\uDE80-\uDE9C\uDEC0-\uDEC7\uDEC9-\uDEE4\uDF00-\uDF35\uDF40-\uDF55\uDF60-\uDF72\uDF80-\uDF91]|\uD803[\uDC00-\uDC48\uDC80-\uDCB2\uDCC0-\uDCF2]|\uD804[\uDC03-\uDC37\uDC83-\uDCAF\uDCD0-\uDCE8\uDD03-\uDD26\uDD50-\uDD72\uDD76\uDD83-\uDDB2\uDDC1-\uDDC4\uDDDA\uDDDC\uDE00-\uDE11\uDE13-\uDE2B\uDE80-\uDE86\uDE88\uDE8A-\uDE8D\uDE8F-\uDE9D\uDE9F-\uDEA8\uDEB0-\uDEDE\uDF05-\uDF0C\uDF0F\uDF10\uDF13-\uDF28\uDF2A-\uDF30\uDF32\uDF33\uDF35-\uDF39\uDF3D\uDF50\uDF5D-\uDF61]|\uD805[\uDC00-\uDC34\uDC47-\uDC4A\uDC80-\uDCAF\uDCC4\uDCC5\uDCC7\uDD80-\uDDAE\uDDD8-\uDDDB\uDE00-\uDE2F\uDE44\uDE80-\uDEAA\uDF00-\uDF19]|\uD806[\uDCA0-\uDCDF\uDCFF\uDE00\uDE0B-\uDE32\uDE3A\uDE50\uDE5C-\uDE83\uDE86-\uDE89\uDEC0-\uDEF8]|\uD807[\uDC00-\uDC08\uDC0A-\uDC2E\uDC40\uDC72-\uDC8F\uDD00-\uDD06\uDD08\uDD09\uDD0B-\uDD30\uDD46]|\uD808[\uDC00-\uDF99]|\uD809[\uDC00-\uDC6E\uDC80-\uDD43]|[\uD80C\uD81C-\uD820\uD840-\uD868\uD86A-\uD86C\uD86F-\uD872\uD874-\uD879][\uDC00-\uDFFF]|\uD80D[\uDC00-\uDC2E]|\uD811[\uDC00-\uDE46]|\uD81A[\uDC00-\uDE38\uDE40-\uDE5E\uDED0-\uDEED\uDF00-\uDF2F\uDF40-\uDF43\uDF63-\uDF77\uDF7D-\uDF8F]|\uD81B[\uDF00-\uDF44\uDF50\uDF93-\uDF9F\uDFE0\uDFE1]|\uD821[\uDC00-\uDFEC]|\uD822[\uDC00-\uDEF2]|\uD82C[\uDC00-\uDD1E\uDD70-\uDEFB]|\uD82F[\uDC00-\uDC6A\uDC70-\uDC7C\uDC80-\uDC88\uDC90-\uDC99]|\uD835[\uDC00-\uDC54\uDC56-\uDC9C\uDC9E\uDC9F\uDCA2\uDCA5\uDCA6\uDCA9-\uDCAC\uDCAE-\uDCB9\uDCBB\uDCBD-\uDCC3\uDCC5-\uDD05\uDD07-\uDD0A\uDD0D-\uDD14\uDD16-\uDD1C\uDD1E-\uDD39\uDD3B-\uDD3E\uDD40-\uDD44\uDD46\uDD4A-\uDD50\uDD52-\uDEA5\uDEA8-\uDEC0\uDEC2-\uDEDA\uDEDC-\uDEFA\uDEFC-\uDF14\uDF16-\uDF34\uDF36-\uDF4E\uDF50-\uDF6E\uDF70-\uDF88\uDF8A-\uDFA8\uDFAA-\uDFC2\uDFC4-\uDFCB]|\uD83A[\uDC00-\uDCC4\uDD00-\uDD43]|\uD83B[\uDE00-\uDE03\uDE05-\uDE1F\uDE21\uDE22\uDE24\uDE27\uDE29-\uDE32\uDE34-\uDE37\uDE39\uDE3B\uDE42\uDE47\uDE49\uDE4B\uDE4D-\uDE4F\uDE51\uDE52\uDE54\uDE57\uDE59\uDE5B\uDE5D\uDE5F\uDE61\uDE62\uDE64\uDE67-\uDE6A\uDE6C-\uDE72\uDE74-\uDE77\uDE79-\uDE7C\uDE7E\uDE80-\uDE89\uDE8B-\uDE9B\uDEA1-\uDEA3\uDEA5-\uDEA9\uDEAB-\uDEBB]|\uD869[\uDC00-\uDED6\uDF00-\uDFFF]|\uD86D[\uDC00-\uDF34\uDF40-\uDFFF]|\uD86E[\uDC00-\uDC1D\uDC20-\uDFFF]|\uD873[\uDC00-\uDEA1\uDEB0-\uDFFF]|\uD87A[\uDC00-\uDFE0]|\uD87E[\uDC00-\uDE1D]/,ee.ID_Continue=/[\xAA\xB5\xBA\xC0-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0300-\u0374\u0376\u0377\u037A-\u037D\u037F\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u0483-\u0487\u048A-\u052F\u0531-\u0556\u0559\u0561-\u0587\u0591-\u05BD\u05BF\u05C1\u05C2\u05C4\u05C5\u05C7\u05D0-\u05EA\u05F0-\u05F2\u0610-\u061A\u0620-\u0669\u066E-\u06D3\u06D5-\u06DC\u06DF-\u06E8\u06EA-\u06FC\u06FF\u0710-\u074A\u074D-\u07B1\u07C0-\u07F5\u07FA\u0800-\u082D\u0840-\u085B\u0860-\u086A\u08A0-\u08B4\u08B6-\u08BD\u08D4-\u08E1\u08E3-\u0963\u0966-\u096F\u0971-\u0983\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BC-\u09C4\u09C7\u09C8\u09CB-\u09CE\u09D7\u09DC\u09DD\u09DF-\u09E3\u09E6-\u09F1\u09FC\u0A01-\u0A03\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A3C\u0A3E-\u0A42\u0A47\u0A48\u0A4B-\u0A4D\u0A51\u0A59-\u0A5C\u0A5E\u0A66-\u0A75\u0A81-\u0A83\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABC-\u0AC5\u0AC7-\u0AC9\u0ACB-\u0ACD\u0AD0\u0AE0-\u0AE3\u0AE6-\u0AEF\u0AF9-\u0AFF\u0B01-\u0B03\u0B05-\u0B0C\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3C-\u0B44\u0B47\u0B48\u0B4B-\u0B4D\u0B56\u0B57\u0B5C\u0B5D\u0B5F-\u0B63\u0B66-\u0B6F\u0B71\u0B82\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BBE-\u0BC2\u0BC6-\u0BC8\u0BCA-\u0BCD\u0BD0\u0BD7\u0BE6-\u0BEF\u0C00-\u0C03\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C39\u0C3D-\u0C44\u0C46-\u0C48\u0C4A-\u0C4D\u0C55\u0C56\u0C58-\u0C5A\u0C60-\u0C63\u0C66-\u0C6F\u0C80-\u0C83\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBC-\u0CC4\u0CC6-\u0CC8\u0CCA-\u0CCD\u0CD5\u0CD6\u0CDE\u0CE0-\u0CE3\u0CE6-\u0CEF\u0CF1\u0CF2\u0D00-\u0D03\u0D05-\u0D0C\u0D0E-\u0D10\u0D12-\u0D44\u0D46-\u0D48\u0D4A-\u0D4E\u0D54-\u0D57\u0D5F-\u0D63\u0D66-\u0D6F\u0D7A-\u0D7F\u0D82\u0D83\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0DCA\u0DCF-\u0DD4\u0DD6\u0DD8-\u0DDF\u0DE6-\u0DEF\u0DF2\u0DF3\u0E01-\u0E3A\u0E40-\u0E4E\u0E50-\u0E59\u0E81\u0E82\u0E84\u0E87\u0E88\u0E8A\u0E8D\u0E94-\u0E97\u0E99-\u0E9F\u0EA1-\u0EA3\u0EA5\u0EA7\u0EAA\u0EAB\u0EAD-\u0EB9\u0EBB-\u0EBD\u0EC0-\u0EC4\u0EC6\u0EC8-\u0ECD\u0ED0-\u0ED9\u0EDC-\u0EDF\u0F00\u0F18\u0F19\u0F20-\u0F29\u0F35\u0F37\u0F39\u0F3E-\u0F47\u0F49-\u0F6C\u0F71-\u0F84\u0F86-\u0F97\u0F99-\u0FBC\u0FC6\u1000-\u1049\u1050-\u109D\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FC-\u1248\u124A-\u124D\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310\u1312-\u1315\u1318-\u135A\u135D-\u135F\u1380-\u138F\u13A0-\u13F5\u13F8-\u13FD\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u16EE-\u16F8\u1700-\u170C\u170E-\u1714\u1720-\u1734\u1740-\u1753\u1760-\u176C\u176E-\u1770\u1772\u1773\u1780-\u17D3\u17D7\u17DC\u17DD\u17E0-\u17E9\u180B-\u180D\u1810-\u1819\u1820-\u1877\u1880-\u18AA\u18B0-\u18F5\u1900-\u191E\u1920-\u192B\u1930-\u193B\u1946-\u196D\u1970-\u1974\u1980-\u19AB\u19B0-\u19C9\u19D0-\u19D9\u1A00-\u1A1B\u1A20-\u1A5E\u1A60-\u1A7C\u1A7F-\u1A89\u1A90-\u1A99\u1AA7\u1AB0-\u1ABD\u1B00-\u1B4B\u1B50-\u1B59\u1B6B-\u1B73\u1B80-\u1BF3\u1C00-\u1C37\u1C40-\u1C49\u1C4D-\u1C7D\u1C80-\u1C88\u1CD0-\u1CD2\u1CD4-\u1CF9\u1D00-\u1DF9\u1DFB-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u203F\u2040\u2054\u2071\u207F\u2090-\u209C\u20D0-\u20DC\u20E1\u20E5-\u20F0\u2102\u2107\u210A-\u2113\u2115\u2119-\u211D\u2124\u2126\u2128\u212A-\u212D\u212F-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2160-\u2188\u2C00-\u2C2E\u2C30-\u2C5E\u2C60-\u2CE4\u2CEB-\u2CF3\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D7F-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u2DE0-\u2DFF\u2E2F\u3005-\u3007\u3021-\u302F\u3031-\u3035\u3038-\u303C\u3041-\u3096\u3099\u309A\u309D-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312E\u3131-\u318E\u31A0-\u31BA\u31F0-\u31FF\u3400-\u4DB5\u4E00-\u9FEA\uA000-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA62B\uA640-\uA66F\uA674-\uA67D\uA67F-\uA6F1\uA717-\uA71F\uA722-\uA788\uA78B-\uA7AE\uA7B0-\uA7B7\uA7F7-\uA827\uA840-\uA873\uA880-\uA8C5\uA8D0-\uA8D9\uA8E0-\uA8F7\uA8FB\uA8FD\uA900-\uA92D\uA930-\uA953\uA960-\uA97C\uA980-\uA9C0\uA9CF-\uA9D9\uA9E0-\uA9FE\uAA00-\uAA36\uAA40-\uAA4D\uAA50-\uAA59\uAA60-\uAA76\uAA7A-\uAAC2\uAADB-\uAADD\uAAE0-\uAAEF\uAAF2-\uAAF6\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uAB30-\uAB5A\uAB5C-\uAB65\uAB70-\uABEA\uABEC\uABED\uABF0-\uABF9\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE00-\uFE0F\uFE20-\uFE2F\uFE33\uFE34\uFE4D-\uFE4F\uFE70-\uFE74\uFE76-\uFEFC\uFF10-\uFF19\uFF21-\uFF3A\uFF3F\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC]|\uD800[\uDC00-\uDC0B\uDC0D-\uDC26\uDC28-\uDC3A\uDC3C\uDC3D\uDC3F-\uDC4D\uDC50-\uDC5D\uDC80-\uDCFA\uDD40-\uDD74\uDDFD\uDE80-\uDE9C\uDEA0-\uDED0\uDEE0\uDF00-\uDF1F\uDF2D-\uDF4A\uDF50-\uDF7A\uDF80-\uDF9D\uDFA0-\uDFC3\uDFC8-\uDFCF\uDFD1-\uDFD5]|\uD801[\uDC00-\uDC9D\uDCA0-\uDCA9\uDCB0-\uDCD3\uDCD8-\uDCFB\uDD00-\uDD27\uDD30-\uDD63\uDE00-\uDF36\uDF40-\uDF55\uDF60-\uDF67]|\uD802[\uDC00-\uDC05\uDC08\uDC0A-\uDC35\uDC37\uDC38\uDC3C\uDC3F-\uDC55\uDC60-\uDC76\uDC80-\uDC9E\uDCE0-\uDCF2\uDCF4\uDCF5\uDD00-\uDD15\uDD20-\uDD39\uDD80-\uDDB7\uDDBE\uDDBF\uDE00-\uDE03\uDE05\uDE06\uDE0C-\uDE13\uDE15-\uDE17\uDE19-\uDE33\uDE38-\uDE3A\uDE3F\uDE60-\uDE7C\uDE80-\uDE9C\uDEC0-\uDEC7\uDEC9-\uDEE6\uDF00-\uDF35\uDF40-\uDF55\uDF60-\uDF72\uDF80-\uDF91]|\uD803[\uDC00-\uDC48\uDC80-\uDCB2\uDCC0-\uDCF2]|\uD804[\uDC00-\uDC46\uDC66-\uDC6F\uDC7F-\uDCBA\uDCD0-\uDCE8\uDCF0-\uDCF9\uDD00-\uDD34\uDD36-\uDD3F\uDD50-\uDD73\uDD76\uDD80-\uDDC4\uDDCA-\uDDCC\uDDD0-\uDDDA\uDDDC\uDE00-\uDE11\uDE13-\uDE37\uDE3E\uDE80-\uDE86\uDE88\uDE8A-\uDE8D\uDE8F-\uDE9D\uDE9F-\uDEA8\uDEB0-\uDEEA\uDEF0-\uDEF9\uDF00-\uDF03\uDF05-\uDF0C\uDF0F\uDF10\uDF13-\uDF28\uDF2A-\uDF30\uDF32\uDF33\uDF35-\uDF39\uDF3C-\uDF44\uDF47\uDF48\uDF4B-\uDF4D\uDF50\uDF57\uDF5D-\uDF63\uDF66-\uDF6C\uDF70-\uDF74]|\uD805[\uDC00-\uDC4A\uDC50-\uDC59\uDC80-\uDCC5\uDCC7\uDCD0-\uDCD9\uDD80-\uDDB5\uDDB8-\uDDC0\uDDD8-\uDDDD\uDE00-\uDE40\uDE44\uDE50-\uDE59\uDE80-\uDEB7\uDEC0-\uDEC9\uDF00-\uDF19\uDF1D-\uDF2B\uDF30-\uDF39]|\uD806[\uDCA0-\uDCE9\uDCFF\uDE00-\uDE3E\uDE47\uDE50-\uDE83\uDE86-\uDE99\uDEC0-\uDEF8]|\uD807[\uDC00-\uDC08\uDC0A-\uDC36\uDC38-\uDC40\uDC50-\uDC59\uDC72-\uDC8F\uDC92-\uDCA7\uDCA9-\uDCB6\uDD00-\uDD06\uDD08\uDD09\uDD0B-\uDD36\uDD3A\uDD3C\uDD3D\uDD3F-\uDD47\uDD50-\uDD59]|\uD808[\uDC00-\uDF99]|\uD809[\uDC00-\uDC6E\uDC80-\uDD43]|[\uD80C\uD81C-\uD820\uD840-\uD868\uD86A-\uD86C\uD86F-\uD872\uD874-\uD879][\uDC00-\uDFFF]|\uD80D[\uDC00-\uDC2E]|\uD811[\uDC00-\uDE46]|\uD81A[\uDC00-\uDE38\uDE40-\uDE5E\uDE60-\uDE69\uDED0-\uDEED\uDEF0-\uDEF4\uDF00-\uDF36\uDF40-\uDF43\uDF50-\uDF59\uDF63-\uDF77\uDF7D-\uDF8F]|\uD81B[\uDF00-\uDF44\uDF50-\uDF7E\uDF8F-\uDF9F\uDFE0\uDFE1]|\uD821[\uDC00-\uDFEC]|\uD822[\uDC00-\uDEF2]|\uD82C[\uDC00-\uDD1E\uDD70-\uDEFB]|\uD82F[\uDC00-\uDC6A\uDC70-\uDC7C\uDC80-\uDC88\uDC90-\uDC99\uDC9D\uDC9E]|\uD834[\uDD65-\uDD69\uDD6D-\uDD72\uDD7B-\uDD82\uDD85-\uDD8B\uDDAA-\uDDAD\uDE42-\uDE44]|\uD835[\uDC00-\uDC54\uDC56-\uDC9C\uDC9E\uDC9F\uDCA2\uDCA5\uDCA6\uDCA9-\uDCAC\uDCAE-\uDCB9\uDCBB\uDCBD-\uDCC3\uDCC5-\uDD05\uDD07-\uDD0A\uDD0D-\uDD14\uDD16-\uDD1C\uDD1E-\uDD39\uDD3B-\uDD3E\uDD40-\uDD44\uDD46\uDD4A-\uDD50\uDD52-\uDEA5\uDEA8-\uDEC0\uDEC2-\uDEDA\uDEDC-\uDEFA\uDEFC-\uDF14\uDF16-\uDF34\uDF36-\uDF4E\uDF50-\uDF6E\uDF70-\uDF88\uDF8A-\uDFA8\uDFAA-\uDFC2\uDFC4-\uDFCB\uDFCE-\uDFFF]|\uD836[\uDE00-\uDE36\uDE3B-\uDE6C\uDE75\uDE84\uDE9B-\uDE9F\uDEA1-\uDEAF]|\uD838[\uDC00-\uDC06\uDC08-\uDC18\uDC1B-\uDC21\uDC23\uDC24\uDC26-\uDC2A]|\uD83A[\uDC00-\uDCC4\uDCD0-\uDCD6\uDD00-\uDD4A\uDD50-\uDD59]|\uD83B[\uDE00-\uDE03\uDE05-\uDE1F\uDE21\uDE22\uDE24\uDE27\uDE29-\uDE32\uDE34-\uDE37\uDE39\uDE3B\uDE42\uDE47\uDE49\uDE4B\uDE4D-\uDE4F\uDE51\uDE52\uDE54\uDE57\uDE59\uDE5B\uDE5D\uDE5F\uDE61\uDE62\uDE64\uDE67-\uDE6A\uDE6C-\uDE72\uDE74-\uDE77\uDE79-\uDE7C\uDE7E\uDE80-\uDE89\uDE8B-\uDE9B\uDEA1-\uDEA3\uDEA5-\uDEA9\uDEAB-\uDEBB]|\uD869[\uDC00-\uDED6\uDF00-\uDFFF]|\uD86D[\uDC00-\uDF34\uDF40-\uDFFF]|\uD86E[\uDC00-\uDC1D\uDC20-\uDFFF]|\uD873[\uDC00-\uDEA1\uDEB0-\uDFFF]|\uD87A[\uDC00-\uDFE0]|\uD87E[\uDC00-\uDE1D]|\uDB40[\uDD00-\uDDEF]/,Object.defineProperty(Z,"__esModule",{value:!0}),Z.JudgeUtil=void 0;const te=Q;Z.JudgeUtil=class{static isIgnoreChar(e){return"string"==typeof e&&("\t"===e||"\v"===e||"\f"===e||" "===e||" "===e||"\ufeff"===e||"\n"===e||"\r"===e||"\u2028"===e||"\u2029"===e)}static isSpaceSeparator(e){return"string"==typeof e&&te.Unicode.Space_Separator.test(e)}static isIdStartChar(e){return"string"==typeof e&&(e>="a"&&e<="z"||e>="A"&&e<="Z"||"$"===e||"_"===e||te.Unicode.ID_Start.test(e))}static isIdContinueChar(e){return"string"==typeof e&&(e>="a"&&e<="z"||e>="A"&&e<="Z"||e>="0"&&e<="9"||"$"===e||"_"===e||"‌"===e||"‍"===e||te.Unicode.ID_Continue.test(e))}static isDigitWithoutZero(e){return/[1-9]/.test(e)}static isDigit(e){return"string"==typeof e&&/[0-9]/.test(e)}static isHexDigit(e){return"string"==typeof e&&/[0-9A-Fa-f]/.test(e)}};var ne={},re={fromCallback:function(e){return Object.defineProperty((function(...t){if("function"!=typeof t[t.length-1])return new Promise(((n,r)=>{e.call(this,...t,((e,t)=>null!=e?r(e):n(t)))}));e.apply(this,t)}),"name",{value:e.name})},fromPromise:function(e){return Object.defineProperty((function(...t){const n=t[t.length-1];if("function"!=typeof n)return e.apply(this,t);e.apply(this,t.slice(0,-1)).then((e=>n(null,e)),n)}),"name",{value:e.name})}},ue=y.default,oe=process.cwd,ie=null,se=process.env.GRACEFUL_FS_PLATFORM||process.platform;process.cwd=function(){return ie||(ie=oe.call(process)),ie};try{process.cwd()}catch(e){}if("function"==typeof process.chdir){var ce=process.chdir;process.chdir=function(e){ie=null,ce.call(process,e)},Object.setPrototypeOf&&Object.setPrototypeOf(process.chdir,ce)}var ae=function(e){ue.hasOwnProperty("O_SYMLINK")&&process.version.match(/^v0\.6\.[0-2]|^v0\.5\./)&&function(e){e.lchmod=function(t,n,r){e.open(t,ue.O_WRONLY|ue.O_SYMLINK,n,(function(t,u){t?r&&r(t):e.fchmod(u,n,(function(t){e.close(u,(function(e){r&&r(t||e)}))}))}))},e.lchmodSync=function(t,n){var r,u=e.openSync(t,ue.O_WRONLY|ue.O_SYMLINK,n),o=!0;try{r=e.fchmodSync(u,n),o=!1}finally{if(o)try{e.closeSync(u)}catch(e){}else e.closeSync(u)}return r}}(e);e.lutimes||function(e){ue.hasOwnProperty("O_SYMLINK")&&e.futimes?(e.lutimes=function(t,n,r,u){e.open(t,ue.O_SYMLINK,(function(t,o){t?u&&u(t):e.futimes(o,n,r,(function(t){e.close(o,(function(e){u&&u(t||e)}))}))}))},e.lutimesSync=function(t,n,r){var u,o=e.openSync(t,ue.O_SYMLINK),i=!0;try{u=e.futimesSync(o,n,r),i=!1}finally{if(i)try{e.closeSync(o)}catch(e){}else e.closeSync(o)}return u}):e.futimes&&(e.lutimes=function(e,t,n,r){r&&process.nextTick(r)},e.lutimesSync=function(){})}(e);e.chown=r(e.chown),e.fchown=r(e.fchown),e.lchown=r(e.lchown),e.chmod=t(e.chmod),e.fchmod=t(e.fchmod),e.lchmod=t(e.lchmod),e.chownSync=u(e.chownSync),e.fchownSync=u(e.fchownSync),e.lchownSync=u(e.lchownSync),e.chmodSync=n(e.chmodSync),e.fchmodSync=n(e.fchmodSync),e.lchmodSync=n(e.lchmodSync),e.stat=o(e.stat),e.fstat=o(e.fstat),e.lstat=o(e.lstat),e.statSync=i(e.statSync),e.fstatSync=i(e.fstatSync),e.lstatSync=i(e.lstatSync),e.chmod&&!e.lchmod&&(e.lchmod=function(e,t,n){n&&process.nextTick(n)},e.lchmodSync=function(){});e.chown&&!e.lchown&&(e.lchown=function(e,t,n,r){r&&process.nextTick(r)},e.lchownSync=function(){});"win32"===se&&(e.rename="function"!=typeof e.rename?e.rename:function(t){function n(n,r,u){var o=Date.now(),i=0;t(n,r,(function s(c){if(c&&("EACCES"===c.code||"EPERM"===c.code||"EBUSY"===c.code)&&Date.now()-o<6e4)return setTimeout((function(){e.stat(r,(function(e,o){e&&"ENOENT"===e.code?t(n,r,s):u(c)}))}),i),void(i<100&&(i+=10));u&&u(c)}))}return Object.setPrototypeOf&&Object.setPrototypeOf(n,t),n}(e.rename));function t(t){return t?function(n,r,u){return t.call(e,n,r,(function(e){s(e)&&(e=null),u&&u.apply(this,arguments)}))}:t}function n(t){return t?function(n,r){try{return t.call(e,n,r)}catch(e){if(!s(e))throw e}}:t}function r(t){return t?function(n,r,u,o){return t.call(e,n,r,u,(function(e){s(e)&&(e=null),o&&o.apply(this,arguments)}))}:t}function u(t){return t?function(n,r,u){try{return t.call(e,n,r,u)}catch(e){if(!s(e))throw e}}:t}function o(t){return t?function(n,r,u){function o(e,t){t&&(t.uid<0&&(t.uid+=4294967296),t.gid<0&&(t.gid+=4294967296)),u&&u.apply(this,arguments)}return"function"==typeof r&&(u=r,r=null),r?t.call(e,n,r,o):t.call(e,n,o)}:t}function i(t){return t?function(n,r){var u=r?t.call(e,n,r):t.call(e,n);return u&&(u.uid<0&&(u.uid+=4294967296),u.gid<0&&(u.gid+=4294967296)),u}:t}function s(e){return!e||("ENOSYS"===e.code||!(process.getuid&&0===process.getuid()||"EINVAL"!==e.code&&"EPERM"!==e.code))}e.read="function"!=typeof e.read?e.read:function(t){function n(n,r,u,o,i,s){var c;if(s&&"function"==typeof s){var a=0;c=function(l,f,d){if(l&&"EAGAIN"===l.code&&a<10)return a++,t.call(e,n,r,u,o,i,c);s.apply(this,arguments)}}return t.call(e,n,r,u,o,i,c)}return Object.setPrototypeOf&&Object.setPrototypeOf(n,t),n}(e.read),e.readSync="function"!=typeof e.readSync?e.readSync:(c=e.readSync,function(t,n,r,u,o){for(var i=0;;)try{return c.call(e,t,n,r,u,o)}catch(e){if("EAGAIN"===e.code&&i<10){i++;continue}throw e}});var c};var le=C.default.Stream,fe=function(e){return{ReadStream:function t(n,r){if(!(this instanceof t))return new t(n,r);le.call(this);var u=this;this.path=n,this.fd=null,this.readable=!0,this.paused=!1,this.flags="r",this.mode=438,this.bufferSize=65536,r=r||{};for(var o=Object.keys(r),i=0,s=o.length;ithis.end)throw new Error("start must be <= end");this.pos=this.start}if(null!==this.fd)return void process.nextTick((function(){u._read()}));e.open(this.path,this.flags,this.mode,(function(e,t){if(e)return u.emit("error",e),void(u.readable=!1);u.fd=t,u.emit("open",t),u._read()}))},WriteStream:function t(n,r){if(!(this instanceof t))return new t(n,r);le.call(this),this.path=n,this.fd=null,this.writable=!0,this.flags="w",this.encoding="binary",this.mode=438,this.bytesWritten=0,r=r||{};for(var u=Object.keys(r),o=0,i=u.length;o= zero");this.pos=this.start}this.busy=!1,this._queue=[],null===this.fd&&(this._open=e.open,this._queue.push([this._open,this.path,this.flags,this.mode,void 0]),this.flush())}}};var de=function(e){if(null===e||"object"!=typeof e)return e;if(e instanceof Object)var t={__proto__:De(e)};else t=Object.create(null);return Object.getOwnPropertyNames(e).forEach((function(n){Object.defineProperty(t,n,Object.getOwnPropertyDescriptor(e,n))})),t},De=Object.getPrototypeOf||function(e){return e.__proto__};var pe,Ee,me=D.default,he=ae,ye=fe,Ce=de,Fe=F.default;function ge(e,t){Object.defineProperty(e,pe,{get:function(){return t}})}"function"==typeof Symbol&&"function"==typeof Symbol.for?(pe=Symbol.for("graceful-fs.queue"),Ee=Symbol.for("graceful-fs.previous")):(pe="___graceful-fs.queue",Ee="___graceful-fs.previous");var Ae=function(){};if(Fe.debuglog?Ae=Fe.debuglog("gfs4"):/\bgfs4\b/i.test(process.env.NODE_DEBUG||"")&&(Ae=function(){var e=Fe.format.apply(Fe,arguments);e="GFS4: "+e.split(/\n/).join("\nGFS4: "),console.error(e)}),!me[pe]){var ve=w[pe]||[];ge(me,ve),me.close=function(e){function t(t,n){return e.call(me,t,(function(e){e||_e(),"function"==typeof n&&n.apply(this,arguments)}))}return Object.defineProperty(t,Ee,{value:e}),t}(me.close),me.closeSync=function(e){function t(t){e.apply(me,arguments),_e()}return Object.defineProperty(t,Ee,{value:e}),t}(me.closeSync),/\bgfs4\b/i.test(process.env.NODE_DEBUG||"")&&process.on("exit",(function(){Ae(me[pe]),g.default.equal(me[pe].length,0)}))}w[pe]||ge(w,me[pe]);var Se,we=Oe(Ce(me));function Oe(e){he(e),e.gracefulify=Oe,e.createReadStream=function(t,n){return new e.ReadStream(t,n)},e.createWriteStream=function(t,n){return new e.WriteStream(t,n)};var t=e.readFile;e.readFile=function(e,n,r){"function"==typeof n&&(r=n,n=null);return function e(n,r,u,o){return t(n,r,(function(t){!t||"EMFILE"!==t.code&&"ENFILE"!==t.code?"function"==typeof u&&u.apply(this,arguments):be([e,[n,r,u],t,o||Date.now(),Date.now()])}))}(e,n,r)};var n=e.writeFile;e.writeFile=function(e,t,r,u){"function"==typeof r&&(u=r,r=null);return function e(t,r,u,o,i){return n(t,r,u,(function(n){!n||"EMFILE"!==n.code&&"ENFILE"!==n.code?"function"==typeof o&&o.apply(this,arguments):be([e,[t,r,u,o],n,i||Date.now(),Date.now()])}))}(e,t,r,u)};var r=e.appendFile;r&&(e.appendFile=function(e,t,n,u){"function"==typeof n&&(u=n,n=null);return function e(t,n,u,o,i){return r(t,n,u,(function(r){!r||"EMFILE"!==r.code&&"ENFILE"!==r.code?"function"==typeof o&&o.apply(this,arguments):be([e,[t,n,u,o],r,i||Date.now(),Date.now()])}))}(e,t,n,u)});var u=e.copyFile;u&&(e.copyFile=function(e,t,n,r){"function"==typeof n&&(r=n,n=0);return function e(t,n,r,o,i){return u(t,n,r,(function(u){!u||"EMFILE"!==u.code&&"ENFILE"!==u.code?"function"==typeof o&&o.apply(this,arguments):be([e,[t,n,r,o],u,i||Date.now(),Date.now()])}))}(e,t,n,r)});var o=e.readdir;e.readdir=function(e,t,n){"function"==typeof t&&(n=t,t=null);var r=i.test(process.version)?function(e,t,n,r){return o(e,u(e,t,n,r))}:function(e,t,n,r){return o(e,t,u(e,t,n,r))};return r(e,t,n);function u(e,t,n,u){return function(o,i){!o||"EMFILE"!==o.code&&"ENFILE"!==o.code?(i&&i.sort&&i.sort(),"function"==typeof n&&n.call(this,o,i)):be([r,[e,t,n],o,u||Date.now(),Date.now()])}}};var i=/^v[0-5]\./;if("v0.8"===process.version.substr(0,4)){var s=ye(e);d=s.ReadStream,D=s.WriteStream}var c=e.ReadStream;c&&(d.prototype=Object.create(c.prototype),d.prototype.open=function(){var e=this;E(e.path,e.flags,e.mode,(function(t,n){t?(e.autoClose&&e.destroy(),e.emit("error",t)):(e.fd=n,e.emit("open",n),e.read())}))});var a=e.WriteStream;a&&(D.prototype=Object.create(a.prototype),D.prototype.open=function(){var e=this;E(e.path,e.flags,e.mode,(function(t,n){t?(e.destroy(),e.emit("error",t)):(e.fd=n,e.emit("open",n))}))}),Object.defineProperty(e,"ReadStream",{get:function(){return d},set:function(e){d=e},enumerable:!0,configurable:!0}),Object.defineProperty(e,"WriteStream",{get:function(){return D},set:function(e){D=e},enumerable:!0,configurable:!0});var l=d;Object.defineProperty(e,"FileReadStream",{get:function(){return l},set:function(e){l=e},enumerable:!0,configurable:!0});var f=D;function d(e,t){return this instanceof d?(c.apply(this,arguments),this):d.apply(Object.create(d.prototype),arguments)}function D(e,t){return this instanceof D?(a.apply(this,arguments),this):D.apply(Object.create(D.prototype),arguments)}Object.defineProperty(e,"FileWriteStream",{get:function(){return f},set:function(e){f=e},enumerable:!0,configurable:!0});var p=e.open;function E(e,t,n,r){return"function"==typeof n&&(r=n,n=null),function e(t,n,r,u,o){return p(t,n,r,(function(i,s){!i||"EMFILE"!==i.code&&"ENFILE"!==i.code?"function"==typeof u&&u.apply(this,arguments):be([e,[t,n,r,u],i,o||Date.now(),Date.now()])}))}(e,t,n,r)}return e.open=E,e}function be(e){Ae("ENQUEUE",e[0].name,e[1]),me[pe].push(e),Be()}function _e(){for(var e=Date.now(),t=0;t2&&(me[pe][t][3]=e,me[pe][t][4]=e);Be()}function Be(){if(clearTimeout(Se),Se=void 0,0!==me[pe].length){var e=me[pe].shift(),t=e[0],n=e[1],r=e[2],u=e[3],o=e[4];if(void 0===u)Ae("RETRY",t.name,n),t.apply(null,n);else if(Date.now()-u>=6e4){Ae("TIMEOUT",t.name,n);var i=n.pop();"function"==typeof i&&i.call(null,r)}else{var s=Date.now()-o,c=Math.max(o-u,1);s>=Math.min(1.2*c,100)?(Ae("RETRY",t.name,n),t.apply(null,n.concat([u]))):me[pe].push(e)}void 0===Se&&(Se=setTimeout(Be,0))}}process.env.TEST_GRACEFUL_FS_GLOBAL_PATCH&&!me.__patched&&(we=Oe(me),me.__patched=!0),function(e){const t=re.fromCallback,n=we,r=["access","appendFile","chmod","chown","close","copyFile","fchmod","fchown","fdatasync","fstat","fsync","ftruncate","futimes","lchmod","lchown","link","lstat","mkdir","mkdtemp","open","opendir","readdir","readFile","readlink","realpath","rename","rm","rmdir","stat","symlink","truncate","unlink","utimes","writeFile"].filter((e=>"function"==typeof n[e]));Object.assign(e,n),r.forEach((r=>{e[r]=t(n[r])})),e.realpath.native=t(n.realpath.native),e.exists=function(e,t){return"function"==typeof t?n.exists(e,t):new Promise((t=>n.exists(e,t)))},e.read=function(e,t,r,u,o,i){return"function"==typeof i?n.read(e,t,r,u,o,i):new Promise(((i,s)=>{n.read(e,t,r,u,o,((e,t,n)=>{if(e)return s(e);i({bytesRead:t,buffer:n})}))}))},e.write=function(e,t,...r){return"function"==typeof r[r.length-1]?n.write(e,t,...r):new Promise(((u,o)=>{n.write(e,t,...r,((e,t,n)=>{if(e)return o(e);u({bytesWritten:t,buffer:n})}))}))},"function"==typeof n.writev&&(e.writev=function(e,t,...r){return"function"==typeof r[r.length-1]?n.writev(e,t,...r):new Promise(((u,o)=>{n.writev(e,t,...r,((e,t,n)=>{if(e)return o(e);u({bytesWritten:t,buffers:n})}))}))})}(ne);var Pe={},ke={};const xe=p.default;ke.checkPath=function(e){if("win32"===process.platform){if(/[<>:"|?*]/.test(e.replace(xe.parse(e).root,""))){const t=new Error(`Path contains invalid characters: ${e}`);throw t.code="EINVAL",t}}};const Ne=ne,{checkPath:Ie}=ke,Te=e=>"number"==typeof e?e:{mode:511,...e}.mode;Pe.makeDir=async(e,t)=>(Ie(e),Ne.mkdir(e,{mode:Te(t),recursive:!0})),Pe.makeDirSync=(e,t)=>(Ie(e),Ne.mkdirSync(e,{mode:Te(t),recursive:!0}));const Re=re.fromPromise,{makeDir:Me,makeDirSync:Le}=Pe,je=Re(Me);var $e={mkdirs:je,mkdirsSync:Le,mkdirp:je,mkdirpSync:Le,ensureDir:je,ensureDirSync:Le};const He=re.fromPromise,Je=ne;var Ge={pathExists:He((function(e){return Je.access(e).then((()=>!0)).catch((()=>!1))})),pathExistsSync:Je.existsSync};const Ve=we;var Ue=function(e,t,n,r){Ve.open(e,"r+",((e,u)=>{if(e)return r(e);Ve.futimes(u,t,n,(e=>{Ve.close(u,(t=>{r&&r(e||t)}))}))}))},We=function(e,t,n){const r=Ve.openSync(e,"r+");return Ve.futimesSync(r,t,n),Ve.closeSync(r)};const ze=ne,Ke=p.default,qe=F.default;function Ye(e,t,n){const r=n.dereference?e=>ze.stat(e,{bigint:!0}):e=>ze.lstat(e,{bigint:!0});return Promise.all([r(e),r(t).catch((e=>{if("ENOENT"===e.code)return null;throw e}))]).then((([e,t])=>({srcStat:e,destStat:t})))}function Xe(e,t){return t.ino&&t.dev&&t.ino===e.ino&&t.dev===e.dev}function Ze(e,t){const n=Ke.resolve(e).split(Ke.sep).filter((e=>e)),r=Ke.resolve(t).split(Ke.sep).filter((e=>e));return n.reduce(((e,t,n)=>e&&r[n]===t),!0)}function Qe(e,t,n){return`Cannot ${n} '${e}' to a subdirectory of itself, '${t}'.`}var et={checkPaths:function(e,t,n,r,u){qe.callbackify(Ye)(e,t,r,((r,o)=>{if(r)return u(r);const{srcStat:i,destStat:s}=o;if(s){if(Xe(i,s)){const r=Ke.basename(e),o=Ke.basename(t);return"move"===n&&r!==o&&r.toLowerCase()===o.toLowerCase()?u(null,{srcStat:i,destStat:s,isChangingCase:!0}):u(new Error("Source and destination must not be the same."))}if(i.isDirectory()&&!s.isDirectory())return u(new Error(`Cannot overwrite non-directory '${t}' with directory '${e}'.`));if(!i.isDirectory()&&s.isDirectory())return u(new Error(`Cannot overwrite directory '${t}' with non-directory '${e}'.`))}return i.isDirectory()&&Ze(e,t)?u(new Error(Qe(e,t,n))):u(null,{srcStat:i,destStat:s})}))},checkPathsSync:function(e,t,n,r){const{srcStat:u,destStat:o}=function(e,t,n){let r;const u=n.dereference?e=>ze.statSync(e,{bigint:!0}):e=>ze.lstatSync(e,{bigint:!0}),o=u(e);try{r=u(t)}catch(e){if("ENOENT"===e.code)return{srcStat:o,destStat:null};throw e}return{srcStat:o,destStat:r}}(e,t,r);if(o){if(Xe(u,o)){const r=Ke.basename(e),i=Ke.basename(t);if("move"===n&&r!==i&&r.toLowerCase()===i.toLowerCase())return{srcStat:u,destStat:o,isChangingCase:!0};throw new Error("Source and destination must not be the same.")}if(u.isDirectory()&&!o.isDirectory())throw new Error(`Cannot overwrite non-directory '${t}' with directory '${e}'.`);if(!u.isDirectory()&&o.isDirectory())throw new Error(`Cannot overwrite directory '${t}' with non-directory '${e}'.`)}if(u.isDirectory()&&Ze(e,t))throw new Error(Qe(e,t,n));return{srcStat:u,destStat:o}},checkParentPaths:function e(t,n,r,u,o){const i=Ke.resolve(Ke.dirname(t)),s=Ke.resolve(Ke.dirname(r));if(s===i||s===Ke.parse(s).root)return o();ze.stat(s,{bigint:!0},((i,c)=>i?"ENOENT"===i.code?o():o(i):Xe(n,c)?o(new Error(Qe(t,r,u))):e(t,n,s,u,o)))},checkParentPathsSync:function e(t,n,r,u){const o=Ke.resolve(Ke.dirname(t)),i=Ke.resolve(Ke.dirname(r));if(i===o||i===Ke.parse(i).root)return;let s;try{s=ze.statSync(i,{bigint:!0})}catch(e){if("ENOENT"===e.code)return;throw e}if(Xe(n,s))throw new Error(Qe(t,r,u));return e(t,n,i,u)},isSrcSubdir:Ze,areIdentical:Xe};const tt=we,nt=p.default,rt=$e.mkdirs,ut=Ge.pathExists,ot=Ue,it=et;function st(e,t,n,r,u){const o=nt.dirname(n);ut(o,((i,s)=>i?u(i):s?at(e,t,n,r,u):void rt(o,(o=>o?u(o):at(e,t,n,r,u)))))}function ct(e,t,n,r,u,o){Promise.resolve(u.filter(n,r)).then((i=>i?e(t,n,r,u,o):o()),(e=>o(e)))}function at(e,t,n,r,u){(r.dereference?tt.stat:tt.lstat)(t,((o,i)=>o?u(o):i.isDirectory()?function(e,t,n,r,u,o){return t?Dt(n,r,u,o):function(e,t,n,r,u){tt.mkdir(n,(o=>{if(o)return u(o);Dt(t,n,r,(t=>t?u(t):dt(n,e,u)))}))}(e.mode,n,r,u,o)}(i,e,t,n,r,u):i.isFile()||i.isCharacterDevice()||i.isBlockDevice()?function(e,t,n,r,u,o){return t?function(e,t,n,r,u){if(!r.overwrite)return r.errorOnExist?u(new Error(`'${n}' already exists`)):u();tt.unlink(n,(o=>o?u(o):lt(e,t,n,r,u)))}(e,n,r,u,o):lt(e,n,r,u,o)}(i,e,t,n,r,u):i.isSymbolicLink()?function(e,t,n,r,u){tt.readlink(t,((t,o)=>t?u(t):(r.dereference&&(o=nt.resolve(process.cwd(),o)),e?void tt.readlink(n,((t,i)=>t?"EINVAL"===t.code||"UNKNOWN"===t.code?tt.symlink(o,n,u):u(t):(r.dereference&&(i=nt.resolve(process.cwd(),i)),it.isSrcSubdir(o,i)?u(new Error(`Cannot copy '${o}' to a subdirectory of itself, '${i}'.`)):e.isDirectory()&&it.isSrcSubdir(i,o)?u(new Error(`Cannot overwrite '${i}' with '${o}'.`)):function(e,t,n){tt.unlink(t,(r=>r?n(r):tt.symlink(e,t,n)))}(o,n,u)))):tt.symlink(o,n,u))))}(e,t,n,r,u):i.isSocket()?u(new Error(`Cannot copy a socket file: ${t}`)):i.isFIFO()?u(new Error(`Cannot copy a FIFO pipe: ${t}`)):u(new Error(`Unknown file: ${t}`))))}function lt(e,t,n,r,u){tt.copyFile(t,n,(o=>o?u(o):r.preserveTimestamps?function(e,t,n,r){if(function(e){return 0==(128&e)}(e))return function(e,t,n){return dt(e,128|t,n)}(n,e,(u=>u?r(u):ft(e,t,n,r)));return ft(e,t,n,r)}(e.mode,t,n,u):dt(n,e.mode,u)))}function ft(e,t,n,r){!function(e,t,n){tt.stat(e,((e,r)=>e?n(e):ot(t,r.atime,r.mtime,n)))}(t,n,(t=>t?r(t):dt(n,e,r)))}function dt(e,t,n){return tt.chmod(e,t,n)}function Dt(e,t,n,r){tt.readdir(e,((u,o)=>u?r(u):pt(o,e,t,n,r)))}function pt(e,t,n,r,u){const o=e.pop();return o?function(e,t,n,r,u,o){const i=nt.join(n,t),s=nt.join(r,t);it.checkPaths(i,s,"copy",u,((t,c)=>{if(t)return o(t);const{destStat:a}=c;!function(e,t,n,r,u){r.filter?ct(at,e,t,n,r,u):at(e,t,n,r,u)}(a,i,s,u,(t=>t?o(t):pt(e,n,r,u,o)))}))}(e,o,t,n,r,u):u()}var Et=function(e,t,n,r){"function"!=typeof n||r?"function"==typeof n&&(n={filter:n}):(r=n,n={}),r=r||function(){},(n=n||{}).clobber=!("clobber"in n)||!!n.clobber,n.overwrite="overwrite"in n?!!n.overwrite:n.clobber,n.preserveTimestamps&&"ia32"===process.arch&&console.warn("fs-extra: Using the preserveTimestamps option in 32-bit node is not recommended;\n\n see https://github.com/jprichardson/node-fs-extra/issues/269"),it.checkPaths(e,t,"copy",n,((u,o)=>{if(u)return r(u);const{srcStat:i,destStat:s}=o;it.checkParentPaths(e,i,t,"copy",(u=>u?r(u):n.filter?ct(st,s,e,t,n,r):st(s,e,t,n,r)))}))};const mt=we,ht=p.default,yt=$e.mkdirsSync,Ct=We,Ft=et;function gt(e,t,n,r){const u=(r.dereference?mt.statSync:mt.lstatSync)(t);if(u.isDirectory())return function(e,t,n,r,u){return t?St(n,r,u):function(e,t,n,r){return mt.mkdirSync(n),St(t,n,r),vt(n,e)}(e.mode,n,r,u)}(u,e,t,n,r);if(u.isFile()||u.isCharacterDevice()||u.isBlockDevice())return function(e,t,n,r,u){return t?function(e,t,n,r){if(r.overwrite)return mt.unlinkSync(n),At(e,t,n,r);if(r.errorOnExist)throw new Error(`'${n}' already exists`)}(e,n,r,u):At(e,n,r,u)}(u,e,t,n,r);if(u.isSymbolicLink())return function(e,t,n,r){let u=mt.readlinkSync(t);r.dereference&&(u=ht.resolve(process.cwd(),u));if(e){let e;try{e=mt.readlinkSync(n)}catch(e){if("EINVAL"===e.code||"UNKNOWN"===e.code)return mt.symlinkSync(u,n);throw e}if(r.dereference&&(e=ht.resolve(process.cwd(),e)),Ft.isSrcSubdir(u,e))throw new Error(`Cannot copy '${u}' to a subdirectory of itself, '${e}'.`);if(mt.statSync(n).isDirectory()&&Ft.isSrcSubdir(e,u))throw new Error(`Cannot overwrite '${e}' with '${u}'.`);return function(e,t){return mt.unlinkSync(t),mt.symlinkSync(e,t)}(u,n)}return mt.symlinkSync(u,n)}(e,t,n,r);if(u.isSocket())throw new Error(`Cannot copy a socket file: ${t}`);if(u.isFIFO())throw new Error(`Cannot copy a FIFO pipe: ${t}`);throw new Error(`Unknown file: ${t}`)}function At(e,t,n,r){return mt.copyFileSync(t,n),r.preserveTimestamps&&function(e,t,n){(function(e){return 0==(128&e)})(e)&&function(e,t){vt(e,128|t)}(n,e);(function(e,t){const n=mt.statSync(e);Ct(t,n.atime,n.mtime)})(t,n)}(e.mode,t,n),vt(n,e.mode)}function vt(e,t){return mt.chmodSync(e,t)}function St(e,t,n){mt.readdirSync(e).forEach((r=>function(e,t,n,r){const u=ht.join(t,e),o=ht.join(n,e),{destStat:i}=Ft.checkPathsSync(u,o,"copy",r);return function(e,t,n,r){if(!r.filter||r.filter(t,n))return gt(e,t,n,r)}(i,u,o,r)}(r,e,t,n)))}var wt=function(e,t,n){"function"==typeof n&&(n={filter:n}),(n=n||{}).clobber=!("clobber"in n)||!!n.clobber,n.overwrite="overwrite"in n?!!n.overwrite:n.clobber,n.preserveTimestamps&&"ia32"===process.arch&&console.warn("fs-extra: Using the preserveTimestamps option in 32-bit node is not recommended;\n\n see https://github.com/jprichardson/node-fs-extra/issues/269");const{srcStat:r,destStat:u}=Ft.checkPathsSync(e,t,"copy",n);return Ft.checkParentPathsSync(e,r,t,"copy"),function(e,t,n,r){if(r.filter&&!r.filter(t,n))return;const u=ht.dirname(n);mt.existsSync(u)||yt(u);return gt(e,t,n,r)}(u,e,t,n)};var Ot={copy:(0,re.fromCallback)(Et),copySync:wt};const bt=we,_t=p.default,Bt=g.default,Pt="win32"===process.platform;function kt(e){["unlink","chmod","stat","lstat","rmdir","readdir"].forEach((t=>{e[t]=e[t]||bt[t],e[t+="Sync"]=e[t]||bt[t]})),e.maxBusyTries=e.maxBusyTries||3}function xt(e,t,n){let r=0;"function"==typeof t&&(n=t,t={}),Bt(e,"rimraf: missing path"),Bt.strictEqual(typeof e,"string","rimraf: path should be a string"),Bt.strictEqual(typeof n,"function","rimraf: callback function required"),Bt(t,"rimraf: invalid options argument provided"),Bt.strictEqual(typeof t,"object","rimraf: options should be object"),kt(t),Nt(e,t,(function u(o){if(o){if(("EBUSY"===o.code||"ENOTEMPTY"===o.code||"EPERM"===o.code)&&rNt(e,t,u)),100*r)}"ENOENT"===o.code&&(o=null)}n(o)}))}function Nt(e,t,n){Bt(e),Bt(t),Bt("function"==typeof n),t.lstat(e,((r,u)=>r&&"ENOENT"===r.code?n(null):r&&"EPERM"===r.code&&Pt?It(e,t,r,n):u&&u.isDirectory()?Rt(e,t,r,n):void t.unlink(e,(r=>{if(r){if("ENOENT"===r.code)return n(null);if("EPERM"===r.code)return Pt?It(e,t,r,n):Rt(e,t,r,n);if("EISDIR"===r.code)return Rt(e,t,r,n)}return n(r)}))))}function It(e,t,n,r){Bt(e),Bt(t),Bt("function"==typeof r),t.chmod(e,438,(u=>{u?r("ENOENT"===u.code?null:n):t.stat(e,((u,o)=>{u?r("ENOENT"===u.code?null:n):o.isDirectory()?Rt(e,t,n,r):t.unlink(e,r)}))}))}function Tt(e,t,n){let r;Bt(e),Bt(t);try{t.chmodSync(e,438)}catch(e){if("ENOENT"===e.code)return;throw n}try{r=t.statSync(e)}catch(e){if("ENOENT"===e.code)return;throw n}r.isDirectory()?Lt(e,t,n):t.unlinkSync(e)}function Rt(e,t,n,r){Bt(e),Bt(t),Bt("function"==typeof r),t.rmdir(e,(u=>{!u||"ENOTEMPTY"!==u.code&&"EEXIST"!==u.code&&"EPERM"!==u.code?u&&"ENOTDIR"===u.code?r(n):r(u):function(e,t,n){Bt(e),Bt(t),Bt("function"==typeof n),t.readdir(e,((r,u)=>{if(r)return n(r);let o,i=u.length;if(0===i)return t.rmdir(e,n);u.forEach((r=>{xt(_t.join(e,r),t,(r=>{if(!o)return r?n(o=r):void(0==--i&&t.rmdir(e,n))}))}))}))}(e,t,r)}))}function Mt(e,t){let n;kt(t=t||{}),Bt(e,"rimraf: missing path"),Bt.strictEqual(typeof e,"string","rimraf: path should be a string"),Bt(t,"rimraf: missing options"),Bt.strictEqual(typeof t,"object","rimraf: options should be object");try{n=t.lstatSync(e)}catch(n){if("ENOENT"===n.code)return;"EPERM"===n.code&&Pt&&Tt(e,t,n)}try{n&&n.isDirectory()?Lt(e,t,null):t.unlinkSync(e)}catch(n){if("ENOENT"===n.code)return;if("EPERM"===n.code)return Pt?Tt(e,t,n):Lt(e,t,n);if("EISDIR"!==n.code)throw n;Lt(e,t,n)}}function Lt(e,t,n){Bt(e),Bt(t);try{t.rmdirSync(e)}catch(r){if("ENOTDIR"===r.code)throw n;if("ENOTEMPTY"===r.code||"EEXIST"===r.code||"EPERM"===r.code)!function(e,t){if(Bt(e),Bt(t),t.readdirSync(e).forEach((n=>Mt(_t.join(e,n),t))),!Pt){return t.rmdirSync(e,t)}{const n=Date.now();do{try{return t.rmdirSync(e,t)}catch{}}while(Date.now()-n<500)}}(e,t);else if("ENOENT"!==r.code)throw r}}var jt=xt;xt.sync=Mt;const $t=we,Ht=re.fromCallback,Jt=jt;var Gt={remove:Ht((function(e,t){if($t.rm)return $t.rm(e,{recursive:!0,force:!0},t);Jt(e,t)})),removeSync:function(e){if($t.rmSync)return $t.rmSync(e,{recursive:!0,force:!0});Jt.sync(e)}};const Vt=re.fromPromise,Ut=ne,Wt=p.default,zt=$e,Kt=Gt,qt=Vt((async function(e){let t;try{t=await Ut.readdir(e)}catch{return zt.mkdirs(e)}return Promise.all(t.map((t=>Kt.remove(Wt.join(e,t)))))}));function Yt(e){let t;try{t=Ut.readdirSync(e)}catch{return zt.mkdirsSync(e)}t.forEach((t=>{t=Wt.join(e,t),Kt.removeSync(t)}))}var Xt={emptyDirSync:Yt,emptydirSync:Yt,emptyDir:qt,emptydir:qt};const Zt=re.fromCallback,Qt=p.default,en=we,tn=$e;var nn={createFile:Zt((function(e,t){function n(){en.writeFile(e,"",(e=>{if(e)return t(e);t()}))}en.stat(e,((r,u)=>{if(!r&&u.isFile())return t();const o=Qt.dirname(e);en.stat(o,((e,r)=>{if(e)return"ENOENT"===e.code?tn.mkdirs(o,(e=>{if(e)return t(e);n()})):t(e);r.isDirectory()?n():en.readdir(o,(e=>{if(e)return t(e)}))}))}))})),createFileSync:function(e){let t;try{t=en.statSync(e)}catch{}if(t&&t.isFile())return;const n=Qt.dirname(e);try{en.statSync(n).isDirectory()||en.readdirSync(n)}catch(e){if(!e||"ENOENT"!==e.code)throw e;tn.mkdirsSync(n)}en.writeFileSync(e,"")}};const rn=re.fromCallback,un=p.default,on=we,sn=$e,cn=Ge.pathExists,{areIdentical:an}=et;var ln={createLink:rn((function(e,t,n){function r(e,t){on.link(e,t,(e=>{if(e)return n(e);n(null)}))}on.lstat(t,((u,o)=>{on.lstat(e,((u,i)=>{if(u)return u.message=u.message.replace("lstat","ensureLink"),n(u);if(o&&an(i,o))return n(null);const s=un.dirname(t);cn(s,((u,o)=>u?n(u):o?r(e,t):void sn.mkdirs(s,(u=>{if(u)return n(u);r(e,t)}))))}))}))})),createLinkSync:function(e,t){let n;try{n=on.lstatSync(t)}catch{}try{const t=on.lstatSync(e);if(n&&an(t,n))return}catch(e){throw e.message=e.message.replace("lstat","ensureLink"),e}const r=un.dirname(t);return on.existsSync(r)||sn.mkdirsSync(r),on.linkSync(e,t)}};const fn=p.default,dn=we,Dn=Ge.pathExists;var pn={symlinkPaths:function(e,t,n){if(fn.isAbsolute(e))return dn.lstat(e,(t=>t?(t.message=t.message.replace("lstat","ensureSymlink"),n(t)):n(null,{toCwd:e,toDst:e})));{const r=fn.dirname(t),u=fn.join(r,e);return Dn(u,((t,o)=>t?n(t):o?n(null,{toCwd:u,toDst:e}):dn.lstat(e,(t=>t?(t.message=t.message.replace("lstat","ensureSymlink"),n(t)):n(null,{toCwd:e,toDst:fn.relative(r,e)})))))}},symlinkPathsSync:function(e,t){let n;if(fn.isAbsolute(e)){if(n=dn.existsSync(e),!n)throw new Error("absolute srcpath does not exist");return{toCwd:e,toDst:e}}{const r=fn.dirname(t),u=fn.join(r,e);if(n=dn.existsSync(u),n)return{toCwd:u,toDst:e};if(n=dn.existsSync(e),!n)throw new Error("relative srcpath does not exist");return{toCwd:e,toDst:fn.relative(r,e)}}}};const En=we;var mn={symlinkType:function(e,t,n){if(n="function"==typeof t?t:n,t="function"!=typeof t&&t)return n(null,t);En.lstat(e,((e,r)=>{if(e)return n(null,"file");t=r&&r.isDirectory()?"dir":"file",n(null,t)}))},symlinkTypeSync:function(e,t){let n;if(t)return t;try{n=En.lstatSync(e)}catch{return"file"}return n&&n.isDirectory()?"dir":"file"}};const hn=re.fromCallback,yn=p.default,Cn=ne,Fn=$e.mkdirs,gn=$e.mkdirsSync,An=pn.symlinkPaths,vn=pn.symlinkPathsSync,Sn=mn.symlinkType,wn=mn.symlinkTypeSync,On=Ge.pathExists,{areIdentical:bn}=et;function _n(e,t,n,r){An(e,t,((u,o)=>{if(u)return r(u);e=o.toDst,Sn(o.toCwd,n,((n,u)=>{if(n)return r(n);const o=yn.dirname(t);On(o,((n,i)=>n?r(n):i?Cn.symlink(e,t,u,r):void Fn(o,(n=>{if(n)return r(n);Cn.symlink(e,t,u,r)}))))}))}))}var Bn={createSymlink:hn((function(e,t,n,r){r="function"==typeof n?n:r,n="function"!=typeof n&&n,Cn.lstat(t,((u,o)=>{!u&&o.isSymbolicLink()?Promise.all([Cn.stat(e),Cn.stat(t)]).then((([u,o])=>{if(bn(u,o))return r(null);_n(e,t,n,r)})):_n(e,t,n,r)}))})),createSymlinkSync:function(e,t,n){let r;try{r=Cn.lstatSync(t)}catch{}if(r&&r.isSymbolicLink()){const n=Cn.statSync(e),r=Cn.statSync(t);if(bn(n,r))return}const u=vn(e,t);e=u.toDst,n=wn(u.toCwd,n);const o=yn.dirname(t);return Cn.existsSync(o)||gn(o),Cn.symlinkSync(e,t,n)}};const{createFile:Pn,createFileSync:kn}=nn,{createLink:xn,createLinkSync:Nn}=ln,{createSymlink:In,createSymlinkSync:Tn}=Bn;var Rn={createFile:Pn,createFileSync:kn,ensureFile:Pn,ensureFileSync:kn,createLink:xn,createLinkSync:Nn,ensureLink:xn,ensureLinkSync:Nn,createSymlink:In,createSymlinkSync:Tn,ensureSymlink:In,ensureSymlinkSync:Tn};var Mn={stringify:function(e,{EOL:t="\n",finalEOL:n=!0,replacer:r=null,spaces:u}={}){const o=n?t:"";return JSON.stringify(e,r,u).replace(/\n/g,t)+o},stripBom:function(e){return Buffer.isBuffer(e)&&(e=e.toString("utf8")),e.replace(/^\uFEFF/,"")}};let Ln;try{Ln=we}catch(e){Ln=D.default}const jn=re,{stringify:$n,stripBom:Hn}=Mn;const Jn=jn.fromPromise((async function(e,t={}){"string"==typeof t&&(t={encoding:t});const n=t.fs||Ln,r=!("throws"in t)||t.throws;let u,o=await jn.fromCallback(n.readFile)(e,t);o=Hn(o);try{u=JSON.parse(o,t?t.reviver:null)}catch(t){if(r)throw t.message=`${e}: ${t.message}`,t;return null}return u}));const Gn=jn.fromPromise((async function(e,t,n={}){const r=n.fs||Ln,u=$n(t,n);await jn.fromCallback(r.writeFile)(e,u,n)}));const Vn={readFile:Jn,readFileSync:function(e,t={}){"string"==typeof t&&(t={encoding:t});const n=t.fs||Ln,r=!("throws"in t)||t.throws;try{let r=n.readFileSync(e,t);return r=Hn(r),JSON.parse(r,t.reviver)}catch(t){if(r)throw t.message=`${e}: ${t.message}`,t;return null}},writeFile:Gn,writeFileSync:function(e,t,n={}){const r=n.fs||Ln,u=$n(t,n);return r.writeFileSync(e,u,n)}};var Un={readJson:Vn.readFile,readJsonSync:Vn.readFileSync,writeJson:Vn.writeFile,writeJsonSync:Vn.writeFileSync};const Wn=re.fromCallback,zn=we,Kn=p.default,qn=$e,Yn=Ge.pathExists;var Xn={outputFile:Wn((function(e,t,n,r){"function"==typeof n&&(r=n,n="utf8");const u=Kn.dirname(e);Yn(u,((o,i)=>o?r(o):i?zn.writeFile(e,t,n,r):void qn.mkdirs(u,(u=>{if(u)return r(u);zn.writeFile(e,t,n,r)}))))})),outputFileSync:function(e,...t){const n=Kn.dirname(e);if(zn.existsSync(n))return zn.writeFileSync(e,...t);qn.mkdirsSync(n),zn.writeFileSync(e,...t)}};const{stringify:Zn}=Mn,{outputFile:Qn}=Xn;var er=async function(e,t,n={}){const r=Zn(t,n);await Qn(e,r,n)};const{stringify:tr}=Mn,{outputFileSync:nr}=Xn;var rr=function(e,t,n){const r=tr(t,n);nr(e,r,n)};const ur=re.fromPromise,or=Un;or.outputJson=ur(er),or.outputJsonSync=rr,or.outputJSON=or.outputJson,or.outputJSONSync=or.outputJsonSync,or.writeJSON=or.writeJson,or.writeJSONSync=or.writeJsonSync,or.readJSON=or.readJson,or.readJSONSync=or.readJsonSync;var ir=or;const sr=we,cr=p.default,ar=Ot.copy,lr=Gt.remove,fr=$e.mkdirp,dr=Ge.pathExists,Dr=et;function pr(e,t,n,r,u){return r?Er(e,t,n,u):n?lr(t,(r=>r?u(r):Er(e,t,n,u))):void dr(t,((r,o)=>r?u(r):o?u(new Error("dest already exists.")):Er(e,t,n,u)))}function Er(e,t,n,r){sr.rename(e,t,(u=>u?"EXDEV"!==u.code?r(u):function(e,t,n,r){const u={overwrite:n,errorOnExist:!0};ar(e,t,u,(t=>t?r(t):lr(e,r)))}(e,t,n,r):r()))}var mr=function(e,t,n,r){"function"==typeof n&&(r=n,n={});const u=n.overwrite||n.clobber||!1;Dr.checkPaths(e,t,"move",n,((n,o)=>{if(n)return r(n);const{srcStat:i,isChangingCase:s=!1}=o;Dr.checkParentPaths(e,i,t,"move",(n=>n?r(n):function(e){const t=cr.dirname(e);return cr.parse(t).root===t}(t)?pr(e,t,u,s,r):void fr(cr.dirname(t),(n=>n?r(n):pr(e,t,u,s,r)))))}))};const hr=we,yr=p.default,Cr=Ot.copySync,Fr=Gt.removeSync,gr=$e.mkdirpSync,Ar=et;function vr(e,t,n){try{hr.renameSync(e,t)}catch(r){if("EXDEV"!==r.code)throw r;return function(e,t,n){const r={overwrite:n,errorOnExist:!0};return Cr(e,t,r),Fr(e)}(e,t,n)}}var Sr=function(e,t,n){const r=(n=n||{}).overwrite||n.clobber||!1,{srcStat:u,isChangingCase:o=!1}=Ar.checkPathsSync(e,t,"move",n);return Ar.checkParentPathsSync(e,u,t,"move"),function(e){const t=yr.dirname(e);return yr.parse(t).root===t}(t)||gr(yr.dirname(t)),function(e,t,n,r){if(r)return vr(e,t,n);if(n)return Fr(t),vr(e,t,n);if(hr.existsSync(t))throw new Error("dest already exists.");return vr(e,t,n)}(e,t,r,o)};var wr,Or,br,_r,Br,Pr={move:(0,re.fromCallback)(mr),moveSync:Sr},kr={...ne,...Ot,...Xt,...Rn,...ir,...$e,...Pr,...Xn,...Ge,...Gt},xr={},Nr={exports:{}},Ir={exports:{}};function Tr(){if(Or)return wr;Or=1;var e=1e3,t=60*e,n=60*t,r=24*n,u=7*r,o=365.25*r;function i(e,t,n,r){var u=t>=1.5*n;return Math.round(e/n)+" "+r+(u?"s":"")}return wr=function(s,c){c=c||{};var a=typeof s;if("string"===a&&s.length>0)return function(i){if((i=String(i)).length>100)return;var s=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(i);if(!s)return;var c=parseFloat(s[1]);switch((s[2]||"ms").toLowerCase()){case"years":case"year":case"yrs":case"yr":case"y":return c*o;case"weeks":case"week":case"w":return c*u;case"days":case"day":case"d":return c*r;case"hours":case"hour":case"hrs":case"hr":case"h":return c*n;case"minutes":case"minute":case"mins":case"min":case"m":return c*t;case"seconds":case"second":case"secs":case"sec":case"s":return c*e;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return c;default:return}}(s);if("number"===a&&isFinite(s))return c.long?function(u){var o=Math.abs(u);if(o>=r)return i(u,o,r,"day");if(o>=n)return i(u,o,n,"hour");if(o>=t)return i(u,o,t,"minute");if(o>=e)return i(u,o,e,"second");return u+" ms"}(s):function(u){var o=Math.abs(u);if(o>=r)return Math.round(u/r)+"d";if(o>=n)return Math.round(u/n)+"h";if(o>=t)return Math.round(u/t)+"m";if(o>=e)return Math.round(u/e)+"s";return u+"ms"}(s);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(s))}}function Rr(){if(_r)return br;return _r=1,br=function(e){function t(e){let r,u,o,i=null;function s(...e){if(!s.enabled)return;const n=s,u=Number(new Date),o=u-(r||u);n.diff=o,n.prev=r,n.curr=u,r=u,e[0]=t.coerce(e[0]),"string"!=typeof e[0]&&e.unshift("%O");let i=0;e[0]=e[0].replace(/%([a-zA-Z%])/g,((r,u)=>{if("%%"===r)return"%";i++;const o=t.formatters[u];if("function"==typeof o){const t=e[i];r=o.call(n,t),e.splice(i,1),i--}return r})),t.formatArgs.call(n,e);(n.log||t.log).apply(n,e)}return s.namespace=e,s.useColors=t.useColors(),s.color=t.selectColor(e),s.extend=n,s.destroy=t.destroy,Object.defineProperty(s,"enabled",{enumerable:!0,configurable:!1,get:()=>null!==i?i:(u!==t.namespaces&&(u=t.namespaces,o=t.enabled(e)),o),set:e=>{i=e}}),"function"==typeof t.init&&t.init(s),s}function n(e,n){const r=t(this.namespace+(void 0===n?":":n)+e);return r.log=this.log,r}function r(e){return e.toString().substring(2,e.toString().length-2).replace(/\.\*\?$/,"*")}return t.debug=t,t.default=t,t.coerce=function(e){if(e instanceof Error)return e.stack||e.message;return e},t.disable=function(){const e=[...t.names.map(r),...t.skips.map(r).map((e=>"-"+e))].join(",");return t.enable(""),e},t.enable=function(e){let n;t.save(e),t.namespaces=e,t.names=[],t.skips=[];const r=("string"==typeof e?e:"").split(/[\s,]+/),u=r.length;for(n=0;n{t[n]=e[n]})),t.names=[],t.skips=[],t.formatters={},t.selectColor=function(e){let n=0;for(let t=0;t{const n=e.startsWith("-")?"":1===e.length?"-":"--",r=t.indexOf(n+e),u=t.indexOf("--");return-1!==r&&(-1===u||r{}),"Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."),t.colors=[6,2,3,4,5,1];try{const e=function(){if($r)return jr;$r=1;const e=E.default,t=A.default,n=Vr(),{env:r}=process;let u;function o(e){return 0!==e&&{level:e,hasBasic:!0,has256:e>=2,has16m:e>=3}}function i(t,o){if(0===u)return 0;if(n("color=16m")||n("color=full")||n("color=truecolor"))return 3;if(n("color=256"))return 2;if(t&&!o&&void 0===u)return 0;const i=u||0;if("dumb"===r.TERM)return i;if("win32"===process.platform){const t=e.release().split(".");return Number(t[0])>=10&&Number(t[2])>=10586?Number(t[2])>=14931?3:2:1}if("CI"in r)return["TRAVIS","CIRCLECI","APPVEYOR","GITLAB_CI","GITHUB_ACTIONS","BUILDKITE"].some((e=>e in r))||"codeship"===r.CI_NAME?1:i;if("TEAMCITY_VERSION"in r)return/^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(r.TEAMCITY_VERSION)?1:0;if("truecolor"===r.COLORTERM)return 3;if("TERM_PROGRAM"in r){const e=parseInt((r.TERM_PROGRAM_VERSION||"").split(".")[0],10);switch(r.TERM_PROGRAM){case"iTerm.app":return e>=3?3:2;case"Apple_Terminal":return 2}}return/-256(color)?$/i.test(r.TERM)?2:/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(r.TERM)||"COLORTERM"in r?1:i}return n("no-color")||n("no-colors")||n("color=false")||n("color=never")?u=0:(n("color")||n("colors")||n("color=true")||n("color=always"))&&(u=1),"FORCE_COLOR"in r&&(u="true"===r.FORCE_COLOR?1:"false"===r.FORCE_COLOR?0:0===r.FORCE_COLOR.length?1:Math.min(parseInt(r.FORCE_COLOR,10),3)),jr={supportsColor:function(e){return o(i(e,e&&e.isTTY))},stdout:o(i(!0,t.isatty(1))),stderr:o(i(!0,t.isatty(2)))}}();e&&(e.stderr||e).level>=2&&(t.colors=[20,21,26,27,32,33,38,39,40,41,42,43,44,45,56,57,62,63,68,69,74,75,76,77,78,79,80,81,92,93,98,99,112,113,128,129,134,135,148,149,160,161,162,163,164,165,166,167,168,169,170,171,172,173,178,179,184,185,196,197,198,199,200,201,202,203,204,205,206,207,208,209,214,215,220,221])}catch(e){}t.inspectOpts=Object.keys(process.env).filter((e=>/^debug_/i.test(e))).reduce(((e,t)=>{const n=t.substring(6).toLowerCase().replace(/_([a-z])/g,((e,t)=>t.toUpperCase()));let r=process.env[t];return r=!!/^(yes|on|true|enabled)$/i.test(r)||!/^(no|off|false|disabled)$/i.test(r)&&("null"===r?null:Number(r)),e[n]=r,e}),{}),e.exports=Rr()(t);const{formatters:u}=e.exports;u.o=function(e){return this.inspectOpts.colors=this.useColors,r.inspect(e,this.inspectOpts).split("\n").map((e=>e.trim())).join(" ")},u.O=function(e){return this.inspectOpts.colors=this.useColors,r.inspect(e,this.inspectOpts)}}(Gr,Gr.exports)),Gr.exports}Jr=Nr,"undefined"==typeof process||"renderer"===process.type||!0===process.browser||process.__nwjs?Jr.exports=(Br||(Br=1,function(e,t){t.formatArgs=function(t){if(t[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+t[0]+(this.useColors?"%c ":" ")+"+"+e.exports.humanize(this.diff),!this.useColors)return;const n="color: "+this.color;t.splice(1,0,n,"color: inherit");let r=0,u=0;t[0].replace(/%[a-zA-Z%]/g,(e=>{"%%"!==e&&(r++,"%c"===e&&(u=r))})),t.splice(u,0,n)},t.save=function(e){try{e?t.storage.setItem("debug",e):t.storage.removeItem("debug")}catch(e){}},t.load=function(){let e;try{e=t.storage.getItem("debug")}catch(e){}return!e&&"undefined"!=typeof process&&"env"in process&&(e=process.env.DEBUG),e},t.useColors=function(){return!("undefined"==typeof window||!window.process||"renderer"!==window.process.type&&!window.process.__nwjs)||("undefined"==typeof navigator||!navigator.userAgent||!navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/))&&("undefined"!=typeof document&&document.documentElement&&document.documentElement.style&&document.documentElement.style.WebkitAppearance||"undefined"!=typeof window&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)&&parseInt(RegExp.$1,10)>=31||"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/))},t.storage=function(){try{return localStorage}catch(e){}}(),t.destroy=(()=>{let e=!1;return()=>{e||(e=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),t.colors=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"],t.log=console.debug||console.log||(()=>{}),e.exports=Rr()(t);const{formatters:n}=e.exports;n.j=function(e){try{return JSON.stringify(e)}catch(e){return"[UnexpectedJSONParseError]: "+e.message}}}(Ir,Ir.exports)),Ir.exports):Jr.exports=Ur();var Wr=function(e){return(e=e||{}).circles?function(e){var t=[],n=[];return e.proto?function e(u){if("object"!=typeof u||null===u)return u;if(u instanceof Date)return new Date(u);if(Array.isArray(u))return r(u,e);if(u instanceof Map)return new Map(r(Array.from(u),e));if(u instanceof Set)return new Set(r(Array.from(u),e));var o={};for(var i in t.push(u),n.push(o),u){var s=u[i];if("object"!=typeof s||null===s)o[i]=s;else if(s instanceof Date)o[i]=new Date(s);else if(s instanceof Map)o[i]=new Map(r(Array.from(s),e));else if(s instanceof Set)o[i]=new Set(r(Array.from(s),e));else if(ArrayBuffer.isView(s))o[i]=zr(s);else{var c=t.indexOf(s);o[i]=-1!==c?n[c]:e(s)}}return t.pop(),n.pop(),o}:function e(u){if("object"!=typeof u||null===u)return u;if(u instanceof Date)return new Date(u);if(Array.isArray(u))return r(u,e);if(u instanceof Map)return new Map(r(Array.from(u),e));if(u instanceof Set)return new Set(r(Array.from(u),e));var o={};for(var i in t.push(u),n.push(o),u)if(!1!==Object.hasOwnProperty.call(u,i)){var s=u[i];if("object"!=typeof s||null===s)o[i]=s;else if(s instanceof Date)o[i]=new Date(s);else if(s instanceof Map)o[i]=new Map(r(Array.from(s),e));else if(s instanceof Set)o[i]=new Set(r(Array.from(s),e));else if(ArrayBuffer.isView(s))o[i]=zr(s);else{var c=t.indexOf(s);o[i]=-1!==c?n[c]:e(s)}}return t.pop(),n.pop(),o};function r(e,r){for(var u=Object.keys(e),o=new Array(u.length),i=0;i!e,Qr=e=>e&&"object"==typeof e&&!Array.isArray(e),eu=(e,t,n)=>{(Array.isArray(t)?t:[t]).forEach((t=>{if(t)throw new Error(`Problem with log4js configuration: (${Kr.inspect(e,{depth:5})}) - ${n}`)}))};var tu={configure:e=>{qr("New configuration to be validated: ",e),eu(e,Zr(Qr(e)),"must be an object."),qr(`Calling pre-processing listeners (${Yr.length})`),Yr.forEach((t=>t(e))),qr("Configuration pre-processing finished."),qr(`Calling configuration listeners (${Xr.length})`),Xr.forEach((t=>t(e))),qr("Configuration finished.")},addListener:e=>{Xr.push(e),qr(`Added listener, now ${Xr.length} listeners`)},addPreProcessingListener:e=>{Yr.push(e),qr(`Added pre-processing listener, now ${Yr.length} listeners`)},throwExceptionIf:eu,anObject:Qr,anInteger:e=>e&&"number"==typeof e&&Number.isInteger(e),validIdentifier:e=>/^[A-Za-z][A-Za-z0-9_]*$/g.test(e),not:Zr},nu={exports:{}};!function(e){function t(e,t){for(var n=e.toString();n.length-1?s:c,l=n(u.getHours()),f=n(u.getMinutes()),d=n(u.getSeconds()),D=t(u.getMilliseconds(),3),p=function(e){var t=Math.abs(e),n=String(Math.floor(t/60)),r=String(t%60);return n=("0"+n).slice(-2),r=("0"+r).slice(-2),0===e?"Z":(e<0?"+":"-")+n+":"+r}(u.getTimezoneOffset());return r.replace(/dd/g,o).replace(/MM/g,i).replace(/y{1,4}/g,a).replace(/hh/g,l).replace(/mm/g,f).replace(/ss/g,d).replace(/SSS/g,D).replace(/O/g,p)}function u(e,t,n,r){e["set"+(r?"":"UTC")+t](n)}e.exports=r,e.exports.asString=r,e.exports.parse=function(t,n,r){if(!t)throw new Error("pattern must be supplied");return function(t,n,r){var o=t.indexOf("O")<0,i=!1,s=[{pattern:/y{1,4}/,regexp:"\\d{1,4}",fn:function(e,t){u(e,"FullYear",t,o)}},{pattern:/MM/,regexp:"\\d{1,2}",fn:function(e,t){u(e,"Month",t-1,o),e.getMonth()!==t-1&&(i=!0)}},{pattern:/dd/,regexp:"\\d{1,2}",fn:function(e,t){i&&u(e,"Month",e.getMonth()-1,o),u(e,"Date",t,o)}},{pattern:/hh/,regexp:"\\d{1,2}",fn:function(e,t){u(e,"Hours",t,o)}},{pattern:/mm/,regexp:"\\d\\d",fn:function(e,t){u(e,"Minutes",t,o)}},{pattern:/ss/,regexp:"\\d\\d",fn:function(e,t){u(e,"Seconds",t,o)}},{pattern:/SSS/,regexp:"\\d\\d\\d",fn:function(e,t){u(e,"Milliseconds",t,o)}},{pattern:/O/,regexp:"[+-]\\d{1,2}:?\\d{2}?|Z",fn:function(e,t){t="Z"===t?0:t.replace(":","");var n=Math.abs(t),r=(t>0?-1:1)*(n%100+60*Math.floor(n/100));e.setUTCMinutes(e.getUTCMinutes()+r)}}],c=s.reduce((function(e,t){return t.pattern.test(e.regexp)?(t.index=e.regexp.match(t.pattern).index,e.regexp=e.regexp.replace(t.pattern,"("+t.regexp+")")):t.index=-1,e}),{regexp:t,index:[]}),a=s.filter((function(e){return e.index>-1}));a.sort((function(e,t){return e.index-t.index}));var l=new RegExp(c.regexp).exec(n);if(l){var f=r||e.exports.now();return a.forEach((function(e,t){e.fn(f,l[t+1])})),f}throw new Error("String '"+n+"' could not be parsed as '"+t+"'")}(t,n,r)},e.exports.now=function(){return new Date},e.exports.ISO8601_FORMAT="yyyy-MM-ddThh:mm:ss.SSS",e.exports.ISO8601_WITH_TZ_OFFSET_FORMAT="yyyy-MM-ddThh:mm:ss.SSSO",e.exports.DATETIME_FORMAT="dd MM yyyy hh:mm:ss.SSS",e.exports.ABSOLUTETIME_FORMAT="hh:mm:ss.SSS"}(nu);const ru=nu.exports,uu=E.default,ou=F.default,iu=p.default,su={bold:[1,22],italic:[3,23],underline:[4,24],inverse:[7,27],white:[37,39],grey:[90,39],black:[90,39],blue:[34,39],cyan:[36,39],green:[32,39],magenta:[35,39],red:[91,39],yellow:[33,39]};function cu(e){return e?`[${su[e][0]}m`:""}function au(e){return e?`[${su[e][1]}m`:""}function lu(e,t){return n=ou.format("[%s] [%s] %s - ",ru.asString(e.startTime),e.level.toString(),e.categoryName),cu(r=t)+n+au(r);var n,r}function fu(e){return lu(e)+ou.format(...e.data)}function du(e){return lu(e,e.level.colour)+ou.format(...e.data)}function Du(e){return ou.format(...e.data)}function pu(e){return e.data[0]}function Eu(e,t){const n=/%(-?[0-9]+)?(\.?-?[0-9]+)?([[\]cdhmnprzxXyflos%])(\{([^}]+)\})?|([^%]+)/;function r(e){return e&&e.pid?e.pid.toString():process.pid.toString()}e=e||"%r %p %c - %m%n";const u={c:function(e,t){let n=e.categoryName;if(t){const e=parseInt(t,10),r=n.split(".");ee&&(n=r.slice(-e).join(iu.sep))}return n},l:function(e){return e.lineNumber?`${e.lineNumber}`:""},o:function(e){return e.columnNumber?`${e.columnNumber}`:""},s:function(e){return e.callStack||""}};function o(e,t,n){return u[e](t,n)}function i(e,t,n){let r=e;return r=function(e,t){let n;return e?(n=parseInt(e.substr(1),10),n>0?t.slice(0,n):t.slice(n)):t}(t,r),r=function(e,t){let n;if(e)if("-"===e.charAt(0))for(n=parseInt(e.substr(1),10);t.lengthDu,basic:()=>fu,colored:()=>du,coloured:()=>du,pattern:e=>Eu(e&&e.pattern,e&&e.tokens),dummy:()=>pu};var hu={basicLayout:fu,messagePassThroughLayout:Du,patternLayout:Eu,colouredLayout:du,coloredLayout:du,dummyLayout:pu,addLayout(e,t){mu[e]=t},layout:(e,t)=>mu[e]&&mu[e](t)};const yu=tu,Cu=["white","grey","black","blue","cyan","green","magenta","red","yellow"];class Fu{constructor(e,t,n){this.level=e,this.levelStr=t,this.colour=n}toString(){return this.levelStr}static getLevel(e,t){return e?e instanceof Fu?e:(e instanceof Object&&e.levelStr&&(e=e.levelStr),Fu[e.toString().toUpperCase()]||t):t}static addLevels(e){if(e){Object.keys(e).forEach((t=>{const n=t.toUpperCase();Fu[n]=new Fu(e[t].value,n,e[t].colour);const r=Fu.levels.findIndex((e=>e.levelStr===n));r>-1?Fu.levels[r]=Fu[n]:Fu.levels.push(Fu[n])})),Fu.levels.sort(((e,t)=>e.level-t.level))}}isLessThanOrEqualTo(e){return"string"==typeof e&&(e=Fu.getLevel(e)),this.level<=e.level}isGreaterThanOrEqualTo(e){return"string"==typeof e&&(e=Fu.getLevel(e)),this.level>=e.level}isEqualTo(e){return"string"==typeof e&&(e=Fu.getLevel(e)),this.level===e.level}}Fu.levels=[],Fu.addLevels({ALL:{value:Number.MIN_VALUE,colour:"grey"},TRACE:{value:5e3,colour:"blue"},DEBUG:{value:1e4,colour:"cyan"},INFO:{value:2e4,colour:"green"},WARN:{value:3e4,colour:"yellow"},ERROR:{value:4e4,colour:"red"},FATAL:{value:5e4,colour:"magenta"},MARK:{value:9007199254740992,colour:"grey"},OFF:{value:Number.MAX_VALUE,colour:"grey"}}),yu.addListener((e=>{const t=e.levels;if(t){yu.throwExceptionIf(e,yu.not(yu.anObject(t)),"levels must be an object");Object.keys(t).forEach((n=>{yu.throwExceptionIf(e,yu.not(yu.validIdentifier(n)),`level name "${n}" is not a valid identifier (must start with a letter, only contain A-Z,a-z,0-9,_)`),yu.throwExceptionIf(e,yu.not(yu.anObject(t[n])),`level "${n}" must be an object`),yu.throwExceptionIf(e,yu.not(t[n].value),`level "${n}" must have a 'value' property`),yu.throwExceptionIf(e,yu.not(yu.anInteger(t[n].value)),`level "${n}".value must have an integer value`),yu.throwExceptionIf(e,yu.not(t[n].colour),`level "${n}" must have a 'colour' property`),yu.throwExceptionIf(e,yu.not(Cu.indexOf(t[n].colour)>-1),`level "${n}".colour must be one of ${Cu.join(", ")}`)}))}})),yu.addListener((e=>{Fu.addLevels(e.levels)}));var gu=Fu,Au={exports:{}},vu={};/*! (c) 2020 Andrea Giammarchi */ -const{parse:Su,stringify:wu}=JSON,{keys:Ou}=Object,bu=String,_u="string",Bu={},Pu="object",ku=(e,t)=>t,xu=e=>e instanceof bu?bu(e):e,Nu=(e,t)=>typeof t===_u?new bu(t):t,Iu=(e,t,n,r)=>{const u=[];for(let o=Ou(n),{length:i}=o,s=0;s{const r=bu(t.push(n)-1);return e.set(n,r),r},Ru=(e,t)=>{const n=Su(e,Nu).map(xu),r=n[0],u=t||ku,o=typeof r===Pu&&r?Iu(n,new Set,r,u):r;return u.call({"":o},"",o)};vu.parse=Ru;const Mu=(e,t,n)=>{const r=t&&typeof t===Pu?(e,n)=>""===e||-1Su(Mu(e));vu.fromJSON=e=>Ru(wu(e));const Lu=vu,ju=gu;class $u{constructor(e,t,n,r,u){this.startTime=new Date,this.categoryName=e,this.data=n,this.level=t,this.context=Object.assign({},r),this.pid=process.pid,u&&(this.functionName=u.functionName,this.fileName=u.fileName,this.lineNumber=u.lineNumber,this.columnNumber=u.columnNumber,this.callStack=u.callStack)}serialise(){const e=this.data.map((e=>(e&&e.message&&e.stack&&(e=Object.assign({message:e.message,stack:e.stack},e)),e)));return this.data=e,Lu.stringify(this)}static deserialise(e){let t;try{const n=Lu.parse(e);n.data=n.data.map((e=>{if(e&&e.message&&e.stack){const t=new Error(e);Object.keys(e).forEach((n=>{t[n]=e[n]})),e=t}return e})),t=new $u(n.categoryName,ju.getLevel(n.level.levelStr),n.data,n.context),t.startTime=new Date(n.startTime),t.pid=n.pid,t.cluster=n.cluster}catch(n){t=new $u("log4js",ju.ERROR,["Unable to parse log:",e,"because: ",n])}return t}}var Hu=$u;const Ju=Nr.exports("log4js:clustering"),Gu=Hu,Vu=tu;let Uu=!1,Wu=null;try{Wu=require("cluster")}catch(e){Ju("cluster module not present"),Uu=!0}const zu=[];let Ku=!1,qu="NODE_APP_INSTANCE";const Yu=()=>Ku&&"0"===process.env[qu],Xu=()=>Uu||Wu.isMaster||Yu(),Zu=e=>{zu.forEach((t=>t(e)))},Qu=(e,t)=>{if(Ju("cluster message received from worker ",e,": ",t),e.topic&&e.data&&(t=e,e=void 0),t&&t.topic&&"log4js:message"===t.topic){Ju("received message: ",t.data);const e=Gu.deserialise(t.data);Zu(e)}};Uu||Vu.addListener((e=>{zu.length=0,({pm2:Ku,disableClustering:Uu,pm2InstanceVar:qu="NODE_APP_INSTANCE"}=e),Ju(`clustering disabled ? ${Uu}`),Ju(`cluster.isMaster ? ${Wu&&Wu.isMaster}`),Ju(`pm2 enabled ? ${Ku}`),Ju(`pm2InstanceVar = ${qu}`),Ju(`process.env[${qu}] = ${process.env[qu]}`),Ku&&process.removeListener("message",Qu),Wu&&Wu.removeListener&&Wu.removeListener("message",Qu),Uu||e.disableClustering?Ju("Not listening for cluster messages, because clustering disabled."):Yu()?(Ju("listening for PM2 broadcast messages"),process.on("message",Qu)):Wu.isMaster?(Ju("listening for cluster messages"),Wu.on("message",Qu)):Ju("not listening for messages, because we are not a master process")}));var eo={onlyOnMaster:(e,t)=>Xu()?e():t,isMaster:Xu,send:e=>{Xu()?Zu(e):(Ku||(e.cluster={workerId:Wu.worker.id,worker:process.pid}),process.send({topic:"log4js:message",data:e.serialise()}))},onMessage:e=>{zu.push(e)}},to={};function no(e){if("number"==typeof e&&Number.isInteger(e))return e;const t={K:1024,M:1048576,G:1073741824},n=Object.keys(t),r=e.substr(e.length-1).toLocaleUpperCase(),u=e.substring(0,e.length-1).trim();if(n.indexOf(r)<0||!Number.isInteger(Number(u)))throw Error(`maxLogSize: "${e}" is invalid`);return u*t[r]}function ro(e){return function(e,t){const n=Object.assign({},t);return Object.keys(e).forEach((r=>{n[r]&&(n[r]=e[r](t[r]))})),n}({maxLogSize:no},e)}const uo={file:ro,fileSync:ro};to.modifyConfig=e=>uo[e.type]?uo[e.type](e):e;var oo={};const io=console.log.bind(console);oo.configure=function(e,t){let n=t.colouredLayout;return e.layout&&(n=t.layout(e.layout.type,e.layout)),function(e,t){return n=>{io(e(n,t))}}(n,e.timezoneOffset)};var so={};so.configure=function(e,t){let n=t.colouredLayout;return e.layout&&(n=t.layout(e.layout.type,e.layout)),function(e,t){return n=>{process.stdout.write(`${e(n,t)}\n`)}}(n,e.timezoneOffset)};var co={};co.configure=function(e,t){let n=t.colouredLayout;return e.layout&&(n=t.layout(e.layout.type,e.layout)),function(e,t){return n=>{process.stderr.write(`${e(n,t)}\n`)}}(n,e.timezoneOffset)};var ao={};ao.configure=function(e,t,n,r){const u=n(e.appender);return function(e,t,n,r){const u=r.getLevel(e),o=r.getLevel(t,r.FATAL);return e=>{const t=e.level;t.isGreaterThanOrEqualTo(u)&&t.isLessThanOrEqualTo(o)&&n(e)}}(e.level,e.maxLevel,u,r)};var lo={};const fo=Nr.exports("log4js:categoryFilter");lo.configure=function(e,t,n){const r=n(e.appender);return function(e,t){return"string"==typeof e&&(e=[e]),n=>{fo(`Checking ${n.categoryName} against ${e}`),-1===e.indexOf(n.categoryName)&&(fo("Not excluded, sending to appender"),t(n))}}(e.exclude,r)};var Do={};const po=Nr.exports("log4js:noLogFilter");Do.configure=function(e,t,n){const r=n(e.appender);return function(e,t){return n=>{po(`Checking data: ${n.data} against filters: ${e}`),"string"==typeof e&&(e=[e]),e=e.filter((e=>null!=e&&""!==e));const r=new RegExp(e.join("|"),"i");(0===e.length||n.data.findIndex((e=>r.test(e)))<0)&&(po("Not excluded, sending to appender"),t(n))}}(e.exclude,r)};var Eo={},mo={exports:{}},ho={},yo={fromCallback:function(e){return Object.defineProperty((function(){if("function"!=typeof arguments[arguments.length-1])return new Promise(((t,n)=>{arguments[arguments.length]=(e,r)=>{if(e)return n(e);t(r)},arguments.length++,e.apply(this,arguments)}));e.apply(this,arguments)}),"name",{value:e.name})},fromPromise:function(e){return Object.defineProperty((function(){const t=arguments[arguments.length-1];if("function"!=typeof t)return e.apply(this,arguments);e.apply(this,arguments).then((e=>t(null,e)),t)}),"name",{value:e.name})}};!function(e){const t=yo.fromCallback,n=we,r=["access","appendFile","chmod","chown","close","copyFile","fchmod","fchown","fdatasync","fstat","fsync","ftruncate","futimes","lchown","lchmod","link","lstat","mkdir","mkdtemp","open","readFile","readdir","readlink","realpath","rename","rmdir","stat","symlink","truncate","unlink","utimes","writeFile"].filter((e=>"function"==typeof n[e]));Object.keys(n).forEach((t=>{"promises"!==t&&(e[t]=n[t])})),r.forEach((r=>{e[r]=t(n[r])})),e.exists=function(e,t){return"function"==typeof t?n.exists(e,t):new Promise((t=>n.exists(e,t)))},e.read=function(e,t,r,u,o,i){return"function"==typeof i?n.read(e,t,r,u,o,i):new Promise(((i,s)=>{n.read(e,t,r,u,o,((e,t,n)=>{if(e)return s(e);i({bytesRead:t,buffer:n})}))}))},e.write=function(e,t,...r){return"function"==typeof r[r.length-1]?n.write(e,t,...r):new Promise(((u,o)=>{n.write(e,t,...r,((e,t,n)=>{if(e)return o(e);u({bytesWritten:t,buffer:n})}))}))},"function"==typeof n.realpath.native&&(e.realpath.native=t(n.realpath.native))}(ho);const Co=p.default;function Fo(e){return(e=Co.normalize(Co.resolve(e)).split(Co.sep)).length>0?e[0]:null}const go=/[<>:"|?*]/;var Ao=function(e){const t=Fo(e);return e=e.replace(t,""),go.test(e)};const vo=we,So=p.default,wo=Ao,Oo=parseInt("0777",8);var bo=function e(t,n,r,u){if("function"==typeof n?(r=n,n={}):n&&"object"==typeof n||(n={mode:n}),"win32"===process.platform&&wo(t)){const e=new Error(t+" contains invalid WIN32 path characters.");return e.code="EINVAL",r(e)}let o=n.mode;const i=n.fs||vo;void 0===o&&(o=Oo&~process.umask()),u||(u=null),r=r||function(){},t=So.resolve(t),i.mkdir(t,o,(o=>{if(!o)return r(null,u=u||t);if("ENOENT"===o.code){if(So.dirname(t)===t)return r(o);e(So.dirname(t),n,((u,o)=>{u?r(u,o):e(t,n,r,o)}))}else i.stat(t,((e,t)=>{e||!t.isDirectory()?r(o,u):r(null,u)}))}))};const _o=we,Bo=p.default,Po=Ao,ko=parseInt("0777",8);var xo=function e(t,n,r){n&&"object"==typeof n||(n={mode:n});let u=n.mode;const o=n.fs||_o;if("win32"===process.platform&&Po(t)){const e=new Error(t+" contains invalid WIN32 path characters.");throw e.code="EINVAL",e}void 0===u&&(u=ko&~process.umask()),r||(r=null),t=Bo.resolve(t);try{o.mkdirSync(t,u),r=r||t}catch(u){if("ENOENT"===u.code){if(Bo.dirname(t)===t)throw u;r=e(Bo.dirname(t),n,r),e(t,n,r)}else{let e;try{e=o.statSync(t)}catch(e){throw u}if(!e.isDirectory())throw u}}return r};const No=(0,yo.fromCallback)(bo);var Io={mkdirs:No,mkdirsSync:xo,mkdirp:No,mkdirpSync:xo,ensureDir:No,ensureDirSync:xo};const To=we;E.default,p.default;var Ro=function(e,t,n,r){To.open(e,"r+",((e,u)=>{if(e)return r(e);To.futimes(u,t,n,(e=>{To.close(u,(t=>{r&&r(e||t)}))}))}))},Mo=function(e,t,n){const r=To.openSync(e,"r+");return To.futimesSync(r,t,n),To.closeSync(r)};const Lo=we,jo=p.default,$o=10,Ho=5,Jo=0,Go=process.versions.node.split("."),Vo=Number.parseInt(Go[0],10),Uo=Number.parseInt(Go[1],10),Wo=Number.parseInt(Go[2],10);function zo(){if(Vo>$o)return!0;if(Vo===$o){if(Uo>Ho)return!0;if(Uo===Ho&&Wo>=Jo)return!0}return!1}function Ko(e,t){const n=jo.resolve(e).split(jo.sep).filter((e=>e)),r=jo.resolve(t).split(jo.sep).filter((e=>e));return n.reduce(((e,t,n)=>e&&r[n]===t),!0)}function qo(e,t,n){return`Cannot ${n} '${e}' to a subdirectory of itself, '${t}'.`}var Yo,Xo,Zo={checkPaths:function(e,t,n,r){!function(e,t,n){zo()?Lo.stat(e,{bigint:!0},((e,r)=>{if(e)return n(e);Lo.stat(t,{bigint:!0},((e,t)=>e?"ENOENT"===e.code?n(null,{srcStat:r,destStat:null}):n(e):n(null,{srcStat:r,destStat:t})))})):Lo.stat(e,((e,r)=>{if(e)return n(e);Lo.stat(t,((e,t)=>e?"ENOENT"===e.code?n(null,{srcStat:r,destStat:null}):n(e):n(null,{srcStat:r,destStat:t})))}))}(e,t,((u,o)=>{if(u)return r(u);const{srcStat:i,destStat:s}=o;return s&&s.ino&&s.dev&&s.ino===i.ino&&s.dev===i.dev?r(new Error("Source and destination must not be the same.")):i.isDirectory()&&Ko(e,t)?r(new Error(qo(e,t,n))):r(null,{srcStat:i,destStat:s})}))},checkPathsSync:function(e,t,n){const{srcStat:r,destStat:u}=function(e,t){let n,r;n=zo()?Lo.statSync(e,{bigint:!0}):Lo.statSync(e);try{r=zo()?Lo.statSync(t,{bigint:!0}):Lo.statSync(t)}catch(e){if("ENOENT"===e.code)return{srcStat:n,destStat:null};throw e}return{srcStat:n,destStat:r}}(e,t);if(u&&u.ino&&u.dev&&u.ino===r.ino&&u.dev===r.dev)throw new Error("Source and destination must not be the same.");if(r.isDirectory()&&Ko(e,t))throw new Error(qo(e,t,n));return{srcStat:r,destStat:u}},checkParentPaths:function e(t,n,r,u,o){const i=jo.resolve(jo.dirname(t)),s=jo.resolve(jo.dirname(r));if(s===i||s===jo.parse(s).root)return o();zo()?Lo.stat(s,{bigint:!0},((i,c)=>i?"ENOENT"===i.code?o():o(i):c.ino&&c.dev&&c.ino===n.ino&&c.dev===n.dev?o(new Error(qo(t,r,u))):e(t,n,s,u,o))):Lo.stat(s,((i,c)=>i?"ENOENT"===i.code?o():o(i):c.ino&&c.dev&&c.ino===n.ino&&c.dev===n.dev?o(new Error(qo(t,r,u))):e(t,n,s,u,o)))},checkParentPathsSync:function e(t,n,r,u){const o=jo.resolve(jo.dirname(t)),i=jo.resolve(jo.dirname(r));if(i===o||i===jo.parse(i).root)return;let s;try{s=zo()?Lo.statSync(i,{bigint:!0}):Lo.statSync(i)}catch(e){if("ENOENT"===e.code)return;throw e}if(s.ino&&s.dev&&s.ino===n.ino&&s.dev===n.dev)throw new Error(qo(t,r,u));return e(t,n,i,u)},isSrcSubdir:Ko};const Qo=we,ei=p.default,ti=Io.mkdirsSync,ni=Mo,ri=Zo;function ui(e,t,n,r){if(!r.filter||r.filter(t,n))return function(e,t,n,r){const u=r.dereference?Qo.statSync:Qo.lstatSync,o=u(t);if(o.isDirectory())return function(e,t,n,r,u){if(!t)return function(e,t,n,r){return Qo.mkdirSync(n),ii(t,n,r),Qo.chmodSync(n,e.mode)}(e,n,r,u);if(t&&!t.isDirectory())throw new Error(`Cannot overwrite non-directory '${r}' with directory '${n}'.`);return ii(n,r,u)}(o,e,t,n,r);if(o.isFile()||o.isCharacterDevice()||o.isBlockDevice())return function(e,t,n,r,u){return t?function(e,t,n,r){if(r.overwrite)return Qo.unlinkSync(n),oi(e,t,n,r);if(r.errorOnExist)throw new Error(`'${n}' already exists`)}(e,n,r,u):oi(e,n,r,u)}(o,e,t,n,r);if(o.isSymbolicLink())return function(e,t,n,r){let u=Qo.readlinkSync(t);r.dereference&&(u=ei.resolve(process.cwd(),u));if(e){let e;try{e=Qo.readlinkSync(n)}catch(e){if("EINVAL"===e.code||"UNKNOWN"===e.code)return Qo.symlinkSync(u,n);throw e}if(r.dereference&&(e=ei.resolve(process.cwd(),e)),ri.isSrcSubdir(u,e))throw new Error(`Cannot copy '${u}' to a subdirectory of itself, '${e}'.`);if(Qo.statSync(n).isDirectory()&&ri.isSrcSubdir(e,u))throw new Error(`Cannot overwrite '${e}' with '${u}'.`);return function(e,t){return Qo.unlinkSync(t),Qo.symlinkSync(e,t)}(u,n)}return Qo.symlinkSync(u,n)}(e,t,n,r)}(e,t,n,r)}function oi(e,t,n,r){return"function"==typeof Qo.copyFileSync?(Qo.copyFileSync(t,n),Qo.chmodSync(n,e.mode),r.preserveTimestamps?ni(n,e.atime,e.mtime):void 0):function(e,t,n,r){const u=65536,o=(Xo?Yo:(Xo=1,Yo=function(e){if("function"==typeof Buffer.allocUnsafe)try{return Buffer.allocUnsafe(e)}catch(t){return new Buffer(e)}return new Buffer(e)}))(u),i=Qo.openSync(t,"r"),s=Qo.openSync(n,"w",e.mode);let c=0;for(;cfunction(e,t,n,r){const u=ei.join(t,e),o=ei.join(n,e),{destStat:i}=ri.checkPathsSync(u,o,"copy");return ui(i,u,o,r)}(r,e,t,n)))}var si=function(e,t,n){"function"==typeof n&&(n={filter:n}),(n=n||{}).clobber=!("clobber"in n)||!!n.clobber,n.overwrite="overwrite"in n?!!n.overwrite:n.clobber,n.preserveTimestamps&&"ia32"===process.arch&&console.warn("fs-extra: Using the preserveTimestamps option in 32-bit node is not recommended;\n\n see https://github.com/jprichardson/node-fs-extra/issues/269");const{srcStat:r,destStat:u}=ri.checkPathsSync(e,t,"copy");return ri.checkParentPathsSync(e,r,t,"copy"),function(e,t,n,r){if(r.filter&&!r.filter(t,n))return;const u=ei.dirname(n);Qo.existsSync(u)||ti(u);return ui(e,t,n,r)}(u,e,t,n)},ci={copySync:si};const ai=yo.fromPromise,li=ho;var fi={pathExists:ai((function(e){return li.access(e).then((()=>!0)).catch((()=>!1))})),pathExistsSync:li.existsSync};const di=we,Di=p.default,pi=Io.mkdirs,Ei=fi.pathExists,mi=Ro,hi=Zo;function yi(e,t,n,r,u){const o=Di.dirname(n);Ei(o,((i,s)=>i?u(i):s?Fi(e,t,n,r,u):void pi(o,(o=>o?u(o):Fi(e,t,n,r,u)))))}function Ci(e,t,n,r,u,o){Promise.resolve(u.filter(n,r)).then((i=>i?e(t,n,r,u,o):o()),(e=>o(e)))}function Fi(e,t,n,r,u){return r.filter?Ci(gi,e,t,n,r,u):gi(e,t,n,r,u)}function gi(e,t,n,r,u){(r.dereference?di.stat:di.lstat)(t,((o,i)=>o?u(o):i.isDirectory()?function(e,t,n,r,u,o){if(!t)return function(e,t,n,r,u){di.mkdir(n,(o=>{if(o)return u(o);Si(t,n,r,(t=>t?u(t):di.chmod(n,e.mode,u)))}))}(e,n,r,u,o);if(t&&!t.isDirectory())return o(new Error(`Cannot overwrite non-directory '${r}' with directory '${n}'.`));return Si(n,r,u,o)}(i,e,t,n,r,u):i.isFile()||i.isCharacterDevice()||i.isBlockDevice()?function(e,t,n,r,u,o){return t?function(e,t,n,r,u){if(!r.overwrite)return r.errorOnExist?u(new Error(`'${n}' already exists`)):u();di.unlink(n,(o=>o?u(o):Ai(e,t,n,r,u)))}(e,n,r,u,o):Ai(e,n,r,u,o)}(i,e,t,n,r,u):i.isSymbolicLink()?function(e,t,n,r,u){di.readlink(t,((t,o)=>t?u(t):(r.dereference&&(o=Di.resolve(process.cwd(),o)),e?void di.readlink(n,((t,i)=>t?"EINVAL"===t.code||"UNKNOWN"===t.code?di.symlink(o,n,u):u(t):(r.dereference&&(i=Di.resolve(process.cwd(),i)),hi.isSrcSubdir(o,i)?u(new Error(`Cannot copy '${o}' to a subdirectory of itself, '${i}'.`)):e.isDirectory()&&hi.isSrcSubdir(i,o)?u(new Error(`Cannot overwrite '${i}' with '${o}'.`)):function(e,t,n){di.unlink(t,(r=>r?n(r):di.symlink(e,t,n)))}(o,n,u)))):di.symlink(o,n,u))))}(e,t,n,r,u):void 0))}function Ai(e,t,n,r,u){return"function"==typeof di.copyFile?di.copyFile(t,n,(t=>t?u(t):vi(e,n,r,u))):function(e,t,n,r,u){const o=di.createReadStream(t);o.on("error",(e=>u(e))).once("open",(()=>{const t=di.createWriteStream(n,{mode:e.mode});t.on("error",(e=>u(e))).on("open",(()=>o.pipe(t))).once("close",(()=>vi(e,n,r,u)))}))}(e,t,n,r,u)}function vi(e,t,n,r){di.chmod(t,e.mode,(u=>u?r(u):n.preserveTimestamps?mi(t,e.atime,e.mtime,r):r()))}function Si(e,t,n,r){di.readdir(e,((u,o)=>u?r(u):wi(o,e,t,n,r)))}function wi(e,t,n,r,u){const o=e.pop();return o?function(e,t,n,r,u,o){const i=Di.join(n,t),s=Di.join(r,t);hi.checkPaths(i,s,"copy",((t,c)=>{if(t)return o(t);const{destStat:a}=c;Fi(a,i,s,u,(t=>t?o(t):wi(e,n,r,u,o)))}))}(e,o,t,n,r,u):u()}var Oi=function(e,t,n,r){"function"!=typeof n||r?"function"==typeof n&&(n={filter:n}):(r=n,n={}),r=r||function(){},(n=n||{}).clobber=!("clobber"in n)||!!n.clobber,n.overwrite="overwrite"in n?!!n.overwrite:n.clobber,n.preserveTimestamps&&"ia32"===process.arch&&console.warn("fs-extra: Using the preserveTimestamps option in 32-bit node is not recommended;\n\n see https://github.com/jprichardson/node-fs-extra/issues/269"),hi.checkPaths(e,t,"copy",((u,o)=>{if(u)return r(u);const{srcStat:i,destStat:s}=o;hi.checkParentPaths(e,i,t,"copy",(u=>u?r(u):n.filter?Ci(yi,s,e,t,n,r):yi(s,e,t,n,r)))}))};var bi={copy:(0,yo.fromCallback)(Oi)};const _i=we,Bi=p.default,Pi=g.default,ki="win32"===process.platform;function xi(e){["unlink","chmod","stat","lstat","rmdir","readdir"].forEach((t=>{e[t]=e[t]||_i[t],e[t+="Sync"]=e[t]||_i[t]})),e.maxBusyTries=e.maxBusyTries||3}function Ni(e,t,n){let r=0;"function"==typeof t&&(n=t,t={}),Pi(e,"rimraf: missing path"),Pi.strictEqual(typeof e,"string","rimraf: path should be a string"),Pi.strictEqual(typeof n,"function","rimraf: callback function required"),Pi(t,"rimraf: invalid options argument provided"),Pi.strictEqual(typeof t,"object","rimraf: options should be object"),xi(t),Ii(e,t,(function u(o){if(o){if(("EBUSY"===o.code||"ENOTEMPTY"===o.code||"EPERM"===o.code)&&rIi(e,t,u)),100*r)}"ENOENT"===o.code&&(o=null)}n(o)}))}function Ii(e,t,n){Pi(e),Pi(t),Pi("function"==typeof n),t.lstat(e,((r,u)=>r&&"ENOENT"===r.code?n(null):r&&"EPERM"===r.code&&ki?Ti(e,t,r,n):u&&u.isDirectory()?Mi(e,t,r,n):void t.unlink(e,(r=>{if(r){if("ENOENT"===r.code)return n(null);if("EPERM"===r.code)return ki?Ti(e,t,r,n):Mi(e,t,r,n);if("EISDIR"===r.code)return Mi(e,t,r,n)}return n(r)}))))}function Ti(e,t,n,r){Pi(e),Pi(t),Pi("function"==typeof r),n&&Pi(n instanceof Error),t.chmod(e,438,(u=>{u?r("ENOENT"===u.code?null:n):t.stat(e,((u,o)=>{u?r("ENOENT"===u.code?null:n):o.isDirectory()?Mi(e,t,n,r):t.unlink(e,r)}))}))}function Ri(e,t,n){let r;Pi(e),Pi(t),n&&Pi(n instanceof Error);try{t.chmodSync(e,438)}catch(e){if("ENOENT"===e.code)return;throw n}try{r=t.statSync(e)}catch(e){if("ENOENT"===e.code)return;throw n}r.isDirectory()?ji(e,t,n):t.unlinkSync(e)}function Mi(e,t,n,r){Pi(e),Pi(t),n&&Pi(n instanceof Error),Pi("function"==typeof r),t.rmdir(e,(u=>{!u||"ENOTEMPTY"!==u.code&&"EEXIST"!==u.code&&"EPERM"!==u.code?u&&"ENOTDIR"===u.code?r(n):r(u):function(e,t,n){Pi(e),Pi(t),Pi("function"==typeof n),t.readdir(e,((r,u)=>{if(r)return n(r);let o,i=u.length;if(0===i)return t.rmdir(e,n);u.forEach((r=>{Ni(Bi.join(e,r),t,(r=>{if(!o)return r?n(o=r):void(0==--i&&t.rmdir(e,n))}))}))}))}(e,t,r)}))}function Li(e,t){let n;xi(t=t||{}),Pi(e,"rimraf: missing path"),Pi.strictEqual(typeof e,"string","rimraf: path should be a string"),Pi(t,"rimraf: missing options"),Pi.strictEqual(typeof t,"object","rimraf: options should be object");try{n=t.lstatSync(e)}catch(n){if("ENOENT"===n.code)return;"EPERM"===n.code&&ki&&Ri(e,t,n)}try{n&&n.isDirectory()?ji(e,t,null):t.unlinkSync(e)}catch(n){if("ENOENT"===n.code)return;if("EPERM"===n.code)return ki?Ri(e,t,n):ji(e,t,n);if("EISDIR"!==n.code)throw n;ji(e,t,n)}}function ji(e,t,n){Pi(e),Pi(t),n&&Pi(n instanceof Error);try{t.rmdirSync(e)}catch(r){if("ENOTDIR"===r.code)throw n;if("ENOTEMPTY"===r.code||"EEXIST"===r.code||"EPERM"===r.code)!function(e,t){if(Pi(e),Pi(t),t.readdirSync(e).forEach((n=>Li(Bi.join(e,n),t))),!ki){return t.rmdirSync(e,t)}{const n=Date.now();do{try{return t.rmdirSync(e,t)}catch(e){}}while(Date.now()-n<500)}}(e,t);else if("ENOENT"!==r.code)throw r}}var $i=Ni;Ni.sync=Li;const Hi=$i;var Ji={remove:(0,yo.fromCallback)(Hi),removeSync:Hi.sync};const Gi=yo.fromCallback,Vi=we,Ui=p.default,Wi=Io,zi=Ji,Ki=Gi((function(e,t){t=t||function(){},Vi.readdir(e,((n,r)=>{if(n)return Wi.mkdirs(e,t);r=r.map((t=>Ui.join(e,t))),function e(){const n=r.pop();if(!n)return t();zi.remove(n,(n=>{if(n)return t(n);e()}))}()}))}));function qi(e){let t;try{t=Vi.readdirSync(e)}catch(t){return Wi.mkdirsSync(e)}t.forEach((t=>{t=Ui.join(e,t),zi.removeSync(t)}))}var Yi={emptyDirSync:qi,emptydirSync:qi,emptyDir:Ki,emptydir:Ki};const Xi=yo.fromCallback,Zi=p.default,Qi=we,es=Io,ts=fi.pathExists;var ns={createFile:Xi((function(e,t){function n(){Qi.writeFile(e,"",(e=>{if(e)return t(e);t()}))}Qi.stat(e,((r,u)=>{if(!r&&u.isFile())return t();const o=Zi.dirname(e);ts(o,((e,r)=>e?t(e):r?n():void es.mkdirs(o,(e=>{if(e)return t(e);n()}))))}))})),createFileSync:function(e){let t;try{t=Qi.statSync(e)}catch(e){}if(t&&t.isFile())return;const n=Zi.dirname(e);Qi.existsSync(n)||es.mkdirsSync(n),Qi.writeFileSync(e,"")}};const rs=yo.fromCallback,us=p.default,os=we,is=Io,ss=fi.pathExists;var cs={createLink:rs((function(e,t,n){function r(e,t){os.link(e,t,(e=>{if(e)return n(e);n(null)}))}ss(t,((u,o)=>u?n(u):o?n(null):void os.lstat(e,(u=>{if(u)return u.message=u.message.replace("lstat","ensureLink"),n(u);const o=us.dirname(t);ss(o,((u,i)=>u?n(u):i?r(e,t):void is.mkdirs(o,(u=>{if(u)return n(u);r(e,t)}))))}))))})),createLinkSync:function(e,t){if(os.existsSync(t))return;try{os.lstatSync(e)}catch(e){throw e.message=e.message.replace("lstat","ensureLink"),e}const n=us.dirname(t);return os.existsSync(n)||is.mkdirsSync(n),os.linkSync(e,t)}};const as=p.default,ls=we,fs=fi.pathExists;var ds={symlinkPaths:function(e,t,n){if(as.isAbsolute(e))return ls.lstat(e,(t=>t?(t.message=t.message.replace("lstat","ensureSymlink"),n(t)):n(null,{toCwd:e,toDst:e})));{const r=as.dirname(t),u=as.join(r,e);return fs(u,((t,o)=>t?n(t):o?n(null,{toCwd:u,toDst:e}):ls.lstat(e,(t=>t?(t.message=t.message.replace("lstat","ensureSymlink"),n(t)):n(null,{toCwd:e,toDst:as.relative(r,e)})))))}},symlinkPathsSync:function(e,t){let n;if(as.isAbsolute(e)){if(n=ls.existsSync(e),!n)throw new Error("absolute srcpath does not exist");return{toCwd:e,toDst:e}}{const r=as.dirname(t),u=as.join(r,e);if(n=ls.existsSync(u),n)return{toCwd:u,toDst:e};if(n=ls.existsSync(e),!n)throw new Error("relative srcpath does not exist");return{toCwd:e,toDst:as.relative(r,e)}}}};const Ds=we;var ps={symlinkType:function(e,t,n){if(n="function"==typeof t?t:n,t="function"!=typeof t&&t)return n(null,t);Ds.lstat(e,((e,r)=>{if(e)return n(null,"file");t=r&&r.isDirectory()?"dir":"file",n(null,t)}))},symlinkTypeSync:function(e,t){let n;if(t)return t;try{n=Ds.lstatSync(e)}catch(e){return"file"}return n&&n.isDirectory()?"dir":"file"}};const Es=yo.fromCallback,ms=p.default,hs=we,ys=Io.mkdirs,Cs=Io.mkdirsSync,Fs=ds.symlinkPaths,gs=ds.symlinkPathsSync,As=ps.symlinkType,vs=ps.symlinkTypeSync,Ss=fi.pathExists;var ws={createSymlink:Es((function(e,t,n,r){r="function"==typeof n?n:r,n="function"!=typeof n&&n,Ss(t,((u,o)=>u?r(u):o?r(null):void Fs(e,t,((u,o)=>{if(u)return r(u);e=o.toDst,As(o.toCwd,n,((n,u)=>{if(n)return r(n);const o=ms.dirname(t);Ss(o,((n,i)=>n?r(n):i?hs.symlink(e,t,u,r):void ys(o,(n=>{if(n)return r(n);hs.symlink(e,t,u,r)}))))}))}))))})),createSymlinkSync:function(e,t,n){if(hs.existsSync(t))return;const r=gs(e,t);e=r.toDst,n=vs(r.toCwd,n);const u=ms.dirname(t);return hs.existsSync(u)||Cs(u),hs.symlinkSync(e,t,n)}};var Os,bs={createFile:ns.createFile,createFileSync:ns.createFileSync,ensureFile:ns.createFile,ensureFileSync:ns.createFileSync,createLink:cs.createLink,createLinkSync:cs.createLinkSync,ensureLink:cs.createLink,ensureLinkSync:cs.createLinkSync,createSymlink:ws.createSymlink,createSymlinkSync:ws.createSymlinkSync,ensureSymlink:ws.createSymlink,ensureSymlinkSync:ws.createSymlinkSync};try{Os=we}catch(e){Os=D.default}function _s(e,t){var n,r="\n";return"object"==typeof t&&null!==t&&(t.spaces&&(n=t.spaces),t.EOL&&(r=t.EOL)),JSON.stringify(e,t?t.replacer:null,n).replace(/\n/g,r)+r}function Bs(e){return Buffer.isBuffer(e)&&(e=e.toString("utf8")),e=e.replace(/^\uFEFF/,"")}var Ps={readFile:function(e,t,n){null==n&&(n=t,t={}),"string"==typeof t&&(t={encoding:t});var r=(t=t||{}).fs||Os,u=!0;"throws"in t&&(u=t.throws),r.readFile(e,t,(function(r,o){if(r)return n(r);var i;o=Bs(o);try{i=JSON.parse(o,t?t.reviver:null)}catch(t){return u?(t.message=e+": "+t.message,n(t)):n(null,null)}n(null,i)}))},readFileSync:function(e,t){"string"==typeof(t=t||{})&&(t={encoding:t});var n=t.fs||Os,r=!0;"throws"in t&&(r=t.throws);try{var u=n.readFileSync(e,t);return u=Bs(u),JSON.parse(u,t.reviver)}catch(t){if(r)throw t.message=e+": "+t.message,t;return null}},writeFile:function(e,t,n,r){null==r&&(r=n,n={});var u=(n=n||{}).fs||Os,o="";try{o=_s(t,n)}catch(e){return void(r&&r(e,null))}u.writeFile(e,o,n,r)},writeFileSync:function(e,t,n){var r=(n=n||{}).fs||Os,u=_s(t,n);return r.writeFileSync(e,u,n)}},ks=Ps;const xs=yo.fromCallback,Ns=ks;var Is={readJson:xs(Ns.readFile),readJsonSync:Ns.readFileSync,writeJson:xs(Ns.writeFile),writeJsonSync:Ns.writeFileSync};const Ts=p.default,Rs=Io,Ms=fi.pathExists,Ls=Is;var js=function(e,t,n,r){"function"==typeof n&&(r=n,n={});const u=Ts.dirname(e);Ms(u,((o,i)=>o?r(o):i?Ls.writeJson(e,t,n,r):void Rs.mkdirs(u,(u=>{if(u)return r(u);Ls.writeJson(e,t,n,r)}))))};const $s=we,Hs=p.default,Js=Io,Gs=Is;var Vs=function(e,t,n){const r=Hs.dirname(e);$s.existsSync(r)||Js.mkdirsSync(r),Gs.writeJsonSync(e,t,n)};const Us=yo.fromCallback,Ws=Is;Ws.outputJson=Us(js),Ws.outputJsonSync=Vs,Ws.outputJSON=Ws.outputJson,Ws.outputJSONSync=Ws.outputJsonSync,Ws.writeJSON=Ws.writeJson,Ws.writeJSONSync=Ws.writeJsonSync,Ws.readJSON=Ws.readJson,Ws.readJSONSync=Ws.readJsonSync;var zs=Ws;const Ks=we,qs=p.default,Ys=ci.copySync,Xs=Ji.removeSync,Zs=Io.mkdirpSync,Qs=Zo;function ec(e,t,n){try{Ks.renameSync(e,t)}catch(r){if("EXDEV"!==r.code)throw r;return function(e,t,n){const r={overwrite:n,errorOnExist:!0};return Ys(e,t,r),Xs(e)}(e,t,n)}}var tc=function(e,t,n){const r=(n=n||{}).overwrite||n.clobber||!1,{srcStat:u}=Qs.checkPathsSync(e,t,"move");return Qs.checkParentPathsSync(e,u,t,"move"),Zs(qs.dirname(t)),function(e,t,n){if(n)return Xs(t),ec(e,t,n);if(Ks.existsSync(t))throw new Error("dest already exists.");return ec(e,t,n)}(e,t,r)},nc={moveSync:tc};const rc=we,uc=p.default,oc=bi.copy,ic=Ji.remove,sc=Io.mkdirp,cc=fi.pathExists,ac=Zo;function lc(e,t,n,r){rc.rename(e,t,(u=>u?"EXDEV"!==u.code?r(u):function(e,t,n,r){const u={overwrite:n,errorOnExist:!0};oc(e,t,u,(t=>t?r(t):ic(e,r)))}(e,t,n,r):r()))}var fc=function(e,t,n,r){"function"==typeof n&&(r=n,n={});const u=n.overwrite||n.clobber||!1;ac.checkPaths(e,t,"move",((n,o)=>{if(n)return r(n);const{srcStat:i}=o;ac.checkParentPaths(e,i,t,"move",(n=>{if(n)return r(n);sc(uc.dirname(t),(n=>n?r(n):function(e,t,n,r){if(n)return ic(t,(u=>u?r(u):lc(e,t,n,r)));cc(t,((u,o)=>u?r(u):o?r(new Error("dest already exists.")):lc(e,t,n,r)))}(e,t,u,r)))}))}))};var dc={move:(0,yo.fromCallback)(fc)};const Dc=yo.fromCallback,pc=we,Ec=p.default,mc=Io,hc=fi.pathExists;var yc={outputFile:Dc((function(e,t,n,r){"function"==typeof n&&(r=n,n="utf8");const u=Ec.dirname(e);hc(u,((o,i)=>o?r(o):i?pc.writeFile(e,t,n,r):void mc.mkdirs(u,(u=>{if(u)return r(u);pc.writeFile(e,t,n,r)}))))})),outputFileSync:function(e,...t){const n=Ec.dirname(e);if(pc.existsSync(n))return pc.writeFileSync(e,...t);mc.mkdirsSync(n),pc.writeFileSync(e,...t)}};!function(e){e.exports=Object.assign({},ho,ci,bi,Yi,bs,zs,Io,nc,dc,yc,fi,Ji);const t=D.default;Object.getOwnPropertyDescriptor(t,"promises")&&Object.defineProperty(e.exports,"promises",{get:()=>t.promises})}(mo);const Cc=Nr.exports("streamroller:fileNameFormatter"),Fc=p.default;const gc=Nr.exports("streamroller:fileNameParser"),Ac=nu.exports;const vc=Nr.exports("streamroller:moveAndMaybeCompressFile"),Sc=mo.exports,wc=v.default;var Oc=async(e,t,n)=>{if(n=function(e){const t={mode:parseInt("0600",8),compress:!1},n=Object.assign({},t,e);return vc(`_parseOption: moveAndMaybeCompressFile called with option=${JSON.stringify(n)}`),n}(n),e!==t){if(await Sc.pathExists(e))if(vc(`moveAndMaybeCompressFile: moving file from ${e} to ${t} ${n.compress?"with":"without"} compress`),n.compress)await new Promise(((r,u)=>{let o=!1;const i=Sc.createWriteStream(t,{mode:n.mode,flags:"wx"}).on("open",(()=>{o=!0;const t=Sc.createReadStream(e).on("open",(()=>{t.pipe(wc.createGzip()).pipe(i)})).on("error",(t=>{vc(`moveAndMaybeCompressFile: error reading ${e}`,t),i.destroy(t)}))})).on("finish",(()=>{vc(`moveAndMaybeCompressFile: finished compressing ${t}, deleting ${e}`),Sc.unlink(e).then(r).catch((t=>{vc(`moveAndMaybeCompressFile: error deleting ${e}, truncating instead`,t),Sc.truncate(e).then(r).catch((t=>{vc(`moveAndMaybeCompressFile: error truncating ${e}`,t),u(t)}))}))})).on("error",(e=>{o?(vc(`moveAndMaybeCompressFile: error writing ${t}, deleting`,e),Sc.unlink(t).then((()=>{u(e)})).catch((e=>{vc(`moveAndMaybeCompressFile: error deleting ${t}`,e),u(e)}))):(vc(`moveAndMaybeCompressFile: error creating ${t}`,e),u(e))}))})).catch((()=>{}));else{vc(`moveAndMaybeCompressFile: renaming ${e} to ${t}`);try{await Sc.move(e,t,{overwrite:!0})}catch(n){if(vc(`moveAndMaybeCompressFile: error renaming ${e} to ${t}`,n),"ENOENT"!==n.code){vc("moveAndMaybeCompressFile: trying copy+truncate instead");try{await Sc.copy(e,t,{overwrite:!0}),await Sc.truncate(e)}catch(e){vc("moveAndMaybeCompressFile: error copy+truncate",e)}}}}}else vc("moveAndMaybeCompressFile: source and target are the same, not doing anything")};const bc=Nr.exports("streamroller:RollingFileWriteStream"),_c=mo.exports,Bc=p.default,Pc=E.default,kc=()=>new Date,xc=nu.exports,{Writable:Nc}=C.default,Ic=({file:e,keepFileExt:t,needsIndex:n,alwaysIncludeDate:r,compress:u,fileNameSep:o})=>{let i=o||".";const s=Fc.join(e.dir,e.name),c=t=>t+e.ext,a=(e,t,r)=>!n&&r||!t?e:e+i+t,l=(e,t,n)=>(t>0||r)&&n?e+i+n:e,f=(e,t)=>t&&u?e+".gz":e,d=t?[l,a,c,f]:[c,l,a,f];return({date:e,index:t})=>(Cc(`_formatFileName: date=${e}, index=${t}`),d.reduce(((n,r)=>r(n,t,e)),s))},Tc=({file:e,keepFileExt:t,pattern:n,fileNameSep:r})=>{let u=r||".";const o="__NOT_MATCHING__";let i=[(e,t)=>e.endsWith(".gz")?(gc("it is gzipped"),t.isCompressed=!0,e.slice(0,-1*".gz".length)):e,t?t=>t.startsWith(e.name)&&t.endsWith(e.ext)?(gc("it starts and ends with the right things"),t.slice(e.name.length+1,-1*e.ext.length)):o:t=>t.startsWith(e.base)?(gc("it starts with the right things"),t.slice(e.base.length+1)):o,n?(e,t)=>{const r=e.split(u);let o=r[r.length-1];gc("items: ",r,", indexStr: ",o);let i=e;void 0!==o&&o.match(/^\d+$/)?(i=e.slice(0,-1*(o.length+1)),gc(`dateStr is ${i}`),n&&!i&&(i=o,o="0")):o="0";try{const r=Ac.parse(n,i,new Date(0,0));return Ac.asString(n,r)!==i?e:(t.index=parseInt(o,10),t.date=i,t.timestamp=r.getTime(),"")}catch(t){return gc(`Problem parsing ${i} as ${n}, error was: `,t),e}}:(e,t)=>e.match(/^\d+$/)?(gc("it has an index"),t.index=parseInt(e,10),""):e];return e=>{let t={filename:e,index:0,isCompressed:!1};return i.reduce(((e,n)=>n(e,t)),e)?null:t}},Rc=Oc;var Mc=class extends Nc{constructor(e,t){if(bc(`constructor: creating RollingFileWriteStream. path=${e}`),"string"!=typeof e||0===e.length)throw new Error(`Invalid filename: ${e}`);if(e.endsWith(Bc.sep))throw new Error(`Filename is a directory: ${e}`);0===e.indexOf(`~${Bc.sep}`)&&(e=e.replace("~",Pc.homedir())),super(t),this.options=this._parseOption(t),this.fileObject=Bc.parse(e),""===this.fileObject.dir&&(this.fileObject=Bc.parse(Bc.join(process.cwd(),e))),this.fileFormatter=Ic({file:this.fileObject,alwaysIncludeDate:this.options.alwaysIncludePattern,needsIndex:this.options.maxSize 0`)}else delete n.maxSize;if(n.numBackups||0===n.numBackups){if(n.numBackups<0)throw new Error(`options.numBackups (${n.numBackups}) should be >= 0`);if(n.numBackups>=Number.MAX_SAFE_INTEGER)throw new Error(`options.numBackups (${n.numBackups}) should be < Number.MAX_SAFE_INTEGER`);n.numToKeep=n.numBackups+1}else if(n.numToKeep<=0)throw new Error(`options.numToKeep (${n.numToKeep}) should be > 0`);return bc(`_parseOption: creating stream with option=${JSON.stringify(n)}`),n}_final(e){this.currentFileStream.end("",this.options.encoding,e)}_write(e,t,n){this._shouldRoll().then((()=>{bc(`_write: writing chunk. file=${this.currentFileStream.path} state=${JSON.stringify(this.state)} chunk=${e}`),this.currentFileStream.write(e,t,(t=>{this.state.currentSize+=e.length,n(t)}))}))}async _shouldRoll(){(this._dateChanged()||this._tooBig())&&(bc(`_shouldRoll: rolling because dateChanged? ${this._dateChanged()} or tooBig? ${this._tooBig()}`),await this._roll())}_dateChanged(){return this.state.currentDate&&this.state.currentDate!==xc(this.options.pattern,kc())}_tooBig(){return this.state.currentSize>=this.options.maxSize}_roll(){return bc("_roll: closing the current stream"),new Promise(((e,t)=>{this.currentFileStream.end("",this.options.encoding,(()=>{this._moveOldFiles().then(e).catch(t)}))}))}async _moveOldFiles(){const e=await this._getExistingFiles();for(let t=(this.state.currentDate?e.filter((e=>e.date===this.state.currentDate)):e).length;t>=0;t--){bc(`_moveOldFiles: i = ${t}`);const e=this.fileFormatter({date:this.state.currentDate,index:t}),n=this.fileFormatter({date:this.state.currentDate,index:t+1}),r={compress:this.options.compress&&0===t,mode:this.options.mode};await Rc(e,n,r)}this.state.currentSize=0,this.state.currentDate=this.state.currentDate?xc(this.options.pattern,kc()):null,bc(`_moveOldFiles: finished rolling files. state=${JSON.stringify(this.state)}`),this._renewWriteStream(),await new Promise(((e,t)=>{this.currentFileStream.write("","utf8",(()=>{this._clean().then(e).catch(t)}))}))}async _getExistingFiles(){const e=await _c.readdir(this.fileObject.dir).catch((()=>[]));bc(`_getExistingFiles: files=${e}`);const t=e.map((e=>this.fileNameParser(e))).filter((e=>e)),n=e=>(e.timestamp?e.timestamp:kc().getTime())-e.index;return t.sort(((e,t)=>n(e)-n(t))),t}_renewWriteStream(){const e=this.fileFormatter({date:this.state.currentDate,index:0}),t=e=>{try{return _c.mkdirSync(e,{recursive:!0})}catch(n){if("ENOENT"===n.code)return t(Bc.dirname(e)),t(e);if("EEXIST"!==n.code&&"EROFS"!==n.code)throw n;try{if(_c.statSync(e).isDirectory())return e;throw n}catch(e){throw n}}};t(this.fileObject.dir);const n={flags:this.options.flags,encoding:this.options.encoding,mode:this.options.mode};var r,u;_c.appendFileSync(e,"",(r={...n},u="flags",r["flag"]=r[u],delete r[u],r)),this.currentFileStream=_c.createWriteStream(e,n),this.currentFileStream.on("error",(e=>{this.emit("error",e)}))}async _clean(){const e=await this._getExistingFiles();if(bc(`_clean: numToKeep = ${this.options.numToKeep}, existingFiles = ${e.length}`),bc("_clean: existing files are: ",e),this._tooManyFiles(e.length)){const n=e.slice(0,e.length-this.options.numToKeep).map((e=>Bc.format({dir:this.fileObject.dir,base:e.filename})));await(t=n,bc(`deleteFiles: files to delete: ${t}`),Promise.all(t.map((e=>_c.unlink(e).catch((t=>{bc(`deleteFiles: error when unlinking ${e}, ignoring. Error was ${t}`)}))))))}var t}_tooManyFiles(e){return this.options.numToKeep>0&&e>this.options.numToKeep}};const Lc=Mc;var jc=class extends Lc{constructor(e,t,n,r){r||(r={}),t&&(r.maxSize=t),r.numBackups||0===r.numBackups||(n||0===n||(n=1),r.numBackups=n),super(e,r),this.backups=r.numBackups,this.size=this.options.maxSize}get theStream(){return this.currentFileStream}};const $c=Mc;var Hc={RollingFileWriteStream:Mc,RollingFileStream:jc,DateRollingFileStream:class extends $c{constructor(e,t,n){t&&"object"==typeof t&&(n=t,t=null),n||(n={}),t||(t="yyyy-MM-dd"),n.pattern=t,n.numBackups||0===n.numBackups?n.daysToKeep=n.numBackups:(n.daysToKeep||0===n.daysToKeep?process.emitWarning("options.daysToKeep is deprecated due to the confusion it causes when used together with file size rolling. Please use options.numBackups instead.","DeprecationWarning","streamroller-DEP0001"):n.daysToKeep=1,n.numBackups=n.daysToKeep),super(e,n),this.mode=this.options.mode}get theStream(){return this.currentFileStream}}};const Jc=Nr.exports("log4js:file"),Gc=p.default,Vc=Hc,Uc=E.default.EOL;let Wc=!1;const zc=new Set;function Kc(){zc.forEach((e=>{e.sighupHandler()}))}function qc(e,t,n,r){const u=new Vc.RollingFileStream(e,t,n,r);return u.on("error",(t=>{console.error("log4js.fileAppender - Writing to file %s, error happened ",e,t)})),u.on("drain",(()=>{process.emit("log4js:pause",!1)})),u}Eo.configure=function(e,t){let n=t.basicLayout;return e.layout&&(n=t.layout(e.layout.type,e.layout)),e.mode=e.mode||384,function(e,t,n,r,u,o){e=Gc.normalize(e),Jc("Creating file appender (",e,", ",n,", ",r=r||0===r?r:5,", ",u,", ",o,")");let i=qc(e,n,r,u);const s=function(e){if(i.writable){if(!0===u.removeColor){const t=/\x1b[[0-9;]*m/g;e.data=e.data.map((e=>"string"==typeof e?e.replace(t,""):e))}i.write(t(e,o)+Uc,"utf8")||process.emit("log4js:pause",!0)}};return s.reopen=function(){i.end((()=>{i=qc(e,n,r,u)}))},s.sighupHandler=function(){Jc("SIGHUP handler called."),s.reopen()},s.shutdown=function(e){zc.delete(s),0===zc.size&&Wc&&(process.removeListener("SIGHUP",Kc),Wc=!1),i.end("","utf-8",e)},zc.add(s),Wc||(process.on("SIGHUP",Kc),Wc=!0),s}(e.filename,n,e.maxLogSize,e.backups,e,e.timezoneOffset)};var Yc={};const Xc=Hc,Zc=E.default.EOL;function Qc(e,t,n,r,u){r.maxSize=r.maxLogSize;const o=function(e,t,n){const r=new Xc.DateRollingFileStream(e,t,n);return r.on("error",(t=>{console.error("log4js.dateFileAppender - Writing to file %s, error happened ",e,t)})),r.on("drain",(()=>{process.emit("log4js:pause",!1)})),r}(e,t,r),i=function(e){o.writable&&(o.write(n(e,u)+Zc,"utf8")||process.emit("log4js:pause",!0))};return i.shutdown=function(e){o.end("","utf-8",e)},i}Yc.configure=function(e,t){let n=t.basicLayout;return e.layout&&(n=t.layout(e.layout.type,e.layout)),e.alwaysIncludePattern||(e.alwaysIncludePattern=!1),e.mode=e.mode||384,Qc(e.filename,e.pattern,n,e,e.timezoneOffset)};var ea={};const ta=Nr.exports("log4js:fileSync"),na=p.default,ra=D.default,ua=E.default.EOL||"\n";function oa(e,t){if(ra.existsSync(e))return;const n=ra.openSync(e,t.flags,t.mode);ra.closeSync(n)}class ia{constructor(e,t,n,r){ta("In RollingFileStream"),function(){if(!e||!t||t<=0)throw new Error("You must specify a filename and file size")}(),this.filename=e,this.size=t,this.backups=n,this.options=r,this.currentSize=0,this.currentSize=function(e){let t=0;try{t=ra.statSync(e).size}catch(t){oa(e,r)}return t}(this.filename)}shouldRoll(){return ta("should roll with current size %d, and max size %d",this.currentSize,this.size),this.currentSize>=this.size}roll(e){const t=this,n=new RegExp(`^${na.basename(e)}`);function r(e){return n.test(e)}function u(t){return parseInt(t.substring(`${na.basename(e)}.`.length),10)||0}function o(e,t){return u(e)>u(t)?1:u(e) ${e}.${r+1}`),ra.renameSync(na.join(na.dirname(e),n),`${e}.${r+1}`)}}ta("Rolling, rolling, rolling"),ta("Renaming the old files"),ra.readdirSync(na.dirname(e)).filter(r).sort(o).reverse().forEach(i)}write(e,t){const n=this;ta("in write"),this.shouldRoll()&&(this.currentSize=0,this.roll(this.filename)),ta("writing the chunk to the file"),n.currentSize+=e.length,ra.appendFileSync(n.filename,e)}}ea.configure=function(e,t){let n=t.basicLayout;e.layout&&(n=t.layout(e.layout.type,e.layout));const r={flags:e.flags||"a",encoding:e.encoding||"utf8",mode:e.mode||384};return function(e,t,n,r,u,o){ta("fileSync appender created");const i=function(e,t,n){let r;var u;return t?r=new ia(e,t,n,o):(oa(u=e,o),r={write(e){ra.appendFileSync(u,e)}}),r}(e=na.normalize(e),n,r=r||0===r?r:5);return e=>{i.write(t(e,u)+ua)}}(e.filename,n,e.maxLogSize,e.backups,e.timezoneOffset,r)};var sa={};const ca=Nr.exports("log4js:tcp"),aa=S.default;sa.configure=function(e,t){ca(`configure with config = ${e}`);let n=function(e){return e.serialise()};return e.layout&&(n=t.layout(e.layout.type,e.layout)),function(e,t){let n=!1;const r=[];let u,o=3,i="__LOG4JS__";function s(e){ca("Writing log event to socket"),n=u.write(`${t(e)}${i}`,"utf8")}function c(){let e;for(ca("emptying buffer");e=r.shift();)s(e)}function a(e){n?s(e):(ca("buffering log event because it cannot write at the moment"),r.push(e))}return function t(){ca(`appender creating socket to ${e.host||"localhost"}:${e.port||5e3}`),i=`${e.endMsg||"__LOG4JS__"}`,u=aa.createConnection(e.port||5e3,e.host||"localhost"),u.on("connect",(()=>{ca("socket connected"),c(),n=!0})),u.on("drain",(()=>{ca("drain event received, emptying buffer"),n=!0,c()})),u.on("timeout",u.end.bind(u)),u.on("error",(e=>{ca("connection error",e),n=!1,c()})),u.on("close",t)}(),a.shutdown=function(e){ca("shutdown called"),r.length&&o?(ca("buffer has items, waiting 100ms to empty"),o-=1,setTimeout((()=>{a.shutdown(e)}),100)):(u.removeAllListeners("close"),u.end(e))},a}(e,n)};const la=p.default,fa=Nr.exports("log4js:appenders"),da=tu,Da=eo,pa=gu,Ea=hu,ma=to,ha=new Map;ha.set("console",oo),ha.set("stdout",so),ha.set("stderr",co),ha.set("logLevelFilter",ao),ha.set("categoryFilter",lo),ha.set("noLogFilter",Do),ha.set("file",Eo),ha.set("dateFile",Yc),ha.set("fileSync",ea),ha.set("tcp",sa);const ya=new Map,Ca=(e,t)=>{fa("Loading module from ",e);try{return require(e)}catch(n){return void da.throwExceptionIf(t,"MODULE_NOT_FOUND"!==n.code,`appender "${e}" could not be loaded (error was: ${n})`)}},Fa=new Set,ga=(e,t)=>{if(ya.has(e))return ya.get(e);if(!t.appenders[e])return!1;if(Fa.has(e))throw new Error(`Dependency loop detected for appender ${e}.`);Fa.add(e),fa(`Creating appender ${e}`);const n=Aa(e,t);return Fa.delete(e),ya.set(e,n),n},Aa=(e,t)=>{const n=t.appenders[e],r=n.type.configure?n.type:((e,t)=>ha.get(e)||Ca(`./${e}`,t)||Ca(e,t)||require.main&&Ca(la.join(la.dirname(require.main.filename),e),t)||Ca(la.join(process.cwd(),e),t))(n.type,t);return da.throwExceptionIf(t,da.not(r),`appender "${e}" is not valid (type "${n.type}" could not be found)`),r.appender&&fa(`DEPRECATION: Appender ${n.type} exports an appender function.`),r.shutdown&&fa(`DEPRECATION: Appender ${n.type} exports a shutdown function.`),fa(`${e}: clustering.isMaster ? ${Da.isMaster()}`),fa(`${e}: appenderModule is ${F.default.inspect(r)}`),Da.onlyOnMaster((()=>(fa(`calling appenderModule.configure for ${e} / ${n.type}`),r.configure(ma.modifyConfig(n),Ea,(e=>ga(e,t)),pa))),(()=>{}))},va=e=>{ya.clear(),Fa.clear();const t=[];Object.values(e.categories).forEach((e=>{t.push(...e.appenders)})),Object.keys(e.appenders).forEach((n=>{(t.includes(n)||"tcp-server"===e.appenders[n].type)&&ga(n,e)}))},Sa=()=>{va({appenders:{out:{type:"stdout"}},categories:{default:{appenders:["out"],level:"trace"}}})};Sa(),da.addListener((e=>{da.throwExceptionIf(e,da.not(da.anObject(e.appenders)),'must have a property "appenders" of type object.');const t=Object.keys(e.appenders);da.throwExceptionIf(e,da.not(t.length),"must define at least one appender."),t.forEach((t=>{da.throwExceptionIf(e,da.not(e.appenders[t].type),`appender "${t}" is not valid (must be an object with property "type")`)}))})),da.addListener(va),Au.exports=ya,Au.exports.init=Sa;var wa={exports:{}};!function(e){const t=Nr.exports("log4js:categories"),n=tu,r=gu,u=Au.exports,o=new Map;function i(e,t,n){if(!1===t.inherit)return;const r=n.lastIndexOf(".");if(r<0)return;const u=n.substring(0,r);let o=e.categories[u];o||(o={inherit:!0,appenders:[]}),i(e,o,u),!e.categories[u]&&o.appenders&&o.appenders.length&&o.level&&(e.categories[u]=o),t.appenders=t.appenders||[],t.level=t.level||o.level,o.appenders.forEach((e=>{t.appenders.includes(e)||t.appenders.push(e)})),t.parent=o}function s(e){if(!e.categories)return;Object.keys(e.categories).forEach((t=>{const n=e.categories[t];i(e,n,t)}))}n.addPreProcessingListener((e=>s(e))),n.addListener((e=>{n.throwExceptionIf(e,n.not(n.anObject(e.categories)),'must have a property "categories" of type object.');const t=Object.keys(e.categories);n.throwExceptionIf(e,n.not(t.length),"must define at least one category."),t.forEach((t=>{const o=e.categories[t];n.throwExceptionIf(e,[n.not(o.appenders),n.not(o.level)],`category "${t}" is not valid (must be an object with properties "appenders" and "level")`),n.throwExceptionIf(e,n.not(Array.isArray(o.appenders)),`category "${t}" is not valid (appenders must be an array of appender names)`),n.throwExceptionIf(e,n.not(o.appenders.length),`category "${t}" is not valid (appenders must contain at least one appender name)`),Object.prototype.hasOwnProperty.call(o,"enableCallStack")&&n.throwExceptionIf(e,"boolean"!=typeof o.enableCallStack,`category "${t}" is not valid (enableCallStack must be boolean type)`),o.appenders.forEach((r=>{n.throwExceptionIf(e,n.not(u.get(r)),`category "${t}" is not valid (appender "${r}" is not defined)`)})),n.throwExceptionIf(e,n.not(r.getLevel(o.level)),`category "${t}" is not valid (level "${o.level}" not recognised; valid levels are ${r.levels.join(", ")})`)})),n.throwExceptionIf(e,n.not(e.categories.default),'must define a "default" category.')}));const c=e=>{o.clear();Object.keys(e.categories).forEach((n=>{const i=e.categories[n],s=[];i.appenders.forEach((e=>{s.push(u.get(e)),t(`Creating category ${n}`),o.set(n,{appenders:s,level:r.getLevel(i.level),enableCallStack:i.enableCallStack||!1})}))}))},a=()=>{c({categories:{default:{appenders:["out"],level:"OFF"}}})};a(),n.addListener(c);const l=e=>(t(`configForCategory: searching for config for ${e}`),o.has(e)?(t(`configForCategory: ${e} exists in config, returning it`),o.get(e)):e.indexOf(".")>0?(t(`configForCategory: ${e} has hierarchy, searching for parents`),l(e.substring(0,e.lastIndexOf(".")))):(t("configForCategory: returning config for default category"),l("default")));e.exports=o,e.exports=Object.assign(e.exports,{appendersForCategory:e=>l(e).appenders,getLevelForCategory:e=>l(e).level,setLevelForCategory:(e,n)=>{let r=o.get(e);if(t(`setLevelForCategory: found ${r} for ${e}`),!r){const n=l(e);t(`setLevelForCategory: no config found for category, found ${n} for parents of ${e}`),r={appenders:n.appenders}}r.level=n,o.set(e,r)},getEnableCallStackForCategory:e=>!0===l(e).enableCallStack,setEnableCallStackForCategory:(e,t)=>{l(e).enableCallStack=t},init:a})}(wa);const Oa=Nr.exports("log4js:logger"),ba=Hu,_a=gu,Ba=eo,Pa=wa.exports,ka=tu,xa=/at (?:(.+)\s+\()?(?:(.+?):(\d+)(?::(\d+))?|([^)]+))\)?/;function Na(e,t=4){const n=e.stack.split("\n").slice(t),r=xa.exec(n[0]);return r&&6===r.length?{functionName:r[1],fileName:r[2],lineNumber:parseInt(r[3],10),columnNumber:parseInt(r[4],10),callStack:n.join("\n")}:null}class Ia{constructor(e){if(!e)throw new Error("No category provided.");this.category=e,this.context={},this.parseCallStack=Na,Oa(`Logger created (${this.category}, ${this.level})`)}get level(){return _a.getLevel(Pa.getLevelForCategory(this.category),_a.TRACE)}set level(e){Pa.setLevelForCategory(this.category,_a.getLevel(e,this.level))}get useCallStack(){return Pa.getEnableCallStackForCategory(this.category)}set useCallStack(e){Pa.setEnableCallStackForCategory(this.category,!0===e)}log(e,...t){let n=_a.getLevel(e);n||(this._log(_a.WARN,"log4js:logger.log: invalid value for log-level as first parameter given: ",e),n=_a.INFO),this.isLevelEnabled(n)&&this._log(n,t)}isLevelEnabled(e){return this.level.isLessThanOrEqualTo(e)}_log(e,t){Oa(`sending log data (${e}) to appenders`);const n=new ba(this.category,e,t,this.context,this.useCallStack&&this.parseCallStack(new Error));Ba.send(n)}addContext(e,t){this.context[e]=t}removeContext(e){delete this.context[e]}clearContext(){this.context={}}setParseCallStackFunction(e){this.parseCallStack=e}}function Ta(e){const t=_a.getLevel(e),n=t.toString().toLowerCase().replace(/_([a-z])/g,(e=>e[1].toUpperCase())),r=n[0].toUpperCase()+n.slice(1);Ia.prototype[`is${r}Enabled`]=function(){return this.isLevelEnabled(t)},Ia.prototype[n]=function(...e){this.log(t,...e)}}_a.levels.forEach(Ta),ka.addListener((()=>{_a.levels.forEach(Ta)}));var Ra=Ia;const Ma=gu;function La(e){return e.originalUrl||e.url}function ja(e,t){for(let n=0;ne.source?e.source:e));t=new RegExp(n.join("|"))}return t}(t.nolog);return(e,i,s)=>{if(e._logging)return s();if(o&&o.test(e.originalUrl))return s();if(n.isLevelEnabled(r)||"auto"===t.level){const o=new Date,{writeHead:s}=i;e._logging=!0,i.writeHead=(e,t)=>{i.writeHead=s,i.writeHead(e,t),i.__statusCode=e,i.__headers=t||{}},i.on("finish",(()=>{i.responseTime=new Date-o,i.statusCode&&"auto"===t.level&&(r=Ma.INFO,i.statusCode>=300&&(r=Ma.WARN),i.statusCode>=400&&(r=Ma.ERROR)),r=function(e,t,n){let r=t;if(n){const t=n.find((t=>{let n=!1;return n=t.from&&t.to?e>=t.from&&e<=t.to:-1!==t.codes.indexOf(e),n}));t&&(r=Ma.getLevel(t.level,r))}return r}(i.statusCode,r,t.statusRules);const s=function(e,t,n){const r=[];return r.push({token:":url",replacement:La(e)}),r.push({token:":protocol",replacement:e.protocol}),r.push({token:":hostname",replacement:e.hostname}),r.push({token:":method",replacement:e.method}),r.push({token:":status",replacement:t.__statusCode||t.statusCode}),r.push({token:":response-time",replacement:t.responseTime}),r.push({token:":date",replacement:(new Date).toUTCString()}),r.push({token:":referrer",replacement:e.headers.referer||e.headers.referrer||""}),r.push({token:":http-version",replacement:`${e.httpVersionMajor}.${e.httpVersionMinor}`}),r.push({token:":remote-addr",replacement:e.headers["x-forwarded-for"]||e.ip||e._remoteAddress||e.socket&&(e.socket.remoteAddress||e.socket.socket&&e.socket.socket.remoteAddress)}),r.push({token:":user-agent",replacement:e.headers["user-agent"]}),r.push({token:":content-length",replacement:t.getHeader("content-length")||t.__headers&&t.__headers["Content-Length"]||"-"}),r.push({token:/:req\[([^\]]+)]/g,replacement:(t,n)=>e.headers[n.toLowerCase()]}),r.push({token:/:res\[([^\]]+)]/g,replacement:(e,n)=>t.getHeader(n.toLowerCase())||t.__headers&&t.__headers[n]}),(e=>{const t=e.concat();for(let e=0;eja(e,s)));t&&n.log(r,t)}else n.log(r,ja(u,s));t.context&&n.removeContext("res")}))}return s()}},nl=Va;let rl=!1;function ul(e){if(!rl)return;Ua("Received log event ",e);Za.appendersForCategory(e.categoryName).forEach((t=>{t(e)}))}function ol(e){rl&&il();let t=e;return"string"==typeof t&&(t=function(e){Ua(`Loading configuration from ${e}`);try{return JSON.parse(Wa.readFileSync(e,"utf8"))}catch(t){throw new Error(`Problem reading config from file "${e}". Error was ${t.message}`,t)}}(e)),Ua(`Configuration is ${t}`),Ka.configure(za(t)),el.onMessage(ul),rl=!0,sl}function il(e){Ua("Shutdown called. Disabling all log writing."),rl=!1;const t=Array.from(Xa.values());Xa.init(),Za.init();const n=t.reduceRight(((e,t)=>t.shutdown?e+1:e),0);if(0===n)return Ua("No appenders with shutdown functions found."),void 0!==e&&e();let r,u=0;function o(t){r=r||t,u+=1,Ua(`Appender shutdowns complete: ${u} / ${n}`),u>=n&&(Ua("All shutdown functions completed."),e&&e(r))}return Ua(`Found ${n} appenders with shutdown functions.`),t.filter((e=>e.shutdown)).forEach((e=>e.shutdown(o))),null}const sl={getLogger:function(e){return rl||ol(process.env.LOG4JS_CONFIG||{appenders:{out:{type:"stdout"}},categories:{default:{appenders:["out"],level:"OFF"}}}),new Qa(e||"default")},configure:ol,shutdown:il,connectLogger:tl,levels:Ya,addLayout:qa.addLayout,recording:function(){return nl}};var cl=sl,al={};Object.defineProperty(al,"__esModule",{value:!0}),al.levelMap=al.getLevel=al.setCategoriesLevel=al.getConfiguration=al.setConfiguration=void 0;const ll=cl;let fl={appenders:{debug:{type:"stdout",layout:{type:"pattern",pattern:"[%d] > hvigor %p %c %[%m%]"}},info:{type:"stdout",layout:{type:"pattern",pattern:"[%d] > hvigor %[%m%]"}},"no-pattern-info":{type:"stdout",layout:{type:"pattern",pattern:"%m"}},wrong:{type:"stderr",layout:{type:"pattern",pattern:"[%d] > hvigor %[%p: %m%]"}},"just-debug":{type:"logLevelFilter",appender:"debug",level:"debug",maxLevel:"debug"},"just-info":{type:"logLevelFilter",appender:"info",level:"info",maxLevel:"info"},"just-wrong":{type:"logLevelFilter",appender:"wrong",level:"warn",maxLevel:"error"}},categories:{default:{appenders:["just-debug","just-info","just-wrong"],level:"debug"},"no-pattern-info":{appenders:["no-pattern-info"],level:"info"}}};al.setConfiguration=e=>{fl=e};al.getConfiguration=()=>fl;let dl=ll.levels.DEBUG;al.setCategoriesLevel=(e,t)=>{dl=e;const n=fl.categories;for(const r in n)(null==t?void 0:t.includes(r))||Object.prototype.hasOwnProperty.call(n,r)&&(n[r].level=e.levelStr)};al.getLevel=()=>dl,al.levelMap=new Map([["ALL",ll.levels.ALL],["MARK",ll.levels.MARK],["TRACE",ll.levels.TRACE],["DEBUG",ll.levels.DEBUG],["INFO",ll.levels.INFO],["WARN",ll.levels.WARN],["ERROR",ll.levels.ERROR],["FATAL",ll.levels.FATAL],["OFF",ll.levels.OFF]]);var Dl=w&&w.__createBinding||(Object.create?function(e,t,n,r){void 0===r&&(r=n);var u=Object.getOwnPropertyDescriptor(t,n);u&&!("get"in u?!t.__esModule:u.writable||u.configurable)||(u={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,r,u)}:function(e,t,n,r){void 0===r&&(r=n),e[r]=t[n]}),pl=w&&w.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),El=w&&w.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var n in e)"default"!==n&&Object.prototype.hasOwnProperty.call(e,n)&&Dl(t,e,n);return pl(t,e),t};Object.defineProperty(xr,"__esModule",{value:!0}),xr.evaluateLogLevel=xr.HvigorLogger=void 0;const ml=El(cl),hl=cl,yl=El(F.default),Cl=al;class Fl{constructor(e){ml.configure((0,Cl.getConfiguration)()),this._logger=ml.getLogger(e),this._logger.level=(0,Cl.getLevel)()}static getLogger(e){return new Fl(e)}log(e,...t){this._logger.log(e,...t)}debug(e,...t){this._logger.debug(e,...t)}info(e,...t){this._logger.info(e,...t)}warn(e,...t){void 0!==e&&""!==e&&this._logger.warn(e,...t)}error(e,...t){this._logger.error(e,...t)}_printTaskExecuteInfo(e,t){this.info(`Finished :${e}... after ${t}`)}_printFailedTaskInfo(e){this.error(`Failed :${e}... `)}_printDisabledTaskInfo(e){this.info(`Disabled :${e}... `)}_printUpToDateTaskInfo(e){this.info(`UP-TO-DATE :${e}... `)}errorMessageExit(e,...t){throw new Error(yl.format(e,...t))}errorExit(e,t,...n){t&&this._logger.error(t,n),this._logger.error(e.stack)}setLevel(e,t){(0,Cl.setCategoriesLevel)(e,t),ml.shutdown(),ml.configure((0,Cl.getConfiguration)())}getLevel(){return this._logger.level}configure(e){const t=(0,Cl.getConfiguration)(),n={appenders:{...t.appenders,...e.appenders},categories:{...t.categories,...e.categories}};(0,Cl.setConfiguration)(n),ml.shutdown(),ml.configure(n)}}xr.HvigorLogger=Fl,xr.evaluateLogLevel=function(e,t){t.debug?e.setLevel(hl.levels.DEBUG):t.warn?e.setLevel(hl.levels.WARN):t.error?e.setLevel(hl.levels.ERROR):e.setLevel(hl.levels.INFO)};var gl=w&&w.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(X,"__esModule",{value:!0}),X.parseJsonText=X.parseJsonFile=void 0;const Al=Z,vl=gl(kr),Sl=gl(p.default),wl=gl(E.default),Ol=xr.HvigorLogger.getLogger("parse-json-util");var bl;!function(e){e[e.Char=0]="Char",e[e.EOF=1]="EOF",e[e.Identifier=2]="Identifier"}(bl||(bl={}));let _l,Bl,Pl,kl,xl,Nl,Il="start",Tl=[],Rl=0,Ml=1,Ll=0,jl=!1,$l="default",Hl="'",Jl=1;function Gl(e,t=!1){Bl=String(e),Il="start",Tl=[],Rl=0,Ml=1,Ll=0,kl=void 0,jl=t;do{_l=Vl(),Xl[Il]()}while("eof"!==_l.type);return kl}function Vl(){for($l="default",xl="",Hl="'",Jl=1;;){Nl=Ul();const e=zl[$l]();if(e)return e}}function Ul(){if(Bl[Rl])return String.fromCodePoint(Bl.codePointAt(Rl))}function Wl(){const e=Ul();return"\n"===e?(Ml++,Ll=0):e?Ll+=e.length:Ll++,e&&(Rl+=e.length),e}X.parseJsonFile=function(e,t=!1,n="utf-8"){const r=vl.default.readFileSync(Sl.default.resolve(e),{encoding:n});try{return Gl(r,t)}catch(t){if(t instanceof SyntaxError){const n=t.message.split("at");2===n.length&&Ol.errorMessageExit(`${n[0].trim()}${wl.default.EOL}\t at ${e}:${n[1].trim()}`)}Ol.errorMessageExit(`${e} is not in valid JSON/JSON5 format.`)}},X.parseJsonText=Gl;const zl={default(){switch(Nl){case"/":return Wl(),void($l="comment");case void 0:return Wl(),Kl("eof")}if(!Al.JudgeUtil.isIgnoreChar(Nl)&&!Al.JudgeUtil.isSpaceSeparator(Nl))return zl[Il]();Wl()},start(){$l="value"},beforePropertyName(){switch(Nl){case"$":case"_":return xl=Wl(),void($l="identifierName");case"\\":return Wl(),void($l="identifierNameStartEscape");case"}":return Kl("punctuator",Wl());case'"':case"'":return Hl=Nl,Wl(),void($l="string")}if(Al.JudgeUtil.isIdStartChar(Nl))return xl+=Wl(),void($l="identifierName");throw tf(bl.Char,Wl())},afterPropertyName(){if(":"===Nl)return Kl("punctuator",Wl());throw tf(bl.Char,Wl())},beforePropertyValue(){$l="value"},afterPropertyValue(){switch(Nl){case",":case"}":return Kl("punctuator",Wl())}throw tf(bl.Char,Wl())},beforeArrayValue(){if("]"===Nl)return Kl("punctuator",Wl());$l="value"},afterArrayValue(){switch(Nl){case",":case"]":return Kl("punctuator",Wl())}throw tf(bl.Char,Wl())},end(){throw tf(bl.Char,Wl())},comment(){switch(Nl){case"*":return Wl(),void($l="multiLineComment");case"/":return Wl(),void($l="singleLineComment")}throw tf(bl.Char,Wl())},multiLineComment(){switch(Nl){case"*":return Wl(),void($l="multiLineCommentAsterisk");case void 0:throw tf(bl.Char,Wl())}Wl()},multiLineCommentAsterisk(){switch(Nl){case"*":return void Wl();case"/":return Wl(),void($l="default");case void 0:throw tf(bl.Char,Wl())}Wl(),$l="multiLineComment"},singleLineComment(){switch(Nl){case"\n":case"\r":case"\u2028":case"\u2029":return Wl(),void($l="default");case void 0:return Wl(),Kl("eof")}Wl()},value(){switch(Nl){case"{":case"[":return Kl("punctuator",Wl());case"n":return Wl(),ql("ull"),Kl("null",null);case"t":return Wl(),ql("rue"),Kl("boolean",!0);case"f":return Wl(),ql("alse"),Kl("boolean",!1);case"-":case"+":return"-"===Wl()&&(Jl=-1),void($l="numerical");case".":case"0":case"I":case"N":return void($l="numerical");case'"':case"'":return Hl=Nl,Wl(),xl="",void($l="string")}if(void 0===Nl||!Al.JudgeUtil.isDigitWithoutZero(Nl))throw tf(bl.Char,Wl());$l="numerical"},numerical(){switch(Nl){case".":return xl=Wl(),void($l="decimalPointLeading");case"0":return xl=Wl(),void($l="zero");case"I":return Wl(),ql("nfinity"),Kl("numeric",Jl*(1/0));case"N":return Wl(),ql("aN"),Kl("numeric",NaN)}if(void 0!==Nl&&Al.JudgeUtil.isDigitWithoutZero(Nl))return xl=Wl(),void($l="decimalInteger");throw tf(bl.Char,Wl())},zero(){switch(Nl){case".":case"e":case"E":return void($l="decimal");case"x":case"X":return xl+=Wl(),void($l="hexadecimal")}return Kl("numeric",0)},decimalInteger(){switch(Nl){case".":case"e":case"E":return void($l="decimal")}if(!Al.JudgeUtil.isDigit(Nl))return Kl("numeric",Jl*Number(xl));xl+=Wl()},decimal(){switch(Nl){case".":xl+=Wl(),$l="decimalFraction";break;case"e":case"E":xl+=Wl(),$l="decimalExponent"}},decimalPointLeading(){if(Al.JudgeUtil.isDigit(Nl))return xl+=Wl(),void($l="decimalFraction");throw tf(bl.Char,Wl())},decimalFraction(){switch(Nl){case"e":case"E":return xl+=Wl(),void($l="decimalExponent")}if(!Al.JudgeUtil.isDigit(Nl))return Kl("numeric",Jl*Number(xl));xl+=Wl()},decimalExponent(){switch(Nl){case"+":case"-":return xl+=Wl(),void($l="decimalExponentSign")}if(Al.JudgeUtil.isDigit(Nl))return xl+=Wl(),void($l="decimalExponentInteger");throw tf(bl.Char,Wl())},decimalExponentSign(){if(Al.JudgeUtil.isDigit(Nl))return xl+=Wl(),void($l="decimalExponentInteger");throw tf(bl.Char,Wl())},decimalExponentInteger(){if(!Al.JudgeUtil.isDigit(Nl))return Kl("numeric",Jl*Number(xl));xl+=Wl()},hexadecimal(){if(Al.JudgeUtil.isHexDigit(Nl))return xl+=Wl(),void($l="hexadecimalInteger");throw tf(bl.Char,Wl())},hexadecimalInteger(){if(!Al.JudgeUtil.isHexDigit(Nl))return Kl("numeric",Jl*Number(xl));xl+=Wl()},identifierNameStartEscape(){if("u"!==Nl)throw tf(bl.Char,Wl());Wl();const e=Yl();switch(e){case"$":case"_":break;default:if(!Al.JudgeUtil.isIdStartChar(e))throw tf(bl.Identifier)}xl+=e,$l="identifierName"},identifierName(){switch(Nl){case"$":case"_":case"‌":case"‍":return void(xl+=Wl());case"\\":return Wl(),void($l="identifierNameEscape")}if(!Al.JudgeUtil.isIdContinueChar(Nl))return Kl("identifier",xl);xl+=Wl()},identifierNameEscape(){if("u"!==Nl)throw tf(bl.Char,Wl());Wl();const e=Yl();switch(e){case"$":case"_":case"‌":case"‍":break;default:if(!Al.JudgeUtil.isIdContinueChar(e))throw tf(bl.Identifier)}xl+=e,$l="identifierName"},string(){switch(Nl){case"\\":return Wl(),void(xl+=function(){const e=Ul(),t=function(){switch(Ul()){case"b":return Wl(),"\b";case"f":return Wl(),"\f";case"n":return Wl(),"\n";case"r":return Wl(),"\r";case"t":return Wl(),"\t";case"v":return Wl(),"\v"}return}();if(t)return t;switch(e){case"0":if(Wl(),Al.JudgeUtil.isDigit(Ul()))throw tf(bl.Char,Wl());return"\0";case"x":return Wl(),function(){let e="",t=Ul();if(!Al.JudgeUtil.isHexDigit(t))throw tf(bl.Char,Wl());if(e+=Wl(),t=Ul(),!Al.JudgeUtil.isHexDigit(t))throw tf(bl.Char,Wl());return e+=Wl(),String.fromCodePoint(parseInt(e,16))}();case"u":return Wl(),Yl();case"\n":case"\u2028":case"\u2029":return Wl(),"";case"\r":return Wl(),"\n"===Ul()&&Wl(),""}if(void 0===e||Al.JudgeUtil.isDigitWithoutZero(e))throw tf(bl.Char,Wl());return Wl()}());case'"':case"'":if(Nl===Hl){const e=Kl("string",xl);return Wl(),e}return void(xl+=Wl());case"\n":case"\r":case void 0:throw tf(bl.Char,Wl());case"\u2028":case"\u2029":!function(e){Ol.warn(`JSON5: '${ef(e)}' in strings is not valid ECMAScript; consider escaping.`)}(Nl)}xl+=Wl()}};function Kl(e,t){return{type:e,value:t,line:Ml,column:Ll}}function ql(e){for(const t of e){if(Ul()!==t)throw tf(bl.Char,Wl());Wl()}}function Yl(){let e="",t=4;for(;t-- >0;){const t=Ul();if(!Al.JudgeUtil.isHexDigit(t))throw tf(bl.Char,Wl());e+=Wl()}return String.fromCodePoint(parseInt(e,16))}const Xl={start(){if("eof"===_l.type)throw tf(bl.EOF);Zl()},beforePropertyName(){switch(_l.type){case"identifier":case"string":return Pl=_l.value,void(Il="afterPropertyName");case"punctuator":return void Ql();case"eof":throw tf(bl.EOF)}},afterPropertyName(){if("eof"===_l.type)throw tf(bl.EOF);Il="beforePropertyValue"},beforePropertyValue(){if("eof"===_l.type)throw tf(bl.EOF);Zl()},afterPropertyValue(){if("eof"===_l.type)throw tf(bl.EOF);switch(_l.value){case",":return void(Il="beforePropertyName");case"}":Ql()}},beforeArrayValue(){if("eof"===_l.type)throw tf(bl.EOF);"punctuator"!==_l.type||"]"!==_l.value?Zl():Ql()},afterArrayValue(){if("eof"===_l.type)throw tf(bl.EOF);switch(_l.value){case",":return void(Il="beforeArrayValue");case"]":Ql()}},end(){}};function Zl(){const e=function(){let e;switch(_l.type){case"punctuator":switch(_l.value){case"{":e={};break;case"[":e=[]}break;case"null":case"boolean":case"numeric":case"string":e=_l.value}return e}();if(jl&&"object"==typeof e&&(e._line=Ml,e._column=Ll),void 0===kl)kl=e;else{const t=Tl[Tl.length-1];Array.isArray(t)?jl&&"object"!=typeof e?t.push({value:e,_line:Ml,_column:Ll}):t.push(e):t[Pl]=jl&&"object"!=typeof e?{value:e,_line:Ml,_column:Ll}:e}!function(e){if(e&&"object"==typeof e)Tl.push(e),Il=Array.isArray(e)?"beforeArrayValue":"beforePropertyName";else{const e=Tl[Tl.length-1];Il=e?Array.isArray(e)?"afterArrayValue":"afterPropertyValue":"end"}}(e)}function Ql(){Tl.pop();const e=Tl[Tl.length-1];Il=e?Array.isArray(e)?"afterArrayValue":"afterPropertyValue":"end"}function ef(e){const t={"'":"\\'",'"':'\\"',"\\":"\\\\","\b":"\\b","\f":"\\f","\n":"\\n","\r":"\\r","\t":"\\t","\v":"\\v","\0":"\\0","\u2028":"\\u2028","\u2029":"\\u2029"};if(t[e])return t[e];if(e<" "){const t=e.charCodeAt(0).toString(16);return`\\x${`00${t}`.substring(t.length)}`}return e}function tf(e,t){let n="";switch(e){case bl.Char:n=void 0===t?`JSON5: invalid end of input at ${Ml}:${Ll}`:`JSON5: invalid character '${ef(t)}' at ${Ml}:${Ll}`;break;case bl.EOF:n=`JSON5: invalid end of input at ${Ml}:${Ll}`;break;case bl.Identifier:Ll-=5,n=`JSON5: invalid identifier character at ${Ml}:${Ll}`}const r=new nf(n);return r.lineNumber=Ml,r.columnNumber=Ll,r}class nf extends SyntaxError{}var rf=w&&w.__createBinding||(Object.create?function(e,t,n,r){void 0===r&&(r=n);var u=Object.getOwnPropertyDescriptor(t,n);u&&!("get"in u?!t.__esModule:u.writable||u.configurable)||(u={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,r,u)}:function(e,t,n,r){void 0===r&&(r=n),e[r]=t[n]}),uf=w&&w.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),of=w&&w.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var n in e)"default"!==n&&Object.prototype.hasOwnProperty.call(e,n)&&rf(t,e,n);return uf(t,e),t};Object.defineProperty(Y,"__esModule",{value:!0});var sf=Y.cleanWorkSpace=Ff=Y.executeInstallHvigor=yf=Y.isHvigorInstalled=mf=Y.isAllDependenciesInstalled=void 0;const cf=of(D.default),af=of(p.default),lf=b,ff=j,df=$,Df=X;let pf,Ef;var mf=Y.isAllDependenciesInstalled=function(){function e(e){const t=null==e?void 0:e.dependencies;return void 0===t?0:Object.getOwnPropertyNames(t).length}if(pf=gf(),Ef=Af(),e(pf)+1!==e(Ef))return!1;for(const e in null==pf?void 0:pf.dependencies)if(!(0,ff.hasNpmPackInPaths)(e,[lf.HVIGOR_PROJECT_DEPENDENCIES_HOME])||!hf(e,pf,Ef))return!1;return!0};function hf(e,t,n){return void 0!==n.dependencies&&(0,ff.offlinePluginConversion)(lf.HVIGOR_PROJECT_ROOT_DIR,t.dependencies[e])===n.dependencies[e]}var yf=Y.isHvigorInstalled=function(){return pf=gf(),Ef=Af(),(0,ff.hasNpmPackInPaths)(lf.HVIGOR_ENGINE_PACKAGE_NAME,[lf.HVIGOR_PROJECT_DEPENDENCIES_HOME])&&(0,ff.offlinePluginConversion)(lf.HVIGOR_PROJECT_ROOT_DIR,pf.hvigorVersion)===Ef.dependencies[lf.HVIGOR_ENGINE_PACKAGE_NAME]};const Cf={cwd:lf.HVIGOR_PROJECT_DEPENDENCIES_HOME,stdio:["inherit","inherit","inherit"]};var Ff=Y.executeInstallHvigor=function(){(0,df.logInfoPrintConsole)("Hvigor installing...");const e={dependencies:{}};e.dependencies[lf.HVIGOR_ENGINE_PACKAGE_NAME]=(0,ff.offlinePluginConversion)(lf.HVIGOR_PROJECT_ROOT_DIR,pf.hvigorVersion);try{cf.mkdirSync(lf.HVIGOR_PROJECT_DEPENDENCIES_HOME,{recursive:!0});const t=af.resolve(lf.HVIGOR_PROJECT_DEPENDENCIES_HOME,lf.DEFAULT_PACKAGE_JSON);cf.writeFileSync(t,JSON.stringify(e))}catch(e){(0,df.logErrorAndExit)(e)}!function(){const e=["config","set","store-dir",lf.HVIGOR_PNPM_STORE_PATH];(0,ff.executeCommand)(lf.HVIGOR_WRAPPER_PNPM_SCRIPT_PATH,e,Cf)}(),(0,ff.executeCommand)(lf.HVIGOR_WRAPPER_PNPM_SCRIPT_PATH,["install"],Cf)};function gf(){const e=af.resolve(lf.HVIGOR_PROJECT_WRAPPER_HOME,lf.DEFAULT_HVIGOR_CONFIG_JSON_FILE_NAME);return cf.existsSync(e)||(0,df.logErrorAndExit)(`Error: Hvigor config file ${e} does not exist.`),(0,Df.parseJsonFile)(e)}function Af(){return cf.existsSync(lf.HVIGOR_PROJECT_DEPENDENCY_PACKAGE_JSON_PATH)?(0,Df.parseJsonFile)(lf.HVIGOR_PROJECT_DEPENDENCY_PACKAGE_JSON_PATH):{dependencies:{}}}sf=Y.cleanWorkSpace=function(){if((0,df.logInfoPrintConsole)("Hvigor cleaning..."),!cf.existsSync(lf.HVIGOR_PROJECT_DEPENDENCIES_HOME))return;const e=cf.readdirSync(lf.HVIGOR_PROJECT_DEPENDENCIES_HOME);if(e&&0!==e.length){cf.existsSync(lf.HVIGOR_BOOT_JS_FILE_PATH)&&(0,ff.executeCommand)(process.argv[0],[lf.HVIGOR_BOOT_JS_FILE_PATH,"--stop-daemon"],{});try{e.forEach((e=>{cf.rmSync(af.resolve(lf.HVIGOR_PROJECT_DEPENDENCIES_HOME,e),{recursive:!0})}))}catch(e){(0,df.logErrorAndExit)(`The hvigor build tool cannot be installed. Please manually clear the workspace directory and synchronize the project again.\n\n Workspace Path: ${lf.HVIGOR_PROJECT_DEPENDENCIES_HOME}.`)}}};var vf={},Sf=w&&w.__createBinding||(Object.create?function(e,t,n,r){void 0===r&&(r=n);var u=Object.getOwnPropertyDescriptor(t,n);u&&!("get"in u?!t.__esModule:u.writable||u.configurable)||(u={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,r,u)}:function(e,t,n,r){void 0===r&&(r=n),e[r]=t[n]}),wf=w&&w.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),Of=w&&w.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var n in e)"default"!==n&&Object.prototype.hasOwnProperty.call(e,n)&&Sf(t,e,n);return wf(t,e),t};Object.defineProperty(vf,"__esModule",{value:!0});var bf=vf.executeBuild=void 0;const _f=b,Bf=Of(D.default),Pf=Of(p.default),kf=$;bf=vf.executeBuild=function(){const e=Pf.resolve(_f.HVIGOR_PROJECT_DEPENDENCIES_HOME,"node_modules","@ohos","hvigor","bin","hvigor.js");try{const t=Bf.realpathSync(e);require(t)}catch(t){(0,kf.logErrorAndExit)(`Error: ENOENT: no such file ${e},delete ${_f.HVIGOR_PROJECT_DEPENDENCIES_HOME} and retry.`)}},function(){if(O.checkNpmConifg(),O.environmentHandler(),O.isPnpmAvailable()||O.executeInstallPnpm(),yf()&&mf())bf();else{sf();try{Ff()}catch(e){return void sf()}bf()}}(); \ No newline at end of file diff --git a/storage/storagefileiojstest/hvigorfile.ts b/storage/storagefileiojstest/hvigorfile.ts deleted file mode 100644 index 0b9c10fc3ade5a54609b2d639f808ca7c25a611a..0000000000000000000000000000000000000000 --- a/storage/storagefileiojstest/hvigorfile.ts +++ /dev/null @@ -1,16 +0,0 @@ -/** - * Copyright (c) 2023 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. - */ -// Script for compiling build behavior. It is built in the build plug-in and cannot be modified currently. -export { legacyAppTasks } from '@ohos/hvigor-ohos-plugin'; \ No newline at end of file diff --git a/storage/storagefileiojstest/hvigorw b/storage/storagefileiojstest/hvigorw deleted file mode 100755 index b4d7760e72934718fc616fcef2806a1c7f04ba34..0000000000000000000000000000000000000000 --- a/storage/storagefileiojstest/hvigorw +++ /dev/null @@ -1,61 +0,0 @@ -# Copyright (c) 2023 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. - -#!/bin/bash - -# ---------------------------------------------------------------------------- -# Hvigor startup script, version 1.0.0 -# -# Required ENV vars: -# ------------------ -# NODE_HOME - location of a Node home dir -# or -# Add /usr/local/nodejs/bin to the PATH environment variable -# ---------------------------------------------------------------------------- - -HVIGOR_APP_HOME=$(dirname $(readlink -f $0)) -HVIGOR_WRAPPER_SCRIPT=${HVIGOR_APP_HOME}/hvigor/hvigor-wrapper.js -warn() { - echo "" - echo -e "\033[1;33m`date '+[%Y-%m-%d %H:%M:%S]'`$@\033[0m" -} - -error() { - echo "" - echo -e "\033[1;31m`date '+[%Y-%m-%d %H:%M:%S]'`$@\033[0m" -} - -fail() { - error "$@" - exit 1 -} - -# Determine node to start hvigor wrapper script -if [ -n "${NODE_HOME}" ];then - EXECUTABLE_NODE="${NODE_HOME}/bin/node" - if [ ! -x "$EXECUTABLE_NODE" ];then - fail "ERROR: NODE_HOME is set to an invalid directory,check $NODE_HOME\n\nPlease set NODE_HOME in your environment to the location where your nodejs installed" - fi -else - EXECUTABLE_NODE="node" - which ${EXECUTABLE_NODE} > /dev/null 2>&1 || fail "ERROR: NODE_HOME is not set and not 'node' command found in your path" -fi - -# Check hvigor wrapper script -if [ ! -r "$HVIGOR_WRAPPER_SCRIPT" ];then - fail "ERROR: Couldn't find hvigor/hvigor-wrapper.js in ${HVIGOR_APP_HOME}" -fi - -# start hvigor-wrapper script -exec "${EXECUTABLE_NODE}" \ - "${HVIGOR_WRAPPER_SCRIPT}" "$@" diff --git a/storage/storagefileiojstest/hvigorw.bat b/storage/storagefileiojstest/hvigorw.bat deleted file mode 100644 index a9cc1302dc821de7f9f82c3327673a730945ec7d..0000000000000000000000000000000000000000 --- a/storage/storagefileiojstest/hvigorw.bat +++ /dev/null @@ -1,70 +0,0 @@ -@rem Copyright (C) 2023 Huawei Device Co., Ltd. -@rem Licensed under the Apache License, Version 2.0 (the "License"); -@rem you may not use this file except in compliance with the License. -@rem You may obtain a copy of the License at -@rem -@rem http://www.apache.org/licenses/LICENSE-2.0 -@rem -@rem Unless required by applicable law or agreed to in writing, software -@rem distributed under the License is distributed on an "AS IS" BASIS, -@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -@rem See the License for the specific language governing permissions and -@rem limitations under the License. - -@if "%DEBUG%" == "" @echo off -@rem ########################################################################## -@rem -@rem Hvigor startup script for Windows -@rem -@rem ########################################################################## - -@rem Set local scope for the variables with windows NT shell -if "%OS%"=="Windows_NT" setlocal - -set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. -set APP_BASE_NAME=%~n0 -set APP_HOME=%DIRNAME% - -@rem Resolve any "." and ".." in APP_HOME to make it shorter. -for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi - -set WRAPPER_MODULE_PATH=%APP_HOME%\hvigor\hvigor-wrapper.js -set NODE_EXE=node.exe - -goto start - -:start -@rem Find node.exe -if defined NODE_HOME goto findNodeFromNodeHome - -%NODE_EXE% --version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto execute - -echo. -echo ERROR: NODE_HOME is not set and no 'node' command could be found in your PATH. -echo. -echo Please set the NODE_HOME variable in your environment to match the -echo location of your NodeJs installation. - -goto fail - -:findNodeFromNodeHome -set NODE_HOME=%NODE_HOME:"=% -set NODE_EXE_PATH=%NODE_HOME%/%NODE_EXE% - -if exist "%NODE_EXE_PATH%" goto execute -echo. -echo ERROR: NODE_HOME is not set and no 'node' command could be found in your PATH. -echo. -echo Please set the NODE_HOME variable in your environment to match the -echo location of your NodeJs installation. - -goto fail - -:execute -@rem Execute hvigor -"%NODE_EXE%" %WRAPPER_MODULE_PATH% %* - -:fail -exit /b 1 diff --git a/storage/storagefileiojstest/oh-package.json5 b/storage/storagefileiojstest/oh-package.json5 deleted file mode 100644 index 1a98aac1810691829d1f9908395de4863cb0623d..0000000000000000000000000000000000000000 --- a/storage/storagefileiojstest/oh-package.json5 +++ /dev/null @@ -1,26 +0,0 @@ -/** - * Copyright (c) 2023 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. - */ -{ - "license": "", - "devDependencies": { - "@ohos/hypium": "1.0.6" - }, - "author": "", - "name": "myapplication454434", - "description": "Please describe the basic information.", - "main": "", - "version": "1.0.0", - "dependencies": {} -} diff --git a/storage/storagefileiojstest/src/main/config.json b/storage/storagefileiojstest/src/main/config.json new file mode 100644 index 0000000000000000000000000000000000000000..b920be6be9b934a410e1d2ad75d902b71a38f4c5 --- /dev/null +++ b/storage/storagefileiojstest/src/main/config.json @@ -0,0 +1,96 @@ +{ + "app": { + "bundleName": "ohos.acts.storage.fileio", + "vendor": "example", + "version": { + "code": 1000000, + "name": "1.0.0" + }, + "apiVersion": { + "compatible": 4, + "target": 5 + } + }, + "deviceConfig": {}, + "module": { + "package": "ohos.acts.storage.fileio", + "name": ".entry", + "deviceType": [ + "tablet", + "default", + "phone" + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "entry", + "moduleType": "entry", + "installationFree": true + }, + "abilities": [ + { + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ], + "orientation": "unspecified", + "formsEnabled": false, + "name": ".MainAbility", + "srcLanguage": "js", + "srcPath": "MainAbility", + "icon": "$media:icon", + "description": "$string:MainAbility_desc", + "label": "$string:MainAbility_label", + "type": "page", + "visible": true, + "launchType": "standard" + }, + { + "orientation": "unspecified", + "formsEnabled": false, + "name": ".TestAbility", + "srcLanguage": "js", + "srcPath": "TestAbility", + "icon": "$media:icon", + "description": "$string:TestAbility_desc", + "label": "$string:TestAbility_label", + "type": "page", + "visible": true, + "launchType": "standard" + } + ], + "js": [ + { + "pages": [ + "pages/index/index" + ], + "name": "default", + "window": { + "designWidth": 720, + "autoDesignWidth": false + } + }, + { + "pages": [ + "pages/index/index" + ], + "name": ".TestAbility", + "window": { + "designWidth": 720, + "autoDesignWidth": false + } + } + ], + "testRunner": { + "name": "OpenHarmonyTestRunner", + "srcPath": "TestRunner" + }, + "mainAbility": ".MainAbility", + "srcPath": "" + } +} \ No newline at end of file diff --git a/storage/storagefileiojstest/entry/src/main/js/MainAbility/pages/index/index.js b/storage/storagefileiojstest/src/main/js/MainAbility/app.js similarity index 73% rename from storage/storagefileiojstest/entry/src/main/js/MainAbility/pages/index/index.js rename to storage/storagefileiojstest/src/main/js/MainAbility/app.js index f086298302bd6362b079bf99cf40dfa1e00d85e9..b4d2bb9877f9c0dff9fd759072c6ea47f5791124 100644 --- a/storage/storagefileiojstest/entry/src/main/js/MainAbility/pages/index/index.js +++ b/storage/storagefileiojstest/src/main/js/MainAbility/app.js @@ -1,22 +1,23 @@ -/** - * Copyright (c) 2023 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. - */ -export default { - data: { - title: "" - }, - onInit() { - this.title = this.$t('strings.world'); - } -} +/* + * Copyright (C) 2021 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. + */ + +export default { + onCreate() { + console.info('ohos.acts.storage.fileio onCreate'); + }, + onDestroy() { + console.info('ohos.acts.storage.fileio onDestroy'); + } +}; diff --git a/storage/storagefileiojstest/entry/src/main/js/MainAbility/i18n/en-US.json b/storage/storagefileiojstest/src/main/js/MainAbility/i18n/en-US.json similarity index 61% rename from storage/storagefileiojstest/entry/src/main/js/MainAbility/i18n/en-US.json rename to storage/storagefileiojstest/src/main/js/MainAbility/i18n/en-US.json index a4c13dcbdc39c537073f638393d7726ac9a5cdc4..ead52ed2e09ec82aaf7aa9f4e714ed39ea88308e 100644 --- a/storage/storagefileiojstest/entry/src/main/js/MainAbility/i18n/en-US.json +++ b/storage/storagefileiojstest/src/main/js/MainAbility/i18n/en-US.json @@ -1,6 +1,6 @@ -{ - "strings": { - "hello": "Hello", - "world": "World" - } +{ + "strings": { + "hello": "Hello", + "world": "Test" + } } \ No newline at end of file diff --git a/storage/storagefileioerrorjstest/entry/src/main/js/MainAbility/i18n/zh-CN.json b/storage/storagefileiojstest/src/main/js/MainAbility/i18n/zh-CN.json similarity index 61% rename from storage/storagefileioerrorjstest/entry/src/main/js/MainAbility/i18n/zh-CN.json rename to storage/storagefileiojstest/src/main/js/MainAbility/i18n/zh-CN.json index b1c02368f72f929e4375a43170444de95dcc5984..3f48f2585b24a8fe4a745e8ee2972a9e991a7803 100644 --- a/storage/storagefileioerrorjstest/entry/src/main/js/MainAbility/i18n/zh-CN.json +++ b/storage/storagefileiojstest/src/main/js/MainAbility/i18n/zh-CN.json @@ -1,6 +1,6 @@ -{ - "strings": { - "hello": "您好", - "world": "世界" - } +{ + "strings": { + "hello": "您好", + "world": "测试" + } } \ No newline at end of file diff --git a/storage/storagefileiojstest/src/main/js/MainAbility/pages/index/index.css b/storage/storagefileiojstest/src/main/js/MainAbility/pages/index/index.css new file mode 100644 index 0000000000000000000000000000000000000000..6fda792753f2e15f22b529c7b90a82185b2770bf --- /dev/null +++ b/storage/storagefileiojstest/src/main/js/MainAbility/pages/index/index.css @@ -0,0 +1,9 @@ +.container { + flex-direction: column; + justify-content: center; + align-items: center; +} + +.title { + font-size: 100px; +} diff --git a/storage/storagefileiojstest/src/main/js/MainAbility/pages/index/index.hml b/storage/storagefileiojstest/src/main/js/MainAbility/pages/index/index.hml new file mode 100644 index 0000000000000000000000000000000000000000..f64b040a5ae394dbaa5e185e1ecd4f4556b92184 --- /dev/null +++ b/storage/storagefileiojstest/src/main/js/MainAbility/pages/index/index.hml @@ -0,0 +1,5 @@ +
+ + {{ $t('strings.hello') }} {{ title }} + +
diff --git a/storage/storagefileioerrorjstest/entry/src/main/js/MainAbility/app.js b/storage/storagefileiojstest/src/main/js/MainAbility/pages/index/index.js similarity index 61% rename from storage/storagefileioerrorjstest/entry/src/main/js/MainAbility/app.js rename to storage/storagefileiojstest/src/main/js/MainAbility/pages/index/index.js index 8c9a4fce93b5e76779bdf446c49269a5a51db98a..6a9118dbb96efe627c20c435fdc1286f5d8611bf 100644 --- a/storage/storagefileioerrorjstest/entry/src/main/js/MainAbility/app.js +++ b/storage/storagefileiojstest/src/main/js/MainAbility/pages/index/index.js @@ -1,26 +1,34 @@ -/** - * Copyright (c) 2023 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 hilog from '@ohos.hilog'; -export default { - onCreate() { - hilog.info(0x0000, 'testTag', '%{public}s', 'Application onCreate'); - }, - onDestroy() { - hilog.info(0x0000, 'testTag', '%{public}s', 'Application onDestroy'); - }, -} - - - +/* + * Copyright (C) 2021 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 app from '@system.app' + + +const injectRef = Object.getPrototypeOf(global) || global +injectRef.regeneratorRuntime = require('@babel/runtime/regenerator') + +export default { + data: { + title: '' + }, + onInit() { + this.title = this.$t('strings.world'); + }, + onShow() { + console.info('onShow finish') + }, + onReady() { + }, +} \ No newline at end of file diff --git a/storage/storagefileiojstest/entry/src/ohosTest/js/TestAbility/app.js b/storage/storagefileiojstest/src/main/js/TestAbility/app.js similarity index 62% rename from storage/storagefileiojstest/entry/src/ohosTest/js/TestAbility/app.js rename to storage/storagefileiojstest/src/main/js/TestAbility/app.js index 469c4f1380182e0dccb04f17eb95d9b503a56d29..d5ee271df29e516d1c8929054283e5f2bf5c981c 100644 --- a/storage/storagefileiojstest/entry/src/ohosTest/js/TestAbility/app.js +++ b/storage/storagefileiojstest/src/main/js/TestAbility/app.js @@ -1,33 +1,31 @@ -/** - * Copyright (c) 2023 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 hilog from '@ohos.hilog'; -import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry'; -import { Hypium } from '@ohos/hypium'; -import testsuite from '../test/List.test'; - -export default { - onCreate() { - hilog.info(0x0000, 'testTag', '%{public}s', 'TestApplication onCreate'); - var abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() - var abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() - hilog.info(0x0000, 'testTag', '%{public}s', 'start run testcase!!!'); - Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite) - }, - onDestroy() { - hilog.info(0x0000, 'testTag', '%{public}s', 'TestApplication onDestroy'); - } -}; - - +/* + * 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. + */ + +import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry' +import { Hypium } from '@ohos/hypium' +import testsuite from '../test/List.test' + +export default { + onCreate() { + console.info('TestApplication onCreate') + var abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() + var abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() + console.info('start run testcase!!!') + Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite) + }, + onDestroy() { + console.info("TestApplication onDestroy"); + } +}; diff --git a/storage/storagefileioerrorjstest/entry/src/ohosTest/js/TestAbility/i18n/en-US.json b/storage/storagefileiojstest/src/main/js/TestAbility/i18n/en-US.json similarity index 100% rename from storage/storagefileioerrorjstest/entry/src/ohosTest/js/TestAbility/i18n/en-US.json rename to storage/storagefileiojstest/src/main/js/TestAbility/i18n/en-US.json diff --git a/storage/storagefileioerrorjstest/entry/src/ohosTest/js/TestAbility/i18n/zh-CN.json b/storage/storagefileiojstest/src/main/js/TestAbility/i18n/zh-CN.json similarity index 100% rename from storage/storagefileioerrorjstest/entry/src/ohosTest/js/TestAbility/i18n/zh-CN.json rename to storage/storagefileiojstest/src/main/js/TestAbility/i18n/zh-CN.json diff --git a/storage/storagefileiojstest/entry/src/ohosTest/js/TestAbility/pages/index/index.css b/storage/storagefileiojstest/src/main/js/TestAbility/pages/index/index.css similarity index 94% rename from storage/storagefileiojstest/entry/src/ohosTest/js/TestAbility/pages/index/index.css rename to storage/storagefileiojstest/src/main/js/TestAbility/pages/index/index.css index b1bcd43387ba131cc1d30975ff7508a6f8084a4b..b21c92c6290ea747bd891e2ab673721afc5521ed 100644 --- a/storage/storagefileiojstest/entry/src/ohosTest/js/TestAbility/pages/index/index.css +++ b/storage/storagefileiojstest/src/main/js/TestAbility/pages/index/index.css @@ -1,30 +1,30 @@ -.container { - display: flex; - flex-direction: column; - justify-content: center; - align-items: center; - left: 0px; - top: 0px; - width: 100%; - height: 100%; -} - -.title { - font-size: 60px; - text-align: center; - width: 100%; - height: 40%; - margin: 10px; -} - -@media screen and (device-type: phone) and (orientation: landscape) { - .title { - font-size: 60px; - } -} - -@media screen and (device-type: tablet) and (orientation: landscape) { - .title { - font-size: 100px; - } +.container { + display: flex; + flex-direction: column; + justify-content: center; + align-items: center; + left: 0px; + top: 0px; + width: 100%; + height: 100%; +} + +.title { + font-size: 60px; + text-align: center; + width: 100%; + height: 40%; + margin: 10px; +} + +@media screen and (device-type: phone) and (orientation: landscape) { + .title { + font-size: 60px; + } +} + +@media screen and (device-type: tablet) and (orientation: landscape) { + .title { + font-size: 100px; + } } \ No newline at end of file diff --git a/storage/storagefileiojstest/src/main/js/TestAbility/pages/index/index.hml b/storage/storagefileiojstest/src/main/js/TestAbility/pages/index/index.hml new file mode 100644 index 0000000000000000000000000000000000000000..f64b040a5ae394dbaa5e185e1ecd4f4556b92184 --- /dev/null +++ b/storage/storagefileiojstest/src/main/js/TestAbility/pages/index/index.hml @@ -0,0 +1,5 @@ +
+ + {{ $t('strings.hello') }} {{ title }} + +
diff --git a/storage/storagefileioerrorjstest/entry/src/ohosTest/js/TestAbility/pages/index/index.js b/storage/storagefileiojstest/src/main/js/TestAbility/pages/index/index.js similarity index 93% rename from storage/storagefileioerrorjstest/entry/src/ohosTest/js/TestAbility/pages/index/index.js rename to storage/storagefileiojstest/src/main/js/TestAbility/pages/index/index.js index ad113c0d214ce0d80c42c75c62d881547b6294ee..d94b75c085fa1c16a0b2721609b18c57a7295476 100644 --- a/storage/storagefileioerrorjstest/entry/src/ohosTest/js/TestAbility/pages/index/index.js +++ b/storage/storagefileiojstest/src/main/js/TestAbility/pages/index/index.js @@ -1,5 +1,5 @@ -/** - * Copyright (c) 2023 Huawei Device Co., Ltd. +/* + * 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 @@ -12,6 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + export default { data: { title: "" diff --git a/storage/storagefileioerrorjstest/entry/src/ohosTest/js/TestRunner/OpenHarmonyTestRunner.js b/storage/storagefileiojstest/src/main/js/TestRunner/OpenHarmonyTestRunner.js similarity index 52% rename from storage/storagefileioerrorjstest/entry/src/ohosTest/js/TestRunner/OpenHarmonyTestRunner.js rename to storage/storagefileiojstest/src/main/js/TestRunner/OpenHarmonyTestRunner.js index 0c1fbd1b2f34dcf4f19a8abe89af6241a3d0677e..b9e78ce7cf73f1ade6ba52a408a44e33f5430f0d 100644 --- a/storage/storagefileioerrorjstest/entry/src/ohosTest/js/TestRunner/OpenHarmonyTestRunner.js +++ b/storage/storagefileiojstest/src/main/js/TestRunner/OpenHarmonyTestRunner.js @@ -1,41 +1,59 @@ -/** - * Copyright (c) 2023 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 hilog from '@ohos.hilog'; -import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry'; - - export default { - onPrepare() { - hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner OnPrepare'); - }, - onRun() { - hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner onRun run'); - var abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() - var abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() - - var testAbilityName = abilityDelegatorArguments.parameters['-p'] + '.TestAbility' - var cmd = 'aa start -d 0 -a ' + testAbilityName + ' -b ' + abilityDelegatorArguments.bundleName - var debug = abilityDelegatorArguments.parameters["-D"] - if (debug == 'true') - { - cmd += ' -D' - } - hilog.info(0x0000, 'testTag', 'cmd : %{public}s', cmd); - abilityDelegator.executeShellCommand(cmd, (err, data) => { - hilog.info(0x0000, 'testTag', 'executeShellCommand : err : %{public}s', JSON.stringify(err) ?? ''); - hilog.info(0x0000, 'testTag', 'executeShellCommand : data : %{public}s', data.stdResult ?? ''); - hilog.info(0x0000, 'testTag', 'executeShellCommand : data : %{public}s', data.exitCode ?? ''); - }) - } -}; +/* + * 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. + */ + +import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry' + +function translateParamsToString(parameters) { + const keySet = new Set([ + '-s class', '-s notClass', '-s suite', '-s itName', + '-s level', '-s testType', '-s size', '-s timeout', + '-s package', '-s dryRun' + ]) + let targetParams = ''; + for (const key in parameters) { + if (keySet.has(key)) { + targetParams += ' ' + key + ' ' + parameters[key] + } + } + return targetParams.trim() +} + + export default { + onPrepare() { + console.info('OpenHarmonyTestRunner OnPrepare') + }, + onRun() { + console.log('OpenHarmonyTestRunner onRun run') + var abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() + var abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() + + var testAbilityName = abilityDelegatorArguments.parameters['-p'] + '.TestAbility' + + var cmd = 'aa start -d 0 -a ' + testAbilityName + ' -b ' + abilityDelegatorArguments.bundleName + cmd += ' ' + translateParamsToString(abilityDelegatorArguments.parameters) + var debug = abilityDelegatorArguments.parameters["-D"] + console.info('debug value : '+debug) + if (debug == 'true') + { + cmd += ' -D' + } + console.info('cmd : '+cmd) + abilityDelegator.executeShellCommand(cmd, (err, data) => { + console.info('executeShellCommand : err : ' + JSON.stringify(err)); + console.info('executeShellCommand : data : ' + data.stdResult); + console.info('executeShellCommand : data : ' + data.exitCode); + }) + } +}; diff --git a/storage/storagefileiojstest/entry/src/ohosTest/js/test/Common.js b/storage/storagefileiojstest/src/main/js/test/Common.js similarity index 94% rename from storage/storagefileiojstest/entry/src/ohosTest/js/test/Common.js rename to storage/storagefileiojstest/src/main/js/test/Common.js index 5552107a9c6a1a8570509e89bd3c64422a7cb2ab..8f93b83109746e525f1955120adab4f366f5eec8 100644 --- a/storage/storagefileiojstest/entry/src/ohosTest/js/test/Common.js +++ b/storage/storagefileiojstest/src/main/js/test/Common.js @@ -1,143 +1,143 @@ -/* - * Copyright (C) 2023 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 fileio from '@ohos.fileio'; -import fileIO from '@ohos.file.fs'; -import featureAbility from '@ohos.ability.featureAbility'; - -export const FILE_CONTENT = 'hello world'; - -import { - describe, it, expect -} -from '@ohos/hypium' - -export function prepareFile(fpath, content) { - try { - let fd = fileio.openSync(fpath, 0o102, 0o666) - fileio.ftruncateSync(fd) - fileio.writeSync(fd, content) - fileio.fsyncSync(fd) - fileio.closeSync(fd) - return true - } - catch (e) { - console.log('Failed to prepareFile for ' + e) - return false - } -} -export function prepareEmptyFile(fpath) { - try { - let fd = fileio.openSync(fpath, 0o102, 0o777) - fileio.closeSync(fd) - return true - } - catch (e) { - console.log('Failed to prepareFile for ' + e) - return false - } -} -export function fileToReadOnly(fpath) { - try { - let fd = fileio.openSync(fpath, 0o1) - fileio.fchmodSync(fd, 0o444) - fileio.fsyncSync(fd) - fileio.closeSync(fd) - return true - } - catch (e) { - console.log('Failed to fileToReadOnly for ' + e); - return false - } -} -export function fileToWriteOnly(fpath) { - try { - let fd = fileio.openSync(fpath, 0o2) - fileio.fchmodSync(fd, 0o222) - fileio.fsyncSync(fd) - fileio.closeSync(fd) - return true - } - catch (e) { - console.log('Failed to fileToWriteOnly ' + e) - return false - } -} - -export async function nextFileName(testName) { - let context = featureAbility.getContext(); - let data = await context.getCacheDir(); - let BASE_PATH = data + '/'; - return BASE_PATH + testName + '_' + randomString(testName.length); -} -export async function fileName(testName) { - let context = featureAbility.getContext(); - let data = await context.getFilesDir(); - let BASE_PATH = data + '/'; - return BASE_PATH + testName + '_' + randomString(testName.length); -} - -export function randomString(num) { - let len= num; - var $chars = 'aaaabbbbcccc'; - var maxPos = $chars.length; - var pwd = ''; - for (var i = 0; i < len; i++) { - pwd += $chars.charAt(Math.floor(Math.random() * maxPos)); - } - return pwd; -} - -export function forceRemoveDir(path, num) { - for (let i = num; i >= 0; i--) { - if (i < num) { - path = path.replace(`/d${i}`, ""); - } - fileio.rmdirSync(path); - } -} - -function isIntNum(val) { - return typeof val === 'number' && val % 1 === 0; -} - -function isBigInt(val) { - return typeof val === 'bigint'; -} - -function isString(str) { - return (typeof str == 'string') && str.constructor == String; -} - -function isBoolean(val) { - return typeof val == 'boolean'; -} - -function isInclude(error, message) { - return error.toString().indexOf(message) != -1; -} - -export { - fileio, - fileIO, - isIntNum, - isBigInt, - isString, - isBoolean, - isInclude, - describe, - it, - expect +/* + * Copyright (C) 2021-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. + */ + +import fileio from '@ohos.fileio'; +import fileIO from '@ohos.file.fs'; +import featureAbility from '@ohos.ability.featureAbility'; + +export const FILE_CONTENT = 'hello world'; + +import { + describe, it, expect +} +from '@ohos/hypium' + +export function prepareFile(fpath, content) { + try { + let fd = fileio.openSync(fpath, 0o102, 0o666) + fileio.ftruncateSync(fd) + fileio.writeSync(fd, content) + fileio.fsyncSync(fd) + fileio.closeSync(fd) + return true + } + catch (e) { + console.log('Failed to prepareFile for ' + e) + return false + } +} +export function prepareEmptyFile(fpath) { + try { + let fd = fileio.openSync(fpath, 0o102, 0o777) + fileio.closeSync(fd) + return true + } + catch (e) { + console.log('Failed to prepareFile for ' + e) + return false + } +} +export function fileToReadOnly(fpath) { + try { + let fd = fileio.openSync(fpath, 0o1) + fileio.fchmodSync(fd, 0o444) + fileio.fsyncSync(fd) + fileio.closeSync(fd) + return true + } + catch (e) { + console.log('Failed to fileToReadOnly for ' + e); + return false + } +} +export function fileToWriteOnly(fpath) { + try { + let fd = fileio.openSync(fpath, 0o2) + fileio.fchmodSync(fd, 0o222) + fileio.fsyncSync(fd) + fileio.closeSync(fd) + return true + } + catch (e) { + console.log('Failed to fileToWriteOnly ' + e) + return false + } +} + +export async function nextFileName(testName) { + let context = featureAbility.getContext(); + let data = await context.getCacheDir(); + let BASE_PATH = data + '/'; + return BASE_PATH + testName + '_' + randomString(testName.length); +} +export async function fileName(testName) { + let context = featureAbility.getContext(); + let data = await context.getFilesDir(); + let BASE_PATH = data + '/'; + return BASE_PATH + testName + '_' + randomString(testName.length); +} + +export function randomString(num) { + let len= num; + var $chars = 'aaaabbbbcccc'; + var maxPos = $chars.length; + var pwd = ''; + for (var i = 0; i < len; i++) { + pwd += $chars.charAt(Math.floor(Math.random() * maxPos)); + } + return pwd; +} + +export function forceRemoveDir(path, num) { + for (let i = num; i >= 0; i--) { + if (i < num) { + path = path.replace(`/d${i}`, ""); + } + fileio.rmdirSync(path); + } +} + +function isIntNum(val) { + return typeof val === 'number' && val % 1 === 0; +} + +function isBigInt(val) { + return typeof val === 'bigint'; +} + +function isString(str) { + return (typeof str == 'string') && str.constructor == String; +} + +function isBoolean(val) { + return typeof val == 'boolean'; +} + +function isInclude(error, message) { + return error.toString().indexOf(message) != -1; +} + +export { + fileio, + fileIO, + isIntNum, + isBigInt, + isString, + isBoolean, + isInclude, + describe, + it, + expect }; \ No newline at end of file diff --git a/storage/storagefileiojstest/entry/src/ohosTest/js/test/FileIO.test.js b/storage/storagefileiojstest/src/main/js/test/FileIO.test.js similarity index 97% rename from storage/storagefileiojstest/entry/src/ohosTest/js/test/FileIO.test.js rename to storage/storagefileiojstest/src/main/js/test/FileIO.test.js index b39cb006b39381070624218d90d6381a5da41e6f..e36811f73f5b20318cdebbe203bbc4324aadff75 100644 --- a/storage/storagefileiojstest/entry/src/ohosTest/js/test/FileIO.test.js +++ b/storage/storagefileiojstest/src/main/js/test/FileIO.test.js @@ -1,4326 +1,4326 @@ -/* - * Copyright (C) 2023 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 fileio from '@ohos.fileio'; -import { describe,it,expect}from '@ohos/hypium' -import { - FILE_CONTENT, - prepareFile, - nextFileName, - prepareEmptyFile, - randomString, - fileName, - forceRemoveDir -} -from './Common' -export default function fileIOTest() { - describe('fileIOTest', function () { - - /** - * @tc.number SUB_STORAGE_FileIO_open&closesync_0000 - * @tc.name fileio_test_open_close_sync_000 - * @tc.desc Function of API, openSync. The test file is exist. - */ - it('fileio_test_open_close_sync_000', 0, async function () { - let fpath = await nextFileName('fileio_test_open_close_sync_000'); - try { - let fd = fileio.openSync(fpath, 0o102, 0o666); - expect(fd !== null).assertTrue(); - fileio.closeSync(fd); - fileio.unlinkSync(fpath); - } - catch (err) { - console.info('fileio_test_open_close_sync_000 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_OpenSync_0000 - * @tc.name fileio_test_open_000 - * @tc.desc Function of API, openSync(mode not for value). The test file is exist. - */ - it('fileio_test_open_000', 0, async function () { - let fpath = await nextFileName('fileio_test_open_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let fd = fileio.openSync(fpath, 0o202); - expect(fd !== null).assertTrue(); - fileio.closeSync(fd); - fileio.unlinkSync(fpath); - } - catch (err) { - console.info('fileio_test_open_000 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_OpenSync_0100 - * @tc.name fileio_test_open_001 - * @tc.desc Function of API, flags=0o100. mode=0o001 - */ - it('fileio_test_open_001', 0, async function () { - let fpath = await nextFileName('fileio_test_open_001'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let fd = fileio.openSync(fpath, 0o100, 0o001); - expect(fd !== null).assertTrue(); - fileio.closeSync(fd); - fileio.unlinkSync(fpath); - } - catch (err) { - console.info('fileio_test_open_001 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_OpenSync_0200 - * @tc.name fileio_test_open_002 - * @tc.desc Function of API, - */ - it('fileio_test_open_002', 0, async function () { - let fpath = await nextFileName('fileio_test_open_002'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let fd = fileio.openSync(fpath); - expect(fd !== null).assertTrue(); - fileio.closeSync(fd); - fileio.unlinkSync(fpath); - } - catch (err) { - console.info('fileio_test_open_002 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_OpenSync_0300 - * @tc.name fileio_test_open_003 - * @tc.desc Function of API, flags=0o100. mode=0o004 - */ - it('fileio_test_open_003', 0, async function () { - let fpath = await nextFileName('fileio_test_open_003'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let fd = fileio.openSync(fpath, 0o100, 0o004); - expect(fd !== null).assertTrue(); - fileio.writeSync(fd, FILE_CONTENT, { - encoding: 'utf-8', - offset: 1, - length: 1, - }); - }catch (err) { - console.info('fileio_test_open_003 has failed for ' + err); - expect(err.message == "Bad file descriptor").assertTrue(); - fileio.unlinkSync(fpath); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_OpenSync_0400 - * @tc.name fileio_test_open_004 - * @tc.desc Function of API, flags=0o101. mode=0o002 - */ - it('fileio_test_open_004', 0, async function () { - let fpath = await nextFileName('fileio_test_open_004'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let fd = fileio.openSync(fpath, 0o101, 0o002); - expect(fd !== null).assertTrue(); - fileio.readSync(fd, new ArrayBuffer(4096), { - offset: 1, - }); - }catch (err) { - console.info('fileio_test_open_004 has failed for ' + err); - expect(err.message == "Bad file descriptor").assertTrue(); - fileio.unlinkSync(fpath); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_OpenSync_0500 - * @tc.name fileio_test_open_005 - * @tc.desc Function of API, flags=0o102. mode=0o001. - */ - it('fileio_test_open_005', 0, async function () { - let fpath = await nextFileName('fileio_test_open_005'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let fd = fileio.openSync(fpath, 0o102, 0o001); - expect(fd !== null).assertTrue(); - let wri = fileio.writeSync(fd, FILE_CONTENT, { - encoding: 'utf-8', - offset: 1, - length: 1, - }); - expect(wri !== null).assertTrue(); - let red = fileio.readSync(fd, new ArrayBuffer(4096), { - offset: 1, - }); - expect(red !== null).assertTrue(); - fileio.closeSync(fd); - fileio.unlinkSync(fpath); - } - catch (err) { - console.info('fileio_test_open_005 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_OpenSync_0600 - * @tc.name fileio_test_open_006 - * @tc.desc Function of API, flags=0o200. mode=0o700 - */ - it('fileio_test_open_006', 0, async function () { - let fpath = await nextFileName('fileio_test_open_006'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - fileio.openSync(fpath, 0o200, 0o700); - fileio.unlinkSync(fpath); - } - catch (err) { - console.info('fileio_test_open_006 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_OpenSync_0700 - * @tc.name fileio_test_open_007 - * @tc.desc Function of API, flags=0o302. mode=0o700. - */ - it('fileio_test_open_007', 0, async function () { - let fpath = await nextFileName('fileio_test_open_007'); - try { - let fd = fileio.openSync(fpath, 0o302, 0o700); - expect(fd !== null).assertTrue(); - let wri = fileio.writeSync(fd, FILE_CONTENT, { - encoding: 'utf-8', - offset: 1, - length: 1, - }); - expect(wri !== null).assertTrue(); - let red = fileio.readSync(fd, new ArrayBuffer(4096), { - offset: 1, - }); - expect(red !== null).assertTrue(); - fileio.closeSync(fd); - fileio.unlinkSync(fpath); - } - catch (err) { - console.info('fileio_test_open_007 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_OpenSync_0800 - * @tc.name fileio_test_open_008 - * @tc.desc Function of API, flags=0o102. mode=0o700 - */ - it('fileio_test_open_008', 0, async function () { - let fpath = await nextFileName('fileio_test_open_008'); - try { - let fd = fileio.openSync(fpath, 0o102, 0o700); - expect(fd !== null).assertTrue(); - let wri = fileio.writeSync(fd, FILE_CONTENT, { - encoding: 'utf-8', - offset: 1, - length: 1, - }); - expect(wri !== null).assertTrue(); - let red = fileio.readSync(fd, new ArrayBuffer(4096), { - offset: 1, - }); - expect(red !== null).assertTrue(); - fileio.closeSync(fd); - fileio.unlinkSync(fpath); - } - catch (err) { - console.info('fileio_test_open_008 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_OpenSync_0900 - * @tc.name fileio_test_open_009 - * @tc.desc Function of API, flags=0o302. - */ - it('fileio_test_open_009', 0, async function () { - let fpath = await nextFileName('fileio_test_open_009'); - try { - fileio.openSync(fpath, 0o302); - }catch (err) { - console.info('fileio_test_open_009 has failed for ' + err); - expect(err.message == "called with O_CREAT/O_TMPFILE but no mode").assertTrue(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_OpenSync_1000 - * @tc.name fileio_test_open_010 - * @tc.desc Function of API, flags=0o402. - */ - it('fileio_test_open_010', 0, async function () { - let fpath = await nextFileName('fileio_test_open_010'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let fd = fileio.openSync(fpath, 0o402); - expect(fd !== null).assertTrue(); - let wri = fileio.writeSync(fd, FILE_CONTENT, { - encoding: 'utf-8', - offset: 1, - length: 1, - }); - expect(wri !== null).assertTrue(); - let red = fileio.readSync(fd, new ArrayBuffer(4096), { - offset: 1, - }); - expect(red !== null).assertTrue(); - fileio.closeSync(fd); - fileio.unlinkSync(fpath); - } - catch (err) { - console.info('fileio_test_open_010 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_OpenSync_1100 - * @tc.name fileio_test_open_011 - * @tc.desc Function of API, flags=0o1000. - */ - it('fileio_test_open_011', 0, async function () { - let fpath = await nextFileName('fileio_test_open_011'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let fd = fileio.openSync(fpath, 0o1000); - expect(fd !== null).assertTrue(); - let red = fileio.readSync(fd, new ArrayBuffer(4096), { - offset: 1, - }); - expect(red !== null).assertTrue(); - fileio.closeSync(fd); - fileio.unlinkSync(fpath); - } - catch (err) { - console.info('fileio_test_open_011 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_OpenSync_1200 - * @tc.name fileio_test_open_012 - * @tc.desc Function of API, flags=0o1001. - */ - it('fileio_test_open_012', 0, async function () { - let fpath = await nextFileName('fileio_test_open_012'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let fd = fileio.openSync(fpath, 0o1001); - expect(fd !== null).assertTrue(); - fileio.readSync(fd, new ArrayBuffer(4096), { - offset: 1, - }); - } - catch (err) { - console.info('fileio_test_open_012 has failed for ' + err); - expect(err.message == "Bad file descriptor").assertTrue(); - fileio.unlinkSync(fpath); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_OpenSync_1300 - * @tc.name fileio_test_open_013 - * @tc.desc Function of API, flags=0o2002. - */ - it('fileio_test_open_013', 0, async function () { - let fpath = await nextFileName('fileio_test_open_013'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let fd = fileio.openSync(fpath, 0o2002); - expect(fd !== null).assertTrue(); - let wri = fileio.writeSync(fd, 'hello', { - encoding: 'utf-8', - offset: 1, - length: 1, - }); - expect(wri !== null).assertTrue(); - let red = fileio.readSync(fd, new ArrayBuffer(4096), { - offset: 1, - }); - expect(red !== null).assertTrue(); - fileio.closeSync(fd); - fileio.unlinkSync(fpath); - } - catch (err) { - console.info('fileio_test_open_013 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_OpenSync_1400 - * @tc.name fileio_test_open_014 - * @tc.desc Function of API, flags=0o4002. - */ - it('fileio_test_open_014', 0, async function (done) { - let fpath = await nextFileName('fileio_test_open_014'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let fd = fileio.openSync(fpath, 0o4002); - expect(fd !== null).assertTrue(); - let fd2 = fileio.openSync(fpath, 0o4002); - expect(fd2 !== null).assertTrue(); - fileio.closeSync(fd); - fileio.closeSync(fd2); - fileio.unlinkSync(fpath); - done(); - } - catch (err) { - console.info('fileio_test_open_014 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_OpenSync_1500 - * @tc.name fileio_test_open_015 - * @tc.desc Function of API, flags=0o20002. - */ - it('fileio_test_open_015', 0, async function () { - let fpath = await nextFileName('fileio_test_open_015'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let fd = fileio.openSync(fpath, 0o20002); - expect(fd !== null).assertTrue(); - fileio.closeSync(fd); - fileio.unlinkSync(fpath); - } - catch (err) { - console.info('fileio_test_open_015 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_OpenSync_1600 - * @tc.name fileio_test_open_016 - * @tc.desc Function of API, flags=0o10002. - */ - it('fileio_test_open_016', 0, async function () { - let fpath = await nextFileName('fileio_test_open_016'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let fd = fileio.openSync(fpath, 0o10002); - expect(fd !== null).assertTrue(); - fileio.closeSync(fd); - fileio.unlinkSync(fpath); - } - catch (err) { - console.info('fileio_test_open_016 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_OpenSync_1700 - * @tc.name fileio_test_open_017 - * @tc.desc Function of API, flags=0o4010002. - */ - it('fileio_test_open_017', 0, async function () { - let fpath = await nextFileName('fileio_test_open_017'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let fd = fileio.openSync(fpath, 0o4010002); - expect(fd !== null).assertTrue(); - fileio.closeSync(fd); - fileio.unlinkSync(fpath); - } - catch (err) { - console.info('fileio_test_open_017 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_OpenSync_1800 - * @tc.name fileio_test_open_018 - * @tc.desc Function of API, flags=0o100002. - */ - it('fileio_test_open_018', 0, async function () { - let fpath = await nextFileName('fileio_test_open_018'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let fd = fileio.openSync(fpath, 0o100002); - expect(fd !== null).assertTrue(); - fileio.closeSync(fd); - fileio.unlinkSync(fpath); - } - catch (err) { - console.info('fileio_test_open_018 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_OpenSync_1900 - * @tc.name fileio_test_open_019 - * @tc.desc Function of API, flags=0o40002. mode=0o700 - */ - it('fileio_test_open_019', 0, async function () { - let fpath = await nextFileName('fileio_test_open_019'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - fileio.openSync(fpath, 0o40002, 0o700); - fileio.unlinkSync(fpath); - }catch (err) { - console.info('fileio_test_open_019 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_OpenSync_2100 - * @tc.name fileio_test_open_021 - * @tc.desc Function of API, flags=0o2000002. - */ - it('fileio_test_open_021', 0, async function () { - let fpath = await nextFileName('fileio_test_open_021'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let fd = fileio.openSync(fpath, 0o2000002); - expect(fd !== null).assertTrue(); - fileio.closeSync(fd); - fileio.unlinkSync(fpath); - } - catch (err) { - console.info('fileio_test_open_021 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_OpenSync_2200 - * @tc.name fileio_test_open_022 - * @tc.desc Function of API, flags=0o200000. - */ - it('fileio_test_open_022', 0, async function () { - let dpath = await nextFileName('fileio_test_open_022') + 'd'; - fileio.mkdirSync(dpath); - try { - fileio.openSync(dpath, 0o200000, 0o666); - fileio.rmdirSync(dpath); - } - catch (err) { - console.info('fileio_test_open_022 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_OpenSync_2300 - * @tc.name fileio_test_open_023 - * @tc.desc Function of API, flags=0o400002. - */ - it('fileio_test_open_023', 0, async function () { - let fpath = await nextFileName('fileio_test_open_023'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let fd = fileio.openSync(fpath, 0o400002); - expect(fd !== null).assertTrue(); - fileio.closeSync(fd); - fileio.unlinkSync(fpath); - } - catch (err) { - console.info('fileio_test_open_023 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_OpenSync_2400 - * @tc.name fileio_test_open_024 - * @tc.desc Function of API, flags=0o1000002.mode=0o700 - */ - it('fileio_test_open_024', 0, async function () { - let fpath = await nextFileName('fileio_test_open_024'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let fd = fileio.openSync(fpath, 0o1000002, 0o700); - expect(fd !== null).assertTrue(); - fileio.closeSync(fd); - fileio.unlinkSync(fpath); - } - catch (err) { - console.info('fileio_test_open_024 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_OpenSync_2500 - * @tc.name fileio_test_open_025 - * @tc.desc Function of API, flags=0o10000002. - */ - it('fileio_test_open_025', 0, async function () { - let fpath = await nextFileName('fileio_test_open_025'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let fd = fileio.openSync(fpath, 0o10000002); - expect(fd !== null).assertTrue(); - fileio.closeSync(fd); - fileio.unlinkSync(fpath); - } - catch (err) { - console.info('fileio_test_open_025 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_OpenSync_2600 - * @tc.name fileio_test_open_026 - * @tc.desc Function of API,flags=0o002.mode=0o700 - */ - it('fileio_test_open_026', 0, async function () { - let fpath = await nextFileName('fileio_test_open_026'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let fd = fileio.openSync(fpath, 0o002, 0o700); - expect(fd !== null).assertTrue(); - fileio.closeSync(fd); - fileio.unlinkSync(fpath); - } - catch (err) { - console.info('fileio_test_open_026 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_OpenSync_2700 - * @tc.name fileio_test_open_027 - * @tc.desc Function of API, flags=0o002.mode=0o400 - */ - it('fileio_test_open_027', 0, async function () { - let fpath = await nextFileName('fileio_test_open_027'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let fd = fileio.openSync(fpath, 0o002, 0o400); - expect(fd !== null).assertTrue(); - let red = fileio.readSync(fd, new ArrayBuffer(4096), { - offset: 1, - }); - expect(red !== null).assertTrue(); - fileio.writeSync(fd, 'hello', { - encoding: 'utf-8', - offset: 1, - length: 1, - }); - throw new Error('read only'); - } - catch (err) { - console.info('fileio_test_open_027 has failed for ' + err); - fileio.unlinkSync(fpath); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_OpenSync_2800 - * @tc.name fileio_test_open_028 - * @tc.desc Function of API, flags=0o002.mode=0o200 - */ - it('fileio_test_open_028', 0, async function () { - let fpath = await nextFileName('fileio_test_open_028'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let fd = fileio.openSync(fpath, 0o002, 0o200); - expect(fd !== null).assertTrue(); - let wri = fileio.writeSync(fd, 'hello', { - encoding: 'utf-8', - offset: 1, - length: 1, - }); - expect(wri !== null).assertTrue(); - fileio.readSync(fd, new ArrayBuffer(4096), { - offset: 1, - }); - throw new Error('write only'); - } - catch (err) { - console.info('fileio_test_open_028 has failed for ' + err); - fileio.unlinkSync(fpath); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_OpenSync_2900 - * @tc.name fileio_test_open_029 - * @tc.desc Function of API, flags=0o002.mode=0o100 - */ - it('fileio_test_open_029', 0, async function () { - let fpath = await nextFileName('fileio_test_open_029'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let fd = fileio.openSync(fpath, 0o002, 0o100); - expect(fd !== null).assertTrue(); - fileio.closeSync(fd); - fileio.unlinkSync(fpath); - } - catch (err) { - console.info('fileio_test_open_029 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_OpenSync_3000 - * @tc.name fileio_test_open_030 - * @tc.desc Function of API, flags=0o002.mode=0o070 - */ - it('fileio_test_open_030', 0, async function () { - let fpath = await nextFileName('fileio_test_open_030'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let fd = fileio.openSync(fpath, 0o002, 0o070); - expect(fd !== null).assertTrue(); - let wri = fileio.writeSync(fd, 'hello', { - encoding: 'utf-8', - offset: 1, - length: 1, - }); - expect(wri !== null).assertTrue(); - let red = fileio.readSync(fd, new ArrayBuffer(4096), { - offset: 1, - }); - expect(red !== null).assertTrue(); - fileio.closeSync(fd); - fileio.unlinkSync(fpath); - } - catch (err) { - console.info('fileio_test_open_030 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_OpenSync_3100 - * @tc.name fileio_test_open_031 - * @tc.desc Function of API, flags=0o002.mode=0o040 - */ - it('fileio_test_open_031', 0, async function () { - let fpath = await nextFileName('fileio_test_open_031'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let fd = fileio.openSync(fpath, 0o002, 0o040); - expect(fd !== null).assertTrue(); - let red = fileio.readSync(fd, new ArrayBuffer(4096), { - offset: 1, - }); - expect(red !== null).assertTrue(); - fileio.writeSync(fd, 'hello', { - encoding: 'utf-8', - offset: 1, - length: 1, - }); - throw new Error('read only'); - } - catch (err) { - console.info('fileio_test_open_031 has failed for ' + err); - fileio.unlinkSync(fpath); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_OpenSync_3200 - * @tc.name fileio_test_open_032 - * @tc.desc Function of API, flags=0o002.mode=0o020 - */ - it('fileio_test_open_032', 0, async function () { - let fpath = await nextFileName('fileio_test_open_032'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let fd = fileio.openSync(fpath, 0o002, 0o020); - expect(fd !== null).assertTrue(); - let wri = fileio.writeSync(fd, 'hello', { - encoding: 'utf-8', - offset: 1, - length: 1, - }); - expect(wri !== null).assertTrue(); - fileio.readSync(fd, new ArrayBuffer(4096), { - offset: 1, - }); - throw new Error('write only'); - } - catch (err) { - console.info('fileio_test_open_032 has failed for ' + err); - fileio.unlinkSync(fpath); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_OpenSync_3300 - * @tc.name fileio_test_open_033 - * @tc.desc Function of API, flags=0o002.mode=0o010 - */ - it('fileio_test_open_033', 0, async function () { - let fpath = await nextFileName('fileio_test_open_033'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let fd = fileio.openSync(fpath, 0o002, 0o010); - expect(fd !== null).assertTrue(); - fileio.closeSync(fd); - fileio.unlinkSync(fpath); - } - catch (err) { - console.info('fileio_test_open_033 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_OpenSync_3400 - * @tc.name fileio_test_open_034 - * @tc.desc Function of API, flags=0o002.mode=0o007 - */ - it('fileio_test_open_034', 0, async function () { - let fpath = await nextFileName('fileio_test_open_034'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let fd = fileio.openSync(fpath, 0o002, 0o007); - expect(fd !== null).assertTrue(); - let ret = fileio.readSync(fd, new ArrayBuffer(4096), { - offset: 1, - }); - expect(ret !== null).assertTrue(); - let wri = fileio.writeSync(fd, 'hello', { - encoding: 'utf-8', - offset: 1, - length: 1, - }); - expect(wri !== null).assertTrue(); - fileio.closeSync(fd); - fileio.unlinkSync(fpath); - } - catch (err) { - console.info('fileio_test_open_034 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_OpenSync_3500 - * @tc.name fileio_test_open_035 - * @tc.desc Function of API, flags=0o002.mode=0o004 - */ - it('fileio_test_open_035', 0, async function () { - let fpath = await nextFileName('fileio_test_open_035'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let fd = fileio.openSync(fpath, 0o002, 0o004); - expect(fd !== null).assertTrue(); - let ret = fileio.readSync(fd, new ArrayBuffer(4096), { - offset: 1, - }); - expect(ret !== null).assertTrue(); - fileio.writeSync(fd, 'hello', { - encoding: 'utf-8', - offset: 1, - length: 1, - }); - throw new Error('read only'); - } - catch (err) { - console.info('fileio_test_open_035 has failed for ' + err); - fileio.unlinkSync(fpath); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_OpenSync_3600 - * @tc.name fileio_test_open_036 - * @tc.desc Function of API, flags=0o002.mode=0o002 - */ - it('fileio_test_open_036', 0, async function () { - let fpath = await nextFileName('fileio_test_open_036'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let fd = fileio.openSync(fpath, 0o002, 0o002); - expect(fd !== null).assertTrue(); - let wri = fileio.writeSync(fd, 'hello', { - encoding: 'utf-8', - offset: 1, - length: 1, - }); - expect(wri !== null).assertTrue(); - fileio.readSync(fd, new ArrayBuffer(4096), { - offset: 1, - }); - throw new Error('write only'); - } - catch (err) { - console.info('fileio_test_open_036 has failed for ' + err); - fileio.unlinkSync(fpath); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_OpenSync_3700 - * @tc.name fileio_test_open_037 - * @tc.desc Function of API, flags=0o002.mode=0o001 - */ - it('fileio_test_open_037', 0, async function () { - let fpath = await nextFileName('fileio_test_open_037'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let fd = fileio.openSync(fpath, 0o002, 0o001); - fileio.closeSync(fd); - fileio.unlinkSync(fpath); - } - catch (err) { - console.info('fileio_test_open_037 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_OpenSync_3800 - * @tc.name fileio_test_open_038 - * @tc.desc Function of API, flags=0o102.mode=0o700 - */ - it('fileio_test_open_038', 0, async function () { - let txt = randomString(4100); - let fpath = await nextFileName(txt); - try { - fileio.openSync(fpath, 0o102, 0o700); - } - catch (err) { - console.info('fileio_test_open_038 has failed for ' + err); - expect(err.message == 'Filename too long').assertTrue(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_OpenSync_0100 - * @tc.name fileio_test_open_sync_001 - * @tc.desc Function of API, openSync(flags=0o200). The test file is exist. - */ - it('fileio_test_open_sync_001', 0, async function () { - let fpath = await nextFileName('fileio_test_open_sync_001'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let fd = fileio.openSync(fpath, 0o200); - expect(fd !== null).assertTrue(); - fileio.closeSync(fd); - fileio.unlinkSync(fpath); - } - catch (err) { - console.info('fileio_test_open_sync_001 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_OpenSync_0200 - * @tc.name fileio_test_open_sync_002 - * @tc.desc Function of API, openSync(flags=0o201). The test file is exist. - */ - it('fileio_test_open_sync_002', 0, async function () { - let fpath = await nextFileName('fileio_test_open_sync_002'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let fd = fileio.openSync(fpath, 0o201); - expect(fd !== null).assertTrue(); - fileio.closeSync(fd); - fileio.unlinkSync(fpath); - } - catch (err) { - console.info('fileio_test_open_sync_002 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_OpenSync_0300 - * @tc.name fileio_test_open_sync_003 - * @tc.desc Function of API, openSync(flags=0o202). The test file is exist. - */ - it('fileio_test_open_sync_003', 0, async function () { - let fpath = await nextFileName('fileio_test_open_sync_003'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let fd = fileio.openSync(fpath, 0o202); - expect(fd !== null).assertTrue(); - fileio.closeSync(fd); - fileio.unlinkSync(fpath); - } - catch (err) { - console.info('fileio_test_open_sync_003 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_OpenSync_0400 - * @tc.name fileio_test_open_sync_004 - * @tc.desc Function of API, openSync(flags=0o102, mode=0o777). The test file is not exist. - */ - it('fileio_test_open_sync_004', 0, async function () { - let fpath = await nextFileName('fileio_test_open_sync_004'); - try { - let fd = fileio.openSync(fpath, 0o102, 0o777); - expect(fd !== null).assertTrue(); - fileio.closeSync(fd); - fileio.unlinkSync(fpath); - } - catch (err) { - console.info('fileio_test_open_sync_004 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_OpenSync_0500 - * @tc.name fileio_test_open_sync_005 - * @tc.desc Function of API, openSync(flags not for value, mode not for value). - */ - it('fileio_test_open_sync_005', 0, async function () { - let dpath = await nextFileName('fileio_test_open_sync_005') + 'd' - try { - fileio.mkdirSync(dpath); - let fd = fileio.openSync(dpath); - expect(fd !== null).assertTrue(); - fileio.closeSync(fd); - fileio.rmdirSync(dpath); - } - catch (err) { - console.info('fileio_test_open_sync_005 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_OpenSync_0600 - * @tc.name fileio_test_open_sync_006 - * @tc.desc Function of API, openSync(flags=0o1, illegal parameter). - */ - it('fileio_test_open_sync_006', 0, async function () { - let dpath = await nextFileName('fileio_test_open_sync_006') + 'd' - try { - fileio.mkdirSync(dpath); - fileio.openSync(dpath, 0o1); - }catch (err) { - console.info('fileio_test_open_sync_006 has failed for ' + err); - expect(err.message == "Is a directory").assertTrue(); - fileio.rmdirSync(dpath); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_OpenSync_0700 - * @tc.name fileio_test_open_sync_007 - * @tc.desc Function of API, openSync(fpath too long). - */ - it('fileio_test_open_sync_007', 0, async function () { - let dpath = await nextFileName('fileio_test_open_sync_007'); - fileio.mkdirSync(dpath); - try { - for (let i = 0; i < 16; i++) { - if (i == 15) { - let fpath = dpath + '/f' + i; - fileio.openSync(fpath, 0o102, 0o777); - fileio.unlinkSync(fpath); - } else { - dpath = dpath + '/d' + i; - fileio.mkdirSync(dpath); - } - } - throw new Error('fpath too long'); - } - catch (err) { - console.info('fileio_test_open_sync_007 has failed for ' + err); - forceRemoveDir(dpath, 15); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_OpenSync_0800 - * @tc.name fileio_test_open_sync_008 - * @tc.desc Function of API, openSync(filename too long). - */ - it('fileio_test_open_sync_008', 0, async function () { - let fpath = await nextFileName(randomString(256)); - try { - fileio.openSync(fpath, 0o102, 0o777); - } - catch (err) { - console.info('fileio_test_open_sync_008 has failed for ' + err); - expect(err.message == "Filename too long").assertTrue(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_OpenSync_0900 - * @tc.name fileio_test_open_sync_009 - * @tc.desc Function of API, openSync(dir layers too long). - */ - it('fileio_test_open_sync_009', 0, async function () { - let dpath = await nextFileName('fileio_test_open_sync_009'); - fileio.mkdirSync(dpath); - try { - for (let i = 0; i < 113; i++) { - if (i == 112) { - let fpath = dpath + '/f' + i - fileio.openSync(fpath, 0o102, 0o777); - fileio.unlinkSync(fpath); - } else { - dpath = dpath + '/d' + i - fileio.mkdirSync(dpath); - } - } - throw new Error('dir layers too long'); - } - catch (err) { - console.info('fileio_test_open_sync_009 has failed for ' + err); - forceRemoveDir(dpath, 112); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_OpenSync_1000 - * @tc.name fileio_test_open_sync_010 - * @tc.desc Function of API, openSync(filename has special characters). - */ - it('fileio_test_open_sync_010', 0, async function () { - let fpath = await nextFileName('?*:<>/|'); - try { - fileio.openSync(fpath, 0o102, 0o777); - } catch (err) { - console.info('fileio_test_open_sync_010 has failed for ' + err); - expect(err.message == "No such file or directory").assertTrue(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_CloseSync_0000 - * @tc.name fileio_test_close_sync_000 - * @tc.desc Function of API, close. The test file is not exist. - */ - it('fileio_test_close_sync_000', 0, async function () { - let fpath = await nextFileName('fileio_test_chmod_sync_000'); - try { - fileio.closeSync(fpath); - } - catch (err) { - console.info('fileio_test_close_sync_000 has failed for ' + err); - expect(err.message == "Invalid fd").assertTrue(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_CloseSync_0100 - * @tc.name fileio_test_close_sync_001 - * @tc.desc Function of API, close(fpath=vaild value). The test file is not exist. - */ - it('fileio_test_close_sync_001', 0, async function () { - try { - fileio.closeSync(-1); - expect(false).assertTrue(); - } - catch (err) { - console.info('fileio_test_close_sync_001 has failed for ' + err); - expect(err.message == "Invalid fd").assertTrue(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_AccessSync_0000 - * @tc.name fileio_test_access_sync_000 - * @tc.desc Function of API,access. The test file is exist. - */ - it('fileio_test_access_sync_000', 0, async function () { - let fpath = await nextFileName('fileio_test_access_sync_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - fileio.accessSync(fpath); - fileio.unlinkSync(fpath); - } - catch (err) { - console.info('fileio_test_access_sync_000 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_AccessSync_0100 - * @tc.name fileio_test_access_sync_001 - * @tc.desc Function of API, launch via fileio. The test file is not exist. - */ - it('fileio_test_access_sync_001', 0, async function () { - try { - fileio.accessSync(1); - } catch (err) { - console.info('fileio_test_access_sync_001 has failed for ' + err); - expect(err.message == "Invalid path").assertTrue(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_AccessSync_0200 - * @tc.name fileio_test_access_sync_002 - * @tc.desc Function of API, access. The test file is not exist. - */ - it('fileio_test_access_sync_002', 0, async function () { - let fpath = await nextFileName('fileIOTest'); - try { - fileio.accessSync(fpath); - }catch (err) { - console.info('fileio_test_access_sync_002 has failed for ' + err); - expect(err.message == "No such file or directory").assertTrue(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_AccessSync_0300 - * @tc.name fileio_test_access_sync_003 - * @tc.desc Function of API, access(mode=1). The test file is exist and have the authority. - */ - it('fileio_test_access_sync_003', 0, async function () { - let fpath = await nextFileName('fileio_test_access_sync_004'); - expect(prepareEmptyFile(fpath)).assertTrue(); - try { - fileio.accessSync(fpath); - fileio.accessSync(fpath, 1); - fileio.unlinkSync(fpath); - } - catch (err) { - console.info('fileio_test_access_sync_004 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_AccessSync_0400 - * @tc.name fileio_test_access_sync_004 - * @tc.desc Function of API, access(mode=2). The test file is exist and have the authority. - */ - it('fileio_test_access_sync_004', 0, async function () { - let fpath = await nextFileName('fileio_test_access_sync_004'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - fileio.accessSync(fpath); - fileio.accessSync(fpath, 2); - fileio.unlinkSync(fpath); - } - catch (err) { - console.info('fileio_test_access_sync_004 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_AccessSync_0500 - * @tc.name fileio_test_access_sync_005 - * @tc.desc Function of API, access(fpath=dir address). The test dir is exist. - */ - it('fileio_test_access_sync_005', 0, async function () { - let dpath = await nextFileName('fileio_test_access_sync_005') + 'd' - try { - fileio.mkdirSync(dpath); - fileio.accessSync(dpath); - fileio.rmdirSync(dpath); - } - catch (err) { - console.info('fileio_test_access_sync_005 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_AccessSync_0600 - * @tc.name fileio_test_access_sync_006 - * @tc.desc Function of API, access(fpath=dir address). The test dir is not exist. - */ - it('fileio_test_access_sync_006', 0, async function () { - let dpath = await nextFileName('fileio_test_access_sync_006') + 'd' - try { - fileio.accessSync(dpath); - } - catch (err) { - console.info('fileio_test_access_sync_006 has failed for ' + err); - expect(err.message == "No such file or directory").assertTrue(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_AccessSync_0700 - * @tc.name fileio_test_access_sync_007 - * @tc.desc Function of API, access(mode=4). - */ - it('fileio_test_access_sync_007', 0, async function () { - let fpath = await nextFileName('fileio_test_access_sync_007'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - fileio.accessSync(fpath); - fileio.accessSync(fpath, 4); - fileio.unlinkSync(fpath); - } - catch (err) { - console.info('fileio_test_access_sync_007 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_Access_Promise_001 - * @tc.name fileio_test_access_promise_001 - * @tc.desc Function of API, access(mode=4). - */ - it('fileio_test_access_promise_001', 0, async function () { - let fpath = await nextFileName('fileio_test_access_promise_001'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - let fd = fileio.access(fpath).then(() => { - expect(fd !== null).assertTrue(); - fileio.unlinkSync(fpath); - console.info('file access Success'); - }).catch(function(err) { - console.info("file access err: " + JSON.stringify(err)); - }); - }); - - /** - * @tc.number SUB_STORAGE_FileIO_Access_Async_001 - * @tc.name fileio_test_access_async_001 - * @tc.desc Function of API, access(mode=4). - */ - it('fileio_test_access_async_001', 0, async function () { - let fpath = await nextFileName('fileio_test_access_async_001'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - let fd = fileio.access(fpath, function (err) { - expect(fd !== null).assertTrue(); - fileio.unlinkSync(fpath); - }); - }); - - /** - * @tc.number SUB_STORAGE_FileIO_UnlinkSync_0000 - * @tc.name fileio_test_unlink_sync_000 - * @tc.desc Function of API,unlinkSync. The test file is exist. - */ - it('fileio_test_unlink_sync_000', 0, async function () { - let fpath = await nextFileName('fileio_test_unlink_sync_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - fileio.unlinkSync(fpath); - } - catch (err) { - console.info('fileio_test_unlink_sync_000 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_UnlinkSync_0100 - * @tc.name fileio_test_unlink_sync_001 - * @tc.desc Function of API, no parameter. - */ - it('fileio_test_unlink_sync_001', 0, async function () { - try { - fileio.unlinkSync(1); - } - catch (err) { - console.info('fileio_test_unlink_sync_001 has failed for ' + err); - expect(err.message == "Invalid path").assertTrue(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_UnlinkSync_0200 - * @tc.name fileio_test_unlink_sync_002 - * @tc.desc Function of API, invalid parameter - */ - it('fileio_test_unlink_sync_002', 0, async function () { - let fpath = await nextFileName('fileIOTest'); - try { - fileio.unlinkSync(fpath); - } catch (err) { - console.info('fileio_test_unlink_sync_002 has failed for ' + err); - expect(err.message == "No such file or directory").assertTrue(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_WriteSync_0000 - * @tc.name fileio_test_write_sync_000 - * @tc.desc Function of API, writeSync. - */ - it('fileio_test_write_sync_000', 0, async function () { - let fpath = await nextFileName('fileio_test_write_sync_000'); - try { - let fd = fileio.openSync(fpath, 0o102, 0o666); - let res = fileio.writeSync(fd, FILE_CONTENT); - expect(typeof(res) == 'number').assertTrue(); - fileio.closeSync(fd); - fileio.unlinkSync(fpath); - } - catch (err) { - console.info('fileio_test_write_sync_000 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_WriteSync_0100 - * @tc.name fileio_test_write_sync_001 - * @tc.desc Function of API, encoding=UTF-8. - */ - it('fileio_test_write_sync_001', 0, async function () { - let fpath = await nextFileName('fileio_test_write_sync_001'); - try { - let fd = fileio.openSync(fpath, 0o102, 0o666); - let res = fileio.writeSync(fd, FILE_CONTENT, { - encoding: 'utf-8', - }); - expect(typeof(res) == 'number').assertTrue(); - fileio.closeSync(fd); - fileio.unlinkSync(fpath); - } - catch (err) { - console.info('fileio_test_write_sync_001 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_WriteSync_0200 - * @tc.name fileio_test_write_sync_002 - * @tc.desc Function of API, offset=1. - */ - it('fileio_test_write_sync_002', 0, async function () { - let fpath = await nextFileName('fileio_test_write_sync_002'); - let text = '0123456789abcdefg'; - try { - let fd = fileio.openSync(fpath, 0o102, 0o666); - expect(fileio.writeSync(fd, text, { - offset: 1, - }) == text.length - 1).assertTrue(); - fileio.closeSync(fd); - fileio.unlinkSync(fpath); - } - catch (err) { - console.info('fileio_test_write_sync_002 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_WriteSync_0300 - * @tc.name fileio_test_write_sync_003 - * @tc.desc Function of API, length = - 1. - */ - it('fileio_test_write_sync_003', 0, async function () { - let fpath = await nextFileName('fileio_test_write_sync_003'); - try { - let fd = fileio.openSync(fpath, 0o102, 0o666); - expect(fileio.writeSync(fd, FILE_CONTENT, { - length: FILE_CONTENT.length - 1, - }) == (FILE_CONTENT.length - 1)).assertTrue(); - fileio.closeSync(fd); - fileio.unlinkSync(fpath); - } - catch (err) { - console.info('fileio_test_write_sync_003 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_WriteSync_0400 - * @tc.name fileio_test_write_sync_004 - * @tc.desc Function of API, length = 1, offset = 1. - */ - it('fileio_test_write_sync_004', 0, async function () { - let fpath = await nextFileName('fileio_test_write_sync_004'); - try { - let fd = fileio.openSync(fpath, 0o102, 0o666); - let res = fileio.writeSync(fd, FILE_CONTENT, { - offset: 1, - length: 1, - }); - expect(typeof(res) == 'number').assertTrue(); - fileio.closeSync(fd); - fileio.unlinkSync(fpath); - } - catch (err) { - console.info('fileio_test_write_sync_004 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_WriteSync_0500 - * @tc.name fileio_test_write_sync_005 - * @tc.desc Function of API, invalid offset. - */ - it('fileio_test_write_sync_005', 0, async function () { - let fpath = await nextFileName('fileio_test_write_sync_005'); - const invalidOffset = 999 - let fd - try { - fd = fileio.openSync(fpath, 0o102, 0o666); - expect(fd).assertInstanceOf('Number'); - expect(fileio.writeSync(fd, FILE_CONTENT, { - offset: invalidOffset, - }) == 1).assertTrue(); - throw new Error('invalid offset'); - } - catch (err) { - console.info('fileio_test_write_sync_005 has failed for ' + err); - fileio.closeSync(fd); - fileio.unlinkSync(fpath); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_WriteSync_0600 - * @tc.name fileio_test_write_sync_006 - * @tc.desc Function of API, invalid length. - */ - it('fileio_test_write_sync_006', 0, async function () { - let fpath = await nextFileName('fileio_test_write_sync_006'); - const invalidLength = 999 - let fd - try { - fd = fileio.openSync(fpath, 0o102, 0o666); - expect(fd).assertInstanceOf('Number'); - expect(fileio.writeSync(fd, FILE_CONTENT, { - length: invalidLength, - }) == 1); - throw new Error('invalid length'); - } - catch (err) { - console.info('fileio_test_write_sync_006 has failed for ' + err); - fileio.closeSync(fd); - fileio.unlinkSync(fpath); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_WriteSync_0700 - * @tc.name fileio_test_write_sync_007 - * @tc.desc Function of API, no parameter. - */ - it('fileio_test_write_sync_007', 0, async function () { - try { - fileio.writeSync(1, 1); - }catch (err) { - console.info('fileio_test_write_sync_007 has failed for ' + err); - expect(err.message == "Illegal write buffer or encoding").assertTrue(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_WriteSync_0800 - * @tc.name fileio_test_write_sync_008 - * @tc.desc Function of API, invalid parameter. - */ - it('fileio_test_write_sync_008', 0, async function () { - try { - fileio.writeSync(-1, FILE_CONTENT); - expect(false).assertTrue(); - } - catch (err) { - console.info('fileio_test_write_sync_008 has failed for ' + err); - expect(err.message == "Invalid fd").assertTrue(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_WriteSync_0900 - * @tc.name fileio_test_write_sync_009 - * @tc.desc Function of API, Set all parameters. - */ - it('fileio_test_write_sync_009', 0, async function () { - let fpath = await nextFileName('fileio_test_write_sync_009'); - try { - let fd = fileio.openSync(fpath, 0o102, 0o666); - let res = fileio.writeSync(fd, FILE_CONTENT, { - encoding: 'utf-8', - position: 0, - offset: 1, - length: 1, - }); - expect(typeof(res) == 'number').assertTrue(); - fileio.closeSync(fd); - fileio.unlinkSync(fpath); - } - catch (err) { - console.info('fileio_test_write_sync_009 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_WriteSync_1000 - * @tc.name fileio_test_write_sync_010 - * @tc.desc Function of API, encoding=gb2312. - */ - it('fileio_test_write_sync_010', 0, async function () { - let fpath = await nextFileName('fileio_test_write_sync_010'); - let fd = fileio.openSync(fpath, 0o102, 0o666); - try { - fileio.writeSync(fd, FILE_CONTENT, { - encoding: 'gb2312', - }); - }catch (err) { - console.info('fileio_test_write_sync_010 has failed for ' + err); - expect(err.message == "Illegal write buffer or encoding").assertTrue(); - fileio.closeSync(fd); - fileio.unlinkSync(fpath); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_ReadSync_0100 - * @tc.name fileio_test_read_sync_001 - * @tc.desc Function of API, offset = 1. - */ - it('fileio_test_read_sync_001', 0, async function () { - let bufLen = 5 - expect(FILE_CONTENT.length > bufLen).assertTrue(); - let fpath = await nextFileName('fileio_test_read_sync_001'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let fd = fileio.openSync(fpath, 0o2); - let len = fileio.readSync(fd, new ArrayBuffer(bufLen), { - offset: 1, - }); - expect(len == bufLen - 1).assertTrue(); - fileio.closeSync(fd); - fileio.unlinkSync(fpath); - } - catch (err) { - console.info('fileio_test_read_sync_001 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_ReadSync_0200 - * @tc.name fileio_test_read_sync_002 - * @tc.desc Function of API, length = 1. - */ - it('fileio_test_read_sync_002', 0, async function () { - let fpath = await nextFileName('fileio_test_read_sync_002'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let fd = fileio.openSync(fpath, 0o2); - let len = fileio.readSync(fd, new ArrayBuffer(4096), { - length: 1, - }); - expect(len == 1).assertTrue(); - fileio.closeSync(fd); - fileio.unlinkSync(fpath); - } - catch (err) { - console.info('fileio_test_read_sync_002 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_ReadSync_0300 - * @tc.name fileio_test_read_sync_003 - * @tc.desc Function of API, invalid offset - */ - it('fileio_test_read_sync_003', 0, async function () { - let fd - const invalidOffset = 99999 - let fpath = await nextFileName('fileio_test_read_sync_003'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - fd = fileio.openSync(fpath, 0o2); - fileio.readSync(fd, new ArrayBuffer(4096), { - offset: invalidOffset, - }); - }catch (err) { - fileio.closeSync(fd); - fileio.unlinkSync(fpath); - console.info('fileio_test_read_sync_003 has failed for ' + err); - expect(err.message == "Invalid option.offset, buffer limit exceeded").assertTrue(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_ReadSync_0300 - * @tc.name fileio_test_read_sync_004 - * @tc.desc Function of API, invalid length. - */ - it('fileio_test_read_sync_004', 0, async function () { - let fd - const invalidLength = 9999 - let fpath = await nextFileName('fileio_test_read_sync_004'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - fd = fileio.openSync(fpath, 0o2); - fileio.readSync(fd, new ArrayBuffer(4096), { - length: invalidLength, - }); - }catch (err) { - fileio.closeSync(fd); - fileio.unlinkSync(fpath); - console.info('fileio_test_read_sync_004 has failed for ' + err); - expect(err.message == "Invalid option.length").assertTrue(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_ReadSync_0500 - * @tc.name fileio_test_read_sync_005 - * @tc.desc Function of API, fpatch = -1. - */ - it('fileio_test_read_sync_005', 0, async function () { - try { - fileio.readSync(-1, new ArrayBuffer(4096)); - } - catch (err) { - console.info('fileio_test_read_sync_005 has failed for ' + err); - expect(err.message == "Invalid fd").assertTrue(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_ReadSync_0600 - * @tc.name fileio_test_read_sync_006 - * @tc.desc Function of API, offset & length & position = 1. - */ - it('fileio_test_read_sync_006', 0, async function () { - let fpath = await nextFileName('fileio_test_read_sync_006'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let fd = fileio.openSync(fpath, 0o2); - let len = fileio.readSync(fd, new ArrayBuffer(4096), { - position: 1, - }); - expect(len == FILE_CONTENT.length - 1); - fileio.closeSync(fd); - fileio.unlinkSync(fpath); - } - catch (err) { - console.info('fileio_test_read_sync_006 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_ReadSync_0700 - * @tc.name fileio_test_read_sync_007 - * @tc.desc Function of API, invalid position. - */ - it('fileio_test_read_sync_007', 0, async function () { - let fpath = await nextFileName('fileio_test_read_sync_007'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let fd = fileio.openSync(fpath, 0o2); - let invalidPos = FILE_CONTENT.length; - let len = fileio.readSync(fd, new ArrayBuffer(4096), { - position: invalidPos, - }); - fileio.closeSync(fd); - fileio.unlinkSync(fpath); - } - catch (err) { - console.info('fileio_test_read_sync_007 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_ReadSync_0800 - * @tc.name fileio_test_read_sync_008 - * @tc.desc Function of API, Enter all parameters correctly. - */ - it('fileio_test_read_sync_008', 0, async function () { - let fpath = await nextFileName('fileio_test_read_sync_008'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let fd = fileio.openSync(fpath, 0o2); - let len = fileio.readSync(fd, new ArrayBuffer(4096), { - position: 1, - offset: 1, - length: 1, - }); - expect(len == 1).assertTrue(); - fileio.closeSync(fd); - fileio.unlinkSync(fpath); - } - catch (err) { - console.info('fileio_test_read_sync_008 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_ReadSync_0900 - * @tc.name fileio_test_read_sync_009 - * @tc.desc Function of API, Set offset and length. - */ - it('fileio_test_read_sync_009', 0, async function () { - let fpath = await nextFileName('fileio_test_read_sync_009'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let fd = fileio.openSync(fpath, 0o2); - let len = fileio.readSync(fd, new ArrayBuffer(4096), { - offset: 1, - length: 1, - }); - expect(len == 1).assertTrue(); - fileio.closeSync(fd); - fileio.unlinkSync(fpath); - } - catch (err) { - console.info('fileio_test_read_sync_009 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_ReadSync_1000 - * @tc.name fileio_test_read_sync_010 - * @tc.desc Function of API, Set error parameters (options). - */ - it('fileio_test_read_sync_010', 0, async function () { - let fpath = await nextFileName('fileio_test_read_sync_010'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - let fd; - try { - fd = fileio.openSync(fpath, 0o2); - fileio.readSync(fd, new ArrayBuffer(4096), { - offset: -1, - length: 1, - }); - }catch (err) { - console.info('fileio_test_read_sync_010 has failed for ' + err); - expect(err.message == "Invalid option.offset, positive integer is desired").assertTrue(); - fileio.closeSync(fd); - fileio.unlinkSync(fpath); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_ChmodSync_0000 - * @tc.name fileio_test_chmod_sync_000 - * @tc.desc Function of API, mode=0o660 - */ - it('fileio_test_chmod_sync_000', 0, async function () { - let fpath = await nextFileName('fileio_test_chmod_sync_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - expect(fileio.chmodSync(fpath, 0o660) !== null).assertTrue(); - expect((fileio.statSync(fpath).mode & 0o777) == 0o660).assertTrue(); - fileio.unlinkSync(fpath); - } - catch (err) { - console.info('fileio_test_chmod_sync_000 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_ChmodSync_0100 - * @tc.name fileio_test_chmod_sync_001 - * @tc.desc Function of API, mode=0o460 - */ - it('fileio_test_chmod_sync_001', 0, async function () { - let fpath = await nextFileName('fileio_test_chmod_sync_001'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - expect(fileio.chmodSync(fpath, 0o460) !== null).assertTrue(); - expect((fileio.statSync(fpath).mode & 0o777) == 0o460).assertTrue(); - fileio.unlinkSync(fpath); - } - catch (err) { - console.info('fileio_test_chmod_sync_001 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_ChmodSync_0200 - * @tc.name fileio_test_chmod_sync_002 - * @tc.desc Function of API, mode=0o260. The test file is exist. - */ - it('fileio_test_chmod_sync_002', 0, async function () { - let fpath = await nextFileName('fileio_test_chmod_sync_002'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - expect(fileio.chmodSync(fpath, 0o260) !== null).assertTrue(); - expect((fileio.statSync(fpath).mode & 0o777) == 0o260).assertTrue(); - fileio.unlinkSync(fpath); - } - catch (err) { - console.info('fileio_test_chmod_sync_002 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_ChmodSync_0300 - * @tc.name fileio_test_chmod_sync_003 - * @tc.desc Function of API, chmodSync. The test file is not exist. - */ - it('fileio_test_chmod_sync_003', 0, async function () { - let fpath = await nextFileName('fileio_test_chmod_sync_003'); - try { - fileio.chmodSync(fpath, 0o260); - }catch (err) { - console.info('fileio_test_chmod_sync_003 has failed for ' + err); - expect(err.message == "No such file or directory").assertTrue(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_ChmodSync_0400 - * @tc.name fileio_test_chmod_sync_004 - * @tc.desc Function of API, fpatch=dir address. The test dir is exist. - */ - it('fileio_test_chmod_sync_004', 0, async function () { - let dpath = await nextFileName('fileio_test_chmod_sync_004'); - try { - fileio.mkdirSync(dpath, 0o777); - expect(fileio.chmodSync(dpath, 0o660) !== null).assertTrue(); - expect((fileio.statSync(dpath).mode & 0o777) == 0o660).assertTrue(); - fileio.rmdirSync(dpath); - } - catch (err) { - console.info('fileio_test_chmod_sync_000 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_ChmodSync_0500 - * @tc.name fileio_test_chmod_sync_005 - * @tc.desc Function of API, fpatch=dir address. The test dir is not exist. - */ - it('fileio_test_chmod_sync_005', 0, async function () { - let dpath; - try { - fileio.chmodSync(dpath, 0o660); - } catch (err) { - console.info('fileio_test_chmod_sync_005 has failed for ' + err); - expect(err.message == "Invalid path").assertTrue(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_ChmodSync_0600 - * @tc.name fileio_test_chmod_sync_006 - * @tc.desc Function of API, mode=0o700. The test file is exist. - */ - it('fileio_test_chmod_sync_006', 0, async function () { - let fpath = await nextFileName('fileio_test_chmod_sync_006'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - expect(fileio.chmodSync(fpath, 0o700) !== null).assertTrue(); - expect((fileio.statSync(fpath).mode & 0o777) == 0o700).assertTrue(); - fileio.unlinkSync(fpath); - } - catch (err) { - console.info('fileio_test_chmod_sync_006 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_ChmodSync_0700 - * @tc.name fileio_test_chmod_sync_007 - * @tc.desc Function of API, mode=0o400. The test file is exist. - */ - it('fileio_test_chmod_sync_007', 0, async function () { - let fpath = await nextFileName('fileio_test_chmod_sync_007'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - expect(fileio.chmodSync(fpath, 0o400) !== null).assertTrue(); - expect((fileio.statSync(fpath).mode & 0o777) == 0o400).assertTrue(); - fileio.unlinkSync(fpath); - } - catch (err) { - console.info('fileio_test_chmod_sync_002 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_ChmodSync_0800 - * @tc.name fileio_test_chmod_sync_008 - * @tc.desc Function of API, mode=0o200. The test file is exist. - */ - it('fileio_test_chmod_sync_008', 0, async function () { - let fpath = await nextFileName('fileio_test_chmod_sync_008'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - expect(fileio.chmodSync(fpath, 0o200) !== null).assertTrue(); - expect((fileio.statSync(fpath).mode & 0o777) == 0o200).assertTrue(); - fileio.unlinkSync(fpath); - } - catch (err) { - console.info('fileio_test_chmod_sync_008 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_ChmodSync_0900 - * @tc.name fileio_test_chmod_sync_009 - * @tc.desc Function of API, mode=0o100. The test file is exist. - */ - it('fileio_test_chmod_sync_009', 0, async function () { - let fpath = await nextFileName('fileio_test_chmod_sync_009'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - expect(fileio.chmodSync(fpath, 0o100) !== null).assertTrue(); - expect((fileio.statSync(fpath).mode & 0o777) == 0o100).assertTrue(); - fileio.unlinkSync(fpath); - } - catch (err) { - console.info('fileio_test_chmod_sync_009 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_ChmodSync_0100 - * @tc.name fileio_test_chmod_sync_010 - * @tc.desc Function of API, mode=0o070. The test file is exist. - */ - it('fileio_test_chmod_sync_010', 0, async function () { - let fpath = await nextFileName('fileio_test_chmod_sync_010'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - expect(fileio.chmodSync(fpath, 0o070) !== null).assertTrue(); - expect((fileio.statSync(fpath).mode & 0o777) == 0o070).assertTrue(); - fileio.unlinkSync(fpath); - } - catch (err) { - console.info('fileio_test_chmod_sync_010 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_ChmodSync_0110 - * @tc.name fileio_test_chmod_sync_011 - * @tc.desc Function of API, mode=0o040. The test file is exist. - */ - it('fileio_test_chmod_sync_011', 0, async function () { - let fpath = await nextFileName('fileio_test_chmod_sync_011'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - expect(fileio.chmodSync(fpath, 0o040) !== null).assertTrue(); - expect((fileio.statSync(fpath).mode & 0o777) == 0o040).assertTrue(); - fileio.unlinkSync(fpath); - } - catch (err) { - console.info('fileio_test_chmod_sync_011 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_ChmodSync_0120 - * @tc.name fileio_test_chmod_sync_012 - * @tc.desc Function of API, mode=0o020. The test file is exist. - */ - it('fileio_test_chmod_sync_012', 0, async function () { - let fpath = await nextFileName('fileio_test_chmod_sync_012'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - expect(fileio.chmodSync(fpath, 0o020) !== null).assertTrue(); - expect((fileio.statSync(fpath).mode & 0o777) == 0o020).assertTrue(); - fileio.unlinkSync(fpath); - } - catch (err) { - console.info('fileio_test_chmod_sync_012 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_ChmodSync_0130 - * @tc.name fileio_test_chmod_sync_013 - * @tc.desc Function of API, mode=0o010. The test file is exist. - */ - it('fileio_test_chmod_sync_013', 0, async function () { - let fpath = await nextFileName('fileio_test_chmod_sync_013'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - expect(fileio.chmodSync(fpath, 0o010) !== null).assertTrue(); - expect((fileio.statSync(fpath).mode & 0o777) == 0o010).assertTrue(); - fileio.unlinkSync(fpath); - } - catch (err) { - console.info('fileio_test_chmod_sync_013 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_ChmodSync_0140 - * @tc.name fileio_test_chmod_sync_014 - * @tc.desc Function of API, mode=0o007. The test file is exist. - */ - it('fileio_test_chmod_sync_014', 0, async function () { - let fpath = await nextFileName('fileio_test_chmod_sync_014'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - expect(fileio.chmodSync(fpath, 0o007) !== null).assertTrue(); - expect((fileio.statSync(fpath).mode & 0o777) == 0o007).assertTrue(); - fileio.unlinkSync(fpath); - } - catch (err) { - console.info('fileio_test_chmod_sync_014 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_ChmodSync_0150 - * @tc.name fileio_test_chmod_sync_015 - * @tc.desc Function of API, mode=0o700. The test file is exist. - */ - it('fileio_test_chmod_sync_015', 0, async function () { - let fpath = await nextFileName('fileio_test_chmod_sync_015'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - expect(fileio.chmodSync(fpath, 0o004) !== null).assertTrue(); - expect((fileio.statSync(fpath).mode & 0o777) == 0o004).assertTrue(); - fileio.unlinkSync(fpath); - } - catch (err) { - console.info('fileio_test_chmod_sync_015 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_ChmodSync_0160 - * @tc.name fileio_test_chmod_sync_016 - * @tc.desc Function of API, mode=0o002. The test file is exist. - */ - it('fileio_test_chmod_sync_016', 0, async function () { - let fpath = await nextFileName('fileio_test_chmod_sync_016'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - expect(fileio.chmodSync(fpath, 0o002) !== null).assertTrue(); - expect((fileio.statSync(fpath).mode & 0o777) == 0o002).assertTrue(); - fileio.unlinkSync(fpath); - } - catch (err) { - console.info('fileio_test_chmod_sync_016 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_ChmodSync_0170 - * @tc.name fileio_test_chmod_sync_017 - * @tc.desc Function of API, mode=0o001. The test file is exist. - */ - it('fileio_test_chmod_sync_017', 0, async function () { - let fpath = await nextFileName('fileio_test_chmod_sync_017'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - expect(fileio.chmodSync(fpath, 0o001) !== null).assertTrue(); - expect((fileio.statSync(fpath).mode & 0o777) == 0o001).assertTrue(); - fileio.unlinkSync(fpath); - } - catch (err) { - console.info('fileio_test_chmod_sync_017 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_copyFileSync_0000 - * @tc.name fileio_test_copy_file_sync_000 - * @tc.desc Function of API, copy. fpatch is vaild, fpathTarget is vaild, same path, file not same. - */ - it('fileio_test_copy_file_sync_000', 0, async function () { - let fpath = await nextFileName('fileio_test_copy_file_sync_000'); - let fpathTarget = fpath + 'tgt' - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - fileio.copyFileSync(fpath, fpathTarget); - fileio.unlinkSync(fpath); - fileio.unlinkSync(fpathTarget); - } - catch (err) { - console.info('fileio_test_copy_file_sync_000 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_copyFileSync_0100 - * @tc.name fileio_test_copy_file_sync_001 - * @tc.desc Function of API, copy. fpatch is invalid, fpathTarget is vaild, same path, file not same. - */ - it('fileio_test_copy_file_sync_001', 0, async function () { - let fpath = await nextFileName('fileio_test_copy_file_sync_001') + 'd' - let fpathTarget = fpath + 'tgt' - try { - fileio.copyFileSync(fpath, fpathTarget); - }catch (err) { - console.info('fileio_test_copy_file_sync_001 has failed for ' + err); - expect(err.message == "No such file or directory").assertTrue(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_copyFileSync_0200 - * @tc.name fileio_test_copy_file_sync_002 - * @tc.desc Function of API, copyFileSync. fpath is vaild, fpathTarget is invalid. - */ - it('fileio_test_copy_file_sync_002', 0, async function () { - let fpath = await nextFileName('fileio_test_copy_file_sync_002'); - try { - fileio.copyFileSync(fpath, 0); - } - catch (err) { - console.info('fileio_test_copy_file_sync_002 has failed for ' + err); - expect(err.message == "The first/second argument requires filepath/fd").assertTrue(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_copyFileSync_0300 - * @tc.name fileio_test_copy_file_sync_003 - * @tc.desc Function of API, copy. fpatch is vaild, fpathTarget is vaild, path not same, file not same. - */ - it('fileio_test_copy_file_sync_003', 0, async function () { - let fpath = await nextFileName('fileio_test_copy_file_sync_003'); - let fpathTarget = fpath + 'f1' - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - fileio.copyFileSync(fpath, fpathTarget); - fileio.unlinkSync(fpath); - fileio.unlinkSync(fpathTarget); - } - catch (err) { - console.info('fileio_test_copy_file_sync_003 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_copyFileSync_0400 - * @tc.name fileio_test_copy_file_sync_004 - * @tc.desc Function of API, copy. fpatch is vaild, fpathTarget is vaild, path not same, file not same. - */ - it('fileio_test_copy_file_sync_004', 0, async function () { - let fpath = await nextFileName('fileio_test_copy_file_sync_004'); - let fpathTarget = await fileName('fileio_test_copy_file_sync_004'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - fileio.copyFileSync(fpath, fpathTarget); - fileio.unlinkSync(fpath); - fileio.unlinkSync(fpathTarget); - } - catch (err) { - console.info('fileio_test_copy_file_sync_004 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_copyFileSync_0500 - * @tc.name fileio_test_copy_file_sync_005 - * @tc.desc Function of API, copy. fpatch is vaild, fpathTarget is vaild, path not same, file not same. - */ - it('fileio_test_copy_file_sync_005', 0, async function () { - let fpath = await nextFileName('fileio_test_copy_file_sync_005'); - let fpathTarget = fpath - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - fileio.copyFileSync(fpath, fpathTarget); - fileio.unlinkSync(fpath); - } - catch (err) { - console.info('fileio_test_copy_file_sync_005 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_copyFileSync_0600 - * @tc.name fileio_test_copy_file_sync_006 - * @tc.desc Function of API, copy.When missing parameters. - */ - it('fileio_test_copy_file_sync_006', 0, async function () { - let fpath = await nextFileName('fileio_test_copy_file_sync_006'); - try { - fileio.copyFileSync(fpath); - }catch (err) { - console.info('fileio_test_copy_file_sync_006 has failed for ' + err); - expect(err.message == "Number of arguments unmatched").assertTrue(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_copyFileSync_0700 - * @tc.name fileio_test_copy_file_sync_007 - * @tc.desc Function of API, copy. fpatch is invalid, fpathTarget is invalid. - */ - it('fileio_test_copy_file_sync_007', 0, async function () { - try { - fileio.copyFileSync(-1, -1); - } catch (err) { - console.info('fileio_test_copy_file_sync_007 has failed for ' + err); - expect(err.message == "The first/second argument requires filepath/fd").assertTrue(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_copyFileSync_0800 - * @tc.name fileio_test_copy_file_sync_008 - * @tc.desc Function of API, parameter more than 4096. - */ - it('fileio_test_copy_file_sync_008', 0, async function () { - let fpath = await nextFileName('fileio_test_copy_file_sync_008'); - fileio.openSync(fpath, 0o102, 0o777); - let dpath = await nextFileName('fileio_test_copy_file_sync_008') + 'd'; - fileio.mkdirSync(dpath); - try { - for (let i = 0; i < 16; i++) { - if (i == 15) { - let fpathTarget = dpath + '/f' + i; - fileio.copyFileSync(fpath, fpathTarget); - fileio.unlinkSync(fpath); - fileio.unlinkSync(fpathTarget); - } else { - dpath = dpath + '/d' + i; - fileio.mkdirSync(dpath); - } - } - throw new Error('parameter more than 4096'); - } - catch (err) { - console.info('fileio_test_copy_file_sync_008 has failed for ' + err); - forceRemoveDir(dpath, 15); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_copyFileSync_0900 - * @tc.name fileio_test_copy_file_sync_009 - * @tc.desc Function of API, filename is too long. - */ - it('fileio_test_copy_file_sync_009', 0, async function () { - let fpath = await nextFileName('fileio_test_copy_file_sync_009'); - fileio.openSync(fpath, 0o102, 0o777); - let fpathTarget = await nextFileName(randomString(256)); - try { - fileio.copyFileSync(fpath, fpathTarget); - } - catch (err) { - fileio.unlinkSync(fpath); - console.info('fileio_test_copy_file_sync_009 has failed for ' + err); - expect(err.message == 'Filename too long').assertTrue(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_copyFileSync_1000 - * @tc.name fileio_test_copy_file_sync_010 - * @tc.desc Function of API, dir layers too long - */ - it('fileio_test_copy_file_sync_010', 0, async function () { - let fpath = await nextFileName('fileio_test_copy_file_sync_010'); - fileio.openSync(fpath, 0o102, 0o777); - let dpath = await nextFileName('fileio_test_copy_file_sync_010') + 'd'; - fileio.mkdirSync(dpath); - try { - for (let i = 0; i < 113; i++) { - if (i == 112) { - let fpathTarget = dpath + '/f' + i - fileio.copyFileSync(fpath, fpathTarget); - fileio.unlinkSync(fpath); - fileio.unlinkSync(fpathTarget); - } else { - dpath = dpath + '/d' + i - fileio.mkdirSync(dpath); - } - } - throw new Error('dir layers too long'); - } - catch (err) { - console.info('fileio_test_copy_file_sync_010 has failed for ' + err); - forceRemoveDir(dpath, 112); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_copyFileSync_1100 - * @tc.name fileio_test_copy_file_sync_011 - * @tc.desc Function of API, special parameter. - */ - it('fileio_test_copy_file_sync_011', 0, async function () { - let fpath = await nextFileName('fileio_test_copy_file_sync_011'); - fileio.openSync(fpath, 0o102, 0o777); - let fpathTarget = await nextFileName('?*:<>/|'); - try { - fileio.copyFileSync(fpath, fpathTarget); - } - catch (err) { - fileio.unlinkSync(fpath); - console.info('fileio_test_copy_file_sync_011 has failed for ' + err); - expect(err.message == "No such file or directory").assertTrue(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_copyFileSync_1200 - * @tc.name fileio_test_copy_file_sync_012 - * @tc.desc Function of API, copy. fpatch is vaild, fpathTarget is vaild, same path, file not same, mode is 0. - */ - it('fileio_test_copy_file_sync_012', 0, async function () { - let fpath = await nextFileName('fileio_test_copy_file_sync_012'); - let fpathTarget = fpath + 'tgt' - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - fileio.copyFileSync(fpath, fpathTarget, 0); - fileio.unlinkSync(fpath); - fileio.unlinkSync(fpathTarget); - } - catch (err) { - console.info('fileio_test_copy_file_sync_012 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_copyFileSync_1200 - * @tc.name fileio_test_copy_file_async_001 - * @tc.desc Function of API, copy. fpatch is vaild, fpathTarget is vaild, same path, file not same, mode is 0. - */ - it('fileio_test_copy_file_async_001', 0, async function () { - let fpath = await nextFileName('fileio_test_copy_file_async_001'); - let fpathTarget = fpath + 'tgt' - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - await fileio.copyFile(fpath, fpathTarget).then(()=> { - fileio.unlinkSync(fpath); - expect(fileio.unlinkSync(fpathTarget) !== null).assertTrue(); - console.info('fileio_test_copy_file_async_001 Success'); - }).catch((err) => { - console.info("fileio_test_copy_file_async_001 err: " + JSON.stringify(err)); - }); - }); - - /** - * @tc.number SUB_STORAGE_FileIO_truncateSync_0000 - * @tc.name fileio_test_truncate_sync_000 - * @tc.desc Function of API, truncateSync. - */ - it('fileio_test_truncate_sync_000', 0, async function () { - let fpath = await nextFileName('fileio_test_truncate_sync_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - expect(fileio.truncateSync(fpath, 10) !== null).assertTrue(); - expect(fileio.statSync(fpath).size == 10).assertTrue(); - fileio.unlinkSync(fpath); - } - catch (err) { - console.info('fileio_test_truncate_sync_000 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_truncateSync_0100 - * @tc.name fileio_test_truncate_sync_001 - * @tc.desc Function of API, no value for parameter. - */ - it('fileio_test_truncate_sync_001', 0, async function () { - try { - fileio.truncateSync(); - }catch (err) { - console.info('fileio_test_truncate_sync_001 has failed for ' + err); - expect(err.message == "Number of arguments unmatched").assertTrue(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_truncateSync_0200 - * @tc.name fileio_test_truncate_sync_002 - * @tc.desc Function of API, no invalid parameter. - */ - it('fileio_test_truncate_sync_002', 0, async function () { - let fpath = await nextFileName('fileio_test_truncate_sync_001'); - try { - fileio.truncateSync(fpath); - }catch (err) { - console.info('fileio_test_truncate_sync_002 has failed for ' + err); - expect(err.message == "No such file or directory").assertTrue(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_truncateSync_0300 - * @tc.name fileio_test_truncate_sync_003 - * @tc.desc Function of API, . - */ - it('fileio_test_truncate_sync_003', 0, async function () { - let fpath = await nextFileName('fileio_test_truncate_sync_003'); - try { - fileio.truncateSync(fpath, -1); - }catch (err) { - console.info('fileio_test_truncate_sync_003 has failed for ' + err); - expect(err.message == "Invalid argument").assertTrue(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_RenameSync_0000 - * @tc.name fileio_test_rename_sync_000 - * @tc.desc Function of API, renameSync. The test file is exist, - * fpathTarget is not same with fpatch, file name are same. - */ - it('fileio_test_rename_sync_000', 0, async function () { - let fpath = await nextFileName('fileio_test_rename_sync_000'); - let fpathTarget = fpath + 'tgt' - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - fileio.renameSync(fpath, fpathTarget); - fileio.accessSync(fpathTarget); - fileio.unlinkSync(fpathTarget); - } - catch (err) { - console.info('fileio_test_rename_sync_000 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_RenameSync_0100 - * @tc.name fileio_test_rename_sync_001 - * @tc.desc Function of API, renameSync. The test file is not exist, - * fpathTarget is not same with fpatch, file name are same. - */ - it('fileio_test_rename_sync_001', 0, async function () { - let fpath = await nextFileName('fileio_test_rename_sync_001'); - let fpathTarget = fpath + 'tgt' - try { - fileio.renameSync(fpath, fpathTarget); - }catch (err) { - console.info('fileio_test_rename_sync_001 has failed for ' + err); - expect(err.message == "No such file or directory").assertTrue(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_RenameSync_0200 - * @tc.name fileio_test_rename_sync_002 - * @tc.desc Function of API, renameSync. The test file is exist, fpathTarget is invalid. - */ - it('fileio_test_rename_sync_002', 0, async function () { - let fpath = await nextFileName('fileio_test_rename_sync_002'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - fileio.renameSync(fpath, '/'); - }catch (err) { - fileio.unlinkSync(fpath); - console.info('fileio_test_rename_sync_002 has failed for ' + err); - expect(err.message == "Cross-device link").assertTrue(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_RenameSync_0300 - * @tc.name fileio_test_rename_sync_003 - * @tc.desc Function of API, renameSync. - * The test file is not exist, fpathTarget is same with fpatch, file name are same. - */ - it('fileio_test_rename_sync_003', 0, async function () { - let fpath = await nextFileName('fileio_test_rename_sync_003'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - console.info('fileio_test_rename_sync_003 Test start'); - fileio.renameSync(fpath, fpath); - fileio.unlinkSync(fpath); - } - catch (err) { - console.info('fileio_test_rename_sync_003 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_RenameSync_0400 - * @tc.name fileio_test_rename_sync_004 - * @tc.desc Function of API, no fpath parameter. - */ - it('fileio_test_rename_sync_004', 0, async function () { - try { - fileio.renameSync(1, 1); - } - catch (err) { - console.info('fileio_test_rename_sync_004 has failed for ' + err); - expect(err.message == "Invalid src").assertTrue(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_RenameSync_0500 - * @tc.name fileio_test_rename_sync_005 - * @tc.desc Function of API, no fpathTarget parameter. - */ - it('fileio_test_rename_sync_005', 0, async function () { - let fpath = await nextFileName('fileio_test_rename_sync_005'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - fileio.renameSync(fpath, 1); - } - catch (err) { - fileio.unlinkSync(fpath); - console.info('fileio_test_rename_sync_005 has failed for ' + err); - expect(err.message == "Invalid dest").assertTrue(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_RenameSync_0600 - * @tc.name fileio_test_rename_sync_006 - * @tc.desc Function of API, rename dir. - */ - it('fileio_test_rename_sync_006', 0, async function () { - let dpath = await nextFileName('fileio_test_rename_sync_006') + 'd' - let dpathTarget = await nextFileName('fileio_test_rename_sync_006-1') + 'd' - try { - fileio.mkdirSync(dpath); - fileio.renameSync(dpath, dpathTarget); - fileio.accessSync(dpathTarget); - fileio.rmdirSync(dpathTarget); - } - catch (err) { - console.info('fileio_test_rename_sync_006 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_RenameSync_0700 - * @tc.name fileio_test_rename_sync_007 - * @tc.desc Function of API, dir not exist. The test dir is not exist. - */ - it('fileio_test_rename_sync_007', 0, async function () { - let dpath = await nextFileName('fileio_test_rename_sync_007') + 'd' - let dpathTarget = await nextFileName('fileio_test_rename_sync_007-1') + 'd' - try { - fileio.renameSync(dpath, dpathTarget); - }catch (err) { - console.info('fileio_test_rename_sync_007 has failed for ' + err); - expect(err.message == "No such file or directory").assertTrue(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_RenameSync_0800 - * @tc.name fileio_test_rename_sync_008 - * @tc.desc Function of API, fpathTarget not exist. fpathTarget not exist. - */ - it('fileio_test_rename_sync_008', 0, async function () { - let dpath = await nextFileName('fileio_test_rename_sync_008') + 'd' - let dpathTarget = '/data/accounts/account_0/appdata/aaa/bbb/fileio_test_rename_sync_008-1d' - try { - fileio.mkdirSync(dpath); - fileio.renameSync(dpath, dpathTarget); - }catch (err) { - fileio.rmdirSync(dpath); - console.info('fileio_test_rename_sync_008 has failed for ' + err); - expect(err.message == "No such file or directory").assertTrue(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_RenameSync_0900 - * @tc.name fileio_test_rename_sync_009 - * @tc.desc Function of API, fpath is same with fpathTarget. fpath is same with fpathTarget. - */ - it('fileio_test_rename_sync_009', 0, async function () { - let dpath = await nextFileName('fileio_test_rename_sync_009') + 'd' - try { - fileio.mkdirSync(dpath); - fileio.renameSync(dpath, dpath); - fileio.accessSync(dpath); - fileio.rmdirSync(dpath); - } - catch (err) { - console.info('fileio_test_rename_sync_009 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_FchmodSync_0000 - * @tc.name fileio_test_fchmod_sync_000 - * @tc.desc Function of API, fchmodSync(mode=0o660). The test file is exist. - */ - it('fileio_test_fchmod_sync_000', 0, async function () { - let fpath = await nextFileName('fileio_test_fchmod_sync_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let fd = fileio.openSync(fpath); - fileio.fchmodSync(fd, 0o660); - expect((fileio.statSync(fpath).mode & 0o777) == 0o660).assertTrue(); - fileio.unlinkSync(fpath); - } - catch (err) { - console.info('fileio_test_fchmod_sync_000 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_FchmodSync_0100 - * @tc.name fileio_test_fchmod_sync_001 - * @tc.desc Function of API, fchmodSync(mode=0o460). The test file is exist. - */ - it('fileio_test_fchmod_sync_001', 0, async function () { - let fpath = await nextFileName('fileio_test_fchmod_sync_001'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let fd = fileio.openSync(fpath); - fileio.fchmodSync(fd, 0o460); - expect((fileio.statSync(fpath).mode & 0o777) == 0o460).assertTrue(); - fileio.unlinkSync(fpath); - } - catch (err) { - console.info('fileio_test_fchmod_sync_001 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_FchmodSync_0200 - * @tc.name fileio_test_fchmod_sync_002 - * @tc.desc Function of API, fchmodSync(mode=0o260). The test file is exist. - */ - it('fileio_test_fchmod_sync_002', 0, async function () { - let fpath = await nextFileName('fileio_test_fchmod_sync_002'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let fd = fileio.openSync(fpath); - fileio.fchmodSync(fd, 0o260); - expect((fileio.statSync(fpath).mode & 0o777) == 0o260).assertTrue(); - fileio.unlinkSync(fpath); - } - catch (err) { - console.info('fileio_test_fchmod_sync_002 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_FchmodSync_0300 - * @tc.name fileio_test_fchmod_sync_003 - * @tc.desc Function of API, file not exist. The test file is not exist. - */ - it('fileio_test_fchmod_sync_003', 0, async function () { - let fpath = await nextFileName('fileio_test_fchmod_sync_003'); - try { - fileio.fchmodSync(fpath, 0o660); - }catch (err) { - console.info('fileio_test_fchmod_sync_003 has failed for ' + err); - expect(err.message == "Invalid fd").assertTrue(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_FchmodSync_0400 - * @tc.name fileio_test_fchmod_sync_004 - * @tc.desc Function of API, mode is invalid. The test file is exist. - */ - it('fileio_test_fchmod_sync_004', 0, async function () { - let fpath = await nextFileName('fileio_test_fchmod_sync_004'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let fd = fileio.openSync(fpath); - fileio.fchmodSync(fd, 2222222222222); - fileio.unlinkSync(fpath); - } - catch (err) { - console.info('fileio_test_fchmod_sync_004 has failed for A' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_FchmodSync_0500 - * @tc.name fileio_test_fchmod_sync_005 - * @tc.desc Function of API, fpath = dir. The test dir is exist. - */ - it('fileio_test_fchmod_sync_005', 0, async function () { - let dpath = await nextFileName('fileio_test_fchmod_sync_005') + 'd' - try { - fileio.mkdirSync(dpath, 0o777); - let fd = fileio.openSync(dpath); - console.info(fd); - fileio.fchmodSync(fd, 0o660); - fileio.rmdirSync(dpath); - } - catch (err) { - console.info('fileio_test_fchmod_sync_005 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_FchmodSync_0600 - * @tc.name fileio_test_fchmod_sync_006 - * @tc.desc Function of API, fpatch = dir. The test dir is not exist. - */ - it('fileio_test_fchmod_sync_006', 0, async function () { - let dpath; - try { - fileio.fchmodSync(dpath, 0o660); - } - catch (err) { - console.info('fileio_test_fchmod_sync_006 has failed for ' + err); - expect(err.message == "Invalid fd").assertTrue(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_FchmodSync_0700 - * @tc.name fileio_test_fchmod_sync_007 - * @tc.desc Function of API, fchmodSync(mode=0o460). The test file is exist. - */ - it('fileio_test_fchmod_sync_007', 0, async function () { - let fpath = await nextFileName('fileio_test_fchmod_sync_007'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let fd = fileio.openSync(fpath); - fileio.fchmodSync(fd, 0o700); - expect((fileio.statSync(fpath).mode & 0o777) == 0o700).assertTrue(); - fileio.unlinkSync(fpath); - } - catch (err) { - console.info('fileio_test_fchmod_sync_007 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_FchmodSync_0800 - * @tc.name fileio_test_fchmod_sync_008 - * @tc.desc Function of API, fchmodSync(mode=0o400). The test file is exist. - */ - it('fileio_test_fchmod_sync_008', 0, async function () { - let fpath = await nextFileName('fileio_test_fchmod_sync_008'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let fd = fileio.openSync(fpath); - fileio.fchmodSync(fd, 0o400); - expect((fileio.statSync(fpath).mode & 0o777) == 0o400).assertTrue(); - fileio.unlinkSync(fpath); - } - catch (err) { - console.info('fileio_test_fchmod_sync_008 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_FchmodSync_0900 - * @tc.name fileio_test_fchmod_sync_009 - * @tc.desc Function of API, fchmodSync(mode=0o200). The test file is exist. - */ - it('fileio_test_fchmod_sync_009', 0, async function () { - let fpath = await nextFileName('fileio_test_fchmod_sync_009'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let fd = fileio.openSync(fpath); - fileio.fchmodSync(fd, 0o200); - expect((fileio.statSync(fpath).mode & 0o777) == 0o200).assertTrue(); - fileio.unlinkSync(fpath); - } - catch (err) { - console.info('fileio_test_fchmod_sync_009 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_FchmodSync_0100 - * @tc.name fileio_test_fchmod_sync_010 - * @tc.desc Function of API, fchmodSync(mode=0o100). The test file is exist. - */ - it('fileio_test_fchmod_sync_010', 0, async function () { - let fpath = await nextFileName('fileio_test_fchmod_sync_010'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let fd = fileio.openSync(fpath); - fileio.fchmodSync(fd, 0o100); - expect((fileio.statSync(fpath).mode & 0o777) == 0o100).assertTrue(); - fileio.unlinkSync(fpath); - } - catch (err) { - console.info('fileio_test_fchmod_sync_010 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_FchmodSync_0110 - * @tc.name fileio_test_fchmod_sync_011 - * @tc.desc Function of API, fchmodSync(mode=0o070). The test file is exist. - */ - it('fileio_test_fchmod_sync_011', 0, async function () { - let fpath = await nextFileName('fileio_test_fchmod_sync_011'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let fd = fileio.openSync(fpath); - fileio.fchmodSync(fd, 0o070); - expect((fileio.statSync(fpath).mode & 0o777) == 0o070).assertTrue(); - fileio.unlinkSync(fpath); - } - catch (err) { - console.info('fileio_test_fchmod_sync_011 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_FchmodSync_0120 - * @tc.name fileio_test_fchmod_sync_012 - * @tc.desc Function of API, fchmodSync(mode=0o040). The test file is exist. - */ - it('fileio_test_fchmod_sync_012', 0, async function () { - let fpath = await nextFileName('fileio_test_fchmod_sync_012'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let fd = fileio.openSync(fpath); - fileio.fchmodSync(fd, 0o040); - expect((fileio.statSync(fpath).mode & 0o777) == 0o040).assertTrue(); - fileio.unlinkSync(fpath); - } - catch (err) { - console.info('fileio_test_fchmod_sync_012 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_FchmodSync_0130 - * @tc.name fileio_test_fchmod_sync_013 - * @tc.desc Function of API, fchmodSync(mode=0o020). The test file is exist. - */ - it('fileio_test_fchmod_sync_013', 0, async function () { - let fpath = await nextFileName('fileio_test_fchmod_sync_013'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let fd = fileio.openSync(fpath); - fileio.fchmodSync(fd, 0o020); - expect((fileio.statSync(fpath).mode & 0o777) == 0o020).assertTrue(); - fileio.unlinkSync(fpath); - } - catch (err) { - console.info('fileio_test_fchmod_sync_013 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_FchmodSync_0140 - * @tc.name fileio_test_fchmod_sync_014 - * @tc.desc Function of API, fchmodSync(mode=0o010). The test file is exist. - */ - it('fileio_test_fchmod_sync_014', 0, async function () { - let fpath = await nextFileName('fileio_test_fchmod_sync_014'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let fd = fileio.openSync(fpath); - fileio.fchmodSync(fd, 0o010); - expect((fileio.statSync(fpath).mode & 0o777) == 0o010).assertTrue(); - fileio.unlinkSync(fpath); - } - catch (err) { - console.info('fileio_test_fchmod_sync_014 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_FchmodSync_0150 - * @tc.name fileio_test_fchmod_sync_015 - * @tc.desc Function of API, fchmodSync(mode=0o007). The test file is exist. - */ - it('fileio_test_fchmod_sync_015', 0, async function () { - let fpath = await nextFileName('fileio_test_fchmod_sync_015'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let fd = fileio.openSync(fpath); - fileio.fchmodSync(fd, 0o007); - expect((fileio.statSync(fpath).mode & 0o777) == 0o007).assertTrue(); - fileio.unlinkSync(fpath); - } - catch (err) { - console.info('fileio_test_fchmod_sync_015 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_FchmodSync_0160 - * @tc.name fileio_test_fchmod_sync_016 - * @tc.desc Function of API, fchmodSync(mode=0o004). The test file is exist. - */ - it('fileio_test_fchmod_sync_016', 0, async function () { - let fpath = await nextFileName('fileio_test_fchmod_sync_016'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let fd = fileio.openSync(fpath); - fileio.fchmodSync(fd, 0o004); - expect((fileio.statSync(fpath).mode & 0o777) == 0o004).assertTrue(); - fileio.unlinkSync(fpath); - } - catch (err) { - console.info('fileio_test_fchmod_sync_016 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_FchmodSync_0170 - * @tc.name fileio_test_fchmod_sync_017 - * @tc.desc Function of API, fchmodSync(mode=0o002). The test file is exist. - */ - it('fileio_test_fchmod_sync_017', 0, async function () { - let fpath = await nextFileName('fileio_test_fchmod_sync_017'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let fd = fileio.openSync(fpath); - fileio.fchmodSync(fd, 0o002); - expect((fileio.statSync(fpath).mode & 0o777) == 0o002).assertTrue(); - fileio.unlinkSync(fpath); - } - catch (err) { - console.info('fileio_test_fchmod_sync_017 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_FchmodSync_0180 - * @tc.name fileio_test_fchmod_sync_018 - * @tc.desc Function of API, fchmodSync(mode=0o001). The test file is exist. - */ - it('fileio_test_fchmod_sync_018', 0, async function () { - let fpath = await nextFileName('fileio_test_fchmod_sync_018'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let fd = fileio.openSync(fpath); - fileio.fchmodSync(fd, 0o001); - expect((fileio.statSync(fpath).mode & 0o777) == 0o001).assertTrue(); - fileio.unlinkSync(fpath); - } - catch (err) { - console.info('fileio_test_fchmod_sync_018 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_FtruncateSync_0000 - * @tc.name fileio_test_ftruncate_sync_000 - * @tc.desc Function of API, ftruncateSync. The test file is exist. - */ - it('fileio_test_ftruncate_sync_000', 0, async function () { - let fpath = await nextFileName('fileio_test_ftruncate_sync_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let fd = fileio.openSync(fpath, 0o2); - fileio.ftruncateSync(fd, 10); - expect(fileio.statSync(fpath).size == 10).assertTrue(); - fileio.unlinkSync(fpath); - } - catch (err) { - console.info('fileio_test_ftruncate_sync_000 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_FtruncateSync_0100 - * @tc.name fileio_test_ftruncate_sync_001 - * @tc.desc Function of API, len not for value. The test file is exist. - */ - it('fileio_test_ftruncate_sync_001', 0, async function () { - let fpath = await nextFileName('fileio_test_ftruncate_sync_001'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let fd = fileio.openSync(fpath, 0o2); - fileio.ftruncateSync(fd); - fileio.closeSync(fd); - fileio.unlinkSync(fpath); - } - catch (err) { - console.info('fileio_test_ftruncate_sync_001 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_FtruncateSync_0200 - * @tc.name fileio_test_ftruncate_sync_002 - * @tc.desc Function of API, invalid parameter. The test file is not exist. - */ - it('fileio_test_ftruncate_sync_002', 0, async function () { - try { - fileio.ftruncateSync(1); - }catch (err) { - console.info('fileio_test_ftruncate_sync_002 has failed for ' + err); - expect(err.message == "Invalid argument").assertTrue(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_FtruncateSync_0300 - * @tc.name fileio_test_ftruncate_sync_003 - * @tc.desc Function of API, invalid parameter. The test file is not exist. - */ - it('fileio_test_ftruncate_sync_003', 0, async function () { - try { - fileio.ftruncateSync(-1); - }catch (err) { - console.info('fileio_test_ftruncate_sync_003 has failed for ' + err); - expect(err.message == "Invalid fd").assertTrue(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_FtruncateSync_0400 - * @tc.name fileio_test_ftruncate_sync_004 - * @tc.desc Function of API, Parameter exception(len = -1). - */ - it('fileio_test_ftruncate_sync_004', 0, async function () { - let fpath = await nextFileName('fileio_test_ftruncate_sync_004'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let fd = fileio.openSync(fpath, 0o2); - fileio.ftruncateSync(fd, -1); - }catch (err) { - console.info('fileio_test_ftruncate_sync_004 has failed for ' + err); - expect(err.message == "Invalid argument").assertTrue(); - fileio.unlinkSync(fpath); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_FsyncSync_0000 - * @tc.name fileio_test_fsync_sync_000 - * @tc.desc Function of API, fsyneSync. - */ - it('fileio_test_fsync_sync_000', 0, async function () { - let fpath = await nextFileName('fileio_test_fsync_sync_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let fd = fileio.openSync(fpath, 0o2); - expect(fileio.fsyncSync(fd) !== null).assertTrue(); - fileio.closeSync(fd); - fileio.unlinkSync(fpath); - } - catch (err) { - console.info('fileio_test_fsync_sync_000 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_FsyncSync_0100 - * @tc.name fileio_test_fsync_sync_001 - * @tc.desc Function of API, no value of parameter. - */ - it('fileio_test_fsync_sync_001', 0, async function () { - try { - fileio.fsyncSync(1); - } - catch (err) { - console.info('fileio_test_fsync_sync_001 has failed for ' + err); - expect(err.message == "Invalid argument").assertTrue(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_FsyncSync_0200 - * @tc.name fileio_test_fsync_sync_002 - * @tc.desc Function of API, invalid parameter. - */ - it('fileio_test_fsync_sync_002', 0, async function () { - try { - fileio.fsyncSync(-1); - expect(false).assertTrue(); - } - catch (err) { - console.info('fileio_test_fsync_sync_002 has failed for ' + err); - expect(err.message == "Invalid fd").assertTrue(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_MkdirSync_RmdirSync_0000 - * @tc.name fileio_test_mkdir_sync_rmdir_sync_000 - * @tc.desc Sync to mkdir and rmdir. - */ - it('fileio_test_mkdir_sync_rmdir_sync_000', 0, async function () { - let dpath = await nextFileName('fileio_test_fsync_sync_000') + 'd' - try { - fileio.mkdirSync(dpath); - fileio.rmdirSync(dpath); - } - catch (err) { - console.info('fileio_test_mkdir_sync_rmdir_sync_000 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_MkdirSync_RmdirSync_0100 - * @tc.name fileio_test_mkdir_sync_rmdir_sync_001 - * @tc.desc Sync to mkdir and rmdir. mkdirSync(mode=0o660). - */ - it('fileio_test_mkdir_sync_rmdir_sync_001', 0, async function () { - let dpath = await nextFileName('fileio_test_mkdir_sync_rmdir_sync_001') + 'd' - try { - fileio.mkdirSync(dpath, 0o660); - fileio.rmdirSync(dpath); - } - catch (err) { - console.info('fileio_test_mkdir_sync_rmdir_sync_001 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_MkdirSync_RmdirSync_0200 - * @tc.name fileio_test_mkdir_sync_rmdir_sync_002 - * @tc.desc Sync to mkdir and rmdir. mkdirSync(mode=0o460). - */ - it('fileio_test_mkdir_sync_rmdir_sync_002', 0, async function () { - let dpath = await nextFileName('fileio_test_mkdir_sync_rmdir_sync_002') + 'd' - try { - fileio.mkdirSync(dpath, 0o460); - fileio.rmdirSync(dpath); - } - catch (err) { - console.info('fileio_test_mkdir_sync_rmdir_sync_002 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_MkdirSync_RmdirSync_0300 - * @tc.name fileio_test_mkdir_sync_rmdir_sync_003 - * @tc.desc Sync to mkdir and rmdir. mkdirSync(mode=0o260). - */ - it('fileio_test_mkdir_sync_rmdir_sync_003', 0, async function () { - let dpath = await nextFileName('fileio_test_mkdir_sync_rmdir_sync_003') + 'd' - try { - fileio.mkdirSync(dpath, 0o260); - fileio.rmdirSync(dpath); - } - catch (err) { - console.info('fileio_test_mkdir_sync_rmdir_sync_003 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_MkdirSync_RmdirSync_0400 - * @tc.name fileio_test_mkdir_sync_rmdir_sync_004 - * @tc.desc Function of API, invalid parameter. The test file is not exist. - */ - it('fileio_test_mkdir_sync_rmdir_sync_004', 0, async function () { - try { - fileio.mkdirSync(1); - }catch (err) { - console.info('fileio_test_mkdir_sync_rmdir_sync_004 has failed for ' + err); - expect(err.message == "Invalid path").assertTrue(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_MkdirSync_RmdirSync_0500 - * @tc.name fileio_test_mkdir_sync_rmdir_sync_005 - * @tc.desc Function of API, invalid parameter. The test file is not exist. - */ - it('fileio_test_mkdir_sync_rmdir_sync_005', 0, async function () { - try { - fileio.mkdirSync('/', 1); - } - catch (err) { - console.info('fileio_test_mkdir_sync_rmdir_sync_005 has failed for ' + err); - expect(err.message == "File exists").assertTrue(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_MkdirSync_RmdirSync_0600 - * @tc.name fileio_test_mkdir_sync_rmdir_sync_006 - * @tc.desc Sync to mkdir and rmdir. mkdirSync(mode=0o700). - */ - it('fileio_test_mkdir_sync_rmdir_sync_006', 0, async function () { - let dpath = await nextFileName('fileio_test_mkdir_sync_rmdir_sync_006') + 'd' - try { - fileio.mkdirSync(dpath, 0o700); - fileio.rmdirSync(dpath); - } - catch (err) { - console.info('fileio_test_mkdir_sync_rmdir_sync_006 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_MkdirSync_RmdirSync_0700 - * @tc.name fileio_test_mkdir_sync_rmdir_sync_007 - * @tc.desc Sync to mkdir and rmdir. mkdirSync(mode=0o400). - */ - it('fileio_test_mkdir_sync_rmdir_sync_007', 0, async function () { - let dpath = await nextFileName('fileio_test_mkdir_sync_rmdir_sync_007') + 'd' - try { - fileio.mkdirSync(dpath, 0o400); - fileio.rmdirSync(dpath); - } - catch (err) { - console.info('fileio_test_mkdir_sync_rmdir_sync_007 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_MkdirSync_RmdirSync_0800 - * @tc.name fileio_test_mkdir_sync_rmdir_sync_008 - * @tc.desc Sync to mkdir and rmdir. mkdirSync(mode=0o200). - */ - it('fileio_test_mkdir_sync_rmdir_sync_008', 0, async function () { - let dpath = await nextFileName('fileio_test_mkdir_sync_rmdir_sync_008') + 'd' - try { - fileio.mkdirSync(dpath, 0o200); - fileio.rmdirSync(dpath); - } - catch (err) { - console.info('fileio_test_mkdir_sync_rmdir_sync_008 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_MkdirSync_RmdirSync_0900 - * @tc.name fileio_test_mkdir_sync_rmdir_sync_009 - * @tc.desc Sync to mkdir and rmdir. mkdirSync(mode=0o100). - */ - it('fileio_test_mkdir_sync_rmdir_sync_009', 0, async function () { - let dpath = await nextFileName('fileio_test_mkdir_sync_rmdir_sync_009') + 'd' - try { - fileio.mkdirSync(dpath, 0o100); - fileio.rmdirSync(dpath); - } - catch (err) { - console.info('fileio_test_mkdir_sync_rmdir_sync_009 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_MkdirSync_RmdirSync_1000 - * @tc.name fileio_test_mkdir_sync_rmdir_sync_010 - * @tc.desc Sync to mkdir and rmdir. mkdirSync(mode=0o070). - */ - it('fileio_test_mkdir_sync_rmdir_sync_010', 0, async function () { - let dpath = await nextFileName('fileio_test_mkdir_sync_rmdir_sync_010') + 'd'; - try { - fileio.mkdirSync(dpath, 0o070); - fileio.rmdirSync(dpath); - } - catch (err) { - console.info('fileio_test_mkdir_sync_rmdir_sync_010 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_MkdirSync_RmdirSync_1100 - * @tc.name fileio_test_mkdir_sync_rmdir_sync_011 - * @tc.desc Sync to mkdir and rmdir. mkdirSync(mode=0o040). - */ - it('fileio_test_mkdir_sync_rmdir_sync_011', 0, async function () { - let dpath = await nextFileName('fileio_test_mkdir_sync_rmdir_sync_011') + 'd'; - try { - fileio.mkdirSync(dpath, 0o040); - fileio.rmdirSync(dpath); - } - catch (err) { - console.info('fileio_test_mkdir_sync_rmdir_sync_011 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_MkdirSync_RmdirSync_1200 - * @tc.name fileio_test_mkdir_sync_rmdir_sync_012 - * @tc.desc Sync to mkdir and rmdir. mkdirSync(mode=0o020). - */ - it('fileio_test_mkdir_sync_rmdir_sync_012', 0, async function () { - let dpath = await nextFileName('fileio_test_mkdir_sync_rmdir_sync_012') + 'd'; - try { - fileio.mkdirSync(dpath, 0o020); - fileio.rmdirSync(dpath); - } - catch (err) { - console.info('fileio_test_mkdir_sync_rmdir_sync_012 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_MkdirSync_RmdirSync_1300 - * @tc.name fileio_test_mkdir_sync_rmdir_sync_013 - * @tc.desc Sync to mkdir and rmdir. mkdirSync(mode=0o010). - */ - it('fileio_test_mkdir_sync_rmdir_sync_013', 0, async function () { - let dpath = await nextFileName('fileio_test_mkdir_sync_rmdir_sync_013') + 'd'; - try { - fileio.mkdirSync(dpath, 0o010); - fileio.rmdirSync(dpath); - } - catch (err) { - console.info('fileio_test_mkdir_sync_rmdir_sync_013 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_MkdirSync_RmdirSync_1400 - * @tc.name fileio_test_mkdir_sync_rmdir_sync_014 - * @tc.desc Sync to mkdir and rmdir. mkdirSync(mode=0o007). - */ - it('fileio_test_mkdir_sync_rmdir_sync_014', 0, async function () { - let dpath = await nextFileName('fileio_test_mkdir_sync_rmdir_sync_014') + 'd'; - try { - fileio.mkdirSync(dpath, 0o007); - fileio.rmdirSync(dpath); - } - catch (err) { - console.info('fileio_test_mkdir_sync_rmdir_sync_014 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_MkdirSync_RmdirSync_1500 - * @tc.name fileio_test_mkdir_sync_rmdir_sync_015 - * @tc.desc Sync to mkdir and rmdir. mkdirSync(mode=0o004). - */ - it('fileio_test_mkdir_sync_rmdir_sync_015', 0, async function () { - let dpath = await nextFileName('fileio_test_mkdir_sync_rmdir_sync_015') + 'd'; - try { - fileio.mkdirSync(dpath, 0o004); - fileio.rmdirSync(dpath); - } - catch (err) { - console.info('fileio_test_mkdir_sync_rmdir_sync_015 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_MkdirSync_RmdirSync_1600 - * @tc.name fileio_test_mkdir_sync_rmdir_sync_016 - * @tc.desc Sync to mkdir and rmdir. mkdirSync(mode=0o002). - */ - it('fileio_test_mkdir_sync_rmdir_sync_016', 0, async function () { - let dpath = await nextFileName('fileio_test_mkdir_sync_rmdir_sync_016') + 'd'; - try { - fileio.mkdirSync(dpath, 0o002); - fileio.rmdirSync(dpath); - } - catch (err) { - console.info('fileio_test_mkdir_sync_rmdir_sync_016 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_MkdirSync_RmdirSync_1700 - * @tc.name fileio_test_mkdir_sync_rmdir_sync_017 - * @tc.desc Sync to mkdir and rmdir. mkdirSync(mode=0o001). - */ - it('fileio_test_mkdir_sync_rmdir_sync_017', 0, async function () { - let dpath = await nextFileName('fileio_test_mkdir_sync_rmdir_sync_017') + 'd'; - try { - fileio.mkdirSync(dpath, 0o001); - fileio.rmdirSync(dpath); - } - catch (err) { - console.info('fileio_test_mkdir_sync_rmdir_sync_017 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_FstatSync_0000 - * @tc.name fileio_test_fstat_sync_000 - * @tc.desc Function of API, fstatSync. The test file is exist. - */ - it('fileio_test_fstat_sync_000', 0, async function () { - let fpath = await nextFileName('fileio_test_fstat_sync_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let fd = fileio.openSync(fpath, 0o2); - let stat = fileio.fstatSync(fd); - expect(stat !== null).assertTrue(); - fileio.closeSync(fd); - fileio.unlinkSync(fpath); - } - catch (err) { - console.info('fileio_test_fstat_sync_000 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_FstatSync_0100 - * @tc.name fileio_test_fstat_sync_001 - * @tc.desc Function of API, fstatSync, fd = -1. The test file is not exist. - */ - it('fileio_test_fstat_sync_001', 0, async function () { - try { - fileio.fstatSync(-1); - expect(false).assertTrue(); - }catch (err) { - console.info('fileio_test_fstat_sync_001 has failed for ' + err); - expect(err.message == "Invalid fd").assertTrue(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_FstatSync_0200 - * @tc.name fileio_test_fstat_sync_002 - * @tc.desc Function of API, fstatSync, fd is string type. - */ - it('fileio_test_fstat_sync_002', 0, async function () { - try { - fileio.fstatSync(""); - }catch (err) { - console.info('fileio_test_fstat_sync_002 has failed for ' + err); - expect(err.message == "Invalid fd").assertTrue(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_FstatSync_0300 - * @tc.name fileio_test_fstat_sync_003 - * @tc.desc Function of API, fstatSync, vaild fd. The test file is exist. - */ - it('fileio_test_fstat_sync_003', 0, async function () { - let dpath = await nextFileName('fileio_test_fstat_sync_003') + 'd' - try { - fileio.mkdirSync(dpath); - let fd = fileio.openSync(dpath); - expect(fd !== null).assertTrue(); - let stat = fileio.fstatSync(fd); - expect(stat !== null).assertTrue(); - fileio.closeSync(fd); - fileio.rmdirSync(dpath); - } - catch (err) { - console.info('fileio_test_fstat_sync_003 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_ChownSync_0000 - * @tc.name fileio_test_chown_sync_000 - * @tc.desc Function of API, chownSync. The test file is exist. - */ - it('fileio_test_chown_sync_000', 0, async function () { - let fpath = await nextFileName('fileio_test_chown_sync_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - let stat = fileio.statSync(fpath); - let UID = stat.uid - let GID = stat.gid - try { - expect(fileio.chownSync(fpath, UID, GID) !== null).assertTrue(); - fileio.unlinkSync(fpath); - } - catch (err) { - console.info('fileio_test_chown_sync_000 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_ChownSync_0100 - * @tc.name fileio_test_chown_sync_001 - * @tc.desc Function of API, chownSync. The test file is not exist. - */ - it('fileio_test_chown_sync_001', 0, async function () { - let fpath = await nextFileName('fileio_test_chown_sync_001'); - let fpathc = await nextFileName('fileio_test_chown_sync_001_1'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - let stat = fileio.statSync(fpath); - let UID = stat.uid - let GID = stat.gid - try { - expect(fileio.chownSync(fpathc, UID, GID)); - }catch (err) { - console.info('fileio_test_chown_sync_001 has failed for ' + err); - expect(err.message == "No such file or directory").assertTrue(); - fileio.unlinkSync(fpath); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_ChownSync_0200 - * @tc.name fileio_test_chown_sync_002 - * @tc.desc Function of API, invalid fd. The test file is not exist. - */ - it('fileio_test_chown_sync_002', 0, async function () { - let fpath = await nextFileName('fileio_test_chown_sync_002'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - expect(fileio.chownSync(fpath, 0, 0)); - }catch (err) { - console.info('fileio_test_chown_sync_002 has failed for ' + err); - expect(err.message == "Operation not permitted").assertTrue(); - fileio.unlinkSync(fpath); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_FchownSync_0000 - * @tc.name fileio_test_fchown_sync_000 - * @tc.desc Function of API, fchownSync. The test file is exist. - */ - it('fileio_test_fchown_sync_000', 0, async function () { - let fpath = await nextFileName('fileio_test_fchown_sync_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - let stat = fileio.statSync(fpath); - let UID = stat.uid - let GID = stat.gid - try { - let fd = fileio.openSync(fpath); - expect(fileio.fchownSync(fd, UID, GID) !== null).assertTrue(); - fileio.closeSync(fd); - fileio.unlinkSync(fpath); - } - catch (err) { - console.info('fileio_test_fchown_sync_000 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_FchownSync_0100 - * @tc.name fileio_test_fchown_sync_001 - * @tc.desc Function of API, fchownSync. The test file is not exist. - */ - it('fileio_test_fchown_sync_001', 0, async function () { - let fpath = await nextFileName('fileio_test_fchown_sync_001'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - let stat = fileio.statSync(fpath); - let UID = stat.uid - let GID = stat.gid - try { - expect(fileio.fchownSync(-1, UID, GID)); - }catch (err) { - fileio.unlinkSync(fpath); - console.info('fileio_test_fchown_sync_001 has failed for ' + err); - expect(err.message == "Bad file descriptor").assertTrue(); - } - - }); - - /** - * @tc.number SUB_STORAGE_FileIO_FchownSync_0200 - * @tc.name fileio_test_fchown_sync_002 - * @tc.desc Function of API, fchownSync, wrong owner. The test file is exist. - */ - it('fileio_test_fchown_sync_002', 0, async function () { - let fpath = await nextFileName('fileio_test_fchown_sync_002'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - let stat = fileio.statSync(fpath); - let fd; - let GID = stat.gid - try { - let fd = fileio.openSync(fpath); - fileio.fchownSync(fd, null, GID); - } - catch (err) { - fileio.unlinkSync(fpath); - console.info('fileio_test_fchown_sync_002 has failed for ' + err); - expect(err.message == "Invalid owner").assertTrue(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_FchownSync_0300 - * @tc.name fileio_test_fchown_sync_003 - * @tc.desc Function of API, fchownSync, wrong group. The test file is exist. - */ - it('fileio_test_fchown_sync_003', 0, async function () { - let fpath = await nextFileName('fileio_test_fchown_sync_003'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - let stat = fileio.statSync(fpath); - let UID = stat.uid; - let fd; - try { - fd = fileio.openSync(fpath, 0o2); - expect(fileio.fchownSync(fd, UID, 0)); - } - catch (err) { - fileio.closeSync(fd); - fileio.unlinkSync(fpath); - console.info('fileio_test_fchown_sync_003 has failed for ' + err); - expect(err.message == "Operation not permitted").assertTrue(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_FchownSync_0400 - * @tc.name fileio_test_fchown_sync_004 - * @tc.desc Function of API, fchownSync, no value of fd. The test file is exist. - */ - it('fileio_test_fchown_sync_004', 0, async function () { - let fpath = await nextFileName('fileio_test_fchown_sync_004'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - let stat = fileio.statSync(fpath); - let UID = stat.uid - let GID = stat.gid - let fd = null - try { - expect(fileio.fchownSync(fd, UID, GID)); - } - catch (err) { - fileio.unlinkSync(fpath); - console.info('fileio_test_fchown_sync_004 has failed for ' + err); - expect(err.message == "Invalid fd").assertTrue(); - } - - }); - - /** - * @tc.number SUB_STORAGE_FileIO_FchownSync_0500 - * @tc.name fileio_test_fchown_sync_005 - * @tc.desc Function of API, fchownSync, no value of owner. The test file is exist. - */ - it('fileio_test_fchown_sync_005', 0, async function () { - let fpath = await nextFileName('fileio_test_fchown_sync_005'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - let stat = fileio.statSync(fpath); - let UID = null - let GID = stat.gid - let fd; - try { - fd = fileio.openSync(fpath); - expect(fileio.fchownSync(fd, UID, GID)); - } - catch (err) { - fileio.closeSync(fd); - fileio.unlinkSync(fpath); - console.info('fileio_test_fchown_sync_005 has failed for ' + err); - expect(err.message == "Invalid owner").assertTrue(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_FchownSync_0600 - * @tc.name fileio_test_fchown_sync_006 - * @tc.desc Function of API, fchownSync, no value of group. The test file is exist. - */ - it('fileio_test_fchown_sync_006', 0, async function () { - let fpath = await nextFileName('fileio_test_fchown_sync_006'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - let stat = fileio.statSync(fpath); - let UID = stat.uid; - let fd; - try { - fd = fileio.openSync(fpath); - fileio.fchownSync(fd, UID, 0); - } - catch (err) { - fileio.closeSync(fd); - fileio.unlinkSync(fpath); - console.info('fileio_test_fchown_sync_006 has failed for ' + err); - expect(err.message == "Operation not permitted").assertTrue(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_FchownSync_0700 - * @tc.name fileio_test_fchown_sync_007 - * @tc.desc Function of API, fchownSync, no value of GID,UID. The test file is exist. - */ - it('fileio_test_fchown_sync_007', 0, async function () { - let fpath = await nextFileName('fileio_test_fchown_sync_007'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - let fd; - try { - fd = fileio.openSync(fpath, 0o2); - fileio.fchownSync(fd, 0, 0); - } - catch (err) { - fileio.closeSync(fd); - fileio.unlinkSync(fpath); - console.info('fileio_test_fchown_sync_007 has failed for ' + err); - expect(err.message == "Operation not permitted").assertTrue(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_prop_write_open_read_4k_sync - * @tc.name fileio_test_prop_write_open_read_4k_sync - * @tc.desc Sync to write & open & read 4K file. - */ - it('fileio_test_prop_write_open_read_4k_sync', 0, async function () { - let fpath = await nextFileName('fileio_test_prop_write_open_read_4k_sync'); - try { - let fd = fileio.openSync(fpath, 0o102, 0o777); - expect(fd !== null).assertTrue(); - expect(fileio.writeSync(fd, randomString(4096)) !== null).assertTrue(); - fileio.closeSync(fd); - let fd1 = fileio.openSync(fpath, 0o2); - let rlen = fileio.readSync(fd1, new ArrayBuffer(4096)); - expect(rlen == 4096).assertTrue(); - fileio.closeSync(fd1); - fileio.unlinkSync(fpath); - } - catch (err) { - console.info('fileio_test_prop_write_open_read_4k_sync has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_prop_write_open_read_4k_sync - * @tc.name fileio_test_prop_copyFile_4k_sync - * @tc.desc Sync to copy 4K file. - */ - it('fileio_test_prop_copyFile_4k_sync', 0, async function () { - let fpath = await nextFileName('fileio_test_prop_copyFile_4k_sync'); - let fpath1 = await fileName('fileio_test_prop_copyFile_4k_1_sync'); - try { - let fd = fileio.openSync(fpath, 0o102, 0o777); - expect(fd !== null).assertTrue(); - expect(fileio.writeSync(fd, randomString(4096)) !== null).assertTrue(); - fileio.closeSync(fd); - fileio.copyFileSync(fpath, fpath1); - fileio.unlinkSync(fpath); - fileio.unlinkSync(fpath1); - } - catch (err) { - console.info('fileio_test_prop_copyFile_4k_sync has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_stat_async_000 - * @tc.name fileio_test_stat_async_000 - * @tc.desc obtain file propertys by stat promise - */ - it('fileio_test_stat_promise_000', 0, async function () { - let fpath = await nextFileName('fileio_test_stat_promise_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - fileio.chmodSync(fpath, 0o660); - fileio.stat(fpath).then((stat)=> { - expect((stat.mode & 0o777) == 0o660).assertTrue(); - fileio.unlinkSync(fpath); - console.info('file stat Success'); - }).catch((err) => { - console.info("file stat err: " + JSON.stringify(err)); - }); - }); - - /** - * @tc.number SUB_STORAGE_FileIO_stat_async_001 - * @tc.name fileio_test_stat_async_001 - * @tc.desc obtain file propertys by stat promise - */ - it('fileio_test_stat_promise_001', 0, async function () { - let fpath = await nextFileName('fileio_test_stat_promise_001'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - fileio.chmodSync(fpath, 0o777); - fileio.stat(fpath).then((stat)=> { - expect((stat.mode & 0o777) == 0o777).assertTrue(); - fileio.unlinkSync(fpath); - console.info('file stat Success'); - }).catch((err) => { - console.info("file stat err: " + JSON.stringify(err)); - }); - }); - - /** - * @tc.number SUB_STORAGE_FileIO_stat_async_002 - * @tc.name fileio_test_stat_async_002 - * @tc.desc obtain file propertys by stat promise - */ - it('fileio_test_stat_promise_002', 0, async function () { - let fpath = await nextFileName('fileio_test_stat_promise_002'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - fileio.chmodSync(fpath, 0o774); - fileio.stat(fpath).then((stat)=> { - expect((stat.mode & 0o777) == 0o774).assertTrue(); - fileio.unlinkSync(fpath); - console.info('file stat Success'); - }).catch((err) => { - console.info("file stat err: " + JSON.stringify(err)); - }); - }); - - /** - * @tc.number SUB_STORAGE_FileIO_stat_async_003 - * @tc.name fileio_test_stat_async_003 - * @tc.desc obtain file propertys by stat promise - */ - it('fileio_test_stat_promise_003', 0, async function () { - let fpath = await nextFileName('fileio_test_stat_promise_003'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - fileio.chmodSync(fpath, 0o772); - fileio.stat(fpath).then((stat)=> { - expect((stat.mode & 0o777) == 0o772).assertTrue(); - fileio.unlinkSync(fpath); - console.info('file stat Success'); - }).catch((err) => { - console.info("file stat err: " + JSON.stringify(err)); - }); - }); - - /** - * @tc.number SUB_STORAGE_FileIO_stat_async_004 - * @tc.name fileio_test_stat_async_004 - * @tc.desc obtain file propertys by stat promise - */ - it('fileio_test_stat_promise_004', 0, async function () { - let fpath = await nextFileName('fileio_test_stat_promise_004'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - fileio.chmodSync(fpath, 0o771); - fileio.stat(fpath).then((stat)=> { - expect((stat.mode & 0o777) == 0o771).assertTrue(); - fileio.unlinkSync(fpath); - console.info('file stat Success'); - }).catch((err) => { - console.info("file stat err: " + JSON.stringify(err)); - }); - }); - - /** - * @tc.number SUB_STORAGE_FileIO_stat_async_005 - * @tc.name fileio_test_stat_async_005 - * @tc.desc obtain file propertys by stat promise - */ - it('fileio_test_stat_promise_005', 0, async function () { - let fpath = await nextFileName('fileio_test_stat_promise_005'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - fileio.chmodSync(fpath, 0o770); - fileio.stat(fpath).then((stat)=> { - expect((stat.mode & 0o777) == 0o770).assertTrue(); - fileio.unlinkSync(fpath); - console.info('file stat Success'); - }).catch((err) => { - console.info("file stat err: " + JSON.stringify(err)); - }); - }); - - /** - * @tc.number SUB_STORAGE_FileIO_stat_async_006 - * @tc.name fileio_test_stat_async_006 - * @tc.desc obtain file propertys by stat promise - */ - it('fileio_test_stat_promise_006', 0, async function () { - let fpath = await nextFileName('fileio_test_stat_promise_006'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - fileio.chmodSync(fpath, 0o666); - fileio.stat(fpath).then((stat)=> { - expect((stat.mode & 0o777) == 0o666).assertTrue(); - fileio.unlinkSync(fpath); - console.info('file stat Success'); - }).catch((err) => { - console.info("file stat err: " + JSON.stringify(err)); - }); - }); - - /** - * @tc.number SUB_STORAGE_FileIO_stat_async_007 - * @tc.name fileio_test_stat_async_007 - * @tc.desc obtain file propertys by stat promise - */ - it('fileio_test_stat_promise_007', 0, async function () { - let fpath = await nextFileName('fileio_test_stat_promise_007'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - fileio.chmodSync(fpath, 0o664); - fileio.stat(fpath).then((stat)=> { - expect((stat.mode & 0o777) == 0o664).assertTrue(); - fileio.unlinkSync(fpath); - console.info('file stat Success'); - }).catch((err) => { - console.info("file stat err: " + JSON.stringify(err)); - }); - }); - - /** - * @tc.number SUB_STORAGE_FileIO_stat_async_008 - * @tc.name fileio_test_stat_async_008 - * @tc.desc obtain file propertys by stat promise - */ - it('fileio_test_stat_promise_008', 0, async function () { - let fpath = await nextFileName('fileio_test_stat_promise_008'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - fileio.chmodSync(fpath, 0o662); - fileio.stat(fpath).then((stat)=> { - expect((stat.mode & 0o777) == 0o662).assertTrue(); - fileio.unlinkSync(fpath); - console.info('file stat Success'); - }).catch((err) => { - console.info("file stat err: " + JSON.stringify(err)); - }); - }); - - /** - * @tc.number SUB_STORAGE_FileIO_stat_async_009 - * @tc.name fileio_test_stat_async_009 - * @tc.desc obtain file propertys by stat promise - */ - it('fileio_test_stat_promise_009', 0, async function () { - let fpath = await nextFileName('fileio_test_stat_promise_009'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - fileio.chmodSync(fpath, 0o661); - fileio.stat(fpath).then((stat)=> { - expect((stat.mode & 0o777) == 0o661).assertTrue(); - fileio.unlinkSync(fpath); - console.info('file stat Success'); - }).catch((err) => { - console.info("file stat err: " + JSON.stringify(err)); - }); - }); - - /** - * @tc.number SUB_STORAGE_FileIO_stat_async_010 - * @tc.name fileio_test_stat_async_010 - * @tc.desc obtain file propertys by stat promise - */ - it('fileio_test_stat_promise_010', 0, async function () { - let fpath = await nextFileName('fileio_test_stat_promise_010'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - fileio.chmodSync(fpath, 0o660); - fileio.stat(fpath).then((stat)=> { - expect((stat.mode & 0o777) == 0o660).assertTrue(); - fileio.unlinkSync(fpath); - console.info('file stat Success'); - }).catch((err) => { - console.info("file stat err: " + JSON.stringify(err)); - }); - }); - - /** - * @tc.number SUB_STORAGE_FileIO_stat_async_011 - * @tc.name fileio_test_stat_async_011 - * @tc.desc obtain file propertys by stat promise - */ - it('fileio_test_stat_promise_011', 0, async function () { - let fpath = await nextFileName('fileio_test_stat_promise_011'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - fileio.chmodSync(fpath, 0o640); - fileio.stat(fpath).then((stat)=> { - expect((stat.mode & 0o777) == 0o640).assertTrue(); - fileio.unlinkSync(fpath); - console.info('file stat Success'); - }).catch((err) => { - console.info("file stat err: " + JSON.stringify(err)); - }); - }); - - /** - * @tc.number SUB_STORAGE_FileIO_stat_async_012 - * @tc.name fileio_test_stat_async_012 - * @tc.desc obtain file propertys by stat promise - */ - it('fileio_test_stat_promise_012', 0, async function () { - let fpath = await nextFileName('fileio_test_stat_promise_012'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - fileio.chmodSync(fpath, 0o600); - fileio.stat(fpath).then((stat)=> { - expect((stat.mode & 0o777) == 0o600).assertTrue(); - fileio.unlinkSync(fpath); - console.info('file stat Success'); - }).catch((err) => { - console.info("file stat err: " + JSON.stringify(err)); - }); - }); - - /** - * @tc.number fileio_test_stat_async_013 - * @tc.name fileio_test_stat_async_013 - * @tc.desc Function of API, obtain file propertys by stat async - */ - it('fileio_test_stat_async_013', 0, async function () { - let fpath = await nextFileName('fileio_test_stat_async_013'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - fileio.chmodSync(fpath, 0o660); - fileio.stat(fpath, function (err, stat) { - expect((stat.mode & 0o777) == 0o660).assertTrue(); - fileio.unlinkSync(fpath); - }); - }); - - /** - * @tc.number fileio_test_stat_async_014 - * @tc.name fileio_test_stat_async_014 - * @tc.desc Function of API, obtain file propertys by stat async - */ - it('fileio_test_stat_async_014', 0, async function () { - let fpath = await nextFileName('fileio_test_stat_async_014'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - fileio.chmodSync(fpath, 0o777); - fileio.stat(fpath, function (err, stat) { - expect((stat.mode & 0o777) == 0o777).assertTrue(); - fileio.unlinkSync(fpath); - }); - }); - - /** - * @tc.number fileio_test_stat_async_015 - * @tc.name fileio_test_stat_async_015 - * @tc.desc Function of API, obtain file propertys by stat async - */ - it('fileio_test_stat_async_015', 0, async function () { - let fpath = await nextFileName('fileio_test_stat_async_015'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - fileio.chmodSync(fpath, 0o776); - fileio.stat(fpath, function (err, stat) { - expect((stat.mode & 0o777) == 0o776).assertTrue(); - fileio.unlinkSync(fpath); - }); - }); - - /** - * @tc.number fileio_test_stat_async_016 - * @tc.name fileio_test_stat_async_016 - * @tc.desc Function of API, obtain file propertys by stat async - */ - it('fileio_test_stat_async_016', 0, async function () { - let fpath = await nextFileName('fileio_test_stat_async_016'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - fileio.chmodSync(fpath, 0o774); - fileio.stat(fpath, function (err, stat) { - expect((stat.mode & 0o777) == 0o774).assertTrue(); - fileio.unlinkSync(fpath); - }); - }); - - /** - * @tc.number fileio_test_stat_async_017 - * @tc.name fileio_test_stat_async_017 - * @tc.desc Function of API, obtain file propertys by stat async - */ - it('fileio_test_stat_async_017', 0, async function () { - let fpath = await nextFileName('fileio_test_stat_async_017'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - fileio.chmodSync(fpath, 0o772); - fileio.stat(fpath, function (err, stat) { - expect((stat.mode & 0o777) == 0o772).assertTrue(); - fileio.unlinkSync(fpath); - }); - }); - - /** - * @tc.number fileio_test_stat_async_018 - * @tc.name fileio_test_stat_async_018 - * @tc.desc Function of API, obtain file propertys by stat async - */ - it('fileio_test_stat_async_018', 0, async function () { - let fpath = await nextFileName('fileio_test_stat_async_018'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - fileio.chmodSync(fpath, 0o771); - fileio.stat(fpath, function (err, stat) { - expect((stat.mode & 0o777) == 0o771).assertTrue(); - fileio.unlinkSync(fpath); - }); - }); - - /** - * @tc.number fileio_test_stat_async_019 - * @tc.name fileio_test_stat_async_019 - * @tc.desc Function of API, obtain file propertys by stat async - */ - it('fileio_test_stat_async_019', 0, async function () { - let fpath = await nextFileName('fileio_test_stat_async_019'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - fileio.chmodSync(fpath, 0o770); - fileio.stat(fpath, function (err, stat) { - expect((stat.mode & 0o777) == 0o770).assertTrue(); - fileio.unlinkSync(fpath); - }); - }); - - /** - * @tc.number fileio_test_stat_async_020 - * @tc.name fileio_test_stat_async_020 - * @tc.desc Function of API, obtain file propertys by stat async - */ - it('fileio_test_stat_async_020', 0, async function () { - let fpath = await nextFileName('fileio_test_stat_async_020'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - fileio.chmodSync(fpath, 0o666); - fileio.stat(fpath, function (err, stat) { - expect((stat.mode & 0o777) == 0o666).assertTrue(); - fileio.unlinkSync(fpath); - }); - }); - - /** - * @tc.number fileio_test_stat_async_021 - * @tc.name fileio_test_stat_async_021 - * @tc.desc Function of API, obtain file propertys by stat async - */ - it('fileio_test_stat_async_021', 0, async function () { - let fpath = await nextFileName('fileio_test_stat_async_021'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - fileio.chmodSync(fpath, 0o664); - fileio.stat(fpath, function (err, stat) { - expect((stat.mode & 0o777) == 0o664).assertTrue(); - fileio.unlinkSync(fpath); - }); - }); - - /** - * @tc.number fileio_test_stat_async_022 - * @tc.name fileio_test_stat_async_022 - * @tc.desc Function of API, obtain file propertys by stat async - */ - it('fileio_test_stat_async_022', 0, async function () { - let fpath = await nextFileName('fileio_test_stat_async_022'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - fileio.chmodSync(fpath, 0o662); - fileio.stat(fpath, function (err, stat) { - expect((stat.mode & 0o777) == 0o662).assertTrue(); - fileio.unlinkSync(fpath); - }); - }); - - /** - * @tc.number fileio_test_stat_async_023 - * @tc.name fileio_test_stat_async_023 - * @tc.desc Function of API, obtain file propertys by stat async - */ - it('fileio_test_stat_async_023', 0, async function () { - let fpath = await nextFileName('fileio_test_stat_async_023'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - fileio.chmodSync(fpath, 0o640); - fileio.stat(fpath, function (err, stat) { - expect((stat.mode & 0o777) == 0o640).assertTrue(); - fileio.unlinkSync(fpath); - }); - }); - - /** - * @tc.number fileio_test_stat_async_024 - * @tc.name fileio_test_stat_async_024 - * @tc.desc Function of API, obtain file propertys by stat async - */ - it('fileio_test_stat_async_024', 0, async function () { - let fpath = await nextFileName('fileio_test_stat_async_024'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - fileio.chmodSync(fpath, 0o600); - fileio.stat(fpath, function (err, stat) { - expect((stat.mode & 0o777) == 0o600).assertTrue(); - fileio.unlinkSync(fpath); - }); - }); - - /** - * @tc.number fileio_test_stat_async_025 - * @tc.name fileio_test_stat_async_025 - * @tc.desc Function of API, obtain file propertys by stat async - */ - it('fileio_test_stat_async_025', 0, async function () { - let fpath = await nextFileName('fileio_test_stat_async_025'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - fileio.chmodSync(fpath, 0o400); - fileio.stat(fpath, function (err, stat) { - expect((stat.mode & 0o777) == 0o400).assertTrue(); - fileio.unlinkSync(fpath); - }); - }); - - /** - * @tc.number fileio_test_stat_async_026 - * @tc.name fileio_test_stat_async_026 - * @tc.desc Function of API, obtain file propertys by stat async - */ - it('fileio_test_stat_async_026', 0, async function () { - let fpath = await nextFileName('fileio_test_stat_async_026'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - fileio.chmodSync(fpath, 0o200); - fileio.stat(fpath, function (err, stat) { - expect((stat.mode & 0o777) == 0o200).assertTrue(); - fileio.unlinkSync(fpath); - }); - }); - - /** - * @tc.number fileio_test_close_async_000 - * @tc.name fileio_test_close_async_000 - * @tc.desc Function of API close promise - */ - it('fileio_test_close_async_000', 0, async function () { - let fpath = await nextFileName('fileio_test_close_async_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - let fd = fileio.openSync(fpath); - expect(fd !== null).assertTrue(); - await fileio.close(fd); - fileio.unlinkSync(fpath); - }); - - /** - * @tc.number fileio_test_close_async_001 - * @tc.name fileio_test_close_async_001 - * @tc.desc Function of API close - */ - it('fileio_test_close_async_001', 0, async function () { - let fpath = await nextFileName('fileio_test_close_async_001'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - let fd = fileio.openSync(fpath); - fileio.close(fd, function (err) { - fileio.unlinkSync(fpath); - }); - }); - }); -} +/* + * Copyright (C) 2021 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 fileio from '@ohos.fileio'; +import { describe,it,expect}from '@ohos/hypium' +import { + FILE_CONTENT, + prepareFile, + nextFileName, + prepareEmptyFile, + randomString, + fileName, + forceRemoveDir +} +from './Common' +export default function fileIOTest() { + describe('fileIOTest', function () { + + /** + * @tc.number SUB_STORAGE_FileIO_open&closesync_0000 + * @tc.name fileio_test_open_close_sync_000 + * @tc.desc Function of API, openSync. The test file is exist. + */ + it('fileio_test_open_close_sync_000', 0, async function () { + let fpath = await nextFileName('fileio_test_open_close_sync_000'); + try { + let fd = fileio.openSync(fpath, 0o102, 0o666); + expect(fd !== null).assertTrue(); + fileio.closeSync(fd); + fileio.unlinkSync(fpath); + } + catch (err) { + console.info('fileio_test_open_close_sync_000 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_OpenSync_0000 + * @tc.name fileio_test_open_000 + * @tc.desc Function of API, openSync(mode not for value). The test file is exist. + */ + it('fileio_test_open_000', 0, async function () { + let fpath = await nextFileName('fileio_test_open_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let fd = fileio.openSync(fpath, 0o202); + expect(fd !== null).assertTrue(); + fileio.closeSync(fd); + fileio.unlinkSync(fpath); + } + catch (err) { + console.info('fileio_test_open_000 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_OpenSync_0100 + * @tc.name fileio_test_open_001 + * @tc.desc Function of API, flags=0o100. mode=0o001 + */ + it('fileio_test_open_001', 0, async function () { + let fpath = await nextFileName('fileio_test_open_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let fd = fileio.openSync(fpath, 0o100, 0o001); + expect(fd !== null).assertTrue(); + fileio.closeSync(fd); + fileio.unlinkSync(fpath); + } + catch (err) { + console.info('fileio_test_open_001 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_OpenSync_0200 + * @tc.name fileio_test_open_002 + * @tc.desc Function of API, + */ + it('fileio_test_open_002', 0, async function () { + let fpath = await nextFileName('fileio_test_open_002'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let fd = fileio.openSync(fpath); + expect(fd !== null).assertTrue(); + fileio.closeSync(fd); + fileio.unlinkSync(fpath); + } + catch (err) { + console.info('fileio_test_open_002 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_OpenSync_0300 + * @tc.name fileio_test_open_003 + * @tc.desc Function of API, flags=0o100. mode=0o004 + */ + it('fileio_test_open_003', 0, async function () { + let fpath = await nextFileName('fileio_test_open_003'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let fd = fileio.openSync(fpath, 0o100, 0o004); + expect(fd !== null).assertTrue(); + fileio.writeSync(fd, FILE_CONTENT, { + encoding: 'utf-8', + offset: 1, + length: 1, + }); + }catch (err) { + console.info('fileio_test_open_003 has failed for ' + err); + expect(err.message == "Bad file descriptor").assertTrue(); + fileio.unlinkSync(fpath); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_OpenSync_0400 + * @tc.name fileio_test_open_004 + * @tc.desc Function of API, flags=0o101. mode=0o002 + */ + it('fileio_test_open_004', 0, async function () { + let fpath = await nextFileName('fileio_test_open_004'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let fd = fileio.openSync(fpath, 0o101, 0o002); + expect(fd !== null).assertTrue(); + fileio.readSync(fd, new ArrayBuffer(4096), { + offset: 1, + }); + }catch (err) { + console.info('fileio_test_open_004 has failed for ' + err); + expect(err.message == "Bad file descriptor").assertTrue(); + fileio.unlinkSync(fpath); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_OpenSync_0500 + * @tc.name fileio_test_open_005 + * @tc.desc Function of API, flags=0o102. mode=0o001. + */ + it('fileio_test_open_005', 0, async function () { + let fpath = await nextFileName('fileio_test_open_005'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let fd = fileio.openSync(fpath, 0o102, 0o001); + expect(fd !== null).assertTrue(); + let wri = fileio.writeSync(fd, FILE_CONTENT, { + encoding: 'utf-8', + offset: 1, + length: 1, + }); + expect(wri !== null).assertTrue(); + let red = fileio.readSync(fd, new ArrayBuffer(4096), { + offset: 1, + }); + expect(red !== null).assertTrue(); + fileio.closeSync(fd); + fileio.unlinkSync(fpath); + } + catch (err) { + console.info('fileio_test_open_005 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_OpenSync_0600 + * @tc.name fileio_test_open_006 + * @tc.desc Function of API, flags=0o200. mode=0o700 + */ + it('fileio_test_open_006', 0, async function () { + let fpath = await nextFileName('fileio_test_open_006'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + fileio.openSync(fpath, 0o200, 0o700); + fileio.unlinkSync(fpath); + } + catch (err) { + console.info('fileio_test_open_006 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_OpenSync_0700 + * @tc.name fileio_test_open_007 + * @tc.desc Function of API, flags=0o302. mode=0o700. + */ + it('fileio_test_open_007', 0, async function () { + let fpath = await nextFileName('fileio_test_open_007'); + try { + let fd = fileio.openSync(fpath, 0o302, 0o700); + expect(fd !== null).assertTrue(); + let wri = fileio.writeSync(fd, FILE_CONTENT, { + encoding: 'utf-8', + offset: 1, + length: 1, + }); + expect(wri !== null).assertTrue(); + let red = fileio.readSync(fd, new ArrayBuffer(4096), { + offset: 1, + }); + expect(red !== null).assertTrue(); + fileio.closeSync(fd); + fileio.unlinkSync(fpath); + } + catch (err) { + console.info('fileio_test_open_007 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_OpenSync_0800 + * @tc.name fileio_test_open_008 + * @tc.desc Function of API, flags=0o102. mode=0o700 + */ + it('fileio_test_open_008', 0, async function () { + let fpath = await nextFileName('fileio_test_open_008'); + try { + let fd = fileio.openSync(fpath, 0o102, 0o700); + expect(fd !== null).assertTrue(); + let wri = fileio.writeSync(fd, FILE_CONTENT, { + encoding: 'utf-8', + offset: 1, + length: 1, + }); + expect(wri !== null).assertTrue(); + let red = fileio.readSync(fd, new ArrayBuffer(4096), { + offset: 1, + }); + expect(red !== null).assertTrue(); + fileio.closeSync(fd); + fileio.unlinkSync(fpath); + } + catch (err) { + console.info('fileio_test_open_008 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_OpenSync_0900 + * @tc.name fileio_test_open_009 + * @tc.desc Function of API, flags=0o302. + */ + it('fileio_test_open_009', 0, async function () { + let fpath = await nextFileName('fileio_test_open_009'); + try { + fileio.openSync(fpath, 0o302); + }catch (err) { + console.info('fileio_test_open_009 has failed for ' + err); + expect(err.message == "called with O_CREAT/O_TMPFILE but no mode").assertTrue(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_OpenSync_1000 + * @tc.name fileio_test_open_010 + * @tc.desc Function of API, flags=0o402. + */ + it('fileio_test_open_010', 0, async function () { + let fpath = await nextFileName('fileio_test_open_010'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let fd = fileio.openSync(fpath, 0o402); + expect(fd !== null).assertTrue(); + let wri = fileio.writeSync(fd, FILE_CONTENT, { + encoding: 'utf-8', + offset: 1, + length: 1, + }); + expect(wri !== null).assertTrue(); + let red = fileio.readSync(fd, new ArrayBuffer(4096), { + offset: 1, + }); + expect(red !== null).assertTrue(); + fileio.closeSync(fd); + fileio.unlinkSync(fpath); + } + catch (err) { + console.info('fileio_test_open_010 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_OpenSync_1100 + * @tc.name fileio_test_open_011 + * @tc.desc Function of API, flags=0o1000. + */ + it('fileio_test_open_011', 0, async function () { + let fpath = await nextFileName('fileio_test_open_011'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let fd = fileio.openSync(fpath, 0o1000); + expect(fd !== null).assertTrue(); + let red = fileio.readSync(fd, new ArrayBuffer(4096), { + offset: 1, + }); + expect(red !== null).assertTrue(); + fileio.closeSync(fd); + fileio.unlinkSync(fpath); + } + catch (err) { + console.info('fileio_test_open_011 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_OpenSync_1200 + * @tc.name fileio_test_open_012 + * @tc.desc Function of API, flags=0o1001. + */ + it('fileio_test_open_012', 0, async function () { + let fpath = await nextFileName('fileio_test_open_012'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let fd = fileio.openSync(fpath, 0o1001); + expect(fd !== null).assertTrue(); + fileio.readSync(fd, new ArrayBuffer(4096), { + offset: 1, + }); + } + catch (err) { + console.info('fileio_test_open_012 has failed for ' + err); + expect(err.message == "Bad file descriptor").assertTrue(); + fileio.unlinkSync(fpath); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_OpenSync_1300 + * @tc.name fileio_test_open_013 + * @tc.desc Function of API, flags=0o2002. + */ + it('fileio_test_open_013', 0, async function () { + let fpath = await nextFileName('fileio_test_open_013'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let fd = fileio.openSync(fpath, 0o2002); + expect(fd !== null).assertTrue(); + let wri = fileio.writeSync(fd, 'hello', { + encoding: 'utf-8', + offset: 1, + length: 1, + }); + expect(wri !== null).assertTrue(); + let red = fileio.readSync(fd, new ArrayBuffer(4096), { + offset: 1, + }); + expect(red !== null).assertTrue(); + fileio.closeSync(fd); + fileio.unlinkSync(fpath); + } + catch (err) { + console.info('fileio_test_open_013 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_OpenSync_1400 + * @tc.name fileio_test_open_014 + * @tc.desc Function of API, flags=0o4002. + */ + it('fileio_test_open_014', 0, async function (done) { + let fpath = await nextFileName('fileio_test_open_014'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let fd = fileio.openSync(fpath, 0o4002); + expect(fd !== null).assertTrue(); + let fd2 = fileio.openSync(fpath, 0o4002); + expect(fd2 !== null).assertTrue(); + fileio.closeSync(fd); + fileio.closeSync(fd2); + fileio.unlinkSync(fpath); + done(); + } + catch (err) { + console.info('fileio_test_open_014 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_OpenSync_1500 + * @tc.name fileio_test_open_015 + * @tc.desc Function of API, flags=0o20002. + */ + it('fileio_test_open_015', 0, async function () { + let fpath = await nextFileName('fileio_test_open_015'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let fd = fileio.openSync(fpath, 0o20002); + expect(fd !== null).assertTrue(); + fileio.closeSync(fd); + fileio.unlinkSync(fpath); + } + catch (err) { + console.info('fileio_test_open_015 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_OpenSync_1600 + * @tc.name fileio_test_open_016 + * @tc.desc Function of API, flags=0o10002. + */ + it('fileio_test_open_016', 0, async function () { + let fpath = await nextFileName('fileio_test_open_016'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let fd = fileio.openSync(fpath, 0o10002); + expect(fd !== null).assertTrue(); + fileio.closeSync(fd); + fileio.unlinkSync(fpath); + } + catch (err) { + console.info('fileio_test_open_016 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_OpenSync_1700 + * @tc.name fileio_test_open_017 + * @tc.desc Function of API, flags=0o4010002. + */ + it('fileio_test_open_017', 0, async function () { + let fpath = await nextFileName('fileio_test_open_017'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let fd = fileio.openSync(fpath, 0o4010002); + expect(fd !== null).assertTrue(); + fileio.closeSync(fd); + fileio.unlinkSync(fpath); + } + catch (err) { + console.info('fileio_test_open_017 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_OpenSync_1800 + * @tc.name fileio_test_open_018 + * @tc.desc Function of API, flags=0o100002. + */ + it('fileio_test_open_018', 0, async function () { + let fpath = await nextFileName('fileio_test_open_018'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let fd = fileio.openSync(fpath, 0o100002); + expect(fd !== null).assertTrue(); + fileio.closeSync(fd); + fileio.unlinkSync(fpath); + } + catch (err) { + console.info('fileio_test_open_018 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_OpenSync_1900 + * @tc.name fileio_test_open_019 + * @tc.desc Function of API, flags=0o40002. mode=0o700 + */ + it('fileio_test_open_019', 0, async function () { + let fpath = await nextFileName('fileio_test_open_019'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + fileio.openSync(fpath, 0o40002, 0o700); + fileio.unlinkSync(fpath); + }catch (err) { + console.info('fileio_test_open_019 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_OpenSync_2100 + * @tc.name fileio_test_open_021 + * @tc.desc Function of API, flags=0o2000002. + */ + it('fileio_test_open_021', 0, async function () { + let fpath = await nextFileName('fileio_test_open_021'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let fd = fileio.openSync(fpath, 0o2000002); + expect(fd !== null).assertTrue(); + fileio.closeSync(fd); + fileio.unlinkSync(fpath); + } + catch (err) { + console.info('fileio_test_open_021 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_OpenSync_2200 + * @tc.name fileio_test_open_022 + * @tc.desc Function of API, flags=0o200000. + */ + it('fileio_test_open_022', 0, async function () { + let dpath = await nextFileName('fileio_test_open_022') + 'd'; + fileio.mkdirSync(dpath); + try { + fileio.openSync(dpath, 0o200000, 0o666); + fileio.rmdirSync(dpath); + } + catch (err) { + console.info('fileio_test_open_022 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_OpenSync_2300 + * @tc.name fileio_test_open_023 + * @tc.desc Function of API, flags=0o400002. + */ + it('fileio_test_open_023', 0, async function () { + let fpath = await nextFileName('fileio_test_open_023'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let fd = fileio.openSync(fpath, 0o400002); + expect(fd !== null).assertTrue(); + fileio.closeSync(fd); + fileio.unlinkSync(fpath); + } + catch (err) { + console.info('fileio_test_open_023 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_OpenSync_2400 + * @tc.name fileio_test_open_024 + * @tc.desc Function of API, flags=0o1000002.mode=0o700 + */ + it('fileio_test_open_024', 0, async function () { + let fpath = await nextFileName('fileio_test_open_024'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let fd = fileio.openSync(fpath, 0o1000002, 0o700); + expect(fd !== null).assertTrue(); + fileio.closeSync(fd); + fileio.unlinkSync(fpath); + } + catch (err) { + console.info('fileio_test_open_024 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_OpenSync_2500 + * @tc.name fileio_test_open_025 + * @tc.desc Function of API, flags=0o10000002. + */ + it('fileio_test_open_025', 0, async function () { + let fpath = await nextFileName('fileio_test_open_025'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let fd = fileio.openSync(fpath, 0o10000002); + expect(fd !== null).assertTrue(); + fileio.closeSync(fd); + fileio.unlinkSync(fpath); + } + catch (err) { + console.info('fileio_test_open_025 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_OpenSync_2600 + * @tc.name fileio_test_open_026 + * @tc.desc Function of API,flags=0o002.mode=0o700 + */ + it('fileio_test_open_026', 0, async function () { + let fpath = await nextFileName('fileio_test_open_026'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let fd = fileio.openSync(fpath, 0o002, 0o700); + expect(fd !== null).assertTrue(); + fileio.closeSync(fd); + fileio.unlinkSync(fpath); + } + catch (err) { + console.info('fileio_test_open_026 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_OpenSync_2700 + * @tc.name fileio_test_open_027 + * @tc.desc Function of API, flags=0o002.mode=0o400 + */ + it('fileio_test_open_027', 0, async function () { + let fpath = await nextFileName('fileio_test_open_027'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let fd = fileio.openSync(fpath, 0o002, 0o400); + expect(fd !== null).assertTrue(); + let red = fileio.readSync(fd, new ArrayBuffer(4096), { + offset: 1, + }); + expect(red !== null).assertTrue(); + fileio.writeSync(fd, 'hello', { + encoding: 'utf-8', + offset: 1, + length: 1, + }); + throw new Error('read only'); + } + catch (err) { + console.info('fileio_test_open_027 has failed for ' + err); + fileio.unlinkSync(fpath); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_OpenSync_2800 + * @tc.name fileio_test_open_028 + * @tc.desc Function of API, flags=0o002.mode=0o200 + */ + it('fileio_test_open_028', 0, async function () { + let fpath = await nextFileName('fileio_test_open_028'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let fd = fileio.openSync(fpath, 0o002, 0o200); + expect(fd !== null).assertTrue(); + let wri = fileio.writeSync(fd, 'hello', { + encoding: 'utf-8', + offset: 1, + length: 1, + }); + expect(wri !== null).assertTrue(); + fileio.readSync(fd, new ArrayBuffer(4096), { + offset: 1, + }); + throw new Error('write only'); + } + catch (err) { + console.info('fileio_test_open_028 has failed for ' + err); + fileio.unlinkSync(fpath); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_OpenSync_2900 + * @tc.name fileio_test_open_029 + * @tc.desc Function of API, flags=0o002.mode=0o100 + */ + it('fileio_test_open_029', 0, async function () { + let fpath = await nextFileName('fileio_test_open_029'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let fd = fileio.openSync(fpath, 0o002, 0o100); + expect(fd !== null).assertTrue(); + fileio.closeSync(fd); + fileio.unlinkSync(fpath); + } + catch (err) { + console.info('fileio_test_open_029 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_OpenSync_3000 + * @tc.name fileio_test_open_030 + * @tc.desc Function of API, flags=0o002.mode=0o070 + */ + it('fileio_test_open_030', 0, async function () { + let fpath = await nextFileName('fileio_test_open_030'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let fd = fileio.openSync(fpath, 0o002, 0o070); + expect(fd !== null).assertTrue(); + let wri = fileio.writeSync(fd, 'hello', { + encoding: 'utf-8', + offset: 1, + length: 1, + }); + expect(wri !== null).assertTrue(); + let red = fileio.readSync(fd, new ArrayBuffer(4096), { + offset: 1, + }); + expect(red !== null).assertTrue(); + fileio.closeSync(fd); + fileio.unlinkSync(fpath); + } + catch (err) { + console.info('fileio_test_open_030 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_OpenSync_3100 + * @tc.name fileio_test_open_031 + * @tc.desc Function of API, flags=0o002.mode=0o040 + */ + it('fileio_test_open_031', 0, async function () { + let fpath = await nextFileName('fileio_test_open_031'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let fd = fileio.openSync(fpath, 0o002, 0o040); + expect(fd !== null).assertTrue(); + let red = fileio.readSync(fd, new ArrayBuffer(4096), { + offset: 1, + }); + expect(red !== null).assertTrue(); + fileio.writeSync(fd, 'hello', { + encoding: 'utf-8', + offset: 1, + length: 1, + }); + throw new Error('read only'); + } + catch (err) { + console.info('fileio_test_open_031 has failed for ' + err); + fileio.unlinkSync(fpath); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_OpenSync_3200 + * @tc.name fileio_test_open_032 + * @tc.desc Function of API, flags=0o002.mode=0o020 + */ + it('fileio_test_open_032', 0, async function () { + let fpath = await nextFileName('fileio_test_open_032'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let fd = fileio.openSync(fpath, 0o002, 0o020); + expect(fd !== null).assertTrue(); + let wri = fileio.writeSync(fd, 'hello', { + encoding: 'utf-8', + offset: 1, + length: 1, + }); + expect(wri !== null).assertTrue(); + fileio.readSync(fd, new ArrayBuffer(4096), { + offset: 1, + }); + throw new Error('write only'); + } + catch (err) { + console.info('fileio_test_open_032 has failed for ' + err); + fileio.unlinkSync(fpath); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_OpenSync_3300 + * @tc.name fileio_test_open_033 + * @tc.desc Function of API, flags=0o002.mode=0o010 + */ + it('fileio_test_open_033', 0, async function () { + let fpath = await nextFileName('fileio_test_open_033'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let fd = fileio.openSync(fpath, 0o002, 0o010); + expect(fd !== null).assertTrue(); + fileio.closeSync(fd); + fileio.unlinkSync(fpath); + } + catch (err) { + console.info('fileio_test_open_033 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_OpenSync_3400 + * @tc.name fileio_test_open_034 + * @tc.desc Function of API, flags=0o002.mode=0o007 + */ + it('fileio_test_open_034', 0, async function () { + let fpath = await nextFileName('fileio_test_open_034'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let fd = fileio.openSync(fpath, 0o002, 0o007); + expect(fd !== null).assertTrue(); + let ret = fileio.readSync(fd, new ArrayBuffer(4096), { + offset: 1, + }); + expect(ret !== null).assertTrue(); + let wri = fileio.writeSync(fd, 'hello', { + encoding: 'utf-8', + offset: 1, + length: 1, + }); + expect(wri !== null).assertTrue(); + fileio.closeSync(fd); + fileio.unlinkSync(fpath); + } + catch (err) { + console.info('fileio_test_open_034 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_OpenSync_3500 + * @tc.name fileio_test_open_035 + * @tc.desc Function of API, flags=0o002.mode=0o004 + */ + it('fileio_test_open_035', 0, async function () { + let fpath = await nextFileName('fileio_test_open_035'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let fd = fileio.openSync(fpath, 0o002, 0o004); + expect(fd !== null).assertTrue(); + let ret = fileio.readSync(fd, new ArrayBuffer(4096), { + offset: 1, + }); + expect(ret !== null).assertTrue(); + fileio.writeSync(fd, 'hello', { + encoding: 'utf-8', + offset: 1, + length: 1, + }); + throw new Error('read only'); + } + catch (err) { + console.info('fileio_test_open_035 has failed for ' + err); + fileio.unlinkSync(fpath); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_OpenSync_3600 + * @tc.name fileio_test_open_036 + * @tc.desc Function of API, flags=0o002.mode=0o002 + */ + it('fileio_test_open_036', 0, async function () { + let fpath = await nextFileName('fileio_test_open_036'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let fd = fileio.openSync(fpath, 0o002, 0o002); + expect(fd !== null).assertTrue(); + let wri = fileio.writeSync(fd, 'hello', { + encoding: 'utf-8', + offset: 1, + length: 1, + }); + expect(wri !== null).assertTrue(); + fileio.readSync(fd, new ArrayBuffer(4096), { + offset: 1, + }); + throw new Error('write only'); + } + catch (err) { + console.info('fileio_test_open_036 has failed for ' + err); + fileio.unlinkSync(fpath); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_OpenSync_3700 + * @tc.name fileio_test_open_037 + * @tc.desc Function of API, flags=0o002.mode=0o001 + */ + it('fileio_test_open_037', 0, async function () { + let fpath = await nextFileName('fileio_test_open_037'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let fd = fileio.openSync(fpath, 0o002, 0o001); + fileio.closeSync(fd); + fileio.unlinkSync(fpath); + } + catch (err) { + console.info('fileio_test_open_037 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_OpenSync_3800 + * @tc.name fileio_test_open_038 + * @tc.desc Function of API, flags=0o102.mode=0o700 + */ + it('fileio_test_open_038', 0, async function () { + let txt = randomString(4100); + let fpath = await nextFileName(txt); + try { + fileio.openSync(fpath, 0o102, 0o700); + } + catch (err) { + console.info('fileio_test_open_038 has failed for ' + err); + expect(err.message == 'Filename too long').assertTrue(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_OpenSync_0100 + * @tc.name fileio_test_open_sync_001 + * @tc.desc Function of API, openSync(flags=0o200). The test file is exist. + */ + it('fileio_test_open_sync_001', 0, async function () { + let fpath = await nextFileName('fileio_test_open_sync_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let fd = fileio.openSync(fpath, 0o200); + expect(fd !== null).assertTrue(); + fileio.closeSync(fd); + fileio.unlinkSync(fpath); + } + catch (err) { + console.info('fileio_test_open_sync_001 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_OpenSync_0200 + * @tc.name fileio_test_open_sync_002 + * @tc.desc Function of API, openSync(flags=0o201). The test file is exist. + */ + it('fileio_test_open_sync_002', 0, async function () { + let fpath = await nextFileName('fileio_test_open_sync_002'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let fd = fileio.openSync(fpath, 0o201); + expect(fd !== null).assertTrue(); + fileio.closeSync(fd); + fileio.unlinkSync(fpath); + } + catch (err) { + console.info('fileio_test_open_sync_002 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_OpenSync_0300 + * @tc.name fileio_test_open_sync_003 + * @tc.desc Function of API, openSync(flags=0o202). The test file is exist. + */ + it('fileio_test_open_sync_003', 0, async function () { + let fpath = await nextFileName('fileio_test_open_sync_003'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let fd = fileio.openSync(fpath, 0o202); + expect(fd !== null).assertTrue(); + fileio.closeSync(fd); + fileio.unlinkSync(fpath); + } + catch (err) { + console.info('fileio_test_open_sync_003 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_OpenSync_0400 + * @tc.name fileio_test_open_sync_004 + * @tc.desc Function of API, openSync(flags=0o102, mode=0o777). The test file is not exist. + */ + it('fileio_test_open_sync_004', 0, async function () { + let fpath = await nextFileName('fileio_test_open_sync_004'); + try { + let fd = fileio.openSync(fpath, 0o102, 0o777); + expect(fd !== null).assertTrue(); + fileio.closeSync(fd); + fileio.unlinkSync(fpath); + } + catch (err) { + console.info('fileio_test_open_sync_004 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_OpenSync_0500 + * @tc.name fileio_test_open_sync_005 + * @tc.desc Function of API, openSync(flags not for value, mode not for value). + */ + it('fileio_test_open_sync_005', 0, async function () { + let dpath = await nextFileName('fileio_test_open_sync_005') + 'd' + try { + fileio.mkdirSync(dpath); + let fd = fileio.openSync(dpath); + expect(fd !== null).assertTrue(); + fileio.closeSync(fd); + fileio.rmdirSync(dpath); + } + catch (err) { + console.info('fileio_test_open_sync_005 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_OpenSync_0600 + * @tc.name fileio_test_open_sync_006 + * @tc.desc Function of API, openSync(flags=0o1, illegal parameter). + */ + it('fileio_test_open_sync_006', 0, async function () { + let dpath = await nextFileName('fileio_test_open_sync_006') + 'd' + try { + fileio.mkdirSync(dpath); + fileio.openSync(dpath, 0o1); + }catch (err) { + console.info('fileio_test_open_sync_006 has failed for ' + err); + expect(err.message == "Is a directory").assertTrue(); + fileio.rmdirSync(dpath); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_OpenSync_0700 + * @tc.name fileio_test_open_sync_007 + * @tc.desc Function of API, openSync(fpath too long). + */ + it('fileio_test_open_sync_007', 0, async function () { + let dpath = await nextFileName('fileio_test_open_sync_007'); + fileio.mkdirSync(dpath); + try { + for (let i = 0; i < 16; i++) { + if (i == 15) { + let fpath = dpath + '/f' + i; + fileio.openSync(fpath, 0o102, 0o777); + fileio.unlinkSync(fpath); + } else { + dpath = dpath + '/d' + i; + fileio.mkdirSync(dpath); + } + } + throw new Error('fpath too long'); + } + catch (err) { + console.info('fileio_test_open_sync_007 has failed for ' + err); + forceRemoveDir(dpath, 15); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_OpenSync_0800 + * @tc.name fileio_test_open_sync_008 + * @tc.desc Function of API, openSync(filename too long). + */ + it('fileio_test_open_sync_008', 0, async function () { + let fpath = await nextFileName(randomString(256)); + try { + fileio.openSync(fpath, 0o102, 0o777); + } + catch (err) { + console.info('fileio_test_open_sync_008 has failed for ' + err); + expect(err.message == "Filename too long").assertTrue(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_OpenSync_0900 + * @tc.name fileio_test_open_sync_009 + * @tc.desc Function of API, openSync(dir layers too long). + */ + it('fileio_test_open_sync_009', 0, async function () { + let dpath = await nextFileName('fileio_test_open_sync_009'); + fileio.mkdirSync(dpath); + try { + for (let i = 0; i < 113; i++) { + if (i == 112) { + let fpath = dpath + '/f' + i + fileio.openSync(fpath, 0o102, 0o777); + fileio.unlinkSync(fpath); + } else { + dpath = dpath + '/d' + i + fileio.mkdirSync(dpath); + } + } + throw new Error('dir layers too long'); + } + catch (err) { + console.info('fileio_test_open_sync_009 has failed for ' + err); + forceRemoveDir(dpath, 112); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_OpenSync_1000 + * @tc.name fileio_test_open_sync_010 + * @tc.desc Function of API, openSync(filename has special characters). + */ + it('fileio_test_open_sync_010', 0, async function () { + let fpath = await nextFileName('?*:<>/|'); + try { + fileio.openSync(fpath, 0o102, 0o777); + } catch (err) { + console.info('fileio_test_open_sync_010 has failed for ' + err); + expect(err.message == "No such file or directory").assertTrue(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_CloseSync_0000 + * @tc.name fileio_test_close_sync_000 + * @tc.desc Function of API, close. The test file is not exist. + */ + it('fileio_test_close_sync_000', 0, async function () { + let fpath = await nextFileName('fileio_test_chmod_sync_000'); + try { + fileio.closeSync(fpath); + } + catch (err) { + console.info('fileio_test_close_sync_000 has failed for ' + err); + expect(err.message == "Invalid fd").assertTrue(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_CloseSync_0100 + * @tc.name fileio_test_close_sync_001 + * @tc.desc Function of API, close(fpath=vaild value). The test file is not exist. + */ + it('fileio_test_close_sync_001', 0, async function () { + try { + fileio.closeSync(-1); + expect(false).assertTrue(); + } + catch (err) { + console.info('fileio_test_close_sync_001 has failed for ' + err); + expect(err.message == "Invalid fd").assertTrue(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_AccessSync_0000 + * @tc.name fileio_test_access_sync_000 + * @tc.desc Function of API,access. The test file is exist. + */ + it('fileio_test_access_sync_000', 0, async function () { + let fpath = await nextFileName('fileio_test_access_sync_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + fileio.accessSync(fpath); + fileio.unlinkSync(fpath); + } + catch (err) { + console.info('fileio_test_access_sync_000 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_AccessSync_0100 + * @tc.name fileio_test_access_sync_001 + * @tc.desc Function of API, launch via fileio. The test file is not exist. + */ + it('fileio_test_access_sync_001', 0, async function () { + try { + fileio.accessSync(1); + } catch (err) { + console.info('fileio_test_access_sync_001 has failed for ' + err); + expect(err.message == "Invalid path").assertTrue(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_AccessSync_0200 + * @tc.name fileio_test_access_sync_002 + * @tc.desc Function of API, access. The test file is not exist. + */ + it('fileio_test_access_sync_002', 0, async function () { + let fpath = await nextFileName('fileIOTest'); + try { + fileio.accessSync(fpath); + }catch (err) { + console.info('fileio_test_access_sync_002 has failed for ' + err); + expect(err.message == "No such file or directory").assertTrue(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_AccessSync_0300 + * @tc.name fileio_test_access_sync_003 + * @tc.desc Function of API, access(mode=1). The test file is exist and have the authority. + */ + it('fileio_test_access_sync_003', 0, async function () { + let fpath = await nextFileName('fileio_test_access_sync_004'); + expect(prepareEmptyFile(fpath)).assertTrue(); + try { + fileio.accessSync(fpath); + fileio.accessSync(fpath, 1); + fileio.unlinkSync(fpath); + } + catch (err) { + console.info('fileio_test_access_sync_004 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_AccessSync_0400 + * @tc.name fileio_test_access_sync_004 + * @tc.desc Function of API, access(mode=2). The test file is exist and have the authority. + */ + it('fileio_test_access_sync_004', 0, async function () { + let fpath = await nextFileName('fileio_test_access_sync_004'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + fileio.accessSync(fpath); + fileio.accessSync(fpath, 2); + fileio.unlinkSync(fpath); + } + catch (err) { + console.info('fileio_test_access_sync_004 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_AccessSync_0500 + * @tc.name fileio_test_access_sync_005 + * @tc.desc Function of API, access(fpath=dir address). The test dir is exist. + */ + it('fileio_test_access_sync_005', 0, async function () { + let dpath = await nextFileName('fileio_test_access_sync_005') + 'd' + try { + fileio.mkdirSync(dpath); + fileio.accessSync(dpath); + fileio.rmdirSync(dpath); + } + catch (err) { + console.info('fileio_test_access_sync_005 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_AccessSync_0600 + * @tc.name fileio_test_access_sync_006 + * @tc.desc Function of API, access(fpath=dir address). The test dir is not exist. + */ + it('fileio_test_access_sync_006', 0, async function () { + let dpath = await nextFileName('fileio_test_access_sync_006') + 'd' + try { + fileio.accessSync(dpath); + } + catch (err) { + console.info('fileio_test_access_sync_006 has failed for ' + err); + expect(err.message == "No such file or directory").assertTrue(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_AccessSync_0700 + * @tc.name fileio_test_access_sync_007 + * @tc.desc Function of API, access(mode=4). + */ + it('fileio_test_access_sync_007', 0, async function () { + let fpath = await nextFileName('fileio_test_access_sync_007'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + fileio.accessSync(fpath); + fileio.accessSync(fpath, 4); + fileio.unlinkSync(fpath); + } + catch (err) { + console.info('fileio_test_access_sync_007 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_Access_Promise_001 + * @tc.name fileio_test_access_promise_001 + * @tc.desc Function of API, access(mode=4). + */ + it('fileio_test_access_promise_001', 0, async function () { + let fpath = await nextFileName('fileio_test_access_promise_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + let fd = fileio.access(fpath).then(() => { + expect(fd !== null).assertTrue(); + fileio.unlinkSync(fpath); + console.info('file access Success'); + }).catch(function(err) { + console.info("file access err: " + JSON.stringify(err)); + }); + }); + + /** + * @tc.number SUB_STORAGE_FileIO_Access_Async_001 + * @tc.name fileio_test_access_async_001 + * @tc.desc Function of API, access(mode=4). + */ + it('fileio_test_access_async_001', 0, async function () { + let fpath = await nextFileName('fileio_test_access_async_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let fd = fileio.access(fpath, function (err) { + expect(fd !== null).assertTrue(); + fileio.unlinkSync(fpath); + }); + }); + + /** + * @tc.number SUB_STORAGE_FileIO_UnlinkSync_0000 + * @tc.name fileio_test_unlink_sync_000 + * @tc.desc Function of API,unlinkSync. The test file is exist. + */ + it('fileio_test_unlink_sync_000', 0, async function () { + let fpath = await nextFileName('fileio_test_unlink_sync_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + fileio.unlinkSync(fpath); + } + catch (err) { + console.info('fileio_test_unlink_sync_000 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_UnlinkSync_0100 + * @tc.name fileio_test_unlink_sync_001 + * @tc.desc Function of API, no parameter. + */ + it('fileio_test_unlink_sync_001', 0, async function () { + try { + fileio.unlinkSync(1); + } + catch (err) { + console.info('fileio_test_unlink_sync_001 has failed for ' + err); + expect(err.message == "Invalid path").assertTrue(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_UnlinkSync_0200 + * @tc.name fileio_test_unlink_sync_002 + * @tc.desc Function of API, invalid parameter + */ + it('fileio_test_unlink_sync_002', 0, async function () { + let fpath = await nextFileName('fileIOTest'); + try { + fileio.unlinkSync(fpath); + } catch (err) { + console.info('fileio_test_unlink_sync_002 has failed for ' + err); + expect(err.message == "No such file or directory").assertTrue(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_WriteSync_0000 + * @tc.name fileio_test_write_sync_000 + * @tc.desc Function of API, writeSync. + */ + it('fileio_test_write_sync_000', 0, async function () { + let fpath = await nextFileName('fileio_test_write_sync_000'); + try { + let fd = fileio.openSync(fpath, 0o102, 0o666); + let res = fileio.writeSync(fd, FILE_CONTENT); + expect(typeof(res) == 'number').assertTrue(); + fileio.closeSync(fd); + fileio.unlinkSync(fpath); + } + catch (err) { + console.info('fileio_test_write_sync_000 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_WriteSync_0100 + * @tc.name fileio_test_write_sync_001 + * @tc.desc Function of API, encoding=UTF-8. + */ + it('fileio_test_write_sync_001', 0, async function () { + let fpath = await nextFileName('fileio_test_write_sync_001'); + try { + let fd = fileio.openSync(fpath, 0o102, 0o666); + let res = fileio.writeSync(fd, FILE_CONTENT, { + encoding: 'utf-8', + }); + expect(typeof(res) == 'number').assertTrue(); + fileio.closeSync(fd); + fileio.unlinkSync(fpath); + } + catch (err) { + console.info('fileio_test_write_sync_001 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_WriteSync_0200 + * @tc.name fileio_test_write_sync_002 + * @tc.desc Function of API, offset=1. + */ + it('fileio_test_write_sync_002', 0, async function () { + let fpath = await nextFileName('fileio_test_write_sync_002'); + let text = '0123456789abcdefg'; + try { + let fd = fileio.openSync(fpath, 0o102, 0o666); + expect(fileio.writeSync(fd, text, { + offset: 1, + }) == text.length - 1).assertTrue(); + fileio.closeSync(fd); + fileio.unlinkSync(fpath); + } + catch (err) { + console.info('fileio_test_write_sync_002 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_WriteSync_0300 + * @tc.name fileio_test_write_sync_003 + * @tc.desc Function of API, length = - 1. + */ + it('fileio_test_write_sync_003', 0, async function () { + let fpath = await nextFileName('fileio_test_write_sync_003'); + try { + let fd = fileio.openSync(fpath, 0o102, 0o666); + expect(fileio.writeSync(fd, FILE_CONTENT, { + length: FILE_CONTENT.length - 1, + }) == (FILE_CONTENT.length - 1)).assertTrue(); + fileio.closeSync(fd); + fileio.unlinkSync(fpath); + } + catch (err) { + console.info('fileio_test_write_sync_003 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_WriteSync_0400 + * @tc.name fileio_test_write_sync_004 + * @tc.desc Function of API, length = 1, offset = 1. + */ + it('fileio_test_write_sync_004', 0, async function () { + let fpath = await nextFileName('fileio_test_write_sync_004'); + try { + let fd = fileio.openSync(fpath, 0o102, 0o666); + let res = fileio.writeSync(fd, FILE_CONTENT, { + offset: 1, + length: 1, + }); + expect(typeof(res) == 'number').assertTrue(); + fileio.closeSync(fd); + fileio.unlinkSync(fpath); + } + catch (err) { + console.info('fileio_test_write_sync_004 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_WriteSync_0500 + * @tc.name fileio_test_write_sync_005 + * @tc.desc Function of API, invalid offset. + */ + it('fileio_test_write_sync_005', 0, async function () { + let fpath = await nextFileName('fileio_test_write_sync_005'); + const invalidOffset = 999 + let fd + try { + fd = fileio.openSync(fpath, 0o102, 0o666); + expect(fd).assertInstanceOf('Number'); + expect(fileio.writeSync(fd, FILE_CONTENT, { + offset: invalidOffset, + }) == 1).assertTrue(); + throw new Error('invalid offset'); + } + catch (err) { + console.info('fileio_test_write_sync_005 has failed for ' + err); + fileio.closeSync(fd); + fileio.unlinkSync(fpath); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_WriteSync_0600 + * @tc.name fileio_test_write_sync_006 + * @tc.desc Function of API, invalid length. + */ + it('fileio_test_write_sync_006', 0, async function () { + let fpath = await nextFileName('fileio_test_write_sync_006'); + const invalidLength = 999 + let fd + try { + fd = fileio.openSync(fpath, 0o102, 0o666); + expect(fd).assertInstanceOf('Number'); + expect(fileio.writeSync(fd, FILE_CONTENT, { + length: invalidLength, + }) == 1); + throw new Error('invalid length'); + } + catch (err) { + console.info('fileio_test_write_sync_006 has failed for ' + err); + fileio.closeSync(fd); + fileio.unlinkSync(fpath); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_WriteSync_0700 + * @tc.name fileio_test_write_sync_007 + * @tc.desc Function of API, no parameter. + */ + it('fileio_test_write_sync_007', 0, async function () { + try { + fileio.writeSync(1, 1); + }catch (err) { + console.info('fileio_test_write_sync_007 has failed for ' + err); + expect(err.message == "Illegal write buffer or encoding").assertTrue(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_WriteSync_0800 + * @tc.name fileio_test_write_sync_008 + * @tc.desc Function of API, invalid parameter. + */ + it('fileio_test_write_sync_008', 0, async function () { + try { + fileio.writeSync(-1, FILE_CONTENT); + expect(false).assertTrue(); + } + catch (err) { + console.info('fileio_test_write_sync_008 has failed for ' + err); + expect(err.message == "Invalid fd").assertTrue(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_WriteSync_0900 + * @tc.name fileio_test_write_sync_009 + * @tc.desc Function of API, Set all parameters. + */ + it('fileio_test_write_sync_009', 0, async function () { + let fpath = await nextFileName('fileio_test_write_sync_009'); + try { + let fd = fileio.openSync(fpath, 0o102, 0o666); + let res = fileio.writeSync(fd, FILE_CONTENT, { + encoding: 'utf-8', + position: 0, + offset: 1, + length: 1, + }); + expect(typeof(res) == 'number').assertTrue(); + fileio.closeSync(fd); + fileio.unlinkSync(fpath); + } + catch (err) { + console.info('fileio_test_write_sync_009 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_WriteSync_1000 + * @tc.name fileio_test_write_sync_010 + * @tc.desc Function of API, encoding=gb2312. + */ + it('fileio_test_write_sync_010', 0, async function () { + let fpath = await nextFileName('fileio_test_write_sync_010'); + let fd = fileio.openSync(fpath, 0o102, 0o666); + try { + fileio.writeSync(fd, FILE_CONTENT, { + encoding: 'gb2312', + }); + }catch (err) { + console.info('fileio_test_write_sync_010 has failed for ' + err); + expect(err.message == "Illegal write buffer or encoding").assertTrue(); + fileio.closeSync(fd); + fileio.unlinkSync(fpath); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_ReadSync_0100 + * @tc.name fileio_test_read_sync_001 + * @tc.desc Function of API, offset = 1. + */ + it('fileio_test_read_sync_001', 0, async function () { + let bufLen = 5 + expect(FILE_CONTENT.length > bufLen).assertTrue(); + let fpath = await nextFileName('fileio_test_read_sync_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let fd = fileio.openSync(fpath, 0o2); + let len = fileio.readSync(fd, new ArrayBuffer(bufLen), { + offset: 1, + }); + expect(len == bufLen - 1).assertTrue(); + fileio.closeSync(fd); + fileio.unlinkSync(fpath); + } + catch (err) { + console.info('fileio_test_read_sync_001 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_ReadSync_0200 + * @tc.name fileio_test_read_sync_002 + * @tc.desc Function of API, length = 1. + */ + it('fileio_test_read_sync_002', 0, async function () { + let fpath = await nextFileName('fileio_test_read_sync_002'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let fd = fileio.openSync(fpath, 0o2); + let len = fileio.readSync(fd, new ArrayBuffer(4096), { + length: 1, + }); + expect(len == 1).assertTrue(); + fileio.closeSync(fd); + fileio.unlinkSync(fpath); + } + catch (err) { + console.info('fileio_test_read_sync_002 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_ReadSync_0300 + * @tc.name fileio_test_read_sync_003 + * @tc.desc Function of API, invalid offset + */ + it('fileio_test_read_sync_003', 0, async function () { + let fd + const invalidOffset = 99999 + let fpath = await nextFileName('fileio_test_read_sync_003'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + fd = fileio.openSync(fpath, 0o2); + fileio.readSync(fd, new ArrayBuffer(4096), { + offset: invalidOffset, + }); + }catch (err) { + fileio.closeSync(fd); + fileio.unlinkSync(fpath); + console.info('fileio_test_read_sync_003 has failed for ' + err); + expect(err.message == "Invalid option.offset, buffer limit exceeded").assertTrue(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_ReadSync_0300 + * @tc.name fileio_test_read_sync_004 + * @tc.desc Function of API, invalid length. + */ + it('fileio_test_read_sync_004', 0, async function () { + let fd + const invalidLength = 9999 + let fpath = await nextFileName('fileio_test_read_sync_004'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + fd = fileio.openSync(fpath, 0o2); + fileio.readSync(fd, new ArrayBuffer(4096), { + length: invalidLength, + }); + }catch (err) { + fileio.closeSync(fd); + fileio.unlinkSync(fpath); + console.info('fileio_test_read_sync_004 has failed for ' + err); + expect(err.message == "Invalid option.length").assertTrue(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_ReadSync_0500 + * @tc.name fileio_test_read_sync_005 + * @tc.desc Function of API, fpatch = -1. + */ + it('fileio_test_read_sync_005', 0, async function () { + try { + fileio.readSync(-1, new ArrayBuffer(4096)); + } + catch (err) { + console.info('fileio_test_read_sync_005 has failed for ' + err); + expect(err.message == "Invalid fd").assertTrue(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_ReadSync_0600 + * @tc.name fileio_test_read_sync_006 + * @tc.desc Function of API, offset & length & position = 1. + */ + it('fileio_test_read_sync_006', 0, async function () { + let fpath = await nextFileName('fileio_test_read_sync_006'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let fd = fileio.openSync(fpath, 0o2); + let len = fileio.readSync(fd, new ArrayBuffer(4096), { + position: 1, + }); + expect(len == FILE_CONTENT.length - 1); + fileio.closeSync(fd); + fileio.unlinkSync(fpath); + } + catch (err) { + console.info('fileio_test_read_sync_006 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_ReadSync_0700 + * @tc.name fileio_test_read_sync_007 + * @tc.desc Function of API, invalid position. + */ + it('fileio_test_read_sync_007', 0, async function () { + let fpath = await nextFileName('fileio_test_read_sync_007'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let fd = fileio.openSync(fpath, 0o2); + let invalidPos = FILE_CONTENT.length; + let len = fileio.readSync(fd, new ArrayBuffer(4096), { + position: invalidPos, + }); + fileio.closeSync(fd); + fileio.unlinkSync(fpath); + } + catch (err) { + console.info('fileio_test_read_sync_007 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_ReadSync_0800 + * @tc.name fileio_test_read_sync_008 + * @tc.desc Function of API, Enter all parameters correctly. + */ + it('fileio_test_read_sync_008', 0, async function () { + let fpath = await nextFileName('fileio_test_read_sync_008'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let fd = fileio.openSync(fpath, 0o2); + let len = fileio.readSync(fd, new ArrayBuffer(4096), { + position: 1, + offset: 1, + length: 1, + }); + expect(len == 1).assertTrue(); + fileio.closeSync(fd); + fileio.unlinkSync(fpath); + } + catch (err) { + console.info('fileio_test_read_sync_008 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_ReadSync_0900 + * @tc.name fileio_test_read_sync_009 + * @tc.desc Function of API, Set offset and length. + */ + it('fileio_test_read_sync_009', 0, async function () { + let fpath = await nextFileName('fileio_test_read_sync_009'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let fd = fileio.openSync(fpath, 0o2); + let len = fileio.readSync(fd, new ArrayBuffer(4096), { + offset: 1, + length: 1, + }); + expect(len == 1).assertTrue(); + fileio.closeSync(fd); + fileio.unlinkSync(fpath); + } + catch (err) { + console.info('fileio_test_read_sync_009 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_ReadSync_1000 + * @tc.name fileio_test_read_sync_010 + * @tc.desc Function of API, Set error parameters (options). + */ + it('fileio_test_read_sync_010', 0, async function () { + let fpath = await nextFileName('fileio_test_read_sync_010'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let fd; + try { + fd = fileio.openSync(fpath, 0o2); + fileio.readSync(fd, new ArrayBuffer(4096), { + offset: -1, + length: 1, + }); + }catch (err) { + console.info('fileio_test_read_sync_010 has failed for ' + err); + expect(err.message == "Invalid option.offset, positive integer is desired").assertTrue(); + fileio.closeSync(fd); + fileio.unlinkSync(fpath); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_ChmodSync_0000 + * @tc.name fileio_test_chmod_sync_000 + * @tc.desc Function of API, mode=0o660 + */ + it('fileio_test_chmod_sync_000', 0, async function () { + let fpath = await nextFileName('fileio_test_chmod_sync_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + expect(fileio.chmodSync(fpath, 0o660) !== null).assertTrue(); + expect((fileio.statSync(fpath).mode & 0o777) == 0o660).assertTrue(); + fileio.unlinkSync(fpath); + } + catch (err) { + console.info('fileio_test_chmod_sync_000 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_ChmodSync_0100 + * @tc.name fileio_test_chmod_sync_001 + * @tc.desc Function of API, mode=0o460 + */ + it('fileio_test_chmod_sync_001', 0, async function () { + let fpath = await nextFileName('fileio_test_chmod_sync_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + expect(fileio.chmodSync(fpath, 0o460) !== null).assertTrue(); + expect((fileio.statSync(fpath).mode & 0o777) == 0o460).assertTrue(); + fileio.unlinkSync(fpath); + } + catch (err) { + console.info('fileio_test_chmod_sync_001 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_ChmodSync_0200 + * @tc.name fileio_test_chmod_sync_002 + * @tc.desc Function of API, mode=0o260. The test file is exist. + */ + it('fileio_test_chmod_sync_002', 0, async function () { + let fpath = await nextFileName('fileio_test_chmod_sync_002'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + expect(fileio.chmodSync(fpath, 0o260) !== null).assertTrue(); + expect((fileio.statSync(fpath).mode & 0o777) == 0o260).assertTrue(); + fileio.unlinkSync(fpath); + } + catch (err) { + console.info('fileio_test_chmod_sync_002 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_ChmodSync_0300 + * @tc.name fileio_test_chmod_sync_003 + * @tc.desc Function of API, chmodSync. The test file is not exist. + */ + it('fileio_test_chmod_sync_003', 0, async function () { + let fpath = await nextFileName('fileio_test_chmod_sync_003'); + try { + fileio.chmodSync(fpath, 0o260); + }catch (err) { + console.info('fileio_test_chmod_sync_003 has failed for ' + err); + expect(err.message == "No such file or directory").assertTrue(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_ChmodSync_0400 + * @tc.name fileio_test_chmod_sync_004 + * @tc.desc Function of API, fpatch=dir address. The test dir is exist. + */ + it('fileio_test_chmod_sync_004', 0, async function () { + let dpath = await nextFileName('fileio_test_chmod_sync_004'); + try { + fileio.mkdirSync(dpath, 0o777); + expect(fileio.chmodSync(dpath, 0o660) !== null).assertTrue(); + expect((fileio.statSync(dpath).mode & 0o777) == 0o660).assertTrue(); + fileio.rmdirSync(dpath); + } + catch (err) { + console.info('fileio_test_chmod_sync_000 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_ChmodSync_0500 + * @tc.name fileio_test_chmod_sync_005 + * @tc.desc Function of API, fpatch=dir address. The test dir is not exist. + */ + it('fileio_test_chmod_sync_005', 0, async function () { + let dpath; + try { + fileio.chmodSync(dpath, 0o660); + } catch (err) { + console.info('fileio_test_chmod_sync_005 has failed for ' + err); + expect(err.message == "Invalid path").assertTrue(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_ChmodSync_0600 + * @tc.name fileio_test_chmod_sync_006 + * @tc.desc Function of API, mode=0o700. The test file is exist. + */ + it('fileio_test_chmod_sync_006', 0, async function () { + let fpath = await nextFileName('fileio_test_chmod_sync_006'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + expect(fileio.chmodSync(fpath, 0o700) !== null).assertTrue(); + expect((fileio.statSync(fpath).mode & 0o777) == 0o700).assertTrue(); + fileio.unlinkSync(fpath); + } + catch (err) { + console.info('fileio_test_chmod_sync_006 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_ChmodSync_0700 + * @tc.name fileio_test_chmod_sync_007 + * @tc.desc Function of API, mode=0o400. The test file is exist. + */ + it('fileio_test_chmod_sync_007', 0, async function () { + let fpath = await nextFileName('fileio_test_chmod_sync_007'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + expect(fileio.chmodSync(fpath, 0o400) !== null).assertTrue(); + expect((fileio.statSync(fpath).mode & 0o777) == 0o400).assertTrue(); + fileio.unlinkSync(fpath); + } + catch (err) { + console.info('fileio_test_chmod_sync_002 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_ChmodSync_0800 + * @tc.name fileio_test_chmod_sync_008 + * @tc.desc Function of API, mode=0o200. The test file is exist. + */ + it('fileio_test_chmod_sync_008', 0, async function () { + let fpath = await nextFileName('fileio_test_chmod_sync_008'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + expect(fileio.chmodSync(fpath, 0o200) !== null).assertTrue(); + expect((fileio.statSync(fpath).mode & 0o777) == 0o200).assertTrue(); + fileio.unlinkSync(fpath); + } + catch (err) { + console.info('fileio_test_chmod_sync_008 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_ChmodSync_0900 + * @tc.name fileio_test_chmod_sync_009 + * @tc.desc Function of API, mode=0o100. The test file is exist. + */ + it('fileio_test_chmod_sync_009', 0, async function () { + let fpath = await nextFileName('fileio_test_chmod_sync_009'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + expect(fileio.chmodSync(fpath, 0o100) !== null).assertTrue(); + expect((fileio.statSync(fpath).mode & 0o777) == 0o100).assertTrue(); + fileio.unlinkSync(fpath); + } + catch (err) { + console.info('fileio_test_chmod_sync_009 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_ChmodSync_0100 + * @tc.name fileio_test_chmod_sync_010 + * @tc.desc Function of API, mode=0o070. The test file is exist. + */ + it('fileio_test_chmod_sync_010', 0, async function () { + let fpath = await nextFileName('fileio_test_chmod_sync_010'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + expect(fileio.chmodSync(fpath, 0o070) !== null).assertTrue(); + expect((fileio.statSync(fpath).mode & 0o777) == 0o070).assertTrue(); + fileio.unlinkSync(fpath); + } + catch (err) { + console.info('fileio_test_chmod_sync_010 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_ChmodSync_0110 + * @tc.name fileio_test_chmod_sync_011 + * @tc.desc Function of API, mode=0o040. The test file is exist. + */ + it('fileio_test_chmod_sync_011', 0, async function () { + let fpath = await nextFileName('fileio_test_chmod_sync_011'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + expect(fileio.chmodSync(fpath, 0o040) !== null).assertTrue(); + expect((fileio.statSync(fpath).mode & 0o777) == 0o040).assertTrue(); + fileio.unlinkSync(fpath); + } + catch (err) { + console.info('fileio_test_chmod_sync_011 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_ChmodSync_0120 + * @tc.name fileio_test_chmod_sync_012 + * @tc.desc Function of API, mode=0o020. The test file is exist. + */ + it('fileio_test_chmod_sync_012', 0, async function () { + let fpath = await nextFileName('fileio_test_chmod_sync_012'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + expect(fileio.chmodSync(fpath, 0o020) !== null).assertTrue(); + expect((fileio.statSync(fpath).mode & 0o777) == 0o020).assertTrue(); + fileio.unlinkSync(fpath); + } + catch (err) { + console.info('fileio_test_chmod_sync_012 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_ChmodSync_0130 + * @tc.name fileio_test_chmod_sync_013 + * @tc.desc Function of API, mode=0o010. The test file is exist. + */ + it('fileio_test_chmod_sync_013', 0, async function () { + let fpath = await nextFileName('fileio_test_chmod_sync_013'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + expect(fileio.chmodSync(fpath, 0o010) !== null).assertTrue(); + expect((fileio.statSync(fpath).mode & 0o777) == 0o010).assertTrue(); + fileio.unlinkSync(fpath); + } + catch (err) { + console.info('fileio_test_chmod_sync_013 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_ChmodSync_0140 + * @tc.name fileio_test_chmod_sync_014 + * @tc.desc Function of API, mode=0o007. The test file is exist. + */ + it('fileio_test_chmod_sync_014', 0, async function () { + let fpath = await nextFileName('fileio_test_chmod_sync_014'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + expect(fileio.chmodSync(fpath, 0o007) !== null).assertTrue(); + expect((fileio.statSync(fpath).mode & 0o777) == 0o007).assertTrue(); + fileio.unlinkSync(fpath); + } + catch (err) { + console.info('fileio_test_chmod_sync_014 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_ChmodSync_0150 + * @tc.name fileio_test_chmod_sync_015 + * @tc.desc Function of API, mode=0o700. The test file is exist. + */ + it('fileio_test_chmod_sync_015', 0, async function () { + let fpath = await nextFileName('fileio_test_chmod_sync_015'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + expect(fileio.chmodSync(fpath, 0o004) !== null).assertTrue(); + expect((fileio.statSync(fpath).mode & 0o777) == 0o004).assertTrue(); + fileio.unlinkSync(fpath); + } + catch (err) { + console.info('fileio_test_chmod_sync_015 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_ChmodSync_0160 + * @tc.name fileio_test_chmod_sync_016 + * @tc.desc Function of API, mode=0o002. The test file is exist. + */ + it('fileio_test_chmod_sync_016', 0, async function () { + let fpath = await nextFileName('fileio_test_chmod_sync_016'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + expect(fileio.chmodSync(fpath, 0o002) !== null).assertTrue(); + expect((fileio.statSync(fpath).mode & 0o777) == 0o002).assertTrue(); + fileio.unlinkSync(fpath); + } + catch (err) { + console.info('fileio_test_chmod_sync_016 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_ChmodSync_0170 + * @tc.name fileio_test_chmod_sync_017 + * @tc.desc Function of API, mode=0o001. The test file is exist. + */ + it('fileio_test_chmod_sync_017', 0, async function () { + let fpath = await nextFileName('fileio_test_chmod_sync_017'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + expect(fileio.chmodSync(fpath, 0o001) !== null).assertTrue(); + expect((fileio.statSync(fpath).mode & 0o777) == 0o001).assertTrue(); + fileio.unlinkSync(fpath); + } + catch (err) { + console.info('fileio_test_chmod_sync_017 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_copyFileSync_0000 + * @tc.name fileio_test_copy_file_sync_000 + * @tc.desc Function of API, copy. fpatch is vaild, fpathTarget is vaild, same path, file not same. + */ + it('fileio_test_copy_file_sync_000', 0, async function () { + let fpath = await nextFileName('fileio_test_copy_file_sync_000'); + let fpathTarget = fpath + 'tgt' + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + fileio.copyFileSync(fpath, fpathTarget); + fileio.unlinkSync(fpath); + fileio.unlinkSync(fpathTarget); + } + catch (err) { + console.info('fileio_test_copy_file_sync_000 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_copyFileSync_0100 + * @tc.name fileio_test_copy_file_sync_001 + * @tc.desc Function of API, copy. fpatch is invalid, fpathTarget is vaild, same path, file not same. + */ + it('fileio_test_copy_file_sync_001', 0, async function () { + let fpath = await nextFileName('fileio_test_copy_file_sync_001') + 'd' + let fpathTarget = fpath + 'tgt' + try { + fileio.copyFileSync(fpath, fpathTarget); + }catch (err) { + console.info('fileio_test_copy_file_sync_001 has failed for ' + err); + expect(err.message == "No such file or directory").assertTrue(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_copyFileSync_0200 + * @tc.name fileio_test_copy_file_sync_002 + * @tc.desc Function of API, copyFileSync. fpath is vaild, fpathTarget is invalid. + */ + it('fileio_test_copy_file_sync_002', 0, async function () { + let fpath = await nextFileName('fileio_test_copy_file_sync_002'); + try { + fileio.copyFileSync(fpath, 0); + } + catch (err) { + console.info('fileio_test_copy_file_sync_002 has failed for ' + err); + expect(err.message == "The first/second argument requires filepath/fd").assertTrue(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_copyFileSync_0300 + * @tc.name fileio_test_copy_file_sync_003 + * @tc.desc Function of API, copy. fpatch is vaild, fpathTarget is vaild, path not same, file not same. + */ + it('fileio_test_copy_file_sync_003', 0, async function () { + let fpath = await nextFileName('fileio_test_copy_file_sync_003'); + let fpathTarget = fpath + 'f1' + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + fileio.copyFileSync(fpath, fpathTarget); + fileio.unlinkSync(fpath); + fileio.unlinkSync(fpathTarget); + } + catch (err) { + console.info('fileio_test_copy_file_sync_003 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_copyFileSync_0400 + * @tc.name fileio_test_copy_file_sync_004 + * @tc.desc Function of API, copy. fpatch is vaild, fpathTarget is vaild, path not same, file not same. + */ + it('fileio_test_copy_file_sync_004', 0, async function () { + let fpath = await nextFileName('fileio_test_copy_file_sync_004'); + let fpathTarget = await fileName('fileio_test_copy_file_sync_004'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + fileio.copyFileSync(fpath, fpathTarget); + fileio.unlinkSync(fpath); + fileio.unlinkSync(fpathTarget); + } + catch (err) { + console.info('fileio_test_copy_file_sync_004 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_copyFileSync_0500 + * @tc.name fileio_test_copy_file_sync_005 + * @tc.desc Function of API, copy. fpatch is vaild, fpathTarget is vaild, path not same, file not same. + */ + it('fileio_test_copy_file_sync_005', 0, async function () { + let fpath = await nextFileName('fileio_test_copy_file_sync_005'); + let fpathTarget = fpath + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + fileio.copyFileSync(fpath, fpathTarget); + fileio.unlinkSync(fpath); + } + catch (err) { + console.info('fileio_test_copy_file_sync_005 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_copyFileSync_0600 + * @tc.name fileio_test_copy_file_sync_006 + * @tc.desc Function of API, copy.When missing parameters. + */ + it('fileio_test_copy_file_sync_006', 0, async function () { + let fpath = await nextFileName('fileio_test_copy_file_sync_006'); + try { + fileio.copyFileSync(fpath); + }catch (err) { + console.info('fileio_test_copy_file_sync_006 has failed for ' + err); + expect(err.message == "Number of arguments unmatched").assertTrue(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_copyFileSync_0700 + * @tc.name fileio_test_copy_file_sync_007 + * @tc.desc Function of API, copy. fpatch is invalid, fpathTarget is invalid. + */ + it('fileio_test_copy_file_sync_007', 0, async function () { + try { + fileio.copyFileSync(-1, -1); + } catch (err) { + console.info('fileio_test_copy_file_sync_007 has failed for ' + err); + expect(err.message == "The first/second argument requires filepath/fd").assertTrue(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_copyFileSync_0800 + * @tc.name fileio_test_copy_file_sync_008 + * @tc.desc Function of API, parameter more than 4096. + */ + it('fileio_test_copy_file_sync_008', 0, async function () { + let fpath = await nextFileName('fileio_test_copy_file_sync_008'); + fileio.openSync(fpath, 0o102, 0o777); + let dpath = await nextFileName('fileio_test_copy_file_sync_008') + 'd'; + fileio.mkdirSync(dpath); + try { + for (let i = 0; i < 16; i++) { + if (i == 15) { + let fpathTarget = dpath + '/f' + i; + fileio.copyFileSync(fpath, fpathTarget); + fileio.unlinkSync(fpath); + fileio.unlinkSync(fpathTarget); + } else { + dpath = dpath + '/d' + i; + fileio.mkdirSync(dpath); + } + } + throw new Error('parameter more than 4096'); + } + catch (err) { + console.info('fileio_test_copy_file_sync_008 has failed for ' + err); + forceRemoveDir(dpath, 15); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_copyFileSync_0900 + * @tc.name fileio_test_copy_file_sync_009 + * @tc.desc Function of API, filename is too long. + */ + it('fileio_test_copy_file_sync_009', 0, async function () { + let fpath = await nextFileName('fileio_test_copy_file_sync_009'); + fileio.openSync(fpath, 0o102, 0o777); + let fpathTarget = await nextFileName(randomString(256)); + try { + fileio.copyFileSync(fpath, fpathTarget); + } + catch (err) { + fileio.unlinkSync(fpath); + console.info('fileio_test_copy_file_sync_009 has failed for ' + err); + expect(err.message == 'Filename too long').assertTrue(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_copyFileSync_1000 + * @tc.name fileio_test_copy_file_sync_010 + * @tc.desc Function of API, dir layers too long + */ + it('fileio_test_copy_file_sync_010', 0, async function () { + let fpath = await nextFileName('fileio_test_copy_file_sync_010'); + fileio.openSync(fpath, 0o102, 0o777); + let dpath = await nextFileName('fileio_test_copy_file_sync_010') + 'd'; + fileio.mkdirSync(dpath); + try { + for (let i = 0; i < 113; i++) { + if (i == 112) { + let fpathTarget = dpath + '/f' + i + fileio.copyFileSync(fpath, fpathTarget); + fileio.unlinkSync(fpath); + fileio.unlinkSync(fpathTarget); + } else { + dpath = dpath + '/d' + i + fileio.mkdirSync(dpath); + } + } + throw new Error('dir layers too long'); + } + catch (err) { + console.info('fileio_test_copy_file_sync_010 has failed for ' + err); + forceRemoveDir(dpath, 112); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_copyFileSync_1100 + * @tc.name fileio_test_copy_file_sync_011 + * @tc.desc Function of API, special parameter. + */ + it('fileio_test_copy_file_sync_011', 0, async function () { + let fpath = await nextFileName('fileio_test_copy_file_sync_011'); + fileio.openSync(fpath, 0o102, 0o777); + let fpathTarget = await nextFileName('?*:<>/|'); + try { + fileio.copyFileSync(fpath, fpathTarget); + } + catch (err) { + fileio.unlinkSync(fpath); + console.info('fileio_test_copy_file_sync_011 has failed for ' + err); + expect(err.message == "No such file or directory").assertTrue(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_copyFileSync_1200 + * @tc.name fileio_test_copy_file_sync_012 + * @tc.desc Function of API, copy. fpatch is vaild, fpathTarget is vaild, same path, file not same, mode is 0. + */ + it('fileio_test_copy_file_sync_012', 0, async function () { + let fpath = await nextFileName('fileio_test_copy_file_sync_012'); + let fpathTarget = fpath + 'tgt' + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + fileio.copyFileSync(fpath, fpathTarget, 0); + fileio.unlinkSync(fpath); + fileio.unlinkSync(fpathTarget); + } + catch (err) { + console.info('fileio_test_copy_file_sync_012 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_copyFileSync_1200 + * @tc.name fileio_test_copy_file_async_001 + * @tc.desc Function of API, copy. fpatch is vaild, fpathTarget is vaild, same path, file not same, mode is 0. + */ + it('fileio_test_copy_file_async_001', 0, async function () { + let fpath = await nextFileName('fileio_test_copy_file_async_001'); + let fpathTarget = fpath + 'tgt' + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + await fileio.copyFile(fpath, fpathTarget).then(()=> { + fileio.unlinkSync(fpath); + expect(fileio.unlinkSync(fpathTarget) !== null).assertTrue(); + console.info('fileio_test_copy_file_async_001 Success'); + }).catch((err) => { + console.info("fileio_test_copy_file_async_001 err: " + JSON.stringify(err)); + }); + }); + + /** + * @tc.number SUB_STORAGE_FileIO_truncateSync_0000 + * @tc.name fileio_test_truncate_sync_000 + * @tc.desc Function of API, truncateSync. + */ + it('fileio_test_truncate_sync_000', 0, async function () { + let fpath = await nextFileName('fileio_test_truncate_sync_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + expect(fileio.truncateSync(fpath, 10) !== null).assertTrue(); + expect(fileio.statSync(fpath).size == 10).assertTrue(); + fileio.unlinkSync(fpath); + } + catch (err) { + console.info('fileio_test_truncate_sync_000 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_truncateSync_0100 + * @tc.name fileio_test_truncate_sync_001 + * @tc.desc Function of API, no value for parameter. + */ + it('fileio_test_truncate_sync_001', 0, async function () { + try { + fileio.truncateSync(); + }catch (err) { + console.info('fileio_test_truncate_sync_001 has failed for ' + err); + expect(err.message == "Number of arguments unmatched").assertTrue(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_truncateSync_0200 + * @tc.name fileio_test_truncate_sync_002 + * @tc.desc Function of API, no invalid parameter. + */ + it('fileio_test_truncate_sync_002', 0, async function () { + let fpath = await nextFileName('fileio_test_truncate_sync_001'); + try { + fileio.truncateSync(fpath); + }catch (err) { + console.info('fileio_test_truncate_sync_002 has failed for ' + err); + expect(err.message == "No such file or directory").assertTrue(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_truncateSync_0300 + * @tc.name fileio_test_truncate_sync_003 + * @tc.desc Function of API, . + */ + it('fileio_test_truncate_sync_003', 0, async function () { + let fpath = await nextFileName('fileio_test_truncate_sync_003'); + try { + fileio.truncateSync(fpath, -1); + }catch (err) { + console.info('fileio_test_truncate_sync_003 has failed for ' + err); + expect(err.message == "Invalid argument").assertTrue(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_RenameSync_0000 + * @tc.name fileio_test_rename_sync_000 + * @tc.desc Function of API, renameSync. The test file is exist, + * fpathTarget is not same with fpatch, file name are same. + */ + it('fileio_test_rename_sync_000', 0, async function () { + let fpath = await nextFileName('fileio_test_rename_sync_000'); + let fpathTarget = fpath + 'tgt' + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + fileio.renameSync(fpath, fpathTarget); + fileio.accessSync(fpathTarget); + fileio.unlinkSync(fpathTarget); + } + catch (err) { + console.info('fileio_test_rename_sync_000 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_RenameSync_0100 + * @tc.name fileio_test_rename_sync_001 + * @tc.desc Function of API, renameSync. The test file is not exist, + * fpathTarget is not same with fpatch, file name are same. + */ + it('fileio_test_rename_sync_001', 0, async function () { + let fpath = await nextFileName('fileio_test_rename_sync_001'); + let fpathTarget = fpath + 'tgt' + try { + fileio.renameSync(fpath, fpathTarget); + }catch (err) { + console.info('fileio_test_rename_sync_001 has failed for ' + err); + expect(err.message == "No such file or directory").assertTrue(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_RenameSync_0200 + * @tc.name fileio_test_rename_sync_002 + * @tc.desc Function of API, renameSync. The test file is exist, fpathTarget is invalid. + */ + it('fileio_test_rename_sync_002', 0, async function () { + let fpath = await nextFileName('fileio_test_rename_sync_002'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + fileio.renameSync(fpath, '/'); + }catch (err) { + fileio.unlinkSync(fpath); + console.info('fileio_test_rename_sync_002 has failed for ' + err); + expect(err.message == "Cross-device link").assertTrue(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_RenameSync_0300 + * @tc.name fileio_test_rename_sync_003 + * @tc.desc Function of API, renameSync. + * The test file is not exist, fpathTarget is same with fpatch, file name are same. + */ + it('fileio_test_rename_sync_003', 0, async function () { + let fpath = await nextFileName('fileio_test_rename_sync_003'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + console.info('fileio_test_rename_sync_003 Test start'); + fileio.renameSync(fpath, fpath); + fileio.unlinkSync(fpath); + } + catch (err) { + console.info('fileio_test_rename_sync_003 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_RenameSync_0400 + * @tc.name fileio_test_rename_sync_004 + * @tc.desc Function of API, no fpath parameter. + */ + it('fileio_test_rename_sync_004', 0, async function () { + try { + fileio.renameSync(1, 1); + } + catch (err) { + console.info('fileio_test_rename_sync_004 has failed for ' + err); + expect(err.message == "Invalid src").assertTrue(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_RenameSync_0500 + * @tc.name fileio_test_rename_sync_005 + * @tc.desc Function of API, no fpathTarget parameter. + */ + it('fileio_test_rename_sync_005', 0, async function () { + let fpath = await nextFileName('fileio_test_rename_sync_005'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + fileio.renameSync(fpath, 1); + } + catch (err) { + fileio.unlinkSync(fpath); + console.info('fileio_test_rename_sync_005 has failed for ' + err); + expect(err.message == "Invalid dest").assertTrue(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_RenameSync_0600 + * @tc.name fileio_test_rename_sync_006 + * @tc.desc Function of API, rename dir. + */ + it('fileio_test_rename_sync_006', 0, async function () { + let dpath = await nextFileName('fileio_test_rename_sync_006') + 'd' + let dpathTarget = await nextFileName('fileio_test_rename_sync_006-1') + 'd' + try { + fileio.mkdirSync(dpath); + fileio.renameSync(dpath, dpathTarget); + fileio.accessSync(dpathTarget); + fileio.rmdirSync(dpathTarget); + } + catch (err) { + console.info('fileio_test_rename_sync_006 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_RenameSync_0700 + * @tc.name fileio_test_rename_sync_007 + * @tc.desc Function of API, dir not exist. The test dir is not exist. + */ + it('fileio_test_rename_sync_007', 0, async function () { + let dpath = await nextFileName('fileio_test_rename_sync_007') + 'd' + let dpathTarget = await nextFileName('fileio_test_rename_sync_007-1') + 'd' + try { + fileio.renameSync(dpath, dpathTarget); + }catch (err) { + console.info('fileio_test_rename_sync_007 has failed for ' + err); + expect(err.message == "No such file or directory").assertTrue(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_RenameSync_0800 + * @tc.name fileio_test_rename_sync_008 + * @tc.desc Function of API, fpathTarget not exist. fpathTarget not exist. + */ + it('fileio_test_rename_sync_008', 0, async function () { + let dpath = await nextFileName('fileio_test_rename_sync_008') + 'd' + let dpathTarget = '/data/accounts/account_0/appdata/aaa/bbb/fileio_test_rename_sync_008-1d' + try { + fileio.mkdirSync(dpath); + fileio.renameSync(dpath, dpathTarget); + }catch (err) { + fileio.rmdirSync(dpath); + console.info('fileio_test_rename_sync_008 has failed for ' + err); + expect(err.message == "No such file or directory").assertTrue(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_RenameSync_0900 + * @tc.name fileio_test_rename_sync_009 + * @tc.desc Function of API, fpath is same with fpathTarget. fpath is same with fpathTarget. + */ + it('fileio_test_rename_sync_009', 0, async function () { + let dpath = await nextFileName('fileio_test_rename_sync_009') + 'd' + try { + fileio.mkdirSync(dpath); + fileio.renameSync(dpath, dpath); + fileio.accessSync(dpath); + fileio.rmdirSync(dpath); + } + catch (err) { + console.info('fileio_test_rename_sync_009 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_FchmodSync_0000 + * @tc.name fileio_test_fchmod_sync_000 + * @tc.desc Function of API, fchmodSync(mode=0o660). The test file is exist. + */ + it('fileio_test_fchmod_sync_000', 0, async function () { + let fpath = await nextFileName('fileio_test_fchmod_sync_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let fd = fileio.openSync(fpath); + fileio.fchmodSync(fd, 0o660); + expect((fileio.statSync(fpath).mode & 0o777) == 0o660).assertTrue(); + fileio.unlinkSync(fpath); + } + catch (err) { + console.info('fileio_test_fchmod_sync_000 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_FchmodSync_0100 + * @tc.name fileio_test_fchmod_sync_001 + * @tc.desc Function of API, fchmodSync(mode=0o460). The test file is exist. + */ + it('fileio_test_fchmod_sync_001', 0, async function () { + let fpath = await nextFileName('fileio_test_fchmod_sync_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let fd = fileio.openSync(fpath); + fileio.fchmodSync(fd, 0o460); + expect((fileio.statSync(fpath).mode & 0o777) == 0o460).assertTrue(); + fileio.unlinkSync(fpath); + } + catch (err) { + console.info('fileio_test_fchmod_sync_001 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_FchmodSync_0200 + * @tc.name fileio_test_fchmod_sync_002 + * @tc.desc Function of API, fchmodSync(mode=0o260). The test file is exist. + */ + it('fileio_test_fchmod_sync_002', 0, async function () { + let fpath = await nextFileName('fileio_test_fchmod_sync_002'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let fd = fileio.openSync(fpath); + fileio.fchmodSync(fd, 0o260); + expect((fileio.statSync(fpath).mode & 0o777) == 0o260).assertTrue(); + fileio.unlinkSync(fpath); + } + catch (err) { + console.info('fileio_test_fchmod_sync_002 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_FchmodSync_0300 + * @tc.name fileio_test_fchmod_sync_003 + * @tc.desc Function of API, file not exist. The test file is not exist. + */ + it('fileio_test_fchmod_sync_003', 0, async function () { + let fpath = await nextFileName('fileio_test_fchmod_sync_003'); + try { + fileio.fchmodSync(fpath, 0o660); + }catch (err) { + console.info('fileio_test_fchmod_sync_003 has failed for ' + err); + expect(err.message == "Invalid fd").assertTrue(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_FchmodSync_0400 + * @tc.name fileio_test_fchmod_sync_004 + * @tc.desc Function of API, mode is invalid. The test file is exist. + */ + it('fileio_test_fchmod_sync_004', 0, async function () { + let fpath = await nextFileName('fileio_test_fchmod_sync_004'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let fd = fileio.openSync(fpath); + fileio.fchmodSync(fd, 2222222222222); + fileio.unlinkSync(fpath); + } + catch (err) { + console.info('fileio_test_fchmod_sync_004 has failed for A' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_FchmodSync_0500 + * @tc.name fileio_test_fchmod_sync_005 + * @tc.desc Function of API, fpath = dir. The test dir is exist. + */ + it('fileio_test_fchmod_sync_005', 0, async function () { + let dpath = await nextFileName('fileio_test_fchmod_sync_005') + 'd' + try { + fileio.mkdirSync(dpath, 0o777); + let fd = fileio.openSync(dpath); + console.info(fd); + fileio.fchmodSync(fd, 0o660); + fileio.rmdirSync(dpath); + } + catch (err) { + console.info('fileio_test_fchmod_sync_005 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_FchmodSync_0600 + * @tc.name fileio_test_fchmod_sync_006 + * @tc.desc Function of API, fpatch = dir. The test dir is not exist. + */ + it('fileio_test_fchmod_sync_006', 0, async function () { + let dpath; + try { + fileio.fchmodSync(dpath, 0o660); + } + catch (err) { + console.info('fileio_test_fchmod_sync_006 has failed for ' + err); + expect(err.message == "Invalid fd").assertTrue(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_FchmodSync_0700 + * @tc.name fileio_test_fchmod_sync_007 + * @tc.desc Function of API, fchmodSync(mode=0o460). The test file is exist. + */ + it('fileio_test_fchmod_sync_007', 0, async function () { + let fpath = await nextFileName('fileio_test_fchmod_sync_007'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let fd = fileio.openSync(fpath); + fileio.fchmodSync(fd, 0o700); + expect((fileio.statSync(fpath).mode & 0o777) == 0o700).assertTrue(); + fileio.unlinkSync(fpath); + } + catch (err) { + console.info('fileio_test_fchmod_sync_007 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_FchmodSync_0800 + * @tc.name fileio_test_fchmod_sync_008 + * @tc.desc Function of API, fchmodSync(mode=0o400). The test file is exist. + */ + it('fileio_test_fchmod_sync_008', 0, async function () { + let fpath = await nextFileName('fileio_test_fchmod_sync_008'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let fd = fileio.openSync(fpath); + fileio.fchmodSync(fd, 0o400); + expect((fileio.statSync(fpath).mode & 0o777) == 0o400).assertTrue(); + fileio.unlinkSync(fpath); + } + catch (err) { + console.info('fileio_test_fchmod_sync_008 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_FchmodSync_0900 + * @tc.name fileio_test_fchmod_sync_009 + * @tc.desc Function of API, fchmodSync(mode=0o200). The test file is exist. + */ + it('fileio_test_fchmod_sync_009', 0, async function () { + let fpath = await nextFileName('fileio_test_fchmod_sync_009'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let fd = fileio.openSync(fpath); + fileio.fchmodSync(fd, 0o200); + expect((fileio.statSync(fpath).mode & 0o777) == 0o200).assertTrue(); + fileio.unlinkSync(fpath); + } + catch (err) { + console.info('fileio_test_fchmod_sync_009 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_FchmodSync_0100 + * @tc.name fileio_test_fchmod_sync_010 + * @tc.desc Function of API, fchmodSync(mode=0o100). The test file is exist. + */ + it('fileio_test_fchmod_sync_010', 0, async function () { + let fpath = await nextFileName('fileio_test_fchmod_sync_010'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let fd = fileio.openSync(fpath); + fileio.fchmodSync(fd, 0o100); + expect((fileio.statSync(fpath).mode & 0o777) == 0o100).assertTrue(); + fileio.unlinkSync(fpath); + } + catch (err) { + console.info('fileio_test_fchmod_sync_010 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_FchmodSync_0110 + * @tc.name fileio_test_fchmod_sync_011 + * @tc.desc Function of API, fchmodSync(mode=0o070). The test file is exist. + */ + it('fileio_test_fchmod_sync_011', 0, async function () { + let fpath = await nextFileName('fileio_test_fchmod_sync_011'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let fd = fileio.openSync(fpath); + fileio.fchmodSync(fd, 0o070); + expect((fileio.statSync(fpath).mode & 0o777) == 0o070).assertTrue(); + fileio.unlinkSync(fpath); + } + catch (err) { + console.info('fileio_test_fchmod_sync_011 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_FchmodSync_0120 + * @tc.name fileio_test_fchmod_sync_012 + * @tc.desc Function of API, fchmodSync(mode=0o040). The test file is exist. + */ + it('fileio_test_fchmod_sync_012', 0, async function () { + let fpath = await nextFileName('fileio_test_fchmod_sync_012'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let fd = fileio.openSync(fpath); + fileio.fchmodSync(fd, 0o040); + expect((fileio.statSync(fpath).mode & 0o777) == 0o040).assertTrue(); + fileio.unlinkSync(fpath); + } + catch (err) { + console.info('fileio_test_fchmod_sync_012 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_FchmodSync_0130 + * @tc.name fileio_test_fchmod_sync_013 + * @tc.desc Function of API, fchmodSync(mode=0o020). The test file is exist. + */ + it('fileio_test_fchmod_sync_013', 0, async function () { + let fpath = await nextFileName('fileio_test_fchmod_sync_013'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let fd = fileio.openSync(fpath); + fileio.fchmodSync(fd, 0o020); + expect((fileio.statSync(fpath).mode & 0o777) == 0o020).assertTrue(); + fileio.unlinkSync(fpath); + } + catch (err) { + console.info('fileio_test_fchmod_sync_013 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_FchmodSync_0140 + * @tc.name fileio_test_fchmod_sync_014 + * @tc.desc Function of API, fchmodSync(mode=0o010). The test file is exist. + */ + it('fileio_test_fchmod_sync_014', 0, async function () { + let fpath = await nextFileName('fileio_test_fchmod_sync_014'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let fd = fileio.openSync(fpath); + fileio.fchmodSync(fd, 0o010); + expect((fileio.statSync(fpath).mode & 0o777) == 0o010).assertTrue(); + fileio.unlinkSync(fpath); + } + catch (err) { + console.info('fileio_test_fchmod_sync_014 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_FchmodSync_0150 + * @tc.name fileio_test_fchmod_sync_015 + * @tc.desc Function of API, fchmodSync(mode=0o007). The test file is exist. + */ + it('fileio_test_fchmod_sync_015', 0, async function () { + let fpath = await nextFileName('fileio_test_fchmod_sync_015'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let fd = fileio.openSync(fpath); + fileio.fchmodSync(fd, 0o007); + expect((fileio.statSync(fpath).mode & 0o777) == 0o007).assertTrue(); + fileio.unlinkSync(fpath); + } + catch (err) { + console.info('fileio_test_fchmod_sync_015 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_FchmodSync_0160 + * @tc.name fileio_test_fchmod_sync_016 + * @tc.desc Function of API, fchmodSync(mode=0o004). The test file is exist. + */ + it('fileio_test_fchmod_sync_016', 0, async function () { + let fpath = await nextFileName('fileio_test_fchmod_sync_016'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let fd = fileio.openSync(fpath); + fileio.fchmodSync(fd, 0o004); + expect((fileio.statSync(fpath).mode & 0o777) == 0o004).assertTrue(); + fileio.unlinkSync(fpath); + } + catch (err) { + console.info('fileio_test_fchmod_sync_016 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_FchmodSync_0170 + * @tc.name fileio_test_fchmod_sync_017 + * @tc.desc Function of API, fchmodSync(mode=0o002). The test file is exist. + */ + it('fileio_test_fchmod_sync_017', 0, async function () { + let fpath = await nextFileName('fileio_test_fchmod_sync_017'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let fd = fileio.openSync(fpath); + fileio.fchmodSync(fd, 0o002); + expect((fileio.statSync(fpath).mode & 0o777) == 0o002).assertTrue(); + fileio.unlinkSync(fpath); + } + catch (err) { + console.info('fileio_test_fchmod_sync_017 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_FchmodSync_0180 + * @tc.name fileio_test_fchmod_sync_018 + * @tc.desc Function of API, fchmodSync(mode=0o001). The test file is exist. + */ + it('fileio_test_fchmod_sync_018', 0, async function () { + let fpath = await nextFileName('fileio_test_fchmod_sync_018'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let fd = fileio.openSync(fpath); + fileio.fchmodSync(fd, 0o001); + expect((fileio.statSync(fpath).mode & 0o777) == 0o001).assertTrue(); + fileio.unlinkSync(fpath); + } + catch (err) { + console.info('fileio_test_fchmod_sync_018 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_FtruncateSync_0000 + * @tc.name fileio_test_ftruncate_sync_000 + * @tc.desc Function of API, ftruncateSync. The test file is exist. + */ + it('fileio_test_ftruncate_sync_000', 0, async function () { + let fpath = await nextFileName('fileio_test_ftruncate_sync_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let fd = fileio.openSync(fpath, 0o2); + fileio.ftruncateSync(fd, 10); + expect(fileio.statSync(fpath).size == 10).assertTrue(); + fileio.unlinkSync(fpath); + } + catch (err) { + console.info('fileio_test_ftruncate_sync_000 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_FtruncateSync_0100 + * @tc.name fileio_test_ftruncate_sync_001 + * @tc.desc Function of API, len not for value. The test file is exist. + */ + it('fileio_test_ftruncate_sync_001', 0, async function () { + let fpath = await nextFileName('fileio_test_ftruncate_sync_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let fd = fileio.openSync(fpath, 0o2); + fileio.ftruncateSync(fd); + fileio.closeSync(fd); + fileio.unlinkSync(fpath); + } + catch (err) { + console.info('fileio_test_ftruncate_sync_001 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_FtruncateSync_0200 + * @tc.name fileio_test_ftruncate_sync_002 + * @tc.desc Function of API, invalid parameter. The test file is not exist. + */ + it('fileio_test_ftruncate_sync_002', 0, async function () { + try { + fileio.ftruncateSync(1); + }catch (err) { + console.info('fileio_test_ftruncate_sync_002 has failed for ' + err); + expect(err.message == "Invalid argument").assertTrue(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_FtruncateSync_0300 + * @tc.name fileio_test_ftruncate_sync_003 + * @tc.desc Function of API, invalid parameter. The test file is not exist. + */ + it('fileio_test_ftruncate_sync_003', 0, async function () { + try { + fileio.ftruncateSync(-1); + }catch (err) { + console.info('fileio_test_ftruncate_sync_003 has failed for ' + err); + expect(err.message == "Invalid fd").assertTrue(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_FtruncateSync_0400 + * @tc.name fileio_test_ftruncate_sync_004 + * @tc.desc Function of API, Parameter exception(len = -1). + */ + it('fileio_test_ftruncate_sync_004', 0, async function () { + let fpath = await nextFileName('fileio_test_ftruncate_sync_004'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let fd = fileio.openSync(fpath, 0o2); + fileio.ftruncateSync(fd, -1); + }catch (err) { + console.info('fileio_test_ftruncate_sync_004 has failed for ' + err); + expect(err.message == "Invalid argument").assertTrue(); + fileio.unlinkSync(fpath); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_FsyncSync_0000 + * @tc.name fileio_test_fsync_sync_000 + * @tc.desc Function of API, fsyneSync. + */ + it('fileio_test_fsync_sync_000', 0, async function () { + let fpath = await nextFileName('fileio_test_fsync_sync_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let fd = fileio.openSync(fpath, 0o2); + expect(fileio.fsyncSync(fd) !== null).assertTrue(); + fileio.closeSync(fd); + fileio.unlinkSync(fpath); + } + catch (err) { + console.info('fileio_test_fsync_sync_000 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_FsyncSync_0100 + * @tc.name fileio_test_fsync_sync_001 + * @tc.desc Function of API, no value of parameter. + */ + it('fileio_test_fsync_sync_001', 0, async function () { + try { + fileio.fsyncSync(1); + } + catch (err) { + console.info('fileio_test_fsync_sync_001 has failed for ' + err); + expect(err.message == "Invalid argument").assertTrue(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_FsyncSync_0200 + * @tc.name fileio_test_fsync_sync_002 + * @tc.desc Function of API, invalid parameter. + */ + it('fileio_test_fsync_sync_002', 0, async function () { + try { + fileio.fsyncSync(-1); + expect(false).assertTrue(); + } + catch (err) { + console.info('fileio_test_fsync_sync_002 has failed for ' + err); + expect(err.message == "Invalid fd").assertTrue(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_MkdirSync_RmdirSync_0000 + * @tc.name fileio_test_mkdir_sync_rmdir_sync_000 + * @tc.desc Sync to mkdir and rmdir. + */ + it('fileio_test_mkdir_sync_rmdir_sync_000', 0, async function () { + let dpath = await nextFileName('fileio_test_fsync_sync_000') + 'd' + try { + fileio.mkdirSync(dpath); + fileio.rmdirSync(dpath); + } + catch (err) { + console.info('fileio_test_mkdir_sync_rmdir_sync_000 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_MkdirSync_RmdirSync_0100 + * @tc.name fileio_test_mkdir_sync_rmdir_sync_001 + * @tc.desc Sync to mkdir and rmdir. mkdirSync(mode=0o660). + */ + it('fileio_test_mkdir_sync_rmdir_sync_001', 0, async function () { + let dpath = await nextFileName('fileio_test_mkdir_sync_rmdir_sync_001') + 'd' + try { + fileio.mkdirSync(dpath, 0o660); + fileio.rmdirSync(dpath); + } + catch (err) { + console.info('fileio_test_mkdir_sync_rmdir_sync_001 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_MkdirSync_RmdirSync_0200 + * @tc.name fileio_test_mkdir_sync_rmdir_sync_002 + * @tc.desc Sync to mkdir and rmdir. mkdirSync(mode=0o460). + */ + it('fileio_test_mkdir_sync_rmdir_sync_002', 0, async function () { + let dpath = await nextFileName('fileio_test_mkdir_sync_rmdir_sync_002') + 'd' + try { + fileio.mkdirSync(dpath, 0o460); + fileio.rmdirSync(dpath); + } + catch (err) { + console.info('fileio_test_mkdir_sync_rmdir_sync_002 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_MkdirSync_RmdirSync_0300 + * @tc.name fileio_test_mkdir_sync_rmdir_sync_003 + * @tc.desc Sync to mkdir and rmdir. mkdirSync(mode=0o260). + */ + it('fileio_test_mkdir_sync_rmdir_sync_003', 0, async function () { + let dpath = await nextFileName('fileio_test_mkdir_sync_rmdir_sync_003') + 'd' + try { + fileio.mkdirSync(dpath, 0o260); + fileio.rmdirSync(dpath); + } + catch (err) { + console.info('fileio_test_mkdir_sync_rmdir_sync_003 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_MkdirSync_RmdirSync_0400 + * @tc.name fileio_test_mkdir_sync_rmdir_sync_004 + * @tc.desc Function of API, invalid parameter. The test file is not exist. + */ + it('fileio_test_mkdir_sync_rmdir_sync_004', 0, async function () { + try { + fileio.mkdirSync(1); + }catch (err) { + console.info('fileio_test_mkdir_sync_rmdir_sync_004 has failed for ' + err); + expect(err.message == "Invalid path").assertTrue(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_MkdirSync_RmdirSync_0500 + * @tc.name fileio_test_mkdir_sync_rmdir_sync_005 + * @tc.desc Function of API, invalid parameter. The test file is not exist. + */ + it('fileio_test_mkdir_sync_rmdir_sync_005', 0, async function () { + try { + fileio.mkdirSync('/', 1); + } + catch (err) { + console.info('fileio_test_mkdir_sync_rmdir_sync_005 has failed for ' + err); + expect(err.message == "File exists").assertTrue(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_MkdirSync_RmdirSync_0600 + * @tc.name fileio_test_mkdir_sync_rmdir_sync_006 + * @tc.desc Sync to mkdir and rmdir. mkdirSync(mode=0o700). + */ + it('fileio_test_mkdir_sync_rmdir_sync_006', 0, async function () { + let dpath = await nextFileName('fileio_test_mkdir_sync_rmdir_sync_006') + 'd' + try { + fileio.mkdirSync(dpath, 0o700); + fileio.rmdirSync(dpath); + } + catch (err) { + console.info('fileio_test_mkdir_sync_rmdir_sync_006 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_MkdirSync_RmdirSync_0700 + * @tc.name fileio_test_mkdir_sync_rmdir_sync_007 + * @tc.desc Sync to mkdir and rmdir. mkdirSync(mode=0o400). + */ + it('fileio_test_mkdir_sync_rmdir_sync_007', 0, async function () { + let dpath = await nextFileName('fileio_test_mkdir_sync_rmdir_sync_007') + 'd' + try { + fileio.mkdirSync(dpath, 0o400); + fileio.rmdirSync(dpath); + } + catch (err) { + console.info('fileio_test_mkdir_sync_rmdir_sync_007 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_MkdirSync_RmdirSync_0800 + * @tc.name fileio_test_mkdir_sync_rmdir_sync_008 + * @tc.desc Sync to mkdir and rmdir. mkdirSync(mode=0o200). + */ + it('fileio_test_mkdir_sync_rmdir_sync_008', 0, async function () { + let dpath = await nextFileName('fileio_test_mkdir_sync_rmdir_sync_008') + 'd' + try { + fileio.mkdirSync(dpath, 0o200); + fileio.rmdirSync(dpath); + } + catch (err) { + console.info('fileio_test_mkdir_sync_rmdir_sync_008 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_MkdirSync_RmdirSync_0900 + * @tc.name fileio_test_mkdir_sync_rmdir_sync_009 + * @tc.desc Sync to mkdir and rmdir. mkdirSync(mode=0o100). + */ + it('fileio_test_mkdir_sync_rmdir_sync_009', 0, async function () { + let dpath = await nextFileName('fileio_test_mkdir_sync_rmdir_sync_009') + 'd' + try { + fileio.mkdirSync(dpath, 0o100); + fileio.rmdirSync(dpath); + } + catch (err) { + console.info('fileio_test_mkdir_sync_rmdir_sync_009 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_MkdirSync_RmdirSync_1000 + * @tc.name fileio_test_mkdir_sync_rmdir_sync_010 + * @tc.desc Sync to mkdir and rmdir. mkdirSync(mode=0o070). + */ + it('fileio_test_mkdir_sync_rmdir_sync_010', 0, async function () { + let dpath = await nextFileName('fileio_test_mkdir_sync_rmdir_sync_010') + 'd'; + try { + fileio.mkdirSync(dpath, 0o070); + fileio.rmdirSync(dpath); + } + catch (err) { + console.info('fileio_test_mkdir_sync_rmdir_sync_010 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_MkdirSync_RmdirSync_1100 + * @tc.name fileio_test_mkdir_sync_rmdir_sync_011 + * @tc.desc Sync to mkdir and rmdir. mkdirSync(mode=0o040). + */ + it('fileio_test_mkdir_sync_rmdir_sync_011', 0, async function () { + let dpath = await nextFileName('fileio_test_mkdir_sync_rmdir_sync_011') + 'd'; + try { + fileio.mkdirSync(dpath, 0o040); + fileio.rmdirSync(dpath); + } + catch (err) { + console.info('fileio_test_mkdir_sync_rmdir_sync_011 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_MkdirSync_RmdirSync_1200 + * @tc.name fileio_test_mkdir_sync_rmdir_sync_012 + * @tc.desc Sync to mkdir and rmdir. mkdirSync(mode=0o020). + */ + it('fileio_test_mkdir_sync_rmdir_sync_012', 0, async function () { + let dpath = await nextFileName('fileio_test_mkdir_sync_rmdir_sync_012') + 'd'; + try { + fileio.mkdirSync(dpath, 0o020); + fileio.rmdirSync(dpath); + } + catch (err) { + console.info('fileio_test_mkdir_sync_rmdir_sync_012 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_MkdirSync_RmdirSync_1300 + * @tc.name fileio_test_mkdir_sync_rmdir_sync_013 + * @tc.desc Sync to mkdir and rmdir. mkdirSync(mode=0o010). + */ + it('fileio_test_mkdir_sync_rmdir_sync_013', 0, async function () { + let dpath = await nextFileName('fileio_test_mkdir_sync_rmdir_sync_013') + 'd'; + try { + fileio.mkdirSync(dpath, 0o010); + fileio.rmdirSync(dpath); + } + catch (err) { + console.info('fileio_test_mkdir_sync_rmdir_sync_013 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_MkdirSync_RmdirSync_1400 + * @tc.name fileio_test_mkdir_sync_rmdir_sync_014 + * @tc.desc Sync to mkdir and rmdir. mkdirSync(mode=0o007). + */ + it('fileio_test_mkdir_sync_rmdir_sync_014', 0, async function () { + let dpath = await nextFileName('fileio_test_mkdir_sync_rmdir_sync_014') + 'd'; + try { + fileio.mkdirSync(dpath, 0o007); + fileio.rmdirSync(dpath); + } + catch (err) { + console.info('fileio_test_mkdir_sync_rmdir_sync_014 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_MkdirSync_RmdirSync_1500 + * @tc.name fileio_test_mkdir_sync_rmdir_sync_015 + * @tc.desc Sync to mkdir and rmdir. mkdirSync(mode=0o004). + */ + it('fileio_test_mkdir_sync_rmdir_sync_015', 0, async function () { + let dpath = await nextFileName('fileio_test_mkdir_sync_rmdir_sync_015') + 'd'; + try { + fileio.mkdirSync(dpath, 0o004); + fileio.rmdirSync(dpath); + } + catch (err) { + console.info('fileio_test_mkdir_sync_rmdir_sync_015 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_MkdirSync_RmdirSync_1600 + * @tc.name fileio_test_mkdir_sync_rmdir_sync_016 + * @tc.desc Sync to mkdir and rmdir. mkdirSync(mode=0o002). + */ + it('fileio_test_mkdir_sync_rmdir_sync_016', 0, async function () { + let dpath = await nextFileName('fileio_test_mkdir_sync_rmdir_sync_016') + 'd'; + try { + fileio.mkdirSync(dpath, 0o002); + fileio.rmdirSync(dpath); + } + catch (err) { + console.info('fileio_test_mkdir_sync_rmdir_sync_016 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_MkdirSync_RmdirSync_1700 + * @tc.name fileio_test_mkdir_sync_rmdir_sync_017 + * @tc.desc Sync to mkdir and rmdir. mkdirSync(mode=0o001). + */ + it('fileio_test_mkdir_sync_rmdir_sync_017', 0, async function () { + let dpath = await nextFileName('fileio_test_mkdir_sync_rmdir_sync_017') + 'd'; + try { + fileio.mkdirSync(dpath, 0o001); + fileio.rmdirSync(dpath); + } + catch (err) { + console.info('fileio_test_mkdir_sync_rmdir_sync_017 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_FstatSync_0000 + * @tc.name fileio_test_fstat_sync_000 + * @tc.desc Function of API, fstatSync. The test file is exist. + */ + it('fileio_test_fstat_sync_000', 0, async function () { + let fpath = await nextFileName('fileio_test_fstat_sync_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let fd = fileio.openSync(fpath, 0o2); + let stat = fileio.fstatSync(fd); + expect(stat !== null).assertTrue(); + fileio.closeSync(fd); + fileio.unlinkSync(fpath); + } + catch (err) { + console.info('fileio_test_fstat_sync_000 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_FstatSync_0100 + * @tc.name fileio_test_fstat_sync_001 + * @tc.desc Function of API, fstatSync, fd = -1. The test file is not exist. + */ + it('fileio_test_fstat_sync_001', 0, async function () { + try { + fileio.fstatSync(-1); + expect(false).assertTrue(); + }catch (err) { + console.info('fileio_test_fstat_sync_001 has failed for ' + err); + expect(err.message == "Invalid fd").assertTrue(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_FstatSync_0200 + * @tc.name fileio_test_fstat_sync_002 + * @tc.desc Function of API, fstatSync, fd is string type. + */ + it('fileio_test_fstat_sync_002', 0, async function () { + try { + fileio.fstatSync(""); + }catch (err) { + console.info('fileio_test_fstat_sync_002 has failed for ' + err); + expect(err.message == "Invalid fd").assertTrue(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_FstatSync_0300 + * @tc.name fileio_test_fstat_sync_003 + * @tc.desc Function of API, fstatSync, vaild fd. The test file is exist. + */ + it('fileio_test_fstat_sync_003', 0, async function () { + let dpath = await nextFileName('fileio_test_fstat_sync_003') + 'd' + try { + fileio.mkdirSync(dpath); + let fd = fileio.openSync(dpath); + expect(fd !== null).assertTrue(); + let stat = fileio.fstatSync(fd); + expect(stat !== null).assertTrue(); + fileio.closeSync(fd); + fileio.rmdirSync(dpath); + } + catch (err) { + console.info('fileio_test_fstat_sync_003 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_ChownSync_0000 + * @tc.name fileio_test_chown_sync_000 + * @tc.desc Function of API, chownSync. The test file is exist. + */ + it('fileio_test_chown_sync_000', 0, async function () { + let fpath = await nextFileName('fileio_test_chown_sync_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let stat = fileio.statSync(fpath); + let UID = stat.uid + let GID = stat.gid + try { + expect(fileio.chownSync(fpath, UID, GID) !== null).assertTrue(); + fileio.unlinkSync(fpath); + } + catch (err) { + console.info('fileio_test_chown_sync_000 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_ChownSync_0100 + * @tc.name fileio_test_chown_sync_001 + * @tc.desc Function of API, chownSync. The test file is not exist. + */ + it('fileio_test_chown_sync_001', 0, async function () { + let fpath = await nextFileName('fileio_test_chown_sync_001'); + let fpathc = await nextFileName('fileio_test_chown_sync_001_1'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let stat = fileio.statSync(fpath); + let UID = stat.uid + let GID = stat.gid + try { + expect(fileio.chownSync(fpathc, UID, GID)); + }catch (err) { + console.info('fileio_test_chown_sync_001 has failed for ' + err); + expect(err.message == "No such file or directory").assertTrue(); + fileio.unlinkSync(fpath); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_ChownSync_0200 + * @tc.name fileio_test_chown_sync_002 + * @tc.desc Function of API, invalid fd. The test file is not exist. + */ + it('fileio_test_chown_sync_002', 0, async function () { + let fpath = await nextFileName('fileio_test_chown_sync_002'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + expect(fileio.chownSync(fpath, 0, 0)); + }catch (err) { + console.info('fileio_test_chown_sync_002 has failed for ' + err); + expect(err.message == "Operation not permitted").assertTrue(); + fileio.unlinkSync(fpath); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_FchownSync_0000 + * @tc.name fileio_test_fchown_sync_000 + * @tc.desc Function of API, fchownSync. The test file is exist. + */ + it('fileio_test_fchown_sync_000', 0, async function () { + let fpath = await nextFileName('fileio_test_fchown_sync_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let stat = fileio.statSync(fpath); + let UID = stat.uid + let GID = stat.gid + try { + let fd = fileio.openSync(fpath); + expect(fileio.fchownSync(fd, UID, GID) !== null).assertTrue(); + fileio.closeSync(fd); + fileio.unlinkSync(fpath); + } + catch (err) { + console.info('fileio_test_fchown_sync_000 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_FchownSync_0100 + * @tc.name fileio_test_fchown_sync_001 + * @tc.desc Function of API, fchownSync. The test file is not exist. + */ + it('fileio_test_fchown_sync_001', 0, async function () { + let fpath = await nextFileName('fileio_test_fchown_sync_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let stat = fileio.statSync(fpath); + let UID = stat.uid + let GID = stat.gid + try { + expect(fileio.fchownSync(-1, UID, GID)); + }catch (err) { + fileio.unlinkSync(fpath); + console.info('fileio_test_fchown_sync_001 has failed for ' + err); + expect(err.message == "Bad file descriptor").assertTrue(); + } + + }); + + /** + * @tc.number SUB_STORAGE_FileIO_FchownSync_0200 + * @tc.name fileio_test_fchown_sync_002 + * @tc.desc Function of API, fchownSync, wrong owner. The test file is exist. + */ + it('fileio_test_fchown_sync_002', 0, async function () { + let fpath = await nextFileName('fileio_test_fchown_sync_002'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let stat = fileio.statSync(fpath); + let fd; + let GID = stat.gid + try { + let fd = fileio.openSync(fpath); + fileio.fchownSync(fd, null, GID); + } + catch (err) { + fileio.unlinkSync(fpath); + console.info('fileio_test_fchown_sync_002 has failed for ' + err); + expect(err.message == "Invalid owner").assertTrue(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_FchownSync_0300 + * @tc.name fileio_test_fchown_sync_003 + * @tc.desc Function of API, fchownSync, wrong group. The test file is exist. + */ + it('fileio_test_fchown_sync_003', 0, async function () { + let fpath = await nextFileName('fileio_test_fchown_sync_003'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let stat = fileio.statSync(fpath); + let UID = stat.uid; + let fd; + try { + fd = fileio.openSync(fpath, 0o2); + expect(fileio.fchownSync(fd, UID, 0)); + } + catch (err) { + fileio.closeSync(fd); + fileio.unlinkSync(fpath); + console.info('fileio_test_fchown_sync_003 has failed for ' + err); + expect(err.message == "Operation not permitted").assertTrue(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_FchownSync_0400 + * @tc.name fileio_test_fchown_sync_004 + * @tc.desc Function of API, fchownSync, no value of fd. The test file is exist. + */ + it('fileio_test_fchown_sync_004', 0, async function () { + let fpath = await nextFileName('fileio_test_fchown_sync_004'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let stat = fileio.statSync(fpath); + let UID = stat.uid + let GID = stat.gid + let fd = null + try { + expect(fileio.fchownSync(fd, UID, GID)); + } + catch (err) { + fileio.unlinkSync(fpath); + console.info('fileio_test_fchown_sync_004 has failed for ' + err); + expect(err.message == "Invalid fd").assertTrue(); + } + + }); + + /** + * @tc.number SUB_STORAGE_FileIO_FchownSync_0500 + * @tc.name fileio_test_fchown_sync_005 + * @tc.desc Function of API, fchownSync, no value of owner. The test file is exist. + */ + it('fileio_test_fchown_sync_005', 0, async function () { + let fpath = await nextFileName('fileio_test_fchown_sync_005'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let stat = fileio.statSync(fpath); + let UID = null + let GID = stat.gid + let fd; + try { + fd = fileio.openSync(fpath); + expect(fileio.fchownSync(fd, UID, GID)); + } + catch (err) { + fileio.closeSync(fd); + fileio.unlinkSync(fpath); + console.info('fileio_test_fchown_sync_005 has failed for ' + err); + expect(err.message == "Invalid owner").assertTrue(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_FchownSync_0600 + * @tc.name fileio_test_fchown_sync_006 + * @tc.desc Function of API, fchownSync, no value of group. The test file is exist. + */ + it('fileio_test_fchown_sync_006', 0, async function () { + let fpath = await nextFileName('fileio_test_fchown_sync_006'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let stat = fileio.statSync(fpath); + let UID = stat.uid; + let fd; + try { + fd = fileio.openSync(fpath); + fileio.fchownSync(fd, UID, 0); + } + catch (err) { + fileio.closeSync(fd); + fileio.unlinkSync(fpath); + console.info('fileio_test_fchown_sync_006 has failed for ' + err); + expect(err.message == "Operation not permitted").assertTrue(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_FchownSync_0700 + * @tc.name fileio_test_fchown_sync_007 + * @tc.desc Function of API, fchownSync, no value of GID,UID. The test file is exist. + */ + it('fileio_test_fchown_sync_007', 0, async function () { + let fpath = await nextFileName('fileio_test_fchown_sync_007'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let fd; + try { + fd = fileio.openSync(fpath, 0o2); + fileio.fchownSync(fd, 0, 0); + } + catch (err) { + fileio.closeSync(fd); + fileio.unlinkSync(fpath); + console.info('fileio_test_fchown_sync_007 has failed for ' + err); + expect(err.message == "Operation not permitted").assertTrue(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_prop_write_open_read_4k_sync + * @tc.name fileio_test_prop_write_open_read_4k_sync + * @tc.desc Sync to write & open & read 4K file. + */ + it('fileio_test_prop_write_open_read_4k_sync', 0, async function () { + let fpath = await nextFileName('fileio_test_prop_write_open_read_4k_sync'); + try { + let fd = fileio.openSync(fpath, 0o102, 0o777); + expect(fd !== null).assertTrue(); + expect(fileio.writeSync(fd, randomString(4096)) !== null).assertTrue(); + fileio.closeSync(fd); + let fd1 = fileio.openSync(fpath, 0o2); + let rlen = fileio.readSync(fd1, new ArrayBuffer(4096)); + expect(rlen == 4096).assertTrue(); + fileio.closeSync(fd1); + fileio.unlinkSync(fpath); + } + catch (err) { + console.info('fileio_test_prop_write_open_read_4k_sync has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_prop_write_open_read_4k_sync + * @tc.name fileio_test_prop_copyFile_4k_sync + * @tc.desc Sync to copy 4K file. + */ + it('fileio_test_prop_copyFile_4k_sync', 0, async function () { + let fpath = await nextFileName('fileio_test_prop_copyFile_4k_sync'); + let fpath1 = await fileName('fileio_test_prop_copyFile_4k_1_sync'); + try { + let fd = fileio.openSync(fpath, 0o102, 0o777); + expect(fd !== null).assertTrue(); + expect(fileio.writeSync(fd, randomString(4096)) !== null).assertTrue(); + fileio.closeSync(fd); + fileio.copyFileSync(fpath, fpath1); + fileio.unlinkSync(fpath); + fileio.unlinkSync(fpath1); + } + catch (err) { + console.info('fileio_test_prop_copyFile_4k_sync has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_stat_async_000 + * @tc.name fileio_test_stat_async_000 + * @tc.desc obtain file propertys by stat promise + */ + it('fileio_test_stat_promise_000', 0, async function () { + let fpath = await nextFileName('fileio_test_stat_promise_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + fileio.chmodSync(fpath, 0o660); + fileio.stat(fpath).then((stat)=> { + expect((stat.mode & 0o777) == 0o660).assertTrue(); + fileio.unlinkSync(fpath); + console.info('file stat Success'); + }).catch((err) => { + console.info("file stat err: " + JSON.stringify(err)); + }); + }); + + /** + * @tc.number SUB_STORAGE_FileIO_stat_async_001 + * @tc.name fileio_test_stat_async_001 + * @tc.desc obtain file propertys by stat promise + */ + it('fileio_test_stat_promise_001', 0, async function () { + let fpath = await nextFileName('fileio_test_stat_promise_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + fileio.chmodSync(fpath, 0o777); + fileio.stat(fpath).then((stat)=> { + expect((stat.mode & 0o777) == 0o777).assertTrue(); + fileio.unlinkSync(fpath); + console.info('file stat Success'); + }).catch((err) => { + console.info("file stat err: " + JSON.stringify(err)); + }); + }); + + /** + * @tc.number SUB_STORAGE_FileIO_stat_async_002 + * @tc.name fileio_test_stat_async_002 + * @tc.desc obtain file propertys by stat promise + */ + it('fileio_test_stat_promise_002', 0, async function () { + let fpath = await nextFileName('fileio_test_stat_promise_002'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + fileio.chmodSync(fpath, 0o774); + fileio.stat(fpath).then((stat)=> { + expect((stat.mode & 0o777) == 0o774).assertTrue(); + fileio.unlinkSync(fpath); + console.info('file stat Success'); + }).catch((err) => { + console.info("file stat err: " + JSON.stringify(err)); + }); + }); + + /** + * @tc.number SUB_STORAGE_FileIO_stat_async_003 + * @tc.name fileio_test_stat_async_003 + * @tc.desc obtain file propertys by stat promise + */ + it('fileio_test_stat_promise_003', 0, async function () { + let fpath = await nextFileName('fileio_test_stat_promise_003'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + fileio.chmodSync(fpath, 0o772); + fileio.stat(fpath).then((stat)=> { + expect((stat.mode & 0o777) == 0o772).assertTrue(); + fileio.unlinkSync(fpath); + console.info('file stat Success'); + }).catch((err) => { + console.info("file stat err: " + JSON.stringify(err)); + }); + }); + + /** + * @tc.number SUB_STORAGE_FileIO_stat_async_004 + * @tc.name fileio_test_stat_async_004 + * @tc.desc obtain file propertys by stat promise + */ + it('fileio_test_stat_promise_004', 0, async function () { + let fpath = await nextFileName('fileio_test_stat_promise_004'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + fileio.chmodSync(fpath, 0o771); + fileio.stat(fpath).then((stat)=> { + expect((stat.mode & 0o777) == 0o771).assertTrue(); + fileio.unlinkSync(fpath); + console.info('file stat Success'); + }).catch((err) => { + console.info("file stat err: " + JSON.stringify(err)); + }); + }); + + /** + * @tc.number SUB_STORAGE_FileIO_stat_async_005 + * @tc.name fileio_test_stat_async_005 + * @tc.desc obtain file propertys by stat promise + */ + it('fileio_test_stat_promise_005', 0, async function () { + let fpath = await nextFileName('fileio_test_stat_promise_005'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + fileio.chmodSync(fpath, 0o770); + fileio.stat(fpath).then((stat)=> { + expect((stat.mode & 0o777) == 0o770).assertTrue(); + fileio.unlinkSync(fpath); + console.info('file stat Success'); + }).catch((err) => { + console.info("file stat err: " + JSON.stringify(err)); + }); + }); + + /** + * @tc.number SUB_STORAGE_FileIO_stat_async_006 + * @tc.name fileio_test_stat_async_006 + * @tc.desc obtain file propertys by stat promise + */ + it('fileio_test_stat_promise_006', 0, async function () { + let fpath = await nextFileName('fileio_test_stat_promise_006'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + fileio.chmodSync(fpath, 0o666); + fileio.stat(fpath).then((stat)=> { + expect((stat.mode & 0o777) == 0o666).assertTrue(); + fileio.unlinkSync(fpath); + console.info('file stat Success'); + }).catch((err) => { + console.info("file stat err: " + JSON.stringify(err)); + }); + }); + + /** + * @tc.number SUB_STORAGE_FileIO_stat_async_007 + * @tc.name fileio_test_stat_async_007 + * @tc.desc obtain file propertys by stat promise + */ + it('fileio_test_stat_promise_007', 0, async function () { + let fpath = await nextFileName('fileio_test_stat_promise_007'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + fileio.chmodSync(fpath, 0o664); + fileio.stat(fpath).then((stat)=> { + expect((stat.mode & 0o777) == 0o664).assertTrue(); + fileio.unlinkSync(fpath); + console.info('file stat Success'); + }).catch((err) => { + console.info("file stat err: " + JSON.stringify(err)); + }); + }); + + /** + * @tc.number SUB_STORAGE_FileIO_stat_async_008 + * @tc.name fileio_test_stat_async_008 + * @tc.desc obtain file propertys by stat promise + */ + it('fileio_test_stat_promise_008', 0, async function () { + let fpath = await nextFileName('fileio_test_stat_promise_008'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + fileio.chmodSync(fpath, 0o662); + fileio.stat(fpath).then((stat)=> { + expect((stat.mode & 0o777) == 0o662).assertTrue(); + fileio.unlinkSync(fpath); + console.info('file stat Success'); + }).catch((err) => { + console.info("file stat err: " + JSON.stringify(err)); + }); + }); + + /** + * @tc.number SUB_STORAGE_FileIO_stat_async_009 + * @tc.name fileio_test_stat_async_009 + * @tc.desc obtain file propertys by stat promise + */ + it('fileio_test_stat_promise_009', 0, async function () { + let fpath = await nextFileName('fileio_test_stat_promise_009'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + fileio.chmodSync(fpath, 0o661); + fileio.stat(fpath).then((stat)=> { + expect((stat.mode & 0o777) == 0o661).assertTrue(); + fileio.unlinkSync(fpath); + console.info('file stat Success'); + }).catch((err) => { + console.info("file stat err: " + JSON.stringify(err)); + }); + }); + + /** + * @tc.number SUB_STORAGE_FileIO_stat_async_010 + * @tc.name fileio_test_stat_async_010 + * @tc.desc obtain file propertys by stat promise + */ + it('fileio_test_stat_promise_010', 0, async function () { + let fpath = await nextFileName('fileio_test_stat_promise_010'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + fileio.chmodSync(fpath, 0o660); + fileio.stat(fpath).then((stat)=> { + expect((stat.mode & 0o777) == 0o660).assertTrue(); + fileio.unlinkSync(fpath); + console.info('file stat Success'); + }).catch((err) => { + console.info("file stat err: " + JSON.stringify(err)); + }); + }); + + /** + * @tc.number SUB_STORAGE_FileIO_stat_async_011 + * @tc.name fileio_test_stat_async_011 + * @tc.desc obtain file propertys by stat promise + */ + it('fileio_test_stat_promise_011', 0, async function () { + let fpath = await nextFileName('fileio_test_stat_promise_011'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + fileio.chmodSync(fpath, 0o640); + fileio.stat(fpath).then((stat)=> { + expect((stat.mode & 0o777) == 0o640).assertTrue(); + fileio.unlinkSync(fpath); + console.info('file stat Success'); + }).catch((err) => { + console.info("file stat err: " + JSON.stringify(err)); + }); + }); + + /** + * @tc.number SUB_STORAGE_FileIO_stat_async_012 + * @tc.name fileio_test_stat_async_012 + * @tc.desc obtain file propertys by stat promise + */ + it('fileio_test_stat_promise_012', 0, async function () { + let fpath = await nextFileName('fileio_test_stat_promise_012'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + fileio.chmodSync(fpath, 0o600); + fileio.stat(fpath).then((stat)=> { + expect((stat.mode & 0o777) == 0o600).assertTrue(); + fileio.unlinkSync(fpath); + console.info('file stat Success'); + }).catch((err) => { + console.info("file stat err: " + JSON.stringify(err)); + }); + }); + + /** + * @tc.number fileio_test_stat_async_013 + * @tc.name fileio_test_stat_async_013 + * @tc.desc Function of API, obtain file propertys by stat async + */ + it('fileio_test_stat_async_013', 0, async function () { + let fpath = await nextFileName('fileio_test_stat_async_013'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + fileio.chmodSync(fpath, 0o660); + fileio.stat(fpath, function (err, stat) { + expect((stat.mode & 0o777) == 0o660).assertTrue(); + fileio.unlinkSync(fpath); + }); + }); + + /** + * @tc.number fileio_test_stat_async_014 + * @tc.name fileio_test_stat_async_014 + * @tc.desc Function of API, obtain file propertys by stat async + */ + it('fileio_test_stat_async_014', 0, async function () { + let fpath = await nextFileName('fileio_test_stat_async_014'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + fileio.chmodSync(fpath, 0o777); + fileio.stat(fpath, function (err, stat) { + expect((stat.mode & 0o777) == 0o777).assertTrue(); + fileio.unlinkSync(fpath); + }); + }); + + /** + * @tc.number fileio_test_stat_async_015 + * @tc.name fileio_test_stat_async_015 + * @tc.desc Function of API, obtain file propertys by stat async + */ + it('fileio_test_stat_async_015', 0, async function () { + let fpath = await nextFileName('fileio_test_stat_async_015'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + fileio.chmodSync(fpath, 0o776); + fileio.stat(fpath, function (err, stat) { + expect((stat.mode & 0o777) == 0o776).assertTrue(); + fileio.unlinkSync(fpath); + }); + }); + + /** + * @tc.number fileio_test_stat_async_016 + * @tc.name fileio_test_stat_async_016 + * @tc.desc Function of API, obtain file propertys by stat async + */ + it('fileio_test_stat_async_016', 0, async function () { + let fpath = await nextFileName('fileio_test_stat_async_016'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + fileio.chmodSync(fpath, 0o774); + fileio.stat(fpath, function (err, stat) { + expect((stat.mode & 0o777) == 0o774).assertTrue(); + fileio.unlinkSync(fpath); + }); + }); + + /** + * @tc.number fileio_test_stat_async_017 + * @tc.name fileio_test_stat_async_017 + * @tc.desc Function of API, obtain file propertys by stat async + */ + it('fileio_test_stat_async_017', 0, async function () { + let fpath = await nextFileName('fileio_test_stat_async_017'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + fileio.chmodSync(fpath, 0o772); + fileio.stat(fpath, function (err, stat) { + expect((stat.mode & 0o777) == 0o772).assertTrue(); + fileio.unlinkSync(fpath); + }); + }); + + /** + * @tc.number fileio_test_stat_async_018 + * @tc.name fileio_test_stat_async_018 + * @tc.desc Function of API, obtain file propertys by stat async + */ + it('fileio_test_stat_async_018', 0, async function () { + let fpath = await nextFileName('fileio_test_stat_async_018'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + fileio.chmodSync(fpath, 0o771); + fileio.stat(fpath, function (err, stat) { + expect((stat.mode & 0o777) == 0o771).assertTrue(); + fileio.unlinkSync(fpath); + }); + }); + + /** + * @tc.number fileio_test_stat_async_019 + * @tc.name fileio_test_stat_async_019 + * @tc.desc Function of API, obtain file propertys by stat async + */ + it('fileio_test_stat_async_019', 0, async function () { + let fpath = await nextFileName('fileio_test_stat_async_019'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + fileio.chmodSync(fpath, 0o770); + fileio.stat(fpath, function (err, stat) { + expect((stat.mode & 0o777) == 0o770).assertTrue(); + fileio.unlinkSync(fpath); + }); + }); + + /** + * @tc.number fileio_test_stat_async_020 + * @tc.name fileio_test_stat_async_020 + * @tc.desc Function of API, obtain file propertys by stat async + */ + it('fileio_test_stat_async_020', 0, async function () { + let fpath = await nextFileName('fileio_test_stat_async_020'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + fileio.chmodSync(fpath, 0o666); + fileio.stat(fpath, function (err, stat) { + expect((stat.mode & 0o777) == 0o666).assertTrue(); + fileio.unlinkSync(fpath); + }); + }); + + /** + * @tc.number fileio_test_stat_async_021 + * @tc.name fileio_test_stat_async_021 + * @tc.desc Function of API, obtain file propertys by stat async + */ + it('fileio_test_stat_async_021', 0, async function () { + let fpath = await nextFileName('fileio_test_stat_async_021'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + fileio.chmodSync(fpath, 0o664); + fileio.stat(fpath, function (err, stat) { + expect((stat.mode & 0o777) == 0o664).assertTrue(); + fileio.unlinkSync(fpath); + }); + }); + + /** + * @tc.number fileio_test_stat_async_022 + * @tc.name fileio_test_stat_async_022 + * @tc.desc Function of API, obtain file propertys by stat async + */ + it('fileio_test_stat_async_022', 0, async function () { + let fpath = await nextFileName('fileio_test_stat_async_022'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + fileio.chmodSync(fpath, 0o662); + fileio.stat(fpath, function (err, stat) { + expect((stat.mode & 0o777) == 0o662).assertTrue(); + fileio.unlinkSync(fpath); + }); + }); + + /** + * @tc.number fileio_test_stat_async_023 + * @tc.name fileio_test_stat_async_023 + * @tc.desc Function of API, obtain file propertys by stat async + */ + it('fileio_test_stat_async_023', 0, async function () { + let fpath = await nextFileName('fileio_test_stat_async_023'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + fileio.chmodSync(fpath, 0o640); + fileio.stat(fpath, function (err, stat) { + expect((stat.mode & 0o777) == 0o640).assertTrue(); + fileio.unlinkSync(fpath); + }); + }); + + /** + * @tc.number fileio_test_stat_async_024 + * @tc.name fileio_test_stat_async_024 + * @tc.desc Function of API, obtain file propertys by stat async + */ + it('fileio_test_stat_async_024', 0, async function () { + let fpath = await nextFileName('fileio_test_stat_async_024'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + fileio.chmodSync(fpath, 0o600); + fileio.stat(fpath, function (err, stat) { + expect((stat.mode & 0o777) == 0o600).assertTrue(); + fileio.unlinkSync(fpath); + }); + }); + + /** + * @tc.number fileio_test_stat_async_025 + * @tc.name fileio_test_stat_async_025 + * @tc.desc Function of API, obtain file propertys by stat async + */ + it('fileio_test_stat_async_025', 0, async function () { + let fpath = await nextFileName('fileio_test_stat_async_025'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + fileio.chmodSync(fpath, 0o400); + fileio.stat(fpath, function (err, stat) { + expect((stat.mode & 0o777) == 0o400).assertTrue(); + fileio.unlinkSync(fpath); + }); + }); + + /** + * @tc.number fileio_test_stat_async_026 + * @tc.name fileio_test_stat_async_026 + * @tc.desc Function of API, obtain file propertys by stat async + */ + it('fileio_test_stat_async_026', 0, async function () { + let fpath = await nextFileName('fileio_test_stat_async_026'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + fileio.chmodSync(fpath, 0o200); + fileio.stat(fpath, function (err, stat) { + expect((stat.mode & 0o777) == 0o200).assertTrue(); + fileio.unlinkSync(fpath); + }); + }); + + /** + * @tc.number fileio_test_close_async_000 + * @tc.name fileio_test_close_async_000 + * @tc.desc Function of API close promise + */ + it('fileio_test_close_async_000', 0, async function () { + let fpath = await nextFileName('fileio_test_close_async_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let fd = fileio.openSync(fpath); + expect(fd !== null).assertTrue(); + await fileio.close(fd); + fileio.unlinkSync(fpath); + }); + + /** + * @tc.number fileio_test_close_async_001 + * @tc.name fileio_test_close_async_001 + * @tc.desc Function of API close + */ + it('fileio_test_close_async_001', 0, async function () { + let fpath = await nextFileName('fileio_test_close_async_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let fd = fileio.openSync(fpath); + fileio.close(fd, function (err) { + fileio.unlinkSync(fpath); + }); + }); + }); +} diff --git a/storage/storagefileiojstest/entry/src/ohosTest/js/test/FileIODir.test.js b/storage/storagefileiojstest/src/main/js/test/FileIODir.test.js similarity index 96% rename from storage/storagefileiojstest/entry/src/ohosTest/js/test/FileIODir.test.js rename to storage/storagefileiojstest/src/main/js/test/FileIODir.test.js index 7e557d6f2a54f430759a5b2d6b9a3df42d7985d1..263e65c8a5cb040ce629f64ba248823629857f81 100644 --- a/storage/storagefileiojstest/entry/src/ohosTest/js/test/FileIODir.test.js +++ b/storage/storagefileiojstest/src/main/js/test/FileIODir.test.js @@ -1,412 +1,412 @@ -/* - * Copyright (C) 2023 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 fileio from '@ohos.fileio'; -import { describe,it,expect}from '@ohos/hypium' -import { - FILE_CONTENT, - prepareFile, - nextFileName, - randomString, - forceRemoveDir -} - from './Common' - -export default function fileIOTestDir() { -describe('fileIOTestDir', function () { - - /** - * @tc.number SUB_STORAGE_FileIO_dir_OpenSync_0000 - * @tc.name fileio_test_dir_open_sync_000 - * @tc.desc Function of API, opendirSync. - */ - it('fileio_test_dir_open_sync_000', 0, async function () { - let dpath = await nextFileName('fileio_test_dir_open_sync_000') + 'd' - try { - fileio.mkdirSync(dpath); - let dd = fileio.opendirSync(dpath); - expect(dd !== null).assertTrue(); - dd.closeSync(); - fileio.rmdirSync(dpath); - } - catch (e) { - console.info('fileio_test_dir_open_sync_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_dir_OpenSync_0100 - * @tc.name fileio_test_dir_open_sync_001 - * @tc.desc Function of API, not set parameter. - */ - it('fileio_test_dir_open_sync_001', 0, function () { - try { - fileio.opendirSync(); - throw new Error('No Parameter'); - } - catch (e) { - console.info('fileio_test_dir_open_sync_001 has failed for ' + e); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_dir_OpenSync_0200 - * @tc.name fileio_test_dir_open_sync_002 - * @tc.desc Function of API, dpath value is not exist. - */ - it('fileio_test_dir_open_sync_002', 0, async function () { - let dpath = await nextFileName('fileio_test_dir_open_sync_002') + 'd' - try { - fileio.opendirSync(dpath); - expect(null).assertFail(); - } - catch (e) { - console.info('fileio_test_dir_open_sync_002 has failed for ' + e); - expect(e.message == 'No such file or directory').assertTrue(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_dir_OpenSync_0300 - * @tc.name fileio_test_dir_open_sync_003 - * @tc.desc Function of API, dpath too long. - */ - it('fileio_test_dir_open_sync_003', 0, async function () { - let dpath = await nextFileName('fileio_test_dir_open_sync_003'); - fileio.mkdirSync(dpath); - try { - for (let i = 0; i < 16; i++) { - console.info('time' + i); - dpath = dpath + '/d' + i; - fileio.mkdirSync(dpath); - } - throw new Error('dpath too long'); - } - catch (e) { - console.info('fileio_test_dir_open_sync_003 has failed for ' + e); - forceRemoveDir(dpath, 16); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_dir_OpenSync_0400 - * @tc.name fileio_test_dir_open_sync_004 - * @tc.desc Function of API, filename too long. - */ - it('fileio_test_dir_open_sync_004', 0, async function () { - let dpath = await nextFileName(randomString(256)); - try { - fileio.mkdirSync(dpath); - expect(null).assertFail(); - } - catch (e) { - console.info('fileio_test_dir_open_sync_004 has failed for ' + e); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_dir_OpenSync_0500 - * @tc.name fileio_test_dir_open_sync_005 - * @tc.desc Function of API, uri dir too many layers. - */ - it('fileio_test_dir_open_sync_005', 0, async function () { - let dpath = await nextFileName('fileio_test_dir_open_sync_005'); - fileio.mkdirSync(dpath); - try { - for (let i = 0; i < 113; i++) { - console.info('time' + i); - dpath = dpath + '/d' + i - fileio.mkdirSync(dpath); - } - throw new Error('dir too many layers'); - } - catch (e) { - console.info('fileio_test_dir_open_sync_005 has failed for ' + e); - forceRemoveDir(dpath, 113); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_dir_OpenSync_0600 - * @tc.name fileio_test_dir_open_sync_006 - * @tc.desc Function of API, file name contain special character. - */ - it('fileio_test_dir_open_sync_006', 0, async function () { - let dpath = await nextFileName('?*:<>/|'); - try { - fileio.mkdirSync(dpath); - expect(null).assertFail(); - } - catch (e) { - console.info('fileio_test_dir_open_sync_006 has failed for ' + e); - expect(e.message == 'No such file or directory').assertTrue(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_dir_OpenASync_001 - * @tc.name fileio_test_dir_open_async_001 - * @tc.desc Function of API, file name contain special character. - */ - it('fileio_test_dir_open_async_001', 0, async function () { - let dpath = await nextFileName('fileio_test_dir_open_async_001') + 'd' - fileio.mkdirSync(dpath); - fileio.opendir(dpath, function (err, dir) { - expect(dir !== null).assertTrue(); - dir.closeSync(); - fileio.rmdirSync(dpath); - }); - }); - - /** - * @tc.number SUB_STORAGE_FileIO_dir_OpenASync_001 - * @tc.name fileio_test_dir_open_async_001 - * @tc.desc Function of API, file name contain special character. - */ - it('fileio_test_dir_open_async_002', 0, async function () { - let dpath = await nextFileName('fileio_test_dir_open_async_002') + 'd' - fileio.mkdirSync(dpath); - fileio.opendir(dpath).then((dir)=> { - expect(dir !== null).assertTrue(); - dir.closeSync(); - fileio.rmdirSync(dpath); - console.info('fileio opendir Success'); - }).catch((err) => { - console.info("fileio opendir err: " + JSON.stringify(err)); - }); - }); - - /** - * @tc.number SUB_STORAGE_FileIO_dir_ReadSync_0000 - * @tc.name fileio_test_dir_read_sync_000 - * @tc.desc Function of API, readSync. The dir contains 1 file. - */ - it('fileio_test_dir_read_sync_000', 0, async function () { - let dpath = await nextFileName('fileio_test_dir_read_sync_000') + 'd' - let fpath = dpath + '/f0' - try { - fileio.mkdirSync(dpath); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - let dd = fileio.opendirSync(dpath); - expect(dd !== null).assertTrue(); - expect(dd.readSync() !== null).assertTrue(); - dd.closeSync(); - fileio.unlinkSync(fpath); - fileio.rmdirSync(dpath); - } - catch (e) { - console.info('fileio_test_dir_read_sync_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_dir_ReadSync_0100 - * @tc.name fileio_test_dir_read_sync_001 - * @tc.desc Function of API, readSync. The dir contains more than 1 files. - */ - it('fileio_test_dir_read_sync_001', 0, async function () { - let dpath = await nextFileName('fileio_test_dir_read_sync_001') + 'd' - let fpathArray = new Array(dpath + '/f1', dpath + '/f2', dpath + '/d3'); - try { - fileio.mkdirSync(dpath); - for (let i = 0; i < 3; i++) { - if (i == 2) { - fileio.mkdirSync(fpathArray[i]) - } else { - expect(prepareFile(fpathArray[i], FILE_CONTENT)).assertTrue(); - } - } - let dd = fileio.opendirSync(dpath); - expect(dd !== null).assertTrue(); - for (let i = 0; i < 3; i++) { - let bool = typeof (dd.readSync()); - expect(bool == 'object').assertTrue(); - console.info('---bool=' + bool); - } - dd.closeSync(); - for (let i = 0; i < 3; i++) { - if (i == 2) { - fileio.rmdirSync(fpathArray[i]); - } else { - fileio.unlinkSync(fpathArray[i]); - } - } - fileio.rmdirSync(dpath); - } - catch (e) { - console.info('fileio_test_dir_read_sync_001 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_dir_ReadSync_0200 - * @tc.name fileio_test_dir_read_sync_002 - * @tc.desc Function of API, repeat read. The dir contains more than 1 files. - */ - it('fileio_test_dir_read_sync_002', 0, async function () { - let dpath = await nextFileName('fileio_test_dir_read_sync_002') + 'd' - let fpathArray = new Array(dpath + '/f1', dpath + '/f2', dpath + '/d3'); - try { - fileio.mkdirSync(dpath) - for (let i = 0; i < 3; i++) { - if (i == 2) { - fileio.mkdirSync(fpathArray[i]) - } else { - expect(prepareFile(fpathArray[i], FILE_CONTENT)).assertTrue(); - } - } - var dd = fileio.opendirSync(dpath); - expect(dd !== null).assertTrue(); - for (let i = 0; i < 3; i++) { - expect(dd.readSync() !== null).assertTrue(); - } - expect(dd.readSync() !== null).assertTrue(); - dd.closeSync(); - for (let i = 0; i < 3; i++) { - if (i == 2) { - fileio.rmdirSync(fpathArray[i]); - } else { - fileio.unlinkSync(fpathArray[i]); - } - } - fileio.rmdirSync(dpath); - } - catch (e) { - console.info('fileio_test_dir_read_sync_002 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_dir_ReadSync_0300 - * @tc.name fileio_test_dir_read_sync_003 - * @tc.desc Function of API, readSync. The dir no any files. - */ - it('fileio_test_dir_read_sync_003', 0, async function () { - let dpath = await nextFileName('fileio_test_dir_read_sync_003') + 'd' - let dd; - try { - fileio.mkdirSync(dpath); - dd = fileio.opendirSync(dpath); - expect(dd !== null).assertTrue(); - expect(dd.readSync() !== null).assertTrue(); - dd.closeSync(); - fileio.rmdirSync(dpath); - } - catch (e) { - console.info('fileio_test_dir_read_sync_003 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_dir_ReadSync_0400 - * @tc.name fileio_test_dir_read_sync_004 - * @tc.desc Function of API, error parameter. - */ - it('fileio_test_dir_read_sync_004', 0, async function () { - let dpath = await nextFileName('fileio_test_dir_read_sync_004') + 'd' - let fpath = dpath + '/f1' - let dd - try { - fileio.mkdirSync(dpath); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - dd = fileio.opendirSync(dpath); - expect(dd !== null).assertTrue(); - expect(dd.readSync(-1) == null).assertTrue(); - expect(null).assertFail(); - } - catch (e) { - console.info('fileio_test_dir_read_sync_004 has failed for ' + e); - expect(e.message == 'Number of arguments unmatched').assertTrue(); - dd.closeSync(); - fileio.unlinkSync(fpath); - fileio.rmdirSync(dpath); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_dir_ReadSync_0500 - * @tc.name fileio_test_dir_read_sync_005 - * @tc.desc Function of API, excess files. - */ - it('fileio_test_dir_read_sync_005', 0, async function () { - let dpath = await nextFileName('fileio_test_dir_read_sync_005') + 'd' - let fpath = dpath + '/f' - try { - fileio.mkdirSync(dpath); - for (let i = 0; i < 10001; i++) { - expect(prepareFile(fpath + i, 'test_text')).assertTrue(); - } - let dd = fileio.opendirSync(dpath); - expect(dd !== null).assertTrue(); - expect(dd.readSync() !== null).assertTrue(); - dd.closeSync(); - for (let i = 0; i < 10001; i++) { - fileio.unlinkSync(fpath + i); - } - fileio.rmdirSync(dpath); - } - catch (e) { - console.info('fileio_test_dir_read_sync_005 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_dir_CloseSync_0000 - * @tc.name fileio_test_dir_close_sync_000 - * @tc.desc Function of API, closeSync. - */ - it('fileio_test_dir_close_sync_000', 0, async function () { - let dpath = await nextFileName('fileio_test_dir_close_sync_000') + 'd' - try { - fileio.mkdirSync(dpath); - let dd = fileio.opendirSync(dpath); - expect(dd !== null).assertTrue(); - dd.closeSync(); - fileio.rmdirSync(dpath); - } - catch (e) { - console.info('fileio_test_dir_close_sync_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_dir_CloseSync_0100 - * @tc.name fileio_test_dir_close_sync_001 - * @tc.desc Function of API, closeSync. error parameter. - */ - it('fileio_test_dir_close_sync_001', 0, async function () { - let dpath = await nextFileName('fileio_test_dir_close_sync_001') + 'd' - try { - fileio.mkdirSync(dpath); - let dd = fileio.opendirSync(dpath); - expect(dd !== null).assertTrue(); - dd.closeSync(-1); - expect(null).assertFail(); - } - catch (e) { - console.info('fileio_test_dir_close_sync_001 has failed for ' + e); - expect(e.message == 'Dir has been closed yet').assertTrue(); - fileio.rmdirSync(dpath); - } - }); -}); -} +/* + * Copyright (C) 2021 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 fileio from '@ohos.fileio'; +import { describe,it,expect}from '@ohos/hypium' +import { + FILE_CONTENT, + prepareFile, + nextFileName, + randomString, + forceRemoveDir +} + from './Common' + +export default function fileIOTestDir() { +describe('fileIOTestDir', function () { + + /** + * @tc.number SUB_STORAGE_FileIO_dir_OpenSync_0000 + * @tc.name fileio_test_dir_open_sync_000 + * @tc.desc Function of API, opendirSync. + */ + it('fileio_test_dir_open_sync_000', 0, async function () { + let dpath = await nextFileName('fileio_test_dir_open_sync_000') + 'd' + try { + fileio.mkdirSync(dpath); + let dd = fileio.opendirSync(dpath); + expect(dd !== null).assertTrue(); + dd.closeSync(); + fileio.rmdirSync(dpath); + } + catch (e) { + console.info('fileio_test_dir_open_sync_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_dir_OpenSync_0100 + * @tc.name fileio_test_dir_open_sync_001 + * @tc.desc Function of API, not set parameter. + */ + it('fileio_test_dir_open_sync_001', 0, function () { + try { + fileio.opendirSync(); + throw new Error('No Parameter'); + } + catch (e) { + console.info('fileio_test_dir_open_sync_001 has failed for ' + e); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_dir_OpenSync_0200 + * @tc.name fileio_test_dir_open_sync_002 + * @tc.desc Function of API, dpath value is not exist. + */ + it('fileio_test_dir_open_sync_002', 0, async function () { + let dpath = await nextFileName('fileio_test_dir_open_sync_002') + 'd' + try { + fileio.opendirSync(dpath); + expect(null).assertFail(); + } + catch (e) { + console.info('fileio_test_dir_open_sync_002 has failed for ' + e); + expect(e.message == 'No such file or directory').assertTrue(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_dir_OpenSync_0300 + * @tc.name fileio_test_dir_open_sync_003 + * @tc.desc Function of API, dpath too long. + */ + it('fileio_test_dir_open_sync_003', 0, async function () { + let dpath = await nextFileName('fileio_test_dir_open_sync_003'); + fileio.mkdirSync(dpath); + try { + for (let i = 0; i < 16; i++) { + console.info('time' + i); + dpath = dpath + '/d' + i; + fileio.mkdirSync(dpath); + } + throw new Error('dpath too long'); + } + catch (e) { + console.info('fileio_test_dir_open_sync_003 has failed for ' + e); + forceRemoveDir(dpath, 16); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_dir_OpenSync_0400 + * @tc.name fileio_test_dir_open_sync_004 + * @tc.desc Function of API, filename too long. + */ + it('fileio_test_dir_open_sync_004', 0, async function () { + let dpath = await nextFileName(randomString(256)); + try { + fileio.mkdirSync(dpath); + expect(null).assertFail(); + } + catch (e) { + console.info('fileio_test_dir_open_sync_004 has failed for ' + e); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_dir_OpenSync_0500 + * @tc.name fileio_test_dir_open_sync_005 + * @tc.desc Function of API, uri dir too many layers. + */ + it('fileio_test_dir_open_sync_005', 0, async function () { + let dpath = await nextFileName('fileio_test_dir_open_sync_005'); + fileio.mkdirSync(dpath); + try { + for (let i = 0; i < 113; i++) { + console.info('time' + i); + dpath = dpath + '/d' + i + fileio.mkdirSync(dpath); + } + throw new Error('dir too many layers'); + } + catch (e) { + console.info('fileio_test_dir_open_sync_005 has failed for ' + e); + forceRemoveDir(dpath, 113); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_dir_OpenSync_0600 + * @tc.name fileio_test_dir_open_sync_006 + * @tc.desc Function of API, file name contain special character. + */ + it('fileio_test_dir_open_sync_006', 0, async function () { + let dpath = await nextFileName('?*:<>/|'); + try { + fileio.mkdirSync(dpath); + expect(null).assertFail(); + } + catch (e) { + console.info('fileio_test_dir_open_sync_006 has failed for ' + e); + expect(e.message == 'No such file or directory').assertTrue(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_dir_OpenASync_001 + * @tc.name fileio_test_dir_open_async_001 + * @tc.desc Function of API, file name contain special character. + */ + it('fileio_test_dir_open_async_001', 0, async function () { + let dpath = await nextFileName('fileio_test_dir_open_async_001') + 'd' + fileio.mkdirSync(dpath); + fileio.opendir(dpath, function (err, dir) { + expect(dir !== null).assertTrue(); + dir.closeSync(); + fileio.rmdirSync(dpath); + }); + }); + + /** + * @tc.number SUB_STORAGE_FileIO_dir_OpenASync_001 + * @tc.name fileio_test_dir_open_async_001 + * @tc.desc Function of API, file name contain special character. + */ + it('fileio_test_dir_open_async_002', 0, async function () { + let dpath = await nextFileName('fileio_test_dir_open_async_002') + 'd' + fileio.mkdirSync(dpath); + fileio.opendir(dpath).then((dir)=> { + expect(dir !== null).assertTrue(); + dir.closeSync(); + fileio.rmdirSync(dpath); + console.info('fileio opendir Success'); + }).catch((err) => { + console.info("fileio opendir err: " + JSON.stringify(err)); + }); + }); + + /** + * @tc.number SUB_STORAGE_FileIO_dir_ReadSync_0000 + * @tc.name fileio_test_dir_read_sync_000 + * @tc.desc Function of API, readSync. The dir contains 1 file. + */ + it('fileio_test_dir_read_sync_000', 0, async function () { + let dpath = await nextFileName('fileio_test_dir_read_sync_000') + 'd' + let fpath = dpath + '/f0' + try { + fileio.mkdirSync(dpath); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let dd = fileio.opendirSync(dpath); + expect(dd !== null).assertTrue(); + expect(dd.readSync() !== null).assertTrue(); + dd.closeSync(); + fileio.unlinkSync(fpath); + fileio.rmdirSync(dpath); + } + catch (e) { + console.info('fileio_test_dir_read_sync_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_dir_ReadSync_0100 + * @tc.name fileio_test_dir_read_sync_001 + * @tc.desc Function of API, readSync. The dir contains more than 1 files. + */ + it('fileio_test_dir_read_sync_001', 0, async function () { + let dpath = await nextFileName('fileio_test_dir_read_sync_001') + 'd' + let fpathArray = new Array(dpath + '/f1', dpath + '/f2', dpath + '/d3'); + try { + fileio.mkdirSync(dpath); + for (let i = 0; i < 3; i++) { + if (i == 2) { + fileio.mkdirSync(fpathArray[i]) + } else { + expect(prepareFile(fpathArray[i], FILE_CONTENT)).assertTrue(); + } + } + let dd = fileio.opendirSync(dpath); + expect(dd !== null).assertTrue(); + for (let i = 0; i < 3; i++) { + let bool = typeof (dd.readSync()); + expect(bool == 'object').assertTrue(); + console.info('---bool=' + bool); + } + dd.closeSync(); + for (let i = 0; i < 3; i++) { + if (i == 2) { + fileio.rmdirSync(fpathArray[i]); + } else { + fileio.unlinkSync(fpathArray[i]); + } + } + fileio.rmdirSync(dpath); + } + catch (e) { + console.info('fileio_test_dir_read_sync_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_dir_ReadSync_0200 + * @tc.name fileio_test_dir_read_sync_002 + * @tc.desc Function of API, repeat read. The dir contains more than 1 files. + */ + it('fileio_test_dir_read_sync_002', 0, async function () { + let dpath = await nextFileName('fileio_test_dir_read_sync_002') + 'd' + let fpathArray = new Array(dpath + '/f1', dpath + '/f2', dpath + '/d3'); + try { + fileio.mkdirSync(dpath) + for (let i = 0; i < 3; i++) { + if (i == 2) { + fileio.mkdirSync(fpathArray[i]) + } else { + expect(prepareFile(fpathArray[i], FILE_CONTENT)).assertTrue(); + } + } + var dd = fileio.opendirSync(dpath); + expect(dd !== null).assertTrue(); + for (let i = 0; i < 3; i++) { + expect(dd.readSync() !== null).assertTrue(); + } + expect(dd.readSync() !== null).assertTrue(); + dd.closeSync(); + for (let i = 0; i < 3; i++) { + if (i == 2) { + fileio.rmdirSync(fpathArray[i]); + } else { + fileio.unlinkSync(fpathArray[i]); + } + } + fileio.rmdirSync(dpath); + } + catch (e) { + console.info('fileio_test_dir_read_sync_002 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_dir_ReadSync_0300 + * @tc.name fileio_test_dir_read_sync_003 + * @tc.desc Function of API, readSync. The dir no any files. + */ + it('fileio_test_dir_read_sync_003', 0, async function () { + let dpath = await nextFileName('fileio_test_dir_read_sync_003') + 'd' + let dd; + try { + fileio.mkdirSync(dpath); + dd = fileio.opendirSync(dpath); + expect(dd !== null).assertTrue(); + expect(dd.readSync() !== null).assertTrue(); + dd.closeSync(); + fileio.rmdirSync(dpath); + } + catch (e) { + console.info('fileio_test_dir_read_sync_003 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_dir_ReadSync_0400 + * @tc.name fileio_test_dir_read_sync_004 + * @tc.desc Function of API, error parameter. + */ + it('fileio_test_dir_read_sync_004', 0, async function () { + let dpath = await nextFileName('fileio_test_dir_read_sync_004') + 'd' + let fpath = dpath + '/f1' + let dd + try { + fileio.mkdirSync(dpath); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + dd = fileio.opendirSync(dpath); + expect(dd !== null).assertTrue(); + expect(dd.readSync(-1) == null).assertTrue(); + expect(null).assertFail(); + } + catch (e) { + console.info('fileio_test_dir_read_sync_004 has failed for ' + e); + expect(e.message == 'Number of arguments unmatched').assertTrue(); + dd.closeSync(); + fileio.unlinkSync(fpath); + fileio.rmdirSync(dpath); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_dir_ReadSync_0500 + * @tc.name fileio_test_dir_read_sync_005 + * @tc.desc Function of API, excess files. + */ + it('fileio_test_dir_read_sync_005', 0, async function () { + let dpath = await nextFileName('fileio_test_dir_read_sync_005') + 'd' + let fpath = dpath + '/f' + try { + fileio.mkdirSync(dpath); + for (let i = 0; i < 10001; i++) { + expect(prepareFile(fpath + i, 'test_text')).assertTrue(); + } + let dd = fileio.opendirSync(dpath); + expect(dd !== null).assertTrue(); + expect(dd.readSync() !== null).assertTrue(); + dd.closeSync(); + for (let i = 0; i < 10001; i++) { + fileio.unlinkSync(fpath + i); + } + fileio.rmdirSync(dpath); + } + catch (e) { + console.info('fileio_test_dir_read_sync_005 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_dir_CloseSync_0000 + * @tc.name fileio_test_dir_close_sync_000 + * @tc.desc Function of API, closeSync. + */ + it('fileio_test_dir_close_sync_000', 0, async function () { + let dpath = await nextFileName('fileio_test_dir_close_sync_000') + 'd' + try { + fileio.mkdirSync(dpath); + let dd = fileio.opendirSync(dpath); + expect(dd !== null).assertTrue(); + dd.closeSync(); + fileio.rmdirSync(dpath); + } + catch (e) { + console.info('fileio_test_dir_close_sync_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_dir_CloseSync_0100 + * @tc.name fileio_test_dir_close_sync_001 + * @tc.desc Function of API, closeSync. error parameter. + */ + it('fileio_test_dir_close_sync_001', 0, async function () { + let dpath = await nextFileName('fileio_test_dir_close_sync_001') + 'd' + try { + fileio.mkdirSync(dpath); + let dd = fileio.opendirSync(dpath); + expect(dd !== null).assertTrue(); + dd.closeSync(-1); + expect(null).assertFail(); + } + catch (e) { + console.info('fileio_test_dir_close_sync_001 has failed for ' + e); + expect(e.message == 'Dir has been closed yet').assertTrue(); + fileio.rmdirSync(dpath); + } + }); +}); +} diff --git a/storage/storagefileiojstest/entry/src/ohosTest/js/test/FileIODirent.test.js b/storage/storagefileiojstest/src/main/js/test/FileIODirent.test.js similarity index 97% rename from storage/storagefileiojstest/entry/src/ohosTest/js/test/FileIODirent.test.js rename to storage/storagefileiojstest/src/main/js/test/FileIODirent.test.js index 7d6a67c59f38a8b35a0fdabaab0e06a1608df7e5..d4b57588d88fe8a5cb28ab0518982904940bff67 100644 --- a/storage/storagefileiojstest/entry/src/ohosTest/js/test/FileIODirent.test.js +++ b/storage/storagefileiojstest/src/main/js/test/FileIODirent.test.js @@ -1,424 +1,424 @@ -/* - * Copyright (C) 2023 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 fileio from '@ohos.fileio'; -import { describe,it,expect}from '@ohos/hypium' -import { - FILE_CONTENT, - prepareFile, - nextFileName -}from './Common'; - -export default function fileIOTestDirent() { -describe('fileIOTestDirent', function () { - - /** - * @tc.number SUB_STORAGE_FileIO_dirent_name_0000 - * @tc.name fileio_test_dirent_name_000 - * @tc.desc Function of API, Get file name. - */ - it('fileio_test_dirent_name_000', 0, async function () { - let dpath = await nextFileName('fileio_test_dirent_name_000') + 'd'; - let fpath = dpath + '/f1'; - try { - expect(fileio.mkdirSync(dpath) !== null); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - let dd = fileio.opendirSync(dpath); - expect(dd !== null).assertTrue(); - let dirent = dd.readSync(); - expect(dirent.name !== null).assertTrue(); - expect(dd.closeSync() !== null); - expect(fileio.unlinkSync(fpath) !== null); - expect(fileio.rmdirSync(dpath) !== null); - } - catch (e) { - console.log('fileio_test_dirent_name_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_dirent_isBlockDevice_0000 - * @tc.name fileio_test_dirent_is_block_device_000 - * @tc.desc Function of API, isBlockDevice. Determine whether it is a block device. - */ - it('fileio_test_dirent_is_block_device_000', 0, async function () { - let dpath = await nextFileName('fileio_test_dirent_is_block_device_000') + 'd'; - let fpath = dpath + '/f1'; - try { - expect(fileio.mkdirSync(dpath) !== null); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - let dd = fileio.opendirSync(dpath); - expect(dd !== null).assertTrue(); - let dirent = dd.readSync(); - expect(dirent !== null).assertTrue(); - expect(dirent.isBlockDevice() !== null); - expect(dd.closeSync() !== null); - expect(fileio.unlinkSync(fpath) !== null); - expect(fileio.rmdirSync(dpath) !== null); - return - } - catch (e) { - console.log('fileio_test_dirent_is_block_device_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_dirent_isBlockDevice_0100 - * @tc.name fileio_test_dirent_is_block_device_001 - * @tc.desc Function of API, isBlockDevice. The parameter is - 1. - */ - it('fileio_test_dirent_is_block_device_001', 0, async function () { - let dpath = await nextFileName('fileio_test_dirent_is_block_device_001') + 'd'; - let fpath = dpath + '/f1'; - let dd; - try { - expect(fileio.mkdirSync(dpath) !== null); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - dd = fileio.opendirSync(dpath); - expect(dd !== null).assertTrue(); - let dirent = dd.readSync(); - expect(dirent !== null).assertTrue(); - dirent.isBlockDevice(-1); - expect(null).assertFail(); - } - catch (e) { - expect(dd.closeSync() !== null); - expect(fileio.unlinkSync(fpath) !== null); - expect(fileio.rmdirSync(dpath) !== null); - console.log('fileio_test_dirent_is_block_device_001 has failed for ' + e); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_dirent_isCharacterDevice_0000 - * @tc.name fileio_test_dirent_is_character_device_000 - * @tc.desc Function of API, isCharacterDevice. Determine whether it is a character device. - */ - it('fileio_test_dirent_is_character_device_000', 0, async function () { - let dpath = await nextFileName('fileio_test_dirent_is_character_device_000') + 'd'; - let fpath = dpath + '/f1'; - try { - expect(fileio.mkdirSync(dpath) !== null); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - let dd = fileio.opendirSync(dpath); - expect(dd !== null).assertTrue(); - let dirent = dd.readSync(); - expect(dirent !== null).assertTrue(); - expect(dirent.isCharacterDevice() !== null); - expect(dd.closeSync() !== null !== null); - expect(fileio.unlinkSync(fpath) !== null); - expect(fileio.rmdirSync(dpath) !== null); - } - catch (e) { - console.log('fileio_test_dirent_is_character_device_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_dirent_isCharacterDevice_0100 - * @tc.name fileio_test_dirent_is_character_device_001 - * @tc.desc Function of API, isCharacterDevice. The parameter is - 1. - */ - it('fileio_test_dirent_is_character_device_001', 0, async function () { - let dpath = await nextFileName('fileio_test_dirent_is_character_device_001') + 'd'; - let fpath = dpath + '/f1'; - let dd; - try { - expect(fileio.mkdirSync(dpath) !== null); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - dd = fileio.opendirSync(dpath); - expect(dd !== null).assertTrue(); - let dirent = dd.readSync(); - expect(dirent !== null).assertTrue(); - dirent.isCharacterDevice(-1); - expect(null).assertFail(); - } - catch (e) { - expect(dd.closeSync() !== null); - expect(fileio.unlinkSync(fpath) !== null); - expect(fileio.rmdirSync(dpath) !== null); - console.log('fileio_test_dirent_is_character_device_001 has failed for ' + e); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_dirent_isDirectory_0000 - * @tc.name fileio_test_dirent_is_directory_000 - * @tc.desc Function of API, isDirectory. Determine whether it is a directory. - */ - it('fileio_test_dirent_is_directory_000', 0, async function () { - let dpath = await nextFileName('fileio_test_dirent_is_directory_000') + 'd'; - let fpath = dpath + '/f1'; - try { - expect(fileio.mkdirSync(dpath) !== null); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - let dd = fileio.opendirSync(dpath); - expect(dd !== null).assertTrue(); - let dirent = dd.readSync(); - expect(dirent !== null).assertTrue(); - expect(dirent.isDirectory() !== null); - expect(dd.closeSync() !== null); - expect(fileio.unlinkSync(fpath) !== null); - expect(fileio.rmdirSync(dpath) !== null); - } - catch (e) { - console.log('fileio_test_dirent_is_directory_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_dirent_isDirectory_0100 - * @tc.name fileio_test_dirent_is_directory_001 - * @tc.desc Function of API, isDirectory. The parameter is - 1 - */ - it('fileio_test_dirent_is_directory_001', 0, async function () { - let dpath = await nextFileName('fileio_test_dirent_is_directory_001') + 'd'; - let fpath = dpath + '/f1'; - let dd; - try { - expect(fileio.mkdirSync(dpath) !== null); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - dd = fileio.opendirSync(dpath); - expect(dd !== null).assertTrue(); - let dirent = dd.readSync(); - expect(dirent !== null).assertTrue(); - dirent.isDirectory(-1); - expect(null).assertFail(); - } - catch (e) { - expect(dd.closeSync() !== null); - expect(fileio.unlinkSync(fpath) !== null); - expect(fileio.rmdirSync(dpath) !== null); - console.log('fileio_test_dirent_is_directory_001 has failed for ' + e); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_dirent_isFifo_0000 - * @tc.name fileio_test_dirent_is_fifo_000 - * @tc.desc Function of API, isFIFO. Determine whether it is a fifo. - */ - it('fileio_test_dirent_is_fifo_000', 0, async function () { - let dpath = await nextFileName('fileio_test_dirent_is_fifo_000') + 'd'; - let fpath = dpath + '/f1'; - try { - expect(fileio.mkdirSync(dpath) !== null); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - let dd = fileio.opendirSync(dpath); - expect(dd !== null).assertTrue(); - let dirent = dd.readSync(); - expect(dirent !== null).assertTrue(); - expect(dirent.isFIFO() !== null); - expect(dd.closeSync() !== null); - expect(fileio.unlinkSync(fpath) !== null); - expect(fileio.rmdirSync(dpath) !== null); - } - catch (e) { - console.log('fileio_test_dirent_is_fifo_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_dirent_isFifo_0100 - * @tc.name fileio_test_dirent_is_fifo_001 - * @tc.desc Function of API, isFIFO. The parameter is - 1 - */ - it('fileio_test_dirent_is_fifo_001', 0, async function () { - let dpath = await nextFileName('fileio_test_dirent_is_fifo_001') + 'd'; - let fpath = dpath + '/f1'; - let dd; - try { - expect(fileio.mkdirSync(dpath) !== null); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - dd = fileio.opendirSync(dpath); - expect(dd !== null).assertTrue(); - let dirent = dd.readSync(); - expect(dirent !== null).assertTrue(); - dirent.isFIFO(-1); - expect(null).assertFail(); - } - catch (e) { - expect(dd.closeSync() !== null); - expect(fileio.unlinkSync(fpath) !== null); - expect(fileio.rmdirSync(dpath) !== null); - console.log('fileio_test_dirent_is_fifo_001 has failed for ' + e); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_dirent_isFile_0000 - * @tc.name fileio_test_dirent_is_file_000 - * @tc.desc Function of API, isFile. Determine whether it is a file. - */ - it('fileio_test_dirent_is_file_000', 0, async function () { - let dpath = await nextFileName('fileio_test_dirent_is_file_000') + 'd'; - let fpath = dpath + '/f1'; - try { - expect(fileio.mkdirSync(dpath) !== null); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - let dd = fileio.opendirSync(dpath); - expect(dd !== null).assertTrue(); - let dirent = dd.readSync(); - expect(dirent !== null).assertTrue(); - expect(dirent.isFile() !== null); - expect(dd.closeSync() !== null); - expect(fileio.unlinkSync(fpath) !== null); - expect(fileio.rmdirSync(dpath) !== null); - } - catch (e) { - console.log('fileio_test_dirent_is_file_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_dirent_isFile_0100 - * @tc.name fileio_test_dirent_is_file_001 - * @tc.desc Function of API, isFile. The parameter is - 1 - */ - it('fileio_test_dirent_is_file_001', 0, async function () { - let dpath = await nextFileName('fileio_test_dirent_is_file_001') + 'd'; - let fpath = dpath + '/f1'; - let dd; - try { - expect(fileio.mkdirSync(dpath) !== null); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - dd = fileio.opendirSync(dpath); - expect(dd !== null).assertTrue(); - let dirent = dd.readSync(); - expect(dirent !== null).assertTrue(); - dirent.isFile(-1); - expect(null).assertFail(); - } - catch (e) { - expect(dd.closeSync() !== null); - expect(fileio.unlinkSync(fpath) !== null); - expect(fileio.rmdirSync(dpath) !== null); - console.log('fileio_test_dirent_is_file_001 has failed for ' + e); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_dirent_isSocket_0000 - * @tc.name fileio_test_dirent_is_socket_000 - * @tc.desc Function of API, isSocket. Determine whether it is a socket. - */ - it('fileio_test_dirent_is_socket_000', 0, async function () { - let dpath = await nextFileName('fileio_test_dirent_is_socket_000') + 'd'; - let fpath = dpath + '/f1'; - try { - expect(fileio.mkdirSync(dpath) !== null); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - let dd = fileio.opendirSync(dpath); - expect(dd !== null).assertTrue(); - let dirent = dd.readSync(); - expect(dirent !== null).assertTrue(); - expect(dirent.isSocket() !== null); - expect(dd.closeSync() !== null); - expect(fileio.unlinkSync(fpath) !== null); - expect(fileio.rmdirSync(dpath) !== null); - } - catch (e) { - console.log('fileio_test_dirent_is_socket_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_dirent_isSocket_0100 - * @tc.name fileio_test_dirent_is_socket_001 - * @tc.desc Function of API, isSocket. The parameter is - 1 - */ - it('fileio_test_dirent_is_socket_001', 0, async function () { - let dpath = await nextFileName('fileio_test_dirent_is_socket_001') + 'd'; - let fpath = dpath + '/f1'; - let dd; - try { - expect(fileio.mkdirSync(dpath) !== null); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - dd = fileio.opendirSync(dpath); - expect(dd !== null).assertTrue(); - let dirent = dd.readSync(); - expect(dirent !== null).assertTrue(); - dirent.isSocket(-1); - expect(null).assertFail(); - } - catch (e) { - expect(dd.closeSync() !== null); - expect(fileio.unlinkSync(fpath) !== null); - expect(fileio.rmdirSync(dpath) !== null); - console.log('fileio_test_dirent_is_socket_001 has failed for ' + e); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_dirent_isSymbolicLlink_0000 - * @tc.name fileio_test_dirent_is_symbolic_link_000 - * @tc.desc Function of API, isSymbolicLink. Determine whether it is a symbolic link. - */ - it('fileio_test_dirent_is_symbolic_link_000', 0, async function () { - let dpath = await nextFileName('fileio_test_dirent_is_symbolic_link_000') + 'd'; - let fpath = dpath + '/f1'; - try { - expect(fileio.mkdirSync(dpath) !== null); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - let dd = fileio.opendirSync(dpath); - expect(dd !== null).assertTrue(); - let dirent = dd.readSync(); - expect(dirent !== null).assertTrue(); - expect(dirent.isSymbolicLink() !== null); - expect(dd.closeSync() !== null); - expect(fileio.unlinkSync(fpath) !== null); - expect(fileio.rmdirSync(dpath) !== null); - } - catch (e) { - console.log('fileio_test_dirent_is_symbolic_link_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_dirent_isSymbolicLlink_0100 - * @tc.name fileio_test_dirent_is_symbolic_link_001 - * @tc.desc Function of API, isSymbolicLink. The parameter is - 1 - */ - it('fileio_test_dirent_is_symbolic_link_001', 0, async function () { - let dpath = await nextFileName('fileio_test_dirent_is_symbolic_link_001') + 'd'; - let fpath = dpath + '/f1'; - let dd; - try { - expect(fileio.mkdirSync(dpath) !== null); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - dd = fileio.opendirSync(dpath); - expect(dd !== null).assertTrue(); - let dirent = dd.readSync(); - expect(dirent !== null).assertTrue(); - dirent.isSymbolicLink(-1); - expect(null).assertFail(); - } - catch (e) { - expect(dd.closeSync() !== null); - expect(fileio.unlinkSync(fpath) !== null); - expect(fileio.rmdirSync(dpath) !== null); - console.log('fileio_test_dirent_is_symbolic_link_001 has failed for ' + e); - } - }); - -});} +/* + * Copyright (C) 2021 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 fileio from '@ohos.fileio'; +import { describe,it,expect}from '@ohos/hypium' +import { + FILE_CONTENT, + prepareFile, + nextFileName +}from './Common'; + +export default function fileIOTestDirent() { +describe('fileIOTestDirent', function () { + + /** + * @tc.number SUB_STORAGE_FileIO_dirent_name_0000 + * @tc.name fileio_test_dirent_name_000 + * @tc.desc Function of API, Get file name. + */ + it('fileio_test_dirent_name_000', 0, async function () { + let dpath = await nextFileName('fileio_test_dirent_name_000') + 'd'; + let fpath = dpath + '/f1'; + try { + expect(fileio.mkdirSync(dpath) !== null); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let dd = fileio.opendirSync(dpath); + expect(dd !== null).assertTrue(); + let dirent = dd.readSync(); + expect(dirent.name !== null).assertTrue(); + expect(dd.closeSync() !== null); + expect(fileio.unlinkSync(fpath) !== null); + expect(fileio.rmdirSync(dpath) !== null); + } + catch (e) { + console.log('fileio_test_dirent_name_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_dirent_isBlockDevice_0000 + * @tc.name fileio_test_dirent_is_block_device_000 + * @tc.desc Function of API, isBlockDevice. Determine whether it is a block device. + */ + it('fileio_test_dirent_is_block_device_000', 0, async function () { + let dpath = await nextFileName('fileio_test_dirent_is_block_device_000') + 'd'; + let fpath = dpath + '/f1'; + try { + expect(fileio.mkdirSync(dpath) !== null); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let dd = fileio.opendirSync(dpath); + expect(dd !== null).assertTrue(); + let dirent = dd.readSync(); + expect(dirent !== null).assertTrue(); + expect(dirent.isBlockDevice() !== null); + expect(dd.closeSync() !== null); + expect(fileio.unlinkSync(fpath) !== null); + expect(fileio.rmdirSync(dpath) !== null); + return + } + catch (e) { + console.log('fileio_test_dirent_is_block_device_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_dirent_isBlockDevice_0100 + * @tc.name fileio_test_dirent_is_block_device_001 + * @tc.desc Function of API, isBlockDevice. The parameter is - 1. + */ + it('fileio_test_dirent_is_block_device_001', 0, async function () { + let dpath = await nextFileName('fileio_test_dirent_is_block_device_001') + 'd'; + let fpath = dpath + '/f1'; + let dd; + try { + expect(fileio.mkdirSync(dpath) !== null); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + dd = fileio.opendirSync(dpath); + expect(dd !== null).assertTrue(); + let dirent = dd.readSync(); + expect(dirent !== null).assertTrue(); + dirent.isBlockDevice(-1); + expect(null).assertFail(); + } + catch (e) { + expect(dd.closeSync() !== null); + expect(fileio.unlinkSync(fpath) !== null); + expect(fileio.rmdirSync(dpath) !== null); + console.log('fileio_test_dirent_is_block_device_001 has failed for ' + e); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_dirent_isCharacterDevice_0000 + * @tc.name fileio_test_dirent_is_character_device_000 + * @tc.desc Function of API, isCharacterDevice. Determine whether it is a character device. + */ + it('fileio_test_dirent_is_character_device_000', 0, async function () { + let dpath = await nextFileName('fileio_test_dirent_is_character_device_000') + 'd'; + let fpath = dpath + '/f1'; + try { + expect(fileio.mkdirSync(dpath) !== null); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let dd = fileio.opendirSync(dpath); + expect(dd !== null).assertTrue(); + let dirent = dd.readSync(); + expect(dirent !== null).assertTrue(); + expect(dirent.isCharacterDevice() !== null); + expect(dd.closeSync() !== null !== null); + expect(fileio.unlinkSync(fpath) !== null); + expect(fileio.rmdirSync(dpath) !== null); + } + catch (e) { + console.log('fileio_test_dirent_is_character_device_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_dirent_isCharacterDevice_0100 + * @tc.name fileio_test_dirent_is_character_device_001 + * @tc.desc Function of API, isCharacterDevice. The parameter is - 1. + */ + it('fileio_test_dirent_is_character_device_001', 0, async function () { + let dpath = await nextFileName('fileio_test_dirent_is_character_device_001') + 'd'; + let fpath = dpath + '/f1'; + let dd; + try { + expect(fileio.mkdirSync(dpath) !== null); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + dd = fileio.opendirSync(dpath); + expect(dd !== null).assertTrue(); + let dirent = dd.readSync(); + expect(dirent !== null).assertTrue(); + dirent.isCharacterDevice(-1); + expect(null).assertFail(); + } + catch (e) { + expect(dd.closeSync() !== null); + expect(fileio.unlinkSync(fpath) !== null); + expect(fileio.rmdirSync(dpath) !== null); + console.log('fileio_test_dirent_is_character_device_001 has failed for ' + e); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_dirent_isDirectory_0000 + * @tc.name fileio_test_dirent_is_directory_000 + * @tc.desc Function of API, isDirectory. Determine whether it is a directory. + */ + it('fileio_test_dirent_is_directory_000', 0, async function () { + let dpath = await nextFileName('fileio_test_dirent_is_directory_000') + 'd'; + let fpath = dpath + '/f1'; + try { + expect(fileio.mkdirSync(dpath) !== null); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let dd = fileio.opendirSync(dpath); + expect(dd !== null).assertTrue(); + let dirent = dd.readSync(); + expect(dirent !== null).assertTrue(); + expect(dirent.isDirectory() !== null); + expect(dd.closeSync() !== null); + expect(fileio.unlinkSync(fpath) !== null); + expect(fileio.rmdirSync(dpath) !== null); + } + catch (e) { + console.log('fileio_test_dirent_is_directory_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_dirent_isDirectory_0100 + * @tc.name fileio_test_dirent_is_directory_001 + * @tc.desc Function of API, isDirectory. The parameter is - 1 + */ + it('fileio_test_dirent_is_directory_001', 0, async function () { + let dpath = await nextFileName('fileio_test_dirent_is_directory_001') + 'd'; + let fpath = dpath + '/f1'; + let dd; + try { + expect(fileio.mkdirSync(dpath) !== null); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + dd = fileio.opendirSync(dpath); + expect(dd !== null).assertTrue(); + let dirent = dd.readSync(); + expect(dirent !== null).assertTrue(); + dirent.isDirectory(-1); + expect(null).assertFail(); + } + catch (e) { + expect(dd.closeSync() !== null); + expect(fileio.unlinkSync(fpath) !== null); + expect(fileio.rmdirSync(dpath) !== null); + console.log('fileio_test_dirent_is_directory_001 has failed for ' + e); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_dirent_isFifo_0000 + * @tc.name fileio_test_dirent_is_fifo_000 + * @tc.desc Function of API, isFIFO. Determine whether it is a fifo. + */ + it('fileio_test_dirent_is_fifo_000', 0, async function () { + let dpath = await nextFileName('fileio_test_dirent_is_fifo_000') + 'd'; + let fpath = dpath + '/f1'; + try { + expect(fileio.mkdirSync(dpath) !== null); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let dd = fileio.opendirSync(dpath); + expect(dd !== null).assertTrue(); + let dirent = dd.readSync(); + expect(dirent !== null).assertTrue(); + expect(dirent.isFIFO() !== null); + expect(dd.closeSync() !== null); + expect(fileio.unlinkSync(fpath) !== null); + expect(fileio.rmdirSync(dpath) !== null); + } + catch (e) { + console.log('fileio_test_dirent_is_fifo_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_dirent_isFifo_0100 + * @tc.name fileio_test_dirent_is_fifo_001 + * @tc.desc Function of API, isFIFO. The parameter is - 1 + */ + it('fileio_test_dirent_is_fifo_001', 0, async function () { + let dpath = await nextFileName('fileio_test_dirent_is_fifo_001') + 'd'; + let fpath = dpath + '/f1'; + let dd; + try { + expect(fileio.mkdirSync(dpath) !== null); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + dd = fileio.opendirSync(dpath); + expect(dd !== null).assertTrue(); + let dirent = dd.readSync(); + expect(dirent !== null).assertTrue(); + dirent.isFIFO(-1); + expect(null).assertFail(); + } + catch (e) { + expect(dd.closeSync() !== null); + expect(fileio.unlinkSync(fpath) !== null); + expect(fileio.rmdirSync(dpath) !== null); + console.log('fileio_test_dirent_is_fifo_001 has failed for ' + e); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_dirent_isFile_0000 + * @tc.name fileio_test_dirent_is_file_000 + * @tc.desc Function of API, isFile. Determine whether it is a file. + */ + it('fileio_test_dirent_is_file_000', 0, async function () { + let dpath = await nextFileName('fileio_test_dirent_is_file_000') + 'd'; + let fpath = dpath + '/f1'; + try { + expect(fileio.mkdirSync(dpath) !== null); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let dd = fileio.opendirSync(dpath); + expect(dd !== null).assertTrue(); + let dirent = dd.readSync(); + expect(dirent !== null).assertTrue(); + expect(dirent.isFile() !== null); + expect(dd.closeSync() !== null); + expect(fileio.unlinkSync(fpath) !== null); + expect(fileio.rmdirSync(dpath) !== null); + } + catch (e) { + console.log('fileio_test_dirent_is_file_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_dirent_isFile_0100 + * @tc.name fileio_test_dirent_is_file_001 + * @tc.desc Function of API, isFile. The parameter is - 1 + */ + it('fileio_test_dirent_is_file_001', 0, async function () { + let dpath = await nextFileName('fileio_test_dirent_is_file_001') + 'd'; + let fpath = dpath + '/f1'; + let dd; + try { + expect(fileio.mkdirSync(dpath) !== null); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + dd = fileio.opendirSync(dpath); + expect(dd !== null).assertTrue(); + let dirent = dd.readSync(); + expect(dirent !== null).assertTrue(); + dirent.isFile(-1); + expect(null).assertFail(); + } + catch (e) { + expect(dd.closeSync() !== null); + expect(fileio.unlinkSync(fpath) !== null); + expect(fileio.rmdirSync(dpath) !== null); + console.log('fileio_test_dirent_is_file_001 has failed for ' + e); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_dirent_isSocket_0000 + * @tc.name fileio_test_dirent_is_socket_000 + * @tc.desc Function of API, isSocket. Determine whether it is a socket. + */ + it('fileio_test_dirent_is_socket_000', 0, async function () { + let dpath = await nextFileName('fileio_test_dirent_is_socket_000') + 'd'; + let fpath = dpath + '/f1'; + try { + expect(fileio.mkdirSync(dpath) !== null); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let dd = fileio.opendirSync(dpath); + expect(dd !== null).assertTrue(); + let dirent = dd.readSync(); + expect(dirent !== null).assertTrue(); + expect(dirent.isSocket() !== null); + expect(dd.closeSync() !== null); + expect(fileio.unlinkSync(fpath) !== null); + expect(fileio.rmdirSync(dpath) !== null); + } + catch (e) { + console.log('fileio_test_dirent_is_socket_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_dirent_isSocket_0100 + * @tc.name fileio_test_dirent_is_socket_001 + * @tc.desc Function of API, isSocket. The parameter is - 1 + */ + it('fileio_test_dirent_is_socket_001', 0, async function () { + let dpath = await nextFileName('fileio_test_dirent_is_socket_001') + 'd'; + let fpath = dpath + '/f1'; + let dd; + try { + expect(fileio.mkdirSync(dpath) !== null); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + dd = fileio.opendirSync(dpath); + expect(dd !== null).assertTrue(); + let dirent = dd.readSync(); + expect(dirent !== null).assertTrue(); + dirent.isSocket(-1); + expect(null).assertFail(); + } + catch (e) { + expect(dd.closeSync() !== null); + expect(fileio.unlinkSync(fpath) !== null); + expect(fileio.rmdirSync(dpath) !== null); + console.log('fileio_test_dirent_is_socket_001 has failed for ' + e); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_dirent_isSymbolicLlink_0000 + * @tc.name fileio_test_dirent_is_symbolic_link_000 + * @tc.desc Function of API, isSymbolicLink. Determine whether it is a symbolic link. + */ + it('fileio_test_dirent_is_symbolic_link_000', 0, async function () { + let dpath = await nextFileName('fileio_test_dirent_is_symbolic_link_000') + 'd'; + let fpath = dpath + '/f1'; + try { + expect(fileio.mkdirSync(dpath) !== null); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let dd = fileio.opendirSync(dpath); + expect(dd !== null).assertTrue(); + let dirent = dd.readSync(); + expect(dirent !== null).assertTrue(); + expect(dirent.isSymbolicLink() !== null); + expect(dd.closeSync() !== null); + expect(fileio.unlinkSync(fpath) !== null); + expect(fileio.rmdirSync(dpath) !== null); + } + catch (e) { + console.log('fileio_test_dirent_is_symbolic_link_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_dirent_isSymbolicLlink_0100 + * @tc.name fileio_test_dirent_is_symbolic_link_001 + * @tc.desc Function of API, isSymbolicLink. The parameter is - 1 + */ + it('fileio_test_dirent_is_symbolic_link_001', 0, async function () { + let dpath = await nextFileName('fileio_test_dirent_is_symbolic_link_001') + 'd'; + let fpath = dpath + '/f1'; + let dd; + try { + expect(fileio.mkdirSync(dpath) !== null); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + dd = fileio.opendirSync(dpath); + expect(dd !== null).assertTrue(); + let dirent = dd.readSync(); + expect(dirent !== null).assertTrue(); + dirent.isSymbolicLink(-1); + expect(null).assertFail(); + } + catch (e) { + expect(dd.closeSync() !== null); + expect(fileio.unlinkSync(fpath) !== null); + expect(fileio.rmdirSync(dpath) !== null); + console.log('fileio_test_dirent_is_symbolic_link_001 has failed for ' + e); + } + }); + +});} diff --git a/storage/storagefileiojstest/entry/src/ohosTest/js/test/FileIOStat.test.js b/storage/storagefileiojstest/src/main/js/test/FileIOStat.test.js similarity index 97% rename from storage/storagefileiojstest/entry/src/ohosTest/js/test/FileIOStat.test.js rename to storage/storagefileiojstest/src/main/js/test/FileIOStat.test.js index 4c695f80e88cd2b37f129111c1da4b5df70e3e44..acf278d91b5eb1a7ceae1b4fb0ffb8cece187b89 100644 --- a/storage/storagefileiojstest/entry/src/ohosTest/js/test/FileIOStat.test.js +++ b/storage/storagefileiojstest/src/main/js/test/FileIOStat.test.js @@ -1,787 +1,787 @@ -/* - * Copyright (C) 2023 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 fileio from '@ohos.fileio'; -import { describe,it,expect}from '@ohos/hypium' -import { - FILE_CONTENT, - prepareFile, - nextFileName, - randomString, - forceRemoveDir -} - from './Common' - -export default function fileIOTestStat() { -describe('fileIOTestStat', function () { - - /** - * @tc.number SUB_STORAGE_FileIO_statSync_0000 - * @tc.name fileio_test_stat_stat_sync_000 - * @tc.desc Function of API, statSync. Gets information about the file in the specified path. - */ - it('fileio_test_stat_stat_sync_000', 0, async function () { - let fpath = await nextFileName('fileio_test_stat_stat_sync_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let stat = fileio.statSync(fpath); - expect(stat !== null).assertTrue(); - fileio.unlinkSync(fpath); - } - catch (e) { - console.log('fileio_test_stat_stat_sync_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_statSync_0100 - * @tc.name fileio_test_stat_stat_sync_001 - * @tc.desc Function of API, statSync. The specified file does not exist. - */ - it('fileio_test_stat_stat_sync_001', 0, async function () { - let fpath = await nextFileName('fileio_test_stat_stat_sync_001'); - try { - fileio.statSync(fpath); - expect(null).assertFail(); - } - catch (e) { - console.log('fileio_test_stat_stat_sync_001 has failed for ' + e); - expect(e.message == 'No such file or directory').assertTrue(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_statSync_0200 - * @tc.name fileio_test_stat_stat_sync_002 - * @tc.desc Function of API, statSync. The parameter is the directory path. - */ - it('fileio_test_stat_stat_sync_002', 0, async function () { - let dpath = await nextFileName('fileio_test_stat_stat_sync_002') + 'd'; - fileio.mkdirSync(dpath); - try { - let stat = fileio.statSync(dpath); - expect(stat !== null).assertTrue(); - fileio.rmdirSync(dpath); - } - catch (e) { - console.log('fileio_test_stat_stat_sync_002 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_statSync_0300 - * @tc.name fileio_test_stat_stat_sync_003 - * @tc.desc Function of API, statSync. The file path is greater than 4096. - */ - it('fileio_test_stat_stat_sync_003', 0, async function () { - let dpath = await nextFileName('fileio_test_stat_stat_sync_003'); - fileio.mkdirSync(dpath); - try { - for (let i = 0; i < 16; i++) { - if (i == 15) { - let fpath = dpath + '/f' + i; - fileio.statSync(fpath); - } else { - dpath = dpath + '/d' + i; - fileio.mkdirSync(dpath); - } - } - expect(null).assertFail(); - } - catch (e) { - console.info('fileio_test_stat_stat_sync_003 has failed for ' + e); - forceRemoveDir(dpath, 15); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_Stat_dev_0000 - * @tc.name fileio_test_stat_dev_000 - * @tc.desc Function of API. Get the device number used by the file. - */ - it('fileio_test_stat_dev_000', 0, async function () { - let fpath = await nextFileName('fileio_test_stat_dev_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let stat = fileio.statSync(fpath); - expect(typeof(stat.dev) == 'number').assertTrue(); - fileio.unlinkSync(fpath); - } - catch (e) { - console.log('fileio_test_stat_dev_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_Stat_ino_0000 - * @tc.name fileio_test_stat_ino_000 - * @tc.desc Function of API. Get inode bigint. - */ - it('fileio_test_stat_ino_000', 0, async function () { - let fpath = await nextFileName('fileio_test_stat_ino_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let stat = fileio.statSync(fpath); - expect(typeof(stat.ino) == 'bigint').assertTrue(); - fileio.unlinkSync(fpath); - } - catch (e) { - console.log('fileio_test_stat_ino_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_Stat_mode_0000 - * @tc.name fileio_test_stat_mode_000 - * @tc.desc Function of API. Get file type and access rights. - */ - it('fileio_test_stat_mode_000', 0, async function () { - let fpath = await nextFileName('fileio_test_stat_mode_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let stat = fileio.statSync(fpath); - expect(typeof(stat.mode) == 'number').assertTrue(); - fileio.unlinkSync(fpath); - } - catch (e) { - console.log('fileio_test_stat_mode_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_Stat_nlink_0000 - * @tc.name fileio_test_stat_nlink_000 - * @tc.desc Function of API. Gets the number of hard connections to the file. - */ - it('fileio_test_stat_nlink_000', 0, async function () { - let fpath = await nextFileName('fileio_test_stat_nlink_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let stat = fileio.statSync(fpath); - expect(typeof(stat.nlink) == 'number').assertTrue(); - fileio.unlinkSync(fpath); - } - catch (e) { - console.log('fileio_test_stat_nlink_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_Stat_uid_0000 - * @tc.name fileio_test_stat_uid_000 - * @tc.desc Function of API. Get file owner user ID. - */ - it('fileio_test_stat_uid_000', 0, async function () { - let fpath = await nextFileName('fileio_test_stat_uid_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let stat = fileio.statSync(fpath); - expect(typeof(stat.uid) == 'number').assertTrue(); - fileio.unlinkSync(fpath); - } - catch (e) { - console.log('fileio_test_stat_uid_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_Stat_gid_0000 - * @tc.name fileio_test_stat_gid_000 - * @tc.desc Function of API. Get group ID. - */ - it('fileio_test_stat_gid_000', 0, async function () { - let fpath = await nextFileName('fileio_test_stat_gid_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let stat = fileio.statSync(fpath); - expect(typeof(stat.gid) == 'number').assertTrue(); - fileio.unlinkSync(fpath); - } - catch (e) { - console.log('fileio_test_stat_gid_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_Stat_rdev_0000 - * @tc.name fileio_test_stat_rdev_000 - * @tc.desc Function of API. Get the device number of the device file. - */ - it('fileio_test_stat_rdev_000', 0, async function () { - let fpath = await nextFileName('fileio_test_stat_rdev_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let stat = fileio.statSync(fpath); - expect(typeof(stat.rdev) == 'number').assertTrue(); - fileio.unlinkSync(fpath); - } - catch (e) { - console.log('fileio_test_stat_rdev_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_stat_size_0000 - * @tc.name fileio_test_stat_size_000 - * @tc.desc Function of API. Gets the file capacity in bytes. - */ - it('fileio_test_stat_size_000', 0, async function () { - let fpath = await nextFileName('fileio_test_stat_size_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let stat = fileio.statSync(fpath); - expect(typeof(stat.size) == 'number').assertTrue(); - fileio.unlinkSync(fpath); - } - catch (e) { - console.log('fileio_test_stat_size_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_Stat_blocks_0000 - * @tc.name fileio_test_stat_blocks_000 - * @tc.desc Function of API. Gets the disk block occupied by the file. - */ - it('fileio_test_stat_blocks_000', 0, async function () { - let fpath = await nextFileName('fileio_test_stat_blocks_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let stat = fileio.statSync(fpath); - expect(typeof(stat.blocks) == 'number').assertTrue(); - fileio.unlinkSync(fpath); - } - catch (e) { - console.log('fileio_test_stat_blocks_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_stat_atime_0000 - * @tc.name fileio_test_stat_atime_000 - * @tc.desc Function of API. Gets the time when a file was last accessed. - */ - it('fileio_test_stat_atime_000', 0, async function () { - let fpath = await nextFileName('fileio_test_stat_atime_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let stat = fileio.statSync(fpath); - expect(typeof(stat.atime) == 'number').assertTrue(); - fileio.unlinkSync(fpath); - } - catch (e) { - console.log('fileio_test_stat_atime_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_Stat_mtime_0000 - * @tc.name fileio_test_stat_mtime_000 - * @tc.desc Function of API. Gets the time when a file was last modified - */ - it('fileio_test_stat_mtime_000', 0, async function () { - let fpath = await nextFileName('fileio_test_stat_mtime_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let stat = fileio.statSync(fpath); - expect(typeof(stat.mtime) == 'number').assertTrue(); - fileio.unlinkSync(fpath); - } - catch (e) { - console.log('fileio_test_stat_mtime_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_Stat_ctime_0000 - * @tc.name fileio_test_stat_ctime_000 - * @tc.desc Function of API. Gets the time when a file last changed state - */ - it('fileio_test_stat_ctime_000', 0, async function () { - let fpath = await nextFileName('fileio_test_stat_ctime_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let stat = fileio.statSync(fpath); - expect(typeof(stat.ctime) == 'number').assertTrue(); - fileio.unlinkSync(fpath); - } - catch (e) { - console.log('fileio_test_stat_ctime_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_Stat_isBlockDevice_0000 - * @tc.name fileio_test_stat_is_block_device_000 - * @tc.desc Function of API, isBlockDevice. Determine whether it is a block device. The return value is Boolean. - */ - it('fileio_test_stat_is_block_device_000', 0, async function () { - let fpath = await nextFileName('fileio_test_stat_is_block_device_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let stat = fileio.statSync(fpath); - expect(typeof(stat.isBlockDevice()) == 'boolean').assertTrue(); - fileio.unlinkSync(fpath); - } - catch (e) { - console.log('fileio_test_stat_is_block_device_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_Stat_isBlockDevice_0100 - * @tc.name fileio_test_stat_is_block_device_001 - * @tc.desc Function of API, isBlockDevice. Determine whether it is a block device. The return value is false. - */ - it('fileio_test_stat_is_block_device_001', 0, async function () { - let fpath = await nextFileName('fileio_test_stat_is_block_device_001'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let stat = fileio.statSync(fpath); - expect(!stat.isBlockDevice()).assertTrue(); - fileio.unlinkSync(fpath); - } - catch (e) { - console.log('fileio_test_stat_is_block_device_001 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_Stat_isBlockDevice_0200 - * @tc.name fileio_test_stat_is_block_device_002 - * @tc.desc Function of API, isBlockDevice. The parameter is - 1 - */ - it('fileio_test_stat_is_block_device_002', 0, async function () { - let fpath = await nextFileName('fileio_test_stat_is_block_device_002'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let stat = fileio.statSync(fpath); - expect(!stat.isBlockDevice(-1)).assertTrue(); - expect(null).assertFail(); - } - catch (e) { - console.log('fileio_test_stat_is_block_device_002 has failed for ' + e); - expect(e.message == 'Number of arguments unmatched').assertTrue(); - fileio.unlinkSync(fpath); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_stat_isCharacterDevice_0000 - * @tc.name fileio_test_stat_is_character_device_000 - * @tc.desc Function of API, isCharacterDevice. - * Determine whether it is a character device. The return value is Boolean. - */ - it('fileio_test_stat_is_character_device_000', 0, async function () { - let fpath = await nextFileName('fileio_test_stat_is_character_device_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let stat = fileio.statSync(fpath); - expect(typeof(stat.isCharacterDevice()) == 'boolean').assertTrue(); - fileio.unlinkSync(fpath); - } - catch (e) { - console.log('fileio_test_stat_is_character_device_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_Stat_isCharacterDevice_0100 - * @tc.name fileio_test_stat_is_character_device_001 - * @tc.desc Function of API, isCharacterDevice. - * Determine whether it is a character device. The return value is false. - */ - it('fileio_test_stat_is_character_device_001', 0, async function () { - let fpath = await nextFileName('fileio_test_stat_is_character_device_001'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let stat = fileio.statSync(fpath); - expect(!stat.isCharacterDevice()).assertTrue(); - fileio.unlinkSync(fpath); - } - catch (e) { - console.log('fileio_test_stat_is_character_device_001 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_Stat_isCharacterDevice_0200 - * @tc.name fileio_test_stat_is_character_device_002 - * @tc.desc Function of API, isCharacterDevice. The parameter is - 1 - */ - it('fileio_test_stat_is_character_device_002', 0, async function () { - let fpath = await nextFileName('fileio_test_stat_is_character_device_002'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let stat = fileio.statSync(fpath); - expect(!stat.isCharacterDevice(-1)).assertTrue(); - expect(null).assertFail(); - } - catch (e) { - console.log('fileio_test_stat_is_character_device_002 has failed for ' + e); - expect(e.message == 'Number of arguments unmatched').assertTrue(); - fileio.unlinkSync(fpath); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_Stat_isDirectory_0000 - * @tc.name fileio_test_stat_is_directory_000 - * @tc.desc Function of API, isDirectory. Determine whether it is a directory. The return value is Boolean. - */ - it('fileio_test_stat_is_directory_000', 0, async function () { - let fpath = await nextFileName('fileio_test_stat_is_directory_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let stat = fileio.statSync(fpath); - expect(typeof(stat.isDirectory()) == 'boolean').assertTrue(); - fileio.unlinkSync(fpath); - } - catch (e) { - console.log('fileio_test_stat_is_directory_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_Stat_isDirectory_0100 - * @tc.name fileio_test_stat_is_directory_001 - * @tc.desc Function of API, isDirectory. Determine whether it is a directory. The return value is false. - */ - it('fileio_test_stat_is_directory_001', 0, async function () { - let fpath = await nextFileName('fileio_test_stat_is_directory_001'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let stat = fileio.statSync(fpath); - expect(!stat.isDirectory()).assertTrue(); - fileio.unlinkSync(fpath); - } - catch (e) { - console.log('fileio_test_stat_is_directory_001 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_Stat_isDirectory_0200 - * @tc.name fileio_test_stat_is_directory_002 - * @tc.desc Function of API, isDirectory. Determine whether it is a directory. The return value is true. - */ - it('fileio_test_stat_is_directory_002', 0, async function () { - let dpath = await nextFileName('fileio_test_stat_is_directory_002') + 'd' - try { - fileio.mkdirSync(dpath); - let stat = fileio.statSync(dpath); - expect(stat.isDirectory()).assertTrue(); - fileio.rmdirSync(dpath); - } - catch (e) { - console.log('fileio_test_stat_is_directory_002 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_Stat_isDirectory_0300 - * @tc.name fileio_test_stat_is_directory_003 - * @tc.desc Function of API, isDirectory. The parameter is - 1 - */ - it('fileio_test_stat_is_directory_003', 0, async function () { - let dpath = await nextFileName('fileio_test_stat_is_directory_003') + 'd' - try { - fileio.mkdirSync(dpath); - let stat = fileio.statSync(dpath); - expect(stat.isDirectory(-1) == null).assertTrue(); - expect(null).assertFail(); - } - catch (e) { - console.log('fileio_test_stat_is_directory_003 has failed for ' + e); - expect(e.message == 'Number of arguments unmatched').assertTrue(); - fileio.rmdirSync(dpath); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_stat_isFifo_0000 - * @tc.name fileio_test_stat_is_fifo_000 - * @tc.desc Function of API, isFIFO. Determine whether it is a fifo. The return value is Boolean. - */ - it('fileio_test_stat_is_fifo_000', 0, async function () { - let fpath = await nextFileName('fileio_test_stat_is_fifo_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let stat = fileio.statSync(fpath); - expect(typeof(stat.isFIFO()) == 'boolean').assertTrue(); - fileio.unlinkSync(fpath); - } - catch (e) { - console.log('fileio_test_stat_is_fifo_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_Stat_isFifo_0100 - * @tc.name fileio_test_stat_is_fifo_001 - * @tc.desc Function of API, isFIFO. Determine whether it is a fifo. The return value is false. - */ - it('fileio_test_stat_is_fifo_001', 0, async function () { - let fpath = await nextFileName('fileio_test_stat_is_fifo_001'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let stat = fileio.statSync(fpath); - expect(!stat.isFIFO()).assertTrue(); - fileio.unlinkSync(fpath); - } - catch (e) { - console.log('fileio_test_stat_is_fifo_001 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_Stat_isFifo_0200 - * @tc.name fileio_test_stat_is_fifo_002 - * @tc.desc Function of API, isFIFO. The parameter is - 1 - */ - it('fileio_test_stat_is_fifo_002', 0, async function () { - let fpath = await nextFileName('fileio_test_stat_is_fifo_002'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let stat = fileio.statSync(fpath); - expect(stat.isFIFO(-1) == null).assertTrue(); - expect(null).assertFail(); - } - catch (e) { - console.log('fileio_test_stat_is_fifo_002 has failed for ' + e); - expect(e.message == 'Number of arguments unmatched').assertTrue(); - fileio.unlinkSync(fpath); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_Stat_isFile_0000 - * @tc.name fileio_test_stat_is_file_000 - * @tc.desc Function of API, isFile. Determine whether it is a file. The return value is Boolean. - */ - it('fileio_test_stat_is_file_000', 0, async function () { - let fpath = await nextFileName('fileio_test_stat_is_file_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let stat = fileio.statSync(fpath); - expect(typeof(stat.isFile()) == 'boolean').assertTrue(); - fileio.unlinkSync(fpath); - } - catch (e) { - console.log('fileio_test_stat_is_file_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_Stat_isFile_0100 - * @tc.name fileio_test_stat_is_file_001 - * @tc.desc Function of API, isFile. Determine whether it is a file. The return value is true. - */ - it('fileio_test_stat_is_file_001', 0, async function () { - let fpath = await nextFileName('fileio_test_stat_is_file_001'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let stat = fileio.statSync(fpath); - expect(stat.isFile()).assertTrue(); - fileio.unlinkSync(fpath); - console.log('---fileio_test_stat_is_file_001 is passed!'); - } - catch (e) { - console.log('fileio_test_stat_is_file_001 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_Stat_isFile_0200 - * @tc.name fileio_test_stat_is_file_002 - * @tc.desc Function of API, isFile. Determine whether it is a file. The return value is false. - */ - it('fileio_test_stat_is_file_002', 0, async function () { - let dpath = await nextFileName('fileio_test_stat_is_file_002'); - try { - fileio.mkdirSync(dpath); - let stat = fileio.statSync(dpath); - expect(!stat.isFile()).assertTrue(); - fileio.rmdirSync(dpath); - } - catch (e) { - console.log('fileio_test_stat_is_file_002 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_Stat_isFile_0300 - * @tc.name fileio_test_stat_is_file_003 - * @tc.desc Function of API, isFile. The parameter is - 1 - */ - it('fileio_test_stat_is_file_003', 0, async function () { - let dpath = await nextFileName('fileio_test_stat_is_file_003'); - try { - fileio.mkdirSync(dpath); - let stat = fileio.statSync(dpath); - expect(stat.isFile(-1) == null).assertTrue(); - expect(null).assertFail(); - } - catch (e) { - console.log('fileio_test_stat_is_file_003 has failed for ' + e); - expect(e.message == 'Number of arguments unmatched').assertTrue(); - fileio.rmdirSync(dpath); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_Stat_isSocket_0000 - * @tc.name fileio_test_stat_is_socket_000 - * @tc.desc Function of API, isSocket. Determine whether it is a socket. The return value is Boolean. - */ - it('fileio_test_stat_is_socket_000', 0, async function () { - let fpath = await nextFileName('fileio_test_stat_is_socket_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let stat = fileio.statSync(fpath); - expect(typeof(stat.isSocket()) == 'boolean').assertTrue(); - fileio.unlinkSync(fpath); - } - catch (e) { - console.log('fileio_test_stat_is_socket_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_Stat_isSocket_0100 - * @tc.name fileio_test_stat_is_socket_001 - * @tc.desc Function of API, isSocket. Determine whether it is a socket. The return value is false. - */ - it('fileio_test_stat_is_socket_001', 0, async function () { - let fpath = await nextFileName('fileio_test_stat_is_socket_001'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let stat = fileio.statSync(fpath); - expect(!stat.isSocket()).assertTrue(); - fileio.unlinkSync(fpath); - } - catch (e) { - console.log('fileio_test_stat_is_socket_001 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_Stat_isSocket_0200 - * @tc.name fileio_test_stat_is_socket_002 - * @tc.desc Function of API, isSocket. The parameter is - 1 - */ - it('fileio_test_stat_is_socket_002', 0, async function () { - let fpath = await nextFileName('fileio_test_stat_is_socket_002'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let stat = fileio.statSync(fpath); - expect(stat.isSocket(-1) == null).assertTrue(); - expect(null).assertFail(); - } - catch (e) { - console.log('fileio_test_stat_is_socket_002 has failed for ' + e); - expect(e.message == 'Number of arguments unmatched').assertTrue(); - fileio.unlinkSync(fpath); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_Stat_isSymbolicLink_0000 - * @tc.name fileio_test_stat_is_symbolic_link_000 - * @tc.desc Function of API, isSymbolicLink. Determine whether it is a symbolic link. The return value is Boolean. - */ - it('fileio_test_stat_is_symbolic_link_000', 0, async function () { - let fpath = await nextFileName('fileio_test_stat_is_symbolic_link_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let stat = fileio.statSync(fpath); - expect(typeof(stat.isSymbolicLink()) == 'boolean').assertTrue(); - fileio.unlinkSync(fpath); - } - catch (e) { - console.log('fileio_test_stat_is_symbolic_link_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_Stat_isSymbolicLink_0100 - * @tc.name fileio_test_stat_is_symbolic_link_001 - * @tc.desc Function of API, isSymbolicLink. Determine whether it is a symbolic link. The return value is false. - */ - it('fileio_test_stat_is_symbolic_link_001', 0, async function () { - let fpath = await nextFileName('fileio_test_stat_is_symbolic_link_001'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let stat = fileio.statSync(fpath); - expect(!stat.isSymbolicLink()).assertTrue(); - fileio.unlinkSync(fpath); - } - catch (e) { - console.log('fileio_test_stat_is_symbolic_link_001 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_Stat_isSymbolicLink_0200 - * @tc.name fileio_test_stat_is_symbolic_link_002 - * @tc.desc Function of API, isSymbolicLink. The parameter is - 1 - */ - it('fileio_test_stat_is_symbolic_link_002', 0, async function () { - let fpath = await nextFileName('fileio_test_stat_is_symbolic_link_002'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let stat = fileio.statSync(fpath); - expect(stat.isSymbolicLink(-1) == null).assertTrue(); - expect(null).assertFail(); - } - catch (e) { - console.log('fileio_test_stat_is_symbolic_link_002 has failed for ' + e); - expect(e.message == 'Number of arguments unmatched').assertTrue(); - fileio.unlinkSync(fpath); - } - }); - -}); -} +/* + * Copyright (C) 2021 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 fileio from '@ohos.fileio'; +import { describe,it,expect}from '@ohos/hypium' +import { + FILE_CONTENT, + prepareFile, + nextFileName, + randomString, + forceRemoveDir +} + from './Common' + +export default function fileIOTestStat() { +describe('fileIOTestStat', function () { + + /** + * @tc.number SUB_STORAGE_FileIO_statSync_0000 + * @tc.name fileio_test_stat_stat_sync_000 + * @tc.desc Function of API, statSync. Gets information about the file in the specified path. + */ + it('fileio_test_stat_stat_sync_000', 0, async function () { + let fpath = await nextFileName('fileio_test_stat_stat_sync_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let stat = fileio.statSync(fpath); + expect(stat !== null).assertTrue(); + fileio.unlinkSync(fpath); + } + catch (e) { + console.log('fileio_test_stat_stat_sync_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_statSync_0100 + * @tc.name fileio_test_stat_stat_sync_001 + * @tc.desc Function of API, statSync. The specified file does not exist. + */ + it('fileio_test_stat_stat_sync_001', 0, async function () { + let fpath = await nextFileName('fileio_test_stat_stat_sync_001'); + try { + fileio.statSync(fpath); + expect(null).assertFail(); + } + catch (e) { + console.log('fileio_test_stat_stat_sync_001 has failed for ' + e); + expect(e.message == 'No such file or directory').assertTrue(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_statSync_0200 + * @tc.name fileio_test_stat_stat_sync_002 + * @tc.desc Function of API, statSync. The parameter is the directory path. + */ + it('fileio_test_stat_stat_sync_002', 0, async function () { + let dpath = await nextFileName('fileio_test_stat_stat_sync_002') + 'd'; + fileio.mkdirSync(dpath); + try { + let stat = fileio.statSync(dpath); + expect(stat !== null).assertTrue(); + fileio.rmdirSync(dpath); + } + catch (e) { + console.log('fileio_test_stat_stat_sync_002 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_statSync_0300 + * @tc.name fileio_test_stat_stat_sync_003 + * @tc.desc Function of API, statSync. The file path is greater than 4096. + */ + it('fileio_test_stat_stat_sync_003', 0, async function () { + let dpath = await nextFileName('fileio_test_stat_stat_sync_003'); + fileio.mkdirSync(dpath); + try { + for (let i = 0; i < 16; i++) { + if (i == 15) { + let fpath = dpath + '/f' + i; + fileio.statSync(fpath); + } else { + dpath = dpath + '/d' + i; + fileio.mkdirSync(dpath); + } + } + expect(null).assertFail(); + } + catch (e) { + console.info('fileio_test_stat_stat_sync_003 has failed for ' + e); + forceRemoveDir(dpath, 15); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_Stat_dev_0000 + * @tc.name fileio_test_stat_dev_000 + * @tc.desc Function of API. Get the device number used by the file. + */ + it('fileio_test_stat_dev_000', 0, async function () { + let fpath = await nextFileName('fileio_test_stat_dev_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let stat = fileio.statSync(fpath); + expect(typeof(stat.dev) == 'number').assertTrue(); + fileio.unlinkSync(fpath); + } + catch (e) { + console.log('fileio_test_stat_dev_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_Stat_ino_0000 + * @tc.name fileio_test_stat_ino_000 + * @tc.desc Function of API. Get inode bigint. + */ + it('fileio_test_stat_ino_000', 0, async function () { + let fpath = await nextFileName('fileio_test_stat_ino_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let stat = fileio.statSync(fpath); + expect(typeof(stat.ino) == 'bigint').assertTrue(); + fileio.unlinkSync(fpath); + } + catch (e) { + console.log('fileio_test_stat_ino_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_Stat_mode_0000 + * @tc.name fileio_test_stat_mode_000 + * @tc.desc Function of API. Get file type and access rights. + */ + it('fileio_test_stat_mode_000', 0, async function () { + let fpath = await nextFileName('fileio_test_stat_mode_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let stat = fileio.statSync(fpath); + expect(typeof(stat.mode) == 'number').assertTrue(); + fileio.unlinkSync(fpath); + } + catch (e) { + console.log('fileio_test_stat_mode_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_Stat_nlink_0000 + * @tc.name fileio_test_stat_nlink_000 + * @tc.desc Function of API. Gets the number of hard connections to the file. + */ + it('fileio_test_stat_nlink_000', 0, async function () { + let fpath = await nextFileName('fileio_test_stat_nlink_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let stat = fileio.statSync(fpath); + expect(typeof(stat.nlink) == 'number').assertTrue(); + fileio.unlinkSync(fpath); + } + catch (e) { + console.log('fileio_test_stat_nlink_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_Stat_uid_0000 + * @tc.name fileio_test_stat_uid_000 + * @tc.desc Function of API. Get file owner user ID. + */ + it('fileio_test_stat_uid_000', 0, async function () { + let fpath = await nextFileName('fileio_test_stat_uid_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let stat = fileio.statSync(fpath); + expect(typeof(stat.uid) == 'number').assertTrue(); + fileio.unlinkSync(fpath); + } + catch (e) { + console.log('fileio_test_stat_uid_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_Stat_gid_0000 + * @tc.name fileio_test_stat_gid_000 + * @tc.desc Function of API. Get group ID. + */ + it('fileio_test_stat_gid_000', 0, async function () { + let fpath = await nextFileName('fileio_test_stat_gid_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let stat = fileio.statSync(fpath); + expect(typeof(stat.gid) == 'number').assertTrue(); + fileio.unlinkSync(fpath); + } + catch (e) { + console.log('fileio_test_stat_gid_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_Stat_rdev_0000 + * @tc.name fileio_test_stat_rdev_000 + * @tc.desc Function of API. Get the device number of the device file. + */ + it('fileio_test_stat_rdev_000', 0, async function () { + let fpath = await nextFileName('fileio_test_stat_rdev_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let stat = fileio.statSync(fpath); + expect(typeof(stat.rdev) == 'number').assertTrue(); + fileio.unlinkSync(fpath); + } + catch (e) { + console.log('fileio_test_stat_rdev_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_stat_size_0000 + * @tc.name fileio_test_stat_size_000 + * @tc.desc Function of API. Gets the file capacity in bytes. + */ + it('fileio_test_stat_size_000', 0, async function () { + let fpath = await nextFileName('fileio_test_stat_size_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let stat = fileio.statSync(fpath); + expect(typeof(stat.size) == 'number').assertTrue(); + fileio.unlinkSync(fpath); + } + catch (e) { + console.log('fileio_test_stat_size_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_Stat_blocks_0000 + * @tc.name fileio_test_stat_blocks_000 + * @tc.desc Function of API. Gets the disk block occupied by the file. + */ + it('fileio_test_stat_blocks_000', 0, async function () { + let fpath = await nextFileName('fileio_test_stat_blocks_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let stat = fileio.statSync(fpath); + expect(typeof(stat.blocks) == 'number').assertTrue(); + fileio.unlinkSync(fpath); + } + catch (e) { + console.log('fileio_test_stat_blocks_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_stat_atime_0000 + * @tc.name fileio_test_stat_atime_000 + * @tc.desc Function of API. Gets the time when a file was last accessed. + */ + it('fileio_test_stat_atime_000', 0, async function () { + let fpath = await nextFileName('fileio_test_stat_atime_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let stat = fileio.statSync(fpath); + expect(typeof(stat.atime) == 'number').assertTrue(); + fileio.unlinkSync(fpath); + } + catch (e) { + console.log('fileio_test_stat_atime_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_Stat_mtime_0000 + * @tc.name fileio_test_stat_mtime_000 + * @tc.desc Function of API. Gets the time when a file was last modified + */ + it('fileio_test_stat_mtime_000', 0, async function () { + let fpath = await nextFileName('fileio_test_stat_mtime_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let stat = fileio.statSync(fpath); + expect(typeof(stat.mtime) == 'number').assertTrue(); + fileio.unlinkSync(fpath); + } + catch (e) { + console.log('fileio_test_stat_mtime_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_Stat_ctime_0000 + * @tc.name fileio_test_stat_ctime_000 + * @tc.desc Function of API. Gets the time when a file last changed state + */ + it('fileio_test_stat_ctime_000', 0, async function () { + let fpath = await nextFileName('fileio_test_stat_ctime_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let stat = fileio.statSync(fpath); + expect(typeof(stat.ctime) == 'number').assertTrue(); + fileio.unlinkSync(fpath); + } + catch (e) { + console.log('fileio_test_stat_ctime_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_Stat_isBlockDevice_0000 + * @tc.name fileio_test_stat_is_block_device_000 + * @tc.desc Function of API, isBlockDevice. Determine whether it is a block device. The return value is Boolean. + */ + it('fileio_test_stat_is_block_device_000', 0, async function () { + let fpath = await nextFileName('fileio_test_stat_is_block_device_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let stat = fileio.statSync(fpath); + expect(typeof(stat.isBlockDevice()) == 'boolean').assertTrue(); + fileio.unlinkSync(fpath); + } + catch (e) { + console.log('fileio_test_stat_is_block_device_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_Stat_isBlockDevice_0100 + * @tc.name fileio_test_stat_is_block_device_001 + * @tc.desc Function of API, isBlockDevice. Determine whether it is a block device. The return value is false. + */ + it('fileio_test_stat_is_block_device_001', 0, async function () { + let fpath = await nextFileName('fileio_test_stat_is_block_device_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let stat = fileio.statSync(fpath); + expect(!stat.isBlockDevice()).assertTrue(); + fileio.unlinkSync(fpath); + } + catch (e) { + console.log('fileio_test_stat_is_block_device_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_Stat_isBlockDevice_0200 + * @tc.name fileio_test_stat_is_block_device_002 + * @tc.desc Function of API, isBlockDevice. The parameter is - 1 + */ + it('fileio_test_stat_is_block_device_002', 0, async function () { + let fpath = await nextFileName('fileio_test_stat_is_block_device_002'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let stat = fileio.statSync(fpath); + expect(!stat.isBlockDevice(-1)).assertTrue(); + expect(null).assertFail(); + } + catch (e) { + console.log('fileio_test_stat_is_block_device_002 has failed for ' + e); + expect(e.message == 'Number of arguments unmatched').assertTrue(); + fileio.unlinkSync(fpath); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_stat_isCharacterDevice_0000 + * @tc.name fileio_test_stat_is_character_device_000 + * @tc.desc Function of API, isCharacterDevice. + * Determine whether it is a character device. The return value is Boolean. + */ + it('fileio_test_stat_is_character_device_000', 0, async function () { + let fpath = await nextFileName('fileio_test_stat_is_character_device_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let stat = fileio.statSync(fpath); + expect(typeof(stat.isCharacterDevice()) == 'boolean').assertTrue(); + fileio.unlinkSync(fpath); + } + catch (e) { + console.log('fileio_test_stat_is_character_device_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_Stat_isCharacterDevice_0100 + * @tc.name fileio_test_stat_is_character_device_001 + * @tc.desc Function of API, isCharacterDevice. + * Determine whether it is a character device. The return value is false. + */ + it('fileio_test_stat_is_character_device_001', 0, async function () { + let fpath = await nextFileName('fileio_test_stat_is_character_device_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let stat = fileio.statSync(fpath); + expect(!stat.isCharacterDevice()).assertTrue(); + fileio.unlinkSync(fpath); + } + catch (e) { + console.log('fileio_test_stat_is_character_device_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_Stat_isCharacterDevice_0200 + * @tc.name fileio_test_stat_is_character_device_002 + * @tc.desc Function of API, isCharacterDevice. The parameter is - 1 + */ + it('fileio_test_stat_is_character_device_002', 0, async function () { + let fpath = await nextFileName('fileio_test_stat_is_character_device_002'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let stat = fileio.statSync(fpath); + expect(!stat.isCharacterDevice(-1)).assertTrue(); + expect(null).assertFail(); + } + catch (e) { + console.log('fileio_test_stat_is_character_device_002 has failed for ' + e); + expect(e.message == 'Number of arguments unmatched').assertTrue(); + fileio.unlinkSync(fpath); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_Stat_isDirectory_0000 + * @tc.name fileio_test_stat_is_directory_000 + * @tc.desc Function of API, isDirectory. Determine whether it is a directory. The return value is Boolean. + */ + it('fileio_test_stat_is_directory_000', 0, async function () { + let fpath = await nextFileName('fileio_test_stat_is_directory_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let stat = fileio.statSync(fpath); + expect(typeof(stat.isDirectory()) == 'boolean').assertTrue(); + fileio.unlinkSync(fpath); + } + catch (e) { + console.log('fileio_test_stat_is_directory_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_Stat_isDirectory_0100 + * @tc.name fileio_test_stat_is_directory_001 + * @tc.desc Function of API, isDirectory. Determine whether it is a directory. The return value is false. + */ + it('fileio_test_stat_is_directory_001', 0, async function () { + let fpath = await nextFileName('fileio_test_stat_is_directory_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let stat = fileio.statSync(fpath); + expect(!stat.isDirectory()).assertTrue(); + fileio.unlinkSync(fpath); + } + catch (e) { + console.log('fileio_test_stat_is_directory_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_Stat_isDirectory_0200 + * @tc.name fileio_test_stat_is_directory_002 + * @tc.desc Function of API, isDirectory. Determine whether it is a directory. The return value is true. + */ + it('fileio_test_stat_is_directory_002', 0, async function () { + let dpath = await nextFileName('fileio_test_stat_is_directory_002') + 'd' + try { + fileio.mkdirSync(dpath); + let stat = fileio.statSync(dpath); + expect(stat.isDirectory()).assertTrue(); + fileio.rmdirSync(dpath); + } + catch (e) { + console.log('fileio_test_stat_is_directory_002 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_Stat_isDirectory_0300 + * @tc.name fileio_test_stat_is_directory_003 + * @tc.desc Function of API, isDirectory. The parameter is - 1 + */ + it('fileio_test_stat_is_directory_003', 0, async function () { + let dpath = await nextFileName('fileio_test_stat_is_directory_003') + 'd' + try { + fileio.mkdirSync(dpath); + let stat = fileio.statSync(dpath); + expect(stat.isDirectory(-1) == null).assertTrue(); + expect(null).assertFail(); + } + catch (e) { + console.log('fileio_test_stat_is_directory_003 has failed for ' + e); + expect(e.message == 'Number of arguments unmatched').assertTrue(); + fileio.rmdirSync(dpath); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_stat_isFifo_0000 + * @tc.name fileio_test_stat_is_fifo_000 + * @tc.desc Function of API, isFIFO. Determine whether it is a fifo. The return value is Boolean. + */ + it('fileio_test_stat_is_fifo_000', 0, async function () { + let fpath = await nextFileName('fileio_test_stat_is_fifo_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let stat = fileio.statSync(fpath); + expect(typeof(stat.isFIFO()) == 'boolean').assertTrue(); + fileio.unlinkSync(fpath); + } + catch (e) { + console.log('fileio_test_stat_is_fifo_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_Stat_isFifo_0100 + * @tc.name fileio_test_stat_is_fifo_001 + * @tc.desc Function of API, isFIFO. Determine whether it is a fifo. The return value is false. + */ + it('fileio_test_stat_is_fifo_001', 0, async function () { + let fpath = await nextFileName('fileio_test_stat_is_fifo_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let stat = fileio.statSync(fpath); + expect(!stat.isFIFO()).assertTrue(); + fileio.unlinkSync(fpath); + } + catch (e) { + console.log('fileio_test_stat_is_fifo_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_Stat_isFifo_0200 + * @tc.name fileio_test_stat_is_fifo_002 + * @tc.desc Function of API, isFIFO. The parameter is - 1 + */ + it('fileio_test_stat_is_fifo_002', 0, async function () { + let fpath = await nextFileName('fileio_test_stat_is_fifo_002'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let stat = fileio.statSync(fpath); + expect(stat.isFIFO(-1) == null).assertTrue(); + expect(null).assertFail(); + } + catch (e) { + console.log('fileio_test_stat_is_fifo_002 has failed for ' + e); + expect(e.message == 'Number of arguments unmatched').assertTrue(); + fileio.unlinkSync(fpath); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_Stat_isFile_0000 + * @tc.name fileio_test_stat_is_file_000 + * @tc.desc Function of API, isFile. Determine whether it is a file. The return value is Boolean. + */ + it('fileio_test_stat_is_file_000', 0, async function () { + let fpath = await nextFileName('fileio_test_stat_is_file_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let stat = fileio.statSync(fpath); + expect(typeof(stat.isFile()) == 'boolean').assertTrue(); + fileio.unlinkSync(fpath); + } + catch (e) { + console.log('fileio_test_stat_is_file_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_Stat_isFile_0100 + * @tc.name fileio_test_stat_is_file_001 + * @tc.desc Function of API, isFile. Determine whether it is a file. The return value is true. + */ + it('fileio_test_stat_is_file_001', 0, async function () { + let fpath = await nextFileName('fileio_test_stat_is_file_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let stat = fileio.statSync(fpath); + expect(stat.isFile()).assertTrue(); + fileio.unlinkSync(fpath); + console.log('---fileio_test_stat_is_file_001 is passed!'); + } + catch (e) { + console.log('fileio_test_stat_is_file_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_Stat_isFile_0200 + * @tc.name fileio_test_stat_is_file_002 + * @tc.desc Function of API, isFile. Determine whether it is a file. The return value is false. + */ + it('fileio_test_stat_is_file_002', 0, async function () { + let dpath = await nextFileName('fileio_test_stat_is_file_002'); + try { + fileio.mkdirSync(dpath); + let stat = fileio.statSync(dpath); + expect(!stat.isFile()).assertTrue(); + fileio.rmdirSync(dpath); + } + catch (e) { + console.log('fileio_test_stat_is_file_002 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_Stat_isFile_0300 + * @tc.name fileio_test_stat_is_file_003 + * @tc.desc Function of API, isFile. The parameter is - 1 + */ + it('fileio_test_stat_is_file_003', 0, async function () { + let dpath = await nextFileName('fileio_test_stat_is_file_003'); + try { + fileio.mkdirSync(dpath); + let stat = fileio.statSync(dpath); + expect(stat.isFile(-1) == null).assertTrue(); + expect(null).assertFail(); + } + catch (e) { + console.log('fileio_test_stat_is_file_003 has failed for ' + e); + expect(e.message == 'Number of arguments unmatched').assertTrue(); + fileio.rmdirSync(dpath); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_Stat_isSocket_0000 + * @tc.name fileio_test_stat_is_socket_000 + * @tc.desc Function of API, isSocket. Determine whether it is a socket. The return value is Boolean. + */ + it('fileio_test_stat_is_socket_000', 0, async function () { + let fpath = await nextFileName('fileio_test_stat_is_socket_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let stat = fileio.statSync(fpath); + expect(typeof(stat.isSocket()) == 'boolean').assertTrue(); + fileio.unlinkSync(fpath); + } + catch (e) { + console.log('fileio_test_stat_is_socket_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_Stat_isSocket_0100 + * @tc.name fileio_test_stat_is_socket_001 + * @tc.desc Function of API, isSocket. Determine whether it is a socket. The return value is false. + */ + it('fileio_test_stat_is_socket_001', 0, async function () { + let fpath = await nextFileName('fileio_test_stat_is_socket_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let stat = fileio.statSync(fpath); + expect(!stat.isSocket()).assertTrue(); + fileio.unlinkSync(fpath); + } + catch (e) { + console.log('fileio_test_stat_is_socket_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_Stat_isSocket_0200 + * @tc.name fileio_test_stat_is_socket_002 + * @tc.desc Function of API, isSocket. The parameter is - 1 + */ + it('fileio_test_stat_is_socket_002', 0, async function () { + let fpath = await nextFileName('fileio_test_stat_is_socket_002'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let stat = fileio.statSync(fpath); + expect(stat.isSocket(-1) == null).assertTrue(); + expect(null).assertFail(); + } + catch (e) { + console.log('fileio_test_stat_is_socket_002 has failed for ' + e); + expect(e.message == 'Number of arguments unmatched').assertTrue(); + fileio.unlinkSync(fpath); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_Stat_isSymbolicLink_0000 + * @tc.name fileio_test_stat_is_symbolic_link_000 + * @tc.desc Function of API, isSymbolicLink. Determine whether it is a symbolic link. The return value is Boolean. + */ + it('fileio_test_stat_is_symbolic_link_000', 0, async function () { + let fpath = await nextFileName('fileio_test_stat_is_symbolic_link_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let stat = fileio.statSync(fpath); + expect(typeof(stat.isSymbolicLink()) == 'boolean').assertTrue(); + fileio.unlinkSync(fpath); + } + catch (e) { + console.log('fileio_test_stat_is_symbolic_link_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_Stat_isSymbolicLink_0100 + * @tc.name fileio_test_stat_is_symbolic_link_001 + * @tc.desc Function of API, isSymbolicLink. Determine whether it is a symbolic link. The return value is false. + */ + it('fileio_test_stat_is_symbolic_link_001', 0, async function () { + let fpath = await nextFileName('fileio_test_stat_is_symbolic_link_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let stat = fileio.statSync(fpath); + expect(!stat.isSymbolicLink()).assertTrue(); + fileio.unlinkSync(fpath); + } + catch (e) { + console.log('fileio_test_stat_is_symbolic_link_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_Stat_isSymbolicLink_0200 + * @tc.name fileio_test_stat_is_symbolic_link_002 + * @tc.desc Function of API, isSymbolicLink. The parameter is - 1 + */ + it('fileio_test_stat_is_symbolic_link_002', 0, async function () { + let fpath = await nextFileName('fileio_test_stat_is_symbolic_link_002'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let stat = fileio.statSync(fpath); + expect(stat.isSymbolicLink(-1) == null).assertTrue(); + expect(null).assertFail(); + } + catch (e) { + console.log('fileio_test_stat_is_symbolic_link_002 has failed for ' + e); + expect(e.message == 'Number of arguments unmatched').assertTrue(); + fileio.unlinkSync(fpath); + } + }); + +}); +} diff --git a/storage/storagefileiojstest/entry/src/ohosTest/js/test/FileIOStream.test.js b/storage/storagefileiojstest/src/main/js/test/FileIOStream.test.js similarity index 97% rename from storage/storagefileiojstest/entry/src/ohosTest/js/test/FileIOStream.test.js rename to storage/storagefileiojstest/src/main/js/test/FileIOStream.test.js index 3612764b3b1fefdec08d85d5601f18aab9de2d90..4494cc827632b883db1349768037ea503e8d6a41 100644 --- a/storage/storagefileiojstest/entry/src/ohosTest/js/test/FileIOStream.test.js +++ b/storage/storagefileiojstest/src/main/js/test/FileIOStream.test.js @@ -1,2007 +1,2007 @@ -/* - * Copyright (C) 2023 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 fileio from '@ohos.fileio'; -import { describe,it,expect}from '@ohos/hypium' -import { - FILE_CONTENT, - prepareFile, - fileToReadOnly, - fileToWriteOnly, - nextFileName, - randomString, - forceRemoveDir -} - from './Common' - -export default function fileIOTestStream() { -describe('fileIOTestStream', function () { - - /** - * @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_0000 - * @tc.name fileio_test_stream_create_stream_sync_000 - * @tc.desc Function of API, mode = r. The test file is exist. - */ - it('fileio_test_stream_create_stream_sync_000', 0, async function () { - let fpath = await nextFileName('fileio_test_stream_create_stream_sync_000'); - expect(prepareFile(fpath, 'hello')).assertTrue(); - expect(fileToReadOnly(fpath)).assertTrue(); - try { - let ss = fileio.createStreamSync(fpath, 'r'); - expect(ss !== null).assertTrue(); - ss.closeSync(); - fileio.unlinkSync(fpath); - console.info('fileio_test_stream_create_stream_sync_000 is passed!'); - } - catch (e) { - console.info('fileio_test_stream_create_stream_sync_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_0100 - * @tc.name fileio_test_stream_create_stream_sync_001 - * @tc.desc Function of API, mode = r. The test file is not exist. - */ - it('fileio_test_stream_create_stream_sync_001', 0, async function () { - let fpath = await nextFileName('fileio_test_stream_create_stream_sync_001'); - try { - fileio.createStreamSync(fpath, 'r'); - expect(null).assertFail(); - } - catch (e) { - console.info('fileio_test_stream_create_stream_sync_001 has failed for ' + e); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_0200 - * @tc.name fileio_test_stream_create_stream_sync_002 - * @tc.desc Function of API, mode = w. The test file is exist. - */ - it('fileio_test_stream_create_stream_sync_002', 0, async function () { - let fpath = await nextFileName('fileio_test_stream_create_stream_sync_002'); - expect(prepareFile(fpath, '')).assertTrue(); - expect(fileToWriteOnly(fpath)).assertTrue(); - let text = '0123456789abcdefg'; - try { - let ss = fileio.createStreamSync(fpath, 'w'); - expect(ss !== null).assertTrue(); - let wlen = ss.writeSync(text); - expect(wlen !== null).assertTrue(); - ss.closeSync(); - expect(fileToReadOnly(fpath)).assertTrue(); - ss = fileio.createStreamSync(fpath, 'r'); - let rlen = ss.readSync(new ArrayBuffer(4096)); - expect(rlen == text.length).assertTrue(); - ss.closeSync(); - fileio.unlinkSync(fpath); - } - catch (e) { - console.info('fileio_test_stream_create_stream_sync_002 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_0300 - * @tc.name fileio_test_stream_create_stream_sync_003 - * @tc.desc Function of API, mode = w. The test file is not exist. - */ - it('fileio_test_stream_create_stream_sync_003', 0, async function () { - let fpath = await nextFileName('fileio_test_stream_create_stream_sync_003'); - try { - let ss = fileio.createStreamSync(fpath, 'w'); - expect(ss !== null).assertTrue(); - ss.closeSync(); - fileio.unlinkSync(fpath); - } - catch (e) { - console.info('fileio_test_stream_create_stream_sync_003 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_0400 - * @tc.name fileio_test_stream_create_stream_sync_004 - * @tc.desc Function of API, mode = a. The test file is exist. - */ - it('fileio_test_stream_create_stream_sync_004', 0, async function () { - let fpath = await nextFileName('fileio_test_stream_create_stream_sync_004'); - expect(prepareFile(fpath, 'a')).assertTrue(); - expect(fileToWriteOnly(fpath)).assertTrue(); - let text = '0123456789abcdefg'; - try { - let ss = fileio.createStreamSync(fpath, 'a'); - expect(ss !== null).assertTrue(); - let wlen = ss.writeSync(text); - expect(wlen !== null).assertTrue(); - ss.closeSync(); - expect(fileToReadOnly(fpath)).assertTrue(); - ss = fileio.createStreamSync(fpath, 'r'); - let rlen = ss.readSync(new ArrayBuffer(4096)); - expect(rlen == text.length + 1).assertTrue(); - ss.closeSync(); - fileio.unlinkSync(fpath); - } - catch (e) { - console.info('fileio_test_stream_create_stream_sync_004 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_0500 - * @tc.name fileio_test_stream_create_stream_sync_005 - * @tc.desc Function of API, mode = a. The test file is not exist. - */ - it('fileio_test_stream_create_stream_sync_005', 0, async function () { - let fpath = await nextFileName('fileio_test_stream_create_stream_sync_005'); - try { - let ss = fileio.createStreamSync(fpath, 'a'); - expect(ss !== null).assertTrue(); - ss.closeSync(); - fileio.unlinkSync(fpath); - } - catch (e) { - console.info('fileio_test_stream_create_stream_sync_005 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_0600 - * @tc.name fileio_test_stream_create_stream_sync_006 - * @tc.desc Function of API, mode = r+. The test file is exist. - */ - it('fileio_test_stream_create_stream_sync_006', 0, async function () { - let fpath = await nextFileName('fileio_test_stream_create_stream_sync_006'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let ss = fileio.createStreamSync(fpath, 'r+'); - expect(ss !== null).assertTrue(); - ss.closeSync(); - fileio.unlinkSync(fpath); - } - catch (e) { - console.info('fileio_test_stream_create_stream_sync_006 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_0700 - * @tc.name fileio_test_stream_create_stream_sync_007 - * @tc.desc Function of API, mode = r+. The test file is not exist. - */ - it('fileio_test_stream_create_stream_sync_007', 0, async function () { - let fpath = await nextFileName('fileio_test_stream_create_stream_sync_007'); - try { - fileio.createStreamSync(fpath, 'r+'); - expect(null).assertFail(); - } - catch (e) { - console.info('fileio_test_stream_create_stream_sync_007 has failed for ' + e); - expect(e.message == 'No such file or directory').assertTrue(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_0800 - * @tc.name fileio_test_stream_create_stream_sync_008 - * @tc.desc Function of API, mode = w+. The test file is exist. - */ - it('fileio_test_stream_create_stream_sync_008', 0, async function () { - let fpath = await nextFileName('fileio_test_stream_create_stream_sync_008'); - expect(prepareFile(fpath, '')).assertTrue(); - let text = '0123456789abcdefg'; - try { - let ss = fileio.createStreamSync(fpath, 'w+'); - expect(ss !== null).assertTrue(); - let wlen = ss.writeSync(text); - expect(wlen !== null).assertTrue(); - ss.closeSync(); - expect(fileToReadOnly(fpath)).assertTrue(); - ss = fileio.createStreamSync(fpath, 'r'); - let rlen = ss.readSync(new ArrayBuffer(4096)); - expect(rlen == text.length).assertTrue(); - ss.closeSync(); - fileio.unlinkSync(fpath); - } - catch (e) { - console.info('fileio_test_stream_create_stream_sync_008 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_0900 - * @tc.name fileio_test_stream_create_stream_sync_009 - * @tc.desc Function of API, mode = w+. The test file is not exist. - */ - it('fileio_test_stream_create_stream_sync_009', 0, async function () { - let fpath = await nextFileName('fileio_test_stream_create_stream_sync_009'); - try { - let ss = fileio.createStreamSync(fpath, 'w+'); - expect(ss !== null).assertTrue(); - ss.closeSync(); - fileio.unlinkSync(fpath); - } - catch (e) { - console.info('fileio_test_stream_create_stream_sync_009 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_1000 - * @tc.name fileio_test_stream_create_stream_sync_010 - * @tc.desc Function of API, mode = a+. The test file is exist. - */ - it('fileio_test_stream_create_stream_sync_010', 0, async function () { - let fpath = await nextFileName('fileio_test_stream_create_stream_sync_010'); - expect(prepareFile(fpath, 'a')).assertTrue(); - let text = '0123456789abcdefg'; - try { - let ss = fileio.createStreamSync(fpath, 'a+'); - expect(ss !== null).assertTrue(); - let wlen = ss.writeSync(text); - expect(wlen !== null).assertTrue(); - ss.closeSync(); - expect(fileToReadOnly(fpath)).assertTrue(); - ss = fileio.createStreamSync(fpath, 'r'); - let rlen = ss.readSync(new ArrayBuffer(4096)); - expect(rlen == text.length + 1).assertTrue(); - ss.closeSync(); - fileio.unlinkSync(fpath); - } - catch (e) { - console.info('fileio_test_stream_create_stream_sync_010 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_1100 - * @tc.name fileio_test_stream_create_stream_sync_011 - * @tc.desc Function of API, mode = a+. The test file is not exist. - */ - it('fileio_test_stream_create_stream_sync_011', 0, async function () { - let fpath = await nextFileName('fileio_test_stream_create_stream_sync_011'); - try { - let ss = fileio.createStreamSync(fpath, 'a+'); - expect(ss !== null).assertTrue(); - ss.closeSync(); - fileio.unlinkSync(fpath); - } - catch (e) { - console.info('fileio_test_stream_create_stream_sync_011 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_1200 - * @tc.name fileio_test_stream_create_stream_sync_012 - * @tc.desc Function of API, mode = rb. The test file is exist. - */ - it('fileio_test_stream_create_stream_sync_012', 0, async function () { - let fpath = await nextFileName('fileio_test_stream_create_stream_sync_012'); - expect(prepareFile(fpath, '')).assertTrue(); - expect(fileToReadOnly(fpath)).assertTrue(); - try { - let ss = fileio.createStreamSync(fpath, 'rb'); - expect(ss !== null).assertTrue(); - ss.closeSync(); - fileio.unlinkSync(fpath); - } - catch (e) { - console.info('fileio_test_stream_create_stream_sync_012 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_1300 - * @tc.name fileio_test_stream_create_stream_sync_013 - * @tc.desc Function of API, mode = ab. The test file is not exist. - */ - it('fileio_test_stream_create_stream_sync_013', 0, async function () { - let fpath = await nextFileName('fileio_test_stream_create_stream_sync_013'); - try { - fileio.createStreamSync(fpath, 'rb'); - expect(null).assertFail(); - } - catch (e) { - console.info('fileio_test_stream_create_stream_sync_013 has failed for ' + e); - expect(e.message == 'No such file or directory').assertTrue(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_1400 - * @tc.name fileio_test_stream_create_stream_sync_014 - * @tc.desc Function of API, mode = wb. The test file is exist. - */ - it('fileio_test_stream_create_stream_sync_014', 0, async function () { - let fpath = await nextFileName('fileio_test_stream_create_stream_sync_014'); - expect(prepareFile(fpath, '')).assertTrue(); - expect(fileToWriteOnly(fpath)).assertTrue(); - let text = '0123456789abcdefg'; - try { - let ss = fileio.createStreamSync(fpath, 'wb'); - expect(ss !== null).assertTrue(); - let wlen = ss.writeSync(text); - expect(wlen !== null).assertTrue(); - ss.closeSync(); - expect(fileToReadOnly(fpath)).assertTrue(); - ss = fileio.createStreamSync(fpath, 'r'); - let rlen = ss.readSync(new ArrayBuffer(4096)); - expect(rlen == text.length).assertTrue(); - ss.closeSync(); - fileio.unlinkSync(fpath); - } - catch (e) { - console.info('fileio_test_stream_create_stream_sync_014 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_1500 - * @tc.name fileio_test_stream_create_stream_sync_015 - * @tc.desc Function of API, mode = wb. The test file is not exist. - */ - it('fileio_test_stream_create_stream_sync_015', 0, async function () { - let fpath = await nextFileName('fileio_test_stream_create_stream_sync_015'); - try { - let ss = fileio.createStreamSync(fpath, 'wb'); - expect(ss !== null).assertTrue(); - ss.closeSync(); - fileio.unlinkSync(fpath); - } - catch (e) { - console.info('fileio_test_stream_create_stream_sync_015 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_1600 - * @tc.name fileio_test_stream_create_stream_sync_016 - * @tc.desc Function of API, mode = ab. The test file is exist. - */ - it('fileio_test_stream_create_stream_sync_016', 0, async function () { - let fpath = await nextFileName('fileio_test_stream_create_stream_sync_016'); - expect(prepareFile(fpath, 'a')).assertTrue(); - expect(fileToWriteOnly(fpath)).assertTrue(); - let text = '0123456789abcdefg'; - try { - let ss = fileio.createStreamSync(fpath, 'ab'); - expect(ss !== null).assertTrue(); - let wlen = ss.writeSync(text); - expect(wlen !== null).assertTrue(); - ss.closeSync(); - expect(fileToReadOnly(fpath)).assertTrue(); - ss = fileio.createStreamSync(fpath, 'r'); - let rlen = ss.readSync(new ArrayBuffer(4096)); - expect(rlen == text.length + 1).assertTrue(); - ss.closeSync(); - fileio.unlinkSync(fpath); - console.info('fileio_test_stream_create_stream_sync_016 is passed!'); - } - catch (e) { - console.info('fileio_test_stream_create_stream_sync_016 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_1700 - * @tc.name fileio_test_stream_create_stream_sync_017 - * @tc.desc Function of API, mode = ab. The test file is not exist. - */ - it('fileio_test_stream_create_stream_sync_017', 0, async function () { - let fpath = await nextFileName('fileio_test_stream_create_stream_sync_017'); - try { - let ss = fileio.createStreamSync(fpath, 'ab'); - expect(ss !== null).assertTrue(); - ss.closeSync(); - fileio.unlinkSync(fpath); - } - catch (e) { - console.info('fileio_test_stream_create_stream_sync_017 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_1800 - * @tc.name fileio_test_stream_create_stream_sync_018 - * @tc.desc Function of API, mode = rb+. The test file is exist. - */ - it('fileio_test_stream_create_stream_sync_018', 0, async function () { - let fpath = await nextFileName('fileio_test_stream_create_stream_sync_018'); - expect(prepareFile(fpath, '')).assertTrue(); - try { - let ss = fileio.createStreamSync(fpath, 'rb+'); - expect(ss !== null).assertTrue(); - ss.closeSync(); - fileio.unlinkSync(fpath); - } - catch (e) { - console.info('fileio_test_stream_create_stream_sync_018 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_1900 - * @tc.name fileio_test_stream_create_stream_sync_019 - * @tc.desc Function of API, mode = rb+. The test file is not exist. - */ - it('fileio_test_stream_create_stream_sync_019', 0, async function () { - let fpath = await nextFileName('fileio_test_stream_create_stream_sync_019'); - try { - fileio.createStreamSync(fpath, 'rb+'); - expect(null).assertFail(); - } - catch (e) { - console.info('fileio_test_stream_create_stream_sync_019 has failed for ' + e); - expect(e.message == 'No such file or directory').assertTrue(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_2000 - * @tc.name fileio_test_stream_create_stream_sync_020 - * @tc.desc Function of API, mode = wb+. The test file is exist. - */ - it('fileio_test_stream_create_stream_sync_020', 0, async function () { - let fpath = await nextFileName('fileio_test_stream_create_stream_sync_020'); - expect(prepareFile(fpath, '')).assertTrue(); - let text = '0123456789abcdefg'; - try { - let ss = fileio.createStreamSync(fpath, 'wb+'); - expect(ss !== null).assertTrue(); - let wlen = ss.writeSync(text); - expect(wlen !== null).assertTrue(); - ss.closeSync(); - expect(fileToReadOnly(fpath)).assertTrue(); - ss = fileio.createStreamSync(fpath, 'r'); - let rlen = ss.readSync(new ArrayBuffer(4096)); - expect(rlen == text.length).assertTrue(); - ss.closeSync(); - fileio.unlinkSync(fpath); - } - catch (e) { - console.info('fileio_test_stream_create_stream_sync_020 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_2100 - * @tc.name fileio_test_stream_create_stream_sync_021 - * @tc.desc Function of API, mode = wb+. The test file is not exist. - */ - it('fileio_test_stream_create_stream_sync_021', 0, async function () { - let fpath = await nextFileName('fileio_test_stream_create_stream_sync_021'); - try { - let ss = fileio.createStreamSync(fpath, 'wb+'); - expect(ss !== null).assertTrue(); - ss.closeSync(); - fileio.unlinkSync(fpath); - } - catch (e) { - console.info('fileio_test_stream_create_stream_sync_021 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_2200 - * @tc.name fileio_test_stream_create_stream_sync_022 - * @tc.desc Function of API, mode = ab+. The test file is exist. - */ - it('fileio_test_stream_create_stream_sync_022', 0, async function () { - let fpath = await nextFileName('fileio_test_stream_create_stream_sync_022'); - expect(prepareFile(fpath, 'a')).assertTrue(); - let text = '0123456789abcdefg'; - try { - let ss = fileio.createStreamSync(fpath, 'ab+'); - expect(ss !== null).assertTrue(); - let wlen = ss.writeSync(text); - expect(wlen !== null).assertTrue(); - ss.closeSync(); - expect(fileToReadOnly(fpath)).assertTrue(); - ss = fileio.createStreamSync(fpath, 'r'); - let rlen = ss.readSync(new ArrayBuffer(4096)); - expect(rlen == text.length + 1).assertTrue(); - ss.closeSync(); - fileio.unlinkSync(fpath); - } - catch (e) { - console.info('fileio_test_stream_create_stream_sync_022 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_2300 - * @tc.name fileio_test_stream_create_stream_sync_023 - * @tc.desc Function of API, mode = ab+. The test file is not exist. - */ - it('fileio_test_stream_create_stream_sync_023', 0, async function () { - let fpath = await nextFileName('fileio_test_stream_create_stream_sync_023'); - try { - let ss = fileio.createStreamSync(fpath, 'ab+'); - expect(ss !== null).assertTrue(); - ss.closeSync(); - fileio.unlinkSync(fpath); - } - catch (e) { - console.info('fileio_test_stream_create_stream_sync_023 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_2400 - * @tc.name fileio_test_stream_create_stream_sync_024 - * @tc.desc Function of API, invalid fpath. - */ - it('fileio_test_stream_create_stream_sync_024', 0, function () { - try { - fileio.createStreamSync('', 'r'); - expect(null).assertFail(); - } - catch (e) { - console.info('fileio_test_stream_create_stream_sync_024 has failed for ' + e); - expect(e.message == 'No such file or directory').assertTrue(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_2500 - * @tc.name fileio_test_stream_create_stream_sync_025 - * @tc.desc Function of API, invalid mode. - */ - it('fileio_test_stream_create_stream_sync_025', 0, async function () { - let fpath = await nextFileName('fileio_test_stream_create_stream_sync_025'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - fileio.createStreamSync(fpath, ''); - throw new Error('invalid mode'); - } - catch (e) { - console.info('fileio_test_stream_create_stream_sync_025 has failed for ' + e); - fileio.unlinkSync(fpath); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_2600 - * @tc.name fileio_test_stream_create_stream_sync_026 - * @tc.desc Function of API, fpath too long. - */ - it('fileio_test_stream_create_stream_sync_026', 0, async function () { - let dpath = await nextFileName('fileio_test_stream_create_stream_sync_026'); - fileio.mkdirSync(dpath); - try { - for (let i = 0; i < 16; i++) { - if (i == 15) { - let fpath = dpath + '/f' + i; - fileio.createStreamSync(fpath, 'w+'); - fileio.unlinkSync(fpath); - } else { - dpath = dpath + '/d' + i; - fileio.mkdirSync(dpath); - } - } - throw new Error('fpath too long'); - } - catch (e) { - console.info('fileio_test_stream_create_stream_sync_026 has failed for ' + e); - forceRemoveDir(dpath, 15); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_2700 - * @tc.name fileio_test_stream_create_stream_sync_027 - * @tc.desc Function of API, filename too long. - */ - it('fileio_test_stream_create_stream_sync_027', 0, async function () { - let fpath = await nextFileName(randomString(256)); - try { - fileio.createStreamSync(fpath, 'w+'); - expect(null).assertFail(); - } - catch (e) { - console.info('fileio_test_stream_create_stream_sync_027 has failed for ' + e); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_2800 - * @tc.name fileio_test_stream_create_stream_sync_028 - * @tc.desc Function of API, path too deep. - */ - it('fileio_test_stream_create_stream_sync_028', 0, async function () { - let dpath = await nextFileName('fileio_test_stream_create_stream_sync_028'); - fileio.mkdirSync(dpath); - try { - for (let i = 0; i < 113; i++) { - if (i == 112) { - let fpath = dpath + '/f' + i - fileio.createStreamSync(fpath, 'w+'); - fileio.unlinkSync(fpath); - } else { - dpath = dpath + '/d' + i - fileio.mkdirSync(dpath); - } - } - throw new Error('path too deep'); - } - catch (e) { - console.info('fileio_test_stream_create_stream_sync_028 has failed for ' + e); - forceRemoveDir(dpath, 112); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_2900 - * @tc.name fileio_test_stream_create_stream_sync_029 - * @tc.desc Function of API, special character. - */ - it('fileio_test_stream_create_stream_sync_029', 0, async function () { - let fpath = await nextFileName('?*:<>/|'); - try { - fileio.createStreamSync(fpath, 'w+'); - expect(null).assertFail(); - } - catch (e) { - console.info('fileio_test_stream_create_stream_sync_029 has failed for ' + e); - expect(e.message == 'No such file or directory').assertTrue(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_3000 - * @tc.name fileio_test_stream_create_stream_sync_030 - * @tc.desc Function of API, mode = w+. Test file length is cleared to 0. - */ - it('fileio_test_stream_create_stream_sync_030', 0, async function () { - let fpath = await nextFileName('fileio_test_stream_create_stream_sync_030'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let fd = fileio.openSync(fpath, 0o102, 0o666); - let buf = new ArrayBuffer(4096); - let number = fileio.readSync(fd, buf); - expect(number == 11).assertTrue(); - let ss = fileio.createStreamSync(fpath, 'w+'); - let num = ss.readSync(buf); - expect(num == 0).assertTrue(); - ss.closeSync(); - fileio.unlinkSync(fpath); - } - catch (e) { - console.info('fileio_test_stream_create_stream_sync_030 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_3100 - * @tc.name fileio_test_stream_create_stream_sync_031 - * @tc.desc Function of API, mode = w. Test file length is cleared to 0. - */ - it('fileio_test_stream_create_stream_sync_031', 0, async function () { - let fpath = await nextFileName('fileio_test_stream_create_stream_sync_031'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let fd = fileio.openSync(fpath, 0o102, 0o666); - let buf = new ArrayBuffer(4096); - let number = fileio.readSync(fd, buf); - expect(number == 11).assertTrue(); - let ss = fileio.createStreamSync(fpath, 'w'); - let num = fileio.readSync(fd, buf); - expect(num == 0).assertTrue(); - ss.closeSync(); - fileio.unlinkSync(fpath); - } - catch (e) { - console.info('fileio_test_stream_create_stream_sync_031 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_stream_FdopenStreamSync_0000 - * @tc.name fileio_test_stream_fdopen_stream_sync_000 - * @tc.desc Function of API, mode=r. The test file is exist. - */ - it('fileio_test_stream_fdopen_stream_sync_000', 0, async function () { - let fpath = await nextFileName('fileio_test_stream_fdopen_stream_sync_000'); - expect(prepareFile(fpath, '')).assertTrue(); - expect(fileToReadOnly(fpath)).assertTrue(); - try { - let fd = fileio.openSync(fpath, 0o0); - let ss = fileio.fdopenStreamSync(fd, 'r'); - expect(ss !== null).assertTrue(); - ss.closeSync(); - fileio.unlinkSync(fpath); - } - catch (e) { - console.info('fileio_test_stream_fdopen_stream_sync_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_stream_FdopenStreamSync_0100 - * @tc.name fileio_test_stream_fdopen_stream_sync_001 - * @tc.desc Function of API, mode=r. The test file is not exist. - */ - it('fileio_test_stream_fdopen_stream_sync_001', 0, function () { - try { - let fd = -1; - let mode = 'r'; - fileio.fdopenStreamSync(fd, mode); - throw new Error('Bad file descriptor'); - } - catch (e) { - console.info('fileio_test_stream_fdopen_stream_sync_001 has failed for ' + e); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_stream_FdopenStreamSync_0200 - * @tc.name fileio_test_stream_fdopen_stream_sync_002 - * @tc.desc Function of API, mode=w. The test file is exist. - */ - it('fileio_test_stream_fdopen_stream_sync_002', 0, async function () { - let fpath = await nextFileName('fileio_test_stream_fdopen_stream_sync_002'); - let fd; - expect(prepareFile(fpath, '')).assertTrue(); - expect(fileToWriteOnly(fpath)).assertTrue(); - let text = '0123456789abcdefg'; - try { - fd = fileio.openSync(fpath, 0o001); - expect(fd !== null).assertTrue(); - let ss = fileio.fdopenStreamSync(fd, 'w'); - expect(ss !== null).assertTrue(); - let wlen = ss.writeSync(text); - expect(wlen !== null).assertTrue(); - ss.closeSync(); - expect(fileToReadOnly(fpath)).assertTrue(); - ss = fileio.createStreamSync(fpath, 'r'); - let rlen = ss.readSync(new ArrayBuffer(4096)); - expect(rlen == text.length).assertTrue(); - ss.closeSync(); - fileio.unlinkSync(fpath); - } - catch (e) { - console.info('fileio_test_stream_fdopen_stream_sync_002 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_stream_FdopenStreamSync_0300 - * @tc.name fileio_test_stream_fdopen_stream_sync_003 - * @tc.desc Function of API, mode=w. The test file is not exist. - */ - it('fileio_test_stream_fdopen_stream_sync_003', 0, async function () { - let fpath = await nextFileName('fileio_test_stream_fdopen_stream_sync_003'); - try { - let fd = fileio.openSync(fpath, 0o101, 0o222); - let ss = fileio.fdopenStreamSync(fd, 'w'); - expect(ss !== null).assertTrue(); - ss.closeSync(); - fileio.unlinkSync(fpath); - } - catch (e) { - console.info('fileio_test_stream_fdopen_stream_sync_003 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_stream_FdopenStreamSync_0400 - * @tc.name fileio_test_stream_fdopen_stream_sync_004 - * @tc.desc Function of API, mode=a. The test file is exist. - */ - it('fileio_test_stream_fdopen_stream_sync_004', 0, async function () { - let fpath = await nextFileName('fileio_test_stream_fdopen_stream_sync_004'); - expect(prepareFile(fpath, '1')).assertTrue(); - expect(fileToWriteOnly(fpath)).assertTrue(); - let text = '0123456789abcdefg'; - try { - let fd = fileio.openSync(fpath, 0o2001); - expect(fd !== null).assertTrue(); - let ss = fileio.fdopenStreamSync(fd, 'a'); - expect(ss !== null).assertTrue(); - let wlen = ss.writeSync(text); - expect(wlen !== null).assertTrue(); - ss.closeSync(); - expect(fileToReadOnly(fpath)).assertTrue(); - ss = fileio.createStreamSync(fpath, 'r'); - let rlen = ss.readSync(new ArrayBuffer(4096)); - expect(rlen == text.length + 1).assertTrue(); - ss.closeSync(); - fileio.unlinkSync(fpath); - } - catch (e) { - console.info('fileio_test_stream_fdopen_stream_sync_004 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_stream_FdopenStreamSync_0500 - * @tc.name fileio_test_stream_fdopen_stream_sync_005 - * @tc.desc Function of API, mode=a. The test file is not exist. - */ - it('fileio_test_stream_fdopen_stream_sync_005', 0, async function () { - let fpath = await nextFileName('fileio_test_stream_fdopen_stream_sync_005'); - try { - let fd = fileio.openSync(fpath, 0o101, 0o222); - let ss = fileio.fdopenStreamSync(fd, 'a'); - expect(ss !== null).assertTrue(); - ss.closeSync(); - fileio.unlinkSync(fpath); - } - catch (e) { - console.info('fileio_test_stream_fdopen_stream_sync_005 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_stream_FdopenStreamSync_0600 - * @tc.name fileio_test_stream_fdopen_stream_sync_006 - * @tc.desc Function of API, mode=r+. The test file is exist. - */ - it('fileio_test_stream_fdopen_stream_sync_006', 0, async function () { - let fpath = await nextFileName('fileio_test_stream_fdopen_stream_sync_006'); - expect(prepareFile(fpath, '')).assertTrue(); - try { - let fd = fileio.openSync(fpath, 0o2); - let ss = fileio.fdopenStreamSync(fd, 'r+'); - expect(ss !== null).assertTrue(); - ss.closeSync(); - fileio.unlinkSync(fpath); - } - catch (e) { - console.info('fileio_test_stream_fdopen_stream_sync_006 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_stream_FdopenStreamSync_0700 - * @tc.name fileio_test_stream_fdopen_stream_sync_007 - * @tc.desc Function of API, mode=r+. The test file is not exist. - */ - it('fileio_test_stream_fdopen_stream_sync_007', 0, async function () { - try { - fileio.fdopenStreamSync(-1, 'r+'); - throw new Error('Bad file descriptor'); - } - catch (e) { - console.info('fileio_test_stream_fdopen_stream_sync_007 has failed for ' + e); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_stream_FdopenStreamSync_0800 - * @tc.name fileio_test_stream_fdopen_stream_sync_008 - * @tc.desc Function of API, mode=w+. The test file is exist. - */ - it('fileio_test_stream_fdopen_stream_sync_008', 0, async function () { - let fpath = await nextFileName('fileio_test_stream_fdopen_stream_sync_008'); - expect(prepareFile(fpath, '')).assertTrue(); - let text = '0123456789abcdefg'; - try { - let fd = fileio.openSync(fpath, 0o2); - expect(fd !== null).assertTrue(); - let ss = fileio.fdopenStreamSync(fd, 'w+'); - expect(ss !== null).assertTrue(); - let wlen = ss.writeSync(text); - expect(wlen !== null).assertTrue(); - ss.closeSync(); - expect(fileToReadOnly(fpath)).assertTrue(); - ss = fileio.createStreamSync(fpath, 'r'); - let rlen = ss.readSync(new ArrayBuffer(4096)); - expect(rlen == text.length).assertTrue(); - ss.closeSync(); - fileio.unlinkSync(fpath); - } - catch (e) { - console.info('fileio_test_stream_fdopen_stream_sync_008 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_stream_FdopenStreamSync_0900 - * @tc.name fileio_test_stream_fdopen_stream_sync_009 - * @tc.desc Function of API, mode=w+. The test file is not exist. - */ - it('fileio_test_stream_fdopen_stream_sync_009', 0, async function () { - let fpath = await nextFileName('fileio_test_stream_fdopen_stream_sync_009'); - try { - let fd = fileio.openSync(fpath, 0o102, 0o666); - let ss = fileio.fdopenStreamSync(fd, 'w+'); - expect(ss !== null).assertTrue(); - ss.closeSync(); - fileio.unlinkSync(fpath); - } - catch (e) { - console.info('fileio_test_stream_fdopen_stream_sync_009 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_stream_FdopenStreamSync_1000 - * @tc.name fileio_test_stream_fdopen_stream_sync_010 - * @tc.desc Function of API, mode=a+. The test file is exist. - */ - it('fileio_test_stream_fdopen_stream_sync_010', 0, async function () { - let fpath = await nextFileName('fileio_test_stream_fdopen_stream_sync_010'); - expect(prepareFile(fpath, '1')).assertTrue(); - let text = '0123456789abcdefg'; - try { - let fd = fileio.openSync(fpath, 0o2002); - expect(fd !== null).assertTrue(); - let ss = fileio.fdopenStreamSync(fd, 'a+'); - expect(ss !== null).assertTrue(); - let wlen = ss.writeSync(text); - expect(wlen !== null).assertTrue(); - ss.closeSync(); - expect(fileToReadOnly(fpath)).assertTrue(); - ss = fileio.createStreamSync(fpath, 'r'); - let rlen = ss.readSync(new ArrayBuffer(4096)); - expect(rlen == text.length + 1).assertTrue(); - ss.closeSync(); - fileio.unlinkSync(fpath); - } - catch (e) { - console.info('fileio_test_stream_fdopen_stream_sync_010 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_stream_FdopenStreamSync_1100 - * @tc.name fileio_test_stream_fdopen_stream_sync_011 - * @tc.desc Function of API, mode=a+. The test file is not exist. - */ - it('fileio_test_stream_fdopen_stream_sync_011', 0, async function () { - let fpath = await nextFileName('fileio_test_stream_fdopen_stream_sync_011'); - try { - let fd = fileio.openSync(fpath, 0o102, 0o666); - let ss = fileio.fdopenStreamSync(fd, 'a+'); - expect(ss !== null).assertTrue(); - ss.closeSync(); - fileio.unlinkSync(fpath); - } - catch (e) { - console.info('fileio_test_stream_fdopen_stream_sync_011 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_stream_FdopenStreamSync_1200 - * @tc.name fileio_test_stream_fdopen_stream_sync_012 - * @tc.desc Function of API, mode=rb. The test file is exist. - */ - it('fileio_test_stream_fdopen_stream_sync_012', 0, async function () { - let fpath = await nextFileName('fileio_test_stream_fdopen_stream_sync_012'); - expect(prepareFile(fpath, '')).assertTrue(); - expect(fileToReadOnly(fpath)).assertTrue(); - try { - let fd = fileio.openSync(fpath, 0o0); - let ss = fileio.fdopenStreamSync(fd, 'rb'); - expect(ss !== null).assertTrue(); - ss.closeSync(); - fileio.unlinkSync(fpath); - } - catch (e) { - console.info('fileio_test_stream_fdopen_stream_sync_012 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_stream_FdopenStreamSync_1300 - * @tc.name fileio_test_stream_fdopen_stream_sync_013 - * @tc.desc Function of API, mode=rb. The test file is not exist. - */ - it('fileio_test_stream_fdopen_stream_sync_013', 0, async function () { - try { - fileio.fdopenStreamSync(-1, 'rb'); - throw new Error('Bad file descriptor'); - } - catch (e) { - console.info('fileio_test_stream_fdopen_stream_sync_013 has failed for ' + e); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_stream_FdopenStreamSync_1400 - * @tc.name fileio_test_stream_fdopen_stream_sync_014 - * @tc.desc Function of API, mode=wb. The test file is exist. - */ - it('fileio_test_stream_fdopen_stream_sync_014', 0, async function () { - let fpath = await nextFileName('fileio_test_stream_fdopen_stream_sync_014'); - expect(prepareFile(fpath, '')).assertTrue(); - expect(fileToWriteOnly(fpath)).assertTrue(); - let text = '0123456789abcdefg'; - try { - let fd = fileio.openSync(fpath, 0o001); - expect(fd !== null).assertTrue(); - let ss = fileio.fdopenStreamSync(fd, 'wb'); - expect(ss !== null).assertTrue(); - let wlen = ss.writeSync(text); - expect(wlen !== null).assertTrue(); - ss.closeSync(); - expect(fileToReadOnly(fpath)).assertTrue(); - ss = fileio.createStreamSync(fpath, 'r'); - let rlen = ss.readSync(new ArrayBuffer(4096)); - expect(rlen == text.length).assertTrue(); - ss.closeSync(); - fileio.unlinkSync(fpath); - } - catch (e) { - console.info('fileio_test_stream_fdopen_stream_sync_014 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_stream_FdopenStreamSync_1500 - * @tc.name fileio_test_stream_fdopen_stream_sync_015 - * @tc.desc Function of API, mode=wb. The test file is not exist. - */ - it('fileio_test_stream_fdopen_stream_sync_015', 0, async function () { - let fpath = await nextFileName('fileio_test_stream_fdopen_stream_sync_015'); - try { - let fd = fileio.openSync(fpath, 0o101, 0o222); - let ss = fileio.fdopenStreamSync(fd, 'wb'); - expect(ss !== null).assertTrue(); - ss.closeSync(); - fileio.unlinkSync(fpath); - } - catch (e) { - console.info('fileio_test_stream_fdopen_stream_sync_015 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_stream_FdopenStreamSync_1600 - * @tc.name fileio_test_stream_fdopen_stream_sync_016 - * @tc.desc Function of API, mode=ab. The test file is exist. - */ - it('fileio_test_stream_fdopen_stream_sync_016', 0, async function () { - let fpath = await nextFileName('fileio_test_stream_fdopen_stream_sync_016'); - expect(prepareFile(fpath, '1')).assertTrue(); - expect(fileToWriteOnly(fpath)).assertTrue(); - let text = '0123456789abcdefg'; - try { - let fd = fileio.openSync(fpath, 0o2001); - expect(fd !== null).assertTrue(); - let ss = fileio.fdopenStreamSync(fd, 'ab'); - expect(ss !== null).assertTrue(); - let wlen = ss.writeSync(text); - expect(wlen !== null).assertTrue(); - ss.closeSync(); - expect(fileToReadOnly(fpath)).assertTrue(); - ss = fileio.createStreamSync(fpath, 'r'); - let rlen = ss.readSync(new ArrayBuffer(4096)); - expect(rlen == text.length + 1).assertTrue(); - ss.closeSync(); - fileio.unlinkSync(fpath); - } - catch (e) { - console.info('fileio_test_stream_fdopen_stream_sync_016 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_stream_FdopenStreamSync_1700 - * @tc.name fileio_test_stream_fdopen_stream_sync_017 - * @tc.desc Function of API, mode=ab. The test file is not exist. - */ - it('fileio_test_stream_fdopen_stream_sync_017', 0, async function () { - let fpath = await nextFileName('fileio_test_stream_fdopen_stream_sync_017'); - try { - let fd = fileio.openSync(fpath, 0o101, 0o222); - let ss = fileio.fdopenStreamSync(fd, 'ab'); - expect(ss !== null).assertTrue(); - ss.closeSync(); - fileio.unlinkSync(fpath); - } - catch (e) { - console.info('fileio_test_stream_fdopen_stream_sync_017 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_stream_FdopenStreamSync_1800 - * @tc.name fileio_test_stream_fdopen_stream_sync_018 - * @tc.desc Function of API, mode=rb+. The test file is exist. - */ - it('fileio_test_stream_fdopen_stream_sync_018', 0, async function () { - let fpath = await nextFileName('fileio_test_stream_fdopen_stream_sync_018'); - expect(prepareFile(fpath, '')).assertTrue(); - try { - let fd = fileio.openSync(fpath, 0o2); - let ss = fileio.fdopenStreamSync(fd, 'rb+'); - expect(ss !== null).assertTrue(); - ss.closeSync(); - fileio.unlinkSync(fpath); - } - catch (e) { - console.info('fileio_test_stream_fdopen_stream_sync_018 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_stream_FdopenStreamSync_1900 - * @tc.name fileio_test_stream_fdopen_stream_sync_019 - * @tc.desc Function of API, mode=rb+. The test file is not exist. - */ - it('fileio_test_stream_fdopen_stream_sync_019', 0, async function () { - try { - fileio.fdopenStreamSync(-1, 'rb+'); - throw new Error('Bad file descriptor'); - } - catch (e) { - console.info('fileio_test_stream_fdopen_stream_sync_019 has failed for ' + e); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_stream_FdopenStreamSync_2000 - * @tc.name fileio_test_stream_fdopen_stream_sync_020 - * @tc.desc Function of API, mode=wb+. The test file is exist. - */ - it('fileio_test_stream_fdopen_stream_sync_020', 0, async function () { - let fpath = await nextFileName('fileio_test_stream_fdopen_stream_sync_020'); - expect(prepareFile(fpath, '')).assertTrue(); - let text = '0123456789abcdefg'; - try { - let fd = fileio.openSync(fpath, 0o002); - expect(fd !== null).assertTrue(); - let ss = fileio.fdopenStreamSync(fd, 'wb+'); - expect(ss !== null).assertTrue(); - let wlen = ss.writeSync(text); - expect(wlen !== null).assertTrue(); - ss.closeSync(); - expect(fileToReadOnly(fpath)).assertTrue(); - ss = fileio.createStreamSync(fpath, 'r'); - let rlen = ss.readSync(new ArrayBuffer(4096)); - expect(rlen == text.length).assertTrue(); - ss.closeSync(); - fileio.unlinkSync(fpath); - } - catch (e) { - console.info('fileio_test_stream_fdopen_stream_sync_020 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_stream_FdopenStreamSync_2100 - * @tc.name fileio_test_stream_fdopen_stream_sync_021 - * @tc.desc Function of API, mode=wb+. The test file is not exist. - */ - it('fileio_test_stream_fdopen_stream_sync_021', 0, async function () { - let fpath = await nextFileName('fileio_test_stream_fdopen_stream_sync_021'); - try { - let fd = fileio.openSync(fpath, 0o102, 0o666); - let ss = fileio.fdopenStreamSync(fd, 'wb+'); - expect(ss !== null).assertTrue(); - ss.closeSync(); - fileio.unlinkSync(fpath); - } - catch (e) { - console.info('fileio_test_stream_fdopen_stream_sync_021 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_stream_FdopenStreamSync_2200 - * @tc.name fileio_test_stream_fdopen_stream_sync_022 - * @tc.desc Function of API, mode=ab+. The test file is exist. - */ - it('fileio_test_stream_fdopen_stream_sync_022', 0, async function () { - let fpath = await nextFileName('fileio_test_stream_fdopen_stream_sync_022'); - expect(prepareFile(fpath, '1')).assertTrue(); - let text = '0123456789abcdefg'; - try { - let fd = fileio.openSync(fpath, 0o2002); - expect(fd !== null).assertTrue(); - let ss = fileio.fdopenStreamSync(fd, 'ab+'); - expect(ss !== null).assertTrue(); - let wlen = ss.writeSync(text); - expect(wlen !== null).assertTrue(); - ss.closeSync(); - expect(fileToReadOnly(fpath)).assertTrue(); - ss = fileio.createStreamSync(fpath, 'r'); - let rlen = ss.readSync(new ArrayBuffer(4096)); - expect(rlen == text.length + 1).assertTrue(); - ss.closeSync(); - fileio.unlinkSync(fpath); - } - catch (e) { - console.info('fileio_test_stream_fdopen_stream_sync_022 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_stream_FdopenStreamSync_2300 - * @tc.name fileio_test_stream_fdopen_stream_sync_023 - * @tc.desc Function of API, mode=ab+. The test file is not exist. - */ - it('fileio_test_stream_fdopen_stream_sync_023', 0, async function () { - let fpath = await nextFileName('fileio_test_stream_fdopen_stream_sync_023'); - try { - let fd = fileio.openSync(fpath, 0o102, 0o666); - let ss = fileio.fdopenStreamSync(fd, 'ab+'); - expect(ss !== null).assertTrue(); - ss.closeSync(); - fileio.unlinkSync(fpath); - } - catch (e) { - console.info('fileio_test_stream_fdopen_stream_sync_023 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_stream_FdopenStreamSync_2400 - * @tc.name fileio_test_stream_fdopen_stream_sync_024 - * @tc.desc Function of API, invalid fields. The test file is not exist. - */ - it('fileio_test_stream_fdopen_stream_sync_024', 0, async function () { - try { - fileio.fdopenStreamSync(null, 'r') - expect(null).assertFail(); - } - catch (e) { - console.info('fileio_test_stream_fdopen_stream_sync_024 has failed for ' + e); - expect(e.message == 'Arg fd is required to be type integer').assertTrue(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_stream_FdopenStreamSync_2400 - * @tc.name fileio_test_stream_fdopen_stream_sync_025 - * @tc.desc Function of API, invalid mode. The test file is exist. - */ - it('fileio_test_stream_fdopen_stream_sync_025', 0, async function () { - let fpath = await nextFileName('fileio_test_stream_fdopen_stream_sync_025'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let fd = fileio.openSync(fpath, 0o2); - fileio.fdopenStreamSync(fd, ''); - throw new Error('invalid mode'); - } - catch (e) { - console.info('fileio_test_stream_fdopen_stream_sync_025 has failed for ' + e); - fileio.unlinkSync(fpath); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_stream_ReadSync_0000 - * @tc.name fileio_test_stream_read_sync_000 - * @tc.desc Function of API, not set options. - */ - it('fileio_test_stream_read_sync_000', 0, async function () { - let fpath = await nextFileName('fileio_test_stream_read_sync_000'); - let text = '0123456789abcdefg'; - expect(prepareFile(fpath, text)).assertTrue(); - try { - let ss = fileio.createStreamSync(fpath, 'r+'); - expect(ss !== null).assertTrue(); - let len = ss.readSync(new ArrayBuffer(4096)); - expect(len == text.length).assertTrue(); - ss.closeSync(); - fileio.unlinkSync(fpath); - } - catch (e) { - console.info('fileio_test_stream_read_sync_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_stream_ReadSync_0100 - * @tc.name fileio_test_stream_read_sync_001 - * @tc.desc Function of API, position. - */ - it('fileio_test_stream_read_sync_001', 0, async function () { - let fpath = await nextFileName('fileio_test_stream_read_sync_001'); - let text = '0123456789abcdefg'; - expect(prepareFile(fpath, text)).assertTrue(); - try { - let ss = fileio.createStreamSync(fpath, 'r+'); - expect(ss !== null).assertTrue(); - let len = ss.readSync(new ArrayBuffer(4096), { - position: 1 - }); - expect(len == text.length - 1).assertTrue(); - ss.closeSync(); - fileio.unlinkSync(fpath); - } - catch (e) { - console.info('fileio_test_stream_read_sync_001 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_stream_ReadSync_0200 - * @tc.name fileio_test_stream_read_sync_002 - * @tc.desc Function of API, offset. - */ - it('fileio_test_stream_read_sync_002', 0, async function () { - let fpath = await nextFileName('fileio_test_stream_read_sync_002'); - let text = '0123456789abcdefg'; - expect(prepareFile(fpath, text)).assertTrue(); - try { - let ss = fileio.createStreamSync(fpath, 'r+'); - expect(ss !== null).assertTrue(); - let len = ss.readSync(new ArrayBuffer(4096), { - offset: 1 - }); - expect(len == text.length).assertTrue(); - ss.closeSync(); - fileio.unlinkSync(fpath); - } - catch (e) { - console.info('fileio_test_stream_read_sync_002 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_stream_ReadSync_0300 - * @tc.name fileio_test_stream_read_sync_003 - * @tc.desc Function of API, length. - */ - it('fileio_test_stream_read_sync_003', 0, async function () { - let fpath = await nextFileName('fileio_test_stream_read_sync_003'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let ss = fileio.createStreamSync(fpath, 'r+'); - expect(ss !== null).assertTrue(); - let len = ss.readSync(new ArrayBuffer(4096), { - length: 1 - }); - expect(len == 1).assertTrue(); - ss.closeSync(); - fileio.unlinkSync(fpath); - } - catch (e) { - console.info('fileio_test_stream_read_sync_003 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_stream_ReadSync_0400 - * @tc.name fileio_test_stream_read_sync_004 - * @tc.desc Function of API, readBuf. - */ - it('fileio_test_stream_read_sync_004', 0, async function () { - let fpath = await nextFileName('fileio_test_stream_read_sync_004'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - var ss = fileio.createStreamSync(fpath, 'r+'); - expect(ss !== null).assertTrue(); - let len = ss.readSync(null); - expect(len == null).assertTrue(); - expect(null).assertFail(); - } - catch (e) { - console.info('fileio_test_stream_read_sync_004 has failed for ' + e); - expect(e.message == 'Invalid read buffer, expect arraybuffer').assertTrue(); - ss.closeSync(); - fileio.unlinkSync(fpath); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_stream_ReadSync_0500 - * @tc.name fileio_test_stream_read_sync_005 - * @tc.desc Function of API, position = -1. - */ - it('fileio_test_stream_read_sync_005', 0, async function () { - let fpath = await nextFileName('fileio_test_stream_read_sync_005'); - let text = '0123456789abcdefg'; - expect(prepareFile(fpath, text)).assertTrue(); - let ss = fileio.createStreamSync(fpath, 'r+'); - expect(ss !== null).assertTrue(); - try { - ss.readSync(new ArrayBuffer(4096), { - position: -1 - }); - } - catch (e) { - console.info('fileio_test_stream_read_sync_005 has failed for ' + e); - expect(e.message == "option.position shall be positive number").assertTrue(); - ss.closeSync(); - fileio.unlinkSync(fpath); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_stream_ReadSync_0600 - * @tc.name fileio_test_stream_read_sync_006 - * @tc.desc Function of API, offset. - */ - it('fileio_test_stream_read_sync_006', 0, async function () { - let fpath = await nextFileName('fileio_test_stream_read_sync_006'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - var ss = fileio.createStreamSync(fpath, 'r+'); - expect(ss !== null).assertTrue(); - let len = ss.readSync(new ArrayBuffer(4096), { - offset: -1 - }); - expect(len == null).assertTrue(); - expect(null).assertFail(); - } - catch (e) { - console.info('fileio_test_stream_read_sync_006 has failed for ' + e); - expect(e.message == 'Invalid option.offset, positive integer is desired').assertTrue(); - ss.closeSync(); - fileio.unlinkSync(fpath); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_stream_WriteSync_0000 - * @tc.name fileio_test_stream_write_sync_000 - * @tc.desc Function of API, not set options. - */ - it('fileio_test_stream_write_sync_000', 0, async function () { - let fpath = await nextFileName('fileio_test_stream_write_sync_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - let text = '0123456789abcdefg'; - try { - let ss = fileio.createStreamSync(fpath, 'r+'); - expect(ss !== null).assertTrue(); - expect(ss.writeSync(text) == text.length).assertTrue(); - ss.closeSync(); - fileio.unlinkSync(fpath); - console.info('---fileio_test_stream_write_sync_000 is passed!'); - } - catch (e) { - console.info('fileio_test_stream_write_sync_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_stream_WriteSync_0100 - * @tc.name fileio_test_stream_write_sync_001 - * @tc.desc Function of API, invalid encoding. - */ - it('fileio_test_stream_write_sync_001', 0, async function () { - let fpath = await nextFileName('fileio_test_stream_write_sync_001'); - expect(prepareFile(fpath, '')).assertTrue(); - let ss - try { - ss = fileio.createStreamSync(fpath, 'w+'); - expect(ss !== null).assertTrue(); - ss.writeSync(FILE_CONTENT, { - encoding: 'ASCII' - }) - expect(null).assertFail(); - } - catch (e) { - console.info('fileio_test_stream_write_sync_001 has failed for ' + e); - expect(e.message == 'Illegal write buffer or encoding').assertTrue(); - ss.closeSync(); - fileio.unlinkSync(fpath); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_stream_WriteSync_0200 - * @tc.name fileio_test_stream_write_sync_002 - * @tc.desc Function of API, position. - */ - it('fileio_test_stream_write_sync_002', 0, async function () { - let fpath = await nextFileName('fileio_test_stream_write_sync_002'); - expect(prepareFile(fpath, 'a')).assertTrue(); - expect(fileToWriteOnly(fpath)).assertTrue(); - try { - let fd = fileio.openSync(fpath, 0o001); - expect(fd !== null).assertTrue(); - let ss = fileio.fdopenStreamSync(fd, 'w'); - expect(ss !== null).assertTrue(); - expect(ss.writeSync('aaa') !== null).assertTrue(); - ss.closeSync(); - expect(fileToReadOnly(fpath)).assertTrue(); - ss = fileio.createStreamSync(fpath, 'r'); - let rlen = ss.readSync(new ArrayBuffer(4096)); - expect(rlen == 3).assertTrue(); - ss.closeSync(); - fileio.unlinkSync(fpath); - } - catch (e) { - console.info('fileio_test_stream_write_sync_002 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_stream_WriteSync_0300 - * @tc.name fileio_test_stream_write_sync_003 - * @tc.desc Function of API, offset. - */ - it('fileio_test_stream_write_sync_003', 0, async function () { - let fpath = await nextFileName('fileio_test_stream_write_sync_003'); - expect(prepareFile(fpath, 'a')).assertTrue(); - expect(fileToWriteOnly(fpath)).assertTrue(); - try { - let fd = fileio.openSync(fpath, 0o001); - expect(fd !== null).assertTrue(); - let ss = fileio.fdopenStreamSync(fd, 'w'); - expect(ss !== null).assertTrue(); - expect(ss.writeSync('aaa') !== null).assertTrue(); - ss.closeSync(); - expect(fileToReadOnly(fpath)).assertTrue(); - ss = fileio.createStreamSync(fpath, 'r'); - let rlen = ss.readSync(new ArrayBuffer(4096)); - expect(rlen == 3).assertTrue(); - ss.closeSync(); - fileio.unlinkSync(fpath); - } - catch (e) { - console.info('fileio_test_stream_write_sync_003 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_stream_WriteSync_0400 - * @tc.name fileio_test_stream_write_sync_004 - * @tc.desc Function of API, length. - */ - it('fileio_test_stream_write_sync_004', 0, async function () { - let fpath = await nextFileName('fileio_test_stream_write_sync_004'); - expect(prepareFile(fpath, 'a')).assertTrue(); - let text = '0123456789abcdefg'; - try { - let ss = fileio.createStreamSync(fpath, 'r+'); - expect(ss !== null).assertTrue(); - let wlen = ss.writeSync(text); - expect(wlen == text.length).assertTrue(); - ss.closeSync(); - ss = fileio.createStreamSync(fpath, 'r+'); - let rlen = ss.readSync(new ArrayBuffer(4096)); - expect(rlen == text.length).assertTrue(); - ss.closeSync(); - fileio.unlinkSync(fpath); - } - catch (e) { - console.info('fileio_test_stream_write_sync_004 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_stream_WriteSync_0500 - * @tc.name fileio_test_stream_write_sync_005 - * @tc.desc Function of API, encoding. - */ - it('fileio_test_stream_write_sync_005', 0, async function () { - let fpath = await nextFileName('fileio_test_stream_write_sync_005'); - expect(prepareFile(fpath, '')).assertTrue(); - let writeStrArray = new Array('aaa', '123'); - let encodingArray = new Array('utf-8', 'utf-16'); - try { - for (let i = 0; i < encodingArray.length; i++) { - let ss = fileio.createStreamSync(fpath, 'w+'); - expect(ss !== null).assertTrue(); - ss.writeSync(writeStrArray[i], { - encoding: encodingArray[i] - }) - ss.closeSync(); - ss = fileio.createStreamSync(fpath, 'r+'); - let rlen = ss.readSync(new ArrayBuffer(4096)); - expect(rlen !== null).assertTrue(); - ss.closeSync(); - } - fileio.unlinkSync(fpath); - } - catch (e) { - console.info('fileio_test_stream_write_sync_005 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_stream_WriteSync_0600 - * @tc.name fileio_test_stream_write_sync_006 - * @tc.desc Function of API, position. - */ - it('fileio_test_stream_write_sync_006', 0, async function () { - let fpath = await nextFileName('fileio_test_stream_write_sync_006'); - expect(prepareFile(fpath, 'a')).assertTrue(); - expect(fileToWriteOnly(fpath)).assertTrue(); - try { - let fd = fileio.openSync(fpath, 0o001); - expect(fd !== null).assertTrue(); - let ss = fileio.fdopenStreamSync(fd, 'w'); - expect(ss !== null).assertTrue(); - expect(ss.writeSync('aaa', { - position: 1 - }) !== null).assertTrue(); - ss.closeSync(); - expect(fileToReadOnly(fpath)).assertTrue(); - ss = fileio.createStreamSync(fpath, 'r'); - let rlen = ss.readSync(new ArrayBuffer(4096)); - expect(rlen == 4).assertTrue(); - ss.closeSync(); - fileio.unlinkSync(fpath); - } - catch (e) { - console.info('fileio_test_stream_write_sync_006 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_stream_WriteSync_0700 - * @tc.name fileio_test_stream_write_sync_007 - * @tc.desc Function of API, offset. - */ - it('fileio_test_stream_write_sync_007', 0, async function () { - let fpath = await nextFileName('fileio_test_stream_write_sync_007'); - expect(prepareFile(fpath, 'a')).assertTrue(); - expect(fileToWriteOnly(fpath)).assertTrue(); - try { - let fd = fileio.openSync(fpath, 0o001); - expect(fd !== null).assertTrue(); - let ss = fileio.fdopenStreamSync(fd, 'w'); - expect(ss !== null).assertTrue(); - expect(ss.writeSync('aaa', { - offset: 1 - }) !== null).assertTrue(); - ss.closeSync(); - expect(fileToReadOnly(fpath)).assertTrue(); - ss = fileio.createStreamSync(fpath, 'r'); - let rlen = ss.readSync(new ArrayBuffer(4096)); - expect(rlen == 2).assertTrue(); - ss.closeSync(); - fileio.unlinkSync(fpath); - } - catch (e) { - console.info('fileio_test_stream_write_sync_007 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_stream_WriteSync_0800 - * @tc.name fileio_test_stream_write_sync_008 - * @tc.desc Function of API, length. - */ - it('fileio_test_stream_write_sync_008', 0, async function () { - let fpath = await nextFileName('fileio_test_stream_write_sync_008'); - expect(prepareFile(fpath, '')).assertTrue(); - let text = '0123456789abcdefg'; - try { - let ss = fileio.createStreamSync(fpath, 'r+'); - expect(ss !== null).assertTrue(); - let wlen = ss.writeSync(text, { - length: text.length - }); - expect(wlen == text.length).assertTrue(); - ss.closeSync(); - ss = fileio.createStreamSync(fpath, 'r+'); - let rlen = ss.readSync(new ArrayBuffer(4096)); - expect(rlen == text.length).assertTrue(); - ss.closeSync(); - fileio.unlinkSync(fpath); - } - catch (e) { - console.info('fileio_test_stream_write_sync_008 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_stream_WriteSync_0900 - * @tc.name fileio_test_stream_write_sync_009 - * @tc.desc Function of API, invalid fcontent. - */ - it('fileio_test_stream_write_sync_009', 0, async function () { - let fpath = await nextFileName('fileio_test_stream_write_sync_009'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - var ss = fileio.createStreamSync(fpath, 'r+'); - expect(ss !== null).assertTrue(); - ss.writeSync(-1); - expect(null).assertFail(); - } - catch (e) { - console.info('fileio_test_stream_write_sync_009 has failed for ' + e); - expect(e.message == 'Illegal write buffer or encoding').assertTrue(); - fileio.unlinkSync(fpath); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_stream_WriteSync_1000 - * @tc.name fileio_test_stream_write_sync_010 - * @tc.desc Function of API, invalid encoding. - */ - it('fileio_test_stream_write_sync_010', 0, async function () { - let fpath = await nextFileName('fileio_test_stream_write_sync_010'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - var ss = fileio.createStreamSync(fpath, 'r+'); - expect(ss !== null).assertTrue(); - ss.writeSync(FILE_CONTENT, { - encoding: '' - }) - expect(null).assertFail(); - } - catch (e) { - console.info('fileio_test_stream_write_sync_010 has failed for ' + e); - expect(e.message == 'Illegal write buffer or encoding').assertTrue(); - ss.closeSync(); - fileio.unlinkSync(fpath); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_stream_WriteSync_1100 - * @tc.name fileio_test_stream_write_sync_011 - * @tc.desc Function of API, invalid position. - */ - it('fileio_test_stream_write_sync_011', 0, async function () { - let fpath = await nextFileName('fileio_test_stream_write_sync_011'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - var ss = fileio.createStreamSync(fpath, 'r+'); - expect(ss !== null).assertTrue(); - ss.writeSync(FILE_CONTENT, { - position: -1 - }) - expect(null).assertFail(); - } - catch (e) { - console.info('fileio_test_stream_write_sync_011 has failed for ' + e); - expect(e.message == 'option.position shall be positive number').assertTrue(); - ss.closeSync(); - fileio.unlinkSync(fpath); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_stream_WriteSync_1200 - * @tc.name fileio_test_stream_write_sync_012 - * @tc.desc Function of API, invalid offset. - */ - it('fileio_test_stream_write_sync_012', 0, async function () { - let fpath = await nextFileName('fileio_test_stream_write_sync_012'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - var ss = fileio.createStreamSync(fpath, 'r+'); - expect(ss !== null).assertTrue(); - ss.writeSync(FILE_CONTENT, { - offset: -1 - }) - expect(null).assertFail(); - } - catch (e) { - console.info('fileio_test_stream_write_sync_012 has failed for ' + e); - expect(e.message == 'Invalid option.offset, positive integer is desired').assertTrue(); - ss.closeSync(); - fileio.unlinkSync(fpath); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_stream_WriteSync_1300 - * @tc.name fileio_test_stream_write_sync_013 - * @tc.desc Function of API, Set all parameters. - */ - it('fileio_test_stream_write_sync_013', 0, async function () { - let fpath = await nextFileName('fileio_test_stream_write_sync_013'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - let text = '0123456789abcdefg'; - try { - let ss = fileio.createStreamSync(fpath, 'r+'); - expect(ss !== null).assertTrue(); - expect(ss.writeSync(text, { - encoding: 'utf-8', - position: 0, - offset: 1, - length: 1, - }) == 1).assertTrue(); - ss.closeSync(); - fileio.unlinkSync(fpath); - console.info('---fileio_test_stream_write_sync_013 is passed!'); - } - catch (e) { - console.info('fileio_test_stream_write_sync_013 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_stream_WriteSync_1400 - * @tc.name fileio_test_stream_write_sync_014 - * @tc.desc Function of API, Set all parameters. - */ - it('fileio_test_stream_write_sync_014', 0, async function () { - let fpath = await nextFileName('fileio_test_stream_write_sync_014'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - let text = '0123456789abcdefg'; - try { - let ss = fileio.createStreamSync(fpath, 'r+'); - expect(ss !== null).assertTrue(); - expect(ss.writeSync(text, { - offset: 2, - length: 2, - }) == 2).assertTrue(); - ss.closeSync(); - fileio.unlinkSync(fpath); - console.info('---fileio_test_stream_write_sync_014 is passed!'); - } - catch (e) { - console.info('fileio_test_stream_write_sync_014 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_stream_write_read_4k_sync - * @tc.name fileio_test_stream_write_read_4k_sync - * @tc.desc Function of API, read 4k file. - */ - it('fileio_test_stream_write_read_4k_sync', 0, async function () { - let fpath = await nextFileName('fileio_test_stream_write_read_4k_sync'); - expect(prepareFile(fpath, 'a')).assertTrue(); - expect(fileToWriteOnly(fpath)).assertTrue(); - try { - let fd = fileio.openSync(fpath, 0o001); - expect(fd !== null).assertTrue(); - let ss = fileio.fdopenStreamSync(fd, 'w'); - expect(ss !== null).assertTrue(); - expect(ss.writeSync(randomString(4096)) !== null).assertTrue(); - ss.closeSync(); - expect(fileToReadOnly(fpath)).assertTrue(); - ss = fileio.createStreamSync(fpath, 'r'); - let rlen = ss.readSync(new ArrayBuffer(4096)); - ss.closeSync(); - fileio.unlinkSync(fpath); - } - catch (e) { - console.info('fileio_test_stream_write_read_4k_sync has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_stream_FlushSync_0000 - * @tc.name fileio_test_stream_flush_sync_000 - * @tc.desc Function of API, flushSync. - */ - it('fileio_test_stream_flush_sync_000', 0, async function () { - let fpath = await nextFileName('fileio_test_stream_flush_sync_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - let text = '0123456789abcdefg'; - try { - let ss = fileio.createStreamSync(fpath, 'r+'); - expect(ss !== null).assertTrue(); - expect(ss.writeSync(text) == text.length).assertTrue(); - ss.flushSync(); - ss.closeSync(); - fileio.unlinkSync(fpath); - } - catch (e) { - console.info('fileio_test_stream_flush_sync_001 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_stream_FlushSync_0100 - * @tc.name fileio_test_stream_flush_sync_001 - * @tc.desc Function of API, error. - */ - it('fileio_test_stream_flush_sync_001', 0, async function () { - let fpath = await nextFileName('fileio_test_stream_flush_sync_001'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let ss = fileio.createStreamSync(fpath, 'r+'); - expect(ss !== null).assertTrue(); - ss.closeSync(); - ss.flushSync(); - expect(null).assertFail(); - } - catch (e) { - console.info('fileio_test_stream_flush_sync_001 has failed for ' + e); - expect(e.message == 'Stream may has been closed').assertTrue(); - fileio.unlinkSync(fpath); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_stream_CloseSync_0000 - * @tc.name fileio_test_stream_close_sync_000 - * @tc.desc Function of API, closeSync. - */ - it('fileio_test_stream_close_sync_000', 0, async function () { - let fpath = await nextFileName('fileio_test_stream_close_sync_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let ss = fileio.createStreamSync(fpath, 'r+'); - ss.closeSync(); - fileio.unlinkSync(fpath); - } - catch (e) { - console.info('fileio_test_stream_close_sync_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_stream_CloseSync_0100 - * @tc.name fileio_test_stream_close_sync_001 - * @tc.desc Function of API, error. - */ - it('fileio_test_stream_close_sync_001', 0, async function () { - let fpath = await nextFileName('fileio_test_stream_close_sync_001'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - let ss; - try { - ss = fileio.createStreamSync(fpath, 'r+'); - ss.closeSync(); - ss.closeSync(); - expect(null).assertFail(); - } - catch (e) { - console.info('fileio_test_stream_close_sync_001 has failed for ' + e); - expect(e.message == 'Stream may have been closed yet').assertTrue(); - fileio.unlinkSync(fpath); - } - }); -}); -} +/* + * Copyright (C) 2021 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 fileio from '@ohos.fileio'; +import { describe,it,expect}from '@ohos/hypium' +import { + FILE_CONTENT, + prepareFile, + fileToReadOnly, + fileToWriteOnly, + nextFileName, + randomString, + forceRemoveDir +} + from './Common' + +export default function fileIOTestStream() { +describe('fileIOTestStream', function () { + + /** + * @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_0000 + * @tc.name fileio_test_stream_create_stream_sync_000 + * @tc.desc Function of API, mode = r. The test file is exist. + */ + it('fileio_test_stream_create_stream_sync_000', 0, async function () { + let fpath = await nextFileName('fileio_test_stream_create_stream_sync_000'); + expect(prepareFile(fpath, 'hello')).assertTrue(); + expect(fileToReadOnly(fpath)).assertTrue(); + try { + let ss = fileio.createStreamSync(fpath, 'r'); + expect(ss !== null).assertTrue(); + ss.closeSync(); + fileio.unlinkSync(fpath); + console.info('fileio_test_stream_create_stream_sync_000 is passed!'); + } + catch (e) { + console.info('fileio_test_stream_create_stream_sync_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_0100 + * @tc.name fileio_test_stream_create_stream_sync_001 + * @tc.desc Function of API, mode = r. The test file is not exist. + */ + it('fileio_test_stream_create_stream_sync_001', 0, async function () { + let fpath = await nextFileName('fileio_test_stream_create_stream_sync_001'); + try { + fileio.createStreamSync(fpath, 'r'); + expect(null).assertFail(); + } + catch (e) { + console.info('fileio_test_stream_create_stream_sync_001 has failed for ' + e); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_0200 + * @tc.name fileio_test_stream_create_stream_sync_002 + * @tc.desc Function of API, mode = w. The test file is exist. + */ + it('fileio_test_stream_create_stream_sync_002', 0, async function () { + let fpath = await nextFileName('fileio_test_stream_create_stream_sync_002'); + expect(prepareFile(fpath, '')).assertTrue(); + expect(fileToWriteOnly(fpath)).assertTrue(); + let text = '0123456789abcdefg'; + try { + let ss = fileio.createStreamSync(fpath, 'w'); + expect(ss !== null).assertTrue(); + let wlen = ss.writeSync(text); + expect(wlen !== null).assertTrue(); + ss.closeSync(); + expect(fileToReadOnly(fpath)).assertTrue(); + ss = fileio.createStreamSync(fpath, 'r'); + let rlen = ss.readSync(new ArrayBuffer(4096)); + expect(rlen == text.length).assertTrue(); + ss.closeSync(); + fileio.unlinkSync(fpath); + } + catch (e) { + console.info('fileio_test_stream_create_stream_sync_002 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_0300 + * @tc.name fileio_test_stream_create_stream_sync_003 + * @tc.desc Function of API, mode = w. The test file is not exist. + */ + it('fileio_test_stream_create_stream_sync_003', 0, async function () { + let fpath = await nextFileName('fileio_test_stream_create_stream_sync_003'); + try { + let ss = fileio.createStreamSync(fpath, 'w'); + expect(ss !== null).assertTrue(); + ss.closeSync(); + fileio.unlinkSync(fpath); + } + catch (e) { + console.info('fileio_test_stream_create_stream_sync_003 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_0400 + * @tc.name fileio_test_stream_create_stream_sync_004 + * @tc.desc Function of API, mode = a. The test file is exist. + */ + it('fileio_test_stream_create_stream_sync_004', 0, async function () { + let fpath = await nextFileName('fileio_test_stream_create_stream_sync_004'); + expect(prepareFile(fpath, 'a')).assertTrue(); + expect(fileToWriteOnly(fpath)).assertTrue(); + let text = '0123456789abcdefg'; + try { + let ss = fileio.createStreamSync(fpath, 'a'); + expect(ss !== null).assertTrue(); + let wlen = ss.writeSync(text); + expect(wlen !== null).assertTrue(); + ss.closeSync(); + expect(fileToReadOnly(fpath)).assertTrue(); + ss = fileio.createStreamSync(fpath, 'r'); + let rlen = ss.readSync(new ArrayBuffer(4096)); + expect(rlen == text.length + 1).assertTrue(); + ss.closeSync(); + fileio.unlinkSync(fpath); + } + catch (e) { + console.info('fileio_test_stream_create_stream_sync_004 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_0500 + * @tc.name fileio_test_stream_create_stream_sync_005 + * @tc.desc Function of API, mode = a. The test file is not exist. + */ + it('fileio_test_stream_create_stream_sync_005', 0, async function () { + let fpath = await nextFileName('fileio_test_stream_create_stream_sync_005'); + try { + let ss = fileio.createStreamSync(fpath, 'a'); + expect(ss !== null).assertTrue(); + ss.closeSync(); + fileio.unlinkSync(fpath); + } + catch (e) { + console.info('fileio_test_stream_create_stream_sync_005 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_0600 + * @tc.name fileio_test_stream_create_stream_sync_006 + * @tc.desc Function of API, mode = r+. The test file is exist. + */ + it('fileio_test_stream_create_stream_sync_006', 0, async function () { + let fpath = await nextFileName('fileio_test_stream_create_stream_sync_006'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let ss = fileio.createStreamSync(fpath, 'r+'); + expect(ss !== null).assertTrue(); + ss.closeSync(); + fileio.unlinkSync(fpath); + } + catch (e) { + console.info('fileio_test_stream_create_stream_sync_006 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_0700 + * @tc.name fileio_test_stream_create_stream_sync_007 + * @tc.desc Function of API, mode = r+. The test file is not exist. + */ + it('fileio_test_stream_create_stream_sync_007', 0, async function () { + let fpath = await nextFileName('fileio_test_stream_create_stream_sync_007'); + try { + fileio.createStreamSync(fpath, 'r+'); + expect(null).assertFail(); + } + catch (e) { + console.info('fileio_test_stream_create_stream_sync_007 has failed for ' + e); + expect(e.message == 'No such file or directory').assertTrue(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_0800 + * @tc.name fileio_test_stream_create_stream_sync_008 + * @tc.desc Function of API, mode = w+. The test file is exist. + */ + it('fileio_test_stream_create_stream_sync_008', 0, async function () { + let fpath = await nextFileName('fileio_test_stream_create_stream_sync_008'); + expect(prepareFile(fpath, '')).assertTrue(); + let text = '0123456789abcdefg'; + try { + let ss = fileio.createStreamSync(fpath, 'w+'); + expect(ss !== null).assertTrue(); + let wlen = ss.writeSync(text); + expect(wlen !== null).assertTrue(); + ss.closeSync(); + expect(fileToReadOnly(fpath)).assertTrue(); + ss = fileio.createStreamSync(fpath, 'r'); + let rlen = ss.readSync(new ArrayBuffer(4096)); + expect(rlen == text.length).assertTrue(); + ss.closeSync(); + fileio.unlinkSync(fpath); + } + catch (e) { + console.info('fileio_test_stream_create_stream_sync_008 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_0900 + * @tc.name fileio_test_stream_create_stream_sync_009 + * @tc.desc Function of API, mode = w+. The test file is not exist. + */ + it('fileio_test_stream_create_stream_sync_009', 0, async function () { + let fpath = await nextFileName('fileio_test_stream_create_stream_sync_009'); + try { + let ss = fileio.createStreamSync(fpath, 'w+'); + expect(ss !== null).assertTrue(); + ss.closeSync(); + fileio.unlinkSync(fpath); + } + catch (e) { + console.info('fileio_test_stream_create_stream_sync_009 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_1000 + * @tc.name fileio_test_stream_create_stream_sync_010 + * @tc.desc Function of API, mode = a+. The test file is exist. + */ + it('fileio_test_stream_create_stream_sync_010', 0, async function () { + let fpath = await nextFileName('fileio_test_stream_create_stream_sync_010'); + expect(prepareFile(fpath, 'a')).assertTrue(); + let text = '0123456789abcdefg'; + try { + let ss = fileio.createStreamSync(fpath, 'a+'); + expect(ss !== null).assertTrue(); + let wlen = ss.writeSync(text); + expect(wlen !== null).assertTrue(); + ss.closeSync(); + expect(fileToReadOnly(fpath)).assertTrue(); + ss = fileio.createStreamSync(fpath, 'r'); + let rlen = ss.readSync(new ArrayBuffer(4096)); + expect(rlen == text.length + 1).assertTrue(); + ss.closeSync(); + fileio.unlinkSync(fpath); + } + catch (e) { + console.info('fileio_test_stream_create_stream_sync_010 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_1100 + * @tc.name fileio_test_stream_create_stream_sync_011 + * @tc.desc Function of API, mode = a+. The test file is not exist. + */ + it('fileio_test_stream_create_stream_sync_011', 0, async function () { + let fpath = await nextFileName('fileio_test_stream_create_stream_sync_011'); + try { + let ss = fileio.createStreamSync(fpath, 'a+'); + expect(ss !== null).assertTrue(); + ss.closeSync(); + fileio.unlinkSync(fpath); + } + catch (e) { + console.info('fileio_test_stream_create_stream_sync_011 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_1200 + * @tc.name fileio_test_stream_create_stream_sync_012 + * @tc.desc Function of API, mode = rb. The test file is exist. + */ + it('fileio_test_stream_create_stream_sync_012', 0, async function () { + let fpath = await nextFileName('fileio_test_stream_create_stream_sync_012'); + expect(prepareFile(fpath, '')).assertTrue(); + expect(fileToReadOnly(fpath)).assertTrue(); + try { + let ss = fileio.createStreamSync(fpath, 'rb'); + expect(ss !== null).assertTrue(); + ss.closeSync(); + fileio.unlinkSync(fpath); + } + catch (e) { + console.info('fileio_test_stream_create_stream_sync_012 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_1300 + * @tc.name fileio_test_stream_create_stream_sync_013 + * @tc.desc Function of API, mode = ab. The test file is not exist. + */ + it('fileio_test_stream_create_stream_sync_013', 0, async function () { + let fpath = await nextFileName('fileio_test_stream_create_stream_sync_013'); + try { + fileio.createStreamSync(fpath, 'rb'); + expect(null).assertFail(); + } + catch (e) { + console.info('fileio_test_stream_create_stream_sync_013 has failed for ' + e); + expect(e.message == 'No such file or directory').assertTrue(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_1400 + * @tc.name fileio_test_stream_create_stream_sync_014 + * @tc.desc Function of API, mode = wb. The test file is exist. + */ + it('fileio_test_stream_create_stream_sync_014', 0, async function () { + let fpath = await nextFileName('fileio_test_stream_create_stream_sync_014'); + expect(prepareFile(fpath, '')).assertTrue(); + expect(fileToWriteOnly(fpath)).assertTrue(); + let text = '0123456789abcdefg'; + try { + let ss = fileio.createStreamSync(fpath, 'wb'); + expect(ss !== null).assertTrue(); + let wlen = ss.writeSync(text); + expect(wlen !== null).assertTrue(); + ss.closeSync(); + expect(fileToReadOnly(fpath)).assertTrue(); + ss = fileio.createStreamSync(fpath, 'r'); + let rlen = ss.readSync(new ArrayBuffer(4096)); + expect(rlen == text.length).assertTrue(); + ss.closeSync(); + fileio.unlinkSync(fpath); + } + catch (e) { + console.info('fileio_test_stream_create_stream_sync_014 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_1500 + * @tc.name fileio_test_stream_create_stream_sync_015 + * @tc.desc Function of API, mode = wb. The test file is not exist. + */ + it('fileio_test_stream_create_stream_sync_015', 0, async function () { + let fpath = await nextFileName('fileio_test_stream_create_stream_sync_015'); + try { + let ss = fileio.createStreamSync(fpath, 'wb'); + expect(ss !== null).assertTrue(); + ss.closeSync(); + fileio.unlinkSync(fpath); + } + catch (e) { + console.info('fileio_test_stream_create_stream_sync_015 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_1600 + * @tc.name fileio_test_stream_create_stream_sync_016 + * @tc.desc Function of API, mode = ab. The test file is exist. + */ + it('fileio_test_stream_create_stream_sync_016', 0, async function () { + let fpath = await nextFileName('fileio_test_stream_create_stream_sync_016'); + expect(prepareFile(fpath, 'a')).assertTrue(); + expect(fileToWriteOnly(fpath)).assertTrue(); + let text = '0123456789abcdefg'; + try { + let ss = fileio.createStreamSync(fpath, 'ab'); + expect(ss !== null).assertTrue(); + let wlen = ss.writeSync(text); + expect(wlen !== null).assertTrue(); + ss.closeSync(); + expect(fileToReadOnly(fpath)).assertTrue(); + ss = fileio.createStreamSync(fpath, 'r'); + let rlen = ss.readSync(new ArrayBuffer(4096)); + expect(rlen == text.length + 1).assertTrue(); + ss.closeSync(); + fileio.unlinkSync(fpath); + console.info('fileio_test_stream_create_stream_sync_016 is passed!'); + } + catch (e) { + console.info('fileio_test_stream_create_stream_sync_016 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_1700 + * @tc.name fileio_test_stream_create_stream_sync_017 + * @tc.desc Function of API, mode = ab. The test file is not exist. + */ + it('fileio_test_stream_create_stream_sync_017', 0, async function () { + let fpath = await nextFileName('fileio_test_stream_create_stream_sync_017'); + try { + let ss = fileio.createStreamSync(fpath, 'ab'); + expect(ss !== null).assertTrue(); + ss.closeSync(); + fileio.unlinkSync(fpath); + } + catch (e) { + console.info('fileio_test_stream_create_stream_sync_017 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_1800 + * @tc.name fileio_test_stream_create_stream_sync_018 + * @tc.desc Function of API, mode = rb+. The test file is exist. + */ + it('fileio_test_stream_create_stream_sync_018', 0, async function () { + let fpath = await nextFileName('fileio_test_stream_create_stream_sync_018'); + expect(prepareFile(fpath, '')).assertTrue(); + try { + let ss = fileio.createStreamSync(fpath, 'rb+'); + expect(ss !== null).assertTrue(); + ss.closeSync(); + fileio.unlinkSync(fpath); + } + catch (e) { + console.info('fileio_test_stream_create_stream_sync_018 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_1900 + * @tc.name fileio_test_stream_create_stream_sync_019 + * @tc.desc Function of API, mode = rb+. The test file is not exist. + */ + it('fileio_test_stream_create_stream_sync_019', 0, async function () { + let fpath = await nextFileName('fileio_test_stream_create_stream_sync_019'); + try { + fileio.createStreamSync(fpath, 'rb+'); + expect(null).assertFail(); + } + catch (e) { + console.info('fileio_test_stream_create_stream_sync_019 has failed for ' + e); + expect(e.message == 'No such file or directory').assertTrue(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_2000 + * @tc.name fileio_test_stream_create_stream_sync_020 + * @tc.desc Function of API, mode = wb+. The test file is exist. + */ + it('fileio_test_stream_create_stream_sync_020', 0, async function () { + let fpath = await nextFileName('fileio_test_stream_create_stream_sync_020'); + expect(prepareFile(fpath, '')).assertTrue(); + let text = '0123456789abcdefg'; + try { + let ss = fileio.createStreamSync(fpath, 'wb+'); + expect(ss !== null).assertTrue(); + let wlen = ss.writeSync(text); + expect(wlen !== null).assertTrue(); + ss.closeSync(); + expect(fileToReadOnly(fpath)).assertTrue(); + ss = fileio.createStreamSync(fpath, 'r'); + let rlen = ss.readSync(new ArrayBuffer(4096)); + expect(rlen == text.length).assertTrue(); + ss.closeSync(); + fileio.unlinkSync(fpath); + } + catch (e) { + console.info('fileio_test_stream_create_stream_sync_020 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_2100 + * @tc.name fileio_test_stream_create_stream_sync_021 + * @tc.desc Function of API, mode = wb+. The test file is not exist. + */ + it('fileio_test_stream_create_stream_sync_021', 0, async function () { + let fpath = await nextFileName('fileio_test_stream_create_stream_sync_021'); + try { + let ss = fileio.createStreamSync(fpath, 'wb+'); + expect(ss !== null).assertTrue(); + ss.closeSync(); + fileio.unlinkSync(fpath); + } + catch (e) { + console.info('fileio_test_stream_create_stream_sync_021 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_2200 + * @tc.name fileio_test_stream_create_stream_sync_022 + * @tc.desc Function of API, mode = ab+. The test file is exist. + */ + it('fileio_test_stream_create_stream_sync_022', 0, async function () { + let fpath = await nextFileName('fileio_test_stream_create_stream_sync_022'); + expect(prepareFile(fpath, 'a')).assertTrue(); + let text = '0123456789abcdefg'; + try { + let ss = fileio.createStreamSync(fpath, 'ab+'); + expect(ss !== null).assertTrue(); + let wlen = ss.writeSync(text); + expect(wlen !== null).assertTrue(); + ss.closeSync(); + expect(fileToReadOnly(fpath)).assertTrue(); + ss = fileio.createStreamSync(fpath, 'r'); + let rlen = ss.readSync(new ArrayBuffer(4096)); + expect(rlen == text.length + 1).assertTrue(); + ss.closeSync(); + fileio.unlinkSync(fpath); + } + catch (e) { + console.info('fileio_test_stream_create_stream_sync_022 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_2300 + * @tc.name fileio_test_stream_create_stream_sync_023 + * @tc.desc Function of API, mode = ab+. The test file is not exist. + */ + it('fileio_test_stream_create_stream_sync_023', 0, async function () { + let fpath = await nextFileName('fileio_test_stream_create_stream_sync_023'); + try { + let ss = fileio.createStreamSync(fpath, 'ab+'); + expect(ss !== null).assertTrue(); + ss.closeSync(); + fileio.unlinkSync(fpath); + } + catch (e) { + console.info('fileio_test_stream_create_stream_sync_023 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_2400 + * @tc.name fileio_test_stream_create_stream_sync_024 + * @tc.desc Function of API, invalid fpath. + */ + it('fileio_test_stream_create_stream_sync_024', 0, function () { + try { + fileio.createStreamSync('', 'r'); + expect(null).assertFail(); + } + catch (e) { + console.info('fileio_test_stream_create_stream_sync_024 has failed for ' + e); + expect(e.message == 'No such file or directory').assertTrue(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_2500 + * @tc.name fileio_test_stream_create_stream_sync_025 + * @tc.desc Function of API, invalid mode. + */ + it('fileio_test_stream_create_stream_sync_025', 0, async function () { + let fpath = await nextFileName('fileio_test_stream_create_stream_sync_025'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + fileio.createStreamSync(fpath, ''); + throw new Error('invalid mode'); + } + catch (e) { + console.info('fileio_test_stream_create_stream_sync_025 has failed for ' + e); + fileio.unlinkSync(fpath); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_2600 + * @tc.name fileio_test_stream_create_stream_sync_026 + * @tc.desc Function of API, fpath too long. + */ + it('fileio_test_stream_create_stream_sync_026', 0, async function () { + let dpath = await nextFileName('fileio_test_stream_create_stream_sync_026'); + fileio.mkdirSync(dpath); + try { + for (let i = 0; i < 16; i++) { + if (i == 15) { + let fpath = dpath + '/f' + i; + fileio.createStreamSync(fpath, 'w+'); + fileio.unlinkSync(fpath); + } else { + dpath = dpath + '/d' + i; + fileio.mkdirSync(dpath); + } + } + throw new Error('fpath too long'); + } + catch (e) { + console.info('fileio_test_stream_create_stream_sync_026 has failed for ' + e); + forceRemoveDir(dpath, 15); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_2700 + * @tc.name fileio_test_stream_create_stream_sync_027 + * @tc.desc Function of API, filename too long. + */ + it('fileio_test_stream_create_stream_sync_027', 0, async function () { + let fpath = await nextFileName(randomString(256)); + try { + fileio.createStreamSync(fpath, 'w+'); + expect(null).assertFail(); + } + catch (e) { + console.info('fileio_test_stream_create_stream_sync_027 has failed for ' + e); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_2800 + * @tc.name fileio_test_stream_create_stream_sync_028 + * @tc.desc Function of API, path too deep. + */ + it('fileio_test_stream_create_stream_sync_028', 0, async function () { + let dpath = await nextFileName('fileio_test_stream_create_stream_sync_028'); + fileio.mkdirSync(dpath); + try { + for (let i = 0; i < 113; i++) { + if (i == 112) { + let fpath = dpath + '/f' + i + fileio.createStreamSync(fpath, 'w+'); + fileio.unlinkSync(fpath); + } else { + dpath = dpath + '/d' + i + fileio.mkdirSync(dpath); + } + } + throw new Error('path too deep'); + } + catch (e) { + console.info('fileio_test_stream_create_stream_sync_028 has failed for ' + e); + forceRemoveDir(dpath, 112); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_2900 + * @tc.name fileio_test_stream_create_stream_sync_029 + * @tc.desc Function of API, special character. + */ + it('fileio_test_stream_create_stream_sync_029', 0, async function () { + let fpath = await nextFileName('?*:<>/|'); + try { + fileio.createStreamSync(fpath, 'w+'); + expect(null).assertFail(); + } + catch (e) { + console.info('fileio_test_stream_create_stream_sync_029 has failed for ' + e); + expect(e.message == 'No such file or directory').assertTrue(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_3000 + * @tc.name fileio_test_stream_create_stream_sync_030 + * @tc.desc Function of API, mode = w+. Test file length is cleared to 0. + */ + it('fileio_test_stream_create_stream_sync_030', 0, async function () { + let fpath = await nextFileName('fileio_test_stream_create_stream_sync_030'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let fd = fileio.openSync(fpath, 0o102, 0o666); + let buf = new ArrayBuffer(4096); + let number = fileio.readSync(fd, buf); + expect(number == 11).assertTrue(); + let ss = fileio.createStreamSync(fpath, 'w+'); + let num = ss.readSync(buf); + expect(num == 0).assertTrue(); + ss.closeSync(); + fileio.unlinkSync(fpath); + } + catch (e) { + console.info('fileio_test_stream_create_stream_sync_030 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_3100 + * @tc.name fileio_test_stream_create_stream_sync_031 + * @tc.desc Function of API, mode = w. Test file length is cleared to 0. + */ + it('fileio_test_stream_create_stream_sync_031', 0, async function () { + let fpath = await nextFileName('fileio_test_stream_create_stream_sync_031'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let fd = fileio.openSync(fpath, 0o102, 0o666); + let buf = new ArrayBuffer(4096); + let number = fileio.readSync(fd, buf); + expect(number == 11).assertTrue(); + let ss = fileio.createStreamSync(fpath, 'w'); + let num = fileio.readSync(fd, buf); + expect(num == 0).assertTrue(); + ss.closeSync(); + fileio.unlinkSync(fpath); + } + catch (e) { + console.info('fileio_test_stream_create_stream_sync_031 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_stream_FdopenStreamSync_0000 + * @tc.name fileio_test_stream_fdopen_stream_sync_000 + * @tc.desc Function of API, mode=r. The test file is exist. + */ + it('fileio_test_stream_fdopen_stream_sync_000', 0, async function () { + let fpath = await nextFileName('fileio_test_stream_fdopen_stream_sync_000'); + expect(prepareFile(fpath, '')).assertTrue(); + expect(fileToReadOnly(fpath)).assertTrue(); + try { + let fd = fileio.openSync(fpath, 0o0); + let ss = fileio.fdopenStreamSync(fd, 'r'); + expect(ss !== null).assertTrue(); + ss.closeSync(); + fileio.unlinkSync(fpath); + } + catch (e) { + console.info('fileio_test_stream_fdopen_stream_sync_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_stream_FdopenStreamSync_0100 + * @tc.name fileio_test_stream_fdopen_stream_sync_001 + * @tc.desc Function of API, mode=r. The test file is not exist. + */ + it('fileio_test_stream_fdopen_stream_sync_001', 0, function () { + try { + let fd = -1; + let mode = 'r'; + fileio.fdopenStreamSync(fd, mode); + throw new Error('Bad file descriptor'); + } + catch (e) { + console.info('fileio_test_stream_fdopen_stream_sync_001 has failed for ' + e); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_stream_FdopenStreamSync_0200 + * @tc.name fileio_test_stream_fdopen_stream_sync_002 + * @tc.desc Function of API, mode=w. The test file is exist. + */ + it('fileio_test_stream_fdopen_stream_sync_002', 0, async function () { + let fpath = await nextFileName('fileio_test_stream_fdopen_stream_sync_002'); + let fd; + expect(prepareFile(fpath, '')).assertTrue(); + expect(fileToWriteOnly(fpath)).assertTrue(); + let text = '0123456789abcdefg'; + try { + fd = fileio.openSync(fpath, 0o001); + expect(fd !== null).assertTrue(); + let ss = fileio.fdopenStreamSync(fd, 'w'); + expect(ss !== null).assertTrue(); + let wlen = ss.writeSync(text); + expect(wlen !== null).assertTrue(); + ss.closeSync(); + expect(fileToReadOnly(fpath)).assertTrue(); + ss = fileio.createStreamSync(fpath, 'r'); + let rlen = ss.readSync(new ArrayBuffer(4096)); + expect(rlen == text.length).assertTrue(); + ss.closeSync(); + fileio.unlinkSync(fpath); + } + catch (e) { + console.info('fileio_test_stream_fdopen_stream_sync_002 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_stream_FdopenStreamSync_0300 + * @tc.name fileio_test_stream_fdopen_stream_sync_003 + * @tc.desc Function of API, mode=w. The test file is not exist. + */ + it('fileio_test_stream_fdopen_stream_sync_003', 0, async function () { + let fpath = await nextFileName('fileio_test_stream_fdopen_stream_sync_003'); + try { + let fd = fileio.openSync(fpath, 0o101, 0o222); + let ss = fileio.fdopenStreamSync(fd, 'w'); + expect(ss !== null).assertTrue(); + ss.closeSync(); + fileio.unlinkSync(fpath); + } + catch (e) { + console.info('fileio_test_stream_fdopen_stream_sync_003 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_stream_FdopenStreamSync_0400 + * @tc.name fileio_test_stream_fdopen_stream_sync_004 + * @tc.desc Function of API, mode=a. The test file is exist. + */ + it('fileio_test_stream_fdopen_stream_sync_004', 0, async function () { + let fpath = await nextFileName('fileio_test_stream_fdopen_stream_sync_004'); + expect(prepareFile(fpath, '1')).assertTrue(); + expect(fileToWriteOnly(fpath)).assertTrue(); + let text = '0123456789abcdefg'; + try { + let fd = fileio.openSync(fpath, 0o2001); + expect(fd !== null).assertTrue(); + let ss = fileio.fdopenStreamSync(fd, 'a'); + expect(ss !== null).assertTrue(); + let wlen = ss.writeSync(text); + expect(wlen !== null).assertTrue(); + ss.closeSync(); + expect(fileToReadOnly(fpath)).assertTrue(); + ss = fileio.createStreamSync(fpath, 'r'); + let rlen = ss.readSync(new ArrayBuffer(4096)); + expect(rlen == text.length + 1).assertTrue(); + ss.closeSync(); + fileio.unlinkSync(fpath); + } + catch (e) { + console.info('fileio_test_stream_fdopen_stream_sync_004 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_stream_FdopenStreamSync_0500 + * @tc.name fileio_test_stream_fdopen_stream_sync_005 + * @tc.desc Function of API, mode=a. The test file is not exist. + */ + it('fileio_test_stream_fdopen_stream_sync_005', 0, async function () { + let fpath = await nextFileName('fileio_test_stream_fdopen_stream_sync_005'); + try { + let fd = fileio.openSync(fpath, 0o101, 0o222); + let ss = fileio.fdopenStreamSync(fd, 'a'); + expect(ss !== null).assertTrue(); + ss.closeSync(); + fileio.unlinkSync(fpath); + } + catch (e) { + console.info('fileio_test_stream_fdopen_stream_sync_005 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_stream_FdopenStreamSync_0600 + * @tc.name fileio_test_stream_fdopen_stream_sync_006 + * @tc.desc Function of API, mode=r+. The test file is exist. + */ + it('fileio_test_stream_fdopen_stream_sync_006', 0, async function () { + let fpath = await nextFileName('fileio_test_stream_fdopen_stream_sync_006'); + expect(prepareFile(fpath, '')).assertTrue(); + try { + let fd = fileio.openSync(fpath, 0o2); + let ss = fileio.fdopenStreamSync(fd, 'r+'); + expect(ss !== null).assertTrue(); + ss.closeSync(); + fileio.unlinkSync(fpath); + } + catch (e) { + console.info('fileio_test_stream_fdopen_stream_sync_006 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_stream_FdopenStreamSync_0700 + * @tc.name fileio_test_stream_fdopen_stream_sync_007 + * @tc.desc Function of API, mode=r+. The test file is not exist. + */ + it('fileio_test_stream_fdopen_stream_sync_007', 0, async function () { + try { + fileio.fdopenStreamSync(-1, 'r+'); + throw new Error('Bad file descriptor'); + } + catch (e) { + console.info('fileio_test_stream_fdopen_stream_sync_007 has failed for ' + e); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_stream_FdopenStreamSync_0800 + * @tc.name fileio_test_stream_fdopen_stream_sync_008 + * @tc.desc Function of API, mode=w+. The test file is exist. + */ + it('fileio_test_stream_fdopen_stream_sync_008', 0, async function () { + let fpath = await nextFileName('fileio_test_stream_fdopen_stream_sync_008'); + expect(prepareFile(fpath, '')).assertTrue(); + let text = '0123456789abcdefg'; + try { + let fd = fileio.openSync(fpath, 0o2); + expect(fd !== null).assertTrue(); + let ss = fileio.fdopenStreamSync(fd, 'w+'); + expect(ss !== null).assertTrue(); + let wlen = ss.writeSync(text); + expect(wlen !== null).assertTrue(); + ss.closeSync(); + expect(fileToReadOnly(fpath)).assertTrue(); + ss = fileio.createStreamSync(fpath, 'r'); + let rlen = ss.readSync(new ArrayBuffer(4096)); + expect(rlen == text.length).assertTrue(); + ss.closeSync(); + fileio.unlinkSync(fpath); + } + catch (e) { + console.info('fileio_test_stream_fdopen_stream_sync_008 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_stream_FdopenStreamSync_0900 + * @tc.name fileio_test_stream_fdopen_stream_sync_009 + * @tc.desc Function of API, mode=w+. The test file is not exist. + */ + it('fileio_test_stream_fdopen_stream_sync_009', 0, async function () { + let fpath = await nextFileName('fileio_test_stream_fdopen_stream_sync_009'); + try { + let fd = fileio.openSync(fpath, 0o102, 0o666); + let ss = fileio.fdopenStreamSync(fd, 'w+'); + expect(ss !== null).assertTrue(); + ss.closeSync(); + fileio.unlinkSync(fpath); + } + catch (e) { + console.info('fileio_test_stream_fdopen_stream_sync_009 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_stream_FdopenStreamSync_1000 + * @tc.name fileio_test_stream_fdopen_stream_sync_010 + * @tc.desc Function of API, mode=a+. The test file is exist. + */ + it('fileio_test_stream_fdopen_stream_sync_010', 0, async function () { + let fpath = await nextFileName('fileio_test_stream_fdopen_stream_sync_010'); + expect(prepareFile(fpath, '1')).assertTrue(); + let text = '0123456789abcdefg'; + try { + let fd = fileio.openSync(fpath, 0o2002); + expect(fd !== null).assertTrue(); + let ss = fileio.fdopenStreamSync(fd, 'a+'); + expect(ss !== null).assertTrue(); + let wlen = ss.writeSync(text); + expect(wlen !== null).assertTrue(); + ss.closeSync(); + expect(fileToReadOnly(fpath)).assertTrue(); + ss = fileio.createStreamSync(fpath, 'r'); + let rlen = ss.readSync(new ArrayBuffer(4096)); + expect(rlen == text.length + 1).assertTrue(); + ss.closeSync(); + fileio.unlinkSync(fpath); + } + catch (e) { + console.info('fileio_test_stream_fdopen_stream_sync_010 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_stream_FdopenStreamSync_1100 + * @tc.name fileio_test_stream_fdopen_stream_sync_011 + * @tc.desc Function of API, mode=a+. The test file is not exist. + */ + it('fileio_test_stream_fdopen_stream_sync_011', 0, async function () { + let fpath = await nextFileName('fileio_test_stream_fdopen_stream_sync_011'); + try { + let fd = fileio.openSync(fpath, 0o102, 0o666); + let ss = fileio.fdopenStreamSync(fd, 'a+'); + expect(ss !== null).assertTrue(); + ss.closeSync(); + fileio.unlinkSync(fpath); + } + catch (e) { + console.info('fileio_test_stream_fdopen_stream_sync_011 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_stream_FdopenStreamSync_1200 + * @tc.name fileio_test_stream_fdopen_stream_sync_012 + * @tc.desc Function of API, mode=rb. The test file is exist. + */ + it('fileio_test_stream_fdopen_stream_sync_012', 0, async function () { + let fpath = await nextFileName('fileio_test_stream_fdopen_stream_sync_012'); + expect(prepareFile(fpath, '')).assertTrue(); + expect(fileToReadOnly(fpath)).assertTrue(); + try { + let fd = fileio.openSync(fpath, 0o0); + let ss = fileio.fdopenStreamSync(fd, 'rb'); + expect(ss !== null).assertTrue(); + ss.closeSync(); + fileio.unlinkSync(fpath); + } + catch (e) { + console.info('fileio_test_stream_fdopen_stream_sync_012 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_stream_FdopenStreamSync_1300 + * @tc.name fileio_test_stream_fdopen_stream_sync_013 + * @tc.desc Function of API, mode=rb. The test file is not exist. + */ + it('fileio_test_stream_fdopen_stream_sync_013', 0, async function () { + try { + fileio.fdopenStreamSync(-1, 'rb'); + throw new Error('Bad file descriptor'); + } + catch (e) { + console.info('fileio_test_stream_fdopen_stream_sync_013 has failed for ' + e); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_stream_FdopenStreamSync_1400 + * @tc.name fileio_test_stream_fdopen_stream_sync_014 + * @tc.desc Function of API, mode=wb. The test file is exist. + */ + it('fileio_test_stream_fdopen_stream_sync_014', 0, async function () { + let fpath = await nextFileName('fileio_test_stream_fdopen_stream_sync_014'); + expect(prepareFile(fpath, '')).assertTrue(); + expect(fileToWriteOnly(fpath)).assertTrue(); + let text = '0123456789abcdefg'; + try { + let fd = fileio.openSync(fpath, 0o001); + expect(fd !== null).assertTrue(); + let ss = fileio.fdopenStreamSync(fd, 'wb'); + expect(ss !== null).assertTrue(); + let wlen = ss.writeSync(text); + expect(wlen !== null).assertTrue(); + ss.closeSync(); + expect(fileToReadOnly(fpath)).assertTrue(); + ss = fileio.createStreamSync(fpath, 'r'); + let rlen = ss.readSync(new ArrayBuffer(4096)); + expect(rlen == text.length).assertTrue(); + ss.closeSync(); + fileio.unlinkSync(fpath); + } + catch (e) { + console.info('fileio_test_stream_fdopen_stream_sync_014 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_stream_FdopenStreamSync_1500 + * @tc.name fileio_test_stream_fdopen_stream_sync_015 + * @tc.desc Function of API, mode=wb. The test file is not exist. + */ + it('fileio_test_stream_fdopen_stream_sync_015', 0, async function () { + let fpath = await nextFileName('fileio_test_stream_fdopen_stream_sync_015'); + try { + let fd = fileio.openSync(fpath, 0o101, 0o222); + let ss = fileio.fdopenStreamSync(fd, 'wb'); + expect(ss !== null).assertTrue(); + ss.closeSync(); + fileio.unlinkSync(fpath); + } + catch (e) { + console.info('fileio_test_stream_fdopen_stream_sync_015 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_stream_FdopenStreamSync_1600 + * @tc.name fileio_test_stream_fdopen_stream_sync_016 + * @tc.desc Function of API, mode=ab. The test file is exist. + */ + it('fileio_test_stream_fdopen_stream_sync_016', 0, async function () { + let fpath = await nextFileName('fileio_test_stream_fdopen_stream_sync_016'); + expect(prepareFile(fpath, '1')).assertTrue(); + expect(fileToWriteOnly(fpath)).assertTrue(); + let text = '0123456789abcdefg'; + try { + let fd = fileio.openSync(fpath, 0o2001); + expect(fd !== null).assertTrue(); + let ss = fileio.fdopenStreamSync(fd, 'ab'); + expect(ss !== null).assertTrue(); + let wlen = ss.writeSync(text); + expect(wlen !== null).assertTrue(); + ss.closeSync(); + expect(fileToReadOnly(fpath)).assertTrue(); + ss = fileio.createStreamSync(fpath, 'r'); + let rlen = ss.readSync(new ArrayBuffer(4096)); + expect(rlen == text.length + 1).assertTrue(); + ss.closeSync(); + fileio.unlinkSync(fpath); + } + catch (e) { + console.info('fileio_test_stream_fdopen_stream_sync_016 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_stream_FdopenStreamSync_1700 + * @tc.name fileio_test_stream_fdopen_stream_sync_017 + * @tc.desc Function of API, mode=ab. The test file is not exist. + */ + it('fileio_test_stream_fdopen_stream_sync_017', 0, async function () { + let fpath = await nextFileName('fileio_test_stream_fdopen_stream_sync_017'); + try { + let fd = fileio.openSync(fpath, 0o101, 0o222); + let ss = fileio.fdopenStreamSync(fd, 'ab'); + expect(ss !== null).assertTrue(); + ss.closeSync(); + fileio.unlinkSync(fpath); + } + catch (e) { + console.info('fileio_test_stream_fdopen_stream_sync_017 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_stream_FdopenStreamSync_1800 + * @tc.name fileio_test_stream_fdopen_stream_sync_018 + * @tc.desc Function of API, mode=rb+. The test file is exist. + */ + it('fileio_test_stream_fdopen_stream_sync_018', 0, async function () { + let fpath = await nextFileName('fileio_test_stream_fdopen_stream_sync_018'); + expect(prepareFile(fpath, '')).assertTrue(); + try { + let fd = fileio.openSync(fpath, 0o2); + let ss = fileio.fdopenStreamSync(fd, 'rb+'); + expect(ss !== null).assertTrue(); + ss.closeSync(); + fileio.unlinkSync(fpath); + } + catch (e) { + console.info('fileio_test_stream_fdopen_stream_sync_018 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_stream_FdopenStreamSync_1900 + * @tc.name fileio_test_stream_fdopen_stream_sync_019 + * @tc.desc Function of API, mode=rb+. The test file is not exist. + */ + it('fileio_test_stream_fdopen_stream_sync_019', 0, async function () { + try { + fileio.fdopenStreamSync(-1, 'rb+'); + throw new Error('Bad file descriptor'); + } + catch (e) { + console.info('fileio_test_stream_fdopen_stream_sync_019 has failed for ' + e); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_stream_FdopenStreamSync_2000 + * @tc.name fileio_test_stream_fdopen_stream_sync_020 + * @tc.desc Function of API, mode=wb+. The test file is exist. + */ + it('fileio_test_stream_fdopen_stream_sync_020', 0, async function () { + let fpath = await nextFileName('fileio_test_stream_fdopen_stream_sync_020'); + expect(prepareFile(fpath, '')).assertTrue(); + let text = '0123456789abcdefg'; + try { + let fd = fileio.openSync(fpath, 0o002); + expect(fd !== null).assertTrue(); + let ss = fileio.fdopenStreamSync(fd, 'wb+'); + expect(ss !== null).assertTrue(); + let wlen = ss.writeSync(text); + expect(wlen !== null).assertTrue(); + ss.closeSync(); + expect(fileToReadOnly(fpath)).assertTrue(); + ss = fileio.createStreamSync(fpath, 'r'); + let rlen = ss.readSync(new ArrayBuffer(4096)); + expect(rlen == text.length).assertTrue(); + ss.closeSync(); + fileio.unlinkSync(fpath); + } + catch (e) { + console.info('fileio_test_stream_fdopen_stream_sync_020 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_stream_FdopenStreamSync_2100 + * @tc.name fileio_test_stream_fdopen_stream_sync_021 + * @tc.desc Function of API, mode=wb+. The test file is not exist. + */ + it('fileio_test_stream_fdopen_stream_sync_021', 0, async function () { + let fpath = await nextFileName('fileio_test_stream_fdopen_stream_sync_021'); + try { + let fd = fileio.openSync(fpath, 0o102, 0o666); + let ss = fileio.fdopenStreamSync(fd, 'wb+'); + expect(ss !== null).assertTrue(); + ss.closeSync(); + fileio.unlinkSync(fpath); + } + catch (e) { + console.info('fileio_test_stream_fdopen_stream_sync_021 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_stream_FdopenStreamSync_2200 + * @tc.name fileio_test_stream_fdopen_stream_sync_022 + * @tc.desc Function of API, mode=ab+. The test file is exist. + */ + it('fileio_test_stream_fdopen_stream_sync_022', 0, async function () { + let fpath = await nextFileName('fileio_test_stream_fdopen_stream_sync_022'); + expect(prepareFile(fpath, '1')).assertTrue(); + let text = '0123456789abcdefg'; + try { + let fd = fileio.openSync(fpath, 0o2002); + expect(fd !== null).assertTrue(); + let ss = fileio.fdopenStreamSync(fd, 'ab+'); + expect(ss !== null).assertTrue(); + let wlen = ss.writeSync(text); + expect(wlen !== null).assertTrue(); + ss.closeSync(); + expect(fileToReadOnly(fpath)).assertTrue(); + ss = fileio.createStreamSync(fpath, 'r'); + let rlen = ss.readSync(new ArrayBuffer(4096)); + expect(rlen == text.length + 1).assertTrue(); + ss.closeSync(); + fileio.unlinkSync(fpath); + } + catch (e) { + console.info('fileio_test_stream_fdopen_stream_sync_022 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_stream_FdopenStreamSync_2300 + * @tc.name fileio_test_stream_fdopen_stream_sync_023 + * @tc.desc Function of API, mode=ab+. The test file is not exist. + */ + it('fileio_test_stream_fdopen_stream_sync_023', 0, async function () { + let fpath = await nextFileName('fileio_test_stream_fdopen_stream_sync_023'); + try { + let fd = fileio.openSync(fpath, 0o102, 0o666); + let ss = fileio.fdopenStreamSync(fd, 'ab+'); + expect(ss !== null).assertTrue(); + ss.closeSync(); + fileio.unlinkSync(fpath); + } + catch (e) { + console.info('fileio_test_stream_fdopen_stream_sync_023 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_stream_FdopenStreamSync_2400 + * @tc.name fileio_test_stream_fdopen_stream_sync_024 + * @tc.desc Function of API, invalid fields. The test file is not exist. + */ + it('fileio_test_stream_fdopen_stream_sync_024', 0, async function () { + try { + fileio.fdopenStreamSync(null, 'r') + expect(null).assertFail(); + } + catch (e) { + console.info('fileio_test_stream_fdopen_stream_sync_024 has failed for ' + e); + expect(e.message == 'Arg fd is required to be type integer').assertTrue(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_stream_FdopenStreamSync_2400 + * @tc.name fileio_test_stream_fdopen_stream_sync_025 + * @tc.desc Function of API, invalid mode. The test file is exist. + */ + it('fileio_test_stream_fdopen_stream_sync_025', 0, async function () { + let fpath = await nextFileName('fileio_test_stream_fdopen_stream_sync_025'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let fd = fileio.openSync(fpath, 0o2); + fileio.fdopenStreamSync(fd, ''); + throw new Error('invalid mode'); + } + catch (e) { + console.info('fileio_test_stream_fdopen_stream_sync_025 has failed for ' + e); + fileio.unlinkSync(fpath); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_stream_ReadSync_0000 + * @tc.name fileio_test_stream_read_sync_000 + * @tc.desc Function of API, not set options. + */ + it('fileio_test_stream_read_sync_000', 0, async function () { + let fpath = await nextFileName('fileio_test_stream_read_sync_000'); + let text = '0123456789abcdefg'; + expect(prepareFile(fpath, text)).assertTrue(); + try { + let ss = fileio.createStreamSync(fpath, 'r+'); + expect(ss !== null).assertTrue(); + let len = ss.readSync(new ArrayBuffer(4096)); + expect(len == text.length).assertTrue(); + ss.closeSync(); + fileio.unlinkSync(fpath); + } + catch (e) { + console.info('fileio_test_stream_read_sync_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_stream_ReadSync_0100 + * @tc.name fileio_test_stream_read_sync_001 + * @tc.desc Function of API, position. + */ + it('fileio_test_stream_read_sync_001', 0, async function () { + let fpath = await nextFileName('fileio_test_stream_read_sync_001'); + let text = '0123456789abcdefg'; + expect(prepareFile(fpath, text)).assertTrue(); + try { + let ss = fileio.createStreamSync(fpath, 'r+'); + expect(ss !== null).assertTrue(); + let len = ss.readSync(new ArrayBuffer(4096), { + position: 1 + }); + expect(len == text.length - 1).assertTrue(); + ss.closeSync(); + fileio.unlinkSync(fpath); + } + catch (e) { + console.info('fileio_test_stream_read_sync_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_stream_ReadSync_0200 + * @tc.name fileio_test_stream_read_sync_002 + * @tc.desc Function of API, offset. + */ + it('fileio_test_stream_read_sync_002', 0, async function () { + let fpath = await nextFileName('fileio_test_stream_read_sync_002'); + let text = '0123456789abcdefg'; + expect(prepareFile(fpath, text)).assertTrue(); + try { + let ss = fileio.createStreamSync(fpath, 'r+'); + expect(ss !== null).assertTrue(); + let len = ss.readSync(new ArrayBuffer(4096), { + offset: 1 + }); + expect(len == text.length).assertTrue(); + ss.closeSync(); + fileio.unlinkSync(fpath); + } + catch (e) { + console.info('fileio_test_stream_read_sync_002 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_stream_ReadSync_0300 + * @tc.name fileio_test_stream_read_sync_003 + * @tc.desc Function of API, length. + */ + it('fileio_test_stream_read_sync_003', 0, async function () { + let fpath = await nextFileName('fileio_test_stream_read_sync_003'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let ss = fileio.createStreamSync(fpath, 'r+'); + expect(ss !== null).assertTrue(); + let len = ss.readSync(new ArrayBuffer(4096), { + length: 1 + }); + expect(len == 1).assertTrue(); + ss.closeSync(); + fileio.unlinkSync(fpath); + } + catch (e) { + console.info('fileio_test_stream_read_sync_003 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_stream_ReadSync_0400 + * @tc.name fileio_test_stream_read_sync_004 + * @tc.desc Function of API, readBuf. + */ + it('fileio_test_stream_read_sync_004', 0, async function () { + let fpath = await nextFileName('fileio_test_stream_read_sync_004'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + var ss = fileio.createStreamSync(fpath, 'r+'); + expect(ss !== null).assertTrue(); + let len = ss.readSync(null); + expect(len == null).assertTrue(); + expect(null).assertFail(); + } + catch (e) { + console.info('fileio_test_stream_read_sync_004 has failed for ' + e); + expect(e.message == 'Invalid read buffer, expect arraybuffer').assertTrue(); + ss.closeSync(); + fileio.unlinkSync(fpath); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_stream_ReadSync_0500 + * @tc.name fileio_test_stream_read_sync_005 + * @tc.desc Function of API, position = -1. + */ + it('fileio_test_stream_read_sync_005', 0, async function () { + let fpath = await nextFileName('fileio_test_stream_read_sync_005'); + let text = '0123456789abcdefg'; + expect(prepareFile(fpath, text)).assertTrue(); + let ss = fileio.createStreamSync(fpath, 'r+'); + expect(ss !== null).assertTrue(); + try { + ss.readSync(new ArrayBuffer(4096), { + position: -1 + }); + } + catch (e) { + console.info('fileio_test_stream_read_sync_005 has failed for ' + e); + expect(e.message == "option.position shall be positive number").assertTrue(); + ss.closeSync(); + fileio.unlinkSync(fpath); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_stream_ReadSync_0600 + * @tc.name fileio_test_stream_read_sync_006 + * @tc.desc Function of API, offset. + */ + it('fileio_test_stream_read_sync_006', 0, async function () { + let fpath = await nextFileName('fileio_test_stream_read_sync_006'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + var ss = fileio.createStreamSync(fpath, 'r+'); + expect(ss !== null).assertTrue(); + let len = ss.readSync(new ArrayBuffer(4096), { + offset: -1 + }); + expect(len == null).assertTrue(); + expect(null).assertFail(); + } + catch (e) { + console.info('fileio_test_stream_read_sync_006 has failed for ' + e); + expect(e.message == 'Invalid option.offset, positive integer is desired').assertTrue(); + ss.closeSync(); + fileio.unlinkSync(fpath); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_stream_WriteSync_0000 + * @tc.name fileio_test_stream_write_sync_000 + * @tc.desc Function of API, not set options. + */ + it('fileio_test_stream_write_sync_000', 0, async function () { + let fpath = await nextFileName('fileio_test_stream_write_sync_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let text = '0123456789abcdefg'; + try { + let ss = fileio.createStreamSync(fpath, 'r+'); + expect(ss !== null).assertTrue(); + expect(ss.writeSync(text) == text.length).assertTrue(); + ss.closeSync(); + fileio.unlinkSync(fpath); + console.info('---fileio_test_stream_write_sync_000 is passed!'); + } + catch (e) { + console.info('fileio_test_stream_write_sync_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_stream_WriteSync_0100 + * @tc.name fileio_test_stream_write_sync_001 + * @tc.desc Function of API, invalid encoding. + */ + it('fileio_test_stream_write_sync_001', 0, async function () { + let fpath = await nextFileName('fileio_test_stream_write_sync_001'); + expect(prepareFile(fpath, '')).assertTrue(); + let ss + try { + ss = fileio.createStreamSync(fpath, 'w+'); + expect(ss !== null).assertTrue(); + ss.writeSync(FILE_CONTENT, { + encoding: 'ASCII' + }) + expect(null).assertFail(); + } + catch (e) { + console.info('fileio_test_stream_write_sync_001 has failed for ' + e); + expect(e.message == 'Illegal write buffer or encoding').assertTrue(); + ss.closeSync(); + fileio.unlinkSync(fpath); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_stream_WriteSync_0200 + * @tc.name fileio_test_stream_write_sync_002 + * @tc.desc Function of API, position. + */ + it('fileio_test_stream_write_sync_002', 0, async function () { + let fpath = await nextFileName('fileio_test_stream_write_sync_002'); + expect(prepareFile(fpath, 'a')).assertTrue(); + expect(fileToWriteOnly(fpath)).assertTrue(); + try { + let fd = fileio.openSync(fpath, 0o001); + expect(fd !== null).assertTrue(); + let ss = fileio.fdopenStreamSync(fd, 'w'); + expect(ss !== null).assertTrue(); + expect(ss.writeSync('aaa') !== null).assertTrue(); + ss.closeSync(); + expect(fileToReadOnly(fpath)).assertTrue(); + ss = fileio.createStreamSync(fpath, 'r'); + let rlen = ss.readSync(new ArrayBuffer(4096)); + expect(rlen == 3).assertTrue(); + ss.closeSync(); + fileio.unlinkSync(fpath); + } + catch (e) { + console.info('fileio_test_stream_write_sync_002 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_stream_WriteSync_0300 + * @tc.name fileio_test_stream_write_sync_003 + * @tc.desc Function of API, offset. + */ + it('fileio_test_stream_write_sync_003', 0, async function () { + let fpath = await nextFileName('fileio_test_stream_write_sync_003'); + expect(prepareFile(fpath, 'a')).assertTrue(); + expect(fileToWriteOnly(fpath)).assertTrue(); + try { + let fd = fileio.openSync(fpath, 0o001); + expect(fd !== null).assertTrue(); + let ss = fileio.fdopenStreamSync(fd, 'w'); + expect(ss !== null).assertTrue(); + expect(ss.writeSync('aaa') !== null).assertTrue(); + ss.closeSync(); + expect(fileToReadOnly(fpath)).assertTrue(); + ss = fileio.createStreamSync(fpath, 'r'); + let rlen = ss.readSync(new ArrayBuffer(4096)); + expect(rlen == 3).assertTrue(); + ss.closeSync(); + fileio.unlinkSync(fpath); + } + catch (e) { + console.info('fileio_test_stream_write_sync_003 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_stream_WriteSync_0400 + * @tc.name fileio_test_stream_write_sync_004 + * @tc.desc Function of API, length. + */ + it('fileio_test_stream_write_sync_004', 0, async function () { + let fpath = await nextFileName('fileio_test_stream_write_sync_004'); + expect(prepareFile(fpath, 'a')).assertTrue(); + let text = '0123456789abcdefg'; + try { + let ss = fileio.createStreamSync(fpath, 'r+'); + expect(ss !== null).assertTrue(); + let wlen = ss.writeSync(text); + expect(wlen == text.length).assertTrue(); + ss.closeSync(); + ss = fileio.createStreamSync(fpath, 'r+'); + let rlen = ss.readSync(new ArrayBuffer(4096)); + expect(rlen == text.length).assertTrue(); + ss.closeSync(); + fileio.unlinkSync(fpath); + } + catch (e) { + console.info('fileio_test_stream_write_sync_004 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_stream_WriteSync_0500 + * @tc.name fileio_test_stream_write_sync_005 + * @tc.desc Function of API, encoding. + */ + it('fileio_test_stream_write_sync_005', 0, async function () { + let fpath = await nextFileName('fileio_test_stream_write_sync_005'); + expect(prepareFile(fpath, '')).assertTrue(); + let writeStrArray = new Array('aaa', '123'); + let encodingArray = new Array('utf-8', 'utf-16'); + try { + for (let i = 0; i < encodingArray.length; i++) { + let ss = fileio.createStreamSync(fpath, 'w+'); + expect(ss !== null).assertTrue(); + ss.writeSync(writeStrArray[i], { + encoding: encodingArray[i] + }) + ss.closeSync(); + ss = fileio.createStreamSync(fpath, 'r+'); + let rlen = ss.readSync(new ArrayBuffer(4096)); + expect(rlen !== null).assertTrue(); + ss.closeSync(); + } + fileio.unlinkSync(fpath); + } + catch (e) { + console.info('fileio_test_stream_write_sync_005 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_stream_WriteSync_0600 + * @tc.name fileio_test_stream_write_sync_006 + * @tc.desc Function of API, position. + */ + it('fileio_test_stream_write_sync_006', 0, async function () { + let fpath = await nextFileName('fileio_test_stream_write_sync_006'); + expect(prepareFile(fpath, 'a')).assertTrue(); + expect(fileToWriteOnly(fpath)).assertTrue(); + try { + let fd = fileio.openSync(fpath, 0o001); + expect(fd !== null).assertTrue(); + let ss = fileio.fdopenStreamSync(fd, 'w'); + expect(ss !== null).assertTrue(); + expect(ss.writeSync('aaa', { + position: 1 + }) !== null).assertTrue(); + ss.closeSync(); + expect(fileToReadOnly(fpath)).assertTrue(); + ss = fileio.createStreamSync(fpath, 'r'); + let rlen = ss.readSync(new ArrayBuffer(4096)); + expect(rlen == 4).assertTrue(); + ss.closeSync(); + fileio.unlinkSync(fpath); + } + catch (e) { + console.info('fileio_test_stream_write_sync_006 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_stream_WriteSync_0700 + * @tc.name fileio_test_stream_write_sync_007 + * @tc.desc Function of API, offset. + */ + it('fileio_test_stream_write_sync_007', 0, async function () { + let fpath = await nextFileName('fileio_test_stream_write_sync_007'); + expect(prepareFile(fpath, 'a')).assertTrue(); + expect(fileToWriteOnly(fpath)).assertTrue(); + try { + let fd = fileio.openSync(fpath, 0o001); + expect(fd !== null).assertTrue(); + let ss = fileio.fdopenStreamSync(fd, 'w'); + expect(ss !== null).assertTrue(); + expect(ss.writeSync('aaa', { + offset: 1 + }) !== null).assertTrue(); + ss.closeSync(); + expect(fileToReadOnly(fpath)).assertTrue(); + ss = fileio.createStreamSync(fpath, 'r'); + let rlen = ss.readSync(new ArrayBuffer(4096)); + expect(rlen == 2).assertTrue(); + ss.closeSync(); + fileio.unlinkSync(fpath); + } + catch (e) { + console.info('fileio_test_stream_write_sync_007 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_stream_WriteSync_0800 + * @tc.name fileio_test_stream_write_sync_008 + * @tc.desc Function of API, length. + */ + it('fileio_test_stream_write_sync_008', 0, async function () { + let fpath = await nextFileName('fileio_test_stream_write_sync_008'); + expect(prepareFile(fpath, '')).assertTrue(); + let text = '0123456789abcdefg'; + try { + let ss = fileio.createStreamSync(fpath, 'r+'); + expect(ss !== null).assertTrue(); + let wlen = ss.writeSync(text, { + length: text.length + }); + expect(wlen == text.length).assertTrue(); + ss.closeSync(); + ss = fileio.createStreamSync(fpath, 'r+'); + let rlen = ss.readSync(new ArrayBuffer(4096)); + expect(rlen == text.length).assertTrue(); + ss.closeSync(); + fileio.unlinkSync(fpath); + } + catch (e) { + console.info('fileio_test_stream_write_sync_008 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_stream_WriteSync_0900 + * @tc.name fileio_test_stream_write_sync_009 + * @tc.desc Function of API, invalid fcontent. + */ + it('fileio_test_stream_write_sync_009', 0, async function () { + let fpath = await nextFileName('fileio_test_stream_write_sync_009'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + var ss = fileio.createStreamSync(fpath, 'r+'); + expect(ss !== null).assertTrue(); + ss.writeSync(-1); + expect(null).assertFail(); + } + catch (e) { + console.info('fileio_test_stream_write_sync_009 has failed for ' + e); + expect(e.message == 'Illegal write buffer or encoding').assertTrue(); + fileio.unlinkSync(fpath); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_stream_WriteSync_1000 + * @tc.name fileio_test_stream_write_sync_010 + * @tc.desc Function of API, invalid encoding. + */ + it('fileio_test_stream_write_sync_010', 0, async function () { + let fpath = await nextFileName('fileio_test_stream_write_sync_010'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + var ss = fileio.createStreamSync(fpath, 'r+'); + expect(ss !== null).assertTrue(); + ss.writeSync(FILE_CONTENT, { + encoding: '' + }) + expect(null).assertFail(); + } + catch (e) { + console.info('fileio_test_stream_write_sync_010 has failed for ' + e); + expect(e.message == 'Illegal write buffer or encoding').assertTrue(); + ss.closeSync(); + fileio.unlinkSync(fpath); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_stream_WriteSync_1100 + * @tc.name fileio_test_stream_write_sync_011 + * @tc.desc Function of API, invalid position. + */ + it('fileio_test_stream_write_sync_011', 0, async function () { + let fpath = await nextFileName('fileio_test_stream_write_sync_011'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + var ss = fileio.createStreamSync(fpath, 'r+'); + expect(ss !== null).assertTrue(); + ss.writeSync(FILE_CONTENT, { + position: -1 + }) + expect(null).assertFail(); + } + catch (e) { + console.info('fileio_test_stream_write_sync_011 has failed for ' + e); + expect(e.message == 'option.position shall be positive number').assertTrue(); + ss.closeSync(); + fileio.unlinkSync(fpath); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_stream_WriteSync_1200 + * @tc.name fileio_test_stream_write_sync_012 + * @tc.desc Function of API, invalid offset. + */ + it('fileio_test_stream_write_sync_012', 0, async function () { + let fpath = await nextFileName('fileio_test_stream_write_sync_012'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + var ss = fileio.createStreamSync(fpath, 'r+'); + expect(ss !== null).assertTrue(); + ss.writeSync(FILE_CONTENT, { + offset: -1 + }) + expect(null).assertFail(); + } + catch (e) { + console.info('fileio_test_stream_write_sync_012 has failed for ' + e); + expect(e.message == 'Invalid option.offset, positive integer is desired').assertTrue(); + ss.closeSync(); + fileio.unlinkSync(fpath); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_stream_WriteSync_1300 + * @tc.name fileio_test_stream_write_sync_013 + * @tc.desc Function of API, Set all parameters. + */ + it('fileio_test_stream_write_sync_013', 0, async function () { + let fpath = await nextFileName('fileio_test_stream_write_sync_013'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let text = '0123456789abcdefg'; + try { + let ss = fileio.createStreamSync(fpath, 'r+'); + expect(ss !== null).assertTrue(); + expect(ss.writeSync(text, { + encoding: 'utf-8', + position: 0, + offset: 1, + length: 1, + }) == 1).assertTrue(); + ss.closeSync(); + fileio.unlinkSync(fpath); + console.info('---fileio_test_stream_write_sync_013 is passed!'); + } + catch (e) { + console.info('fileio_test_stream_write_sync_013 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_stream_WriteSync_1400 + * @tc.name fileio_test_stream_write_sync_014 + * @tc.desc Function of API, Set all parameters. + */ + it('fileio_test_stream_write_sync_014', 0, async function () { + let fpath = await nextFileName('fileio_test_stream_write_sync_014'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let text = '0123456789abcdefg'; + try { + let ss = fileio.createStreamSync(fpath, 'r+'); + expect(ss !== null).assertTrue(); + expect(ss.writeSync(text, { + offset: 2, + length: 2, + }) == 2).assertTrue(); + ss.closeSync(); + fileio.unlinkSync(fpath); + console.info('---fileio_test_stream_write_sync_014 is passed!'); + } + catch (e) { + console.info('fileio_test_stream_write_sync_014 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_stream_write_read_4k_sync + * @tc.name fileio_test_stream_write_read_4k_sync + * @tc.desc Function of API, read 4k file. + */ + it('fileio_test_stream_write_read_4k_sync', 0, async function () { + let fpath = await nextFileName('fileio_test_stream_write_read_4k_sync'); + expect(prepareFile(fpath, 'a')).assertTrue(); + expect(fileToWriteOnly(fpath)).assertTrue(); + try { + let fd = fileio.openSync(fpath, 0o001); + expect(fd !== null).assertTrue(); + let ss = fileio.fdopenStreamSync(fd, 'w'); + expect(ss !== null).assertTrue(); + expect(ss.writeSync(randomString(4096)) !== null).assertTrue(); + ss.closeSync(); + expect(fileToReadOnly(fpath)).assertTrue(); + ss = fileio.createStreamSync(fpath, 'r'); + let rlen = ss.readSync(new ArrayBuffer(4096)); + ss.closeSync(); + fileio.unlinkSync(fpath); + } + catch (e) { + console.info('fileio_test_stream_write_read_4k_sync has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_stream_FlushSync_0000 + * @tc.name fileio_test_stream_flush_sync_000 + * @tc.desc Function of API, flushSync. + */ + it('fileio_test_stream_flush_sync_000', 0, async function () { + let fpath = await nextFileName('fileio_test_stream_flush_sync_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let text = '0123456789abcdefg'; + try { + let ss = fileio.createStreamSync(fpath, 'r+'); + expect(ss !== null).assertTrue(); + expect(ss.writeSync(text) == text.length).assertTrue(); + ss.flushSync(); + ss.closeSync(); + fileio.unlinkSync(fpath); + } + catch (e) { + console.info('fileio_test_stream_flush_sync_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_stream_FlushSync_0100 + * @tc.name fileio_test_stream_flush_sync_001 + * @tc.desc Function of API, error. + */ + it('fileio_test_stream_flush_sync_001', 0, async function () { + let fpath = await nextFileName('fileio_test_stream_flush_sync_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let ss = fileio.createStreamSync(fpath, 'r+'); + expect(ss !== null).assertTrue(); + ss.closeSync(); + ss.flushSync(); + expect(null).assertFail(); + } + catch (e) { + console.info('fileio_test_stream_flush_sync_001 has failed for ' + e); + expect(e.message == 'Stream may has been closed').assertTrue(); + fileio.unlinkSync(fpath); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_stream_CloseSync_0000 + * @tc.name fileio_test_stream_close_sync_000 + * @tc.desc Function of API, closeSync. + */ + it('fileio_test_stream_close_sync_000', 0, async function () { + let fpath = await nextFileName('fileio_test_stream_close_sync_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let ss = fileio.createStreamSync(fpath, 'r+'); + ss.closeSync(); + fileio.unlinkSync(fpath); + } + catch (e) { + console.info('fileio_test_stream_close_sync_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_stream_CloseSync_0100 + * @tc.name fileio_test_stream_close_sync_001 + * @tc.desc Function of API, error. + */ + it('fileio_test_stream_close_sync_001', 0, async function () { + let fpath = await nextFileName('fileio_test_stream_close_sync_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let ss; + try { + ss = fileio.createStreamSync(fpath, 'r+'); + ss.closeSync(); + ss.closeSync(); + expect(null).assertFail(); + } + catch (e) { + console.info('fileio_test_stream_close_sync_001 has failed for ' + e); + expect(e.message == 'Stream may have been closed yet').assertTrue(); + fileio.unlinkSync(fpath); + } + }); +}); +} diff --git a/storage/storagefileiojstest/entry/src/ohosTest/js/test/List.test.js b/storage/storagefileiojstest/src/main/js/test/List.test.js similarity index 96% rename from storage/storagefileiojstest/entry/src/ohosTest/js/test/List.test.js rename to storage/storagefileiojstest/src/main/js/test/List.test.js index d822290765f6906af2ab7e63896259d02cfd7322..13520c17f42400326f2495c0850bd91bd58bfcd0 100644 --- a/storage/storagefileiojstest/entry/src/ohosTest/js/test/List.test.js +++ b/storage/storagefileiojstest/src/main/js/test/List.test.js @@ -1,121 +1,121 @@ -/* - * Copyright (C) 2023 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 fileIOTest from './FileIO.test.js' -import fileIOTestDir from './FileIODir.test.js' -import fileIOTestDirent from './FileIODirent.test.js' -import fileIOTestStat from './FileIOStat.test.js' -import fileIOTestStream from './FileIOStream.test.js' -import fileioDirClose from './module_fileio/class_dir/close.test.js' -import fileioDirListfile from './module_fileio/class_dir/listfile.test.js' -import fileioDirRead from './module_fileio/class_dir/read.test.js' -import fileioDirent from './module_fileio/class_dirent/all.test.js' -import fileioStream from './module_fileio/class_stream/all.test.js' -import fileioRandomAccessFileClose from './module_fileio/class_randomAccessFile/close.test.js' -import fileioRandomAccessFileRead from './module_fileio/class_randomAccessFile/read.test.js' -import fileioRandomAccessFileSetFilePointer from './module_fileio/class_randomAccessFile/setFilePointer.test.js' -import fileioRandomAccessFileWrite from './module_fileio/class_randomAccessFile/write.test.js' -import fileioStreamClose from './module_fileio/class_stream/close.test.js' -import fileioStreamFlush from './module_fileio/class_stream/flush.test.js' -import fileioStreamRead from './module_fileio/class_stream/read.test.js' -import fileioStreamWrite from './module_fileio/class_stream/write.test.js' -import fileioCreateWatcher from './module_fileio/class_watcher/createWatcher.test.js' -import fileioAccess from './module_fileio/members/access.test.js' -import fileioChmod from './module_fileio/members/chmod.test.js' -import fileioChown from './module_fileio/members/chown.test.js' -import fileioClose from './module_fileio/members/close.test.js' -import fileioCopyfile from './module_fileio/members/copyFile.test.js' -import fileioCreateRandomAccessFile from './module_fileio/members/createRandomAccessFile.test.js' -import fileioCreateStream from './module_fileio/members/createStream.test.js' -import fileioFchmod from './module_fileio/members/fchmod.test.js' -import fileioFchown from './module_fileio/members/fchown.test.js' -import fileioFdatasync from './module_fileio/members/fdatasync.test.js' -import fileioFdOpenStream from './module_fileio/members/fdopenStream.test.js' -import fileioFstat from './module_fileio/members/fstat.test.js' -import fileioFsync from './module_fileio/members/fsync.test.js' -import fileioFtruncate from './module_fileio/members/ftruncate.test.js' -import fileioHash from './module_fileio/members/hash.test.js' -import fileioLchown from './module_fileio/members/lchown.test.js' -import fileioLseek from './module_fileio/members/lseek.test.js' -import fileioLstat from './module_fileio/members/lstat.test.js' -import fileioMkdirRmdir from './module_fileio/members/mkdir_rmdir.test.js' -import fileioMkdtemp from './module_fileio/members/mkdtemp.test.js' -import fileioOpen from './module_fileio/members/open.test.js' -import fileioOpendirClose from './module_fileio/members/opendir_close.test.js' -import fileioOpenClose from './module_fileio/members/open_close.test.js' -import fileioPosixFallocate from './module_fileio/members/posix_fallocate.test.js' -import fileioRead from './module_fileio/members/read.test.js' -import fileioReadtext from './module_fileio/members/readtext.test.js' -import fileioRename from './module_fileio/members/rename.test.js' -import fileioRmdir from './module_fileio/members/rmdir.test.js' -import fileioStat from './module_fileio/members/stat.test.js' -import fileioSymlink from './module_fileio/members/symlink.test.js' -import fileioTruncate from './module_fileio/members/truncate.test.js' -import fileioUnlink from './module_fileio/members/unlink.test.js' -import fileioWrite from './module_fileio/members/write.test.js' -export default function testsuite() { - fileIOTest() - fileIOTestDir() - fileIOTestDirent() - fileIOTestStat() - fileIOTestStream() - fileioDirClose() - fileioDirListfile() - fileioDirRead() - fileioDirent() - fileioStream() - fileioRandomAccessFileClose() - fileioRandomAccessFileRead() - fileioRandomAccessFileSetFilePointer() - fileioRandomAccessFileWrite() - fileioStreamClose() - fileioStreamFlush() - fileioStreamRead() - fileioStreamWrite() - fileioCreateWatcher() - fileioAccess() - fileioChmod() - fileioChown() - fileioClose() - fileioCopyfile() - fileioCreateRandomAccessFile() - fileioCreateStream() - fileioFchmod() - fileioFchown() - fileioFdatasync() - fileioFdOpenStream() - fileioFstat() - fileioFsync() - fileioFtruncate() - fileioHash() - fileioLchown() - fileioLseek() - fileioLstat() - fileioMkdirRmdir() - fileioMkdtemp() - fileioOpen() - fileioOpendirClose() - fileioOpenClose() - fileioPosixFallocate() - fileioRead() - fileioReadtext() - fileioRename() - fileioRmdir() - fileioStat() - fileioSymlink() - fileioTruncate() - fileioUnlink() - fileioWrite() -} +/* + * Copyright (C) 2021-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. + */ + +import fileIOTest from './FileIO.test.js' +import fileIOTestDir from './FileIODir.test.js' +import fileIOTestDirent from './FileIODirent.test.js' +import fileIOTestStat from './FileIOStat.test.js' +import fileIOTestStream from './FileIOStream.test.js' +import fileioDirClose from './module_fileio/class_dir/close.test.js' +import fileioDirListfile from './module_fileio/class_dir/listfile.test.js' +import fileioDirRead from './module_fileio/class_dir/read.test.js' +import fileioDirent from './module_fileio/class_dirent/all.test.js' +import fileioStream from './module_fileio/class_stream/all.test.js' +import fileioRandomAccessFileClose from './module_fileio/class_randomAccessFile/close.test.js' +import fileioRandomAccessFileRead from './module_fileio/class_randomAccessFile/read.test.js' +import fileioRandomAccessFileSetFilePointer from './module_fileio/class_randomAccessFile/setFilePointer.test.js' +import fileioRandomAccessFileWrite from './module_fileio/class_randomAccessFile/write.test.js' +import fileioStreamClose from './module_fileio/class_stream/close.test.js' +import fileioStreamFlush from './module_fileio/class_stream/flush.test.js' +import fileioStreamRead from './module_fileio/class_stream/read.test.js' +import fileioStreamWrite from './module_fileio/class_stream/write.test.js' +import fileioCreateWatcher from './module_fileio/class_watcher/createWatcher.test.js' +import fileioAccess from './module_fileio/members/access.test.js' +import fileioChmod from './module_fileio/members/chmod.test.js' +import fileioChown from './module_fileio/members/chown.test.js' +import fileioClose from './module_fileio/members/close.test.js' +import fileioCopyfile from './module_fileio/members/copyFile.test.js' +import fileioCreateRandomAccessFile from './module_fileio/members/createRandomAccessFile.test.js' +import fileioCreateStream from './module_fileio/members/createStream.test.js' +import fileioFchmod from './module_fileio/members/fchmod.test.js' +import fileioFchown from './module_fileio/members/fchown.test.js' +import fileioFdatasync from './module_fileio/members/fdatasync.test.js' +import fileioFdOpenStream from './module_fileio/members/fdopenStream.test.js' +import fileioFstat from './module_fileio/members/fstat.test.js' +import fileioFsync from './module_fileio/members/fsync.test.js' +import fileioFtruncate from './module_fileio/members/ftruncate.test.js' +import fileioHash from './module_fileio/members/hash.test.js' +import fileioLchown from './module_fileio/members/lchown.test.js' +import fileioLseek from './module_fileio/members/lseek.test.js' +import fileioLstat from './module_fileio/members/lstat.test.js' +import fileioMkdirRmdir from './module_fileio/members/mkdir_rmdir.test.js' +import fileioMkdtemp from './module_fileio/members/mkdtemp.test.js' +import fileioOpen from './module_fileio/members/open.test.js' +import fileioOpendirClose from './module_fileio/members/opendir_close.test.js' +import fileioOpenClose from './module_fileio/members/open_close.test.js' +import fileioPosixFallocate from './module_fileio/members/posix_fallocate.test.js' +import fileioRead from './module_fileio/members/read.test.js' +import fileioReadtext from './module_fileio/members/readtext.test.js' +import fileioRename from './module_fileio/members/rename.test.js' +import fileioRmdir from './module_fileio/members/rmdir.test.js' +import fileioStat from './module_fileio/members/stat.test.js' +import fileioSymlink from './module_fileio/members/symlink.test.js' +import fileioTruncate from './module_fileio/members/truncate.test.js' +import fileioUnlink from './module_fileio/members/unlink.test.js' +import fileioWrite from './module_fileio/members/write.test.js' +export default function testsuite() { + fileIOTest() + fileIOTestDir() + fileIOTestDirent() + fileIOTestStat() + fileIOTestStream() + fileioDirClose() + fileioDirListfile() + fileioDirRead() + fileioDirent() + fileioStream() + fileioRandomAccessFileClose() + fileioRandomAccessFileRead() + fileioRandomAccessFileSetFilePointer() + fileioRandomAccessFileWrite() + fileioStreamClose() + fileioStreamFlush() + fileioStreamRead() + fileioStreamWrite() + fileioCreateWatcher() + fileioAccess() + fileioChmod() + fileioChown() + fileioClose() + fileioCopyfile() + fileioCreateRandomAccessFile() + fileioCreateStream() + fileioFchmod() + fileioFchown() + fileioFdatasync() + fileioFdOpenStream() + fileioFstat() + fileioFsync() + fileioFtruncate() + fileioHash() + fileioLchown() + fileioLseek() + fileioLstat() + fileioMkdirRmdir() + fileioMkdtemp() + fileioOpen() + fileioOpendirClose() + fileioOpenClose() + fileioPosixFallocate() + fileioRead() + fileioReadtext() + fileioRename() + fileioRmdir() + fileioStat() + fileioSymlink() + fileioTruncate() + fileioUnlink() + fileioWrite() +} diff --git a/storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/class_constants/constants.test.js b/storage/storagefileiojstest/src/main/js/test/module_fileio/class_constants/constants.test.js similarity index 92% rename from storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/class_constants/constants.test.js rename to storage/storagefileiojstest/src/main/js/test/module_fileio/class_constants/constants.test.js index bf190b979beb7602baf9dabbf2ecbb44be44a7f4..18f0219b746ae161bd862d9b57a89fae2eebb120 100644 --- a/storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/class_constants/constants.test.js +++ b/storage/storagefileiojstest/src/main/js/test/module_fileio/class_constants/constants.test.js @@ -1,75 +1,75 @@ -/** - * Copyright (c) 2023 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 { - fileio, - describe, it, expect, -} from '../../Common'; - -export default function constants() { -describe('constants', function () { - - /** - * @tc.number SUB_DF_FILEIO_CONSTANTS - * @tc.name fileio_test_constants - * @tc.desc Test constants() interface. - * @tc.size MEDIUM(中型) - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_constants', 0, function () { - try { - expect(fileio.constants.F_OK == 0).assertTrue(); - expect(fileio.constants.X_OK == 1).assertTrue(); - expect(fileio.constants.W_OK == 2).assertTrue(); - expect(fileio.constants.R_OK == 4).assertTrue(); - expect(fileio.constants.O_RDONLY == 0o0).assertTrue(); - expect(fileio.constants.O_WRONLY == 0o1).assertTrue(); - expect(fileio.constants.O_RDWR == 0o2).assertTrue(); - expect(fileio.constants.O_CREAT == 0o100).assertTrue(); - expect(fileio.constants.O_EXCL == 0o200).assertTrue(); - expect(fileio.constants.O_TRUNC == 0o1000).assertTrue(); - expect(fileio.constants.O_APPEND == 0o2000).assertTrue(); - expect(fileio.constants.O_NONBLOCK == 0o4000).assertTrue(); - expect(fileio.constants.O_DIRECTORY == 0o200000).assertTrue(); - expect(fileio.constants.O_NOFOLLOW == 0o400000).assertTrue(); - expect(fileio.constants.O_SYNC == 0o4010000).assertTrue(); - expect(fileio.constants.S_IFMT == 0o170000).assertTrue(); - expect(fileio.constants.S_IFSOCK == 0o140000).assertTrue(); - expect(fileio.constants.S_IFLNK == 0o120000).assertTrue(); - expect(fileio.constants.S_IFREG == 0o100000).assertTrue(); - expect(fileio.constants.S_IFBLK == 0o060000).assertTrue(); - expect(fileio.constants.S_IFDIR == 0o040000).assertTrue(); - expect(fileio.constants.S_IFCHR == 0o020000).assertTrue(); - expect(fileio.constants.S_IFIFO == 0o010000).assertTrue(); - expect(fileio.constants.S_IRWXU == 0o0700).assertTrue(); - expect(fileio.constants.S_IRUSR == 0o0400).assertTrue(); - expect(fileio.constants.S_IWUSR == 0o0200).assertTrue(); - expect(fileio.constants.S_IXUSR == 0o0100).assertTrue(); - expect(fileio.constants.S_IRWXG == 0o0070).assertTrue(); - expect(fileio.constants.S_IRGRP == 0o0040).assertTrue(); - expect(fileio.constants.S_IWGRP == 0o0020).assertTrue(); - expect(fileio.constants.S_IXGRP == 0o0010).assertTrue(); - expect(fileio.constants.S_IRWXO == 0o0007).assertTrue(); - expect(fileio.constants.S_IROTH == 0o0004).assertTrue(); - expect(fileio.constants.S_IWOTH == 0o0002).assertTrue(); - expect(fileio.constants.S_IXOTH == 0o0001).assertTrue(); - } catch (e) { - console.log('fileio_test_constants has failed for ' + e); - expect(null).assertFail(); - } - }); -});} +/* + * Copyright (C) 2021 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 { + fileio, + describe, it, expect, +} from '../../Common'; + +export default function constants() { +describe('constants', function () { + + /** + * @tc.number SUB_DF_FILEIO_CONSTANTS + * @tc.name fileio_test_constants + * @tc.desc Test constants() interface. + * @tc.size MEDIUM(中型) + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_constants', 0, function () { + try { + expect(fileio.constants.F_OK == 0).assertTrue(); + expect(fileio.constants.X_OK == 1).assertTrue(); + expect(fileio.constants.W_OK == 2).assertTrue(); + expect(fileio.constants.R_OK == 4).assertTrue(); + expect(fileio.constants.O_RDONLY == 0o0).assertTrue(); + expect(fileio.constants.O_WRONLY == 0o1).assertTrue(); + expect(fileio.constants.O_RDWR == 0o2).assertTrue(); + expect(fileio.constants.O_CREAT == 0o100).assertTrue(); + expect(fileio.constants.O_EXCL == 0o200).assertTrue(); + expect(fileio.constants.O_TRUNC == 0o1000).assertTrue(); + expect(fileio.constants.O_APPEND == 0o2000).assertTrue(); + expect(fileio.constants.O_NONBLOCK == 0o4000).assertTrue(); + expect(fileio.constants.O_DIRECTORY == 0o200000).assertTrue(); + expect(fileio.constants.O_NOFOLLOW == 0o400000).assertTrue(); + expect(fileio.constants.O_SYNC == 0o4010000).assertTrue(); + expect(fileio.constants.S_IFMT == 0o170000).assertTrue(); + expect(fileio.constants.S_IFSOCK == 0o140000).assertTrue(); + expect(fileio.constants.S_IFLNK == 0o120000).assertTrue(); + expect(fileio.constants.S_IFREG == 0o100000).assertTrue(); + expect(fileio.constants.S_IFBLK == 0o060000).assertTrue(); + expect(fileio.constants.S_IFDIR == 0o040000).assertTrue(); + expect(fileio.constants.S_IFCHR == 0o020000).assertTrue(); + expect(fileio.constants.S_IFIFO == 0o010000).assertTrue(); + expect(fileio.constants.S_IRWXU == 0o0700).assertTrue(); + expect(fileio.constants.S_IRUSR == 0o0400).assertTrue(); + expect(fileio.constants.S_IWUSR == 0o0200).assertTrue(); + expect(fileio.constants.S_IXUSR == 0o0100).assertTrue(); + expect(fileio.constants.S_IRWXG == 0o0070).assertTrue(); + expect(fileio.constants.S_IRGRP == 0o0040).assertTrue(); + expect(fileio.constants.S_IWGRP == 0o0020).assertTrue(); + expect(fileio.constants.S_IXGRP == 0o0010).assertTrue(); + expect(fileio.constants.S_IRWXO == 0o0007).assertTrue(); + expect(fileio.constants.S_IROTH == 0o0004).assertTrue(); + expect(fileio.constants.S_IWOTH == 0o0002).assertTrue(); + expect(fileio.constants.S_IXOTH == 0o0001).assertTrue(); + } catch (e) { + console.log('fileio_test_constants has failed for ' + e); + expect(null).assertFail(); + } + }); +});} diff --git a/storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/class_dir/close.test.js b/storage/storagefileiojstest/src/main/js/test/module_fileio/class_dir/close.test.js similarity index 90% rename from storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/class_dir/close.test.js rename to storage/storagefileiojstest/src/main/js/test/module_fileio/class_dir/close.test.js index 9e9c54d950d27a4cad0be40de8dd941c37f4a3e0..0cbdb7ed60b2b6f8d9388dc2e0199e89678062d6 100644 --- a/storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/class_dir/close.test.js +++ b/storage/storagefileiojstest/src/main/js/test/module_fileio/class_dir/close.test.js @@ -1,100 +1,100 @@ -/** - * Copyright (c) 2023 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 { - fileio, - nextFileName, - describe, - it, - expect, -} from '../../Common'; - -export default function fileioDirClose() { -describe('fileio_dir_close', function () { - - /** - * @tc.number SUB_DF_FILEIO_DIR_CLOSE_ASYNC_0000 - * @tc.name fileio_test_dir_close_async_000 - * @tc.desc Test Dir close() interface,return in promise mode. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_dir_close_async_000', 0, async function (done) { - let dpath = await nextFileName('fileio_test_dir_close_async_000') + 'd'; - - try { - fileio.mkdirSync(dpath); - let dd = await fileio.opendir(dpath); - await dd.close(); - fileio.rmdirSync(dpath); - done(); - } catch (e) { - console.info('fileio_test_dir_close_async_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FileIO_Dir_close_Async_0100 - * @tc.name fileio_test_dir_close_async_001 - * @tc.desc Test Dir close() interface,return in callback mode. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_dir_close_async_001', 0, async function (done) { - let dpath = await nextFileName('fileio_test_dir_close_async_001') + 'd'; - - try { - fileio.mkdirSync(dpath); - let dd = await fileio.opendir(dpath); - dd.close(function (err) { - fileio.rmdirSync(dpath); - done(); - }); - } catch (e) { - console.info('fileio_test_dir_close_async_001 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FileIO_Dir_close_Async_0200 - * @tc.name fileio_test_dir_close_async_002 - * @tc.desc Test Dir close() interface,there are multiple parameters. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_dir_close_async_002', 0, async function (done) { - let dpath = await nextFileName('fileio_test_dir_close_async_002') + 'd'; - try { - fileio.mkdirSync(dpath); - let dd = await fileio.opendir(dpath); - dd.close(-1,function (err) { - }); - } catch (e) { - console.info('fileio_test_dir_close_async_002 has failed for ' + e); - expect(e.message == "Number of arguments unmatched").assertTrue(); - fileio.rmdirSync(dpath); - done(); - } - }); -}); -} +/* + * Copyright (C) 2021 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 { + fileio, + nextFileName, + describe, + it, + expect, +} from '../../Common'; + +export default function fileioDirClose() { +describe('fileio_dir_close', function () { + + /** + * @tc.number SUB_DF_FILEIO_DIR_CLOSE_ASYNC_0000 + * @tc.name fileio_test_dir_close_async_000 + * @tc.desc Test Dir close() interface,return in promise mode. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_dir_close_async_000', 0, async function (done) { + let dpath = await nextFileName('fileio_test_dir_close_async_000') + 'd'; + + try { + fileio.mkdirSync(dpath); + let dd = await fileio.opendir(dpath); + await dd.close(); + fileio.rmdirSync(dpath); + done(); + } catch (e) { + console.info('fileio_test_dir_close_async_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_Dir_close_Async_0100 + * @tc.name fileio_test_dir_close_async_001 + * @tc.desc Test Dir close() interface,return in callback mode. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_dir_close_async_001', 0, async function (done) { + let dpath = await nextFileName('fileio_test_dir_close_async_001') + 'd'; + + try { + fileio.mkdirSync(dpath); + let dd = await fileio.opendir(dpath); + dd.close(function (err) { + fileio.rmdirSync(dpath); + done(); + }); + } catch (e) { + console.info('fileio_test_dir_close_async_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_Dir_close_Async_0200 + * @tc.name fileio_test_dir_close_async_002 + * @tc.desc Test Dir close() interface,there are multiple parameters. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_dir_close_async_002', 0, async function (done) { + let dpath = await nextFileName('fileio_test_dir_close_async_002') + 'd'; + try { + fileio.mkdirSync(dpath); + let dd = await fileio.opendir(dpath); + dd.close(-1,function (err) { + }); + } catch (e) { + console.info('fileio_test_dir_close_async_002 has failed for ' + e); + expect(e.message == "Number of arguments unmatched").assertTrue(); + fileio.rmdirSync(dpath); + done(); + } + }); +}); +} diff --git a/storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/class_dir/listfile.test.js b/storage/storagefileiojstest/src/main/js/test/module_fileio/class_dir/listfile.test.js similarity index 97% rename from storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/class_dir/listfile.test.js rename to storage/storagefileiojstest/src/main/js/test/module_fileio/class_dir/listfile.test.js index 978dd65f3c6fbe4e77ca47909effab5c20c4d2e9..93ebed3ba0b605b2d6850f46347212ae183b821f 100644 --- a/storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/class_dir/listfile.test.js +++ b/storage/storagefileiojstest/src/main/js/test/module_fileio/class_dir/listfile.test.js @@ -1,415 +1,415 @@ -/* - * Copyright (C) 2023 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 { - fileio, FILE_CONTENT, prepareFile, nextFileName, randomString, isInclude, - describe, it, expect -} from '../../Common'; -export default function fileioDirListfile() { -describe('fileio_dir_listfile', function () { - - /** - * @tc.number SUB_STORAGE_FileIO_DIR_LISTFILE_SYNC_0000 - * @tc.name fileio_test_dir_listfile_sync_000 - * @tc.desc Test Dir listfileSync() interface. - * List all files and subfolders in the directory directory entry Dirent. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_dir_listfile_sync_000', 0, async function () { - let dpath = await nextFileName('fileio_test_dir_listfile_sync_000') + 'd'; - let fpath = dpath + '/listfile_sync_000'; - let ffpath = dpath + '/listfile_async_000_1'; - let ddpath = dpath + '/listfile_sync_000_1d'; - fileio.mkdirSync(dpath); - fileio.mkdirSync(ddpath); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - expect(prepareFile(ffpath, FILE_CONTENT)).assertTrue(); - - try { - let dir = fileio.opendirSync(dpath); - let dirents = dir.listfileSync(0); - for (let i = 0; i < dirents.length; i++) { - if (dirents[i].isFile()) { - console.info('fileio_test_dir_listfile_sync_000 File: ' + dirents[i].name); - } else if (dirents[i].isDirectory()) { - console.info('fileio_test_dir_listfile_sync_000 Directory: ' + dirents[i].name); - } - } - dir.closeSync(); - fileio.rmdirSync(dpath); - } catch (err) { - console.info('fileio_test_dir_listfile_sync_000 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_DIR_LISTFILE_SYNC_0100 - * @tc.name fileio_test_dir_listfile_sync_001 - * @tc.desc Test Dir listfileSync() interface. - * Loop to obtain the files and subfolders directory items in the directory Dirent. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_dir_listfile_sync_001', 0, async function () { - let dpath = await nextFileName('fileio_test_dir_listfile_sync_001') + 'd'; - fileio.mkdirSync(dpath); - let spath = dpath; - let fdpath = dpath; - - try { - for (let i = 0; i < 113; i++) { - let fpath = dpath + '/f' + randomString(10) + i; - fileio.openSync(fpath, 0o102, 0o777); - dpath = dpath + '/d' + randomString(10) + i; - fileio.mkdirSync(dpath); - } - let dir = fileio.opendirSync(fdpath); - let dirents = dir.listfileSync(0); - while (dirents.length) { - for (let i = 0; i < dirents.length; i++) { - if (dirents[i].isFile()) { - console.info('fileio_test_dir_listfile_sync_001 File: ' + dirents[i].name); - } else if (dirents[i].isDirectory()) { - fdpath = fdpath + '/' + dirents[i].name; - console.info('fileio_test_dir_listfile_sync_001 Directory: ' + dirents[i].name); - } - } - dir = fileio.opendirSync(fdpath); - dirents = dir.listfileSync(0); - } - fileio.rmdirSync(spath); - } catch (err) { - console.info('fileio_test_dir_listfile_sync_001 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_DIR_LISTFILE_SYNC_0200 - * @tc.name fileio_test_dir_listfile_sync_002 - * @tc.desc Test Dir listfileSync() interface. - * List the specified number of files and subfolders in the directory Dirent. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_dir_listfile_sync_002', 0, async function () { - let dpath = await nextFileName('fileio_test_dir_listfile_sync_002') + 'd'; - let fpath = dpath + '/listfile_sync_002'; - let ffpath = dpath + '/listfile_async_002_1'; - let ddpath = dpath + '/listfile_sync_002_1d'; - fileio.mkdirSync(dpath); - fileio.mkdirSync(ddpath); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - expect(prepareFile(ffpath, FILE_CONTENT)).assertTrue(); - - try { - let dir = fileio.opendirSync(dpath); - let dirents = dir.listfileSync(2); - for (let i = 0; i < dirents.length; i++) { - if (dirents[i].isFile()) { - console.info('fileio_test_dir_listfile_sync_002 File: ' + dirents[i].name); - } else if (dirents[i].isDirectory()) { - console.info('fileio_test_dir_listfile_sync_002 Directory: ' + dirents[i].name); - } - } - dir.closeSync(); - fileio.rmdirSync(dpath); - } catch (err) { - console.info('fileio_test_dir_listfile_sync_002 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_DIR_LISTFILE_SYNC_0300 - * @tc.name fileio_test_dir_listfile_sync_003 - * @tc.desc Test Dir listfileSync() interface. - * List all files and subfolders in the directory directory entry Dirent. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_dir_listfile_sync_003', 0, async function () { - let dpath = await nextFileName('fileio_test_dir_listfile_sync_003') + 'd'; - fileio.mkdirSync(dpath); - - try { - let dir = fileio.opendirSync(dpath); - let dirents = dir.listfileSync(0); - expect(dirents.length == 0).assertTrue(); - dir.closeSync(); - fileio.rmdirSync(dpath); - } catch (err) { - console.info('fileio_test_dir_listfile_sync_003 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_DIR_LISTFILE_SYNC_0400 - * @tc.name fileio_test_dir_listfile_sync_004 - * @tc.desc Test Dir listfileSync() interface. Invalid listNum. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_dir_listfile_sync_004', 0, async function () { - let dpath = await nextFileName('fileio_test_dir_listfile_sync_004') + 'd'; - fileio.mkdirSync(dpath); - - try { - let dir = fileio.opendirSync(dpath); - dir.listfileSync(dpath); - } catch (err) { - console.info('fileio_test_dir_listfile_sync_004 has failed for ' + err); - expect(isInclude(err.message, 'Invalid listNum')).assertTrue(); - fileio.rmdirSync(dpath); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_DIR_LISTFILE_SYNC_0400 - * @tc.name fileio_test_dir_listfile_sync_004 - * @tc.desc Test Dir listfileSync() interface. No parameters. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_dir_listfile_sync_005', 0, async function () { - let dpath = await nextFileName('fileio_test_dir_listfile_sync_005') + 'd'; - fileio.mkdirSync(dpath); - - try { - let dir = fileio.opendirSync(dpath); - dir.listfileSync(); - } catch (err) { - console.info('fileio_test_dir_listfile_sync_005 has failed for ' + err); - expect(isInclude(err.message, 'Number of arguments unmatched')).assertTrue(); - fileio.rmdirSync(dpath); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_DIR_LISTFILE_ASYNC_0000 - * @tc.name fileio_test_dir_listfile_async_000 - * @tc.desc Test Dir listfile() interface. return in callback mode. - * List all files and subfolders in the directory directory entry Dirent. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_dir_listfile_async_000', 0, async function (done) { - let dpath = await nextFileName('fileio_test_dir_listfile_async_000') + 'd'; - let fpath = dpath + '/listfile_async_000'; - let ffpath = dpath + '/listfile_async_000_1'; - let ddpath = dpath + '/listfile_async_000_1d'; - fileio.mkdirSync(dpath); - fileio.mkdirSync(ddpath); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - expect(prepareFile(ffpath, FILE_CONTENT)).assertTrue(); - - try { - let dir = fileio.opendirSync(dpath); - dir.listfile(0, function (err, dirents) { - for (let i = 0; i < dirents.length; i++) { - if (dirents[i].isFile()) { - console.info('fileio_test_dir_listfile_async_000 File: ' + dirents[i].name); - } else if (dirents[i].isDirectory()) { - console.info('fileio_test_dir_listfile_async_000 Directory: ' + dirents[i].name); - } - } - dir.closeSync(); - fileio.rmdirSync(dpath); - done(); - }); - } catch (err) { - console.info('fileio_test_dir_listfile_async_000 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_DIR_LISTFILE_ASYNC_0100 - * @tc.name fileio_test_dir_listfile_async_001 - * @tc.desc Test Dir listfile() interface. return in promise mode. - * Loop to obtain the files and subfolders directory items in the directory Dirent. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_dir_listfile_async_001', 0, async function (done) { - let dpath = await nextFileName('fileio_test_dir_listfile_async_001') + 'd'; - fileio.mkdirSync(dpath); - let spath = dpath; - let fdpath = dpath; - - try { - for (let i = 0; i < 113; i++) { - let fpath = dpath + '/f' + randomString(10) + i; - fileio.openSync(fpath, 0o102, 0o777); - dpath = dpath + '/d' + randomString(10) + i; - fileio.mkdirSync(dpath); - } - let dir = fileio.opendirSync(fdpath); - let dirents = await dir.listfile(0); - while (dirents.length) { - for (let i = 0; i < dirents.length; i++) { - if (dirents[i].isFile()) { - console.info('fileio_test_dir_listfile_async_001 File: ' + dirents[i].name); - } else if (dirents[i].isDirectory()) { - fdpath = fdpath + '/' + dirents[i].name; - console.info('fileio_test_dir_listfile_async_001 Directory: ' + dirents[i].name); - } - } - dir = fileio.opendirSync(fdpath); - dirents = await dir.listfile(0); - } - fileio.rmdirSync(spath); - done(); - } catch (err) { - console.info('fileio_test_dir_listfile_async_001 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_DIR_LISTFILE_ASYNC_0200 - * @tc.name fileio_test_dir_listfile_async_002 - * @tc.desc Test Dir listfile() interface. return in promise mode. - * List the specified number of files and subfolders in the directory Dirent. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_dir_listfile_async_002', 0, async function (done) { - let dpath = await nextFileName('fileio_test_dir_listfile_async_002') + 'd'; - let fpath = dpath + '/listfile_async_002'; - let ffpath = dpath + '/listfile_async_002_1'; - let ddpath = dpath + '/listfile_async_002_1d'; - fileio.mkdirSync(dpath); - fileio.mkdirSync(ddpath); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - expect(prepareFile(ffpath, FILE_CONTENT)).assertTrue(); - - try { - let dir = fileio.opendirSync(dpath); - let dirents = await dir.listfile(2); - for (let i = 0; i < dirents.length; i++) { - if (dirents[i].isFile()) { - console.info('fileio_test_dir_listfile_async_002 File: ' + dirents[i].name); - } else if (dirents[i].isDirectory()) { - console.info('fileio_test_dir_listfile_async_002 Directory: ' + dirents[i].name); - } - } - dir.closeSync(); - fileio.rmdirSync(dpath); - done(); - } catch (err) { - console.info('fileio_test_dir_listfile_async_002 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_DIR_LISTFILE_ASYNC_0300 - * @tc.name fileio_test_dir_listfile_async_003 - * @tc.desc Test Dir listfile() interface. return in promise mode. - * List all files and subfolders in the directory directory entry Dirent. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_dir_listfile_async_003', 0, async function (done) { - let dpath = await nextFileName('fileio_test_dir_listfile_async_003') + 'd'; - fileio.mkdirSync(dpath); - - try { - let dir = fileio.opendirSync(dpath); - let dirents = await dir.listfile(0); - expect(dirents.length == 0).assertTrue(); - dir.closeSync(); - fileio.rmdirSync(dpath); - done(); - } catch (err) { - console.info('fileio_test_dir_listfile_async_003 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_DIR_LISTFILE_ASYNC_0400 - * @tc.name fileio_test_dir_listfile_async_004 - * @tc.desc Test Dir listfile() interface. Invalid listNum. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_dir_listfile_async_004', 0, async function (done) { - let dpath = await nextFileName('fileio_test_dir_listfile_async_004') + 'd'; - fileio.mkdirSync(dpath); - - try { - let dir = fileio.opendirSync(dpath); - dir.listfile(dpath, function (err, dirents) { - }); - } catch (err) { - console.info('fileio_test_dir_listfile_async_004 has failed for ' + err); - expect(isInclude(err.message, 'Invalid listNum')).assertTrue(); - fileio.rmdirSync(dpath); - done(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_DIR_LISTFILE_ASYNC_0500 - * @tc.name fileio_test_dir_listfile_async_005 - * @tc.desc Test Dir listfile() interface. No parameters. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_dir_listfile_async_005', 0, async function (done) { - let dpath = await nextFileName('fileio_test_dir_listfile_async_005') + 'd'; - fileio.mkdirSync(dpath); - - try { - let dir = fileio.opendirSync(dpath); - await dir.listfile(); - } catch (err) { - console.info('fileio_test_dir_listfile_async_005 has failed for ' + err); - expect(isInclude(err.message, 'Number of arguments unmatched')).assertTrue(); - fileio.rmdirSync(dpath); - done(); - } - }); -}) +/* + * Copyright (C) 2021 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 { + fileio, FILE_CONTENT, prepareFile, nextFileName, randomString, isInclude, + describe, it, expect +} from '../../Common'; +export default function fileioDirListfile() { +describe('fileio_dir_listfile', function () { + + /** + * @tc.number SUB_STORAGE_FileIO_DIR_LISTFILE_SYNC_0000 + * @tc.name fileio_test_dir_listfile_sync_000 + * @tc.desc Test Dir listfileSync() interface. + * List all files and subfolders in the directory directory entry Dirent. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_dir_listfile_sync_000', 0, async function () { + let dpath = await nextFileName('fileio_test_dir_listfile_sync_000') + 'd'; + let fpath = dpath + '/listfile_sync_000'; + let ffpath = dpath + '/listfile_async_000_1'; + let ddpath = dpath + '/listfile_sync_000_1d'; + fileio.mkdirSync(dpath); + fileio.mkdirSync(ddpath); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + expect(prepareFile(ffpath, FILE_CONTENT)).assertTrue(); + + try { + let dir = fileio.opendirSync(dpath); + let dirents = dir.listfileSync(0); + for (let i = 0; i < dirents.length; i++) { + if (dirents[i].isFile()) { + console.info('fileio_test_dir_listfile_sync_000 File: ' + dirents[i].name); + } else if (dirents[i].isDirectory()) { + console.info('fileio_test_dir_listfile_sync_000 Directory: ' + dirents[i].name); + } + } + dir.closeSync(); + fileio.rmdirSync(dpath); + } catch (err) { + console.info('fileio_test_dir_listfile_sync_000 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_DIR_LISTFILE_SYNC_0100 + * @tc.name fileio_test_dir_listfile_sync_001 + * @tc.desc Test Dir listfileSync() interface. + * Loop to obtain the files and subfolders directory items in the directory Dirent. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_dir_listfile_sync_001', 0, async function () { + let dpath = await nextFileName('fileio_test_dir_listfile_sync_001') + 'd'; + fileio.mkdirSync(dpath); + let spath = dpath; + let fdpath = dpath; + + try { + for (let i = 0; i < 113; i++) { + let fpath = dpath + '/f' + randomString(10) + i; + fileio.openSync(fpath, 0o102, 0o777); + dpath = dpath + '/d' + randomString(10) + i; + fileio.mkdirSync(dpath); + } + let dir = fileio.opendirSync(fdpath); + let dirents = dir.listfileSync(0); + while (dirents.length) { + for (let i = 0; i < dirents.length; i++) { + if (dirents[i].isFile()) { + console.info('fileio_test_dir_listfile_sync_001 File: ' + dirents[i].name); + } else if (dirents[i].isDirectory()) { + fdpath = fdpath + '/' + dirents[i].name; + console.info('fileio_test_dir_listfile_sync_001 Directory: ' + dirents[i].name); + } + } + dir = fileio.opendirSync(fdpath); + dirents = dir.listfileSync(0); + } + fileio.rmdirSync(spath); + } catch (err) { + console.info('fileio_test_dir_listfile_sync_001 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_DIR_LISTFILE_SYNC_0200 + * @tc.name fileio_test_dir_listfile_sync_002 + * @tc.desc Test Dir listfileSync() interface. + * List the specified number of files and subfolders in the directory Dirent. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_dir_listfile_sync_002', 0, async function () { + let dpath = await nextFileName('fileio_test_dir_listfile_sync_002') + 'd'; + let fpath = dpath + '/listfile_sync_002'; + let ffpath = dpath + '/listfile_async_002_1'; + let ddpath = dpath + '/listfile_sync_002_1d'; + fileio.mkdirSync(dpath); + fileio.mkdirSync(ddpath); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + expect(prepareFile(ffpath, FILE_CONTENT)).assertTrue(); + + try { + let dir = fileio.opendirSync(dpath); + let dirents = dir.listfileSync(2); + for (let i = 0; i < dirents.length; i++) { + if (dirents[i].isFile()) { + console.info('fileio_test_dir_listfile_sync_002 File: ' + dirents[i].name); + } else if (dirents[i].isDirectory()) { + console.info('fileio_test_dir_listfile_sync_002 Directory: ' + dirents[i].name); + } + } + dir.closeSync(); + fileio.rmdirSync(dpath); + } catch (err) { + console.info('fileio_test_dir_listfile_sync_002 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_DIR_LISTFILE_SYNC_0300 + * @tc.name fileio_test_dir_listfile_sync_003 + * @tc.desc Test Dir listfileSync() interface. + * List all files and subfolders in the directory directory entry Dirent. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_dir_listfile_sync_003', 0, async function () { + let dpath = await nextFileName('fileio_test_dir_listfile_sync_003') + 'd'; + fileio.mkdirSync(dpath); + + try { + let dir = fileio.opendirSync(dpath); + let dirents = dir.listfileSync(0); + expect(dirents.length == 0).assertTrue(); + dir.closeSync(); + fileio.rmdirSync(dpath); + } catch (err) { + console.info('fileio_test_dir_listfile_sync_003 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_DIR_LISTFILE_SYNC_0400 + * @tc.name fileio_test_dir_listfile_sync_004 + * @tc.desc Test Dir listfileSync() interface. Invalid listNum. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_dir_listfile_sync_004', 0, async function () { + let dpath = await nextFileName('fileio_test_dir_listfile_sync_004') + 'd'; + fileio.mkdirSync(dpath); + + try { + let dir = fileio.opendirSync(dpath); + dir.listfileSync(dpath); + } catch (err) { + console.info('fileio_test_dir_listfile_sync_004 has failed for ' + err); + expect(isInclude(err.message, 'Invalid listNum')).assertTrue(); + fileio.rmdirSync(dpath); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_DIR_LISTFILE_SYNC_0400 + * @tc.name fileio_test_dir_listfile_sync_004 + * @tc.desc Test Dir listfileSync() interface. No parameters. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_dir_listfile_sync_005', 0, async function () { + let dpath = await nextFileName('fileio_test_dir_listfile_sync_005') + 'd'; + fileio.mkdirSync(dpath); + + try { + let dir = fileio.opendirSync(dpath); + dir.listfileSync(); + } catch (err) { + console.info('fileio_test_dir_listfile_sync_005 has failed for ' + err); + expect(isInclude(err.message, 'Number of arguments unmatched')).assertTrue(); + fileio.rmdirSync(dpath); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_DIR_LISTFILE_ASYNC_0000 + * @tc.name fileio_test_dir_listfile_async_000 + * @tc.desc Test Dir listfile() interface. return in callback mode. + * List all files and subfolders in the directory directory entry Dirent. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_dir_listfile_async_000', 0, async function (done) { + let dpath = await nextFileName('fileio_test_dir_listfile_async_000') + 'd'; + let fpath = dpath + '/listfile_async_000'; + let ffpath = dpath + '/listfile_async_000_1'; + let ddpath = dpath + '/listfile_async_000_1d'; + fileio.mkdirSync(dpath); + fileio.mkdirSync(ddpath); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + expect(prepareFile(ffpath, FILE_CONTENT)).assertTrue(); + + try { + let dir = fileio.opendirSync(dpath); + dir.listfile(0, function (err, dirents) { + for (let i = 0; i < dirents.length; i++) { + if (dirents[i].isFile()) { + console.info('fileio_test_dir_listfile_async_000 File: ' + dirents[i].name); + } else if (dirents[i].isDirectory()) { + console.info('fileio_test_dir_listfile_async_000 Directory: ' + dirents[i].name); + } + } + dir.closeSync(); + fileio.rmdirSync(dpath); + done(); + }); + } catch (err) { + console.info('fileio_test_dir_listfile_async_000 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_DIR_LISTFILE_ASYNC_0100 + * @tc.name fileio_test_dir_listfile_async_001 + * @tc.desc Test Dir listfile() interface. return in promise mode. + * Loop to obtain the files and subfolders directory items in the directory Dirent. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_dir_listfile_async_001', 0, async function (done) { + let dpath = await nextFileName('fileio_test_dir_listfile_async_001') + 'd'; + fileio.mkdirSync(dpath); + let spath = dpath; + let fdpath = dpath; + + try { + for (let i = 0; i < 113; i++) { + let fpath = dpath + '/f' + randomString(10) + i; + fileio.openSync(fpath, 0o102, 0o777); + dpath = dpath + '/d' + randomString(10) + i; + fileio.mkdirSync(dpath); + } + let dir = fileio.opendirSync(fdpath); + let dirents = await dir.listfile(0); + while (dirents.length) { + for (let i = 0; i < dirents.length; i++) { + if (dirents[i].isFile()) { + console.info('fileio_test_dir_listfile_async_001 File: ' + dirents[i].name); + } else if (dirents[i].isDirectory()) { + fdpath = fdpath + '/' + dirents[i].name; + console.info('fileio_test_dir_listfile_async_001 Directory: ' + dirents[i].name); + } + } + dir = fileio.opendirSync(fdpath); + dirents = await dir.listfile(0); + } + fileio.rmdirSync(spath); + done(); + } catch (err) { + console.info('fileio_test_dir_listfile_async_001 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_DIR_LISTFILE_ASYNC_0200 + * @tc.name fileio_test_dir_listfile_async_002 + * @tc.desc Test Dir listfile() interface. return in promise mode. + * List the specified number of files and subfolders in the directory Dirent. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_dir_listfile_async_002', 0, async function (done) { + let dpath = await nextFileName('fileio_test_dir_listfile_async_002') + 'd'; + let fpath = dpath + '/listfile_async_002'; + let ffpath = dpath + '/listfile_async_002_1'; + let ddpath = dpath + '/listfile_async_002_1d'; + fileio.mkdirSync(dpath); + fileio.mkdirSync(ddpath); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + expect(prepareFile(ffpath, FILE_CONTENT)).assertTrue(); + + try { + let dir = fileio.opendirSync(dpath); + let dirents = await dir.listfile(2); + for (let i = 0; i < dirents.length; i++) { + if (dirents[i].isFile()) { + console.info('fileio_test_dir_listfile_async_002 File: ' + dirents[i].name); + } else if (dirents[i].isDirectory()) { + console.info('fileio_test_dir_listfile_async_002 Directory: ' + dirents[i].name); + } + } + dir.closeSync(); + fileio.rmdirSync(dpath); + done(); + } catch (err) { + console.info('fileio_test_dir_listfile_async_002 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_DIR_LISTFILE_ASYNC_0300 + * @tc.name fileio_test_dir_listfile_async_003 + * @tc.desc Test Dir listfile() interface. return in promise mode. + * List all files and subfolders in the directory directory entry Dirent. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_dir_listfile_async_003', 0, async function (done) { + let dpath = await nextFileName('fileio_test_dir_listfile_async_003') + 'd'; + fileio.mkdirSync(dpath); + + try { + let dir = fileio.opendirSync(dpath); + let dirents = await dir.listfile(0); + expect(dirents.length == 0).assertTrue(); + dir.closeSync(); + fileio.rmdirSync(dpath); + done(); + } catch (err) { + console.info('fileio_test_dir_listfile_async_003 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_DIR_LISTFILE_ASYNC_0400 + * @tc.name fileio_test_dir_listfile_async_004 + * @tc.desc Test Dir listfile() interface. Invalid listNum. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_dir_listfile_async_004', 0, async function (done) { + let dpath = await nextFileName('fileio_test_dir_listfile_async_004') + 'd'; + fileio.mkdirSync(dpath); + + try { + let dir = fileio.opendirSync(dpath); + dir.listfile(dpath, function (err, dirents) { + }); + } catch (err) { + console.info('fileio_test_dir_listfile_async_004 has failed for ' + err); + expect(isInclude(err.message, 'Invalid listNum')).assertTrue(); + fileio.rmdirSync(dpath); + done(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_DIR_LISTFILE_ASYNC_0500 + * @tc.name fileio_test_dir_listfile_async_005 + * @tc.desc Test Dir listfile() interface. No parameters. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_dir_listfile_async_005', 0, async function (done) { + let dpath = await nextFileName('fileio_test_dir_listfile_async_005') + 'd'; + fileio.mkdirSync(dpath); + + try { + let dir = fileio.opendirSync(dpath); + await dir.listfile(); + } catch (err) { + console.info('fileio_test_dir_listfile_async_005 has failed for ' + err); + expect(isInclude(err.message, 'Number of arguments unmatched')).assertTrue(); + fileio.rmdirSync(dpath); + done(); + } + }); +}) } \ No newline at end of file diff --git a/storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/class_dir/read.test.js b/storage/storagefileiojstest/src/main/js/test/module_fileio/class_dir/read.test.js similarity index 96% rename from storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/class_dir/read.test.js rename to storage/storagefileiojstest/src/main/js/test/module_fileio/class_dir/read.test.js index cb155ef3056d3ecab0f431d02b4d731d64d4a633..eb845099dd124a51e44c2e9eb596af840183f907 100644 --- a/storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/class_dir/read.test.js +++ b/storage/storagefileiojstest/src/main/js/test/module_fileio/class_dir/read.test.js @@ -1,681 +1,681 @@ -/* - * Copyright (C) 2023 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 { - fileio, FILE_CONTENT, prepareFile, nextFileName, isString, isBoolean, forceRemoveDir, - describe, it, expect, -} from '../../Common'; - -export default function fileioDirRead() { -describe('fileio_dir_read', function () { - - /** - * @tc.number SUB_DF_FILEIO_DIR_READ_ASYNC_0000 - * @tc.name fileio_test_dir_read_async_000 - * @tc.desc Test Dir read() interface,return in promise mode. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_dir_read_async_000', 0, async function (done) { - let dpath = await nextFileName('fileio_test_dir_read_async_000') + 'd'; - let fpath = dpath + '/f1'; - - try { - fileio.mkdirSync(dpath); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - let dd = fileio.opendirSync(dpath); - let dir = await dd.read(); - dd.closeSync(); - fileio.unlinkSync(fpath); - fileio.rmdirSync(dpath); - done(); - } - catch (e) { - console.info('fileio_test_dir_read_async_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_DIR_READ_ASYNC_0100 - * @tc.name fileio_test_dir_read_async_001 - * @tc.desc Test Dir read() interface,return in callback mode. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_dir_read_async_001', 0, async function (done) { - let dpath = await nextFileName('fileio_test_dir_read_async_001') + 'd'; - let fpath = dpath + '/f1'; - - try { - fileio.mkdirSync(dpath); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - let dd = fileio.opendirSync(dpath); - dd.read(function (err, dirent) { - dd.closeSync(); - fileio.unlinkSync(fpath); - fileio.rmdirSync(dpath); - done(); - }); - } catch (e) { - console.info('fileio_test_dir_read_async_001 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_DIR_READ_ASYNC_0200 - * @tc.name fileio_test_dir_read_async_002 - * @tc.desc Test Dir read() interface,there are multiple parameters. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_dir_read_async_002', 0, async function (done) { - let dpath = await nextFileName('fileio_test_dir_read_async_002') + 'd'; - let fpath = dpath + '/f1'; - let dd = null - try { - fileio.mkdirSync(dpath); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - dd = fileio.opendirSync(dpath); - dd.read(-1,function (err, dirent) { - - }); - } catch (e) { - console.info('fileio_test_dir_read_async_002 has failed for ' + e); - expect(e.message == "Number of arguments unmatched").assertTrue(); - dd.closeSync(); - fileio.unlinkSync(fpath); - fileio.rmdirSync(dpath); - done(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_DIR_READ_SYNC_0000 - * @tc.name fileio_dir_read_sync_000 - * @tc.desc Test Dir readSync() interface. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_dir_read_sync_000', 0, async function () { - let dpath = await nextFileName('fileio_dir_read_sync_000') + 'd'; - let fpath = dpath + '/f1'; - - try { - fileio.mkdirSync(dpath); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - let dd = fileio.opendirSync(dpath); - dd.readSync(); - dd.closeSync(); - fileio.unlinkSync(fpath); - fileio.rmdirSync(dpath); - } catch (e) { - console.info('fileio_dir_read_sync_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_DIR_READ_SYNC_0100 - * @tc.name fileio_dir_read_sync_001 - * @tc.desc Test Dir.readSync() interface,there are multiple parameters. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_dir_read_sync_001', 0, async function () { - let dpath = await nextFileName('fileio_dir_read_sync_001') + 'd'; - let fpath = dpath + '/f1'; - let dd = null; - try { - fileio.mkdirSync(dpath); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - dd = fileio.opendirSync(dpath); - dd.readSync(-1); - } catch (e) { - console.info('fileio_dir_read_sync_001 has failed for ' + e); - expect(e.message == "Number of arguments unmatched").assertTrue(); - dd.closeSync(); - fileio.unlinkSync(fpath); - fileio.rmdirSync(dpath); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_DIR_READ_SYNC_NAME_0000 - * @tc.name fileio_dir_read_sync_name_000 - * @tc.desc Test Dir.readSync() interface. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_dir_read_sync_name_000', 0, async function (done) { - let dpath = await nextFileName('fileio_dir_read_sync_name_000') + 'd'; - let fpath = dpath + '/f1'; - try { - fileio.mkdirSync(dpath); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - let dd = await fileio.opendir(dpath); - let dir = dd.readSync(); - expect(isString(dir.name)).assertTrue(); - expect(fpath.indexOf(dir.name) > -1).assertTrue(); - fileio.unlinkSync(fpath); - fileio.rmdirSync(dpath); - done(); - } catch (e) { - console.info('fileio_dir_read_sync_name_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_DIR_READ_SYNC_NAME_0100 - * @tc.name fileio_dir_read_sync_name_001 - * @tc.desc Test Dir.readSync() interface. Synchronous loop reads next directory entry. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_dir_read_sync_name_001', 0, async function () { - let dpath = await nextFileName('fileio_dir_read_sync_name_001') + 'd'; - fileio.mkdirSync(dpath); - let fdpath = dpath; - - try { - for (let i = 0; i < 10; i++) { - console.info('time' + i); - dpath = dpath + '/d' + i; - fileio.mkdirSync(dpath); - } - let dir = fileio.opendirSync(fdpath); - let dirent = dir.readSync(); - while (dirent) { - fdpath = fdpath + '/' + dirent.name; - dir = fileio.opendirSync(fdpath); - dirent = dir.readSync(); - } - forceRemoveDir(dpath, 10); - } catch (e) { - console.info('fileio_dir_read_sync_name_001 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_DIR_READ_SYNC_ISBLOCKDEVICE_0000 - * @tc.name fileio_dir_read_sync_isBlockDevice_000 - * @tc.desc Test Dir.readSync() interface. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_dir_read_sync_isBlockDevice_000', 0, async function (done) { - let dpath = await nextFileName('fileio_dir_read_sync_isBlockDevice_000') + 'd'; - let fpath = dpath + '/f1'; - try { - fileio.mkdirSync(dpath); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - let dd = await fileio.opendir(dpath); - let dir = dd.readSync(); - expect(isBoolean(dir.isBlockDevice())).assertTrue(); - expect(dir.isBlockDevice() === false).assertTrue(); - fileio.unlinkSync(fpath); - fileio.rmdirSync(dpath); - done(); - } catch (e) { - console.info('fileio_dir_read_sync_isBlockDevice_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_DIR_READ_SYNC_ISCHARACTERDEVICE_0000 - * @tc.name fileio_dir_read_sync_isCharacterDevice_000 - * @tc.desc Test Dir.readSync() interface. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_dir_read_sync_isCharacterDevice_000', 0, async function (done) { - let dpath = await nextFileName('fileio_dir_read_sync_isCharacterDevice_000') + 'd'; - let fpath = dpath + '/f1'; - try { - fileio.mkdirSync(dpath); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - let dd = await fileio.opendir(dpath); - let dir = dd.readSync(); - expect(isBoolean(dir.isCharacterDevice())).assertTrue(); - expect(dir.isCharacterDevice() === false).assertTrue(); - fileio.unlinkSync(fpath); - fileio.rmdirSync(dpath); - done(); - } catch (e) { - console.info('fileio_dir_read_sync_isCharacterDevice_000 has failed for ' + e); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_DIR_READ_SYNC_ISDIRECTORY_0000 - * @tc.name fileio_dir_read_sync_isDirectory_000 - * @tc.desc Test Dir.readSync() interface. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_dir_read_sync_isDirectory_000', 0, async function (done) { - let dpath = await nextFileName('fileio_dir_read_sync_isDirectory_000') + 'd'; - let fpath = dpath + '/f1'; - try { - fileio.mkdirSync(dpath); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - let dd = await fileio.opendir(dpath); - let dir = dd.readSync(); - expect(isBoolean(dir.isDirectory())).assertTrue(); - expect(dir.isDirectory() === false).assertTrue(); - fileio.unlinkSync(fpath); - fileio.rmdirSync(dpath); - done(); - } catch (e) { - console.info('fileio_dir_read_sync_isDirectory_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_DIR_READ_SYNC_ISFIFO_0000 - * @tc.name fileio_dir_read_sync_isFIFO_000 - * @tc.desc Test Dir.readSync() interface. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_dir_read_sync_isFIFO_000', 0, async function (done) { - let dpath = await nextFileName('fileio_dir_read_sync_isFIFO_000') + 'd'; - let fpath = dpath + '/f1'; - try { - fileio.mkdirSync(dpath); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - let dd = await fileio.opendir(dpath); - let dir = dd.readSync(); - expect(isBoolean(dir.isFIFO())).assertTrue(); - expect(dir.isFIFO() === false).assertTrue(); - fileio.unlinkSync(fpath); - fileio.rmdirSync(dpath); - done(); - } catch (e) { - console.info('fileio_dir_read_sync_isFIFO_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_DIR_READ_SYNC_ISFILE_0000 - * @tc.name fileio_dir_read_sync_isFile_000 - * @tc.desc Test Dir.readSync() interface. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_dir_read_sync_isFile_000', 0, async function (done) { - let dpath = await nextFileName('fileio_dir_read_sync_isFile_000') + 'd'; - let fpath = dpath + '/f1'; - try { - fileio.mkdirSync(dpath); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - let dd = await fileio.opendir(dpath); - let dir = dd.readSync(); - expect(isBoolean(dir.isFile())).assertTrue(); - expect(dir.isFile()).assertTrue(); - fileio.unlinkSync(fpath); - fileio.rmdirSync(dpath); - done(); - } catch (e) { - console.info('fileio_dir_read_sync_isFile_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_DIR_READ_SYNC_ISCOCKET_0000 - * @tc.name fileio_dir_read_sync_isSocket_000 - * @tc.desc Test Dir.readSync() interface. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_dir_read_sync_isSocket_000', 0, async function (done) { - let dpath = await nextFileName('fileio_dir_read_sync_isSocket_000') + 'd'; - let fpath = dpath + '/f1'; - try { - fileio.mkdirSync(dpath); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - let dd = await fileio.opendir(dpath); - let dir = dd.readSync(); - expect(isBoolean(dir.isSocket())).assertTrue(); - expect(dir.isSocket() === false).assertTrue(); - fileio.unlinkSync(fpath); - fileio.rmdirSync(dpath); - done(); - } catch (e) { - console.info('fileio_dir_read_sync_isSocket_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_DIR_READ_SYNC_ISSYMBOLICLINK_0000 - * @tc.name fileio_dir_read_sync_isSymbolicLink_000 - * @tc.desc Test Dir.readSync() interface. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_dir_read_sync_isSymbolicLink_000', 0, async function (done) { - let dpath = await nextFileName('fileio_dir_read_sync_isSymbolicLink_000') + 'd'; - let fpath = dpath + '/f1'; - try { - fileio.mkdirSync(dpath); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - let dd = await fileio.opendir(dpath); - let dir = dd.readSync(); - expect(isBoolean(dir.isSymbolicLink())).assertTrue(); - expect(dir.isSymbolicLink() === false).assertTrue(); - fileio.unlinkSync(fpath); - fileio.rmdirSync(dpath); - done(); - } catch (e) { - console.info('fileio_dir_read_sync_isSymbolicLink_000 has failed for ' + e); - expect(null); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_DIR_READ_ASYNC_NAME_0000 - * @tc.name fileio_dir_read_async_name_000 - * @tc.desc Test Dir.readAsync() interface. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_dir_read_async_name_000', 0, async function (done) { - let dpath = await nextFileName('fileio_dir_read_async_name_000') + 'd'; - let fpath = dpath + '/f1'; - try { - fileio.mkdirSync(dpath); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - let dd = await fileio.opendir(dpath); - let dir = await dd.read(); - expect(isString(dir.name)).assertTrue(); - expect(fpath.indexOf(dir.name) > -1).assertTrue(); - fileio.unlinkSync(fpath); - fileio.rmdirSync(dpath); - done(); - } catch (e) { - console.info('fileio_dir_read_async_name_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_DIR_READ_ASYNC_NAME_0100 - * @tc.name fileio_dir_read_async_name_001 - * @tc.desc Test Dir.readAsync() interface. Asynchronously loop to read next directory item. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_dir_read_async_name_001', 0, async function (done) { - let dpath = await nextFileName('fileio_dir_read_async_name_001') + 'd'; - fileio.mkdirSync(dpath); - let fdpath = dpath; - - try { - for (let i = 0; i < 10; i++) { - console.info('time' + i); - dpath = dpath + '/d' + i; - fileio.mkdirSync(dpath); - } - let dir = fileio.opendirSync(fdpath); - let dirent = await dir.read(); - while (dirent) { - fdpath = fdpath + '/' + dirent.name; - dir = fileio.opendirSync(fdpath); - dirent = await dir.read(); - } - forceRemoveDir(dpath, 10); - done(); - } catch (e) { - console.info('fileio_dir_read_async_name_001 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_DIR_READ_ASYNC_ISBLOCKDEVICE_0000 - * @tc.name fileio_dir_read_async_isBlockDevice_000 - * @tc.desc Test Dir.readAsync() interface. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_dir_read_async_isBlockDevice_000', 0, async function (done) { - let dpath = await nextFileName('fileio_dir_read_async_isBlockDevice_000') + 'd'; - let fpath = dpath + '/f1'; - try { - fileio.mkdirSync(dpath); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - let dd = await fileio.opendir(dpath); - let dir = await dd.read(); - expect(isBoolean(dir.isBlockDevice())).assertTrue(); - expect(dir.isBlockDevice() === false).assertTrue(); - fileio.unlinkSync(fpath); - fileio.rmdirSync(dpath); - done(); - } catch (e) { - console.info('fileio_dir_read_async_isBlockDevice_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_DIR_READ_ASYNC_ISCHARACTERDEVICE_0000 - * @tc.name fileio_dir_read_async_isCharacterDevice_000 - * @tc.desc Test Dir.readAsync() interface. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - - it('fileio_dir_read_async_isCharacterDevice_000', 0, async function (done) { - let dpath = await nextFileName('fileio_dir_read_async_isCharacterDevice_000') + 'd'; - let fpath = dpath + '/f1'; - try { - fileio.mkdirSync(dpath); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - let dd = await fileio.opendir(dpath); - let dir = await dd.read(); - expect(isBoolean(dir.isCharacterDevice())).assertTrue(); - expect(dir.isCharacterDevice() === false).assertTrue(); - fileio.unlinkSync(fpath); - fileio.rmdirSync(dpath); - done(); - } catch (e) { - console.info('fileio_dir_read_async_isCharacterDevice_000 has failed for ' + e); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_DIR_READ_ASYNC_ISDIRECTORY_0000 - * @tc.name fileio_dir_read_async_isDirectory_000 - * @tc.desc Test Dir.readAsync() interface. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_dir_read_async_isDirectory_000', 0, async function (done) { - let dpath = await nextFileName('fileio_dir_read_async_isDirectory_000') + 'd'; - let fpath = dpath + '/f1'; - try { - fileio.mkdirSync(dpath); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - let dd = await fileio.opendir(dpath); - let dir = await dd.read(); - expect(isBoolean(dir.isDirectory())).assertTrue(); - expect(dir.isDirectory() === false).assertTrue(); - fileio.unlinkSync(fpath); - fileio.rmdirSync(dpath); - done(); - } catch (e) { - console.info('fileio_dir_read_async_isDirectory_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_DIR_READ_ASYNC_ISFIFO_0000 - * @tc.name fileio_dir_read_async_isFIFO_000 - * @tc.desc Test Dir.readAsync() interface. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_dir_read_async_isFIFO_000', 0, async function (done) { - let dpath = await nextFileName('fileio_dir_read_async_isFIFO_000') + 'd'; - let fpath = dpath + '/f1'; - try { - fileio.mkdirSync(dpath); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - let dd = await fileio.opendir(dpath); - let dir = await dd.read(); - expect(isBoolean(dir.isFIFO())).assertTrue(); - expect(dir.isFIFO() === false).assertTrue(); - fileio.unlinkSync(fpath); - fileio.rmdirSync(dpath); - done(); - } catch (e) { - console.info('fileio_dir_read_async_isFIFO_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_DIR_READ_ASYNC_ISFILE_0000 - * @tc.name fileio_dir_read_async_isFile_000 - * @tc.desc Test Dir.readAsync() interface. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_dir_read_async_isFile_000', 0, async function (done) { - let dpath = await nextFileName('fileio_dir_read_async_isFile_000') + 'd'; - let fpath = dpath + '/f1'; - try { - fileio.mkdirSync(dpath); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - let dd = await fileio.opendir(dpath); - let dir = await dd.read(); - expect(isBoolean(dir.isFile())).assertTrue(); - expect(dir.isFile()).assertTrue(); - fileio.unlinkSync(fpath); - fileio.rmdirSync(dpath); - done(); - } catch (e) { - console.info('fileio_dir_read_async_isFile_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_DIR_READ_ASYNC_ISSOCKET_0000 - * @tc.name fileio_dir_read_async_isSocket_000 - * @tc.desc Test Dir.readAsync() interface. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_dir_read_async_isSocket_000', 0, async function (done) { - let dpath = await nextFileName('fileio_dir_read_async_isSocket_000') + 'd'; - let fpath = dpath + '/f1'; - try { - fileio.mkdirSync(dpath); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - let dd = await fileio.opendir(dpath);; - let dir = await dd.read();; - expect(isBoolean(dir.isSocket())).assertTrue(); - expect(dir.isSocket() === false).assertTrue(); - fileio.unlinkSync(fpath); - fileio.rmdirSync(dpath); - done(); - } catch (e) { - console.info('fileio_dir_read_async_isSocket_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_DIR_READ_ASYNC_ISSYMBOLICLINK_0000 - * @tc.name fileio_dir_read_async_isSymbolicLink_000 - * @tc.desc Test Dir.readAsync() interface. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_dir_read_async_isSymbolicLink_000', 0, async function (done) { - let dpath = await nextFileName('fileio_dir_read_async_isSymbolicLink_000') + 'd'; - let fpath = dpath + '/f1'; - try { - fileio.mkdirSync(dpath); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - let dd = await fileio.opendir(dpath); - let dir = await dd.read(); - expect(isBoolean(dir.isSymbolicLink())).assertTrue(); - expect(dir.isSymbolicLink() === false).assertTrue(); - fileio.unlinkSync(fpath); - fileio.rmdirSync(dpath); - done(); - } catch (e) { - console.info('fileio_dir_read_async_isSymbolicLink_000 has failed for ' + e); - expect(null).assertFail(); - } - }); -})} +/* + * Copyright (C) 2021 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 { + fileio, FILE_CONTENT, prepareFile, nextFileName, isString, isBoolean, forceRemoveDir, + describe, it, expect, +} from '../../Common'; + +export default function fileioDirRead() { +describe('fileio_dir_read', function () { + + /** + * @tc.number SUB_DF_FILEIO_DIR_READ_ASYNC_0000 + * @tc.name fileio_test_dir_read_async_000 + * @tc.desc Test Dir read() interface,return in promise mode. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_dir_read_async_000', 0, async function (done) { + let dpath = await nextFileName('fileio_test_dir_read_async_000') + 'd'; + let fpath = dpath + '/f1'; + + try { + fileio.mkdirSync(dpath); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let dd = fileio.opendirSync(dpath); + let dir = await dd.read(); + dd.closeSync(); + fileio.unlinkSync(fpath); + fileio.rmdirSync(dpath); + done(); + } + catch (e) { + console.info('fileio_test_dir_read_async_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_DIR_READ_ASYNC_0100 + * @tc.name fileio_test_dir_read_async_001 + * @tc.desc Test Dir read() interface,return in callback mode. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_dir_read_async_001', 0, async function (done) { + let dpath = await nextFileName('fileio_test_dir_read_async_001') + 'd'; + let fpath = dpath + '/f1'; + + try { + fileio.mkdirSync(dpath); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let dd = fileio.opendirSync(dpath); + dd.read(function (err, dirent) { + dd.closeSync(); + fileio.unlinkSync(fpath); + fileio.rmdirSync(dpath); + done(); + }); + } catch (e) { + console.info('fileio_test_dir_read_async_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_DIR_READ_ASYNC_0200 + * @tc.name fileio_test_dir_read_async_002 + * @tc.desc Test Dir read() interface,there are multiple parameters. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_dir_read_async_002', 0, async function (done) { + let dpath = await nextFileName('fileio_test_dir_read_async_002') + 'd'; + let fpath = dpath + '/f1'; + let dd = null + try { + fileio.mkdirSync(dpath); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + dd = fileio.opendirSync(dpath); + dd.read(-1,function (err, dirent) { + + }); + } catch (e) { + console.info('fileio_test_dir_read_async_002 has failed for ' + e); + expect(e.message == "Number of arguments unmatched").assertTrue(); + dd.closeSync(); + fileio.unlinkSync(fpath); + fileio.rmdirSync(dpath); + done(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_DIR_READ_SYNC_0000 + * @tc.name fileio_dir_read_sync_000 + * @tc.desc Test Dir readSync() interface. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_dir_read_sync_000', 0, async function () { + let dpath = await nextFileName('fileio_dir_read_sync_000') + 'd'; + let fpath = dpath + '/f1'; + + try { + fileio.mkdirSync(dpath); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let dd = fileio.opendirSync(dpath); + dd.readSync(); + dd.closeSync(); + fileio.unlinkSync(fpath); + fileio.rmdirSync(dpath); + } catch (e) { + console.info('fileio_dir_read_sync_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_DIR_READ_SYNC_0100 + * @tc.name fileio_dir_read_sync_001 + * @tc.desc Test Dir.readSync() interface,there are multiple parameters. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_dir_read_sync_001', 0, async function () { + let dpath = await nextFileName('fileio_dir_read_sync_001') + 'd'; + let fpath = dpath + '/f1'; + let dd = null; + try { + fileio.mkdirSync(dpath); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + dd = fileio.opendirSync(dpath); + dd.readSync(-1); + } catch (e) { + console.info('fileio_dir_read_sync_001 has failed for ' + e); + expect(e.message == "Number of arguments unmatched").assertTrue(); + dd.closeSync(); + fileio.unlinkSync(fpath); + fileio.rmdirSync(dpath); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_DIR_READ_SYNC_NAME_0000 + * @tc.name fileio_dir_read_sync_name_000 + * @tc.desc Test Dir.readSync() interface. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_dir_read_sync_name_000', 0, async function (done) { + let dpath = await nextFileName('fileio_dir_read_sync_name_000') + 'd'; + let fpath = dpath + '/f1'; + try { + fileio.mkdirSync(dpath); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let dd = await fileio.opendir(dpath); + let dir = dd.readSync(); + expect(isString(dir.name)).assertTrue(); + expect(fpath.indexOf(dir.name) > -1).assertTrue(); + fileio.unlinkSync(fpath); + fileio.rmdirSync(dpath); + done(); + } catch (e) { + console.info('fileio_dir_read_sync_name_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_DIR_READ_SYNC_NAME_0100 + * @tc.name fileio_dir_read_sync_name_001 + * @tc.desc Test Dir.readSync() interface. Synchronous loop reads next directory entry. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_dir_read_sync_name_001', 0, async function () { + let dpath = await nextFileName('fileio_dir_read_sync_name_001') + 'd'; + fileio.mkdirSync(dpath); + let fdpath = dpath; + + try { + for (let i = 0; i < 10; i++) { + console.info('time' + i); + dpath = dpath + '/d' + i; + fileio.mkdirSync(dpath); + } + let dir = fileio.opendirSync(fdpath); + let dirent = dir.readSync(); + while (dirent) { + fdpath = fdpath + '/' + dirent.name; + dir = fileio.opendirSync(fdpath); + dirent = dir.readSync(); + } + forceRemoveDir(dpath, 10); + } catch (e) { + console.info('fileio_dir_read_sync_name_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_DIR_READ_SYNC_ISBLOCKDEVICE_0000 + * @tc.name fileio_dir_read_sync_isBlockDevice_000 + * @tc.desc Test Dir.readSync() interface. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_dir_read_sync_isBlockDevice_000', 0, async function (done) { + let dpath = await nextFileName('fileio_dir_read_sync_isBlockDevice_000') + 'd'; + let fpath = dpath + '/f1'; + try { + fileio.mkdirSync(dpath); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let dd = await fileio.opendir(dpath); + let dir = dd.readSync(); + expect(isBoolean(dir.isBlockDevice())).assertTrue(); + expect(dir.isBlockDevice() === false).assertTrue(); + fileio.unlinkSync(fpath); + fileio.rmdirSync(dpath); + done(); + } catch (e) { + console.info('fileio_dir_read_sync_isBlockDevice_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_DIR_READ_SYNC_ISCHARACTERDEVICE_0000 + * @tc.name fileio_dir_read_sync_isCharacterDevice_000 + * @tc.desc Test Dir.readSync() interface. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_dir_read_sync_isCharacterDevice_000', 0, async function (done) { + let dpath = await nextFileName('fileio_dir_read_sync_isCharacterDevice_000') + 'd'; + let fpath = dpath + '/f1'; + try { + fileio.mkdirSync(dpath); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let dd = await fileio.opendir(dpath); + let dir = dd.readSync(); + expect(isBoolean(dir.isCharacterDevice())).assertTrue(); + expect(dir.isCharacterDevice() === false).assertTrue(); + fileio.unlinkSync(fpath); + fileio.rmdirSync(dpath); + done(); + } catch (e) { + console.info('fileio_dir_read_sync_isCharacterDevice_000 has failed for ' + e); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_DIR_READ_SYNC_ISDIRECTORY_0000 + * @tc.name fileio_dir_read_sync_isDirectory_000 + * @tc.desc Test Dir.readSync() interface. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_dir_read_sync_isDirectory_000', 0, async function (done) { + let dpath = await nextFileName('fileio_dir_read_sync_isDirectory_000') + 'd'; + let fpath = dpath + '/f1'; + try { + fileio.mkdirSync(dpath); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let dd = await fileio.opendir(dpath); + let dir = dd.readSync(); + expect(isBoolean(dir.isDirectory())).assertTrue(); + expect(dir.isDirectory() === false).assertTrue(); + fileio.unlinkSync(fpath); + fileio.rmdirSync(dpath); + done(); + } catch (e) { + console.info('fileio_dir_read_sync_isDirectory_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_DIR_READ_SYNC_ISFIFO_0000 + * @tc.name fileio_dir_read_sync_isFIFO_000 + * @tc.desc Test Dir.readSync() interface. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_dir_read_sync_isFIFO_000', 0, async function (done) { + let dpath = await nextFileName('fileio_dir_read_sync_isFIFO_000') + 'd'; + let fpath = dpath + '/f1'; + try { + fileio.mkdirSync(dpath); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let dd = await fileio.opendir(dpath); + let dir = dd.readSync(); + expect(isBoolean(dir.isFIFO())).assertTrue(); + expect(dir.isFIFO() === false).assertTrue(); + fileio.unlinkSync(fpath); + fileio.rmdirSync(dpath); + done(); + } catch (e) { + console.info('fileio_dir_read_sync_isFIFO_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_DIR_READ_SYNC_ISFILE_0000 + * @tc.name fileio_dir_read_sync_isFile_000 + * @tc.desc Test Dir.readSync() interface. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_dir_read_sync_isFile_000', 0, async function (done) { + let dpath = await nextFileName('fileio_dir_read_sync_isFile_000') + 'd'; + let fpath = dpath + '/f1'; + try { + fileio.mkdirSync(dpath); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let dd = await fileio.opendir(dpath); + let dir = dd.readSync(); + expect(isBoolean(dir.isFile())).assertTrue(); + expect(dir.isFile()).assertTrue(); + fileio.unlinkSync(fpath); + fileio.rmdirSync(dpath); + done(); + } catch (e) { + console.info('fileio_dir_read_sync_isFile_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_DIR_READ_SYNC_ISCOCKET_0000 + * @tc.name fileio_dir_read_sync_isSocket_000 + * @tc.desc Test Dir.readSync() interface. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_dir_read_sync_isSocket_000', 0, async function (done) { + let dpath = await nextFileName('fileio_dir_read_sync_isSocket_000') + 'd'; + let fpath = dpath + '/f1'; + try { + fileio.mkdirSync(dpath); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let dd = await fileio.opendir(dpath); + let dir = dd.readSync(); + expect(isBoolean(dir.isSocket())).assertTrue(); + expect(dir.isSocket() === false).assertTrue(); + fileio.unlinkSync(fpath); + fileio.rmdirSync(dpath); + done(); + } catch (e) { + console.info('fileio_dir_read_sync_isSocket_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_DIR_READ_SYNC_ISSYMBOLICLINK_0000 + * @tc.name fileio_dir_read_sync_isSymbolicLink_000 + * @tc.desc Test Dir.readSync() interface. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_dir_read_sync_isSymbolicLink_000', 0, async function (done) { + let dpath = await nextFileName('fileio_dir_read_sync_isSymbolicLink_000') + 'd'; + let fpath = dpath + '/f1'; + try { + fileio.mkdirSync(dpath); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let dd = await fileio.opendir(dpath); + let dir = dd.readSync(); + expect(isBoolean(dir.isSymbolicLink())).assertTrue(); + expect(dir.isSymbolicLink() === false).assertTrue(); + fileio.unlinkSync(fpath); + fileio.rmdirSync(dpath); + done(); + } catch (e) { + console.info('fileio_dir_read_sync_isSymbolicLink_000 has failed for ' + e); + expect(null); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_DIR_READ_ASYNC_NAME_0000 + * @tc.name fileio_dir_read_async_name_000 + * @tc.desc Test Dir.readAsync() interface. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_dir_read_async_name_000', 0, async function (done) { + let dpath = await nextFileName('fileio_dir_read_async_name_000') + 'd'; + let fpath = dpath + '/f1'; + try { + fileio.mkdirSync(dpath); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let dd = await fileio.opendir(dpath); + let dir = await dd.read(); + expect(isString(dir.name)).assertTrue(); + expect(fpath.indexOf(dir.name) > -1).assertTrue(); + fileio.unlinkSync(fpath); + fileio.rmdirSync(dpath); + done(); + } catch (e) { + console.info('fileio_dir_read_async_name_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_DIR_READ_ASYNC_NAME_0100 + * @tc.name fileio_dir_read_async_name_001 + * @tc.desc Test Dir.readAsync() interface. Asynchronously loop to read next directory item. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_dir_read_async_name_001', 0, async function (done) { + let dpath = await nextFileName('fileio_dir_read_async_name_001') + 'd'; + fileio.mkdirSync(dpath); + let fdpath = dpath; + + try { + for (let i = 0; i < 10; i++) { + console.info('time' + i); + dpath = dpath + '/d' + i; + fileio.mkdirSync(dpath); + } + let dir = fileio.opendirSync(fdpath); + let dirent = await dir.read(); + while (dirent) { + fdpath = fdpath + '/' + dirent.name; + dir = fileio.opendirSync(fdpath); + dirent = await dir.read(); + } + forceRemoveDir(dpath, 10); + done(); + } catch (e) { + console.info('fileio_dir_read_async_name_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_DIR_READ_ASYNC_ISBLOCKDEVICE_0000 + * @tc.name fileio_dir_read_async_isBlockDevice_000 + * @tc.desc Test Dir.readAsync() interface. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_dir_read_async_isBlockDevice_000', 0, async function (done) { + let dpath = await nextFileName('fileio_dir_read_async_isBlockDevice_000') + 'd'; + let fpath = dpath + '/f1'; + try { + fileio.mkdirSync(dpath); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let dd = await fileio.opendir(dpath); + let dir = await dd.read(); + expect(isBoolean(dir.isBlockDevice())).assertTrue(); + expect(dir.isBlockDevice() === false).assertTrue(); + fileio.unlinkSync(fpath); + fileio.rmdirSync(dpath); + done(); + } catch (e) { + console.info('fileio_dir_read_async_isBlockDevice_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_DIR_READ_ASYNC_ISCHARACTERDEVICE_0000 + * @tc.name fileio_dir_read_async_isCharacterDevice_000 + * @tc.desc Test Dir.readAsync() interface. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + + it('fileio_dir_read_async_isCharacterDevice_000', 0, async function (done) { + let dpath = await nextFileName('fileio_dir_read_async_isCharacterDevice_000') + 'd'; + let fpath = dpath + '/f1'; + try { + fileio.mkdirSync(dpath); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let dd = await fileio.opendir(dpath); + let dir = await dd.read(); + expect(isBoolean(dir.isCharacterDevice())).assertTrue(); + expect(dir.isCharacterDevice() === false).assertTrue(); + fileio.unlinkSync(fpath); + fileio.rmdirSync(dpath); + done(); + } catch (e) { + console.info('fileio_dir_read_async_isCharacterDevice_000 has failed for ' + e); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_DIR_READ_ASYNC_ISDIRECTORY_0000 + * @tc.name fileio_dir_read_async_isDirectory_000 + * @tc.desc Test Dir.readAsync() interface. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_dir_read_async_isDirectory_000', 0, async function (done) { + let dpath = await nextFileName('fileio_dir_read_async_isDirectory_000') + 'd'; + let fpath = dpath + '/f1'; + try { + fileio.mkdirSync(dpath); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let dd = await fileio.opendir(dpath); + let dir = await dd.read(); + expect(isBoolean(dir.isDirectory())).assertTrue(); + expect(dir.isDirectory() === false).assertTrue(); + fileio.unlinkSync(fpath); + fileio.rmdirSync(dpath); + done(); + } catch (e) { + console.info('fileio_dir_read_async_isDirectory_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_DIR_READ_ASYNC_ISFIFO_0000 + * @tc.name fileio_dir_read_async_isFIFO_000 + * @tc.desc Test Dir.readAsync() interface. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_dir_read_async_isFIFO_000', 0, async function (done) { + let dpath = await nextFileName('fileio_dir_read_async_isFIFO_000') + 'd'; + let fpath = dpath + '/f1'; + try { + fileio.mkdirSync(dpath); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let dd = await fileio.opendir(dpath); + let dir = await dd.read(); + expect(isBoolean(dir.isFIFO())).assertTrue(); + expect(dir.isFIFO() === false).assertTrue(); + fileio.unlinkSync(fpath); + fileio.rmdirSync(dpath); + done(); + } catch (e) { + console.info('fileio_dir_read_async_isFIFO_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_DIR_READ_ASYNC_ISFILE_0000 + * @tc.name fileio_dir_read_async_isFile_000 + * @tc.desc Test Dir.readAsync() interface. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_dir_read_async_isFile_000', 0, async function (done) { + let dpath = await nextFileName('fileio_dir_read_async_isFile_000') + 'd'; + let fpath = dpath + '/f1'; + try { + fileio.mkdirSync(dpath); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let dd = await fileio.opendir(dpath); + let dir = await dd.read(); + expect(isBoolean(dir.isFile())).assertTrue(); + expect(dir.isFile()).assertTrue(); + fileio.unlinkSync(fpath); + fileio.rmdirSync(dpath); + done(); + } catch (e) { + console.info('fileio_dir_read_async_isFile_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_DIR_READ_ASYNC_ISSOCKET_0000 + * @tc.name fileio_dir_read_async_isSocket_000 + * @tc.desc Test Dir.readAsync() interface. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_dir_read_async_isSocket_000', 0, async function (done) { + let dpath = await nextFileName('fileio_dir_read_async_isSocket_000') + 'd'; + let fpath = dpath + '/f1'; + try { + fileio.mkdirSync(dpath); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let dd = await fileio.opendir(dpath);; + let dir = await dd.read();; + expect(isBoolean(dir.isSocket())).assertTrue(); + expect(dir.isSocket() === false).assertTrue(); + fileio.unlinkSync(fpath); + fileio.rmdirSync(dpath); + done(); + } catch (e) { + console.info('fileio_dir_read_async_isSocket_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_DIR_READ_ASYNC_ISSYMBOLICLINK_0000 + * @tc.name fileio_dir_read_async_isSymbolicLink_000 + * @tc.desc Test Dir.readAsync() interface. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_dir_read_async_isSymbolicLink_000', 0, async function (done) { + let dpath = await nextFileName('fileio_dir_read_async_isSymbolicLink_000') + 'd'; + let fpath = dpath + '/f1'; + try { + fileio.mkdirSync(dpath); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let dd = await fileio.opendir(dpath); + let dir = await dd.read(); + expect(isBoolean(dir.isSymbolicLink())).assertTrue(); + expect(dir.isSymbolicLink() === false).assertTrue(); + fileio.unlinkSync(fpath); + fileio.rmdirSync(dpath); + done(); + } catch (e) { + console.info('fileio_dir_read_async_isSymbolicLink_000 has failed for ' + e); + expect(null).assertFail(); + } + }); +})} diff --git a/storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/class_dirent/all.test.js b/storage/storagefileiojstest/src/main/js/test/module_fileio/class_dirent/all.test.js similarity index 96% rename from storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/class_dirent/all.test.js rename to storage/storagefileiojstest/src/main/js/test/module_fileio/class_dirent/all.test.js index 866915404f525279173811ae41c7ad2c4c125c6c..7608ba3c026aac639e2d072fc033d06aa08aad89 100644 --- a/storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/class_dirent/all.test.js +++ b/storage/storagefileiojstest/src/main/js/test/module_fileio/class_dirent/all.test.js @@ -1,536 +1,536 @@ -/* - * Copyright (C) 2023 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 { - fileio, FILE_CONTENT, prepareFile, nextFileName, isBoolean, isString, - describe, it, expect, -} from '../../Common'; - -export default function fileioDirent() { -describe('fileio_dirent', function () { - - /** - * @tc.number SUB_DF_FILEIO_DIRENT_NAME_0010 - * @tc.name fileio_test_dirent_name_001 - * @tc.desc Test dirent interface - * @tc.size MEDIUM(中型) - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_dirent_name_001', 0, async function (done) { - let dpath = await nextFileName('fileio_test_dirent_name_001') + 'd'; - let fpath = dpath + '/f2'; - - try { - expect(fileio.mkdirSync(dpath) == null).assertTrue(); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - let dd = fileio.opendirSync(dpath); - expect(dd !== null).assertTrue(); - dd.read(function (err, dirent) { - expect(dirent !== null).assertTrue(); - expect(isString(dirent.name)).assertTrue(); - expect(dd.closeSync() == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - expect(fileio.rmdirSync(dpath) == null).assertTrue(); - done(); - }) - } catch (e) { - console.log('fileio_test_dirent_name_001 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_DIRENT_NAME_0000 - * @tc.name fileio_test_dirent_name_000 - * @tc.desc Test dirent interface - * @tc.size MEDIUM(中型) - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_dirent_name_000', 0, async function (done) { - let dpath = await nextFileName('fileio_test_dirent_name_000') + 'd'; - let fpath = dpath + '/f1'; - - try { - expect(fileio.mkdirSync(dpath) == null).assertTrue(); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - let dd = fileio.opendirSync(dpath); - expect(dd !== null).assertTrue(); - let dirent = await dd.read(); - expect(dirent !== null).assertTrue(); - expect(isString(dirent.name)).assertTrue(); - expect(dd.closeSync() == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - expect(fileio.rmdirSync(dpath) == null).assertTrue(); - done(); - - } catch (e) { - console.log('fileio_test_dirent_name_000 has failed for ' + e); - expect(null).assertFail(); - } - }) - - /** - * @tc.number SUB_DF_FileIO_Dir_ReadSync_0200 - * @tc.name fileio_test_dirent_name_002 - * @tc.desc Test readSync() interface - * @tc.size MEDIUM(中型) - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_dirent_name_002', 0, async function () { - let dpath = await nextFileName('fileio_test_dirent_name_002') + 'd'; - let fpath = dpath + '/f1'; - - try { - expect(fileio.mkdirSync(dpath) == null).assertTrue(); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - let dd = fileio.opendirSync(dpath); - expect(dd !== null).assertTrue(); - let dirent = dd.readSync(); - expect(dirent !== null).assertTrue(); - expect(isString(dirent.name)).assertTrue(); - expect(dd.closeSync() == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - expect(fileio.rmdirSync(dpath) == null).assertTrue(); - } catch (e) { - console.log('fileio_test_dirent_name_002 has failed for ' + e); - expect(null).assertFail(); - } - }) - - /** - * @tc.number SUB_DF_FILEIO_DIR_ISBLOCKDEVICE_0000 - * @tc.name fileio_test_dirent_is_block_device_000 - * @tc.desc Test isBlockDevice() interface - * @tc.size MEDIUM(中型) - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_dirent_is_block_device_000', 0, async function () { - let dpath = await nextFileName('fileio_test_dirent_is_block_device_000') + 'd'; - let fpath = dpath + '/f1'; - try { - expect(fileio.mkdirSync(dpath) == null).assertTrue(); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - let dd = fileio.opendirSync(dpath); - expect(dd !== null).assertTrue(); - let dirent = dd.readSync(); - expect(dirent !== null).assertTrue(); - expect(isBoolean(dirent.isBlockDevice())).assertTrue(); - expect(dd.closeSync() == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - expect(fileio.rmdirSync(dpath) == null).assertTrue(); - } catch (e) { - console.log('fileio_test_dirent_is_block_device_000 has failed for ' + e); - expect(null).assertFail(); - } - }) - - /** - * @tc.number SUB_DF_FILEIO_DIR_ISBLOCKDEVICE_0010 - * @tc.name fileio_test_dirent_is_block_device_001 - * @tc.desc Test isBlockDevice() interface - * @tc.size MEDIUM(中型) - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_dirent_is_block_device_001', 0, async function () { - let dpath = await nextFileName('fileio_test_dirent_is_block_device_001') + 'd'; - let fpath = dpath + '/f1'; - let dd; - - try { - expect(fileio.mkdirSync(dpath) == null).assertTrue(); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - dd = fileio.opendirSync(dpath); - expect(dd !== null).assertTrue(); - let dirent = dd.readSync(); - expect(dirent !== null).assertTrue(); - dirent.isBlockDevice(-1); - expect(null).assertFail(); - } catch (e) { - expect(dd.closeSync() == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - expect(fileio.rmdirSync(dpath) == null).assertTrue(); - } - }) - - /** - * @tc.number SUB_DF_FILEIO_DIR_ISCHARACTERDEVICE_0000 - * @tc.name fileio_test_dirent_is_character_device_000 - * @tc.desc Test isCharacterDevice() interface - * @tc.size MEDIUM(中型) - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_dirent_is_character_device_000', 0, async function () { - let dpath = await nextFileName('fileio_test_dirent_is_character_device_000') + 'd'; - let fpath = dpath + '/f1'; - - try { - expect(fileio.mkdirSync(dpath) == null).assertTrue(); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - let dd = fileio.opendirSync(dpath); - expect(dd !== null).assertTrue(); - let dirent = dd.readSync(); - expect(dirent !== null).assertTrue(); - expect(isBoolean(dirent.isCharacterDevice())).assertTrue(); - expect(dd.closeSync() == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - expect(fileio.rmdirSync(dpath) == null).assertTrue(); - } catch (e) { - console.log('fileio_test_dirent_is_character_device_000 has failed for ' + e); - expect(null).assertFail(); - } - }) - - /** - * @tc.number SUB_DF_FILEIO_DIR_ISCHARACTERDEVICE_0010 - * @tc.name fileio_test_dirent_is_character_device_001 - * @tc.desc Test isCharacterDevice() interface - * @tc.size MEDIUM(中型) - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_dirent_is_character_device_001', 0, async function () { - let dpath = await nextFileName('fileio_test_dirent_is_character_device_001') + 'd'; - let fpath = dpath + '/f1'; - let dd; - - try { - expect(fileio.mkdirSync(dpath) == null).assertTrue(); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - dd = fileio.opendirSync(dpath); - expect(dd !== null).assertTrue(); - let dirent = dd.readSync(); - expect(dirent !== null).assertTrue(); - dirent.isCharacterDevice(-1); - expect(null).assertFail(); - } catch (e) { - expect(dd.closeSync() == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - expect(fileio.rmdirSync(dpath) == null).assertTrue(); - } - }) - - /** - * @tc.number SUB_DF_FILEIO_DIR_ISDIRECTORY_0000 - * @tc.name fileio_test_dirent_is_directory_000 - * @tc.desc Test isDirectory() interface - * @tc.size MEDIUM(中型) - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_dirent_is_directory_000', 0, async function () { - let dpath = await nextFileName('fileio_test_dirent_is_directory_000') + 'd'; - let fpath = dpath + '/f1'; - - try { - expect(fileio.mkdirSync(dpath) == null).assertTrue(); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - let dd = fileio.opendirSync(dpath); - expect(dd !== null).assertTrue(); - let dirent = dd.readSync(); - expect(dirent !== null).assertTrue(); - expect(isBoolean(dirent.isDirectory())).assertTrue(); - expect(dd.closeSync() == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - expect(fileio.rmdirSync(dpath) == null).assertTrue(); - } catch (e) { - console.log('fileio_test_dirent_is_directory_000 has failed for ' + e); - expect(null).assertFail(); - } - }) - - /** - * @tc.number SUB_DF_FileIO_Dir_IsDirectory_0010 - * @tc.name fileio_test_dirent_is_directory_001 - * @tc.desc Test isDirectory() interface - * @tc.size MEDIUM(中型) - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_dirent_is_directory_001', 0, async function () { - let dpath = await nextFileName('fileio_test_dirent_is_directory_001') + 'd'; - let fpath = dpath + '/f1'; - let dd; - - try { - expect(fileio.mkdirSync(dpath) == null).assertTrue(); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - dd = fileio.opendirSync(dpath); - expect(dd !== null).assertTrue(); - let dirent = dd.readSync(); - expect(dirent !== null).assertTrue(); - dirent.isDirectory(-1); - expect(null).assertFail(); - } catch (e) { - expect(dd.closeSync() == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - expect(fileio.rmdirSync(dpath) == null).assertTrue(); - } - }) - - /** - * @tc.number SUB_DF_FILEIO_DIR_ISFIFO_0000 - * @tc.name fileio_test_dirent_is_fifo_000 - * @tc.desc Test isFIFO() interface - * @tc.size MEDIUM(中型) - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_dirent_is_fifo_000', 0, async function () { - let dpath = await nextFileName('fileio_test_dirent_is_fifo_000') + 'd'; - let fpath = dpath + '/f1'; - - try { - expect(fileio.mkdirSync(dpath) == null).assertTrue(); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - let dd = fileio.opendirSync(dpath); - expect(dd !== null).assertTrue(); - let dirent = dd.readSync(); - expect(dirent !== null).assertTrue(); - expect(isBoolean(dirent.isFIFO())).assertTrue() - expect(dd.closeSync() == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - expect(fileio.rmdirSync(dpath) == null).assertTrue(); - } catch (e) { - console.log('fileio_test_dirent_is_fifo_000 has failed for ' + e); - expect(null).assertFail() - } - }) - - /** - * @tc.number SUB_DF_FILEIO_DIR_ISFIFO_0010 - * @tc.name fileio_test_dirent_is_fifo_001 - * @tc.desc Test isFIFO() interface - * @tc.size MEDIUM(中型) - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_dirent_is_fifo_001', 0, async function () { - let dpath = await nextFileName('fileio_test_dirent_is_fifo_001') + 'd'; - let fpath = dpath + '/f1'; - let dd; - - try { - expect(fileio.mkdirSync(dpath) == null).assertTrue(); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - dd = fileio.opendirSync(dpath); - expect(dd !== null).assertTrue(); - let dirent = dd.readSync(); - expect(dirent !== null).assertTrue(); - dirent.isFIFO(-1); - expect(null).assertFail(); - } catch (e) { - expect(dd.closeSync() == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - expect(fileio.rmdirSync(dpath) == null).assertTrue(); - } - }) - - /** - * @tc.number SUB_DF_FILEIO_DIR_ISFILE_0000 - * @tc.name fileio_test_dirent_is_file_000 - * @tc.desc Test isFILE() interface - * @tc.size MEDIUM(中型) - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_dirent_is_file_000', 0, async function () { - let dpath = await nextFileName('fileio_test_dirent_is_file_000') + 'd'; - let fpath = dpath + '/f1'; - - try { - expect(fileio.mkdirSync(dpath) == null).assertTrue(); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - let dd = fileio.opendirSync(dpath); - expect(dd !== null).assertTrue(); - let dirent = dd.readSync(); - expect(dirent !== null).assertTrue(); - expect(isBoolean(dirent.isFile())).assertTrue(); - expect(dd.closeSync() == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - expect(fileio.rmdirSync(dpath) == null).assertTrue(); - } catch (e) { - console.log('fileio_test_dirent_is_file_000 has failed for ' + e); - expect(null).assertFail(); - } - }) - - /** - * @tc.number SUB_DF_FILEIO_DIR_ISFILE_0010 - * @tc.name fileio_test_dirent_is_file_001 - * @tc.desc Test isFILE() interface - * @tc.size MEDIUM(中型) - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_dirent_is_file_001', 0, async function () { - let dpath = await nextFileName('fileio_test_dirent_is_file_001') + 'd'; - let fpath = dpath + '/f1'; - let dd; - - try { - expect(fileio.mkdirSync(dpath) == null).assertTrue(); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - dd = fileio.opendirSync(dpath); - expect(dd !== null).assertTrue(); - let dirent = dd.readSync(); - expect(dirent !== null).assertTrue(); - dirent.isFile(-1); - expect(null).assertFail(); - } catch (e) { - expect(dd.closeSync() == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - expect(fileio.rmdirSync(dpath) == null).assertTrue(); - } - }) - - /** - * @tc.number SUB_DF_FILEIO_DIR_ISSOCKET_0000 - * @tc.name fileio_test_dirent_is_socket_000 - * @tc.desc Test isSocket() interface - * @tc.size MEDIUM(中型) - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_dirent_is_socket_000', 0, async function () { - let dpath = await nextFileName('fileio_test_dirent_is_socket_000') + 'd'; - let fpath = dpath + '/f1'; - - try { - expect(fileio.mkdirSync(dpath) == null).assertTrue(); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - let dd = fileio.opendirSync(dpath); - expect(dd !== null).assertTrue(); - let dirent = dd.readSync(); - expect(dirent !== null).assertTrue(); - expect(isBoolean(dirent.isSocket())).assertTrue(); - expect(dd.closeSync() == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - expect(fileio.rmdirSync(dpath) == null).assertTrue(); - } catch (e) { - console.log('fileio_test_dirent_is_socket_000 has failed for ' + e); - expect(null).assertFail(); - } - }) - - /** - * @tc.number SUB_DF_FILEIO_DIR_ISSOCKET_0010 - * @tc.name fileio_test_dirent_is_socket_001 - * @tc.desc Test isSocket() interface - * @tc.size MEDIUM(中型) - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_dirent_is_socket_001', 0, async function () { - let dpath = await nextFileName('fileio_test_dirent_is_socket_001') + 'd'; - let fpath = dpath + '/f1'; - let dd; - - try { - expect(fileio.mkdirSync(dpath) == null).assertTrue(); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - dd = fileio.opendirSync(dpath); - expect(dd !== null).assertTrue(); - let dirent = dd.readSync(); - expect(dirent !== null).assertTrue() - dirent.isSocket(-1); - expect(null).assertFail(); - } catch (e) { - expect(dd.closeSync() == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - expect(fileio.rmdirSync(dpath) == null).assertTrue(); - } - }) - - /** - * @tc.number SUB_DF_FileIO_Dir_IsSymbolicLink_0000 - * @tc.name fileio_test_dirent_is_symbolic_link_000 - * @tc.desc Test isSymbolicLink() interface - * @tc.size MEDIUM(中型) - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_dirent_is_symbolic_link_000', 0, async function () { - let dpath = await nextFileName('fileio_test_dirent_is_symbolic_link_000') + 'd'; - let fpath = dpath + '/f1'; - - try { - expect(fileio.mkdirSync(dpath) == null).assertTrue(); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - let dd = fileio.opendirSync(dpath); - expect(dd !== null).assertTrue() - let dirent = dd.readSync(); - expect(dirent !== null).assertTrue(); - expect(isBoolean(dirent.isSymbolicLink())).assertTrue(); - expect(dd.closeSync() == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - expect(fileio.rmdirSync(dpath) == null).assertTrue(); - } catch (e) { - console.log('fileio_test_dirent_is_symbolic_link_000 has failed for ' + e); - expect(null).assertFail(); - } - }) - - /** - * @tc.number SUB_DF_FILEIO_DIR_ISSYMBOLICLINK_0010 - * @tc.name fileio_test_dirent_is_symbolic_link_001 - * @tc.desc Test isSymbolicLink() interface - * @tc.size MEDIUM(中型) - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_dirent_is_symbolic_link_001', 0, async function () { - let dpath = await nextFileName('fileio_test_dirent_is_symbolic_link_001') + 'd'; - let fpath = dpath + '/f1'; - let dd; - - try { - expect(fileio.mkdirSync(dpath) == null).assertTrue(); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - dd = fileio.opendirSync(dpath); - expect(dd !== null).assertTrue(); - let dirent = dd.readSync(); - expect(dirent !== null).assertTrue(); - dirent.isSymbolicLink(-1); - expect(null).assertFail(); - } catch (e) { - expect(dd.closeSync() == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue() - expect(fileio.rmdirSync(dpath) == null).assertTrue(); - } - }); -});} +/* + * Copyright (C) 2021 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 { + fileio, FILE_CONTENT, prepareFile, nextFileName, isBoolean, isString, + describe, it, expect, +} from '../../Common'; + +export default function fileioDirent() { +describe('fileio_dirent', function () { + + /** + * @tc.number SUB_DF_FILEIO_DIRENT_NAME_0010 + * @tc.name fileio_test_dirent_name_001 + * @tc.desc Test dirent interface + * @tc.size MEDIUM(中型) + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_dirent_name_001', 0, async function (done) { + let dpath = await nextFileName('fileio_test_dirent_name_001') + 'd'; + let fpath = dpath + '/f2'; + + try { + expect(fileio.mkdirSync(dpath) == null).assertTrue(); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let dd = fileio.opendirSync(dpath); + expect(dd !== null).assertTrue(); + dd.read(function (err, dirent) { + expect(dirent !== null).assertTrue(); + expect(isString(dirent.name)).assertTrue(); + expect(dd.closeSync() == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + expect(fileio.rmdirSync(dpath) == null).assertTrue(); + done(); + }) + } catch (e) { + console.log('fileio_test_dirent_name_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_DIRENT_NAME_0000 + * @tc.name fileio_test_dirent_name_000 + * @tc.desc Test dirent interface + * @tc.size MEDIUM(中型) + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_dirent_name_000', 0, async function (done) { + let dpath = await nextFileName('fileio_test_dirent_name_000') + 'd'; + let fpath = dpath + '/f1'; + + try { + expect(fileio.mkdirSync(dpath) == null).assertTrue(); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let dd = fileio.opendirSync(dpath); + expect(dd !== null).assertTrue(); + let dirent = await dd.read(); + expect(dirent !== null).assertTrue(); + expect(isString(dirent.name)).assertTrue(); + expect(dd.closeSync() == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + expect(fileio.rmdirSync(dpath) == null).assertTrue(); + done(); + + } catch (e) { + console.log('fileio_test_dirent_name_000 has failed for ' + e); + expect(null).assertFail(); + } + }) + + /** + * @tc.number SUB_DF_FileIO_Dir_ReadSync_0200 + * @tc.name fileio_test_dirent_name_002 + * @tc.desc Test readSync() interface + * @tc.size MEDIUM(中型) + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_dirent_name_002', 0, async function () { + let dpath = await nextFileName('fileio_test_dirent_name_002') + 'd'; + let fpath = dpath + '/f1'; + + try { + expect(fileio.mkdirSync(dpath) == null).assertTrue(); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let dd = fileio.opendirSync(dpath); + expect(dd !== null).assertTrue(); + let dirent = dd.readSync(); + expect(dirent !== null).assertTrue(); + expect(isString(dirent.name)).assertTrue(); + expect(dd.closeSync() == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + expect(fileio.rmdirSync(dpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_test_dirent_name_002 has failed for ' + e); + expect(null).assertFail(); + } + }) + + /** + * @tc.number SUB_DF_FILEIO_DIR_ISBLOCKDEVICE_0000 + * @tc.name fileio_test_dirent_is_block_device_000 + * @tc.desc Test isBlockDevice() interface + * @tc.size MEDIUM(中型) + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_dirent_is_block_device_000', 0, async function () { + let dpath = await nextFileName('fileio_test_dirent_is_block_device_000') + 'd'; + let fpath = dpath + '/f1'; + try { + expect(fileio.mkdirSync(dpath) == null).assertTrue(); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let dd = fileio.opendirSync(dpath); + expect(dd !== null).assertTrue(); + let dirent = dd.readSync(); + expect(dirent !== null).assertTrue(); + expect(isBoolean(dirent.isBlockDevice())).assertTrue(); + expect(dd.closeSync() == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + expect(fileio.rmdirSync(dpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_test_dirent_is_block_device_000 has failed for ' + e); + expect(null).assertFail(); + } + }) + + /** + * @tc.number SUB_DF_FILEIO_DIR_ISBLOCKDEVICE_0010 + * @tc.name fileio_test_dirent_is_block_device_001 + * @tc.desc Test isBlockDevice() interface + * @tc.size MEDIUM(中型) + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_dirent_is_block_device_001', 0, async function () { + let dpath = await nextFileName('fileio_test_dirent_is_block_device_001') + 'd'; + let fpath = dpath + '/f1'; + let dd; + + try { + expect(fileio.mkdirSync(dpath) == null).assertTrue(); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + dd = fileio.opendirSync(dpath); + expect(dd !== null).assertTrue(); + let dirent = dd.readSync(); + expect(dirent !== null).assertTrue(); + dirent.isBlockDevice(-1); + expect(null).assertFail(); + } catch (e) { + expect(dd.closeSync() == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + expect(fileio.rmdirSync(dpath) == null).assertTrue(); + } + }) + + /** + * @tc.number SUB_DF_FILEIO_DIR_ISCHARACTERDEVICE_0000 + * @tc.name fileio_test_dirent_is_character_device_000 + * @tc.desc Test isCharacterDevice() interface + * @tc.size MEDIUM(中型) + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_dirent_is_character_device_000', 0, async function () { + let dpath = await nextFileName('fileio_test_dirent_is_character_device_000') + 'd'; + let fpath = dpath + '/f1'; + + try { + expect(fileio.mkdirSync(dpath) == null).assertTrue(); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let dd = fileio.opendirSync(dpath); + expect(dd !== null).assertTrue(); + let dirent = dd.readSync(); + expect(dirent !== null).assertTrue(); + expect(isBoolean(dirent.isCharacterDevice())).assertTrue(); + expect(dd.closeSync() == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + expect(fileio.rmdirSync(dpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_test_dirent_is_character_device_000 has failed for ' + e); + expect(null).assertFail(); + } + }) + + /** + * @tc.number SUB_DF_FILEIO_DIR_ISCHARACTERDEVICE_0010 + * @tc.name fileio_test_dirent_is_character_device_001 + * @tc.desc Test isCharacterDevice() interface + * @tc.size MEDIUM(中型) + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_dirent_is_character_device_001', 0, async function () { + let dpath = await nextFileName('fileio_test_dirent_is_character_device_001') + 'd'; + let fpath = dpath + '/f1'; + let dd; + + try { + expect(fileio.mkdirSync(dpath) == null).assertTrue(); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + dd = fileio.opendirSync(dpath); + expect(dd !== null).assertTrue(); + let dirent = dd.readSync(); + expect(dirent !== null).assertTrue(); + dirent.isCharacterDevice(-1); + expect(null).assertFail(); + } catch (e) { + expect(dd.closeSync() == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + expect(fileio.rmdirSync(dpath) == null).assertTrue(); + } + }) + + /** + * @tc.number SUB_DF_FILEIO_DIR_ISDIRECTORY_0000 + * @tc.name fileio_test_dirent_is_directory_000 + * @tc.desc Test isDirectory() interface + * @tc.size MEDIUM(中型) + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_dirent_is_directory_000', 0, async function () { + let dpath = await nextFileName('fileio_test_dirent_is_directory_000') + 'd'; + let fpath = dpath + '/f1'; + + try { + expect(fileio.mkdirSync(dpath) == null).assertTrue(); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let dd = fileio.opendirSync(dpath); + expect(dd !== null).assertTrue(); + let dirent = dd.readSync(); + expect(dirent !== null).assertTrue(); + expect(isBoolean(dirent.isDirectory())).assertTrue(); + expect(dd.closeSync() == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + expect(fileio.rmdirSync(dpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_test_dirent_is_directory_000 has failed for ' + e); + expect(null).assertFail(); + } + }) + + /** + * @tc.number SUB_DF_FileIO_Dir_IsDirectory_0010 + * @tc.name fileio_test_dirent_is_directory_001 + * @tc.desc Test isDirectory() interface + * @tc.size MEDIUM(中型) + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_dirent_is_directory_001', 0, async function () { + let dpath = await nextFileName('fileio_test_dirent_is_directory_001') + 'd'; + let fpath = dpath + '/f1'; + let dd; + + try { + expect(fileio.mkdirSync(dpath) == null).assertTrue(); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + dd = fileio.opendirSync(dpath); + expect(dd !== null).assertTrue(); + let dirent = dd.readSync(); + expect(dirent !== null).assertTrue(); + dirent.isDirectory(-1); + expect(null).assertFail(); + } catch (e) { + expect(dd.closeSync() == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + expect(fileio.rmdirSync(dpath) == null).assertTrue(); + } + }) + + /** + * @tc.number SUB_DF_FILEIO_DIR_ISFIFO_0000 + * @tc.name fileio_test_dirent_is_fifo_000 + * @tc.desc Test isFIFO() interface + * @tc.size MEDIUM(中型) + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_dirent_is_fifo_000', 0, async function () { + let dpath = await nextFileName('fileio_test_dirent_is_fifo_000') + 'd'; + let fpath = dpath + '/f1'; + + try { + expect(fileio.mkdirSync(dpath) == null).assertTrue(); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let dd = fileio.opendirSync(dpath); + expect(dd !== null).assertTrue(); + let dirent = dd.readSync(); + expect(dirent !== null).assertTrue(); + expect(isBoolean(dirent.isFIFO())).assertTrue() + expect(dd.closeSync() == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + expect(fileio.rmdirSync(dpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_test_dirent_is_fifo_000 has failed for ' + e); + expect(null).assertFail() + } + }) + + /** + * @tc.number SUB_DF_FILEIO_DIR_ISFIFO_0010 + * @tc.name fileio_test_dirent_is_fifo_001 + * @tc.desc Test isFIFO() interface + * @tc.size MEDIUM(中型) + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_dirent_is_fifo_001', 0, async function () { + let dpath = await nextFileName('fileio_test_dirent_is_fifo_001') + 'd'; + let fpath = dpath + '/f1'; + let dd; + + try { + expect(fileio.mkdirSync(dpath) == null).assertTrue(); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + dd = fileio.opendirSync(dpath); + expect(dd !== null).assertTrue(); + let dirent = dd.readSync(); + expect(dirent !== null).assertTrue(); + dirent.isFIFO(-1); + expect(null).assertFail(); + } catch (e) { + expect(dd.closeSync() == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + expect(fileio.rmdirSync(dpath) == null).assertTrue(); + } + }) + + /** + * @tc.number SUB_DF_FILEIO_DIR_ISFILE_0000 + * @tc.name fileio_test_dirent_is_file_000 + * @tc.desc Test isFILE() interface + * @tc.size MEDIUM(中型) + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_dirent_is_file_000', 0, async function () { + let dpath = await nextFileName('fileio_test_dirent_is_file_000') + 'd'; + let fpath = dpath + '/f1'; + + try { + expect(fileio.mkdirSync(dpath) == null).assertTrue(); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let dd = fileio.opendirSync(dpath); + expect(dd !== null).assertTrue(); + let dirent = dd.readSync(); + expect(dirent !== null).assertTrue(); + expect(isBoolean(dirent.isFile())).assertTrue(); + expect(dd.closeSync() == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + expect(fileio.rmdirSync(dpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_test_dirent_is_file_000 has failed for ' + e); + expect(null).assertFail(); + } + }) + + /** + * @tc.number SUB_DF_FILEIO_DIR_ISFILE_0010 + * @tc.name fileio_test_dirent_is_file_001 + * @tc.desc Test isFILE() interface + * @tc.size MEDIUM(中型) + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_dirent_is_file_001', 0, async function () { + let dpath = await nextFileName('fileio_test_dirent_is_file_001') + 'd'; + let fpath = dpath + '/f1'; + let dd; + + try { + expect(fileio.mkdirSync(dpath) == null).assertTrue(); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + dd = fileio.opendirSync(dpath); + expect(dd !== null).assertTrue(); + let dirent = dd.readSync(); + expect(dirent !== null).assertTrue(); + dirent.isFile(-1); + expect(null).assertFail(); + } catch (e) { + expect(dd.closeSync() == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + expect(fileio.rmdirSync(dpath) == null).assertTrue(); + } + }) + + /** + * @tc.number SUB_DF_FILEIO_DIR_ISSOCKET_0000 + * @tc.name fileio_test_dirent_is_socket_000 + * @tc.desc Test isSocket() interface + * @tc.size MEDIUM(中型) + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_dirent_is_socket_000', 0, async function () { + let dpath = await nextFileName('fileio_test_dirent_is_socket_000') + 'd'; + let fpath = dpath + '/f1'; + + try { + expect(fileio.mkdirSync(dpath) == null).assertTrue(); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let dd = fileio.opendirSync(dpath); + expect(dd !== null).assertTrue(); + let dirent = dd.readSync(); + expect(dirent !== null).assertTrue(); + expect(isBoolean(dirent.isSocket())).assertTrue(); + expect(dd.closeSync() == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + expect(fileio.rmdirSync(dpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_test_dirent_is_socket_000 has failed for ' + e); + expect(null).assertFail(); + } + }) + + /** + * @tc.number SUB_DF_FILEIO_DIR_ISSOCKET_0010 + * @tc.name fileio_test_dirent_is_socket_001 + * @tc.desc Test isSocket() interface + * @tc.size MEDIUM(中型) + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_dirent_is_socket_001', 0, async function () { + let dpath = await nextFileName('fileio_test_dirent_is_socket_001') + 'd'; + let fpath = dpath + '/f1'; + let dd; + + try { + expect(fileio.mkdirSync(dpath) == null).assertTrue(); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + dd = fileio.opendirSync(dpath); + expect(dd !== null).assertTrue(); + let dirent = dd.readSync(); + expect(dirent !== null).assertTrue() + dirent.isSocket(-1); + expect(null).assertFail(); + } catch (e) { + expect(dd.closeSync() == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + expect(fileio.rmdirSync(dpath) == null).assertTrue(); + } + }) + + /** + * @tc.number SUB_DF_FileIO_Dir_IsSymbolicLink_0000 + * @tc.name fileio_test_dirent_is_symbolic_link_000 + * @tc.desc Test isSymbolicLink() interface + * @tc.size MEDIUM(中型) + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_dirent_is_symbolic_link_000', 0, async function () { + let dpath = await nextFileName('fileio_test_dirent_is_symbolic_link_000') + 'd'; + let fpath = dpath + '/f1'; + + try { + expect(fileio.mkdirSync(dpath) == null).assertTrue(); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let dd = fileio.opendirSync(dpath); + expect(dd !== null).assertTrue() + let dirent = dd.readSync(); + expect(dirent !== null).assertTrue(); + expect(isBoolean(dirent.isSymbolicLink())).assertTrue(); + expect(dd.closeSync() == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + expect(fileio.rmdirSync(dpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_test_dirent_is_symbolic_link_000 has failed for ' + e); + expect(null).assertFail(); + } + }) + + /** + * @tc.number SUB_DF_FILEIO_DIR_ISSYMBOLICLINK_0010 + * @tc.name fileio_test_dirent_is_symbolic_link_001 + * @tc.desc Test isSymbolicLink() interface + * @tc.size MEDIUM(中型) + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_dirent_is_symbolic_link_001', 0, async function () { + let dpath = await nextFileName('fileio_test_dirent_is_symbolic_link_001') + 'd'; + let fpath = dpath + '/f1'; + let dd; + + try { + expect(fileio.mkdirSync(dpath) == null).assertTrue(); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + dd = fileio.opendirSync(dpath); + expect(dd !== null).assertTrue(); + let dirent = dd.readSync(); + expect(dirent !== null).assertTrue(); + dirent.isSymbolicLink(-1); + expect(null).assertFail(); + } catch (e) { + expect(dd.closeSync() == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue() + expect(fileio.rmdirSync(dpath) == null).assertTrue(); + } + }); +});} diff --git a/storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/class_randomAccessFile/close.test.js b/storage/storagefileiojstest/src/main/js/test/module_fileio/class_randomAccessFile/close.test.js similarity index 95% rename from storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/class_randomAccessFile/close.test.js rename to storage/storagefileiojstest/src/main/js/test/module_fileio/class_randomAccessFile/close.test.js index dd62e3f358f61d5757834a498484b48688e567f8..b3d8a5fb5a029b816fe52611543c4db594c5c9b7 100644 --- a/storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/class_randomAccessFile/close.test.js +++ b/storage/storagefileiojstest/src/main/js/test/module_fileio/class_randomAccessFile/close.test.js @@ -1,70 +1,70 @@ -/* - * Copyright (C) 2023 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 { - fileio, nextFileName, - describe, it, expect -} from '../../Common'; - -export default function fileioRandomAccessFileClose() { -describe('fileio_randomAccessFile_close', function () { - - /** - * @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_CLOSE_SYNC_0000 - * @tc.name fileio_randomaccessfile_close_sync_000 - * @tc.desc Test closeSync() interface. Close the RandomAccessFile object. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_randomaccessfile_close_sync_000', 0, async function () { - let fpath = await nextFileName('fileio_randomaccessfile_close_sync_000'); - - try { - let randomaccessfile = fileio.createRandomAccessFileSync(fpath, 0, 0o102); - randomaccessfile.closeSync(); - fileio.unlinkSync(fpath); - } catch(err) { - console.info('fileio_randomaccessfile_close_sync_000 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_CLOSE_SYNC_0100 - * @tc.name fileio_randomaccessfile_close_sync_001 - * @tc.desc Test closeSync() interface. Parameter mismatch. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_randomaccessfile_close_sync_001', 0, async function () { - let fpath = await nextFileName('fileio_randomaccessfile_close_sync_001'); - let randomaccessfile = fileio.createRandomAccessFileSync(fpath, 0, 0o102); - - try { - randomaccessfile.closeSync(1); - expect(false).assertTrue(); - } catch(err) { - console.info('fileio_randomaccessfile_close_sync_001 has failed for ' + err); - expect(err.message == "Number of arguments unmatched").assertTrue(); - randomaccessfile.closeSync(); - fileio.unlinkSync(fpath); - } - }); -}) +/* + * 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. + */ + +import { + fileio, nextFileName, + describe, it, expect +} from '../../Common'; + +export default function fileioRandomAccessFileClose() { +describe('fileio_randomAccessFile_close', function () { + + /** + * @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_CLOSE_SYNC_0000 + * @tc.name fileio_randomaccessfile_close_sync_000 + * @tc.desc Test closeSync() interface. Close the RandomAccessFile object. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_randomaccessfile_close_sync_000', 0, async function () { + let fpath = await nextFileName('fileio_randomaccessfile_close_sync_000'); + + try { + let randomaccessfile = fileio.createRandomAccessFileSync(fpath, 0, 0o102); + randomaccessfile.closeSync(); + fileio.unlinkSync(fpath); + } catch(err) { + console.info('fileio_randomaccessfile_close_sync_000 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_CLOSE_SYNC_0100 + * @tc.name fileio_randomaccessfile_close_sync_001 + * @tc.desc Test closeSync() interface. Parameter mismatch. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_randomaccessfile_close_sync_001', 0, async function () { + let fpath = await nextFileName('fileio_randomaccessfile_close_sync_001'); + let randomaccessfile = fileio.createRandomAccessFileSync(fpath, 0, 0o102); + + try { + randomaccessfile.closeSync(1); + expect(false).assertTrue(); + } catch(err) { + console.info('fileio_randomaccessfile_close_sync_001 has failed for ' + err); + expect(err.message == "Number of arguments unmatched").assertTrue(); + randomaccessfile.closeSync(); + fileio.unlinkSync(fpath); + } + }); +}) } \ No newline at end of file diff --git a/storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/class_randomAccessFile/read.test.js b/storage/storagefileiojstest/src/main/js/test/module_fileio/class_randomAccessFile/read.test.js similarity index 97% rename from storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/class_randomAccessFile/read.test.js rename to storage/storagefileiojstest/src/main/js/test/module_fileio/class_randomAccessFile/read.test.js index 8ba53a704f4f0ee884a6e90e7cf561e98d865123..9edd5a0a37bdbade4fb42b793c593033de8f8324 100644 --- a/storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/class_randomAccessFile/read.test.js +++ b/storage/storagefileiojstest/src/main/js/test/module_fileio/class_randomAccessFile/read.test.js @@ -1,777 +1,777 @@ -/* - * Copyright (C) 2023 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 { - fileio, FILE_CONTENT, prepareFile, nextFileName, - describe, it, expect, -} from '../../Common'; - -export default function fileioRandomAccessFileRead() { -describe('fileio_randomAccessFile_read', function () { - - /** - * @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_READ_SYNC_0000 - * @tc.name fileio_randomaccessfile_read_sync_000 - * @tc.desc Test readSync() interface. Test to read data synchronously. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_randomaccessfile_read_sync_000', 0, async function () { - let fpath = await nextFileName('fileio_randomaccessfile_read_sync_000'); - - try { - let fd = fileio.openSync(fpath, 0o102, 0o666); - let randomaccessfile = fileio.createRandomAccessFileSync(fd, 0); - let length = 4096; - let num = randomaccessfile.writeSync(new ArrayBuffer(length)); - expect(num == length).assertTrue(); - randomaccessfile.setFilePointerSync(0); - let number = randomaccessfile.readSync(new ArrayBuffer(length)); - expect(number == length).assertTrue(); - randomaccessfile.closeSync(); - fileio.unlinkSync(fpath); - } catch (err) { - console.info('fileio_randomaccessfile_read_sync_000 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_READ_SYNC_0100 - * @tc.name fileio_randomaccessfile_read_sync_001 - * @tc.desc Test readSync() interface. When the position is 1. Test to read data synchronously. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_randomaccessfile_read_sync_001', 0, async function () { - let fpath = await nextFileName('fileio_randomaccessfile_read_sync_001'); - - try { - let randomaccessfile = fileio.createRandomAccessFileSync(fpath, 0, 0o102); - let length = 20; - let num = randomaccessfile.writeSync(new ArrayBuffer(length)); - expect(num == length).assertTrue(); - randomaccessfile.setFilePointerSync(0); - let number = randomaccessfile.readSync(new ArrayBuffer(length), { position: 1 }); - expect(number == length - 1).assertTrue(); - randomaccessfile.closeSync(); - fileio.unlinkSync(fpath); - } catch (err) { - console.info('fileio_randomaccessfile_read_sync_001 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_READ_SYNC_0200 - * @tc.name fileio_randomaccessfile_read_sync_002 - * @tc.desc Test readSync() interface. When the offset is 1. Test to read data synchronously. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_randomaccessfile_read_sync_002', 0, async function () { - let fpath = await nextFileName('fileio_randomaccessfile_read_sync_002'); - - try { - let randomaccessfile = fileio.createRandomAccessFileSync(fpath, 0, 0o102); - let length = 20; - let num = randomaccessfile.writeSync(new ArrayBuffer(length)); - expect(num == length).assertTrue(); - randomaccessfile.setFilePointerSync(0); - let number = randomaccessfile.readSync(new ArrayBuffer(length), { offset: 1 }); - expect(number == length - 1).assertTrue(); - randomaccessfile.closeSync(); - fileio.unlinkSync(fpath); - } catch (err) { - console.info('fileio_randomaccessfile_read_sync_002 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_READ_SYNC_0300 - * @tc.name fileio_randomaccessfile_read_sync_003 - * @tc.desc Test readSync() interface. When the offset is 1 and the length is 5. Test to read data synchronously. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_randomaccessfile_read_sync_003', 0, async function () { - let fpath = await nextFileName('fileio_randomaccessfile_read_sync_003'); - - try { - let randomaccessfile = fileio.createRandomAccessFileSync(fpath, 0, 0o102); - let length = 20; - let num = randomaccessfile.writeSync(new ArrayBuffer(length)); - expect(num == length).assertTrue(); - randomaccessfile.setFilePointerSync(0); - let number = randomaccessfile.readSync(new ArrayBuffer(length), { offset: 1, length: 5 }); - expect(number == 5).assertTrue(); - randomaccessfile.closeSync(); - fileio.unlinkSync(fpath); - } catch (err) { - console.info('fileio_randomaccessfile_read_sync_003 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_READ_SYNC_0400 - * @tc.name fileio_randomaccessfile_read_sync_004 - * @tc.desc Test readSync() interface. When offset equals buffer length. Test to read data synchronously. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_randomaccessfile_read_sync_004', 0, async function () { - let fpath = await nextFileName('fileio_randomaccessfile_read_sync_004'); - - try { - let randomaccessfile = fileio.createRandomAccessFileSync(fpath, 0, 0o102); - let length = 4096; - let num = randomaccessfile.writeSync(new ArrayBuffer(length)); - expect(num == length).assertTrue(); - randomaccessfile.setFilePointerSync(0); - let number = randomaccessfile.readSync(new ArrayBuffer(length), { offset: length }); - expect(number == 0).assertTrue(); - randomaccessfile.closeSync(); - fileio.unlinkSync(fpath); - } catch (err) { - console.info('fileio_randomaccessfile_read_sync_004 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_READ_SYNC_0500 - * @tc.name fileio_randomaccessfile_read_sync_005 - * @tc.desc Test readSync() interface. When the offset is 1 and the position is 6. Test to read data synchronously. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_randomaccessfile_read_sync_005', 0, async function () { - let fpath = await nextFileName('fileio_randomaccessfile_read_sync_005'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let randomaccessfile = fileio.createRandomAccessFileSync(fpath, 0, 0o102); - let length = 20; - let number = randomaccessfile.readSync(new ArrayBuffer(length), { offset: 1, position: 6 }); - expect(number == FILE_CONTENT.length - 6).assertTrue(); - randomaccessfile.closeSync(); - fileio.unlinkSync(fpath); - } catch (err) { - console.info('fileio_randomaccessfile_read_sync_005 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_READ_SYNC_0600 - * @tc.name fileio_randomaccessfile_read_sync_006 - * @tc.desc Test readSync() interface. When the offset is negative. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_randomaccessfile_read_sync_006', 0, async function () { - let fpath = await nextFileName('fileio_randomaccessfile_read_sync_006'); - let fd = fileio.openSync(fpath, 0o102, 0o666); - let randomaccessfile = fileio.createRandomAccessFileSync(fd, 0); - - try { - randomaccessfile.readSync(new ArrayBuffer(4096), { offset: -1 }); - expect(false).assertTrue(); - } catch (err) { - console.info('fileio_randomaccessfile_read_sync_006 has failed for ' + err); - expect(err.message == "Invalid buffer/options").assertTrue(); - randomaccessfile.closeSync(); - fileio.unlinkSync(fpath); - } - }); - - /** - * @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_READ_SYNC_0700 - * @tc.name fileio_randomaccessfile_read_sync_007 - * @tc.desc Test readSync() interface. When offset+length>buffer.size. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_randomaccessfile_read_sync_007', 0, async function () { - let fpath = await nextFileName('fileio_randomaccessfile_read_sync_007'); - let randomaccessfile = fileio.createRandomAccessFileSync(fpath, 0, 0o102); - - try { - randomaccessfile.readSync(new ArrayBuffer(4096), { offset: 1, length: 4096 }); - expect(false).assertTrue(); - } catch (err) { - console.info('fileio_randomaccessfile_read_sync_007 has failed for ' + err); - expect(err.message == "Invalid buffer/options").assertTrue(); - randomaccessfile.closeSync(); - fileio.unlinkSync(fpath); - } - }); - - /** - * @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_READ_SYNC_0800 - * @tc.name fileio_randomaccessfile_read_sync_008 - * @tc.desc Test readSync() interface. When the offset is greater than the buffer length. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_randomaccessfile_read_sync_008', 0, async function () { - let fpath = await nextFileName('fileio_randomaccessfile_read_sync_008'); - let randomaccessfile = fileio.createRandomAccessFileSync(fpath, 0, 0o102); - - try { - let length = 4096; - randomaccessfile.readSync(new ArrayBuffer(length), { offset: length + 1 }); - expect(false).assertTrue(); - } catch (err) { - console.info('fileio_randomaccessfile_read_sync_008 has failed for ' + err); - expect(err.message == "Invalid buffer/options").assertTrue(); - randomaccessfile.closeSync(); - fileio.unlinkSync(fpath); - } - }); - - /** - * @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_READ_SYNC_0900 - * @tc.name fileio_randomaccessfile_read_sync_009 - * @tc.desc Test readSync() interface. When the length is greater than the buffer length. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_randomaccessfile_read_sync_009', 0, async function () { - let fpath = await nextFileName('fileio_randomaccessfile_read_sync_009'); - let randomaccessfile = fileio.createRandomAccessFileSync(fpath, 0, 0o102); - - try { - let length = 4096; - randomaccessfile.readSync(new ArrayBuffer(length), { length: length + 1 }); - expect(false).assertTrue(); - } catch (err) { - console.info('fileio_randomaccessfile_read_sync_009 has failed for ' + err); - expect(err.message == "Invalid buffer/options").assertTrue(); - randomaccessfile.closeSync(); - fileio.unlinkSync(fpath); - } - }); - - /** - * @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_READ_SYNC_1000 - * @tc.name fileio_randomaccessfile_read_sync_010 - * @tc.desc Test readSync() interface. The "length" of option must > 0. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_randomaccessfile_read_sync_010', 0, async function () { - let fpath = await nextFileName('fileio_randomaccessfile_read_sync_010'); - let randomaccessfile; - - try { - randomaccessfile = fileio.createRandomAccessFileSync(fpath, 0, 0o102); - let length = 4096; - let num = randomaccessfile.writeSync(new ArrayBuffer(length)); - expect(num == length).assertTrue(); - randomaccessfile.setFilePointerSync(0); - randomaccessfile.readSync(new ArrayBuffer(16), { offset: 13, length: -1 }); - expect(false).assertTrue(); - } catch (err) { - randomaccessfile.closeSync(); - fileio.unlinkSync(fpath); - console.info('fileio_randomaccessfile_read_sync_010 has failed for ' + err); - expect(err.message == "Invalid buffer/options").assertTrue(); - } - }); - - /** - * @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_READ_SYNC_1100 - * @tc.name fileio_randomaccessfile_read_sync_011 - * @tc.desc Test readSync() interface. When there are no parameters. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_randomaccessfile_read_sync_011', 0, async function () { - let fpath = await nextFileName('fileio_randomaccessfile_read_sync_011'); - let randomaccessfile = fileio.createRandomAccessFileSync(fpath, 0, 0o102); - - try { - randomaccessfile.readSync(); - expect(false).assertTrue(); - } catch (err) { - console.info('fileio_randomaccessfile_read_sync_011 has failed for ' + err); - expect(err.message == "Number of arguments unmatched").assertTrue(); - randomaccessfile.closeSync(); - fileio.unlinkSync(fpath); - } - }); - - /** - * @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_READ_SYNC_1200 - * @tc.name fileio_randomaccessfile_read_sync_012 - * @tc.desc Test readSync() interface. When the position is negative. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_randomaccessfile_read_sync_012', 0, async function () { - let fpath = await nextFileName('fileio_randomaccessfile_read_sync_012'); - let randomaccessfile = fileio.createRandomAccessFileSync(fpath, 0, 0o102); - - try { - randomaccessfile.readSync(new ArrayBuffer(4096), { position: -1 }); - expect(false).assertTrue(); - } catch (err) { - console.info('fileio_randomaccessfile_read_sync_012 has failed for ' + err); - expect(err.message == "Invalid buffer/options").assertTrue(); - randomaccessfile.closeSync(); - fileio.unlinkSync(fpath); - } - }); - - /** - * @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_READ_SYNC_1300 - * @tc.name fileio_randomaccessfile_read_sync_013 - * @tc.desc Test readSync() interface. When the parameter type is wrong. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_randomaccessfile_read_sync_013', 0, async function () { - let fpath = await nextFileName('fileio_randomaccessfile_read_sync_013'); - let randomaccessfile = fileio.createRandomAccessFileSync(fpath, 0, 0o102); - - try { - randomaccessfile.readSync(''); - expect(false).assertTrue(); - } catch (err) { - console.info('fileio_randomaccessfile_read_sync_013 has failed for ' + err); - expect(err.message == "Invalid buffer/options").assertTrue(); - randomaccessfile.closeSync(); - fileio.unlinkSync(fpath); - } - }); - - /** - * @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_READ_ASYNC_0000 - * @tc.name fileio_randomaccessfile_read_async_000 - * @tc.desc Test read() interface. return in callback mode. Test to read data asynchronously. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_randomaccessfile_read_async_000', 0, async function (done) { - let fpath = await nextFileName('fileio_randomaccessfile_read_async_000'); - - try { - let randomaccessfile = await fileio.createRandomAccessFile(fpath, 0, 0o102); - let length = 4096; - let num = await randomaccessfile.write(new ArrayBuffer(length)); - expect(num == length).assertTrue(); - randomaccessfile.setFilePointerSync(0); - randomaccessfile.read(new ArrayBuffer(length), function (err, readOut) { - expect(readOut.bytesRead == length).assertTrue(); - randomaccessfile.closeSync(); - fileio.unlinkSync(fpath); - done(); - }); - } catch (err) { - console.info('fileio_randomaccessfile_read_async_000 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_READ_ASYNC_0100 - * @tc.name fileio_randomaccessfile_read_async_001 - * @tc.desc Test read() interface. When the position is 1. Test to read data asynchronously. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_randomaccessfile_read_async_001', 0, async function (done) { - let fpath = await nextFileName('fileio_randomaccessfile_read_async_001'); - - try { - fileio.createRandomAccessFile(fpath, 0, 0o102, async function (err, randomaccessfile) { - let length = 20; - let num = await randomaccessfile.write(new ArrayBuffer(length)); - expect(num == length).assertTrue(); - randomaccessfile.setFilePointerSync(0); - let readOut = await randomaccessfile.read(new ArrayBuffer(length), { position: 1 }); - expect(readOut.bytesRead == length - 1).assertTrue(); - randomaccessfile.closeSync(); - fileio.unlinkSync(fpath); - done(); - }); - } catch (err) { - console.info('fileio_randomaccessfile_read_async_001 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_READ_ASYNC_0200 - * @tc.name fileio_randomaccessfile_read_async_002 - * @tc.desc Test read() interface. When the offset is 1. Test to read data asynchronously. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_randomaccessfile_read_async_002', 0, async function (done) { - let fpath = await nextFileName('fileio_randomaccessfile_read_async_002'); - - try { - let fd = fileio.openSync(fpath, 0o102, 0o666); - let randomaccessfile = await fileio.createRandomAccessFile(fd, 0); - let length = 20; - let num = await randomaccessfile.write(new ArrayBuffer(length)); - expect(num == length).assertTrue(); - randomaccessfile.setFilePointerSync(0); - let readOut = await randomaccessfile.read(new ArrayBuffer(length), { offset: 1 }); - expect(readOut.bytesRead == length - 1).assertTrue(); - expect(readOut.offset == 1).assertTrue(); - randomaccessfile.closeSync(); - fileio.unlinkSync(fpath); - done(); - } catch (err) { - console.info('fileio_randomaccessfile_read_async_002 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_READ_ASYNC_0300 - * @tc.name fileio_randomaccessfile_read_async_003 - * @tc.desc Test read() interface. When the offset is 1 and the length is 5. Test to read data asynchronously. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_randomaccessfile_read_async_003', 0, async function (done) { - let fpath = await nextFileName('fileio_randomaccessfile_read_async_003'); - - try { - let randomaccessfile = await fileio.createRandomAccessFile(fpath, 0, 0o102); - let length = 20; - let num = await randomaccessfile.write(new ArrayBuffer(length)); - expect(num == length).assertTrue(); - randomaccessfile.setFilePointerSync(0); - randomaccessfile.read(new ArrayBuffer(length), { offset: 1, length: 5 }, function (err, readOut) { - expect(readOut.bytesRead == 5).assertTrue(); - expect(readOut.offset == 1).assertTrue(); - randomaccessfile.closeSync(); - fileio.unlinkSync(fpath); - done(); - }); - } catch (err) { - console.info('fileio_randomaccessfile_read_async_003 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_READ_ASYNC_0400 - * @tc.name fileio_randomaccessfile_read_async_004 - * @tc.desc Test read() interface. When offset equals buffer length. Test to read data asynchronously. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_randomaccessfile_read_async_004', 0, async function (done) { - let fpath = await nextFileName('fileio_randomaccessfile_read_async_004'); - - try { - let randomaccessfile = await fileio.createRandomAccessFile(fpath, 0, 0o102); - let length = 4096; - let num = await randomaccessfile.write(new ArrayBuffer(length)); - expect(num == length).assertTrue(); - randomaccessfile.setFilePointerSync(0); - let readOut = await randomaccessfile.read(new ArrayBuffer(length), { offset: length }); - expect(readOut.bytesRead == 0).assertTrue(); - expect(readOut.offset == 4096).assertTrue(); - randomaccessfile.closeSync(); - fileio.unlinkSync(fpath); - done(); - } catch (err) { - console.info('fileio_randomaccessfile_read_async_004 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_READ_ASYNC_0500 - * @tc.name fileio_randomaccessfile_read_async_005 - * @tc.desc Test read() interface. When the offset is 1 and the position is 6. Test to read data asynchronously. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_randomaccessfile_read_async_005', 0, async function (done) { - let fpath = await nextFileName('fileio_randomaccessfile_read_async_005'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let randomaccessfile = await fileio.createRandomAccessFile(fpath, 0, 0o102); - let length = 20; - let readOut = await randomaccessfile.read(new ArrayBuffer(length), { offset: 1, position: 6 }); - expect(readOut.bytesRead == FILE_CONTENT.length - 6).assertTrue(); - expect(readOut.offset == 1).assertTrue(); - let start = readOut.offset; - let end = readOut.offset + readOut.bytesRead; - let result = String.fromCharCode.apply(null, new Uint8Array(readOut.buffer.slice(start, end))); - expect(result == "world").assertTrue(); - randomaccessfile.closeSync(); - fileio.unlinkSync(fpath); - done(); - } catch (err) { - console.info('fileio_randomaccessfile_read_async_005 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_READ_ASYNC_0600 - * @tc.name fileio_randomaccessfile_read_async_006 - * @tc.desc Test read() interface. When the offset is negative. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_randomaccessfile_read_async_006', 0, async function (done) { - let fpath = await nextFileName('fileio_randomaccessfile_read_async_006'); - let randomaccessfile = await fileio.createRandomAccessFile(fpath, 0, 0o102); - - try { - await randomaccessfile.read(new ArrayBuffer(4096), { offset: -1 }); - } catch (err) { - console.info('fileio_randomaccessfile_read_async_006 has failed for ' + err); - expect(err.message == "Invalid buffer/options").assertTrue(); - randomaccessfile.closeSync(); - fileio.unlinkSync(fpath); - done(); - } - }); - - /** - * @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_READ_ASYNC_0700 - * @tc.name fileio_randomaccessfile_read_async_007 - * @tc.desc Test read() interface. When offset+length>buffer.size. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_randomaccessfile_read_async_007', 0, async function (done) { - let fpath = await nextFileName('fileio_randomaccessfile_read_async_007'); - let randomaccessfile = await fileio.createRandomAccessFile(fpath, 0, 0o102); - - try { - await randomaccessfile.read(new ArrayBuffer(4096), { offset: 1, length: 4096 }); - } catch (err) { - console.info('fileio_randomaccessfile_read_async_007 has failed for ' + err); - expect(err.message == "Invalid buffer/options").assertTrue(); - randomaccessfile.closeSync(); - fileio.unlinkSync(fpath); - done(); - } - }); - - /** - * @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_READ_ASYNC_0800 - * @tc.name fileio_randomaccessfile_read_async_008 - * @tc.desc Test read() interface. When the offset is greater than the buffer length. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_randomaccessfile_read_async_008', 0, async function (done) { - let fpath = await nextFileName('fileio_randomaccessfile_read_async_008'); - let fd = fileio.openSync(fpath, 0o102, 0o666); - let randomaccessfile = await fileio.createRandomAccessFile(fd, 0); - - try { - let length = 4096; - randomaccessfile.read(new ArrayBuffer(length), { offset: length + 1 }, function (err) { - }); - } catch (err) { - console.info('fileio_randomaccessfile_read_async_008 has failed for ' + err); - expect(err.message == "Invalid buffer/options").assertTrue(); - randomaccessfile.closeSync(); - fileio.unlinkSync(fpath); - done(); - } - }); - - /** - * @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_READ_ASYNC_0900 - * @tc.name fileio_randomaccessfile_read_async_009 - * @tc.desc Test read() interface. When the length is greater than the buffer length. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_randomaccessfile_read_async_009', 0, async function (done) { - let fpath = await nextFileName('fileio_randomaccessfile_read_async_009'); - let randomaccessfile = await fileio.createRandomAccessFile(fpath, 0, 0o102); - - try { - let length = 4096; - await randomaccessfile.read(new ArrayBuffer(length), { length: length + 1 }); - } catch (err) { - console.info('fileio_randomaccessfile_read_async_009 has failed for ' + err); - expect(err.message == "Invalid buffer/options").assertTrue(); - randomaccessfile.closeSync(); - fileio.unlinkSync(fpath); - done(); - } - }); - - /** - * @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_READ_ASYNC_1000 - * @tc.name fileio_randomaccessfile_read_async_010 - * @tc.desc Test read() interface. The "length" of option must > 0. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_randomaccessfile_read_async_010', 0, async function (done) { - let fpath = await nextFileName('fileio_randomaccessfile_read_async_010'); - let randomaccessfile; - - try { - randomaccessfile = await fileio.createRandomAccessFile(fpath, 0, 0o102); - let length = 4096; - let num = randomaccessfile.writeSync(new ArrayBuffer(length)); - expect(num == length).assertTrue(); - randomaccessfile.setFilePointerSync(0); - await randomaccessfile.read(new ArrayBuffer(16), { offset: 13, length: -1 }); - expect(false).assertTrue(); - } catch (err) { - randomaccessfile.closeSync(); - fileio.unlinkSync(fpath); - console.info('fileio_randomaccessfile_read_async_010 has failed for ' + err); - expect(err.message == "Invalid buffer/options").assertTrue(); - done(); - } - }); - - /** - * @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_READ_ASYNC_1100 - * @tc.name fileio_randomaccessfile_read_async_011 - * @tc.desc Test read() interface. When there are no parameters. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_randomaccessfile_read_async_011', 0, async function (done) { - let fpath = await nextFileName('fileio_randomaccessfile_read_async_011'); - let randomaccessfile = await fileio.createRandomAccessFile(fpath, 0, 0o102); - - try { - await randomaccessfile.read(); - } catch (err) { - console.info('fileio_randomaccessfile_read_async_011 has failed for ' + err); - expect(err.message == "Number of arguments unmatched").assertTrue(); - randomaccessfile.closeSync(); - fileio.unlinkSync(fpath); - done(); - } - }); - - /** - * @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_READ_ASYNC_1200 - * @tc.name fileio_randomaccessfile_read_async_012 - * @tc.desc Test read() interface. When the position is negative. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_randomaccessfile_read_async_012', 0, async function (done) { - let fpath = await nextFileName('fileio_randomaccessfile_read_async_012'); - let randomaccessfile = await fileio.createRandomAccessFile(fpath, 0, 0o102); - - try { - await randomaccessfile.read(new ArrayBuffer(4096), { position: -1 }); - } catch (err) { - console.info('fileio_randomaccessfile_read_async_012 has failed for ' + err); - expect(err.message == "Invalid buffer/options").assertTrue(); - randomaccessfile.closeSync(); - fileio.unlinkSync(fpath); - done(); - } - }); - - /** - * @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_READ_ASYNC_1300 - * @tc.name fileio_randomaccessfile_read_async_013 - * @tc.desc Test read() interface. When the parameter type is wrong. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_randomaccessfile_read_async_013', 0, async function (done) { - let fpath = await nextFileName('fileio_randomaccessfile_read_async_013'); - let randomaccessfile = await fileio.createRandomAccessFile(fpath, 0, 0o102); - - try { - await randomaccessfile.read(''); - } catch (err) { - console.info('fileio_randomaccessfile_read_async_013 has failed for ' + err); - expect(err.message == "Invalid buffer/options").assertTrue(); - randomaccessfile.closeSync(); - fileio.unlinkSync(fpath); - done() - } - }); -}) +/* + * 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. + */ + +import { + fileio, FILE_CONTENT, prepareFile, nextFileName, + describe, it, expect, +} from '../../Common'; + +export default function fileioRandomAccessFileRead() { +describe('fileio_randomAccessFile_read', function () { + + /** + * @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_READ_SYNC_0000 + * @tc.name fileio_randomaccessfile_read_sync_000 + * @tc.desc Test readSync() interface. Test to read data synchronously. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_randomaccessfile_read_sync_000', 0, async function () { + let fpath = await nextFileName('fileio_randomaccessfile_read_sync_000'); + + try { + let fd = fileio.openSync(fpath, 0o102, 0o666); + let randomaccessfile = fileio.createRandomAccessFileSync(fd, 0); + let length = 4096; + let num = randomaccessfile.writeSync(new ArrayBuffer(length)); + expect(num == length).assertTrue(); + randomaccessfile.setFilePointerSync(0); + let number = randomaccessfile.readSync(new ArrayBuffer(length)); + expect(number == length).assertTrue(); + randomaccessfile.closeSync(); + fileio.unlinkSync(fpath); + } catch (err) { + console.info('fileio_randomaccessfile_read_sync_000 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_READ_SYNC_0100 + * @tc.name fileio_randomaccessfile_read_sync_001 + * @tc.desc Test readSync() interface. When the position is 1. Test to read data synchronously. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_randomaccessfile_read_sync_001', 0, async function () { + let fpath = await nextFileName('fileio_randomaccessfile_read_sync_001'); + + try { + let randomaccessfile = fileio.createRandomAccessFileSync(fpath, 0, 0o102); + let length = 20; + let num = randomaccessfile.writeSync(new ArrayBuffer(length)); + expect(num == length).assertTrue(); + randomaccessfile.setFilePointerSync(0); + let number = randomaccessfile.readSync(new ArrayBuffer(length), { position: 1 }); + expect(number == length - 1).assertTrue(); + randomaccessfile.closeSync(); + fileio.unlinkSync(fpath); + } catch (err) { + console.info('fileio_randomaccessfile_read_sync_001 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_READ_SYNC_0200 + * @tc.name fileio_randomaccessfile_read_sync_002 + * @tc.desc Test readSync() interface. When the offset is 1. Test to read data synchronously. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_randomaccessfile_read_sync_002', 0, async function () { + let fpath = await nextFileName('fileio_randomaccessfile_read_sync_002'); + + try { + let randomaccessfile = fileio.createRandomAccessFileSync(fpath, 0, 0o102); + let length = 20; + let num = randomaccessfile.writeSync(new ArrayBuffer(length)); + expect(num == length).assertTrue(); + randomaccessfile.setFilePointerSync(0); + let number = randomaccessfile.readSync(new ArrayBuffer(length), { offset: 1 }); + expect(number == length - 1).assertTrue(); + randomaccessfile.closeSync(); + fileio.unlinkSync(fpath); + } catch (err) { + console.info('fileio_randomaccessfile_read_sync_002 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_READ_SYNC_0300 + * @tc.name fileio_randomaccessfile_read_sync_003 + * @tc.desc Test readSync() interface. When the offset is 1 and the length is 5. Test to read data synchronously. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_randomaccessfile_read_sync_003', 0, async function () { + let fpath = await nextFileName('fileio_randomaccessfile_read_sync_003'); + + try { + let randomaccessfile = fileio.createRandomAccessFileSync(fpath, 0, 0o102); + let length = 20; + let num = randomaccessfile.writeSync(new ArrayBuffer(length)); + expect(num == length).assertTrue(); + randomaccessfile.setFilePointerSync(0); + let number = randomaccessfile.readSync(new ArrayBuffer(length), { offset: 1, length: 5 }); + expect(number == 5).assertTrue(); + randomaccessfile.closeSync(); + fileio.unlinkSync(fpath); + } catch (err) { + console.info('fileio_randomaccessfile_read_sync_003 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_READ_SYNC_0400 + * @tc.name fileio_randomaccessfile_read_sync_004 + * @tc.desc Test readSync() interface. When offset equals buffer length. Test to read data synchronously. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_randomaccessfile_read_sync_004', 0, async function () { + let fpath = await nextFileName('fileio_randomaccessfile_read_sync_004'); + + try { + let randomaccessfile = fileio.createRandomAccessFileSync(fpath, 0, 0o102); + let length = 4096; + let num = randomaccessfile.writeSync(new ArrayBuffer(length)); + expect(num == length).assertTrue(); + randomaccessfile.setFilePointerSync(0); + let number = randomaccessfile.readSync(new ArrayBuffer(length), { offset: length }); + expect(number == 0).assertTrue(); + randomaccessfile.closeSync(); + fileio.unlinkSync(fpath); + } catch (err) { + console.info('fileio_randomaccessfile_read_sync_004 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_READ_SYNC_0500 + * @tc.name fileio_randomaccessfile_read_sync_005 + * @tc.desc Test readSync() interface. When the offset is 1 and the position is 6. Test to read data synchronously. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_randomaccessfile_read_sync_005', 0, async function () { + let fpath = await nextFileName('fileio_randomaccessfile_read_sync_005'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let randomaccessfile = fileio.createRandomAccessFileSync(fpath, 0, 0o102); + let length = 20; + let number = randomaccessfile.readSync(new ArrayBuffer(length), { offset: 1, position: 6 }); + expect(number == FILE_CONTENT.length - 6).assertTrue(); + randomaccessfile.closeSync(); + fileio.unlinkSync(fpath); + } catch (err) { + console.info('fileio_randomaccessfile_read_sync_005 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_READ_SYNC_0600 + * @tc.name fileio_randomaccessfile_read_sync_006 + * @tc.desc Test readSync() interface. When the offset is negative. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_randomaccessfile_read_sync_006', 0, async function () { + let fpath = await nextFileName('fileio_randomaccessfile_read_sync_006'); + let fd = fileio.openSync(fpath, 0o102, 0o666); + let randomaccessfile = fileio.createRandomAccessFileSync(fd, 0); + + try { + randomaccessfile.readSync(new ArrayBuffer(4096), { offset: -1 }); + expect(false).assertTrue(); + } catch (err) { + console.info('fileio_randomaccessfile_read_sync_006 has failed for ' + err); + expect(err.message == "Invalid buffer/options").assertTrue(); + randomaccessfile.closeSync(); + fileio.unlinkSync(fpath); + } + }); + + /** + * @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_READ_SYNC_0700 + * @tc.name fileio_randomaccessfile_read_sync_007 + * @tc.desc Test readSync() interface. When offset+length>buffer.size. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_randomaccessfile_read_sync_007', 0, async function () { + let fpath = await nextFileName('fileio_randomaccessfile_read_sync_007'); + let randomaccessfile = fileio.createRandomAccessFileSync(fpath, 0, 0o102); + + try { + randomaccessfile.readSync(new ArrayBuffer(4096), { offset: 1, length: 4096 }); + expect(false).assertTrue(); + } catch (err) { + console.info('fileio_randomaccessfile_read_sync_007 has failed for ' + err); + expect(err.message == "Invalid buffer/options").assertTrue(); + randomaccessfile.closeSync(); + fileio.unlinkSync(fpath); + } + }); + + /** + * @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_READ_SYNC_0800 + * @tc.name fileio_randomaccessfile_read_sync_008 + * @tc.desc Test readSync() interface. When the offset is greater than the buffer length. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_randomaccessfile_read_sync_008', 0, async function () { + let fpath = await nextFileName('fileio_randomaccessfile_read_sync_008'); + let randomaccessfile = fileio.createRandomAccessFileSync(fpath, 0, 0o102); + + try { + let length = 4096; + randomaccessfile.readSync(new ArrayBuffer(length), { offset: length + 1 }); + expect(false).assertTrue(); + } catch (err) { + console.info('fileio_randomaccessfile_read_sync_008 has failed for ' + err); + expect(err.message == "Invalid buffer/options").assertTrue(); + randomaccessfile.closeSync(); + fileio.unlinkSync(fpath); + } + }); + + /** + * @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_READ_SYNC_0900 + * @tc.name fileio_randomaccessfile_read_sync_009 + * @tc.desc Test readSync() interface. When the length is greater than the buffer length. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_randomaccessfile_read_sync_009', 0, async function () { + let fpath = await nextFileName('fileio_randomaccessfile_read_sync_009'); + let randomaccessfile = fileio.createRandomAccessFileSync(fpath, 0, 0o102); + + try { + let length = 4096; + randomaccessfile.readSync(new ArrayBuffer(length), { length: length + 1 }); + expect(false).assertTrue(); + } catch (err) { + console.info('fileio_randomaccessfile_read_sync_009 has failed for ' + err); + expect(err.message == "Invalid buffer/options").assertTrue(); + randomaccessfile.closeSync(); + fileio.unlinkSync(fpath); + } + }); + + /** + * @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_READ_SYNC_1000 + * @tc.name fileio_randomaccessfile_read_sync_010 + * @tc.desc Test readSync() interface. The "length" of option must > 0. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_randomaccessfile_read_sync_010', 0, async function () { + let fpath = await nextFileName('fileio_randomaccessfile_read_sync_010'); + let randomaccessfile; + + try { + randomaccessfile = fileio.createRandomAccessFileSync(fpath, 0, 0o102); + let length = 4096; + let num = randomaccessfile.writeSync(new ArrayBuffer(length)); + expect(num == length).assertTrue(); + randomaccessfile.setFilePointerSync(0); + randomaccessfile.readSync(new ArrayBuffer(16), { offset: 13, length: -1 }); + expect(false).assertTrue(); + } catch (err) { + randomaccessfile.closeSync(); + fileio.unlinkSync(fpath); + console.info('fileio_randomaccessfile_read_sync_010 has failed for ' + err); + expect(err.message == "Invalid buffer/options").assertTrue(); + } + }); + + /** + * @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_READ_SYNC_1100 + * @tc.name fileio_randomaccessfile_read_sync_011 + * @tc.desc Test readSync() interface. When there are no parameters. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_randomaccessfile_read_sync_011', 0, async function () { + let fpath = await nextFileName('fileio_randomaccessfile_read_sync_011'); + let randomaccessfile = fileio.createRandomAccessFileSync(fpath, 0, 0o102); + + try { + randomaccessfile.readSync(); + expect(false).assertTrue(); + } catch (err) { + console.info('fileio_randomaccessfile_read_sync_011 has failed for ' + err); + expect(err.message == "Number of arguments unmatched").assertTrue(); + randomaccessfile.closeSync(); + fileio.unlinkSync(fpath); + } + }); + + /** + * @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_READ_SYNC_1200 + * @tc.name fileio_randomaccessfile_read_sync_012 + * @tc.desc Test readSync() interface. When the position is negative. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_randomaccessfile_read_sync_012', 0, async function () { + let fpath = await nextFileName('fileio_randomaccessfile_read_sync_012'); + let randomaccessfile = fileio.createRandomAccessFileSync(fpath, 0, 0o102); + + try { + randomaccessfile.readSync(new ArrayBuffer(4096), { position: -1 }); + expect(false).assertTrue(); + } catch (err) { + console.info('fileio_randomaccessfile_read_sync_012 has failed for ' + err); + expect(err.message == "Invalid buffer/options").assertTrue(); + randomaccessfile.closeSync(); + fileio.unlinkSync(fpath); + } + }); + + /** + * @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_READ_SYNC_1300 + * @tc.name fileio_randomaccessfile_read_sync_013 + * @tc.desc Test readSync() interface. When the parameter type is wrong. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_randomaccessfile_read_sync_013', 0, async function () { + let fpath = await nextFileName('fileio_randomaccessfile_read_sync_013'); + let randomaccessfile = fileio.createRandomAccessFileSync(fpath, 0, 0o102); + + try { + randomaccessfile.readSync(''); + expect(false).assertTrue(); + } catch (err) { + console.info('fileio_randomaccessfile_read_sync_013 has failed for ' + err); + expect(err.message == "Invalid buffer/options").assertTrue(); + randomaccessfile.closeSync(); + fileio.unlinkSync(fpath); + } + }); + + /** + * @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_READ_ASYNC_0000 + * @tc.name fileio_randomaccessfile_read_async_000 + * @tc.desc Test read() interface. return in callback mode. Test to read data asynchronously. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_randomaccessfile_read_async_000', 0, async function (done) { + let fpath = await nextFileName('fileio_randomaccessfile_read_async_000'); + + try { + let randomaccessfile = await fileio.createRandomAccessFile(fpath, 0, 0o102); + let length = 4096; + let num = await randomaccessfile.write(new ArrayBuffer(length)); + expect(num == length).assertTrue(); + randomaccessfile.setFilePointerSync(0); + randomaccessfile.read(new ArrayBuffer(length), function (err, readOut) { + expect(readOut.bytesRead == length).assertTrue(); + randomaccessfile.closeSync(); + fileio.unlinkSync(fpath); + done(); + }); + } catch (err) { + console.info('fileio_randomaccessfile_read_async_000 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_READ_ASYNC_0100 + * @tc.name fileio_randomaccessfile_read_async_001 + * @tc.desc Test read() interface. When the position is 1. Test to read data asynchronously. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_randomaccessfile_read_async_001', 0, async function (done) { + let fpath = await nextFileName('fileio_randomaccessfile_read_async_001'); + + try { + fileio.createRandomAccessFile(fpath, 0, 0o102, async function (err, randomaccessfile) { + let length = 20; + let num = await randomaccessfile.write(new ArrayBuffer(length)); + expect(num == length).assertTrue(); + randomaccessfile.setFilePointerSync(0); + let readOut = await randomaccessfile.read(new ArrayBuffer(length), { position: 1 }); + expect(readOut.bytesRead == length - 1).assertTrue(); + randomaccessfile.closeSync(); + fileio.unlinkSync(fpath); + done(); + }); + } catch (err) { + console.info('fileio_randomaccessfile_read_async_001 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_READ_ASYNC_0200 + * @tc.name fileio_randomaccessfile_read_async_002 + * @tc.desc Test read() interface. When the offset is 1. Test to read data asynchronously. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_randomaccessfile_read_async_002', 0, async function (done) { + let fpath = await nextFileName('fileio_randomaccessfile_read_async_002'); + + try { + let fd = fileio.openSync(fpath, 0o102, 0o666); + let randomaccessfile = await fileio.createRandomAccessFile(fd, 0); + let length = 20; + let num = await randomaccessfile.write(new ArrayBuffer(length)); + expect(num == length).assertTrue(); + randomaccessfile.setFilePointerSync(0); + let readOut = await randomaccessfile.read(new ArrayBuffer(length), { offset: 1 }); + expect(readOut.bytesRead == length - 1).assertTrue(); + expect(readOut.offset == 1).assertTrue(); + randomaccessfile.closeSync(); + fileio.unlinkSync(fpath); + done(); + } catch (err) { + console.info('fileio_randomaccessfile_read_async_002 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_READ_ASYNC_0300 + * @tc.name fileio_randomaccessfile_read_async_003 + * @tc.desc Test read() interface. When the offset is 1 and the length is 5. Test to read data asynchronously. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_randomaccessfile_read_async_003', 0, async function (done) { + let fpath = await nextFileName('fileio_randomaccessfile_read_async_003'); + + try { + let randomaccessfile = await fileio.createRandomAccessFile(fpath, 0, 0o102); + let length = 20; + let num = await randomaccessfile.write(new ArrayBuffer(length)); + expect(num == length).assertTrue(); + randomaccessfile.setFilePointerSync(0); + randomaccessfile.read(new ArrayBuffer(length), { offset: 1, length: 5 }, function (err, readOut) { + expect(readOut.bytesRead == 5).assertTrue(); + expect(readOut.offset == 1).assertTrue(); + randomaccessfile.closeSync(); + fileio.unlinkSync(fpath); + done(); + }); + } catch (err) { + console.info('fileio_randomaccessfile_read_async_003 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_READ_ASYNC_0400 + * @tc.name fileio_randomaccessfile_read_async_004 + * @tc.desc Test read() interface. When offset equals buffer length. Test to read data asynchronously. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_randomaccessfile_read_async_004', 0, async function (done) { + let fpath = await nextFileName('fileio_randomaccessfile_read_async_004'); + + try { + let randomaccessfile = await fileio.createRandomAccessFile(fpath, 0, 0o102); + let length = 4096; + let num = await randomaccessfile.write(new ArrayBuffer(length)); + expect(num == length).assertTrue(); + randomaccessfile.setFilePointerSync(0); + let readOut = await randomaccessfile.read(new ArrayBuffer(length), { offset: length }); + expect(readOut.bytesRead == 0).assertTrue(); + expect(readOut.offset == 4096).assertTrue(); + randomaccessfile.closeSync(); + fileio.unlinkSync(fpath); + done(); + } catch (err) { + console.info('fileio_randomaccessfile_read_async_004 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_READ_ASYNC_0500 + * @tc.name fileio_randomaccessfile_read_async_005 + * @tc.desc Test read() interface. When the offset is 1 and the position is 6. Test to read data asynchronously. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_randomaccessfile_read_async_005', 0, async function (done) { + let fpath = await nextFileName('fileio_randomaccessfile_read_async_005'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let randomaccessfile = await fileio.createRandomAccessFile(fpath, 0, 0o102); + let length = 20; + let readOut = await randomaccessfile.read(new ArrayBuffer(length), { offset: 1, position: 6 }); + expect(readOut.bytesRead == FILE_CONTENT.length - 6).assertTrue(); + expect(readOut.offset == 1).assertTrue(); + let start = readOut.offset; + let end = readOut.offset + readOut.bytesRead; + let result = String.fromCharCode.apply(null, new Uint8Array(readOut.buffer.slice(start, end))); + expect(result == "world").assertTrue(); + randomaccessfile.closeSync(); + fileio.unlinkSync(fpath); + done(); + } catch (err) { + console.info('fileio_randomaccessfile_read_async_005 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_READ_ASYNC_0600 + * @tc.name fileio_randomaccessfile_read_async_006 + * @tc.desc Test read() interface. When the offset is negative. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_randomaccessfile_read_async_006', 0, async function (done) { + let fpath = await nextFileName('fileio_randomaccessfile_read_async_006'); + let randomaccessfile = await fileio.createRandomAccessFile(fpath, 0, 0o102); + + try { + await randomaccessfile.read(new ArrayBuffer(4096), { offset: -1 }); + } catch (err) { + console.info('fileio_randomaccessfile_read_async_006 has failed for ' + err); + expect(err.message == "Invalid buffer/options").assertTrue(); + randomaccessfile.closeSync(); + fileio.unlinkSync(fpath); + done(); + } + }); + + /** + * @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_READ_ASYNC_0700 + * @tc.name fileio_randomaccessfile_read_async_007 + * @tc.desc Test read() interface. When offset+length>buffer.size. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_randomaccessfile_read_async_007', 0, async function (done) { + let fpath = await nextFileName('fileio_randomaccessfile_read_async_007'); + let randomaccessfile = await fileio.createRandomAccessFile(fpath, 0, 0o102); + + try { + await randomaccessfile.read(new ArrayBuffer(4096), { offset: 1, length: 4096 }); + } catch (err) { + console.info('fileio_randomaccessfile_read_async_007 has failed for ' + err); + expect(err.message == "Invalid buffer/options").assertTrue(); + randomaccessfile.closeSync(); + fileio.unlinkSync(fpath); + done(); + } + }); + + /** + * @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_READ_ASYNC_0800 + * @tc.name fileio_randomaccessfile_read_async_008 + * @tc.desc Test read() interface. When the offset is greater than the buffer length. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_randomaccessfile_read_async_008', 0, async function (done) { + let fpath = await nextFileName('fileio_randomaccessfile_read_async_008'); + let fd = fileio.openSync(fpath, 0o102, 0o666); + let randomaccessfile = await fileio.createRandomAccessFile(fd, 0); + + try { + let length = 4096; + randomaccessfile.read(new ArrayBuffer(length), { offset: length + 1 }, function (err) { + }); + } catch (err) { + console.info('fileio_randomaccessfile_read_async_008 has failed for ' + err); + expect(err.message == "Invalid buffer/options").assertTrue(); + randomaccessfile.closeSync(); + fileio.unlinkSync(fpath); + done(); + } + }); + + /** + * @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_READ_ASYNC_0900 + * @tc.name fileio_randomaccessfile_read_async_009 + * @tc.desc Test read() interface. When the length is greater than the buffer length. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_randomaccessfile_read_async_009', 0, async function (done) { + let fpath = await nextFileName('fileio_randomaccessfile_read_async_009'); + let randomaccessfile = await fileio.createRandomAccessFile(fpath, 0, 0o102); + + try { + let length = 4096; + await randomaccessfile.read(new ArrayBuffer(length), { length: length + 1 }); + } catch (err) { + console.info('fileio_randomaccessfile_read_async_009 has failed for ' + err); + expect(err.message == "Invalid buffer/options").assertTrue(); + randomaccessfile.closeSync(); + fileio.unlinkSync(fpath); + done(); + } + }); + + /** + * @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_READ_ASYNC_1000 + * @tc.name fileio_randomaccessfile_read_async_010 + * @tc.desc Test read() interface. The "length" of option must > 0. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_randomaccessfile_read_async_010', 0, async function (done) { + let fpath = await nextFileName('fileio_randomaccessfile_read_async_010'); + let randomaccessfile; + + try { + randomaccessfile = await fileio.createRandomAccessFile(fpath, 0, 0o102); + let length = 4096; + let num = randomaccessfile.writeSync(new ArrayBuffer(length)); + expect(num == length).assertTrue(); + randomaccessfile.setFilePointerSync(0); + await randomaccessfile.read(new ArrayBuffer(16), { offset: 13, length: -1 }); + expect(false).assertTrue(); + } catch (err) { + randomaccessfile.closeSync(); + fileio.unlinkSync(fpath); + console.info('fileio_randomaccessfile_read_async_010 has failed for ' + err); + expect(err.message == "Invalid buffer/options").assertTrue(); + done(); + } + }); + + /** + * @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_READ_ASYNC_1100 + * @tc.name fileio_randomaccessfile_read_async_011 + * @tc.desc Test read() interface. When there are no parameters. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_randomaccessfile_read_async_011', 0, async function (done) { + let fpath = await nextFileName('fileio_randomaccessfile_read_async_011'); + let randomaccessfile = await fileio.createRandomAccessFile(fpath, 0, 0o102); + + try { + await randomaccessfile.read(); + } catch (err) { + console.info('fileio_randomaccessfile_read_async_011 has failed for ' + err); + expect(err.message == "Number of arguments unmatched").assertTrue(); + randomaccessfile.closeSync(); + fileio.unlinkSync(fpath); + done(); + } + }); + + /** + * @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_READ_ASYNC_1200 + * @tc.name fileio_randomaccessfile_read_async_012 + * @tc.desc Test read() interface. When the position is negative. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_randomaccessfile_read_async_012', 0, async function (done) { + let fpath = await nextFileName('fileio_randomaccessfile_read_async_012'); + let randomaccessfile = await fileio.createRandomAccessFile(fpath, 0, 0o102); + + try { + await randomaccessfile.read(new ArrayBuffer(4096), { position: -1 }); + } catch (err) { + console.info('fileio_randomaccessfile_read_async_012 has failed for ' + err); + expect(err.message == "Invalid buffer/options").assertTrue(); + randomaccessfile.closeSync(); + fileio.unlinkSync(fpath); + done(); + } + }); + + /** + * @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_READ_ASYNC_1300 + * @tc.name fileio_randomaccessfile_read_async_013 + * @tc.desc Test read() interface. When the parameter type is wrong. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_randomaccessfile_read_async_013', 0, async function (done) { + let fpath = await nextFileName('fileio_randomaccessfile_read_async_013'); + let randomaccessfile = await fileio.createRandomAccessFile(fpath, 0, 0o102); + + try { + await randomaccessfile.read(''); + } catch (err) { + console.info('fileio_randomaccessfile_read_async_013 has failed for ' + err); + expect(err.message == "Invalid buffer/options").assertTrue(); + randomaccessfile.closeSync(); + fileio.unlinkSync(fpath); + done() + } + }); +}) } \ No newline at end of file diff --git a/storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/class_randomAccessFile/setFilePointer.test.js b/storage/storagefileiojstest/src/main/js/test/module_fileio/class_randomAccessFile/setFilePointer.test.js similarity index 96% rename from storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/class_randomAccessFile/setFilePointer.test.js rename to storage/storagefileiojstest/src/main/js/test/module_fileio/class_randomAccessFile/setFilePointer.test.js index 29b26fd4ba826ea26c673e64a3b43191dd6c77a7..9de6f6f0f332241c3c078acf11755d436ef18ba9 100644 --- a/storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/class_randomAccessFile/setFilePointer.test.js +++ b/storage/storagefileiojstest/src/main/js/test/module_fileio/class_randomAccessFile/setFilePointer.test.js @@ -1,96 +1,96 @@ -/* - * Copyright (C) 2023 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 { - fileio, nextFileName, describe, it, expect -} from '../../Common'; - -export default function fileioRandomAccessFileSetFilePointer() { -describe('fileio_randomAccessFile_setFilePointer', function () { - - /** - * @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_SET_FILE_POINTER_SYNC_0000 - * @tc.name fileio_randomaccessfile_set_file_pointer_sync_000 - * @tc.desc Test setFilePointerSync() interface. Set file offset pointer position. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_randomaccessfile_set_file_pointer_sync_000', 0, async function () { - let fpath = await nextFileName('fileio_randomaccessfile_set_file_pointer_sync_000'); - - try { - let randomaccessfile = fileio.createRandomAccessFileSync(fpath, 0, 0o102); - expect(randomaccessfile.fpointer == 0).assertTrue(); - randomaccessfile.setFilePointerSync(5); - expect(randomaccessfile.fpointer == 5).assertTrue(); - randomaccessfile.closeSync(); - fileio.unlinkSync(fpath); - } catch(err) { - console.info('fileio_randomaccessfile_set_file_pointer_sync_000 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_SET_FILE_POINTER_SYNC_0100 - * @tc.name fileio_randomaccessfile_set_file_pointer_sync_001 - * @tc.desc Test setFilePointerSync() interface. Invalid fpointer. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_randomaccessfile_set_file_pointer_sync_001', 0, async function () { - let fpath = await nextFileName('fileio_randomaccessfile_set_file_pointer_sync_001'); - let randomaccessfile = fileio.createRandomAccessFileSync(fpath, 0, 0o102); - - try { - randomaccessfile.setFilePointerSync('5'); - expect(false).assertTrue(); - } catch(err) { - console.info('fileio_randomaccessfile_set_file_pointer_sync_001 has failed for ' + err); - expect(err.message == "Invalid fpointer").assertTrue(); - randomaccessfile.closeSync(); - fileio.unlinkSync(fpath); - } - }); - - /** - * @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_SET_FILE_POINTER_SYNC_0200 - * @tc.name fileio_randomaccessfile_set_file_pointer_sync_002 - * @tc.desc Test setFilePointerSync() interface. Missing Parameter. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_randomaccessfile_set_file_pointer_sync_002', 0, async function () { - let fpath = await nextFileName('fileio_randomaccessfile_set_file_pointer_sync_002'); - let randomaccessfile = fileio.createRandomAccessFileSync(fpath, 0, 0o102); - - try { - randomaccessfile.setFilePointerSync(); - expect(false).assertTrue(); - } catch(err) { - console.info('fileio_randomaccessfile_set_file_pointer_sync_002 has failed for ' + err); - expect(err.message == "Number of arguments unmatched").assertTrue(); - randomaccessfile.closeSync(); - fileio.unlinkSync(fpath); - } - }); -}) +/* + * 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. + */ + +import { + fileio, nextFileName, describe, it, expect +} from '../../Common'; + +export default function fileioRandomAccessFileSetFilePointer() { +describe('fileio_randomAccessFile_setFilePointer', function () { + + /** + * @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_SET_FILE_POINTER_SYNC_0000 + * @tc.name fileio_randomaccessfile_set_file_pointer_sync_000 + * @tc.desc Test setFilePointerSync() interface. Set file offset pointer position. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_randomaccessfile_set_file_pointer_sync_000', 0, async function () { + let fpath = await nextFileName('fileio_randomaccessfile_set_file_pointer_sync_000'); + + try { + let randomaccessfile = fileio.createRandomAccessFileSync(fpath, 0, 0o102); + expect(randomaccessfile.fpointer == 0).assertTrue(); + randomaccessfile.setFilePointerSync(5); + expect(randomaccessfile.fpointer == 5).assertTrue(); + randomaccessfile.closeSync(); + fileio.unlinkSync(fpath); + } catch(err) { + console.info('fileio_randomaccessfile_set_file_pointer_sync_000 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_SET_FILE_POINTER_SYNC_0100 + * @tc.name fileio_randomaccessfile_set_file_pointer_sync_001 + * @tc.desc Test setFilePointerSync() interface. Invalid fpointer. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_randomaccessfile_set_file_pointer_sync_001', 0, async function () { + let fpath = await nextFileName('fileio_randomaccessfile_set_file_pointer_sync_001'); + let randomaccessfile = fileio.createRandomAccessFileSync(fpath, 0, 0o102); + + try { + randomaccessfile.setFilePointerSync('5'); + expect(false).assertTrue(); + } catch(err) { + console.info('fileio_randomaccessfile_set_file_pointer_sync_001 has failed for ' + err); + expect(err.message == "Invalid fpointer").assertTrue(); + randomaccessfile.closeSync(); + fileio.unlinkSync(fpath); + } + }); + + /** + * @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_SET_FILE_POINTER_SYNC_0200 + * @tc.name fileio_randomaccessfile_set_file_pointer_sync_002 + * @tc.desc Test setFilePointerSync() interface. Missing Parameter. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_randomaccessfile_set_file_pointer_sync_002', 0, async function () { + let fpath = await nextFileName('fileio_randomaccessfile_set_file_pointer_sync_002'); + let randomaccessfile = fileio.createRandomAccessFileSync(fpath, 0, 0o102); + + try { + randomaccessfile.setFilePointerSync(); + expect(false).assertTrue(); + } catch(err) { + console.info('fileio_randomaccessfile_set_file_pointer_sync_002 has failed for ' + err); + expect(err.message == "Number of arguments unmatched").assertTrue(); + randomaccessfile.closeSync(); + fileio.unlinkSync(fpath); + } + }); +}) } \ No newline at end of file diff --git a/storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/class_randomAccessFile/write.test.js b/storage/storagefileiojstest/src/main/js/test/module_fileio/class_randomAccessFile/write.test.js similarity index 97% rename from storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/class_randomAccessFile/write.test.js rename to storage/storagefileiojstest/src/main/js/test/module_fileio/class_randomAccessFile/write.test.js index df5f660d636b4b61e36f741ff6b499cb742bfc47..4508ceb4d115e0a59706b8e2983c154ef014c316 100644 --- a/storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/class_randomAccessFile/write.test.js +++ b/storage/storagefileiojstest/src/main/js/test/module_fileio/class_randomAccessFile/write.test.js @@ -1,749 +1,749 @@ -/* - * Copyright (C) 2023 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 { - fileio, prepareFile, FILE_CONTENT, nextFileName, - describe, it, expect -} from '../../Common'; - -export default function fileioRandomAccessFileWrite() { -describe('fileio_randomAccessFile_write', function () { - - /** - * @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_WRITE_SYNC_0000 - * @tc.name fileio_randomaccessfile_write_sync_000 - * @tc.desc Test writeSync() interface. Test write data synchronously. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_randomaccessfile_write_sync_000', 0, async function () { - let fpath = await nextFileName('fileio_randomaccessfile_write_sync_000'); - - try { - let randomaccessfile = fileio.createRandomAccessFileSync(fpath, 0, 0o102); - let length = 4096; - let num = randomaccessfile.writeSync(new ArrayBuffer(length)); - expect(num == length).assertTrue(); - randomaccessfile.closeSync(); - fileio.unlinkSync(fpath); - } catch(err) { - console.info('fileio_randomaccessfile_write_sync_000 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_WRITE_SYNC_0100 - * @tc.name fileio_randomaccessfile_write_sync_001 - * @tc.desc Test writeSync() interface. When the offset is 1. Test write data synchronously. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_randomaccessfile_write_sync_001', 0, async function () { - let fpath = await nextFileName('fileio_randomaccessfile_write_sync_001'); - - try { - let randomaccessfile = fileio.createRandomAccessFileSync(fpath, 0, 0o102); - let length = 20; - let num = randomaccessfile.writeSync(new ArrayBuffer(length), { offset: 1 }); - expect(num == length - 1).assertTrue(); - randomaccessfile.closeSync(); - fileio.unlinkSync(fpath); - } catch(err) { - console.info('fileio_randomaccessfile_write_sync_001 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_WRITE_SYNC_0200 - * @tc.name fileio_randomaccessfile_write_sync_002 - * @tc.desc Test writeSync() interface. When the position is 1. Test write data synchronously. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_randomaccessfile_write_sync_002', 0, async function () { - let fpath = await nextFileName('fileio_randomaccessfile_write_sync_002'); - - try { - let fd = fileio.openSync(fpath, 0o102, 0o666); - let randomaccessfile = fileio.createRandomAccessFileSync(fd, 0); - let length = 20; - let num = randomaccessfile.writeSync(new ArrayBuffer(length), { position: 1 }); - expect(num == length).assertTrue(); - randomaccessfile.closeSync(); - fileio.unlinkSync(fpath); - } catch(err) { - console.info('fileio_randomaccessfile_write_sync_002 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_WRITE_SYNC_0300 - * @tc.name fileio_randomaccessfile_write_sync_003 - * @tc.desc Test writeSync() interface. When the offset is 1 and length is 10. Test write data synchronously. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_randomaccessfile_write_sync_003', 0, async function () { - let fpath = await nextFileName('fileio_randomaccessfile_write_sync_003'); - - try { - let randomaccessfile = fileio.createRandomAccessFileSync(fpath, 0, 0o102); - let length = 20; - let num = randomaccessfile.writeSync(new ArrayBuffer(length), { offset: 1, length: 10 }); - expect(num == 10).assertTrue(); - randomaccessfile.closeSync(); - fileio.unlinkSync(fpath); - } catch(err) { - console.info('fileio_randomaccessfile_write_sync_003 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_WRITE_SYNC_0400 - * @tc.name fileio_randomaccessfile_write_sync_004 - * @tc.desc Test writeSync() interface. When the offset is 1 and position is 5. Test write data synchronously. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_randomaccessfile_write_sync_004', 0, async function () { - let fpath = await nextFileName('fileio_randomaccessfile_write_sync_004'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let randomaccessfile = fileio.createRandomAccessFileSync(fpath, 0, 0o102); - let length = 20; - let options = { - offset: 1, - position:5 - } - let num = randomaccessfile.writeSync(new ArrayBuffer(length), options); - expect(num == length - 1).assertTrue(); - randomaccessfile.setFilePointerSync(0); - let number = randomaccessfile.readSync(new ArrayBuffer(4096)); - expect(number == (length - options.offset + options.position)).assertTrue(); - randomaccessfile.closeSync(); - fileio.unlinkSync(fpath); - } catch(err) { - console.info('fileio_randomaccessfile_write_sync_004 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_WRITE_SYNC_0500 - * @tc.name fileio_randomaccessfile_write_sync_005 - * @tc.desc Test writeSync() interface. When offset equals buffer length. Test write data synchronously. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_randomaccessfile_write_sync_005', 0, async function () { - let fpath = await nextFileName('fileio_randomaccessfile_write_sync_005'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let randomaccessfile = fileio.createRandomAccessFileSync(fpath, 0, 0o102); - let length = 4096; - let num = randomaccessfile.writeSync(new ArrayBuffer(length), { offset: length }); - expect(num == 0).assertTrue(); - randomaccessfile.closeSync(); - fileio.unlinkSync(fpath); - } catch(err) { - console.info('fileio_randomaccessfile_write_sync_005 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_WRITE_SYNC_0600 - * @tc.name fileio_randomaccessfile_write_sync_006 - * @tc.desc Test writeSync() interface. When offset+length>buffer.size. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_randomaccessfile_write_sync_006', 0, async function () { - let fpath = await nextFileName('fileio_randomaccessfile_write_sync_006'); - let randomaccessfile = fileio.createRandomAccessFileSync(fpath, 0, 0o102); - - try { - randomaccessfile.writeSync(new ArrayBuffer(4096), { offset: 5, length: 4095 }); - expect(false).assertTrue(); - } catch(err) { - console.info('fileio_randomaccessfile_write_sync_006 has failed for ' + err); - expect(err.message == "Invalid buffer/options").assertTrue(); - randomaccessfile.closeSync(); - fileio.unlinkSync(fpath); - } - }); - - /** - * @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_WRITE_SYNC_0700 - * @tc.name fileio_randomaccessfile_write_sync_007 - * @tc.desc Test writeSync() interface. When the offset is greater than the buffer length. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_randomaccessfile_write_sync_007', 0, async function () { - let fpath = await nextFileName('fileio_randomaccessfile_write_sync_007'); - let randomaccessfile = fileio.createRandomAccessFileSync(fpath, 0, 0o102); - - try { - let length = 4096; - randomaccessfile.writeSync(new ArrayBuffer(length), { offset: length + 1 }); - expect(false).assertTrue(); - } catch(err) { - console.info('fileio_randomaccessfile_write_sync_007 has failed for ' + err); - expect(err.message == "Invalid buffer/options").assertTrue(); - randomaccessfile.closeSync(); - fileio.unlinkSync(fpath); - } - }); - - /** - * @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_WRITE_SYNC_0800 - * @tc.name fileio_randomaccessfile_write_sync_008 - * @tc.desc Test writeSync() interface. When there are no parameters. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_randomaccessfile_write_sync_008', 0, async function () { - let fpath = await nextFileName('fileio_randomaccessfile_write_sync_008'); - let randomaccessfile = fileio.createRandomAccessFileSync(fpath, 0, 0o102); - - try { - randomaccessfile.writeSync(); - expect(false).assertTrue(); - } catch(err) { - console.info('fileio_randomaccessfile_write_sync_008 has failed for ' + err); - expect(err.message == "Number of arguments unmatched").assertTrue(); - randomaccessfile.closeSync(); - fileio.unlinkSync(fpath); - } - }); - - /** - * @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_WRITE_SYNC_0900 - * @tc.name fileio_randomaccessfile_write_sync_009 - * @tc.desc Test writeSync() interface. When the offset is negative. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_randomaccessfile_write_sync_009', 0, async function () { - let fpath = await nextFileName('fileio_randomaccessfile_write_sync_009'); - let fd = fileio.openSync(fpath, 0o102, 0o666); - let randomaccessfile = fileio.createRandomAccessFileSync(fd, 0); - - try { - randomaccessfile.writeSync(new ArrayBuffer(4096), { offset: -1 }); - expect(false).assertTrue(); - } catch(err) { - console.info('fileio_randomaccessfile_write_sync_009 has failed for ' + err); - expect(err.message == "Invalid buffer/options").assertTrue(); - randomaccessfile.closeSync(); - fileio.unlinkSync(fpath); - } - }); - - /** - * @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_WRITE_SYNC_1000 - * @tc.name fileio_randomaccessfile_write_sync_010 - * @tc.desc Test writeSync() interface. The "length" of option must > 0. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_randomaccessfile_write_sync_010', 0, async function () { - let fpath = await nextFileName('fileio_randomaccessfile_write_sync_010'); - let randomaccessfile; - - try { - randomaccessfile = fileio.createRandomAccessFileSync(fpath, 0, 0o102); - let length = 100; - randomaccessfile.writeSync(new ArrayBuffer(length), { offset: 1, length: -1 }); - expect(false).assertTrue(); - } catch(err) { - randomaccessfile.closeSync(); - fileio.unlinkSync(fpath); - console.info('fileio_randomaccessfile_write_sync_010 has failed for ' + err); - expect(err.message == "Invalid buffer/options").assertTrue(); - } - }); - - /** - * @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_WRITE_SYNC_1100 - * @tc.name fileio_randomaccessfile_write_sync_011 - * @tc.desc Test writeSync() interface. When the buffer parameter type is wrong. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_randomaccessfile_write_sync_011', 0, async function () { - let fpath = await nextFileName('fileio_randomaccessfile_write_sync_011'); - let randomaccessfile = fileio.createRandomAccessFileSync(fpath, 0, 0o102); - - try { - randomaccessfile.writeSync(10, { length: -1 }); - expect(false).assertTrue(); - } catch(err) { - console.info('fileio_randomaccessfile_write_sync_011 has failed for ' + err); - expect(err.message == "Invalid buffer/options").assertTrue(); - randomaccessfile.closeSync(); - fileio.unlinkSync(fpath); - } - }); - - /** - * @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_WRITE_SYNC_1200 - * @tc.name fileio_randomaccessfile_write_sync_012 - * @tc.desc Test writeSync() interface. When the length is greater than the buffer length. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_randomaccessfile_write_sync_012', 0, async function () { - let fpath = await nextFileName('fileio_randomaccessfile_write_sync_012'); - let randomaccessfile = fileio.createRandomAccessFileSync(fpath, 0, 0o102); - - try { - let length = 4096; - randomaccessfile.writeSync(new ArrayBuffer(length), { length: length + 1 }); - expect(false).assertTrue(); - } catch(err) { - console.info('fileio_randomaccessfile_write_sync_012 has failed for ' + err); - expect(err.message == "Invalid buffer/options").assertTrue(); - randomaccessfile.closeSync(); - fileio.unlinkSync(fpath); - } - }); - - /** - * @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_WRITE_SYNC_1300 - * @tc.name fileio_randomaccessfile_write_sync_013 - * @tc.desc Test writeSync() interface. When the position is negative. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_randomaccessfile_write_sync_013', 0, async function () { - let fpath = await nextFileName('fileio_randomaccessfile_write_sync_013'); - let randomaccessfile = fileio.createRandomAccessFileSync(fpath, 0, 0o102); - - try { - randomaccessfile.writeSync(new ArrayBuffer(4096), { position: -1 }); - expect(false).assertTrue(); - } catch(err) { - console.info('fileio_randomaccessfile_write_sync_013 has failed for ' + err); - expect(err.message == "Invalid buffer/options").assertTrue(); - randomaccessfile.closeSync(); - fileio.unlinkSync(fpath); - } - }); - - /** - * @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_WRITE_ASYNC_0000 - * @tc.name fileio_randomaccessfile_write_async_000 - * @tc.desc Test write() interface. return in promise mode. Test write data asynchronously. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_randomaccessfile_write_async_000', 0, async function (done) { - let fpath = await nextFileName('fileio_randomaccessfile_write_async_000'); - - try { - fileio.createRandomAccessFile(fpath, 0, 0o102, async function(err, randomaccessfile) { - let length = 4096; - let num = await randomaccessfile.write(new ArrayBuffer(length)); - expect(num == length).assertTrue(); - randomaccessfile.closeSync(); - fileio.unlinkSync(fpath); - done(); - }); - } catch(err) { - console.info('fileio_randomaccessfile_write_async_000 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_WRITE_ASYNC_0100 - * @tc.name fileio_randomaccessfile_write_async_001 - * @tc.desc Test write() interface. When the offset is 1. return in callback mode. Test write data asynchronously. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_randomaccessfile_write_async_001', 0, async function (done) { - let fpath = await nextFileName('fileio_randomaccessfile_write_async_001'); - - try { - let fd = fileio.openSync(fpath, 0o102, 0o666); - let randomaccessfile = await fileio.createRandomAccessFile(fd, 0); - let length = 20; - randomaccessfile.write(new ArrayBuffer(length), { offset: 1 }, function(err, bytesWritten) { - expect(bytesWritten == length - 1).assertTrue(); - randomaccessfile.closeSync(); - fileio.unlinkSync(fpath); - done(); - }); - } catch(err) { - console.info('fileio_randomaccessfile_write_async_001 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_WRITE_ASYNC_0200 - * @tc.name fileio_randomaccessfile_write_async_002 - * @tc.desc Test write() interface. When the position is 1. Test write data asynchronously. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_randomaccessfile_write_async_002', 0, async function (done) { - let fpath = await nextFileName('fileio_randomaccessfile_write_async_002'); - - try { - let randomaccessfile = await fileio.createRandomAccessFile(fpath, 0, 0o102); - let length = 20; - let num = await randomaccessfile.write(new ArrayBuffer(length), { position: 1 }); - expect(num == length).assertTrue(); - randomaccessfile.closeSync(); - fileio.unlinkSync(fpath); - done(); - } catch(err) { - console.info('fileio_randomaccessfile_write_async_002 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_WRITE_ASYNC_0300 - * @tc.name fileio_randomaccessfile_write_async_003 - * @tc.desc Test write() interface. When the offset is 1 and length is 10. Test write data asynchronously. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_randomaccessfile_write_async_003', 0, async function (done) { - let fpath = await nextFileName('fileio_randomaccessfile_write_async_003'); - - try { - let randomaccessfile = await fileio.createRandomAccessFile(fpath, 0, 0o102); - let length = 20; - let num = await randomaccessfile.write(new ArrayBuffer(length), { offset: 1, length: 10 }); - expect(num == 10).assertTrue(); - randomaccessfile.closeSync(); - fileio.unlinkSync(fpath); - done(); - } catch(err) { - console.info('fileio_randomaccessfile_write_async_003 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_WRITE_ASYNC_0400 - * @tc.name fileio_randomaccessfile_write_async_004 - * @tc.desc Test write() interface. When the offset is 1 and position is 5. Test write data asynchronously. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_randomaccessfile_write_async_004', 0, async function (done) { - let fpath = await nextFileName('fileio_randomaccessfile_write_async_004'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let randomaccessfile = await fileio.createRandomAccessFile(fpath, 0, 0o102); - let length = 20; - let options = { - offset: 1, - position:5 - } - let num = await randomaccessfile.write(new ArrayBuffer(length), options); - expect(num == length - 1).assertTrue(); - randomaccessfile.setFilePointerSync(0); - let readOut = await randomaccessfile.read(new ArrayBuffer(4096)); - expect(readOut.bytesRead == (length - options.offset + options.position)).assertTrue(); - randomaccessfile.closeSync(); - fileio.unlinkSync(fpath); - done(); - } catch(err) { - console.info('fileio_randomaccessfile_write_async_004 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_WRITE_ASYNC_0500 - * @tc.name fileio_randomaccessfile_write_async_005 - * @tc.desc Test write() interface. When offset equals buffer length. Test write data asynchronously. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_randomaccessfile_write_async_005', 0, async function (done) { - let fpath = await nextFileName('fileio_randomaccessfile_write_async_005'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let randomaccessfile = await fileio.createRandomAccessFile(fpath, 0, 0o102); - let length = 4096; - let num = await randomaccessfile.write(new ArrayBuffer(length), { offset: length }); - expect(num == 0).assertTrue(); - randomaccessfile.closeSync(); - fileio.unlinkSync(fpath); - done(); - } catch(err) { - console.info('fileio_randomaccessfile_write_async_005 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_WRITE_ASYNC_0600 - * @tc.name fileio_randomaccessfile_write_async_006 - * @tc.desc Test write() interface. When offset+length>buffer.size. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_randomaccessfile_write_async_006', 0, async function (done) { - let fpath = await nextFileName('fileio_randomaccessfile_write_async_006'); - let randomaccessfile = await fileio.createRandomAccessFile(fpath, 0, 0o102); - - try { - let length = 4096; - await randomaccessfile.write(new ArrayBuffer(length), { offset: 5, length: 4095 }); - } catch(err) { - console.info('fileio_randomaccessfile_write_async_006 has failed for ' + err); - expect(err.message == "Invalid buffer/options").assertTrue(); - randomaccessfile.closeSync(); - fileio.unlinkSync(fpath); - done(); - } - }); - - /** - * @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_WRITE_ASYNC_0700 - * @tc.name fileio_randomaccessfile_write_async_007 - * @tc.desc Test write() interface. When the offset is greater than the buffer length. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_randomaccessfile_write_async_007', 0, async function (done) { - let fpath = await nextFileName('fileio_randomaccessfile_write_async_007'); - let randomaccessfile = await fileio.createRandomAccessFile(fpath, 0, 0o102); - - try { - let length = 4096; - randomaccessfile.write(new ArrayBuffer(length), { offset: length + 1 }, function(err) { - }); - } catch(err) { - console.info('fileio_randomaccessfile_write_async_007 has failed for ' + err); - expect(err.message == "Invalid buffer/options").assertTrue(); - randomaccessfile.closeSync(); - fileio.unlinkSync(fpath); - done(); - } - }); - - /** - * @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_WRITE_ASYNC_0800 - * @tc.name fileio_randomaccessfile_write_async_008 - * @tc.desc Test write() interface. When there are no parameters. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_randomaccessfile_write_async_008', 0, async function (done) { - let fpath = await nextFileName('fileio_randomaccessfile_write_async_008'); - let randomaccessfile = await fileio.createRandomAccessFile(fpath, 0, 0o102); - - try { - await randomaccessfile.write(); - } catch(err) { - console.info('fileio_randomaccessfile_write_async_008 has failed for ' + err); - expect(err.message == "Number of arguments unmatched").assertTrue(); - randomaccessfile.closeSync(); - fileio.unlinkSync(fpath); - done(); - } - }); - - /** - * @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_WRITE_ASYNC_0900 - * @tc.name fileio_randomaccessfile_write_async_009 - * @tc.desc Test write() interface. When the offset is negative. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_randomaccessfile_write_async_009', 0, async function (done) { - let fpath = await nextFileName('fileio_randomaccessfile_write_async_009'); - let fd = fileio.openSync(fpath, 0o102, 0o666); - let randomaccessfile = await fileio.createRandomAccessFile(fd, 0); - - try { - await randomaccessfile.write(new ArrayBuffer(4096), { offset: -1 }); - } catch(err) { - console.info('fileio_randomaccessfile_write_async_009 has failed for ' + err); - expect(err.message == "Invalid buffer/options").assertTrue(); - randomaccessfile.closeSync(); - fileio.unlinkSync(fpath); - done(); - } - }); - - /** - * @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_WRITE_ASYNC_1000 - * @tc.name fileio_randomaccessfile_write_async_010 - * @tc.desc Test write() interface. The "length" of option must > 0. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_randomaccessfile_write_async_010', 0, async function (done) { - let fpath = await nextFileName('fileio_randomaccessfile_write_async_010'); - let randomaccessfile; - - try { - randomaccessfile = await fileio.createRandomAccessFile(fpath, 0, 0o102); - let length = 100; - await randomaccessfile.write(new ArrayBuffer(length), { offset: 1, length: -1 }); - expect(false).assertTrue(); - } catch(err) { - randomaccessfile.closeSync(); - fileio.unlinkSync(fpath); - console.info('fileio_randomaccessfile_write_async_010 has failed for ' + err); - expect(err.message == "Invalid buffer/options").assertTrue(); - done(); - } - }); - - /** - * @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_WRITE_ASYNC_1100 - * @tc.name fileio_randomaccessfile_write_async_011 - * @tc.desc Test write() interface. When the buffer parameter type is wrong. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_randomaccessfile_write_async_011', 0, async function (done) { - let fpath = await nextFileName('fileio_randomaccessfile_write_async_011'); - let randomaccessfile = await fileio.createRandomAccessFile(fpath, 0, 0o102); - - try { - await randomaccessfile.write(10, { length: -1 }); - } catch(err) { - console.info('fileio_randomaccessfile_write_async_011 has failed for ' + err); - expect(err.message == "Invalid buffer/options").assertTrue(); - randomaccessfile.closeSync(); - fileio.unlinkSync(fpath); - done(); - } - }); - - /** - * @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_WRITE_ASYNC_1200 - * @tc.name fileio_randomaccessfile_write_async_012 - * @tc.desc Test write() interface. When the length is greater than the buffer length. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_randomaccessfile_write_async_012', 0, async function (done) { - let fpath = await nextFileName('fileio_randomaccessfile_write_async_012'); - let randomaccessfile = await fileio.createRandomAccessFile(fpath, 0, 0o102); - - try { - let length = 4096; - await randomaccessfile.write(new ArrayBuffer(length), { length: length + 1 }); - } catch(err) { - console.info('fileio_randomaccessfile_write_async_012 has failed for ' + err); - expect(err.message == "Invalid buffer/options").assertTrue(); - randomaccessfile.closeSync(); - fileio.unlinkSync(fpath); - done(); - } - }); - - /** - * @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_WRITE_ASYNC_1300 - * @tc.name fileio_randomaccessfile_write_async_013 - * @tc.desc Test write() interface. When the position is negative. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_randomaccessfile_write_async_013', 0, async function (done) { - let fpath = await nextFileName('fileio_randomaccessfile_write_async_013'); - let randomaccessfile = await fileio.createRandomAccessFile(fpath, 0, 0o102); - - try { - await randomaccessfile.write(new ArrayBuffer(4096), { position: -1 }); - } catch(err) { - console.info('fileio_randomaccessfile_write_async_013 has failed for ' + err); - expect(err.message == "Invalid buffer/options").assertTrue(); - randomaccessfile.closeSync(); - fileio.unlinkSync(fpath); - done(); - } - }); -}) +/* + * 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. + */ + +import { + fileio, prepareFile, FILE_CONTENT, nextFileName, + describe, it, expect +} from '../../Common'; + +export default function fileioRandomAccessFileWrite() { +describe('fileio_randomAccessFile_write', function () { + + /** + * @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_WRITE_SYNC_0000 + * @tc.name fileio_randomaccessfile_write_sync_000 + * @tc.desc Test writeSync() interface. Test write data synchronously. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_randomaccessfile_write_sync_000', 0, async function () { + let fpath = await nextFileName('fileio_randomaccessfile_write_sync_000'); + + try { + let randomaccessfile = fileio.createRandomAccessFileSync(fpath, 0, 0o102); + let length = 4096; + let num = randomaccessfile.writeSync(new ArrayBuffer(length)); + expect(num == length).assertTrue(); + randomaccessfile.closeSync(); + fileio.unlinkSync(fpath); + } catch(err) { + console.info('fileio_randomaccessfile_write_sync_000 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_WRITE_SYNC_0100 + * @tc.name fileio_randomaccessfile_write_sync_001 + * @tc.desc Test writeSync() interface. When the offset is 1. Test write data synchronously. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_randomaccessfile_write_sync_001', 0, async function () { + let fpath = await nextFileName('fileio_randomaccessfile_write_sync_001'); + + try { + let randomaccessfile = fileio.createRandomAccessFileSync(fpath, 0, 0o102); + let length = 20; + let num = randomaccessfile.writeSync(new ArrayBuffer(length), { offset: 1 }); + expect(num == length - 1).assertTrue(); + randomaccessfile.closeSync(); + fileio.unlinkSync(fpath); + } catch(err) { + console.info('fileio_randomaccessfile_write_sync_001 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_WRITE_SYNC_0200 + * @tc.name fileio_randomaccessfile_write_sync_002 + * @tc.desc Test writeSync() interface. When the position is 1. Test write data synchronously. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_randomaccessfile_write_sync_002', 0, async function () { + let fpath = await nextFileName('fileio_randomaccessfile_write_sync_002'); + + try { + let fd = fileio.openSync(fpath, 0o102, 0o666); + let randomaccessfile = fileio.createRandomAccessFileSync(fd, 0); + let length = 20; + let num = randomaccessfile.writeSync(new ArrayBuffer(length), { position: 1 }); + expect(num == length).assertTrue(); + randomaccessfile.closeSync(); + fileio.unlinkSync(fpath); + } catch(err) { + console.info('fileio_randomaccessfile_write_sync_002 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_WRITE_SYNC_0300 + * @tc.name fileio_randomaccessfile_write_sync_003 + * @tc.desc Test writeSync() interface. When the offset is 1 and length is 10. Test write data synchronously. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_randomaccessfile_write_sync_003', 0, async function () { + let fpath = await nextFileName('fileio_randomaccessfile_write_sync_003'); + + try { + let randomaccessfile = fileio.createRandomAccessFileSync(fpath, 0, 0o102); + let length = 20; + let num = randomaccessfile.writeSync(new ArrayBuffer(length), { offset: 1, length: 10 }); + expect(num == 10).assertTrue(); + randomaccessfile.closeSync(); + fileio.unlinkSync(fpath); + } catch(err) { + console.info('fileio_randomaccessfile_write_sync_003 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_WRITE_SYNC_0400 + * @tc.name fileio_randomaccessfile_write_sync_004 + * @tc.desc Test writeSync() interface. When the offset is 1 and position is 5. Test write data synchronously. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_randomaccessfile_write_sync_004', 0, async function () { + let fpath = await nextFileName('fileio_randomaccessfile_write_sync_004'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let randomaccessfile = fileio.createRandomAccessFileSync(fpath, 0, 0o102); + let length = 20; + let options = { + offset: 1, + position:5 + } + let num = randomaccessfile.writeSync(new ArrayBuffer(length), options); + expect(num == length - 1).assertTrue(); + randomaccessfile.setFilePointerSync(0); + let number = randomaccessfile.readSync(new ArrayBuffer(4096)); + expect(number == (length - options.offset + options.position)).assertTrue(); + randomaccessfile.closeSync(); + fileio.unlinkSync(fpath); + } catch(err) { + console.info('fileio_randomaccessfile_write_sync_004 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_WRITE_SYNC_0500 + * @tc.name fileio_randomaccessfile_write_sync_005 + * @tc.desc Test writeSync() interface. When offset equals buffer length. Test write data synchronously. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_randomaccessfile_write_sync_005', 0, async function () { + let fpath = await nextFileName('fileio_randomaccessfile_write_sync_005'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let randomaccessfile = fileio.createRandomAccessFileSync(fpath, 0, 0o102); + let length = 4096; + let num = randomaccessfile.writeSync(new ArrayBuffer(length), { offset: length }); + expect(num == 0).assertTrue(); + randomaccessfile.closeSync(); + fileio.unlinkSync(fpath); + } catch(err) { + console.info('fileio_randomaccessfile_write_sync_005 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_WRITE_SYNC_0600 + * @tc.name fileio_randomaccessfile_write_sync_006 + * @tc.desc Test writeSync() interface. When offset+length>buffer.size. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_randomaccessfile_write_sync_006', 0, async function () { + let fpath = await nextFileName('fileio_randomaccessfile_write_sync_006'); + let randomaccessfile = fileio.createRandomAccessFileSync(fpath, 0, 0o102); + + try { + randomaccessfile.writeSync(new ArrayBuffer(4096), { offset: 5, length: 4095 }); + expect(false).assertTrue(); + } catch(err) { + console.info('fileio_randomaccessfile_write_sync_006 has failed for ' + err); + expect(err.message == "Invalid buffer/options").assertTrue(); + randomaccessfile.closeSync(); + fileio.unlinkSync(fpath); + } + }); + + /** + * @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_WRITE_SYNC_0700 + * @tc.name fileio_randomaccessfile_write_sync_007 + * @tc.desc Test writeSync() interface. When the offset is greater than the buffer length. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_randomaccessfile_write_sync_007', 0, async function () { + let fpath = await nextFileName('fileio_randomaccessfile_write_sync_007'); + let randomaccessfile = fileio.createRandomAccessFileSync(fpath, 0, 0o102); + + try { + let length = 4096; + randomaccessfile.writeSync(new ArrayBuffer(length), { offset: length + 1 }); + expect(false).assertTrue(); + } catch(err) { + console.info('fileio_randomaccessfile_write_sync_007 has failed for ' + err); + expect(err.message == "Invalid buffer/options").assertTrue(); + randomaccessfile.closeSync(); + fileio.unlinkSync(fpath); + } + }); + + /** + * @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_WRITE_SYNC_0800 + * @tc.name fileio_randomaccessfile_write_sync_008 + * @tc.desc Test writeSync() interface. When there are no parameters. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_randomaccessfile_write_sync_008', 0, async function () { + let fpath = await nextFileName('fileio_randomaccessfile_write_sync_008'); + let randomaccessfile = fileio.createRandomAccessFileSync(fpath, 0, 0o102); + + try { + randomaccessfile.writeSync(); + expect(false).assertTrue(); + } catch(err) { + console.info('fileio_randomaccessfile_write_sync_008 has failed for ' + err); + expect(err.message == "Number of arguments unmatched").assertTrue(); + randomaccessfile.closeSync(); + fileio.unlinkSync(fpath); + } + }); + + /** + * @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_WRITE_SYNC_0900 + * @tc.name fileio_randomaccessfile_write_sync_009 + * @tc.desc Test writeSync() interface. When the offset is negative. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_randomaccessfile_write_sync_009', 0, async function () { + let fpath = await nextFileName('fileio_randomaccessfile_write_sync_009'); + let fd = fileio.openSync(fpath, 0o102, 0o666); + let randomaccessfile = fileio.createRandomAccessFileSync(fd, 0); + + try { + randomaccessfile.writeSync(new ArrayBuffer(4096), { offset: -1 }); + expect(false).assertTrue(); + } catch(err) { + console.info('fileio_randomaccessfile_write_sync_009 has failed for ' + err); + expect(err.message == "Invalid buffer/options").assertTrue(); + randomaccessfile.closeSync(); + fileio.unlinkSync(fpath); + } + }); + + /** + * @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_WRITE_SYNC_1000 + * @tc.name fileio_randomaccessfile_write_sync_010 + * @tc.desc Test writeSync() interface. The "length" of option must > 0. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_randomaccessfile_write_sync_010', 0, async function () { + let fpath = await nextFileName('fileio_randomaccessfile_write_sync_010'); + let randomaccessfile; + + try { + randomaccessfile = fileio.createRandomAccessFileSync(fpath, 0, 0o102); + let length = 100; + randomaccessfile.writeSync(new ArrayBuffer(length), { offset: 1, length: -1 }); + expect(false).assertTrue(); + } catch(err) { + randomaccessfile.closeSync(); + fileio.unlinkSync(fpath); + console.info('fileio_randomaccessfile_write_sync_010 has failed for ' + err); + expect(err.message == "Invalid buffer/options").assertTrue(); + } + }); + + /** + * @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_WRITE_SYNC_1100 + * @tc.name fileio_randomaccessfile_write_sync_011 + * @tc.desc Test writeSync() interface. When the buffer parameter type is wrong. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_randomaccessfile_write_sync_011', 0, async function () { + let fpath = await nextFileName('fileio_randomaccessfile_write_sync_011'); + let randomaccessfile = fileio.createRandomAccessFileSync(fpath, 0, 0o102); + + try { + randomaccessfile.writeSync(10, { length: -1 }); + expect(false).assertTrue(); + } catch(err) { + console.info('fileio_randomaccessfile_write_sync_011 has failed for ' + err); + expect(err.message == "Invalid buffer/options").assertTrue(); + randomaccessfile.closeSync(); + fileio.unlinkSync(fpath); + } + }); + + /** + * @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_WRITE_SYNC_1200 + * @tc.name fileio_randomaccessfile_write_sync_012 + * @tc.desc Test writeSync() interface. When the length is greater than the buffer length. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_randomaccessfile_write_sync_012', 0, async function () { + let fpath = await nextFileName('fileio_randomaccessfile_write_sync_012'); + let randomaccessfile = fileio.createRandomAccessFileSync(fpath, 0, 0o102); + + try { + let length = 4096; + randomaccessfile.writeSync(new ArrayBuffer(length), { length: length + 1 }); + expect(false).assertTrue(); + } catch(err) { + console.info('fileio_randomaccessfile_write_sync_012 has failed for ' + err); + expect(err.message == "Invalid buffer/options").assertTrue(); + randomaccessfile.closeSync(); + fileio.unlinkSync(fpath); + } + }); + + /** + * @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_WRITE_SYNC_1300 + * @tc.name fileio_randomaccessfile_write_sync_013 + * @tc.desc Test writeSync() interface. When the position is negative. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_randomaccessfile_write_sync_013', 0, async function () { + let fpath = await nextFileName('fileio_randomaccessfile_write_sync_013'); + let randomaccessfile = fileio.createRandomAccessFileSync(fpath, 0, 0o102); + + try { + randomaccessfile.writeSync(new ArrayBuffer(4096), { position: -1 }); + expect(false).assertTrue(); + } catch(err) { + console.info('fileio_randomaccessfile_write_sync_013 has failed for ' + err); + expect(err.message == "Invalid buffer/options").assertTrue(); + randomaccessfile.closeSync(); + fileio.unlinkSync(fpath); + } + }); + + /** + * @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_WRITE_ASYNC_0000 + * @tc.name fileio_randomaccessfile_write_async_000 + * @tc.desc Test write() interface. return in promise mode. Test write data asynchronously. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_randomaccessfile_write_async_000', 0, async function (done) { + let fpath = await nextFileName('fileio_randomaccessfile_write_async_000'); + + try { + fileio.createRandomAccessFile(fpath, 0, 0o102, async function(err, randomaccessfile) { + let length = 4096; + let num = await randomaccessfile.write(new ArrayBuffer(length)); + expect(num == length).assertTrue(); + randomaccessfile.closeSync(); + fileio.unlinkSync(fpath); + done(); + }); + } catch(err) { + console.info('fileio_randomaccessfile_write_async_000 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_WRITE_ASYNC_0100 + * @tc.name fileio_randomaccessfile_write_async_001 + * @tc.desc Test write() interface. When the offset is 1. return in callback mode. Test write data asynchronously. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_randomaccessfile_write_async_001', 0, async function (done) { + let fpath = await nextFileName('fileio_randomaccessfile_write_async_001'); + + try { + let fd = fileio.openSync(fpath, 0o102, 0o666); + let randomaccessfile = await fileio.createRandomAccessFile(fd, 0); + let length = 20; + randomaccessfile.write(new ArrayBuffer(length), { offset: 1 }, function(err, bytesWritten) { + expect(bytesWritten == length - 1).assertTrue(); + randomaccessfile.closeSync(); + fileio.unlinkSync(fpath); + done(); + }); + } catch(err) { + console.info('fileio_randomaccessfile_write_async_001 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_WRITE_ASYNC_0200 + * @tc.name fileio_randomaccessfile_write_async_002 + * @tc.desc Test write() interface. When the position is 1. Test write data asynchronously. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_randomaccessfile_write_async_002', 0, async function (done) { + let fpath = await nextFileName('fileio_randomaccessfile_write_async_002'); + + try { + let randomaccessfile = await fileio.createRandomAccessFile(fpath, 0, 0o102); + let length = 20; + let num = await randomaccessfile.write(new ArrayBuffer(length), { position: 1 }); + expect(num == length).assertTrue(); + randomaccessfile.closeSync(); + fileio.unlinkSync(fpath); + done(); + } catch(err) { + console.info('fileio_randomaccessfile_write_async_002 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_WRITE_ASYNC_0300 + * @tc.name fileio_randomaccessfile_write_async_003 + * @tc.desc Test write() interface. When the offset is 1 and length is 10. Test write data asynchronously. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_randomaccessfile_write_async_003', 0, async function (done) { + let fpath = await nextFileName('fileio_randomaccessfile_write_async_003'); + + try { + let randomaccessfile = await fileio.createRandomAccessFile(fpath, 0, 0o102); + let length = 20; + let num = await randomaccessfile.write(new ArrayBuffer(length), { offset: 1, length: 10 }); + expect(num == 10).assertTrue(); + randomaccessfile.closeSync(); + fileio.unlinkSync(fpath); + done(); + } catch(err) { + console.info('fileio_randomaccessfile_write_async_003 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_WRITE_ASYNC_0400 + * @tc.name fileio_randomaccessfile_write_async_004 + * @tc.desc Test write() interface. When the offset is 1 and position is 5. Test write data asynchronously. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_randomaccessfile_write_async_004', 0, async function (done) { + let fpath = await nextFileName('fileio_randomaccessfile_write_async_004'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let randomaccessfile = await fileio.createRandomAccessFile(fpath, 0, 0o102); + let length = 20; + let options = { + offset: 1, + position:5 + } + let num = await randomaccessfile.write(new ArrayBuffer(length), options); + expect(num == length - 1).assertTrue(); + randomaccessfile.setFilePointerSync(0); + let readOut = await randomaccessfile.read(new ArrayBuffer(4096)); + expect(readOut.bytesRead == (length - options.offset + options.position)).assertTrue(); + randomaccessfile.closeSync(); + fileio.unlinkSync(fpath); + done(); + } catch(err) { + console.info('fileio_randomaccessfile_write_async_004 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_WRITE_ASYNC_0500 + * @tc.name fileio_randomaccessfile_write_async_005 + * @tc.desc Test write() interface. When offset equals buffer length. Test write data asynchronously. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_randomaccessfile_write_async_005', 0, async function (done) { + let fpath = await nextFileName('fileio_randomaccessfile_write_async_005'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let randomaccessfile = await fileio.createRandomAccessFile(fpath, 0, 0o102); + let length = 4096; + let num = await randomaccessfile.write(new ArrayBuffer(length), { offset: length }); + expect(num == 0).assertTrue(); + randomaccessfile.closeSync(); + fileio.unlinkSync(fpath); + done(); + } catch(err) { + console.info('fileio_randomaccessfile_write_async_005 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_WRITE_ASYNC_0600 + * @tc.name fileio_randomaccessfile_write_async_006 + * @tc.desc Test write() interface. When offset+length>buffer.size. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_randomaccessfile_write_async_006', 0, async function (done) { + let fpath = await nextFileName('fileio_randomaccessfile_write_async_006'); + let randomaccessfile = await fileio.createRandomAccessFile(fpath, 0, 0o102); + + try { + let length = 4096; + await randomaccessfile.write(new ArrayBuffer(length), { offset: 5, length: 4095 }); + } catch(err) { + console.info('fileio_randomaccessfile_write_async_006 has failed for ' + err); + expect(err.message == "Invalid buffer/options").assertTrue(); + randomaccessfile.closeSync(); + fileio.unlinkSync(fpath); + done(); + } + }); + + /** + * @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_WRITE_ASYNC_0700 + * @tc.name fileio_randomaccessfile_write_async_007 + * @tc.desc Test write() interface. When the offset is greater than the buffer length. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_randomaccessfile_write_async_007', 0, async function (done) { + let fpath = await nextFileName('fileio_randomaccessfile_write_async_007'); + let randomaccessfile = await fileio.createRandomAccessFile(fpath, 0, 0o102); + + try { + let length = 4096; + randomaccessfile.write(new ArrayBuffer(length), { offset: length + 1 }, function(err) { + }); + } catch(err) { + console.info('fileio_randomaccessfile_write_async_007 has failed for ' + err); + expect(err.message == "Invalid buffer/options").assertTrue(); + randomaccessfile.closeSync(); + fileio.unlinkSync(fpath); + done(); + } + }); + + /** + * @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_WRITE_ASYNC_0800 + * @tc.name fileio_randomaccessfile_write_async_008 + * @tc.desc Test write() interface. When there are no parameters. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_randomaccessfile_write_async_008', 0, async function (done) { + let fpath = await nextFileName('fileio_randomaccessfile_write_async_008'); + let randomaccessfile = await fileio.createRandomAccessFile(fpath, 0, 0o102); + + try { + await randomaccessfile.write(); + } catch(err) { + console.info('fileio_randomaccessfile_write_async_008 has failed for ' + err); + expect(err.message == "Number of arguments unmatched").assertTrue(); + randomaccessfile.closeSync(); + fileio.unlinkSync(fpath); + done(); + } + }); + + /** + * @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_WRITE_ASYNC_0900 + * @tc.name fileio_randomaccessfile_write_async_009 + * @tc.desc Test write() interface. When the offset is negative. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_randomaccessfile_write_async_009', 0, async function (done) { + let fpath = await nextFileName('fileio_randomaccessfile_write_async_009'); + let fd = fileio.openSync(fpath, 0o102, 0o666); + let randomaccessfile = await fileio.createRandomAccessFile(fd, 0); + + try { + await randomaccessfile.write(new ArrayBuffer(4096), { offset: -1 }); + } catch(err) { + console.info('fileio_randomaccessfile_write_async_009 has failed for ' + err); + expect(err.message == "Invalid buffer/options").assertTrue(); + randomaccessfile.closeSync(); + fileio.unlinkSync(fpath); + done(); + } + }); + + /** + * @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_WRITE_ASYNC_1000 + * @tc.name fileio_randomaccessfile_write_async_010 + * @tc.desc Test write() interface. The "length" of option must > 0. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_randomaccessfile_write_async_010', 0, async function (done) { + let fpath = await nextFileName('fileio_randomaccessfile_write_async_010'); + let randomaccessfile; + + try { + randomaccessfile = await fileio.createRandomAccessFile(fpath, 0, 0o102); + let length = 100; + await randomaccessfile.write(new ArrayBuffer(length), { offset: 1, length: -1 }); + expect(false).assertTrue(); + } catch(err) { + randomaccessfile.closeSync(); + fileio.unlinkSync(fpath); + console.info('fileio_randomaccessfile_write_async_010 has failed for ' + err); + expect(err.message == "Invalid buffer/options").assertTrue(); + done(); + } + }); + + /** + * @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_WRITE_ASYNC_1100 + * @tc.name fileio_randomaccessfile_write_async_011 + * @tc.desc Test write() interface. When the buffer parameter type is wrong. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_randomaccessfile_write_async_011', 0, async function (done) { + let fpath = await nextFileName('fileio_randomaccessfile_write_async_011'); + let randomaccessfile = await fileio.createRandomAccessFile(fpath, 0, 0o102); + + try { + await randomaccessfile.write(10, { length: -1 }); + } catch(err) { + console.info('fileio_randomaccessfile_write_async_011 has failed for ' + err); + expect(err.message == "Invalid buffer/options").assertTrue(); + randomaccessfile.closeSync(); + fileio.unlinkSync(fpath); + done(); + } + }); + + /** + * @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_WRITE_ASYNC_1200 + * @tc.name fileio_randomaccessfile_write_async_012 + * @tc.desc Test write() interface. When the length is greater than the buffer length. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_randomaccessfile_write_async_012', 0, async function (done) { + let fpath = await nextFileName('fileio_randomaccessfile_write_async_012'); + let randomaccessfile = await fileio.createRandomAccessFile(fpath, 0, 0o102); + + try { + let length = 4096; + await randomaccessfile.write(new ArrayBuffer(length), { length: length + 1 }); + } catch(err) { + console.info('fileio_randomaccessfile_write_async_012 has failed for ' + err); + expect(err.message == "Invalid buffer/options").assertTrue(); + randomaccessfile.closeSync(); + fileio.unlinkSync(fpath); + done(); + } + }); + + /** + * @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_WRITE_ASYNC_1300 + * @tc.name fileio_randomaccessfile_write_async_013 + * @tc.desc Test write() interface. When the position is negative. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_randomaccessfile_write_async_013', 0, async function (done) { + let fpath = await nextFileName('fileio_randomaccessfile_write_async_013'); + let randomaccessfile = await fileio.createRandomAccessFile(fpath, 0, 0o102); + + try { + await randomaccessfile.write(new ArrayBuffer(4096), { position: -1 }); + } catch(err) { + console.info('fileio_randomaccessfile_write_async_013 has failed for ' + err); + expect(err.message == "Invalid buffer/options").assertTrue(); + randomaccessfile.closeSync(); + fileio.unlinkSync(fpath); + done(); + } + }); +}) } \ No newline at end of file diff --git a/storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/class_stream/all.test.js b/storage/storagefileiojstest/src/main/js/test/module_fileio/class_stream/all.test.js similarity index 96% rename from storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/class_stream/all.test.js rename to storage/storagefileiojstest/src/main/js/test/module_fileio/class_stream/all.test.js index 08a87cc7006e64502cb86c56121590c378568263..311e185810e9ed5148d6bb81dbedbe4e321bb8c0 100644 --- a/storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/class_stream/all.test.js +++ b/storage/storagefileiojstest/src/main/js/test/module_fileio/class_stream/all.test.js @@ -1,304 +1,304 @@ -/* - * Copyright (C) 2023 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 { - fileio, FILE_CONTENT, prepareFile, nextFileName, - describe, it, expect, -} from '../../Common'; - -export default function fileioStream() { -describe('fileio_stream_1', function () { - - /** - * @tc.number SUB_DF_FILEIO_STREAM_CREATESTREAMSYNC_0000 - * @tc.name fileio_test_stream_create_stream_sync_000 - * @tc.desc Test createStreamSync() interface, Open read-write file. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_stream_create_stream_sync_000', 0, async function () { - let fpath = await nextFileName('fileio_test_stream_create_stream_sync_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let ss = fileio.createStreamSync(fpath, 'r+'); - expect(ss !== null).assertTrue(); - ss.closeSync(); - fileio.unlinkSync(fpath); - } catch (err) { - console.info('fileio_test_stream_create_stream_sync_000 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_STREAM_CREATESTREAMSYNC_0100 - * @tc.name fileio_test_stream_create_stream_sync_001 - * @tc.desc Test createStreamSync() interface, When file does not exist. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_stream_create_stream_sync_001', 0, async function () { - let fpath = await nextFileName('fileio_test_stream_create_stream_sync_001'); - - try { - fileio.createStreamSync(fpath, 'r+'); - } catch (err) { - console.info('fileio_test_stream_create_stream_sync_001 has failed for ' + err); - expect(err.message == "No such file or directory").assertTrue(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_STREAM_CREATESTREAMSYNC_0200 - * @tc.name fileio_test_stream_create_stream_sync_002 - * @tc.desc Test createStreamSync() interface, When mode is invalid. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_stream_create_stream_sync_002', 0, async function () { - let fpath = await nextFileName('fileio_test_stream_create_stream_sync_002'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - fileio.createStreamSync(fpath, 'ohos'); - } catch (err) { - console.info('fileio_test_stream_create_stream_sync_002 has failed for ' + err); - expect(err.message == "Invalid argument").assertTrue(); - fileio.unlinkSync(fpath); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_STREAM_READSYNC_0000 - * @tc.name fileio_test_stream_read_sync_000 - * @tc.desc Test readSync() interface, read data from stream file. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_stream_read_sync_000', 0, async function () { - let fpath = await nextFileName('fileio_test_stream_read_sync_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let ss = fileio.createStreamSync(fpath, 'r+'); - expect(ss !== null).assertTrue(); - let len = ss.readSync(new ArrayBuffer(4096)); - expect(len == FILE_CONTENT.length).assertTrue(); - ss.closeSync(); - fileio.unlinkSync(fpath); - } catch (err) { - console.info('fileio_test_stream_read_sync_000 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_STREAM_READSYNC_0100 - * @tc.name fileio_test_stream_read_sync_001 - * @tc.desc Test the readSync method of class Stream,When offset equals buffer length.. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_stream_read_sync_001', 0, async function () { - let fpath = await nextFileName('fileio_test_stream_read_sync_001'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let ss = fileio.createStreamSync(fpath, 'r+'); - let len = ss.readSync(new ArrayBuffer(4096), { - offset: 4096 - }); - expect(len == 0).assertTrue(); - ss.closeSync(); - fileio.unlinkSync(fpath); - } catch (err) { - console.info('fileio_test_stream_read_sync_001 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_STREAM_READSYNC_0200 - * @tc.name fileio_test_stream_read_sync_002 - * @tc.desc Test the readSync method of class Stream,When the length is 1. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_stream_read_sync_002', 0, async function () { - let fpath = await nextFileName('fileio_test_stream_read_sync_002'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let ss = fileio.createStreamSync(fpath, 'r+'); - let len = ss.readSync(new ArrayBuffer(4096), { - length: 1 - }); - expect(len == 1).assertTrue(); - ss.closeSync(); - fileio.unlinkSync(fpath); - } catch (err) { - console.info('fileio_test_stream_read_sync_002 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_STREAM_READSYNC_0300 - * @tc.name fileio_test_stream_read_sync_003 - * @tc.desc Test the readSync method of class Stream,When the position is 1. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_stream_read_sync_003', 0, async function () { - let fpath = await nextFileName('fileio_test_stream_read_sync_003'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let ss = fileio.createStreamSync(fpath, 'r+'); - let len = ss.readSync(new ArrayBuffer(4096), { - position: 1 - }); - expect(len == (FILE_CONTENT.length - 1)).assertTrue(); - ss.closeSync(); - fileio.unlinkSync(fpath); - } catch (err) { - console.info('fileio_test_stream_read_sync_003 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_STREAM_READSYNC_0400 - * @tc.name fileio_test_stream_read_sync_004 - * @tc.desc Test the readSync method of class Stream,When the offset is greater than the buffer length. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_stream_read_sync_004', 0, async function () { - let ss; - let fpath = await nextFileName('fileio_test_stream_read_sync_004'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - ss = fileio.createStreamSync(fpath, 'r+'); - ss.readSync(new ArrayBuffer(4096), { - offset: 4097 - }); - } catch (err) { - console.info('fileio_test_stream_read_sync_004 has failed for ' + err); - expect(err.message == "Invalid option.offset, buffer limit exceeded").assertTrue(); - ss.closeSync(); - fileio.unlinkSync(fpath); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_STREAM_READSYNC_0500 - * @tc.name fileio_test_stream_read_sync_005 - * @tc.desc Test the readSync method of class Stream, When the length is greater than the buffer length. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_stream_read_sync_005', 0, async function () { - let ss; - let fpath = await nextFileName('fileio_test_stream_read_sync_005'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - ss = fileio.createStreamSync(fpath, 'r+'); - ss.readSync(new ArrayBuffer(4096), { - length: 4097 - }); - } catch (err) { - console.info('fileio_test_stream_read_sync_005 has failed for ' + err); - expect(err.message == "Invalid option.length").assertTrue(); - ss.closeSync(); - fileio.unlinkSync(fpath); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_STREAM_READSYNC_0600 - * @tc.name fileio_test_stream_read_sync_006 - * @tc.desc Test the readSync method of class Stream. - * When position is equal to the length of the file content plus one. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_stream_read_sync_006', 0, async function () { - let fpath = await nextFileName('fileio_test_stream_read_sync_006'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let ss = fileio.createStreamSync(fpath, 'r+'); - let invalidPos = FILE_CONTENT.length + 1; - let len = ss.readSync(new ArrayBuffer(4096), { - position: invalidPos - }); - expect(len == 0).assertTrue(); - ss.closeSync(); - fileio.unlinkSync(fpath); - } catch (err) { - console.info('fileio_test_stream_read_sync_006 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_STREAM_WRITESYNC_0000 - * @tc.name fileio_test_stream_write_sync_000 - * @tc.desc Test writeSync() interface, Write data to stream file. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_stream_write_sync_000', 0, async function () { - let fpath = await nextFileName('fileio_test_stream_write_sync_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let ss = fileio.createStreamSync(fpath, 'r+'); - expect(ss !== null).assertTrue(); - expect(ss.writeSync(FILE_CONTENT) == FILE_CONTENT.length).assertTrue(); - ss.closeSync(); - fileio.unlinkSync(fpath); - } catch (err) { - console.info('fileio_test_stream_write_sync_000 has failed for ' + err); - expect(null).assertFail(); - } - }); -});} +/* + * Copyright (C) 2021 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 { + fileio, FILE_CONTENT, prepareFile, nextFileName, + describe, it, expect, +} from '../../Common'; + +export default function fileioStream() { +describe('fileio_stream_1', function () { + + /** + * @tc.number SUB_DF_FILEIO_STREAM_CREATESTREAMSYNC_0000 + * @tc.name fileio_test_stream_create_stream_sync_000 + * @tc.desc Test createStreamSync() interface, Open read-write file. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_stream_create_stream_sync_000', 0, async function () { + let fpath = await nextFileName('fileio_test_stream_create_stream_sync_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let ss = fileio.createStreamSync(fpath, 'r+'); + expect(ss !== null).assertTrue(); + ss.closeSync(); + fileio.unlinkSync(fpath); + } catch (err) { + console.info('fileio_test_stream_create_stream_sync_000 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STREAM_CREATESTREAMSYNC_0100 + * @tc.name fileio_test_stream_create_stream_sync_001 + * @tc.desc Test createStreamSync() interface, When file does not exist. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_stream_create_stream_sync_001', 0, async function () { + let fpath = await nextFileName('fileio_test_stream_create_stream_sync_001'); + + try { + fileio.createStreamSync(fpath, 'r+'); + } catch (err) { + console.info('fileio_test_stream_create_stream_sync_001 has failed for ' + err); + expect(err.message == "No such file or directory").assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STREAM_CREATESTREAMSYNC_0200 + * @tc.name fileio_test_stream_create_stream_sync_002 + * @tc.desc Test createStreamSync() interface, When mode is invalid. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_stream_create_stream_sync_002', 0, async function () { + let fpath = await nextFileName('fileio_test_stream_create_stream_sync_002'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + fileio.createStreamSync(fpath, 'ohos'); + } catch (err) { + console.info('fileio_test_stream_create_stream_sync_002 has failed for ' + err); + expect(err.message == "Invalid argument").assertTrue(); + fileio.unlinkSync(fpath); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STREAM_READSYNC_0000 + * @tc.name fileio_test_stream_read_sync_000 + * @tc.desc Test readSync() interface, read data from stream file. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_stream_read_sync_000', 0, async function () { + let fpath = await nextFileName('fileio_test_stream_read_sync_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let ss = fileio.createStreamSync(fpath, 'r+'); + expect(ss !== null).assertTrue(); + let len = ss.readSync(new ArrayBuffer(4096)); + expect(len == FILE_CONTENT.length).assertTrue(); + ss.closeSync(); + fileio.unlinkSync(fpath); + } catch (err) { + console.info('fileio_test_stream_read_sync_000 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STREAM_READSYNC_0100 + * @tc.name fileio_test_stream_read_sync_001 + * @tc.desc Test the readSync method of class Stream,When offset equals buffer length.. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_stream_read_sync_001', 0, async function () { + let fpath = await nextFileName('fileio_test_stream_read_sync_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let ss = fileio.createStreamSync(fpath, 'r+'); + let len = ss.readSync(new ArrayBuffer(4096), { + offset: 4096 + }); + expect(len == 0).assertTrue(); + ss.closeSync(); + fileio.unlinkSync(fpath); + } catch (err) { + console.info('fileio_test_stream_read_sync_001 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STREAM_READSYNC_0200 + * @tc.name fileio_test_stream_read_sync_002 + * @tc.desc Test the readSync method of class Stream,When the length is 1. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_stream_read_sync_002', 0, async function () { + let fpath = await nextFileName('fileio_test_stream_read_sync_002'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let ss = fileio.createStreamSync(fpath, 'r+'); + let len = ss.readSync(new ArrayBuffer(4096), { + length: 1 + }); + expect(len == 1).assertTrue(); + ss.closeSync(); + fileio.unlinkSync(fpath); + } catch (err) { + console.info('fileio_test_stream_read_sync_002 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STREAM_READSYNC_0300 + * @tc.name fileio_test_stream_read_sync_003 + * @tc.desc Test the readSync method of class Stream,When the position is 1. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_stream_read_sync_003', 0, async function () { + let fpath = await nextFileName('fileio_test_stream_read_sync_003'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let ss = fileio.createStreamSync(fpath, 'r+'); + let len = ss.readSync(new ArrayBuffer(4096), { + position: 1 + }); + expect(len == (FILE_CONTENT.length - 1)).assertTrue(); + ss.closeSync(); + fileio.unlinkSync(fpath); + } catch (err) { + console.info('fileio_test_stream_read_sync_003 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STREAM_READSYNC_0400 + * @tc.name fileio_test_stream_read_sync_004 + * @tc.desc Test the readSync method of class Stream,When the offset is greater than the buffer length. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_stream_read_sync_004', 0, async function () { + let ss; + let fpath = await nextFileName('fileio_test_stream_read_sync_004'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + ss = fileio.createStreamSync(fpath, 'r+'); + ss.readSync(new ArrayBuffer(4096), { + offset: 4097 + }); + } catch (err) { + console.info('fileio_test_stream_read_sync_004 has failed for ' + err); + expect(err.message == "Invalid option.offset, buffer limit exceeded").assertTrue(); + ss.closeSync(); + fileio.unlinkSync(fpath); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STREAM_READSYNC_0500 + * @tc.name fileio_test_stream_read_sync_005 + * @tc.desc Test the readSync method of class Stream, When the length is greater than the buffer length. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_stream_read_sync_005', 0, async function () { + let ss; + let fpath = await nextFileName('fileio_test_stream_read_sync_005'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + ss = fileio.createStreamSync(fpath, 'r+'); + ss.readSync(new ArrayBuffer(4096), { + length: 4097 + }); + } catch (err) { + console.info('fileio_test_stream_read_sync_005 has failed for ' + err); + expect(err.message == "Invalid option.length").assertTrue(); + ss.closeSync(); + fileio.unlinkSync(fpath); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STREAM_READSYNC_0600 + * @tc.name fileio_test_stream_read_sync_006 + * @tc.desc Test the readSync method of class Stream. + * When position is equal to the length of the file content plus one. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_stream_read_sync_006', 0, async function () { + let fpath = await nextFileName('fileio_test_stream_read_sync_006'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let ss = fileio.createStreamSync(fpath, 'r+'); + let invalidPos = FILE_CONTENT.length + 1; + let len = ss.readSync(new ArrayBuffer(4096), { + position: invalidPos + }); + expect(len == 0).assertTrue(); + ss.closeSync(); + fileio.unlinkSync(fpath); + } catch (err) { + console.info('fileio_test_stream_read_sync_006 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STREAM_WRITESYNC_0000 + * @tc.name fileio_test_stream_write_sync_000 + * @tc.desc Test writeSync() interface, Write data to stream file. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_stream_write_sync_000', 0, async function () { + let fpath = await nextFileName('fileio_test_stream_write_sync_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let ss = fileio.createStreamSync(fpath, 'r+'); + expect(ss !== null).assertTrue(); + expect(ss.writeSync(FILE_CONTENT) == FILE_CONTENT.length).assertTrue(); + ss.closeSync(); + fileio.unlinkSync(fpath); + } catch (err) { + console.info('fileio_test_stream_write_sync_000 has failed for ' + err); + expect(null).assertFail(); + } + }); +});} diff --git a/storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/class_stream/close.test.js b/storage/storagefileiojstest/src/main/js/test/module_fileio/class_stream/close.test.js similarity index 95% rename from storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/class_stream/close.test.js rename to storage/storagefileiojstest/src/main/js/test/module_fileio/class_stream/close.test.js index 7f92a7fbd9d78499742495a2833ac763aaac8f75..493c7a5c83546277e4964a1d5e239c499f8b4287 100644 --- a/storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/class_stream/close.test.js +++ b/storage/storagefileiojstest/src/main/js/test/module_fileio/class_stream/close.test.js @@ -1,125 +1,125 @@ -/* - * Copyright (C) 2023 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 { - fileio, FILE_CONTENT, prepareFile, nextFileName, - describe, it, expect, -} from '../../Common'; - -export default function fileioStreamClose() { -describe('fileio_stream_close', function () { - - /** - * @tc.number SUB_DF_FILEIO_STREAM_CLOSESYNC_0000 - * @tc.name fileio_test_stream_close_sync_000 - * @tc.desc Test closeSync() interface,Close file stream. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_stream_close_sync_000', 0, async function () { - let fpath = await nextFileName('fileio_test_stream_close_sync_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let fd = fileio.openSync(fpath, 0o2); - let ss = fileio.fdopenStreamSync(fd, 'r+'); - expect(ss !== null).assertTrue(); - ss.closeSync(); - fileio.unlinkSync(fpath); - } catch (err) { - console.info('fileio_test_stream_close_sync_000 has failed for ' + err); - expect(null).assertFail(); - } - }) - - /** - * @tc.number SUB_DF_FILEIO_STREAM_CLOSESYNC_0100 - * @tc.name fileio_test_stream_close_sync_001 - * @tc.desc Test closeSync() interface,When there are parameters. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_stream_close_sync_001', 0, async function () { - let fpath = await nextFileName('fileio_test_stream_close_sync_001'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let fd = fileio.openSync(fpath, 0o2); - let ss = fileio.fdopenStreamSync(fd, 'r+'); - expect(ss !== null).assertTrue(); - ss.closeSync(1); - } catch (err) { - console.info('fileio_test_stream_close_sync_001 has failed for ' + err); - expect(err.message == "Number of arguments unmatched").assertTrue(); - fileio.unlinkSync(fpath); - } - }) - - /** - * @tc.number SUB_DF_FILEIO_STREAM_CLOSEASYNC_0000 - * @tc.name fileio_test_stream_close_async_000 - * @tc.desc Test close() interface,return in promise mode. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_stream_close_async_000', 0, async function (done) { - let fpath = await nextFileName('fileio_test_stream_close_async_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let fd = fileio.openSync(fpath, 0o2); - let ss = fileio.fdopenStreamSync(fd, 'r+'); - expect(ss !== null).assertTrue(); - await ss.close(); - fileio.unlinkSync(fpath); - done(); - } catch (err) { - console.info('fileio_test_stream_close_async_000 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_STREAM_CLOSEASYNC_0100 - * @tc.name fileio_test_stream_close_async_001 - * @tc.desc Test close() interface,return in callback mode. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_stream_close_async_001', 0, async function (done) { - let fpath = await nextFileName('fileio_test_stream_close_async_001'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let fd = fileio.openSync(fpath, 0o2); - let ss = fileio.fdopenStreamSync(fd, 'r+'); - expect(ss !== null).assertTrue(); - ss.close(function (err) { - fileio.unlinkSync(fpath); - }) - done(); - } catch (err) { - console.info('fileio_test_stream_close_async_001 has failed for ' + err); - expect(null).assertFail(); - } - }); -});} +/* + * Copyright (C) 2021 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 { + fileio, FILE_CONTENT, prepareFile, nextFileName, + describe, it, expect, +} from '../../Common'; + +export default function fileioStreamClose() { +describe('fileio_stream_close', function () { + + /** + * @tc.number SUB_DF_FILEIO_STREAM_CLOSESYNC_0000 + * @tc.name fileio_test_stream_close_sync_000 + * @tc.desc Test closeSync() interface,Close file stream. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_stream_close_sync_000', 0, async function () { + let fpath = await nextFileName('fileio_test_stream_close_sync_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath, 0o2); + let ss = fileio.fdopenStreamSync(fd, 'r+'); + expect(ss !== null).assertTrue(); + ss.closeSync(); + fileio.unlinkSync(fpath); + } catch (err) { + console.info('fileio_test_stream_close_sync_000 has failed for ' + err); + expect(null).assertFail(); + } + }) + + /** + * @tc.number SUB_DF_FILEIO_STREAM_CLOSESYNC_0100 + * @tc.name fileio_test_stream_close_sync_001 + * @tc.desc Test closeSync() interface,When there are parameters. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_stream_close_sync_001', 0, async function () { + let fpath = await nextFileName('fileio_test_stream_close_sync_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let fd = fileio.openSync(fpath, 0o2); + let ss = fileio.fdopenStreamSync(fd, 'r+'); + expect(ss !== null).assertTrue(); + ss.closeSync(1); + } catch (err) { + console.info('fileio_test_stream_close_sync_001 has failed for ' + err); + expect(err.message == "Number of arguments unmatched").assertTrue(); + fileio.unlinkSync(fpath); + } + }) + + /** + * @tc.number SUB_DF_FILEIO_STREAM_CLOSEASYNC_0000 + * @tc.name fileio_test_stream_close_async_000 + * @tc.desc Test close() interface,return in promise mode. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_stream_close_async_000', 0, async function (done) { + let fpath = await nextFileName('fileio_test_stream_close_async_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath, 0o2); + let ss = fileio.fdopenStreamSync(fd, 'r+'); + expect(ss !== null).assertTrue(); + await ss.close(); + fileio.unlinkSync(fpath); + done(); + } catch (err) { + console.info('fileio_test_stream_close_async_000 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STREAM_CLOSEASYNC_0100 + * @tc.name fileio_test_stream_close_async_001 + * @tc.desc Test close() interface,return in callback mode. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_stream_close_async_001', 0, async function (done) { + let fpath = await nextFileName('fileio_test_stream_close_async_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath, 0o2); + let ss = fileio.fdopenStreamSync(fd, 'r+'); + expect(ss !== null).assertTrue(); + ss.close(function (err) { + fileio.unlinkSync(fpath); + }) + done(); + } catch (err) { + console.info('fileio_test_stream_close_async_001 has failed for ' + err); + expect(null).assertFail(); + } + }); +});} diff --git a/storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/class_stream/flush.test.js b/storage/storagefileiojstest/src/main/js/test/module_fileio/class_stream/flush.test.js similarity index 96% rename from storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/class_stream/flush.test.js rename to storage/storagefileiojstest/src/main/js/test/module_fileio/class_stream/flush.test.js index 1ba834d55dad74fe6083fc2c4da69002149a1421..62eab7098f43fbebe91d66871f4c63bbaad28e89 100644 --- a/storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/class_stream/flush.test.js +++ b/storage/storagefileiojstest/src/main/js/test/module_fileio/class_stream/flush.test.js @@ -1,134 +1,134 @@ -/* - * Copyright (C) 2023 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 { - fileio, FILE_CONTENT, prepareFile, nextFileName, - describe, it, expect, -} from '../../Common'; - -export default function fileioStreamFlush() { -describe('fileio_stream_flush', function () { - - /** - * @tc.number SUB_DF_FILEIO_STREAM_FLUSHSYNC_0000 - * @tc.name fileio_test_stream_flush_sync_000 - * @tc.desc Test flushSync() interface, refresh file stream. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_stream_flush_sync_000', 0, async function () { - let fpath = await nextFileName('fileio_test_stream_flush_sync_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let ss = fileio.createStreamSync(fpath, 'r+'); - expect(ss !== null).assertTrue(); - expect(ss.writeSync(FILE_CONTENT) == FILE_CONTENT.length).assertTrue(); - ss.flushSync(); - ss.closeSync(); - fileio.unlinkSync(fpath); - } catch (err) { - console.info('fileio_test_stream_flush_sync_000 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_STREAM_FLUSHSYNC_0100 - * @tc.name fileio_test_stream_flush_sync_001 - * @tc.desc Test flushSync() interface, When there are parameters. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_stream_flush_sync_001', 0, async function () { - let fpath = await nextFileName('fileio_test_stream_flush_sync_001'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - let ss = fileio.createStreamSync(fpath, 'r+'); - expect(ss !== null).assertTrue(); - expect(ss.writeSync(FILE_CONTENT) == FILE_CONTENT.length).assertTrue(); - try { - ss.flushSync(1); - } catch (err) { - console.info('fileio_test_stream_flush_sync_001 has failed for ' + err); - expect(err.message == "Number of arguments unmatched").assertTrue(); - ss.closeSync(); - fileio.unlinkSync(fpath); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_STREAM_FLUSHASYNC_0000 - * @tc.name fileio_test_stream_flush_async_000 - * @tc.desc Test flush() interface, refresh the file stream and return in promise mode. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_stream_flush_async_000', 0, async function (done) { - let fpath = await nextFileName('fileio_test_stream_flush_async_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let ss = fileio.createStreamSync(fpath, 'r+'); - expect(ss !== null).assertTrue(); - expect(ss.writeSync(FILE_CONTENT) == FILE_CONTENT.length).assertTrue(); - ss.flush().then( - function (err) { - ss.closeSync(); - fileio.unlinkSync(fpath); - }) - done(); - } catch (err) { - console.info('fileio_test_stream_flush_async_000 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_STREAM_FLUSHASYNC_0100 - * @tc.name fileio_test_stream_flush_async_001 - * @tc.desc Test flush() interface, refresh the file stream and return in callback mode. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_stream_flush_async_001', 0, async function (done) { - let fpath = await nextFileName('fileio_test_stream_flush_async_001'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let ss = fileio.createStreamSync(fpath, 'r+'); - expect(ss !== null).assertTrue(); - expect(ss.writeSync(FILE_CONTENT) == FILE_CONTENT.length).assertTrue(); - ss.flush(function (err) { - ss.closeSync(); - fileio.unlinkSync(fpath); - done(); - }) - } catch (err) { - console.info('fileio_test_stream_flush_async_001 has failed for ' + err); - expect(null).assertFail(); - } - }); - -}); -} +/* + * Copyright (C) 2021 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 { + fileio, FILE_CONTENT, prepareFile, nextFileName, + describe, it, expect, +} from '../../Common'; + +export default function fileioStreamFlush() { +describe('fileio_stream_flush', function () { + + /** + * @tc.number SUB_DF_FILEIO_STREAM_FLUSHSYNC_0000 + * @tc.name fileio_test_stream_flush_sync_000 + * @tc.desc Test flushSync() interface, refresh file stream. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_stream_flush_sync_000', 0, async function () { + let fpath = await nextFileName('fileio_test_stream_flush_sync_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let ss = fileio.createStreamSync(fpath, 'r+'); + expect(ss !== null).assertTrue(); + expect(ss.writeSync(FILE_CONTENT) == FILE_CONTENT.length).assertTrue(); + ss.flushSync(); + ss.closeSync(); + fileio.unlinkSync(fpath); + } catch (err) { + console.info('fileio_test_stream_flush_sync_000 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STREAM_FLUSHSYNC_0100 + * @tc.name fileio_test_stream_flush_sync_001 + * @tc.desc Test flushSync() interface, When there are parameters. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_stream_flush_sync_001', 0, async function () { + let fpath = await nextFileName('fileio_test_stream_flush_sync_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + let ss = fileio.createStreamSync(fpath, 'r+'); + expect(ss !== null).assertTrue(); + expect(ss.writeSync(FILE_CONTENT) == FILE_CONTENT.length).assertTrue(); + try { + ss.flushSync(1); + } catch (err) { + console.info('fileio_test_stream_flush_sync_001 has failed for ' + err); + expect(err.message == "Number of arguments unmatched").assertTrue(); + ss.closeSync(); + fileio.unlinkSync(fpath); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STREAM_FLUSHASYNC_0000 + * @tc.name fileio_test_stream_flush_async_000 + * @tc.desc Test flush() interface, refresh the file stream and return in promise mode. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_stream_flush_async_000', 0, async function (done) { + let fpath = await nextFileName('fileio_test_stream_flush_async_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let ss = fileio.createStreamSync(fpath, 'r+'); + expect(ss !== null).assertTrue(); + expect(ss.writeSync(FILE_CONTENT) == FILE_CONTENT.length).assertTrue(); + ss.flush().then( + function (err) { + ss.closeSync(); + fileio.unlinkSync(fpath); + }) + done(); + } catch (err) { + console.info('fileio_test_stream_flush_async_000 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STREAM_FLUSHASYNC_0100 + * @tc.name fileio_test_stream_flush_async_001 + * @tc.desc Test flush() interface, refresh the file stream and return in callback mode. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_stream_flush_async_001', 0, async function (done) { + let fpath = await nextFileName('fileio_test_stream_flush_async_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let ss = fileio.createStreamSync(fpath, 'r+'); + expect(ss !== null).assertTrue(); + expect(ss.writeSync(FILE_CONTENT) == FILE_CONTENT.length).assertTrue(); + ss.flush(function (err) { + ss.closeSync(); + fileio.unlinkSync(fpath); + done(); + }) + } catch (err) { + console.info('fileio_test_stream_flush_async_001 has failed for ' + err); + expect(null).assertFail(); + } + }); + +}); +} diff --git a/storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/class_stream/read.test.js b/storage/storagefileiojstest/src/main/js/test/module_fileio/class_stream/read.test.js similarity index 97% rename from storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/class_stream/read.test.js rename to storage/storagefileiojstest/src/main/js/test/module_fileio/class_stream/read.test.js index ab43e99457bd32b822580937aa5972948f3e929b..ab5eb02f998309adfa9e727c05d172c8fa10a66d 100644 --- a/storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/class_stream/read.test.js +++ b/storage/storagefileiojstest/src/main/js/test/module_fileio/class_stream/read.test.js @@ -1,628 +1,628 @@ -/* - * Copyright (C) 2023 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 { - fileio, FILE_CONTENT, prepareFile, nextFileName, - describe, it, expect, -} from '../../Common'; - -export default function fileioStreamRead() { -describe('fileio_stream_read', function () { - - /** - * @tc.number SUB_DF_FILEIO_STREAM_READSYNC_0000 - * @tc.name fileio_test_stream_read_sync_000 - * @tc.desc Test Stream.readSync() interface. - * Undefined option arguments, use default options. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 3 - * @tc.require - */ - it('fileio_test_stream_read_sync_000', 3, async function () { - let fpath = await nextFileName('fileio_test_stream_read_sync_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let sr = fileio.createStreamSync(fpath, 'r+'); - expect(sr !== null).assertTrue(); - let readLen1 = sr.readSync(new ArrayBuffer(16), undefined); - expect(readLen1 == FILE_CONTENT.length).assertTrue(); - let readLen2 = sr.readSync(new ArrayBuffer(8), undefined); - expect(readLen2 == 0).assertTrue(); - sr.closeSync(); - fileio.unlinkSync(fpath); - } catch (e) { - console.log('fileio_test_stream_read_sync_000 has failed for ' + e); - expect(false).assertTrue(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_STREAM_READSYNC_0100 - * @tc.name fileio_test_stream_read_sync_001 - * @tc.desc Test Stream.readSync() interface. - * Undefined option arguments, use default options. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 3 - * @tc.require - */ - it('fileio_test_stream_read_sync_001', 3, async function () { - let fpath = await nextFileName('fileio_test_stream_read_sync_001'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let sr = fileio.createStreamSync(fpath, 'r+'); - expect(sr !== null).assertTrue(); - let readLen1 = sr.readSync(new ArrayBuffer(16), { - offset: undefined, - length: undefined - }); - expect(readLen1 == FILE_CONTENT.length).assertTrue(); - let readLen2 = sr.readSync(new ArrayBuffer(8), { - offset: undefined, - length: undefined - }); - expect(readLen2 == 0).assertTrue(); - sr.closeSync(); - fileio.unlinkSync(fpath); - } catch (e) { - console.log('fileio_test_stream_read_sync_001 has failed for ' + e); - expect(false).assertTrue(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_STREAM_READASYNC_0000 - * @tc.name fileio_test_stream_read_async_000 - * @tc.desc Test read() interface,return in promise mode. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_stream_read_async_000', 0, async function (done) { - let fpath = await nextFileName('fileio_test_stream_read_async_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let ss = fileio.createStreamSync(fpath, 'r+'); - expect(ss !== null).assertTrue(); - let readout = await ss.read(new ArrayBuffer(4096)); - expect(readout.bytesRead == FILE_CONTENT.length).assertTrue(); - ss.closeSync(); - fileio.unlinkSync(fpath); - done(); - } catch (err) { - console.info('fileio_test_stream_read_async_000 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_STREAM_READASYNC_0100 - * @tc.name fileio_test_stream_read_async_001 - * @tc.desc Test read() interface, return in callback mode. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_stream_read_async_001', 0, async function () { - let fpath = await nextFileName('fileio_test_stream_read_async_001'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let ss = fileio.createStreamSync(fpath, 'r+'); - expect(ss !== null).assertTrue(); - ss.read(new ArrayBuffer(4096), null, function (err, readout) { - expect(readout.bytesRead == FILE_CONTENT.length).assertTrue(); - ss.closeSync(); - fileio.unlinkSync(fpath); - }); - } catch (err) { - console.info('fileio_test_stream_read_async_001 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_STREAM_READASYNC_0200 - * @tc.name fileio_test_stream_read_async_002 - * @tc.desc Test read() interface, When the offset is 1 and the length is 5. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_stream_read_async_002', 0, async function (done) { - let fpath = await nextFileName('fileio_test_stream_read_async_002'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let ss = fileio.createStreamSync(fpath, 'r+'); - expect(ss !== null).assertTrue(); - let options = { - offset: 1, - length: 5 - } - let readout = await ss.read(new ArrayBuffer(4096),options); - expect(readout.bytesRead == 5).assertTrue(); - ss.closeSync(); - fileio.unlinkSync(fpath); - done(); - } catch (err) { - console.info('fileio_test_stream_read_async_002 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_STREAM_READASYNC_0300 - * @tc.name fileio_test_stream_read_async_003 - * @tc.desc Test read() interface, When offset equals buffer length. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_stream_read_async_003', 0, async function (done) { - let fpath = await nextFileName('fileio_test_stream_read_async_003'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let ss = fileio.createStreamSync(fpath, 'r+'); - expect(ss !== null).assertTrue(); - let readout = await ss.read(new ArrayBuffer(4096), {offset: 4096}); - expect(readout.bytesRead == 0).assertTrue(); - expect(readout.offset == 4096).assertTrue(); - ss.closeSync(); - fileio.unlinkSync(fpath); - done(); - } catch (err) { - console.info('fileio_test_stream_read_async_003 has failed for ' + err); - expect(null).assertFail(); - } - }); - - - /** - * @tc.number SUB_DF_FILEIO_STREAM_READASYNC_0400 - * @tc.name fileio_test_stream_read_async_004 - * @tc.desc Test read() interface, When the offset is 1 and the position is 5. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_stream_read_async_004', 0, async function (done) { - let fpath = await nextFileName('fileio_test_stream_read_async_004'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let ss = fileio.createStreamSync(fpath, 'r+'); - expect(ss !== null).assertTrue(); - let options = { - offset: 1, - position:6 - } - let readout = await ss.read(new ArrayBuffer(4096),options); - expect(readout.bytesRead == FILE_CONTENT.length-6).assertTrue(); - expect(readout.offset == 1).assertTrue(); - let start = readout.offset; - let end = readout.offset+readout.bytesRead; - let result = String.fromCharCode.apply(null, new Uint8Array(readout.buffer.slice(start,end))); - expect(result== "world").assertTrue(); - ss.closeSync(); - fileio.unlinkSync(fpath); - done(); - } catch (err) { - console.info('fileio_test_stream_read_async_004 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_STREAM_READASYNC_0500 - * @tc.name fileio_test_stream_read_async_005 - * @tc.desc Test read() interface, When the offset is negative. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_stream_read_async_005', 0, async function (done) { - let fpath = await nextFileName('fileio_test_stream_read_async_005'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - let ss = fileio.createStreamSync(fpath, 'r+'); - expect(ss !== null).assertTrue(); - try { - await ss.read(new ArrayBuffer(4096), {offset: -1}); - } catch (err) { - console.info('fileio_test_stream_read_async_005 has failed for ' + err); - expect(err.message == "Invalid option.offset, positive integer is desired").assertTrue(); - ss.closeSync(); - fileio.unlinkSync(fpath); - done(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_STREAM_READASYNC_0600 - * @tc.name fileio_test_stream_read_async_006 - * @tc.desc Test read() interface, When offset+length>buffer.size. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_stream_read_async_006', 0, async function (done) { - let fpath = await nextFileName('fileio_test_stream_read_async_006'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - let ss = fileio.createStreamSync(fpath, 'r+'); - expect(ss !== null).assertTrue(); - try { - await ss.read(new ArrayBuffer(4096), {offset: 1,length:4096}); - } catch (err) { - console.info('fileio_test_stream_read_async_006 has failed for ' + err); - expect(err.message == "Invalid option.length").assertTrue(); - ss.closeSync(); - fileio.unlinkSync(fpath); - done(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_STREAM_READASYNC_0700 - * @tc.name fileio_test_stream_read_async_007 - * @tc.desc Test read() interface, When the offset is greater than the buffer length. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_stream_read_async_007', 0, async function (done) { - let fpath = await nextFileName('fileio_test_stream_read_async_007'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - let ss = fileio.createStreamSync(fpath, 'r+'); - expect(ss !== null).assertTrue(); - try { - await ss.read(new ArrayBuffer(4096), {offset: 4097}); - } catch (err) { - console.info('fileio_test_stream_read_async_007 has failed for ' + err); - expect(err.message == "Invalid option.offset, buffer limit exceeded").assertTrue(); - ss.closeSync(); - fileio.unlinkSync(fpath); - done(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_STREAM_READASYNC_0800 - * @tc.name fileio_test_stream_read_async_008 - * @tc.desc Test read() interface, When the length is greater than the buffer length. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_stream_read_async_008', 0, async function (done) { - let fpath = await nextFileName('fileio_test_stream_read_async_008'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - let ss = fileio.createStreamSync(fpath, 'r+'); - expect(ss !== null).assertTrue(); - try { - await ss.read(new ArrayBuffer(4096), {length: 4097}); - } catch (err) { - console.info('fileio_test_stream_read_async_008 has failed for ' + err); - expect(err.message == "Invalid option.length").assertTrue(); - ss.closeSync(); - fileio.unlinkSync(fpath); - done(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_STREAM_READASYNC_0900 - * @tc.name fileio_test_stream_read_async_009 - * @tc.desc Test read() interface, When the length is negative,equivalent to omitting the parameter. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_stream_read_async_009', 0, async function (done) { - let fpath = await nextFileName('fileio_test_stream_read_async_009'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - let ss = fileio.createStreamSync(fpath, 'r+'); - - try { - expect(ss !== null).assertTrue(); - await ss.read(new ArrayBuffer(16), {offset:13, length: -1}); - expect(false).assertTrue(); - } catch (err) { - ss.closeSync(); - fileio.unlinkSync(fpath); - console.info('fileio_test_stream_read_async_009 has failed for ' + err); - expect(err.message == "Invalid option.length").assertTrue(); - done(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_STREAM_READASYNC_1000 - * @tc.name fileio_test_stream_read_async_010 - * @tc.desc Test read() interface, When there are no parameters. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_stream_read_async_010', 0, async function (done) { - let fpath = await nextFileName('fileio_test_stream_read_async_010'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - let ss = fileio.createStreamSync(fpath, 'r+'); - expect(ss !== null).assertTrue(); - try { - await ss.read(); - } catch (err) { - console.info('fileio_test_stream_read_async_010 has failed for ' + err); - expect(err.message == "Number of arguments unmatched").assertTrue(); - ss.closeSync(); - fileio.unlinkSync(fpath); - done(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_STREAM_READASYNC_1100 - * @tc.name fileio_test_stream_read_async_011 - * @tc.desc Test read() interface, When length>FILE_CONTENT.length. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_stream_read_async_011', 0, async function (done) { - let fpath = await nextFileName('fileio_test_stream_read_async_011'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - let ss = fileio.createStreamSync(fpath, 'r+'); - expect(ss !== null).assertTrue(); - try { - let readout = await ss.read(new ArrayBuffer(4096), {length: FILE_CONTENT.length+1}); - expect(readout.bytesRead == FILE_CONTENT.length).assertTrue(); - ss.closeSync(); - fileio.unlinkSync(fpath); - done(); - } catch (err) { - console.info('fileio_test_stream_read_async_011 has failed for ' + err); - expect(false).assertTrue(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_STREAM_READASYNC_1200 - * @tc.name fileio_test_stream_read_async_012 - * @tc.desc Test read() interface, When the position is negative. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_stream_read_async_012', 0, async function (done) { - let fpath = await nextFileName('fileio_test_stream_read_async_012'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - let ss = fileio.createStreamSync(fpath, 'r+'); - expect(ss !== null).assertTrue(); - try { - await ss.read(new ArrayBuffer(4096), {position:-1}); - } catch (err) { - console.info('fileio_test_stream_read_async_012 has failed for ' + err); - expect(err.message == "option.position shall be positive number").assertTrue(); - ss.closeSync(); - fileio.unlinkSync(fpath); - done(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_STREAM_READASYNC_1300 - * @tc.name fileio_test_stream_read_async_013 - * @tc.desc Test read() interface,When the parameter type is wrong. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_stream_read_async_013', 0, async function (done) { - let fpath = await nextFileName('fileio_test_stream_read_async_013'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - let ss = fileio.createStreamSync(fpath, 'r+'); - expect(ss !== null).assertTrue(); - try { - await ss.read(""); - } catch (err) { - console.info('fileio_test_stream_read_async_013 has failed for ' + err); - expect(err.message == "Invalid read buffer, expect arraybuffer").assertTrue(); - ss.closeSync(); - fileio.unlinkSync(fpath); - done(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_STREAM_READ_ASYNC_1400 - * @tc.name fileio_test_stream_read_async_014 - * @tc.desc Test the read() interface of class Stream. Promise. - * Undefined option arguments, use default options. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 3 - * @tc.require - */ - it('fileio_test_stream_read_async_014', 3, async function (done) { - let fpath = await nextFileName('fileio_test_stream_read_async_014'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let sr = fileio.createStreamSync(fpath, 'r+'); - expect(sr !== null).assertTrue(); - let readRes1 = await sr.read(new ArrayBuffer(16), undefined); - expect(readRes1.bytesRead == FILE_CONTENT.length).assertTrue(); - expect(readRes1.offset == 0).assertTrue(); - let readRes2 = await sr.read(new ArrayBuffer(8), undefined); - expect(readRes2.bytesRead == 0).assertTrue(); - expect(readRes2.offset == 0).assertTrue(); - sr.closeSync(); - fileio.unlinkSync(fpath); - done(); - } catch (e) { - console.log('fileio_test_stream_read_async_014 has failed for ' + e); - expect(false).assertTrue(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_STREAM_READ_ASYNC_1500 - * @tc.name fileio_test_stream_read_async_015 - * @tc.desc Test the read() interface of class Stream. Callback. - * Undefined option arguments, use default options. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 3 - * @tc.require - */ - it('fileio_test_stream_read_async_015', 3, async function (done) { - let fpath = await nextFileName('fileio_test_stream_read_async_015'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let sr = fileio.createStreamSync(fpath, 'r+'); - expect(sr !== null).assertTrue(); - sr.read(new ArrayBuffer(16), undefined, (err, readRes1) => { - if (err) { - console.log('fileio_test_stream_read_async_015 error package1: ' + JSON.stringify(err)); - expect(false).assertTrue(); - } - expect(readRes1.bytesRead == FILE_CONTENT.length).assertTrue(); - expect(readRes1.offset == 0).assertTrue(); - sr.read(new ArrayBuffer(8), undefined, (err, readRes2) => { - if (err) { - console.log('fileio_test_stream_read_async_015 error package2: ' + JSON.stringify(err)); - expect(false).assertTrue(); - } - expect(readRes2.bytesRead == 0).assertTrue(); - expect(readRes2.offset == 0).assertTrue(); - sr.closeSync(); - fileio.unlinkSync(fpath); - done(); - }); - }); - } catch (e) { - console.log('fileio_test_stream_read_async_015 has failed for ' + e); - expect(false).assertTrue(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_STREAM_READ_ASYNC_1600 - * @tc.name fileio_test_stream_read_async_016 - * @tc.desc Test the read() interface of class Stream. Promise. - * Undefined option arguments, use default options. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 3 - * @tc.require - */ - it('fileio_test_stream_read_async_016', 3, async function (done) { - let fpath = await nextFileName('fileio_test_stream_read_async_016'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let sr = fileio.createStreamSync(fpath, 'r+'); - expect(sr !== null).assertTrue(); - let readRes1 = await sr.read(new ArrayBuffer(16), { - position: undefined, - offset: undefined, - length: undefined - }); - expect(readRes1.bytesRead == FILE_CONTENT.length).assertTrue(); - expect(readRes1.offset == 0).assertTrue(); - let readRes2 = await sr.read(new ArrayBuffer(8), { - offset: undefined, - length: undefined - }); - expect(readRes2.bytesRead == 0).assertTrue(); - expect(readRes2.offset == 0).assertTrue(); - sr.closeSync(); - fileio.unlinkSync(fpath); - done(); - } catch (e) { - console.log('fileio_test_stream_read_async_016 has failed for ' + e); - expect(false).assertTrue(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_STREAM_READ_ASYNC_1700 - * @tc.name fileio_test_stream_read_async_017 - * @tc.desc Test the read() interface of class Stream. Callback. - * Undefined option arguments, use default options. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 3 - * @tc.require - */ - it('fileio_test_stream_read_async_017', 3, async function (done) { - let fpath = await nextFileName('fileio_test_stream_read_async_017'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let sr = fileio.createStreamSync(fpath, 'r+'); - expect(sr !== null).assertTrue(); - sr.read(new ArrayBuffer(4096), { - position: undefined, - offset: undefined, - length: undefined - }, (err, readRes1) => { - if (err) { - console.log('fileio_test_stream_read_async_017 error package1: ' + JSON.stringify(err)); - expect(false).assertTrue(); - } - expect(readRes1.bytesRead == FILE_CONTENT.length).assertTrue(); - expect(readRes1.offset == 0).assertTrue(); - sr.read(new ArrayBuffer(8), { - offset: undefined, - length: undefined - }, (err, readRes2) => { - if (err) { - console.log('fileio_test_stream_read_async_017 error package2: ' + JSON.stringify(err)); - expect(false).assertTrue(); - } - expect(readRes2.bytesRead == 0).assertTrue(); - expect(readRes2.offset == 0).assertTrue(); - sr.closeSync(); - fileio.unlinkSync(fpath); - done(); - }); - }); - } catch (e) { - console.log('fileio_test_stream_read_async_017 has failed for ' + e); - expect(false).assertTrue(); - } - }); -}); -} +/* + * Copyright (C) 2021 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 { + fileio, FILE_CONTENT, prepareFile, nextFileName, + describe, it, expect, +} from '../../Common'; + +export default function fileioStreamRead() { +describe('fileio_stream_read', function () { + + /** + * @tc.number SUB_DF_FILEIO_STREAM_READSYNC_0000 + * @tc.name fileio_test_stream_read_sync_000 + * @tc.desc Test Stream.readSync() interface. + * Undefined option arguments, use default options. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileio_test_stream_read_sync_000', 3, async function () { + let fpath = await nextFileName('fileio_test_stream_read_sync_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let sr = fileio.createStreamSync(fpath, 'r+'); + expect(sr !== null).assertTrue(); + let readLen1 = sr.readSync(new ArrayBuffer(16), undefined); + expect(readLen1 == FILE_CONTENT.length).assertTrue(); + let readLen2 = sr.readSync(new ArrayBuffer(8), undefined); + expect(readLen2 == 0).assertTrue(); + sr.closeSync(); + fileio.unlinkSync(fpath); + } catch (e) { + console.log('fileio_test_stream_read_sync_000 has failed for ' + e); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STREAM_READSYNC_0100 + * @tc.name fileio_test_stream_read_sync_001 + * @tc.desc Test Stream.readSync() interface. + * Undefined option arguments, use default options. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileio_test_stream_read_sync_001', 3, async function () { + let fpath = await nextFileName('fileio_test_stream_read_sync_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let sr = fileio.createStreamSync(fpath, 'r+'); + expect(sr !== null).assertTrue(); + let readLen1 = sr.readSync(new ArrayBuffer(16), { + offset: undefined, + length: undefined + }); + expect(readLen1 == FILE_CONTENT.length).assertTrue(); + let readLen2 = sr.readSync(new ArrayBuffer(8), { + offset: undefined, + length: undefined + }); + expect(readLen2 == 0).assertTrue(); + sr.closeSync(); + fileio.unlinkSync(fpath); + } catch (e) { + console.log('fileio_test_stream_read_sync_001 has failed for ' + e); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STREAM_READASYNC_0000 + * @tc.name fileio_test_stream_read_async_000 + * @tc.desc Test read() interface,return in promise mode. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_stream_read_async_000', 0, async function (done) { + let fpath = await nextFileName('fileio_test_stream_read_async_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let ss = fileio.createStreamSync(fpath, 'r+'); + expect(ss !== null).assertTrue(); + let readout = await ss.read(new ArrayBuffer(4096)); + expect(readout.bytesRead == FILE_CONTENT.length).assertTrue(); + ss.closeSync(); + fileio.unlinkSync(fpath); + done(); + } catch (err) { + console.info('fileio_test_stream_read_async_000 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STREAM_READASYNC_0100 + * @tc.name fileio_test_stream_read_async_001 + * @tc.desc Test read() interface, return in callback mode. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_stream_read_async_001', 0, async function () { + let fpath = await nextFileName('fileio_test_stream_read_async_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let ss = fileio.createStreamSync(fpath, 'r+'); + expect(ss !== null).assertTrue(); + ss.read(new ArrayBuffer(4096), null, function (err, readout) { + expect(readout.bytesRead == FILE_CONTENT.length).assertTrue(); + ss.closeSync(); + fileio.unlinkSync(fpath); + }); + } catch (err) { + console.info('fileio_test_stream_read_async_001 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STREAM_READASYNC_0200 + * @tc.name fileio_test_stream_read_async_002 + * @tc.desc Test read() interface, When the offset is 1 and the length is 5. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_stream_read_async_002', 0, async function (done) { + let fpath = await nextFileName('fileio_test_stream_read_async_002'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let ss = fileio.createStreamSync(fpath, 'r+'); + expect(ss !== null).assertTrue(); + let options = { + offset: 1, + length: 5 + } + let readout = await ss.read(new ArrayBuffer(4096),options); + expect(readout.bytesRead == 5).assertTrue(); + ss.closeSync(); + fileio.unlinkSync(fpath); + done(); + } catch (err) { + console.info('fileio_test_stream_read_async_002 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STREAM_READASYNC_0300 + * @tc.name fileio_test_stream_read_async_003 + * @tc.desc Test read() interface, When offset equals buffer length. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_stream_read_async_003', 0, async function (done) { + let fpath = await nextFileName('fileio_test_stream_read_async_003'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let ss = fileio.createStreamSync(fpath, 'r+'); + expect(ss !== null).assertTrue(); + let readout = await ss.read(new ArrayBuffer(4096), {offset: 4096}); + expect(readout.bytesRead == 0).assertTrue(); + expect(readout.offset == 4096).assertTrue(); + ss.closeSync(); + fileio.unlinkSync(fpath); + done(); + } catch (err) { + console.info('fileio_test_stream_read_async_003 has failed for ' + err); + expect(null).assertFail(); + } + }); + + + /** + * @tc.number SUB_DF_FILEIO_STREAM_READASYNC_0400 + * @tc.name fileio_test_stream_read_async_004 + * @tc.desc Test read() interface, When the offset is 1 and the position is 5. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_stream_read_async_004', 0, async function (done) { + let fpath = await nextFileName('fileio_test_stream_read_async_004'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let ss = fileio.createStreamSync(fpath, 'r+'); + expect(ss !== null).assertTrue(); + let options = { + offset: 1, + position:6 + } + let readout = await ss.read(new ArrayBuffer(4096),options); + expect(readout.bytesRead == FILE_CONTENT.length-6).assertTrue(); + expect(readout.offset == 1).assertTrue(); + let start = readout.offset; + let end = readout.offset+readout.bytesRead; + let result = String.fromCharCode.apply(null, new Uint8Array(readout.buffer.slice(start,end))); + expect(result== "world").assertTrue(); + ss.closeSync(); + fileio.unlinkSync(fpath); + done(); + } catch (err) { + console.info('fileio_test_stream_read_async_004 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STREAM_READASYNC_0500 + * @tc.name fileio_test_stream_read_async_005 + * @tc.desc Test read() interface, When the offset is negative. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_stream_read_async_005', 0, async function (done) { + let fpath = await nextFileName('fileio_test_stream_read_async_005'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let ss = fileio.createStreamSync(fpath, 'r+'); + expect(ss !== null).assertTrue(); + try { + await ss.read(new ArrayBuffer(4096), {offset: -1}); + } catch (err) { + console.info('fileio_test_stream_read_async_005 has failed for ' + err); + expect(err.message == "Invalid option.offset, positive integer is desired").assertTrue(); + ss.closeSync(); + fileio.unlinkSync(fpath); + done(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STREAM_READASYNC_0600 + * @tc.name fileio_test_stream_read_async_006 + * @tc.desc Test read() interface, When offset+length>buffer.size. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_stream_read_async_006', 0, async function (done) { + let fpath = await nextFileName('fileio_test_stream_read_async_006'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let ss = fileio.createStreamSync(fpath, 'r+'); + expect(ss !== null).assertTrue(); + try { + await ss.read(new ArrayBuffer(4096), {offset: 1,length:4096}); + } catch (err) { + console.info('fileio_test_stream_read_async_006 has failed for ' + err); + expect(err.message == "Invalid option.length").assertTrue(); + ss.closeSync(); + fileio.unlinkSync(fpath); + done(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STREAM_READASYNC_0700 + * @tc.name fileio_test_stream_read_async_007 + * @tc.desc Test read() interface, When the offset is greater than the buffer length. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_stream_read_async_007', 0, async function (done) { + let fpath = await nextFileName('fileio_test_stream_read_async_007'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let ss = fileio.createStreamSync(fpath, 'r+'); + expect(ss !== null).assertTrue(); + try { + await ss.read(new ArrayBuffer(4096), {offset: 4097}); + } catch (err) { + console.info('fileio_test_stream_read_async_007 has failed for ' + err); + expect(err.message == "Invalid option.offset, buffer limit exceeded").assertTrue(); + ss.closeSync(); + fileio.unlinkSync(fpath); + done(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STREAM_READASYNC_0800 + * @tc.name fileio_test_stream_read_async_008 + * @tc.desc Test read() interface, When the length is greater than the buffer length. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_stream_read_async_008', 0, async function (done) { + let fpath = await nextFileName('fileio_test_stream_read_async_008'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let ss = fileio.createStreamSync(fpath, 'r+'); + expect(ss !== null).assertTrue(); + try { + await ss.read(new ArrayBuffer(4096), {length: 4097}); + } catch (err) { + console.info('fileio_test_stream_read_async_008 has failed for ' + err); + expect(err.message == "Invalid option.length").assertTrue(); + ss.closeSync(); + fileio.unlinkSync(fpath); + done(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STREAM_READASYNC_0900 + * @tc.name fileio_test_stream_read_async_009 + * @tc.desc Test read() interface, When the length is negative,equivalent to omitting the parameter. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_stream_read_async_009', 0, async function (done) { + let fpath = await nextFileName('fileio_test_stream_read_async_009'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let ss = fileio.createStreamSync(fpath, 'r+'); + + try { + expect(ss !== null).assertTrue(); + await ss.read(new ArrayBuffer(16), {offset:13, length: -1}); + expect(false).assertTrue(); + } catch (err) { + ss.closeSync(); + fileio.unlinkSync(fpath); + console.info('fileio_test_stream_read_async_009 has failed for ' + err); + expect(err.message == "Invalid option.length").assertTrue(); + done(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STREAM_READASYNC_1000 + * @tc.name fileio_test_stream_read_async_010 + * @tc.desc Test read() interface, When there are no parameters. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_stream_read_async_010', 0, async function (done) { + let fpath = await nextFileName('fileio_test_stream_read_async_010'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let ss = fileio.createStreamSync(fpath, 'r+'); + expect(ss !== null).assertTrue(); + try { + await ss.read(); + } catch (err) { + console.info('fileio_test_stream_read_async_010 has failed for ' + err); + expect(err.message == "Number of arguments unmatched").assertTrue(); + ss.closeSync(); + fileio.unlinkSync(fpath); + done(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STREAM_READASYNC_1100 + * @tc.name fileio_test_stream_read_async_011 + * @tc.desc Test read() interface, When length>FILE_CONTENT.length. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_stream_read_async_011', 0, async function (done) { + let fpath = await nextFileName('fileio_test_stream_read_async_011'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let ss = fileio.createStreamSync(fpath, 'r+'); + expect(ss !== null).assertTrue(); + try { + let readout = await ss.read(new ArrayBuffer(4096), {length: FILE_CONTENT.length+1}); + expect(readout.bytesRead == FILE_CONTENT.length).assertTrue(); + ss.closeSync(); + fileio.unlinkSync(fpath); + done(); + } catch (err) { + console.info('fileio_test_stream_read_async_011 has failed for ' + err); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STREAM_READASYNC_1200 + * @tc.name fileio_test_stream_read_async_012 + * @tc.desc Test read() interface, When the position is negative. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_stream_read_async_012', 0, async function (done) { + let fpath = await nextFileName('fileio_test_stream_read_async_012'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let ss = fileio.createStreamSync(fpath, 'r+'); + expect(ss !== null).assertTrue(); + try { + await ss.read(new ArrayBuffer(4096), {position:-1}); + } catch (err) { + console.info('fileio_test_stream_read_async_012 has failed for ' + err); + expect(err.message == "option.position shall be positive number").assertTrue(); + ss.closeSync(); + fileio.unlinkSync(fpath); + done(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STREAM_READASYNC_1300 + * @tc.name fileio_test_stream_read_async_013 + * @tc.desc Test read() interface,When the parameter type is wrong. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_stream_read_async_013', 0, async function (done) { + let fpath = await nextFileName('fileio_test_stream_read_async_013'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let ss = fileio.createStreamSync(fpath, 'r+'); + expect(ss !== null).assertTrue(); + try { + await ss.read(""); + } catch (err) { + console.info('fileio_test_stream_read_async_013 has failed for ' + err); + expect(err.message == "Invalid read buffer, expect arraybuffer").assertTrue(); + ss.closeSync(); + fileio.unlinkSync(fpath); + done(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STREAM_READ_ASYNC_1400 + * @tc.name fileio_test_stream_read_async_014 + * @tc.desc Test the read() interface of class Stream. Promise. + * Undefined option arguments, use default options. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileio_test_stream_read_async_014', 3, async function (done) { + let fpath = await nextFileName('fileio_test_stream_read_async_014'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let sr = fileio.createStreamSync(fpath, 'r+'); + expect(sr !== null).assertTrue(); + let readRes1 = await sr.read(new ArrayBuffer(16), undefined); + expect(readRes1.bytesRead == FILE_CONTENT.length).assertTrue(); + expect(readRes1.offset == 0).assertTrue(); + let readRes2 = await sr.read(new ArrayBuffer(8), undefined); + expect(readRes2.bytesRead == 0).assertTrue(); + expect(readRes2.offset == 0).assertTrue(); + sr.closeSync(); + fileio.unlinkSync(fpath); + done(); + } catch (e) { + console.log('fileio_test_stream_read_async_014 has failed for ' + e); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STREAM_READ_ASYNC_1500 + * @tc.name fileio_test_stream_read_async_015 + * @tc.desc Test the read() interface of class Stream. Callback. + * Undefined option arguments, use default options. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileio_test_stream_read_async_015', 3, async function (done) { + let fpath = await nextFileName('fileio_test_stream_read_async_015'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let sr = fileio.createStreamSync(fpath, 'r+'); + expect(sr !== null).assertTrue(); + sr.read(new ArrayBuffer(16), undefined, (err, readRes1) => { + if (err) { + console.log('fileio_test_stream_read_async_015 error package1: ' + JSON.stringify(err)); + expect(false).assertTrue(); + } + expect(readRes1.bytesRead == FILE_CONTENT.length).assertTrue(); + expect(readRes1.offset == 0).assertTrue(); + sr.read(new ArrayBuffer(8), undefined, (err, readRes2) => { + if (err) { + console.log('fileio_test_stream_read_async_015 error package2: ' + JSON.stringify(err)); + expect(false).assertTrue(); + } + expect(readRes2.bytesRead == 0).assertTrue(); + expect(readRes2.offset == 0).assertTrue(); + sr.closeSync(); + fileio.unlinkSync(fpath); + done(); + }); + }); + } catch (e) { + console.log('fileio_test_stream_read_async_015 has failed for ' + e); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STREAM_READ_ASYNC_1600 + * @tc.name fileio_test_stream_read_async_016 + * @tc.desc Test the read() interface of class Stream. Promise. + * Undefined option arguments, use default options. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileio_test_stream_read_async_016', 3, async function (done) { + let fpath = await nextFileName('fileio_test_stream_read_async_016'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let sr = fileio.createStreamSync(fpath, 'r+'); + expect(sr !== null).assertTrue(); + let readRes1 = await sr.read(new ArrayBuffer(16), { + position: undefined, + offset: undefined, + length: undefined + }); + expect(readRes1.bytesRead == FILE_CONTENT.length).assertTrue(); + expect(readRes1.offset == 0).assertTrue(); + let readRes2 = await sr.read(new ArrayBuffer(8), { + offset: undefined, + length: undefined + }); + expect(readRes2.bytesRead == 0).assertTrue(); + expect(readRes2.offset == 0).assertTrue(); + sr.closeSync(); + fileio.unlinkSync(fpath); + done(); + } catch (e) { + console.log('fileio_test_stream_read_async_016 has failed for ' + e); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STREAM_READ_ASYNC_1700 + * @tc.name fileio_test_stream_read_async_017 + * @tc.desc Test the read() interface of class Stream. Callback. + * Undefined option arguments, use default options. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileio_test_stream_read_async_017', 3, async function (done) { + let fpath = await nextFileName('fileio_test_stream_read_async_017'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let sr = fileio.createStreamSync(fpath, 'r+'); + expect(sr !== null).assertTrue(); + sr.read(new ArrayBuffer(4096), { + position: undefined, + offset: undefined, + length: undefined + }, (err, readRes1) => { + if (err) { + console.log('fileio_test_stream_read_async_017 error package1: ' + JSON.stringify(err)); + expect(false).assertTrue(); + } + expect(readRes1.bytesRead == FILE_CONTENT.length).assertTrue(); + expect(readRes1.offset == 0).assertTrue(); + sr.read(new ArrayBuffer(8), { + offset: undefined, + length: undefined + }, (err, readRes2) => { + if (err) { + console.log('fileio_test_stream_read_async_017 error package2: ' + JSON.stringify(err)); + expect(false).assertTrue(); + } + expect(readRes2.bytesRead == 0).assertTrue(); + expect(readRes2.offset == 0).assertTrue(); + sr.closeSync(); + fileio.unlinkSync(fpath); + done(); + }); + }); + } catch (e) { + console.log('fileio_test_stream_read_async_017 has failed for ' + e); + expect(false).assertTrue(); + } + }); +}); +} diff --git a/storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/class_stream/write.test.js b/storage/storagefileiojstest/src/main/js/test/module_fileio/class_stream/write.test.js similarity index 97% rename from storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/class_stream/write.test.js rename to storage/storagefileiojstest/src/main/js/test/module_fileio/class_stream/write.test.js index 7b22c54dca83d570354bdfb4bf897b2edf71535e..7c0c726f09236d88226bc67a3c2738f6e20bb4e9 100644 --- a/storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/class_stream/write.test.js +++ b/storage/storagefileiojstest/src/main/js/test/module_fileio/class_stream/write.test.js @@ -1,701 +1,701 @@ -/* - * Copyright (C) 2023 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 { - fileio, FILE_CONTENT, prepareFile, nextFileName, - describe, it, expect, -} from '../../Common'; - -export default function fileioStreamWrite() { -describe('fileio_stream_write', function () { - - /** - * @tc.number SUB_DF_FILEIO_STREAM_WRITE_SYNC_0000 - * @tc.name fileio_test_stream_write_sync_000 - * @tc.desc Test the writeSync() interface of class Stream. - * Undefined option arguments, use default options. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 3 - * @tc.require - */ - it('fileio_test_stream_write_sync_000', 3, async function () { - let fpath = await nextFileName('fileio_test_stream_write_sync_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let sr = fileio.createStreamSync(fpath, 'r+'); - expect(sr !== null).assertTrue(); - let bytesWritten1 = sr.writeSync(FILE_CONTENT, undefined); - expect(bytesWritten1 == FILE_CONTENT.length).assertTrue(); - let bytesWritten2 = sr.writeSync(new ArrayBuffer(FILE_CONTENT.length), undefined); - expect(bytesWritten2 == FILE_CONTENT.length).assertTrue(); - let readLen = sr.readSync(new ArrayBuffer(4096), { position: 0 }); - expect(readLen == FILE_CONTENT.length * 2).assertTrue(); - sr.closeSync(); - fileio.unlinkSync(fpath); - } catch (e) { - console.log('fileio_test_stream_write_sync_000 has failed for ' + e); - expect(false).assertTrue(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_STREAM_WRITE_SYNC_0100 - * @tc.name fileio_test_stream_write_sync_001 - * @tc.desc Test the writeSync() interface of class Stream. - * Undefined option arguments, use default options. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 3 - * @tc.require - */ - it('fileio_test_stream_write_sync_001', 3, async function () { - let fpath = await nextFileName('fileio_test_stream_write_sync_001'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let sr = fileio.createStreamSync(fpath, 'r+'); - expect(sr !== null).assertTrue(); - let bytesWritten1 = sr.writeSync(FILE_CONTENT, { - offset: undefined, - length: undefined, - encoding: undefined - }); - expect(bytesWritten1 == FILE_CONTENT.length).assertTrue(); - let bytesWritten2 = sr.writeSync(new ArrayBuffer(FILE_CONTENT.length), { - offset: undefined, - length: undefined, - encoding: undefined - }); - expect(bytesWritten2 == FILE_CONTENT.length).assertTrue(); - let readLen = sr.readSync(new ArrayBuffer(4096), { position: 0 }); - expect(readLen == FILE_CONTENT.length * 2).assertTrue(); - sr.closeSync(); - fileio.unlinkSync(fpath); - } catch (e) { - console.log('fileio_test_stream_write_sync_001 has failed for ' + e); - expect(false).assertTrue(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_STREAM_WRITEASYNC_0000 - * @tc.name fileio_test_stream_write_async_000 - * @tc.desc Test write() interface,When the position is 1,return in promise mode. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_stream_write_async_000', 0, async function (done) { - let fpath = await nextFileName('fileio_test_stream_write_async_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let ss = fileio.createStreamSync(fpath, 'r+'); - expect(ss !== null).assertTrue(); - let length = 4096; - ss.write(new ArrayBuffer(length), { - position: 1 - }).then(function (len) { - expect(len == length).assertTrue(); - fileio.unlinkSync(fpath); - ss.closeSync(); - done(); - }) - } catch (err) { - console.info('fileio_test_stream_write_async_000 has failed for ' + err); - expect(null).assertFail(); - done(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_STREAM_WRITEASYNC_0100 - * @tc.name fileio_test_stream_write_async_001 - * @tc.desc Test write() interface,return in callback mode. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_stream_write_async_001', 0, async function (done) { - let fpath = await nextFileName('fileio_test_stream_write_async_001'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let ss = fileio.createStreamSync(fpath, 'r+'); - expect(ss !== null).assertTrue(); - ss.write(new ArrayBuffer(4096), { offset: 1, encoding: 'utf-8' }, function (err, bytesWritten) { - expect(bytesWritten == 4095).assertTrue(); - fileio.unlinkSync(fpath); - ss.closeSync(); - done(); - }); - } catch (err) { - console.info('fileio_test_stream_write_async_001 has failed for ' + err); - expect(null).assertFail(); - done(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_STREAM_WRITEASYNC_0200 - * @tc.name fileio_test_stream_write_async_002 - * @tc.desc Test write() interface,When the offset is 1. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_stream_write_async_002', 0, async function (done) { - let fpath = await nextFileName('fileio_test_stream_write_async_002'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let ss = fileio.createStreamSync(fpath, 'r+'); - expect(ss !== null).assertTrue(); - let content = "hello, world"; - let bytesWritten = await ss.write(content, { offset: 1, length: 5, encoding: 'utf-8' }); - expect(bytesWritten == 5).assertTrue(); - fileio.unlinkSync(fpath); - ss.closeSync(); - done(); - } catch (err) { - console.info('fileio_test_stream_write_async_002 has failed for ' + err); - expect(null).assertFail(); - done(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_STREAM_WRITEASYNC_0300 - * @tc.name fileio_test_stream_write_async_003 - * @tc.desc Test write() interface,When the offset is 1 and position is 5. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_stream_write_async_003', 0, async function (done) { - let fpath = await nextFileName('fileio_test_stream_write_async_003'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let ss = fileio.createStreamSync(fpath, 'r+'); - expect(ss !== null).assertTrue(); - let content = "test"; - let bytesWritten = await ss.write(content, {offset:1, position:5, encoding: 'utf-8' }); - expect(bytesWritten == content.length-1).assertTrue(); - let readOut = await ss.read(new ArrayBuffer(4096), {offset:0,position: 0}); - let start = readOut.offset; - let end = readOut.offset+readOut.bytesRead; - let result = String.fromCharCode.apply(null, new Uint8Array(readOut.buffer.slice(start,end))); - expect(result == "helloestrld").assertTrue(); - fileio.unlinkSync(fpath); - ss.closeSync(); - done(); - } catch (err) { - console.info('fileio_test_stream_write_async_003 has failed for ' + err); - expect(null).assertFail(); - done(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_STREAM_WRITEASYNC_0400 - * @tc.name fileio_test_stream_write_async_004 - * @tc.desc Test write() interface,When there is only the first parameter. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_stream_write_async_004', 0, async function (done) { - let fpath = await nextFileName('fileio_test_stream_write_async_004'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let ss = fileio.createStreamSync(fpath, 'r+'); - expect(ss !== null).assertTrue(); - let content = "hello, world"; - let bytesWritten = await ss.write(content); - expect(bytesWritten == content.length).assertTrue(); - fileio.unlinkSync(fpath); - ss.closeSync(); - done(); - } catch (err) { - console.info('fileio_test_stream_write_async_004 has failed for ' + err); - expect(null).assertFail(); - done(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_STREAM_WRITEASYNC_0500 - * @tc.name fileio_test_stream_write_async_005 - * @tc.desc Test write() interface,When offset equals buffer length. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_stream_write_async_005', 0, async function (done) { - let fpath = await nextFileName('fileio_test_stream_write_async_005'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let ss = fileio.createStreamSync(fpath, 'r+'); - expect(ss !== null).assertTrue(); - let content = "hello, world"; - let bytesWritten = await ss.write(content, {offset: content.length}); - expect(bytesWritten == 0).assertTrue(); - fileio.unlinkSync(fpath); - ss.closeSync(); - done(); - } catch (err) { - console.info('fileio_test_stream_write_async_005 has failed for ' + err); - expect(null).assertFail(); - done(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_STREAM_WRITEASYNC_0600 - * @tc.name fileio_test_stream_write_async_006 - * @tc.desc Test write() interface,When offset+length>buffer.size. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_stream_write_async_006', 0, async function (done) { - let fpath = await nextFileName('fileio_test_stream_write_async_006'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - let ss = fileio.createStreamSync(fpath, 'r+'); - expect(ss !== null).assertTrue(); - try { - let content = "hello, world"; - await ss.write(content,{offset: 5, length:10}); - done(); - } catch (err) { - console.info('fileio_test_stream_write_async_006 has failed for ' + err); - expect(err.message == "Invalid option.length").assertTrue(); - fileio.unlinkSync(fpath); - ss.closeSync(); - done(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_STREAM_WRITEASYNC_0700 - * @tc.name fileio_test_stream_write_async_007 - * @tc.desc Test write() interface,When the offset is greater than the buffer length. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_stream_write_async_007', 0, async function (done) { - let fpath = await nextFileName('fileio_test_stream_write_async_007'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - let ss = fileio.createStreamSync(fpath, 'r+'); - expect(ss !== null).assertTrue(); - try { - let content = "hello, world"; - await ss.write(content, {offset:content.length+1}); - } catch (err) { - console.info('fileio_test_stream_write_async_007 has failed for ' + err); - expect(err.message == "Invalid option.offset, buffer limit exceeded").assertTrue(); - fileio.unlinkSync(fpath); - ss.closeSync(); - done(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_STREAM_WRITEASYNC_0800 - * @tc.name fileio_test_stream_write_async_008 - * @tc.desc Test write() interface,when encoding invalid. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_stream_write_async_008', 0, async function (done) { - let fpath = await nextFileName('fileio_test_stream_write_async_008'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - let ss = fileio.createStreamSync(fpath, 'r+'); - expect(ss !== null).assertTrue(); - try { - await ss.write("hello, world", {encoding: 'GB2312' }); - } catch (err) { - console.info('fileio_test_stream_write_async_008 has failed for ' + err); - expect(err.message == "Illegal write buffer or encoding").assertTrue(); - ss.closeSync(); - fileio.unlinkSync(fpath); - done(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_STREAM_WRITEASYNC_0900 - * @tc.name fileio_test_stream_write_async_009 - * @tc.desc Test write() interface,When there are no parameters. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_stream_write_async_009', 0, async function (done) { - let fpath = await nextFileName('fileio_test_stream_write_async_009'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - let ss = fileio.createStreamSync(fpath, 'r+'); - expect(ss !== null).assertTrue(); - try { - await ss.write(); - } catch (err) { - console.info('fileio_test_stream_write_async_009 has failed for ' + err); - expect(err.message == "Number of arguments unmatched").assertTrue(); - fileio.unlinkSync(fpath); - ss.closeSync(); - done(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_STREAM_WRITEASYNC_1000 - * @tc.name fileio_test_stream_write_async_010 - * @tc.desc Test write() interface,When the offset is negative. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_stream_write_async_010', 0, async function (done) { - let fpath = await nextFileName('fileio_test_stream_write_async_010'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - let ss = fileio.createStreamSync(fpath, 'r+'); - expect(ss !== null).assertTrue(); - try { - - let content = "hello, world"; - await ss.write(content, {offset:-1}); - } catch (err) { - console.info('fileio_test_stream_write_async_010 has failed for ' + err); - expect(err.message == "Invalid option.offset, positive integer is desired").assertTrue(); - fileio.unlinkSync(fpath); - ss.closeSync(); - done(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_STREAM_WRITEASYNC_1100 - * @tc.name fileio_test_stream_write_async_011 - * @tc.desc Test write() interface,When the length is negative,equivalent to omitting the parameter. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_stream_write_async_011', 0, async function (done) { - let fpath = await nextFileName('fileio_test_stream_write_async_011'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - let ss = fileio.createStreamSync(fpath, 'r+'); - expect(ss !== null).assertTrue(); - try { - let content = "hello, world"; - await ss.write(content, {offset:1 ,length:-1}); - expect(false).assertTrue(); - } catch (err) { - ss.closeSync(); - fileio.unlinkSync(fpath); - console.info('fileio_test_stream_write_async_011 has failed for ' + err); - expect(err.message == "Invalid option.length").assertTrue(); - done(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_STREAM_WRITEASYNC_1200 - * @tc.name fileio_test_stream_write_async_012 - * @tc.desc Test write() interface,When the buffer parameter type is wrong. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_stream_write_async_012', 0, async function (done) { - let fpath = await nextFileName('fileio_test_stream_write_async_012'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - let ss = fileio.createStreamSync(fpath, 'r+'); - expect(ss !== null).assertTrue(); - try { - - await ss.write(12, {length:-1}); - } catch (err) { - console.info('fileio_test_stream_write_async_012 has failed for ' + err); - expect(err.message == "Illegal write buffer or encoding").assertTrue(); - fileio.unlinkSync(fpath); - ss.closeSync(); - done(); - } - }); - - - /** - * @tc.number SUB_DF_FILEIO_STREAM_WRITEASYNC_1300 - * @tc.name fileio_test_stream_write_async_013 - * @tc.desc Test write() interface,When the length is greater than the buffer length. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_stream_write_async_013', 0, async function (done) { - let fpath = await nextFileName('fileio_test_stream_write_async_013'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - let ss = fileio.createStreamSync(fpath, 'r+'); - expect(ss !== null).assertTrue(); - try { - await ss.write(new ArrayBuffer(4096), {length:4097}); - } catch (err) { - console.info('fileio_test_stream_write_async_013 has failed for ' + err); - expect(err.message == "Invalid option.length").assertTrue(); - fileio.unlinkSync(fpath); - ss.closeSync(); - done(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_STREAM_WRITEASYNC_1400 - * @tc.name fileio_test_stream_write_async_014 - * @tc.desc Test write() interface,When the length>content.length . - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_stream_write_async_014', 0, async function (done) { - let fpath = await nextFileName('fileio_test_stream_write_async_014'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - let ss = fileio.createStreamSync(fpath, 'r+'); - expect(ss !== null).assertTrue(); - try { - let content = "hello,world"; - await ss.write(content,{length:content.length+1}); - } catch (err) { - console.info('fileio_test_stream_write_async_014 has failed for ' + err); - expect(err.message == "Invalid option.length").assertTrue(); - fileio.unlinkSync(fpath); - ss.closeSync(); - done(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_STREAM_WRITEASYNC_1500 - * @tc.name fileio_test_stream_write_async_015 - * @tc.desc Test write() interface,When the position is negative. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_stream_write_async_015', 0, async function (done) { - let fpath = await nextFileName('fileio_test_stream_write_async_015'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - let ss = fileio.createStreamSync(fpath, 'r+'); - expect(ss !== null).assertTrue(); - try { - let content = "hello, world"; - await ss.write(content, {position:-1}); - } catch (err) { - console.info('fileio_test_stream_write_async_015 has failed for ' + err); - expect(err.message == "option.position shall be positive number").assertTrue(); - fileio.unlinkSync(fpath); - ss.closeSync(); - done(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_STREAM_WRITE_ASYNC_1600 - * @tc.name fileio_test_stream_write_async_016 - * @tc.desc Test the write() interface of class Stream. Promise. - * Undefined option arguments, use default options. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 3 - * @tc.require - */ - it('fileio_test_stream_write_async_016', 3, async function (done) { - let fpath = await nextFileName('fileio_test_stream_write_async_016'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let sr = fileio.createStreamSync(fpath, 'r+'); - expect(sr !== null).assertTrue(); - let bytesWritten1 = await sr.write(FILE_CONTENT, undefined); - expect(bytesWritten1 == FILE_CONTENT.length).assertTrue(); - let bytesWritten2 = await sr.write(new ArrayBuffer(FILE_CONTENT.length), undefined); - expect(bytesWritten2 == FILE_CONTENT.length).assertTrue(); - let readLen = sr.readSync(new ArrayBuffer(4096), { position: 0 }); - expect(readLen == FILE_CONTENT.length * 2).assertTrue(); - sr.closeSync(); - fileio.unlinkSync(fpath); - done(); - } catch (e) { - console.log('fileio_test_stream_write_async_016 has failed for ' + e.message + ', code: ' + e.code); - expect(false).assertTrue(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_STREAM_WRITE_ASYNC_1700 - * @tc.name fileio_test_stream_write_async_017 - * @tc.desc Test the write() interface of class Stream. Callback. - * Undefined option arguments, use default options. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 3 - * @tc.require - */ - it('fileio_test_stream_write_async_017', 3, async function (done) { - let fpath = await nextFileName('fileio_test_stream_write_async_017'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let sr = fileio.createStreamSync(fpath, 'r+'); - expect(sr !== null).assertTrue(); - sr.write(FILE_CONTENT, undefined, (err, bytesWritten1) => { - if (err) { - console.log('fileio_test_stream_write_async_017 err package1: ' + JSON.stringify(err)); - expect(false).assertTrue(); - } - expect(bytesWritten1 == FILE_CONTENT.length).assertTrue(); - sr.write(new ArrayBuffer(FILE_CONTENT.length), undefined, (err, bytesWritten2) => { - if (err) { - console.log('fileio_test_stream_write_async_017 err package2: ' + JSON.stringify(err)); - expect(false).assertTrue(); - } - expect(bytesWritten2 == FILE_CONTENT.length).assertTrue(); - let readLen = sr.readSync(new ArrayBuffer(4096), { position: 0 }); - expect(readLen == FILE_CONTENT.length * 2).assertTrue(); - sr.closeSync(); - fileio.unlinkSync(fpath); - done(); - }); - }); - } catch (e) { - console.log('fileio_test_stream_write_async_017 has failed for ' + e); - expect(false).assertTrue(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_STREAM_WRITE_ASYNC_1800 - * @tc.name fileio_test_stream_write_async_018 - * @tc.desc Test the write() interface of class Stream. Promise. - * Undefined option arguments, use default options. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 3 - * @tc.require - */ - it('fileio_test_stream_write_async_018', 3, async function (done) { - let fpath = await nextFileName('fileio_test_stream_write_async_018'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let sr = fileio.createStreamSync(fpath, 'r+'); - expect(sr !== null).assertTrue(); - let bytesWritten1 = await sr.write(FILE_CONTENT, { - offset: undefined, - length: undefined, - encoding: undefined - }); - expect(bytesWritten1 == FILE_CONTENT.length).assertTrue(); - let bytesWritten2 = await sr.write(new ArrayBuffer(FILE_CONTENT.length), { - offset: undefined, - length: undefined, - encoding: undefined - }); - expect(bytesWritten2 == FILE_CONTENT.length).assertTrue(); - let readLen = sr.readSync(new ArrayBuffer(4096), { position: 0 }); - expect(readLen == FILE_CONTENT.length * 2).assertTrue(); - sr.closeSync(); - fileio.unlinkSync(fpath); - done(); - } catch (e) { - console.log('fileio_test_stream_write_async_018 has failed for ' + e); - expect(false).assertTrue(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_STREAM_WRITE_ASYNC_1900 - * @tc.name fileio_test_stream_write_async_019 - * @tc.desc Test the write() interface of class Stream. Callback. - * Undefined option arguments, use default options. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 3 - * @tc.require - */ - it('fileio_test_stream_write_async_019', 3, async function (done) { - let fpath = await nextFileName('fileio_test_stream_write_async_019'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let sr = fileio.createStreamSync(fpath, 'r+'); - expect(sr !== null).assertTrue(); - sr.write(FILE_CONTENT, { - offset: undefined, - length: undefined, - encoding: undefined - }, (err, bytesWritten1) => { - if (err) { - console.log('fileio_test_stream_write_async_019 err package1: ' + JSON.stringify(err)); - expect(false).assertTrue(); - } - expect(bytesWritten1 == FILE_CONTENT.length).assertTrue(); - sr.write(new ArrayBuffer(FILE_CONTENT.length), { - offset: undefined, - length: undefined, - encoding: undefined - }, (err, bytesWritten2) => { - if (err) { - console.log('fileio_test_stream_write_async_019 err package2: ' + JSON.stringify(err)); - expect(false).assertTrue(); - } - expect(bytesWritten2 == FILE_CONTENT.length).assertTrue(); - let readLen = sr.readSync(new ArrayBuffer(4096), { position: 0 }); - expect(readLen == FILE_CONTENT.length * 2).assertTrue(); - sr.closeSync(); - fileio.unlinkSync(fpath); - done(); - }); - }); - } catch (e) { - console.log('fileio_test_stream_write_async_019 has failed for ' + e); - expect(false).assertTrue(); - } - }); -}); -} +/* + * Copyright (C) 2021 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 { + fileio, FILE_CONTENT, prepareFile, nextFileName, + describe, it, expect, +} from '../../Common'; + +export default function fileioStreamWrite() { +describe('fileio_stream_write', function () { + + /** + * @tc.number SUB_DF_FILEIO_STREAM_WRITE_SYNC_0000 + * @tc.name fileio_test_stream_write_sync_000 + * @tc.desc Test the writeSync() interface of class Stream. + * Undefined option arguments, use default options. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileio_test_stream_write_sync_000', 3, async function () { + let fpath = await nextFileName('fileio_test_stream_write_sync_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let sr = fileio.createStreamSync(fpath, 'r+'); + expect(sr !== null).assertTrue(); + let bytesWritten1 = sr.writeSync(FILE_CONTENT, undefined); + expect(bytesWritten1 == FILE_CONTENT.length).assertTrue(); + let bytesWritten2 = sr.writeSync(new ArrayBuffer(FILE_CONTENT.length), undefined); + expect(bytesWritten2 == FILE_CONTENT.length).assertTrue(); + let readLen = sr.readSync(new ArrayBuffer(4096), { position: 0 }); + expect(readLen == FILE_CONTENT.length * 2).assertTrue(); + sr.closeSync(); + fileio.unlinkSync(fpath); + } catch (e) { + console.log('fileio_test_stream_write_sync_000 has failed for ' + e); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STREAM_WRITE_SYNC_0100 + * @tc.name fileio_test_stream_write_sync_001 + * @tc.desc Test the writeSync() interface of class Stream. + * Undefined option arguments, use default options. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileio_test_stream_write_sync_001', 3, async function () { + let fpath = await nextFileName('fileio_test_stream_write_sync_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let sr = fileio.createStreamSync(fpath, 'r+'); + expect(sr !== null).assertTrue(); + let bytesWritten1 = sr.writeSync(FILE_CONTENT, { + offset: undefined, + length: undefined, + encoding: undefined + }); + expect(bytesWritten1 == FILE_CONTENT.length).assertTrue(); + let bytesWritten2 = sr.writeSync(new ArrayBuffer(FILE_CONTENT.length), { + offset: undefined, + length: undefined, + encoding: undefined + }); + expect(bytesWritten2 == FILE_CONTENT.length).assertTrue(); + let readLen = sr.readSync(new ArrayBuffer(4096), { position: 0 }); + expect(readLen == FILE_CONTENT.length * 2).assertTrue(); + sr.closeSync(); + fileio.unlinkSync(fpath); + } catch (e) { + console.log('fileio_test_stream_write_sync_001 has failed for ' + e); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STREAM_WRITEASYNC_0000 + * @tc.name fileio_test_stream_write_async_000 + * @tc.desc Test write() interface,When the position is 1,return in promise mode. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_stream_write_async_000', 0, async function (done) { + let fpath = await nextFileName('fileio_test_stream_write_async_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let ss = fileio.createStreamSync(fpath, 'r+'); + expect(ss !== null).assertTrue(); + let length = 4096; + ss.write(new ArrayBuffer(length), { + position: 1 + }).then(function (len) { + expect(len == length).assertTrue(); + fileio.unlinkSync(fpath); + ss.closeSync(); + done(); + }) + } catch (err) { + console.info('fileio_test_stream_write_async_000 has failed for ' + err); + expect(null).assertFail(); + done(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STREAM_WRITEASYNC_0100 + * @tc.name fileio_test_stream_write_async_001 + * @tc.desc Test write() interface,return in callback mode. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_stream_write_async_001', 0, async function (done) { + let fpath = await nextFileName('fileio_test_stream_write_async_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let ss = fileio.createStreamSync(fpath, 'r+'); + expect(ss !== null).assertTrue(); + ss.write(new ArrayBuffer(4096), { offset: 1, encoding: 'utf-8' }, function (err, bytesWritten) { + expect(bytesWritten == 4095).assertTrue(); + fileio.unlinkSync(fpath); + ss.closeSync(); + done(); + }); + } catch (err) { + console.info('fileio_test_stream_write_async_001 has failed for ' + err); + expect(null).assertFail(); + done(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STREAM_WRITEASYNC_0200 + * @tc.name fileio_test_stream_write_async_002 + * @tc.desc Test write() interface,When the offset is 1. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_stream_write_async_002', 0, async function (done) { + let fpath = await nextFileName('fileio_test_stream_write_async_002'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let ss = fileio.createStreamSync(fpath, 'r+'); + expect(ss !== null).assertTrue(); + let content = "hello, world"; + let bytesWritten = await ss.write(content, { offset: 1, length: 5, encoding: 'utf-8' }); + expect(bytesWritten == 5).assertTrue(); + fileio.unlinkSync(fpath); + ss.closeSync(); + done(); + } catch (err) { + console.info('fileio_test_stream_write_async_002 has failed for ' + err); + expect(null).assertFail(); + done(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STREAM_WRITEASYNC_0300 + * @tc.name fileio_test_stream_write_async_003 + * @tc.desc Test write() interface,When the offset is 1 and position is 5. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_stream_write_async_003', 0, async function (done) { + let fpath = await nextFileName('fileio_test_stream_write_async_003'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let ss = fileio.createStreamSync(fpath, 'r+'); + expect(ss !== null).assertTrue(); + let content = "test"; + let bytesWritten = await ss.write(content, {offset:1, position:5, encoding: 'utf-8' }); + expect(bytesWritten == content.length-1).assertTrue(); + let readOut = await ss.read(new ArrayBuffer(4096), {offset:0,position: 0}); + let start = readOut.offset; + let end = readOut.offset+readOut.bytesRead; + let result = String.fromCharCode.apply(null, new Uint8Array(readOut.buffer.slice(start,end))); + expect(result == "helloestrld").assertTrue(); + fileio.unlinkSync(fpath); + ss.closeSync(); + done(); + } catch (err) { + console.info('fileio_test_stream_write_async_003 has failed for ' + err); + expect(null).assertFail(); + done(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STREAM_WRITEASYNC_0400 + * @tc.name fileio_test_stream_write_async_004 + * @tc.desc Test write() interface,When there is only the first parameter. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_stream_write_async_004', 0, async function (done) { + let fpath = await nextFileName('fileio_test_stream_write_async_004'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let ss = fileio.createStreamSync(fpath, 'r+'); + expect(ss !== null).assertTrue(); + let content = "hello, world"; + let bytesWritten = await ss.write(content); + expect(bytesWritten == content.length).assertTrue(); + fileio.unlinkSync(fpath); + ss.closeSync(); + done(); + } catch (err) { + console.info('fileio_test_stream_write_async_004 has failed for ' + err); + expect(null).assertFail(); + done(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STREAM_WRITEASYNC_0500 + * @tc.name fileio_test_stream_write_async_005 + * @tc.desc Test write() interface,When offset equals buffer length. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_stream_write_async_005', 0, async function (done) { + let fpath = await nextFileName('fileio_test_stream_write_async_005'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let ss = fileio.createStreamSync(fpath, 'r+'); + expect(ss !== null).assertTrue(); + let content = "hello, world"; + let bytesWritten = await ss.write(content, {offset: content.length}); + expect(bytesWritten == 0).assertTrue(); + fileio.unlinkSync(fpath); + ss.closeSync(); + done(); + } catch (err) { + console.info('fileio_test_stream_write_async_005 has failed for ' + err); + expect(null).assertFail(); + done(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STREAM_WRITEASYNC_0600 + * @tc.name fileio_test_stream_write_async_006 + * @tc.desc Test write() interface,When offset+length>buffer.size. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_stream_write_async_006', 0, async function (done) { + let fpath = await nextFileName('fileio_test_stream_write_async_006'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let ss = fileio.createStreamSync(fpath, 'r+'); + expect(ss !== null).assertTrue(); + try { + let content = "hello, world"; + await ss.write(content,{offset: 5, length:10}); + done(); + } catch (err) { + console.info('fileio_test_stream_write_async_006 has failed for ' + err); + expect(err.message == "Invalid option.length").assertTrue(); + fileio.unlinkSync(fpath); + ss.closeSync(); + done(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STREAM_WRITEASYNC_0700 + * @tc.name fileio_test_stream_write_async_007 + * @tc.desc Test write() interface,When the offset is greater than the buffer length. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_stream_write_async_007', 0, async function (done) { + let fpath = await nextFileName('fileio_test_stream_write_async_007'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let ss = fileio.createStreamSync(fpath, 'r+'); + expect(ss !== null).assertTrue(); + try { + let content = "hello, world"; + await ss.write(content, {offset:content.length+1}); + } catch (err) { + console.info('fileio_test_stream_write_async_007 has failed for ' + err); + expect(err.message == "Invalid option.offset, buffer limit exceeded").assertTrue(); + fileio.unlinkSync(fpath); + ss.closeSync(); + done(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STREAM_WRITEASYNC_0800 + * @tc.name fileio_test_stream_write_async_008 + * @tc.desc Test write() interface,when encoding invalid. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_stream_write_async_008', 0, async function (done) { + let fpath = await nextFileName('fileio_test_stream_write_async_008'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let ss = fileio.createStreamSync(fpath, 'r+'); + expect(ss !== null).assertTrue(); + try { + await ss.write("hello, world", {encoding: 'GB2312' }); + } catch (err) { + console.info('fileio_test_stream_write_async_008 has failed for ' + err); + expect(err.message == "Illegal write buffer or encoding").assertTrue(); + ss.closeSync(); + fileio.unlinkSync(fpath); + done(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STREAM_WRITEASYNC_0900 + * @tc.name fileio_test_stream_write_async_009 + * @tc.desc Test write() interface,When there are no parameters. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_stream_write_async_009', 0, async function (done) { + let fpath = await nextFileName('fileio_test_stream_write_async_009'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let ss = fileio.createStreamSync(fpath, 'r+'); + expect(ss !== null).assertTrue(); + try { + await ss.write(); + } catch (err) { + console.info('fileio_test_stream_write_async_009 has failed for ' + err); + expect(err.message == "Number of arguments unmatched").assertTrue(); + fileio.unlinkSync(fpath); + ss.closeSync(); + done(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STREAM_WRITEASYNC_1000 + * @tc.name fileio_test_stream_write_async_010 + * @tc.desc Test write() interface,When the offset is negative. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_stream_write_async_010', 0, async function (done) { + let fpath = await nextFileName('fileio_test_stream_write_async_010'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let ss = fileio.createStreamSync(fpath, 'r+'); + expect(ss !== null).assertTrue(); + try { + + let content = "hello, world"; + await ss.write(content, {offset:-1}); + } catch (err) { + console.info('fileio_test_stream_write_async_010 has failed for ' + err); + expect(err.message == "Invalid option.offset, positive integer is desired").assertTrue(); + fileio.unlinkSync(fpath); + ss.closeSync(); + done(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STREAM_WRITEASYNC_1100 + * @tc.name fileio_test_stream_write_async_011 + * @tc.desc Test write() interface,When the length is negative,equivalent to omitting the parameter. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_stream_write_async_011', 0, async function (done) { + let fpath = await nextFileName('fileio_test_stream_write_async_011'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let ss = fileio.createStreamSync(fpath, 'r+'); + expect(ss !== null).assertTrue(); + try { + let content = "hello, world"; + await ss.write(content, {offset:1 ,length:-1}); + expect(false).assertTrue(); + } catch (err) { + ss.closeSync(); + fileio.unlinkSync(fpath); + console.info('fileio_test_stream_write_async_011 has failed for ' + err); + expect(err.message == "Invalid option.length").assertTrue(); + done(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STREAM_WRITEASYNC_1200 + * @tc.name fileio_test_stream_write_async_012 + * @tc.desc Test write() interface,When the buffer parameter type is wrong. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_stream_write_async_012', 0, async function (done) { + let fpath = await nextFileName('fileio_test_stream_write_async_012'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let ss = fileio.createStreamSync(fpath, 'r+'); + expect(ss !== null).assertTrue(); + try { + + await ss.write(12, {length:-1}); + } catch (err) { + console.info('fileio_test_stream_write_async_012 has failed for ' + err); + expect(err.message == "Illegal write buffer or encoding").assertTrue(); + fileio.unlinkSync(fpath); + ss.closeSync(); + done(); + } + }); + + + /** + * @tc.number SUB_DF_FILEIO_STREAM_WRITEASYNC_1300 + * @tc.name fileio_test_stream_write_async_013 + * @tc.desc Test write() interface,When the length is greater than the buffer length. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_stream_write_async_013', 0, async function (done) { + let fpath = await nextFileName('fileio_test_stream_write_async_013'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let ss = fileio.createStreamSync(fpath, 'r+'); + expect(ss !== null).assertTrue(); + try { + await ss.write(new ArrayBuffer(4096), {length:4097}); + } catch (err) { + console.info('fileio_test_stream_write_async_013 has failed for ' + err); + expect(err.message == "Invalid option.length").assertTrue(); + fileio.unlinkSync(fpath); + ss.closeSync(); + done(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STREAM_WRITEASYNC_1400 + * @tc.name fileio_test_stream_write_async_014 + * @tc.desc Test write() interface,When the length>content.length . + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_stream_write_async_014', 0, async function (done) { + let fpath = await nextFileName('fileio_test_stream_write_async_014'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let ss = fileio.createStreamSync(fpath, 'r+'); + expect(ss !== null).assertTrue(); + try { + let content = "hello,world"; + await ss.write(content,{length:content.length+1}); + } catch (err) { + console.info('fileio_test_stream_write_async_014 has failed for ' + err); + expect(err.message == "Invalid option.length").assertTrue(); + fileio.unlinkSync(fpath); + ss.closeSync(); + done(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STREAM_WRITEASYNC_1500 + * @tc.name fileio_test_stream_write_async_015 + * @tc.desc Test write() interface,When the position is negative. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_stream_write_async_015', 0, async function (done) { + let fpath = await nextFileName('fileio_test_stream_write_async_015'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let ss = fileio.createStreamSync(fpath, 'r+'); + expect(ss !== null).assertTrue(); + try { + let content = "hello, world"; + await ss.write(content, {position:-1}); + } catch (err) { + console.info('fileio_test_stream_write_async_015 has failed for ' + err); + expect(err.message == "option.position shall be positive number").assertTrue(); + fileio.unlinkSync(fpath); + ss.closeSync(); + done(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STREAM_WRITE_ASYNC_1600 + * @tc.name fileio_test_stream_write_async_016 + * @tc.desc Test the write() interface of class Stream. Promise. + * Undefined option arguments, use default options. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileio_test_stream_write_async_016', 3, async function (done) { + let fpath = await nextFileName('fileio_test_stream_write_async_016'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let sr = fileio.createStreamSync(fpath, 'r+'); + expect(sr !== null).assertTrue(); + let bytesWritten1 = await sr.write(FILE_CONTENT, undefined); + expect(bytesWritten1 == FILE_CONTENT.length).assertTrue(); + let bytesWritten2 = await sr.write(new ArrayBuffer(FILE_CONTENT.length), undefined); + expect(bytesWritten2 == FILE_CONTENT.length).assertTrue(); + let readLen = sr.readSync(new ArrayBuffer(4096), { position: 0 }); + expect(readLen == FILE_CONTENT.length * 2).assertTrue(); + sr.closeSync(); + fileio.unlinkSync(fpath); + done(); + } catch (e) { + console.log('fileio_test_stream_write_async_016 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STREAM_WRITE_ASYNC_1700 + * @tc.name fileio_test_stream_write_async_017 + * @tc.desc Test the write() interface of class Stream. Callback. + * Undefined option arguments, use default options. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileio_test_stream_write_async_017', 3, async function (done) { + let fpath = await nextFileName('fileio_test_stream_write_async_017'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let sr = fileio.createStreamSync(fpath, 'r+'); + expect(sr !== null).assertTrue(); + sr.write(FILE_CONTENT, undefined, (err, bytesWritten1) => { + if (err) { + console.log('fileio_test_stream_write_async_017 err package1: ' + JSON.stringify(err)); + expect(false).assertTrue(); + } + expect(bytesWritten1 == FILE_CONTENT.length).assertTrue(); + sr.write(new ArrayBuffer(FILE_CONTENT.length), undefined, (err, bytesWritten2) => { + if (err) { + console.log('fileio_test_stream_write_async_017 err package2: ' + JSON.stringify(err)); + expect(false).assertTrue(); + } + expect(bytesWritten2 == FILE_CONTENT.length).assertTrue(); + let readLen = sr.readSync(new ArrayBuffer(4096), { position: 0 }); + expect(readLen == FILE_CONTENT.length * 2).assertTrue(); + sr.closeSync(); + fileio.unlinkSync(fpath); + done(); + }); + }); + } catch (e) { + console.log('fileio_test_stream_write_async_017 has failed for ' + e); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STREAM_WRITE_ASYNC_1800 + * @tc.name fileio_test_stream_write_async_018 + * @tc.desc Test the write() interface of class Stream. Promise. + * Undefined option arguments, use default options. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileio_test_stream_write_async_018', 3, async function (done) { + let fpath = await nextFileName('fileio_test_stream_write_async_018'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let sr = fileio.createStreamSync(fpath, 'r+'); + expect(sr !== null).assertTrue(); + let bytesWritten1 = await sr.write(FILE_CONTENT, { + offset: undefined, + length: undefined, + encoding: undefined + }); + expect(bytesWritten1 == FILE_CONTENT.length).assertTrue(); + let bytesWritten2 = await sr.write(new ArrayBuffer(FILE_CONTENT.length), { + offset: undefined, + length: undefined, + encoding: undefined + }); + expect(bytesWritten2 == FILE_CONTENT.length).assertTrue(); + let readLen = sr.readSync(new ArrayBuffer(4096), { position: 0 }); + expect(readLen == FILE_CONTENT.length * 2).assertTrue(); + sr.closeSync(); + fileio.unlinkSync(fpath); + done(); + } catch (e) { + console.log('fileio_test_stream_write_async_018 has failed for ' + e); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STREAM_WRITE_ASYNC_1900 + * @tc.name fileio_test_stream_write_async_019 + * @tc.desc Test the write() interface of class Stream. Callback. + * Undefined option arguments, use default options. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileio_test_stream_write_async_019', 3, async function (done) { + let fpath = await nextFileName('fileio_test_stream_write_async_019'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let sr = fileio.createStreamSync(fpath, 'r+'); + expect(sr !== null).assertTrue(); + sr.write(FILE_CONTENT, { + offset: undefined, + length: undefined, + encoding: undefined + }, (err, bytesWritten1) => { + if (err) { + console.log('fileio_test_stream_write_async_019 err package1: ' + JSON.stringify(err)); + expect(false).assertTrue(); + } + expect(bytesWritten1 == FILE_CONTENT.length).assertTrue(); + sr.write(new ArrayBuffer(FILE_CONTENT.length), { + offset: undefined, + length: undefined, + encoding: undefined + }, (err, bytesWritten2) => { + if (err) { + console.log('fileio_test_stream_write_async_019 err package2: ' + JSON.stringify(err)); + expect(false).assertTrue(); + } + expect(bytesWritten2 == FILE_CONTENT.length).assertTrue(); + let readLen = sr.readSync(new ArrayBuffer(4096), { position: 0 }); + expect(readLen == FILE_CONTENT.length * 2).assertTrue(); + sr.closeSync(); + fileio.unlinkSync(fpath); + done(); + }); + }); + } catch (e) { + console.log('fileio_test_stream_write_async_019 has failed for ' + e); + expect(false).assertTrue(); + } + }); +}); +} diff --git a/storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/class_watcher/createWatcher.test.js b/storage/storagefileiojstest/src/main/js/test/module_fileio/class_watcher/createWatcher.test.js similarity index 96% rename from storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/class_watcher/createWatcher.test.js rename to storage/storagefileiojstest/src/main/js/test/module_fileio/class_watcher/createWatcher.test.js index 7dac778429872d0d44ba120d1fe48f652a32dfca..ff5201dc99eec40c0a04eee6f8b9d7ff52b72ac7 100644 --- a/storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/class_watcher/createWatcher.test.js +++ b/storage/storagefileiojstest/src/main/js/test/module_fileio/class_watcher/createWatcher.test.js @@ -1,333 +1,333 @@ -/* - * Copyright (C) 2023 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 { - fileio, FILE_CONTENT, prepareFile, nextFileName, - describe, it, expect, -} from '../../Common'; - -export default function fileioCreateWatcher() { -describe('fileio_createWatcher', function () { - - /** - * @tc.number SUB_DF_FILEIO_CREATEWATCHER_0000 - * @tc.name fileio_test_createWatcher_async_000 - * @tc.desc Test createWatcher() interface. rename 1 times stopSync() - * @tc.size MEDIUM(中型) - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_createWatcher_async_000', 0, async function (done) { - let fpath = await nextFileName('fileio_test_createWatcher_async_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let event = 1; - let flag = 0; - let ob = await fileio.createWatcher(fpath, event, function (data) { - expect(data == event).assertTrue(); - flag = 1; - }); - let after = fpath + 'yjz'; - - await fileio.rename(fpath, after); - setTimeout(function () { - expect(flag == 1).assertTrue(); - ob.stopSync(); - expect(fileio.unlinkSync(after) == null).assertTrue(); - done(); - }, 51); - } catch (e) { - console.log('fileio_test_createWatcher_async_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_CREATEWATCHER_0100 - * @tc.name fileio_test_createWatcher_async_001 - * @tc.desc Test createWatcher() interface. write 2 times stopSync() - * @tc.size MEDIUM(中型) - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_createWatcher_async_001', 0, async function (done) { - let fpath = await nextFileName('fileio_test_createWatcher_async_001'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let event = 2; - let flag = 0; - let ob = await fileio.createWatcher(fpath, event, function (data) { - flag = 1; - }); - let fd = fileio.openSync(fpath, 0o2); - let ss = 'okk'; - await fileio.write(fd, ss); - await fileio.write(fd, ss); - ob.stopSync(); - expect(flag == 1).assertTrue(); - expect(fileio.closeSync(fd) == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - done(); - } catch (e) { - console.log('fileio_test_createWatcher_async_001 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_CREATEWATCHER_0200 - * @tc.name fileio_test_createWatcher_async_002 - * @tc.desc Test createWatcher() interface. rename 1 time ,stop() - * @tc.size MEDIUM(中型) - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_createWatcher_async_002', 0, async function (done) { - let fpath = await nextFileName('fileio_test_createWatcher_async_002'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let event = 1; - let flag = 0; - let ob = await fileio.createWatcher(fpath, event, function (data) { - expect(data == event).assertTrue(); - flag = 1; - }); - let after = fpath + 'yjz'; - fileio.renameSync(fpath, after); - setTimeout(async function () { - expect(flag == 1).assertTrue(); - await ob.stop(); - expect(fileio.unlinkSync(after) == null).assertTrue(); - done(); - }, 50); - } catch (e) { - console.log('fileio_test_createWatcher_async_002 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_CREATEWATCHER_0300 - * @tc.name fileio_test_createWatcher_async_003 - * @tc.desc Test createWatcher() interface. rename 2 time ,stop() - * @tc.size MEDIUM(中型) - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_createWatcher_async_003', 0, async function (done) { - let fpath = await nextFileName('fileio_test_createWatcher_async_003'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let event = 1; - let flag = 0; - let ob = await fileio.createWatcher(fpath, event, function (data) { - expect(data == event).assertTrue(); - flag = 3; - }); - let after = fpath + 'yjz'; - await fileio.rename(fpath, after); - await fileio.rename(after, after); - ob.stop(function () { - expect(flag == 3).assertTrue(); - expect(fileio.unlinkSync(after) == null).assertTrue(); - done(); - }); - } catch (e) { - console.log('fileio_test_createWatcher_async_003 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_CREATEWATCHER_0400 - * @tc.name fileio_test_createWatcher_async_004 - * @tc.desc Test createWatcher() interface.write 2 time ,stop() - * @tc.size MEDIUM(中型) - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_createWatcher_async_004', 0, async function (done) { - let fpath = await nextFileName('fileio_test_createWatcher_async_004'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let event = 2; - let flag = 0; - let ob = await fileio.createWatcher(fpath, event, function (data) { - expect(data == 2).assertTrue(); - flag = 4; - }); - let fd = fileio.openSync(fpath, 0o2); - let ss = 'okk'; - await fileio.write(fd, ss); - await fileio.write(fd, ss); - ob.stop(function () { - expect(flag == 4).assertTrue(); - expect(fileio.closeSync(fd) == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - done(); - }); - } catch (e) { - console.log('fileio_test_createWatcher_async_004 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_CREATEWATCHER_0500 - * @tc.name fileio_test_createWatcher_async_005 - * @tc.desc Test createWatcher() interface. rename 3 times stopSync() - * @tc.size MEDIUM(中型) - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_createWatcher_async_005', 0, async function (done) { - let fpath = await nextFileName('fileio_test_createWatcher_async_005'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let event = 1; - let flag = 0; - let ob = await fileio.createWatcher(fpath, event, function (data) { - expect(data == event).assertTrue(); - flag = flag + 1; - }); - let after = fpath + 'yjz'; - await fileio.rename(fpath, after); - await fileio.rename(after, fpath); - await fileio.rename(fpath, after); - setTimeout(function () { - ob.stopSync(); - console.log('fileio_test_createWatcher_async_005 flag is ' + flag); - expect(flag == 2 || flag == 3).assertTrue(); - expect(fileio.unlinkSync(after) == null).assertTrue(); - done(); - }, 51); - } catch (e) { - console.log('fileio_test_createWatcher_async_005 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_CREATEWATCHER_0600 - * @tc.name fileio_test_createWatcher_async_006 - * @tc.desc Test createWatcher() interface.write 2 times, stop() - * @tc.size MEDIUM(中型) - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_createWatcher_async_006', 0, async function (done) { - let fpath = await nextFileName('fileio_test_createWatcher_async_006'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let event = 2; - let flag = 0; - let ob = await fileio.createWatcher(fpath, event, function (data) { - expect(data == 2).assertTrue(); - flag = flag + 1; - }); - let fd = fileio.openSync(fpath, 0o2); - let ss = 'okk'; - await fileio.write(fd, ss); - await fileio.write(fd, ss); - await ob.stop(); - console.log('fileio_test_createWatcher_async_006 flag is' + flag); - expect(flag == 1 || flag == 2).assertTrue(); - expect(fileio.closeSync(fd) == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - done(); - } catch (e) { - console.log('fileio_test_createWatcher_async_006 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_CREATEWATCHER_0700 - * @tc.name fileio_test_createWatcher_async_007 - * @tc.desc Test createWatcher() interface.rename 1 times, write 1 times, stop() - * @tc.size MEDIUM(中型) - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_createWatcher_async_007', 0, async function (done) { - let fpath = await nextFileName('fileio_test_createWatcher_async_007'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let event = 3; - let flag = 0; - let ob = await fileio.createWatcher(fpath, event, function (data) { - flag = flag + 1; - }); - let fd = fileio.openSync(fpath, 0o2); - let ss = 'okk'; - await fileio.write(fd, ss); - let after = fpath + 'yjz'; - await fileio.rename(fpath, after); - await ob.stop(); - console.log('fileio_test_createWatcher_async_007 flag is ' + flag); - expect(flag == 1 || flag == 2).assertTrue(); - expect(fileio.closeSync(fd) == null).assertTrue(); - expect(fileio.unlinkSync(after) == null).assertTrue(); - done(); - } catch (e) { - console.log('fileio_test_createWatcher_async_007 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_CREATEWATCHER_0800 - * @tc.name fileio_test_createWatcher_async_008 - * @tc.desc Test createWatcher() interface.rename 1 times, write 1 times - * @tc.size MEDIUM(中型) - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_createWatcher_async_008', 0, async function (done) { - let fpath = await nextFileName('fileio_test_createWatcher_async_008'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let event = 3; - let flag = 0; - await fileio.createWatcher(fpath, event, function (data) { - flag = flag + 1; - }); - let fd = fileio.openSync(fpath, 0o2); - let ss = 'okk'; - await fileio.write(fd, ss); - let after = fpath + 'yjz'; - await fileio.rename(fpath, after); - setTimeout(function () { - expect(flag == 2).assertTrue(); - expect(fileio.closeSync(fd) == null).assertTrue(); - expect(fileio.unlinkSync(after) == null).assertTrue(); - done(); - }, 50); - } catch (e) { - console.log('fileio_test_createWatcher_async_008 has failed for ' + e); - expect(null).assertFail(); - } - }); -}); -} +/* + * Copyright (C) 2021 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 { + fileio, FILE_CONTENT, prepareFile, nextFileName, + describe, it, expect, +} from '../../Common'; + +export default function fileioCreateWatcher() { +describe('fileio_createWatcher', function () { + + /** + * @tc.number SUB_DF_FILEIO_CREATEWATCHER_0000 + * @tc.name fileio_test_createWatcher_async_000 + * @tc.desc Test createWatcher() interface. rename 1 times stopSync() + * @tc.size MEDIUM(中型) + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_createWatcher_async_000', 0, async function (done) { + let fpath = await nextFileName('fileio_test_createWatcher_async_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let event = 1; + let flag = 0; + let ob = await fileio.createWatcher(fpath, event, function (data) { + expect(data == event).assertTrue(); + flag = 1; + }); + let after = fpath + 'yjz'; + + await fileio.rename(fpath, after); + setTimeout(function () { + expect(flag == 1).assertTrue(); + ob.stopSync(); + expect(fileio.unlinkSync(after) == null).assertTrue(); + done(); + }, 51); + } catch (e) { + console.log('fileio_test_createWatcher_async_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_CREATEWATCHER_0100 + * @tc.name fileio_test_createWatcher_async_001 + * @tc.desc Test createWatcher() interface. write 2 times stopSync() + * @tc.size MEDIUM(中型) + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_createWatcher_async_001', 0, async function (done) { + let fpath = await nextFileName('fileio_test_createWatcher_async_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let event = 2; + let flag = 0; + let ob = await fileio.createWatcher(fpath, event, function (data) { + flag = 1; + }); + let fd = fileio.openSync(fpath, 0o2); + let ss = 'okk'; + await fileio.write(fd, ss); + await fileio.write(fd, ss); + ob.stopSync(); + expect(flag == 1).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_test_createWatcher_async_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_CREATEWATCHER_0200 + * @tc.name fileio_test_createWatcher_async_002 + * @tc.desc Test createWatcher() interface. rename 1 time ,stop() + * @tc.size MEDIUM(中型) + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_createWatcher_async_002', 0, async function (done) { + let fpath = await nextFileName('fileio_test_createWatcher_async_002'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let event = 1; + let flag = 0; + let ob = await fileio.createWatcher(fpath, event, function (data) { + expect(data == event).assertTrue(); + flag = 1; + }); + let after = fpath + 'yjz'; + fileio.renameSync(fpath, after); + setTimeout(async function () { + expect(flag == 1).assertTrue(); + await ob.stop(); + expect(fileio.unlinkSync(after) == null).assertTrue(); + done(); + }, 50); + } catch (e) { + console.log('fileio_test_createWatcher_async_002 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_CREATEWATCHER_0300 + * @tc.name fileio_test_createWatcher_async_003 + * @tc.desc Test createWatcher() interface. rename 2 time ,stop() + * @tc.size MEDIUM(中型) + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_createWatcher_async_003', 0, async function (done) { + let fpath = await nextFileName('fileio_test_createWatcher_async_003'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let event = 1; + let flag = 0; + let ob = await fileio.createWatcher(fpath, event, function (data) { + expect(data == event).assertTrue(); + flag = 3; + }); + let after = fpath + 'yjz'; + await fileio.rename(fpath, after); + await fileio.rename(after, after); + ob.stop(function () { + expect(flag == 3).assertTrue(); + expect(fileio.unlinkSync(after) == null).assertTrue(); + done(); + }); + } catch (e) { + console.log('fileio_test_createWatcher_async_003 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_CREATEWATCHER_0400 + * @tc.name fileio_test_createWatcher_async_004 + * @tc.desc Test createWatcher() interface.write 2 time ,stop() + * @tc.size MEDIUM(中型) + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_createWatcher_async_004', 0, async function (done) { + let fpath = await nextFileName('fileio_test_createWatcher_async_004'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let event = 2; + let flag = 0; + let ob = await fileio.createWatcher(fpath, event, function (data) { + expect(data == 2).assertTrue(); + flag = 4; + }); + let fd = fileio.openSync(fpath, 0o2); + let ss = 'okk'; + await fileio.write(fd, ss); + await fileio.write(fd, ss); + ob.stop(function () { + expect(flag == 4).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + }); + } catch (e) { + console.log('fileio_test_createWatcher_async_004 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_CREATEWATCHER_0500 + * @tc.name fileio_test_createWatcher_async_005 + * @tc.desc Test createWatcher() interface. rename 3 times stopSync() + * @tc.size MEDIUM(中型) + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_createWatcher_async_005', 0, async function (done) { + let fpath = await nextFileName('fileio_test_createWatcher_async_005'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let event = 1; + let flag = 0; + let ob = await fileio.createWatcher(fpath, event, function (data) { + expect(data == event).assertTrue(); + flag = flag + 1; + }); + let after = fpath + 'yjz'; + await fileio.rename(fpath, after); + await fileio.rename(after, fpath); + await fileio.rename(fpath, after); + setTimeout(function () { + ob.stopSync(); + console.log('fileio_test_createWatcher_async_005 flag is ' + flag); + expect(flag == 2 || flag == 3).assertTrue(); + expect(fileio.unlinkSync(after) == null).assertTrue(); + done(); + }, 51); + } catch (e) { + console.log('fileio_test_createWatcher_async_005 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_CREATEWATCHER_0600 + * @tc.name fileio_test_createWatcher_async_006 + * @tc.desc Test createWatcher() interface.write 2 times, stop() + * @tc.size MEDIUM(中型) + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_createWatcher_async_006', 0, async function (done) { + let fpath = await nextFileName('fileio_test_createWatcher_async_006'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let event = 2; + let flag = 0; + let ob = await fileio.createWatcher(fpath, event, function (data) { + expect(data == 2).assertTrue(); + flag = flag + 1; + }); + let fd = fileio.openSync(fpath, 0o2); + let ss = 'okk'; + await fileio.write(fd, ss); + await fileio.write(fd, ss); + await ob.stop(); + console.log('fileio_test_createWatcher_async_006 flag is' + flag); + expect(flag == 1 || flag == 2).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_test_createWatcher_async_006 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_CREATEWATCHER_0700 + * @tc.name fileio_test_createWatcher_async_007 + * @tc.desc Test createWatcher() interface.rename 1 times, write 1 times, stop() + * @tc.size MEDIUM(中型) + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_createWatcher_async_007', 0, async function (done) { + let fpath = await nextFileName('fileio_test_createWatcher_async_007'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let event = 3; + let flag = 0; + let ob = await fileio.createWatcher(fpath, event, function (data) { + flag = flag + 1; + }); + let fd = fileio.openSync(fpath, 0o2); + let ss = 'okk'; + await fileio.write(fd, ss); + let after = fpath + 'yjz'; + await fileio.rename(fpath, after); + await ob.stop(); + console.log('fileio_test_createWatcher_async_007 flag is ' + flag); + expect(flag == 1 || flag == 2).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(after) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_test_createWatcher_async_007 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_CREATEWATCHER_0800 + * @tc.name fileio_test_createWatcher_async_008 + * @tc.desc Test createWatcher() interface.rename 1 times, write 1 times + * @tc.size MEDIUM(中型) + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_createWatcher_async_008', 0, async function (done) { + let fpath = await nextFileName('fileio_test_createWatcher_async_008'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let event = 3; + let flag = 0; + await fileio.createWatcher(fpath, event, function (data) { + flag = flag + 1; + }); + let fd = fileio.openSync(fpath, 0o2); + let ss = 'okk'; + await fileio.write(fd, ss); + let after = fpath + 'yjz'; + await fileio.rename(fpath, after); + setTimeout(function () { + expect(flag == 2).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(after) == null).assertTrue(); + done(); + }, 50); + } catch (e) { + console.log('fileio_test_createWatcher_async_008 has failed for ' + e); + expect(null).assertFail(); + } + }); +}); +} diff --git a/storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/members/access.test.js b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/access.test.js similarity index 96% rename from storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/members/access.test.js rename to storage/storagefileiojstest/src/main/js/test/module_fileio/members/access.test.js index 13f90bb2ef3e26b82775c39f934f351b4846bdb7..b5d7fe1df5b3f303a84276f4629acb36869e59f5 100644 --- a/storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/members/access.test.js +++ b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/access.test.js @@ -1,413 +1,413 @@ -/* - * Copyright (C) 2023 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 { - fileio, FILE_CONTENT, prepareFile, nextFileName, isIntNum, - describe, it, expect, -} from '../../Common'; - -export default function fileioAccess() { -describe('fileio_access', function () { - - /** - * @tc.number SUB_DF_FILEIO_ACCESSSYNC_0000 - * @tc.name fileio_test_access_sync_000 - * @tc.desc Test accessSync() interface. - * This interface shall work properly in normal case - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_access_sync_000', 0, async function () { - let fpath = await nextFileName('fileio_test_access_sync_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - fileio.accessSync(fpath); - fileio.unlinkSync(fpath); - } catch (err) { - console.info('fileio_test_access_sync_000 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_ACCESSSYNC_0100 - * @tc.name fileio_test_access_sync_001 - * @tc.desc Test accessSync() interface. - * Test that the current process has write permission. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_access_sync_001', 0, async function () { - let fpath = await nextFileName('fileio_test_access_sync_001'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - fileio.accessSync(fpath, 2); - fileio.unlinkSync(fpath); - } catch (err) { - console.info('fileio_test_access_sync_001 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_ACCESSSYNC_0200 - * @tc.name fileio_test_access_sync_002 - * @tc.desc Test accessSync() interface. - * Test that the current process has read permission. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_access_sync_002', 0, async function () { - let fpath = await nextFileName('fileio_test_access_sync_002'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - fileio.accessSync(fpath, 4); - fileio.unlinkSync(fpath); - } catch (err) { - console.info('fileio_test_access_sync_002 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_ACCESSSYNC_0300 - * @tc.name fileio_test_access_sync_003 - * @tc.desc Test accessSync() interface. - * Test that the current process has read and write permissions. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_access_sync_003', 0, async function () { - let fpath = await nextFileName('fileio_test_access_sync_003'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - fileio.accessSync(fpath, 2 | 4); - fileio.unlinkSync(fpath); - } catch (err) { - console.info('fileio_test_access_sync_003 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_ACCESSSYNC_0400 - * @tc.name fileio_test_access_sync_004 - * @tc.desc Test accessSync() interface. - * Test that the current process has executable permissions. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_access_sync_004', 0, async function () { - let fpath = await nextFileName('fileio_test_access_sync_004'); - fileio.openSync(fpath, 0o102, 0o777); - - try { - fileio.accessSync(fpath, 1); - fileio.unlinkSync(fpath); - } catch (err) { - console.info('fileio_test_access_sync_004 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_ACCESSSYNC_0500 - * @tc.name fileio_test_access_sync_005 - * @tc.desc Test accessSync() interface. - * The test file is not exist. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_access_sync_005', 0, async function () { - let fpath = await nextFileName('fileio_test_access_sync_005'); - - try { - fileio.accessSync(fpath); - } catch (err) { - console.info('fileio_test_access_sync_005 has failed for ' + err); - expect(err.message == 'No such file or directory').assertTrue(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_ACCESSSYNC_0600 - * @tc.name fileio_test_access_sync_006 - * @tc.desc Test accessSync() interface. - * Undefined option arguments, use default mode = 0(Is file exist). - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 3 - * @tc.require - */ - it('fileio_test_access_sync_006', 3, async function () { - let fpath = await nextFileName('fileio_test_access_sync_006'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - fileio.accessSync(fpath, undefined); - fileio.unlinkSync(fpath); - } catch (err) { - console.info('fileio_test_access_sync_006 has failed for ' + err); - expect(false).assertTrue(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_ACCESSASYNC_0000 - * @tc.name fileio_test_access_async_000 - * @tc.desc Test access() interface. Promise. - * This interface shall work properly in normal case. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_access_async_000', 0, async function (done) { - let fpath = await nextFileName('fileio_test_access_async_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - await fileio.access(fpath); - fileio.unlinkSync(fpath); - done(); - } catch (err) { - console.info('fileio_test_access_async_000 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_ACCESSASYNC_0100 - * @tc.name fileio_test_access_async_001 - * @tc.desc Test access() interface. Promise. - * Use promise to test that the current process has read permission. Async method reads data from file. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_access_async_001', 0, async function (done) { - let fpath = await nextFileName('fileio_test_access_async_001'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - await fileio.access(fpath, 4); - let fd = fileio.openSync(fpath); - expect(isIntNum(fd)).assertTrue(); - expect((await fileio.read(fd, new ArrayBuffer(4096))) != null).assertTrue(); - fileio.closeSync(fd); - fileio.unlinkSync(fpath); - done(); - } catch (err) { - console.info('fileio_test_access_async_001 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_ACCESSASYNC_0200 - * @tc.name fileio_test_access_async_002 - * @tc.desc Test access() interface. Callback. - * Test file exists. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_access_async_002', 0, async function (done) { - let fpath = await nextFileName('fileio_test_access_async_002'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - fileio.access(fpath, function (error) { - fileio.unlinkSync(fpath); - done(); - }); - } catch (err) { - console.info('fileio_test_access_async_002 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_ACCESSASYNC_0300 - * @tc.name fileio_test_access_async_003 - * @tc.desc Test access() interface. Callback. - * Use callback to test that the current process has read permission. Async method reads data from file. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_access_async_003', 0, async function (done) { - let fpath = await nextFileName('fileio_test_access_async_003'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - fileio.access(fpath, 4, async function (error) { - let fd = fileio.openSync(fpath); - expect(isIntNum(fd)).assertTrue(); - expect((await fileio.read(fd, new ArrayBuffer(4096))) != null).assertTrue(); - fileio.closeSync(fd); - fileio.unlinkSync(fpath); - }); - done(); - } catch (err) { - console.info('fileio_test_access_async_003 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_ACCESSASYNC_0400 - * @tc.name fileio_test_access_async_004 - * @tc.desc Test access() interface. Promise. - * Use promises to test that the current process has executable permissions. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_access_async_004', 0, async function (done) { - let fpath = await nextFileName('fileio_test_access_async_004'); - fileio.openSync(fpath, 0o102, 0o777); - - try { - await fileio.access(fpath, 1); - fileio.unlinkSync(fpath); - done(); - } catch (err) { - console.info('fileio_test_access_async_004 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_ACCESSASYNC_0500 - * @tc.name fileio_test_access_async_005 - * @tc.desc Test access() interface. Callback. - * Use callback to test that the current process has write permission. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_access_async_005', 0, async function (done) { - let fpath = await nextFileName('fileio_test_access_async_005'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - fileio.access(fpath, 2, function (error) { - fileio.unlinkSync(fpath); - done(); - }); - } catch (err) { - console.info('fileio_test_access_async_005 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_ACCESSASYNC_0600 - * @tc.name fileio_test_access_async_006 - * @tc.desc Test access() interface. Promise. - * Async test file does not exist. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_access_async_006', 0, async function (done) { - let fpath = await nextFileName('fileio_test_access_async_006'); - - try { - await fileio.access(fpath); - } catch (err) { - console.info('fileio_test_access_async_006 has failed for ' + err); - expect(err.message == 'No such file or directory').assertTrue(); - done(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_ACCESSASYNC_0700 - * @tc.name fileio_test_access_async_007 - * @tc.desc Test access() interface. Callback. - * Undefined option arguments, use default mode = 0(Is file exist). - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 3 - * @tc.require - */ - it('fileio_test_access_async_007', 3, async function (done) { - let fpath = await nextFileName('fileio_test_access_async_007'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - fileio.access(fpath, undefined, (error) => { - if (error) { - console.info('fileio_test_access_async_007 error: ' + err); - expect(flase).assertTrue(); - } - fileio.unlinkSync(fpath); - done(); - }); - } catch (err) { - console.info('fileio_test_access_async_007 has failed for ' + err); - expect(flase).assertTrue(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_ACCESSASYNC_0800 - * @tc.name fileio_test_access_async_008 - * @tc.desc Test access() interface. Promise. - * Undefined option arguments, use default mode = 0(Is file exist). - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 3 - * @tc.require - */ - it('fileio_test_access_async_008', 3, async function (done) { - let fpath = await nextFileName('fileio_test_access_async_008'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - await fileio.access(fpath, undefined); - fileio.unlinkSync(fpath); - done(); - } catch (err) { - console.info('fileio_test_access_async_008 has failed for ' + err); - expect(flase).assertTrue(); - } - }); -}); -} +/* + * Copyright (C) 2021 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 { + fileio, FILE_CONTENT, prepareFile, nextFileName, isIntNum, + describe, it, expect, +} from '../../Common'; + +export default function fileioAccess() { +describe('fileio_access', function () { + + /** + * @tc.number SUB_DF_FILEIO_ACCESSSYNC_0000 + * @tc.name fileio_test_access_sync_000 + * @tc.desc Test accessSync() interface. + * This interface shall work properly in normal case + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_access_sync_000', 0, async function () { + let fpath = await nextFileName('fileio_test_access_sync_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + fileio.accessSync(fpath); + fileio.unlinkSync(fpath); + } catch (err) { + console.info('fileio_test_access_sync_000 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_ACCESSSYNC_0100 + * @tc.name fileio_test_access_sync_001 + * @tc.desc Test accessSync() interface. + * Test that the current process has write permission. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_access_sync_001', 0, async function () { + let fpath = await nextFileName('fileio_test_access_sync_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + fileio.accessSync(fpath, 2); + fileio.unlinkSync(fpath); + } catch (err) { + console.info('fileio_test_access_sync_001 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_ACCESSSYNC_0200 + * @tc.name fileio_test_access_sync_002 + * @tc.desc Test accessSync() interface. + * Test that the current process has read permission. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_access_sync_002', 0, async function () { + let fpath = await nextFileName('fileio_test_access_sync_002'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + fileio.accessSync(fpath, 4); + fileio.unlinkSync(fpath); + } catch (err) { + console.info('fileio_test_access_sync_002 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_ACCESSSYNC_0300 + * @tc.name fileio_test_access_sync_003 + * @tc.desc Test accessSync() interface. + * Test that the current process has read and write permissions. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_access_sync_003', 0, async function () { + let fpath = await nextFileName('fileio_test_access_sync_003'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + fileio.accessSync(fpath, 2 | 4); + fileio.unlinkSync(fpath); + } catch (err) { + console.info('fileio_test_access_sync_003 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_ACCESSSYNC_0400 + * @tc.name fileio_test_access_sync_004 + * @tc.desc Test accessSync() interface. + * Test that the current process has executable permissions. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_access_sync_004', 0, async function () { + let fpath = await nextFileName('fileio_test_access_sync_004'); + fileio.openSync(fpath, 0o102, 0o777); + + try { + fileio.accessSync(fpath, 1); + fileio.unlinkSync(fpath); + } catch (err) { + console.info('fileio_test_access_sync_004 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_ACCESSSYNC_0500 + * @tc.name fileio_test_access_sync_005 + * @tc.desc Test accessSync() interface. + * The test file is not exist. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_access_sync_005', 0, async function () { + let fpath = await nextFileName('fileio_test_access_sync_005'); + + try { + fileio.accessSync(fpath); + } catch (err) { + console.info('fileio_test_access_sync_005 has failed for ' + err); + expect(err.message == 'No such file or directory').assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_ACCESSSYNC_0600 + * @tc.name fileio_test_access_sync_006 + * @tc.desc Test accessSync() interface. + * Undefined option arguments, use default mode = 0(Is file exist). + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileio_test_access_sync_006', 3, async function () { + let fpath = await nextFileName('fileio_test_access_sync_006'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + fileio.accessSync(fpath, undefined); + fileio.unlinkSync(fpath); + } catch (err) { + console.info('fileio_test_access_sync_006 has failed for ' + err); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_ACCESSASYNC_0000 + * @tc.name fileio_test_access_async_000 + * @tc.desc Test access() interface. Promise. + * This interface shall work properly in normal case. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_access_async_000', 0, async function (done) { + let fpath = await nextFileName('fileio_test_access_async_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + await fileio.access(fpath); + fileio.unlinkSync(fpath); + done(); + } catch (err) { + console.info('fileio_test_access_async_000 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_ACCESSASYNC_0100 + * @tc.name fileio_test_access_async_001 + * @tc.desc Test access() interface. Promise. + * Use promise to test that the current process has read permission. Async method reads data from file. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_access_async_001', 0, async function (done) { + let fpath = await nextFileName('fileio_test_access_async_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + await fileio.access(fpath, 4); + let fd = fileio.openSync(fpath); + expect(isIntNum(fd)).assertTrue(); + expect((await fileio.read(fd, new ArrayBuffer(4096))) != null).assertTrue(); + fileio.closeSync(fd); + fileio.unlinkSync(fpath); + done(); + } catch (err) { + console.info('fileio_test_access_async_001 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_ACCESSASYNC_0200 + * @tc.name fileio_test_access_async_002 + * @tc.desc Test access() interface. Callback. + * Test file exists. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_access_async_002', 0, async function (done) { + let fpath = await nextFileName('fileio_test_access_async_002'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + fileio.access(fpath, function (error) { + fileio.unlinkSync(fpath); + done(); + }); + } catch (err) { + console.info('fileio_test_access_async_002 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_ACCESSASYNC_0300 + * @tc.name fileio_test_access_async_003 + * @tc.desc Test access() interface. Callback. + * Use callback to test that the current process has read permission. Async method reads data from file. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_access_async_003', 0, async function (done) { + let fpath = await nextFileName('fileio_test_access_async_003'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + fileio.access(fpath, 4, async function (error) { + let fd = fileio.openSync(fpath); + expect(isIntNum(fd)).assertTrue(); + expect((await fileio.read(fd, new ArrayBuffer(4096))) != null).assertTrue(); + fileio.closeSync(fd); + fileio.unlinkSync(fpath); + }); + done(); + } catch (err) { + console.info('fileio_test_access_async_003 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_ACCESSASYNC_0400 + * @tc.name fileio_test_access_async_004 + * @tc.desc Test access() interface. Promise. + * Use promises to test that the current process has executable permissions. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_access_async_004', 0, async function (done) { + let fpath = await nextFileName('fileio_test_access_async_004'); + fileio.openSync(fpath, 0o102, 0o777); + + try { + await fileio.access(fpath, 1); + fileio.unlinkSync(fpath); + done(); + } catch (err) { + console.info('fileio_test_access_async_004 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_ACCESSASYNC_0500 + * @tc.name fileio_test_access_async_005 + * @tc.desc Test access() interface. Callback. + * Use callback to test that the current process has write permission. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_access_async_005', 0, async function (done) { + let fpath = await nextFileName('fileio_test_access_async_005'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + fileio.access(fpath, 2, function (error) { + fileio.unlinkSync(fpath); + done(); + }); + } catch (err) { + console.info('fileio_test_access_async_005 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_ACCESSASYNC_0600 + * @tc.name fileio_test_access_async_006 + * @tc.desc Test access() interface. Promise. + * Async test file does not exist. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_access_async_006', 0, async function (done) { + let fpath = await nextFileName('fileio_test_access_async_006'); + + try { + await fileio.access(fpath); + } catch (err) { + console.info('fileio_test_access_async_006 has failed for ' + err); + expect(err.message == 'No such file or directory').assertTrue(); + done(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_ACCESSASYNC_0700 + * @tc.name fileio_test_access_async_007 + * @tc.desc Test access() interface. Callback. + * Undefined option arguments, use default mode = 0(Is file exist). + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileio_test_access_async_007', 3, async function (done) { + let fpath = await nextFileName('fileio_test_access_async_007'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + fileio.access(fpath, undefined, (error) => { + if (error) { + console.info('fileio_test_access_async_007 error: ' + err); + expect(flase).assertTrue(); + } + fileio.unlinkSync(fpath); + done(); + }); + } catch (err) { + console.info('fileio_test_access_async_007 has failed for ' + err); + expect(flase).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_ACCESSASYNC_0800 + * @tc.name fileio_test_access_async_008 + * @tc.desc Test access() interface. Promise. + * Undefined option arguments, use default mode = 0(Is file exist). + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileio_test_access_async_008', 3, async function (done) { + let fpath = await nextFileName('fileio_test_access_async_008'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + await fileio.access(fpath, undefined); + fileio.unlinkSync(fpath); + done(); + } catch (err) { + console.info('fileio_test_access_async_008 has failed for ' + err); + expect(flase).assertTrue(); + } + }); +}); +} diff --git a/storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/members/chmod.test.js b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/chmod.test.js similarity index 96% rename from storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/members/chmod.test.js rename to storage/storagefileiojstest/src/main/js/test/module_fileio/members/chmod.test.js index 0b2d0a1e240bd6a79cf908a8ec2bcb35a2fdedd3..0b4560551c2873bc91a9dd3c2d1d40da983b936d 100644 --- a/storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/members/chmod.test.js +++ b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/chmod.test.js @@ -1,223 +1,223 @@ -/* - * Copyright (C) 2023 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 { - fileio, FILE_CONTENT, prepareFile, nextFileName, - describe, it, expect, -} from '../../Common'; - -export default function fileioChmod() { -describe('fileio_chmod', function () { - - /** - * @tc.number SUB_DF_FILEIO_CHMODSYNC_0000 - * @tc.name fileio_test_chmod_sync_000 - * @tc.desc Test chmodSync() interfaces, mode = 0o660. Test file permissions modified successfully. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_chmod_sync_000', 0, async function () { - let fpath = await nextFileName('fileio_test_chmod_sync_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - fileio.chmodSync(fpath, 0o660); - expect((fileio.statSync(fpath).mode & 0o777) == 0o660).assertTrue(); - fileio.unlinkSync(fpath); - } catch (e) { - console.info('fileio_test_chmod_sync_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_CHMODSYNC_0100 - * @tc.name fileio_test_chmod_sync_001 - * @tc.desc Test chmodSync() interfaces, mode = 0o0700. Test file permissions modified successfully. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_chmod_sync_001', 0, async function () { - let fpath = await nextFileName('fileio_test_chmod_sync_001'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - fileio.chmodSync(fpath, 0o0700); - expect((fileio.statSync(fpath).mode & 0o777) == 0o0700).assertTrue(); - fileio.unlinkSync(fpath); - } catch (e) { - console.info('fileio_test_chmod_sync_001 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_CHMODSYNC_0200 - * @tc.name fileio_test_chmod_sync_002 - * @tc.desc Test chmodSync() interfaces, invalid path. Test file modification failed. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_chmod_sync_002', 0, async function () { - let fpath = await nextFileName('fileio_test_chmod_sync_002'); - - try { - fileio.chmodSync(fpath, 0o0700); - } catch (e) { - console.info('fileio_test_chmod_sync_002 has failed for ' + e); - expect(e.message == "No such file or directory").assertTrue(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_CHMODASYNC_0000 - * @tc.name fileio_test_chmod_async_000 - * @tc.desc Test the chmodAsync() interface with promise, mode = 0o660. Test file permissions modified successfully. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_chmod_async_000', 0, async function (done) { - let fpath = await nextFileName('fileio_test_chmod_async_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - fileio - .chmod(fpath, 0o660) - .then(function (err) { - expect((fileio.statSync(fpath).mode & 0o777) == 0o660).assertTrue(); - fileio.unlinkSync(fpath); - done(); - }) - .catch(function (e) { - console.info(e); - }); - done(); - } catch (e) { - console.info('fileio_test_chmod_async_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_CHMODASYNC_0100 - * @tc.name fileio_test_chmod_async_001 - * @tc.desc Test the chmodAsync() interface with promise, mode = 0o0700. Test file permissions modified successfully. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_chmod_async_001', 0, async function (done) { - let fpath = await nextFileName('fileio_test_chmod_async_001'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - fileio - .chmod(fpath, 0o0700) - .then(function (err) { - expect((fileio.statSync(fpath).mode & 0o777) == 0o0700).assertTrue(); - fileio.unlinkSync(fpath); - done(); - }) - .catch(function (e) { - console.info(e); - }); - done(); - } catch (e) { - console.info('fileio_test_chmod_async_001 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_CHMODASYNC_0200 - * @tc.name fileio_test_chmod_async_002 - * @tc.desc Test the chmodAsync() interface with callback, mode = 0o660. Test file permissions modified successfully. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_chmod_async_002', 0, async function (done) { - let fpath = await nextFileName('fileio_test_chmod_async_002'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - fileio.chmod(fpath, 0o660, function () { - expect((fileio.statSync(fpath).mode & 0o777) == 0o660).assertTrue(); - fileio.unlinkSync(fpath); - done(); - }); - } catch (e) { - console.info('fileio_test_chmod_async_002 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_CHMODASYNC_0300 - * @tc.name fileio_test_chmod_async_003 - * @tc.desc Test the chmodAsync() interface with callback, mode = 0o0700. Test file permissions modified successfully. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_chmod_async_003', 0, async function (done) { - let fpath = await nextFileName('fileio_test_chmod_async_003'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - fileio.chmod(fpath, 0o0700, function () { - expect((fileio.statSync(fpath).mode & 0o777) == 0o0700).assertTrue(); - fileio.unlinkSync(fpath); - done(); - }); - } catch (e) { - console.info('fileio_test_chmod_async_003 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_CHMODASYNC_0400 - * @tc.name fileio_test_chmod_async_004 - * @tc.desc Test the chmodAsync() interface with promise, invalid path. Test file modification failed. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_chmod_async_004', 0, async function (done) { - let fpath = await nextFileName('fileio_test_chmod_async_004'); - - try { - await fileio.chmod(fpath, 0o660); - } catch (e) { - console.info('fileio_test_chmod_async_004 has failed for ' + e); - expect(e.message == "No such file or directory").assertTrue(); - done(); - } - }); -}); -} +/* + * Copyright (C) 2021 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 { + fileio, FILE_CONTENT, prepareFile, nextFileName, + describe, it, expect, +} from '../../Common'; + +export default function fileioChmod() { +describe('fileio_chmod', function () { + + /** + * @tc.number SUB_DF_FILEIO_CHMODSYNC_0000 + * @tc.name fileio_test_chmod_sync_000 + * @tc.desc Test chmodSync() interfaces, mode = 0o660. Test file permissions modified successfully. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_chmod_sync_000', 0, async function () { + let fpath = await nextFileName('fileio_test_chmod_sync_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + fileio.chmodSync(fpath, 0o660); + expect((fileio.statSync(fpath).mode & 0o777) == 0o660).assertTrue(); + fileio.unlinkSync(fpath); + } catch (e) { + console.info('fileio_test_chmod_sync_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_CHMODSYNC_0100 + * @tc.name fileio_test_chmod_sync_001 + * @tc.desc Test chmodSync() interfaces, mode = 0o0700. Test file permissions modified successfully. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_chmod_sync_001', 0, async function () { + let fpath = await nextFileName('fileio_test_chmod_sync_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + fileio.chmodSync(fpath, 0o0700); + expect((fileio.statSync(fpath).mode & 0o777) == 0o0700).assertTrue(); + fileio.unlinkSync(fpath); + } catch (e) { + console.info('fileio_test_chmod_sync_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_CHMODSYNC_0200 + * @tc.name fileio_test_chmod_sync_002 + * @tc.desc Test chmodSync() interfaces, invalid path. Test file modification failed. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_chmod_sync_002', 0, async function () { + let fpath = await nextFileName('fileio_test_chmod_sync_002'); + + try { + fileio.chmodSync(fpath, 0o0700); + } catch (e) { + console.info('fileio_test_chmod_sync_002 has failed for ' + e); + expect(e.message == "No such file or directory").assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_CHMODASYNC_0000 + * @tc.name fileio_test_chmod_async_000 + * @tc.desc Test the chmodAsync() interface with promise, mode = 0o660. Test file permissions modified successfully. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_chmod_async_000', 0, async function (done) { + let fpath = await nextFileName('fileio_test_chmod_async_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + fileio + .chmod(fpath, 0o660) + .then(function (err) { + expect((fileio.statSync(fpath).mode & 0o777) == 0o660).assertTrue(); + fileio.unlinkSync(fpath); + done(); + }) + .catch(function (e) { + console.info(e); + }); + done(); + } catch (e) { + console.info('fileio_test_chmod_async_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_CHMODASYNC_0100 + * @tc.name fileio_test_chmod_async_001 + * @tc.desc Test the chmodAsync() interface with promise, mode = 0o0700. Test file permissions modified successfully. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_chmod_async_001', 0, async function (done) { + let fpath = await nextFileName('fileio_test_chmod_async_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + fileio + .chmod(fpath, 0o0700) + .then(function (err) { + expect((fileio.statSync(fpath).mode & 0o777) == 0o0700).assertTrue(); + fileio.unlinkSync(fpath); + done(); + }) + .catch(function (e) { + console.info(e); + }); + done(); + } catch (e) { + console.info('fileio_test_chmod_async_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_CHMODASYNC_0200 + * @tc.name fileio_test_chmod_async_002 + * @tc.desc Test the chmodAsync() interface with callback, mode = 0o660. Test file permissions modified successfully. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_chmod_async_002', 0, async function (done) { + let fpath = await nextFileName('fileio_test_chmod_async_002'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + fileio.chmod(fpath, 0o660, function () { + expect((fileio.statSync(fpath).mode & 0o777) == 0o660).assertTrue(); + fileio.unlinkSync(fpath); + done(); + }); + } catch (e) { + console.info('fileio_test_chmod_async_002 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_CHMODASYNC_0300 + * @tc.name fileio_test_chmod_async_003 + * @tc.desc Test the chmodAsync() interface with callback, mode = 0o0700. Test file permissions modified successfully. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_chmod_async_003', 0, async function (done) { + let fpath = await nextFileName('fileio_test_chmod_async_003'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + fileio.chmod(fpath, 0o0700, function () { + expect((fileio.statSync(fpath).mode & 0o777) == 0o0700).assertTrue(); + fileio.unlinkSync(fpath); + done(); + }); + } catch (e) { + console.info('fileio_test_chmod_async_003 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_CHMODASYNC_0400 + * @tc.name fileio_test_chmod_async_004 + * @tc.desc Test the chmodAsync() interface with promise, invalid path. Test file modification failed. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_chmod_async_004', 0, async function (done) { + let fpath = await nextFileName('fileio_test_chmod_async_004'); + + try { + await fileio.chmod(fpath, 0o660); + } catch (e) { + console.info('fileio_test_chmod_async_004 has failed for ' + e); + expect(e.message == "No such file or directory").assertTrue(); + done(); + } + }); +}); +} diff --git a/storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/members/chown.test.js b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/chown.test.js similarity index 96% rename from storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/members/chown.test.js rename to storage/storagefileiojstest/src/main/js/test/module_fileio/members/chown.test.js index 029edb077f992f7a29d64ba1ca929ed68b200a93..86cd5e67ac340b18c56aa5124ae21d7d114af0c9 100644 --- a/storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/members/chown.test.js +++ b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/chown.test.js @@ -1,277 +1,277 @@ -/* - * Copyright (C) 2023 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 { - fileio, FILE_CONTENT, prepareFile, nextFileName, - describe, it, expect, -} from '../../Common'; - -export default function fileioChown() { -describe('fileio_chown', function () { - - /** - * @tc.number SUB_DF_FILEIO_CHOWNSYNC_0000 - * @tc.name fileio_test_chown_sync_000 - * @tc.desc Test chownSync() interface. The test file was modified successfully. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_chown_sync_000', 0, async function () { - let fpath = await nextFileName('fileio_test_chown_sync_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - fileio.chmodSync(fpath, 0o777); - let stat = fileio.statSync(fpath); - fileio.chownSync(fpath, stat.uid, stat.gid); - fileio.unlinkSync(fpath); - } catch (e) { - console.info('fileio_test_chown_sync_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_CHOWNSYNC_0100 - * @tc.name fileio_test_chown_sync_001 - * @tc.desc Test chownSync() interface, wrong uid, gid. Test file modification failed. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_chown_sync_001', 0, async function () { - let fpath = await nextFileName('fileio_test_chown_sync_001'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - fileio.chownSync(fpath, 0, 0); - } catch (e) { - console.info('fileio_test_chown_sync_001 has failed for ' + e); - expect(e.message == "Operation not permitted").assertTrue(); - fileio.unlinkSync(fpath); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_CHOWNSYNC_0200 - * @tc.name fileio_test_chown_sync_002 - * @tc.desc Test chownSync() interface, wrong owner. Test file modification failed. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_chown_sync_002', 0, async function () { - let fpath = await nextFileName('fileio_test_chown_sync_002'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let stat = fileio.statSync(fpath); - fileio.chownSync(fpath, null, stat.gid); - } catch (e) { - console.info('fileio_test_chown_sync_002 has failed for ' + e); - expect(e.message == "Invalid owner").assertTrue(); - fileio.unlinkSync(fpath); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_CHOWNSYNC_0300 - * @tc.name fileio_test_chown_sync_003 - * @tc.desc Test chownSync() interface, wrong group. Test file modification failed. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_chown_sync_003', 0, async function () { - let fpath = await nextFileName('fileio_test_chown_sync_003'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let stat = fileio.statSync(fpath); - fileio.chownSync(fpath, stat.uid, null); - } catch (e) { - console.info('fileio_test_chown_sync_003 has failed for ' + e); - expect(e.message == "Invalid group").assertTrue(); - fileio.unlinkSync(fpath); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_CHOWNSYNC_0400 - * @tc.name fileio_test_chown_sync_004 - * @tc.desc Test chownSync() interface, file does not exist. Test file modification failed. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_chown_sync_004', 0, async function () { - let fpath = await nextFileName('fileio_test_chown_sync_004'); - let ffpath = await nextFileName('fileio_test_chown_sync_004_1'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let stat = fileio.statSync(fpath); - fileio.chownSync(ffpath, stat.uid, stat.gid); - } catch (e) { - console.info('fileio_test_chown_sync_004 has failed for ' + e); - expect(e.message == "No such file or directory").assertTrue(); - fileio.unlinkSync(fpath); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_CHOWNASYNC_0000 - * @tc.name fileio_test_chown_async_00 - * @tc.desc Test the chownAsync() interface with promise. The test file was modified successfully. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_chown_async_000', 0, async function (done) { - let fpath = await nextFileName('fileio_test_chown_async_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - fileio.chmodSync(fpath, 0o777); - let stat = fileio.statSync(fpath); - await fileio.chown(fpath, stat.uid, stat.gid); - fileio.unlinkSync(fpath); - done(); - } catch (e) { - console.info('fileio_test_chown_async_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_CHOWNASYNC_0100 - * @tc.name fileio_test_chown_async_001 - * @tc.desc Test the chownAsync() interface with callback. The test file was modified successfully. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_chown_async_001', 0, async function (done) { - let fpath = await nextFileName('fileio_test_chown_async_001'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - fileio.chmodSync(fpath, 0o777); - let stat = fileio.statSync(fpath); - fileio.chown(fpath, stat.uid, stat.gid, function (error) { - fileio.unlinkSync(fpath); - done(); - }); - } catch (e) { - console.info('fileio_test_chown_async_001 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_CHOWNASYNC_0200 - * @tc.name fileio_test_chown_async_002 - * @tc.desc Test the chownAsync() interface with promise, wrong uid, gid. Test file modification failed. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_chown_async_002', 0, async function (done) { - let fpath = await nextFileName('fileio_test_chown_async_002'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - await fileio.chown(fpath, 0, 0); - } catch (e) { - console.info('fileio_test_chown_async_002 has failed for ' + e); - expect(e.message == "Operation not permitted").assertTrue(); - fileio.unlinkSync(fpath); - done(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_CHOWNASYNC_0300 - * @tc.name fileio_test_chown_async_003 - * @tc.desc Test the chownAsync() interface with promise, wrong owner. Test file modification failed. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_chown_async_003', 0, async function (done) { - let fpath = await nextFileName('fileio_test_chown_async_003'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let stat = fileio.statSync(fpath); - await fileio.chown(fpath, null, stat.gid); - } catch (e) { - console.info('fileio_test_chown_async_003 has failed for ' + e); - expect(e.message == "Invalid owner").assertTrue(); - fileio.unlinkSync(fpath); - done(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_CHOWNASYNC_0400 - * @tc.name fileio_test_chown_async_004 - * @tc.desc Test the chownAsync() interface with callback, wrong group. Test file modification failed. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_chown_async_004', 0, async function (done) { - let fpath = await nextFileName('fileio_test_chown_async_004'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let stat = fileio.statSync(fpath); - fileio.chown(fpath, stat.uid, null, function (error) { - }); - } catch (e) { - console.info('fileio_test_chown_async_004 has failed for ' + e); - expect(e.message == "Invalid group").assertTrue(); - fileio.unlinkSync(fpath); - done(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_CHOWNASYNC_0500 - * @tc.name fileio_test_chown_async_005 - * @tc.desc Test the chownAsync() interface with promise, file does not exist. Test file modification failed. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_chown_async_005', 0, async function (done) { - let fpath = await nextFileName('fileio_test_chown_async_005'); - let ffpath = await nextFileName('fileio_test_chown_async_005_1'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let stat = fileio.statSync(fpath); - await fileio.chown(ffpath, stat.uid, stat.gid); - } catch (e) { - console.info('fileio_test_chown_async_005 has failed for ' + e); - expect(e.message == "No such file or directory").assertTrue(); - fileio.unlinkSync(fpath); - done(); - } - }); -}); -} +/* + * Copyright (C) 2021 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 { + fileio, FILE_CONTENT, prepareFile, nextFileName, + describe, it, expect, +} from '../../Common'; + +export default function fileioChown() { +describe('fileio_chown', function () { + + /** + * @tc.number SUB_DF_FILEIO_CHOWNSYNC_0000 + * @tc.name fileio_test_chown_sync_000 + * @tc.desc Test chownSync() interface. The test file was modified successfully. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_chown_sync_000', 0, async function () { + let fpath = await nextFileName('fileio_test_chown_sync_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + fileio.chmodSync(fpath, 0o777); + let stat = fileio.statSync(fpath); + fileio.chownSync(fpath, stat.uid, stat.gid); + fileio.unlinkSync(fpath); + } catch (e) { + console.info('fileio_test_chown_sync_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_CHOWNSYNC_0100 + * @tc.name fileio_test_chown_sync_001 + * @tc.desc Test chownSync() interface, wrong uid, gid. Test file modification failed. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_chown_sync_001', 0, async function () { + let fpath = await nextFileName('fileio_test_chown_sync_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + fileio.chownSync(fpath, 0, 0); + } catch (e) { + console.info('fileio_test_chown_sync_001 has failed for ' + e); + expect(e.message == "Operation not permitted").assertTrue(); + fileio.unlinkSync(fpath); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_CHOWNSYNC_0200 + * @tc.name fileio_test_chown_sync_002 + * @tc.desc Test chownSync() interface, wrong owner. Test file modification failed. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_chown_sync_002', 0, async function () { + let fpath = await nextFileName('fileio_test_chown_sync_002'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let stat = fileio.statSync(fpath); + fileio.chownSync(fpath, null, stat.gid); + } catch (e) { + console.info('fileio_test_chown_sync_002 has failed for ' + e); + expect(e.message == "Invalid owner").assertTrue(); + fileio.unlinkSync(fpath); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_CHOWNSYNC_0300 + * @tc.name fileio_test_chown_sync_003 + * @tc.desc Test chownSync() interface, wrong group. Test file modification failed. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_chown_sync_003', 0, async function () { + let fpath = await nextFileName('fileio_test_chown_sync_003'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let stat = fileio.statSync(fpath); + fileio.chownSync(fpath, stat.uid, null); + } catch (e) { + console.info('fileio_test_chown_sync_003 has failed for ' + e); + expect(e.message == "Invalid group").assertTrue(); + fileio.unlinkSync(fpath); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_CHOWNSYNC_0400 + * @tc.name fileio_test_chown_sync_004 + * @tc.desc Test chownSync() interface, file does not exist. Test file modification failed. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_chown_sync_004', 0, async function () { + let fpath = await nextFileName('fileio_test_chown_sync_004'); + let ffpath = await nextFileName('fileio_test_chown_sync_004_1'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let stat = fileio.statSync(fpath); + fileio.chownSync(ffpath, stat.uid, stat.gid); + } catch (e) { + console.info('fileio_test_chown_sync_004 has failed for ' + e); + expect(e.message == "No such file or directory").assertTrue(); + fileio.unlinkSync(fpath); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_CHOWNASYNC_0000 + * @tc.name fileio_test_chown_async_00 + * @tc.desc Test the chownAsync() interface with promise. The test file was modified successfully. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_chown_async_000', 0, async function (done) { + let fpath = await nextFileName('fileio_test_chown_async_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + fileio.chmodSync(fpath, 0o777); + let stat = fileio.statSync(fpath); + await fileio.chown(fpath, stat.uid, stat.gid); + fileio.unlinkSync(fpath); + done(); + } catch (e) { + console.info('fileio_test_chown_async_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_CHOWNASYNC_0100 + * @tc.name fileio_test_chown_async_001 + * @tc.desc Test the chownAsync() interface with callback. The test file was modified successfully. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_chown_async_001', 0, async function (done) { + let fpath = await nextFileName('fileio_test_chown_async_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + fileio.chmodSync(fpath, 0o777); + let stat = fileio.statSync(fpath); + fileio.chown(fpath, stat.uid, stat.gid, function (error) { + fileio.unlinkSync(fpath); + done(); + }); + } catch (e) { + console.info('fileio_test_chown_async_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_CHOWNASYNC_0200 + * @tc.name fileio_test_chown_async_002 + * @tc.desc Test the chownAsync() interface with promise, wrong uid, gid. Test file modification failed. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_chown_async_002', 0, async function (done) { + let fpath = await nextFileName('fileio_test_chown_async_002'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + await fileio.chown(fpath, 0, 0); + } catch (e) { + console.info('fileio_test_chown_async_002 has failed for ' + e); + expect(e.message == "Operation not permitted").assertTrue(); + fileio.unlinkSync(fpath); + done(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_CHOWNASYNC_0300 + * @tc.name fileio_test_chown_async_003 + * @tc.desc Test the chownAsync() interface with promise, wrong owner. Test file modification failed. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_chown_async_003', 0, async function (done) { + let fpath = await nextFileName('fileio_test_chown_async_003'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let stat = fileio.statSync(fpath); + await fileio.chown(fpath, null, stat.gid); + } catch (e) { + console.info('fileio_test_chown_async_003 has failed for ' + e); + expect(e.message == "Invalid owner").assertTrue(); + fileio.unlinkSync(fpath); + done(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_CHOWNASYNC_0400 + * @tc.name fileio_test_chown_async_004 + * @tc.desc Test the chownAsync() interface with callback, wrong group. Test file modification failed. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_chown_async_004', 0, async function (done) { + let fpath = await nextFileName('fileio_test_chown_async_004'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let stat = fileio.statSync(fpath); + fileio.chown(fpath, stat.uid, null, function (error) { + }); + } catch (e) { + console.info('fileio_test_chown_async_004 has failed for ' + e); + expect(e.message == "Invalid group").assertTrue(); + fileio.unlinkSync(fpath); + done(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_CHOWNASYNC_0500 + * @tc.name fileio_test_chown_async_005 + * @tc.desc Test the chownAsync() interface with promise, file does not exist. Test file modification failed. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_chown_async_005', 0, async function (done) { + let fpath = await nextFileName('fileio_test_chown_async_005'); + let ffpath = await nextFileName('fileio_test_chown_async_005_1'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let stat = fileio.statSync(fpath); + await fileio.chown(ffpath, stat.uid, stat.gid); + } catch (e) { + console.info('fileio_test_chown_async_005 has failed for ' + e); + expect(e.message == "No such file or directory").assertTrue(); + fileio.unlinkSync(fpath); + done(); + } + }); +}); +} diff --git a/storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/members/close.test.js b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/close.test.js similarity index 96% rename from storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/members/close.test.js rename to storage/storagefileiojstest/src/main/js/test/module_fileio/members/close.test.js index f52098303159ebd699ca3717b812e52cc3b3eacc..821798e47d92e2d6ab509c9d17186f71722f2fb9 100644 --- a/storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/members/close.test.js +++ b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/close.test.js @@ -1,198 +1,198 @@ -/* - * Copyright (C) 2023 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 { - fileio, - describe, it, expect, nextFileName, prepareFile, FILE_CONTENT -} from '../../Common'; - -export default function fileioClose() { -describe('fileio_close', function () { - - /** - * @tc.number SUB_DF_FILEIO_CLOSESYNC_0000 - * @tc.name fileio_test_close_sync_000 - * @tc.desc Test closeSync() interfaces. Test file has been closed. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_close_sync_000', 0,async function () { - let fpath = await nextFileName('fileio_test_close_sync_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let fd = fileio.openSync(fpath, 0o102, 0o666); - fileio.closeSync(fd); - fileio.closeSync(fd); - } catch (e) { - console.info('fileio_test_close_sync_000 has failed for ' + e); - expect(e.message == 'Bad file descriptor').assertTrue(); - fileio.unlinkSync(fpath); - } - }) - - /** - * @tc.number SUB_DF_FILEIO_CLOSESYNC_0100 - * @tc.name fileio_test_close_sync_001 - * @tc.desc Test closeSync() interfaces, No parameters. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_close_sync_001', 0, function () { - try { - fileio.closeSync(); - } catch (e) { - console.info('fileio_test_close_sync_001 has failed for ' + e); - expect(e.message == 'Number of arguments unmatched').assertTrue(); - } - }) - - /** - * @tc.number SUB_DF_FILEIO_CLOSESYNC_0200 - * @tc.name fileio_test_close_sync_002 - * @tc.desc Test closeSync() interfaces, fd is illegal. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_close_sync_002', 0, function () { - try { - fileio.closeSync(-1); - expect(false).assertTrue(); - } catch (e) { - console.info('fileio_test_close_sync_002 has failed for ' + e); - expect(e.message == 'Invalid fd').assertTrue(); - } - }) - - /** - * @tc.number SUB_DF_FILEIO_CLOSE_ASYNC_0000 - * @tc.name fileio_test_close_async_000 - * @tc.desc Test close() interfaces, return in callback mode. Test file has been closed. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_close_async_000', 0, async function (done) { - let fpath = await nextFileName('fileio_test_close_async_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - let fd = fileio.openSync(fpath, 0o102, 0o666); - fileio.close(fd, function (err) { - try { - fileio.closeSync(fd); - } catch (e) { - console.info('fileio_test_close_async_000 has failed for ' + e); - expect(e.message == 'Bad file descriptor').assertTrue(); - fileio.unlinkSync(fpath); - done(); - } - }); - }) - - /** - * @tc.number SUB_DF_FILEIO_CLOSE_ASYNC_0100 - * @tc.name fileio_test_close_async_001 - * @tc.desc Test close() interfaces, return in promise mode. Test file has been closed. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_close_async_001', 0, async function (done) { - let fpath = await nextFileName('fileio_test_close_async_001'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let fd = fileio.openSync(fpath, 0o102, 0o666); - await fileio.close(fd); - fileio.closeSync(fd); - } catch (e) { - console.info('fileio_test_close_async_001 has failed for ' + e); - expect(e.message == 'Bad file descriptor').assertTrue(); - fileio.unlinkSync(fpath); - done(); - } - }) - - /** - * @tc.number SUB_DF_FILEIO_CLOSE_ASYNC_0200 - * @tc.name fileio_test_close_async_002 - * @tc.desc Test close() interfaces, there are multiple parameters. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_close_async_002', 0, async function (done) { - let fpath = await nextFileName('fileio_test_close_async_002'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let fd = fileio.openSync(fpath, 0o102, 0o666); - fileio.close(fd, 2, function (err) { - }); - } catch (e) { - console.info('fileio_test_close_async_002 has failed for ' + e); - expect(e.message == "Number of arguments unmatched").assertTrue(); - fileio.unlinkSync(fpath); - done(); - } - }) - - /** - * @tc.number SUB_DF_FILEIO_CLOSE_ASYNC_0300 - * @tc.name fileio_test_close_async_003 - * @tc.desc Test close() interfaces, fd is illegal. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_close_async_003', 0, async function (done) { - try { - await fileio.close(-1); - expect(false).assertTrue(); - } catch (e) { - console.info('fileio_test_close_async_003 has failed for ' + e); - expect(e.message == "Invalid fd").assertTrue(); - done(); - } - }) - - /** - * @tc.number SUB_DF_FILEIO_CLOSE_ASYNC_0400 - * @tc.name fileio_test_close_async_004 - * @tc.desc Test close() interfaces, No parameters. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_close_async_004', 0, async function (done) { - try { - await fileio.close(); - } catch (e) { - console.info('fileio_test_close_async_004 has failed for ' + e); - expect(e.message == "Number of arguments unmatched").assertTrue(); - done(); - } - }) -}) -} +/* + * Copyright (C) 2021 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 { + fileio, + describe, it, expect, nextFileName, prepareFile, FILE_CONTENT +} from '../../Common'; + +export default function fileioClose() { +describe('fileio_close', function () { + + /** + * @tc.number SUB_DF_FILEIO_CLOSESYNC_0000 + * @tc.name fileio_test_close_sync_000 + * @tc.desc Test closeSync() interfaces. Test file has been closed. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_close_sync_000', 0,async function () { + let fpath = await nextFileName('fileio_test_close_sync_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let fd = fileio.openSync(fpath, 0o102, 0o666); + fileio.closeSync(fd); + fileio.closeSync(fd); + } catch (e) { + console.info('fileio_test_close_sync_000 has failed for ' + e); + expect(e.message == 'Bad file descriptor').assertTrue(); + fileio.unlinkSync(fpath); + } + }) + + /** + * @tc.number SUB_DF_FILEIO_CLOSESYNC_0100 + * @tc.name fileio_test_close_sync_001 + * @tc.desc Test closeSync() interfaces, No parameters. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_close_sync_001', 0, function () { + try { + fileio.closeSync(); + } catch (e) { + console.info('fileio_test_close_sync_001 has failed for ' + e); + expect(e.message == 'Number of arguments unmatched').assertTrue(); + } + }) + + /** + * @tc.number SUB_DF_FILEIO_CLOSESYNC_0200 + * @tc.name fileio_test_close_sync_002 + * @tc.desc Test closeSync() interfaces, fd is illegal. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_close_sync_002', 0, function () { + try { + fileio.closeSync(-1); + expect(false).assertTrue(); + } catch (e) { + console.info('fileio_test_close_sync_002 has failed for ' + e); + expect(e.message == 'Invalid fd').assertTrue(); + } + }) + + /** + * @tc.number SUB_DF_FILEIO_CLOSE_ASYNC_0000 + * @tc.name fileio_test_close_async_000 + * @tc.desc Test close() interfaces, return in callback mode. Test file has been closed. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_close_async_000', 0, async function (done) { + let fpath = await nextFileName('fileio_test_close_async_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let fd = fileio.openSync(fpath, 0o102, 0o666); + fileio.close(fd, function (err) { + try { + fileio.closeSync(fd); + } catch (e) { + console.info('fileio_test_close_async_000 has failed for ' + e); + expect(e.message == 'Bad file descriptor').assertTrue(); + fileio.unlinkSync(fpath); + done(); + } + }); + }) + + /** + * @tc.number SUB_DF_FILEIO_CLOSE_ASYNC_0100 + * @tc.name fileio_test_close_async_001 + * @tc.desc Test close() interfaces, return in promise mode. Test file has been closed. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_close_async_001', 0, async function (done) { + let fpath = await nextFileName('fileio_test_close_async_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath, 0o102, 0o666); + await fileio.close(fd); + fileio.closeSync(fd); + } catch (e) { + console.info('fileio_test_close_async_001 has failed for ' + e); + expect(e.message == 'Bad file descriptor').assertTrue(); + fileio.unlinkSync(fpath); + done(); + } + }) + + /** + * @tc.number SUB_DF_FILEIO_CLOSE_ASYNC_0200 + * @tc.name fileio_test_close_async_002 + * @tc.desc Test close() interfaces, there are multiple parameters. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_close_async_002', 0, async function (done) { + let fpath = await nextFileName('fileio_test_close_async_002'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath, 0o102, 0o666); + fileio.close(fd, 2, function (err) { + }); + } catch (e) { + console.info('fileio_test_close_async_002 has failed for ' + e); + expect(e.message == "Number of arguments unmatched").assertTrue(); + fileio.unlinkSync(fpath); + done(); + } + }) + + /** + * @tc.number SUB_DF_FILEIO_CLOSE_ASYNC_0300 + * @tc.name fileio_test_close_async_003 + * @tc.desc Test close() interfaces, fd is illegal. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_close_async_003', 0, async function (done) { + try { + await fileio.close(-1); + expect(false).assertTrue(); + } catch (e) { + console.info('fileio_test_close_async_003 has failed for ' + e); + expect(e.message == "Invalid fd").assertTrue(); + done(); + } + }) + + /** + * @tc.number SUB_DF_FILEIO_CLOSE_ASYNC_0400 + * @tc.name fileio_test_close_async_004 + * @tc.desc Test close() interfaces, No parameters. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_close_async_004', 0, async function (done) { + try { + await fileio.close(); + } catch (e) { + console.info('fileio_test_close_async_004 has failed for ' + e); + expect(e.message == "Number of arguments unmatched").assertTrue(); + done(); + } + }) +}) +} diff --git a/storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/members/copyFile.test.js b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/copyFile.test.js similarity index 96% rename from storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/members/copyFile.test.js rename to storage/storagefileiojstest/src/main/js/test/module_fileio/members/copyFile.test.js index 46239b21315ddf7c502cd4cc86a02231c5ebb0d9..f68f7a25ab6867aa576d54fa9cd373f1607fca2d 100644 --- a/storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/members/copyFile.test.js +++ b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/copyFile.test.js @@ -1,369 +1,369 @@ -/* - * Copyright (C) 2023 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 { - fileio, FILE_CONTENT, prepareFile, nextFileName, - describe, it, expect, -} from '../../Common'; - -export default function fileioCopyfile() { -describe('fileio_copyfile', function () { - - /** - * @tc.number SUB_DF_FILEIO_COPY_FILE_SYNC_0000 - * @tc.name fileio_copy_file_sync_000 - * @tc.desc Test copyFileSync() interfaces. Test file copied successfully. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_copy_file_sync_000', 0, async function () { - let fpath = await nextFileName('fileio_copy_file_sync_000'); - let fpathTarget = fpath + 'tgt'; - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - fileio.copyFileSync(fpath, fpathTarget); - fileio.accessSync(fpathTarget); - fileio.unlinkSync(fpath); - fileio.unlinkSync(fpathTarget); - } catch (e) { - console.info('fileio_copy_file_sync_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_COPY_FILE_SYNC_0100 - * @tc.name fileio_copy_file_sync_001 - * @tc.desc Test copyFileSync() interfaces. Test file copied successfully. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_copy_file_sync_001', 0, async function () { - let fpath = await nextFileName('fileio_copy_file_sync_001'); - let fpathTarget = fpath + 'tgt'; - let fd = fileio.openSync(fpath, 0o102, 0o666); - - try { - fileio.copyFileSync(fd, fpathTarget); - fileio.accessSync(fpathTarget); - fileio.closeSync(fd); - fileio.unlinkSync(fpath); - fileio.unlinkSync(fpathTarget); - } catch (e) { - console.info('fileio_copy_file_sync_001 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_COPY_FILE_SYNC_0200 - * @tc.name fileio_copy_file_sync_002 - * @tc.desc Test copyFileSync() interfaces, invalid path. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_copy_file_sync_002', 0, async function () { - let fpath = await nextFileName('fileio_copy_file_sync_002'); - let fpathTarget = fpath + 'tgt'; - - try { - fileio.copyFileSync(fpath, fpathTarget); - } catch (e) { - console.info('fileio_copy_file_sync_002 has failed for ' + e); - expect(e.message == 'No such file or directory').assertTrue(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_COPY_FILE_SYNC_0300 - * @tc.name fileio_copy_file_sync_003 - * @tc.desc Test copyFileSync() interfaces, No parameters. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_copy_file_sync_003', 0, function () { - try { - fileio.copyFileSync(); - } catch (e) { - console.info('fileio_copy_file_sync_003 has failed for ' + e); - expect(e.message == 'Number of arguments unmatched').assertTrue(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_COPY_FILE_SYNC_0400 - * @tc.name fileio_copy_file_sync_004 - * @tc.desc Test copyFileSync() interfaces, No parameters. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 3 - * @tc.require - */ - it('fileio_copy_file_sync_004', 3, async function () { - let fpath = await nextFileName('fileio_copy_file_sync_004'); - let fpathTarget = fpath + 'tgt'; - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - fileio.copyFileSync(fpath, fpathTarget, undefined); - let stat1 = fileio.statSync(fpath); - let stat2 = fileio.statSync(fpathTarget); - expect(stat1.size == stat2.size).assertTrue(); - fileio.unlinkSync(fpath); - fileio.unlinkSync(fpathTarget); - } catch (e) { - console.log('fileio_copy_file_sync_004 has failed for ' + e); - expect(false).assertTrue(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_COPY_FILE_ASYNC_0000 - * @tc.name fileio_copy_file_async_000 - * @tc.desc Test copyFile() interfaces, return in promise mode. Test file copied successfully. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_copy_file_async_000', 0, async function (done) { - let fpath = await nextFileName('fileio_copy_file_async_000'); - let fpathTarget = fpath + 'tgt'; - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - await fileio.copyFile(fpath, fpathTarget); - fileio.accessSync(fpathTarget); - fileio.unlinkSync(fpath); - fileio.unlinkSync(fpathTarget); - done(); - } catch (e) { - console.info('fileio_copy_file_async_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_COPY_FILE_ASYNC_0100 - * @tc.name fileio_copy_file_async_001 - * @tc.desc Test copyFile() interfaces, return in callback mode. Test file copied successfully. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_copy_file_async_001', 0, async function (done) { - let fpath = await nextFileName('fileio_copy_file_async_001'); - let fpathTarget = fpath + 'tgt'; - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - fileio.copyFile(fpath, fpathTarget, function (error) { - fileio.accessSync(fpathTarget); - fileio.unlinkSync(fpath); - fileio.unlinkSync(fpathTarget); - done(); - }); - } catch (e) { - console.info('fileio_copy_file_async_001 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_COPY_FILE_ASYNC_0200 - * @tc.name fileio_copy_file_async_002 - * @tc.desc Test copyFile() interfaces, return in promise mode. Test file copied successfully. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_copy_file_async_002', 0, async function (done) { - let fpath = await nextFileName('fileio_copy_file_async_002'); - let fpathTarget = fpath + 'tgt'; - let fd = fileio.openSync(fpath, 0o102, 0o666); - - try { - await fileio.copyFile(fd, fpathTarget); - fileio.accessSync(fpathTarget); - fileio.closeSync(fd); - fileio.unlinkSync(fpath); - fileio.unlinkSync(fpathTarget); - done(); - } catch (e) { - console.info('fileio_copy_file_async_002 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_COPY_FILE_ASYNC_0300 - * @tc.name fileio_copy_file_async_003 - * @tc.desc Test copyFile() interfaces, Invalid path. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_copy_file_async_003', 0, async function (done) { - let fpath = await nextFileName('fileio_copy_file_async_003'); - let fpathTarget = fpath + 'tgt'; - try { - await fileio.copyFile(fpath, fpathTarget); - } catch (e) { - console.info('fileio_copy_file_async_003 has failed for ' + e); - expect(e.message == 'No such file or directory').assertTrue(); - done(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_COPY_FILE_ASYNC_0400 - * @tc.name fileio_copy_file_async_004 - * @tc.desc Test copyFile() interfaces. Invalid argument fd < 0. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_copy_file_async_004', 0, async function (done) { - let fpath = await nextFileName('fileio_copy_file_async_004'); - try { - await fileio.copyFile(-1, fpath); - } catch (e) { - console.info('fileio_copy_file_async_004 has failed for ' + e); - expect(e.message == 'The first/second argument requires filepath/fd').assertTrue(); - done(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_COPY_FILE_ASYNC_0500 - * @tc.name fileio_copy_file_async_005 - * @tc.desc Test copyFile() interfaces, Invalid mode. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_copy_file_async_005', 0, async function (done) { - let fpath = await nextFileName('fileio_copy_file_async_005'); - let fpathTarget = fpath + 'tgt'; - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - fileio.copyFile(fpath, fpathTarget, '1', function (error) { - }); - } catch (e) { - console.info('fileio_copy_file_async_005 has failed for ' + e); - expect(e.message == 'Invalid mode' || e.message == 'Invalid arg').assertTrue(); - fileio.unlinkSync(fpath); - done(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_COPY_FILE_ASYNC_0600 - * @tc.name fileio_copy_file_async_006 - * @tc.desc Test copyFile() interfaces, No parameters. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_copy_file_async_006', 0, async function (done) { - try { - await fileio.copyFile(); - } catch (e) { - console.info('fileio_copy_file_async_006 has failed for ' + e); - expect(e.message == 'Number of arguments unmatched').assertTrue(); - done(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_COPY_FILE_ASYNC_0700 - * @tc.name fileio_copy_file_async_007 - * @tc.desc Test copyFile() interfaces. Promise. - * Undefined option arguments, use default mode = 0. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 3 - * @tc.require - */ - it('fileio_copy_file_async_007', 3, async function (done) { - let fpath = await nextFileName('fileio_copy_file_async_007'); - let fpathTarget = fpath + 'tgt'; - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - await fileio.copyFile(fpath, fpathTarget, undefined); - let stat1 = fileio.statSync(fpath); - let stat2 = fileio.statSync(fpathTarget); - expect(stat1.size == stat2.size).assertTrue(); - fileio.unlinkSync(fpath); - fileio.unlinkSync(fpathTarget); - done(); - } catch (e) { - console.log('fileio_copy_file_async_007 has failed for ' + e); - expect(false).assertTrue(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_COPY_FILE_ASYNC_0800 - * @tc.name fileio_copy_file_async_008 - * @tc.desc Test copyFile() interfaces. Callback. - * Undefined option arguments, use default mode = 0. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 3 - * @tc.require - */ - it('fileio_copy_file_async_008', 3, async function (done) { - let fpath = await nextFileName('fileio_copy_file_async_008'); - let fpathTarget = fpath + 'tgt'; - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - fileio.copyFile(fpath, fpathTarget, undefined, (err) => { - if (err) { - console.log('fileio_copy_file_async_008 error package: ' + JSON.stringify(err)); - expect(false).assertTrue(); - } - let stat1 = fileio.statSync(fpath); - let stat2 = fileio.statSync(fpathTarget); - expect(stat1.size == stat2.size).assertTrue(); - fileio.unlinkSync(fpath); - fileio.unlinkSync(fpathTarget); - done(); - }); - } catch (e) { - console.log('fileio_copy_file_async_008 has failed for ' + e); - expect(false).assertTrue(); - } - }); -}); -} +/* + * Copyright (C) 2021 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 { + fileio, FILE_CONTENT, prepareFile, nextFileName, + describe, it, expect, +} from '../../Common'; + +export default function fileioCopyfile() { +describe('fileio_copyfile', function () { + + /** + * @tc.number SUB_DF_FILEIO_COPY_FILE_SYNC_0000 + * @tc.name fileio_copy_file_sync_000 + * @tc.desc Test copyFileSync() interfaces. Test file copied successfully. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_copy_file_sync_000', 0, async function () { + let fpath = await nextFileName('fileio_copy_file_sync_000'); + let fpathTarget = fpath + 'tgt'; + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + fileio.copyFileSync(fpath, fpathTarget); + fileio.accessSync(fpathTarget); + fileio.unlinkSync(fpath); + fileio.unlinkSync(fpathTarget); + } catch (e) { + console.info('fileio_copy_file_sync_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_COPY_FILE_SYNC_0100 + * @tc.name fileio_copy_file_sync_001 + * @tc.desc Test copyFileSync() interfaces. Test file copied successfully. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_copy_file_sync_001', 0, async function () { + let fpath = await nextFileName('fileio_copy_file_sync_001'); + let fpathTarget = fpath + 'tgt'; + let fd = fileio.openSync(fpath, 0o102, 0o666); + + try { + fileio.copyFileSync(fd, fpathTarget); + fileio.accessSync(fpathTarget); + fileio.closeSync(fd); + fileio.unlinkSync(fpath); + fileio.unlinkSync(fpathTarget); + } catch (e) { + console.info('fileio_copy_file_sync_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_COPY_FILE_SYNC_0200 + * @tc.name fileio_copy_file_sync_002 + * @tc.desc Test copyFileSync() interfaces, invalid path. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_copy_file_sync_002', 0, async function () { + let fpath = await nextFileName('fileio_copy_file_sync_002'); + let fpathTarget = fpath + 'tgt'; + + try { + fileio.copyFileSync(fpath, fpathTarget); + } catch (e) { + console.info('fileio_copy_file_sync_002 has failed for ' + e); + expect(e.message == 'No such file or directory').assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_COPY_FILE_SYNC_0300 + * @tc.name fileio_copy_file_sync_003 + * @tc.desc Test copyFileSync() interfaces, No parameters. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_copy_file_sync_003', 0, function () { + try { + fileio.copyFileSync(); + } catch (e) { + console.info('fileio_copy_file_sync_003 has failed for ' + e); + expect(e.message == 'Number of arguments unmatched').assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_COPY_FILE_SYNC_0400 + * @tc.name fileio_copy_file_sync_004 + * @tc.desc Test copyFileSync() interfaces, No parameters. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileio_copy_file_sync_004', 3, async function () { + let fpath = await nextFileName('fileio_copy_file_sync_004'); + let fpathTarget = fpath + 'tgt'; + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + fileio.copyFileSync(fpath, fpathTarget, undefined); + let stat1 = fileio.statSync(fpath); + let stat2 = fileio.statSync(fpathTarget); + expect(stat1.size == stat2.size).assertTrue(); + fileio.unlinkSync(fpath); + fileio.unlinkSync(fpathTarget); + } catch (e) { + console.log('fileio_copy_file_sync_004 has failed for ' + e); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_COPY_FILE_ASYNC_0000 + * @tc.name fileio_copy_file_async_000 + * @tc.desc Test copyFile() interfaces, return in promise mode. Test file copied successfully. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_copy_file_async_000', 0, async function (done) { + let fpath = await nextFileName('fileio_copy_file_async_000'); + let fpathTarget = fpath + 'tgt'; + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + await fileio.copyFile(fpath, fpathTarget); + fileio.accessSync(fpathTarget); + fileio.unlinkSync(fpath); + fileio.unlinkSync(fpathTarget); + done(); + } catch (e) { + console.info('fileio_copy_file_async_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_COPY_FILE_ASYNC_0100 + * @tc.name fileio_copy_file_async_001 + * @tc.desc Test copyFile() interfaces, return in callback mode. Test file copied successfully. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_copy_file_async_001', 0, async function (done) { + let fpath = await nextFileName('fileio_copy_file_async_001'); + let fpathTarget = fpath + 'tgt'; + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + fileio.copyFile(fpath, fpathTarget, function (error) { + fileio.accessSync(fpathTarget); + fileio.unlinkSync(fpath); + fileio.unlinkSync(fpathTarget); + done(); + }); + } catch (e) { + console.info('fileio_copy_file_async_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_COPY_FILE_ASYNC_0200 + * @tc.name fileio_copy_file_async_002 + * @tc.desc Test copyFile() interfaces, return in promise mode. Test file copied successfully. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_copy_file_async_002', 0, async function (done) { + let fpath = await nextFileName('fileio_copy_file_async_002'); + let fpathTarget = fpath + 'tgt'; + let fd = fileio.openSync(fpath, 0o102, 0o666); + + try { + await fileio.copyFile(fd, fpathTarget); + fileio.accessSync(fpathTarget); + fileio.closeSync(fd); + fileio.unlinkSync(fpath); + fileio.unlinkSync(fpathTarget); + done(); + } catch (e) { + console.info('fileio_copy_file_async_002 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_COPY_FILE_ASYNC_0300 + * @tc.name fileio_copy_file_async_003 + * @tc.desc Test copyFile() interfaces, Invalid path. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_copy_file_async_003', 0, async function (done) { + let fpath = await nextFileName('fileio_copy_file_async_003'); + let fpathTarget = fpath + 'tgt'; + try { + await fileio.copyFile(fpath, fpathTarget); + } catch (e) { + console.info('fileio_copy_file_async_003 has failed for ' + e); + expect(e.message == 'No such file or directory').assertTrue(); + done(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_COPY_FILE_ASYNC_0400 + * @tc.name fileio_copy_file_async_004 + * @tc.desc Test copyFile() interfaces. Invalid argument fd < 0. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_copy_file_async_004', 0, async function (done) { + let fpath = await nextFileName('fileio_copy_file_async_004'); + try { + await fileio.copyFile(-1, fpath); + } catch (e) { + console.info('fileio_copy_file_async_004 has failed for ' + e); + expect(e.message == 'The first/second argument requires filepath/fd').assertTrue(); + done(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_COPY_FILE_ASYNC_0500 + * @tc.name fileio_copy_file_async_005 + * @tc.desc Test copyFile() interfaces, Invalid mode. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_copy_file_async_005', 0, async function (done) { + let fpath = await nextFileName('fileio_copy_file_async_005'); + let fpathTarget = fpath + 'tgt'; + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + fileio.copyFile(fpath, fpathTarget, '1', function (error) { + }); + } catch (e) { + console.info('fileio_copy_file_async_005 has failed for ' + e); + expect(e.message == 'Invalid mode' || e.message == 'Invalid arg').assertTrue(); + fileio.unlinkSync(fpath); + done(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_COPY_FILE_ASYNC_0600 + * @tc.name fileio_copy_file_async_006 + * @tc.desc Test copyFile() interfaces, No parameters. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_copy_file_async_006', 0, async function (done) { + try { + await fileio.copyFile(); + } catch (e) { + console.info('fileio_copy_file_async_006 has failed for ' + e); + expect(e.message == 'Number of arguments unmatched').assertTrue(); + done(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_COPY_FILE_ASYNC_0700 + * @tc.name fileio_copy_file_async_007 + * @tc.desc Test copyFile() interfaces. Promise. + * Undefined option arguments, use default mode = 0. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileio_copy_file_async_007', 3, async function (done) { + let fpath = await nextFileName('fileio_copy_file_async_007'); + let fpathTarget = fpath + 'tgt'; + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + await fileio.copyFile(fpath, fpathTarget, undefined); + let stat1 = fileio.statSync(fpath); + let stat2 = fileio.statSync(fpathTarget); + expect(stat1.size == stat2.size).assertTrue(); + fileio.unlinkSync(fpath); + fileio.unlinkSync(fpathTarget); + done(); + } catch (e) { + console.log('fileio_copy_file_async_007 has failed for ' + e); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_COPY_FILE_ASYNC_0800 + * @tc.name fileio_copy_file_async_008 + * @tc.desc Test copyFile() interfaces. Callback. + * Undefined option arguments, use default mode = 0. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileio_copy_file_async_008', 3, async function (done) { + let fpath = await nextFileName('fileio_copy_file_async_008'); + let fpathTarget = fpath + 'tgt'; + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + fileio.copyFile(fpath, fpathTarget, undefined, (err) => { + if (err) { + console.log('fileio_copy_file_async_008 error package: ' + JSON.stringify(err)); + expect(false).assertTrue(); + } + let stat1 = fileio.statSync(fpath); + let stat2 = fileio.statSync(fpathTarget); + expect(stat1.size == stat2.size).assertTrue(); + fileio.unlinkSync(fpath); + fileio.unlinkSync(fpathTarget); + done(); + }); + } catch (e) { + console.log('fileio_copy_file_async_008 has failed for ' + e); + expect(false).assertTrue(); + } + }); +}); +} diff --git a/storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/members/createRandomAccessFile.test.js b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/createRandomAccessFile.test.js similarity index 97% rename from storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/members/createRandomAccessFile.test.js rename to storage/storagefileiojstest/src/main/js/test/module_fileio/members/createRandomAccessFile.test.js index 3c6e4fb8354d3068b0066fac726423c53840168d..f08dd145551066430dffd383223246b1056380d1 100644 --- a/storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/members/createRandomAccessFile.test.js +++ b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/createRandomAccessFile.test.js @@ -1,920 +1,920 @@ -/* - * Copyright (C) 2023 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 { - fileio, prepareFile, nextFileName, isIntNum, FILE_CONTENT, - describe, it, expect -} from '../../Common'; - -export default function fileioCreateRandomAccessFile() { -describe('fileio_create_randomAccessFile', function () { - - /** - * @tc.number SUB_STORAGE_FILEIO_CREATE_RANDOMACCESSFILE_SYNC_0000 - * @tc.name fileio_create_randomaccessfile_sync_000 - * @tc.desc Test createRandomAccessFileSync() interface. - * Create RandomAccessFile object to access file based on file path. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_create_randomaccessfile_sync_000', 0, async function () { - let fpath = await nextFileName('fileio_create_randomaccessfile_sync_000'); - expect(prepareFile(fpath, '')).assertTrue(); - - try { - let randomaccessfile = fileio.createRandomAccessFileSync(fpath, 0, 0o2); - expect(isIntNum(randomaccessfile.fd)).assertTrue(); - randomaccessfile.closeSync(); - fileio.unlinkSync(fpath); - } catch(err) { - console.info('fileio_create_randomaccessfile_sync_000 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FILEIO_CREATE_RANDOMACCESSFILE_SYNC_0100 - * @tc.name fileio_create_randomaccessfile_sync_001 - * @tc.desc Test createRandomAccessFileSync() interface. fpointer = 5. - * Create RandomAccessFile object to access file from fpointer location. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_create_randomaccessfile_sync_001', 0, async function () { - let fpath = await nextFileName('fileio_create_randomaccessfile_sync_001'); - - try { - let randomaccessfile = fileio.createRandomAccessFileSync(fpath, 5, 0o102); - expect(isIntNum(randomaccessfile.fd)).assertTrue(); - expect(randomaccessfile.fpointer == 5).assertTrue(); - randomaccessfile.closeSync(); - fileio.unlinkSync(fpath); - } catch(err) { - console.info('fileio_create_randomaccessfile_sync_001 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FILEIO_CREATE_RANDOMACCESSFILE_SYNC_0200 - * @tc.name fileio_create_randomaccessfile_sync_002 - * @tc.desc Test createRandomAccessFileSync() interface. - * Create RandomAccessFile object based on file descriptor to access file. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_create_randomaccessfile_sync_002', 0, async function () { - let fpath = await nextFileName('fileio_create_randomaccessfile_sync_002'); - - try { - let fd = fileio.openSync(fpath, 0o102, 0o666); - let randomaccessfile = fileio.createRandomAccessFileSync(fd, 0); - expect(isIntNum(randomaccessfile.fd)).assertTrue(); - randomaccessfile.closeSync(); - fileio.unlinkSync(fpath); - } catch(err) { - console.info('fileio_create_randomaccessfile_sync_002 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FILEIO_CREATE_RANDOMACCESSFILE_SYNC_0300 - * @tc.name fileio_create_randomaccessfile_sync_003 - * @tc.desc Test createRandomAccessFileSync() interface. fpointer = 1. - * Create RandomAccessFile object based on file descriptor to access file. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_create_randomaccessfile_sync_003', 0, async function () { - let fpath = await nextFileName('fileio_create_randomaccessfile_sync_003'); - - try { - let fd = fileio.openSync(fpath, 0o102, 0o666); - let randomaccessfile = fileio.createRandomAccessFileSync(fd, 1); - expect(isIntNum(randomaccessfile.fd)).assertTrue(); - expect(randomaccessfile.fpointer == 1).assertTrue(); - randomaccessfile.closeSync(); - fileio.unlinkSync(fpath); - } catch(err) { - console.info('fileio_create_randomaccessfile_sync_003 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FILEIO_CREATE_RANDOMACCESSFILE_SYNC_0400 - * @tc.name fileio_create_randomaccessfile_sync_004 - * @tc.desc Test createRandomAccessFileSync() interface. No such file or directory. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_create_randomaccessfile_sync_004', 0, async function () { - let fpath = await nextFileName('fileio_create_randomaccessfile_sync_004'); - - try { - fileio.createRandomAccessFileSync(fpath, 0, 0o2); - expect(false).assertTrue(); - } catch(err) { - console.info('fileio_create_randomaccessfile_sync_004 has failed for ' + err); - expect(err.message == "No such file or directory").assertTrue(); - } - }); - - /** - * @tc.number SUB_STORAGE_FILEIO_CREATE_RANDOMACCESSFILE_SYNC_0500 - * @tc.name fileio_create_randomaccessfile_sync_005 - * @tc.desc Test createRandomAccessFileSync() interface. Invalid fd. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_create_randomaccessfile_sync_005', 0, async function () { - try { - fileio.createRandomAccessFileSync(-1, 0); - expect(false).assertTrue(); - } catch(err) { - console.info('fileio_create_randomaccessfile_sync_005 has failed for ' + err); - expect(err.message == "Invalid fd").assertTrue(); - } - }); - - /** - * @tc.number SUB_STORAGE_FILEIO_CREATE_RANDOMACCESSFILE_SYNC_0600 - * @tc.name fileio_create_randomaccessfile_sync_006 - * @tc.desc Test createRandomAccessFileSync() interface. Invalid fp. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_create_randomaccessfile_sync_006', 0, async function () { - let fpath = await nextFileName('fileio_create_randomaccessfile_sync_006'); - let fd = fileio.openSync(fpath, 0o102, 0o666); - - try { - fileio.createRandomAccessFileSync(fd, '1'); - expect(false).assertTrue(); - } catch(err) { - console.info('fileio_create_randomaccessfile_sync_006 has failed for ' + err); - expect(err.message == "Invalid fp").assertTrue(); - fileio.closeSync(fd); - fileio.unlinkSync(fpath); - } - }); - - /** - * @tc.number SUB_STORAGE_FILEIO_CREATE_RANDOMACCESSFILE_SYNC_0700 - * @tc.name fileio_create_randomaccessfile_sync_007 - * @tc.desc Test createRandomAccessFileSync() interface. Missing Parameter. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_create_randomaccessfile_sync_007', 0, async function () { - let fpath = await nextFileName('fileio_create_randomaccessfile_sync_007'); - let fd = fileio.openSync(fpath, 0o102, 0o666); - - try { - fileio.createRandomAccessFileSync(fd); - expect(false).assertTrue(); - } catch(err) { - console.info('fileio_create_randomaccessfile_sync_007 has failed for ' + err); - expect(err.message == "Number of arguments unmatched").assertTrue(); - fileio.closeSync(fd); - fileio.unlinkSync(fpath); - } - }); - - /** - * @tc.number SUB_STORAGE_FILEIO_CREATE_RANDOMACCESSFILE_SYNC_0800 - * @tc.name fileio_create_randomaccessfile_sync_008 - * @tc.desc Test createRandomAccessFileSync() interface. flags=0o202. - * Create RandomAccessFile object to access file based on file path. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_create_randomaccessfile_sync_008', 0, async function () { - let fpath = await nextFileName('fileio_create_randomaccessfile_sync_008'); - expect(prepareFile(fpath, '')).assertTrue(); - - try { - let randomaccessfile = fileio.createRandomAccessFileSync(fpath, 0, 0o202); - expect(isIntNum(randomaccessfile.fd)).assertTrue(); - randomaccessfile.closeSync(); - fileio.unlinkSync(fpath); - } catch(err) { - console.info('fileio_create_randomaccessfile_sync_008 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FILEIO_CREATE_RANDOMACCESSFILE_SYNC_0900 - * @tc.name fileio_create_randomaccessfile_sync_009 - * @tc.desc Test createRandomAccessFileSync() interface. flags=0o302. File exists. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_create_randomaccessfile_sync_009', 0, async function () { - let fpath = await nextFileName('fileio_create_randomaccessfile_sync_009'); - expect(prepareFile(fpath, '')).assertTrue(); - - try { - fileio.createRandomAccessFileSync(fpath, 0, 0o302); - expect(false).assertTrue(); - } catch(err) { - console.info('fileio_create_randomaccessfile_sync_009 has failed for ' + err); - expect(err.message == "File exists").assertTrue(); - fileio.unlinkSync(fpath); - } - }); - - /** - * @tc.number SUB_STORAGE_FILEIO_CREATE_RANDOMACCESSFILE_SYNC_1000 - * @tc.name fileio_create_randomaccessfile_sync_010 - * @tc.desc Test createRandomAccessFileSync() interface. flags=0o1002. - * If the file exists and the file is opened for write-only or read-write, trim its length to zero. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_create_randomaccessfile_sync_010', 0, async function () { - let fpath = await nextFileName('fileio_create_randomaccessfile_sync_010'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let randomaccessfile = fileio.createRandomAccessFileSync(fpath, 0, 0o1002); - let number = randomaccessfile.readSync(new ArrayBuffer(4096)); - expect(number == 0).assertTrue(); - randomaccessfile.closeSync(); - fileio.unlinkSync(fpath); - } catch(err) { - console.info('fileio_create_randomaccessfile_sync_010 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FILEIO_CREATE_RANDOMACCESSFILE_SYNC_1100 - * @tc.name fileio_create_randomaccessfile_sync_011 - * @tc.desc Test createRandomAccessFileSync() interface. flags=0o2002. - * Open as append, subsequent writes will append to the end of the file. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_create_randomaccessfile_sync_011', 0, async function () { - let fpath = await nextFileName('fileio_create_randomaccessfile_sync_011'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let randomaccessfile = fileio.createRandomAccessFileSync(fpath, 0, 0o2002); - let length = 100; - let num = randomaccessfile.writeSync(new ArrayBuffer(length)); - expect(num == length).assertTrue(); - randomaccessfile.setFilePointerSync(0); - let number = randomaccessfile.readSync(new ArrayBuffer(4096), { position: 0 }); - expect(number == length + FILE_CONTENT.length).assertTrue(); - randomaccessfile.closeSync(); - fileio.unlinkSync(fpath); - } catch(err) { - console.info('fileio_create_randomaccessfile_sync_011 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FILEIO_CREATE_RANDOMACCESSFILE_SYNC_1200 - * @tc.name fileio_create_randomaccessfile_sync_012 - * @tc.desc Test createRandomAccessFileSync() interface. flags=0o200002. Not a directory. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_create_randomaccessfile_sync_012', 0, async function () { - let fpath = await nextFileName('fileio_create_randomaccessfile_sync_012'); - expect(prepareFile(fpath, '')).assertTrue(); - - try { - fileio.createRandomAccessFileSync(fpath, 0, 0o200002); - expect(false).assertTrue(); - } catch(err) { - console.info('fileio_create_randomaccessfile_sync_012 has failed for ' + err); - expect(err.message == "Not a directory").assertTrue(); - fileio.unlinkSync(fpath); - } - }); - - /** - * @tc.number SUB_STORAGE_FILEIO_CREATE_RANDOMACCESSFILE_SYNC_1300 - * @tc.name fileio_create_randomaccessfile_sync_013 - * @tc.desc Test createRandomAccessFileSync() interface. flags=0o400002. - * Create RandomAccessFile object to access file based on file path. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_create_randomaccessfile_sync_013', 0, async function () { - let fpath = await nextFileName('fileio_create_randomaccessfile_sync_013'); - expect(prepareFile(fpath, '')).assertTrue(); - - try { - let randomaccessfile = fileio.createRandomAccessFileSync(fpath, 0, 0o400002); - expect(isIntNum(randomaccessfile.fd)).assertTrue(); - randomaccessfile.closeSync(); - fileio.unlinkSync(fpath); - } catch(err) { - console.info('fileio_create_randomaccessfile_sync_013 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FILEIO_CREATE_RANDOMACCESSFILE_SYNC_1400 - * @tc.name fileio_create_randomaccessfile_sync_014 - * @tc.desc Test createRandomAccessFileSync() interface. flags=0o4010002. - * Create RandomAccessFile object to access file based on file path. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_create_randomaccessfile_sync_014', 0, async function () { - let fpath = await nextFileName('fileio_create_randomaccessfile_sync_014'); - expect(prepareFile(fpath, '')).assertTrue(); - - try { - let randomaccessfile = fileio.createRandomAccessFileSync(fpath, 0, 0o4010002); - expect(isIntNum(randomaccessfile.fd)).assertTrue(); - randomaccessfile.closeSync(); - fileio.unlinkSync(fpath); - } catch(err) { - console.info('fileio_create_randomaccessfile_sync_014 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FILEIO_CREATE_RANDOMACCESSFILE_SYNC_1500 - * @tc.name fileio_create_randomaccessfile_sync_015 - * @tc.desc Test createRandomAccessFileSync() interface. flags=0o200002. Invalid filepath. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_create_randomaccessfile_sync_015', 0, async function () { - let dpath = await nextFileName('fileio_create_randomaccessfile_sync_015') + 'd'; - fileio.mkdirSync(dpath); - - try { - fileio.createRandomAccessFileSync(dpath, 0, 0o200002); - expect(false).assertTrue(); - } catch(err) { - console.info('fileio_create_randomaccessfile_sync_015 has failed for ' + err); - expect(err.message == "Invalid filepath").assertTrue(); - fileio.rmdirSync(dpath); - } - }); - - /** - * @tc.number SUB_STORAGE_FILEIO_CREATE_RANDOMACCESSFILE_SYNC_1600 - * @tc.name fileio_create_randomaccessfile_sync_016 - * @tc.desc Test createRandomAccessFileSync() interface. flags=0o400002. Symbolic link loop. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_create_randomaccessfile_sync_016', 0, async function () { - let fpath = await nextFileName('fileio_create_randomaccessfile_sync_016'); - let ffpath = fpath + 'aaaa'; - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - fileio.symlinkSync(fpath, ffpath); - fileio.createRandomAccessFileSync(ffpath, 0, 0o400002); - expect(false).assertTrue(); - } catch(err) { - console.info('fileio_create_randomaccessfile_sync_016 has failed for ' + err); - expect(err.message == 'Symbolic link loop' || - err.message == 'Too many symbolic links encountered').assertTrue(); - fileio.unlinkSync(fpath); - fileio.unlinkSync(ffpath); - } - }); - - /** - * @tc.number SUB_STORAGE_FILEIO_CREATE_RANDOMACCESSFILE_ASYNC_0000 - * @tc.name fileio_create_randomaccessfile_async_000 - * @tc.desc Test createRandomAccessFile() interface. return in promise mode. - * Create RandomAccessFile object to access file based on file path. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_create_randomaccessfile_async_000', 0, async function (done) { - let fpath = await nextFileName('fileio_create_randomaccessfile_async_000'); - expect(prepareFile(fpath, '')).assertTrue(); - - try { - let randomaccessfile = await fileio.createRandomAccessFile(fpath, 0, 0o2); - expect(isIntNum(randomaccessfile.fd)).assertTrue(); - randomaccessfile.closeSync(); - fileio.unlinkSync(fpath); - done(); - } catch(err) { - console.info('fileio_create_randomaccessfile_async_000 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FILEIO_CREATE_RANDOMACCESSFILE_ASYNC_0100 - * @tc.name fileio_create_randomaccessfile_async_001 - * @tc.desc Test createRandomAccessFile() interface. fpointer = 10. return in callback mode. - * Create RandomAccessFile object to access file based on file path. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_create_randomaccessfile_async_001', 0, async function (done) { - let fpath = await nextFileName('fileio_create_randomaccessfile_async_001'); - - try { - fileio.createRandomAccessFile(fpath, 10, 0o102, function(err, randomaccessfile) { - expect(isIntNum(randomaccessfile.fd)).assertTrue(); - expect(randomaccessfile.fpointer == 10).assertTrue(); - randomaccessfile.closeSync(); - fileio.unlinkSync(fpath); - done(); - }); - } catch(err) { - console.info('fileio_create_randomaccessfile_async_001 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FILEIO_CREATE_RANDOMACCESSFILE_ASYNC_0200 - * @tc.name fileio_create_randomaccessfile_async_002 - * @tc.desc Test createRandomAccessFile() interface. - * Create RandomAccessFile object based on file descriptor to access file. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_create_randomaccessfile_async_002', 0, async function (done) { - let fpath = await nextFileName('fileio_create_randomaccessfile_async_002'); - - try { - let fd = fileio.openSync(fpath, 0o102, 0o666); - fileio.createRandomAccessFile(fd, 0, function(err, randomaccessfile) { - expect(isIntNum(randomaccessfile.fd)).assertTrue(); - randomaccessfile.closeSync(); - fileio.unlinkSync(fpath); - done(); - }); - } catch(err) { - console.info('fileio_create_randomaccessfile_async_002 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FILEIO_CREATE_RANDOMACCESSFILE_ASYNC_0300 - * @tc.name fileio_create_randomaccessfile_async_003 - * @tc.desc Test createRandomAccessFile() interface. fpointer = 1. - * Create RandomAccessFile object based on file descriptor to access file. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_create_randomaccessfile_async_003', 0, async function (done) { - let fpath = await nextFileName('fileio_create_randomaccessfile_async_003'); - - try { - let fd = fileio.openSync(fpath, 0o102, 0o666); - let randomaccessfile = await fileio.createRandomAccessFile(fd, 1); - expect(isIntNum(randomaccessfile.fd)).assertTrue(); - expect(randomaccessfile.fpointer == 1).assertTrue(); - randomaccessfile.closeSync(); - fileio.unlinkSync(fpath); - done(); - } catch(err) { - console.info('fileio_create_randomaccessfile_async_003 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FILEIO_CREATE_RANDOMACCESSFILE_ASYNC_0400 - * @tc.name fileio_create_randomaccessfile_async_004 - * @tc.desc Test createRandomAccessFile() interface. No such file or directory. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_create_randomaccessfile_async_004', 0, async function (done) { - let fpath = await nextFileName('fileio_create_randomaccessfile_async_004'); - - try { - await fileio.createRandomAccessFile(fpath, 0, 0o2); - } catch(err) { - console.info('fileio_create_randomaccessfile_async_004 has failed for ' + err); - expect(err.message == "No such file or directory").assertTrue(); - done(); - } - }); - - /** - * @tc.number SUB_STORAGE_FILEIO_CREATE_RANDOMACCESSFILE_ASYNC_0500 - * @tc.name fileio_create_randomaccessfile_async_005 - * @tc.desc Test createRandomAccessFile() interface. Invalid fd. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_create_randomaccessfile_async_005', 0, async function (done) { - try { - fileio.createRandomAccessFile(-1, 0, function(err) { - }); - } catch(err) { - console.info('fileio_create_randomaccessfile_async_005 has failed for ' + err); - expect(err.message == "Invalid fd").assertTrue(); - done(); - } - }); - - /** - * @tc.number SUB_STORAGE_FILEIO_CREATE_RANDOMACCESSFILE_ASYNC_0600 - * @tc.name fileio_create_randomaccessfile_async_006 - * @tc.desc Test createRandomAccessFile() interface. Invalid fp. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_create_randomaccessfile_async_006', 0, async function (done) { - let fpath = await nextFileName('fileio_create_randomaccessfile_async_006'); - let fd = fileio.openSync(fpath, 0o102, 0o666); - - try { - await fileio.createRandomAccessFile(fd, '1'); - } catch(err) { - console.info('fileio_create_randomaccessfile_async_006 has failed for ' + err); - expect(err.message == "Invalid fp").assertTrue(); - fileio.closeSync(fd); - fileio.unlinkSync(fpath); - done(); - } - }); - - /** - * @tc.number SUB_STORAGE_FILEIO_CREATE_RANDOMACCESSFILE_ASYNC_0700 - * @tc.name fileio_create_randomaccessfile_async_007 - * @tc.desc Test createRandomAccessFile() interface. Missing Parameter. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_create_randomaccessfile_async_007', 0, async function (done) { - let fpath = await nextFileName('fileio_create_randomaccessfile_async_007'); - let fd = fileio.openSync(fpath, 0o102, 0o666); - - try { - await fileio.createRandomAccessFile(fd); - } catch(err) { - console.info('fileio_create_randomaccessfile_async_007 has failed for ' + err); - expect(err.message == "Number of arguments unmatched").assertTrue(); - fileio.closeSync(fd); - fileio.unlinkSync(fpath); - done(); - } - }); - - /** - * @tc.number SUB_STORAGE_FILEIO_CREATE_RANDOMACCESSFILE_ASYNC_0800 - * @tc.name fileio_create_randomaccessfile_async_008 - * @tc.desc Test createRandomAccessFile() interface. flags=0o202. - * Create RandomAccessFile object to access file based on file path. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_create_randomaccessfile_async_008', 0, async function (done) { - let fpath = await nextFileName('fileio_create_randomaccessfile_async_008'); - expect(prepareFile(fpath, '')).assertTrue(); - - try { - fileio.createRandomAccessFile(fpath, 0, 0o202, function(err, randomaccessfile) { - expect(isIntNum(randomaccessfile.fd)).assertTrue(); - randomaccessfile.closeSync(); - fileio.unlinkSync(fpath); - done(); - }); - } catch(err) { - console.info('fileio_create_randomaccessfile_async_008 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FILEIO_CREATE_RANDOMACCESSFILE_SYNC_0900 - * @tc.name fileio_create_randomaccessfile_sync_009 - * @tc.desc Test createRandomAccessFile() interface. flags=0o302. File exists. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_create_randomaccessfile_async_009', 0, async function (done) { - let fpath = await nextFileName('fileio_create_randomaccessfile_async_009'); - expect(prepareFile(fpath, '')).assertTrue(); - - try { - await fileio.createRandomAccessFile(fpath, 0, 0o302); - } catch(err) { - console.info('fileio_create_randomaccessfile_async_009 has failed for ' + err); - expect(err.message == "File exists").assertTrue(); - fileio.unlinkSync(fpath); - done(); - } - }); - - /** - * @tc.number SUB_STORAGE_FILEIO_CREATE_RANDOMACCESSFILE_ASYNC_1000 - * @tc.name fileio_create_randomaccessfile_async_010 - * @tc.desc Test createRandomAccessFile() interface. flags=0o1002. - * If the file exists and the file is opened for write-only or read-write, trim its length to zero. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_create_randomaccessfile_async_010', 0, async function (done) { - let fpath = await nextFileName('fileio_create_randomaccessfile_async_010'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let randomaccessfile = await fileio.createRandomAccessFile(fpath, 0, 0o1002); - let number = randomaccessfile.readSync(new ArrayBuffer(4096)); - expect(number == 0).assertTrue(); - randomaccessfile.closeSync(); - fileio.unlinkSync(fpath); - done(); - } catch(err) { - console.info('fileio_create_randomaccessfile_async_010 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FILEIO_CREATE_RANDOMACCESSFILE_ASYNC_1100 - * @tc.name fileio_create_randomaccessfile_async_011 - * @tc.desc Test createRandomAccessFile() interface. flags=0o2002. - * Open as append, subsequent writes will append to the end of the file. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_create_randomaccessfile_async_011', 0, async function (done) { - let fpath = await nextFileName('fileio_create_randomaccessfile_async_011'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let randomaccessfile = await fileio.createRandomAccessFile(fpath, 0, 0o2002); - let length = 100; - let num = randomaccessfile.writeSync(new ArrayBuffer(length)); - expect(num == length).assertTrue(); - randomaccessfile.setFilePointerSync(0); - let number = randomaccessfile.readSync(new ArrayBuffer(4096), { position: 0 }); - expect(number == length + FILE_CONTENT.length).assertTrue(); - randomaccessfile.closeSync(); - fileio.unlinkSync(fpath); - done(); - } catch(err) { - console.info('fileio_create_randomaccessfile_async_011 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FILEIO_CREATE_RANDOMACCESSFILE_ASYNC_1200 - * @tc.name fileio_create_randomaccessfile_async_012 - * @tc.desc Test createRandomAccessFile() interface. flags=0o200002. Not a directory. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_create_randomaccessfile_async_012', 0, async function (done) { - let fpath = await nextFileName('fileio_create_randomaccessfile_async_012'); - expect(prepareFile(fpath, '')).assertTrue(); - - try { - await fileio.createRandomAccessFile(fpath, 0, 0o200002); - } catch(err) { - console.info('fileio_create_randomaccessfile_async_012 has failed for ' + err); - expect(err.message == "Not a directory").assertTrue(); - fileio.unlinkSync(fpath); - done(); - } - }); - - /** - * @tc.number SUB_STORAGE_FILEIO_CREATE_RANDOMACCESSFILE_ASYNC_1300 - * @tc.name fileio_create_randomaccessfile_async_013 - * @tc.desc Test createRandomAccessFile() interface. flags=0o400002. - * Create RandomAccessFile object to access file based on file path. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_create_randomaccessfile_async_013', 0, async function (done) { - let fpath = await nextFileName('fileio_create_randomaccessfile_async_013'); - expect(prepareFile(fpath, '')).assertTrue(); - - try { - let randomaccessfile = await fileio.createRandomAccessFile(fpath, 0, 0o400002); - expect(isIntNum(randomaccessfile.fd)).assertTrue(); - randomaccessfile.closeSync(); - fileio.unlinkSync(fpath); - done(); - } catch(err) { - console.info('fileio_create_randomaccessfile_async_013 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FILEIO_CREATE_RANDOMACCESSFILE_ASYNC_1400 - * @tc.name fileio_create_randomaccessfile_async_014 - * @tc.desc Test createRandomAccessFile() interface. flags=0o4010002. - * Create RandomAccessFile object to access file based on file path. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_create_randomaccessfile_async_014', 0, async function (done) { - let fpath = await nextFileName('fileio_create_randomaccessfile_async_014'); - expect(prepareFile(fpath, '')).assertTrue(); - - try { - let randomaccessfile = await fileio.createRandomAccessFile(fpath, 0, 0o4010002); - expect(isIntNum(randomaccessfile.fd)).assertTrue(); - randomaccessfile.closeSync(); - fileio.unlinkSync(fpath); - done(); - } catch(err) { - console.info('fileio_create_randomaccessfile_async_014 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FILEIO_CREATE_RANDOMACCESSFILE_ASYNC_1500 - * @tc.name fileio_create_randomaccessfile_async_015 - * @tc.desc Test createRandomAccessFile() interface. flags=0o200002. Invalid filepath. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_create_randomaccessfile_async_015', 0, async function (done) { - let dpath = await nextFileName('fileio_create_randomaccessfile_async_015') + 'd'; - fileio.mkdirSync(dpath); - - try { - await fileio.createRandomAccessFile(dpath, 0, 0o200002); - } catch(err) { - console.info('fileio_create_randomaccessfile_async_015 has failed for ' + err); - expect(err.message == "Invalid filepath").assertTrue(); - fileio.rmdirSync(dpath); - done(); - } - }); - - /** - * @tc.number SUB_STORAGE_FILEIO_CREATE_RANDOMACCESSFILE_ASYNC_1600 - * @tc.name fileio_create_randomaccessfile_async_016 - * @tc.desc Test createRandomAccessFile() interface. flags=0o400002. Symbolic link loop. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_create_randomaccessfile_async_016', 0, async function (done) { - let fpath = await nextFileName('fileio_create_randomaccessfile_async_016'); - let ffpath = fpath + 'aaaa'; - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - fileio.symlinkSync(fpath, ffpath); - await fileio.createRandomAccessFile(ffpath, 0, 0o400002); - } catch(err) { - console.info('fileio_create_randomaccessfile_async_016 has failed for ' + err); - expect(err.message == 'Symbolic link loop' || - err.message == 'Too many symbolic links encountered').assertTrue(); - fileio.unlinkSync(fpath); - fileio.unlinkSync(ffpath); - done(); - } - }); - - /** - * @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_MULTITHREADED_REPLICATION_0000 - * @tc.name fileio_randomaccessfile_multithreaded_replication_000 - * @tc.desc Test createRandomAccessFileSync() interface. Test multi-threaded replication. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_randomaccessfile_multithreaded_replication_000', 0, async function (done) { - let srcpath = await nextFileName('fileio_randomaccessfile_multithreaded_replication_000'); - let dstpath = await nextFileName('fileio_randomaccessfile_multithreaded_replication_000_1'); - let length = 4096; - let buffer = new ArrayBuffer(length); - expect(prepareFile(srcpath, buffer)).assertTrue(); - - try { - let fileSize = fileio.statSync(srcpath).size; - // init randomaccessfiles - let threadNums = 4; - let srcfiles = new Array(); - let dstfiles = new Array(); - for (let i = 0; i < threadNums; i++) { - srcfiles[i] = fileio.createRandomAccessFileSync(srcpath, fileSize / threadNums * i, 0o2); - dstfiles[i] = fileio.createRandomAccessFileSync(dstpath, fileSize / threadNums * i, 0o102); - } - // copy in every thread i from multi-thread - let bufs = new Array(threadNums); - let len = length / threadNums; - for(let i = 0; i < threadNums; i++) { - bufs[i] = new ArrayBuffer(len); - srcfiles[i].read(bufs[i]).then(async function(readOut) { - let writeLen = await dstfiles[i].write(readOut.buffer); - expect(writeLen == len).assertTrue(); - dstfiles[i].closeSync(); - srcfiles[i].closeSync(); - if (i == threadNums - 1) { - let size = fileio.statSync(dstpath).size; - expect(size == fileSize).assertTrue(); - fileio.unlinkSync(srcpath); - fileio.unlinkSync(dstpath); - done(); - } - }); - } - } catch (err) { - console.info('fileio_randomaccessfile_multithreaded_replication_000 has failed for ' + err); - expect(null).assertFail(); - } - }); -}) -} +/* + * 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. + */ + +import { + fileio, prepareFile, nextFileName, isIntNum, FILE_CONTENT, + describe, it, expect +} from '../../Common'; + +export default function fileioCreateRandomAccessFile() { +describe('fileio_create_randomAccessFile', function () { + + /** + * @tc.number SUB_STORAGE_FILEIO_CREATE_RANDOMACCESSFILE_SYNC_0000 + * @tc.name fileio_create_randomaccessfile_sync_000 + * @tc.desc Test createRandomAccessFileSync() interface. + * Create RandomAccessFile object to access file based on file path. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_create_randomaccessfile_sync_000', 0, async function () { + let fpath = await nextFileName('fileio_create_randomaccessfile_sync_000'); + expect(prepareFile(fpath, '')).assertTrue(); + + try { + let randomaccessfile = fileio.createRandomAccessFileSync(fpath, 0, 0o2); + expect(isIntNum(randomaccessfile.fd)).assertTrue(); + randomaccessfile.closeSync(); + fileio.unlinkSync(fpath); + } catch(err) { + console.info('fileio_create_randomaccessfile_sync_000 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FILEIO_CREATE_RANDOMACCESSFILE_SYNC_0100 + * @tc.name fileio_create_randomaccessfile_sync_001 + * @tc.desc Test createRandomAccessFileSync() interface. fpointer = 5. + * Create RandomAccessFile object to access file from fpointer location. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_create_randomaccessfile_sync_001', 0, async function () { + let fpath = await nextFileName('fileio_create_randomaccessfile_sync_001'); + + try { + let randomaccessfile = fileio.createRandomAccessFileSync(fpath, 5, 0o102); + expect(isIntNum(randomaccessfile.fd)).assertTrue(); + expect(randomaccessfile.fpointer == 5).assertTrue(); + randomaccessfile.closeSync(); + fileio.unlinkSync(fpath); + } catch(err) { + console.info('fileio_create_randomaccessfile_sync_001 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FILEIO_CREATE_RANDOMACCESSFILE_SYNC_0200 + * @tc.name fileio_create_randomaccessfile_sync_002 + * @tc.desc Test createRandomAccessFileSync() interface. + * Create RandomAccessFile object based on file descriptor to access file. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_create_randomaccessfile_sync_002', 0, async function () { + let fpath = await nextFileName('fileio_create_randomaccessfile_sync_002'); + + try { + let fd = fileio.openSync(fpath, 0o102, 0o666); + let randomaccessfile = fileio.createRandomAccessFileSync(fd, 0); + expect(isIntNum(randomaccessfile.fd)).assertTrue(); + randomaccessfile.closeSync(); + fileio.unlinkSync(fpath); + } catch(err) { + console.info('fileio_create_randomaccessfile_sync_002 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FILEIO_CREATE_RANDOMACCESSFILE_SYNC_0300 + * @tc.name fileio_create_randomaccessfile_sync_003 + * @tc.desc Test createRandomAccessFileSync() interface. fpointer = 1. + * Create RandomAccessFile object based on file descriptor to access file. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_create_randomaccessfile_sync_003', 0, async function () { + let fpath = await nextFileName('fileio_create_randomaccessfile_sync_003'); + + try { + let fd = fileio.openSync(fpath, 0o102, 0o666); + let randomaccessfile = fileio.createRandomAccessFileSync(fd, 1); + expect(isIntNum(randomaccessfile.fd)).assertTrue(); + expect(randomaccessfile.fpointer == 1).assertTrue(); + randomaccessfile.closeSync(); + fileio.unlinkSync(fpath); + } catch(err) { + console.info('fileio_create_randomaccessfile_sync_003 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FILEIO_CREATE_RANDOMACCESSFILE_SYNC_0400 + * @tc.name fileio_create_randomaccessfile_sync_004 + * @tc.desc Test createRandomAccessFileSync() interface. No such file or directory. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_create_randomaccessfile_sync_004', 0, async function () { + let fpath = await nextFileName('fileio_create_randomaccessfile_sync_004'); + + try { + fileio.createRandomAccessFileSync(fpath, 0, 0o2); + expect(false).assertTrue(); + } catch(err) { + console.info('fileio_create_randomaccessfile_sync_004 has failed for ' + err); + expect(err.message == "No such file or directory").assertTrue(); + } + }); + + /** + * @tc.number SUB_STORAGE_FILEIO_CREATE_RANDOMACCESSFILE_SYNC_0500 + * @tc.name fileio_create_randomaccessfile_sync_005 + * @tc.desc Test createRandomAccessFileSync() interface. Invalid fd. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_create_randomaccessfile_sync_005', 0, async function () { + try { + fileio.createRandomAccessFileSync(-1, 0); + expect(false).assertTrue(); + } catch(err) { + console.info('fileio_create_randomaccessfile_sync_005 has failed for ' + err); + expect(err.message == "Invalid fd").assertTrue(); + } + }); + + /** + * @tc.number SUB_STORAGE_FILEIO_CREATE_RANDOMACCESSFILE_SYNC_0600 + * @tc.name fileio_create_randomaccessfile_sync_006 + * @tc.desc Test createRandomAccessFileSync() interface. Invalid fp. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_create_randomaccessfile_sync_006', 0, async function () { + let fpath = await nextFileName('fileio_create_randomaccessfile_sync_006'); + let fd = fileio.openSync(fpath, 0o102, 0o666); + + try { + fileio.createRandomAccessFileSync(fd, '1'); + expect(false).assertTrue(); + } catch(err) { + console.info('fileio_create_randomaccessfile_sync_006 has failed for ' + err); + expect(err.message == "Invalid fp").assertTrue(); + fileio.closeSync(fd); + fileio.unlinkSync(fpath); + } + }); + + /** + * @tc.number SUB_STORAGE_FILEIO_CREATE_RANDOMACCESSFILE_SYNC_0700 + * @tc.name fileio_create_randomaccessfile_sync_007 + * @tc.desc Test createRandomAccessFileSync() interface. Missing Parameter. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_create_randomaccessfile_sync_007', 0, async function () { + let fpath = await nextFileName('fileio_create_randomaccessfile_sync_007'); + let fd = fileio.openSync(fpath, 0o102, 0o666); + + try { + fileio.createRandomAccessFileSync(fd); + expect(false).assertTrue(); + } catch(err) { + console.info('fileio_create_randomaccessfile_sync_007 has failed for ' + err); + expect(err.message == "Number of arguments unmatched").assertTrue(); + fileio.closeSync(fd); + fileio.unlinkSync(fpath); + } + }); + + /** + * @tc.number SUB_STORAGE_FILEIO_CREATE_RANDOMACCESSFILE_SYNC_0800 + * @tc.name fileio_create_randomaccessfile_sync_008 + * @tc.desc Test createRandomAccessFileSync() interface. flags=0o202. + * Create RandomAccessFile object to access file based on file path. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_create_randomaccessfile_sync_008', 0, async function () { + let fpath = await nextFileName('fileio_create_randomaccessfile_sync_008'); + expect(prepareFile(fpath, '')).assertTrue(); + + try { + let randomaccessfile = fileio.createRandomAccessFileSync(fpath, 0, 0o202); + expect(isIntNum(randomaccessfile.fd)).assertTrue(); + randomaccessfile.closeSync(); + fileio.unlinkSync(fpath); + } catch(err) { + console.info('fileio_create_randomaccessfile_sync_008 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FILEIO_CREATE_RANDOMACCESSFILE_SYNC_0900 + * @tc.name fileio_create_randomaccessfile_sync_009 + * @tc.desc Test createRandomAccessFileSync() interface. flags=0o302. File exists. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_create_randomaccessfile_sync_009', 0, async function () { + let fpath = await nextFileName('fileio_create_randomaccessfile_sync_009'); + expect(prepareFile(fpath, '')).assertTrue(); + + try { + fileio.createRandomAccessFileSync(fpath, 0, 0o302); + expect(false).assertTrue(); + } catch(err) { + console.info('fileio_create_randomaccessfile_sync_009 has failed for ' + err); + expect(err.message == "File exists").assertTrue(); + fileio.unlinkSync(fpath); + } + }); + + /** + * @tc.number SUB_STORAGE_FILEIO_CREATE_RANDOMACCESSFILE_SYNC_1000 + * @tc.name fileio_create_randomaccessfile_sync_010 + * @tc.desc Test createRandomAccessFileSync() interface. flags=0o1002. + * If the file exists and the file is opened for write-only or read-write, trim its length to zero. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_create_randomaccessfile_sync_010', 0, async function () { + let fpath = await nextFileName('fileio_create_randomaccessfile_sync_010'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let randomaccessfile = fileio.createRandomAccessFileSync(fpath, 0, 0o1002); + let number = randomaccessfile.readSync(new ArrayBuffer(4096)); + expect(number == 0).assertTrue(); + randomaccessfile.closeSync(); + fileio.unlinkSync(fpath); + } catch(err) { + console.info('fileio_create_randomaccessfile_sync_010 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FILEIO_CREATE_RANDOMACCESSFILE_SYNC_1100 + * @tc.name fileio_create_randomaccessfile_sync_011 + * @tc.desc Test createRandomAccessFileSync() interface. flags=0o2002. + * Open as append, subsequent writes will append to the end of the file. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_create_randomaccessfile_sync_011', 0, async function () { + let fpath = await nextFileName('fileio_create_randomaccessfile_sync_011'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let randomaccessfile = fileio.createRandomAccessFileSync(fpath, 0, 0o2002); + let length = 100; + let num = randomaccessfile.writeSync(new ArrayBuffer(length)); + expect(num == length).assertTrue(); + randomaccessfile.setFilePointerSync(0); + let number = randomaccessfile.readSync(new ArrayBuffer(4096), { position: 0 }); + expect(number == length + FILE_CONTENT.length).assertTrue(); + randomaccessfile.closeSync(); + fileio.unlinkSync(fpath); + } catch(err) { + console.info('fileio_create_randomaccessfile_sync_011 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FILEIO_CREATE_RANDOMACCESSFILE_SYNC_1200 + * @tc.name fileio_create_randomaccessfile_sync_012 + * @tc.desc Test createRandomAccessFileSync() interface. flags=0o200002. Not a directory. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_create_randomaccessfile_sync_012', 0, async function () { + let fpath = await nextFileName('fileio_create_randomaccessfile_sync_012'); + expect(prepareFile(fpath, '')).assertTrue(); + + try { + fileio.createRandomAccessFileSync(fpath, 0, 0o200002); + expect(false).assertTrue(); + } catch(err) { + console.info('fileio_create_randomaccessfile_sync_012 has failed for ' + err); + expect(err.message == "Not a directory").assertTrue(); + fileio.unlinkSync(fpath); + } + }); + + /** + * @tc.number SUB_STORAGE_FILEIO_CREATE_RANDOMACCESSFILE_SYNC_1300 + * @tc.name fileio_create_randomaccessfile_sync_013 + * @tc.desc Test createRandomAccessFileSync() interface. flags=0o400002. + * Create RandomAccessFile object to access file based on file path. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_create_randomaccessfile_sync_013', 0, async function () { + let fpath = await nextFileName('fileio_create_randomaccessfile_sync_013'); + expect(prepareFile(fpath, '')).assertTrue(); + + try { + let randomaccessfile = fileio.createRandomAccessFileSync(fpath, 0, 0o400002); + expect(isIntNum(randomaccessfile.fd)).assertTrue(); + randomaccessfile.closeSync(); + fileio.unlinkSync(fpath); + } catch(err) { + console.info('fileio_create_randomaccessfile_sync_013 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FILEIO_CREATE_RANDOMACCESSFILE_SYNC_1400 + * @tc.name fileio_create_randomaccessfile_sync_014 + * @tc.desc Test createRandomAccessFileSync() interface. flags=0o4010002. + * Create RandomAccessFile object to access file based on file path. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_create_randomaccessfile_sync_014', 0, async function () { + let fpath = await nextFileName('fileio_create_randomaccessfile_sync_014'); + expect(prepareFile(fpath, '')).assertTrue(); + + try { + let randomaccessfile = fileio.createRandomAccessFileSync(fpath, 0, 0o4010002); + expect(isIntNum(randomaccessfile.fd)).assertTrue(); + randomaccessfile.closeSync(); + fileio.unlinkSync(fpath); + } catch(err) { + console.info('fileio_create_randomaccessfile_sync_014 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FILEIO_CREATE_RANDOMACCESSFILE_SYNC_1500 + * @tc.name fileio_create_randomaccessfile_sync_015 + * @tc.desc Test createRandomAccessFileSync() interface. flags=0o200002. Invalid filepath. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_create_randomaccessfile_sync_015', 0, async function () { + let dpath = await nextFileName('fileio_create_randomaccessfile_sync_015') + 'd'; + fileio.mkdirSync(dpath); + + try { + fileio.createRandomAccessFileSync(dpath, 0, 0o200002); + expect(false).assertTrue(); + } catch(err) { + console.info('fileio_create_randomaccessfile_sync_015 has failed for ' + err); + expect(err.message == "Invalid filepath").assertTrue(); + fileio.rmdirSync(dpath); + } + }); + + /** + * @tc.number SUB_STORAGE_FILEIO_CREATE_RANDOMACCESSFILE_SYNC_1600 + * @tc.name fileio_create_randomaccessfile_sync_016 + * @tc.desc Test createRandomAccessFileSync() interface. flags=0o400002. Symbolic link loop. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_create_randomaccessfile_sync_016', 0, async function () { + let fpath = await nextFileName('fileio_create_randomaccessfile_sync_016'); + let ffpath = fpath + 'aaaa'; + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + fileio.symlinkSync(fpath, ffpath); + fileio.createRandomAccessFileSync(ffpath, 0, 0o400002); + expect(false).assertTrue(); + } catch(err) { + console.info('fileio_create_randomaccessfile_sync_016 has failed for ' + err); + expect(err.message == 'Symbolic link loop' || + err.message == 'Too many symbolic links encountered').assertTrue(); + fileio.unlinkSync(fpath); + fileio.unlinkSync(ffpath); + } + }); + + /** + * @tc.number SUB_STORAGE_FILEIO_CREATE_RANDOMACCESSFILE_ASYNC_0000 + * @tc.name fileio_create_randomaccessfile_async_000 + * @tc.desc Test createRandomAccessFile() interface. return in promise mode. + * Create RandomAccessFile object to access file based on file path. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_create_randomaccessfile_async_000', 0, async function (done) { + let fpath = await nextFileName('fileio_create_randomaccessfile_async_000'); + expect(prepareFile(fpath, '')).assertTrue(); + + try { + let randomaccessfile = await fileio.createRandomAccessFile(fpath, 0, 0o2); + expect(isIntNum(randomaccessfile.fd)).assertTrue(); + randomaccessfile.closeSync(); + fileio.unlinkSync(fpath); + done(); + } catch(err) { + console.info('fileio_create_randomaccessfile_async_000 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FILEIO_CREATE_RANDOMACCESSFILE_ASYNC_0100 + * @tc.name fileio_create_randomaccessfile_async_001 + * @tc.desc Test createRandomAccessFile() interface. fpointer = 10. return in callback mode. + * Create RandomAccessFile object to access file based on file path. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_create_randomaccessfile_async_001', 0, async function (done) { + let fpath = await nextFileName('fileio_create_randomaccessfile_async_001'); + + try { + fileio.createRandomAccessFile(fpath, 10, 0o102, function(err, randomaccessfile) { + expect(isIntNum(randomaccessfile.fd)).assertTrue(); + expect(randomaccessfile.fpointer == 10).assertTrue(); + randomaccessfile.closeSync(); + fileio.unlinkSync(fpath); + done(); + }); + } catch(err) { + console.info('fileio_create_randomaccessfile_async_001 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FILEIO_CREATE_RANDOMACCESSFILE_ASYNC_0200 + * @tc.name fileio_create_randomaccessfile_async_002 + * @tc.desc Test createRandomAccessFile() interface. + * Create RandomAccessFile object based on file descriptor to access file. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_create_randomaccessfile_async_002', 0, async function (done) { + let fpath = await nextFileName('fileio_create_randomaccessfile_async_002'); + + try { + let fd = fileio.openSync(fpath, 0o102, 0o666); + fileio.createRandomAccessFile(fd, 0, function(err, randomaccessfile) { + expect(isIntNum(randomaccessfile.fd)).assertTrue(); + randomaccessfile.closeSync(); + fileio.unlinkSync(fpath); + done(); + }); + } catch(err) { + console.info('fileio_create_randomaccessfile_async_002 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FILEIO_CREATE_RANDOMACCESSFILE_ASYNC_0300 + * @tc.name fileio_create_randomaccessfile_async_003 + * @tc.desc Test createRandomAccessFile() interface. fpointer = 1. + * Create RandomAccessFile object based on file descriptor to access file. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_create_randomaccessfile_async_003', 0, async function (done) { + let fpath = await nextFileName('fileio_create_randomaccessfile_async_003'); + + try { + let fd = fileio.openSync(fpath, 0o102, 0o666); + let randomaccessfile = await fileio.createRandomAccessFile(fd, 1); + expect(isIntNum(randomaccessfile.fd)).assertTrue(); + expect(randomaccessfile.fpointer == 1).assertTrue(); + randomaccessfile.closeSync(); + fileio.unlinkSync(fpath); + done(); + } catch(err) { + console.info('fileio_create_randomaccessfile_async_003 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FILEIO_CREATE_RANDOMACCESSFILE_ASYNC_0400 + * @tc.name fileio_create_randomaccessfile_async_004 + * @tc.desc Test createRandomAccessFile() interface. No such file or directory. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_create_randomaccessfile_async_004', 0, async function (done) { + let fpath = await nextFileName('fileio_create_randomaccessfile_async_004'); + + try { + await fileio.createRandomAccessFile(fpath, 0, 0o2); + } catch(err) { + console.info('fileio_create_randomaccessfile_async_004 has failed for ' + err); + expect(err.message == "No such file or directory").assertTrue(); + done(); + } + }); + + /** + * @tc.number SUB_STORAGE_FILEIO_CREATE_RANDOMACCESSFILE_ASYNC_0500 + * @tc.name fileio_create_randomaccessfile_async_005 + * @tc.desc Test createRandomAccessFile() interface. Invalid fd. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_create_randomaccessfile_async_005', 0, async function (done) { + try { + fileio.createRandomAccessFile(-1, 0, function(err) { + }); + } catch(err) { + console.info('fileio_create_randomaccessfile_async_005 has failed for ' + err); + expect(err.message == "Invalid fd").assertTrue(); + done(); + } + }); + + /** + * @tc.number SUB_STORAGE_FILEIO_CREATE_RANDOMACCESSFILE_ASYNC_0600 + * @tc.name fileio_create_randomaccessfile_async_006 + * @tc.desc Test createRandomAccessFile() interface. Invalid fp. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_create_randomaccessfile_async_006', 0, async function (done) { + let fpath = await nextFileName('fileio_create_randomaccessfile_async_006'); + let fd = fileio.openSync(fpath, 0o102, 0o666); + + try { + await fileio.createRandomAccessFile(fd, '1'); + } catch(err) { + console.info('fileio_create_randomaccessfile_async_006 has failed for ' + err); + expect(err.message == "Invalid fp").assertTrue(); + fileio.closeSync(fd); + fileio.unlinkSync(fpath); + done(); + } + }); + + /** + * @tc.number SUB_STORAGE_FILEIO_CREATE_RANDOMACCESSFILE_ASYNC_0700 + * @tc.name fileio_create_randomaccessfile_async_007 + * @tc.desc Test createRandomAccessFile() interface. Missing Parameter. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_create_randomaccessfile_async_007', 0, async function (done) { + let fpath = await nextFileName('fileio_create_randomaccessfile_async_007'); + let fd = fileio.openSync(fpath, 0o102, 0o666); + + try { + await fileio.createRandomAccessFile(fd); + } catch(err) { + console.info('fileio_create_randomaccessfile_async_007 has failed for ' + err); + expect(err.message == "Number of arguments unmatched").assertTrue(); + fileio.closeSync(fd); + fileio.unlinkSync(fpath); + done(); + } + }); + + /** + * @tc.number SUB_STORAGE_FILEIO_CREATE_RANDOMACCESSFILE_ASYNC_0800 + * @tc.name fileio_create_randomaccessfile_async_008 + * @tc.desc Test createRandomAccessFile() interface. flags=0o202. + * Create RandomAccessFile object to access file based on file path. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_create_randomaccessfile_async_008', 0, async function (done) { + let fpath = await nextFileName('fileio_create_randomaccessfile_async_008'); + expect(prepareFile(fpath, '')).assertTrue(); + + try { + fileio.createRandomAccessFile(fpath, 0, 0o202, function(err, randomaccessfile) { + expect(isIntNum(randomaccessfile.fd)).assertTrue(); + randomaccessfile.closeSync(); + fileio.unlinkSync(fpath); + done(); + }); + } catch(err) { + console.info('fileio_create_randomaccessfile_async_008 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FILEIO_CREATE_RANDOMACCESSFILE_SYNC_0900 + * @tc.name fileio_create_randomaccessfile_sync_009 + * @tc.desc Test createRandomAccessFile() interface. flags=0o302. File exists. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_create_randomaccessfile_async_009', 0, async function (done) { + let fpath = await nextFileName('fileio_create_randomaccessfile_async_009'); + expect(prepareFile(fpath, '')).assertTrue(); + + try { + await fileio.createRandomAccessFile(fpath, 0, 0o302); + } catch(err) { + console.info('fileio_create_randomaccessfile_async_009 has failed for ' + err); + expect(err.message == "File exists").assertTrue(); + fileio.unlinkSync(fpath); + done(); + } + }); + + /** + * @tc.number SUB_STORAGE_FILEIO_CREATE_RANDOMACCESSFILE_ASYNC_1000 + * @tc.name fileio_create_randomaccessfile_async_010 + * @tc.desc Test createRandomAccessFile() interface. flags=0o1002. + * If the file exists and the file is opened for write-only or read-write, trim its length to zero. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_create_randomaccessfile_async_010', 0, async function (done) { + let fpath = await nextFileName('fileio_create_randomaccessfile_async_010'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let randomaccessfile = await fileio.createRandomAccessFile(fpath, 0, 0o1002); + let number = randomaccessfile.readSync(new ArrayBuffer(4096)); + expect(number == 0).assertTrue(); + randomaccessfile.closeSync(); + fileio.unlinkSync(fpath); + done(); + } catch(err) { + console.info('fileio_create_randomaccessfile_async_010 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FILEIO_CREATE_RANDOMACCESSFILE_ASYNC_1100 + * @tc.name fileio_create_randomaccessfile_async_011 + * @tc.desc Test createRandomAccessFile() interface. flags=0o2002. + * Open as append, subsequent writes will append to the end of the file. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_create_randomaccessfile_async_011', 0, async function (done) { + let fpath = await nextFileName('fileio_create_randomaccessfile_async_011'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let randomaccessfile = await fileio.createRandomAccessFile(fpath, 0, 0o2002); + let length = 100; + let num = randomaccessfile.writeSync(new ArrayBuffer(length)); + expect(num == length).assertTrue(); + randomaccessfile.setFilePointerSync(0); + let number = randomaccessfile.readSync(new ArrayBuffer(4096), { position: 0 }); + expect(number == length + FILE_CONTENT.length).assertTrue(); + randomaccessfile.closeSync(); + fileio.unlinkSync(fpath); + done(); + } catch(err) { + console.info('fileio_create_randomaccessfile_async_011 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FILEIO_CREATE_RANDOMACCESSFILE_ASYNC_1200 + * @tc.name fileio_create_randomaccessfile_async_012 + * @tc.desc Test createRandomAccessFile() interface. flags=0o200002. Not a directory. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_create_randomaccessfile_async_012', 0, async function (done) { + let fpath = await nextFileName('fileio_create_randomaccessfile_async_012'); + expect(prepareFile(fpath, '')).assertTrue(); + + try { + await fileio.createRandomAccessFile(fpath, 0, 0o200002); + } catch(err) { + console.info('fileio_create_randomaccessfile_async_012 has failed for ' + err); + expect(err.message == "Not a directory").assertTrue(); + fileio.unlinkSync(fpath); + done(); + } + }); + + /** + * @tc.number SUB_STORAGE_FILEIO_CREATE_RANDOMACCESSFILE_ASYNC_1300 + * @tc.name fileio_create_randomaccessfile_async_013 + * @tc.desc Test createRandomAccessFile() interface. flags=0o400002. + * Create RandomAccessFile object to access file based on file path. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_create_randomaccessfile_async_013', 0, async function (done) { + let fpath = await nextFileName('fileio_create_randomaccessfile_async_013'); + expect(prepareFile(fpath, '')).assertTrue(); + + try { + let randomaccessfile = await fileio.createRandomAccessFile(fpath, 0, 0o400002); + expect(isIntNum(randomaccessfile.fd)).assertTrue(); + randomaccessfile.closeSync(); + fileio.unlinkSync(fpath); + done(); + } catch(err) { + console.info('fileio_create_randomaccessfile_async_013 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FILEIO_CREATE_RANDOMACCESSFILE_ASYNC_1400 + * @tc.name fileio_create_randomaccessfile_async_014 + * @tc.desc Test createRandomAccessFile() interface. flags=0o4010002. + * Create RandomAccessFile object to access file based on file path. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_create_randomaccessfile_async_014', 0, async function (done) { + let fpath = await nextFileName('fileio_create_randomaccessfile_async_014'); + expect(prepareFile(fpath, '')).assertTrue(); + + try { + let randomaccessfile = await fileio.createRandomAccessFile(fpath, 0, 0o4010002); + expect(isIntNum(randomaccessfile.fd)).assertTrue(); + randomaccessfile.closeSync(); + fileio.unlinkSync(fpath); + done(); + } catch(err) { + console.info('fileio_create_randomaccessfile_async_014 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FILEIO_CREATE_RANDOMACCESSFILE_ASYNC_1500 + * @tc.name fileio_create_randomaccessfile_async_015 + * @tc.desc Test createRandomAccessFile() interface. flags=0o200002. Invalid filepath. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_create_randomaccessfile_async_015', 0, async function (done) { + let dpath = await nextFileName('fileio_create_randomaccessfile_async_015') + 'd'; + fileio.mkdirSync(dpath); + + try { + await fileio.createRandomAccessFile(dpath, 0, 0o200002); + } catch(err) { + console.info('fileio_create_randomaccessfile_async_015 has failed for ' + err); + expect(err.message == "Invalid filepath").assertTrue(); + fileio.rmdirSync(dpath); + done(); + } + }); + + /** + * @tc.number SUB_STORAGE_FILEIO_CREATE_RANDOMACCESSFILE_ASYNC_1600 + * @tc.name fileio_create_randomaccessfile_async_016 + * @tc.desc Test createRandomAccessFile() interface. flags=0o400002. Symbolic link loop. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_create_randomaccessfile_async_016', 0, async function (done) { + let fpath = await nextFileName('fileio_create_randomaccessfile_async_016'); + let ffpath = fpath + 'aaaa'; + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + fileio.symlinkSync(fpath, ffpath); + await fileio.createRandomAccessFile(ffpath, 0, 0o400002); + } catch(err) { + console.info('fileio_create_randomaccessfile_async_016 has failed for ' + err); + expect(err.message == 'Symbolic link loop' || + err.message == 'Too many symbolic links encountered').assertTrue(); + fileio.unlinkSync(fpath); + fileio.unlinkSync(ffpath); + done(); + } + }); + + /** + * @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_MULTITHREADED_REPLICATION_0000 + * @tc.name fileio_randomaccessfile_multithreaded_replication_000 + * @tc.desc Test createRandomAccessFileSync() interface. Test multi-threaded replication. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_randomaccessfile_multithreaded_replication_000', 0, async function (done) { + let srcpath = await nextFileName('fileio_randomaccessfile_multithreaded_replication_000'); + let dstpath = await nextFileName('fileio_randomaccessfile_multithreaded_replication_000_1'); + let length = 4096; + let buffer = new ArrayBuffer(length); + expect(prepareFile(srcpath, buffer)).assertTrue(); + + try { + let fileSize = fileio.statSync(srcpath).size; + // init randomaccessfiles + let threadNums = 4; + let srcfiles = new Array(); + let dstfiles = new Array(); + for (let i = 0; i < threadNums; i++) { + srcfiles[i] = fileio.createRandomAccessFileSync(srcpath, fileSize / threadNums * i, 0o2); + dstfiles[i] = fileio.createRandomAccessFileSync(dstpath, fileSize / threadNums * i, 0o102); + } + // copy in every thread i from multi-thread + let bufs = new Array(threadNums); + let len = length / threadNums; + for(let i = 0; i < threadNums; i++) { + bufs[i] = new ArrayBuffer(len); + srcfiles[i].read(bufs[i]).then(async function(readOut) { + let writeLen = await dstfiles[i].write(readOut.buffer); + expect(writeLen == len).assertTrue(); + dstfiles[i].closeSync(); + srcfiles[i].closeSync(); + if (i == threadNums - 1) { + let size = fileio.statSync(dstpath).size; + expect(size == fileSize).assertTrue(); + fileio.unlinkSync(srcpath); + fileio.unlinkSync(dstpath); + done(); + } + }); + } + } catch (err) { + console.info('fileio_randomaccessfile_multithreaded_replication_000 has failed for ' + err); + expect(null).assertFail(); + } + }); +}) +} diff --git a/storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/members/createStream.test.js b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/createStream.test.js similarity index 96% rename from storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/members/createStream.test.js rename to storage/storagefileiojstest/src/main/js/test/module_fileio/members/createStream.test.js index ddc33fc953f4328595f122c1cf2e79aba4a1f1cd..a73b4ab4e1da318b55b64d1a47cbdc0301e1a87e 100644 --- a/storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/members/createStream.test.js +++ b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/createStream.test.js @@ -1,148 +1,148 @@ -/* - * Copyright (C) 2023 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 { - fileio, FILE_CONTENT, prepareFile, nextFileName, - describe, it, expect, -} from '../../Common'; - -export default function fileioCreateStream() { -describe('fileio_createStream', function () { - - /** - * @tc.number SUB_DF_FILEIO_STREAM_CREATE_STREAM_ASYNC_0000 - * @tc.name fileio_test_stream_create_stream_async_000 - * @tc.desc Test createStreamAsync() interfaces. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_stream_create_stream_async_000', 0, async function (done) { - let fpath = await nextFileName('fileio_test_stream_create_stream_async_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let ss = await fileio.createStream(fpath, 'r+'); - expect(ss !== null).assertTrue(); - expect(ss.writeSync(FILE_CONTENT) == FILE_CONTENT.length).assertTrue(); - expect(ss.closeSync() == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - done(); - } catch (e) { - console.log('fileio_test_stream_create_stream_async_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_STREAM_CREATE_STREAM_ASYNC_0010 - * @tc.name fileio_test_stream_create_stream_async_001 - * @tc.desc Test createStreamAsync() interfaces. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_stream_create_stream_async_001', 0, async function (done) { - let fpath = await nextFileName('fileio_test_stream_create_stream_async_001'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - fileio.createStream(fpath, 'r+', function (err, stream) { - expect(stream.closeSync() == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - done(); - }); - } catch (e) { - console.log('fileio_test_stream_create_stream_async_001 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_STREAM_CREATE_STREAM_ASYNC_0020 - * @tc.name fileio_test_stream_create_stream_async_002 - * @tc.desc Test createStreamAsync() interfaces. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_stream_create_stream_async_002', 0, async function (done) { - let fpath = await nextFileName('fileio_test_stream_create_stream_async_002'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - fileio.createStream(fpath, 'r+', function (err, stream) { - expect(stream.writeSync(FILE_CONTENT) == FILE_CONTENT.length).assertTrue(); - expect(stream.closeSync() == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - done(); - }); - } catch (e) { - console.log('fileio_test_stream_create_stream_async_002 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_STREAM_CREATE_STREAM_ASYNC_0030 - * @tc.name fileio_test_stream_create_stream_async_003 - * @tc.desc Test createStreamAsync() interfaces. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_stream_create_stream_async_003', 0, async function (done) { - let fpath = await nextFileName('fileio_test_stream_create_stream_async_003'); - - try { - fileio.createStream(fpath, 'r+', function (err) { - done(); - }); - } catch (e) { - expect(!!e).assertTrue(); - done(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_STREAM_CREATE_STREAM_ASYNC_0030 - * @tc.name fileio_test_stream_create_stream_async_003 - * @tc.desc Test createStreamSync() interface. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_stream_create_stream_async_004', 0, async function (done) { - let fpath = await nextFileName('fileio_test_stream_create_stream_async_004'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - fileio.createStream(fpath, 'ohos', function (err) { - fileio.unlinkSync(fpath); - done(); - }); - } catch (e) { - console.info("fileio_test_stream_create_stream_async_004 has failed for " + e); - fileio.unlinkSync(fpath); - done(); - } - }); -}); -} +/* + * Copyright (C) 2021 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 { + fileio, FILE_CONTENT, prepareFile, nextFileName, + describe, it, expect, +} from '../../Common'; + +export default function fileioCreateStream() { +describe('fileio_createStream', function () { + + /** + * @tc.number SUB_DF_FILEIO_STREAM_CREATE_STREAM_ASYNC_0000 + * @tc.name fileio_test_stream_create_stream_async_000 + * @tc.desc Test createStreamAsync() interfaces. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_stream_create_stream_async_000', 0, async function (done) { + let fpath = await nextFileName('fileio_test_stream_create_stream_async_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let ss = await fileio.createStream(fpath, 'r+'); + expect(ss !== null).assertTrue(); + expect(ss.writeSync(FILE_CONTENT) == FILE_CONTENT.length).assertTrue(); + expect(ss.closeSync() == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_test_stream_create_stream_async_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STREAM_CREATE_STREAM_ASYNC_0010 + * @tc.name fileio_test_stream_create_stream_async_001 + * @tc.desc Test createStreamAsync() interfaces. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_stream_create_stream_async_001', 0, async function (done) { + let fpath = await nextFileName('fileio_test_stream_create_stream_async_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + fileio.createStream(fpath, 'r+', function (err, stream) { + expect(stream.closeSync() == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + }); + } catch (e) { + console.log('fileio_test_stream_create_stream_async_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STREAM_CREATE_STREAM_ASYNC_0020 + * @tc.name fileio_test_stream_create_stream_async_002 + * @tc.desc Test createStreamAsync() interfaces. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_stream_create_stream_async_002', 0, async function (done) { + let fpath = await nextFileName('fileio_test_stream_create_stream_async_002'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + fileio.createStream(fpath, 'r+', function (err, stream) { + expect(stream.writeSync(FILE_CONTENT) == FILE_CONTENT.length).assertTrue(); + expect(stream.closeSync() == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + }); + } catch (e) { + console.log('fileio_test_stream_create_stream_async_002 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STREAM_CREATE_STREAM_ASYNC_0030 + * @tc.name fileio_test_stream_create_stream_async_003 + * @tc.desc Test createStreamAsync() interfaces. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_stream_create_stream_async_003', 0, async function (done) { + let fpath = await nextFileName('fileio_test_stream_create_stream_async_003'); + + try { + fileio.createStream(fpath, 'r+', function (err) { + done(); + }); + } catch (e) { + expect(!!e).assertTrue(); + done(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STREAM_CREATE_STREAM_ASYNC_0030 + * @tc.name fileio_test_stream_create_stream_async_003 + * @tc.desc Test createStreamSync() interface. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_stream_create_stream_async_004', 0, async function (done) { + let fpath = await nextFileName('fileio_test_stream_create_stream_async_004'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + fileio.createStream(fpath, 'ohos', function (err) { + fileio.unlinkSync(fpath); + done(); + }); + } catch (e) { + console.info("fileio_test_stream_create_stream_async_004 has failed for " + e); + fileio.unlinkSync(fpath); + done(); + } + }); +}); +} diff --git a/storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/members/fchmod.test.js b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/fchmod.test.js similarity index 96% rename from storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/members/fchmod.test.js rename to storage/storagefileiojstest/src/main/js/test/module_fileio/members/fchmod.test.js index e71d54c737d0a340d5d6ea78c1d34d0e8e6c56fc..3eed5f370e6e6f4a33d578c9f3181d5c67262a8e 100644 --- a/storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/members/fchmod.test.js +++ b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/fchmod.test.js @@ -1,190 +1,190 @@ -/* - * Copyright (C) 2023 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 { - fileio, FILE_CONTENT, prepareFile, nextFileName, - describe, it, expect, -} from '../../Common'; - -export default function fileioFchmod() { -describe('fileio_fchmod', function () { - - /** - * @tc.number SUB_DF_FILEIO_FCHMOD_SYNC_0000 - * @tc.name fileio_test_fchmod_sync_000 - * @tc.desc Test fchmodSync() interfaces, mode = 0o660. Test file permissions modified successfully. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_fchmod_sync_000', 0, async function () { - let fpath = await nextFileName('fileio_test_fchmod_sync_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let fd = fileio.openSync(fpath, 0o2); - fileio.fchmodSync(fd, 0o660); - expect((fileio.statSync(fpath).mode & 0o777) == 0o660).assertTrue(); - fileio.closeSync(fd); - fileio.unlinkSync(fpath); - } catch (e) { - console.info('fileio_test_fchmod_sync_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_FCHMOD_SYNC_0100 - * @tc.name fileio_test_fchmod_sync_001 - * @tc.desc Test fchmodSync() interfaces, invalid fd. Test file modification failed. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_fchmod_sync_001', 0, function () { - try { - fileio.fchmodSync(-1, 0o660); - } catch (e) { - console.info('fileio_test_fchmod_sync_001 has failed for ' + e); - expect(e.message == "Bad file descriptor").assertTrue(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_FCHMOD_ASYNC_0000 - * @tc.name fileio_test_fchmod_async_000 - * @tc.desc Test the fchmodAsync() interface with callback, mode = 1002. Test file permissions modified successfully. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_fchmod_async_000', 0, async function (done) { - let fpath = await nextFileName('fileio_test_fchmod_async_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let fd = fileio.openSync(fpath, 0o1, 0o0200); - fileio.fchmod(fd, 1002, function (err) { - expect((fileio.statSync(fpath).mode & 0o777) == 0o752).assertTrue(); - fileio.closeSync(fd); - fileio.unlinkSync(fpath); - done(); - }); - } catch (e) { - console.info('fileio_test_fchmod_async_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_FCHMOD_ASYNC_0100 - * @tc.name fileio_test_fchmod_async_001 - * @tc.desc Test the fchmodAsync() interface with callback, mode = 1003. Test file permissions modified successfully. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_fchmod_async_001', 0, async function (done) { - let fpath = await nextFileName('fileio_test_fchmod_async_001'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let fd = fileio.openSync(fpath, 0o0, 0o0200); - fileio.fchmod(fd, 1003).then(function (err) { - expect((fileio.statSync(fpath).mode & 0o777) == 0o753).assertTrue(); - fileio.closeSync(fd); - fileio.unlinkSync(fpath); - done(); - }) - } catch (e) { - console.info('fileio_test_fchmod_async_001 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_FCHMOD_ASYNC_0200 - * @tc.name fileio_test_fchmod_async_002 - * @tc.desc Test the fchmodAsync() interface with callback, mode = 0o100. Test file permissions modified successfully. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_fchmod_async_002', 0, async function (done) { - let fpath = await nextFileName('fileio_test_fchmod_async_002'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let fd = fileio.openSync(fpath, 0o1, 0o020); - fileio.fchmod(fd, 0o100, function (err) { - expect((fileio.statSync(fpath).mode & 0o777) == 0o100).assertTrue(); - fileio.closeSync(fd); - fileio.unlinkSync(fpath); - done(); - }); - } catch (e) { - console.info('fileio_test_fchmod_async_002 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_FCHMOD_ASYNC_0300 - * @tc.name fileio_test_fchmod_async_003 - * @tc.desc Test the fchmodAsync() interface with promise, mode = 0o400. Test file permissions modified successfully. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_fchmod_async_003', 0, async function (done) { - let fpath = await nextFileName('fileio_test_fchmod_async_003'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let fd = fileio.openSync(fpath, 0o1, 0o020); - await fileio.fchmod(fd, 0o400); - expect((fileio.statSync(fpath).mode & 0o777) == 0o400).assertTrue(); - fileio.closeSync(fd); - fileio.unlinkSync(fpath); - done(); - } catch (e) { - console.info('fileio_test_fchmod_async_003 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_FCHMOD_ASYNC_0400 - * @tc.name fileio_test_fchmod_async_004 - * @tc.desc Test the fchmodAsync() interface with promise, invalid fd. Test file modification failed. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_fchmod_async_004', 0, async function (done) { - try { - await fileio.fchmod(-1, 0o666); - } catch (e) { - console.info('fileio_test_fchmod_async_004 has failed for ' + e); - expect(e.message == "Bad file descriptor").assertTrue(); - done(); - } - }); -}); -} +/* + * Copyright (C) 2021 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 { + fileio, FILE_CONTENT, prepareFile, nextFileName, + describe, it, expect, +} from '../../Common'; + +export default function fileioFchmod() { +describe('fileio_fchmod', function () { + + /** + * @tc.number SUB_DF_FILEIO_FCHMOD_SYNC_0000 + * @tc.name fileio_test_fchmod_sync_000 + * @tc.desc Test fchmodSync() interfaces, mode = 0o660. Test file permissions modified successfully. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_fchmod_sync_000', 0, async function () { + let fpath = await nextFileName('fileio_test_fchmod_sync_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath, 0o2); + fileio.fchmodSync(fd, 0o660); + expect((fileio.statSync(fpath).mode & 0o777) == 0o660).assertTrue(); + fileio.closeSync(fd); + fileio.unlinkSync(fpath); + } catch (e) { + console.info('fileio_test_fchmod_sync_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_FCHMOD_SYNC_0100 + * @tc.name fileio_test_fchmod_sync_001 + * @tc.desc Test fchmodSync() interfaces, invalid fd. Test file modification failed. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_fchmod_sync_001', 0, function () { + try { + fileio.fchmodSync(-1, 0o660); + } catch (e) { + console.info('fileio_test_fchmod_sync_001 has failed for ' + e); + expect(e.message == "Bad file descriptor").assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_FCHMOD_ASYNC_0000 + * @tc.name fileio_test_fchmod_async_000 + * @tc.desc Test the fchmodAsync() interface with callback, mode = 1002. Test file permissions modified successfully. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_fchmod_async_000', 0, async function (done) { + let fpath = await nextFileName('fileio_test_fchmod_async_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath, 0o1, 0o0200); + fileio.fchmod(fd, 1002, function (err) { + expect((fileio.statSync(fpath).mode & 0o777) == 0o752).assertTrue(); + fileio.closeSync(fd); + fileio.unlinkSync(fpath); + done(); + }); + } catch (e) { + console.info('fileio_test_fchmod_async_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_FCHMOD_ASYNC_0100 + * @tc.name fileio_test_fchmod_async_001 + * @tc.desc Test the fchmodAsync() interface with callback, mode = 1003. Test file permissions modified successfully. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_fchmod_async_001', 0, async function (done) { + let fpath = await nextFileName('fileio_test_fchmod_async_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let fd = fileio.openSync(fpath, 0o0, 0o0200); + fileio.fchmod(fd, 1003).then(function (err) { + expect((fileio.statSync(fpath).mode & 0o777) == 0o753).assertTrue(); + fileio.closeSync(fd); + fileio.unlinkSync(fpath); + done(); + }) + } catch (e) { + console.info('fileio_test_fchmod_async_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_FCHMOD_ASYNC_0200 + * @tc.name fileio_test_fchmod_async_002 + * @tc.desc Test the fchmodAsync() interface with callback, mode = 0o100. Test file permissions modified successfully. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_fchmod_async_002', 0, async function (done) { + let fpath = await nextFileName('fileio_test_fchmod_async_002'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let fd = fileio.openSync(fpath, 0o1, 0o020); + fileio.fchmod(fd, 0o100, function (err) { + expect((fileio.statSync(fpath).mode & 0o777) == 0o100).assertTrue(); + fileio.closeSync(fd); + fileio.unlinkSync(fpath); + done(); + }); + } catch (e) { + console.info('fileio_test_fchmod_async_002 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_FCHMOD_ASYNC_0300 + * @tc.name fileio_test_fchmod_async_003 + * @tc.desc Test the fchmodAsync() interface with promise, mode = 0o400. Test file permissions modified successfully. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_fchmod_async_003', 0, async function (done) { + let fpath = await nextFileName('fileio_test_fchmod_async_003'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let fd = fileio.openSync(fpath, 0o1, 0o020); + await fileio.fchmod(fd, 0o400); + expect((fileio.statSync(fpath).mode & 0o777) == 0o400).assertTrue(); + fileio.closeSync(fd); + fileio.unlinkSync(fpath); + done(); + } catch (e) { + console.info('fileio_test_fchmod_async_003 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_FCHMOD_ASYNC_0400 + * @tc.name fileio_test_fchmod_async_004 + * @tc.desc Test the fchmodAsync() interface with promise, invalid fd. Test file modification failed. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_fchmod_async_004', 0, async function (done) { + try { + await fileio.fchmod(-1, 0o666); + } catch (e) { + console.info('fileio_test_fchmod_async_004 has failed for ' + e); + expect(e.message == "Bad file descriptor").assertTrue(); + done(); + } + }); +}); +} diff --git a/storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/members/fchown.test.js b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/fchown.test.js similarity index 96% rename from storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/members/fchown.test.js rename to storage/storagefileiojstest/src/main/js/test/module_fileio/members/fchown.test.js index 0163bc88034dd5e288fd80829a91874792191f8e..268fd1cf05d7e0c008c4f60a020b56aa59970671 100644 --- a/storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/members/fchown.test.js +++ b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/fchown.test.js @@ -1,218 +1,218 @@ -/* - * Copyright (C) 2023 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 { - fileio, FILE_CONTENT, prepareFile, nextFileName, isIntNum, - describe, it, expect, -} from '../../Common'; - -export default function fileioFchown() { -describe('fileio_fchown', async function () { - - /** - * @tc.number SUB_DF_FILEIO_FCHOWN_ASYNC_0000 - * @tc.name fileio_test_fchown_async_000 - * @tc.desc Test the fchownAsync() interface with callback. The test file was modified successfully. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_fchown_async_000', 0, async function (done) { - let fpath = await nextFileName('fileio_test_fchown_async_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let stat = fileio.statSync(fpath); - expect(isIntNum(stat.uid)).assertTrue(); - let fd = fileio.openSync(fpath, 0o102, 0o666); - fileio.fchmodSync(fd, 0o777); - fileio.fchown(fd, stat.uid, stat.gid, function (err) { - fileio.closeSync(fd); - fileio.unlinkSync(fpath); - done(); - }); - } catch (e) { - console.info('fileio_test_fchown_async_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_FCHOWN_ASYNC_0100 - * @tc.name fileio_test_fchown_async_001 - * @tc.desc Test the fchownAsync() interface with promise. The test file was modified successfully. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_fchown_async_001', 0, async function (done) { - let fpath = await nextFileName('fileio_test_fchown_async_001'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let stat = fileio.statSync(fpath); - expect(isIntNum(stat.uid)).assertTrue(); - let fd = fileio.openSync(fpath, 0o102, 0o666); - fileio.fchmodSync(fd, 0o777); - await fileio.fchown(fd, stat.uid, stat.gid); - fileio.closeSync(fd); - fileio.unlinkSync(fpath); - done(); - } catch (e) { - console.info('fileio_test_fchown_async_001 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_FCHOWN_ASYNC_0200 - * @tc.name fileio_test_fchown_async_002 - * @tc.desc Test the fchownAsync() interface with promise, invalid fd. Test file modification failed. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_fchown_async_002', 0, async function (done) { - let fpath = await nextFileName('fileio_test_fchown_async_002'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let stat = fileio.statSync(fpath); - await fileio.fchown(-1, stat.uid, stat.gid); - } catch (e) { - console.info('fileio_test_fchown_async_002 has failed for ' + e); - expect(e.message == "Bad file descriptor").assertTrue(); - fileio.unlinkSync(fpath); - done(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_FCHOWN_ASYNC_0300 - * @tc.name fileio_test_fchown_async_003 - * @tc.desc Test the fchownAsync() interface with promise, wrong uid, gid. Test file modification failed. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_fchown_async_003', 0, async function (done) { - let fpath = await nextFileName('fileio_test_fchown_async_003'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let fd = fileio.openSync(fpath); - await fileio.fchown(fd, 0, 0); - } catch (e) { - console.info('fileio_test_fchown_async_003 has failed for ' + e); - expect(e.message == "Operation not permitted").assertTrue(); - fileio.unlinkSync(fpath); - done(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_FCHOWN_SYNC_0000 - * @tc.name fileio_test_fchown_sync_000 - * @tc.desc Test fchownSync() interface. The test file was modified successfully. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_fchown_sync_000', 0, async function () { - let fpath = await nextFileName('fileio_test_fchown_sync_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let stat = fileio.statSync(fpath); - expect(isIntNum(stat.uid)).assertTrue(); - let fd = fileio.openSync(fpath, 0o102, 0o666); - fileio.fchmodSync(fd, 0o777); - fileio.fchownSync(fd, stat.uid, stat.gid); - fileio.closeSync(fd); - fileio.unlinkSync(fpath); - } catch (e) { - console.info('fileio_test_fchown_sync_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_FCHOWN_SYNC_0100 - * @tc.name fileio_test_fchown_sync_001 - * @tc.desc Test fchownSync() interface, invalid fd. Test file modification failed. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_fchown_sync_001', 0, async function () { - let fpath = await nextFileName('fileio_test_fchown_sync_001'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let stat = fileio.statSync(fpath); - fileio.fchownSync(-1, stat.uid, stat.gid); - } catch (e) { - console.info('fileio_test_fchown_sync_001 has failed for ' + e); - expect(e.message == "Bad file descriptor").assertTrue(); - fileio.unlinkSync(fpath); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_FCHOWN_SYNC_0200 - * @tc.name fileio_test_fchown_sync_002 - * @tc.desc Test fchownSync() interface, wrong uid, gid. Test file modification failed. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_fchown_sync_002', 0, async function () { - let fpath = await nextFileName('fileio_test_fchown_sync_002'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let fd = fileio.openSync(fpath); - fileio.fchownSync(fd, 0, 0); - } catch (e) { - console.info('fileio_test_fchown_sync_002 has failed for ' + e); - expect(e.message == "Operation not permitted").assertTrue(); - fileio.unlinkSync(fpath); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_FCHOWN_SYNC_0300 - * @tc.name fileio_test_fchown_sync_003 - * @tc.desc Test fchownSync() interface, wrong owner. Test file modification failed. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_fchown_sync_003', 0, async function () { - let fpath = await nextFileName('fileio_test_fchown_sync_003'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let fd = fileio.openSync(fpath); - let stat = fileio.statSync(fpath); - fileio.fchownSync(fd, null, stat.gid); - } catch (e) { - console.info('fileio_test_fchown_sync_003 has failed for ' + e); - expect(e.message == "Invalid owner").assertTrue(); - fileio.unlinkSync(fpath); - } - }); -}); -} +/* + * Copyright (C) 2021 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 { + fileio, FILE_CONTENT, prepareFile, nextFileName, isIntNum, + describe, it, expect, +} from '../../Common'; + +export default function fileioFchown() { +describe('fileio_fchown', async function () { + + /** + * @tc.number SUB_DF_FILEIO_FCHOWN_ASYNC_0000 + * @tc.name fileio_test_fchown_async_000 + * @tc.desc Test the fchownAsync() interface with callback. The test file was modified successfully. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_fchown_async_000', 0, async function (done) { + let fpath = await nextFileName('fileio_test_fchown_async_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let stat = fileio.statSync(fpath); + expect(isIntNum(stat.uid)).assertTrue(); + let fd = fileio.openSync(fpath, 0o102, 0o666); + fileio.fchmodSync(fd, 0o777); + fileio.fchown(fd, stat.uid, stat.gid, function (err) { + fileio.closeSync(fd); + fileio.unlinkSync(fpath); + done(); + }); + } catch (e) { + console.info('fileio_test_fchown_async_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_FCHOWN_ASYNC_0100 + * @tc.name fileio_test_fchown_async_001 + * @tc.desc Test the fchownAsync() interface with promise. The test file was modified successfully. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_fchown_async_001', 0, async function (done) { + let fpath = await nextFileName('fileio_test_fchown_async_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let stat = fileio.statSync(fpath); + expect(isIntNum(stat.uid)).assertTrue(); + let fd = fileio.openSync(fpath, 0o102, 0o666); + fileio.fchmodSync(fd, 0o777); + await fileio.fchown(fd, stat.uid, stat.gid); + fileio.closeSync(fd); + fileio.unlinkSync(fpath); + done(); + } catch (e) { + console.info('fileio_test_fchown_async_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_FCHOWN_ASYNC_0200 + * @tc.name fileio_test_fchown_async_002 + * @tc.desc Test the fchownAsync() interface with promise, invalid fd. Test file modification failed. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_fchown_async_002', 0, async function (done) { + let fpath = await nextFileName('fileio_test_fchown_async_002'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let stat = fileio.statSync(fpath); + await fileio.fchown(-1, stat.uid, stat.gid); + } catch (e) { + console.info('fileio_test_fchown_async_002 has failed for ' + e); + expect(e.message == "Bad file descriptor").assertTrue(); + fileio.unlinkSync(fpath); + done(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_FCHOWN_ASYNC_0300 + * @tc.name fileio_test_fchown_async_003 + * @tc.desc Test the fchownAsync() interface with promise, wrong uid, gid. Test file modification failed. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_fchown_async_003', 0, async function (done) { + let fpath = await nextFileName('fileio_test_fchown_async_003'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let fd = fileio.openSync(fpath); + await fileio.fchown(fd, 0, 0); + } catch (e) { + console.info('fileio_test_fchown_async_003 has failed for ' + e); + expect(e.message == "Operation not permitted").assertTrue(); + fileio.unlinkSync(fpath); + done(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_FCHOWN_SYNC_0000 + * @tc.name fileio_test_fchown_sync_000 + * @tc.desc Test fchownSync() interface. The test file was modified successfully. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_fchown_sync_000', 0, async function () { + let fpath = await nextFileName('fileio_test_fchown_sync_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let stat = fileio.statSync(fpath); + expect(isIntNum(stat.uid)).assertTrue(); + let fd = fileio.openSync(fpath, 0o102, 0o666); + fileio.fchmodSync(fd, 0o777); + fileio.fchownSync(fd, stat.uid, stat.gid); + fileio.closeSync(fd); + fileio.unlinkSync(fpath); + } catch (e) { + console.info('fileio_test_fchown_sync_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_FCHOWN_SYNC_0100 + * @tc.name fileio_test_fchown_sync_001 + * @tc.desc Test fchownSync() interface, invalid fd. Test file modification failed. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_fchown_sync_001', 0, async function () { + let fpath = await nextFileName('fileio_test_fchown_sync_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let stat = fileio.statSync(fpath); + fileio.fchownSync(-1, stat.uid, stat.gid); + } catch (e) { + console.info('fileio_test_fchown_sync_001 has failed for ' + e); + expect(e.message == "Bad file descriptor").assertTrue(); + fileio.unlinkSync(fpath); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_FCHOWN_SYNC_0200 + * @tc.name fileio_test_fchown_sync_002 + * @tc.desc Test fchownSync() interface, wrong uid, gid. Test file modification failed. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_fchown_sync_002', 0, async function () { + let fpath = await nextFileName('fileio_test_fchown_sync_002'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let fd = fileio.openSync(fpath); + fileio.fchownSync(fd, 0, 0); + } catch (e) { + console.info('fileio_test_fchown_sync_002 has failed for ' + e); + expect(e.message == "Operation not permitted").assertTrue(); + fileio.unlinkSync(fpath); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_FCHOWN_SYNC_0300 + * @tc.name fileio_test_fchown_sync_003 + * @tc.desc Test fchownSync() interface, wrong owner. Test file modification failed. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_fchown_sync_003', 0, async function () { + let fpath = await nextFileName('fileio_test_fchown_sync_003'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let fd = fileio.openSync(fpath); + let stat = fileio.statSync(fpath); + fileio.fchownSync(fd, null, stat.gid); + } catch (e) { + console.info('fileio_test_fchown_sync_003 has failed for ' + e); + expect(e.message == "Invalid owner").assertTrue(); + fileio.unlinkSync(fpath); + } + }); +}); +} diff --git a/storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/members/fdatasync.test.js b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/fdatasync.test.js similarity index 95% rename from storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/members/fdatasync.test.js rename to storage/storagefileiojstest/src/main/js/test/module_fileio/members/fdatasync.test.js index 1dbff5e050ad9bda10b46afd59f5cd1acd7e81e3..55b4d61d7882141c0b02e5f1fd1a765dc0bf1fb7 100644 --- a/storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/members/fdatasync.test.js +++ b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/fdatasync.test.js @@ -1,142 +1,142 @@ -/* - * Copyright (C) 2023 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 { - fileio, FILE_CONTENT, prepareFile, nextFileName, - describe, it, expect, -} from '../../Common'; - -export default function fileioFdatasync() { -describe('fileio_fdatasync', async function () { - - /** - * @tc.number SUB_DF_FILEIO_FDATASYNC_ASYNC_0000 - * @tc.name fileio_test_fdatasync_async_000 - * @tc.desc Test fdatasync() interfaces. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_fdatasync_async_000', 0, async function () { - let fpath = await nextFileName('fileio_test_fdatasync_async_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let fd = fileio.openSync(fpath, 0o102, 0o666); - fileio.fdatasync(fd, function (err) { - expect(fileio.closeSync(fd) == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - }); - } catch (e) { - console.log('fileio_test_fdatasync_async_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_FDATASYNC_ASYNC_0010 - * @tc.name fileio_test_fdatasync_async_001 - * @tc.desc Test fdatasync() interfaces. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_fdatasync_async_001', 0, async function () { - let fpath = await nextFileName('fileio_test_fdatasync_async_001'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let fd = fileio.openSync(fpath, 0o102, 0o666); - fileio - .fdatasync(fd) - .then(function (err) { - expect(fileio.closeSync(fd) == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - }) - .catch(function (err) { - expect(null).assertFail(); - }); - } catch (e) { - console.log('fileio_test_fdatasync_async_001 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_FDATASYNC_ASYNC_0020 - * @tc.name fileio_test_fdatasync_async_002 - * @tc.desc Test fdatasync() interfaces. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_fdatasync_async_002', 0, async function (done) { - try { - let fd = -1; - await fileio.fdatasync(fd); - expect(null).assertFail(); - done() - } catch (e) { - console.info('fileio_test_fdatasync_async_002 has failed for ' + e); - done(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_FDATASYNC_SYNC_0000 - * @tc.name fileio_test_fdatasync_sync_000 - * @tc.desc Test fdatasyncSync() interfaces. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_fdatasync_sync_000', 0, async function () { - let fpath = await nextFileName('fileio_test_fdatasync_sync_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let fd = fileio.openSync(fpath, 0o102, 0o666); - expect(fileio.fdatasyncSync(fd) == null).assertTrue(); - expect(fileio.closeSync(fd) == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - } catch (e) { - console.log('fileio_test_fdatasync_sync_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_FDATASYNC_SYNC_0010 - * @tc.name fileio_test_fdatasync_sync_001 - * @tc.desc Test fdatasyncSync() interfaces. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_fdatasync_sync_001', 0, async function () { - try { - fileio.fdatasyncSync(-1); - expect(null).assertFail(); - } catch (e) { - console.log('fileio_test_fdatasync_sync_001 has failed for ' + e); - } - }); -}); -} +/* + * Copyright (C) 2021 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 { + fileio, FILE_CONTENT, prepareFile, nextFileName, + describe, it, expect, +} from '../../Common'; + +export default function fileioFdatasync() { +describe('fileio_fdatasync', async function () { + + /** + * @tc.number SUB_DF_FILEIO_FDATASYNC_ASYNC_0000 + * @tc.name fileio_test_fdatasync_async_000 + * @tc.desc Test fdatasync() interfaces. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_fdatasync_async_000', 0, async function () { + let fpath = await nextFileName('fileio_test_fdatasync_async_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath, 0o102, 0o666); + fileio.fdatasync(fd, function (err) { + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + }); + } catch (e) { + console.log('fileio_test_fdatasync_async_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_FDATASYNC_ASYNC_0010 + * @tc.name fileio_test_fdatasync_async_001 + * @tc.desc Test fdatasync() interfaces. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_fdatasync_async_001', 0, async function () { + let fpath = await nextFileName('fileio_test_fdatasync_async_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath, 0o102, 0o666); + fileio + .fdatasync(fd) + .then(function (err) { + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + }) + .catch(function (err) { + expect(null).assertFail(); + }); + } catch (e) { + console.log('fileio_test_fdatasync_async_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_FDATASYNC_ASYNC_0020 + * @tc.name fileio_test_fdatasync_async_002 + * @tc.desc Test fdatasync() interfaces. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_fdatasync_async_002', 0, async function (done) { + try { + let fd = -1; + await fileio.fdatasync(fd); + expect(null).assertFail(); + done() + } catch (e) { + console.info('fileio_test_fdatasync_async_002 has failed for ' + e); + done(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_FDATASYNC_SYNC_0000 + * @tc.name fileio_test_fdatasync_sync_000 + * @tc.desc Test fdatasyncSync() interfaces. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_fdatasync_sync_000', 0, async function () { + let fpath = await nextFileName('fileio_test_fdatasync_sync_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath, 0o102, 0o666); + expect(fileio.fdatasyncSync(fd) == null).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_test_fdatasync_sync_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_FDATASYNC_SYNC_0010 + * @tc.name fileio_test_fdatasync_sync_001 + * @tc.desc Test fdatasyncSync() interfaces. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_fdatasync_sync_001', 0, async function () { + try { + fileio.fdatasyncSync(-1); + expect(null).assertFail(); + } catch (e) { + console.log('fileio_test_fdatasync_sync_001 has failed for ' + e); + } + }); +}); +} diff --git a/storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/members/fdopenStream.test.js b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/fdopenStream.test.js similarity index 96% rename from storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/members/fdopenStream.test.js rename to storage/storagefileiojstest/src/main/js/test/module_fileio/members/fdopenStream.test.js index 16f5dce8867ed76289242df05bb27080732d3ba5..c123210c4696123130d08d5dec7ad69dccfe2ab4 100644 --- a/storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/members/fdopenStream.test.js +++ b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/fdopenStream.test.js @@ -1,133 +1,133 @@ -/* - * Copyright (C) 2023 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 { - fileio, FILE_CONTENT, prepareFile, nextFileName, isIntNum, - describe, it, expect, -} from '../../Common'; - -export default function fileioFdOpenStream() { -describe('fileio_FdOpenStream', async function () { - - /** - * @tc.number SUB_DF_FILEIO_FDOPENSTREAM_SYNC_0000 - * @tc.name fileio_test_fdopenstream_sync_000 - * @tc.desc Test fdopenStreamSync() interface. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_fdopenstream_sync_000', 0, async function () { - let fpath = await nextFileName('fileio_test_fdopenstream_sync_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let fd = fileio.openSync(fpath, 0o2); - let mode = 'r+'; - let fp = fileio.fdopenStreamSync(fd, mode); - let buf = new ArrayBuffer(4096); - let data = fp.readSync(buf, {}); - expect(data == FILE_CONTENT.length).assertTrue(); - expect(fp !== null).assertTrue(); - expect(fp.closeSync() == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - } catch (e) { - expect(null).assertFail(); - } - }) - - /** - * @tc.number SUB_DF_FILEIO_FDOPENSTREAM_SYNC_0010 - * @tc.name fileio_test_fdopenstream_sync_001 - * @tc.desc Test fdopenStreamSync() interface. - * This interface shall throw an exception when the fpath is not given. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_fdopenstream_sync_001', 0, function () { - try { - let fd = -1; - let mode = 'r+'; - let fp = fileio.fdopenStreamSync(fd, mode); - throw new Error('Bad file descriptor'); - } catch (e) { - console.log('fileio_test_fdopenstream_sync_001 has failed for ' + e); - } - }) - - /** - * @tc.number SUB_DF_FILEIO_FDOPENSTREAM_ASYNC_000 - * @tc.name fileio_test_fdopenstream_async_000 - * @tc.desc Test fdopenStream() interface. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_fdopenstream_async_000', 0, async function (done) { - let fpath = await nextFileName('fileio_test_fdopenstream_async_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let fd = fileio.openSync(fpath, 0o2); - expect(isIntNum(fd)).assertTrue(); - let mode = 'r+'; - let fp = await fileio.fdopenStream(fd, mode); - fp.read(new ArrayBuffer(4096), {}, function (err, data) { - expect(fp !== null).assertTrue(); - fp.closeSync(); - expect(data.bytesRead == FILE_CONTENT.length).assertTrue(); - fileio.unlinkSync(fpath); - done(); - }) - } catch (e) { - console.log('fileio_test_fdopenstream_async_000 has failed for ' + e); - expect(null).assertFail(); - } - }) - - /** - * @tc.number SUB_DF_FILEIO_FDOPENSTREAM_ASYNC_001 - * @tc.name fileio_test_fdopenstream_async_001 - * @tc.desc Test fdopenStream() interface. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_fdopenstream_async_001', 0, async function (done) { - let fpath = await nextFileName('fileio_test_fdopenstream_async_001'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let fd = fileio.openSync(fpath, 0o2); - expect(isIntNum(fd)).assertTrue(); - let mode = 'r+'; - fileio.fdopenStream(fd, mode, function (err, fp) { - expect(fp !== null).assertTrue(); - fp.read(new ArrayBuffer(4096), {}, function (err, data) { - expect(fp !== null).assertTrue(); - fp.closeSync(); - expect(data.bytesRead == FILE_CONTENT.length).assertTrue(); - fileio.unlinkSync(fpath); - done(); - }) - }) - } catch (e) { - console.info('fileio_test_fdopenstream_async_001 has failed for ' + e); - expect(null).assertFail(); - } - }) -})} +/* + * Copyright (C) 2021 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 { + fileio, FILE_CONTENT, prepareFile, nextFileName, isIntNum, + describe, it, expect, +} from '../../Common'; + +export default function fileioFdOpenStream() { +describe('fileio_FdOpenStream', async function () { + + /** + * @tc.number SUB_DF_FILEIO_FDOPENSTREAM_SYNC_0000 + * @tc.name fileio_test_fdopenstream_sync_000 + * @tc.desc Test fdopenStreamSync() interface. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_fdopenstream_sync_000', 0, async function () { + let fpath = await nextFileName('fileio_test_fdopenstream_sync_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let fd = fileio.openSync(fpath, 0o2); + let mode = 'r+'; + let fp = fileio.fdopenStreamSync(fd, mode); + let buf = new ArrayBuffer(4096); + let data = fp.readSync(buf, {}); + expect(data == FILE_CONTENT.length).assertTrue(); + expect(fp !== null).assertTrue(); + expect(fp.closeSync() == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + expect(null).assertFail(); + } + }) + + /** + * @tc.number SUB_DF_FILEIO_FDOPENSTREAM_SYNC_0010 + * @tc.name fileio_test_fdopenstream_sync_001 + * @tc.desc Test fdopenStreamSync() interface. + * This interface shall throw an exception when the fpath is not given. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_fdopenstream_sync_001', 0, function () { + try { + let fd = -1; + let mode = 'r+'; + let fp = fileio.fdopenStreamSync(fd, mode); + throw new Error('Bad file descriptor'); + } catch (e) { + console.log('fileio_test_fdopenstream_sync_001 has failed for ' + e); + } + }) + + /** + * @tc.number SUB_DF_FILEIO_FDOPENSTREAM_ASYNC_000 + * @tc.name fileio_test_fdopenstream_async_000 + * @tc.desc Test fdopenStream() interface. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_fdopenstream_async_000', 0, async function (done) { + let fpath = await nextFileName('fileio_test_fdopenstream_async_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let fd = fileio.openSync(fpath, 0o2); + expect(isIntNum(fd)).assertTrue(); + let mode = 'r+'; + let fp = await fileio.fdopenStream(fd, mode); + fp.read(new ArrayBuffer(4096), {}, function (err, data) { + expect(fp !== null).assertTrue(); + fp.closeSync(); + expect(data.bytesRead == FILE_CONTENT.length).assertTrue(); + fileio.unlinkSync(fpath); + done(); + }) + } catch (e) { + console.log('fileio_test_fdopenstream_async_000 has failed for ' + e); + expect(null).assertFail(); + } + }) + + /** + * @tc.number SUB_DF_FILEIO_FDOPENSTREAM_ASYNC_001 + * @tc.name fileio_test_fdopenstream_async_001 + * @tc.desc Test fdopenStream() interface. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_fdopenstream_async_001', 0, async function (done) { + let fpath = await nextFileName('fileio_test_fdopenstream_async_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let fd = fileio.openSync(fpath, 0o2); + expect(isIntNum(fd)).assertTrue(); + let mode = 'r+'; + fileio.fdopenStream(fd, mode, function (err, fp) { + expect(fp !== null).assertTrue(); + fp.read(new ArrayBuffer(4096), {}, function (err, data) { + expect(fp !== null).assertTrue(); + fp.closeSync(); + expect(data.bytesRead == FILE_CONTENT.length).assertTrue(); + fileio.unlinkSync(fpath); + done(); + }) + }) + } catch (e) { + console.info('fileio_test_fdopenstream_async_001 has failed for ' + e); + expect(null).assertFail(); + } + }) +})} diff --git a/storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/members/fstat.test.js b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/fstat.test.js similarity index 97% rename from storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/members/fstat.test.js rename to storage/storagefileiojstest/src/main/js/test/module_fileio/members/fstat.test.js index aac7dc8e98f22ee4d928a63e1cefe382ab73ef13..ef601a783e20e462c59113c4b5828ba9e541f00c 100644 --- a/storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/members/fstat.test.js +++ b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/fstat.test.js @@ -1,1758 +1,1758 @@ -/* - * Copyright (C) 2023 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 { - fileio, FILE_CONTENT, prepareFile, nextFileName, isIntNum, isBigInt, isBoolean, - describe, it, expect, -} from '../../Common'; - -export default function fileioFstat() { -describe('fileio_fstat', function () { - - /** - * @tc.number SUB_DF_FILEIO_STAT_FSTAT_SYNC_0000 - * @tc.name fileio_stat_fstat_sync_000 - * @tc.desc Test fileio.fstatSync() interfaces. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_stat_fstat_sync_000', 0, async function () { - let fpath = await nextFileName('fileio_stat_fstat_sync_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let fd = fileio.openSync(fpath, 0o2); - expect(isIntNum(fd)).assertTrue(); - let stat = fileio.fstatSync(fd); - expect(stat !== null).assertTrue(); - fileio.closeSync(fd); - fileio.unlinkSync(fpath); - } catch (e) { - console.info('fileio_stat_fstat_sync_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_STAT_FSTAT_SYNC_0010 - * @tc.name fileio_test_stat_fstat_sync_001 - * @tc.desc Test fstatSync() interfaces. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_stat_fstat_sync_001', 0, function () { - try { - let invalidFD = -1; - fileio.fstatSync(invalidFD); - expect(null).assertFail(); - } catch (e) { - console.log('fileio_test_stat_fstat_sync_001 has failed for ' + e); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_FSTAT_DEV_0000 - * @tc.name fileio_fstat_dev_000 - * @tc.desc Test the dev member of class Fstat. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_fstat_dev_000', 0, async function () { - let fpath = await nextFileName('fileio_fstat_dev_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let fd = fileio.openSync(fpath); - let stat = fileio.fstatSync(fd); - expect(isIntNum(stat.dev)).assertTrue(); - expect(fileio.closeSync(fd) == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - } catch (e) { - console.log('fileio_fstat_dev_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_FSTAT_INO_0000 - * @tc.name fileio_fstat_ino_000 - * @tc.desc Test the ino member of class Fstat - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_fstat_ino_000', 0, async function () { - let fpath = await nextFileName('fileio_fstat_ino_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let fd = fileio.openSync(fpath); - let stat = fileio.fstatSync(fd); - expect(isBigInt(stat.ino)).assertTrue(); - expect(fileio.closeSync(fd) == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - } catch (e) { - console.log('fileio_fstat_ino_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_FSTAT_MODE_0000 - * @tc.name fileio_fstat_mode_000 - * @tc.desc Test the mode member of class Fstat - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_fstat_mode_000', 0, async function () { - let fpath = await nextFileName('fileio_fstat_mode_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let fd = fileio.openSync(fpath); - let stat = fileio.fstatSync(fd); - expect(isIntNum(stat.mode)).assertTrue(); - expect(fileio.closeSync(fd) == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - } catch (e) { - console.log('fileio_fstat_mode_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_FSTAT_NLINK_0000 - * @tc.name fileio_fstat_nlink_000 - * @tc.desc Test the nlink member of class Fstat - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_fstat_nlink_000', 0, async function () { - let fpath = await nextFileName('fileio_fstat_nlink_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let fd = fileio.openSync(fpath); - let stat = fileio.fstatSync(fd); - expect(isIntNum(stat.nlink)).assertTrue(); - expect(fileio.closeSync(fd) == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - } catch (e) { - console.log('fileio_fstat_nlink_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_FSTAT_UID_0000 - * @tc.name fileio_fstat_uid_000 - * @tc.desc Test the uid member of class Fstat - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_fstat_uid_000', 0, async function () { - let fpath = await nextFileName('fileio_fstat_uid_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let fd = fileio.openSync(fpath); - let stat = fileio.fstatSync(fd); - expect(isIntNum(stat.uid)).assertTrue(); - expect(fileio.closeSync(fd) == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - } catch (e) { - console.log('fileio_fstat_uid_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_FSTAT_GID_0000 - * @tc.name fileio_fstat_gid_000 - * @tc.desc Test the gid member of class Fstat - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_fstat_gid_000', 0, async function () { - let fpath = await nextFileName('fileio_fstat_gid_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let fd = fileio.openSync(fpath); - let stat = fileio.fstatSync(fd); - expect(isIntNum(stat.gid)).assertTrue(); - expect(fileio.closeSync(fd) == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - } catch (e) { - console.log('fileio_fstat_gid_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_FSTAT_RDEV_0000 - * @tc.name fileio_lstat_rdev_000 - * @tc.desc Test the rdev member of class Fstat - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_fstat_rdev_000', 0, async function () { - let fpath = await nextFileName('fileio_fstat_rdev_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let fd = fileio.openSync(fpath); - let stat = fileio.fstatSync(fd); - expect(isIntNum(stat.rdev)).assertTrue(); - expect(fileio.closeSync(fd) == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - } catch (e) { - console.log('fileio_fstat_rdev_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_FSTAT_SIZE_0000 - * @tc.name fileio_fstat_size_000 - * @tc.desc Test the size member of class Fstat - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_fstat_size_000', 0, async function () { - let fpath = await nextFileName('fileio_fstat_size_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let fd = fileio.openSync(fpath); - let stat = fileio.fstatSync(fd); - expect(isIntNum(stat.size)).assertTrue(); - expect(fileio.closeSync(fd) == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - } catch (e) { - console.log('fileio_fstat_size_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_FSTAT_BLOCKS_0000 - * @tc.name fileio_fstat_blocks_000 - * @tc.desc Test the blocks member of class Fstat - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_fstat_blocks_000', 0, async function () { - let fpath = await nextFileName('fileio_fstat_blocks_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let fd = fileio.openSync(fpath); - let stat = fileio.fstatSync(fd); - expect(isIntNum(stat.blocks)).assertTrue(); - expect(fileio.closeSync(fd) == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - } catch (e) { - console.log('fileio_fstat_blocks_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_FSTAT_ATIME_0000 - * @tc.name fileio_fstat_atime_000 - * @tc.desc Test the atime member of class Fstat - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_fstat_atime_000', 0, async function () { - let fpath = await nextFileName('fileio_fstat_atime_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let fd = fileio.openSync(fpath); - let stat = fileio.fstatSync(fd); - expect(isIntNum(stat.atime)).assertTrue(); - expect(fileio.closeSync(fd) == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - } catch (e) { - console.log('fileio_fstat_atime_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_FSTAT_MTIME_0000 - * @tc.name fileio_fstat_mtime_000 - * @tc.desc Test the mtime member of class Fstat - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_fstat_mtime_000', 0, async function () { - let fpath = await nextFileName('fileio_fstat_mtime_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let fd = fileio.openSync(fpath); - let stat = fileio.fstatSync(fd); - expect(isIntNum(stat.mtime)).assertTrue(); - expect(fileio.closeSync(fd) == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - } catch (e) { - console.log('fileio_fstat_mtime_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_FSTAT_CTIME_0000 - * @tc.name fileio_fstat_ctime_000 - * @tc.desc Test the ctime member of class Fstat - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_fstat_ctime_000', 0, async function () { - let fpath = await nextFileName('fileio_fstat_ctime_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let fd = fileio.openSync(fpath); - let stat = fileio.fstatSync(fd); - expect(isIntNum(stat.ctime)).assertTrue(); - expect(fileio.closeSync(fd) == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - } catch (e) { - console.log('fileio_lstat_ctime_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_FSTAT_IS_BLOCK_DEVICE_0000 - * @tc.name fileio_fstat_is_block_device_000 - * @tc.desc Test the isBlockDevice() method of class Fstat. - * This interface shall return a boolean variable. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_fstat_is_block_device_000', 0, async function () { - let fpath = await nextFileName('fileio_fstat_is_block_device_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let fd = fileio.openSync(fpath); - let stat = fileio.fstatSync(fd); - expect(isBoolean(stat.isBlockDevice())).assertTrue(); - expect(fileio.closeSync(fd) == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - } catch (e) { - console.log('fileio_fstat_is_block_device_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_FSTAT_IS_BLOCK_DEVICE_0010 - * @tc.name fileio_fstat_is_block_device_001 - * @tc.desc Test the isBlockDevice() method of class Fstat. - * This interface shall not treat a normal file as a block special device. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_fstat_is_block_device_001', 0, async function () { - let fpath = await nextFileName('fileio_fstat_is_block_device_001'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let fd = fileio.openSync(fpath); - let stat = fileio.fstatSync(fd); - expect(stat.isBlockDevice() === false).assertTrue(); - expect(fileio.closeSync(fd) == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - } catch (e) { - console.log('fileio_fstat_is_block_device_001 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_FSTAT_IS_BLOCK_DEVICE_0020 - * @tc.name fileio_test_fstat_is_block_device_002 - * @tc.desc Test Fstat.isBlockDevice() interface. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_fstat_is_block_device_002', 0, async function () { - let fpath = await nextFileName('fileio_test_fstat_is_block_device_002'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let fd = fileio.openSync(fpath); - let stat = fileio.fstatSync(fd); - expect(stat.isBlockDevice(-1) === false).assertTrue(); - expect(fileio.closeSync(fd) == null).assertTrue(); - expect(null).assertFail(); - } catch (e) { - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_FSTAT_IS_CHARACTER_DEVICE_0000 - * @tc.name fileio_fstat_is_character_device_000 - * @tc.desc Test Fstat.isCharacterDevice() interface. - * This interface shall return a boolean variable. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_fstat_is_character_device_000', 0, async function () { - let fpath = await nextFileName('fileio_fstat_is_character_device_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let fd = fileio.openSync(fpath); - let stat = fileio.fstatSync(fd); - expect(isBoolean(stat.isCharacterDevice())).assertTrue(); - expect(fileio.closeSync(fd) == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - } catch (e) { - console.log('fileio_fstat_is_character_device_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_FSTAT_IS_CHARACTER_DEVICE_0010 - * @tc.name fileio_fstat_is_character_device_001 - * @tc.desc Test Fstat.isCharacterDevice() interface. - * This interface shall not treat a normal file as a character special device. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_fstat_is_character_device_001', 0, async function () { - let fpath = await nextFileName('fileio_fstat_is_character_device_001'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let fd = fileio.openSync(fpath); - let stat = fileio.fstatSync(fd); - expect(stat.isCharacterDevice() === false).assertTrue(); - expect(fileio.closeSync(fd) == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - } catch (e) { - console.log('fileio_fstat_is_character_device_001 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_FSTAT_IS_CHARACTER_DEVICE_0020 - * @tc.name fileio_test_fstat_is_character_device_002 - * @tc.desc Test Fstat.isCharacterDevice() interface. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_fstat_is_character_device_002', 0, async function () { - let fpath = await nextFileName('fileio_test_fstat_is_character_device_002'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let fd = fileio.openSync(fpath); - let stat = fileio.fstatSync(fd); - expect(stat.isCharacterDevice(-1) === false).assertTrue(); - expect(fileio.closeSync(fd) == null).assertTrue(); - expect(null).assertFail(); - } catch (e) { - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_FSTAT_IS_DIRECTORY_0000 - * @tc.name fileio_fstat_is_directory_000 - * @tc.desc Test Fstat.isDirectory() interface. - * This interface shall return a boolean variable. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_fstat_is_directory_000', 0, async function () { - let fpath = await nextFileName('fileio_fstat_is_directory_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let fd = fileio.openSync(fpath); - let stat = fileio.fstatSync(fd); - expect(isBoolean(stat.isDirectory())).assertTrue(); - expect(fileio.closeSync(fd) == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - } catch (e) { - console.log('fileio_fstat_is_directory_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_FSTAT_IS_DIRECTORY_0010 - * @tc.name fileio_fstat_is_directory_001 - * @tc.desc Test Fstat.isDirectory() interface. - * This interface shall not treat a normal file as a directory. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_fstat_is_directory_001', 0, async function () { - let fpath = await nextFileName('fileio_fstat_is_directory_001'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let fd = fileio.openSync(fpath); - let stat = fileio.fstatSync(fd); - expect(stat.isDirectory() === false).assertTrue(); - expect(fileio.closeSync(fd) == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - } catch (e) { - console.log('fileio_fstat_is_directory_001 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_FSTAT_IS_DIRECTORY_0020 - * @tc.name fileio_fstat_is_directory_002 - * @tc.desc Test Fstat.isDirectory() interface. - * This interface shall treat a directory as a directory. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_fstat_is_directory_002', 0, async function () { - let dpath = await nextFileName('fileio_fstat_is_directory_002') + 'dd'; - - try { - expect(fileio.mkdirSync(dpath) == null).assertTrue(); - let fd = fileio.openSync(dpath); - let stat = fileio.fstatSync(fd); - expect(stat.isDirectory()).assertTrue(); - expect(fileio.closeSync(fd) == null).assertTrue(); - expect(fileio.rmdirSync(dpath) == null).assertTrue(); - } catch (e) { - console.log('fileio_fstat_is_directory_002 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_FSTAT_IS_DIRECTORY_0030 - * @tc.name fileio_test_fstat_is_directory_003 - * @tc.desc Test Fstat.isDirectory() interface. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_fstat_is_directory_003', 0, async function () { - let dpath = await nextFileName('fileio_test_fstat_is_directory_003') + 'd'; - - try { - expect(fileio.mkdirSync(dpath) == null).assertTrue(); - let fd = fileio.openSync(dpath); - let stat = fileio.fstatSync(fd); - expect(stat.isDirectory(-1)).assertTrue(); - expect(fileio.closeSync(fd) == null).assertTrue(); - expect(null).assertFail(); - } catch (e) { - expect(fileio.rmdirSync(dpath) == null).assertTrue(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_FSTAT_IS_FIFO_0000 - * @tc.name fileio_fstat_is_fifo_000 - * @tc.desc Test Fstat.isFIFO() interface. - * This interface shall return a boolean variable. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_fstat_is_fifo_000', 0, async function () { - let fpath = await nextFileName('fileio_fstat_is_fifo_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let fd = fileio.openSync(fpath); - let stat = fileio.fstatSync(fd); - expect(isBoolean(stat.isFIFO())).assertTrue(); - expect(fileio.closeSync(fd) == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - } catch (e) { - console.log('fileio_fstat_is_fifo_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_FSTAT_IS_FIFO_0010 - * @tc.name fileio_fstat_is_fifo_001 - * @tc.desc Test Fstat.isFIFO() interface. - * This interface shall not treat a normal file as a FIFO. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_fstat_is_fifo_001', 0, async function () { - let fpath = await nextFileName('fileio_fstat_is_fifo_001'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let fd = fileio.openSync(fpath); - let stat = fileio.fstatSync(fd); - expect(stat.isFIFO() === false).assertTrue(); - expect(fileio.closeSync(fd) == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - } catch (e) { - console.log('fileio_fstat_is_fifo_001 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_FSTAT_IS_FIFO_0020 - * @tc.name fileio_test_fstat_is_fifo_002 - * @tc.desc Test Fstat.isFIFO() interface. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_fstat_is_fifo_002', 0, async function () { - let fpath = await nextFileName('fileio_test_fstat_is_fifo_002'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let fd = fileio.openSync(fpath); - let stat = fileio.fstatSync(fd); - expect(stat.isFIFO(-1) === false).assertTrue(); - expect(fileio.closeSync(fd) == null).assertTrue(); - expect(null).assertFail(); - } catch (e) { - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_FSTAT_IS_FILE_0000 - * @tc.name fileio_fstat_is_file_000 - * @tc.desc Test Fstat.isFile() interface. - * This interface shall return a boolean variable. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_fstat_is_file_000', 0, async function () { - let fpath = await nextFileName('fileio_fstat_is_file_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let fd = fileio.openSync(fpath); - let stat = fileio.fstatSync(fd); - expect(isBoolean(stat.isFile())).assertTrue(); - expect(fileio.closeSync(fd) == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - } catch (e) { - console.log('fileio_fstat_is_file_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_FSTAT_IS_FILE_0010 - * @tc.name fileio_fstat_is_file_001 - * @tc.desc Test Fstat.isFile() interface. - * This interface shall treat a normal file as a normal file. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_fstat_is_file_001', 0, async function () { - let fpath = await nextFileName('fileio_fstat_is_file_001'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let fd = fileio.openSync(fpath); - let stat = fileio.fstatSync(fd); - expect(stat.isFile()).assertTrue(); - expect(fileio.closeSync(fd) == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - } catch (e) { - console.log('fileio_fstat_is_file_001 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_FSTAT_IS_FILE_0020 - * @tc.name fileio_fstat_is_file_002 - * @tc.desc Test Fstat.isFile() interface. - * This interface shall not treat a directory as a normal file. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_fstat_is_file_002', 0, async function () { - let dpath = await nextFileName('fileio_fstat_is_file_002') + 'aa'; - - try { - expect(fileio.mkdirSync(dpath) == null).assertTrue(); - let fd = fileio.openSync(dpath); - let stat = fileio.fstatSync(fd); - expect(stat.isFile() === false).assertTrue(); - expect(fileio.closeSync(fd) == null).assertTrue(); - expect(fileio.rmdirSync(dpath) == null).assertTrue(); - } catch (e) { - console.log('fileio_fstat_is_file_002 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_FSTAT_IS_FILE_0030 - * @tc.name fileio_test_fstat_is_file_003 - * @tc.desc Test Fstat.isFile() interface. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_fstat_is_file_003', 0, async function () { - let dpath = await nextFileName('fileio_test_fstat_is_file_003') + 'ab'; - - try { - expect(fileio.mkdirSync(dpath) == null).assertTrue(); - let fd = fileio.openSync(dpath); - let stat = fileio.fstatSync(fd); - expect(stat.isFile(-1) === false).assertTrue(); - expect(fileio.closeSync(fd) == null).assertTrue(); - expect(null).assertFail(); - } catch (e) { - expect(fileio.rmdirSync(dpath) == null).assertTrue(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_FSTAT_IS_SOCKET_0000 - * @tc.name fileio_fstat_is_socket_000 - * @tc.desc Test Fstat.isSocket() interface. - * This interface shall return a boolean variable. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_fstat_is_socket_000', 0, async function () { - let fpath = await nextFileName('fileio_fstat_is_socket_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let fd = fileio.openSync(fpath); - let stat = fileio.fstatSync(fd); - expect(isBoolean(stat.isSocket())).assertTrue(); - expect(fileio.closeSync(fd) == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - } catch (e) { - console.log('fileio_fstat_is_socket_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_FSTAT_IS_SOCKET_0010 - * @tc.name fileio_fstat_is_socket_001 - * @tc.desc Test Fstat.isSocket() interface. - * This interface shall not treat a file as a socket. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_fstat_is_socket_001', 0, async function () { - let fpath = await nextFileName('fileio_fstat_is_socket_001'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let fd = fileio.openSync(fpath); - let stat = fileio.fstatSync(fd); - expect(stat.isSocket() === false).assertTrue(); - expect(fileio.closeSync(fd) == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - } catch (e) { - console.log('fileio_fstat_is_socket_001 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_FSTAT_IS_SOCKET_0020 - * @tc.name fileio_test_fstat_is_socket_002 - * @tc.desc Test Fstat.isSocket() interface. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_fstat_is_socket_002', 0, async function () { - let fpath = await nextFileName('fileio_test_fstat_is_socket_002'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let fd = fileio.openSync(fpath); - let stat = fileio.fstatSync(fd); - expect(stat.isSocket(-1) === false).assertTrue(); - expect(fileio.closeSync(fd) == null).assertTrue(); - expect(null).assertFail(); - } catch (e) { - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_FSTAT_IS_SYMBOLIC_LINK_0000 - * @tc.name fileio_fstat_is_symbolic_link_000 - * @tc.desc Test Fstat.isSymbolicLink() interface. - * This interface shall return a boolean variable. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_fstat_is_symbolic_link_000', 0, async function () { - let fpath = await nextFileName('fileio_fstat_is_symbolic_link_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let fd = fileio.openSync(fpath); - let stat = fileio.fstatSync(fd); - expect(isBoolean(stat.isSymbolicLink())).assertTrue(); - expect(fileio.closeSync(fd) == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - } catch (e) { - console.log('fileio_fstat_is_symbolic_link_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_FSTAT_IS_SYMBOLIC_LINK_0010 - * @tc.name fileio_fstat_is_symbolic_link_001 - * @tc.desc Test Fstat.isSymbolicLink() interface. - * This interface shall not treat a normal file as a symbolic link. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_fstat_is_symbolic_link_001', 0, async function () { - let fpath = await nextFileName('fileio_fstat_is_symbolic_link_001'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let fd = fileio.openSync(fpath); - let stat = fileio.fstatSync(fd); - expect(stat.isSymbolicLink() === false).assertTrue(); - expect(fileio.closeSync(fd) == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - } catch (e) { - console.log('fileio_fstat_is_symbolic_link_001 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_FSTAT_IS_SYMBOLIC_LINK_0020 - * @tc.name fileio_test_fstat_is_symbolic_link_002 - * @tc.desc Test Fstat.isSymbolicLink() interface. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_fstat_is_symbolic_link_002', 0, async function () { - let fpath = await nextFileName('fileio_test_fstat_is_symbolic_link_002'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let fd = fileio.openSync(fpath); - let stat = fileio.fstatSync(fd); - expect(stat.isSymbolicLink(-1) === false).assertTrue(); - expect(fileio.closeSync(fd) == null).assertTrue(); - expect(null).assertFail(); - } catch (e) { - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_FSTAT_ASYNC_0000 - * @tc.name fileio_fstat_async_000 - * @tc.desc Test Stat.FstatAsync() interface. - * This interface shall work properly in normal case when providing the promise async model. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_fstat_async_000', 0, async function (done) { - let fpath = await nextFileName('fileio_fstat_async_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let fd = fileio.openSync(fpath); - fileio.fstat(fd).then((stat) => { - expect(stat !== null).assertTrue(); - expect(fileio.closeSync(fd) == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - }); - done(); - } catch (e) { - console.log('fileio_fstat_async_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_FSTAT_ASYNC_0000 - * @tc.name fileio_fstat_async_001 - * @tc.desc Test Stat.FstatAsync() interface. - * This interface shall work properly in normal case when providing the callback async model. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_fstat_async_001', 0, async function (done) { - let fpath = await nextFileName('fileio_fstat_async_001'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let fd = fileio.openSync(fpath); - fileio.fstat(fd, function (error) { - expect(fileio.closeSync(fd) == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - done(); - }); - } catch (e) { - console.log('fileio_fstat_async_001 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_FSTAT_ASYNC_DEV_0000 - * @tc.name fileio_fstat_async_dev_000 - * @tc.desc Test the dev member of class Lstat. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_fstat_async_dev_000', 0, async function (done) { - let fpath = await nextFileName('fileio_fstat_async_dev_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let fd = fileio.openSync(fpath); - let stat = await fileio.fstat(fd); - expect(isIntNum(stat.dev)).assertTrue(); - expect(fileio.closeSync(fd) == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - done(); - } catch (e) { - console.log('fileio_fstat_async_dev_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_FSTAT_ASYNC_INO_0000 - * @tc.name fileio_fstat_async_ino_000 - * @tc.desc Test the ino member of class Lstat. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_fstat_async_ino_000', 0, async function (done) { - let fpath = await nextFileName('fileio_fstat_async_ino_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let fd = fileio.openSync(fpath); - let stat = await fileio.fstat(fd); - expect(isBigInt(stat.ino)).assertTrue(); - expect(fileio.closeSync(fd) == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - done(); - } catch (e) { - console.log('fileio_fstat_async_ino_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_FSTAT_ASYNC_MODE_0000 - * @tc.name fileio_fstat_async_mode_000 - * @tc.desc Test the mode member of class Lstat. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_fstat_async_mode_000', 0, async function (done) { - let fpath = await nextFileName('fileio_fstat_async_mode_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let fd = fileio.openSync(fpath); - let stat = await fileio.fstat(fd); - expect(isIntNum(stat.mode)).assertTrue(); - expect(fileio.closeSync(fd) == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - done(); - } catch (e) { - console.log('fileio_fstat_async_mode_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_FSTAT_ASYNC_NLINK_0000 - * @tc.name fileio_fstat_async_nlink_000 - * @tc.desc Test the nlink member of class Lstat. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_fstat_async_nlink_000', 0, async function (done) { - let fpath = await nextFileName('fileio_fstat_async_nlink_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let fd = fileio.openSync(fpath); - let stat = await fileio.fstat(fd); - expect(isIntNum(stat.nlink)).assertTrue(); - expect(fileio.closeSync(fd) == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - done(); - } catch (e) { - console.log('fileio_fstat_async_nlink_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_FSTAT_ASYNC_UID_0000 - * @tc.name fileio_fstat_async_uid_000 - * @tc.desc Test the uid member of class Lstat. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_fstat_async_uid_000', 0, async function (done) { - let fpath = await nextFileName('fileio_fstat_async_uid_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let fd = fileio.openSync(fpath); - let stat = await fileio.fstat(fd); - expect(isIntNum(stat.uid)).assertTrue(); - expect(fileio.closeSync(fd) == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - done(); - } catch (e) { - console.log('fileio_fstat_async_uid_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_FSTAT_ASYNC_GID_0000 - * @tc.name fileio_fstat_async_gid_000 - * @tc.desc Test the gid member of class Lstat. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_fstat_async_gid_000', 0, async function (done) { - let fpath = await nextFileName('fileio_fstat_async_gid_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let fd = fileio.openSync(fpath); - let stat = await fileio.fstat(fd); - expect(isIntNum(stat.gid)).assertTrue(); - expect(fileio.closeSync(fd) == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - done(); - } catch (e) { - console.log('fileio_fstat_async_gid_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_FSTAT_ASYNC_RDEV_0000 - * @tc.name fileio_fstat_async_rdev_000 - * @tc.desc Test the rdev member of class Lstat. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_fstat_async_rdev_000', 0, async function (done) { - let fpath = await nextFileName('fileio_fstat_async_rdev_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let fd = fileio.openSync(fpath); - let stat = await fileio.fstat(fd); - expect(isIntNum(stat.rdev)).assertTrue(); - expect(fileio.closeSync(fd) == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - done(); - } catch (e) { - console.log('fileio_fstat_async_rdev_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_FSTAT_ASYNC_SIZE_0000 - * @tc.name fileio_fstat_async_size_000 - * @tc.desc Test the size member of class lstat. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_fstat_async_size_000', 0, async function (done) { - let fpath = await nextFileName('fileio_fstat_async_size_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let fd = fileio.openSync(fpath); - let stat = await fileio.fstat(fd); - expect(isIntNum(stat.size)).assertTrue(); - expect(fileio.closeSync(fd) == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - done(); - } catch (e) { - console.log('fileio_fstat_async_size_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_FSTAT_ASYNC_BLOCKS_0000 - * @tc.name fileio_fstat_async_blocks_000 - * @tc.desc Test Fstat.blocks() interface. - * @tc.desc Test the blocks member of class lstat. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_fstat_async_blocks_000', 0, async function (done) { - let fpath = await nextFileName('fileio_fstat_async_blocks_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let fd = fileio.openSync(fpath); - let stat = await fileio.fstat(fd); - expect(isIntNum(stat.blocks)).assertTrue(); - expect(fileio.closeSync(fd) == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - done(); - } catch (e) { - console.log('fileio_fstat_async_blocks_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_FSTAT_ASYNC_ATIME_0000 - * @tc.name fileio_fstat_async_atime_000 - * @tc.desc Test Fstat.atime() interface. - * @tc.desc Test the atime member of class lstat. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_fstat_async_atime_000', 0, async function (done) { - let fpath = await nextFileName('fileio_fstat_async_atime_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let fd = fileio.openSync(fpath); - let stat = await fileio.fstat(fd); - expect(isIntNum(stat.atime)).assertTrue(); - expect(fileio.closeSync(fd) == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - done(); - } catch (e) { - console.log('fileio_fstat_async_atime_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_FSTAT_ASYNC_MTIME_0000 - * @tc.name fileio_fstat_async_mtime_000 - * @tc.desc Test Fstat.mtime() interface. - * @tc.desc Test the mtime member of class lstat. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_fstat_async_mtime_000', 0, async function (done) { - let fpath = await nextFileName('fileio_fstat_async_mtime_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let fd = fileio.openSync(fpath); - let stat = await fileio.fstat(fd); - expect(isIntNum(stat.mtime)).assertTrue(); - expect(fileio.closeSync(fd) == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - done(); - } catch (e) { - console.log('fileio_fstat_async_mtime_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_FSTAT_ASYNC_CTIME_0000 - * @tc.name fileio_fstat_async_ctime_000 - * @tc.desc Test the ctime member of class lstat. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_fstat_async_ctime_000', 0, async function (done) { - let fpath = await nextFileName('fileio_fstat_async_ctime_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let fd = fileio.openSync(fpath); - let stat = await fileio.fstat(fd); - expect(isIntNum(stat.ctime)).assertTrue(); - expect(fileio.closeSync(fd) == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - done(); - } catch (e) { - console.log('fileio_fstat_async_ctime_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_FSTAT_ASYNC_IS_BLOCK_DEVICE_0000 - * @tc.name fileio_fstat_async_is_block_device_000 - * @tc.desc Test the isBlockDevice method of class lstat. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_fstat_async_is_block_device_000', 0, async function (done) { - let fpath = await nextFileName('fileio_fstat_async_is_block_device_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let fd = fileio.openSync(fpath); - let stat = await fileio.fstat(fd); - expect(isBoolean(stat.isBlockDevice())).assertTrue(); - expect(fileio.closeSync(fd) == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - done(); - } catch (e) { - console.log('fileio_fstat_async_is_block_device_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_FSTAT_ASYNC_IS_BLOCK_DEVICE_0010 - * @tc.name fileio_fstat_async_is_block_device_001 - * @tc.desc Test the isBlockDevice method of class lstat. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_fstat_async_is_block_device_001', 0, async function (done) { - let fpath = await nextFileName('fileio_fstat_async_is_block_device_001'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let fd = fileio.openSync(fpath); - let stat = await fileio.fstat(fd); - expect(stat.isBlockDevice() === false).assertTrue(); - expect(fileio.closeSync(fd) == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - done(); - } catch (e) { - console.log('fileio_fstat_async_is_block_device_001 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_FSTAT_ASYNC_IS_CHARACTER_DEVICE_0000 - * @tc.name fileio_fstat_async_is_character_device_000 - * @tc.desc Test the isCharacterDevice method of class lstat. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_fstat_async_is_character_device_000', 0, async function (done) { - let fpath = await nextFileName('fileio_fstat_async_is_character_device_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let fd = fileio.openSync(fpath); - let stat = await fileio.fstat(fd); - expect(isBoolean(stat.isCharacterDevice())).assertTrue(); - expect(fileio.closeSync(fd) == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - done(); - } catch (e) { - console.log('fileio_fstat_async_is_character_device_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_FSTAT_ASYNC_IS_CHARACTER_DEVICE_0010 - * @tc.name fileio_fstat_async_is_character_device_001 - * @tc.desc Test the isCharacterDevice method of class lstat. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_fstat_async_is_character_device_001', 0, async function (done) { - let fpath = await nextFileName('fileio_fstat_async_is_character_device_001'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let fd = fileio.openSync(fpath); - let stat = await fileio.fstat(fd); - expect(stat.isCharacterDevice() === false).assertTrue(); - expect(fileio.closeSync(fd) == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - done(); - } catch (e) { - console.log('fileio_fstat_async_is_character_device_001 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_FSTAT_ASYNC_IS_DIRECTORY_0000 - * @tc.name fileio_fstat_async_is_directory_000 - * @tc.desc Test lstat.isDirectory() interface. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_fstat_async_is_directory_000', 0, async function (done) { - let fpath = await nextFileName('fileio_fstat_async_is_directory_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let fd = fileio.openSync(fpath); - let stat = await fileio.fstat(fd); - expect(isBoolean(stat.isDirectory())).assertTrue(); - expect(fileio.closeSync(fd) == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - done(); - } catch (e) { - console.log('fileio_fstat_async_is_directory_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_FSTAT_ASYNC_IS_DIRECTORY_0010 - * @tc.name fileio_fstat_async_is_directory_001 - * @tc.desc Test lstat.isDirectory() interface. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_fstat_async_is_directory_001', 0, async function (done) { - let fpath = await nextFileName('fileio_fstat_async_is_directory_001'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let fd = fileio.openSync(fpath); - let stat = await fileio.fstat(fd); - expect(stat.isDirectory() === false).assertTrue(); - expect(fileio.closeSync(fd) == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - done(); - } catch (e) { - console.log('fileio_fstat_async_is_directory_001 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_FSTAT_ASYNC_IS_DIRECTORY_0020 - * @tc.name fileio_fstat_async_is_directory_002 - * @tc.desc Test lstat.isDirectory() interface. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_fstat_async_is_directory_002', 0, async function (done) { - let dpath = await nextFileName('fileio_fstat_async_is_directory_002') + 'da'; - - try { - expect(fileio.mkdirSync(dpath) == null).assertTrue(); - let fd = fileio.openSync(dpath); - let stat = await fileio.fstat(fd); - expect(stat.isDirectory()).assertTrue(); - expect(fileio.closeSync(fd) == null).assertTrue(); - expect(fileio.rmdirSync(dpath) == null).assertTrue(); - done(); - } catch (e) { - console.log('fileio_fstat_async_is_directory_002 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_FSTAT_ASYNC_IS_FIFO_0000 - * @tc.name fileio_fstat_async_is_fifo_000 - * @tc.desc Test lstat.isFIFO() interface. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_fstat_async_is_fifo_000', 0, async function (done) { - let fpath = await nextFileName('fileio_fstat_async_is_fifo_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let fd = fileio.openSync(fpath); - let stat = await fileio.fstat(fd); - expect(isBoolean(stat.isFIFO())).assertTrue(); - expect(fileio.closeSync(fd) == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - done(); - } catch (e) { - console.log('fileio_fstat_async_is_fifo_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_FSTAT_ASYNC_IS_FIFO_0010 - * @tc.name fileio_fstat_async_is_fifo_001 - * @tc.desc Test lstat.isFIFO() interface. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_fstat_async_is_fifo_001', 0, async function (done) { - let fpath = await nextFileName('fileio_fstat_async_is_fifo_001'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let fd = fileio.openSync(fpath); - let stat = await fileio.fstat(fd); - expect(stat.isFIFO() === false).assertTrue(); - expect(fileio.closeSync(fd) == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - done(); - } catch (e) { - console.log('fileio_fstat_async_is_fifo_001 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_FSTAT_ASYNC_IS_FILE_0000 - * @tc.name fileio_fstat_async_is_file_000 - * @tc.desc Test lstat.isFile() interface. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_fstat_async_is_file_000', 0, async function (done) { - let fpath = await nextFileName('fileio_fstat_async_is_file_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let fd = fileio.openSync(fpath); - let stat = await fileio.fstat(fd); - expect(isBoolean(stat.isFile())).assertTrue(); - expect(fileio.closeSync(fd) == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - done(); - } catch (e) { - console.log('fileio_fstat_async_is_file_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_FSTAT_ASYNC_IS_FILE_0010 - * @tc.name fileio_fstat_async_is_file_001 - * @tc.desc Test lstat.isFile() interface. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_fstat_async_is_file_001', 0, async function (done) { - let fpath = await nextFileName('fileio_fstat_async_is_file_001'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let fd = fileio.openSync(fpath); - let stat = await fileio.fstat(fd); - expect(stat.isFile()).assertTrue(); - expect(fileio.closeSync(fd) == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - done(); - } catch (e) { - console.log('fileio_fstat_async_is_file_001 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_FSTAT_ASYNC_IS_FILE_0020 - * @tc.name fileio_fstat_async_is_file_002 - * @tc.desc Test lstat.isFile() interface. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_fstat_async_is_file_002', 0, async function (done) { - let dpath = await nextFileName('fileio_fstat_async_is_file_002'); - - try { - expect(fileio.mkdirSync(dpath) == null).assertTrue(); - let fd = fileio.openSync(dpath); - let stat = await fileio.fstat(fd); - expect(stat.isFile() === false).assertTrue(); - expect(fileio.closeSync(fd) == null).assertTrue(); - expect(fileio.rmdirSync(dpath) == null).assertTrue(); - done(); - } catch (e) { - console.log('fileio_fstat_async_is_file_002 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_FSTAT_ASYNC_IS_SOCKET_0000 - * @tc.name fileio_fstat_async_is_socket_000 - * @tc.desc Test lstat.isSocket() interface. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_fstat_async_is_socket_000', 0, async function (done) { - let fpath = await nextFileName('fileio_fstat_async_is_socket_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let fd = fileio.openSync(fpath); - let stat = await fileio.fstat(fd); - expect(isBoolean(stat.isSocket())).assertTrue(); - expect(fileio.closeSync(fd) == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - done(); - } catch (e) { - console.log('fileio_fstat_async_is_socket_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_FSTAT_ASYNC_IS_SOCKET_0010 - * @tc.name fileio_fstat_async_is_socket_001 - * @tc.desc Test lstat.isSocket() interface. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_fstat_async_is_socket_001', 0, async function (done) { - let fpath = await nextFileName('fileio_fstat_async_is_socket_001'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let fd = fileio.openSync(fpath); - let stat = await fileio.fstat(fd); - expect(stat.isSocket() === false).assertTrue(); - expect(fileio.closeSync(fd) == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - done(); - } catch (e) { - console.log('fileio_fstat_async_is_socket_001 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_FSTAT_ASYNC_IS_SYMBOLIC_LINK_0000 - * @tc.name fileio_fstat_async_is_symbolic_link_000 - * @tc.desc Test fstat.isSymbolicLink() interface. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_fstat_async_is_symbolic_link_000', 0, async function (done) { - let fpath = await nextFileName('fileio_fstat_async_is_symbolic_link_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let fd = fileio.openSync(fpath); - let stat = await fileio.fstat(fd); - expect(isBoolean(stat.isSymbolicLink())).assertTrue(); - expect(fileio.closeSync(fd) == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - done(); - } catch (e) { - console.log('fileio_fstat_async_is_symbolic_link_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_FSTAT_ASYNC_IS_SYMBOLIC_LINK_0010 - * @tc.name fileio_fstat_async_is_symbolic_link_001 - * @tc.desc Test lstat.isSymbolicLink() interface. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_fstat_async_is_symbolic_link_001', 0, async function (done) { - let fpath = await nextFileName('fileio_fstat_async_is_symbolic_link_001'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let fd = fileio.openSync(fpath); - let stat = await fileio.fstat(fd); - expect(stat.isSymbolicLink() === false).assertTrue(); - expect(fileio.closeSync(fd) == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - done(); - } catch (e) { - console.log('fileio_fstat_async_is_symbolic_link_001 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_APPEND_FILE_SYNC_0010 - * @tc.name fileio_test_append_file_sync_000 - * @tc.desc Test lstat.fstatSync() interface. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_append_file_sync_000', 0, async function (done) { - let fpath = await nextFileName('fileio_test_append_file_sync_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let fd = fileio.openSync(fpath, 0o2002); - let stat = fileio.fstatSync(fd); - expect(isIntNum(stat.size)).assertTrue(); - expect(isIntNum(fd)).assertTrue(); - expect(fileio.writeSync(fd, FILE_CONTENT) == FILE_CONTENT.length).assertTrue(); - expect(fileio.closeSync(fd) == null).assertTrue(); - - let fd2 = fileio.openSync(fpath, 0o2002); - stat = fileio.fstatSync(fd2); - expect(stat.size == FILE_CONTENT.length * 2).assertTrue(); - expect(fileio.closeSync(fd2) == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - } catch (e) { - console.log('fileio_test_append_file_sync_000 has failed for ' + e); - expect(null).assertFail(); - } - done(); - }); - -});} +/* + * Copyright (C) 2021 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 { + fileio, FILE_CONTENT, prepareFile, nextFileName, isIntNum, isBigInt, isBoolean, + describe, it, expect, +} from '../../Common'; + +export default function fileioFstat() { +describe('fileio_fstat', function () { + + /** + * @tc.number SUB_DF_FILEIO_STAT_FSTAT_SYNC_0000 + * @tc.name fileio_stat_fstat_sync_000 + * @tc.desc Test fileio.fstatSync() interfaces. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_stat_fstat_sync_000', 0, async function () { + let fpath = await nextFileName('fileio_stat_fstat_sync_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath, 0o2); + expect(isIntNum(fd)).assertTrue(); + let stat = fileio.fstatSync(fd); + expect(stat !== null).assertTrue(); + fileio.closeSync(fd); + fileio.unlinkSync(fpath); + } catch (e) { + console.info('fileio_stat_fstat_sync_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STAT_FSTAT_SYNC_0010 + * @tc.name fileio_test_stat_fstat_sync_001 + * @tc.desc Test fstatSync() interfaces. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_stat_fstat_sync_001', 0, function () { + try { + let invalidFD = -1; + fileio.fstatSync(invalidFD); + expect(null).assertFail(); + } catch (e) { + console.log('fileio_test_stat_fstat_sync_001 has failed for ' + e); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_FSTAT_DEV_0000 + * @tc.name fileio_fstat_dev_000 + * @tc.desc Test the dev member of class Fstat. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_fstat_dev_000', 0, async function () { + let fpath = await nextFileName('fileio_fstat_dev_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath); + let stat = fileio.fstatSync(fd); + expect(isIntNum(stat.dev)).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_fstat_dev_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_FSTAT_INO_0000 + * @tc.name fileio_fstat_ino_000 + * @tc.desc Test the ino member of class Fstat + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_fstat_ino_000', 0, async function () { + let fpath = await nextFileName('fileio_fstat_ino_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath); + let stat = fileio.fstatSync(fd); + expect(isBigInt(stat.ino)).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_fstat_ino_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_FSTAT_MODE_0000 + * @tc.name fileio_fstat_mode_000 + * @tc.desc Test the mode member of class Fstat + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_fstat_mode_000', 0, async function () { + let fpath = await nextFileName('fileio_fstat_mode_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath); + let stat = fileio.fstatSync(fd); + expect(isIntNum(stat.mode)).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_fstat_mode_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_FSTAT_NLINK_0000 + * @tc.name fileio_fstat_nlink_000 + * @tc.desc Test the nlink member of class Fstat + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_fstat_nlink_000', 0, async function () { + let fpath = await nextFileName('fileio_fstat_nlink_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath); + let stat = fileio.fstatSync(fd); + expect(isIntNum(stat.nlink)).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_fstat_nlink_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_FSTAT_UID_0000 + * @tc.name fileio_fstat_uid_000 + * @tc.desc Test the uid member of class Fstat + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_fstat_uid_000', 0, async function () { + let fpath = await nextFileName('fileio_fstat_uid_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath); + let stat = fileio.fstatSync(fd); + expect(isIntNum(stat.uid)).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_fstat_uid_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_FSTAT_GID_0000 + * @tc.name fileio_fstat_gid_000 + * @tc.desc Test the gid member of class Fstat + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_fstat_gid_000', 0, async function () { + let fpath = await nextFileName('fileio_fstat_gid_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath); + let stat = fileio.fstatSync(fd); + expect(isIntNum(stat.gid)).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_fstat_gid_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_FSTAT_RDEV_0000 + * @tc.name fileio_lstat_rdev_000 + * @tc.desc Test the rdev member of class Fstat + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_fstat_rdev_000', 0, async function () { + let fpath = await nextFileName('fileio_fstat_rdev_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath); + let stat = fileio.fstatSync(fd); + expect(isIntNum(stat.rdev)).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_fstat_rdev_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_FSTAT_SIZE_0000 + * @tc.name fileio_fstat_size_000 + * @tc.desc Test the size member of class Fstat + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_fstat_size_000', 0, async function () { + let fpath = await nextFileName('fileio_fstat_size_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath); + let stat = fileio.fstatSync(fd); + expect(isIntNum(stat.size)).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_fstat_size_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_FSTAT_BLOCKS_0000 + * @tc.name fileio_fstat_blocks_000 + * @tc.desc Test the blocks member of class Fstat + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_fstat_blocks_000', 0, async function () { + let fpath = await nextFileName('fileio_fstat_blocks_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath); + let stat = fileio.fstatSync(fd); + expect(isIntNum(stat.blocks)).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_fstat_blocks_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_FSTAT_ATIME_0000 + * @tc.name fileio_fstat_atime_000 + * @tc.desc Test the atime member of class Fstat + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_fstat_atime_000', 0, async function () { + let fpath = await nextFileName('fileio_fstat_atime_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath); + let stat = fileio.fstatSync(fd); + expect(isIntNum(stat.atime)).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_fstat_atime_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_FSTAT_MTIME_0000 + * @tc.name fileio_fstat_mtime_000 + * @tc.desc Test the mtime member of class Fstat + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_fstat_mtime_000', 0, async function () { + let fpath = await nextFileName('fileio_fstat_mtime_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath); + let stat = fileio.fstatSync(fd); + expect(isIntNum(stat.mtime)).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_fstat_mtime_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_FSTAT_CTIME_0000 + * @tc.name fileio_fstat_ctime_000 + * @tc.desc Test the ctime member of class Fstat + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_fstat_ctime_000', 0, async function () { + let fpath = await nextFileName('fileio_fstat_ctime_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath); + let stat = fileio.fstatSync(fd); + expect(isIntNum(stat.ctime)).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_lstat_ctime_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_FSTAT_IS_BLOCK_DEVICE_0000 + * @tc.name fileio_fstat_is_block_device_000 + * @tc.desc Test the isBlockDevice() method of class Fstat. + * This interface shall return a boolean variable. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_fstat_is_block_device_000', 0, async function () { + let fpath = await nextFileName('fileio_fstat_is_block_device_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath); + let stat = fileio.fstatSync(fd); + expect(isBoolean(stat.isBlockDevice())).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_fstat_is_block_device_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_FSTAT_IS_BLOCK_DEVICE_0010 + * @tc.name fileio_fstat_is_block_device_001 + * @tc.desc Test the isBlockDevice() method of class Fstat. + * This interface shall not treat a normal file as a block special device. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_fstat_is_block_device_001', 0, async function () { + let fpath = await nextFileName('fileio_fstat_is_block_device_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath); + let stat = fileio.fstatSync(fd); + expect(stat.isBlockDevice() === false).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_fstat_is_block_device_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_FSTAT_IS_BLOCK_DEVICE_0020 + * @tc.name fileio_test_fstat_is_block_device_002 + * @tc.desc Test Fstat.isBlockDevice() interface. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_fstat_is_block_device_002', 0, async function () { + let fpath = await nextFileName('fileio_test_fstat_is_block_device_002'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath); + let stat = fileio.fstatSync(fd); + expect(stat.isBlockDevice(-1) === false).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(null).assertFail(); + } catch (e) { + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_FSTAT_IS_CHARACTER_DEVICE_0000 + * @tc.name fileio_fstat_is_character_device_000 + * @tc.desc Test Fstat.isCharacterDevice() interface. + * This interface shall return a boolean variable. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_fstat_is_character_device_000', 0, async function () { + let fpath = await nextFileName('fileio_fstat_is_character_device_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let fd = fileio.openSync(fpath); + let stat = fileio.fstatSync(fd); + expect(isBoolean(stat.isCharacterDevice())).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_fstat_is_character_device_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_FSTAT_IS_CHARACTER_DEVICE_0010 + * @tc.name fileio_fstat_is_character_device_001 + * @tc.desc Test Fstat.isCharacterDevice() interface. + * This interface shall not treat a normal file as a character special device. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_fstat_is_character_device_001', 0, async function () { + let fpath = await nextFileName('fileio_fstat_is_character_device_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath); + let stat = fileio.fstatSync(fd); + expect(stat.isCharacterDevice() === false).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_fstat_is_character_device_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_FSTAT_IS_CHARACTER_DEVICE_0020 + * @tc.name fileio_test_fstat_is_character_device_002 + * @tc.desc Test Fstat.isCharacterDevice() interface. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_fstat_is_character_device_002', 0, async function () { + let fpath = await nextFileName('fileio_test_fstat_is_character_device_002'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath); + let stat = fileio.fstatSync(fd); + expect(stat.isCharacterDevice(-1) === false).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(null).assertFail(); + } catch (e) { + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_FSTAT_IS_DIRECTORY_0000 + * @tc.name fileio_fstat_is_directory_000 + * @tc.desc Test Fstat.isDirectory() interface. + * This interface shall return a boolean variable. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_fstat_is_directory_000', 0, async function () { + let fpath = await nextFileName('fileio_fstat_is_directory_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath); + let stat = fileio.fstatSync(fd); + expect(isBoolean(stat.isDirectory())).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_fstat_is_directory_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_FSTAT_IS_DIRECTORY_0010 + * @tc.name fileio_fstat_is_directory_001 + * @tc.desc Test Fstat.isDirectory() interface. + * This interface shall not treat a normal file as a directory. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_fstat_is_directory_001', 0, async function () { + let fpath = await nextFileName('fileio_fstat_is_directory_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath); + let stat = fileio.fstatSync(fd); + expect(stat.isDirectory() === false).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_fstat_is_directory_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_FSTAT_IS_DIRECTORY_0020 + * @tc.name fileio_fstat_is_directory_002 + * @tc.desc Test Fstat.isDirectory() interface. + * This interface shall treat a directory as a directory. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_fstat_is_directory_002', 0, async function () { + let dpath = await nextFileName('fileio_fstat_is_directory_002') + 'dd'; + + try { + expect(fileio.mkdirSync(dpath) == null).assertTrue(); + let fd = fileio.openSync(dpath); + let stat = fileio.fstatSync(fd); + expect(stat.isDirectory()).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.rmdirSync(dpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_fstat_is_directory_002 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_FSTAT_IS_DIRECTORY_0030 + * @tc.name fileio_test_fstat_is_directory_003 + * @tc.desc Test Fstat.isDirectory() interface. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_fstat_is_directory_003', 0, async function () { + let dpath = await nextFileName('fileio_test_fstat_is_directory_003') + 'd'; + + try { + expect(fileio.mkdirSync(dpath) == null).assertTrue(); + let fd = fileio.openSync(dpath); + let stat = fileio.fstatSync(fd); + expect(stat.isDirectory(-1)).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(null).assertFail(); + } catch (e) { + expect(fileio.rmdirSync(dpath) == null).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_FSTAT_IS_FIFO_0000 + * @tc.name fileio_fstat_is_fifo_000 + * @tc.desc Test Fstat.isFIFO() interface. + * This interface shall return a boolean variable. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_fstat_is_fifo_000', 0, async function () { + let fpath = await nextFileName('fileio_fstat_is_fifo_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath); + let stat = fileio.fstatSync(fd); + expect(isBoolean(stat.isFIFO())).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_fstat_is_fifo_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_FSTAT_IS_FIFO_0010 + * @tc.name fileio_fstat_is_fifo_001 + * @tc.desc Test Fstat.isFIFO() interface. + * This interface shall not treat a normal file as a FIFO. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_fstat_is_fifo_001', 0, async function () { + let fpath = await nextFileName('fileio_fstat_is_fifo_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath); + let stat = fileio.fstatSync(fd); + expect(stat.isFIFO() === false).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_fstat_is_fifo_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_FSTAT_IS_FIFO_0020 + * @tc.name fileio_test_fstat_is_fifo_002 + * @tc.desc Test Fstat.isFIFO() interface. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_fstat_is_fifo_002', 0, async function () { + let fpath = await nextFileName('fileio_test_fstat_is_fifo_002'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath); + let stat = fileio.fstatSync(fd); + expect(stat.isFIFO(-1) === false).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(null).assertFail(); + } catch (e) { + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_FSTAT_IS_FILE_0000 + * @tc.name fileio_fstat_is_file_000 + * @tc.desc Test Fstat.isFile() interface. + * This interface shall return a boolean variable. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_fstat_is_file_000', 0, async function () { + let fpath = await nextFileName('fileio_fstat_is_file_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath); + let stat = fileio.fstatSync(fd); + expect(isBoolean(stat.isFile())).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_fstat_is_file_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_FSTAT_IS_FILE_0010 + * @tc.name fileio_fstat_is_file_001 + * @tc.desc Test Fstat.isFile() interface. + * This interface shall treat a normal file as a normal file. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_fstat_is_file_001', 0, async function () { + let fpath = await nextFileName('fileio_fstat_is_file_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath); + let stat = fileio.fstatSync(fd); + expect(stat.isFile()).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_fstat_is_file_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_FSTAT_IS_FILE_0020 + * @tc.name fileio_fstat_is_file_002 + * @tc.desc Test Fstat.isFile() interface. + * This interface shall not treat a directory as a normal file. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_fstat_is_file_002', 0, async function () { + let dpath = await nextFileName('fileio_fstat_is_file_002') + 'aa'; + + try { + expect(fileio.mkdirSync(dpath) == null).assertTrue(); + let fd = fileio.openSync(dpath); + let stat = fileio.fstatSync(fd); + expect(stat.isFile() === false).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.rmdirSync(dpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_fstat_is_file_002 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_FSTAT_IS_FILE_0030 + * @tc.name fileio_test_fstat_is_file_003 + * @tc.desc Test Fstat.isFile() interface. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_fstat_is_file_003', 0, async function () { + let dpath = await nextFileName('fileio_test_fstat_is_file_003') + 'ab'; + + try { + expect(fileio.mkdirSync(dpath) == null).assertTrue(); + let fd = fileio.openSync(dpath); + let stat = fileio.fstatSync(fd); + expect(stat.isFile(-1) === false).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(null).assertFail(); + } catch (e) { + expect(fileio.rmdirSync(dpath) == null).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_FSTAT_IS_SOCKET_0000 + * @tc.name fileio_fstat_is_socket_000 + * @tc.desc Test Fstat.isSocket() interface. + * This interface shall return a boolean variable. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_fstat_is_socket_000', 0, async function () { + let fpath = await nextFileName('fileio_fstat_is_socket_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath); + let stat = fileio.fstatSync(fd); + expect(isBoolean(stat.isSocket())).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_fstat_is_socket_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_FSTAT_IS_SOCKET_0010 + * @tc.name fileio_fstat_is_socket_001 + * @tc.desc Test Fstat.isSocket() interface. + * This interface shall not treat a file as a socket. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_fstat_is_socket_001', 0, async function () { + let fpath = await nextFileName('fileio_fstat_is_socket_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath); + let stat = fileio.fstatSync(fd); + expect(stat.isSocket() === false).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_fstat_is_socket_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_FSTAT_IS_SOCKET_0020 + * @tc.name fileio_test_fstat_is_socket_002 + * @tc.desc Test Fstat.isSocket() interface. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_fstat_is_socket_002', 0, async function () { + let fpath = await nextFileName('fileio_test_fstat_is_socket_002'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let fd = fileio.openSync(fpath); + let stat = fileio.fstatSync(fd); + expect(stat.isSocket(-1) === false).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(null).assertFail(); + } catch (e) { + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_FSTAT_IS_SYMBOLIC_LINK_0000 + * @tc.name fileio_fstat_is_symbolic_link_000 + * @tc.desc Test Fstat.isSymbolicLink() interface. + * This interface shall return a boolean variable. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_fstat_is_symbolic_link_000', 0, async function () { + let fpath = await nextFileName('fileio_fstat_is_symbolic_link_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath); + let stat = fileio.fstatSync(fd); + expect(isBoolean(stat.isSymbolicLink())).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_fstat_is_symbolic_link_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_FSTAT_IS_SYMBOLIC_LINK_0010 + * @tc.name fileio_fstat_is_symbolic_link_001 + * @tc.desc Test Fstat.isSymbolicLink() interface. + * This interface shall not treat a normal file as a symbolic link. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_fstat_is_symbolic_link_001', 0, async function () { + let fpath = await nextFileName('fileio_fstat_is_symbolic_link_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath); + let stat = fileio.fstatSync(fd); + expect(stat.isSymbolicLink() === false).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_fstat_is_symbolic_link_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_FSTAT_IS_SYMBOLIC_LINK_0020 + * @tc.name fileio_test_fstat_is_symbolic_link_002 + * @tc.desc Test Fstat.isSymbolicLink() interface. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_fstat_is_symbolic_link_002', 0, async function () { + let fpath = await nextFileName('fileio_test_fstat_is_symbolic_link_002'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath); + let stat = fileio.fstatSync(fd); + expect(stat.isSymbolicLink(-1) === false).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(null).assertFail(); + } catch (e) { + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_FSTAT_ASYNC_0000 + * @tc.name fileio_fstat_async_000 + * @tc.desc Test Stat.FstatAsync() interface. + * This interface shall work properly in normal case when providing the promise async model. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_fstat_async_000', 0, async function (done) { + let fpath = await nextFileName('fileio_fstat_async_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath); + fileio.fstat(fd).then((stat) => { + expect(stat !== null).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + }); + done(); + } catch (e) { + console.log('fileio_fstat_async_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_FSTAT_ASYNC_0000 + * @tc.name fileio_fstat_async_001 + * @tc.desc Test Stat.FstatAsync() interface. + * This interface shall work properly in normal case when providing the callback async model. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_fstat_async_001', 0, async function (done) { + let fpath = await nextFileName('fileio_fstat_async_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath); + fileio.fstat(fd, function (error) { + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + }); + } catch (e) { + console.log('fileio_fstat_async_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_FSTAT_ASYNC_DEV_0000 + * @tc.name fileio_fstat_async_dev_000 + * @tc.desc Test the dev member of class Lstat. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_fstat_async_dev_000', 0, async function (done) { + let fpath = await nextFileName('fileio_fstat_async_dev_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let fd = fileio.openSync(fpath); + let stat = await fileio.fstat(fd); + expect(isIntNum(stat.dev)).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_fstat_async_dev_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_FSTAT_ASYNC_INO_0000 + * @tc.name fileio_fstat_async_ino_000 + * @tc.desc Test the ino member of class Lstat. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_fstat_async_ino_000', 0, async function (done) { + let fpath = await nextFileName('fileio_fstat_async_ino_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let fd = fileio.openSync(fpath); + let stat = await fileio.fstat(fd); + expect(isBigInt(stat.ino)).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_fstat_async_ino_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_FSTAT_ASYNC_MODE_0000 + * @tc.name fileio_fstat_async_mode_000 + * @tc.desc Test the mode member of class Lstat. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_fstat_async_mode_000', 0, async function (done) { + let fpath = await nextFileName('fileio_fstat_async_mode_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let fd = fileio.openSync(fpath); + let stat = await fileio.fstat(fd); + expect(isIntNum(stat.mode)).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_fstat_async_mode_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_FSTAT_ASYNC_NLINK_0000 + * @tc.name fileio_fstat_async_nlink_000 + * @tc.desc Test the nlink member of class Lstat. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_fstat_async_nlink_000', 0, async function (done) { + let fpath = await nextFileName('fileio_fstat_async_nlink_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let fd = fileio.openSync(fpath); + let stat = await fileio.fstat(fd); + expect(isIntNum(stat.nlink)).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_fstat_async_nlink_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_FSTAT_ASYNC_UID_0000 + * @tc.name fileio_fstat_async_uid_000 + * @tc.desc Test the uid member of class Lstat. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_fstat_async_uid_000', 0, async function (done) { + let fpath = await nextFileName('fileio_fstat_async_uid_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let fd = fileio.openSync(fpath); + let stat = await fileio.fstat(fd); + expect(isIntNum(stat.uid)).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_fstat_async_uid_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_FSTAT_ASYNC_GID_0000 + * @tc.name fileio_fstat_async_gid_000 + * @tc.desc Test the gid member of class Lstat. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_fstat_async_gid_000', 0, async function (done) { + let fpath = await nextFileName('fileio_fstat_async_gid_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let fd = fileio.openSync(fpath); + let stat = await fileio.fstat(fd); + expect(isIntNum(stat.gid)).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_fstat_async_gid_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_FSTAT_ASYNC_RDEV_0000 + * @tc.name fileio_fstat_async_rdev_000 + * @tc.desc Test the rdev member of class Lstat. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_fstat_async_rdev_000', 0, async function (done) { + let fpath = await nextFileName('fileio_fstat_async_rdev_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let fd = fileio.openSync(fpath); + let stat = await fileio.fstat(fd); + expect(isIntNum(stat.rdev)).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_fstat_async_rdev_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_FSTAT_ASYNC_SIZE_0000 + * @tc.name fileio_fstat_async_size_000 + * @tc.desc Test the size member of class lstat. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_fstat_async_size_000', 0, async function (done) { + let fpath = await nextFileName('fileio_fstat_async_size_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let fd = fileio.openSync(fpath); + let stat = await fileio.fstat(fd); + expect(isIntNum(stat.size)).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_fstat_async_size_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_FSTAT_ASYNC_BLOCKS_0000 + * @tc.name fileio_fstat_async_blocks_000 + * @tc.desc Test Fstat.blocks() interface. + * @tc.desc Test the blocks member of class lstat. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_fstat_async_blocks_000', 0, async function (done) { + let fpath = await nextFileName('fileio_fstat_async_blocks_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let fd = fileio.openSync(fpath); + let stat = await fileio.fstat(fd); + expect(isIntNum(stat.blocks)).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_fstat_async_blocks_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_FSTAT_ASYNC_ATIME_0000 + * @tc.name fileio_fstat_async_atime_000 + * @tc.desc Test Fstat.atime() interface. + * @tc.desc Test the atime member of class lstat. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_fstat_async_atime_000', 0, async function (done) { + let fpath = await nextFileName('fileio_fstat_async_atime_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let fd = fileio.openSync(fpath); + let stat = await fileio.fstat(fd); + expect(isIntNum(stat.atime)).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_fstat_async_atime_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_FSTAT_ASYNC_MTIME_0000 + * @tc.name fileio_fstat_async_mtime_000 + * @tc.desc Test Fstat.mtime() interface. + * @tc.desc Test the mtime member of class lstat. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_fstat_async_mtime_000', 0, async function (done) { + let fpath = await nextFileName('fileio_fstat_async_mtime_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let fd = fileio.openSync(fpath); + let stat = await fileio.fstat(fd); + expect(isIntNum(stat.mtime)).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_fstat_async_mtime_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_FSTAT_ASYNC_CTIME_0000 + * @tc.name fileio_fstat_async_ctime_000 + * @tc.desc Test the ctime member of class lstat. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_fstat_async_ctime_000', 0, async function (done) { + let fpath = await nextFileName('fileio_fstat_async_ctime_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath); + let stat = await fileio.fstat(fd); + expect(isIntNum(stat.ctime)).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_fstat_async_ctime_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_FSTAT_ASYNC_IS_BLOCK_DEVICE_0000 + * @tc.name fileio_fstat_async_is_block_device_000 + * @tc.desc Test the isBlockDevice method of class lstat. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_fstat_async_is_block_device_000', 0, async function (done) { + let fpath = await nextFileName('fileio_fstat_async_is_block_device_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath); + let stat = await fileio.fstat(fd); + expect(isBoolean(stat.isBlockDevice())).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_fstat_async_is_block_device_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_FSTAT_ASYNC_IS_BLOCK_DEVICE_0010 + * @tc.name fileio_fstat_async_is_block_device_001 + * @tc.desc Test the isBlockDevice method of class lstat. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_fstat_async_is_block_device_001', 0, async function (done) { + let fpath = await nextFileName('fileio_fstat_async_is_block_device_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath); + let stat = await fileio.fstat(fd); + expect(stat.isBlockDevice() === false).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_fstat_async_is_block_device_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_FSTAT_ASYNC_IS_CHARACTER_DEVICE_0000 + * @tc.name fileio_fstat_async_is_character_device_000 + * @tc.desc Test the isCharacterDevice method of class lstat. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_fstat_async_is_character_device_000', 0, async function (done) { + let fpath = await nextFileName('fileio_fstat_async_is_character_device_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath); + let stat = await fileio.fstat(fd); + expect(isBoolean(stat.isCharacterDevice())).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_fstat_async_is_character_device_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_FSTAT_ASYNC_IS_CHARACTER_DEVICE_0010 + * @tc.name fileio_fstat_async_is_character_device_001 + * @tc.desc Test the isCharacterDevice method of class lstat. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_fstat_async_is_character_device_001', 0, async function (done) { + let fpath = await nextFileName('fileio_fstat_async_is_character_device_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath); + let stat = await fileio.fstat(fd); + expect(stat.isCharacterDevice() === false).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_fstat_async_is_character_device_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_FSTAT_ASYNC_IS_DIRECTORY_0000 + * @tc.name fileio_fstat_async_is_directory_000 + * @tc.desc Test lstat.isDirectory() interface. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_fstat_async_is_directory_000', 0, async function (done) { + let fpath = await nextFileName('fileio_fstat_async_is_directory_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath); + let stat = await fileio.fstat(fd); + expect(isBoolean(stat.isDirectory())).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_fstat_async_is_directory_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_FSTAT_ASYNC_IS_DIRECTORY_0010 + * @tc.name fileio_fstat_async_is_directory_001 + * @tc.desc Test lstat.isDirectory() interface. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_fstat_async_is_directory_001', 0, async function (done) { + let fpath = await nextFileName('fileio_fstat_async_is_directory_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath); + let stat = await fileio.fstat(fd); + expect(stat.isDirectory() === false).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_fstat_async_is_directory_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_FSTAT_ASYNC_IS_DIRECTORY_0020 + * @tc.name fileio_fstat_async_is_directory_002 + * @tc.desc Test lstat.isDirectory() interface. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_fstat_async_is_directory_002', 0, async function (done) { + let dpath = await nextFileName('fileio_fstat_async_is_directory_002') + 'da'; + + try { + expect(fileio.mkdirSync(dpath) == null).assertTrue(); + let fd = fileio.openSync(dpath); + let stat = await fileio.fstat(fd); + expect(stat.isDirectory()).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.rmdirSync(dpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_fstat_async_is_directory_002 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_FSTAT_ASYNC_IS_FIFO_0000 + * @tc.name fileio_fstat_async_is_fifo_000 + * @tc.desc Test lstat.isFIFO() interface. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_fstat_async_is_fifo_000', 0, async function (done) { + let fpath = await nextFileName('fileio_fstat_async_is_fifo_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath); + let stat = await fileio.fstat(fd); + expect(isBoolean(stat.isFIFO())).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_fstat_async_is_fifo_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_FSTAT_ASYNC_IS_FIFO_0010 + * @tc.name fileio_fstat_async_is_fifo_001 + * @tc.desc Test lstat.isFIFO() interface. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_fstat_async_is_fifo_001', 0, async function (done) { + let fpath = await nextFileName('fileio_fstat_async_is_fifo_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath); + let stat = await fileio.fstat(fd); + expect(stat.isFIFO() === false).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_fstat_async_is_fifo_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_FSTAT_ASYNC_IS_FILE_0000 + * @tc.name fileio_fstat_async_is_file_000 + * @tc.desc Test lstat.isFile() interface. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_fstat_async_is_file_000', 0, async function (done) { + let fpath = await nextFileName('fileio_fstat_async_is_file_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath); + let stat = await fileio.fstat(fd); + expect(isBoolean(stat.isFile())).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_fstat_async_is_file_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_FSTAT_ASYNC_IS_FILE_0010 + * @tc.name fileio_fstat_async_is_file_001 + * @tc.desc Test lstat.isFile() interface. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_fstat_async_is_file_001', 0, async function (done) { + let fpath = await nextFileName('fileio_fstat_async_is_file_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath); + let stat = await fileio.fstat(fd); + expect(stat.isFile()).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_fstat_async_is_file_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_FSTAT_ASYNC_IS_FILE_0020 + * @tc.name fileio_fstat_async_is_file_002 + * @tc.desc Test lstat.isFile() interface. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_fstat_async_is_file_002', 0, async function (done) { + let dpath = await nextFileName('fileio_fstat_async_is_file_002'); + + try { + expect(fileio.mkdirSync(dpath) == null).assertTrue(); + let fd = fileio.openSync(dpath); + let stat = await fileio.fstat(fd); + expect(stat.isFile() === false).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.rmdirSync(dpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_fstat_async_is_file_002 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_FSTAT_ASYNC_IS_SOCKET_0000 + * @tc.name fileio_fstat_async_is_socket_000 + * @tc.desc Test lstat.isSocket() interface. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_fstat_async_is_socket_000', 0, async function (done) { + let fpath = await nextFileName('fileio_fstat_async_is_socket_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath); + let stat = await fileio.fstat(fd); + expect(isBoolean(stat.isSocket())).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_fstat_async_is_socket_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_FSTAT_ASYNC_IS_SOCKET_0010 + * @tc.name fileio_fstat_async_is_socket_001 + * @tc.desc Test lstat.isSocket() interface. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_fstat_async_is_socket_001', 0, async function (done) { + let fpath = await nextFileName('fileio_fstat_async_is_socket_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath); + let stat = await fileio.fstat(fd); + expect(stat.isSocket() === false).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_fstat_async_is_socket_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_FSTAT_ASYNC_IS_SYMBOLIC_LINK_0000 + * @tc.name fileio_fstat_async_is_symbolic_link_000 + * @tc.desc Test fstat.isSymbolicLink() interface. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_fstat_async_is_symbolic_link_000', 0, async function (done) { + let fpath = await nextFileName('fileio_fstat_async_is_symbolic_link_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let fd = fileio.openSync(fpath); + let stat = await fileio.fstat(fd); + expect(isBoolean(stat.isSymbolicLink())).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_fstat_async_is_symbolic_link_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_FSTAT_ASYNC_IS_SYMBOLIC_LINK_0010 + * @tc.name fileio_fstat_async_is_symbolic_link_001 + * @tc.desc Test lstat.isSymbolicLink() interface. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_fstat_async_is_symbolic_link_001', 0, async function (done) { + let fpath = await nextFileName('fileio_fstat_async_is_symbolic_link_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath); + let stat = await fileio.fstat(fd); + expect(stat.isSymbolicLink() === false).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_fstat_async_is_symbolic_link_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_APPEND_FILE_SYNC_0010 + * @tc.name fileio_test_append_file_sync_000 + * @tc.desc Test lstat.fstatSync() interface. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_append_file_sync_000', 0, async function (done) { + let fpath = await nextFileName('fileio_test_append_file_sync_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath, 0o2002); + let stat = fileio.fstatSync(fd); + expect(isIntNum(stat.size)).assertTrue(); + expect(isIntNum(fd)).assertTrue(); + expect(fileio.writeSync(fd, FILE_CONTENT) == FILE_CONTENT.length).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + + let fd2 = fileio.openSync(fpath, 0o2002); + stat = fileio.fstatSync(fd2); + expect(stat.size == FILE_CONTENT.length * 2).assertTrue(); + expect(fileio.closeSync(fd2) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_test_append_file_sync_000 has failed for ' + e); + expect(null).assertFail(); + } + done(); + }); + +});} diff --git a/storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/members/fsync.test.js b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/fsync.test.js similarity index 95% rename from storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/members/fsync.test.js rename to storage/storagefileiojstest/src/main/js/test/module_fileio/members/fsync.test.js index c642ef1107e9fd2024ac9ec52a9d2ce2f34f84ad..f7c8fd016578366aff52b37fd82defd0f16391c2 100644 --- a/storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/members/fsync.test.js +++ b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/fsync.test.js @@ -1,136 +1,136 @@ -/* - * Copyright (C) 2023 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 { - fileio, FILE_CONTENT, prepareFile, nextFileName, - describe, it, expect, -} from '../../Common'; - -export default function fileioFsync() { -describe('fileio_fsync', function () { - - /** - * @tc.number SUB_DF_FILEIO_FSYNC_SYNC_0000 - * @tc.name fileio_test_fsync_sync_000 - * @tc.desc Test fsyncSync() interface. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_fsync_sync_000', 0, async function () { - let fpath = await nextFileName('fileio_test_fsync_sync_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let fd = fileio.openSync(fpath, 0o2); - expect(fileio.fsyncSync(fd) == null).assertTrue(); - expect(fileio.closeSync(fd) == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - } catch (e) { - console.log('fileio_test_fsync_sync_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_FSYNC_SYNC_0010 - * @tc.name fileio_test_fsync_sync_001 - * @tc.desc Test fsyncSync() interface. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_fsync_sync_001', 0, function () { - try { - fileio.fsyncSync(-1); - expect(null).assertFail(); - } catch (e) { - console.log('fileio_test_fsync_sync_001 has failed for ' + e); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_FSYNC_ASYNC_000 - * @tc.name fileio_test_fsync_sync_000 - * @tc.desc Test fsync() interface. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_fsync_async_000', 0, async function (done) { - let fpath = await nextFileName('fileio_test_fsync_async_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let fd = fileio.openSync(fpath, 0o2); - await fileio.fsync(fd); - expect(fileio.closeSync(fd) == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - done(); - } catch (e) { - console.log('fileio_test_fsync_async_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_FSYNC_ASYNC_001 - * @tc.name fileio_test_fsync_sync_001 - * @tc.desc Test fsync() interface. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_fsync_async_001', 0, async function (done) { - let fpath = await nextFileName('fileio_test_fsync_sync_001'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let fd = fileio.openSync(fpath, 0o2); - fileio.fsync(fd, function (error) { - expect(fileio.closeSync(fd) == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - }); - done(); - } catch (e) { - console.log('fileio_test_fsync_async_001 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_FSYNC_ASYNC_002 - * @tc.name fileio_test_fsync_sync_002 - * @tc.desc Test fsync() interface. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_fsync_async_002', 0, async function (done) { - try { - let fd = -1; - await fileio.fsync(fd); - expect(null).assertFail(); - done(); - } catch (e) { - done(); - } - }) -})} +/* + * Copyright (C) 2021 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 { + fileio, FILE_CONTENT, prepareFile, nextFileName, + describe, it, expect, +} from '../../Common'; + +export default function fileioFsync() { +describe('fileio_fsync', function () { + + /** + * @tc.number SUB_DF_FILEIO_FSYNC_SYNC_0000 + * @tc.name fileio_test_fsync_sync_000 + * @tc.desc Test fsyncSync() interface. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_fsync_sync_000', 0, async function () { + let fpath = await nextFileName('fileio_test_fsync_sync_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath, 0o2); + expect(fileio.fsyncSync(fd) == null).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_test_fsync_sync_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_FSYNC_SYNC_0010 + * @tc.name fileio_test_fsync_sync_001 + * @tc.desc Test fsyncSync() interface. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_fsync_sync_001', 0, function () { + try { + fileio.fsyncSync(-1); + expect(null).assertFail(); + } catch (e) { + console.log('fileio_test_fsync_sync_001 has failed for ' + e); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_FSYNC_ASYNC_000 + * @tc.name fileio_test_fsync_sync_000 + * @tc.desc Test fsync() interface. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_fsync_async_000', 0, async function (done) { + let fpath = await nextFileName('fileio_test_fsync_async_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath, 0o2); + await fileio.fsync(fd); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_test_fsync_async_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_FSYNC_ASYNC_001 + * @tc.name fileio_test_fsync_sync_001 + * @tc.desc Test fsync() interface. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_fsync_async_001', 0, async function (done) { + let fpath = await nextFileName('fileio_test_fsync_sync_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath, 0o2); + fileio.fsync(fd, function (error) { + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + }); + done(); + } catch (e) { + console.log('fileio_test_fsync_async_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_FSYNC_ASYNC_002 + * @tc.name fileio_test_fsync_sync_002 + * @tc.desc Test fsync() interface. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_fsync_async_002', 0, async function (done) { + try { + let fd = -1; + await fileio.fsync(fd); + expect(null).assertFail(); + done(); + } catch (e) { + done(); + } + }) +})} diff --git a/storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/members/ftruncate.test.js b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/ftruncate.test.js similarity index 96% rename from storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/members/ftruncate.test.js rename to storage/storagefileiojstest/src/main/js/test/module_fileio/members/ftruncate.test.js index 61d31afb66952422bd65083cf0fe488afa2563ff..00faf154a4f1f63fb05860635dafd3a1a7098908 100644 --- a/storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/members/ftruncate.test.js +++ b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/ftruncate.test.js @@ -1,277 +1,277 @@ -/* - * Copyright (C) 2023 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.e - */ - -import { - fileio, FILE_CONTENT, prepareFile, nextFileName, isIntNum, - describe, it, expect, -} from '../../Common'; - -export default function fileioFtruncate() { -describe('fileio_ftruncate', function () { - - /** - * @tc.number SUB_DF_FILEIO_FTRUNCATE_ASYNC_0000 - * @tc.name fileio_test_ftruncate_async_000 - * @tc.desc Test ftruncateAsync() interfaces. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_ftruncate_async_000', 0, async function (done) { - let fpath = await nextFileName('fileio_test_ftruncate_async_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - let fd = fileio.openSync(fpath, 0o2); - expect(isIntNum(fd)).assertTrue(); - let truncateLen = 5; - try { - fileio.ftruncate(fd, truncateLen, function (err) { - let len = fileio.readSync(fd, new ArrayBuffer(4096)); - expect(len == truncateLen).assertTrue(); - expect(fileio.closeSync(fd) == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - done(); - }) - } catch (e) { - console.log('fileio_test_ftruncate_async_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_FTRUNCATE_ASYNC_0100 - * @tc.name fileio_test_ftruncate_async_001 - * @tc.desc Test ftruncateAsync() interfaces. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_ftruncate_async_001', 0, async function (done) { - let fpath = await nextFileName('fileio_test_ftruncate_async_001'); - expect(prepareFile(fpath, 'truncate')).assertTrue(); - let fd = fileio.openSync(fpath, 0o2); - expect(isIntNum(fd)).assertTrue(); - let truncateLen = 2; - try { - fileio.ftruncate(fd, truncateLen) - .then(function (err) { - expect(err == null).assertTrue(); - let len = fileio.readSync(fd, new ArrayBuffer(4096)); - expect(len == truncateLen).assertTrue(); - expect(fileio.closeSync(fd) == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - done(); - }) - .catch(function (e) { - console.log('catch ' + e); - }) - } catch (e) { - console.log('fileio_test_ftruncate_async_001 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_FTRUNCATE_ASYNC_0200 - * @tc.name fileio_test_ftruncate_async_002 - * @tc.desc Test ftruncateAsync() interfaces. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_ftruncate_async_002', 0, async function (done) { - let fpath = await nextFileName('fileio_test_ftruncate_async_002'); - let truncateLen = 2; - try { - fileio.ftruncate(fpath, truncateLen, function (err) { - done(); - }) - } catch (e) { - console.log('fileio_test_ftruncate_async_002 has failed for ' + e); - expect(!!e).assertTrue(); - done(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_FTRUNCATE_ASYNC_0300 - * @tc.name fileio_test_ftruncate_async_003 - * @tc.desc Test ftruncate() interfaces. Promise. - * Undefined option arguments, use default length = 0. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 3 - * @tc.require - */ - it('fileio_test_ftruncate_async_003', 3, async function (done) { - let fpath = await nextFileName('fileio_test_ftruncate_async_003'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let fd = fileio.openSync(fpath, 0o2); - expect(isIntNum(fd)).assertTrue(); - await fileio.ftruncate(fd, undefined); - let readLen = fileio.readSync(fd, new ArrayBuffer(4096)); - expect(readLen == 0).assertTrue(); - fileio.closeSync(fd); - fileio.unlinkSync(fpath); - done(); - } catch (e) { - console.log('fileio_test_ftruncate_async_003 has failed for ' + e); - expect(false).assertTrue(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_FTRUNCATE_ASYNC_0400 - * @tc.name fileio_test_ftruncate_async_004 - * @tc.desc Test ftruncate() interfaces. Callback. - * Undefined option arguments, use default length = 0. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 3 - * @tc.require - */ - it('fileio_test_ftruncate_async_004', 3, async function (done) { - let fpath = await nextFileName('fileio_test_ftruncate_async_004'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let fd = fileio.openSync(fpath, 0o2); - expect(isIntNum(fd)).assertTrue(); - fileio.ftruncate(fd, undefined, (err) => { - if (err) { - console.log('fileio_test_ftruncate_async_004 error: ' + e); - expect(false).assertTrue(); - } - let readLen = fileio.readSync(fd, new ArrayBuffer(4096)); - expect(readLen == 0).assertTrue(); - fileio.closeSync(fd); - fileio.unlinkSync(fpath); - done(); - }); - - } catch (e) { - console.log('fileio_test_ftruncate_async_004 has failed for ' + e); - expect(false).assertTrue(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_FTRUNCATE_SYNC_0000 - * @tc.name fileio_test_ftruncate_sync_000 - * @tc.desc Test ftruncateSync() interfaces. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_ftruncate_sync_000', 0, async function () { - let fpath = await nextFileName('fileio_test_ftruncate_sync_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - let fd = fileio.openSync(fpath, 0o2); - expect(isIntNum(fd)).assertTrue(); - let truncateLen = 5; - try { - fileio.ftruncateSync(fd, truncateLen); - let len = fileio.readSync(fd, new ArrayBuffer(4096)); - expect(len == truncateLen).assertTrue(); - expect(fileio.closeSync(fd) == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - } catch (e) { - console.log('fileio_test_ftruncate_sync_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_FTRUNCATE_SYNC_0100 - * @tc.name fileio_test_ftruncate_sync_001 - * @tc.desc Test ftruncateSync() interfaces. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_ftruncate_sync_001', 0, async function () { - let fpath = await nextFileName('fileio_test_ftruncate_sync_001'); - expect(prepareFile(fpath, 'truncate')).assertTrue(); - let fd = fileio.openSync(fpath, 0o2); - expect(isIntNum(fd)).assertTrue(); - let truncateLen = 2; - try { - fileio.ftruncateSync(fd, truncateLen); - let len = fileio.readSync(fd, new ArrayBuffer(4096)); - expect(len == truncateLen).assertTrue(); - expect(fileio.closeSync(fd) == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - } catch (e) { - console.log('fileio_test_ftruncate_sync_001 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_FTRUNCATE_SYNC_0200 - * @tc.name fileio_test_ftruncate_sync_002 - * @tc.desc Test ftruncateSync() interfaces. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_ftruncate_sync_002', 0, async function () { - let fpath = await nextFileName('fileio_test_ftruncate_sync_002'); - let truncateLen = 2; - try { - fileio.ftruncateSync(fpath, truncateLen); - } catch (e) { - console.log('fileio_test_ftruncate_sync_002 has failed for ' + e); - expect(!!e).assertTrue(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_FTRUNCATE_SYNC_0300 - * @tc.name fileio_test_ftruncate_sync_003 - * @tc.desc Test ftruncateSync() interfaces. - * Undefined option arguments, use default length = 0. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 3 - * @tc.require - */ - it('fileio_test_ftruncate_sync_003', 3, async function (done) { - let fpath = await nextFileName('fileio_test_ftruncate_sync_003'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let fd = fileio.openSync(fpath, 0o2); - expect(isIntNum(fd)).assertTrue(); - fileio.ftruncateSync(fd, undefined); - let readLen = fileio.readSync(fd, new ArrayBuffer(4096)); - expect(readLen == 0).assertTrue(); - fileio.closeSync(fd); - fileio.unlinkSync(fpath); - done(); - } catch (e) { - console.log('fileio_test_ftruncate_sync_003 has failed for ' + e); - expect(false).assertTrue(); - } - }); -}); -} +/* + * Copyright (C) 2021 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.e + */ + +import { + fileio, FILE_CONTENT, prepareFile, nextFileName, isIntNum, + describe, it, expect, +} from '../../Common'; + +export default function fileioFtruncate() { +describe('fileio_ftruncate', function () { + + /** + * @tc.number SUB_DF_FILEIO_FTRUNCATE_ASYNC_0000 + * @tc.name fileio_test_ftruncate_async_000 + * @tc.desc Test ftruncateAsync() interfaces. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_ftruncate_async_000', 0, async function (done) { + let fpath = await nextFileName('fileio_test_ftruncate_async_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let fd = fileio.openSync(fpath, 0o2); + expect(isIntNum(fd)).assertTrue(); + let truncateLen = 5; + try { + fileio.ftruncate(fd, truncateLen, function (err) { + let len = fileio.readSync(fd, new ArrayBuffer(4096)); + expect(len == truncateLen).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + }) + } catch (e) { + console.log('fileio_test_ftruncate_async_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_FTRUNCATE_ASYNC_0100 + * @tc.name fileio_test_ftruncate_async_001 + * @tc.desc Test ftruncateAsync() interfaces. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_ftruncate_async_001', 0, async function (done) { + let fpath = await nextFileName('fileio_test_ftruncate_async_001'); + expect(prepareFile(fpath, 'truncate')).assertTrue(); + let fd = fileio.openSync(fpath, 0o2); + expect(isIntNum(fd)).assertTrue(); + let truncateLen = 2; + try { + fileio.ftruncate(fd, truncateLen) + .then(function (err) { + expect(err == null).assertTrue(); + let len = fileio.readSync(fd, new ArrayBuffer(4096)); + expect(len == truncateLen).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + }) + .catch(function (e) { + console.log('catch ' + e); + }) + } catch (e) { + console.log('fileio_test_ftruncate_async_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_FTRUNCATE_ASYNC_0200 + * @tc.name fileio_test_ftruncate_async_002 + * @tc.desc Test ftruncateAsync() interfaces. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_ftruncate_async_002', 0, async function (done) { + let fpath = await nextFileName('fileio_test_ftruncate_async_002'); + let truncateLen = 2; + try { + fileio.ftruncate(fpath, truncateLen, function (err) { + done(); + }) + } catch (e) { + console.log('fileio_test_ftruncate_async_002 has failed for ' + e); + expect(!!e).assertTrue(); + done(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_FTRUNCATE_ASYNC_0300 + * @tc.name fileio_test_ftruncate_async_003 + * @tc.desc Test ftruncate() interfaces. Promise. + * Undefined option arguments, use default length = 0. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileio_test_ftruncate_async_003', 3, async function (done) { + let fpath = await nextFileName('fileio_test_ftruncate_async_003'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath, 0o2); + expect(isIntNum(fd)).assertTrue(); + await fileio.ftruncate(fd, undefined); + let readLen = fileio.readSync(fd, new ArrayBuffer(4096)); + expect(readLen == 0).assertTrue(); + fileio.closeSync(fd); + fileio.unlinkSync(fpath); + done(); + } catch (e) { + console.log('fileio_test_ftruncate_async_003 has failed for ' + e); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_FTRUNCATE_ASYNC_0400 + * @tc.name fileio_test_ftruncate_async_004 + * @tc.desc Test ftruncate() interfaces. Callback. + * Undefined option arguments, use default length = 0. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileio_test_ftruncate_async_004', 3, async function (done) { + let fpath = await nextFileName('fileio_test_ftruncate_async_004'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath, 0o2); + expect(isIntNum(fd)).assertTrue(); + fileio.ftruncate(fd, undefined, (err) => { + if (err) { + console.log('fileio_test_ftruncate_async_004 error: ' + e); + expect(false).assertTrue(); + } + let readLen = fileio.readSync(fd, new ArrayBuffer(4096)); + expect(readLen == 0).assertTrue(); + fileio.closeSync(fd); + fileio.unlinkSync(fpath); + done(); + }); + + } catch (e) { + console.log('fileio_test_ftruncate_async_004 has failed for ' + e); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_FTRUNCATE_SYNC_0000 + * @tc.name fileio_test_ftruncate_sync_000 + * @tc.desc Test ftruncateSync() interfaces. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_ftruncate_sync_000', 0, async function () { + let fpath = await nextFileName('fileio_test_ftruncate_sync_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let fd = fileio.openSync(fpath, 0o2); + expect(isIntNum(fd)).assertTrue(); + let truncateLen = 5; + try { + fileio.ftruncateSync(fd, truncateLen); + let len = fileio.readSync(fd, new ArrayBuffer(4096)); + expect(len == truncateLen).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_test_ftruncate_sync_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_FTRUNCATE_SYNC_0100 + * @tc.name fileio_test_ftruncate_sync_001 + * @tc.desc Test ftruncateSync() interfaces. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_ftruncate_sync_001', 0, async function () { + let fpath = await nextFileName('fileio_test_ftruncate_sync_001'); + expect(prepareFile(fpath, 'truncate')).assertTrue(); + let fd = fileio.openSync(fpath, 0o2); + expect(isIntNum(fd)).assertTrue(); + let truncateLen = 2; + try { + fileio.ftruncateSync(fd, truncateLen); + let len = fileio.readSync(fd, new ArrayBuffer(4096)); + expect(len == truncateLen).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_test_ftruncate_sync_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_FTRUNCATE_SYNC_0200 + * @tc.name fileio_test_ftruncate_sync_002 + * @tc.desc Test ftruncateSync() interfaces. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_ftruncate_sync_002', 0, async function () { + let fpath = await nextFileName('fileio_test_ftruncate_sync_002'); + let truncateLen = 2; + try { + fileio.ftruncateSync(fpath, truncateLen); + } catch (e) { + console.log('fileio_test_ftruncate_sync_002 has failed for ' + e); + expect(!!e).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_FTRUNCATE_SYNC_0300 + * @tc.name fileio_test_ftruncate_sync_003 + * @tc.desc Test ftruncateSync() interfaces. + * Undefined option arguments, use default length = 0. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileio_test_ftruncate_sync_003', 3, async function (done) { + let fpath = await nextFileName('fileio_test_ftruncate_sync_003'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath, 0o2); + expect(isIntNum(fd)).assertTrue(); + fileio.ftruncateSync(fd, undefined); + let readLen = fileio.readSync(fd, new ArrayBuffer(4096)); + expect(readLen == 0).assertTrue(); + fileio.closeSync(fd); + fileio.unlinkSync(fpath); + done(); + } catch (e) { + console.log('fileio_test_ftruncate_sync_003 has failed for ' + e); + expect(false).assertTrue(); + } + }); +}); +} diff --git a/storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/members/hash.test.js b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/hash.test.js similarity index 94% rename from storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/members/hash.test.js rename to storage/storagefileiojstest/src/main/js/test/module_fileio/members/hash.test.js index c55aef946623f94fc3b554acd7a51cb675ecb8dc..c3767e2862d35d935d1d13fca18d67495d95708e 100644 --- a/storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/members/hash.test.js +++ b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/hash.test.js @@ -1,48 +1,48 @@ -/* - * Copyright (C) 2023 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 { - fileio, FILE_CONTENT, prepareFile, nextFileName, - describe, it, expect, -} from '../../Common'; - -export default function fileioHash() { -describe('fileio_hash', function () { - - /** - * @tc.number SUB_DF_FILEIO_HASH_ASYNC_0000 - * @tc.name fileio_test_hash_async_000 - * @tc.desc Test hashAsync() interface. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_hash_async_000', 0, async function (done) { - let fpath = await nextFileName('fileio_test_hash_async_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let str = await fileio.hash(fpath,'md5'); - console.log('fileio_test_hash_async_000 hash value is ' + str); - expect(str == '5EB63BBBE01EEED093CB22BB8F5ACDC3').assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - done(); - } catch (e) { - console.log('fileio_test_hash_async_000 has failed for ' + e); - expect(null).assertFail(); - } - }); -});} +/* + * Copyright (C) 2021 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 { + fileio, FILE_CONTENT, prepareFile, nextFileName, + describe, it, expect, +} from '../../Common'; + +export default function fileioHash() { +describe('fileio_hash', function () { + + /** + * @tc.number SUB_DF_FILEIO_HASH_ASYNC_0000 + * @tc.name fileio_test_hash_async_000 + * @tc.desc Test hashAsync() interface. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_hash_async_000', 0, async function (done) { + let fpath = await nextFileName('fileio_test_hash_async_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let str = await fileio.hash(fpath,'md5'); + console.log('fileio_test_hash_async_000 hash value is ' + str); + expect(str == '5EB63BBBE01EEED093CB22BB8F5ACDC3').assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_test_hash_async_000 has failed for ' + e); + expect(null).assertFail(); + } + }); +});} diff --git a/storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/members/lchown.test.js b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/lchown.test.js similarity index 96% rename from storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/members/lchown.test.js rename to storage/storagefileiojstest/src/main/js/test/module_fileio/members/lchown.test.js index 105d020c0f0aac76b0fca65878d6c72f4e57a3ad..2636e17ed4b68720c9a6148b70c5bc67dc942abb 100644 --- a/storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/members/lchown.test.js +++ b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/lchown.test.js @@ -1,300 +1,300 @@ -/* - * Copyright (C) 2023 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 { - fileio, FILE_CONTENT, prepareFile, nextFileName, isIntNum, - describe, it, expect, -} from '../../Common'; - -export default function fileioLchown() { -describe('fileio_lchown', function () { - - /** - * @tc.number SUB_DF_FILEIO_LSEEK_SYNC_0000 - * @tc.name fileio_test_lchown_sync_000 - * @tc.desc Test lchownSync() interface. The test file was modified successfully. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_lchown_sync_000', 0, async function () { - let fpath = await nextFileName('fileio_test_lchown_sync_000'); - let ffpath = fpath + 'aaaa'; - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - fileio.symlinkSync(fpath, ffpath); - let stat = fileio.statSync(fpath); - fileio.lchownSync(ffpath, stat.uid, stat.gid); - fileio.unlinkSync(fpath); - fileio.unlinkSync(ffpath); - } catch (e) { - console.info('fileio_test_lchown_sync_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_LSEEK_SYNC_0100 - * @tc.name fileio_test_lchown_sync_001 - * @tc.desc Test lchownSync() interface, invalid path. Test file modification failed. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_lchown_sync_001', 0, async function () { - let fpath = await nextFileName('fileio_test_lchown_sync_001'); - let ffpath = await nextFileName('fileio_test_lchown_sync_001_1'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let stat = fileio.statSync(fpath); - fileio.lchownSync(ffpath, stat.uid, stat.gid); - } catch (e) { - console.info('fileio_test_lchown_sync_001 has failed for ' + e); - expect(e.message == "No such file or directory").assertTrue(); - fileio.unlinkSync(fpath); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_LSEEK_SYNC_0200 - * @tc.name fileio_test_lchown_sync_002 - * @tc.desc Test lchownSync() interface, wrong uid, gid. Test file modification failed. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_lchown_sync_002', 0, async function () { - let fpath = await nextFileName('fileio_test_lchown_sync_002'); - let ffpath = fpath + 'aaaa'; - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - fileio.symlinkSync(fpath, ffpath); - fileio.lchownSync(ffpath, 0, 0); - } catch (e) { - console.info('fileio_test_lchown_sync_002 has failed for ' + e); - expect(e.message == "Operation not permitted").assertTrue(); - fileio.unlinkSync(fpath); - fileio.unlinkSync(ffpath); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_LSEEK_SYNC_0300 - * @tc.name fileio_test_lchown_sync_003 - * @tc.desc Test lchownSync() interface, wrong owner. Test file modification failed. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_lchown_sync_003', 0, async function () { - let fpath = await nextFileName('fileio_test_lchown_sync_003'); - let ffpath = fpath + 'aaaa'; - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - fileio.symlinkSync(fpath, ffpath); - let stat = fileio.statSync(fpath); - fileio.lchownSync(ffpath, null, stat.gid); - } catch (e) { - console.info('fileio_test_lchown_sync_003 has failed for ' + e); - expect(e.message == "Invalid owner").assertTrue(); - fileio.unlinkSync(fpath); - fileio.unlinkSync(ffpath); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_LSEEK_SYNC_0400 - * @tc.name fileio_test_lchown_sync_004 - * @tc.desc Test lchownSync() interface, wrong group. Test file modification failed. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_lchown_sync_004', 0, async function () { - let fpath = await nextFileName('fileio_test_lchown_sync_004'); - let ffpath = fpath + 'aaaa'; - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - fileio.symlinkSync(fpath, ffpath); - let stat = fileio.statSync(fpath); - fileio.lchownSync(ffpath, stat.uid, null); - } catch (e) { - console.info('fileio_test_lchown_sync_004 has failed for ' + e); - expect(e.message == "Invalid group").assertTrue(); - fileio.unlinkSync(fpath); - fileio.unlinkSync(ffpath); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_LCHOWN_ASYNC_0000 - * @tc.name fileio_test_lchown_async_000 - * @tc.desc Test the lchownASync() interface with promise. The test file was modified successfully. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_lchown_async_000', 0, async function (done) { - let fpath = await nextFileName('fileio_test_lchown_async_000'); - let ffpath = fpath + 'aaaa'; - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - fileio.symlinkSync(fpath, ffpath); - let stat = fileio.statSync(fpath); - await fileio.lchown(ffpath, stat.uid, stat.gid); - fileio.unlinkSync(fpath); - fileio.unlinkSync(ffpath); - done(); - } catch (e) { - console.info('fileio_test_lchown_async_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_LCHOWN_ASYNC_0100 - * @tc.name fileio_test_lchown_async_001 - * @tc.desc Test the lchownASync() interface with callback. The test file was modified successfully. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_lchown_async_001', 0, async function (done) { - let fpath = await nextFileName('fileio_test_lchown_async_001'); - let ffpath = fpath + 'aaaa'; - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - fileio.symlinkSync(fpath, ffpath); - let stat = fileio.statSync(fpath); - fileio.lchown(ffpath, stat.uid, stat.gid, function (error) { - fileio.unlinkSync(fpath); - fileio.unlinkSync(ffpath); - done(); - }); - } catch (e) { - console.info('fileio_test_lchown_async_001 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_LCHOWN_ASYNC_0200 - * @tc.name fileio_test_lchown_async_002 - * @tc.desc Test the lchownASync() interface with promise, invalid path. Test file modification failed. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_lchown_async_002', 0, async function (done) { - let fpath = await nextFileName('fileio_test_lchown_async_002'); - let ffpath = await nextFileName('fileio_test_lchown_sync_001_1'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let stat = fileio.statSync(fpath); - await fileio.lchown(ffpath, stat.uid, stat.gid); - } catch (e) { - console.info('fileio_test_lchown_async_002 has failed for ' + e); - expect(e.message == "No such file or directory").assertTrue(); - fileio.unlinkSync(fpath); - done(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_LCHOWN_ASYNC_0300 - * @tc.name fileio_test_lchown_async_003 - * @tc.desc Test the lchownASync() interface with promise, wrong uid, gid. Test file modification failed. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_lchown_async_003', 0, async function (done) { - let fpath = await nextFileName('fileio_test_lchown_async_003'); - let ffpath = fpath + 'aaaa'; - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - fileio.symlinkSync(fpath, ffpath); - await fileio.lchown(ffpath, 0, 0); - } catch (e) { - console.info('fileio_test_lchown_async_003 has failed for ' + e); - expect(e.message == "Operation not permitted").assertTrue(); - fileio.unlinkSync(fpath); - fileio.unlinkSync(ffpath); - done(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_LCHOWN_ASYNC_0400 - * @tc.name fileio_test_lchown_async_004 - * @tc.desc Test the lchownASync() interface with promise, wrong owner. Test file modification failed. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_lchown_async_004', 0, async function (done) { - let fpath = await nextFileName('fileio_test_lchown_async_004'); - let ffpath = fpath + 'aaaa'; - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - fileio.symlinkSync(fpath, ffpath); - let stat = fileio.statSync(fpath); - await fileio.lchown(ffpath, null, stat.gid); - } catch (e) { - console.info('fileio_test_lchown_async_004 has failed for ' + e); - expect(e.message == "Invalid owner").assertTrue(); - fileio.unlinkSync(fpath); - fileio.unlinkSync(ffpath); - done(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_LCHOWN_ASYNC_0500 - * @tc.name fileio_test_lchown_async_005 - * @tc.desc Test the lchownASync() interface with promise, wrong group. Test file modification failed. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_lchown_async_005', 0, async function (done) { - let fpath = await nextFileName('fileio_test_lchown_async_005'); - let ffpath = fpath + 'aaaa'; - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - fileio.symlinkSync(fpath, ffpath); - let stat = fileio.statSync(fpath); - await fileio.lchown(ffpath, stat.uid, null); - } catch (e) { - console.info('fileio_test_lchown_async_005 has failed for ' + e); - expect(e.message == "Invalid group").assertTrue(); - fileio.unlinkSync(fpath); - fileio.unlinkSync(ffpath); - done(); - } - }); -}); -} +/* + * Copyright (C) 2021 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 { + fileio, FILE_CONTENT, prepareFile, nextFileName, isIntNum, + describe, it, expect, +} from '../../Common'; + +export default function fileioLchown() { +describe('fileio_lchown', function () { + + /** + * @tc.number SUB_DF_FILEIO_LSEEK_SYNC_0000 + * @tc.name fileio_test_lchown_sync_000 + * @tc.desc Test lchownSync() interface. The test file was modified successfully. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_lchown_sync_000', 0, async function () { + let fpath = await nextFileName('fileio_test_lchown_sync_000'); + let ffpath = fpath + 'aaaa'; + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + fileio.symlinkSync(fpath, ffpath); + let stat = fileio.statSync(fpath); + fileio.lchownSync(ffpath, stat.uid, stat.gid); + fileio.unlinkSync(fpath); + fileio.unlinkSync(ffpath); + } catch (e) { + console.info('fileio_test_lchown_sync_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LSEEK_SYNC_0100 + * @tc.name fileio_test_lchown_sync_001 + * @tc.desc Test lchownSync() interface, invalid path. Test file modification failed. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_lchown_sync_001', 0, async function () { + let fpath = await nextFileName('fileio_test_lchown_sync_001'); + let ffpath = await nextFileName('fileio_test_lchown_sync_001_1'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let stat = fileio.statSync(fpath); + fileio.lchownSync(ffpath, stat.uid, stat.gid); + } catch (e) { + console.info('fileio_test_lchown_sync_001 has failed for ' + e); + expect(e.message == "No such file or directory").assertTrue(); + fileio.unlinkSync(fpath); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LSEEK_SYNC_0200 + * @tc.name fileio_test_lchown_sync_002 + * @tc.desc Test lchownSync() interface, wrong uid, gid. Test file modification failed. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_lchown_sync_002', 0, async function () { + let fpath = await nextFileName('fileio_test_lchown_sync_002'); + let ffpath = fpath + 'aaaa'; + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + fileio.symlinkSync(fpath, ffpath); + fileio.lchownSync(ffpath, 0, 0); + } catch (e) { + console.info('fileio_test_lchown_sync_002 has failed for ' + e); + expect(e.message == "Operation not permitted").assertTrue(); + fileio.unlinkSync(fpath); + fileio.unlinkSync(ffpath); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LSEEK_SYNC_0300 + * @tc.name fileio_test_lchown_sync_003 + * @tc.desc Test lchownSync() interface, wrong owner. Test file modification failed. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_lchown_sync_003', 0, async function () { + let fpath = await nextFileName('fileio_test_lchown_sync_003'); + let ffpath = fpath + 'aaaa'; + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + fileio.symlinkSync(fpath, ffpath); + let stat = fileio.statSync(fpath); + fileio.lchownSync(ffpath, null, stat.gid); + } catch (e) { + console.info('fileio_test_lchown_sync_003 has failed for ' + e); + expect(e.message == "Invalid owner").assertTrue(); + fileio.unlinkSync(fpath); + fileio.unlinkSync(ffpath); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LSEEK_SYNC_0400 + * @tc.name fileio_test_lchown_sync_004 + * @tc.desc Test lchownSync() interface, wrong group. Test file modification failed. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_lchown_sync_004', 0, async function () { + let fpath = await nextFileName('fileio_test_lchown_sync_004'); + let ffpath = fpath + 'aaaa'; + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + fileio.symlinkSync(fpath, ffpath); + let stat = fileio.statSync(fpath); + fileio.lchownSync(ffpath, stat.uid, null); + } catch (e) { + console.info('fileio_test_lchown_sync_004 has failed for ' + e); + expect(e.message == "Invalid group").assertTrue(); + fileio.unlinkSync(fpath); + fileio.unlinkSync(ffpath); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LCHOWN_ASYNC_0000 + * @tc.name fileio_test_lchown_async_000 + * @tc.desc Test the lchownASync() interface with promise. The test file was modified successfully. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_lchown_async_000', 0, async function (done) { + let fpath = await nextFileName('fileio_test_lchown_async_000'); + let ffpath = fpath + 'aaaa'; + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + fileio.symlinkSync(fpath, ffpath); + let stat = fileio.statSync(fpath); + await fileio.lchown(ffpath, stat.uid, stat.gid); + fileio.unlinkSync(fpath); + fileio.unlinkSync(ffpath); + done(); + } catch (e) { + console.info('fileio_test_lchown_async_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LCHOWN_ASYNC_0100 + * @tc.name fileio_test_lchown_async_001 + * @tc.desc Test the lchownASync() interface with callback. The test file was modified successfully. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_lchown_async_001', 0, async function (done) { + let fpath = await nextFileName('fileio_test_lchown_async_001'); + let ffpath = fpath + 'aaaa'; + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + fileio.symlinkSync(fpath, ffpath); + let stat = fileio.statSync(fpath); + fileio.lchown(ffpath, stat.uid, stat.gid, function (error) { + fileio.unlinkSync(fpath); + fileio.unlinkSync(ffpath); + done(); + }); + } catch (e) { + console.info('fileio_test_lchown_async_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LCHOWN_ASYNC_0200 + * @tc.name fileio_test_lchown_async_002 + * @tc.desc Test the lchownASync() interface with promise, invalid path. Test file modification failed. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_lchown_async_002', 0, async function (done) { + let fpath = await nextFileName('fileio_test_lchown_async_002'); + let ffpath = await nextFileName('fileio_test_lchown_sync_001_1'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let stat = fileio.statSync(fpath); + await fileio.lchown(ffpath, stat.uid, stat.gid); + } catch (e) { + console.info('fileio_test_lchown_async_002 has failed for ' + e); + expect(e.message == "No such file or directory").assertTrue(); + fileio.unlinkSync(fpath); + done(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LCHOWN_ASYNC_0300 + * @tc.name fileio_test_lchown_async_003 + * @tc.desc Test the lchownASync() interface with promise, wrong uid, gid. Test file modification failed. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_lchown_async_003', 0, async function (done) { + let fpath = await nextFileName('fileio_test_lchown_async_003'); + let ffpath = fpath + 'aaaa'; + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + fileio.symlinkSync(fpath, ffpath); + await fileio.lchown(ffpath, 0, 0); + } catch (e) { + console.info('fileio_test_lchown_async_003 has failed for ' + e); + expect(e.message == "Operation not permitted").assertTrue(); + fileio.unlinkSync(fpath); + fileio.unlinkSync(ffpath); + done(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LCHOWN_ASYNC_0400 + * @tc.name fileio_test_lchown_async_004 + * @tc.desc Test the lchownASync() interface with promise, wrong owner. Test file modification failed. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_lchown_async_004', 0, async function (done) { + let fpath = await nextFileName('fileio_test_lchown_async_004'); + let ffpath = fpath + 'aaaa'; + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + fileio.symlinkSync(fpath, ffpath); + let stat = fileio.statSync(fpath); + await fileio.lchown(ffpath, null, stat.gid); + } catch (e) { + console.info('fileio_test_lchown_async_004 has failed for ' + e); + expect(e.message == "Invalid owner").assertTrue(); + fileio.unlinkSync(fpath); + fileio.unlinkSync(ffpath); + done(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LCHOWN_ASYNC_0500 + * @tc.name fileio_test_lchown_async_005 + * @tc.desc Test the lchownASync() interface with promise, wrong group. Test file modification failed. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_lchown_async_005', 0, async function (done) { + let fpath = await nextFileName('fileio_test_lchown_async_005'); + let ffpath = fpath + 'aaaa'; + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + fileio.symlinkSync(fpath, ffpath); + let stat = fileio.statSync(fpath); + await fileio.lchown(ffpath, stat.uid, null); + } catch (e) { + console.info('fileio_test_lchown_async_005 has failed for ' + e); + expect(e.message == "Invalid group").assertTrue(); + fileio.unlinkSync(fpath); + fileio.unlinkSync(ffpath); + done(); + } + }); +}); +} diff --git a/storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/members/lseek.test.js b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/lseek.test.js similarity index 95% rename from storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/members/lseek.test.js rename to storage/storagefileiojstest/src/main/js/test/module_fileio/members/lseek.test.js index 17027aa2685a4491ef9fcff10c2d10e049c655c4..eaa8caa537ab680d05cea59b6fcd59dec1ae1e50 100644 --- a/storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/members/lseek.test.js +++ b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/lseek.test.js @@ -1,124 +1,124 @@ -/* - * Copyright (C) 2023 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 { - fileio, FILE_CONTENT, prepareFile, nextFileName, isIntNum, - describe, it, expect, -} from '../../Common'; - -export default function fileioLseek() { -describe('fileio_lseek', function () { - - /** - * @tc.number _SUB_DF_FILEIO_LSEEK_ASYNC_0000 - * @tc.name fileio_test_lseek_async_000 - * @tc.desc Test lseekAsync()interfaces. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_lseek_async_000', 0, async function (done) { - let fpath = await nextFileName('fileio_test_lseek_async_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let fd = fileio.openSync(fpath, 0o2); - await fileio.lseek(fd, -1, 2, function (err) { - expect(fileio.closeSync(fd) == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - done(); - }) - } catch (e) { - console.log('fileio_test_lseek_async_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number _SUB_DF_FILEIO_LSEEK_ASYNC_0010 - * @tc.name fileio_test_lseek_async_001 - * @tc.desc Test lseekAsync()interfaces. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_lseek_async_001', 0, async function (done) { - let fpath = await nextFileName('fileio_test_lseek_async_001'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let fd = fileio.openSync(fpath, 0o2); - let num = await fileio.lseek(fd, -1, 2); - expect(isIntNum(num)).assertTrue(); - expect(fileio.closeSync(fd) == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - done(); - } catch (e) { - console.log('fileio_test_lseek_async_001 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_LSEEK_SYNC_0000 - * @tc.name fileio_test_lseek_sync_000 - * @tc.desc Test lseekSync()interfaces. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_lseek_sync_000', 0, async function () { - let fpath = await nextFileName('fileio_test_lseek_sync_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let fd = fileio.openSync(fpath, 0o102, 0o666); - let num = fileio.lseekSync(fd, -1, 2); - expect(isIntNum(num)).assertTrue(); - expect(fileio.closeSync(fd) == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - } catch (e) { - console.log('fileio_test_lseek_sync_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_LSEEK_SYNC_0010 - * @tc.name fileio_test_lseek_sync_001 - * @tc.desc Test lseekSync() interfaces. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_lseek_sync_001', 0, async function () { - let fpath = await nextFileName('fileio_test_lseek_sync_001'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let fd = fileio.openSync(fpath, 0o102, 0o666); - let num = fileio.lseekSync(fd, 9, 0); - expect(isIntNum(num)).assertTrue(); - expect(fileio.closeSync(fd) == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - } catch (e) { - console.log('fileio_test_lseek_sync_001 has failed for ' + e); - expect(null).assertFail(); - } - }); -}); -} +/* + * Copyright (C) 2021 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 { + fileio, FILE_CONTENT, prepareFile, nextFileName, isIntNum, + describe, it, expect, +} from '../../Common'; + +export default function fileioLseek() { +describe('fileio_lseek', function () { + + /** + * @tc.number _SUB_DF_FILEIO_LSEEK_ASYNC_0000 + * @tc.name fileio_test_lseek_async_000 + * @tc.desc Test lseekAsync()interfaces. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_lseek_async_000', 0, async function (done) { + let fpath = await nextFileName('fileio_test_lseek_async_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let fd = fileio.openSync(fpath, 0o2); + await fileio.lseek(fd, -1, 2, function (err) { + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + }) + } catch (e) { + console.log('fileio_test_lseek_async_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number _SUB_DF_FILEIO_LSEEK_ASYNC_0010 + * @tc.name fileio_test_lseek_async_001 + * @tc.desc Test lseekAsync()interfaces. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_lseek_async_001', 0, async function (done) { + let fpath = await nextFileName('fileio_test_lseek_async_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let fd = fileio.openSync(fpath, 0o2); + let num = await fileio.lseek(fd, -1, 2); + expect(isIntNum(num)).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_test_lseek_async_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LSEEK_SYNC_0000 + * @tc.name fileio_test_lseek_sync_000 + * @tc.desc Test lseekSync()interfaces. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_lseek_sync_000', 0, async function () { + let fpath = await nextFileName('fileio_test_lseek_sync_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath, 0o102, 0o666); + let num = fileio.lseekSync(fd, -1, 2); + expect(isIntNum(num)).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_test_lseek_sync_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LSEEK_SYNC_0010 + * @tc.name fileio_test_lseek_sync_001 + * @tc.desc Test lseekSync() interfaces. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_lseek_sync_001', 0, async function () { + let fpath = await nextFileName('fileio_test_lseek_sync_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath, 0o102, 0o666); + let num = fileio.lseekSync(fd, 9, 0); + expect(isIntNum(num)).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_test_lseek_sync_001 has failed for ' + e); + expect(null).assertFail(); + } + }); +}); +} diff --git a/storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/members/lstat.test.js b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/lstat.test.js similarity index 96% rename from storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/members/lstat.test.js rename to storage/storagefileiojstest/src/main/js/test/module_fileio/members/lstat.test.js index 9930ab3bcdf9e177fc5e00a18cca5a876841f897..4524ac9d9a1099e72f8e9af77ead1c30289141d1 100644 --- a/storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/members/lstat.test.js +++ b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/lstat.test.js @@ -1,1663 +1,1663 @@ -/* - * Copyright (C) 2023 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 { - fileio, FILE_CONTENT, prepareFile, nextFileName, isIntNum, isBigInt, isBoolean, - describe, it, expect, -} from '../../Common'; - -export default function fileioLstat() { -describe('fileio_lstat', function () { - - /** - * @tc.number SUB_DF_FILEIO_LSTAT_SYNC_0000 - * @tc.name fileio_lstat_sync_000 - * @tc.desc Test Lstat.lstatSync() interface. - * This interface shall work properly in normal case. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_lstat_sync_000', 0, async function () { - let fpath = await nextFileName('fileio_lstat_sync_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let stat = fileio.lstatSync(fpath); - expect(stat !== null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - } catch (e) { - console.log('fileio_lstat_sync_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_LSTAT_SYNC_0010 - * @tc.name fileio_lstat_sync_001 - * @tc.desc Test Lstat.lstatSync() interface. - * This interface shall throw an exception when the file isnt's exist. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_lstat_sync_001', 0, async function () { - let fpath = await nextFileName('fileio_lstat_sync_001'); - - try { - fileio.lstatSync(fpath); - expect(null).assertFail(); - } catch (e) { - console.log('fileio_lstat_sync_001 has failed for ' + e); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_LSTAT_DEV_0000 - * @tc.name fileio_lstat_dev_000 - * @tc.desc Test the dev member of class Lstat. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_lstat_dev_000', 0, async function () { - let fpath = await nextFileName('fileio_lstat_dev_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let stat = fileio.lstatSync(fpath); - expect(isIntNum(stat.dev)).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - } catch (e) { - console.log('fileio_lstat_dev_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_LSTAT_INO_0000 - * @tc.name fileio_lstat_ino_000 - * @tc.desc Test the ino member of class Lstat - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_lstat_ino_000', 0, async function () { - let fpath = await nextFileName('fileio_lstat_ino_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let stat = fileio.lstatSync(fpath); - expect(isBigInt(stat.ino)).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - } catch (e) { - console.log('fileio_lstat_ino_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_LSTAT_MODE_0000 - * @tc.name fileio_lstat_mode_000 - * @tc.desc Test the mode member of class Lstat - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_lstat_mode_000', 0, async function () { - let fpath = await nextFileName('fileio_lstat_mode_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let stat = fileio.lstatSync(fpath); - expect(isIntNum(stat.mode)).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - } catch (e) { - console.log('fileio_lstat_mode_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_LSTAT_NLINK_0000 - * @tc.name fileio_lstat_nlink_000 - * @tc.desc Test the nlink member of class Lstat - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_lstat_nlink_000', 0, async function () { - let fpath = await nextFileName('fileio_lstat_nlink_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let stat = fileio.lstatSync(fpath); - expect(isIntNum(stat.nlink)).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - } catch (e) { - console.log('fileio_lstat_nlink_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_LSTAT_UID_0000 - * @tc.name fileio_lstat_uid_000 - * @tc.desc Test the uid member of class Lstat - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_lstat_uid_000', 0, async function () { - let fpath = await nextFileName('fileio_lstat_uid_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let stat = fileio.lstatSync(fpath); - expect(isIntNum(stat.uid)).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - } catch (e) { - console.log('fileio_lstat_uid_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_LSTAT_GID_0000 - * @tc.name fileio_lstat_gid_000 - * @tc.desc Test the gid member of class Lstat - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_lstat_gid_000', 0, async function () { - let fpath = await nextFileName('fileio_lstat_gid_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let stat = fileio.lstatSync(fpath); - expect(isIntNum(stat.gid)).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - } catch (e) { - console.log('fileio_lstat_gid_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_LSTAT_RDEV_0000 - * @tc.name fileio_lstat_rdev_000 - * @tc.desc Test the rdev member of class Lstat - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_lstat_rdev_000', 0, async function () { - let fpath = await nextFileName('fileio_lstat_rdev_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let stat = fileio.lstatSync(fpath); - expect(isIntNum(stat.rdev)).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - } catch (e) { - console.log('fileio_lstat_rdev_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_LSTAT_SIZE_0000 - * @tc.name fileio_lstat_size_000 - * @tc.desc Test the size member of class Lstat - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_lstat_size_000', 0, async function () { - let fpath = await nextFileName('fileio_lstat_size_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let stat = fileio.lstatSync(fpath); - expect(isIntNum(stat.size)).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - } catch (e) { - console.log('fileio_lstat_size_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_LSTAT_BLOCKS_0000 - * @tc.name fileio_lstat_blocks_000 - * @tc.desc Test the blocks member of class Lstat - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_lstat_blocks_000', 0, async function () { - let fpath = await nextFileName('fileio_lstat_blocks_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let stat = fileio.lstatSync(fpath); - expect(isIntNum(stat.blocks)).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - } catch (e) { - console.log('fileio_lstat_blocks_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_LSTAT_ATIME_0000 - * @tc.name fileio_lstat_atime_000 - * @tc.desc Test the atime member of class Lstat - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_lstat_atime_000', 0, async function () { - let fpath = await nextFileName('fileio_lstat_atime_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let stat = fileio.lstatSync(fpath); - expect(isIntNum(stat.atime)).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - } catch (e) { - console.log('fileio_lstat_atime_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_LSTAT_MTIME_0000 - * @tc.name fileio_lstat_mtime_000 - * @tc.desc Test the mtime member of class Lstat - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_lstat_mtime_000', 0, async function () { - let fpath = await nextFileName('fileio_lstat_mtime_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let stat = fileio.lstatSync(fpath); - expect(isIntNum(stat.mtime)).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - } catch (e) { - console.log('fileio_lstat_mtime_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_LSTAT_CTIME_0000 - * @tc.name fileio_lstat_ctime_000 - * @tc.desc Test the ctime member of class Lstat - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_lstat_ctime_000', 0, async function () { - let fpath = await nextFileName('fileio_lstat_ctime_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let stat = fileio.lstatSync(fpath); - expect(isIntNum(stat.ctime)).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - } catch (e) { - console.log('fileio_lstat_ctime_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_LSTAT_IS_BLOCK_DEVICE_0000 - * @tc.name fileio_lstat_is_block_device_000 - * @tc.desc Test the isBlockDevice() method of class Lstat. - * This interface shall return a boolean variable. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_lstat_is_block_device_000', 0, async function () { - let fpath = await nextFileName('fileio_lstat_is_block_device_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let stat = fileio.lstatSync(fpath); - expect(isBoolean(stat.isBlockDevice())).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - } catch (e) { - console.log('fileio_lstat_is_block_device_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_LSTAT_IS_BLOCK_DEVICE_0010 - * @tc.name fileio_lstat_is_block_device_001 - * @tc.desc Test the isBlockDevice() method of class Lstat. - * This interface shall not treat a normal file as a block special device. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_lstat_is_block_device_001', 0, async function () { - let fpath = await nextFileName('fileio_lstat_is_block_device_001'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let stat = fileio.lstatSync(fpath); - expect(stat.isBlockDevice() === false).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - } catch (e) { - console.log('fileio_lstat_is_block_device_001 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_LSTAT_IS_BLOCK_DEVICE_0020 - * @tc.name fileio_test_lstat_is_block_device_002 - * @tc.desc Test Lstat.isBlockDevice() interface. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_lstat_is_block_device_002', 0, async function () { - let fpath = await nextFileName('fileio_test_lstat_is_block_device_002'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let stat = fileio.lstatSync(fpath); - expect(stat.isBlockDevice(-1) === false).assertTrue(); - expect(null).assertFail(); - } catch (e) { - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_LSTAT_IS_CHARACTER_DEVICE_0000 - * @tc.name fileio_lstat_is_character_device_000 - * @tc.desc Test Lstat.isCharacterDevice() interface. - * This interface shall return a boolean variable. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_lstat_is_character_device_000', 0, async function () { - let fpath = await nextFileName('fileio_lstat_is_character_device_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let stat = fileio.lstatSync(fpath); - expect(isBoolean(stat.isCharacterDevice())).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - } catch (e) { - console.log('fileio_lstat_is_character_device_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_LSTAT_IS_CHARACTER_DEVICE_0010 - * @tc.name fileio_lstat_is_character_device_001 - * @tc.desc Test Lstat.isCharacterDevice() interface. - * This interface shall not treat a normal file as a character special device. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_lstat_is_character_device_001', 0, async function () { - let fpath = await nextFileName('fileio_lstat_is_character_device_001'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let stat = fileio.lstatSync(fpath); - expect(stat.isCharacterDevice() === false).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - } catch (e) { - console.log('fileio_lstat_is_character_device_001 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_LSTAT_IS_CHARACTER_DEVICE_0020 - * @tc.name fileio_test_lstat_is_character_device_002 - * @tc.desc Test Lstat.isCharacterDevice() interface. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_lstat_is_character_device_002', 0, async function () { - let fpath = await nextFileName('fileio_test_lstat_is_character_device_002'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let stat = fileio.lstatSync(fpath); - expect(stat.isCharacterDevice(-1) === false).assertTrue(); - expect(null).assertFail(); - } catch (e) { - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_LSTAT_IS_DIRECTORY_0000 - * @tc.name fileio_lstat_is_directory_000 - * @tc.desc Test Lstat.isDirectory() interface. - * This interface shall return a boolean variable. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_lstat_is_directory_000', 0, async function () { - let fpath = await nextFileName('fileio_lstat_is_directory_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let stat = fileio.lstatSync(fpath); - expect(isBoolean(stat.isDirectory())).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - } catch (e) { - console.log('fileio_lstat_is_directory_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_LSTAT_IS_DIRECTORY_0010 - * @tc.name fileio_lstat_is_directory_001 - * @tc.desc Test Lstat.isDirectory() interface. - * This interface shall not treat a normal file as a directory. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_lstat_is_directory_001', 0, async function () { - let fpath = await nextFileName('fileio_lstat_is_directory_001'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let stat = fileio.lstatSync(fpath); - expect(stat.isDirectory() === false).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - } catch (e) { - console.log('fileio_lstat_is_directory_001 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_LSTAT_IS_DIRECTORY_0020 - * @tc.name fileio_lstat_is_directory_002 - * @tc.desc Test Lstat.isDirectory() interface. - * This interface shall not treat a normal file as a directory. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_lstat_is_directory_002', 0, async function () { - let dpath = await nextFileName('fileio_lstat_is_directory_002') + 'd'; - - try { - expect(fileio.mkdirSync(dpath) == null).assertTrue(); - let stat = fileio.lstatSync(dpath); - expect(stat.isDirectory()).assertTrue(); - expect(fileio.rmdirSync(dpath) == null).assertTrue(); - } catch (e) { - console.log('fileio_lstat_is_directory_002 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_LSTAT_IS_DIRECTORY_0030 - * @tc.name fileio_lstat_is_directory_003 - * @tc.desc Test Lstat.isDirectory() interface. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_lstat_is_directory_003', 0, async function () { - let dpath = await nextFileName('fileio_lstat_is_directory_003') + 'd'; - - try { - expect(fileio.mkdirSync(dpath) == null).assertTrue(); - let stat = fileio.lstatSync(dpath); - expect(stat.isDirectory(-1)).assertTrue(); - expect(null).assertFail(); - } catch (e) { - expect(fileio.rmdirSync(dpath) == null).assertTrue(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_LSTAT_IS_FIFO_0000 - * @tc.name fileio_lstat_is_fifo_000 - * @tc.desc Test Lstat.isFIFO() interface. - * This interface shall return a boolean variable. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_lstat_is_fifo_000', 0, async function () { - let fpath = await nextFileName('fileio_lstat_is_fifo_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let stat = fileio.lstatSync(fpath); - expect(isBoolean(stat.isFIFO())).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - } catch (e) { - console.log('fileio_lstat_is_fifo_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_LSTAT_IS_FIFO_0010 - * @tc.name fileio_lstat_is_fifo_001 - * @tc.desc Test Lstat.isFIFO() interface. - * This interface shall not treat a normal file as a FIFO. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_lstat_is_fifo_001', 0, async function () { - let fpath = await nextFileName('fileio_lstat_is_fifo_001'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let stat = fileio.lstatSync(fpath); - expect(stat.isFIFO() === false).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - } catch (e) { - console.log('fileio_lstat_is_fifo_001 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_LSTAT_IS_FIFO_0020 - * @tc.name fileio_test_stat_is_fifo_002 - * @tc.desc Test Lstat.isFIFO() interface. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_lstat_is_fifo_002', 0, async function () { - let fpath = await nextFileName('fileio_test_lstat_is_fifo_002'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let stat = fileio.lstatSync(fpath); - expect(stat.isFIFO(-1) === false).assertTrue(); - expect(null).assertFail(); - } catch (e) { - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_LSTAT_IS_FILE_0000 - * @tc.name fileio_lstat_is_file_000 - * @tc.desc Test Lstat.isFile() interface. - * This interface shall return a boolean variable. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_lstat_is_file_000', 0, async function () { - let fpath = await nextFileName('fileio_lstat_is_file_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let stat = fileio.lstatSync(fpath); - expect(isBoolean(stat.isFile())).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - } catch (e) { - console.log('fileio_lstat_is_file_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_LSTAT_IS_FILE_0010 - * @tc.name fileio_lstat_is_file_001 - * @tc.desc Test Lstat.isFile() interface. - * This interface shall treat a normal file as a normal file. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_lstat_is_file_001', 0, async function () { - let fpath = await nextFileName('fileio_lstat_is_file_001'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let stat = fileio.lstatSync(fpath); - expect(stat.isFile()).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - } catch (e) { - console.log('fileio_lstat_is_file_001 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_LSTAT_IS_FILE_0020 - * @tc.name fileio_lstat_is_file_002 - * @tc.desc Test Lstat.isFile() interface. - * This interface shall not treat a directory as a normal file. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_lstat_is_file_002', 0, async function () { - let dpath = await nextFileName('fileio_lstat_is_file_002'); - - try { - expect(fileio.mkdirSync(dpath) == null).assertTrue(); - let stat = fileio.lstatSync(dpath); - expect(stat.isFile() === false).assertTrue(); - expect(fileio.rmdirSync(dpath) == null).assertTrue(); - } catch (e) { - console.log('fileio_lstat_is_file_002 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_LSTAT_IS_FILE_0030 - * @tc.name fileio_test_lstat_is_file_003 - * @tc.desc Test Lstat.isFile() interface. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_lstat_is_file_003', 0, async function () { - let dpath = await nextFileName('fileio_test_lstat_is_file_003'); - - try { - expect(fileio.mkdirSync(dpath) == null).assertTrue(); - let stat = fileio.lstatSync(dpath); - expect(stat.isFile(-1) === false).assertTrue(); - expect(null).assertFail(); - } catch (e) { - expect(fileio.rmdirSync(dpath) == null).assertTrue(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_LSTAT_IS_SOCKET_0000 - * @tc.name fileio_lstat_is_socket_000 - * @tc.desc Test Lstat.isSocket() interface. - * This interface shall return a boolean variable. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_lstat_is_socket_000', 0, async function () { - let fpath = await nextFileName('fileio_lstat_is_socket_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let stat = fileio.lstatSync(fpath); - expect(isBoolean(stat.isSocket())).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - } catch (e) { - console.log('fileio_lstat_is_socket_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_LSTAT_IS_SOCKET_0010 - * @tc.name fileio_lstat_is_socket_001 - * @tc.desc Test Lstat.isSocket() interface. - * This interface shall not treat a file as a socket. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_lstat_is_socket_001', 0, async function () { - let fpath = await nextFileName('fileio_lstat_is_socket_001'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let stat = fileio.lstatSync(fpath); - expect(stat.isSocket() === false).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - } catch (e) { - console.log('fileio_lstat_is_socket_001 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_LSTAT_IS_SOCKET_0020 - * @tc.name fileio_test_lstat_is_socket_002 - * @tc.desc Test Lstat.isSocket() interface. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_lstat_is_socket_002', 0, async function () { - let fpath = await nextFileName('fileio_test_lstat_is_socket_002'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let stat = fileio.lstatSync(fpath); - expect(stat.isSocket(-1) === false).assertTrue(); - expect(null).assertFail(); - } catch (e) { - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_LSTAT_IS_SYMBOLIC_LINK_0000 - * @tc.name fileio_lstat_is_symbolic_link_000 - * @tc.desc Test Lstat.isSymbolicLink() interface. - * This interface shall return a boolean variable. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_lstat_is_symbolic_link_000', 0, async function () { - let fpath = await nextFileName('fileio_lstat_is_symbolic_link_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let stat = fileio.lstatSync(fpath); - expect(isBoolean(stat.isSymbolicLink())).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - } catch (e) { - console.log('fileio_lstat_is_symbolic_link_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_LSTAT_IS_SYMBOLIC_LINK_0010 - * @tc.name fileio_lstat_is_symbolic_link_001 - * @tc.desc Test Lstat.isSymbolicLink() interface. - * This interface shall not treat a normal file as a symbolic link. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_lstat_is_symbolic_link_001', 0, async function () { - let fpath = await nextFileName('fileio_lstat_is_symbolic_link_001'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let stat = fileio.lstatSync(fpath); - expect(stat.isSymbolicLink() === false).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - } catch (e) { - console.log('fileio_lstat_is_symbolic_link_001 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_LSTAT_IS_SYMBOLIC_LINK_0020 - * @tc.name fileio_test_lstat_is_symbolic_link_002 - * @tc.desc Test Lstat.isSymbolicLink() interface. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_lstat_is_symbolic_link_002', 0, async function () { - let fpath = await nextFileName('fileio_test_lstat_is_symbolic_link_002'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let stat = fileio.lstatSync(fpath); - expect(stat.isSymbolicLink(-1) === false).assertTrue(); - expect(null).assertFail(); - } catch (e) { - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_LSTAT_ASYNC_0000 - * @tc.name fileio_lstat_async_000 - * @tc.desc Test Stat.lstatAsync() interface. - * This interface shall work properly in normal case when providing the promise async model. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_lstat_async_000', 0, async function (done) { - let fpath = await nextFileName('fileio_lstat_async_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - fileio.lstat(fpath).then((stat) => { - expect(stat !== null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - }); - done(); - } catch (e) { - console.log('fileio_lstat_async_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_LSTAT_ASYNC_0010 - * @tc.name fileio_lstat_async_001 - * @tc.desc Test Stat.lstatAsync() interface. - * This interface shall work properly in normal case when providing the callback async model. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_lstat_async_001', 0, async function (done) { - let fpath = await nextFileName('fileio_lstat_async_001'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - fileio.lstat(fpath, function (error) { - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - done(); - }); - } catch (e) { - console.log('fileio_lstat_async_001 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_LSTAT_ASYNC_0020 - * @tc.name fileio_lstat_async_002 - * @tc.desc Test Stat.lstatAsync() interface. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_lstat_async_002', 0, async function (done) { - let fpath = await nextFileName('fileio_lstat_async_002'); - - try { - fileio.lstat(fpath, function (err) { - done(); - }); - } catch (e) { - console.log('fileio_lstat_async_002 has failed for ' + e); - expect(!!e).assertTrue(); - done(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_LSTAT_ASYNC_DEV_0000 - * @tc.name fileio_lstat_async_dev_000 - * @tc.desc Test the dev member of class Lstat. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_lstat_async_dev_000', 0, async function (done) { - let fpath = await nextFileName('fileio_lstat_async_dev_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let stat = await fileio.lstat(fpath); - expect(isIntNum(stat.dev)).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - done(); - } catch (e) { - console.log('fileio_lstat_async_dev_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_LSTAT_ASYNC_INO_0000 - * @tc.name fileio_lstat_async_ino_000 - * @tc.desc Test the ino member of class Lstat. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_lstat_async_ino_000', 0, async function (done) { - let fpath = await nextFileName('fileio_lstat_async_ino_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let stat = await fileio.lstat(fpath); - expect(isBigInt(stat.ino)).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - done(); - } catch (e) { - console.log('fileio_lstat_async_ino_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_LSTAT_ASYNC_MODE_0000 - * @tc.name fileio_lstat_async_mode_000 - * @tc.desc Test the mode member of class Lstat. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_lstat_async_mode_000', 0, async function (done) { - let fpath = await nextFileName('fileio_lstat_async_mode_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let stat = await fileio.lstat(fpath); - expect(isIntNum(stat.mode)).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - done(); - } catch (e) { - console.log('fileio_lstat_async_mode_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_LSTAT_ASYNC_NLINK_0000 - * @tc.name fileio_lstat_async_nlink_000 - * @tc.desc Test the nlink member of class Lstat. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_lstat_async_nlink_000', 0, async function (done) { - let fpath = await nextFileName('fileio_lstat_async_nlink_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let stat = await fileio.lstat(fpath); - expect(isIntNum(stat.nlink)).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - done(); - } catch (e) { - console.log('fileio_lstat_async_nlink_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_LSTAT_ASYNC_UID_0000 - * @tc.name fileio_lstat_async_uid_000 - * @tc.desc Test the uid member of class Lstat. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_lstat_async_uid_000', 0, async function (done) { - let fpath = await nextFileName('fileio_lstat_async_uid_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let stat = await fileio.lstat(fpath); - expect(isIntNum(stat.uid)).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - done(); - } catch (e) { - console.log('fileio_lstat_async_uid_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_LSTAT_ASYNC_GID_0000 - * @tc.name fileio_lstat_async_gid_000 - * @tc.desc Test the gid member of class Lstat. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_lstat_async_gid_000', 0, async function (done) { - let fpath = await nextFileName('fileio_lstat_async_gid_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let stat = await fileio.lstat(fpath); - expect(isIntNum(stat.gid)).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - done(); - } catch (e) { - console.log('fileio_lstat_async_gid_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_LSTAT_ASYNC_RDEV_0000 - * @tc.name fileio_lstat_async_rdev_000 - * @tc.desc Test the rdev member of class Lstat. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_lstat_async_rdev_000', 0, async function (done) { - let fpath = await nextFileName('fileio_lstat_async_rdev_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let stat = await fileio.lstat(fpath); - expect(isIntNum(stat.rdev)).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - done(); - } catch (e) { - console.log('fileio_lstat_async_rdev_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_LSTAT_ASYNC_SIZE_0000 - * @tc.name fileio_lstat_async_size_000 - * @tc.desc Test the size member of class lstat. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_lstat_async_size_000', 0, async function (done) { - let fpath = await nextFileName('fileio_lstat_async_size_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let stat = await fileio.lstat(fpath); - expect(isIntNum(stat.size)).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - done(); - } catch (e) { - console.log('fileio_lstat_async_size_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_LSTAT_ASYNC_BLOCKS_0000 - * @tc.name fileio_lstat_async_blocks_000 - * @tc.desc Test lstat.blocks() interface. - * @tc.desc Test the blocks member of class lstat. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_lstat_async_blocks_000', 0, async function (done) { - let fpath = await nextFileName('fileio_lstat_async_blocks_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let stat = await fileio.lstat(fpath); - expect(isIntNum(stat.blocks)).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - done(); - } catch (e) { - console.log('fileio_lstat_async_blocks_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_LSTAT_ASYNC_ATIME_0000 - * @tc.name fileio_lstat_async_atime_000 - * @tc.desc Test lstat.atime() interface. - * @tc.desc Test the atime member of class lstat. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_lstat_async_atime_000', 0, async function (done) { - let fpath = await nextFileName('fileio_lstat_async_atime_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let stat = await fileio.lstat(fpath); - expect(isIntNum(stat.atime)).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - done(); - } catch (e) { - console.log('fileio_lstat_async_atime_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_LSTAT_ASYNC_MTIME_0000 - * @tc.name fileio_lstat_async_mtime_000 - * @tc.desc Test lstat.mtime() interface. - * @tc.desc Test the mtime member of class lstat. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_lstat_async_mtime_000', 0, async function (done) { - let fpath = await nextFileName('fileio_lstat_async_mtime_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let stat = await fileio.lstat(fpath); - expect(isIntNum(stat.mtime)).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - done(); - } catch (e) { - console.log('fileio_lstat_async_mtime_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_LSTAT_ASYNC_CTIME_0000 - * @tc.name fileio_lstat_async_ctime_000 - * @tc.desc Test the ctime member of class lstat. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_lstat_async_ctime_000', 0, async function (done) { - let fpath = await nextFileName('fileio_lstat_async_ctime_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let stat = await fileio.lstat(fpath); - expect(isIntNum(stat.ctime)).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - done(); - } catch (e) { - console.log('fileio_lstat_async_ctime_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_LSTAT_ASYNC_IS_BLOCK_DEVICE_0000 - * @tc.name fileio_lstat_async_is_block_device_000 - * @tc.desc Test the isBlockDevice method of class lstat. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_lstat_async_is_block_device_000', 0, async function (done) { - let fpath = await nextFileName('fileio_lstat_async_is_block_device_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let stat = await fileio.lstat(fpath); - expect(isBoolean(stat.isBlockDevice())).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - done(); - } catch (e) { - console.log('fileio_lstat_async_is_block_device_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_LSTAT_ASYNC_IS_BLOCK_DEVICE_0010 - * @tc.name fileio_lstat_async_is_block_device_001 - * @tc.desc Test the isBlockDevice method of class lstat. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_lstat_async_is_block_device_001', 0, async function (done) { - let fpath = await nextFileName('fileio_lstat_async_is_block_device_001'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let stat = await fileio.lstat(fpath); - expect(stat.isBlockDevice() === false).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - done(); - } catch (e) { - console.log('fileio_lstat_async_is_block_device_001 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_LSTAT_ASYNC_IS_CHARACTER_DEVICE_0000 - * @tc.name fileio_lstat_async_is_character_device_000 - * @tc.desc Test the isCharacterDevice method of class lstat. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_lstat_async_is_character_device_000', 0, async function (done) { - let fpath = await nextFileName('fileio_lstat_async_is_character_device_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let stat = await fileio.lstat(fpath); - expect(isBoolean(stat.isCharacterDevice())).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - done(); - } catch (e) { - console.log('fileio_lstat_async_is_character_device_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_LSTAT_ASYNC_IS_CHARACTER_DEVICE_0010 - * @tc.name fileio_lstat_async_is_character_device_001 - * @tc.desc Test the isCharacterDevice method of class lstat. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_lstat_async_is_character_device_001', 0, async function (done) { - let fpath = await nextFileName('fileio_lstat_async_is_character_device_001'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let stat = await fileio.lstat(fpath); - expect(stat.isCharacterDevice() === false).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - done(); - } catch (e) { - console.log('fileio_lstat_async_is_character_device_001 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_LSTAT_ASYNC_IS_DIRECTORY_0000 - * @tc.name fileio_lstat_async_is_directory_000 - * @tc.desc Test lstat.isDirectory() interface. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_lstat_async_is_directory_000', 0, async function (done) { - let fpath = await nextFileName('fileio_lstat_async_is_directory_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let stat = await fileio.lstat(fpath); - expect(isBoolean(stat.isDirectory())).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - done(); - } catch (e) { - console.log('fileio_lstat_async_is_directory_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_LSTAT_ASYNC_IS_DIRECTORY_0010 - * @tc.name fileio_lstat_async_is_directory_001 - * @tc.desc Test lstat.isDirectory() interface. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_lstat_async_is_directory_001', 0, async function (done) { - let fpath = await nextFileName('fileio_lstat_async_is_directory_001'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let stat = await fileio.lstat(fpath); - expect(stat.isDirectory() === false).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - done(); - } catch (e) { - console.log('fileio_lstat_async_is_directory_001 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_LSTAT_ASYNC_IS_DIRECTORY_0020 - * @tc.name fileio_lstat_async_is_directory_002 - * @tc.desc Test lstat.isDirectory() interface. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_lstat_async_is_directory_002', 0, async function (done) { - let dpath = await nextFileName('fileio_lstat_async_is_directory_002') + 'd'; - - try { - expect(fileio.mkdirSync(dpath) == null).assertTrue(); - let stat = await fileio.lstat(dpath); - expect(stat.isDirectory()).assertTrue(); - expect(fileio.rmdirSync(dpath) == null).assertTrue(); - done(); - } catch (e) { - console.log('fileio_lstat_async_is_directory_002 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_LSTAT_ASYNC_IS_FIFO_0000 - * @tc.name fileio_lstat_async_is_fifo_000 - * @tc.desc Test lstat.isFIFO() interface. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_lstat_async_is_fifo_000', 0, async function (done) { - let fpath = await nextFileName('fileio_lstat_async_is_fifo_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let stat = await fileio.lstat(fpath); - expect(isBoolean(stat.isFIFO())).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - done(); - } catch (e) { - console.log('fileio_lstat_async_is_fifo_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_LSTAT_ASYNC_IS_FIFO_0010 - * @tc.name fileio_lstat_async_is_fifo_001 - * @tc.desc Test lstat.isFIFO() interface. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_lstat_async_is_fifo_001', 0, async function (done) { - let fpath = await nextFileName('fileio_lstat_async_is_fifo_001'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let stat = await fileio.lstat(fpath); - expect(stat.isFIFO() === false).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - done(); - } catch (e) { - console.log('fileio_lstat_async_is_fifo_001 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_LSTAT_ASYNC_IS_FILE_0000 - * @tc.name fileio_lstat_async_is_file_000 - * @tc.desc Test lstat.isFile() interface. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_lstat_async_is_file_000', 0, async function (done) { - let fpath = await nextFileName('fileio_lstat_async_is_file_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let stat = await fileio.lstat(fpath); - expect(isBoolean(stat.isFile())).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - done(); - } catch (e) { - console.log('fileio_lstat_async_is_file_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_LSTAT_ASYNC_IS_FILE_0010 - * @tc.name fileio_lstat_async_is_file_001 - * @tc.desc Test lstat.isFile() interface. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_lstat_async_is_file_001', 0, async function (done) { - let fpath = await nextFileName('fileio_lstat_async_is_file_001'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let stat = await fileio.lstat(fpath); - expect(stat.isFile()).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - done(); - } catch (e) { - console.log('fileio_lstat_async_is_file_001 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_LSTAT_ASYNC_IS_FILE_0020 - * @tc.name fileio_lstat_async_is_file_002 - * @tc.desc Test lstat.isFile() interface. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_lstat_async_is_file_002', 0, async function (done) { - let dpath = await nextFileName('fileio_lstat_async_is_file_002'); - - try { - expect(fileio.mkdirSync(dpath) == null).assertTrue(); - let stat = await fileio.lstat(dpath); - expect(stat.isFile() === false).assertTrue(); - expect(fileio.rmdirSync(dpath) == null).assertTrue(); - done(); - } catch (e) { - console.log('fileio_lstat_async_is_file_002 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_LSTAT_ASYNC_IS_SOCKET_0000 - * @tc.name fileio_lstat_async_is_socket_000 - * @tc.desc Test lstat.isSocket() interface. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_lstat_async_is_socket_000', 0, async function (done) { - let fpath = await nextFileName('fileio_lstat_async_is_socket_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let stat = await fileio.lstat(fpath); - expect(isBoolean(stat.isSocket())).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - done(); - } catch (e) { - console.log('fileio_lstat_async_is_socket_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_LSTAT_ASYNC_IS_SOCKET_0010 - * @tc.name fileio_lstat_async_is_socket_001 - * @tc.desc Test lstat.isSocket() interface. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_lstat_async_is_socket_001', 0, async function (done) { - let fpath = await nextFileName('fileio_lstat_async_is_socket_001'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let stat = await fileio.lstat(fpath); - expect(stat.isSocket() === false).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - done(); - } catch (e) { - console.log('fileio_lstat_async_is_socket_001 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_LSTAT_ASYNC_IS_SYMBOLIC_LINK_0000 - * @tc.name fileio_lstat_async_is_symbolic_link_000 - * @tc.desc Test lstat.isSymbolicLink() interface. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_lstat_async_is_symbolic_link_000', 0, async function (done) { - let fpath = await nextFileName('fileio_lstat_async_is_symbolic_link_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let stat = await fileio.lstat(fpath); - expect(isBoolean(stat.isSymbolicLink())).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - done(); - } catch (e) { - console.log('fileio_lstat_async_is_symbolic_link_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_LSTAT_ASYNC_IS_SYMBOLIC_LINK_0010 - * @tc.name fileio_lstat_async_is_symbolic_link_001 - * @tc.desc Test lstat.isSymbolicLink() interface. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_lstat_async_is_symbolic_link_001', 0, async function (done) { - let fpath = await nextFileName('fileio_lstat_async_is_symbolic_link_001'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let stat = await fileio.lstat(fpath); - expect(stat.isSymbolicLink() === false).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - done(); - } catch (e) { - console.log('fileio_lstat_async_is_symbolic_link_001 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_APPEND_FILE_SYNC_0010 - * @tc.name fileio_test_append_file_sync_000 - * @tc.desc Test lstat.lstatSync() interface. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_append_file_sync_000', 0, async function (done) { - let fpath = await nextFileName('fileio_test_append_file_sync_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let stat = fileio.lstatSync(fpath); - expect(isIntNum(stat.size)).assertTrue(); - - let fd = fileio.openSync(fpath, 0o2002); - expect(isIntNum(fd)).assertTrue(); - - expect(fileio.writeSync(fd, FILE_CONTENT) == FILE_CONTENT.length).assertTrue(); - expect(fileio.closeSync(fd) == null).assertTrue(); - - stat = fileio.lstatSync(fpath); - expect(stat.size == FILE_CONTENT.length * 2).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - } catch (e) { - console.log('fileio_test_append_file_sync_000 has failed for ' + e); - expect(null).assertFail(); - } - done(); - }); -});} +/* + * Copyright (C) 2021 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 { + fileio, FILE_CONTENT, prepareFile, nextFileName, isIntNum, isBigInt, isBoolean, + describe, it, expect, +} from '../../Common'; + +export default function fileioLstat() { +describe('fileio_lstat', function () { + + /** + * @tc.number SUB_DF_FILEIO_LSTAT_SYNC_0000 + * @tc.name fileio_lstat_sync_000 + * @tc.desc Test Lstat.lstatSync() interface. + * This interface shall work properly in normal case. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_lstat_sync_000', 0, async function () { + let fpath = await nextFileName('fileio_lstat_sync_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileio.lstatSync(fpath); + expect(stat !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_lstat_sync_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LSTAT_SYNC_0010 + * @tc.name fileio_lstat_sync_001 + * @tc.desc Test Lstat.lstatSync() interface. + * This interface shall throw an exception when the file isnt's exist. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_lstat_sync_001', 0, async function () { + let fpath = await nextFileName('fileio_lstat_sync_001'); + + try { + fileio.lstatSync(fpath); + expect(null).assertFail(); + } catch (e) { + console.log('fileio_lstat_sync_001 has failed for ' + e); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LSTAT_DEV_0000 + * @tc.name fileio_lstat_dev_000 + * @tc.desc Test the dev member of class Lstat. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_lstat_dev_000', 0, async function () { + let fpath = await nextFileName('fileio_lstat_dev_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileio.lstatSync(fpath); + expect(isIntNum(stat.dev)).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_lstat_dev_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LSTAT_INO_0000 + * @tc.name fileio_lstat_ino_000 + * @tc.desc Test the ino member of class Lstat + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_lstat_ino_000', 0, async function () { + let fpath = await nextFileName('fileio_lstat_ino_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let stat = fileio.lstatSync(fpath); + expect(isBigInt(stat.ino)).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_lstat_ino_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LSTAT_MODE_0000 + * @tc.name fileio_lstat_mode_000 + * @tc.desc Test the mode member of class Lstat + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_lstat_mode_000', 0, async function () { + let fpath = await nextFileName('fileio_lstat_mode_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileio.lstatSync(fpath); + expect(isIntNum(stat.mode)).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_lstat_mode_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LSTAT_NLINK_0000 + * @tc.name fileio_lstat_nlink_000 + * @tc.desc Test the nlink member of class Lstat + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_lstat_nlink_000', 0, async function () { + let fpath = await nextFileName('fileio_lstat_nlink_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileio.lstatSync(fpath); + expect(isIntNum(stat.nlink)).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_lstat_nlink_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LSTAT_UID_0000 + * @tc.name fileio_lstat_uid_000 + * @tc.desc Test the uid member of class Lstat + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_lstat_uid_000', 0, async function () { + let fpath = await nextFileName('fileio_lstat_uid_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileio.lstatSync(fpath); + expect(isIntNum(stat.uid)).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_lstat_uid_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LSTAT_GID_0000 + * @tc.name fileio_lstat_gid_000 + * @tc.desc Test the gid member of class Lstat + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_lstat_gid_000', 0, async function () { + let fpath = await nextFileName('fileio_lstat_gid_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileio.lstatSync(fpath); + expect(isIntNum(stat.gid)).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_lstat_gid_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LSTAT_RDEV_0000 + * @tc.name fileio_lstat_rdev_000 + * @tc.desc Test the rdev member of class Lstat + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_lstat_rdev_000', 0, async function () { + let fpath = await nextFileName('fileio_lstat_rdev_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileio.lstatSync(fpath); + expect(isIntNum(stat.rdev)).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_lstat_rdev_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LSTAT_SIZE_0000 + * @tc.name fileio_lstat_size_000 + * @tc.desc Test the size member of class Lstat + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_lstat_size_000', 0, async function () { + let fpath = await nextFileName('fileio_lstat_size_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileio.lstatSync(fpath); + expect(isIntNum(stat.size)).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_lstat_size_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LSTAT_BLOCKS_0000 + * @tc.name fileio_lstat_blocks_000 + * @tc.desc Test the blocks member of class Lstat + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_lstat_blocks_000', 0, async function () { + let fpath = await nextFileName('fileio_lstat_blocks_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileio.lstatSync(fpath); + expect(isIntNum(stat.blocks)).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_lstat_blocks_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LSTAT_ATIME_0000 + * @tc.name fileio_lstat_atime_000 + * @tc.desc Test the atime member of class Lstat + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_lstat_atime_000', 0, async function () { + let fpath = await nextFileName('fileio_lstat_atime_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileio.lstatSync(fpath); + expect(isIntNum(stat.atime)).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_lstat_atime_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LSTAT_MTIME_0000 + * @tc.name fileio_lstat_mtime_000 + * @tc.desc Test the mtime member of class Lstat + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_lstat_mtime_000', 0, async function () { + let fpath = await nextFileName('fileio_lstat_mtime_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileio.lstatSync(fpath); + expect(isIntNum(stat.mtime)).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_lstat_mtime_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LSTAT_CTIME_0000 + * @tc.name fileio_lstat_ctime_000 + * @tc.desc Test the ctime member of class Lstat + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_lstat_ctime_000', 0, async function () { + let fpath = await nextFileName('fileio_lstat_ctime_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileio.lstatSync(fpath); + expect(isIntNum(stat.ctime)).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_lstat_ctime_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LSTAT_IS_BLOCK_DEVICE_0000 + * @tc.name fileio_lstat_is_block_device_000 + * @tc.desc Test the isBlockDevice() method of class Lstat. + * This interface shall return a boolean variable. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_lstat_is_block_device_000', 0, async function () { + let fpath = await nextFileName('fileio_lstat_is_block_device_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileio.lstatSync(fpath); + expect(isBoolean(stat.isBlockDevice())).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_lstat_is_block_device_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LSTAT_IS_BLOCK_DEVICE_0010 + * @tc.name fileio_lstat_is_block_device_001 + * @tc.desc Test the isBlockDevice() method of class Lstat. + * This interface shall not treat a normal file as a block special device. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_lstat_is_block_device_001', 0, async function () { + let fpath = await nextFileName('fileio_lstat_is_block_device_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileio.lstatSync(fpath); + expect(stat.isBlockDevice() === false).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_lstat_is_block_device_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LSTAT_IS_BLOCK_DEVICE_0020 + * @tc.name fileio_test_lstat_is_block_device_002 + * @tc.desc Test Lstat.isBlockDevice() interface. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_lstat_is_block_device_002', 0, async function () { + let fpath = await nextFileName('fileio_test_lstat_is_block_device_002'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileio.lstatSync(fpath); + expect(stat.isBlockDevice(-1) === false).assertTrue(); + expect(null).assertFail(); + } catch (e) { + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LSTAT_IS_CHARACTER_DEVICE_0000 + * @tc.name fileio_lstat_is_character_device_000 + * @tc.desc Test Lstat.isCharacterDevice() interface. + * This interface shall return a boolean variable. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_lstat_is_character_device_000', 0, async function () { + let fpath = await nextFileName('fileio_lstat_is_character_device_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileio.lstatSync(fpath); + expect(isBoolean(stat.isCharacterDevice())).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_lstat_is_character_device_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LSTAT_IS_CHARACTER_DEVICE_0010 + * @tc.name fileio_lstat_is_character_device_001 + * @tc.desc Test Lstat.isCharacterDevice() interface. + * This interface shall not treat a normal file as a character special device. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_lstat_is_character_device_001', 0, async function () { + let fpath = await nextFileName('fileio_lstat_is_character_device_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileio.lstatSync(fpath); + expect(stat.isCharacterDevice() === false).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_lstat_is_character_device_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LSTAT_IS_CHARACTER_DEVICE_0020 + * @tc.name fileio_test_lstat_is_character_device_002 + * @tc.desc Test Lstat.isCharacterDevice() interface. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_lstat_is_character_device_002', 0, async function () { + let fpath = await nextFileName('fileio_test_lstat_is_character_device_002'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileio.lstatSync(fpath); + expect(stat.isCharacterDevice(-1) === false).assertTrue(); + expect(null).assertFail(); + } catch (e) { + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LSTAT_IS_DIRECTORY_0000 + * @tc.name fileio_lstat_is_directory_000 + * @tc.desc Test Lstat.isDirectory() interface. + * This interface shall return a boolean variable. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_lstat_is_directory_000', 0, async function () { + let fpath = await nextFileName('fileio_lstat_is_directory_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileio.lstatSync(fpath); + expect(isBoolean(stat.isDirectory())).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_lstat_is_directory_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LSTAT_IS_DIRECTORY_0010 + * @tc.name fileio_lstat_is_directory_001 + * @tc.desc Test Lstat.isDirectory() interface. + * This interface shall not treat a normal file as a directory. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_lstat_is_directory_001', 0, async function () { + let fpath = await nextFileName('fileio_lstat_is_directory_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileio.lstatSync(fpath); + expect(stat.isDirectory() === false).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_lstat_is_directory_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LSTAT_IS_DIRECTORY_0020 + * @tc.name fileio_lstat_is_directory_002 + * @tc.desc Test Lstat.isDirectory() interface. + * This interface shall not treat a normal file as a directory. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_lstat_is_directory_002', 0, async function () { + let dpath = await nextFileName('fileio_lstat_is_directory_002') + 'd'; + + try { + expect(fileio.mkdirSync(dpath) == null).assertTrue(); + let stat = fileio.lstatSync(dpath); + expect(stat.isDirectory()).assertTrue(); + expect(fileio.rmdirSync(dpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_lstat_is_directory_002 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LSTAT_IS_DIRECTORY_0030 + * @tc.name fileio_lstat_is_directory_003 + * @tc.desc Test Lstat.isDirectory() interface. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_lstat_is_directory_003', 0, async function () { + let dpath = await nextFileName('fileio_lstat_is_directory_003') + 'd'; + + try { + expect(fileio.mkdirSync(dpath) == null).assertTrue(); + let stat = fileio.lstatSync(dpath); + expect(stat.isDirectory(-1)).assertTrue(); + expect(null).assertFail(); + } catch (e) { + expect(fileio.rmdirSync(dpath) == null).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LSTAT_IS_FIFO_0000 + * @tc.name fileio_lstat_is_fifo_000 + * @tc.desc Test Lstat.isFIFO() interface. + * This interface shall return a boolean variable. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_lstat_is_fifo_000', 0, async function () { + let fpath = await nextFileName('fileio_lstat_is_fifo_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileio.lstatSync(fpath); + expect(isBoolean(stat.isFIFO())).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_lstat_is_fifo_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LSTAT_IS_FIFO_0010 + * @tc.name fileio_lstat_is_fifo_001 + * @tc.desc Test Lstat.isFIFO() interface. + * This interface shall not treat a normal file as a FIFO. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_lstat_is_fifo_001', 0, async function () { + let fpath = await nextFileName('fileio_lstat_is_fifo_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileio.lstatSync(fpath); + expect(stat.isFIFO() === false).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_lstat_is_fifo_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LSTAT_IS_FIFO_0020 + * @tc.name fileio_test_stat_is_fifo_002 + * @tc.desc Test Lstat.isFIFO() interface. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_lstat_is_fifo_002', 0, async function () { + let fpath = await nextFileName('fileio_test_lstat_is_fifo_002'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileio.lstatSync(fpath); + expect(stat.isFIFO(-1) === false).assertTrue(); + expect(null).assertFail(); + } catch (e) { + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LSTAT_IS_FILE_0000 + * @tc.name fileio_lstat_is_file_000 + * @tc.desc Test Lstat.isFile() interface. + * This interface shall return a boolean variable. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_lstat_is_file_000', 0, async function () { + let fpath = await nextFileName('fileio_lstat_is_file_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileio.lstatSync(fpath); + expect(isBoolean(stat.isFile())).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_lstat_is_file_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LSTAT_IS_FILE_0010 + * @tc.name fileio_lstat_is_file_001 + * @tc.desc Test Lstat.isFile() interface. + * This interface shall treat a normal file as a normal file. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_lstat_is_file_001', 0, async function () { + let fpath = await nextFileName('fileio_lstat_is_file_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileio.lstatSync(fpath); + expect(stat.isFile()).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_lstat_is_file_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LSTAT_IS_FILE_0020 + * @tc.name fileio_lstat_is_file_002 + * @tc.desc Test Lstat.isFile() interface. + * This interface shall not treat a directory as a normal file. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_lstat_is_file_002', 0, async function () { + let dpath = await nextFileName('fileio_lstat_is_file_002'); + + try { + expect(fileio.mkdirSync(dpath) == null).assertTrue(); + let stat = fileio.lstatSync(dpath); + expect(stat.isFile() === false).assertTrue(); + expect(fileio.rmdirSync(dpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_lstat_is_file_002 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LSTAT_IS_FILE_0030 + * @tc.name fileio_test_lstat_is_file_003 + * @tc.desc Test Lstat.isFile() interface. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_lstat_is_file_003', 0, async function () { + let dpath = await nextFileName('fileio_test_lstat_is_file_003'); + + try { + expect(fileio.mkdirSync(dpath) == null).assertTrue(); + let stat = fileio.lstatSync(dpath); + expect(stat.isFile(-1) === false).assertTrue(); + expect(null).assertFail(); + } catch (e) { + expect(fileio.rmdirSync(dpath) == null).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LSTAT_IS_SOCKET_0000 + * @tc.name fileio_lstat_is_socket_000 + * @tc.desc Test Lstat.isSocket() interface. + * This interface shall return a boolean variable. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_lstat_is_socket_000', 0, async function () { + let fpath = await nextFileName('fileio_lstat_is_socket_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileio.lstatSync(fpath); + expect(isBoolean(stat.isSocket())).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_lstat_is_socket_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LSTAT_IS_SOCKET_0010 + * @tc.name fileio_lstat_is_socket_001 + * @tc.desc Test Lstat.isSocket() interface. + * This interface shall not treat a file as a socket. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_lstat_is_socket_001', 0, async function () { + let fpath = await nextFileName('fileio_lstat_is_socket_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileio.lstatSync(fpath); + expect(stat.isSocket() === false).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_lstat_is_socket_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LSTAT_IS_SOCKET_0020 + * @tc.name fileio_test_lstat_is_socket_002 + * @tc.desc Test Lstat.isSocket() interface. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_lstat_is_socket_002', 0, async function () { + let fpath = await nextFileName('fileio_test_lstat_is_socket_002'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileio.lstatSync(fpath); + expect(stat.isSocket(-1) === false).assertTrue(); + expect(null).assertFail(); + } catch (e) { + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LSTAT_IS_SYMBOLIC_LINK_0000 + * @tc.name fileio_lstat_is_symbolic_link_000 + * @tc.desc Test Lstat.isSymbolicLink() interface. + * This interface shall return a boolean variable. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_lstat_is_symbolic_link_000', 0, async function () { + let fpath = await nextFileName('fileio_lstat_is_symbolic_link_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileio.lstatSync(fpath); + expect(isBoolean(stat.isSymbolicLink())).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_lstat_is_symbolic_link_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LSTAT_IS_SYMBOLIC_LINK_0010 + * @tc.name fileio_lstat_is_symbolic_link_001 + * @tc.desc Test Lstat.isSymbolicLink() interface. + * This interface shall not treat a normal file as a symbolic link. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_lstat_is_symbolic_link_001', 0, async function () { + let fpath = await nextFileName('fileio_lstat_is_symbolic_link_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileio.lstatSync(fpath); + expect(stat.isSymbolicLink() === false).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_lstat_is_symbolic_link_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LSTAT_IS_SYMBOLIC_LINK_0020 + * @tc.name fileio_test_lstat_is_symbolic_link_002 + * @tc.desc Test Lstat.isSymbolicLink() interface. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_lstat_is_symbolic_link_002', 0, async function () { + let fpath = await nextFileName('fileio_test_lstat_is_symbolic_link_002'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileio.lstatSync(fpath); + expect(stat.isSymbolicLink(-1) === false).assertTrue(); + expect(null).assertFail(); + } catch (e) { + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LSTAT_ASYNC_0000 + * @tc.name fileio_lstat_async_000 + * @tc.desc Test Stat.lstatAsync() interface. + * This interface shall work properly in normal case when providing the promise async model. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_lstat_async_000', 0, async function (done) { + let fpath = await nextFileName('fileio_lstat_async_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + fileio.lstat(fpath).then((stat) => { + expect(stat !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + }); + done(); + } catch (e) { + console.log('fileio_lstat_async_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LSTAT_ASYNC_0010 + * @tc.name fileio_lstat_async_001 + * @tc.desc Test Stat.lstatAsync() interface. + * This interface shall work properly in normal case when providing the callback async model. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_lstat_async_001', 0, async function (done) { + let fpath = await nextFileName('fileio_lstat_async_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + fileio.lstat(fpath, function (error) { + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + }); + } catch (e) { + console.log('fileio_lstat_async_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LSTAT_ASYNC_0020 + * @tc.name fileio_lstat_async_002 + * @tc.desc Test Stat.lstatAsync() interface. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_lstat_async_002', 0, async function (done) { + let fpath = await nextFileName('fileio_lstat_async_002'); + + try { + fileio.lstat(fpath, function (err) { + done(); + }); + } catch (e) { + console.log('fileio_lstat_async_002 has failed for ' + e); + expect(!!e).assertTrue(); + done(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LSTAT_ASYNC_DEV_0000 + * @tc.name fileio_lstat_async_dev_000 + * @tc.desc Test the dev member of class Lstat. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_lstat_async_dev_000', 0, async function (done) { + let fpath = await nextFileName('fileio_lstat_async_dev_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = await fileio.lstat(fpath); + expect(isIntNum(stat.dev)).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_lstat_async_dev_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LSTAT_ASYNC_INO_0000 + * @tc.name fileio_lstat_async_ino_000 + * @tc.desc Test the ino member of class Lstat. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_lstat_async_ino_000', 0, async function (done) { + let fpath = await nextFileName('fileio_lstat_async_ino_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = await fileio.lstat(fpath); + expect(isBigInt(stat.ino)).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_lstat_async_ino_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LSTAT_ASYNC_MODE_0000 + * @tc.name fileio_lstat_async_mode_000 + * @tc.desc Test the mode member of class Lstat. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_lstat_async_mode_000', 0, async function (done) { + let fpath = await nextFileName('fileio_lstat_async_mode_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = await fileio.lstat(fpath); + expect(isIntNum(stat.mode)).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_lstat_async_mode_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LSTAT_ASYNC_NLINK_0000 + * @tc.name fileio_lstat_async_nlink_000 + * @tc.desc Test the nlink member of class Lstat. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_lstat_async_nlink_000', 0, async function (done) { + let fpath = await nextFileName('fileio_lstat_async_nlink_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = await fileio.lstat(fpath); + expect(isIntNum(stat.nlink)).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_lstat_async_nlink_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LSTAT_ASYNC_UID_0000 + * @tc.name fileio_lstat_async_uid_000 + * @tc.desc Test the uid member of class Lstat. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_lstat_async_uid_000', 0, async function (done) { + let fpath = await nextFileName('fileio_lstat_async_uid_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = await fileio.lstat(fpath); + expect(isIntNum(stat.uid)).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_lstat_async_uid_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LSTAT_ASYNC_GID_0000 + * @tc.name fileio_lstat_async_gid_000 + * @tc.desc Test the gid member of class Lstat. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_lstat_async_gid_000', 0, async function (done) { + let fpath = await nextFileName('fileio_lstat_async_gid_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = await fileio.lstat(fpath); + expect(isIntNum(stat.gid)).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_lstat_async_gid_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LSTAT_ASYNC_RDEV_0000 + * @tc.name fileio_lstat_async_rdev_000 + * @tc.desc Test the rdev member of class Lstat. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_lstat_async_rdev_000', 0, async function (done) { + let fpath = await nextFileName('fileio_lstat_async_rdev_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = await fileio.lstat(fpath); + expect(isIntNum(stat.rdev)).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_lstat_async_rdev_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LSTAT_ASYNC_SIZE_0000 + * @tc.name fileio_lstat_async_size_000 + * @tc.desc Test the size member of class lstat. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_lstat_async_size_000', 0, async function (done) { + let fpath = await nextFileName('fileio_lstat_async_size_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = await fileio.lstat(fpath); + expect(isIntNum(stat.size)).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_lstat_async_size_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LSTAT_ASYNC_BLOCKS_0000 + * @tc.name fileio_lstat_async_blocks_000 + * @tc.desc Test lstat.blocks() interface. + * @tc.desc Test the blocks member of class lstat. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_lstat_async_blocks_000', 0, async function (done) { + let fpath = await nextFileName('fileio_lstat_async_blocks_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = await fileio.lstat(fpath); + expect(isIntNum(stat.blocks)).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_lstat_async_blocks_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LSTAT_ASYNC_ATIME_0000 + * @tc.name fileio_lstat_async_atime_000 + * @tc.desc Test lstat.atime() interface. + * @tc.desc Test the atime member of class lstat. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_lstat_async_atime_000', 0, async function (done) { + let fpath = await nextFileName('fileio_lstat_async_atime_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = await fileio.lstat(fpath); + expect(isIntNum(stat.atime)).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_lstat_async_atime_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LSTAT_ASYNC_MTIME_0000 + * @tc.name fileio_lstat_async_mtime_000 + * @tc.desc Test lstat.mtime() interface. + * @tc.desc Test the mtime member of class lstat. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_lstat_async_mtime_000', 0, async function (done) { + let fpath = await nextFileName('fileio_lstat_async_mtime_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = await fileio.lstat(fpath); + expect(isIntNum(stat.mtime)).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_lstat_async_mtime_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LSTAT_ASYNC_CTIME_0000 + * @tc.name fileio_lstat_async_ctime_000 + * @tc.desc Test the ctime member of class lstat. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_lstat_async_ctime_000', 0, async function (done) { + let fpath = await nextFileName('fileio_lstat_async_ctime_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = await fileio.lstat(fpath); + expect(isIntNum(stat.ctime)).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_lstat_async_ctime_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LSTAT_ASYNC_IS_BLOCK_DEVICE_0000 + * @tc.name fileio_lstat_async_is_block_device_000 + * @tc.desc Test the isBlockDevice method of class lstat. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_lstat_async_is_block_device_000', 0, async function (done) { + let fpath = await nextFileName('fileio_lstat_async_is_block_device_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = await fileio.lstat(fpath); + expect(isBoolean(stat.isBlockDevice())).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_lstat_async_is_block_device_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LSTAT_ASYNC_IS_BLOCK_DEVICE_0010 + * @tc.name fileio_lstat_async_is_block_device_001 + * @tc.desc Test the isBlockDevice method of class lstat. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_lstat_async_is_block_device_001', 0, async function (done) { + let fpath = await nextFileName('fileio_lstat_async_is_block_device_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = await fileio.lstat(fpath); + expect(stat.isBlockDevice() === false).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_lstat_async_is_block_device_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LSTAT_ASYNC_IS_CHARACTER_DEVICE_0000 + * @tc.name fileio_lstat_async_is_character_device_000 + * @tc.desc Test the isCharacterDevice method of class lstat. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_lstat_async_is_character_device_000', 0, async function (done) { + let fpath = await nextFileName('fileio_lstat_async_is_character_device_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = await fileio.lstat(fpath); + expect(isBoolean(stat.isCharacterDevice())).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_lstat_async_is_character_device_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LSTAT_ASYNC_IS_CHARACTER_DEVICE_0010 + * @tc.name fileio_lstat_async_is_character_device_001 + * @tc.desc Test the isCharacterDevice method of class lstat. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_lstat_async_is_character_device_001', 0, async function (done) { + let fpath = await nextFileName('fileio_lstat_async_is_character_device_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = await fileio.lstat(fpath); + expect(stat.isCharacterDevice() === false).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_lstat_async_is_character_device_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LSTAT_ASYNC_IS_DIRECTORY_0000 + * @tc.name fileio_lstat_async_is_directory_000 + * @tc.desc Test lstat.isDirectory() interface. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_lstat_async_is_directory_000', 0, async function (done) { + let fpath = await nextFileName('fileio_lstat_async_is_directory_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = await fileio.lstat(fpath); + expect(isBoolean(stat.isDirectory())).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_lstat_async_is_directory_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LSTAT_ASYNC_IS_DIRECTORY_0010 + * @tc.name fileio_lstat_async_is_directory_001 + * @tc.desc Test lstat.isDirectory() interface. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_lstat_async_is_directory_001', 0, async function (done) { + let fpath = await nextFileName('fileio_lstat_async_is_directory_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = await fileio.lstat(fpath); + expect(stat.isDirectory() === false).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_lstat_async_is_directory_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LSTAT_ASYNC_IS_DIRECTORY_0020 + * @tc.name fileio_lstat_async_is_directory_002 + * @tc.desc Test lstat.isDirectory() interface. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_lstat_async_is_directory_002', 0, async function (done) { + let dpath = await nextFileName('fileio_lstat_async_is_directory_002') + 'd'; + + try { + expect(fileio.mkdirSync(dpath) == null).assertTrue(); + let stat = await fileio.lstat(dpath); + expect(stat.isDirectory()).assertTrue(); + expect(fileio.rmdirSync(dpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_lstat_async_is_directory_002 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LSTAT_ASYNC_IS_FIFO_0000 + * @tc.name fileio_lstat_async_is_fifo_000 + * @tc.desc Test lstat.isFIFO() interface. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_lstat_async_is_fifo_000', 0, async function (done) { + let fpath = await nextFileName('fileio_lstat_async_is_fifo_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = await fileio.lstat(fpath); + expect(isBoolean(stat.isFIFO())).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_lstat_async_is_fifo_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LSTAT_ASYNC_IS_FIFO_0010 + * @tc.name fileio_lstat_async_is_fifo_001 + * @tc.desc Test lstat.isFIFO() interface. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_lstat_async_is_fifo_001', 0, async function (done) { + let fpath = await nextFileName('fileio_lstat_async_is_fifo_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = await fileio.lstat(fpath); + expect(stat.isFIFO() === false).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_lstat_async_is_fifo_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LSTAT_ASYNC_IS_FILE_0000 + * @tc.name fileio_lstat_async_is_file_000 + * @tc.desc Test lstat.isFile() interface. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_lstat_async_is_file_000', 0, async function (done) { + let fpath = await nextFileName('fileio_lstat_async_is_file_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = await fileio.lstat(fpath); + expect(isBoolean(stat.isFile())).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_lstat_async_is_file_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LSTAT_ASYNC_IS_FILE_0010 + * @tc.name fileio_lstat_async_is_file_001 + * @tc.desc Test lstat.isFile() interface. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_lstat_async_is_file_001', 0, async function (done) { + let fpath = await nextFileName('fileio_lstat_async_is_file_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = await fileio.lstat(fpath); + expect(stat.isFile()).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_lstat_async_is_file_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LSTAT_ASYNC_IS_FILE_0020 + * @tc.name fileio_lstat_async_is_file_002 + * @tc.desc Test lstat.isFile() interface. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_lstat_async_is_file_002', 0, async function (done) { + let dpath = await nextFileName('fileio_lstat_async_is_file_002'); + + try { + expect(fileio.mkdirSync(dpath) == null).assertTrue(); + let stat = await fileio.lstat(dpath); + expect(stat.isFile() === false).assertTrue(); + expect(fileio.rmdirSync(dpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_lstat_async_is_file_002 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LSTAT_ASYNC_IS_SOCKET_0000 + * @tc.name fileio_lstat_async_is_socket_000 + * @tc.desc Test lstat.isSocket() interface. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_lstat_async_is_socket_000', 0, async function (done) { + let fpath = await nextFileName('fileio_lstat_async_is_socket_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = await fileio.lstat(fpath); + expect(isBoolean(stat.isSocket())).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_lstat_async_is_socket_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LSTAT_ASYNC_IS_SOCKET_0010 + * @tc.name fileio_lstat_async_is_socket_001 + * @tc.desc Test lstat.isSocket() interface. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_lstat_async_is_socket_001', 0, async function (done) { + let fpath = await nextFileName('fileio_lstat_async_is_socket_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = await fileio.lstat(fpath); + expect(stat.isSocket() === false).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_lstat_async_is_socket_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LSTAT_ASYNC_IS_SYMBOLIC_LINK_0000 + * @tc.name fileio_lstat_async_is_symbolic_link_000 + * @tc.desc Test lstat.isSymbolicLink() interface. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_lstat_async_is_symbolic_link_000', 0, async function (done) { + let fpath = await nextFileName('fileio_lstat_async_is_symbolic_link_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = await fileio.lstat(fpath); + expect(isBoolean(stat.isSymbolicLink())).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_lstat_async_is_symbolic_link_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LSTAT_ASYNC_IS_SYMBOLIC_LINK_0010 + * @tc.name fileio_lstat_async_is_symbolic_link_001 + * @tc.desc Test lstat.isSymbolicLink() interface. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_lstat_async_is_symbolic_link_001', 0, async function (done) { + let fpath = await nextFileName('fileio_lstat_async_is_symbolic_link_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = await fileio.lstat(fpath); + expect(stat.isSymbolicLink() === false).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_lstat_async_is_symbolic_link_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_APPEND_FILE_SYNC_0010 + * @tc.name fileio_test_append_file_sync_000 + * @tc.desc Test lstat.lstatSync() interface. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_append_file_sync_000', 0, async function (done) { + let fpath = await nextFileName('fileio_test_append_file_sync_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileio.lstatSync(fpath); + expect(isIntNum(stat.size)).assertTrue(); + + let fd = fileio.openSync(fpath, 0o2002); + expect(isIntNum(fd)).assertTrue(); + + expect(fileio.writeSync(fd, FILE_CONTENT) == FILE_CONTENT.length).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + + stat = fileio.lstatSync(fpath); + expect(stat.size == FILE_CONTENT.length * 2).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_test_append_file_sync_000 has failed for ' + e); + expect(null).assertFail(); + } + done(); + }); +});} diff --git a/storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/members/mkdir_rmdir.test.js b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/mkdir_rmdir.test.js similarity index 96% rename from storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/members/mkdir_rmdir.test.js rename to storage/storagefileiojstest/src/main/js/test/module_fileio/members/mkdir_rmdir.test.js index 76d3e4f2e3c8834fa05f3f4a8dc49fb8d11e8988..04f56203c007b10b8b6409dd77abe74f76308802 100644 --- a/storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/members/mkdir_rmdir.test.js +++ b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/mkdir_rmdir.test.js @@ -1,258 +1,258 @@ -/* - * Copyright (C) 2023 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 { fileio, nextFileName, describe, it, expect } from '../../Common'; - -export default function fileioMkdirRmdir() { -describe('fileio_mkdir_rmdir', function () { - - /** - * @tc.number SUB_DF_FILEIO_MKDIR_SYNC_RMDIR_SYNC_0000 - * @tc.name fileio_mkdir_sync_rmdir_sync_000 - * @tc.desc Test mkdirSync() and rmdirSync() interfaces. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_mkdir_sync_rmdir_sync_000', 0, async function () { - let dpath = await nextFileName('fileio_mkdir_sync_rmdir_sync_000') + 'd'; - - try { - expect(fileio.mkdirSync(dpath) == null).assertTrue(); - expect(fileio.rmdirSync(dpath) == null).assertTrue(); - } catch (e) { - console.log('fileio_mkdir_sync_rmdir_sync_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_MKDIR_SYNC_RMDIR_SYNC_0100 - * @tc.name fileio_mkdir_sync_rmdir_sync_001 - * @tc.desc Test mkdirSync() interfaces. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_mkdir_sync_rmdir_sync_001', 0, function () { - try { - expect(fileio.mkdirSync('/') == null).assertTrue(); - expect(null).assertFail(); - } catch (e) { - console.log('fileio_mkdir_sync_rmdir_sync_001 has failed for ' + e); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_MKDIR_SYNC_RMDIR_SYNC_0200 - * @tc.name fileio_mkdir_sync_rmdir_sync_002 - * @tc.desc Test mkdirSync() interfaces. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_mkdir_sync_rmdir_sync_002', 0, function () { - try { - expect(fileio.mkdirSync(12) == null).assertTrue(); - expect(null).assertFail(); - } catch (e) { - console.log('fileio_mkdir_sync_rmdir_sync_002 has failed for ' + e); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_MKDIR_SYNC_RMDIR_SYNC_0300 - * @tc.name fileio_mkdir_sync_rmdir_sync_003 - * @tc.desc Test mkdirSync() interfaces. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_mkdir_sync_rmdir_sync_003', 0, async function () { - let dpath = await nextFileName('fileio_mkdir_sync_rmdir_sync_003'); - - try { - fileio.mkdirSync(dpath, undefined); - fileio.rmdirSync(dpath); - } catch (e) { - console.log('fileio_mkdir_sync_rmdir_sync_003 has failed for ' + e); - expect(false).assertTrue(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_MKDIR_ASYNC_RMDIR_SYNC_0000 - * @tc.name fileio_mkdir_async_rmdir_sync_000 - * @tc.desc Test mkdir() and rmdirSync() interfaces. Promise. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_mkdir_async_rmdir_sync_000', 0, async function (done) { - let dpath = await nextFileName('fileio_mkdir_async_rmdir_sync_000') + 'd'; - - try { - expect(await fileio.mkdir(dpath) == null).assertTrue(); - expect(fileio.rmdirSync(dpath) == null).assertTrue(); - done(); - } catch (e) { - console.log('fileio_mkdir_async_rmdir_sync_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_MKDIR_ASYNC_RMDIR_SYNC_0100 - * @tc.name fileio_mkdir_async_rmdir_sync_001 - * @tc.desc Test mkdir() and rmdirSync() interfaces. Callback. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_mkdir_async_rmdir_sync_001', 0, async function (done) { - let dpath = await nextFileName('fileio_mkdir_async_rmdir_sync_001') + 'd'; - - try { - fileio.mkdir(dpath, function (error) { - expect(fileio.rmdirSync(dpath) == null).assertTrue(); - done(); - }); - } catch (e) { - console.log('fileio_mkdir_async_rmdir_sync_001 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_MKDIR_ASYNC_RMDIR_SYNC_0200 - * @tc.name fileio_mkdir_async_rmdir_sync_002 - * @tc.desc Test mkdir() and rmdirSync() interfaces. Promise. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_mkdir_async_rmdir_sync_002', 0, async function (done) { - let fpath = await nextFileName('fileio_mkdir_async_rmdir_sync_002'); - - try { - expect(await fileio.mkdir(fpath, 777) == null).assertTrue(); - expect(fileio.rmdirSync(fpath) == null).assertTrue(); - done(); - } catch (e) { - console.log('fileio_mkdir_async_rmdir_sync_002 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_MKDIR_ASYNC_RMDIR_SYNC_0300 - * @tc.name fileio_mkdir_async_rmdir_sync_003 - * @tc.desc Test mkdir() and rmdirSync() interfaces. Promise. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_mkdir_async_rmdir_sync_003', 0, async function (done) { - let fpath = await nextFileName('fileio_mkdir_async_rmdir_sync_003'); - - try { - expect(await fileio.mkdir(fpath, 400) == null).assertTrue(); - expect(fileio.rmdirSync(fpath) == null).assertTrue(); - done(); - } catch (e) { - console.log('fileio_mkdir_async_rmdir_sync_003 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_MKDIR_ASYNC_RMDIR_SYNC_0400 - * @tc.name fileio_mkdir_async_rmdir_sync_004 - * @tc.desc Test mkdir() and interfaces. Promise. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_mkdir_async_rmdir_sync_004', 0, async function (done) { - try { - expect(await fileio.mkdir(12) == null).assertTrue(); - expect(null).assertFail(); - } catch (e) { - console.log('fileio_mkdir_async_rmdir_sync_004 has failed for ' + e); - done(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_MKDIR_ASYNC_RMDIR_SYNC_0500 - * @tc.name fileio_mkdir_async_rmdir_sync_005 - * @tc.desc Test mkdir() interfaces. Promise. - * Undefined option arguments, use default options. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_mkdir_async_rmdir_sync_005', 0, async function (done) { - let dpath = await nextFileName('fileio_mkdir_async_rmdir_sync_005'); - - try { - await fileio.mkdir(dpath, undefined); - fileio.rmdirSync(dpath); - done(); - } catch (e) { - console.log('fileio_mkdir_async_rmdir_sync_005 has failed for ' + e); - expect(false).assertTrue(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_MKDIR_ASYNC_RMDIR_SYNC_0600 - * @tc.name fileio_mkdir_async_rmdir_sync_006 - * @tc.desc Test mkdir() interfaces. Callback. - * Undefined option arguments, use default options. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_mkdir_async_rmdir_sync_006', 0, async function (done) { - let dpath = await nextFileName('fileio_mkdir_async_rmdir_sync_006'); - - try { - fileio.mkdir(dpath, undefined, (err) => { - if (err) { - console.log('fileio_mkdir_async_rmdir_sync_006 error: ' + e); - expect(false).assertTrue(); - } - fileio.rmdirSync(dpath); - done(); - }); - } catch (e) { - console.log('fileio_mkdir_async_rmdir_sync_006 has failed for ' + e); - expect(false).assertTrue(); - } - }); -}); -} +/* + * Copyright (C) 2021 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 { fileio, nextFileName, describe, it, expect } from '../../Common'; + +export default function fileioMkdirRmdir() { +describe('fileio_mkdir_rmdir', function () { + + /** + * @tc.number SUB_DF_FILEIO_MKDIR_SYNC_RMDIR_SYNC_0000 + * @tc.name fileio_mkdir_sync_rmdir_sync_000 + * @tc.desc Test mkdirSync() and rmdirSync() interfaces. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_mkdir_sync_rmdir_sync_000', 0, async function () { + let dpath = await nextFileName('fileio_mkdir_sync_rmdir_sync_000') + 'd'; + + try { + expect(fileio.mkdirSync(dpath) == null).assertTrue(); + expect(fileio.rmdirSync(dpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_mkdir_sync_rmdir_sync_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_MKDIR_SYNC_RMDIR_SYNC_0100 + * @tc.name fileio_mkdir_sync_rmdir_sync_001 + * @tc.desc Test mkdirSync() interfaces. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_mkdir_sync_rmdir_sync_001', 0, function () { + try { + expect(fileio.mkdirSync('/') == null).assertTrue(); + expect(null).assertFail(); + } catch (e) { + console.log('fileio_mkdir_sync_rmdir_sync_001 has failed for ' + e); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_MKDIR_SYNC_RMDIR_SYNC_0200 + * @tc.name fileio_mkdir_sync_rmdir_sync_002 + * @tc.desc Test mkdirSync() interfaces. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_mkdir_sync_rmdir_sync_002', 0, function () { + try { + expect(fileio.mkdirSync(12) == null).assertTrue(); + expect(null).assertFail(); + } catch (e) { + console.log('fileio_mkdir_sync_rmdir_sync_002 has failed for ' + e); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_MKDIR_SYNC_RMDIR_SYNC_0300 + * @tc.name fileio_mkdir_sync_rmdir_sync_003 + * @tc.desc Test mkdirSync() interfaces. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_mkdir_sync_rmdir_sync_003', 0, async function () { + let dpath = await nextFileName('fileio_mkdir_sync_rmdir_sync_003'); + + try { + fileio.mkdirSync(dpath, undefined); + fileio.rmdirSync(dpath); + } catch (e) { + console.log('fileio_mkdir_sync_rmdir_sync_003 has failed for ' + e); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_MKDIR_ASYNC_RMDIR_SYNC_0000 + * @tc.name fileio_mkdir_async_rmdir_sync_000 + * @tc.desc Test mkdir() and rmdirSync() interfaces. Promise. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_mkdir_async_rmdir_sync_000', 0, async function (done) { + let dpath = await nextFileName('fileio_mkdir_async_rmdir_sync_000') + 'd'; + + try { + expect(await fileio.mkdir(dpath) == null).assertTrue(); + expect(fileio.rmdirSync(dpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_mkdir_async_rmdir_sync_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_MKDIR_ASYNC_RMDIR_SYNC_0100 + * @tc.name fileio_mkdir_async_rmdir_sync_001 + * @tc.desc Test mkdir() and rmdirSync() interfaces. Callback. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_mkdir_async_rmdir_sync_001', 0, async function (done) { + let dpath = await nextFileName('fileio_mkdir_async_rmdir_sync_001') + 'd'; + + try { + fileio.mkdir(dpath, function (error) { + expect(fileio.rmdirSync(dpath) == null).assertTrue(); + done(); + }); + } catch (e) { + console.log('fileio_mkdir_async_rmdir_sync_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_MKDIR_ASYNC_RMDIR_SYNC_0200 + * @tc.name fileio_mkdir_async_rmdir_sync_002 + * @tc.desc Test mkdir() and rmdirSync() interfaces. Promise. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_mkdir_async_rmdir_sync_002', 0, async function (done) { + let fpath = await nextFileName('fileio_mkdir_async_rmdir_sync_002'); + + try { + expect(await fileio.mkdir(fpath, 777) == null).assertTrue(); + expect(fileio.rmdirSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_mkdir_async_rmdir_sync_002 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_MKDIR_ASYNC_RMDIR_SYNC_0300 + * @tc.name fileio_mkdir_async_rmdir_sync_003 + * @tc.desc Test mkdir() and rmdirSync() interfaces. Promise. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_mkdir_async_rmdir_sync_003', 0, async function (done) { + let fpath = await nextFileName('fileio_mkdir_async_rmdir_sync_003'); + + try { + expect(await fileio.mkdir(fpath, 400) == null).assertTrue(); + expect(fileio.rmdirSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_mkdir_async_rmdir_sync_003 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_MKDIR_ASYNC_RMDIR_SYNC_0400 + * @tc.name fileio_mkdir_async_rmdir_sync_004 + * @tc.desc Test mkdir() and interfaces. Promise. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_mkdir_async_rmdir_sync_004', 0, async function (done) { + try { + expect(await fileio.mkdir(12) == null).assertTrue(); + expect(null).assertFail(); + } catch (e) { + console.log('fileio_mkdir_async_rmdir_sync_004 has failed for ' + e); + done(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_MKDIR_ASYNC_RMDIR_SYNC_0500 + * @tc.name fileio_mkdir_async_rmdir_sync_005 + * @tc.desc Test mkdir() interfaces. Promise. + * Undefined option arguments, use default options. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_mkdir_async_rmdir_sync_005', 0, async function (done) { + let dpath = await nextFileName('fileio_mkdir_async_rmdir_sync_005'); + + try { + await fileio.mkdir(dpath, undefined); + fileio.rmdirSync(dpath); + done(); + } catch (e) { + console.log('fileio_mkdir_async_rmdir_sync_005 has failed for ' + e); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_MKDIR_ASYNC_RMDIR_SYNC_0600 + * @tc.name fileio_mkdir_async_rmdir_sync_006 + * @tc.desc Test mkdir() interfaces. Callback. + * Undefined option arguments, use default options. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_mkdir_async_rmdir_sync_006', 0, async function (done) { + let dpath = await nextFileName('fileio_mkdir_async_rmdir_sync_006'); + + try { + fileio.mkdir(dpath, undefined, (err) => { + if (err) { + console.log('fileio_mkdir_async_rmdir_sync_006 error: ' + e); + expect(false).assertTrue(); + } + fileio.rmdirSync(dpath); + done(); + }); + } catch (e) { + console.log('fileio_mkdir_async_rmdir_sync_006 has failed for ' + e); + expect(false).assertTrue(); + } + }); +}); +} diff --git a/storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/members/mkdtemp.test.js b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/mkdtemp.test.js similarity index 95% rename from storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/members/mkdtemp.test.js rename to storage/storagefileiojstest/src/main/js/test/module_fileio/members/mkdtemp.test.js index 7d13183657a045f8248ed41c8301ac8c5fa9d925..2bddb858e4e6c123af479db7343706b8862ca988 100644 --- a/storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/members/mkdtemp.test.js +++ b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/mkdtemp.test.js @@ -1,109 +1,109 @@ -/* - * Copyright (C) 2023 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 { fileio, nextFileName, describe, it, expect } from '../../Common'; - -export default function fileioMkdtemp() { -describe('fileio_mkdtemp', function () { - - /** - * @tc.number SUB_DF_FILEIO_MKDTEMP_SYNC_0000 - * @tc.name fileio_test_mkdtemp_sync_000 - * @tc.desc Test mkdtempSync() interface. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_mkdtemp_sync_000', 0, async function () { - let dpath = await nextFileName('fileio_test_mkdtemp_sync_000'); - dpath = dpath + 'XXXX'; - - try { - let res = fileio.mkdtempSync(dpath); - expect(null).assertFail(); - } catch (e) { - console.log('fileio_test_mkdtemp_sync_000 has failed for ' + e); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_MKDTEMP_SYNC_0010 - * @tc.name fileio_test_mkdtemp_sync_001 - * @tc.desc Test mkdtempSync() interface. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_mkdtemp_sync_001', 0, async function () { - let dpath = await nextFileName('fileio_test_mkdtemp_sync_001'); - dpath = dpath + 'XXXXXX'; - - try { - let res = fileio.mkdtempSync(dpath); - expect(fileio.rmdirSync(res) == null).assertTrue(); - } catch (e) { - console.log('fileio_test_mkdtemp_sync_001 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_MKDTEMP_ASYNC_0000 - * @tc.name fileio_test_mkdtemp_async_000 - * @tc.desc Test mkdtempASync() interface. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_mkdtemp_async_000', 0, async function (done) { - let dpath = await nextFileName('fileio_test_mkdtemp_async_000'); - dpath = dpath + 'XXXXXX'; - try { - let res = await fileio.mkdtemp(dpath); - expect(fileio.rmdirSync(res) == null).assertTrue(); - done(); - } catch (e) { - console.log('fileio_test_mkdtemp_async_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_MKDTEMP_ASYNC_0010 - * @tc.name fileio_test_mkdtemp_async_001 - * @tc.desc Test mkdtempASync() interface. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_mkdtemp_async_001', 0, async function (done) { - let dpath = await nextFileName('fileio_test_mkdtemp_async_001'); - dpath = dpath + 'XXXXXX'; - - try { - fileio.mkdtemp(dpath, function (err, res) { - expect(fileio.rmdirSync(res) == null).assertTrue(); - done(); - }); - } catch (e) { - console.log('fileio_test_mkdtemp_async_001 has failed for ' + e); - expect(null).assertFail(); - } - }); -});} +/* + * Copyright (C) 2021 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 { fileio, nextFileName, describe, it, expect } from '../../Common'; + +export default function fileioMkdtemp() { +describe('fileio_mkdtemp', function () { + + /** + * @tc.number SUB_DF_FILEIO_MKDTEMP_SYNC_0000 + * @tc.name fileio_test_mkdtemp_sync_000 + * @tc.desc Test mkdtempSync() interface. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_mkdtemp_sync_000', 0, async function () { + let dpath = await nextFileName('fileio_test_mkdtemp_sync_000'); + dpath = dpath + 'XXXX'; + + try { + let res = fileio.mkdtempSync(dpath); + expect(null).assertFail(); + } catch (e) { + console.log('fileio_test_mkdtemp_sync_000 has failed for ' + e); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_MKDTEMP_SYNC_0010 + * @tc.name fileio_test_mkdtemp_sync_001 + * @tc.desc Test mkdtempSync() interface. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_mkdtemp_sync_001', 0, async function () { + let dpath = await nextFileName('fileio_test_mkdtemp_sync_001'); + dpath = dpath + 'XXXXXX'; + + try { + let res = fileio.mkdtempSync(dpath); + expect(fileio.rmdirSync(res) == null).assertTrue(); + } catch (e) { + console.log('fileio_test_mkdtemp_sync_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_MKDTEMP_ASYNC_0000 + * @tc.name fileio_test_mkdtemp_async_000 + * @tc.desc Test mkdtempASync() interface. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_mkdtemp_async_000', 0, async function (done) { + let dpath = await nextFileName('fileio_test_mkdtemp_async_000'); + dpath = dpath + 'XXXXXX'; + try { + let res = await fileio.mkdtemp(dpath); + expect(fileio.rmdirSync(res) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_test_mkdtemp_async_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_MKDTEMP_ASYNC_0010 + * @tc.name fileio_test_mkdtemp_async_001 + * @tc.desc Test mkdtempASync() interface. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_mkdtemp_async_001', 0, async function (done) { + let dpath = await nextFileName('fileio_test_mkdtemp_async_001'); + dpath = dpath + 'XXXXXX'; + + try { + fileio.mkdtemp(dpath, function (err, res) { + expect(fileio.rmdirSync(res) == null).assertTrue(); + done(); + }); + } catch (e) { + console.log('fileio_test_mkdtemp_async_001 has failed for ' + e); + expect(null).assertFail(); + } + }); +});} diff --git a/storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/members/open.test.js b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/open.test.js similarity index 96% rename from storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/members/open.test.js rename to storage/storagefileiojstest/src/main/js/test/module_fileio/members/open.test.js index 6eeb205bbb1cb86c51287dd87e5d20df95a79875..d294ff8ddff21fb7f465526afbb8fb9a5478ffb7 100644 --- a/storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/members/open.test.js +++ b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/open.test.js @@ -1,408 +1,408 @@ -/* - * Copyright (C) 2023 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 { - fileio, FILE_CONTENT, prepareFile, nextFileName, isIntNum, - describe, it, expect, -} from '../../Common'; - -export default function fileioOpen() { -describe('fileio_open', function () { - - /** - * @tc.number SUB_DF_FILEIO_OPEN_SYNC_0000 - * @tc.name fileio_test_open_sync_000 - * @tc.desc Test openSync() interfaces. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_open_sync_000', 0, function () { - try { - fileio.openSync('/', 0o102, 0o666); - expect(null).assertFail(); - } catch (e) { - console.log('fileio_test_open_sync_000 has failed for ' + e); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_OPEN_ASYNC_0000 - * @tc.name fileio_test_open_async_000 - * @tc.desc Test openASync() interfaces. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_open_async_000', 0, async function (done) { - let fpath = await nextFileName('fileio_test_open_async_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - await fileio.access(fpath).then(function (err) { - fileio.open(fpath, 0, 0o0400, function (err, fd) { - fileio.read(fd, new ArrayBuffer(4096)) - .then(function (res) { - expect(res.bytesRead == FILE_CONTENT.length).assertTrue(); - fileio.closeSync(fd); - fileio.unlinkSync(fpath); - done(); - }); - }); - }); - } catch (e) { - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_OPEN_ASYNC_0100 - * @tc.name fileio_test_open_async_001 - * @tc.desc Test openASync() interfaces. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_open_async_001', 0, async function (done) { - let fpath = await nextFileName('fileio_test_open_async_001'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - await fileio.open(fpath, 0, 0o0400, function (err, fd) { - fileio.read(fd, new ArrayBuffer(4096)) - .then(function (res) { - expect(res.bytesRead == FILE_CONTENT.length).assertTrue(); - fileio.closeSync(fd); - fileio.unlinkSync(fpath); - done(); - }); - }); - } catch (e) { - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_OPEN_ASYNC_0200 - * @tc.name fileio_test_open_async_002 - * @tc.desc Test openASync() interfaces. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_open_async_002', 0, async function (done) { - let fpath = await nextFileName('fileio_test_open_async_002'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - await fileio.open(fpath, 0, function (err, fd) { - fileio.read(fd, new ArrayBuffer(4096)) - .then(function (res) { - expect(res.bytesRead == FILE_CONTENT.length).assertTrue(); - fileio.closeSync(fd); - fileio.unlinkSync(fpath); - done(); - }); - }); - } catch (e) { - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_OPEN_ASYNC_0300 - * @tc.name fileio_test_open_async_003 - * @tc.desc Test openASync() interfaces. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_open_async_003', 0, async function (done) { - let fpath = await nextFileName('fileio_test_open_async_003'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - fileio.open(fpath, 0o2, function (err, fd) { - fileio.read(fd, new ArrayBuffer(4096)) - .then(function (res) { - expect(res.bytesRead == FILE_CONTENT.length).assertTrue(); - fileio.closeSync(fd); - fileio.unlinkSync(fpath); - done(); - }); - }); - } catch (e) { - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_OPEN_ASYNC_0400 - * @tc.name fileio_test_open_async_004 - * @tc.desc Test openASync() interfaces. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_open_async_004', 0, async function (done) { - let fpath = await nextFileName('fileio_test_open_async_004'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - await fileio.open(fpath) - .then(function (fd) { - fileio.read(fd, new ArrayBuffer(4096)) - .then(function (res) { - expect(res.bytesRead == FILE_CONTENT.length).assertTrue(); - fileio.closeSync(fd); - fileio.unlinkSync(fpath); - }); - }) - .catch(function (err) { - expect(err == null).assertTrue(); - }) - done(); - } catch (e) { - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_OPEN_ASYNC_0500 - * @tc.name fileio_test_open_async_005 - * @tc.desc Test openASync() interfaces. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_open_async_005', 0, async function (done) { - let fpath = await nextFileName('fileio_test_open_async_005'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - await fileio.open(fpath, 0o0) - .then(function (fd) { - fileio.read(fd, new ArrayBuffer(4096)) - .then(function (res) { - expect(res.bytesRead == FILE_CONTENT.length).assertTrue(); - fileio.closeSync(fd); - fileio.unlinkSync(fpath); - }) - }) - .catch(function (err) { - expect(err == null).assertTrue(); - }) - done(); - } catch (e) { - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_OPEN_ASYNC_0600 - * @tc.name fileio_test_open_async_006 - * @tc.desc Test openASync() interfaces. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_open_async_006', 0, async function (done) { - let fpath = await nextFileName('fileio_test_open_async_006'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - await fileio.open(fpath, 0o2, 0o0200) - .then(function (fd) { - fileio.read(fd, new ArrayBuffer(4096)) - .then(function (res) { - expect(res.bytesRead == FILE_CONTENT.length).assertTrue(); - fileio.closeSync(fd); - fileio.unlinkSync(fpath); - }); - }) - .catch(function (err) { - expect(err == null).assertTrue(); - }) - done(); - } catch (e) { - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_OPEN_ASYNC_0700 - * @tc.name fileio_test_open_async_007 - * @tc.desc Test openASync() interfaces. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_open_async_007', 0, async function (done) { - let fpath = await nextFileName('fileio_test_open_async_007'); - try { - fileio.open(fpath, 0o0101, 0o0222, function (err, fd) { - expect(fd !== null).assertTrue(); - fileio.writeSync(fd, FILE_CONTENT, { - encoding: 'utf-8', - offset: 1, - length: 1, - }); - expect(fileio.closeSync(fd) !== null).assertTrue(); - expect(fileio.unlinkSync(fpath) !== null).assertTrue(); - done(); - }); - } catch (e) { - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_OPEN_ASYNC_0800 - * @tc.name fileio_test_open_async_008 - * @tc.desc Test openASync() interfaces. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_open_async_008', 0, async function (done) { - let fpath = await nextFileName('fileio_test_open_async_008'); - try { - fileio.open(fpath, 0o100, 0o0444, function (err, fd) { - expect(fd !== null).assertTrue(); - expect(fileio.closeSync(fd) !== null).assertTrue(); - expect(fileio.unlinkSync(fpath) !== null).assertTrue(); - done(); - }); - } catch (e) { - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_OPEN_ASYNC_0900 - * @tc.name fileio_test_open_async_009 - * @tc.desc Test openASync() interfaces. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_open_async_009', 0, async function (done) { - let fpath = await nextFileName('fileio_test_open_async_009'); - try { - fileio.open(fpath, 0o2101, 0o0222, function (err, fd) { - expect(fd !== null).assertTrue(); - let wri = fileio.writeSync(fd, 'hello1', { - encoding: 'utf-8', - offset: 1, - length: 1, - }); - expect(wri !== null).assertTrue(); - let writ = fileio.writeSync(fd, 'hello2', { - encoding: 'utf-8', - offset: 1, - length: 1, - }); - expect(writ !== null).assertTrue(); - expect(fileio.closeSync(fd) !== null).assertTrue(); - expect(fileio.unlinkSync(fpath) !== null).assertTrue(); - done(); - }); - } catch (e) { - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_OPEN_ASYNC_1000 - * @tc.name fileio_test_open_async_010 - * @tc.desc Test open() interfaces. - * Use default: flag = O_RDONLY, mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 3 - * @tc.require - */ - it('fileio_test_open_async_010', 3, async function (done) { - let fpath = await nextFileName('fileio_test_open_async_010'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - fileio.open(fpath, undefined, undefined, (err, fd) => { - if (err) { - console.log('fileio_test_open_async_010 error: ' + e); - expect(false).assertTrue(); - } - expect(isIntNum(fd)).assertTrue(); - let readLen = fileio.readSync(fd, new ArrayBuffer(4096)); - expect(readLen == FILE_CONTENT.length).assertTrue(); - fileio.write(fd, FILE_CONTENT, (err, bytesWritten) => { - if (err) { - fileio.closeSync(fd); - fileio.unlinkSync(fpath); - console.log('fileIO_test_open_async_010 error package: ' + err); - expect(err.message == 'Bad file descriptor').assertTrue(); - done(); - } else { - expect(false).assertTrue(); - } - }); - }); - } catch (e) { - console.log('fileio_test_open_async_010 has failed for ' + e); - expect(false).assertTrue(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_OPEN_ASYNC_1100 - * @tc.name fileio_test_open_async_011 - * @tc.desc Test open() interfaces. - * Use default: flag = O_RDONLY, mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 3 - * @tc.require - */ - it('fileio_test_open_async_011', 3, async function (done) { - let fpath = await nextFileName('fileio_test_open_async_011'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - let fd; - - try { - fd = await fileio.open(fpath, undefined, undefined); - expect(isIntNum(fd)).assertTrue(); - let readLen = fileio.readSync(fd, new ArrayBuffer(4096)); - expect(readLen == FILE_CONTENT.length).assertTrue(); - fileio.writeSync(fd, FILE_CONTENT); - expect(false).assertTrue(); - } catch (e) { - fileio.closeSync(fd); - fileio.unlinkSync(fpath); - console.log('fileio_test_open_async_011 has failed for' + e); - expect(e.message == 'Bad file descriptor').assertTrue(); - done(); - } - }); -}); -} +/* + * Copyright (C) 2021 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 { + fileio, FILE_CONTENT, prepareFile, nextFileName, isIntNum, + describe, it, expect, +} from '../../Common'; + +export default function fileioOpen() { +describe('fileio_open', function () { + + /** + * @tc.number SUB_DF_FILEIO_OPEN_SYNC_0000 + * @tc.name fileio_test_open_sync_000 + * @tc.desc Test openSync() interfaces. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_open_sync_000', 0, function () { + try { + fileio.openSync('/', 0o102, 0o666); + expect(null).assertFail(); + } catch (e) { + console.log('fileio_test_open_sync_000 has failed for ' + e); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_OPEN_ASYNC_0000 + * @tc.name fileio_test_open_async_000 + * @tc.desc Test openASync() interfaces. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_open_async_000', 0, async function (done) { + let fpath = await nextFileName('fileio_test_open_async_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + await fileio.access(fpath).then(function (err) { + fileio.open(fpath, 0, 0o0400, function (err, fd) { + fileio.read(fd, new ArrayBuffer(4096)) + .then(function (res) { + expect(res.bytesRead == FILE_CONTENT.length).assertTrue(); + fileio.closeSync(fd); + fileio.unlinkSync(fpath); + done(); + }); + }); + }); + } catch (e) { + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_OPEN_ASYNC_0100 + * @tc.name fileio_test_open_async_001 + * @tc.desc Test openASync() interfaces. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_open_async_001', 0, async function (done) { + let fpath = await nextFileName('fileio_test_open_async_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + await fileio.open(fpath, 0, 0o0400, function (err, fd) { + fileio.read(fd, new ArrayBuffer(4096)) + .then(function (res) { + expect(res.bytesRead == FILE_CONTENT.length).assertTrue(); + fileio.closeSync(fd); + fileio.unlinkSync(fpath); + done(); + }); + }); + } catch (e) { + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_OPEN_ASYNC_0200 + * @tc.name fileio_test_open_async_002 + * @tc.desc Test openASync() interfaces. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_open_async_002', 0, async function (done) { + let fpath = await nextFileName('fileio_test_open_async_002'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + await fileio.open(fpath, 0, function (err, fd) { + fileio.read(fd, new ArrayBuffer(4096)) + .then(function (res) { + expect(res.bytesRead == FILE_CONTENT.length).assertTrue(); + fileio.closeSync(fd); + fileio.unlinkSync(fpath); + done(); + }); + }); + } catch (e) { + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_OPEN_ASYNC_0300 + * @tc.name fileio_test_open_async_003 + * @tc.desc Test openASync() interfaces. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_open_async_003', 0, async function (done) { + let fpath = await nextFileName('fileio_test_open_async_003'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + fileio.open(fpath, 0o2, function (err, fd) { + fileio.read(fd, new ArrayBuffer(4096)) + .then(function (res) { + expect(res.bytesRead == FILE_CONTENT.length).assertTrue(); + fileio.closeSync(fd); + fileio.unlinkSync(fpath); + done(); + }); + }); + } catch (e) { + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_OPEN_ASYNC_0400 + * @tc.name fileio_test_open_async_004 + * @tc.desc Test openASync() interfaces. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_open_async_004', 0, async function (done) { + let fpath = await nextFileName('fileio_test_open_async_004'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + await fileio.open(fpath) + .then(function (fd) { + fileio.read(fd, new ArrayBuffer(4096)) + .then(function (res) { + expect(res.bytesRead == FILE_CONTENT.length).assertTrue(); + fileio.closeSync(fd); + fileio.unlinkSync(fpath); + }); + }) + .catch(function (err) { + expect(err == null).assertTrue(); + }) + done(); + } catch (e) { + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_OPEN_ASYNC_0500 + * @tc.name fileio_test_open_async_005 + * @tc.desc Test openASync() interfaces. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_open_async_005', 0, async function (done) { + let fpath = await nextFileName('fileio_test_open_async_005'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + await fileio.open(fpath, 0o0) + .then(function (fd) { + fileio.read(fd, new ArrayBuffer(4096)) + .then(function (res) { + expect(res.bytesRead == FILE_CONTENT.length).assertTrue(); + fileio.closeSync(fd); + fileio.unlinkSync(fpath); + }) + }) + .catch(function (err) { + expect(err == null).assertTrue(); + }) + done(); + } catch (e) { + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_OPEN_ASYNC_0600 + * @tc.name fileio_test_open_async_006 + * @tc.desc Test openASync() interfaces. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_open_async_006', 0, async function (done) { + let fpath = await nextFileName('fileio_test_open_async_006'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + await fileio.open(fpath, 0o2, 0o0200) + .then(function (fd) { + fileio.read(fd, new ArrayBuffer(4096)) + .then(function (res) { + expect(res.bytesRead == FILE_CONTENT.length).assertTrue(); + fileio.closeSync(fd); + fileio.unlinkSync(fpath); + }); + }) + .catch(function (err) { + expect(err == null).assertTrue(); + }) + done(); + } catch (e) { + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_OPEN_ASYNC_0700 + * @tc.name fileio_test_open_async_007 + * @tc.desc Test openASync() interfaces. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_open_async_007', 0, async function (done) { + let fpath = await nextFileName('fileio_test_open_async_007'); + try { + fileio.open(fpath, 0o0101, 0o0222, function (err, fd) { + expect(fd !== null).assertTrue(); + fileio.writeSync(fd, FILE_CONTENT, { + encoding: 'utf-8', + offset: 1, + length: 1, + }); + expect(fileio.closeSync(fd) !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + done(); + }); + } catch (e) { + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_OPEN_ASYNC_0800 + * @tc.name fileio_test_open_async_008 + * @tc.desc Test openASync() interfaces. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_open_async_008', 0, async function (done) { + let fpath = await nextFileName('fileio_test_open_async_008'); + try { + fileio.open(fpath, 0o100, 0o0444, function (err, fd) { + expect(fd !== null).assertTrue(); + expect(fileio.closeSync(fd) !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + done(); + }); + } catch (e) { + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_OPEN_ASYNC_0900 + * @tc.name fileio_test_open_async_009 + * @tc.desc Test openASync() interfaces. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_open_async_009', 0, async function (done) { + let fpath = await nextFileName('fileio_test_open_async_009'); + try { + fileio.open(fpath, 0o2101, 0o0222, function (err, fd) { + expect(fd !== null).assertTrue(); + let wri = fileio.writeSync(fd, 'hello1', { + encoding: 'utf-8', + offset: 1, + length: 1, + }); + expect(wri !== null).assertTrue(); + let writ = fileio.writeSync(fd, 'hello2', { + encoding: 'utf-8', + offset: 1, + length: 1, + }); + expect(writ !== null).assertTrue(); + expect(fileio.closeSync(fd) !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + done(); + }); + } catch (e) { + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_OPEN_ASYNC_1000 + * @tc.name fileio_test_open_async_010 + * @tc.desc Test open() interfaces. + * Use default: flag = O_RDONLY, mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 3 + * @tc.require + */ + it('fileio_test_open_async_010', 3, async function (done) { + let fpath = await nextFileName('fileio_test_open_async_010'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + fileio.open(fpath, undefined, undefined, (err, fd) => { + if (err) { + console.log('fileio_test_open_async_010 error: ' + e); + expect(false).assertTrue(); + } + expect(isIntNum(fd)).assertTrue(); + let readLen = fileio.readSync(fd, new ArrayBuffer(4096)); + expect(readLen == FILE_CONTENT.length).assertTrue(); + fileio.write(fd, FILE_CONTENT, (err, bytesWritten) => { + if (err) { + fileio.closeSync(fd); + fileio.unlinkSync(fpath); + console.log('fileIO_test_open_async_010 error package: ' + err); + expect(err.message == 'Bad file descriptor').assertTrue(); + done(); + } else { + expect(false).assertTrue(); + } + }); + }); + } catch (e) { + console.log('fileio_test_open_async_010 has failed for ' + e); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_OPEN_ASYNC_1100 + * @tc.name fileio_test_open_async_011 + * @tc.desc Test open() interfaces. + * Use default: flag = O_RDONLY, mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 3 + * @tc.require + */ + it('fileio_test_open_async_011', 3, async function (done) { + let fpath = await nextFileName('fileio_test_open_async_011'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let fd; + + try { + fd = await fileio.open(fpath, undefined, undefined); + expect(isIntNum(fd)).assertTrue(); + let readLen = fileio.readSync(fd, new ArrayBuffer(4096)); + expect(readLen == FILE_CONTENT.length).assertTrue(); + fileio.writeSync(fd, FILE_CONTENT); + expect(false).assertTrue(); + } catch (e) { + fileio.closeSync(fd); + fileio.unlinkSync(fpath); + console.log('fileio_test_open_async_011 has failed for' + e); + expect(e.message == 'Bad file descriptor').assertTrue(); + done(); + } + }); +}); +} diff --git a/storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/members/open_close.test.js b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/open_close.test.js similarity index 95% rename from storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/members/open_close.test.js rename to storage/storagefileiojstest/src/main/js/test/module_fileio/members/open_close.test.js index 57b69fb7481f68e9b289091d3363ca98ea858ad1..4c98f1bc14b90b3efb0bf4429d0b6d803b6fa202 100644 --- a/storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/members/open_close.test.js +++ b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/open_close.test.js @@ -1,174 +1,174 @@ -/* - * Copyright (C) 2023 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 { - fileio, FILE_CONTENT, prepareFile, nextFileName, isIntNum, - describe, it, expect, -} from '../../Common'; - -export default function fileioOpenClose() { -describe('fileio_open_close', function () { - - /** - * @tc.number SUB_DF_FILEIO_OPEN_CLOSE_SYNC_0000 - * @tc.name fileio_open_close_sync_000 - * @tc.desc Test openSync() and closeSync() interfaces. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_open_close_sync_000', 0, async function () { - let fpath = await nextFileName('fileio_open_close_sync_000'); - - try { - let fd = fileio.openSync(fpath, 0o102, 0o666); - expect(isIntNum(fd)).assertTrue(); - expect(fileio.closeSync(fd) == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - } catch (e) { - console.log('fileio_open_close_sync_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_OPEN_CLOSE_SYNC_0010 - * @tc.name fileio_open_close_sync_001 - * @tc.desc Test openSync() and closeSync() interfaces. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_open_close_sync_001', 0, async function () { - let fpath = await nextFileName('fileio_open_close_sync_001'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let fd = fileio.openSync(fpath); - expect(isIntNum(fd)).assertTrue(); - expect(fileio.closeSync(fd) == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - } catch (e) { - console.log('fileio_open_close_sync_001 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_OPEN_SYNC_0000 - * @tc.name fileio_open_sync_000 - * @tc.desc Test openSync() interface. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_open_sync_000', 0, function () { - try { - fileio.openSync('/', 0o102, 0o666); - expect(null).assertFail(); - } catch (e) { - console.log('fileio_open_sync_000 has failed for ' + e); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_OPEN_SYNC_0100 - * @tc.name fileio_open_sync_001 - * @tc.desc Test openSync() interface. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_open_sync_001', 0, async function () { - let fpath = await nextFileName('fileio_open_sync_001'); - - try { - fileio.openSync(fpath, 0o102); - expect(null).assertFail(); - } catch (e) { - console.log('fileio_open_sync_001 has failed for ' + e); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_OPEN_SYNC_0200 - * @tc.name fileio_open_sync_002 - * @tc.desc Test openSync() interface. - * Use default: flag = O_RDONLY, mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 3 - * @tc.require - */ - it('fileio_open_sync_002', 3, async function () { - let fpath = await nextFileName('fileio_open_sync_002'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - let fd; - - try { - fd = fileio.openSync(fpath, undefined, undefined); - expect(isIntNum(fd)).assertTrue(); - let readLen = fileio.readSync(fd, new ArrayBuffer(4096)); - expect(readLen == FILE_CONTENT.length).assertTrue(); - fileio.writeSync(fd, FILE_CONTENT); - expect(false).assertTrue(); - } catch (e) { - fileio.closeSync(fd); - fileio.unlinkSync(fpath); - console.log('fileio_open_sync_002 has failed for ' + e); - expect(e.message == 'Bad file descriptor').assertTrue(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_CLOSE_SYNC_0000 - * @tc.name fileio_close_sync_000 - * @tc.desc Test closeSync() interface. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_close_sync_000', 0, function () { - try { - fileio.closeSync(); - expect(null).assertFail(); - } catch (e) { - console.log('fileio_close_sync_000 has failed for ' + e); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_CLOSE_SYNC_0010 - * @tc.name fileio_close_sync_001 - * @tc.desc Test closeSync() interface. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_close_sync_001', 0, function () { - try { - fileio.closeSync(-1); - expect(null).assertFail(); - } catch (e) { - console.log('fileio_close_sync_001 has failed for ' + e); - } - }); -});} +/* + * Copyright (C) 2021 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 { + fileio, FILE_CONTENT, prepareFile, nextFileName, isIntNum, + describe, it, expect, +} from '../../Common'; + +export default function fileioOpenClose() { +describe('fileio_open_close', function () { + + /** + * @tc.number SUB_DF_FILEIO_OPEN_CLOSE_SYNC_0000 + * @tc.name fileio_open_close_sync_000 + * @tc.desc Test openSync() and closeSync() interfaces. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_open_close_sync_000', 0, async function () { + let fpath = await nextFileName('fileio_open_close_sync_000'); + + try { + let fd = fileio.openSync(fpath, 0o102, 0o666); + expect(isIntNum(fd)).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_open_close_sync_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_OPEN_CLOSE_SYNC_0010 + * @tc.name fileio_open_close_sync_001 + * @tc.desc Test openSync() and closeSync() interfaces. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_open_close_sync_001', 0, async function () { + let fpath = await nextFileName('fileio_open_close_sync_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath); + expect(isIntNum(fd)).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_open_close_sync_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_OPEN_SYNC_0000 + * @tc.name fileio_open_sync_000 + * @tc.desc Test openSync() interface. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_open_sync_000', 0, function () { + try { + fileio.openSync('/', 0o102, 0o666); + expect(null).assertFail(); + } catch (e) { + console.log('fileio_open_sync_000 has failed for ' + e); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_OPEN_SYNC_0100 + * @tc.name fileio_open_sync_001 + * @tc.desc Test openSync() interface. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_open_sync_001', 0, async function () { + let fpath = await nextFileName('fileio_open_sync_001'); + + try { + fileio.openSync(fpath, 0o102); + expect(null).assertFail(); + } catch (e) { + console.log('fileio_open_sync_001 has failed for ' + e); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_OPEN_SYNC_0200 + * @tc.name fileio_open_sync_002 + * @tc.desc Test openSync() interface. + * Use default: flag = O_RDONLY, mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 3 + * @tc.require + */ + it('fileio_open_sync_002', 3, async function () { + let fpath = await nextFileName('fileio_open_sync_002'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let fd; + + try { + fd = fileio.openSync(fpath, undefined, undefined); + expect(isIntNum(fd)).assertTrue(); + let readLen = fileio.readSync(fd, new ArrayBuffer(4096)); + expect(readLen == FILE_CONTENT.length).assertTrue(); + fileio.writeSync(fd, FILE_CONTENT); + expect(false).assertTrue(); + } catch (e) { + fileio.closeSync(fd); + fileio.unlinkSync(fpath); + console.log('fileio_open_sync_002 has failed for ' + e); + expect(e.message == 'Bad file descriptor').assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_CLOSE_SYNC_0000 + * @tc.name fileio_close_sync_000 + * @tc.desc Test closeSync() interface. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_close_sync_000', 0, function () { + try { + fileio.closeSync(); + expect(null).assertFail(); + } catch (e) { + console.log('fileio_close_sync_000 has failed for ' + e); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_CLOSE_SYNC_0010 + * @tc.name fileio_close_sync_001 + * @tc.desc Test closeSync() interface. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_close_sync_001', 0, function () { + try { + fileio.closeSync(-1); + expect(null).assertFail(); + } catch (e) { + console.log('fileio_close_sync_001 has failed for ' + e); + } + }); +});} diff --git a/storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/members/opendir_close.test.js b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/opendir_close.test.js similarity index 95% rename from storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/members/opendir_close.test.js rename to storage/storagefileiojstest/src/main/js/test/module_fileio/members/opendir_close.test.js index 4794de39414460d472ee855919346bae01dab271..8915b762950b94ecd3bdc69bead737063ec71880 100644 --- a/storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/members/opendir_close.test.js +++ b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/opendir_close.test.js @@ -1,116 +1,116 @@ -/* - * Copyright (C) 2023 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 { fileio, nextFileName, describe, it, expect } from '../../Common'; - -export default function fileioOpendirClose() { -describe('fileio_opendir_close', function () { - - /** - * @tc.number SUB_DF_FILEIO_OPEN_CLOSEDIR_SYNC_0000 - * @tc.name fileio_dir_open_close_sync_000 - * @tc.desc Test opendirSync() and Dir.closeSync() interfaces. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_dir_open_close_sync_000', 0, async function () { - let dpath = await nextFileName('fileio_dir_open_close_sync_000') + 'd'; - - try { - expect(fileio.mkdirSync(dpath) == null).assertTrue(); - let dd = fileio.opendirSync(dpath); - expect(dd !== null).assertTrue(); - expect(dd.closeSync() == null).assertTrue(); - expect(fileio.rmdirSync(dpath) == null).assertTrue(); - } catch (e) { - console.log('fileio_dir_open_close_sync_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_OPEN_CLOSEDIR_SYNC_0010 - * @tc.name fileio_dir_open_close_sync_001 - * @tc.desc Test opendirSync() interface. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_dir_open_close_sync_001', 0, async function () { - let dpath = await nextFileName('fileio_dir_open_close_sync_001') + 'd'; - - try { - fileio.opendirSync(dpath); - expect(null).assertFail(); - } catch (e) { - console.log('fileio_dir_open_close_sync_001 has failed for ' + e); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_OPEN_CLOSEDIR_ASYNC_0000 - * @tc.name fileio_dir_open_close_async_000 - * @tc.desc Test opendirAsync() and Dir.closeSync() interfaces. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_dir_open_close_async_000', 0, async function (done) { - let dpath = await nextFileName('fileio_dir_open_close_async_000') + 'd'; - - try { - expect(fileio.mkdirSync(dpath) == null).assertTrue(); - let dd = await fileio.opendir(dpath); - expect(dd !== null).assertTrue(); - expect(dd.closeSync() == null).assertTrue(); - expect(fileio.rmdirSync(dpath) == null).assertTrue(); - done(); - } catch (e) { - console.log('fileio_dir_open_close_async_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_OPEN_CLOSEDIR_ASYNC_0010 - * @tc.name fileio_dir_open_close_async_001 - * @tc.desc Test opendirAsync() and Dir.closeSync() interfaces. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_dir_open_close_async_001', 0, async function (done) { - let dpath = await nextFileName('fileio_dir_open_close_async_001') + 'd'; - - try { - expect(fileio.mkdirSync(dpath) == null).assertTrue(); - fileio.opendir(dpath, function (error, dd) { - expect(dd !== null).assertTrue(); - expect(dd.closeSync() == null).assertTrue(); - expect(fileio.rmdirSync(dpath) == null).assertTrue(); - done(); - }); - } catch (e) { - console.log('fileio_dir_open_close_async_001 has failed for ' + e); - expect(null).assertFail(); - } - }); -}); -} +/* + * Copyright (C) 2021 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 { fileio, nextFileName, describe, it, expect } from '../../Common'; + +export default function fileioOpendirClose() { +describe('fileio_opendir_close', function () { + + /** + * @tc.number SUB_DF_FILEIO_OPEN_CLOSEDIR_SYNC_0000 + * @tc.name fileio_dir_open_close_sync_000 + * @tc.desc Test opendirSync() and Dir.closeSync() interfaces. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_dir_open_close_sync_000', 0, async function () { + let dpath = await nextFileName('fileio_dir_open_close_sync_000') + 'd'; + + try { + expect(fileio.mkdirSync(dpath) == null).assertTrue(); + let dd = fileio.opendirSync(dpath); + expect(dd !== null).assertTrue(); + expect(dd.closeSync() == null).assertTrue(); + expect(fileio.rmdirSync(dpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_dir_open_close_sync_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_OPEN_CLOSEDIR_SYNC_0010 + * @tc.name fileio_dir_open_close_sync_001 + * @tc.desc Test opendirSync() interface. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_dir_open_close_sync_001', 0, async function () { + let dpath = await nextFileName('fileio_dir_open_close_sync_001') + 'd'; + + try { + fileio.opendirSync(dpath); + expect(null).assertFail(); + } catch (e) { + console.log('fileio_dir_open_close_sync_001 has failed for ' + e); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_OPEN_CLOSEDIR_ASYNC_0000 + * @tc.name fileio_dir_open_close_async_000 + * @tc.desc Test opendirAsync() and Dir.closeSync() interfaces. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_dir_open_close_async_000', 0, async function (done) { + let dpath = await nextFileName('fileio_dir_open_close_async_000') + 'd'; + + try { + expect(fileio.mkdirSync(dpath) == null).assertTrue(); + let dd = await fileio.opendir(dpath); + expect(dd !== null).assertTrue(); + expect(dd.closeSync() == null).assertTrue(); + expect(fileio.rmdirSync(dpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_dir_open_close_async_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_OPEN_CLOSEDIR_ASYNC_0010 + * @tc.name fileio_dir_open_close_async_001 + * @tc.desc Test opendirAsync() and Dir.closeSync() interfaces. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_dir_open_close_async_001', 0, async function (done) { + let dpath = await nextFileName('fileio_dir_open_close_async_001') + 'd'; + + try { + expect(fileio.mkdirSync(dpath) == null).assertTrue(); + fileio.opendir(dpath, function (error, dd) { + expect(dd !== null).assertTrue(); + expect(dd.closeSync() == null).assertTrue(); + expect(fileio.rmdirSync(dpath) == null).assertTrue(); + done(); + }); + } catch (e) { + console.log('fileio_dir_open_close_async_001 has failed for ' + e); + expect(null).assertFail(); + } + }); +}); +} diff --git a/storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/members/posix_fallocate.test.js b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/posix_fallocate.test.js similarity index 95% rename from storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/members/posix_fallocate.test.js rename to storage/storagefileiojstest/src/main/js/test/module_fileio/members/posix_fallocate.test.js index bc2dd35441a3aaea1304abb8881ede99bba626b7..7b655c923337692409848777dc37d3980b99f647 100644 --- a/storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/members/posix_fallocate.test.js +++ b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/posix_fallocate.test.js @@ -1,99 +1,99 @@ -/* - * Copyright (C) 2023 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 { - fileio, FILE_CONTENT, prepareFile, nextFileName, isIntNum, - describe, it, expect, -} from '../../Common'; - -export default function fileioPosixFallocate() { -describe('fileio_posix_fallocate', function () { - - /** - * @tc.number SUB_DF_FILEIO_POSIX_FALLOCATE_SYNC_0000 - * @tc.name fileio_test_posix_fallocate_sync_000 - * @tc.desc Test fsyncSync() interface. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_posix_fallocate_sync_000', 0, async function () { - let fpath = await nextFileName('fileio_test_posix_fallocate_sync_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let fd = fileio.openSync(fpath, 0o102, 0o666); - expect(isIntNum(fd)).assertTrue(); - fileio.posixFallocateSync(fd, 100, 999); - expect(fileio.closeSync(fd) == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - } catch (e) { - console.log('fileio_test_posix_fallocate_sync_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_POSIX_FALLOCATE_ASYNC_0000 - * @tc.name fileio_test_posix_fallocate_async_000 - * @tc.desc Test fsyncASync() interface. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_posix_fallocate_async_000', 0, async function (done) { - let fpath = await nextFileName('fileio_test_posix_fallocate_async_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let fd = fileio.openSync(fpath, 0o2); - expect(isIntNum(fd)).assertTrue(); - await fileio.posixFallocate(fd, 100, 999, function (err) { - expect(fileio.closeSync(fd) == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - done(); - }); - } catch (e) { - console.log('fileio_test_posix_fallocate_async_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_POSIX_FALLOCATE_ASYNC_0010 - * @tc.name fileio_test_posix_fallocate_async_001 - * @tc.desc Test lseekAsync()interfaces. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_posix_fallocate_async_001', 0, async function (done) { - let fpath = await nextFileName('fileio_test_posix_fallocate_async_001'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let fd = fileio.openSync(fpath, 0o2); - expect(isIntNum(fd)).assertTrue(); - await fileio.posixFallocate(fd, 100, 999); - expect(fileio.closeSync(fd) == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - done(); - } catch (e) { - console.log('fileio_test_posix_fallocate_async_001 has failed for ' + e); - expect(null).assertFail(); - } - }); -}); -} +/* + * Copyright (C) 2021 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 { + fileio, FILE_CONTENT, prepareFile, nextFileName, isIntNum, + describe, it, expect, +} from '../../Common'; + +export default function fileioPosixFallocate() { +describe('fileio_posix_fallocate', function () { + + /** + * @tc.number SUB_DF_FILEIO_POSIX_FALLOCATE_SYNC_0000 + * @tc.name fileio_test_posix_fallocate_sync_000 + * @tc.desc Test fsyncSync() interface. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_posix_fallocate_sync_000', 0, async function () { + let fpath = await nextFileName('fileio_test_posix_fallocate_sync_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let fd = fileio.openSync(fpath, 0o102, 0o666); + expect(isIntNum(fd)).assertTrue(); + fileio.posixFallocateSync(fd, 100, 999); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_test_posix_fallocate_sync_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_POSIX_FALLOCATE_ASYNC_0000 + * @tc.name fileio_test_posix_fallocate_async_000 + * @tc.desc Test fsyncASync() interface. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_posix_fallocate_async_000', 0, async function (done) { + let fpath = await nextFileName('fileio_test_posix_fallocate_async_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let fd = fileio.openSync(fpath, 0o2); + expect(isIntNum(fd)).assertTrue(); + await fileio.posixFallocate(fd, 100, 999, function (err) { + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + }); + } catch (e) { + console.log('fileio_test_posix_fallocate_async_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_POSIX_FALLOCATE_ASYNC_0010 + * @tc.name fileio_test_posix_fallocate_async_001 + * @tc.desc Test lseekAsync()interfaces. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_posix_fallocate_async_001', 0, async function (done) { + let fpath = await nextFileName('fileio_test_posix_fallocate_async_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let fd = fileio.openSync(fpath, 0o2); + expect(isIntNum(fd)).assertTrue(); + await fileio.posixFallocate(fd, 100, 999); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_test_posix_fallocate_async_001 has failed for ' + e); + expect(null).assertFail(); + } + }); +}); +} diff --git a/storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/members/read.test.js b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/read.test.js similarity index 96% rename from storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/members/read.test.js rename to storage/storagefileiojstest/src/main/js/test/module_fileio/members/read.test.js index 89f3e2ac02bb3a26ee1b4d338e3fa6db8a1f17c2..99b65343efdbbf54e7c68f151b7bbb69b5c59459 100644 --- a/storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/members/read.test.js +++ b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/read.test.js @@ -1,775 +1,775 @@ -/* - * Copyright (C) 2023 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 { - fileio, FILE_CONTENT, prepareFile, nextFileName, isIntNum, - describe, it, expect, -} from '../../Common'; - -export default function fileioRead() { -describe('fileio_read', function () { - - /** - * @tc.number SUB_DF_FILEIO_READ_SYNC_0000 - * @tc.name fileio_test_read_sync_000 - * @tc.desc Test readSync() interfaces. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_read_sync_000', 0, async function () { - let fpath = await nextFileName('fileio_test_read_sync_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let fd = fileio.openSync(fpath, 0o2); - expect(isIntNum(fd)).assertTrue(); - let len = fileio.readSync(fd, new ArrayBuffer(4096)); - expect(len == FILE_CONTENT.length).assertTrue(); - expect(fileio.closeSync(fd) == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - } catch (e) { - console.log('fileio_test_read_sync_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_READ_SYNC_0100 - * @tc.name fileio_test_read_sync_001 - * @tc.desc Test readSync() interfaces. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_read_sync_001', 0, async function () { - let bufLen = 5; - expect(FILE_CONTENT.length > bufLen).assertTrue(); - let fpath = await nextFileName('fileio_test_read_sync_001'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let fd = fileio.openSync(fpath, 0o2); - expect(isIntNum(fd)).assertTrue(); - let len = fileio.readSync(fd, new ArrayBuffer(bufLen), { - offset: 1, - }); - expect(len == bufLen - 1).assertTrue(); - expect(fileio.closeSync(fd) == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - } catch (e) { - console.log('fileio_test_read_sync_001 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_READ_SYNC_0200 - * @tc.name fileio_test_read_sync_002 - * @tc.desc Test readSync() interfaces. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_read_sync_002', 0, async function () { - let fpath = await nextFileName('fileio_test_read_sync_002'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let fd = fileio.openSync(fpath, 0o2); - expect(isIntNum(fd)).assertTrue(); - let len = fileio.readSync(fd, new ArrayBuffer(4096), { - length: 1, - }); - expect(len == 1).assertTrue(); - expect(fileio.closeSync(fd) == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - } catch (e) { - console.log('fileio_test_read_sync_002 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_READ_SYNC_0300 - * @tc.name fileio_test_read_sync_003 - * @tc.desc Test readSync() interfaces. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_read_sync_003', 0, async function () { - let fpath = await nextFileName('fileio_test_read_sync_003'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let fd = fileio.openSync(fpath, 0o2); - expect(isIntNum(fd)).assertTrue(); - let len = fileio.readSync(fd, new ArrayBuffer(4096), { - position: 1, - }); - expect(len == FILE_CONTENT.length - 1).assertTrue(); - expect(fileio.closeSync(fd) == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - } catch (e) { - console.log('fileio_test_read_sync_003 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_READ_SYNC_0400 - * @tc.name fileio_test_read_sync_004 - * @tc.desc Test readSync() interfaces. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_read_sync_004', 0, async function () { - let fd; - const invalidOffset = 99999; - let fpath = await nextFileName('fileio_test_read_sync_004'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - fd = fileio.openSync(fpath, 0o2); - expect(isIntNum(fd)).assertTrue(); - fileio.readSync(fd, new ArrayBuffer(4096), { - offset: invalidOffset, - }); - expect(null).assertFail(); - } catch (e) { - expect(fileio.closeSync(fd) == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_READ_SYNC_0500 - * @tc.name fileio_test_read_sync_005 - * @tc.desc Test readSync() interfaces. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_read_sync_005', 0, async function () { - let fd; - const invalidLength = 9999; - let fpath = await nextFileName('fileio_test_read_sync_005'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - fd = fileio.openSync(fpath, 0o2); - expect(isIntNum(fd)).assertTrue(); - fileio.readSync(fd, new ArrayBuffer(4096), { - length: invalidLength, - }); - expect(null).assertFail(); - } catch (e) { - expect(fileio.closeSync(fd) == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_READ_SYNC_0600 - * @tc.name fileio_test_read_sync_006 - * @tc.desc Test readSync() interfaces. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_read_sync_006', 0, async function () { - let fpath = await nextFileName('fileio_test_read_sync_006'); - let fd; - - try { - fileio.readSync(-1, new ArrayBuffer(4096)); - expect(null).assertFail(); - } catch (e) { - console.log('fileio_test_read_sync_006 has failed for ' + e); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_READ_SYNC_0700 - * @tc.name fileio_test_read_sync_007 - * @tc.desc Test readSync() interfaces. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_read_sync_007', 0, async function () { - let fpath = await nextFileName('fileio_test_read_sync_007'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let fd = fileio.openSync(fpath, 0o2); - expect(isIntNum(fd)).assertTrue(); - let len = fileio.readSync(fd, new ArrayBuffer(4096), { - position: 1, - }); - expect(len == FILE_CONTENT.length - 1).assertTrue(); - expect(fileio.closeSync(fd) == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - } catch (e) { - console.log('fileio_test_read_sync_007 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_READ_SYNC_0800 - * @tc.name fileio_test_read_sync_008 - * @tc.desc Test readSync() interfaces. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_read_sync_008', 0, async function () { - let fpath = await nextFileName('fileio_test_read_sync_008'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let fd = fileio.openSync(fpath, 0o2); - expect(isIntNum(fd)).assertTrue(); - let invalidPos = FILE_CONTENT.length + 1; - let len = fileio.readSync(fd, new ArrayBuffer(4096), { - position: invalidPos, - }); - expect(len == 0).assertTrue(); - expect(fileio.closeSync(fd) == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - } catch (e) { - console.log('fileio_test_read_sync_008 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_READ_SYNC_0900 - * @tc.name fileio_test_read_sync_009 - * @tc.desc Test readSync() interfaces. - * Undefined option arguments, use default options. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 3 - * @tc.require - */ - it('fileio_test_read_sync_009', 3, async function () { - let fpath = await nextFileName('fileio_test_read_sync_009'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let fd = fileio.openSync(fpath, 0o2); - expect(isIntNum(fd)).assertTrue(); - let readLen1 = fileio.readSync(fd, new ArrayBuffer(16), undefined); - expect(readLen1 == FILE_CONTENT.length).assertTrue(); - let readLen2 = fileio.readSync(fd, new ArrayBuffer(8), undefined); - expect(readLen2 == 0).assertTrue(); - fileio.closeSync(fd); - fileio.unlinkSync(fpath); - } catch (e) { - console.log('fileio_test_read_sync_009 has failed for ' + e); - expect(false).assertTrue(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_READ_SYNC_1000 - * @tc.name fileio_test_read_sync_010 - * @tc.desc Test readSync() interfaces. - * Undefined option arguments, use default options. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 3 - * @tc.require - */ - it('fileio_test_read_sync_010', 3, async function () { - let fpath = await nextFileName('fileio_test_read_sync_010'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let fd = fileio.openSync(fpath, 0o2); - expect(isIntNum(fd)).assertTrue(); - let readLen1 = fileio.readSync(fd, new ArrayBuffer(16), { - offset: undefined, - position: undefined, - length: undefined, - }); - expect(readLen1 == FILE_CONTENT.length).assertTrue(); - let readLen2 = fileio.readSync(fd, new ArrayBuffer(8), { - offset: undefined, - position: undefined, - length: undefined, - }); - expect(readLen2 == 0).assertTrue(); - fileio.closeSync(fd); - fileio.unlinkSync(fpath); - } catch (e) { - console.log('fileio_test_read_sync_010 has failed for ' + e); - expect(false).assertTrue(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_READ_ASYNC_0000 - * @tc.name fileio_test_read_async_000 - * @tc.desc Test read() interfaces. Promise. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_read_async_000', 0, async function (done) { - let fpath = await nextFileName('fileio_test_read_async_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let fd = fileio.openSync(fpath, 0o2); - expect(isIntNum(fd)).assertTrue(); - let res = await fileio.read(fd, new ArrayBuffer(4096)); - expect(res.bytesRead == FILE_CONTENT.length).assertTrue(); - expect(fileio.closeSync(fd) == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - done(); - } catch (e) { - console.log('fileio_test_read_async_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_READ_ASYNC_0100 - * @tc.name fileio_test_read_async_001 - * @tc.desc Test read() interfaces. Callback. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_read_async_001', 0, async function (done) { - let fpath = await nextFileName('fileio_test_read_async_001'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let fd = fileio.openSync(fpath, 0o2); - expect(isIntNum(fd)).assertTrue(); - fileio.read(fd, new ArrayBuffer(4096), async function (err, data) { - expect(data.bytesRead == FILE_CONTENT.length).assertTrue(); - expect(fileio.closeSync(fd) == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - done(); - }); - } catch (e) { - console.log('fileio_test_read_async_001 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_READ_ASYNC_0200 - * @tc.name fileio_test_read_async_002 - * @tc.desc Test read() interfaces. Promise. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_read_async_002', 0, async function (done) { - let fpath = await nextFileName('fileio_test_read_async_002'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let fd = fileio.openSync(fpath); - expect(isIntNum(fd)).assertTrue(); - let readout = await fileio.read(fd, new ArrayBuffer(4096)); - expect(readout.buffer.byteLength == 4096).assertTrue(); - expect(fileio.closeSync(fd) == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - done(); - } catch (e) { - console.log('fileio_test_read_async_002 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_READ_ASYNC_0300 - * @tc.name fileio_test_read_async_003 - * @tc.desc Test read() interfaces. Promise. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_read_async_003', 0, async function (done) { - let fpath = await nextFileName('fileio_test_read_async_003'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let fd = fileio.openSync(fpath); - expect(isIntNum(fd)).assertTrue(); - let readout = await fileio.read(fd, new ArrayBuffer(4096), { - offset: 1, - }); - expect(readout.bytesRead == FILE_CONTENT.length).assertTrue(); - expect(fileio.closeSync(fd) == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - done(); - } catch (e) { - console.log('fileio_test_read_async_003 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_READ_ASYNC_0400 - * @tc.name fileio_test_read_async_004 - * @tc.desc Test read() interface. Promise. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_read_async_004', 0, async function (done) { - let fpath = await nextFileName('fileio_test_read_async_004'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let fd = fileio.openSync(fpath); - expect(isIntNum(fd)).assertTrue(); - let readout = await fileio.read(fd, new ArrayBuffer(4096), { - offset: 1, - length: 3, - }); - expect(readout.bytesRead == 3).assertTrue(); - expect(fileio.closeSync(fd) == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - done(); - } catch (e) { - console.log('fileio_test_read_async_004 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_READ_ASYNC_0500 - * @tc.name fileio_test_read_async_005 - * @tc.desc Test read() interfaces. Promise. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_read_async_005', 0, async function (done) { - let fpath = await nextFileName('fileio_test_read_async_005'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let fd = fileio.openSync(fpath); - expect(isIntNum(fd)).assertTrue(); - let readout = await fileio.read(fd, new ArrayBuffer(5), { - offset: 1, - }); - expect(readout.bytesRead == 4).assertTrue(); - expect(fileio.closeSync(fd) == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - done(); - } catch (e) { - console.log('fileio_test_read_async_005 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_READ_ASYNC_0600 - * @tc.name fileio_test_read_async_006 - * @tc.desc Test read() interfaces. Promise. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_read_async_006', 0, async function (done) { - let fd; - const invalidOffset = 999; - let fpath = await nextFileName('fileio_test_read_async_006'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - fd = fileio.openSync(fpath, 0o2); - expect(isIntNum(fd)).assertTrue(); - await fileio.read(fd, new ArrayBuffer(4096), { - offset: invalidOffset, - }); - throw new Error('invalid offset'); - } catch (e) { - expect(fileio.closeSync(fd) == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - done(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_READ_ASYNC_0700 - * @tc.name fileio_test_read_async_007 - * @tc.desc Test read() interfaces. Promise. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_read_async_007', 0, async function (done) { - let fpath = await nextFileName('fileio_test_read_async_007'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - let fd; - - try { - fd = fileio.openSync(fpath, 0o2); - expect(isIntNum(fd)).assertTrue(); - let invalidPos = FILE_CONTENT.length + 1; - let err = await fileio.read(fd, new ArrayBuffer(4096), { - offset: 1, - position: invalidPos, - }); - expect(!!err).assertTrue(); - expect(fileio.closeSync(fd) == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - done(); - } catch (e) { - console.log('fileio_test_read_async_007 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_READ_ASYNC_0800 - * @tc.name fileio_test_read_async_008 - * @tc.desc Test read() interfaces. Promise. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_read_async_008', 0, async function (done) { - try { - await fileio.read(-1, new ArrayBuffer(4096)); - expect(null).assertFail(); - } catch (e) { - console.info('fileio_test_read_async_008 has failed for ' + e); - done(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_READ_ASYNC_0900 - * @tc.name fileio_test_read_async_009 - * @tc.desc Test read() interfaces. Promise. - * Undefined option arguments, use default options. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 3 - * @tc.require - */ - it('fileio_test_read_async_009', 3, async function (done) { - let fpath = await nextFileName('fileio_test_read_async_009'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let fd = fileio.openSync(fpath, 0o2); - expect(isIntNum(fd)).assertTrue(); - let readRes1 = await fileio.read(fd, new ArrayBuffer(16), undefined); - expect(readRes1.bytesRead == FILE_CONTENT.length).assertTrue(); - expect(readRes1.offset == 0).assertTrue(); - let readRes2 = await fileio.read(fd, new ArrayBuffer(8), undefined); - expect(readRes2.bytesRead == 0).assertTrue(); - expect(readRes2.offset == 0).assertTrue(); - fileio.closeSync(fd); - fileio.unlinkSync(fpath); - done(); - } catch (e) { - console.log('fileio_test_read_async_009 has failed for ' + e); - expect(false).assertTrue(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_READ_ASYNC_1000 - * @tc.name fileio_test_read_async_010 - * @tc.desc Test read() interfaces. Callback. - * Undefined option arguments, use default options. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 3 - * @tc.require - */ - it('fileio_test_read_async_010', 3, async function (done) { - let fpath = await nextFileName('fileio_test_read_async_010'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let fd = fileio.openSync(fpath, 0o2); - expect(isIntNum(fd)).assertTrue(); - fileio.read(fd, new ArrayBuffer(16), undefined, (err, readRes1) => { - if(err) { - console.log('fileio_test_read_async_010 err package1: ' + JSON.stringify(err)); - expect(false).assertTrue(); - } - expect(readRes1.bytesRead == FILE_CONTENT.length).assertTrue(); - expect(readRes1.offset == 0).assertTrue(); - fileio.read(fd, new ArrayBuffer(8), undefined, (err, readRes2) => { - if(err) { - console.log('fileio_test_read_async_010 err package2: ' + JSON.stringify(err)); - expect(false).assertTrue(); - } - expect(readRes2.bytesRead == 0).assertTrue(); - expect(readRes2.offset == 0).assertTrue(); - fileio.closeSync(fd); - fileio.unlinkSync(fpath); - done(); - }); - }); - } catch (e) { - console.log('fileio_test_read_async_010 has failed for ' + e); - expect(false).assertTrue(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_READ_ASYNC_1100 - * @tc.name fileio_test_read_async_011 - * @tc.desc Test read() interfaces. Promise. - * Undefined option arguments, use default options. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 3 - * @tc.require - */ - it('fileio_test_read_async_011', 3, async function (done) { - let fpath = await nextFileName('fileio_test_read_async_011'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let fd = fileio.openSync(fpath, 0o2); - expect(isIntNum(fd)).assertTrue(); - let readRes1 = await fileio.read(fd, new ArrayBuffer(4096), { - offset: undefined, - length: undefined, - }); - expect(readRes1.bytesRead == FILE_CONTENT.length).assertTrue(); - expect(readRes1.offset == 0).assertTrue(); - let readRes2 = await fileio.read(fd, new ArrayBuffer(4096), { - offset: undefined, - length: undefined, - }); - expect(readRes2.bytesRead == 0).assertTrue(); - expect(readRes2.offset == 0).assertTrue(); - fileio.closeSync(fd); - fileio.unlinkSync(fpath); - done(); - } catch (e) { - console.log('fileio_test_read_async_011 has failed for ' + e); - expect(false).assertTrue(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_READ_ASYNC_1200 - * @tc.name fileio_test_read_async_012 - * @tc.desc Test read() interfaces. Callback. - * Undefined option arguments, use default options. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 3 - * @tc.require - */ - it('fileio_test_read_async_012', 3, async function (done) { - let fpath = await nextFileName('fileio_test_read_async_012'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let fd = fileio.openSync(fpath, 0o2); - expect(isIntNum(fd)).assertTrue(); - fileio.read(fd, new ArrayBuffer(16), { - offset: undefined, - length: undefined, - }, (err, readRes1) => { - if(err) { - console.log('fileio_test_read_async_012 err package1: ' + JSON.stringify(err)); - expect(false).assertTrue(); - } - expect(readRes1.bytesRead == FILE_CONTENT.length).assertTrue(); - expect(readRes1.offset == 0).assertTrue(); - fileio.read(fd, new ArrayBuffer(8), { - offset: undefined, - length: undefined, - }, (err, readRes2) => { - if (err) { - console.log('fileio_test_read_async_012 err package2: ' + JSON.stringify(err)); - expect(false).assertTrue(); - } - expect(readRes2.bytesRead == 0).assertTrue(); - expect(readRes2.offset == 0).assertTrue(); - fileio.closeSync(fd); - fileio.unlinkSync(fpath); - done(); - }); - }); - } catch (e) { - console.log('fileio_test_read_async_012 has failed for ' + e); - expect(false).assertTrue(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_READ_ASYNC_READOUT_OFFSET_0000 - * @tc.name fileio_test_read_async_readout_offset_000 - * @tc.desc Test read() ReadOut.offset interfaces. Promise. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_read_async_readout_offset_000', 0, async function (done) { - let fpath = await nextFileName('fileio_test_read_async_readout_offset_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let fd = fileio.openSync(fpath); - expect(isIntNum(fd)).assertTrue(); - let readout = await fileio.read(fd, new ArrayBuffer(4096), { - offset: 1, - }); - expect(readout.offset == 1).assertTrue(); - expect(fileio.closeSync(fd) == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - done(); - } catch (e) { - console.log('fileio_test_read_async_readout_offset_000 has failed for ' + e); - expect(null).assertFail(); - } - }); -}); -} +/* + * Copyright (C) 2021 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 { + fileio, FILE_CONTENT, prepareFile, nextFileName, isIntNum, + describe, it, expect, +} from '../../Common'; + +export default function fileioRead() { +describe('fileio_read', function () { + + /** + * @tc.number SUB_DF_FILEIO_READ_SYNC_0000 + * @tc.name fileio_test_read_sync_000 + * @tc.desc Test readSync() interfaces. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_read_sync_000', 0, async function () { + let fpath = await nextFileName('fileio_test_read_sync_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath, 0o2); + expect(isIntNum(fd)).assertTrue(); + let len = fileio.readSync(fd, new ArrayBuffer(4096)); + expect(len == FILE_CONTENT.length).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_test_read_sync_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_READ_SYNC_0100 + * @tc.name fileio_test_read_sync_001 + * @tc.desc Test readSync() interfaces. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_read_sync_001', 0, async function () { + let bufLen = 5; + expect(FILE_CONTENT.length > bufLen).assertTrue(); + let fpath = await nextFileName('fileio_test_read_sync_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath, 0o2); + expect(isIntNum(fd)).assertTrue(); + let len = fileio.readSync(fd, new ArrayBuffer(bufLen), { + offset: 1, + }); + expect(len == bufLen - 1).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_test_read_sync_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_READ_SYNC_0200 + * @tc.name fileio_test_read_sync_002 + * @tc.desc Test readSync() interfaces. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_read_sync_002', 0, async function () { + let fpath = await nextFileName('fileio_test_read_sync_002'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath, 0o2); + expect(isIntNum(fd)).assertTrue(); + let len = fileio.readSync(fd, new ArrayBuffer(4096), { + length: 1, + }); + expect(len == 1).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_test_read_sync_002 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_READ_SYNC_0300 + * @tc.name fileio_test_read_sync_003 + * @tc.desc Test readSync() interfaces. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_read_sync_003', 0, async function () { + let fpath = await nextFileName('fileio_test_read_sync_003'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath, 0o2); + expect(isIntNum(fd)).assertTrue(); + let len = fileio.readSync(fd, new ArrayBuffer(4096), { + position: 1, + }); + expect(len == FILE_CONTENT.length - 1).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_test_read_sync_003 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_READ_SYNC_0400 + * @tc.name fileio_test_read_sync_004 + * @tc.desc Test readSync() interfaces. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_read_sync_004', 0, async function () { + let fd; + const invalidOffset = 99999; + let fpath = await nextFileName('fileio_test_read_sync_004'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + fd = fileio.openSync(fpath, 0o2); + expect(isIntNum(fd)).assertTrue(); + fileio.readSync(fd, new ArrayBuffer(4096), { + offset: invalidOffset, + }); + expect(null).assertFail(); + } catch (e) { + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_READ_SYNC_0500 + * @tc.name fileio_test_read_sync_005 + * @tc.desc Test readSync() interfaces. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_read_sync_005', 0, async function () { + let fd; + const invalidLength = 9999; + let fpath = await nextFileName('fileio_test_read_sync_005'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + fd = fileio.openSync(fpath, 0o2); + expect(isIntNum(fd)).assertTrue(); + fileio.readSync(fd, new ArrayBuffer(4096), { + length: invalidLength, + }); + expect(null).assertFail(); + } catch (e) { + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_READ_SYNC_0600 + * @tc.name fileio_test_read_sync_006 + * @tc.desc Test readSync() interfaces. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_read_sync_006', 0, async function () { + let fpath = await nextFileName('fileio_test_read_sync_006'); + let fd; + + try { + fileio.readSync(-1, new ArrayBuffer(4096)); + expect(null).assertFail(); + } catch (e) { + console.log('fileio_test_read_sync_006 has failed for ' + e); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_READ_SYNC_0700 + * @tc.name fileio_test_read_sync_007 + * @tc.desc Test readSync() interfaces. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_read_sync_007', 0, async function () { + let fpath = await nextFileName('fileio_test_read_sync_007'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath, 0o2); + expect(isIntNum(fd)).assertTrue(); + let len = fileio.readSync(fd, new ArrayBuffer(4096), { + position: 1, + }); + expect(len == FILE_CONTENT.length - 1).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_test_read_sync_007 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_READ_SYNC_0800 + * @tc.name fileio_test_read_sync_008 + * @tc.desc Test readSync() interfaces. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_read_sync_008', 0, async function () { + let fpath = await nextFileName('fileio_test_read_sync_008'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath, 0o2); + expect(isIntNum(fd)).assertTrue(); + let invalidPos = FILE_CONTENT.length + 1; + let len = fileio.readSync(fd, new ArrayBuffer(4096), { + position: invalidPos, + }); + expect(len == 0).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_test_read_sync_008 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_READ_SYNC_0900 + * @tc.name fileio_test_read_sync_009 + * @tc.desc Test readSync() interfaces. + * Undefined option arguments, use default options. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 3 + * @tc.require + */ + it('fileio_test_read_sync_009', 3, async function () { + let fpath = await nextFileName('fileio_test_read_sync_009'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath, 0o2); + expect(isIntNum(fd)).assertTrue(); + let readLen1 = fileio.readSync(fd, new ArrayBuffer(16), undefined); + expect(readLen1 == FILE_CONTENT.length).assertTrue(); + let readLen2 = fileio.readSync(fd, new ArrayBuffer(8), undefined); + expect(readLen2 == 0).assertTrue(); + fileio.closeSync(fd); + fileio.unlinkSync(fpath); + } catch (e) { + console.log('fileio_test_read_sync_009 has failed for ' + e); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_READ_SYNC_1000 + * @tc.name fileio_test_read_sync_010 + * @tc.desc Test readSync() interfaces. + * Undefined option arguments, use default options. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 3 + * @tc.require + */ + it('fileio_test_read_sync_010', 3, async function () { + let fpath = await nextFileName('fileio_test_read_sync_010'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath, 0o2); + expect(isIntNum(fd)).assertTrue(); + let readLen1 = fileio.readSync(fd, new ArrayBuffer(16), { + offset: undefined, + position: undefined, + length: undefined, + }); + expect(readLen1 == FILE_CONTENT.length).assertTrue(); + let readLen2 = fileio.readSync(fd, new ArrayBuffer(8), { + offset: undefined, + position: undefined, + length: undefined, + }); + expect(readLen2 == 0).assertTrue(); + fileio.closeSync(fd); + fileio.unlinkSync(fpath); + } catch (e) { + console.log('fileio_test_read_sync_010 has failed for ' + e); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_READ_ASYNC_0000 + * @tc.name fileio_test_read_async_000 + * @tc.desc Test read() interfaces. Promise. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_read_async_000', 0, async function (done) { + let fpath = await nextFileName('fileio_test_read_async_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath, 0o2); + expect(isIntNum(fd)).assertTrue(); + let res = await fileio.read(fd, new ArrayBuffer(4096)); + expect(res.bytesRead == FILE_CONTENT.length).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_test_read_async_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_READ_ASYNC_0100 + * @tc.name fileio_test_read_async_001 + * @tc.desc Test read() interfaces. Callback. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_read_async_001', 0, async function (done) { + let fpath = await nextFileName('fileio_test_read_async_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath, 0o2); + expect(isIntNum(fd)).assertTrue(); + fileio.read(fd, new ArrayBuffer(4096), async function (err, data) { + expect(data.bytesRead == FILE_CONTENT.length).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + }); + } catch (e) { + console.log('fileio_test_read_async_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_READ_ASYNC_0200 + * @tc.name fileio_test_read_async_002 + * @tc.desc Test read() interfaces. Promise. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_read_async_002', 0, async function (done) { + let fpath = await nextFileName('fileio_test_read_async_002'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath); + expect(isIntNum(fd)).assertTrue(); + let readout = await fileio.read(fd, new ArrayBuffer(4096)); + expect(readout.buffer.byteLength == 4096).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_test_read_async_002 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_READ_ASYNC_0300 + * @tc.name fileio_test_read_async_003 + * @tc.desc Test read() interfaces. Promise. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_read_async_003', 0, async function (done) { + let fpath = await nextFileName('fileio_test_read_async_003'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath); + expect(isIntNum(fd)).assertTrue(); + let readout = await fileio.read(fd, new ArrayBuffer(4096), { + offset: 1, + }); + expect(readout.bytesRead == FILE_CONTENT.length).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_test_read_async_003 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_READ_ASYNC_0400 + * @tc.name fileio_test_read_async_004 + * @tc.desc Test read() interface. Promise. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_read_async_004', 0, async function (done) { + let fpath = await nextFileName('fileio_test_read_async_004'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath); + expect(isIntNum(fd)).assertTrue(); + let readout = await fileio.read(fd, new ArrayBuffer(4096), { + offset: 1, + length: 3, + }); + expect(readout.bytesRead == 3).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_test_read_async_004 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_READ_ASYNC_0500 + * @tc.name fileio_test_read_async_005 + * @tc.desc Test read() interfaces. Promise. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_read_async_005', 0, async function (done) { + let fpath = await nextFileName('fileio_test_read_async_005'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath); + expect(isIntNum(fd)).assertTrue(); + let readout = await fileio.read(fd, new ArrayBuffer(5), { + offset: 1, + }); + expect(readout.bytesRead == 4).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_test_read_async_005 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_READ_ASYNC_0600 + * @tc.name fileio_test_read_async_006 + * @tc.desc Test read() interfaces. Promise. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_read_async_006', 0, async function (done) { + let fd; + const invalidOffset = 999; + let fpath = await nextFileName('fileio_test_read_async_006'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + fd = fileio.openSync(fpath, 0o2); + expect(isIntNum(fd)).assertTrue(); + await fileio.read(fd, new ArrayBuffer(4096), { + offset: invalidOffset, + }); + throw new Error('invalid offset'); + } catch (e) { + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_READ_ASYNC_0700 + * @tc.name fileio_test_read_async_007 + * @tc.desc Test read() interfaces. Promise. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_read_async_007', 0, async function (done) { + let fpath = await nextFileName('fileio_test_read_async_007'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let fd; + + try { + fd = fileio.openSync(fpath, 0o2); + expect(isIntNum(fd)).assertTrue(); + let invalidPos = FILE_CONTENT.length + 1; + let err = await fileio.read(fd, new ArrayBuffer(4096), { + offset: 1, + position: invalidPos, + }); + expect(!!err).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_test_read_async_007 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_READ_ASYNC_0800 + * @tc.name fileio_test_read_async_008 + * @tc.desc Test read() interfaces. Promise. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_read_async_008', 0, async function (done) { + try { + await fileio.read(-1, new ArrayBuffer(4096)); + expect(null).assertFail(); + } catch (e) { + console.info('fileio_test_read_async_008 has failed for ' + e); + done(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_READ_ASYNC_0900 + * @tc.name fileio_test_read_async_009 + * @tc.desc Test read() interfaces. Promise. + * Undefined option arguments, use default options. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 3 + * @tc.require + */ + it('fileio_test_read_async_009', 3, async function (done) { + let fpath = await nextFileName('fileio_test_read_async_009'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath, 0o2); + expect(isIntNum(fd)).assertTrue(); + let readRes1 = await fileio.read(fd, new ArrayBuffer(16), undefined); + expect(readRes1.bytesRead == FILE_CONTENT.length).assertTrue(); + expect(readRes1.offset == 0).assertTrue(); + let readRes2 = await fileio.read(fd, new ArrayBuffer(8), undefined); + expect(readRes2.bytesRead == 0).assertTrue(); + expect(readRes2.offset == 0).assertTrue(); + fileio.closeSync(fd); + fileio.unlinkSync(fpath); + done(); + } catch (e) { + console.log('fileio_test_read_async_009 has failed for ' + e); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_READ_ASYNC_1000 + * @tc.name fileio_test_read_async_010 + * @tc.desc Test read() interfaces. Callback. + * Undefined option arguments, use default options. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 3 + * @tc.require + */ + it('fileio_test_read_async_010', 3, async function (done) { + let fpath = await nextFileName('fileio_test_read_async_010'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath, 0o2); + expect(isIntNum(fd)).assertTrue(); + fileio.read(fd, new ArrayBuffer(16), undefined, (err, readRes1) => { + if(err) { + console.log('fileio_test_read_async_010 err package1: ' + JSON.stringify(err)); + expect(false).assertTrue(); + } + expect(readRes1.bytesRead == FILE_CONTENT.length).assertTrue(); + expect(readRes1.offset == 0).assertTrue(); + fileio.read(fd, new ArrayBuffer(8), undefined, (err, readRes2) => { + if(err) { + console.log('fileio_test_read_async_010 err package2: ' + JSON.stringify(err)); + expect(false).assertTrue(); + } + expect(readRes2.bytesRead == 0).assertTrue(); + expect(readRes2.offset == 0).assertTrue(); + fileio.closeSync(fd); + fileio.unlinkSync(fpath); + done(); + }); + }); + } catch (e) { + console.log('fileio_test_read_async_010 has failed for ' + e); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_READ_ASYNC_1100 + * @tc.name fileio_test_read_async_011 + * @tc.desc Test read() interfaces. Promise. + * Undefined option arguments, use default options. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 3 + * @tc.require + */ + it('fileio_test_read_async_011', 3, async function (done) { + let fpath = await nextFileName('fileio_test_read_async_011'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath, 0o2); + expect(isIntNum(fd)).assertTrue(); + let readRes1 = await fileio.read(fd, new ArrayBuffer(4096), { + offset: undefined, + length: undefined, + }); + expect(readRes1.bytesRead == FILE_CONTENT.length).assertTrue(); + expect(readRes1.offset == 0).assertTrue(); + let readRes2 = await fileio.read(fd, new ArrayBuffer(4096), { + offset: undefined, + length: undefined, + }); + expect(readRes2.bytesRead == 0).assertTrue(); + expect(readRes2.offset == 0).assertTrue(); + fileio.closeSync(fd); + fileio.unlinkSync(fpath); + done(); + } catch (e) { + console.log('fileio_test_read_async_011 has failed for ' + e); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_READ_ASYNC_1200 + * @tc.name fileio_test_read_async_012 + * @tc.desc Test read() interfaces. Callback. + * Undefined option arguments, use default options. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 3 + * @tc.require + */ + it('fileio_test_read_async_012', 3, async function (done) { + let fpath = await nextFileName('fileio_test_read_async_012'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath, 0o2); + expect(isIntNum(fd)).assertTrue(); + fileio.read(fd, new ArrayBuffer(16), { + offset: undefined, + length: undefined, + }, (err, readRes1) => { + if(err) { + console.log('fileio_test_read_async_012 err package1: ' + JSON.stringify(err)); + expect(false).assertTrue(); + } + expect(readRes1.bytesRead == FILE_CONTENT.length).assertTrue(); + expect(readRes1.offset == 0).assertTrue(); + fileio.read(fd, new ArrayBuffer(8), { + offset: undefined, + length: undefined, + }, (err, readRes2) => { + if (err) { + console.log('fileio_test_read_async_012 err package2: ' + JSON.stringify(err)); + expect(false).assertTrue(); + } + expect(readRes2.bytesRead == 0).assertTrue(); + expect(readRes2.offset == 0).assertTrue(); + fileio.closeSync(fd); + fileio.unlinkSync(fpath); + done(); + }); + }); + } catch (e) { + console.log('fileio_test_read_async_012 has failed for ' + e); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_READ_ASYNC_READOUT_OFFSET_0000 + * @tc.name fileio_test_read_async_readout_offset_000 + * @tc.desc Test read() ReadOut.offset interfaces. Promise. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_read_async_readout_offset_000', 0, async function (done) { + let fpath = await nextFileName('fileio_test_read_async_readout_offset_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath); + expect(isIntNum(fd)).assertTrue(); + let readout = await fileio.read(fd, new ArrayBuffer(4096), { + offset: 1, + }); + expect(readout.offset == 1).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_test_read_async_readout_offset_000 has failed for ' + e); + expect(null).assertFail(); + } + }); +}); +} diff --git a/storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/members/readtext.test.js b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/readtext.test.js similarity index 96% rename from storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/members/readtext.test.js rename to storage/storagefileiojstest/src/main/js/test/module_fileio/members/readtext.test.js index 0e2c29a453886b8937431475a978e8272af0f643..279cfcc9c20527676ca6f73ff3350cfc4e8a17ad 100644 --- a/storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/members/readtext.test.js +++ b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/readtext.test.js @@ -1,413 +1,413 @@ -/* - * Copyright (C) 2023 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 { - fileio, FILE_CONTENT, prepareFile, nextFileName, - describe, it, expect, -} from '../../Common'; - -export default function fileioReadtext() { -describe('fileio_readtext', function () { - - /** - * @tc.number SUB_DF_FILEIO_READ_TEXT_SYNC_0000 - * @tc.name fileio_test_readtext_sync_000 - * @tc.desc Test readtextSync() interfaces. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_readtext_sync_000', 0, async function () { - let fpath = await nextFileName('fileio_test_readtext_sync_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let str = fileio.readTextSync(fpath); - expect(str == FILE_CONTENT).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - } catch (e) { - console.log('fileio_test_readtext_sync_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_READ_TEXT_SYNC_0100 - * @tc.name fileio_test_readtext_sync_001 - * @tc.desc Test readtextSync() interfaces. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_readtext_sync_001', 0, async function () { - let fpath = await nextFileName('fileio_test_readtext_sync_001'); - let pos = 1; - let len = 0; - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let str = fileio.readTextSync(fpath, { position: pos }); - expect(str == FILE_CONTENT.substring(pos, FILE_CONTENT.length + 1)).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - } catch (e) { - console.log('fileio_test_readtext_sync_001 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_READ_TEXT_SYNC_0200 - * @tc.name fileio_test_readtext_sync_002 - * @tc.desc Test readtextSync() interfaces. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_readtext_sync_002', 0, async function () { - let fpath = await nextFileName('fileio_test_readtext_sync_002'); - let pos = 1; - let len = FILE_CONTENT.length; - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let str = fileio.readTextSync(fpath, { position: pos, length: len }); - expect(str == FILE_CONTENT.substring(pos, len + 1)).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - } catch (e) { - console.log('fileio_test_readtext_sync_002 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_READ_TEXT_SYNC_0300 - * @tc.name fileio_test_readtext_sync_003 - * @tc.desc Test readtextSync() interfaces. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_readtext_sync_003', 0, function () { - try { - fileio.readTextSync(); - expect(null).assertFail(); - } catch (e) { - console.log('fileio_test_readtext_sync_003 has failed for ' + e); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_READ_TEXT_SYNC_0400 - * @tc.name fileio_test_readtext_sync_004 - * @tc.desc Test readtextSync() interfaces. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_readtext_sync_004', 0, async function () { - let fpath = await nextFileName('fileio_test_readtext_sync_004'); - - try { - fileio.readTextSync(fpath); - expect(null).assertFail(); - } catch (e) { - console.log('fileio_test_readtext_sync_004 has failed for ' + e); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_READ_TEXT_SYNC_0500 - * @tc.name fileio_test_readtext_sync_005 - * @tc.desc Test readtextSync() interfaces. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_readtext_sync_005', 0, async function () { - const invalidLength = -1; - let fpath = await nextFileName('fileio_test_readtext_sync_005'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - fileio.readTextSync(fpath, { length: invalidLength }); - expect(false).assertTrue(); - } catch (e) { - fileio.unlinkSync(fpath); - console.log('fileio_test_readtext_sync_005 has failed for ' + e); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_READ_TEXT_SYNC_0600 - * @tc.name fileio_test_readtext_sync_006 - * @tc.desc Test readtextSync() interfaces. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 3 - * @tc.require - */ - it('fileio_test_readtext_sync_006', 3, async function () { - let fpath = await nextFileName('fileio_test_readtext_sync_006'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let str = fileio.readTextSync(fpath, undefined); - expect(str == FILE_CONTENT).assertTrue(); - fileio.unlinkSync(fpath); - } catch (e) { - console.log('fileio_test_readtext_sync_006 has failed for ' + e); - expect(false).assertTrue(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_READ_TEXT_SYNC_0700 - * @tc.name fileio_test_readtext_sync_007 - * @tc.desc Test readtextSync() interfaces. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 3 - * @tc.require - */ - it('fileio_test_readtext_sync_007', 3, async function () { - let fpath = await nextFileName('fileio_test_readtext_sync_007'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let str = fileio.readTextSync(fpath, { - position: undefined, - length: undefined, - encoding: undefined, - }); - expect(str == FILE_CONTENT).assertTrue(); - fileio.unlinkSync(fpath); - } catch (e) { - console.log('fileio_test_readtext_sync_007 has failed for ' + e); - expect(false).assertTrue(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_READ_TEXT_ASYNC_0000 - * @tc.name fileio_test_readtext_async_000 - * @tc.desc Test readtext() interfaces. Callback. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_readtext_async_000', 0, async function (done) { - let fpath = await nextFileName('fileio_test_readtext_async_000'); - let pos = 1; - let len = FILE_CONTENT.length; - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - fileio.readText(fpath, { position: pos, length: len, encoding: 'utf-8' }, function (err, str) { - expect(str == FILE_CONTENT.substr(pos, len)).assertTrue(); - fileio.unlinkSync(fpath); - done(); - }); - } catch (e) { - console.log('fileio_test_readtext_async_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_READ_TEXT_ASYNC_0100 - * @tc.name fileio_test_readtext_async_001 - * @tc.desc Test readtext() interfaces. Callback. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_readtext_async_001', 0, async function (done) { - let fpath = await nextFileName('fileio_test_readtext_async_001'); - let pos = 1; - let len = FILE_CONTENT.length; - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - fileio.readText(fpath, { position: 1 }, function (err, str) { - expect(str == FILE_CONTENT.substr(pos, len)).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - done(); - }); - } catch (e) { - console.log('fileio_test_readtext_async_001 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_READ_TEXT_ASYNC_0200 - * @tc.name fileio_test_readtext_async_002 - * @tc.desc Test readtext() interfaces. Callback. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_readtext_async_002', 0, async function (done) { - let fpath = await nextFileName('fileio_test_readtext_async_002'); - let pos = 1; - let len = FILE_CONTENT.length; - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - fileio.readText(fpath, { position: 1 }, function (err, str) { - expect(str == FILE_CONTENT.substr(pos, len)).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - }); - fileio.readText(fpath, { position: 1 }) - .then(function (str) { - expect(str == FILE_CONTENT.substr(pos, len)).assertTrue(); - }) - .catch(function (e) { - expect(e == null).assertTrue(); - }); - done(); - } catch (e) { - console.log('fileio_test_readtext_async_002 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_READ_TEXT_SYNC_0300 - * @tc.name fileio_test_readtext_async_003 - * @tc.desc Test readtext() interfaces. Promise. - * Use default option. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 3 - * @tc.require - */ - it('fileio_test_readtext_async_003', 3, async function (done) { - let fpath = await nextFileName('fileio_test_readtext_async_003'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let str = await fileio.readText(fpath, undefined); - expect(str == FILE_CONTENT).assertTrue(); - fileio.unlinkSync(fpath); - done(); - } catch (e) { - console.log('fileio_test_readtext_async_003 has failed for ' + e); - expect(false).assertTrue(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_READ_TEXT_SYNC_0400 - * @tc.name fileio_test_readtext_async_004 - * @tc.desc Test readtext() interfaces. Callback. - * Use default option. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 3 - * @tc.require - */ - it('fileio_test_readtext_async_004', 3, async function (done) { - let fpath = await nextFileName('fileio_test_readtext_async_004'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - fileio.readText(fpath, undefined, (err, str) => { - if (err) { - console.log('fileio_test_readtext_async_004 error package: ' + JSON.stringify(err)); - expect(false).assertTrue(); - } - expect(str == FILE_CONTENT).assertTrue(); - fileio.unlinkSync(fpath); - done(); - }); - } catch (e) { - console.log('fileio_test_readtext_async_004 has failed for ' + e); - expect(false).assertTrue(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_READ_TEXT_SYNC_0500 - * @tc.name fileio_test_readtext_async_005 - * @tc.desc Test readtext() interfaces. Promise. - * Use default option. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 3 - * @tc.require - */ - it('fileio_test_readtext_async_005', 3, async function (done) { - let fpath = await nextFileName('fileio_test_readtext_async_005'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let str = await fileio.readText(fpath, { - position: undefined, - length: undefined, - encoding: undefined, - }); - expect(str == FILE_CONTENT).assertTrue(); - fileio.unlinkSync(fpath); - done(); - } catch (e) { - console.log('fileio_test_readtext_async_005 has failed for ' + e); - expect(false).assertTrue(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_READ_TEXT_SYNC_0600 - * @tc.name fileio_test_readtext_async_006 - * @tc.desc Test readtext() interfaces. Callback. - * Use default option. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 3 - * @tc.require - */ - it('fileio_test_readtext_async_006', 3, async function (done) { - let fpath = await nextFileName('fileio_test_readtext_async_006'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - fileio.readText(fpath, { - position: undefined, - length: undefined, - encoding: undefined, - }, (err, str) => { - if (err) { - console.log('fileio_test_readtext_async_006 error package: ' + JSON.stringify(err)); - expect(false).assertTrue(); - } - expect(str == FILE_CONTENT).assertTrue(); - fileio.unlinkSync(fpath); - done(); - }); - } catch (e) { - console.log('fileio_test_readtext_async_006 has failed for ' + e); - expect(false).assertTrue(); - } - }); -}); -} +/* + * Copyright (C) 2021 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 { + fileio, FILE_CONTENT, prepareFile, nextFileName, + describe, it, expect, +} from '../../Common'; + +export default function fileioReadtext() { +describe('fileio_readtext', function () { + + /** + * @tc.number SUB_DF_FILEIO_READ_TEXT_SYNC_0000 + * @tc.name fileio_test_readtext_sync_000 + * @tc.desc Test readtextSync() interfaces. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_readtext_sync_000', 0, async function () { + let fpath = await nextFileName('fileio_test_readtext_sync_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let str = fileio.readTextSync(fpath); + expect(str == FILE_CONTENT).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_test_readtext_sync_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_READ_TEXT_SYNC_0100 + * @tc.name fileio_test_readtext_sync_001 + * @tc.desc Test readtextSync() interfaces. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_readtext_sync_001', 0, async function () { + let fpath = await nextFileName('fileio_test_readtext_sync_001'); + let pos = 1; + let len = 0; + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let str = fileio.readTextSync(fpath, { position: pos }); + expect(str == FILE_CONTENT.substring(pos, FILE_CONTENT.length + 1)).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_test_readtext_sync_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_READ_TEXT_SYNC_0200 + * @tc.name fileio_test_readtext_sync_002 + * @tc.desc Test readtextSync() interfaces. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_readtext_sync_002', 0, async function () { + let fpath = await nextFileName('fileio_test_readtext_sync_002'); + let pos = 1; + let len = FILE_CONTENT.length; + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let str = fileio.readTextSync(fpath, { position: pos, length: len }); + expect(str == FILE_CONTENT.substring(pos, len + 1)).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_test_readtext_sync_002 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_READ_TEXT_SYNC_0300 + * @tc.name fileio_test_readtext_sync_003 + * @tc.desc Test readtextSync() interfaces. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_readtext_sync_003', 0, function () { + try { + fileio.readTextSync(); + expect(null).assertFail(); + } catch (e) { + console.log('fileio_test_readtext_sync_003 has failed for ' + e); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_READ_TEXT_SYNC_0400 + * @tc.name fileio_test_readtext_sync_004 + * @tc.desc Test readtextSync() interfaces. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_readtext_sync_004', 0, async function () { + let fpath = await nextFileName('fileio_test_readtext_sync_004'); + + try { + fileio.readTextSync(fpath); + expect(null).assertFail(); + } catch (e) { + console.log('fileio_test_readtext_sync_004 has failed for ' + e); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_READ_TEXT_SYNC_0500 + * @tc.name fileio_test_readtext_sync_005 + * @tc.desc Test readtextSync() interfaces. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_readtext_sync_005', 0, async function () { + const invalidLength = -1; + let fpath = await nextFileName('fileio_test_readtext_sync_005'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + fileio.readTextSync(fpath, { length: invalidLength }); + expect(false).assertTrue(); + } catch (e) { + fileio.unlinkSync(fpath); + console.log('fileio_test_readtext_sync_005 has failed for ' + e); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_READ_TEXT_SYNC_0600 + * @tc.name fileio_test_readtext_sync_006 + * @tc.desc Test readtextSync() interfaces. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 3 + * @tc.require + */ + it('fileio_test_readtext_sync_006', 3, async function () { + let fpath = await nextFileName('fileio_test_readtext_sync_006'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let str = fileio.readTextSync(fpath, undefined); + expect(str == FILE_CONTENT).assertTrue(); + fileio.unlinkSync(fpath); + } catch (e) { + console.log('fileio_test_readtext_sync_006 has failed for ' + e); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_READ_TEXT_SYNC_0700 + * @tc.name fileio_test_readtext_sync_007 + * @tc.desc Test readtextSync() interfaces. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 3 + * @tc.require + */ + it('fileio_test_readtext_sync_007', 3, async function () { + let fpath = await nextFileName('fileio_test_readtext_sync_007'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let str = fileio.readTextSync(fpath, { + position: undefined, + length: undefined, + encoding: undefined, + }); + expect(str == FILE_CONTENT).assertTrue(); + fileio.unlinkSync(fpath); + } catch (e) { + console.log('fileio_test_readtext_sync_007 has failed for ' + e); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_READ_TEXT_ASYNC_0000 + * @tc.name fileio_test_readtext_async_000 + * @tc.desc Test readtext() interfaces. Callback. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_readtext_async_000', 0, async function (done) { + let fpath = await nextFileName('fileio_test_readtext_async_000'); + let pos = 1; + let len = FILE_CONTENT.length; + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + fileio.readText(fpath, { position: pos, length: len, encoding: 'utf-8' }, function (err, str) { + expect(str == FILE_CONTENT.substr(pos, len)).assertTrue(); + fileio.unlinkSync(fpath); + done(); + }); + } catch (e) { + console.log('fileio_test_readtext_async_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_READ_TEXT_ASYNC_0100 + * @tc.name fileio_test_readtext_async_001 + * @tc.desc Test readtext() interfaces. Callback. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_readtext_async_001', 0, async function (done) { + let fpath = await nextFileName('fileio_test_readtext_async_001'); + let pos = 1; + let len = FILE_CONTENT.length; + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + fileio.readText(fpath, { position: 1 }, function (err, str) { + expect(str == FILE_CONTENT.substr(pos, len)).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + }); + } catch (e) { + console.log('fileio_test_readtext_async_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_READ_TEXT_ASYNC_0200 + * @tc.name fileio_test_readtext_async_002 + * @tc.desc Test readtext() interfaces. Callback. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_readtext_async_002', 0, async function (done) { + let fpath = await nextFileName('fileio_test_readtext_async_002'); + let pos = 1; + let len = FILE_CONTENT.length; + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + fileio.readText(fpath, { position: 1 }, function (err, str) { + expect(str == FILE_CONTENT.substr(pos, len)).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + }); + fileio.readText(fpath, { position: 1 }) + .then(function (str) { + expect(str == FILE_CONTENT.substr(pos, len)).assertTrue(); + }) + .catch(function (e) { + expect(e == null).assertTrue(); + }); + done(); + } catch (e) { + console.log('fileio_test_readtext_async_002 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_READ_TEXT_SYNC_0300 + * @tc.name fileio_test_readtext_async_003 + * @tc.desc Test readtext() interfaces. Promise. + * Use default option. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 3 + * @tc.require + */ + it('fileio_test_readtext_async_003', 3, async function (done) { + let fpath = await nextFileName('fileio_test_readtext_async_003'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let str = await fileio.readText(fpath, undefined); + expect(str == FILE_CONTENT).assertTrue(); + fileio.unlinkSync(fpath); + done(); + } catch (e) { + console.log('fileio_test_readtext_async_003 has failed for ' + e); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_READ_TEXT_SYNC_0400 + * @tc.name fileio_test_readtext_async_004 + * @tc.desc Test readtext() interfaces. Callback. + * Use default option. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 3 + * @tc.require + */ + it('fileio_test_readtext_async_004', 3, async function (done) { + let fpath = await nextFileName('fileio_test_readtext_async_004'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + fileio.readText(fpath, undefined, (err, str) => { + if (err) { + console.log('fileio_test_readtext_async_004 error package: ' + JSON.stringify(err)); + expect(false).assertTrue(); + } + expect(str == FILE_CONTENT).assertTrue(); + fileio.unlinkSync(fpath); + done(); + }); + } catch (e) { + console.log('fileio_test_readtext_async_004 has failed for ' + e); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_READ_TEXT_SYNC_0500 + * @tc.name fileio_test_readtext_async_005 + * @tc.desc Test readtext() interfaces. Promise. + * Use default option. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 3 + * @tc.require + */ + it('fileio_test_readtext_async_005', 3, async function (done) { + let fpath = await nextFileName('fileio_test_readtext_async_005'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let str = await fileio.readText(fpath, { + position: undefined, + length: undefined, + encoding: undefined, + }); + expect(str == FILE_CONTENT).assertTrue(); + fileio.unlinkSync(fpath); + done(); + } catch (e) { + console.log('fileio_test_readtext_async_005 has failed for ' + e); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_READ_TEXT_SYNC_0600 + * @tc.name fileio_test_readtext_async_006 + * @tc.desc Test readtext() interfaces. Callback. + * Use default option. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 3 + * @tc.require + */ + it('fileio_test_readtext_async_006', 3, async function (done) { + let fpath = await nextFileName('fileio_test_readtext_async_006'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + fileio.readText(fpath, { + position: undefined, + length: undefined, + encoding: undefined, + }, (err, str) => { + if (err) { + console.log('fileio_test_readtext_async_006 error package: ' + JSON.stringify(err)); + expect(false).assertTrue(); + } + expect(str == FILE_CONTENT).assertTrue(); + fileio.unlinkSync(fpath); + done(); + }); + } catch (e) { + console.log('fileio_test_readtext_async_006 has failed for ' + e); + expect(false).assertTrue(); + } + }); +}); +} diff --git a/storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/members/rename.test.js b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/rename.test.js similarity index 95% rename from storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/members/rename.test.js rename to storage/storagefileiojstest/src/main/js/test/module_fileio/members/rename.test.js index 5ecc29c059f1d42626bca9a6162c34cec45e80d8..f54e9f9969b53bd901c2d1738049432099a9587f 100644 --- a/storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/members/rename.test.js +++ b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/rename.test.js @@ -1,109 +1,109 @@ -/* - * Copyright (C) 2023 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 { - fileio, FILE_CONTENT, prepareFile, nextFileName, - describe, it, expect, -} from '../../Common'; -export default function fileioRename() { -describe('fileio_rename', function () { - - /** - * @tc.number SUB_DF_FILEIO_RENAME_ASYNC_0000 - * @tc.name fileio_test_rename_async_000 - * @tc.desc Test renameAsync() interfaces. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_rename_async_000', 0, async function (done) { - let fpath = await nextFileName('fileio_test_rename_async_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let newf = fpath + '123'; - fileio.rename(fpath, newf) - .then(function (err) { - expect(fileio.accessSync(newf) == null).assertTrue(); - expect(err == null).assertTrue(); - expect(fileio.unlinkSync(newf) == null).assertTrue(); - }) - .catch(function (e) { - expect(e == null).assertTrue(); - }) - done(); - } catch (e) { - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_RENAME_ASYNC_0010 - * @tc.name fileio_test_rename_async_001 - * @tc.desc Test renameAsync() interfaces. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_rename_async_001', 0, async function (done) { - let fpath = await nextFileName('fileio_test_rename_async_001'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let newf = fpath + 'aaa'; - fileio.rename(fpath, newf, function (err) { - expect(fileio.accessSync(newf) == null).assertTrue(); - expect(fileio.unlinkSync(newf) == null).assertTrue(); - done(); - }) - } catch (e) { - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_RENAME_ASYNC_0020 - * @tc.name fileio_test_rename_async_002 - * @tc.desc Test renameAsync() interfaces. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_rename_async_002', 0, async function (done) { - let fpath = await nextFileName('fileio_test_rename_async_002'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - fileio.access(fpath).then(function (err) { - let newf = fpath + '123'; - fileio.rename(fpath, newf) - .then(function (err) { - expect(fileio.accessSync(newf) == null).assertTrue(); - expect(err == null).assertTrue(); - expect(fileio.unlinkSync(newf) == null).assertTrue(); - }) - }) - .catch(function (e) { - expect(e == null).assertTrue(); - }) - done(); - } catch (e) { - expect(null).assertFail(); - } - }); -});} +/* + * Copyright (C) 2021 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 { + fileio, FILE_CONTENT, prepareFile, nextFileName, + describe, it, expect, +} from '../../Common'; +export default function fileioRename() { +describe('fileio_rename', function () { + + /** + * @tc.number SUB_DF_FILEIO_RENAME_ASYNC_0000 + * @tc.name fileio_test_rename_async_000 + * @tc.desc Test renameAsync() interfaces. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_rename_async_000', 0, async function (done) { + let fpath = await nextFileName('fileio_test_rename_async_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let newf = fpath + '123'; + fileio.rename(fpath, newf) + .then(function (err) { + expect(fileio.accessSync(newf) == null).assertTrue(); + expect(err == null).assertTrue(); + expect(fileio.unlinkSync(newf) == null).assertTrue(); + }) + .catch(function (e) { + expect(e == null).assertTrue(); + }) + done(); + } catch (e) { + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_RENAME_ASYNC_0010 + * @tc.name fileio_test_rename_async_001 + * @tc.desc Test renameAsync() interfaces. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_rename_async_001', 0, async function (done) { + let fpath = await nextFileName('fileio_test_rename_async_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let newf = fpath + 'aaa'; + fileio.rename(fpath, newf, function (err) { + expect(fileio.accessSync(newf) == null).assertTrue(); + expect(fileio.unlinkSync(newf) == null).assertTrue(); + done(); + }) + } catch (e) { + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_RENAME_ASYNC_0020 + * @tc.name fileio_test_rename_async_002 + * @tc.desc Test renameAsync() interfaces. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_rename_async_002', 0, async function (done) { + let fpath = await nextFileName('fileio_test_rename_async_002'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + fileio.access(fpath).then(function (err) { + let newf = fpath + '123'; + fileio.rename(fpath, newf) + .then(function (err) { + expect(fileio.accessSync(newf) == null).assertTrue(); + expect(err == null).assertTrue(); + expect(fileio.unlinkSync(newf) == null).assertTrue(); + }) + }) + .catch(function (e) { + expect(e == null).assertTrue(); + }) + done(); + } catch (e) { + expect(null).assertFail(); + } + }); +});} diff --git a/storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/members/rmdir.test.js b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/rmdir.test.js similarity index 96% rename from storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/members/rmdir.test.js rename to storage/storagefileiojstest/src/main/js/test/module_fileio/members/rmdir.test.js index 43de9d7cfc33c01f6f48b35bf7a6ea3e3ee55429..9e1f2fde3d2936f83d98e089766084be78194452 100644 --- a/storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/members/rmdir.test.js +++ b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/rmdir.test.js @@ -1,430 +1,430 @@ -/* - * Copyright (C) 2023 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 { - fileio, FILE_CONTENT, prepareFile, nextFileName, randomString, isInclude, - describe, it, expect, -} from '../../Common'; -export default function fileioRmdir() { -describe('fileio_rmdir', function () { - - /** - * @tc.number SUB_STORAGE_FileIO_RMDIR_SYNC_0000 - * @tc.name fileio_test_rmdir_sync_000 - * @tc.desc Test rmdirSync() interface. - * Recursively delete all files and subfolders in a directory. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_rmdir_sync_000', 0, async function () { - let dpath = await nextFileName('fileio_test_rmdir_sync_000') + 'd'; - let fpath = dpath + '/rmdir_sync_000'; - let ddpath = dpath + '/rmdir_sync_000_1d'; - fileio.mkdirSync(dpath); - fileio.mkdirSync(ddpath); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - fileio.rmdirSync(dpath); - } catch (err) { - console.info('fileio_test_rmdir_sync_000 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_RMDIR_SYNC_0100 - * @tc.name fileio_test_rmdir_sync_001 - * @tc.desc Test rmdirSync() interface. - * Recursively delete all files and subfolders in a directory. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_rmdir_sync_001', 0, async function () { - let dpath = await nextFileName('fileio_test_rmdir_sync_001') + 'd'; - let fpath = dpath + '/rmdir_sync_001'; - let ffpath = dpath + '/rmdir_sync_001_1'; - let ddpath = dpath + '/rmdir_sync_001_1d'; - let fffpath = ddpath + '/rmdir_sync_002'; - fileio.mkdirSync(dpath); - fileio.mkdirSync(ddpath); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - expect(prepareFile(ffpath, FILE_CONTENT)).assertTrue(); - expect(prepareFile(fffpath, FILE_CONTENT)).assertTrue(); - - try { - fileio.rmdirSync(dpath); - } catch (err) { - console.info('fileio_test_rmdir_sync_001 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_RMDIR_SYNC_0200 - * @tc.name fileio_test_rmdir_sync_002 - * @tc.desc Test rmdirSync() interface. - * Recursively delete all files and subfolders in a directory. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_rmdir_sync_002', 0, async function () { - let dpath = await nextFileName('fileio_test_rmdir_sync_002') + 'd'; - fileio.mkdirSync(dpath); - let fdpath = dpath; - - try { - for (let i = 0; i < 113; i++) { - let fpath = dpath + '/f' + randomString(10) + i; - fileio.openSync(fpath, 0o102, 0o777); - dpath = dpath + '/d' + randomString(10) + i; - fileio.mkdirSync(dpath); - } - fileio.rmdirSync(fdpath); - } catch (err) { - console.info('fileio_test_rmdir_sync_002 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_RMDIR_SYNC_0300 - * @tc.name fileio_test_rmdir_sync_003 - * @tc.desc Test rmdirSync() interface. The path contains ../, normal call. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_rmdir_sync_003', 0, async function () { - let dpath = await nextFileName('../cache/fileio_test_rmdir_sync_003') + 'd'; - - try { - fileio.mkdirSync(dpath); - fileio.rmdirSync(dpath); - } catch (err) { - console.info('fileio_test_rmdir_sync_003 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_RMDIR_SYNC_0400 - * @tc.name fileio_test_rmdir_sync_004 - * @tc.desc Test rmdirSync() interface. Invalid path. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_rmdir_sync_004', 0, async function () { - let dpath = await nextFileName('fileio_test_rmdir_sync_004') + 'd'; - - try { - fileio.rmdirSync(dpath); - } catch (err) { - console.info('fileio_test_rmdir_sync_004 has failed for ' + err); - expect(isInclude(err.message, 'No such file or directory')).assertTrue(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_RMDIR_SYNC_0500 - * @tc.name fileio_test_rmdir_sync_005 - * @tc.desc Test rmdirSync() interface. No parameters. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_rmdir_sync_005', 0, async function () { - try { - fileio.rmdirSync(); - } catch (err) { - console.info('fileio_test_rmdir_sync_005 has failed for ' + err); - expect(isInclude(err.message, 'Number of arguments unmatched')).assertTrue(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_RMDIR_SYNC_0600 - * @tc.name fileio_test_rmdir_sync_006 - * @tc.desc Test rmdirSync() interface. Invalid path. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_rmdir_sync_006', 0, async function () { - try { - fileio.rmdirSync(''); - } catch (err) { - console.info('fileio_test_rmdir_sync_006 has failed for ' + err); - expect(isInclude(err.message, 'No such file or directory')).assertTrue(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_RMDIR_SYNC_0700 - * @tc.name fileio_test_rmdir_sync_007 - * @tc.desc Test rmdirSync() interface. Not a directory. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_rmdir_sync_007', 0, async function () { - let fpath = await nextFileName('fileio_test_rmdir_sync_007'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - fileio.rmdirSync(fpath); - } catch (err) { - console.info('fileio_test_rmdir_sync_007 has failed for ' + err); - expect(isInclude(err.message, 'Not a directory')).assertTrue(); - fileio.unlinkSync(fpath); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_RMDIR_ASYNC_0000 - * @tc.name fileio_test_rmdir_async_000 - * @tc.desc Test rmdir() interface, return in promise mode. - * Recursively delete all files and subfolders in a directory. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_rmdir_async_000', 0, async function (done) { - let dpath = await nextFileName('fileio_test_rmdir_async_000') + 'd'; - fileio.mkdirSync(dpath); - let fdpath = dpath; - - try { - for (let i = 0; i < 113; i++) { - let fpath = dpath + '/f' + randomString(10) + i; - await fileio.open(fpath, 0o102, 0o777); - dpath = dpath + '/d' + randomString(10) + i; - await fileio.mkdir(dpath); - } - await fileio.rmdir(fdpath); - done(); - } catch (err) { - console.info('fileio_test_rmdir_async_000 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_RMDIR_ASYNC_0100 - * @tc.name fileio_test_rmdir_async_001 - * @tc.desc Test rmdir() interface, return in callback mode. - * Recursively delete all files and subfolders in a directory. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_rmdir_async_001', 0, async function (done) { - let dpath = await nextFileName('fileio_test_rmdir_async_001') + 'd'; - fileio.mkdirSync(dpath); - let fdpath = dpath; - - try { - for (let i = 0; i < 113; i++) { - let fpath = dpath + '/f' + randomString(10) + i; - await fileio.open(fpath, 0o102, 0o777); - dpath = dpath + '/d' + randomString(10) + i; - await fileio.mkdir(dpath); - } - fileio.rmdir(fdpath, function () { - done(); - }); - } catch (err) { - console.info('fileio_test_rmdir_async_001 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_RMDIR_ASYNC_0200 - * @tc.name fileio_test_rmdir_async_002 - * @tc.desc Test rmdir() interface, return in promise mode. - * Recursively delete all files and subfolders in a directory. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_rmdir_async_002', 0, async function (done) { - let dpath = await nextFileName('fileio_test_rmdir_async_002') + 'd'; - let fpath = dpath + '/rmdir_async_002'; - let ddpath = dpath + '/rmdir_async_002_1d'; - fileio.mkdirSync(dpath); - fileio.mkdirSync(ddpath); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - await fileio.rmdir(dpath); - done() - } catch (err) { - console.info('fileio_test_rmdir_async_002 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_RMDIR_ASYNC_0300 - * @tc.name fileio_test_rmdir_async_003 - * @tc.desc Test rmdir() interface, return in callback mode. - * Recursively delete all files and subfolders in a directory. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_rmdir_async_003', 0, async function (done) { - let dpath = await nextFileName('fileio_test_rmdir_async_003') + 'd'; - let fpath = dpath + '/rmdir_async_003'; - let ffpath = dpath + '/rmdir_async_003_1'; - let ddpath = dpath + '/rmdir_async_003_1d'; - let fffpath = ddpath + '/rmdir_async_003_2'; - fileio.mkdirSync(dpath); - fileio.mkdirSync(ddpath); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - expect(prepareFile(ffpath, FILE_CONTENT)).assertTrue(); - expect(prepareFile(fffpath, FILE_CONTENT)).assertTrue(); - - try { - fileio.rmdir(dpath, function () { - done(); - }); - } catch (err) { - console.info('fileio_test_rmdir_async_003 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_RMDIR_ASYNC_0400 - * @tc.name fileio_test_rmdir_async_004 - * @tc.desc Test rmdirSync() interface. The path contains ../, normal call. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_rmdir_async_004', 0, async function () { - let dpath = await nextFileName('../cache/fileio_test_rmdir_async_004') + 'd'; - - try { - fileio.mkdirSync(dpath); - await fileio.rmdir(dpath); - } catch (err) { - console.info('fileio_test_rmdir_async_004 has failed for ' + err); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_RMDIR_ASYNC_0500 - * @tc.name fileio_test_rmdir_async_005 - * @tc.desc Test rmdir() interface. Invalid path. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_rmdir_async_005', 0, async function (done) { - let dpath = await nextFileName('fileio_test_rmdir_async_005') + 'd'; - - try { - await fileio.rmdir(dpath); - } catch (err) { - console.info('fileio_test_rmdir_async_005 has failed for ' + err); - expect(isInclude(err.message, 'No such file or directory')).assertTrue(); - done(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_RMDIR_ASYNC_0600 - * @tc.name fileio_test_rmdir_async_006 - * @tc.desc Test rmdir() interface. Parameter mismatch. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_rmdir_async_006', 0, async function (done) { - let dpath = await nextFileName('fileio_test_rmdir_async_006') + 'd'; - try { - fileio.rmdir(dpath, '', function() { - }); - } catch (err) { - console.info('fileio_test_rmdir_async_006 has failed for ' + err); - expect(isInclude(err.message, 'Number of arguments unmatched')).assertTrue(); - done(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_RMDIR_ASYNC_0700 - * @tc.name fileio_test_rmdir_async_007 - * @tc.desc Test rmdir() interface. Invalid path. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_rmdir_async_007', 0, async function (done) { - try { - await fileio.rmdir(''); - } catch (err) { - console.info('fileio_test_rmdir_async_007 has failed for ' + err); - expect(isInclude(err.message, 'No such file or directory')).assertTrue(); - done(); - } - }); - - /** - * @tc.number SUB_STORAGE_FileIO_RMDIR_ASYNC_0800 - * @tc.name fileio_test_rmdir_async_008 - * @tc.desc Test rmdir() interface. Not a directory. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_rmdir_async_008', 0, async function (done) { - let fpath = await nextFileName('fileio_test_rmdir_async_008'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - await fileio.rmdir(fpath); - } catch (err) { - console.info('fileio_test_rmdir_async_008 has failed for ' + err); - expect(isInclude(err.message, 'Not a directory')).assertTrue(); - fileio.unlinkSync(fpath); - done(); - } - }); -}) +/* + * Copyright (C) 2021 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 { + fileio, FILE_CONTENT, prepareFile, nextFileName, randomString, isInclude, + describe, it, expect, +} from '../../Common'; +export default function fileioRmdir() { +describe('fileio_rmdir', function () { + + /** + * @tc.number SUB_STORAGE_FileIO_RMDIR_SYNC_0000 + * @tc.name fileio_test_rmdir_sync_000 + * @tc.desc Test rmdirSync() interface. + * Recursively delete all files and subfolders in a directory. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_rmdir_sync_000', 0, async function () { + let dpath = await nextFileName('fileio_test_rmdir_sync_000') + 'd'; + let fpath = dpath + '/rmdir_sync_000'; + let ddpath = dpath + '/rmdir_sync_000_1d'; + fileio.mkdirSync(dpath); + fileio.mkdirSync(ddpath); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + fileio.rmdirSync(dpath); + } catch (err) { + console.info('fileio_test_rmdir_sync_000 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_RMDIR_SYNC_0100 + * @tc.name fileio_test_rmdir_sync_001 + * @tc.desc Test rmdirSync() interface. + * Recursively delete all files and subfolders in a directory. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_rmdir_sync_001', 0, async function () { + let dpath = await nextFileName('fileio_test_rmdir_sync_001') + 'd'; + let fpath = dpath + '/rmdir_sync_001'; + let ffpath = dpath + '/rmdir_sync_001_1'; + let ddpath = dpath + '/rmdir_sync_001_1d'; + let fffpath = ddpath + '/rmdir_sync_002'; + fileio.mkdirSync(dpath); + fileio.mkdirSync(ddpath); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + expect(prepareFile(ffpath, FILE_CONTENT)).assertTrue(); + expect(prepareFile(fffpath, FILE_CONTENT)).assertTrue(); + + try { + fileio.rmdirSync(dpath); + } catch (err) { + console.info('fileio_test_rmdir_sync_001 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_RMDIR_SYNC_0200 + * @tc.name fileio_test_rmdir_sync_002 + * @tc.desc Test rmdirSync() interface. + * Recursively delete all files and subfolders in a directory. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_rmdir_sync_002', 0, async function () { + let dpath = await nextFileName('fileio_test_rmdir_sync_002') + 'd'; + fileio.mkdirSync(dpath); + let fdpath = dpath; + + try { + for (let i = 0; i < 113; i++) { + let fpath = dpath + '/f' + randomString(10) + i; + fileio.openSync(fpath, 0o102, 0o777); + dpath = dpath + '/d' + randomString(10) + i; + fileio.mkdirSync(dpath); + } + fileio.rmdirSync(fdpath); + } catch (err) { + console.info('fileio_test_rmdir_sync_002 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_RMDIR_SYNC_0300 + * @tc.name fileio_test_rmdir_sync_003 + * @tc.desc Test rmdirSync() interface. The path contains ../, normal call. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_rmdir_sync_003', 0, async function () { + let dpath = await nextFileName('../cache/fileio_test_rmdir_sync_003') + 'd'; + + try { + fileio.mkdirSync(dpath); + fileio.rmdirSync(dpath); + } catch (err) { + console.info('fileio_test_rmdir_sync_003 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_RMDIR_SYNC_0400 + * @tc.name fileio_test_rmdir_sync_004 + * @tc.desc Test rmdirSync() interface. Invalid path. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_rmdir_sync_004', 0, async function () { + let dpath = await nextFileName('fileio_test_rmdir_sync_004') + 'd'; + + try { + fileio.rmdirSync(dpath); + } catch (err) { + console.info('fileio_test_rmdir_sync_004 has failed for ' + err); + expect(isInclude(err.message, 'No such file or directory')).assertTrue(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_RMDIR_SYNC_0500 + * @tc.name fileio_test_rmdir_sync_005 + * @tc.desc Test rmdirSync() interface. No parameters. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_rmdir_sync_005', 0, async function () { + try { + fileio.rmdirSync(); + } catch (err) { + console.info('fileio_test_rmdir_sync_005 has failed for ' + err); + expect(isInclude(err.message, 'Number of arguments unmatched')).assertTrue(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_RMDIR_SYNC_0600 + * @tc.name fileio_test_rmdir_sync_006 + * @tc.desc Test rmdirSync() interface. Invalid path. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_rmdir_sync_006', 0, async function () { + try { + fileio.rmdirSync(''); + } catch (err) { + console.info('fileio_test_rmdir_sync_006 has failed for ' + err); + expect(isInclude(err.message, 'No such file or directory')).assertTrue(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_RMDIR_SYNC_0700 + * @tc.name fileio_test_rmdir_sync_007 + * @tc.desc Test rmdirSync() interface. Not a directory. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_rmdir_sync_007', 0, async function () { + let fpath = await nextFileName('fileio_test_rmdir_sync_007'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + fileio.rmdirSync(fpath); + } catch (err) { + console.info('fileio_test_rmdir_sync_007 has failed for ' + err); + expect(isInclude(err.message, 'Not a directory')).assertTrue(); + fileio.unlinkSync(fpath); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_RMDIR_ASYNC_0000 + * @tc.name fileio_test_rmdir_async_000 + * @tc.desc Test rmdir() interface, return in promise mode. + * Recursively delete all files and subfolders in a directory. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_rmdir_async_000', 0, async function (done) { + let dpath = await nextFileName('fileio_test_rmdir_async_000') + 'd'; + fileio.mkdirSync(dpath); + let fdpath = dpath; + + try { + for (let i = 0; i < 113; i++) { + let fpath = dpath + '/f' + randomString(10) + i; + await fileio.open(fpath, 0o102, 0o777); + dpath = dpath + '/d' + randomString(10) + i; + await fileio.mkdir(dpath); + } + await fileio.rmdir(fdpath); + done(); + } catch (err) { + console.info('fileio_test_rmdir_async_000 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_RMDIR_ASYNC_0100 + * @tc.name fileio_test_rmdir_async_001 + * @tc.desc Test rmdir() interface, return in callback mode. + * Recursively delete all files and subfolders in a directory. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_rmdir_async_001', 0, async function (done) { + let dpath = await nextFileName('fileio_test_rmdir_async_001') + 'd'; + fileio.mkdirSync(dpath); + let fdpath = dpath; + + try { + for (let i = 0; i < 113; i++) { + let fpath = dpath + '/f' + randomString(10) + i; + await fileio.open(fpath, 0o102, 0o777); + dpath = dpath + '/d' + randomString(10) + i; + await fileio.mkdir(dpath); + } + fileio.rmdir(fdpath, function () { + done(); + }); + } catch (err) { + console.info('fileio_test_rmdir_async_001 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_RMDIR_ASYNC_0200 + * @tc.name fileio_test_rmdir_async_002 + * @tc.desc Test rmdir() interface, return in promise mode. + * Recursively delete all files and subfolders in a directory. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_rmdir_async_002', 0, async function (done) { + let dpath = await nextFileName('fileio_test_rmdir_async_002') + 'd'; + let fpath = dpath + '/rmdir_async_002'; + let ddpath = dpath + '/rmdir_async_002_1d'; + fileio.mkdirSync(dpath); + fileio.mkdirSync(ddpath); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + await fileio.rmdir(dpath); + done() + } catch (err) { + console.info('fileio_test_rmdir_async_002 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_RMDIR_ASYNC_0300 + * @tc.name fileio_test_rmdir_async_003 + * @tc.desc Test rmdir() interface, return in callback mode. + * Recursively delete all files and subfolders in a directory. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_rmdir_async_003', 0, async function (done) { + let dpath = await nextFileName('fileio_test_rmdir_async_003') + 'd'; + let fpath = dpath + '/rmdir_async_003'; + let ffpath = dpath + '/rmdir_async_003_1'; + let ddpath = dpath + '/rmdir_async_003_1d'; + let fffpath = ddpath + '/rmdir_async_003_2'; + fileio.mkdirSync(dpath); + fileio.mkdirSync(ddpath); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + expect(prepareFile(ffpath, FILE_CONTENT)).assertTrue(); + expect(prepareFile(fffpath, FILE_CONTENT)).assertTrue(); + + try { + fileio.rmdir(dpath, function () { + done(); + }); + } catch (err) { + console.info('fileio_test_rmdir_async_003 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_RMDIR_ASYNC_0400 + * @tc.name fileio_test_rmdir_async_004 + * @tc.desc Test rmdirSync() interface. The path contains ../, normal call. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_rmdir_async_004', 0, async function () { + let dpath = await nextFileName('../cache/fileio_test_rmdir_async_004') + 'd'; + + try { + fileio.mkdirSync(dpath); + await fileio.rmdir(dpath); + } catch (err) { + console.info('fileio_test_rmdir_async_004 has failed for ' + err); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_RMDIR_ASYNC_0500 + * @tc.name fileio_test_rmdir_async_005 + * @tc.desc Test rmdir() interface. Invalid path. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_rmdir_async_005', 0, async function (done) { + let dpath = await nextFileName('fileio_test_rmdir_async_005') + 'd'; + + try { + await fileio.rmdir(dpath); + } catch (err) { + console.info('fileio_test_rmdir_async_005 has failed for ' + err); + expect(isInclude(err.message, 'No such file or directory')).assertTrue(); + done(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_RMDIR_ASYNC_0600 + * @tc.name fileio_test_rmdir_async_006 + * @tc.desc Test rmdir() interface. Parameter mismatch. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_rmdir_async_006', 0, async function (done) { + let dpath = await nextFileName('fileio_test_rmdir_async_006') + 'd'; + try { + fileio.rmdir(dpath, '', function() { + }); + } catch (err) { + console.info('fileio_test_rmdir_async_006 has failed for ' + err); + expect(isInclude(err.message, 'Number of arguments unmatched')).assertTrue(); + done(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_RMDIR_ASYNC_0700 + * @tc.name fileio_test_rmdir_async_007 + * @tc.desc Test rmdir() interface. Invalid path. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_rmdir_async_007', 0, async function (done) { + try { + await fileio.rmdir(''); + } catch (err) { + console.info('fileio_test_rmdir_async_007 has failed for ' + err); + expect(isInclude(err.message, 'No such file or directory')).assertTrue(); + done(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_RMDIR_ASYNC_0800 + * @tc.name fileio_test_rmdir_async_008 + * @tc.desc Test rmdir() interface. Not a directory. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_rmdir_async_008', 0, async function (done) { + let fpath = await nextFileName('fileio_test_rmdir_async_008'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + await fileio.rmdir(fpath); + } catch (err) { + console.info('fileio_test_rmdir_async_008 has failed for ' + err); + expect(isInclude(err.message, 'Not a directory')).assertTrue(); + fileio.unlinkSync(fpath); + done(); + } + }); +}) } \ No newline at end of file diff --git a/storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/members/stat.test.js b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/stat.test.js similarity index 96% rename from storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/members/stat.test.js rename to storage/storagefileiojstest/src/main/js/test/module_fileio/members/stat.test.js index aa4e088bde24afb82e77c17020664b91da43b8b0..2e7c739c5e8b14e216b1d3d589cb53ac21864ca3 100644 --- a/storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/members/stat.test.js +++ b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/stat.test.js @@ -1,1647 +1,1647 @@ -/* - * Copyright (C) 2023 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 { - fileio, FILE_CONTENT, prepareFile, nextFileName, isIntNum, isBigInt, isBoolean, - describe, it, expect, -} from '../../Common'; - -export default function fileioStat() { -describe('fileio_stat', function () { - - /** - * @tc.number SUB_DF_FILEIO_STAT_SYNC_0000 - * @tc.name fileio_stat_sync_000 - * @tc.desc Test Stat.statSync() interfaces. - * This interface shall work properly in normal case. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_stat_sync_000', 0, async function () { - let fpath = await nextFileName('fileio_stat_sync_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let stat = fileio.statSync(fpath); - expect(stat !== null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - } catch (e) { - console.log('fileio_stat_sync_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_STAT_SYNC_0010 - * @tc.name fileio_stat_sync_001 - * @tc.desc Test Stat.statSync() interfaces. - * This interface shall throw an exception when the file isnt's exist. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_stat_sync_001', 0, async function () { - let fpath = await nextFileName('fileio_stat_sync_001'); - - try { - fileio.statSync(fpath); - expect(null).assertFail(); - } catch (e) { - console.log('fileio_stat_sync_001 has failed for ' + e); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_STAT_SYNC_DEV_0000 - * @tc.name fileio_stat_sync_dev_000 - * @tc.desc Test Stat.statSync_Dev() interfaces. - * @tc.desc Test the dev member of class Stat. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_stat_sync_dev_000', 0, async function () { - let fpath = await nextFileName('fileio_stat_sync_dev_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let stat = fileio.statSync(fpath); - expect(isIntNum(stat.dev)).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - } catch (e) { - console.log('fileio_stat_sync_dev_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_STAT_INO_0000 - * @tc.name fileio_stat_sync_ino_000 - * @tc.desc Test Stat.statSync_Ino() interfaces. - * @tc.desc Test the ino member of class Stat - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_stat_sync_ino_000', 0, async function () { - let fpath = await nextFileName('fileio_stat_sync_ino_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let stat = fileio.statSync(fpath); - expect(isBigInt(stat.ino)).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - } catch (e) { - console.log('fileio_stat_sync_ino_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_STAT_MODE_0000 - * @tc.name fileio_stat_sync_mode_000 - * @tc.desc Test Stat.statSync_Mode() interfaces. - * @tc.desc Test the mode member of class Stat - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_stat_sync_mode_000', 0, async function () { - let fpath = await nextFileName('fileio_stat_sync_mode_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let stat = fileio.statSync(fpath); - expect(isIntNum(stat.mode)).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - } catch (e) { - console.log('fileio_stat_sync_mode_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_STAT_NLINK_0000 - * @tc.name fileio_stat_sync_nlink_000 - * @tc.desc Test Stat.statSync_Nlink() interfaces. - * @tc.desc Test the nlink member of class Stat - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_stat_sync_nlink_000', 0, async function () { - let fpath = await nextFileName('fileio_stat_sync_nlink_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let stat = fileio.statSync(fpath); - expect(isIntNum(stat.nlink)).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - } catch (e) { - console.log('fileio_stat_sync_nlink_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_STAT_UID_0000 - * @tc.name fileio_stat_sync_uid_000 - * @tc.desc Test Stat.statSync_Uid() interfaces. - * @tc.desc Test the uid member of class Stat - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_stat_sync_uid_000', 0, async function () { - let fpath = await nextFileName('fileio_stat_sync_uid_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let stat = fileio.statSync(fpath); - expect(isIntNum(stat.uid)).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - } catch (e) { - console.log('fileio_stat_sync_uid_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_STAT_SYNC_GID_0000 - * @tc.name fileio_stat_sync_gid_000 - * @tc.desc Test Stat.statSync_Gid() interfaces. - * @tc.desc Test the gid member of class Stat - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_stat_sync_gid_000', 0, async function () { - let fpath = await nextFileName('fileio_stat_sync_gid_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let stat = fileio.statSync(fpath); - expect(isIntNum(stat.gid)).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - } catch (e) { - console.log('fileio_stat_sync_gid_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_STAT_SYNC_RDEV_0000 - * @tc.name fileio_stat_sync_rdev_000 - * @tc.desc Test Stat.statSync_Rdev() interfaces. - * @tc.desc Test the rdev member of class Stat - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_stat_sync_rdev_000', 0, async function () { - let fpath = await nextFileName('fileio_stat_sync_rdev_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let stat = fileio.statSync(fpath); - expect(isIntNum(stat.rdev)).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - } catch (e) { - console.log('fileio_stat_sync_rdev_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_STAT_SYNC_SIZE_0000 - * @tc.name fileio_stat_sync_size_000 - * @tc.desc Test Stat.statSync_Size() interfaces. - * @tc.desc Test the size member of class Stat - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_stat_sync_size_000', 0, async function () { - let fpath = await nextFileName('fileio_stat_sync_size_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let stat = fileio.statSync(fpath); - expect(isIntNum(stat.size)).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - } catch (e) { - console.log('fileio_stat_sync_size_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_STAT_SYNC_BLOCKS_0000 - * @tc.name fileio_stat_sync_blocks_000 - * @tc.desc Test Stat.statSync_Block() interfaces. - * @tc.desc Test the blocks member of class Stat - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_stat_sync_blocks_000', 0, async function () { - let fpath = await nextFileName('fileio_stat_sync_blocks_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let stat = fileio.statSync(fpath); - expect(isIntNum(stat.blocks)).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - } catch (e) { - console.log('fileio_stat_sync_blocks_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_STAT_SYNC_ATIME_0000 - * @tc.name fileio_stat_sync_atime_000 - * @tc.desc Test Stat.statSync_Atime() interfaces. - * @tc.desc Test the atime member of class Stat - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_stat_sync_atime_000', 0, async function () { - let fpath = await nextFileName('fileio_stat_sync_atime_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let stat = fileio.statSync(fpath); - expect(isIntNum(stat.atime)).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - } catch (e) { - console.log('fileio_stat_sync_atime_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_STAT_SYNC_MTIME_0000 - * @tc.name fileio_stat_sync_mtime_000 - * @tc.desc Test Stat.statSync_Mtime() interfaces. - * @tc.desc Test the mtime member of class Stat - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_stat_sync_mtime_000', 0, async function () { - let fpath = await nextFileName('fileio_stat_sync_mtime_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let stat = fileio.statSync(fpath); - expect(isIntNum(stat.mtime)).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - } catch (e) { - console.log('fileio_stat_sync_mtime_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_STAT_SYNC_CTIME_0000 - * @tc.name fileio_stat_sync_ctime_000 - * @tc.desc Test Stat.statSync_Ctime() interfaces. - * @tc.desc Test the ctime member of class Stat - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_stat_sync_ctime_000', 0, async function () { - let fpath = await nextFileName('fileio_stat_sync_ctime_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let stat = fileio.statSync(fpath); - expect(isIntNum(stat.ctime)).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - } catch (e) { - console.log('fileio_stat_sync_ctime_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_STAT_SYNC_ISBLOCKDEVICE_0000 - * @tc.name fileio_stat_sync_is_block_device_000 - * @tc.desc Test Stat.statSync_IsBlockDevice() interfaces. - * @tc.desc Test the isBlockDevice() method of class Stat. - * This interface shall return a boolean variable. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_stat_sync_is_block_device_000', 0, async function () { - let fpath = await nextFileName('fileio_stat_sync_is_block_device_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let stat = fileio.statSync(fpath); - expect(isBoolean(stat.isBlockDevice())).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - } catch (e) { - console.log('fileio_stat_sync_is_block_device_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_STAT_SYNC_ISBLOCKDEVICE_0010 - * @tc.name fileio_stat_sync_is_block_device_001 - * @tc.desc Test Stat.statSync_IsBlockDevice() interfaces. - * @tc.desc Test the isBlockDevice() method of class Stat. - * This interface shall not treat a normal file as a block special device. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_stat_sync_is_block_device_001', 0, async function () { - let fpath = await nextFileName('fileio_stat_sync_is_block_device_001'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let stat = fileio.statSync(fpath); - expect(stat.isBlockDevice() === false).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - } catch (e) { - console.log('fileio_stat_sync_is_block_device_001 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_STAT_SYNC_ISBLOCKDEVICE_0020 - * @tc.name fileio_stat_sync_is_block_device_002 - * @tc.desc Test Stat.statSync_IsBlockDevice() interfaces. - * @tc.desc Test the isBlockDevice() method of class Stat. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_stat_sync_is_block_device_002', 0, async function () { - let fpath = await nextFileName('fileio_stat_sync_is_block_device_002'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let stat = fileio.statSync(fpath); - expect(stat.isBlockDevice(-1) === false).assertTrue(); - expect(null).assertFail(); - } catch (e) { - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_STAT_SYNC_ISCHARACTER_DEVICE_0000 - * @tc.name fileio_stat_sync_is_character_device_000 - * @tc.desc Test Stat.statsync_IsCharacterDevice() interfaces. - * This interface shall return a boolean variable. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_stat_sync_is_character_device_000', 0, async function () { - let fpath = await nextFileName('fileio_stat_sync_is_character_device_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let stat = fileio.statSync(fpath); - expect(isBoolean(stat.isCharacterDevice())).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - } catch (e) { - console.log('fileio_stat_sync_is_character_device_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_STAT_SYNC_ISCHARACTER_DEVICE_0010 - * @tc.name fileio_stat_sync_is_character_device_001 - * @tc.desc Test Stat.statsync_IsCharacterDevice() interfaces. - * This interface shall not treat a normal file as a character special device. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_stat_sync_is_character_device_001', 0, async function () { - let fpath = await nextFileName('fileio_stat_sync_is_character_device_001'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let stat = fileio.statSync(fpath); - expect(stat.isCharacterDevice() === false).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - } catch (e) { - console.log('fileio_stat_sync_is_character_device_001 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_STAT_SYNC_ISCHARACTER_DEVICE_0020 - * @tc.name fileio_stat_sync_is_character_device_002 - * @tc.desc Test Stat.statsync_IsCharacterDevice() interfaces. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_stat_sync_is_character_device_002', 0, async function () { - let fpath = await nextFileName('fileio_stat_sync_is_character_device_002'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let stat = fileio.statSync(fpath); - expect(stat.isCharacterDevice(-1) === false).assertTrue(); - expect(null).assertFail(); - } catch (e) { - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_STAT_SYNC_ISDIRECTORY_0000 - * @tc.name fileio_stat_sync_is_directory_000 - * @tc.desc Test Stat.statsync_isDirectory() interfaces. - * This interface shall return a boolean variable. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_stat_sync_is_directory_000', 0, async function () { - let fpath = await nextFileName('fileio_stat_sync_is_directory_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let stat = fileio.statSync(fpath); - expect(isBoolean(stat.isDirectory())).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - } catch (e) { - console.log('fileio_stat_sync_is_directory_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_STAT_SYNC_ISDIRECTORY_0010 - * @tc.name fileio_stat_sync_is_directory_001 - * @tc.desc Test Stat.statsync_isDirectory() interfaces. - * This interface shall not treat a normal file as a directory. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_stat_sync_is_directory_001', 0, async function () { - let fpath = await nextFileName('fileio_stat_sync_is_directory_001'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let stat = fileio.statSync(fpath); - expect(stat.isDirectory() === false).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - } catch (e) { - console.log('fileio_stat_sync_is_directory_001 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_STAT_SYNC_ISDIRECTORY_0020 - * @tc.name fileio_stat_sync_is_directory_002 - * @tc.desc Test Stat.statsync_isDirectory() interfaces. - * This interface shall treat a directory as a directory. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_stat_sync_is_directory_002', 0, async function () { - let dpath = await nextFileName('fileio_stat_sync_is_directory_002') + 'd'; - - try { - expect(fileio.mkdirSync(dpath) == null).assertTrue(); - let stat = fileio.statSync(dpath); - expect(stat.isDirectory()).assertTrue(); - expect(fileio.rmdirSync(dpath) == null).assertTrue(); - } catch (e) { - console.log('fileio_stat_sync_is_directory_002 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_STAT_SYNC_ISDIRECTORY_0030 - * @tc.name fileio_stat_sync_is_directory_003 - * @tc.desc Test Stat.statsync_isDirectory() interfaces. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_stat_sync_is_directory_003', 0, async function () { - let dpath = await nextFileName('fileio_stat_sync_is_directory_003') + 'd'; - - try { - expect(fileio.mkdirSync(dpath) == null).assertTrue(); - let stat = fileio.statSync(dpath); - expect(stat.isDirectory(-1)).assertTrue(); - expect(null).assertFail(); - } catch (e) { - expect(fileio.rmdirSync(dpath) == null).assertTrue(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_STAT_SYNC_ISFIFO_0000 - * @tc.name fileio_stat_sync_is_fifo_000 - * @tc.desc Test Stat.statsync_isFIFO() interfaces. - * This interface shall return a boolean variable. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_stat_sync_is_fifo_000', 0, async function () { - let fpath = await nextFileName('fileio_stat_sync_is_fifo_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let stat = fileio.statSync(fpath); - expect(isBoolean(stat.isFIFO())).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - } catch (e) { - console.log('fileio_stat_sync_is_fifo_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_STAT_SYNC_ISFIFO_0010 - * @tc.name fileio_stat_sync_is_fifo_001 - * @tc.desc Test Stat.statsync_isFIFO() interfaces. - * This interface shall not treat a normal file as a FIFO. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_stat_sync_is_fifo_001', 0, async function () { - let fpath = await nextFileName('fileio_stat_sync_is_fifo_001'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let stat = fileio.statSync(fpath); - expect(stat.isFIFO() === false).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - } catch (e) { - console.log('fileio_stat_sync_is_fifo_001 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_STAT_SYNC_ISFIFO_0020 - * @tc.name fileio_stat_sync_is_fifo_002 - * @tc.desc Test Stat.statsync_isFIFO() interfaces. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_stat_sync_is_fifo_002', 0, async function () { - let fpath = await nextFileName('fileio_stat_sync_is_fifo_002'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let stat = fileio.statSync(fpath); - expect(stat.isFIFO(-1) === false).assertTrue(); - expect(null).assertFail(); - } catch (e) { - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_STAT_SYNC_ISFILE_0000 - * @tc.name fileio_stat_sync_is_file_000 - * @tc.desc Test Stat.statsync_isFile() interfaces. - * This interface shall return a boolean variable. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_stat_sync_is_file_000', 0, async function () { - let fpath = await nextFileName('fileio_stat_sync_is_file_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let stat = fileio.statSync(fpath); - expect(isBoolean(stat.isFile())).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - } catch (e) { - console.log('fileio_stat_sync_is_file_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_STAT_SYNC_ISFILE_0010 - * @tc.name fileio_stat_sync_is_file_001 - * @tc.desc Test Stat.statsync_isFile() interfaces. - * This interface shall treat a normal file as a normal file. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_stat_sync_is_file_001', 0, async function () { - let fpath = await nextFileName('fileio_stat_sync_is_file_001'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let stat = fileio.statSync(fpath); - expect(stat.isFile()).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - } catch (e) { - console.log('fileio_stat_sync_is_file_001 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_STAT_SYNC_ISFILE_0020 - * @tc.name fileio_stat_sync_is_file_002 - * @tc.desc Test Stat.statsync_isFile() interfaces. - * This interface shall not treat a directory as a normal file. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_stat_sync_is_file_002', 0, async function () { - let dpath = await nextFileName('fileio_stat_sync_is_file_002'); - - try { - expect(fileio.mkdirSync(dpath) == null).assertTrue(); - let stat = fileio.statSync(dpath); - expect(stat.isFile() === false).assertTrue(); - expect(fileio.rmdirSync(dpath) == null).assertTrue(); - } catch (e) { - console.log('fileio_stat_sync_is_file_002 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_STAT_SYNC_ISFILE_0030 - * @tc.name fileio_stat_sync_is_file_003 - * @tc.desc Test Stat.statsync_isFile() interfaces. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_stat_sync_is_file_003', 0, async function () { - let dpath = await nextFileName('fileio_stat_sync_is_file_003'); - - try { - expect(fileio.mkdirSync(dpath) == null).assertTrue(); - let stat = fileio.statSync(dpath); - expect(stat.isFile(-1) === false).assertTrue(); - expect(null).assertFail(); - } catch (e) { - expect(fileio.rmdirSync(dpath) == null).assertTrue(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_STAT_SYNC_ISSOCKET_0000 - * @tc.name fileio_stat_sync_is_socket_000 - * @tc.desc Test Stat.statsync_isSocket() interfaces. - * This interface shall return a boolean variable. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_stat_sync_is_socket_000', 0, async function () { - let fpath = await nextFileName('fileio_stat_sync_is_socket_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let stat = fileio.statSync(fpath); - expect(isBoolean(stat.isSocket())).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - } catch (e) { - console.log('fileio_stat_sync_is_socket_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_STAT_SYNC_ISSOCKET_0010 - * @tc.name fileio_stat_sync_is_socket_001 - * @tc.desc Test Stat.statsync_isSocket() interfaces. - * This interface shall not treat a file as a socket. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_stat_sync_is_socket_001', 0, async function () { - let fpath = await nextFileName('fileio_stat_sync_is_socket_001'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let stat = fileio.statSync(fpath); - expect(stat.isSocket() === false).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - } catch (e) { - console.log('fileio_stat_sync_is_socket_001 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_STAT_SYNC_ISSOCKET_0020 - * @tc.name fileio_stat_sync_is_socket_002 - * @tc.desc Test Stat.statsync_isSocket() interfaces. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_stat_sync_is_socket_002', 0, async function () { - let fpath = await nextFileName('fileio_stat_sync_is_socket_002'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let stat = fileio.statSync(fpath); - expect(stat.isSocket(-1) === false).assertTrue(); - expect(null).assertFail(); - } catch (e) { - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_STAT_SYNC_ISSYMBOLICLINK_0000 - * @tc.name fileio_stat_sync_is_symbolic_link_000 - * @tc.desc Test Stat.statasync_isSymbolicLink() interfaces. - * This interface shall return a boolean variable. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_stat_sync_is_symbolic_link_000', 0, async function () { - let fpath = await nextFileName('fileio_stat_sync_is_symbolic_link_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let stat = fileio.statSync(fpath); - expect(isBoolean(stat.isSymbolicLink())).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - } catch (e) { - console.log('fileio_stat_sync_is_symbolic_link_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_STAT_SYNC_ISSYMBOLICLINK_0010 - * @tc.name fileio_stat_sync_is_symbolic_link_001 - * @tc.desc Test Stat.statasync_isSymbolicLink() interfaces. - * This interface shall not treat a normal file as a symbolic link. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_stat_sync_is_symbolic_link_001', 0, async function () { - let fpath = await nextFileName('fileio_stat_sync_is_symbolic_link_001'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let stat = fileio.statSync(fpath); - expect(stat.isSymbolicLink() === false).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - } catch (e) { - console.log('fileio_stat_is_symbolic_link_001 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_STAT_SYNC_ISSYMBOLICLINK_0020 - * @tc.name fileio_stat_sync_is_symbolic_link_002 - * @tc.desc Test Stat.isSymbolicLink() interfaces. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_stat_sync_is_symbolic_link_002', 0, async function () { - let fpath = await nextFileName('fileio_stat_sync_is_symbolic_link_002'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let stat = fileio.statSync(fpath); - expect(stat.isSymbolicLink(-1) === false).assertTrue(); - expect(null).assertFail(); - } catch (e) { - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_STAT_ASYNC_0000 - * @tc.name fileio_stat_async_000 - * @tc.desc Test Stat.statAsync() interface. - * This interface shall work properly in normal case when providing the promise async model. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_stat_async_000', 0, async function (done) { - let fpath = await nextFileName('fileio_stat_async_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - fileio.stat(fpath).then((stat) => { - expect(stat !== null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - }); - done(); - } catch (e) { - console.log('fileio_stat_async_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_STAT_ASYNC_0000 - * @tc.name fileio_stat_async_001 - * @tc.desc Test Stat.statAsync() interface. - * This interface shall work properly in normal case when providing the callback async model. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_stat_async_001', 0, async function (done) { - let fpath = await nextFileName('fileio_stat_async_001'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - fileio.stat(fpath, function (error) { - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - done(); - }); - } catch (e) { - console.log('fileio_stat_async_001 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_STAT_ASYNC_DEV_0000 - * @tc.name fileio_stat_async_dev_000 - * @tc.desc Test the dev member of class Stat. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_stat_async_dev_000', 0, async function (done) { - let fpath = await nextFileName('fileio_stat_async_dev_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let stat = await fileio.stat(fpath); - expect(isIntNum(stat.dev)).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - done(); - } catch (e) { - console.log('fileio_stat_async_dev_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_STAT_ASYNC_INO_0000 - * @tc.name fileio_stat_async_ino_000 - * @tc.desc Test the ino member of class Stat. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_stat_async_ino_000', 0, async function (done) { - let fpath = await nextFileName('fileio_stat_async_ino_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let stat = await fileio.stat(fpath); - expect(isBigInt(stat.ino)).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - done(); - } catch (e) { - console.log('fileio_stat_async_ino_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_STAT_ASYNC_MODE_0000 - * @tc.name fileio_stat_async_mode_000 - * @tc.desc Test the mode member of class Stat. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_stat_async_mode_000', 0, async function (done) { - let fpath = await nextFileName('fileio_stat_async_mode_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let stat = await fileio.stat(fpath); - expect(isIntNum(stat.mode)).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - done(); - } catch (e) { - console.log('fileio_stat_async_mode_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_STAT_ASYNC_NLINK_0000 - * @tc.name fileio_stat_async_nlink_000 - * @tc.desc Test the nlink member of class Stat. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_stat_async_nlink_000', 0, async function (done) { - let fpath = await nextFileName('fileio_stat_async_nlink_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let stat = await fileio.stat(fpath); - expect(isIntNum(stat.nlink)).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - done(); - } catch (e) { - console.log('fileio_stat_async_nlink_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_STAT_ASYNC_UID_0000 - * @tc.name fileio_stat_async_uid_000 - * @tc.desc Test the uid member of class Stat. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_stat_async_uid_000', 0, async function (done) { - let fpath = await nextFileName('fileio_stat_async_uid_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let stat = await fileio.stat(fpath); - expect(isIntNum(stat.uid)).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - done(); - } catch (e) { - console.log('fileio_stat_async_uid_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_STAT_ASYNC_GID_0000 - * @tc.name fileio_stat_async_gid_000 - * @tc.desc Test the gid member of class Stat. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_stat_async_gid_000', 0, async function (done) { - let fpath = await nextFileName('fileio_stat_async_gid_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let stat = await fileio.stat(fpath); - expect(isIntNum(stat.gid)).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - done(); - } catch (e) { - console.log('fileio_stat_async_gid_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_STAT_ASYNC_RDEV_0000 - * @tc.name fileio_stat_async_rdev_000 - * @tc.desc Test the rdev member of class Stat. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_stat_async_rdev_000', 0, async function (done) { - let fpath = await nextFileName('fileio_stat_async_rdev_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let stat = await fileio.stat(fpath); - expect(isIntNum(stat.rdev)).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - done(); - } catch (e) { - console.log('fileio_stat_async_rdev_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_STAT_ASYNC_SIZE_0000 - * @tc.name fileio_stat_async_size_000 - * @tc.desc Test the size member of class Stat. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_stat_async_size_000', 0, async function (done) { - let fpath = await nextFileName('fileio_stat_async_size_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let stat = await fileio.stat(fpath); - expect(isIntNum(stat.size)).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - done(); - } catch (e) { - console.log('fileio_stat_async_size_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_STAT_ASYNC_BLOCKS_0000 - * @tc.name fileio_stat_async_blocks_000 - * @tc.desc Test Stat.blocks() interface. - * @tc.desc Test the blocks member of class Stat. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_stat_async_blocks_000', 0, async function (done) { - let fpath = await nextFileName('fileio_stat_async_blocks_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let stat = await fileio.stat(fpath); - expect(isIntNum(stat.blocks)).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - done(); - } catch (e) { - console.log('fileio_stat_async_blocks_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_STAT_ASYNC_ATIME_0000 - * @tc.name fileio_stat_async_atime_000 - * @tc.desc Test Stat.atime() interface. - * @tc.desc Test the atime member of class Stat. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_stat_async_atime_000', 0, async function (done) { - let fpath = await nextFileName('fileio_stat_async_atime_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let stat = await fileio.stat(fpath); - expect(isIntNum(stat.atime)).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - done(); - } catch (e) { - console.log('fileio_stat_async_atime_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_STAT_ASYNC_MTIME_0000 - * @tc.name fileio_stat_async_mtime_000 - * @tc.desc Test Stat.mtime() interface. - * @tc.desc Test the mtime member of class Stat. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_stat_async_mtime_000', 0, async function (done) { - let fpath = await nextFileName('fileio_stat_async_mtime_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let stat = await fileio.stat(fpath); - expect(isIntNum(stat.mtime)).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - done(); - } catch (e) { - console.log('fileio_stat_async_mtime_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_STAT_ASYNC_CTIME_0000 - * @tc.name fileio_stat_async_ctime_000 - * @tc.desc Test the ctime member of class Stat. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_stat_async_ctime_000', 0, async function (done) { - let fpath = await nextFileName('fileio_stat_async_ctime_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let stat = await fileio.stat(fpath); - expect(isIntNum(stat.ctime)).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - done(); - } catch (e) { - console.log('fileio_stat_async_ctime_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_STAT_ASYNC_ISBLOCKDEVICE_0000 - * @tc.name fileio_stat_async_is_block_device_000 - * @tc.desc Test the isBlockDevice method of class Stat. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_stat_async_is_block_device_000', 0, async function (done) { - let fpath = await nextFileName('fileio_stat_async_is_block_device_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let stat = await fileio.stat(fpath); - expect(isBoolean(stat.isBlockDevice())).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - done(); - } catch (e) { - console.log('fileio_stat_async_is_block_device_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_STAT_ASYNC_ISBLOCKDEVICE_0010 - * @tc.name fileio_stat_async_is_block_device_001 - * @tc.desc Test the isBlockDevice method of class Stat. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_stat_async_is_block_device_001', 0, async function (done) { - let fpath = await nextFileName('fileio_stat_async_is_block_device_001'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let stat = await fileio.stat(fpath); - expect(stat.isBlockDevice() === false).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - done(); - } catch (e) { - console.log('fileio_stat_async_is_block_device_001 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_STAT_ASYNC_ISCHARACTERDEVICE_0000 - * @tc.name fileio_stat_async_is_character_device_000 - * @tc.desc Test the isCharacterDevice method of class Stat. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_stat_async_is_character_device_000', 0, async function (done) { - let fpath = await nextFileName('fileio_stat_async_is_character_device_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let stat = await fileio.stat(fpath); - expect(isBoolean(stat.isCharacterDevice())).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - done(); - } catch (e) { - console.log('fileio_stat_async_is_character_device_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_STAT_ASYNC_ISCHARACTERDEVICE_0010 - * @tc.name fileio_stat_async_is_character_device_001 - * @tc.desc Test the isCharacterDevice method of class Stat. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_stat_async_is_character_device_001', 0, async function (done) { - let fpath = await nextFileName('fileio_stat_async_is_character_device_001'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let stat = await fileio.stat(fpath); - expect(stat.isCharacterDevice() === false).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - done(); - } catch (e) { - console.log('fileio_stat_async_is_character_device_001 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_STAT_ASYNC_ISDIRECTORY_0000 - * @tc.name fileio_stat_async_is_directory_000 - * @tc.desc Test Stat.isDirectory() interface. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_stat_async_is_directory_000', 0, async function (done) { - let fpath = await nextFileName('fileio_stat_async_is_directory_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let stat = await fileio.stat(fpath); - expect(isBoolean(stat.isDirectory())).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - done(); - } catch (e) { - console.log('fileio_stat_async_is_directory_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_STAT_ASYNC_ISDIRECTORY_0010 - * @tc.name fileio_stat_async_is_directory_001 - * @tc.desc Test Stat.isDirectory() interface. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_stat_async_is_directory_001', 0, async function (done) { - let fpath = await nextFileName('fileio_stat_async_is_directory_001'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let stat = await fileio.stat(fpath); - expect(stat.isDirectory() === false).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - done(); - } catch (e) { - console.log('fileio_stat_async_is_directory_001 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_STAT_ASYNC_ISDIRECTORY_0020 - * @tc.name fileio_stat_async_is_directory_002 - * @tc.desc Test Stat.isDirectory() interface. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_stat_async_is_directory_002', 0, async function (done) { - let dpath = await nextFileName('fileio_stat_async_is_directory_002') + 'd'; - - try { - expect(fileio.mkdirSync(dpath) == null).assertTrue(); - let stat = await fileio.stat(dpath); - expect(stat.isDirectory()).assertTrue(); - expect(fileio.rmdirSync(dpath) == null).assertTrue(); - done(); - } catch (e) { - console.log('fileio_stat_async_is_directory_002 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_STAT_ASYNC_ISFIFO_0000 - * @tc.name fileio_stat_async_is_fifo_000 - * @tc.desc Test Stat.isFIFO() interface. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_stat_async_is_fifo_000', 0, async function (done) { - let fpath = await nextFileName('fileio_stat_async_is_fifo_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let stat = await fileio.stat(fpath); - expect(isBoolean(stat.isFIFO())).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - done(); - } catch (e) { - console.log('fileio_stat_async_is_fifo_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_STAT_ASYNC_ISFIFO_0010 - * @tc.name fileio_stat_async_is_fifo_001 - * @tc.desc Test Stat.isFIFO() interface. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_stat_async_is_fifo_001', 0, async function (done) { - let fpath = await nextFileName('fileio_stat_async_is_fifo_001'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let stat = await fileio.stat(fpath); - expect(stat.isFIFO() === false).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - done(); - } catch (e) { - console.log('fileio_stat_async_is_fifo_001 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_STAT_ASYNC_ISFILE_0000 - * @tc.name fileio_stat_async_is_file_000 - * @tc.desc Test Stat.isFile() interface. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_stat_async_is_file_000', 0, async function (done) { - let fpath = await nextFileName('fileio_stat_async_is_file_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let stat = await fileio.stat(fpath); - expect(isBoolean(stat.isFile())).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - done(); - } catch (e) { - console.log('fileio_stat_async_is_file_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_STAT_ASYNC_ISFILE_0010 - * @tc.name fileio_stat_async_is_file_001 - * @tc.desc Test Stat.isFile() interface. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_stat_async_is_file_001', 0, async function (done) { - let fpath = await nextFileName('fileio_stat_async_is_file_001'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let stat = await fileio.stat(fpath); - expect(stat.isFile()).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - done(); - } catch (e) { - console.log('fileio_stat_async_is_file_001 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_STAT_ASYNC_ISFILE_0020 - * @tc.name fileio_stat_async_is_file_002 - * @tc.desc Test Stat.isFile() interface. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_stat_async_is_file_002', 0, async function (done) { - let dpath = await nextFileName('fileio_stat_async_is_file_002'); - - try { - expect(fileio.mkdirSync(dpath) == null).assertTrue(); - let stat = await fileio.stat(dpath); - expect(stat.isFile() === false).assertTrue(); - expect(fileio.rmdirSync(dpath) == null).assertTrue(); - done(); - } catch (e) { - console.log('fileio_stat_async_is_file_002 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_STAT_ASYNC_ISSOCKET_0000 - * @tc.name fileio_stat_async_is_socket_000 - * @tc.desc Test Stat.isSocket() interface. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_stat_async_is_socket_000', 0, async function (done) { - let fpath = await nextFileName('fileio_stat_async_is_socket_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let stat = await fileio.stat(fpath); - expect(isBoolean(stat.isSocket())).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - done(); - } catch (e) { - console.log('fileio_stat_async_is_socket_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_STAT_ASYNC_ISSOCKET_0010 - * @tc.name fileio_stat_async_is_socket_001 - * @tc.desc Test Stat.isSocket() interface. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_stat_async_is_socket_001', 0, async function (done) { - let fpath = await nextFileName('fileio_stat_async_is_socket_001'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let stat = await fileio.stat(fpath); - expect(stat.isSocket() === false).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - done(); - } catch (e) { - console.log('fileio_stat_async_is_socket_001 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_STAT_ASYNC_ISSYMBOLICLINK_0000 - * @tc.name fileio_stat_async_is_symbolic_link_000 - * @tc.desc Test Stat.isSymbolicLink() interface. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_stat_async_is_symbolic_link_000', 0, async function (done) { - let fpath = await nextFileName('fileio_stat_async_is_symbolic_link_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let stat = await fileio.stat(fpath); - expect(isBoolean(stat.isSymbolicLink())).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - done(); - } catch (e) { - console.log('fileio_stat_async_is_symbolic_link_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_STAT_ASYNC_ISSYMBOLICLINK_0010 - * @tc.name fileio_stat_async_is_symbolic_link_001 - * @tc.desc Test Stat.isSymbolicLink() interface. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_stat_async_is_symbolic_link_001', 0, async function (done) { - let fpath = await nextFileName('fileio_stat_async_is_symbolic_link_001'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let stat = await fileio.stat(fpath); - expect(stat.isSymbolicLink() === false).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - done(); - } catch (e) { - console.log('fileio_stat_async_is_symbolic_link_001 has failed for ' + e); - expect(null).assertFail(); - } - }); - - it('fileio_test_append_file_sync_000', 0, async function (done) { - let fpath = await nextFileName('fileio_test_append_file_sync_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let stat = fileio.statSync(fpath); - expect(isIntNum(stat.size)).assertTrue(); - - let fd = fileio.openSync(fpath, 0o2002); - expect(isIntNum(fd)).assertTrue(); - - expect(fileio.writeSync(fd, FILE_CONTENT) == FILE_CONTENT.length).assertTrue(); - expect(fileio.closeSync(fd) == null).assertTrue(); - - stat = fileio.statSync(fpath); - expect(stat.size == FILE_CONTENT.length * 2).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - } catch (e) { - console.log('fileio_test_append_file_sync_000 has failed for ' + e); - expect(null).assertFail(); - } - done(); - }); -});} +/* + * Copyright (C) 2021 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 { + fileio, FILE_CONTENT, prepareFile, nextFileName, isIntNum, isBigInt, isBoolean, + describe, it, expect, +} from '../../Common'; + +export default function fileioStat() { +describe('fileio_stat', function () { + + /** + * @tc.number SUB_DF_FILEIO_STAT_SYNC_0000 + * @tc.name fileio_stat_sync_000 + * @tc.desc Test Stat.statSync() interfaces. + * This interface shall work properly in normal case. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_stat_sync_000', 0, async function () { + let fpath = await nextFileName('fileio_stat_sync_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileio.statSync(fpath); + expect(stat !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_stat_sync_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STAT_SYNC_0010 + * @tc.name fileio_stat_sync_001 + * @tc.desc Test Stat.statSync() interfaces. + * This interface shall throw an exception when the file isnt's exist. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_stat_sync_001', 0, async function () { + let fpath = await nextFileName('fileio_stat_sync_001'); + + try { + fileio.statSync(fpath); + expect(null).assertFail(); + } catch (e) { + console.log('fileio_stat_sync_001 has failed for ' + e); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STAT_SYNC_DEV_0000 + * @tc.name fileio_stat_sync_dev_000 + * @tc.desc Test Stat.statSync_Dev() interfaces. + * @tc.desc Test the dev member of class Stat. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_stat_sync_dev_000', 0, async function () { + let fpath = await nextFileName('fileio_stat_sync_dev_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileio.statSync(fpath); + expect(isIntNum(stat.dev)).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_stat_sync_dev_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STAT_INO_0000 + * @tc.name fileio_stat_sync_ino_000 + * @tc.desc Test Stat.statSync_Ino() interfaces. + * @tc.desc Test the ino member of class Stat + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_stat_sync_ino_000', 0, async function () { + let fpath = await nextFileName('fileio_stat_sync_ino_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileio.statSync(fpath); + expect(isBigInt(stat.ino)).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_stat_sync_ino_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STAT_MODE_0000 + * @tc.name fileio_stat_sync_mode_000 + * @tc.desc Test Stat.statSync_Mode() interfaces. + * @tc.desc Test the mode member of class Stat + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_stat_sync_mode_000', 0, async function () { + let fpath = await nextFileName('fileio_stat_sync_mode_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileio.statSync(fpath); + expect(isIntNum(stat.mode)).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_stat_sync_mode_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STAT_NLINK_0000 + * @tc.name fileio_stat_sync_nlink_000 + * @tc.desc Test Stat.statSync_Nlink() interfaces. + * @tc.desc Test the nlink member of class Stat + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_stat_sync_nlink_000', 0, async function () { + let fpath = await nextFileName('fileio_stat_sync_nlink_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileio.statSync(fpath); + expect(isIntNum(stat.nlink)).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_stat_sync_nlink_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STAT_UID_0000 + * @tc.name fileio_stat_sync_uid_000 + * @tc.desc Test Stat.statSync_Uid() interfaces. + * @tc.desc Test the uid member of class Stat + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_stat_sync_uid_000', 0, async function () { + let fpath = await nextFileName('fileio_stat_sync_uid_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileio.statSync(fpath); + expect(isIntNum(stat.uid)).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_stat_sync_uid_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STAT_SYNC_GID_0000 + * @tc.name fileio_stat_sync_gid_000 + * @tc.desc Test Stat.statSync_Gid() interfaces. + * @tc.desc Test the gid member of class Stat + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_stat_sync_gid_000', 0, async function () { + let fpath = await nextFileName('fileio_stat_sync_gid_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileio.statSync(fpath); + expect(isIntNum(stat.gid)).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_stat_sync_gid_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STAT_SYNC_RDEV_0000 + * @tc.name fileio_stat_sync_rdev_000 + * @tc.desc Test Stat.statSync_Rdev() interfaces. + * @tc.desc Test the rdev member of class Stat + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_stat_sync_rdev_000', 0, async function () { + let fpath = await nextFileName('fileio_stat_sync_rdev_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileio.statSync(fpath); + expect(isIntNum(stat.rdev)).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_stat_sync_rdev_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STAT_SYNC_SIZE_0000 + * @tc.name fileio_stat_sync_size_000 + * @tc.desc Test Stat.statSync_Size() interfaces. + * @tc.desc Test the size member of class Stat + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_stat_sync_size_000', 0, async function () { + let fpath = await nextFileName('fileio_stat_sync_size_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileio.statSync(fpath); + expect(isIntNum(stat.size)).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_stat_sync_size_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STAT_SYNC_BLOCKS_0000 + * @tc.name fileio_stat_sync_blocks_000 + * @tc.desc Test Stat.statSync_Block() interfaces. + * @tc.desc Test the blocks member of class Stat + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_stat_sync_blocks_000', 0, async function () { + let fpath = await nextFileName('fileio_stat_sync_blocks_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileio.statSync(fpath); + expect(isIntNum(stat.blocks)).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_stat_sync_blocks_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STAT_SYNC_ATIME_0000 + * @tc.name fileio_stat_sync_atime_000 + * @tc.desc Test Stat.statSync_Atime() interfaces. + * @tc.desc Test the atime member of class Stat + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_stat_sync_atime_000', 0, async function () { + let fpath = await nextFileName('fileio_stat_sync_atime_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileio.statSync(fpath); + expect(isIntNum(stat.atime)).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_stat_sync_atime_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STAT_SYNC_MTIME_0000 + * @tc.name fileio_stat_sync_mtime_000 + * @tc.desc Test Stat.statSync_Mtime() interfaces. + * @tc.desc Test the mtime member of class Stat + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_stat_sync_mtime_000', 0, async function () { + let fpath = await nextFileName('fileio_stat_sync_mtime_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileio.statSync(fpath); + expect(isIntNum(stat.mtime)).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_stat_sync_mtime_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STAT_SYNC_CTIME_0000 + * @tc.name fileio_stat_sync_ctime_000 + * @tc.desc Test Stat.statSync_Ctime() interfaces. + * @tc.desc Test the ctime member of class Stat + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_stat_sync_ctime_000', 0, async function () { + let fpath = await nextFileName('fileio_stat_sync_ctime_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileio.statSync(fpath); + expect(isIntNum(stat.ctime)).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_stat_sync_ctime_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STAT_SYNC_ISBLOCKDEVICE_0000 + * @tc.name fileio_stat_sync_is_block_device_000 + * @tc.desc Test Stat.statSync_IsBlockDevice() interfaces. + * @tc.desc Test the isBlockDevice() method of class Stat. + * This interface shall return a boolean variable. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_stat_sync_is_block_device_000', 0, async function () { + let fpath = await nextFileName('fileio_stat_sync_is_block_device_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileio.statSync(fpath); + expect(isBoolean(stat.isBlockDevice())).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_stat_sync_is_block_device_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STAT_SYNC_ISBLOCKDEVICE_0010 + * @tc.name fileio_stat_sync_is_block_device_001 + * @tc.desc Test Stat.statSync_IsBlockDevice() interfaces. + * @tc.desc Test the isBlockDevice() method of class Stat. + * This interface shall not treat a normal file as a block special device. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_stat_sync_is_block_device_001', 0, async function () { + let fpath = await nextFileName('fileio_stat_sync_is_block_device_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileio.statSync(fpath); + expect(stat.isBlockDevice() === false).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_stat_sync_is_block_device_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STAT_SYNC_ISBLOCKDEVICE_0020 + * @tc.name fileio_stat_sync_is_block_device_002 + * @tc.desc Test Stat.statSync_IsBlockDevice() interfaces. + * @tc.desc Test the isBlockDevice() method of class Stat. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_stat_sync_is_block_device_002', 0, async function () { + let fpath = await nextFileName('fileio_stat_sync_is_block_device_002'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileio.statSync(fpath); + expect(stat.isBlockDevice(-1) === false).assertTrue(); + expect(null).assertFail(); + } catch (e) { + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STAT_SYNC_ISCHARACTER_DEVICE_0000 + * @tc.name fileio_stat_sync_is_character_device_000 + * @tc.desc Test Stat.statsync_IsCharacterDevice() interfaces. + * This interface shall return a boolean variable. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_stat_sync_is_character_device_000', 0, async function () { + let fpath = await nextFileName('fileio_stat_sync_is_character_device_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileio.statSync(fpath); + expect(isBoolean(stat.isCharacterDevice())).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_stat_sync_is_character_device_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STAT_SYNC_ISCHARACTER_DEVICE_0010 + * @tc.name fileio_stat_sync_is_character_device_001 + * @tc.desc Test Stat.statsync_IsCharacterDevice() interfaces. + * This interface shall not treat a normal file as a character special device. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_stat_sync_is_character_device_001', 0, async function () { + let fpath = await nextFileName('fileio_stat_sync_is_character_device_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileio.statSync(fpath); + expect(stat.isCharacterDevice() === false).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_stat_sync_is_character_device_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STAT_SYNC_ISCHARACTER_DEVICE_0020 + * @tc.name fileio_stat_sync_is_character_device_002 + * @tc.desc Test Stat.statsync_IsCharacterDevice() interfaces. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_stat_sync_is_character_device_002', 0, async function () { + let fpath = await nextFileName('fileio_stat_sync_is_character_device_002'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileio.statSync(fpath); + expect(stat.isCharacterDevice(-1) === false).assertTrue(); + expect(null).assertFail(); + } catch (e) { + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STAT_SYNC_ISDIRECTORY_0000 + * @tc.name fileio_stat_sync_is_directory_000 + * @tc.desc Test Stat.statsync_isDirectory() interfaces. + * This interface shall return a boolean variable. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_stat_sync_is_directory_000', 0, async function () { + let fpath = await nextFileName('fileio_stat_sync_is_directory_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileio.statSync(fpath); + expect(isBoolean(stat.isDirectory())).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_stat_sync_is_directory_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STAT_SYNC_ISDIRECTORY_0010 + * @tc.name fileio_stat_sync_is_directory_001 + * @tc.desc Test Stat.statsync_isDirectory() interfaces. + * This interface shall not treat a normal file as a directory. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_stat_sync_is_directory_001', 0, async function () { + let fpath = await nextFileName('fileio_stat_sync_is_directory_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileio.statSync(fpath); + expect(stat.isDirectory() === false).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_stat_sync_is_directory_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STAT_SYNC_ISDIRECTORY_0020 + * @tc.name fileio_stat_sync_is_directory_002 + * @tc.desc Test Stat.statsync_isDirectory() interfaces. + * This interface shall treat a directory as a directory. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_stat_sync_is_directory_002', 0, async function () { + let dpath = await nextFileName('fileio_stat_sync_is_directory_002') + 'd'; + + try { + expect(fileio.mkdirSync(dpath) == null).assertTrue(); + let stat = fileio.statSync(dpath); + expect(stat.isDirectory()).assertTrue(); + expect(fileio.rmdirSync(dpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_stat_sync_is_directory_002 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STAT_SYNC_ISDIRECTORY_0030 + * @tc.name fileio_stat_sync_is_directory_003 + * @tc.desc Test Stat.statsync_isDirectory() interfaces. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_stat_sync_is_directory_003', 0, async function () { + let dpath = await nextFileName('fileio_stat_sync_is_directory_003') + 'd'; + + try { + expect(fileio.mkdirSync(dpath) == null).assertTrue(); + let stat = fileio.statSync(dpath); + expect(stat.isDirectory(-1)).assertTrue(); + expect(null).assertFail(); + } catch (e) { + expect(fileio.rmdirSync(dpath) == null).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STAT_SYNC_ISFIFO_0000 + * @tc.name fileio_stat_sync_is_fifo_000 + * @tc.desc Test Stat.statsync_isFIFO() interfaces. + * This interface shall return a boolean variable. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_stat_sync_is_fifo_000', 0, async function () { + let fpath = await nextFileName('fileio_stat_sync_is_fifo_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileio.statSync(fpath); + expect(isBoolean(stat.isFIFO())).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_stat_sync_is_fifo_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STAT_SYNC_ISFIFO_0010 + * @tc.name fileio_stat_sync_is_fifo_001 + * @tc.desc Test Stat.statsync_isFIFO() interfaces. + * This interface shall not treat a normal file as a FIFO. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_stat_sync_is_fifo_001', 0, async function () { + let fpath = await nextFileName('fileio_stat_sync_is_fifo_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileio.statSync(fpath); + expect(stat.isFIFO() === false).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_stat_sync_is_fifo_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STAT_SYNC_ISFIFO_0020 + * @tc.name fileio_stat_sync_is_fifo_002 + * @tc.desc Test Stat.statsync_isFIFO() interfaces. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_stat_sync_is_fifo_002', 0, async function () { + let fpath = await nextFileName('fileio_stat_sync_is_fifo_002'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileio.statSync(fpath); + expect(stat.isFIFO(-1) === false).assertTrue(); + expect(null).assertFail(); + } catch (e) { + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STAT_SYNC_ISFILE_0000 + * @tc.name fileio_stat_sync_is_file_000 + * @tc.desc Test Stat.statsync_isFile() interfaces. + * This interface shall return a boolean variable. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_stat_sync_is_file_000', 0, async function () { + let fpath = await nextFileName('fileio_stat_sync_is_file_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileio.statSync(fpath); + expect(isBoolean(stat.isFile())).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_stat_sync_is_file_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STAT_SYNC_ISFILE_0010 + * @tc.name fileio_stat_sync_is_file_001 + * @tc.desc Test Stat.statsync_isFile() interfaces. + * This interface shall treat a normal file as a normal file. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_stat_sync_is_file_001', 0, async function () { + let fpath = await nextFileName('fileio_stat_sync_is_file_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileio.statSync(fpath); + expect(stat.isFile()).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_stat_sync_is_file_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STAT_SYNC_ISFILE_0020 + * @tc.name fileio_stat_sync_is_file_002 + * @tc.desc Test Stat.statsync_isFile() interfaces. + * This interface shall not treat a directory as a normal file. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_stat_sync_is_file_002', 0, async function () { + let dpath = await nextFileName('fileio_stat_sync_is_file_002'); + + try { + expect(fileio.mkdirSync(dpath) == null).assertTrue(); + let stat = fileio.statSync(dpath); + expect(stat.isFile() === false).assertTrue(); + expect(fileio.rmdirSync(dpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_stat_sync_is_file_002 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STAT_SYNC_ISFILE_0030 + * @tc.name fileio_stat_sync_is_file_003 + * @tc.desc Test Stat.statsync_isFile() interfaces. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_stat_sync_is_file_003', 0, async function () { + let dpath = await nextFileName('fileio_stat_sync_is_file_003'); + + try { + expect(fileio.mkdirSync(dpath) == null).assertTrue(); + let stat = fileio.statSync(dpath); + expect(stat.isFile(-1) === false).assertTrue(); + expect(null).assertFail(); + } catch (e) { + expect(fileio.rmdirSync(dpath) == null).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STAT_SYNC_ISSOCKET_0000 + * @tc.name fileio_stat_sync_is_socket_000 + * @tc.desc Test Stat.statsync_isSocket() interfaces. + * This interface shall return a boolean variable. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_stat_sync_is_socket_000', 0, async function () { + let fpath = await nextFileName('fileio_stat_sync_is_socket_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileio.statSync(fpath); + expect(isBoolean(stat.isSocket())).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_stat_sync_is_socket_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STAT_SYNC_ISSOCKET_0010 + * @tc.name fileio_stat_sync_is_socket_001 + * @tc.desc Test Stat.statsync_isSocket() interfaces. + * This interface shall not treat a file as a socket. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_stat_sync_is_socket_001', 0, async function () { + let fpath = await nextFileName('fileio_stat_sync_is_socket_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileio.statSync(fpath); + expect(stat.isSocket() === false).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_stat_sync_is_socket_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STAT_SYNC_ISSOCKET_0020 + * @tc.name fileio_stat_sync_is_socket_002 + * @tc.desc Test Stat.statsync_isSocket() interfaces. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_stat_sync_is_socket_002', 0, async function () { + let fpath = await nextFileName('fileio_stat_sync_is_socket_002'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileio.statSync(fpath); + expect(stat.isSocket(-1) === false).assertTrue(); + expect(null).assertFail(); + } catch (e) { + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STAT_SYNC_ISSYMBOLICLINK_0000 + * @tc.name fileio_stat_sync_is_symbolic_link_000 + * @tc.desc Test Stat.statasync_isSymbolicLink() interfaces. + * This interface shall return a boolean variable. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_stat_sync_is_symbolic_link_000', 0, async function () { + let fpath = await nextFileName('fileio_stat_sync_is_symbolic_link_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileio.statSync(fpath); + expect(isBoolean(stat.isSymbolicLink())).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_stat_sync_is_symbolic_link_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STAT_SYNC_ISSYMBOLICLINK_0010 + * @tc.name fileio_stat_sync_is_symbolic_link_001 + * @tc.desc Test Stat.statasync_isSymbolicLink() interfaces. + * This interface shall not treat a normal file as a symbolic link. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_stat_sync_is_symbolic_link_001', 0, async function () { + let fpath = await nextFileName('fileio_stat_sync_is_symbolic_link_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileio.statSync(fpath); + expect(stat.isSymbolicLink() === false).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_stat_is_symbolic_link_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STAT_SYNC_ISSYMBOLICLINK_0020 + * @tc.name fileio_stat_sync_is_symbolic_link_002 + * @tc.desc Test Stat.isSymbolicLink() interfaces. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_stat_sync_is_symbolic_link_002', 0, async function () { + let fpath = await nextFileName('fileio_stat_sync_is_symbolic_link_002'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileio.statSync(fpath); + expect(stat.isSymbolicLink(-1) === false).assertTrue(); + expect(null).assertFail(); + } catch (e) { + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STAT_ASYNC_0000 + * @tc.name fileio_stat_async_000 + * @tc.desc Test Stat.statAsync() interface. + * This interface shall work properly in normal case when providing the promise async model. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_stat_async_000', 0, async function (done) { + let fpath = await nextFileName('fileio_stat_async_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + fileio.stat(fpath).then((stat) => { + expect(stat !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + }); + done(); + } catch (e) { + console.log('fileio_stat_async_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STAT_ASYNC_0000 + * @tc.name fileio_stat_async_001 + * @tc.desc Test Stat.statAsync() interface. + * This interface shall work properly in normal case when providing the callback async model. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_stat_async_001', 0, async function (done) { + let fpath = await nextFileName('fileio_stat_async_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + fileio.stat(fpath, function (error) { + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + }); + } catch (e) { + console.log('fileio_stat_async_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STAT_ASYNC_DEV_0000 + * @tc.name fileio_stat_async_dev_000 + * @tc.desc Test the dev member of class Stat. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_stat_async_dev_000', 0, async function (done) { + let fpath = await nextFileName('fileio_stat_async_dev_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = await fileio.stat(fpath); + expect(isIntNum(stat.dev)).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_stat_async_dev_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STAT_ASYNC_INO_0000 + * @tc.name fileio_stat_async_ino_000 + * @tc.desc Test the ino member of class Stat. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_stat_async_ino_000', 0, async function (done) { + let fpath = await nextFileName('fileio_stat_async_ino_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = await fileio.stat(fpath); + expect(isBigInt(stat.ino)).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_stat_async_ino_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STAT_ASYNC_MODE_0000 + * @tc.name fileio_stat_async_mode_000 + * @tc.desc Test the mode member of class Stat. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_stat_async_mode_000', 0, async function (done) { + let fpath = await nextFileName('fileio_stat_async_mode_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = await fileio.stat(fpath); + expect(isIntNum(stat.mode)).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_stat_async_mode_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STAT_ASYNC_NLINK_0000 + * @tc.name fileio_stat_async_nlink_000 + * @tc.desc Test the nlink member of class Stat. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_stat_async_nlink_000', 0, async function (done) { + let fpath = await nextFileName('fileio_stat_async_nlink_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = await fileio.stat(fpath); + expect(isIntNum(stat.nlink)).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_stat_async_nlink_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STAT_ASYNC_UID_0000 + * @tc.name fileio_stat_async_uid_000 + * @tc.desc Test the uid member of class Stat. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_stat_async_uid_000', 0, async function (done) { + let fpath = await nextFileName('fileio_stat_async_uid_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = await fileio.stat(fpath); + expect(isIntNum(stat.uid)).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_stat_async_uid_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STAT_ASYNC_GID_0000 + * @tc.name fileio_stat_async_gid_000 + * @tc.desc Test the gid member of class Stat. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_stat_async_gid_000', 0, async function (done) { + let fpath = await nextFileName('fileio_stat_async_gid_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = await fileio.stat(fpath); + expect(isIntNum(stat.gid)).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_stat_async_gid_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STAT_ASYNC_RDEV_0000 + * @tc.name fileio_stat_async_rdev_000 + * @tc.desc Test the rdev member of class Stat. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_stat_async_rdev_000', 0, async function (done) { + let fpath = await nextFileName('fileio_stat_async_rdev_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = await fileio.stat(fpath); + expect(isIntNum(stat.rdev)).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_stat_async_rdev_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STAT_ASYNC_SIZE_0000 + * @tc.name fileio_stat_async_size_000 + * @tc.desc Test the size member of class Stat. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_stat_async_size_000', 0, async function (done) { + let fpath = await nextFileName('fileio_stat_async_size_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = await fileio.stat(fpath); + expect(isIntNum(stat.size)).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_stat_async_size_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STAT_ASYNC_BLOCKS_0000 + * @tc.name fileio_stat_async_blocks_000 + * @tc.desc Test Stat.blocks() interface. + * @tc.desc Test the blocks member of class Stat. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_stat_async_blocks_000', 0, async function (done) { + let fpath = await nextFileName('fileio_stat_async_blocks_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = await fileio.stat(fpath); + expect(isIntNum(stat.blocks)).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_stat_async_blocks_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STAT_ASYNC_ATIME_0000 + * @tc.name fileio_stat_async_atime_000 + * @tc.desc Test Stat.atime() interface. + * @tc.desc Test the atime member of class Stat. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_stat_async_atime_000', 0, async function (done) { + let fpath = await nextFileName('fileio_stat_async_atime_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = await fileio.stat(fpath); + expect(isIntNum(stat.atime)).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_stat_async_atime_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STAT_ASYNC_MTIME_0000 + * @tc.name fileio_stat_async_mtime_000 + * @tc.desc Test Stat.mtime() interface. + * @tc.desc Test the mtime member of class Stat. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_stat_async_mtime_000', 0, async function (done) { + let fpath = await nextFileName('fileio_stat_async_mtime_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = await fileio.stat(fpath); + expect(isIntNum(stat.mtime)).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_stat_async_mtime_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STAT_ASYNC_CTIME_0000 + * @tc.name fileio_stat_async_ctime_000 + * @tc.desc Test the ctime member of class Stat. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_stat_async_ctime_000', 0, async function (done) { + let fpath = await nextFileName('fileio_stat_async_ctime_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = await fileio.stat(fpath); + expect(isIntNum(stat.ctime)).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_stat_async_ctime_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STAT_ASYNC_ISBLOCKDEVICE_0000 + * @tc.name fileio_stat_async_is_block_device_000 + * @tc.desc Test the isBlockDevice method of class Stat. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_stat_async_is_block_device_000', 0, async function (done) { + let fpath = await nextFileName('fileio_stat_async_is_block_device_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = await fileio.stat(fpath); + expect(isBoolean(stat.isBlockDevice())).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_stat_async_is_block_device_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STAT_ASYNC_ISBLOCKDEVICE_0010 + * @tc.name fileio_stat_async_is_block_device_001 + * @tc.desc Test the isBlockDevice method of class Stat. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_stat_async_is_block_device_001', 0, async function (done) { + let fpath = await nextFileName('fileio_stat_async_is_block_device_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = await fileio.stat(fpath); + expect(stat.isBlockDevice() === false).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_stat_async_is_block_device_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STAT_ASYNC_ISCHARACTERDEVICE_0000 + * @tc.name fileio_stat_async_is_character_device_000 + * @tc.desc Test the isCharacterDevice method of class Stat. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_stat_async_is_character_device_000', 0, async function (done) { + let fpath = await nextFileName('fileio_stat_async_is_character_device_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = await fileio.stat(fpath); + expect(isBoolean(stat.isCharacterDevice())).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_stat_async_is_character_device_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STAT_ASYNC_ISCHARACTERDEVICE_0010 + * @tc.name fileio_stat_async_is_character_device_001 + * @tc.desc Test the isCharacterDevice method of class Stat. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_stat_async_is_character_device_001', 0, async function (done) { + let fpath = await nextFileName('fileio_stat_async_is_character_device_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = await fileio.stat(fpath); + expect(stat.isCharacterDevice() === false).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_stat_async_is_character_device_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STAT_ASYNC_ISDIRECTORY_0000 + * @tc.name fileio_stat_async_is_directory_000 + * @tc.desc Test Stat.isDirectory() interface. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_stat_async_is_directory_000', 0, async function (done) { + let fpath = await nextFileName('fileio_stat_async_is_directory_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = await fileio.stat(fpath); + expect(isBoolean(stat.isDirectory())).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_stat_async_is_directory_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STAT_ASYNC_ISDIRECTORY_0010 + * @tc.name fileio_stat_async_is_directory_001 + * @tc.desc Test Stat.isDirectory() interface. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_stat_async_is_directory_001', 0, async function (done) { + let fpath = await nextFileName('fileio_stat_async_is_directory_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = await fileio.stat(fpath); + expect(stat.isDirectory() === false).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_stat_async_is_directory_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STAT_ASYNC_ISDIRECTORY_0020 + * @tc.name fileio_stat_async_is_directory_002 + * @tc.desc Test Stat.isDirectory() interface. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_stat_async_is_directory_002', 0, async function (done) { + let dpath = await nextFileName('fileio_stat_async_is_directory_002') + 'd'; + + try { + expect(fileio.mkdirSync(dpath) == null).assertTrue(); + let stat = await fileio.stat(dpath); + expect(stat.isDirectory()).assertTrue(); + expect(fileio.rmdirSync(dpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_stat_async_is_directory_002 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STAT_ASYNC_ISFIFO_0000 + * @tc.name fileio_stat_async_is_fifo_000 + * @tc.desc Test Stat.isFIFO() interface. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_stat_async_is_fifo_000', 0, async function (done) { + let fpath = await nextFileName('fileio_stat_async_is_fifo_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = await fileio.stat(fpath); + expect(isBoolean(stat.isFIFO())).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_stat_async_is_fifo_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STAT_ASYNC_ISFIFO_0010 + * @tc.name fileio_stat_async_is_fifo_001 + * @tc.desc Test Stat.isFIFO() interface. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_stat_async_is_fifo_001', 0, async function (done) { + let fpath = await nextFileName('fileio_stat_async_is_fifo_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = await fileio.stat(fpath); + expect(stat.isFIFO() === false).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_stat_async_is_fifo_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STAT_ASYNC_ISFILE_0000 + * @tc.name fileio_stat_async_is_file_000 + * @tc.desc Test Stat.isFile() interface. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_stat_async_is_file_000', 0, async function (done) { + let fpath = await nextFileName('fileio_stat_async_is_file_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = await fileio.stat(fpath); + expect(isBoolean(stat.isFile())).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_stat_async_is_file_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STAT_ASYNC_ISFILE_0010 + * @tc.name fileio_stat_async_is_file_001 + * @tc.desc Test Stat.isFile() interface. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_stat_async_is_file_001', 0, async function (done) { + let fpath = await nextFileName('fileio_stat_async_is_file_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = await fileio.stat(fpath); + expect(stat.isFile()).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_stat_async_is_file_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STAT_ASYNC_ISFILE_0020 + * @tc.name fileio_stat_async_is_file_002 + * @tc.desc Test Stat.isFile() interface. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_stat_async_is_file_002', 0, async function (done) { + let dpath = await nextFileName('fileio_stat_async_is_file_002'); + + try { + expect(fileio.mkdirSync(dpath) == null).assertTrue(); + let stat = await fileio.stat(dpath); + expect(stat.isFile() === false).assertTrue(); + expect(fileio.rmdirSync(dpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_stat_async_is_file_002 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STAT_ASYNC_ISSOCKET_0000 + * @tc.name fileio_stat_async_is_socket_000 + * @tc.desc Test Stat.isSocket() interface. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_stat_async_is_socket_000', 0, async function (done) { + let fpath = await nextFileName('fileio_stat_async_is_socket_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = await fileio.stat(fpath); + expect(isBoolean(stat.isSocket())).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_stat_async_is_socket_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STAT_ASYNC_ISSOCKET_0010 + * @tc.name fileio_stat_async_is_socket_001 + * @tc.desc Test Stat.isSocket() interface. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_stat_async_is_socket_001', 0, async function (done) { + let fpath = await nextFileName('fileio_stat_async_is_socket_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = await fileio.stat(fpath); + expect(stat.isSocket() === false).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_stat_async_is_socket_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STAT_ASYNC_ISSYMBOLICLINK_0000 + * @tc.name fileio_stat_async_is_symbolic_link_000 + * @tc.desc Test Stat.isSymbolicLink() interface. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_stat_async_is_symbolic_link_000', 0, async function (done) { + let fpath = await nextFileName('fileio_stat_async_is_symbolic_link_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = await fileio.stat(fpath); + expect(isBoolean(stat.isSymbolicLink())).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_stat_async_is_symbolic_link_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STAT_ASYNC_ISSYMBOLICLINK_0010 + * @tc.name fileio_stat_async_is_symbolic_link_001 + * @tc.desc Test Stat.isSymbolicLink() interface. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_stat_async_is_symbolic_link_001', 0, async function (done) { + let fpath = await nextFileName('fileio_stat_async_is_symbolic_link_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = await fileio.stat(fpath); + expect(stat.isSymbolicLink() === false).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_stat_async_is_symbolic_link_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + it('fileio_test_append_file_sync_000', 0, async function (done) { + let fpath = await nextFileName('fileio_test_append_file_sync_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileio.statSync(fpath); + expect(isIntNum(stat.size)).assertTrue(); + + let fd = fileio.openSync(fpath, 0o2002); + expect(isIntNum(fd)).assertTrue(); + + expect(fileio.writeSync(fd, FILE_CONTENT) == FILE_CONTENT.length).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + + stat = fileio.statSync(fpath); + expect(stat.size == FILE_CONTENT.length * 2).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_test_append_file_sync_000 has failed for ' + e); + expect(null).assertFail(); + } + done(); + }); +});} diff --git a/storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/members/symlink.test.js b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/symlink.test.js similarity index 95% rename from storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/members/symlink.test.js rename to storage/storagefileiojstest/src/main/js/test/module_fileio/members/symlink.test.js index 97a85eab17f1ff3b2b4443357c3bbd9a13c06eee..a779d84d22f8d05695f2252bd6c8901810151cef 100644 --- a/storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/members/symlink.test.js +++ b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/symlink.test.js @@ -1,101 +1,101 @@ -/* - * Copyright (C) 2023 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 { - fileio, FILE_CONTENT, prepareFile, nextFileName, - describe, it, expect, -} from '../../Common'; - -export default function fileioSymlink() { -describe('fileio_symlink', function () { - - /** - * @tc.number SUB_DF_FILEIO_SYMLINK_SYNC_0000 - * @tc.name fileio_test_symlink_sync_000 - * @tc.desc Test SymlinkSync interfaces. - * This interface shall not treat a normal file as a directory. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_symlink_sync_000', 0, async function () { - let fpath = await nextFileName('fileio_test_symlink_sync_000'); - - try { - fileio.symlinkSync(fpath, fpath + 'aaaa'); - fileio.accessSync(fpath + 'aaaa'); - expect(null).assertFail(); - } catch (e) { - console.info('fileio_test_symlink_sync_000 has failed for ' + e); - fileio.unlinkSync(fpath + 'aaaa'); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_SYMLINK_ASYNC_0000 - * @tc.name fileio_test_symlink_async_000 - * @tc.desc Test SymlinkAsync interfaces. - * This interface shall not treat a normal file as a directory. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_symlink_async_000', 0, async function (done) { - let fpath = await nextFileName('fileio_test_symlink_async_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - fileio.symlink(fpath, fpath + '1067').then(function (err) { - fileio.accessSync(fpath + '1067'); - fileio.unlinkSync(fpath); - fileio.unlinkSync(fpath + '1067'); - }) - done(); - } catch (e) { - console.info('fileio_test_symlink_async_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_SYMLINK_ASYNC_0010 - * @tc.name fileio_test_symlink_async_001 - * @tc.desc Test SymlinkAsync interfaces. - * This interface shall not treat a normal file as a directory. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_symlink_async_001', 0, async function (done) { - let fpath = await nextFileName('fileio_test_symlink_async_001'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - fileio.symlink(fpath, fpath + 'pass2', function (err) { - fileio.accessSync(fpath + 'pass2'); - fileio.unlinkSync(fpath); - fileio.unlinkSync(fpath + 'pass2'); - done(); - }); - } catch (e) { - console.info('fileio_test_symlink_async_001 has failed for ' + e); - expect(null).assertFail(); - } - }); -}); -} +/* + * Copyright (C) 2021 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 { + fileio, FILE_CONTENT, prepareFile, nextFileName, + describe, it, expect, +} from '../../Common'; + +export default function fileioSymlink() { +describe('fileio_symlink', function () { + + /** + * @tc.number SUB_DF_FILEIO_SYMLINK_SYNC_0000 + * @tc.name fileio_test_symlink_sync_000 + * @tc.desc Test SymlinkSync interfaces. + * This interface shall not treat a normal file as a directory. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_symlink_sync_000', 0, async function () { + let fpath = await nextFileName('fileio_test_symlink_sync_000'); + + try { + fileio.symlinkSync(fpath, fpath + 'aaaa'); + fileio.accessSync(fpath + 'aaaa'); + expect(null).assertFail(); + } catch (e) { + console.info('fileio_test_symlink_sync_000 has failed for ' + e); + fileio.unlinkSync(fpath + 'aaaa'); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_SYMLINK_ASYNC_0000 + * @tc.name fileio_test_symlink_async_000 + * @tc.desc Test SymlinkAsync interfaces. + * This interface shall not treat a normal file as a directory. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_symlink_async_000', 0, async function (done) { + let fpath = await nextFileName('fileio_test_symlink_async_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + fileio.symlink(fpath, fpath + '1067').then(function (err) { + fileio.accessSync(fpath + '1067'); + fileio.unlinkSync(fpath); + fileio.unlinkSync(fpath + '1067'); + }) + done(); + } catch (e) { + console.info('fileio_test_symlink_async_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_SYMLINK_ASYNC_0010 + * @tc.name fileio_test_symlink_async_001 + * @tc.desc Test SymlinkAsync interfaces. + * This interface shall not treat a normal file as a directory. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_symlink_async_001', 0, async function (done) { + let fpath = await nextFileName('fileio_test_symlink_async_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + fileio.symlink(fpath, fpath + 'pass2', function (err) { + fileio.accessSync(fpath + 'pass2'); + fileio.unlinkSync(fpath); + fileio.unlinkSync(fpath + 'pass2'); + done(); + }); + } catch (e) { + console.info('fileio_test_symlink_async_001 has failed for ' + e); + expect(null).assertFail(); + } + }); +}); +} diff --git a/storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/members/truncate.test.js b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/truncate.test.js similarity index 96% rename from storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/members/truncate.test.js rename to storage/storagefileiojstest/src/main/js/test/module_fileio/members/truncate.test.js index 3511473b9fe90561fa15d019d36272a85e341b23..3f46d7add2a0e83829a2f964d54a30d4a15284b2 100644 --- a/storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/members/truncate.test.js +++ b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/truncate.test.js @@ -1,265 +1,265 @@ -/* - * Copyright (C) 2023 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 { - fileio, FILE_CONTENT, prepareFile, nextFileName, isIntNum, - describe, it, expect, -} from '../../Common'; - -export default function fileioTruncate() { -describe('fileio_truncate', function () { - - /** - * @tc.number SUB_DF_FILEIO_TRUNCATE_ASYNC_0000 - * @tc.name fileio_truncate_async_000 - * @tc.desc Test truncate() interfaces. Callback. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_truncate_async_000', 0, async function (done) { - let fpath = await nextFileName('fileio_truncate_async_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - let truncateLen = 5; - - try { - fileio.truncate(fpath, truncateLen, function (err) { - let fd = fileio.openSync(fpath, 0o2); - expect(isIntNum(fd)).assertTrue(); - let len = fileio.readSync(fd, new ArrayBuffer(4096)); - expect(len == truncateLen).assertTrue(); - expect(fileio.closeSync(fd) == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - done(); - }); - } catch (e) { - console.log('fileio_truncate_async_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_TRUNCATE_ASYNC_0100 - * @tc.name fileio_truncate_async_001 - * @tc.desc Test truncate() interfaces. Promise. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_truncate_async_001', 0, async function (done) { - let fpath = await nextFileName('fileio_truncate_async_001'); - expect(prepareFile(fpath, 'truncate')).assertTrue(); - let truncateLen = 2; - - try { - fileio - .truncate(fpath, truncateLen) - .then(function (err) { - expect(err == null).assertTrue(); - let fd = fileio.openSync(fpath, 0o2); - expect(isIntNum(fd)).assertTrue(); - let len = fileio.readSync(fd, new ArrayBuffer(4096)); - expect(len == truncateLen).assertTrue(); - expect(fileio.closeSync(fd) == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - done(); - }) - .catch(function (e) { - console.log('catch ' + e); - }); - } catch (e) { - console.log('fileio_truncate_async_001 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_TRUNCATE_ASYNC_0200 - * @tc.name fileio_truncate_async_002 - * @tc.desc Test truncate() interfaces. Callback. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_truncate_async_002', 0, async function (done) { - let fpath = await nextFileName('fileio_truncate_async_002'); - let truncateLen = 2; - - try { - fileio.truncate(fpath, truncateLen, function (err) { - done(); - }); - } catch (e) { - expect(!!e).assertTrue(); - done(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_TRUNCATE_ASYNC_0300 - * @tc.name fileio_truncate_async_003 - * @tc.desc Test the truncate() interface. Promise. - * Use default truncateLen = 0. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 3 - * @tc.require - */ - it('fileio_truncate_async_003', 3, async function (done) { - let fpath = await nextFileName('fileio_truncate_async_003'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - await fileio.truncate(fpath, undefined); - let fd = fileio.openSync(fpath, 0o2); - expect(isIntNum(fd)).assertTrue(); - let readLen = fileio.readSync(fd, new ArrayBuffer(4096)); - expect(readLen == 0).assertTrue(); - fileio.closeSync(fd); - fileio.unlinkSync(fpath); - done(); - } catch (e) { - console.log('fileio_truncate_async_003 has failed for ' + e); - expect(false).assertTrue(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_TRUNCATE_ASYNC_0400 - * @tc.name fileio_truncate_async_004 - * @tc.desc Test the truncate() interface. Callback. - * Use default truncateLen = 0. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 3 - * @tc.require - */ - it('fileio_truncate_async_004', 3, async function (done) { - let fpath = await nextFileName('fileio_truncate_async_004'); - expect(prepareFile(fpath, 'truncate')).assertTrue(); - - try { - fileio.truncate(fpath, undefined, (err) => { - if (err) { - console.log('fileio_truncate_async_004 error package: ' + JSON.stringify(err)); - expect(false).assertTrue(); - } - let fd = fileio.openSync(fpath, 0o2); - expect(isIntNum(fd)).assertTrue(); - let readLen = fileio.readSync(fd, new ArrayBuffer(4096)); - expect(readLen == 0).assertTrue(); - fileio.closeSync(fd); - fileio.unlinkSync(fpath); - done(); - }); - } catch(e) { - console.log('fileio_truncate_async_004 has failed for ' + e); - expect(false).assertTrue(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_TRUNCATE_SYNC_0000 - * @tc.name fileio_test_truncate_sync_000 - * @tc.desc Test truncateSync() interfaces. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_truncate_sync_000', 0, async function () { - let fpath = await nextFileName('fileio_test_truncate_sync_000'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - expect(fileio.truncateSync(fpath) == null).assertTrue(); - expect(fileio.statSync(fpath).size == 0).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - } catch (e) { - console.log('fileio_test_truncate_sync_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_TRUNCATE_SYNC_0100 - * @tc.name fileio_test_truncate_sync_001 - * @tc.desc Test truncateSync() interfaces. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_truncate_sync_001', 0, async function () { - let fpath = await nextFileName('fileio_test_truncate_sync_001'); - - try { - fileio.truncateSync(fpath); - expect(null).assertFail(); - } catch (e) { - console.log('fileio_test_truncate_sync_001 has failed for ' + e); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_TRUNCATE_SYNC_0200 - * @tc.name fileio_test_truncate_sync_002 - * @tc.desc Test truncateSync() interfaces. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_truncate_sync_002', 0, function () { - try { - fileio.truncateSync(); - expect(null).assertFail(); - } catch (e) { - console.log('fileio_test_truncate_sync_002 has failed for ' + e); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_TRUNCATE_SYNC_0300 - * @tc.name fileio_test_truncate_sync_003 - * @tc.desc Test the truncateSync() interface. - * Use default truncateLen = 0. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 3 - * @tc.require - */ - it('fileio_test_truncate_sync_003', 3, async function () { - let fpath = await nextFileName('fileio_test_truncate_sync_003'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - fileio.truncateSync(fpath, undefined); - let fd = fileio.openSync(fpath, 0o2); - expect(isIntNum(fd)).assertTrue(); - let readLen = fileio.readSync(fd, new ArrayBuffer(4096)); - expect(readLen == 0).assertTrue(); - fileio.closeSync(fd); - fileio.unlinkSync(fpath); - } catch (e) { - console.log('fileio_test_truncate_sync_003 has failed for ' + e); - expect(false).assertTrue(); - } - }); -}); -} +/* + * Copyright (C) 2021 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 { + fileio, FILE_CONTENT, prepareFile, nextFileName, isIntNum, + describe, it, expect, +} from '../../Common'; + +export default function fileioTruncate() { +describe('fileio_truncate', function () { + + /** + * @tc.number SUB_DF_FILEIO_TRUNCATE_ASYNC_0000 + * @tc.name fileio_truncate_async_000 + * @tc.desc Test truncate() interfaces. Callback. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_truncate_async_000', 0, async function (done) { + let fpath = await nextFileName('fileio_truncate_async_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let truncateLen = 5; + + try { + fileio.truncate(fpath, truncateLen, function (err) { + let fd = fileio.openSync(fpath, 0o2); + expect(isIntNum(fd)).assertTrue(); + let len = fileio.readSync(fd, new ArrayBuffer(4096)); + expect(len == truncateLen).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + }); + } catch (e) { + console.log('fileio_truncate_async_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_TRUNCATE_ASYNC_0100 + * @tc.name fileio_truncate_async_001 + * @tc.desc Test truncate() interfaces. Promise. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_truncate_async_001', 0, async function (done) { + let fpath = await nextFileName('fileio_truncate_async_001'); + expect(prepareFile(fpath, 'truncate')).assertTrue(); + let truncateLen = 2; + + try { + fileio + .truncate(fpath, truncateLen) + .then(function (err) { + expect(err == null).assertTrue(); + let fd = fileio.openSync(fpath, 0o2); + expect(isIntNum(fd)).assertTrue(); + let len = fileio.readSync(fd, new ArrayBuffer(4096)); + expect(len == truncateLen).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + }) + .catch(function (e) { + console.log('catch ' + e); + }); + } catch (e) { + console.log('fileio_truncate_async_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_TRUNCATE_ASYNC_0200 + * @tc.name fileio_truncate_async_002 + * @tc.desc Test truncate() interfaces. Callback. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_truncate_async_002', 0, async function (done) { + let fpath = await nextFileName('fileio_truncate_async_002'); + let truncateLen = 2; + + try { + fileio.truncate(fpath, truncateLen, function (err) { + done(); + }); + } catch (e) { + expect(!!e).assertTrue(); + done(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_TRUNCATE_ASYNC_0300 + * @tc.name fileio_truncate_async_003 + * @tc.desc Test the truncate() interface. Promise. + * Use default truncateLen = 0. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 3 + * @tc.require + */ + it('fileio_truncate_async_003', 3, async function (done) { + let fpath = await nextFileName('fileio_truncate_async_003'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + await fileio.truncate(fpath, undefined); + let fd = fileio.openSync(fpath, 0o2); + expect(isIntNum(fd)).assertTrue(); + let readLen = fileio.readSync(fd, new ArrayBuffer(4096)); + expect(readLen == 0).assertTrue(); + fileio.closeSync(fd); + fileio.unlinkSync(fpath); + done(); + } catch (e) { + console.log('fileio_truncate_async_003 has failed for ' + e); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_TRUNCATE_ASYNC_0400 + * @tc.name fileio_truncate_async_004 + * @tc.desc Test the truncate() interface. Callback. + * Use default truncateLen = 0. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 3 + * @tc.require + */ + it('fileio_truncate_async_004', 3, async function (done) { + let fpath = await nextFileName('fileio_truncate_async_004'); + expect(prepareFile(fpath, 'truncate')).assertTrue(); + + try { + fileio.truncate(fpath, undefined, (err) => { + if (err) { + console.log('fileio_truncate_async_004 error package: ' + JSON.stringify(err)); + expect(false).assertTrue(); + } + let fd = fileio.openSync(fpath, 0o2); + expect(isIntNum(fd)).assertTrue(); + let readLen = fileio.readSync(fd, new ArrayBuffer(4096)); + expect(readLen == 0).assertTrue(); + fileio.closeSync(fd); + fileio.unlinkSync(fpath); + done(); + }); + } catch(e) { + console.log('fileio_truncate_async_004 has failed for ' + e); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_TRUNCATE_SYNC_0000 + * @tc.name fileio_test_truncate_sync_000 + * @tc.desc Test truncateSync() interfaces. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_truncate_sync_000', 0, async function () { + let fpath = await nextFileName('fileio_test_truncate_sync_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + expect(fileio.truncateSync(fpath) == null).assertTrue(); + expect(fileio.statSync(fpath).size == 0).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_test_truncate_sync_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_TRUNCATE_SYNC_0100 + * @tc.name fileio_test_truncate_sync_001 + * @tc.desc Test truncateSync() interfaces. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_truncate_sync_001', 0, async function () { + let fpath = await nextFileName('fileio_test_truncate_sync_001'); + + try { + fileio.truncateSync(fpath); + expect(null).assertFail(); + } catch (e) { + console.log('fileio_test_truncate_sync_001 has failed for ' + e); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_TRUNCATE_SYNC_0200 + * @tc.name fileio_test_truncate_sync_002 + * @tc.desc Test truncateSync() interfaces. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_truncate_sync_002', 0, function () { + try { + fileio.truncateSync(); + expect(null).assertFail(); + } catch (e) { + console.log('fileio_test_truncate_sync_002 has failed for ' + e); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_TRUNCATE_SYNC_0300 + * @tc.name fileio_test_truncate_sync_003 + * @tc.desc Test the truncateSync() interface. + * Use default truncateLen = 0. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 3 + * @tc.require + */ + it('fileio_test_truncate_sync_003', 3, async function () { + let fpath = await nextFileName('fileio_test_truncate_sync_003'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + fileio.truncateSync(fpath, undefined); + let fd = fileio.openSync(fpath, 0o2); + expect(isIntNum(fd)).assertTrue(); + let readLen = fileio.readSync(fd, new ArrayBuffer(4096)); + expect(readLen == 0).assertTrue(); + fileio.closeSync(fd); + fileio.unlinkSync(fpath); + } catch (e) { + console.log('fileio_test_truncate_sync_003 has failed for ' + e); + expect(false).assertTrue(); + } + }); +}); +} diff --git a/storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/members/unlink.test.js b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/unlink.test.js similarity index 95% rename from storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/members/unlink.test.js rename to storage/storagefileiojstest/src/main/js/test/module_fileio/members/unlink.test.js index ee05106b277aead7bdfd971707cf1e7ac8a0f8e7..3a5f4da6f4e2777e80525652761cb75e9f74e8b5 100644 --- a/storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/members/unlink.test.js +++ b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/unlink.test.js @@ -1,175 +1,175 @@ -/* - * Copyright (C) 2023 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 { - fileio, FILE_CONTENT, prepareFile, nextFileName, - describe, it, expect, -} from '../../Common'; - -export default function fileioUnlink() { -describe('fileio_unlink', function () { - - /** - * @tc.number SUB_DF_FILEIO_UNLINK_SYNC_0000 - * @tc.name fileio_test_unlink_sync_000 - * @tc.desc Test unlinkSync() interfaces. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_unlink_sync_000', 0, function () { - try { - fileio.unlinkSync(); - expect(null).assertFail(); - } catch (e) { - console.log('fileio_test_unlink_sync_000 has failed for ' + e); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_UNLINK_SYNC_0010 - * @tc.name fileio_test_unlink_sync_001 - * @tc.desc Test unlinkSync() interfaces. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_unlink_sync_001', 0, async function () { - let fpath = await nextFileName('fileIOTest'); - - try { - fileio.unlinkSync(fpath); - expect(null).assertFail(); - } catch (e) { - console.log('fileio_test_unlink_sync_001 has failed for ' + e); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_UNLINK_SYNC_0020 - * @tc.name fileio_test_unlink_sync_002 - * @tc.desc Test unlinkSync() interfaces. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_unlink_sync_002', 0, async function () { - let fpath = await nextFileName('fileio_test_unlink_sync_002'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - expect(fileio.accessSync(fpath) == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - } catch (e) { - console.log('fileio_test_unlink_sync_002 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FileIO_UnlinkAync_0000 - * @tc.name fileio_test_unlink_async_000 - * @tc.desc Test unlinkAsync() interfaces. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_unlink_async_000', 0, async function (done) { - let fpath = await nextFileName('fileIOTest'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - expect(await fileio.unlink(fpath) == null).assertTrue(); - done(); - } catch (e) { - console.log('fileio_test_unlink_async_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FileIO_UnlinkAync_0010 - * @tc.name fileio_test_unlink_async_001 - * @tc.desc Test unlinkAsync() interfaces. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_unlink_async_001', 0, async function (done) { - let fpath = await nextFileName('fileIOTest'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - fileio.unlink(fpath, function (error) { - done(); - }); - } catch (e) { - console.log('fileio_test_unlink_async_001 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_UNLINK_SYNC_0020 - * @tc.name fileio_test_unlink_sync_002 - * @tc.desc Test unlink() interfaces. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_unlink_async_002', 0, async function (done) { - let fpath = await nextFileName('fileio_test_unlink_async_002'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - fileio.unlink(fpath, function (err) { - done(); - }); - } catch (e) { - console.log('fileio_test_unlink_async_002 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_UNLINK_SYNC_0030 - * @tc.name fileio_test_unlink_sync_003 - * @tc.desc Test unlink() interfaces. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_unlink_async_003', 0, async function (done) { - let fpath = await nextFileName('fileio_test_unlink_async_003'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - fileio.unlink(fpath).then(function (err) { - done(); - }); - } catch (e) { - console.log('fileio_test_unlink_async_003 has failed for ' + e); - expect(null).assertFail(); - } - }); -}); -} +/* + * Copyright (C) 2021 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 { + fileio, FILE_CONTENT, prepareFile, nextFileName, + describe, it, expect, +} from '../../Common'; + +export default function fileioUnlink() { +describe('fileio_unlink', function () { + + /** + * @tc.number SUB_DF_FILEIO_UNLINK_SYNC_0000 + * @tc.name fileio_test_unlink_sync_000 + * @tc.desc Test unlinkSync() interfaces. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_unlink_sync_000', 0, function () { + try { + fileio.unlinkSync(); + expect(null).assertFail(); + } catch (e) { + console.log('fileio_test_unlink_sync_000 has failed for ' + e); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_UNLINK_SYNC_0010 + * @tc.name fileio_test_unlink_sync_001 + * @tc.desc Test unlinkSync() interfaces. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_unlink_sync_001', 0, async function () { + let fpath = await nextFileName('fileIOTest'); + + try { + fileio.unlinkSync(fpath); + expect(null).assertFail(); + } catch (e) { + console.log('fileio_test_unlink_sync_001 has failed for ' + e); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_UNLINK_SYNC_0020 + * @tc.name fileio_test_unlink_sync_002 + * @tc.desc Test unlinkSync() interfaces. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_unlink_sync_002', 0, async function () { + let fpath = await nextFileName('fileio_test_unlink_sync_002'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + expect(fileio.accessSync(fpath) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_test_unlink_sync_002 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_UnlinkAync_0000 + * @tc.name fileio_test_unlink_async_000 + * @tc.desc Test unlinkAsync() interfaces. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_unlink_async_000', 0, async function (done) { + let fpath = await nextFileName('fileIOTest'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + expect(await fileio.unlink(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_test_unlink_async_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_UnlinkAync_0010 + * @tc.name fileio_test_unlink_async_001 + * @tc.desc Test unlinkAsync() interfaces. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_unlink_async_001', 0, async function (done) { + let fpath = await nextFileName('fileIOTest'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + fileio.unlink(fpath, function (error) { + done(); + }); + } catch (e) { + console.log('fileio_test_unlink_async_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_UNLINK_SYNC_0020 + * @tc.name fileio_test_unlink_sync_002 + * @tc.desc Test unlink() interfaces. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_unlink_async_002', 0, async function (done) { + let fpath = await nextFileName('fileio_test_unlink_async_002'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + fileio.unlink(fpath, function (err) { + done(); + }); + } catch (e) { + console.log('fileio_test_unlink_async_002 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_UNLINK_SYNC_0030 + * @tc.name fileio_test_unlink_sync_003 + * @tc.desc Test unlink() interfaces. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_unlink_async_003', 0, async function (done) { + let fpath = await nextFileName('fileio_test_unlink_async_003'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + fileio.unlink(fpath).then(function (err) { + done(); + }); + } catch (e) { + console.log('fileio_test_unlink_async_003 has failed for ' + e); + expect(null).assertFail(); + } + }); +}); +} diff --git a/storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/members/write.test.js b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/write.test.js similarity index 96% rename from storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/members/write.test.js rename to storage/storagefileiojstest/src/main/js/test/module_fileio/members/write.test.js index c798dd19789da937ce4957306fa5d6a6da8a99fa..a1e6c8b1db723dad7a338b3ff410318b4d76c100 100644 --- a/storage/storagefileiojstest/entry/src/ohosTest/js/test/module_fileio/members/write.test.js +++ b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/write.test.js @@ -1,814 +1,814 @@ -/* - * Copyright (C) 2023 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 { - fileio, FILE_CONTENT, nextFileName, isIntNum, prepareFile, - describe, it, expect, -} from '../../Common'; - -export default function fileioWrite() { -describe('fileio_write', function () { - - /** - * @tc.number SUB_DF_FILEIO_WRITE_SYNC_0000 - * @tc.name fileio_test_write_sync_000 - * @tc.desc Test writeSync() interfaces. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_write_sync_000', 0, async function () { - let fpath = await nextFileName('fileio_test_write_sync_000'); - - try { - let fd = fileio.openSync(fpath, 0o102, 0o666); - expect(isIntNum(fd)).assertTrue(); - expect(fileio.writeSync(fd, FILE_CONTENT) == FILE_CONTENT.length).assertTrue(); - expect(fileio.closeSync(fd) == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - } catch (e) { - console.log('fileio_test_write_sync_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_WRITE_SYNC_0100 - * @tc.name fileio_test_write_sync_001 - * @tc.desc Test writeSync() interfaces. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_write_sync_001', 0, async function () { - let fpath = await nextFileName('fileio_test_write_sync_001'); - - try { - let fd = fileio.openSync(fpath, 0o102, 0o666); - expect(isIntNum(fd)).assertTrue(); - expect( - fileio.writeSync(fd, FILE_CONTENT, { - encoding: 'utf-8', - }) - == FILE_CONTENT.length).assertTrue(); - expect(fileio.closeSync(fd) == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - } catch (e) { - console.log('fileio_test_write_sync_001 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_WRITE_SYNC_0200 - * @tc.name fileio_test_write_sync_002 - * @tc.desc Test writeSync() interfaces. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_write_sync_002', 0, async function () { - let fpath = await nextFileName('fileio_test_write_sync_002'); - - try { - let fd = fileio.openSync(fpath, 0o102, 0o666); - expect(isIntNum(fd)).assertTrue(); - expect( - fileio.writeSync(fd, FILE_CONTENT, { - offset: 1, - }) - == FILE_CONTENT.length - 1).assertTrue(); - expect(fileio.closeSync(fd) == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - } catch (e) { - console.log('fileio_test_write_sync_002 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_WRITE_SYNC_0300 - * @tc.name fileio_test_write_sync_003 - * @tc.desc Test writeSync() interfaces. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_write_sync_003', 0, async function () { - let fpath = await nextFileName('fileio_test_write_sync_003'); - - try { - let fd = fileio.openSync(fpath, 0o102, 0o666); - expect(isIntNum(fd)).assertTrue(); - expect( - fileio.writeSync(fd, FILE_CONTENT, { - length: FILE_CONTENT.length - 1, - }) - == FILE_CONTENT.length - 1).assertTrue(); - expect(fileio.closeSync(fd) == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - } catch (e) { - console.log('fileio_test_write_sync_003 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_WRITE_SYNC_0400 - * @tc.name fileio_test_write_sync_004 - * @tc.desc Test writeSync() interfaces. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_write_sync_004', 0, async function () { - let fpath = await nextFileName('fileio_test_write_sync_004'); - - try { - let fd = fileio.openSync(fpath, 0o102, 0o666); - expect(isIntNum(fd)).assertTrue(); - expect( - fileio.writeSync(fd, FILE_CONTENT, { - offset: 1, - length: 1, - }) - == 1).assertTrue(); - expect(fileio.closeSync(fd) == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - } catch (e) { - console.log('fileio_test_write_sync_004 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_WRITE_SYNC_0500 - * @tc.name fileio_test_write_sync_005 - * @tc.desc Test writeSync() interfaces. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_write_sync_005', 0, async function () { - let fpath = await nextFileName('fileio_test_write_sync_005'); - const invalidOffset = 999; - let fd; - - try { - fd = fileio.openSync(fpath, 0o102, 0o666); - expect(isIntNum(fd)).assertTrue(); - expect( - fileio.writeSync(fd, FILE_CONTENT, { - offset: invalidOffset, - }) - == 1).assertTrue(); - expect(null).assertFail(); - } catch (e) { - expect(fileio.closeSync(fd) == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_WRITE_SYNC_0600 - * @tc.name fileio_test_write_sync_006 - * @tc.desc Test writeSync() interfaces. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_write_sync_006', 0, async function () { - let fpath = await nextFileName('fileio_test_write_sync_006'); - const invalidLength = 999; - let fd; - - try { - fd = fileio.openSync(fpath, 0o102, 0o666); - expect(isIntNum(fd)).assertTrue(); - expect( - fileio.writeSync(fd, FILE_CONTENT, { - length: invalidLength, - }) - == 1).assertTrue(); - expect(null).assertFail(); - } catch (e) { - expect(fileio.closeSync(fd) == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_WRITE_SYNC_0700 - * @tc.name fileio_test_write_sync_007 - * @tc.desc Test writeSync() interfaces. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_write_sync_007', 0, function () { - try { - fileio.writeSync(); - expect(null).assertFail(); - } catch (e) { - console.log('fileio_test_write_sync_007 has failed for ' + e); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_WRITE_SYNC_0800 - * @tc.name fileio_test_write_sync_008 - * @tc.desc Test writeSync() interfaces. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_write_sync_008', 0, function () { - try { - fileio.writeSync(-1, FILE_CONTENT); - expect(false).assertTrue(); - } catch (e) { - console.log('fileio_test_write_sync_008 has failed for ' + e); - expect(e.message == 'Invalid fd').assertTrue(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_WRITE_SYNC_0900 - * @tc.name fileio_test_write_sync_009 - * @tc.desc Test writeSync() interfaces. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_write_sync_009', 0, async function () { - let fpath = await nextFileName('fileio_test_write_sync_009'); - - try { - let fd = fileio.openSync(fpath, 0o102, 0o666); - expect(isIntNum(fd)).assertTrue(); - let writeNum = fileio.writeSync(fd, new ArrayBuffer(4096)); - expect(writeNum == 4096).assertTrue(); - expect(fileio.closeSync(fd) == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - } catch (e) { - console.log('fileio_test_write_sync_009 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_WRITE_SYNC_1000 - * @tc.name fileio_test_write_sync_010 - * @tc.desc Test writeSync() interfaces. - * Undefined option arguments, use default options. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 3 - * @tc.require - */ - it('fileio_test_write_sync_010', 3, async function () { - let fpath = await nextFileName('fileio_test_write_sync_010'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let fd = fileio.openSync(fpath, 0o102, 0o666); - expect(isIntNum(fd)).assertTrue(); - let bytesWritten = fileio.writeSync(fd, FILE_CONTENT, undefined); - expect(bytesWritten == FILE_CONTENT.length).assertTrue(); - fileio.closeSync(fd); - fileio.unlinkSync(fpath); - } catch (e) { - console.log('fileio_test_write_sync_010 has failed for ' + e); - expect(false).assertTrue(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_WRITE_SYNC_1100 - * @tc.name fileio_test_write_sync_011 - * @tc.desc Test writeSync() interfaces. - * Undefined option arguments, use default options. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 3 - * @tc.require - */ - it('fileio_test_write_sync_011', 3, async function () { - let fpath = await nextFileName('fileio_test_write_sync_011'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - try { - let fd = fileio.openSync(fpath, 0o102, 0o666); - expect(isIntNum(fd)).assertTrue(); - let bytesWritten = fileio.writeSync(fd, FILE_CONTENT, { - position: undefined, - offset: undefined, - length: undefined, - encoding: undefined, - }); - expect(bytesWritten == FILE_CONTENT.length).assertTrue(); - fileio.closeSync(fd); - fileio.unlinkSync(fpath); - } catch (e) { - console.log('fileio_test_write_sync_011 has failed for ' + e); - expect(false).assertTrue(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_WRITE_ASYNC_0000 - * @tc.name fileio_test_write_async_000 - * @tc.desc Test write() interfaces. Promise. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_write_async_000', 0, async function (done) { - let fpath = await nextFileName('fileio_write_async_000'); - - try { - let fd = fileio.openSync(fpath, 0o102, 0o666); - expect(isIntNum(fd)).assertTrue(); - expect(await fileio.write(fd, FILE_CONTENT) == FILE_CONTENT.length).assertTrue(); - expect(fileio.closeSync(fd) == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - done(); - } catch (e) { - console.log('fileio_write_async_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_WRITE_ASYNC_0100 - * @tc.name fileio_test_write_async_001 - * @tc.desc Test write() interfaces. Promise. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_write_async_001', 0, async function (done) { - let fpath = await nextFileName('fileio_test_write_async_001'); - - try { - let fd = fileio.openSync(fpath, 0o102, 0o666); - expect(isIntNum(fd)).assertTrue(); - let writeNum = await fileio.write(fd, FILE_CONTENT, { - offset: 1, - }); - expect(writeNum == FILE_CONTENT.length - 1).assertTrue(); - expect(fileio.closeSync(fd) == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - done(); - } catch (e) { - console.log('fileio_test_write_async_001 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_WRITE_ASYNC_0200 - * @tc.name fileio_test_write_async_002 - * @tc.desc Test write() interfaces. Promise. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_write_async_002', 0, async function (done) { - let fpath = await nextFileName('fileio_test_write_async_002'); - - try { - let fd = fileio.openSync(fpath, 0o102, 0o666); - expect(isIntNum(fd)).assertTrue(); - let writeNum = await fileio.write(fd, FILE_CONTENT, { - offset: 1, - length: 3, - }); - expect(writeNum == 3).assertTrue(); - expect(fileio.closeSync(fd) == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - done(); - } catch (e) { - console.log('fileio_test_write_async_002 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_WRITE_ASYNC_0300 - * @tc.name fileio_test_write_async_003 - * @tc.desc Test write() interfaces. Promise. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_write_async_003', 0, async function (done) { - let fpath = await nextFileName('fileio_test_write_async_003'); - - try { - let fd = fileio.openSync(fpath, 0o102, 0o666); - expect(isIntNum(fd)).assertTrue(); - let writeNum = await fileio.write(fd, FILE_CONTENT, { - offset: 1, - length: 3, - position: 5, - }); - expect(writeNum == 3).assertTrue(); - expect(fileio.closeSync(fd) == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - done(); - } catch (e) { - console.log('fileio_test_write_async_003 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_WRITE_ASYNC_0400 - * @tc.name fileio_test_write_async_004 - * @tc.desc Test write() interfaces. Promise. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_write_async_004', 0, async function (done) { - let fpath = await nextFileName('fileio_test_write_async_004'); - - try { - let fd = fileio.openSync(fpath, 0o102, 0o666); - expect(isIntNum(fd)).assertTrue(); - let writeNum = await fileio.write(fd, FILE_CONTENT, { - offset: 0, - length: 4, - position: 5, - encoding: 'utf-8', - }); - expect(writeNum == 4).assertTrue(); - expect(fileio.closeSync(fd) == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - done(); - } catch (e) { - console.log('fileio_test_write_async_004 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_WRITE_ASYNC_0500 - * @tc.name fileio_test_write_async_005 - * @tc.desc Test write() interfaces. Callback. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_write_async_005', 0, async function (done) { - let fpath = await nextFileName('fileio_test_write_async_005'); - - try { - let fd = fileio.openSync(fpath, 0o102, 0o666); - expect(isIntNum(fd)).assertTrue(); - fileio.write(fd, new ArrayBuffer(4096), function ( - error, - bytesWritten - ) { - expect(bytesWritten == 4096).assertTrue(); - expect(fileio.closeSync(fd) == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - }); - done(); - } catch (e) { - console.log('fileio_test_write_async_005 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_WRITE_ASYNC_0600 - * @tc.name fileio_test_write_async_006 - * @tc.desc Test write() interfaces. Callback. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_write_async_006', 0, async function (done) { - let fpath = await nextFileName('fileio_test_write_async_006'); - - try { - let fd = fileio.openSync(fpath, 0o102, 0o666); - expect(isIntNum(fd)).assertTrue(); - fileio.write( - fd, - FILE_CONTENT, - { - offset: 1, - }, function (error, bytesWritten) { - expect(bytesWritten == FILE_CONTENT.length - 1).assertTrue(); - expect(fileio.closeSync(fd) == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - done(); - } - ); - } catch (e) { - console.log('fileio_test_write_async_006 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_WRITE_ASYNC_0700 - * @tc.name fileio_test_write_async_007 - * @tc.desc Test write() interfaces. Callback. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_write_async_007', 0, async function (done) { - let fpath = await nextFileName('fileio_test_write_async_007'); - - try { - let fd = fileio.openSync(fpath, 0o102, 0o666); - expect(isIntNum(fd)).assertTrue(); - fileio.write( - fd, - FILE_CONTENT, - { - offset: 1, - length: 5, - }, function (error, bytesWritten) { - expect(bytesWritten == 5).assertTrue(); - expect(fileio.closeSync(fd) == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - done(); - } - ); - } catch (e) { - console.log('fileio_test_write_async_007 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_WRITE_ASYNC_0800 - * @tc.name fileio_test_write_async_008 - * @tc.desc Test write() interfaces. Callback. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_write_async_008', 0, async function (done) { - let fpath = await nextFileName('fileio_test_write_async_008'); - - try { - let fd = fileio.openSync(fpath, 0o102, 0o666); - expect(isIntNum(fd)).assertTrue(); - fileio.write( - fd, - FILE_CONTENT, - { - offset: 1, - length: 5, - position: 5, - }, function (error, bytesWritten) { - expect(bytesWritten == 5).assertTrue(); - expect(fileio.closeSync(fd) == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - done(); - } - ); - } catch (e) { - console.log('fileio_test_write_async_008 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_WRITE_ASYNC_0900 - * @tc.name fileio_test_write_async_009 - * @tc.desc Test write() interfaces. Callback. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_write_async_009', 0, async function (done) { - let fpath = await nextFileName('fileio_test_write_async_009'); - - try { - let fd = fileio.openSync(fpath, 0o102, 0o666); - expect(isIntNum(fd)).assertTrue(); - fileio.write( - fd, - FILE_CONTENT, - { - offset: 1, - length: 5, - position: 5, - encoding: 'utf-8', - }, function (error, bytesWritten) { - expect(bytesWritten == 5).assertTrue(); - expect(fileio.closeSync(fd) == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - done(); - } - ); - } catch (e) { - console.log('fileio_test_write_async_009 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_WRITE_ASYNC_1000 - * @tc.name fileio_test_write_async_010 - * @tc.desc Test write() interfaces. Promise. - * Undefined option arguments, use default options. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 3 - * @tc.require - */ - it('fileio_test_write_async_010', 3, async function (done) { - let fpath = await nextFileName('fileio_test_write_async_010'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let fd = fileio.openSync(fpath, 0o102, 0o666); - expect(isIntNum(fd)).assertTrue(); - let bytesWritten1 = await fileio.write(fd, FILE_CONTENT, undefined); - expect(bytesWritten1 == FILE_CONTENT.length).assertTrue(); - let bytesWritten2 = await fileio.write(fd, new ArrayBuffer(FILE_CONTENT.length), undefined); - expect(bytesWritten2 == FILE_CONTENT.length).assertTrue(); - let readLen = fileio.readSync(fd, new ArrayBuffer(4096), { position: 0 }); - expect(readLen == FILE_CONTENT.length * 2).assertTrue(); - fileio.closeSync(fd); - fileio.unlinkSync(fpath); - done(); - } catch (e) { - console.log('fileio_test_write_async_010 has failed for ' + e); - expect(false).assertTrue(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_WRITE_ASYNC_1100 - * @tc.name fileio_test_write_async_011 - * @tc.desc Test write() interfaces. Callback. - * Undefined option arguments, use default options. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 3 - * @tc.require - */ - it('fileio_test_write_async_011', 3, async function (done) { - let fpath = await nextFileName('fileio_test_write_async_011'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let fd = fileio.openSync(fpath, 0o102, 0o666); - expect(isIntNum(fd)).assertTrue(); - fileio.write(fd, FILE_CONTENT, undefined, (err, bytesWritten1) => { - if (err) { - console.log('fileio_test_write_async_011 err package1: ' + JSON.stringify(err)); - expect(false).assertTrue(); - } - expect(bytesWritten1 == FILE_CONTENT.length).assertTrue(); - fileio.write(fd, new ArrayBuffer(FILE_CONTENT.length), undefined, (err, bytesWritten2) => { - if (err) { - console.log('fileio_test_write_async_011 err package2: ' + JSON.stringify(err)); - expect(false).assertTrue(); - } - expect(bytesWritten2 == FILE_CONTENT.length).assertTrue(); - let readLen = fileio.readSync(fd, new ArrayBuffer(4096), { position: 0 }); - expect(readLen == FILE_CONTENT.length * 2).assertTrue(); - fileio.closeSync(fd); - fileio.unlinkSync(fpath); - done(); - }); - }); - } catch (e) { - console.log('fileio_test_write_async_011 has failed for ' + e); - expect(false).assertTrue(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_WRITE_ASYNC_1200 - * @tc.name fileio_test_write_async_012 - * @tc.desc Test write() interfaces. Promise. - * Undefined option arguments, use default options. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 3 - * @tc.require - */ - it('fileio_test_write_async_012', 3, async function (done) { - let fpath = await nextFileName('fileio_test_write_async_012'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let fd = fileio.openSync(fpath, 0o102, 0o666); - expect(isIntNum(fd)).assertTrue(); - let bytesWritten1 = await fileio.write(fd, FILE_CONTENT, { - length: undefined, - offset: undefined, - encoding: undefined, - }); - expect(bytesWritten1 == FILE_CONTENT.length).assertTrue(); - let bytesWritten2 = await fileio.write(fd, new ArrayBuffer(FILE_CONTENT.length), { - length: undefined, - offset: undefined, - encoding: undefined, - }); - expect(bytesWritten2 == FILE_CONTENT.length).assertTrue(); - let readLen = fileio.readSync(fd, new ArrayBuffer(4096), { position: 0 }); - expect(readLen == FILE_CONTENT.length * 2).assertTrue(); - fileio.closeSync(fd); - fileio.unlinkSync(fpath); - done(); - } catch (e) { - console.log('fileio_test_write_async_012 has failed for ' + e); - expect(false).assertTrue(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_WRITE_ASYNC_1300 - * @tc.name fileio_test_write_async_013 - * @tc.desc Test write() interfaces. Callback. - * Undefined option arguments, use default options. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 3 - * @tc.require - */ - it('fileio_test_write_async_013', 3, async function (done) { - let fpath = await nextFileName('fileio_test_write_async_013'); - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); - - try { - let fd = fileio.openSync(fpath, 0o102, 0o666); - expect(isIntNum(fd)).assertTrue(); - fileio.write(fd, FILE_CONTENT, { - length: undefined, - offset: undefined, - encoding: undefined, - }, (err, bytesWritten1) => { - if (err) { - console.log('fileio_test_write_async_013 err package1: ' + JSON.stringify(err)); - expect(false).assertTrue(); - } - expect(bytesWritten1 == FILE_CONTENT.length).assertTrue(); - fileio.write(fd, new ArrayBuffer(FILE_CONTENT.length), { - length: undefined, - offset: undefined, - encoding: undefined, - }, (err, bytesWritten2) => { - if (err) { - console.log('fileio_test_write_async_013 err package2: ' + JSON.stringify(err)); - expect(false).assertTrue(); - } - expect(bytesWritten2 == FILE_CONTENT.length).assertTrue(); - let readLen = fileio.readSync(fd, new ArrayBuffer(4096), { position: 0 }); - expect(readLen == FILE_CONTENT.length * 2).assertTrue(); - fileio.closeSync(fd); - fileio.unlinkSync(fpath); - done(); - }); - }); - } catch (e) { - console.log('fileio_test_write_async_013 has failed for ' + e); - expect(false).assertTrue(); - } - }); -}); -} +/* + * Copyright (C) 2021 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 { + fileio, FILE_CONTENT, nextFileName, isIntNum, prepareFile, + describe, it, expect, +} from '../../Common'; + +export default function fileioWrite() { +describe('fileio_write', function () { + + /** + * @tc.number SUB_DF_FILEIO_WRITE_SYNC_0000 + * @tc.name fileio_test_write_sync_000 + * @tc.desc Test writeSync() interfaces. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_write_sync_000', 0, async function () { + let fpath = await nextFileName('fileio_test_write_sync_000'); + + try { + let fd = fileio.openSync(fpath, 0o102, 0o666); + expect(isIntNum(fd)).assertTrue(); + expect(fileio.writeSync(fd, FILE_CONTENT) == FILE_CONTENT.length).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_test_write_sync_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_WRITE_SYNC_0100 + * @tc.name fileio_test_write_sync_001 + * @tc.desc Test writeSync() interfaces. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_write_sync_001', 0, async function () { + let fpath = await nextFileName('fileio_test_write_sync_001'); + + try { + let fd = fileio.openSync(fpath, 0o102, 0o666); + expect(isIntNum(fd)).assertTrue(); + expect( + fileio.writeSync(fd, FILE_CONTENT, { + encoding: 'utf-8', + }) + == FILE_CONTENT.length).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_test_write_sync_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_WRITE_SYNC_0200 + * @tc.name fileio_test_write_sync_002 + * @tc.desc Test writeSync() interfaces. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_write_sync_002', 0, async function () { + let fpath = await nextFileName('fileio_test_write_sync_002'); + + try { + let fd = fileio.openSync(fpath, 0o102, 0o666); + expect(isIntNum(fd)).assertTrue(); + expect( + fileio.writeSync(fd, FILE_CONTENT, { + offset: 1, + }) + == FILE_CONTENT.length - 1).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_test_write_sync_002 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_WRITE_SYNC_0300 + * @tc.name fileio_test_write_sync_003 + * @tc.desc Test writeSync() interfaces. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_write_sync_003', 0, async function () { + let fpath = await nextFileName('fileio_test_write_sync_003'); + + try { + let fd = fileio.openSync(fpath, 0o102, 0o666); + expect(isIntNum(fd)).assertTrue(); + expect( + fileio.writeSync(fd, FILE_CONTENT, { + length: FILE_CONTENT.length - 1, + }) + == FILE_CONTENT.length - 1).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_test_write_sync_003 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_WRITE_SYNC_0400 + * @tc.name fileio_test_write_sync_004 + * @tc.desc Test writeSync() interfaces. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_write_sync_004', 0, async function () { + let fpath = await nextFileName('fileio_test_write_sync_004'); + + try { + let fd = fileio.openSync(fpath, 0o102, 0o666); + expect(isIntNum(fd)).assertTrue(); + expect( + fileio.writeSync(fd, FILE_CONTENT, { + offset: 1, + length: 1, + }) + == 1).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_test_write_sync_004 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_WRITE_SYNC_0500 + * @tc.name fileio_test_write_sync_005 + * @tc.desc Test writeSync() interfaces. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_write_sync_005', 0, async function () { + let fpath = await nextFileName('fileio_test_write_sync_005'); + const invalidOffset = 999; + let fd; + + try { + fd = fileio.openSync(fpath, 0o102, 0o666); + expect(isIntNum(fd)).assertTrue(); + expect( + fileio.writeSync(fd, FILE_CONTENT, { + offset: invalidOffset, + }) + == 1).assertTrue(); + expect(null).assertFail(); + } catch (e) { + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_WRITE_SYNC_0600 + * @tc.name fileio_test_write_sync_006 + * @tc.desc Test writeSync() interfaces. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_write_sync_006', 0, async function () { + let fpath = await nextFileName('fileio_test_write_sync_006'); + const invalidLength = 999; + let fd; + + try { + fd = fileio.openSync(fpath, 0o102, 0o666); + expect(isIntNum(fd)).assertTrue(); + expect( + fileio.writeSync(fd, FILE_CONTENT, { + length: invalidLength, + }) + == 1).assertTrue(); + expect(null).assertFail(); + } catch (e) { + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_WRITE_SYNC_0700 + * @tc.name fileio_test_write_sync_007 + * @tc.desc Test writeSync() interfaces. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_write_sync_007', 0, function () { + try { + fileio.writeSync(); + expect(null).assertFail(); + } catch (e) { + console.log('fileio_test_write_sync_007 has failed for ' + e); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_WRITE_SYNC_0800 + * @tc.name fileio_test_write_sync_008 + * @tc.desc Test writeSync() interfaces. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_write_sync_008', 0, function () { + try { + fileio.writeSync(-1, FILE_CONTENT); + expect(false).assertTrue(); + } catch (e) { + console.log('fileio_test_write_sync_008 has failed for ' + e); + expect(e.message == 'Invalid fd').assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_WRITE_SYNC_0900 + * @tc.name fileio_test_write_sync_009 + * @tc.desc Test writeSync() interfaces. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_write_sync_009', 0, async function () { + let fpath = await nextFileName('fileio_test_write_sync_009'); + + try { + let fd = fileio.openSync(fpath, 0o102, 0o666); + expect(isIntNum(fd)).assertTrue(); + let writeNum = fileio.writeSync(fd, new ArrayBuffer(4096)); + expect(writeNum == 4096).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_test_write_sync_009 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_WRITE_SYNC_1000 + * @tc.name fileio_test_write_sync_010 + * @tc.desc Test writeSync() interfaces. + * Undefined option arguments, use default options. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 3 + * @tc.require + */ + it('fileio_test_write_sync_010', 3, async function () { + let fpath = await nextFileName('fileio_test_write_sync_010'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath, 0o102, 0o666); + expect(isIntNum(fd)).assertTrue(); + let bytesWritten = fileio.writeSync(fd, FILE_CONTENT, undefined); + expect(bytesWritten == FILE_CONTENT.length).assertTrue(); + fileio.closeSync(fd); + fileio.unlinkSync(fpath); + } catch (e) { + console.log('fileio_test_write_sync_010 has failed for ' + e); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_WRITE_SYNC_1100 + * @tc.name fileio_test_write_sync_011 + * @tc.desc Test writeSync() interfaces. + * Undefined option arguments, use default options. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 3 + * @tc.require + */ + it('fileio_test_write_sync_011', 3, async function () { + let fpath = await nextFileName('fileio_test_write_sync_011'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let fd = fileio.openSync(fpath, 0o102, 0o666); + expect(isIntNum(fd)).assertTrue(); + let bytesWritten = fileio.writeSync(fd, FILE_CONTENT, { + position: undefined, + offset: undefined, + length: undefined, + encoding: undefined, + }); + expect(bytesWritten == FILE_CONTENT.length).assertTrue(); + fileio.closeSync(fd); + fileio.unlinkSync(fpath); + } catch (e) { + console.log('fileio_test_write_sync_011 has failed for ' + e); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_WRITE_ASYNC_0000 + * @tc.name fileio_test_write_async_000 + * @tc.desc Test write() interfaces. Promise. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_write_async_000', 0, async function (done) { + let fpath = await nextFileName('fileio_write_async_000'); + + try { + let fd = fileio.openSync(fpath, 0o102, 0o666); + expect(isIntNum(fd)).assertTrue(); + expect(await fileio.write(fd, FILE_CONTENT) == FILE_CONTENT.length).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_write_async_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_WRITE_ASYNC_0100 + * @tc.name fileio_test_write_async_001 + * @tc.desc Test write() interfaces. Promise. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_write_async_001', 0, async function (done) { + let fpath = await nextFileName('fileio_test_write_async_001'); + + try { + let fd = fileio.openSync(fpath, 0o102, 0o666); + expect(isIntNum(fd)).assertTrue(); + let writeNum = await fileio.write(fd, FILE_CONTENT, { + offset: 1, + }); + expect(writeNum == FILE_CONTENT.length - 1).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_test_write_async_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_WRITE_ASYNC_0200 + * @tc.name fileio_test_write_async_002 + * @tc.desc Test write() interfaces. Promise. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_write_async_002', 0, async function (done) { + let fpath = await nextFileName('fileio_test_write_async_002'); + + try { + let fd = fileio.openSync(fpath, 0o102, 0o666); + expect(isIntNum(fd)).assertTrue(); + let writeNum = await fileio.write(fd, FILE_CONTENT, { + offset: 1, + length: 3, + }); + expect(writeNum == 3).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_test_write_async_002 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_WRITE_ASYNC_0300 + * @tc.name fileio_test_write_async_003 + * @tc.desc Test write() interfaces. Promise. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_write_async_003', 0, async function (done) { + let fpath = await nextFileName('fileio_test_write_async_003'); + + try { + let fd = fileio.openSync(fpath, 0o102, 0o666); + expect(isIntNum(fd)).assertTrue(); + let writeNum = await fileio.write(fd, FILE_CONTENT, { + offset: 1, + length: 3, + position: 5, + }); + expect(writeNum == 3).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_test_write_async_003 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_WRITE_ASYNC_0400 + * @tc.name fileio_test_write_async_004 + * @tc.desc Test write() interfaces. Promise. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_write_async_004', 0, async function (done) { + let fpath = await nextFileName('fileio_test_write_async_004'); + + try { + let fd = fileio.openSync(fpath, 0o102, 0o666); + expect(isIntNum(fd)).assertTrue(); + let writeNum = await fileio.write(fd, FILE_CONTENT, { + offset: 0, + length: 4, + position: 5, + encoding: 'utf-8', + }); + expect(writeNum == 4).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_test_write_async_004 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_WRITE_ASYNC_0500 + * @tc.name fileio_test_write_async_005 + * @tc.desc Test write() interfaces. Callback. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_write_async_005', 0, async function (done) { + let fpath = await nextFileName('fileio_test_write_async_005'); + + try { + let fd = fileio.openSync(fpath, 0o102, 0o666); + expect(isIntNum(fd)).assertTrue(); + fileio.write(fd, new ArrayBuffer(4096), function ( + error, + bytesWritten + ) { + expect(bytesWritten == 4096).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + }); + done(); + } catch (e) { + console.log('fileio_test_write_async_005 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_WRITE_ASYNC_0600 + * @tc.name fileio_test_write_async_006 + * @tc.desc Test write() interfaces. Callback. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_write_async_006', 0, async function (done) { + let fpath = await nextFileName('fileio_test_write_async_006'); + + try { + let fd = fileio.openSync(fpath, 0o102, 0o666); + expect(isIntNum(fd)).assertTrue(); + fileio.write( + fd, + FILE_CONTENT, + { + offset: 1, + }, function (error, bytesWritten) { + expect(bytesWritten == FILE_CONTENT.length - 1).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } + ); + } catch (e) { + console.log('fileio_test_write_async_006 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_WRITE_ASYNC_0700 + * @tc.name fileio_test_write_async_007 + * @tc.desc Test write() interfaces. Callback. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_write_async_007', 0, async function (done) { + let fpath = await nextFileName('fileio_test_write_async_007'); + + try { + let fd = fileio.openSync(fpath, 0o102, 0o666); + expect(isIntNum(fd)).assertTrue(); + fileio.write( + fd, + FILE_CONTENT, + { + offset: 1, + length: 5, + }, function (error, bytesWritten) { + expect(bytesWritten == 5).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } + ); + } catch (e) { + console.log('fileio_test_write_async_007 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_WRITE_ASYNC_0800 + * @tc.name fileio_test_write_async_008 + * @tc.desc Test write() interfaces. Callback. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_write_async_008', 0, async function (done) { + let fpath = await nextFileName('fileio_test_write_async_008'); + + try { + let fd = fileio.openSync(fpath, 0o102, 0o666); + expect(isIntNum(fd)).assertTrue(); + fileio.write( + fd, + FILE_CONTENT, + { + offset: 1, + length: 5, + position: 5, + }, function (error, bytesWritten) { + expect(bytesWritten == 5).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } + ); + } catch (e) { + console.log('fileio_test_write_async_008 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_WRITE_ASYNC_0900 + * @tc.name fileio_test_write_async_009 + * @tc.desc Test write() interfaces. Callback. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_write_async_009', 0, async function (done) { + let fpath = await nextFileName('fileio_test_write_async_009'); + + try { + let fd = fileio.openSync(fpath, 0o102, 0o666); + expect(isIntNum(fd)).assertTrue(); + fileio.write( + fd, + FILE_CONTENT, + { + offset: 1, + length: 5, + position: 5, + encoding: 'utf-8', + }, function (error, bytesWritten) { + expect(bytesWritten == 5).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } + ); + } catch (e) { + console.log('fileio_test_write_async_009 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_WRITE_ASYNC_1000 + * @tc.name fileio_test_write_async_010 + * @tc.desc Test write() interfaces. Promise. + * Undefined option arguments, use default options. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 3 + * @tc.require + */ + it('fileio_test_write_async_010', 3, async function (done) { + let fpath = await nextFileName('fileio_test_write_async_010'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath, 0o102, 0o666); + expect(isIntNum(fd)).assertTrue(); + let bytesWritten1 = await fileio.write(fd, FILE_CONTENT, undefined); + expect(bytesWritten1 == FILE_CONTENT.length).assertTrue(); + let bytesWritten2 = await fileio.write(fd, new ArrayBuffer(FILE_CONTENT.length), undefined); + expect(bytesWritten2 == FILE_CONTENT.length).assertTrue(); + let readLen = fileio.readSync(fd, new ArrayBuffer(4096), { position: 0 }); + expect(readLen == FILE_CONTENT.length * 2).assertTrue(); + fileio.closeSync(fd); + fileio.unlinkSync(fpath); + done(); + } catch (e) { + console.log('fileio_test_write_async_010 has failed for ' + e); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_WRITE_ASYNC_1100 + * @tc.name fileio_test_write_async_011 + * @tc.desc Test write() interfaces. Callback. + * Undefined option arguments, use default options. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 3 + * @tc.require + */ + it('fileio_test_write_async_011', 3, async function (done) { + let fpath = await nextFileName('fileio_test_write_async_011'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath, 0o102, 0o666); + expect(isIntNum(fd)).assertTrue(); + fileio.write(fd, FILE_CONTENT, undefined, (err, bytesWritten1) => { + if (err) { + console.log('fileio_test_write_async_011 err package1: ' + JSON.stringify(err)); + expect(false).assertTrue(); + } + expect(bytesWritten1 == FILE_CONTENT.length).assertTrue(); + fileio.write(fd, new ArrayBuffer(FILE_CONTENT.length), undefined, (err, bytesWritten2) => { + if (err) { + console.log('fileio_test_write_async_011 err package2: ' + JSON.stringify(err)); + expect(false).assertTrue(); + } + expect(bytesWritten2 == FILE_CONTENT.length).assertTrue(); + let readLen = fileio.readSync(fd, new ArrayBuffer(4096), { position: 0 }); + expect(readLen == FILE_CONTENT.length * 2).assertTrue(); + fileio.closeSync(fd); + fileio.unlinkSync(fpath); + done(); + }); + }); + } catch (e) { + console.log('fileio_test_write_async_011 has failed for ' + e); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_WRITE_ASYNC_1200 + * @tc.name fileio_test_write_async_012 + * @tc.desc Test write() interfaces. Promise. + * Undefined option arguments, use default options. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 3 + * @tc.require + */ + it('fileio_test_write_async_012', 3, async function (done) { + let fpath = await nextFileName('fileio_test_write_async_012'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath, 0o102, 0o666); + expect(isIntNum(fd)).assertTrue(); + let bytesWritten1 = await fileio.write(fd, FILE_CONTENT, { + length: undefined, + offset: undefined, + encoding: undefined, + }); + expect(bytesWritten1 == FILE_CONTENT.length).assertTrue(); + let bytesWritten2 = await fileio.write(fd, new ArrayBuffer(FILE_CONTENT.length), { + length: undefined, + offset: undefined, + encoding: undefined, + }); + expect(bytesWritten2 == FILE_CONTENT.length).assertTrue(); + let readLen = fileio.readSync(fd, new ArrayBuffer(4096), { position: 0 }); + expect(readLen == FILE_CONTENT.length * 2).assertTrue(); + fileio.closeSync(fd); + fileio.unlinkSync(fpath); + done(); + } catch (e) { + console.log('fileio_test_write_async_012 has failed for ' + e); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_WRITE_ASYNC_1300 + * @tc.name fileio_test_write_async_013 + * @tc.desc Test write() interfaces. Callback. + * Undefined option arguments, use default options. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 3 + * @tc.require + */ + it('fileio_test_write_async_013', 3, async function (done) { + let fpath = await nextFileName('fileio_test_write_async_013'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath, 0o102, 0o666); + expect(isIntNum(fd)).assertTrue(); + fileio.write(fd, FILE_CONTENT, { + length: undefined, + offset: undefined, + encoding: undefined, + }, (err, bytesWritten1) => { + if (err) { + console.log('fileio_test_write_async_013 err package1: ' + JSON.stringify(err)); + expect(false).assertTrue(); + } + expect(bytesWritten1 == FILE_CONTENT.length).assertTrue(); + fileio.write(fd, new ArrayBuffer(FILE_CONTENT.length), { + length: undefined, + offset: undefined, + encoding: undefined, + }, (err, bytesWritten2) => { + if (err) { + console.log('fileio_test_write_async_013 err package2: ' + JSON.stringify(err)); + expect(false).assertTrue(); + } + expect(bytesWritten2 == FILE_CONTENT.length).assertTrue(); + let readLen = fileio.readSync(fd, new ArrayBuffer(4096), { position: 0 }); + expect(readLen == FILE_CONTENT.length * 2).assertTrue(); + fileio.closeSync(fd); + fileio.unlinkSync(fpath); + done(); + }); + }); + } catch (e) { + console.log('fileio_test_write_async_013 has failed for ' + e); + expect(false).assertTrue(); + } + }); +}); +} diff --git a/storage/storagefileiojstest/entry/src/main/resources/base/element/string.json b/storage/storagefileiojstest/src/main/resources/base/element/string.json similarity index 94% rename from storage/storagefileiojstest/entry/src/main/resources/base/element/string.json rename to storage/storagefileiojstest/src/main/resources/base/element/string.json index b3bdc98af5bc1ce516cfd0a8780ecfb80db93154..12e97063fc3e434d85e81eaa9d8ccc64904b7e06 100644 --- a/storage/storagefileiojstest/entry/src/main/resources/base/element/string.json +++ b/storage/storagefileiojstest/src/main/resources/base/element/string.json @@ -1,28 +1,28 @@ -{ - "string": [ - { - "name": "app_name", - "value": "storagefileiojstest" - }, - { - "name": "mainability_description", - "value": "JS_Phone_Empty Feature Ability" - }, - { - "name": "MainAbility_desc", - "value": "description" - }, - { - "name": "MainAbility_label", - "value": "label" - }, - { - "name": "TestAbility_desc", - "value": "description" - }, - { - "name": "TestAbility_label", - "value": "label" - } - ] -} +{ + "string": [ + { + "name": "app_name", + "value": "storagefileiojstest" + }, + { + "name": "mainability_description", + "value": "JS_Phone_Empty Feature Ability" + }, + { + "name": "MainAbility_desc", + "value": "description" + }, + { + "name": "MainAbility_label", + "value": "label" + }, + { + "name": "TestAbility_desc", + "value": "description" + }, + { + "name": "TestAbility_label", + "value": "label" + } + ] +} diff --git a/storage/storagefileioerrorjstest/entry/src/ohosTest/resources/base/media/icon.png b/storage/storagefileiojstest/src/main/resources/base/media/icon.png similarity index 100% rename from storage/storagefileioerrorjstest/entry/src/ohosTest/resources/base/media/icon.png rename to storage/storagefileiojstest/src/main/resources/base/media/icon.png