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

!7394 【回合monthly】Add XTS for lstat, symlink hash, readText, access mkdtemp,...

!7394 【回合monthly】Add XTS for lstat, symlink hash, readText, access mkdtemp, rename, copyFile interfaces of mod_fs
Merge pull request !7394 from zhuhongtao666/cherry-pick-1675386955
/*
* Copyright (C) 2022 Huawei Device Co., Ltd.
* Copyright (C) 2022-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
......@@ -13,7 +13,6 @@
* limitations under the License.
*/
import fileio from '@ohos.fileio';
import fileIO from '@ohos.file.fs';
import util from '@ohos.util';
import featureAbility from '@ohos.ability.featureAbility';
......@@ -30,8 +29,8 @@ export function prepareFile(fpath, content) {
let file = fileIO.openSync(fpath, fileIO.OpenMode.CREATE | fileIO.OpenMode.READ_WRITE)
fileIO.truncateSync(file.fd)
fileIO.writeSync(file.fd, content)
fileio.fsyncSync(file.fd)
fileio.closeSync(file.fd)
fileIO.fsyncSync(file.fd)
fileIO.closeSync(file)
return true
}
catch (e) {
......@@ -40,46 +39,6 @@ export function prepareFile(fpath, content) {
}
}
export function prepareEmptyFile(fpath) {
try {
let file = fileIO.openSync(fpath, fileIO.OpenMode.CREATE | fileIO.OpenMode.READ_WRITE)
fileio.closeSync(file.fd)
return true
}
catch (e) {
console.log('Failed to prepareFile for ' + e)
return false
}
}
export function fileToReadOnly(fpath) {
try {
let file = fileIO.openSync(fpath, fileIO.OpenMode.CREATE)
fileio.fchmodSync(file.fd, 0o444)
fileio.fsyncSync(file.fd)
fileio.closeSync(file.fd)
return true
}
catch (e) {
console.log('Failed to fileToReadOnly for ' + e);
return false
}
}
export function fileToWriteOnly(fpath) {
try {
let file = fileIO.openSync(fpath, fileIO.OpenMode.CREATE | fileIO.OpenMode.WRITE_ONLY)
fileio.fchmodSync(file.fd, 0o222)
fileio.fsyncSync(file.fd)
fileio.closeSync(file.fd)
return true
}
catch (e) {
console.log('Failed to fileToWriteOnly ' + e)
return false
}
}
export async function nextFileName(testName) {
let context = featureAbility.getContext();
let data = await context.getCacheDir();
......@@ -105,15 +64,6 @@ export function randomString(num) {
return pwd;
}
export function forceRemoveDir(path, num) {
for (let i = num; i >= 0; i--) {
if (i < num) {
path = path.replace(`/d${i}`, "");
}
fileio.rmdirSync(path);
}
}
function isIntNum(val) {
return typeof val === 'number' && val % 1 === 0;
}
......@@ -126,22 +76,11 @@ function isString(str) {
return (typeof str == 'string') && str.constructor == String;
}
function isBoolean(val) {
return typeof val == 'boolean';
}
function isInclude(error, message) {
return error.toString().indexOf(message) != -1;
}
export {
fileio,
fileIO,
isIntNum,
isBigInt,
isString,
isBoolean,
isInclude,
describe,
it,
expect,
......
/*
* 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, isIntNum, describe, it, expect,
} from '../Common';
export default function fileIOAccess() {
describe('fileIO_fs_access', function () {
/**
* @tc.number SUB_DF_FILEIO_ACCESS_SYNC_0000
* @tc.name fileIO_test_access_sync_000
* @tc.desc Test accessSync() interface.
* This interface shall work properly in normal case.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('fileIO_test_access_sync_000', 0, async function () {
let fpath = await nextFileName('fileIO_test_access_sync_000');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
expect(fileIO.accessSync(fpath)).assertTrue();
let file = fileIO.openSync(fpath);
expect(isIntNum(file.fd)).assertTrue();
let readlen = fileIO.readSync(file.fd, new ArrayBuffer(4096));
expect(readlen == FILE_CONTENT.length).assertTrue();
fileIO.closeSync(file);
fileIO.unlinkSync(fpath);
} catch (e) {
console.log('fileIO_test_access_sync_000 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_ACCESS_SYNC_0100
* @tc.name fileIO_test_access_sync_001
* @tc.desc Test accessSync() interface.
* The test file is not exist.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_access_sync_001', 0, async function () {
let fpath = await nextFileName('fileIO_test_access_sync_001');
try {
let ret = fileIO.accessSync(fpath);
expect(ret === false).assertTrue();
} catch (e) {
console.log('fileIO_test_access_sync_001 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_ACCESS_SYNC_0200
* @tc.name fileIO_test_access_sync_002
* @tc.desc Test accessSync() interface.
* The test file path is illegal.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_access_sync_002', 0, async function () {
try {
expect(fileIO.accessSync(-1)).assertTrue();
expect(false).assertTrue();
} catch (e) {
console.log('fileIO_test_access_sync_001 has failed for ' + e.message + ', code: ' + e.code);
expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_ACCESS_ASYNC_0000
* @tc.name fileIO_test_access_async_000
* @tc.desc Test access() interface. Promise.
* Use promise to test that the file is exist. Sync method reads data from file.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_access_async_000', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_access_async_000');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let ret = await fileIO.access(fpath);
expect(ret === true).assertTrue();
let file = fileIO.openSync(fpath);
expect(isIntNum(file.fd)).assertTrue();
let readlen = fileIO.readSync(file.fd, new ArrayBuffer(4096));
expect(readlen == FILE_CONTENT.length).assertTrue();
fileIO.closeSync(file);
fileIO.unlinkSync(fpath);
done();
} catch (e) {
console.log('fileIO_test_access_async_000 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_ACCESS_ASYNC_0100
* @tc.name fileIO_test_access_async_001
* @tc.desc Test access() interface. Callback.
* Use callback to test that the file is exist. Sync method reads data from file.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_access_async_001', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_access_async_001');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
fileIO.access(fpath, (err, ret) => {
if (err) {
console.log('fileIO_test_access_async_001 error package: ' + JSON.stringify(err));
expect(false).assertTrue();
}
expect(ret === true).assertTrue();
let file = fileIO.openSync(fpath);
expect(isIntNum(file.fd)).assertTrue();
let readlen = fileIO.readSync(file.fd, new ArrayBuffer(4096));
expect(readlen == FILE_CONTENT.length).assertTrue();
fileIO.closeSync(file);
fileIO.unlinkSync(fpath);
});
done();
} catch (e) {
console.log('fileIO_test_access_async_001 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_ACCESS_ASYNC_0200
* @tc.name fileIO_test_access_async_002
* @tc.desc Test access() interface. Promise.
* Async test file does not exist.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_access_async_002', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_access_async_002');
try {
let ret = await fileIO.access(fpath);
expect(ret === false).assertTrue();
done();
} catch (e) {
console.log('fileIO_test_access_async_002 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_ACCESS_ASYNC_0300
* @tc.name fileIO_test_access_async_003
* @tc.desc Test access() interface. Callback.
* Async test file does not exist.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_access_async_003', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_access_async_002');
try {
fileIO.access(fpath, (err, ret) => {
if (err) {
console.log('fileIO_test_access_async_003 error package: ' + JSON.stringify(err));
expect(false).assertTrue();
}
expect(ret === false).assertTrue();
done();
});
} catch (e) {
console.log('fileIO_test_access_async_003 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_ACCESS_ASYNC_0400
* @tc.name fileIO_test_access_async_004
* @tc.desc Test access() interface. Promise.
* Invalid path parameter.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_access_async_004', 0, async function (done) {
try {
await fileIO.access(-1);
expect(false).assertTrue();
} catch (e) {
console.log('fileIO_test_access_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_ACCESS_ASYNC_0500
* @tc.name fileIO_test_access_async_005
* @tc.desc Test access() interface. Callback.
* Invalid path parameter.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_access_async_005', 0, async function (done) {
try {
fileIO.access(-1, (err) => {
expect(false).assertTrue();
});
} catch (e) {
console.log('fileIO_test_access_async_005 has failed for ' + e.message + ', code: ' + e.code);
expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue();
done();
}
});
});
}
......@@ -14,8 +14,7 @@
*/
import {
fileio, fileIO, FILE_CONTENT, prepareFile, nextFileName,
describe, it, expect,
fileIO, FILE_CONTENT, prepareFile, nextFileName, describe, it, expect,
} from '../Common';
export default function fileIOFdatasync() {
......@@ -38,8 +37,8 @@ export default function fileIOFdatasync() {
try {
let file = fileIO.openSync(fpath, fileIO.OpenMode.READ_WRITE);
fileIO.fdatasyncSync(file.fd);
fileio.closeSync(file.fd);
fileio.unlinkSync(fpath);
fileIO.closeSync(file);
fileIO.unlinkSync(fpath);
} catch (e) {
console.log('fileIO_test_fdatasync_sync_000 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
......@@ -47,12 +46,12 @@ export default function fileIOFdatasync() {
});
/**
* @tc.number SUB_DF_FILEIO_FDATASYNC_SYNC_0010
* @tc.number SUB_DF_FILEIO_FDATASYNC_SYNC_0100
* @tc.name fileIO_test_fdatasync_sync_001
* @tc.desc Test fdatasyncSync() interfaces. Invalid fd parameter.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_fdatasync_sync_001', 0, async function () {
......@@ -67,12 +66,12 @@ export default function fileIOFdatasync() {
});
/**
* @tc.number SUB_DF_FILEIO_FDATASYNC_SYNC_0020
* @tc.number SUB_DF_FILEIO_FDATASYNC_SYNC_0200
* @tc.name fileIO_test_fdatasync_sync_002
* @tc.desc Test fdatasyncSync() interfaces. Missing parameter.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_fdatasync_sync_002', 0, async function () {
......@@ -107,8 +106,8 @@ export default function fileIOFdatasync() {
console.log('fileIO_test_fdatasync_async_000 error package: ' + JSON.stringify(err));
expect(false).assertTrue();
}
fileio.closeSync(file.fd);
fileio.unlinkSync(fpath);
fileIO.closeSync(file);
fileIO.unlinkSync(fpath);
done();
});
} catch (e) {
......@@ -118,13 +117,13 @@ export default function fileIOFdatasync() {
});
/**
* @tc.number SUB_DF_FILEIO_FDATASYNC_ASYNC_0010
* @tc.number SUB_DF_FILEIO_FDATASYNC_ASYNC_0100
* @tc.name fileIO_test_fdatasync_async_001
* @tc.desc Test fdatasync() interfaces. Promise.then().catch().
* Open the file in read-write mode, and synchronize the file content data.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_fdatasync_async_001', 0, async function (done) {
......@@ -133,9 +132,9 @@ export default function fileIOFdatasync() {
try {
let file = fileIO.openSync(fpath, fileIO.OpenMode.READ_WRITE);
fileio.fdatasync(file.fd).then(() => {
fileio.closeSync(file.fd);
fileio.unlinkSync(fpath);
fileIO.fdatasync(file.fd).then(() => {
fileIO.closeSync(file);
fileIO.unlinkSync(fpath);
done();
}).catch((err) => {
console.log('fileIO_test_fdatasync_async_001 error package: ' + JSON.stringify(err));
......@@ -148,13 +147,13 @@ export default function fileIOFdatasync() {
});
/**
* @tc.number SUB_DF_FILEIO_FDATASYNC_ASYNC_0020
* @tc.number SUB_DF_FILEIO_FDATASYNC_ASYNC_0200
* @tc.name fileIO_test_fdatasync_async_002
* @tc.desc Test fdatasync() interfaces. await Promise.
* Open the file in read-write mode, and synchronize the file content data.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_fdatasync_async_002', 0, async function (done) {
......@@ -163,9 +162,9 @@ export default function fileIOFdatasync() {
try {
let file = fileIO.openSync(fpath, fileIO.OpenMode.READ_WRITE);
await fileio.fdatasync(file.fd);
fileio.closeSync(file.fd);
fileio.unlinkSync(fpath);
await fileIO.fdatasync(file.fd);
fileIO.closeSync(file);
fileIO.unlinkSync(fpath);
done();
} catch (e) {
console.log('fileIO_test_fdatasync_async_002 has failed for ' + e.message + ', code: ' + e.code);
......@@ -174,13 +173,13 @@ export default function fileIOFdatasync() {
});
/**
* @tc.number SUB_DF_FILEIO_FDATASYNC_ASYNC_0030
* @tc.number SUB_DF_FILEIO_FDATASYNC_ASYNC_0300
* @tc.name fileIO_test_fdatasync_async_003
* @tc.desc Test fdatasync() interfaces. await Promise.
* Invalid fd parameter.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_fdatasync_async_003', 0, async function (done) {
......@@ -196,13 +195,13 @@ export default function fileIOFdatasync() {
});
/**
* @tc.number SUB_DF_FILEIO_FDATASYNC_ASYNC_0040
* @tc.number SUB_DF_FILEIO_FDATASYNC_ASYNC_0400
* @tc.name fileIO_test_fdatasync_async_004
* @tc.desc Test fdatasync() interfaces. Callback.
* Invalid fd parameter.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_fdatasync_async_004', 0, async function (done) {
......@@ -210,7 +209,7 @@ export default function fileIOFdatasync() {
try {
fileIO.fdatasync(-1, (err) => {
if (err) {
console.log('fileIO_test_fdatasync_async_004 error package: {' + err.message + ', code: ' + err.code + '}');
console.log('fileIO_test_fdatasync_async_004 error: {message: ' + err.message + ', code: ' + err.code + '}');
expect(err.code == 13900008 && err.message == 'Bad file descriptor').assertTrue();
done();
}
......@@ -222,13 +221,13 @@ export default function fileIOFdatasync() {
});
/**
* @tc.number SUB_DF_FILEIO_FDATASYNC_ASYNC_0050
* @tc.number SUB_DF_FILEIO_FDATASYNC_ASYNC_0500
* @tc.name fileIO_test_fdatasync_async_005
* @tc.desc Test fdatasync() interfaces. Promise.then().catch()
* Invalid fd parameter.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_fdatasync_async_005', 0, async function (done) {
......@@ -237,7 +236,7 @@ export default function fileIOFdatasync() {
fileIO.fdatasync(-1).then(() => {
expect(false).assertTrue();
}).catch((err) => {
console.log('fileIO_test_fdatasync_async_005 error package: {' + err.message + ', code: ' + err.code + '}');
console.log('fileIO_test_fdatasync_async_005 error: {message: ' + err.message + ', code: ' + err.code + '}');
expect(err.code == 13900008 && err.message == 'Bad file descriptor').assertTrue();
done();
});
......@@ -248,13 +247,13 @@ export default function fileIOFdatasync() {
});
/**
* @tc.number SUB_DF_FILEIO_FDATASYNC_ASYNC_0060
* @tc.number SUB_DF_FILEIO_FDATASYNC_ASYNC_0600
* @tc.name fileIO_test_fdatasync_async_006
* @tc.desc Test fdatasync() interfaces. Promise.
* Missing parameter.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_fdatasync_async_006', 0, async function (done) {
......@@ -270,19 +269,19 @@ export default function fileIOFdatasync() {
});
/**
* @tc.number SUB_DF_FILEIO_FDATASYNC_ASYNC_0070
* @tc.number SUB_DF_FILEIO_FDATASYNC_ASYNC_0700
* @tc.name fileIO_test_fdatasync_async_007
* @tc.desc Test fdatasync() interfaces. Callback.
* Missing parameter.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_fdatasync_async_007', 0, async function (done) {
try {
fileIO.fdatasync(() => {
fileIO.fdatasync((err) => {
expect(false).assertTrue();
});
} catch (e) {
......
......@@ -14,8 +14,7 @@
*/
import {
fileio, fileIO, FILE_CONTENT, prepareFile, nextFileName,
describe, it, expect,
fileIO, FILE_CONTENT, prepareFile, nextFileName, describe, it, expect,
} from '../Common';
export default function fileIOFsync() {
......@@ -38,8 +37,8 @@ describe('fileIO_fs_fsync', function () {
try {
let file = fileIO.openSync(fpath, fileIO.OpenMode.READ_WRITE);
fileIO.fsyncSync(file.fd);
fileio.closeSync(file.fd);
fileio.unlinkSync(fpath);
fileIO.closeSync(file);
fileIO.unlinkSync(fpath);
} catch (e) {
console.log('fileIO_test_fsync_sync_000 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
......@@ -47,12 +46,12 @@ describe('fileIO_fs_fsync', function () {
});
/**
* @tc.number SUB_DF_FILEIO_FSYNC_SYNC_0010
* @tc.number SUB_DF_FILEIO_FSYNC_SYNC_0100
* @tc.name fileIO_test_fsync_sync_001
* @tc.desc Test fsyncSync() interface. Invalid fd parameter.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_fsync_sync_001', 0, function () {
......@@ -67,12 +66,12 @@ describe('fileIO_fs_fsync', function () {
});
/**
* @tc.number SUB_DF_FILEIO_FSYNC_SYNC_0020
* @tc.number SUB_DF_FILEIO_FSYNC_SYNC_0200
* @tc.name fileIO_test_fsync_sync_002
* @tc.desc Test fsyncSync() interface. Missing parameter.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_fsync_sync_002', 0, function () {
......@@ -103,8 +102,8 @@ describe('fileIO_fs_fsync', function () {
try {
let file = fileIO.openSync(fpath, fileIO.OpenMode.READ_WRITE);
await fileIO.fsync(file.fd);
fileio.closeSync(file.fd);
fileio.unlinkSync(fpath);
fileIO.closeSync(file);
fileIO.unlinkSync(fpath);
done();
} catch (e) {
console.log('fileIO_test_fsync_async_000 has failed for ' + e.message + ', code: ' + e.code);
......@@ -113,13 +112,13 @@ describe('fileIO_fs_fsync', function () {
});
/**
* @tc.number SUB_DF_FILEIO_FSYNC_ASYNC_0010
* @tc.number SUB_DF_FILEIO_FSYNC_ASYNC_0100
* @tc.name fileIO_test_fsync_async_001
* @tc.desc Test fsync() interface. Promise.then().catch()
* Open the file in read-write mode, and synchronize the file content data.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_fsync_async_001', 0, async function (done) {
......@@ -129,8 +128,8 @@ describe('fileIO_fs_fsync', function () {
try {
let file = fileIO.openSync(fpath, fileIO.OpenMode.READ_WRITE);
fileIO.fsync(file.fd).then(() => {
fileio.closeSync(file.fd);
fileio.unlinkSync(fpath);
fileIO.closeSync(file);
fileIO.unlinkSync(fpath);
done();
}).catch((err) => {
console.log('fileIO_test_fsync_async_001 error package: ' + JSON.stringify(err));
......@@ -143,13 +142,13 @@ describe('fileIO_fs_fsync', function () {
});
/**
* @tc.number SUB_DF_FILEIO_FSYNC_ASYNC_002
* @tc.number SUB_DF_FILEIO_FSYNC_ASYNC_0200
* @tc.name fileIO_test_fsync_async_002
* @tc.desc Test fsync() interface. Callback.
* Open the file in read-write mode, and synchronize the file content data.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_fsync_async_002', 0, async function (done) {
......@@ -163,8 +162,8 @@ describe('fileIO_fs_fsync', function () {
console.log('fileIO_test_fsync_async_002 error package: ' + JSON.stringify(err));
expect(false).assertTrue();
}
fileio.closeSync(file.fd);
fileio.unlinkSync(fpath);
fileIO.closeSync(file);
fileIO.unlinkSync(fpath);
});
done();
} catch (e) {
......@@ -174,13 +173,13 @@ describe('fileIO_fs_fsync', function () {
});
/**
* @tc.number SUB_DF_FILEIO_FSYNC_ASYNC_003
* @tc.number SUB_DF_FILEIO_FSYNC_ASYNC_0300
* @tc.name fileIO_test_fsync_async_003
* @tc.desc Test fsync() interface. await Promise.
* Invalid fd parameter.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_fsync_async_003', 0, async function (done) {
......@@ -196,13 +195,13 @@ describe('fileIO_fs_fsync', function () {
});
/**
* @tc.number SUB_DF_FILEIO_FSYNC_ASYNC_004
* @tc.number SUB_DF_FILEIO_FSYNC_ASYNC_0400
* @tc.name fileIO_test_fsync_async_004
* @tc.desc Test fsync() interface. Callback.
* Invalid fd parameter.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_fsync_async_004', 0, async function (done) {
......@@ -210,7 +209,7 @@ describe('fileIO_fs_fsync', function () {
try {
fileIO.fsync(-1, (err) => {
if (err) {
console.log('fileIO_test_fsync_async_004 error package: {' + err.message + ', code: ' + err.code + '}');
console.log('fileIO_test_fsync_async_004 error: {message: ' + err.message + ', code: ' + err.code + '}');
expect(err.code == 13900008 && err.message == 'Bad file descriptor').assertTrue();
done();
}
......@@ -222,13 +221,13 @@ describe('fileIO_fs_fsync', function () {
});
/**
* @tc.number SUB_DF_FILEIO_FSYNC_ASYNC_005
* @tc.number SUB_DF_FILEIO_FSYNC_ASYNC_0500
* @tc.name fileIO_test_fsync_async_005
* @tc.desc Test fsync() interface. Promise.then().catch()
* Missing parameter.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_fsync_async_005', 0, async function (done) {
......@@ -237,7 +236,7 @@ describe('fileIO_fs_fsync', function () {
fileIO.fsync(-1).then(() => {
expect(false).assertTrue();
}).catch((err) => {
console.log('fileIO_test_fsync_async_005 error package: {' + err.message + ', code: ' + err.code + '}');
console.log('fileIO_test_fsync_async_005 error: {message: ' + err.message + ', code: ' + err.code + '}');
expect(err.code == 13900008 && err.message == 'Bad file descriptor').assertTrue();
done();
});
......@@ -248,13 +247,13 @@ describe('fileIO_fs_fsync', function () {
});
/**
* @tc.number SUB_DF_FILEIO_FSYNC_ASYNC_006
* @tc.number SUB_DF_FILEIO_FSYNC_ASYNC_0600
* @tc.name fileIO_test_fsync_async_006
* @tc.desc Test fsync() interface. await Promise.
* Missing parameter.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_fsync_async_006', 0, async function (done) {
......@@ -270,19 +269,19 @@ describe('fileIO_fs_fsync', function () {
});
/**
* @tc.number SUB_DF_FILEIO_FSYNC_ASYNC_006
* @tc.name fileIO_test_fsync_async_006
* @tc.number SUB_DF_FILEIO_FSYNC_ASYNC_0700
* @tc.name fileIO_test_fsync_async_007
* @tc.desc Test fsync() interface. Callback.
* Missing parameter.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_fsync_async_007', 0, async function (done) {
try {
fileIO.fsync(() => {
fileIO.fsync((err) => {
expect(false).assertTrue();
});
} catch (e) {
......
/*
* 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 fileHash from '@ohos.file.hash';
import {
fileIO, FILE_CONTENT, prepareFile, nextFileName, describe, it, expect,
} from '../Common';
export default function fileIOHash() {
describe('fileIO_fs_hash', function () {
/**
* @tc.number SUB_DF_FILEIO_HASH_ASYNC_0000
* @tc.name fileIO_test_hash_async_000
* @tc.desc Test hash() interface. Promise.
* Encrypt files using the MD5 hashing algorithm
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('fileIO_test_hash_async_000', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_hash_async_000');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let str = await fileHash.hash(fpath,'md5');
console.log('fileIO_test_hash_async_000 hash value is ' + str);
expect(str == '5EB63BBBE01EEED093CB22BB8F5ACDC3').assertTrue();
fileIO.unlinkSync(fpath);
done();
} catch (e) {
console.log('fileIO_test_hash_async_000 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_HASH_ASYNC_0100
* @tc.name fileIO_test_hash_async_001
* @tc.desc Test hash() interface. Callback.
* Encrypt files using the MD5 hashing algorithm.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_hash_async_001', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_hash_async_001');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
fileHash.hash(fpath, 'md5', (err, str) => {
if (err) {
console.log('fileIO_test_hash_async_001 error package: ' + JSON.stringify(err));
expect(false).assertTrue();
}
console.log('fileIO_test_hash_async_001 hash value is ' + str);
expect(str == '5EB63BBBE01EEED093CB22BB8F5ACDC3').assertTrue();
fileIO.unlinkSync(fpath);
done();
});
} catch (e) {
console.log('fileIO_test_hash_async_001 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_HASH_ASYNC_0200
* @tc.name fileIO_test_hash_async_002
* @tc.desc Test hash() interface. Promise.
* Encrypt files using the sha1 hashing algorithm.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_hash_async_002', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_hash_async_002');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let str = await fileHash.hash(fpath, 'sha1');
console.log('fileIO_test_hash_async_000 hash value is ' + str);
expect(str == '2AAE6C35C94FCFB415DBE95F408B9CE91EE846ED').assertTrue();
fileIO.unlinkSync(fpath);
done();
} catch (e) {
console.log('fileIO_test_hash_async_002 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_HASH_ASYNC_0300
* @tc.name fileIO_test_hash_async_003
* @tc.desc Test hash() interface. Callback.
* Encrypt files using the sha1 hashing algorithm.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_hash_async_003', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_hash_async_003');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
fileHash.hash(fpath, 'sha1', (err, str) => {
if (err) {
console.log('fileIO_test_hash_async_003 error package: ' + JSON.stringify(err));
expect(false).assertTrue();
}
console.log('fileIO_test_hash_async_003 hash value is ' + str);
expect(str == '2AAE6C35C94FCFB415DBE95F408B9CE91EE846ED').assertTrue();
fileIO.unlinkSync(fpath);
done();
});
} catch (e) {
console.log('fileIO_test_hash_async_003 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_HASH_ASYNC_0400
* @tc.name fileIO_test_hash_async_004
* @tc.desc Test hash() interface. Promise.
* Encrypt files using the sha256 hashing algorithm.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_hash_async_004', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_hash_async_004');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let str = await fileHash.hash(fpath, 'sha256');
console.log('fileIO_test_hash_async_001 hash value is ' + str);
expect(str == 'B94D27B9934D3E08A52E52D7DA7DABFAC484EFE37A5380EE9088F7ACE2EFCDE9').assertTrue();
fileIO.unlinkSync(fpath);
done();
} catch (e) {
console.log('fileIO_test_hash_async_004 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_HASH_ASYNC_0500
* @tc.name fileIO_test_hash_async_005
* @tc.desc Test hash() interface. Callback.
* Encrypt files using the sha256 hashing algorithm.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_hash_async_005', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_hash_async_005');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
fileHash.hash(fpath, 'sha256', (err, str) => {
if (err) {
console.log('fileIO_test_hash_async_005 error package: ' + JSON.stringify(err));
expect(false).assertTrue();
}
console.log('fileIO_test_hash_async_005 hash value is ' + str);
expect(str == 'B94D27B9934D3E08A52E52D7DA7DABFAC484EFE37A5380EE9088F7ACE2EFCDE9').assertTrue();
fileIO.unlinkSync(fpath);
done();
});
} catch (e) {
console.log('fileIO_test_hash_async_005 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_HASH_ASYNC_0600
* @tc.name fileIO_test_hash_async_006
* @tc.desc Test hash() interface. Promise.
* Invalid mode.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_hash_async_006', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_hash_async_006');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
await fileHash.hash(fpath, '256');
expect(false).assertTrue();
} catch (e) {
fileIO.unlinkSync(fpath);
console.log('fileIO_test_hash_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_HASH_ASYNC_0700
* @tc.name fileIO_test_hash_async_007
* @tc.desc Test hash() interface. Promise.
* Missing parameter.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_hash_async_007', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_hash_async_007');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
fileHash.hash(fpath, (err) => {
expect(false).assertTrue();
});
} catch (e) {
fileIO.unlinkSync(fpath);
console.log('fileIO_test_hash_async_007 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, 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,
} from '../Common';
export default function fileIOSymlink() {
describe('fileIO_fs_symlink', function () {
/**
* @tc.number SUB_DF_FILEIO_SYMLINK_SYNC_0000
* @tc.name fileIO_test_symlink_sync_000
* @tc.desc Test symlinkSync() interfaces.
* Create a symbolic link to verify normal function.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it('fileIO_test_symlink_sync_000', 0, async function () {
let fpath = await nextFileName('fileIO_test_symlink_sync_000');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
fileIO.symlinkSync(fpath, fpath + 'link0');
expect(fileIO.accessSync(fpath + 'link0')).assertTrue();
fileIO.unlinkSync(fpath);
fileIO.unlinkSync(fpath + 'link0');
} catch (e) {
console.log('fileIO_test_symlink_sync_000 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_SYMLINK_SYNC_0100
* @tc.name fileIO_test_symlink_sync_001
* @tc.desc Test symlinkSync() interfaces.
* Missing parameter.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_symlink_sync_001', 0, async function () {
let fpath = await nextFileName('fileIO_test_symlink_sync_001');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
fileIO.symlinkSync(fpath);
expect(false).assertTrue();
} catch (e) {
fileIO.unlinkSync(fpath);
console.log('fileIO_test_symlink_sync_001 has failed for ' + e.message + ', code: ' + e.code);
expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_SYMLINK_ASYNC_0000
* @tc.name fileIO_test_symlink_async_000
* @tc.desc Test SymlinkAsync interfaces. Promise.then().catch()
* Create a symbolic link to verify normal function.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it('fileIO_test_symlink_async_000', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_symlink_async_000');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
fileIO.symlink(fpath, fpath + 'link1').then(() => {
expect(fileIO.accessSync(fpath + 'link1')).assertTrue();
fileIO.unlinkSync(fpath);
fileIO.unlinkSync(fpath + 'link1');
}).catch((err) => {
console.log('fileIO_test_symlink_async_000 error package: ' + JSON.stringify(err));
expect(false).assertTrue();
})
done();
} catch (e) {
console.log('fileIO_test_symlink_async_000 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_SYMLINK_ASYNC_0100
* @tc.name fileIO_test_symlink_async_001
* @tc.desc Test SymlinkAsync interfaces. await Promise.
* Create a symbolic link to verify normal function.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_symlink_async_001', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_symlink_async_001');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
await fileIO.symlink(fpath, fpath + 'link2');
expect(fileIO.accessSync(fpath + 'link2')).assertTrue();
fileIO.unlinkSync(fpath);
fileIO.unlinkSync(fpath + 'link2');
done();
} catch (e) {
console.log('fileIO_test_symlink_async_001 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_SYMLINK_ASYNC_0200
* @tc.name fileIO_test_symlink_async_002
* @tc.desc Test SymlinkAsync interfaces. Promise.
* Create a symbolic link to verify normal function.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_symlink_async_002', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_symlink_async_002');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
fileIO.symlink(fpath, fpath + 'link3', (err) => {
if (err) {
console.log('fileIO_test_symlink_async_002 error package: ' + JSON.stringify(err));
expect(false).assertTrue();
}
expect(fileIO.accessSync(fpath + 'link3')).assertTrue();
fileIO.unlinkSync(fpath);
fileIO.unlinkSync(fpath + 'link3');
done();
});
} catch (e) {
console.log('fileIO_test_symlink_async_002 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_SYMLINK_ASYNC_0300
* @tc.name fileIO_test_symlink_async_003
* @tc.desc Test SymlinkAsync interfaces. Promise.
* Missing parameter.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_symlink_async_003', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_symlink_async_003');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
await fileIO.symlink(fpath);
expect(false).assertTrue();
} catch (e) {
fileIO.unlinkSync(fpath);
console.log('fileIO_test_symlink_async_003 has failed for ' + e.message + ', code: ' + e.code);
expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue();
done();
}
});
});
}
......@@ -14,8 +14,7 @@
*/
import {
fileio, fileIO, FILE_CONTENT, prepareFile, nextFileName, isIntNum,
describe, it, expect,
fileIO, FILE_CONTENT, prepareFile, nextFileName, isIntNum, describe, it, expect,
} from '../Common';
export default function fileIOTruncate() {
......@@ -40,13 +39,13 @@ import {
await fileIO.truncate(fpath, truncateLen);
let file = fileIO.openSync(fpath, fileIO.OpenMode.READ_WRITE);
expect(isIntNum(file.fd)).assertTrue();
let len = fileIO.readSync(file.fd, new ArrayBuffer(4096));
expect(len == truncateLen).assertTrue();
fileio.closeSync(file.fd);
fileio.unlinkSync(fpath);
let readLen = fileIO.readSync(file.fd, new ArrayBuffer(4096));
expect(readLen == truncateLen).assertTrue();
fileIO.closeSync(file);
fileIO.unlinkSync(fpath);
done();
} catch (e) {
console.info('fileIO_truncate_async_000 has failed for ' + e.message + ', code: ' + e.code);
console.log('fileIO_truncate_async_000 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
......@@ -58,7 +57,7 @@ import {
* Truncate the file with fd and truncateLen = 5.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.level Level 3
* @tc.require
*/
it('fileIO_truncate_async_001', 0, async function (done) {
......@@ -74,12 +73,12 @@ import {
console.log('fileIO_truncate_async_001 error package: ' + JSON.stringify(err));
expect(false).assertTrue();
}
let len = fileIO.readSync(file.fd, new ArrayBuffer(4096));
expect(len == truncateLen).assertTrue();
fileio.closeSync(file.fd);
fileio.unlinkSync(fpath);
let readLen = fileIO.readSync(file.fd, new ArrayBuffer(4096));
expect(readLen == truncateLen).assertTrue();
fileIO.closeSync(file);
fileIO.unlinkSync(fpath);
done();
})
});
} catch (e) {
console.log('fileIO_truncate_async_001 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
......@@ -93,7 +92,7 @@ import {
* Truncate the file with path and truncateLen = 2.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.level Level 3
* @tc.require
*/
it('fileIO_truncate_async_002', 0, async function (done) {
......@@ -105,10 +104,10 @@ import {
fileIO.truncate(fpath, truncateLen).then(() => {
let file = fileIO.openSync(fpath, fileIO.OpenMode.READ_WRITE);
expect(isIntNum(file.fd)).assertTrue();
let len = fileIO.readSync(file.fd, new ArrayBuffer(4096));
expect(len == truncateLen).assertTrue();
fileio.closeSync(file.fd);
fileio.unlinkSync(fpath);
let readLen = fileIO.readSync(file.fd, new ArrayBuffer(4096));
expect(readLen == truncateLen).assertTrue();
fileIO.closeSync(file);
fileIO.unlinkSync(fpath);
done();
}).catch((err) => {
console.log('fileIO_truncate_async_002 error package: ' + JSON.stringify(err));
......@@ -127,7 +126,7 @@ import {
* Truncate the file with fd and truncateLen = 2.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.level Level 3
* @tc.require
*/
it('fileIO_truncate_async_003', 0, async function (done) {
......@@ -139,15 +138,15 @@ import {
try {
expect(isIntNum(file.fd)).assertTrue();
fileIO.truncate(file.fd, truncateLen).then(() => {
let len = fileIO.readSync(file.fd, new ArrayBuffer(4096));
expect(len == truncateLen).assertTrue();
fileio.closeSync(file.fd);
fileio.unlinkSync(fpath);
let readLen = fileIO.readSync(file.fd, new ArrayBuffer(4096));
expect(readLen == truncateLen).assertTrue();
fileIO.closeSync(file);
fileIO.unlinkSync(fpath);
done();
}).catch((err) => {
console.log('fileIO_truncate_async_003 error package: ' + JSON.stringify(err));
expect(false).assertTrue();
})
});
} catch(e) {
console.log('fileIO_truncate_async_003 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
......@@ -158,10 +157,10 @@ import {
* @tc.number SUB_DF_FILEIO_TRUNCATE_ASYNC_0400
* @tc.name fileIO_truncate_async_004
* @tc.desc Test the truncate() interface. Callback.
* Truncate the file with path and truncateLen = 2.
* The path point to nothing, no such file.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.level Level 3
* @tc.require
*/
it('fileIO_truncate_async_004', 0, async function (done) {
......@@ -171,7 +170,7 @@ import {
try {
fileIO.truncate(fpath, truncateLen, (err) => {
if (err) {
console.log('fileIO_truncate_async_004 error package: {' + err.message + ', code: ' + err.code + '}');
console.log('fileIO_truncate_async_004 error: {message: ' + err.message + ', code: ' + err.code + '}');
expect(err.code == 13900002 && err.message == 'No such file or directory').assertTrue();
done();
}
......@@ -186,10 +185,10 @@ import {
* @tc.number SUB_DF_FILEIO_TRUNCATE_ASYNC_0500
* @tc.name fileIO_truncate_async_005
* @tc.desc Test the truncate() interface. Promise.
* Truncate the file with path and truncateLen = 2.
* The path point to nothing, no such file.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.level Level 3
* @tc.require
*/
it('fileIO_truncate_async_005', 0, async function (done) {
......@@ -206,6 +205,74 @@ import {
}
});
/**
* @tc.number SUB_DF_FILEIO_TRUNCATE_ASYNC_0600
* @tc.name fileIO_truncate_async_006
* @tc.desc Test the truncate() interface. Callback.
* Truncate the file with fd and truncateLen = 0.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 3
* @tc.require
*/
it('fileIO_truncate_async_006', 0, async function (done) {
let fpath = await nextFileName('fileIO_truncate_async_006');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
let file = fileIO.openSync(fpath, fileIO.OpenMode.READ_WRITE);
try {
expect(isIntNum(file.fd)).assertTrue();
fileIO.truncate(file.fd, (err) => {
if(err) {
console.log('fileIO_truncate_async_006 error package: ' + JSON.stringify(err));
expect(false).assertTrue();
}
let readLen = fileIO.readSync(file.fd, new ArrayBuffer(4096));
expect(readLen == 0).assertTrue();
fileIO.closeSync(file);
fileIO.unlinkSync(fpath);
done();
});
} catch (e) {
console.log('fileIO_truncate_async_006 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_TRUNCATE_ASYNC_0700
* @tc.name fileIO_truncate_async_007
* @tc.desc Test the truncate() interface. Callback.
* Truncate the file with fd and truncateLen = 0.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 3
* @tc.require
*/
it('fileIO_truncate_async_007', 0, async function (done) {
let fpath = await nextFileName('fileIO_truncate_async_007');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
fileIO.truncate(fpath, (err) => {
if(err) {
console.log('fileIO_truncate_async_007 error package: ' + JSON.stringify(err));
expect(false).assertTrue();
}
let file = fileIO.openSync(fpath, fileIO.OpenMode.READ_WRITE);
expect(isIntNum(file.fd)).assertTrue();
let readLen = fileIO.readSync(file.fd, new ArrayBuffer(4096));
expect(readLen == 0).assertTrue();
fileIO.closeSync(file);
fileIO.unlinkSync(fpath);
done();
});
} catch (e) {
console.log('fileIO_truncate_async_008 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_TRUNCATE_SYNC_0000
* @tc.name fileIO_test_truncate_sync_000
......@@ -213,7 +280,7 @@ import {
* Truncate the file with path.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_truncate_sync_000', 0, async function () {
......@@ -223,7 +290,7 @@ import {
try {
fileIO.truncateSync(fpath);
expect(fileIO.statSync(fpath).size == 0).assertTrue();
fileio.unlinkSync(fpath);
fileIO.unlinkSync(fpath);
} catch (e) {
console.log('fileIO_test_truncate_sync_000 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
......@@ -237,7 +304,7 @@ import {
* Truncate the file with fd and truncateLen = 5.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_truncate_sync_001', 0, async function () {
......@@ -249,10 +316,10 @@ import {
try {
expect(isIntNum(file.fd)).assertTrue();
fileIO.truncateSync(file.fd, truncateLen);
let len = fileIO.readSync(file.fd, new ArrayBuffer(4096));
expect(len == truncateLen).assertTrue();
fileio.closeSync(file.fd);
fileio.unlinkSync(fpath);
let readLen = fileIO.readSync(file.fd, new ArrayBuffer(4096));
expect(readLen == truncateLen).assertTrue();
fileIO.closeSync(file);
fileIO.unlinkSync(fpath);
} catch (e) {
console.log('fileIO_test_truncate_sync_001 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
......@@ -266,7 +333,7 @@ import {
* The path point to nothing, no such file.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_truncate_sync_002', 0, async function () {
......@@ -287,7 +354,7 @@ import {
* @tc.desc Test the truncateSync() interface. Invalid parameter.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_truncate_sync_003', 0, async function () {
......@@ -308,7 +375,7 @@ import {
* @tc.desc Test truncateSync() interfaces. Missing parameters.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_truncate_sync_004', 0, function () {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册