提交 de89279e 编写于 作者: Z zhangxingxia

update fileio xts

Signed-off-by: Nzhangxingxia <zhangxingxia1@huawei.com>
上级 679e4cec
......@@ -123,6 +123,7 @@ describe('fileio_stream_read', function () {
expect(ss !== null).assertTrue();
let readout = await ss.read(new ArrayBuffer(4096), {offset: 4096});
expect(readout.bytesRead == 0).assertTrue();
expect(readout.offset == 4096).assertTrue();
ss.closeSync();
fileio.unlinkSync(fpath);
done();
......@@ -151,10 +152,13 @@ describe('fileio_stream_read', function () {
expect(ss !== null).assertTrue();
let options = {
offset: 1,
position:5
position:6
}
let readout = await ss.read(new ArrayBuffer(4096),options);
expect(readout.bytesRead == FILE_CONTENT.length).assertTrue();
expect(readout.bytesRead == FILE_CONTENT.length-6).assertTrue();
expect(readout.offset == 1).assertTrue();
let result = String.fromCharCode.apply(null, new Uint8Array(readout.buffer.slice(readout.offset,readout.offset+readout.bytesRead)));
expect(result== "world").assertTrue();
ss.closeSync();
fileio.unlinkSync(fpath);
done();
......@@ -267,7 +271,7 @@ describe('fileio_stream_read', function () {
/**
* @tc.number SUB_DF_FILEIO_STREAM_READASYNC_0900
* @tc.name fileio_test_stream_read_async_009
* @tc.desc Test read() interface, When the length is negative.
* @tc.desc Test read() interface, When the length is negative,equivalent to omitting the parameter.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
......@@ -279,15 +283,13 @@ describe('fileio_stream_read', function () {
let ss = fileio.createStreamSync(fpath, 'r+');
expect(ss !== null).assertTrue();
try {
let readout = await ss.read(new ArrayBuffer(4096), {length: -1});
console.info("====>"+readout.bytesRead);
done();
} catch (err) {
console.info('fileio_test_stream_read_async_009 has failed for ' + err);
expect(err.message == "Failed GetReadArg").assertTrue();
let readout = await ss.read(new ArrayBuffer(16), {offset:13, length: -1});
expect(readout.bytesRead == 3).assertTrue();
ss.closeSync();
fileio.unlinkSync(fpath);
done();
} catch (err) {
console.info('fileio_test_stream_read_async_009 has failed for ' + err);
}
});
......@@ -340,4 +342,54 @@ describe('fileio_stream_read', function () {
console.info('fileio_test_stream_read_async_011 has failed for ' + err);
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_READASYNC_1200
* @tc.name fileio_test_stream_read_async_012
* @tc.desc Test read() interface, When the position is negative.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('fileio_test_stream_read_async_012', 0, async function (done) {
let fpath = await nextFileName('fileio_test_stream_read_async_012');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
let ss = fileio.createStreamSync(fpath, 'r+');
expect(ss !== null).assertTrue();
try {
await ss.read(new ArrayBuffer(4096), {position:-1});
} catch (err) {
console.info('fileio_test_stream_read_async_012 has failed for ' + err);
expect(err.message == "Failed GetReadArg").assertTrue();
ss.closeSync();
fileio.unlinkSync(fpath);
done();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_READASYNC_1300
* @tc.name fileio_test_stream_read_async_013
* @tc.desc Test read() interface,When the parameter type is wrong.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('fileio_test_stream_read_async_013', 0, async function (done) {
let fpath = await nextFileName('fileio_test_stream_read_async_013');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
let ss = fileio.createStreamSync(fpath, 'r+');
expect(ss !== null).assertTrue();
try {
await ss.read("");
} catch (err) {
console.info('fileio_test_stream_read_async_013 has failed for ' + err);
expect(err.message == "Failed GetReadArg").assertTrue();
ss.closeSync();
fileio.unlinkSync(fpath);
done();
}
});
});
......@@ -113,7 +113,7 @@ describe('fileio_stream_write', function () {
/**
* @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.desc Test write() interface,When the offset is 1 and position is 5.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
......@@ -126,9 +126,12 @@ describe('fileio_stream_write', function () {
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();
let content = "test";
let bytesWritten = await ss.write(content, {offset:1, position:5, encoding: 'utf-8' });
expect(bytesWritten == content.length-1).assertTrue();
let readOut = await ss.read(new ArrayBuffer(4096), {offset:0,position: 0});
let result = String.fromCharCode.apply(null, new Uint8Array(readOut.buffer.slice(readOut.offset,readOut.offset+readOut.bytesRead)));
expect(result == "helloestrld").assertTrue();
fileio.unlinkSync(fpath);
ss.closeSync();
done();
......@@ -330,7 +333,7 @@ describe('fileio_stream_write', function () {
/**
* @tc.number SUB_DF_FILEIO_STREAM_WRITEASYNC_1100
* @tc.name fileio_test_stream_write_async_011
* @tc.desc Test write() interface,When the length is negative.
* @tc.desc Test write() interface,When the length is negative,equivalent to omitting the parameter.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
......@@ -343,15 +346,13 @@ describe('fileio_stream_write', function () {
expect(ss !== null).assertTrue();
try {
let content = "hello, world";
let number = await ss.write(content, {length:-1});
console.info("====>"+number);
done();
} catch (err) {
console.info('fileio_test_stream_write_async_011 has failed for ' + err);
expect(err.message == "Invalid option.length, positive integer is desired").assertTrue();
let number = await ss.write(content, {offset:1 ,length:-1});
expect(number == content.length-1).assertTrue();
fileio.unlinkSync(fpath);
ss.closeSync();
done();
} catch (err) {
console.info('fileio_test_stream_write_async_011 has failed for ' + err);
}
});
......@@ -432,4 +433,30 @@ describe('fileio_stream_write', function () {
done();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_WRITEASYNC_1500
* @tc.name fileio_test_stream_write_async_015
* @tc.desc Test write() interface,When the position is negative.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('fileio_test_stream_write_async_015', 0, async function (done) {
let fpath = await nextFileName('fileio_test_stream_write_async_015');
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, {position:-1});
} catch (err) {
console.info('fileio_test_stream_write_async_015 has failed for ' + err);
expect(err.message == "option.position shall be positive number").assertTrue();
fileio.unlinkSync(fpath);
ss.closeSync();
done();
}
});
});
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册