提交 9bf33b13 编写于 作者: Z zhangxingxia

resolve issues

Signed-off-by: Nzhangxingxia <zhangxingxia1@huawei.com>
上级 9e3da4da
...@@ -2257,7 +2257,7 @@ describe('fileIOTest', function () { ...@@ -2257,7 +2257,7 @@ describe('fileIOTest', function () {
fileio.copyFileSync(-1, -1); fileio.copyFileSync(-1, -1);
} catch (err) { } catch (err) {
console.info('fileio_test_copy_file_sync_007 has failed for ' + err); console.info('fileio_test_copy_file_sync_007 has failed for ' + err);
expect(err.message == "Invalid argument").assertTrue(); expect(err.message == "Invalid argument" || err.message == "Bad file descriptor").assertTrue();
} }
}); });
......
...@@ -23,8 +23,8 @@ describe('fileio_stream', function () { ...@@ -23,8 +23,8 @@ describe('fileio_stream', function () {
/** /**
* @tc.number SUB_DF_FILEIO_STREAM_CREATESTREAMSYNC_0000 * @tc.number SUB_DF_FILEIO_STREAM_CREATESTREAMSYNC_0000
* @tc.name fileio_test_stream_create_stream_sync_000 * @tc.name fileio_test_stream_create_stream_sync_000
* @tc.desc Test createStreamSync() interface. * @tc.desc Test createStreamSync() interface, Open read-write file.
* @tc.size MEDIUM(中型) * @tc.size MEDIUM
* @tc.type Function * @tc.type Function
* @tc.level Level 0 * @tc.level Level 0
* @tc.require * @tc.require
...@@ -36,19 +36,19 @@ describe('fileio_stream', function () { ...@@ -36,19 +36,19 @@ describe('fileio_stream', function () {
try { try {
let ss = fileio.createStreamSync(fpath, 'r+'); let ss = fileio.createStreamSync(fpath, 'r+');
expect(ss !== null).assertTrue(); expect(ss !== null).assertTrue();
expect(ss.closeSync() == null).assertTrue(); ss.closeSync();
expect(fileio.unlinkSync(fpath) == null).assertTrue(); fileio.unlinkSync(fpath);
} catch (e) { } catch (err) {
console.log('fileio_test_stream_create_stream_sync_000 has failed for ' + e); console.info('fileio_test_stream_create_stream_sync_000 has failed for ' + err);
expect(null).assertFail(); expect(null).assertFail();
} }
}); });
/** /**
* @tc.number SUB_DF_FILEIO_STREAM_CREATESTREAMSYNC_0010 * @tc.number SUB_DF_FILEIO_STREAM_CREATESTREAMSYNC_0100
* @tc.name fileio_test_stream_create_stream_sync_001 * @tc.name fileio_test_stream_create_stream_sync_001
* @tc.desc Test createStreamSync() interface. * @tc.desc Test createStreamSync() interface, When file does not exist.
* @tc.size MEDIUM(中型) * @tc.size MEDIUM
* @tc.type Function * @tc.type Function
* @tc.level Level 0 * @tc.level Level 0
* @tc.require * @tc.require
...@@ -58,17 +58,17 @@ describe('fileio_stream', function () { ...@@ -58,17 +58,17 @@ describe('fileio_stream', function () {
try { try {
fileio.createStreamSync(fpath, 'r+'); fileio.createStreamSync(fpath, 'r+');
expect(null).assertFail(); } catch (err) {
} catch (e) { console.info('fileio_test_stream_create_stream_sync_001 has failed for ' + err);
console.log('fileio_test_stream_create_stream_sync_001 has failed for ' + e); expect(err.message == "No such file or directory").assertTrue();
} }
}); });
/** /**
* @tc.number SUB_DF_FILEIO_STREAM_CREATESTREAMSYNC_0020 * @tc.number SUB_DF_FILEIO_STREAM_CREATESTREAMSYNC_0200
* @tc.name fileio_test_stream_create_stream_sync_002 * @tc.name fileio_test_stream_create_stream_sync_002
* @tc.desc Test createStreamSync() interface. * @tc.desc Test createStreamSync() interface, When mode is invalid.
* @tc.size MEDIUM(中型) * @tc.size MEDIUM
* @tc.type Function * @tc.type Function
* @tc.level Level 0 * @tc.level Level 0
* @tc.require * @tc.require
...@@ -79,17 +79,18 @@ describe('fileio_stream', function () { ...@@ -79,17 +79,18 @@ describe('fileio_stream', function () {
try { try {
fileio.createStreamSync(fpath, 'ohos'); fileio.createStreamSync(fpath, 'ohos');
expect(null).assertFail(); } catch (err) {
} catch (e) { console.info('fileio_test_stream_create_stream_sync_002 has failed for ' + err);
expect(fileio.unlinkSync(fpath) == null).assertTrue(); expect(err.message == "Invalid argument").assertTrue();
fileio.unlinkSync(fpath);
} }
}); });
/** /**
* @tc.number SUB_DF_FILEIO_STREAM_READSYNC_0000 * @tc.number SUB_DF_FILEIO_STREAM_READSYNC_0000
* @tc.name fileio_test_stream_read_sync_000 * @tc.name fileio_test_stream_read_sync_000
* @tc.desc Test readSync() interface. * @tc.desc Test readSync() interface, read data from stream file.
* @tc.size MEDIUM(中型) * @tc.size MEDIUM
* @tc.type Function * @tc.type Function
* @tc.level Level 0 * @tc.level Level 0
* @tc.require * @tc.require
...@@ -103,48 +104,46 @@ describe('fileio_stream', function () { ...@@ -103,48 +104,46 @@ describe('fileio_stream', function () {
expect(ss !== null).assertTrue(); expect(ss !== null).assertTrue();
let len = ss.readSync(new ArrayBuffer(4096)); let len = ss.readSync(new ArrayBuffer(4096));
expect(len == FILE_CONTENT.length).assertTrue(); expect(len == FILE_CONTENT.length).assertTrue();
expect(ss.closeSync() == null).assertTrue(); ss.closeSync();
expect(fileio.unlinkSync(fpath) == null).assertTrue(); fileio.unlinkSync(fpath);
} catch (e) { } catch (err) {
console.log('fileio_test_stream_read_sync_000 has failed for ' + e); console.info('fileio_test_stream_read_sync_000 has failed for ' + err);
expect(null).assertFail(); expect(null).assertFail();
} }
}); });
/** /**
* @tc.number SUB_DF_FILEIO_STREAM_READSYNC_0010 * @tc.number SUB_DF_FILEIO_STREAM_READSYNC_0100
* @tc.name fileio_test_stream_read_sync_001 * @tc.name fileio_test_stream_read_sync_001
* @tc.desc Test the readSync method of class Stream. * @tc.desc Test the readSync method of class Stream,When offset equals buffer length..
* @tc.size MEDIUM(中型) * @tc.size MEDIUM
* @tc.type Function * @tc.type Function
* @tc.level Level 0 * @tc.level Level 0
* @tc.require * @tc.require
*/ */
it('fileio_test_stream_read_sync_001', 0, async function () { it('fileio_test_stream_read_sync_001', 0, async function () {
let bufLen = 5;
expect(FILE_CONTENT.length > bufLen).assertTrue();
let fpath = await nextFileName('fileio_test_stream_read_sync_001'); let fpath = await nextFileName('fileio_test_stream_read_sync_001');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try { try {
let ss = fileio.createStreamSync(fpath, 'r+'); let ss = fileio.createStreamSync(fpath, 'r+');
let len = ss.readSync(new ArrayBuffer(bufLen), { let len = ss.readSync(new ArrayBuffer(4096), {
offset: 1 offset: 4096
}); });
expect(len == (bufLen - 1)).assertTrue(); expect(len == 0).assertTrue();
expect(ss.closeSync() == null).assertTrue(); ss.closeSync();
expect(fileio.unlinkSync(fpath) == null).assertTrue(); fileio.unlinkSync(fpath);
} catch (e) { } catch (err) {
console.log('fileio_test_stream_read_sync_001 has failed for ' + e); console.info('fileio_test_stream_read_sync_001 has failed for ' + err);
expect(null).assertFail(); expect(null).assertFail();
} }
}); });
/** /**
* @tc.number SUB_DF_FILEIO_STREAM_READSYNC_0020 * @tc.number SUB_DF_FILEIO_STREAM_READSYNC_0200
* @tc.name fileio_test_stream_read_sync_002 * @tc.name fileio_test_stream_read_sync_002
* @tc.desc Test the readSync method of class Stream. * @tc.desc Test the readSync method of class Stream,When the length is 1.
* @tc.size MEDIUM(中型) * @tc.size MEDIUM
* @tc.type Function * @tc.type Function
* @tc.level Level 0 * @tc.level Level 0
* @tc.require * @tc.require
...@@ -159,19 +158,19 @@ describe('fileio_stream', function () { ...@@ -159,19 +158,19 @@ describe('fileio_stream', function () {
length: 1 length: 1
}); });
expect(len == 1).assertTrue(); expect(len == 1).assertTrue();
expect(ss.closeSync() == null).assertTrue(); ss.closeSync();
expect(fileio.unlinkSync(fpath) == null).assertTrue(); fileio.unlinkSync(fpath);
} catch (e) { } catch (err) {
console.log('fileio_test_stream_read_sync_002 has failed for ' + e); console.info('fileio_test_stream_read_sync_002 has failed for ' + err);
expect(null).assertFail(); expect(null).assertFail();
} }
}); });
/** /**
* @tc.number SUB_DF_FILEIO_STREAM_READSYNC_0030 * @tc.number SUB_DF_FILEIO_STREAM_READSYNC_0300
* @tc.name fileio_test_stream_read_sync_003 * @tc.name fileio_test_stream_read_sync_003
* @tc.desc Test the readSync method of class Stream. * @tc.desc Test the readSync method of class Stream,When the position is 1.
* @tc.size MEDIUM(中型) * @tc.size MEDIUM
* @tc.type Function * @tc.type Function
* @tc.level Level 0 * @tc.level Level 0
* @tc.require * @tc.require
...@@ -186,73 +185,73 @@ describe('fileio_stream', function () { ...@@ -186,73 +185,73 @@ describe('fileio_stream', function () {
position: 1 position: 1
}); });
expect(len == (FILE_CONTENT.length - 1)).assertTrue(); expect(len == (FILE_CONTENT.length - 1)).assertTrue();
expect(ss.closeSync() == null).assertTrue(); ss.closeSync();
expect(fileio.unlinkSync(fpath) == null).assertTrue(); fileio.unlinkSync(fpath);
} catch (e) { } catch (err) {
console.log('fileio_test_stream_read_sync_003 has failed for ' + e); console.info('fileio_test_stream_read_sync_003 has failed for ' + err);
expect(null).assertFail(); expect(null).assertFail();
} }
}); });
/** /**
* @tc.number SUB_DF_FILEIO_STREAM_READSYNC_0040 * @tc.number SUB_DF_FILEIO_STREAM_READSYNC_0400
* @tc.name fileio_test_stream_read_sync_004 * @tc.name fileio_test_stream_read_sync_004
* @tc.desc Test the readSync method of class Stream. * @tc.desc Test the readSync method of class Stream,When the offset is greater than the buffer length.
* @tc.size MEDIUM(中型) * @tc.size MEDIUM
* @tc.type Function * @tc.type Function
* @tc.level Level 0 * @tc.level Level 0
* @tc.require * @tc.require
*/ */
it('fileio_test_stream_read_sync_004', 0, async function () { it('fileio_test_stream_read_sync_004', 0, async function () {
let ss; let ss;
const invalidOffset = 99999;
let fpath = await nextFileName('fileio_test_stream_read_sync_004'); let fpath = await nextFileName('fileio_test_stream_read_sync_004');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try { try {
ss = fileio.createStreamSync(fpath, 'r+'); ss = fileio.createStreamSync(fpath, 'r+');
ss.readSync(new ArrayBuffer(4096), { ss.readSync(new ArrayBuffer(4096), {
offset: invalidOffset offset: 4097
}); });
expect(null).assertFail(); } catch (err) {
} catch (e) { console.info('fileio_test_stream_read_sync_004 has failed for ' + err);
expect(ss.closeSync() == null).assertTrue(); expect(err.message == "Invalid option.offset, buffer limit exceeded").assertTrue();
expect(fileio.unlinkSync(fpath) == null).assertTrue(); ss.closeSync();
fileio.unlinkSync(fpath);
} }
}); });
/** /**
* @tc.number SUB_DF_FILEIO_STREAM_READSYNC_0050 * @tc.number SUB_DF_FILEIO_STREAM_READSYNC_0500
* @tc.name fileio_test_stream_read_sync_005 * @tc.name fileio_test_stream_read_sync_005
* @tc.desc Test the readSync method of class Stream. * @tc.desc Test the readSync method of class Stream, When the length is greater than the buffer length.
* @tc.size MEDIUM(中型) * @tc.size MEDIUM
* @tc.type Function * @tc.type Function
* @tc.level Level 0 * @tc.level Level 0
* @tc.require * @tc.require
*/ */
it('fileio_test_stream_read_sync_005', 0, async function () { it('fileio_test_stream_read_sync_005', 0, async function () {
let ss; let ss;
const invalidLength = 9999;
let fpath = await nextFileName('fileio_test_stream_read_sync_005'); let fpath = await nextFileName('fileio_test_stream_read_sync_005');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try { try {
ss = fileio.createStreamSync(fpath, 'r+'); ss = fileio.createStreamSync(fpath, 'r+');
ss.readSync(new ArrayBuffer(4096), { ss.readSync(new ArrayBuffer(4096), {
length: invalidLength length: 4097
}); });
expect(null).assertFail(); } catch (err) {
} catch (e) { console.info('fileio_test_stream_read_sync_005 has failed for ' + err);
expect(ss.closeSync() == null).assertTrue(); expect(err.message == "Invalid option.length, buffer limit exceeded").assertTrue();
expect(fileio.unlinkSync(fpath) == null).assertTrue(); ss.closeSync();
fileio.unlinkSync(fpath);
} }
}); });
/** /**
* @tc.number SUB_DF_FILEIO_STREAM_READSYNC_0060 * @tc.number SUB_DF_FILEIO_STREAM_READSYNC_0600
* @tc.name fileio_test_stream_read_sync_006 * @tc.name fileio_test_stream_read_sync_006
* @tc.desc Test the readSync method of class Stream. * @tc.desc Test the readSync method of class Stream, When position is equal to the length of the file content plus one.
* @tc.size MEDIUM(中型) * @tc.size MEDIUM
* @tc.type Function * @tc.type Function
* @tc.level Level 0 * @tc.level Level 0
* @tc.require * @tc.require
...@@ -268,10 +267,10 @@ describe('fileio_stream', function () { ...@@ -268,10 +267,10 @@ describe('fileio_stream', function () {
position: invalidPos position: invalidPos
}); });
expect(len == 0).assertTrue(); expect(len == 0).assertTrue();
expect(ss.closeSync() == null).assertTrue(); ss.closeSync();
expect(fileio.unlinkSync(fpath) == null).assertTrue(); fileio.unlinkSync(fpath);
} catch (e) { } catch (err) {
console.log('fileio_test_stream_read_sync_006 has failed for ' + e); console.info('fileio_test_stream_read_sync_006 has failed for ' + err);
expect(null).assertFail(); expect(null).assertFail();
} }
}); });
...@@ -279,8 +278,8 @@ describe('fileio_stream', function () { ...@@ -279,8 +278,8 @@ describe('fileio_stream', function () {
/** /**
* @tc.number SUB_DF_FILEIO_STREAM_WRITESYNC_0000 * @tc.number SUB_DF_FILEIO_STREAM_WRITESYNC_0000
* @tc.name fileio_test_stream_write_sync_000 * @tc.name fileio_test_stream_write_sync_000
* @tc.desc Test writeSync() interface. * @tc.desc Test writeSync() interface, Write data to stream file.
* @tc.size MEDIUM(中型) * @tc.size MEDIUM
* @tc.type Function * @tc.type Function
* @tc.level Level 0 * @tc.level Level 0
* @tc.require * @tc.require
...@@ -293,10 +292,10 @@ describe('fileio_stream', function () { ...@@ -293,10 +292,10 @@ describe('fileio_stream', function () {
let ss = fileio.createStreamSync(fpath, 'r+'); let ss = fileio.createStreamSync(fpath, 'r+');
expect(ss !== null).assertTrue(); expect(ss !== null).assertTrue();
expect(ss.writeSync(FILE_CONTENT) == FILE_CONTENT.length).assertTrue(); expect(ss.writeSync(FILE_CONTENT) == FILE_CONTENT.length).assertTrue();
expect(ss.closeSync() == null).assertTrue(); ss.closeSync();
expect(fileio.unlinkSync(fpath) == null).assertTrue(); fileio.unlinkSync(fpath);
} catch (e) { } catch (err) {
console.log('fileio_test_stream_write_sync_000 has failed for ' + e); console.info('fileio_test_stream_write_sync_000 has failed for ' + err);
expect(null).assertFail(); expect(null).assertFail();
} }
}); });
......
...@@ -18,101 +18,105 @@ import { ...@@ -18,101 +18,105 @@ import {
describe, it, expect, describe, it, expect,
} from '../../Common'; } from '../../Common';
describe('fileio_stream', function () { describe('fileio_stream_close', function () {
/** /**
* @tc.number SUB_DF_FILEIO_STREAM_FDOPENSTREAMSYNC_0000 * @tc.number SUB_DF_FILEIO_STREAM_CLOSESYNC_0000
* @tc.name fileio_test_stream_fdopen_stream_sync_000 * @tc.name fileio_test_stream_close_sync_000
* @tc.desc Test fdopenStreamSync() interface * @tc.desc Test closeSync() interface,Close file stream.
* @tc.size MEDIUM(中型) * @tc.size MEDIUM
* @tc.type Function * @tc.type Function
* @tc.level Level 0 * @tc.level Level 0
* @tc.require * @tc.require
*/ */
it('fileio_test_stream_fdopen_stream_sync_000', 0, async function () { it('fileio_test_stream_close_sync_000', 0, async function () {
let fpath = await nextFileName('fileio_test_stream_fdopen_stream_sync_000'); let fpath = await nextFileName('fileio_test_stream_close_sync_000');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try { try {
let fd = fileio.openSync(fpath, 0o2); let fd = fileio.openSync(fpath, 0o2);
let ss = fileio.fdopenStreamSync(fd, 'r+'); let ss = fileio.fdopenStreamSync(fd, 'r+');
expect(ss !== null).assertTrue(); expect(ss !== null).assertTrue();
expect(ss.closeSync() == null).assertTrue(); ss.closeSync();
expect(fileio.unlinkSync(fpath) == null).assertTrue(); fileio.unlinkSync(fpath);
} catch (e) { } catch (err) {
console.log('fileio_test_stream_fdopen_stream_sync_000 has failed for ' + e); console.info('fileio_test_stream_close_sync_000 has failed for ' + err);
expect(null).assertFail(); expect(null).assertFail();
} }
}) })
/** /**
* @tc.number SUB_DF_FILEIO_STREAM_FDOPENSTREAMSYNC_0010 * @tc.number SUB_DF_FILEIO_STREAM_CLOSESYNC_0100
* @tc.name fileio_test_stream_fdopen_stream_sync_001 * @tc.name fileio_test_stream_close_sync_001
* @tc.desc Test fdopenStreamSync() interface * @tc.desc Test closeSync() interface,When there are parameters.
* @tc.size MEDIUM(中型) * @tc.size MEDIUM
* @tc.type Function * @tc.type Function
* @tc.level Level 0 * @tc.level Level 0
* @tc.require * @tc.require
*/ */
it('fileio_test_stream_fdopen_stream_sync_001', 0, function () { it('fileio_test_stream_close_sync_001', 0, async function () {
let fpath = await nextFileName('fileio_test_stream_close_sync_000');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try { try {
let ss = fileio.fdopenStreamSync(-1, 'r+'); let fd = fileio.openSync(fpath, 0o2);
expect(null).assertFail(); let ss = fileio.fdopenStreamSync(fd, 'r+');
} catch (e) { expect(ss !== null).assertTrue();
console.log('fileio_test_stream_fdopen_stream_sync_001 has failed for ' + e); ss.closeSync(1);
} catch (err) {
console.info('fileio_test_stream_close_sync_001 has failed for ' + err);
fileio.unlinkSync(fpath);
} }
}) })
/** /**
* @tc.number SUB_DF_FILEIO_STREAM_FDOPENSTREAMASYNC_0000 * @tc.number SUB_DF_FILEIO_STREAM_CLOSEASYNC_0000
* @tc.name fileio_test_stream_fdopen_stream_async_000 * @tc.name fileio_test_stream_close_async_000
* @tc.desc Test fdopenStreamSync() interface * @tc.desc Test close() interface,return in promise mode.
* @tc.size MEDIUM(中型) * @tc.size MEDIUM
* @tc.type Function * @tc.type Function
* @tc.level Level 0 * @tc.level Level 0
* @tc.require * @tc.require
*/ */
it('fileio_test_stream_fdopen_stream_async_000', 0, async function (done) { it('fileio_test_stream_close_async_000', 0, async function (done) {
let fpath = await nextFileName('fileio_test_stream_fdopen_stream_async_000'); let fpath = await nextFileName('fileio_test_stream_close_async_000');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try { try {
let fd = await fileio.openSync(fpath, 0o2); let fd = await fileio.openSync(fpath, 0o2);
let ss = await fileio.fdopenStreamSync(fd, 'r+'); let ss = await fileio.fdopenStreamSync(fd, 'r+');
expect(ss !== null).assertTrue(); expect(ss !== null).assertTrue();
expect(ss.closeSync() == null).assertTrue(); await ss.close();
expect(fileio.unlinkSync(fpath) == null).assertTrue(); fileio.unlinkSync(fpath);
done(); done();
} catch (e) { } catch (err) {
console.log('fileio_test_stream_fdopen_stream_async_000 has failed for ' + e); console.info('fileio_test_stream_close_async_000 has failed for ' + err);
expect(null).assertFail(); expect(null).assertFail();
} }
}); });
/** /**
* @tc.number SUB_DF_FILEIO_STREAM_FDOPENSTREAMASYNC_0010 * @tc.number SUB_DF_FILEIO_STREAM_CLOSEASYNC_0100
* @tc.name fileio_test_stream_fdopen_stream_async_001 * @tc.name fileio_test_stream_close_async_001
* @tc.desc Test fdopenStreamSync() interface * @tc.desc Test close() interface,return in callback mode.
* @tc.size MEDIUM(中型) * @tc.size MEDIUM
* @tc.type Function * @tc.type Function
* @tc.level Level 0 * @tc.level Level 0
* @tc.require * @tc.require
*/ */
it('fileio_test_stream_fdopen_stream_async_001', 0, async function (done) { it('fileio_test_stream_close_async_001', 0, async function (done) {
let fpath = await nextFileName('fileio_test_stream_fdopen_stream_async_001'); let fpath = await nextFileName('fileio_test_stream_close_async_001');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try { try {
let fd = await fileio.openSync(fpath, 0o2); let fd = await fileio.openSync(fpath, 0o2);
let ss = await fileio.fdopenStreamSync(fd, 'r+'); let ss = await fileio.fdopenStreamSync(fd, 'r+');
expect(ss !== null).assertTrue(); expect(ss !== null).assertTrue();
ss.close(function (err, stream) { ss.close(function (err) {
expect(fileio.unlinkSync(fpath) == null).assertTrue(); fileio.unlinkSync(fpath);
}) })
done(); done();
} catch (e) { } catch (err) {
console.log('fileio_test_stream_fdopen_stream_async_001 has failed for ' + e); console.info('fileio_test_stream_close_async_001 has failed for ' + err);
expect(null).assertFail(); expect(null).assertFail();
} }
}); });
......
...@@ -18,13 +18,13 @@ import { ...@@ -18,13 +18,13 @@ import {
describe, it, expect, describe, it, expect,
} from '../../Common'; } from '../../Common';
describe('fileio_stream', function () { describe('fileio_stream_flush', function () {
/** /**
* @tc.number SUB_DF_FILEIO_STREAM_FLUSHSYNC_0000 * @tc.number SUB_DF_FILEIO_STREAM_FLUSHSYNC_0000
* @tc.name fileio_test_stream_flush_sync_000 * @tc.name fileio_test_stream_flush_sync_000
* @tc.desc Test flushSync() interface * @tc.desc Test flushSync() interface, refresh file stream.
* @tc.size MEDIUM(中型) * @tc.size MEDIUM
* @tc.type Function * @tc.type Function
* @tc.level Level 0 * @tc.level Level 0
* @tc.require * @tc.require
...@@ -37,20 +37,46 @@ describe('fileio_stream', function () { ...@@ -37,20 +37,46 @@ describe('fileio_stream', function () {
let ss = fileio.createStreamSync(fpath, 'r+'); let ss = fileio.createStreamSync(fpath, 'r+');
expect(ss !== null).assertTrue(); expect(ss !== null).assertTrue();
expect(ss.writeSync(FILE_CONTENT) == FILE_CONTENT.length).assertTrue(); expect(ss.writeSync(FILE_CONTENT) == FILE_CONTENT.length).assertTrue();
expect(ss.flushSync() == null).assertTrue(); ss.flushSync();
expect(ss.closeSync() == null).assertTrue(); ss.closeSync();
expect(fileio.unlinkSync(fpath) == null).assertTrue(); fileio.unlinkSync(fpath);
} catch (e) { } catch (err) {
console.log('fileio_test_stream_flush_sync_000 has failed for ' + e); console.info('fileio_test_stream_flush_sync_000 has failed for ' + err);
expect(null).assertFail(); expect(null).assertFail();
} }
}); });
/**
* @tc.number SUB_DF_FILEIO_STREAM_FLUSHSYNC_0100
* @tc.name fileio_test_stream_flush_sync_001
* @tc.desc Test flushSync() interface, When there are parameters.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('fileio_test_stream_flush_sync_001', 0, async function () {
let fpath = await nextFileName('fileio_test_stream_flush_sync_001');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
let ss = fileio.createStreamSync(fpath, 'r+');
expect(ss !== null).assertTrue();
expect(ss.writeSync(FILE_CONTENT) == FILE_CONTENT.length).assertTrue();
try {
ss.flushSync(1);
} catch (err) {
console.info('fileio_test_stream_flush_sync_001 has failed for ' + err);
expect(err.message == "Number of arguments unmatched").assertTrue();
ss.closeSync();
fileio.unlinkSync(fpath);
}
});
/** /**
* @tc.number SUB_DF_FILEIO_STREAM_FLUSHASYNC_0000 * @tc.number SUB_DF_FILEIO_STREAM_FLUSHASYNC_0000
* @tc.name fileio_test_stream_flush_async_000 * @tc.name fileio_test_stream_flush_async_000
* @tc.desc Test flushSync() interface * @tc.desc Test flush() interface, refresh the file stream and return in promise mode.
* @tc.size MEDIUM(中型) * @tc.size MEDIUM
* @tc.type Function * @tc.type Function
* @tc.level Level 0 * @tc.level Level 0
* @tc.require * @tc.require
...@@ -62,25 +88,24 @@ describe('fileio_stream', function () { ...@@ -62,25 +88,24 @@ describe('fileio_stream', function () {
try { try {
let ss = await fileio.createStreamSync(fpath, 'r+'); let ss = await fileio.createStreamSync(fpath, 'r+');
expect(ss !== null).assertTrue(); expect(ss !== null).assertTrue();
expect(ss.writeSync(FILE_CONTENT) == FILE_CONTENT.length).assertTrue();
ss.flush().then( ss.flush().then(
function (err) { function (err) {
expect(!err).assertTrue(); ss.closeSync();
expect(ss.writeSync(FILE_CONTENT) == FILE_CONTENT.length).assertTrue(); fileio.unlinkSync(fpath);
expect(ss.closeSync() == null).assertTrue();
expect(fileio.unlinkSync(fpath) == null).assertTrue();
}) })
done(); done();
} catch (e) { } catch (err) {
console.log('fileio_test_stream_flush_async_000 has failed for ' + e); console.info('fileio_test_stream_flush_async_000 has failed for ' + err);
expect(null).assertFail(); expect(null).assertFail();
} }
}); });
/** /**
* @tc.number SUB_DF_FILEIO_STREAM_FLUSHASYNC_0010 * @tc.number SUB_DF_FILEIO_STREAM_FLUSHASYNC_0100
* @tc.name fileio_test_stream_flush_async_001 * @tc.name fileio_test_stream_flush_async_001
* @tc.desc Test flushSync() interface * @tc.desc Test flush() interface, refresh the file stream and return in callback mode.
* @tc.size MEDIUM(中型) * @tc.size MEDIUM
* @tc.type Function * @tc.type Function
* @tc.level Level 0 * @tc.level Level 0
* @tc.require * @tc.require
...@@ -94,13 +119,14 @@ describe('fileio_stream', function () { ...@@ -94,13 +119,14 @@ describe('fileio_stream', function () {
expect(ss !== null).assertTrue(); expect(ss !== null).assertTrue();
expect(ss.writeSync(FILE_CONTENT) == FILE_CONTENT.length).assertTrue(); expect(ss.writeSync(FILE_CONTENT) == FILE_CONTENT.length).assertTrue();
ss.flush(function (err) { ss.flush(function (err) {
expect(ss.closeSync() == null).assertTrue(); ss.closeSync();
expect(fileio.unlinkSync(fpath) == null).assertTrue(); fileio.unlinkSync(fpath);
done(); done();
}) })
} catch (e) { } catch (err) {
console.log('fileio_test_stream_flush_async_001 has failed for ' + e); console.info('fileio_test_stream_flush_async_001 has failed for ' + err);
expect(null).assertFail(); expect(null).assertFail();
} }
}); });
}); });
...@@ -18,13 +18,13 @@ import { ...@@ -18,13 +18,13 @@ import {
describe, it, expect, describe, it, expect,
} from '../../Common'; } from '../../Common';
describe('fileio_stream', function () { describe('fileio_stream_read', function () {
/** /**
* @tc.number SUB_DF_FILEIO_STREAM_READASYNC_0000 * @tc.number SUB_DF_FILEIO_STREAM_READASYNC_0000
* @tc.name fileio_test_stream_read_async_000 * @tc.name fileio_test_stream_read_async_000
* @tc.desc Test readAsync() interface * @tc.desc Test read() interface,return in promise mode.
* @tc.size MEDIUM(中型) * @tc.size MEDIUM
* @tc.type Function * @tc.type Function
* @tc.level Level 0 * @tc.level Level 0
* @tc.require * @tc.require
...@@ -38,20 +38,20 @@ describe('fileio_stream', function () { ...@@ -38,20 +38,20 @@ describe('fileio_stream', function () {
expect(ss !== null).assertTrue(); expect(ss !== null).assertTrue();
let readout = await ss.read(new ArrayBuffer(4096)); let readout = await ss.read(new ArrayBuffer(4096));
expect(readout.bytesRead == FILE_CONTENT.length).assertTrue(); expect(readout.bytesRead == FILE_CONTENT.length).assertTrue();
expect(ss.closeSync() == null).assertTrue(); ss.closeSync();
expect(fileio.unlinkSync(fpath) == null).assertTrue(); fileio.unlinkSync(fpath);
done(); done();
} catch (e) { } catch (err) {
console.log('fileio_test_stream_read_async_000 has failed for ' + e); console.info('fileio_test_stream_read_async_000 has failed for ' + err);
expect(null).assertFail(); expect(null).assertFail();
} }
}); });
/** /**
* @tc.number SUB_DF_FILEIO_STREAM_READASYNC_0010 * @tc.number SUB_DF_FILEIO_STREAM_READASYNC_0100
* @tc.name fileio_test_stream_read_async_001 * @tc.name fileio_test_stream_read_async_001
* @tc.desc Test readAsync() interface * @tc.desc Test read() interface, return in callback mode.
* @tc.size MEDIUM(中型) * @tc.size MEDIUM
* @tc.type Function * @tc.type Function
* @tc.level Level 0 * @tc.level Level 0
* @tc.require * @tc.require
...@@ -65,12 +65,178 @@ describe('fileio_stream', function () { ...@@ -65,12 +65,178 @@ describe('fileio_stream', function () {
expect(ss !== null).assertTrue(); expect(ss !== null).assertTrue();
ss.read(new ArrayBuffer(4096), null, function (err, readout) { ss.read(new ArrayBuffer(4096), null, function (err, readout) {
expect(readout.bytesRead == FILE_CONTENT.length).assertTrue(); expect(readout.bytesRead == FILE_CONTENT.length).assertTrue();
expect(ss.closeSync() == null).assertTrue(); ss.closeSync();
expect(fileio.unlinkSync(fpath) == null).assertTrue(); fileio.unlinkSync(fpath);
}); });
} catch (e) { } catch (err) {
console.log('fileio_test_stream_read_async_001 has failed for ' + e); console.info('fileio_test_stream_read_async_001 has failed for ' + err);
expect(null).assertFail(); expect(null).assertFail();
} }
}); });
/**
* @tc.number SUB_DF_FILEIO_STREAM_READASYNC_0200
* @tc.name fileio_test_stream_read_async_002
* @tc.desc Test read() interface, When the offset is 1 and the length is 5.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('fileio_test_stream_read_async_002', 0, async function (done) {
let fpath = await nextFileName('fileio_test_stream_read_async_002');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let ss = fileio.createStreamSync(fpath, 'r+');
expect(ss !== null).assertTrue();
let options = {
offset: 1,
length: 5
}
let readout = await ss.read(new ArrayBuffer(4096),options);
expect(readout.bytesRead == 5).assertTrue();
ss.closeSync();
fileio.unlinkSync(fpath);
done();
} catch (err) {
console.info('fileio_test_stream_read_async_002 has failed for ' + err);
expect(null).assertFail();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_READASYNC_0300
* @tc.name fileio_test_stream_read_async_003
* @tc.desc Test read() interface, When offset equals buffer length.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('fileio_test_stream_read_async_003', 0, async function (done) {
let fpath = await nextFileName('fileio_test_stream_read_async_003');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let ss = fileio.createStreamSync(fpath, 'r+');
expect(ss !== null).assertTrue();
let readout = await ss.read(new ArrayBuffer(4096), {offset: 4096});
expect(readout.bytesRead == 0).assertTrue();
ss.closeSync();
fileio.unlinkSync(fpath);
done();
} catch (err) {
console.info('fileio_test_stream_read_async_003 has failed for ' + err);
expect(null).assertFail();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_READASYNC_0400
* @tc.name fileio_test_stream_read_async_004
* @tc.desc Test read() interface, When the offset is 1 and the position is 5.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('fileio_test_stream_read_async_004', 0, async function (done) {
let fpath = await nextFileName('fileio_test_stream_read_async_004');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let ss = fileio.createStreamSync(fpath, 'r+');
expect(ss !== null).assertTrue();
let options = {
offset: 1,
position:5
}
let readout = await ss.read(new ArrayBuffer(4096),options);
expect(readout.bytesRead == FILE_CONTENT.length).assertTrue();
ss.closeSync();
fileio.unlinkSync(fpath);
done();
} catch (err) {
console.info('fileio_test_stream_read_async_004 has failed for ' + err);
expect(null).assertFail();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_READASYNC_0500
* @tc.name fileio_test_stream_read_async_005
* @tc.desc Test read() interface, When the offset is negative.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('fileio_test_stream_read_async_005', 0, async function (done) {
let fpath = await nextFileName('fileio_test_stream_read_async_005');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
let ss = fileio.createStreamSync(fpath, 'r+');
expect(ss !== null).assertTrue();
try {
await ss.read(new ArrayBuffer(4096), {offset: -1});
} catch (err) {
console.info('fileio_test_stream_read_async_005 has failed for ' + err);
expect(err.message == "Failed GetReadArg").assertTrue();
ss.closeSync();
fileio.unlinkSync(fpath);
done();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_READASYNC_0600
* @tc.name fileio_test_stream_read_async_006
* @tc.desc Test read() interface, When offset+length>buffer.size.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('fileio_test_stream_read_async_006', 0, async function (done) {
let fpath = await nextFileName('fileio_test_stream_read_async_006');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
let ss = fileio.createStreamSync(fpath, 'r+');
expect(ss !== null).assertTrue();
try {
await ss.read(new ArrayBuffer(4096), {offset: 1,length:4096});
} catch (err) {
console.info('fileio_test_stream_read_async_006 has failed for ' + err);
expect(err.message == "Failed GetReadArg").assertTrue();
ss.closeSync();
fileio.unlinkSync(fpath);
done();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_READASYNC_0700
* @tc.name fileio_test_stream_read_async_007
* @tc.desc Test read() interface, When the offset is greater than the buffer length.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('fileio_test_stream_read_async_007', 0, async function (done) {
let fpath = await nextFileName('fileio_test_stream_read_async_007');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
let ss = fileio.createStreamSync(fpath, 'r+');
expect(ss !== null).assertTrue();
try {
await ss.read(new ArrayBuffer(4096), {offset: 4097});
} catch (err) {
console.info('fileio_test_stream_read_async_007 has failed for ' + err);
expect(err.message == "Failed GetReadArg").assertTrue();
ss.closeSync();
fileio.unlinkSync(fpath);
done();
}
});
}); });
...@@ -18,13 +18,13 @@ import { ...@@ -18,13 +18,13 @@ import {
describe, it, expect, describe, it, expect,
} from '../../Common'; } from '../../Common';
describe('fileio_stream', function () { describe('fileio_stream_write', function () {
/** /**
* @tc.number SUB_DF_FILEIO_STREAM_WRITEASYNC_0000 * @tc.number SUB_DF_FILEIO_STREAM_WRITEASYNC_0000
* @tc.name fileio_test_stream_write_async_000 * @tc.name fileio_test_stream_write_async_000
* @tc.desc Test Stream.write() interface * @tc.desc Test write() interface,When the position is 1,return in promise mode.
* @tc.size MEDIUM(中型) * @tc.size MEDIUM
* @tc.type Function * @tc.type Function
* @tc.level Level 0 * @tc.level Level 0
* @tc.require * @tc.require
...@@ -41,21 +41,22 @@ describe('fileio_stream', function () { ...@@ -41,21 +41,22 @@ describe('fileio_stream', function () {
position: 1 position: 1
}).then(function (len) { }).then(function (len) {
expect(len == length).assertTrue(); expect(len == length).assertTrue();
expect(fileio.unlinkSync(fpath) == null).assertTrue(); fileio.unlinkSync(fpath);
ss.closeSync();
done(); done();
}) })
} catch (e) { } catch (err) {
console.log('fileio_test_stream_write_async_000 has failed for ' + e); console.info('fileio_test_stream_write_async_000 has failed for ' + err);
expect(null).assertFail(); expect(null).assertFail();
done(); done();
} }
}); });
/** /**
* @tc.number SUB_DF_FILEIO_STREAM_WRITEASYNC_0010 * @tc.number SUB_DF_FILEIO_STREAM_WRITEASYNC_0100
* @tc.name fileio_test_stream_write_async_001 * @tc.name fileio_test_stream_write_async_001
* @tc.desc Test Stream.write() interface * @tc.desc Test write() interface,return in callback mode.
* @tc.size MEDIUM(中型) * @tc.size MEDIUM
* @tc.type Function * @tc.type Function
* @tc.level Level 0 * @tc.level Level 0
* @tc.require * @tc.require
...@@ -67,17 +68,262 @@ describe('fileio_stream', function () { ...@@ -67,17 +68,262 @@ describe('fileio_stream', function () {
try { try {
let ss = fileio.createStreamSync(fpath, 'r+'); let ss = fileio.createStreamSync(fpath, 'r+');
expect(ss !== null).assertTrue(); expect(ss !== null).assertTrue();
let length = 4096; ss.write(new ArrayBuffer(4096), { offset: 1, encoding: 'utf-8' }, function (err, bytesWritten) {
let offset = 1; expect(bytesWritten == 4095).assertTrue();
ss.write(new ArrayBuffer(length), { offset: offset, encoding: 'utf-8' }, function (err, bytesWritten) { fileio.unlinkSync(fpath);
expect(bytesWritten == (length - offset)).assertTrue(); ss.closeSync();
expect(fileio.unlinkSync(fpath) == null).assertTrue();
done(); done();
}); });
} catch (e) { } catch (err) {
console.log('fileio_test_stream_write_async_001 has failed for ' + e); console.info('fileio_test_stream_write_async_001 has failed for ' + err);
expect(null).assertFail();
done();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_WRITEASYNC_0200
* @tc.name fileio_test_stream_write_async_002
* @tc.desc Test write() interface,When the offset is 1.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('fileio_test_stream_write_async_002', 0, async function (done) {
let fpath = await nextFileName('fileio_test_stream_write_async_002');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let ss = fileio.createStreamSync(fpath, 'r+');
expect(ss !== null).assertTrue();
let content = "hello, world";
let bytesWritten = await ss.write(content, { offset: 1, length: 5, encoding: 'utf-8' });
expect(bytesWritten == 5).assertTrue();
fileio.unlinkSync(fpath);
ss.closeSync();
done();
} catch (err) {
console.info('fileio_test_stream_write_async_002 has failed for ' + err);
expect(null).assertFail();
done();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_WRITEASYNC_0300
* @tc.name fileio_test_stream_write_async_003
* @tc.desc Test write() interface,When the length is 1.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('fileio_test_stream_write_async_003', 0, async function (done) {
let fpath = await nextFileName('fileio_test_stream_write_async_003');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let ss = fileio.createStreamSync(fpath, 'r+');
expect(ss !== null).assertTrue();
let content = "hello, world";
let bytesWritten = await ss.write(content, { length: 1, encoding: 'utf-8' });
expect(bytesWritten == 1).assertTrue();
fileio.unlinkSync(fpath);
ss.closeSync();
done();
} catch (err) {
console.info('fileio_test_stream_write_async_003 has failed for ' + err);
expect(null).assertFail();
done();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_WRITEASYNC_0400
* @tc.name fileio_test_stream_write_async_004
* @tc.desc Test write() interface,When there is only the first parameter.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('fileio_test_stream_write_async_004', 0, async function (done) {
let fpath = await nextFileName('fileio_test_stream_write_async_004');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let ss = fileio.createStreamSync(fpath, 'r+');
expect(ss !== null).assertTrue();
let content = "hello, world";
let bytesWritten = await ss.write(content);
expect(bytesWritten == content.length).assertTrue();
fileio.unlinkSync(fpath);
ss.closeSync();
done();
} catch (err) {
console.info('fileio_test_stream_write_async_004 has failed for ' + err);
expect(null).assertFail(); expect(null).assertFail();
done(); done();
} }
}); });
/**
* @tc.number SUB_DF_FILEIO_STREAM_WRITEASYNC_0500
* @tc.name fileio_test_stream_write_async_005
* @tc.desc Test write() interface,When offset equals buffer length.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('fileio_test_stream_write_async_005', 0, async function (done) {
let fpath = await nextFileName('fileio_test_stream_write_async_005');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let ss = fileio.createStreamSync(fpath, 'r+');
expect(ss !== null).assertTrue();
let content = "hello, world";
let bytesWritten = await ss.write(content, {offset: content.length});
expect(bytesWritten == 0).assertTrue();
fileio.unlinkSync(fpath);
ss.closeSync();
done();
} catch (err) {
console.info('fileio_test_stream_write_async_005 has failed for ' + err);
expect(null).assertFail();
done();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_WRITEASYNC_0600
* @tc.name fileio_test_stream_write_async_006
* @tc.desc Test write() interface,When offset+length>buffer.size.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('fileio_test_stream_write_async_006', 0, async function (done) {
let fpath = await nextFileName('fileio_test_stream_write_async_006');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
let ss = fileio.createStreamSync(fpath, 'r+');
expect(ss !== null).assertTrue();
try {
let content = "hello, world";
await ss.write(content,{offset: 5, length:10});
done();
} catch (err) {
console.info('fileio_test_stream_write_async_006 has failed for ' + err);
expect(err.message == "Invalid option.length, buffer limit exceeded").assertTrue();
fileio.unlinkSync(fpath);
ss.closeSync();
done();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_WRITEASYNC_0700
* @tc.name fileio_test_stream_write_async_007
* @tc.desc Test write() interface,When the offset is greater than the buffer length.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('fileio_test_stream_write_async_007', 0, async function (done) {
let fpath = await nextFileName('fileio_test_stream_write_async_007');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
let ss = fileio.createStreamSync(fpath, 'r+');
expect(ss !== null).assertTrue();
try {
let content = "hello, world";
await ss.write(content, {offset:content.length+1});
} catch (err) {
console.info('fileio_test_stream_write_async_007 has failed for ' + err);
expect(err.message == "Invalid option.offset, buffer limit exceeded").assertTrue();
fileio.unlinkSync(fpath);
ss.closeSync();
done();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_WRITEASYNC_0800
* @tc.name fileio_test_stream_write_async_008
* @tc.desc Test write() interface,when encoding invalid.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('fileio_test_stream_write_async_008', 0, async function (done) {
let fpath = await nextFileName('fileio_test_stream_write_async_008');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
let ss = fileio.createStreamSync(fpath, 'r+');
expect(ss !== null).assertTrue();
try {
await ss.write("hello, world", {encoding: 'GB2312' });
} catch (err) {
console.info('fileio_test_stream_write_async_008 has failed for ' + err);
expect(err.message == "Illegal write buffer or encoding").assertTrue();
ss.closeSync();
fileio.unlinkSync(fpath);
done();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_WRITEASYNC_0900
* @tc.name fileio_test_stream_write_async_009
* @tc.desc Test write() interface,When there are no parameters.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('fileio_test_stream_write_async_009', 0, async function (done) {
let fpath = await nextFileName('fileio_test_stream_write_async_009');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
let ss = fileio.createStreamSync(fpath, 'r+');
expect(ss !== null).assertTrue();
try {
await ss.write();
} catch (err) {
console.info('fileio_test_stream_write_async_009 has failed for ' + err);
expect(err.message == "Number of arguments unmatched").assertTrue();
fileio.unlinkSync(fpath);
ss.closeSync();
done();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_WRITEASYNC_1000
* @tc.name fileio_test_stream_write_async_010
* @tc.desc Test write() interface,When the offset is negative.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('fileio_test_stream_write_async_010', 0, async function (done) {
let fpath = await nextFileName('fileio_test_stream_write_async_010');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
let ss = fileio.createStreamSync(fpath, 'r+');
expect(ss !== null).assertTrue();
try {
let content = "hello, world";
await ss.write(content, {offset:-1});
} catch (err) {
console.info('fileio_test_stream_write_async_010 has failed for ' + err);
expect(err.message == "Invalid option.offset, positive integer is desired").assertTrue();
fileio.unlinkSync(fpath);
ss.closeSync();
done();
}
});
}); });
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册