diff --git a/storage/storagefileiov9jstest/src/main/js/test/List.test.js b/storage/storagefileiov9jstest/src/main/js/test/List.test.js index e9db0776574c891924a9593cbc24f9189b5938f9..c6caaa91c1cb83070cbf7e38879e8e75f061fd21 100644 --- a/storage/storagefileiov9jstest/src/main/js/test/List.test.js +++ b/storage/storagefileiov9jstest/src/main/js/test/List.test.js @@ -26,6 +26,7 @@ import fileIOListfile from './members/listFile.test.js' import fileIOLstat from './members/lstat.test.js' import fileIOMkdir from './members/mkdir.test.js' import fileIOMkdtemp from './members/mkdtemp.test.js' +import fileIOMoveDir from './members/moveDir.test.js' import fileIOMoveFile from './members/moveFile.test.js' import fileIOOpen from './members/open.test.js' import fileIORead from './members/read.test.js' @@ -56,6 +57,7 @@ export default function testsuite() { fileIOLstat() fileIOMkdir() fileIOMkdtemp() + fileIOMoveDir() fileIOMoveFile() fileIOOpen() fileIORead() diff --git a/storage/storagefileiov9jstest/src/main/js/test/members/moveDir.test.js b/storage/storagefileiov9jstest/src/main/js/test/members/moveDir.test.js new file mode 100755 index 0000000000000000000000000000000000000000..7ff0c6c2a630f3aa5f65eef7c135cad5f176ba6d --- /dev/null +++ b/storage/storagefileiov9jstest/src/main/js/test/members/moveDir.test.js @@ -0,0 +1,921 @@ +/* + * Copyright (C) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the 'License'); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an 'AS IS' BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import featureAbility from '@ohos.ability.featureAbility'; +import { + fileIO, FILE_CONTENT, prepareFile, nextFileName, describe, it, expect, randomString +} from '../Common'; + +export default function fileIOMoveDir() { + describe('fileIO_fs_moveDir', function () { + const DIRMODE_DIRECTORY_THROW_ERR = 0; + const DIRMODE_FILE_THROW_ERR = 1; + const DIRMODE_FILE_REPLACE = 2; + const DIRMODE_DIRECTORY_REPLACE = 3; + let readyFiles = async (testNum) => { + let dpath = await featureAbility.getContext().getFilesDir() + '/' + testNum; + try { + let ddpath1 = dpath + '/srcDir'; + let ddpath2 = dpath + '/destDir'; + let dddpath1 = ddpath1 + '/srcDir_first'; + let dddpath2 = ddpath2 + '/srcDir'; + let fpath1 = ddpath1 + '/srcFile_first_01'; + let fpath2 = ddpath1 + '/srcFile_first_02'; + let fpath3 = dddpath2 + '/srcFile_first_01'; + let fpath4 = dddpath2 + '/destFile_second_01'; + let ffpath1 = dddpath1 + '/srcFile_second_01'; + let ffpath2 = dddpath1 + '/srcFile_second_02'; + let ddddpath1 = dddpath1 + '/srcDir_second'; + let ddddpath2 = dddpath2 + '/srcDir_first'; + let fffpath1 = ddddpath1 + '/srcFile_third_01'; + let fffpath2 = ddddpath1 + '/srcFile_third_02'; + let fffpath3 = ddddpath2 + '/srcFile_second_01'; + let fffpath4 = ddddpath2 + '/destFile_third_01'; + fileIO.mkdirSync(dpath); + fileIO.mkdirSync(ddpath1); + fileIO.mkdirSync(ddpath2); + fileIO.mkdirSync(dddpath1); + fileIO.mkdirSync(dddpath2); + fileIO.mkdirSync(ddddpath1); + fileIO.mkdirSync(ddddpath2); + expect(prepareFile(fpath1, randomString(10))).assertTrue(); + expect(prepareFile(fpath2, randomString(15))).assertTrue(); + expect(prepareFile(fpath3, randomString(20))).assertTrue(); + expect(prepareFile(fpath4, randomString(25))).assertTrue(); + expect(prepareFile(ffpath1, randomString(30))).assertTrue(); + expect(prepareFile(ffpath2, randomString(35))).assertTrue(); + expect(prepareFile(fffpath1, randomString(40))).assertTrue(); + expect(prepareFile(fffpath2, randomString(45))).assertTrue(); + expect(prepareFile(fffpath3, randomString(50))).assertTrue(); + expect(prepareFile(fffpath4, randomString(55))).assertTrue(); + return { + baseDir: dpath, + srcDir: ddpath1, + destDir: ddpath2 + }; + } catch (e) { + console.log(testNum + 'failed to readyFiles for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + return { + baseDir: dpath, + srcDir: null, + destDir: null + } + } + } + + /** + * @tc.number SUB_DF_FILEIO_MOVEDIR_ASYNC_0000 + * @tc.name fileIO_test_moveDir_async_000 + * @tc.desc Test moveDir() interface.Promise. + * There is no target folder(src) under path dest. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_test_moveDir_async_000', 3, async function (done) { + let dpath = await featureAbility.getContext().getFilesDir() + '/fileIO_test_moveDir_async_000'; + let ddpath1 = dpath + '/srcDir'; + let ddpath2 = dpath + '/destDir'; + let fpath1 = ddpath1 + '/srcFile_first_01'; + let fpath2 = ddpath1 + '/srcFile_first_02'; + let dddpath = ddpath1 + '/srcDir_first'; + let ffpath1 = dddpath + '/srcFile_second_01'; + let ffpath2 = dddpath + '/srcFile_second_02'; + fileIO.mkdirSync(dpath); + fileIO.mkdirSync(ddpath1); + fileIO.mkdirSync(ddpath2); + fileIO.mkdirSync(dddpath); + expect(prepareFile(fpath1, randomString(10))).assertTrue(); + expect(prepareFile(fpath2, randomString(15))).assertTrue(); + expect(prepareFile(ffpath1, randomString(20))).assertTrue(); + expect(prepareFile(ffpath2, randomString(25))).assertTrue(); + + try { + let stat1 = fileIO.statSync(fpath1); + let stat2 = fileIO.statSync(ffpath1); + await fileIO.moveDir(ddpath1, ddpath2); + expect(fileIO.accessSync(ddpath1)).assertFalse(); + expect(fileIO.accessSync(ddpath2 + '/srcDir/srcFile_first_01')).assertTrue(); + expect(fileIO.accessSync(ddpath2 + '/srcDir/srcDir_first/srcFile_second_01')).assertTrue(); + let stat3 = fileIO.statSync(ddpath2 + '/srcDir/srcFile_first_01'); + expect(stat1.size == stat3.size).assertTrue(); + let stat4 = fileIO.statSync(ddpath2 + '/srcDir/srcDir_first/srcFile_second_01'); + expect(stat2.size == stat4.size).assertTrue(); + fileIO.rmdirSync(dpath); + done(); + } catch (e) { + console.log('fileIO_test_moveDir_async_000 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_MOVEDIR_ASYNC_0100 + * @tc.name fileIO_test_moveDir_async_001 + * @tc.desc Test moveDir() interface.Callback. + * There is no target folder(src) under path dest. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_test_moveDir_async_001', 3, async function (done) { + let dpath = await featureAbility.getContext().getFilesDir() + '/fileIO_test_moveDir_async_001'; + let ddpath1 = dpath + '/srcDir'; + let ddpath2 = dpath + '/destDir'; + let fpath1 = ddpath1 + '/srcFile_first_01'; + let fpath2 = ddpath1 + '/srcFile_first_02'; + let dddpath = ddpath1 + '/srcDir_first'; + let ffpath1 = dddpath + '/srcFile_second_01'; + let ffpath2 = dddpath + '/srcFile_second_02'; + fileIO.mkdirSync(dpath); + fileIO.mkdirSync(ddpath1); + fileIO.mkdirSync(ddpath2); + fileIO.mkdirSync(dddpath); + expect(prepareFile(fpath1, randomString(10))).assertTrue(); + expect(prepareFile(fpath2, randomString(15))).assertTrue(); + expect(prepareFile(ffpath1, randomString(20))).assertTrue(); + expect(prepareFile(ffpath2, randomString(25))).assertTrue(); + + try { + let stat1 = fileIO.statSync(fpath1); + let stat2 = fileIO.statSync(ffpath1); + fileIO.moveDir(ddpath1, ddpath2, (err) => { + if (err) { + console.log('fileIO_test_moveDir_async_001 err package ' + JSON.stringify(err)); + expect(false).assertTrue(); + } + expect(fileIO.accessSync(ddpath1)).assertFalse(); + expect(fileIO.accessSync(ddpath2 + '/srcDir/srcFile_first_01')).assertTrue(); + expect(fileIO.accessSync(ddpath2 + '/srcDir/srcDir_first/srcFile_second_01')).assertTrue(); + let stat3 = fileIO.statSync(ddpath2 + '/srcDir/srcFile_first_01'); + expect(stat1.size == stat3.size).assertTrue(); + let stat4 = fileIO.statSync(ddpath2 + '/srcDir/srcDir_first/srcFile_second_01'); + expect(stat2.size == stat4.size).assertTrue(); + fileIO.rmdirSync(dpath); + done(); + }); + } catch (e) { + console.log('fileIO_test_moveDir_async_001 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_MOVEDIR_ASYNC_0200 + * @tc.name fileIO_test_moveDir_async_002 + * @tc.desc Test moveDir() interface.Promise. + * There is a target folder(src) under path dest but it is empty. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_test_moveDir_async_002', 3, async function (done) { + let dpath = await featureAbility.getContext().getFilesDir() + '/fileIO_test_moveDir_async_002'; + let ddpath1 = dpath + '/srcDir'; + let ddpath2 = dpath + '/destDir'; + let dddpath2 = ddpath2 + '/srcDir'; + let fpath1 = ddpath1 + '/srcFile_first_01'; + let fpath2 = ddpath1 + '/srcFile_first_02'; + let dddpath1 = ddpath1 + '/srcDir_first'; + let ffpath1 = dddpath1 + '/srcFile_second_01'; + let ffpath2 = dddpath1 + '/srcFile_second_02'; + fileIO.mkdirSync(dpath); + fileIO.mkdirSync(ddpath1); + fileIO.mkdirSync(ddpath2); + fileIO.mkdirSync(dddpath1); + fileIO.mkdirSync(dddpath2); + expect(prepareFile(fpath1, randomString(10))).assertTrue(); + expect(prepareFile(fpath2, randomString(15))).assertTrue(); + expect(prepareFile(ffpath1, randomString(20))).assertTrue(); + expect(prepareFile(ffpath2, randomString(25))).assertTrue(); + + try { + let stat1 = fileIO.statSync(fpath1); + let stat2 = fileIO.statSync(ffpath1); + await fileIO.moveDir(ddpath1, ddpath2); + expect(fileIO.accessSync(ddpath1)).assertFalse(); + expect(fileIO.accessSync(ddpath2 + '/srcDir/srcFile_first_01')).assertTrue(); + expect(fileIO.accessSync(ddpath2 + '/srcDir/srcDir_first/srcFile_second_01')).assertTrue(); + let stat3 = fileIO.statSync(ddpath2 + '/srcDir/srcFile_first_01'); + expect(stat1.size == stat3.size).assertTrue(); + let stat4 = fileIO.statSync(ddpath2 + '/srcDir/srcDir_first/srcFile_second_01'); + expect(stat2.size == stat4.size).assertTrue(); + fileIO.rmdirSync(dpath); + done(); + } catch (e) { + console.log('fileIO_test_moveDir_async_002 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_MOVEDIR_ASYNC_0300 + * @tc.name fileIO_test_moveDir_async_003 + * @tc.desc Test moveDir() interface.Callback. + * There is a target folder(src) under path dest but it is empty. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_test_moveDir_async_003', 3, async function (done) { + let dpath = await featureAbility.getContext().getFilesDir() + '/fileIO_test_moveDir_async_003'; + let ddpath1 = dpath + '/srcDir'; + let ddpath2 = dpath + '/destDir'; + let dddpath2 = ddpath2 + '/srcDir'; + let fpath1 = ddpath1 + '/srcFile_first_01'; + let fpath2 = ddpath1 + '/srcFile_first_02'; + let dddpath1 = ddpath1 + '/srcDir_first'; + let ffpath1 = dddpath1 + '/srcFile_second_01'; + let ffpath2 = dddpath1 + '/srcFile_second_02'; + fileIO.mkdirSync(dpath); + fileIO.mkdirSync(ddpath1); + fileIO.mkdirSync(ddpath2); + fileIO.mkdirSync(dddpath1); + fileIO.mkdirSync(dddpath2); + expect(prepareFile(fpath1, randomString(10))).assertTrue(); + expect(prepareFile(fpath2, randomString(15))).assertTrue(); + expect(prepareFile(ffpath1, randomString(20))).assertTrue(); + expect(prepareFile(ffpath2, randomString(25))).assertTrue(); + + try { + let stat1 = fileIO.statSync(fpath1); + let stat2 = fileIO.statSync(ffpath1); + fileIO.moveDir(ddpath1, ddpath2, (err) => { + if (err) { + console.log('fileIO_test_moveDir_async_003 err package ' + JSON.stringify(err)); + expect(false).assertTrue(); + } + expect(fileIO.accessSync(ddpath1)).assertFalse(); + expect(fileIO.accessSync(ddpath2 + '/srcDir/srcFile_first_01')).assertTrue(); + expect(fileIO.accessSync(ddpath2 + '/srcDir/srcDir_first/srcFile_second_01')).assertTrue(); + let stat3 = fileIO.statSync(ddpath2 + '/srcDir/srcFile_first_01'); + expect(stat1.size == stat3.size).assertTrue(); + let stat4 = fileIO.statSync(ddpath2 + '/srcDir/srcDir_first/srcFile_second_01'); + expect(stat2.size == stat4.size).assertTrue(); + fileIO.rmdirSync(dpath); + done(); + }); + } catch (e) { + console.log('fileIO_test_moveDir_async_003 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_MOVEDIR_ASYNC_0400 + * @tc.name fileIO_test_moveDir_async_004 + * @tc.desc Test moveFile() interface.Promise. + * There is a target folder(src) under path dest and it is not empty.Mode is DIRMODE_DIRECTORY_REPLACE. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_test_moveDir_async_004', 0, async function (done) { + let dpath = await readyFiles('fileIO_test_moveDir_async_004'); + + try { + let stat1 = fileIO.statSync(dpath.srcDir + '/srcFile_first_01'); + let stat2 = fileIO.statSync(dpath.srcDir + '/srcDir_first/srcFile_second_01'); + let dirent1 = fileIO.listFileSync(dpath.destDir, {recursion : true}); + expect(dirent1.length == 4).assertTrue(); + await fileIO.moveDir(dpath.srcDir, dpath.destDir, DIRMODE_DIRECTORY_REPLACE); + expect(fileIO.accessSync(dpath.srcDir)).assertFalse(); + expect(fileIO.accessSync(dpath.destDir + '/srcDir/destFile_second_01')).assertFalse(); + expect(fileIO.accessSync(dpath.destDir + '/srcDir/srcDir_first/destFile_third_01')).assertFalse(); + let stat3 = fileIO.statSync(dpath.destDir + '/srcDir/srcFile_first_01'); + expect(stat1.size == stat3.size).assertTrue(); + let stat4 = fileIO.statSync(dpath.destDir + '/srcDir/srcDir_first/srcFile_second_01'); + expect(stat2.size == stat4.size).assertTrue(); + let dirent2 = fileIO.listFileSync(dpath.destDir, {recursion : true}); + expect(dirent2.length == 6).assertTrue(); + fileIO.rmdirSync(dpath.baseDir); + done(); + } catch (e) { + console.log('fileIO_test_moveDir_async_004 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_MOVEDIR_ASYNC_0500 + * @tc.name fileIO_test_moveDir_async_005 + * @tc.desc Test moveFile() interface.Callback. + * There is a target folder(src) under path dest and it is not empty.Mode is DIRMODE_DIRECTORY_REPLACE. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_test_moveDir_async_005', 0, async function (done) { + let dpath = await readyFiles('fileIO_test_moveDir_async_005'); + + try { + let stat1 = fileIO.statSync(dpath.srcDir + '/srcFile_first_01'); + let stat2 = fileIO.statSync(dpath.srcDir + '/srcDir_first/srcFile_second_01'); + let dirent1 = fileIO.listFileSync(dpath.destDir, {recursion : true}); + expect(dirent1.length == 4).assertTrue(); + fileIO.moveDir(dpath.srcDir, dpath.destDir, DIRMODE_DIRECTORY_REPLACE, (err) => { + if (err) { + console.log('fileIO_test_moveDir_async_005 err package ' + JSON.stringify(err)); + expect(false).assertTrue(); + } + expect(fileIO.accessSync(dpath.srcDir)).assertFalse(); + expect(fileIO.accessSync(dpath.destDir + '/srcDir/destFile_second_01')).assertFalse(); + expect(fileIO.accessSync(dpath.destDir + '/srcDir/srcDir_first/destFile_third_01')).assertFalse(); + let stat3 = fileIO.statSync(dpath.destDir + '/srcDir/srcFile_first_01'); + expect(stat1.size == stat3.size).assertTrue(); + let stat4 = fileIO.statSync(dpath.destDir + '/srcDir/srcDir_first/srcFile_second_01'); + expect(stat2.size == stat4.size).assertTrue(); + let dirent2 = fileIO.listFileSync(dpath.destDir, {recursion : true}); + expect(dirent2.length == 6).assertTrue(); + fileIO.rmdirSync(dpath.baseDir); + done(); + }); + } catch (e) { + console.log('fileIO_test_moveDir_async_005 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_MOVEDIR_ASYNC_0600 + * @tc.name fileIO_test_moveDir_async_006 + * @tc.desc Test moveFile() interface.Promise. + * There is a target folder(src) under path dest and it is not empty.Mode is DIRMODE_FILE_REPLACE. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_test_moveDir_async_006', 0, async function (done) { + let dpath = await readyFiles('fileIO_test_moveDir_async_006'); + + try { + let stat1 = fileIO.statSync(dpath.destDir + '/srcDir/srcFile_first_01'); + let stat2 = fileIO.statSync(dpath.destDir + '/srcDir/srcDir_first/srcFile_second_01'); + + let dirent1 = fileIO.listFileSync(dpath.destDir, {recursion : true}); + expect(dirent1.length == 4).assertTrue(); + await fileIO.moveDir(dpath.srcDir, dpath.destDir, DIRMODE_FILE_REPLACE); + expect(fileIO.accessSync(dpath.srcDir)).assertFalse(); + expect(fileIO.accessSync(dpath.destDir + '/srcDir/destFile_second_01')).assertTrue(); + expect(fileIO.accessSync(dpath.destDir + '/srcDir/srcDir_first/destFile_third_01')).assertTrue(); + let stat3 = fileIO.statSync(dpath.destDir + '/srcDir/srcFile_first_01'); + expect(stat1.size != stat3.size && stat3.size == 10).assertTrue(); + let stat4 = fileIO.statSync(dpath.destDir + '/srcDir/srcDir_first/srcFile_second_01'); + expect(stat2.size != stat4.size && stat4.size == 30).assertTrue(); + let dirent2 = fileIO.listFileSync(dpath.destDir, {recursion : true}); + expect(dirent2.length == 8).assertTrue(); + fileIO.rmdirSync(dpath.baseDir); + done(); + } catch (e) { + console.log('fileIO_test_moveDir_async_006 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_MOVEDIR_ASYNC_0700 + * @tc.name fileIO_test_moveDir_async_007 + * @tc.desc Test moveFile() interface.Callback. + * There is a target folder(src) under path dest and it is not empty.Mode is DIRMODE_FILE_REPLACE. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_test_moveDir_async_007', 0, async function (done) { + let dpath = await readyFiles('fileIO_test_moveDir_async_007'); + + try { + let stat1 = fileIO.statSync(dpath.destDir + '/srcDir/srcFile_first_01'); + let stat2 = fileIO.statSync(dpath.destDir + '/srcDir/srcDir_first/srcFile_second_01'); + let dirent1 = fileIO.listFileSync(dpath.destDir, {recursion : true}); + expect(dirent1.length == 4).assertTrue(); + fileIO.moveDir(dpath.srcDir, dpath.destDir, DIRMODE_FILE_REPLACE, (err) => { + if (err) { + console.log('fileIO_test_moveDir_async_007 err package ' + JSON.stringify(err)); + expect(false).assertTrue(); + } + expect(fileIO.accessSync(dpath.srcDir)).assertFalse(); + expect(fileIO.accessSync(dpath.destDir + '/srcDir/destFile_second_01')).assertTrue(); + expect(fileIO.accessSync(dpath.destDir + '/srcDir/srcDir_first/destFile_third_01')).assertTrue(); + let stat3 = fileIO.statSync(dpath.destDir + '/srcDir/srcFile_first_01'); + expect(stat1.size != stat3.size && stat3.size == 10).assertTrue(); + let stat4 = fileIO.statSync(dpath.destDir + '/srcDir/srcDir_first/srcFile_second_01'); + expect(stat2.size != stat4.size && stat4.size == 30).assertTrue(); + let dirent2 = fileIO.listFileSync(dpath.destDir, {recursion : true}); + expect(dirent2.length == 8).assertTrue(); + fileIO.rmdirSync(dpath.baseDir); + done(); + }); + } catch (e) { + console.log('fileIO_test_moveDir_async_007 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_MOVEDIRSYNC_0800 + * @tc.name fileIO_test_moveDir_async_008 + * @tc.desc Test moveFile() interface.Promise. + * There is a target folder(src) under path dest and it is not empty.Mode is DIRMODE_FILE_THROW_ERR. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_test_moveDir_async_008', 0, async function (done) { + let dpath = await readyFiles('fileIO_test_moveDir_async_008'); + + try { + let dirnet1 = fileIO.listFileSync(dpath.destDir, {recursion : true}); + expect(dirnet1.length == 4).assertTrue(); + await fileIO.moveDir(dpath.srcDir, dpath.destDir, DIRMODE_FILE_THROW_ERR); + expect(false).assertTrue(); + } catch (err) { + console.log('fileIO_test_moveDir_async_008 has failed for ' + err.message + ', code: ' + err.code); + let stat1 = fileIO.statSync(dpath.srcDir + '/srcFile_first_01'); + let stat2 = fileIO.statSync(dpath.srcDir + '/srcDir_first/srcFile_second_01'); + let stat3 = fileIO.statSync(dpath.destDir + '/srcDir/srcFile_first_01'); + expect(stat1.size != stat3.size && stat3.size == 20).assertTrue(); + let stat4 = fileIO.statSync(dpath.destDir + '/srcDir/srcDir_first/srcFile_second_01'); + expect(stat2.size != stat4.size && stat4.size == 50).assertTrue(); + expect(fileIO.accessSync(dpath.destDir + '/srcDir/srcFile_first_02')).assertTrue(); + expect(fileIO.accessSync(dpath.destDir + '/srcDir/srcDir_first/srcFile_second_02')).assertTrue(); + expect(fileIO.accessSync(dpath.destDir + '/srcDir/destFile_second_01')).assertTrue(); + expect(fileIO.accessSync(dpath.destDir + '/srcDir/srcDir_first/destFile_third_01')).assertTrue(); + expect(fileIO.accessSync(dpath.destDir + '/srcDir/srcDir_first/srcFile_second_01')).assertTrue(); + let dirent2 = fileIO.listFileSync(dpath.destDir, {recursion : true}); + expect(dirent2.length == 8).assertTrue(); + fileIO.rmdirSync(dpath.baseDir); + expect(err.code == 13900015 && err.message == 'File exists').assertTrue(); + expect(err.data.length == 2).assertTrue(); + done(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_MOVEDIRSYNC_0900 + * @tc.name fileIO_test_moveDir_async_009 + * @tc.desc Test moveFile() interface.Callback. + * There is a target folder(src) under path dest and it is not empty.Mode is DIRMODE_FILE_THROW_ERR. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_test_moveDir_async_009', 0, async function (done) { + let dpath = await readyFiles('fileIO_test_moveDir_async_009'); + + try { + let dirent1 = fileIO.listFileSync(dpath.destDir, {recursion : true}); + expect(dirent1.length == 4).assertTrue(); + fileIO.moveDir(dpath.srcDir, dpath.destDir, DIRMODE_FILE_THROW_ERR, (err) => { + if (err) { + console.log('fileIO_test_moveDir_async_009 error:' + JSON.stringify(err)); + let stat1 = fileIO.statSync(dpath.srcDir + '/srcFile_first_01'); + let stat2 = fileIO.statSync(dpath.srcDir + '/srcDir_first/srcFile_second_01'); + let stat3 = fileIO.statSync(dpath.destDir + '/srcDir/srcFile_first_01'); + expect(stat1.size != stat3.size && stat3.size == 20).assertTrue(); + let stat4 = fileIO.statSync(dpath.destDir + '/srcDir/srcDir_first/srcFile_second_01'); + expect(stat2.size != stat4.size && stat4.size == 50).assertTrue(); + expect(fileIO.accessSync(dpath.destDir + '/srcDir/srcFile_first_02')).assertTrue(); + expect(fileIO.accessSync(dpath.destDir + '/srcDir/srcDir_first/srcFile_second_02')).assertTrue(); + expect(fileIO.accessSync(dpath.destDir + '/srcDir/destFile_second_01')).assertTrue(); + expect(fileIO.accessSync(dpath.destDir + '/srcDir/srcDir_first/destFile_third_01')).assertTrue(); + let dirent2 = fileIO.listFileSync(dpath.destDir, {recursion : true}); + expect(dirent2.length == 8).assertTrue(); + fileIO.rmdirSync(dpath.baseDir); + expect(err.code == 13900015 && err.message == 'File exists').assertTrue(); + expect(err.data.length == 2).assertTrue(); + done(); + } + }); + } catch (e) { + console.log('fileIO_test_moveDir_async_009 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_MOVEDIRSYNC_1000 + * @tc.name fileIO_test_moveDir_async_010 + * @tc.desc Test moveFile() interface.Promise. + * There is a target folder(src) under path dest and it is not empty.Mode is DIRMODE_DIRECTORY_THROW_ERR. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_test_moveDir_async_010', 0, async function (done) { + let dpath = await readyFiles('fileIO_test_moveDir_async_010'); + + try { + await fileIO.moveDir(dpath.srcDir, dpath.destDir, DIRMODE_DIRECTORY_THROW_ERR); + expect(false).assertTrue(); + } catch (e) { + fileIO.rmdirSync(dpath.baseDir); + console.log('fileIO_test_moveDir_async_010 has failed for ' + e.message + ', code: ' + e.code); + expect(e.code == 13900032 && e.message == 'Directory not empty').assertTrue(); + done(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_MOVEDIRSYNC_1100 + * @tc.name fileIO_test_moveDir_async_011 + * @tc.desc Test moveFile() interface.Callback. + * There is a target folder(src) under path dest and it is not empty.Mode is DIRMODE_DIRECTORY_THROW_ERR. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_test_moveDir_async_011', 0, async function (done) { + let dpath = await readyFiles('fileIO_test_moveDir_async_011'); + + try { + fileIO.moveDir(dpath.srcDir, dpath.destDir, DIRMODE_DIRECTORY_THROW_ERR, (err) => { + if (err) { + fileIO.rmdirSync(dpath.baseDir); + console.log('fileIO_test_moveDir_async_011 error: {message: ' + err.message + ', code: ' + err.code + '}'); + expect(err.code == 13900032 && err.message == 'Directory not empty').assertTrue(); + done(); + } + }); + } catch (e) { + console.log('fileIO_test_moveDir_async_011 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_MOVEDIRSYNC_1200 + * @tc.name fileIO_test_moveDir_async_012 + * @tc.desc Test moveFile() interface.Promise. + * Src is empty and there is a target folder(src) under path dest but it is empty. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_test_moveDir_async_012', 3, async function (done) { + let dpath = await nextFileName('fileIO_test_moveDir_async_012'); + let fpath = dpath + '/file_006.txt'; + let ddpath = dpath + '/dir_006'; + let ddpath2 = dpath + '/dir2_006'; + let ffpath3 = ddpath2 + '/new.txt'; + let dddpath3= ddpath2 + '/dir_006'; + fileIO.mkdirSync(dpath); + fileIO.mkdirSync(ddpath); + fileIO.mkdirSync(ddpath2); + fileIO.mkdirSync(dddpath3); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + expect(prepareFile(ffpath3, FILE_CONTENT)).assertTrue(); + + try { + await fileIO.moveDir(ddpath, ddpath2, DIRMODE_FILE_REPLACE); + expect(fileIO.accessSync(ddpath)).assertFalse(); + fileIO.rmdirSync(dpath); + done(); + } catch (e) { + console.log('fileIO_test_moveDir_async_012 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_MOVEDIRSYNC_1300 + * @tc.name fileIO_test_moveDir_async_013 + * @tc.desc Test moveFile() interface.Callback. + * Src is empty and there is a target folder(src) under path dest but it is empty. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_test_moveDir_async_013', 3, async function (done) { + let dpath = await nextFileName('fileIO_test_moveDir_async_013'); + let fpath = dpath + '/file_006.txt'; + let ddpath = dpath + '/dir_006'; + let ddpath2 = dpath + '/dir2_006'; + let ffpath3 = ddpath2 + '/new.txt'; + let dddpath3= ddpath2 + '/dir_006'; + fileIO.mkdirSync(dpath); + fileIO.mkdirSync(ddpath); + fileIO.mkdirSync(ddpath2); + fileIO.mkdirSync(dddpath3); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + expect(prepareFile(ffpath3, FILE_CONTENT)).assertTrue(); + + try { + fileIO.moveDir(ddpath, ddpath2, DIRMODE_FILE_REPLACE, (err) => { + if (err) { + console.log('fileIO_test_moveDir_async_013 err package ' + JSON.stringify(err)); + expect(false).assertTrue(); + } + expect(fileIO.accessSync(ddpath)).assertFalse(); + fileIO.rmdirSync(dpath); + done(); + }); + } catch (e) { + console.log('fileIO_test_moveDir_async_013 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_MOVEDIRSYNC_1400 + * @tc.name fileIO_test_moveDir_async_014 + * @tc.desc Test moveFile() interface.Promise. + * Src is empty and there is no target folder(src) under path dest. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_test_moveDir_async_014', 3, async function (done) { + let dpath = await nextFileName('fileIO_test_moveDir_async_014'); + let fpath = dpath + '/file_007.txt'; + let ddpath = dpath + '/dir_007'; + let ddpath2 = dpath + '/dir2_007'; + let ffpath3 = ddpath2 + '/new.txt'; + fileIO.mkdirSync(dpath); + fileIO.mkdirSync(ddpath); + fileIO.mkdirSync(ddpath2); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + expect(prepareFile(ffpath3, FILE_CONTENT)).assertTrue(); + + try { + await fileIO.moveDir(ddpath, ddpath2, DIRMODE_FILE_REPLACE); + expect(fileIO.accessSync(ddpath)).assertFalse(); + fileIO.rmdirSync(dpath); + done(); + } catch (e) { + console.log('fileIO_test_moveDir_async_014 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_MOVEDIRSYNC_1500 + * @tc.name fileIO_test_moveDir_async_015 + * @tc.desc Test moveFile() interface.CallBack. + * Src is empty and there is no target folder(src) under path dest. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_test_moveDir_async_015', 3, async function (done) { + let dpath = await nextFileName('fileIO_test_moveDir_async_015'); + let fpath = dpath + '/file_007.txt'; + let ddpath = dpath + '/dir_007'; + let ddpath2 = dpath + '/dir2_007'; + let ffpath3 = ddpath2 + '/new.txt'; + fileIO.mkdirSync(dpath); + fileIO.mkdirSync(ddpath); + fileIO.mkdirSync(ddpath2); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + expect(prepareFile(ffpath3, FILE_CONTENT)).assertTrue(); + + try { + fileIO.moveDir(ddpath, ddpath2, DIRMODE_FILE_REPLACE, (err) => { + if (err) { + console.log('fileIO_test_moveDir_async_015 err package ' + JSON.stringify(err)); + expect(false).assertTrue(); + } + expect(fileIO.accessSync(ddpath)).assertFalse(); + fileIO.rmdirSync(dpath); + done(); + }); + } catch (e) { + console.log('fileIO_test_moveDir_async_015 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_MOVEDIRSYNC_1600 + * @tc.name fileIO_test_moveDir_async_016 + * @tc.desc Test moveFile() interface.Promise. + * Invalid mode. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_test_moveDir_async_016', 3, async function (done) { + let dpath = await readyFiles('fileIO_test_moveDir_async_016'); + + try { + const INVALIDE_MODE = -1; + await fileIO.moveDir(dpath.srcDir, dpath.destDir, INVALIDE_MODE); + expect(false).assertTrue(); + } catch (err) { + fileIO.rmdirSync(dpath.baseDir); + console.log('fileIO_test_moveDir_async_016 has failed for ' + err.message + ', code: ' + err.code); + expect(err.code == 13900020 && err.message == 'Invalid argument').assertTrue(); + done(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_MOVEDIRSYNC_1700 + * @tc.name fileIO_test_moveDir_async_017 + * @tc.desc Test moveFile() interface.Callback. + * Invalid mode. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_test_moveDir_async_017', 3, async function (done) { + let dpath = await readyFiles('fileIO_test_moveDir_async_017'); + + try { + const INVALIDE_MODE = 4; + fileIO.moveDir(dpath.srcDir, dpath.destDir, INVALIDE_MODE, (err) => { + expect(false).assertTrue(); + }); + } catch (e) { + fileIO.rmdirSync(dpath.baseDir); + console.log('fileIO_test_moveDir_async_017 has failed for ' + e.message + ', code: ' + e.code); + expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue(); + done(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_MOVEDIRSYNC_1800 + * @tc.name fileIO_test_moveDir_async_018 + * @tc.desc Test moveFile() interface.Promise. + * Invalid path.The path point to a file, not a directory. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_test_moveDir_async_018', 3, async function (done) { + let dpath = await readyFiles('fileIO_test_moveDir_async_018'); + + try { + await fileIO.moveDir(dpath.srcDir + '/srcFile_first_01', dpath.destDir + 'srcDir/srcFile_first_01'); + expect(false).assertTrue(); + } catch (e) { + fileIO.rmdirSync(dpath.baseDir); + console.log('fileIO_test_moveDir_async_018 has failed for ' + e.message + ', code: ' + e.code); + expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue(); + done(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_MOVEDIRSYNC_1900 + * @tc.name fileIO_test_moveDir_async_019 + * @tc.desc Test moveFile() interface.Callback. + * Invalid path.The path point to a file, not a directory. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_test_moveDir_async_019', 3, async function (done) { + let dpath = await readyFiles('fileIO_test_moveDir_async_019'); + + try { + fileIO.moveDir(dpath.srcDir + '/srcFile_first_01', dpath.destDir + 'srcDir/srcFile_first_01', (err) => { + expect(false).assertTrue(); + }); + } catch (e) { + fileIO.rmdirSync(dpath.baseDir); + console.log('fileIO_test_moveDir_async_019 has failed for ' + e.message + ', code: ' + e.code); + expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue(); + done(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_MOVEDIRSYNC_2000 + * @tc.name fileIO_test_moveDir_async_020 + * @tc.desc Test moveFile() interface.Promise. + * Invalid path. Can not move the same path. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_test_moveDir_async_020', 3, async function (done) { + let dpath = await readyFiles('fileIO_test_moveDir_async_020'); + + try { + await fileIO.moveDir(dpath.srcDir, dpath.srcDir, DIRMODE_FILE_THROW_ERR); + expect(false).assertTrue(); + } catch (e) { + fileIO.rmdirSync(dpath.baseDir); + console.log('fileIO_test_moveDir_async_020 has failed for ' + e.message + ', code: ' + e.code); + expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue(); + done(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_MOVEDIRSYNC_2100 + * @tc.name fileIO_test_moveDir_async_021 + * @tc.desc Test moveFile() interface.Callback. + * Invalid path.Can not move the same path. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_test_moveDir_async_021', 3, async function (done) { + let dpath = await readyFiles('fileIO_test_moveDir_async_021'); + + try { + fileIO.moveDir(dpath.srcDir, dpath.srcDir, DIRMODE_FILE_THROW_ERR, (err) => { + if (err) { + fileIO.rmdirSync(dpath.baseDir); + console.log('fileIO_test_moveDir_async_021 error: {message: ' + err.message + ', code: ' + err.code + '}'); + expect(err.code == 13900020 && err.message == 'Invalid argument').assertTrue(); + done(); + } + }); + } catch (e) { + console.log('fileIO_test_moveDir_async_021 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_MOVEDIRSYNC_2200 + * @tc.name fileIO_test_moveDir_async_022 + * @tc.desc Test moveFile() interface.Promise. + * Invalid path. Can not move subPath. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_test_moveDir_async_022', 3, async function (done) { + let dpath = await readyFiles('fileIO_test_moveDir_async_023'); + + try { + await fileIO.moveDir(dpath.srcDir, dpath.srcDir + '/srcDir_first', DIRMODE_FILE_THROW_ERR); + expect(false).assertTrue(); + } catch (e) { + fileIO.rmdirSync(dpath.baseDir); + console.log('fileIO_test_moveDir_async_022 has failed for ' + e.message + ', code: ' + e.code); + expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue(); + done(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_MOVEDIRSYNC_2300 + * @tc.name fileIO_test_moveDir_async_023 + * @tc.desc Test moveFile() interface.Callback. + * Invalid path.Can not move subPath. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 3 + * @tc.require + */ + it('fileIO_test_moveDir_async_023', 3, async function (done) { + let dpath = await readyFiles('fileIO_test_moveDir_async_023'); + + try { + fileIO.moveDir(dpath.srcDir, dpath.srcDir + '/srcDir_first', DIRMODE_FILE_THROW_ERR, (err) => { + if (err) { + fileIO.rmdirSync(dpath.baseDir); + console.log('fileIO_test_moveDir_async_023 error: {message: ' + err.message + ', code: ' + err.code + '}'); + expect(err.code == 13900020 && err.message == 'Invalid argument').assertTrue(); + done(); + } + }); + } catch (e) { + console.log('fileIO_test_moveDir_async_023 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); +}); +} \ No newline at end of file