提交 bdcdbd83 编写于 作者: R raoxian

update fileio testcase

Signed-off-by: Nraoxian <raoxian@huawei.com>
上级 d03b3c3e
......@@ -74,10 +74,7 @@ export function fileToWriteOnly(fpath) {
return false
}
}
export function nextFileName1(testName) {
const BASE_PATH = '/data/accounts/account_0/appdata/ohos.acts.storage.fileio/cache/'
return BASE_PATH + testName + '_' + randomString(testName.length);
}
export async function nextFileName(testName) {
let context = featureAbility.getContext();
let data = await context.getCacheDir();
......
......@@ -59,20 +59,22 @@ describe('fileio_stream', function () {
* @tc.require
*/
it('fileio_test_stream_write_async_001', 0, async function (done) {
let fpath = nextFileName1('fileio_test_stream_write_async_001');
let fpath = await nextFileName('fileio_test_stream_write_async_001');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let ss = fileio.createStreamSync(fpath, 'r+');
expect(ss !== null).assertTrue();
ss.write(new ArrayBuffer(4096), { offset: 1, encoding: 'utf-8' }, function (err, bytesWritten) {
expect(bytesWritten == (FILE_CONTENT.length - 1)).assertTrue();
expect(fileio.unlinkSync(fpath) == null).assertTrue();
expect(bytesWritten == 4095).assertTrue();
fileio.unlinkSync(fpath);
ss.closeSync();
done();
});
done();
} catch (e) {
console.log('fileio_test_stream_write_async_001 has failed for ' + e);
} catch (err) {
console.info('fileio_test_stream_write_async_001 has failed for ' + err);
expect(null).assertFail();
done();
}
});
});
......@@ -166,16 +166,10 @@ describe('fileio_copyfile', function () {
it('fileio_copy_file_async_003', 0, async function (done) {
let fpath = await nextFileName('fileio_copy_file_async_003');
try {
fileio
.copyFile(1, fpath)
.then(function (err) {
})
.catch(function (e) {
expect(!!e).assertTrue();
done();
});
await fileio.copyFile(1, fpath);
} catch (e) {
expect(!!e).assertTrue();
console.log('fileio_copy_file_async_003 has failed for ' + e);
expect(e.message == "Invalid argument").assertTrue();
done();
}
});
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册