未验证 提交 0747a7ca 编写于 作者: O openharmony_ci 提交者: Gitee

!3549 update file testcase

Merge pull request !3549 from raoxian/cherry-pick-1655171785
......@@ -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();
......
......@@ -36,16 +36,19 @@ describe('fileio_stream', function () {
try {
let ss = fileio.createStreamSync(fpath, 'r+');
expect(ss !== null).assertTrue();
ss.write(new ArrayBuffer(4096), {
let length = 4096;
ss.write(new ArrayBuffer(length), {
position: 1
}).then(function (len) {
expect(len == (FILE_CONTENT.length - 1)).assertTrue();
expect(fileio.unlinkSync(fpath) == null).assertTrue();
expect(len == length).assertTrue();
fileio.unlinkSync(fpath);
ss.closeSync();
done();
})
done();
} catch (e) {
console.log('fileio_test_stream_write_async_000 has failed for ' + e);
} catch (err) {
console.info('fileio_test_stream_write_async_000 has failed for ' + err);
expect(null).assertFail();
done();
}
});
......@@ -59,20 +62,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();
}
});
});
......@@ -169,14 +169,12 @@ describe('fileio_copyfile', function () {
fileio
.copyFile(1, fpath)
.then(function (err) {
})
.catch(function (e) {
expect(!!e).assertTrue();
fileio.unlinkSync(fpath);
done();
});
} catch (e) {
expect(!!e).assertTrue();
done();
console.log('fileio_copy_file_async_003 has failed for ' + e);
expect(null).assertFail();
}
});
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册