diff --git a/storage/storagefileiov9jstest/src/main/js/test/members/open.test.js b/storage/storagefileiov9jstest/src/main/js/test/members/open.test.js index 9f7d752e03b627ddf8aa4d428ca333082035934f..536eb3503a559eb5ae3091971f3a678f5796a8c2 100644 --- a/storage/storagefileiov9jstest/src/main/js/test/members/open.test.js +++ b/storage/storagefileiov9jstest/src/main/js/test/members/open.test.js @@ -363,7 +363,7 @@ export default function fileIOOpen() { * @tc.level Level 3 * @tc.require */ - it('fileIO_test_open_sync_013', 0, async function (done) { + it('fileIO_test_open_sync_013', 0, async function () { try { fileIO.openSync(-1, fileIO.OpenMode.READ_WRITE); @@ -371,7 +371,30 @@ export default function fileIOOpen() { } catch (e) { console.log('fileIO_test_open_sync_013 has failed for ' + e.message + ', code: ' + e.code); expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue(); - done(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_OPEN_SYNC_1400 + * @tc.name fileIO_test_open_sync_014 + * @tc.desc Test openSync() interfaces. mode=0o200000. + * The path refers to a directory, not a file. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_test_open_sync_014', 0, async function () { + let dpath = await nextFileName('fileIO_test_open_sync_012'); + fileIO.mkdirSync(dpath); + + try { + fileIO.openSync(dpath, fileIO.OpenMode.READ_WRITE); + expect(false).assertTrue(); + } catch (e) { + fileIO.rmdirSync(dpath); + console.log('fileIO_test_open_sync_014 has failed for ' + e.message + ', code: ' + e.code); + expect(e.code == 13900019 && e.message == 'Is a directory').assertTrue(); } }); @@ -1218,5 +1241,59 @@ export default function fileIOOpen() { expect(false).assertTrue(); } }); + + /** + * @tc.number SUB_DF_FILEIO_OPEN_ASYNC_2900 + * @tc.name fileIO_test_open_async_029 + * @tc.desc Test open() interfaces. Promise. + * The path refers to a file, not a directory. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_test_open_async_029', 0, async function (done) { + let dpath = await nextFileName('fileIO_test_open_async_029'); + fileIO.mkdirSync(dpath); + + try { + await fileIO.open(dpath, fileIO.OpenMode.READ_WRITE); + expect(false).assertTrue(); + } catch (e) { + fileIO.rmdirSync(dpath); + console.log('fileIO_test_open_async_029 has failed for ' + e.message + ', code: ' + e.code); + expect(e.code == 13900019 && e.message == 'Is a directory').assertTrue(); + done(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_OPEN_ASYNC_3000 + * @tc.name fileIO_test_open_async_030 + * @tc.desc Test open() interfaces. Callback. + * The path refers to a file, not a directory. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_test_open_async_030', 0, async function (done) { + let dpath = await nextFileName('fileIO_test_open_async_030'); + fileIO.mkdirSync(dpath); + + try { + fileIO.open(dpath, fileIO.OpenMode.READ_WRITE, (err, file) => { + if (err) { + fileIO.rmdirSync(dpath); + console.log('fileIO_test_open_async_030 error: {message: ' + err.message + ', code: ' + err.code + '}'); + expect(err.code == 13900019 && err.message == 'Is a directory').assertTrue(); + done(); + } + }); + } catch (e) { + console.log('fileIO_test_open_async_030 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); }); } diff --git a/storage/storagefileiov9jstest/src/main/js/test/members/rename.test.js b/storage/storagefileiov9jstest/src/main/js/test/members/rename.test.js index 5e600bcb9cbc3047b613062416f7264042c5637c..8c1863e816a4288ecc891e9861a0dd7ebcfbedfc 100644 --- a/storage/storagefileiov9jstest/src/main/js/test/members/rename.test.js +++ b/storage/storagefileiov9jstest/src/main/js/test/members/rename.test.js @@ -13,6 +13,7 @@ * limitations under the License. */ +import featureAbility from '@ohos.ability.featureAbility'; import { fileIO, FILE_CONTENT, prepareFile, nextFileName, describe, it, expect, randomString } from '../Common'; @@ -176,18 +177,64 @@ describe('fileIO_fs_rename', function () { * @tc.level Level 3 * @tc.require */ - it('fileIO_test_rename_sync_006', 0, async function (done) { + it('fileIO_test_rename_sync_006', 0, async function () { let fpath = await nextFileName('fileIO_test_rename_sync_006'); let fpathTarget = fpath + randomString(250); expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); try { - await fileIO.rename(fpath, fpathTarget); + fileIO.renameSync(fpath, fpathTarget); expect(false).assertTrue(); } catch (e) { + fileIO.unlinkSync(fpath); console.log('fileIO_test_rename_sync_006 has failed for ' + e.message + ', code: ' + e.code); expect(e.code == 13900030 && e.message == 'File name too long').assertTrue(); - done(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_RENAME_SYNC_0700 + * @tc.name fileIO_test_rename_sync_007 + * @tc.desc Test rename() interfaces. + * Don't have permission to operate on the root directory. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_test_rename_sync_007', 0, async function () { + + try { + fileIO.renameSync('/data', '/data_new'); + expect(false).assertTrue(); + } catch (e) { + console.log('fileIO_test_rename_sync_007 has failed for ' + e.message + ', code: ' + e.code); + expect(e.code == 13900012 && e.message == 'Permission denied').assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_RENAME_SYNC_0800 + * @tc.name fileIO_test_rename_sync_008 + * @tc.desc Test rename() interfaces. + * Can't modify file names across devices. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_test_rename_sync_008', 0, async function () { + let dstDir = await featureAbility.getContext().getOrCreateDistributedDir(); + let fpath = await nextFileName('fileIO_test_rename_sync_008'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + fileIO.renameSync(fpath, dstDir + '/data_new'); + expect(false).assertTrue(); + } catch (e) { + fileIO.unlinkSync(fpath); + console.log('fileIO_test_rename_sync_008 has failed for ' + e.message + ', code: ' + e.code); + expect(e.code == 13900016 && e.message == 'Cross-device link').assertTrue(); } }); @@ -453,6 +500,7 @@ describe('fileIO_fs_rename', function () { await fileIO.rename(fpath, fpathTarget); expect(false).assertTrue(); } catch (e) { + fileIO.unlinkSync(fpath); console.log('fileIO_test_rename_async_009 has failed for ' + e.message + ', code: ' + e.code); expect(e.code == 13900030 && e.message == 'File name too long').assertTrue(); done(); @@ -488,5 +536,83 @@ describe('fileIO_fs_rename', function () { expect(false).assertTrue(); } }); + + /** + * @tc.number SUB_DF_FILEIO_RENAME_ASYNC_1100 + * @tc.name fileIO_test_rename_async_011 + * @tc.desc Test rename() interfaces. Promise. + * Don't have permission to operate on the root directory. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_test_rename_async_011', 0, async function (done) { + + try { + await fileIO.rename('/data', '/data_new'); + expect(false).assertTrue(); + } catch (e) { + console.log('fileIO_test_rename_async_011 has failed for ' + e.message + ', code: ' + e.code); + expect(e.code == 13900012 && e.message == 'Permission denied').assertTrue(); + done(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_RENAME_ASYNC_1200 + * @tc.name fileIO_test_rename_async_012 + * @tc.desc Test rename() interfaces. + * Can't modify file names across devices. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_test_rename_async_012', 0, async function (done) { + let dstDir = await featureAbility.getContext().getOrCreateDistributedDir(); + let fpath = await nextFileName('fileIO_test_rename_async_012'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + await fileIO.rename(fpath, dstDir + '/data_new'); + expect(false).assertTrue(); + } catch (e) { + fileIO.unlinkSync(fpath); + console.log('fileIO_test_rename_async_012 has failed for ' + e.message + ', code: ' + e.code); + expect(e.code == 13900016 && e.message == 'Cross-device link').assertTrue(); + done(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_RENAME_ASYNC_1300 + * @tc.name fileIO_test_rename_async_013 + * @tc.desc Test rename() interfaces. + * Can't modify file names across devices. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_test_rename_async_013', 0, async function (done) { + let dstDir = await featureAbility.getContext().getOrCreateDistributedDir(); + let fpath = await nextFileName('fileIO_test_rename_async_013'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + fileIO.rename(fpath, dstDir + '/data_new', (err) => { + if (err) { + fileIO.unlinkSync(fpath); + console.log('fileIO_test_symlink_async_005 error: {message: ' + err.message + ', code: ' + err.code + '}'); + expect(err.code == 13900016 && err.message == 'Cross-device link').assertTrue(); + done(); + } + }); + } catch (e) { + console.log('fileIO_test_rename_async_013 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); }); } diff --git a/storage/storagefileiov9jstest/src/main/js/test/members/symlink.test.js b/storage/storagefileiov9jstest/src/main/js/test/members/symlink.test.js index 0e94637db91afd2949df45265a53be4dca6cffcd..9265721c62b7f5e82741bad4dc262264381f6549 100644 --- a/storage/storagefileiov9jstest/src/main/js/test/members/symlink.test.js +++ b/storage/storagefileiov9jstest/src/main/js/test/members/symlink.test.js @@ -13,6 +13,7 @@ * limitations under the License. */ +import featureAbility from '@ohos.ability.featureAbility'; import { fileIO, FILE_CONTENT, prepareFile, nextFileName, describe, it, expect, } from '../Common'; @@ -69,6 +70,31 @@ describe('fileIO_fs_symlink', function () { } }); + /** + * @tc.number SUB_DF_FILEIO_SYMLINK_SYNC_0200 + * @tc.name fileIO_test_symlink_sync_002 + * @tc.desc Test symlinkSync() interfaces. + * Can't create a symbolic links in distributed directories. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_test_symlink_sync_002', 0, async function () { + let dstDir = await featureAbility.getContext().getOrCreateDistributedDir(); + let fpath = await nextFileName('fileIO_test_symlink_sync_002'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + fileIO.symlinkSync(fpath, dstDir + '/link_000'); + expect(false).assertTrue(); + } catch (e) { + fileIO.unlinkSync(fpath); + console.log('fileIO_test_symlink_sync_002 has failed for ' + e.message + ', code: ' + e.code); + expect(e.code == 13900001 && e.message == 'Operation not permitted').assertTrue(); + } + }); + /** * @tc.number SUB_DF_FILEIO_SYMLINK_ASYNC_0000 * @tc.name fileIO_test_symlink_async_000 @@ -180,5 +206,61 @@ describe('fileIO_fs_symlink', function () { done(); } }); + + /** + * @tc.number SUB_DF_FILEIO_SYMLINK_ASYNC_0400 + * @tc.name fileIO_test_symlink_async_004 + * @tc.desc Test symlink() interfaces. + * Can't create a symbolic links in distributed directories. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_test_symlink_async_004', 0, async function (done) { + let dstDir = await featureAbility.getContext().getOrCreateDistributedDir(); + let fpath = await nextFileName('fileIO_test_symlink_async_004'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + await fileIO.symlink(fpath, dstDir + '/link_001'); + expect(false).assertTrue(); + } catch (e) { + fileIO.unlinkSync(fpath); + console.log('fileIO_test_symlink_async_004 has failed for ' + e.message + ', code: ' + e.code); + expect(e.code == 13900001 && e.message == 'Operation not permitted').assertTrue(); + done(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_SYMLINK_ASYNC_0500 + * @tc.name fileIO_test_symlink_async_005 + * @tc.desc Test symlink() interfaces. + * Can't create a symbolic links in distributed directories. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_test_symlink_async_005', 0, async function (done) { + let dstDir = await featureAbility.getContext().getOrCreateDistributedDir(); + let fpath = await nextFileName('fileIO_test_symlink_async_005'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + fileIO.symlink(fpath, dstDir + '/link_002', (err) => { + if (err) { + fileIO.unlinkSync(fpath); + console.log('fileIO_test_symlink_async_005 error: {message: ' + err.message + ', code: ' + err.code + '}'); + expect(err.code == 13900001 && err.message == 'Operation not permitted').assertTrue(); + done(); + } + }); + } catch (e) { + console.log('fileIO_test_symlink_async_005 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); }); } diff --git a/storage/storagefileiov9jstest/src/main/js/test/members/unlink.test.js b/storage/storagefileiov9jstest/src/main/js/test/members/unlink.test.js index 5fb4d2d5d40a45980f3441a6db82f3efaaee80cc..63397396d1df34a24207865f84e6ec6cb048ea97 100644 --- a/storage/storagefileiov9jstest/src/main/js/test/members/unlink.test.js +++ b/storage/storagefileiov9jstest/src/main/js/test/members/unlink.test.js @@ -86,6 +86,31 @@ describe('fileIO_fs_unlink', function () { } }); + /** + * @tc.number SUB_DF_FILEIO_UNLINK_SYNC_0300 + * @tc.name fileIO_test_unlink_sync_003 + * @tc.desc Test unlinkSync() interfaces. + * The path refers to a directory, not a file. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_test_unlink_sync_003', 0, async function () { + let dpath = await nextFileName('fileIO_test_unlink_sync_003'); + fileIO.mkdirSync(dpath); + + try { + expect(fileIO.accessSync(dpath)).assertTrue(); + fileIO.unlinkSync(dpath); + expect(false).assertTrue(); + } catch (e) { + fileIO.rmdirSync(dpath); + console.log('fileIO_test_unlink_sync_003 has failed for ' + e.message + ', code: ' + e.code); + expect(e.code == 13900019 && e.message == 'Is a directory').assertTrue(); + } + }); + /** * @tc.number SUB_DF_FileIO_UNLINK_ASYNC_0000 * @tc.name fileIO_test_unlink_async_000 @@ -212,5 +237,61 @@ describe('fileIO_fs_unlink', function () { done(); } }); + + /** + * @tc.number SUB_DF_FILEIO_UNLINK_ASYNC_0500 + * @tc.name fileIO_test_unlink_async_005 + * @tc.desc Test unlink() interfaces. Promise. + * The path refers to a directory, not a file. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_test_unlink_async_005', 0, async function (done) { + let dpath = await nextFileName('fileIO_test_unlink_async_005'); + fileIO.mkdirSync(dpath); + + try { + expect(fileIO.accessSync(dpath)).assertTrue(); + await fileIO.unlink(dpath); + expect(false).assertTrue(); + } catch (e) { + fileIO.rmdirSync(dpath); + console.log('fileIO_test_unlink_async_005 has failed for ' + e.message + ', code: ' + e.code); + expect(e.code == 13900019 && e.message == 'Is a directory').assertTrue(); + done(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_UNLINK_ASYNC_0600 + * @tc.name fileIO_test_unlink_async_006 + * @tc.desc Test unlink() interfaces. Callback. + * The path refers to a directory, not a file. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_test_unlink_async_006', 0, async function (done) { + let dpath = await nextFileName('fileIO_test_unlink_async_006'); + fileIO.mkdirSync(dpath); + + try { + expect(fileIO.accessSync(dpath)).assertTrue(); + fileIO.unlink(dpath, (err) => { + if (err) { + fileIO.rmdirSync(dpath); + console.log('fileIO_test_unlink_async_006 error: {message: ' + err.message + ', code: ' + err.code + '}'); + expect(err.code == 13900019 && err.message == 'Is a directory').assertTrue(); + done(); + } + }); + } catch (e) { + console.log('fileIO_test_unlink_async_006 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); }); }