diff --git a/storage/BUILD.gn b/storage/BUILD.gn index ea773fd18e9815557e97fa0f125bcc4ef63868c1..76d7c1ed6cfdfbfc6045f887b35eadb1e0750877 100644 --- a/storage/BUILD.gn +++ b/storage/BUILD.gn @@ -15,6 +15,14 @@ import("//test/xts/tools/build/suite.gni") group("storage") { testonly = true if (is_standard_system) { - deps = [ "storagefileiojstest:storagefileio_js_test" ] + deps = [ + "storagefileconcurrentjstest:storagefileconcurrent_js_test", + "storagefileioerrorjstest:storagefileioerror_js_test", + "storagefileiojstest:storagefileio_js_test", + "storagefileioperformancejstest:storagefileioperformance_js_test", + "storagefileioreliabilityjstest:storagefileioreliability_js_test", + "storagefileiostabilityjstest:storagefileiostability_js_test", + "storagefilestabilityjstest:storagefilestability_js_test", + ] } } diff --git a/storage/storageerrorjstest/BUILD.gn b/storage/storageerrorjstest/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..f03e5a5ddd533fa845221f5a687fe896ff7404a9 --- /dev/null +++ b/storage/storageerrorjstest/BUILD.gn @@ -0,0 +1,18 @@ +# 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("//test/xts/tools/build/suite.gni") + +ohos_js_hap_suite("storagefileioerror_js_test") { + test_hap_name = "storagefileioerrorjstest" + hap_source_path = "hap/entry-debug-rich-signed.hap" +} diff --git a/storage/storageerrorjstest/Test.json b/storage/storageerrorjstest/Test.json new file mode 100644 index 0000000000000000000000000000000000000000..1e5f3497ea4b14a8d5330555290b590dc023389b --- /dev/null +++ b/storage/storageerrorjstest/Test.json @@ -0,0 +1,18 @@ +{ + "description": "Configuration for storage file and fileio Tests", + "driver": { + "type": "JSUnitTest", + "test-timeout": "21600000", + "package": "ohos.acts.stroage.fileio", + "shell-timeout": "21600000" + }, + "kits": [ + { + "test-file-name": [ + "storagefileioerrorjstest.hap" + ], + "type": "AppInstallKit", + "cleanup-apps": true + } + ] +} \ No newline at end of file diff --git a/storage/storageerrorjstest/hap/entry-debug-rich-signed.hap b/storage/storageerrorjstest/hap/entry-debug-rich-signed.hap new file mode 100644 index 0000000000000000000000000000000000000000..0f9cb18ddec9a65763600009b7a33822522e1880 Binary files /dev/null and b/storage/storageerrorjstest/hap/entry-debug-rich-signed.hap differ diff --git a/storage/storageerrorjstest/project/entry/package.json b/storage/storageerrorjstest/project/entry/package.json new file mode 100644 index 0000000000000000000000000000000000000000..4cf06fee5959d788e6cb205ae961a5c1cacd65b9 --- /dev/null +++ b/storage/storageerrorjstest/project/entry/package.json @@ -0,0 +1,6 @@ +{ + "devDependencies": { + "chai": "^4.3.4", + "mocha": "^9.0.1" + } +} diff --git a/storage/storageerrorjstest/project/entry/src/main/config.json b/storage/storageerrorjstest/project/entry/src/main/config.json new file mode 100644 index 0000000000000000000000000000000000000000..12fda07721102cdd208f3d9021a250592706579a --- /dev/null +++ b/storage/storageerrorjstest/project/entry/src/main/config.json @@ -0,0 +1,62 @@ +{ + "app": { + "bundleName": "ohos.acts.stroage.fileio", + "vendor": "example", + "version": { + "code": 1000000, + "name": "1.0.0" + }, + "apiVersion": { + "compatible": 4, + "target": 5, + "releaseType": "Release" + } + }, + "deviceConfig": {}, + "module": { + "package": "ohos.acts.stroage.fileio", + "name": ".MyApplication", + "deviceType": [ + "phone" + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "entry", + "moduleType": "entry", + "installationFree": true + }, + "abilities": [ + { + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ], + "name": "ohos.acts.stroage.fileio.MainAbility", + "icon": "$media:icon", + "description": "$string:mainability_description", + "label": "$string:app_name", + "type": "page", + "launchType": "standard", + "visible": true + } + ], + "js": [ + { + "pages": [ + "pages/index/index" + ], + "name": "default", + "window": { + "designWidth": 720, + "autoDesignWidth": false + } + } + ] + } +} \ No newline at end of file diff --git a/storage/storageerrorjstest/project/entry/src/main/js/default/app.js b/storage/storageerrorjstest/project/entry/src/main/js/default/app.js new file mode 100644 index 0000000000000000000000000000000000000000..5fefaead87d0899fd7e07a2f2241a40bfd298339 --- /dev/null +++ b/storage/storageerrorjstest/project/entry/src/main/js/default/app.js @@ -0,0 +1,8 @@ +export default { + onCreate() { + console.info('ohos.acts.distributeddatamgr.distributedfile onCreate'); + }, + onDestroy() { + console.info('ohos.acts.distributeddatamgr.distributedfile onCreate'); + } +}; diff --git a/storage/storageerrorjstest/project/entry/src/main/js/default/i18n/en-US.json b/storage/storageerrorjstest/project/entry/src/main/js/default/i18n/en-US.json new file mode 100644 index 0000000000000000000000000000000000000000..ead52ed2e09ec82aaf7aa9f4e714ed39ea88308e --- /dev/null +++ b/storage/storageerrorjstest/project/entry/src/main/js/default/i18n/en-US.json @@ -0,0 +1,6 @@ +{ + "strings": { + "hello": "Hello", + "world": "Test" + } +} \ No newline at end of file diff --git a/storage/storageerrorjstest/project/entry/src/main/js/default/i18n/zh-CN.json b/storage/storageerrorjstest/project/entry/src/main/js/default/i18n/zh-CN.json new file mode 100644 index 0000000000000000000000000000000000000000..3f48f2585b24a8fe4a745e8ee2972a9e991a7803 --- /dev/null +++ b/storage/storageerrorjstest/project/entry/src/main/js/default/i18n/zh-CN.json @@ -0,0 +1,6 @@ +{ + "strings": { + "hello": "您好", + "world": "测试" + } +} \ No newline at end of file diff --git a/storage/storageerrorjstest/project/entry/src/main/js/default/pages/index/index.css b/storage/storageerrorjstest/project/entry/src/main/js/default/pages/index/index.css new file mode 100644 index 0000000000000000000000000000000000000000..6fda792753f2e15f22b529c7b90a82185b2770bf --- /dev/null +++ b/storage/storageerrorjstest/project/entry/src/main/js/default/pages/index/index.css @@ -0,0 +1,9 @@ +.container { + flex-direction: column; + justify-content: center; + align-items: center; +} + +.title { + font-size: 100px; +} diff --git a/storage/storageerrorjstest/project/entry/src/main/js/default/pages/index/index.hml b/storage/storageerrorjstest/project/entry/src/main/js/default/pages/index/index.hml new file mode 100644 index 0000000000000000000000000000000000000000..f64b040a5ae394dbaa5e185e1ecd4f4556b92184 --- /dev/null +++ b/storage/storageerrorjstest/project/entry/src/main/js/default/pages/index/index.hml @@ -0,0 +1,5 @@ +
+ + {{ $t('strings.hello') }} {{ title }} + +
diff --git a/storage/storageerrorjstest/project/entry/src/main/js/default/pages/index/index.js b/storage/storageerrorjstest/project/entry/src/main/js/default/pages/index/index.js new file mode 100644 index 0000000000000000000000000000000000000000..572ce6e94d0cd867a15eb94b1b7b0da9497a99b3 --- /dev/null +++ b/storage/storageerrorjstest/project/entry/src/main/js/default/pages/index/index.js @@ -0,0 +1,38 @@ +/* + * 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 file from '@system.file' +import app from '@system.app' + +import {Core} from 'deccjsunit/index' +export default { + 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() { + }, +} \ No newline at end of file diff --git a/storage/storageerrorjstest/project/entry/src/main/js/test/Common.js b/storage/storageerrorjstest/project/entry/src/main/js/test/Common.js new file mode 100644 index 0000000000000000000000000000000000000000..c5bc08482173733896e49c8fab5239bef520ee7c --- /dev/null +++ b/storage/storageerrorjstest/project/entry/src/main/js/test/Common.js @@ -0,0 +1,170 @@ +/* + * 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 '@system.fileio' + +export const FILE_CONTENT = 'hello world' + +export function prepareFile(fpath, content) { + try { + let fd = fileio.openSync(fpath, 0o102, 0o666) + fileio.ftruncateSync(fd) + fileio.writeSync(fd, content) + fileio.fsyncSync(fd) + fileio.closeSync(fd) + return true + } + catch (e) { + console.log('Failed to prepareFile for ' + e) + return false + } +} +export function prepareFile1(fpath, content) { + try { + let fd = fileio.openSync(fpath, 0o102, 0o777) + fileio.ftruncateSync(fd) + fileio.writeSync(fd, content) + fileio.fsyncSync(fd) + fileio.closeSync(fd) + return true + } + catch (e) { + console.log('Failed to prepareFile for ' + e) + return false + } +} +export function prepareEmptyFile(fpath) { + try { + let fd = fileio.openSync(fpath, 0o102, 0o777) + fileio.closeSync(fd) + return true + } + catch (e) { + console.log('Failed to prepareFile for ' + e) + return false + } +} +export function fileToReadOnly(fpath) { + try { + let fd = fileio.openSync(fpath, 0o1) + fileio.fchmodSync(fd, 0o444) + fileio.fsyncSync(fd) + fileio.closeSync(fd) + return true + } + catch (e) { + console.log('Failed to fileToReadOnly for ' + e); + return false + } +} +export function fileToWriteOnly(fpath) { + try { + let fd = fileio.openSync(fpath, 0o2) + fileio.fchmodSync(fd, 0o222) + fileio.fsyncSync(fd) + fileio.closeSync(fd) + return true + } + catch (e) { + console.log('Failed to fileToWriteOnly ' + e) + return false + } +} +export function fileToReadAndWrite(fpath) { + try { + let fd = fileio.openSync(fpath, 0o1) + fileio.fchmodSync(fd, 0o777) + fileio.fsyncSync(fd) + fileio.closeSync(fd) + return true + } + catch (e) { + console.log('Failed to fileToReadAndWrite ' + e); + return false + } +} +export function appName(testName) { + const BASE_PATH = '/data/accounts/account_0/appdata/ohos.acts.stroage.fileio/' + return BASE_PATH + testName +} +export function nextFileName(testName) { + const BASE_PATH = '/data/accounts/account_0/appdata/ohos.acts.stroage.fileio/cache/' + return BASE_PATH + testName +} +export function fileName(testName) { + const BASE_PATH = '/data/accounts/account_0/appdata/ohos.acts.stroage.fileio/files/' + return BASE_PATH + testName +} +export function cacheFileName(testName) { + const BASE_PATH = '/data/accounts/account_0/appdata/ohos.acts.stroage.fileio/files/cache/' + return BASE_PATH + testName +} +export function differentFileName(testName) { + const BASE_PATH = '/data/accounts/account_0/ohos.acts.distributeddatamgr.distributedfile/' + return BASE_PATH + testName +} +export function differentCacheName(testName) { + const BASE_PATH = '/data/accounts/account_0/ohos.acts.distributeddatamgr.distributedfile/cache/' + return BASE_PATH + testName +} + +export function getFileTextLen(fpath) { + let ss + try { + ss = fileio.Stream.createStreamSync(fpath, 'r+') + expect(ss !== null).assertTrue() + let len = ss.readSync(new ArrayBuffer(4096)) + console.log('file:' + fpath) + console.log('file lenth:' + len) + expect(ss.closeSync() !== null).assertTrue() + return len + } + catch (e) { + console.log('Failed to getFileTextLen ' + e) + expect(ss.closeSync() !== null).assertTrue() + return null + } +} +export function isFileExist(fpath) { + try { + expect(fileio.accessSync(fpath) !== null).assertTrue() + console.log('file:' + fpath) + console.log('status:exist') + return true + } + catch (e) { + console.log('file:' + fpath) + console.log('status:non-existen') + return false + } +} +export function sleep(n) { + var start = new Date().getTime(); + while (true) { + if (new Date().getTime() - start > n) { + break; + } + } +} +export function randomString(num) { + let len= num; + var $chars = 'aaaabbbbcccc'; + var maxPos = $chars.length; + var pwd = ''; + for (var i = 0; i < len; i++) { + pwd += $chars.charAt(Math.floor(Math.random() * maxPos)); + } + return pwd; +} diff --git a/storage/storageerrorjstest/project/entry/src/main/js/test/FileError.test.js b/storage/storageerrorjstest/project/entry/src/main/js/test/FileError.test.js new file mode 100644 index 0000000000000000000000000000000000000000..9d10bce6fb499625141f90b4fa26617e8573d50e --- /dev/null +++ b/storage/storageerrorjstest/project/entry/src/main/js/test/FileError.test.js @@ -0,0 +1,341 @@ +/* + * 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 '@system.fileio' +import file from '@system.file'; +import { + describe, + it, + expect +} + from 'deccjsunit/index' +import { + FILE_CONTENT, + prepareFile, + fileName, + randomString, +} + from './Common' + +describe('FileError', function () { + + /** + * @tc.number SUB_STORAGE_File_test_error_0000 + * @tc.name File_test_error_000 + * @tc.desc Function of API, Move files when disk space is full. + * Create the file (file_test_error) in advance and give 777 permission, + * path:/data/accounts/account_0/appdata/ohos.acts.stroage.fileio/files/file_test_error + */ + it('File_test_error_000', 0, async function (done) { + file.move({ + srcUri: 'internal://app/file_test_error', + dstUri: 'internal://cache/file_test_error', + success: function (uri) { + console.log('file_test_error_000 pass, uri:' + uri); + expect(null).assertFail(); + }, + fail: function (data, code) { + console.log('file_test_error_000 call move fail, code: ' + code + ', data: ' + data); + done(); + }, + }); + }); + + /** + * @tc.number SUB_STORAGE_File_test_error_0100 + * @tc.name File_test_error_001 + * @tc.desc Function of API, Copy files when disk space is full. + * Create the file (file_test_error) in advance and give 777 permission, + * path:/data/accounts/account_0/appdata/ohos.acts.stroage.fileio/files/file_test_error + */ + it('File_test_error_001', 0, async function (done) { + file.copy({ + srcUri: 'internal://app/file_test_error', + dstUri: 'internal://cache/file_test_error', + success: function (uri) { + console.log('file_test_error_001 pass, uri:' + uri); + expect(null).assertFail(); + }, + fail: function (data, code) { + console.log('file_test_error_001 call copy fail, code: ' + code + ', data: ' + data); + done(); + }, + }); + }); + + /** + * @tc.number SUB_STORAGE_File_test_error_0200 + * @tc.name File_test_error_002 + * @tc.desc Function of API, Write files when disk space is full. + */ + it('File_test_error_002', 0, async function (done) { + file.writeText({ + uri: 'internal://app/file_test_error', + text: FILE_CONTENT, + success: function () { + console.log('file_test_error_002 call writeText success.'); + expect(null).assertFail(); + }, + fail: function (data, code) { + console.log('file_test_error_002 call writeText fail, code: ' + code + ', data: ' + data); + done(); + }, + }); + }); + + /** + * @tc.number SUB_STORAGE_File_test_error_0300 + * @tc.name File_test_error_003 + * @tc.desc Function of API, Write files when disk space is full. + */ + it('File_test_error_003', 0, async function (done) { + let buf = new Uint8Array([48, 49, 50, 51, 65, 66, 67, 68, 32, 33]); + file.writeArrayBuffer({ + uri: 'internal://app/file_test_error', + buffer: buf, + success: function () { + console.log('file_test_error_003 call writeArrayBuffer success.'); + expect(null).assertFail(); + }, + fail: function (data, code) { + console.log('file_test_error_003 call writeArrayBuffer fail, code: ' + code + ', data: ' + data); + done(); + }, + }); + }); + + /** + * @tc.number SUB_STORAGE_File_test_error_0400 + * @tc.name File_test_error_004 + * @tc.desc Function of API, When inode is full, verify the folder creation function + */ + it('File_test_error_004', 0, async function (done) { + file.mkdir({ + uri: 'internal://app/file_test_error004d', + success: function () { + console.log('file_test_error_004 call mkdir success.'); + expect(null).assertFail(); + }, + fail: function (data, code) { + console.log('file_test_error_004 call mkdir fail, code: ' + code + ', data: ' + data); + done(); + }, + }); + }); + + /** + * @tc.number SUB_STORAGE_File_test_error_0500 + * @tc.name File_test_error_005 + * @tc.desc Function of API, Prerequisites create file 200M,When ram is filled to + * the remaining 100m, verify the function of reading 200m files + */ + it('File_test_error_005', 0, async function (done) { + file.readText({ + uri: 'internal://app/file_test_error_005', + success: function (data) { + console.log('file_test_error_005 pass, Content:' + data.text); + done(); + }, + fail: function (data, code) { + console.log('file_test_error_005 call readText fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + }); + + /** + * @tc.number SUB_STORAGE_File_test_error_0600 + * @tc.name File_test_error_006 + * @tc.desc Function of API, Prerequisites create file 200M,When ram is filled to + * the remaining 100m, verify the function of reading 200m files + */ + it('File_test_error_006', 0, async function (done) { + file.readArrayBuffer({ + uri: 'internal://app/file_test_error_006', + success: function (data) { + console.log('file_test_error_006 pass, Content:' + data.buffer); + done(); + }, + fail: function (data, code) { + console.log('file_test_error_006 call readArrayBuffer fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + }); + + /** + * @tc.number SUB_STORAGE_File_test_error_0700 + * @tc.name File_test_error_007 + * @tc.desc Function of API, delete file + */ + it('File_test_error_007', 0, async function (done) { + let fpath = fileName('file_test_error_007'); + expect(prepareFile(fpath, FILE_CONTENT) !== null).assertTrue(); + file.rmdir({ + uri: 'internal://app/file_test_error_007', + recursive: true, + success: function () { + console.log('file_test_error_007 call rmdir success.'); + done(); + }, + fail: function (data, code) { + console.log('file_test_error_007 call rmdir fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + }); + + /** + * @tc.number SUB_STORAGE_File_test_error_0800 + * @tc.name File_test_error_008 + * @tc.desc Function of API, Try to delete the folder while the file in the folder is reading and writing + */ + it('File_test_error_008', 0, async function (done) { + file.writeText({ + uri: 'internal://app/file_test_error_008', + text: randomString(4096), + success: function () { + console.log('file_test_error_008 call mkdir success.'); + done(); + }, + fail: function (data, code) { + console.log('file_test_error_008 call mkdir fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + file.rmdir({ + uri: 'internal://app/file_test_error_008', + success: function () { + console.log('file_test_error_008 call rmdir success.'); + expect(null).assertFail(); + }, + fail: function (data, code) { + console.log('file_test_error_008 call rmdir fail, code: ' + code + ', data: ' + data); + done(); + }, + }); + }); + + /** + * @tc.number SUB_STORAGE_File_test_error_0900 + * @tc.name File_test_error_009 + * @tc.desc Function of API, Delete non empty folder + */ + it('File_test_error_009', 0, async function (done) { + let dpath = fileName('file_test_error_009') + 'd'; + let fpath = dpath + '/file_test_error_009'; + expect(fileio.mkdirSync(dpath) !== null).assertTrue(); + expect(prepareFile(fpath, FILE_CONTENT) !== null).assertTrue(); + file.rmdir({ + uri: 'internal://app/file_test_error_009d', + recursive: true, + success: function () { + console.log('file_test_error_009 call rmdir success.'); + done(); + }, + fail: function (data, code) { + console.log('file_test_error_009 call rmdir fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + }); + + /** + * @tc.number SUB_STORAGE_File_test_error_1000 + * @tc.name File_test_error_010 + * @tc.desc Function of API, Delete non empty folder + */ + it('File_test_error_010', 0, async function (done) { + let dpath = fileName('file_test_error_010') + 'd'; + let fpath = dpath + '/file_test_error_010'; + expect(fileio.mkdirSync(dpath) !== null).assertTrue(); + expect(prepareFile(fpath, FILE_CONTENT) !== null).assertTrue(); + file.rmdir({ + uri: 'internal://app/file_test_error_010d', + recursive: false, + success: function () { + console.log('file_test_error_010 call rmdir success.'); + expect(null).assertFail(); + }, + fail: function (data, code) { + console.log('file_test_error_010 call rmdir fail, code: ' + code + ', data: ' + data); + done(); + }, + }); + }); + + /** + * @tc.number SUB_STORAGE_File_test_error_1100 + * @tc.name File_test_error_011 + * @tc.desc Function of API, Unsupported same encoding format + */ + it('File_test_error_011', 0, async function (done) { + file.writeText({ + uri: 'internal://app/file_test_error_011', + text: 'hello', + encoding: 'gbk', + success: function () { + console.log('file_test_error_011 call writeText success.'); + expect(null).assertFail(); + }, + fail: function (data, code) { + console.log('file_test_error_011 call writeText fail, code: ' + code + ', data: ' + data); + done(); + }, + }); + }); + + /** + * @tc.number SUB_STORAGE_File_test_error_1200 + * @tc.name File_test_error_012 + * @tc.desc Function of API, Unsupported same encoding format + */ + it('File_test_error_012', 0, async function (done) { + file.writeText({ + uri: 'internal://app/file_test_error_012', + text: 'Text that just for test.', + encoding: 'Utf-8', + success: function () { + console.log('file_test_error_012 call writeText success.'); + done(); + }, + fail: function (data, code) { + console.log('file_test_error_012 call writeText fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + file.readText({ + uri: 'internal://app/file_test_error_012', + encoding: 'GBK', + success: function (data) { + console.log('file_test_error_012 call readText success.' + data.text); + expect(null).assertFail(); + }, + fail: function (data, code) { + console.log('file_test_error_012 call readText fail, code: ' + code + ', data: ' + data); + file.delete({ + uri: 'internal://app/file_test_error_012', + success: function () { + console.log('file_test_error_012 call delete success'); + done(); + }, + fail: function (data, code) { + console.log('file_test_error_012 call delete fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + }, + }); + }); +}); diff --git a/storage/storageerrorjstest/project/entry/src/main/js/test/FileIOError.test.js b/storage/storageerrorjstest/project/entry/src/main/js/test/FileIOError.test.js new file mode 100644 index 0000000000000000000000000000000000000000..8b262bbdbb98724289f41b7288f6703787a48ba2 --- /dev/null +++ b/storage/storageerrorjstest/project/entry/src/main/js/test/FileIOError.test.js @@ -0,0 +1,470 @@ +/* + * 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 '@system.fileio' +import { + describe, + it, + expect +} + from 'deccjsunit/index' +import { + FILE_CONTENT, + prepareFile, + fileName, + nextFileName, + appName, + randomString, +} + from './Common' + +describe('FileIOError', function () { + + /** + * @tc.number SUB_STORAGE_FileIo_test_error_0000 + * @tc.name FileIo_test_error_000 + * @tc.desc Function of API, Copy files when disk space is full + * Create the file (fileio_test_error) in advance and give 777 permission, + * path:/data/accounts/account_0/appdata/ohos.acts.stroage.fileio/cache/fileio_test_error + */ + it('FileIo_test_error_000', 0, function () { + let fpath = nextFileName('fileio_test_error'); + let fpathTarget = appName('fileio_test_error'); + try { + expect(fileio.copyFileSync(fpath, fpathTarget) !== null).assertTrue(); + expect(null).assertFail(); + } + catch (e) { + console.log('fileio_test_error_000 has failed for ' + e); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIo_test_error_0100 + * @tc.name FileIo_test_error_001 + * @tc.desc Function of API, mkdir files when disk space is full + */ + it('FileIo_test_error_001', 0, function () { + let dpath = nextFileName('fileio_test_error_001d'); + try { + expect(fileio.mkdirSync(dpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_error_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIo_test_error_0200 + * @tc.name FileIo_test_error_002 + * @tc.desc Function of API, When inode is full, verify the folder creation function + */ + it('FileIo_test_error_002', 0, function () { + let dpath = fileName('fileio_test_error_002d'); + try { + expect(fileio.mkdirSync(dpath) !== null).assertTrue(); + expect(null).assertFail(); + } + catch (e) { + console.log('fileio_test_error_002 has failed for ' + e); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIo_test_error_0300 + * @tc.name FileIo_test_error_003 + * @tc.desc Function of API, When the disk space is full, verify the synchronous write file data function + */ + it('FileIo_test_error_003', 0, function () { + let fpath = nextFileName('fileio_test_error_003'); + try { + let fd = fileio.openSync(fpath, 0o102, 0o777); + expect(fd !== null).assertTrue(); + expect(fileio.writeSync(fd, FILE_CONTENT) !== null).assertTrue(); + expect(fileio.closeSync(fd) !== null).assertTrue(); + expect(null).assertFail(); + } + catch (e) { + console.log('fileio_test_error_003 has failed for ' + e); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIo_test_error_0400 + * @tc.name FileIo_test_error_004 + * @tc.desc Function of API, When the disk space is full, verify synchronization and write the buffer data back to the disk for data synchronization + */ + it('FileIo_test_error_004', 0, function () { + let fpath = nextFileName('fileio_test_error_004'); + try { + let fd = fileio.openSync(fpath, 0o102, 0o777); + expect(fd !== null).assertTrue(); + expect(fileio.fsyncSync(fd) !== null).assertTrue(); + expect(fileio.closeSync(fd) !== null).assertTrue(); + expect(null).assertFail(); + } + catch (e) { + console.log('fileio_test_error_004 has failed for ' + e); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIo_test_error_0500 + * @tc.name FileIo_test_error_005 + * @tc.desc Function of API, Open 200m file function when there is 100m left in RAM + * Create a 200m file (fileio_test_error_005) and grant 777 permissions, + * path:/data/accounts/account_0/appdata/ohos.acts.stroage.fileio/cache/fileio_test_error_005 + */ + it('FileIo_test_error_005', 0, function () { + let fpath = nextFileName('fileio_test_error_005'); + try { + let fd = fileio.openSync(fpath); + expect(fd !== null).assertTrue(); + expect(fileio.closeSync(fd) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_error_005 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIo_test_error_0600 + * @tc.name FileIo_test_error_006 + * @tc.desc Function of API, Read 200m file function when there is 100m left in RAM + * Create a 200m file (fileio_test_error_005) and grant 777 permissions, + * path:/data/accounts/account_0/appdata/ohos.acts.stroage.fileio/cache/fileio_test_error_005 + */ + it('FileIo_test_error_006', 0, function () { + let fpath = nextFileName('fileio_test_error_005'); + try { + let fd = fileio.openSync(fpath); + expect(fd !== null).assertTrue(); + let rlen = fileio.readSync(fd, new ArrayBuffer(209715200)); + expect(rlen == 209715200).assertTrue(); + expect(fileio.closeSync(fd) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_error_006 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIo_test_error_0700 + * @tc.name FileIo_test_error_007 + * @tc.desc Function of API, Verify the function of obtaining 200m file stream synchronously when 100m ram is left + * Create a 200m file (fileio_test_error_005) and grant 777 permissions, + * path:/data/accounts/account_0/appdata/ohos.acts.stroage.fileio/cache/fileio_test_error_005 + */ + it('FileIo_test_error_007', 0, function () { + let fpath = nextFileName('fileio_test_error_005'); + try { + let ss = fileio.createStreamSync(fpath, 'r+'); + expect(ss !== null).assertTrue(); + expect(ss.closeSync() !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_error_007 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIo_test_error_0800 + * @tc.name FileIo_test_error_008 + * @tc.desc Function of API, Read 200m file function when there is 100m left in RAM + * Create a 200m file (fileio_test_error_005) and grant 777 permissions, + * path:/data/accounts/account_0/appdata/ohos.acts.stroage.fileio/cache/fileio_test_error_005 + */ + it('FileIo_test_error_008', 0, function () { + let fpath = nextFileName('fileio_test_error_005'); + try { + let ss = fileio.createStreamSync(fpath, 'r+'); + expect(ss !== null).assertTrue(); + let rlen = ss.readSync(new ArrayBuffer(209715200)); + expect(rlen == 209715200).assertTrue(); + expect(ss.closeSync() !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_error_008 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIo_test_error_0900 + * @tc.name FileIo_test_error_009 + * @tc.desc Function of API, Delete directories with files + */ + it('FileIo_test_error_009', 0, function () { + let dpath = fileName('fileio_test_error_009d'); + let fpath = dpath + '/fileio_test_error_009f'; + fileio.mkdirSync(dpath); + prepareFile(fpath, 'hello'); + try { + expect(fileio.rmdirSync(dpath) !== null).assertTrue(); + expect(null).assertFail(); + } + catch (e) { + console.log('fileio_test_error_009 has failed for ' + e); + fileio.unlinkSync(fpath); + fileio.rmdirSync(dpath); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIo_test_error1000 + * @tc.name FileIo_test_error_010 + * @tc.desc Function of API, delete file + */ + it('FileIo_test_error_010', 0, function () { + let fpath = fileName('fileio_test_error_010f'); + prepareFile(fpath, 'hello'); + try { + expect(fileio.rmdirSync(fpath) !== null).assertTrue(); + expect(null).assertFail(); + } + catch (e) { + console.log('fileio_test_error_010 has failed for ' + e); + fileio.unlinkSync(fpath); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIo_test_error_1100 + * @tc.name FileIo_test_error_011 + * @tc.desc Function of API, Pass in a path that exceeds 4096 bytes to copy the file + */ + it('FileIo_test_error_011', 0, function () { + let fpath = nextFileName('fileio_test_error_011'); + fileio.openSync(fpath, 0o102, 0o777); + let dpath = nextFileName('fileio_error_011d'); + fileio.mkdirSync(dpath); + try { + for (let i = 0; i < 16; i++) { + if (i == 15) { + let fpathTarget = dpath + '/f' + randomString(248); + expect(fileio.copyFileSync(fpath, fpathTarget) !== null).assertTrue(); + console.log((i + 1) + ' copy success'); + expect(null).assertFail(); + } else { + dpath = dpath + '/d' + randomString(248); + fileio.mkdirSync(dpath); + console.log((i + 1) + ' mkdir success'); + } + } + } + catch (e) { + console.log('fileio_test_error_011 has failed for ' + e); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIo_test_error_0120 + * @tc.name FileIo_test_error_012 + * @tc.desc Function of API, flags=0o102. The test file is exist. + */ + it('FileIo_test_error_012', 0, function () { + let fpath = nextFileName('FileIo_test_error_012'); + prepareFile(fpath, FILE_CONTENT); + try { + fileio.openSync(fpath, 0o102); + expect(null).assertFail(); + } + catch (e) { + console.log('FileIo_test_error_012 has failed for ' + e); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_OpenSync_0130 + * @tc.name FileIo_test_error_013 + * @tc.desc Function of API, flags=0o102 + */ + it('FileIo_test_error_013', 0, function () { + let fpath = nextFileName('FileIo_test_error_013'); + try { + fileio.openSync(fpath, 0o102); + expect(null).assertFail(); + } + catch (e) { + console.log('FileIo_test_error_013 has failed for ' + e); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_OpenSync_0140 + * @tc.name FileIo_test_error_014 + * @tc.desc Function of API, flags=0o202. The test file is exist. + */ + it('FileIo_test_error_014', 0, function () { + let fpath = nextFileName('FileIo_test_error_014'); + prepareFile(fpath, FILE_CONTENT); + try { + fileio.openSync(fpath, 0o202); + expect(null).assertFail(); + } + catch (e) { + console.log('FileIo_test_error_014 has failed for ' + e); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_OpenSync_0150 + * @tc.name FileIo_test_error_015 + * @tc.desc Function of API, flags=0o302. The test file is exist. + */ + it('FileIo_test_error_015', 0, function () { + let fpath = nextFileName('FileIo_test_error_015'); + prepareFile(fpath, FILE_CONTENT); + try { + fileio.openSync(fpath, 0o302); + expect(null).assertFail(); + } + catch (e) { + console.log('FileIo_test_error_015 has failed for ' + e); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_OpenSync_0160 + * @tc.name FileIo_test_error_016 + * @tc.desc Function of API, flags=0o100002. The test file is exist. + */ + it('FileIo_test_error_016', 0, function () { + let fpath = nextFileName('FileIo_test_error_016'); + prepareFile(fpath, FILE_CONTENT); + try { + fileio.openSync(fpath, 0o100002); + expect(null).assertFail(); + } + catch (e) { + console.log('FileIo_test_error_016 has failed for ' + e); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_OpenSync_0170 + * @tc.name FileIo_test_error_017 + * @tc.desc Function of API, flags=0o40002 The test file is exist. + */ + it('FileIo_test_error_017', 0, function () { + let dpath = nextFileName('FileIo_test_error_017'); + expect(fileio.mkdirSync(dpath) !== null).assertTrue(); + try { + fileio.openSync(dpath, 0o40002); + expect(null).assertFail(); + } + catch (e) { + console.log('FileIo_test_error_017 has failed for ' + e); + expect(fileio.rmdirSync(dpath) !== null).assertTrue(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_OpenSync_0180 + * @tc.name FileIo_test_error_018 + * @tc.desc Function of API, flags=0o20040002. The test file is exist. + */ + it('FileIo_test_error_018', 0, function () { + let fpath = nextFileName('FileIo_test_error_018'); + try { + fileio.openSync(fpath, 0o20040002); + expect(null).assertFail(); + } + catch (e) { + console.log('FileIo_test_error_018 has failed for ' + e); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_OpenSync_0190 + * @tc.name FileIo_test_error_019 + * @tc.desc Function of API, flags=0o400002. The test file is exist. + */ + it('FileIo_test_error_019', 0, function () { + let fpath = nextFileName('FileIo_test_error_019'); + let txt = 'h' + prepareFile(fpath, txt); + try { + fileio.openSync(fpath, 0o400002); + expect(null).assertFail(); + } + catch (e) { + console.log('FileIo_test_error_019 has failed for ' + e); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_OpenSync_0200 + * @tc.name FileIo_test_error_020 + * @tc.desc Function of API, flags=0o400002. The test file is exist. + */ + it('FileIo_test_error_020', 0, function () { + let fpath = nextFileName('FileIo_test_error_020'); + let txt = randomString(5000); + prepareFile(fpath, txt); + try { + fileio.openSync(fpath, 0o400002); + expect(null).assertFail(); + } + catch (e) { + console.log('FileIo_test_error_020 has failed for ' + e); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_OpenSync_0210 + * @tc.name FileIo_test_error_021 + * @tc.desc Function of API, flags=0o10000102. The test file is exist. + */ + it('FileIo_test_error_021', 0, function () { + let fpath = nextFileName('FileIo_test_error_021'); + try { + fileio.openSync(fpath, 0o10000102); + expect(null).assertFail(); + } + catch (e) { + console.log('FileIo_test_error_021 has failed for ' + e); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_OpenSync_0220 + * @tc.name FileIo_test_error_022 + * @tc.desc Function of API,mode=1 The test file is exist. + */ + it('FileIo_test_error_022', 0, function () { + let fpath = nextFileName('FileIo_test_error_022'); + prepareFile(fpath, FILE_CONTENT); + let fpathTarget = fpath + 'f1'; + try { + fileio.copyFileSync(fpath, fpathTarget, 1); + expect(null).assertFail(); + } + catch (e) { + console.log('FileIo_test_error_021 has failed for ' + e); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + }); + +}); diff --git a/storage/storageerrorjstest/project/entry/src/main/js/test/FileVirtualPath.test.js b/storage/storageerrorjstest/project/entry/src/main/js/test/FileVirtualPath.test.js new file mode 100644 index 0000000000000000000000000000000000000000..dcffe71655ded51570b15f386fce74dbb4bfbb75 --- /dev/null +++ b/storage/storageerrorjstest/project/entry/src/main/js/test/FileVirtualPath.test.js @@ -0,0 +1,528 @@ +/* + * 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 '@system.fileio'; +import file from '@system.file'; +import { + describe, + it, + expect +} + from 'deccjsunit/index' +import { + FILE_CONTENT, + prepareFile, + fileName, +} + from './Common' + +describe('fileVirtualPath', function () { + + /** + * @tc.number SUB_STORAGE_File_Delete_0900 + * @tc.name File_Delete_009 + * @tc.desc Function of API, virtual path, Delete files from outside the package. + * create directory and grant 777 permission: + * /data/accounts/account_0/appdata/ohos.acts.distributeddatamgr.distributedfile + */ + it('File_Delete_009', 0, async function (done) { + file.writeText({ + uri: 'internal://app/../../ohos.acts.distributeddatamgr.distributedfile/File_Delete_009', + text: 'sawyerwang', + success: function () { + console.log('File_Delete_009 mkdir success'); + done(); + }, + fail: function (data, code) { + console.log('File_Delete_009 , code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + file.delete({ + uri: 'internal://app/../../ohos.acts.distributeddatamgr.distributedfile/File_Delete_009', + success: function () { + console.log('File_Delete_009 call delete success'); + done(); + }, + fail: function (data, code) { + console.log(code); + expect(null).assertFail(); + }, + }); + }); + + /** + * @tc.number SUB_STORAGE_File_Delete_1000 + * @tc.name File_Delete_010 + * @tc.desc Function of API, virtual path, Delete files from outside the package. + * Create files and maintain file permissions(755):/data/accounts/account_0/appdata/123456 + */ + it('File_Delete_010', 0, async function (done) { + file.delete({ + uri: 'internal://app/../../123456', + success: function () { + console.log('File_Delete_010 => pass'); + expect(null).assertFail(); + }, + fail: function (data, code) { + console.log('File_Delete_010 => fail ,code: ' + code + ', data: ' + data); + expect(code == 300).assertTrue(); + done(); + }, + }); + }); + + /** + * @tc.number SUB_STORAGE_File_writeText_1200 + * @tc.name File_writeText_012 + * @tc.desc Function of API, virtual path, Write files from outside the package. + * create directory and grant 777 permission: + * /data/accounts/account_0/appdata/ohos.acts.distributeddatamgr.distributedfile + */ + it('File_writeText_012', 0, async function (done) { + file.writeText({ + uri: 'internal://app/../../ohos.acts.distributeddatamgr.distributedfile/File_writeText_012', + text: 'sawyerwang', + success: function () { + console.log('File_writeText_012 mkdir success'); + done(); + }, + fail: function (data, code) { + console.log('File_writeText_012 , code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + file.readText({ + uri: 'internal://app/../../ohos.acts.distributeddatamgr.distributedfile/File_writeText_012', + success: function (data) { + console.log('File_writeText_012 => call readText pass, ' + data.text); + done(); + }, + fail: function (data, code) { + console.log('File_writeText_012 call readText callback fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + file.delete({ + uri: 'internal://app/../../ohos.acts.distributeddatamgr.distributedfile/File_writeText_012', + success: function () { + console.log('File_writeText_012 delete success'); + done(); + }, + fail: function (data, code) { + console.log('File_writeText_012 call delete callback fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + }); + + /** + * @tc.number SUB_STORAGE_File_writeArrayBuffer_1100 + * @tc.name File_writeArrayBuffer_011 + * @tc.desc Function of API, virtual path, Write files from outside the package. + * create directory and grant 777 permission: + * /data/accounts/account_0/appdata/ohos.acts.distributeddatamgr.distributedfile + */ + it('File_writeArrayBuffer_011', 0, async function (done) { + let buf = new Uint8Array([48, 49, 50, 51, 65, 66, 67, 68, 32, 33]); + file.writeArrayBuffer({ + uri: 'internal://app/../../ohos.acts.distributeddatamgr.distributedfile/File_writeArrayBuffer_011', + buffer: buf, + append: true, + success: function () { + console.log('File_writeArrayBuffer_011 call writeArrayBuffer success.'); + done(); + }, + fail: function (data, code) { + console.log('File_writeArrayBuffer_011 , code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + file.readArrayBuffer({ + uri: 'internal://app/../../ohos.acts.distributeddatamgr.distributedfile/File_writeArrayBuffer_011', + success: function (data) { + console.log('File_writeArrayBuffer_011 readArrayBuffer: call success' + data.buffer); + done(); + }, + fail: function (data, code) { + console.log('File_writeArrayBuffer_011 readArrayBuffer , code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + file.delete({ + uri: 'internal://app/../../ohos.acts.distributeddatamgr.distributedfile/File_writeArrayBuffer_011' + }); + }); + + /** + * @tc.number SUB_STORAGE_File_readText_0800 + * @tc.name File_readText_008 + * @tc.desc Function of API, virtual path, Read files from outside the package. + * create directory and grant 777 permission: + * /data/accounts/account_0/appdata/ohos.acts.distributeddatamgr.distributedfile + */ + it('File_readText_008', 0, async function (done) { + file.writeText({ + uri: 'internal://app/../../ohos.acts.distributeddatamgr.distributedfile/File_readText_008', + text: 'Text that just for test.', + success: function () { + console.log('File_readText_008 call writeText success.'); + done(); + }, + fail: function (data, code) { + console.log('File_readText_008 call writeText callback fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + file.readText({ + uri: 'internal://app/../../ohos.acts.distributeddatamgr.distributedfile/File_readText_008', + success: function (data) { + console.log('File_readText_008 call readText success. data.text:' + data.text); + done(); + }, + fail: function (data, code) { + console.log('File_readText_008 call readText callback fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + file.delete({ + uri: 'internal://app/../../ohos.acts.distributeddatamgr.distributedfile/File_readText_008' + }); + }); + + /** + * @tc.number SUB_STORAGE_File_readText_0900 + * @tc.name File_readText_009 + * @tc.desc Function of API, virtual path, Read files from outside the package. + * Create files and maintain file permissions(755):/data/accounts/account_0/appdata/123456 + */ + it('File_readText_009', 0, async function (done) { + file.readText({ + uri: 'internal://app/../../123456', + success: function (data) { + console.log('File_readText_009 => pass, data.text:' + data.text); + done(); + }, + fail: function (data, code) { + console.log('File_readText_009 call readText callback fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + }); + + /** + * @tc.number SUB_STORAGE_File_read_array_buffer_1000 + * @tc.name File_read_array_buffer_010 + * @tc.desc Function of API, virtual path, Read files from outside the package. + * create directory and grant 777 permission: + * /data/accounts/account_0/appdata/ohos.acts.distributeddatamgr.distributedfile + */ + it('File_read_array_buffer_010', 0, async function (done) { + var buffer = new Uint8Array([48, 49, 50, 51, 65, 66, 67, 68, 32, 33]); + file.writeArrayBuffer({ + uri: 'internal://cache/../../ohos.acts.distributeddatamgr.distributedfile/File_read_array_buffer_010', + buffer: buffer, + success: function () { + console.log('File_read_array_buffer_010 call writeArrayBuffer success.'); + done(); + }, + fail: function (data, code) { + console.log('File_read_array_buffer_010 , code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + file.readArrayBuffer({ + uri: 'internal://cache/../../ohos.acts.distributeddatamgr.distributedfile/File_read_array_buffer_010', + position: 0, + length: 10, + success: function (data) { + console.log('File_read_array_buffer_010 call readArrayBuffer success. data.buffer:' + data.buffer); + done(); + }, + fail: function (data, code) { + console.log('File_read_array_buffer_010 , code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + file.delete({ + uri: 'internal://cache/../../ohos.acts.distributeddatamgr.distributedfile/File_read_array_buffer_010' + }); + }); + + /** + * @tc.number SUB_STORAGE_File_read_array_buffer_1100 + * @tc.name File_read_array_buffer_011 + * @tc.desc Function of API, virtual path, Read files from outside the package. + * Create files and maintain file permissions(755):/data/accounts/account_0/appdata/123456 + */ + it('File_read_array_buffer_011', 0, async function (done) { + file.readArrayBuffer({ + uri: 'internal://cache/../../123456', + position: 0, + length: 10, + success: function (data) { + console.log('File_read_array_buffer_011 => pass, data.buffer: ' + data.buffer); + done(); + }, + fail: function (data, code) { + console.log('File_read_array_buffer_011 , code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + }); + + /** + * @tc.number SUB_STORAGE_File_access_0900 + * @tc.name File_access_009 + * @tc.desc Function of API, virtual path, Determine whether files outside the package exist. + * create directory and grant 777 permission: + * /data/accounts/account_0/appdata/ohos.acts.distributeddatamgr.distributedfile + */ + it('File_access_009', 0, async function (done) { + file.writeText({ + uri: 'internal://cache/../../ohos.acts.distributeddatamgr.distributedfile/File_access_009', + text: 'Text that just for test.', + success: function () { + console.log('File_access_009 mkdir success.'); + done(); + }, + fail: function (data, code) { + console.log('File_access_009 fail,code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + file.access({ + uri: 'internal://cache/../../ohos.acts.distributeddatamgr.distributedfile/File_access_009', + success: function () { + console.log('File_access_009 call access success.'); + done(); + }, + fail: function (data, code) { + console.log('File_access_009 , code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + file.delete({ + uri: 'internal://cache/../../ohos.acts.distributeddatamgr.distributedfile/File_access_009', + success: function () { + console.log('File_access_009 call delete success.'); + done(); + }, + fail: function (data, code) { + console.log('File_access_009 , code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + }); + + /** + * @tc.number SUB_STORAGE_File_access_1000 + * @tc.name File_access_010 + * @tc.desc Function of API, virtual path, Determine whether files outside the package exist. + * Create files and maintain file permissions(755): + * /data/accounts/account_0/appdata/123456 + */ + it('File_access_010', 0, async function (done) { + file.access({ + uri: 'internal://cache/../../123456', + success: function () { + console.log('File_access_010 call access success.'); + done(); + }, + fail: function (data, code) { + console.log('File_access_010 , code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + }); + + /** + * @tc.number SUB_STORAGE_File_mkdir_0900 + * @tc.name File_mkdir_009 + * @tc.desc Function of API, virtual path, Create directory outside package. + * create directory and grant 777 permission: + * /data/accounts/account_0/appdata/ohos.acts.distributeddatamgr.distributedfile + */ + it('File_mkdir_009', 0, async function (done) { + file.mkdir({ + uri: 'internal://app/../../ohos.acts.distributeddatamgr.distributedfile/File_mkdir_009', + success: function () { + console.log('File_mkdir_009 call mkdir success.'); + done(); + }, + fail: function (data, code) { + console.log('File_mkdir_009 call mkdir callback fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + file.rmdir({ + uri: 'internal://app/../../ohos.acts.distributeddatamgr.distributedfile/File_mkdir_009', + success: function () { + console.log('File_mkdir_009 call rmdir success.'); + done(); + }, + fail: function (data, code) { + console.log('File_mkdir_009 call rmdir callback fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + }); + + /** + * @tc.number SUB_STORAGE_File_rmdir_0900 + * @tc.name File_rmdir_009 + * @tc.desc Function of API, virtual path, Delete directory outside package. + * create directory and grant 777 permission: + * /data/accounts/account_0/appdata/ohos.acts.distributeddatamgr.distributedfile + */ + it('File_rmdir_009', 0, async function (done) { + file.mkdir({ + uri: 'internal://app/../../ohos.acts.distributeddatamgr.distributedfile/File_rmdir_009', + success: function () { + console.log('File_rmdir_009 call mkdir success.'); + done(); + }, + fail: function (data, code) { + console.log('File_rmdir_009 call mkdir callback fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + file.rmdir({ + uri: 'internal://app/../../ohos.acts.distributeddatamgr.distributedfile/File_rmdir_009', + success: function () { + console.log('File_rmdir_009 call rmdir success.'); + done(); + }, + fail: function (data, code) { + console.log('File_rmdir_009 call rmdir callback fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + }); + + /** + * @tc.number SUB_STORAGE_File_Move_1300 + * @tc.name File_Move_013 + * @tc.desc Function of API, virtual path, Move files out of package. + * create directory and grant 777 permission: + * /data/accounts/account_0/appdata/ohos.acts.distributeddatamgr.distributedfile + */ + it('File_Move_013', 0, async function (done) { + let srcFpath = fileName('File_Move_013'); + expect(prepareFile(srcFpath, FILE_CONTENT) !== null).assertTrue(); + file.move({ + srcUri: 'internal://app/../files/File_Move_013', + dstUri: 'internal://app/../../ohos.acts.distributeddatamgr.distributedfile/File_Move_013', + success: function (uri) { + console.log('File_Move_013 => pass,uri: ' + uri); + done(); + }, + fail: function (data, code) { + console.log('File_Move_013 , code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + }); + + /** + * @tc.number SUB_STORAGE_File_Copy_1300 + * @tc.name File_Copy_013 + * @tc.desc Function of API, virtual path, Copy files out of package. + * create directory and grant 777 permission: + * /data/accounts/account_0/appdata/ohos.acts.distributeddatamgr.distributedfile + */ + it('File_Copy_013', 0, async function (done) { + let srcFpath = fileName('File_Copy_013'); + expect(prepareFile(srcFpath, 'test') !== null).assertTrue(); + file.copy({ + srcUri: 'internal://app/../files/File_Copy_013', + dstUri: 'internal://app/../../ohos.acts.distributeddatamgr.distributedfile/File_Copy_013', + success: function (uri) { + console.log('File_Copy_013=> pass uri:' + uri); + done(); + }, + fail: function (data, code) { + console.log('File_Copy_013 , code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + }); + + /** + * @tc.number SUB_STORAGE_File_List_1500 + * @tc.name File_List_015 + * @tc.desc Function of API, virtual path, Query the files in the directory outside the package. + * create directory and grant 777 permission: + * /data/accounts/account_0/appdata/ohos.acts.distributeddatamgr.distributedfile + */ + it('File_List_015', 0, async function (done) { + file.writeText({ + uri: 'internal://cache/../../ohos.acts.distributeddatamgr.distributedfile/File_List_015', + text: 'Text that just for test.', + success: function () { + console.log('File_List_015 mkdir success.'); + done(); + }, + fail: function (data, code) { + console.log('File_List_015 fail,code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + file.writeText({ + uri: 'internal://cache/../../ohos.acts.distributeddatamgr.distributedfile/File_List_015_1', + text: 'Text that just for test.', + success: function () { + console.log('File_List_015_1 mkdir success.'); + done(); + }, + fail: function (data, code) { + console.log('File_List_015_1 fail,code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + file.list({ + uri: 'internal://app/../../ohos.acts.distributeddatamgr.distributedfile', + success: function (data) { + console.log('File_List_015 => pass' + JSON.stringify(data.fileList)); + done(); + }, + fail: function (data, code) { + console.log('File_List_015 , code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + }); + + /** + * @tc.number SUB_STORAGE_File_List_1500 + * @tc.name File_List_015 + * @tc.desc Function of API, virtual path, Query the files in the directory outside the package. + * create directory and grant 777 permission: + * /data/accounts/account_0/appdata/ohos.acts.distributeddatamgr.distributedfile + */ + it('File_Get_017', 0, async function (done) { + file.get({ + uri: 'internal://app/../../ohos.acts.distributeddatamgr.distributedfile', + success: function (data) { + console.log('File_Get_017 => pass'); + done(); + }, + fail: function (data, code) { + console.log('File_Get_017 , code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + }); + +}); diff --git a/storage/storageerrorjstest/project/entry/src/main/js/test/List.test.js b/storage/storageerrorjstest/project/entry/src/main/js/test/List.test.js new file mode 100644 index 0000000000000000000000000000000000000000..8763126afd199f6c79afc4a1276c2dcabab37d69 --- /dev/null +++ b/storage/storageerrorjstest/project/entry/src/main/js/test/List.test.js @@ -0,0 +1,18 @@ +/* + * 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('./FileIOError.test.js') +require('./FileError.test.js') +require('./FileVirtualPath.test.js') diff --git a/storage/storagefileconcurrentjstest/BUILD.gn b/storage/storagefileconcurrentjstest/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..1c8d7d293e24e7c4f2829bd88a54ba0cd0e9b9bd --- /dev/null +++ b/storage/storagefileconcurrentjstest/BUILD.gn @@ -0,0 +1,18 @@ +# 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("//test/xts/tools/build/suite.gni") + +ohos_js_hap_suite("storagefileconcurrent_js_test") { + test_hap_name = "storagefileconcurrentjstest" + hap_source_path = "hap/entry-debug-rich-signed.hap" +} diff --git a/storage/storagefileconcurrentjstest/Test.json b/storage/storagefileconcurrentjstest/Test.json new file mode 100644 index 0000000000000000000000000000000000000000..2b6bec9567ae6884bd5442cf60c0fad23f4d2cc5 --- /dev/null +++ b/storage/storagefileconcurrentjstest/Test.json @@ -0,0 +1,18 @@ +{ + "description": "Configuration for storage file and fileio Tests", + "driver": { + "type": "JSUnitTest", + "test-timeout": "21600000", + "package": "ohos.acts.stroage.fileio", + "shell-timeout": "21600000" + }, + "kits": [ + { + "test-file-name": [ + "storagefileconcurrentjstest.hap" + ], + "type": "AppInstallKit", + "cleanup-apps": true + } + ] +} \ No newline at end of file diff --git a/storage/storagefileconcurrentjstest/hap/entry-debug-rich-signed.hap b/storage/storagefileconcurrentjstest/hap/entry-debug-rich-signed.hap new file mode 100644 index 0000000000000000000000000000000000000000..f50cd112701e2db182fcd0a96f610b15e452a36f Binary files /dev/null and b/storage/storagefileconcurrentjstest/hap/entry-debug-rich-signed.hap differ diff --git a/storage/storagefileconcurrentjstest/project/entry/package.json b/storage/storagefileconcurrentjstest/project/entry/package.json new file mode 100644 index 0000000000000000000000000000000000000000..4cf06fee5959d788e6cb205ae961a5c1cacd65b9 --- /dev/null +++ b/storage/storagefileconcurrentjstest/project/entry/package.json @@ -0,0 +1,6 @@ +{ + "devDependencies": { + "chai": "^4.3.4", + "mocha": "^9.0.1" + } +} diff --git a/storage/storagefileconcurrentjstest/project/entry/src/main/config.json b/storage/storagefileconcurrentjstest/project/entry/src/main/config.json new file mode 100644 index 0000000000000000000000000000000000000000..12fda07721102cdd208f3d9021a250592706579a --- /dev/null +++ b/storage/storagefileconcurrentjstest/project/entry/src/main/config.json @@ -0,0 +1,62 @@ +{ + "app": { + "bundleName": "ohos.acts.stroage.fileio", + "vendor": "example", + "version": { + "code": 1000000, + "name": "1.0.0" + }, + "apiVersion": { + "compatible": 4, + "target": 5, + "releaseType": "Release" + } + }, + "deviceConfig": {}, + "module": { + "package": "ohos.acts.stroage.fileio", + "name": ".MyApplication", + "deviceType": [ + "phone" + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "entry", + "moduleType": "entry", + "installationFree": true + }, + "abilities": [ + { + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ], + "name": "ohos.acts.stroage.fileio.MainAbility", + "icon": "$media:icon", + "description": "$string:mainability_description", + "label": "$string:app_name", + "type": "page", + "launchType": "standard", + "visible": true + } + ], + "js": [ + { + "pages": [ + "pages/index/index" + ], + "name": "default", + "window": { + "designWidth": 720, + "autoDesignWidth": false + } + } + ] + } +} \ No newline at end of file diff --git a/storage/storagefileconcurrentjstest/project/entry/src/main/js/default/app.js b/storage/storagefileconcurrentjstest/project/entry/src/main/js/default/app.js new file mode 100644 index 0000000000000000000000000000000000000000..5fefaead87d0899fd7e07a2f2241a40bfd298339 --- /dev/null +++ b/storage/storagefileconcurrentjstest/project/entry/src/main/js/default/app.js @@ -0,0 +1,8 @@ +export default { + onCreate() { + console.info('ohos.acts.distributeddatamgr.distributedfile onCreate'); + }, + onDestroy() { + console.info('ohos.acts.distributeddatamgr.distributedfile onCreate'); + } +}; diff --git a/storage/storagefileconcurrentjstest/project/entry/src/main/js/default/i18n/en-US.json b/storage/storagefileconcurrentjstest/project/entry/src/main/js/default/i18n/en-US.json new file mode 100644 index 0000000000000000000000000000000000000000..ead52ed2e09ec82aaf7aa9f4e714ed39ea88308e --- /dev/null +++ b/storage/storagefileconcurrentjstest/project/entry/src/main/js/default/i18n/en-US.json @@ -0,0 +1,6 @@ +{ + "strings": { + "hello": "Hello", + "world": "Test" + } +} \ No newline at end of file diff --git a/storage/storagefileconcurrentjstest/project/entry/src/main/js/default/i18n/zh-CN.json b/storage/storagefileconcurrentjstest/project/entry/src/main/js/default/i18n/zh-CN.json new file mode 100644 index 0000000000000000000000000000000000000000..3f48f2585b24a8fe4a745e8ee2972a9e991a7803 --- /dev/null +++ b/storage/storagefileconcurrentjstest/project/entry/src/main/js/default/i18n/zh-CN.json @@ -0,0 +1,6 @@ +{ + "strings": { + "hello": "您好", + "world": "测试" + } +} \ No newline at end of file diff --git a/storage/storagefileconcurrentjstest/project/entry/src/main/js/default/pages/index/index.css b/storage/storagefileconcurrentjstest/project/entry/src/main/js/default/pages/index/index.css new file mode 100644 index 0000000000000000000000000000000000000000..6fda792753f2e15f22b529c7b90a82185b2770bf --- /dev/null +++ b/storage/storagefileconcurrentjstest/project/entry/src/main/js/default/pages/index/index.css @@ -0,0 +1,9 @@ +.container { + flex-direction: column; + justify-content: center; + align-items: center; +} + +.title { + font-size: 100px; +} diff --git a/storage/storagefileconcurrentjstest/project/entry/src/main/js/default/pages/index/index.hml b/storage/storagefileconcurrentjstest/project/entry/src/main/js/default/pages/index/index.hml new file mode 100644 index 0000000000000000000000000000000000000000..f64b040a5ae394dbaa5e185e1ecd4f4556b92184 --- /dev/null +++ b/storage/storagefileconcurrentjstest/project/entry/src/main/js/default/pages/index/index.hml @@ -0,0 +1,5 @@ +
+ + {{ $t('strings.hello') }} {{ title }} + +
diff --git a/storage/storagefileconcurrentjstest/project/entry/src/main/js/default/pages/index/index.js b/storage/storagefileconcurrentjstest/project/entry/src/main/js/default/pages/index/index.js new file mode 100644 index 0000000000000000000000000000000000000000..572ce6e94d0cd867a15eb94b1b7b0da9497a99b3 --- /dev/null +++ b/storage/storagefileconcurrentjstest/project/entry/src/main/js/default/pages/index/index.js @@ -0,0 +1,38 @@ +/* + * 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 file from '@system.file' +import app from '@system.app' + +import {Core} from 'deccjsunit/index' +export default { + 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() { + }, +} \ No newline at end of file diff --git a/storage/storagefileconcurrentjstest/project/entry/src/main/js/test/Common.js b/storage/storagefileconcurrentjstest/project/entry/src/main/js/test/Common.js new file mode 100644 index 0000000000000000000000000000000000000000..c5bc08482173733896e49c8fab5239bef520ee7c --- /dev/null +++ b/storage/storagefileconcurrentjstest/project/entry/src/main/js/test/Common.js @@ -0,0 +1,170 @@ +/* + * 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 '@system.fileio' + +export const FILE_CONTENT = 'hello world' + +export function prepareFile(fpath, content) { + try { + let fd = fileio.openSync(fpath, 0o102, 0o666) + fileio.ftruncateSync(fd) + fileio.writeSync(fd, content) + fileio.fsyncSync(fd) + fileio.closeSync(fd) + return true + } + catch (e) { + console.log('Failed to prepareFile for ' + e) + return false + } +} +export function prepareFile1(fpath, content) { + try { + let fd = fileio.openSync(fpath, 0o102, 0o777) + fileio.ftruncateSync(fd) + fileio.writeSync(fd, content) + fileio.fsyncSync(fd) + fileio.closeSync(fd) + return true + } + catch (e) { + console.log('Failed to prepareFile for ' + e) + return false + } +} +export function prepareEmptyFile(fpath) { + try { + let fd = fileio.openSync(fpath, 0o102, 0o777) + fileio.closeSync(fd) + return true + } + catch (e) { + console.log('Failed to prepareFile for ' + e) + return false + } +} +export function fileToReadOnly(fpath) { + try { + let fd = fileio.openSync(fpath, 0o1) + fileio.fchmodSync(fd, 0o444) + fileio.fsyncSync(fd) + fileio.closeSync(fd) + return true + } + catch (e) { + console.log('Failed to fileToReadOnly for ' + e); + return false + } +} +export function fileToWriteOnly(fpath) { + try { + let fd = fileio.openSync(fpath, 0o2) + fileio.fchmodSync(fd, 0o222) + fileio.fsyncSync(fd) + fileio.closeSync(fd) + return true + } + catch (e) { + console.log('Failed to fileToWriteOnly ' + e) + return false + } +} +export function fileToReadAndWrite(fpath) { + try { + let fd = fileio.openSync(fpath, 0o1) + fileio.fchmodSync(fd, 0o777) + fileio.fsyncSync(fd) + fileio.closeSync(fd) + return true + } + catch (e) { + console.log('Failed to fileToReadAndWrite ' + e); + return false + } +} +export function appName(testName) { + const BASE_PATH = '/data/accounts/account_0/appdata/ohos.acts.stroage.fileio/' + return BASE_PATH + testName +} +export function nextFileName(testName) { + const BASE_PATH = '/data/accounts/account_0/appdata/ohos.acts.stroage.fileio/cache/' + return BASE_PATH + testName +} +export function fileName(testName) { + const BASE_PATH = '/data/accounts/account_0/appdata/ohos.acts.stroage.fileio/files/' + return BASE_PATH + testName +} +export function cacheFileName(testName) { + const BASE_PATH = '/data/accounts/account_0/appdata/ohos.acts.stroage.fileio/files/cache/' + return BASE_PATH + testName +} +export function differentFileName(testName) { + const BASE_PATH = '/data/accounts/account_0/ohos.acts.distributeddatamgr.distributedfile/' + return BASE_PATH + testName +} +export function differentCacheName(testName) { + const BASE_PATH = '/data/accounts/account_0/ohos.acts.distributeddatamgr.distributedfile/cache/' + return BASE_PATH + testName +} + +export function getFileTextLen(fpath) { + let ss + try { + ss = fileio.Stream.createStreamSync(fpath, 'r+') + expect(ss !== null).assertTrue() + let len = ss.readSync(new ArrayBuffer(4096)) + console.log('file:' + fpath) + console.log('file lenth:' + len) + expect(ss.closeSync() !== null).assertTrue() + return len + } + catch (e) { + console.log('Failed to getFileTextLen ' + e) + expect(ss.closeSync() !== null).assertTrue() + return null + } +} +export function isFileExist(fpath) { + try { + expect(fileio.accessSync(fpath) !== null).assertTrue() + console.log('file:' + fpath) + console.log('status:exist') + return true + } + catch (e) { + console.log('file:' + fpath) + console.log('status:non-existen') + return false + } +} +export function sleep(n) { + var start = new Date().getTime(); + while (true) { + if (new Date().getTime() - start > n) { + break; + } + } +} +export function randomString(num) { + let len= num; + var $chars = 'aaaabbbbcccc'; + var maxPos = $chars.length; + var pwd = ''; + for (var i = 0; i < len; i++) { + pwd += $chars.charAt(Math.floor(Math.random() * maxPos)); + } + return pwd; +} diff --git a/storage/storagefileconcurrentjstest/project/entry/src/main/js/test/FileConcurrent.test.js b/storage/storagefileconcurrentjstest/project/entry/src/main/js/test/FileConcurrent.test.js new file mode 100644 index 0000000000000000000000000000000000000000..3e34851c00c4f742ee51bc42a771c08cf447f52b --- /dev/null +++ b/storage/storagefileconcurrentjstest/project/entry/src/main/js/test/FileConcurrent.test.js @@ -0,0 +1,439 @@ +/* + * 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 '@system.fileio' +import file from '@system.file'; +import { + describe, + beforeAll, + beforeEach, + afterEach, + afterAll, + it, + expect +} + from 'deccjsunit/index' +import { + FILE_CONTENT, + prepareFile, + fileName, + cacheFileName, + getFileTextLen, + isFileExist, + prepareEmptyFile, + randomString +} + from './Common' + +describe('fileconcurrent', function () { + + /** + * @tc.number SUB_STORAGE_file_test_0000 + * @tc.name file_test_0000 Function of API, out of package, Virtual path(create and give 777 authority). + * @tc.desc Function of API, Simultaneous write. + */ + it('file_test_000', 0, async function (done) { + for (let i = 0; i < 10; i++) { + file.writeText({ + uri: 'internal://app/file_test_000', + text: 'Text', + success: function () { + console.log('file_test_000 => pass, call writeText success. '); + done(); + }, + fail: function (data, code) { + console.log('file_test_000 => call writeText fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + file.writeText({ + uri: 'internal://app/file_test_000', + text: 'Text1', + success: function () { + console.log('file_test_000 => pass, call writeText success. '); + done(); + }, + fail: function (data, code) { + console.log('file_test_000 => call writeText fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + file.writeText({ + uri: 'internal://app/file_test_000', + text: 'Text2', + success: function () { + console.log('file_test_000 => pass, call writeText success. '); + done(); + }, + fail: function (data, code) { + console.log('file_test_000 => call writeText fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + } + }); + + /** + * @tc.number SUB_STORAGE_File_readText_0100 + * @tc.name file_test_001 + * @tc.desc Function of API Simultaneous reading. + */ + it('file_test_001', 0, async function (done) { + file.writeText({ + uri: 'internal://app/file_test_001', + text: 'Text', + success: function () { + console.log('file_test_001 call writeText success.'); + done(); + }, + fail: function (data, code) { + console.log('file_test_001 call writeText fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + for (let i = 0; i < 10; i++) { + file.readText({ + uri: 'internal://app/file_test_001', + success: function (data) { + console.log('file_test_001 => pass, call readText success. data.text: ' ); + done(); + }, + fail: function (data, code) { + console.log('file_test_001 => call readText fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + file.readText({ + uri: 'internal://app/file_test_001', + success: function (data) { + console.log('file_test_001 => pass, call readText success. data.text: ' ); + done(); + }, + fail: function (data, code) { + console.log('file_test_001 => call readText fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + file.readText({ + uri: 'internal://app/file_test_001', + success: function (data) { + console.log('file_test_001 => pass, call readText success. data.text: ' ); + done(); + }, + fail: function (code, data) { + console.log('file_test_001 => call readText fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + } + }); + + /** + * @tc.number SUB_STORAGE_file_test_0200 + * @tc.name file_test_002 + * @tc.desc Function of API Simultaneous copying. + */ + it('file_test_002', 0, async function (done) { + file.writeText({ + uri: 'internal://app/file_test_002', + text: 'Text', + append: true, + success: function () { + console.log('file_test_002 call writeText success.'); + done(); + }, + fail: function (data, code) { + console.log('file_test_002 call writeText fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + for (let i = 0; i < 10; i++) { + file.copy({ + srcUri: 'internal://app/file_test_002', + dstUri: 'internal://app/file_test_002', + success: function (uri) { + console.log('file_test_002 => pass,call copy success. uri:' ); + done(); + }, + fail: function (data, code) { + console.log('file_test_002 => call copy fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + file.copy({ + srcUri: 'internal://app/file_test_002', + dstUri: 'internal://app/file_test_002' + '100', + success: function (uri) { + console.log('file_test_002 => pass,call copy success. uri:' ); + done(); + }, + fail: function (data, code) { + console.log('file_test_002 => call copy fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + file.copy({ + srcUri: 'internal://app/file_test_002', + dstUri: 'internal://app/file_test_002' + '200', + success: function (uri) { + console.log('file_test_002 => pass,call copy success. uri:' ); + done(); + }, + fail: function (data, code) { + console.log('file_test_002 => call copy fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + } + }); + + /** + * @tc.number SUB_STORAGE_file_test_0300 + * @tc.name file_test_003 + * @tc.desc Function of API, Move files while writing to them continuously + */ + it('file_test_003', 0, async function (done) { + for (let i = 0; i < 10; i++) { + file.writeText({ + uri: 'internal://app/file_test_003', + text: 'Text', + append: true, + success: function () { + console.log('file_test_003 => pass,call writeText success.'); + done(); + }, + fail: function (data, code) { + console.log('file_test_003 => call writeText fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + file.move({ + srcUri: 'internal://app/file_test_003', + dstUri: 'internal://file_test_003', + success: function (uri) { + console.log('file_test_003 => pass,call move success. uri:' ); + done(); + }, + fail: function (data, code) { + console.log('file_test_003 =>call move fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + } + }); + + /** + * @tc.number SUB_STORAGE_file_test_0400 + * @tc.name file_test_004 + * @tc.desc Function of API,Continuous reading + */ + it('file_test_004', 0, async function (done) { + let buf = new Uint8Array([48, 49, 50, 51, 65, 66, 67, 68, 32, 33]); + file.writeArrayBuffer({ + uri: 'internal://app/file_test_004', + buffer: buf, + success: function () { + console.log('file_test_004 call writeArrayBuffer success.'); + done(); + }, + fail: function (data, code) { + console.error('file_test_004 call writeArrayBuffer fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + for (let i = 0; i < 10; i++) { + file.readArrayBuffer({ + uri: 'internal://app/file_test_004', + success: function (data) { + console.log('file_test_004 => pass,call readArrayBuffer success. '); + done(); + }, + fail: function (data, code) { + console.log('file_test_004 => call readArrayBuffer fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + file.readArrayBuffer({ + uri: 'internal://app/file_test_004', + success: function (data) { + console.log('file_test_004 => pass,call readArrayBuffer success. '); + done(); + }, + fail: function (data, code) { + console.log('file_test_004 => call readArrayBuffer fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + file.readArrayBuffer({ + uri: 'internal://app/file_test_004', + success: function (data) { + console.log('file_test_004 => pass,call readArrayBuffer success. '); + done(); + }, + fail: function (data, code) { + console.log('file_test_004 => call readArrayBuffer fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + } + }); + + /** + * @tc.number SUB_STORAGE_file_test_0500 + * @tc.name file_test_005 + * @tc.desc Function of API,Continuous writeing + */ + it('file_test_005', 0, async function (done) { + let buf = new Uint8Array([48, 49, 50, 51, 65, 66, 67, 68, 32, 33]); + for (let i = 0; i < 10; i++) { + file.writeArrayBuffer({ + uri: 'internal://app/file_test_005', + buffer: buf, + success: function () { + console.log('file_test_005 => pass,call writeArrayBuffer success.'); + done(); + }, + fail: function (data, code) { + console.log('file_test_005 => call writeArrayBuffer fail, code: ' + code); + expect(null).assertFail(); + }, + }); + file.writeArrayBuffer({ + uri: 'internal://app/file_test_005', + buffer: buf, + success: function () { + console.log('file_test_005 => pass,call writeArrayBuffer success.'); + done(); + }, + fail: function (data, code) { + console.log('file_test_005 => call writeArrayBuffer fail, code: ' + code); + expect(null).assertFail(); + }, + }); + file.writeArrayBuffer({ + uri: 'internal://app/file_test_005', + buffer: buf, + success: function () { + console.log('file_test_005 => pass,call writeArrayBuffer success.'); + done(); + }, + fail: function (data, code) { + console.log('file_test_005 => call writeArrayBuffer fail, code: ' + code); + expect(null).assertFail(); + }, + }); + } + }); + + /** + * @tc.number SUB_STORAGE_file_test_0600 + * @tc.name file_test_006 + * @tc.desc Function of API,Write and read simultaneously for one file + */ + it('file_test_006', 0, async function (done) { + for (let i = 0; i < 10; i++) { + file.writeText({ + uri: 'internal://app/file_test_006', + text: 'Text', + success: function () { + console.log('file_test_006 => pass,call writeText success.'); + done(); + }, + fail: function (data, code) { + console.log('file_test_006 => call fail callback fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + file.readText({ + uri: 'internal://app/file_test_006', + success: function (data) { + console.log('file_test_006 => pass,call readText success: '); + done(); + }, + fail: function (data, code) { + console.log('file_test_006 => call readText fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + } + }); + + /** + * @tc.number SUB_STORAGE_file_test_0700 + * @tc.name file_test_007 + * @tc.desc Function of API,Write and read simultaneously for one file + */ + it('file_test_007', 0, async function (done) { + let buf = new Uint8Array([48, 49, 50, 51, 65, 66, 67, 68, 32, 33]); + for (let i = 0; i < 10; i++) { + file.writeArrayBuffer({ + uri: 'internal://app/file_test_007', + buffer: buf, + success: function () { + console.log('file_test_007 => pass,call writeArrayBuffer success.'); + done(); + }, + fail: function (data, code) { + console.log('file_test_007 => call writeArrayBuffer fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + file.readArrayBuffer({ + uri: 'internal://app/file_test_007', + success: function (data) { + console.log('file_test_007 => pass,call readArrayBuffer success: '); + done(); + }, + fail: function (data, code) { + console.log('file_test_007 => call readArrayBuffer fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + } + }); + + /** + * @tc.number SUB_STORAGE_file_test_0800 + * @tc.name file_test_008 + * @tc.desc Function of API, Copy files while writing + */ + it('file_test_008', 0, async function (done) { + for (let i = 0; i < 10; i++) { + file.writeText({ + uri: 'internal://app/file_test_008', + text: 'Text', + success: function () { + console.log('file_test_008 => pass, call writeText success.'); + done(); + }, + fail: function (data, code) { + console.log('file_test_008 => call writeText fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + file.copy({ + srcUri: 'internal://app/file_test_008', + dstUri: 'internal://app/file_test_008', + success: function (uri) { + console.log('file_test_008 => pass,call copy success. uri:'); + done(); + }, + fail: function (data, code) { + console.log('file_test_008 => call copy fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + } + }); +}); diff --git a/storage/storagefileconcurrentjstest/project/entry/src/main/js/test/List.test.js b/storage/storagefileconcurrentjstest/project/entry/src/main/js/test/List.test.js new file mode 100644 index 0000000000000000000000000000000000000000..4c2fad370f61865fbfc258978b5e1de959db81cc --- /dev/null +++ b/storage/storagefileconcurrentjstest/project/entry/src/main/js/test/List.test.js @@ -0,0 +1,16 @@ +/* + * 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('./FileConcurrent.test.js') diff --git a/storage/storagefileiojstest/BUILD.gn b/storage/storagefileiojstest/BUILD.gn index cdf2e8c3848ba01a25f3f3521ddeb7530dcc7177..6a5383c531151cea2a4fefd1646338658a9d5803 100644 --- a/storage/storagefileiojstest/BUILD.gn +++ b/storage/storagefileiojstest/BUILD.gn @@ -13,6 +13,6 @@ import("//test/xts/tools/build/suite.gni") ohos_js_hap_suite("storagefileio_js_test") { - test_hap_name = "StoragefileioJSTest" + test_hap_name = "Storagefileiojstest" hap_source_path = "hap/entry-debug-rich-signed.hap" } diff --git a/storage/storagefileiojstest/Test.json b/storage/storagefileiojstest/Test.json index 05a9b24da74c6e10c6d62711af7cc7db3ec08d2c..a4520a6ccb821c7bd27143f641cc78310cee9e20 100644 --- a/storage/storagefileiojstest/Test.json +++ b/storage/storagefileiojstest/Test.json @@ -1,4 +1,3 @@ - { "description": "Configuration for storage file and fileio Tests", "driver": { diff --git a/storage/storagefileiojstest/hap/entry-debug-rich-signed.hap b/storage/storagefileiojstest/hap/entry-debug-rich-signed.hap index 9cc98c7fd8494d9f98037fcf7c9ce2337f062dc9..811743ae375d1798a868bd09f85d49c3152be321 100644 Binary files a/storage/storagefileiojstest/hap/entry-debug-rich-signed.hap and b/storage/storagefileiojstest/hap/entry-debug-rich-signed.hap differ diff --git a/storage/storagefileiojstest/project/entry/src/main/js/default/app.js b/storage/storagefileiojstest/project/entry/src/main/js/default/app.js index 60ee141c8dbd251c763b7b74552b5a133a774d6a..5fefaead87d0899fd7e07a2f2241a40bfd298339 100644 --- a/storage/storagefileiojstest/project/entry/src/main/js/default/app.js +++ b/storage/storagefileiojstest/project/entry/src/main/js/default/app.js @@ -1,18 +1,3 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - export default { onCreate() { console.info('ohos.acts.distributeddatamgr.distributedfile onCreate'); diff --git a/storage/storagefileiojstest/project/entry/src/main/js/default/pages/index/index.js b/storage/storagefileiojstest/project/entry/src/main/js/default/pages/index/index.js index aa194c7ca685eda80583e5487152a7188d419673..572ce6e94d0cd867a15eb94b1b7b0da9497a99b3 100644 --- a/storage/storagefileiojstest/project/entry/src/main/js/default/pages/index/index.js +++ b/storage/storagefileiojstest/project/entry/src/main/js/default/pages/index/index.js @@ -16,39 +16,23 @@ import file from '@system.file' import app from '@system.app' -import {Core, ExpectExtend, ReportExtend} from 'deccjsunit/index' - +import {Core} from 'deccjsunit/index' export default { - data: { - title: "" - }, - onInit() { - this.title = this.$t('strings.world'); - }, - onShow() { - console.info('onShow finish') - const core = Core.getInstance() - const expectExtend = new ExpectExtend({ - 'id': 'extend' - }) - const reportExtend = new ReportExtend(file) -// const instrumentLog = new InstrumentLog({ -// 'id': 'report' -// }) - core.addService('expect', expectExtend) - core.addService('report', reportExtend) -// core.addService('report', instrumentLog) - core.init() -// core.subscribeEvent('spec', instrumentLog) -// core.subscribeEvent('suite', instrumentLog) -// core.subscribeEvent('task', instrumentLog) - - const configService = core.getDefaultService('config') - configService.setConfig(this) - - require('../../../test/List.test') - core.execute() - }, - onReady() { - }, + 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() { + }, } \ No newline at end of file diff --git a/storage/storagefileiojstest/project/entry/src/main/js/test/Common.js b/storage/storagefileiojstest/project/entry/src/main/js/test/Common.js index b441690bd0d4184f075d4162cc279eb6012dd473..c5bc08482173733896e49c8fab5239bef520ee7c 100644 --- a/storage/storagefileiojstest/project/entry/src/main/js/test/Common.js +++ b/storage/storagefileiojstest/project/entry/src/main/js/test/Common.js @@ -1,13 +1,13 @@ /* * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); + * Licensed under the Apache License, Version 2.0 (the 'License'); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, + * distributed under the License is distributed on an 'AS IS' BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. @@ -15,147 +15,156 @@ import fileio from '@system.fileio' -export const FILE_CONTENT = "仙女星系 (英语: Andromeda Galaxy; M31; NGC 224 ;曾被称为 仙女座大星云 ),位于仙女座方位的拥有巨大盘状结构的 \ -旋涡星系 , 梅西耶星表 编号为M31, 星云星团新总表 编号位 NGC 224 ,直径22万光年,距离地球有254万光年,是距银河系最近的大星系。" +export const FILE_CONTENT = 'hello world' -//创建一个可读写文件 export function prepareFile(fpath, content) { - try { - let fd = fileio.openSync(fpath, 0o102, 0o666) - fileio.ftruncateSync(fd) - fileio.writeSync(fd, content) - fileio.fsyncSync(fd) - fileio.closeSync(fd) - return true - } catch (e) { - console.log("Failed to prepareFile for " + e) - return false - } + try { + let fd = fileio.openSync(fpath, 0o102, 0o666) + fileio.ftruncateSync(fd) + fileio.writeSync(fd, content) + fileio.fsyncSync(fd) + fileio.closeSync(fd) + return true + } + catch (e) { + console.log('Failed to prepareFile for ' + e) + return false + } } export function prepareFile1(fpath, content) { - try { - let fd = fileio.openSync(fpath, 0o102, 0o777) - fileio.ftruncateSync(fd) - fileio.writeSync(fd, content) - fileio.fsyncSync(fd) - fileio.closeSync(fd) - return true - } catch (e) { - console.log("Failed to prepareFile for " + e) - return false - } + try { + let fd = fileio.openSync(fpath, 0o102, 0o777) + fileio.ftruncateSync(fd) + fileio.writeSync(fd, content) + fileio.fsyncSync(fd) + fileio.closeSync(fd) + return true + } + catch (e) { + console.log('Failed to prepareFile for ' + e) + return false + } } -//创建一个可读的空文件 export function prepareEmptyFile(fpath) { - try { - let fd = fileio.openSync(fpath, 0o102, 0o777) - fileio.closeSync(fd) - return true - } catch (e) { - console.log("Failed to prepareFile for " + e) - return false - } + try { + let fd = fileio.openSync(fpath, 0o102, 0o777) + fileio.closeSync(fd) + return true + } + catch (e) { + console.log('Failed to prepareFile for ' + e) + return false + } } -//将已存在的文件访问权限改为只读 export function fileToReadOnly(fpath) { - try { - let fd = fileio.openSync(fpath, 0o1) - fileio.fchmodSync(fd, 0o444) - fileio.fsyncSync(fd) - fileio.closeSync(fd) - return true - } catch (e) { - console.log("Failed to fileToReadOnly for " + e) - return false - } + try { + let fd = fileio.openSync(fpath, 0o1) + fileio.fchmodSync(fd, 0o444) + fileio.fsyncSync(fd) + fileio.closeSync(fd) + return true + } + catch (e) { + console.log('Failed to fileToReadOnly for ' + e); + return false + } } -//将已存在的文件访问权限改为只写 export function fileToWriteOnly(fpath) { - try { - let fd = fileio.openSync(fpath, 0o2) - fileio.fchmodSync(fd, 0o222) - fileio.fsyncSync(fd) - fileio.closeSync(fd) - return true - } catch (e) { - console.log("Failed to fileToWriteOnly " + e) - return false - } + try { + let fd = fileio.openSync(fpath, 0o2) + fileio.fchmodSync(fd, 0o222) + fileio.fsyncSync(fd) + fileio.closeSync(fd) + return true + } + catch (e) { + console.log('Failed to fileToWriteOnly ' + e) + return false + } } -//将已存在的文件访问权限改为读写 export function fileToReadAndWrite(fpath) { - try { - let fd = fileio.openSync(fpath, 0o1) - fileio.fchmodSync(fd, 0o777) - fileio.fsyncSync(fd) - fileio.closeSync(fd) - return true - } catch (e) { - console.log("Failed to fileToReadAndWrite " + e) - return false - } + try { + let fd = fileio.openSync(fpath, 0o1) + fileio.fchmodSync(fd, 0o777) + fileio.fsyncSync(fd) + fileio.closeSync(fd) + return true + } + catch (e) { + console.log('Failed to fileToReadAndWrite ' + e); + return false + } +} +export function appName(testName) { + const BASE_PATH = '/data/accounts/account_0/appdata/ohos.acts.stroage.fileio/' + return BASE_PATH + testName } -var fileSeed = 0 export function nextFileName(testName) { - const BASE_PATH = "/data/accounts/account_0/appdata/ohos.acts.stroage.fileio/cache/" - return BASE_PATH + testName + const BASE_PATH = '/data/accounts/account_0/appdata/ohos.acts.stroage.fileio/cache/' + return BASE_PATH + testName } export function fileName(testName) { - const BASE_PATH = "/data/accounts/account_0/appdata/ohos.acts.stroage.fileio/files/" - return BASE_PATH + testName + const BASE_PATH = '/data/accounts/account_0/appdata/ohos.acts.stroage.fileio/files/' + return BASE_PATH + testName +} +export function cacheFileName(testName) { + const BASE_PATH = '/data/accounts/account_0/appdata/ohos.acts.stroage.fileio/files/cache/' + return BASE_PATH + testName } export function differentFileName(testName) { - const BASE_PATH = "/data/accounts/account_0/ohos.acts.distributeddatamgr.distributedfile/" - return BASE_PATH + testName + const BASE_PATH = '/data/accounts/account_0/ohos.acts.distributeddatamgr.distributedfile/' + return BASE_PATH + testName } -export function cacheFileName(testName) { - const BASE_PATH = "/data/accounts/account_0/appdata/ohos.acts.stroage.fileio/files/cache/" - return BASE_PATH + testName +export function differentCacheName(testName) { + const BASE_PATH = '/data/accounts/account_0/ohos.acts.distributeddatamgr.distributedfile/cache/' + return BASE_PATH + testName } export function getFileTextLen(fpath) { - let ss - try{ - ss = fileio.Stream.createStreamSync(fpath, "r+") - expect(ss !== null).assertTrue() - let len = ss.readSync(new ArrayBuffer(4096)) - console.log("文件:" + fpath) - console.log("文本长度:" + len) - expect(ss.closeSync() !== null).assertTrue() - return len - } catch (e) { - console.log("Failed to getFileTextLen " + e) - expect(ss.closeSync() !== null).assertTrue() - return null - } + let ss + try { + ss = fileio.Stream.createStreamSync(fpath, 'r+') + expect(ss !== null).assertTrue() + let len = ss.readSync(new ArrayBuffer(4096)) + console.log('file:' + fpath) + console.log('file lenth:' + len) + expect(ss.closeSync() !== null).assertTrue() + return len + } + catch (e) { + console.log('Failed to getFileTextLen ' + e) + expect(ss.closeSync() !== null).assertTrue() + return null + } } export function isFileExist(fpath) { - try{ - expect(fileio.accessSync(fpath) !== null).assertTrue() - console.log("文件:" + fpath) - console.log("状态:存在") - return true - } catch (e) { - console.log("文件:" + fpath) - console.log("状态:不存在") - return false - } + try { + expect(fileio.accessSync(fpath) !== null).assertTrue() + console.log('file:' + fpath) + console.log('status:exist') + return true + } + catch (e) { + console.log('file:' + fpath) + console.log('status:non-existen') + return false + } } export function sleep(n) { - var start = new Date().getTime(); - while (true) { - if (new Date().getTime() - start > n) { - break; - } + var start = new Date().getTime(); + while (true) { + if (new Date().getTime() - start > n) { + break; } + } +} +export function randomString(num) { + let len= num; + var $chars = 'aaaabbbbcccc'; + var maxPos = $chars.length; + var pwd = ''; + for (var i = 0; i < len; i++) { + pwd += $chars.charAt(Math.floor(Math.random() * maxPos)); + } + return pwd; } -export function randomString(len) { - len = len; - var $chars = 'aaaabbbbcccc'; - var maxPos = $chars.length; - var pwd = ''; - for (var i = 0; i < len; i++) { - pwd += $chars.charAt(Math.floor(Math.random() * maxPos)); - } - return pwd; -} \ No newline at end of file diff --git a/storage/storagefileiojstest/project/entry/src/main/js/test/File.test.js b/storage/storagefileiojstest/project/entry/src/main/js/test/File.test.js index 39d759fec6bdc538aab79fa98bb2aff30cd3a15d..789800a3350ffea38b321f757dac2dba4bf38d00 100644 --- a/storage/storagefileiojstest/project/entry/src/main/js/test/File.test.js +++ b/storage/storagefileiojstest/project/entry/src/main/js/test/File.test.js @@ -1,26 +1,40 @@ /* * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); + * Licensed under the Apache License, Version 2.0 (the 'License'); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, + * distributed under the License is distributed on an 'AS IS' BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ - import fileio from '@system.fileio'; +import bundle_mgr from '@ohos.bundle_mgr' import file from '@system.file'; -import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index' import { - FILE_CONTENT, prepareFile, fileName, randomString, sleep, - cacheFileName, prepareEmptyFile, nextFileName -} from './Common' - + describe, + beforeAll, + beforeEach, + afterEach, + afterAll, + it, + expect +} + from 'deccjsunit/index' +import { + FILE_CONTENT, + prepareFile, + fileName, + randomString, + cacheFileName, + prepareEmptyFile, + nextFileName +} + from './Common' describe('fileTest', function () { @@ -30,8 +44,8 @@ describe('fileTest', function () { * @tc.desc Function of API, delete file.The test file is exist. */ it('File_Delete_001', 0, async function (done) { - let fpath = fileName("File_Delete_001") - prepareFile(fpath, "hello") + let fpath = fileName('File_Delete_001'); + prepareFile(fpath, 'hello'); file.delete({ uri: 'internal://app/File_Delete_001', success: function () { @@ -44,7 +58,7 @@ describe('fileTest', function () { done(); }, }); - }) + }); /** * @tc.number SUB_STORAGE_File_Delete_0200 @@ -74,7 +88,7 @@ describe('fileTest', function () { expect(null).assertFail(); }, }); - }) + }); /** * @tc.number SUB_STORAGE_File_Delete_0300 @@ -86,7 +100,7 @@ describe('fileTest', function () { uri: 'internal://ohos/workspace/text.txt', success: function () { console.log('File_Delete_003 call delete success.'); - expect(null).assertFail() + expect(null).assertFail(); }, fail: function (data, code) { console.log('File_Delete_003 call delete fail, code: ' + code + ', data: ' + data); @@ -94,7 +108,8 @@ describe('fileTest', function () { done(); }, }); - }) + + }); /** * @tc.number SUB_STORAGE_File_Delete_0400 @@ -118,7 +133,7 @@ describe('fileTest', function () { done(); }, }); - }) + }); /** * @tc.number SUB_STORAGE_File_Delete_0500 @@ -138,7 +153,7 @@ describe('fileTest', function () { done(); }, }); - }) + }); /** * @tc.number SUB_STORAGE_File_Delete_0600 @@ -167,7 +182,7 @@ describe('fileTest', function () { done(); }, }); - }) + }); /** * @tc.number SUB_STORAGE_File_Delete_0700 @@ -186,7 +201,7 @@ describe('fileTest', function () { console.log('File_Delete_007 call writeText fail, code: ' + code + ', data: ' + data); expect(null).assertFail(); }, - }) + }); file.delete({ uri: 'internal://cache/File_Delete_007', success: function () { @@ -198,7 +213,7 @@ describe('fileTest', function () { expect(null).assertFail(); }, }); - }) + }); /** * @tc.number SUB_STORAGE_File_Delete_0800 @@ -229,7 +244,7 @@ describe('fileTest', function () { expect(null).assertFail(); }, }); - }) + }); /** * @tc.number SUB_STORAGE_File_writeText_0100 @@ -252,14 +267,14 @@ describe('fileTest', function () { file.readText({ uri: 'internal://app/File_writeText_001', success: function (data) { - console.log('File_writeText_001 call read success. Content: ' + data.text); + console.log('File_writeText_001 call read success. Content: ' ); done(); }, fail: function (data, code) { console.log('File_writeText_001 call read fail , code: ' + code + ', data: ' + data); expect(null).assertFail(); }, - }) + }); file.delete({ uri: 'internal://app/File_writeText_001', success: function () { @@ -271,7 +286,7 @@ describe('fileTest', function () { expect(null).assertFail(); }, }); - }) + }); /** * @tc.number SUB_STORAGE_File_writeText_0200 @@ -307,7 +322,7 @@ describe('fileTest', function () { file.readText({ uri: 'internal://app/File_writeText_002', success: function (data) { - console.log('File_writeText_002 call read success. Content: ' + data.text); + console.log('File_writeText_002 call read success. Content: ' ); done(); }, fail: function (data, code) { @@ -326,7 +341,7 @@ describe('fileTest', function () { expect(null).assertFail(); }, }); - }) + }); /** * @tc.number SUB_STORAGE_File_writeText_0300 @@ -334,7 +349,7 @@ describe('fileTest', function () { * @tc.desc Different types of strings for text. */ it('File_writeText_003', 0, async function (done) { - let txt = 'hello 你好 مرحبا こんにちは 안녕하세요.' + let txt = 'hello 你好 ????? こんにちは ?????.' file.writeText({ uri: 'internal://app/File_writeText_003', text: txt, @@ -350,7 +365,7 @@ describe('fileTest', function () { file.readText({ uri: 'internal://app/File_writeText_003', success: function (data) { - console.log('File_writeText_003 call read success. Content: ' + data.text); + console.log('File_writeText_003 call read success. Content: ' ); done(); }, fail: function (data, code) { @@ -369,7 +384,7 @@ describe('fileTest', function () { expect(null).assertFail(); }, }); - }) + }); /** * @tc.number SUB_STORAGE_File_writeText_0400 @@ -394,7 +409,7 @@ describe('fileTest', function () { uri: 'internal://app/File_writeText_004', encoding: 'UTF-8', success: function (data) { - console.log('File_writeText_004 call readText success. Content: ' + data.text); + console.log('File_writeText_004 call readText success. Content: ' ); done(); }, fail: function (data, code) { @@ -413,7 +428,7 @@ describe('fileTest', function () { expect(null).assertFail(); }, }); - }) + }); /** * @tc.number SUB_STORAGE_File_writeText_0500 @@ -449,7 +464,7 @@ describe('fileTest', function () { file.readText({ uri: 'internal://app/File_writeText_005', success: function (data) { - console.log('File_writeText_005 call read success ' + data.text); + console.log('File_writeText_005 call read success ' ); done(); }, fail: function (data, code) { @@ -468,7 +483,7 @@ describe('fileTest', function () { expect(null).assertFail(); }, }); - }) + }); /** * @tc.number SUB_STORAGE_File_writeText_0600 @@ -491,7 +506,7 @@ describe('fileTest', function () { file.readText({ uri: 'internal://app/File_writeText_006', success: function (data) { - console.log('File_writeText_006 call read success ' + data.text); + console.log('File_writeText_006 call read success ' ); done(); }, fail: function (data, code) { @@ -510,7 +525,7 @@ describe('fileTest', function () { expect(null).assertFail(); }, }); - }) + }); /** * @tc.number SUB_STORAGE_File_writeText_0700 @@ -531,7 +546,7 @@ describe('fileTest', function () { done(); }, }); - }) + }); /** * @tc.number SUB_STORAGE_File_writeText_0800 @@ -539,7 +554,7 @@ describe('fileTest', function () { * @tc.desc Function of API, error code: 300 The uri path is dir path. */ it('File_writeText_008', 0, async function (done) { - let dpath = fileName("File_writeText_008d"); + let dpath = fileName('File_writeText_008d'); expect(fileio.mkdirSync(dpath) !== null).assertTrue(); file.writeText({ uri: 'internal://app/File_writeText_008d/', @@ -554,7 +569,7 @@ describe('fileTest', function () { done(); }, }); - }) + }); /** * @tc.number SUB_STORAGE_File_writeText_0900 @@ -575,7 +590,7 @@ describe('fileTest', function () { done(); }, }); - }) + }); /** * @tc.number SUB_STORAGE_File_writeText_1000 @@ -605,8 +620,8 @@ describe('fileTest', function () { console.log('File_writeText_010 fail, code: ' + code + ', data: ' + data); expect(null).assertFail(); }, - }) - }) + }); + }); /** * @tc.number SUB_STORAGE_File_writeText_1100 @@ -629,14 +644,14 @@ describe('fileTest', function () { file.readText({ uri: 'internal://app/../files/File_writeText_011', success: function (data) { - console.log('File_writeText_011 read success ' + data.text); + console.log('File_writeText_011 read success ' ); done(); }, fail: function (data, code) { console.log('File_writeText_011 , code: ' + code + ', data: ' + data); expect(null).assertFail(); }, - }) + }); file.delete({ uri: 'internal://app/../files/File_writeText_011', success: function () { @@ -648,7 +663,7 @@ describe('fileTest', function () { expect(null).assertFail(); }, }); - }) + }); /** * @tc.number SUB_STORAGE_File_writeText_1300 @@ -660,7 +675,7 @@ describe('fileTest', function () { uri: 'internal://app/../../File_writeText_013', text: 'sawyerwang', success: function () { - console.log('File_writeText_013 mkdir success') + console.log('File_writeText_013 mkdir success'); expect(null).assertFail(); }, fail: function (data, code) { @@ -669,7 +684,8 @@ describe('fileTest', function () { done(); }, }); - }) + + }); /** * @tc.number SUB_STORAGE_File_writeArrayBuffer_0100 @@ -694,7 +710,7 @@ describe('fileTest', function () { file.readArrayBuffer({ uri: 'internal://cache/File_writeArrayBuffer_001', success: function (data) { - console.log('File_writeArrayBuffer_001 call readArrayBuffer success.' + data.buffer); + console.log('File_writeArrayBuffer_001 call readArrayBuffer success.' ); done(); }, fail: function (data, code) { @@ -705,7 +721,7 @@ describe('fileTest', function () { file.delete({ uri: 'internal://cache/File_writeArrayBuffer_001' }); - }) + }); /** * @tc.number SUB_STORAGE_File_writeArrayBuffer_0200 @@ -729,18 +745,18 @@ describe('fileTest', function () { file.readArrayBuffer({ uri: 'internal://cache/File_writeArrayBuffer_002', success: function (data) { - console.log('File_writeArrayBuffer_002 call readArrayBuffer success.' + data.buffer); + console.log('File_writeArrayBuffer_002 call readArrayBuffer success.' ); done(); }, fail: function (data, code) { console.log('File_writeArrayBuffer_002 , code: ' + code + ', data: ' + data); expect(null).assertFail(); }, - }) + }); file.delete({ uri: 'internal://cache/File_writeArrayBuffer_002' }); - }) + }); /** * @tc.number SUB_STORAGE_File_writeArrayBuffer_0300 @@ -777,7 +793,7 @@ describe('fileTest', function () { file.readArrayBuffer({ uri: 'internal://cache/File_writeArrayBuffer_003', success: function (data) { - console.log('File_writeArrayBuffer_003 readArrayBuffer success:' + data.buffer) + console.log('File_writeArrayBuffer_003 readArrayBuffer success:' ); done(); }, fail: function (data, code) { @@ -785,7 +801,7 @@ describe('fileTest', function () { expect(null).assertFail(); }, }); - }) + }); /** * @tc.number SUB_STORAGE_File_writeArrayBuffer_0400 @@ -823,7 +839,7 @@ describe('fileTest', function () { file.readArrayBuffer({ uri: 'internal://cache/File_writeArrayBuffer_004', success: function (data) { - console.log('File_writeArrayBuffer_004: readArrayBuffer success ' + data.buffer) + console.log('File_writeArrayBuffer_004: readArrayBuffer success ' ); done(); }, fail: function (data, code) { @@ -834,7 +850,7 @@ describe('fileTest', function () { file.delete({ uri: 'internal://cache/File_writeArrayBuffer_004' }); - }) + }); /** * @tc.number SUB_STORAGE_File_writeArrayBuffer_0500 @@ -871,7 +887,7 @@ describe('fileTest', function () { file.readArrayBuffer({ uri: 'internal://cache/File_writeArrayBuffer_005', success: function (data) { - console.log('File_writeArrayBuffer_005 read success:' + data.buffer); + console.log('File_writeArrayBuffer_005 read success:' ); done(); }, fail: function (data, code) { @@ -882,7 +898,7 @@ describe('fileTest', function () { file.delete({ uri: 'internal://cache/File_writeArrayBuffer_005' }); - }) + }); /** * @tc.number SUB_STORAGE_File_writeArrayBuffer_0600 @@ -926,7 +942,7 @@ describe('fileTest', function () { expect(null).assertFail(); }, }); - }) + }); /** * @tc.number SUB_STORAGE_File_writeArrayBuffer_0700 @@ -948,7 +964,7 @@ describe('fileTest', function () { done(); }, }); - }) + }); /** * @tc.number SUB_STORAGE_File_writeArrayBuffer_0800 @@ -961,7 +977,7 @@ describe('fileTest', function () { uri: 'internal://app/File_writeArrayBuffer_008', success: function () { console.log('call mkdir success.'); - done() + done(); }, fail: function (data, code) { console.error('call fail callback fail, code: ' + code + ', data: ' + data); @@ -980,7 +996,7 @@ describe('fileTest', function () { done(); }, }); - }) + }); /** * @tc.number SUB_STORAGE_File_writeArrayBuffer_0900 @@ -988,19 +1004,19 @@ describe('fileTest', function () { * @tc.desc Function of API, error code: 300 */ it('File_writeArrayBuffer_009', 0, async function (done) { - let buf = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]) - file.writeArrayBuffer({ - uri: 'internal://app/File_writeArrayBuffer_009', - buffer: buf, - success: function () { - console.log('File_writeArrayBuffer_009 call success'); - done(); - }, - fail: function (data, code) { - console.log('File_writeArrayBuffer_009 fail'); - expect(null).assertFail(); - }, - }); + let buf = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]); + file.writeArrayBuffer({ + uri: 'internal://app/File_writeArrayBuffer_009', + buffer: buf, + success: function () { + console.log('File_writeArrayBuffer_009 call success'); + done(); + }, + fail: function (data, code) { + console.log('File_writeArrayBuffer_009 fail'); + expect(null).assertFail(); + }, + }); file.readArrayBuffer({ uri: 'internal://app/File_writeArrayBuffer_009', success: function (data) { @@ -1023,7 +1039,7 @@ describe('fileTest', function () { expect(null).assertFail(); }, }); - }) + }); /** * @tc.number SUB_STORAGE_File_writeArrayBuffer_1000 @@ -1055,8 +1071,8 @@ describe('fileTest', function () { console.log('File_writeArrayBuffer_010 readArrayBuffer , code: ' + code + ', data: ' + data); expect(null).assertFail(); }, - }) - }) + }); + }); /** * @tc.number SUB_STORAGE_File_writeArrayBuffer_1200 @@ -1079,7 +1095,7 @@ describe('fileTest', function () { done(); }, }); - }) + }); /** * @tc.number SUB_STORAGE_File_readText_0100 @@ -1110,7 +1126,7 @@ describe('fileTest', function () { expect(null).assertFail(); }, }); - }) + }); /** * @tc.number SUB_STORAGE_File_readText_0200 @@ -1143,7 +1159,7 @@ describe('fileTest', function () { expect(null).assertFail(); }, }); - }) + }); /** * @tc.number SUB_STORAGE_File_readText_0300 @@ -1163,7 +1179,7 @@ describe('fileTest', function () { done(); }, }); - }) + }); /** * @tc.number SUB_STORAGE_File_readText_0400 @@ -1183,7 +1199,7 @@ describe('fileTest', function () { done(); }, }); - }) + }); /** * @tc.number SUB_STORAGE_File_readText_0500 @@ -1203,7 +1219,7 @@ describe('fileTest', function () { done(); }, }); - }) + }); /** * @tc.number SUB_STORAGE_File_readText_0600 @@ -1226,7 +1242,7 @@ describe('fileTest', function () { file.readText({ uri: 'internal://cache/File_readText_006', success: function (data) { - console.log('File_readText_006 call success' + data.text); + console.log('File_readText_006 call success' ); done(); }, fail: function (data, code) { @@ -1244,8 +1260,8 @@ describe('fileTest', function () { console.log('File_readText_006 fail, code: ' + code + ', data: ' + data); expect(null).assertFail(); }, - }) - }) + }); + }); /** * @tc.number SUB_STORAGE_File_readText_0700 @@ -1268,7 +1284,7 @@ describe('fileTest', function () { file.readText({ uri: 'internal://app/../files/../files/File_readText_007', success: function (data) { - console.log('File_readText_007 call readText success. data.text:' + data.text); + console.log('File_readText_007 call readText success. data.text:' ); done(); }, fail: function (data, code) { @@ -1279,7 +1295,7 @@ describe('fileTest', function () { file.delete({ uri: 'internal://app/../files/../files/File_readText_007' }); - }) + }); /** * @tc.number SUB_STORAGE_File_read_array_buffer_0100 @@ -1316,7 +1332,7 @@ describe('fileTest', function () { file.delete({ uri: 'internal://cache/File_read_array_buffer_001' }); - }) + }); /** * @tc.number SUB_STORAGE_File_read_array_buffer_0200 @@ -1348,7 +1364,7 @@ describe('fileTest', function () { expect(null).assertFail(); }, }); - }) + }); /** * @tc.number SUB_STORAGE_File_read_array_buffer_0300 @@ -1359,7 +1375,7 @@ describe('fileTest', function () { file.readArrayBuffer({ uri: '', success: function (data) { - console.log('File_read_array_buffer_003 call readArrayBuffer success: ' + data.buffer); + console.log('File_read_array_buffer_003 call readArrayBuffer success: ' ); expect(null).assertFail(); }, fail: function (data, code) { @@ -1368,7 +1384,7 @@ describe('fileTest', function () { done(); }, }); - }) + }); /** * @tc.number SUB_STORAGE_File_read_array_buffer_0400 @@ -1376,13 +1392,13 @@ describe('fileTest', function () { * @tc.desc Function of API, readArrayBuffer, wrong position. */ it('File_read_array_buffer_004', 0, async function (done) { - let fpath = fileName('File_read_array_buffer_004') - prepareFile(fpath, FILE_CONTENT) + let fpath = fileName('File_read_array_buffer_004'); + prepareFile(fpath, FILE_CONTENT); file.readArrayBuffer({ uri: fpath, position: 100, success: function (data) { - console.log('File_read_array_buffer_004 call readArrayBuffer success: ' + data.buffer); + console.log('File_read_array_buffer_004 call readArrayBuffer success: ' ); expect(null).assertFail(); }, fail: function (data, code) { @@ -1391,7 +1407,7 @@ describe('fileTest', function () { done(); }, }); - }) + }); /** * @tc.number SUB_STORAGE_File_read_array_buffer_0500 @@ -1399,13 +1415,13 @@ describe('fileTest', function () { * @tc.desc Function of API, readArrayBuffer, wrong length. */ it('File_read_array_buffer_005', 0, async function (done) { - let fpath = fileName('File_read_array_buffer_005') - prepareFile(fpath, FILE_CONTENT) + let fpath = fileName('File_read_array_buffer_005'); + prepareFile(fpath, FILE_CONTENT); file.readArrayBuffer({ uri: fpath, length: -1, success: function (data) { - console.log('File_read_array_buffer_005 call readArrayBuffer success: ' + data.buffer); + console.log('File_read_array_buffer_005 call readArrayBuffer success: ' ); expect(null).assertFail(); }, fail: function (data, code) { @@ -1413,8 +1429,8 @@ describe('fileTest', function () { expect(code == 202).assertTrue(); done(); }, - }) - }) + }); + }); /** * @tc.number SUB_STORAGE_File_read_array_buffer_0600 @@ -1425,7 +1441,7 @@ describe('fileTest', function () { file.readArrayBuffer({ uri: 'internal://app', success: function (data) { - console.log('File_read_array_buffer_006 call readArrayBuffer success: ' + data.buffer); + console.log('File_read_array_buffer_006 call readArrayBuffer success: ' ); expect(null).assertFail(); }, fail: function (data, code) { @@ -1434,7 +1450,7 @@ describe('fileTest', function () { done(); }, }); - }) + }); /** * @tc.number SUB_STORAGE_File_read_array_buffer_0700 @@ -1445,7 +1461,7 @@ describe('fileTest', function () { file.readArrayBuffer({ uri: 'internal://cache/File_read_array_buffer_007', success: function (data) { - resolve('File_read_array_buffer_007 call readArrayBuffer success: ' + data.buffer); + console.log('File_read_array_buffer_007 call readArrayBuffer success: ' ); expect(null).assertFail(); }, fail: function (data, code) { @@ -1454,7 +1470,7 @@ describe('fileTest', function () { done(); }, }); - }) + }); /** * @tc.number SUB_STORAGE_File_read_array_buffer_0800 @@ -1462,7 +1478,7 @@ describe('fileTest', function () { * @tc.desc Function of API, cache path.The test file is exist. */ it('File_read_array_buffer_008', 0, async function (done) { - let buf = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]) + let buf = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]); file.writeArrayBuffer({ uri: 'internal://app/File_read_array_buffer_008', buffer: buf, @@ -1474,11 +1490,11 @@ describe('fileTest', function () { console.log('File_read_array_buffer_008 fail, code: ' + code + ', data: ' + data); expect(null).assertFail(); }, - }) + }); file.readArrayBuffer({ uri: 'internal://app/File_read_array_buffer_008', success: function (data) { - console.log('File_read_array_buffer_008 call success ' + data.buffer); + console.log('File_read_array_buffer_008 call success ' ); done(); }, fail: function (data, code) { @@ -1497,7 +1513,7 @@ describe('fileTest', function () { expect(null).assertFail(); }, }); - }) + }); /** * @tc.number SUB_STORAGE_File_read_array_buffer_0900 @@ -1523,7 +1539,7 @@ describe('fileTest', function () { position: 0, length: 10, success: function (data) { - console.log('File_read_array_buffer_009 call readArrayBuffer success. data.buffer:' + data.buffer); + console.log('File_read_array_buffer_009 call readArrayBuffer success. data.buffer:' ); done(); }, fail: function (data, code) { @@ -1534,7 +1550,7 @@ describe('fileTest', function () { file.delete({ uri: 'internal://cache/../cache/File_read_array_buffer_009' }); - }) + }); /** * @tc.number SUB_STORAGE_File_access_0100 @@ -1576,7 +1592,7 @@ describe('fileTest', function () { expect(null).assertFail(); }, }); - }) + }); /** * @tc.number SUB_STORAGE_File_access_0200 @@ -1617,7 +1633,7 @@ describe('fileTest', function () { expect(null).assertFail(); }, }); - }) + }); /** * @tc.number SUB_STORAGE_File_access_0300 @@ -1625,7 +1641,7 @@ describe('fileTest', function () { * @tc.desc Function of API, error code: 202 The test file and dir are exist. */ it('File_access_003', 0, async function (done) { - let fpath = fileName('File_access_003') + let fpath = fileName('File_access_003'); file.access({ uri: fpath, success: function () { @@ -1638,7 +1654,7 @@ describe('fileTest', function () { done(); }, }); - }) + }); /** * @tc.number SUB_STORAGE_File_access_0400 @@ -1658,7 +1674,7 @@ describe('fileTest', function () { done(); }, }); - }) + }); /** * @tc.number SUB_STORAGE_File_access_0500 @@ -1678,7 +1694,7 @@ describe('fileTest', function () { done(); }, }); - }) + }); /** * @tc.number SUB_STORAGE_File_access_0600 @@ -1708,7 +1724,8 @@ describe('fileTest', function () { done(); }, }); - }) + + }); /** * @tc.number SUB_STORAGE_File_access_0700 @@ -1720,7 +1737,7 @@ describe('fileTest', function () { uri: 'internal://app/File_access_007', text: 'hello', success: function () { - console.log('File_access_007 mkdir success ') + console.log('File_access_007 mkdir success '); done(); }, fail: function (data, code) { @@ -1750,7 +1767,7 @@ describe('fileTest', function () { expect(null).assertFail(); }, }); - }) + }); /** * @tc.number SUB_STORAGE_File_access_0800 @@ -1792,7 +1809,7 @@ describe('fileTest', function () { expect(null).assertFail(); }, }); - }) + }); /** * @tc.number SUB_STORAGE_File_mkdir_0100 @@ -1822,7 +1839,7 @@ describe('fileTest', function () { expect(null).assertFail(); }, }); - }) + }); /** * @tc.number SUB_STORAGE_File_mkdir_0200 @@ -1842,7 +1859,7 @@ describe('fileTest', function () { done(); }, }); - }) + }); /** * @tc.number SUB_STORAGE_File_mkdir_0300 @@ -1862,7 +1879,7 @@ describe('fileTest', function () { expect(null).assertFail(); }, }); - }) + }); /** * @tc.number SUB_STORAGE_File_mkdir_0400 @@ -1882,7 +1899,7 @@ describe('fileTest', function () { done(); }, }); - }) + }); /** * @tc.number SUB_STORAGE_File_mkdir_0500 @@ -1902,7 +1919,7 @@ describe('fileTest', function () { done(); }, }); - }) + }); /** * @tc.number SUB_STORAGE_File_mkdir_0600 @@ -1923,7 +1940,7 @@ describe('fileTest', function () { done(); }, }); - }) + }); /** * @tc.number SUB_STORAGE_File_mkdir_0700 @@ -1952,8 +1969,8 @@ describe('fileTest', function () { console.log('File_mkdir_007 fail, code: ' + code + ', data: ' + data); expect(null).assertFail(); }, - }) - }) + }); + }); /** * @tc.number SUB_STORAGE_File_mkdir_0800 @@ -1983,7 +2000,7 @@ describe('fileTest', function () { expect(null).assertFail(); }, }); - }) + }); /** * @tc.number SUB_STORAGE_File_mkdir_1000 @@ -2003,7 +2020,7 @@ describe('fileTest', function () { done(); }, }); - }) + }); /** * @tc.number SUB_STORAGE_File_rmdir_0100 @@ -2033,7 +2050,7 @@ describe('fileTest', function () { expect(null).assertFail(); }, }); - }) + }); /** * @tc.number SUB_STORAGE_File_rmdir_0200 @@ -2066,7 +2083,7 @@ describe('fileTest', function () { done(); }, }); - }) + }); /** * @tc.number SUB_STORAGE_File_rmdir_0300 @@ -2075,14 +2092,38 @@ describe('fileTest', function () { */ it('File_rmdir_003', 0, async function (done) { file.mkdir({ - uri: 'internal://app/test/File_rmdir_003', + uri: 'internal://app/test/File_rmdir_003/File_rmdir_003_1/File_rmdir_003_2', + recursive: true, + success: function () { + console.log('File_rmdir_003 mkdir success.'); + done(); + }, + fail: function (data, code) { + console.log('File_rmdir_003 fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + file.mkdir({ + uri: 'internal://app/test/File_rmdir_003_1/File_rmdir_003_1/File_rmdir_003_2', + recursive: true, + success: function () { + console.log('File_rmdir_003 mkdir success.'); + done(); + }, + fail: function (data, code) { + console.log('File_rmdir_003 fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + file.mkdir({ + uri: 'internal://app/test/File_rmdir_003_2/File_rmdir_003_1/File_rmdir_003_2', recursive: true, success: function () { console.log('File_rmdir_003 mkdir success.'); done(); }, fail: function (data, code) { - console.log('File_rmdir_003 fail'); + console.log('File_rmdir_003 fail, code: ' + code + ', data: ' + data); expect(null).assertFail(); }, }); @@ -2098,7 +2139,7 @@ describe('fileTest', function () { expect(null).assertFail(); }, }); - }) + }); /** * @tc.number SUB_STORAGE_File_rmdir_0400 @@ -2118,7 +2159,7 @@ describe('fileTest', function () { done(); }, }); - }) + }); /** * @tc.number SUB_STORAGE_File_rmdir_0500 @@ -2138,7 +2179,7 @@ describe('fileTest', function () { done(); }, }); - }) + }); /** * @tc.number SUB_STORAGE_File_rmdir_0600 @@ -2170,7 +2211,7 @@ describe('fileTest', function () { expect(null).assertFail(); }, }); - }) + }); /** * @tc.number SUB_STORAGE_File_rmdir_0700 @@ -2192,15 +2233,15 @@ describe('fileTest', function () { file.rmdir({ uri: 'internal://cache/File_rmdir_007d', success: function () { - console.log('File_rmdir_007 mkdir success'); + console.log('File_rmdir_007 rmdir success'); done(); }, fail: function (data, code) { console.log('File_rmdir_007 fail, code: ' + code + ', data: ' + data); expect(null).assertFail(); }, - }) - }) + }); + }); /** * @tc.number SUB_STORAGE_File_rmdir_0800 @@ -2230,7 +2271,7 @@ describe('fileTest', function () { expect(null).assertFail(); }, }); - }) + }); /** * @tc.number SUB_STORAGE_File_rmdir_1000 @@ -2250,7 +2291,7 @@ describe('fileTest', function () { done(); }, }); - }) + }); /** * @tc.number SUB_STORAGE_File_Move_0100 @@ -2282,7 +2323,7 @@ describe('fileTest', function () { expect(null).assertFail(); }, }); - }) + }); /** * @tc.number SUB_STORAGE_File_Move_0200 @@ -2310,7 +2351,7 @@ describe('fileTest', function () { }, }); } - }) + }); /** * @tc.number SUB_STORAGE_File_Move_0300 @@ -2321,8 +2362,8 @@ describe('fileTest', function () { let srcFpath = fileName('File_Move_003'); expect(prepareFile(srcFpath, FILE_CONTENT) !== null).assertTrue(); let dstFpath = cacheFileName('File_Move_003'); - let srcUri = 'internal://app/File_Move_003' - let dstUri = 'internal://app/cache/File_Move_003' + let srcUri = 'internal://app/File_Move_003'; + let dstUri = 'internal://app/cache/File_Move_003'; file.move({ srcUri: srcUri, dstUri: dstUri, @@ -2335,7 +2376,7 @@ describe('fileTest', function () { expect(null).assertFail(); }, }); - }) + }); /** * @tc.number SUB_STORAGE_File_Move_0400 @@ -2358,7 +2399,7 @@ describe('fileTest', function () { done(); }, }); - }) + }); /** * @tc.number SUB_STORAGE_File_Move_0500 @@ -2366,8 +2407,8 @@ describe('fileTest', function () { * @tc.desc Function of API, error code: 300.The test file is exist. */ it('File_Move_005', 0, async function (done) { - let srcDpath = fileName('File_Move_005d') - expect(fileio.mkdirSync(srcDpath) !== null).assertTrue() + let srcDpath = fileName('File_Move_005d'); + expect(fileio.mkdirSync(srcDpath) !== null).assertTrue(); file.move({ srcUri: 'internal://app/File_Move_005d', dstUri: 'internal://app/cache/File_Move_005d', @@ -2381,7 +2422,7 @@ describe('fileTest', function () { done(); }, }); - }) + }); /** * @tc.number SUB_STORAGE_File_Move_0600 @@ -2404,7 +2445,7 @@ describe('fileTest', function () { done(); }, }); - }) + }); /** * @tc.number SUB_STORAGE_File_Move_0700 @@ -2435,7 +2476,7 @@ describe('fileTest', function () { }, }); fileio.rmdirSync(dpath); - }) + }); /** * @tc.number SUB_STORAGE_File_Move_0800 @@ -2478,7 +2519,7 @@ describe('fileTest', function () { expect(null).assertFail(); }, }); - }) + }); /** * @tc.number SUB_STORAGE_File_Move_0900 @@ -2501,7 +2542,7 @@ describe('fileTest', function () { done(); }, }); - }) + }); /** * @tc.number SUB_STORAGE_File_Move_1000 @@ -2526,7 +2567,7 @@ describe('fileTest', function () { done(); }, }); - }) + }); /** * @tc.number SUB_STORAGE_File_Move_1100 @@ -2541,14 +2582,14 @@ describe('fileTest', function () { dstUri: 'internal://app/cache/../../cache/File_Move_011', success: function (uri) { console.log('File_Move_011 => pass, uri' + uri); - done() + done(); }, fail: function (data, code) { console.log('File_Move_011 , code: ' + code + ', data: ' + data); expect(null).assertFail(); }, }); - }) + }); /** * @tc.number SUB_STORAGE_File_Move_1200 @@ -2571,7 +2612,7 @@ describe('fileTest', function () { done(); }, }); - }) + }); /** * @tc.number SUB_STORAGE_File_Move_1400 @@ -2595,7 +2636,7 @@ describe('fileTest', function () { expect(null).assertFail(); }, }); - }) + }); /** * @tc.number SUB_STORAGE_File_Copy_0100 @@ -2606,7 +2647,6 @@ describe('fileTest', function () { let srcFpath = fileName('File_Copy_001'); let dstFpath = cacheFileName('File_Copy_001'); expect(prepareFile(srcFpath, 'test.') !== null).assertTrue(); - sleep(10); file.copy({ srcUri: 'internal://app/File_Copy_001', dstUri: 'internal://app/cache/File_Copy_001', @@ -2622,7 +2662,7 @@ describe('fileTest', function () { file.readText({ uri: 'internal://app/cache/File_Copy_001', success: function (data) { - console.log('File_Copy_001 read success:' + data.text); + console.log('File_Copy_001 read success:' ); expect(fileio.unlinkSync(srcFpath) !== null).assertTrue(); expect(fileio.unlinkSync(dstFpath) !== null).assertTrue(); done(); @@ -2632,7 +2672,7 @@ describe('fileTest', function () { expect(null).assertFail(); }, }); - }) + }); /** * @tc.number SUB_STORAGE_File_Copy_0200 @@ -2660,7 +2700,7 @@ describe('fileTest', function () { }, }); } - }) + }); /** * @tc.number SUB_STORAGE_File_Copy_0300 @@ -2686,7 +2726,7 @@ describe('fileTest', function () { file.readText({ uri: 'internal://app/cache/File_Copy_003', success: function (data) { - console.log('File_Copy_003 readText success, data.text:' + data.text); + console.log('File_Copy_003 readText success, data.text:' ); expect(fileio.unlinkSync(srcFpath) !== null).assertTrue(); expect(fileio.unlinkSync(dstFpath) !== null).assertTrue(); done(); @@ -2697,7 +2737,7 @@ describe('fileTest', function () { }, }); - }) + }); /** * @tc.number SUB_STORAGE_File_Copy_0400 @@ -2721,7 +2761,7 @@ describe('fileTest', function () { done(); }, }); - }) + }); /** * @tc.number SUB_STORAGE_File_Copy_0500 @@ -2754,7 +2794,7 @@ describe('fileTest', function () { done(); }, }); - }) + }); /** * @tc.number SUB_STORAGE_File_Copy_0600 @@ -2775,7 +2815,7 @@ describe('fileTest', function () { done(); }, }); - }) + }); /** * @tc.number SUB_STORAGE_File_Copy_0700 @@ -2806,7 +2846,7 @@ describe('fileTest', function () { done(); }, }); - }) + }); /** * @tc.number SUB_STORAGE_File_Copy_0800 @@ -2848,7 +2888,7 @@ describe('fileTest', function () { console.log('File_Copy_008 fail, code: ' + code + ', data: ' + data); expect(null).assertFail(); }, - }) + }); file.delete({ uri: 'internal://cache/File_Copy_008', success: function () { @@ -2859,16 +2899,16 @@ describe('fileTest', function () { console.log('File_Copy_008 fail, code: ' + code + ', data: ' + data); expect(null).assertFail(); }, - }) - }) + }); + }); /** * @tc.number SUB_STORAGE_File_Copy_0900 * @tc.name File_Copy_009 * @tc.desc Function of API, same path. - */ + */ it('File_Copy_009', 0, async function (done) { - let srcFpath = fileName('File_Copy_009') + let srcFpath = fileName('File_Copy_009'); expect(prepareFile(srcFpath, FILE_CONTENT) !== null).assertTrue(); file.copy({ srcUri: 'internal://app/File_Copy_009', @@ -2884,7 +2924,7 @@ describe('fileTest', function () { done(); }, }); - }) + }); /** * @tc.number SUB_STORAGE_File_Copy_1000 @@ -2911,7 +2951,7 @@ describe('fileTest', function () { done(); }, }); - }) + }); /** * @tc.number SUB_STORAGE_File_Copy_1100 @@ -2936,7 +2976,7 @@ describe('fileTest', function () { file.readText({ uri: 'internal://app/cache/../../cache/File_Copy_011', success: function (data) { - console.log('File_Copy_011 read success:' + data.text); + console.log('File_Copy_011 read success:' ); done(); }, fail: function (data, code) { @@ -2944,7 +2984,7 @@ describe('fileTest', function () { expect(null).assertFail(); }, }); - }) + }); /** * @tc.number SUB_STORAGE_File_Copy_1200 @@ -2968,7 +3008,7 @@ describe('fileTest', function () { done(); }, }); - }) + }); /** * @tc.number SUB_STORAGE_File_Copy_1400 @@ -2993,7 +3033,7 @@ describe('fileTest', function () { expect(null).assertFail(); }, }); - }) + }); /** * @tc.number SUB_STORAGE_File_List_0100 @@ -3010,7 +3050,7 @@ describe('fileTest', function () { file.list({ uri: 'internal://app/File_List_001d', success: function (data) { - console.log('File_List_001 call list success.' + JSON.stringify(data.fileList)) + console.log('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(); @@ -3021,7 +3061,7 @@ describe('fileTest', function () { expect(null).assertFail(); }, }); - }) + }); /** * @tc.number SUB_STORAGE_File_List_0200 @@ -3049,7 +3089,7 @@ describe('fileTest', function () { expect(null).assertFail(); }, }); - }) + }); /** * @tc.number SUB_STORAGE_File_List_0300 @@ -3074,7 +3114,6 @@ describe('fileTest', function () { expect(null).assertFail(); }, }); - file.writeText({ uri: 'internal://app/File_List_003d/File_List_003', text: '1', @@ -3097,7 +3136,7 @@ describe('fileTest', function () { expect(null).assertFail(); }, }); - }) + }); /** * @tc.number SUB_STORAGE_File_List_0400 @@ -3122,7 +3161,7 @@ describe('fileTest', function () { expect(null).assertFail(); }, }); - }) + }); /** * @tc.number SUB_STORAGE_File_List_0500 @@ -3147,7 +3186,7 @@ describe('fileTest', function () { expect(null).assertFail(); }, }); - }) + }); /** * @tc.number SUB_STORAGE_File_List_0600 @@ -3168,7 +3207,7 @@ describe('fileTest', function () { done(); }, }); - }) + }); /** * @tc.number SUB_STORAGE_File_List_0700 @@ -3190,7 +3229,7 @@ describe('fileTest', function () { expect(null).assertFail(); }, }); - }) + }); /** * @tc.number SUB_STORAGE_File_List_0800 @@ -3210,7 +3249,7 @@ describe('fileTest', function () { done(); }, }); - }) + }); /** * @tc.number SUB_STORAGE_File_List_0900 @@ -3240,7 +3279,7 @@ describe('fileTest', function () { done(); }, }); - }) + }); /** * @tc.number SUB_STORAGE_File_List_1000 @@ -3259,8 +3298,9 @@ describe('fileTest', function () { expect(prepareFile(fpath, FILE_CONTENT) !== null).assertTrue(); expect(prepareFile(ffpath, FILE_CONTENT) !== null).assertTrue(); expect(prepareFile(fffpath, FILE_CONTENT) !== null).assertTrue(); - } catch (e) { - console.log("File_List_010 has failed for " + e) + } + catch (e) { + console.log('File_List_010 has failed for ' + e); expect(null).assertFail(); } file.list({ @@ -3279,7 +3319,7 @@ describe('fileTest', function () { expect(null).assertFail(); }, }); - }) + }); /** * @tc.number SUB_STORAGE_File_List_1100 @@ -3307,7 +3347,7 @@ describe('fileTest', function () { expect(null).assertFail(); }, }); - }) + }); /** * @tc.number SUB_STORAGE_File_List_1200 @@ -3326,7 +3366,7 @@ describe('fileTest', function () { expect(null).assertFail(); }, }); - }) + }); /** * @tc.number SUB_STORAGE_File_Get_0100 @@ -3340,7 +3380,7 @@ describe('fileTest', function () { uri: 'internal://app/File_Get_001', recursive: true, success: function (data) { - console.log('File_Get_001 pass,data.uri:' + data.uri); + console.log('File_Get_001 pass,data.uri:' ); expect(fileio.unlinkSync(fpath) !== null).assertTrue(); done(); }, @@ -3349,7 +3389,7 @@ describe('fileTest', function () { expect(null).assertFail(); }, }); - }) + }); /** * @tc.number SUB_STORAGE_File_Get_0200 @@ -3364,7 +3404,7 @@ describe('fileTest', function () { recursive: false, success: function (data) { console.log('File_Get_002 => file list:'); - console.log('{uri:' + data.uri); + console.log('{uri:' ); console.log('length:' + data.length); console.log('lastModifiedTime:' + data.lastModifiedTime); console.log('type:' + data.type); @@ -3377,7 +3417,7 @@ describe('fileTest', function () { expect(null).assertFail(); }, }); - }) + }); /** * @tc.number SUB_STORAGE_File_Get_0300 @@ -3391,7 +3431,7 @@ describe('fileTest', function () { uri: 'internal://app/File_Get_003', success: function (data) { console.log('File_Get_003 => file list:'); - console.log('{uri:' + data.uri); + console.log('{uri:' ); console.log('length:' + data.length); console.log('lastModifiedTime:' + data.lastModifiedTime); console.log('type:' + data.type); @@ -3405,7 +3445,7 @@ describe('fileTest', function () { expect(null).assertFail(); }, }); - }) + }); /** * @tc.number SUB_STORAGE_File_Get_0400 @@ -3413,7 +3453,7 @@ describe('fileTest', function () { * @tc.desc Function of API, recursive = ture.The test file is exist. */ it('File_Get_004', 0, async function (done) { - let dpath = fileName('File_Get_004d') + let dpath = fileName('File_Get_004d'); let ddpath = dpath + '/File_Get_004dd' let fpath = dpath + '/File_Get_004f' let ffpath = ddpath + '/File_Get_004ff' @@ -3426,7 +3466,7 @@ describe('fileTest', function () { recursive: true, success: function (data) { console.log('File_Get_004 => file list:'); - console.log('{uri:' + data.uri); + console.log('{uri:' ); console.log('length:' + data.length); console.log('lastModifiedTime:' + data.lastModifiedTime); console.log('type:' + data.type); @@ -3443,7 +3483,7 @@ describe('fileTest', function () { expect(null).assertFail(); }, }); - }) + }); /** * @tc.number SUB_STORAGE_File_Get_0500 @@ -3464,7 +3504,7 @@ describe('fileTest', function () { recursive: false, success: function (data) { console.log('File_Get_005 => file list :'); - console.log('{uri:' + data.uri); + console.log('{uri:' ); console.log('length:' + data.length); console.log('lastModifiedTime:' + data.lastModifiedTime); console.log('type:' + data.type); @@ -3481,7 +3521,7 @@ describe('fileTest', function () { expect(null).assertFail(); }, }); - }) + }); /** * @tc.number SUB_STORAGE_File_Get_0600 @@ -3501,7 +3541,7 @@ describe('fileTest', function () { uri: 'internal://app/File_Get_006d', success: function (data) { console.log('File_Get_006 file list:'); - console.log('{uri:' + data.uri); + console.log('{uri:' ); console.log('length:' + data.length); console.log('lastModifiedTime:' + data.lastModifiedTime); console.log('type:' + data.type); @@ -3518,7 +3558,7 @@ describe('fileTest', function () { expect(null).assertFail(); }, }); - }) + }); /** * @tc.number SUB_STORAGE_File_Get_0700 @@ -3529,7 +3569,7 @@ describe('fileTest', function () { file.get({ recursive: true, success: function (data) { - console.log('File_Get_007 call Copy success.') + console.log('File_Get_007 call Copy success.'); expect(null).assertFail(); }, fail: function (data, code) { @@ -3538,7 +3578,7 @@ describe('fileTest', function () { done(); }, }); - }) + }); /** * @tc.number SUB_STORAGE_File_Get_0800 @@ -3557,7 +3597,7 @@ describe('fileTest', function () { done(); }, }); - }) + }); /** * @tc.number SUB_STORAGE_File_Get_0900 @@ -3577,7 +3617,7 @@ describe('fileTest', function () { done(); }, }); - }) + }); /** * @tc.number SUB_STORAGE_File_Get_1000 @@ -3597,7 +3637,7 @@ describe('fileTest', function () { done(); }, }); - }) + }); /** * @tc.number SUB_STORAGE_File_Get_1100 @@ -3616,13 +3656,13 @@ describe('fileTest', function () { console.log('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.log('file list'); - console.log('uri:' + data.uri); + console.log('uri:' ); console.log('length:' + data.length); console.log('lastModifiedTime:' + data.lastModifiedTime); console.log('type:' + data.type); @@ -3644,8 +3684,8 @@ describe('fileTest', function () { console.log('File_Get_011 fail, code: ' + code + ', data: ' + data); expect(null).assertFail(); }, - }) - }) + }); + }); /** * @tc.number SUB_STORAGE_File_Get_1200 @@ -3667,7 +3707,7 @@ describe('fileTest', function () { recursive: true, success: function (data) { console.log('file list'); - console.log('uri:' + data.uri); + console.log('uri:' ); console.log('length:' + data.length); console.log('lastModifiedTime:' + data.lastModifiedTime); console.log('type:' + data.type); @@ -3681,7 +3721,7 @@ describe('fileTest', function () { done(); }, }); - }) + }); /** * @tc.number SUB_STORAGE_File_Get_1300 @@ -3702,7 +3742,7 @@ describe('fileTest', function () { recursive: true, success: function (data) { console.log('File_Get_013 => file list:'); - console.log('{uri:' + data.uri); + console.log('{uri:' ); console.log('length:' + data.length); console.log('lastModifiedTime:' + data.lastModifiedTime); console.log('type:' + data.type); @@ -3719,7 +3759,7 @@ describe('fileTest', function () { expect(null).assertFail(); }, }); - }) + }); /** * @tc.number SUB_STORAGE_File_Get_1400 @@ -3731,7 +3771,7 @@ describe('fileTest', function () { uri: 'internal://app/../files/../../', success: function (data) { console.log('File_Get_014 => file list :'); - console.log('{uri:' + data.uri); + console.log('{uri:' ); console.log('length:' + data.length); console.log('lastModifiedTime:' + data.lastModifiedTime); console.log('type:' + data.type); @@ -3744,5 +3784,5 @@ describe('fileTest', function () { expect(null).assertFail(); }, }); - }) -}) \ No newline at end of file + }); +}); diff --git a/storage/storagefileiojstest/project/entry/src/main/js/test/FileIO.test.js b/storage/storagefileiojstest/project/entry/src/main/js/test/FileIO.test.js index 3e0d8164e9daf48cb46c87ec0e442a5293be760a..b4f52731e5686a3b714c62038752096dac032060 100644 --- a/storage/storagefileiojstest/project/entry/src/main/js/test/FileIO.test.js +++ b/storage/storagefileiojstest/project/entry/src/main/js/test/FileIO.test.js @@ -1,43 +1,61 @@ /* * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); + * Licensed under the Apache License, Version 2.0 (the 'License'); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, + * distributed under the License is distributed on an 'AS IS' BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import fileio from '@ohos.fileio'; -import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index' +import bundle_mgr from '@ohos.bundle_mgr' import { - FILE_CONTENT, prepareFile, nextFileName, prepareEmptyFile, differentFileName, randomString, fileName -} from './Common' + describe, + beforeAll, + beforeEach, + afterEach, + afterAll, + it, + expect +} +from 'deccjsunit/index' +import { + FILE_CONTENT, + prepareFile, + nextFileName, + prepareEmptyFile, + differentFileName, + randomString, + fileName +} + from './Common' describe('fileIOTest', function () { - + 1 /** * @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, function () { - let fpath = nextFileName('fileio_test_open_close_sync_000') + let fpath = nextFileName('fileio_test_open_close_sync_000'); try { - let fd = fileio.openSync(fpath, 0o102, 0o666) - expect(fd !== null).assertTrue() - expect(fileio.closeSync(fd) !== null).assertTrue() - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - } catch (e) { - console.log("fileio_test_open_close_sync_000 has failed for " + e) - expect(null).assertFail() + let fd = fileio.openSync(fpath, 0o102, 0o666); + expect(fd !== null).assertTrue(); + expect(fileio.closeSync(fd) !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_open_close_sync_000 has failed for ' + e); + expect(null).assertFail(); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_OpenSync_0000 @@ -45,18 +63,879 @@ describe('fileIOTest', function () { * @tc.desc Function of API, openSync(mode not for value). The test file is exist. */ it('fileio_test_open_000', 0, function () { - let fpath = nextFileName('fileio_test_open_000') - prepareFile(fpath, FILE_CONTENT) + let fpath = nextFileName('fileio_test_open_000'); + prepareFile(fpath, FILE_CONTENT); + try { + let fd = fileio.openSync(fpath, 0o202); + expect(fd !== null).assertTrue(); + expect(fileio.closeSync(fd) !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_open_000 has failed for ' + e); + 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, function () { + let fpath = nextFileName('fileio_test_open_001'); + prepareFile(fpath, FILE_CONTENT); + try { + let fd = fileio.openSync(fpath, 0o100, 0o01); + expect(fd !== null).assertTrue(); + expect(fileio.closeSync(fd) !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_open_001 has failed for ' + e); + 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, function () { + let fpath = nextFileName('fileio_test_open_002'); + prepareFile(fpath, FILE_CONTENT); + try { + let fd = fileio.openSync(fpath); + expect(fd !== null).assertTrue(); + expect(fileio.closeSync(fd) !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_open_002 has failed for ' + e); + 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, function () { + let fpath = nextFileName('fileio_test_open_003'); + prepareFile(fpath, FILE_CONTENT); + 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 (e) { + console.log('fileio_test_open_003 has failed for ' + e); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + }); + + /** + * @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, function () { + let fpath = nextFileName('fileio_test_open_004'); + prepareFile(fpath, FILE_CONTENT); + try { + let fd = fileio.openSync(fpath, 0o101, 0o002); + expect(fd !== null).assertTrue(); + fileio.readSync(fd, new ArrayBuffer(4096), { + offset: 1, + }); + expect(null).assertFail(); + } + catch (e) { + console.log('fileio_test_open_004 has failed for ' + e); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + }); + + /** + * @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, function () { + let fpath = nextFileName('fileio_test_open_005'); + prepareFile(fpath, FILE_CONTENT); + 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(); + expect(fileio.closeSync(fd) !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_open_005 has failed for ' + e); + 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, function () { + let fpath = nextFileName('fileio_test_open_006'); + prepareFile(fpath, FILE_CONTENT); + try { + fileio.openSync(fpath, 0o200, 0o700); + expect(null).assertFail(); + } + catch (e) { + console.log('fileio_test_open_006 has failed for ' + e); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + }); + + /** + * @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, function () { + let fpath = 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(); + expect(fileio.closeSync(fd) !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_open_007 has failed for ' + e); + 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, function () { + let fpath = 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(); + expect(fileio.closeSync(fd) !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_open_008 has failed for ' + e); + 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, function () { + let fpath = nextFileName('fileio_test_open_009'); + try { + fileio.openSync(fpath, 0o302); + expect(null).assertFail(); + } + catch (e) { + console.log('fileio_test_open_009 has failed for ' + e); + } + }); + + /** + * @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, function () { + let fpath = nextFileName('fileio_test_open_010'); + prepareFile(fpath, FILE_CONTENT); + 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(); + expect(fileio.closeSync(fd) !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_open_010 has failed for ' + e); + 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, function () { + let fpath = nextFileName('fileio_test_open_011'); + prepareFile(fpath, FILE_CONTENT); + 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(); + expect(fileio.closeSync(fd) !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_open_011 has failed for ' + e); + 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, function () { + let fpath = nextFileName('fileio_test_open_012'); + prepareFile(fpath, FILE_CONTENT); + try { + let fd = fileio.openSync(fpath, 0o1001); + expect(fd !== null).assertTrue(); + fileio.readSync(fd, new ArrayBuffer(4096), { + offset: 1, + }); + expect(null).assertFail(); + } + catch (e) { + console.log('fileio_test_open_012 has failed for ' + e); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + }); + + /** + * @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, function () { + let fpath = nextFileName('fileio_test_open_013'); + prepareFile(fpath, FILE_CONTENT); + 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(); + expect(fileio.closeSync(fd) !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_open_013 has failed for ' + e); + 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 = nextFileName('fileio_test_open_014'); + prepareFile(fpath, FILE_CONTENT); + try { + let fd = fileio.openSync(fpath, 0o4002); + expect(fd !== null).assertTrue(); + let fd_1 = fileio.openSync(fpath, 0o4002); + expect(fd_1 !== null).assertTrue(); + expect(fileio.closeSync(fd) !== null).assertTrue(); + expect(fileio.closeSync(fd_1) !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + done(); + } + catch (e) { + console.log('fileio_test_open_014 has failed for ' + e); + 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, function () { + let fpath = nextFileName('fileio_test_open_015'); + prepareFile(fpath, FILE_CONTENT); + try { + let fd = fileio.openSync(fpath, 0o20002); + expect(fd !== null).assertTrue(); + expect(fileio.closeSync(fd) !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_open_015 has failed for ' + e); + 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, function () { + let fpath = nextFileName('fileio_test_open_016'); + prepareFile(fpath, FILE_CONTENT); + try { + let fd = fileio.openSync(fpath, 0o10002); + expect(fd !== null).assertTrue(); + expect(fileio.closeSync(fd) !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_open_016 has failed for ' + e); + 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, function () { + let fpath = nextFileName('fileio_test_open_017'); + prepareFile(fpath, FILE_CONTENT); + try { + let fd = fileio.openSync(fpath, 0o4010002); + expect(fd !== null).assertTrue(); + expect(fileio.closeSync(fd) !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_open_017 has failed for ' + e); + 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, function () { + let fpath = nextFileName('fileio_test_open_018'); + prepareFile(fpath, FILE_CONTENT); + try { + let fd = fileio.openSync(fpath, 0o100002); + expect(fd !== null).assertTrue(); + expect(fileio.closeSync(fd) !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_open_018 has failed for ' + e); + 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, function () { + let fpath = nextFileName('fileio_test_open_019'); + prepareFile(fpath, FILE_CONTENT); + try { + fileio.openSync(fpath, 0o40002, 0o700); + expect(null).assertFail(); + } + catch (e) { + console.log('fileio_test_open_019 has failed for ' + e); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + }); + + /** + * @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, function () { + let fpath = nextFileName('fileio_test_open_021'); + prepareFile(fpath, FILE_CONTENT); + try { + let fd = fileio.openSync(fpath, 0o2000002); + expect(fd !== null).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_open_021 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_OpenSync_2200 + * @tc.name fileio_test_open_022 + * @tc.desc Function of API, flags=0o200002. + */ + it('fileio_test_open_022', 0, function () { + let fpath = nextFileName('fileio_test_open_022'); + prepareFile(fpath, FILE_CONTENT); + try { + let fd = fileio.openSync(fpath, 0o200002); + expect(fd !== null).assertTrue(); + expect(fileio.closeSync(fd) !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_open_022 has failed for ' + e); + 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, function () { + let fpath = nextFileName('fileio_test_open_023'); + prepareFile(fpath, FILE_CONTENT); + try { + let fd = fileio.openSync(fpath, 0o400002); + expect(fd !== null).assertTrue(); + expect(fileio.closeSync(fd) !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_open_023 has failed for ' + e); + 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, function () { + let fpath = nextFileName('fileio_test_open_024'); + prepareFile(fpath, FILE_CONTENT); + try { + let fd = fileio.openSync(fpath, 0o1000002, 0o700); + expect(fd !== null).assertTrue(); + expect(fileio.closeSync(fd) !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_open_024 has failed for ' + e); + 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, function () { + let fpath = nextFileName('fileio_test_open_025'); + prepareFile(fpath, FILE_CONTENT); + try { + let fd = fileio.openSync(fpath, 0o10000002); + expect(fd !== null).assertTrue(); + expect(fileio.closeSync(fd) !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_open_025 has failed for ' + e); + 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, function () { + let fpath = nextFileName('fileio_test_open_026'); + prepareFile(fpath, FILE_CONTENT); + try { + let fd = fileio.openSync(fpath, 0o002, 0o700); + expect(fd !== null).assertTrue(); + expect(fileio.closeSync(fd) !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_open_026 has failed for ' + e); + 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, function () { + let fpath = nextFileName('fileio_test_open_027'); + prepareFile(fpath, FILE_CONTENT); + 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 (e) { + console.log('fileio_test_open_027 has failed for ' + e); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + }); + + /** + * @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, function () { + let fpath = nextFileName('fileio_test_open_028'); + prepareFile(fpath, FILE_CONTENT); + 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 (e) { + console.log('fileio_test_open_028 has failed for ' + e); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + }); + + /** + * @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, function () { + let fpath = nextFileName('fileio_test_open_029'); + prepareFile(fpath, FILE_CONTENT); + try { + let fd = fileio.openSync(fpath, 0o002, 0o100); + expect(fd !== null).assertTrue(); + expect(fileio.closeSync(fd) !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_open_029 has failed for ' + e); + 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, function () { + let fpath = nextFileName('fileio_test_open_030'); + prepareFile(fpath, FILE_CONTENT); + 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(); + expect(fileio.closeSync(fd) !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_open_030 has failed for ' + e); + 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, function () { + let fpath = nextFileName('fileio_test_open_031'); + prepareFile(fpath, FILE_CONTENT); + 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 (e) { + console.log('fileio_test_open_031 has failed for ' + e); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + }); + + /** + * @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, function () { + let fpath = nextFileName('fileio_test_open_032'); + prepareFile(fpath, FILE_CONTENT); + 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 (e) { + console.log('fileio_test_open_032 has failed for ' + e); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + }); + + /** + * @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, function () { + let fpath = nextFileName('fileio_test_open_033'); + prepareFile(fpath, FILE_CONTENT); + try { + let fd = fileio.openSync(fpath, 0o002, 0o010); + expect(fd !== null).assertTrue(); + expect(fileio.closeSync(fd) !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_open_033 has failed for ' + e); + 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, function () { + let fpath = nextFileName('fileio_test_open_034'); + prepareFile(fpath, FILE_CONTENT); + 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(); + expect(fileio.closeSync(fd) !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_open_034 has failed for ' + e); + 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, function () { + let fpath = nextFileName('fileio_test_open_035'); + prepareFile(fpath, FILE_CONTENT); try { - let fd = fileio.openSync(fpath, 0o202) - expect(fd !== null).assertTrue() - expect(fileio.closeSync(fd) !== null).assertTrue() - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - } catch (e) { - console.log("fileio_test_open_000 has failed for " + e) - expect(null).assertFail() + 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 (e) { + console.log('fileio_test_open_035 has failed for ' + e); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); } - }) + }); + + /** + * @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, function () { + let fpath = nextFileName('fileio_test_open_036'); + prepareFile(fpath, FILE_CONTENT); + 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 (e) { + console.log('fileio_test_open_036 has failed for ' + e); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + }); + + /** + * @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, function () { + let fpath = nextFileName('fileio_test_open_037'); + prepareFile(fpath, FILE_CONTENT); + try { + let fd = fileio.openSync(fpath, 0o002, 0o001); + expect(fileio.closeSync(fd) !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_open_037 has failed for ' + e); + 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, function () { + let txt = randomString(4100); + let fpath = nextFileName(txt); + try { + let fd = fileio.openSync(fpath, 0o102, 0o700); + expect(null).assertFail(); + } + catch (e) { + console.log('fileio_test_open_038 has failed for ' + e); + } + }); /** * @tc.number SUB_STORAGE_FileIO_OpenSync_0100 @@ -64,18 +943,19 @@ describe('fileIOTest', function () { * @tc.desc Function of API, openSync(flags=0o200). The test file is exist. */ it('fileio_test_open_sync_001', 0, function () { - let fpath = nextFileName('fileio_test_open_sync_001') - prepareFile(fpath, FILE_CONTENT) + let fpath = nextFileName('fileio_test_open_sync_001'); + prepareFile(fpath, FILE_CONTENT); try { - let fd = fileio.openSync(fpath, 0o200) - expect(fd !== null).assertTrue() - expect(fileio.closeSync(fd) !== null).assertTrue() - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - } catch (e) { - console.log("fileio_test_open_sync_001 has failed for " + e) - expect(null).assertFail() + let fd = fileio.openSync(fpath, 0o200); + expect(fd !== null).assertTrue(); + expect(fileio.closeSync(fd) !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_open_sync_001 has failed for ' + e); + expect(null).assertFail(); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_OpenSync_0200 @@ -83,18 +963,19 @@ describe('fileIOTest', function () { * @tc.desc Function of API, openSync(flags=0o201). The test file is exist. */ it('fileio_test_open_sync_002', 0, function () { - let fpath = nextFileName('fileio_test_open_sync_002') - prepareFile(fpath, FILE_CONTENT) + let fpath = nextFileName('fileio_test_open_sync_002'); + prepareFile(fpath, FILE_CONTENT); try { - let fd = fileio.openSync(fpath, 0o201) - expect(fd !== null).assertTrue() - expect(fileio.closeSync(fd) !== null).assertTrue() - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - } catch (e) { - console.log("fileio_test_open_sync_002 has failed for " + e) - expect(null).assertFail() + let fd = fileio.openSync(fpath, 0o201); + expect(fd !== null).assertTrue(); + expect(fileio.closeSync(fd) !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_open_sync_002 has failed for ' + e); + expect(null).assertFail(); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_OpenSync_0300 @@ -102,18 +983,19 @@ describe('fileIOTest', function () { * @tc.desc Function of API, openSync(flags=0o202). The test file is exist. */ it('fileio_test_open_sync_003', 0, function () { - let fpath = nextFileName('fileio_test_open_sync_003') - prepareFile(fpath, FILE_CONTENT) + let fpath = nextFileName('fileio_test_open_sync_003'); + prepareFile(fpath, FILE_CONTENT); try { - let fd = fileio.openSync(fpath, 0o202) - expect(fd !== null).assertTrue() - expect(fileio.closeSync(fd) !== null).assertTrue() - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - } catch (e) { - console.log("fileio_test_open_sync_003 has failed for " + e) - expect(null).assertFail() + let fd = fileio.openSync(fpath, 0o202); + expect(fd !== null).assertTrue(); + expect(fileio.closeSync(fd) !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_open_sync_003 has failed for ' + e); + expect(null).assertFail(); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_OpenSync_0400 @@ -121,17 +1003,18 @@ describe('fileIOTest', function () { * @tc.desc Function of API, openSync(flags=0o102, mode=0o777). The test file is not exist. */ it('fileio_test_open_sync_004', 0, function () { - let fpath = nextFileName('fileio_test_open_sync_004') + let fpath = nextFileName('fileio_test_open_sync_004'); try { - let fd = fileio.openSync(fpath, 0o102, 0o777) - expect(fd !== null).assertTrue() - expect(fileio.closeSync(fd) !== null).assertTrue() - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - } catch (e) { - console.log("fileio_test_open_sync_004 has failed for " + e) - expect(null).assertFail() + let fd = fileio.openSync(fpath, 0o102, 0o777); + expect(fd !== null).assertTrue(); + expect(fileio.closeSync(fd) !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_open_sync_004 has failed for ' + e); + expect(null).assertFail(); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_OpenSync_0500 @@ -141,16 +1024,17 @@ describe('fileIOTest', function () { it('fileio_test_open_sync_005', 0, function () { let dpath = nextFileName('fileio_test_open_sync_005') + 'd' try { - expect(fileio.mkdirSync(dpath) !== null).assertTrue() - let fd = fileio.openSync(dpath) - expect(fd !== null).assertTrue() - expect(fileio.closeSync(fd) !== null).assertTrue() - expect(fileio.rmdirSync(dpath) !== null).assertTrue() - } catch (e) { - console.log("fileio_test_open_sync_005 has failed for " + e) - expect(null).assertFail() + expect(fileio.mkdirSync(dpath) !== null).assertTrue(); + let fd = fileio.openSync(dpath); + expect(fd !== null).assertTrue(); + expect(fileio.closeSync(fd) !== null).assertTrue(); + expect(fileio.rmdirSync(dpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_open_sync_005 has failed for ' + e); + expect(null).assertFail(); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_OpenSync_0600 @@ -160,14 +1044,15 @@ describe('fileIOTest', function () { it('fileio_test_open_sync_006', 0, function () { let dpath = nextFileName('fileio_test_open_sync_006') + 'd' try { - expect(fileio.mkdirSync(dpath) !== null).assertTrue() - fileio.openSync(dpath, 0o1) - expect(null).assertFail() - } catch (e) { - console.log("fileio_test_open_sync_006 has failed for " + e) - fileio.rmdirSync(dpath) + expect(fileio.mkdirSync(dpath) !== null).assertTrue(); + fileio.openSync(dpath, 0o1); + expect(null).assertFail(); + } + catch (e) { + console.log('fileio_test_open_sync_006 has failed for ' + e); + fileio.rmdirSync(dpath); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_OpenSync_0700 @@ -175,23 +1060,24 @@ describe('fileIOTest', function () { * @tc.desc Function of API, openSync(fpath too long). */ it('fileio_test_open_sync_007', 0, function () { - let dpath = nextFileName("fileio_open1") - fileio.mkdirSync(dpath) + let dpath = nextFileName('fileio_open1'); + fileio.mkdirSync(dpath); try { for (let i = 0; i < 16; i++) { if (i == 15) { - let fpath = dpath + "/f" + randomString(248) - fileio.openSync(fpath, 0o102, 0o777) + let fpath = dpath + '/f' + randomString(248); + fileio.openSync(fpath, 0o102, 0o777); } else { - dpath = dpath + "/d" + randomString(248) - fileio.mkdirSync(dpath) + dpath = dpath + '/d' + randomString(248); + fileio.mkdirSync(dpath); } } - expect(null).assertFail() - } catch (e) { - console.log("fileio_test_open_sync_007 has failed for " + e) + expect(null).assertFail(); + } + catch (e) { + console.log('fileio_test_open_sync_007 has failed for ' + e); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_OpenSync_0800 @@ -199,14 +1085,15 @@ describe('fileIOTest', function () { * @tc.desc Function of API, openSync(filename too long). */ it('fileio_test_open_sync_008', 0, function () { - let fpath = nextFileName(randomString(256)) + let fpath = nextFileName(randomString(256)); try { - fileio.openSync(fpath, 0o102, 0o777) - expect(null).assertFail() - } catch (e) { - console.log("fileio_test_open_sync_008 has failed for " + e) + fileio.openSync(fpath, 0o102, 0o777); + expect(null).assertFail(); + } + catch (e) { + console.log('fileio_test_open_sync_008 has failed for ' + e); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_OpenSync_0900 @@ -214,23 +1101,24 @@ describe('fileIOTest', function () { * @tc.desc Function of API, openSync(dir layers too long). */ it('fileio_test_open_sync_009', 0, function () { - let dpath = nextFileName("prop1") - fileio.mkdirSync(dpath) + let dpath = nextFileName('prop1'); + fileio.mkdirSync(dpath); try { for (let i = 0; i < 113; i++) { if (i == 112) { - let fpath = dpath + "/f" + i - fileio.openSync(fpath, 0o102, 0o777) + let fpath = dpath + '/f' + i + fileio.openSync(fpath, 0o102, 0o777); } else { - dpath = dpath + "/" + i - fileio.mkdirSync(dpath) + dpath = dpath + '/' + i + fileio.mkdirSync(dpath); } } - expect(null).assertFail() - } catch (e) { - console.log("fileio_test_open_sync_009 has failed for " + e) + expect(null).assertFail(); + } + catch (e) { + console.log('fileio_test_open_sync_009 has failed for ' + e); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_OpenSync_1000 @@ -238,14 +1126,15 @@ describe('fileIOTest', function () { * @tc.desc Function of API, openSync(filename has special characters). */ it('fileio_test_open_sync_010', 0, function () { - let fpath = nextFileName("?*:<>/|") + let fpath = nextFileName('?*:<>/|'); try { - fileio.openSync(fpath, 0o102, 0o777) - expect(null).assertFail() - } catch (e) { - console.log("fileio_test_open_sync_010 has failed for " + e) + fileio.openSync(fpath, 0o102, 0o777); + expect(null).assertFail(); + } + catch (e) { + console.log('fileio_test_open_sync_010 has failed for ' + e); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_CloseSync_0000 @@ -253,15 +1142,16 @@ describe('fileIOTest', function () { * @tc.desc Function of API, close. The test file is not exist. */ it('fileio_test_close_sync_000', 0, function () { - let fpath = nextFileName('fileio_test_chmod_sync_000') + let fpath = nextFileName('fileio_test_chmod_sync_000'); try { - fileio.closeSync(fpath) - expect(null).assertFail() + fileio.closeSync(fpath); + expect(null).assertFail(); - } catch (e) { - console.log("fileio_test_close_sync_000 has failed for " + e) + } + catch (e) { + console.log('fileio_test_close_sync_000 has failed for ' + e); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_CloseSync_0100 @@ -270,12 +1160,13 @@ describe('fileIOTest', function () { */ it('fileio_test_close_sync_001', 0, function () { try { - fileio.closeSync(-1) - expect(null).assertFail() - } catch (e) { - console.log("fileio_test_close_sync_001 has failed for " + e) + fileio.closeSync(-1); + expect(null).assertFail(); + } + catch (e) { + console.log('fileio_test_close_sync_001 has failed for ' + e); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_AccessSync_0000 @@ -283,16 +1174,17 @@ describe('fileIOTest', function () { * @tc.desc Function of API,access. The test file is exist. */ it('fileio_test_access_sync_000', 0, function () { - let fpath = nextFileName('fileio_test_access_sync_000') - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + let fpath = nextFileName('fileio_test_access_sync_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); try { - expect(fileio.accessSync(fpath) !== null).assertTrue() - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - } catch (e) { - console.log("fileio_test_access_sync_000 has failed for " + e) - expect(null).assertFail() + expect(fileio.accessSync(fpath) !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_access_sync_000 has failed for ' + e); + expect(null).assertFail(); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_AccessSync_0100 @@ -301,12 +1193,13 @@ describe('fileIOTest', function () { */ it('fileio_test_access_sync_001', 0, function () { try { - fileio.accessSync(1) - expect(null).assertFail() - } catch (e) { - console.log("fileio_test_access_sync_001 has failed for " + e) + fileio.accessSync(1); + expect(null).assertFail(); + } + catch (e) { + console.log('fileio_test_access_sync_001 has failed for ' + e); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_AccessSync_0200 @@ -314,14 +1207,15 @@ describe('fileIOTest', function () { * @tc.desc Function of API, access. The test file is not exist. */ it('fileio_test_access_sync_002', 0, function () { - let fpath = nextFileName('fileIOTest') + let fpath = nextFileName('fileIOTest'); try { - fileio.accessSync(fpath) - expect(null).assertFail() - } catch (e) { - console.log("fileio_test_access_sync_002 has failed for " + e) + fileio.accessSync(fpath); + expect(null).assertFail(); + } + catch (e) { + console.log('fileio_test_access_sync_002 has failed for ' + e); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_AccessSync_0300 @@ -329,18 +1223,19 @@ describe('fileIOTest', function () { * @tc.desc Function of API, access(mode=1). The test file is exist and have the authority. */ it('fileio_test_access_sync_003', 0, function () { - let fpath = nextFileName('fileio_test_access_sync_004') - expect(prepareEmptyFile(fpath)).assertTrue() + let fpath = nextFileName('fileio_test_access_sync_004'); + expect(prepareEmptyFile(fpath)).assertTrue(); try { - let fd = fileio.accessSync(fpath) - console.log(fd) - expect(fileio.accessSync(fpath, 1) !== null).assertTrue() - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - } catch (e) { - console.log("fileio_test_access_sync_004 has failed for " + e) - expect(null).assertFail() + let fd = fileio.accessSync(fpath); + console.log(fd); + expect(fileio.accessSync(fpath, 1) !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_access_sync_004 has failed for ' + e); + expect(null).assertFail(); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_AccessSync_0400 @@ -348,18 +1243,19 @@ describe('fileIOTest', function () { * @tc.desc Function of API, access(mode=2). The test file is exist and have the authority. */ it('fileio_test_access_sync_004', 0, function () { - let fpath = nextFileName('fileio_test_access_sync_004') - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + let fpath = nextFileName('fileio_test_access_sync_004'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); try { - let fd = fileio.accessSync(fpath) - expect(fd !== null).assertTrue() - expect(fileio.accessSync(fpath, 2) !== null).assertTrue() - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - } catch (e) { - console.log("fileio_test_access_sync_004 has failed for " + e) - expect(null).assertFail() + let fd = fileio.accessSync(fpath); + expect(fd !== null).assertTrue(); + expect(fileio.accessSync(fpath, 2) !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_access_sync_004 has failed for ' + e); + expect(null).assertFail(); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_AccessSync_0500 @@ -369,15 +1265,16 @@ describe('fileIOTest', function () { it('fileio_test_access_sync_005', 0, function () { let dpath = nextFileName('fileio_test_access_sync_005') + 'd' try { - expect(fileio.mkdirSync(dpath) !== null).assertTrue() - let fd = fileio.accessSync(dpath) - expect(fd == undefined).assertTrue() - expect(fileio.rmdirSync(dpath) !== null).assertTrue() - } catch (e) { - console.log("fileio_test_access_sync_005 has failed for " + e) - expect(null).assertFail() + expect(fileio.mkdirSync(dpath) !== null).assertTrue(); + let fd = fileio.accessSync(dpath); + expect(fd == undefined).assertTrue(); + expect(fileio.rmdirSync(dpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_access_sync_005 has failed for ' + e); + expect(null).assertFail(); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_AccessSync_0600 @@ -387,12 +1284,33 @@ describe('fileIOTest', function () { it('fileio_test_access_sync_006', 0, function () { let dpath = nextFileName('fileio_test_access_sync_006') + 'd' try { - fileio.accessSync(dpath) - expect(null).assertFail() - } catch (e) { - console.log("fileio_test_access_sync_006 has failed for " + e) + fileio.accessSync(dpath); + expect(null).assertFail(); + } + catch (e) { + console.log('fileio_test_access_sync_006 has failed for ' + e); + } + }); + + /** + * @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, function () { + let fpath = nextFileName('fileio_test_access_sync_007'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let fd = fileio.accessSync(fpath); + expect(fd !== null).assertTrue(); + expect(fileio.accessSync(fpath, 4) !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_access_sync_007 has failed for ' + e); + expect(null).assertFail(); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_UnlinkSync_0000 @@ -400,15 +1318,16 @@ describe('fileIOTest', function () { * @tc.desc Function of API,unlinkSync. The test file is exist. */ it('fileio_test_unlink_sync_000', 0, function () { - let fpath = nextFileName('fileio_test_unlink_sync_000') - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + let fpath = nextFileName('fileio_test_unlink_sync_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); try { - expect(fileio.unlinkSync(fpath) !== null) - } catch (e) { - console.log("fileio_test_unlink_sync_000 has failed for " + e) - expect(null).assertFail() + expect(fileio.unlinkSync(fpath) !== null); + } + catch (e) { + console.log('fileio_test_unlink_sync_000 has failed for ' + e); + expect(null).assertFail(); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_UnlinkSync_0100 @@ -417,12 +1336,13 @@ describe('fileIOTest', function () { */ it('fileio_test_unlink_sync_001', 0, function () { try { - fileio.unlinkSync(1) - expect(null).assertFail() - } catch (e) { - console.log("fileio_test_unlink_sync_002 has failed for " + e) + fileio.unlinkSync(1); + expect(null).assertFail(); + } + catch (e) { + console.log('fileio_test_unlink_sync_002 has failed for ' + e); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_UnlinkSync_0200 @@ -430,14 +1350,15 @@ describe('fileIOTest', function () { * @tc.desc Function of API, invaild parameter */ it('fileio_test_unlink_sync_002', 0, function () { - let fpath = nextFileName('fileIOTest') + let fpath = nextFileName('fileIOTest'); try { - fileio.unlinkSync(fpath) - expect(null).assertFail() - } catch (e) { - console.log("fileio_test_unlink_sync_003 has failed for " + e) + fileio.unlinkSync(fpath); + expect(null).assertFail(); + } + catch (e) { + console.log('fileio_test_unlink_sync_003 has failed for ' + e); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_WriteSync_0000 @@ -445,17 +1366,19 @@ describe('fileIOTest', function () { * @tc.desc Function of API, writeSync. */ it('fileio_test_write_sync_000', 0, function () { - let fpath = nextFileName('fileio_test_write_sync_000') + let fpath = nextFileName('fileio_test_write_sync_000'); try { - let fd = fileio.openSync(fpath, 0o102, 0o666) - expect(fileio.writeSync(fd, FILE_CONTENT) !== null).assertTrue() - expect(fileio.closeSync(fd) !== null).assertTrue() - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - } catch (e) { - console.log("fileio_test_write_sync_000 has failed for " + e) - expect(null).assertFail() + let fd = fileio.openSync(fpath, 0o102, 0o666); + let res = fileio.writeSync(fd, FILE_CONTENT); + expect(typeof(res) == 'number').assertTrue(); + expect(fileio.closeSync(fd) !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_write_sync_000 has failed for ' + e); + expect(null).assertFail(); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_WriteSync_0100 @@ -463,19 +1386,21 @@ describe('fileIOTest', function () { * @tc.desc Function of API, encoding=UTF-8. */ it('fileio_test_write_sync_001', 0, function () { - let fpath = nextFileName('fileio_test_write_sync_001') - try { - let fd = fileio.openSync(fpath, 0o102, 0o666) - expect(fileio.writeSync(fd, FILE_CONTENT, { - encoding: "utf-8", - }) !== null).assertTrue() - expect(fileio.closeSync(fd) !== null).assertTrue() - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - } catch (e) { - console.log("fileio_test_write_sync_001 has failed for " + e) - expect(null).assertFail() + let fpath = 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(); + expect(fileio.closeSync(fd) !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_write_sync_001 has failed for ' + e); + expect(null).assertFail(); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_WriteSync_0200 @@ -483,20 +1408,21 @@ describe('fileIOTest', function () { * @tc.desc Function of API, offset=1. */ it('fileio_test_write_sync_002', 0, function () { - let fpath = nextFileName('fileio_test_write_sync_002') - let text = "0123456789abcdefg"; + let fpath = nextFileName('fileio_test_write_sync_002'); + let text = '0123456789abcdefg'; try { - let fd = fileio.openSync(fpath, 0o102, 0o666) + let fd = fileio.openSync(fpath, 0o102, 0o666); expect(fileio.writeSync(fd, text, { offset: 1, - }) == text.length - 1).assertTrue() - expect(fileio.closeSync(fd) !== null).assertTrue() - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - } catch (e) { - console.log("fileio_test_write_sync_002 has failed for " + e) - expect(null).assertFail() + }) == text.length - 1).assertTrue(); + expect(fileio.closeSync(fd) !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_write_sync_002 has failed for ' + e); + expect(null).assertFail(); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_WriteSync_0300 @@ -504,19 +1430,20 @@ describe('fileIOTest', function () { * @tc.desc Function of API, length = - 1. */ it('fileio_test_write_sync_003', 0, function () { - let fpath = nextFileName('fileio_test_write_sync_003') + let fpath = nextFileName('fileio_test_write_sync_003'); try { - let fd = fileio.openSync(fpath, 0o102, 0o666) + let fd = fileio.openSync(fpath, 0o102, 0o666); expect(fileio.writeSync(fd, FILE_CONTENT, { length: FILE_CONTENT.length - 1, - }) == (FILE_CONTENT.length - 1)).assertTrue() - expect(fileio.closeSync(fd) !== null).assertTrue() - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - } catch (e) { - console.log("fileio_test_write_sync_003 has failed for " + e) - expect(null).assertFail() + }) == (FILE_CONTENT.length - 1)).assertTrue(); + expect(fileio.closeSync(fd) !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_write_sync_003 has failed for ' + e); + expect(null).assertFail(); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_WriteSync_0400 @@ -524,20 +1451,22 @@ describe('fileIOTest', function () { * @tc.desc Function of API, length = 1, offset = 1. */ it('fileio_test_write_sync_004', 0, function () { - let fpath = nextFileName('fileio_test_write_sync_004') + let fpath = nextFileName('fileio_test_write_sync_004'); try { - let fd = fileio.openSync(fpath, 0o102, 0o666) - expect(fileio.writeSync(fd, FILE_CONTENT, { + let fd = fileio.openSync(fpath, 0o102, 0o666); + let res = fileio.writeSync(fd, FILE_CONTENT, { offset: 1, length: 1, - }) !== null).assertTrue() - expect(fileio.closeSync(fd) !== null).assertTrue() - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - } catch (e) { - console.log("fileio_test_write_sync_004 has failed for " + e) - expect(null).assertFail() + }); + expect(typeof(res) == 'number').assertTrue(); + expect(fileio.closeSync(fd) !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_write_sync_004 has failed for ' + e); + expect(null).assertFail(); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_WriteSync_0500 @@ -545,21 +1474,22 @@ describe('fileIOTest', function () { * @tc.desc Function of API, invaild offset. */ it('fileio_test_write_sync_005', 0, function () { - let fpath = nextFileName('fileio_test_write_sync_005') + let fpath = nextFileName('fileio_test_write_sync_005'); const invalidOffset = 999 let fd try { - fd = fileio.openSync(fpath, 0o102, 0o666) - expect(fd).assertInstanceOf('Number') + fd = fileio.openSync(fpath, 0o102, 0o666); + expect(fd).assertInstanceOf('Number'); expect(fileio.writeSync(fd, FILE_CONTENT, { offset: invalidOffset, - }) == 1).assertTrue() - expect(null).assertFail() - } catch (e) { - expect(fileio.closeSync(fd) !== null).assertTrue() - expect(fileio.unlinkSync(fpath) !== null).assertTrue() + }) == 1).assertTrue(); + expect(null).assertFail(); + } + catch (e) { + expect(fileio.closeSync(fd) !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_WriteSync_0600 @@ -567,21 +1497,22 @@ describe('fileIOTest', function () { * @tc.desc Function of API, invaild length. */ it('fileio_test_write_sync_006', 0, function () { - let fpath = nextFileName('fileio_test_write_sync_006') + let fpath = nextFileName('fileio_test_write_sync_006'); const invalidLength = 999 let fd try { - fd = fileio.openSync(fpath, 0o102, 0o666) - expect(fd).assertInstanceOf('Number') + fd = fileio.openSync(fpath, 0o102, 0o666); + expect(fd).assertInstanceOf('Number'); expect(fileio.writeSync(fd, FILE_CONTENT, { length: invalidLength, - }) == 1) - expect(null).assertFail() - } catch (e) { - expect(fileio.closeSync(fd) !== null).assertTrue() - expect(fileio.unlinkSync(fpath) !== null).assertTrue() + }) == 1); + expect(null).assertFail(); + } + catch (e) { + expect(fileio.closeSync(fd) !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_WriteSync_0700 @@ -590,12 +1521,13 @@ describe('fileIOTest', function () { */ it('fileio_test_write_sync_007', 0, function () { try { - fileio.writeSync(1, 1) - expect(null).assertFail() - } catch (e) { - console.log("fileio_test_write_sync_007 has failed for " + e) + fileio.writeSync(1, 1); + expect(null).assertFail(); + } + catch (e) { + console.log('fileio_test_write_sync_007 has failed for ' + e); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_WriteSync_0800 @@ -604,33 +1536,93 @@ describe('fileIOTest', function () { */ it('fileio_test_write_sync_008', 0, function () { try { - console.log(fileio.writeSync(-1, FILE_CONTENT)) - expect(null).assertFail() - } catch (e) { - console.log("fileio_test_write_sync_008 has failed for " + e) + console.log(fileio.writeSync(-1, FILE_CONTENT)); + expect(null).assertFail(); + } + catch (e) { + console.log('fileio_test_write_sync_008 has failed for ' + e); + } + }); + + /** + * @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, function () { + let fpath = 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(); + expect(fileio.closeSync(fd) !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_write_sync_009 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_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, function () { + let fpath = nextFileName('fileio_test_write_sync_010'); + let fd = fileio.openSync(fpath, 0o102, 0o666); + try { + fileio.writeSync(fd, FILE_CONTENT, { + encoding: 'gb2312', + }); + expect(null).assertFail(); + } + catch (e) { + console.log('fileio_test_write_sync_010 has failed for ' + e); + expect(fileio.closeSync(fd) !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_ReadSync_0000 * @tc.name fileio_test_read_sync_000 * @tc.desc Function of API, readSync. */ - it('fileio_test_read_sync_000', 0, function () { - let fpath = nextFileName('fileio_test_read_sync_000') - let text = "0123456789abcdefg"; - expect(prepareFile(fpath, text)).assertTrue() - try { - let fd = fileio.openSync(fpath, 0o2) - let len = fileio.readSync(fd, new ArrayBuffer(4096)) - expect(len == text.length).assertTrue() - expect(fileio.closeSync(fd) !== null).assertTrue() - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - } catch (e) { - console.log("fileio_test_read_sync_000 has failed for " + e) - expect(null).assertFail() + it('fileio_test_read_sync_000', 0, async function (done) { + let fpath = nextFileName('fileio_test_read_sync_000'); + let text = '0123456789abcdefg'; + expect(prepareFile(fpath, text)).assertTrue(); + try { + let fd = fileio.openSync(fpath, 0o2); + let len = fileio.readSync(fd, new ArrayBuffer(4096)); + expect(len == text.length).assertTrue(); + expect(fileio.closeSync(fd) !== null).assertTrue(); + file.readText({ + uri: 'internal://cache/fileio_test_read_sync_000', + success: function (data) { + console.log('call readText success: ' + data.text); + expect(text == data.text).assertTrue(); + done(); + }, + fail: function (data, code) { + console.error('call fail callback fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_read_sync_000 has failed for ' + e); + expect(null).assertFail(); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_ReadSync_0100 @@ -639,22 +1631,23 @@ describe('fileIOTest', function () { */ it('fileio_test_read_sync_001', 0, function () { let bufLen = 5 - expect(FILE_CONTENT.length > bufLen).assertTrue() - let fpath = nextFileName('fileio_test_read_sync_001') - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + expect(FILE_CONTENT.length > bufLen).assertTrue(); + let fpath = nextFileName('fileio_test_read_sync_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); try { - let fd = fileio.openSync(fpath, 0o2) + let fd = fileio.openSync(fpath, 0o2); let len = fileio.readSync(fd, new ArrayBuffer(bufLen), { - offset: 1, - }) - expect(len == bufLen - 1).assertTrue() - expect(fileio.closeSync(fd) !== null).assertTrue() - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - } catch (e) { - console.log("fileio_test_read_sync_001 has failed for " + e) - expect(null).assertFail() + offset: 1, + }); + expect(len == bufLen - 1).assertTrue(); + expect(fileio.closeSync(fd) !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_read_sync_001 has failed for ' + e); + expect(null).assertFail(); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_ReadSync_0200 @@ -662,21 +1655,22 @@ describe('fileIOTest', function () { * @tc.desc Function of API, length = 1. */ it('fileio_test_read_sync_002', 0, function () { - let fpath = nextFileName('fileio_test_read_sync_002') - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + let fpath = nextFileName('fileio_test_read_sync_002'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); try { - let fd = fileio.openSync(fpath, 0o2) + let fd = fileio.openSync(fpath, 0o2); let len = fileio.readSync(fd, new ArrayBuffer(4096), { length: 1, - }) - expect(len == 1).assertTrue() - expect(fileio.closeSync(fd) !== null).assertTrue() - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - } catch (e) { - console.log("fileio_test_read_sync_002 has failed for " + e) - expect(null).assertFail() + }); + expect(len == 1).assertTrue(); + expect(fileio.closeSync(fd) !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_read_sync_002 has failed for ' + e); + expect(null).assertFail(); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_ReadSync_0300 @@ -686,204 +1680,517 @@ describe('fileIOTest', function () { it('fileio_test_read_sync_003', 0, function () { let fd const invalidOffset = 99999 - let fpath = nextFileName('fileio_test_read_sync_003') - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + let fpath = 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, + }); + expect(null).assertFail(); + } + catch (e) { + expect(fileio.closeSync(fd) !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + console.log('fileio_test_read_sync_003 has failed for ' + e); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_ReadSync_0300 + * @tc.name fileio_test_read_sync_004 + * @tc.desc Function of API, invaild length. + */ + it('fileio_test_read_sync_004', 0, function () { + let fd + const invalidLength = 9999 + let fpath = 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, + }); + expect(null).assertFail(); + } + catch (e) { + expect(fileio.closeSync(fd) !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + console.log('fileio_test_read_sync_004 has failed for ' + e); + } + }); + + /** + * @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, function () { + try { + fileio.readSync(-1, new ArrayBuffer(4096)); + expect(null).assertFail(); + } + catch (e) { + console.log('fileio_test_read_sync_005 has failed for ' + e); + } + }); + + /** + * @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, function () { + let fpath = 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); + expect(fileio.closeSync(fd) !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_read_sync_006 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_ReadSync_0700 + * @tc.name fileio_test_read_sync_007 + * @tc.desc Function of API, invaild position. + */ + it('fileio_test_read_sync_007', 0, function () { + let fpath = 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, + }); + expect(fileio.closeSync(fd) !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_read_sync_007 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_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, function () { + let fpath = 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(); + expect(fileio.closeSync(fd) !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_read_sync_008 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_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, function () { + let fpath = 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(); + expect(fileio.closeSync(fd) !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_read_sync_009 has failed for ' + e); + 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, function () { + let fpath = 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), { + position: 1, + offset: 1, + length: 1, + }); + expect(null).assertFail(); + } + catch (e) { + console.log('fileio_test_read_sync_010 has failed for ' + e); + expect(fileio.closeSync(fd) !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + }); + + /** + * @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, function () { + let fpath = 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(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_chmod_sync_000 has failed for ' + e); + 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, function () { + let fpath = 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(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_chmod_sync_001 has failed for ' + e); + 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, function () { + let fpath = 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(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_chmod_sync_002 has failed for ' + e); + 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, function () { + let fpath = nextFileName('fileio_test_chmod_sync_003'); + try { + fileio.chmodSync(fpath, 0o260); + expect(null).assertFail(); + } + catch (e) { + console.log('fileio_test_chmod_sync_003 has failed for ' + e); + } + }); + + /** + * @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, function () { + let dpath = nextFileName('fileio_test_chmod_sync_004'); + try { + expect(fileio.mkdirSync(dpath, 0o777) !== null).assertTrue(); + expect(fileio.chmodSync(dpath, 0o660) !== null).assertTrue(); + expect((fileio.statSync(dpath).mode & 0o777) == 0o660).assertTrue(); + expect(fileio.rmdirSync(dpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_chmod_sync_000 has failed for ' + e); + 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, function () { + let dpath; + try { + fileio.chmodSync(dpath, 0o660); + expect(null).assertFail(); + } + catch (e) { + console.log('fileio_test_chmod_sync_005 has failed for ' + e); + } + }); + + /** + * @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, function () { + let fpath = 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(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_chmod_sync_006 has failed for ' + e); + 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, function () { + let fpath = nextFileName('fileio_test_chmod_sync_007'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); try { - fd = fileio.openSync(fpath, 0o2) - fileio.readSync(fd, new ArrayBuffer(4096), { - offset: invalidOffset, - }) - expect(null).assertFail() - } catch (e) { - expect(fileio.closeSync(fd) !== null).assertTrue() - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - console.log("fileio_test_read_sync_003 has failed for " + e) + expect(fileio.chmodSync(fpath, 0o400) !== null).assertTrue(); + expect((fileio.statSync(fpath).mode & 0o777) == 0o400).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_chmod_sync_002 has failed for ' + e); + expect(null).assertFail(); } - }) + }); /** - * @tc.number SUB_STORAGE_FileIO_ReadSync_0300 - * @tc.name fileio_test_read_sync_004 - * @tc.desc Function of API, invaild length. + * @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_read_sync_004', 0, function () { - let fd - const invalidLength = 9999 - let fpath = nextFileName('fileio_test_read_sync_004') - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() - + it('fileio_test_chmod_sync_008', 0, function () { + let fpath = nextFileName('fileio_test_chmod_sync_008'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); try { - fd = fileio.openSync(fpath, 0o2) - fileio.readSync(fd, new ArrayBuffer(4096), { - length: invalidLength, - }) - expect(null).assertFail() - } catch (e) { - expect(fileio.closeSync(fd) !== null).assertTrue() - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - console.log("fileio_test_read_sync_004 has failed for " + e) + expect(fileio.chmodSync(fpath, 0o200) !== null).assertTrue(); + expect((fileio.statSync(fpath).mode & 0o777) == 0o200).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_chmod_sync_008 has failed for ' + e); + expect(null).assertFail(); } - }) + }); /** - * @tc.number SUB_STORAGE_FileIO_ReadSync_0500 - * @tc.name fileio_test_read_sync_005 - * @tc.desc Function of API, fpatch = -1. + * @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_read_sync_005', 0, function () { + it('fileio_test_chmod_sync_009', 0, function () { + let fpath = nextFileName('fileio_test_chmod_sync_009'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); try { - fileio.readSync(-1, new ArrayBuffer(4096)) - expect(null).assertFail() - } catch (e) { - console.log("fileio_test_read_sync_005 has failed for " + e) + expect(fileio.chmodSync(fpath, 0o100) !== null).assertTrue(); + expect((fileio.statSync(fpath).mode & 0o777) == 0o100).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_chmod_sync_009 has failed for ' + e); + expect(null).assertFail(); } - }) + }); /** - * @tc.number SUB_STORAGE_FileIO_ReadSync_0600 - * @tc.name fileio_test_read_sync_006 - * @tc.desc Function of API, offset & length & position = 1. + * @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_read_sync_006', 0, function () { - let fpath = nextFileName('fileio_test_read_sync_006') - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + it('fileio_test_chmod_sync_010', 0, function () { + let fpath = nextFileName('fileio_test_chmod_sync_010'); + 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) - expect(fileio.closeSync(fd) !== null).assertTrue() - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - } catch (e) { - console.log("fileio_test_read_sync_006 has failed for " + e) - expect(null).assertFail() + expect(fileio.chmodSync(fpath, 0o070) !== null).assertTrue(); + expect((fileio.statSync(fpath).mode & 0o777) == 0o070).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_chmod_sync_010 has failed for ' + e); + expect(null).assertFail(); } - }) + }); /** - * @tc.number SUB_STORAGE_FileIO_ReadSync_0700 - * @tc.name fileio_test_read_sync_007 - * @tc.desc Function of API, invaild position. + * @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_read_sync_007', 0, function () { - let fpath = nextFileName('fileio_test_read_sync_007') - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + it('fileio_test_chmod_sync_011', 0, function () { + let fpath = nextFileName('fileio_test_chmod_sync_011'); + 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, - }) - expect(fileio.closeSync(fd) !== null).assertTrue() - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - } catch (e) { - console.log("fileio_test_read_sync_007 has failed for " + e) - expect(null).assertFail() + expect(fileio.chmodSync(fpath, 0o040) !== null).assertTrue(); + expect((fileio.statSync(fpath).mode & 0o777) == 0o040).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_chmod_sync_011 has failed for ' + e); + expect(null).assertFail(); } - }) + }); /** - * @tc.number SUB_STORAGE_FileIO_ChmodSync_0000 - * @tc.name fileio_test_chmod_sync_000 - * @tc.desc Function of API, mode=0o660 + * @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_000', 0, function () { - let fpath = nextFileName('fileio_test_chmod_sync_000') - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + it('fileio_test_chmod_sync_012', 0, function () { + let fpath = nextFileName('fileio_test_chmod_sync_012'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); try { - expect(fileio.chmodSync(fpath, 0o660) !== null).assertTrue() - expect((fileio.statSync(fpath).mode & 0o777) == 0o660).assertTrue() - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - } catch (e) { - console.log("fileio_test_chmod_sync_000 has failed for " + e) - expect(null).assertFail() + expect(fileio.chmodSync(fpath, 0o020) !== null).assertTrue(); + expect((fileio.statSync(fpath).mode & 0o777) == 0o020).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_chmod_sync_012 has failed for ' + e); + expect(null).assertFail(); } - }) + }); /** - * @tc.number SUB_STORAGE_FileIO_ChmodSync_0100 - * @tc.name fileio_test_chmod_sync_001 - * @tc.desc Function of API, mode=0o460 + * @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_001', 0, function () { - let fpath = nextFileName('fileio_test_chmod_sync_001') - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + it('fileio_test_chmod_sync_013', 0, function () { + let fpath = nextFileName('fileio_test_chmod_sync_013'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); try { - expect(fileio.chmodSync(fpath, 0o460) !== null).assertTrue() - expect((fileio.statSync(fpath).mode & 0o777) == 0o460).assertTrue() - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - } catch (e) { - console.log("fileio_test_chmod_sync_001 has failed for " + e) - expect(null).assertFail() + expect(fileio.chmodSync(fpath, 0o010) !== null).assertTrue(); + expect((fileio.statSync(fpath).mode & 0o777) == 0o010).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_chmod_sync_013 has failed for ' + e); + 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. + * @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_002', 0, function () { - let fpath = nextFileName('fileio_test_chmod_sync_002') - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + it('fileio_test_chmod_sync_014', 0, function () { + let fpath = nextFileName('fileio_test_chmod_sync_014'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); try { - expect(fileio.chmodSync(fpath, 0o260) !== null).assertTrue() - expect((fileio.statSync(fpath).mode & 0o777) == 0o260).assertTrue() - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - } catch (e) { - console.log("fileio_test_chmod_sync_002 has failed for " + e) - expect(null).assertFail() + expect(fileio.chmodSync(fpath, 0o007) !== null).assertTrue(); + expect((fileio.statSync(fpath).mode & 0o777) == 0o007).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_chmod_sync_014 has failed for ' + e); + 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. + * @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_003', 0, function () { - let fpath = nextFileName('fileio_test_chmod_sync_003') + it('fileio_test_chmod_sync_015', 0, function () { + let fpath = nextFileName('fileio_test_chmod_sync_015'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); try { - fileio.chmodSync(fpath, 0o260) - expect(null).assertFail() - } catch (e) { - console.log("fileio_test_chmod_sync_003 has failed for " + e) + expect(fileio.chmodSync(fpath, 0o004) !== null).assertTrue(); + expect((fileio.statSync(fpath).mode & 0o777) == 0o004).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_chmod_sync_015 has failed for ' + e); + expect(null).assertFail(); } - }) + }); /** - * @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. + * @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_004', 0, function () { - let dpath = nextFileName('fileio_test_chmod_sync_004') + it('fileio_test_chmod_sync_016', 0, function () { + let fpath = nextFileName('fileio_test_chmod_sync_016'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); try { - expect(fileio.mkdirSync(dpath, 0o777) !== null).assertTrue() - expect(fileio.chmodSync(dpath, 0o660) !== null).assertTrue() - expect((fileio.statSync(dpath).mode & 0o777) == 0o660).assertTrue() - expect(fileio.rmdirSync(dpath) !== null).assertTrue() - } catch (e) { - console.log("fileio_test_chmod_sync_000 has failed for " + e) - expect(null).assertFail() + expect(fileio.chmodSync(fpath, 0o002) !== null).assertTrue(); + expect((fileio.statSync(fpath).mode & 0o777) == 0o002).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_chmod_sync_016 has failed for ' + e); + 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. + * @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_005', 0, function () { - let dpath; + it('fileio_test_chmod_sync_017', 0, function () { + let fpath = nextFileName('fileio_test_chmod_sync_017'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); try { - fileio.chmodSync(dpath, 0o660) - expect(null).assertFail() - } catch (e) { - console.log("fileio_test_chmod_sync_005 has failed for " + e) + expect(fileio.chmodSync(fpath, 0o001) !== null).assertTrue(); + expect((fileio.statSync(fpath).mode & 0o777) == 0o001).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_chmod_sync_017 has failed for ' + e); + expect(null).assertFail(); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_copyFileSync_0000 @@ -891,18 +2198,19 @@ describe('fileIOTest', function () { * @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, function () { - let fpath = nextFileName('fileio_test_copy_file_sync_000') + let fpath = nextFileName('fileio_test_copy_file_sync_000'); let fpathTarget = fpath + 'tgt' - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); try { - expect(fileio.copyFileSync(fpath, fpathTarget) !== null).assertTrue() - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - expect(fileio.unlinkSync(fpathTarget) !== null).assertTrue() - } catch (e) { - console.log("fileio_test_copy_file_sync_000 has failed for " + e) - expect(null).assertFail() + expect(fileio.copyFileSync(fpath, fpathTarget) !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + expect(fileio.unlinkSync(fpathTarget) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_copy_file_sync_000 has failed for ' + e); + expect(null).assertFail(); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_copyFileSync_0100 @@ -913,12 +2221,13 @@ describe('fileIOTest', function () { let fpath = nextFileName('fileio_test_copy_file_sync_001') + 'd' let fpathTarget = fpath + 'tgt' try { - fileio.copyFileSync(fpath, fpathTarget) - expect(null).assertFail() - } catch (e) { - console.log("fileio_test_copy_file_sync_001 has failed for " + e); + fileio.copyFileSync(fpath, fpathTarget); + expect(null).assertFail(); + } + catch (e) { + console.log('fileio_test_copy_file_sync_001 has failed for ' + e); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_copyFileSync_0200 @@ -926,14 +2235,15 @@ describe('fileIOTest', function () { * @tc.desc Function of API, copy. fpatch is vaild, fpathTarget is invaild. */ it('fileio_test_copy_file_sync_002', 0, function () { - let fpath = nextFileName('fileio_test_copy_file_sync_002') + let fpath = nextFileName('fileio_test_copy_file_sync_002'); try { - fileio.copyFileSync(fpath, 0) - expect(null).assertFail() - } catch (e) { - console.log("fileio_test_copy_file_sync_002 has failed for " + e); + fileio.copyFileSync(fpath, 0); + expect(null).assertFail(); + } + catch (e) { + console.log('fileio_test_copy_file_sync_002 has failed for ' + e); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_copyFileSync_0300 @@ -941,18 +2251,19 @@ describe('fileIOTest', function () { * @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, function () { - let fpath = nextFileName('fileio_test_copy_file_sync_003') + let fpath = nextFileName('fileio_test_copy_file_sync_003'); let fpathTarget = fpath + 'f1' - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); try { - expect(fileio.copyFileSync(fpath, fpathTarget) !== null).assertTrue() - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - expect(fileio.unlinkSync(fpathTarget) !== null).assertTrue() - } catch (e) { - console.log("fileio_test_copy_file_sync_003 has failed for " + e) - expect(null).assertFail() + expect(fileio.copyFileSync(fpath, fpathTarget) !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + expect(fileio.unlinkSync(fpathTarget) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_copy_file_sync_003 has failed for ' + e); + expect(null).assertFail(); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_copyFileSync_0400 @@ -960,18 +2271,19 @@ describe('fileIOTest', function () { * @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, function () { - let fpath = nextFileName('fileio_test_copy_file_sync_004') - let fpathTarget = fileName('fileio_test_copy_file_sync_004') - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + let fpath = nextFileName('fileio_test_copy_file_sync_004'); + let fpathTarget = fileName('fileio_test_copy_file_sync_004'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); try { - expect(fileio.copyFileSync(fpath, fpathTarget) !== null).assertTrue() - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - expect(fileio.unlinkSync(fpathTarget) !== null).assertTrue() - } catch (e) { - console.log("fileio_test_copy_file_sync_004 has failed for " + e) - expect(null).assertFail() + expect(fileio.copyFileSync(fpath, fpathTarget) !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + expect(fileio.unlinkSync(fpathTarget) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_copy_file_sync_004 has failed for ' + e); + expect(null).assertFail(); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_copyFileSync_0500 @@ -979,17 +2291,18 @@ describe('fileIOTest', function () { * @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, function () { - let fpath = nextFileName('fileio_test_copy_file_sync_005') + let fpath = nextFileName('fileio_test_copy_file_sync_005'); let fpathTarget = fpath - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); try { - expect(fileio.copyFileSync(fpath, fpathTarget) !== null).assertTrue() + expect(fileio.copyFileSync(fpath, fpathTarget) !== null).assertTrue(); expect(fileio.unlinkSync(fpath) !== null).assertTrue(); - } catch (e) { - console.log("fileio_test_copy_file_sync_005 has failed for " + e) - expect(null).assertFail() + } + catch (e) { + console.log('fileio_test_copy_file_sync_005 has failed for ' + e); + expect(null).assertFail(); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_copyFileSync_0600 @@ -997,29 +2310,31 @@ describe('fileIOTest', function () { * @tc.desc Function of API, copy. fpathTarget is invaild. */ it('fileio_test_copy_file_sync_006', 0, function () { - let fpath = nextFileName('fileio_test_copy_file_sync_006') + let fpath = nextFileName('fileio_test_copy_file_sync_006'); let fpathTarget = fpath + 'tgt' try { - fileio.copyFileSync(fpath, fpathTarget) - expect(null).assertFail() - } catch (e) { - console.log("fileio_test_copy_file_sync_006 has failed for " + e) + fileio.copyFileSync(fpath, fpathTarget); + expect(null).assertFail(); + } + catch (e) { + console.log('fileio_test_copy_file_sync_006 has failed for ' + e); } - }) + }); /** - * @tc.number SUB_STORAGE_FileIO_copyFileSync_0700 - * @tc.name fileio_test_copy_file_sync_007 - * @tc.desc Function of API, copy. fpatch is invaild, fpathTarget is invaild. - */ + * @tc.number SUB_STORAGE_FileIO_copyFileSync_0700 + * @tc.name fileio_test_copy_file_sync_007 + * @tc.desc Function of API, copy. fpatch is invaild, fpathTarget is invaild. + */ it('fileio_test_copy_file_sync_007', 0, function () { try { - fileio.copyFileSync(1, 1) - expect(null).assertFail() - } catch (e) { - console.log("fileio_test_copy_file_sync_007 has failed for " + e) + fileio.copyFileSync(1, 1); + expect(null).assertFail(); + } + catch (e) { + console.log('fileio_test_copy_file_sync_007 has failed for ' + e); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_copyFileSync_0800 @@ -1027,25 +2342,26 @@ describe('fileIOTest', function () { * @tc.desc Function of API, parameter more than 4096. */ it('fileio_test_copy_file_sync_008', 0, function () { - let fpath = nextFileName("fileio_test_copy_file_sync_008") - fileio.openSync(fpath, 0o102, 0o777) - let dpath = nextFileName("fileio_copy1") - fileio.mkdirSync(dpath) + let fpath = nextFileName('fileio_test_copy_file_sync_008'); + fileio.openSync(fpath, 0o102, 0o777); + let dpath = nextFileName('fileio_copy1'); + fileio.mkdirSync(dpath); try { for (let i = 0; i < 16; i++) { if (i == 15) { - let fpathTarget = dpath + "/f" + randomString(248) - fileio.copyFileSync(fpath, fpathTarget) + let fpathTarget = dpath + '/f' + randomString(248); + fileio.copyFileSync(fpath, fpathTarget); } else { - dpath = dpath + "/d" + randomString(248) - fileio.mkdirSync(dpath) + dpath = dpath + '/d' + randomString(248); + fileio.mkdirSync(dpath); } } - expect(null).assertFail() - } catch (e) { - console.log("fileio_test_copy_file_sync_008 has failed for " + e) + expect(null).assertFail(); + } + catch (e) { + console.log('fileio_test_copy_file_sync_008 has failed for ' + e); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_copyFileSync_0900 @@ -1053,62 +2369,85 @@ describe('fileIOTest', function () { * @tc.desc Function of API, filename is too long. */ it('fileio_test_copy_file_sync_009', 0, function () { - let fpath = nextFileName("fileio_test_copy_file_sync_009") - fileio.openSync(fpath, 0o102, 0o777) - let fpathTarget = nextFileName(randomString(256)) + let fpath = nextFileName('fileio_test_copy_file_sync_009'); + fileio.openSync(fpath, 0o102, 0o777); + let fpathTarget = nextFileName(randomString(256)); try { - fileio.copyFileSync(fpath, fpathTarget) - expect(null).assertFail() - } catch (e) { - fileio.unlinkSync(fpath) - console.log("fileio_test_open_sync_008 has failed for " + e) + fileio.copyFileSync(fpath, fpathTarget); + expect(null).assertFail(); + } + catch (e) { + fileio.unlinkSync(fpath); + console.log('fileio_test_open_sync_008 has failed for ' + e); } - }) + }); /** - * @tc.number SUB_STORAGE_FileIO_OpenSync_1000 - * @tc.name fileio_test_open_sync_010 + * @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_open_sync_010', 0, function () { - let fpath = nextFileName("fileio_test_open_sync_010") - fileio.openSync(fpath, 0o102, 0o777) - let dpath = nextFileName("prop") - fileio.mkdirSync(dpath) + it('fileio_test_copy_file_sync_010', 0, function () { + let fpath = nextFileName('fileio_test_copy_file_sync_010'); + fileio.openSync(fpath, 0o102, 0o777); + let dpath = nextFileName('prop'); + fileio.mkdirSync(dpath); try { for (let i = 0; i < 113; i++) { if (i == 112) { - let fpathTarget = dpath + "/f" + i - fileio.copyFileSync(fpath, fpathTarget) + let fpathTarget = dpath + '/f' + i + fileio.copyFileSync(fpath, fpathTarget); } else { - dpath = dpath + "/" + i - fileio.mkdirSync(dpath) + dpath = dpath + '/' + i + fileio.mkdirSync(dpath); } } - expect(null).assertFail() - } catch (e) { - fileio.unlinkSync(fpath) - console.log("fileio_test_open_sync_010 has failed for " + e) + expect(null).assertFail(); + } + catch (e) { + fileio.unlinkSync(fpath); + console.log('fileio_test_copy_file_sync_010 has failed for ' + e); } - }) + }); /** - * @tc.number SUB_STORAGE_FileIO_OpenSync_1100 - * @tc.name fileio_test_open_sync_011 + * @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_open_sync_011', 0, function () { - let fpath = nextFileName("fileio_test_open_sync_011") - fileio.openSync(fpath, 0o102, 0o777) - let fpathTarget = nextFileName("?*:<>/|") + it('fileio_test_copy_file_sync_011', 0, function () { + let fpath = nextFileName('fileio_test_copy_file_sync_011'); + fileio.openSync(fpath, 0o102, 0o777); + let fpathTarget = nextFileName('?*:<>/|'); try { - fileio.copyFileSync(fpath, fpathTarget) - expect(null).assertFail() - } catch (e) { - fileio.unlinkSync(fpath) - console.log("fileio_test_open_sync_011 has failed for " + e) + fileio.copyFileSync(fpath, fpathTarget); + expect(null).assertFail(); + } + catch (e) { + fileio.unlinkSync(fpath); + console.log('fileio_test_copy_file_sync_011 has failed for ' + e); } - }) + }); + + /** + * @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, function () { + let fpath = nextFileName('fileio_test_copy_file_sync_012'); + let fpathTarget = fpath + 'tgt' + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + expect(fileio.copyFileSync(fpath, fpathTarget, 0) !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + expect(fileio.unlinkSync(fpathTarget) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_copy_file_sync_012 has failed for ' + e); + expect(null).assertFail(); + } + }); /** * @tc.number SUB_STORAGE_FileIO_truncateSync_0000 @@ -1116,17 +2455,18 @@ describe('fileIOTest', function () { * @tc.desc Function of API, truncateSync. */ it('fileio_test_truncate_sync_000', 0, function () { - let fpath = nextFileName('fileio_test_truncate_sync_000') - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + let fpath = nextFileName('fileio_test_truncate_sync_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); try { - expect(fileio.truncateSync(fpath) !== null).assertTrue() - expect(fileio.statSync(fpath).size == 0).assertTrue() - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - } catch (e) { - console.log("fileio_test_truncate_sync_000 has failed for " + e) - expect(null).assertFail() + expect(fileio.truncateSync(fpath, 10) !== null).assertTrue(); + expect(fileio.statSync(fpath).size == 10).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_truncate_sync_000 has failed for ' + e); + expect(null).assertFail(); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_truncateSync_0100 @@ -1135,12 +2475,13 @@ describe('fileIOTest', function () { */ it('fileio_test_truncate_sync_001', 0, function () { try { - fileio.truncateSync() - expect(null).assertFail() - } catch (e) { - console.log("fileio_test_truncate_sync_001 has failed for " + e) + fileio.truncateSync(); + expect(null).assertFail(); + } + catch (e) { + console.log('fileio_test_truncate_sync_001 has failed for ' + e); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_truncateSync_0200 @@ -1148,14 +2489,31 @@ describe('fileIOTest', function () { * @tc.desc Function of API, no invaild parameter. */ it('fileio_test_truncate_sync_002', 0, function () { - let fpath = nextFileName('fileio_test_truncate_sync_001') + let fpath = nextFileName('fileio_test_truncate_sync_001'); try { - fileio.truncateSync(fpath) - expect(null).assertFail() - } catch (e) { - console.log("fileio_test_truncate_sync_002 has failed for " + e) + fileio.truncateSync(fpath); + expect(null).assertFail(); + } + catch (e) { + console.log('fileio_test_truncate_sync_002 has failed for ' + e); } - }) + }); + + /** + * @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, function () { + let fpath = nextFileName('fileio_test_truncate_sync_003'); + try { + fileio.truncateSync(fpath, -1); + expect(null).assertFail(); + } + catch (e) { + console.log('fileio_test_truncate_sync_003 has failed for ' + e); + } + }); /** * @tc.number SUB_STORAGE_FileIO_RenameSync_0000 @@ -1163,34 +2521,36 @@ describe('fileIOTest', function () { * @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, function () { - let fpath = nextFileName('fileio_test_rename_sync_000') + let fpath = nextFileName('fileio_test_rename_sync_000'); let fpathTarget = fpath + 'tgt' - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); try { - expect(fileio.renameSync(fpath, fpathTarget) !== null).assertTrue() - expect(fileio.accessSync(fpathTarget) !== null).assertTrue() - expect(fileio.unlinkSync(fpathTarget) !== null).assertTrue() - } catch (e) { - console.log("fileio_test_rename_sync_000 has failed for " + e) - expect(null).assertFail() + expect(fileio.renameSync(fpath, fpathTarget) !== null).assertTrue(); + expect(fileio.accessSync(fpathTarget) !== null).assertTrue(); + expect(fileio.unlinkSync(fpathTarget) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_rename_sync_000 has failed for ' + e); + 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. - */ + * @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, function () { - let fpath = nextFileName('fileio_test_rename_sync_001') + let fpath = nextFileName('fileio_test_rename_sync_001'); let fpathTarget = fpath + 'tgt' try { - fileio.renameSync(fpath, fpathTarget) - expect(null).assertFail() - } catch (e) { - console.log("fileio_test_rename_sync_001 has failed for " + e) + fileio.renameSync(fpath, fpathTarget); + expect(null).assertFail(); + } + catch (e) { + console.log('fileio_test_rename_sync_001 has failed for ' + e); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_RenameSync_0200 @@ -1198,16 +2558,17 @@ describe('fileIOTest', function () { * @tc.desc Function of API, renameSync. The test file is exist, fpathTarget is invaild. */ it('fileio_test_rename_sync_002', 0, function () { - let fpath = nextFileName('fileio_test_rename_sync_002') - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + let fpath = nextFileName('fileio_test_rename_sync_002'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); try { - fileio.renameSync(fpath, "/") - expect(null).assertFail() - } catch (e) { - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - console.log("fileio_test_rename_sync_002 has failed for " + e) + fileio.renameSync(fpath, '/'); + expect(null).assertFail(); + } + catch (e) { + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + console.log('fileio_test_rename_sync_002 has failed for ' + e); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_RenameSync_0300 @@ -1215,17 +2576,18 @@ describe('fileIOTest', function () { * @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, function () { - let fpath = nextFileName('fileio_test_rename_sync_003') - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() - try { - console.log("fileio_test_rename_sync_003 Test start"); - fileio.renameSync(fpath, fpath) - expect(null).assertFail() - } catch (e) { - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - console.log("fileio_test_rename_sync_003 Test finish. " + e); + let fpath = nextFileName('fileio_test_rename_sync_003'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + console.log('fileio_test_rename_sync_003 Test start'); + fileio.renameSync(fpath, fpath); + expect(null).assertFail(); + } + catch (e) { + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + console.log('fileio_test_rename_sync_003 Test finish. ' + e); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_RenameSync_0400 @@ -1234,12 +2596,13 @@ describe('fileIOTest', function () { */ it('fileio_test_rename_sync_004', 0, function () { try { - fileio.renameSync(1, 1) - expect(null).assertNull() - } catch (e) { - console.log("fileio_test_rename_sync_004 pass. " + e); + fileio.renameSync(1, 1); + expect(null).assertFail(); + } + catch (e) { + console.log('fileio_test_rename_sync_004 pass. ' + e); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_RenameSync_0500 @@ -1247,16 +2610,17 @@ describe('fileIOTest', function () { * @tc.desc Function of API, no fpathTarget parameter. */ it('fileio_test_rename_sync_005', 0, function () { - let fpath = nextFileName('fileio_test_rename_sync_005') - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + let fpath = nextFileName('fileio_test_rename_sync_005'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); try { - fileio.renameSync(fpath, 1) - expect(null).assertFail() - } catch (e) { - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - console.log("fileio_test_rename_sync_005 pass. " + e); + fileio.renameSync(fpath, 1); + expect(null).assertFail(); + } + catch (e) { + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + console.log('fileio_test_rename_sync_005 pass. ' + e); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_RenameSync_0600 @@ -1267,15 +2631,16 @@ describe('fileIOTest', function () { let dpath = nextFileName('fileio_test_rename_sync_006') + 'd' let dpathTarget = nextFileName('fileio_test_rename_sync_006-1') + 'd' try { - expect(fileio.mkdirSync(dpath) !== null).assertTrue() - expect(fileio.renameSync(dpath, dpathTarget) == undefined).assertTrue() - expect(fileio.accessSync(dpathTarget) !== null).assertTrue() - expect(fileio.rmdirSync(dpathTarget) !== null).assertTrue() - } catch (e) { - console.log("fileio_test_rename_sync_006 has failed for " + e) - expect(null).assertFail() + expect(fileio.mkdirSync(dpath) !== null).assertTrue(); + expect(fileio.renameSync(dpath, dpathTarget) == undefined).assertTrue(); + expect(fileio.accessSync(dpathTarget) !== null).assertTrue(); + expect(fileio.rmdirSync(dpathTarget) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_rename_sync_006 has failed for ' + e); + expect(null).assertFail(); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_RenameSync_0700 @@ -1286,12 +2651,13 @@ describe('fileIOTest', function () { let dpath = nextFileName('fileio_test_rename_sync_007') + 'd' let dpathTarget = nextFileName('fileio_test_rename_sync_007-1') + 'd' try { - fileio.renameSync(dpath, dpathTarget) - expect(null).assertFail() - } catch (e) { - console.log("fileio_test_rename_sync_007 has failed for " + e) + fileio.renameSync(dpath, dpathTarget); + expect(null).assertFail(); + } + catch (e) { + console.log('fileio_test_rename_sync_007 has failed for ' + e); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_RenameSync_0800 @@ -1302,14 +2668,15 @@ describe('fileIOTest', function () { let dpath = nextFileName('fileio_test_rename_sync_008') + 'd' let dpathTarget = '/data/accounts/account_0/appdata/aaa/bbb/fileio_test_rename_sync_008-1d' try { - expect(fileio.mkdirSync(dpath) !== null).assertTrue() - fileio.renameSync(dpath, dpathTarget) - expect(null).assertFail() - } catch (e) { - expect(fileio.rmdirSync(dpath) !== null).assertTrue() - console.log("fileio_test_rename_sync_008 has failed for " + e) + expect(fileio.mkdirSync(dpath) !== null).assertTrue(); + fileio.renameSync(dpath, dpathTarget); + expect(null).assertFail(); + } + catch (e) { + expect(fileio.rmdirSync(dpath) !== null).assertTrue(); + console.log('fileio_test_rename_sync_008 has failed for ' + e); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_RenameSync_0900 @@ -1319,16 +2686,17 @@ describe('fileIOTest', function () { it('fileio_test_rename_sync_009', 0, function () { let dpath = nextFileName('fileio_test_rename_sync_009') + 'd' try { - expect(fileio.mkdirSync(dpath) !== null).assertTrue() + expect(fileio.mkdirSync(dpath) !== null).assertTrue(); let result = fileio.renameSync(dpath, dpath); - expect(result === undefined).assertTrue() - expect(fileio.accessSync(dpath) !== null).assertTrue() - expect(fileio.rmdirSync(dpath) !== null).assertTrue() - } catch (e) { - console.log("fileio_test_rename_sync_009 has failed for " + e) - expect(null).assertFail() + expect(result === undefined).assertTrue(); + expect(fileio.accessSync(dpath) !== null).assertTrue(); + expect(fileio.rmdirSync(dpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_rename_sync_009 has failed for ' + e); + expect(null).assertFail(); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_FchmodSync_0000 @@ -1336,18 +2704,19 @@ describe('fileIOTest', function () { * @tc.desc Function of API, fchmodSync(mode=0o660). The test file is exist. */ it('fileio_test_fchmod_sync_000', 0, function () { - let fpath = nextFileName('fileio_test_fchmod_sync_000') - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + let fpath = nextFileName('fileio_test_fchmod_sync_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); try { - let fd = fileio.openSync(fpath) - expect(fileio.fchmodSync(fd, 0o660) !== null).assertTrue() - expect((fileio.statSync(fpath).mode & 0o777) == 0o660).assertTrue() - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - } catch (e) { - console.log("fileio_test_fchmod_sync_000 has failed for " + e) - expect(null).assertFail() + let fd = fileio.openSync(fpath); + expect(fileio.fchmodSync(fd, 0o660) !== null).assertTrue(); + expect((fileio.statSync(fpath).mode & 0o777) == 0o660).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_fchmod_sync_000 has failed for ' + e); + expect(null).assertFail(); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_FchmodSync_0100 @@ -1355,18 +2724,19 @@ describe('fileIOTest', function () { * @tc.desc Function of API, fchmodSync(mode=0o460). The test file is exist. */ it('fileio_test_fchmod_sync_001', 0, function () { - let fpath = nextFileName('fileio_test_fchmod_sync_001') - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + let fpath = nextFileName('fileio_test_fchmod_sync_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); try { - let fd = fileio.openSync(fpath) - expect(fileio.fchmodSync(fd, 0o460) !== null).assertTrue() - expect((fileio.statSync(fpath).mode & 0o777) == 0o460).assertTrue() - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - } catch (e) { - console.log("fileio_test_fchmod_sync_001 has failed for " + e) - expect(null).assertFail() + let fd = fileio.openSync(fpath); + expect(fileio.fchmodSync(fd, 0o460) !== null).assertTrue(); + expect((fileio.statSync(fpath).mode & 0o777) == 0o460).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_fchmod_sync_001 has failed for ' + e); + expect(null).assertFail(); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_FchmodSync_0200 @@ -1374,18 +2744,19 @@ describe('fileIOTest', function () { * @tc.desc Function of API, fchmodSync(mode=0o260). The test file is exist. */ it('fileio_test_fchmod_sync_002', 0, function () { - let fpath = nextFileName('fileio_test_fchmod_sync_002') - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + let fpath = nextFileName('fileio_test_fchmod_sync_002'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); try { - let fd = fileio.openSync(fpath) - expect(fileio.fchmodSync(fd, 0o260) !== null).assertTrue() - expect((fileio.statSync(fpath).mode & 0o777) == 0o260).assertTrue() - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - } catch (e) { - console.log("fileio_test_fchmod_sync_002 has failed for " + e) - expect(null).assertFail() + let fd = fileio.openSync(fpath); + expect(fileio.fchmodSync(fd, 0o260) !== null).assertTrue(); + expect((fileio.statSync(fpath).mode & 0o777) == 0o260).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_fchmod_sync_002 has failed for ' + e); + expect(null).assertFail(); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_FchmodSync_0300 @@ -1393,13 +2764,15 @@ describe('fileIOTest', function () { * @tc.desc Function of API, file not exist. The test file is not exist. */ it('fileio_test_fchmod_sync_003', 0, function () { + let fpath = nextFileName('fileio_test_fchmod_sync_003'); try { - expect(fileio.fchmodSync(-1, 0o660) !== null).assertTrue() - expect(null).assertFail() - } catch (e) { - console.log("fileio_test_fchmod_sync_003 has failed for " + e) + expect(fileio.fchmodSync(fpath, 0o660) !== null).assertTrue(); + expect(null).assertFail(); + } + catch (e) { + console.log('fileio_test_fchmod_sync_003 has failed for ' + e); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_FchmodSync_0400 @@ -1407,17 +2780,18 @@ describe('fileIOTest', function () { * @tc.desc Function of API, mode is invaild. The test file is exist. */ it('fileio_test_fchmod_sync_004', 0, function () { - let fpath = nextFileName('fileio_test_fchmod_sync_004') - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + let fpath = nextFileName('fileio_test_fchmod_sync_004'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); try { - let fd = fileio.openSync(fpath) - expect(fileio.fchmodSync(fd, 2222222222222) !== null).assertTrue() - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - } catch (e) { - console.log("fileio_test_fchmod_sync_004 has failed for A" + e) - expect(null).assertFail() + let fd = fileio.openSync(fpath); + expect(fileio.fchmodSync(fd, 2222222222222) !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_fchmod_sync_004 has failed for A' + e); + expect(null).assertFail(); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_FchmodSync_0500 @@ -1427,16 +2801,17 @@ describe('fileIOTest', function () { it('fileio_test_fchmod_sync_005', 0, function () { let dpath = nextFileName('fileio_test_fchmod_sync_005') + 'd' try { - expect(fileio.mkdirSync(dpath, 0o777) !== null).assertTrue() - let fd = fileio.openSync(dpath) + expect(fileio.mkdirSync(dpath, 0o777) !== null).assertTrue(); + let fd = fileio.openSync(dpath); console.log(fd); - expect(fileio.fchmodSync(fd, 0o660) !== null).assertTrue() - expect(fileio.rmdirSync(dpath) !== null).assertTrue() - } catch (e) { - console.log("fileio_test_fchmod_sync_005 has failed for " + e) - expect(null).assertFail() + expect(fileio.fchmodSync(fd, 0o660) !== null).assertTrue(); + expect(fileio.rmdirSync(dpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_fchmod_sync_005 has failed for ' + e); + expect(null).assertFail(); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_FchmodSync_0600 @@ -1444,14 +2819,255 @@ describe('fileIOTest', function () { * @tc.desc Function of API, fpatch = dir. The test dir is not exist. */ it('fileio_test_fchmod_sync_006', 0, function () { - let dpath + let dpath; + try { + fileio.fchmodSync(dpath, 0o660); + expect(null).assertFail(); + } + catch (e) { + console.log('fileio_test_fchmod_sync_006 has failed for ' + e); + } + }); + + /** + * @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, function () { + let fpath = nextFileName('fileio_test_fchmod_sync_007'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let fd = fileio.openSync(fpath); + expect(fileio.fchmodSync(fd, 0o700) !== null).assertTrue(); + expect((fileio.statSync(fpath).mode & 0o777) == 0o700).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_fchmod_sync_007 has failed for ' + e); + 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, function () { + let fpath = nextFileName('fileio_test_fchmod_sync_008'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let fd = fileio.openSync(fpath); + expect(fileio.fchmodSync(fd, 0o400) !== null).assertTrue(); + expect((fileio.statSync(fpath).mode & 0o777) == 0o400).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_fchmod_sync_008 has failed for ' + e); + 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, function () { + let fpath = nextFileName('fileio_test_fchmod_sync_009'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let fd = fileio.openSync(fpath); + expect(fileio.fchmodSync(fd, 0o200) !== null).assertTrue(); + expect((fileio.statSync(fpath).mode & 0o777) == 0o200).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_fchmod_sync_009 has failed for ' + e); + 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, function () { + let fpath = nextFileName('fileio_test_fchmod_sync_010'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let fd = fileio.openSync(fpath); + expect(fileio.fchmodSync(fd, 0o100) !== null).assertTrue(); + expect((fileio.statSync(fpath).mode & 0o777) == 0o100).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_fchmod_sync_010 has failed for ' + e); + 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, function () { + let fpath = nextFileName('fileio_test_fchmod_sync_011'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let fd = fileio.openSync(fpath); + expect(fileio.fchmodSync(fd, 0o070) !== null).assertTrue(); + expect((fileio.statSync(fpath).mode & 0o777) == 0o070).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_fchmod_sync_011 has failed for ' + e); + 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, function () { + let fpath = nextFileName('fileio_test_fchmod_sync_012'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let fd = fileio.openSync(fpath); + expect(fileio.fchmodSync(fd, 0o040) !== null).assertTrue(); + expect((fileio.statSync(fpath).mode & 0o777) == 0o040).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_fchmod_sync_012 has failed for ' + e); + 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, function () { + let fpath = nextFileName('fileio_test_fchmod_sync_013'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let fd = fileio.openSync(fpath); + expect(fileio.fchmodSync(fd, 0o020) !== null).assertTrue(); + expect((fileio.statSync(fpath).mode & 0o777) == 0o020).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_fchmod_sync_013 has failed for ' + e); + 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, function () { + let fpath = nextFileName('fileio_test_fchmod_sync_014'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let fd = fileio.openSync(fpath); + expect(fileio.fchmodSync(fd, 0o010) !== null).assertTrue(); + expect((fileio.statSync(fpath).mode & 0o777) == 0o010).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_fchmod_sync_014 has failed for ' + e); + 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, function () { + let fpath = nextFileName('fileio_test_fchmod_sync_015'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let fd = fileio.openSync(fpath); + expect(fileio.fchmodSync(fd, 0o007) !== null).assertTrue(); + expect((fileio.statSync(fpath).mode & 0o777) == 0o007).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_fchmod_sync_015 has failed for ' + e); + 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, function () { + let fpath = nextFileName('fileio_test_fchmod_sync_016'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let fd = fileio.openSync(fpath); + expect(fileio.fchmodSync(fd, 0o004) !== null).assertTrue(); + expect((fileio.statSync(fpath).mode & 0o777) == 0o004).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_fchmod_sync_016 has failed for ' + e); + 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, function () { + let fpath = nextFileName('fileio_test_fchmod_sync_017'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let fd = fileio.openSync(fpath); + expect(fileio.fchmodSync(fd, 0o002) !== null).assertTrue(); + expect((fileio.statSync(fpath).mode & 0o777) == 0o002).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_fchmod_sync_017 has failed for ' + e); + 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, function () { + let fpath = nextFileName('fileio_test_fchmod_sync_018'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); try { - fileio.fchmodSync(dpath, 0o660) - expect(null).assertNull() - } catch (e) { - console.log("fileio_test_fchmod_sync_006 has failed for " + e) + let fd = fileio.openSync(fpath); + expect(fileio.fchmodSync(fd, 0o001) !== null).assertTrue(); + expect((fileio.statSync(fpath).mode & 0o777) == 0o001).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_fchmod_sync_018 has failed for ' + e); + expect(null).assertFail(); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_FtruncateSync_0000 @@ -1459,18 +3075,19 @@ describe('fileIOTest', function () { * @tc.desc Function of API, ftruncateSync. The test file is exist. */ it('fileio_test_ftruncate_sync_000', 0, function () { - let fpath = nextFileName('fileio_test_ftruncate_sync_000') - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + let fpath = nextFileName('fileio_test_ftruncate_sync_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); try { - let fd = fileio.openSync(fpath, 0o2) - expect(fileio.ftruncateSync(fd) !== null).assertTrue() - expect(fileio.statSync(fpath).size == 0).assertTrue() - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - } catch (e) { - console.log("fileio_test_ftruncate_sync_000 has failed for " + e) - expect(null).assertFail() + let fd = fileio.openSync(fpath, 0o2); + expect(fileio.ftruncateSync(fd, 10) !== null).assertTrue(); + expect(fileio.statSync(fpath).size == 10).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_ftruncate_sync_000 has failed for ' + e); + expect(null).assertFail(); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_FtruncateSync_0100 @@ -1478,18 +3095,19 @@ describe('fileIOTest', function () { * @tc.desc Function of API, len not for value. The test file is exist. */ it('fileio_test_ftruncate_sync_001', 0, function () { - let fpath = nextFileName('fileio_test_ftruncate_sync_001') - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + let fpath = nextFileName('fileio_test_ftruncate_sync_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); try { - let fd = fileio.openSync(fpath, 0o2) - expect(fileio.ftruncateSync(fd) !== null).assertTrue() - expect(fileio.closeSync(fd) !== null).assertTrue() - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - } catch (e) { - console.log("fileio_test_ftruncate_sync_001 has failed for " + e) - expect(null).assertFail() + let fd = fileio.openSync(fpath, 0o2); + expect(fileio.ftruncateSync(fd) !== null).assertTrue(); + expect(fileio.closeSync(fd) !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_ftruncate_sync_001 has failed for ' + e); + expect(null).assertFail(); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_FtruncateSync_0200 @@ -1498,12 +3116,13 @@ describe('fileIOTest', function () { */ it('fileio_test_ftruncate_sync_002', 0, function () { try { - fileio.ftruncateSync(1) - expect(null).assertFail() - } catch (e) { - console.log("fileio_test_ftruncate_sync_002 has failed for " + e) + fileio.ftruncateSync(1); + expect(null).assertFail(); + } + catch (e) { + console.log('fileio_test_ftruncate_sync_002 has failed for ' + e); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_FtruncateSync_0300 @@ -1512,12 +3131,31 @@ describe('fileIOTest', function () { */ it('fileio_test_ftruncate_sync_003', 0, function () { try { - fileio.ftruncateSync(-1) - expect(null).assertFail() - } catch (e) { - console.log("fileio_test_ftruncate_sync_003 has failed for " + e) + fileio.ftruncateSync(-1); + expect(null).assertFail(); + } + catch (e) { + console.log('fileio_test_ftruncate_sync_003 has failed for ' + e); + } + }); + + /** + * @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, function () { + let fpath = nextFileName('fileio_test_ftruncate_sync_004'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let fd = fileio.openSync(fpath, 0o2); + expect(fileio.ftruncateSync(fd, -1) !== null).assertTrue(); + expect(null).assertFail(); + } + catch (e) { + console.log('fileio_test_ftruncate_sync_004 has failed for ' + e); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_FsyncSync_0000 @@ -1525,18 +3163,19 @@ describe('fileIOTest', function () { * @tc.desc Function of API, fsyneSync. */ it('fileio_test_fsync_sync_000', 0, function () { - let fpath = nextFileName('fileio_test_fsync_sync_000') - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + let fpath = nextFileName('fileio_test_fsync_sync_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); try { - let fd = fileio.openSync(fpath, 0o2) - expect(fileio.fsyncSync(fd) !== null).assertTrue() - expect(fileio.closeSync(fd) !== null).assertTrue() - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - } catch (e) { - console.log("fileio_test_fsync_sync_000 has failed for " + e) - expect(null).assertFail() + let fd = fileio.openSync(fpath, 0o2); + expect(fileio.fsyncSync(fd) !== null).assertTrue(); + expect(fileio.closeSync(fd) !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_fsync_sync_000 has failed for ' + e); + expect(null).assertFail(); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_FsyncSync_0100 @@ -1545,12 +3184,13 @@ describe('fileIOTest', function () { */ it('fileio_test_fsync_sync_001', 0, function () { try { - fileio.fsyncSync(1) - expect(null).assertFail() - } catch (e) { - console.log("fileio_test_fsync_sync_001 has failed for " + e) + fileio.fsyncSync(1); + expect(null).assertFail(); + } + catch (e) { + console.log('fileio_test_fsync_sync_001 has failed for ' + e); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_FsyncSync_0200 @@ -1559,12 +3199,13 @@ describe('fileIOTest', function () { */ it('fileio_test_fsync_sync_002', 0, function () { try { - fileio.fsyncSync(-1) - expect(null).assertFail() - } catch (e) { - console.log("fileio_test_fsync_sync_002 has failed for " + e) + fileio.fsyncSync(-1); + expect(null).assertFail(); + } + catch (e) { + console.log('fileio_test_fsync_sync_002 has failed for ' + e); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_MkdirSync_RmdirSync_0000 @@ -1574,13 +3215,14 @@ describe('fileIOTest', function () { it('fileio_test_mkdir_sync_rmdir_sync_000', 0, function () { let dpath = nextFileName('fileio_test_fsync_sync_000') + 'd' try { - expect(fileio.mkdirSync(dpath) !== null).assertTrue() - expect(fileio.rmdirSync(dpath) !== null).assertTrue() - } catch (e) { - console.log("fileio_test_mkdir_sync_rmdir_sync_000 has failed for " + e) - expect(null).assertFail() + expect(fileio.mkdirSync(dpath) !== null).assertTrue(); + expect(fileio.rmdirSync(dpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_mkdir_sync_rmdir_sync_000 has failed for ' + e); + expect(null).assertFail(); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_MkdirSync_RmdirSync_0100 @@ -1590,13 +3232,14 @@ describe('fileIOTest', function () { it('fileio_test_mkdir_sync_rmdir_sync_001', 0, function () { let dpath = nextFileName('fileio_test_mkdir_sync_rmdir_sync_001') + 'd' try { - expect(fileio.mkdirSync(dpath, 0o660) !== null).assertTrue() - expect(fileio.rmdirSync(dpath) !== null).assertTrue() - } catch (e) { - console.log("fileio_test_mkdir_sync_rmdir_sync_001 has failed for " + e) - expect(null).assertFail() + expect(fileio.mkdirSync(dpath, 0o660) !== null).assertTrue(); + expect(fileio.rmdirSync(dpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_mkdir_sync_rmdir_sync_001 has failed for ' + e); + expect(null).assertFail(); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_MkdirSync_RmdirSync_0200 @@ -1606,13 +3249,14 @@ describe('fileIOTest', function () { it('fileio_test_mkdir_sync_rmdir_sync_002', 0, function () { let dpath = nextFileName('fileio_test_mkdir_sync_rmdir_sync_002') + 'd' try { - expect(fileio.mkdirSync(dpath, 0o460) !== null).assertTrue() - expect(fileio.rmdirSync(dpath) !== null).assertTrue() - } catch (e) { - console.log("fileio_test_mkdir_sync_rmdir_sync_002 has failed for " + e) - expect(null).assertFail() + expect(fileio.mkdirSync(dpath, 0o460) !== null).assertTrue(); + expect(fileio.rmdirSync(dpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_mkdir_sync_rmdir_sync_002 has failed for ' + e); + expect(null).assertFail(); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_MkdirSync_RmdirSync_0300 @@ -1622,13 +3266,14 @@ describe('fileIOTest', function () { it('fileio_test_mkdir_sync_rmdir_sync_003', 0, function () { let dpath = nextFileName('fileio_test_mkdir_sync_rmdir_sync_003') + 'd' try { - expect(fileio.mkdirSync(dpath, 0o260) !== null).assertTrue() - expect(fileio.rmdirSync(dpath) !== null).assertTrue() - } catch (e) { - console.log("fileio_test_mkdir_sync_rmdir_sync_003 has failed for " + e) - expect(null).assertFail() + expect(fileio.mkdirSync(dpath, 0o260) !== null).assertTrue(); + expect(fileio.rmdirSync(dpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_mkdir_sync_rmdir_sync_003 has failed for ' + e); + expect(null).assertFail(); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_MkdirSync_RmdirSync_0400 @@ -1637,12 +3282,13 @@ describe('fileIOTest', function () { */ it('fileio_test_mkdir_sync_rmdir_sync_004', 0, function () { try { - expect(fileio.mkdirSync(1) !== null) - expect(null).assertFail() - } catch (e) { - console.log("fileio_test_fsync_sync_004 has failed for " + e) + expect(fileio.mkdirSync(1) !== null); + expect(null).assertFail(); + } + catch (e) { + console.log('fileio_test_fsync_sync_004 has failed for ' + e); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_MkdirSync_RmdirSync_0500 @@ -1651,12 +3297,217 @@ describe('fileIOTest', function () { */ it('fileio_test_mkdir_sync_rmdir_sync_005', 0, function () { try { - expect(fileio.mkdirSync("/", 1) !== null).assertTrue() - expect(null).assertFail() - } catch (e) { - console.log("fileio_test_fsync_sync_005 has failed for " + e) + expect(fileio.mkdirSync('/', 1) !== null).assertTrue(); + expect(null).assertFail(); + } + catch (e) { + console.log('fileio_test_fsync_sync_005 has failed for ' + e); + } + }); + + /** + * @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, function () { + let dpath = nextFileName('fileio_test_mkdir_sync_rmdir_sync_006') + 'd' + try { + expect(fileio.mkdirSync(dpath, 0o700) !== null).assertTrue(); + expect(fileio.rmdirSync(dpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_mkdir_sync_rmdir_sync_006 has failed for ' + e); + 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, function () { + let dpath = nextFileName('fileio_test_mkdir_sync_rmdir_sync_007') + 'd' + try { + expect(fileio.mkdirSync(dpath, 0o400) !== null).assertTrue(); + expect(fileio.rmdirSync(dpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_mkdir_sync_rmdir_sync_007 has failed for ' + e); + 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, function () { + let dpath = nextFileName('fileio_test_mkdir_sync_rmdir_sync_008') + 'd' + try { + expect(fileio.mkdirSync(dpath, 0o200) !== null).assertTrue(); + expect(fileio.rmdirSync(dpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_mkdir_sync_rmdir_sync_008 has failed for ' + e); + 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, function () { + let dpath = nextFileName('fileio_test_mkdir_sync_rmdir_sync_009') + 'd' + try { + expect(fileio.mkdirSync(dpath, 0o100) !== null).assertTrue(); + expect(fileio.rmdirSync(dpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_mkdir_sync_rmdir_sync_009 has failed for ' + e); + 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, function () { + let dpath = nextFileName('fileio_test_mkdir_sync_rmdir_sync_010') + 'd'; + try { + expect(fileio.mkdirSync(dpath, 0o070) !== null).assertTrue(); + expect(fileio.rmdirSync(dpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_mkdir_sync_rmdir_sync_010 has failed for ' + e); + 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, function () { + let dpath = nextFileName('fileio_test_mkdir_sync_rmdir_sync_011') + 'd'; + try { + expect(fileio.mkdirSync(dpath, 0o040) !== null).assertTrue(); + expect(fileio.rmdirSync(dpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_mkdir_sync_rmdir_sync_011 has failed for ' + e); + 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, function () { + let dpath = nextFileName('fileio_test_mkdir_sync_rmdir_sync_012') + 'd'; + try { + expect(fileio.mkdirSync(dpath, 0o020) !== null).assertTrue(); + expect(fileio.rmdirSync(dpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_mkdir_sync_rmdir_sync_012 has failed for ' + e); + 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, function () { + let dpath = nextFileName('fileio_test_mkdir_sync_rmdir_sync_013') + 'd'; + try { + expect(fileio.mkdirSync(dpath, 0o010) !== null).assertTrue(); + expect(fileio.rmdirSync(dpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_mkdir_sync_rmdir_sync_013 has failed for ' + e); + 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, function () { + let dpath = nextFileName('fileio_test_mkdir_sync_rmdir_sync_014') + 'd'; + try { + expect(fileio.mkdirSync(dpath, 0o007) !== null).assertTrue(); + expect(fileio.rmdirSync(dpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_mkdir_sync_rmdir_sync_014 has failed for ' + e); + 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, function () { + let dpath = nextFileName('fileio_test_mkdir_sync_rmdir_sync_015') + 'd'; + try { + expect(fileio.mkdirSync(dpath, 0o004) !== null).assertTrue(); + expect(fileio.rmdirSync(dpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_mkdir_sync_rmdir_sync_015 has failed for ' + e); + 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, function () { + let dpath = nextFileName('fileio_test_mkdir_sync_rmdir_sync_016') + 'd'; + try { + expect(fileio.mkdirSync(dpath, 0o002) !== null).assertTrue(); + expect(fileio.rmdirSync(dpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_mkdir_sync_rmdir_sync_016 has failed for ' + e); + 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, function () { + let dpath = nextFileName('fileio_test_mkdir_sync_rmdir_sync_017') + 'd'; + try { + expect(fileio.mkdirSync(dpath, 0o001) !== null).assertTrue(); + expect(fileio.rmdirSync(dpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_mkdir_sync_rmdir_sync_017 has failed for ' + e); + expect(null).assertFail(); + } + }); /** * @tc.number SUB_STORAGE_FileIO_FstatSync_0000 @@ -1664,19 +3515,20 @@ describe('fileIOTest', function () { * @tc.desc Function of API, fstatSync. The test file is exist. */ it('fileio_test_fstat_sync_000', 0, function () { - let fpath = nextFileName('fileio_test_fstat_sync_000') - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + let fpath = 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() - expect(fileio.closeSync(fd) !== null).assertTrue() - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - } catch (e) { - console.log("fileio_test_fstat_sync_000 has failed for " + e) - expect(null).assertFail() + let fd = fileio.openSync(fpath, 0o2); + let stat = fileio.fstatSync(fd); + expect(stat !== null).assertTrue(); + expect(fileio.closeSync(fd) !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_fstat_sync_000 has failed for ' + e); + expect(null).assertFail(); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_FstatSync_0100 @@ -1685,12 +3537,13 @@ describe('fileIOTest', function () { */ it('fileio_test_fstat_sync_001', 0, function () { try { - expect(fileio.fstatSync(1) !== null).assertTrue() - expect(null).assertFail() - } catch (e) { - console.log("fileio_test_fstat_sync_001 has failed for " + e) + expect(fileio.fstatSync(1) !== null).assertTrue(); + expect(null).assertFail(); + } + catch (e) { + console.log('fileio_test_fstat_sync_001 has failed for ' + e); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_FstatSync_0200 @@ -1699,12 +3552,13 @@ describe('fileIOTest', function () { */ it('fileio_test_fstat_sync_002', 0, function () { try { - expect(fileio.fstatSync(1) !== null).assertTrue() - expect(null).assertFail() - } catch (e) { - console.log("fileio_test_fstat_sync_002 has failed for " + e) + expect(fileio.fstatSync(1) !== null).assertTrue(); + expect(null).assertFail(); + } + catch (e) { + console.log('fileio_test_fstat_sync_002 has failed for ' + e); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_FstatSync_0300 @@ -1714,18 +3568,19 @@ describe('fileIOTest', function () { it('fileio_test_fstat_sync_003', 0, function () { let dpath = nextFileName('fileio_test_fstat_sync_003') + 'd' try { - expect(fileio.mkdirSync(dpath) !== null).assertTrue() - let fd = fileio.openSync(dpath) - expect(fd !== null).assertTrue() - let stat = fileio.fstatSync(fd) - expect(stat !== null).assertTrue() - expect(fileio.closeSync(fd) !== null).assertTrue() - expect(fileio.rmdirSync(dpath) !== null).assertTrue() - } catch (e) { - console.log("fileio_test_fstat_sync_003 has failed for " + e) - expect(null).assertFail() + expect(fileio.mkdirSync(dpath) !== null).assertTrue(); + let fd = fileio.openSync(dpath); + expect(fd !== null).assertTrue(); + let stat = fileio.fstatSync(fd); + expect(stat !== null).assertTrue(); + expect(fileio.closeSync(fd) !== null).assertTrue(); + expect(fileio.rmdirSync(dpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_fstat_sync_003 has failed for ' + e); + expect(null).assertFail(); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_ChownSync_0000 @@ -1733,19 +3588,20 @@ describe('fileIOTest', function () { * @tc.desc Function of API, chownSync. The test file is exist. */ it('fileio_test_chown_sync_000', 0, function () { - let fpath = nextFileName('fileio_test_chown_sync_000') - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() - let stat = fileio.statSync(fpath) + let fpath = 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() - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - } catch (e) { - console.log("fileio_test_chown_sync_000 has failed for " + e) - expect(null).assertFail() + expect(fileio.chownSync(fpath, UID, GID) !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_chown_sync_000 has failed for ' + e); + expect(null).assertFail(); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_ChownSync_0100 @@ -1753,20 +3609,21 @@ describe('fileIOTest', function () { * @tc.desc Function of API, chownSync. The test file is not exist. */ it('fileio_test_chown_sync_001', 0, function () { - let fpath = nextFileName('fileio_test_chown_sync_001') - let fpath_1 = nextFileName('fileio_test_chown_sync_001_1') - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() - let stat = fileio.statSync(fpath) + let fpath = nextFileName('fileio_test_chown_sync_001'); + let fpathc = 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(fpath_1, UID, GID)) - expect(null).assertFail() - } catch (e) { - console.log("fileio_test_chown_sync_001 has failed for " + e) - expect(fileio.unlinkSync(fpath) !== null).assertTrue() + expect(fileio.chownSync(fpathc, UID, GID)); + expect(null).assertFail(); + } + catch (e) { + console.log('fileio_test_chown_sync_001 has failed for ' + e); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_ChownSync_0200 @@ -1774,16 +3631,17 @@ describe('fileIOTest', function () { * @tc.desc Function of API, invaild fd. The test file is not exist. */ it('fileio_test_chown_sync_002', 0, function () { - let fpath = nextFileName('fileio_test_chown_sync_002') - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() - try { - expect(fileio.chownSync(fpath, 0, 0)) - expect(null).assertFail() - } catch (e) { - console.log("fileio_test_chown_sync_002 has failed for " + e) - expect(fileio.unlinkSync(fpath) !== null).assertTrue() + let fpath = nextFileName('fileio_test_chown_sync_002'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + expect(fileio.chownSync(fpath, 0, 0)); + expect(null).assertFail(); + } + catch (e) { + console.log('fileio_test_chown_sync_002 has failed for ' + e); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_FchownSync_0000 @@ -1791,21 +3649,22 @@ describe('fileIOTest', function () { * @tc.desc Function of API, fchownSync. The test file is exist. */ it('fileio_test_fchown_sync_000', 0, function () { - let fpath = nextFileName('fileio_test_fchown_sync_000') - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() - let stat = fileio.statSync(fpath) + let fpath = 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() - expect(fileio.closeSync(fd) !== null).assertTrue() - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - } catch (e) { - console.log("fileio_test_fchown_sync_000 has failed for " + e) - expect(null).assertFail() + let fd = fileio.openSync(fpath); + expect(fileio.fchownSync(fd, UID, GID) !== null).assertTrue(); + expect(fileio.closeSync(fd) !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_fchown_sync_000 has failed for ' + e); + expect(null).assertFail(); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_FchownSync_0100 @@ -1813,19 +3672,21 @@ describe('fileIOTest', function () { * @tc.desc Function of API, fchownSync. The test file is not exist. */ it('fileio_test_fchown_sync_001', 0, function () { - let fpath = nextFileName('fileio_test_fchown_sync_001') - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() - let stat = fileio.statSync(fpath) + let fpath = 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)) - expect(null).assertFail() - } catch (e) { - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - console.log("fileio_test_fchown_sync_001 has failed for " + e) + expect(fileio.fchownSync(-1, UID, GID)); + expect(null).assertFail(); + } + catch (e) { + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + console.log('fileio_test_fchown_sync_001 has failed for ' + e); } - }) + + }); /** * @tc.number SUB_STORAGE_FileIO_FchownSync_0200 @@ -1833,20 +3694,21 @@ describe('fileIOTest', function () { * @tc.desc Function of API, fchownSync, wrong owner. The test file is exist. */ it('fileio_test_fchown_sync_002', 0, function () { - let fpath = nextFileName('fileio_test_fchown_sync_002') - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() - let stat = fileio.statSync(fpath) + let fpath = 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, cc, GID) - expect(null).assertFail() - } catch (e) { - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - console.log("fileio_test_fchown_sync_002 has failed for " + e) + let fd = fileio.openSync(fpath); + fileio.fchownSync(fd, cc, GID); + expect(null).assertFail(); + } + catch (e) { + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + console.log('fileio_test_fchown_sync_002 has failed for ' + e); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_FchownSync_0300 @@ -1854,21 +3716,22 @@ describe('fileIOTest', function () { * @tc.desc Function of API, fchownSync, wrong group. The test file is exist. */ it('fileio_test_fchown_sync_003', 0, function () { - let fpath = nextFileName('fileio_test_fchown_sync_003') - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() - let stat = fileio.statSync(fpath) + let fpath = 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)) - expect(null).assertFail() - } catch (e) { - expect(fileio.closeSync(fd) !== null).assertTrue() - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - console.log("fileio_test_fchown_sync_003 has failed for " + e) + fd = fileio.openSync(fpath, 0o2); + expect(fileio.fchownSync(fd, UID, 0)); + expect(null).assertFail(); + } + catch (e) { + expect(fileio.closeSync(fd) !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + console.log('fileio_test_fchown_sync_003 has failed for ' + e); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_FchownSync_0400 @@ -1876,20 +3739,23 @@ describe('fileIOTest', function () { * @tc.desc Function of API, fchownSync, no value of fd. The test file is exist. */ it('fileio_test_fchown_sync_004', 0, function () { - let fpath = nextFileName('fileio_test_fchown_sync_004') - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() - let stat = fileio.statSync(fpath) + let fpath = 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)) - expect(null).assertFail() - } catch (e) { - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - console.log("fileio_test_fchown_sync_004 has failed for " + e) + expect(fileio.fchownSync(fd, UID, GID)); + expect(null).assertFail(); + + } + catch (e) { + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + console.log('fileio_test_fchown_sync_004 has failed for ' + e); } - }) + + }); /** * @tc.number SUB_STORAGE_FileIO_FchownSync_0500 @@ -1897,22 +3763,23 @@ describe('fileIOTest', function () { * @tc.desc Function of API, fchownSync, no value of owner. The test file is exist. */ it('fileio_test_fchown_sync_005', 0, function () { - let fpath = nextFileName('fileio_test_fchown_sync_005') - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() - let stat = fileio.statSync(fpath) + let fpath = 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)) - expect(null).assertFail() - } catch (e) { - expect(fileio.closeSync(fd) !== null).assertTrue() - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - console.log("fileio_test_fchown_sync_005 has failed for " + e) + fd = fileio.openSync(fpath); + expect(fileio.fchownSync(fd, UID, GID)); + expect(null).assertFail(); + } + catch (e) { + expect(fileio.closeSync(fd) !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + console.log('fileio_test_fchown_sync_005 has failed for ' + e); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_FchownSync_0600 @@ -1920,22 +3787,23 @@ describe('fileIOTest', function () { * @tc.desc Function of API, fchownSync, no value of group. The test file is exist. */ it('fileio_test_fchown_sync_006', 0, function () { - let fpath = nextFileName('fileio_test_fchown_sync_006') - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() - let stat = fileio.statSync(fpath) + let fpath = nextFileName('fileio_test_fchown_sync_006'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let stat = fileio.statSync(fpath); let UID = stat.uid let GID = null let fd; try { - fd = fileio.openSync(fpath) - expect(fileio.fchownSync(fd, UID, GID)) - expect(null).assertFail() - } catch (e) { - expect(fileio.closeSync(fd) !== null).assertTrue() - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - console.log("fileio_test_fchown_sync_006 has failed for " + e) + fd = fileio.openSync(fpath); + expect(fileio.fchownSync(fd, UID, GID)); + expect(null).assertFail(); + } + catch (e) { + expect(fileio.closeSync(fd) !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + console.log('fileio_test_fchown_sync_006 has failed for ' + e); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_FchownSync_0700 @@ -1943,21 +3811,22 @@ describe('fileIOTest', function () { * @tc.desc Function of API, fchownSync, no value of GID,UID. The test file is exist. */ it('fileio_test_fchown_sync_007', 0, function () { - let fpath = nextFileName('fileio_test_fchown_sync_007') - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + let fpath = nextFileName('fileio_test_fchown_sync_007'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); let fd; let UID = null let GID = null try { - fd = fileio.openSync(fpath, 0o2) - expect(fileio.fchownSync(fd, UID, GID)) - expect(null).assertFail() - } catch (e) { - expect(fileio.closeSync(fd) !== null).assertTrue() - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - console.log("fileio_test_fchown_sync_007 has failed for " + e) + fd = fileio.openSync(fpath, 0o2); + expect(fileio.fchownSync(fd, UID, GID)); + expect(null).assertFail(); + } + catch (e) { + expect(fileio.closeSync(fd) !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + console.log('fileio_test_fchown_sync_007 has failed for ' + e); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_prop_write_open_read_4k_sync @@ -1965,22 +3834,23 @@ describe('fileIOTest', function () { * @tc.desc Sync to write & open & read 4K file. */ it('fileio_test_prop_write_open_read_4k_sync', 0, function () { - let fpath = 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() - expect(fileio.closeSync(fd) !== null).assertTrue() - let fd1 = fileio.openSync(fpath, 0o2) - let rlen = fileio.readSync(fd1, new ArrayBuffer(4096)) - expect(rlen == 4096).assertTrue() - expect(fileio.closeSync(fd1) !== null).assertTrue() - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - } catch (e) { - console.log("fileio_test_prop_write_open_read_4k_sync has failed for " + e) - expect(null).assertFail() + let fpath = 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(); + expect(fileio.closeSync(fd) !== null).assertTrue(); + let fd1 = fileio.openSync(fpath, 0o2); + let rlen = fileio.readSync(fd1, new ArrayBuffer(4096)); + expect(rlen == 4096).assertTrue(); + expect(fileio.closeSync(fd1) !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_prop_write_open_read_4k_sync has failed for ' + e); + expect(null).assertFail(); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_prop_write_open_read_4k_sync @@ -1988,19 +3858,20 @@ describe('fileIOTest', function () { * @tc.desc Sync to copy 4K file. */ it('fileio_test_prop_copyFile_4k_sync', 0, function () { - let fpath = nextFileName('fileio_test_prop_copyFile_4k_sync') - let fpath1 = 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() - expect(fileio.closeSync(fd) !== null).assertTrue() - expect(fileio.copyFileSync(fpath, fpath1) !== null).assertTrue() - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - expect(fileio.unlinkSync(fpath1) !== null).assertTrue() - } catch (e) { - console.log("fileio_test_prop_copyFile_4k_sync has failed for " + e) - expect(null).assertFail() - } - }) -}) \ No newline at end of file + let fpath = nextFileName('fileio_test_prop_copyFile_4k_sync'); + let fpath1 = 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(); + expect(fileio.closeSync(fd) !== null).assertTrue(); + expect(fileio.copyFileSync(fpath, fpath1) !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + expect(fileio.unlinkSync(fpath1) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_prop_copyFile_4k_sync has failed for ' + e); + expect(null).assertFail(); + } + }); +}); \ No newline at end of file diff --git a/storage/storagefileiojstest/project/entry/src/main/js/test/FileIODir.test.js b/storage/storagefileiojstest/project/entry/src/main/js/test/FileIODir.test.js index d0e35899113dad577ab6fcb4bbc5f8f3c183725a..5b0300240181d5f98f663d66e68828019aaa8e66 100644 --- a/storage/storagefileiojstest/project/entry/src/main/js/test/FileIODir.test.js +++ b/storage/storagefileiojstest/project/entry/src/main/js/test/FileIODir.test.js @@ -1,21 +1,32 @@ /* * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); + * Licensed under the Apache License, Version 2.0 (the 'License'); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, + * distributed under the License is distributed on an 'AS IS' BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import fileio from '@ohos.fileio'; -import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index' -import { FILE_CONTENT, prepareFile, nextFileName, prepareFile1, randomString } from './Common' +import { + describe, + it, + expect +} + from 'deccjsunit/index' +import { + FILE_CONTENT, + prepareFile, + nextFileName, + randomString +} + from './Common' describe('fileIOTestDir', function () { @@ -27,16 +38,17 @@ describe('fileIOTestDir', function () { it('fileio_test_dir_open_sync_000', 0, function () { let dpath = nextFileName('fileio_test_dir_open_sync_000') + 'd' try { - expect(fileio.mkdirSync(dpath) !== null).assertTrue() - let dd = fileio.opendirSync(dpath) - expect(dd !== null).assertTrue() - expect(dd.closeSync() == null).assertTrue() - expect(fileio.rmdirSync(dpath) !== null).assertTrue() - } catch (e) { - console.log("fileio_test_dir_open_sync_000 has failed for " + e) - expect(null).assertFail() + expect(fileio.mkdirSync(dpath) !== null).assertTrue(); + let dd = fileio.opendirSync(dpath); + expect(dd !== null).assertTrue(); + expect(dd.closeSync() == null).assertTrue(); + expect(fileio.rmdirSync(dpath) !== null).assertTrue(); } - }) + catch (e) { + console.log('fileio_test_dir_open_sync_000 has failed for ' + e); + expect(null).assertFail(); + } + }); /** * @tc.number SUB_STORAGE_FileIO_dir_OpenSync_0100 @@ -45,12 +57,13 @@ describe('fileIOTestDir', function () { */ it('fileio_test_dir_open_sync_001', 0, function () { try { - fileio.opendirSync() - expect(null).assertFail() - } catch (e) { - console.log("fileio_test_dir_open_sync_001 has failed for " + e) + fileio.opendirSync(); + expect(null).assertFail(); + } + catch (e) { + console.log('fileio_test_dir_open_sync_001 has failed for ' + e); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_dir_OpenSync_0200 @@ -60,12 +73,13 @@ describe('fileIOTestDir', function () { it('fileio_test_dir_open_sync_002', 0, function () { let dpath = nextFileName('fileio_test_dir_open_sync_003') + 'd' try { - fileio.opendirSync(dpath) - expect(null).assertFail() - } catch (e) { - console.log("fileio_test_dir_open_sync_002 has failed for " + e) + fileio.opendirSync(dpath); + expect(null).assertFail(); + } + catch (e) { + console.log('fileio_test_dir_open_sync_002 has failed for ' + e); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_dir_OpenSync_0300 @@ -73,19 +87,20 @@ describe('fileIOTestDir', function () { * @tc.desc Function of API, dpath too long. */ it('fileio_test_dir_open_sync_003', 0, function () { - let dpath = nextFileName("fileio_dir11") - fileio.mkdirSync(dpath) + let dpath = nextFileName('fileio_dir11'); + fileio.mkdirSync(dpath); try { for (let i = 0; i < 16; i++) { - console.log("time" + i) - dpath = dpath + "/f" + randomString(248) - fileio.mkdirSync(dpath) + console.log('time' + i); + dpath = dpath + '/f' + randomString(248); + fileio.mkdirSync(dpath); } - expect(null).assertFail() - } catch (e) { - console.log("fileio_test_dir_open_sync_003 has failed for " + e) + expect(null).assertFail(); } - }) + catch (e) { + console.log('fileio_test_dir_open_sync_003 has failed for ' + e); + } + }); /** * @tc.number SUB_STORAGE_FileIO_dir_OpenSync_0400 @@ -93,14 +108,15 @@ describe('fileIOTestDir', function () { * @tc.desc Function of API, filename too long. */ it('fileio_test_dir_open_sync_004', 0, function () { - let dpath = nextFileName(randomString(256)) + let dpath = nextFileName(randomString(256)); try { - fileio.mkdirSync(dpath) - expect(null).assertFail() - } catch (e) { - console.log("fileio_test_dir_open_sync_004 has failed for " + e) + fileio.mkdirSync(dpath); + expect(null).assertFail(); + } + catch (e) { + console.log('fileio_test_dir_open_sync_004 has failed for ' + e); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_dir_OpenSync_0500 @@ -108,19 +124,20 @@ describe('fileIOTestDir', function () { * @tc.desc Function of API, uri dir too many layers. */ it('fileio_test_dir_open_sync_005', 0, function () { - let dpath = nextFileName("dir") - fileio.mkdirSync(dpath) + let dpath = nextFileName('dir'); + fileio.mkdirSync(dpath); try { for (let i = 0; i < 1024; i++) { - console.log("time" + i) - dpath = dpath + "/" + i - fileio.mkdirSync(dpath) + console.log('time' + i); + dpath = dpath + '/' + i + fileio.mkdirSync(dpath); } - expect(null).assertFail() - } catch (e) { - console.log("fileio_test_dir_open_sync_005 has failed for " + e) + expect(null).assertFail(); } - }) + catch (e) { + console.log('fileio_test_dir_open_sync_005 has failed for ' + e); + } + }); /** * @tc.number SUB_STORAGE_FileIO_dir_OpenSync_0600 @@ -128,14 +145,15 @@ describe('fileIOTestDir', function () { * @tc.desc Function of API, file name contain special character. */ it('fileio_test_dir_open_sync_006', 0, function () { - let dpath = nextFileName("?*:<>/|") + let dpath = nextFileName('?*:<>/|'); try { - fileio.mkdirSync(dpath) - expect(null).assertFail() - } catch (e) { - console.log("fileio_test_dir_open_sync_006 has failed for " + e) + fileio.mkdirSync(dpath); + expect(null).assertFail(); + } + catch (e) { + console.log('fileio_test_dir_open_sync_006 has failed for ' + e); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_dir_ReadSync_0000 @@ -146,19 +164,20 @@ describe('fileIOTestDir', function () { let dpath = nextFileName('fileio_test_dir_read_sync_000') + 'd' let fpath = dpath + '/f0' try { - expect(typeof (fileio.mkdirSync(dpath)) == "undefined").assertTrue() - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() - let dd = fileio.opendirSync(dpath) - expect(dd !== null).assertTrue() - expect(dd.readSync() !== null).assertTrue() - expect(dd.closeSync() == null).assertTrue() - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - expect(fileio.rmdirSync(dpath) !== null).assertTrue() - } catch (e) { - console.log("fileio_test_dir_read_sync_000 has failed for " + e) - expect(null).assertFail() + expect(typeof(fileio.mkdirSync(dpath)) == 'undefined').assertTrue(); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let dd = fileio.opendirSync(dpath); + expect(dd !== null).assertTrue(); + expect(dd.readSync() !== null).assertTrue(); + expect(dd.closeSync() == null).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + expect(fileio.rmdirSync(dpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_dir_read_sync_000 has failed for ' + e); + expect(null).assertFail(); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_dir_ReadSync_0100 @@ -167,41 +186,42 @@ describe('fileIOTestDir', function () { */ it('fileio_test_dir_read_sync_001', 0, function () { let dpath = nextFileName('fileio_test_dir_read_sync_001') + 'd' - let fpathArray = new Array(dpath + '/f1', dpath + '/f2', dpath + '/d3') + let fpathArray = new Array(dpath + '/f1', dpath + '/f2', dpath + '/d3'); try { - expect(fileio.mkdirSync(dpath) !== null).assertTrue() + expect(fileio.mkdirSync(dpath) !== null).assertTrue(); for (let i = 0; i < 3; i++) { if (i == 2) { - expect(fileio.mkdirSync(fpathArray[i]) !== null).assertTrue() + expect(fileio.mkdirSync(fpathArray[i]) !== null).assertTrue(); } else { - expect(prepareFile(fpathArray[i], FILE_CONTENT)).assertTrue() + expect(prepareFile(fpathArray[i], FILE_CONTENT)).assertTrue(); } } - let dd = fileio.opendirSync(dpath) - expect(dd !== null).assertTrue() + let dd = fileio.opendirSync(dpath); + expect(dd !== null).assertTrue(); for (let i = 0; i < 3; i++) { if (i == 2) { - let bool = typeof (dd.readSync()) - expect(bool == "object").assertTrue() - console.log("---bool=" + bool) + let bool = typeof(dd.readSync()); + expect(bool == 'object').assertTrue(); + console.log('---bool=' + bool); } else { - expect(dd.readSync() !== null).assertTrue() + expect(dd.readSync() !== null).assertTrue(); } } - expect(dd.closeSync() == null).assertTrue() + expect(dd.closeSync() == null).assertTrue(); for (let i = 0; i < 3; i++) { if (i == 2) { - expect(fileio.rmdirSync(fpathArray[i]) !== null).assertTrue() + expect(fileio.rmdirSync(fpathArray[i]) !== null).assertTrue(); } else { - expect(fileio.unlinkSync(fpathArray[i]) !== null).assertTrue() + expect(fileio.unlinkSync(fpathArray[i]) !== null).assertTrue(); } } - expect(fileio.rmdirSync(dpath) !== null).assertTrue() - } catch (e) { - console.log("fileio_test_dir_read_sync_001 has failed for " + e) - expect(null).assertFail() + expect(fileio.rmdirSync(dpath) !== null).assertTrue(); } - }) + catch (e) { + console.log('fileio_test_dir_read_sync_001 has failed for ' + e); + expect(null).assertFail(); + } + }); /** * @tc.number SUB_STORAGE_FileIO_dir_ReadSync_0200 @@ -210,36 +230,37 @@ describe('fileIOTestDir', function () { */ it('fileio_test_dir_read_sync_002', 0, function () { let dpath = nextFileName('fileio_test_dir_read_sync_002') + 'd' - let fpathArray = new Array(dpath + '/f1', dpath + '/f2', dpath + '/d3') + let fpathArray = new Array(dpath + '/f1', dpath + '/f2', dpath + '/d3'); try { - expect(fileio.mkdirSync(dpath) !== null).assertTrue() + expect(fileio.mkdirSync(dpath) !== null).assertTrue(); for (let i = 0; i < 3; i++) { if (i == 2) { - expect(fileio.mkdirSync(fpathArray[i]) !== null).assertTrue() + expect(fileio.mkdirSync(fpathArray[i]) !== null).assertTrue(); } else { - expect(prepareFile(fpathArray[i], FILE_CONTENT)).assertTrue() + expect(prepareFile(fpathArray[i], FILE_CONTENT)).assertTrue(); } } - var dd = fileio.opendirSync(dpath) - expect(dd !== null).assertTrue() + var dd = fileio.opendirSync(dpath); + expect(dd !== null).assertTrue(); for (let i = 0; i < 3; i++) { - expect(dd.readSync() !== null).assertTrue() + expect(dd.readSync() !== null).assertTrue(); } - expect(dd.readSync() == null).assertTrue() - expect(null).assertFail() - } catch (e) { - console.log("fileio_test_dir_read_sync_002 has failed for " + e) - expect(dd.closeSync() == null).assertTrue() + expect(dd.readSync() == null).assertTrue(); + expect(null).assertFail(); + } + catch (e) { + console.log('fileio_test_dir_read_sync_002 has failed for ' + e); + expect(dd.closeSync() == null).assertTrue(); for (let i = 0; i < 3; i++) { if (i == 2) { - expect(fileio.rmdirSync(fpathArray[i]) !== null).assertTrue() + expect(fileio.rmdirSync(fpathArray[i]) !== null).assertTrue(); } else { - expect(fileio.unlinkSync(fpathArray[i]) !== null).assertTrue() + expect(fileio.unlinkSync(fpathArray[i]) !== null).assertTrue(); } } - expect(fileio.rmdirSync(dpath) !== null).assertTrue() - } - }) + expect(fileio.rmdirSync(dpath) !== null).assertTrue(); + } + }); /** * @tc.number SUB_STORAGE_FileIO_dir_ReadSync_0300 @@ -250,17 +271,18 @@ describe('fileIOTestDir', function () { let dpath = nextFileName('fileio_test_dir_read_sync_003') + 'd' let dd; try { - expect(fileio.mkdirSync(dpath) !== null).assertTrue() - dd = fileio.opendirSync(dpath) - expect(dd !== null).assertTrue() - expect(dd.readSync() == null).assertTrue() - expect(null).assertFail() - } catch (e) { - expect(dd.closeSync() == null).assertTrue() - expect(fileio.rmdirSync(dpath) !== null).assertTrue() - console.log("fileio_test_dir_read_sync_003 has failed for " + e) + expect(fileio.mkdirSync(dpath) !== null).assertTrue(); + dd = fileio.opendirSync(dpath); + expect(dd !== null).assertTrue(); + expect(dd.readSync() == null).assertTrue(); + expect(null).assertFail(); + } + catch (e) { + expect(dd.closeSync() == null).assertTrue(); + expect(fileio.rmdirSync(dpath) !== null).assertTrue(); + console.log('fileio_test_dir_read_sync_003 has failed for ' + e); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_dir_ReadSync_0400 @@ -272,19 +294,20 @@ describe('fileIOTestDir', function () { let fpath = dpath + '/f1' let dd try { - expect(fileio.mkdirSync(dpath) !== null).assertTrue() - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() - dd = fileio.opendirSync(dpath) - expect(dd !== null).assertTrue() - expect(dd.readSync(-1) == null).assertTrue() - expect(null).assertFail() - } catch (e) { - expect(dd.closeSync() == null).assertTrue() - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - expect(fileio.rmdirSync(dpath) !== null).assertTrue() - console.log("fileio_test_dir_read_sync_004 has failed for " + e) + expect(fileio.mkdirSync(dpath) !== null).assertTrue(); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + dd = fileio.opendirSync(dpath); + expect(dd !== null).assertTrue(); + expect(dd.readSync(-1) == null).assertTrue(); + expect(null).assertFail(); } - }) + catch (e) { + expect(dd.closeSync() == null).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + expect(fileio.rmdirSync(dpath) !== null).assertTrue(); + console.log('fileio_test_dir_read_sync_004 has failed for ' + e); + } + }); /** * @tc.number SUB_STORAGE_FileIO_dir_ReadSync_0500 @@ -295,23 +318,24 @@ describe('fileIOTestDir', function () { let dpath = nextFileName('fileio_test_dir_read_sync_005') + 'd' let fpath = dpath + '/f' try { - expect(typeof (fileio.mkdirSync(dpath)) == "undefined").assertTrue() + expect(typeof(fileio.mkdirSync(dpath)) == 'undefined').assertTrue(); for (let i = 0; i < 10001; i++) { - expect(prepareFile(fpath + i, "test_text")).assertTrue() + expect(prepareFile(fpath + i, 'test_text')).assertTrue(); } - let dd = fileio.opendirSync(dpath) - expect(dd !== null).assertTrue() - expect(dd.readSync() !== null).assertTrue() - expect(dd.closeSync() == null).assertTrue() + let dd = fileio.opendirSync(dpath); + expect(dd !== null).assertTrue(); + expect(dd.readSync() !== null).assertTrue(); + expect(dd.closeSync() == null).assertTrue(); for (let i = 0; i < 10001; i++) { - fileio.unlinkSync(fpath + i) + fileio.unlinkSync(fpath + i); } - expect(fileio.rmdirSync(dpath) !== null).assertTrue() - } catch (e) { - console.log("fileio_test_dir_read_sync_005 has failed for " + e) - expect(null).assertFail() + expect(fileio.rmdirSync(dpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_dir_read_sync_005 has failed for ' + e); + expect(null).assertFail(); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_dir_CloseSync_0000 @@ -321,14 +345,15 @@ describe('fileIOTestDir', function () { it('fileio_test_dir_close_sync_000', 0, function () { let dpath = nextFileName('fileio_test_dir_close_sync_000') + 'd' try { - expect(fileio.mkdirSync(dpath) !== null).assertTrue() - let dd = fileio.opendirSync(dpath) - expect(dd !== null).assertTrue() - expect(dd.closeSync() == null).assertTrue() - expect(fileio.rmdirSync(dpath) !== null).assertTrue() - } catch (e) { - console.log("fileio_test_dir_close_sync_000 has failed for " + e) - expect(null).assertFail() + expect(fileio.mkdirSync(dpath) !== null).assertTrue(); + let dd = fileio.opendirSync(dpath); + expect(dd !== null).assertTrue(); + expect(dd.closeSync() == null).assertTrue(); + expect(fileio.rmdirSync(dpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_dir_close_sync_000 has failed for ' + e); + expect(null).assertFail(); } - }) -}) \ No newline at end of file + }); +}); diff --git a/storage/storagefileiojstest/project/entry/src/main/js/test/FileIODirent.test.js b/storage/storagefileiojstest/project/entry/src/main/js/test/FileIODirent.test.js index 05f961891e12f9d647e8e71f082bbd2c37bb9446..e31bdfb62557f9dc8a32e8c353ea25462a162297 100644 --- a/storage/storagefileiojstest/project/entry/src/main/js/test/FileIODirent.test.js +++ b/storage/storagefileiojstest/project/entry/src/main/js/test/FileIODirent.test.js @@ -1,21 +1,31 @@ /* * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); + * Licensed under the Apache License, Version 2.0 (the 'License'); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, + * distributed under the License is distributed on an 'AS IS' BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ -import fileio from '@system.fileio' -import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index' -import { FILE_CONTENT, prepareFile, nextFileName } from './Common' +import fileio from '@system.fileio'; +import { + describe, + it, + expect +} + from 'deccjsunit/index'; +import { + FILE_CONTENT, + prepareFile, + nextFileName +} + from './Common'; describe('fileIOTestDirent', function () { @@ -25,23 +35,24 @@ describe('fileIOTestDirent', function () { * @tc.desc Function of API, Get file name. */ it('fileio_test_dirent_name_000', 0, function () { - let dpath = nextFileName('fileio_test_dirent_name_000') + 'd' - let fpath = dpath + '/f1' + let dpath = nextFileName('fileio_test_dirent_name_000') + 'd'; + let fpath = dpath + '/f1'; try { - expect(fileio.mkdirSync(dpath) !== null) - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() - let dd = fileio.opendirSync(dpath) - expect(dd !== null).assertTrue() - let dirent = dd.readSync() - expect(dirent.name !== null).assertTrue() - expect(dd.closeSync() !== null) - expect(fileio.unlinkSync(fpath) !== null) - expect(fileio.rmdirSync(dpath) !== null) - } catch (e) { - console.log("fileio_test_dirent_name_000 has failed for " + e) - expect(null).assertFail() + expect(fileio.mkdirSync(dpath) !== null); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let dd = fileio.opendirSync(dpath); + expect(dd !== null).assertTrue(); + let dirent = dd.readSync(); + expect(dirent.name !== null).assertTrue(); + expect(dd.closeSync() !== null); + expect(fileio.unlinkSync(fpath) !== null); + expect(fileio.rmdirSync(dpath) !== null); + } + catch (e) { + console.log('fileio_test_dirent_name_000 has failed for ' + e); + expect(null).assertFail(); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_dirent_isBlockDevice_0000 @@ -49,25 +60,26 @@ describe('fileIOTestDirent', function () { * @tc.desc Function of API, isBlockDevice. Determine whether it is a block device. */ it('fileio_test_dirent_is_block_device_000', 0, function () { - let dpath = nextFileName('fileio_test_dirent_is_block_device_000') + 'd' - let fpath = dpath + '/f1' + let dpath = nextFileName('fileio_test_dirent_is_block_device_000') + 'd'; + let fpath = dpath + '/f1'; try { - expect(fileio.mkdirSync(dpath) !== null) - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() - let dd = fileio.opendirSync(dpath) - expect(dd !== null).assertTrue() - let dirent = dd.readSync() - expect(dirent !== null).assertTrue() - expect(dirent.isBlockDevice() !== null) - expect(dd.closeSync() !== null) - expect(fileio.unlinkSync(fpath) !== null) - expect(fileio.rmdirSync(dpath) !== null) + expect(fileio.mkdirSync(dpath) !== null); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let dd = fileio.opendirSync(dpath); + expect(dd !== null).assertTrue(); + let dirent = dd.readSync(); + expect(dirent !== null).assertTrue(); + expect(dirent.isBlockDevice() !== null); + expect(dd.closeSync() !== null); + expect(fileio.unlinkSync(fpath) !== null); + expect(fileio.rmdirSync(dpath) !== null); return - } catch (e) { - console.log("fileio_test_dirent_is_block_device_000 has failed for " + e) - expect(null).assertFail() + } + catch (e) { + console.log('fileio_test_dirent_is_block_device_000 has failed for ' + e); + expect(null).assertFail(); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_dirent_isBlockDevice_0100 @@ -75,25 +87,26 @@ describe('fileIOTestDirent', function () { * @tc.desc Function of API, isBlockDevice. The parameter is - 1. */ it('fileio_test_dirent_is_block_device_001', 0, function () { - let dpath = nextFileName('fileio_test_dirent_is_block_device_001') + 'd' - let fpath = dpath + '/f1' - let dd + let dpath = nextFileName('fileio_test_dirent_is_block_device_001') + 'd'; + let fpath = dpath + '/f1'; + let dd; try { - expect(fileio.mkdirSync(dpath) !== null) - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() - dd = fileio.opendirSync(dpath) - expect(dd !== null).assertTrue() - let dirent = dd.readSync() - expect(dirent !== null).assertTrue() - dirent.isBlockDevice(-1) - expect(null).assertFail() - } catch (e) { - expect(dd.closeSync() !== null) - expect(fileio.unlinkSync(fpath) !== null) - expect(fileio.rmdirSync(dpath) !== null) - console.log("fileio_test_dirent_is_block_device_001 has failed for " + e) + expect(fileio.mkdirSync(dpath) !== null); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + dd = fileio.opendirSync(dpath); + expect(dd !== null).assertTrue(); + let dirent = dd.readSync(); + expect(dirent !== null).assertTrue(); + dirent.isBlockDevice(-1); + expect(null).assertFail(); + } + catch (e) { + expect(dd.closeSync() !== null); + expect(fileio.unlinkSync(fpath) !== null); + expect(fileio.rmdirSync(dpath) !== null); + console.log('fileio_test_dirent_is_block_device_001 has failed for ' + e); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_dirent_isCharacterDevice_0000 @@ -101,24 +114,25 @@ describe('fileIOTestDirent', function () { * @tc.desc Function of API, isCharacterDevice. Determine whether it is a character device. */ it('fileio_test_dirent_is_character_device_000', 0, function () { - let dpath = nextFileName('fileio_test_dirent_is_character_device_000') + 'd' - let fpath = dpath + '/f1' + let dpath = nextFileName('fileio_test_dirent_is_character_device_000') + 'd'; + let fpath = dpath + '/f1'; try { - expect(fileio.mkdirSync(dpath) !== null) - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() - let dd = fileio.opendirSync(dpath) - expect(dd !== null).assertTrue() - let dirent = dd.readSync() - expect(dirent !== null).assertTrue() - expect(dirent.isCharacterDevice() !== null) - expect(dd.closeSync() !== null !== null) - expect(fileio.unlinkSync(fpath) !== null) - expect(fileio.rmdirSync(dpath) !== null) - } catch (e) { - console.log("fileio_test_dirent_is_character_device_000 has failed for " + e) - expect(null).assertFail() + expect(fileio.mkdirSync(dpath) !== null); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let dd = fileio.opendirSync(dpath); + expect(dd !== null).assertTrue(); + let dirent = dd.readSync(); + expect(dirent !== null).assertTrue(); + expect(dirent.isCharacterDevice() !== null); + expect(dd.closeSync() !== null !== null); + expect(fileio.unlinkSync(fpath) !== null); + expect(fileio.rmdirSync(dpath) !== null); + } + catch (e) { + console.log('fileio_test_dirent_is_character_device_000 has failed for ' + e); + expect(null).assertFail(); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_dirent_isCharacterDevice_0100 @@ -126,25 +140,26 @@ describe('fileIOTestDirent', function () { * @tc.desc Function of API, isCharacterDevice. The parameter is - 1. */ it('fileio_test_dirent_is_character_device_001', 0, function () { - let dpath = nextFileName('fileio_test_dirent_is_character_device_001') + 'd' - let fpath = dpath + '/f1' - let dd + let dpath = nextFileName('fileio_test_dirent_is_character_device_001') + 'd'; + let fpath = dpath + '/f1'; + let dd; try { - expect(fileio.mkdirSync(dpath) !== null) - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() - dd = fileio.opendirSync(dpath) - expect(dd !== null).assertTrue() - let dirent = dd.readSync() - expect(dirent !== null).assertTrue() - dirent.isCharacterDevice(-1) - expect(null).assertFail() - } catch (e) { - expect(dd.closeSync() !== null) - expect(fileio.unlinkSync(fpath) !== null) - expect(fileio.rmdirSync(dpath) !== null) - console.log("fileio_test_dirent_is_character_device_001 has failed for " + e) + expect(fileio.mkdirSync(dpath) !== null); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + dd = fileio.opendirSync(dpath); + expect(dd !== null).assertTrue(); + let dirent = dd.readSync(); + expect(dirent !== null).assertTrue(); + dirent.isCharacterDevice(-1); + expect(null).assertFail(); + } + catch (e) { + expect(dd.closeSync() !== null); + expect(fileio.unlinkSync(fpath) !== null); + expect(fileio.rmdirSync(dpath) !== null); + console.log('fileio_test_dirent_is_character_device_001 has failed for ' + e); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_dirent_isDirectory_0000 @@ -152,24 +167,25 @@ describe('fileIOTestDirent', function () { * @tc.desc Function of API, isDirectory. Determine whether it is a directory. */ it('fileio_test_dirent_is_directory_000', 0, function () { - let dpath = nextFileName('fileio_test_dirent_is_directory_000') + 'd' - let fpath = dpath + '/f1' + let dpath = nextFileName('fileio_test_dirent_is_directory_000') + 'd'; + let fpath = dpath + '/f1'; try { - expect(fileio.mkdirSync(dpath) !== null) - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() - let dd = fileio.opendirSync(dpath) - expect(dd !== null).assertTrue() - let dirent = dd.readSync() - expect(dirent !== null).assertTrue() - expect(dirent.isDirectory() !== null) - expect(dd.closeSync() !== null) - expect(fileio.unlinkSync(fpath) !== null) - expect(fileio.rmdirSync(dpath) !== null) - } catch (e) { - console.log("fileio_test_dirent_is_directory_000 has failed for " + e) - expect(null).assertFail() + expect(fileio.mkdirSync(dpath) !== null); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let dd = fileio.opendirSync(dpath); + expect(dd !== null).assertTrue(); + let dirent = dd.readSync(); + expect(dirent !== null).assertTrue(); + expect(dirent.isDirectory() !== null); + expect(dd.closeSync() !== null); + expect(fileio.unlinkSync(fpath) !== null); + expect(fileio.rmdirSync(dpath) !== null); + } + catch (e) { + console.log('fileio_test_dirent_is_directory_000 has failed for ' + e); + expect(null).assertFail(); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_dirent_isDirectory_0100 @@ -177,25 +193,26 @@ describe('fileIOTestDirent', function () { * @tc.desc Function of API, isDirectory. The parameter is - 1 */ it('fileio_test_dirent_is_directory_001', 0, function () { - let dpath = nextFileName('fileio_test_dirent_is_directory_001') + 'd' - let fpath = dpath + '/f1' - let dd + let dpath = nextFileName('fileio_test_dirent_is_directory_001') + 'd'; + let fpath = dpath + '/f1'; + let dd; try { - expect(fileio.mkdirSync(dpath) !== null) - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() - dd = fileio.opendirSync(dpath) - expect(dd !== null).assertTrue() - let dirent = dd.readSync() - expect(dirent !== null).assertTrue() - dirent.isDirectory(-1) - expect(null).assertFail() - } catch (e) { - expect(dd.closeSync() !== null) - expect(fileio.unlinkSync(fpath) !== null) - expect(fileio.rmdirSync(dpath) !== null) - console.log("fileio_test_dirent_is_directory_001 has failed for " + e) + expect(fileio.mkdirSync(dpath) !== null); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + dd = fileio.opendirSync(dpath); + expect(dd !== null).assertTrue(); + let dirent = dd.readSync(); + expect(dirent !== null).assertTrue(); + dirent.isDirectory(-1); + expect(null).assertFail(); + } + catch (e) { + expect(dd.closeSync() !== null); + expect(fileio.unlinkSync(fpath) !== null); + expect(fileio.rmdirSync(dpath) !== null); + console.log('fileio_test_dirent_is_directory_001 has failed for ' + e); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_dirent_isFifo_0000 @@ -203,24 +220,25 @@ describe('fileIOTestDirent', function () { * @tc.desc Function of API, isFIFO. Determine whether it is a fifo. */ it('fileio_test_dirent_is_fifo_000', 0, function () { - let dpath = nextFileName('fileio_test_dirent_is_fifo_000') + 'd' - let fpath = dpath + '/f1' + let dpath = nextFileName('fileio_test_dirent_is_fifo_000') + 'd'; + let fpath = dpath + '/f1'; try { - expect(fileio.mkdirSync(dpath) !== null) - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() - let dd = fileio.opendirSync(dpath) - expect(dd !== null).assertTrue() - let dirent = dd.readSync() - expect(dirent !== null).assertTrue() - expect(dirent.isFIFO() !== null) - expect(dd.closeSync() !== null) - expect(fileio.unlinkSync(fpath) !== null) - expect(fileio.rmdirSync(dpath) !== null) - } catch (e) { - console.log("fileio_test_dirent_is_fifo_000 has failed for " + e) - expect(null).assertFail() + expect(fileio.mkdirSync(dpath) !== null); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let dd = fileio.opendirSync(dpath); + expect(dd !== null).assertTrue(); + let dirent = dd.readSync(); + expect(dirent !== null).assertTrue(); + expect(dirent.isFIFO() !== null); + expect(dd.closeSync() !== null); + expect(fileio.unlinkSync(fpath) !== null); + expect(fileio.rmdirSync(dpath) !== null); + } + catch (e) { + console.log('fileio_test_dirent_is_fifo_000 has failed for ' + e); + expect(null).assertFail(); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_dirent_isFifo_0100 @@ -228,25 +246,26 @@ describe('fileIOTestDirent', function () { * @tc.desc Function of API, isFIFO. The parameter is - 1 */ it('fileio_test_dirent_is_fifo_001', 0, function () { - let dpath = nextFileName('fileio_test_dirent_is_fifo_001') + 'd' - let fpath = dpath + '/f1' - let dd + let dpath = nextFileName('fileio_test_dirent_is_fifo_001') + 'd'; + let fpath = dpath + '/f1'; + let dd; try { - expect(fileio.mkdirSync(dpath) !== null) - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() - dd = fileio.opendirSync(dpath) - expect(dd !== null).assertTrue() - let dirent = dd.readSync() - expect(dirent !== null).assertTrue() - dirent.isFIFO(-1) - expect(null).assertFail() - } catch (e) { - expect(dd.closeSync() !== null) - expect(fileio.unlinkSync(fpath) !== null) - expect(fileio.rmdirSync(dpath) !== null) - console.log("fileio_test_dirent_is_fifo_001 has failed for " + e) + expect(fileio.mkdirSync(dpath) !== null); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + dd = fileio.opendirSync(dpath); + expect(dd !== null).assertTrue(); + let dirent = dd.readSync(); + expect(dirent !== null).assertTrue(); + dirent.isFIFO(-1); + expect(null).assertFail(); + } + catch (e) { + expect(dd.closeSync() !== null); + expect(fileio.unlinkSync(fpath) !== null); + expect(fileio.rmdirSync(dpath) !== null); + console.log('fileio_test_dirent_is_fifo_001 has failed for ' + e); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_dirent_isFile_0000 @@ -254,24 +273,25 @@ describe('fileIOTestDirent', function () { * @tc.desc Function of API, isFile. Determine whether it is a file. */ it('fileio_test_dirent_is_file_000', 0, function () { - let dpath = nextFileName('fileio_test_dirent_is_file_000') + 'd' - let fpath = dpath + '/f1' + let dpath = nextFileName('fileio_test_dirent_is_file_000') + 'd'; + let fpath = dpath + '/f1'; try { - expect(fileio.mkdirSync(dpath) !== null) - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() - let dd = fileio.opendirSync(dpath) - expect(dd !== null).assertTrue() - let dirent = dd.readSync() - expect(dirent !== null).assertTrue() - expect(dirent.isFile() !== null) - expect(dd.closeSync() !== null) - expect(fileio.unlinkSync(fpath) !== null) - expect(fileio.rmdirSync(dpath) !== null) - } catch (e) { - console.log("fileio_test_dirent_is_file_000 has failed for " + e) - expect(null).assertFail() + expect(fileio.mkdirSync(dpath) !== null); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let dd = fileio.opendirSync(dpath); + expect(dd !== null).assertTrue(); + let dirent = dd.readSync(); + expect(dirent !== null).assertTrue(); + expect(dirent.isFile() !== null); + expect(dd.closeSync() !== null); + expect(fileio.unlinkSync(fpath) !== null); + expect(fileio.rmdirSync(dpath) !== null); + } + catch (e) { + console.log('fileio_test_dirent_is_file_000 has failed for ' + e); + expect(null).assertFail(); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_dirent_isFile_0100 @@ -279,25 +299,26 @@ describe('fileIOTestDirent', function () { * @tc.desc Function of API, isFile. The parameter is - 1 */ it('fileio_test_dirent_is_file_001', 0, function () { - let dpath = nextFileName('fileio_test_dirent_is_file_001') + 'd' - let fpath = dpath + '/f1' - let dd + let dpath = nextFileName('fileio_test_dirent_is_file_001') + 'd'; + let fpath = dpath + '/f1'; + let dd; try { - expect(fileio.mkdirSync(dpath) !== null) - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() - dd = fileio.opendirSync(dpath) - expect(dd !== null).assertTrue() - let dirent = dd.readSync() - expect(dirent !== null).assertTrue() - dirent.isFile(-1) - expect(null).assertFail() - } catch (e) { - expect(dd.closeSync() !== null) - expect(fileio.unlinkSync(fpath) !== null) - expect(fileio.rmdirSync(dpath) !== null) - console.log("fileio_test_dirent_is_file_001 has failed for " + e) + expect(fileio.mkdirSync(dpath) !== null); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + dd = fileio.opendirSync(dpath); + expect(dd !== null).assertTrue(); + let dirent = dd.readSync(); + expect(dirent !== null).assertTrue(); + dirent.isFile(-1); + expect(null).assertFail(); + } + catch (e) { + expect(dd.closeSync() !== null); + expect(fileio.unlinkSync(fpath) !== null); + expect(fileio.rmdirSync(dpath) !== null); + console.log('fileio_test_dirent_is_file_001 has failed for ' + e); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_dirent_isSocket_0000 @@ -305,24 +326,25 @@ describe('fileIOTestDirent', function () { * @tc.desc Function of API, isSocket. Determine whether it is a socket. */ it('fileio_test_dirent_is_socket_000', 0, function () { - let dpath = nextFileName('fileio_test_dirent_is_socket_000') + 'd' - let fpath = dpath + '/f1' + let dpath = nextFileName('fileio_test_dirent_is_socket_000') + 'd'; + let fpath = dpath + '/f1'; try { - expect(fileio.mkdirSync(dpath) !== null) - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() - let dd = fileio.opendirSync(dpath) - expect(dd !== null).assertTrue() - let dirent = dd.readSync() - expect(dirent !== null).assertTrue() - expect(dirent.isSocket() !== null) - expect(dd.closeSync() !== null) - expect(fileio.unlinkSync(fpath) !== null) - expect(fileio.rmdirSync(dpath) !== null) - } catch (e) { - console.log("fileio_test_dirent_is_socket_000 has failed for " + e) - expect(null).assertFail() + expect(fileio.mkdirSync(dpath) !== null); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let dd = fileio.opendirSync(dpath); + expect(dd !== null).assertTrue(); + let dirent = dd.readSync(); + expect(dirent !== null).assertTrue(); + expect(dirent.isSocket() !== null); + expect(dd.closeSync() !== null); + expect(fileio.unlinkSync(fpath) !== null); + expect(fileio.rmdirSync(dpath) !== null); + } + catch (e) { + console.log('fileio_test_dirent_is_socket_000 has failed for ' + e); + expect(null).assertFail(); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_dirent_isSocket_0100 @@ -330,25 +352,26 @@ describe('fileIOTestDirent', function () { * @tc.desc Function of API, isSocket. The parameter is - 1 */ it('fileio_test_dirent_is_socket_001', 0, function () { - let dpath = nextFileName('fileio_test_dirent_is_socket_001') + 'd' - let fpath = dpath + '/f1' - let dd + let dpath = nextFileName('fileio_test_dirent_is_socket_001') + 'd'; + let fpath = dpath + '/f1'; + let dd; try { - expect(fileio.mkdirSync(dpath) !== null) - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() - dd = fileio.opendirSync(dpath) - expect(dd !== null).assertTrue() - let dirent = dd.readSync() - expect(dirent !== null).assertTrue() - dirent.isSocket(-1) - expect(null).assertFail() - } catch (e) { - expect(dd.closeSync() !== null) - expect(fileio.unlinkSync(fpath) !== null) - expect(fileio.rmdirSync(dpath) !== null) - console.log("fileio_test_dirent_is_socket_001 has failed for " + e) + expect(fileio.mkdirSync(dpath) !== null); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + dd = fileio.opendirSync(dpath); + expect(dd !== null).assertTrue(); + let dirent = dd.readSync(); + expect(dirent !== null).assertTrue(); + dirent.isSocket(-1); + expect(null).assertFail(); + } + catch (e) { + expect(dd.closeSync() !== null); + expect(fileio.unlinkSync(fpath) !== null); + expect(fileio.rmdirSync(dpath) !== null); + console.log('fileio_test_dirent_is_socket_001 has failed for ' + e); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_dirent_isSymbolicLlink_0000 @@ -356,24 +379,25 @@ describe('fileIOTestDirent', function () { * @tc.desc Function of API, isSymbolicLink. Determine whether it is a symbolic link. */ it('fileio_test_dirent_is_symbolic_link_000', 0, function () { - let dpath = nextFileName('fileio_test_dirent_is_symbolic_link_000') + 'd' - let fpath = dpath + '/f1' + let dpath = nextFileName('fileio_test_dirent_is_symbolic_link_000') + 'd'; + let fpath = dpath + '/f1'; try { - expect(fileio.mkdirSync(dpath) !== null) - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() - let dd = fileio.opendirSync(dpath) - expect(dd !== null).assertTrue() - let dirent = dd.readSync() - expect(dirent !== null).assertTrue() - expect(dirent.isSymbolicLink() !== null) - expect(dd.closeSync() !== null) - expect(fileio.unlinkSync(fpath) !== null) - expect(fileio.rmdirSync(dpath) !== null) - } catch (e) { - console.log("fileio_test_dirent_is_symbolic_link_000 has failed for " + e) - expect(null).assertFail() + expect(fileio.mkdirSync(dpath) !== null); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let dd = fileio.opendirSync(dpath); + expect(dd !== null).assertTrue(); + let dirent = dd.readSync(); + expect(dirent !== null).assertTrue(); + expect(dirent.isSymbolicLink() !== null); + expect(dd.closeSync() !== null); + expect(fileio.unlinkSync(fpath) !== null); + expect(fileio.rmdirSync(dpath) !== null); + } + catch (e) { + console.log('fileio_test_dirent_is_symbolic_link_000 has failed for ' + e); + expect(null).assertFail(); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_dirent_isSymbolicLlink_0100 @@ -381,23 +405,25 @@ describe('fileIOTestDirent', function () { * @tc.desc Function of API, isSymbolicLink. The parameter is - 1 */ it('fileio_test_dirent_is_symbolic_link_001', 0, function () { - let dpath = nextFileName('fileio_test_dirent_is_symbolic_link_001') + 'd' - let fpath = dpath + '/f1' - let dd + let dpath = nextFileName('fileio_test_dirent_is_symbolic_link_001') + 'd'; + let fpath = dpath + '/f1'; + let dd; try { - expect(fileio.mkdirSync(dpath) !== null) - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() - dd = fileio.opendirSync(dpath) - expect(dd !== null).assertTrue() - let dirent = dd.readSync() - expect(dirent !== null).assertTrue() - dirent.isSymbolicLink(-1) - expect(null).assertFail() - } catch (e) { - expect(dd.closeSync() !== null) - expect(fileio.unlinkSync(fpath) !== null) - expect(fileio.rmdirSync(dpath) !== null) - console.log("fileio_test_dirent_is_symbolic_link_001 has failed for " + e) + expect(fileio.mkdirSync(dpath) !== null); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + dd = fileio.opendirSync(dpath); + expect(dd !== null).assertTrue(); + let dirent = dd.readSync(); + expect(dirent !== null).assertTrue(); + dirent.isSymbolicLink(-1); + expect(null).assertFail(); + } + catch (e) { + expect(dd.closeSync() !== null); + expect(fileio.unlinkSync(fpath) !== null); + expect(fileio.rmdirSync(dpath) !== null); + console.log('fileio_test_dirent_is_symbolic_link_001 has failed for ' + e); } - }) -}) + }); + +}); \ No newline at end of file diff --git a/storage/storagefileiojstest/project/entry/src/main/js/test/FileIOStat.test.js b/storage/storagefileiojstest/project/entry/src/main/js/test/FileIOStat.test.js index cc0a8eba856e10d6b047db4621281280d70aa059..ff923dc8133ea20a329e6f8d7df0009a81c2c415 100644 --- a/storage/storagefileiojstest/project/entry/src/main/js/test/FileIOStat.test.js +++ b/storage/storagefileiojstest/project/entry/src/main/js/test/FileIOStat.test.js @@ -1,21 +1,32 @@ /* * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); + * Licensed under the Apache License, Version 2.0 (the 'License'); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, + * distributed under the License is distributed on an 'AS IS' BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import fileio from '@ohos.fileio'; -import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index' -import { FILE_CONTENT, prepareFile, nextFileName, randomString } from './Common' +import { + describe, + it, + expect +} + from 'deccjsunit/index' +import { + FILE_CONTENT, + prepareFile, + nextFileName, + randomString +} + from './Common' describe('fileIOTestStat', function () { @@ -25,17 +36,18 @@ describe('fileIOTestStat', function () { * @tc.desc Function of API, statSync. Gets information about the file in the specified path. */ it('fileio_test_stat_stat_sync_000', 0, function () { - let fpath = nextFileName('fileio_test_stat_stat_sync_000') - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + let fpath = nextFileName('fileio_test_stat_stat_sync_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); try { - let stat = fileio.statSync(fpath) - expect(stat !== null).assertTrue() - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - } catch (e) { - console.log("fileio_test_stat_stat_sync_000 has failed for " + e) - expect(null).assertFail() + let stat = fileio.statSync(fpath); + expect(stat !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_stat_stat_sync_000 has failed for ' + e); + expect(null).assertFail(); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_statSync_0100 @@ -43,14 +55,15 @@ describe('fileIOTestStat', function () { * @tc.desc Function of API, statSync. The specified file does not exist. */ it('fileio_test_stat_stat_sync_001', 0, function () { - let fpath = nextFileName('fileio_test_stat_stat_sync_001') + let fpath = nextFileName('fileio_test_stat_stat_sync_001'); try { - fileio.statSync(fpath) - expect(null).assertFail() - } catch (e) { - console.log("fileio_test_stat_stat_sync_001 has failed for " + e) + fileio.statSync(fpath); + expect(null).assertFail(); } - }) + catch (e) { + console.log('fileio_test_stat_stat_sync_001 has failed for ' + e); + } + }); /** * @tc.number SUB_STORAGE_FileIO_statSync_0200 @@ -58,17 +71,18 @@ describe('fileIOTestStat', function () { * @tc.desc Function of API, statSync. The parameter is the directory path. */ it('fileio_test_stat_stat_sync_002', 0, function () { - let dpath = nextFileName('fileio_test_stat_stat_sync_002') + 'd' - expect(fileio.mkdirSync(dpath) !== null).assertTrue() + let dpath = nextFileName('fileio_test_stat_stat_sync_002') + 'd'; + expect(fileio.mkdirSync(dpath) !== null).assertTrue(); try { - let stat = fileio.statSync(dpath) - expect(stat !== null).assertTrue() - expect(fileio.rmdirSync(dpath) !== null).assertTrue() - } catch (e) { - console.log("fileio_test_stat_stat_sync_002 has failed for " + e) - expect(null).assertFail() + let stat = fileio.statSync(dpath); + expect(stat !== null).assertTrue(); + expect(fileio.rmdirSync(dpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_stat_stat_sync_002 has failed for ' + e); + expect(null).assertFail(); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_statSync_0300 @@ -76,21 +90,22 @@ describe('fileIOTestStat', function () { * @tc.desc Function of API, statSync. The file path is greater than 4096. */ it('fileio_test_stat_stat_sync_003', 0, function () { - let dpath = nextFileName("fileio_stat1") + let dpath = nextFileName('fileio_stat1'); try { for (let i = 0; i < 16; i++) { if (i == 15) { - let fpath = dpath + "/f" + randomString(252) - fileio.statSync(fpath) + let fpath = dpath + '/f' + randomString(252); + fileio.statSync(fpath); } else { - dpath = dpath + "/d" + randomString(252) + dpath = dpath + '/d' + randomString(252); } } - expect(null).assertFail() - } catch (e) { - console.log("fileio_test_stat_stat_sync_003 has failed for " + e) + expect(null).assertFail(); + } + catch (e) { + console.log('fileio_test_stat_stat_sync_003 has failed for ' + e); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_Stat_dev_0000 @@ -98,17 +113,18 @@ describe('fileIOTestStat', function () { * @tc.desc Function of API. Get the device number used by the file. */ it('fileio_test_stat_dev_000', 0, function () { - let fpath = nextFileName('fileio_test_stat_dev_000') - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + let fpath = nextFileName('fileio_test_stat_dev_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); try { - let stat = fileio.statSync(fpath) - expect(typeof (stat.dev) == "number").assertTrue() - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - } catch (e) { - console.log("fileio_test_stat_dev_000 has failed for " + e) - expect(null).assertFail() + let stat = fileio.statSync(fpath); + expect(typeof(stat.dev) == 'number').assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_stat_dev_000 has failed for ' + e); + expect(null).assertFail(); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_Stat_ino_0000 @@ -116,17 +132,18 @@ describe('fileIOTestStat', function () { * @tc.desc Function of API. Get inode number. */ it('fileio_test_stat_ino_000', 0, function () { - let fpath = nextFileName('fileio_test_stat_ino_000') - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + let fpath = nextFileName('fileio_test_stat_ino_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); try { - let stat = fileio.statSync(fpath) - expect(typeof (stat.ino) == "number").assertTrue() - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - } catch (e) { - console.log("fileio_test_stat_ino_000 has failed for " + e) - expect(null).assertFail() + let stat = fileio.statSync(fpath); + expect(typeof(stat.ino) == 'number').assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_stat_ino_000 has failed for ' + e); + expect(null).assertFail(); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_Stat_mode_0000 @@ -134,17 +151,18 @@ describe('fileIOTestStat', function () { * @tc.desc Function of API. Get file type and access rights. */ it('fileio_test_stat_mode_000', 0, function () { - let fpath = nextFileName('fileio_test_stat_mode_000') - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + let fpath = nextFileName('fileio_test_stat_mode_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); try { - let stat = fileio.statSync(fpath) - expect(typeof (stat.mode) == "number").assertTrue() - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - } catch (e) { - console.log("fileio_test_stat_mode_000 has failed for " + e) - expect(null).assertFail() + let stat = fileio.statSync(fpath); + expect(typeof(stat.mode) == 'number').assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_stat_mode_000 has failed for ' + e); + expect(null).assertFail(); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_Stat_nlink_0000 @@ -152,17 +170,18 @@ describe('fileIOTestStat', function () { * @tc.desc Function of API. Gets the number of hard connections to the file. */ it('fileio_test_stat_nlink_000', 0, function () { - let fpath = nextFileName('fileio_test_stat_nlink_000') - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + let fpath = nextFileName('fileio_test_stat_nlink_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); try { - let stat = fileio.statSync(fpath) - expect(typeof (stat.nlink) == "number").assertTrue() - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - } catch (e) { - console.log("fileio_test_stat_nlink_000 has failed for " + e) - expect(null).assertFail() + let stat = fileio.statSync(fpath); + expect(typeof(stat.nlink) == 'number').assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_stat_nlink_000 has failed for ' + e); + expect(null).assertFail(); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_Stat_uid_0000 @@ -170,17 +189,18 @@ describe('fileIOTestStat', function () { * @tc.desc Function of API. Get file owner user ID. */ it('fileio_test_stat_uid_000', 0, function () { - let fpath = nextFileName('fileio_test_stat_uid_000') - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + let fpath = nextFileName('fileio_test_stat_uid_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); try { - let stat = fileio.statSync(fpath) - expect(typeof (stat.uid) == "number").assertTrue() - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - } catch (e) { - console.log("fileio_test_stat_uid_000 has failed for " + e) - expect(null).assertFail() + let stat = fileio.statSync(fpath); + expect(typeof(stat.uid) == 'number').assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_stat_uid_000 has failed for ' + e); + expect(null).assertFail(); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_Stat_gid_0000 @@ -188,17 +208,18 @@ describe('fileIOTestStat', function () { * @tc.desc Function of API. Get group ID. */ it('fileio_test_stat_gid_000', 0, function () { - let fpath = nextFileName('fileio_test_stat_gid_000') - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + let fpath = nextFileName('fileio_test_stat_gid_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); try { - let stat = fileio.statSync(fpath) - expect(typeof (stat.gid) == "number").assertTrue() - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - } catch (e) { - console.log("fileio_test_stat_gid_000 has failed for " + e) - expect(null).assertFail() + let stat = fileio.statSync(fpath); + expect(typeof(stat.gid) == 'number').assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_stat_gid_000 has failed for ' + e); + expect(null).assertFail(); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_Stat_rdev_0000 @@ -206,17 +227,18 @@ describe('fileIOTestStat', function () { * @tc.desc Function of API. Get the device number of the device file. */ it('fileio_test_stat_rdev_000', 0, function () { - let fpath = nextFileName('fileio_test_stat_rdev_000') - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + let fpath = nextFileName('fileio_test_stat_rdev_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); try { - let stat = fileio.statSync(fpath) - expect(typeof (stat.rdev) == "number").assertTrue() - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - } catch (e) { - console.log("fileio_test_stat_rdev_000 has failed for " + e) - expect(null).assertFail() + let stat = fileio.statSync(fpath); + expect(typeof(stat.rdev) == 'number').assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_stat_rdev_000 has failed for ' + e); + expect(null).assertFail(); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_stat_size_0000 @@ -224,17 +246,18 @@ describe('fileIOTestStat', function () { * @tc.desc Function of API. Gets the file capacity in bytes. */ it('fileio_test_stat_size_000', 0, function () { - let fpath = nextFileName('fileio_test_stat_size_000') - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + let fpath = nextFileName('fileio_test_stat_size_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); try { - let stat = fileio.statSync(fpath) - expect(typeof (stat.size) == "number").assertTrue() - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - } catch (e) { - console.log("fileio_test_stat_size_000 has failed for " + e) - expect(null).assertFail() + let stat = fileio.statSync(fpath); + expect(typeof(stat.size) == 'number').assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_stat_size_000 has failed for ' + e); + expect(null).assertFail(); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_Stat_blksize_0000 @@ -242,17 +265,18 @@ describe('fileIOTestStat', function () { * @tc.desc Function of API. Gets the size of the disk block containing the file. */ it('fileio_test_stat_blksize_000', 0, function () { - let fpath = nextFileName('fileio_test_stat_blksize_000') - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + let fpath = nextFileName('fileio_test_stat_blksize_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); try { - let stat = fileio.statSync(fpath) - expect(typeof (stat.blksize) == "number").assertTrue() - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - } catch (e) { - console.log("fileio_test_stat_blksize_000 has failed for " + e) - expect(null).assertFail() + let stat = fileio.statSync(fpath); + expect(typeof(stat.blksize) == 'number').assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_stat_blksize_000 has failed for ' + e); + expect(null).assertFail(); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_Stat_blocks_0000 @@ -260,17 +284,18 @@ describe('fileIOTestStat', function () { * @tc.desc Function of API. Gets the disk block occupied by the file. */ it('fileio_test_stat_blocks_000', 0, function () { - let fpath = nextFileName('fileio_test_stat_blocks_000') - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + let fpath = nextFileName('fileio_test_stat_blocks_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); try { - let stat = fileio.statSync(fpath) - expect(typeof (stat.blocks) == "number").assertTrue() - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - } catch (e) { - console.log("fileio_test_stat_blocks_000 has failed for " + e) - expect(null).assertFail() + let stat = fileio.statSync(fpath); + expect(typeof(stat.blocks) == 'number').assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_stat_blocks_000 has failed for ' + e); + expect(null).assertFail(); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_stat_atime_0000 @@ -278,17 +303,18 @@ describe('fileIOTestStat', function () { * @tc.desc Function of API. Gets the time when a file was last accessed. */ it('fileio_test_stat_atime_000', 0, function () { - let fpath = nextFileName('fileio_test_stat_atime_000') - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + let fpath = nextFileName('fileio_test_stat_atime_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); try { - let stat = fileio.statSync(fpath) - expect(typeof (stat.atime) == "number").assertTrue() - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - } catch (e) { - console.log("fileio_test_stat_atime_000 has failed for " + e) - expect(null).assertFail() + let stat = fileio.statSync(fpath); + expect(typeof(stat.atime) == 'number').assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_stat_atime_000 has failed for ' + e); + expect(null).assertFail(); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_Stat_mtime_0000 @@ -296,17 +322,18 @@ describe('fileIOTestStat', function () { * @tc.desc Function of API. Gets the time when a file was last modified */ it('fileio_test_stat_mtime_000', 0, function () { - let fpath = nextFileName('fileio_test_stat_mtime_000') - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + let fpath = nextFileName('fileio_test_stat_mtime_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); try { - let stat = fileio.statSync(fpath) - expect(typeof (stat.mtime) == "number").assertTrue() - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - } catch (e) { - console.log("fileio_test_stat_mtime_000 has failed for " + e) - expect(null).assertFail() + let stat = fileio.statSync(fpath); + expect(typeof(stat.mtime) == 'number').assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_stat_mtime_000 has failed for ' + e); + expect(null).assertFail(); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_Stat_ctime_0000 @@ -314,17 +341,18 @@ describe('fileIOTestStat', function () { * @tc.desc Function of API. Gets the time when a file last changed state */ it('fileio_test_stat_ctime_000', 0, function () { - let fpath = nextFileName('fileio_test_stat_ctime_000') - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + let fpath = nextFileName('fileio_test_stat_ctime_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); try { - let stat = fileio.statSync(fpath) - expect(typeof (stat.ctime) == "number").assertTrue() - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - } catch (e) { - console.log("fileio_test_stat_ctime_000 has failed for " + e) - expect(null).assertFail() + let stat = fileio.statSync(fpath); + expect(typeof(stat.ctime) == 'number').assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_stat_ctime_000 has failed for ' + e); + expect(null).assertFail(); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_Stat_isBlockDevice_0000 @@ -332,17 +360,18 @@ describe('fileIOTestStat', function () { * @tc.desc Function of API, isBlockDevice. Determine whether it is a block device. The return value is Boolean. */ it('fileio_test_stat_is_block_device_000', 0, function () { - let fpath = nextFileName('fileio_test_stat_is_block_device_000') - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + let fpath = nextFileName('fileio_test_stat_is_block_device_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); try { - let stat = fileio.statSync(fpath) - expect(typeof (stat.isBlockDevice()) == "boolean").assertTrue() - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - } catch (e) { - console.log("fileio_test_stat_is_block_device_000 has failed for " + e) - expect(null).assertFail() + let stat = fileio.statSync(fpath); + expect(typeof(stat.isBlockDevice()) == 'boolean').assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_stat_is_block_device_000 has failed for ' + e); + expect(null).assertFail(); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_Stat_isBlockDevice_0100 @@ -350,17 +379,18 @@ describe('fileIOTestStat', function () { * @tc.desc Function of API, isBlockDevice. Determine whether it is a block device. The return value is false. */ it('fileio_test_stat_is_block_device_001', 0, function () { - let fpath = nextFileName('fileio_test_stat_is_block_device_001') - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + let fpath = nextFileName('fileio_test_stat_is_block_device_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); try { - let stat = fileio.statSync(fpath) - expect(!stat.isBlockDevice()).assertTrue() - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - } catch (e) { - console.log("fileio_test_stat_is_block_device_001 has failed for " + e) - expect(null).assertFail() + let stat = fileio.statSync(fpath); + expect(!stat.isBlockDevice()).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_stat_is_block_device_001 has failed for ' + e); + expect(null).assertFail(); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_Stat_isBlockDevice_0200 @@ -368,17 +398,18 @@ describe('fileIOTestStat', function () { * @tc.desc Function of API, isBlockDevice. The parameter is - 1 */ it('fileio_test_stat_is_block_device_002', 0, function () { - let fpath = nextFileName('fileio_test_stat_is_block_device_002') - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + let fpath = nextFileName('fileio_test_stat_is_block_device_002'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); try { - let stat = fileio.statSync(fpath) - expect(!stat.isBlockDevice(-1)).assertTrue() - expect(null).assertFail() - } catch (e) { - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - console.log("fileio_test_stat_is_block_device_002 has failed for " + e) + let stat = fileio.statSync(fpath); + expect(!stat.isBlockDevice(-1)).assertTrue(); + expect(null).assertFail(); + } + catch (e) { + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + console.log('fileio_test_stat_is_block_device_002 has failed for ' + e); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_stat_isCharacterDevice_0000 @@ -386,17 +417,18 @@ describe('fileIOTestStat', function () { * @tc.desc Function of API, isCharacterDevice. Determine whether it is a character device. The return value is Boolean. */ it('fileio_test_stat_is_character_device_000', 0, function () { - let fpath = nextFileName('fileio_test_stat_is_character_device_000') - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + let fpath = nextFileName('fileio_test_stat_is_character_device_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); try { - let stat = fileio.statSync(fpath) - expect(typeof (stat.isCharacterDevice()) == "boolean").assertTrue() - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - } catch (e) { - console.log("fileio_test_stat_is_character_device_000 has failed for " + e) - expect(null).assertFail() + let stat = fileio.statSync(fpath); + expect(typeof(stat.isCharacterDevice()) == 'boolean').assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_stat_is_character_device_000 has failed for ' + e); + expect(null).assertFail(); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_Stat_isCharacterDevice_0100 @@ -404,17 +436,18 @@ describe('fileIOTestStat', function () { * @tc.desc Function of API, isCharacterDevice. Determine whether it is a character device. The return value is false. */ it('fileio_test_stat_is_character_device_001', 0, function () { - let fpath = nextFileName('fileio_test_stat_is_character_device_001') - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + let fpath = nextFileName('fileio_test_stat_is_character_device_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); try { - let stat = fileio.statSync(fpath) - expect(!stat.isCharacterDevice()).assertTrue() - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - } catch (e) { - console.log("fileio_test_stat_is_character_device_001 has failed for " + e) - expect(null).assertFail() + let stat = fileio.statSync(fpath); + expect(!stat.isCharacterDevice()).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_stat_is_character_device_001 has failed for ' + e); + expect(null).assertFail(); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_Stat_isCharacterDevice_0200 @@ -422,17 +455,18 @@ describe('fileIOTestStat', function () { * @tc.desc Function of API, isCharacterDevice. The parameter is - 1 */ it('fileio_test_stat_is_character_device_002', 0, function () { - let fpath = nextFileName('fileio_test_stat_is_character_device_002') - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + let fpath = nextFileName('fileio_test_stat_is_character_device_002'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); try { - let stat = fileio.statSync(fpath) - expect(!stat.isCharacterDevice(-1)).assertTrue() - expect(null).assertFail() - } catch (e) { - console.log("fileio_test_stat_is_character_device_002 has failed for " + e) - expect(fileio.unlinkSync(fpath) !== null).assertTrue() + let stat = fileio.statSync(fpath); + expect(!stat.isCharacterDevice(-1)).assertTrue(); + expect(null).assertFail(); + } + catch (e) { + console.log('fileio_test_stat_is_character_device_002 has failed for ' + e); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_Stat_isDirectory_0000 @@ -440,17 +474,18 @@ describe('fileIOTestStat', function () { * @tc.desc Function of API, isDirectory. Determine whether it is a directory. The return value is Boolean. */ it('fileio_test_stat_is_directory_000', 0, function () { - let fpath = nextFileName('fileio_test_stat_is_directory_000') - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + let fpath = nextFileName('fileio_test_stat_is_directory_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); try { - let stat = fileio.statSync(fpath) - expect(typeof (stat.isDirectory()) == "boolean").assertTrue() - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - } catch (e) { - console.log("fileio_test_stat_is_directory_000 has failed for " + e) - expect(null).assertFail() + let stat = fileio.statSync(fpath); + expect(typeof(stat.isDirectory()) == 'boolean').assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_stat_is_directory_000 has failed for ' + e); + expect(null).assertFail(); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_Stat_isDirectory_0100 @@ -458,17 +493,18 @@ describe('fileIOTestStat', function () { * @tc.desc Function of API, isDirectory. Determine whether it is a directory. The return value is false. */ it('fileio_test_stat_is_directory_001', 0, function () { - let fpath = nextFileName('fileio_test_stat_is_directory_001') - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + let fpath = nextFileName('fileio_test_stat_is_directory_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); try { - let stat = fileio.statSync(fpath) - expect(!stat.isDirectory()).assertTrue() - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - } catch (e) { - console.log("fileio_test_stat_is_directory_001 has failed for " + e) - expect(null).assertFail() + let stat = fileio.statSync(fpath); + expect(!stat.isDirectory()).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_stat_is_directory_001 has failed for ' + e); + expect(null).assertFail(); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_Stat_isDirectory_0200 @@ -477,16 +513,17 @@ describe('fileIOTestStat', function () { */ it('fileio_test_stat_is_directory_002', 0, function () { let dpath = nextFileName('fileio_test_stat_is_directory_002') + 'd' - try { - expect(fileio.mkdirSync(dpath) !== null).assertTrue() - let stat = fileio.statSync(dpath) - expect(stat.isDirectory()).assertTrue() - expect(fileio.rmdirSync(dpath) !== null).assertTrue() - } catch (e) { - console.log("fileio_test_stat_is_directory_002 has failed for " + e) - expect(null).assertFail() - } - }) + try { + expect(fileio.mkdirSync(dpath) !== null).assertTrue(); + let stat = fileio.statSync(dpath); + expect(stat.isDirectory()).assertTrue(); + expect(fileio.rmdirSync(dpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_stat_is_directory_002 has failed for ' + e); + expect(null).assertFail(); + } + }); /** * @tc.number SUB_STORAGE_FileIO_Stat_isDirectory_0300 @@ -496,15 +533,16 @@ describe('fileIOTestStat', function () { it('fileio_test_stat_is_directory_003', 0, function () { let dpath = nextFileName('fileio_test_stat_is_directory_003') + 'd' try { - expect(fileio.mkdirSync(dpath) !== null).assertTrue() - let stat = fileio.statSync(dpath) - expect(stat.isDirectory(-1) == null).assertTrue() - expect(null).assertFail() - } catch (e) { - console.log("fileio_test_stat_is_directory_003 has failed for " + e) - expect(fileio.rmdirSync(dpath) !== null).assertTrue() + expect(fileio.mkdirSync(dpath) !== null).assertTrue(); + let stat = fileio.statSync(dpath); + expect(stat.isDirectory(-1) == null).assertTrue(); + expect(null).assertFail(); + } + catch (e) { + console.log('fileio_test_stat_is_directory_003 has failed for ' + e); + expect(fileio.rmdirSync(dpath) !== null).assertTrue(); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_stat_isFifo_0000 @@ -512,17 +550,18 @@ describe('fileIOTestStat', function () { * @tc.desc Function of API, isFIFO. Determine whether it is a fifo. The return value is Boolean. */ it('fileio_test_stat_is_fifo_000', 0, function () { - let fpath = nextFileName('fileio_test_stat_is_fifo_000') - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + let fpath = nextFileName('fileio_test_stat_is_fifo_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); try { - let stat = fileio.statSync(fpath) - expect(typeof (stat.isFIFO()) == "boolean").assertTrue() - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - } catch (e) { - console.log("fileio_test_stat_is_fifo_000 has failed for " + e) - expect(null).assertFail() + let stat = fileio.statSync(fpath); + expect(typeof(stat.isFIFO()) == 'boolean').assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_stat_is_fifo_000 has failed for ' + e); + expect(null).assertFail(); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_Stat_isFifo_0100 @@ -530,17 +569,18 @@ describe('fileIOTestStat', function () { * @tc.desc Function of API, isFIFO. Determine whether it is a fifo. The return value is false. */ it('fileio_test_stat_is_fifo_001', 0, function () { - let fpath = nextFileName('fileio_test_stat_is_fifo_001') - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + let fpath = nextFileName('fileio_test_stat_is_fifo_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); try { - let stat = fileio.statSync(fpath) - expect(!stat.isFIFO()).assertTrue() - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - } catch (e) { - console.log("fileio_test_stat_is_fifo_001 has failed for " + e) - expect(null).assertFail() + let stat = fileio.statSync(fpath); + expect(!stat.isFIFO()).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_stat_is_fifo_001 has failed for ' + e); + expect(null).assertFail(); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_Stat_isFifo_0200 @@ -548,17 +588,18 @@ describe('fileIOTestStat', function () { * @tc.desc Function of API, isFIFO. The parameter is - 1 */ it('fileio_test_stat_is_fifo_002', 0, function () { - let fpath = nextFileName('fileio_test_stat_is_fifo_002') - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + let fpath = nextFileName('fileio_test_stat_is_fifo_002'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); try { - let stat = fileio.statSync(fpath) - expect(stat.isFIFO(-1) == null).assertTrue() - expect(null).assertFail() - } catch (e) { - console.log("fileio_test_stat_is_fifo_002 has failed for " + e) - expect(fileio.unlinkSync(fpath) !== null).assertTrue() + let stat = fileio.statSync(fpath); + expect(stat.isFIFO(-1) == null).assertTrue(); + expect(null).assertFail(); + } + catch (e) { + console.log('fileio_test_stat_is_fifo_002 has failed for ' + e); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_Stat_isFile_0000 @@ -566,17 +607,18 @@ describe('fileIOTestStat', function () { * @tc.desc Function of API, isFile. Determine whether it is a file. The return value is Boolean. */ it('fileio_test_stat_is_file_000', 0, function () { - let fpath = nextFileName('fileio_test_stat_is_file_000') - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + let fpath = nextFileName('fileio_test_stat_is_file_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); try { - let stat = fileio.statSync(fpath) - expect(typeof (stat.isFile()) == "boolean").assertTrue() - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - } catch (e) { - console.log("fileio_test_stat_is_file_000 has failed for " + e) - expect(null).assertFail() + let stat = fileio.statSync(fpath); + expect(typeof(stat.isFile()) == 'boolean').assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_stat_is_file_000 has failed for ' + e); + expect(null).assertFail(); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_Stat_isFile_0100 @@ -584,18 +626,19 @@ describe('fileIOTestStat', function () { * @tc.desc Function of API, isFile. Determine whether it is a file. The return value is true. */ it('fileio_test_stat_is_file_001', 0, function () { - let fpath = nextFileName('fileio_test_stat_is_file_001') - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + let fpath = nextFileName('fileio_test_stat_is_file_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); try { - let stat = fileio.statSync(fpath) - expect(stat.isFile()).assertTrue() - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - console.log("---fileio_test_stat_is_file_001 is passed!") - } catch (e) { - console.log("fileio_test_stat_is_file_001 has failed for " + e) - expect(null).assertFail() + let stat = fileio.statSync(fpath); + expect(stat.isFile()).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + console.log('---fileio_test_stat_is_file_001 is passed!'); + } + catch (e) { + console.log('fileio_test_stat_is_file_001 has failed for ' + e); + expect(null).assertFail(); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_Stat_isFile_0200 @@ -603,17 +646,18 @@ describe('fileIOTestStat', function () { * @tc.desc Function of API, isFile. Determine whether it is a file. The return value is false. */ it('fileio_test_stat_is_file_002', 0, function () { - let dpath = nextFileName('fileio_test_stat_is_file_002') + let dpath = nextFileName('fileio_test_stat_is_file_002'); try { - expect(fileio.mkdirSync(dpath) !== null).assertTrue() - let stat = fileio.statSync(dpath) - expect(!stat.isFile()).assertTrue() - expect(fileio.rmdirSync(dpath) !== null).assertTrue() - } catch (e) { - console.log("fileio_test_stat_is_file_002 has failed for " + e) - expect(null).assertFail() + expect(fileio.mkdirSync(dpath) !== null).assertTrue(); + let stat = fileio.statSync(dpath); + expect(!stat.isFile()).assertTrue(); + expect(fileio.rmdirSync(dpath) !== null).assertTrue(); } - }) + catch (e) { + console.log('fileio_test_stat_is_file_002 has failed for ' + e); + expect(null).assertFail(); + } + }); /** * @tc.number SUB_STORAGE_FileIO_Stat_isFile_0300 @@ -621,17 +665,18 @@ describe('fileIOTestStat', function () { * @tc.desc Function of API, isFile. The parameter is - 1 */ it('fileio_test_stat_is_file_003', 0, function () { - let dpath = nextFileName('fileio_test_stat_is_file_003') + let dpath = nextFileName('fileio_test_stat_is_file_003'); try { - expect(fileio.mkdirSync(dpath) !== null).assertTrue() - let stat = fileio.statSync(dpath) - expect(stat.isFile(-1) == null).assertTrue() - expect(null).assertFail() - } catch (e) { - expect(fileio.rmdirSync(dpath) !== null).assertTrue() - console.log("fileio_test_stat_is_file_003 has failed for " + e) + expect(fileio.mkdirSync(dpath) !== null).assertTrue(); + let stat = fileio.statSync(dpath); + expect(stat.isFile(-1) == null).assertTrue(); + expect(null).assertFail(); + } + catch (e) { + expect(fileio.rmdirSync(dpath) !== null).assertTrue(); + console.log('fileio_test_stat_is_file_003 has failed for ' + e); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_Stat_isSocket_0000 @@ -639,17 +684,18 @@ describe('fileIOTestStat', function () { * @tc.desc Function of API, isSocket. Determine whether it is a socket. The return value is Boolean. */ it('fileio_test_stat_is_socket_000', 0, function () { - let fpath = nextFileName('fileio_test_stat_is_socket_000') - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + let fpath = nextFileName('fileio_test_stat_is_socket_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); try { - let stat = fileio.statSync(fpath) - expect(typeof (stat.isSocket()) == "boolean").assertTrue() - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - } catch (e) { - console.log("fileio_test_stat_is_socket_000 has failed for " + e) - expect(null).assertFail() + let stat = fileio.statSync(fpath); + expect(typeof(stat.isSocket()) == 'boolean').assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_stat_is_socket_000 has failed for ' + e); + expect(null).assertFail(); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_Stat_isSocket_0100 @@ -657,17 +703,18 @@ describe('fileIOTestStat', function () { * @tc.desc Function of API, isSocket. Determine whether it is a socket. The return value is false. */ it('fileio_test_stat_is_socket_001', 0, function () { - let fpath = nextFileName('fileio_test_stat_is_socket_001') - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + let fpath = nextFileName('fileio_test_stat_is_socket_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); try { - let stat = fileio.statSync(fpath) - expect(!stat.isSocket()).assertTrue() - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - } catch (e) { - console.log("fileio_test_stat_is_socket_001 has failed for " + e) - expect(null).assertFail() + let stat = fileio.statSync(fpath); + expect(!stat.isSocket()).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_stat_is_socket_001 has failed for ' + e); + expect(null).assertFail(); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_Stat_isSocket_0200 @@ -675,17 +722,18 @@ describe('fileIOTestStat', function () { * @tc.desc Function of API, isSocket. The parameter is - 1 */ it('fileio_test_stat_is_socket_002', 0, function () { - let fpath = nextFileName('fileio_test_stat_is_socket_002') - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + let fpath = nextFileName('fileio_test_stat_is_socket_002'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); try { - let stat = fileio.statSync(fpath) - expect(stat.isSocket(-1) == null).assertTrue() - expect(null).assertFail() - } catch (e) { - console.log("fileio_test_stat_is_socket_002 has failed for " + e) - expect(fileio.unlinkSync(fpath) !== null).assertTrue() + let stat = fileio.statSync(fpath); + expect(stat.isSocket(-1) == null).assertTrue(); + expect(null).assertFail(); + } + catch (e) { + console.log('fileio_test_stat_is_socket_002 has failed for ' + e); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_Stat_isSymbolicLink_0000 @@ -693,17 +741,18 @@ describe('fileIOTestStat', function () { * @tc.desc Function of API, isSymbolicLink. Determine whether it is a symbolic link. The return value is Boolean. */ it('fileio_test_stat_is_symbolic_link_000', 0, function () { - let fpath = nextFileName('fileio_test_stat_is_symbolic_link_000') - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + let fpath = nextFileName('fileio_test_stat_is_symbolic_link_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); try { - let stat = fileio.statSync(fpath) - expect(typeof (stat.isSymbolicLink()) == "boolean").assertTrue() - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - } catch (e) { - console.log("fileio_test_stat_is_symbolic_link_000 has failed for " + e) - expect(null).assertFail() + let stat = fileio.statSync(fpath); + expect(typeof(stat.isSymbolicLink()) == 'boolean').assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_stat_is_symbolic_link_000 has failed for ' + e); + expect(null).assertFail(); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_Stat_isSymbolicLink_0100 @@ -711,17 +760,18 @@ describe('fileIOTestStat', function () { * @tc.desc Function of API, isSymbolicLink. Determine whether it is a symbolic link. The return value is false. */ it('fileio_test_stat_is_symbolic_link_001', 0, function () { - let fpath = nextFileName('fileio_test_stat_is_symbolic_link_001') - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + let fpath = nextFileName('fileio_test_stat_is_symbolic_link_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); try { - let stat = fileio.statSync(fpath) - expect(!stat.isSymbolicLink()).assertTrue() - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - } catch (e) { - console.log("fileio_test_stat_is_symbolic_link_001 has failed for " + e) - expect(null).assertFail() + let stat = fileio.statSync(fpath); + expect(!stat.isSymbolicLink()).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_stat_is_symbolic_link_001 has failed for ' + e); + expect(null).assertFail(); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_Stat_isSymbolicLink_0200 @@ -729,15 +779,17 @@ describe('fileIOTestStat', function () { * @tc.desc Function of API, isSymbolicLink. The parameter is - 1 */ it('fileio_test_stat_is_symbolic_link_002', 0, function () { - let fpath = nextFileName('fileio_test_stat_is_symbolic_link_002') - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() - try { - let stat = fileio.statSync(fpath) - expect(stat.isSymbolicLink(-1) == null).assertTrue() - expect(null).assertFail() - } catch (e) { - console.log("fileio_test_stat_is_symbolic_link_002 has failed for " + e) - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - } - }) -}) \ No newline at end of file + let fpath = nextFileName('fileio_test_stat_is_symbolic_link_002'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let stat = fileio.statSync(fpath); + expect(stat.isSymbolicLink(-1) == null).assertTrue(); + expect(null).assertFail(); + } + catch (e) { + console.log('fileio_test_stat_is_symbolic_link_002 has failed for ' + e); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + }); + +}); diff --git a/storage/storagefileiojstest/project/entry/src/main/js/test/FileIOStream.test.js b/storage/storagefileiojstest/project/entry/src/main/js/test/FileIOStream.test.js index ca8b6624e29bcdaf5c99f873a4193cf05b905543..fbf2043ae939ac0344cf9f389af776aafd312557 100644 --- a/storage/storagefileiojstest/project/entry/src/main/js/test/FileIOStream.test.js +++ b/storage/storagefileiojstest/project/entry/src/main/js/test/FileIOStream.test.js @@ -1,23 +1,41 @@ /* * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); + * Licensed under the Apache License, Version 2.0 (the 'License'); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, + * distributed under the License is distributed on an 'AS IS' BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import fileio from '@ohos.fileio'; -import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index' +import file from '@system.file' import { - FILE_CONTENT, prepareFile, fileToReadOnly, fileToWriteOnly, sleep, fileToReadAndWrite, nextFileName, randomString -} from './Common' + describe, + beforeAll, + beforeEach, + afterEach, + afterAll, + it, + expect +} + from 'deccjsunit/index' +import { + FILE_CONTENT, + prepareFile, + fileToReadOnly, + fileToWriteOnly, + sleep, + fileToReadAndWrite, + nextFileName, + randomString +} + from './Common' describe('fileIOTestStream', function () { @@ -27,20 +45,21 @@ describe('fileIOTestStream', function () { * @tc.desc Function of API, mode = r. The test file is exist. */ it('fileio_test_stream_create_stream_sync_000', 0, function () { - let fpath = nextFileName('fileio_test_stream_create_stream_sync_000') - expect(prepareFile(fpath, "")).assertTrue() - expect(fileToReadOnly(fpath)).assertTrue() - try { - let ss = fileio.createStreamSync(fpath, "r") - expect(ss !== null).assertTrue() - expect(ss.closeSync() !== null).assertTrue() - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - console.log("fileio_test_stream_create_stream_sync_000 is passed!") - } catch (e) { - console.log("fileio_test_stream_create_stream_sync_000 has failed for " + e) - expect(null).assertFail() + let fpath = nextFileName('fileio_test_stream_create_stream_sync_000'); + expect(prepareFile(fpath, '')).assertTrue(); + expect(fileToReadOnly(fpath)).assertTrue(); + try { + let ss = fileio.createStreamSync(fpath, 'r'); + expect(ss !== null).assertTrue(); + expect(ss.closeSync() !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + console.log('fileio_test_stream_create_stream_sync_000 is passed!'); + } + catch (e) { + console.log('fileio_test_stream_create_stream_sync_000 has failed for ' + e); + expect(null).assertFail(); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_0100 @@ -48,14 +67,15 @@ describe('fileIOTestStream', function () { * @tc.desc Function of API, mode = r. The test file is not exist. */ it('fileio_test_stream_create_stream_sync_001', 0, function () { - let fpath = nextFileName('fileio_test_stream_create_stream_sync_001') + let fpath = nextFileName('fileio_test_stream_create_stream_sync_001'); try { - expect(fileio.createStreamSync(fpath, "r") == null).assertTrue() - expect(null).assertFail() - } catch (e) { - console.log("fileio_test_stream_create_stream_sync_001 has failed for " + e) + expect(fileio.createStreamSync(fpath, 'r') == null).assertTrue(); + expect(null).assertFail(); + } + catch (e) { + console.log('fileio_test_stream_create_stream_sync_001 has failed for ' + e); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_0200 @@ -63,27 +83,28 @@ describe('fileIOTestStream', function () { * @tc.desc Function of API, mode = w. The test file is exist. */ it('fileio_test_stream_create_stream_sync_002', 0, function () { - let fpath = nextFileName('fileio_test_stream_create_stream_sync_002') - expect(prepareFile(fpath, "")).assertTrue() - expect(fileToWriteOnly(fpath)).assertTrue() - let text = "0123456789abcdefg"; - try { - let ss = fileio.createStreamSync(fpath, "w") - expect(ss !== null).assertTrue() - let wlen = ss.writeSync(text) - expect(wlen !== null).assertTrue() - expect(ss.closeSync() !== null).assertTrue() - expect(fileToReadOnly(fpath)).assertTrue() - ss = fileio.createStreamSync(fpath, "r") - let rlen = ss.readSync(new ArrayBuffer(4096)) - expect(rlen == text.length).assertTrue() - expect(ss.closeSync() !== null).assertTrue() - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - } catch (e) { - console.log("fileio_test_stream_create_stream_sync_002 has failed for " + e) - expect(null).assertFail() - } - }) + let fpath = nextFileName('fileio_test_stream_create_stream_sync_002'); + expect(prepareFile(fpath, '')).assertTrue(); + expect(fileToWriteOnly(fpath)).assertTrue(); + let text = '0123456789abcdefg'; + try { + let ss = fileio.createStreamSync(fpath, 'w'); + expect(ss !== null).assertTrue(); + let wlen = ss.writeSync(text); + expect(wlen !== null).assertTrue(); + expect(ss.closeSync() !== null).assertTrue(); + expect(fileToReadOnly(fpath)).assertTrue(); + ss = fileio.createStreamSync(fpath, 'r'); + let rlen = ss.readSync(new ArrayBuffer(4096)); + expect(rlen == text.length).assertTrue(); + expect(ss.closeSync() !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_stream_create_stream_sync_002 has failed for ' + e); + expect(null).assertFail(); + } + }); /** * @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_0300 @@ -91,17 +112,18 @@ describe('fileIOTestStream', function () { * @tc.desc Function of API, mode = w. The test file is not exist. */ it('fileio_test_stream_create_stream_sync_003', 0, function () { - let fpath = nextFileName('fileio_test_stream_create_stream_sync_003') + let fpath = nextFileName('fileio_test_stream_create_stream_sync_003'); try { - let ss = fileio.createStreamSync(fpath, "w") - expect(ss !== null).assertTrue() - expect(ss.closeSync() !== null).assertTrue() - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - } catch (e) { - console.log("fileio_test_stream_create_stream_sync_003 has failed for " + e) - expect(null).assertFail() + let ss = fileio.createStreamSync(fpath, 'w'); + expect(ss !== null).assertTrue(); + expect(ss.closeSync() !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_stream_create_stream_sync_003 has failed for ' + e); + expect(null).assertFail(); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_0400 @@ -109,28 +131,29 @@ describe('fileIOTestStream', function () { * @tc.desc Function of API, mode = a. The test file is exist. */ it('fileio_test_stream_create_stream_sync_004', 0, function () { - let fpath = nextFileName('fileio_test_stream_create_stream_sync_004') - expect(prepareFile(fpath, "a")).assertTrue() - expect(fileToWriteOnly(fpath)).assertTrue() - let text = "0123456789abcdefg"; - try { - let ss = fileio.createStreamSync(fpath, "a") - expect(ss !== null).assertTrue() - let wlen = ss.writeSync(text) - expect(wlen !== null).assertTrue() - expect(ss.closeSync() !== null).assertTrue() - expect(fileToReadOnly(fpath)).assertTrue() - ss = fileio.createStreamSync(fpath, "r") - let rlen = ss.readSync(new ArrayBuffer(4096)) - expect(rlen == text.length + 1).assertTrue() - expect(ss.closeSync() !== null).assertTrue() - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - } catch (e) { - console.log("fileio_test_stream_create_stream_sync_004 has failed for " + e) - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - expect(null).assertFail() - } - }) + let fpath = nextFileName('fileio_test_stream_create_stream_sync_004'); + expect(prepareFile(fpath, 'a')).assertTrue(); + expect(fileToWriteOnly(fpath)).assertTrue(); + let text = '0123456789abcdefg'; + try { + let ss = fileio.createStreamSync(fpath, 'a'); + expect(ss !== null).assertTrue(); + let wlen = ss.writeSync(text); + expect(wlen !== null).assertTrue(); + expect(ss.closeSync() !== null).assertTrue(); + expect(fileToReadOnly(fpath)).assertTrue(); + ss = fileio.createStreamSync(fpath, 'r'); + let rlen = ss.readSync(new ArrayBuffer(4096)); + expect(rlen == text.length + 1).assertTrue(); + expect(ss.closeSync() !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_stream_create_stream_sync_004 has failed for ' + e); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + expect(null).assertFail(); + } + }); /** * @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_0500 @@ -138,17 +161,18 @@ describe('fileIOTestStream', function () { * @tc.desc Function of API, mode = a. The test file is not exist. */ it('fileio_test_stream_create_stream_sync_005', 0, function () { - let fpath = nextFileName('fileio_test_stream_create_stream_sync_005') + let fpath = nextFileName('fileio_test_stream_create_stream_sync_005'); try { - let ss = fileio.createStreamSync(fpath, "a") - expect(ss !== null).assertTrue() - expect(ss.closeSync() !== null).assertTrue() - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - } catch (e) { - console.log("fileio_test_stream_create_stream_sync_005 has failed for " + e) - expect(null).assertFail() + let ss = fileio.createStreamSync(fpath, 'a'); + expect(ss !== null).assertTrue(); + expect(ss.closeSync() !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); } - }) + catch (e) { + console.log('fileio_test_stream_create_stream_sync_005 has failed for ' + e); + expect(null).assertFail(); + } + }); /** * @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_0600 @@ -156,18 +180,19 @@ describe('fileIOTestStream', function () { * @tc.desc Function of API, mode = r+. The test file is exist. */ it('fileio_test_stream_create_stream_sync_006', 0, function () { - let fpath = nextFileName('fileio_test_stream_create_stream_sync_006') - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() - try { - let ss = fileio.createStreamSync(fpath, "r+") - expect(ss !== null).assertTrue() - expect(ss.closeSync() !== null).assertTrue() - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - } catch (e) { - console.log("fileio_test_stream_create_stream_sync_006 has failed for " + e) - expect(null).assertFail() + let fpath = nextFileName('fileio_test_stream_create_stream_sync_006'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let ss = fileio.createStreamSync(fpath, 'r+'); + expect(ss !== null).assertTrue(); + expect(ss.closeSync() !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_stream_create_stream_sync_006 has failed for ' + e); + expect(null).assertFail(); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_0700 @@ -175,14 +200,15 @@ describe('fileIOTestStream', function () { * @tc.desc Function of API, mode = r+. The test file is not exist. */ it('fileio_test_stream_create_stream_sync_007', 0, function () { - let fpath = nextFileName('fileio_test_stream_create_stream_sync_007') + let fpath = nextFileName('fileio_test_stream_create_stream_sync_007'); try { - fileio.createStreamSync(fpath, "r+") - expect(null).assertFail() - } catch (e) { - console.log("fileio_test_stream_create_stream_sync_007 has failed for " + e) + fileio.createStreamSync(fpath, 'r+'); + expect(null).assertFail(); + } + catch (e) { + console.log('fileio_test_stream_create_stream_sync_007 has failed for ' + e); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_0800 @@ -190,26 +216,27 @@ describe('fileIOTestStream', function () { * @tc.desc Function of API, mode = w+. The test file is exist. */ it('fileio_test_stream_create_stream_sync_008', 0, function () { - let fpath = nextFileName('fileio_test_stream_create_stream_sync_008') - expect(prepareFile(fpath, "")).assertTrue() - let text = "0123456789abcdefg"; - try { - let ss = fileio.createStreamSync(fpath, "w+") - expect(ss !== null).assertTrue() - let wlen = ss.writeSync(text) - expect(wlen !== null).assertTrue() - expect(ss.closeSync() !== null).assertTrue() - expect(fileToReadOnly(fpath)).assertTrue() - ss = fileio.createStreamSync(fpath, "r") - let rlen = ss.readSync(new ArrayBuffer(4096)) - expect(rlen == text.length).assertTrue() - expect(ss.closeSync() !== null).assertTrue() - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - } catch (e) { - console.log("fileio_test_stream_create_stream_sync_008 has failed for " + e) - expect(null).assertFail() - } - }) + let fpath = nextFileName('fileio_test_stream_create_stream_sync_008'); + expect(prepareFile(fpath, '')).assertTrue(); + let text = '0123456789abcdefg'; + try { + let ss = fileio.createStreamSync(fpath, 'w+'); + expect(ss !== null).assertTrue(); + let wlen = ss.writeSync(text); + expect(wlen !== null).assertTrue(); + expect(ss.closeSync() !== null).assertTrue(); + expect(fileToReadOnly(fpath)).assertTrue(); + ss = fileio.createStreamSync(fpath, 'r'); + let rlen = ss.readSync(new ArrayBuffer(4096)); + expect(rlen == text.length).assertTrue(); + expect(ss.closeSync() !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_stream_create_stream_sync_008 has failed for ' + e); + expect(null).assertFail(); + } + }); /** * @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_0900 @@ -217,17 +244,18 @@ describe('fileIOTestStream', function () { * @tc.desc Function of API, mode = w+. The test file is not exist. */ it('fileio_test_stream_create_stream_sync_009', 0, function () { - let fpath = nextFileName('fileio_test_stream_create_stream_sync_009') + let fpath = nextFileName('fileio_test_stream_create_stream_sync_009'); try { - let ss = fileio.createStreamSync(fpath, "w+") - expect(ss !== null).assertTrue() - expect(ss.closeSync() !== null).assertTrue() - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - } catch (e) { - console.log("fileio_test_stream_create_stream_sync_009 has failed for " + e) - expect(null).assertFail() + let ss = fileio.createStreamSync(fpath, 'w+'); + expect(ss !== null).assertTrue(); + expect(ss.closeSync() !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_stream_create_stream_sync_009 has failed for ' + e); + expect(null).assertFail(); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_1000 @@ -235,405 +263,425 @@ describe('fileIOTestStream', function () { * @tc.desc Function of API, mode = a+. The test file is exist. */ it('fileio_test_stream_create_stream_sync_010', 0, function () { - let fpath = nextFileName('fileio_test_stream_create_stream_sync_010') - expect(prepareFile(fpath, "a")).assertTrue() - let text = "0123456789abcdefg"; - try { - let ss = fileio.createStreamSync(fpath, "a+") - expect(ss !== null).assertTrue() - let wlen = ss.writeSync(text) - expect(wlen !== null).assertTrue() - expect(ss.closeSync() !== null).assertTrue() - expect(fileToReadOnly(fpath)).assertTrue() - ss = fileio.createStreamSync(fpath, "r") - let rlen = ss.readSync(new ArrayBuffer(4096)) - expect(rlen == text.length + 1).assertTrue() - expect(ss.closeSync() !== null).assertTrue() - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - } catch (e) { - console.log("fileio_test_stream_create_stream_sync_010 has failed for " + e) - expect(null).assertFail() - } - }) - - /** - * @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_1100 - * @tc.name fileio_test_stream_create_stream_sync_011 - * @tc.desc Function of API, mode = a+. The test file is not exist. - */ + let fpath = nextFileName('fileio_test_stream_create_stream_sync_010'); + expect(prepareFile(fpath, 'a')).assertTrue(); + let text = '0123456789abcdefg'; + try { + let ss = fileio.createStreamSync(fpath, 'a+'); + expect(ss !== null).assertTrue(); + let wlen = ss.writeSync(text); + expect(wlen !== null).assertTrue(); + expect(ss.closeSync() !== null).assertTrue(); + expect(fileToReadOnly(fpath)).assertTrue(); + ss = fileio.createStreamSync(fpath, 'r'); + let rlen = ss.readSync(new ArrayBuffer(4096)); + expect(rlen == text.length + 1).assertTrue(); + expect(ss.closeSync() !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_stream_create_stream_sync_010 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_1100 + * @tc.name fileio_test_stream_create_stream_sync_011 + * @tc.desc Function of API, mode = a+. The test file is not exist. + */ it('fileio_test_stream_create_stream_sync_011', 0, function () { - let fpath = nextFileName('fileio_test_stream_create_stream_sync_011') + let fpath = nextFileName('fileio_test_stream_create_stream_sync_011'); try { - let ss = fileio.createStreamSync(fpath, "a+") - expect(ss !== null).assertTrue() - expect(ss.closeSync() !== null).assertTrue() - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - } catch (e) { - console.log("fileio_test_stream_create_stream_sync_011 has failed for " + e) - expect(null).assertFail() + let ss = fileio.createStreamSync(fpath, 'a+'); + expect(ss !== null).assertTrue(); + expect(ss.closeSync() !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); } - }) + catch (e) { + console.log('fileio_test_stream_create_stream_sync_011 has failed for ' + e); + expect(null).assertFail(); + } + }); /** - * @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_1200 - * @tc.name fileio_test_stream_create_stream_sync_012 - * @tc.desc Function of API, mode = ab. The test file is exist. - */ + * @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_1200 + * @tc.name fileio_test_stream_create_stream_sync_012 + * @tc.desc Function of API, mode = ab. The test file is exist. + */ it('fileio_test_stream_create_stream_sync_012', 0, function () { - let fpath = nextFileName('fileio_test_stream_create_stream_sync_012') - expect(prepareFile(fpath, "")).assertTrue() - expect(fileToReadOnly(fpath)).assertTrue() - try { - let ss = fileio.createStreamSync(fpath, "rb") - expect(ss !== null).assertTrue() - expect(ss.closeSync() !== null).assertTrue() - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - } catch (e) { - console.log("fileio_test_stream_create_stream_sync_012 has failed for " + e) - expect(null).assertFail() - } - }) - - /** - * @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_1300 - * @tc.name fileio_test_stream_create_stream_sync_013 - * @tc.desc Function of API, mode = ab. The test file is not exist. - */ + let fpath = nextFileName('fileio_test_stream_create_stream_sync_012'); + expect(prepareFile(fpath, '')).assertTrue(); + expect(fileToReadOnly(fpath)).assertTrue(); + try { + let ss = fileio.createStreamSync(fpath, 'rb'); + expect(ss !== null).assertTrue(); + expect(ss.closeSync() !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_stream_create_stream_sync_012 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_1300 + * @tc.name fileio_test_stream_create_stream_sync_013 + * @tc.desc Function of API, mode = ab. The test file is not exist. + */ it('fileio_test_stream_create_stream_sync_013', 0, function () { - let fpath = nextFileName('fileio_test_stream_create_stream_sync_013') + let fpath = nextFileName('fileio_test_stream_create_stream_sync_013'); try { - fileio.createStreamSync(fpath, "rb") - expect(null).assertFail() - } catch (e) { - console.log("fileio_test_stream_create_stream_sync_013 has failed for " + e) + fileio.createStreamSync(fpath, 'rb'); + expect(null).assertFail(); } - }) + catch (e) { + console.log('fileio_test_stream_create_stream_sync_013 has failed for ' + e); + } + }); /** - * @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_1400 - * @tc.name fileio_test_stream_create_stream_sync_014 - * @tc.desc Function of API, mode = wb. The test file is exist. - */ + * @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_1400 + * @tc.name fileio_test_stream_create_stream_sync_014 + * @tc.desc Function of API, mode = wb. The test file is exist. + */ it('fileio_test_stream_create_stream_sync_014', 0, function () { - let fpath = nextFileName('fileio_test_stream_create_stream_sync_014') - expect(prepareFile(fpath, "")).assertTrue() - expect(fileToWriteOnly(fpath)).assertTrue() - let text = "0123456789abcdefg"; - try { - let ss = fileio.createStreamSync(fpath, "wb") - expect(ss !== null).assertTrue() - let wlen = ss.writeSync(text) - expect(wlen !== null).assertTrue() - expect(ss.closeSync() !== null).assertTrue() - expect(fileToReadOnly(fpath)).assertTrue() - ss = fileio.createStreamSync(fpath, "r") - let rlen = ss.readSync(new ArrayBuffer(4096)) - expect(rlen == text.length).assertTrue() - expect(ss.closeSync() !== null).assertTrue() - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - } catch (e) { - console.log("fileio_test_stream_create_stream_sync_014 has failed for " + e) - expect(null).assertFail() - } - }) - - /** - * @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_1500 - * @tc.name fileio_test_stream_create_stream_sync_015 - * @tc.desc Function of API, mode = wb. The test file is not exist. - */ + let fpath = nextFileName('fileio_test_stream_create_stream_sync_014'); + expect(prepareFile(fpath, '')).assertTrue(); + expect(fileToWriteOnly(fpath)).assertTrue(); + let text = '0123456789abcdefg'; + try { + let ss = fileio.createStreamSync(fpath, 'wb'); + expect(ss !== null).assertTrue(); + let wlen = ss.writeSync(text); + expect(wlen !== null).assertTrue(); + expect(ss.closeSync() !== null).assertTrue(); + expect(fileToReadOnly(fpath)).assertTrue(); + ss = fileio.createStreamSync(fpath, 'r'); + let rlen = ss.readSync(new ArrayBuffer(4096)); + expect(rlen == text.length).assertTrue(); + expect(ss.closeSync() !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_stream_create_stream_sync_014 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_1500 + * @tc.name fileio_test_stream_create_stream_sync_015 + * @tc.desc Function of API, mode = wb. The test file is not exist. + */ it('fileio_test_stream_create_stream_sync_015', 0, function () { - let fpath = nextFileName('fileio_test_stream_create_stream_sync_015') + let fpath = nextFileName('fileio_test_stream_create_stream_sync_015'); try { - let ss = fileio.createStreamSync(fpath, "wb") - expect(ss !== null).assertTrue() - expect(ss.closeSync() !== null).assertTrue() - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - } catch (e) { - console.log("fileio_test_stream_create_stream_sync_015 has failed for " + e) - expect(null).assertFail() + let ss = fileio.createStreamSync(fpath, 'wb'); + expect(ss !== null).assertTrue(); + expect(ss.closeSync() !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_stream_create_stream_sync_015 has failed for ' + e); + expect(null).assertFail(); } - }) + }); /** - * @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_1600 - * @tc.name fileio_test_stream_create_stream_sync_016 - * @tc.desc Function of API, mode = ab. The test file is exist. - */ + * @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_1600 + * @tc.name fileio_test_stream_create_stream_sync_016 + * @tc.desc Function of API, mode = ab. The test file is exist. + */ it('fileio_test_stream_create_stream_sync_016', 0, function () { - let fpath = nextFileName('fileio_test_stream_create_stream_sync_016') - expect(prepareFile(fpath, "a")).assertTrue() - expect(fileToWriteOnly(fpath)).assertTrue() - let text = "0123456789abcdefg"; - try { - let ss = fileio.createStreamSync(fpath, "ab") - expect(ss !== null).assertTrue() - let wlen = ss.writeSync(text) - expect(wlen !== null).assertTrue() - expect(ss.closeSync() !== null).assertTrue() - expect(fileToReadOnly(fpath)).assertTrue() - ss = fileio.createStreamSync(fpath, "r") - let rlen = ss.readSync(new ArrayBuffer(4096)) - expect(rlen == text.length + 1).assertTrue() - expect(ss.closeSync() !== null).assertTrue() - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - console.log("fileio_test_stream_create_stream_sync_016 is passed!") - } catch (e) { - console.log("fileio_test_stream_create_stream_sync_016 has failed for " + e) - expect(null).assertFail() - } - }) - - /** - * @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_1700 - * @tc.name fileio_test_stream_create_stream_sync_017 - * @tc.desc Function of API, mode = ab. The test file is not exist. - */ + let fpath = nextFileName('fileio_test_stream_create_stream_sync_016'); + expect(prepareFile(fpath, 'a')).assertTrue(); + expect(fileToWriteOnly(fpath)).assertTrue(); + let text = '0123456789abcdefg'; + try { + let ss = fileio.createStreamSync(fpath, 'ab'); + expect(ss !== null).assertTrue(); + let wlen = ss.writeSync(text); + expect(wlen !== null).assertTrue(); + expect(ss.closeSync() !== null).assertTrue(); + expect(fileToReadOnly(fpath)).assertTrue(); + ss = fileio.createStreamSync(fpath, 'r'); + let rlen = ss.readSync(new ArrayBuffer(4096)); + expect(rlen == text.length + 1).assertTrue(); + expect(ss.closeSync() !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + console.log('fileio_test_stream_create_stream_sync_016 is passed!'); + } + catch (e) { + console.log('fileio_test_stream_create_stream_sync_016 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_1700 + * @tc.name fileio_test_stream_create_stream_sync_017 + * @tc.desc Function of API, mode = ab. The test file is not exist. + */ it('fileio_test_stream_create_stream_sync_017', 0, function () { - let fpath = nextFileName('fileio_test_stream_create_stream_sync_017') + let fpath = nextFileName('fileio_test_stream_create_stream_sync_017'); try { - let ss = fileio.createStreamSync(fpath, "ab") - expect(ss !== null).assertTrue() - expect(ss.closeSync() !== null).assertTrue() - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - } catch (e) { - console.log("fileio_test_stream_create_stream_sync_017 has failed for " + e) - expect(null).assertFail() + let ss = fileio.createStreamSync(fpath, 'ab'); + expect(ss !== null).assertTrue(); + expect(ss.closeSync() !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_stream_create_stream_sync_017 has failed for ' + e); + expect(null).assertFail(); } - }) + }); /** - * @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_1800 - * @tc.name fileio_test_stream_create_stream_sync_018 - * @tc.desc Function of API, mode = rb+. The test file is exist. - */ + * @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_1800 + * @tc.name fileio_test_stream_create_stream_sync_018 + * @tc.desc Function of API, mode = rb+. The test file is exist. + */ it('fileio_test_stream_create_stream_sync_018', 0, function () { - let fpath = nextFileName('fileio_test_stream_create_stream_sync_018') - expect(prepareFile(fpath, "")).assertTrue() - try { - let ss = fileio.createStreamSync(fpath, "rb+") - expect(ss !== null).assertTrue() - expect(ss.closeSync() !== null).assertTrue() - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - } catch (e) { - console.log("fileio_test_stream_create_stream_sync_018 has failed for " + e) - expect(null).assertFail() + let fpath = nextFileName('fileio_test_stream_create_stream_sync_018'); + expect(prepareFile(fpath, '')).assertTrue(); + try { + let ss = fileio.createStreamSync(fpath, 'rb+'); + expect(ss !== null).assertTrue(); + expect(ss.closeSync() !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_stream_create_stream_sync_018 has failed for ' + e); + expect(null).assertFail(); } - }) + }); /** - * @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_1900 - * @tc.name fileio_test_stream_create_stream_sync_019 - * @tc.desc Function of API, mode = rb+. The test file is not exist. - */ + * @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_1900 + * @tc.name fileio_test_stream_create_stream_sync_019 + * @tc.desc Function of API, mode = rb+. The test file is not exist. + */ it('fileio_test_stream_create_stream_sync_019', 0, function () { - let fpath = nextFileName('fileio_test_stream_create_stream_sync_019') + let fpath = nextFileName('fileio_test_stream_create_stream_sync_019'); try { - fileio.createStreamSync(fpath, "rb+") - expect(null).assertFail() - } catch (e) { - console.log("fileio_test_stream_create_stream_sync_019 has failed for " + e) + fileio.createStreamSync(fpath, 'rb+'); + expect(null).assertFail(); + } + catch (e) { + console.log('fileio_test_stream_create_stream_sync_019 has failed for ' + e); } - }) + }); /** - * @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_2000 - * @tc.name fileio_test_stream_create_stream_sync_020 - * @tc.desc Function of API, mode = wb+. The test file is exist. - */ + * @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_2000 + * @tc.name fileio_test_stream_create_stream_sync_020 + * @tc.desc Function of API, mode = wb+. The test file is exist. + */ it('fileio_test_stream_create_stream_sync_020', 0, function () { - let fpath = nextFileName('fileio_test_stream_create_stream_sync_020') - expect(prepareFile(fpath, "")).assertTrue() - let text = "0123456789abcdefg"; - try { - let ss = fileio.createStreamSync(fpath, "wb+") - expect(ss !== null).assertTrue() - let wlen = ss.writeSync(text) - expect(wlen !== null).assertTrue() - expect(ss.closeSync() !== null).assertTrue() - expect(fileToReadOnly(fpath)).assertTrue() - ss = fileio.createStreamSync(fpath, "r") - let rlen = ss.readSync(new ArrayBuffer(4096)) - expect(rlen == text.length).assertTrue() - expect(ss.closeSync() !== null).assertTrue() - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - } catch (e) { - console.log("fileio_test_stream_create_stream_sync_020 has failed for " + e) - expect(null).assertFail() - } - }) - - /** - * @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_2100 - * @tc.name fileio_test_stream_create_stream_sync_021 - * @tc.desc Function of API, mode = wb+. The test file is not exist. - */ + let fpath = nextFileName('fileio_test_stream_create_stream_sync_020'); + expect(prepareFile(fpath, '')).assertTrue(); + let text = '0123456789abcdefg'; + try { + let ss = fileio.createStreamSync(fpath, 'wb+'); + expect(ss !== null).assertTrue(); + let wlen = ss.writeSync(text); + expect(wlen !== null).assertTrue(); + expect(ss.closeSync() !== null).assertTrue(); + expect(fileToReadOnly(fpath)).assertTrue(); + ss = fileio.createStreamSync(fpath, 'r'); + let rlen = ss.readSync(new ArrayBuffer(4096)); + expect(rlen == text.length).assertTrue(); + expect(ss.closeSync() !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_stream_create_stream_sync_020 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_2100 + * @tc.name fileio_test_stream_create_stream_sync_021 + * @tc.desc Function of API, mode = wb+. The test file is not exist. + */ it('fileio_test_stream_create_stream_sync_021', 0, function () { - let fpath = nextFileName('fileio_test_stream_create_stream_sync_021') + let fpath = nextFileName('fileio_test_stream_create_stream_sync_021'); try { - let ss = fileio.createStreamSync(fpath, "wb+") - expect(ss !== null).assertTrue() - expect(ss.closeSync() !== null).assertTrue() - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - } catch (e) { - console.log("fileio_test_stream_create_stream_sync_021 has failed for " + e) - expect(null).assertFail() + let ss = fileio.createStreamSync(fpath, 'wb+'); + expect(ss !== null).assertTrue(); + expect(ss.closeSync() !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); } - }) + catch (e) { + console.log('fileio_test_stream_create_stream_sync_021 has failed for ' + e); + expect(null).assertFail(); + } + }); /** - * @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_2200 - * @tc.name fileio_test_stream_create_stream_sync_022 - * @tc.desc Function of API, mode = ab+. The test file is exist. - */ + * @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_2200 + * @tc.name fileio_test_stream_create_stream_sync_022 + * @tc.desc Function of API, mode = ab+. The test file is exist. + */ it('fileio_test_stream_create_stream_sync_022', 0, function () { - let fpath = nextFileName('fileio_test_stream_create_stream_sync_022') - expect(prepareFile(fpath, "a")).assertTrue() - let text = "0123456789abcdefg"; - try { - let ss = fileio.createStreamSync(fpath, "ab+") - expect(ss !== null).assertTrue() - let wlen = ss.writeSync(text) - expect(wlen !== null).assertTrue() - expect(ss.closeSync() !== null).assertTrue() - expect(fileToReadOnly(fpath)).assertTrue() - ss = fileio.createStreamSync(fpath, "r") - let rlen = ss.readSync(new ArrayBuffer(4096)) - expect(rlen == text.length + 1).assertTrue() - expect(ss.closeSync() !== null).assertTrue() - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - } catch (e) { - console.log("fileio_test_stream_create_stream_sync_022 has failed for " + e) - expect(null).assertFail() - } - }) - - /** - * @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_2300 - * @tc.name fileio_test_stream_create_stream_sync_023 - * @tc.desc Function of API, mode = ab+. The test file is not exist. - */ + let fpath = nextFileName('fileio_test_stream_create_stream_sync_022'); + expect(prepareFile(fpath, 'a')).assertTrue(); + let text = '0123456789abcdefg'; + try { + let ss = fileio.createStreamSync(fpath, 'ab+'); + expect(ss !== null).assertTrue(); + let wlen = ss.writeSync(text); + expect(wlen !== null).assertTrue(); + expect(ss.closeSync() !== null).assertTrue(); + expect(fileToReadOnly(fpath)).assertTrue(); + ss = fileio.createStreamSync(fpath, 'r'); + let rlen = ss.readSync(new ArrayBuffer(4096)); + expect(rlen == text.length + 1).assertTrue(); + expect(ss.closeSync() !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_stream_create_stream_sync_022 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_2300 + * @tc.name fileio_test_stream_create_stream_sync_023 + * @tc.desc Function of API, mode = ab+. The test file is not exist. + */ it('fileio_test_stream_create_stream_sync_023', 0, function () { - let fpath = nextFileName('fileio_test_stream_create_stream_sync_023') + let fpath = nextFileName('fileio_test_stream_create_stream_sync_023'); try { - let ss = fileio.createStreamSync(fpath, "ab+") - expect(ss !== null).assertTrue() - expect(ss.closeSync() !== null).assertTrue() - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - } catch (e) { - console.log("fileio_test_stream_create_stream_sync_023 has failed for " + e) - expect(null).assertFail() + let ss = fileio.createStreamSync(fpath, 'ab+'); + expect(ss !== null).assertTrue(); + expect(ss.closeSync() !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); } - }) + catch (e) { + console.log('fileio_test_stream_create_stream_sync_023 has failed for ' + e); + expect(null).assertFail(); + } + }); /** - * @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_2400 - * @tc.name fileio_test_stream_create_stream_sync_024 - * @tc.desc Function of API, invaild fpath. - */ + * @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_2400 + * @tc.name fileio_test_stream_create_stream_sync_024 + * @tc.desc Function of API, invaild fpath. + */ it('fileio_test_stream_create_stream_sync_024', 0, function () { try { - fileio.createStreamSync("", "r") - expect(null).assertFail() - } catch (e) { - console.log("fileio_test_stream_create_stream_sync_024 is passed!" + e) + fileio.createStreamSync('', 'r'); + expect(null).assertFail(); + } + catch (e) { + console.log('fileio_test_stream_create_stream_sync_024 is passed!' + e); } - }) + }); /** - * @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_2500 - * @tc.name fileio_test_stream_create_stream_sync_025 - * @tc.desc Function of API, invaild mode. - */ + * @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_2500 + * @tc.name fileio_test_stream_create_stream_sync_025 + * @tc.desc Function of API, invaild mode. + */ it('fileio_test_stream_create_stream_sync_025', 0, function () { - let fpath = nextFileName('fileio_test_stream_create_stream_sync_025') - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + let fpath = nextFileName('fileio_test_stream_create_stream_sync_025'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); try { - fileio.createStreamSync(fpath, "") - expect(null).assertFail() - } catch (e) { - console.log("fileio_test_stream_create_stream_sync_025 is passed!" + e) - expect(fileio.unlinkSync(fpath) !== null).assertTrue() + fileio.createStreamSync(fpath, ''); + expect(null).assertFail(); + } + catch (e) { + console.log('fileio_test_stream_create_stream_sync_025 is passed!' + e); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); } - }) + }); /** - * @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_2600 - * @tc.name fileio_test_stream_create_stream_sync_026 - * @tc.desc Function of API, fpath too long. - */ + * @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_2600 + * @tc.name fileio_test_stream_create_stream_sync_026 + * @tc.desc Function of API, fpath too long. + */ it('fileio_test_stream_create_stream_sync_026', 0, function () { - let dpath = nextFileName("fileio_stream") - fileio.mkdirSync(dpath) + let dpath = nextFileName('fileio_stream'); + fileio.mkdirSync(dpath); try { for (let i = 0; i < 16; i++) { if (i == 15) { - let fpath = dpath + "/f" + randomString(248) - fileio.createStreamSync(fpath, "w+") + let fpath = dpath + '/f' + randomString(248); + fileio.createStreamSync(fpath, 'w+'); } else { - dpath = dpath + "/d" + randomString(248) - fileio.mkdirSync(dpath) + dpath = dpath + '/d' + randomString(248); + fileio.mkdirSync(dpath); } } - expect(null).assertFail() - } catch (e) { - console.log("fileio_test_stream_create_stream_sync_026 has failed for " + e) + expect(null).assertFail(); + } + catch (e) { + console.log('fileio_test_stream_create_stream_sync_026 has failed for ' + e); } - }) + }); /** - * @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_2700 - * @tc.name fileio_test_stream_create_stream_sync_027 - * @tc.desc Function of API, filename too long. - */ + * @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_2700 + * @tc.name fileio_test_stream_create_stream_sync_027 + * @tc.desc Function of API, filename too long. + */ it('fileio_test_stream_create_stream_sync_027', 0, function () { - let fpath = nextFileName(randomString(256)) + let fpath = nextFileName(randomString(256)); try { - fileio.createStreamSync(fpath, "w+") - expect(null).assertFail() - } catch (e) { - console.log("fileio_test_stream_create_stream_sync_027 has failed for " + e) + fileio.createStreamSync(fpath, 'w+'); + expect(null).assertFail(); + } + catch (e) { + console.log('fileio_test_stream_create_stream_sync_027 has failed for ' + e); } - }) + }); /** - * @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_2800 - * @tc.name fileio_test_stream_create_stream_sync_028 - * @tc.desc Function of API, path too deep. - */ + * @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_2800 + * @tc.name fileio_test_stream_create_stream_sync_028 + * @tc.desc Function of API, path too deep. + */ it('fileio_test_stream_create_stream_sync_028', 0, function () { - let dpath = nextFileName("stream") - fileio.mkdirSync(dpath) + let dpath = nextFileName('stream'); + fileio.mkdirSync(dpath); try { for (let i = 0; i < 113; i++) { if (i == 112) { - let fpath = dpath + "/f" + i - fileio.createStreamSync(fpath, "w+") + let fpath = dpath + '/f' + i + fileio.createStreamSync(fpath, 'w+'); } else { - dpath = dpath + "/" + i - fileio.mkdirSync(dpath) + dpath = dpath + '/' + i + fileio.mkdirSync(dpath); } } - expect(null).assertFail() - } catch (e) { - console.log("fileio_test_stream_create_stream_sync_028 has failed for " + e) + expect(null).assertFail(); + } + catch (e) { + console.log('fileio_test_stream_create_stream_sync_028 has failed for ' + e); } - }) - + }); + /** - * @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_2900 - * @tc.name fileio_test_stream_create_stream_sync_029 - * @tc.desc Function of API, special character. - */ + * @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_2900 + * @tc.name fileio_test_stream_create_stream_sync_029 + * @tc.desc Function of API, special character. + */ it('fileio_test_stream_create_stream_sync_029', 0, function () { - let fpath = nextFileName("?*:<>/|") + let fpath = nextFileName('?*:<>/|'); try { - fileio.createStreamSync(fpath, "w+") - expect(null).assertFail() - } catch (e) { - console.log("fileio_test_stream_create_stream_sync_029 has failed for " + e) + fileio.createStreamSync(fpath, 'w+'); + expect(null).assertFail(); } - }) + catch (e) { + console.log('fileio_test_stream_create_stream_sync_029 has failed for ' + e); + } + }); /** * @tc.number SUB_STORAGE_FileIO_stream_FdopenStreamSync_0000 @@ -641,22 +689,22 @@ describe('fileIOTestStream', function () { * @tc.desc Function of API, mode=r. The test file is exist. */ it('fileio_test_stream_fdopen_stream_sync_000', 0, function () { - let fpath = nextFileName('fileio_test_stream_fdopen_stream_sync_000') - expect(prepareFile(fpath, "")).assertTrue() - expect(fileToReadOnly(fpath)).assertTrue() - - try { - let fd = fileio.openSync(fpath, 0o0) - let ss = fileio.fdopenStreamSync(fd, "r") - expect(ss !== null).assertTrue() - expect(fileio.closeSync(fd) !== null).assertTrue() - expect(ss.closeSync() !== null).assertTrue() - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - } catch (e) { - console.log("fileio_test_stream_fdopen_stream_sync_000 has failed for " + e) - expect(null).assertFail() + let fpath = nextFileName('fileio_test_stream_fdopen_stream_sync_000'); + expect(prepareFile(fpath, '')).assertTrue(); + expect(fileToReadOnly(fpath)).assertTrue(); + try { + let fd = fileio.openSync(fpath, 0o0); + let ss = fileio.fdopenStreamSync(fd, 'r'); + expect(ss !== null).assertTrue(); + expect(fileio.closeSync(fd) !== null).assertTrue(); + expect(ss.closeSync() !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_stream_fdopen_stream_sync_000 has failed for ' + e); + expect(null).assertFail(); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_stream_FdopenStreamSync_0100 @@ -665,12 +713,13 @@ describe('fileIOTestStream', function () { */ it('fileio_test_stream_fdopen_stream_sync_001', 0, function () { try { - expect(fileio.fdopenStreamSync(-1, "r") == null).assertTrue() - expect(null).assertFail() - } catch (e) { - console.log("fileio_test_stream_fdopen_stream_sync_001 has failed for " + e) + expect(fileio.fdopenStreamSync(-1, 'r') == null).assertTrue(); + expect(null).assertFail(); + } + catch (e) { + console.log('fileio_test_stream_fdopen_stream_sync_001 has failed for ' + e); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_stream_FdopenStreamSync_0200 @@ -678,31 +727,32 @@ describe('fileIOTestStream', function () { * @tc.desc Function of API, mode=w. The test file is exist. */ it('fileio_test_stream_fdopen_stream_sync_002', 0, function () { - let fpath = nextFileName('fileio_test_stream_fdopen_stream_sync_002') + let fpath = nextFileName('fileio_test_stream_fdopen_stream_sync_002'); let fd; - expect(prepareFile(fpath, "")).assertTrue() - expect(fileToWriteOnly(fpath)).assertTrue() - let text = "0123456789abcdefg"; - try { - fd = fileio.openSync(fpath, 0o001) - expect(fd !== null).assertTrue() - let ss = fileio.fdopenStreamSync(fd, "w") - expect(ss !== null).assertTrue() - let wlen = ss.writeSync(text) - expect(wlen !== null).assertTrue() - expect(ss.closeSync() !== null).assertTrue() - expect(fileToReadOnly(fpath)).assertTrue() - ss = fileio.createStreamSync(fpath, "r") - let rlen = ss.readSync(new ArrayBuffer(4096)) - expect(rlen == text.length).assertTrue() - expect(fileio.closeSync(fd) !== null).assertTrue() - expect(ss.closeSync() !== null).assertTrue() - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - } catch (e) { - console.log("fileio_test_stream_fdopen_stream_sync_002 has failed for " + e) - expect(null).assertFail() - } - }) + expect(prepareFile(fpath, '')).assertTrue(); + expect(fileToWriteOnly(fpath)).assertTrue(); + let text = '0123456789abcdefg'; + try { + fd = fileio.openSync(fpath, 0o001); + expect(fd !== null).assertTrue(); + let ss = fileio.fdopenStreamSync(fd, 'w'); + expect(ss !== null).assertTrue(); + let wlen = ss.writeSync(text); + expect(wlen !== null).assertTrue(); + expect(ss.closeSync() !== null).assertTrue(); + expect(fileToReadOnly(fpath)).assertTrue(); + ss = fileio.createStreamSync(fpath, 'r'); + let rlen = ss.readSync(new ArrayBuffer(4096)); + expect(rlen == text.length).assertTrue(); + expect(fileio.closeSync(fd) !== null).assertTrue(); + expect(ss.closeSync() !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_stream_fdopen_stream_sync_002 has failed for ' + e); + expect(null).assertFail(); + } + }); /** * @tc.number SUB_STORAGE_FileIO_stream_FdopenStreamSync_0300 @@ -710,19 +760,20 @@ describe('fileIOTestStream', function () { * @tc.desc Function of API, mode=w. The test file is not exist. */ it('fileio_test_stream_fdopen_stream_sync_003', 0, function () { - let fpath = nextFileName('fileio_test_stream_fdopen_stream_sync_003') + let fpath = nextFileName('fileio_test_stream_fdopen_stream_sync_003'); try { - let fd = fileio.openSync(fpath, 0o101, 0o222) - let ss = fileio.fdopenStreamSync(fd, "w") - expect(ss !== null).assertTrue() - expect(fileio.closeSync(fd) !== null).assertTrue() - expect(ss.closeSync() !== null).assertTrue() - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - } catch (e) { - console.log("fileio_test_stream_fdopen_stream_sync_003 has failed for " + e) - expect(null).assertFail() + let fd = fileio.openSync(fpath, 0o101, 0o222); + let ss = fileio.fdopenStreamSync(fd, 'w'); + expect(ss !== null).assertTrue(); + expect(fileio.closeSync(fd) !== null).assertTrue(); + expect(ss.closeSync() !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_stream_fdopen_stream_sync_003 has failed for ' + e); + expect(null).assertFail(); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_stream_FdopenStreamSync_0400 @@ -730,30 +781,31 @@ describe('fileIOTestStream', function () { * @tc.desc Function of API, mode=a. The test file is exist. */ it('fileio_test_stream_fdopen_stream_sync_004', 0, function () { - let fpath = nextFileName('fileio_test_stream_fdopen_stream_sync_004') - expect(prepareFile(fpath, "1")).assertTrue() - expect(fileToWriteOnly(fpath)).assertTrue() - let text = "0123456789abcdefg"; - try { - let fd = fileio.openSync(fpath, 0o2001) - expect(fd !== null).assertTrue() - let ss = fileio.fdopenStreamSync(fd, "a") - expect(ss !== null).assertTrue() - let wlen = ss.writeSync(text) - expect(wlen !== null).assertTrue() - expect(ss.closeSync() !== null).assertTrue() - expect(fileToReadOnly(fpath)).assertTrue() - ss = fileio.createStreamSync(fpath, "r") - let rlen = ss.readSync(new ArrayBuffer(4096)) - expect(rlen == text.length + 1).assertTrue() - expect(fileio.closeSync(fd) !== null).assertTrue() - expect(ss.closeSync() !== null).assertTrue() - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - } catch (e) { - console.log("fileio_test_stream_fdopen_stream_sync_004 has failed for " + e) - expect(null).assertFail() - } - }) + let fpath = nextFileName('fileio_test_stream_fdopen_stream_sync_004'); + expect(prepareFile(fpath, '1')).assertTrue(); + expect(fileToWriteOnly(fpath)).assertTrue(); + let text = '0123456789abcdefg'; + try { + let fd = fileio.openSync(fpath, 0o2001); + expect(fd !== null).assertTrue(); + let ss = fileio.fdopenStreamSync(fd, 'a'); + expect(ss !== null).assertTrue(); + let wlen = ss.writeSync(text); + expect(wlen !== null).assertTrue(); + expect(ss.closeSync() !== null).assertTrue(); + expect(fileToReadOnly(fpath)).assertTrue(); + ss = fileio.createStreamSync(fpath, 'r'); + let rlen = ss.readSync(new ArrayBuffer(4096)); + expect(rlen == text.length + 1).assertTrue(); + expect(fileio.closeSync(fd) !== null).assertTrue(); + expect(ss.closeSync() !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_stream_fdopen_stream_sync_004 has failed for ' + e); + expect(null).assertFail(); + } + }); /** * @tc.number SUB_STORAGE_FileIO_stream_FdopenStreamSync_0500 @@ -761,19 +813,20 @@ describe('fileIOTestStream', function () { * @tc.desc Function of API, mode=a. The test file is not exist. */ it('fileio_test_stream_fdopen_stream_sync_005', 0, function () { - let fpath = nextFileName('fileio_test_stream_fdopen_stream_sync_005') + let fpath = nextFileName('fileio_test_stream_fdopen_stream_sync_005'); try { - let fd = fileio.openSync(fpath, 0o101, 0o222) - let ss = fileio.fdopenStreamSync(fd, "a") - expect(ss !== null).assertTrue() - expect(fileio.closeSync(fd) !== null).assertTrue() - expect(ss.closeSync() !== null).assertTrue() - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - } catch (e) { - console.log("fileio_test_stream_fdopen_stream_sync_005 has failed for " + e) - expect(null).assertFail() + let fd = fileio.openSync(fpath, 0o101, 0o222); + let ss = fileio.fdopenStreamSync(fd, 'a'); + expect(ss !== null).assertTrue(); + expect(fileio.closeSync(fd) !== null).assertTrue(); + expect(ss.closeSync() !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); } - }) + catch (e) { + console.log('fileio_test_stream_fdopen_stream_sync_005 has failed for ' + e); + expect(null).assertFail(); + } + }); /** * @tc.number SUB_STORAGE_FileIO_stream_FdopenStreamSync_0600 @@ -781,20 +834,21 @@ describe('fileIOTestStream', function () { * @tc.desc Function of API, mode=r+. The test file is exist. */ it('fileio_test_stream_fdopen_stream_sync_006', 0, function () { - let fpath = nextFileName('fileio_test_stream_fdopen_stream_sync_006') - expect(prepareFile(fpath, "")).assertTrue() - try { - let fd = fileio.openSync(fpath, 0o2) - let ss = fileio.fdopenStreamSync(fd, "r+") - expect(ss !== null).assertTrue() - expect(fileio.closeSync(fd) !== null).assertTrue() - expect(ss.closeSync() !== null).assertTrue() - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - } catch (e) { - console.log("fileio_test_stream_fdopen_stream_sync_006 has failed for " + e) - expect(null).assertFail() + let fpath = nextFileName('fileio_test_stream_fdopen_stream_sync_006'); + expect(prepareFile(fpath, '')).assertTrue(); + try { + let fd = fileio.openSync(fpath, 0o2); + let ss = fileio.fdopenStreamSync(fd, 'r+'); + expect(ss !== null).assertTrue(); + expect(fileio.closeSync(fd) !== null).assertTrue(); + expect(ss.closeSync() !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_stream_fdopen_stream_sync_006 has failed for ' + e); + expect(null).assertFail(); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_stream_FdopenStreamSync_0700 @@ -803,12 +857,13 @@ describe('fileIOTestStream', function () { */ it('fileio_test_stream_fdopen_stream_sync_007', 0, function () { try { - fileio.fdopenStreamSync(-1, "r+") - expect(null).assertFail() - } catch (e) { - console.log("fileio_test_stream_fdopen_stream_sync_007 has failed for " + e) + fileio.fdopenStreamSync(-1, 'r+'); + expect(null).assertFail(); + } + catch (e) { + console.log('fileio_test_stream_fdopen_stream_sync_007 has failed for ' + e); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_stream_FdopenStreamSync_0800 @@ -816,29 +871,30 @@ describe('fileIOTestStream', function () { * @tc.desc Function of API, mode=w+. The test file is exist. */ it('fileio_test_stream_fdopen_stream_sync_008', 0, function () { - let fpath = nextFileName('fileio_test_stream_fdopen_stream_sync_008') - expect(prepareFile(fpath, "")).assertTrue() - let text = "0123456789abcdefg"; - try { - let fd = fileio.openSync(fpath, 0o2) - expect(fd !== null).assertTrue() - let ss = fileio.fdopenStreamSync(fd, "w+") - expect(ss !== null).assertTrue() - let wlen = ss.writeSync(text) - expect(wlen !== null).assertTrue() - expect(ss.closeSync() !== null).assertTrue() - expect(fileToReadOnly(fpath)).assertTrue() - ss = fileio.createStreamSync(fpath, "r") - let rlen = ss.readSync(new ArrayBuffer(4096)) - expect(rlen == text.length).assertTrue() - expect(fileio.closeSync(fd) !== null).assertTrue() - expect(ss.closeSync() !== null).assertTrue() - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - } catch (e) { - console.log("fileio_test_stream_fdopen_stream_sync_008 has failed for " + e) - expect(null).assertFail() - } - }) + let fpath = nextFileName('fileio_test_stream_fdopen_stream_sync_008'); + expect(prepareFile(fpath, '')).assertTrue(); + let text = '0123456789abcdefg'; + try { + let fd = fileio.openSync(fpath, 0o2); + expect(fd !== null).assertTrue(); + let ss = fileio.fdopenStreamSync(fd, 'w+'); + expect(ss !== null).assertTrue(); + let wlen = ss.writeSync(text); + expect(wlen !== null).assertTrue(); + expect(ss.closeSync() !== null).assertTrue(); + expect(fileToReadOnly(fpath)).assertTrue(); + ss = fileio.createStreamSync(fpath, 'r'); + let rlen = ss.readSync(new ArrayBuffer(4096)); + expect(rlen == text.length).assertTrue(); + expect(fileio.closeSync(fd) !== null).assertTrue(); + expect(ss.closeSync() !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_stream_fdopen_stream_sync_008 has failed for ' + e); + expect(null).assertFail(); + } + }); /** * @tc.number SUB_STORAGE_FileIO_stream_FdopenStreamSync_0900 @@ -846,19 +902,20 @@ describe('fileIOTestStream', function () { * @tc.desc Function of API, mode=w+. The test file is not exist. */ it('fileio_test_stream_fdopen_stream_sync_009', 0, function () { - let fpath = nextFileName('fileio_test_stream_fdopen_stream_sync_009') + let fpath = nextFileName('fileio_test_stream_fdopen_stream_sync_009'); try { - let fd = fileio.openSync(fpath, 0o102, 0o666) - let ss = fileio.fdopenStreamSync(fd, "w+") - expect(ss !== null).assertTrue() - expect(fileio.closeSync(fd) !== null).assertTrue() - expect(ss.closeSync() !== null).assertTrue() - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - } catch (e) { - console.log("fileio_test_stream_fdopen_stream_sync_009 has failed for " + e) - expect(null).assertFail() + let fd = fileio.openSync(fpath, 0o102, 0o666); + let ss = fileio.fdopenStreamSync(fd, 'w+'); + expect(ss !== null).assertTrue(); + expect(fileio.closeSync(fd) !== null).assertTrue(); + expect(ss.closeSync() !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_stream_fdopen_stream_sync_009 has failed for ' + e); + expect(null).assertFail(); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_stream_FdopenStreamSync_1000 @@ -866,29 +923,30 @@ describe('fileIOTestStream', function () { * @tc.desc Function of API, mode=a+. The test file is exist. */ it('fileio_test_stream_fdopen_stream_sync_010', 0, function () { - let fpath = nextFileName('fileio_test_stream_fdopen_stream_sync_010') - expect(prepareFile(fpath, "1")).assertTrue() - let text = "0123456789abcdefg"; - try { - let fd = fileio.openSync(fpath, 0o2002) - expect(fd !== null).assertTrue() - let ss = fileio.fdopenStreamSync(fd, "a+") - expect(ss !== null).assertTrue() - let wlen = ss.writeSync(text) - expect(wlen !== null).assertTrue() - expect(ss.closeSync() !== null).assertTrue() - expect(fileToReadOnly(fpath)).assertTrue() - ss = fileio.createStreamSync(fpath, "r") - let rlen = ss.readSync(new ArrayBuffer(4096)) - expect(rlen == text.length + 1).assertTrue() - expect(fileio.closeSync(fd) !== null).assertTrue() - expect(ss.closeSync() !== null).assertTrue() - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - } catch (e) { - console.log("fileio_test_stream_fdopen_stream_sync_010 has failed for " + e) - expect(null).assertFail() - } - }) + let fpath = nextFileName('fileio_test_stream_fdopen_stream_sync_010'); + expect(prepareFile(fpath, '1')).assertTrue(); + let text = '0123456789abcdefg'; + try { + let fd = fileio.openSync(fpath, 0o2002); + expect(fd !== null).assertTrue(); + let ss = fileio.fdopenStreamSync(fd, 'a+'); + expect(ss !== null).assertTrue(); + let wlen = ss.writeSync(text); + expect(wlen !== null).assertTrue(); + expect(ss.closeSync() !== null).assertTrue(); + expect(fileToReadOnly(fpath)).assertTrue(); + ss = fileio.createStreamSync(fpath, 'r'); + let rlen = ss.readSync(new ArrayBuffer(4096)); + expect(rlen == text.length + 1).assertTrue(); + expect(fileio.closeSync(fd) !== null).assertTrue(); + expect(ss.closeSync() !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_stream_fdopen_stream_sync_010 has failed for ' + e); + expect(null).assertFail(); + } + }); /** * @tc.number SUB_STORAGE_FileIO_stream_FdopenStreamSync_1100 @@ -896,19 +954,20 @@ describe('fileIOTestStream', function () { * @tc.desc Function of API, mode=a+. The test file is not exist. */ it('fileio_test_stream_fdopen_stream_sync_011', 0, function () { - let fpath = nextFileName('fileio_test_stream_fdopen_stream_sync_011') + let fpath = nextFileName('fileio_test_stream_fdopen_stream_sync_011'); try { - let fd = fileio.openSync(fpath, 0o102, 0o666) - let ss = fileio.fdopenStreamSync(fd, "a+") - expect(ss !== null).assertTrue() - expect(fileio.closeSync(fd) !== null).assertTrue() - expect(ss.closeSync() !== null).assertTrue() - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - } catch (e) { - console.log("fileio_test_stream_fdopen_stream_sync_011 has failed for " + e) - expect(null).assertFail() + let fd = fileio.openSync(fpath, 0o102, 0o666); + let ss = fileio.fdopenStreamSync(fd, 'a+'); + expect(ss !== null).assertTrue(); + expect(fileio.closeSync(fd) !== null).assertTrue(); + expect(ss.closeSync() !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); } - }) + catch (e) { + console.log('fileio_test_stream_fdopen_stream_sync_011 has failed for ' + e); + expect(null).assertFail(); + } + }); /** * @tc.number SUB_STORAGE_FileIO_stream_FdopenStreamSync_1200 @@ -916,21 +975,22 @@ describe('fileIOTestStream', function () { * @tc.desc Function of API, mode=rb. The test file is exist. */ it('fileio_test_stream_fdopen_stream_sync_012', 0, function () { - let fpath = nextFileName('fileio_test_stream_fdopen_stream_sync_012') - expect(prepareFile(fpath, "")).assertTrue() - expect(fileToReadOnly(fpath)).assertTrue() - try { - let fd = fileio.openSync(fpath, 0o0) - let ss = fileio.fdopenStreamSync(fd, "rb") - expect(ss !== null).assertTrue() - expect(fileio.closeSync(fd) !== null).assertTrue() - expect(ss.closeSync() !== null).assertTrue() - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - } catch (e) { - console.log("fileio_test_stream_fdopen_stream_sync_012 has failed for " + e) - expect(null).assertFail() + let fpath = nextFileName('fileio_test_stream_fdopen_stream_sync_012'); + expect(prepareFile(fpath, '')).assertTrue(); + expect(fileToReadOnly(fpath)).assertTrue(); + try { + let fd = fileio.openSync(fpath, 0o0); + let ss = fileio.fdopenStreamSync(fd, 'rb'); + expect(ss !== null).assertTrue(); + expect(fileio.closeSync(fd) !== null).assertTrue(); + expect(ss.closeSync() !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_stream_fdopen_stream_sync_012 has failed for ' + e); + expect(null).assertFail(); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_stream_FdopenStreamSync_1300 @@ -939,12 +999,13 @@ describe('fileIOTestStream', function () { */ it('fileio_test_stream_fdopen_stream_sync_013', 0, function () { try { - fileio.fdopenStreamSync(-1, "rb") - expect(null).assertFail() - } catch (e) { - console.log("fileio_test_stream_fdopen_stream_sync_013 has failed for " + e) + fileio.fdopenStreamSync(-1, 'rb'); + expect(null).assertFail(); + } + catch (e) { + console.log('fileio_test_stream_fdopen_stream_sync_013 has failed for ' + e); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_stream_FdopenStreamSync_1400 @@ -952,30 +1013,31 @@ describe('fileIOTestStream', function () { * @tc.desc Function of API, mode=wb. The test file is exist. */ it('fileio_test_stream_fdopen_stream_sync_014', 0, function () { - let fpath = nextFileName('fileio_test_stream_fdopen_stream_sync_014') - expect(prepareFile(fpath, "")).assertTrue() - expect(fileToWriteOnly(fpath)).assertTrue() - let text = "0123456789abcdefg"; - try { - let fd = fileio.openSync(fpath, 0o001) - expect(fd !== null).assertTrue() - let ss = fileio.fdopenStreamSync(fd, "wb") - expect(ss !== null).assertTrue() - let wlen = ss.writeSync(text) - expect(wlen !== null).assertTrue() - expect(ss.closeSync() !== null).assertTrue() - expect(fileToReadOnly(fpath)).assertTrue() - ss = fileio.createStreamSync(fpath, "r") - let rlen = ss.readSync(new ArrayBuffer(4096)) - expect(rlen == text.length).assertTrue() - expect(fileio.closeSync(fd) !== null).assertTrue() - expect(ss.closeSync() !== null).assertTrue() - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - } catch (e) { - console.log("fileio_test_stream_fdopen_stream_sync_014 has failed for " + e) - expect(null).assertFail() - } - }) + let fpath = nextFileName('fileio_test_stream_fdopen_stream_sync_014'); + expect(prepareFile(fpath, '')).assertTrue(); + expect(fileToWriteOnly(fpath)).assertTrue(); + let text = '0123456789abcdefg'; + try { + let fd = fileio.openSync(fpath, 0o001); + expect(fd !== null).assertTrue(); + let ss = fileio.fdopenStreamSync(fd, 'wb'); + expect(ss !== null).assertTrue(); + let wlen = ss.writeSync(text); + expect(wlen !== null).assertTrue(); + expect(ss.closeSync() !== null).assertTrue(); + expect(fileToReadOnly(fpath)).assertTrue(); + ss = fileio.createStreamSync(fpath, 'r'); + let rlen = ss.readSync(new ArrayBuffer(4096)); + expect(rlen == text.length).assertTrue(); + expect(fileio.closeSync(fd) !== null).assertTrue(); + expect(ss.closeSync() !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_stream_fdopen_stream_sync_014 has failed for ' + e); + expect(null).assertFail(); + } + }); /** * @tc.number SUB_STORAGE_FileIO_stream_FdopenStreamSync_1500 @@ -983,20 +1045,20 @@ describe('fileIOTestStream', function () { * @tc.desc Function of API, mode=wb. The test file is not exist. */ it('fileio_test_stream_fdopen_stream_sync_015', 0, function () { - let fpath = nextFileName('fileio_test_stream_fdopen_stream_sync_015') - + let fpath = nextFileName('fileio_test_stream_fdopen_stream_sync_015'); try { - let fd = fileio.openSync(fpath, 0o101, 0o222) - let ss = fileio.fdopenStreamSync(fd, "wb") - expect(ss !== null).assertTrue() - expect(fileio.closeSync(fd) !== null).assertTrue() - expect(ss.closeSync() !== null).assertTrue() - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - } catch (e) { - console.log("fileio_test_stream_fdopen_stream_sync_015 has failed for " + e) - expect(null).assertFail() + let fd = fileio.openSync(fpath, 0o101, 0o222); + let ss = fileio.fdopenStreamSync(fd, 'wb'); + expect(ss !== null).assertTrue(); + expect(fileio.closeSync(fd) !== null).assertTrue(); + expect(ss.closeSync() !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_stream_fdopen_stream_sync_015 has failed for ' + e); + expect(null).assertFail(); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_stream_FdopenStreamSync_1600 @@ -1004,30 +1066,31 @@ describe('fileIOTestStream', function () { * @tc.desc Function of API, mode=ab. The test file is exist. */ it('fileio_test_stream_fdopen_stream_sync_016', 0, function () { - let fpath = nextFileName('fileio_test_stream_fdopen_stream_sync_016') - expect(prepareFile(fpath, "1")).assertTrue() - expect(fileToWriteOnly(fpath)).assertTrue() - let text = "0123456789abcdefg"; - try { - let fd = fileio.openSync(fpath, 0o2001) - expect(fd !== null).assertTrue() - let ss = fileio.fdopenStreamSync(fd, "ab") - expect(ss !== null).assertTrue() - let wlen = ss.writeSync(text) - expect(wlen !== null).assertTrue() - expect(ss.closeSync() !== null).assertTrue() - expect(fileToReadOnly(fpath)).assertTrue() - ss = fileio.createStreamSync(fpath, "r") - let rlen = ss.readSync(new ArrayBuffer(4096)) - expect(rlen == text.length + 1).assertTrue() - expect(fileio.closeSync(fd) !== null).assertTrue() - expect(ss.closeSync() !== null).assertTrue() - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - } catch (e) { - console.log("fileio_test_stream_fdopen_stream_sync_016 has failed for " + e) - expect(null).assertFail() - } - }) + let fpath = nextFileName('fileio_test_stream_fdopen_stream_sync_016'); + expect(prepareFile(fpath, '1')).assertTrue(); + expect(fileToWriteOnly(fpath)).assertTrue(); + let text = '0123456789abcdefg'; + try { + let fd = fileio.openSync(fpath, 0o2001); + expect(fd !== null).assertTrue(); + let ss = fileio.fdopenStreamSync(fd, 'ab'); + expect(ss !== null).assertTrue(); + let wlen = ss.writeSync(text); + expect(wlen !== null).assertTrue(); + expect(ss.closeSync() !== null).assertTrue(); + expect(fileToReadOnly(fpath)).assertTrue(); + ss = fileio.createStreamSync(fpath, 'r'); + let rlen = ss.readSync(new ArrayBuffer(4096)); + expect(rlen == text.length + 1).assertTrue(); + expect(fileio.closeSync(fd) !== null).assertTrue(); + expect(ss.closeSync() !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_stream_fdopen_stream_sync_016 has failed for ' + e); + expect(null).assertFail(); + } + }); /** * @tc.number SUB_STORAGE_FileIO_stream_FdopenStreamSync_1700 @@ -1035,19 +1098,20 @@ describe('fileIOTestStream', function () { * @tc.desc Function of API, mode=ab. The test file is not exist. */ it('fileio_test_stream_fdopen_stream_sync_017', 0, function () { - let fpath = nextFileName('fileio_test_stream_fdopen_stream_sync_017') + let fpath = nextFileName('fileio_test_stream_fdopen_stream_sync_017'); try { - let fd = fileio.openSync(fpath, 0o101, 0o222) - let ss = fileio.fdopenStreamSync(fd, "ab") - expect(ss !== null).assertTrue() - expect(fileio.closeSync(fd) !== null).assertTrue() - expect(ss.closeSync() !== null).assertTrue() - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - } catch (e) { - console.log("fileio_test_stream_fdopen_stream_sync_017 has failed for " + e) - expect(null).assertFail() + let fd = fileio.openSync(fpath, 0o101, 0o222); + let ss = fileio.fdopenStreamSync(fd, 'ab'); + expect(ss !== null).assertTrue(); + expect(fileio.closeSync(fd) !== null).assertTrue(); + expect(ss.closeSync() !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); } - }) + catch (e) { + console.log('fileio_test_stream_fdopen_stream_sync_017 has failed for ' + e); + expect(null).assertFail(); + } + }); /** * @tc.number SUB_STORAGE_FileIO_stream_FdopenStreamSync_1800 @@ -1055,19 +1119,20 @@ describe('fileIOTestStream', function () { * @tc.desc Function of API, mode=rb+. The test file is exist. */ it('fileio_test_stream_fdopen_stream_sync_018', 0, function () { - let fpath = nextFileName('fileio_test_stream_fdopen_stream_sync_018') - expect(prepareFile(fpath, "")).assertTrue() - try { - let fd = fileio.openSync(fpath, 0o2) - let ss = fileio.fdopenStreamSync(fd, "rb+") - expect(ss !== null).assertTrue() - expect(ss.closeSync() !== null).assertTrue() - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - } catch (e) { - console.log("fileio_test_stream_fdopen_stream_sync_018 has failed for " + e) - expect(null).assertFail() + let fpath = nextFileName('fileio_test_stream_fdopen_stream_sync_018'); + expect(prepareFile(fpath, '')).assertTrue(); + try { + let fd = fileio.openSync(fpath, 0o2); + let ss = fileio.fdopenStreamSync(fd, 'rb+'); + expect(ss !== null).assertTrue(); + expect(ss.closeSync() !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_stream_fdopen_stream_sync_018 has failed for ' + e); + expect(null).assertFail(); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_stream_FdopenStreamSync_1900 @@ -1076,12 +1141,13 @@ describe('fileIOTestStream', function () { */ it('fileio_test_stream_fdopen_stream_sync_019', 0, function () { try { - fileio.fdopenStreamSync(-1, "rb+") - expect(null).assertFail() - } catch (e) { - console.log("fileio_test_stream_fdopen_stream_sync_019 has failed for " + e) + fileio.fdopenStreamSync(-1, 'rb+'); + expect(null).assertFail(); + } + catch (e) { + console.log('fileio_test_stream_fdopen_stream_sync_019 has failed for ' + e); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_stream_FdopenStreamSync_2000 @@ -1089,29 +1155,30 @@ describe('fileIOTestStream', function () { * @tc.desc Function of API, mode=wb+. The test file is exist. */ it('fileio_test_stream_fdopen_stream_sync_020', 0, function () { - let fpath = nextFileName('fileio_test_stream_fdopen_stream_sync_020') - expect(prepareFile(fpath, "")).assertTrue() - let text = "0123456789abcdefg"; - try { - let fd = fileio.openSync(fpath, 0o002) - expect(fd !== null).assertTrue() - let ss = fileio.fdopenStreamSync(fd, "wb+") - expect(ss !== null).assertTrue() - let wlen = ss.writeSync(text) - expect(wlen !== null).assertTrue() - expect(ss.closeSync() !== null).assertTrue() - expect(fileToReadOnly(fpath)).assertTrue() - ss = fileio.createStreamSync(fpath, "r") - let rlen = ss.readSync(new ArrayBuffer(4096)) - expect(rlen == text.length).assertTrue() - expect(fileio.closeSync(fd) !== null).assertTrue() - expect(ss.closeSync() !== null).assertTrue() - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - } catch (e) { - console.log("fileio_test_stream_fdopen_stream_sync_020 has failed for " + e) - expect(null).assertFail() - } - }) + let fpath = nextFileName('fileio_test_stream_fdopen_stream_sync_020'); + expect(prepareFile(fpath, '')).assertTrue(); + let text = '0123456789abcdefg'; + try { + let fd = fileio.openSync(fpath, 0o002); + expect(fd !== null).assertTrue(); + let ss = fileio.fdopenStreamSync(fd, 'wb+'); + expect(ss !== null).assertTrue(); + let wlen = ss.writeSync(text); + expect(wlen !== null).assertTrue(); + expect(ss.closeSync() !== null).assertTrue(); + expect(fileToReadOnly(fpath)).assertTrue(); + ss = fileio.createStreamSync(fpath, 'r'); + let rlen = ss.readSync(new ArrayBuffer(4096)); + expect(rlen == text.length).assertTrue(); + expect(fileio.closeSync(fd) !== null).assertTrue(); + expect(ss.closeSync() !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_stream_fdopen_stream_sync_020 has failed for ' + e); + expect(null).assertFail(); + } + }); /** * @tc.number SUB_STORAGE_FileIO_stream_FdopenStreamSync_2100 @@ -1119,19 +1186,20 @@ describe('fileIOTestStream', function () { * @tc.desc Function of API, mode=wb+. The test file is not exist. */ it('fileio_test_stream_fdopen_stream_sync_021', 0, function () { - let fpath = nextFileName('fileio_test_stream_fdopen_stream_sync_021') + let fpath = nextFileName('fileio_test_stream_fdopen_stream_sync_021'); try { - let fd = fileio.openSync(fpath, 0o102, 0o666) - let ss = fileio.fdopenStreamSync(fd, "wb+") - expect(ss !== null).assertTrue() - expect(fileio.closeSync(fd) !== null).assertTrue() - expect(ss.closeSync() !== null).assertTrue() - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - } catch (e) { - console.log("fileio_test_stream_fdopen_stream_sync_021 has failed for " + e) - expect(null).assertFail() + let fd = fileio.openSync(fpath, 0o102, 0o666); + let ss = fileio.fdopenStreamSync(fd, 'wb+'); + expect(ss !== null).assertTrue(); + expect(fileio.closeSync(fd) !== null).assertTrue(); + expect(ss.closeSync() !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_stream_fdopen_stream_sync_021 has failed for ' + e); + expect(null).assertFail(); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_stream_FdopenStreamSync_2200 @@ -1139,29 +1207,30 @@ describe('fileIOTestStream', function () { * @tc.desc Function of API, mode=ab+. The test file is exist. */ it('fileio_test_stream_fdopen_stream_sync_022', 0, function () { - let fpath = nextFileName('fileio_test_stream_fdopen_stream_sync_022') - expect(prepareFile(fpath, "1")).assertTrue() - let text = "0123456789abcdefg"; - try { - let fd = fileio.openSync(fpath, 0o2002) - expect(fd !== null).assertTrue() - let ss = fileio.fdopenStreamSync(fd, "ab+") - expect(ss !== null).assertTrue() - let wlen = ss.writeSync(text) - expect(wlen !== null).assertTrue() - expect(ss.closeSync() !== null).assertTrue() - expect(fileToReadOnly(fpath)).assertTrue() - ss = fileio.createStreamSync(fpath, "r") - let rlen = ss.readSync(new ArrayBuffer(4096)) - expect(rlen == text.length + 1).assertTrue() - expect(fileio.closeSync(fd) !== null).assertTrue() - expect(ss.closeSync() !== null).assertTrue() - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - } catch (e) { - console.log("fileio_test_stream_fdopen_stream_sync_022 has failed for " + e) - expect(null).assertFail() - } - }) + let fpath = nextFileName('fileio_test_stream_fdopen_stream_sync_022'); + expect(prepareFile(fpath, '1')).assertTrue(); + let text = '0123456789abcdefg'; + try { + let fd = fileio.openSync(fpath, 0o2002); + expect(fd !== null).assertTrue(); + let ss = fileio.fdopenStreamSync(fd, 'ab+'); + expect(ss !== null).assertTrue(); + let wlen = ss.writeSync(text); + expect(wlen !== null).assertTrue(); + expect(ss.closeSync() !== null).assertTrue(); + expect(fileToReadOnly(fpath)).assertTrue(); + ss = fileio.createStreamSync(fpath, 'r'); + let rlen = ss.readSync(new ArrayBuffer(4096)); + expect(rlen == text.length + 1).assertTrue(); + expect(fileio.closeSync(fd) !== null).assertTrue(); + expect(ss.closeSync() !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_stream_fdopen_stream_sync_022 has failed for ' + e); + expect(null).assertFail(); + } + }); /** * @tc.number SUB_STORAGE_FileIO_stream_FdopenStreamSync_2300 @@ -1169,19 +1238,20 @@ describe('fileIOTestStream', function () { * @tc.desc Function of API, mode=ab+. The test file is not exist. */ it('fileio_test_stream_fdopen_stream_sync_023', 0, function () { - let fpath = nextFileName('fileio_test_stream_fdopen_stream_sync_023') + let fpath = nextFileName('fileio_test_stream_fdopen_stream_sync_023'); try { - let fd = fileio.openSync(fpath, 0o102, 0o666) - let ss = fileio.fdopenStreamSync(fd, "ab+") - expect(ss !== null).assertTrue() - expect(fileio.closeSync(fd) !== null).assertTrue() - expect(ss.closeSync() !== null).assertTrue() - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - } catch (e) { - console.log("fileio_test_stream_fdopen_stream_sync_023 has failed for " + e) - expect(null).assertFail() + let fd = fileio.openSync(fpath, 0o102, 0o666); + let ss = fileio.fdopenStreamSync(fd, 'ab+'); + expect(ss !== null).assertTrue(); + expect(fileio.closeSync(fd) !== null).assertTrue(); + expect(ss.closeSync() !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); } - }) + catch (e) { + console.log('fileio_test_stream_fdopen_stream_sync_023 has failed for ' + e); + expect(null).assertFail(); + } + }); /** * @tc.number SUB_STORAGE_FileIO_stream_FdopenStreamSync_2400 @@ -1190,12 +1260,13 @@ describe('fileIOTestStream', function () { */ it('fileio_test_stream_fdopen_stream_sync_024', 0, function () { try { - expect(fileio.fdopenStreamSync(null, "r") == null).assertTrue() + expect(fileio.fdopenStreamSync(null, 'r') == null).assertTrue(); expect(null).assertFail(); - } catch (e) { - console.log("---fileio_test_stream_fdopen_stream_sync_024 is passed!" + e) + } + catch (e) { + console.log('---fileio_test_stream_fdopen_stream_sync_024 is passed!' + e); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_stream_FdopenStreamSync_2400 @@ -1203,17 +1274,18 @@ describe('fileIOTestStream', function () { * @tc.desc Function of API, invaild mode. The test file is exist. */ it('fileio_test_stream_fdopen_stream_sync_025', 0, function () { - let fpath = nextFileName('fileio_test_stream_fdopen_stream_sync_025') - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + let fpath = nextFileName('fileio_test_stream_fdopen_stream_sync_025'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); try { - let fd = fileio.openSync(fpath, 0o2) - expect(fileio.fdopenStreamSync(fd, "") == null).assertTrue() + let fd = fileio.openSync(fpath, 0o2); + expect(fileio.fdopenStreamSync(fd, '') == null).assertTrue(); expect(null).assertFail(); - } catch (e) { - console.log("---fileio_test_stream_fdopen_stream_sync_025 is passed!" + e) - expect(fileio.unlinkSync(fpath) !== null).assertTrue() + } + catch (e) { + console.log('---fileio_test_stream_fdopen_stream_sync_025 is passed!' + e); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_stream_ReadSync_0000 @@ -1221,21 +1293,22 @@ describe('fileIOTestStream', function () { * @tc.desc Function of API, not set options. */ it('fileio_test_stream_read_sync_000', 0, function () { - let fpath = nextFileName('fileio_test_stream_read_sync_000') - let text = "0123456789abcdefg"; - expect(prepareFile(fpath, text)).assertTrue() - try { - let ss = fileio.createStreamSync(fpath, "r+") - expect(ss !== null).assertTrue() - let len = ss.readSync(new ArrayBuffer(4096)) - expect(len == text.length).assertTrue() - expect(ss.closeSync() !== null).assertTrue() - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - } catch (e) { - console.log("fileio_test_stream_read_sync_000 has failed for " + e) - expect(null).assertFail() + let fpath = nextFileName('fileio_test_stream_read_sync_000'); + let text = '0123456789abcdefg'; + expect(prepareFile(fpath, text)).assertTrue(); + try { + let ss = fileio.createStreamSync(fpath, 'r+'); + expect(ss !== null).assertTrue(); + let len = ss.readSync(new ArrayBuffer(4096)); + expect(len == text.length).assertTrue(); + expect(ss.closeSync() !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_stream_read_sync_000 has failed for ' + e); + expect(null).assertFail(); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_stream_ReadSync_0100 @@ -1243,23 +1316,24 @@ describe('fileIOTestStream', function () { * @tc.desc Function of API, position. */ it('fileio_test_stream_read_sync_001', 0, function () { - let fpath = nextFileName('fileio_test_stream_read_sync_001') - let text = "0123456789abcdefg"; - expect(prepareFile(fpath, text)).assertTrue() + let fpath = nextFileName('fileio_test_stream_read_sync_001'); + let text = '0123456789abcdefg'; + expect(prepareFile(fpath, text)).assertTrue(); try { - let ss = fileio.createStreamSync(fpath, "r+") - expect(ss !== null).assertTrue() + let ss = fileio.createStreamSync(fpath, 'r+'); + expect(ss !== null).assertTrue(); let len = ss.readSync(new ArrayBuffer(4096), { position: 1 - }) - expect(len == text.length - 1).assertTrue() - expect(ss.closeSync() !== null).assertTrue() - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - } catch (e) { - console.log("fileio_test_stream_read_sync_001 has failed for " + e) - expect(null).assertFail() + }); + expect(len == text.length - 1).assertTrue(); + expect(ss.closeSync() !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_stream_read_sync_001 has failed for ' + e); + expect(null).assertFail(); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_stream_ReadSync_0200 @@ -1267,23 +1341,24 @@ describe('fileIOTestStream', function () { * @tc.desc Function of API, offset. */ it('fileio_test_stream_read_sync_002', 0, function () { - let fpath = nextFileName('fileio_test_stream_read_sync_002') - let text = "0123456789abcdefg"; - expect(prepareFile(fpath, text)).assertTrue() + let fpath = nextFileName('fileio_test_stream_read_sync_002'); + let text = '0123456789abcdefg'; + expect(prepareFile(fpath, text)).assertTrue(); try { - let ss = fileio.createStreamSync(fpath, "r+") - expect(ss !== null).assertTrue() + let ss = fileio.createStreamSync(fpath, 'r+'); + expect(ss !== null).assertTrue(); let len = ss.readSync(new ArrayBuffer(4096), { offset: 1 - }) - expect(len == text.length).assertTrue() - expect(ss.closeSync() !== null).assertTrue() - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - } catch (e) { - console.log("fileio_test_stream_read_sync_002 has failed for " + e) - expect(null).assertFail() + }); + expect(len == text.length).assertTrue(); + expect(ss.closeSync() !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_stream_read_sync_002 has failed for ' + e); + expect(null).assertFail(); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_stream_ReadSync_0300 @@ -1291,22 +1366,23 @@ describe('fileIOTestStream', function () { * @tc.desc Function of API, length. */ it('fileio_test_stream_read_sync_003', 0, function () { - let fpath = nextFileName('fileio_test_stream_read_sync_003') - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + let fpath = nextFileName('fileio_test_stream_read_sync_003'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); try { - let ss = fileio.createStreamSync(fpath, "r+") - expect(ss !== null).assertTrue() + let ss = fileio.createStreamSync(fpath, 'r+'); + expect(ss !== null).assertTrue(); let len = ss.readSync(new ArrayBuffer(4096), { length: 1 - }) - expect(len == 1).assertTrue() - expect(ss.closeSync() !== null).assertTrue() - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - } catch (e) { - console.log("fileio_test_stream_read_sync_003 has failed for " + e) - expect(null).assertFail() + }); + expect(len == 1).assertTrue(); + expect(ss.closeSync() !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_stream_read_sync_003 has failed for ' + e); + expect(null).assertFail(); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_stream_ReadSync_0400 @@ -1314,20 +1390,21 @@ describe('fileIOTestStream', function () { * @tc.desc Function of API, readBuf. */ it('fileio_test_stream_read_sync_004', 0, function () { - let fpath = nextFileName('fileio_test_stream_read_sync_004') - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + let fpath = nextFileName('fileio_test_stream_read_sync_004'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); try { - var ss = fileio.createStreamSync(fpath, "r+") - expect(ss !== null).assertTrue() - let len = ss.readSync(null) - expect(len == null).assertTrue() - expect(null).assertFail() - } catch (e) { - console.log("fileio_test_stream_read_sync_004 has failed for " + e) - expect(ss.closeSync() !== null).assertTrue() - expect(fileio.unlinkSync(fpath) !== null).assertTrue() + var ss = fileio.createStreamSync(fpath, 'r+'); + expect(ss !== null).assertTrue(); + let len = ss.readSync(null); + expect(len == null).assertTrue(); + expect(null).assertFail(); + } + catch (e) { + console.log('fileio_test_stream_read_sync_004 has failed for ' + e); + expect(ss.closeSync() !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_stream_ReadSync_0500 @@ -1335,23 +1412,24 @@ describe('fileIOTestStream', function () { * @tc.desc Function of API, position = -1. */ it('fileio_test_stream_read_sync_005', 0, function () { - let fpath = nextFileName('fileio_test_stream_read_sync_005') - let text = "0123456789abcdefg"; - expect(prepareFile(fpath, text)).assertTrue() + let fpath = nextFileName('fileio_test_stream_read_sync_005'); + let text = '0123456789abcdefg'; + expect(prepareFile(fpath, text)).assertTrue(); try { - var ss = fileio.createStreamSync(fpath, "r+") - expect(ss !== null).assertTrue() + var ss = fileio.createStreamSync(fpath, 'r+'); + expect(ss !== null).assertTrue(); let len = ss.readSync(new ArrayBuffer(4096), { position: -1 - }) - expect(len == text.length).assertTrue() - expect(ss.closeSync() !== null).assertTrue() - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - } catch (e) { - console.log("---fileio_test_stream_read_sync_005 has failed for " + e) - expect(null).assertFail() + }); + expect(len == text.length).assertTrue(); + expect(ss.closeSync() !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('---fileio_test_stream_read_sync_005 has failed for ' + e); + expect(null).assertFail(); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_stream_ReadSync_0600 @@ -1359,22 +1437,23 @@ describe('fileIOTestStream', function () { * @tc.desc Function of API, offset. */ it('fileio_test_stream_read_sync_006', 0, function () { - let fpath = nextFileName('fileio_test_stream_read_sync_006') - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + let fpath = nextFileName('fileio_test_stream_read_sync_006'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); try { - var ss = fileio.createStreamSync(fpath, "r+") - expect(ss !== null).assertTrue() + var ss = fileio.createStreamSync(fpath, 'r+'); + expect(ss !== null).assertTrue(); let len = ss.readSync(new ArrayBuffer(4096), { offset: -1 - }) - expect(len == null).assertTrue() - expect(null).assertFail() - } catch (e) { - console.log("fileio_test_stream_read_sync_006 has failed for " + e) - expect(ss.closeSync() !== null).assertTrue() - expect(fileio.unlinkSync(fpath) !== null).assertTrue() + }); + expect(len == null).assertTrue(); + expect(null).assertFail(); + } + catch (e) { + console.log('fileio_test_stream_read_sync_006 has failed for ' + e); + expect(ss.closeSync() !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_stream_WriteSync_0000 @@ -1382,21 +1461,22 @@ describe('fileIOTestStream', function () { * @tc.desc Function of API, not set options. */ it('fileio_test_stream_write_sync_000', 0, function () { - let fpath = nextFileName('fileio_test_stream_write_sync_000') - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() - let text = "0123456789abcdefg"; - try { - let ss = fileio.createStreamSync(fpath, "r+") - expect(ss !== null).assertTrue() - expect(ss.writeSync(text) == text.length).assertTrue() - expect(ss.closeSync() !== null).assertTrue() - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - console.log("---fileio_test_stream_write_sync_000 is passed!") - } catch (e) { - console.log("fileio_test_stream_write_sync_000 has failed for " + e) - expect(null).assertFail() + let fpath = nextFileName('fileio_test_stream_write_sync_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let text = '0123456789abcdefg'; + try { + let ss = fileio.createStreamSync(fpath, 'r+'); + expect(ss !== null).assertTrue(); + expect(ss.writeSync(text) == text.length).assertTrue(); + expect(ss.closeSync() !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + console.log('---fileio_test_stream_write_sync_000 is passed!'); + } + catch (e) { + console.log('fileio_test_stream_write_sync_000 has failed for ' + e); + expect(null).assertFail(); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_stream_WriteSync_0100 @@ -1404,22 +1484,23 @@ describe('fileIOTestStream', function () { * @tc.desc Function of API, invaild encoding. */ it('fileio_test_stream_write_sync_001', 0, function () { - let fpath = nextFileName('fileio_test_stream_write_sync_001') - expect(prepareFile(fpath, "")).assertTrue() + let fpath = nextFileName('fileio_test_stream_write_sync_001'); + expect(prepareFile(fpath, '')).assertTrue(); let ss try { - ss = fileio.createStreamSync(fpath, "w+") - expect(ss !== null).assertTrue() + ss = fileio.createStreamSync(fpath, 'w+'); + expect(ss !== null).assertTrue(); expect(ss.writeSync(FILE_CONTENT, { - encoding: "ASCII" - }) !== null).assertTrue() - expect(null).assertFail() - } catch (e) { - console.log("fileio_test_stream_write_sync_001 has failed for " + e) - expect(ss.closeSync() !== null).assertTrue() - expect(fileio.unlinkSync(fpath) !== null).assertTrue() + encoding: 'ASCII' + }) !== null).assertTrue(); + expect(null).assertFail(); + } + catch (e) { + console.log('fileio_test_stream_write_sync_001 has failed for ' + e); + expect(ss.closeSync() !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_stream_WriteSync_0200 @@ -1427,28 +1508,29 @@ describe('fileIOTestStream', function () { * @tc.desc Function of API, position. */ it('fileio_test_stream_write_sync_002', 0, function () { - let fpath = nextFileName('fileio_test_stream_write_sync_002') - expect(prepareFile(fpath, "a")).assertTrue() - expect(fileToWriteOnly(fpath)).assertTrue() - try { - let fd = fileio.openSync(fpath, 0o001) - expect(fd !== null).assertTrue() - let ss = fileio.fdopenStreamSync(fd, "w") - expect(ss !== null).assertTrue() - expect(ss.writeSync("aaa") !== null).assertTrue() - expect(ss.closeSync() !== null).assertTrue() - expect(fileToReadOnly(fpath)).assertTrue() - ss = fileio.createStreamSync(fpath, "r") - let rlen = ss.readSync(new ArrayBuffer(4096)) - expect(rlen == 3).assertTrue() - expect(fileio.closeSync(fd) !== null).assertTrue() - expect(ss.closeSync() !== null).assertTrue() - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - } catch (e) { - console.log("fileio_test_stream_write_sync_002 has failed for " + e) - expect(null).assertFail() - } - }) + let fpath = nextFileName('fileio_test_stream_write_sync_002'); + expect(prepareFile(fpath, 'a')).assertTrue(); + expect(fileToWriteOnly(fpath)).assertTrue(); + try { + let fd = fileio.openSync(fpath, 0o001); + expect(fd !== null).assertTrue(); + let ss = fileio.fdopenStreamSync(fd, 'w'); + expect(ss !== null).assertTrue(); + expect(ss.writeSync('aaa') !== null).assertTrue(); + expect(ss.closeSync() !== null).assertTrue(); + expect(fileToReadOnly(fpath)).assertTrue(); + ss = fileio.createStreamSync(fpath, 'r'); + let rlen = ss.readSync(new ArrayBuffer(4096)); + expect(rlen == 3).assertTrue(); + expect(fileio.closeSync(fd) !== null).assertTrue(); + expect(ss.closeSync() !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_stream_write_sync_002 has failed for ' + e); + expect(null).assertFail(); + } + }); /** * @tc.number SUB_STORAGE_FileIO_stream_WriteSync_0300 @@ -1456,28 +1538,29 @@ describe('fileIOTestStream', function () { * @tc.desc Function of API, offset. */ it('fileio_test_stream_write_sync_003', 0, function () { - let fpath = nextFileName('fileio_test_stream_write_sync_003') - expect(prepareFile(fpath, "a")).assertTrue() - expect(fileToWriteOnly(fpath)).assertTrue() - try { - let fd = fileio.openSync(fpath, 0o001) - expect(fd !== null).assertTrue() - let ss = fileio.fdopenStreamSync(fd, "w") - expect(ss !== null).assertTrue() - expect(ss.writeSync("aaa") !== null).assertTrue() - expect(ss.closeSync() !== null).assertTrue() - expect(fileToReadOnly(fpath)).assertTrue() - ss = fileio.createStreamSync(fpath, "r") - let rlen = ss.readSync(new ArrayBuffer(4096)) - expect(rlen == 3).assertTrue() - expect(fileio.closeSync(fd) !== null).assertTrue() - expect(ss.closeSync() !== null).assertTrue() - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - } catch (e) { - console.log("fileio_test_stream_write_sync_003 has failed for " + e) - expect(null).assertFail() - } - }) + let fpath = nextFileName('fileio_test_stream_write_sync_003'); + expect(prepareFile(fpath, 'a')).assertTrue(); + expect(fileToWriteOnly(fpath)).assertTrue(); + try { + let fd = fileio.openSync(fpath, 0o001); + expect(fd !== null).assertTrue(); + let ss = fileio.fdopenStreamSync(fd, 'w'); + expect(ss !== null).assertTrue(); + expect(ss.writeSync('aaa') !== null).assertTrue(); + expect(ss.closeSync() !== null).assertTrue(); + expect(fileToReadOnly(fpath)).assertTrue(); + ss = fileio.createStreamSync(fpath, 'r'); + let rlen = ss.readSync(new ArrayBuffer(4096)); + expect(rlen == 3).assertTrue(); + expect(fileio.closeSync(fd) !== null).assertTrue(); + expect(ss.closeSync() !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_stream_write_sync_003 has failed for ' + e); + expect(null).assertFail(); + } + }); /** * @tc.number SUB_STORAGE_FileIO_stream_WriteSync_0400 @@ -1485,25 +1568,26 @@ describe('fileIOTestStream', function () { * @tc.desc Function of API, length. */ it('fileio_test_stream_write_sync_004', 0, function () { - let fpath = nextFileName('fileio_test_stream_write_sync_004') - expect(prepareFile(fpath, "a")).assertTrue() - let text = "0123456789abcdefg"; - try { - let ss = fileio.createStreamSync(fpath, "r+") - expect(ss !== null).assertTrue() - let wlen = ss.writeSync(text) - expect(wlen == text.length).assertTrue() - expect(ss.closeSync() !== null).assertTrue() - ss = fileio.createStreamSync(fpath, "r+") - let rlen = ss.readSync(new ArrayBuffer(4096)) - expect(rlen == text.length).assertTrue() - expect(ss.closeSync() !== null).assertTrue() - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - } catch (e) { - console.log("fileio_test_stream_write_sync_004 has failed for " + e) - expect(null).assertFail() - } - }) + let fpath = nextFileName('fileio_test_stream_write_sync_004'); + expect(prepareFile(fpath, 'a')).assertTrue(); + let text = '0123456789abcdefg'; + try { + let ss = fileio.createStreamSync(fpath, 'r+'); + expect(ss !== null).assertTrue(); + let wlen = ss.writeSync(text); + expect(wlen == text.length).assertTrue(); + expect(ss.closeSync() !== null).assertTrue(); + ss = fileio.createStreamSync(fpath, 'r+'); + let rlen = ss.readSync(new ArrayBuffer(4096)); + expect(rlen == text.length).assertTrue(); + expect(ss.closeSync() !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_stream_write_sync_004 has failed for ' + e); + expect(null).assertFail(); + } + }); /** * @tc.number SUB_STORAGE_FileIO_stream_WriteSync_0500 @@ -1511,30 +1595,31 @@ describe('fileIOTestStream', function () { * @tc.desc Function of API, encoding. */ it('fileio_test_stream_write_sync_005', 0, function () { - let fpath = nextFileName('fileio_test_stream_write_sync_005') - expect(prepareFile(fpath, "")).assertTrue() - let writeStrArray = new Array("aaa", "123") - let encodingArray = new Array('utf-8', 'utf-16') + let fpath = nextFileName('fileio_test_stream_write_sync_005'); + expect(prepareFile(fpath, '')).assertTrue(); + let writeStrArray = new Array('aaa', '123'); + let encodingArray = new Array('utf-8', 'utf-16'); try { for (let i = 0; i < encodingArray.length; i++) { - let ss = fileio.createStreamSync(fpath, "w+") - expect(ss !== null).assertTrue() + let ss = fileio.createStreamSync(fpath, 'w+'); + expect(ss !== null).assertTrue(); expect(ss.writeSync(writeStrArray[i], { encoding: encodingArray[i] - }) !== null).assertTrue() - expect(ss.closeSync() !== null).assertTrue() - ss = fileio.createStreamSync(fpath, "r+") - let rlen = ss.readSync(new ArrayBuffer(4096)) - expect(rlen !== null).assertTrue() - expect(ss.closeSync() !== null).assertTrue() + }) !== null).assertTrue(); + expect(ss.closeSync() !== null).assertTrue(); + ss = fileio.createStreamSync(fpath, 'r+'); + let rlen = ss.readSync(new ArrayBuffer(4096)); + expect(rlen !== null).assertTrue(); + expect(ss.closeSync() !== null).assertTrue(); } - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - } catch (e) { - console.log("fileio_test_stream_write_sync_005 has failed for " + e) - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - expect(null).assertFail() + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_stream_write_sync_005 has failed for ' + e); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + expect(null).assertFail(); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_stream_WriteSync_0600 @@ -1542,30 +1627,31 @@ describe('fileIOTestStream', function () { * @tc.desc Function of API, position. */ it('fileio_test_stream_write_sync_006', 0, function () { - let fpath = nextFileName('fileio_test_stream_write_sync_006') - expect(prepareFile(fpath, "a")).assertTrue() - expect(fileToWriteOnly(fpath)).assertTrue() - try { - let fd = fileio.openSync(fpath, 0o001) - expect(fd !== null).assertTrue() - let ss = fileio.fdopenStreamSync(fd, "w") - expect(ss !== null).assertTrue() - expect(ss.writeSync("aaa", { + let fpath = nextFileName('fileio_test_stream_write_sync_006'); + expect(prepareFile(fpath, 'a')).assertTrue(); + expect(fileToWriteOnly(fpath)).assertTrue(); + try { + let fd = fileio.openSync(fpath, 0o001); + expect(fd !== null).assertTrue(); + let ss = fileio.fdopenStreamSync(fd, 'w'); + expect(ss !== null).assertTrue(); + expect(ss.writeSync('aaa', { position: 1 - }) !== null).assertTrue() - expect(ss.closeSync() !== null).assertTrue() - expect(fileToReadOnly(fpath)).assertTrue() - ss = fileio.createStreamSync(fpath, "r") - let rlen = ss.readSync(new ArrayBuffer(4096)) - expect(rlen == 4).assertTrue() - expect(fileio.closeSync(fd) !== null).assertTrue() - expect(ss.closeSync() !== null).assertTrue() - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - } catch (e) { - console.log("fileio_test_stream_write_sync_006 has failed for " + e) - expect(null).assertFail() - } - }) + }) !== null).assertTrue(); + expect(ss.closeSync() !== null).assertTrue(); + expect(fileToReadOnly(fpath)).assertTrue(); + ss = fileio.createStreamSync(fpath, 'r'); + let rlen = ss.readSync(new ArrayBuffer(4096)); + expect(rlen == 4).assertTrue(); + expect(fileio.closeSync(fd) !== null).assertTrue(); + expect(ss.closeSync() !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_stream_write_sync_006 has failed for ' + e); + expect(null).assertFail(); + } + }); /** * @tc.number SUB_STORAGE_FileIO_stream_WriteSync_0700 @@ -1573,30 +1659,31 @@ describe('fileIOTestStream', function () { * @tc.desc Function of API, offset. */ it('fileio_test_stream_write_sync_007', 0, function () { - let fpath = nextFileName('fileio_test_stream_write_sync_007') - expect(prepareFile(fpath, "a")).assertTrue() - expect(fileToWriteOnly(fpath)).assertTrue() - try { - let fd = fileio.openSync(fpath, 0o001) - expect(fd !== null).assertTrue() - let ss = fileio.fdopenStreamSync(fd, "w") - expect(ss !== null).assertTrue() - expect(ss.writeSync("aaa", { + let fpath = nextFileName('fileio_test_stream_write_sync_007'); + expect(prepareFile(fpath, 'a')).assertTrue(); + expect(fileToWriteOnly(fpath)).assertTrue(); + try { + let fd = fileio.openSync(fpath, 0o001); + expect(fd !== null).assertTrue(); + let ss = fileio.fdopenStreamSync(fd, 'w'); + expect(ss !== null).assertTrue(); + expect(ss.writeSync('aaa', { offset: 1 - }) !== null).assertTrue() - expect(ss.closeSync() !== null).assertTrue() - expect(fileToReadOnly(fpath)).assertTrue() - ss = fileio.createStreamSync(fpath, "r") - let rlen = ss.readSync(new ArrayBuffer(4096)) - expect(rlen == 2).assertTrue() - expect(fileio.closeSync(fd) !== null).assertTrue() - expect(ss.closeSync() !== null).assertTrue() - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - } catch (e) { - console.log("fileio_test_stream_write_sync_007 has failed for " + e) - expect(null).assertFail() - } - }) + }) !== null).assertTrue(); + expect(ss.closeSync() !== null).assertTrue(); + expect(fileToReadOnly(fpath)).assertTrue(); + ss = fileio.createStreamSync(fpath, 'r'); + let rlen = ss.readSync(new ArrayBuffer(4096)); + expect(rlen == 2).assertTrue(); + expect(fileio.closeSync(fd) !== null).assertTrue(); + expect(ss.closeSync() !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_stream_write_sync_007 has failed for ' + e); + expect(null).assertFail(); + } + }); /** * @tc.number SUB_STORAGE_FileIO_stream_WriteSync_0800 @@ -1604,27 +1691,28 @@ describe('fileIOTestStream', function () { * @tc.desc Function of API, length. */ it('fileio_test_stream_write_sync_008', 0, function () { - let fpath = nextFileName('fileio_test_stream_write_sync_008') - expect(prepareFile(fpath, "")).assertTrue() - let text = "0123456789abcdefg"; + let fpath = nextFileName('fileio_test_stream_write_sync_008'); + expect(prepareFile(fpath, '')).assertTrue(); + let text = '0123456789abcdefg'; try { - let ss = fileio.createStreamSync(fpath, "r+") - expect(ss !== null).assertTrue() + let ss = fileio.createStreamSync(fpath, 'r+'); + expect(ss !== null).assertTrue(); let wlen = ss.writeSync(text, { length: text.length - }) - expect(wlen == text.length).assertTrue() - expect(ss.closeSync() !== null).assertTrue() - ss = fileio.createStreamSync(fpath, "r+") - let rlen = ss.readSync(new ArrayBuffer(4096)) - expect(rlen == text.length).assertTrue() - expect(ss.closeSync() !== null).assertTrue() - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - } catch (e) { - console.log("fileio_test_stream_write_sync_008 has failed for " + e) - expect(null).assertFail() + }); + expect(wlen == text.length).assertTrue(); + expect(ss.closeSync() !== null).assertTrue(); + ss = fileio.createStreamSync(fpath, 'r+'); + let rlen = ss.readSync(new ArrayBuffer(4096)); + expect(rlen == text.length).assertTrue(); + expect(ss.closeSync() !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_stream_write_sync_008 has failed for ' + e); + expect(null).assertFail(); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_stream_WriteSync_0900 @@ -1632,18 +1720,19 @@ describe('fileIOTestStream', function () { * @tc.desc Function of API, invaild fcontent. */ it('fileio_test_stream_write_sync_009', 0, function () { - let fpath = nextFileName('fileio_test_stream_write_sync_009') - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + let fpath = nextFileName('fileio_test_stream_write_sync_009'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); try { - var ss = fileio.createStreamSync(fpath, "r+") - expect(ss !== null).assertTrue() - ss.writeSync(-1) - expect(null).assertFail() - } catch (e) { - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - console.log("fileio_test_stream_write_sync_009 has failed for " + e) + var ss = fileio.createStreamSync(fpath, 'r+'); + expect(ss !== null).assertTrue(); + ss.writeSync(-1); + expect(null).assertFail(); + } + catch (e) { + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + console.log('fileio_test_stream_write_sync_009 has failed for ' + e); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_stream_WriteSync_1000 @@ -1651,21 +1740,22 @@ describe('fileIOTestStream', function () { * @tc.desc Function of API, invaild encoding. */ it('fileio_test_stream_write_sync_010', 0, function () { - let fpath = nextFileName('fileio_test_stream_write_sync_010') - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + let fpath = nextFileName('fileio_test_stream_write_sync_010'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); try { - var ss = fileio.createStreamSync(fpath, "r+") - expect(ss !== null).assertTrue() + var ss = fileio.createStreamSync(fpath, 'r+'); + expect(ss !== null).assertTrue(); expect(ss.writeSync(FILE_CONTENT, { - encoding: "" - }) == null).assertTrue() - expect(null).assertFail() - } catch (e) { - console.log("fileio_test_stream_write_sync_010 has failed for " + e) - expect(ss.closeSync() !== null).assertTrue() - expect(fileio.unlinkSync(fpath) !== null).assertTrue() + encoding: '' + }) == null).assertTrue(); + expect(null).assertFail(); + } + catch (e) { + console.log('fileio_test_stream_write_sync_010 has failed for ' + e); + expect(ss.closeSync() !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_stream_WriteSync_1100 @@ -1673,21 +1763,22 @@ describe('fileIOTestStream', function () { * @tc.desc Function of API, invaild position. */ it('fileio_test_stream_write_sync_011', 0, function () { - let fpath = nextFileName('fileio_test_stream_write_sync_011') - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + let fpath = nextFileName('fileio_test_stream_write_sync_011'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); try { - var ss = fileio.createStreamSync(fpath, "r+") - expect(ss !== null).assertTrue() + var ss = fileio.createStreamSync(fpath, 'r+'); + expect(ss !== null).assertTrue(); expect(ss.writeSync(FILE_CONTENT, { position: -1 - }) == null).assertTrue() - expect(null).assertFail() - } catch (e) { - console.log("fileio_test_stream_write_sync_011 has failed for " + e) - expect(ss.closeSync() !== null).assertTrue() - expect(fileio.unlinkSync(fpath) !== null).assertTrue() + }) == null).assertTrue(); + expect(null).assertFail(); + } + catch (e) { + console.log('fileio_test_stream_write_sync_011 has failed for ' + e); + expect(ss.closeSync() !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_stream_WriteSync_1200 @@ -1695,21 +1786,76 @@ describe('fileIOTestStream', function () { * @tc.desc Function of API, invaild offset. */ it('fileio_test_stream_write_sync_012', 0, function () { - let fpath = nextFileName('fileio_test_stream_write_sync_012') - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + let fpath = nextFileName('fileio_test_stream_write_sync_012'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); try { - var ss = fileio.createStreamSync(fpath, "r+") - expect(ss !== null).assertTrue() + var ss = fileio.createStreamSync(fpath, 'r+'); + expect(ss !== null).assertTrue(); expect(ss.writeSync(FILE_CONTENT, { offset: -1 - }) == null).assertTrue() - expect(null).assertFail() - } catch (e) { - console.log("fileio_test_stream_write_sync_012 has failed for " + e) - expect(ss.closeSync() !== null).assertTrue() - expect(fileio.unlinkSync(fpath) !== null).assertTrue() + }) == null).assertTrue(); + expect(null).assertFail(); + } + catch (e) { + console.log('fileio_test_stream_write_sync_012 has failed for ' + e); + expect(ss.closeSync() !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_stream_WriteSync_1300 + * @tc.name fileio_test_stream_write_sync_013 + * @tc.desc Function of API, Set all parameters. + */ + it('fileio_test_stream_write_sync_013', 0, function () { + let fpath = nextFileName('fileio_test_stream_write_sync_013'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let text = '0123456789abcdefg'; + try { + let ss = fileio.createStreamSync(fpath, 'r+'); + expect(ss !== null).assertTrue(); + expect(ss.writeSync(text, { + encoding: 'utf-8', + position: 0, + offset: 1, + length: 1, + }) == 1).assertTrue(); + expect(ss.closeSync() !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + console.log('---fileio_test_stream_write_sync_013 is passed!'); + } + catch (e) { + console.log('fileio_test_stream_write_sync_013 has failed for ' + e); + expect(null).assertFail(); } - }) + }); + + /** + * @tc.number SUB_STORAGE_FileIO_stream_WriteSync_1400 + * @tc.name fileio_test_stream_write_sync_014 + * @tc.desc Function of API, Set all parameters. + */ + it('fileio_test_stream_write_sync_014', 0, function () { + let fpath = nextFileName('fileio_test_stream_write_sync_014'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let text = '0123456789abcdefg'; + try { + let ss = fileio.createStreamSync(fpath, 'r+'); + expect(ss !== null).assertTrue(); + expect(ss.writeSync(text, { + offset: 2, + length: 2, + }) == 2).assertTrue(); + expect(ss.closeSync() !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + console.log('---fileio_test_stream_write_sync_014 is passed!'); + } + catch (e) { + console.log('fileio_test_stream_write_sync_014 has failed for ' + e); + expect(null).assertFail(); + } + }); /** * @tc.number SUB_STORAGE_FileIO_stream_write_read_4k_sync @@ -1717,27 +1863,28 @@ describe('fileIOTestStream', function () { * @tc.desc Function of API, read 4k file. */ it('fileio_test_stream_write_read_4k_sync', 0, function () { - let fpath = nextFileName('fileio_test_stream_write_read_4k_sync') - expect(prepareFile(fpath, "a")).assertTrue() - expect(fileToWriteOnly(fpath)).assertTrue() - try { - let fd = fileio.openSync(fpath, 0o001) - expect(fd !== null).assertTrue() - let ss = fileio.fdopenStreamSync(fd, "w") - expect(ss !== null).assertTrue() - expect(ss.writeSync(randomString(4096)) !== null).assertTrue() - expect(ss.closeSync() !== null).assertTrue() - expect(fileToReadOnly(fpath)).assertTrue() - ss = fileio.createStreamSync(fpath, "r") - let rlen = ss.readSync(new ArrayBuffer(4096)) - expect(fileio.closeSync(fd) !== null).assertTrue() - expect(ss.closeSync() !== null).assertTrue() - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - } catch (e) { - console.log("fileio_test_stream_write_read_4k_sync has failed for " + e) - expect(null).assertFail() - } - }) + let fpath = nextFileName('fileio_test_stream_write_read_4k_sync'); + expect(prepareFile(fpath, 'a')).assertTrue(); + expect(fileToWriteOnly(fpath)).assertTrue(); + try { + let fd = fileio.openSync(fpath, 0o001); + expect(fd !== null).assertTrue(); + let ss = fileio.fdopenStreamSync(fd, 'w'); + expect(ss !== null).assertTrue(); + expect(ss.writeSync(randomString(4096)) !== null).assertTrue(); + expect(ss.closeSync() !== null).assertTrue(); + expect(fileToReadOnly(fpath)).assertTrue(); + ss = fileio.createStreamSync(fpath, 'r'); + let rlen = ss.readSync(new ArrayBuffer(4096)); + expect(fileio.closeSync(fd) !== null).assertTrue(); + expect(ss.closeSync() !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_stream_write_read_4k_sync has failed for ' + e); + expect(null).assertFail(); + } + }); /** * @tc.number SUB_STORAGE_FileIO_stream_FlushSync_0000 @@ -1745,21 +1892,22 @@ describe('fileIOTestStream', function () { * @tc.desc Function of API, flushSync. */ it('fileio_test_stream_flush_sync_000', 0, function () { - let fpath = nextFileName('fileio_test_stream_flush_sync_000') - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() - let text = "0123456789abcdefg"; - try { - let ss = fileio.createStreamSync(fpath, "r+") - expect(ss !== null).assertTrue() - expect(ss.writeSync(text) == text.length).assertTrue() - expect(ss.flushSync() !== null).assertTrue() - expect(ss.closeSync() !== null).assertTrue() - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - } catch (e) { - console.log("fileio_test_stream_flush_sync_001 has failed for " + e) - expect(null).assertFail() + let fpath = nextFileName('fileio_test_stream_flush_sync_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let text = '0123456789abcdefg'; + try { + let ss = fileio.createStreamSync(fpath, 'r+'); + expect(ss !== null).assertTrue(); + expect(ss.writeSync(text) == text.length).assertTrue(); + expect(ss.flushSync() !== null).assertTrue(); + expect(ss.closeSync() !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_stream_flush_sync_001 has failed for ' + e); + expect(null).assertFail(); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_stream_FlushSync_0100 @@ -1767,19 +1915,20 @@ describe('fileIOTestStream', function () { * @tc.desc Function of API, error. */ it('fileio_test_stream_flush_sync_001', 0, function () { - let fpath = nextFileName('fileio_test_stream_flush_sync_001') - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + let fpath = nextFileName('fileio_test_stream_flush_sync_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); try { - let ss = fileio.createStreamSync(fpath, "r+") - expect(ss !== null).assertTrue() - expect(ss.closeSync() !== null).assertTrue() - ss.flushSync() - expect(null).assertFail() - } catch (e) { - console.log("fileio_test_stream_flush_sync_001 has failed for " + e) - expect(fileio.unlinkSync(fpath) !== null).assertTrue() + let ss = fileio.createStreamSync(fpath, 'r+'); + expect(ss !== null).assertTrue(); + expect(ss.closeSync() !== null).assertTrue(); + ss.flushSync(); + expect(null).assertFail(); + } + catch (e) { + console.log('fileio_test_stream_flush_sync_001 has failed for ' + e); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); } - }) + }); /** * @tc.number SUB_STORAGE_FileIO_stream_CloseSync_0000 @@ -1787,35 +1936,37 @@ describe('fileIOTestStream', function () { * @tc.desc Function of API, closeSync. */ it('fileio_test_stream_close_sync_000', 0, function () { - let fpath = nextFileName('fileio_test_stream_close_sync_000') - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() - try { - let ss = fileio.createStreamSync(fpath, "r+") - expect(ss.closeSync() !== null).assertTrue() - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - } catch (e) { - console.log("fileio_test_stream_close_sync_000 has failed for " + e) - expect(null).assertFail() + let fpath = nextFileName('fileio_test_stream_close_sync_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let ss = fileio.createStreamSync(fpath, 'r+'); + expect(ss.closeSync() !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + } + catch (e) { + console.log('fileio_test_stream_close_sync_000 has failed for ' + e); + expect(null).assertFail(); } - }) - + }); + /** * @tc.number SUB_STORAGE_FileIO_stream_CloseSync_0100 * @tc.name fileio_test_stream_close_sync_001 * @tc.desc Function of API, error. */ it('fileio_test_stream_close_sync_001', 0, function () { - let fpath = nextFileName('fileio_test_stream_close_sync_001') - expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + let fpath = nextFileName('fileio_test_stream_close_sync_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); let ss; try { - ss = fileio.createStreamSync(fpath, "r+") - expect(ss.closeSync() !== null).assertTrue() - expect(ss.closeSync() == null).assertTrue() - expect(null).assertFail() - } catch (e) { - expect(fileio.unlinkSync(fpath) !== null).assertTrue() - console.log("fileio_test_stream_close_sync_001 has failed for " + e) + ss = fileio.createStreamSync(fpath, 'r+'); + expect(ss.closeSync() !== null).assertTrue(); + expect(ss.closeSync() == null).assertTrue(); + expect(null).assertFail(); + } + catch (e) { + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + console.log('fileio_test_stream_close_sync_001 has failed for ' + e); } - }) -}) \ No newline at end of file + }); +}); diff --git a/storage/storagefileiojstest/project/entry/src/main/js/test/List.test.js b/storage/storagefileiojstest/project/entry/src/main/js/test/List.test.js index e8dcb6983c538ff31bc98cef1e83b2ca8224c7f2..57ae4964dd88c49806a29228a631113db7c35ae6 100644 --- a/storage/storagefileiojstest/project/entry/src/main/js/test/List.test.js +++ b/storage/storagefileiojstest/project/entry/src/main/js/test/List.test.js @@ -18,4 +18,4 @@ require('./FileIO.test.js') require('./FileIODir.test.js') require('./FileIODirent.test.js') require('./FileIOStat.test.js') -require('./FileIOStream.test.js') \ No newline at end of file +require('./FileIOStream.test.js') diff --git a/storage/storagefileiojstest/project/entry/src/main/resources/base/element/string.json b/storage/storagefileiojstest/project/entry/src/main/resources/base/element/string.json deleted file mode 100644 index 2f9470d82c49675a64972657d8d367cd95e51c63..0000000000000000000000000000000000000000 --- a/storage/storagefileiojstest/project/entry/src/main/resources/base/element/string.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "string": [ - { - "name": "app_name", - "value": "MyApplication" - }, - { - "name": "mainability_description", - "value": "JS_Phone_Empty Feature Ability" - } - ] -} \ No newline at end of file diff --git a/storage/storagefileiojstest/project/entry/src/main/resources/base/media/icon.png b/storage/storagefileiojstest/project/entry/src/main/resources/base/media/icon.png deleted file mode 100644 index ce307a8827bd75456441ceb57d530e4c8d45d36c..0000000000000000000000000000000000000000 Binary files a/storage/storagefileiojstest/project/entry/src/main/resources/base/media/icon.png and /dev/null differ diff --git a/storage/storagefileioperformancejstest/BUILD.gn b/storage/storagefileioperformancejstest/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..f5d8af0217e1bf0d868e7388214321243a786fda --- /dev/null +++ b/storage/storagefileioperformancejstest/BUILD.gn @@ -0,0 +1,18 @@ +# 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("//test/xts/tools/build/suite.gni") + +ohos_js_hap_suite("storagefileioperformance_js_test") { + test_hap_name = "storagefileioperformancejstest" + hap_source_path = "hap/entry-debug-rich-signed.hap" +} diff --git a/storage/storagefileioperformancejstest/Test.json b/storage/storagefileioperformancejstest/Test.json new file mode 100644 index 0000000000000000000000000000000000000000..253ff0c8cf772e2969eb192efac5bc3695d51c71 --- /dev/null +++ b/storage/storagefileioperformancejstest/Test.json @@ -0,0 +1,18 @@ +{ + "description": "Configuration for storage file and fileio Tests", + "driver": { + "type": "JSUnitTest", + "test-timeout": "21600000", + "package": "ohos.acts.stroage.fileio", + "shell-timeout": "21600000" + }, + "kits": [ + { + "test-file-name": [ + "storagefileioperformancejstest.hap" + ], + "type": "AppInstallKit", + "cleanup-apps": true + } + ] +} \ No newline at end of file diff --git a/storage/storagefileioperformancejstest/hap/entry-debug-rich-signed.hap b/storage/storagefileioperformancejstest/hap/entry-debug-rich-signed.hap new file mode 100644 index 0000000000000000000000000000000000000000..3b621d08132b7cc25888edbd1d8688ad3dea4b56 Binary files /dev/null and b/storage/storagefileioperformancejstest/hap/entry-debug-rich-signed.hap differ diff --git a/storage/storagefileioperformancejstest/project/entry/package.json b/storage/storagefileioperformancejstest/project/entry/package.json new file mode 100644 index 0000000000000000000000000000000000000000..4cf06fee5959d788e6cb205ae961a5c1cacd65b9 --- /dev/null +++ b/storage/storagefileioperformancejstest/project/entry/package.json @@ -0,0 +1,6 @@ +{ + "devDependencies": { + "chai": "^4.3.4", + "mocha": "^9.0.1" + } +} diff --git a/storage/storagefileioperformancejstest/project/entry/src/main/config.json b/storage/storagefileioperformancejstest/project/entry/src/main/config.json new file mode 100644 index 0000000000000000000000000000000000000000..12fda07721102cdd208f3d9021a250592706579a --- /dev/null +++ b/storage/storagefileioperformancejstest/project/entry/src/main/config.json @@ -0,0 +1,62 @@ +{ + "app": { + "bundleName": "ohos.acts.stroage.fileio", + "vendor": "example", + "version": { + "code": 1000000, + "name": "1.0.0" + }, + "apiVersion": { + "compatible": 4, + "target": 5, + "releaseType": "Release" + } + }, + "deviceConfig": {}, + "module": { + "package": "ohos.acts.stroage.fileio", + "name": ".MyApplication", + "deviceType": [ + "phone" + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "entry", + "moduleType": "entry", + "installationFree": true + }, + "abilities": [ + { + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ], + "name": "ohos.acts.stroage.fileio.MainAbility", + "icon": "$media:icon", + "description": "$string:mainability_description", + "label": "$string:app_name", + "type": "page", + "launchType": "standard", + "visible": true + } + ], + "js": [ + { + "pages": [ + "pages/index/index" + ], + "name": "default", + "window": { + "designWidth": 720, + "autoDesignWidth": false + } + } + ] + } +} \ No newline at end of file diff --git a/storage/storagefileioperformancejstest/project/entry/src/main/js/default/app.js b/storage/storagefileioperformancejstest/project/entry/src/main/js/default/app.js new file mode 100644 index 0000000000000000000000000000000000000000..5fefaead87d0899fd7e07a2f2241a40bfd298339 --- /dev/null +++ b/storage/storagefileioperformancejstest/project/entry/src/main/js/default/app.js @@ -0,0 +1,8 @@ +export default { + onCreate() { + console.info('ohos.acts.distributeddatamgr.distributedfile onCreate'); + }, + onDestroy() { + console.info('ohos.acts.distributeddatamgr.distributedfile onCreate'); + } +}; diff --git a/storage/storagefileioperformancejstest/project/entry/src/main/js/default/i18n/en-US.json b/storage/storagefileioperformancejstest/project/entry/src/main/js/default/i18n/en-US.json new file mode 100644 index 0000000000000000000000000000000000000000..ead52ed2e09ec82aaf7aa9f4e714ed39ea88308e --- /dev/null +++ b/storage/storagefileioperformancejstest/project/entry/src/main/js/default/i18n/en-US.json @@ -0,0 +1,6 @@ +{ + "strings": { + "hello": "Hello", + "world": "Test" + } +} \ No newline at end of file diff --git a/storage/storagefileioperformancejstest/project/entry/src/main/js/default/i18n/zh-CN.json b/storage/storagefileioperformancejstest/project/entry/src/main/js/default/i18n/zh-CN.json new file mode 100644 index 0000000000000000000000000000000000000000..3f48f2585b24a8fe4a745e8ee2972a9e991a7803 --- /dev/null +++ b/storage/storagefileioperformancejstest/project/entry/src/main/js/default/i18n/zh-CN.json @@ -0,0 +1,6 @@ +{ + "strings": { + "hello": "您好", + "world": "测试" + } +} \ No newline at end of file diff --git a/storage/storagefileioperformancejstest/project/entry/src/main/js/default/pages/index/index.css b/storage/storagefileioperformancejstest/project/entry/src/main/js/default/pages/index/index.css new file mode 100644 index 0000000000000000000000000000000000000000..6fda792753f2e15f22b529c7b90a82185b2770bf --- /dev/null +++ b/storage/storagefileioperformancejstest/project/entry/src/main/js/default/pages/index/index.css @@ -0,0 +1,9 @@ +.container { + flex-direction: column; + justify-content: center; + align-items: center; +} + +.title { + font-size: 100px; +} diff --git a/storage/storagefileioperformancejstest/project/entry/src/main/js/default/pages/index/index.hml b/storage/storagefileioperformancejstest/project/entry/src/main/js/default/pages/index/index.hml new file mode 100644 index 0000000000000000000000000000000000000000..f64b040a5ae394dbaa5e185e1ecd4f4556b92184 --- /dev/null +++ b/storage/storagefileioperformancejstest/project/entry/src/main/js/default/pages/index/index.hml @@ -0,0 +1,5 @@ +
+ + {{ $t('strings.hello') }} {{ title }} + +
diff --git a/storage/storagefileioperformancejstest/project/entry/src/main/js/default/pages/index/index.js b/storage/storagefileioperformancejstest/project/entry/src/main/js/default/pages/index/index.js new file mode 100644 index 0000000000000000000000000000000000000000..572ce6e94d0cd867a15eb94b1b7b0da9497a99b3 --- /dev/null +++ b/storage/storagefileioperformancejstest/project/entry/src/main/js/default/pages/index/index.js @@ -0,0 +1,38 @@ +/* + * 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 file from '@system.file' +import app from '@system.app' + +import {Core} from 'deccjsunit/index' +export default { + 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() { + }, +} \ No newline at end of file diff --git a/storage/storagefileioperformancejstest/project/entry/src/main/js/test/Common.js b/storage/storagefileioperformancejstest/project/entry/src/main/js/test/Common.js new file mode 100644 index 0000000000000000000000000000000000000000..c5bc08482173733896e49c8fab5239bef520ee7c --- /dev/null +++ b/storage/storagefileioperformancejstest/project/entry/src/main/js/test/Common.js @@ -0,0 +1,170 @@ +/* + * 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 '@system.fileio' + +export const FILE_CONTENT = 'hello world' + +export function prepareFile(fpath, content) { + try { + let fd = fileio.openSync(fpath, 0o102, 0o666) + fileio.ftruncateSync(fd) + fileio.writeSync(fd, content) + fileio.fsyncSync(fd) + fileio.closeSync(fd) + return true + } + catch (e) { + console.log('Failed to prepareFile for ' + e) + return false + } +} +export function prepareFile1(fpath, content) { + try { + let fd = fileio.openSync(fpath, 0o102, 0o777) + fileio.ftruncateSync(fd) + fileio.writeSync(fd, content) + fileio.fsyncSync(fd) + fileio.closeSync(fd) + return true + } + catch (e) { + console.log('Failed to prepareFile for ' + e) + return false + } +} +export function prepareEmptyFile(fpath) { + try { + let fd = fileio.openSync(fpath, 0o102, 0o777) + fileio.closeSync(fd) + return true + } + catch (e) { + console.log('Failed to prepareFile for ' + e) + return false + } +} +export function fileToReadOnly(fpath) { + try { + let fd = fileio.openSync(fpath, 0o1) + fileio.fchmodSync(fd, 0o444) + fileio.fsyncSync(fd) + fileio.closeSync(fd) + return true + } + catch (e) { + console.log('Failed to fileToReadOnly for ' + e); + return false + } +} +export function fileToWriteOnly(fpath) { + try { + let fd = fileio.openSync(fpath, 0o2) + fileio.fchmodSync(fd, 0o222) + fileio.fsyncSync(fd) + fileio.closeSync(fd) + return true + } + catch (e) { + console.log('Failed to fileToWriteOnly ' + e) + return false + } +} +export function fileToReadAndWrite(fpath) { + try { + let fd = fileio.openSync(fpath, 0o1) + fileio.fchmodSync(fd, 0o777) + fileio.fsyncSync(fd) + fileio.closeSync(fd) + return true + } + catch (e) { + console.log('Failed to fileToReadAndWrite ' + e); + return false + } +} +export function appName(testName) { + const BASE_PATH = '/data/accounts/account_0/appdata/ohos.acts.stroage.fileio/' + return BASE_PATH + testName +} +export function nextFileName(testName) { + const BASE_PATH = '/data/accounts/account_0/appdata/ohos.acts.stroage.fileio/cache/' + return BASE_PATH + testName +} +export function fileName(testName) { + const BASE_PATH = '/data/accounts/account_0/appdata/ohos.acts.stroage.fileio/files/' + return BASE_PATH + testName +} +export function cacheFileName(testName) { + const BASE_PATH = '/data/accounts/account_0/appdata/ohos.acts.stroage.fileio/files/cache/' + return BASE_PATH + testName +} +export function differentFileName(testName) { + const BASE_PATH = '/data/accounts/account_0/ohos.acts.distributeddatamgr.distributedfile/' + return BASE_PATH + testName +} +export function differentCacheName(testName) { + const BASE_PATH = '/data/accounts/account_0/ohos.acts.distributeddatamgr.distributedfile/cache/' + return BASE_PATH + testName +} + +export function getFileTextLen(fpath) { + let ss + try { + ss = fileio.Stream.createStreamSync(fpath, 'r+') + expect(ss !== null).assertTrue() + let len = ss.readSync(new ArrayBuffer(4096)) + console.log('file:' + fpath) + console.log('file lenth:' + len) + expect(ss.closeSync() !== null).assertTrue() + return len + } + catch (e) { + console.log('Failed to getFileTextLen ' + e) + expect(ss.closeSync() !== null).assertTrue() + return null + } +} +export function isFileExist(fpath) { + try { + expect(fileio.accessSync(fpath) !== null).assertTrue() + console.log('file:' + fpath) + console.log('status:exist') + return true + } + catch (e) { + console.log('file:' + fpath) + console.log('status:non-existen') + return false + } +} +export function sleep(n) { + var start = new Date().getTime(); + while (true) { + if (new Date().getTime() - start > n) { + break; + } + } +} +export function randomString(num) { + let len= num; + var $chars = 'aaaabbbbcccc'; + var maxPos = $chars.length; + var pwd = ''; + for (var i = 0; i < len; i++) { + pwd += $chars.charAt(Math.floor(Math.random() * maxPos)); + } + return pwd; +} diff --git a/storage/storagefileioperformancejstest/project/entry/src/main/js/test/FileIOPerformance.js b/storage/storagefileioperformancejstest/project/entry/src/main/js/test/FileIOPerformance.js new file mode 100644 index 0000000000000000000000000000000000000000..ba0281b42e96c01f5f0bf33e53e464f383e76896 --- /dev/null +++ b/storage/storagefileioperformancejstest/project/entry/src/main/js/test/FileIOPerformance.js @@ -0,0 +1,494 @@ +/* + * 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 '@system.fileio' +import { + describe, + it, +} + from 'deccjsunit/index' +import { + FILE_CONTENT, + prepareFile, + nextFileName, + sleep, + randomString +} + from './Common' + +describe('fileTest', function () { + + /** + * @tc.number SUB_STORAGE_fileioPerformance_Dir_Dirent + * @tc.name fileioPerformance_Dir_Dirent + * @tc.desc Dirent Perform 1000 performance tests + */ + it('fileioPerformance_Dir_Dirent', 0, function () { + for (let i = 0; i < 1000; i++) { + let dpath = nextFileName('fileioPerformance_Dir') + 'd' + let fpath = dpath + '/f0' + fileio.mkdirSync(dpath); + prepareFile(fpath, FILE_CONTENT); + let start = new Date().getTime(); + let dd = fileio.opendirSync(dpath); + let end = new Date().getTime(); + let time = end - start; + console.log('fileioPerformance_Dir,opendirSync:' + dd + ', time:' + time + ',' + i); + let start1 = new Date().getTime(); + let dirent = dd.readSync(); + let end1 = new Date().getTime(); + let time1 = end1 - start1; + console.log('fileioPerformance_Dir,readSync:' + dirent + ', time1:' + time1 + ',' + i); + let start5 = new Date().getTime(); + let isBlockDevice = dirent.isBlockDevice(); + let end5 = new Date().getTime(); + let time5 = end5 - start5; + console.log('fileioPerformance_Dirent,isBlockDevice:' + isBlockDevice + ', time5:' + time5 + ',' + i); + let start6 = new Date().getTime(); + let isCharacterDevice = dirent.isCharacterDevice(); + let end6 = new Date().getTime(); + let time6 = end6 - start6; + console.log('fileioPerformance_Dirent,isCharacterDevice:' + isCharacterDevice + ', time6:' + time6 + ',' + i); + let start7 = new Date().getTime(); + let isDirectory = dirent.isDirectory(); + let end7 = new Date().getTime(); + let time7 = end7 - start7; + console.log('fileioPerformance_Dirent,isDirectory:' + isDirectory + ', time7:' + time7 + ',' + i); + let start8 = new Date().getTime(); + let isFIFO = dirent.isFIFO(); + let end8 = new Date().getTime(); + let time8 = end8 - start8; + console.log('fileioPerformance_Dirent,isFIFO:' + isFIFO + ', time8:' + time8 + ',' + i); + let start9 = new Date().getTime(); + let isFile = dirent.isFile(); + let end9 = new Date().getTime(); + let time9 = end9 - start9; + console.log('fileioPerformance_Dirent,isFile:' + isFile + ', time9:' + time9 + ',' + i); + let start1000 = new Date().getTime(); + let isSocket = dirent.isSocket(); + let end1000 = new Date().getTime(); + let time1000 = end1000 - start1000; + console.log('fileioPerformance_Dirent,isSocket:' + isSocket + ', time1000:' + time1000 + ',' + i); + let start12 = new Date().getTime(); + let isSymbolicLink = dirent.isSymbolicLink(); + let end12 = new Date().getTime(); + let time12 = end12 - start12; + console.log('fileioPerformance_Dirent,isSymbolicLink:' + isSymbolicLink + ', time12:' + time12 + ',' + i); + let start2 = new Date().getTime(); + let result = dd.closeSync(); + let end2 = new Date().getTime(); + let time2 = end2 - start2; + console.log('fileioPerformance_Dir,closeSync:' + result + ', time2:' + time2 + ',' + i); + let start3 = new Date().getTime(); + let unlinkSync = fileio.unlinkSync(fpath); + let end3 = new Date().getTime(); + let time3 = end3 - start3; + console.log('fileioPerformance_prop,unlinkSync:' + unlinkSync + ', time3:' + time3 + ',' + i); + let start4 = new Date().getTime(); + let rmdirSync = fileio.rmdirSync(dpath); + let end4 = new Date().getTime(); + let time4 = end4 - start4 + console.log('fileioPerformance_prop,rmdirSync:' + rmdirSync + ', time4:' + time4 + ',' + i); + } + sleep(3000); + }); + + /** + * @tc.number SUB_STORAGE_fileioPerformance_stat + * @tc.name fileioPerformance_stat + * @tc.desc Stat Perform 1000 performance tests + */ + it('fileioPerformance_stat', 0, function () { + for (let i = 0; i < 1000; i++) { + let fpath = nextFileName('fileioPerformance_stat-4k'); + let txt = randomString(4096); + prepareFile(fpath, txt); + let start0 = new Date().getTime(); + let stat = fileio.statSync(fpath); + let end0 = new Date().getTime(); + let time0 = end0 - start0; + console.log('stat,statSync:' + stat + ', time0:' + time0 + ',' + i); + let start = new Date().getTime(); + let isBlockDevice = stat.isBlockDevice(); + let end = new Date().getTime(); + let time = end - start; + console.log('stat,isBlockDevice:' + isBlockDevice + ', time:' + time + ',' + i); + let start1 = new Date().getTime(); + let isCharacterDevice = stat.isCharacterDevice(); + let end1 = new Date().getTime(); + let time1 = end1 - start1; + console.log('stat,isCharacterDevice:' + isCharacterDevice + ', time1:' + time1 + ',' + i); + let start2 = new Date().getTime(); + let isDirectory = stat.isDirectory(); + let end2 = new Date().getTime(); + let time2 = end2 - start2; + console.log('stat,isDirectory:' + isDirectory + ', time2:' + time2 + ',' + i); + let start3 = new Date().getTime(); + let isFIFO = stat.isFIFO(); + let end3 = new Date().getTime(); + let time3 = end3 - start3; + console.log('stat,isFIFO:' + isFIFO + ', time3:' + time3 + ',' + i); + let start4 = new Date().getTime(); + let isFile = stat.isFile(); + let end4 = new Date().getTime(); + let time4 = end4 - start4; + console.log('stat,isFile:' + isFile + ', time4:' + time4 + ',' + i); + let start5 = new Date().getTime(); + let isSocket = stat.isSocket(); + let end5 = new Date().getTime(); + let time5 = end5 - start5; + console.log('stat,isSocket:' + isSocket + ', time5:' + time5 + ',' + i); + let start6 = new Date().getTime(); + let isSymbolicLink = stat.isSymbolicLink(); + let end6 = new Date().getTime(); + let time6 = end6 - start6; + console.log('stat,isSymbolicLink:' + isSymbolicLink + ', time6:' + time6 + ',' + i); + } + sleep(3000); + }); + + /** + * @tc.number SUB_STORAGE_fileioPerformance_prop + * @tc.name fileioPerformance_prop + * @tc.desc Prop Perform 1000 performance tests + */ + it('fileioPerformance_prop', 0, function () { + let dpath = nextFileName('fileioPerformance_Dir') + 'd' + for (let i = 0; i < 1000; i++) { + let start0 = new Date().getTime(); + let mkdirSync = fileio.mkdirSync(dpath + i); + let end0 = new Date().getTime(); + let time0 = end0 - start0; + console.log('fileioPerformance_prop_mkdirSync,mkdirSync:' + mkdirSync + ', time0:' + time0 + ',' + i); + } + for (let i = 0; i < 1000; i++) { + prepareFile(dpath + '999/f0' + i, randomString(4096)); + } + let fd; + for (let i = 0; i < 1000; i++) { + let start = new Date().getTime(); + fd = fileio.openSync(dpath + '999/f0' + i, 0o102, 0o666); + let end = new Date().getTime(); + let time = end - start + console.log('fileioPerformance_prop_openSync,openSync:' + fd + ', time:' + time + ',' + i); + } + for (let i = 0; i < 1000; i++) { + let accessSync; + let start1 = new Date().getTime(); + accessSync = fileio.accessSync(dpath + '999/f0' + i); + let end1 = new Date().getTime(); + let time1 = end1 - start1; + console.log('fileioPerformance_prop_accessSync,accessSync:' + accessSync + ', time1:' + time1 + ',' + i); + } + for (let i = 0; i < 1000; i++) { + let chmodSync; + let start5 = new Date().getTime(); + chmodSync = fileio.chmodSync(dpath + '999/f0' + i, 0o660); + let end5 = new Date().getTime(); + let time5 = end5 - start5; + console.log('fileioPerformance_prop_chmodSync,chmodSync:' + chmodSync + ', time5:' + time5 + ',' + i); + } + let stat = fileio.Stat.statSync(dpath + '999/f0999'); + for (let i = 0; i < 1000; i++) { + let chownSync; + let start6 = new Date().getTime(); + chownSync = fileio.chownSync(dpath + '999/f0' + i, stat.uid, stat.gid); + let end6 = new Date().getTime(); + let time6 = end6 - start6; + console.log('fileioPerformance_prop_chownSync,chownSync:' + chownSync + ', time6:' + time6 + ',' + i); + } + for (let i = 0; i < 1000; i++) { + let copyFileSync; + let start7 = new Date().getTime(); + copyFileSync = fileio.copyFileSync(dpath + '999/f0' + i, dpath + '998/f0' + i); + let end7 = new Date().getTime(); + let time7 = end7 - start7; + console.log('fileioPerformance_prop_copyFileSync,copyFileSync:' + copyFileSync + ', time7:' + time7 + ',' + i); + } + for (let i = 0; i < 1000; i++) { + let fchmodSync; + let start8 = new Date().getTime(); + fchmodSync = fileio.fchmodSync(fd, 0o660); + let end8 = new Date().getTime(); + let time8 = end8 - start8; + console.log('fileioPerformance_prop_fchmodSync,fchmodSync:' + fchmodSync + ', time8:' + time8 + ',' + i); + } + for (let i = 0; i < 1000; i++) { + let fchownSync; + let start9 = new Date().getTime(); + fchownSync = fileio.fchownSync(fd, stat.uid, stat.gid); + let end9 = new Date().getTime(); + let time9 = end9 - start9; + console.log('fileioPerformance_prop_fchownSync,fchownSync:' + fchownSync + ', time9:' + time9 + ',' + i); + } + for (let i = 0; i < 1000; i++) { + let fstatSync; + let start1000 = new Date().getTime(); + fstatSync = fileio.fstatSync(fd); + let end1000 = new Date().getTime(); + let time1000 = end1000 - start1000; + console.log('fileioPerformance_prop_fstatSync,fstatSync:' + fstatSync + ', time1000:' + time1000 + ',' + i); + } + for (let i = 0; i < 1000; i++) { + let ftruncateSync; + let start12 = new Date().getTime(); + ftruncateSync = fileio.ftruncateSync(fd); + let end12 = new Date().getTime(); + let time12 = end12 - start12; + console.log('fileioPerformance_prop_ftruncateSync,:' + ftruncateSync + ', time12:' + time12 + ',' + i); + } + for (let i = 0; i < 1000; i++) { + let renameSync; + let start13 = new Date().getTime(); + renameSync = fileio.renameSync(dpath + '998/f0' + i, dpath + '998/f0' + i + 'a'); + let end13 = new Date().getTime(); + let time13 = end13 - start13; + console.log('fileioPerformance_prop_renameSync,renameSync:' + renameSync + ', time13:' + time13 + ',' + i); + } + for (let i = 0; i < 1000; i++) { + let truncateSync; + let start14 = new Date().getTime(); + truncateSync = fileio.truncateSync(dpath + '998/f0' + i + 'a', 1000); + let end14 = new Date().getTime(); + let time14 = end14 - start14; + console.log('fileioPerformance_prop_truncateSync,truncateSync:' + truncateSync + ', time14:' + time14 + ',' + i); + } + for (let i = 0; i < 1000; i++) { + let fsyncSync; + let start16 = new Date().getTime(); + fsyncSync = fileio.fsyncSync(fd); + let end16 = new Date().getTime(); + let time16 = end16 - start16; + console.log('fileioPerformance_prop_fsyncSync,fsyncSync:' + fsyncSync + ', time16:' + time16 + ',' + i); + } + for (let i = 0; i < 1000; i++) { + let closeSync; + let start2 = new Date().getTime(); + let fd1 = fileio.openSync(dpath + '999/f0' + i, 0o102, 0o666); + closeSync = fileio.closeSync(fd1); + let end2 = new Date().getTime(); + let time2 = end2 - start2; + console.log('fileioPerformance_prop_closeSync,closeSync:' + closeSync + ', time2:' + time2 + ',' + i); + } + sleep(3000); + }); + + /** + * @tc.number SUB_STORAGE_fileioPerformance_prop_write_read + * @tc.name fileioPerformance_prop_write_read + * @tc.desc Prop_write_read Perform 1000 performance tests + */ + it('fileioPerformance_prop_write_read', 0, function () { + for (let i = 0; i < 1000; i++) { + let dpath = nextFileName('prop_write_read') + 'd'; + let fpath = dpath + '/prop_write_read'; + fileio.mkdirSync(dpath); + prepareFile(fpath, 'a'); + let fd = fileio.openSync(fpath, 0o102, 0o666); + let data = randomString(4096); + let start17 = new Date().getTime(); + let writeSync = fileio.writeSync(fd, data); + let end17 = new Date().getTime(); + let time17 = end17 - start17; + console.log('fileioPerformance_prop_write,4K_prop_writeSync:' + writeSync + ', time17:' + time17 + ',' + i); + let readSync; + let start18 = new Date().getTime(); + writeSync = fileio.readSync(fd, new ArrayBuffer(4096)); + let end18 = new Date().getTime(); + let time18 = end18 - start18; + console.log('fileioPerformance_prop_readSync,4K_prop_readSync:' + readSync + ', time18:' + time18 + ',' + i); + fileio.closeSync(fd); + fileio.unlinkSync(fpath); + fileio.rmdirSync(dpath); + } + }); + + /** + * @tc.number SUB_STORAGE_fileioPerformance_stream + * @tc.name fileioPerformance_stream + * @tc.desc Stream Perform 1000 performance tests + */ + it('fileioPerformance_stream', 0, function () { + let fpath = nextFileName('fileioPerformance_stream4K'); + let txt = randomString(4096); + prepareFile(fpath, txt); + for (let i = 0; i < 1000; i++) { + let fd = fileio.openSync(fpath, 0o2); + let start = new Date().getTime(); + let ss = fileio.fdopenStreamSync(fd, 'r+'); + let end = new Date().getTime(); + let time = end - start; + console.log('fileioPerformance_stream,fdopenStreamSync(r+):' + ss + ', time:' + time + ',' + i); + fileio.closeSync(fd); + ss.closeSync(); + } + for (let i = 0; i < 1000; i++) { + let fd0 = fileio.openSync(fpath, 0o2); + let start0 = new Date().getTime(); + let ss0 = fileio.fdopenStreamSync(fd0, 'rb+'); + let end0 = new Date().getTime(); + let time0 = end0 - start0; + console.log('fileioPerformance_stream,fdopenStreamSync(rb+):' + ss0 + ', time0:' + time0 + ',' + i); + fileio.closeSync(fd0); + ss0.closeSync(); + } + for (let i = 0; i < 1000; i++) { + let start1 = new Date().getTime(); + let createFlag0 = fileio.createStreamSync(fpath, 'r+'); + let end1 = new Date().getTime(); + let time1 = end1 - start1; + console.log('fileioPerformance_stream,createStreamSync(r+):' + createFlag0 + ', time1:' + time1 + ',' + i); + createFlag0.closeSync(); + } + for (let i = 0; i < 1000; i++) { + let start2 = new Date().getTime(); + let createFlag = fileio.createStreamSync(fpath, 'rb+'); + let end2 = new Date().getTime(); + let time2 = end2 - start2; + console.log('fileioPerformance_stream,createStreamSync(rb+):' + createFlag + ', time2:' + time2 + ',' + i); + } + for (let i = 0; i < 1000; i++) { + let createFlag = fileio.createStreamSync(fpath, 'r+'); + let start3 = new Date().getTime(); + let readSync = createFlag.readSync(new ArrayBuffer(4096)); + let end3 = new Date().getTime(); + let time3 = end3 - start3 + console.log('fileioPerformance_stream,readSync:' + readSync + ', time3:' + time3 + ',' + i); + createFlag.closeSync(); + } + for (let i = 0; i < 1000; i++) { + let createFlag = fileio.createStreamSync(fpath, 'r+'); + let start4 = new Date().getTime(); + let flushSync = createFlag.flushSync(); + let end4 = new Date().getTime(); + let time4 = end4 - start4 + console.log('fileioPerformance_stream,flushSync:' + flushSync + ', time4:' + time4 + ',' + i); + createFlag.closeSync(); + } + for (let i = 0; i < 1000; i++) { + let createFlag = fileio.createStreamSync(fpath, 'r+'); + let start5 = new Date().getTime(); + let closeSync = createFlag.closeSync(); + let end5 = new Date().getTime(); + let time5 = end5 - start5 + console.log('fileioPerformance_stream,closeSync:' + closeSync + ', time5:' + time5 + ',' + i); + } + sleep(3000); + }); + + /** + * @tc.number SUB_STORAGE_fileioPerformance_stream_write_read + * @tc.name fileioPerformance_stream_write_read + * @tc.desc Stream_write_read Perform 1000 performance tests + */ + it('fileioPerformance_stream_write_read_4K', 0, function () { + let fpath = nextFileName('stream_write_read'); + for (let i = 0; i < 1000; i++) { + let ws = fileio.createStreamSync(fpath, 'w'); + let data = randomString(4096); + let start1 = new Date().getTime(); + let writeSync = ws.writeSync(data); + let end1 = new Date().getTime(); + let time1 = end1 - start1 + console.log('fileioPerformance_stream_write,4K_stream_writeSync:' + writeSync + ', time1:' + time1 + ',' + i); + ws.closeSync(); + } + sleep(3000); + for (let i = 0; i < 1000; i++) { + let rs = fileio.createStreamSync(fpath, 'r'); + let start2 = new Date().getTime(); + let readSync = rs.readSync(new ArrayBuffer(4096)); + let end2 = new Date().getTime(); + let time2 = end2 - start2 + console.log('fileioPerformance_stream_readSync,4K_stream_readSync:' + readSync + ', time2:' + time2 + ',' + i); + rs.closeSync(); + } + sleep(3000); + }); + + /** + * @tc.number SUB_STORAGE_fileioPerformance_stream_write_read + * @tc.name fileioPerformance_stream_write_read + * @tc.desc Stream_write_read Perform ROM remaining less than 10% of the total + */ + it('fileioPerformance_stream_write_read', 0, function () { + let fpath = nextFileName('stream_write_read'); + let data; + for (let i = 0; i < 1024; i++) { + data = data + randomString(1024); + } + for (let i = 0; i < 1000; i++) { + let ws = fileio.createStreamSync(fpath, 'w'); + let start1 = new Date().getTime(); + let writeSync = ws.writeSync(data); + let end1 = new Date().getTime(); + let time1 = end1 - start1; + console.log('fileioPerformance_stream_write,1M_stream_writeSync:' + writeSync + ', time1:' + time1 + ',' + i); + let rs = fileio.createStreamSync(fpath, 'r'); + let start2 = new Date().getTime(); + let readSync = rs.readSync(new ArrayBuffer(1048576)); + let end2 = new Date().getTime(); + let time2 = end2 - start2 + console.log('fileioPerformance_stream_readSync,1M_stream_readSync:' + readSync + ', time2:' + time2 + ',' + i); + ws.closeSync(); + fileio.unlinkSync(fpath); + } + }); + + /** + * @tc.number SUB_STORAGE_fileioPerformance_prop_copyFile + * @tc.name fileioPerformance_prop_copyFile + * @tc.desc 0.5G Synchronous opening performance test of test files + * The path needs to be manually placed in advance + * data/accounts/account_0/appdata/ohos.acts.distributeddatamgr.distributedfile/cache/p1'的0.5g文件) + */ + it('fileioPerformance_prop_copyFile', 0, function () { + console.log('---fileioPerformance_prop_copyFile 0.5G---start---'); + let fpath = nextFileName('p1'); + let fpathTarget = nextFileName('p2'); + for (let i = 0; i < 1000; i++) { + let start2 = new Date().getTime(); + let copyFileSync = fileio.copyFileSync(fpath, fpathTarget); + let end2 = new Date().getTime(); + let time2 = end2 - start2 + console.log('fileioPerformance_prop_copyFileSync,copyFileSync:' + copyFileSync + ', time2:' + time2 + ',' + i); + fileio.unlinkSync(fpathTarget); + sleep(300); + } + fileio.closeSync(fd); + sleep(3000); + }); + + /** + * @tc.number SUB_STORAGE_fileioPerformance_prop_openSync + * @tc.name fileioPerformance_prop_openSync + * @tc.desc 0.5G Synchronous opening performance test of test files + * The path needs to be manually placed in advance + * data/accounts/account_0/appdata/ohos.acts.distributeddatamgr.distributedfile/cache/p1'的0.5g文件) + */ + it('fileioPerformance_prop_openSync', 0, function () { + console.log('---fileioPerformance_prop_openSync 0.5G---start---'); + let fpath = nextFileName('p1'); + let fd + for (let i = 0; i < 1000; i++) { + let start = new Date().getTime(); + fd = fileio.openSync(fpath, 0o2002); + let end = new Date().getTime(); + let time = end - start + console.log('fileioPerformance_prop_openSync,openSync:' + fd + ', time:' + time + ',' + i); + } + fileio.closeSync(fd); + sleep(3000); + }); +}); diff --git a/storage/storagefileioperformancejstest/project/entry/src/main/js/test/FilePerformance.js b/storage/storagefileioperformancejstest/project/entry/src/main/js/test/FilePerformance.js new file mode 100644 index 0000000000000000000000000000000000000000..c7eef3f2a400014b9464b000fc1bffa1e8ec524d --- /dev/null +++ b/storage/storagefileioperformancejstest/project/entry/src/main/js/test/FilePerformance.js @@ -0,0 +1,439 @@ +/* + * 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 file from '@system.file'; +import fileio from '@ohos.fileio'; +import { + describe, + it, + expect +} + from 'deccjsunit/index' +import { + randomString +} + from './Common' + +describe('fileTest', function () { + + /** + * @tc.number SUB_STORAGE_File_mkdir_1100 + * @tc.name File_mkdir_011 + * @tc.desc Function of API, Run 1000 times to obtain each running time. + */ + it('File_mkdir_011', 0, async function (done) { + let start = new Date().getTime(); + for (let i = 0; i < 1000; i++) { + file.mkdir({ + uri: 'internal://app/File_mkdir_011' + i, + success: function () { + let end = new Date().getTime(); + let time = end - start; + console.log('-------File_mkdir_011 call mkdir success, time:' + time + ',' + i); + start = new Date().getTime(); + done(); + }, + fail: function (data, code) { + console.log('-------File_mkdir_011 call mkdir fail! code:' + code + ', data' + data); + expect(null).assertFail(); + }, + }); + } + }); + + /** + * @tc.number SUB_STORAGE_File_access_1100 + * @tc.name File_access_011 + * @tc.desc Function of API, Run 1000 times to obtain each running time. + */ + it('File_access_011', 0, async function (done) { + let start = new Date().getTime(); + for (let i = 0; i < 1000; i++) { + file.access({ + uri: 'internal://app/File_mkdir_011' + i, + success: function () { + let end = new Date().getTime(); + let time = end - start; + console.log('-------File_access_011 call access success, time:' + time + ',' + i); + start = new Date().getTime(); + done(); + }, + fail: function (data, code) { + console.log('-------File_access_011 call access fail! code:' + code + ', data' + data); + expect(null).assertFail(); + }, + }); + } + }); + + /** + * @tc.number SUB_STORAGE_File_rmdir_1100 + * @tc.name File_rmdir_011 + * @tc.desc Function of API, Run 1000 times to obtain each running time. + */ + it('File_rmdir_011', 0, async function (done) { + let start = new Date().getTime(); + for (let i = 0; i < 1000; i++) { + file.rmdir({ + uri: 'internal://app/File_mkdir_011' + i, + success: function () { + let end = new Date().getTime(); + let time = end - start; + console.log('-------File_rmdir_011 call rmdir success, time:' + time + ',' + i); + start = new Date().getTime(); + done(); + }, + fail: function (data, code) { + console.log('-------File_rmdir_011 call rmdir fail! code:' + code + ', data' + data); + expect(null).assertFail(); + }, + }); + } + }); + + /** + * @tc.number SUB_STORAGE_File_Copy_1500 + * @tc.name File_Copy_015 + * @tc.desc Function of API, Run 1000 times to obtain each running time. + */ + it('File_Copy_015', 0, function (done) { + file.writeText({ + uri: 'internal://app/File_Copy_015', + text: 'hello', + success: function () { + console.log('File_Copy_015 call writeText success'); + done(); + }, + fail: function (data, code) { + console.log('File_Copy_015 call writeText fail! code:' + code + ', data' + data); + expect(null).assertFail(); + }, + }); + let start = new Date().getTime(); + for (let i = 0; i < 1000; i++) { + file.copy({ + srcUri: 'internal://app/File_Copy_015', + dstUri: 'internal://app/File_Copy_015_1' + i, + success: function () { + let end = new Date().getTime(); + let time = end - start; + console.log('-------File_Copy_015 call copy success, time:' + time + ',' + i); + start = new Date().getTime(); + done(); + }, + fail: function (data, code) { + console.log('-------File_Copy_015 call copy fail! code:' + code + ', data' + data); + expect(null).assertFail(); + }, + }); + } + file.delete({ + uri: 'internal://app/File_Copy_015', + success: function () { + console.log('-------File_Copy_015 call delete success.'); + done(); + }, + fail: function (data, code) { + console.log('-------File_Copy_015 call delete fail! code:' + code + ', data' + data); + expect(null).assertFail(); + }, + }); + }); + + /** + * @tc.number SUB_STORAGE_File_Delete_1100 + * @tc.name File_Delete_011 + * @tc.desc Function of API, Run 1000 times to obtain each running time. + */ + it('File_Delete_011', 0, function (done) { + let start = new Date().getTime(); + for (let i = 0; i < 1000; i++) { + file.delete({ + uri: 'internal://app/File_Copy_015_1' + i, + success: function () { + let end = new Date().getTime(); + let time = end - start; + console.log('-------File_Delete_011 call delete success, time:' + time + ',' + i); + start = new Date().getTime(); + done(); + }, + fail: function (data, code) { + console.log('-------File_Delete_011 call delete fail! code:' + code + ', data' + data); + expect(null).assertFail(); + }, + }); + } + }); + + /** + * @tc.number SUB_STORAGE_File_List_1300 + * @tc.name File_List_013 + * @tc.desc Function of API, Run 1000 times to obtain each running time. + */ + it('File_List_013', 0, async function (done) { + file.writeText({ + uri: 'internal://app/File_List_013', + text: 'Text that just for test.', + success: function () { + console.log('File_List_013 call writeText success.'); + done(); + }, + fail: function (data, code) { + console.error('File_List_013 call writeText fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + let start = new Date().getTime(); + for (let i = 0; i <= 1000; i++) { + file.list({ + uri: 'internal://app/', + success: function () { + let end = new Date().getTime(); + let time = end - start; + console.log('File_List_013 Difference time:' + time + ',' + i); + start = new Date().getTime(); + done(); + }, + fail: function (data, code) { + console.error('File_List_013 call list fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + } + }); + + /** + * @tc.number SUB_STORAGE_File_List_1400 + * @tc.name File_List_014 + * @tc.desc Function of API, Run 1000 times to obtain each running time. + */ + it('File_List_014', 0, async function (done) { + for (let i = 0; i < 1000; i++) { + file.writeText({ + uri: 'internal://app/File_List_014' + i, + text: 'Text that just for test.', + success: function () { + console.log('File_List_014 call writeText success.'); + done(); + }, + fail: function (data, code) { + console.error('File_List_014 call writeText fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + } + let start = new Date().getTime(); + for (let i = 0; i <= 1000; i++) { + file.list({ + uri: 'internal://app/', + success: function () { + let end = new Date().getTime(); + let time = end - start; + console.log('File_List_014 Difference time:' + time + ',' + i); + start = new Date().getTime(); + done(); + }, + fail: function (data, code) { + console.error('File_List_014 call list fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + } + }); + + /** + * @tc.number SUB_STORAGE_File_Get_1500 + * @tc.name File_Get_015 + * @tc.desc Function of API, Run 1000 times to obtain each running time. + */ + it('File_Get_015', 0, async function (done) { + file.writeText({ + uri: 'internal://app/File_Get_015', + text: 'Text that just for test.', + success: function () { + console.log('File_Get_015 call writeText success.'); + done(); + }, + fail: function (data, code) { + console.error('File_Get_015 call writeText fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + let start = new Date().getTime(); + for (let i = 0; i <= 1000; i++) { + file.get({ + uri: 'internal://app/File_Get_015', + success: function () { + let end = new Date().getTime(); + let time = end - start; + console.log('File_Get_015 Difference time:' + time + ',' + i); + start = new Date().getTime(); + done(); + }, + fail: function (data, code) { + console.error('File_Get_015 call get fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + } + }); + + /** + * @tc.number SUB_STORAGE_File_Get_1600 + * @tc.name File_Get_016 + * @tc.desc Function of API, Run 1000 times to obtain each running time. + */ + it('File_Get_016', 0, async function (done) { + for (let i = 0; i < 1000; i++) { + file.writeText({ + uri: 'internal://app/File_Get_016' + i, + text: 'Text that just for test.', + success: function () { + console.log('File_Get_016 call writeText success.'); + done(); + }, + fail: function (data, code) { + console.error('File_Get_016 call writeText fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + } + let start = new Date().getTime(); + for (let i = 0; i <= 1000; i++) { + file.get({ + uri: 'internal://app/File_Get_016' + i, + success: function (data) { + console.log(data.uri); + let end = new Date().getTime(); + let time = end - start; + console.log('File_Get_016 Difference time:' + time + ',' + i); + start = new Date().getTime(); + done(); + }, + fail: function (data, code) { + console.error('File_Get_016 call get fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + } + }); + + /** + * @tc.number SUB_STORAGE_File_writeText_1400 + * @tc.name File_writeText_014 + * @tc.desc Function of API, Run 1000 times to obtain each running time. + */ + it('File_writeText_014', 0, async function (done) { + let text = randomString(4096); + let start = new Date().getTime(); + for (let i = 0; i <= 1000; i++) { + file.writeText({ + uri: 'internal://app/File_writeText_014', + text: text, + success: function () { + let end = new Date().getTime(); + let time = end - start; + console.log('File_writeText_014 4K Difference time:' + time + ',' + i); + start = new Date().getTime(); + done(); + }, + fail: function (data, code) { + console.error('File_writeText_014 call writeText fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + } + }); + + /** + * @tc.number SUB_STORAGE_File_readText_1000 + * @tc.name File_readText_010 + * @tc.desc Function of API, Run 1000 times to obtain each running time. + */ + it('File_readText_010', 0, async function (done) { + let start = new Date().getTime(); + for (let i = 0; i <= 1000; i++) { + file.readText({ + uri: 'internal://app/File_writeText_014', + success: function () { + let end = new Date().getTime(); + let time = end - start; + console.log('File_readText_010 4K Difference time:' + time + ',' + i); + start = new Date().getTime(); + done(); + }, + fail: function (data, code) { + console.log('File_readText_010 call readText fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + } + }); + + /** + * @tc.number SUB_STORAGE_File_writeArrayBuffer_1300 + * @tc.name File_writeArrayBuffer_013 + * @tc.desc Function of API, Run 1000 times to obtain each running time. + */ + it('File_writeArrayBuffer_013', 0, async function (done) { + let buf = new Uint8Array(4096); + for (let i = 0; i < 4096; i++) { + buf[i] = 100 + } + let start = new Date().getTime(); + for (let i = 0; i <= 1000; i++) { + file.writeArrayBuffer({ + uri: 'internal://app/File_writeArrayBuffer_013', + buffer: buf, + success: function () { + console.log('call writeArrayBuffer success.'); + let end = new Date().getTime(); + let time = end - start; + console.log('File_writeArrayBuffer_013 4K Difference time:' + time + ',' + i); + start = new Date().getTime(); + done(); + }, + fail: function (data, code) { + console.error('File_writeArrayBuffer_013 call writeArrayBuffer fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + } + }); + + /** + * @tc.number SUB_STORAGE_File_readArrayBuffer_1200 + * @tc.name File_readArrayBuffer_012 + * @tc.desc Function of API, Run 1000 times to obtain each running time. + */ + it('File_readArrayBuffer_012', 0, async function (done) { + let start = new Date().getTime(); + for (let i = 0; i <= 1000; i++) { + file.readArrayBuffer({ + uri: 'internal://app/File_writeArrayBuffer_013', + success: function () { + let end = new Date().getTime(); + let time = end - start; + console.log('File_readArrayBuffer_012 4K Difference time:' + time + ',' + i); + start = new Date().getTime(); + done(); + }, + fail: function (data, code) { + console.error('File_readArrayBuffer_012 call readArrayBuffer fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + } + }); +}); diff --git a/storage/storagefileioperformancejstest/project/entry/src/main/js/test/List.test.js b/storage/storagefileioperformancejstest/project/entry/src/main/js/test/List.test.js new file mode 100644 index 0000000000000000000000000000000000000000..2d7e8c31e676076e65642e01dac568bcda53e2f7 --- /dev/null +++ b/storage/storagefileioperformancejstest/project/entry/src/main/js/test/List.test.js @@ -0,0 +1,17 @@ +/* + * 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('./FileIOPerformance.js') +require('./FilePerformance.js') diff --git a/storage/storagefileioreliabilityjstest/BUILD.gn b/storage/storagefileioreliabilityjstest/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..94515f31467bd1bfbbb940589e2737c57e81e4a0 --- /dev/null +++ b/storage/storagefileioreliabilityjstest/BUILD.gn @@ -0,0 +1,18 @@ +# 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("//test/xts/tools/build/suite.gni") + +ohos_js_hap_suite("storagefileioreliability_js_test") { + test_hap_name = "storagefileioreliabilityjstest" + hap_source_path = "hap/entry-debug-rich-signed.hap" +} diff --git a/storage/storagefileioreliabilityjstest/Test.json b/storage/storagefileioreliabilityjstest/Test.json new file mode 100644 index 0000000000000000000000000000000000000000..cedc584baa3e37eabe7404eac6240ee198de806f --- /dev/null +++ b/storage/storagefileioreliabilityjstest/Test.json @@ -0,0 +1,18 @@ +{ + "description": "Configuration for storage file and fileio Tests", + "driver": { + "type": "JSUnitTest", + "test-timeout": "21600000", + "package": "ohos.acts.stroage.fileio", + "shell-timeout": "21600000" + }, + "kits": [ + { + "test-file-name": [ + "storagefileioreliabilityjstest.hap" + ], + "type": "AppInstallKit", + "cleanup-apps": true + } + ] +} \ No newline at end of file diff --git a/storage/storagefileioreliabilityjstest/hap/entry-debug-rich-signed.hap b/storage/storagefileioreliabilityjstest/hap/entry-debug-rich-signed.hap new file mode 100644 index 0000000000000000000000000000000000000000..6a7ca362364ac887040c065553ad2422c7a2bbfe Binary files /dev/null and b/storage/storagefileioreliabilityjstest/hap/entry-debug-rich-signed.hap differ diff --git a/storage/storagefileioreliabilityjstest/project/entry/package.json b/storage/storagefileioreliabilityjstest/project/entry/package.json new file mode 100644 index 0000000000000000000000000000000000000000..4cf06fee5959d788e6cb205ae961a5c1cacd65b9 --- /dev/null +++ b/storage/storagefileioreliabilityjstest/project/entry/package.json @@ -0,0 +1,6 @@ +{ + "devDependencies": { + "chai": "^4.3.4", + "mocha": "^9.0.1" + } +} diff --git a/storage/storagefileioreliabilityjstest/project/entry/src/main/config.json b/storage/storagefileioreliabilityjstest/project/entry/src/main/config.json new file mode 100644 index 0000000000000000000000000000000000000000..12fda07721102cdd208f3d9021a250592706579a --- /dev/null +++ b/storage/storagefileioreliabilityjstest/project/entry/src/main/config.json @@ -0,0 +1,62 @@ +{ + "app": { + "bundleName": "ohos.acts.stroage.fileio", + "vendor": "example", + "version": { + "code": 1000000, + "name": "1.0.0" + }, + "apiVersion": { + "compatible": 4, + "target": 5, + "releaseType": "Release" + } + }, + "deviceConfig": {}, + "module": { + "package": "ohos.acts.stroage.fileio", + "name": ".MyApplication", + "deviceType": [ + "phone" + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "entry", + "moduleType": "entry", + "installationFree": true + }, + "abilities": [ + { + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ], + "name": "ohos.acts.stroage.fileio.MainAbility", + "icon": "$media:icon", + "description": "$string:mainability_description", + "label": "$string:app_name", + "type": "page", + "launchType": "standard", + "visible": true + } + ], + "js": [ + { + "pages": [ + "pages/index/index" + ], + "name": "default", + "window": { + "designWidth": 720, + "autoDesignWidth": false + } + } + ] + } +} \ No newline at end of file diff --git a/storage/storagefileioreliabilityjstest/project/entry/src/main/js/default/app.js b/storage/storagefileioreliabilityjstest/project/entry/src/main/js/default/app.js new file mode 100644 index 0000000000000000000000000000000000000000..5fefaead87d0899fd7e07a2f2241a40bfd298339 --- /dev/null +++ b/storage/storagefileioreliabilityjstest/project/entry/src/main/js/default/app.js @@ -0,0 +1,8 @@ +export default { + onCreate() { + console.info('ohos.acts.distributeddatamgr.distributedfile onCreate'); + }, + onDestroy() { + console.info('ohos.acts.distributeddatamgr.distributedfile onCreate'); + } +}; diff --git a/storage/storagefileioreliabilityjstest/project/entry/src/main/js/default/i18n/en-US.json b/storage/storagefileioreliabilityjstest/project/entry/src/main/js/default/i18n/en-US.json new file mode 100644 index 0000000000000000000000000000000000000000..ead52ed2e09ec82aaf7aa9f4e714ed39ea88308e --- /dev/null +++ b/storage/storagefileioreliabilityjstest/project/entry/src/main/js/default/i18n/en-US.json @@ -0,0 +1,6 @@ +{ + "strings": { + "hello": "Hello", + "world": "Test" + } +} \ No newline at end of file diff --git a/storage/storagefileioreliabilityjstest/project/entry/src/main/js/default/i18n/zh-CN.json b/storage/storagefileioreliabilityjstest/project/entry/src/main/js/default/i18n/zh-CN.json new file mode 100644 index 0000000000000000000000000000000000000000..3f48f2585b24a8fe4a745e8ee2972a9e991a7803 --- /dev/null +++ b/storage/storagefileioreliabilityjstest/project/entry/src/main/js/default/i18n/zh-CN.json @@ -0,0 +1,6 @@ +{ + "strings": { + "hello": "您好", + "world": "测试" + } +} \ No newline at end of file diff --git a/storage/storagefileioreliabilityjstest/project/entry/src/main/js/default/pages/index/index.css b/storage/storagefileioreliabilityjstest/project/entry/src/main/js/default/pages/index/index.css new file mode 100644 index 0000000000000000000000000000000000000000..6fda792753f2e15f22b529c7b90a82185b2770bf --- /dev/null +++ b/storage/storagefileioreliabilityjstest/project/entry/src/main/js/default/pages/index/index.css @@ -0,0 +1,9 @@ +.container { + flex-direction: column; + justify-content: center; + align-items: center; +} + +.title { + font-size: 100px; +} diff --git a/storage/storagefileioreliabilityjstest/project/entry/src/main/js/default/pages/index/index.hml b/storage/storagefileioreliabilityjstest/project/entry/src/main/js/default/pages/index/index.hml new file mode 100644 index 0000000000000000000000000000000000000000..f64b040a5ae394dbaa5e185e1ecd4f4556b92184 --- /dev/null +++ b/storage/storagefileioreliabilityjstest/project/entry/src/main/js/default/pages/index/index.hml @@ -0,0 +1,5 @@ +
+ + {{ $t('strings.hello') }} {{ title }} + +
diff --git a/storage/storagefileioreliabilityjstest/project/entry/src/main/js/default/pages/index/index.js b/storage/storagefileioreliabilityjstest/project/entry/src/main/js/default/pages/index/index.js new file mode 100644 index 0000000000000000000000000000000000000000..572ce6e94d0cd867a15eb94b1b7b0da9497a99b3 --- /dev/null +++ b/storage/storagefileioreliabilityjstest/project/entry/src/main/js/default/pages/index/index.js @@ -0,0 +1,38 @@ +/* + * 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 file from '@system.file' +import app from '@system.app' + +import {Core} from 'deccjsunit/index' +export default { + 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() { + }, +} \ No newline at end of file diff --git a/storage/storagefileioreliabilityjstest/project/entry/src/main/js/test/Common.js b/storage/storagefileioreliabilityjstest/project/entry/src/main/js/test/Common.js new file mode 100644 index 0000000000000000000000000000000000000000..c5bc08482173733896e49c8fab5239bef520ee7c --- /dev/null +++ b/storage/storagefileioreliabilityjstest/project/entry/src/main/js/test/Common.js @@ -0,0 +1,170 @@ +/* + * 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 '@system.fileio' + +export const FILE_CONTENT = 'hello world' + +export function prepareFile(fpath, content) { + try { + let fd = fileio.openSync(fpath, 0o102, 0o666) + fileio.ftruncateSync(fd) + fileio.writeSync(fd, content) + fileio.fsyncSync(fd) + fileio.closeSync(fd) + return true + } + catch (e) { + console.log('Failed to prepareFile for ' + e) + return false + } +} +export function prepareFile1(fpath, content) { + try { + let fd = fileio.openSync(fpath, 0o102, 0o777) + fileio.ftruncateSync(fd) + fileio.writeSync(fd, content) + fileio.fsyncSync(fd) + fileio.closeSync(fd) + return true + } + catch (e) { + console.log('Failed to prepareFile for ' + e) + return false + } +} +export function prepareEmptyFile(fpath) { + try { + let fd = fileio.openSync(fpath, 0o102, 0o777) + fileio.closeSync(fd) + return true + } + catch (e) { + console.log('Failed to prepareFile for ' + e) + return false + } +} +export function fileToReadOnly(fpath) { + try { + let fd = fileio.openSync(fpath, 0o1) + fileio.fchmodSync(fd, 0o444) + fileio.fsyncSync(fd) + fileio.closeSync(fd) + return true + } + catch (e) { + console.log('Failed to fileToReadOnly for ' + e); + return false + } +} +export function fileToWriteOnly(fpath) { + try { + let fd = fileio.openSync(fpath, 0o2) + fileio.fchmodSync(fd, 0o222) + fileio.fsyncSync(fd) + fileio.closeSync(fd) + return true + } + catch (e) { + console.log('Failed to fileToWriteOnly ' + e) + return false + } +} +export function fileToReadAndWrite(fpath) { + try { + let fd = fileio.openSync(fpath, 0o1) + fileio.fchmodSync(fd, 0o777) + fileio.fsyncSync(fd) + fileio.closeSync(fd) + return true + } + catch (e) { + console.log('Failed to fileToReadAndWrite ' + e); + return false + } +} +export function appName(testName) { + const BASE_PATH = '/data/accounts/account_0/appdata/ohos.acts.stroage.fileio/' + return BASE_PATH + testName +} +export function nextFileName(testName) { + const BASE_PATH = '/data/accounts/account_0/appdata/ohos.acts.stroage.fileio/cache/' + return BASE_PATH + testName +} +export function fileName(testName) { + const BASE_PATH = '/data/accounts/account_0/appdata/ohos.acts.stroage.fileio/files/' + return BASE_PATH + testName +} +export function cacheFileName(testName) { + const BASE_PATH = '/data/accounts/account_0/appdata/ohos.acts.stroage.fileio/files/cache/' + return BASE_PATH + testName +} +export function differentFileName(testName) { + const BASE_PATH = '/data/accounts/account_0/ohos.acts.distributeddatamgr.distributedfile/' + return BASE_PATH + testName +} +export function differentCacheName(testName) { + const BASE_PATH = '/data/accounts/account_0/ohos.acts.distributeddatamgr.distributedfile/cache/' + return BASE_PATH + testName +} + +export function getFileTextLen(fpath) { + let ss + try { + ss = fileio.Stream.createStreamSync(fpath, 'r+') + expect(ss !== null).assertTrue() + let len = ss.readSync(new ArrayBuffer(4096)) + console.log('file:' + fpath) + console.log('file lenth:' + len) + expect(ss.closeSync() !== null).assertTrue() + return len + } + catch (e) { + console.log('Failed to getFileTextLen ' + e) + expect(ss.closeSync() !== null).assertTrue() + return null + } +} +export function isFileExist(fpath) { + try { + expect(fileio.accessSync(fpath) !== null).assertTrue() + console.log('file:' + fpath) + console.log('status:exist') + return true + } + catch (e) { + console.log('file:' + fpath) + console.log('status:non-existen') + return false + } +} +export function sleep(n) { + var start = new Date().getTime(); + while (true) { + if (new Date().getTime() - start > n) { + break; + } + } +} +export function randomString(num) { + let len= num; + var $chars = 'aaaabbbbcccc'; + var maxPos = $chars.length; + var pwd = ''; + for (var i = 0; i < len; i++) { + pwd += $chars.charAt(Math.floor(Math.random() * maxPos)); + } + return pwd; +} diff --git a/storage/storagefileioreliabilityjstest/project/entry/src/main/js/test/FileIOReliability.js b/storage/storagefileioreliabilityjstest/project/entry/src/main/js/test/FileIOReliability.js new file mode 100644 index 0000000000000000000000000000000000000000..102751321098d5c71c0eb6d3e6216ae7d4eeb980 --- /dev/null +++ b/storage/storagefileioreliabilityjstest/project/entry/src/main/js/test/FileIOReliability.js @@ -0,0 +1,188 @@ +/* + * 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 '@system.fileio' +import { + describe, + it, + expect +} + from 'deccjsunit/index' +import { + FILE_CONTENT, + prepareFile, + nextFileName, + sleep +} + from './Common' + +describe('fileIOReliability', function () { + + /** + * @tc.number SUB_STORAGE_fileIOReliability_dir + * @tc.name fileIOReliability_dir + * @tc.desc Dir Reliability Test + */ + it('fileIOReliability_dir', 0, function () { + for (let i = 0; i < 100000; i++) { + try { + let dpath = nextFileName('fileIOReliability') + 'd'; + fileio.mkdirSync(dpath); + let fpath = dpath + '/f1'; + prepareFile(fpath, FILE_CONTENT); + let dd = fileio.opendirSync(dpath); + dd.readSync(); + dd.closeSync(); + fileio.unlinkSync(fpath); + fileio.rmdirSync(dpath); + sleep(300); + } + catch (e) { + console.log('fileIOReliability_dir has failed for ' + e); + expect(null).assertFail(); + } + } + }); + + /** + * @tc.number SUB_STORAGE_fileIOReliability_dirent + * @tc.name fileIOReliability_dirent + * @tc.desc Dirent Reliability Test + */ + it('fileIOReliability_dirent', 0, function () { + for (let i = 0; i < 100000; i++) { + try { + let dpath = nextFileName('fileIOReliability') + 'd'; + fileio.mkdirSync(dpath); + let fpath = dpath + '/f1'; + prepareFile(fpath, FILE_CONTENT); + let dd = fileio.opendirSync(dpath); + let dirent = dd.readSync(); + dirent.isBlockDevice(); + dirent.isCharacterDevice(); + dirent.isDirectory(); + dirent.isFIFO(); + dirent.isSocket(); + dirent.isSymbolicLink(); + dd.closeSync(); + fileio.unlinkSync(fpath); + fileio.rmdirSync(dpath); + sleep(300); + } + catch (e) { + console.log('fileIOReliability_dirent has failed for ' + e); + expect(null).assertFail(); + } + } + }); + + /** + * @tc.number SUB_STORAGE_fileIOReliability_stat + * @tc.name fileIOReliability_stat + * @tc.desc Stat Reliability Test + */ + it('fileIOReliability_stat', 0, function () { + for (let i = 0; i < 100000; i++) { + try { + let dpath = nextFileName('fileIOReliability') + 'd'; + fileio.mkdirSync(dpath); + let fpath = dpath + '/f1'; + prepareFile(fpath, FILE_CONTENT); + let stat = fileio.statSync(fpath); + stat.isBlockDevice(); + stat.isCharacterDevice(); + stat.isDirectory(); + stat.isFIFO(); + stat.isSocket(); + stat.isSymbolicLink(); + fileio.unlinkSync(fpath); + fileio.rmdirSync(dpath); + sleep(300); + } + catch (e) { + console.log('fileIOReliability_stat has failed for ' + e); + expect(null).assertFail(); + } + } + }); + + /** + * @tc.number SUB_STORAGE_fileIOReliability_stream + * @tc.name fileIOReliability_stream + * @tc.desc Stream Reliability Test + */ + it('fileIOReliability_stream', 0, function () { + for (let i = 0; i < 100000; i++) { + let fpath = nextFileName('fileIOReliability_stream'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let ss; + try { + let fd = fileio.openSync(fpath, 0o2); + ss = fileio.fdopenStreamSync(fd, 'r+'); + ss.writeSync(FILE_CONTENT); + ss.flushSync(); + ss.closeSync(); + ss = fileio.createStreamSync(fpath, 'r+'); + ss.readSync(new ArrayBuffer(4096)); + ss.closeSync(); + fileio.unlinkSync(fpath); + sleep(300); + } + catch (e) { + console.log('fileIOReliability_stream has failed for ' + e); + expect(null).assertFail(); + } + } + }); + + /** + * @tc.number SUB_STORAGE_fileIOReliability_prop + * @tc.name fileIOReliability_prop + * @tc.desc Prop Reliability Test + */ + it('fileIOReliability_prop', 0, function () { + for (let i = 0; i < 100000; i++) { + try { + let dpath = nextFileName('fileIOReliability') + 'd'; + fileio.mkdirSync(dpath); + let fpath = nextFileName('fileIOReliability'); + let fpathTarget = fpath + 'tgt'; + let fpathTarget1 = fpath + 'tgtt'; + let ff = fileio.openSync(fpath, 0o102, 0o666); + fileio.accessSync(fpath); + fileio.chmodSync(fpath, 0o660); + let stat = fileio.statSync(fpath); + fileio.chownSync(fpath, stat.uid, stat.gid); + fileio.copyFileSync(fpath, fpathTarget); + fileio.fchmodSync(ff, 0o660); + fileio.fchownSync(ff, stat.uid, stat.gid); + fileio.fstatSync(ff); + fileio.ftruncateSync(ff); + fileio.renameSync(fpath, fpathTarget1); + fileio.fsyncSync(ff); + fileio.truncateSync(fpathTarget1); + fileio.writeSync(ff, FILE_CONTENT); + fileio.closeSync(ff); + fileio.unlinkSync(fpathTarget1); + fileio.unlinkSync(fpathTarget); + fileio.rmdirSync(dpath); + sleep(300); + } + catch (e) { + console.log('fileIOReliability_prop has failed for ' + e); + expect(null).assertFail(); + } + } + }); +}); diff --git a/storage/storagefileioreliabilityjstest/project/entry/src/main/js/test/List.test.js b/storage/storagefileioreliabilityjstest/project/entry/src/main/js/test/List.test.js new file mode 100644 index 0000000000000000000000000000000000000000..c04e4626b2c11fa9e346fc26395700aec41ae83a --- /dev/null +++ b/storage/storagefileioreliabilityjstest/project/entry/src/main/js/test/List.test.js @@ -0,0 +1,16 @@ +/* + * 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('./FileIOReliability.js') diff --git a/storage/storagefileiostabilityjstest/BUILD.gn b/storage/storagefileiostabilityjstest/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..0b81565b1d639916b53bfced953783adca47e569 --- /dev/null +++ b/storage/storagefileiostabilityjstest/BUILD.gn @@ -0,0 +1,18 @@ +# 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("//test/xts/tools/build/suite.gni") + +ohos_js_hap_suite("storagefileiostability_js_test") { + test_hap_name = "storagefileiostabilityjstest" + hap_source_path = "hap/entry-debug-rich-signed.hap" +} diff --git a/storage/storagefileiostabilityjstest/Test.json b/storage/storagefileiostabilityjstest/Test.json new file mode 100644 index 0000000000000000000000000000000000000000..bc24f18acba350c0596064bcae83676feaf0b157 --- /dev/null +++ b/storage/storagefileiostabilityjstest/Test.json @@ -0,0 +1,18 @@ +{ + "description": "Configuration for storage file and fileio Tests", + "driver": { + "type": "JSUnitTest", + "test-timeout": "21600000", + "package": "ohos.acts.stroage.fileio", + "shell-timeout": "21600000" + }, + "kits": [ + { + "test-file-name": [ + "storagefileiostabilityjstest.hap" + ], + "type": "AppInstallKit", + "cleanup-apps": true + } + ] +} \ No newline at end of file diff --git a/storage/storagefileiostabilityjstest/hap/entry-debug-rich-signed.hap b/storage/storagefileiostabilityjstest/hap/entry-debug-rich-signed.hap new file mode 100644 index 0000000000000000000000000000000000000000..3debebce74f4e00316c8219268d38d57ca925bad Binary files /dev/null and b/storage/storagefileiostabilityjstest/hap/entry-debug-rich-signed.hap differ diff --git a/storage/storagefileiostabilityjstest/project/entry/package.json b/storage/storagefileiostabilityjstest/project/entry/package.json new file mode 100644 index 0000000000000000000000000000000000000000..4cf06fee5959d788e6cb205ae961a5c1cacd65b9 --- /dev/null +++ b/storage/storagefileiostabilityjstest/project/entry/package.json @@ -0,0 +1,6 @@ +{ + "devDependencies": { + "chai": "^4.3.4", + "mocha": "^9.0.1" + } +} diff --git a/storage/storagefileiostabilityjstest/project/entry/src/main/config.json b/storage/storagefileiostabilityjstest/project/entry/src/main/config.json new file mode 100644 index 0000000000000000000000000000000000000000..12fda07721102cdd208f3d9021a250592706579a --- /dev/null +++ b/storage/storagefileiostabilityjstest/project/entry/src/main/config.json @@ -0,0 +1,62 @@ +{ + "app": { + "bundleName": "ohos.acts.stroage.fileio", + "vendor": "example", + "version": { + "code": 1000000, + "name": "1.0.0" + }, + "apiVersion": { + "compatible": 4, + "target": 5, + "releaseType": "Release" + } + }, + "deviceConfig": {}, + "module": { + "package": "ohos.acts.stroage.fileio", + "name": ".MyApplication", + "deviceType": [ + "phone" + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "entry", + "moduleType": "entry", + "installationFree": true + }, + "abilities": [ + { + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ], + "name": "ohos.acts.stroage.fileio.MainAbility", + "icon": "$media:icon", + "description": "$string:mainability_description", + "label": "$string:app_name", + "type": "page", + "launchType": "standard", + "visible": true + } + ], + "js": [ + { + "pages": [ + "pages/index/index" + ], + "name": "default", + "window": { + "designWidth": 720, + "autoDesignWidth": false + } + } + ] + } +} \ No newline at end of file diff --git a/storage/storagefileiostabilityjstest/project/entry/src/main/js/test/Common.js b/storage/storagefileiostabilityjstest/project/entry/src/main/js/test/Common.js new file mode 100644 index 0000000000000000000000000000000000000000..c5bc08482173733896e49c8fab5239bef520ee7c --- /dev/null +++ b/storage/storagefileiostabilityjstest/project/entry/src/main/js/test/Common.js @@ -0,0 +1,170 @@ +/* + * 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 '@system.fileio' + +export const FILE_CONTENT = 'hello world' + +export function prepareFile(fpath, content) { + try { + let fd = fileio.openSync(fpath, 0o102, 0o666) + fileio.ftruncateSync(fd) + fileio.writeSync(fd, content) + fileio.fsyncSync(fd) + fileio.closeSync(fd) + return true + } + catch (e) { + console.log('Failed to prepareFile for ' + e) + return false + } +} +export function prepareFile1(fpath, content) { + try { + let fd = fileio.openSync(fpath, 0o102, 0o777) + fileio.ftruncateSync(fd) + fileio.writeSync(fd, content) + fileio.fsyncSync(fd) + fileio.closeSync(fd) + return true + } + catch (e) { + console.log('Failed to prepareFile for ' + e) + return false + } +} +export function prepareEmptyFile(fpath) { + try { + let fd = fileio.openSync(fpath, 0o102, 0o777) + fileio.closeSync(fd) + return true + } + catch (e) { + console.log('Failed to prepareFile for ' + e) + return false + } +} +export function fileToReadOnly(fpath) { + try { + let fd = fileio.openSync(fpath, 0o1) + fileio.fchmodSync(fd, 0o444) + fileio.fsyncSync(fd) + fileio.closeSync(fd) + return true + } + catch (e) { + console.log('Failed to fileToReadOnly for ' + e); + return false + } +} +export function fileToWriteOnly(fpath) { + try { + let fd = fileio.openSync(fpath, 0o2) + fileio.fchmodSync(fd, 0o222) + fileio.fsyncSync(fd) + fileio.closeSync(fd) + return true + } + catch (e) { + console.log('Failed to fileToWriteOnly ' + e) + return false + } +} +export function fileToReadAndWrite(fpath) { + try { + let fd = fileio.openSync(fpath, 0o1) + fileio.fchmodSync(fd, 0o777) + fileio.fsyncSync(fd) + fileio.closeSync(fd) + return true + } + catch (e) { + console.log('Failed to fileToReadAndWrite ' + e); + return false + } +} +export function appName(testName) { + const BASE_PATH = '/data/accounts/account_0/appdata/ohos.acts.stroage.fileio/' + return BASE_PATH + testName +} +export function nextFileName(testName) { + const BASE_PATH = '/data/accounts/account_0/appdata/ohos.acts.stroage.fileio/cache/' + return BASE_PATH + testName +} +export function fileName(testName) { + const BASE_PATH = '/data/accounts/account_0/appdata/ohos.acts.stroage.fileio/files/' + return BASE_PATH + testName +} +export function cacheFileName(testName) { + const BASE_PATH = '/data/accounts/account_0/appdata/ohos.acts.stroage.fileio/files/cache/' + return BASE_PATH + testName +} +export function differentFileName(testName) { + const BASE_PATH = '/data/accounts/account_0/ohos.acts.distributeddatamgr.distributedfile/' + return BASE_PATH + testName +} +export function differentCacheName(testName) { + const BASE_PATH = '/data/accounts/account_0/ohos.acts.distributeddatamgr.distributedfile/cache/' + return BASE_PATH + testName +} + +export function getFileTextLen(fpath) { + let ss + try { + ss = fileio.Stream.createStreamSync(fpath, 'r+') + expect(ss !== null).assertTrue() + let len = ss.readSync(new ArrayBuffer(4096)) + console.log('file:' + fpath) + console.log('file lenth:' + len) + expect(ss.closeSync() !== null).assertTrue() + return len + } + catch (e) { + console.log('Failed to getFileTextLen ' + e) + expect(ss.closeSync() !== null).assertTrue() + return null + } +} +export function isFileExist(fpath) { + try { + expect(fileio.accessSync(fpath) !== null).assertTrue() + console.log('file:' + fpath) + console.log('status:exist') + return true + } + catch (e) { + console.log('file:' + fpath) + console.log('status:non-existen') + return false + } +} +export function sleep(n) { + var start = new Date().getTime(); + while (true) { + if (new Date().getTime() - start > n) { + break; + } + } +} +export function randomString(num) { + let len= num; + var $chars = 'aaaabbbbcccc'; + var maxPos = $chars.length; + var pwd = ''; + for (var i = 0; i < len; i++) { + pwd += $chars.charAt(Math.floor(Math.random() * maxPos)); + } + return pwd; +} diff --git a/storage/storagefileiostabilityjstest/project/entry/src/main/js/test/FileIOStability.js b/storage/storagefileiostabilityjstest/project/entry/src/main/js/test/FileIOStability.js new file mode 100644 index 0000000000000000000000000000000000000000..882dcdc18ec3bf76c9df42adf0ae844dded4f846 --- /dev/null +++ b/storage/storagefileiostabilityjstest/project/entry/src/main/js/test/FileIOStability.js @@ -0,0 +1,197 @@ +/* + * 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 '@system.fileio' +import { + describe, + it, + expect +} + from 'deccjsunit/index' +import { + FILE_CONTENT, + prepareFile, + nextFileName, + sleep +} + from './Common' + +describe('fileIOStability', function () { + + /** + * @tc.number SUB_STORAGE_fileIOStability_dir + * @tc.name fileIOStability_dir + * @tc.desc Function of API, 7*24 + */ + it('fileIOStability_dir', 0, function () { + for (let i = 0; i <= 100000; i++) { + try { + let dpath = nextFileName('fileIOStability') + 'd'; + fileio.mkdirSync(dpath); + let fpath = dpath + '/f1'; + prepareFile(fpath, FILE_CONTENT); + let dd = fileio.opendirSync(dpath); + dd.readSync(); + dd.closeSync(); + fileio.unlinkSync(fpath); + fileio.rmdirSync(dpath); + } + catch (e) { + console.log('fileIOStability_dir has failed for ' + e); + expect(null).assertFail(); + } + } + }); + + /** + * @tc.number SUB_STORAGE_fileIOStability_dir + * @tc.name fileIOStability_dir + * @tc.desc Function of API, 7*24 + */ + it('fileIOStability_dirent', 0, function () { + for (let i = 0; i <= 100000; i++) { + try { + let dpath = nextFileName('fileIOStability') + 'd'; + fileio.mkdirSync(dpath); + let fpath = dpath + '/f1'; + prepareFile(fpath, FILE_CONTENT); + let dd = fileio.opendirSync(dpath); + let dirent = dd.readSync(); + dirent.isBlockDevice(); + dirent.isCharacterDevice(); + dirent.isDirectory(); + dirent.isFIFO(); + dirent.isSocket(); + dirent.isSymbolicLink(); + dd.closeSync(); + fileio.unlinkSync(fpath); + fileio.rmdirSync(dpath); + } + catch (e) { + console.log('fileIOStability_dirent has failed for ' + e); + expect(null).assertFail(); + } + } + }); + + /** + * @tc.number SUB_STORAGE_fileIOStability_stat + * @tc.name fileIOStability_stat + * @tc.desc Function of API, 7*24 + */ + it('fileIOStability_stat', 0, function () { + for (let i = 0; i <= 100000; i++) { + try { + let dpath = nextFileName('fileIOStability') + 'd'; + fileio.mkdirSync(dpath); + let fpath = dpath + '/f1'; + prepareFile(fpath, FILE_CONTENT); + let stat = fileio.statSync(fpath); + stat.isBlockDevice(); + stat.isCharacterDevice(); + stat.isDirectory(); + stat.isFIFO(); + stat.isSocket(); + stat.isSymbolicLink(); + stat.dev; + stat.uid; + stat.ino; + stat.mode; + stat.nlink; + stat.gid; + stat.rdev; + stat.size; + stat.blocks; + stat.atime; + stat.mtime; + stat.ctime; + fileio.unlinkSync(fpath); + fileio.rmdirSync(dpath); + } + catch (e) { + console.log('fileIOStability_stat has failed for ' + e); + expect(null).assertFail(); + } + } + }); + + /** + * @tc.number SUB_STORAGE_fileIOStability_stream + * @tc.name fileIOStability_stream + * @tc.desc Function of API, 7*24 + */ + it('fileIOStability_stream', 0, function () { + for (let i = 0; i <= 100000; i++) { + let fpath = nextFileName('fileIOStability_stream'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let ss; + try { + let fd = fileio.openSync(fpath, 0o2); + ss = fileio.fdopenStreamSync(fd, 'r+'); + ss.writeSync(FILE_CONTENT); + ss.flushSync(); + ss.closeSync(); + ss = fileio.createStreamSync(fpath, 'r+'); + ss.readSync(new ArrayBuffer(4096)); + ss.closeSync(); + fileio.unlinkSync(fpath); + } + catch (e) { + console.log('fileIOStability_stream has failed for ' + e); + expect(null).assertFail(); + } + } + }); + + /** + * @tc.number SUB_STORAGE_fileIOStability_prop + * @tc.name fileIOStability_prop + * @tc.desc Function of API, 7*24 + */ + it('fileIOStability_prop', 0, function () { + for (let i = 0; i <= 100000; i++) { + try { + let dpath = nextFileName('fileIOStability') + 'd'; + fileio.mkdirSync(dpath); + let fpath = nextFileName('fileIOStability'); + let fpathTarget = fpath + 'tgt'; + let fpathTarget1 = fpath + 'tgtt'; + let ff = fileio.openSync(fpath, 0o102, 0o666); + fileio.accessSync(fpath); + fileio.chmodSync(fpath, 0o660); + let stat = fileio.statSync(fpath); + fileio.chownSync(fpath, stat.uid, stat.gid); + fileio.copyFileSync(fpath, fpathTarget); + fileio.fchmodSync(ff, 0o660); + fileio.fchownSync(ff, stat.uid, stat.gid); + fileio.fstatSync(ff); + fileio.ftruncateSync(ff); + fileio.renameSync(fpath, fpathTarget1); + fileio.fsyncSync(ff); + fileio.truncateSync(fpathTarget1); + fileio.writeSync(ff, FILE_CONTENT); + fileio.closeSync(ff); + fileio.unlinkSync(fpathTarget1); + fileio.unlinkSync(fpathTarget); + fileio.rmdirSync(dpath); + sleep(4000); + } + catch (e) { + console.log('fileIOStability_pop has failed for ' + e); + expect(null).assertFail(); + } + } + }); + +}); diff --git a/storage/storagefileiostabilityjstest/project/entry/src/main/js/test/List.test.js b/storage/storagefileiostabilityjstest/project/entry/src/main/js/test/List.test.js new file mode 100644 index 0000000000000000000000000000000000000000..1e7de3ab003b2cb29cf3c944c23229176c756cc6 --- /dev/null +++ b/storage/storagefileiostabilityjstest/project/entry/src/main/js/test/List.test.js @@ -0,0 +1,16 @@ +/* + * 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('./FileIOStability.js') diff --git a/storage/storagefilestabilityjstest/BUILD.gn b/storage/storagefilestabilityjstest/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..b139df6eab79a771b195748f0a510d753eabb172 --- /dev/null +++ b/storage/storagefilestabilityjstest/BUILD.gn @@ -0,0 +1,18 @@ +# 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("//test/xts/tools/build/suite.gni") + +ohos_js_hap_suite("storagefilestability_js_test") { + test_hap_name = "storagefilestabilityjstest" + hap_source_path = "hap/entry-debug-rich-signed.hap" +} diff --git a/storage/storagefilestabilityjstest/Test.json b/storage/storagefilestabilityjstest/Test.json new file mode 100644 index 0000000000000000000000000000000000000000..d7e546b6eddf7c39130dddd0cf72ac782f82156d --- /dev/null +++ b/storage/storagefilestabilityjstest/Test.json @@ -0,0 +1,18 @@ +{ + "description": "Configuration for storage file and fileio Tests", + "driver": { + "type": "JSUnitTest", + "test-timeout": "21600000", + "package": "ohos.acts.stroage.fileio", + "shell-timeout": "21600000" + }, + "kits": [ + { + "test-file-name": [ + "storagefilestabilityjstest.hap" + ], + "type": "AppInstallKit", + "cleanup-apps": true + } + ] +} \ No newline at end of file diff --git a/storage/storagefilestabilityjstest/hap/entry-debug-rich-signed.hap b/storage/storagefilestabilityjstest/hap/entry-debug-rich-signed.hap new file mode 100644 index 0000000000000000000000000000000000000000..8672c6ec961c8051b5908cbfc65cc9656b50541c Binary files /dev/null and b/storage/storagefilestabilityjstest/hap/entry-debug-rich-signed.hap differ diff --git a/storage/storagefilestabilityjstest/project/entry/package.json b/storage/storagefilestabilityjstest/project/entry/package.json new file mode 100644 index 0000000000000000000000000000000000000000..4cf06fee5959d788e6cb205ae961a5c1cacd65b9 --- /dev/null +++ b/storage/storagefilestabilityjstest/project/entry/package.json @@ -0,0 +1,6 @@ +{ + "devDependencies": { + "chai": "^4.3.4", + "mocha": "^9.0.1" + } +} diff --git a/storage/storagefilestabilityjstest/project/entry/src/main/config.json b/storage/storagefilestabilityjstest/project/entry/src/main/config.json new file mode 100644 index 0000000000000000000000000000000000000000..12fda07721102cdd208f3d9021a250592706579a --- /dev/null +++ b/storage/storagefilestabilityjstest/project/entry/src/main/config.json @@ -0,0 +1,62 @@ +{ + "app": { + "bundleName": "ohos.acts.stroage.fileio", + "vendor": "example", + "version": { + "code": 1000000, + "name": "1.0.0" + }, + "apiVersion": { + "compatible": 4, + "target": 5, + "releaseType": "Release" + } + }, + "deviceConfig": {}, + "module": { + "package": "ohos.acts.stroage.fileio", + "name": ".MyApplication", + "deviceType": [ + "phone" + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "entry", + "moduleType": "entry", + "installationFree": true + }, + "abilities": [ + { + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ], + "name": "ohos.acts.stroage.fileio.MainAbility", + "icon": "$media:icon", + "description": "$string:mainability_description", + "label": "$string:app_name", + "type": "page", + "launchType": "standard", + "visible": true + } + ], + "js": [ + { + "pages": [ + "pages/index/index" + ], + "name": "default", + "window": { + "designWidth": 720, + "autoDesignWidth": false + } + } + ] + } +} \ No newline at end of file diff --git a/storage/storagefilestabilityjstest/project/entry/src/main/js/default/app.js b/storage/storagefilestabilityjstest/project/entry/src/main/js/default/app.js new file mode 100644 index 0000000000000000000000000000000000000000..5fefaead87d0899fd7e07a2f2241a40bfd298339 --- /dev/null +++ b/storage/storagefilestabilityjstest/project/entry/src/main/js/default/app.js @@ -0,0 +1,8 @@ +export default { + onCreate() { + console.info('ohos.acts.distributeddatamgr.distributedfile onCreate'); + }, + onDestroy() { + console.info('ohos.acts.distributeddatamgr.distributedfile onCreate'); + } +}; diff --git a/storage/storagefilestabilityjstest/project/entry/src/main/js/default/i18n/en-US.json b/storage/storagefilestabilityjstest/project/entry/src/main/js/default/i18n/en-US.json new file mode 100644 index 0000000000000000000000000000000000000000..ead52ed2e09ec82aaf7aa9f4e714ed39ea88308e --- /dev/null +++ b/storage/storagefilestabilityjstest/project/entry/src/main/js/default/i18n/en-US.json @@ -0,0 +1,6 @@ +{ + "strings": { + "hello": "Hello", + "world": "Test" + } +} \ No newline at end of file diff --git a/storage/storagefilestabilityjstest/project/entry/src/main/js/default/i18n/zh-CN.json b/storage/storagefilestabilityjstest/project/entry/src/main/js/default/i18n/zh-CN.json new file mode 100644 index 0000000000000000000000000000000000000000..3f48f2585b24a8fe4a745e8ee2972a9e991a7803 --- /dev/null +++ b/storage/storagefilestabilityjstest/project/entry/src/main/js/default/i18n/zh-CN.json @@ -0,0 +1,6 @@ +{ + "strings": { + "hello": "您好", + "world": "测试" + } +} \ No newline at end of file diff --git a/storage/storagefilestabilityjstest/project/entry/src/main/js/default/pages/index/index.css b/storage/storagefilestabilityjstest/project/entry/src/main/js/default/pages/index/index.css new file mode 100644 index 0000000000000000000000000000000000000000..6fda792753f2e15f22b529c7b90a82185b2770bf --- /dev/null +++ b/storage/storagefilestabilityjstest/project/entry/src/main/js/default/pages/index/index.css @@ -0,0 +1,9 @@ +.container { + flex-direction: column; + justify-content: center; + align-items: center; +} + +.title { + font-size: 100px; +} diff --git a/storage/storagefilestabilityjstest/project/entry/src/main/js/default/pages/index/index.hml b/storage/storagefilestabilityjstest/project/entry/src/main/js/default/pages/index/index.hml new file mode 100644 index 0000000000000000000000000000000000000000..f64b040a5ae394dbaa5e185e1ecd4f4556b92184 --- /dev/null +++ b/storage/storagefilestabilityjstest/project/entry/src/main/js/default/pages/index/index.hml @@ -0,0 +1,5 @@ +
+ + {{ $t('strings.hello') }} {{ title }} + +
diff --git a/storage/storagefilestabilityjstest/project/entry/src/main/js/default/pages/index/index.js b/storage/storagefilestabilityjstest/project/entry/src/main/js/default/pages/index/index.js new file mode 100644 index 0000000000000000000000000000000000000000..572ce6e94d0cd867a15eb94b1b7b0da9497a99b3 --- /dev/null +++ b/storage/storagefilestabilityjstest/project/entry/src/main/js/default/pages/index/index.js @@ -0,0 +1,38 @@ +/* + * 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 file from '@system.file' +import app from '@system.app' + +import {Core} from 'deccjsunit/index' +export default { + 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() { + }, +} \ No newline at end of file diff --git a/storage/storagefilestabilityjstest/project/entry/src/main/js/test/Common.js b/storage/storagefilestabilityjstest/project/entry/src/main/js/test/Common.js new file mode 100644 index 0000000000000000000000000000000000000000..c5bc08482173733896e49c8fab5239bef520ee7c --- /dev/null +++ b/storage/storagefilestabilityjstest/project/entry/src/main/js/test/Common.js @@ -0,0 +1,170 @@ +/* + * 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 '@system.fileio' + +export const FILE_CONTENT = 'hello world' + +export function prepareFile(fpath, content) { + try { + let fd = fileio.openSync(fpath, 0o102, 0o666) + fileio.ftruncateSync(fd) + fileio.writeSync(fd, content) + fileio.fsyncSync(fd) + fileio.closeSync(fd) + return true + } + catch (e) { + console.log('Failed to prepareFile for ' + e) + return false + } +} +export function prepareFile1(fpath, content) { + try { + let fd = fileio.openSync(fpath, 0o102, 0o777) + fileio.ftruncateSync(fd) + fileio.writeSync(fd, content) + fileio.fsyncSync(fd) + fileio.closeSync(fd) + return true + } + catch (e) { + console.log('Failed to prepareFile for ' + e) + return false + } +} +export function prepareEmptyFile(fpath) { + try { + let fd = fileio.openSync(fpath, 0o102, 0o777) + fileio.closeSync(fd) + return true + } + catch (e) { + console.log('Failed to prepareFile for ' + e) + return false + } +} +export function fileToReadOnly(fpath) { + try { + let fd = fileio.openSync(fpath, 0o1) + fileio.fchmodSync(fd, 0o444) + fileio.fsyncSync(fd) + fileio.closeSync(fd) + return true + } + catch (e) { + console.log('Failed to fileToReadOnly for ' + e); + return false + } +} +export function fileToWriteOnly(fpath) { + try { + let fd = fileio.openSync(fpath, 0o2) + fileio.fchmodSync(fd, 0o222) + fileio.fsyncSync(fd) + fileio.closeSync(fd) + return true + } + catch (e) { + console.log('Failed to fileToWriteOnly ' + e) + return false + } +} +export function fileToReadAndWrite(fpath) { + try { + let fd = fileio.openSync(fpath, 0o1) + fileio.fchmodSync(fd, 0o777) + fileio.fsyncSync(fd) + fileio.closeSync(fd) + return true + } + catch (e) { + console.log('Failed to fileToReadAndWrite ' + e); + return false + } +} +export function appName(testName) { + const BASE_PATH = '/data/accounts/account_0/appdata/ohos.acts.stroage.fileio/' + return BASE_PATH + testName +} +export function nextFileName(testName) { + const BASE_PATH = '/data/accounts/account_0/appdata/ohos.acts.stroage.fileio/cache/' + return BASE_PATH + testName +} +export function fileName(testName) { + const BASE_PATH = '/data/accounts/account_0/appdata/ohos.acts.stroage.fileio/files/' + return BASE_PATH + testName +} +export function cacheFileName(testName) { + const BASE_PATH = '/data/accounts/account_0/appdata/ohos.acts.stroage.fileio/files/cache/' + return BASE_PATH + testName +} +export function differentFileName(testName) { + const BASE_PATH = '/data/accounts/account_0/ohos.acts.distributeddatamgr.distributedfile/' + return BASE_PATH + testName +} +export function differentCacheName(testName) { + const BASE_PATH = '/data/accounts/account_0/ohos.acts.distributeddatamgr.distributedfile/cache/' + return BASE_PATH + testName +} + +export function getFileTextLen(fpath) { + let ss + try { + ss = fileio.Stream.createStreamSync(fpath, 'r+') + expect(ss !== null).assertTrue() + let len = ss.readSync(new ArrayBuffer(4096)) + console.log('file:' + fpath) + console.log('file lenth:' + len) + expect(ss.closeSync() !== null).assertTrue() + return len + } + catch (e) { + console.log('Failed to getFileTextLen ' + e) + expect(ss.closeSync() !== null).assertTrue() + return null + } +} +export function isFileExist(fpath) { + try { + expect(fileio.accessSync(fpath) !== null).assertTrue() + console.log('file:' + fpath) + console.log('status:exist') + return true + } + catch (e) { + console.log('file:' + fpath) + console.log('status:non-existen') + return false + } +} +export function sleep(n) { + var start = new Date().getTime(); + while (true) { + if (new Date().getTime() - start > n) { + break; + } + } +} +export function randomString(num) { + let len= num; + var $chars = 'aaaabbbbcccc'; + var maxPos = $chars.length; + var pwd = ''; + for (var i = 0; i < len; i++) { + pwd += $chars.charAt(Math.floor(Math.random() * maxPos)); + } + return pwd; +} diff --git a/storage/storagefilestabilityjstest/project/entry/src/main/js/test/FileReliability.js b/storage/storagefilestabilityjstest/project/entry/src/main/js/test/FileReliability.js new file mode 100644 index 0000000000000000000000000000000000000000..febc53ebde1c1d08f6a3699d7da855ac21975299 --- /dev/null +++ b/storage/storagefilestabilityjstest/project/entry/src/main/js/test/FileReliability.js @@ -0,0 +1,291 @@ +/* + * 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 '@system.fileio' +import file from '@system.file'; +import { + describe, + it, + expect +} + from 'deccjsunit/index' +import { + FILE_CONTENT, + prepareFile, + nextFileName, + differentFileName +} + from './Common' + +describe('FileReliability', function () { + + /** + * @tc.number SUB_STORAGE_FileReliability + * @tc.name FileReliability + * @tc.desc Function of API, Reliability test 7*24. + */ + it('FileReliability', 0, async function (done) { + for (let i = 0; i < 100000; i++) { + let promiseMkdir = new Promise(function (resolve, reject) { + file.mkdir({ + uri: 'internal://app/fileStability' + i, + success: function () { + console.log(i + 'call mkdir success.'); + done(); + }, + fail: function (data, code) { + console.log(i + 'call mkdir fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + setTimeout(function () { + resolve('mkdir success!'); + }, 10); + }); + promiseMkdir.then(function () { + console.log('mkdir success'); + }); + let promiseWriteText = new Promise(function (resolve, reject) { + file.writeText({ + uri: 'internal://app/fileStability' + i + '/fileStability01' + i, + text: 'Text that just for test.', + success: function () { + console.log(i + 'call writeText success.'); + done(); + }, + fail: function (data, code) { + console.log(i + 'call writeText fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + setTimeout(function () { + resolve('writeText success!'); + }, 15); + }); + promiseWriteText.then(function () { + console.log('writeText success'); + }); + let promiseReadText = new Promise(function (resolve, reject) { + file.readText({ + uri: 'internal://app/fileStability' + i + '/fileStability01' + i, + success: function (data) { + console.log(i + 'call readText success: ' + data.text); + done(); + }, + fail: function (data, code) { + console.log(i + 'call readText fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + setTimeout(function () { + resolve('readText success!'); + }, 15); + }); + promiseReadText.then(function () { + console.log('readText success'); + }); + let promiseAccess = new Promise(function (resolve, reject) { + file.access({ + uri: 'internal://app/fileStability' + i + '/fileStability01' + i, + success: function () { + console.log(i + 'call access success.'); + done(); + }, + fail: function (data, code) { + console.log(i + 'call access fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + setTimeout(function () { + resolve('access success!'); + }, 15); + }); + promiseAccess.then(function () { + console.log('access success'); + }); + let promiseGet = new Promise(function (resolve, reject) { + file.get({ + uri: 'internal://app/fileStability' + i + '/fileStability01' + i, + success: function (data) { + console.log(i + 'call readText success: ' + data.uri); + done(); + }, + fail: function (data, code) { + console.log(i + 'call callback fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + setTimeout(function () { + resolve('get success!'); + }, 15); + }); + promiseGet.then(function () { + console.log('get success'); + }); + let promiseList = new Promise(function (resolve, reject) { + file.list({ + uri: 'internal://app/fileStability' + i, + success: function (data) { + console.log(i + 'call readText success: ' + data.fileList); + done(); + }, + fail: function (data, code) { + console.log(i + 'call fail callback fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + setTimeout(function () { + resolve('list success!'); + }, 15); + }); + promiseList.then(function () { + console.log('list success'); + }); + let promiseCopy = new Promise(function (resolve, reject) { + file.copy({ + srcUri: 'internal://app/fileStability' + i + '/fileStability01' + i, + dstUri: 'internal://app/fileStability' + i + '/fileStability02' + i, + success: function (uri) { + console.log(i + 'call success copy success uri: ' + uri); + done(); + }, + fail: function (data, code) { + console.log(i + 'call fail copy fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + setTimeout(function () { + resolve('copy success!'); + }, 15); + }); + promiseCopy.then(function () { + console.log('copy success'); + }); + let promiseMove = new Promise(function (resolve, reject) { + file.move({ + srcUri: 'internal://app/fileStability' + i + '/fileStability01' + i, + dstUri: 'internal://app/fileStability01' + i, + success: function (uri) { + console.log(i + 'call success move success. uri: ' + uri); + done(); + }, + fail: function (data, code) { + console.log(i + 'call fail move fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + setTimeout(function () { + resolve('move success!'); + }, 15); + }); + promiseMove.then(function () { + console.log('move success'); + }); + file.delete({ + uri: 'internal://app/fileStability01' + i, + success: function () { + console.log(i + 'call delete success.'); + done(); + }, + fail: function (data, code) { + console.log(i + 'call fail delete fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + file.delete({ + uri: 'internal://app/fileStability' + i + '/fileStability02' + i, + success: function () { + console.log(i + 'call delete success.'); + done(); + }, + fail: function (data, code) { + console.log(i + 'call fail delete fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + let promiseWriteArrayBuffer = new Promise(function (resolve, reject) { + let buf = new Uint8Array([48, 49, 50, 51, 65, 66, 67, 68, 32, 33]); + file.writeArrayBuffer({ + uri: 'internal://app/fileStability' + i + '/fileStability02' + i, + buffer: buf, + success: function () { + console.log(i + 'call writeArrayBuffer success.'); + done(); + }, + fail: function (data, code) { + console.log(i + 'call fail writeArrayBuffer fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + setTimeout(function () { + resolve('writeArrayBuffer success!'); + }, 15); + }); + promiseWriteArrayBuffer.then(function () { + console.log('writeArrayBuffer success'); + }); + let promiseReadArrayBuffer = new Promise(function (resolve, reject) { + file.readArrayBuffer({ + uri: 'internal://app/fileStability' + i + '/fileStability02' + i, + success: function (data) { + console.log(i + 'call readArrayBuffer success: ' + data.buffer); + done(); + }, + fail: function (data, code) { + console.log(i + 'call fail readArrayBuffer fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + setTimeout(function () { + resolve('readArrayBuffer success!'); + }, 15); + }); + promiseReadArrayBuffer.then(function () { + console.log('readArrayBuffer success'); + }); + file.delete({ + uri: 'internal://app/fileStability' + i + '/fileStability02' + i, + success: function () { + console.log(i + 'call delete success.'); + done(); + }, + fail: function (data, code) { + console.log(i + 'call fail delete fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + let promiseRmdir = new Promise(function (resolve, reject) { + file.rmdir({ + uri: 'internal://app/fileStability' + i, + recursive: true, + success: function () { + console.log(i + 'call rmdir success.'); + done(); + }, + fail: function (data, code) { + console.log(i + 'call fail rmdir fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + setTimeout(function () { + resolve('rmdir success!'); + }, 15); + }); + promiseReadArrayBuffer.then(function () { + console.log('rmdir success'); + }); + + } + }); +}); diff --git a/storage/storagefilestabilityjstest/project/entry/src/main/js/test/FileStability.js b/storage/storagefilestabilityjstest/project/entry/src/main/js/test/FileStability.js new file mode 100644 index 0000000000000000000000000000000000000000..d19730c866ad9e8f06c88e61632711ce2fe4705e --- /dev/null +++ b/storage/storagefilestabilityjstest/project/entry/src/main/js/test/FileStability.js @@ -0,0 +1,291 @@ +/* + * 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 '@system.fileio' +import file from '@system.file'; +import { + describe, + it, + expect +} + from 'deccjsunit/index' +import { + FILE_CONTENT, + prepareFile, + nextFileName, + differentFileName +} + from './Common' + +describe('FileReliability', function () { + + /** + * @tc.number SUB_STORAGE_FileReliability + * @tc.name FileReliability + * @tc.desc Function of API, Reliability test 7*24. + */ + it('FileReliability', 0, async function (done) { + for (let i = 0; i < 100000; i++) { + let promiseMkdir = new Promise(function (resolve, reject) { + file.mkdir({ + uri: 'internal://app/fileStability' + i, + success: function () { + console.log(i + 'call mkdir success.'); + done(); + }, + fail: function (data, code) { + console.log(i + 'call mkdir fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + setTimeout(function () { + resolve('mkdir success!'); + }, 250); + }); + promiseMkdir.then(function () { + console.log('mkdir success'); + }); + let promiseWriteText = new Promise(function (resolve, reject) { + file.writeText({ + uri: 'internal://app/fileStability' + i + '/fileStability01' + i, + text: 'Text that just for test.', + success: function () { + console.log(i + 'call writeText success.'); + done(); + }, + fail: function (data, code) { + console.log(i + 'call writeText fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + setTimeout(function () { + resolve('writeText success!'); + }, 250); + }); + promiseWriteText.then(function () { + console.log('writeText success'); + }); + let promiseReadText = new Promise(function (resolve, reject) { + file.readText({ + uri: 'internal://app/fileStability' + i + '/fileStability01' + i, + success: function (data) { + console.log(i + 'call readText success: ' + data.text); + done(); + }, + fail: function (data, code) { + console.log(i + 'call readText fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + setTimeout(function () { + resolve('readText success!'); + }, 250); + }); + promiseReadText.then(function () { + console.log('readText success'); + }); + let promiseAccess = new Promise(function (resolve, reject) { + file.access({ + uri: 'internal://app/fileStability' + i + '/fileStability01' + i, + success: function () { + console.log(i + 'call access success.'); + done(); + }, + fail: function (data, code) { + console.log(i + 'call access fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + setTimeout(function () { + resolve('access success!'); + }, 250); + }); + promiseAccess.then(function () { + console.log('access success'); + }); + let promiseGet = new Promise(function (resolve, reject) { + file.get({ + uri: 'internal://app/fileStability' + i + '/fileStability01' + i, + success: function (data) { + console.log(i + 'call readText success: ' + data.uri); + done(); + }, + fail: function (data, code) { + console.log(i + 'call callback fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + setTimeout(function () { + resolve('get success!'); + }, 250); + }); + promiseGet.then(function () { + console.log('get success'); + }); + let promiseList = new Promise(function (resolve, reject) { + file.list({ + uri: 'internal://app/fileStability' + i, + success: function (data) { + console.log(i + 'call readText success: ' + data.fileList); + done(); + }, + fail: function (data, code) { + console.log(i + 'call fail callback fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + setTimeout(function () { + resolve('list success!'); + }, 250); + }); + promiseList.then(function () { + console.log('list success'); + }); + let promiseCopy = new Promise(function (resolve, reject) { + file.copy({ + srcUri: 'internal://app/fileStability' + i + '/fileStability01' + i, + dstUri: 'internal://app/fileStability' + i + '/fileStability02' + i, + success: function (uri) { + console.log(i + 'call success copy success uri: ' + uri); + done(); + }, + fail: function (data, code) { + console.log(i + 'call fail copy fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + setTimeout(function () { + resolve('copy success!'); + }, 250); + }); + promiseCopy.then(function () { + console.log('copy success'); + }); + let promiseMove = new Promise(function (resolve, reject) { + file.move({ + srcUri: 'internal://app/fileStability' + i + '/fileStability01' + i, + dstUri: 'internal://app/fileStability01' + i, + success: function (uri) { + console.log(i + 'call success move success. uri: ' + uri); + done(); + }, + fail: function (data, code) { + console.log(i + 'call fail move fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + setTimeout(function () { + resolve('move success!'); + }, 250); + }); + promiseMove.then(function () { + console.log('move success'); + }); + file.delete({ + uri: 'internal://app/fileStability01' + i, + success: function () { + console.log(i + 'call delete success.'); + done(); + }, + fail: function (data, code) { + console.log(i + 'call fail delete fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + file.delete({ + uri: 'internal://app/fileStability' + i + '/fileStability02' + i, + success: function () { + console.log(i + 'call delete success.'); + done(); + }, + fail: function (data, code) { + console.log(i + 'call fail delete fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + let promiseWriteArrayBuffer = new Promise(function (resolve, reject) { + let buf = new Uint8Array([48, 49, 50, 51, 65, 66, 67, 68, 32, 33]); + file.writeArrayBuffer({ + uri: 'internal://app/fileStability' + i + '/fileStability02' + i, + buffer: buf, + success: function () { + console.log(i + 'call writeArrayBuffer success.'); + done(); + }, + fail: function (data, code) { + console.log(i + 'call fail writeArrayBuffer fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + setTimeout(function () { + resolve('writeArrayBuffer success!'); + }, 250); + }); + promiseWriteArrayBuffer.then(function () { + console.log('writeArrayBuffer success'); + }); + let promiseReadArrayBuffer = new Promise(function (resolve, reject) { + file.readArrayBuffer({ + uri: 'internal://app/fileStability' + i + '/fileStability02' + i, + success: function (data) { + console.log(i + 'call readArrayBuffer success: ' + data.buffer); + done(); + }, + fail: function (data, code) { + console.log(i + 'call fail readArrayBuffer fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + setTimeout(function () { + resolve('readArrayBuffer success!'); + }, 250); + }); + promiseReadArrayBuffer.then(function () { + console.log('readArrayBuffer success'); + }); + file.delete({ + uri: 'internal://app/fileStability' + i + '/fileStability02' + i, + success: function () { + console.log(i + 'call delete success.'); + done(); + }, + fail: function (data, code) { + console.log(i + 'call fail delete fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + let promiseRmdir = new Promise(function (resolve, reject) { + file.rmdir({ + uri: 'internal://app/fileStability' + i, + recursive: true, + success: function () { + console.log(i + 'call rmdir success.'); + done(); + }, + fail: function (data, code) { + console.log(i + 'call fail rmdir fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + setTimeout(function () { + resolve('rmdir success!'); + }, 250); + }); + promiseRmdir.then(function () { + console.log('rmdir success'); + }); + + } + }); +}); diff --git a/storage/storagefilestabilityjstest/project/entry/src/main/js/test/List.test.js b/storage/storagefilestabilityjstest/project/entry/src/main/js/test/List.test.js new file mode 100644 index 0000000000000000000000000000000000000000..177b4adfc06e7511c583c9d152d22254c603bb32 --- /dev/null +++ b/storage/storagefilestabilityjstest/project/entry/src/main/js/test/List.test.js @@ -0,0 +1,17 @@ +/* + * 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('./FileReliability.js') +require('./FileStability.js')