From 7349fae1f6ad79432a87c86d69ae5be5a2814b33 Mon Sep 17 00:00:00 2001 From: gsl_1234 Date: Fri, 14 Oct 2022 10:19:57 +0800 Subject: [PATCH] =?UTF-8?q?fileIO=E6=A8=A1=E5=9D=97open=E3=80=81read?= =?UTF-8?q?=E3=80=81stat=E3=80=81truncate=E3=80=81write=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E7=94=A8=E4=BE=8B=E5=A2=9E=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: gsl_1234 --- .../src/main/js/test/Common.js | 4 +- .../src/main/js/test/List.test.js | 12 +- .../module_fileio/members/open_file.test.js | 490 ++++ .../test/module_fileio/members/readV9.test.js | 374 +++ .../test/module_fileio/members/statV9.test.js | 2021 +++++++++++++++++ .../module_fileio/members/truncateV9.test.js | 318 +++ .../module_fileio/members/writeV9.test.js | 451 ++++ 7 files changed, 3668 insertions(+), 2 deletions(-) create mode 100644 storage/storagefileiojstest/src/main/js/test/module_fileio/members/open_file.test.js create mode 100644 storage/storagefileiojstest/src/main/js/test/module_fileio/members/readV9.test.js create mode 100644 storage/storagefileiojstest/src/main/js/test/module_fileio/members/statV9.test.js create mode 100644 storage/storagefileiojstest/src/main/js/test/module_fileio/members/truncateV9.test.js create mode 100644 storage/storagefileiojstest/src/main/js/test/module_fileio/members/writeV9.test.js diff --git a/storage/storagefileiojstest/src/main/js/test/Common.js b/storage/storagefileiojstest/src/main/js/test/Common.js index ab53cac8a..da73fc2eb 100644 --- a/storage/storagefileiojstest/src/main/js/test/Common.js +++ b/storage/storagefileiojstest/src/main/js/test/Common.js @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021 Huawei Device Co., Ltd. + * Copyright (C) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the 'License'); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -14,6 +14,7 @@ */ import fileio from '@ohos.fileio'; +import fileIO from '@ohos.file.fs'; import featureAbility from '@ohos.ability.featureAbility'; export const FILE_CONTENT = 'hello world'; @@ -126,6 +127,7 @@ function isInclude(error, message) { export { fileio, + fileIO, isIntNum, isString, isBoolean, diff --git a/storage/storagefileiojstest/src/main/js/test/List.test.js b/storage/storagefileiojstest/src/main/js/test/List.test.js index c4ede6bac..ed70db4bf 100644 --- a/storage/storagefileiojstest/src/main/js/test/List.test.js +++ b/storage/storagefileiojstest/src/main/js/test/List.test.js @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021 Huawei Device Co., Ltd. + * Copyright (C) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -65,6 +65,11 @@ import fileioSymlink from './module_fileio/members/symlink.test.js' import fileioTruncate from './module_fileio/members/truncate.test.js' import fileioUnlink from './module_fileio/members/unlink.test.js' import fileioWrite from './module_fileio/members/write.test.js' +import fileIOOpenFile from './module_fileio/members/open_file.test.js' +import fileIORead from './module_fileio/members/readV9.test.js' +import fileIOStat from './module_fileio/members/statV9.test.js' +import fileIOTruncate from './module_fileio/members/truncateV9.test.js' +import fileIOWrite from './module_fileio/members/writeV9.test.js' export default function testsuite() { fileIOTest() fileIOTestDir() @@ -118,4 +123,9 @@ export default function testsuite() { fileioTruncate() fileioUnlink() fileioWrite() + fileIOOpenFile() + fileIORead() + fileIOStat() + fileIOTruncate() + fileIOWrite() } diff --git a/storage/storagefileiojstest/src/main/js/test/module_fileio/members/open_file.test.js b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/open_file.test.js new file mode 100644 index 000000000..3d993beb3 --- /dev/null +++ b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/open_file.test.js @@ -0,0 +1,490 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the 'License'); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an 'AS IS' BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// import fileIO from '@ohos.file.fs'; +import { + fileio, fileIO, FILE_CONTENT, prepareFile, nextFileName, isIntNum, + describe, it, expect, + } from '../../Common'; + + export default function fileIOOpenFile() { + describe('fileIO_fs_open_file', function () { + + /** + * @tc.number SUB_DF_FILEIO_OPENIO_SYNC_0000 + * @tc.name fileIO_open_sync_000 + * @tc.desc Test openSync() interfaces. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_open_sync_000', 0, async function (done) { + let fpath = await nextFileName('fileIO_open_sync_000'); + + try { + let file = fileIO.openSync(fpath, 0o102); + console.info('fileIO_open_sync_000, fd: ' + file.fd); + expect(isIntNum(file.fd)).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileIO_open_sync_000 has failed for ' + e.message + ', code: ' + e.code); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_OPENIO_SYNC_0010 + * @tc.name fileIO_open_sync_001 + * @tc.desc Test openSync() interfaces. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_open_sync_001', 0, function () { + try { + fileIO.openSync(); + expect(null).assertFail(); + } catch (e) { + console.log('fileIO_open_sync_001 has failed for ' + e.message + ', code: ' + e.code); + expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue; + } + }); + + /** + * @tc.number SUB_DF_FILEIO_OPENIO_SYNC_0020 + * @tc.name fileIO_open_sync_002 + * @tc.desc Test openSync() interfaces. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_open_sync_002', 0, async function (done) { + let fpath = await nextFileName('fileIO_open_sync_002'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let file = fileIO.openSync(fpath, 0o202); + console.info('fileIO_open_sync_002, fd: ' + file.fd); + expect(isIntNum(file.fd)).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileIO_open_sync_002 has failed for ' + e.message + ', code: ' + e.code); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_OPENIO_SYNC_0030 + * @tc.name fileIO_open_sync_003 + * @tc.desc Test openSync() interfaces. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_open_sync_003', 0, async function (done) { + let fpath = await nextFileName('fileIO_open_sync_003'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let file = fileIO.openSync(fpath, 0o1002); + console.info('fileIO_open_sync_003, fd: ' + file.fd); + expect(isIntNum(file.fd)).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileIO_open_sync_003 has failed for ' + e.message + ', code: ' + e.code); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_OPENIO_SYNC_0040 + * @tc.name fileIO_open_sync_004 + * @tc.desc Test openSync() interfaces. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_open_sync_004', 0, async function (done) { + let fpath = await nextFileName('fileIO_open_sync_004'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let file = fileIO.openSync(fpath, 0o2002); + console.info('fileIO_open_sync_004, fd: ' + file.fd); + expect(isIntNum(file.fd)).assertTrue(); + let length = 100; + let num = fileIO.writeSync(file.fd, new ArrayBuffer(length)); + expect(num == length).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileIO_open_sync_004 has failed for ' + e.message + ', code: ' + e.code); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_OPENIO_SYNC_0050 + * @tc.name fileIO_open_sync_005 + * @tc.desc Test openSync() interfaces. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_open_sync_005', 0, async function (done) { + let fpath = await nextFileName('fileIO_open_sync_005'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let file = fileIO.openSync(fpath, 0o4002); + console.info('fileIO_open_sync_005, fd: ' + file.fd); + expect(isIntNum(file.fd)).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileIO_open_sync_005 has failed for ' + e.message + ', code: ' + e.code); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_OPENIO_SYNC_0060 + * @tc.name fileIO_open_sync_006 + * @tc.desc Test openSync() interfaces. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_open_sync_006', 0, async function (done) { + let dpath = await nextFileName('fileIO_open_sync_006'); + fileio.mkdirSync(dpath); + + try { + let file = fileIO.openSync(dpath, 0o200000); + console.info('fileIO_open_sync_006, fd: ' + file.fd); + fileio.rmdirSync(dpath); + expect(isIntNum(file.fd)).assertTrue(); + done(); + } catch (e) { + console.log('fileIO_open_sync_006 has failed for ' + e.message + ', code: ' + e.code); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_OPENIO_SYNC_0070 + * @tc.name fileIO_open_sync_007 + * @tc.desc Test openSync() interfaces. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_open_sync_007', 0, async function (done) { + let fpath = await nextFileName('fileIO_open_sync_007'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let file = fileIO.openSync(fpath, 0o400002); + console.info('fileIO_open_sync_007, fd: ' + file.fd); + expect(isIntNum(file.fd)).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileIO_open_sync_007 has failed for ' + e.message + ', code: ' + e.code); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_OPENIO_SYNC_0080 + * @tc.name fileIO_open_sync_008 + * @tc.desc Test openSync() interfaces. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_open_sync_008', 0, async function (done) { + let fpath = await nextFileName('fileIO_open_sync_008'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let file = fileIO.openSync(fpath, 0o4010002); + console.info('fileIO_open_sync_008, fd: ' + file.fd); + expect(isIntNum(file.fd)).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileIO_open_sync_008 has failed for ' + e.message + ', code: ' + e.code); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_OPEN_FILE_ASYNC_0000 + * @tc.name fileIO_open_async_000 + * @tc.desc Test openAsync() interfaces. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_open_async_000', 0, async function (done) { + let fpath = await nextFileName('fileIO_open_async_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let file = await fileIO.open(fpath, 0o102); + console.info('fileIO_open_async_000, fd: ' + file.fd); + expect(isIntNum(file.fd)).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileIO_open_async_000 has failed for ' + e.message + ', code: ' + e.code); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_OPENIO_ASYNC_0010 + * @tc.name fileIO_open_async_001 + * @tc.desc Test openAsync() interfaces. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_open_async_001', 0, function () { + try { + fileIO.openAsync(); + expect(null).assertFail(); + } catch (e) { + console.log('fileIO_open_async_001 has failed for ' + e.message + ', code: ' + e.code); + expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue; + } + }); + /** + * @tc.number SUB_DF_FILEIO_OPEN_FILE_ASYNC_0020 + * @tc.name fileIO_open_async_002 + * @tc.desc Test openAsync() interfaces. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_open_async_002', 0, async function (done) { + let fpath = await nextFileName('fileIO_open_async_002'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let file = await fileIO.open(fpath, 0o202); + console.info('fileIO_open_async_002, fd: ' + file.fd); + expect(isIntNum(file.fd)).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileIO_open_async_002 has failed for ' + e.message + ', code: ' + e.code); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_OPEN_FILE_ASYNC_0030 + * @tc.name fileIO_open_async_003 + * @tc.desc Test openAsync() interfaces. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_open_async_003', 0, async function (done) { + let fpath = await nextFileName('fileIO_open_async_003'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let file = await fileIO.open(fpath, 0o1002); + console.info('fileIO_open_async_003, fd: ' + file.fd); + expect(isIntNum(file.fd)).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileIO_open_async_003 has failed for ' + e.message + ', code: ' + e.code); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_OPEN_FILE_ASYNC_0040 + * @tc.name fileIO_open_async_004 + * @tc.desc Test openAsync() interfaces. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_open_async_004', 0, async function (done) { + let fpath = await nextFileName('fileIO_open_async_004'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let file = await fileIO.open(fpath, 0o2002); + console.info('fileIO_open_async_004, fd: ' + file.fd); + expect(isIntNum(file.fd)).assertTrue(); + let length = 100; + let num = fileIO.writeSync(file.fd,new ArrayBuffer(length)); + expect(num == length).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileIO_open_async_004 has failed for ' + e.message + ', code: ' + e.code); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_OPEN_ASYNC_0050 + * @tc.name fileIO_open_async_005 + * @tc.desc Test openAsync() interfaces. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_open_async_005', 0, async function (done) { + let fpath = await nextFileName('fileIO_open_async_005'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let file = await fileIO.open(fpath, 0o4002); + console.info('fileIO_open_async_005, fd: ' + file.fd); + expect(isIntNum(file.fd)).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileIO_open_async_005 has failed for ' + e.message + ', code: ' + e.code); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_OPEN_FILE_ASYNC_0060 + * @tc.name fileIO_open_async_006 + * @tc.desc Test openAsync() interfaces. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_open_async_006', 0, async function (done) { + let dpath = await nextFileName('fileIO_open_async_006'); + fileio.mkdirSync(dpath); + + try { + let file = await fileIO.open(dpath, 0o200000); + console.info('fileIO_open_async_006, fd: ' + file.fd); + fileio.rmdirSync(dpath); + expect(isIntNum(file.fd)).assertTrue(); + done(); + } catch (e) { + console.log('fileIO_open_async_006 has failed for ' + e.message + ', code: ' + e.code); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_OPEN_FILE_ASYNC_0070 + * @tc.name fileIO_open_async_007 + * @tc.desc Test openAsync() interfaces. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_open_async_007', 0, async function (done) { + let fpath = await nextFileName('fileIO_open_async_007'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let file = await fileIO.open(fpath, 0o400002); + console.info('fileIO_open_async_007, fd: ' + file.fd); + expect(isIntNum(file.fd)).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileIO_open_async_007 has failed for ' + e.message + ', code: ' + e.code); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_OPEN_FILE_ASYNC_0080 + * @tc.name fileIO_open_async_007 + * @tc.desc Test openAsync() interfaces. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_open_async_008', 0, async function (done) { + let fpath = await nextFileName('fileIO_open_async_008'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let file = await fileIO.open(fpath, 0o4010002); + console.info('fileIO_open_async_008, fd: ' + file.fd); + expect(isIntNum(file.fd)).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileIO_open_async_008 has failed for ' + e.message + ', code: ' + e.code); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_OPENIO_ASYNC_0090 + * @tc.name fileIO_open_async_009 + * @tc.desc Test openAsync() interfaces. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_open_async_009', 0, async function (done) { + let fpath = await nextFileName('fileIO_open_async_009'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + fileIO.open(fpath, 0o102, function (err,file) { + console.info('fileIO_open_async_009, fd: ' + file.fd); + expect(isIntNum(file.fd)).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + }); + } catch (e) { + console.log('fileIO_open_async_009 has failed for ' + e.message + ', code: ' + e.code); + expect(null).assertFail(); + } + }); +}); +} \ No newline at end of file diff --git a/storage/storagefileiojstest/src/main/js/test/module_fileio/members/readV9.test.js b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/readV9.test.js new file mode 100644 index 000000000..45030b30d --- /dev/null +++ b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/readV9.test.js @@ -0,0 +1,374 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the 'License'); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an 'AS IS' BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// import fileIO from '@ohos.file.fs'; +import { + fileio, fileIO, FILE_CONTENT, prepareFile, nextFileName, isIntNum, + describe, it, expect, +} from '../../Common'; + + export default function fileIORead() { + describe('fileIO_fs_read', function () { + + /** + * @tc.number SUB_DF_FILEIO_READ_SYNC_0000 + * @tc.name fileIO_test_read_sync_000 + * @tc.desc Test readSync() interfaces. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_test_read_sync_000', 0, async function () { + let fpath = await nextFileName('fileIO_test_read_sync_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath, 0o2); + expect(isIntNum(fd)).assertTrue(); + let len = fileIO.readSync(fd, new ArrayBuffer(4096)); + expect(len == FILE_CONTENT.length).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileIO_test_read_sync_000 has failed for ' + e.message + ', code: ' + e.code); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_READ_SYNC_0010 + * @tc.name fileIO_test_read_sync_001 + * @tc.desc Test readSync() interfaces. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_test_read_sync_001', 0, async function () { + let fpath = await nextFileName('fileIO_test_read_sync_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath, 0o2); + expect(isIntNum(fd)).assertTrue(); + let len = fileIO.readSync(fd, new ArrayBuffer(4096), { + length: 1, + }); + expect(len == 1).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileIO_test_read_sync_001 has failed for ' + e.message + ', code: ' + e.code); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_READ_SYNC_0020 + * @tc.name fileIO_test_read_sync_002 + * @tc.desc Test readSync() interfaces. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_test_read_sync_002', 0, async function () { + let fpath = await nextFileName('fileIO_test_read_sync_002'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath, 0o2); + expect(isIntNum(fd)).assertTrue(); + let len = fileIO.readSync(fd, new ArrayBuffer(4096), { + offset: 1, + }); + expect(len == FILE_CONTENT.length - 1).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileIO_test_read_sync_002 has failed for ' + e.message + ', code: ' + e.code); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_READ_SYNC_0030 + * @tc.name fileIO_test_read_sync_003 + * @tc.desc Test readSync() interfaces. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_test_read_sync_003', 0, async function () { + let fd; + const invalidLength = 9999; + let fpath = await nextFileName('fileIO_test_read_sync_003'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + fd = fileio.openSync(fpath, 0o2, 0o664); + expect(isIntNum(fd)).assertTrue(); + fileIO.readSync(fd, new ArrayBuffer(4096), {length: invalidLength}); + expect(null).assertFail(); + } catch (e) { + console.log('fileIO_test_read_sync_003 has failed for ' + e.message + ', code: ' + e.code); + expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_READ_SYNC_0040 + * @tc.name fileIO_test_read_sync_004 + * @tc.desc Test readSync() interfaces. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_test_read_sync_004', 0, async function () { + let fpath = await nextFileName('fileIO_test_read_sync_004'); + + try { + fileIO.readSync(-1, new ArrayBuffer(4096)); + expect(null).assertFail(); + } catch (e) { + console.log('fileIO_test_read_sync_004 has failed for ' + e.message + ', code: ' + e.code); + expect(e.code == 13900008 && e.message == 'Bad file descriptor').assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_READ_SYNC_0050 + * @tc.name fileIO_test_read_sync_005 + * @tc.desc Test readSync() interfaces. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_test_read_sync_005', 0, async function () { + let fpath = await nextFileName('fileIO_test_read_sync_005'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath, 0o2); + expect(isIntNum(fd)).assertTrue(); + let invalidPos = FILE_CONTENT.length + 1; + let len = fileIO.readSync(fd, new ArrayBuffer(4096), { + offset: invalidPos, + }); + expect(len == 0).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileIO_test_read_sync_005 has failed for ' + e.message + ', code: ' + e.code); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_READ_ASYNC_0000 + * @tc.name fileIO_test_read_async_000 + * @tc.desc Test readAsync() interfaces. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_test_read_async_000', 0, async function (done) { + let fpath = await nextFileName('fileIO_test_read_async_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath, 0o2); + expect(isIntNum(fd)).assertTrue(); + let res = await fileIO.read(fd, new ArrayBuffer(4096)); + expect(res == FILE_CONTENT.length).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileIO_test_read_async_000 has failed for ' + e.message + ', code: ' + e.code); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_READ_ASYNC_0010 + * @tc.name fileIO_test_read_async_001 + * @tc.desc Test readAsync() interfaces. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_test_read_async_001', 0, async function (done) { + let fpath = await nextFileName('fileIO_test_read_async_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath, 0o2); + expect(isIntNum(fd)).assertTrue(); + fileIO.read(fd, new ArrayBuffer(4096), async function (err, readlen) { + expect(readlen == FILE_CONTENT.length).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + }); + } catch (e) { + console.log('fileIO_test_read_async_001 has failed for ' + e.message + ', code: ' + e.code); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_READ_ASYNC_0020 + * @tc.name fileIO_test_read_async_002 + * @tc.desc Test readAsync() interfaces. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_test_read_async_002', 0, async function (done) { + let fpath = await nextFileName('fileIO_test_read_async_002'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath); + expect(isIntNum(fd)).assertTrue(); + let readlen = await fileIO.read(fd, new ArrayBuffer(4096)); + expect(readlen == FILE_CONTENT.length).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileIO_test_read_async_002 has failed for ' + e.message + ', code: ' + e.code); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_READ_ASYNC_0030 + * @tc.name fileIO_test_read_async_003 + * @tc.desc Test readAsync() interfaces. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_test_read_async_003', 0, async function (done) { + let fpath = await nextFileName('fileIO_test_read_async_003'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath); + expect(isIntNum(fd)).assertTrue(); + let readlen = await fileIO.read(fd, new ArrayBuffer(4096), { + offset: 1, + }); + expect(readlen == FILE_CONTENT.length - 1).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileIO_test_read_async_003 has failed for ' + e.message + ', code: ' + e.code); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_READ_ASYNC_0040 + * @tc.name fileIO_test_read_async_004 + * @tc.desc Test readAsync() interface. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_test_read_async_004', 0, async function (done) { + let fpath = await nextFileName('fileIO_test_read_async_004'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath); + expect(isIntNum(fd)).assertTrue(); + let readlen = await fileIO.read(fd, new ArrayBuffer(4096), { + length: 3, + }); + expect(readlen == 3).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileIO_test_read_async_004 has failed for ' + e.message + ', code: ' + e.code); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_READ_ASYNC_0050 + * @tc.name fileIO_test_read_async_005 + * @tc.desc Test readAsync() interfaces. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_test_read_async_005', 0, async function (done) { + let fpath = await nextFileName('fileIO_test_read_async_005'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath, 0o2); + expect(isIntNum(fd)).assertTrue(); + let len = await fileIO.read(fd, new ArrayBuffer(4096), { + offset: FILE_CONTENT.length + 10, + }); + expect(isIntNum(len)).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileIO_test_read_async_005 has failed for ' + e.message + ', code: ' + e.code); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_READ_ASYNC_0060 + * @tc.name fileIO_test_read_async_006 + * @tc.desc Test readAsync() interfaces. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_test_read_async_006', 0, async function (done) { + try { + await fileIO.read(-1, new ArrayBuffer(4096)); + expect(null).assertFail(); + } catch (e) { + console.log('fileIO_test_read_async_006 has failed for ' + e.message + ', code: ' + e.code); + expect(e.code == 13900008 && e.message == 'Bad file descriptor').assertTrue(); + done(); + } + }); + +}); +} diff --git a/storage/storagefileiojstest/src/main/js/test/module_fileio/members/statV9.test.js b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/statV9.test.js new file mode 100644 index 000000000..8d6b7e066 --- /dev/null +++ b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/statV9.test.js @@ -0,0 +1,2021 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the 'License'); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an 'AS IS' BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// import fileIO from '@ohos.file.fs'; +import { + fileio, fileIO, FILE_CONTENT, prepareFile, nextFileName, isIntNum, isBoolean, + describe, it, expect, + } from '../../Common'; + +export default function fileIOStat() { +describe('fileIO_fs_stat', function () { + + /** + * @tc.number SUB_DF_FILEIO_STAT_SYNC_0000 + * @tc.name fileIO_stat_sync_000 + * @tc.desc Test Stat.statSync() interfaces. + * This interface shall work properly in normal case. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_stat_sync_000', 0, async function () { + let fpath = await nextFileName('fileIO_stat_sync_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileIO.statSync(fpath); + expect(stat !== null).assertTrue(); + + let fd = fileio.openSync(fpath, 0o102, 0o664); + let stat2 = fileIO.statSync(fd); + expect(stat2 !== null).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_statv9_sync_000 has failed for ' + e.message + ', code: ' + e.code); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STAT_SYNC_0010 + * @tc.name fileIO_stat_sync_001 + * @tc.desc Test Stat.statSync() interfaces. + * This interface shall throw an exception when the file isnt's exist. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_stat_sync_001', 0, async function () { + let fpath = await nextFileName('fileIO_stat_sync_001'); + + try { + fileIO.statSync(fpath); + expect(null).assertFail(); + + let invalidFD = -1; + fileIO.statSync(invalidFD); + expect(null).assertFail(); + } catch (e) { + expect(e.code == 13900002 && e.message == 'No such file or directory').assertTrue(); + console.log('fileio_statv9_sync_001 has failed for ' + e.message + ', code: ' + e.code); + } + }); + + + /** + * @tc.number SUB_DF_FILEIO_STAT_INO_0000 + * @tc.name fileIO_stat_sync_ino_000 + * @tc.desc Test Stat.statSync_Ino() interfaces. + * @tc.desc Test the ino member of class Stat + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_stat_sync_ino_000', 0, async function () { + let fpath = await nextFileName('fileIO_stat_sync_ino_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileIO.statSync(fpath); + expect(isIntNum(stat.ino)).assertTrue(); + + let fd = fileio.openSync(fpath); + let stat2 = fileIO.statSync(fd); + expect(isIntNum(stat2.ino)).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.info('fileIO_stat_sync_ino_000 has failed for ' + e.message + ', code: ' + e.code); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STAT_MODE_0000 + * @tc.name fileIO_stat_sync_mode_000 + * @tc.desc Test Stat.statSync_Mode() interfaces. + * @tc.desc Test the mode member of class Stat + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_stat_sync_mode_000', 0, async function () { + let fpath = await nextFileName('fileIO_stat_sync_mode_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileIO.statSync(fpath); + expect(isIntNum(stat.mode)).assertTrue(); + + let fd = fileio.openSync(fpath); + let stat2 = fileIO.statSync(fd); + expect(isIntNum(stat2.mode)).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.info('fileIO_stat_sync_mode_000 has failed for ' + e.message + ', code: ' + e.code); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STAT_UID_0000 + * @tc.name fileIO_stat_sync_uid_000 + * @tc.desc Test Stat.statSync_Uid() interfaces. + * @tc.desc Test the uid member of class Stat + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_stat_sync_uid_000', 0, async function () { + let fpath = await nextFileName('fileIO_stat_sync_uid_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileIO.statSync(fpath); + expect(isIntNum(stat.uid)).assertTrue(); + + let fd = fileio.openSync(fpath); + let stat2 = fileIO.statSync(fd); + expect(isIntNum(stat2.uid)).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileIO_stat_sync_uid_000 has failed for ' + e.message + ', code: ' + e.code); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STAT_SYNC_GID_0000 + * @tc.name fileIO_stat_sync_gid_000 + * @tc.desc Test Stat.statSync_Gid() interfaces. + * @tc.desc Test the gid member of class Stat + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_stat_sync_gid_000', 0, async function () { + let fpath = await nextFileName('fileIO_stat_sync_gid_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileIO.statSync(fpath); + expect(isIntNum(stat.gid)).assertTrue(); + + let fd = fileio.openSync(fpath); + let stat2 = fileIO.statSync(fd); + expect(isIntNum(stat2.gid)).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileIO_stat_sync_gid_000 has failed for ' + e.message + ', code: ' + e.code); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STAT_SYNC_SIZE_0000 + * @tc.name fileIO_stat_sync_size_000 + * @tc.desc Test Stat.statSync_Size() interfaces. + * @tc.desc Test the size member of class Stat + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_stat_sync_size_000', 0, async function () { + let fpath = await nextFileName('fileIO_stat_sync_size_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileIO.statSync(fpath); + expect(isIntNum(stat.size)).assertTrue(); + + let fd = fileio.openSync(fpath); + let stat2 = fileIO.statSync(fd); + expect(isIntNum(stat2.size)).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileIO_stat_sync_size_000 has failed for ' + e.message + ', code: ' + e.code); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STAT_SYNC_BLKSIZE_0000 + * @tc.name fileIO_stat_sync_blksize_000 + * @tc.desc Test Stat.statSync_Blksize() interfaces. + * @tc.desc Test the blksize member of class Stat + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_stat_sync_blksize_000', 0, async function () { + let fpath = await nextFileName('fileIO_stat_sync_blksize_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileIO.statSync(fpath); + expect(isIntNum(stat.blksize)).assertTrue(); + + let fd = fileio.openSync(fpath); + let stat2 = fileIO.statSync(fd); + expect(isIntNum(stat2.blksize)).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileIO_stat_sync_blksize_000 has failed for ' + e.message + ', code: ' + e.code); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STAT_SYNC_ATIME_0000 + * @tc.name fileIO_stat_sync_atime_000 + * @tc.desc Test Stat.statSync_Atime() interfaces. + * @tc.desc Test the atime member of class Stat + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_stat_sync_atime_000', 0, async function () { + let fpath = await nextFileName('fileIO_stat_sync_atime_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileIO.statSync(fpath); + expect(isIntNum(stat.atime)).assertTrue(); + + let fd = fileio.openSync(fpath); + let stat2 = fileIO.statSync(fd); + expect(isIntNum(stat2.atime)).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileIO_stat_sync_atime_000 has failed for ' + e.message + ', code: ' + e.code); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STAT_SYNC_MTIME_0000 + * @tc.name fileIO_stat_sync_mtime_000 + * @tc.desc Test Stat.statSync_Mtime() interfaces. + * @tc.desc Test the mtime member of class Stat + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_stat_sync_mtime_000', 0, async function () { + let fpath = await nextFileName('fileIO_stat_sync_mtime_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileIO.statSync(fpath); + expect(isIntNum(stat.mtime)).assertTrue(); + + let fd = fileio.openSync(fpath); + let stat2 = fileIO.statSync(fd); + expect(isIntNum(stat2.mtime)).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileIO_stat_sync_mtime_000 has failed for ' + e.message + ', code: ' + e.code); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STAT_SYNC_CTIME_0000 + * @tc.name fileIO_stat_sync_ctime_000 + * @tc.desc Test Stat.statSync_Ctime() interfaces. + * @tc.desc Test the ctime member of class Stat + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_stat_sync_ctime_000', 0, async function () { + let fpath = await nextFileName('fileIO_stat_sync_ctime_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileIO.statSync(fpath); + expect(isIntNum(stat.ctime)).assertTrue(); + + let fd = fileio.openSync(fpath); + let stat2 = fileIO.statSync(fd); + expect(isIntNum(stat2.ctime)).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileIO_stat_sync_ctime_000 has failed for ' + e.message + ', code: ' + e.code); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STAT_SYNC_ISBLOCKDEVICE_0000 + * @tc.name fileIO_stat_sync_is_block_device_000 + * @tc.desc Test Stat.statSync_IsBlockDevice() interfaces. + * @tc.desc Test the isBlockDevice() method of class Stat. + * This interface shall return a boolean variable. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_stat_sync_is_block_device_000', 0, async function () { + let fpath = await nextFileName('fileIO_stat_sync_is_block_device_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileIO.statSync(fpath); + expect(isBoolean(stat.isBlockDevice())).assertTrue(); + + let fd = fileio.openSync(fpath); + let stat2 = fileIO.statSync(fd); + expect(isBoolean(stat2.isBlockDevice())).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileIO_stat_sync_is_block_device_000 has failed for ' + e.message + ', code: ' + e.code); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STAT_SYNC_ISBLOCKDEVICE_0010 + * @tc.name fileIO_stat_sync_is_block_device_001 + * @tc.desc Test Stat.statSync_IsBlockDevice() interfaces. + * @tc.desc Test the isBlockDevice() method of class Stat. + * This interface shall not treat a normal file as a block special device. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_stat_sync_is_block_device_001', 0, async function () { + let fpath = await nextFileName('fileIO_stat_sync_is_block_device_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileIO.statSync(fpath); + expect(stat.isBlockDevice() === false).assertTrue(); + + let fd = fileio.openSync(fpath); + let stat2 = fileIO.statSync(fd); + expect(stat2.isBlockDevice() === false).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileIO_stat_sync_is_block_device_001 has failed for ' + e.message + ', code: ' + e.code); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STAT_SYNC_ISBLOCKDEVICE_0020 + * @tc.name fileIO_stat_sync_is_block_device_002 + * @tc.desc Test Stat.statSync_IsBlockDevice() interfaces. + * @tc.desc Test the isBlockDevice() method of class Stat. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_stat_sync_is_block_device_002', 0, async function () { + let fpath = await nextFileName('fileIO_stat_sync_is_block_device_002'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileIO.statSync(fpath); + expect(stat.isBlockDevice(-1) === false).assertTrue(); + expect(null).assertFail(); + } catch (e) { + console.info('fileIO_stat_sync_is_block_device_002 has failed for ' + e.message + ', code: ' + e.code); + expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STAT_SYNC_ISBLOCKDEVICE_0020 + * @tc.name fileIO_stat_sync_is_block_device_003 + * @tc.desc Test Stat.statSync_IsBlockDevice() interfaces. + * @tc.desc Test the isBlockDevice() method of class Stat. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_stat_sync_is_block_device_003', 0, async function () { + let fpath = await nextFileName('fileIO_stat_sync_is_block_device_003'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath); + let stat2 = fileIO.statSync(fd); + expect(stat2.isBlockDevice(-1) === false).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(null).assertFail(); + } catch (e) { + console.info('fileIO_stat_sync_is_block_device_003 has failed for ' + e.message + ', code: ' + e.code); + expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } + }); + /** + * @tc.number SUB_DF_FILEIO_STAT_SYNC_ISCHARACTER_DEVICE_0000 + * @tc.name fileIO_stat_sync_is_character_device_000 + * @tc.desc Test Stat.statsync_IsCharacterDevice() interfaces. + * This interface shall return a boolean variable. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_stat_sync_is_character_device_000', 0, async function () { + let fpath = await nextFileName('fileIO_stat_sync_is_character_device_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileIO.statSync(fpath); + expect(isBoolean(stat.isCharacterDevice())).assertTrue(); + + let fd = fileio.openSync(fpath); + let stat2 = fileIO.statSync(fd); + expect(isBoolean(stat2.isCharacterDevice())).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileIO_stat_sync_is_character_device_000 has failed for ' + e.message + ', code: ' + e.code); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STAT_SYNC_ISCHARACTER_DEVICE_0010 + * @tc.name fileIO_stat_sync_is_character_device_001 + * @tc.desc Test Stat.statsync_IsCharacterDevice() interfaces. + * This interface shall not treat a normal file as a character special device. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_stat_sync_is_character_device_001', 0, async function () { + let fpath = await nextFileName('fileIO_stat_sync_is_character_device_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileIO.statSync(fpath); + expect(stat.isCharacterDevice() === false).assertTrue(); + + let fd = fileio.openSync(fpath); + let stat2 = fileIO.statSync(fd); + expect(stat2.isCharacterDevice() === false).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileIO_stat_sync_is_character_device_001 has failed for ' + e.message + ', code: ' + e.code); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STAT_SYNC_ISCHARACTER_DEVICE_0020 + * @tc.name fileIO_stat_sync_is_character_device_002 + * @tc.desc Test Stat.statsync_IsCharacterDevice() interfaces. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_stat_sync_is_character_device_002', 0, async function () { + let fpath = await nextFileName('fileIO_stat_sync_is_character_device_002'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileIO.statSync(fpath); + expect(stat.isCharacterDevice(-1) === false).assertTrue(); + expect(null).assertFail(); + } catch (e) { + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STAT_SYNC_ISCHARACTER_DEVICE_0020 + * @tc.name fileIO_stat_sync_is_character_device_003 + * @tc.desc Test Stat.statsync_IsCharacterDevice() interfaces. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_stat_sync_is_character_device_003', 0, async function () { + let fpath = await nextFileName('fileIO_stat_sync_is_character_device_003'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath); + let stat2 = fileIO.statSync(fd); + expect(stat2.isCharacterDevice(-1) === false).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(null).assertFail(); + } catch (e) { + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STAT_SYNC_ISDIRECTORY_0000 + * @tc.name fileIO_stat_sync_is_directory_000 + * @tc.desc Test Stat.statsync_isDirectory() interfaces. + * This interface shall return a boolean variable. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_stat_sync_is_directory_000', 0, async function () { + let fpath = await nextFileName('fileIO_stat_sync_is_directory_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileIO.statSync(fpath); + expect(isBoolean(stat.isDirectory())).assertTrue(); + + let fd = fileio.openSync(fpath); + let stat2 = fileIO.statSync(fd); + expect(isBoolean(stat2.isDirectory())).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileIO_stat_sync_is_directory_000 has failed for ' + e.message + ', code: ' + e.code); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STAT_SYNC_ISDIRECTORY_0010 + * @tc.name fileIO_stat_sync_is_directory_001 + * @tc.desc Test Stat.statsync_isDirectory() interfaces. + * This interface shall not treat a normal file as a directory. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_stat_sync_is_directory_001', 0, async function () { + let fpath = await nextFileName('fileIO_stat_sync_is_directory_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileIO.statSync(fpath); + expect(stat.isDirectory() === false).assertTrue(); + + let fd = fileio.openSync(fpath); + let stat2 = fileIO.statSync(fd); + expect(stat2.isDirectory() === false).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileIO_stat_sync_is_directory_001 has failed for ' + e.message + ', code: ' + e.code); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STAT_SYNC_ISDIRECTORY_0020 + * @tc.name fileIO_stat_sync_is_directory_002 + * @tc.desc Test Stat.statsync_isDirectory() interfaces. + * This interface shall treat a directory as a directory. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_stat_sync_is_directory_002', 0, async function () { + let dpath = await nextFileName('fileIO_stat_sync_is_directory_002') + 'd'; + + try { + expect(fileio.mkdirSync(dpath) == null).assertTrue(); + let stat = fileIO.statSync(dpath); + expect(stat.isDirectory()).assertTrue(); + + let fd = fileio.openSync(dpath); + let stat2 = fileIO.statSync(fd); + expect(stat2.isDirectory()).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + + expect(fileio.rmdirSync(dpath) == null).assertTrue(); + } catch (e) { + console.log('fileIO_stat_sync_is_directory_002 has failed for ' + e.message + ', code: ' + e.code); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STAT_SYNC_ISDIRECTORY_0030 + * @tc.name fileIO_stat_sync_is_directory_003 + * @tc.desc Test Stat.statsync_isDirectory() interfaces. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_stat_sync_is_directory_003', 0, async function () { + let dpath = await nextFileName('fileIO_stat_sync_is_directory_003') + 'd'; + + try { + expect(fileio.mkdirSync(dpath) == null).assertTrue(); + let stat = fileIO.statSync(dpath); + expect(stat.isDirectory(-1) === false).assertTrue(); + expect(null).assertFail(); + } catch (e) { + expect(fileio.rmdirSync(dpath) == null).assertTrue(); + expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STAT_SYNC_ISDIRECTORY_0040 + * @tc.name fileIO_stat_sync_is_directory_004 + * @tc.desc Test Stat.statsync_isDirectory() interfaces. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_stat_sync_is_directory_004', 0, async function () { + let dpath = await nextFileName('fileIO_stat_sync_is_directory_004') + 'd'; + + try { + expect(fileio.mkdirSync(dpath) == null).assertTrue(); + let fd = fileio.openSync(dpath); + let stat2 = fileIO.statSync(fd); + expect(stat2.isDirectory(-1) === false).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(null).assertFail(); + } catch (e) { + + expect(fileio.rmdirSync(dpath) == null).assertTrue(); + expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STAT_SYNC_ISFIFO_0000 + * @tc.name fileIO_stat_sync_is_fifo_000 + * @tc.desc Test Stat.statsync_isFIFO() interfaces. + * This interface shall return a boolean variable. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_stat_sync_is_fifo_000', 0, async function () { + let fpath = await nextFileName('fileIO_stat_sync_is_fifo_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileIO.statSync(fpath); + expect(isBoolean(stat.isFIFO())).assertTrue(); + + let fd = fileio.openSync(fpath); + let stat2 = fileIO.statSync(fd); + expect(isBoolean(stat2.isFIFO())).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileIO_stat_sync_is_fifo_000 has failed for ' + e.message + ', code: ' + e.code); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STAT_SYNC_ISFIFO_0010 + * @tc.name fileIO_stat_sync_is_fifo_001 + * @tc.desc Test Stat.statsync_isFIFO() interfaces. + * This interface shall not treat a normal file as a FIFO. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_stat_sync_is_fifo_001', 0, async function () { + let fpath = await nextFileName('fileIO_stat_sync_is_fifo_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileIO.statSync(fpath); + expect(stat.isFIFO() === false).assertTrue(); + + let fd = fileio.openSync(fpath); + let stat2 = fileIO.statSync(fd); + expect(stat2.isFIFO() === false).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileIO_stat_sync_is_fifo_001 has failed for ' + e.message + ', code: ' + e.code); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STAT_SYNC_ISFIFO_0020 + * @tc.name fileIO_stat_sync_is_fifo_002 + * @tc.desc Test Stat.statsync_isFIFO() interfaces. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_stat_sync_is_fifo_002', 0, async function () { + let fpath = await nextFileName('fileIO_stat_sync_is_fifo_002'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileIO.statSync(fpath); + expect(stat.isFile(-1) === false).assertTrue(); + expect(null).assertFail(); + } catch (e) { + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STAT_SYNC_ISFIFO_0020 + * @tc.name fileIO_stat_sync_is_fifo_003 + * @tc.desc Test Stat.statsync_isFIFO() interfaces. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_stat_sync_is_fifo_003', 0, async function () { + let fpath = await nextFileName('fileIO_stat_sync_is_fifo_003'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath); + let stat2 = fileIO.statSync(fd); + expect(stat2.isFile(-1) === false).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(null).assertFail(); + } catch (e) { + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue(); + } + }); + /** + * @tc.number SUB_DF_FILEIO_STAT_SYNC_ISFILE_0000 + * @tc.name fileIO_stat_sync_is_file_000 + * @tc.desc Test Stat.statsync_isFile() interfaces. + * This interface shall return a boolean variable. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_stat_sync_is_file_000', 0, async function () { + let fpath = await nextFileName('fileIO_stat_sync_is_file_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileIO.statSync(fpath); + expect(isBoolean(stat.isFile())).assertTrue(); + + let fd = fileio.openSync(fpath); + let stat2 = fileIO.statSync(fd); + expect(isBoolean(stat2.isFile())).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileIO_stat_sync_is_file_000 has failed for ' + e.message + ', code: ' + e.code); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STAT_SYNC_ISFILE_0010 + * @tc.name fileIO_stat_sync_is_file_001 + * @tc.desc Test Stat.statsync_isFile() interfaces. + * This interface shall treat a normal file as a normal file. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_stat_sync_is_file_001', 0, async function () { + let fpath = await nextFileName('fileIO_stat_sync_is_file_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileIO.statSync(fpath); + expect(stat.isFile()).assertTrue(); + + let fd = fileio.openSync(fpath); + let stat2 = fileIO.statSync(fd); + expect(stat2.isFile()).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileIO_stat_sync_is_file_001 has failed for ' + e.message + ', code: ' + e.code); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STAT_SYNC_ISFILE_0020 + * @tc.name fileIO_stat_sync_is_file_002 + * @tc.desc Test Stat.statsync_isFile() interfaces. + * This interface shall not treat a directory as a normal file. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_stat_sync_is_file_002', 0, async function () { + let dpath = await nextFileName('fileIO_stat_sync_is_file_002'); + + try { + expect(fileio.mkdirSync(dpath) == null).assertTrue(); + let stat = fileIO.statSync(dpath); + expect(stat.isFile() === false).assertTrue(); + + let fd = fileio.openSync(dpath); + let stat2 = fileIO.statSync(fd); + expect(stat2.isFile() === false).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + + expect(fileio.rmdirSync(dpath) == null).assertTrue(); + } catch (e) { + console.log('fileIO_stat_sync_is_file_002 has failed for ' + e.message + ', code: ' + e.code); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STAT_SYNC_ISFILE_0030 + * @tc.name fileIO_stat_sync_is_file_003 + * @tc.desc Test Stat.statsync_isFile() interfaces. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_stat_sync_is_file_003', 0, async function () { + let dpath = await nextFileName('fileIO_stat_sync_is_file_003'); + + try { + expect(fileio.mkdirSync(dpath) == null).assertTrue(); + let stat = fileIO.statSync(dpath); + expect(stat.isFile(-1) === false).assertTrue(); + expect(null).assertFail(); + } catch (e) { + expect(fileio.rmdirSync(dpath) == null).assertTrue(); + expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STAT_SYNC_ISFILE_0030 + * @tc.name fileIO_stat_sync_is_file_004 + * @tc.desc Test Stat.statsync_isFile() interfaces. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_stat_sync_is_file_004', 0, async function () { + let dpath = await nextFileName('fileIO_stat_sync_is_file_004'); + + try { + expect(fileio.mkdirSync(dpath) == null).assertTrue(); + let fd = fileio.openSync(dpath); + let stat2 = fileIO.statSync(fd); + expect(stat2.isFile(-1) === false).assertTrue(); + expect(null).assertFail(); + expect(fileio.closeSync(fd) == null).assertTrue(); + } catch (e) { + expect(fileio.rmdirSync(dpath) == null).assertTrue(); + expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue(); + } + }); + /** + * @tc.number SUB_DF_FILEIO_STAT_SYNC_ISSOCKET_0000 + * @tc.name fileIO_stat_sync_is_socket_000 + * @tc.desc Test Stat.statsync_isSocket() interfaces. + * This interface shall return a boolean variable. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_stat_sync_is_socket_000', 0, async function () { + let fpath = await nextFileName('fileIO_stat_sync_is_socket_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileIO.statSync(fpath); + expect(isBoolean(stat.isSocket())).assertTrue(); + + let fd = fileio.openSync(fpath); + let stat2 = fileIO.statSync(fd); + expect(isBoolean(stat2.isSocket())).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileIO_stat_sync_is_socket_000 has failed for ' + e.message + ', code: ' + e.code); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STAT_SYNC_ISSOCKET_0010 + * @tc.name fileIO_stat_sync_is_socket_001 + * @tc.desc Test Stat.statsync_isSocket() interfaces. + * This interface shall not treat a file as a socket. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_stat_sync_is_socket_001', 0, async function () { + let fpath = await nextFileName('fileIO_stat_sync_is_socket_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileIO.statSync(fpath); + expect(stat.isSocket() === false).assertTrue(); + + let fd = fileio.openSync(fpath); + let stat2 = fileIO.statSync(fd); + expect(stat2.isSocket() === false).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileIO_stat_sync_is_socket_001 has failed for ' + e.message + ', code: ' + e.code); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STAT_SYNC_ISSOCKET_0020 + * @tc.name fileIO_stat_sync_is_socket_002 + * @tc.desc Test Stat.statsync_isSocket() interfaces. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_stat_sync_is_socket_002', 0, async function () { + let fpath = await nextFileName('fileIO_stat_sync_is_socket_002'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileIO.statSync(fpath); + expect(stat.isSocket(-1) === false).assertTrue(); + expect(null).assertFail(); + } catch (e) { + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STAT_SYNC_ISSOCKET_0020 + * @tc.name fileIO_stat_sync_is_socket_003 + * @tc.desc Test Stat.statsync_isSocket() interfaces. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_stat_sync_is_socket_003', 0, async function () { + let fpath = await nextFileName('fileIO_stat_sync_is_socket_003'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath); + let stat2 = fileIO.statSync(fd); + expect(stat2.isSocket(-1) === false).assertTrue(); + expect(null).assertFail(); + expect(fileio.closeSync(fd) == null).assertTrue(); + } catch (e) { + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue(); + } + }); + /** + * @tc.number SUB_DF_FILEIO_STAT_SYNC_ISSYMBOLICLINK_0000 + * @tc.name fileIO_stat_sync_is_symbolic_link_000 + * @tc.desc Test Stat.statasync_isSymbolicLink() interfaces. + * This interface shall return a boolean variable. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_stat_sync_is_symbolic_link_000', 0, async function () { + let fpath = await nextFileName('fileIO_stat_sync_is_symbolic_link_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileIO.statSync(fpath); + expect(isBoolean(stat.isSymbolicLink())).assertTrue(); + + let fd = fileio.openSync(fpath); + let stat2 = fileIO.statSync(fd); + expect(isBoolean(stat2.isSymbolicLink())).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileIO_stat_sync_is_symbolic_link_000 has failed for ' + e.message + ', code: ' + e.code); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STAT_SYNC_ISSYMBOLICLINK_0010 + * @tc.name fileIO_stat_sync_is_symbolic_link_001 + * @tc.desc Test Stat.statasync_isSymbolicLink() interfaces. + * This interface shall not treat a normal file as a symbolic link. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_stat_sync_is_symbolic_link_001', 0, async function () { + let fpath = await nextFileName('fileIO_stat_sync_is_symbolic_link_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileIO.statSync(fpath); + expect(stat.isSymbolicLink() === false).assertTrue(); + + let fd = fileio.openSync(fpath); + let stat2 = fileIO.statSync(fd); + expect(stat2.isSymbolicLink() === false).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileIO_stat_sync_is_symbolic_link_001 has failed for ' + e.message + ', code: ' + e.code); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STAT_SYNC_ISSYMBOLICLINK_0020 + * @tc.name fileIO_stat_sync_is_symbolic_link_002 + * @tc.desc Test Stat.isSymbolicLink() interfaces. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_stat_sync_is_symbolic_link_002', 0, async function () { + let fpath = await nextFileName('fileIO_stat_sync_is_symbolic_link_002'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileIO.statSync(fpath); + expect(stat.isSymbolicLink(-1) === false).assertTrue(); + expect(null).assertFail(); + } catch (e) { + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STAT_SYNC_ISSYMBOLICLINK_0020 + * @tc.name fileIO_stat_sync_is_symbolic_link_003 + * @tc.desc Test Stat.isSymbolicLink() interfaces. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_stat_sync_is_symbolic_link_003', 0, async function () { + let fpath = await nextFileName('fileIO_stat_sync_is_symbolic_link_003'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath); + let stat2 = fileIO.statSync(fd); + expect(stat2.isSymbolicLink(-1) === false).assertTrue(); + expect(null).assertFail(); + expect(fileio.closeSync(fd) == null).assertTrue(); + } catch (e) { + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue(); + } + }); + /** + * @tc.number SUB_DF_FILEIO_STAT_ASYNC_0000 + * @tc.name fileIO_stat_async_000 + * @tc.desc Test Stat.statAsync() interface. + * This interface shall work properly in normal case when providing the promise async model. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_stat_async_000', 0, async function (done) { + let fpath = await nextFileName('fileIO_stat_async_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + fileIO.stat(fpath).then((stat) => { + expect(stat !== null).assertTrue(); + }); + + let fd = fileio.openSync(fpath); + fileIO.stat(fd).then((stat2) => { + expect(stat2 !== null).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + }); + + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileIO_stat_async_000 has failed for ' + e.message + ', code: ' + e.code); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STAT_ASYNC_0000 + * @tc.name fileIO_stat_async_001 + * @tc.desc Test Stat.statAsync() interface. + * This interface shall work properly in normal case when providing the callback async model. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_stat_async_001', 0, async function (done) { + let fpath = await nextFileName('fileIO_stat_async_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + fileIO.stat(fpath, function (error) { + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + }); + } catch (e) { + console.log('fileIO_stat_async_001 has failed for ' + e.message + ', code: ' + e.code); + expect(null).assertFail(); + } + }); + + + /** + * @tc.number SUB_DF_FILEIO_STAT_ASYNC_0000 + * @tc.name fileIO_stat_async_002 + * @tc.desc Test Stat.statAsync() interface. + * This interface shall work properly in normal case when providing the callback async model. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_stat_async_002', 0, async function (done) { + let fpath = await nextFileName('fileIO_stat_async_002'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath); + fileIO.stat(fd, function (error) { + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + }); + } catch (e) { + console.log('fileIO_stat_async_002 has failed for ' + e.message + ', code: ' + e.code); + expect(null).assertFail(); + } + }); + /** + * @tc.number SUB_DF_FILEIO_STAT_ASYNC_INO_0000 + * @tc.name fileIO_stat_async_ino_000 + * @tc.desc Test the ino member of class Stat. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_stat_async_ino_000', 0, async function (done) { + let fpath = await nextFileName('fileIO_stat_async_ino_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = await fileIO.stat(fpath); + expect(isIntNum(stat.ino)).assertTrue(); + + let fd = fileio.openSync(fpath); + let stat2 = await fileIO.stat(fd); + expect(isIntNum(stat2.ino)).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileIO_stat_async_ino_000 has failed for ' + e.message + ', code: ' + e.code); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STAT_ASYNC_MODE_0000 + * @tc.name fileIO_stat_async_mode_000 + * @tc.desc Test the mode member of class Stat. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_stat_async_mode_000', 0, async function (done) { + let fpath = await nextFileName('fileIO_stat_async_mode_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = await fileIO.stat(fpath); + expect(isIntNum(stat.mode)).assertTrue(); + + let fd = fileio.openSync(fpath); + let stat2 = await fileIO.stat(fd); + expect(isIntNum(stat2.mode)).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileIO_stat_async_mode_000 has failed for ' + e.message + ', code: ' + e.code); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STAT_ASYNC_UID_0000 + * @tc.name fileIO_stat_async_uid_000 + * @tc.desc Test the uid member of class Stat. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_stat_async_uid_000', 0, async function (done) { + let fpath = await nextFileName('fileIO_stat_async_uid_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = await fileIO.stat(fpath); + expect(isIntNum(stat.uid)).assertTrue(); + + let fd = fileio.openSync(fpath); + let stat2 = await fileIO.stat(fd); + expect(isIntNum(stat2.uid)).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileIO_stat_async_uid_000 has failed for ' + e.message + ', code: ' + e.code); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STAT_ASYNC_GID_0000 + * @tc.name fileIO_stat_async_gid_000 + * @tc.desc Test the gid member of class Stat. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_stat_async_gid_000', 0, async function (done) { + let fpath = await nextFileName('fileIO_stat_async_gid_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = await fileIO.stat(fpath); + expect(isIntNum(stat.gid)).assertTrue(); + + let fd = fileio.openSync(fpath); + let stat2 = await fileIO.stat(fd); + expect(isIntNum(stat2.gid)).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileIO_stat_async_gid_000 has failed for ' + e.message + ', code: ' + e.code); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STAT_ASYNC_SIZE_0000 + * @tc.name fileIO_stat_async_size_000 + * @tc.desc Test the size member of class Stat. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_stat_async_size_000', 0, async function (done) { + let fpath = await nextFileName('fileIO_stat_async_size_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = await fileIO.stat(fpath); + expect(isIntNum(stat.size)).assertTrue(); + + let fd = fileio.openSync(fpath); + let stat2 = await fileIO.stat(fd); + expect(isIntNum(stat2.size)).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileIO_stat_async_size_000 has failed for ' + e.message + ', code: ' + e.code); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STAT_ASYNC_ATIME_0000 + * @tc.name fileIO_stat_async_atime_000 + * @tc.desc Test Stat.atime() interface. + * @tc.desc Test the atime member of class Stat. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_stat_async_atime_000', 0, async function (done) { + let fpath = await nextFileName('fileIO_stat_async_atime_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = await fileIO.stat(fpath); + expect(isIntNum(stat.atime)).assertTrue(); + + let fd = fileio.openSync(fpath); + let stat2 = await fileIO.stat(fd); + expect(isIntNum(stat2.atime)).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileIO_stat_async_atime_000 has failed for ' + e.message + ', code: ' + e.code); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STAT_ASYNC_MTIME_0000 + * @tc.name fileIO_stat_async_mtime_000 + * @tc.desc Test Stat.mtime() interface. + * @tc.desc Test the mtime member of class Stat. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_stat_async_mtime_000', 0, async function (done) { + let fpath = await nextFileName('fileIO_stat_async_mtime_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = await fileIO.stat(fpath); + expect(isIntNum(stat.mtime)).assertTrue(); + + let fd = fileio.openSync(fpath); + let stat2 = await fileIO.stat(fd); + expect(isIntNum(stat2.mtime)).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileIO_stat_async_mtime_000 has failed for ' + e.message + ', code: ' + e.code); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STAT_ASYNC_CTIME_0000 + * @tc.name fileIO_stat_async_ctime_000 + * @tc.desc Test the ctime member of class Stat. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_stat_async_ctime_000', 0, async function (done) { + let fpath = await nextFileName('fileIO_stat_async_ctime_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = await fileIO.stat(fpath); + expect(isIntNum(stat.ctime)).assertTrue(); + + let fd = fileio.openSync(fpath); + let stat2 = await fileIO.stat(fd); + expect(isIntNum(stat2.ctime)).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileIO_stat_async_ctime_000 has failed for ' + e.message + ', code: ' + e.code); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STAT_ASYNC_ISBLOCKDEVICE_0000 + * @tc.name fileIO_stat_async_is_block_device_000 + * @tc.desc Test the isBlockDevice method of class Stat. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_stat_async_is_block_device_000', 0, async function (done) { + let fpath = await nextFileName('fileIO_stat_async_is_block_device_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = await fileIO.stat(fpath); + expect(isBoolean(stat.isBlockDevice())).assertTrue(); + + let fd = fileio.openSync(fpath); + let stat2 = await fileIO.stat(fd); + expect(isBoolean(stat2.isBlockDevice())).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileIO_stat_async_is_block_device_000 has failed for ' + e.message + ', code: ' + e.code); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STAT_ASYNC_ISBLOCKDEVICE_0010 + * @tc.name fileIO_stat_async_is_block_device_001 + * @tc.desc Test the isBlockDevice method of class Stat. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_stat_async_is_block_device_001', 0, async function (done) { + let fpath = await nextFileName('fileIO_stat_async_is_block_device_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = await fileIO.stat(fpath); + expect(stat.isBlockDevice() === false).assertTrue(); + + let fd = fileio.openSync(fpath); + let stat2 = await fileIO.stat(fd); + expect(stat2.isBlockDevice() === false).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileIO_stat_async_is_block_device_001 has failed for ' + e.message + ', code: ' + e.code); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STAT_ASYNC_ISCHARACTERDEVICE_0000 + * @tc.name fileIO_stat_async_is_character_device_000 + * @tc.desc Test the isCharacterDevice method of class Stat. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_stat_async_is_character_device_000', 0, async function (done) { + let fpath = await nextFileName('fileIO_stat_async_is_character_device_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = await fileIO.stat(fpath); + expect(isBoolean(stat.isCharacterDevice())).assertTrue(); + + let fd = fileio.openSync(fpath); + let stat2 = await fileIO.stat(fd); + expect(isBoolean(stat2.isCharacterDevice())).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileIO_stat_async_is_character_device_000 has failed for ' + e.message + ', code: ' + e.code); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STAT_ASYNC_ISCHARACTERDEVICE_0010 + * @tc.name fileIO_stat_async_is_character_device_001 + * @tc.desc Test the isCharacterDevice method of class Stat. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_stat_async_is_character_device_001', 0, async function (done) { + let fpath = await nextFileName('fileIO_stat_async_is_character_device_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = await fileIO.stat(fpath); + expect(stat.isCharacterDevice() === false).assertTrue(); + + let fd = fileio.openSync(fpath); + let stat2 = await fileIO.stat(fd); + expect(stat2.isCharacterDevice() === false).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileIO_stat_async_is_character_device_001 has failed for ' + e.message + ', code: ' + e.code); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STAT_ASYNC_ISDIRECTORY_0000 + * @tc.name fileIO_stat_async_is_directory_000 + * @tc.desc Test Stat.isDirectory() interface. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_stat_async_is_directory_000', 0, async function (done) { + let fpath = await nextFileName('fileIO_stat_async_is_directory_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = await fileIO.stat(fpath); + expect(isBoolean(stat.isDirectory())).assertTrue(); + + let fd = fileio.openSync(fpath); + let stat2 = await fileIO.stat(fd); + expect(isBoolean(stat2.isDirectory())).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileIO_stat_async_is_directory_000 has failed for ' + e.message + ', code: ' + e.code); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STAT_ASYNC_ISDIRECTORY_0010 + * @tc.name fileIO_stat_async_is_directory_001 + * @tc.desc Test Stat.isDirectory() interface. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_stat_async_is_directory_001', 0, async function (done) { + let fpath = await nextFileName('fileIO_stat_async_is_directory_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = await fileIO.stat(fpath); + expect(stat.isDirectory() === false).assertTrue(); + + let fd = fileio.openSync(fpath); + let stat2 = await fileIO.stat(fd); + expect(stat2.isDirectory() === false).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileIO_stat_async_is_directory_001 has failed for ' + e.message + ', code: ' + e.code); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STAT_ASYNC_ISDIRECTORY_0020 + * @tc.name fileIO_stat_async_is_directory_002 + * @tc.desc Test Stat.isDirectory() interface. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_stat_async_is_directory_002', 0, async function (done) { + let dpath = await nextFileName('fileIO_stat_async_is_directory_002') + 'd'; + + try { + expect(fileio.mkdirSync(dpath) == null).assertTrue(); + let stat = await fileIO.stat(dpath); + expect(stat.isDirectory()).assertTrue(); + + let fd = fileio.openSync(dpath); + let stat2 = await fileIO.stat(fd); + expect(stat2.isDirectory()).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + + expect(fileio.rmdirSync(dpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileIO_stat_async_is_directory_002 has failed for ' + e.message + ', code: ' + e.code); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STAT_ASYNC_ISFIFO_0000 + * @tc.name fileIO_stat_async_is_fifo_000 + * @tc.desc Test Stat.isFIFO() interface. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_stat_async_is_fifo_000', 0, async function (done) { + let fpath = await nextFileName('fileIO_stat_async_is_fifo_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = await fileIO.stat(fpath); + expect(isBoolean(stat.isFIFO())).assertTrue(); + + let fd = fileio.openSync(fpath); + let stat2 = await fileIO.stat(fd); + expect(isBoolean(stat2.isFIFO())).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileIO_stat_async_is_fifo_000 has failed for ' + e.message + ', code: ' + e.code); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STAT_ASYNC_ISFIFO_0010 + * @tc.name fileIO_stat_async_is_fifo_001 + * @tc.desc Test Stat.isFIFO() interface. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_stat_async_is_fifo_001', 0, async function (done) { + let fpath = await nextFileName('fileIO_stat_async_is_fifo_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = await fileIO.stat(fpath); + expect(stat.isFIFO() === false).assertTrue(); + + let fd = fileio.openSync(fpath); + let stat2 = await fileIO.stat(fd); + expect(stat2.isFIFO() === false).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileIO_stat_async_is_fifo_001 has failed for ' + e.message + ', code: ' + e.code); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STAT_ASYNC_ISFILE_0000 + * @tc.name fileIO_stat_async_is_file_000 + * @tc.desc Test Stat.isFile() interface. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_stat_async_is_file_000', 0, async function (done) { + let fpath = await nextFileName('fileIO_stat_async_is_file_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = await fileIO.stat(fpath); + expect(isBoolean(stat.isFile())).assertTrue(); + + let fd = fileio.openSync(fpath); + let stat2 = await fileIO.stat(fd); + expect(isBoolean(stat2.isFile())).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileIO_stat_async_is_file_000 has failed for ' + e.message + ', code: ' + e.code); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STAT_ASYNC_ISFILE_0010 + * @tc.name fileIO_stat_async_is_file_001 + * @tc.desc Test Stat.isFile() interface. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_stat_async_is_file_001', 0, async function (done) { + let fpath = await nextFileName('fileIO_stat_async_is_file_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = await fileIO.stat(fpath); + expect(stat.isFile()).assertTrue(); + + let fd = fileio.openSync(fpath); + let stat2 = await fileIO.stat(fd); + expect(stat2.isFile()).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileIO_stat_async_is_file_001 has failed for ' + e.message + ', code: ' + e.code); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STAT_ASYNC_ISFILE_0020 + * @tc.name fileIO_stat_async_is_file_002 + * @tc.desc Test Stat.isFile() interface. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_stat_async_is_file_002', 0, async function (done) { + let dpath = await nextFileName('fileIO_stat_async_is_file_002'); + + try { + expect(fileio.mkdirSync(dpath) == null).assertTrue(); + let stat = await fileIO.stat(dpath); + expect(stat.isFile() === false).assertTrue(); + + let fd = fileio.openSync(dpath); + let stat2 = await fileIO.stat(fd); + expect(stat2.isFile() === false).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + + expect(fileio.rmdirSync(dpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileIO_stat_async_is_file_002 has failed for ' + e.message + ', code: ' + e.code); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STAT_ASYNC_ISSOCKET_0000 + * @tc.name fileIO_stat_async_is_socket_000 + * @tc.desc Test Stat.isSocket() interface. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_stat_async_is_socket_000', 0, async function (done) { + let fpath = await nextFileName('fileIO_stat_async_is_socket_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = await fileIO.stat(fpath); + expect(isBoolean(stat.isSocket())).assertTrue(); + + let fd = fileio.openSync(fpath); + let stat2 = await fileIO.stat(fd); + expect(isBoolean(stat2.isSocket())).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileIO_stat_async_is_socket_000 has failed for ' + e.message + ', code: ' + e.code); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STAT_ASYNC_ISSOCKET_0010 + * @tc.name fileIO_stat_async_is_socket_001 + * @tc.desc Test Stat.isSocket() interface. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_stat_async_is_socket_001', 0, async function (done) { + let fpath = await nextFileName('fileIO_stat_async_is_socket_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = await fileIO.stat(fpath); + expect(stat.isSocket() === false).assertTrue(); + + let fd = fileio.openSync(fpath); + let stat2 = await fileIO.stat(fd); + expect(stat2.isSocket() === false).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileIO_stat_async_is_socket_001 has failed for ' + e.message + ', code: ' + e.code); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STAT_ASYNC_ISSYMBOLICLINK_0000 + * @tc.name fileIO_stat_async_is_symbolic_link_000 + * @tc.desc Test Stat.isSymbolicLink() interface. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_stat_async_is_symbolic_link_000', 0, async function (done) { + let fpath = await nextFileName('fileIO_stat_async_is_symbolic_link_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = await fileIO.stat(fpath); + expect(isBoolean(stat.isSymbolicLink())).assertTrue(); + + let fd = fileio.openSync(fpath); + let stat2 = await fileIO.stat(fd); + expect(isBoolean(stat2.isSymbolicLink())).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileIO_stat_async_is_symbolic_link_000 has failed for ' + e.message + ', code: ' + e.code); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STAT_ASYNC_ISSYMBOLICLINK_0010 + * @tc.name fileIO_stat_async_is_symbolic_link_001 + * @tc.desc Test Stat.isSymbolicLink() interface. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_stat_async_is_symbolic_link_001', 0, async function (done) { + let fpath = await nextFileName('fileIO_stat_async_is_symbolic_link_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = await fileIO.stat(fpath); + expect(stat.isSymbolicLink() === false).assertTrue(); + + let fd = fileio.openSync(fpath); + let stat2 = await fileIO.stat(fd); + expect(stat2.isSymbolicLink() === false).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileIO_stat_async_is_symbolic_link_001 has failed for ' + e.message + ', code: ' + e.code); + expect(null).assertFail(); + } + }); + + it('fileio_test_append_file_sync_000', 0, async function (done) { + let fpath = await nextFileName('fileio_test_append_file_sync_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileIO.statSync(fpath); + expect(isIntNum(stat.size)).assertTrue(); + + let fd = fileio.openSync(fpath, 0o2002); + expect(isIntNum(fd)).assertTrue(); + expect(fileio.writeSync(fd, FILE_CONTENT) == FILE_CONTENT.length).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + + stat = fileIO.statSync(fpath); + expect(stat.size == FILE_CONTENT.length * 2).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_test_append_file_sync_000 has failed for ' + e.message + ', code: ' + e.code); + expect(null).assertFail(); + } + done(); + }); + + it('fileio_test_append_file_sync_001', 0, async function (done) { + let fpath = await nextFileName('fileio_test_append_file_sync_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath, 0o2002); + let stat = fileIO.statSync(fd); + expect(isIntNum(stat.size)).assertTrue(); + expect(isIntNum(fd)).assertTrue(); + expect(fileio.writeSync(fd, FILE_CONTENT) == FILE_CONTENT.length).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + + let fd2 = fileio.openSync(fpath, 0o2002); + stat = fileIO.statSync(fd2); + expect(stat.size == FILE_CONTENT.length * 2).assertTrue(); + expect(fileio.closeSync(fd2) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_test_append_file_sync_001 has failed for ' + e.message + ', code: ' + e.code); + expect(null).assertFail(); + } + done(); + }); +}); +} diff --git a/storage/storagefileiojstest/src/main/js/test/module_fileio/members/truncateV9.test.js b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/truncateV9.test.js new file mode 100644 index 000000000..3bbefb521 --- /dev/null +++ b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/truncateV9.test.js @@ -0,0 +1,318 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the 'License'); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an 'AS IS' BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// import fileIO from '@ohos.file.fs'; +import { + fileio, fileIO, FILE_CONTENT, prepareFile, nextFileName, isIntNum, + describe, it, expect, +} from '../../Common'; + + export default function fileIOTruncate() { + describe('fileIO_fs_truncate', function () { + + /** + * @tc.number SUB_DF_FILEIO_TRUNCATE_ASYNC_0000 + * @tc.name fileIO_truncate_async_000 + * @tc.desc Test the truncateAsync() interface that receives the fpath parameter. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_truncate_async_000', 0, async function (done) { + let fpath = await nextFileName('fileIO_truncate_async_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let truncateLen = 5; + + try { + await fileIO.truncate(fpath, truncateLen); + let fd = fileio.openSync(fpath, 0o2); + expect(isIntNum(fd)).assertTrue(); + let len = fileio.readSync(fd, new ArrayBuffer(4096)); + expect(len == truncateLen).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.info('fileIO_truncate_async_000 has failed for ' + e.message + ', code: ' + e.code); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_TRUNCATE_ASYNC_0010 + * @tc.name fileIO_truncate_async_001 + * @tc.desc Test the truncateAsync() interface that receives the fd parameter. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_truncate_async_001', 0, async function (done) { + let fpath = await nextFileName('fileIO_truncate_async_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let fd = fileio.openSync(fpath, 0o2); + expect(isIntNum(fd)).assertTrue(); + let truncateLen = 5; + + try { + fileIO.truncate(fd, truncateLen, function (err) { + let len = fileio.readSync(fd, new ArrayBuffer(4096)); + expect(len == truncateLen).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + }) + } catch (e) { + console.log('fileIO_truncate_async_001 has failed for ' + e.message + ', code: ' + e.code); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_TRUNCATE_ASYNC_0020 + * @tc.name fileIO_truncate_async_002 + * @tc.desc Test the truncateAsync() interface that receives the fpath parameter. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_truncate_async_002', 0, async function (done) { + let fpath = await nextFileName('fileIO_truncate_async_002'); + expect(prepareFile(fpath, 'truncate')).assertTrue(); + let truncateLen = 2; + + try { + fileIO + .truncate(fpath, truncateLen) + .then(function (err) { + expect(err == null).assertTrue(); + let fd = fileio.openSync(fpath, 0o2); + expect(isIntNum(fd)).assertTrue(); + let len = fileio.readSync(fd, new ArrayBuffer(4096)); + expect(len == truncateLen).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + }) + .catch(function (e) { + console.log('catch ' + e.message + ', code: ' + e.code); + }); + } catch(e) { + console.log('fileIO_truncate_async_002 has failed for ' + e.message + ', code: ' + e.code); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_TRUNCATE_ASYNC_0030 + * @tc.name fileIO_truncate_async_003 + * @tc.desc Test the truncateAsync() interface that receives the fd parameter. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_truncate_async_003', 0, async function (done) { + let fpath = await nextFileName('fileIO_truncate_async_003'); + expect(prepareFile(fpath, 'truncate')).assertTrue(); + let fd = fileio.openSync(fpath, 0o2); + expect(isIntNum(fd)).assertTrue(); + let truncateLen = 2; + + try { + fileIO.truncate(fd, truncateLen) + .then(function (err) { + expect(err == null).assertTrue(); + let len = fileio.readSync(fd, new ArrayBuffer(4096)); + expect(len == truncateLen).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + }) + .catch(function (e) { + console.log('catch ' + e.message + ', code: ' + e.code); + }) + } catch(e) { + console.log('fileIO_truncate_async_003 has failed for ' + e.message + ', code: ' + e.code); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_TRUNCATE_ASYNC_0040 + * @tc.name fileIO_truncate_async_004 + * @tc.desc Test the truncateAsync() interface that receives the fpath parameter. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_truncate_async_004', 0, async function (done) { + let fpath = await nextFileName('fileIO_truncate_async_004'); + let truncateLen = 2; + + try { + fileIO.truncate(fpath, truncateLen, function (err) { + done(); + }); + } catch (e) { + console.log('fileIO_truncate_async_004 has failed for ' + e.message + ', code: ' + e.code); + expect(!!e).assertTrue(); + expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue(); + done(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_TRUNCATE_SYNC_0000 + * @tc.name fileIO_test_truncate_sync_000 + * @tc.desc Test the truncateSync() interface that receives the fpath parameter. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_test_truncate_sync_000', 0, async function () { + let fpath = await nextFileName('fileIO_test_truncate_sync_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + expect(fileIO.truncateSync(fpath) == null).assertTrue(); + expect(fileio.statSync(fpath).size == 0).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileIO_test_truncate_sync_000 has failed for ' + e.message + ', code: ' + e.code); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_TRUNCATE_SYNC_0000 + * @tc.name fileIO_test_truncate_sync_001 + * @tc.desc Test the truncateSync() interface that receives the fd parameter. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_test_truncate_sync_001', 0, async function () { + let fpath = await nextFileName('fileIO_test_truncate_sync_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let fd = fileio.openSync(fpath, 0o2); + expect(isIntNum(fd)).assertTrue(); + let truncateLen = 5; + + try { + fileIO.truncateSync(fd, truncateLen); + let len = fileio.readSync(fd, new ArrayBuffer(4096)); + expect(len == truncateLen).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileIO_test_truncate_sync_001 has failed for ' + e.message + ', code: ' + e.code); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_TRUNCATE_SYNC_0010 + * @tc.name fileIO_test_truncate_sync_002 + * @tc.desc Test the truncateSync() interface that receives the fpath parameter. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_test_truncate_sync_002', 0, async function () { + let fpath = await nextFileName('fileIO_test_truncate_sync_002'); + + try { + let stat = fileIO.truncateSync(fpath); + console.info('fileIO_test_truncate_sync_002 = ' + stat); + expect(null).assertFail(); + } catch (e) { + expect(e.code == 13900002 && e.message == 'No such file or directory').assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_TRUNCATE_SYNC_0010 + * @tc.name fileIO_test_truncate_sync_003 + * @tc.desc Test the truncateSync() interface that receives the fd parameter. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_test_truncate_sync_003', 0, async function () { + let fpath = await nextFileName('fileIO_test_truncate_sync_003'); + expect(prepareFile(fpath, 'truncate')).assertTrue(); + let fd = fileio.openSync(fpath, 0o2); + expect(isIntNum(fd)).assertTrue(); + let truncateLen = 2; + try { + fileIO.truncateSync(fd, truncateLen); + let len = fileio.readSync(fd, new ArrayBuffer(4096)); + expect(len == truncateLen).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileIO_test_truncate_sync_003 has failed for ' + e.message + ', code: ' + e.code); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_TRUNCATE_SYNC_0020 + * @tc.name fileIO_test_truncate_sync_004 + * @tc.desc Test truncateSync() interfaces. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_test_truncate_sync_004', 0, function () { + try { + let stat = fileIO.truncateSync(); + console.info('fileIO_test_truncate_sync_004 = ' + stat); + } catch (e) { + expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_TRUNCATE_SYNC_0020 + * @tc.name fileio_test_truncate_sync_v9_005 + * @tc.desc Test truncateSync() interfaces. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_truncate_sync_005', 0, async function () { + let fpath = await nextFileName('fileio_test_truncate_sync_005'); + let truncateLen = 2; + try { + fileIO.truncateSync(fpath, truncateLen); + } catch (e) { + console.log('fileio_test_ftruncate_sync_005 has failed for ' + e.message + ', code: ' + e.code); + expect(!!e).assertTrue(); + } + }); + +}); +} + diff --git a/storage/storagefileiojstest/src/main/js/test/module_fileio/members/writeV9.test.js b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/writeV9.test.js new file mode 100644 index 000000000..c8e03b3a9 --- /dev/null +++ b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/writeV9.test.js @@ -0,0 +1,451 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the 'License'); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an 'AS IS' BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// import fileIO from '@ohos.file.fs'; +import { + fileio, fileIO, FILE_CONTENT, nextFileName, isIntNum, + describe, it, expect, +} from '../../Common'; + + export default function fileIOWrite() { + describe('fileIO_fs_write', function () { + + /** + * @tc.number SUB_DF_FILEIO_WRITE_SYNC_0000 + * @tc.name fileIO_test_write_sync_000 + * @tc.desc Test writeSync() interfaces. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_test_write_sync_000', 0, async function () { + let fpath = await nextFileName('fileIO_test_write_sync_000'); + + try { + let fd = fileio.openSync(fpath, 0o102, 0o664); + expect(isIntNum(fd)).assertTrue(); + expect(fileIO.writeSync(fd, FILE_CONTENT) == FILE_CONTENT.length).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileIO_test_write_sync_000 has failed for ' + e.message + ', code: ' + e.code); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_WRITE_SYNC_0010 + * @tc.name fileIO_test_write_sync_001 + * @tc.desc Test writeSync() interfaces. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_test_write_sync_001', 0, async function () { + let fpath = await nextFileName('fileIO_test_write_sync_001'); + + try { + let fd = fileio.openSync(fpath, 0o102, 0o664); + expect(isIntNum(fd)).assertTrue(); + expect( + fileIO.writeSync(fd, FILE_CONTENT, { + encoding: 'utf-8', + }) + == FILE_CONTENT.length).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileIO_test_write_sync_001 has failed for ' + e.message + ', code: ' + e.code); + expect(null).assertFail(); + } + }); + + + /** + * @tc.number SUB_DF_FILEIO_WRITE_SYNC_0020 + * @tc.name fileIO_test_write_sync_002 + * @tc.desc Test writeSync() interfaces. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_test_write_sync_002', 0, async function () { + let fpath = await nextFileName('fileIO_test_write_sync_002'); + + try { + let fd = fileio.openSync(fpath, 0o102, 0o664); + expect(isIntNum(fd)).assertTrue(); + expect( + fileIO.writeSync(fd, FILE_CONTENT, { + length: FILE_CONTENT.length - 1, + }) + == FILE_CONTENT.length - 1).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileIO_test_write_sync_002 has failed for ' + e.message + ', code: ' + e.code); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_WRITE_SYNC_0030 + * @tc.name fileIO_test_write_sync_003 + * @tc.desc Test writeSync() interfaces. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_test_write_sync_003', 0, async function () { + let fpath = await nextFileName('fileIO_test_write_sync_003'); + + try { + let fd = fileio.openSync(fpath, 0o102, 0o664); + expect(isIntNum(fd)).assertTrue(); + expect( + fileIO.writeSync(fd, FILE_CONTENT, { + length: 1, + }) + == 1).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileIO_test_write_sync_003 has failed for ' + e.message + ', code: ' + e.code); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_WRITE_SYNC_0040 + * @tc.name fileIO_test_write_sync_004 + * @tc.desc Test writeSync() interfaces. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_test_write_sync_004', 0, async function () { + let fpath = await nextFileName('fileIO_test_write_sync_004'); + let fd = fileio.openSync(fpath, 0o102, 0o664); + expect(isIntNum(fd)).assertTrue(); + const invalidLength = 9999; + + try { + fileIO.writeSync(fd, FILE_CONTENT, { + length: invalidLength, + }) + expect(null).assertFail(); + } catch (e) { + console.info('fileIO_test_write_sync_004 has failed for ' + e.message + ', code: ' + e.code); + expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_WRITE_SYNC_0050 + * @tc.name fileIO_test_write_sync_005 + * @tc.desc Test writeSync() interfaces. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_test_write_sync_005', 0, function () { + try { + fileIO.writeSync(-1, FILE_CONTENT); + expect(null).assertFail(); + } catch (e) { + console.log('fileIO_test_write_sync_005 has failed for ' + e.message + ', code: ' + e.code); + expect(e.code == 13900008 && e.message == 'Bad file descriptor').assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_WRITE_SYNC_0060 + * @tc.name fileIO_test_write_sync_006 + * @tc.desc Test writeSync() interfaces. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_test_write_sync_006', 0, async function () { + let fpath = await nextFileName('fileIO_test_write_sync_006'); + + try { + let fd = fileio.openSync(fpath, 0o102, 0o664); + expect(isIntNum(fd)).assertTrue(); + let writeNum = fileIO.writeSync(fd, new ArrayBuffer(4096)); + expect(writeNum == 4096).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileIO_test_write_sync_006 has failed for ' + e.message + ', code: ' + e.code); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_WRITE_ASYNC_0000 + * @tc.name fileIO_test_write_async_000 + * @tc.desc Test writeAsync() interfaces. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_write_async_000', 0, async function (done) { + let fpath = await nextFileName('fileIO_write_async_000'); + + try { + let fd = fileio.openSync(fpath, 0o102, 0o664); + expect(isIntNum(fd)).assertTrue(); + expect(await fileIO.write(fd, FILE_CONTENT) == FILE_CONTENT.length).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileIO_write_async_000 has failed for ' + e.message + ', code: ' + e.code); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_WRITE_ASYNC_0010 + * @tc.name fileIO_test_write_async_001 + * @tc.desc Test writeAsync() interfaces. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_test_write_async_001', 0, async function (done) { + let fpath = await nextFileName('fileIO_test_write_async_001'); + + try { + let fd = fileio.openSync(fpath, 0o102, 0o664); + expect(isIntNum(fd)).assertTrue(); + let writeNum = await fileIO.write(fd, FILE_CONTENT, { + length: 3, + }); + expect(writeNum == 3).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileIO_test_write_async_001 has failed for ' + e.message + ', code: ' + e.code); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_WRITE_ASYNC_0020 + * @tc.name fileIO_test_write_async_002 + * @tc.desc Test writeAsync() interfaces. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_test_write_async_002', 0, async function (done) { + let fpath = await nextFileName('fileIO_test_write_async_002'); + + try { + let fd = fileio.openSync(fpath, 0o102, 0o664); + expect(isIntNum(fd)).assertTrue(); + let writeNum = await fileIO.write(fd, FILE_CONTENT, { + length: 3, + offset: 5, + }); + expect(writeNum == 3).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileIO_test_write_async_002 has failed for ' + e.message + ', code: ' + e.code); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_WRITE_ASYNC_0030 + * @tc.name fileIO_test_write_async_003 + * @tc.desc Test writeAsync() interfaces. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_test_write_async_003', 0, async function (done) { + let fpath = await nextFileName('fileIO_test_write_async_003'); + + try { + let fd = fileio.openSync(fpath, 0o102, 0o664); + expect(isIntNum(fd)).assertTrue(); + let writeNum = await fileIO.write(fd, FILE_CONTENT, { + length: 4, + offset: 5, + encoding: 'utf-8', + }); + expect(writeNum == 4).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileIO_test_write_async_003 has failed for ' + e.message + ', code: ' + e.code); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_WRITE_ASYNC_0040 + * @tc.name fileIO_test_write_async_004 + * @tc.desc Test writeAsync() interfaces. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_test_write_async_004', 0, async function (done) { + let fpath = await nextFileName('fileIO_test_write_async_004'); + + try { + let fd = fileio.openSync(fpath, 0o102, 0o664); + expect(isIntNum(fd)).assertTrue(); + await fileIO.write(fd, new ArrayBuffer(4096), function ( + error, + bytesWritten + ) { + expect(bytesWritten == 4096).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + }); + done(); + } catch (e) { + console.log('fileIO_test_write_async_004 has failed for ' + e.message + ', code: ' + e.code); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_WRITE_ASYNC_0050 + * @tc.name fileIO_test_write_async_005 + * @tc.desc Test writeAsync() interfaces. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_test_write_async_005', 0, async function (done) { + let fpath = await nextFileName('fileIO_test_write_async_005'); + + try { + let fd = fileio.openSync(fpath, 0o102, 0o664); + expect(isIntNum(fd)).assertTrue(); + await fileIO.write( + fd, + FILE_CONTENT, + { + length: 5, + }, function (error, bytesWritten) { + expect(bytesWritten == 5).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } + ); + } catch (e) { + console.log('fileIO_test_write_async_005 has failed for ' + e.message + ', code: ' + e.code); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_WRITE_ASYNC_0060 + * @tc.name fileIO_test_write_async_006 + * @tc.desc Test writeAsync() interfaces. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_test_write_async_006', 0, async function (done) { + let fpath = await nextFileName('fileIO_test_write_async_006'); + + try { + let fd = fileio.openSync(fpath, 0o102, 0o664); + expect(isIntNum(fd)).assertTrue(); + await fileIO.write( + fd, + FILE_CONTENT, + { + length: 5, + offset: 5, + }, function (error, bytesWritten) { + expect(bytesWritten == 5).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } + ); + } catch (e) { + console.log('fileIO_test_write_async_006 has failed for ' + e.message + ', code: ' + e.code); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_WRITE_ASYNC_0070 + * @tc.name fileIO_test_write_async_007 + * @tc.desc Test writeAsync() interfaces. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_test_write_async_007', 0, async function (done) { + let fpath = await nextFileName('fileIO_test_write_async_007'); + + try { + let fd = fileio.openSync(fpath, 0o102, 0o664); + expect(isIntNum(fd)).assertTrue(); + await fileIO.write( + fd, + FILE_CONTENT, + { + length: 5, + offset: 5, + encoding: 'utf-8', + }, function (error, bytesWritten) { + expect(bytesWritten == 5).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } + ); + } catch (e) { + console.log('fileIO_test_write_async_007 has failed for ' + e.message + ', code: ' + e.code); + expect(null).assertFail(); + } + }); + +}); +} + -- GitLab