未验证 提交 b58b0856 编写于 作者: O openharmony_ci 提交者: Gitee

!7357 Add XTS for mkdtemp, rename and copyFile interfaces of mod_fs

Merge pull request !7357 from zhuhongtao666/readText_copyFile
/*
* 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 {
fileIO, FILE_CONTENT, prepareFile, nextFileName, describe, it, expect, randomString
} from '../Common';
export default function fileIOCopyfile() {
describe('fileIO_fs_copyfile', function () {
/**
* @tc.number SUB_DF_FILEIO_COPY_FILE_SYNC_0000
* @tc.name fileIO_copy_file_sync_000
* @tc.desc Test copyFileSync() interfaces.
* Test file copied successfully by path.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('fileIO_copy_file_sync_000', 0, async function () {
let fpath = await nextFileName('fileIO_copy_file_sync_000');
let fpathTarget = fpath + 'tgt';
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
fileIO.copyFileSync(fpath, fpathTarget);
let stat1 = fileIO.statSync(fpath);
let stat2 = fileIO.statSync(fpathTarget);
expect(stat1.size == stat2.size).assertTrue();
fileIO.unlinkSync(fpath);
fileIO.unlinkSync(fpathTarget);
} catch (e) {
console.log('fileIO_copy_file_sync_000 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_COPY_FILE_SYNC_0100
* @tc.name fileIO_copy_file_sync_001
* @tc.desc Test copyFileSync() interfaces.
* Test file copied successfully by file descriptor.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_copy_file_sync_001', 0, async function () {
let fpath = await nextFileName('fileIO_copy_file_sync_001');
let fpathTarget = fpath + 'tgt';
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let file = fileIO.openSync(fpath, fileIO.OpenMode.READ_WRITE);
fileIO.copyFileSync(file.fd, fpathTarget);
let stat1 = fileIO.statSync(fpath);
let stat2 = fileIO.statSync(fpathTarget);
expect(stat1.size == stat2.size).assertTrue();
fileIO.closeSync(file);
fileIO.unlinkSync(fpath);
fileIO.unlinkSync(fpathTarget);
} catch (e) {
console.log('fileIO_copy_file_sync_001 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_COPY_FILE_SYNC_0200
* @tc.name fileIO_copy_file_sync_002
* @tc.desc Test copyFileSync() interfaces.
* The path point to nothing, no such file.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @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);
expect(false).assertTrue();
} catch (e) {
console.log('fileIO_copy_file_sync_002 has failed for ' + e.message + ', code: ' + e.code);
expect(e.code == 13900002 && 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.
* Missing parameters.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_copy_file_sync_003', 0, function () {
try {
fileIO.copyFileSync();
expect(false).assertTrue();
} catch (e) {
console.log('fileIO_copy_file_sync_003 has failed for ' + e.message + ', code: ' + e.code);
expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_COPY_FILE_SYNC_0400
* @tc.name fileIO_copy_file_sync_004
* @tc.desc Test copyFileSync() interfaces.
* Invalid type of mode.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_copy_file_sync_004', 0, async function () {
let fpath = await nextFileName('fileIO_copy_file_sync_004');
let fpathTarget = fpath + 'tgt';
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
fileIO.copyFileSync(fpath, fpathTarget, '0');
expect(false).assertTrue();
} catch (e) {
fileIO.unlinkSync(fpath);
console.log('fileIO_copy_file_sync_004 has failed for ' + e.message + ', code: ' + e.code);
expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_COPY_FILE_SYNC_0500
* @tc.name fileIO_copy_file_sync_005
* @tc.desc Test copyFileSync() interfaces.
* Test file copied successfully by file descriptor.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_copy_file_sync_005', 0, async function () {
let fpath = await nextFileName('fileIO_copy_file_sync_005');
let fpathTarget = fpath + 'tgt';
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
let fileTgt = fileIO.openSync(fpathTarget, fileIO.OpenMode.CREATE | fileIO.OpenMode.READ_WRITE);
try {
let file = fileIO.openSync(fpath, fileIO.OpenMode.READ_WRITE);
fileIO.copyFileSync(file.fd, fileTgt.fd);
let stat1 = fileIO.statSync(fpath);
let stat2 = fileIO.statSync(fpathTarget);
expect(stat1.size == stat2.size).assertTrue();
fileIO.closeSync(file);
fileIO.closeSync(fileTgt);
fileIO.unlinkSync(fpath);
fileIO.unlinkSync(fpathTarget);
} catch (e) {
console.log('fileIO_copy_file_sync_005 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_COPY_FILE_SYNC_0600
* @tc.name fileIO_copy_file_sync_006
* @tc.desc Test copyFileSync() interfaces.
* Test file copied successfully by file descriptor and path.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_copy_file_sync_006', 0, async function () {
let fpath = await nextFileName('fileIO_copy_file_sync_006');
let fpathTarget = fpath + 'tgt';
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
let fileTgt = fileIO.openSync(fpathTarget, fileIO.OpenMode.CREATE | fileIO.OpenMode.READ_WRITE);
try {
fileIO.copyFileSync(fpath, fileTgt.fd);
let stat1 = fileIO.statSync(fpath);
let stat2 = fileIO.statSync(fpathTarget);
expect(stat1.size == stat2.size).assertTrue();
fileIO.closeSync(fileTgt);
fileIO.unlinkSync(fpath);
fileIO.unlinkSync(fpathTarget);
} catch (e) {
console.log('fileIO_copy_file_sync_006 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_COPY_FILE_SYNC_0700
* @tc.name fileIO_copy_file_sync_007
* @tc.desc Test copyFileSync() interfaces.
* Don't support mode = 1.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_copy_file_sync_007', 0, async function (done) {
let fpath = await nextFileName('fileIO_copy_file_sync_007');
let fpathTarget = fpath + 'tgt';
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
fileIO.copyFileSync(fpath, fpathTarget, 1);
expect(false).assertTrue();
} catch (e) {
fileIO.unlinkSync(fpath);
console.log('fileIO_copy_file_sync_007 has failed for ' + e.message + ', code: ' + e.code);
expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue();
done();
}
});
/**
* @tc.number SUB_DF_FILEIO_COPY_FILE_SYNC_0800
* @tc.name fileIO_copy_file_sync_008
* @tc.desc Test copyFileSync() interfaces.
* The length of file name is too long.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_copy_file_sync_008', 0, async function () {
let fpath = await nextFileName('fileIO_copy_file_sync_008');
let fpathTarget = fpath + randomString(250);
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
fileIO.copyFileSync(fpath, fpathTarget);
expect(false).assertTrue();
} catch (e) {
fileIO.unlinkSync(fpath);
console.log('fileIO_copy_file_sync_008 has failed for ' + e.message + ', code: ' + e.code);
expect(e.code == 13900030 && e.message == 'File name too long').assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_COPY_FILE_ASYNC_0000
* @tc.name fileIO_copy_file_async_000
* @tc.desc Test copyFile() interfaces. Promise.
* Test file copied successfully by path.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_copy_file_async_000', 0, async function (done) {
let fpath = await nextFileName('fileIO_copy_file_async_000');
let fpathTarget = fpath + 'tgt';
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
await fileIO.copyFile(fpath, fpathTarget);
let stat1 = fileIO.statSync(fpath);
let stat2 = fileIO.statSync(fpathTarget);
expect(stat1.size == stat2.size).assertTrue();
fileIO.unlinkSync(fpath);
fileIO.unlinkSync(fpathTarget);
done();
} catch (e) {
console.log('fileIO_copy_file_async_000 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_COPY_FILE_ASYNC_0100
* @tc.name fileIO_copy_file_async_001
* @tc.desc Test copyFile() interfaces. Callback.
* Test file copied successfully by path.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_copy_file_async_001', 0, async function (done) {
let fpath = await nextFileName('fileIO_copy_file_async_001');
let fpathTarget = fpath + 'tgt';
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
fileIO.copyFile(fpath, fpathTarget, (err) => {
if (err) {
console.log('fileIO_copy_file_async_001 error package: ' + JSON.stringify(err));
expect(false).assertTrue();
}
let stat1 = fileIO.statSync(fpath);
let stat2 = fileIO.statSync(fpathTarget);
expect(stat1.size == stat2.size).assertTrue();
fileIO.unlinkSync(fpath);
fileIO.unlinkSync(fpathTarget);
done();
});
} catch (e) {
console.log('fileIO_copy_file_async_001 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_COPY_FILE_ASYNC_0200
* @tc.name fileIO_copy_file_async_002
* @tc.desc Test copyFile() interfaces. Promise.
* Test file copied successfully by file descriptor.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_copy_file_async_002', 0, async function (done) {
let fpath = await nextFileName('fileIO_copy_file_async_002');
let fpathTarget = fpath + 'tgt';
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let file = fileIO.openSync(fpath, fileIO.OpenMode.CREATE | fileIO.OpenMode.READ_WRITE);
await fileIO.copyFile(file.fd, fpathTarget);
let stat1 = fileIO.statSync(fpath);
let stat2 = fileIO.statSync(fpathTarget);
expect(stat1.size == stat2.size).assertTrue();
fileIO.closeSync(file);
fileIO.unlinkSync(fpath);
fileIO.unlinkSync(fpathTarget);
done();
} catch (e) {
console.log('fileIO_copy_file_async_002 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_COPY_FILE_ASYNC_0300
* @tc.name fileIO_copy_file_async_003
* @tc.desc Test copyFile() interfaces. Promise.
* The path point to nothing, no such file.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_copy_file_async_003', 0, async function (done) {
let fpath = await nextFileName('fileIO_copy_file_async_003');
let fpathTarget = fpath + 'tgt';
try {
await fileIO.copyFile(fpath, fpathTarget);
expect(false).assertTrue();
} catch (e) {
console.log('fileIO_copy_file_async_003 has failed for ' + e.message + ', code: ' + e.code);
expect(e.code == 13900002 && e.message == 'No such file or directory').assertTrue();
done();
}
});
/**
* @tc.number SUB_DF_FILEIO_COPY_FILE_ASYNC_0400
* @tc.name fileIO_copy_file_async_004
* @tc.desc Test copyFile() interfaces. Callback.
* The path point to nothing, no such file.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_copy_file_async_004', 0, async function (done) {
let fpath = await nextFileName('fileIO_copy_file_async_004');
let fpathTarget = fpath + 'tgt';
try {
fileIO.copyFile(fpath, fpathTarget, (err) => {
if (err) {
console.log('fileIO_copy_file_async_005 error: {message: ' + err.message + ', code: ' + err.code + '}');
expect(err.code == 13900002 && err.message == 'No such file or directory').assertTrue();
done();
}
});
} catch (e) {
console.log('fileIO_copy_file_async_004 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_COPY_FILE_ASYNC_0500
* @tc.name fileIO_copy_file_async_005
* @tc.desc Test copyFile() interfaces. Promise.then().catch()
* The path point to nothing, no such file.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @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';
try {
fileIO.copyFile(fpath, fpathTarget).then(() => {
expect(false).assertTrue();
}).catch((err) => {
console.log('fileIO_copy_file_async_005 error: {message: ' + err.message + ', code: ' + err.code + '}');
expect(err.code == 13900002 && err.message == 'No such file or directory').assertTrue();
done();
});
} catch (e) {
console.log('fileIO_copy_file_async_005 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_COPY_FILE_ASYNC_0600
* @tc.name fileIO_copy_file_async_006
* @tc.desc Test copyFile() interfaces. Promise.
* Missing Parameter.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_copy_file_async_006', 0, async function (done) {
let fpath = await nextFileName('fileIO_copy_file_async_006');
try {
await fileIO.copyFile(fpath);
expect(false).assertTrue();
} catch (e) {
console.log('fileIO_copy_file_async_006 has failed for ' + e.message + ', code: ' + e.code);
expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue();
done();
}
});
/**
* @tc.number SUB_DF_FILEIO_COPY_FILE_ASYNC_0700
* @tc.name fileIO_copy_file_async_007
* @tc.desc Test copyFile() interfaces. Callback.
* Missing Parameter.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_copy_file_async_007', 0, async function (done) {
let fpath = await nextFileName('fileIO_copy_file_async_007');
try {
fileIO.copyFile(fpath, (err) => {
expect(false).assertTrue();
});
} catch (e) {
console.log('fileIO_copy_file_async_007 has failed for ' + e.message + ', code: ' + e.code);
expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue();
done();
}
});
/**
* @tc.number SUB_DF_FILEIO_COPY_FILE_ASYNC_0800
* @tc.name fileIO_copy_file_async_008
* @tc.desc Test copyFile() interfaces. Promise.
* Test file copied successfully by path when mode = 0.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_copy_file_async_008', 0, async function (done) {
let fpath = await nextFileName('fileIO_copy_file_async_008');
let fpathTarget = fpath + 'tgt';
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
await fileIO.copyFile(fpath, fpathTarget, 0);
let stat1 = fileIO.statSync(fpath);
let stat2 = fileIO.statSync(fpathTarget);
expect(stat1.size == stat2.size).assertTrue();
fileIO.unlinkSync(fpath);
fileIO.unlinkSync(fpathTarget);
done();
} catch (e) {
console.log('fileIO_copy_file_async_008 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_COPY_FILE_ASYNC_0900
* @tc.name fileIO_copy_file_async_009
* @tc.desc Test copyFile() interfaces. Callback.
* Test file copied successfully by path when mode = 0.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_copy_file_async_009', 0, async function (done) {
let fpath = await nextFileName('fileIO_copy_file_async_009');
let fpathTarget = fpath + 'tgt';
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
fileIO.copyFile(fpath, fpathTarget, 0, (err) => {
if (err) {
console.log('fileIO_copy_file_async_007 error package: ' + JSON.stringify(err));
expect(false).assertTrue();
}
let stat1 = fileIO.statSync(fpath);
let stat2 = fileIO.statSync(fpathTarget);
expect(stat1.size == stat2.size).assertTrue();
fileIO.unlinkSync(fpath);
fileIO.unlinkSync(fpathTarget);
done();
});
} catch (e) {
console.log('fileIO_copy_file_async_007 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_COPY_FILE_ASYNC_1000
* @tc.name fileIO_copy_file_async_010
* @tc.desc Test copyFile() interfaces. Callback.
* Don't support mode = 1.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_copy_file_async_010', 0, async function (done) {
let fpath = await nextFileName('fileIO_copy_file_async_010');
let fpathTarget = fpath + 'tgt';
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
fileIO.copyFile(fpath, fpathTarget, 1, (err) => {
expect(false).assertTrue();
});
} catch (e) {
fileIO.unlinkSync(fpath);
console.log('fileIO_copy_file_async_010 has failed for ' + e.message + ', code: ' + e.code);
expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue();
done();
}
});
/**
* @tc.number SUB_DF_FILEIO_COPY_FILE_ASYNC_1100
* @tc.name fileIO_copy_file_async_011
* @tc.desc Test copyFile() interfaces. Promise.
* Invalid type of mode.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_copy_file_async_011', 0, async function (done) {
let fpath = await nextFileName('fileIO_copy_file_async_011');
let fpathTarget = fpath + 'tgt';
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
await fileIO.copyFile(fpath, fpathTarget, '0');
expect(false).assertTrue();
} catch (e) {
fileIO.unlinkSync(fpath);
console.log('fileIO_copy_file_async_011 has failed for ' + e.message + ', code: ' + e.code);
expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue();
done();
}
});
/**
* @tc.number SUB_DF_FILEIO_COPY_FILE_ASYNC_1200
* @tc.name fileIO_copy_file_async_012
* @tc.desc Test copyFile() interfaces. Promise.
* Test file copied successfully by file descriptor.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_copy_file_async_012', 0, async function (done) {
let fpath = await nextFileName('fileIO_copy_file_async_012');
let fpathTarget = fpath + 'tgt';
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
let fileTgt = fileIO.openSync(fpathTarget, fileIO.OpenMode.CREATE | fileIO.OpenMode.READ_WRITE);
try {
let file = fileIO.openSync(fpath, fileIO.OpenMode.READ_WRITE);
await fileIO.copyFile(file.fd, fileTgt.fd);
let stat1 = fileIO.statSync(fpath);
let stat2 = fileIO.statSync(fpathTarget);
expect(stat1.size == stat2.size).assertTrue();
fileIO.closeSync(file);
fileIO.closeSync(fileTgt);
fileIO.unlinkSync(fpath);
fileIO.unlinkSync(fpathTarget);
done();
} catch (e) {
console.log('fileIO_copy_file_async_012 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_COPY_FILE_ASYNC_1300
* @tc.name fileIO_copy_file_async_013
* @tc.desc Test copyFile() interfaces. Callback.
* Test file copied successfully by file descriptor.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_copy_file_async_013', 0, async function (done) {
let fpath = await nextFileName('fileIO_copy_file_async_012');
let fpathTarget = fpath + 'tgt';
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
let fileTgt = fileIO.openSync(fpathTarget, fileIO.OpenMode.CREATE | fileIO.OpenMode.READ_WRITE);
try {
let file = fileIO.openSync(fpath, fileIO.OpenMode.READ_WRITE);
fileIO.copyFile(file.fd, fileTgt.fd, (err) => {
if (err) {
console.log('fileIO_copy_file_async_013 error package: ' + JSON.stringify(err));
expect(false).assertTrue();
}
let stat1 = fileIO.statSync(fpath);
let stat2 = fileIO.statSync(fpathTarget);
expect(stat1.size == stat2.size).assertTrue();
fileIO.closeSync(file);
fileIO.closeSync(fileTgt);
fileIO.unlinkSync(fpath);
fileIO.unlinkSync(fpathTarget);
done();
});
} catch (e) {
console.log('fileIO_copy_file_async_013 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_COPY_FILE_ASYNC_1400
* @tc.name fileIO_copy_file_async_014
* @tc.desc Test copyFile() interfaces. Promise.
* Test file copied successfully by file descriptor and path when mode = 0.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_copy_file_async_014', 0, async function (done) {
let fpath = await nextFileName('fileIO_copy_file_async_014');
let fpathTarget = fpath + 'tgt';
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
expect(prepareFile(fpathTarget, FILE_CONTENT)).assertTrue();
try {
let file = fileIO.openSync(fpathTarget, fileIO.OpenMode.READ_WRITE);
await fileIO.copyFile(fpath, file.fd, 0);
let stat1 = fileIO.statSync(fpath);
let stat2 = fileIO.statSync(fpathTarget);
expect(stat1.size == stat2.size).assertTrue();
fileIO.closeSync(file);
fileIO.unlinkSync(fpath);
fileIO.unlinkSync(fpathTarget);
done();
} catch (e) {
console.log('fileIO_copy_file_async_014 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_COPY_FILE_ASYNC_1500
* @tc.name fileIO_copy_file_async_015
* @tc.desc Test copyFile() interfaces. Callback.
* Test file copied successfully by file descriptor and path.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_copy_file_async_015', 0, async function (done) {
let fpath = await nextFileName('fileIO_copy_file_async_014');
let fpathTarget = fpath + 'tgt';
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
let file = fileIO.openSync(fpathTarget, fileIO.OpenMode.CREATE | fileIO.OpenMode.READ_WRITE);
try {
fileIO.copyFile(fpath, file.fd, 0, (err) => {
if (err) {
console.log('fileIO_copy_file_async_013 error package: ' + JSON.stringify(err));
expect(false).assertTrue();
}
let stat1 = fileIO.statSync(fpath);
let stat2 = fileIO.statSync(fpathTarget);
expect(stat1.size == stat2.size).assertTrue();
fileIO.closeSync(file);
fileIO.unlinkSync(fpath);
fileIO.unlinkSync(fpathTarget);
done();
});
} catch (e) {
console.log('fileIO_copy_file_async_015 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_COPY_FILE_ASYNC_1600
* @tc.name fileIO_copy_file_async_016
* @tc.desc Test copyFile() interfaces. Promise
* The length of file name is too long.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_copy_file_async_016', 0, async function (done) {
let fpath = await nextFileName('fileIO_copy_file_async_016');
let fpathTarget = fpath + randomString(250);
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
await fileIO.copyFile(fpath, fpathTarget);
expect(false).assertTrue();
} catch (e) {
console.log('fileIO_copy_file_async_016 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_COPY_FILE_ASYNC_1700
* @tc.name fileIO_copy_file_async_017
* @tc.desc Test copyFile() interfaces. Callback
* The length of file name is too long.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_copy_file_async_017', 0, async function (done) {
let fpath = await nextFileName('fileIO_copy_file_async_017');
let fpathTarget = fpath + randomString(250);
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
fileIO.copyFile(fpath, fpathTarget, (err) => {
if (err) {
fileIO.unlinkSync(fpath);
console.log('fileIO_copy_file_async_017 error: {message: ' + err.message + ', code: ' + err.code);
expect(err.code == 13900030 && err.message == 'File name too long').assertTrue();
done();
}
});
} catch (e) {
console.log('fileIO_copy_file_async_017 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
});
}
/*
* 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 { fileIO, nextFileName, describe, it, expect } from '../Common';
export default function fileIOMkdtemp() {
describe('fileIO_fs_mkdtemp', function () {
/**
* @tc.number SUB_DF_FILEIO_MKDTEMP_SYNC_0000
* @tc.name fileIO_test_mkdtemp_sync_000
* @tc.desc Test mkdtempSync() interface.
* Create a temporary directory, verify the normal function.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it('fileIO_test_mkdtemp_sync_000', 0, async function () {
let dpath = await nextFileName('fileIO_test_mkdtemp_sync_000');
try {
dpath = dpath + 'XXXXXX';
let res = fileIO.mkdtempSync(dpath);
expect(fileIO.accessSync(res)).assertTrue();
fileIO.rmdirSync(res);
} catch (e) {
console.log('fileIO_test_mkdtemp_sync_000 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_MKDTEMP_SYNC_0100
* @tc.name fileIO_test_mkdtemp_sync_001
* @tc.desc Test mkdtempSync() interface.
* The directory should end in XXXXXX.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_mkdtemp_sync_001', 0, async function () {
let dpath = await nextFileName('fileIO_test_mkdtemp_sync_000');
try {
fileIO.mkdtempSync(dpath);
expect(false).assertTrue();
} catch (e) {
console.log('fileIO_test_mkdtemp_sync_001 has failed for ' + e.message + ', code: ' + e.code);
expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_MKDTEMP_SYNC_0200
* @tc.name fileIO_test_mkdtemp_sync_002
* @tc.desc Test mkdtempSync() interface.
* Missing parameters.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_mkdtemp_sync_002', 0, async function () {
try {
fileIO.mkdtempSync();
expect(false).assertTrue();
} catch (e) {
console.log('fileIO_test_mkdtemp_sync_002 has failed for ' + e.message + ', code: ' + e.code);
expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_MKDTEMP_ASYNC_0000
* @tc.name fileIO_test_mkdtemp_async_000
* @tc.desc Test mkdtemp() interface. Promise.
* Create a temporary directory, verify the normal function.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_mkdtemp_async_000', 0, async function (done) {
let dpath = await nextFileName('fileIO_test_mkdtemp_async_000');
try {
dpath = dpath + 'XXXXXX';
let res = await fileIO.mkdtemp(dpath);
expect(fileIO.accessSync(res)).assertTrue();
fileIO.rmdirSync(res);
done();
} catch (e) {
console.log('fileIO_test_mkdtemp_async_000 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_MKDTEMP_ASYNC_0100
* @tc.name fileIO_test_mkdtemp_async_001
* @tc.desc Test mkdtemp() interface. Callback.
* Create a temporary directory, verify the normal function.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_mkdtemp_async_001', 0, async function (done) {
let dpath = await nextFileName('fileIO_test_mkdtemp_async_001');
try {
dpath = dpath + 'XXXXXX';
fileIO.mkdtemp(dpath, (err, res) => {
if (err) {
console.log('fileIO_test_mkdtemp_async_001 error package: ' + JSON.stringify(err));
expect(false).assertTrue();
}
expect(fileIO.accessSync(res)).assertTrue();
fileIO.rmdirSync(res);
done();
});
} catch (e) {
console.log('fileIO_test_mkdtemp_async_001 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_MKDTEMP_ASYNC_0200
* @tc.name fileIO_test_mkdtemp_async_002
* @tc.desc Test mkdtemp() interface. Promise.
* The directory should end in XXXXXX.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_mkdtemp_async_002', 0, async function (done) {
let dpath = await nextFileName('fileIO_test_mkdtemp_async_002');
try {
await fileIO.mkdtemp(dpath);
expect(false).assertTrue();
} catch (e) {
console.log('fileIO_test_mkdtemp_async_002 has failed for ' + e.message + ', code: ' + e.code);
expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue();
done();
}
});
/**
* @tc.number SUB_DF_FILEIO_MKDTEMP_ASYNC_0300
* @tc.name fileIO_test_mkdtemp_async_003
* @tc.desc Test mkdtemp() interface. Callback.
* The directory should end in XXXXXX.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_mkdtemp_async_003', 0, async function (done) {
let dpath = await nextFileName('fileIO_test_mkdtemp_async_003');
try {
fileIO.mkdtemp(dpath, (err) => {
if (err) {
console.log('fileIO_test_mkdtemp_async_003 error package: ' + JSON.stringify(err));
expect(err.code == 13900020 && err.message == 'Invalid argument').assertTrue();
done();
}
});
} catch (e) {
console.log('fileIO_test_mkdtemp_async_003 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_MKDTEMP_ASYNC_0400
* @tc.name fileIO_test_mkdtemp_async_004
* @tc.desc Test mkdtemp() interface. Promise.
* Missing parameters.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_mkdtemp_async_004', 0, async function (done) {
try {
await fileIO.mkdtemp();
expect(false).assertTrue();
} catch (e) {
console.log('fileIO_test_mkdtemp_async_004 has failed for ' + e.message + ', code: ' + e.code);
expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue();
done();
}
});
});
}
/*
* 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 {
fileIO, FILE_CONTENT, prepareFile, nextFileName, describe, it, expect, randomString
} from '../Common';
export default function fileIORename() {
describe('fileIO_fs_rename', function () {
/**
* @tc.number SUB_DF_FILEIO_RENAME_SYNC_0000
* @tc.name fileIO_test_rename_sync_000
* @tc.desc Test renameSync() interfaces.
* Rename the file by path, verify the normal function.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it('fileIO_test_rename_sync_000', 0, async function () {
let fpath = await nextFileName('fileIO_test_rename_sync_000');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let newf = fpath + 'test';
fileIO.renameSync(fpath, newf);
expect(fileIO.accessSync(newf)).assertTrue();
fileIO.unlinkSync(newf);
} catch (e) {
console.log('fileIO_test_rename_sync_000 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_RENAME_SYNC_0100
* @tc.name fileIO_test_rename_sync_001
* @tc.desc Test renameSync() interfaces.
* The path point to nothing, no such file.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_rename_sync_001', 0, async function () {
let fpath = await nextFileName('fileIO_test_rename_sync_001');
try {
fileIO.renameSync(fpath, fpath + 'test');
expect(false).assertTrue();
} catch (e) {
console.log('fileIO_test_rename_sync_001 has failed for ' + e.message + ', code: ' + e.code);
expect(e.code == 13900002 && e.message == 'No such file or directory').assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_RENAME_SYNC_0200
* @tc.name fileIO_test_rename_sync_002
* @tc.desc Test renameSync() interfaces.
* Missing parameter.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_rename_sync_002', 0, async function () {
let fpath = await nextFileName('fileIO_test_rename_sync_002');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
fileIO.renameSync(fpath);
expect(false).assertTrue();
} catch (e) {
fileIO.unlinkSync(fpath);
console.log('fileIO_test_rename_sync_002 has failed for ' + e.message + ', code: ' + e.code);
expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_RENAME_SYNC_0300
* @tc.name fileIO_test_rename_sync_003
* @tc.desc Test renameSync() interfaces.
* Illegal second parameter.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_rename_sync_003', 0, async function () {
let fpath = await nextFileName('fileIO_test_rename_sync_003');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
fileIO.renameSync(fpath, null);
expect(false).assertTrue();
} catch (e) {
fileIO.unlinkSync(fpath);
console.log('fileIO_test_rename_sync_003 has failed for ' + e.message + ', code: ' + e.code);
expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_RENAME_SYNC_0400
* @tc.name fileIO_test_rename_sync_004
* @tc.desc Test renameSync() interfaces.
* Illegal second parameter.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_rename_sync_004', 0, async function () {
let fpath = await nextFileName('fileIO_test_rename_sync_004');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
fileIO.renameSync(fpath, undefined);
expect(false).assertTrue();
} catch (e) {
fileIO.unlinkSync(fpath);
console.log('fileIO_test_rename_sync_004 has failed for ' + e.message + ', code: ' + e.code);
expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_RENAME_SYNC_0500
* @tc.name fileIO_test_rename_sync_005
* @tc.desc Test renameSync() interfaces.
* Modify file names across directory.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_rename_sync_005', 0, async function () {
let dpath = await nextFileName('fileIO_test_rename_sync_005');
let fpath = dpath + '/file_000';
fileIO.mkdirSync(dpath);
fileIO.mkdirSync(dpath + '/dir_000');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let newf = dpath + '/dir_000/newFileName';
fileIO.renameSync(fpath, newf);
fileIO.rmdirSync(dpath);
} catch (e) {
console.log('fileIO_test_rename_sync_005 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_RENAME_SYNC_0600
* @tc.name fileIO_test_rename_sync_006
* @tc.desc Test renameSync() interfaces.
* The length of file name is too long.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_rename_sync_006', 0, async function (done) {
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);
expect(false).assertTrue();
} catch (e) {
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_ASYNC_0000
* @tc.name fileIO_test_rename_async_000
* @tc.desc Test rename() interfaces. Promise.
* Rename the file by path, verify the normal function.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_rename_async_000', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_rename_async_000');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
let newf = fpath + '123';
try {
await fileIO.rename(fpath, newf);
expect(fileIO.accessSync(newf)).assertTrue();
fileIO.unlinkSync(newf);
done();
} catch (e) {
console.log('fileIO_test_rename_async_000 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_RENAME_ASYNC_0100
* @tc.name fileIO_test_rename_async_001
* @tc.desc Test rename() interfaces. Callback.
* Rename the file by path, verify the normal function.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_rename_async_001', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_rename_async_001');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
let newf = fpath + 'aaa';
try {
fileIO.rename(fpath, newf, (err) => {
if (err) {
console.log('fileIO_test_rename_async_001 error package: ' + JSON.stringify(err));
expect(false).assertTrue();
}
expect(fileIO.accessSync(newf)).assertTrue();
fileIO.unlinkSync(newf);
done();
})
} catch (e) {
console.log('fileIO_test_rename_async_001 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_RENAME_ASYNC_0200
* @tc.name fileIO_test_rename_async_002
* @tc.desc Test rename() interfaces. Promise.
* The path point to nothing, no such file.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_rename_async_002', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_rename_async_002');
try {
await fileIO.rename(fpath, fpath + 'bbb');
expect(false).assertTrue();
} catch (e) {
console.log('fileIO_test_rename_async_002 has failed for ' + e.message + ', code: ' + e.code);
expect(e.code == 13900002 && e.message == 'No such file or directory').assertTrue();
done();
}
});
/**
* @tc.number SUB_DF_FILEIO_RENAME_ASYNC_0300
* @tc.name fileIO_test_rename_async_003
* @tc.desc Test rename() interfaces. Callback.
* The path point to nothing, no such file.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_rename_async_003', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_rename_async_003');
try {
fileIO.rename(fpath, fpath + 'bbb', (err) => {
if (err) {
console.log('fileIO_test_rename_async_003 error: {message: ' + err.message + ', code: ' + err.code + '}');
expect(err.code == 13900002 && err.message == 'No such file or directory').assertTrue();
done();
}
});
} catch (e) {
console.log('fileIO_test_rename_async_003 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_RENAME_ASYNC_0400
* @tc.name fileIO_test_rename_async_004
* @tc.desc Test rename() interfaces. Promise.
* Missing parameter.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_rename_async_004', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_rename_async_004');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
await fileIO.rename(fpath);
expect(false).assertTrue();
} catch (e) {
fileIO.unlinkSync(fpath);
console.log('fileIO_test_rename_async_004 has failed for ' + e.message + ', code: ' + e.code);
expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue();
done();
}
});
/**
* @tc.number SUB_DF_FILEIO_RENAME_ASYNC_0500
* @tc.name fileIO_test_rename_async_005
* @tc.desc Test rename() interfaces. Promise.
* Illegal second parameter.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_rename_async_005', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_rename_async_005');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
await fileIO.rename(fpath, null);
expect(false).assertTrue();
} catch (e) {
fileIO.unlinkSync(fpath);
console.log('fileIO_test_rename_async_005 has failed for ' + e.message + ', code: ' + e.code);
expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue();
done();
}
});
/**
* @tc.number SUB_DF_FILEIO_RENAME_ASYNC_0600
* @tc.name fileIO_test_rename_async_006
* @tc.desc Test rename() interfaces. Promise.
* Illegal second parameter.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_rename_async_006', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_rename_async_006');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
await fileIO.rename(fpath, undefined);
expect(false).assertTrue();
} catch (e) {
fileIO.unlinkSync(fpath);
console.log('fileIO_test_rename_async_006 has failed for ' + e.message + ', code: ' + e.code);
expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue();
done();
}
});
/**
* @tc.number SUB_DF_FILEIO_RENAME_ASYNC_0700
* @tc.name fileIO_test_rename_async_007
* @tc.desc Test rename() interfaces. Promise.
* Modify file names across directory.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_rename_async_007', 0, async function (done) {
let dpath = await nextFileName('fileIO_test_rename_async_007');
let fpath = dpath + '/file_001';
fileIO.mkdirSync(dpath);
fileIO.mkdirSync(dpath + '/dir_001');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let newf = dpath + '/dir_001/newFileName';
await fileIO.rename(fpath, newf);
fileIO.rmdirSync(dpath);
done();
} catch (e) {
console.log('fileIO_test_rename_async_007 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_RENAME_ASYNC_0800
* @tc.name fileIO_test_rename_async_008
* @tc.desc Test rename() interfaces. Callback.
* Modify file names across directory.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_rename_async_008', 0, async function (done) {
let dpath = await nextFileName('fileIO_test_rename_async_008');
let fpath = dpath + '/file_002';
fileIO.mkdirSync(dpath);
fileIO.mkdirSync(dpath + '/dir_002');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let newf = dpath + '/dir_002/newFileName';
fileIO.rename(fpath, newf, (err) => {
if (err) {
console.log('fileIO_test_rename_async_008 error package: ' + JSON.stringify(err));
expect(false).assertTrue();
}
fileIO.rmdirSync(dpath);
});
done();
} catch (e) {
console.log('fileIO_test_rename_async_008 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_RENAME_ASYNC_0900
* @tc.name fileIO_test_rename_async_009
* @tc.desc Test rename() interfaces. Promise
* The length of file name is too long.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_rename_async_009', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_rename_async_009');
let fpathTarget = fpath + randomString(250);
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
await fileIO.rename(fpath, fpathTarget);
expect(false).assertTrue();
} catch (e) {
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();
}
});
/**
* @tc.number SUB_DF_FILEIO_RENAME_ASYNC_1000
* @tc.name fileIO_test_rename_async_010
* @tc.desc Test rename() interfaces. Callback
* The length of file name is too long.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_rename_async_010', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_rename_async_010');
let fpathTarget = fpath + randomString(250);
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
fileIO.rename(fpath, fpathTarget, (err) => {
if (err) {
fileIO.unlinkSync(fpath);
console.log('fileIO_test_rename_async_010 error: {message: ' + err.message + ', code: ' + err.code + '}');
expect(err.code == 13900030 && err.message == 'File name too long').assertTrue();
done();
}
});
} catch (e) {
console.log('fileIO_test_rename_async_010 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
});
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册