diff --git a/storage/storagefileiojstest/BUILD.gn b/storage/storagefileiojstest/BUILD.gn index bbcfa31a77d6d28e501fc1c0362cb2b36e9ae02a..a47d2455d530c3a0a88697a6cf7ceb2878bd9eea 100644 --- a/storage/storagefileiojstest/BUILD.gn +++ b/storage/storagefileiojstest/BUILD.gn @@ -25,7 +25,9 @@ ohos_js_hap_suite("storagefileio_js_test") { part_name = "xts_acts" } ohos_js_assets("storagefileio_js_assets") { - source_dir = "./src/main/js/default" + js2abc = true + hap_profile = "./src/main/config.json" + source_dir = "./src/main/js" } ohos_resources("storagefileio_js_resources") { sources = [ "./src/main/resources" ] diff --git a/storage/storagefileiojstest/Test.json b/storage/storagefileiojstest/Test.json index d32ddf4ac3eb41aad30acecbb26114a86fd50198..8dde280edd1704f62858f5a3d041345ec6d7eed1 100644 --- a/storage/storagefileiojstest/Test.json +++ b/storage/storagefileiojstest/Test.json @@ -1,16 +1,15 @@ { - "description": "Configuration for storage file and fileio Tests", + "description": "Configuration for storage fileio Tests", "driver": { - "type": "JSUnitTest", + "type": "OHJSUnitTest", "test-timeout": "1800000", - "package": "ohos.acts.storage.fileio", - "shell-timeout": "60000" + "shell-timeout": "1800000", + "bundle-name": "ohos.acts.storage.fileio", + "package-name": "ohos.acts.storage.fileio" }, "kits": [ { - "test-file-name": [ - "ActsStorageFileIoJSTest.hap" - ], + "test-file-name": ["ActsStorageFileIoJSTest.hap"], "type": "AppInstallKit", "cleanup-apps": true } diff --git a/storage/storagefileiojstest/src/main/config.json b/storage/storagefileiojstest/src/main/config.json index beb7366c8d05ae0ab29ee07302404db7c77e164e..14b48f21c781ae8521f6691421621094bf232ab0 100644 --- a/storage/storagefileiojstest/src/main/config.json +++ b/storage/storagefileiojstest/src/main/config.json @@ -1,61 +1,94 @@ { - "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": ".MyApplication", - "deviceType": [ - "phone" - ], - "distro": { - "deliveryWithInstall": true, - "moduleName": "entry", - "moduleType": "entry", - "installationFree": true + "app": { + "bundleName": "ohos.acts.storage.fileio", + "vendor": "example", + "version": { + "code": 1000000, + "name": "1.0.0" + }, + "apiVersion": { + "compatible": 4, + "target": 5 + } }, - "abilities": [ - { - "skills": [ - { - "entities": [ - "entity.system.home" - ], - "actions": [ - "action.system.home" - ] - } + "deviceConfig": {}, + "module": { + "package": "ohos.acts.storage.fileio", + "name": ".entry", + "deviceType": [ + "phone" ], - "name": "ohos.acts.storage.fileio.MainAbility", - "icon": "$media:icon", - "description": "$string:mainability_description", - "label": "$string:app_name", - "type": "page", - "launchType": "standard", - "visible": true - } - ], - "js": [ - { - "pages": [ - "pages/index/index" + "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" + } ], - "name": "default", - "window": { - "designWidth": 720, - "autoDesignWidth": false - } - } - ] - } + "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/src/main/js/default/app.js b/storage/storagefileiojstest/src/main/js/MainAbility/app.js similarity index 81% rename from storage/storagefileiojstest/src/main/js/default/app.js rename to storage/storagefileiojstest/src/main/js/MainAbility/app.js index 60ee141c8dbd251c763b7b74552b5a133a774d6a..b4d2bb9877f9c0dff9fd759072c6ea47f5791124 100644 --- a/storage/storagefileiojstest/src/main/js/default/app.js +++ b/storage/storagefileiojstest/src/main/js/MainAbility/app.js @@ -15,9 +15,9 @@ export default { onCreate() { - console.info('ohos.acts.distributeddatamgr.distributedfile onCreate'); + console.info('ohos.acts.storage.fileio onCreate'); }, onDestroy() { - console.info('ohos.acts.distributeddatamgr.distributedfile onCreate'); + console.info('ohos.acts.storage.fileio onDestroy'); } }; diff --git a/storage/storagefileiojstest/src/main/js/default/i18n/en-US.json b/storage/storagefileiojstest/src/main/js/MainAbility/i18n/en-US.json similarity index 100% rename from storage/storagefileiojstest/src/main/js/default/i18n/en-US.json rename to storage/storagefileiojstest/src/main/js/MainAbility/i18n/en-US.json diff --git a/storage/storagefileiojstest/src/main/js/default/i18n/zh-CN.json b/storage/storagefileiojstest/src/main/js/MainAbility/i18n/zh-CN.json similarity index 100% rename from storage/storagefileiojstest/src/main/js/default/i18n/zh-CN.json rename to storage/storagefileiojstest/src/main/js/MainAbility/i18n/zh-CN.json diff --git a/storage/storagefileiojstest/src/main/js/default/pages/index/index.css b/storage/storagefileiojstest/src/main/js/MainAbility/pages/index/index.css similarity index 100% rename from storage/storagefileiojstest/src/main/js/default/pages/index/index.css rename to storage/storagefileiojstest/src/main/js/MainAbility/pages/index/index.css diff --git a/storage/storagefileiojstest/src/main/js/default/pages/index/index.hml b/storage/storagefileiojstest/src/main/js/MainAbility/pages/index/index.hml similarity index 100% rename from storage/storagefileiojstest/src/main/js/default/pages/index/index.hml rename to storage/storagefileiojstest/src/main/js/MainAbility/pages/index/index.hml diff --git a/storage/storagefileiojstest/src/main/js/default/pages/index/index.js b/storage/storagefileiojstest/src/main/js/MainAbility/pages/index/index.js similarity index 77% rename from storage/storagefileiojstest/src/main/js/default/pages/index/index.js rename to storage/storagefileiojstest/src/main/js/MainAbility/pages/index/index.js index 61921cf3ba7d0a16a9c2edb9b9f04c1fb69a6333..6a9118dbb96efe627c20c435fdc1286f5d8611bf 100644 --- a/storage/storagefileiojstest/src/main/js/default/pages/index/index.js +++ b/storage/storagefileiojstest/src/main/js/MainAbility/pages/index/index.js @@ -15,26 +15,19 @@ import app from '@system.app' -import {Core} from 'deccjsunit/index' const injectRef = Object.getPrototypeOf(global) || global injectRef.regeneratorRuntime = require('@babel/runtime/regenerator') export default { - data: { - title: '' + data: { + title: '' }, onInit() { this.title = this.$t('strings.world'); }, onShow() { console.info('onShow finish') - const core = Core.getInstance() - core.init() - const configService = core.getDefaultService('config') - configService.setConfig(this) - require('../../test/List.test') - core.execute() }, onReady() { }, diff --git a/storage/storagefileiojstest/src/main/js/TestAbility/app.js b/storage/storagefileiojstest/src/main/js/TestAbility/app.js new file mode 100644 index 0000000000000000000000000000000000000000..d5ee271df29e516d1c8929054283e5f2bf5c981c --- /dev/null +++ b/storage/storagefileiojstest/src/main/js/TestAbility/app.js @@ -0,0 +1,31 @@ +/* + * 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/storagefileiojstest/src/main/js/TestAbility/i18n/en-US.json b/storage/storagefileiojstest/src/main/js/TestAbility/i18n/en-US.json new file mode 100644 index 0000000000000000000000000000000000000000..55561b83737c3c31d082fbfa11e5fc987a351104 --- /dev/null +++ b/storage/storagefileiojstest/src/main/js/TestAbility/i18n/en-US.json @@ -0,0 +1,8 @@ +{ + "strings": { + "hello": "Hello", + "world": "World" + }, + "Files": { + } +} \ No newline at end of file diff --git a/storage/storagefileiojstest/src/main/js/TestAbility/i18n/zh-CN.json b/storage/storagefileiojstest/src/main/js/TestAbility/i18n/zh-CN.json new file mode 100644 index 0000000000000000000000000000000000000000..cce1af06761a42add0cac1a0567aa3237eda8cb4 --- /dev/null +++ b/storage/storagefileiojstest/src/main/js/TestAbility/i18n/zh-CN.json @@ -0,0 +1,8 @@ +{ + "strings": { + "hello": "您好", + "world": "世界" + }, + "Files": { + } +} \ No newline at end of file diff --git a/storage/storagefileiojstest/src/main/js/TestAbility/pages/index/index.css b/storage/storagefileiojstest/src/main/js/TestAbility/pages/index/index.css new file mode 100644 index 0000000000000000000000000000000000000000..b21c92c6290ea747bd891e2ab673721afc5521ed --- /dev/null +++ b/storage/storagefileiojstest/src/main/js/TestAbility/pages/index/index.css @@ -0,0 +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; + } +} \ No newline at end of file diff --git a/storage/storagefilejstest/src/main/js/default/pages/index/index.hml b/storage/storagefileiojstest/src/main/js/TestAbility/pages/index/index.hml similarity index 100% rename from storage/storagefilejstest/src/main/js/default/pages/index/index.hml rename to storage/storagefileiojstest/src/main/js/TestAbility/pages/index/index.hml diff --git a/storage/storagefileiojstest/src/main/js/TestAbility/pages/index/index.js b/storage/storagefileiojstest/src/main/js/TestAbility/pages/index/index.js new file mode 100644 index 0000000000000000000000000000000000000000..d94b75c085fa1c16a0b2721609b18c57a7295476 --- /dev/null +++ b/storage/storagefileiojstest/src/main/js/TestAbility/pages/index/index.js @@ -0,0 +1,26 @@ +/* + * 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. + */ + +export default { + data: { + title: "" + }, + onInit() { + this.title = this.$t('strings.world'); + } +} + + + diff --git a/storage/storagefileiojstest/src/main/js/TestRunner/OpenHarmonyTestRunner.js b/storage/storagefileiojstest/src/main/js/TestRunner/OpenHarmonyTestRunner.js new file mode 100644 index 0000000000000000000000000000000000000000..b9e78ce7cf73f1ade6ba52a408a44e33f5430f0d --- /dev/null +++ b/storage/storagefileiojstest/src/main/js/TestRunner/OpenHarmonyTestRunner.js @@ -0,0 +1,59 @@ +/* + * 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/src/main/js/default/test/FileIO.test.js b/storage/storagefileiojstest/src/main/js/default/test/FileIO.test.js deleted file mode 100644 index 0c1849d547efaa497e7735438e39616ce7c96f65..0000000000000000000000000000000000000000 --- a/storage/storagefileiojstest/src/main/js/default/test/FileIO.test.js +++ /dev/null @@ -1,4313 +0,0 @@ -/* - * 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 'deccjsunit/index' -import { - FILE_CONTENT, - prepareFile, - nextFileName, - prepareEmptyFile, - randomString, - fileName, - forceRemoveDir -} -from './Common' -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, - }); - expect(null).assertFail(); - }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, - }); - expect(null).assertFail(); - }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); - expect(null).assertFail(); - } - catch (err) { - fileio.unlinkSync(fpath); - } - }); - - /** - * @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, - }); - expect(null).assertFail(); - } - 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, - }); - expect(null).assertFail(); - } - catch (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, - }); - expect(null).assertFail(); - } - catch (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, - }); - expect(null).assertFail(); - } - catch (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, - }); - expect(null).assertFail(); - } - catch (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, - }); - expect(null).assertFail(); - } - catch (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, - }); - expect(null).assertFail(); - } - catch (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 { - let fd = fileio.openSync(fpath, 0o102, 0o700); - expect(null).assertFail(); - } - catch (err) { - console.info('fileio_test_open_038 has failed for ' + err); - } - }); - - /** - * @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); - //expect(null).assertFail(); - }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); - } - } - expect(null).assertFail(); - } - 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); - } - }); - - /** - * @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); - } - } - expect(null).assertFail(); - } - 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); - } - catch (err) { - console.info('fileio_test_close_sync_001 has failed for ' + err); - expect(err.message == "Bad file descriptor").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); - expect(null).assertFail(); - } - 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(); - expect(null).assertFail(); - } - catch (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); - expect(null).assertFail(); - } - catch (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); - } - catch (err) { - console.info('fileio_test_write_sync_008 has failed for ' + err); - expect(err.message == "Bad file descriptor").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, buffer limit exceeded").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 == "Bad file descriptor").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, copy. fpatch 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 == "No such file or directory").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 == "Invalid argument" || err.message == "Bad file descriptor").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); - } - } - expect(null).assertFail(); - } - 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); - expect(null).assertFail(); - } - catch (err) { - fileio.unlinkSync(fpath); - console.info('fileio_test_copy_file_sync_009 has failed for ' + err); - } - }); - - /** - * @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); - } - } - expect(null).assertFail(); - } - 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); - expect(null).assertFail(); - } - catch (err) { - fileio.unlinkSync(fpath); - } - }); - - /** - * @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); - expect(null).assertFail(); - } - catch (err) { - console.info('fileio_test_rename_sync_004 pass. ' + err); - } - }); - - /** - * @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); - expect(null).assertFail(); - } - catch (err) { - fileio.unlinkSync(fpath); - console.info('fileio_test_rename_sync_005 pass. ' + err); - } - }); - - /** - * @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 == "Bad file descriptor").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); - } - catch (err) { - console.info('fileio_test_fsync_sync_002 has failed for ' + err); - expect(err.message == "Bad file descriptor").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 { - expect(fileio.fstatSync(-1) !== null).assertTrue(); - }catch (err) { - console.info('fileio_test_fstat_sync_001 has failed for ' + err); - expect(err.message == "Bad file descriptor").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 == "Operation not permitted").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 == "Operation not permitted").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); - await 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); - await fileio.close(fd, function (err) { - fileio.unlinkSync(fpath); - }); - }); -}); \ No newline at end of file diff --git a/storage/storagefileiojstest/src/main/js/default/test/List.test.js b/storage/storagefileiojstest/src/main/js/default/test/List.test.js deleted file mode 100644 index bb53fca8d9a3cb8e265e46fb011327fa6ab4606e..0000000000000000000000000000000000000000 --- a/storage/storagefileiojstest/src/main/js/default/test/List.test.js +++ /dev/null @@ -1,61 +0,0 @@ -/* - * 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. - */ - -require('./FileIO.test.js') -require('./FileIODir.test.js') -require('./FileIODirent.test.js') -require('./FileIOStat.test.js') -require('./FileIOStream.test.js') -require('./module_fileio/members/open_close.test.js'); -require('./module_fileio/class_dirent/all.test.js'); -require('./module_fileio/class_watcher/createWatcher.test.js'); -require('./module_fileio/class_stream/flush.test.js'); -require('./module_fileio/class_stream/read.test.js'); -require('./module_fileio/members/access.test.js'); -require('./module_fileio/members/chmod.test.js'); -require('./module_fileio/members/chown.test.js'); -require('./module_fileio/members/close.test.js'); -require('./module_fileio/members/copyFile.test.js'); -require('./module_fileio/members/createStream.test.js'); -require('./module_fileio/members/fchmod.test.js'); -require('./module_fileio/members/fchown.test.js'); -require('./module_fileio/members/fdatasync.test.js'); -require('./module_fileio/members/fdopenStream.test.js'); -require('./module_fileio/members/fstat.test.js'); -require('./module_fileio/members/fsync.test.js'); -require('./module_fileio/members/ftruncate.test.js'); -require('./module_fileio/members/hash.test.js'); -require('./module_fileio/members/lchown.test.js'); -require('./module_fileio/members/lseek.test.js'); -require('./module_fileio/members/lstat.test.js'); -require('./module_fileio/members/mkdir_rmdir.test.js'); -require('./module_fileio/members/mkdtemp.test.js'); -require('./module_fileio/members/open.test.js'); -require('./module_fileio/members/opendir_close.test.js'); -require('./module_fileio/members/posix_fallocate.test.js'); -require('./module_fileio/members/read.test.js'); -require('./module_fileio/members/readtext.test.js'); -require('./module_fileio/members/rename.test.js'); -require('./module_fileio/members/rmdir.test.js'); -require('./module_fileio/members/stat.test.js'); -require('./module_fileio/members/symlink.test.js'); -require('./module_fileio/members/truncate.test.js'); -require('./module_fileio/members/unlink.test.js'); -require('./module_fileio/members/write.test.js'); -require('./module_fileio/class_dir/read.test.js'); -require('./module_fileio/class_dir/close.test.js'); -require('./module_fileio/class_stream/all.test.js'); -require('./module_fileio/class_stream/close.test.js'); -require('./module_fileio/class_stream/write.test.js'); diff --git a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/mkdir_rmdir.test.js b/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/mkdir_rmdir.test.js deleted file mode 100644 index 63524e97d8517c085cd8bf07283396af6f484d7b..0000000000000000000000000000000000000000 --- a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/mkdir_rmdir.test.js +++ /dev/null @@ -1,327 +0,0 @@ -/* - * 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, isIntNum } from '../../Common'; - -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 { - fileio.mkdirSync(dpath); - expect((fileio.opendirSync(dpath)) != null).assertTrue(); - console.info('fileio_mkdir_sync_rmdir_sync_000 has mkdir SUCCESS'); - fileio.rmdirSync(dpath); - }catch (e) { - console.info('fileio_mkdir_sync_rmdir_sync_000 has failed for '+e); - expect(false).assertTrue(); - } - try { - fileio.opendirSync(dpath); - expect(false).assertTrue(); - }catch (e) { - expect(e.toString().indexOf('No such file or directory') != -1).assertTrue(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_MKDIR_SYNC_RMDIR_SYNC_0100 - * @tc.name fileio_mkdir_sync_rmdir_sync_001 - * @tc.desc Test mkdirSync() interfaces,Path parameter passing '/' - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_mkdir_sync_rmdir_sync_001', 0, function () { - try { - fileio.mkdirSync('/'); - expect(false).assertTrue(); - } catch (e) { - expect(e.toString().indexOf('File exists') != -1).assertTrue(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_MKDIR_SYNC_RMDIR_SYNC_0200 - * @tc.name fileio_mkdir_sync_rmdir_sync_002 - * @tc.desc Test mkdirSync() interfaces,Path parameter passes invalid path 12 - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_mkdir_sync_rmdir_sync_002', 0, function () { - try { - fileio.mkdirSync(12); - expect(false).assertTrue(); - } catch (e) { - expect(e.toString().indexOf('Invalid path') != -1).assertTrue(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_MKDIR_SYNC_RMDIR_SYNC_0300 - * @tc.name fileio_mkdir_sync_rmdir_sync_003 - * @tc.desc Test mkdirSync() interfaces,Path passes null parameter - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_mkdir_sync_rmdir_sync_003', 0, function () { - try { - fileio.mkdirSync(); - expect(false).assertTrue(); - } catch (e) { - expect(e.toString().indexOf('Number of arguments unmatched') != -1).assertTrue(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_MKDIR_SYNC_RMDIR_SYNC_0400 - * @tc.name fileio_mkdir_sync_rmdir_sync_004 - * @tc.desc Test rmdirSync() interfaces,Path parameter passes invalid path 12 - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_mkdir_sync_rmdir_sync_004', 0, function () { - try { - fileio.rmdirSync(12); - expect(false).assertTrue(); - } catch (e) { - expect(e.toString().indexOf('Invalid path') != -1).assertTrue(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_MKDIR_SYNC_RMDIR_SYNC_0500 - * @tc.name fileio_mkdir_sync_rmdir_sync_005 - * @tc.desc Test rmdirSync() interfaces,Path passes null parameter - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_mkdir_sync_rmdir_sync_005', 0, function () { - try { - fileio.rmdirSync(); - expect(false).assertTrue(); - } catch (e) { - expect(e.toString().indexOf('Number of arguments unmatched') != -1).assertTrue(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_MKDIR_ASYNC_RMDIR_SYNC_0000 - * @tc.name fileio_mkdir_async_rmdir_sync_000 - * @tc.desc Test mkdir() 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 { - await fileio.mkdir(dpath); - expect((fileio.opendirSync(dpath)) != null).assertTrue(); - console.info('fileio_mkdir_async_rmdir_sync_000 has mkdir SUCCESS'); - fileio.rmdirSync(dpath); - done(); - }catch (e) { - console.info('fileio_mkdir_async_rmdir_sync_000 has mkdir failed for ' + e); - expect(false).assertTrue(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_MKDIR_ASYNC_RMDIR_SYNC_0100 - * @tc.name fileio_mkdir_async_rmdir_sync_001 - * @tc.desc Test mkdir() 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(error.toString().indexOf('No error information') != -1).assertTrue(); - expect((fileio.opendirSync(dpath)) != null).assertTrue(); - console.info('fileio_mkdir_async_rmdir_sync_001 has mkdir SUCCESS'); - fileio.rmdirSync(dpath); - }); - } catch (e) { - console.info('fileio_mkdir_async_rmdir_sync_001 has mkdir failed for ' + e); - expect(false).assertTrue(); - } - done(); - }); - - /** - * @tc.number SUB_DF_FILEIO_MKDIR_ASYNC_RMDIR_SYNC_0200 - * @tc.name fileio_mkdir_async_rmdir_sync_002 - * @tc.desc Test mkdir() interfaces,mode parameter passing 777 - * @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 { - await fileio.mkdir(fpath, 777); - expect((fileio.opendirSync(fpath)) != null).assertTrue(); - console.info('fileio_mkdir_async_rmdir_sync_002 has mkdir SUCCESS'); - fileio.rmdirSync(fpath); - done(); - } catch (e) { - console.info('fileio_mkdir_async_rmdir_sync_002 has mkdir failed for ' + e); - expect(false).assertTrue(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_MKDIR_ASYNC_RMDIR_SYNC_0300 - * @tc.name fileio_mkdir_async_rmdir_sync_003 - * @tc.desc Test mkdir() interfaces,mode parameter passing 400 - * @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 { - await fileio.mkdir(fpath, 400); - expect((fileio.opendirSync(fpath)) != null).assertTrue(); - console.info('fileio_mkdir_async_rmdir_sync_003 has mkdir SUCCESS'); - fileio.rmdirSync(fpath); - done(); - } catch (e) { - console.info('fileio_mkdir_async_rmdir_sync_003 has mkdir failed for ' + e); - expect(false).assertTrue(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_MKDIR_ASYNC_RMDIR_SYNC_0400 - * @tc.name fileio_mkdir_async_rmdir_sync_004 - * @tc.desc Test mkdir() interfaces,Path parameter passes invalid path 12 - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_mkdir_async_rmdir_sync_004', 0, async function (done) { - try { - await fileio.mkdir(12); - expect(false).assertTrue(); - } catch (e) { - expect(e.toString().indexOf('Invalid path') != -1).assertTrue(); - done(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_MKDIR_ASYNC_RMDIR_SYNC_0500 - * @tc.name fileio_mkdir_async_rmdir_sync_005 - * @tc.desc Test mkdir() interfaces,Path parameter passing '/' - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_mkdir_async_rmdir_sync_005', 0, async function (done) { - try { - await fileio.mkdir('/'); - expect(false).assertTrue(); - } catch (e) { - expect(e.toString().indexOf('File exists') != -1).assertTrue(); - done(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_MKDIR_ASYNC_RMDIR_SYNC_0600 - * @tc.name fileio_mkdir_async_rmdir_sync_006 - * @tc.desc Test mkdir() interfaces,Path passes null parameter - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_mkdir_async_rmdir_sync_006', 0, async function (done) { - try { - await fileio.mkdir(); - expect(false).assertTrue(); - } catch (e) { - expect(e.toString().indexOf('Number of arguments unmatched') != -1).assertTrue(); - console.info('fileio_mkdir_async_rmdir_sync_006 has failed for ' + e); - done(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_MKDIR_SYNC_RMDIR_ASYNC_0000 - * @tc.name fileio_mkdir_sync_rmdir_async_000 - * @tc.desc Test rmdir() and interfaces,Path parameter passes invalid path 12 - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_mkdir_sync_rmdir_async_000', 0, async function (done) { - try { - await fileio.rmdir(12); - expect(false).assertTrue(); - }catch (e) { - expect(e.toString().indexOf('Invalid path') != -1).assertTrue(); - done(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_MKDIR_SYNC_RMDIR_ASYNC_0100 - * @tc.name fileio_mkdir_sync_rmdir_async_001 - * @tc.desc Test rmdir() and interfaces,Path passes null parameter - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it('fileio_mkdir_sync_rmdir_async_001', 0, async function (done) { - try { - await fileio.rmdir(); - expect(false).assertTrue(); - }catch (e) { - expect(e.toString().indexOf('Number of arguments unmatched') != -1).assertTrue(); - done(); - } - }); -}); \ No newline at end of file diff --git a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/rmdir.test.js b/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/rmdir.test.js deleted file mode 100644 index 30107b8a44a57fae1ae109f1173854974fe09f17..0000000000000000000000000000000000000000 --- a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/rmdir.test.js +++ /dev/null @@ -1,153 +0,0 @@ -/* - * 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'; - -describe('fileio_rmdir', function () { - - /** - * @tc.number SUB_DF_FILEIO_RMDIR_ASYNC_0000 - * @tc.name fileio_test_rmdir_async_000 - * @tc.desc Test rmdirAsync() interfaces. - * @tc.size MEDIUM - * @tc.type Functoin - * @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'; - - try { - expect(fileio.mkdirSync(dpath) == null).assertTrue(); - expect(await fileio.rmdir(dpath) == null).assertTrue(); - fileio - .access(dpath) - .then(function () { - expect(null).assertFail(); - done(); - }) - .catch((err) => { - expect(!!err).assertTrue(); - done(); - }); - } catch (e) { - console.log('fileio_test_rmdir_async_000 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_RMDIR_ASYNC_0010 - * @tc.name fileio_test_rmdir_async_001 - * @tc.desc Test rmdirAsync() interfaces. - * @tc.size MEDIUM - * @tc.type Functoin - * @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'; - - try { - expect(fileio.mkdirSync(dpath) == null).assertTrue(); - fileio.rmdir(dpath, function (err) { - fileio - .access(dpath) - .then(function () { - expect(null).assertFail(); - done(); - }) - .catch((err) => { - expect(!!err).assertTrue(); - done(); - }); - }); - } catch (e) { - console.log('fileio_test_rmdir_async_001 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_RMDIR_ASYNC_0020 - * @tc.name fileio_test_rmdir_async_002 - * @tc.desc Test rmdirAsync() interfaces. - * @tc.size MEDIUM - * @tc.type Functoin - * @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'; - expect(prepareFile(dpath, FILE_CONTENT)).assertTrue(); - - try { - fileio.rmdir(dpath, async function (err) { - expect(!!err).assertTrue(); - expect(await fileio.access(dpath) == null).assertTrue(); - await fileio.unlink(dpath); - done(); - }); - } catch (e) { - console.log('fileio_test_rmdir_async_002 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_RMDIR_ASYNC_0030 - * @tc.name fileio_test_rmdir_async_003 - * @tc.desc Test rmdirAsync() interfaces. - * @tc.size MEDIUM - * @tc.type Functoin - * @tc.level Level 0 - * @tc.require - */ - it('fileio_test_rmdir_async_003', 0, function (done) { - try { - fileio.rmdir('1.js', function (err) { - expect(!!err).assertTrue(); - done(); - }); - } catch (e) { - console.log('fileio_test_rmdir_async_003 has failed for ' + e); - expect(null).assertFail(); - } - }); - - /** - * @tc.number SUB_DF_FILEIO_RMDIR_SYNC_0000 - * @tc.name fileio_test_rmdir_sync_000 - * @tc.desc Test rmdirSync() interfaces. - * @tc.size MEDIUM - * @tc.type Functoin - * @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'; - - try { - expect(fileio.mkdirSync(dpath) == null).assertTrue(); - expect(fileio.rmdirSync(dpath) == null).assertTrue(); - } catch (e) { - console.log('fileio_test_rmdir_sync_000 has failed for ' + e); - expect(null).assertFail(); - } - }); -}); diff --git a/storage/storagefileiojstest/src/main/js/default/test/Common.js b/storage/storagefileiojstest/src/main/js/test/Common.js similarity index 96% rename from storage/storagefileiojstest/src/main/js/default/test/Common.js rename to storage/storagefileiojstest/src/main/js/test/Common.js index df933b5f77eea806363c0168a4ab5d99cadb6e54..ab53cac8ac295a330dfd702774e50d0e29894358 100644 --- a/storage/storagefileiojstest/src/main/js/default/test/Common.js +++ b/storage/storagefileiojstest/src/main/js/test/Common.js @@ -21,7 +21,7 @@ export const FILE_CONTENT = 'hello world'; import { describe, it, expect } -from 'deccjsunit/index' +from '@ohos/hypium' export function prepareFile(fpath, content) { try { @@ -120,11 +120,16 @@ function isBoolean(val) { return typeof val == 'boolean'; } +function isInclude(error, message) { + return error.toString().indexOf(message) != -1; +} + export { fileio, isIntNum, isString, isBoolean, + isInclude, describe, it, expect diff --git a/storage/storagefileiojstest/src/main/js/test/FileIO.test.js b/storage/storagefileiojstest/src/main/js/test/FileIO.test.js new file mode 100644 index 0000000000000000000000000000000000000000..0fd8e37a4dc1906320532d7644c4c801af0412ce --- /dev/null +++ b/storage/storagefileiojstest/src/main/js/test/FileIO.test.js @@ -0,0 +1,4320 @@ +/* + * 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); + } + catch (err) { + console.info('fileio_test_close_sync_001 has failed for ' + err); + expect(err.message == "Bad file descriptor").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); + } + catch (err) { + console.info('fileio_test_write_sync_008 has failed for ' + err); + expect(err.message == "Bad file descriptor").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, buffer limit exceeded").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 == "Bad file descriptor").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, copy. fpatch 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 == "No such file or directory").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 == "Invalid argument" || err.message == "Bad file descriptor").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 == "Bad file descriptor").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); + } + catch (err) { + console.info('fileio_test_fsync_sync_002 has failed for ' + err); + expect(err.message == "Bad file descriptor").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 { + expect(fileio.fstatSync(-1) !== null).assertTrue(); + }catch (err) { + console.info('fileio_test_fstat_sync_001 has failed for ' + err); + expect(err.message == "Bad file descriptor").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 == "Operation not permitted").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 == "Operation not permitted").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); + await 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); + await fileio.close(fd, function (err) { + fileio.unlinkSync(fpath); + }); + }); + }); +} diff --git a/storage/storagefileiojstest/src/main/js/default/test/FileIODir.test.js b/storage/storagefileiojstest/src/main/js/test/FileIODir.test.js similarity index 98% rename from storage/storagefileiojstest/src/main/js/default/test/FileIODir.test.js rename to storage/storagefileiojstest/src/main/js/test/FileIODir.test.js index 79cb96ef6de89c64d4a0cdce7381fcca1dea8928..263e65c8a5cb040ce629f64ba248823629857f81 100644 --- a/storage/storagefileiojstest/src/main/js/default/test/FileIODir.test.js +++ b/storage/storagefileiojstest/src/main/js/test/FileIODir.test.js @@ -14,7 +14,7 @@ */ import fileio from '@ohos.fileio'; -import { describe,it,expect}from 'deccjsunit/index' +import { describe,it,expect}from '@ohos/hypium' import { FILE_CONTENT, prepareFile, @@ -24,6 +24,7 @@ import { } from './Common' +export default function fileIOTestDir() { describe('fileIOTestDir', function () { /** @@ -54,7 +55,7 @@ describe('fileIOTestDir', function () { it('fileio_test_dir_open_sync_001', 0, function () { try { fileio.opendirSync(); - expect(null).assertFail(); + throw new Error('No Parameter'); } catch (e) { console.info('fileio_test_dir_open_sync_001 has failed for ' + e); @@ -92,7 +93,7 @@ describe('fileIOTestDir', function () { dpath = dpath + '/d' + i; fileio.mkdirSync(dpath); } - expect(null).assertFail(); + throw new Error('dpath too long'); } catch (e) { console.info('fileio_test_dir_open_sync_003 has failed for ' + e); @@ -130,7 +131,7 @@ describe('fileIOTestDir', function () { dpath = dpath + '/d' + i fileio.mkdirSync(dpath); } - expect(null).assertFail(); + throw new Error('dir too many layers'); } catch (e) { console.info('fileio_test_dir_open_sync_005 has failed for ' + e); @@ -408,3 +409,4 @@ describe('fileIOTestDir', function () { } }); }); +} diff --git a/storage/storagefileiojstest/src/main/js/default/test/FileIODirent.test.js b/storage/storagefileiojstest/src/main/js/test/FileIODirent.test.js similarity index 99% rename from storage/storagefileiojstest/src/main/js/default/test/FileIODirent.test.js rename to storage/storagefileiojstest/src/main/js/test/FileIODirent.test.js index b695fe91252227c0cc83bde533e6dea2a8209e94..d4b57588d88fe8a5cb28ab0518982904940bff67 100644 --- a/storage/storagefileiojstest/src/main/js/default/test/FileIODirent.test.js +++ b/storage/storagefileiojstest/src/main/js/test/FileIODirent.test.js @@ -14,13 +14,14 @@ */ import fileio from '@ohos.fileio'; -import { describe,it,expect}from 'deccjsunit/index' +import { describe,it,expect}from '@ohos/hypium' import { FILE_CONTENT, prepareFile, nextFileName }from './Common'; +export default function fileIOTestDirent() { describe('fileIOTestDirent', function () { /** @@ -420,4 +421,4 @@ describe('fileIOTestDirent', function () { } }); -}); \ No newline at end of file +});} diff --git a/storage/storagefileiojstest/src/main/js/default/test/FileIOStat.test.js b/storage/storagefileiojstest/src/main/js/test/FileIOStat.test.js similarity index 99% rename from storage/storagefileiojstest/src/main/js/default/test/FileIOStat.test.js rename to storage/storagefileiojstest/src/main/js/test/FileIOStat.test.js index bf3aff2c69bccdae5043fd49313e38f7994c32f4..f45ab61fa3f17792e0a1873c71fb7f73824dbc6e 100644 --- a/storage/storagefileiojstest/src/main/js/default/test/FileIOStat.test.js +++ b/storage/storagefileiojstest/src/main/js/test/FileIOStat.test.js @@ -14,7 +14,7 @@ */ import fileio from '@ohos.fileio'; -import { describe,it,expect}from 'deccjsunit/index' +import { describe,it,expect}from '@ohos/hypium' import { FILE_CONTENT, prepareFile, @@ -24,6 +24,7 @@ import { } from './Common' +export default function fileIOTestStat() { describe('fileIOTestStat', function () { /** @@ -781,3 +782,4 @@ describe('fileIOTestStat', function () { }); }); +} diff --git a/storage/storagefileiojstest/src/main/js/default/test/FileIOStream.test.js b/storage/storagefileiojstest/src/main/js/test/FileIOStream.test.js similarity index 99% rename from storage/storagefileiojstest/src/main/js/default/test/FileIOStream.test.js rename to storage/storagefileiojstest/src/main/js/test/FileIOStream.test.js index 64f02c7247f7242b6f61dbe7c30a5bc2392e1fce..4494cc827632b883db1349768037ea503e8d6a41 100644 --- a/storage/storagefileiojstest/src/main/js/default/test/FileIOStream.test.js +++ b/storage/storagefileiojstest/src/main/js/test/FileIOStream.test.js @@ -14,7 +14,7 @@ */ import fileio from '@ohos.fileio'; -import { describe,it,expect}from 'deccjsunit/index' +import { describe,it,expect}from '@ohos/hypium' import { FILE_CONTENT, prepareFile, @@ -26,6 +26,7 @@ import { } from './Common' +export default function fileIOTestStream() { describe('fileIOTestStream', function () { /** @@ -585,7 +586,7 @@ describe('fileIOTestStream', function () { expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); try { fileio.createStreamSync(fpath, ''); - expect(null).assertFail(); + throw new Error('invalid mode'); } catch (e) { console.info('fileio_test_stream_create_stream_sync_025 has failed for ' + e); @@ -612,7 +613,7 @@ describe('fileIOTestStream', function () { fileio.mkdirSync(dpath); } } - expect(null).assertFail(); + throw new Error('fpath too long'); } catch (e) { console.info('fileio_test_stream_create_stream_sync_026 has failed for ' + e); @@ -655,7 +656,7 @@ describe('fileIOTestStream', function () { fileio.mkdirSync(dpath); } } - expect(null).assertFail(); + throw new Error('path too deep'); } catch (e) { console.info('fileio_test_stream_create_stream_sync_028 has failed for ' + e); @@ -762,7 +763,7 @@ describe('fileIOTestStream', function () { let fd = -1; let mode = 'r'; fileio.fdopenStreamSync(fd, mode); - expect(null).assertFail(); + throw new Error('Bad file descriptor'); } catch (e) { console.info('fileio_test_stream_fdopen_stream_sync_001 has failed for ' + e); @@ -901,7 +902,7 @@ describe('fileIOTestStream', function () { it('fileio_test_stream_fdopen_stream_sync_007', 0, async function () { try { fileio.fdopenStreamSync(-1, 'r+'); - expect(null).assertFail(); + throw new Error('Bad file descriptor'); } catch (e) { console.info('fileio_test_stream_fdopen_stream_sync_007 has failed for ' + e); @@ -1038,7 +1039,7 @@ describe('fileIOTestStream', function () { it('fileio_test_stream_fdopen_stream_sync_013', 0, async function () { try { fileio.fdopenStreamSync(-1, 'rb'); - expect(null).assertFail(); + throw new Error('Bad file descriptor'); } catch (e) { console.info('fileio_test_stream_fdopen_stream_sync_013 has failed for ' + e); @@ -1176,7 +1177,7 @@ describe('fileIOTestStream', function () { it('fileio_test_stream_fdopen_stream_sync_019', 0, async function () { try { fileio.fdopenStreamSync(-1, 'rb+'); - expect(null).assertFail(); + throw new Error('Bad file descriptor'); } catch (e) { console.info('fileio_test_stream_fdopen_stream_sync_019 has failed for ' + e); @@ -1310,7 +1311,7 @@ describe('fileIOTestStream', function () { try { let fd = fileio.openSync(fpath, 0o2); fileio.fdopenStreamSync(fd, ''); - expect(null).assertFail(); + throw new Error('invalid mode'); } catch (e) { console.info('fileio_test_stream_fdopen_stream_sync_025 has failed for ' + e); @@ -2003,3 +2004,4 @@ describe('fileIOTestStream', function () { } }); }); +} diff --git a/storage/storagefileiojstest/src/main/js/test/List.test.js b/storage/storagefileiojstest/src/main/js/test/List.test.js new file mode 100644 index 0000000000000000000000000000000000000000..8d3aeda3b2eab66c34efbb2243c0aca24a0721b6 --- /dev/null +++ b/storage/storagefileiojstest/src/main/js/test/List.test.js @@ -0,0 +1,111 @@ +/* + * 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 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 fileio_dir_close from './module_fileio/class_dir/close.test.js' +import fileio_dir_listfile from './module_fileio/class_dir/listfile.test.js' +import fileio_dir_read from './module_fileio/class_dir/read.test.js' +import fileio_dirent from './module_fileio/class_dirent/all.test.js' +import fileio_stream_1 from './module_fileio/class_stream/all.test.js' +import fileio_stream_close from './module_fileio/class_stream/close.test.js' +import fileio_stream_flush from './module_fileio/class_stream/flush.test.js' +import fileio_stream_read from './module_fileio/class_stream/read.test.js' +import fileio_stream_write from './module_fileio/class_stream/write.test.js' +import fileio_createWatcher from './module_fileio/class_watcher/createWatcher.test.js' +import fileio_access from './module_fileio/members/access.test.js' +import fileio_chmod from './module_fileio/members/chmod.test.js' +import fileio_chown from './module_fileio/members/chown.test.js' +import fileio_close from './module_fileio/members/close.test.js' +import fileio_copyfile from './module_fileio/members/copyFile.test.js' +import fileio_createStream from './module_fileio/members/createStream.test.js' +import fileio_fchmod from './module_fileio/members/fchmod.test.js' +import fileio_fchown from './module_fileio/members/fchown.test.js' +import fileio_fdatasync from './module_fileio/members/fdatasync.test.js' +import fileio_FdOpenStream from './module_fileio/members/fdopenStream.test.js' +import fileio_stat_fstat from './module_fileio/members/fstat.test.js' +import fileio_stat_fsync from './module_fileio/members/fsync.test.js' +import fileio_ftruncate from './module_fileio/members/ftruncate.test.js' +import fileio_hash from './module_fileio/members/hash.test.js' +import fileio_lchown from './module_fileio/members/lchown.test.js' +import fileio_lseek from './module_fileio/members/lseek.test.js' +import fileio_lstat from './module_fileio/members/lstat.test.js' +import fileio_mkdir_rmdir from './module_fileio/members/mkdir_rmdir.test.js' +import fileio_mkdtemp from './module_fileio/members/mkdtemp.test.js' +import fileio_open from './module_fileio/members/open.test.js' +import fileio_dir_opendir_close from './module_fileio/members/opendir_close.test.js' +import fileio_open_close from './module_fileio/members/open_close.test.js' +import fileio_posix_fallocate from './module_fileio/members/posix_fallocate.test.js' +import fileio_read from './module_fileio/members/read.test.js' +import fileio_readtext from './module_fileio/members/readtext.test.js' +import fileio_rename from './module_fileio/members/rename.test.js' +import fileio_rmdir from './module_fileio/members/rmdir.test.js' +import fileio_stat from './module_fileio/members/stat.test.js' +import fileio_symlink from './module_fileio/members/symlink.test.js' +import fileio_truncate from './module_fileio/members/truncate.test.js' +import fileio_unlink from './module_fileio/members/unlink.test.js' +import fileio_write from './module_fileio/members/write.test.js' +export default function testsuite() { + fileIOTest() + fileIOTestDir() + fileIOTestDirent() + fileIOTestStat() + fileIOTestStream() + fileio_dir_close() + fileio_dir_listfile() + fileio_dir_read() + fileio_dirent() + fileio_stream_1() + fileio_stream_close() + fileio_stream_flush() + fileio_stream_read() + fileio_stream_write() + fileio_createWatcher() + fileio_access() + fileio_chmod() + fileio_chown() + fileio_close() + fileio_copyfile() + fileio_createStream() + fileio_fchmod() + fileio_fchown() + fileio_fdatasync() + fileio_FdOpenStream() + fileio_stat_fstat() + fileio_stat_fsync() + fileio_ftruncate() + fileio_hash() + fileio_lchown() + fileio_lseek() + fileio_lstat() + fileio_mkdir_rmdir() + fileio_mkdtemp() + fileio_open() + fileio_dir_opendir_close() + fileio_open_close() + fileio_posix_fallocate() + fileio_read() + fileio_readtext() + fileio_rename() + fileio_rmdir() + fileio_stat() + fileio_symlink() + fileio_truncate() + fileio_unlink() + fileio_write() +} diff --git a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/class_constants/constants.test.js b/storage/storagefileiojstest/src/main/js/test/module_fileio/class_constants/constants.test.js similarity index 98% rename from storage/storagefileiojstest/src/main/js/default/test/module_fileio/class_constants/constants.test.js rename to storage/storagefileiojstest/src/main/js/test/module_fileio/class_constants/constants.test.js index a69abf694b783a750a1603859fa2562e79627a88..18f0219b746ae161bd862d9b57a89fae2eebb120 100644 --- a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/class_constants/constants.test.js +++ b/storage/storagefileiojstest/src/main/js/test/module_fileio/class_constants/constants.test.js @@ -18,6 +18,7 @@ import { describe, it, expect, } from '../../Common'; +export default function constants() { describe('constants', function () { /** @@ -71,4 +72,4 @@ describe('constants', function () { expect(null).assertFail(); } }); -}); \ No newline at end of file +});} diff --git a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/class_dir/close.test.js b/storage/storagefileiojstest/src/main/js/test/module_fileio/class_dir/close.test.js similarity index 98% rename from storage/storagefileiojstest/src/main/js/default/test/module_fileio/class_dir/close.test.js rename to storage/storagefileiojstest/src/main/js/test/module_fileio/class_dir/close.test.js index feb81a3e73ab7ddcd713fb519348ec6a691feaea..69dc406f88814cc73000a15e780efff07a184cc4 100644 --- a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/class_dir/close.test.js +++ b/storage/storagefileiojstest/src/main/js/test/module_fileio/class_dir/close.test.js @@ -21,6 +21,7 @@ import { expect, } from '../../Common'; +export default function fileio_dir_close() { describe('fileio_dir_close', function () { /** @@ -96,3 +97,4 @@ describe('fileio_dir_close', function () { } }); }); +} diff --git a/storage/storagefileiojstest/src/main/js/test/module_fileio/class_dir/listfile.test.js b/storage/storagefileiojstest/src/main/js/test/module_fileio/class_dir/listfile.test.js new file mode 100644 index 0000000000000000000000000000000000000000..299d20913c1a5a5ec0f0765e02669eead28e967a --- /dev/null +++ b/storage/storagefileiojstest/src/main/js/test/module_fileio/class_dir/listfile.test.js @@ -0,0 +1,317 @@ +/* + * 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 fileio_dir_listfile() { +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. + * @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(); + } + }); + + 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(); + } + }); + + 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(); + } + }); + + 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(); + } + }); + + 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); + } + }); + + 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_READDIRASYNC_0200 + * @tc.name fileio_test_readdir_async_002 + * @tc.desc Test readdirASync() interface. + * @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(); + } + }); + + 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(); + } + }); + + 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(); + } + }); + + 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(); + } + }); + + 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(); + } + }); + + 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/src/main/js/default/test/module_fileio/class_dir/read.test.js b/storage/storagefileiojstest/src/main/js/test/module_fileio/class_dir/read.test.js similarity index 99% rename from storage/storagefileiojstest/src/main/js/default/test/module_fileio/class_dir/read.test.js rename to storage/storagefileiojstest/src/main/js/test/module_fileio/class_dir/read.test.js index 9912e6d22b8109669c31a8946fabec060d2a6fed..ec8680071b604922f3250e5415b7f90a076cfe53 100644 --- a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/class_dir/read.test.js +++ b/storage/storagefileiojstest/src/main/js/test/module_fileio/class_dir/read.test.js @@ -18,6 +18,7 @@ import { describe, it, expect, } from '../../Common'; +export default function fileio_dir_read() { describe('fileio_dir_read', function () { /** @@ -677,4 +678,4 @@ describe('fileio_dir_read', function () { expect(null).assertFail(); } }); -}) \ No newline at end of file +})} diff --git a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/class_dirent/all.test.js b/storage/storagefileiojstest/src/main/js/test/module_fileio/class_dirent/all.test.js similarity index 98% rename from storage/storagefileiojstest/src/main/js/default/test/module_fileio/class_dirent/all.test.js rename to storage/storagefileiojstest/src/main/js/test/module_fileio/class_dirent/all.test.js index acf4b065f72b28c758d8eb7d4f70ed82fb0d2500..b85a926585dd286f0e03ccabdc2145d13f89833f 100644 --- a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/class_dirent/all.test.js +++ b/storage/storagefileiojstest/src/main/js/test/module_fileio/class_dirent/all.test.js @@ -18,6 +18,7 @@ import { describe, it, expect, } from '../../Common'; +export default function fileio_dirent() { describe('fileio_dirent', function () { /** @@ -85,16 +86,16 @@ describe('fileio_dirent', function () { }) /** - * @tc.number SUB_DF_FileIO_Dir_ReadSync_0000 - * @tc.name fileio_test_dirent_name_000 + * @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_000', 0, async function () { - let dpath = await nextFileName('fileio_test_dirent_name_000') + 'd'; + it('fileio_test_dirent_name_002', 0, async function () { + let dpath = await nextFileName('fileio_test_dirent_name_002') + 'd'; let fpath = dpath + '/f1'; try { @@ -109,7 +110,7 @@ describe('fileio_dirent', function () { expect(fileio.unlinkSync(fpath) == null).assertTrue(); expect(fileio.rmdirSync(dpath) == null).assertTrue(); } catch (e) { - console.log('fileio_test_dirent_name_000 has failed for ' + e); + console.log('fileio_test_dirent_name_002 has failed for ' + e); expect(null).assertFail(); } }) @@ -532,4 +533,4 @@ describe('fileio_dirent', function () { expect(fileio.rmdirSync(dpath) == null).assertTrue(); } }); -}); \ No newline at end of file +});} diff --git a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/class_stream/all.test.js b/storage/storagefileiojstest/src/main/js/test/module_fileio/class_stream/all.test.js similarity index 99% rename from storage/storagefileiojstest/src/main/js/default/test/module_fileio/class_stream/all.test.js rename to storage/storagefileiojstest/src/main/js/test/module_fileio/class_stream/all.test.js index bf1436209cd1ff80ca28ad5f09d0c114f1485562..588ed624189b765b930ff93574853bf6b5991b34 100644 --- a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/class_stream/all.test.js +++ b/storage/storagefileiojstest/src/main/js/test/module_fileio/class_stream/all.test.js @@ -18,6 +18,7 @@ import { describe, it, expect, } from '../../Common'; +export default function fileio_stream_1() { describe('fileio_stream_1', function () { /** @@ -299,4 +300,4 @@ describe('fileio_stream_1', function () { expect(null).assertFail(); } }); -}); \ No newline at end of file +});} diff --git a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/class_stream/close.test.js b/storage/storagefileiojstest/src/main/js/test/module_fileio/class_stream/close.test.js similarity index 98% rename from storage/storagefileiojstest/src/main/js/default/test/module_fileio/class_stream/close.test.js rename to storage/storagefileiojstest/src/main/js/test/module_fileio/class_stream/close.test.js index 47a5caea974fa013e29c8146eb37a5c40dc179a1..2affae101a372f8319d9603b02fbaceb47aa9f15 100644 --- a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/class_stream/close.test.js +++ b/storage/storagefileiojstest/src/main/js/test/module_fileio/class_stream/close.test.js @@ -18,6 +18,7 @@ import { describe, it, expect, } from '../../Common'; +export default function fileio_stream_close() { describe('fileio_stream_close', function () { /** @@ -121,4 +122,4 @@ describe('fileio_stream_close', function () { expect(null).assertFail(); } }); -}); \ No newline at end of file +});} diff --git a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/class_stream/flush.test.js b/storage/storagefileiojstest/src/main/js/test/module_fileio/class_stream/flush.test.js similarity index 98% rename from storage/storagefileiojstest/src/main/js/default/test/module_fileio/class_stream/flush.test.js rename to storage/storagefileiojstest/src/main/js/test/module_fileio/class_stream/flush.test.js index 03abff26907b8c686b1322c8e7d52966771c97c7..eb94d6305752eb81f1efffbcb10048109567c202 100644 --- a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/class_stream/flush.test.js +++ b/storage/storagefileiojstest/src/main/js/test/module_fileio/class_stream/flush.test.js @@ -18,6 +18,7 @@ import { describe, it, expect, } from '../../Common'; +export default function fileio_stream_flush() { describe('fileio_stream_flush', function () { /** @@ -130,3 +131,4 @@ describe('fileio_stream_flush', function () { }); }); +} diff --git a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/class_stream/read.test.js b/storage/storagefileiojstest/src/main/js/test/module_fileio/class_stream/read.test.js similarity index 99% rename from storage/storagefileiojstest/src/main/js/default/test/module_fileio/class_stream/read.test.js rename to storage/storagefileiojstest/src/main/js/test/module_fileio/class_stream/read.test.js index 5745b7b1e73794d4bb2667fffb935a0d458afd66..7a2772fa1c8e4c6d562817d4a3fbb0452ba113e6 100644 --- a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/class_stream/read.test.js +++ b/storage/storagefileiojstest/src/main/js/test/module_fileio/class_stream/read.test.js @@ -18,6 +18,7 @@ import { describe, it, expect, } from '../../Common'; +export default function fileio_stream_read() { describe('fileio_stream_read', function () { /** @@ -395,3 +396,4 @@ describe('fileio_stream_read', function () { } }); }); +} diff --git a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/class_stream/write.test.js b/storage/storagefileiojstest/src/main/js/test/module_fileio/class_stream/write.test.js similarity index 99% rename from storage/storagefileiojstest/src/main/js/default/test/module_fileio/class_stream/write.test.js rename to storage/storagefileiojstest/src/main/js/test/module_fileio/class_stream/write.test.js index f375f3b4bb44169ef0eb1e77ca78dc30b71e1c67..ba582824571411b27c2aa998c5a6278c37aa615b 100644 --- a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/class_stream/write.test.js +++ b/storage/storagefileiojstest/src/main/js/test/module_fileio/class_stream/write.test.js @@ -18,6 +18,7 @@ import { describe, it, expect, } from '../../Common'; +export default function fileio_stream_write() { describe('fileio_stream_write', function () { /** @@ -462,3 +463,4 @@ describe('fileio_stream_write', function () { } }); }); +} diff --git a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/class_watcher/createWatcher.test.js b/storage/storagefileiojstest/src/main/js/test/module_fileio/class_watcher/createWatcher.test.js similarity index 99% rename from storage/storagefileiojstest/src/main/js/default/test/module_fileio/class_watcher/createWatcher.test.js rename to storage/storagefileiojstest/src/main/js/test/module_fileio/class_watcher/createWatcher.test.js index 03eb874e6fac35b64c9d3a52a871c41807e7be8c..0823b6f6ac3da96ccbc739e049bf24eb261dab44 100644 --- a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/class_watcher/createWatcher.test.js +++ b/storage/storagefileiojstest/src/main/js/test/module_fileio/class_watcher/createWatcher.test.js @@ -18,6 +18,7 @@ import { describe, it, expect, } from '../../Common'; +export default function fileio_createWatcher() { describe('fileio_createWatcher', function () { /** @@ -329,3 +330,4 @@ describe('fileio_createWatcher', function () { } }); }); +} diff --git a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/access.test.js b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/access.test.js similarity index 99% rename from storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/access.test.js rename to storage/storagefileiojstest/src/main/js/test/module_fileio/members/access.test.js index bcca536854fbfada8ffe5e7922b01e3421d7ac64..1bbe970e686fb0f416ea8fb38142670a873bbdf8 100644 --- a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/access.test.js +++ b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/access.test.js @@ -18,6 +18,7 @@ import { describe, it, expect, } from '../../Common'; +export default function fileio_access() { describe('fileio_access', function () { /** @@ -333,3 +334,4 @@ describe('fileio_access', function () { } }); }); +} diff --git a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/chmod.test.js b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/chmod.test.js similarity index 99% rename from storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/chmod.test.js rename to storage/storagefileiojstest/src/main/js/test/module_fileio/members/chmod.test.js index 914a11c96c7dcd4919f9f320e7a9de04b9976594..474332080e848166d59793b824c34152741ed18d 100644 --- a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/chmod.test.js +++ b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/chmod.test.js @@ -18,6 +18,7 @@ import { describe, it, expect, } from '../../Common'; +export default function fileio_chmod() { describe('fileio_chmod', function () { /** @@ -219,3 +220,4 @@ describe('fileio_chmod', function () { } }); }); +} diff --git a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/chown.test.js b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/chown.test.js similarity index 99% rename from storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/chown.test.js rename to storage/storagefileiojstest/src/main/js/test/module_fileio/members/chown.test.js index f2356211fe9f6e355957cd9cec18554c96ab3ca6..26aa88d191b497bb1f11cd0ccd8b402e3b2ac346 100644 --- a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/chown.test.js +++ b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/chown.test.js @@ -18,6 +18,7 @@ import { describe, it, expect, } from '../../Common'; +export default function fileio_chown() { describe('fileio_chown', function () { /** @@ -273,3 +274,4 @@ describe('fileio_chown', function () { } }); }); +} diff --git a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/close.test.js b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/close.test.js similarity index 99% rename from storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/close.test.js rename to storage/storagefileiojstest/src/main/js/test/module_fileio/members/close.test.js index dd1e4eb32b21205514b70f8183edc6380053e435..3a70810df6c5541bafe4ad0a4c2b7f6077e0a04f 100644 --- a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/close.test.js +++ b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/close.test.js @@ -18,6 +18,7 @@ import { describe, it, expect, nextFileName, prepareFile, FILE_CONTENT } from '../../Common'; +export default function fileio_close() { describe('fileio_close', function () { /** @@ -192,3 +193,4 @@ describe('fileio_close', function () { } }) }) +} diff --git a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/copyFile.test.js b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/copyFile.test.js similarity index 99% rename from storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/copyFile.test.js rename to storage/storagefileiojstest/src/main/js/test/module_fileio/members/copyFile.test.js index 2e8132a8a8cdfa3ff08cf27eda858b55afeaeb11..00886246cd0fc3bda6069a1e8bbd98b50e0f215e 100644 --- a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/copyFile.test.js +++ b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/copyFile.test.js @@ -18,6 +18,7 @@ import { describe, it, expect, } from '../../Common'; +export default function fileio_copyfile() { describe('fileio_copyfile', function () { /** @@ -275,3 +276,4 @@ describe('fileio_copyfile', function () { } }); }); +} diff --git a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/createStream.test.js b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/createStream.test.js similarity index 98% rename from storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/createStream.test.js rename to storage/storagefileiojstest/src/main/js/test/module_fileio/members/createStream.test.js index 3d5f0137a115eb6d0a904378e269fd1a7465e121..4a9889116dd0e7c21af2fa76963036139408d0ae 100644 --- a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/createStream.test.js +++ b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/createStream.test.js @@ -18,6 +18,7 @@ import { describe, it, expect, } from '../../Common'; +export default function fileio_createStream() { describe('fileio_createStream', function () { /** @@ -144,3 +145,4 @@ describe('fileio_createStream', function () { } }); }); +} diff --git a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/fchmod.test.js b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/fchmod.test.js similarity index 99% rename from storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/fchmod.test.js rename to storage/storagefileiojstest/src/main/js/test/module_fileio/members/fchmod.test.js index dc8748261dc7aad9ebd1c9b0d00b7ba1091f1749..ac57e43edb85eaf41307e0f446bec751900918a0 100644 --- a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/fchmod.test.js +++ b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/fchmod.test.js @@ -18,6 +18,7 @@ import { describe, it, expect, } from '../../Common'; +export default function fileio_fchmod() { describe('fileio_fchmod', function () { /** @@ -186,3 +187,4 @@ describe('fileio_fchmod', function () { } }); }); +} diff --git a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/fchown.test.js b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/fchown.test.js similarity index 99% rename from storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/fchown.test.js rename to storage/storagefileiojstest/src/main/js/test/module_fileio/members/fchown.test.js index 8f08c678db2ac29d797a446fd52b589ef07b6c31..1d0cfb2bb0b8d74ed1f35bf36424e8c1874b0948 100644 --- a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/fchown.test.js +++ b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/fchown.test.js @@ -18,6 +18,7 @@ import { describe, it, expect, } from '../../Common'; +export default function fileio_fchown() { describe('fileio_fchown', async function () { /** @@ -262,3 +263,4 @@ describe('fileio_fchown', async function () { } }); }); +} diff --git a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/fdatasync.test.js b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/fdatasync.test.js similarity index 98% rename from storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/fdatasync.test.js rename to storage/storagefileiojstest/src/main/js/test/module_fileio/members/fdatasync.test.js index b93ca90ec2e391a0cd86aa6bd2e0cd8ac3b5f77e..035a58d6aae54fe3f5cb93127ec8c1f802d829f3 100644 --- a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/fdatasync.test.js +++ b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/fdatasync.test.js @@ -18,6 +18,7 @@ import { describe, it, expect, } from '../../Common'; +export default function fileio_fdatasync() { describe('fileio_fdatasync', async function () { /** @@ -138,3 +139,4 @@ describe('fileio_fdatasync', async function () { } }); }); +} diff --git a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/fdopenStream.test.js b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/fdopenStream.test.js similarity index 82% rename from storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/fdopenStream.test.js rename to storage/storagefileiojstest/src/main/js/test/module_fileio/members/fdopenStream.test.js index f36c7f863e4ed3a704f25085ef823a61d469781b..b81cbc5508f1ec434084ee76346f8e60281818fb 100644 --- a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/fdopenStream.test.js +++ b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/fdopenStream.test.js @@ -18,6 +18,7 @@ import { describe, it, expect, } from '../../Common'; +export default function fileio_FdOpenStream() { describe('fileio_FdOpenStream', async function () { /** @@ -62,7 +63,7 @@ describe('fileio_FdOpenStream', async function () { let fd = -1; let mode = 'r+'; let fp = fileio.fdopenStreamSync(fd, mode); - expect(null).assertFail(); + throw new Error('Bad file descriptor'); } catch (e) { console.log('fileio_test_fdopenstream_sync_001 has failed for ' + e); } @@ -86,18 +87,12 @@ describe('fileio_FdOpenStream', async function () { let mode = 'r+'; let fp = await fileio.fdopenStream(fd, mode); fp.read(new ArrayBuffer(4096), {}, function (err, data) { - if (!err) { - expect(fp !== null).assertTrue(); - expect(fp.closeSync() == null).assertTrue(); - expect(data.bytesRead == FILE_CONTENT.length).assertTrue(); - } else { - console.log('Cannot read from the stream ' + err); - expect(null).assertFail(); - } - + expect(fp !== null).assertTrue(); + fp.closeSync(); + expect(data.bytesRead == FILE_CONTENT.length).assertTrue(); + fileio.unlinkSync(fpath); + done(); }) - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - done(); } catch (e) { console.log('fileio_test_fdopenstream_async_000 has failed for ' + e); expect(null).assertFail(); @@ -120,24 +115,19 @@ describe('fileio_FdOpenStream', async function () { let fd = fileio.openSync(fpath, 0o2); expect(isIntNum(fd)).assertTrue(); let mode = 'r+'; - fileio.fdopenStream(fd, mode, function (error, fp) { + fileio.fdopenStream(fd, mode, function (err, fp) { expect(fp !== null).assertTrue(); fp.read(new ArrayBuffer(4096), {}, function (err, data) { - if (!err) { - expect(fp !== null).assertTrue(); - expect(fp.closeSync() == null).assertTrue(); - expect(data.bytesRead == FILE_CONTENT.length).assertTrue(); - } else { - console.log('Cannot read from the stream ' + err); - expect(null).assertFail(); - } + expect(fp !== null).assertTrue(); + fp.closeSync(); + expect(data.bytesRead == FILE_CONTENT.length).assertTrue(); + fileio.unlinkSync(fpath); + done(); }) - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - done(); }) } catch (e) { - console.log('fileio_test_fdopenstream_async_001 has failed for ' + e); + console.info('fileio_test_fdopenstream_async_001 has failed for ' + e); expect(null).assertFail(); } }) -}) \ No newline at end of file +})} diff --git a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/fstat.test.js b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/fstat.test.js similarity index 99% rename from storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/fstat.test.js rename to storage/storagefileiojstest/src/main/js/test/module_fileio/members/fstat.test.js index aa399e3c452d80798763b75682cf969b186e7a49..d35f05243e0deb11566002f3f4bd529810c2454e 100644 --- a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/fstat.test.js +++ b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/fstat.test.js @@ -18,6 +18,7 @@ import { describe, it, expect, } from '../../Common'; +export default function fileio_stat_fstat() { describe('fileio_stat_fstat', function () { /** @@ -38,10 +39,10 @@ describe('fileio_stat_fstat', function () { expect(isIntNum(fd)).assertTrue(); let stat = fileio.fstatSync(fd); expect(stat !== null).assertTrue(); - expect(fileio.closeSync(fd) == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); + fileio.closeSync(fd); + fileio.unlinkSync(fpath); } catch (e) { - console.log('fileio_stat_fstat_sync_000 has failed for ' + e); + console.info('fileio_stat_fstat_sync_000 has failed for ' + e); expect(null).assertFail(); } }); @@ -1754,4 +1755,4 @@ describe('fileio_stat_fstat', function () { done(); }); -}); \ No newline at end of file +});} diff --git a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/fsync.test.js b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/fsync.test.js similarity index 98% rename from storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/fsync.test.js rename to storage/storagefileiojstest/src/main/js/test/module_fileio/members/fsync.test.js index 7f6777b3f4c3406a429eaa5904a7e9126fe0401e..1a004d324bd1def1738777428f04b2d73ff98ebc 100644 --- a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/fsync.test.js +++ b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/fsync.test.js @@ -18,6 +18,7 @@ import { describe, it, expect, } from '../../Common'; +export default function fileio_stat_fsync() { describe('fileio_stat_fsync', function () { /** @@ -132,4 +133,4 @@ describe('fileio_stat_fsync', function () { done(); } }) -}) \ No newline at end of file +})} diff --git a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/ftruncate.test.js b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/ftruncate.test.js similarity index 99% rename from storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/ftruncate.test.js rename to storage/storagefileiojstest/src/main/js/test/module_fileio/members/ftruncate.test.js index 2cea2ada9ac0f6188fc3a149840823b5863f0328..8d655fcf54dcf8478de1255a28ac07c6b0a51713 100644 --- a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/ftruncate.test.js +++ b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/ftruncate.test.js @@ -18,6 +18,7 @@ import { describe, it, expect, } from '../../Common'; +export default function fileio_ftruncate() { describe('fileio_ftruncate', function () { /** @@ -179,4 +180,4 @@ describe('fileio_ftruncate', function () { expect(!!e).assertTrue(); } }); -}); \ No newline at end of file +});} diff --git a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/hash.test.js b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/hash.test.js similarity index 97% rename from storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/hash.test.js rename to storage/storagefileiojstest/src/main/js/test/module_fileio/members/hash.test.js index 27968ae243b2c514f09a0c95aba9bbe05e863022..66045e4f0dc3f72bbff4c651f082c0b5c2ab7f21 100644 --- a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/hash.test.js +++ b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/hash.test.js @@ -18,6 +18,7 @@ import { describe, it, expect, } from '../../Common'; +export default function fileio_hash() { describe('fileio_hash', function () { /** @@ -44,4 +45,4 @@ describe('fileio_hash', function () { expect(null).assertFail(); } }); -}); \ No newline at end of file +});} diff --git a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/lchown.test.js b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/lchown.test.js similarity index 99% rename from storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/lchown.test.js rename to storage/storagefileiojstest/src/main/js/test/module_fileio/members/lchown.test.js index 715b7da0da1be1dd956c72186ee05c4f10772db3..490ff08a2143bef427d7d9f2686638944e4fb7af 100644 --- a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/lchown.test.js +++ b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/lchown.test.js @@ -18,6 +18,7 @@ import { describe, it, expect, } from '../../Common'; +export default function fileio_lchown() { describe('fileio_lchown', function () { /** @@ -296,3 +297,4 @@ describe('fileio_lchown', function () { } }); }); +} diff --git a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/lseek.test.js b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/lseek.test.js similarity index 98% rename from storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/lseek.test.js rename to storage/storagefileiojstest/src/main/js/test/module_fileio/members/lseek.test.js index 61c543466dc751bc957e5da4301c9509281a521e..d06508000bac872d7dbd2b8704c069b4418bfa0e 100644 --- a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/lseek.test.js +++ b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/lseek.test.js @@ -18,6 +18,7 @@ import { describe, it, expect, } from '../../Common'; +export default function fileio_lseek() { describe('fileio_lseek', function () { /** @@ -120,3 +121,4 @@ describe('fileio_lseek', function () { } }); }); +} diff --git a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/lstat.test.js b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/lstat.test.js similarity index 99% rename from storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/lstat.test.js rename to storage/storagefileiojstest/src/main/js/test/module_fileio/members/lstat.test.js index b2e08c7536381cc61f86274066999f8e9c863378..ca213246439d711039fc8b14ae50ff59d42efac7 100644 --- a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/lstat.test.js +++ b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/lstat.test.js @@ -18,6 +18,7 @@ import { describe, it, expect, } from '../../Common'; +export default function fileio_lstat() { describe('fileio_lstat', function () { /** @@ -1659,4 +1660,4 @@ describe('fileio_lstat', function () { } done(); }); -}); \ No newline at end of file +});} diff --git a/storage/storagefileiojstest/src/main/js/test/module_fileio/members/mkdir_rmdir.test.js b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/mkdir_rmdir.test.js new file mode 100644 index 0000000000000000000000000000000000000000..db156bd6d8089dabf8bf3175cf718b3bd1f8ae27 --- /dev/null +++ b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/mkdir_rmdir.test.js @@ -0,0 +1,202 @@ +/* + * 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 fileio_mkdir_rmdir() { +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_0010 + * @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_0020 + * @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_ASYNC_RMDIR_SYNC_0000 + * @tc.name fileio_mkdir_async_rmdir_sync_000 + * @tc.desc Test mkdirAsync() and rmdirSync() interfaces. + * @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_0010 + * @tc.name fileio_mkdir_async_rmdir_sync_001 + * @tc.desc Test mkdirAsync() and rmdirSync() interfaces. + * @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_0020 + * @tc.name fileio_mkdir_async_rmdir_sync_002 + * @tc.desc Test mkdirAsync() and rmdirSync() interfaces. + * @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_0030 + * @tc.name fileio_mkdir_async_rmdir_sync_003 + * @tc.desc Test mkdirAsync() and rmdirSync() interfaces. + * @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_0040 + * @tc.name fileio_mkdir_async_rmdir_sync_004 + * @tc.desc Test mkdirAsync() and interfaces. + * @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) { + done(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_MKDIR_ASYNC_RMDIR_SYNC_0050 + * @tc.name fileio_mkdir_async_rmdir_sync_005 + * @tc.desc Test mkdirAsync()interfaces. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_mkdir_async_rmdir_sync_005', 0, async function (done) { + try { + expect(await fileio.mkdir('/').indexOf('') > -1).assertTrue(); + expect(null).assertFail(); + } catch (e) { + done(); + } + }); +});} diff --git a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/mkdtemp.test.js b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/mkdtemp.test.js similarity index 98% rename from storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/mkdtemp.test.js rename to storage/storagefileiojstest/src/main/js/test/module_fileio/members/mkdtemp.test.js index 78ec9a44c53b37a7314c15becec6231e4cf0e599..841ce64388c2b4690fb815090dee3c0246f20647 100644 --- a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/mkdtemp.test.js +++ b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/mkdtemp.test.js @@ -15,6 +15,7 @@ import { fileio, nextFileName, describe, it, expect } from '../../Common'; +export default function fileio_mkdtemp() { describe('fileio_mkdtemp', function () { /** @@ -105,4 +106,4 @@ describe('fileio_mkdtemp', function () { expect(null).assertFail(); } }); -}); \ No newline at end of file +});} diff --git a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/open.test.js b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/open.test.js similarity index 99% rename from storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/open.test.js rename to storage/storagefileiojstest/src/main/js/test/module_fileio/members/open.test.js index 7e3e9d5a21403f021cea0c81fc00559c6fd51bc9..efd32a8a83d5559e7d7ff7e14e1c241567f4bbc0 100644 --- a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/open.test.js +++ b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/open.test.js @@ -18,6 +18,7 @@ import { describe, it, expect, } from '../../Common'; +export default function fileio_open() { describe('fileio_open', function () { /** @@ -339,3 +340,4 @@ describe('fileio_open', function () { } }); }); +} diff --git a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/open_close.test.js b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/open_close.test.js similarity index 98% rename from storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/open_close.test.js rename to storage/storagefileiojstest/src/main/js/test/module_fileio/members/open_close.test.js index 9e9c02d1eb9c3fa4d702a907568b81605f6c60f2..f4d569fe8d344367f27ab8304d3429d3117fa6df 100644 --- a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/open_close.test.js +++ b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/open_close.test.js @@ -18,6 +18,7 @@ import { describe, it, expect, } from '../../Common'; +export default function fileio_open_close() { describe('fileio_open_close', function () { /** @@ -140,4 +141,4 @@ describe('fileio_open_close', function () { console.log('fileio_close_sync_001 has failed for ' + e); } }); -}); \ No newline at end of file +});} diff --git a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/opendir_close.test.js b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/opendir_close.test.js similarity index 98% rename from storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/opendir_close.test.js rename to storage/storagefileiojstest/src/main/js/test/module_fileio/members/opendir_close.test.js index ca6b2b2ab872d26924a753845f142a31885259c6..454fd8e3c2dbb82c94ef729be576b04f81d03496 100644 --- a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/opendir_close.test.js +++ b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/opendir_close.test.js @@ -15,6 +15,7 @@ import { fileio, nextFileName, describe, it, expect } from '../../Common'; +export default function fileio_dir_opendir_close() { describe('fileio_dir_opendir_close', function () { /** @@ -112,3 +113,4 @@ describe('fileio_dir_opendir_close', function () { } }); }); +} diff --git a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/posix_fallocate.test.js b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/posix_fallocate.test.js similarity index 98% rename from storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/posix_fallocate.test.js rename to storage/storagefileiojstest/src/main/js/test/module_fileio/members/posix_fallocate.test.js index 4d4cc80da6d0ae4b20ed83400dbf7e083efd2a77..2ff150657b782e238c57571f11a7b054d2f14dde 100644 --- a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/posix_fallocate.test.js +++ b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/posix_fallocate.test.js @@ -18,6 +18,7 @@ import { describe, it, expect, } from '../../Common'; +export default function fileio_posix_fallocate() { describe('fileio_posix_fallocate', function () { /** @@ -95,3 +96,4 @@ describe('fileio_posix_fallocate', function () { } }); }); +} diff --git a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/read.test.js b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/read.test.js similarity index 99% rename from storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/read.test.js rename to storage/storagefileiojstest/src/main/js/test/module_fileio/members/read.test.js index 37d2976849c07e241c15946447891ac077f3ee28..36548422a0e4278c801f747cca1214a8ec397317 100644 --- a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/read.test.js +++ b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/read.test.js @@ -18,6 +18,7 @@ import { describe, it, expect, } from '../../Common'; +export default function fileio_read() { describe('fileio_read', function () { /** @@ -457,8 +458,7 @@ describe('fileio_read', function () { await fileio.read(fd, new ArrayBuffer(4096), { offset: invalidOffset, }); - expect(null).assertFail(); - done(); + throw new Error('invalid offset'); } catch (e) { expect(fileio.closeSync(fd) == null).assertTrue(); expect(fileio.unlinkSync(fpath) == null).assertTrue(); @@ -546,3 +546,4 @@ describe('fileio_read', function () { } }); }); +} diff --git a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/readtext.test.js b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/readtext.test.js similarity index 98% rename from storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/readtext.test.js rename to storage/storagefileiojstest/src/main/js/test/module_fileio/members/readtext.test.js index 9f30bd64462603ea40db3ae77a35431124146ac5..957ae56860dd367fc0d0fe5e1b2923620fea9f90 100644 --- a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/readtext.test.js +++ b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/readtext.test.js @@ -18,6 +18,7 @@ import { describe, it, expect, } from '../../Common'; +export default function fileio_readtext() { describe('fileio_readtext', function () { /** @@ -148,7 +149,7 @@ describe('fileio_readtext', function () { fileio.readTextSync(fpath, { length: invalidLength, }); - expect(null).assertFail(); + throw new Error('invalid length'); } catch (e) { expect(fileio.unlinkSync(fpath) == null).assertTrue(); } @@ -242,3 +243,4 @@ describe('fileio_readtext', function () { } }); }); +} diff --git a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/rename.test.js b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/rename.test.js similarity index 98% rename from storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/rename.test.js rename to storage/storagefileiojstest/src/main/js/test/module_fileio/members/rename.test.js index 73065f4544b67a810bc3acc94339c208aa166415..181862d537ef4b3413853508106817f9fd56618a 100644 --- a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/rename.test.js +++ b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/rename.test.js @@ -17,6 +17,7 @@ import { fileio, FILE_CONTENT, prepareFile, nextFileName, describe, it, expect, } from '../../Common'; +export default function fileio_rename() { describe('fileio_rename', function () { /** @@ -105,4 +106,4 @@ describe('fileio_rename', function () { expect(null).assertFail(); } }); -}); \ No newline at end of file +});} diff --git a/storage/storagefileiojstest/src/main/js/test/module_fileio/members/rmdir.test.js b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/rmdir.test.js new file mode 100644 index 0000000000000000000000000000000000000000..d0970c0a6d6da868f2f0b7dbba71d06a871e99ae --- /dev/null +++ b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/rmdir.test.js @@ -0,0 +1,381 @@ +/* + * 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 fileio_rmdir() { +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. Invalid path. + * @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('fileio_test_rmdir_sync_003') + 'd'; + + try { + fileio.rmdirSync(dpath); + } catch (err) { + console.info('fileio_test_rmdir_sync_003 has failed for ' + err); + expect(isInclude(err.message, 'No such file or directory')).assertTrue(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_RMDIR_SYNC_0400 + * @tc.name fileio_test_rmdir_sync_004 + * @tc.desc Test rmdirSync() interface. No parameters. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_rmdir_sync_004', 0, async function () { + try { + fileio.rmdirSync(); + } catch (err) { + console.info('fileio_test_rmdir_sync_004 has failed for ' + err); + expect(isInclude(err.message, 'Number of arguments unmatched')).assertTrue(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_RMDIR_SYNC_0500 + * @tc.name fileio_test_rmdir_sync_005 + * @tc.desc Test rmdirSync() interface. Invalid path. + * @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, 'No such file or directory')).assertTrue(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_RMDIR_SYNC_0600 + * @tc.name fileio_test_rmdir_sync_006 + * @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_006', 0, async function () { + let fpath = await nextFileName('fileio_test_rmdir_sync_006'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + fileio.rmdirSync(fpath); + } catch (err) { + console.info('fileio_test_rmdir_sync_006 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_001'; + let ffpath = dpath + '/rmdir_async_001_1'; + let ddpath = dpath + '/rmdir_async_001_1d'; + let fffpath = ddpath + '/rmdir_async_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.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 rmdir() interface. Invalid path. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_rmdir_async_004', 0, async function (done) { + let dpath = await nextFileName('fileio_test_rmdir_async_004') + 'd'; + + try { + await fileio.rmdir(dpath); + } catch (err) { + console.info('fileio_test_rmdir_async_004 has failed for ' + err); + expect(isInclude(err.message, 'No such file or directory')).assertTrue(); + done(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_RMDIR_ASYNC_0500 + * @tc.name fileio_test_rmdir_async_005 + * @tc.desc Test rmdir() interface. Parameter mismatch. + * @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 { + fileio.rmdir(dpath, '', function() { + }); + } catch (err) { + console.info('fileio_test_rmdir_async_005 has failed for ' + err); + expect(isInclude(err.message, 'Number of arguments unmatched')).assertTrue(); + done(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_RMDIR_ASYNC_0600 + * @tc.name fileio_test_rmdir_async_006 + * @tc.desc Test rmdir() interface. Invalid path. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_rmdir_async_006', 0, async function (done) { + try { + await fileio.rmdir(''); + } catch (err) { + console.info('fileio_test_rmdir_async_006 has failed for ' + err); + expect(isInclude(err.message, 'No such file or directory')).assertTrue(); + done(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_RMDIR_ASYNC_0700 + * @tc.name fileio_test_rmdir_async_007 + * @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_007', 0, async function (done) { + let fpath = await nextFileName('fileio_test_rmdir_async_007'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + await fileio.rmdir(fpath); + } catch (err) { + console.info('fileio_test_rmdir_async_007 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/src/main/js/default/test/module_fileio/members/stat.test.js b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/stat.test.js similarity index 99% rename from storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/stat.test.js rename to storage/storagefileiojstest/src/main/js/test/module_fileio/members/stat.test.js index 313b5c40f852520b0742b2993273ac5c4b7908b7..c756e3b96ed71dc0098977612984c7f0b812a1df 100644 --- a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/stat.test.js +++ b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/stat.test.js @@ -18,6 +18,7 @@ import { describe, it, expect, } from '../../Common'; +export default function fileio_stat() { describe('fileio_stat', function () { /** @@ -1643,4 +1644,4 @@ describe('fileio_stat', function () { } done(); }); -}); \ No newline at end of file +});} diff --git a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/symlink.test.js b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/symlink.test.js similarity index 98% rename from storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/symlink.test.js rename to storage/storagefileiojstest/src/main/js/test/module_fileio/members/symlink.test.js index 9368a8c8a12df4c2409cd7fc9b80abbd15c5f0f7..821e7bb35c8c0ecb1d0c9cd0bfb4d467539749ee 100644 --- a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/symlink.test.js +++ b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/symlink.test.js @@ -18,6 +18,7 @@ import { describe, it, expect, } from '../../Common'; +export default function fileio_symlink() { describe('fileio_symlink', function () { /** @@ -97,3 +98,4 @@ describe('fileio_symlink', function () { } }); }); +} diff --git a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/truncate.test.js b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/truncate.test.js similarity index 99% rename from storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/truncate.test.js rename to storage/storagefileiojstest/src/main/js/test/module_fileio/members/truncate.test.js index d14750f498d5add3032251d0af625191901be1ae..8def7bec86df141f289d5cc0f2df43c424dcaab7 100644 --- a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/truncate.test.js +++ b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/truncate.test.js @@ -18,6 +18,7 @@ import { describe, it, expect, } from '../../Common'; +export default function fileio_truncate() { describe('fileio_truncate', function () { /** @@ -170,3 +171,4 @@ describe('fileio_truncate', function () { } }); }); +} diff --git a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/unlink.test.js b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/unlink.test.js similarity index 99% rename from storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/unlink.test.js rename to storage/storagefileiojstest/src/main/js/test/module_fileio/members/unlink.test.js index 09574790513c079497224c66658e2bbb5e2061a1..70661ba28c3dde508f52a049251a857f289d0f42 100644 --- a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/unlink.test.js +++ b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/unlink.test.js @@ -18,6 +18,7 @@ import { describe, it, expect, } from '../../Common'; +export default function fileio_unlink() { describe('fileio_unlink', function () { /** @@ -171,3 +172,4 @@ describe('fileio_unlink', function () { } }); }); +} diff --git a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/write.test.js b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/write.test.js similarity index 99% rename from storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/write.test.js rename to storage/storagefileiojstest/src/main/js/test/module_fileio/members/write.test.js index 5ddbc78849cc6b9d9602acc761aadcfcbb31e540..a0487d7462e3fbcc41dda766c53a7f304dbdb43c 100644 --- a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/write.test.js +++ b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/write.test.js @@ -18,6 +18,7 @@ import { describe, it, expect, } from '../../Common'; +export default function fileio_write() { describe('fileio_write', function () { /** @@ -587,3 +588,4 @@ describe('fileio_write', function () { } }); }); +} diff --git a/storage/storagefileiojstest/src/main/resources/base/element/string.json b/storage/storagefileiojstest/src/main/resources/base/element/string.json index 6fb8909313d1424e4ce3c0e4ecfe10a1075f7bbf..12e97063fc3e434d85e81eaa9d8ccc64904b7e06 100644 --- a/storage/storagefileiojstest/src/main/resources/base/element/string.json +++ b/storage/storagefileiojstest/src/main/resources/base/element/string.json @@ -2,11 +2,27 @@ "string": [ { "name": "app_name", - "value": "Storagefileiojstest" + "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" } ] -} \ No newline at end of file +} diff --git a/storage/storagefilejstest/BUILD.gn b/storage/storagefilejstest/BUILD.gn index ef78aba8d6458e3534cd967837ced38903c4eae7..d6d439a312951198bad39cc82dc93275d70571c6 100644 --- a/storage/storagefilejstest/BUILD.gn +++ b/storage/storagefilejstest/BUILD.gn @@ -25,7 +25,9 @@ ohos_js_hap_suite("storagefile_js_test") { part_name = "xts_acts" } ohos_js_assets("storagefile_js_assets") { - source_dir = "./src/main/js/default" + js2abc = true + hap_profile = "./src/main/config.json" + source_dir = "./src/main/js" } ohos_resources("storagefile_js_resources") { sources = [ "./src/main/resources" ] diff --git a/storage/storagefilejstest/Test.json b/storage/storagefilejstest/Test.json index 02aef3b4c95b9418fe9e37eeffb0ef6cbbe6857a..6db12c331959d306ecba01a6808e7c119a61e505 100644 --- a/storage/storagefilejstest/Test.json +++ b/storage/storagefilejstest/Test.json @@ -1,16 +1,15 @@ { "description": "Configuration for storage file Tests", "driver": { - "type": "JSUnitTest", + "type": "OHJSUnitTest", "test-timeout": "600000", - "package": "ohos.acts.storage.file", - "shell-timeout": "60000" + "shell-timeout": "600000", + "bundle-name": "ohos.acts.storage.file", + "package-name": "ohos.acts.storage.file" }, "kits": [ { - "test-file-name": [ - "ActsStorageFileJSTest.hap" - ], + "test-file-name": ["ActsStorageFileJSTest.hap"], "type": "AppInstallKit", "cleanup-apps": true } diff --git a/storage/storagefilejstest/src/main/config.json b/storage/storagefilejstest/src/main/config.json index 3ec429b58232870071c1eb6d46419b09fe132c65..7c1aca40928e0a126c376df08427fe570088a63f 100644 --- a/storage/storagefilejstest/src/main/config.json +++ b/storage/storagefilejstest/src/main/config.json @@ -1,61 +1,94 @@ { - "app": { - "bundleName": "ohos.acts.storage.file", - "vendor": "example", - "version": { - "code": 1000000, - "name": "1.0.0" - }, - "apiVersion": { - "compatible": 4, - "target": 5 - } - }, - "deviceConfig": {}, - "module": { - "package": "ohos.acts.storage.file", - "name": ".MyApplication", - "deviceType": [ - "phone" - ], - "distro": { - "deliveryWithInstall": true, - "moduleName": "entry", - "moduleType": "entry", - "installationFree": true + "app": { + "bundleName": "ohos.acts.storage.file", + "vendor": "example", + "version": { + "code": 1000000, + "name": "1.0.0" + }, + "apiVersion": { + "compatible": 4, + "target": 5 + } }, - "abilities": [ - { - "skills": [ - { - "entities": [ - "entity.system.home" - ], - "actions": [ - "action.system.home" - ] - } + "deviceConfig": {}, + "module": { + "package": "ohos.acts.storage.file", + "name": ".entry", + "deviceType": [ + "phone" ], - "name": "ohos.acts.storage.file.MainAbility", - "icon": "$media:icon", - "description": "$string:mainability_description", - "label": "$string:app_name", - "type": "page", - "launchType": "standard", - "visible": true - } - ], - "js": [ - { - "pages": [ - "pages/index/index" + "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" + } ], - "name": "default", - "window": { - "designWidth": 720, - "autoDesignWidth": false - } - } - ] - } + "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/storagefilejstest/src/main/js/default/app.js b/storage/storagefilejstest/src/main/js/MainAbility/app.js similarity index 81% rename from storage/storagefilejstest/src/main/js/default/app.js rename to storage/storagefilejstest/src/main/js/MainAbility/app.js index 60ee141c8dbd251c763b7b74552b5a133a774d6a..38b923e9598eb7b023ac98bef564fedd06a081f7 100644 --- a/storage/storagefilejstest/src/main/js/default/app.js +++ b/storage/storagefilejstest/src/main/js/MainAbility/app.js @@ -15,9 +15,9 @@ export default { onCreate() { - console.info('ohos.acts.distributeddatamgr.distributedfile onCreate'); + console.info('ohos.acts.storage.file onCreate'); }, onDestroy() { - console.info('ohos.acts.distributeddatamgr.distributedfile onCreate'); + console.info('ohos.acts.storage.file onDestroy'); } }; diff --git a/storage/storagefilejstest/src/main/js/default/i18n/en-US.json b/storage/storagefilejstest/src/main/js/MainAbility/i18n/en-US.json similarity index 100% rename from storage/storagefilejstest/src/main/js/default/i18n/en-US.json rename to storage/storagefilejstest/src/main/js/MainAbility/i18n/en-US.json diff --git a/storage/storagefilejstest/src/main/js/default/i18n/zh-CN.json b/storage/storagefilejstest/src/main/js/MainAbility/i18n/zh-CN.json similarity index 100% rename from storage/storagefilejstest/src/main/js/default/i18n/zh-CN.json rename to storage/storagefilejstest/src/main/js/MainAbility/i18n/zh-CN.json diff --git a/storage/storagefilejstest/src/main/js/default/pages/index/index.css b/storage/storagefilejstest/src/main/js/MainAbility/pages/index/index.css similarity index 100% rename from storage/storagefilejstest/src/main/js/default/pages/index/index.css rename to storage/storagefilejstest/src/main/js/MainAbility/pages/index/index.css diff --git a/storage/storagefilejstest/src/main/js/MainAbility/pages/index/index.hml b/storage/storagefilejstest/src/main/js/MainAbility/pages/index/index.hml new file mode 100644 index 0000000000000000000000000000000000000000..f64b040a5ae394dbaa5e185e1ecd4f4556b92184 --- /dev/null +++ b/storage/storagefilejstest/src/main/js/MainAbility/pages/index/index.hml @@ -0,0 +1,5 @@ +
+ + {{ $t('strings.hello') }} {{ title }} + +
diff --git a/storage/storagefilejstest/src/main/js/default/pages/index/index.js b/storage/storagefilejstest/src/main/js/MainAbility/pages/index/index.js similarity index 77% rename from storage/storagefilejstest/src/main/js/default/pages/index/index.js rename to storage/storagefilejstest/src/main/js/MainAbility/pages/index/index.js index 61921cf3ba7d0a16a9c2edb9b9f04c1fb69a6333..6a9118dbb96efe627c20c435fdc1286f5d8611bf 100644 --- a/storage/storagefilejstest/src/main/js/default/pages/index/index.js +++ b/storage/storagefilejstest/src/main/js/MainAbility/pages/index/index.js @@ -15,26 +15,19 @@ import app from '@system.app' -import {Core} from 'deccjsunit/index' const injectRef = Object.getPrototypeOf(global) || global injectRef.regeneratorRuntime = require('@babel/runtime/regenerator') export default { - data: { - title: '' + data: { + title: '' }, onInit() { this.title = this.$t('strings.world'); }, onShow() { console.info('onShow finish') - const core = Core.getInstance() - core.init() - const configService = core.getDefaultService('config') - configService.setConfig(this) - require('../../test/List.test') - core.execute() }, onReady() { }, diff --git a/storage/storagefilejstest/src/main/js/TestAbility/app.js b/storage/storagefilejstest/src/main/js/TestAbility/app.js new file mode 100644 index 0000000000000000000000000000000000000000..d5ee271df29e516d1c8929054283e5f2bf5c981c --- /dev/null +++ b/storage/storagefilejstest/src/main/js/TestAbility/app.js @@ -0,0 +1,31 @@ +/* + * 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/storagefilejstest/src/main/js/TestAbility/i18n/en-US.json b/storage/storagefilejstest/src/main/js/TestAbility/i18n/en-US.json new file mode 100644 index 0000000000000000000000000000000000000000..55561b83737c3c31d082fbfa11e5fc987a351104 --- /dev/null +++ b/storage/storagefilejstest/src/main/js/TestAbility/i18n/en-US.json @@ -0,0 +1,8 @@ +{ + "strings": { + "hello": "Hello", + "world": "World" + }, + "Files": { + } +} \ No newline at end of file diff --git a/storage/storagefilejstest/src/main/js/TestAbility/i18n/zh-CN.json b/storage/storagefilejstest/src/main/js/TestAbility/i18n/zh-CN.json new file mode 100644 index 0000000000000000000000000000000000000000..cce1af06761a42add0cac1a0567aa3237eda8cb4 --- /dev/null +++ b/storage/storagefilejstest/src/main/js/TestAbility/i18n/zh-CN.json @@ -0,0 +1,8 @@ +{ + "strings": { + "hello": "您好", + "world": "世界" + }, + "Files": { + } +} \ No newline at end of file diff --git a/storage/storagefilejstest/src/main/js/TestAbility/pages/index/index.css b/storage/storagefilejstest/src/main/js/TestAbility/pages/index/index.css new file mode 100644 index 0000000000000000000000000000000000000000..b21c92c6290ea747bd891e2ab673721afc5521ed --- /dev/null +++ b/storage/storagefilejstest/src/main/js/TestAbility/pages/index/index.css @@ -0,0 +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; + } +} \ No newline at end of file diff --git a/storage/storagefilejstest/src/main/js/TestAbility/pages/index/index.hml b/storage/storagefilejstest/src/main/js/TestAbility/pages/index/index.hml new file mode 100644 index 0000000000000000000000000000000000000000..f64b040a5ae394dbaa5e185e1ecd4f4556b92184 --- /dev/null +++ b/storage/storagefilejstest/src/main/js/TestAbility/pages/index/index.hml @@ -0,0 +1,5 @@ +
+ + {{ $t('strings.hello') }} {{ title }} + +
diff --git a/storage/storagefilejstest/src/main/js/TestAbility/pages/index/index.js b/storage/storagefilejstest/src/main/js/TestAbility/pages/index/index.js new file mode 100644 index 0000000000000000000000000000000000000000..d94b75c085fa1c16a0b2721609b18c57a7295476 --- /dev/null +++ b/storage/storagefilejstest/src/main/js/TestAbility/pages/index/index.js @@ -0,0 +1,26 @@ +/* + * 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. + */ + +export default { + data: { + title: "" + }, + onInit() { + this.title = this.$t('strings.world'); + } +} + + + diff --git a/storage/storagefilejstest/src/main/js/TestRunner/OpenHarmonyTestRunner.js b/storage/storagefilejstest/src/main/js/TestRunner/OpenHarmonyTestRunner.js new file mode 100644 index 0000000000000000000000000000000000000000..b9e78ce7cf73f1ade6ba52a408a44e33f5430f0d --- /dev/null +++ b/storage/storagefilejstest/src/main/js/TestRunner/OpenHarmonyTestRunner.js @@ -0,0 +1,59 @@ +/* + * 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/storagefilejstest/src/main/js/default/test/Common.js b/storage/storagefilejstest/src/main/js/test/Common.js similarity index 98% rename from storage/storagefilejstest/src/main/js/default/test/Common.js rename to storage/storagefilejstest/src/main/js/test/Common.js index 0acf9a977d46ee0ff5261daf9867ef4eeefcf5e3..e5085412f78440b882f79b7fdff8cb1bd3b39ac0 100644 --- a/storage/storagefilejstest/src/main/js/default/test/Common.js +++ b/storage/storagefilejstest/src/main/js/test/Common.js @@ -21,7 +21,7 @@ export const FILE_CONTENT = 'hello world'; import { describe, it, expect } -from 'deccjsunit/index' +from '@ohos/hypium' export function prepareFile(fpath, content) { try { diff --git a/storage/storagefilejstest/src/main/js/default/test/File.test.js b/storage/storagefilejstest/src/main/js/test/File.test.js similarity index 73% rename from storage/storagefilejstest/src/main/js/default/test/File.test.js rename to storage/storagefilejstest/src/main/js/test/File.test.js index fbf9b85c0f6e5a9878088d91522cf78b692afcb5..9c8614ddb48a8d0120b5d4fdcff0c1060d33615b 100644 --- a/storage/storagefilejstest/src/main/js/default/test/File.test.js +++ b/storage/storagefilejstest/src/main/js/test/File.test.js @@ -20,7 +20,7 @@ import { it, expect } -from 'deccjsunit/index' +from '@ohos/hypium' import { FILE_CONTENT, prepareFile, @@ -33,6 +33,7 @@ import { } from './Common' +export default function fileTest() { describe('fileTest', function () { /** @@ -67,24 +68,23 @@ describe('fileTest', function () { uri: 'internal://cache/File_Delete_002', success: function () { console.info('File_Delete_002 call mkdir success.'); - done(); + file.delete({ + uri: 'internal://cache/File_Delete_002', + success: function () { + console.info('File_Delete_002 call delete success.'); + done(); + }, + fail: function (data, code) { + console.info('File_Delete_002 call delete fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); }, fail: function (data, code) { console.info('File_Delete_002 call mkdir fail, code: ' + code + ', data: ' + data); expect(null).assertFail(); }, }); - file.delete({ - uri: 'internal://cache/File_Delete_002', - success: function () { - console.info('File_Delete_002 call delete success.'); - done(); - }, - fail: function (data, code) { - console.info('File_Delete_002 call delete fail, code: ' + code + ', data: ' + data); - expect(null).assertFail(); - }, - }); }); /** @@ -116,7 +116,7 @@ describe('fileTest', function () { it('File_Delete_004', 0, async function (done) { let dpath = await fileName('File_Delete_004'); let fpath = dpath + '/File_Delete_004'; - expect(fileio.mkdirSync(dpath) !== null).assertTrue(); + fileio.mkdirSync(dpath); expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); file.delete({ uri: 'internal://app/File_Delete_004', @@ -192,24 +192,23 @@ describe('fileTest', function () { text: 'test', success: function () { console.info('File_Delete_007 call writeText success'); - done(); + file.delete({ + uri: 'internal://cache/File_Delete_007', + success: function () { + console.info('File_Delete_007 call delete success'); + done(); + }, + fail: function (data, code) { + console.info('File_Delete_007 call delete fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); }, fail: function (data, code) { console.info('File_Delete_007 call writeText fail, code: ' + code + ', data: ' + data); expect(null).assertFail(); }, }); - file.delete({ - uri: 'internal://cache/File_Delete_007', - success: function () { - console.info('File_Delete_007 call delete success'); - done(); - }, - fail: function (data, code) { - console.info('File_Delete_007 call delete fail, code: ' + code + ', data: ' + data); - expect(null).assertFail(); - }, - }); }); /** @@ -223,27 +222,26 @@ describe('fileTest', function () { text: 'Text that just for test.', success: function () { console.info('File_Delete_008 call writeText success'); - done(); + file.delete({ + uri: 'internal://cache/../cache/File_Delete_008', + success: function () { + console.info('File_Delete_008 call delete success'); + done(); + }, + fail: function (data, code) { + console.info('File_Delete_008 call delete fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + complete: function () { + console.info('delete completed'); + } + }); }, fail: function (data, code) { console.info('File_Delete_008 call writeText fail, code: ' + code + ', data: ' + data); expect(null).assertFail(); }, }); - file.delete({ - uri: 'internal://cache/../cache/File_Delete_008', - success: function () { - console.info('File_Delete_008 call delete success'); - done(); - }, - fail: function (data, code) { - console.info('File_Delete_008 call delete fail, code: ' + code + ', data: ' + data); - expect(null).assertFail(); - }, - complete: function () { - console.info('delete completed'); - } - }); }); /** @@ -257,35 +255,33 @@ describe('fileTest', function () { text: 'sawyerwang.', success: function () { console.info('File_writeText_001 call writeText success'); - done(); + file.readText({ + uri: 'internal://cache/File_writeText_001', + success: function (data) { + console.info('File_writeText_001 call read success. Content: ' ); + file.delete({ + uri: 'internal://cache/File_writeText_001', + success: function () { + console.info('File_writeText_001 call delete success'); + done(); + }, + fail: function (data, code) { + console.info('File_writeText_001 call delete fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + }, + fail: function (data, code) { + console.info('File_writeText_001 call read fail , code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); }, fail: function (data, code) { console.info('File_writeText_001 call writeText fail , code: ' + code + ', data: ' + data); expect(null).assertFail(); }, }); - file.readText({ - uri: 'internal://cache/File_writeText_001', - success: function (data) { - console.info('File_writeText_001 call read success. Content: ' ); - done(); - }, - fail: function (data, code) { - console.info('File_writeText_001 call read fail , code: ' + code + ', data: ' + data); - expect(null).assertFail(); - }, - }); - file.delete({ - uri: 'internal://cache/File_writeText_001', - success: function () { - console.info('File_writeText_001 call delete success'); - done(); - }, - fail: function (data, code) { - console.info('File_writeText_001 call delete fail, code: ' + code + ', data: ' + data); - expect(null).assertFail(); - }, - }); }); /** @@ -355,35 +351,33 @@ describe('fileTest', function () { text: txt, success: function () { console.info('File_writeText_003 call writeText success.'); - done(); + file.readText({ + uri: 'internal://cache/File_writeText_003', + success: function (data) { + console.info('File_writeText_003 call read success. Content: ' ); + file.delete({ + uri: 'internal://cache/File_writeText_003', + success: function () { + console.info('File_writeText_003 call delete success'); + done(); + }, + fail: function (data, code) { + console.info('File_writeText_003 call delete fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + }, + fail: function (data, code) { + console.info('File_writeText_003 call read fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); }, fail: function (data, code) { console.info('File_writeText_003 call writeText fail, code: ' + code + ', data: ' + data); expect(null).assertFail(); }, }); - file.readText({ - uri: 'internal://cache/File_writeText_003', - success: function (data) { - console.info('File_writeText_003 call read success. Content: ' ); - done(); - }, - fail: function (data, code) { - console.info('File_writeText_003 call read fail, code: ' + code + ', data: ' + data); - expect(null).assertFail(); - }, - }); - file.delete({ - uri: 'internal://cache/File_writeText_003', - success: function () { - console.info('File_writeText_003 call delete success'); - done(); - }, - fail: function (data, code) { - console.info('File_writeText_003 call delete fail, code: ' + code + ', data: ' + data); - expect(null).assertFail(); - }, - }); }); /** @@ -398,36 +392,34 @@ describe('fileTest', function () { encoding: 'UTF-8', success: function () { console.info('File_writeText_004 call writeText success.'); - done(); + file.readText({ + uri: 'internal://cache/File_writeText_004', + encoding: 'UTF-8', + success: function (data) { + console.info('File_writeText_004 call readText success. Content: ' ); + file.delete({ + uri: 'internal://cache/File_writeText_004', + success: function () { + console.info('File_writeText_004 delete success'); + done(); + }, + fail: function (data, code) { + console.info('File_writeText_004 delete fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + }, + fail: function (data, code) { + console.info('File_writeText_004 call readText fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); }, fail: function (data, code) { console.info('File_writeText_004 call writeText fail, code: ' + code + ', data: ' + data); expect(null).assertFail(); }, }); - file.readText({ - uri: 'internal://cache/File_writeText_004', - encoding: 'UTF-8', - success: function (data) { - console.info('File_writeText_004 call readText success. Content: ' ); - done(); - }, - fail: function (data, code) { - console.info('File_writeText_004 call readText fail, code: ' + code + ', data: ' + data); - expect(null).assertFail(); - }, - }); - file.delete({ - uri: 'internal://cache/File_writeText_004', - success: function () { - console.info('File_writeText_004 delete success'); - done(); - }, - fail: function (data, code) { - console.info('File_writeText_004 delete , code: ' + code + ', data: ' + data); - expect(null).assertFail(); - }, - }); }); /** @@ -496,35 +488,33 @@ describe('fileTest', function () { text: 'hello', success: function () { console.info('File_writeText_006 call writeText success.'); - done(); + file.readText({ + uri: 'internal://cache/File_writeText_006', + success: function (data) { + console.info('File_writeText_006 call read success ' ); + file.delete({ + uri: 'internal://cache/File_writeText_006', + success: function () { + console.info('File_writeText_006 delete success'); + done(); + }, + fail: function (data, code) { + console.info('File_writeText_006 delete fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + }, + fail: function (data, code) { + console.info('File_writeText_006 call readText fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); }, fail: function (data, code) { console.info('File_writeText_006 call writeText fail, code: ' + code + ', data: ' + data); expect(null).assertFail(); }, }); - file.readText({ - uri: 'internal://cache/File_writeText_006', - success: function (data) { - console.info('File_writeText_006 call read success ' ); - done(); - }, - fail: function (data, code) { - console.info('File_writeText_006 call readText fail, code: ' + code + ', data: ' + data); - expect(null).assertFail(); - }, - }); - file.delete({ - uri: 'internal://cache/File_writeText_006', - success: function () { - console.info('File_writeText_006 delete success'); - done(); - }, - fail: function (data, code) { - console.info('File_writeText_006 delete , code: ' + code + ', data: ' + data); - expect(null).assertFail(); - }, - }); }); /** @@ -555,7 +545,7 @@ describe('fileTest', function () { */ it('File_writeText_008', 0, async function (done) { let dpath = await nextFileName('File_writeText_008d'); - expect(fileio.mkdirSync(dpath) !== null).assertTrue(); + fileio.mkdirSync(dpath); file.writeText({ uri: 'internal://cache/File_writeText_008d/', text: 'hello', @@ -603,21 +593,20 @@ describe('fileTest', function () { text: 'test', success: function () { console.info('File_writeText_010 mkdir success'); - done(); - }, - fail: function (data, code) { - console.info('File_writeText_010 fail code: ' + code + ', data: ' + data); - expect(null).assertFail(); - }, - }); - file.delete({ - uri: 'internal://cache/File_writeText_010', - success: function () { - console.info('File_writeText_010 delete success'); - done(); + file.delete({ + uri: 'internal://cache/File_writeText_010', + success: function () { + console.info('File_writeText_010 delete success'); + done(); + }, + fail: function (data, code) { + console.info('File_writeText_010 delete fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); }, fail: function (data, code) { - console.info('File_writeText_010 fail, code: ' + code + ', data: ' + data); + console.info('File_writeText_010 writeText fail, code: ' + code + ', data: ' + data); expect(null).assertFail(); }, }); @@ -633,33 +622,31 @@ describe('fileTest', function () { uri: 'internal://cache/../cache/File_writeText_011', text: 'sawyerwang', success: function () { - console.info('File_writeText_011 mkdir success '); - done(); - }, - fail: function (data, code) { - console.info('File_writeText_011 , code: ' + code + ', data: ' + data); - expect(null).assertFail(); - }, - }); - file.readText({ - uri: 'internal://cache/../cache/File_writeText_011', - success: function (data) { - console.info('File_writeText_011 read success ' ); - done(); - }, - fail: function (data, code) { - console.info('File_writeText_011 , code: ' + code + ', data: ' + data); - expect(null).assertFail(); - }, - }); - file.delete({ - uri: 'internal://cache/../cache/File_writeText_011', - success: function () { - console.info('File_writeText_011 delete success'); - done(); + console.info('File_writeText_011 writeText success '); + file.readText({ + uri: 'internal://cache/../cache/File_writeText_011', + success: function (data) { + console.info('File_writeText_011 readText success ' ); + file.delete({ + uri: 'internal://cache/../cache/File_writeText_011', + success: function () { + console.info('File_writeText_011 delete success'); + done(); + }, + fail: function (data, code) { + console.info('File_writeText_011 delete fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + }, + fail: function (data, code) { + console.info('File_writeText_011 readText fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); }, fail: function (data, code) { - console.info('File_writeText_011 delete , code: ' + code + ', data: ' + data); + console.info('File_writeText_011 writeText fail, code: ' + code + ', data: ' + data); expect(null).assertFail(); }, }); @@ -702,27 +689,33 @@ describe('fileTest', function () { append: true, success: function () { console.info('File_writeArrayBuffer_001 call writeArrayBuffer success.'); - done(); - }, - fail: function (data, code) { - console.info('File_writeArrayBuffer_001 , code: ' + code + ', data: ' + data); - expect(null).assertFail(); - }, - }); - file.readArrayBuffer({ - uri: 'internal://cache/File_writeArrayBuffer_001', - success: function (data) { - console.info('File_writeArrayBuffer_001 call readArrayBuffer success.' ); - done(); + file.readArrayBuffer({ + uri: 'internal://cache/File_writeArrayBuffer_001', + success: function (data) { + console.info('File_writeArrayBuffer_001 call readArrayBuffer success.' ); + file.delete({ + uri: 'internal://cache/File_writeArrayBuffer_001', + success: function () { + console.info('File_writeArrayBuffer_001 delete success'); + done(); + }, + fail: function (data, code) { + console.info('File_writeArrayBuffer_001 delete fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + }, + fail: function (data, code) { + console.info('File_writeArrayBuffer_001 readArrayBuffer fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); }, fail: function (data, code) { - console.info('File_writeArrayBuffer_001 readArrayBuffer , code: ' + code + ', data: ' + data); + console.info('File_writeArrayBuffer_001 writeArrayBuffer fail, code: ' + code + ', data: ' + data); expect(null).assertFail(); }, }); - file.delete({ - uri: 'internal://cache/File_writeArrayBuffer_001' - }); }); /** @@ -737,27 +730,33 @@ describe('fileTest', function () { buffer: buf, success: function () { console.info('File_writeArrayBuffer_002 call writeArrayBuffer success.'); - done(); - }, - fail: function (data, code) { - console.info('File_writeArrayBuffer_002 , code: ' + code + ', data: ' + data); - expect(null).assertFail(); - }, - }); - file.readArrayBuffer({ - uri: 'internal://cache/File_writeArrayBuffer_002', - success: function (data) { - console.info('File_writeArrayBuffer_002 call readArrayBuffer success.' ); - done(); + file.readArrayBuffer({ + uri: 'internal://cache/File_writeArrayBuffer_002', + success: function (data) { + console.info('File_writeArrayBuffer_002 call readArrayBuffer success.' ); + file.delete({ + uri: 'internal://cache/File_writeArrayBuffer_002', + success: function () { + console.info('File_writeArrayBuffer_002 delete success'); + done(); + }, + fail: function (data, code) { + console.info('File_writeArrayBuffer_002 delete fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + }, + fail: function (data, code) { + console.info('File_writeArrayBuffer_002 readArrayBuffer fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); }, fail: function (data, code) { - console.info('File_writeArrayBuffer_002 , code: ' + code + ', data: ' + data); + console.info('File_writeArrayBuffer_002 writeArrayBuffer fail, code: ' + code + ', data: ' + data); expect(null).assertFail(); }, }); - file.delete({ - uri: 'internal://cache/File_writeArrayBuffer_002' - }); }); /** @@ -772,34 +771,32 @@ describe('fileTest', function () { buffer: buf, success: function () { console.info('File_writeArrayBuffer_003 call writeText success.'); - done(); - }, - fail: function (data, code) { - console.info('File_writeArrayBuffer_003 , code: ' + code + ', data: ' + data); - expect(null).assertFail(); - }, - }); - file.writeArrayBuffer({ - uri: 'internal://cache/File_writeArrayBuffer_003', - buffer: buf, - append: true, - success: function () { - console.info('File_writeArrayBuffer_003 call writeArrayBuffer success.'); - done(); - }, - fail: function (data, code) { - console.info('File_writeArrayBuffer_003 , code: ' + code + ', data: ' + data); - expect(null).assertFail(); - }, - }); - file.readArrayBuffer({ - uri: 'internal://cache/File_writeArrayBuffer_003', - success: function (data) { - console.info('File_writeArrayBuffer_003 readArrayBuffer success:' ); - done(); + file.writeArrayBuffer({ + uri: 'internal://cache/File_writeArrayBuffer_003', + buffer: buf, + append: true, + success: function () { + console.info('File_writeArrayBuffer_003 call writeArrayBuffer success.'); + file.readArrayBuffer({ + uri: 'internal://cache/File_writeArrayBuffer_003', + success: function (data) { + console.info('File_writeArrayBuffer_003 readArrayBuffer success:' ); + done(); + }, + fail: function (data, code) { + console.info('File_writeArrayBuffer_003 readArrayBuffer fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + }, + fail: function (data, code) { + console.info('File_writeArrayBuffer_003 writeArrayBuffer append fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); }, fail: function (data, code) { - console.info('File_writeArrayBuffer_003 , code: ' + code + ', data: ' + data); + console.info('File_writeArrayBuffer_003 writeArrayBuffer fail, code: ' + code + ', data: ' + data); expect(null).assertFail(); }, }); @@ -818,40 +815,45 @@ describe('fileTest', function () { append: false, success: function () { console.info('File_writeArrayBuffer_004 success call writeText success.'); - done(); - }, - fail: function (data, code) { - console.info('File_writeArrayBuffer_004 , code: ' + code + ', data: ' + data); - expect(null).assertFail(); - }, - }); - file.writeArrayBuffer({ - uri: 'internal://cache/File_writeArrayBuffer_004', - buffer: buf, - append: false, - success: function () { - console.info('File_writeArrayBuffer_004 call writeArrayBuffer success.'); - done(); - }, - fail: function (data, code) { - console.info('File_writeArrayBuffer_004 , code: ' + code + ', data: ' + data); - expect(null).assertFail(); - }, - }); - file.readArrayBuffer({ - uri: 'internal://cache/File_writeArrayBuffer_004', - success: function (data) { - console.info('File_writeArrayBuffer_004: readArrayBuffer success ' ); - done(); + file.writeArrayBuffer({ + uri: 'internal://cache/File_writeArrayBuffer_004', + buffer: buf, + append: false, + success: function () { + console.info('File_writeArrayBuffer_004 call writeArrayBuffer success.'); + file.readArrayBuffer({ + uri: 'internal://cache/File_writeArrayBuffer_004', + success: function (data) { + console.info('File_writeArrayBuffer_004: readArrayBuffer success ' ); + file.delete({ + uri: 'internal://cache/File_writeArrayBuffer_004', + success: function () { + console.info('File_writeArrayBuffer_004 call delete success'); + done(); + }, + fail: function (data, code) { + console.info('File_writeArrayBuffer_004 delete fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + }, + fail: function (data, code) { + console.info('File_writeArrayBuffer_004 readArrayBuffer fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + }, + fail: function (data, code) { + console.info('File_writeArrayBuffer_004 writeArrayBuffer fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); }, fail: function (data, code) { - console.info('File_writeArrayBuffer_004 , code: ' + code + ', data: ' + data); + console.info('File_writeArrayBuffer_004 writeText fail, code: ' + code + ', data: ' + data); expect(null).assertFail(); }, }); - file.delete({ - uri: 'internal://cache/File_writeArrayBuffer_004' - }); }); /** @@ -1011,33 +1013,31 @@ describe('fileTest', function () { uri: 'internal://cache/File_writeArrayBuffer_009', buffer: buf, success: function () { - console.info('File_writeArrayBuffer_009 call success'); - done(); - }, - fail: function (data, code) { - console.info('File_writeArrayBuffer_009 fail'); - expect(null).assertFail(); - }, - }); - file.readArrayBuffer({ - uri: 'internal://cache/File_writeArrayBuffer_009', - success: function (data) { - console.info('File_writeArrayBuffer_009 pass'); - done(); - }, - fail: function (data, code) { - console.info('File_writeArrayBuffer_009 , code: ' + code + ', data: ' + data); - expect(null).assertFail(); - }, - }); - file.delete({ - uri: 'internal://cache/File_writeArrayBuffer_009', - success: function () { - console.info('File_writeArrayBuffer_009 call success'); - done(); + console.info('File_writeArrayBuffer_009 call writeArrayBuffer success'); + file.readArrayBuffer({ + uri: 'internal://cache/File_writeArrayBuffer_009', + success: function (data) { + console.info('File_writeArrayBuffer_009 call readArrayBuffer pass'); + file.delete({ + uri: 'internal://cache/File_writeArrayBuffer_009', + success: function () { + console.info('File_writeArrayBuffer_009 call delete success'); + done(); + }, + fail: function (data, code) { + console.info('File_writeArrayBuffer_009 delete fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + }, + fail: function (data, code) { + console.info('File_writeArrayBuffer_009 readArrayBuffer fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); }, fail: function (data, code) { - console.info('File_writeArrayBuffer_009 fail, code: ' + code + ', data: ' + data); + console.info('File_writeArrayBuffer_009 writeArrayBuffer fail, code: ' + code + ', data: ' + data); expect(null).assertFail(); }, }); @@ -1056,21 +1056,20 @@ describe('fileTest', function () { append: true, success: function () { console.info('File_writeArrayBuffer_010 call writeArrayBuffer success.'); - done(); - }, - fail: function (data, code) { - console.info('File_writeArrayBuffer_010 , code: ' + code + ', data: ' + data); - expect(null).assertFail(); - }, - }); - file.readArrayBuffer({ - uri: 'internal://cache/../cache/File_writeArrayBuffer_010', - success: function (data) { - console.info('File_writeArrayBuffer_010 pass'); - done(); + file.readArrayBuffer({ + uri: 'internal://cache/../cache/File_writeArrayBuffer_010', + success: function (data) { + console.info('File_writeArrayBuffer_010 call readArrayBuffer pass'); + done(); + }, + fail: function (data, code) { + console.info('File_writeArrayBuffer_010 readArrayBuffer fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); }, fail: function (data, code) { - console.info('File_writeArrayBuffer_010 readArrayBuffer , code: ' + code + ', data: ' + data); + console.info('File_writeArrayBuffer_010 writeArrayBuffer fail, code: ' + code + ', data: ' + data); expect(null).assertFail(); }, }); @@ -1113,21 +1112,20 @@ describe('fileTest', function () { text: 'Text that just for test.', success: function () { console.info('File_readText_001 call writeText success.'); - done(); - }, - fail: function (data, code) { - console.info('File_readText_001 , code: ' + code + ', data: ' + data); - expect(null).assertFail(); - }, - }); - file.readText({ - uri: 'internal://cache/File_readText_001', - success: function (data) { - console.info('File_readText_001 call readText success.'); - done(); + file.readText({ + uri: 'internal://cache/File_readText_001', + success: function (data) { + console.info('File_readText_001 call readText success.'); + done(); + }, + fail: function (data, code) { + console.info('File_readText_001 readText fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); }, fail: function (data, code) { - console.info('File_readText_001 , code: ' + code + ', data: ' + data); + console.info('File_readText_001 writeText fail, code: ' + code + ', data: ' + data); expect(null).assertFail(); }, }); @@ -1145,22 +1143,21 @@ describe('fileTest', function () { encoding: 'utf-8', success: function () { console.info('File_readText_002 call writeText success.'); - done(); - }, - fail: function (data, code) { - console.info('File_readText_002 , code: ' + code + ', data: ' + data); - expect(null).assertFail(); - }, - }); - file.readText({ - uri: 'internal://cache/File_readText_002', - encoding: 'utf-8', - success: function (data) { - console.info('File_readText_002 call readText success.'); - done(); + file.readText({ + uri: 'internal://cache/File_readText_002', + encoding: 'utf-8', + success: function (data) { + console.info('File_readText_002 call readText success.'); + done(); + }, + fail: function (data, code) { + console.info('File_readText_002 readText fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); }, fail: function (data, code) { - console.info('File_readText_002 , code: ' + code + ', data: ' + data); + console.info('File_readText_002 writeText fail, code: ' + code + ', data: ' + data); expect(null).assertFail(); }, }); @@ -1226,43 +1223,41 @@ describe('fileTest', function () { }); }); - /** - * @tc.number SUB_STORAGE_File_readText_0600 - * @tc.name File_readText_006 - * @tc.desc Function of API, readText, cache path. - */ - it('File_readText_006', 0, async function (done) { - file.writeText({ - uri: 'internal://cache/File_readText_006', - text: 'test', - success: function () { - console.info('File_readText_006 call success'); - done(); - }, - fail: function (data, code) { - console.info('File_readText_006 fail, code: ' + code + ', data: ' + data); - expect(null).assertFail(); - }, - }); - file.readText({ - uri: 'internal://cache/File_readText_006', - success: function (data) { - console.info('File_readText_006 call success' ); - done(); - }, - fail: function (data, code) { - console.info('File_readText_006 fail'); - expect(null).assertFail(); - }, - }); - file.delete({ + /** + * @tc.number SUB_STORAGE_File_readText_0600 + * @tc.name File_readText_006 + * @tc.desc Function of API, readText, cache path. + */ + it('File_readText_006', 0, async function (done) { + file.writeText({ uri: 'internal://cache/File_readText_006', + text: 'test', success: function () { console.info('File_readText_006 call success'); - done(); + file.readText({ + uri: 'internal://cache/File_readText_006', + success: function (data) { + console.info('File_readText_006 call success' ); + file.delete({ + uri: 'internal://cache/File_readText_006', + success: function () { + console.info('File_readText_006 call success'); + done(); + }, + fail: function (data, code) { + console.info('File_readText_006 delete fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + }, + fail: function (data, code) { + console.info('File_readText_006 readText fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); }, fail: function (data, code) { - console.info('File_readText_006 fail, code: ' + code + ', data: ' + data); + console.info('File_readText_006 writeText fail, code: ' + code + ', data: ' + data); expect(null).assertFail(); }, }); @@ -1279,27 +1274,33 @@ describe('fileTest', function () { text: 'Text that just for test.', success: function () { console.info('File_readText_007 call writeText success.'); - done(); - }, - fail: function (data, code) { - console.info('File_readText_007 , code: ' + code + ', data: ' + data); - expect(null).assertFail(); - }, - }); - file.readText({ - uri: 'internal://cache/../files/../files/File_readText_007', - success: function (data) { - console.info('File_readText_007 call readText success. data.text:' ); - done(); + file.readText({ + uri: 'internal://cache/../files/../files/File_readText_007', + success: function (data) { + console.info('File_readText_007 call readText success. data.text:' ); + file.delete({ + uri: 'internal://cache/../files/../files/File_readText_007', + success: function () { + console.info('File_readText_007 call delete success'); + done(); + }, + fail: function (data, code) { + console.info('File_readText_007 delete fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + }, + fail: function (data, code) { + console.info('File_readText_007 readText fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); }, fail: function (data, code) { - console.info('File_readText_007 , code: ' + code + ', data: ' + data); + console.info('File_readText_007 writeText fail, code: ' + code + ', data: ' + data); expect(null).assertFail(); }, }); - file.delete({ - uri: 'internal://cache/../files/../files/File_readText_007' - }); }); /** @@ -1318,7 +1319,7 @@ describe('fileTest', function () { success: function (data) { console.info("call readText success: " + data.text); expect(text == data.text).assertTrue(); - expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + fileio.unlinkSync(fpath); done(); }, fail: function (data, code) { @@ -1347,29 +1348,35 @@ describe('fileTest', function () { buffer: buffer, success: function () { console.info('File_read_array_buffer_001 call writeArrayBuffer success.'); - done(); - }, - fail: function (data, code) { - console.info('File_read_array_buffer_001 , code: ' + code + ', data: ' + data); - expect(null).assertFail(); - }, - }); - file.readArrayBuffer({ - uri: 'internal://cache/File_read_array_buffer_001', - position: 0, - length: 10, - success: function (data) { - console.info('File_read_array_buffer_001 pass'); - done(); + file.readArrayBuffer({ + uri: 'internal://cache/File_read_array_buffer_001', + position: 0, + length: 10, + success: function (data) { + console.info('File_read_array_buffer_001 call readArrayBuffer pass'); + file.delete({ + uri: 'internal://cache/File_read_array_buffer_001', + success: function () { + console.info('File_read_array_buffer_001 call delete success'); + done(); + }, + fail: function (data, code) { + console.info('File_read_array_buffer_001 delete fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + }, + fail: function (data, code) { + console.info('File_read_array_buffer_001 readArrayBuffer fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); }, fail: function (data, code) { - console.info('File_read_array_buffer_001 , code: ' + code + ', data: ' + data); + console.info('File_read_array_buffer_001 writeArrayBuffer fail, code: ' + code + ', data: ' + data); expect(null).assertFail(); }, }); - file.delete({ - uri: 'internal://cache/File_read_array_buffer_001' - }); }); /** @@ -1384,21 +1391,20 @@ describe('fileTest', function () { buffer: buffer, success: function () { console.info('File_read_array_buffer_002 call writeArrayBuffer success.'); - done(); - }, - fail: function (data, code) { - console.info('File_read_array_buffer_002 , code: ' + code + ', data: ' + data); - expect(null).assertFail(); - }, - }); - file.readArrayBuffer({ - uri: 'internal://cache/File_read_array_buffer_002', - success: function (data) { - console.info('File_read_array_buffer_002 pass'); - done(); + file.readArrayBuffer({ + uri: 'internal://cache/File_read_array_buffer_002', + success: function (data) { + console.info('File_read_array_buffer_002 call readArrayBuffer pass'); + done(); + }, + fail: function (data, code) { + console.info('File_read_array_buffer_002 readArrayBuffer fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); }, fail: function (data, code) { - console.info('File_read_array_buffer_002 , code: ' + code + ', data: ' + data); + console.info('File_read_array_buffer_002 writeArrayBuffer fail, code: ' + code + ', data: ' + data); expect(null).assertFail(); }, }); @@ -1521,33 +1527,31 @@ describe('fileTest', function () { uri: 'internal://cache/File_read_array_buffer_008', buffer: buf, success: function () { - console.info('File_read_array_buffer_008 call success'); - done(); - }, - fail: function (data, code) { - console.info('File_read_array_buffer_008 fail, code: ' + code + ', data: ' + data); - expect(null).assertFail(); - }, - }); - file.readArrayBuffer({ - uri: 'internal://cache/File_read_array_buffer_008', - success: function (data) { - console.info('File_read_array_buffer_008 call success ' ); - done(); - }, - fail: function (data, code) { - console.info('File_read_array_buffer_008 fail'); - expect(null).assertFail(); - }, - }); - file.delete({ - uri: 'internal://cache/File_read_array_buffer_008', - success: function () { - console.info('File_read_array_buffer_008:call success'); - done(); + console.info('File_read_array_buffer_008 call writeArrayBuffer success'); + file.readArrayBuffer({ + uri: 'internal://cache/File_read_array_buffer_008', + success: function (data) { + console.info('File_read_array_buffer_008 call readArrayBuffer success ' ); + file.delete({ + uri: 'internal://cache/File_read_array_buffer_008', + success: function () { + console.info('File_read_array_buffer_008 call delete success'); + done(); + }, + fail: function (data, code) { + console.info('File_read_array_buffer_008 delete fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + }, + fail: function (data, code) { + console.info('File_read_array_buffer_008 readArrayBuffer fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); }, fail: function (data, code) { - console.info('File_read_array_buffer_008 fail, code: ' + code + ', data: ' + data); + console.info('File_read_array_buffer_008 writeArrayBuffer fail, code: ' + code + ', data: ' + data); expect(null).assertFail(); }, }); @@ -1565,31 +1569,37 @@ describe('fileTest', function () { buffer: buffer, success: function () { console.info('File_read_array_buffer_009 call writeArrayBuffer success.'); - done(); - }, - fail: function (data, code) { - console.info('File_read_array_buffer_009 , code: ' + code + ', data: ' + data); - expect(null).assertFail(); - }, - }); - file.readArrayBuffer({ - uri: 'internal://cache/../cache/File_read_array_buffer_009', - position: 0, - length: 10, - success: function (data) { - console.info('File_read_array_buffer_009 call readArrayBuffer success. data.buffer:' ); - done(); + file.readArrayBuffer({ + uri: 'internal://cache/../cache/File_read_array_buffer_009', + position: 0, + length: 10, + success: function (data) { + console.info('File_read_array_buffer_009 call readArrayBuffer success. data.buffer:' ); + file.delete({ + uri: 'internal://cache/../cache/File_read_array_buffer_009', + success: function () { + console.info('File_read_array_buffer_009 call delete success'); + done(); + }, + fail: function (data, code) { + console.info('File_read_array_buffer_009 delete fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + }, + fail: function (data, code) { + console.info('File_read_array_buffer_009 readArrayBuffer fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + complete: function () { + console.info('readArrayBuffer completed'); + } + }); }, fail: function (data, code) { - console.info('File_read_array_buffer_009 , code: ' + code + ', data: ' + data); + console.info('File_read_array_buffer_009 writeArrayBuffer fail, code: ' + code + ', data: ' + data); expect(null).assertFail(); }, - complete: function () { - console.info('readArrayBuffer completed'); - } - }); - file.delete({ - uri: 'internal://cache/../cache/File_read_array_buffer_009' }); }); @@ -1603,33 +1613,31 @@ describe('fileTest', function () { uri: 'internal://cache/File_access_001', text: 'Text that just for test.', success: function () { - console.info('File_access_001 call success.'); - done(); - }, - fail: function (data, code) { - console.info('File_access_001 fail,code: ' + code + ', data: ' + data); - expect(null).assertFail(); - }, - }); - file.access({ - uri: 'internal://cache/File_access_001', - success: function () { - console.info('File_access_001 call access success.'); - done(); - }, - fail: function (data, code) { - console.info('File_access_001 , code: ' + code + ', data: ' + data); - expect(null).assertFail(); - }, - }); - file.delete({ - uri: 'internal://cache/File_access_001', - success: function () { - console.info('File_access_001 call delete success.'); - done(); + console.info('File_access_001 call writeText success.'); + file.access({ + uri: 'internal://cache/File_access_001', + success: function () { + console.info('File_access_001 call access success.'); + file.delete({ + uri: 'internal://cache/File_access_001', + success: function () { + console.info('File_access_001 call delete success.'); + done(); + }, + fail: function (data, code) { + console.info('File_access_001 delete fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + }, + fail: function (data, code) { + console.info('File_access_001 access fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); }, fail: function (data, code) { - console.info('File_access_001 , code: ' + code + ', data: ' + data); + console.info('File_access_001 writeText fail, code: ' + code + ', data: ' + data); expect(null).assertFail(); }, }); @@ -1644,33 +1652,31 @@ describe('fileTest', function () { file.mkdir({ uri: 'internal://cache/File_access_002', success: function () { - console.info('File_access_002 call success.'); - done(); - }, - fail: function (data, code) { - console.info('File_access_002 fail, code: ' + code + ', data: ' + data); - expect(null).assertFail(); - }, - }); - file.access({ - uri: 'internal://cache/File_access_002', - success: function () { - console.info('File_access_002 call access success.'); - done(); - }, - fail: function (data, code) { - console.info('File_access_002 , code: ' + code + ', data: ' + data); - expect(null).assertFail(); - }, - }); - file.rmdir({ - uri: 'internal://cache/File_access_002', - success: function () { - console.info('File_access_002 call rmdir success.'); - done(); + console.info('File_access_002 call mkdir success.'); + file.access({ + uri: 'internal://cache/File_access_002', + success: function () { + console.info('File_access_002 call access success.'); + file.rmdir({ + uri: 'internal://cache/File_access_002', + success: function () { + console.info('File_access_002 call rmdir success.'); + done(); + }, + fail: function (data, code) { + console.info('File_access_002 rmdir fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + }, + fail: function (data, code) { + console.info('File_access_002 access fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); }, fail: function (data, code) { - console.info('File_access_002 , code: ' + code + ', data: ' + data); + console.info('File_access_002 mkdir fail, code: ' + code + ', data: ' + data); expect(null).assertFail(); }, }); @@ -1778,33 +1784,31 @@ describe('fileTest', function () { uri: 'internal://cache/File_access_007', text: 'hello', success: function () { - console.info('File_access_007 mkdir success '); - done(); - }, - fail: function (data, code) { - console.info('File_access_007 fail, code: ' + code + ', data: ' + data); - expect(null).assertFail(); - }, - }); - file.access({ - uri: 'internal://cache/File_access_007', - success: function () { - console.info('File_access_007 access success'); - done(); - }, - fail: function (data, code) { - console.info('File_access_007 fail'); - expect(null).assertFail(); - }, - }); - file.delete({ - uri: 'internal://cache/File_access_007', - success: function () { - console.info('File_access_007 delete success'); - done(); + console.info('File_access_007 writeText success '); + file.access({ + uri: 'internal://cache/File_access_007', + success: function () { + console.info('File_access_007 access success'); + file.delete({ + uri: 'internal://cache/File_access_007', + success: function () { + console.info('File_access_007 delete success'); + done(); + }, + fail: function (data, code) { + console.info('File_access_007 delete fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + }, + fail: function (data, code) { + console.info('File_access_007 access fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); }, fail: function (data, code) { - console.info('File_access_007 fail, code: ' + code + ', data: ' + data); + console.info('File_access_007 writeText fail, code: ' + code + ', data: ' + data); expect(null).assertFail(); }, }); @@ -1820,36 +1824,34 @@ describe('fileTest', function () { uri: 'internal://cache/../cache/File_access_008', text: 'Text that just for test.', success: function () { - console.info('File_access_008 mkdir success.'); - done(); - }, - fail: function (data, code) { - console.info('File_access_008 fail,code: ' + code + ', data: ' + data); - expect(null).assertFail(); - }, - }); - file.access({ - uri: 'internal://cache/../cache/File_access_008', - success: function () { - console.info('File_access_008 call access success.'); - done(); - }, - fail: function (data, code) { - console.info('File_access_008 , code: ' + code + ', data: ' + data); - expect(null).assertFail(); - }, - complete: function () { - console.info('access completed'); - } - }); - file.delete({ - uri: 'internal://cache/../cache/File_access_008', - success: function () { - console.info('File_access_008 call delete success.'); - done(); + console.info('File_access_008 writeText success.'); + file.access({ + uri: 'internal://cache/../cache/File_access_008', + success: function () { + console.info('File_access_008 call access success.'); + file.delete({ + uri: 'internal://cache/../cache/File_access_008', + success: function () { + console.info('File_access_008 call delete success.'); + done(); + }, + fail: function (data, code) { + console.info('File_access_008 delete fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + } + }); + }, + fail: function (data, code) { + console.info('File_access_008 access fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + complete: function () { + console.info('access completed'); + } + }); }, fail: function (data, code) { - console.info('File_access_008 , code: ' + code + ', data: ' + data); + console.info('File_access_008 writeText fail, code: ' + code + ', data: ' + data); expect(null).assertFail(); }, }); @@ -1865,21 +1867,20 @@ describe('fileTest', function () { uri: 'internal://cache/File_mkdir_001', success: function () { console.info('File_mkdir_001 call mkdir success.'); - done(); - }, - fail: function (data, code) { - console.info('File_mkdir_001 , code: ' + code + ', data: ' + data); - expect(null).assertFail(); - }, - }); - file.rmdir({ - uri: 'internal://cache/File_mkdir_001', - success: function () { - console.info('File_mkdir_001 call rmdir success.'); - done(); + file.rmdir({ + uri: 'internal://cache/File_mkdir_001', + success: function () { + console.info('File_mkdir_001 call rmdir success.'); + done(); + }, + fail: function (data, code) { + console.info('File_mkdir_001 rmdir fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); }, fail: function (data, code) { - console.info('File_mkdir_001 , code: ' + code + ', data: ' + data); + console.info('File_mkdir_001 mkdir fail, code: ' + code + ', data: ' + data); expect(null).assertFail(); }, }); @@ -1996,21 +1997,20 @@ describe('fileTest', function () { uri: 'internal://cache/File_mkdir_007d', success: function () { console.info('File_mkdir_007 mkdir success'); - done(); - }, - fail: function (data, code) { - console.info('File_mkdir_007 fail, code: ' + code + ', data: ' + data); - expect(null).assertFail(); - }, - }); - file.rmdir({ - uri: 'internal://cache/File_mkdir_007d', - success: function () { - console.info('File_mkdir_007 delete success'); - done(); + file.rmdir({ + uri: 'internal://cache/File_mkdir_007d', + success: function () { + console.info('File_mkdir_007 delete success'); + done(); + }, + fail: function (data, code) { + console.info('File_mkdir_007 delete fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); }, fail: function (data, code) { - console.info('File_mkdir_007 fail, code: ' + code + ', data: ' + data); + console.info('File_mkdir_007 mkdir fail, code: ' + code + ', data: ' + data); expect(null).assertFail(); }, }); @@ -2020,27 +2020,26 @@ describe('fileTest', function () { * @tc.number SUB_STORAGE_File_mkdir_0800 * @tc.name File_mkdir_008 * @tc.desc Function of API, virtual path. - */ - it('File_mkdir_008', 0, async function (done) { - file.mkdir({ - uri: 'internal://cache/../files/File_mkdir_008', - success: function () { - console.info('File_mkdir_008 call mkdir success.'); - done(); - }, - fail: function (data, code) { - console.info('File_mkdir_008 , code: ' + code + ', data: ' + data); - expect(null).assertFail(); - }, - }); - file.rmdir({ + */ + it('File_mkdir_008', 0, async function (done) { + file.mkdir({ uri: 'internal://cache/../files/File_mkdir_008', success: function () { - console.info('File_mkdir_008 call rmdir success.'); - done(); + console.info('File_mkdir_008 call mkdir success.'); + file.rmdir({ + uri: 'internal://cache/../files/File_mkdir_008', + success: function () { + console.info('File_mkdir_008 call rmdir success.'); + done(); + }, + fail: function (data, code) { + console.info('File_mkdir_008 rmdir fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); }, fail: function (data, code) { - console.info('File_mkdir_008 , code: ' + code + ', data: ' + data); + console.info('File_mkdir_008 mkdir fail, code: ' + code + ', data: ' + data); expect(null).assertFail(); }, }); @@ -2079,21 +2078,20 @@ describe('fileTest', function () { uri: 'internal://cache/File_rmdir_001', success: function () { console.info('File_rmdir_001 call mkdir success.'); - done(); - }, - fail: function (data, code) { - console.info('File_rmdir_001 fail, code: ' + code + ', data: ' + data); - expect(null).assertFail(); - }, - }); - file.rmdir({ - uri: 'internal://cache/File_rmdir_001', - success: function () { - console.info('File_rmdir_001 call rmdir success.'); - done(); + file.rmdir({ + uri: 'internal://cache/File_rmdir_001', + success: function () { + console.info('File_rmdir_001 call rmdir success.'); + done(); + }, + fail: function (data, code) { + console.info('File_rmdir_001 rmdir fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); }, fail: function (data, code) { - console.info('File_rmdir_001 fail, code: ' + code + ', data: ' + data); + console.info('File_rmdir_001 mkdir fail, code: ' + code + ', data: ' + data); expect(null).assertFail(); }, }); @@ -2240,21 +2238,20 @@ describe('fileTest', function () { uri: uri, success: function () { console.info('File_rmdir_006 mkdir success'); - done(); - }, - fail: function (data, code) { - console.info('File_rmdir_006 fail'); - expect(null).assertFail(); - }, - }); - file.rmdir({ - uri: uri, - success: function () { - console.info('File_rmdir_006 => rmdir success'); - done(); + file.rmdir({ + uri: uri, + success: function () { + console.info('File_rmdir_006 rmdir success'); + done(); + }, + fail: function (data, code) { + console.info('File_rmdir_006 rmdir fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); }, fail: function (data, code) { - console.info('File_rmdir_006 => fail'); + console.info('File_rmdir_006 mkdir fail, code: ' + code + ', data: ' + data); expect(null).assertFail(); }, }); @@ -2270,21 +2267,20 @@ describe('fileTest', function () { uri: 'internal://cache/File_rmdir_007d', success: function () { console.info('File_rmdir_007 mkdir success'); - done(); - }, - fail: function (data, code) { - console.info('File_rmdir_007 fail, code: ' + code + ', data: ' + data); - expect(null).assertFail(); - }, - }); - file.rmdir({ - uri: 'internal://cache/File_rmdir_007d', - success: function () { - console.info('File_rmdir_007 rmdir success'); - done(); + file.rmdir({ + uri: 'internal://cache/File_rmdir_007d', + success: function () { + console.info('File_rmdir_007 rmdir success'); + done(); + }, + fail: function (data, code) { + console.info('File_rmdir_007 rmdir fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); }, fail: function (data, code) { - console.info('File_rmdir_007 fail, code: ' + code + ', data: ' + data); + console.info('File_rmdir_007 mkdir fail, code: ' + code + ', data: ' + data); expect(null).assertFail(); }, }); @@ -2300,21 +2296,20 @@ describe('fileTest', function () { uri: 'internal://cache/../files/File_rmdir_008', success: function () { console.info('File_rmdir_008 call mkdir success.'); - done(); - }, - fail: function (data, code) { - console.info('File_rmdir_008 , code: ' + code + ', data: ' + data); - expect(null).assertFail(); - }, - }); - file.rmdir({ - uri: 'internal://cache/../files/File_rmdir_008', - success: function () { - console.info('File_rmdir_008 call rmdir success.'); - done(); + file.rmdir({ + uri: 'internal://cache/../files/File_rmdir_008', + success: function () { + console.info('File_rmdir_008 call rmdir success.'); + done(); + }, + fail: function (data, code) { + console.info('File_rmdir_008 rmdir fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); }, fail: function (data, code) { - console.info('File_rmdir_008 , code: ' + code + ', data: ' + data); + console.info('File_rmdir_008 mkdir fail, code: ' + code + ', data: ' + data); expect(null).assertFail(); }, }); @@ -2354,25 +2349,24 @@ describe('fileTest', function () { text: 'Text that just for test.', success: function () { console.info('File_Move_001 call writeText success.'); - done(); + file.move({ + srcUri: 'internal://cache/File_Move_001', + dstUri: 'internal://cache/File_Move_001_1', + success: function (data) { + console.info('File_Move_001 call writeText success. data:' + data); + done(); + }, + fail: function (data, code) { + console.info('File_Move_001 move fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); }, fail: function (data, code) { console.error('File_Move_001 call writeText fail, code: ' + code + ', data: ' + data); expect(null).assertFail(); }, }); - file.move({ - srcUri: 'internal://cache/File_Move_001', - dstUri: 'internal://cache/File_Move_001_1', - success: function (data) { - console.info('File_Move_001 call writeText success. data:' + data); - done(); - }, - fail: function (data, code) { - console.info('File_Move_001 , code: ' + code + ', data: ' + data); - expect(null).assertFail(); - }, - }); }); /** @@ -2458,7 +2452,7 @@ describe('fileTest', function () { */ it('File_Move_005', 0, async function (done) { let srcDpath = await fileName('File_Move_005d'); - expect(fileio.mkdirSync(srcDpath) !== null).assertTrue(); + fileio.mkdirSync(srcDpath); file.move({ srcUri: 'internal://cache/../files/File_Move_005d', dstUri: 'internal://app/cache/File_Move_005d', @@ -2537,34 +2531,32 @@ describe('fileTest', function () { uri: 'internal://cache/File_Move_008', text: 'sss', success: function () { - console.info('File_Move_008 mkdir success '); - done(); - }, - fail: function (data, code) { - console.info('File_Move_008 fail, code: ' + code + ', data: ' + data); - expect(null).assertFail(); - }, - }); - file.move({ - srcUri: 'internal://cache/File_Move_008', - dstUri: 'internal://app/File_Move_008', - success: function (uri) { - console.info('File_Move_008 => pass, uri:' + uri); - done(); - }, - fail: function (data, code) { - console.info('File_Move_008 , code: ' + code + ', data: ' + data); - expect(null).assertFail(); - }, - }); - file.delete({ - uri: 'internal://app/File_Move_008', - success: function () { - console.info('File_Move_008 delete success'); - done(); + console.info('File_Move_008 writeText success '); + file.move({ + srcUri: 'internal://cache/File_Move_008', + dstUri: 'internal://app/File_Move_008', + success: function (uri) { + console.info('File_Move_008 move pass, uri:' + uri); + file.delete({ + uri: 'internal://app/File_Move_008', + success: function () { + console.info('File_Move_008 delete success'); + done(); + }, + fail: function (data, code) { + console.info('File_Move_008 delete fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + }, + fail: function (data, code) { + console.info('File_Move_008 move fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); }, fail: function (data, code) { - console.info('File_Move_008 fail, code: ' + code + ', data: ' + data); + console.info('File_Move_008 writeText fail, code: ' + code + ', data: ' + data); expect(null).assertFail(); }, }); @@ -2586,7 +2578,7 @@ describe('fileTest', function () { done(); }, fail: function (data, code) { - console.info('File_Move_009 , code: ' + code + ', data: ' + data); + console.info('File_Move_009 call move fail, code: ' + code + ', data: ' + data); expect(null).assertFail(); }, }); @@ -2703,23 +2695,22 @@ describe('fileTest', function () { dstUri: 'internal://cache/../files/cache/File_Copy_001', success: function () { console.info('File_Copy_001 call copy success.'); - done(); - }, - fail: function (data, code) { - console.info('File_Copy_001 , code: ' + code + ', data: ' + data); - expect(null).assertFail(); - }, - }); - file.readText({ - uri: 'internal://cache/../files/cache/File_Copy_001', - success: function (data) { - console.info('File_Copy_001 read success:' ); - expect(fileio.unlinkSync(srcFpath) !== null).assertTrue(); - expect(fileio.unlinkSync(dstFpath) !== null).assertTrue(); - done(); + file.readText({ + uri: 'internal://cache/../files/cache/File_Copy_001', + success: function (data) { + console.info('File_Copy_001 read success:' ); + fileio.unlinkSync(srcFpath); + fileio.unlinkSync(dstFpath); + done(); + }, + fail: function (data, code) { + console.info('File_Copy_001 readText fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); }, fail: function (data, code) { - console.info('File_Copy_001 call readText callback fail, code: ' + code + ', data: ' + data); + console.info('File_Copy_001 copy fail, code: ' + code + ', data: ' + data); expect(null).assertFail(); }, }); @@ -2741,8 +2732,8 @@ describe('fileTest', function () { dstUri: 'internal://cache/../files/cache/File_Copy_002' + typeArray[i], success: function () { console.info('File_Copy_002 call copy success.'); - expect(fileio.unlinkSync(srcFpath) !== null).assertTrue(); - expect(fileio.unlinkSync(dstFpath) !== null).assertTrue(); + fileio.unlinkSync(srcFpath); + fileio.unlinkSync(dstFpath); done(); }, fail: function (data, code) { @@ -2767,25 +2758,23 @@ describe('fileTest', function () { dstUri: 'internal://cache/../files/cache/File_Copy_003', success: function () { console.info('File_Copy_003 call copy success.'); - done(); - }, - fail: function (data, code) { - console.info('File_Copy_003 , code: ' + code + ', data: ' + data); - expect(null).assertFail(); - }, - }); - file.readText({ - uri: 'internal://cache/../files/cache/File_Copy_003', - success: function (data) { - console.info('File_Copy_003 readText success, data.text:' ); - expect(fileio.unlinkSync(srcFpath) !== null).assertTrue(); - expect(fileio.unlinkSync(dstFpath) !== null).assertTrue(); - done(); + file.readText({ + uri: 'internal://cache/../files/cache/File_Copy_003', + success: function (data) { + console.info('File_Copy_003 readText success, data.text:'); + fileio.unlinkSync(srcFpath); + fileio.unlinkSync(dstFpath); + done(); + }, + fail: function (data, code) { + console.info('File_Copy_003 readText fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); }, fail: function (data, code) { - console.info('File_Copy_003 call readText callback fail, code: ' + code + ', data: ' + data); + console.info('File_Copy_003 copy fail, code: ' + code + ', data: ' + data); expect(null).assertFail(); - }, }); }); @@ -2808,7 +2797,7 @@ describe('fileTest', function () { fail: function (data, code) { console.info('File_Copy_004 , code: ' + code + ', data: ' + data); expect(code == 202).assertTrue(); - expect(fileio.unlinkSync(srcFpath) !== null).assertTrue(); + fileio.unlinkSync(srcFpath); done(); }, }); @@ -2908,44 +2897,41 @@ describe('fileTest', function () { text: 'test', success: function () { console.info('File_Copy_008 mkdir success'); - done(); - }, - fail: function (data, code) { - console.info('File_Copy_008 fail, code: ' + code + ', data: ' + data); - expect(null).assertFail(); - }, - }); - file.copy({ - srcUri: 'internal://cache/File_Copy_008', - dstUri: 'internal://cache/../files/File_Copy_008', - success: function () { - console.info('File_Copy_008 move success'); - done(); - }, - fail: function (data, code) { - console.info('File_Copy_008 , code: ' + code + ', data: ' + data); - expect(null).assertFail(); - }, - }); - file.delete({ - uri: 'internal://cache/../files/File_Copy_008', - success: function () { - console.info('File_Copy_008 delete success '); - done(); - }, - fail: function (data, code) { - console.info('File_Copy_008 fail, code: ' + code + ', data: ' + data); - expect(null).assertFail(); - }, - }); - file.delete({ - uri: 'internal://cache/File_Copy_008', - success: function () { - console.info('File_Copy_008 delete success'); - done(); + file.copy({ + srcUri: 'internal://cache/File_Copy_008', + dstUri: 'internal://cache/../files/File_Copy_008', + success: function () { + console.info('File_Copy_008 copy success'); + file.delete({ + uri: 'internal://cache/../files/File_Copy_008', + success: function () { + console.info('File_Copy_008 delete success '); + file.delete({ + uri: 'internal://cache/File_Copy_008', + success: function () { + console.info('File_Copy_008 delete success'); + done(); + }, + fail: function (data, code) { + console.info('File_Copy_008 cache delete fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + }, + fail: function (data, code) { + console.info('File_Copy_008 files delete fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + }, + fail: function (data, code) { + console.info('File_Copy_008 copy fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); }, fail: function (data, code) { - console.info('File_Copy_008 fail, code: ' + code + ', data: ' + data); + console.info('File_Copy_008 writeText fail, code: ' + code + ', data: ' + data); expect(null).assertFail(); }, }); @@ -3015,21 +3001,20 @@ describe('fileTest', function () { dstUri: 'internal://cache/File_Copy_011', success: function () { console.info('File_Copy_011 copy pass'); - done(); - }, - fail: function (data, code) { - console.info('File_Copy_011 , code: ' + code + ', data: ' + data); - expect(null).assertFail(); - }, - }); - file.readText({ - uri: 'internal://cache/File_Copy_011', - success: function (data) { - console.info('File_Copy_011 read success:' ); - done(); + file.readText({ + uri: 'internal://cache/File_Copy_011', + success: function (data) { + console.info('File_Copy_011 read success:' ); + done(); + }, + fail: function (data, code) { + console.info('File_Copy_011 readText fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); }, fail: function (data, code) { - console.info('File_Copy_011 call readText callback fail, code: ' + code + ', data: ' + data); + console.info('File_Copy_011 copy fail, code: ' + code + ', data: ' + data); expect(null).assertFail(); }, }); @@ -3053,7 +3038,7 @@ describe('fileTest', function () { fail: function (data, code) { console.info('File_Copy_012 , code: ' + code + ', data: ' + data); expect(code == 300).assertTrue(); - expect(fileio.unlinkSync(srcFpath) !== null).assertTrue(); + fileio.unlinkSync(srcFpath); done(); }, }); @@ -3096,16 +3081,16 @@ describe('fileTest', function () { let dpath = await fileName('File_List_001') + 'd'; let fpath = dpath + '/File_List_001'; let ddpath = dpath + '/File_List_001_1d'; - expect(fileio.mkdirSync(dpath) !== null).assertTrue(); - expect(fileio.mkdirSync(ddpath) !== null).assertTrue(); + fileio.mkdirSync(dpath); + fileio.mkdirSync(ddpath); expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); file.list({ uri: 'internal://cache/../files/File_List_001d', success: function (data) { console.info('File_List_001 call list success.' + JSON.stringify(data.fileList)); - expect(fileio.unlinkSync(fpath) !== null).assertTrue(); - expect(fileio.rmdirSync(ddpath) !== null).assertTrue(); - expect(fileio.rmdirSync(dpath) !== null).assertTrue(); + fileio.unlinkSync(fpath); + fileio.rmdirSync(ddpath); + fileio.rmdirSync(dpath); done(); }, fail: function (data, code) { @@ -3124,16 +3109,16 @@ describe('fileTest', function () { let dpath = await fileName('File_List_002') + 'd'; let fpath = dpath + '/File_List_002'; let ddpath = dpath + '/File_List_002_1d'; - expect(fileio.mkdirSync(dpath) !== null).assertTrue(); - expect(fileio.mkdirSync(ddpath) !== null).assertTrue(); + fileio.mkdirSync(dpath); + fileio.mkdirSync(ddpath); expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); file.list({ uri: 'internal://cache/../files/File_List_002d', success: function (data) { console.info('File_List_002 call list success.' + JSON.stringify(data.fileList)); - expect(fileio.unlinkSync(fpath) !== null).assertTrue(); - expect(fileio.rmdirSync(ddpath) !== null).assertTrue(); - expect(fileio.rmdirSync(dpath) !== null).assertTrue(); + fileio.unlinkSync(fpath); + fileio.rmdirSync(ddpath); + fileio.rmdirSync(dpath); done(); }, fail: function (data, code) { @@ -3152,8 +3137,8 @@ describe('fileTest', function () { let dpath = await fileName('File_List_003') + 'd'; let fpath = dpath + '/File_List_003'; let ddpath = dpath + '/File_List_003_1d'; - expect(fileio.mkdirSync(dpath) !== null).assertTrue(); - expect(fileio.mkdirSync(ddpath) !== null).assertTrue(); + fileio.mkdirSync(dpath); + fileio.mkdirSync(ddpath); expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); file.list({ uri: 'internal://cache/../files/File_List_003d', @@ -3172,15 +3157,19 @@ describe('fileTest', function () { success: function (data) { console.info('File_List_003 call write success.'); done(); - } + }, + fail: function (data, code) { + console.info('File_List_003 , code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, }); file.list({ uri: 'internal://cache/../files/File_List_003d', success: function (data) { console.info('File_List_003 call list success.' + JSON.stringify(data.fileList)); - expect(fileio.unlinkSync(fpath) !== null).assertTrue(); - expect(fileio.rmdirSync(ddpath) !== null).assertTrue(); - expect(fileio.rmdirSync(dpath) !== null).assertTrue(); + fileio.unlinkSync(fpath); + fileio.rmdirSync(ddpath); + fileio.rmdirSync(dpath); done(); }, fail: function (data, code) { @@ -3199,8 +3188,8 @@ describe('fileTest', function () { let dpath = await fileName('File_List_004') + 'd'; let fpath = dpath + '/File_List_004'; let ddpath = dpath + '/File_List_004_1d'; - expect(fileio.mkdirSync(dpath) !== null).assertTrue(); - expect(fileio.mkdirSync(ddpath) !== null).assertTrue(); + fileio.mkdirSync(dpath); + fileio.mkdirSync(ddpath); expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); file.list({ uri: 'internal://cache/../files/File_List_004d', @@ -3224,8 +3213,8 @@ describe('fileTest', function () { let dpath = await fileName('File_List_005') + 'd'; let fpath = dpath + '/File_List_005'; let ddpath = dpath + '/File_List_005_1d'; - expect(fileio.mkdirSync(dpath) !== null).assertTrue(); - expect(fileio.mkdirSync(ddpath) !== null).assertTrue(); + fileio.mkdirSync(dpath); + fileio.mkdirSync(ddpath); expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); file.list({ uri: 'internal://cache/../files/File_List_005d', @@ -3273,7 +3262,7 @@ describe('fileTest', function () { uri: 'internal://cache/../files/File_List_007', success: function (data) { console.info('File_List_007 pass, data.fileList:' + JSON.stringify(data.fileList)); - expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + fileio.unlinkSync(fpath); done(); }, fail: function (data, code) { @@ -3345,8 +3334,8 @@ describe('fileTest', function () { let ddpath = dpath + '/File_List_010_1d'; let fffpath = ddpath + '/File_List_010_2'; try { - expect(fileio.mkdirSync(dpath) !== null).assertTrue(); - expect(fileio.mkdirSync(ddpath) !== null).assertTrue(); + fileio.mkdirSync(dpath); + fileio.mkdirSync(ddpath); expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); expect(prepareFile(ffpath, FILE_CONTENT)).assertTrue(); expect(prepareFile(fffpath, FILE_CONTENT)).assertTrue(); @@ -3359,11 +3348,11 @@ describe('fileTest', function () { uri: 'internal://cache/File_List_010d', success: function (data) { console.info('File_List_010 => pass' + JSON.stringify(data.fileList)); - expect(fileio.unlinkSync(fpath) !== null).assertTrue(); - expect(fileio.unlinkSync(ffpath) !== null).assertTrue(); - expect(fileio.unlinkSync(fffpath) !== null).assertTrue(); - expect(fileio.rmdirSync(ddpath) !== null).assertTrue(); - expect(fileio.rmdirSync(dpath) !== null).assertTrue(); + fileio.unlinkSync(fpath); + fileio.unlinkSync(ffpath); + fileio.unlinkSync(fffpath); + fileio.rmdirSync(ddpath); + fileio.rmdirSync(dpath); done(); }, fail: function (data, code) { @@ -3382,16 +3371,16 @@ describe('fileTest', function () { let dpath = await fileName('File_List_011') + 'd'; let fpath = dpath + '/File_List_011'; let ddpath = dpath + '/File_List_011_1d'; - expect(fileio.mkdirSync(dpath) !== null).assertTrue(); - expect(fileio.mkdirSync(ddpath) !== null).assertTrue(); + fileio.mkdirSync(dpath); + fileio.mkdirSync(ddpath); expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); file.list({ uri: 'internal://cache/../files/File_List_011d', success: function (data) { console.info('File_List_011 call list success.' + JSON.stringify(data.fileList)); - expect(fileio.unlinkSync(fpath) !== null).assertTrue(); - expect(fileio.rmdirSync(ddpath) !== null).assertTrue(); - expect(fileio.rmdirSync(dpath) !== null).assertTrue(); + fileio.unlinkSync(fpath); + fileio.rmdirSync(ddpath); + fileio.rmdirSync(dpath); done(); }, fail: function (data, code) { @@ -3436,7 +3425,7 @@ describe('fileTest', function () { recursive: true, success: function (data) { console.info('File_Get_001 pass,data.uri:' ); - expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + fileio.unlinkSync(fpath); done(); }, fail: function (data, code) { @@ -3464,7 +3453,7 @@ describe('fileTest', function () { console.info('lastModifiedTime:' + data.lastModifiedTime); console.info('type:' + data.type); console.info('subFiles:' + data.subFiles + '}'); - expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + fileio.unlinkSync(fpath); done(); }, fail: function (data, code) { @@ -3492,7 +3481,7 @@ describe('fileTest', function () { console.info('type:' + data.type); console.info('subFiles:' + data.subFiles + '}'); console.info('File_Get_003 => pass'); - expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + fileio.unlinkSync(fpath); done(); }, fail: function (data, code) { @@ -3512,8 +3501,8 @@ describe('fileTest', function () { let ddpath = dpath + '/File_Get_004dd' let fpath = dpath + '/File_Get_004f' let ffpath = ddpath + '/File_Get_004ff' - expect(fileio.mkdirSync(dpath) !== null).assertTrue(); - expect(fileio.mkdirSync(ddpath) !== null).assertTrue(); + fileio.mkdirSync(dpath); + fileio.mkdirSync(ddpath); expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); expect(prepareFile(ffpath, FILE_CONTENT)).assertTrue(); file.get({ @@ -3527,10 +3516,10 @@ describe('fileTest', function () { console.info('type:' + data.type); console.info('subFiles:' + data.subFiles + '}'); console.info('File_Get_004 => pass'); - expect(fileio.unlinkSync(ffpath) !== null).assertTrue(); - expect(fileio.unlinkSync(fpath) !== null).assertTrue(); - expect(fileio.rmdirSync(ddpath) !== null).assertTrue(); - expect(fileio.rmdirSync(dpath) !== null).assertTrue(); + fileio.unlinkSync(ffpath); + fileio.unlinkSync(fpath); + fileio.rmdirSync(ddpath); + fileio.rmdirSync(dpath); done(); }, fail: function (data, code) { @@ -3550,8 +3539,8 @@ describe('fileTest', function () { let ddpath = dpath + '/File_Get_005dd'; let fpath = dpath + '/File_Get_005f'; let ffpath = ddpath + '/File_Get_005ff'; - expect(fileio.mkdirSync(dpath) !== null).assertTrue(); - expect(fileio.mkdirSync(ddpath) !== null).assertTrue(); + fileio.mkdirSync(dpath); + fileio.mkdirSync(ddpath); expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); expect(prepareFile(ffpath, FILE_CONTENT)).assertTrue(); file.get({ @@ -3565,10 +3554,10 @@ describe('fileTest', function () { console.info('type:' + data.type); console.info('subFiles:' + data.subFiles + '}'); console.info('File_Get_005 => pass'); - expect(fileio.unlinkSync(ffpath) !== null).assertTrue(); - expect(fileio.unlinkSync(fpath) !== null).assertTrue(); - expect(fileio.rmdirSync(ddpath) !== null).assertTrue(); - expect(fileio.rmdirSync(dpath) !== null).assertTrue(); + fileio.unlinkSync(ffpath); + fileio.unlinkSync(fpath); + fileio.rmdirSync(ddpath); + fileio.rmdirSync(dpath); done(); }, fail: function (data, code) { @@ -3588,8 +3577,8 @@ describe('fileTest', function () { let ddpath = dpath + '/File_Get_006dd'; let fpath = dpath + '/File_Get_006f'; let ffpath = ddpath + '/File_Get_006ff'; - expect(fileio.mkdirSync(dpath) !== null).assertTrue(); - expect(fileio.mkdirSync(ddpath) !== null).assertTrue(); + fileio.mkdirSync(dpath); + fileio.mkdirSync(ddpath); expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); expect(prepareFile(ffpath, FILE_CONTENT)).assertTrue(); file.get({ @@ -3602,10 +3591,10 @@ describe('fileTest', function () { console.info('type:' + data.type); console.info('subFiles:' + data.subFiles + '}'); console.info('File_Get_006 => pass'); - expect(fileio.unlinkSync(ffpath) !== null).assertTrue(); - expect(fileio.unlinkSync(fpath) !== null).assertTrue(); - expect(fileio.rmdirSync(ddpath) !== null).assertTrue(); - expect(fileio.rmdirSync(dpath) !== null).assertTrue(); + fileio.unlinkSync(ffpath); + fileio.unlinkSync(fpath); + fileio.rmdirSync(ddpath); + fileio.rmdirSync(dpath); done(); }, fail: function (data, code) { @@ -3704,39 +3693,37 @@ describe('fileTest', function () { uri: 'internal://cache/File_Get_011', text: 'test', success: function () { - console.info('File_Get_011 mkdir success'); - done(); - }, - fail: function (data, code) { - console.info('File_Get_011 fail, code: ' + code + ', data: ' + data); - expect(null).assertFail(); - }, - }); - file.get({ - uri: 'internal://cache/File_Get_011', - recursive: true, - success: function (data) { - console.info('file list'); - console.info('uri:' ); - console.info('length:' + data.length); - console.info('lastModifiedTime:' + data.lastModifiedTime); - console.info('type:' + data.type); - console.info('subFiles:' + data.subFiles); - done(); - }, - fail: function (data, code) { - console.info('File_Get_011 fail, code: ' + code + ', data: ' + data); - expect(null).assertFail(); - }, - }); - file.delete({ - uri: 'internal://cache/File_Get_011', - success: function () { - console.info('File_Get_011 delete success'); - done(); + console.info('File_Get_011 writeText success'); + file.get({ + uri: 'internal://cache/File_Get_011', + recursive: true, + success: function (data) { + console.info('file list'); + console.info('uri:' ); + console.info('length:' + data.length); + console.info('lastModifiedTime:' + data.lastModifiedTime); + console.info('type:' + data.type); + console.info('subFiles:' + data.subFiles); + file.delete({ + uri: 'internal://cache/File_Get_011', + success: function () { + console.info('File_Get_011 delete success'); + done(); + }, + fail: function (data, code) { + console.info('File_Get_011 delete fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + }, + fail: function (data, code) { + console.info('File_Get_011 get fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); }, fail: function (data, code) { - console.info('File_Get_011 fail, code: ' + code + ', data: ' + data); + console.info('File_Get_011 writeText fail, code: ' + code + ', data: ' + data); expect(null).assertFail(); }, }); @@ -3751,7 +3738,7 @@ describe('fileTest', function () { let firstPath = randomString(32); let dpath = await fileName(firstPath); let uri = 'internal://cache/' + firstPath; - expect(fileio.mkdirSync(dpath) !== null).assertTrue(); + fileio.mkdirSync(dpath); for (let i = 0; i < 16; i++) { console.info('time' + i); let sonPath = randomString(251); @@ -3788,8 +3775,8 @@ describe('fileTest', function () { let ddpath = dpath + '/File_Get_013dd'; let fpath = dpath + '/File_Get_013f'; let ffpath = ddpath + '/File_Get_013ff'; - expect(fileio.mkdirSync(dpath) !== null).assertTrue(); - expect(fileio.mkdirSync(ddpath) !== null).assertTrue(); + fileio.mkdirSync(dpath); + fileio.mkdirSync(ddpath); expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); expect(prepareFile(ffpath, FILE_CONTENT)).assertTrue(); file.get({ @@ -3803,10 +3790,10 @@ describe('fileTest', function () { console.info('type:' + data.type); console.info('subFiles:' + data.subFiles + '}'); console.info('File_Get_013 => pass'); - expect(fileio.unlinkSync(ffpath) !== null).assertTrue(); - expect(fileio.unlinkSync(fpath) !== null).assertTrue(); - expect(fileio.rmdirSync(ddpath) !== null).assertTrue(); - expect(fileio.rmdirSync(dpath) !== null).assertTrue(); + fileio.unlinkSync(ffpath); + fileio.unlinkSync(fpath); + fileio.rmdirSync(ddpath); + fileio.rmdirSync(dpath); done(); }, fail: function (data, code) { @@ -3844,3 +3831,4 @@ describe('fileTest', function () { }); }); }); +} diff --git a/storage/storagefilejstest/src/main/js/default/test/List.test.js b/storage/storagefilejstest/src/main/js/test/List.test.js similarity index 86% rename from storage/storagefilejstest/src/main/js/default/test/List.test.js rename to storage/storagefilejstest/src/main/js/test/List.test.js index c2671eb8018479b176ad42c417e1686f945c0d81..310b09786bf19ae54b383d380b7238beda6041ba 100644 --- a/storage/storagefilejstest/src/main/js/default/test/List.test.js +++ b/storage/storagefilejstest/src/main/js/test/List.test.js @@ -13,4 +13,7 @@ * limitations under the License. */ -require('./File.test.js') +import fileTest from './File.test.js' +export default function testsuite() { + fileTest() +} diff --git a/storage/storagefilejstest/src/main/resources/base/element/string.json b/storage/storagefilejstest/src/main/resources/base/element/string.json index 2f1b420896d5575a11941c0bc2fcec8765ccd561..9d3fa1bb64c9d599c1fe17b05e95900b0eea025c 100644 --- a/storage/storagefilejstest/src/main/resources/base/element/string.json +++ b/storage/storagefilejstest/src/main/resources/base/element/string.json @@ -2,11 +2,27 @@ "string": [ { "name": "app_name", - "value": "Storagefilejstest" + "value": "storagefilejstest" }, { "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 +}