From 8ec20c3a00ac0d365bb7ab52f2a8d33ed4ec311e Mon Sep 17 00:00:00 2001 From: futurezhou Date: Fri, 30 Dec 2022 11:36:49 +0800 Subject: [PATCH] fixed 5885e7d from https://gitee.com/zhuhongtao66/xts_acts_mod_fs_xts/pulls/7065 Add XTS for lstat and symlink interfaces of mod_fs Signed-off-by: futurezhou --- .../src/main/js/test/Common.js | 67 +- .../src/main/js/test/members/access.test.js | 255 +++ .../src/main/js/test/members/copyFile.test.js | 794 ++++++++ .../main/js/test/members/fdatasync.test.js | 65 +- .../src/main/js/test/members/fsync.test.js | 63 +- .../src/main/js/test/members/hash.test.js | 246 +++ .../src/main/js/test/members/lstat.test.js | 1707 +++++++++++++++++ .../src/main/js/test/members/mkdtemp.test.js | 215 +++ .../src/main/js/test/members/open.test.js | 297 ++- .../src/main/js/test/members/read.test.js | 320 ++- .../src/main/js/test/members/readtext.test.js | 698 +++++++ .../src/main/js/test/members/rename.test.js | 492 +++++ .../src/main/js/test/members/stat.test.js | 438 ++--- .../src/main/js/test/members/symlink.test.js | 184 ++ .../src/main/js/test/members/truncate.test.js | 145 +- .../src/main/js/test/members/write.test.js | 414 ++-- 16 files changed, 5491 insertions(+), 909 deletions(-) create mode 100644 storage/storagefileiov9jstest/src/main/js/test/members/access.test.js create mode 100644 storage/storagefileiov9jstest/src/main/js/test/members/copyFile.test.js create mode 100644 storage/storagefileiov9jstest/src/main/js/test/members/hash.test.js create mode 100644 storage/storagefileiov9jstest/src/main/js/test/members/lstat.test.js create mode 100644 storage/storagefileiov9jstest/src/main/js/test/members/mkdtemp.test.js create mode 100644 storage/storagefileiov9jstest/src/main/js/test/members/readtext.test.js create mode 100644 storage/storagefileiov9jstest/src/main/js/test/members/rename.test.js create mode 100644 storage/storagefileiov9jstest/src/main/js/test/members/symlink.test.js diff --git a/storage/storagefileiov9jstest/src/main/js/test/Common.js b/storage/storagefileiov9jstest/src/main/js/test/Common.js index 9ca52d041..407eb27aa 100644 --- a/storage/storagefileiov9jstest/src/main/js/test/Common.js +++ b/storage/storagefileiov9jstest/src/main/js/test/Common.js @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 Huawei Device Co., Ltd. + * Copyright (C) 2022-2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the 'License'); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -13,7 +13,6 @@ * limitations under the License. */ -import fileio from '@ohos.fileio'; import fileIO from '@ohos.file.fs'; import util from '@ohos.util'; import featureAbility from '@ohos.ability.featureAbility'; @@ -30,8 +29,8 @@ export function prepareFile(fpath, content) { let file = fileIO.openSync(fpath, fileIO.OpenMode.CREATE | fileIO.OpenMode.READ_WRITE) fileIO.truncateSync(file.fd) fileIO.writeSync(file.fd, content) - fileio.fsyncSync(file.fd) - fileio.closeSync(file.fd) + fileIO.fsyncSync(file.fd) + fileIO.closeSync(file) return true } catch (e) { @@ -40,46 +39,6 @@ export function prepareFile(fpath, content) { } } -export function prepareEmptyFile(fpath) { - try { - let file = fileIO.openSync(fpath, fileIO.OpenMode.CREATE | fileIO.OpenMode.READ_WRITE) - fileio.closeSync(file.fd) - return true - } - catch (e) { - console.log('Failed to prepareFile for ' + e) - return false - } -} - -export function fileToReadOnly(fpath) { - try { - let file = fileIO.openSync(fpath, fileIO.OpenMode.CREATE) - fileio.fchmodSync(file.fd, 0o444) - fileio.fsyncSync(file.fd) - fileio.closeSync(file.fd) - return true - } - catch (e) { - console.log('Failed to fileToReadOnly for ' + e); - return false - } -} - -export function fileToWriteOnly(fpath) { - try { - let file = fileIO.openSync(fpath, fileIO.OpenMode.CREATE | fileIO.OpenMode.WRITE_ONLY) - fileio.fchmodSync(file.fd, 0o222) - fileio.fsyncSync(file.fd) - fileio.closeSync(file.fd) - return true - } - catch (e) { - console.log('Failed to fileToWriteOnly ' + e) - return false - } -} - export async function nextFileName(testName) { let context = featureAbility.getContext(); let data = await context.getCacheDir(); @@ -105,15 +64,6 @@ export function randomString(num) { return pwd; } -export function forceRemoveDir(path, num) { - for (let i = num; i >= 0; i--) { - if (i < num) { - path = path.replace(`/d${i}`, ""); - } - fileio.rmdirSync(path); - } -} - function isIntNum(val) { return typeof val === 'number' && val % 1 === 0; } @@ -126,22 +76,11 @@ function isString(str) { return (typeof str == 'string') && str.constructor == String; } -function isBoolean(val) { - return typeof val == 'boolean'; -} - -function isInclude(error, message) { - return error.toString().indexOf(message) != -1; -} - export { - fileio, fileIO, isIntNum, isBigInt, isString, - isBoolean, - isInclude, describe, it, expect, diff --git a/storage/storagefileiov9jstest/src/main/js/test/members/access.test.js b/storage/storagefileiov9jstest/src/main/js/test/members/access.test.js new file mode 100644 index 000000000..5c79db65e --- /dev/null +++ b/storage/storagefileiov9jstest/src/main/js/test/members/access.test.js @@ -0,0 +1,255 @@ +/* + * Copyright (C) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the 'License'); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an 'AS IS' BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { + fileIO, FILE_CONTENT, prepareFile, nextFileName, isIntNum, describe, it, expect, +} from '../Common'; + +export default function fileIOAccess() { +describe('fileIO_fs_access', function () { + + /** + * @tc.number SUB_DF_FILEIO_ACCESS_SYNC_0000 + * @tc.name fileIO_test_access_sync_000 + * @tc.desc Test accessSync() interface. + * This interface shall work properly in normal case. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_test_access_sync_000', 0, async function () { + let fpath = await nextFileName('fileIO_test_access_sync_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + expect(fileIO.accessSync(fpath)).assertTrue(); + let file = fileIO.openSync(fpath); + expect(isIntNum(file.fd)).assertTrue(); + let readlen = fileIO.readSync(file.fd, new ArrayBuffer(4096)); + expect(readlen == FILE_CONTENT.length).assertTrue(); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); + } catch (e) { + console.log('fileIO_test_access_sync_000 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_ACCESS_SYNC_0100 + * @tc.name fileIO_test_access_sync_001 + * @tc.desc Test accessSync() interface. + * The test file is not exist. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_test_access_sync_001', 0, async function () { + let fpath = await nextFileName('fileIO_test_access_sync_001'); + + try { + let ret = fileIO.accessSync(fpath); + expect(ret === false).assertTrue(); + } catch (e) { + console.log('fileIO_test_access_sync_001 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_ACCESS_SYNC_0200 + * @tc.name fileIO_test_access_sync_002 + * @tc.desc Test accessSync() interface. + * The test file path is illegal. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_test_access_sync_002', 0, async function () { + + try { + expect(fileIO.accessSync(-1)).assertTrue(); + expect(false).assertTrue(); + } catch (e) { + console.log('fileIO_test_access_sync_001 has failed for ' + e.message + ', code: ' + e.code); + expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_ACCESS_ASYNC_0000 + * @tc.name fileIO_test_access_async_000 + * @tc.desc Test access() interface. Promise. + * Use promise to test that the file is exist. Sync method reads data from file. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_test_access_async_000', 0, async function (done) { + let fpath = await nextFileName('fileIO_test_access_async_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let ret = await fileIO.access(fpath); + expect(ret === true).assertTrue(); + let file = fileIO.openSync(fpath); + expect(isIntNum(file.fd)).assertTrue(); + let readlen = fileIO.readSync(file.fd, new ArrayBuffer(4096)); + expect(readlen == FILE_CONTENT.length).assertTrue(); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); + done(); + } catch (e) { + console.log('fileIO_test_access_async_000 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_ACCESS_ASYNC_0100 + * @tc.name fileIO_test_access_async_001 + * @tc.desc Test access() interface. Callback. + * Use callback to test that the file is exist. Sync method reads data from file. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_test_access_async_001', 0, async function (done) { + let fpath = await nextFileName('fileIO_test_access_async_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + fileIO.access(fpath, (err, ret) => { + if (err) { + console.log('fileIO_test_access_async_001 error package: ' + JSON.stringify(err)); + expect(false).assertTrue(); + } + expect(ret === true).assertTrue(); + let file = fileIO.openSync(fpath); + expect(isIntNum(file.fd)).assertTrue(); + let readlen = fileIO.readSync(file.fd, new ArrayBuffer(4096)); + expect(readlen == FILE_CONTENT.length).assertTrue(); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); + }); + done(); + } catch (e) { + console.log('fileIO_test_access_async_001 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_ACCESS_ASYNC_0200 + * @tc.name fileIO_test_access_async_002 + * @tc.desc Test access() interface. Promise. + * Async test file does not exist. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_test_access_async_002', 0, async function (done) { + let fpath = await nextFileName('fileIO_test_access_async_002'); + + try { + let ret = await fileIO.access(fpath); + expect(ret === false).assertTrue(); + done(); + } catch (e) { + console.log('fileIO_test_access_async_002 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_ACCESS_ASYNC_0300 + * @tc.name fileIO_test_access_async_003 + * @tc.desc Test access() interface. Callback. + * Async test file does not exist. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_test_access_async_003', 0, async function (done) { + let fpath = await nextFileName('fileIO_test_access_async_002'); + + try { + fileIO.access(fpath, (err, ret) => { + if (err) { + console.log('fileIO_test_access_async_003 error package: ' + JSON.stringify(err)); + expect(false).assertTrue(); + } + expect(ret === false).assertTrue(); + done(); + }); + } catch (e) { + console.log('fileIO_test_access_async_003 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_ACCESS_ASYNC_0400 + * @tc.name fileIO_test_access_async_004 + * @tc.desc Test access() interface. Promise. + * Invalid path parameter. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_test_access_async_004', 0, async function (done) { + + try { + await fileIO.access(-1); + expect(false).assertTrue(); + } catch (e) { + console.log('fileIO_test_access_async_004 has failed for ' + e.message + ', code: ' + e.code); + expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue(); + done(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_ACCESS_ASYNC_0500 + * @tc.name fileIO_test_access_async_005 + * @tc.desc Test access() interface. Callback. + * Invalid path parameter. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_test_access_async_005', 0, async function (done) { + + try { + fileIO.access(-1, (err) => { + expect(false).assertTrue(); + }); + } catch (e) { + console.log('fileIO_test_access_async_005 has failed for ' + e.message + ', code: ' + e.code); + expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue(); + done(); + } + }); +}); +} diff --git a/storage/storagefileiov9jstest/src/main/js/test/members/copyFile.test.js b/storage/storagefileiov9jstest/src/main/js/test/members/copyFile.test.js new file mode 100644 index 000000000..8b9d0e6cc --- /dev/null +++ b/storage/storagefileiov9jstest/src/main/js/test/members/copyFile.test.js @@ -0,0 +1,794 @@ +/* + * Copyright (C) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the 'License'); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an 'AS IS' BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { + fileIO, FILE_CONTENT, prepareFile, nextFileName, describe, it, expect, randomString +} from '../Common'; + +export default function fileIOCopyfile() { +describe('fileIO_fs_copyfile', function () { + + /** + * @tc.number SUB_DF_FILEIO_COPY_FILE_SYNC_0000 + * @tc.name fileIO_copy_file_sync_000 + * @tc.desc Test copyFileSync() interfaces. + * Test file copied successfully by path. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_copy_file_sync_000', 0, async function () { + let fpath = await nextFileName('fileIO_copy_file_sync_000'); + let fpathTarget = fpath + 'tgt'; + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + fileIO.copyFileSync(fpath, fpathTarget); + let stat1 = fileIO.statSync(fpath); + let stat2 = fileIO.statSync(fpathTarget); + expect(stat1.size == stat2.size).assertTrue(); + fileIO.unlinkSync(fpath); + fileIO.unlinkSync(fpathTarget); + } catch (e) { + console.log('fileIO_copy_file_sync_000 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_COPY_FILE_SYNC_0100 + * @tc.name fileIO_copy_file_sync_001 + * @tc.desc Test copyFileSync() interfaces. + * Test file copied successfully by file descriptor. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_copy_file_sync_001', 0, async function () { + let fpath = await nextFileName('fileIO_copy_file_sync_001'); + let fpathTarget = fpath + 'tgt'; + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let file = fileIO.openSync(fpath, fileIO.OpenMode.READ_WRITE); + fileIO.copyFileSync(file.fd, fpathTarget); + let stat1 = fileIO.statSync(fpath); + let stat2 = fileIO.statSync(fpathTarget); + expect(stat1.size == stat2.size).assertTrue(); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); + fileIO.unlinkSync(fpathTarget); + } catch (e) { + console.log('fileIO_copy_file_sync_001 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_COPY_FILE_SYNC_0200 + * @tc.name fileIO_copy_file_sync_002 + * @tc.desc Test copyFileSync() interfaces. + * The path point to nothing, no such file. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_copy_file_sync_002', 0, async function () { + let fpath = await nextFileName('fileIO_copy_file_sync_002'); + let fpathTarget = fpath + 'tgt'; + + try { + fileIO.copyFileSync(fpath, fpathTarget); + expect(false).assertTrue(); + } catch (e) { + console.log('fileIO_copy_file_sync_002 has failed for ' + e.message + ', code: ' + e.code); + expect(e.code == 13900002 && e.message == 'No such file or directory').assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_COPY_FILE_SYNC_0300 + * @tc.name fileIO_copy_file_sync_003 + * @tc.desc Test copyFileSync() interfaces. + * Missing parameters. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_copy_file_sync_003', 0, function () { + + try { + fileIO.copyFileSync(); + expect(false).assertTrue(); + } catch (e) { + console.log('fileIO_copy_file_sync_003 has failed for ' + e.message + ', code: ' + e.code); + expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_COPY_FILE_SYNC_0400 + * @tc.name fileIO_copy_file_sync_004 + * @tc.desc Test copyFileSync() interfaces. + * Invalid type of mode. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_copy_file_sync_004', 0, async function () { + let fpath = await nextFileName('fileIO_copy_file_sync_004'); + let fpathTarget = fpath + 'tgt'; + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + fileIO.copyFileSync(fpath, fpathTarget, '0'); + expect(false).assertTrue(); + } catch (e) { + fileIO.unlinkSync(fpath); + console.log('fileIO_copy_file_sync_004 has failed for ' + e.message + ', code: ' + e.code); + expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_COPY_FILE_SYNC_0500 + * @tc.name fileIO_copy_file_sync_005 + * @tc.desc Test copyFileSync() interfaces. + * Test file copied successfully by file descriptor. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_copy_file_sync_005', 0, async function () { + let fpath = await nextFileName('fileIO_copy_file_sync_005'); + let fpathTarget = fpath + 'tgt'; + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let fileTgt = fileIO.openSync(fpathTarget, fileIO.OpenMode.CREATE | fileIO.OpenMode.READ_WRITE); + + try { + let file = fileIO.openSync(fpath, fileIO.OpenMode.READ_WRITE); + fileIO.copyFileSync(file.fd, fileTgt.fd); + let stat1 = fileIO.statSync(fpath); + let stat2 = fileIO.statSync(fpathTarget); + expect(stat1.size == stat2.size).assertTrue(); + fileIO.closeSync(file); + fileIO.closeSync(fileTgt); + fileIO.unlinkSync(fpath); + fileIO.unlinkSync(fpathTarget); + } catch (e) { + console.log('fileIO_copy_file_sync_005 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_COPY_FILE_SYNC_0600 + * @tc.name fileIO_copy_file_sync_006 + * @tc.desc Test copyFileSync() interfaces. + * Test file copied successfully by file descriptor and path. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_copy_file_sync_006', 0, async function () { + let fpath = await nextFileName('fileIO_copy_file_sync_006'); + let fpathTarget = fpath + 'tgt'; + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let fileTgt = fileIO.openSync(fpathTarget, fileIO.OpenMode.CREATE | fileIO.OpenMode.READ_WRITE); + + try { + fileIO.copyFileSync(fpath, fileTgt.fd); + let stat1 = fileIO.statSync(fpath); + let stat2 = fileIO.statSync(fpathTarget); + expect(stat1.size == stat2.size).assertTrue(); + fileIO.closeSync(fileTgt); + fileIO.unlinkSync(fpath); + fileIO.unlinkSync(fpathTarget); + } catch (e) { + console.log('fileIO_copy_file_sync_006 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_COPY_FILE_SYNC_0700 + * @tc.name fileIO_copy_file_sync_007 + * @tc.desc Test copyFileSync() interfaces. + * Don't support mode = 1. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_copy_file_sync_007', 0, async function (done) { + let fpath = await nextFileName('fileIO_copy_file_sync_007'); + let fpathTarget = fpath + 'tgt'; + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + fileIO.copyFileSync(fpath, fpathTarget, 1); + expect(false).assertTrue(); + } catch (e) { + fileIO.unlinkSync(fpath); + console.log('fileIO_copy_file_sync_007 has failed for ' + e.message + ', code: ' + e.code); + expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue(); + done(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_COPY_FILE_SYNC_0800 + * @tc.name fileIO_copy_file_sync_008 + * @tc.desc Test copyFileSync() interfaces. + * The length of file name is too long. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_copy_file_sync_008', 0, async function () { + let fpath = await nextFileName('fileIO_copy_file_sync_008'); + let fpathTarget = fpath + randomString(250); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + fileIO.copyFileSync(fpath, fpathTarget); + expect(false).assertTrue(); + } catch (e) { + fileIO.unlinkSync(fpath); + console.log('fileIO_copy_file_sync_008 has failed for ' + e.message + ', code: ' + e.code); + expect(e.code == 13900030 && e.message == 'File name too long').assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_COPY_FILE_ASYNC_0000 + * @tc.name fileIO_copy_file_async_000 + * @tc.desc Test copyFile() interfaces. Promise. + * Test file copied successfully by path. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_copy_file_async_000', 0, async function (done) { + let fpath = await nextFileName('fileIO_copy_file_async_000'); + let fpathTarget = fpath + 'tgt'; + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + await fileIO.copyFile(fpath, fpathTarget); + let stat1 = fileIO.statSync(fpath); + let stat2 = fileIO.statSync(fpathTarget); + expect(stat1.size == stat2.size).assertTrue(); + fileIO.unlinkSync(fpath); + fileIO.unlinkSync(fpathTarget); + done(); + } catch (e) { + console.log('fileIO_copy_file_async_000 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_COPY_FILE_ASYNC_0100 + * @tc.name fileIO_copy_file_async_001 + * @tc.desc Test copyFile() interfaces. Callback. + * Test file copied successfully by path. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_copy_file_async_001', 0, async function (done) { + let fpath = await nextFileName('fileIO_copy_file_async_001'); + let fpathTarget = fpath + 'tgt'; + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + fileIO.copyFile(fpath, fpathTarget, (err) => { + if (err) { + console.log('fileIO_copy_file_async_001 error package: ' + JSON.stringify(err)); + expect(false).assertTrue(); + } + let stat1 = fileIO.statSync(fpath); + let stat2 = fileIO.statSync(fpathTarget); + expect(stat1.size == stat2.size).assertTrue(); + fileIO.unlinkSync(fpath); + fileIO.unlinkSync(fpathTarget); + done(); + }); + } catch (e) { + console.log('fileIO_copy_file_async_001 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_COPY_FILE_ASYNC_0200 + * @tc.name fileIO_copy_file_async_002 + * @tc.desc Test copyFile() interfaces. Promise. + * Test file copied successfully by file descriptor. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_copy_file_async_002', 0, async function (done) { + let fpath = await nextFileName('fileIO_copy_file_async_002'); + let fpathTarget = fpath + 'tgt'; + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let file = fileIO.openSync(fpath, fileIO.OpenMode.CREATE | fileIO.OpenMode.READ_WRITE); + await fileIO.copyFile(file.fd, fpathTarget); + let stat1 = fileIO.statSync(fpath); + let stat2 = fileIO.statSync(fpathTarget); + expect(stat1.size == stat2.size).assertTrue(); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); + fileIO.unlinkSync(fpathTarget); + done(); + } catch (e) { + console.log('fileIO_copy_file_async_002 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_COPY_FILE_ASYNC_0300 + * @tc.name fileIO_copy_file_async_003 + * @tc.desc Test copyFile() interfaces. Promise. + * The path point to nothing, no such file. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_copy_file_async_003', 0, async function (done) { + let fpath = await nextFileName('fileIO_copy_file_async_003'); + let fpathTarget = fpath + 'tgt'; + + try { + await fileIO.copyFile(fpath, fpathTarget); + expect(false).assertTrue(); + } catch (e) { + console.log('fileIO_copy_file_async_003 has failed for ' + e.message + ', code: ' + e.code); + expect(e.code == 13900002 && e.message == 'No such file or directory').assertTrue(); + done(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_COPY_FILE_ASYNC_0400 + * @tc.name fileIO_copy_file_async_004 + * @tc.desc Test copyFile() interfaces. Callback. + * The path point to nothing, no such file. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_copy_file_async_004', 0, async function (done) { + let fpath = await nextFileName('fileIO_copy_file_async_004'); + let fpathTarget = fpath + 'tgt'; + + try { + fileIO.copyFile(fpath, fpathTarget, (err) => { + if (err) { + console.log('fileIO_copy_file_async_005 error: {message: ' + err.message + ', code: ' + err.code + '}'); + expect(err.code == 13900002 && err.message == 'No such file or directory').assertTrue(); + done(); + } + }); + } catch (e) { + console.log('fileIO_copy_file_async_004 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_COPY_FILE_ASYNC_0500 + * @tc.name fileIO_copy_file_async_005 + * @tc.desc Test copyFile() interfaces. Promise.then().catch() + * The path point to nothing, no such file. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_copy_file_async_005', 0, async function (done) { + let fpath = await nextFileName('fileIO_copy_file_async_005'); + let fpathTarget = fpath + 'tgt'; + + try { + fileIO.copyFile(fpath, fpathTarget).then(() => { + expect(false).assertTrue(); + }).catch((err) => { + console.log('fileIO_copy_file_async_005 error: {message: ' + err.message + ', code: ' + err.code + '}'); + expect(err.code == 13900002 && err.message == 'No such file or directory').assertTrue(); + done(); + }); + } catch (e) { + console.log('fileIO_copy_file_async_005 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_COPY_FILE_ASYNC_0600 + * @tc.name fileIO_copy_file_async_006 + * @tc.desc Test copyFile() interfaces. Promise. + * Missing Parameter. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_copy_file_async_006', 0, async function (done) { + let fpath = await nextFileName('fileIO_copy_file_async_006'); + + try { + await fileIO.copyFile(fpath); + expect(false).assertTrue(); + } catch (e) { + console.log('fileIO_copy_file_async_006 has failed for ' + e.message + ', code: ' + e.code); + expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue(); + done(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_COPY_FILE_ASYNC_0700 + * @tc.name fileIO_copy_file_async_007 + * @tc.desc Test copyFile() interfaces. Callback. + * Missing Parameter. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_copy_file_async_007', 0, async function (done) { + let fpath = await nextFileName('fileIO_copy_file_async_007'); + + try { + fileIO.copyFile(fpath, (err) => { + expect(false).assertTrue(); + }); + } catch (e) { + console.log('fileIO_copy_file_async_007 has failed for ' + e.message + ', code: ' + e.code); + expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue(); + done(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_COPY_FILE_ASYNC_0800 + * @tc.name fileIO_copy_file_async_008 + * @tc.desc Test copyFile() interfaces. Promise. + * Test file copied successfully by path when mode = 0. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_copy_file_async_008', 0, async function (done) { + let fpath = await nextFileName('fileIO_copy_file_async_008'); + let fpathTarget = fpath + 'tgt'; + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + await fileIO.copyFile(fpath, fpathTarget, 0); + let stat1 = fileIO.statSync(fpath); + let stat2 = fileIO.statSync(fpathTarget); + expect(stat1.size == stat2.size).assertTrue(); + fileIO.unlinkSync(fpath); + fileIO.unlinkSync(fpathTarget); + done(); + } catch (e) { + console.log('fileIO_copy_file_async_008 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_COPY_FILE_ASYNC_0900 + * @tc.name fileIO_copy_file_async_009 + * @tc.desc Test copyFile() interfaces. Callback. + * Test file copied successfully by path when mode = 0. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_copy_file_async_009', 0, async function (done) { + let fpath = await nextFileName('fileIO_copy_file_async_009'); + let fpathTarget = fpath + 'tgt'; + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + fileIO.copyFile(fpath, fpathTarget, 0, (err) => { + if (err) { + console.log('fileIO_copy_file_async_007 error package: ' + JSON.stringify(err)); + expect(false).assertTrue(); + } + let stat1 = fileIO.statSync(fpath); + let stat2 = fileIO.statSync(fpathTarget); + expect(stat1.size == stat2.size).assertTrue(); + fileIO.unlinkSync(fpath); + fileIO.unlinkSync(fpathTarget); + done(); + }); + } catch (e) { + console.log('fileIO_copy_file_async_007 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_COPY_FILE_ASYNC_1000 + * @tc.name fileIO_copy_file_async_010 + * @tc.desc Test copyFile() interfaces. Callback. + * Don't support mode = 1. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_copy_file_async_010', 0, async function (done) { + let fpath = await nextFileName('fileIO_copy_file_async_010'); + let fpathTarget = fpath + 'tgt'; + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + fileIO.copyFile(fpath, fpathTarget, 1, (err) => { + expect(false).assertTrue(); + }); + } catch (e) { + fileIO.unlinkSync(fpath); + console.log('fileIO_copy_file_async_010 has failed for ' + e.message + ', code: ' + e.code); + expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue(); + done(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_COPY_FILE_ASYNC_1100 + * @tc.name fileIO_copy_file_async_011 + * @tc.desc Test copyFile() interfaces. Promise. + * Invalid type of mode. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_copy_file_async_011', 0, async function (done) { + let fpath = await nextFileName('fileIO_copy_file_async_011'); + let fpathTarget = fpath + 'tgt'; + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + await fileIO.copyFile(fpath, fpathTarget, '0'); + expect(false).assertTrue(); + } catch (e) { + fileIO.unlinkSync(fpath); + console.log('fileIO_copy_file_async_011 has failed for ' + e.message + ', code: ' + e.code); + expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue(); + done(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_COPY_FILE_ASYNC_1200 + * @tc.name fileIO_copy_file_async_012 + * @tc.desc Test copyFile() interfaces. Promise. + * Test file copied successfully by file descriptor. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_copy_file_async_012', 0, async function (done) { + let fpath = await nextFileName('fileIO_copy_file_async_012'); + let fpathTarget = fpath + 'tgt'; + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let fileTgt = fileIO.openSync(fpathTarget, fileIO.OpenMode.CREATE | fileIO.OpenMode.READ_WRITE); + + try { + let file = fileIO.openSync(fpath, fileIO.OpenMode.READ_WRITE); + await fileIO.copyFile(file.fd, fileTgt.fd); + let stat1 = fileIO.statSync(fpath); + let stat2 = fileIO.statSync(fpathTarget); + expect(stat1.size == stat2.size).assertTrue(); + fileIO.closeSync(file); + fileIO.closeSync(fileTgt); + fileIO.unlinkSync(fpath); + fileIO.unlinkSync(fpathTarget); + done(); + } catch (e) { + console.log('fileIO_copy_file_async_012 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_COPY_FILE_ASYNC_1300 + * @tc.name fileIO_copy_file_async_013 + * @tc.desc Test copyFile() interfaces. Callback. + * Test file copied successfully by file descriptor. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_copy_file_async_013', 0, async function (done) { + let fpath = await nextFileName('fileIO_copy_file_async_012'); + let fpathTarget = fpath + 'tgt'; + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let fileTgt = fileIO.openSync(fpathTarget, fileIO.OpenMode.CREATE | fileIO.OpenMode.READ_WRITE); + + try { + let file = fileIO.openSync(fpath, fileIO.OpenMode.READ_WRITE); + fileIO.copyFile(file.fd, fileTgt.fd, (err) => { + if (err) { + console.log('fileIO_copy_file_async_013 error package: ' + JSON.stringify(err)); + expect(false).assertTrue(); + } + let stat1 = fileIO.statSync(fpath); + let stat2 = fileIO.statSync(fpathTarget); + expect(stat1.size == stat2.size).assertTrue(); + fileIO.closeSync(file); + fileIO.closeSync(fileTgt); + fileIO.unlinkSync(fpath); + fileIO.unlinkSync(fpathTarget); + done(); + }); + } catch (e) { + console.log('fileIO_copy_file_async_013 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_COPY_FILE_ASYNC_1400 + * @tc.name fileIO_copy_file_async_014 + * @tc.desc Test copyFile() interfaces. Promise. + * Test file copied successfully by file descriptor and path when mode = 0. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_copy_file_async_014', 0, async function (done) { + let fpath = await nextFileName('fileIO_copy_file_async_014'); + let fpathTarget = fpath + 'tgt'; + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + expect(prepareFile(fpathTarget, FILE_CONTENT)).assertTrue(); + + try { + let file = fileIO.openSync(fpathTarget, fileIO.OpenMode.READ_WRITE); + await fileIO.copyFile(fpath, file.fd, 0); + let stat1 = fileIO.statSync(fpath); + let stat2 = fileIO.statSync(fpathTarget); + expect(stat1.size == stat2.size).assertTrue(); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); + fileIO.unlinkSync(fpathTarget); + done(); + } catch (e) { + console.log('fileIO_copy_file_async_014 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_COPY_FILE_ASYNC_1500 + * @tc.name fileIO_copy_file_async_015 + * @tc.desc Test copyFile() interfaces. Callback. + * Test file copied successfully by file descriptor and path. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_copy_file_async_015', 0, async function (done) { + let fpath = await nextFileName('fileIO_copy_file_async_014'); + let fpathTarget = fpath + 'tgt'; + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let file = fileIO.openSync(fpathTarget, fileIO.OpenMode.CREATE | fileIO.OpenMode.READ_WRITE); + + try { + fileIO.copyFile(fpath, file.fd, 0, (err) => { + if (err) { + console.log('fileIO_copy_file_async_013 error package: ' + JSON.stringify(err)); + expect(false).assertTrue(); + } + let stat1 = fileIO.statSync(fpath); + let stat2 = fileIO.statSync(fpathTarget); + expect(stat1.size == stat2.size).assertTrue(); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); + fileIO.unlinkSync(fpathTarget); + done(); + }); + } catch (e) { + console.log('fileIO_copy_file_async_015 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_COPY_FILE_ASYNC_1600 + * @tc.name fileIO_copy_file_async_016 + * @tc.desc Test copyFile() interfaces. Promise + * The length of file name is too long. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_copy_file_async_016', 0, async function (done) { + let fpath = await nextFileName('fileIO_copy_file_async_016'); + let fpathTarget = fpath + randomString(250); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + await fileIO.copyFile(fpath, fpathTarget); + expect(false).assertTrue(); + } catch (e) { + console.log('fileIO_copy_file_async_016 has failed for ' + e.message + ', code: ' + e.code); + expect(e.code == 13900030 && e.message == 'File name too long').assertTrue(); + done(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_COPY_FILE_ASYNC_1700 + * @tc.name fileIO_copy_file_async_017 + * @tc.desc Test copyFile() interfaces. Callback + * The length of file name is too long. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_copy_file_async_017', 0, async function (done) { + let fpath = await nextFileName('fileIO_copy_file_async_017'); + let fpathTarget = fpath + randomString(250); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + fileIO.copyFile(fpath, fpathTarget, (err) => { + if (err) { + fileIO.unlinkSync(fpath); + console.log('fileIO_copy_file_async_017 error: {message: ' + err.message + ', code: ' + err.code); + expect(err.code == 13900030 && err.message == 'File name too long').assertTrue(); + done(); + } + }); + } catch (e) { + console.log('fileIO_copy_file_async_017 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); +}); +} diff --git a/storage/storagefileiov9jstest/src/main/js/test/members/fdatasync.test.js b/storage/storagefileiov9jstest/src/main/js/test/members/fdatasync.test.js index 09fd0be69..688e82a12 100644 --- a/storage/storagefileiov9jstest/src/main/js/test/members/fdatasync.test.js +++ b/storage/storagefileiov9jstest/src/main/js/test/members/fdatasync.test.js @@ -14,8 +14,7 @@ */ import { - fileio, fileIO, FILE_CONTENT, prepareFile, nextFileName, - describe, it, expect, + fileIO, FILE_CONTENT, prepareFile, nextFileName, describe, it, expect, } from '../Common'; export default function fileIOFdatasync() { @@ -38,8 +37,8 @@ export default function fileIOFdatasync() { try { let file = fileIO.openSync(fpath, fileIO.OpenMode.READ_WRITE); fileIO.fdatasyncSync(file.fd); - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); } catch (e) { console.log('fileIO_test_fdatasync_sync_000 has failed for ' + e.message + ', code: ' + e.code); expect(false).assertTrue(); @@ -47,12 +46,12 @@ export default function fileIOFdatasync() { }); /** - * @tc.number SUB_DF_FILEIO_FDATASYNC_SYNC_0010 + * @tc.number SUB_DF_FILEIO_FDATASYNC_SYNC_0100 * @tc.name fileIO_test_fdatasync_sync_001 * @tc.desc Test fdatasyncSync() interfaces. Invalid fd parameter. * @tc.size MEDIUM * @tc.type Function - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_test_fdatasync_sync_001', 0, async function () { @@ -67,12 +66,12 @@ export default function fileIOFdatasync() { }); /** - * @tc.number SUB_DF_FILEIO_FDATASYNC_SYNC_0020 + * @tc.number SUB_DF_FILEIO_FDATASYNC_SYNC_0200 * @tc.name fileIO_test_fdatasync_sync_002 * @tc.desc Test fdatasyncSync() interfaces. Missing parameter. * @tc.size MEDIUM * @tc.type Function - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_test_fdatasync_sync_002', 0, async function () { @@ -107,8 +106,8 @@ export default function fileIOFdatasync() { console.log('fileIO_test_fdatasync_async_000 error package: ' + JSON.stringify(err)); expect(false).assertTrue(); } - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); done(); }); } catch (e) { @@ -118,13 +117,13 @@ export default function fileIOFdatasync() { }); /** - * @tc.number SUB_DF_FILEIO_FDATASYNC_ASYNC_0010 + * @tc.number SUB_DF_FILEIO_FDATASYNC_ASYNC_0100 * @tc.name fileIO_test_fdatasync_async_001 * @tc.desc Test fdatasync() interfaces. Promise.then().catch(). * Open the file in read-write mode, and synchronize the file content data. * @tc.size MEDIUM * @tc.type Function - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_test_fdatasync_async_001', 0, async function (done) { @@ -133,9 +132,9 @@ export default function fileIOFdatasync() { try { let file = fileIO.openSync(fpath, fileIO.OpenMode.READ_WRITE); - fileio.fdatasync(file.fd).then(() => { - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); + fileIO.fdatasync(file.fd).then(() => { + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); done(); }).catch((err) => { console.log('fileIO_test_fdatasync_async_001 error package: ' + JSON.stringify(err)); @@ -148,13 +147,13 @@ export default function fileIOFdatasync() { }); /** - * @tc.number SUB_DF_FILEIO_FDATASYNC_ASYNC_0020 + * @tc.number SUB_DF_FILEIO_FDATASYNC_ASYNC_0200 * @tc.name fileIO_test_fdatasync_async_002 * @tc.desc Test fdatasync() interfaces. await Promise. * Open the file in read-write mode, and synchronize the file content data. * @tc.size MEDIUM * @tc.type Function - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_test_fdatasync_async_002', 0, async function (done) { @@ -163,9 +162,9 @@ export default function fileIOFdatasync() { try { let file = fileIO.openSync(fpath, fileIO.OpenMode.READ_WRITE); - await fileio.fdatasync(file.fd); - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); + await fileIO.fdatasync(file.fd); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); done(); } catch (e) { console.log('fileIO_test_fdatasync_async_002 has failed for ' + e.message + ', code: ' + e.code); @@ -174,13 +173,13 @@ export default function fileIOFdatasync() { }); /** - * @tc.number SUB_DF_FILEIO_FDATASYNC_ASYNC_0030 + * @tc.number SUB_DF_FILEIO_FDATASYNC_ASYNC_0300 * @tc.name fileIO_test_fdatasync_async_003 * @tc.desc Test fdatasync() interfaces. await Promise. * Invalid fd parameter. * @tc.size MEDIUM * @tc.type Function - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_test_fdatasync_async_003', 0, async function (done) { @@ -196,13 +195,13 @@ export default function fileIOFdatasync() { }); /** - * @tc.number SUB_DF_FILEIO_FDATASYNC_ASYNC_0040 + * @tc.number SUB_DF_FILEIO_FDATASYNC_ASYNC_0400 * @tc.name fileIO_test_fdatasync_async_004 * @tc.desc Test fdatasync() interfaces. Callback. * Invalid fd parameter. * @tc.size MEDIUM * @tc.type Function - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_test_fdatasync_async_004', 0, async function (done) { @@ -210,7 +209,7 @@ export default function fileIOFdatasync() { try { fileIO.fdatasync(-1, (err) => { if (err) { - console.log('fileIO_test_fdatasync_async_004 error package: {' + err.message + ', code: ' + err.code + '}'); + console.log('fileIO_test_fdatasync_async_004 error: {message: ' + err.message + ', code: ' + err.code + '}'); expect(err.code == 13900008 && err.message == 'Bad file descriptor').assertTrue(); done(); } @@ -222,13 +221,13 @@ export default function fileIOFdatasync() { }); /** - * @tc.number SUB_DF_FILEIO_FDATASYNC_ASYNC_0050 + * @tc.number SUB_DF_FILEIO_FDATASYNC_ASYNC_0500 * @tc.name fileIO_test_fdatasync_async_005 * @tc.desc Test fdatasync() interfaces. Promise.then().catch() * Invalid fd parameter. * @tc.size MEDIUM * @tc.type Function - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_test_fdatasync_async_005', 0, async function (done) { @@ -237,7 +236,7 @@ export default function fileIOFdatasync() { fileIO.fdatasync(-1).then(() => { expect(false).assertTrue(); }).catch((err) => { - console.log('fileIO_test_fdatasync_async_005 error package: {' + err.message + ', code: ' + err.code + '}'); + console.log('fileIO_test_fdatasync_async_005 error: {message: ' + err.message + ', code: ' + err.code + '}'); expect(err.code == 13900008 && err.message == 'Bad file descriptor').assertTrue(); done(); }); @@ -248,13 +247,13 @@ export default function fileIOFdatasync() { }); /** - * @tc.number SUB_DF_FILEIO_FDATASYNC_ASYNC_0060 + * @tc.number SUB_DF_FILEIO_FDATASYNC_ASYNC_0600 * @tc.name fileIO_test_fdatasync_async_006 * @tc.desc Test fdatasync() interfaces. Promise. * Missing parameter. * @tc.size MEDIUM * @tc.type Function - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_test_fdatasync_async_006', 0, async function (done) { @@ -270,19 +269,19 @@ export default function fileIOFdatasync() { }); /** - * @tc.number SUB_DF_FILEIO_FDATASYNC_ASYNC_0070 + * @tc.number SUB_DF_FILEIO_FDATASYNC_ASYNC_0700 * @tc.name fileIO_test_fdatasync_async_007 * @tc.desc Test fdatasync() interfaces. Callback. * Missing parameter. * @tc.size MEDIUM * @tc.type Function - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_test_fdatasync_async_007', 0, async function (done) { try { - fileIO.fdatasync(() => { + fileIO.fdatasync((err) => { expect(false).assertTrue(); }); } catch (e) { diff --git a/storage/storagefileiov9jstest/src/main/js/test/members/fsync.test.js b/storage/storagefileiov9jstest/src/main/js/test/members/fsync.test.js index 3df5683f7..b5c8fdec8 100644 --- a/storage/storagefileiov9jstest/src/main/js/test/members/fsync.test.js +++ b/storage/storagefileiov9jstest/src/main/js/test/members/fsync.test.js @@ -14,8 +14,7 @@ */ import { - fileio, fileIO, FILE_CONTENT, prepareFile, nextFileName, - describe, it, expect, + fileIO, FILE_CONTENT, prepareFile, nextFileName, describe, it, expect, } from '../Common'; export default function fileIOFsync() { @@ -38,8 +37,8 @@ describe('fileIO_fs_fsync', function () { try { let file = fileIO.openSync(fpath, fileIO.OpenMode.READ_WRITE); fileIO.fsyncSync(file.fd); - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); } catch (e) { console.log('fileIO_test_fsync_sync_000 has failed for ' + e.message + ', code: ' + e.code); expect(false).assertTrue(); @@ -47,12 +46,12 @@ describe('fileIO_fs_fsync', function () { }); /** - * @tc.number SUB_DF_FILEIO_FSYNC_SYNC_0010 + * @tc.number SUB_DF_FILEIO_FSYNC_SYNC_0100 * @tc.name fileIO_test_fsync_sync_001 * @tc.desc Test fsyncSync() interface. Invalid fd parameter. * @tc.size MEDIUM * @tc.type Function - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_test_fsync_sync_001', 0, function () { @@ -67,12 +66,12 @@ describe('fileIO_fs_fsync', function () { }); /** - * @tc.number SUB_DF_FILEIO_FSYNC_SYNC_0020 + * @tc.number SUB_DF_FILEIO_FSYNC_SYNC_0200 * @tc.name fileIO_test_fsync_sync_002 * @tc.desc Test fsyncSync() interface. Missing parameter. * @tc.size MEDIUM * @tc.type Function - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_test_fsync_sync_002', 0, function () { @@ -103,8 +102,8 @@ describe('fileIO_fs_fsync', function () { try { let file = fileIO.openSync(fpath, fileIO.OpenMode.READ_WRITE); await fileIO.fsync(file.fd); - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); done(); } catch (e) { console.log('fileIO_test_fsync_async_000 has failed for ' + e.message + ', code: ' + e.code); @@ -113,13 +112,13 @@ describe('fileIO_fs_fsync', function () { }); /** - * @tc.number SUB_DF_FILEIO_FSYNC_ASYNC_0010 + * @tc.number SUB_DF_FILEIO_FSYNC_ASYNC_0100 * @tc.name fileIO_test_fsync_async_001 * @tc.desc Test fsync() interface. Promise.then().catch() * Open the file in read-write mode, and synchronize the file content data. * @tc.size MEDIUM * @tc.type Function - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_test_fsync_async_001', 0, async function (done) { @@ -129,8 +128,8 @@ describe('fileIO_fs_fsync', function () { try { let file = fileIO.openSync(fpath, fileIO.OpenMode.READ_WRITE); fileIO.fsync(file.fd).then(() => { - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); done(); }).catch((err) => { console.log('fileIO_test_fsync_async_001 error package: ' + JSON.stringify(err)); @@ -143,13 +142,13 @@ describe('fileIO_fs_fsync', function () { }); /** - * @tc.number SUB_DF_FILEIO_FSYNC_ASYNC_002 + * @tc.number SUB_DF_FILEIO_FSYNC_ASYNC_0200 * @tc.name fileIO_test_fsync_async_002 * @tc.desc Test fsync() interface. Callback. * Open the file in read-write mode, and synchronize the file content data. * @tc.size MEDIUM * @tc.type Function - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_test_fsync_async_002', 0, async function (done) { @@ -163,8 +162,8 @@ describe('fileIO_fs_fsync', function () { console.log('fileIO_test_fsync_async_002 error package: ' + JSON.stringify(err)); expect(false).assertTrue(); } - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); }); done(); } catch (e) { @@ -174,13 +173,13 @@ describe('fileIO_fs_fsync', function () { }); /** - * @tc.number SUB_DF_FILEIO_FSYNC_ASYNC_003 + * @tc.number SUB_DF_FILEIO_FSYNC_ASYNC_0300 * @tc.name fileIO_test_fsync_async_003 * @tc.desc Test fsync() interface. await Promise. * Invalid fd parameter. * @tc.size MEDIUM * @tc.type Function - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_test_fsync_async_003', 0, async function (done) { @@ -196,13 +195,13 @@ describe('fileIO_fs_fsync', function () { }); /** - * @tc.number SUB_DF_FILEIO_FSYNC_ASYNC_004 + * @tc.number SUB_DF_FILEIO_FSYNC_ASYNC_0400 * @tc.name fileIO_test_fsync_async_004 * @tc.desc Test fsync() interface. Callback. * Invalid fd parameter. * @tc.size MEDIUM * @tc.type Function - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_test_fsync_async_004', 0, async function (done) { @@ -210,7 +209,7 @@ describe('fileIO_fs_fsync', function () { try { fileIO.fsync(-1, (err) => { if (err) { - console.log('fileIO_test_fsync_async_004 error package: {' + err.message + ', code: ' + err.code + '}'); + console.log('fileIO_test_fsync_async_004 error: {message: ' + err.message + ', code: ' + err.code + '}'); expect(err.code == 13900008 && err.message == 'Bad file descriptor').assertTrue(); done(); } @@ -222,13 +221,13 @@ describe('fileIO_fs_fsync', function () { }); /** - * @tc.number SUB_DF_FILEIO_FSYNC_ASYNC_005 + * @tc.number SUB_DF_FILEIO_FSYNC_ASYNC_0500 * @tc.name fileIO_test_fsync_async_005 * @tc.desc Test fsync() interface. Promise.then().catch() * Missing parameter. * @tc.size MEDIUM * @tc.type Function - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_test_fsync_async_005', 0, async function (done) { @@ -237,7 +236,7 @@ describe('fileIO_fs_fsync', function () { fileIO.fsync(-1).then(() => { expect(false).assertTrue(); }).catch((err) => { - console.log('fileIO_test_fsync_async_005 error package: {' + err.message + ', code: ' + err.code + '}'); + console.log('fileIO_test_fsync_async_005 error: {message: ' + err.message + ', code: ' + err.code + '}'); expect(err.code == 13900008 && err.message == 'Bad file descriptor').assertTrue(); done(); }); @@ -248,13 +247,13 @@ describe('fileIO_fs_fsync', function () { }); /** - * @tc.number SUB_DF_FILEIO_FSYNC_ASYNC_006 + * @tc.number SUB_DF_FILEIO_FSYNC_ASYNC_0600 * @tc.name fileIO_test_fsync_async_006 * @tc.desc Test fsync() interface. await Promise. * Missing parameter. * @tc.size MEDIUM * @tc.type Function - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_test_fsync_async_006', 0, async function (done) { @@ -270,19 +269,19 @@ describe('fileIO_fs_fsync', function () { }); /** - * @tc.number SUB_DF_FILEIO_FSYNC_ASYNC_006 - * @tc.name fileIO_test_fsync_async_006 + * @tc.number SUB_DF_FILEIO_FSYNC_ASYNC_0700 + * @tc.name fileIO_test_fsync_async_007 * @tc.desc Test fsync() interface. Callback. * Missing parameter. * @tc.size MEDIUM * @tc.type Function - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_test_fsync_async_007', 0, async function (done) { try { - fileIO.fsync(() => { + fileIO.fsync((err) => { expect(false).assertTrue(); }); } catch (e) { diff --git a/storage/storagefileiov9jstest/src/main/js/test/members/hash.test.js b/storage/storagefileiov9jstest/src/main/js/test/members/hash.test.js new file mode 100644 index 000000000..99215f89e --- /dev/null +++ b/storage/storagefileiov9jstest/src/main/js/test/members/hash.test.js @@ -0,0 +1,246 @@ +/* + * Copyright (C) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the 'License'); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an 'AS IS' BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import fileHash from '@ohos.file.hash'; +import { + fileIO, FILE_CONTENT, prepareFile, nextFileName, describe, it, expect, +} from '../Common'; + +export default function fileIOHash() { +describe('fileIO_fs_hash', function () { + + /** + * @tc.number SUB_DF_FILEIO_HASH_ASYNC_0000 + * @tc.name fileIO_test_hash_async_000 + * @tc.desc Test hash() interface. Promise. + * Encrypt files using the MD5 hashing algorithm + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_test_hash_async_000', 0, async function (done) { + let fpath = await nextFileName('fileIO_test_hash_async_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let str = await fileHash.hash(fpath,'md5'); + console.log('fileIO_test_hash_async_000 hash value is ' + str); + expect(str == '5EB63BBBE01EEED093CB22BB8F5ACDC3').assertTrue(); + fileIO.unlinkSync(fpath); + done(); + } catch (e) { + console.log('fileIO_test_hash_async_000 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_HASH_ASYNC_0100 + * @tc.name fileIO_test_hash_async_001 + * @tc.desc Test hash() interface. Callback. + * Encrypt files using the MD5 hashing algorithm. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_test_hash_async_001', 0, async function (done) { + let fpath = await nextFileName('fileIO_test_hash_async_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + fileHash.hash(fpath, 'md5', (err, str) => { + if (err) { + console.log('fileIO_test_hash_async_001 error package: ' + JSON.stringify(err)); + expect(false).assertTrue(); + } + console.log('fileIO_test_hash_async_001 hash value is ' + str); + expect(str == '5EB63BBBE01EEED093CB22BB8F5ACDC3').assertTrue(); + fileIO.unlinkSync(fpath); + done(); + }); + } catch (e) { + console.log('fileIO_test_hash_async_001 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_HASH_ASYNC_0200 + * @tc.name fileIO_test_hash_async_002 + * @tc.desc Test hash() interface. Promise. + * Encrypt files using the sha1 hashing algorithm. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_test_hash_async_002', 0, async function (done) { + let fpath = await nextFileName('fileIO_test_hash_async_002'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let str = await fileHash.hash(fpath, 'sha1'); + console.log('fileIO_test_hash_async_000 hash value is ' + str); + expect(str == '2AAE6C35C94FCFB415DBE95F408B9CE91EE846ED').assertTrue(); + fileIO.unlinkSync(fpath); + done(); + } catch (e) { + console.log('fileIO_test_hash_async_002 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_HASH_ASYNC_0300 + * @tc.name fileIO_test_hash_async_003 + * @tc.desc Test hash() interface. Callback. + * Encrypt files using the sha1 hashing algorithm. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_test_hash_async_003', 0, async function (done) { + let fpath = await nextFileName('fileIO_test_hash_async_003'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + fileHash.hash(fpath, 'sha1', (err, str) => { + if (err) { + console.log('fileIO_test_hash_async_003 error package: ' + JSON.stringify(err)); + expect(false).assertTrue(); + } + console.log('fileIO_test_hash_async_003 hash value is ' + str); + expect(str == '2AAE6C35C94FCFB415DBE95F408B9CE91EE846ED').assertTrue(); + fileIO.unlinkSync(fpath); + done(); + }); + } catch (e) { + console.log('fileIO_test_hash_async_003 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_HASH_ASYNC_0400 + * @tc.name fileIO_test_hash_async_004 + * @tc.desc Test hash() interface. Promise. + * Encrypt files using the sha256 hashing algorithm. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_test_hash_async_004', 0, async function (done) { + let fpath = await nextFileName('fileIO_test_hash_async_004'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let str = await fileHash.hash(fpath, 'sha256'); + console.log('fileIO_test_hash_async_001 hash value is ' + str); + expect(str == 'B94D27B9934D3E08A52E52D7DA7DABFAC484EFE37A5380EE9088F7ACE2EFCDE9').assertTrue(); + fileIO.unlinkSync(fpath); + done(); + } catch (e) { + console.log('fileIO_test_hash_async_004 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_HASH_ASYNC_0500 + * @tc.name fileIO_test_hash_async_005 + * @tc.desc Test hash() interface. Callback. + * Encrypt files using the sha256 hashing algorithm. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_test_hash_async_005', 0, async function (done) { + let fpath = await nextFileName('fileIO_test_hash_async_005'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + fileHash.hash(fpath, 'sha256', (err, str) => { + if (err) { + console.log('fileIO_test_hash_async_005 error package: ' + JSON.stringify(err)); + expect(false).assertTrue(); + } + console.log('fileIO_test_hash_async_005 hash value is ' + str); + expect(str == 'B94D27B9934D3E08A52E52D7DA7DABFAC484EFE37A5380EE9088F7ACE2EFCDE9').assertTrue(); + fileIO.unlinkSync(fpath); + done(); + }); + } catch (e) { + console.log('fileIO_test_hash_async_005 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_HASH_ASYNC_0600 + * @tc.name fileIO_test_hash_async_006 + * @tc.desc Test hash() interface. Promise. + * Invalid mode. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_test_hash_async_006', 0, async function (done) { + let fpath = await nextFileName('fileIO_test_hash_async_006'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + await fileHash.hash(fpath, '256'); + expect(false).assertTrue(); + } catch (e) { + fileIO.unlinkSync(fpath); + console.log('fileIO_test_hash_async_006 has failed for ' + e.message + ', code: ' + e.code); + expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue(); + done(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_HASH_ASYNC_0700 + * @tc.name fileIO_test_hash_async_007 + * @tc.desc Test hash() interface. Promise. + * Missing parameter. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_test_hash_async_007', 0, async function (done) { + let fpath = await nextFileName('fileIO_test_hash_async_007'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + fileHash.hash(fpath, (err) => { + expect(false).assertTrue(); + }); + } catch (e) { + fileIO.unlinkSync(fpath); + console.log('fileIO_test_hash_async_007 has failed for ' + e.message + ', code: ' + e.code); + expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue(); + done(); + } + }); +}) +} diff --git a/storage/storagefileiov9jstest/src/main/js/test/members/lstat.test.js b/storage/storagefileiov9jstest/src/main/js/test/members/lstat.test.js new file mode 100644 index 000000000..57ecedf7d --- /dev/null +++ b/storage/storagefileiov9jstest/src/main/js/test/members/lstat.test.js @@ -0,0 +1,1707 @@ +/* + * Copyright (C) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the 'License'); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an 'AS IS' BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { + fileIO, FILE_CONTENT, prepareFile, nextFileName, isIntNum, isBigInt, + describe, it, expect, +} from '../Common'; + +export default function fileIOLstat() { +describe('fileIO_fs_lstat', function () { + + /** + * @tc.number SUB_DF_FILEIO_LSTAT_SYNC_0000 + * @tc.name fileIO_lstat_sync_000 + * @tc.desc Test lstatSync() interface. + * Enter the path parameter to get the file stat. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_lstat_sync_000', 0, async function () { + let fpath = await nextFileName('fileIO_lstat_sync_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileIO.lstatSync(fpath); + expect(stat !== null).assertTrue(); + fileIO.unlinkSync(fpath); + } catch (e) { + console.log('fileIO_lstat_sync_000 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LSTAT_SYNC_0100 + * @tc.name fileIO_lstat_sync_001 + * @tc.desc Test lstatSync() interface. + * The path point to nothing, no such file. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_lstat_sync_001', 0, async function () { + let fpath = await nextFileName('fileIO_lstat_sync_001'); + + try { + fileIO.lstatSync(fpath); + expect(false).assertTrue(); + } catch (e) { + console.log('fileIO_lstat_sync_001 has failed for ' + e.message + ', code: ' + e.code); + expect(e.code == 13900002 && e.message == 'No such file or directory').assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LSTAT_SYNC_0200 + * @tc.name fileIO_lstat_sync_002 + * @tc.desc Test lstatSync() interface. + * Missing parameters. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_lstat_sync_002', 0, async function () { + + try { + fileIO.lstatSync(); + expect(false).assertTrue(); + } catch (e) { + console.log('fileIO_lstat_sync_002 has failed for ' + e.message + ', code: ' + e.code); + expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue(); + } + }); + /** + * @tc.number SUB_DF_FILEIO_LSTAT_INO_0000 + * @tc.name fileIO_lstat_ino_000 + * @tc.desc Test the ino member of class Stat. + * Enter the path parameter to get stat.ino of the file. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_lstat_ino_000', 0, async function () { + let fpath = await nextFileName('fileIO_lstat_ino_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let stat = fileIO.lstatSync(fpath); + expect(isBigInt(stat.ino)).assertTrue(); + fileIO.unlinkSync(fpath); + } catch (e) { + console.log('fileIO_lstat_ino_000 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LSTAT_MODE_0000 + * @tc.name fileIO_lstat_mode_000 + * @tc.desc Test the mode member of class Stat. + * Enter the path parameter to get stat.mode of the file. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_lstat_mode_000', 0, async function () { + let fpath = await nextFileName('fileIO_lstat_mode_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileIO.lstatSync(fpath); + expect(isIntNum(stat.mode)).assertTrue(); + fileIO.unlinkSync(fpath); + } catch (e) { + console.log('fileIO_lstat_mode_000 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LSTAT_UID_0000 + * @tc.name fileIO_lstat_uid_000 + * @tc.desc Test the uid member of class Stat. + * Enter the path parameter to get stat.uid of the file. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_lstat_uid_000', 0, async function () { + let fpath = await nextFileName('fileIO_lstat_uid_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileIO.lstatSync(fpath); + expect(isIntNum(stat.uid)).assertTrue(); + fileIO.unlinkSync(fpath); + } catch (e) { + console.log('fileIO_lstat_uid_000 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LSTAT_GID_0000 + * @tc.name fileIO_lstat_gid_000 + * @tc.desc Test the gid member of class Stat. + * Enter the path parameter to get stat.gid of the file. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_lstat_gid_000', 0, async function () { + let fpath = await nextFileName('fileIO_lstat_gid_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileIO.lstatSync(fpath); + expect(isIntNum(stat.gid)).assertTrue(); + fileIO.unlinkSync(fpath); + } catch (e) { + console.log('fileIO_lstat_gid_000 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LSTAT_SIZE_0000 + * @tc.name fileIO_lstat_size_000 + * @tc.desc Test the size member of class Stat. + * Enter the path parameter to get stat.size of the file. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_lstat_size_000', 0, async function () { + let fpath = await nextFileName('fileIO_lstat_size_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileIO.lstatSync(fpath); + expect(isIntNum(stat.size)).assertTrue(); + fileIO.unlinkSync(fpath); + } catch (e) { + console.log('fileIO_lstat_size_000 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LSTAT_ATIME_0000 + * @tc.name fileIO_lstat_atime_000 + * @tc.desc Test the atime member of class Stat. + * Enter the path or parameter to get stat.atime of the file. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_lstat_atime_000', 0, async function () { + let fpath = await nextFileName('fileIO_lstat_atime_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileIO.lstatSync(fpath); + expect(isIntNum(stat.atime)).assertTrue(); + fileIO.unlinkSync(fpath); + } catch (e) { + console.log('fileIO_lstat_atime_000 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LSTAT_MTIME_0000 + * @tc.name fileIO_lstat_mtime_000 + * @tc.desc Test the mtime member of class Stat. + * Enter the path parameter to get stat.mtime of the file. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_lstat_mtime_000', 0, async function () { + let fpath = await nextFileName('fileIO_lstat_mtime_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileIO.lstatSync(fpath); + expect(isIntNum(stat.mtime)).assertTrue(); + fileIO.unlinkSync(fpath); + } catch (e) { + console.log('fileIO_lstat_mtime_000 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LSTAT_CTIME_0000 + * @tc.name fileIO_lstat_ctime_000 + * @tc.desc Test the ctime member of class Stat. + * Enter the path parameter to get stat.ctime of the file. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_lstat_ctime_000', 0, async function () { + let fpath = await nextFileName('fileIO_lstat_ctime_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileIO.lstatSync(fpath); + expect(isIntNum(stat.ctime)).assertTrue(); + fileIO.unlinkSync(fpath); + } catch (e) { + console.log('fileIO_lstat_ctime_000 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LSTAT_IS_BLOCK_DEVICE_0000 + * @tc.name fileIO_lstat_is_block_device_000 + * @tc.desc Test Lstat.isBlockDevice() interface. + * This interface shall not treat a normal file as a block special device. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_lstat_is_block_device_000', 0, async function () { + let fpath = await nextFileName('fileIO_lstat_is_block_device_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileIO.lstatSync(fpath); + expect(stat.isBlockDevice() === false).assertTrue(); + fileIO.unlinkSync(fpath); + } catch (e) { + console.log('fileIO_lstat_is_block_device_000 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LSTAT_IS_BLOCK_DEVICE_0100 + * @tc.name fileIO_test_lstat_is_block_device_001 + * @tc.desc Test Lstat.isBlockDevice() interface. + * This interface does not require parameters. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_test_lstat_is_block_device_001', 0, async function () { + let fpath = await nextFileName('fileIO_test_lstat_is_block_device_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + fileIO.lstatSync(fpath).isBlockDevice(-1); + expect(false).assertTrue(); + } catch (e) { + fileIO.unlinkSync(fpath); + console.log('fileIO_test_lstat_is_block_device_001 has failed for ' + e.message + ', code: ' + e.code); + expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LSTAT_IS_CHARACTER_DEVICE_0000 + * @tc.name fileIO_lstat_is_character_device_000 + * @tc.desc Test Lstat.isCharacterDevice() interface. + * This interface shall not treat a normal file as a character special device. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_lstat_is_character_device_000', 0, async function () { + let fpath = await nextFileName('fileIO_lstat_is_character_device_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileIO.lstatSync(fpath); + expect(stat.isCharacterDevice() === false).assertTrue(); + fileIO.unlinkSync(fpath); + } catch (e) { + console.log('fileIO_lstat_is_character_device_000 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LSTAT_IS_CHARACTER_DEVICE_0100 + * @tc.name fileIO_lstat_is_character_device_001 + * @tc.desc Test Lstat.isCharacterDevice() interface. + * This interface does not require parameters. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_test_lstat_is_character_device_001', 0, async function () { + let fpath = await nextFileName('fileIO_test_lstat_is_character_device_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + fileIO.lstatSync(fpath).isCharacterDevice(-1); + expect(false).assertTrue(); + } catch (e) { + fileIO.unlinkSync(fpath); + console.log('fileIO_test_lstat_is_character_device_001 has failed for ' + e.message + ', code: ' + e.code); + expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LSTAT_IS_DIRECTORY_0000 + * @tc.name fileIO_lstat_is_directory_000 + * @tc.desc Test Lstat.isDirectory() interface. + * This interface shall not treat a normal file as a directory. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_lstat_is_directory_000', 0, async function () { + let fpath = await nextFileName('fileIO_lstat_is_directory_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileIO.lstatSync(fpath); + expect(stat.isDirectory() === false).assertTrue(); + fileIO.unlinkSync(fpath); + } catch (e) { + console.log('fileIO_lstat_is_directory_000 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LSTAT_IS_DIRECTORY_0100 + * @tc.name fileIO_lstat_is_directory_001 + * @tc.desc Test Lstat.isDirectory() interface. + * This interface shall treat a directory as a directory. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_lstat_is_directory_001', 0, async function () { + let dpath = await nextFileName('fileIO_lstat_is_directory_001') + 'd'; + + try { + fileIO.mkdirSync(dpath); + let stat = fileIO.lstatSync(dpath); + expect(stat.isDirectory() === true).assertTrue(); + fileIO.rmdirSync(dpath); + } catch (e) { + console.log('fileIO_lstat_is_directory_001 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LSTAT_IS_DIRECTORY_0200 + * @tc.name fileIO_lstat_is_directory_002 + * @tc.desc Test Lstat.isDirectory() interface. + * This interface does not require parameters. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_lstat_is_directory_002', 0, async function () { + let dpath = await nextFileName('fileIO_lstat_is_directory_002') + 'd'; + + try { + fileIO.mkdirSync(dpath); + fileIO.lstatSync(dpath).isDirectory(-1); + expect(false).assertTrue(); + } catch (e) { + fileIO.rmdirSync(dpath); + console.log('fileIO_lstat_is_directory_002 has failed for ' + e.message + ', code: ' + e.code); + expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LSTAT_IS_FIFO_0000 + * @tc.name fileIO_lstat_is_fifo_000 + * @tc.desc Test Lstat.isFIFO() interface. + * This interface shall not treat a normal file as a FIFO. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_lstat_is_fifo_000', 0, async function () { + let fpath = await nextFileName('fileIO_lstat_is_fifo_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileIO.lstatSync(fpath); + expect(stat.isFIFO() === false).assertTrue(); + fileIO.unlinkSync(fpath); + } catch (e) { + console.log('fileIO_lstat_is_fifo_000 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LSTAT_IS_FIFO_0100 + * @tc.name fileIO_lstat_is_fifo_001 + * @tc.desc Test Lstat.isFIFO() interface. + * This interface does not require parameters. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_test_lstat_is_fifo_002', 0, async function () { + let fpath = await nextFileName('fileIO_test_lstat_is_fifo_002'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + fileIO.lstatSync(fpath).isFIFO(-1); + expect(false).assertTrue(); + } catch (e) { + fileIO.unlinkSync(fpath); + console.log('fileIO_test_lstat_is_fifo_002 has failed for ' + e.message + ', code: ' + e.code); + expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LSTAT_IS_FILE_0000 + * @tc.name fileIO_lstat_is_file_000 + * @tc.desc Test Lstat.isFile() interface. + * This interface shall treat a normal file as a normal file. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_lstat_is_file_000', 0, async function () { + let fpath = await nextFileName('fileIO_lstat_is_file_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileIO.lstatSync(fpath); + expect(stat.isFile() === true).assertTrue(); + fileIO.unlinkSync(fpath); + } catch (e) { + console.log('fileIO_lstat_is_file_000 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LSTAT_IS_FILE_0100 + * @tc.name fileIO_lstat_is_file_001 + * @tc.desc Test Lstat.isFile() interface. + * This interface shall not treat a directory as a normal file. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_lstat_is_file_001', 0, async function () { + let dpath = await nextFileName('fileIO_lstat_is_file_001'); + + try { + fileIO.mkdirSync(dpath); + let stat = fileIO.lstatSync(dpath); + expect(stat.isFile() === false).assertTrue(); + fileIO.rmdirSync(dpath); + } catch (e) { + console.log('fileIO_lstat_is_file_001 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LSTAT_IS_FILE_0200 + * @tc.name fileIO_test_lstat_is_file_002 + * @tc.desc Test Lstat.isFile() interface. + * This interface does not require parameters. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_test_lstat_is_file_002', 0, async function () { + let dpath = await nextFileName('fileIO_test_lstat_is_file_002'); + + try { + fileIO.mkdirSync(dpath); + fileIO.lstatSync(dpath).isFile(-1); + expect(false).assertTrue(); + } catch (e) { + fileIO.rmdirSync(dpath); + console.log('fileIO_test_lstat_is_file_002 has failed for ' + e.message + ', code: ' + e.code); + expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LSTAT_IS_SOCKET_0000 + * @tc.name fileIO_lstat_is_socket_000 + * @tc.desc Test Lstat.isSocket() interface. + * This interface shall not treat a file as a socket. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_lstat_is_socket_000', 0, async function () { + let fpath = await nextFileName('fileIO_lstat_is_socket_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileIO.lstatSync(fpath); + expect(stat.isSocket() === false).assertTrue(); + fileIO.unlinkSync(fpath); + } catch (e) { + console.log('fileIO_lstat_is_socket_000 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LSTAT_IS_SOCKET_0100 + * @tc.name fileIO_lstat_is_socket_001 + * @tc.desc Test Lstat.isSocket() interface. + * This interface does not require parameters. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_lstat_is_socket_001', 0, async function () { + let fpath = await nextFileName('fileIO_lstat_is_socket_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + fileIO.lstatSync(fpath).isSocket(-1); + expect(false).assertTrue(); + } catch (e) { + fileIO.unlinkSync(fpath); + console.log('fileIO_lstat_is_socket_001 has failed for ' + e.message + ', code: ' + e.code); + expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LSTAT_IS_SYMBOLIC_LINK_0000 + * @tc.name fileIO_lstat_is_symbolic_link_000 + * @tc.desc Test Lstat.isSymbolicLink() interface. + * This interface shall not treat a normal file as a symbolic link. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_lstat_is_symbolic_link_000', 0, async function () { + let fpath = await nextFileName('fileIO_lstat_is_symbolic_link_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileIO.lstatSync(fpath); + expect(stat.isSymbolicLink() === false).assertTrue(); + } catch (e) { + fileIO.unlinkSync(fpath); + console.log('fileIO_lstat_is_symbolic_link_000 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LSTAT_IS_SYMBOLIC_LINK_0100 + * @tc.name fileIO_lstat_is_symbolic_link_001 + * @tc.desc Test Lstat.isSymbolicLink() interface. + * This interface does not require parameters. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_lstat_is_symbolic_link_001', 0, async function () { + let fpath = await nextFileName('fileIO_lstat_is_symbolic_link_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + fileIO.lstatSync(fpath).isSymbolicLink(-1); + expect(false).assertTrue(); + } catch (e) { + fileIO.unlinkSync(fpath); + console.log('fileIO_lstat_is_symbolic_link_001 has failed for ' + e.message + ', code: ' + e.code); + expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LSTAT_ASYNC_0000 + * @tc.name fileIO_lstat_async_000 + * @tc.desc Test lstat() interface. Promise.then().catch() + * Enter the path parameter to get the file stat. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_lstat_async_000', 0, async function (done) { + let fpath = await nextFileName('fileIO_lstat_async_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + fileIO.lstat(fpath).then((stat) => { + expect(stat !== null).assertTrue(); + fileIO.unlinkSync(fpath); + done(); + }).catch((err) => { + console.log('fileIO_lstat_async_000 error package: ' + JSON.stringify(err)); + expect(false).assertTrue(); + }); + } catch (e) { + console.log('fileIO_lstat_async_000 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LSTAT_ASYNC_0100 + * @tc.name fileIO_lstat_async_001 + * @tc.desc Test lstat() interface. Callback. + * Enter the path or parameter to get the file stat. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_lstat_async_001', 0, async function (done) { + let fpath = await nextFileName('fileIO_lstat_async_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + fileIO.lstat(fpath, (err) => { + if(err) { + console.log('fileIO_lstat_async_001 error package: ' + JSON.stringify(err)); + expect(false).assertTrue(); + } + fileIO.unlinkSync(fpath); + done(); + }); + } catch (e) { + console.log('fileIO_lstat_async_001 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LSTAT_ASYNC_0200 + * @tc.name fileIO_lstat_async_002 + * @tc.desc Test lstat() interface. Promise. + * Enter the path or parameter to get the file stat. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_lstat_async_002', 0, async function (done) { + let fpath = await nextFileName('fileIO_lstat_async_002'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = await fileIO.lstat(fpath); + expect(stat !== null).assertTrue(); + fileIO.unlinkSync(fpath); + done(); + } catch (e) { + console.log('fileIO_lstat_async_002 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LSTAT_ASYNC_0300 + * @tc.name fileIO_lstat_async_003 + * @tc.desc Test lstat() interface. + * The path point to nothing, no such file. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_lstat_async_003', 0, async function (done) { + let fpath = await nextFileName('fileIO_lstat_async_003'); + + try { + fileIO.lstat(fpath, (err) => { + if (err) { + console.log('fileIO_lstat_async_003 error: {message: ' + err.message + ', code: ' + err.code + '}'); + expect(err.code == 13900002 && err.message == 'No such file or directory').assertTrue(); + done(); + } + }); + } catch (e) { + console.log('fileIO_lstat_async_003 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LSTAT_ASYNC_0400 + * @tc.name fileIO_lstat_async_004 + * @tc.desc Test lstat() interface. Promise. + * The path point to nothing, no such file. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_lstat_async_004', 0, async function (done) { + let fpath = await nextFileName('fileIO_lstat_async_004'); + + try { + await fileIO.lstat(fpath); + expect(false).assertTrue(); + } catch (e) { + console.log('fileIO_lstat_async_004 has failed for ' + e.message + ', code: ' + e.code); + expect(e.code == 13900002 && e.message == 'No such file or directory').assertTrue(); + done(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LSTAT_ASYNC_INO_0000 + * @tc.name fileIO_lstat_async_ino_000 + * @tc.desc Test the ino member of class Stat. Promise. + * Enter the path parameter to get stat.ino of the file. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_lstat_async_ino_000', 0, async function (done) { + let fpath = await nextFileName('fileIO_lstat_async_ino_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = await fileIO.lstat(fpath); + expect(isBigInt(stat.ino)).assertTrue(); + fileIO.unlinkSync(fpath); + done(); + } catch (e) { + console.log('fileIO_lstat_async_ino_000 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LSTAT_ASYNC_INO_0100 + * @tc.name fileIO_lstat_async_ino_001 + * @tc.desc Test the ino member of class Stat. Callback. + * Enter the path parameter to get stat.ino of the file. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_lstat_async_ino_001', 0, async function (done) { + let fpath = await nextFileName('fileIO_lstat_async_ino_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + fileIO.lstat(fpath, (err, stat) => { + if(err) { + console.log('fileIO_lstat_async_ino_001 error package: ' + JSON.stringify(err)); + expect(false).assertTrue(); + } + expect(isBigInt(stat.ino)).assertTrue(); + fileIO.unlinkSync(fpath); + done(); + }); + } catch (e) { + console.log('fileIO_lstat_async_ino_001 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LSTAT_ASYNC_MODE_0000 + * @tc.name fileIO_lstat_async_mode_000 + * @tc.desc Test the mode member of class Stat. Promise. + * Enter the path or parameter to get stat.mode of the file. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_lstat_async_mode_000', 0, async function (done) { + let fpath = await nextFileName('fileIO_lstat_async_mode_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = await fileIO.lstat(fpath); + expect(isIntNum(stat.mode)).assertTrue(); + fileIO.unlinkSync(fpath); + done(); + } catch (e) { + console.log('fileIO_lstat_async_mode_000 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LSTAT_ASYNC_MODE_0100 + * @tc.name fileIO_lstat_async_mode_001 + * @tc.desc Test the mode member of class Stat. Callback. + * Enter the path or parameter to get stat.mode of the file. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_lstat_async_mode_001', 0, async function (done) { + let fpath = await nextFileName('fileIO_lstat_async_mode_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + fileIO.lstat(fpath, (err, stat) => { + if(err) { + console.log('fileIO_lstat_async_mode_001 error package: ' + JSON.stringify(err)); + expect(false).assertTrue(); + } + expect(isIntNum(stat.mode)).assertTrue(); + fileIO.unlinkSync(fpath); + done(); + }); + } catch (e) { + console.log('fileIO_lstat_async_mode_000 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LSTAT_ASYNC_UID_0000 + * @tc.name fileIO_lstat_async_uid_000 + * @tc.desc Test the uid member of class Stat. Promise. + * Enter the path parameter to get stat.uid of the file. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_lstat_async_uid_000', 0, async function (done) { + let fpath = await nextFileName('fileIO_lstat_async_uid_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = await fileIO.lstat(fpath); + expect(isIntNum(stat.uid)).assertTrue(); + fileIO.unlinkSync(fpath); + done(); + } catch (e) { + console.log('fileIO_lstat_async_uid_000 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LSTAT_ASYNC_UID_0100 + * @tc.name fileIO_lstat_async_uid_001 + * @tc.desc Test the uid member of class Stat. Callback. + * Enter the path parameter to get stat.uid of the file. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_lstat_async_uid_001', 0, async function (done) { + let fpath = await nextFileName('fileIO_lstat_async_uid_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + fileIO.lstat(fpath, (err, stat) => { + if(err) { + console.log('fileIO_lstat_async_uid_001 error package: ' + JSON.stringify(err)); + expect(false).assertTrue(); + } + expect(isIntNum(stat.uid)).assertTrue(); + fileIO.unlinkSync(fpath); + done(); + }); + } catch (e) { + console.log('fileIO_lstat_async_uid_000 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LSTAT_ASYNC_GID_0000 + * @tc.name fileIO_lstat_async_gid_000 + * @tc.desc Test the gid member of class Stat. Promise. + * Enter the path parameter to get stat.gid of the file. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_lstat_async_gid_000', 0, async function (done) { + let fpath = await nextFileName('fileIO_lstat_async_gid_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = await fileIO.lstat(fpath); + expect(isIntNum(stat.gid)).assertTrue(); + fileIO.unlinkSync(fpath); + done(); + } catch (e) { + console.log('fileIO_lstat_async_gid_000 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LSTAT_ASYNC_GID_0100 + * @tc.name fileIO_lstat_async_gid_001 + * @tc.desc Test the gid member of class Stat. Callback. + * Enter the path parameter to get stat.gid of the file. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_lstat_async_gid_001', 0, async function (done) { + let fpath = await nextFileName('fileIO_lstat_async_gid_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + fileIO.lstat(fpath, (err, stat) => { + if (err) { + console.log('fileIO_lstat_async_gid_001 error package: ' + JSON.stringify(err)); + expect(false).assertTrue(); + } + expect(isIntNum(stat.gid)).assertTrue(); + fileIO.unlinkSync(fpath); + done(); + }); + } catch (e) { + console.log('fileIO_lstat_async_gid_001 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LSTAT_ASYNC_SIZE_0000 + * @tc.name fileIO_lstat_async_size_000 + * @tc.desc Test the size member of class Stat. Promise. + * Enter the path parameter to get stat.size of the file. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_lstat_async_size_000', 0, async function (done) { + let fpath = await nextFileName('fileIO_lstat_async_size_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = await fileIO.lstat(fpath); + expect(isIntNum(stat.size)).assertTrue(); + fileIO.unlinkSync(fpath); + done(); + } catch (e) { + console.log('fileIO_lstat_async_size_000 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LSTAT_ASYNC_SIZE_0100 + * @tc.name fileIO_lstat_async_size_001 + * @tc.desc Test the size member of class Stat. Callback. + * Enter the path parameter to get stat.size of the file. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_lstat_async_size_001', 0, async function (done) { + let fpath = await nextFileName('fileIO_lstat_async_size_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + fileIO.lstat(fpath, (err, stat) => { + if (err) { + console.log('fileIO_lstat_async_size_001 error package: ' + JSON.stringify(err)); + expect(false).assertTrue(); + } + expect(isIntNum(stat.size)).assertTrue(); + fileIO.unlinkSync(fpath); + done(); + }); + } catch (e) { + console.log('fileIO_lstat_async_size_000 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LSTAT_ASYNC_ATIME_0000 + * @tc.name fileIO_lstat_async_atime_000 + * @tc.desc Test the atime member of class Stat. Promise. + * Enter the path parameter to get stat.atime of the file. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_lstat_async_atime_000', 0, async function (done) { + let fpath = await nextFileName('fileIO_lstat_async_atime_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = await fileIO.lstat(fpath); + expect(isIntNum(stat.atime)).assertTrue(); + fileIO.unlinkSync(fpath); + done(); + } catch (e) { + console.log('fileIO_lstat_async_atime_000 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LSTAT_ASYNC_ATIME_0100 + * @tc.name fileIO_lstat_async_atime_001 + * @tc.desc Test the atime member of class Stat. Callback. + * Enter the path or fd parameter to get stat.atime of the file. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_lstat_async_atime_001', 0, async function (done) { + let fpath = await nextFileName('fileIO_lstat_async_atime_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + fileIO.lstat(fpath, (err, stat) => { + if (err) { + console.log('fileIO_lstat_async_atime_001 error package: ' + JSON.stringify(err)); + expect(false).assertTrue(); + } + expect(isIntNum(stat.atime)).assertTrue(); + fileIO.unlinkSync(fpath); + done(); + }); + } catch (e) { + console.log('fileIO_lstat_async_atime_001 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LSTAT_ASYNC_MTIME_0000 + * @tc.name fileIO_lstat_async_mtime_000 + * @tc.desc Test the mtime member of class Stat. Promise. + * Enter the path or fd parameter to get stat.mtime of the file. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_lstat_async_mtime_000', 0, async function (done) { + let fpath = await nextFileName('fileIO_lstat_async_mtime_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = await fileIO.lstat(fpath); + expect(isIntNum(stat.mtime)).assertTrue(); + fileIO.unlinkSync(fpath); + done(); + } catch (e) { + console.log('fileIO_lstat_async_mtime_000 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LSTAT_ASYNC_MTIME_0100 + * @tc.name fileIO_lstat_async_mtime_001 + * @tc.desc Test the mtime member of class Stat. Callback. + * Enter the path or fd parameter to get stat.mtime of the file. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_lstat_async_mtime_001', 0, async function (done) { + let fpath = await nextFileName('fileIO_lstat_async_mtime_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + fileIO.lstat(fpath, (err, stat) => { + if (err) { + console.log('fileIO_lstat_async_mtime_001 error package: ' + JSON.stringify(err)); + expect(false).assertTrue(); + } + expect(isIntNum(stat.mtime)).assertTrue(); + fileIO.unlinkSync(fpath); + done(); + }); + } catch (e) { + console.log('fileIO_lstat_async_mtime_001 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LSTAT_ASYNC_CTIME_0000 + * @tc.name fileIO_lstat_async_ctime_000 + * @tc.desc Test the ctime member of class Stat. Promise. + * Enter the path or fd parameter to get stat.ctime of the file. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_lstat_async_ctime_000', 0, async function (done) { + let fpath = await nextFileName('fileIO_lstat_async_ctime_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = await fileIO.lstat(fpath); + expect(isIntNum(stat.ctime)).assertTrue(); + fileIO.unlinkSync(fpath); + done(); + } catch (e) { + console.log('fileIO_lstat_async_ctime_000 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LSTAT_ASYNC_CTIME_0100 + * @tc.name fileIO_lstat_async_ctime_001 + * @tc.desc Test the ctime member of class Stat. Callback. + * Enter the path or fd parameter to get stat.ctime of the file. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_lstat_async_ctime_001', 0, async function (done) { + let fpath = await nextFileName('fileIO_lstat_async_ctime_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + fileIO.lstat(fpath, (err, stat) => { + if (err) { + console.log('fileIO_lstat_async_ctime_001 error package: ' + JSON.stringify(err)); + expect(false).assertTrue(); + } + expect(isIntNum(stat.ctime)).assertTrue(); + fileIO.unlinkSync(fpath); + done(); + }); + } catch (e) { + console.log('fileIO_lstat_async_ctime_000 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LSTAT_ASYNC_IS_BLOCK_DEVICE_0000 + * @tc.name fileIO_lstat_async_is_block_device_000 + * @tc.desc Test the isBlockDevice() method of class Stat. Promise. + * This interface shall not treat a normal file as a block special device. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_lstat_async_is_block_device_000', 0, async function (done) { + let fpath = await nextFileName('fileIO_lstat_async_is_block_device_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = await fileIO.lstat(fpath); + expect(stat.isBlockDevice() === false).assertTrue(); + fileIO.unlinkSync(fpath); + done(); + } catch (e) { + console.log('fileIO_lstat_async_is_block_device_000 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LSTAT_ASYNC_IS_BLOCK_DEVICE_0010 + * @tc.name fileIO_lstat_async_is_block_device_001 + * @tc.desc Test the isBlockDevice() method of class Stat. Callback. + * This interface shall not treat a normal file as a block special device. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_lstat_async_is_block_device_001', 0, async function (done) { + let fpath = await nextFileName('fileIO_lstat_async_is_block_device_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + fileIO.lstat(fpath, (err, stat) => { + if (err) { + console.log('fileIO_lstat_async_is_block_device_001 error package: ' + JSON.stringify(err)); + expect(false).assertTrue(); + } + expect(stat.isBlockDevice() === false).assertTrue(); + fileIO.unlinkSync(fpath); + done(); + }); + } catch (e) { + console.log('fileIO_lstat_async_is_block_device_001 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LSTAT_ASYNC_IS_CHARACTER_DEVICE_0000 + * @tc.name fileIO_lstat_async_is_character_device_000 + * @tc.desc Test the isCharacterDevice() method of class Stat. Promise. + * This interface shall not treat a normal file as a character special device. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_lstat_async_is_character_device_000', 0, async function (done) { + let fpath = await nextFileName('fileIO_lstat_async_is_character_device_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = await fileIO.lstat(fpath); + expect(stat.isCharacterDevice() === false).assertTrue(); + fileIO.unlinkSync(fpath); + done(); + } catch (e) { + console.log('fileIO_lstat_async_is_character_device_000 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LSTAT_ASYNC_IS_CHARACTER_DEVICE_0010 + * @tc.name fileIO_lstat_async_is_character_device_001 + * @tc.desc Test the isCharacterDevice() method of class Stat. Callback. + * This interface shall not treat a normal file as a character special device. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_lstat_async_is_character_device_001', 0, async function (done) { + let fpath = await nextFileName('fileIO_lstat_async_is_character_device_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + fileIO.lstat(fpath, (err, stat) => { + if (err) { + console.log('fileIO_lstat_async_is_character_device_001 error package: ' + JSON.stringify(err)); + expect(false).assertTrue(); + } + expect(stat.isCharacterDevice() === false).assertTrue(); + fileIO.unlinkSync(fpath); + done(); + }); + } catch (e) { + console.log('fileIO_lstat_async_is_character_device_001 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LSTAT_ASYNC_IS_DIRECTORY_0000 + * @tc.name fileIO_lstat_async_is_directory_000 + * @tc.desc Test the isDirectory() method of class Stat. Promise. + * This interface shall not treat a normal file as a directory. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_lstat_async_is_directory_000', 0, async function (done) { + let fpath = await nextFileName('fileIO_lstat_async_is_directory_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = await fileIO.lstat(fpath); + expect(stat.isDirectory() === false).assertTrue(); + fileIO.unlinkSync(fpath); + done(); + } catch (e) { + console.log('fileIO_lstat_async_is_directory_000 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LSTAT_ASYNC_IS_DIRECTORY_0010 + * @tc.name fileIO_lstat_async_is_directory_001 + * @tc.desc Test the isDirectory() method of class Stat. Promise. + * This interface shall not treat a directory as a directory. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_lstat_async_is_directory_001', 0, async function (done) { + let dpath = await nextFileName('fileIO_lstat_async_is_directory_001') + 'd'; + + + try { + fileIO.mkdirSync(dpath); + let stat = await fileIO.lstat(dpath); + expect(stat.isDirectory() === true).assertTrue(); + fileIO.rmdirSync(dpath); + done(); + } catch (e) { + console.log('fileIO_lstat_async_is_directory_001 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LSTAT_ASYNC_IS_DIRECTORY_0020 + * @tc.name fileIO_lstat_async_is_directory_002 + * @tc.desc Test the isDirectory() method of class Stat. Callback. + * This interface shall not treat a directory as a directory. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_lstat_async_is_directory_002', 0, async function (done) { + let dpath = await nextFileName('fileIO_lstat_async_is_directory_002') + 'd'; + + try { + fileIO.mkdirSync(dpath); + fileIO.lstat(dpath, (err, stat) => { + if (err) { + console.log('fileIO_lstat_async_is_directory_002 error package: ' + JSON.stringify(err)); + expect(false).assertTrue(); + } + expect(stat.isDirectory() === true).assertTrue(); + fileIO.rmdirSync(dpath); + done(); + }); + } catch (e) { + console.log('fileIO_lstat_async_is_directory_002 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LSTAT_ASYNC_IS_FIFO_0000 + * @tc.name fileIO_lstat_async_is_fifo_000 + * @tc.desc Test the isFIFO() method of class Stat. Promise. + * This interface shall not treat a normal file as a FIFO. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_lstat_async_is_fifo_000', 0, async function (done) { + let fpath = await nextFileName('fileIO_lstat_async_is_fifo_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = await fileIO.lstat(fpath); + expect(stat.isFIFO() === false).assertTrue(); + fileIO.unlinkSync(fpath); + done(); + } catch (e) { + console.log('fileIO_lstat_async_is_fifo_000 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LSTAT_ASYNC_IS_FIFO_0010 + * @tc.name fileIO_lstat_async_is_fifo_001 + * @tc.desc Test the isFIFO() method of class Stat. Callback. + * This interface shall not treat a normal file as a FIFO. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_lstat_async_is_fifo_001', 0, async function (done) { + let fpath = await nextFileName('fileIO_lstat_async_is_fifo_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + fileIO.lstat(fpath, (err, stat) => { + if (err) { + console.log('fileIO_lstat_async_is_character_device_001 error package: ' + JSON.stringify(err)); + expect(false).assertTrue(); + } + expect(stat.isFIFO() === false).assertTrue(); + fileIO.unlinkSync(fpath); + done(); + }); + } catch (e) { + console.log('fileIO_lstat_async_is_fifo_001 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LSTAT_ASYNC_IS_FILE_0000 + * @tc.name fileIO_lstat_async_is_file_000 + * @tc.desc Test the isFile() method of class Stat. Promise. + * This interface shall treat a normal file as a normal file. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_lstat_async_is_file_000', 0, async function (done) { + let fpath = await nextFileName('fileIO_lstat_async_is_file_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = await fileIO.lstat(fpath); + expect(stat.isFile() === true).assertTrue(); + fileIO.unlinkSync(fpath); + done(); + } catch (e) { + console.log('fileIO_lstat_async_is_file_000 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LSTAT_ASYNC_IS_FILE_0010 + * @tc.name fileIO_lstat_async_is_file_001 + * @tc.desc Test the isFile() method of class Stat. Callback. + * This interface shall treat a normal file as a normal file. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_lstat_async_is_file_001', 0, async function (done) { + let fpath = await nextFileName('fileIO_lstat_async_is_file_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + fileIO.lstat(fpath, (err, stat) => { + if (err) { + console.log('fileIO_lstat_async_is_file_001 error package: ' + JSON.stringify(err)); + expect(false).assertTrue(); + } + expect(stat.isFile() === true).assertTrue(); + fileIO.unlinkSync(fpath); + done(); + }); + } catch (e) { + console.log('fileIO_lstat_async_is_file_001 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LSTAT_ASYNC_IS_FILE_0020 + * @tc.name fileIO_lstat_async_is_file_002 + * @tc.desc Test the isFile() method of class Stat. Promise. + * This interface shall not treat a directory as a normal file. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_lstat_async_is_file_002', 0, async function (done) { + let dpath = await nextFileName('fileIO_lstat_async_is_file_002'); + + try { + fileIO.mkdirSync(dpath); + let stat = await fileIO.lstat(dpath); + expect(stat.isFile() === false).assertTrue(); + fileIO.rmdirSync(dpath); + done(); + } catch (e) { + console.log('fileIO_lstat_async_is_file_002 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LSTAT_ASYNC_IS_SOCKET_0000 + * @tc.name fileIO_lstat_async_is_socket_000 + * @tc.desc Test the isSocket() method of class Stat. Promise. + * This interface shall not treat a file as a socket. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_lstat_async_is_socket_000', 0, async function (done) { + let fpath = await nextFileName('fileIO_lstat_async_is_socket_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = await fileIO.lstat(fpath); + expect(stat.isSocket() === false).assertTrue(); + fileIO.unlinkSync(fpath); + done(); + } catch (e) { + console.log('fileIO_lstat_async_is_socket_000 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LSTAT_ASYNC_IS_SOCKET_0010 + * @tc.name fileIO_lstat_async_is_socket_001 + * @tc.desc Test the isSocket() method of class Stat. Callback. + * This interface shall not treat a file as a socket. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_lstat_async_is_socket_001', 0, async function (done) { + let fpath = await nextFileName('fileIO_lstat_async_is_socket_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + fileIO.lstat(fpath, (err, stat) => { + if (err) { + console.log('fileIO_lstat_async_is_socket_001 error package: ' + JSON.stringify(err)); + expect(false).assertTrue(); + } + expect(stat.isSocket() === false).assertTrue(); + fileIO.unlinkSync(fpath); + done(); + }); + } catch (e) { + console.log('fileIO_lstat_async_is_socket_001 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LSTAT_ASYNC_IS_SYMBOLIC_LINK_0000 + * @tc.name fileIO_lstat_async_is_symbolic_link_000 + * @tc.desc Test the isSymbolicLink() method of class Stat. Promise. + * This interface shall not treat a normal file as a symbolic link. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_lstat_async_is_symbolic_link_000', 0, async function (done) { + let fpath = await nextFileName('fileIO_lstat_async_is_symbolic_link_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = await fileIO.lstat(fpath); + expect(stat.isSymbolicLink() === false).assertTrue(); + fileIO.unlinkSync(fpath); + done(); + } catch (e) { + console.log('fileIO_lstat_async_is_symbolic_link_000 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_LSTAT_ASYNC_IS_SYMBOLIC_LINK_0100 + * @tc.name fileIO_lstat_async_is_symbolic_link_001 + * @tc.desc Test the isSymbolicLink() method of class Stat. Callback. + * This interface shall not treat a normal file as a symbolic link. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_lstat_async_is_symbolic_link_001', 0, async function (done) { + let fpath = await nextFileName('fileIO_lstat_async_is_symbolic_link_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + fileIO.lstat(fpath, (err, stat) => { + if (err) { + console.log('fileIO_lstat_async_is_symbolic_link_001 error package: ' + JSON.stringify(err)); + expect(false).assertTrue(); + } + expect(stat.isSymbolicLink() === false).assertTrue(); + fileIO.unlinkSync(fpath); + done(); + }); + } catch (e) { + console.log('fileIO_lstat_async_is_symbolic_link_001 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_APPEND_FILE_SYNC_0010 + * @tc.name fileIO_test_append_file_sync_000 + * @tc.desc Test lstat.lstatSync() interface. + * Modify the file, view the file status changes by path. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_test_append_file_sync_000', 0, async function () { + let fpath = await nextFileName('fileIO_test_append_file_sync_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileIO.lstatSync(fpath); + expect(isIntNum(stat.size)).assertTrue(); + + let file = fileIO.openSync(fpath, fileIO.OpenMode.APPEND | fileIO.OpenMode.READ_WRITE); + expect(isIntNum(file.fd)).assertTrue(); + + expect(fileIO.writeSync(file.fd, FILE_CONTENT) == FILE_CONTENT.length).assertTrue(); + fileIO.closeSync(file); + + stat = fileIO.lstatSync(fpath); + expect(stat.size == FILE_CONTENT.length * 2).assertTrue(); + fileIO.unlinkSync(fpath); + } catch (e) { + console.log('fileIO_test_append_file_sync_000 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); +}) +} diff --git a/storage/storagefileiov9jstest/src/main/js/test/members/mkdtemp.test.js b/storage/storagefileiov9jstest/src/main/js/test/members/mkdtemp.test.js new file mode 100644 index 000000000..aee25dd85 --- /dev/null +++ b/storage/storagefileiov9jstest/src/main/js/test/members/mkdtemp.test.js @@ -0,0 +1,215 @@ +/* + * Copyright (C) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the 'License'); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an 'AS IS' BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { fileIO, nextFileName, describe, it, expect } from '../Common'; + +export default function fileIOMkdtemp() { +describe('fileIO_fs_mkdtemp', function () { + + /** + * @tc.number SUB_DF_FILEIO_MKDTEMP_SYNC_0000 + * @tc.name fileIO_test_mkdtemp_sync_000 + * @tc.desc Test mkdtempSync() interface. + * Create a temporary directory, verify the normal function. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_test_mkdtemp_sync_000', 0, async function () { + let dpath = await nextFileName('fileIO_test_mkdtemp_sync_000'); + + try { + dpath = dpath + 'XXXXXX'; + let res = fileIO.mkdtempSync(dpath); + expect(fileIO.accessSync(res)).assertTrue(); + fileIO.rmdirSync(res); + } catch (e) { + console.log('fileIO_test_mkdtemp_sync_000 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_MKDTEMP_SYNC_0100 + * @tc.name fileIO_test_mkdtemp_sync_001 + * @tc.desc Test mkdtempSync() interface. + * The directory should end in XXXXXX. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_test_mkdtemp_sync_001', 0, async function () { + let dpath = await nextFileName('fileIO_test_mkdtemp_sync_000'); + + try { + fileIO.mkdtempSync(dpath); + expect(false).assertTrue(); + } catch (e) { + console.log('fileIO_test_mkdtemp_sync_001 has failed for ' + e.message + ', code: ' + e.code); + expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_MKDTEMP_SYNC_0200 + * @tc.name fileIO_test_mkdtemp_sync_002 + * @tc.desc Test mkdtempSync() interface. + * Missing parameters. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_test_mkdtemp_sync_002', 0, async function () { + + try { + fileIO.mkdtempSync(); + expect(false).assertTrue(); + } catch (e) { + console.log('fileIO_test_mkdtemp_sync_002 has failed for ' + e.message + ', code: ' + e.code); + expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_MKDTEMP_ASYNC_0000 + * @tc.name fileIO_test_mkdtemp_async_000 + * @tc.desc Test mkdtemp() interface. Promise. + * Create a temporary directory, verify the normal function. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_test_mkdtemp_async_000', 0, async function (done) { + let dpath = await nextFileName('fileIO_test_mkdtemp_async_000'); + + try { + dpath = dpath + 'XXXXXX'; + let res = await fileIO.mkdtemp(dpath); + expect(fileIO.accessSync(res)).assertTrue(); + fileIO.rmdirSync(res); + done(); + } catch (e) { + console.log('fileIO_test_mkdtemp_async_000 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_MKDTEMP_ASYNC_0100 + * @tc.name fileIO_test_mkdtemp_async_001 + * @tc.desc Test mkdtemp() interface. Callback. + * Create a temporary directory, verify the normal function. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_test_mkdtemp_async_001', 0, async function (done) { + let dpath = await nextFileName('fileIO_test_mkdtemp_async_001'); + + try { + dpath = dpath + 'XXXXXX'; + fileIO.mkdtemp(dpath, (err, res) => { + if (err) { + console.log('fileIO_test_mkdtemp_async_001 error package: ' + JSON.stringify(err)); + expect(false).assertTrue(); + } + expect(fileIO.accessSync(res)).assertTrue(); + fileIO.rmdirSync(res); + done(); + }); + } catch (e) { + console.log('fileIO_test_mkdtemp_async_001 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_MKDTEMP_ASYNC_0200 + * @tc.name fileIO_test_mkdtemp_async_002 + * @tc.desc Test mkdtemp() interface. Promise. + * The directory should end in XXXXXX. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_test_mkdtemp_async_002', 0, async function (done) { + let dpath = await nextFileName('fileIO_test_mkdtemp_async_002'); + + try { + await fileIO.mkdtemp(dpath); + expect(false).assertTrue(); + } catch (e) { + console.log('fileIO_test_mkdtemp_async_002 has failed for ' + e.message + ', code: ' + e.code); + expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue(); + done(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_MKDTEMP_ASYNC_0300 + * @tc.name fileIO_test_mkdtemp_async_003 + * @tc.desc Test mkdtemp() interface. Callback. + * The directory should end in XXXXXX. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_test_mkdtemp_async_003', 0, async function (done) { + let dpath = await nextFileName('fileIO_test_mkdtemp_async_003'); + + try { + fileIO.mkdtemp(dpath, (err) => { + if (err) { + console.log('fileIO_test_mkdtemp_async_003 error package: ' + JSON.stringify(err)); + expect(err.code == 13900020 && err.message == 'Invalid argument').assertTrue(); + done(); + } + }); + } catch (e) { + console.log('fileIO_test_mkdtemp_async_003 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_MKDTEMP_ASYNC_0400 + * @tc.name fileIO_test_mkdtemp_async_004 + * @tc.desc Test mkdtemp() interface. Promise. + * Missing parameters. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_test_mkdtemp_async_004', 0, async function (done) { + + try { + await fileIO.mkdtemp(); + expect(false).assertTrue(); + } catch (e) { + console.log('fileIO_test_mkdtemp_async_004 has failed for ' + e.message + ', code: ' + e.code); + expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue(); + done(); + } + }); +}); +} diff --git a/storage/storagefileiov9jstest/src/main/js/test/members/open.test.js b/storage/storagefileiov9jstest/src/main/js/test/members/open.test.js index e6c3e59af..9f7d752e0 100644 --- a/storage/storagefileiov9jstest/src/main/js/test/members/open.test.js +++ b/storage/storagefileiov9jstest/src/main/js/test/members/open.test.js @@ -14,8 +14,7 @@ */ import { - fileio, fileIO, FILE_CONTENT, prepareFile, nextFileName, isIntNum, - describe, it, expect, + fileIO, FILE_CONTENT, prepareFile, nextFileName, isIntNum, describe, it, expect, } from '../Common'; export default function fileIOOpen() { @@ -40,8 +39,8 @@ export default function fileIOOpen() { expect(isIntNum(file.fd)).assertTrue(); let readlen = fileIO.readSync(file.fd, new ArrayBuffer(4096)); expect(readlen == FILE_CONTENT.length).assertTrue(); - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); } catch (e) { console.log('fileIO_test_open_sync_000 has failed for ' + e.message + ', code: ' + e.code); expect(false).assertTrue(); @@ -55,7 +54,7 @@ export default function fileIOOpen() { * Open the file in write-only mode, verifying the file is writable. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_test_open_sync_001', 0, async function () { @@ -65,10 +64,10 @@ export default function fileIOOpen() { try { let file = fileIO.openSync(fpath, fileIO.OpenMode.WRITE_ONLY); expect(isIntNum(file.fd)).assertTrue(); - let num = fileIO.writeSync(file.fd, FILE_CONTENT); - expect(num == FILE_CONTENT.length).assertTrue(); - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); + let bytesWritten = fileIO.writeSync(file.fd, FILE_CONTENT); + expect(bytesWritten == FILE_CONTENT.length).assertTrue(); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); } catch (e) { console.log('fileIO_test_open_sync_001 has failed for ' + e.message + ', code: ' + e.code); expect(false).assertTrue(); @@ -82,7 +81,7 @@ export default function fileIOOpen() { * Open the file in read-write mode, verifying the file is readable and writable. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_test_open_sync_002', 0, async function () { @@ -95,10 +94,10 @@ export default function fileIOOpen() { let readlen = fileIO.readSync(file.fd, new ArrayBuffer(4096)); expect(readlen == FILE_CONTENT.length).assertTrue(); let length = 20; - let num = fileIO.writeSync(file.fd, new ArrayBuffer(length)); - expect(num == length).assertTrue(); - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); + let bytesWritten = fileIO.writeSync(file.fd, new ArrayBuffer(length)); + expect(bytesWritten == length).assertTrue(); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); } catch (e) { console.log('fileIO_test_open_sync_002 has failed for ' + e.message + ', code: ' + e.code); expect(false).assertTrue(); @@ -111,7 +110,7 @@ export default function fileIOOpen() { * @tc.desc Test openSync() interfaces. Missing parameters. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_test_open_sync_003', 0, function () { @@ -131,7 +130,7 @@ export default function fileIOOpen() { * If the path point to the file which does not exist, the file can be created. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_test_open_sync_004', 0, async function () { @@ -140,8 +139,8 @@ export default function fileIOOpen() { try { let file = fileIO.openSync(fpath, fileIO.OpenMode.CREATE | fileIO.OpenMode.READ_WRITE); expect(isIntNum(file.fd)).assertTrue(); - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); } catch (e) { console.log('fileIO_test_open_sync_004 has failed for ' + e.message + ', code: ' + e.code); expect(false).assertTrue(); @@ -155,7 +154,7 @@ export default function fileIOOpen() { * If the file exists and the file is opened for read-write, trim its length to zero. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_test_open_sync_005', 0, async function () { @@ -165,10 +164,10 @@ export default function fileIOOpen() { try { let file = fileIO.openSync(fpath, fileIO.OpenMode.TRUNC | fileIO.OpenMode.READ_WRITE); expect(isIntNum(file.fd)).assertTrue(); - let number = fileIO.readSync(file.fd, new ArrayBuffer(4096)); - expect(number == 0).assertTrue(); - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); + let readLen = fileIO.readSync(file.fd, new ArrayBuffer(4096)); + expect(readLen == 0).assertTrue(); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); } catch (e) { console.log('fileIO_test_open_sync_005 has failed for ' + e.message + ', code: ' + e.code); expect(false).assertTrue(); @@ -182,7 +181,7 @@ export default function fileIOOpen() { * Open as append, subsequent writes will append to the end of the file. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_test_open_sync_006', 0, async function () { @@ -193,12 +192,12 @@ export default function fileIOOpen() { let file = fileIO.openSync(fpath, fileIO.OpenMode.APPEND | fileIO.OpenMode.READ_WRITE); expect(isIntNum(file.fd)).assertTrue(); let length = 100; - let num = fileIO.writeSync(file.fd, new ArrayBuffer(length)); - expect(num == length).assertTrue(); - let number = fileIO.readSync(file.fd, new ArrayBuffer(4096), { offset: 0 }); - expect(number == length + FILE_CONTENT.length).assertTrue(); - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); + let bytesWritten = fileIO.writeSync(file.fd, new ArrayBuffer(length)); + expect(bytesWritten == length).assertTrue(); + let readLen = fileIO.readSync(file.fd, new ArrayBuffer(4096), { offset: 0 }); + expect(readLen == length + FILE_CONTENT.length).assertTrue(); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); } catch (e) { console.log('fileIO_test_open_sync_006 has failed for ' + e.message + ', code: ' + e.code); expect(false).assertTrue(); @@ -212,7 +211,7 @@ export default function fileIOOpen() { * If the file is a special file, the opening and subsequent IOs perform non-blocking operations. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_test_open_sync_007', 0, async function () { @@ -222,8 +221,8 @@ export default function fileIOOpen() { try { let file = fileIO.openSync(fpath, fileIO.OpenMode.NONBLOCK | fileIO.OpenMode.READ_WRITE); expect(isIntNum(file.fd)).assertTrue(); - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); } catch (e) { console.log('fileIO_test_open_sync_007 has failed for ' + e.message + ', code: ' + e.code); expect(false).assertTrue(); @@ -237,17 +236,17 @@ export default function fileIOOpen() { * The path points to a directory. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_test_open_sync_008', 0, async function () { let dpath = await nextFileName('fileIO_test_open_sync_008'); - fileio.mkdirSync(dpath); + fileIO.mkdirSync(dpath); try { let file = fileIO.openSync(dpath, fileIO.OpenMode.DIR); expect(isIntNum(file.fd)).assertTrue(); - fileio.rmdirSync(dpath); + fileIO.rmdirSync(dpath); } catch (e) { console.log('fileIO_test_open_sync_008 has failed for ' + e.message + ', code: ' + e.code); expect(false).assertTrue(); @@ -261,7 +260,7 @@ export default function fileIOOpen() { * The path does not a directory, throw error. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_test_open_sync_009', 0, async function () { @@ -272,7 +271,7 @@ export default function fileIOOpen() { fileIO.openSync(fpath, fileIO.OpenMode.DIR); expect(false).assertTrue(); } catch (e) { - fileio.unlinkSync(fpath); + fileIO.unlinkSync(fpath); console.log('fileIO_test_open_sync_009 has failed for ' + e.message + ', code: ' + e.code); expect(e.code == 13900018 && e.message == 'Not a directory').assertTrue(); } @@ -285,7 +284,7 @@ export default function fileIOOpen() { * The path does not point to a symbolic link. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_test_open_sync_010', 0, async function () { @@ -295,8 +294,8 @@ export default function fileIOOpen() { try { let file = fileIO.openSync(fpath, fileIO.OpenMode.NOFOLLOW | fileIO.OpenMode.READ_WRITE); expect(isIntNum(file.fd)).assertTrue(); - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); } catch (e) { console.log('fileIO_test_open_sync_010 has failed for ' + e.message + ', code: ' + e.code); expect(false).assertTrue(); @@ -310,7 +309,7 @@ export default function fileIOOpen() { * The path points to a symbolic link, throw error. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_test_open_sync_011', 0, async function () { @@ -319,12 +318,12 @@ export default function fileIOOpen() { expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); try { - fileio.symlinkSync(fpath, ffpath); + fileIO.symlinkSync(fpath, ffpath); fileIO.openSync(ffpath, fileIO.OpenMode.NOFOLLOW | fileIO.OpenMode.READ_WRITE); expect(false).assertTrue(); } catch (e) { - fileio.unlinkSync(fpath); - fileio.unlinkSync(ffpath); + fileIO.unlinkSync(fpath); + fileIO.unlinkSync(ffpath); console.log('fileIO_test_open_sync_011 has failed for ' + e.message + ', code: ' + e.code); expect(e.code == 13900033 && e.message == 'Too many symbolic links encountered').assertTrue(); } @@ -337,7 +336,7 @@ export default function fileIOOpen() { * Open the file in the way of synchronous IO. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_test_open_sync_012', 0, async function () { @@ -347,8 +346,8 @@ export default function fileIOOpen() { try { let file = fileIO.openSync(fpath, fileIO.OpenMode.SYNC | fileIO.OpenMode.READ_WRITE); expect(isIntNum(file.fd)).assertTrue(); - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); } catch (e) { console.log('fileIO_test_open_sync_012 has failed for ' + e.message + ', code: ' + e.code); expect(false).assertTrue(); @@ -361,7 +360,7 @@ export default function fileIOOpen() { * @tc.desc Test openSync() interfaces. Invalid path. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_test_open_sync_013', 0, async function (done) { @@ -394,10 +393,10 @@ export default function fileIOOpen() { let file = await fileIO.open(fpath, fileIO.OpenMode.READ_ONLY); expect(isIntNum(file.fd)).assertTrue(); fileIO.read(file.fd, new ArrayBuffer(4096)) - .then((res) => { - expect(res == FILE_CONTENT.length).assertTrue(); - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); + .then((readLen) => { + expect(readLen == FILE_CONTENT.length).assertTrue(); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); done(); }); } catch (e) { @@ -413,7 +412,7 @@ export default function fileIOOpen() { * Open the file in read-only mode, verifying the file is readable. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_test_open_async_001', 0, async function (done) { @@ -428,10 +427,10 @@ export default function fileIOOpen() { } expect(isIntNum(file.fd)).assertTrue(); fileIO.read(file.fd, new ArrayBuffer(4096)) - .then((res) => { - expect(res == FILE_CONTENT.length).assertTrue(); - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); + .then((readLen) => { + expect(readLen == FILE_CONTENT.length).assertTrue(); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); done(); }); }); @@ -448,7 +447,7 @@ export default function fileIOOpen() { * Open the file in write-only mode, verifying the file is writable. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_test_open_async_002', 0, async function (done) { @@ -460,10 +459,10 @@ export default function fileIOOpen() { let file = await fileIO.open(fpath, fileIO.OpenMode.WRITE_ONLY); expect(isIntNum(file.fd)).assertTrue(); fileIO.write(file.fd, new ArrayBuffer(length)) - .then((num) => { - expect(num == length).assertTrue(); - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); + .then((bytesWritten) => { + expect(bytesWritten == length).assertTrue(); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); done(); }); } catch (e) { @@ -479,7 +478,7 @@ export default function fileIOOpen() { * Open the file in write-only mode, verifying the file is writable. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_test_open_async_003', 0, async function (done) { @@ -495,10 +494,10 @@ export default function fileIOOpen() { } expect(isIntNum(file.fd)).assertTrue(); fileIO.write(file.fd, new ArrayBuffer(length)) - .then((num) => { - expect(num == length).assertTrue(); - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); + .then((bytesWritten) => { + expect(bytesWritten == length).assertTrue(); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); }); }); done(); @@ -515,7 +514,7 @@ export default function fileIOOpen() { * The path point to nothing, no such file. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_test_open_async_004', 0, async function (done) { @@ -538,7 +537,7 @@ export default function fileIOOpen() { * The path point to nothing, no such file. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_test_open_async_005', 0, async function (done) { @@ -547,7 +546,7 @@ export default function fileIOOpen() { try { fileIO.open(fpath, fileIO.OpenMode.READ_WRITE, (err) => { if(err) { - console.log('fileIO_test_open_async_005 error package: {' + err.message + ', code: ' + err.code + '}'); + console.log('fileIO_test_open_async_005 error: {message: ' + err.message + ', code: ' + err.code + '}'); expect(err.code == 13900002 && err.message == 'No such file or directory').assertTrue(); done(); } @@ -565,7 +564,7 @@ export default function fileIOOpen() { * The path point to nothing, no such file. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_test_open_async_006', 0, async function () { @@ -575,8 +574,8 @@ export default function fileIOOpen() { fileIO.open(fpath, fileIO.OpenMode.READ_WRITE).then(() => { expect(false).assertTrue(); }).catch((err) => { - fileio.unlinkSync(fpath); - console.log('fileIO_test_open_async_006 error package: {' + err.message + ', code: ' + err.code + '}'); + fileIO.unlinkSync(fpath); + console.log('fileIO_test_open_async_006 error: {message: ' + err.message + ', code: ' + err.code + '}'); expect(err.code == 13900002 && err.message == 'No such file or directory').assertTrue(); }); } catch (e) { @@ -592,7 +591,7 @@ export default function fileIOOpen() { * Invalid path. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_test_open_async_007', 0, async function (done) { @@ -614,13 +613,13 @@ export default function fileIOOpen() { * Invalid path. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_test_open_async_008', 0, async function (done) { try { - fileIO.open(-1, fileIO.OpenMode.READ_WRITE, () => { + fileIO.open(-1, fileIO.OpenMode.READ_WRITE, (err) => { expect(false).assertTrue(); }); } catch (e) { @@ -637,7 +636,7 @@ export default function fileIOOpen() { * If the path point to the file which does not exist, the file can be created. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_test_open_async_009', 0, async function (done) { @@ -646,8 +645,8 @@ export default function fileIOOpen() { try { let file = await fileIO.open(fpath, fileIO.OpenMode.CREATE | fileIO.OpenMode.READ_WRITE); expect(isIntNum(file.fd)).assertTrue(); - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); done(); } catch (e) { console.log('fileIO_test_open_async_009 has failed for ' + e.message + ', code: ' + e.code); @@ -662,7 +661,7 @@ export default function fileIOOpen() { * If the path point to the file which does not exist, the file can be created. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_test_open_async_010', 0, async function (done) { @@ -675,8 +674,8 @@ export default function fileIOOpen() { expect(false).assertTrue(); } expect(isIntNum(file.fd)).assertTrue(); - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); done(); }); } catch (e) { @@ -692,7 +691,7 @@ export default function fileIOOpen() { * If the file exists and the file is opened for read-write, trim its length to zero. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_test_open_async_011', 0, async function (done) { @@ -703,10 +702,10 @@ export default function fileIOOpen() { let file = await fileIO.open(fpath, fileIO.OpenMode.TRUNC | fileIO.OpenMode.READ_WRITE); expect(isIntNum(file.fd)).assertTrue(); fileIO.read(file.fd, new ArrayBuffer(4096)) - .then((number) => { - expect(number == 0).assertTrue(); - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); + .then((readLen) => { + expect(readLen == 0).assertTrue(); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); }); done(); } catch (e) { @@ -722,7 +721,7 @@ export default function fileIOOpen() { * If the file exists and the file is opened for read-write, trim its length to zero. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_test_open_async_012', 0, async function (done) { @@ -737,10 +736,10 @@ export default function fileIOOpen() { } expect(isIntNum(file.fd)).assertTrue(); fileIO.read(file.fd, new ArrayBuffer(4096)) - .then((number) => { - expect(number == 0).assertTrue(); - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); + .then((readLen) => { + expect(readLen == 0).assertTrue(); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); }); done(); }); @@ -757,7 +756,7 @@ export default function fileIOOpen() { * Open as append, subsequent writes will append to the end of the file. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_test_open_async_013', 0, async function (done) { @@ -770,10 +769,10 @@ export default function fileIOOpen() { expect(isIntNum(file.fd)).assertTrue(); fileIO.writeSync(file.fd, new ArrayBuffer(length)); fileIO.read(file.fd, new ArrayBuffer(4096), { offset: 0 }) - .then((number) => { - expect(number == length + FILE_CONTENT.length).assertTrue(); - fileIO.closeSync(file.fd); - fileio.unlinkSync(fpath); + .then((readLen) => { + expect(readLen == length + FILE_CONTENT.length).assertTrue(); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); }); done(); } catch (e) { @@ -789,7 +788,7 @@ export default function fileIOOpen() { * Open as append, subsequent writes will append to the end of the file. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_test_open_async_014', 0, async function (done) { @@ -806,10 +805,10 @@ export default function fileIOOpen() { expect(isIntNum(file.fd)).assertTrue(); fileIO.writeSync(file.fd, new ArrayBuffer(length)); fileIO.read(file.fd, new ArrayBuffer(4096), { offset: 0 }) - .then((number) => { - expect(number == length + FILE_CONTENT.length).assertTrue(); - fileIO.closeSync(file.fd); - fileio.unlinkSync(fpath); + .then((readLen) => { + expect(readLen == length + FILE_CONTENT.length).assertTrue(); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); }); done(); }); @@ -826,7 +825,7 @@ export default function fileIOOpen() { * If the file is a special file, the opening and subsequent IOs perform non-blocking operations. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_test_open_async_015', 0, async function (done) { @@ -836,8 +835,8 @@ export default function fileIOOpen() { try { let file = await fileIO.open(fpath, fileIO.OpenMode.NONBLOCK | fileIO.OpenMode.READ_WRITE); expect(isIntNum(file.fd)).assertTrue(); - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); done(); } catch (e) { console.log('fileIO_test_open_async_015 has failed for ' + e.message + ', code: ' + e.code); @@ -852,7 +851,7 @@ export default function fileIOOpen() { * If the file is a special file, the opening and subsequent IOs perform non-blocking operations. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_test_open_async_016', 0, async function (done) { @@ -866,8 +865,8 @@ export default function fileIOOpen() { expect(false).assertTrue(); } expect(isIntNum(file.fd)).assertTrue(); - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); done(); }); } catch (e) { @@ -883,17 +882,17 @@ export default function fileIOOpen() { * The path points to a directory. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_test_open_async_017', 0, async function (done) { let dpath = await nextFileName('fileIO_test_open_async_017'); - fileio.mkdirSync(dpath); + fileIO.mkdirSync(dpath); try { let file = await fileIO.open(dpath, fileIO.OpenMode.DIR); expect(isIntNum(file.fd)).assertTrue(); - fileio.rmdirSync(dpath); + fileIO.rmdirSync(dpath); done(); } catch (e) { console.log('fileIO_test_open_async_017 has failed for ' + e.message + ', code: ' + e.code); @@ -908,12 +907,12 @@ export default function fileIOOpen() { * The path points to a directory. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_test_open_async_018', 0, async function (done) { let dpath = await nextFileName('fileIO_test_open_async_018'); - fileio.mkdirSync(dpath); + fileIO.mkdirSync(dpath); try { fileIO.open(dpath, fileIO.OpenMode.DIR, (err, file) => { @@ -922,7 +921,7 @@ export default function fileIOOpen() { expect(false).assertTrue(); } expect(isIntNum(file.fd)).assertTrue(); - fileio.rmdirSync(dpath); + fileIO.rmdirSync(dpath); done(); }); } catch (e) { @@ -938,7 +937,7 @@ export default function fileIOOpen() { * The path does not point to a directory, throw error. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_test_open_async_019', 0, async function (done) { @@ -949,7 +948,7 @@ export default function fileIOOpen() { await fileIO.open(fpath, fileIO.OpenMode.DIR); expect(false).assertTrue(); } catch (e) { - fileio.unlinkSync(fpath); + fileIO.unlinkSync(fpath); console.log('fileIO_test_open_async_019 has failed for ' + e.message + ', code: ' + e.code); expect(e.code == 13900018 && e.message == 'Not a directory').assertTrue(); done(); @@ -963,7 +962,7 @@ export default function fileIOOpen() { * The path does not point to a directory, throw error. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_test_open_async_020', 0, async function (done) { @@ -973,8 +972,8 @@ export default function fileIOOpen() { try { fileIO.open(fpath, fileIO.OpenMode.DIR, (err) => { if(err) { - fileio.unlinkSync(fpath); - console.log('fileIO_test_open_async_020 error package: {' + err.message + ', code: ' + err.code + '}'); + fileIO.unlinkSync(fpath); + console.log('fileIO_test_open_async_020 error: {message: ' + err.message + ', code: ' + err.code + '}'); expect(err.code == 13900018 && err.message == 'Not a directory').assertTrue(); done(); } @@ -992,7 +991,7 @@ export default function fileIOOpen() { * The path does not point to a directory, throw error. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_test_open_async_021', 0, async function (done) { @@ -1003,8 +1002,8 @@ export default function fileIOOpen() { fileIO.open(fpath, fileIO.OpenMode.DIR).then(() => { expect(false).assertTrue(); }).catch((err) => { - fileio.unlinkSync(fpath); - console.log('fileIO_test_open_async_021 error package: {' + err.message + ', code: ' + err.code + '}'); + fileIO.unlinkSync(fpath); + console.log('fileIO_test_open_async_021 error: {message: ' + err.message + ', code: ' + err.code + '}'); expect(err.code == 13900018 && err.message == 'Not a directory').assertTrue(); done(); }); @@ -1021,7 +1020,7 @@ export default function fileIOOpen() { * The path does not point to a symbolic link. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_test_open_async_022', 0, async function (done) { @@ -1031,8 +1030,8 @@ export default function fileIOOpen() { try { let file = await fileIO.open(fpath, fileIO.OpenMode.NOFOLLOW | fileIO.OpenMode.READ_WRITE); expect(isIntNum(file.fd)).assertTrue(); - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); done(); } catch (e) { console.log('fileIO_test_open_async_022 has failed for ' + e.message + ', code: ' + e.code); @@ -1047,7 +1046,7 @@ export default function fileIOOpen() { * The path does not point to a symbolic link. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_test_open_async_023', 0, async function (done) { @@ -1061,8 +1060,8 @@ export default function fileIOOpen() { expect(false).assertTrue(); } expect(isIntNum(file.fd)).assertTrue(); - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); done(); }); } catch (e) { @@ -1078,7 +1077,7 @@ export default function fileIOOpen() { * The path point to a symbolic link, throw error. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_test_open_async_024', 0, async function (done) { @@ -1087,12 +1086,12 @@ export default function fileIOOpen() { expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); try { - fileio.symlinkSync(fpath, ffpath); + fileIO.symlinkSync(fpath, ffpath); await fileIO.open(ffpath, fileIO.OpenMode.NOFOLLOW | fileIO.OpenMode.READ_WRITE); expect(false).assertTrue(); } catch (e) { - fileio.unlinkSync(fpath); - fileio.unlinkSync(ffpath); + fileIO.unlinkSync(fpath); + fileIO.unlinkSync(ffpath); console.log('fileIO_test_open_async_024 has failed for ' + e.message + ', code: ' + e.code); expect(e.code == 13900033 && e.message == 'Too many symbolic links encountered').assertTrue(); done(); @@ -1106,7 +1105,7 @@ export default function fileIOOpen() { * The path point to a symbolic link, throw error. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_test_open_async_025', 0, async function (done) { @@ -1115,14 +1114,14 @@ export default function fileIOOpen() { expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); try { - fileio.symlinkSync(fpath, ffpath); + fileIO.symlinkSync(fpath, ffpath); fileIO.open(ffpath, fileIO.OpenMode.NOFOLLOW | fileIO.OpenMode.READ_WRITE, (err) => { if(err) { - console.log('fileIO_test_open_async_025 error package: {' + err.message + ', code: ' + err.code + '}'); + console.log('fileIO_test_open_async_025 error: {message: ' + err.message + ', code: ' + err.code + '}'); expect(err.code == 13900033 && err.message == 'Too many symbolic links encountered').assertTrue(); } - fileio.unlinkSync(fpath); - fileio.unlinkSync(ffpath); + fileIO.unlinkSync(fpath); + fileIO.unlinkSync(ffpath); done(); }); } catch (e) { @@ -1138,7 +1137,7 @@ export default function fileIOOpen() { * The path point to a symbolic link, throw error. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_test_open_async_026', 0, async function (done) { @@ -1147,14 +1146,14 @@ export default function fileIOOpen() { expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); try { - fileio.symlinkSync(fpath, ffpath); + fileIO.symlinkSync(fpath, ffpath); fileIO.open(ffpath, fileIO.OpenMode.NOFOLLOW | fileIO.OpenMode.READ_WRITE).then(() => { expect(false).assertTrue(); }).catch((err) => { - console.log('fileIO_test_open_async_026 error package: {' + err.message + ', code: ' + err.code + '}'); + console.log('fileIO_test_open_async_026 error: {message: ' + err.message + ', code: ' + err.code + '}'); expect(err.code == 13900033 && err.message == 'Too many symbolic links encountered').assertTrue(); - fileio.unlinkSync(fpath); - fileio.unlinkSync(ffpath); + fileIO.unlinkSync(fpath); + fileIO.unlinkSync(ffpath); done(); }); } catch (e) { @@ -1170,7 +1169,7 @@ export default function fileIOOpen() { * Open the file in the way of synchronous IO. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_test_open_async_027', 0, async function (done) { @@ -1180,8 +1179,8 @@ export default function fileIOOpen() { try { let file = await fileIO.open(fpath, fileIO.OpenMode.SYNC | fileIO.OpenMode.READ_WRITE); expect(isIntNum(file.fd)).assertTrue(); - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); done(); } catch (e) { console.log('fileIO_test_open_async_027 has failed for ' + e.message + ', code: ' + e.code); @@ -1196,7 +1195,7 @@ export default function fileIOOpen() { * Open the file in the way of synchronous IO. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_test_open_async_028', 0, async function (done) { @@ -1210,8 +1209,8 @@ export default function fileIOOpen() { expect(false).assertTrue(); } expect(isIntNum(file.fd)).assertTrue(); - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); done(); }); } catch (e) { diff --git a/storage/storagefileiov9jstest/src/main/js/test/members/read.test.js b/storage/storagefileiov9jstest/src/main/js/test/members/read.test.js index 6bebb8573..378915fd4 100644 --- a/storage/storagefileiov9jstest/src/main/js/test/members/read.test.js +++ b/storage/storagefileiov9jstest/src/main/js/test/members/read.test.js @@ -14,8 +14,7 @@ */ import { - fileio, fileIO, FILE_CONTENT, prepareFile, nextFileName, isIntNum, - describe, it, expect, util + fileIO, FILE_CONTENT, prepareFile, nextFileName, isIntNum, describe, it, expect, util } from '../Common'; export default function fileIORead() { @@ -38,11 +37,10 @@ export default function fileIORead() { try { let file = fileIO.openSync(fpath, fileIO.OpenMode.READ_ONLY); expect(isIntNum(file.fd)).assertTrue(); - expect( - fileIO.readSync(file.fd, new ArrayBuffer(4096)) - == FILE_CONTENT.length).assertTrue(); - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); + let readLen = fileIO.readSync(file.fd, new ArrayBuffer(4096)); + expect(readLen == FILE_CONTENT.length).assertTrue(); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); } catch (e) { console.log('fileIO_test_read_sync_000 has failed for ' + e.message + ', code: ' + e.code); expect(false).assertTrue(); @@ -56,7 +54,7 @@ export default function fileIORead() { * Open the file in read-only mode, reading the file with length = 1. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_test_read_sync_001', 0, async function () { @@ -66,13 +64,12 @@ export default function fileIORead() { try { let file = fileIO.openSync(fpath, fileIO.OpenMode.READ_ONLY); expect(isIntNum(file.fd)).assertTrue(); - expect( - fileIO.readSync(file.fd, new ArrayBuffer(4096), { - length: 1, - }) - == 1).assertTrue(); - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); + let readLen = fileIO.readSync(file.fd, new ArrayBuffer(4096), { + length: 1, + }); + expect(readLen == 1).assertTrue(); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); } catch (e) { console.log('fileIO_test_read_sync_001 has failed for ' + e.message + ', code: ' + e.code); expect(false).assertTrue(); @@ -86,7 +83,7 @@ export default function fileIORead() { * Open the file in read-only mode, reading the file with length < 0(Read normal). * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_test_read_sync_002', 0, async function () { @@ -100,8 +97,8 @@ export default function fileIORead() { length: -1, }); expect(readLen == FILE_CONTENT.length).assertTrue(); - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); } catch (e) { console.log('fileIO_test_read_sync_002 has failed for ' + e.message + ', code: ' + e.code); expect(false).assertTrue(); @@ -115,7 +112,7 @@ export default function fileIORead() { * Open the file in read-only mode, reading the file with length > the content of file(Read normal). * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_test_read_sync_003', 0, async function () { @@ -125,12 +122,12 @@ export default function fileIORead() { try { let file = fileIO.openSync(fpath, fileIO.OpenMode.READ_ONLY); expect(isIntNum(file.fd)).assertTrue(); - expect(fileIO.readSync(file.fd, new ArrayBuffer(4096), { - length: FILE_CONTENT.length + 1, - }) - == FILE_CONTENT.length).assertTrue(); - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); + let readLen = fileIO.readSync(file.fd, new ArrayBuffer(4096), { + length: FILE_CONTENT.length + 1, + }); + expect(readLen == FILE_CONTENT.length).assertTrue(); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); } catch (e) { console.log('fileIO_test_read_sync_003 has failed for ' + e.message + ', code: ' + e.code); expect(false).assertTrue(); @@ -144,7 +141,7 @@ export default function fileIORead() { * Read the file with invalid length > size of ArrayBuffer. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_test_read_sync_004', 0, async function () { @@ -159,8 +156,8 @@ export default function fileIORead() { }); expect(false).assertTrue(); } catch (e) { - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); console.log('fileIO_test_read_sync_004 has failed for ' + e.message + ', code: ' + e.code); expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue(); } @@ -173,7 +170,7 @@ export default function fileIORead() { * Open the file in read-only mode, reading the file with offset(position) = 1. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_test_read_sync_005', 0, async function () { @@ -183,13 +180,12 @@ export default function fileIORead() { try { let file = fileIO.openSync(fpath, fileIO.OpenMode.READ_ONLY); expect(isIntNum(file.fd)).assertTrue(); - expect( - fileIO.readSync(file.fd, new ArrayBuffer(4096), { - offset: 1, - }) - == FILE_CONTENT.length - 1).assertTrue(); - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); + let readLen = fileIO.readSync(file.fd, new ArrayBuffer(4096), { + offset: 1, + }); + expect(readLen == FILE_CONTENT.length - 1).assertTrue(); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); } catch (e) { console.log('fileIO_test_read_sync_005 has failed for ' + e.message + ', code: ' + e.code); expect(false).assertTrue(); @@ -203,7 +199,7 @@ export default function fileIORead() { * Read the file with invalid offset = -1. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_test_read_sync_006', 0, async function () { @@ -218,8 +214,8 @@ export default function fileIORead() { }); expect(false).assertTrue(); } catch (e) { - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); console.log('fileIO_test_read_sync_006 has failed for ' + e.message + ', code: ' + e.code); expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue(); } @@ -232,7 +228,7 @@ export default function fileIORead() { * Open the file in read-only mode, reading the file with offset(position) > the content of file(Read normal). * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_test_read_sync_007', 0, async function () { @@ -242,13 +238,12 @@ export default function fileIORead() { try { let file = fileIO.openSync(fpath, fileIO.OpenMode.READ_ONLY); expect(isIntNum(file.fd)).assertTrue(); - expect( - fileIO.readSync(file.fd, new ArrayBuffer(4096), { - offset: FILE_CONTENT.length + 1, - }) - == 0).assertTrue(); - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); + let readLen = fileIO.readSync(file.fd, new ArrayBuffer(4096), { + offset: FILE_CONTENT.length + 1, + }); + expect(readLen == 0).assertTrue(); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); } catch (e) { console.log('fileIO_test_read_sync_007 has failed for ' + e.message + ', code: ' + e.code); expect(false).assertTrue(); @@ -262,7 +257,7 @@ export default function fileIORead() { * Open the file in read-only mode, reading the file with offset(position) = 1, length = 10. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_test_read_sync_008', 0, async function () { @@ -272,14 +267,13 @@ export default function fileIORead() { try { let file = fileIO.openSync(fpath, fileIO.OpenMode.READ_ONLY); expect(isIntNum(file.fd)).assertTrue(); - expect( - fileIO.readSync(file.fd, new ArrayBuffer(4096), { - offset: 1, - length: FILE_CONTENT.length - 1, - }) - == FILE_CONTENT.length - 1).assertTrue(); - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); + let readLen = fileIO.readSync(file.fd, new ArrayBuffer(4096), { + offset: 1, + length: FILE_CONTENT.length - 1, + }); + expect(readLen == FILE_CONTENT.length - 1).assertTrue(); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); } catch (e) { console.log('fileIO_test_read_sync_008 has failed for ' + e.message + ', code: ' + e.code); expect(false).assertTrue(); @@ -293,7 +287,7 @@ export default function fileIORead() { * Read the file with invalid fd. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_test_read_sync_009', 0, async function () { @@ -314,7 +308,7 @@ export default function fileIORead() { * Verify that the Chinese, English, and symbols can be read correctly. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_test_read_sync_010', 0, async function () { @@ -330,8 +324,8 @@ export default function fileIORead() { let textDecoder = new util.TextDecoder("utf-8", { ignoreBOM: true }); let resultPut = textDecoder.decode(new Uint8Array(buf), { stream: true }); expect(resultPut == CONTENT).assertTrue(); - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); } catch (e) { console.log('fileIO_test_read_sync_010 has failed for ' + e.message + ', code: ' + e.code); expect(false).assertTrue(); @@ -357,8 +351,8 @@ export default function fileIORead() { expect(isIntNum(file.fd)).assertTrue(); let readLen = await fileIO.read(file.fd, new ArrayBuffer(4096)); expect(readLen == FILE_CONTENT.length).assertTrue(); - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); done(); } catch (e) { console.log('fileIO_test_read_async_000 has failed for ' + e.message + ', code: ' + e.code); @@ -373,7 +367,7 @@ export default function fileIORead() { * Open the file in read-only mode, verifying the normal read function. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_test_read_async_001', 0, async function (done) { @@ -389,8 +383,8 @@ export default function fileIORead() { expect(false).assertTrue(); } expect(readlen == FILE_CONTENT.length).assertTrue(); - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); done(); }); } catch (e) { @@ -406,7 +400,7 @@ export default function fileIORead() { * Open the file in write-only mode, verifying it is not readable. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_test_read_async_002', 0, async function (done) { @@ -419,8 +413,8 @@ export default function fileIORead() { await fileIO.read(file.fd, new ArrayBuffer(4096)); expect(false).assertTrue(); } catch (e) { - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); console.log('fileIO_test_read_async_002 has failed for ' + e.message + ', code: ' + e.code); expect(e.code == 13900008 && e.message == 'Bad file descriptor').assertTrue(); done(); @@ -434,7 +428,7 @@ export default function fileIORead() { * Open the file in write-only mode, verifying it is not readable. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_test_read_async_003', 0, async function (done) { @@ -447,9 +441,9 @@ export default function fileIORead() { expect(isIntNum(file.fd)).assertTrue(); fileIO.read(file.fd, new ArrayBuffer(4096), (err) => { if(err) { - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); - console.log('fileIO_test_read_async_003 error package: {' + err.message + ', code: ' + err.code + '}'); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); + console.log('fileIO_test_read_async_003 error: {message: ' + err.message + ', code: ' + err.code + '}'); expect(err.code == 13900008 && err.message == 'Bad file descriptor').assertTrue(); done(); } @@ -467,7 +461,7 @@ export default function fileIORead() { * Open the file in read-only mode, reading the file with offset(position) = 1. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_test_read_async_004', 0, async function (done) { @@ -481,8 +475,8 @@ export default function fileIORead() { offset: 1, }); expect(readlen == FILE_CONTENT.length - 1).assertTrue(); - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); done(); } catch (e) { console.log('fileIO_test_read_async_004 has failed for ' + e.message + ', code: ' + e.code); @@ -497,7 +491,7 @@ export default function fileIORead() { * Open the file in read-only mode, reading the file with offset(position) = 1. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_test_read_async_005', 0, async function (done) { @@ -508,16 +502,16 @@ export default function fileIORead() { let file = fileIO.openSync(fpath, fileIO.OpenMode.READ_ONLY); expect(isIntNum(file.fd)).assertTrue(); fileIO.read(file.fd, new ArrayBuffer(4096), { - offset: 1, - }, (err, readLen) => { - if(err) { - console.log('fileIO_test_read_async_005 err package' + JSON.stringify(err)); - expect(false).assertTrue(); - } - expect(readLen == FILE_CONTENT.length - 1).assertTrue(); - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); - done(); + offset: 1, + }, (err, readLen) => { + if(err) { + console.log('fileIO_test_read_async_005 err package' + JSON.stringify(err)); + expect(false).assertTrue(); + } + expect(readLen == FILE_CONTENT.length - 1).assertTrue(); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); + done(); }); } catch (e) { console.log('fileIO_test_read_async_005 has failed for ' + e.message + ', code: ' + e.code); @@ -532,7 +526,7 @@ export default function fileIORead() { * Open the file in read-only mode, reading the file with length = 1. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_test_read_async_006', 0, async function (done) { @@ -546,8 +540,8 @@ export default function fileIORead() { length: 3, }); expect(readLen == 3).assertTrue(); - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); done(); } catch (e) { console.log('fileIO_test_read_async_006 has failed for ' + e.message + ', code: ' + e.code); @@ -562,7 +556,7 @@ export default function fileIORead() { * Open the file in read-only mode, reading the file with length = 1. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_test_read_async_007', 0, async function (done) { @@ -573,16 +567,16 @@ export default function fileIORead() { let file = fileIO.openSync(fpath, fileIO.OpenMode.READ_ONLY); expect(isIntNum(file.fd)).assertTrue(); fileIO.read(file.fd, new ArrayBuffer(4096), { - length: 3, - }, (err, readLen) => { - if(err) { - console.log('fileIO_test_read_async_007 err package' + JSON.stringify(err)); - expect(false).assertTrue(); - } - expect(readLen == 3).assertTrue(); - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); - done(); + length: 3, + }, (err, readLen) => { + if(err) { + console.log('fileIO_test_read_async_007 err package' + JSON.stringify(err)); + expect(false).assertTrue(); + } + expect(readLen == 3).assertTrue(); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); + done(); }); } catch (e) { console.log('fileIO_test_read_async_007 has failed for ' + e.message + ', code: ' + e.code); @@ -597,7 +591,7 @@ export default function fileIORead() { * Open the file in read-only mode, reading the file with offset > the content of file(Read normal). * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_test_read_async_008', 0, async function (done) { @@ -607,12 +601,12 @@ export default function fileIORead() { try { let file = fileIO.openSync(fpath, fileIO.OpenMode.READ_ONLY); expect(isIntNum(file.fd)).assertTrue(); - let len = await fileIO.read(file.fd, new ArrayBuffer(4096), { + let readLen = await fileIO.read(file.fd, new ArrayBuffer(4096), { offset: FILE_CONTENT.length + 1, }); - expect(len == 0).assertTrue(); - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); + expect(readLen == 0).assertTrue(); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); done(); } catch (e) { console.log('fileIO_test_read_async_008 has failed for ' + e.message + ', code: ' + e.code); @@ -627,7 +621,7 @@ export default function fileIORead() { * Open the file in read-only mode, reading the file with offset > the content of file(Read normal). * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_test_read_async_009', 0, async function (done) { @@ -638,16 +632,16 @@ export default function fileIORead() { let file = fileIO.openSync(fpath, fileIO.OpenMode.READ_ONLY); expect(isIntNum(file.fd)).assertTrue(); fileIO.read(file.fd, new ArrayBuffer(4096), { - offset: FILE_CONTENT.length + 1, - }, (err, len) => { - if(err) { - console.log('fileIO_test_read_async_009 err package' + JSON.stringify(err)); - expect(false).assertTrue(); - } - expect(len == 0).assertTrue(); - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); - done(); + offset: FILE_CONTENT.length + 1, + }, (err, readLen) => { + if(err) { + console.log('fileIO_test_read_async_009 err package' + JSON.stringify(err)); + expect(false).assertTrue(); + } + expect(readLen == 0).assertTrue(); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); + done(); }); } catch (e) { console.log('fileIO_test_read_async_009 has failed for ' + e.message + ', code: ' + e.code); @@ -656,13 +650,13 @@ export default function fileIORead() { }); /** - * @tc.number SUB_DF_FILEIO_READ_ASYNC_0100 + * @tc.number SUB_DF_FILEIO_READ_ASYNC_1000 * @tc.name fileIO_test_read_async_010 * @tc.desc Test read() interfaces. * Open the file in read-only mode, reading the file with offset(position) = 1, length = 11. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_test_read_async_010', 0, async function (done) { @@ -677,8 +671,8 @@ export default function fileIORead() { length: FILE_CONTENT.length, }); expect(readLen == FILE_CONTENT.length - 1).assertTrue(); - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); done(); } catch (e) { console.log('fileIO_test_read_async_010 has failed for ' + e.message + ', code: ' + e.code); @@ -693,7 +687,7 @@ export default function fileIORead() { * Open the file in read-only mode, reading the file with offset(position) = 1, length = 11. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_test_read_async_011', 0, async function (done) { @@ -712,8 +706,8 @@ export default function fileIORead() { expect(false).assertTrue(); } expect(readLen == FILE_CONTENT.length - 1).assertTrue(); - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); done(); }); } catch (e) { @@ -723,13 +717,13 @@ export default function fileIORead() { }); /** - * @tc.number SUB_DF_FILEIO_READ_ASYNC_0120 + * @tc.number SUB_DF_FILEIO_READ_ASYNC_1200 * @tc.name fileIO_test_read_async_012 * @tc.desc Test read() interfaces. Promise. * Read with invalid fd parameters. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_test_read_async_012', 0, async function (done) { @@ -750,14 +744,14 @@ export default function fileIORead() { * Read with invalid fd parameters. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_test_read_async_013', 0, async function (done) { try { fileIO.read(-1, new ArrayBuffer(4096), (err) => { if(err) { - console.log('fileIO_test_read_async_013 error package: {' + err.message + ', code: ' + err.code + '}'); + console.log('fileIO_test_read_async_013 error: {message: ' + err.message + ', code: ' + err.code + '}'); expect(err.code == 13900008 && err.message == 'Bad file descriptor').assertTrue(); done(); } @@ -775,7 +769,7 @@ export default function fileIORead() { * Read with invalid offset < 0. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_test_read_async_014', 0, async function (done) { @@ -787,13 +781,13 @@ export default function fileIORead() { try { expect(isIntNum(file.fd)).assertTrue(); fileIO.read(file.fd, new ArrayBuffer(4096), { - offset: invalidOffset - }, () => { - expect(false).assertTrue(); + offset: invalidOffset, + }, (err) => { + expect(false).assertTrue(); }); } catch (e) { - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); console.log('fileIO_test_read_async_014 has failed for ' + e.message + ', code: ' + e.code); expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue(); done(); @@ -807,7 +801,7 @@ export default function fileIORead() { * Read with invalid length > size of ArrayBuffer(4096). * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_test_read_async_015', 0, async function (done) { @@ -819,13 +813,13 @@ export default function fileIORead() { try { expect(isIntNum(file.fd)).assertTrue(); fileIO.read(file.fd, new ArrayBuffer(4096), { - length: invalidLength - }, () => { - expect(false).assertTrue(); + length: invalidLength, + }, (err) => { + expect(false).assertTrue(); }); } catch (e) { - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); console.log('fileIO_test_read_async_015 has failed for ' + e.message + ', code: ' + e.code); expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue(); done(); @@ -839,7 +833,7 @@ export default function fileIORead() { * Open the file in read-only mode, reading the file with empty option. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_test_read_async_016', 0, async function (done) { @@ -851,8 +845,8 @@ export default function fileIORead() { expect(isIntNum(file.fd)).assertTrue(); let readLen = await fileIO.read(file.fd, new ArrayBuffer(4096), {}); expect(readLen == FILE_CONTENT.length).assertTrue(); - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); done(); } catch (e) { console.log('fileIO_test_read_async_016 has failed for ' + e.message + ', code: ' + e.code); @@ -861,13 +855,13 @@ export default function fileIORead() { }); /** - * @tc.number SUB_DF_FILEIO_READ_ASYNC_0170 + * @tc.number SUB_DF_FILEIO_READ_ASYNC_1700 * @tc.name fileIO_test_read_async_017 * @tc.desc Test read() interfaces. Callback. * Open the file in read-only mode, reading the file with empty option. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_test_read_async_017', 0, async function (done) { @@ -878,16 +872,16 @@ export default function fileIORead() { let file = fileIO.openSync(fpath, fileIO.OpenMode.READ_ONLY); expect(isIntNum(file.fd)).assertTrue(); fileIO.read(file.fd, new ArrayBuffer(4096), { - }, (err, readLen) => { - if(err) { - console.log('fileIO_test_read_async_017 err package ' + JSON.stringify(err)); - expect(false).assertTrue(); - } - expect(readLen == FILE_CONTENT.length).assertTrue(); - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); - done(); - }); + }, (err, readLen) => { + if(err) { + console.log('fileIO_test_read_async_017 err package ' + JSON.stringify(err)); + expect(false).assertTrue(); + } + expect(readLen == FILE_CONTENT.length).assertTrue(); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); + done(); + }); } catch (e) { console.log('fileIO_test_read_async_017 has failed for ' + e.message + ', code: ' + e.code); expect(false).assertTrue(); @@ -895,13 +889,13 @@ export default function fileIORead() { }); /** - * @tc.number SUB_DF_FILEIO_READ_ASYNC_0180 + * @tc.number SUB_DF_FILEIO_READ_ASYNC_1800 * @tc.name fileIO_test_read_async_018 * @tc.desc Test read() interfaces. * Open the file in read-only mode, reading the file with length = -1(Read normal). * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_test_read_async_018', 0, async function () { @@ -913,10 +907,10 @@ export default function fileIORead() { expect(isIntNum(file.fd)).assertTrue(); let readLen = await fileIO.read(file.fd, new ArrayBuffer(4096), { length: -1, - }) + }); expect(readLen == FILE_CONTENT.length).assertTrue(); - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); } catch (e) { console.log('fileIO_test_read_async_018 has failed for ' + e.message + ', code: ' + e.code); expect(false).assertTrue(); @@ -924,13 +918,13 @@ export default function fileIORead() { }); /** - * @tc.number SUB_DF_FILEIO_READ_ASYNC_0190 + * @tc.number SUB_DF_FILEIO_READ_ASYNC_1900 * @tc.name fileIO_test_read_async_019 * @tc.desc Test read() interfaces. * Verify that the Chinese, English, and symbols can be read correctly. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_test_read_async_019', 0, async function (done) { @@ -946,8 +940,8 @@ export default function fileIORead() { let textDecoder = new util.TextDecoder("utf-8", { ignoreBOM: true }); let resultPut = textDecoder.decodeWithStream(new Uint8Array(buf), { stream: true }); expect(resultPut == CONTENT).assertTrue(); - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); done(); } catch (e) { console.log('fileIO_test_read_async_019 has failed for ' + e.message + ', code: ' + e.code); diff --git a/storage/storagefileiov9jstest/src/main/js/test/members/readtext.test.js b/storage/storagefileiov9jstest/src/main/js/test/members/readtext.test.js new file mode 100644 index 000000000..5f473fd21 --- /dev/null +++ b/storage/storagefileiov9jstest/src/main/js/test/members/readtext.test.js @@ -0,0 +1,698 @@ +/* + * Copyright (C) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the 'License'); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an 'AS IS' BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { + fileIO, FILE_CONTENT, prepareFile, nextFileName, describe, it, expect, +} from '../Common'; + +export default function fileIOReadtext() { +describe('fileIO_fs_readtext', function () { + + /** + * @tc.number SUB_DF_FILEIO_READ_TEXT_SYNC_0000 + * @tc.name fileIO_test_readtext_sync_000 + * @tc.desc Test readtextSync() interfaces. + * Read file content by path, verify normal function. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_test_readtext_sync_000', 0, async function () { + let fpath = await nextFileName('fileIO_test_readtext_sync_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let str = fileIO.readTextSync(fpath); + expect(str == FILE_CONTENT).assertTrue(); + fileIO.unlinkSync(fpath); + } catch (e) { + console.log('fileIO_test_readtext_sync_000 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_READ_TEXT_SYNC_0100 + * @tc.name fileIO_test_readtext_sync_001 + * @tc.desc Test readtextSync() interfaces. + * str.substring(startIndex, [endIndex - 1]): Extracts and returns a string by index. + * Read file content by path when offset = 1. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_test_readtext_sync_001', 0, async function () { + let fpath = await nextFileName('fileIO_test_readtext_sync_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let str = fileIO.readTextSync(fpath, { offset: 1 }); + expect(str == FILE_CONTENT.substring(1, FILE_CONTENT.length + 1)).assertTrue(); + fileIO.unlinkSync(fpath); + } catch (e) { + console.log('fileIO_test_readtext_sync_001 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_READ_TEXT_SYNC_0200 + * @tc.name fileIO_test_readtext_sync_002 + * @tc.desc Test readtextSync() interfaces. + * Read file content by path when offset = 2, length = 4. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_test_readtext_sync_002', 0, async function () { + let fpath = await nextFileName('fileIO_test_readtext_sync_002'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let str = fileIO.readTextSync(fpath, { + offset: 2, + length: 4 + }); + expect(str == FILE_CONTENT.substring(2, 6)).assertTrue(); + fileIO.unlinkSync(fpath); + } catch (e) { + console.log('fileIO_test_readtext_sync_002 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_READ_TEXT_SYNC_0300 + * @tc.name fileIO_test_readtext_sync_003 + * @tc.desc Test readtextSync() interfaces. + * Read file content by path when offset = 1, length = 11, encoding = 'utf-8'. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_test_readtext_sync_003', 0, async function () { + let fpath = await nextFileName('fileIO_test_readtext_sync_003'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let str = fileIO.readTextSync(fpath, { + offset: 1, + length: FILE_CONTENT.length, + encoding: 'utf-8' + }); + expect(str == FILE_CONTENT.substring(1, FILE_CONTENT.length + 1)).assertTrue(); + fileIO.unlinkSync(fpath); + } catch (e) { + console.log('fileIO_test_readtext_sync_002 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_READ_TEXT_SYNC_0400 + * @tc.name fileIO_test_readtext_sync_004 + * @tc.desc Test readtextSync() interfaces. + * Missing parameter. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_test_readtext_sync_004', 0, async function () { + + try { + fileIO.readTextSync(); + expect(false).assertTrue(); + } catch (e) { + console.log('fileIO_test_readtext_sync_003 has failed for ' + e.message + ', code: ' + e.code); + expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_READ_TEXT_SYNC_0500 + * @tc.name fileIO_test_readtext_sync_005 + * @tc.desc Test readtextSync() interfaces. + * The path point to nothing, no such file. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_test_readtext_sync_005', 0, async function () { + let fpath = await nextFileName('fileIO_test_readtext_sync_005'); + + try { + fileIO.readTextSync(fpath); + expect(false).assertTrue(); + } catch (e) { + console.log('fileIO_test_readtext_sync_005 has failed for ' + e.message + ', code: ' + e.code); + expect(e.code == 13900002 && e.message == 'No such file or directory').assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_READ_TEXT_SYNC_0600 + * @tc.name fileIO_test_readtext_sync_006 + * @tc.desc Test readtextSync() interfaces. + * Read file content with invalid offset < 0. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_test_readtext_sync_006', 0, async function () { + let fpath = await nextFileName('fileIO_test_readtext_sync_006'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + const invalidOffset = -1; + fileIO.readTextSync(fpath, { offset: invalidOffset }); + expect(false).assertTrue(); + } catch (e) { + fileIO.unlinkSync(fpath); + console.log('fileIO_test_readtext_sync_006 has failed for ' + e.message + ', code: ' + e.code); + expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_READ_TEXT_SYNC_0700 + * @tc.name fileIO_test_readtext_sync_007 + * @tc.desc Test readtextSync() interfaces. + * Read file content with invalid offset = 9999. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_test_readtext_sync_007', 0, async function () { + let fpath = await nextFileName('fileIO_test_readtext_sync_007'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + const invalidOffset = 9999; + fileIO.readTextSync(fpath, { offset: invalidOffset }); + expect(false).assertTrue(); + } catch (e) { + fileIO.unlinkSync(fpath); + console.log('fileIO_test_readtext_sync_007 has failed for ' + e.message + ', code: ' + e.code); + expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_READ_TEXT_SYNC_0800 + * @tc.name fileIO_test_readtext_sync_008 + * @tc.desc Test readtextSync() interfaces. + * Read file content with invalid length < 0. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_test_readtext_sync_008', 0, async function () { + let fpath = await nextFileName('fileIO_test_readtext_sync_008'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + const invalidLength = -1; + fileIO.readTextSync(fpath, { length: invalidLength }); + expect(false).assertTrue(); + } catch (e) { + fileIO.unlinkSync(fpath); + console.log('fileIO_test_readtext_sync_008 has failed for ' + e.message + ', code: ' + e.code); + expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_READ_TEXT_ASYNC_0000 + * @tc.name fileIO_test_readtext_async_000 + * @tc.desc Test readtext() interfaces. Promise. + * Read file content by path, verify normal function. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_test_readtext_async_000', 0, async function (done) { + let fpath = await nextFileName('fileIO_test_readtext_async_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let str = await fileIO.readText(fpath); + expect(str == FILE_CONTENT).assertTrue(); + fileIO.unlinkSync(fpath); + done(); + } catch (e) { + console.log('fileIO_test_readtext_async_000 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_READ_TEXT_ASYNC_0100 + * @tc.name fileIO_test_readtext_async_001 + * @tc.desc Test readtext() interfaces. Callback. + * Read file content by path, verify normal function. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_test_readtext_async_001', 0, async function (done) { + let fpath = await nextFileName('fileIO_test_readtext_async_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + fileIO.readText(fpath, (err, str) => { + if (err) { + console.log('fileIO_test_readtext_async_001 error package: ' + JSON.stringify(err)); + expect(false).assertTrue(); + } + expect(str == FILE_CONTENT).assertTrue(); + fileIO.unlinkSync(fpath); + done(); + }); + } catch (e) { + console.log('fileIO_test_readtext_async_001 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_READ_TEXT_ASYNC_0200 + * @tc.name fileIO_test_readtext_async_002 + * @tc.desc Test readtext() interfaces. Promise. + * Read file content by path when offset = 1. + * str.substr(startIndex, [length]): Extracts and returns a string by index and length of str. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_test_readtext_async_002', 0, async function (done) { + let fpath = await nextFileName('fileIO_test_readtext_async_002'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let str = await fileIO.readText(fpath, { offset: 1 }); + expect(str == FILE_CONTENT.substr(1, FILE_CONTENT.length - 1)).assertTrue(); + fileIO.unlinkSync(fpath); + done(); + } catch (e) { + console.log('fileIO_test_readtext_async_002 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_READ_TEXT_ASYNC_0300 + * @tc.name fileIO_test_readtext_async_003 + * @tc.desc Test readtext() interfaces. Callback. + * Read file content by path when offset = 1. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_test_readtext_async_003', 0, async function (done) { + let fpath = await nextFileName('fileIO_test_readtext_async_003'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + fileIO.readText(fpath, { offset: 1 }, (err, str) => { + if (err) { + console.log('fileIO_test_readtext_async_003 error package: ' + JSON.stringify(err)); + expect(false).assertTrue(); + } + expect(str == FILE_CONTENT.substr(1, FILE_CONTENT.length - 1)).assertTrue(); + fileIO.unlinkSync(fpath); + done(); + }); + } catch (e) { + console.log('fileIO_test_readtext_async_003 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_READ_TEXT_ASYNC_0400 + * @tc.name fileIO_test_readtext_async_004 + * @tc.desc Test readtext() interfaces. Promise. + * Read file content by path when offset = 1, length = 2. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_test_readtext_async_004', 0, async function (done) { + let fpath = await nextFileName('fileIO_test_readtext_async_004'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let str = await fileIO.readText(fpath, { + offset: 1, + length: 2 + }); + expect(str == FILE_CONTENT.substr(1, 2)).assertTrue(); + fileIO.unlinkSync(fpath); + done(); + } catch (e) { + console.log('fileIO_test_readtext_async_004 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_READ_TEXT_ASYNC_0500 + * @tc.name fileIO_test_readtext_async_005 + * @tc.desc Test readtext() interfaces. Callback. + * Read file content by path when offset = 1, length = 2. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_test_readtext_async_005', 0, async function (done) { + let fpath = await nextFileName('fileIO_test_readtext_async_005'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + fileIO.readText(fpath, { + offset: 1, + length: 2 + }, (err, str) => { + if (err) { + console.log('fileIO_test_readtext_async_005 error package: ' + JSON.stringify(err)); + expect(false).assertTrue(); + } + expect(str == FILE_CONTENT.substr(1, 2)).assertTrue(); + fileIO.unlinkSync(fpath); + done(); + }); + } catch (e) { + console.log('fileIO_test_readtext_async_005 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_READ_TEXT_ASYNC_0600 + * @tc.name fileIO_test_readtext_async_006 + * @tc.desc Test readtext() interfaces. Promise. + * Read file content by path when offset = 1, length = 11, encoding = 'utf-8'. + * str.slice(startIndex, [endIndex - 1]): Extracts and returns a string by index. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_test_readtext_async_006', 0, async function (done) { + let fpath = await nextFileName('fileIO_test_readtext_async_006'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let str = await fileIO.readText(fpath, { + offset: 1, + length: FILE_CONTENT.length, + encoding: 'utf-8' + }); + expect(str == FILE_CONTENT.slice(1, FILE_CONTENT.length + 1)).assertTrue(); + fileIO.unlinkSync(fpath); + done(); + } catch (e) { + console.log('fileIO_test_readtext_async_006 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_READ_TEXT_ASYNC_0700 + * @tc.name fileIO_test_readtext_async_007 + * @tc.desc Test readtext() interfaces. Promise.then().catch() + * Read file content by path when offset = 1, length = 11, encoding = 'utf-8'. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_test_readtext_async_007', 0, async function (done) { + let fpath = await nextFileName('fileIO_test_readtext_async_007'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + fileIO.readText(fpath, { + offset: 1, + length: FILE_CONTENT.length, + encoding: 'utf-8' + }).then((str) => { + expect(str == FILE_CONTENT.slice(1, FILE_CONTENT.length + 1)).assertTrue(); + fileIO.unlinkSync(fpath); + done(); + }).catch((err) => { + console.log('fileIO_test_readtext_async_007 error package: ' + JSON.stringify(err)); + expect(false).assertTrue(); + }); + } catch (e) { + console.log('fileIO_test_readtext_async_007 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_READ_TEXT_ASYNC_0800 + * @tc.name fileIO_test_readtext_async_008 + * @tc.desc Test readtext() interfaces. Callback. + * Read file content by path when offset = 1, length = 11, encoding = 'utf-8'. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_test_readtext_async_008', 0, async function (done) { + let fpath = await nextFileName('fileIO_test_readtext_async_008'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + fileIO.readText(fpath, { + offset: 1, + length: FILE_CONTENT.length, + encoding: 'utf-8' + }, (err, str) => { + if (err) { + console.log('fileIO_test_readtext_async_008 error package: ' + JSON.stringify(err)); + expect(false).assertTrue(); + } + expect(str == FILE_CONTENT.slice(1, FILE_CONTENT.length + 1)).assertTrue(); + fileIO.unlinkSync(fpath); + done(); + }); + } catch (e) { + console.log('fileIO_test_readtext_async_008 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_READ_TEXT_ASYNC_0900 + * @tc.name fileIO_test_readtext_async_009 + * @tc.desc Test readtext() interfaces. Promise. + * Read file content by path when option parameter is empty. + * str.slice(startIndex, [endIndex - 1]): Extracts and returns a string by index. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_test_readtext_async_009', 0, async function (done) { + let fpath = await nextFileName('fileIO_test_readtext_async_009'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let str = await fileIO.readText(fpath, {}); + expect(str == FILE_CONTENT).assertTrue(); + fileIO.unlinkSync(fpath); + done(); + } catch (e) { + console.log('fileIO_test_readtext_async_009 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_READ_TEXT_ASYNC_1000 + * @tc.name fileIO_test_readtext_async_010 + * @tc.desc Test readtext() interfaces. Callback. + * Read file content by path when option parameter is empty. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_test_readtext_async_010', 0, async function (done) { + let fpath = await nextFileName('fileIO_test_readtext_async_010'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + fileIO.readText(fpath, {}, (err, str) => { + if (err) { + console.log('fileIO_test_readtext_async_010 error package: ' + JSON.stringify(err)); + expect(false).assertTrue(); + } + expect(str == FILE_CONTENT).assertTrue(); + fileIO.unlinkSync(fpath); + done(); + }); + } catch (e) { + console.log('fileIO_test_readtext_async_010 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_READ_TEXT_ASYNC_1100 + * @tc.name fileIO_test_readtext_async_011 + * @tc.desc Test readtext() interfaces. Promise. + * The path point to nothing, no such file. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_test_readtext_async_011', 0, async function (done) { + let fpath = await nextFileName('fileIO_test_readtext_async_011'); + + try { + await fileIO.readText(fpath); + expect(false).assertTrue(); + } catch (e) { + console.log('fileIO_test_readtext_async_011 has failed for ' + e.message + ', code: ' + e.code); + expect(e.code == 13900002 && e.message == 'No such file or directory').assertTrue(); + done(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_READ_TEXT_ASYNC_1200 + * @tc.name fileIO_test_readtext_async_012 + * @tc.desc Test readtext() interfaces. Callback. + * The path point to nothing, no such file. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_test_readtext_async_012', 0, async function (done) { + let fpath = await nextFileName('fileIO_test_readtext_async_012'); + + try { + fileIO.readText(fpath, (err) => { + if (err) { + console.log('fileIO_test_readtext_async_012 error: {message:' + err.message + ', code: ' + err.code + '}'); + expect(err.code == 13900002 && err.message == 'No such file or directory').assertTrue(); + done(); + } + }); + } catch (e) { + console.log('fileIO_test_readtext_async_012 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_READ_TEXT_ASYNC_1300 + * @tc.name fileIO_test_readtext_async_013 + * @tc.desc Test readtext() interfaces. + * Read file content with invalid offset < 0. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_test_readtext_async_013', 0, async function (done) { + let fpath = await nextFileName('fileIO_test_readtext_async_013'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + const invalidOffset = -1; + await fileIO.readText(fpath, { offset: invalidOffset }); + expect(false).assertTrue(); + } catch (e) { + fileIO.unlinkSync(fpath); + console.log('fileIO_test_readtext_async_013 has failed for ' + e.message + ', code: ' + e.code); + expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue(); + done(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_READ_TEXT_ASYNC_1400 + * @tc.name fileIO_test_readtext_async_014 + * @tc.desc Test readtext() interfaces. + * Read file content with invalid offset = 9999. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_test_readtext_async_014', 0, async function (done) { + let fpath = await nextFileName('fileIO_test_readtext_async_014'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + const invalidOffset = 9999; + await fileIO.readText(fpath, { offset: invalidOffset }); + expect(false).assertTrue(); + } catch (e) { + fileIO.unlinkSync(fpath); + console.log('fileIO_test_readtext_async_014 has failed for ' + e.message + ', code: ' + e.code); + expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue(); + done(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_READ_TEXT_ASYNC_1500 + * @tc.name fileIO_test_readtext_async_015 + * @tc.desc Test readtext() interfaces. + * Read file content with invalid length < 0. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_test_readtext_async_015', 0, async function (done) { + let fpath = await nextFileName('fileIO_test_readtext_async_015'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + const invalidLength = -1; + await fileIO.readText(fpath, { length: invalidLength }); + expect(false).assertTrue(); + } catch (e) { + fileIO.unlinkSync(fpath); + console.log('fileIO_test_readtext_async_015 has failed for ' + e.message + ', code: ' + e.code); + expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue(); + done(); + } + }); +}); +} diff --git a/storage/storagefileiov9jstest/src/main/js/test/members/rename.test.js b/storage/storagefileiov9jstest/src/main/js/test/members/rename.test.js new file mode 100644 index 000000000..5e600bcb9 --- /dev/null +++ b/storage/storagefileiov9jstest/src/main/js/test/members/rename.test.js @@ -0,0 +1,492 @@ +/* + * Copyright (C) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the 'License'); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an 'AS IS' BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { + fileIO, FILE_CONTENT, prepareFile, nextFileName, describe, it, expect, randomString +} from '../Common'; + +export default function fileIORename() { +describe('fileIO_fs_rename', function () { + + /** + * @tc.number SUB_DF_FILEIO_RENAME_SYNC_0000 + * @tc.name fileIO_test_rename_sync_000 + * @tc.desc Test renameSync() interfaces. + * Rename the file by path, verify the normal function. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_test_rename_sync_000', 0, async function () { + let fpath = await nextFileName('fileIO_test_rename_sync_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let newf = fpath + 'test'; + fileIO.renameSync(fpath, newf); + expect(fileIO.accessSync(newf)).assertTrue(); + fileIO.unlinkSync(newf); + } catch (e) { + console.log('fileIO_test_rename_sync_000 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_RENAME_SYNC_0100 + * @tc.name fileIO_test_rename_sync_001 + * @tc.desc Test renameSync() interfaces. + * The path point to nothing, no such file. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_test_rename_sync_001', 0, async function () { + let fpath = await nextFileName('fileIO_test_rename_sync_001'); + + try { + fileIO.renameSync(fpath, fpath + 'test'); + expect(false).assertTrue(); + } catch (e) { + console.log('fileIO_test_rename_sync_001 has failed for ' + e.message + ', code: ' + e.code); + expect(e.code == 13900002 && e.message == 'No such file or directory').assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_RENAME_SYNC_0200 + * @tc.name fileIO_test_rename_sync_002 + * @tc.desc Test renameSync() interfaces. + * Missing parameter. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_test_rename_sync_002', 0, async function () { + let fpath = await nextFileName('fileIO_test_rename_sync_002'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + fileIO.renameSync(fpath); + expect(false).assertTrue(); + } catch (e) { + fileIO.unlinkSync(fpath); + console.log('fileIO_test_rename_sync_002 has failed for ' + e.message + ', code: ' + e.code); + expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_RENAME_SYNC_0300 + * @tc.name fileIO_test_rename_sync_003 + * @tc.desc Test renameSync() interfaces. + * Illegal second parameter. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_test_rename_sync_003', 0, async function () { + let fpath = await nextFileName('fileIO_test_rename_sync_003'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + fileIO.renameSync(fpath, null); + expect(false).assertTrue(); + } catch (e) { + fileIO.unlinkSync(fpath); + console.log('fileIO_test_rename_sync_003 has failed for ' + e.message + ', code: ' + e.code); + expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_RENAME_SYNC_0400 + * @tc.name fileIO_test_rename_sync_004 + * @tc.desc Test renameSync() interfaces. + * Illegal second parameter. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_test_rename_sync_004', 0, async function () { + let fpath = await nextFileName('fileIO_test_rename_sync_004'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + fileIO.renameSync(fpath, undefined); + expect(false).assertTrue(); + } catch (e) { + fileIO.unlinkSync(fpath); + console.log('fileIO_test_rename_sync_004 has failed for ' + e.message + ', code: ' + e.code); + expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_RENAME_SYNC_0500 + * @tc.name fileIO_test_rename_sync_005 + * @tc.desc Test renameSync() interfaces. + * Modify file names across directory. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_test_rename_sync_005', 0, async function () { + let dpath = await nextFileName('fileIO_test_rename_sync_005'); + let fpath = dpath + '/file_000'; + fileIO.mkdirSync(dpath); + fileIO.mkdirSync(dpath + '/dir_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let newf = dpath + '/dir_000/newFileName'; + fileIO.renameSync(fpath, newf); + fileIO.rmdirSync(dpath); + } catch (e) { + console.log('fileIO_test_rename_sync_005 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_RENAME_SYNC_0600 + * @tc.name fileIO_test_rename_sync_006 + * @tc.desc Test renameSync() interfaces. + * The length of file name is too long. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_test_rename_sync_006', 0, async function (done) { + let fpath = await nextFileName('fileIO_test_rename_sync_006'); + let fpathTarget = fpath + randomString(250); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + await fileIO.rename(fpath, fpathTarget); + expect(false).assertTrue(); + } catch (e) { + console.log('fileIO_test_rename_sync_006 has failed for ' + e.message + ', code: ' + e.code); + expect(e.code == 13900030 && e.message == 'File name too long').assertTrue(); + done(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_RENAME_ASYNC_0000 + * @tc.name fileIO_test_rename_async_000 + * @tc.desc Test rename() interfaces. Promise. + * Rename the file by path, verify the normal function. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_test_rename_async_000', 0, async function (done) { + let fpath = await nextFileName('fileIO_test_rename_async_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let newf = fpath + '123'; + + try { + await fileIO.rename(fpath, newf); + expect(fileIO.accessSync(newf)).assertTrue(); + fileIO.unlinkSync(newf); + done(); + } catch (e) { + console.log('fileIO_test_rename_async_000 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_RENAME_ASYNC_0100 + * @tc.name fileIO_test_rename_async_001 + * @tc.desc Test rename() interfaces. Callback. + * Rename the file by path, verify the normal function. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_test_rename_async_001', 0, async function (done) { + let fpath = await nextFileName('fileIO_test_rename_async_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let newf = fpath + 'aaa'; + + try { + fileIO.rename(fpath, newf, (err) => { + if (err) { + console.log('fileIO_test_rename_async_001 error package: ' + JSON.stringify(err)); + expect(false).assertTrue(); + } + expect(fileIO.accessSync(newf)).assertTrue(); + fileIO.unlinkSync(newf); + done(); + }) + } catch (e) { + console.log('fileIO_test_rename_async_001 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_RENAME_ASYNC_0200 + * @tc.name fileIO_test_rename_async_002 + * @tc.desc Test rename() interfaces. Promise. + * The path point to nothing, no such file. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_test_rename_async_002', 0, async function (done) { + let fpath = await nextFileName('fileIO_test_rename_async_002'); + + try { + await fileIO.rename(fpath, fpath + 'bbb'); + expect(false).assertTrue(); + } catch (e) { + console.log('fileIO_test_rename_async_002 has failed for ' + e.message + ', code: ' + e.code); + expect(e.code == 13900002 && e.message == 'No such file or directory').assertTrue(); + done(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_RENAME_ASYNC_0300 + * @tc.name fileIO_test_rename_async_003 + * @tc.desc Test rename() interfaces. Callback. + * The path point to nothing, no such file. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_test_rename_async_003', 0, async function (done) { + let fpath = await nextFileName('fileIO_test_rename_async_003'); + + try { + fileIO.rename(fpath, fpath + 'bbb', (err) => { + if (err) { + console.log('fileIO_test_rename_async_003 error: {message: ' + err.message + ', code: ' + err.code + '}'); + expect(err.code == 13900002 && err.message == 'No such file or directory').assertTrue(); + done(); + } + }); + } catch (e) { + console.log('fileIO_test_rename_async_003 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_RENAME_ASYNC_0400 + * @tc.name fileIO_test_rename_async_004 + * @tc.desc Test rename() interfaces. Promise. + * Missing parameter. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_test_rename_async_004', 0, async function (done) { + let fpath = await nextFileName('fileIO_test_rename_async_004'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + await fileIO.rename(fpath); + expect(false).assertTrue(); + } catch (e) { + fileIO.unlinkSync(fpath); + console.log('fileIO_test_rename_async_004 has failed for ' + e.message + ', code: ' + e.code); + expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue(); + done(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_RENAME_ASYNC_0500 + * @tc.name fileIO_test_rename_async_005 + * @tc.desc Test rename() interfaces. Promise. + * Illegal second parameter. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_test_rename_async_005', 0, async function (done) { + let fpath = await nextFileName('fileIO_test_rename_async_005'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + await fileIO.rename(fpath, null); + expect(false).assertTrue(); + } catch (e) { + fileIO.unlinkSync(fpath); + console.log('fileIO_test_rename_async_005 has failed for ' + e.message + ', code: ' + e.code); + expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue(); + done(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_RENAME_ASYNC_0600 + * @tc.name fileIO_test_rename_async_006 + * @tc.desc Test rename() interfaces. Promise. + * Illegal second parameter. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_test_rename_async_006', 0, async function (done) { + let fpath = await nextFileName('fileIO_test_rename_async_006'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + await fileIO.rename(fpath, undefined); + expect(false).assertTrue(); + } catch (e) { + fileIO.unlinkSync(fpath); + console.log('fileIO_test_rename_async_006 has failed for ' + e.message + ', code: ' + e.code); + expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue(); + done(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_RENAME_ASYNC_0700 + * @tc.name fileIO_test_rename_async_007 + * @tc.desc Test rename() interfaces. Promise. + * Modify file names across directory. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_test_rename_async_007', 0, async function (done) { + let dpath = await nextFileName('fileIO_test_rename_async_007'); + let fpath = dpath + '/file_001'; + fileIO.mkdirSync(dpath); + fileIO.mkdirSync(dpath + '/dir_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let newf = dpath + '/dir_001/newFileName'; + await fileIO.rename(fpath, newf); + fileIO.rmdirSync(dpath); + done(); + } catch (e) { + console.log('fileIO_test_rename_async_007 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_RENAME_ASYNC_0800 + * @tc.name fileIO_test_rename_async_008 + * @tc.desc Test rename() interfaces. Callback. + * Modify file names across directory. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_test_rename_async_008', 0, async function (done) { + let dpath = await nextFileName('fileIO_test_rename_async_008'); + let fpath = dpath + '/file_002'; + fileIO.mkdirSync(dpath); + fileIO.mkdirSync(dpath + '/dir_002'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let newf = dpath + '/dir_002/newFileName'; + fileIO.rename(fpath, newf, (err) => { + if (err) { + console.log('fileIO_test_rename_async_008 error package: ' + JSON.stringify(err)); + expect(false).assertTrue(); + } + fileIO.rmdirSync(dpath); + }); + done(); + } catch (e) { + console.log('fileIO_test_rename_async_008 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_RENAME_ASYNC_0900 + * @tc.name fileIO_test_rename_async_009 + * @tc.desc Test rename() interfaces. Promise + * The length of file name is too long. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_test_rename_async_009', 0, async function (done) { + let fpath = await nextFileName('fileIO_test_rename_async_009'); + let fpathTarget = fpath + randomString(250); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + await fileIO.rename(fpath, fpathTarget); + expect(false).assertTrue(); + } catch (e) { + console.log('fileIO_test_rename_async_009 has failed for ' + e.message + ', code: ' + e.code); + expect(e.code == 13900030 && e.message == 'File name too long').assertTrue(); + done(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_RENAME_ASYNC_1000 + * @tc.name fileIO_test_rename_async_010 + * @tc.desc Test rename() interfaces. Callback + * The length of file name is too long. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_test_rename_async_010', 0, async function (done) { + let fpath = await nextFileName('fileIO_test_rename_async_010'); + let fpathTarget = fpath + randomString(250); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + fileIO.rename(fpath, fpathTarget, (err) => { + if (err) { + fileIO.unlinkSync(fpath); + console.log('fileIO_test_rename_async_010 error: {message: ' + err.message + ', code: ' + err.code + '}'); + expect(err.code == 13900030 && err.message == 'File name too long').assertTrue(); + done(); + } + }); + } catch (e) { + console.log('fileIO_test_rename_async_010 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); +}); +} diff --git a/storage/storagefileiov9jstest/src/main/js/test/members/stat.test.js b/storage/storagefileiov9jstest/src/main/js/test/members/stat.test.js index c0291448c..d6f55460f 100644 --- a/storage/storagefileiov9jstest/src/main/js/test/members/stat.test.js +++ b/storage/storagefileiov9jstest/src/main/js/test/members/stat.test.js @@ -14,7 +14,7 @@ */ import { - fileio, fileIO, FILE_CONTENT, prepareFile, nextFileName, isIntNum, isBigInt, + fileIO, FILE_CONTENT, prepareFile, nextFileName, isIntNum, isBigInt, describe, it, expect, } from '../Common'; @@ -42,8 +42,8 @@ describe('fileIO_fs_stat', function () { let file = fileIO.openSync(fpath); let stat2 = fileIO.statSync(file.fd); expect(stat2 !== null).assertTrue(); - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); } catch (e) { console.log('fileIO_stat_sync_000 has failed for ' + e.message + ', code: ' + e.code); expect(false).assertTrue(); @@ -57,7 +57,7 @@ describe('fileIO_fs_stat', function () { * The path point to nothing, no such file. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_stat_sync_001', 0, async function () { @@ -78,7 +78,7 @@ describe('fileIO_fs_stat', function () { * @tc.desc Test statSync() interfaces. Missing parameters. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_stat_sync_002', 0, async function () { @@ -99,7 +99,7 @@ describe('fileIO_fs_stat', function () { * Enter the path or fd parameter to get stat.ino of the file. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_stat_sync_ino_000', 0, async function () { @@ -113,10 +113,10 @@ describe('fileIO_fs_stat', function () { let file = fileIO.openSync(fpath); let stat2 = fileIO.statSync(file.fd); expect(isBigInt(stat2.ino)).assertTrue(); - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); } catch (e) { - console.info('fileIO_stat_sync_ino_000 has failed for ' + e.message + ', code: ' + e.code); + console.log('fileIO_stat_sync_ino_000 has failed for ' + e.message + ', code: ' + e.code); expect(false).assertTrue(); } }); @@ -128,7 +128,7 @@ describe('fileIO_fs_stat', function () { * Enter the path or fd parameter to get stat.mode of the file. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_stat_sync_mode_000', 0, async function () { @@ -142,10 +142,10 @@ describe('fileIO_fs_stat', function () { let file = fileIO.openSync(fpath); let stat2 = fileIO.statSync(file.fd); expect(isIntNum(stat2.mode)).assertTrue(); - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); } catch (e) { - console.info('fileIO_stat_sync_mode_000 has failed for ' + e.message + ', code: ' + e.code); + console.log('fileIO_stat_sync_mode_000 has failed for ' + e.message + ', code: ' + e.code); expect(false).assertTrue(); } }); @@ -157,7 +157,7 @@ describe('fileIO_fs_stat', function () { * Enter the path or fd parameter to get stat.uid of the file. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_stat_sync_uid_000', 0, async function () { @@ -171,8 +171,8 @@ describe('fileIO_fs_stat', function () { let file = fileIO.openSync(fpath); let stat2 = fileIO.statSync(file.fd); expect(isIntNum(stat2.uid)).assertTrue(); - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); } catch (e) { console.log('fileIO_stat_sync_uid_000 has failed for ' + e.message + ', code: ' + e.code); expect(false).assertTrue(); @@ -186,7 +186,7 @@ describe('fileIO_fs_stat', function () { * Enter the path or fd parameter to get stat.gid of the file. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_stat_sync_gid_000', 0, async function () { @@ -200,8 +200,8 @@ describe('fileIO_fs_stat', function () { let file = fileIO.openSync(fpath); let stat2 = fileIO.statSync(file.fd); expect(isIntNum(stat2.gid)).assertTrue(); - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); } catch (e) { console.log('fileIO_stat_sync_gid_000 has failed for ' + e.message + ', code: ' + e.code); expect(false).assertTrue(); @@ -215,7 +215,7 @@ describe('fileIO_fs_stat', function () { * Enter the path or fd parameter to get stat.size of the file. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_stat_sync_size_000', 0, async function () { @@ -229,8 +229,8 @@ describe('fileIO_fs_stat', function () { let file = fileIO.openSync(fpath); let stat2 = fileIO.statSync(file.fd); expect(isIntNum(stat2.size)).assertTrue(); - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); } catch (e) { console.log('fileIO_stat_sync_size_000 has failed for ' + e.message + ', code: ' + e.code); expect(false).assertTrue(); @@ -244,7 +244,7 @@ describe('fileIO_fs_stat', function () { * Enter the path or fd parameter to get stat.atime of the file. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_stat_sync_atime_000', 0, async function () { @@ -258,8 +258,8 @@ describe('fileIO_fs_stat', function () { let file = fileIO.openSync(fpath); let stat2 = fileIO.statSync(file.fd); expect(isIntNum(stat2.atime)).assertTrue(); - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); } catch (e) { console.log('fileIO_stat_sync_atime_000 has failed for ' + e.message + ', code: ' + e.code); expect(false).assertTrue(); @@ -273,7 +273,7 @@ describe('fileIO_fs_stat', function () { * Enter the path or fd parameter to get stat.mtime of the file. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_stat_sync_mtime_000', 0, async function () { @@ -287,8 +287,8 @@ describe('fileIO_fs_stat', function () { let file = fileIO.openSync(fpath); let stat2 = fileIO.statSync(file.fd); expect(isIntNum(stat2.mtime)).assertTrue(); - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); } catch (e) { console.log('fileIO_stat_sync_mtime_000 has failed for ' + e.message + ', code: ' + e.code); expect(false).assertTrue(); @@ -302,7 +302,7 @@ describe('fileIO_fs_stat', function () { * Enter the path or fd parameter to get stat.ctime of the file. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_stat_sync_ctime_000', 0, async function () { @@ -316,8 +316,8 @@ describe('fileIO_fs_stat', function () { let file = fileIO.openSync(fpath); let stat2 = fileIO.statSync(file.fd); expect(isIntNum(stat2.ctime)).assertTrue(); - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); } catch (e) { console.log('fileIO_stat_sync_ctime_000 has failed for ' + e.message + ', code: ' + e.code); expect(false).assertTrue(); @@ -331,7 +331,7 @@ describe('fileIO_fs_stat', function () { * This interface shall not treat a normal file as a block special device. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_stat_sync_is_block_device_000', 0, async function () { @@ -345,8 +345,8 @@ describe('fileIO_fs_stat', function () { let file = fileIO.openSync(fpath); let stat2 = fileIO.statSync(file.fd); expect(stat2.isBlockDevice() === false).assertTrue(); - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); } catch (e) { console.log('fileIO_stat_sync_is_block_device_000 has failed for ' + e.message + ', code: ' + e.code); expect(false).assertTrue(); @@ -360,7 +360,7 @@ describe('fileIO_fs_stat', function () { * This interface does not require parameters. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_stat_sync_is_block_device_001', 0, async function () { @@ -371,8 +371,8 @@ describe('fileIO_fs_stat', function () { fileIO.statSync(fpath).isBlockDevice(-1); expect(false).assertTrue(); } catch (e) { - fileio.unlinkSync(fpath); - console.info('fileIO_stat_sync_is_block_device_001 has failed for ' + e.message + ', code: ' + e.code); + fileIO.unlinkSync(fpath); + console.log('fileIO_stat_sync_is_block_device_001 has failed for ' + e.message + ', code: ' + e.code); expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue(); } }); @@ -384,7 +384,7 @@ describe('fileIO_fs_stat', function () { * This interface does not require parameters. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_stat_sync_is_block_device_002', 0, async function () { @@ -396,9 +396,9 @@ describe('fileIO_fs_stat', function () { fileIO.statSync(file.fd).isBlockDevice(-1); expect(false).assertTrue(); } catch (e) { - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); - console.info('fileIO_stat_sync_is_block_device_002 has failed for ' + e.message + ', code: ' + e.code); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); + console.log('fileIO_stat_sync_is_block_device_002 has failed for ' + e.message + ', code: ' + e.code); expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue(); } @@ -411,7 +411,7 @@ describe('fileIO_fs_stat', function () { * This interface shall not treat a normal file as a character special device. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_stat_sync_is_character_device_000', 0, async function () { @@ -425,8 +425,8 @@ describe('fileIO_fs_stat', function () { let file = fileIO.openSync(fpath); let stat2 = fileIO.statSync(file.fd); expect(stat2.isCharacterDevice() === false).assertTrue(); - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); } catch (e) { console.log('fileIO_stat_sync_is_character_device_000 has failed for ' + e.message + ', code: ' + e.code); expect(false).assertTrue(); @@ -440,7 +440,7 @@ describe('fileIO_fs_stat', function () { * This interface does not require parameters. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_stat_sync_is_character_device_001', 0, async function () { @@ -451,7 +451,7 @@ describe('fileIO_fs_stat', function () { fileIO.statSync(fpath).isCharacterDevice(-1); expect(false).assertTrue(); } catch (e) { - fileio.unlinkSync(fpath); + fileIO.unlinkSync(fpath); console.log('fileIO_stat_sync_is_character_device_001 has failed for ' + e.message + ', code: ' + e.code); expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue(); } @@ -464,7 +464,7 @@ describe('fileIO_fs_stat', function () { * This interface does not require parameters. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_stat_sync_is_character_device_002', 0, async function () { @@ -476,8 +476,8 @@ describe('fileIO_fs_stat', function () { fileIO.statSync(file.fd).isCharacterDevice(-1); expect(false).assertTrue(); } catch (e) { - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); console.log('fileIO_stat_sync_is_character_device_002 has failed for ' + e.message + ', code: ' + e.code); expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue(); } @@ -490,7 +490,7 @@ describe('fileIO_fs_stat', function () { * This interface shall not treat a normal file as a directory. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_stat_sync_is_directory_000', 0, async function () { @@ -504,8 +504,8 @@ describe('fileIO_fs_stat', function () { let file = fileIO.openSync(fpath); let stat2 = fileIO.statSync(file.fd); expect(stat2.isDirectory() === false).assertTrue(); - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); } catch (e) { console.log('fileIO_stat_sync_is_directory_000 has failed for ' + e.message + ', code: ' + e.code); expect(false).assertTrue(); @@ -519,22 +519,22 @@ describe('fileIO_fs_stat', function () { * This interface shall treat a directory as a directory. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_stat_sync_is_directory_001', 0, async function () { let dpath = await nextFileName('fileIO_stat_sync_is_directory_001'); try { - fileio.mkdirSync(dpath); + fileIO.mkdirSync(dpath); let stat = fileIO.statSync(dpath); expect(stat.isDirectory() === true).assertTrue(); let file = fileIO.openSync(dpath, fileIO.OpenMode.DIR); let stat2 = fileIO.statSync(file.fd); expect(stat2.isDirectory() === true).assertTrue(); - fileio.closeSync(file.fd); - fileio.rmdirSync(dpath); + fileIO.closeSync(file); + fileIO.rmdirSync(dpath); } catch (e) { console.log('fileIO_stat_sync_is_directory_001 has failed for ' + e.message + ', code: ' + e.code); expect(false).assertTrue(); @@ -548,18 +548,18 @@ describe('fileIO_fs_stat', function () { * This interface does not require parameters. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_stat_sync_is_directory_002', 0, async function () { let dpath = await nextFileName('fileIO_stat_sync_is_directory_002') + 'd'; try { - fileio.mkdirSync(dpath); + fileIO.mkdirSync(dpath); fileIO.statSync(dpath).isDirectory(-1); expect(false).assertTrue(); } catch (e) { - fileio.rmdirSync(dpath); + fileIO.rmdirSync(dpath); console.log('fileIO_stat_sync_is_directory_002 has failed for ' + e.message + ', code: ' + e.code); expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue(); } @@ -572,20 +572,20 @@ describe('fileIO_fs_stat', function () { * This interface does not require parameters. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_stat_sync_is_directory_003', 0, async function () { let dpath = await nextFileName('fileIO_stat_sync_is_directory_003') + 'd'; - fileio.mkdirSync(dpath); + fileIO.mkdirSync(dpath); let file = fileIO.openSync(dpath, fileIO.OpenMode.DIR); try { fileIO.statSync(file.fd).isDirectory(-1); expect(false).assertTrue(); } catch (e) { - fileio.closeSync(file.fd); - fileio.rmdirSync(dpath); + fileIO.closeSync(file); + fileIO.rmdirSync(dpath); console.log('fileIO_stat_sync_is_directory_003 has failed for ' + e.message + ', code: ' + e.code); expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue(); } @@ -598,7 +598,7 @@ describe('fileIO_fs_stat', function () { * This interface shall not treat a normal file as a FIFO. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_stat_sync_is_fifo_000', 0, async function () { @@ -612,8 +612,8 @@ describe('fileIO_fs_stat', function () { let file = fileIO.openSync(fpath); let stat2 = fileIO.statSync(file.fd); expect(stat2.isFIFO() === false).assertTrue(); - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); } catch (e) { console.log('fileIO_stat_sync_is_fifo_000 has failed for ' + e.message + ', code: ' + e.code); expect(false).assertTrue(); @@ -627,7 +627,7 @@ describe('fileIO_fs_stat', function () { * This interface does not require parameters. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_stat_sync_is_fifo_001', 0, async function () { @@ -638,7 +638,7 @@ describe('fileIO_fs_stat', function () { fileIO.statSync(fpath).isFile(-1); expect(false).assertTrue(); } catch (e) { - fileio.unlinkSync(fpath); + fileIO.unlinkSync(fpath); console.log('fileIO_stat_sync_is_fifo_001 has failed for ' + e.message + ', code: ' + e.code); expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue(); } @@ -651,7 +651,7 @@ describe('fileIO_fs_stat', function () { * This interface does not require parameters. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_stat_sync_is_fifo_002', 0, async function () { @@ -663,8 +663,8 @@ describe('fileIO_fs_stat', function () { fileIO.statSync(file.fd).isFile(-1); expect(false).assertTrue(); } catch (e) { - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); console.log('fileIO_stat_sync_is_fifo_002 has failed for ' + e.message + ', code: ' + e.code); expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue(); } @@ -676,7 +676,7 @@ describe('fileIO_fs_stat', function () { * This interface shall treat a normal file as a normal file. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_stat_sync_is_file_000', 0, async function () { @@ -690,8 +690,8 @@ describe('fileIO_fs_stat', function () { let file = fileIO.openSync(fpath); let stat2 = fileIO.statSync(file.fd); expect(stat2.isFile() === true).assertTrue(); - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); } catch (e) { console.log('fileIO_stat_sync_is_file_000 has failed for ' + e.message + ', code: ' + e.code); expect(false).assertTrue(); @@ -705,22 +705,22 @@ describe('fileIO_fs_stat', function () { * This interface shall not treat a directory as a normal file. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_stat_sync_is_file_001', 0, async function () { let dpath = await nextFileName('fileIO_stat_sync_is_file_001'); try { - fileio.mkdirSync(dpath); + fileIO.mkdirSync(dpath); let stat = fileIO.statSync(dpath); expect(stat.isFile() === false).assertTrue(); let file = fileIO.openSync(dpath, fileIO.OpenMode.DIR); let stat2 = fileIO.statSync(file.fd); expect(stat2.isFile() === false).assertTrue(); - fileio.closeSync(file.fd); - fileio.rmdirSync(dpath); + fileIO.closeSync(file); + fileIO.rmdirSync(dpath); } catch (e) { console.log('fileIO_stat_sync_is_file_001 has failed for ' + e.message + ', code: ' + e.code); expect(false).assertTrue(); @@ -734,18 +734,18 @@ describe('fileIO_fs_stat', function () { * This interface does not require parameters. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_stat_sync_is_file_002', 0, async function () { let dpath = await nextFileName('fileIO_stat_sync_is_file_002'); try { - fileio.mkdirSync(dpath); + fileIO.mkdirSync(dpath); fileIO.statSync(dpath).isFile(-1); expect(false).assertTrue(); } catch (e) { - fileio.rmdirSync(dpath); + fileIO.rmdirSync(dpath); console.log('fileIO_stat_sync_is_file_002 has failed for ' + e.message + ', code: ' + e.code); expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue(); } @@ -758,20 +758,20 @@ describe('fileIO_fs_stat', function () { * This interface does not require parameters. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_stat_sync_is_file_003', 0, async function () { let dpath = await nextFileName('fileIO_stat_sync_is_file_003'); - fileio.mkdirSync(dpath); + fileIO.mkdirSync(dpath); let file = fileIO.openSync(dpath, fileIO.OpenMode.DIR); try { fileIO.statSync(file.fd).isFile(-1); expect(false).assertTrue(); } catch (e) { - fileio.closeSync(file.fd); - fileio.rmdirSync(dpath); + fileIO.closeSync(file); + fileIO.rmdirSync(dpath); console.log('fileIO_stat_sync_is_file_003 has failed for ' + e.message + ', code: ' + e.code); expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue(); } @@ -784,7 +784,7 @@ describe('fileIO_fs_stat', function () { * This interface shall not treat a file as a socket. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_stat_sync_is_socket_000', 0, async function () { @@ -798,8 +798,8 @@ describe('fileIO_fs_stat', function () { let file = fileIO.openSync(fpath); let stat2 = fileIO.statSync(file.fd); expect(stat2.isSocket() === false).assertTrue(); - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); } catch (e) { console.log('fileIO_stat_sync_is_socket_000 has failed for ' + e.message + ', code: ' + e.code); expect(false).assertTrue(); @@ -813,7 +813,7 @@ describe('fileIO_fs_stat', function () { * This interface does not require parameters. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_stat_sync_is_socket_001', 0, async function () { @@ -824,7 +824,7 @@ describe('fileIO_fs_stat', function () { fileIO.statSync(fpath).isSocket(-1); expect(false).assertTrue(); } catch (e) { - fileio.unlinkSync(fpath); + fileIO.unlinkSync(fpath); console.log('fileIO_stat_sync_is_socket_001 has failed for ' + e.message + ', code: ' + e.code); expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue(); } @@ -837,7 +837,7 @@ describe('fileIO_fs_stat', function () { * This interface does not require parameters. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_stat_sync_is_socket_002', 0, async function () { @@ -849,8 +849,8 @@ describe('fileIO_fs_stat', function () { fileIO.statSync(file.fd).isSocket(-1); expect(false).assertTrue(); } catch (e) { - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); console.log('fileIO_stat_sync_is_socket_002 has failed for ' + e.message + ', code: ' + e.code); expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue(); } @@ -862,7 +862,7 @@ describe('fileIO_fs_stat', function () { * This interface shall not treat a normal file as a symbolic link. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_stat_sync_is_symbolic_link_000', 0, async function () { @@ -876,8 +876,8 @@ describe('fileIO_fs_stat', function () { let file = fileIO.openSync(fpath); let stat2 = fileIO.statSync(file.fd); expect(stat2.isSymbolicLink() === false).assertTrue(); - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); } catch (e) { console.log('fileIO_stat_sync_is_symbolic_link_000 has failed for ' + e.message + ', code: ' + e.code); expect(false).assertTrue(); @@ -891,7 +891,7 @@ describe('fileIO_fs_stat', function () { * This interface does not require parameters. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_stat_sync_is_symbolic_link_001', 0, async function () { @@ -902,7 +902,7 @@ describe('fileIO_fs_stat', function () { fileIO.statSync(fpath).isSymbolicLink(-1); expect(false).assertTrue(); } catch (e) { - fileio.unlinkSync(fpath); + fileIO.unlinkSync(fpath); console.log('fileIO_stat_sync_is_symbolic_link_001 has failed for ' + e.message + ', code: ' + e.code); expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue(); } @@ -915,7 +915,7 @@ describe('fileIO_fs_stat', function () { * This interface does not require parameters. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_stat_sync_is_symbolic_link_002', 0, async function () { @@ -927,8 +927,8 @@ describe('fileIO_fs_stat', function () { fileIO.statSync(file.fd).isSymbolicLink(-1); expect(false).assertTrue(); } catch (e) { - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); console.log('fileIO_stat_sync_is_symbolic_link_001 has failed for ' + e.message + ', code: ' + e.code); expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue(); } @@ -959,12 +959,12 @@ describe('fileIO_fs_stat', function () { let file = fileIO.openSync(fpath); fileIO.stat(file.fd).then((stat2) => { expect(stat2 !== null).assertTrue(); - fileio.closeSync(file.fd); + fileIO.closeSync(file); }).catch((err) => { console.log('fileIO_stat_async_000 error package2: ' + JSON.stringify(err)); expect(false).assertTrue(); }); - fileio.unlinkSync(fpath); + fileIO.unlinkSync(fpath); done(); } catch (e) { console.log('fileIO_stat_async_000 has failed for ' + e.message + ', code: ' + e.code); @@ -993,8 +993,8 @@ describe('fileIO_fs_stat', function () { let file = fileIO.openSync(fpath); let stat2 = await fileIO.stat(file.fd); expect(stat2 !== null).assertTrue(); - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); done(); } catch (e) { console.log('fileIO_stat_async_001 has failed for ' + e.message + ', code: ' + e.code); @@ -1009,7 +1009,7 @@ describe('fileIO_fs_stat', function () { * Enter the path or fd parameter to get the file stat. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_stat_async_002', 0, async function (done) { @@ -1032,8 +1032,8 @@ describe('fileIO_fs_stat', function () { expect(false).assertTrue(); } expect(stat2 !== null).assertTrue(); - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); done(); }); } catch (e) { @@ -1049,7 +1049,7 @@ describe('fileIO_fs_stat', function () { * The path point to nothing, no such file. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_stat_async_003', 0, async function (done) { @@ -1072,7 +1072,7 @@ describe('fileIO_fs_stat', function () { * The path point to nothing, no such file. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_stat_async_004', 0, async function (done) { @@ -1081,7 +1081,7 @@ describe('fileIO_fs_stat', function () { try { fileIO.stat(fpath, (err) => { if (err) { - console.log('fileIO_stat_async_004 error package: {' + err.message + ', code: ' + err.code + '}'); + console.log('fileIO_stat_async_004 error: {message: ' + err.message + ', code: ' + err.code + '}'); expect(err.code == 13900002 && err.message == 'No such file or directory').assertTrue(); done(); } @@ -1099,7 +1099,7 @@ describe('fileIO_fs_stat', function () { * Invalid path or fd parameter. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_stat_async_005', 0, async function (done) { @@ -1120,13 +1120,13 @@ describe('fileIO_fs_stat', function () { * Invalid path or fd parameter. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_stat_async_006', 0, async function (done) { try { - fileIO.stat(-1, () => { + fileIO.stat(-1, (err) => { expect(false).assertTrue(); }); } catch (e) { @@ -1143,7 +1143,7 @@ describe('fileIO_fs_stat', function () { * Enter the path or fd parameter to get stat.ino of the file. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_stat_async_ino_000', 0, async function (done) { @@ -1157,8 +1157,8 @@ describe('fileIO_fs_stat', function () { let file = fileIO.openSync(fpath); let stat2 = await fileIO.stat(file.fd); expect(isBigInt(stat2.ino)).assertTrue(); - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); done(); } catch (e) { console.log('fileIO_stat_async_ino_000 has failed for ' + e.message + ', code: ' + e.code); @@ -1173,7 +1173,7 @@ describe('fileIO_fs_stat', function () { * Enter the path or fd parameter to get stat.atime of the file. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_stat_async_ino_001', 0, async function (done) { @@ -1196,8 +1196,8 @@ describe('fileIO_fs_stat', function () { expect(false).assertTrue(); } expect(isBigInt(stat2.ino)).assertTrue(); - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); done(); }); } catch (e) { @@ -1213,7 +1213,7 @@ describe('fileIO_fs_stat', function () { * Enter the path or fd parameter to get stat.mode of the file. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_stat_async_mode_000', 0, async function (done) { @@ -1227,8 +1227,8 @@ describe('fileIO_fs_stat', function () { let file = fileIO.openSync(fpath); let stat2 = await fileIO.stat(file.fd); expect(isIntNum(stat2.mode)).assertTrue(); - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); done(); } catch (e) { console.log('fileIO_stat_async_mode_000 has failed for ' + e.message + ', code: ' + e.code); @@ -1243,7 +1243,7 @@ describe('fileIO_fs_stat', function () { * Enter the path or fd parameter to get stat.mode of the file. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_stat_async_mode_001', 0, async function (done) { @@ -1266,8 +1266,8 @@ describe('fileIO_fs_stat', function () { expect(false).assertTrue(); } expect(isIntNum(stat2.mode)).assertTrue(); - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); done(); }); } catch (e) { @@ -1283,7 +1283,7 @@ describe('fileIO_fs_stat', function () { * Enter the path or fd parameter to get stat.uid of the file. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_stat_async_uid_000', 0, async function (done) { @@ -1297,8 +1297,8 @@ describe('fileIO_fs_stat', function () { let file = fileIO.openSync(fpath); let stat2 = await fileIO.stat(file.fd); expect(isIntNum(stat2.uid)).assertTrue(); - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); done(); } catch (e) { console.log('fileIO_stat_async_uid_000 has failed for ' + e.message + ', code: ' + e.code); @@ -1313,7 +1313,7 @@ describe('fileIO_fs_stat', function () { * Enter the path or fd parameter to get stat.uid of the file. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_stat_async_uid_001', 0, async function (done) { @@ -1336,8 +1336,8 @@ describe('fileIO_fs_stat', function () { expect(false).assertTrue(); } expect(isIntNum(stat2.uid)).assertTrue(); - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); done(); }); } catch (e) { @@ -1354,7 +1354,7 @@ describe('fileIO_fs_stat', function () { * Enter the path or fd parameter to get stat.gid of the file. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_stat_async_gid_000', 0, async function (done) { @@ -1368,8 +1368,8 @@ describe('fileIO_fs_stat', function () { let file = fileIO.openSync(fpath); let stat2 = await fileIO.stat(file.fd); expect(isIntNum(stat2.gid)).assertTrue(); - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); done(); } catch (e) { console.log('fileIO_stat_async_gid_000 has failed for ' + e.message + ', code: ' + e.code); @@ -1384,7 +1384,7 @@ describe('fileIO_fs_stat', function () { * Enter the path or fd parameter to get stat.gid of the file. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_stat_async_gid_001', 0, async function (done) { @@ -1407,8 +1407,8 @@ describe('fileIO_fs_stat', function () { expect(false).assertTrue(); } expect(isIntNum(stat2.gid)).assertTrue(); - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); done(); }); } catch (e) { @@ -1424,7 +1424,7 @@ describe('fileIO_fs_stat', function () { * Enter the path or fd parameter to get stat.size of the file. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_stat_async_size_000', 0, async function (done) { @@ -1438,8 +1438,8 @@ describe('fileIO_fs_stat', function () { let file = fileIO.openSync(fpath); let stat2 = await fileIO.stat(file.fd); expect(isIntNum(stat2.size)).assertTrue(); - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); done(); } catch (e) { console.log('fileIO_stat_async_size_000 has failed for ' + e.message + ', code: ' + e.code); @@ -1454,7 +1454,7 @@ describe('fileIO_fs_stat', function () { * Enter the path or fd parameter to get stat.size of the file. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_stat_async_size_001', 0, async function (done) { @@ -1477,8 +1477,8 @@ describe('fileIO_fs_stat', function () { expect(false).assertTrue(); } expect(isIntNum(stat2.size)).assertTrue(); - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); done(); }); } catch (e) { @@ -1494,7 +1494,7 @@ describe('fileIO_fs_stat', function () { * Enter the path or fd parameter to get stat.atime of the file. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_stat_async_atime_000', 0, async function (done) { @@ -1508,8 +1508,8 @@ describe('fileIO_fs_stat', function () { let file = fileIO.openSync(fpath); let stat2 = await fileIO.stat(file.fd); expect(isIntNum(stat2.atime)).assertTrue(); - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); done(); } catch (e) { console.log('fileIO_stat_async_atime_000 has failed for ' + e.message + ', code: ' + e.code); @@ -1524,7 +1524,7 @@ describe('fileIO_fs_stat', function () { * Enter the path or fd parameter to get stat.atime of the file. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_stat_async_atime_001', 0, async function (done) { @@ -1547,8 +1547,8 @@ describe('fileIO_fs_stat', function () { expect(false).assertTrue(); } expect(isIntNum(stat2.atime)).assertTrue(); - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); done(); }); } catch (e) { @@ -1564,7 +1564,7 @@ describe('fileIO_fs_stat', function () { * Enter the path or fd parameter to get stat.mtime of the file. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_stat_async_mtime_000', 0, async function (done) { @@ -1578,8 +1578,8 @@ describe('fileIO_fs_stat', function () { let file = fileIO.openSync(fpath); let stat2 = await fileIO.stat(file.fd); expect(isIntNum(stat2.mtime)).assertTrue(); - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); done(); } catch (e) { console.log('fileIO_stat_async_mtime_000 has failed for ' + e.message + ', code: ' + e.code); @@ -1594,7 +1594,7 @@ describe('fileIO_fs_stat', function () { * Enter the path or fd parameter to get stat.mtime of the file. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_stat_async_mtime_001', 0, async function (done) { @@ -1617,8 +1617,8 @@ describe('fileIO_fs_stat', function () { expect(false).assertTrue(); } expect(isIntNum(stat2.mtime)).assertTrue(); - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); done(); }); } catch (e) { @@ -1634,7 +1634,7 @@ describe('fileIO_fs_stat', function () { * Enter the path or fd parameter to get stat.ctime of the file. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_stat_async_ctime_000', 0, async function (done) { @@ -1648,8 +1648,8 @@ describe('fileIO_fs_stat', function () { let file = fileIO.openSync(fpath); let stat2 = await fileIO.stat(file.fd); expect(isIntNum(stat2.ctime)).assertTrue(); - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); done(); } catch (e) { console.log('fileIO_stat_async_ctime_000 has failed for ' + e.message + ', code: ' + e.code); @@ -1664,7 +1664,7 @@ describe('fileIO_fs_stat', function () { * Enter the path or fd parameter to get stat.ctime of the file. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_stat_async_ctime_001', 0, async function (done) { @@ -1687,8 +1687,8 @@ describe('fileIO_fs_stat', function () { expect(false).assertTrue(); } expect(isIntNum(stat2.ctime)).assertTrue(); - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); done(); }); } catch (e) { @@ -1704,7 +1704,7 @@ describe('fileIO_fs_stat', function () { * This interface shall not treat a normal file as a block special device. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_stat_async_is_block_device_000', 0, async function (done) { @@ -1718,8 +1718,8 @@ describe('fileIO_fs_stat', function () { let file = fileIO.openSync(fpath); let stat2 = await fileIO.stat(file.fd); expect(stat2.isBlockDevice() === false).assertTrue(); - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); done(); } catch (e) { console.log('fileIO_stat_async_is_block_device_000 has failed for ' + e.message + ', code: ' + e.code); @@ -1734,7 +1734,7 @@ describe('fileIO_fs_stat', function () { * This interface shall not treat a normal file as a block special device. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_stat_async_is_block_device_001', 0, async function (done) { @@ -1757,8 +1757,8 @@ describe('fileIO_fs_stat', function () { expect(false).assertTrue(); } expect(stat2.isBlockDevice() === false).assertTrue(); - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); done(); }); } catch (e) { @@ -1774,7 +1774,7 @@ describe('fileIO_fs_stat', function () { * This interface shall not treat a normal file as a character special device. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_stat_async_is_character_device_000', 0, async function (done) { @@ -1788,8 +1788,8 @@ describe('fileIO_fs_stat', function () { let file = fileIO.openSync(fpath); let stat2 = await fileIO.stat(file.fd); expect(stat2.isCharacterDevice() === false).assertTrue(); - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); done(); } catch (e) { console.log('fileIO_stat_async_is_character_device_000 has failed for ' + e.message + ', code: ' + e.code); @@ -1804,7 +1804,7 @@ describe('fileIO_fs_stat', function () { * This interface shall not treat a normal file as a character special device. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_stat_async_is_character_device_001', 0, async function (done) { @@ -1827,8 +1827,8 @@ describe('fileIO_fs_stat', function () { expect(false).assertTrue(); } expect(stat2.isCharacterDevice() === false).assertTrue(); - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); done(); }); } catch (e) { @@ -1844,7 +1844,7 @@ describe('fileIO_fs_stat', function () { * This interface shall not treat a normal file as a directory. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_stat_async_is_directory_000', 0, async function (done) { @@ -1858,8 +1858,8 @@ describe('fileIO_fs_stat', function () { let file = fileIO.openSync(fpath); let stat2 = await fileIO.stat(file.fd); expect(stat2.isDirectory() === false).assertTrue(); - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); done(); } catch (e) { console.log('fileIO_stat_async_is_directory_000 has failed for ' + e.message + ', code: ' + e.code); @@ -1874,22 +1874,22 @@ describe('fileIO_fs_stat', function () { * This interface shall not treat a directory as a directory. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_stat_async_is_directory_001', 0, async function (done) { let dpath = await nextFileName('fileIO_stat_async_is_directory_001') + 'd'; try { - fileio.mkdirSync(dpath); + fileIO.mkdirSync(dpath); let stat = await fileIO.stat(dpath); expect(stat.isDirectory() === true).assertTrue(); let file = fileIO.openSync(dpath, fileIO.OpenMode.DIR); let stat2 = await fileIO.stat(file.fd); expect(stat2.isDirectory() === true).assertTrue(); - fileio.closeSync(file.fd); - fileio.rmdirSync(dpath); + fileIO.closeSync(file); + fileIO.rmdirSync(dpath); done(); } catch (e) { console.log('fileIO_stat_async_is_directory_001 has failed for ' + e.message + ', code: ' + e.code); @@ -1904,14 +1904,14 @@ describe('fileIO_fs_stat', function () { * This interface shall not treat a directory as a directory. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_stat_async_is_directory_002', 0, async function (done) { let dpath = await nextFileName('fileIO_stat_async_is_directory_002') + 'd'; try { - fileio.mkdirSync(dpath); + fileIO.mkdirSync(dpath); fileIO.stat(dpath, (err, stat) => { if(err) { console.log('fileIO_stat_async_is_directory_002 error package1: ' + JSON.stringify(err)); @@ -1927,8 +1927,8 @@ describe('fileIO_fs_stat', function () { expect(false).assertTrue(); } expect(stat2.isDirectory() === true).assertTrue(); - fileio.closeSync(file.fd); - fileio.rmdirSync(dpath); + fileIO.closeSync(file); + fileIO.rmdirSync(dpath); done(); }); } catch (e) { @@ -1944,7 +1944,7 @@ describe('fileIO_fs_stat', function () { * This interface shall not treat a normal file as a FIFO. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_stat_async_is_fifo_000', 0, async function (done) { @@ -1958,8 +1958,8 @@ describe('fileIO_fs_stat', function () { let file = fileIO.openSync(fpath); let stat2 = await fileIO.stat(file.fd); expect(stat2.isFIFO() === false).assertTrue(); - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); done(); } catch (e) { console.log('fileIO_stat_async_is_fifo_000 has failed for ' + e.message + ', code: ' + e.code); @@ -1974,7 +1974,7 @@ describe('fileIO_fs_stat', function () { * This interface shall not treat a normal file as a FIFO. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_stat_async_is_fifo_001', 0, async function (done) { @@ -1997,8 +1997,8 @@ describe('fileIO_fs_stat', function () { expect(false).assertTrue(); } expect(stat2.isFIFO() === false).assertTrue(); - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); done(); }); } catch (e) { @@ -2014,7 +2014,7 @@ describe('fileIO_fs_stat', function () { * This interface shall treat a normal file as a normal file. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_stat_async_is_file_000', 0, async function (done) { @@ -2028,8 +2028,8 @@ describe('fileIO_fs_stat', function () { let file = fileIO.openSync(fpath); let stat2 = await fileIO.stat(file.fd); expect(stat2.isFile() === true).assertTrue(); - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); done(); } catch (e) { console.log('fileIO_stat_async_is_file_000 has failed for ' + e.message + ', code: ' + e.code); @@ -2044,7 +2044,7 @@ describe('fileIO_fs_stat', function () { * This interface shall treat a normal file as a normal file. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_stat_async_is_file_001', 0, async function (done) { @@ -2067,8 +2067,8 @@ describe('fileIO_fs_stat', function () { expect(false).assertTrue(); } expect(stat2.isFile() === true).assertTrue(); - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); done(); }); } catch (e) { @@ -2084,22 +2084,22 @@ describe('fileIO_fs_stat', function () { * This interface shall not treat a directory as a normal file. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_stat_async_is_file_002', 0, async function (done) { let dpath = await nextFileName('fileIO_stat_async_is_file_002'); try { - fileio.mkdirSync(dpath); + fileIO.mkdirSync(dpath); let stat = await fileIO.stat(dpath); expect(stat.isFile() === false).assertTrue(); let file = fileIO.openSync(dpath, fileIO.OpenMode.DIR); let stat2 = await fileIO.stat(file.fd); expect(stat2.isFile() === false).assertTrue(); - fileio.closeSync(file.fd); - fileio.rmdirSync(dpath); + fileIO.closeSync(file); + fileIO.rmdirSync(dpath); done(); } catch (e) { console.log('fileIO_stat_async_is_file_002 has failed for ' + e.message + ', code: ' + e.code); @@ -2114,7 +2114,7 @@ describe('fileIO_fs_stat', function () { * This interface shall not treat a file as a socket. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_stat_async_is_socket_000', 0, async function (done) { @@ -2128,7 +2128,7 @@ describe('fileIO_fs_stat', function () { let file = fileIO.openSync(fpath); let stat2 = await fileIO.stat(file.fd); expect(stat2.isSocket() === false).assertTrue(); - fileio.closeSync(file.fd); + fileIO.closeSync(file); done(); } catch (e) { console.log('fileIO_stat_async_is_socket_000 has failed for ' + e.message + ', code: ' + e.code); @@ -2143,7 +2143,7 @@ describe('fileIO_fs_stat', function () { * This interface shall not treat a file as a socket. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_stat_async_is_socket_001', 0, async function (done) { @@ -2166,8 +2166,8 @@ describe('fileIO_fs_stat', function () { expect(false).assertTrue(); } expect(stat2.isSocket() === false).assertTrue(); - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); done(); }); } catch (e) { @@ -2183,7 +2183,7 @@ describe('fileIO_fs_stat', function () { * This interface shall not treat a normal file as a symbolic link. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_stat_async_is_symbolic_link_000', 0, async function (done) { @@ -2197,8 +2197,8 @@ describe('fileIO_fs_stat', function () { let file = fileIO.openSync(fpath); let stat2 = await fileIO.stat(file.fd); expect(stat2.isSymbolicLink() === false).assertTrue(); - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); done(); } catch (e) { console.log('fileIO_stat_async_is_symbolic_link_000 has failed for ' + e.message + ', code: ' + e.code); @@ -2213,7 +2213,7 @@ describe('fileIO_fs_stat', function () { * This interface shall not treat a normal file as a symbolic link. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_stat_async_is_symbolic_link_001', 0, async function (done) { @@ -2236,8 +2236,8 @@ describe('fileIO_fs_stat', function () { expect(false).assertTrue(); } expect(stat2.isSymbolicLink() === false).assertTrue(); - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); done(); }); } catch (e) { @@ -2253,7 +2253,7 @@ describe('fileIO_fs_stat', function () { * Modify the file, view the file status changes by path. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_test_append_file_sync_000', 0, async function (done) { @@ -2267,11 +2267,11 @@ describe('fileIO_fs_stat', function () { let file = fileIO.openSync(fpath, fileIO.OpenMode.APPEND | fileIO.OpenMode.READ_WRITE); expect(isIntNum(file.fd)).assertTrue(); expect(fileIO.writeSync(file.fd, FILE_CONTENT) == FILE_CONTENT.length).assertTrue(); - fileio.closeSync(file.fd); + fileIO.closeSync(file); stat = fileIO.statSync(fpath); expect(stat.size == FILE_CONTENT.length * 2).assertTrue(); - fileio.unlinkSync(fpath); + fileIO.unlinkSync(fpath); done(); } catch (e) { console.log('fileIO_test_append_file_sync_000 has failed for ' + e.message + ', code: ' + e.code); @@ -2286,7 +2286,7 @@ describe('fileIO_fs_stat', function () { * Modify the file, view the file status changes by fd. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_test_append_file_sync_001', 0, async function (done) { @@ -2299,13 +2299,13 @@ describe('fileIO_fs_stat', function () { expect(isIntNum(stat.size)).assertTrue(); expect(isIntNum(file.fd)).assertTrue(); expect(fileIO.writeSync(file.fd, FILE_CONTENT) == FILE_CONTENT.length).assertTrue(); - fileio.closeSync(file.fd); + fileIO.closeSync(file); let file2 = fileIO.openSync(fpath, fileIO.OpenMode.READ_WRITE); stat = fileIO.statSync(file2.fd); expect(stat.size == FILE_CONTENT.length * 2).assertTrue(); - fileio.closeSync(file2.fd); - fileio.unlinkSync(fpath); + fileIO.closeSync(file2.fd); + fileIO.unlinkSync(fpath); done(); } catch (e) { console.log('fileIO_test_append_file_sync_001 has failed for ' + e.message + ', code: ' + e.code); diff --git a/storage/storagefileiov9jstest/src/main/js/test/members/symlink.test.js b/storage/storagefileiov9jstest/src/main/js/test/members/symlink.test.js new file mode 100644 index 000000000..0e94637db --- /dev/null +++ b/storage/storagefileiov9jstest/src/main/js/test/members/symlink.test.js @@ -0,0 +1,184 @@ +/* + * Copyright (C) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the 'License'); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an 'AS IS' BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { + fileIO, FILE_CONTENT, prepareFile, nextFileName, describe, it, expect, +} from '../Common'; + +export default function fileIOSymlink() { +describe('fileIO_fs_symlink', function () { + + /** + * @tc.number SUB_DF_FILEIO_SYMLINK_SYNC_0000 + * @tc.name fileIO_test_symlink_sync_000 + * @tc.desc Test symlinkSync() interfaces. + * Create a symbolic link to verify normal function. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_test_symlink_sync_000', 0, async function () { + let fpath = await nextFileName('fileIO_test_symlink_sync_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + fileIO.symlinkSync(fpath, fpath + 'link0'); + expect(fileIO.accessSync(fpath + 'link0')).assertTrue(); + fileIO.unlinkSync(fpath); + fileIO.unlinkSync(fpath + 'link0'); + } catch (e) { + console.log('fileIO_test_symlink_sync_000 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_SYMLINK_SYNC_0100 + * @tc.name fileIO_test_symlink_sync_001 + * @tc.desc Test symlinkSync() interfaces. + * Missing parameter. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_test_symlink_sync_001', 0, async function () { + let fpath = await nextFileName('fileIO_test_symlink_sync_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + fileIO.symlinkSync(fpath); + expect(false).assertTrue(); + } catch (e) { + fileIO.unlinkSync(fpath); + console.log('fileIO_test_symlink_sync_001 has failed for ' + e.message + ', code: ' + e.code); + expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_SYMLINK_ASYNC_0000 + * @tc.name fileIO_test_symlink_async_000 + * @tc.desc Test SymlinkAsync interfaces. Promise.then().catch() + * Create a symbolic link to verify normal function. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_test_symlink_async_000', 0, async function (done) { + let fpath = await nextFileName('fileIO_test_symlink_async_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + fileIO.symlink(fpath, fpath + 'link1').then(() => { + expect(fileIO.accessSync(fpath + 'link1')).assertTrue(); + fileIO.unlinkSync(fpath); + fileIO.unlinkSync(fpath + 'link1'); + }).catch((err) => { + console.log('fileIO_test_symlink_async_000 error package: ' + JSON.stringify(err)); + expect(false).assertTrue(); + }) + done(); + } catch (e) { + console.log('fileIO_test_symlink_async_000 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_SYMLINK_ASYNC_0100 + * @tc.name fileIO_test_symlink_async_001 + * @tc.desc Test SymlinkAsync interfaces. await Promise. + * Create a symbolic link to verify normal function. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_test_symlink_async_001', 0, async function (done) { + let fpath = await nextFileName('fileIO_test_symlink_async_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + await fileIO.symlink(fpath, fpath + 'link2'); + expect(fileIO.accessSync(fpath + 'link2')).assertTrue(); + fileIO.unlinkSync(fpath); + fileIO.unlinkSync(fpath + 'link2'); + done(); + } catch (e) { + console.log('fileIO_test_symlink_async_001 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_SYMLINK_ASYNC_0200 + * @tc.name fileIO_test_symlink_async_002 + * @tc.desc Test SymlinkAsync interfaces. Promise. + * Create a symbolic link to verify normal function. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_test_symlink_async_002', 0, async function (done) { + let fpath = await nextFileName('fileIO_test_symlink_async_002'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + fileIO.symlink(fpath, fpath + 'link3', (err) => { + if (err) { + console.log('fileIO_test_symlink_async_002 error package: ' + JSON.stringify(err)); + expect(false).assertTrue(); + } + expect(fileIO.accessSync(fpath + 'link3')).assertTrue(); + fileIO.unlinkSync(fpath); + fileIO.unlinkSync(fpath + 'link3'); + done(); + }); + } catch (e) { + console.log('fileIO_test_symlink_async_002 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_SYMLINK_ASYNC_0300 + * @tc.name fileIO_test_symlink_async_003 + * @tc.desc Test SymlinkAsync interfaces. Promise. + * Missing parameter. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_test_symlink_async_003', 0, async function (done) { + let fpath = await nextFileName('fileIO_test_symlink_async_003'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + await fileIO.symlink(fpath); + expect(false).assertTrue(); + } catch (e) { + fileIO.unlinkSync(fpath); + console.log('fileIO_test_symlink_async_003 has failed for ' + e.message + ', code: ' + e.code); + expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue(); + done(); + } + }); +}); +} diff --git a/storage/storagefileiov9jstest/src/main/js/test/members/truncate.test.js b/storage/storagefileiov9jstest/src/main/js/test/members/truncate.test.js index 39d2b2bc7..654f1dd4f 100644 --- a/storage/storagefileiov9jstest/src/main/js/test/members/truncate.test.js +++ b/storage/storagefileiov9jstest/src/main/js/test/members/truncate.test.js @@ -14,8 +14,7 @@ */ import { - fileio, fileIO, FILE_CONTENT, prepareFile, nextFileName, isIntNum, - describe, it, expect, + fileIO, FILE_CONTENT, prepareFile, nextFileName, isIntNum, describe, it, expect, } from '../Common'; export default function fileIOTruncate() { @@ -40,13 +39,13 @@ import { await fileIO.truncate(fpath, truncateLen); let file = fileIO.openSync(fpath, fileIO.OpenMode.READ_WRITE); expect(isIntNum(file.fd)).assertTrue(); - let len = fileIO.readSync(file.fd, new ArrayBuffer(4096)); - expect(len == truncateLen).assertTrue(); - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); + let readLen = fileIO.readSync(file.fd, new ArrayBuffer(4096)); + expect(readLen == truncateLen).assertTrue(); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); done(); } catch (e) { - console.info('fileIO_truncate_async_000 has failed for ' + e.message + ', code: ' + e.code); + console.log('fileIO_truncate_async_000 has failed for ' + e.message + ', code: ' + e.code); expect(false).assertTrue(); } }); @@ -58,7 +57,7 @@ import { * Truncate the file with fd and truncateLen = 5. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_truncate_async_001', 0, async function (done) { @@ -74,12 +73,12 @@ import { console.log('fileIO_truncate_async_001 error package: ' + JSON.stringify(err)); expect(false).assertTrue(); } - let len = fileIO.readSync(file.fd, new ArrayBuffer(4096)); - expect(len == truncateLen).assertTrue(); - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); + let readLen = fileIO.readSync(file.fd, new ArrayBuffer(4096)); + expect(readLen == truncateLen).assertTrue(); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); done(); - }) + }); } catch (e) { console.log('fileIO_truncate_async_001 has failed for ' + e.message + ', code: ' + e.code); expect(false).assertTrue(); @@ -93,7 +92,7 @@ import { * Truncate the file with path and truncateLen = 2. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_truncate_async_002', 0, async function (done) { @@ -105,10 +104,10 @@ import { fileIO.truncate(fpath, truncateLen).then(() => { let file = fileIO.openSync(fpath, fileIO.OpenMode.READ_WRITE); expect(isIntNum(file.fd)).assertTrue(); - let len = fileIO.readSync(file.fd, new ArrayBuffer(4096)); - expect(len == truncateLen).assertTrue(); - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); + let readLen = fileIO.readSync(file.fd, new ArrayBuffer(4096)); + expect(readLen == truncateLen).assertTrue(); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); done(); }).catch((err) => { console.log('fileIO_truncate_async_002 error package: ' + JSON.stringify(err)); @@ -127,7 +126,7 @@ import { * Truncate the file with fd and truncateLen = 2. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_truncate_async_003', 0, async function (done) { @@ -139,15 +138,15 @@ import { try { expect(isIntNum(file.fd)).assertTrue(); fileIO.truncate(file.fd, truncateLen).then(() => { - let len = fileIO.readSync(file.fd, new ArrayBuffer(4096)); - expect(len == truncateLen).assertTrue(); - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); + let readLen = fileIO.readSync(file.fd, new ArrayBuffer(4096)); + expect(readLen == truncateLen).assertTrue(); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); done(); }).catch((err) => { console.log('fileIO_truncate_async_003 error package: ' + JSON.stringify(err)); expect(false).assertTrue(); - }) + }); } catch(e) { console.log('fileIO_truncate_async_003 has failed for ' + e.message + ', code: ' + e.code); expect(false).assertTrue(); @@ -158,10 +157,10 @@ import { * @tc.number SUB_DF_FILEIO_TRUNCATE_ASYNC_0400 * @tc.name fileIO_truncate_async_004 * @tc.desc Test the truncate() interface. Callback. - * Truncate the file with path and truncateLen = 2. + * The path point to nothing, no such file. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_truncate_async_004', 0, async function (done) { @@ -171,7 +170,7 @@ import { try { fileIO.truncate(fpath, truncateLen, (err) => { if (err) { - console.log('fileIO_truncate_async_004 error package: {' + err.message + ', code: ' + err.code + '}'); + console.log('fileIO_truncate_async_004 error: {message: ' + err.message + ', code: ' + err.code + '}'); expect(err.code == 13900002 && err.message == 'No such file or directory').assertTrue(); done(); } @@ -186,10 +185,10 @@ import { * @tc.number SUB_DF_FILEIO_TRUNCATE_ASYNC_0500 * @tc.name fileIO_truncate_async_005 * @tc.desc Test the truncate() interface. Promise. - * Truncate the file with path and truncateLen = 2. + * The path point to nothing, no such file. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_truncate_async_005', 0, async function (done) { @@ -206,6 +205,74 @@ import { } }); + /** + * @tc.number SUB_DF_FILEIO_TRUNCATE_ASYNC_0600 + * @tc.name fileIO_truncate_async_006 + * @tc.desc Test the truncate() interface. Callback. + * Truncate the file with fd and truncateLen = 0. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_truncate_async_006', 0, async function (done) { + let fpath = await nextFileName('fileIO_truncate_async_006'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let file = fileIO.openSync(fpath, fileIO.OpenMode.READ_WRITE); + + try { + expect(isIntNum(file.fd)).assertTrue(); + fileIO.truncate(file.fd, (err) => { + if(err) { + console.log('fileIO_truncate_async_006 error package: ' + JSON.stringify(err)); + expect(false).assertTrue(); + } + let readLen = fileIO.readSync(file.fd, new ArrayBuffer(4096)); + expect(readLen == 0).assertTrue(); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); + done(); + }); + } catch (e) { + console.log('fileIO_truncate_async_006 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_TRUNCATE_ASYNC_0700 + * @tc.name fileIO_truncate_async_007 + * @tc.desc Test the truncate() interface. Callback. + * Truncate the file with fd and truncateLen = 0. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_truncate_async_007', 0, async function (done) { + let fpath = await nextFileName('fileIO_truncate_async_007'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + fileIO.truncate(fpath, (err) => { + if(err) { + console.log('fileIO_truncate_async_007 error package: ' + JSON.stringify(err)); + expect(false).assertTrue(); + } + let file = fileIO.openSync(fpath, fileIO.OpenMode.READ_WRITE); + expect(isIntNum(file.fd)).assertTrue(); + let readLen = fileIO.readSync(file.fd, new ArrayBuffer(4096)); + expect(readLen == 0).assertTrue(); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); + done(); + }); + } catch (e) { + console.log('fileIO_truncate_async_008 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); + /** * @tc.number SUB_DF_FILEIO_TRUNCATE_SYNC_0000 * @tc.name fileIO_test_truncate_sync_000 @@ -213,7 +280,7 @@ import { * Truncate the file with path. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_test_truncate_sync_000', 0, async function () { @@ -223,7 +290,7 @@ import { try { fileIO.truncateSync(fpath); expect(fileIO.statSync(fpath).size == 0).assertTrue(); - fileio.unlinkSync(fpath); + fileIO.unlinkSync(fpath); } catch (e) { console.log('fileIO_test_truncate_sync_000 has failed for ' + e.message + ', code: ' + e.code); expect(false).assertTrue(); @@ -237,7 +304,7 @@ import { * Truncate the file with fd and truncateLen = 5. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_test_truncate_sync_001', 0, async function () { @@ -249,10 +316,10 @@ import { try { expect(isIntNum(file.fd)).assertTrue(); fileIO.truncateSync(file.fd, truncateLen); - let len = fileIO.readSync(file.fd, new ArrayBuffer(4096)); - expect(len == truncateLen).assertTrue(); - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); + let readLen = fileIO.readSync(file.fd, new ArrayBuffer(4096)); + expect(readLen == truncateLen).assertTrue(); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); } catch (e) { console.log('fileIO_test_truncate_sync_001 has failed for ' + e.message + ', code: ' + e.code); expect(false).assertTrue(); @@ -266,7 +333,7 @@ import { * The path point to nothing, no such file. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_test_truncate_sync_002', 0, async function () { @@ -287,7 +354,7 @@ import { * @tc.desc Test the truncateSync() interface. Invalid parameter. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_test_truncate_sync_003', 0, async function () { @@ -308,7 +375,7 @@ import { * @tc.desc Test truncateSync() interfaces. Missing parameters. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_test_truncate_sync_004', 0, function () { diff --git a/storage/storagefileiov9jstest/src/main/js/test/members/write.test.js b/storage/storagefileiov9jstest/src/main/js/test/members/write.test.js index 883c67852..c2b36e1e5 100644 --- a/storage/storagefileiov9jstest/src/main/js/test/members/write.test.js +++ b/storage/storagefileiov9jstest/src/main/js/test/members/write.test.js @@ -14,8 +14,7 @@ */ import { - fileio, fileIO, FILE_CONTENT, prepareFile, nextFileName, isIntNum, - describe, it, expect, + fileIO, FILE_CONTENT, prepareFile, nextFileName, isIntNum, describe, it, expect, } from '../Common'; export default function fileIOWrite() { @@ -38,11 +37,10 @@ export default function fileIOWrite() { try { let file = fileIO.openSync(fpath, fileIO.OpenMode.WRITE_ONLY); expect(isIntNum(file.fd)).assertTrue(); - expect( - fileIO.writeSync(file.fd, FILE_CONTENT) - == FILE_CONTENT.length).assertTrue(); - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); + let bytesWritten = fileIO.writeSync(file.fd, FILE_CONTENT); + expect(bytesWritten == FILE_CONTENT.length).assertTrue(); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); } catch (e) { console.log('fileIO_test_write_sync_000 has failed for ' + e.message + ', code: ' + e.code); expect(false).assertTrue(); @@ -56,7 +54,7 @@ export default function fileIOWrite() { * Open the file in write-only mode, writing a string with encoding = 'utf-8'. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_test_write_sync_001', 0, async function () { @@ -66,13 +64,12 @@ export default function fileIOWrite() { try { let file = fileIO.openSync(fpath, fileIO.OpenMode.WRITE_ONLY); expect(isIntNum(file.fd)).assertTrue(); - expect( - fileIO.writeSync(file.fd, FILE_CONTENT, { - encoding: 'utf-8', - }) - == FILE_CONTENT.length).assertTrue(); - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); + let bytesWritten = fileIO.writeSync(file.fd, FILE_CONTENT, { + encoding: 'utf-8', + }) + expect(bytesWritten == FILE_CONTENT.length).assertTrue(); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); } catch (e) { console.log('fileIO_test_write_sync_001 has failed for ' + e.message + ', code: ' + e.code); expect(false).assertTrue(); @@ -86,7 +83,7 @@ export default function fileIOWrite() { * Open the file in write-only mode, writing a string from offset(position) = 1. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_test_write_sync_002', 0, async function () { @@ -96,13 +93,12 @@ export default function fileIOWrite() { try { let file = fileIO.openSync(fpath, fileIO.OpenMode.WRITE_ONLY); expect(isIntNum(file.fd)).assertTrue(); - expect( - fileIO.writeSync(file.fd, FILE_CONTENT, { - offset: 1, - }) - == FILE_CONTENT.length).assertTrue(); - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); + let bytesWritten = fileIO.writeSync(file.fd, FILE_CONTENT, { + offset: 1, + }); + expect(bytesWritten == FILE_CONTENT.length).assertTrue(); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); } catch (e) { console.log('fileIO_test_write_sync_002 has failed for ' + e.message + ', code: ' + e.code); expect(false).assertTrue(); @@ -116,7 +112,7 @@ export default function fileIOWrite() { * Open the file in write-only mode, writing a string of length = 1. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_test_write_sync_003', 0, async function () { @@ -126,13 +122,12 @@ export default function fileIOWrite() { try { let file = fileIO.openSync(fpath, fileIO.OpenMode.WRITE_ONLY); expect(isIntNum(file.fd)).assertTrue(); - expect( - fileIO.writeSync(file.fd, FILE_CONTENT, { - length: 1, - }) - == 1).assertTrue(); - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); + let bytesWritten = fileIO.writeSync(file.fd, FILE_CONTENT, { + length: 1, + }); + expect(bytesWritten == 1).assertTrue(); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); } catch (e) { console.log('fileIO_test_write_sync_003 has failed for ' + e.message + ', code: ' + e.code); expect(false).assertTrue(); @@ -146,25 +141,24 @@ export default function fileIOWrite() { * Open the file in write-only mode, writing a string of length = 1 and offset(position) = 1. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ - it('fileio_test_write_sync_004', 0, async function () { - let fpath = await nextFileName('fileio_test_write_sync_004'); + it('fileIO_test_write_sync_004', 0, async function () { + let fpath = await nextFileName('fileIO_test_write_sync_004'); expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); try { let file = fileIO.openSync(fpath, fileIO.OpenMode.WRITE_ONLY); expect(isIntNum(file.fd)).assertTrue(); - expect( - fileIO.writeSync(file.fd, FILE_CONTENT, { - offset: 1, - length: 1, - }) - == 1).assertTrue(); - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); - } catch (e) { - console.log('fileio_test_write_sync_004 has failed for ' + e.message + ', code: ' + e.code); + let bytesWritten = fileIO.writeSync(file.fd, FILE_CONTENT, { + offset: 1, + length: 1, + }); + expect(bytesWritten == 1).assertTrue(); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); + } catch (e) { + console.log('fileIO_test_write_sync_004 has failed for ' + e.message + ', code: ' + e.code); expect(false).assertTrue(); } }); @@ -176,7 +170,7 @@ export default function fileIOWrite() { * Open the file in write-only mode, writing a string of length = 1, offset(position) = 1, encoding = 'utf-8'. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_test_write_sync_005', 0, async function () { @@ -185,18 +179,17 @@ export default function fileIOWrite() { try { let file = fileIO.openSync(fpath, fileIO.OpenMode.WRITE_ONLY); expect(isIntNum(file.fd)).assertTrue(); - expect( - fileIO.writeSync(file.fd, FILE_CONTENT, { - offset: 1, - length: 5, - encoding: 'utf-8', - }) - == 5).assertTrue(); - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); + let bytesWritten = fileIO.writeSync(file.fd, FILE_CONTENT, { + offset: 1, + length: 5, + encoding: 'utf-8', + }); + expect(bytesWritten == 5).assertTrue(); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); } catch (e) { console.log('fileIO_test_write_sync_005 has failed for ' + e.message + ', code: ' + e.code); - expect(null).assertFail(); + expect(false).assertTrue(); } }); @@ -207,23 +200,23 @@ export default function fileIOWrite() { * Write with invalid 'length' option. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_test_write_sync_006', 0, async function () { let fpath = await nextFileName('fileIO_test_write_sync_006'); expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); let file = fileIO.openSync(fpath, fileIO.OpenMode.WRITE_ONLY); - + const invalidLength = 9999; + try { expect(isIntNum(file.fd)).assertTrue(); - const invalidLength = 9999; fileIO.writeSync(file.fd, FILE_CONTENT, { length: invalidLength }) expect(false).assertTrue(); } catch (e) { - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); - console.info('fileIO_test_write_sync_006 has failed for ' + e.message + ', code: ' + e.code); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); + console.log('fileIO_test_write_sync_006 has failed for ' + e.message + ', code: ' + e.code); expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue(); } }); @@ -235,7 +228,7 @@ export default function fileIOWrite() { * Write with invalid fd parameters. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_test_write_sync_007', 0, function () { @@ -256,7 +249,7 @@ export default function fileIOWrite() { * Open the file in write-only mode, writing an ArrayBuffer(4096). * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_test_write_sync_008', 0, async function () { @@ -266,10 +259,10 @@ export default function fileIOWrite() { try { let file = fileIO.openSync(fpath, fileIO.OpenMode.WRITE_ONLY); expect(isIntNum(file.fd)).assertTrue(); - let writeNum = fileIO.writeSync(file.fd, new ArrayBuffer(4096)); - expect(writeNum == 4096).assertTrue(); - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); + let bytesWritten = fileIO.writeSync(file.fd, new ArrayBuffer(4096)); + expect(bytesWritten == 4096).assertTrue(); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); } catch (e) { console.log('fileIO_test_write_sync_008 has failed for ' + e.message + ', code: ' + e.code); expect(false).assertTrue(); @@ -283,23 +276,23 @@ export default function fileIOWrite() { * Write with invalid 'length' option. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_test_write_sync_009', 0, async function () { let fpath = await nextFileName('fileIO_test_write_sync_009'); expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); let file = fileIO.openSync(fpath, fileIO.OpenMode.WRITE_ONLY); - + const invalidLength = 4097; + try { expect(isIntNum(file.fd)).assertTrue(); - const invalidLength = 4097; fileIO.writeSync(file.fd, new ArrayBuffer(4096), { length: invalidLength }) expect(false).assertTrue(); } catch (e) { - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); - console.info('fileIO_test_write_sync_009 has failed for ' + e.message + ', code: ' + e.code); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); + console.log('fileIO_test_write_sync_009 has failed for ' + e.message + ', code: ' + e.code); expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue(); } }); @@ -311,23 +304,23 @@ export default function fileIOWrite() { * Write with invalid 'offset' option. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_test_write_sync_010', 0, async function () { let fpath = await nextFileName('fileIO_test_write_sync_010'); expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); let file = fileIO.openSync(fpath, fileIO.OpenMode.WRITE_ONLY); - + const invalidOffset = -1; + try { expect(isIntNum(file.fd)).assertTrue(); - const invalidOffset = -1; fileIO.writeSync(file.fd, FILE_CONTENT, { offset: invalidOffset }); expect(false).assertTrue(); } catch (e) { - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); - console.info('fileIO_test_write_sync_010 has failed for ' + e.message + ', code: ' + e.code); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); + console.log('fileIO_test_write_sync_010 has failed for ' + e.message + ', code: ' + e.code); expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue(); } }); @@ -349,10 +342,10 @@ export default function fileIOWrite() { try { let file = fileIO.openSync(fpath, fileIO.OpenMode.WRITE_ONLY); expect(isIntNum(file.fd)).assertTrue(); - let writeLen = await fileIO.write(file.fd, FILE_CONTENT); - expect(writeLen == FILE_CONTENT.length).assertTrue(); - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); + let bytesWritten = await fileIO.write(file.fd, FILE_CONTENT); + expect(bytesWritten == FILE_CONTENT.length).assertTrue(); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); done(); } catch (e) { console.log('fileIO_test_write_async_000 has failed for ' + e.message + ', code: ' + e.code); @@ -367,7 +360,7 @@ export default function fileIOWrite() { * Open the file in write-only mode, verifying the normal write function. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_test_write_async_001', 0, async function (done) { @@ -377,10 +370,10 @@ export default function fileIOWrite() { try { let file = fileIO.openSync(fpath, fileIO.OpenMode.WRITE_ONLY); expect(isIntNum(file.fd)).assertTrue(); - let writeLen = await fileIO.write(file.fd, FILE_CONTENT); - expect(writeLen == FILE_CONTENT.length).assertTrue(); - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); + let bytesWritten = await fileIO.write(file.fd, FILE_CONTENT); + expect(bytesWritten == FILE_CONTENT.length).assertTrue(); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); done(); } catch (e) { console.log('fileIO_test_write_async_001 has failed for ' + e.message + ', code: ' + e.code); @@ -395,7 +388,7 @@ export default function fileIOWrite() { * Open the file in read-only mode, verifying that it is not writable. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_test_write_async_002', 0, async function (done) { @@ -408,8 +401,8 @@ export default function fileIOWrite() { await fileIO.write(file.fd, FILE_CONTENT); expect(false).assertTrue(); } catch (e) { - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); console.log('fileIO_test_write_async_002 has failed for ' + e.message + ', code: ' + e.code); expect(e.code == 13900008 && e.message == 'Bad file descriptor').assertTrue(); done(); @@ -423,7 +416,7 @@ export default function fileIOWrite() { * Open the file in read-only mode, verifying that it is not writable. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_test_write_async_003', 0, async function (done) { @@ -435,9 +428,9 @@ export default function fileIOWrite() { expect(isIntNum(file.fd)).assertTrue(); fileIO.write(file.fd, FILE_CONTENT, (err) => { if(err) { - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); - console.log('fileIO_test_write_async_003 error package: {' + err.message + ', code: ' + err.code + '}'); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); + console.log('fileIO_test_write_async_003 error: {message: ' + err.message + ', code: ' + err.code + '}'); expect(err.code == 13900008 && err.message == 'Bad file descriptor').assertTrue(); done(); } @@ -455,7 +448,7 @@ export default function fileIOWrite() { * Open the file in write-only mode, writing a string of length = 3. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_test_write_async_004', 0, async function (done) { @@ -469,8 +462,8 @@ export default function fileIOWrite() { length: 3, }); expect(bytesWritten == 3).assertTrue(); - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); done(); } catch (e) { console.log('fileIO_test_write_async_004 has failed for ' + e.message + ', code: ' + e.code); @@ -485,7 +478,7 @@ export default function fileIOWrite() { * Open the file in write-only mode, writing a string of length = 3. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_test_write_async_005', 0, async function (done) { @@ -495,14 +488,16 @@ export default function fileIOWrite() { try { let file = fileIO.openSync(fpath, fileIO.OpenMode.WRITE_ONLY); expect(isIntNum(file.fd)).assertTrue(); - fileIO.write(file.fd, FILE_CONTENT, { length: 3 }, (err, bytesWritten) => { + fileIO.write(file.fd, FILE_CONTENT, { + length: 3, + }, (err, bytesWritten) => { if(err) { console.log('fileIO_test_write_async_005 err package: ' + JSON.stringify(err)); expect(false).assertTrue(); } expect(bytesWritten == 3).assertTrue(); - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); done(); }); } catch (e) { @@ -518,7 +513,7 @@ export default function fileIOWrite() { * Open the file in write-only mode, writing a string from offset(position) = 5. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_test_write_async_006', 0, async function (done) { @@ -528,12 +523,12 @@ export default function fileIOWrite() { try { let file = fileIO.openSync(fpath, fileIO.OpenMode.WRITE_ONLY); expect(isIntNum(file.fd)).assertTrue(); - let writeNum = await fileIO.write(file.fd, FILE_CONTENT, { + let bytesWritten = await fileIO.write(file.fd, FILE_CONTENT, { offset: 5, }); - expect(writeNum == FILE_CONTENT.length).assertTrue(); - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); + expect(bytesWritten == FILE_CONTENT.length).assertTrue(); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); done(); } catch (e) { console.log('fileIO_test_write_async_006 has failed for ' + e.message + ', code: ' + e.code); @@ -548,7 +543,7 @@ export default function fileIOWrite() { * Open the file in write-only mode, writing a string from offset(position) = 5. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_test_write_async_007', 0, async function (done) { @@ -559,17 +554,17 @@ export default function fileIOWrite() { let file = fileIO.openSync(fpath, fileIO.OpenMode.WRITE_ONLY); expect(isIntNum(file.fd)).assertTrue(); fileIO.write(file.fd, FILE_CONTENT, { - offset: 5 - }, (err, bytesWritten) => { - if(err) { - console.log('fileIO_test_write_async_007 err package: ' + JSON.stringify(err)); - expect(false).assertTrue(); - } - expect(bytesWritten == FILE_CONTENT.length).assertTrue(); - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); - done(); - }); + offset: 5, + }, (err, bytesWritten) => { + if(err) { + console.log('fileIO_test_write_async_007 err package: ' + JSON.stringify(err)); + expect(false).assertTrue(); + } + expect(bytesWritten == FILE_CONTENT.length).assertTrue(); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); + done(); + }); } catch (e) { console.log('fileIO_test_write_async_007 has failed for ' + e.message + ', code: ' + e.code); expect(false).assertTrue(); @@ -583,7 +578,7 @@ export default function fileIOWrite() { * Open the file in write-only mode, writing a string of with length = 3 and offset = 5. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_test_write_async_008', 0, async function (done) { @@ -593,13 +588,13 @@ export default function fileIOWrite() { try { let file = fileIO.openSync(fpath, fileIO.OpenMode.WRITE_ONLY); expect(isIntNum(file.fd)).assertTrue(); - let writeNum = await fileIO.write(file.fd, FILE_CONTENT, { + let bytesWritten = await fileIO.write(file.fd, FILE_CONTENT, { length: 3, offset: 5, }); - expect(writeNum == 3).assertTrue(); - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); + expect(bytesWritten == 3).assertTrue(); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); done(); } catch (e) { console.log('fileIO_test_write_async_008 has failed for ' + e.message + ', code: ' + e.code); @@ -614,7 +609,7 @@ export default function fileIOWrite() { * Open the file in write-only mode, writing a string of with length = 3 and offset = 5. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_test_write_async_009', 0, async function (done) { @@ -625,18 +620,18 @@ export default function fileIOWrite() { let file = fileIO.openSync(fpath, fileIO.OpenMode.WRITE_ONLY); expect(isIntNum(file.fd)).assertTrue(); fileIO.write(file.fd, FILE_CONTENT, { - length: 3, - offset: 5, - }, (err, writeNum) => { - if(err) { - console.log('fileIO_test_write_async_009 err package: ' + JSON.stringify(err)); - expect(false).assertTrue(); - } - expect(writeNum == 3).assertTrue(); - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); - done(); - }); + length: 3, + offset: 5, + }, (err, bytesWritten) => { + if(err) { + console.log('fileIO_test_write_async_009 err package: ' + JSON.stringify(err)); + expect(false).assertTrue(); + } + expect(bytesWritten == 3).assertTrue(); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); + done(); + }); } catch (e) { console.log('fileIO_test_write_async_009 has failed for ' + e.message + ', code: ' + e.code); expect(false).assertTrue(); @@ -650,7 +645,7 @@ export default function fileIOWrite() { * Open the file in write-only mode, writing a string of with length = 3, offset = 5 and encoding = 'utf-8'. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_test_write_async_010', 0, async function (done) { @@ -660,14 +655,14 @@ export default function fileIOWrite() { try { let file = fileIO.openSync(fpath, fileIO.OpenMode.WRITE_ONLY); expect(isIntNum(file.fd)).assertTrue(); - let writeNum = await fileIO.write(file.fd, FILE_CONTENT, { + let bytesWritten = await fileIO.write(file.fd, FILE_CONTENT, { length: 4, offset: 5, encoding: 'utf-8', }); - expect(writeNum == 4).assertTrue(); - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); + expect(bytesWritten == 4).assertTrue(); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); done(); } catch (e) { console.log('fileIO_test_write_async_010 has failed for ' + e.message + ', code: ' + e.code); @@ -682,7 +677,7 @@ export default function fileIOWrite() { * Open the file in write-only mode, writing a string of with length = 3, offset = 5 and encoding = 'utf-8'. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_test_write_async_011', 0, async function (done) { @@ -693,20 +688,19 @@ export default function fileIOWrite() { let file = fileIO.openSync(fpath, fileIO.OpenMode.WRITE_ONLY); expect(isIntNum(file.fd)).assertTrue(); fileIO.write(file.fd, FILE_CONTENT, { - length: 5, - offset: 5, - encoding: 'utf-8', - }, (err, bytesWritten) => { - if(err) { - console.log('fileIO_test_write_async_011 err package: ' + JSON.stringify(err)); - expect(false).assertTrue(); - } - expect(bytesWritten == 5).assertTrue(); - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); - done(); + length: 5, + offset: 5, + encoding: 'utf-8', + }, (err, bytesWritten) => { + if(err) { + console.log('fileIO_test_write_async_011 err package: ' + JSON.stringify(err)); + expect(false).assertTrue(); } - ); + expect(bytesWritten == 5).assertTrue(); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); + done(); + }); } catch (e) { console.log('fileIO_test_write_async_011 has failed for ' + e.message + ', code: ' + e.code); expect(false).assertTrue(); @@ -720,7 +714,7 @@ export default function fileIOWrite() { * Open the file in write-only mode, writing an ArrayBuffer(4096). * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_test_write_async_012', 0, async function (done) { @@ -732,8 +726,8 @@ export default function fileIOWrite() { expect(isIntNum(file.fd)).assertTrue(); let bytesWritten = await fileIO.write(file.fd, new ArrayBuffer(4096)); expect(bytesWritten == 4096).assertTrue(); - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); done(); } catch (e) { console.log('fileIO_test_write_async_012 has failed for ' + e.message + ', code: ' + e.code); @@ -748,7 +742,7 @@ export default function fileIOWrite() { * Open the file in write-only mode, writing an ArrayBuffer(4096). * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_test_write_async_013', 0, async function (done) { @@ -764,8 +758,8 @@ export default function fileIOWrite() { expect(false).assertTrue(); } expect(bytesWritten == 4096).assertTrue(); - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); done(); }); } catch (e) { @@ -781,7 +775,7 @@ export default function fileIOWrite() { * Open the file in write-only mode, writing a string with empty option parameters. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_test_write_async_014', 0, async function (done) { @@ -793,8 +787,8 @@ export default function fileIOWrite() { expect(isIntNum(file.fd)).assertTrue(); let bytesWritten = await fileIO.write(file.fd, FILE_CONTENT, {}); expect(bytesWritten == FILE_CONTENT.length).assertTrue(); - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); done(); } catch (e) { console.log('fileIO_test_write_async_014 has failed for ' + e.message + ', code: ' + e.code); @@ -809,7 +803,7 @@ export default function fileIOWrite() { * Open the file in write-only mode, writing a string with empty option parameters. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_test_write_async_015', 0, async function (done) { @@ -820,16 +814,16 @@ export default function fileIOWrite() { let file = fileIO.openSync(fpath, fileIO.OpenMode.WRITE_ONLY); expect(isIntNum(file.fd)).assertTrue(); fileIO.write(file.fd, new ArrayBuffer(4096), { - }, (err, bytesWritten) => { - if(err) { - console.log('fileIO_test_write_async_015 err package ' + JSON.stringify(err)); - expect(false).assertTrue(); - } - expect(bytesWritten == 4096).assertTrue(); - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); - done(); - }); + }, (err, bytesWritten) => { + if(err) { + console.log('fileIO_test_write_async_015 err package ' + JSON.stringify(err)); + expect(false).assertTrue(); + } + expect(bytesWritten == 4096).assertTrue(); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); + done(); + }); } catch (e) { console.log('fileIO_test_write_async_015 has failed for ' + e.message + ', code: ' + e.code); expect(false).assertTrue(); @@ -843,7 +837,7 @@ export default function fileIOWrite() { * Write with invalid fd parameters. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_test_write_async_016', 0, async function (done) { @@ -854,7 +848,7 @@ export default function fileIOWrite() { await fileIO.write(-1, FILE_CONTENT); expect(false).assertTrue(); } catch (e) { - fileio.unlinkSync(fpath); + fileIO.unlinkSync(fpath); console.log('fileIO_test_write_async_016 has failed for ' + e.message + ', code: ' + e.code); expect(e.code == 13900008 && e.message == 'Bad file descriptor').assertTrue(); done(); @@ -868,7 +862,7 @@ export default function fileIOWrite() { * Write with invalid fd parameters. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_test_write_async_017', 0, async function (done) { @@ -878,8 +872,8 @@ export default function fileIOWrite() { try { fileIO.write(-1, FILE_CONTENT, (err) => { if(err) { - fileio.unlinkSync(fpath); - console.log('fileIO_test_open_async_020 error package: {' + err.message + ', code: ' + err.code + '}'); + fileIO.unlinkSync(fpath); + console.log('fileIO_test_open_async_020 error: {message: ' + err.message + ', code: ' + err.code + '}'); expect(err.code == 13900008 && err.message == 'Bad file descriptor').assertTrue(); done(); } @@ -896,26 +890,26 @@ export default function fileIOWrite() { * Write with invalid length parameters. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_test_write_async_018', 0, async function (done) { let fpath = await nextFileName('fileIO_test_write_async_018'); expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); let file = fileIO.openSync(fpath, fileIO.OpenMode.WRITE_ONLY); - + const invalidLength = 9999; + try { expect(isIntNum(file.fd)).assertTrue(); - const invalidLength = 9999; fileIO.write(file.fd, FILE_CONTENT, { - length: invalidLength, - }, () => { - expect(false).assertTrue(); - }) + length: invalidLength, + }, (err) => { + expect(false).assertTrue(); + }); } catch (e) { - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); - console.info('fileIO_test_write_async_018 has failed for ' + e.message + ', code: ' + e.code); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); + console.log('fileIO_test_write_async_018 has failed for ' + e.message + ', code: ' + e.code); expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue(); done(); } @@ -928,26 +922,26 @@ export default function fileIOWrite() { * Write with invalid length parameters. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_test_write_async_019', 0, async function (done) { let fpath = await nextFileName('fileIO_test_write_async_019'); expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); let file = fileIO.openSync(fpath, fileIO.OpenMode.WRITE_ONLY); - + const invalidLength = 4097; + try { expect(isIntNum(file.fd)).assertTrue(); - const invalidLength = 4097; fileIO.write(file.fd, new ArrayBuffer(4096), { length: invalidLength, - }, () => { - expect(false).assertTrue(); - }) + }, (err) => { + expect(false).assertTrue(); + }); } catch (e) { - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); - console.info('fileIO_test_write_async_019 has failed for ' + e.message + ', code: ' + e.code); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); + console.log('fileIO_test_write_async_019 has failed for ' + e.message + ', code: ' + e.code); expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue(); done(); } @@ -960,26 +954,26 @@ export default function fileIOWrite() { * Write with invalid length parameters. * @tc.size MEDIUM * @tc.type Functoin - * @tc.level Level 0 + * @tc.level Level 3 * @tc.require */ it('fileIO_test_write_async_020', 0, async function (done) { let fpath = await nextFileName('fileIO_test_write_async_020'); expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); let file = fileIO.openSync(fpath, fileIO.OpenMode.WRITE_ONLY); - + const invalidOffset = -1; + try { expect(isIntNum(file.fd)).assertTrue(); - const invalidOffset = -1; fileIO.write(file.fd, FILE_CONTENT, { - offset: invalidOffset, - }, () => { - expect(false).assertTrue(); - }) + offset: invalidOffset, + }, (err) => { + expect(false).assertTrue(); + }); } catch (e) { - fileio.closeSync(file.fd); - fileio.unlinkSync(fpath); - console.info('fileIO_test_write_async_020 has failed for ' + e.message + ', code: ' + e.code); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); + console.log('fileIO_test_write_async_020 has failed for ' + e.message + ', code: ' + e.code); expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue(); done(); } -- GitLab