提交 967b181c 编写于 作者: R raoxian

修改fileio dir.read()遍历到末尾读取异常问题

Signed-off-by: Nraoxian <raoxian@huawei.com>
上级 96b2eeb4
......@@ -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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册