From 5a4cd7d35d0249fa28890abf572fe61251aa22a1 Mon Sep 17 00:00:00 2001 From: raoxian Date: Fri, 21 Jan 2022 10:44:44 +0800 Subject: [PATCH] =?UTF-8?q?fileio=E6=96=B0=E5=A2=9Eclose=EF=BC=8Cfdatasync?= =?UTF-8?q?Sync=E6=B5=8B=E8=AF=95=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: raoxian --- .../test/module_fileio/members/close.test.js | 72 ++++++++++++++++++- .../module_fileio/members/fdatasync.test.js | 71 +++++++++++------- 2 files changed, 117 insertions(+), 26 deletions(-) diff --git a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/close.test.js b/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/close.test.js index 08e52bd48..032e49a40 100644 --- a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/close.test.js +++ b/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/close.test.js @@ -15,7 +15,7 @@ import { fileio, - describe, it, expect, + describe, it, expect, nextFileName, prepareFile, FILE_CONTENT } from '../../Common'; describe('fileio_close', function () { @@ -55,4 +55,74 @@ describe('fileio_close', function () { console.log('fileio_test_close_sync_001 has failed for ' + e); } }) + + /** + * @tc.number SUB_DF_FILEIO_CLOSE_ASYNC_0000 + * @tc.name fileio_test_close_async_000 + * @tc.desc Test close() interfaces + * @tc.size MEDIUM(中型) + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_close_async_000', 0, async function (done) { + let fpath = await nextFileName('fileio_test_close_async_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath, 0o102, 0o666); + fileio.close(fd, function (err) { + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + }); + } catch (e) { + console.log('fileio_test_close_async_000 has failed for ' + e); + expect(null).assertFail(); + } + }) + + /** + * @tc.number SUB_DF_FILEIO_CLOSE_ASYNC_0010 + * @tc.name fileio_test_close_async_001 + * @tc.desc Test close() interfaces + * @tc.size MEDIUM(中型) + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_close_async_001', 0, async function (done) { + let fpath = await nextFileName('fileio_test_close_async_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath, 0o102, 0o666); + expect(await fileio.close(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_test_close_async_001 has failed for ' + e); + expect(null).assertFail(); + } + }) + + /** + * @tc.number SUB_DF_FILEIO_CLOSE_ASYNC_0020 + * @tc.name fileio_test_close_async_002 + * @tc.desc Test close() interfaces + * @tc.size MEDIUM(中型) + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_close_async_002', 0, async function (done) { + try { + await fileio.close(-1); + expect(null).assertFail(); + done(); + } catch (e) { + expect(!!e).assertTrue(); + console.log('fileio_test_close_async_002 has failed for ' + e); + done(); + } + }) }) diff --git a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/fdatasync.test.js b/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/fdatasync.test.js index 417b22bfd..43e766658 100644 --- a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/fdatasync.test.js +++ b/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/fdatasync.test.js @@ -48,7 +48,7 @@ describe('fileio_fdatasync', async function () { /** * @tc.number SUB_DF_FILEIO_FDATASYNC_ASYNC_0010 * @tc.name fileio_test_fdatasync_async_001 - * @tc.desc Test fdatasyncSync() interfaces. + * @tc.desc Test fdatasync() interfaces. * @tc.size MEDIUM * @tc.type Function * @tc.level Level 0 @@ -60,11 +60,17 @@ describe('fileio_fdatasync', async function () { try { let fd = fileio.openSync(fpath, 0o102, 0o666); - - fileio.write(fd, FILE_CONTENT); - expect(fileio.closeSync(fd) == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); + fileio + .fdatasync(fd) + .then(function (err) { + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + }) + .catch(function (err) { + expect(null).assertFail(); + }); } catch (e) { + console.log('fileio_test_fdatasync_async_001 has failed for ' + e); expect(null).assertFail(); } }); @@ -78,46 +84,61 @@ describe('fileio_fdatasync', async function () { * @tc.level Level 0 * @tc.require */ - it('fileio_test_fdatasync_async_002', 0, async function () { + it('fileio_test_fdatasync_async_002', 0, async function (done) { let fpath = await nextFileName('fileio_test_fdatasync_async_002'); expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); try { - let fd = fileio.openSync(fpath, 0o102, 0o666); - fileio - .fdatasync(fd) - .then(function (err) { - expect(fileio.closeSync(fd) == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - }) - .catch(function (err) { - expect(null).assertFail(); - }); + let fd = -1; + await fileio.fdatasync(fd); + expect(null).assertFail(); + done() } catch (e) { + expect(!!e).assertTrue(); console.log('fileio_test_fdatasync_async_002 has failed for ' + e); - expect(null).assertFail(); + done(); } }); /** - * @tc.number SUB_DF_FILEIO_FDATASYNC_ASYNC_0030 - * @tc.name fileio_test_fdatasync_async_003 - * @tc.desc Test fdatasync() interfaces. + * @tc.number SUB_DF_FILEIO_FDATASYNC_SYNC_0000 + * @tc.name fileio_test_fdatasync_sync_000 + * @tc.desc Test fdatasyncSync() interfaces. * @tc.size MEDIUM * @tc.type Function * @tc.level Level 0 * @tc.require */ - it('fileio_test_fdatasync_async_003', 0, async function () { - let fpath = await nextFileName('fileio_test_fdatasync_async_003'); + it('fileio_test_fdatasync_sync_000', 0, async function () { + let fpath = await nextFileName('fileio_test_fdatasync_sync_000'); expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); try { - let fd = -1; - await fileio.fdatasync(fd); + let fd = fileio.openSync(fpath, 0o102, 0o666); + expect(fileio.fdatasyncSync(fd) == null).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_test_fdatasync_sync_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_FDATASYNC_SYNC_0010 + * @tc.name fileio_test_fdatasync_sync_001 + * @tc.desc Test fdatasyncSync() interfaces. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_fdatasync_sync_001', 0, async function () { + try { + fileio.fdatasyncSync(-1); expect(null).assertFail(); } catch (e) { - console.log('fileio_test_fdatasync_async_003 has failed for ' + e); + console.log('fileio_test_fdatasync_sync_001 has failed for ' + e); } }); }); -- GitLab