From 88d48ee7bb005d3d880b99f891930671a54994ef Mon Sep 17 00:00:00 2001 From: raoxian Date: Thu, 28 Jul 2022 14:59:14 +0800 Subject: [PATCH] =?UTF-8?q?fixed=20967b181=20from=20https://gitee.com/stor?= =?UTF-8?q?age-sandboxing/xts=5Facts/pulls/4673=20=E4=BF=AE=E6=94=B9fileio?= =?UTF-8?q?=20dir.read()=E9=81=8D=E5=8E=86=E5=88=B0=E6=9C=AB=E5=B0=BE?= =?UTF-8?q?=E8=AF=BB=E5=8F=96=E5=BC=82=E5=B8=B8=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: raoxian --- .../test/module_fileio/class_dir/read.test.js | 72 ++++++++++++++++++- 1 file changed, 70 insertions(+), 2 deletions(-) diff --git a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/class_dir/read.test.js b/storage/storagefileiojstest/src/main/js/default/test/module_fileio/class_dir/read.test.js index c4a83c295..9912e6d22 100644 --- a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/class_dir/read.test.js +++ b/storage/storagefileiojstest/src/main/js/default/test/module_fileio/class_dir/read.test.js @@ -14,7 +14,7 @@ */ import { - fileio, FILE_CONTENT, prepareFile, nextFileName, isString, isBoolean, + fileio, FILE_CONTENT, prepareFile, nextFileName, isString, isBoolean, forceRemoveDir, describe, it, expect, } from '../../Common'; @@ -190,6 +190,40 @@ describe('fileio_dir_read', function () { } }); + /** + * @tc.number SUB_DF_FILEIO_DIR_READ_SYNC_NAME_0100 + * @tc.name fileio_dir_read_sync_name_001 + * @tc.desc Test Dir.readSync() interface. Synchronous loop reads next directory entry. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_dir_read_sync_name_001', 0, async function () { + let dpath = await nextFileName('fileio_dir_read_sync_name_001') + 'd'; + fileio.mkdirSync(dpath); + let fdpath = dpath; + + try { + for (let i = 0; i < 10; i++) { + console.info('time' + i); + dpath = dpath + '/d' + i; + fileio.mkdirSync(dpath); + } + let dir = fileio.opendirSync(fdpath); + let dirent = dir.readSync(); + while (dirent) { + fdpath = fdpath + '/' + dirent.name; + dir = fileio.opendirSync(fdpath); + dirent = dir.readSync(); + } + forceRemoveDir(dpath, 10); + } catch (e) { + console.info('fileio_dir_read_sync_name_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + /** * @tc.number SUB_DF_FILEIO_DIR_READ_SYNC_ISBLOCKDEVICE_0000 * @tc.name fileio_dir_read_sync_isBlockDevice_000 @@ -413,7 +447,41 @@ describe('fileio_dir_read', function () { } }); - + /** + * @tc.number SUB_DF_FILEIO_DIR_READ_ASYNC_NAME_0100 + * @tc.name fileio_dir_read_async_name_001 + * @tc.desc Test Dir.readAsync() interface. Asynchronously loop to read next directory item. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_dir_read_async_name_001', 0, async function (done) { + let dpath = await nextFileName('fileio_dir_read_async_name_001') + 'd'; + fileio.mkdirSync(dpath); + let fdpath = dpath; + + try { + for (let i = 0; i < 10; i++) { + console.info('time' + i); + dpath = dpath + '/d' + i; + fileio.mkdirSync(dpath); + } + let dir = fileio.opendirSync(fdpath); + let dirent = await dir.read(); + while (dirent) { + fdpath = fdpath + '/' + dirent.name; + dir = fileio.opendirSync(fdpath); + dirent = await dir.read(); + } + forceRemoveDir(dpath, 10); + done(); + } catch (e) { + console.info('fileio_dir_read_async_name_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + /** * @tc.number SUB_DF_FILEIO_DIR_READ_ASYNC_ISBLOCKDEVICE_0000 * @tc.name fileio_dir_read_async_isBlockDevice_000 -- GitLab