diff --git a/storage/storagefileiojstest/Test.json b/storage/storagefileiojstest/Test.json index 8dde280edd1704f62858f5a3d041345ec6d7eed1..b0a0edc17c4ae32b7e47522f0e78a1a1567f738b 100644 --- a/storage/storagefileiojstest/Test.json +++ b/storage/storagefileiojstest/Test.json @@ -2,8 +2,8 @@ "description": "Configuration for storage fileio Tests", "driver": { "type": "OHJSUnitTest", - "test-timeout": "1800000", - "shell-timeout": "1800000", + "test-timeout": "600000", + "shell-timeout": "600000", "bundle-name": "ohos.acts.storage.fileio", "package-name": "ohos.acts.storage.fileio" }, diff --git a/storage/storagefileiojstest/src/main/js/test/module_fileio/members/rmdir.test.js b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/rmdir.test.js index 6060b2c5ed55ce7f09fb468273f962b317f5d9a2..9e1f2fde3d2936f83d98e089766084be78194452 100644 --- a/storage/storagefileiojstest/src/main/js/test/module_fileio/members/rmdir.test.js +++ b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/rmdir.test.js @@ -108,45 +108,48 @@ describe('fileio_rmdir', function () { /** * @tc.number SUB_STORAGE_FileIO_RMDIR_SYNC_0300 * @tc.name fileio_test_rmdir_sync_003 - * @tc.desc Test rmdirSync() interface. Invalid path. + * @tc.desc Test rmdirSync() interface. The path contains ../, normal call. * @tc.size MEDIUM * @tc.type Function * @tc.level Level 0 * @tc.require */ it('fileio_test_rmdir_sync_003', 0, async function () { - let dpath = await nextFileName('fileio_test_rmdir_sync_003') + 'd'; + let dpath = await nextFileName('../cache/fileio_test_rmdir_sync_003') + 'd'; try { + fileio.mkdirSync(dpath); fileio.rmdirSync(dpath); } catch (err) { console.info('fileio_test_rmdir_sync_003 has failed for ' + err); - expect(isInclude(err.message, 'No such file or directory')).assertTrue(); + expect(null).assertFail(); } }); /** * @tc.number SUB_STORAGE_FileIO_RMDIR_SYNC_0400 * @tc.name fileio_test_rmdir_sync_004 - * @tc.desc Test rmdirSync() interface. No parameters. + * @tc.desc Test rmdirSync() interface. Invalid path. * @tc.size MEDIUM * @tc.type Function * @tc.level Level 0 * @tc.require */ it('fileio_test_rmdir_sync_004', 0, async function () { + let dpath = await nextFileName('fileio_test_rmdir_sync_004') + 'd'; + try { - fileio.rmdirSync(); + fileio.rmdirSync(dpath); } catch (err) { console.info('fileio_test_rmdir_sync_004 has failed for ' + err); - expect(isInclude(err.message, 'Number of arguments unmatched')).assertTrue(); + expect(isInclude(err.message, 'No such file or directory')).assertTrue(); } }); /** * @tc.number SUB_STORAGE_FileIO_RMDIR_SYNC_0500 * @tc.name fileio_test_rmdir_sync_005 - * @tc.desc Test rmdirSync() interface. Invalid path. + * @tc.desc Test rmdirSync() interface. No parameters. * @tc.size MEDIUM * @tc.type Function * @tc.level Level 0 @@ -154,29 +157,47 @@ describe('fileio_rmdir', function () { */ it('fileio_test_rmdir_sync_005', 0, async function () { try { - fileio.rmdirSync(''); + fileio.rmdirSync(); } catch (err) { console.info('fileio_test_rmdir_sync_005 has failed for ' + err); - expect(isInclude(err.message, 'No such file or directory')).assertTrue(); + expect(isInclude(err.message, 'Number of arguments unmatched')).assertTrue(); } }); /** * @tc.number SUB_STORAGE_FileIO_RMDIR_SYNC_0600 * @tc.name fileio_test_rmdir_sync_006 - * @tc.desc Test rmdirSync() interface. Not a directory. + * @tc.desc Test rmdirSync() interface. Invalid path. * @tc.size MEDIUM * @tc.type Function * @tc.level Level 0 * @tc.require */ it('fileio_test_rmdir_sync_006', 0, async function () { - let fpath = await nextFileName('fileio_test_rmdir_sync_006'); + try { + fileio.rmdirSync(''); + } catch (err) { + console.info('fileio_test_rmdir_sync_006 has failed for ' + err); + expect(isInclude(err.message, 'No such file or directory')).assertTrue(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_RMDIR_SYNC_0700 + * @tc.name fileio_test_rmdir_sync_007 + * @tc.desc Test rmdirSync() interface. Not a directory. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_rmdir_sync_007', 0, async function () { + let fpath = await nextFileName('fileio_test_rmdir_sync_007'); expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); try { fileio.rmdirSync(fpath); } catch (err) { - console.info('fileio_test_rmdir_sync_006 has failed for ' + err); + console.info('fileio_test_rmdir_sync_007 has failed for ' + err); expect(isInclude(err.message, 'Not a directory')).assertTrue(); fileio.unlinkSync(fpath); } @@ -282,10 +303,10 @@ describe('fileio_rmdir', function () { */ it('fileio_test_rmdir_async_003', 0, async function (done) { let dpath = await nextFileName('fileio_test_rmdir_async_003') + 'd'; - let fpath = dpath + '/rmdir_async_001'; - let ffpath = dpath + '/rmdir_async_001_1'; - let ddpath = dpath + '/rmdir_async_001_1d'; - let fffpath = ddpath + '/rmdir_async_002'; + let fpath = dpath + '/rmdir_async_003'; + let ffpath = dpath + '/rmdir_async_003_1'; + let ddpath = dpath + '/rmdir_async_003_1d'; + let fffpath = ddpath + '/rmdir_async_003_2'; fileio.mkdirSync(dpath); fileio.mkdirSync(ddpath); expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); @@ -305,28 +326,28 @@ describe('fileio_rmdir', function () { /** * @tc.number SUB_STORAGE_FileIO_RMDIR_ASYNC_0400 * @tc.name fileio_test_rmdir_async_004 - * @tc.desc Test rmdir() interface. Invalid path. + * @tc.desc Test rmdirSync() interface. The path contains ../, normal call. * @tc.size MEDIUM * @tc.type Function * @tc.level Level 0 * @tc.require */ - it('fileio_test_rmdir_async_004', 0, async function (done) { - let dpath = await nextFileName('fileio_test_rmdir_async_004') + 'd'; + it('fileio_test_rmdir_async_004', 0, async function () { + let dpath = await nextFileName('../cache/fileio_test_rmdir_async_004') + 'd'; try { + fileio.mkdirSync(dpath); await fileio.rmdir(dpath); } catch (err) { console.info('fileio_test_rmdir_async_004 has failed for ' + err); - expect(isInclude(err.message, 'No such file or directory')).assertTrue(); - done(); + expect(null).assertFail(); } }); /** * @tc.number SUB_STORAGE_FileIO_RMDIR_ASYNC_0500 * @tc.name fileio_test_rmdir_async_005 - * @tc.desc Test rmdir() interface. Parameter mismatch. + * @tc.desc Test rmdir() interface. Invalid path. * @tc.size MEDIUM * @tc.type Function * @tc.level Level 0 @@ -334,12 +355,12 @@ describe('fileio_rmdir', function () { */ it('fileio_test_rmdir_async_005', 0, async function (done) { let dpath = await nextFileName('fileio_test_rmdir_async_005') + 'd'; + try { - fileio.rmdir(dpath, '', function() { - }); + await fileio.rmdir(dpath); } catch (err) { console.info('fileio_test_rmdir_async_005 has failed for ' + err); - expect(isInclude(err.message, 'Number of arguments unmatched')).assertTrue(); + expect(isInclude(err.message, 'No such file or directory')).assertTrue(); done(); } }); @@ -347,18 +368,20 @@ describe('fileio_rmdir', function () { /** * @tc.number SUB_STORAGE_FileIO_RMDIR_ASYNC_0600 * @tc.name fileio_test_rmdir_async_006 - * @tc.desc Test rmdir() interface. Invalid path. + * @tc.desc Test rmdir() interface. Parameter mismatch. * @tc.size MEDIUM * @tc.type Function * @tc.level Level 0 * @tc.require */ it('fileio_test_rmdir_async_006', 0, async function (done) { + let dpath = await nextFileName('fileio_test_rmdir_async_006') + 'd'; try { - await fileio.rmdir(''); + fileio.rmdir(dpath, '', function() { + }); } catch (err) { console.info('fileio_test_rmdir_async_006 has failed for ' + err); - expect(isInclude(err.message, 'No such file or directory')).assertTrue(); + expect(isInclude(err.message, 'Number of arguments unmatched')).assertTrue(); done(); } }); @@ -366,19 +389,38 @@ describe('fileio_rmdir', function () { /** * @tc.number SUB_STORAGE_FileIO_RMDIR_ASYNC_0700 * @tc.name fileio_test_rmdir_async_007 - * @tc.desc Test rmdir() interface. Not a directory. + * @tc.desc Test rmdir() interface. Invalid path. * @tc.size MEDIUM * @tc.type Function * @tc.level Level 0 * @tc.require */ it('fileio_test_rmdir_async_007', 0, async function (done) { - let fpath = await nextFileName('fileio_test_rmdir_async_007'); + try { + await fileio.rmdir(''); + } catch (err) { + console.info('fileio_test_rmdir_async_007 has failed for ' + err); + expect(isInclude(err.message, 'No such file or directory')).assertTrue(); + done(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_RMDIR_ASYNC_0800 + * @tc.name fileio_test_rmdir_async_008 + * @tc.desc Test rmdir() interface. Not a directory. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileio_test_rmdir_async_008', 0, async function (done) { + let fpath = await nextFileName('fileio_test_rmdir_async_008'); expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); try { await fileio.rmdir(fpath); } catch (err) { - console.info('fileio_test_rmdir_async_007 has failed for ' + err); + console.info('fileio_test_rmdir_async_008 has failed for ' + err); expect(isInclude(err.message, 'Not a directory')).assertTrue(); fileio.unlinkSync(fpath); done(); diff --git a/storage/storagefilejstest/Test.json b/storage/storagefilejstest/Test.json index 6db12c331959d306ecba01a6808e7c119a61e505..5d01ba638110f426b203d61a1b825fe86a784569 100644 --- a/storage/storagefilejstest/Test.json +++ b/storage/storagefilejstest/Test.json @@ -2,8 +2,8 @@ "description": "Configuration for storage file Tests", "driver": { "type": "OHJSUnitTest", - "test-timeout": "600000", - "shell-timeout": "600000", + "test-timeout": "120000", + "shell-timeout": "120000", "bundle-name": "ohos.acts.storage.file", "package-name": "ohos.acts.storage.file" }, diff --git a/storage/storagefilejstest/src/main/js/test/File.test.js b/storage/storagefilejstest/src/main/js/test/File.test.js index 9c8614ddb48a8d0120b5d4fdcff0c1060d33615b..2d8f151a039cfc7796770da0660482fcd3debb30 100644 --- a/storage/storagefilejstest/src/main/js/test/File.test.js +++ b/storage/storagefilejstest/src/main/js/test/File.test.js @@ -433,48 +433,45 @@ describe('fileTest', function () { text: 'hello,world', success: function () { console.info('File_writeText_005 call writeText success.'); - done(); - }, - fail: function (data, code) { - console.info('File_writeText_005 call writeText fail, code: ' + code + ', data: ' + data); - expect(null).assertFail(); - }, - }); - file.writeText({ - uri: 'internal://cache/File_writeText_005', - text: 'hello', - append: true, - success: function () { - console.info('File_writeText_005 call writeText success.'); - done(); + file.writeText({ + uri: 'internal://cache/File_writeText_005', + text: 'hello', + append: true, + success: function () { + console.info('File_writeText_005 call writeText success.'); + file.readText({ + uri: 'internal://cache/File_writeText_005', + success: function (data) { + console.info('File_writeText_005 call read success ' ); + file.delete({ + uri: 'internal://cache/File_writeText_005', + success: function () { + console.info('File_writeText_005 call delete success'); + done(); + }, + fail: function (data, code) { + console.info('File_writeText_005 call delete fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + }, + fail: function (data, code) { + console.info('File_writeText_005 call readText fail , code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + }, + fail: function (data, code) { + console.info('File_writeText_005 call writeText fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); }, fail: function (data, code) { console.info('File_writeText_005 call writeText fail, code: ' + code + ', data: ' + data); expect(null).assertFail(); }, }); - file.readText({ - uri: 'internal://cache/File_writeText_005', - success: function (data) { - console.info('File_writeText_005 call read success ' ); - done(); - }, - fail: function (data, code) { - console.info('File_writeText_005 call readText fail , code: ' + code + ', data: ' + data); - expect(null).assertFail(); - }, - }); - file.delete({ - uri: 'internal://cache/File_writeText_005', - success: function () { - console.info('File_writeText_005 call delete success'); - done(); - }, - fail: function (data, code) { - console.info('File_writeText_005 call delete fail, code: ' + code + ', data: ' + data); - expect(null).assertFail(); - }, - }); }); /** @@ -916,33 +913,31 @@ describe('fileTest', function () { buffer: buf, success: function () { console.info('File_writeArrayBuffer_006 call writeText success.'); - done(); - }, - fail: function (data, code) { - console.info('File_writeArrayBuffer_006 , code: ' + code + ', data: ' + data); - expect(null).assertFail(); - }, - }); - file.writeArrayBuffer({ - uri: 'internal://cache/File_writeArrayBuffer_006', - buffer: buf, - success: function () { - console.info('File_writeArrayBuffer_006 call writeArrayBuffer success.'); - done(); - }, - fail: function (data, code) { - console.info('File_writeArrayBuffer_006 , code: ' + code + ', data: ' + data); - expect(null).assertFail(); - }, - }); - file.readArrayBuffer({ - uri: 'internal://cache/File_writeArrayBuffer_006', - success: function () { - console.info('File_writeArrayBuffer_006 pass'); - done(); + file.writeArrayBuffer({ + uri: 'internal://cache/File_writeArrayBuffer_006', + buffer: buf, + success: function () { + console.info('File_writeArrayBuffer_006 call writeArrayBuffer success.'); + file.readArrayBuffer({ + uri: 'internal://cache/File_writeArrayBuffer_006', + success: function () { + console.info('File_writeArrayBuffer_006 call readArrayBuffer pass'); + done(); + }, + fail: function (data, code) { + console.info('File_writeArrayBuffer_006 readArrayBuffer fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + }, + fail: function (data, code) { + console.info('File_writeArrayBuffer_006 writeArrayBuffer fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); }, fail: function (data, code) { - console.info('File_writeArrayBuffer_006 , code: ' + code + ', data: ' + data); + console.info('File_writeArrayBuffer_006 writeText fail, code: ' + code + ', data: ' + data); expect(null).assertFail(); }, }); @@ -2213,7 +2208,7 @@ describe('fileTest', function () { */ it('File_rmdir_005', 0, async function (done) { file.rmdir({ - uri: 'internal://app/test/123', + uri: 'internal://app/notdir/123', success: function () { console.info('File_rmdir_005 call rmdir success.'); expect(null).assertFail();