From 09fe36ef541998b0e6c9ed3fdb9e7dba0f6b7e02 Mon Sep 17 00:00:00 2001 From: zhangxingxia Date: Mon, 30 May 2022 17:53:45 +0800 Subject: [PATCH] update fileio xts Signed-off-by: zhangxingxia --- .../module_fileio/class_stream/read.test.js | 101 +++++++++++++++++ .../module_fileio/class_stream/write.test.js | 106 ++++++++++++++++++ 2 files changed, 207 insertions(+) diff --git a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/class_stream/read.test.js b/storage/storagefileiojstest/src/main/js/default/test/module_fileio/class_stream/read.test.js index 44ce2be7b..61c438d4b 100644 --- a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/class_stream/read.test.js +++ b/storage/storagefileiojstest/src/main/js/default/test/module_fileio/class_stream/read.test.js @@ -239,4 +239,105 @@ describe('fileio_stream_read', function () { } }); + /** + * @tc.number SUB_DF_FILEIO_STREAM_READASYNC_0800 + * @tc.name fileio_test_stream_read_async_008 + * @tc.desc Test read() interface, When the length is greater than the buffer length. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_stream_read_async_008', 0, async function (done) { + let fpath = await nextFileName('fileio_test_stream_read_async_008'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let ss = fileio.createStreamSync(fpath, 'r+'); + expect(ss !== null).assertTrue(); + try { + await ss.read(new ArrayBuffer(4096), {length: 4097}); + } catch (err) { + console.info('fileio_test_stream_read_async_008 has failed for ' + err); + expect(err.message == "Failed GetReadArg").assertTrue(); + ss.closeSync(); + fileio.unlinkSync(fpath); + done(); + } + }); + + /** + * @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.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_stream_read_async_009', 0, async function (done) { + let fpath = await nextFileName('fileio_test_stream_read_async_009'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + 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(); + ss.closeSync(); + fileio.unlinkSync(fpath); + done(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STREAM_READASYNC_1000 + * @tc.name fileio_test_stream_read_async_010 + * @tc.desc Test read() interface, When there are no parameters. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_stream_read_async_010', 0, async function (done) { + let fpath = await nextFileName('fileio_test_stream_read_async_010'); + 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_010 has failed for ' + err); + expect(err.message == "Number of arguments unmatched").assertTrue(); + ss.closeSync(); + fileio.unlinkSync(fpath); + done(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STREAM_READASYNC_1100 + * @tc.name fileio_test_stream_read_async_011 + * @tc.desc Test read() interface, When length>FILE_CONTENT.length. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_stream_read_async_011', 0, async function (done) { + let fpath = await nextFileName('fileio_test_stream_read_async_011'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let ss = fileio.createStreamSync(fpath, 'r+'); + expect(ss !== null).assertTrue(); + try { + let readout = await ss.read(new ArrayBuffer(4096), {length: FILE_CONTENT.length+1}); + expect(readout.bytesRead == FILE_CONTENT.length).assertTrue(); + ss.closeSync(); + fileio.unlinkSync(fpath); + done(); + } catch (err) { + console.info('fileio_test_stream_read_async_011 has failed for ' + err); + } + }); }); diff --git a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/class_stream/write.test.js b/storage/storagefileiojstest/src/main/js/default/test/module_fileio/class_stream/write.test.js index 9ffb75911..be098244e 100644 --- a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/class_stream/write.test.js +++ b/storage/storagefileiojstest/src/main/js/default/test/module_fileio/class_stream/write.test.js @@ -326,4 +326,110 @@ describe('fileio_stream_write', function () { done(); } }); + + /** + * @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.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_stream_write_async_011', 0, async function (done) { + let fpath = await nextFileName('fileio_test_stream_write_async_011'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let ss = fileio.createStreamSync(fpath, 'r+'); + 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(); + fileio.unlinkSync(fpath); + ss.closeSync(); + done(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_STREAM_WRITEASYNC_1200 + * @tc.name fileio_test_stream_write_async_012 + * @tc.desc Test write() interface,When the buffer parameter type is wrong. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_stream_write_async_012', 0, async function (done) { + let fpath = await nextFileName('fileio_test_stream_write_async_012'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let ss = fileio.createStreamSync(fpath, 'r+'); + expect(ss !== null).assertTrue(); + try { + + await ss.write(12, {length:-1}); + } catch (err) { + console.info('fileio_test_stream_write_async_012 has failed for ' + err); + expect(err.message == "Illegal write buffer or encoding").assertTrue(); + fileio.unlinkSync(fpath); + ss.closeSync(); + done(); + } + }); + + + /** + * @tc.number SUB_DF_FILEIO_STREAM_WRITEASYNC_1300 + * @tc.name fileio_test_stream_write_async_013 + * @tc.desc Test write() interface,When the length is greater than the buffer length. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_stream_write_async_013', 0, async function (done) { + let fpath = await nextFileName('fileio_test_stream_write_async_013'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let ss = fileio.createStreamSync(fpath, 'r+'); + expect(ss !== null).assertTrue(); + try { + await ss.write(new ArrayBuffer(4096), {length:4097}); + } catch (err) { + console.info('fileio_test_stream_write_async_013 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_1400 + * @tc.name fileio_test_stream_write_async_014 + * @tc.desc Test write() interface,When the length>content.length . + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_stream_write_async_014', 0, async function (done) { + let fpath = await nextFileName('fileio_test_stream_write_async_014'); + 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,{length:content.length+1}); + } catch (err) { + console.info('fileio_test_stream_write_async_014 has failed for ' + err); + expect(err.message == "Invalid option.length, buffer limit exceeded").assertTrue(); + fileio.unlinkSync(fpath); + ss.closeSync(); + done(); + } + }); }); -- GitLab