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

!7400 【回合monthly】Add XTS for close, mkdir, rmdir, unlink, creatStream,...

!7400 【回合monthly】Add XTS for close, mkdir, rmdir, unlink, creatStream, fdopenStream, class_stream interface of mod_fs.
Merge pull request !7400 from zhuhongtao666/cherry-pick-1675408196
/*
* 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,21 +13,61 @@
* limitations under the License.
*/
import fileIOAccess from './members/access.test.js'
import fileIOClose from './members/close.test.js'
import fileIOCopyfile from './members/copyFile.test.js'
import fileIOCreateStream from './members/createStream.test.js'
import fileIOFdatasync from './members/fdatasync.test.js'
import fileIOFdOpenStream from './members/fdopenStream.test.js'
import fileIOFileLock from './members/fileLock.test.js'
import fileIOFsync from './members/fsync.test.js'
import fileIOHash from './members/hash.test.js'
import fileIOListfile from './members/listFile.test.js'
import fileIOLstat from './members/lstat.test.js'
import fileIOMkdir from './members/mkdir.test.js'
import fileIOMkdtemp from './members/mkdtemp.test.js'
import fileIOMoveFile from './members/moveFile.test.js'
import fileIOOpen from './members/open.test.js'
import fileIORead from './members/read.test.js'
import fileIOReadtext from './members/readtext.test.js'
import fileIORename from './members/rename.test.js'
import fileIORmdir from './members/rmdir.test'
import fileIOStat from './members/stat.test.js'
import fileIOStreamClose from './class_stream/close.test.js'
import fileIOStreamFlush from './class_stream/flush.test.js'
import fileIOStreamRead from './class_stream/read.test.js'
import fileIOStreamWrite from './class_stream/write.test.js'
import fileIOSymlink from './members/symlink.test.js'
import fileIOTruncate from './members/truncate.test.js'
import fileIOUnlink from './members/unlink.test.js'
import fileIOWrite from './members/write.test.js'
export default function testsuite() {
fileIOAccess()
fileIOClose()
fileIOCopyfile()
fileIOCreateStream()
fileIOFdatasync()
fileIOFdOpenStream()
fileIOFileLock()
fileIOFsync()
fileIOHash()
fileIOListfile()
fileIOLstat()
fileIOMkdir()
fileIOMkdtemp()
fileIOMoveFile()
fileIOOpen()
fileIORead()
fileIOReadtext()
fileIORename()
fileIORmdir()
fileIOStat()
fileIOStreamClose()
fileIOStreamFlush()
fileIOStreamRead()
fileIOStreamWrite()
fileIOSymlink()
fileIOTruncate()
fileIOUnlink()
fileIOWrite()
}
/*
* 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 fileIOStreamClose() {
describe('fileIO_fs_stream_close', function () {
/**
* @tc.number SUB_DF_FILEIO_STREAM_CLOSE_SYNC_0000
* @tc.name fileIO_test_stream_close_sync_000
* @tc.desc Test the closeSync() interface of class Stream.
* Open a file stream, close file stream.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('fileIO_test_stream_close_sync_000', 0, async function () {
let fpath = await nextFileName('fileIO_test_stream_close_sync_000');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let sr = fileIO.createStreamSync(fpath, 'r');
expect(sr !== null).assertTrue();
sr.closeSync();
fileIO.unlinkSync(fpath);
} catch (e) {
console.log('fileIO_test_stream_close_sync_000 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
})
/**
* @tc.number SUB_DF_FILEIO_STREAM_CLOSE_SYNC_0100
* @tc.name fileIO_test_stream_close_sync_001
* @tc.desc Test the closeSync() interface of class Stream.
* Invalid parameter, don't requrie any parameters.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_stream_close_sync_001', 0, async function () {
let fpath = await nextFileName('fileIO_test_stream_close_sync_001');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
let sr = fileIO.createStreamSync(fpath, 'r');
try {
expect(sr !== null).assertTrue();
sr.closeSync(1);
expect(false).assertTrue();
} catch (e) {
sr.closeSync();
fileIO.unlinkSync(fpath);
console.log('fileIO_test_stream_close_sync_001 has failed for ' + e.message + ', code: ' + e.code);
expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue();
}
})
/**
* @tc.number SUB_DF_FILEIO_STREAM_CLOSE_SYNC_0200
* @tc.name fileIO_test_stream_close_sync_002
* @tc.desc Test the closeSync() interface of class Stream.
* The file stream has been closed.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_stream_close_sync_002', 0, async function () {
let fpath = await nextFileName('fileIO_test_stream_close_sync_002');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
let sr = fileIO.createStreamSync(fpath, 'r');
try {
expect(sr !== null).assertTrue();
sr.closeSync();
sr.closeSync();
expect(false).assertTrue();
} catch (e) {
fileIO.unlinkSync(fpath);
console.log('fileIO_test_stream_close_sync_002 has failed for ' + e.message + ', code: ' + e.code);
expect(e.code == 13900005 && e.message == 'I/O error').assertTrue();
}
})
/**
* @tc.number SUB_DF_FILEIO_STREAM_CLOSE_ASYNC_0000
* @tc.name fileIO_test_stream_close_async_000
* @tc.desc Test the close() interface of class Stream. Promise.
* Open a file stream, close file stream.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 1
* @tc.require
*/
it('fileIO_test_stream_close_async_000', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_stream_close_async_000');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let sr = fileIO.createStreamSync(fpath, 'r');
expect(sr !== null).assertTrue();
await sr.close();
fileIO.unlinkSync(fpath);
done();
} catch (e) {
console.log('fileIO_test_stream_close_async_000 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_CLOSE_ASYNC_0100
* @tc.name fileIO_test_stream_close_async_001
* @tc.desc Test the close() interface of class Stream. Callback.
* Open a file stream, close file stream.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 1
* @tc.require
*/
it('fileIO_test_stream_close_async_001', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_stream_close_async_001');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let sr = fileIO.createStreamSync(fpath, 'r');
expect(sr !== null).assertTrue();
sr.close((err) => {
if (err) {
console.log('fileIO_test_stream_close_async_001 error package: ' + JSON.stringify(err));
expect(false).assertTrue();
}
fileIO.unlinkSync(fpath);
})
done();
} catch (e) {
console.log('fileIO_test_stream_close_async_001 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_CLOSE_ASYNC_0200
* @tc.name fileIO_test_stream_close_async_002
* @tc.desc Test the close() interface of class Stream. Promise.
* The file stream has been closed.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_stream_close_async_002', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_stream_close_async_002');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let sr = fileIO.createStreamSync(fpath, 'r');
expect(sr !== null).assertTrue();
await sr.close();
await sr.close();
expect(false).assertTrue();
} catch (e) {
fileIO.unlinkSync(fpath);
console.log('fileIO_test_stream_close_async_002 has failed for ' + e.message + ', code: ' + e.code);
expect(e.code == 13900005 && e.message == 'I/O error').assertTrue();
done();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_CLOSE_ASYNC_0300
* @tc.name fileIO_test_stream_close_async_003
* @tc.desc Test the close() interface of class Stream. Promise.
* Invalid parameter, don't requrie any parameters.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_stream_close_async_003', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_stream_close_async_003');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let sr = fileIO.createStreamSync(fpath, 'r');
expect(sr !== null).assertTrue();
await sr.close(1);
expect(false).assertTrue();
} catch (e) {
fileIO.unlinkSync(fpath);
console.log('fileIO_test_stream_close_async_003 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 fileIOStreamFlush() {
describe('fileIO_fs_stream_flush', function () {
/**
* @tc.number SUB_DF_FILEIO_STREAM_FLUSH_SYNC_0000
* @tc.name fileIO_test_stream_flush_sync_000
* @tc.desc Test the flushSync() interface of class Stream.
* Refresh file stream.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('fileIO_test_stream_flush_sync_000', 0, async function () {
let fpath = await nextFileName('fileIO_test_stream_flush_sync_000');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let sr = fileIO.createStreamSync(fpath, 'r+');
expect(sr !== null).assertTrue();
expect(sr.writeSync(FILE_CONTENT) == FILE_CONTENT.length).assertTrue();
sr.flushSync();
sr.closeSync();
fileIO.unlinkSync(fpath);
} catch (e) {
console.log('fileIO_test_stream_flush_sync_000 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_FLUSH_SYNC_0100
* @tc.name fileIO_test_stream_flush_sync_001
* @tc.desc Test the flushSync() interface of class Stream.
* Invalid parameter, don't requrie any parameters.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_stream_flush_sync_001', 0, async function () {
let fpath = await nextFileName('fileIO_test_stream_flush_sync_001');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
let sr = fileIO.createStreamSync(fpath, 'r+');
try {
expect(sr !== null).assertTrue();
sr.flushSync(1);
expect(false).assertTrue();
} catch (e) {
sr.closeSync();
fileIO.unlinkSync(fpath);
console.log('fileIO_test_stream_flush_sync_001 has failed for ' + e.message + ', code: ' + e.code);
expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_FLUSH_ASYNC_0000
* @tc.name fileIO_test_stream_flush_async_000
* @tc.desc Test the flush() interface of class Stream. Promise.then().catch()
* Refresh the file stream.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_stream_flush_async_000', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_stream_flush_async_000');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let sr = await fileIO.createStreamSync(fpath, 'r+');
expect(sr !== null).assertTrue();
expect(sr.writeSync(FILE_CONTENT) == FILE_CONTENT.length).assertTrue();
sr.flush().then(() => {
sr.closeSync();
fileIO.unlinkSync(fpath);
done();
}).catch((err) => {
console.log('fileIO_test_stream_flush_async_000 error package' + JSON.stringify(err));
expect(false).assertTrue();
});
} catch (e) {
console.log('fileIO_test_stream_flush_async_000 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_FLUSH_ASYNC_0100
* @tc.name fileIO_test_stream_flush_async_001
* @tc.desc Test the flush() interface of class Stream. Callback.
* Refresh the file stream.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 1
* @tc.require
*/
it('fileIO_test_stream_flush_async_001', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_stream_flush_async_001');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let sr = await fileIO.createStreamSync(fpath, 'r+');
expect(sr !== null).assertTrue();
expect(sr.writeSync(FILE_CONTENT) == FILE_CONTENT.length).assertTrue();
sr.flush((err) => {
if (err) {
console.log('fileIO_test_stream_flush_async_001 error package' + JSON.stringify(err));
expect(false).assertTrue();
}
sr.closeSync();
fileIO.unlinkSync(fpath);
done();
})
} catch (e) {
console.log('fileIO_test_stream_flush_async_001 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_FLUSH_ASYNC_0100
* @tc.name fileIO_test_stream_flush_async_001
* @tc.desc Test the flush() interface of class Stream. Promise.
* Refresh the file stream.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_stream_flush_sync_001', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_stream_flush_sync_001');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
let sr = fileIO.createStreamSync(fpath, 'r+');
try {
expect(sr !== null).assertTrue();
await sr.flush(1);
expect(false).assertTrue();
} catch (e) {
sr.closeSync();
fileIO.unlinkSync(fpath);
console.log('fileIO_test_stream_flush_sync_001 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, nextFileName, prepareFile, describe, it, expect,
} from '../Common';
export default function fileIOClose() {
describe('fileIO_fs_close', function () {
/**
* @tc.number SUB_DF_FILEIO_CLOSE_SYNC_0000
* @tc.name fileIO_test_close_sync_000
* @tc.desc Test closeSync() interfaces.
* Open file and close file by fd.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('fileIO_test_close_sync_000', 0, async function () {
let fpath = await nextFileName('fileIO_test_close_sync_000');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let file = fileIO.openSync(fpath, fileIO.OpenMode.READ_WRITE);
fileIO.closeSync(file.fd);
fileIO.unlinkSync(fpath);
} catch (e) {
console.log('fileIO_test_close_sync_000 has failed for ' + e.message + ', code: ' + e.code);
}
});
/**
* @tc.number SUB_DF_FILEIO_CLOSE_SYNC_0100
* @tc.name fileIO_test_close_sync_001
* @tc.desc Test closeSync() interfaces.
* Open file and close file by file object.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('fileIO_test_close_sync_001', 0, async function () {
let fpath = await nextFileName('fileIO_test_close_sync_001');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let file = fileIO.openSync(fpath, fileIO.OpenMode.READ_WRITE);
fileIO.closeSync(file);
fileIO.unlinkSync(fpath);
} catch (e) {
console.log('fileIO_test_close_sync_001 has failed for ' + e.message + ', code: ' + e.code);
}
});
/**
* @tc.number SUB_DF_FILEIO_CLOSE_SYNC_0200
* @tc.name fileIO_test_close_sync_002
* @tc.desc Test closeSync() interfaces.
* Test fd has been closed.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_close_sync_002', 0, async function () {
let fpath = await nextFileName('fileIO_test_close_sync_002');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let file = fileIO.openSync(fpath, fileIO.OpenMode.READ_WRITE);
fileIO.closeSync(file.fd);
fileIO.closeSync(file.fd);
expect(false).assertTrue();
} catch (e) {
fileIO.unlinkSync(fpath);
console.log('fileIO_test_close_sync_002 has failed for ' + e.message + ', code: ' + e.code);
expect(e.code == 13900008 && e.message == 'Bad file descriptor').assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_CLOSE_SYNC_0300
* @tc.name fileIO_test_close_sync_003
* @tc.desc Test closeSync() interfaces.
* Test file has been closed.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_close_sync_003', 0, async function () {
let fpath = await nextFileName('fileIO_test_close_sync_003');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let file = fileIO.openSync(fpath, fileIO.OpenMode.READ_WRITE);
fileIO.closeSync(file);
fileIO.closeSync(file);
expect(false).assertTrue();
} catch (e) {
fileIO.unlinkSync(fpath);
console.log('fileIO_test_close_sync_003 has failed for ' + e.message + ', code: ' + e.code);
expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_CLOSE_SYNC_0400
* @tc.name fileIO_test_close_sync_004
* @tc.desc Test closeSync() interfaces.
* No parameters.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_close_sync_004', 0, function () {
try {
fileIO.closeSync();
expect(false).assertTrue();
} catch (e) {
console.log('fileIO_test_close_sync_004 has failed for ' + e.message + ', code: ' + e.code);
expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_CLOSE_SYNC_0500
* @tc.name fileIO_test_close_sync_005
* @tc.desc Test closeSync() interfaces.
* Illegal type of parameter.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_close_sync_005', 0, function () {
try {
fileIO.closeSync(-1);
expect(false).assertTrue();
} catch (e) {
console.log('fileIO_test_close_sync_005 has failed for ' + e.message + ', code: ' + e.code);
expect(e.code == 13900008 && e.message == 'Bad file descriptor').assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_CLOSE_ASYNC_0000
* @tc.name fileIO_test_close_async_000
* @tc.desc Test close() interfaces. Callback.
* Open file and close file by fd.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_close_async_000', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_close_async_000');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let file = fileIO.openSync(fpath, fileIO.OpenMode.READ_WRITE);
fileIO.close(file.fd, (err) => {
if(err) {
console.log('fileIO_test_close_async_000 error package: ' + JSON.stringify(err));
expect(false).assertTrue();
}
fileIO.unlinkSync(fpath);
done();
});
} catch (e) {
console.log('fileIO_test_close_async_000 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_CLOSE_ASYNC_0100
* @tc.name fileIO_test_close_async_001
* @tc.desc Test close() interfaces. Callback.
* Open file and close file by file object.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_close_async_001', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_close_async_001');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let file = fileIO.openSync(fpath, fileIO.OpenMode.READ_WRITE);
fileIO.close(file, (err) => {
if(err) {
console.log('fileIO_test_close_async_001 error package: ' + JSON.stringify(err));
expect(false).assertTrue();
}
fileIO.unlinkSync(fpath);
done();
});
} catch (e) {
console.log('fileIO_test_close_async_001 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_CLOSE_ASYNC_0200
* @tc.name fileIO_test_close_async_002
* @tc.desc Test close() interfaces. Promise.
* Open file and close file by fd.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_close_async_002', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_close_async_002');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let file = fileIO.openSync(fpath, fileIO.OpenMode.READ_WRITE);
await fileIO.close(file.fd);
fileIO.unlinkSync(fpath);
done();
} catch (e) {
console.log('fileIO_test_close_async_002 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_CLOSE_ASYNC_0300
* @tc.name fileIO_test_close_async_003
* @tc.desc Test close() interfaces. Promise.
* Open file and close file by file object.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_close_async_003', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_close_async_003');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let file = fileIO.openSync(fpath, fileIO.OpenMode.READ_WRITE);
await fileIO.close(file);
fileIO.unlinkSync(fpath);
done();
} catch (e) {
console.log('fileIO_test_close_async_003 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_CLOSE_ASYNC_0400
* @tc.name fileIO_test_close_async_004
* @tc.desc Test close() interfaces. Promise.
* Test file has been closed.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_close_async_004', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_close_async_004');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let file = fileIO.openSync(fpath, fileIO.OpenMode.READ_WRITE);
await fileIO.close(file.fd);
await fileIO.close(file.fd);
expect(false).assertTrue();
} catch (e) {
fileIO.unlinkSync(fpath);
console.log('fileIO_test_close_async_004 has failed for ' + e.message + ', code: ' + e.code);
expect(e.code == 13900008 && e.message == 'Bad file descriptor').assertTrue();
done();
}
});
/**
* @tc.number SUB_DF_FILEIO_CLOSE_ASYNC_0500
* @tc.name fileIO_test_close_async_005
* @tc.desc Test close() interfaces. Promise.
* Test file has been closed.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_close_async_005', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_close_async_005');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let file = fileIO.openSync(fpath, fileIO.OpenMode.READ_WRITE);
await fileIO.close(file);
await fileIO.close(file);
expect(false).assertTrue();
} catch (e) {
fileIO.unlinkSync(fpath);
console.log('fileIO_test_close_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_CLOSE_ASYNC_0600
* @tc.name fileIO_test_close_async_006
* @tc.desc Test close() interfaces. Promise.
* There are multiple parameters.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_close_async_006', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_close_async_006');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let file = fileIO.openSync(fpath, fileIO.OpenMode.READ_WRITE);
await fileIO.close(file.fd, 2);
expect(false).assertTrue();
} catch (e) {
fileIO.unlinkSync(fpath);
console.log('fileIO_test_close_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_CLOSE_ASYNC_0700
* @tc.name fileIO_test_close_async_007
* @tc.desc Test close() interfaces.
* Illegal type of parameter. Promise.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_close_async_007', 0, async function (done) {
try {
await fileIO.close(-1);
expect(false).assertTrue();
} catch (e) {
console.log('fileIO_test_close_async_007 has failed for ' + e.message + ', code: ' + e.code);
expect(e.code == 13900008 && e.message == 'Bad file descriptor').assertTrue();
done();
}
});
/**
* @tc.number SUB_DF_FILEIO_CLOSE_ASYNC_0800
* @tc.name fileIO_test_close_async_008
* @tc.desc Test close() interfaces. Promise.
* No parameters.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_close_async_008', 0, async function (done) {
try {
await fileIO.close();
expect(false).assertTrue();
} catch (e) {
console.log('fileIO_test_close_async_008 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, prepareFile, FILE_CONTENT,
} from '../Common';
export default function fileIOMkdir() {
describe('fileIO_fs_mkdir', function () {
/**
* @tc.number SUB_DF_FILEIO_MKDIR_SYNC_0000
* @tc.name fileIO_test_mkdir_sync_000
* @tc.desc Test mkdirSync() interfaces.
* Create a directory, verify normal function.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('fileIO_test_mkdir_sync_000', 0, async function () {
let dpath = await nextFileName('fileIO_test_mkdir_sync_000') + 'd';
try {
fileIO.mkdirSync(dpath);
expect(fileIO.accessSync(dpath)).assertTrue();
fileIO.rmdirSync(dpath);
} catch (e) {
console.log('fileIO_test_mkdir_sync_000 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_MKDIR_SYNC_0100
* @tc.name fileIO_test_mkdir_sync_001
* @tc.desc Test mkdirSync() interfaces.
* The directory has been existed.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_mkdir_sync_001', 0, async function () {
try {
fileIO.mkdirSync('/');
expect(false).assertTrue();
} catch (e) {
console.log('fileIO_test_mkdir_sync_001 has failed for ' + e.message + ', code: ' + e.code);
expect(e.code == 13900015 && e.message == 'File exists').assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_MKDIR_SYNC_0200
* @tc.name fileIO_test_mkdir_sync_002
* @tc.desc Test mkdirSync() interfaces.
* The path is empty.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_mkdir_sync_002', 0, async function () {
try {
fileIO.mkdirSync('');
expect(false).assertTrue();
} catch (e) {
console.log('fileIO_test_mkdir_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_MKDIR_SYNC_0300
* @tc.name fileIO_test_mkdir_sync_003
* @tc.desc Test mkdirSync() interfaces.
* The path has pointed to a file.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_mkdir_sync_003', 0, async function () {
let fpath = await nextFileName('fileIO_test_mkdir_sync_003');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
fileIO.mkdirSync(fpath);
expect(false).assertTrue();
} catch (e) {
console.log('fileIO_test_mkdir_sync_003 has failed for ' + e.message + ', code: ' + e.code);
expect(e.code == 13900015 && e.message == 'File exists').assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_MKDIR_ASYNC_0000
* @tc.name fileIO_test_mkdir_async_000
* @tc.desc Test mkdir() interfaces. Promise.
* Create a directory, verify normal function.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_mkdir_async_000', 0, async function (done) {
let dpath = await nextFileName('fileIO_test_mkdir_async_000') + 'd';
try {
await fileIO.mkdir(dpath);
expect(fileIO.accessSync(dpath)).assertTrue();
fileIO.rmdirSync(dpath);
done();
} catch (e) {
console.log('fileIO_test_mkdir_async_000 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_MKDIR_ASYNC_0100
* @tc.name fileIO_test_mkdir_async_001
* @tc.desc Test mkdir() interfaces. Callback.
* Create a directory, verify normal function.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_mkdir_async_001', 0, async function (done) {
let dpath = await nextFileName('fileIO_test_mkdir_async_001') + 'd';
try {
fileIO.mkdir(dpath, (err) => {
if(err) {
console.log('fileIO_test_mkdir_async_001 error package: ' + JSON.stringify(err));
expect(false).assertTrue();
}
expect(fileIO.accessSync(dpath)).assertTrue();
fileIO.rmdirSync(dpath);
done();
});
} catch (e) {
console.log('fileIO_test_mkdir_async_001 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_MKDIR_ASYNC_0200
* @tc.name fileIO_test_mkdir_async_002
* @tc.desc Test mkdir() interfaces. Promise.
* Missing parameter.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_mkdir_async_002', 0, async function (done) {
try {
await fileIO.mkdir();
expect(false).assertTrue();
} catch (e) {
console.log('fileIO_test_mkdir_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_MKDIR_ASYNC_0300
* @tc.name fileIO_test_mkdir_async_003
* @tc.desc Test mkdir() interfaces. Callback.
* The directory has been existed.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_mkdir_async_003', 0, async function (done) {
try {
fileIO.mkdir('/', (err) => {
if(err) {
console.log('fileIO_test_mkdir_async_003 error: {message: ' + err.message + ', code: ' + err.code + '}');
expect(err.code == 13900015 && err.message == 'File exists').assertTrue();
done();
}
});
} catch (e) {
console.log('fileIO_test_mkdir_async_003 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_MKDIR_ASYNC_0400
* @tc.name fileIO_test_mkdir_async_004
* @tc.desc Test mkdir() interfaces. Promise.
* The path has pointed to a file.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_mkdir_async_004', 0, async function () {
let fpath = await nextFileName('fileIO_test_mkdir_async_004');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
await fileIO.mkdirSync(fpath);
expect(false).assertTrue();
} catch (e) {
console.log('fileIO_test_mkdir_async_004 has failed for ' + e.message + ', code: ' + e.code);
expect(e.code == 13900015 && e.message == 'File exists').assertTrue();
}
});
})
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册