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 314593e955bfba95bf11db46865aa7d9fe24ad5b..dd1e4eb32b21205514b70f8183edc6380053e435 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 @@ -20,32 +20,33 @@ import { describe('fileio_close', function () { - /** * @tc.number SUB_DF_FILEIO_CLOSESYNC_0000 * @tc.name fileio_test_close_sync_000 - * @tc.desc Test closeSync() interfaces + * @tc.desc Test closeSync() interfaces. Test file has been closed. * @tc.size MEDIUM * @tc.type Function * @tc.level Level 0 * @tc.require */ it('fileio_test_close_sync_000', 0,async function () { - let fpath = await nextFileName('fileio_test_close_async_000'); + let fpath = await nextFileName('fileio_test_close_sync_000'); expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); try { let fd = fileio.openSync(fpath, 0o102, 0o666); fileio.closeSync(fd); - fileio.unlinkSync(fpath); + fileio.closeSync(fd); } catch (e) { console.info('fileio_test_close_sync_000 has failed for ' + e); + expect(e.message == 'Bad file descriptor').assertTrue(); + fileio.unlinkSync(fpath); } }) /** * @tc.number SUB_DF_FILEIO_CLOSESYNC_0100 * @tc.name fileio_test_close_sync_001 - * @tc.desc Test closeSync() interfaces,No parameters. + * @tc.desc Test closeSync() interfaces, No parameters. * @tc.size MEDIUM * @tc.type Function * @tc.level Level 0 @@ -61,9 +62,9 @@ describe('fileio_close', function () { }) /** - * @tc.number SUB_DF_FILEIO_CLOSESYNC_0010 - * @tc.name fileio_test_close_sync_001 - * @tc.desc Test closeSync() interfaces,fd is illegal. + * @tc.number SUB_DF_FILEIO_CLOSESYNC_0200 + * @tc.name fileio_test_close_sync_002 + * @tc.desc Test closeSync() interfaces, fd is illegal. * @tc.size MEDIUM * @tc.type Function * @tc.level Level 0 @@ -81,7 +82,7 @@ describe('fileio_close', function () { /** * @tc.number SUB_DF_FILEIO_CLOSE_ASYNC_0000 * @tc.name fileio_test_close_async_000 - * @tc.desc Test close() interfaces,return in callback mode. + * @tc.desc Test close() interfaces, return in callback mode. Test file has been closed. * @tc.size MEDIUM * @tc.type Function * @tc.level Level 0 @@ -90,23 +91,23 @@ describe('fileio_close', function () { 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) { + let fd = fileio.openSync(fpath, 0o102, 0o666); + fileio.close(fd, function (err) { + try { + fileio.closeSync(fd); + } catch (e) { + console.info('fileio_test_close_async_000 has failed for ' + e); + expect(e.message == 'Bad file descriptor').assertTrue(); fileio.unlinkSync(fpath); done(); - }); - } catch (e) { - console.info('fileio_test_close_async_000 has failed for ' + e); - expect(null).assertFail(); - } + } + }); }) /** - * @tc.number SUB_DF_FILEIO_CLOSE_ASYNC_0010 + * @tc.number SUB_DF_FILEIO_CLOSE_ASYNC_0100 * @tc.name fileio_test_close_async_001 - * @tc.desc Test close() interfaces,return in promise mode. + * @tc.desc Test close() interfaces, return in promise mode. Test file has been closed. * @tc.size MEDIUM * @tc.type Function * @tc.level Level 0 @@ -119,31 +120,31 @@ describe('fileio_close', function () { try { let fd = fileio.openSync(fpath, 0o102, 0o666); await fileio.close(fd); - fileio.unlinkSync(fpath); - done(); + fileio.closeSync(fd); } catch (e) { console.info('fileio_test_close_async_001 has failed for ' + e); - expect(null).assertFail(); + expect(e.message == 'Bad file descriptor').assertTrue(); + fileio.unlinkSync(fpath); + done(); } }) /** - * @tc.number SUB_DF_FILEIO_CLOSE_ASYNC_0020 + * @tc.number SUB_DF_FILEIO_CLOSE_ASYNC_0200 * @tc.name fileio_test_close_async_002 - * @tc.desc Test close() interfaces,there are multiple parameters. + * @tc.desc Test close() interfaces, there are multiple parameters. * @tc.size MEDIUM * @tc.type Function * @tc.level Level 0 * @tc.require */ it('fileio_test_close_async_002', 0, async function (done) { - - let fpath = await nextFileName('fileio_test_close_async_001'); + let fpath = await nextFileName('fileio_test_close_async_002'); expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); try { let fd = fileio.openSync(fpath, 0o102, 0o666); - fileio.close(fd, 2,function (err) { + fileio.close(fd, 2, function (err) { }); } catch (e) { console.info('fileio_test_close_async_002 has failed for ' + e); @@ -152,4 +153,42 @@ describe('fileio_close', function () { done(); } }) + + /** + * @tc.number SUB_DF_FILEIO_CLOSE_ASYNC_0300 + * @tc.name fileio_test_close_async_003 + * @tc.desc Test close() interfaces, fd is illegal. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_close_async_003', 0, async function (done) { + try { + await fileio.close(-1); + } catch (e) { + console.info('fileio_test_close_async_003 has failed for ' + e); + expect(e.message == "Bad file descriptor").assertTrue(); + done(); + } + }) + + /** + * @tc.number SUB_DF_FILEIO_CLOSE_ASYNC_0400 + * @tc.name fileio_test_close_async_004 + * @tc.desc Test close() interfaces, No parameters. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_close_async_004', 0, async function (done) { + try { + await fileio.close(); + } catch (e) { + console.info('fileio_test_close_async_004 has failed for ' + e); + expect(e.message == "Number of arguments unmatched").assertTrue(); + done(); + } + }) }) diff --git a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/copyFile.test.js b/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/copyFile.test.js index 25189f587f135374e8a4f20943567a4d0b7ae505..2e8132a8a8cdfa3ff08cf27eda858b55afeaeb11 100644 --- a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/copyFile.test.js +++ b/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/copyFile.test.js @@ -23,7 +23,7 @@ describe('fileio_copyfile', function () { /** * @tc.number SUB_DF_FILEIO_COPY_FILE_SYNC_0000 * @tc.name fileio_copy_file_sync_000 - * @tc.desc Test copyFileSync() interfaces. + * @tc.desc Test copyFileSync() interfaces. Test file copied successfully. * @tc.size MEDIUM * @tc.type Function * @tc.level Level 0 @@ -35,19 +35,20 @@ describe('fileio_copyfile', function () { expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); try { - expect(fileio.copyFileSync(fpath, fpathTarget) == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - expect(fileio.unlinkSync(fpathTarget) == null).assertTrue(); + fileio.copyFileSync(fpath, fpathTarget); + fileio.accessSync(fpathTarget); + fileio.unlinkSync(fpath); + fileio.unlinkSync(fpathTarget); } catch (e) { - console.log('fileio_copy_file_sync_000 has failed for ' + e); + console.info('fileio_copy_file_sync_000 has failed for ' + e); expect(null).assertFail(); } }); /** - * @tc.number SUB_DF_FILEIO_COPY_FILE_SYNC_0010 + * @tc.number SUB_DF_FILEIO_COPY_FILE_SYNC_0100 * @tc.name fileio_copy_file_sync_001 - * @tc.desc Test copyFileSync() interfaces. + * @tc.desc Test copyFileSync() interfaces. Test file copied successfully. * @tc.size MEDIUM * @tc.type Function * @tc.level Level 0 @@ -56,37 +57,63 @@ describe('fileio_copyfile', function () { it('fileio_copy_file_sync_001', 0, async function () { let fpath = await nextFileName('fileio_copy_file_sync_001'); let fpathTarget = fpath + 'tgt'; + let fd = fileio.openSync(fpath, 0o102, 0o666); try { - fileio.copyFileSync(fpath, fpathTarget); - expect(null).assertFail(); + fileio.copyFileSync(fd, fpathTarget); + fileio.accessSync(fpathTarget); + fileio.closeSync(fd); + fileio.unlinkSync(fpath); + fileio.unlinkSync(fpathTarget); } catch (e) { - console.log('fileio_copy_file_sync_001 has failed for ' + e); + console.info('fileio_copy_file_sync_001 has failed for ' + e); + expect(null).assertFail(); } }); /** - * @tc.number SUB_DF_FILEIO_COPY_FILE_SYNC_0020 + * @tc.number SUB_DF_FILEIO_COPY_FILE_SYNC_0200 * @tc.name fileio_copy_file_sync_002 - * @tc.desc Test copyFileSync() interfaces. + * @tc.desc Test copyFileSync() interfaces, invalid path. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_copy_file_sync_002', 0, async function () { + let fpath = await nextFileName('fileio_copy_file_sync_002'); + let fpathTarget = fpath + 'tgt'; + + try { + fileio.copyFileSync(fpath, fpathTarget); + } catch (e) { + console.info('fileio_copy_file_sync_002 has failed for ' + e); + expect(e.message == 'No such file or directory').assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_COPY_FILE_SYNC_0300 + * @tc.name fileio_copy_file_sync_003 + * @tc.desc Test copyFileSync() interfaces, No parameters. * @tc.size MEDIUM * @tc.type Function * @tc.level Level 0 * @tc.require */ - it('fileio_copy_file_sync_002', 0, function () { + it('fileio_copy_file_sync_003', 0, function () { try { fileio.copyFileSync(); - expect(null).assertFail(); } catch (e) { - console.log('fileio_copy_file_sync_002 has failed for ' + e); + console.info('fileio_copy_file_sync_003 has failed for ' + e); + expect(e.message == 'Number of arguments unmatched').assertTrue(); } }); /** * @tc.number SUB_DF_FILEIO_COPY_FILE_ASYNC_0000 * @tc.name fileio_copy_file_async_000 - * @tc.desc Test copyFileAsync() interfaces. + * @tc.desc Test copyFileAsync() interfaces, return in promise mode. Test file copied successfully. * @tc.size MEDIUM * @tc.type Function * @tc.level Level 0 @@ -98,46 +125,48 @@ describe('fileio_copyfile', function () { expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); try { - expect(await fileio.copyFile(fpath, fpathTarget) == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - expect(fileio.unlinkSync(fpathTarget) == null).assertTrue(); + await fileio.copyFile(fpath, fpathTarget); + fileio.accessSync(fpathTarget); + fileio.unlinkSync(fpath); + fileio.unlinkSync(fpathTarget); done(); } catch (e) { - console.log('fileio_copy_file_async_000 has failed for ' + e); + console.info('fileio_copy_file_async_000 has failed for ' + e); expect(null).assertFail(); } }); /** - * @tc.number SUB_DF_FILEIO_COPY_FILE_ASYNC_0010 + * @tc.number SUB_DF_FILEIO_COPY_FILE_ASYNC_0100 * @tc.name fileio_copy_file_async_001 - * @tc.desc Test copyFileAsync() interfaces. + * @tc.desc Test copyFileAsync() interfaces, return in callback mode. Test file copied successfully. * @tc.size MEDIUM * @tc.type Function * @tc.level Level 0 * @tc.require */ it('fileio_copy_file_async_001', 0, async function (done) { - let fpath = await nextFileName('fileio_copy_file_async_000'); + let fpath = await nextFileName('fileio_copy_file_async_001'); let fpathTarget = fpath + 'tgt'; expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); try { fileio.copyFile(fpath, fpathTarget, function (error) { - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - expect(fileio.unlinkSync(fpathTarget) == null).assertTrue(); + fileio.accessSync(fpathTarget); + fileio.unlinkSync(fpath); + fileio.unlinkSync(fpathTarget); done(); }); } catch (e) { - console.log('fileio_copy_file_async_000 has failed for ' + e); + console.info('fileio_copy_file_async_001 has failed for ' + e); expect(null).assertFail(); } }); /** - * @tc.number SUB_DF_FILEIO_COPY_FILE_ASYNC_0020 + * @tc.number SUB_DF_FILEIO_COPY_FILE_ASYNC_0200 * @tc.name fileio_copy_file_async_002 - * @tc.desc Test copyFileAsync() interfaces. + * @tc.desc Test copyFileAsync() interfaces, return in promise mode. Test file copied successfully. * @tc.size MEDIUM * @tc.type Function * @tc.level Level 0 @@ -146,18 +175,25 @@ describe('fileio_copyfile', function () { it('fileio_copy_file_async_002', 0, async function (done) { let fpath = await nextFileName('fileio_copy_file_async_002'); let fpathTarget = fpath + 'tgt'; + let fd = fileio.openSync(fpath, 0o102, 0o666); + try { - expect(await fileio.copyFile(fpath, fpathTarget).indexOf('') > -1).assertTrue(); - expect(null).assertFail(); - } catch (e) { + await fileio.copyFile(fd, fpathTarget); + fileio.accessSync(fpathTarget); + fileio.closeSync(fd); + fileio.unlinkSync(fpath); + fileio.unlinkSync(fpathTarget); done(); + } catch (e) { + console.info('fileio_copy_file_async_002 has failed for ' + e); + expect(null).assertFail(); } }); /** - * @tc.number SUB_DF_FILEIO_COPY_FILE_ASYNC_0030 + * @tc.number SUB_DF_FILEIO_COPY_FILE_ASYNC_0300 * @tc.name fileio_copy_file_async_003 - * @tc.desc Test copyFileAsync() interfaces. + * @tc.desc Test copyFileAsync() interfaces, Invalid path. * @tc.size MEDIUM * @tc.type Function * @tc.level Level 0 @@ -165,23 +201,20 @@ describe('fileio_copyfile', function () { */ it('fileio_copy_file_async_003', 0, async function (done) { let fpath = await nextFileName('fileio_copy_file_async_003'); + let fpathTarget = fpath + 'tgt'; try { - fileio - .copyFile(1, fpath) - .then(function (err) { - fileio.unlinkSync(fpath); - done(); - }); + await fileio.copyFile(fpath, fpathTarget); } catch (e) { - console.log('fileio_copy_file_async_003 has failed for ' + e); - expect(null).assertFail(); + console.info('fileio_copy_file_async_003 has failed for ' + e); + expect(e.message == 'No such file or directory').assertTrue(); + done(); } }); /** - * @tc.number SUB_DF_FILEIO_COPY_FILE_ASYNC_0040 + * @tc.number SUB_DF_FILEIO_COPY_FILE_ASYNC_0400 * @tc.name fileio_copy_file_async_004 - * @tc.desc Test copyFileAsync() interfaces. + * @tc.desc Test copyFileAsync() interfaces. Invalid argument. * @tc.size MEDIUM * @tc.type Function * @tc.level Level 0 @@ -189,13 +222,55 @@ describe('fileio_copyfile', function () { */ it('fileio_copy_file_async_004', 0, async function (done) { let fpath = await nextFileName('fileio_copy_file_async_004'); + try { + await fileio.copyFile(-1, fpath); + } catch (e) { + console.info('fileio_copy_file_async_004 has failed for ' + e); + expect(e.message == 'Invalid argument' || e.message == 'No such file or directory').assertTrue(); + done(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_COPY_FILE_ASYNC_0500 + * @tc.name fileio_copy_file_async_005 + * @tc.desc Test copyFileAsync() interfaces, Invalid mode. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_copy_file_async_005', 0, async function (done) { + let fpath = await nextFileName('fileio_copy_file_async_005'); + let fpathTarget = fpath + 'tgt'; expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { - expect(await fileio.copyFile(fpath, 1) == null).assertTrue(); - expect(fileio.unlinkSync(fpath) == null).assertTrue(); - expect(null).assertFail(); + fileio.copyFile(fpath, fpathTarget, '1', function (error) { + }); + } catch (e) { + console.info('fileio_copy_file_async_005 has failed for ' + e); + expect(e.message == 'Invalid mode' || e.message == 'Invalid arg').assertTrue(); + fileio.unlinkSync(fpath); done(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_COPY_FILE_ASYNC_0600 + * @tc.name fileio_copy_file_async_006 + * @tc.desc Test copyFileAsync() interfaces, No parameters. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_copy_file_async_006', 0, async function (done) { + try { + await fileio.copyFile(); } catch (e) { + console.info('fileio_copy_file_async_006 has failed for ' + e); + expect(e.message == 'Number of arguments unmatched').assertTrue(); done(); } });