未验证 提交 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
...@@ -13,21 +13,61 @@ ...@@ -13,21 +13,61 @@
* limitations under the License. * 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 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 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 fileIOMoveFile from './members/moveFile.test.js'
import fileIOOpen from './members/open.test.js' import fileIOOpen from './members/open.test.js'
import fileIORead from './members/read.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 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 fileIOTruncate from './members/truncate.test.js'
import fileIOUnlink from './members/unlink.test.js'
import fileIOWrite from './members/write.test.js' import fileIOWrite from './members/write.test.js'
export default function testsuite() { export default function testsuite() {
fileIOAccess()
fileIOClose()
fileIOCopyfile()
fileIOCreateStream()
fileIOFdatasync()
fileIOFdOpenStream()
fileIOFileLock() fileIOFileLock()
fileIOFsync()
fileIOHash()
fileIOListfile() fileIOListfile()
fileIOLstat()
fileIOMkdir()
fileIOMkdtemp()
fileIOMoveFile() fileIOMoveFile()
fileIOOpen() fileIOOpen()
fileIORead() fileIORead()
fileIOReadtext()
fileIORename()
fileIORmdir()
fileIOStat() fileIOStat()
fileIOStreamClose()
fileIOStreamFlush()
fileIOStreamRead()
fileIOStreamWrite()
fileIOSymlink()
fileIOTruncate() fileIOTruncate()
fileIOUnlink()
fileIOWrite() 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, prepareFile, nextFileName, describe, it, expect,
} from '../Common';
export default function fileIOStreamRead() {
describe('fileIO_fs_stream_read', function () {
/**
* @tc.number SUB_DF_FILEIO_STREAM_READ_SYNC_0000
* @tc.name fileIO_test_stream_read_sync_000
* @tc.desc Test the readSync() interface of class Stream.
* Create a file stream in r+ mode, reading data from this stream.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('fileIO_test_stream_read_sync_000', 0, async function () {
let fpath = await nextFileName('fileIO_test_stream_read_sync_000');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let sr = fileIO.createStreamSync(fpath, 'r+');
expect(sr !== null).assertTrue();
let readLen = sr.readSync(new ArrayBuffer(4096));
expect(readLen == FILE_CONTENT.length).assertTrue();
sr.closeSync();
fileIO.unlinkSync(fpath);
} catch (e) {
console.log('fileIO_test_stream_read_sync_000 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_READ_SYNC_0100
* @tc.name fileIO_test_stream_read_sync_001
* @tc.desc Test the readSync() interface of class Stream.
* Create a file stream in r+ mode, reading data with length = 2.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_stream_read_sync_001', 0, async function () {
let fpath = await nextFileName('fileIO_test_stream_read_sync_001');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let sr = fileIO.createStreamSync(fpath, 'r+');
expect(sr !== null).assertTrue();
let readLen = sr.readSync(new ArrayBuffer(4096), { length: 2 });
expect(readLen == 2).assertTrue();
sr.closeSync();
fileIO.unlinkSync(fpath);
} catch (e) {
console.log('fileIO_test_stream_read_sync_001 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_READ_SYNC_0200
* @tc.name fileIO_test_stream_read_sync_002
* @tc.desc Test the readSync() interface of class Stream.
* Create a file stream in r+ mode, reading data with offset = 2.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_stream_read_sync_002', 0, async function () {
let fpath = await nextFileName('fileIO_test_stream_read_sync_002');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let sr = fileIO.createStreamSync(fpath, 'r+');
expect(sr !== null).assertTrue();
let readLen = sr.readSync(new ArrayBuffer(4096), { offset: 2 });
expect(readLen == FILE_CONTENT.length - 2).assertTrue();
sr.closeSync();
fileIO.unlinkSync(fpath);
} catch (e) {
console.log('fileIO_test_stream_read_sync_002 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_READ_SYNC_0300
* @tc.name fileIO_test_stream_read_sync_003
* @tc.desc Test the readSync() interface of class Stream.
* Create a file stream in r+ mode, reading data with offset = 1 and length = 11.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_stream_read_sync_003', 0, async function () {
let fpath = await nextFileName('fileIO_test_stream_read_sync_003');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let sr = fileIO.createStreamSync(fpath, 'r+');
expect(sr !== null).assertTrue();
let readLen = sr.readSync(new ArrayBuffer(4096), {
offset: 1,
length: FILE_CONTENT.length
});
expect(readLen == FILE_CONTENT.length - 1).assertTrue();
sr.closeSync();
fileIO.unlinkSync(fpath);
} catch (e) {
console.log('fileIO_test_stream_read_sync_003 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_READ_SYNC_0400
* @tc.name fileIO_test_stream_read_sync_004
* @tc.desc Test the readSync() interface of class Stream.
* Read data with invalid type of parameter.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_stream_read_sync_004', 0, async function () {
let fpath = await nextFileName('fileIO_test_stream_read_sync_004');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
let sr = fileIO.createStreamSync(fpath, 'r+');
try {
expect(sr !== null).assertTrue();
sr.readSync("");
expect(false).assertTrue();
} catch (e) {
sr.closeSync();
fileIO.unlinkSync(fpath);
console.log('fileIO_test_stream_read_sync_004 has failed for ' + e.message + ', code: ' + e.code);
expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_READ_SYNC_0500
* @tc.name fileIO_test_stream_read_sync_005
* @tc.desc Test the readSync() interface of class Stream.
* Read data with invalid length > size of ArrayBuffer(4096).
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_stream_read_sync_005', 0, async function () {
let fpath = await nextFileName('fileIO_test_stream_read_sync_005');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
let sr = fileIO.createStreamSync(fpath, 'r+');
const invalidLength = 4097;
try {
expect(sr !== null).assertTrue();
sr.readSync(new ArrayBuffer(4096), { length: invalidLength });
expect(false).assertTrue();
} catch (e) {
sr.closeSync();
fileIO.unlinkSync(fpath);
console.log('fileIO_test_stream_read_sync_005 has failed for ' + e.message + ', code: ' + e.code);
expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_READ_SYNC_0600
* @tc.name fileIO_test_stream_read_sync_006
* @tc.desc Test the readSync() interface of class Stream.
* Read data with invalid offset = -1.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_stream_read_sync_006', 0, async function () {
let fpath = await nextFileName('fileIO_test_stream_read_sync_006');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
let sr = fileIO.createStreamSync(fpath, 'r+');
const invalidOffset = -1;
try {
expect(sr !== null).assertTrue();
sr.readSync(new ArrayBuffer(4096), { offset: invalidOffset });
expect(false).assertTrue();
} catch (e) {
sr.closeSync();
fileIO.unlinkSync(fpath);
console.log('fileIO_test_stream_read_sync_006 has failed for ' + e.message + ', code: ' + e.code);
expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_READ_ASYNC_0000
* @tc.name fileIO_test_stream_read_async_000
* @tc.desc Test read() interface, Promise.
* Create a file stream in r+ mode, reading data from this stream.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 1
* @tc.require
*/
it('fileIO_test_stream_read_async_000', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_stream_read_async_000');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let sr = fileIO.createStreamSync(fpath, 'r+');
expect(sr !== null).assertTrue();
let readLen = await sr.read(new ArrayBuffer(4096));
expect(readLen == FILE_CONTENT.length).assertTrue();
sr.closeSync();
fileIO.unlinkSync(fpath);
done();
} catch (e) {
console.log('fileIO_test_stream_read_async_000 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_READ_ASYNC_0100
* @tc.name fileIO_test_stream_read_async_001
* @tc.desc Test read() interface, Callback.
* Create a file stream in r+ mode, reading data from this stream.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 1
* @tc.require
*/
it('fileIO_test_stream_read_async_001', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_stream_read_async_001');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let sr = fileIO.createStreamSync(fpath, 'r+');
expect(sr !== null).assertTrue();
sr.read(new ArrayBuffer(4096), (err, readLen) => {
if (err) {
console.log('fileIO_test_stream_read_async_001 error package: ' + JSON.stringify(err));
expect(false).assertTrue();
}
expect(readLen == FILE_CONTENT.length).assertTrue();
sr.closeSync();
fileIO.unlinkSync(fpath);
done();
});
} catch (e) {
console.log('fileIO_test_stream_read_async_001 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_READ_ASYNC_0200
* @tc.name fileIO_test_stream_read_async_002
* @tc.desc Test the read() interface of class Stream. Promise.
* Create a file stream in r+ mode, reading data with length = 5.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_stream_read_async_002', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_stream_read_async_002');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let sr = fileIO.createStreamSync(fpath, 'r+');
expect(sr !== null).assertTrue();
let readLen = await sr.read(new ArrayBuffer(4096), {
length: 5
});
expect(readLen == 5).assertTrue();
sr.closeSync();
fileIO.unlinkSync(fpath);
done();
} catch (e) {
console.log('fileIO_test_stream_read_async_002 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_READ_ASYNC_0300
* @tc.name fileIO_test_stream_read_async_003
* @tc.desc Test the read() interface of class Stream. Callback.
* Create a file stream in r+ mode, reading data with length = 5.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_stream_read_async_003', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_stream_read_async_003');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let sr = fileIO.createStreamSync(fpath, 'r+');
expect(sr !== null).assertTrue();
sr.read(new ArrayBuffer(4096), {
length: 5
}, (err, readLen) => {
if (err) {
console.log('fileIO_test_stream_read_async_003 error package: ' + JSON.stringify(err));
expect(false).assertTrue();
}
expect(readLen == 5).assertTrue();
sr.closeSync();
fileIO.unlinkSync(fpath);
done();
});
} catch (e) {
console.log('fileIO_test_stream_read_async_003 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_READ_ASYNC_0400
* @tc.name fileIO_test_stream_read_async_004
* @tc.desc Test the read() interface of class Stream. Promise.
* Create a file stream in r+ mode, reading data with offset = 5.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_stream_read_async_004', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_stream_read_async_004');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let sr = fileIO.createStreamSync(fpath, 'r+');
expect(sr !== null).assertTrue();
let readLen = await sr.read(new ArrayBuffer(4096), {
offset: 5
});
expect(readLen == FILE_CONTENT.length - 5).assertTrue();
sr.closeSync();
fileIO.unlinkSync(fpath);
done();
} catch (e) {
console.log('fileIO_test_stream_read_async_004 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_READ_ASYNC_0500
* @tc.name fileIO_test_stream_read_async_005
* @tc.desc Test the read() interface of class Stream. Callback.
* Create a file stream in r+ mode, reading data with offset = 5.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_stream_read_async_005', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_stream_read_async_005');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let sr = fileIO.createStreamSync(fpath, 'r+');
expect(sr !== null).assertTrue();
sr.read(new ArrayBuffer(4096), {
offset: 5
}, (err, readLen) => {
if (err) {
console.log('fileIO_test_stream_read_async_005 error package: ' + JSON.stringify(err));
expect(false).assertTrue();
}
expect(readLen == FILE_CONTENT.length - 5).assertTrue();
sr.closeSync();
fileIO.unlinkSync(fpath);
done();
});
} catch (e) {
console.log('fileIO_test_stream_read_async_005 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_READ_ASYNC_0600
* @tc.name fileIO_test_stream_read_async_006
* @tc.desc Test the read() interface of class Stream. Promise.
* Read data with invalid length > size of ArrayBuffer(4096).
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_stream_read_async_006', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_stream_read_async_006');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
let sr = fileIO.createStreamSync(fpath, 'r+');
try {
expect(sr !== null).assertTrue();
const invalidLength = 4097;
await sr.read(new ArrayBuffer(4096), { length: invalidLength });
expect(false).assertTrue();
} catch (e) {
sr.closeSync();
fileIO.unlinkSync(fpath);
console.log('fileIO_test_stream_read_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_STREAM_READ_ASYNC_0700
* @tc.name fileIO_test_stream_read_async_007
* @tc.desc Test the read() interface of class Stream. Callback.
* Read data with invalid offset = -1.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_stream_read_async_007', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_stream_read_async_007');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
let sr = fileIO.createStreamSync(fpath, 'r+');
try {
expect(sr !== null).assertTrue();
const invalidOffset = -1;
sr.read(new ArrayBuffer(4096), {
offset: invalidOffset
}, (err) => {
expect(false).assertTrue();
});
} catch (e) {
sr.closeSync();
fileIO.unlinkSync(fpath);
console.log('fileIO_test_stream_read_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_STREAM_READ_ASYNC_0800
* @tc.name fileIO_test_stream_read_async_008
* @tc.desc Test the read() interface of class Stream. Promise.
* Create a file stream in r+ mode, reading data with offset = 1 and length = 11.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_stream_read_async_008', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_stream_read_async_008');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let sr = fileIO.createStreamSync(fpath, 'r+');
expect(sr !== null).assertTrue();
let readLen = await sr.read(new ArrayBuffer(4096), {
offset: 1,
length: FILE_CONTENT.length
});
expect(readLen == FILE_CONTENT.length - 1).assertTrue();
sr.closeSync();
fileIO.unlinkSync(fpath);
done();
} catch (e) {
console.log('fileIO_test_stream_read_async_008 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_READ_ASYNC_0900
* @tc.name fileIO_test_stream_read_async_009
* @tc.desc Test the read() interface of class Stream. Callback.
* Create a file stream in r+ mode, reading data with offset = 1 and length = 11.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_stream_read_async_009', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_stream_read_async_009');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let sr = fileIO.createStreamSync(fpath, 'r+');
expect(sr !== null).assertTrue();
sr.read(new ArrayBuffer(4096), {
offset: 1,
length: FILE_CONTENT.length
}, (err, readLen) => {
if (err) {
console.log('fileIO_test_stream_read_async_009 error package: ' + JSON.stringify(err));
expect(false).assertTrue();
}
expect(readLen == FILE_CONTENT.length - 1).assertTrue();
sr.closeSync();
fileIO.unlinkSync(fpath);
done();
});
} catch (e) {
console.log('fileIO_test_stream_read_async_009 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_READ_ASYNC_1000
* @tc.name fileIO_test_stream_read_async_010
* @tc.desc Test the read() interface of class Stream. Promise.
* Create a file stream in r+ mode, reading data with empty option.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_stream_read_async_010', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_stream_read_async_010');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let sr = fileIO.createStreamSync(fpath, 'r+');
expect(sr !== null).assertTrue();
let readLen = await sr.read(new ArrayBuffer(4096), {});
expect(readLen == FILE_CONTENT.length).assertTrue();
sr.closeSync();
fileIO.unlinkSync(fpath);
done();
} catch (e) {
console.log('fileIO_test_stream_read_async_010 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_READ_ASYNC_1100
* @tc.name fileIO_test_stream_read_async_011
* @tc.desc Test the read() interface of class Stream. Callback.
* Create a file stream in r+ mode, reading data with empty option.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_stream_read_async_011', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_stream_read_async_011');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let sr = fileIO.createStreamSync(fpath, 'r+');
expect(sr !== null).assertTrue();
sr.read(new ArrayBuffer(4096), {
}, (err, readLen) => {
if (err) {
console.log('fileIO_test_stream_read_async_011 error package: ' + JSON.stringify(err));
expect(false).assertTrue();
}
expect(readLen == FILE_CONTENT.length).assertTrue();
sr.closeSync();
fileIO.unlinkSync(fpath);
done();
});
} catch (e) {
console.log('fileIO_test_stream_read_async_011 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_READ_ASYNC_1200
* @tc.name fileIO_test_stream_read_async_012
* @tc.desc Test the read() interface of class Stream. Promise. Missing parameter.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_stream_read_async_012', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_stream_read_async_012');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
let sr = fileIO.createStreamSync(fpath, 'r+');
try {
expect(sr !== null).assertTrue();
await sr.read();
expect(false).assertTrue();
} catch (e) {
sr.closeSync();
fileIO.unlinkSync(fpath);
console.log('fileIO_test_stream_read_async_012 has failed for ' + e.message + ', code: ' + e.code);
expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue();
done();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_READ_ASYNC_1300
* @tc.name fileIO_test_stream_read_async_013
* @tc.desc Test the read() interface of class Stream. Promise.
* Read data with invalid type of parameter.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_stream_read_async_013', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_stream_read_async_013');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
let sr = fileIO.createStreamSync(fpath, 'r+');
try {
expect(sr !== null).assertTrue();
await sr.read("");
expect(false).assertTrue();
} catch (e) {
sr.closeSync();
fileIO.unlinkSync(fpath);
console.log('fileIO_test_stream_read_async_013 has failed for ' + e.message + ', code: ' + e.code);
expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue();
done();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_READ_ASYNC_1400
* @tc.name fileIO_test_stream_read_async_014
* @tc.desc Test the read() interface of class Stream. Callback.
* Read data with invalid type of parameter.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_stream_read_async_014', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_stream_read_async_014');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
let sr = fileIO.createStreamSync(fpath, 'r+');
try {
expect(sr !== null).assertTrue();
sr.read("", (err) => {
expect(false).assertTrue();
});
} catch (e) {
sr.closeSync();
fileIO.unlinkSync(fpath);
console.log('fileIO_test_stream_read_async_014 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 fileIOStreamWrite() {
describe('fileIO_fs_stream_write', function () {
/**
* @tc.number SUB_DF_FILEIO_STREAM_WRITE_SYNC_0000
* @tc.name fileIO_test_stream_write_sync_000
* @tc.desc Test the writeSync() interface of class Stream.
* Create a file stream in r+ mode, writing an ArrayBuffer.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('fileIO_test_stream_write_sync_000', 0, async function () {
let fpath = await nextFileName('fileIO_test_stream_write_sync_000');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let sr = fileIO.createStreamSync(fpath, 'r+');
expect(sr !== null).assertTrue();
let bytesWritten = sr.writeSync(new ArrayBuffer(4096));
expect(bytesWritten == 4096).assertTrue();
sr.closeSync();
fileIO.unlinkSync(fpath);
} catch (e) {
console.log('fileIO_test_stream_write_sync_000 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_WRITE_SYNC_0100
* @tc.name fileIO_test_stream_write_sync_001
* @tc.desc Test the writeSync() interface of class Stream.
* Create a file stream in r+ mode, writing a string.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_stream_write_sync_001', 0, async function () {
let fpath = await nextFileName('fileIO_test_stream_write_sync_001');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let sr = fileIO.createStreamSync(fpath, 'r+');
expect(sr !== null).assertTrue();
let bytesWritten = sr.writeSync(FILE_CONTENT);
expect(bytesWritten == FILE_CONTENT.length).assertTrue();
sr.closeSync();
fileIO.unlinkSync(fpath);
} catch (e) {
console.log('fileIO_test_stream_write_sync_001 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_WRITE_SYNC_0200
* @tc.name fileIO_test_stream_write_sync_002
* @tc.desc Test the writeSync() interface of class Stream.
* Create a file stream in r+ mode, writing a string with offset = 1.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_stream_write_sync_002', 0, async function () {
let fpath = await nextFileName('fileIO_test_stream_write_sync_002');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let sr = fileIO.createStreamSync(fpath, 'r+');
expect(sr !== null).assertTrue();
let bytesWritten = sr.writeSync(FILE_CONTENT, { offset: 1 });
expect(bytesWritten == FILE_CONTENT.length).assertTrue();
sr.closeSync();
fileIO.unlinkSync(fpath);
} catch (e) {
console.log('fileIO_test_stream_write_sync_002 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_WRITE_SYNC_0300
* @tc.name fileIO_test_stream_write_sync_003
* @tc.desc Test the writeSync() interface of class Stream.
* Write a string with invalide offset = -1.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_stream_write_sync_003', 0, async function () {
let fpath = await nextFileName('fileIO_test_stream_write_sync_003');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
let sr = fileIO.createStreamSync(fpath, 'r+');
const invalidOffset = -1;
try {
expect(sr !== null).assertTrue();
sr.writeSync(new ArrayBuffer(4096), { offset: invalidOffset });
expect(false).assertTrue();
} catch (e) {
sr.closeSync();
fileIO.unlinkSync(fpath);
console.log('fileIO_test_stream_write_sync_003 has failed for ' + e.message + ', code: ' + e.code);
expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_WRITE_SYNC_0400
* @tc.name fileIO_test_stream_write_sync_004
* @tc.desc Test the writeSync() interface of class Stream.
* Create a file stream in r+ mode, writing a string with encoding = 'utf-8'.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_stream_write_sync_004', 0, async function () {
let fpath = await nextFileName('fileIO_test_stream_write_sync_004');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let sr = fileIO.createStreamSync(fpath, 'r+');
expect(sr !== null).assertTrue();
let bytesWritten = sr.writeSync(FILE_CONTENT, { encoding: 'utf-8' });
expect(bytesWritten == FILE_CONTENT.length).assertTrue();
sr.closeSync();
fileIO.unlinkSync(fpath);
} catch (e) {
console.log('fileIO_test_stream_write_sync_004 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_WRITE_SYNC_0500
* @tc.name fileIO_test_stream_write_sync_005
* @tc.desc Test the writeSync() interface of class Stream.
* Create a file stream in r+ mode, writing a string with length = 5.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_stream_write_sync_005', 0, async function () {
let fpath = await nextFileName('fileIO_test_stream_write_sync_005');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let sr = fileIO.createStreamSync(fpath, 'r+');
expect(sr !== null).assertTrue();
let bytesWritten = sr.writeSync(FILE_CONTENT, { length: 5 });
expect(bytesWritten == 5).assertTrue();
sr.closeSync();
fileIO.unlinkSync(fpath);
} catch (e) {
console.log('fileIO_test_stream_write_sync_005 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_WRITE_SYNC_0600
* @tc.name fileIO_test_stream_write_sync_006
* @tc.desc Test the writeSync() interface of class Stream.
* Write an ArrayBuffer with invalid length > size of ArrayBuffer(4096).
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_stream_write_sync_006', 0, async function () {
let fpath = await nextFileName('fileIO_test_stream_write_sync_006');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
let sr = fileIO.createStreamSync(fpath, 'r+');
try {
expect(sr !== null).assertTrue();
const invalidLength = 4097;
sr.writeSync(new ArrayBuffer(4096), { length: invalidLength });
expect(false).assertTrue();
} catch (e) {
sr.closeSync();
fileIO.unlinkSync(fpath);
console.log('fileIO_test_stream_write_sync_006 has failed for ' + e.message + ', code: ' + e.code);
expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_WRITE_SYNC_0700
* @tc.name fileIO_test_stream_write_sync_007
* @tc.desc Test the writeSync() interface of class Stream.
* Write a string with invalid length = 9999.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_stream_write_sync_007', 0, async function () {
let fpath = await nextFileName('fileIO_test_stream_write_sync_007');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
let sr = fileIO.createStreamSync(fpath, 'r+');
const invalidLength = 9999;
try {
expect(sr !== null).assertTrue();
sr.writeSync(FILE_CONTENT, { length: invalidLength });
expect(false).assertTrue();
} catch (e) {
sr.closeSync();
fileIO.unlinkSync(fpath);
console.log('fileIO_test_stream_write_sync_007 has failed for ' + e.message + ', code: ' + e.code);
expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_WRITE_SYNC_0800
* @tc.name fileIO_test_stream_write_sync_008
* @tc.desc Test the writeSync() interface of class Stream.
* Create a file stream in r+ mode, writing an ArrayBuffer with offset = 1, length = 4096 and encoding = 'utf-8'.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_stream_write_sync_008', 0, async function () {
let fpath = await nextFileName('fileIO_test_stream_write_sync_008');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let sr = fileIO.createStreamSync(fpath, 'r+');
expect(sr !== null).assertTrue();
let bytesWritten = sr.writeSync(new ArrayBuffer(4096), {
offset: 1,
length: 4096,
encoding: 'utf-8'
});
expect(bytesWritten == 4096).assertTrue();
sr.closeSync();
fileIO.unlinkSync(fpath);
} catch (e) {
console.log('fileIO_test_stream_write_sync_008 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_WRITE_SYNC_0900
* @tc.name fileIO_test_stream_write_sync_009
* @tc.desc Test the writeSync() interface of class Stream.
* Create a file stream in r+ mode, writing a string with offset = 1, length = 11 and encoding = 'utf-8'.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_stream_write_sync_009', 0, async function () {
let fpath = await nextFileName('fileIO_test_stream_write_sync_009');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let sr = fileIO.createStreamSync(fpath, 'r+');
expect(sr !== null).assertTrue();
let bytesWritten = sr.writeSync(FILE_CONTENT, {
offset: 1,
length: FILE_CONTENT.length,
encoding: 'utf-8'
});
expect(bytesWritten == FILE_CONTENT.length).assertTrue();
sr.closeSync();
fileIO.unlinkSync(fpath);
} catch (e) {
console.log('fileIO_test_stream_write_sync_009 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_WRITE_SYNC_1000
* @tc.name fileIO_test_stream_write_sync_010
* @tc.desc Test the writeSync() interface of class Stream.
* Create a file stream in r+ mode, writing a string with empty option.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_stream_write_sync_010', 0, async function () {
let fpath = await nextFileName('fileIO_test_stream_write_sync_010');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let sr = fileIO.createStreamSync(fpath, 'r+');
expect(sr !== null).assertTrue();
let bytesWritten = sr.writeSync(FILE_CONTENT, {});
expect(bytesWritten == FILE_CONTENT.length).assertTrue();
sr.closeSync();
fileIO.unlinkSync(fpath);
} catch (e) {
console.log('fileIO_test_stream_write_sync_010 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_WRITE_SYNC_1100
* @tc.name fileIO_test_stream_write_sync_011
* @tc.desc Test the writeSync() interface of class Stream.
* There are no parameters.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_stream_write_sync_011', 0, async function () {
let fpath = await nextFileName('fileIO_test_stream_write_sync_011');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
let sr = fileIO.createStreamSync(fpath, 'r+');
try {
expect(sr !== null).assertTrue();
sr.writeSync();
expect(false).assertTrue();
} catch (e) {
sr.closeSync();
fileIO.unlinkSync(fpath);
console.log('fileIO_test_stream_write_sync_011 has failed for ' + e.message + ', code: ' + e.code);
expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_WRITE_ASYNC_0000
* @tc.name fileIO_test_stream_write_async_000
* @tc.desc Test the write() interface of class Stream. Promise.
* Create a file stream in r+ mode, writing an ArrayBuffer.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 1
* @tc.require
*/
it('fileIO_test_stream_write_async_000', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_stream_write_async_000');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let sr = fileIO.createStreamSync(fpath, 'r+');
expect(sr !== null).assertTrue();
let bytesWritten = await sr.write(new ArrayBuffer(4096));
expect(bytesWritten == 4096).assertTrue();
sr.closeSync();
fileIO.unlinkSync(fpath);
done();
} catch (e) {
console.log('fileIO_test_stream_write_async_000 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_WRITE_ASYNC_0100
* @tc.name fileIO_test_stream_write_async_001
* @tc.desc Test the write() interface of class Stream. Callback.
* Create a file stream in r+ mode, writing an ArrayBuffer.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 1
* @tc.require
*/
it('fileIO_test_stream_write_async_001', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_stream_write_async_001');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let sr = fileIO.createStreamSync(fpath, 'r+');
expect(sr !== null).assertTrue();
sr.write(new ArrayBuffer(4096), (err, bytesWritten) => {
if (err) {
console.log('fileIO_test_stream_write_async_001 err package: ' + JSON.stringify(err));
expect(false).assertTrue();
}
expect(bytesWritten == 4096).assertTrue();
sr.closeSync();
fileIO.unlinkSync(fpath);
done();
});
} catch (e) {
console.log('fileIO_test_stream_write_async_001 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_WRITE_ASYNC_0200
* @tc.name fileIO_test_stream_write_async_002
* @tc.desc Test the write() interface of class Stream. Promise.
* Create a file stream in r+ mode, writing a string.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_stream_write_async_002', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_stream_write_async_002');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let sr = fileIO.createStreamSync(fpath, 'r+');
expect(sr !== null).assertTrue();
let bytesWritten = await sr.write(FILE_CONTENT);
expect(bytesWritten == FILE_CONTENT.length).assertTrue();
sr.closeSync();
fileIO.unlinkSync(fpath);
done();
} catch (e) {
console.log('fileIO_test_stream_write_async_002 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_WRITE_ASYNC_0300
* @tc.name fileIO_test_stream_write_async_003
* @tc.desc Test the write() interface of class Stream. Callback.
* Create a file stream in r+ mode, writing a string.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_stream_write_async_003', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_stream_write_async_003');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let sr = fileIO.createStreamSync(fpath, 'r+');
expect(sr !== null).assertTrue();
sr.write(FILE_CONTENT, (err, bytesWritten) => {
if (err) {
console.log('fileIO_test_stream_write_async_003 err package: ' + JSON.stringify(err));
expect(false).assertTrue();
}
expect(bytesWritten == FILE_CONTENT.length).assertTrue();
sr.closeSync();
fileIO.unlinkSync(fpath);
done();
});
} catch (e) {
console.log('fileIO_test_stream_write_async_003 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_WRITE_ASYNC_0400
* @tc.name fileIO_test_stream_write_async_004
* @tc.desc Test the write() interface of class Stream. Promise.
* Create a file stream in r+ mode, writing a string with offset = 1.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_stream_write_async_004', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_stream_write_async_004');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let sr = fileIO.createStreamSync(fpath, 'r+');
expect(sr !== null).assertTrue();
let bytesWritten = await sr.write(FILE_CONTENT, { offset: 1 });
expect(bytesWritten == FILE_CONTENT.length).assertTrue();
sr.closeSync();
fileIO.unlinkSync(fpath);
done();
} catch (e) {
console.log('fileIO_test_stream_write_async_004 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_WRITE_ASYNC_0500
* @tc.name fileIO_test_stream_write_async_005
* @tc.desc Test the write() interface of class Stream. Callback.
* Create a file stream in r+ mode, writing a string with offset = 1.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_stream_write_async_005', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_stream_write_async_005');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let sr = fileIO.createStreamSync(fpath, 'r+');
expect(sr !== null).assertTrue();
sr.write(FILE_CONTENT, {
offset: 1
}, (err, bytesWritten) => {
if (err) {
console.log('fileIO_test_stream_write_async_005 err package: ' + JSON.stringify(err));
expect(false).assertTrue();
}
expect(bytesWritten == FILE_CONTENT.length).assertTrue();
sr.closeSync();
fileIO.unlinkSync(fpath);
done();
});
} catch (e) {
console.log('fileIO_test_stream_write_async_005 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_WRITE_ASYNC_0600
* @tc.name fileIO_test_stream_write_async_006
* @tc.desc Test the write() interface of class Stream. Callback.
* Write a string with invalide offset = -1.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_stream_write_async_006', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_stream_write_async_006');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
let sr = fileIO.createStreamSync(fpath, 'r+');
const invalidOffset = -1;
try {
expect(sr !== null).assertTrue();
sr.write(new ArrayBuffer(4096), {
offset: invalidOffset
}, (err) => {
expect(false).assertTrue();
});
} catch (e) {
sr.closeSync();
fileIO.unlinkSync(fpath);
console.log('fileIO_test_stream_write_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_STREAM_WRITE_ASYNC_0700
* @tc.name fileIO_test_stream_write_async_007
* @tc.desc Test the write() interface of class Stream. Promise.
* Create a file stream in r+ mode, writing a string with encoding = 'utf-8'.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_stream_write_async_007', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_stream_write_async_007');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let sr = fileIO.createStreamSync(fpath, 'r+');
expect(sr !== null).assertTrue();
let bytesWritten = await sr.write(FILE_CONTENT, { encoding: 'utf-8' });
expect(bytesWritten == FILE_CONTENT.length).assertTrue();
sr.closeSync();
fileIO.unlinkSync(fpath);
done();
} catch (e) {
console.log('fileIO_test_stream_write_async_007 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_WRITE_ASYNC_0800
* @tc.name fileIO_test_stream_write_async_008
* @tc.desc Test the write() interface of class Stream. Promise.
* Create a file stream in r+ mode, writing a string with encoding = 'utf-8'.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_stream_write_async_008', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_stream_write_async_008');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let sr = fileIO.createStreamSync(fpath, 'r+');
expect(sr !== null).assertTrue();
sr.write(FILE_CONTENT, {
encoding: 'utf-8'
}, (err, bytesWritten) => {
if (err) {
console.log('fileIO_test_stream_write_async_008 err package: ' + JSON.stringify(err));
expect(false).assertTrue();
}
expect(bytesWritten == FILE_CONTENT.length).assertTrue();
sr.closeSync();
fileIO.unlinkSync(fpath);
done();
});
} catch (e) {
console.log('fileIO_test_stream_write_async_008 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
done();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_WRITE_ASYNC_0900
* @tc.name fileIO_test_stream_write_async_009
* @tc.desc Test the write() interface of class Stream. Promise.
* Create a file stream in r+ mode, writing a string with length = 5.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_stream_write_async_009', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_stream_write_async_009');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let sr = fileIO.createStreamSync(fpath, 'r+');
expect(sr !== null).assertTrue();
let bytesWritten = await sr.write(FILE_CONTENT, { length: 5 });
expect(bytesWritten == 5).assertTrue();
sr.closeSync();
fileIO.unlinkSync(fpath);
done();
} catch (e) {
console.log('fileIO_test_stream_write_async_009 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_WRITE_ASYNC_1000
* @tc.name fileIO_test_stream_write_async_010
* @tc.desc Test the write() interface of class Stream. Callback.
* Create a file stream in r+ mode, writing a string with length = 5.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_stream_write_async_010', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_stream_write_async_010');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let sr = fileIO.createStreamSync(fpath, 'r+');
expect(sr !== null).assertTrue();
sr.write(FILE_CONTENT, {
length: 5
}, (err, bytesWritten) => {
if (err) {
console.log('fileIO_test_stream_write_async_010 err package: ' + JSON.stringify(err));
expect(false).assertTrue();
}
expect(bytesWritten == 5).assertTrue();
sr.closeSync();
fileIO.unlinkSync(fpath);
done();
});
} catch (e) {
console.log('fileIO_test_stream_write_async_010 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_WRITE_ASYNC_1100
* @tc.name fileIO_test_stream_write_async_011
* @tc.desc Test the write() interface of class Stream. Callback.
* Write an ArrayBuffer with invalid length > size of ArrayBuffer(4096).
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_stream_write_async_011', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_stream_write_async_011');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
let sr = fileIO.createStreamSync(fpath, 'r+');
const invalidLength = 4097;
try {
expect(sr !== null).assertTrue();
sr.write(new ArrayBuffer(4096), {
length: invalidLength
}, (err) => {
expect(false).assertTrue();
});
} catch (e) {
sr.closeSync();
fileIO.unlinkSync(fpath);
console.log('fileIO_test_stream_write_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_STREAM_WRITE_ASYNC_1200
* @tc.name fileIO_test_stream_write_async_012
* @tc.desc Test the write() interface of class Stream. Callback.
* Write a string with invalid length = 9999.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_stream_write_async_012', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_stream_write_async_012');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
let sr = fileIO.createStreamSync(fpath, 'r+');
const invalidLength = 9999;
try {
expect(sr !== null).assertTrue();
sr.write(FILE_CONTENT, {
length: invalidLength
}, (err) => {
expect(false).assertTrue();
});
} catch (e) {
sr.closeSync();
fileIO.unlinkSync(fpath);
console.log('fileIO_test_stream_write_async_012 has failed for ' + e.message + ', code: ' + e.code);
expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue();
done();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_WRITE_ASYNC_1300
* @tc.name fileIO_test_stream_write_async_013
* @tc.desc Test the write() interface of class Stream. Promise.
* Create a file stream in r+ mode, writing an ArrayBuffer with offset = 1, length = 4096 and encoding = 'utf-8'.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_stream_write_async_013', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_stream_write_async_013');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let sr = fileIO.createStreamSync(fpath, 'r+');
expect(sr !== null).assertTrue();
let bytesWritten = await sr.write(new ArrayBuffer(4096), {
offset: 1,
length: 4096,
encoding: 'utf-8'
});
expect(bytesWritten == 4096).assertTrue();
sr.closeSync();
fileIO.unlinkSync(fpath);
done();
} catch (e) {
console.log('fileIO_test_stream_write_async_013 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_WRITE_ASYNC_1400
* @tc.name fileIO_test_stream_write_async_014
* @tc.desc Test the write() interface of class Stream. Callback.
* Create a file stream in r+ mode, writing an ArrayBuffer with offset = 1, length = 4096 and encoding = 'utf-8'.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_stream_write_async_014', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_stream_write_async_014');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let sr = fileIO.createStreamSync(fpath, 'r+');
expect(sr !== null).assertTrue();
sr.write(new ArrayBuffer(4096), {
offset: 1,
length: 4096,
encoding: 'utf-8'
}, (err, bytesWritten) => {
if (err) {
console.log('fileIO_test_stream_write_async_014 err package: ' + JSON.stringify(err));
expect(false).assertTrue();
}
expect(bytesWritten == 4096).assertTrue();
sr.closeSync();
fileIO.unlinkSync(fpath);
done();
});
} catch (e) {
console.log('fileIO_test_stream_write_async_014 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_WRITE_ASYNC_1500
* @tc.name fileIO_test_stream_write_async_015
* @tc.desc Test the write() interface of class Stream. Promise.
* Create a file stream in r+ mode, writing a string with offset = 1, length = 4096 and encoding = 'utf-8'.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_stream_write_async_015', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_stream_write_async_015');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let sr = fileIO.createStreamSync(fpath, 'r+');
expect(sr !== null).assertTrue();
let bytesWritten = await sr.write(FILE_CONTENT, {
offset: 1,
length: FILE_CONTENT.length,
encoding: 'utf-8'
});
expect(bytesWritten == FILE_CONTENT.length).assertTrue();
sr.closeSync();
fileIO.unlinkSync(fpath);
done();
} catch (e) {
console.log('fileIO_test_stream_write_async_015 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_WRITE_ASYNC_1600
* @tc.name fileIO_test_stream_write_async_016
* @tc.desc Test the write() interface of class Stream. Callback.
* Create a file stream in r+ mode, writing a string with offset = 1, length = 4096 and encoding = 'utf-8'.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_stream_write_async_016', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_stream_write_async_016');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let sr = fileIO.createStreamSync(fpath, 'r+');
expect(sr !== null).assertTrue();
sr.write(FILE_CONTENT, {
offset: 1,
length: FILE_CONTENT.length,
encoding: 'utf-8'
}, (err, bytesWritten) => {
if (err) {
console.log('fileIO_test_stream_write_async_016 err package: ' + JSON.stringify(err));
expect(false).assertTrue();
}
expect(bytesWritten == FILE_CONTENT.length).assertTrue();
sr.closeSync();
fileIO.unlinkSync(fpath);
done();
});
} catch (e) {
console.log('fileIO_test_stream_write_async_016 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_WRITE_ASYNC_1700
* @tc.name fileIO_test_stream_write_async_017
* @tc.desc Test the write() interface of class Stream. Promise.
* Create a file stream in r+ mode, writing a string with empty option.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_stream_write_async_017', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_stream_write_async_017');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let sr = fileIO.createStreamSync(fpath, 'r+');
expect(sr !== null).assertTrue();
let bytesWritten = await sr.write(FILE_CONTENT, {});
expect(bytesWritten == FILE_CONTENT.length).assertTrue();
sr.closeSync();
fileIO.unlinkSync(fpath);
done();
} catch (e) {
console.log('fileIO_test_stream_write_async_017 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_WRITE_ASYNC_1800
* @tc.name fileIO_test_stream_write_async_018
* @tc.desc Test the write() interface of class Stream. Callback.
* Create a file stream in r+ mode, writing a string with empty option.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_stream_write_async_018', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_stream_write_async_018');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let sr = fileIO.createStreamSync(fpath, 'r+');
expect(sr !== null).assertTrue();
sr.write(FILE_CONTENT, {
}, (err, bytesWritten) => {
if (err) {
console.log('fileIO_test_stream_write_async_018 err package: ' + JSON.stringify(err));
expect(false).assertTrue();
}
expect(bytesWritten == FILE_CONTENT.length).assertTrue();
sr.closeSync();
fileIO.unlinkSync(fpath);
done();
});
} catch (e) {
console.log('fileIO_test_stream_write_async_018 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_WRITE_ASYNC_1900
* @tc.name fileIO_test_stream_write_async_019
* @tc.desc Test the write() interface of class Stream. Promise.
* There are no parameters.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_stream_write_async_019', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_stream_write_async_019');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
let sr = fileIO.createStreamSync(fpath, 'r+');
try {
expect(sr !== null).assertTrue();
await sr.write();
expect(false).assertTrue();
} catch (e) {
sr.closeSync();
fileIO.unlinkSync(fpath);
console.log('fileIO_test_stream_write_async_019 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, FILE_CONTENT, prepareFile, nextFileName, describe, it, expect,
} from '../Common';
export default function fileIOCreateStream() {
describe('fileIO_fs_createStream', function () {
/**
* @tc.number SUB_DF_FILEIO_STREAM_CREATESTREAM_SYNC_0000
* @tc.name fileIO_test_create_stream_sync_000
* @tc.desc Test createStreamSync() interface.
* Create stream in 'r' mode and read data from this stream.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_create_stream_sync_000', 0, async function () {
let fpath = await nextFileName('fileIO_test_create_stream_sync_000');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
let sr = fileIO.createStreamSync(fpath, 'r');
try {
expect(sr !== null).assertTrue();
expect(sr.readSync(new ArrayBuffer(4096)) == FILE_CONTENT.length).assertTrue();
sr.writeSync(FILE_CONTENT);
expect(false).assertTrue();
} catch (e) {
sr.closeSync();
fileIO.unlinkSync(fpath);
console.log('fileIO_test_create_stream_sync_000 has failed for ' + e.message + ', code: ' + e.code);
expect(e.code == 13900005 && e.message == 'I/O error').assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_CREATESTREAM_SYNC_0100
* @tc.name fileIO_test_create_stream_sync_001
* @tc.desc Test createStreamSync() interface.
* File does not exist.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_create_stream_sync_001', 0, async function () {
let fpath = await nextFileName('fileIO_test_create_stream_sync_001');
try {
fileIO.createStreamSync(fpath, 'r');
expect(false).assertTrue();
} catch (e) {
console.log('fileIO_test_create_stream_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_STREAM_CREATESTREAM_SYNC_0200
* @tc.name fileIO_test_create_stream_sync_002
* @tc.desc Test createStreamSync() interface.
* Create stream in 'r+' mode, reading and writing data from this stream.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('fileIO_test_create_stream_sync_002', 0, async function () {
let fpath = await nextFileName('fileIO_test_create_stream_sync_002');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let sr = fileIO.createStreamSync(fpath, 'r+');
expect(sr !== null).assertTrue();
expect(sr.readSync(new ArrayBuffer(4096)) == FILE_CONTENT.length).assertTrue();
expect(sr.writeSync(FILE_CONTENT) == FILE_CONTENT.length).assertTrue();
sr.closeSync();
fileIO.unlinkSync(fpath);
} catch (e) {
console.log('fileIO_test_create_stream_sync_002 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_CREATESTREAM_SYNC_0300
* @tc.name fileIO_test_create_stream_sync_003
* @tc.desc Test createStreamSync() interface.
* Create stream in 'r+' mode, file does not exist.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_create_stream_sync_003', 0, async function () {
let fpath = await nextFileName('fileIO_test_create_stream_sync_003');
try {
fileIO.createStreamSync(fpath, 'r+');
expect(false).assertTrue();
} catch (e) {
console.log('fileIO_test_create_stream_sync_003 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_STREAM_CREATESTREAM_SYNC_0400
* @tc.name fileIO_test_create_stream_sync_004
* @tc.desc Test createStreamSync() interface.
* Invalid mode.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_create_stream_sync_004', 0, async function () {
let fpath = await nextFileName('fileIO_test_create_stream_sync_004');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
fileIO.createStreamSync(fpath, 'ohos');
expect(false).assertTrue();
} catch (e) {
console.log('fileIO_test_create_stream_sync_004 has failed for ' + e.message + ', code: ' + e.code);
expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue();
fileIO.unlinkSync(fpath);
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_CREATESTREAM_SYNC_0500
* @tc.name fileIO_test_create_stream_sync_005
* @tc.desc Test createStreamSync() interface.
* Missing parameter.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_create_stream_sync_005', 0, async function () {
let fpath = await nextFileName('fileIO_test_create_stream_sync_005');
try {
fileIO.createStreamSync(fpath);
expect(false).assertTrue();
} catch (e) {
console.log('fileIO_test_create_stream_sync_005 has failed for ' + e.message + ', code: ' + e.code);
expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_CREATESTREAM_SYNC_0600
* @tc.name fileIO_test_create_stream_sync_006
* @tc.desc Test createStreamSync() interface.
* Create stream in 'w' mode, writing data to file.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_create_stream_sync_006', 0, async function () {
let fpath = await nextFileName('fileIO_test_create_stream_sync_006');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
let sw = fileIO.createStreamSync(fpath, 'w');
try {
expect(sw !== null).assertTrue();
expect(sw.writeSync(FILE_CONTENT) == FILE_CONTENT.length).assertTrue();
sw.readSync(new ArrayBuffer(4096));
expect(false).assertTrue();
} catch (e) {
sw.closeSync();
fileIO.unlinkSync(fpath);
console.log('fileIO_test_create_stream_sync_006 has failed for ' + e.message + ', code: ' + e.code);
expect(e.code == 13900005 && e.message == 'I/O error').assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_CREATESTREAM_SYNC_0700
* @tc.name fileIO_test_create_stream_sync_007
* @tc.desc Test createStreamSync() interface.
* Create stream in 'w' mode and empty contents.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_create_stream_sync_007', 0, async function () {
let fpath = await nextFileName('fileIO_test_create_stream_sync_007');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let sw = fileIO.createStreamSync(fpath, 'w');
expect(sw !== null).assertTrue();
expect(sw.writeSync(FILE_CONTENT) == FILE_CONTENT.length).assertTrue();
sw.closeSync();
let sr = fileIO.createStreamSync(fpath, 'r');
expect(sr.readSync(new ArrayBuffer(4096)) == FILE_CONTENT.length).assertTrue();
sr.closeSync();
fileIO.unlinkSync(fpath);
} catch (e) {
console.log('fileIO_test_create_stream_sync_007 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_CREATESTREAM_SYNC_0800
* @tc.name fileIO_test_create_stream_sync_008
* @tc.desc Test createStreamSync() interface.
* Create stream in 'w' mode, creat a file.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_create_stream_sync_008', 0, async function () {
let fpath = await nextFileName('fileIO_test_create_stream_sync_008');
try {
let sw = fileIO.createStreamSync(fpath, 'w');
expect(sw !== null).assertTrue();
expect(sw.writeSync(FILE_CONTENT) == FILE_CONTENT.length).assertTrue();
sw.closeSync();
fileIO.unlinkSync(fpath);
} catch (e) {
console.log('fileIO_test_create_stream_sync_008 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_CREATESTREAM_SYNC_0900
* @tc.name fileIO_test_create_stream_sync_009
* @tc.desc Test createStreamSync() interface.
* Create stream in 'w+' mode and empty contents.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_create_stream_sync_009', 0, async function () {
let fpath = await nextFileName('fileIO_test_create_stream_sync_009');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let sw = fileIO.createStreamSync(fpath, 'w+');
expect(sw !== null).assertTrue();
expect(sw.writeSync(FILE_CONTENT) == FILE_CONTENT.length).assertTrue();
expect(sw.readSync(new ArrayBuffer(4096)) == FILE_CONTENT.length).assertTrue();
sw.closeSync();
fileIO.unlinkSync(fpath);
} catch (e) {
console.log('fileIO_test_create_stream_sync_009 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_CREATESTREAM_SYNC_1000
* @tc.name fileIO_test_create_stream_sync_010
* @tc.desc Test createStreamSync() interface.
* Create stream in 'w+' mode and creat a file.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_create_stream_sync_010', 0, async function () {
let fpath = await nextFileName('fileIO_test_create_stream_sync_010');
try {
let sw = fileIO.createStreamSync(fpath, 'w+');
expect(sw !== null).assertTrue();
expect(sw.writeSync(FILE_CONTENT) == FILE_CONTENT.length).assertTrue();
expect(sw.readSync(new ArrayBuffer(4096)) == FILE_CONTENT.length).assertTrue();
sw.closeSync();
fileIO.unlinkSync(fpath);
} catch (e) {
console.log('fileIO_test_create_stream_sync_010 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_CREATESTREAM_SYNC_1100
* @tc.name fileIO_test_create_stream_sync_011
* @tc.desc Test createStreamSync() interface.
* Create stream in 'a' mode and append contents.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_create_stream_sync_011', 0, async function () {
let fpath = await nextFileName('fileIO_test_create_stream_sync_011');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let sa = fileIO.createStreamSync(fpath, 'a');
expect(sa !== null).assertTrue();
expect(sa.writeSync(FILE_CONTENT) == FILE_CONTENT.length).assertTrue();
sa.closeSync();
let sr = fileIO.createStreamSync(fpath, 'r');
expect(sr.readSync(new ArrayBuffer(4096)) == FILE_CONTENT.length * 2).assertTrue();
sr.closeSync();
fileIO.unlinkSync(fpath);
} catch (e) {
console.log('fileIO_test_create_stream_sync_011 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_CREATESTREAM_SYNC_1200
* @tc.name fileIO_test_create_stream_sync_012
* @tc.desc Test createStreamSync() interface.
* Create stream in 'a' mode and creat a file.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_create_stream_sync_012', 0, async function () {
let fpath = await nextFileName('fileIO_test_create_stream_sync_012');
try {
let sa = fileIO.createStreamSync(fpath, 'a');
expect(sa !== null).assertTrue();
expect(sa.writeSync(FILE_CONTENT) == FILE_CONTENT.length).assertTrue();
sa.closeSync();
fileIO.unlinkSync(fpath);
} catch (e) {
console.log('fileIO_test_create_stream_sync_012 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_CREATESTREAM_SYNC_1300
* @tc.name fileIO_test_create_stream_sync_013
* @tc.desc Test createStreamSync() interface.
* Create stream in 'a' mode and write data to file.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_create_stream_sync_013', 0, async function () {
let fpath = await nextFileName('fileIO_test_create_stream_sync_013');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
let sa = fileIO.createStreamSync(fpath, 'a');
try {
expect(sa !== null).assertTrue();
expect(sa.writeSync(FILE_CONTENT) == FILE_CONTENT.length).assertTrue();
sa.readSync(new ArrayBuffer(4096));
expect(false).assertTrue();
} catch (e) {
sa.closeSync();
fileIO.unlinkSync(fpath);
console.log('fileIO_test_create_stream_sync_013 has failed for ' + e.message + ', code: ' + e.code);
expect(e.code == 13900005 && e.message == 'I/O error').assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_CREATESTREAM_SYNC_1400
* @tc.name fileIO_test_create_stream_sync_014
* @tc.desc Test createStreamSync() interface.
* Create stream in 'a+' mode and append contents.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_create_stream_sync_014', 0, async function () {
let fpath = await nextFileName('fileIO_test_create_stream_sync_014');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let sa = fileIO.createStreamSync(fpath, 'a+');
expect(sa !== null).assertTrue();
expect(sa.writeSync(FILE_CONTENT) == FILE_CONTENT.length).assertTrue();
expect(sa.readSync(new ArrayBuffer(4096)) == FILE_CONTENT.length * 2).assertTrue();
sa.closeSync();
fileIO.unlinkSync(fpath);
} catch (e) {
console.log('fileIO_test_create_stream_sync_014 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_CREATESTREAM_SYNC_1500
* @tc.name fileIO_test_create_stream_sync_015
* @tc.desc Test createStreamSync() interface.
* Create stream in 'a+' mode and creat a file.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_create_stream_sync_015', 0, async function () {
let fpath = await nextFileName('fileIO_test_create_stream_sync_015');
try {
let sa = fileIO.createStreamSync(fpath, 'a+');
expect(sa !== null).assertTrue();
expect(sa.writeSync(FILE_CONTENT) == FILE_CONTENT.length).assertTrue();
expect(sa.readSync(new ArrayBuffer(4096)) == FILE_CONTENT.length).assertTrue();
sa.closeSync();
fileIO.unlinkSync(fpath);
} catch (e) {
console.log('fileIO_test_create_stream_sync_015 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_CREATE_CREATESTREAM_ASYNC_0000
* @tc.name fileIO_test_create_stream_async_000
* @tc.desc Test createStream() interfaces. Promise.
* Create stream in 'r' mode and read data from stream.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_create_stream_async_000', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_create_stream_async_000');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
let sr = await fileIO.createStream(fpath, 'r');
try {
expect(sr !== null).assertTrue();
expect(sr.readSync(new ArrayBuffer(4096)) == FILE_CONTENT.length).assertTrue();
sr.writeSync(FILE_CONTENT);
expect(false).assertTrue();
} catch (e) {
sr.closeSync();
fileIO.unlinkSync(fpath);
console.log('fileIO_test_create_stream_async_000 has failed for ' + e.message + ', code: ' + e.code);
expect(e.code == 13900005 && e.message == 'I/O error').assertTrue();
done();
}
});
/**
* @tc.number SUB_DF_FILEIO_CREATE_CREATESTREAM_ASYNC_0100
* @tc.name fileIO_test_create_stream_async_001
* @tc.desc Test createStream() interfaces. Callback.
* Create stream in 'r' mode and read data from stream.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_create_stream_async_001', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_create_stream_async_001');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
fileIO.createStream(fpath, 'r', (err, sr) => {
if (err) {
console.log('fileIO_test_create_stream_async_001 error package: ' + JSON.stringify(err));
expect(false).assertTrue();
}
expect(sr !== null).assertTrue();
expect(sr.readSync(new ArrayBuffer(4096)) == FILE_CONTENT.length).assertTrue();
sr.write(FILE_CONTENT, (err) => {
if (err) {
sr.closeSync();
fileIO.unlinkSync(fpath);
console.log(
'fileIO_test_create_stream_async_001 error: {message: ' + err.message + ', code: ' + err.code + '}'
);
expect(err.code == 13900005 && err.message == 'I/O error').assertTrue();
done();
} else {
expect(false).assertTrue();
}
});
});
} catch (e) {
console.log('fileIO_test_create_stream_async_001 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_CREATE_CREATESTREAM_ASYNC_0200
* @tc.name fileIO_test_create_stream_async_002
* @tc.desc Test createStream() interfaces. Promise.
* Create stream in 'r' mode, file does not exist.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_create_stream_async_002', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_create_stream_async_002');
try {
await fileIO.createStream(fpath, 'r');
expect(false).assertTrue();
} catch (e) {
console.log('fileIO_test_create_stream_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_CREATE_CREATESTREAM_ASYNC_0300
* @tc.name fileIO_test_create_stream_async_003
* @tc.desc Test createStream() interfaces. Callback.
* Create stream in 'r' mode, file does not exist.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_create_stream_async_003', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_create_stream_async_003');
try {
fileIO.createStream(fpath, 'r', (err) => {
if (err) {
console.log('fileIO_test_create_stream_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_create_stream_async_003 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_CREATE_CREATESTREAM_ASYNC_0400
* @tc.name fileIO_test_create_stream_async_004
* @tc.desc Test createStream() interfaces. Promise.
* Create stream in 'r+' mode, reading and writing data from this stream.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 1
* @tc.require
*/
it('fileIO_test_create_stream_async_004', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_create_stream_async_004');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let sr = await fileIO.createStream(fpath, 'r+');
expect(sr !== null).assertTrue();
expect(sr.readSync(new ArrayBuffer(4096)) == FILE_CONTENT.length).assertTrue();
expect(sr.writeSync(FILE_CONTENT) == FILE_CONTENT.length).assertTrue();
sr.closeSync();
fileIO.unlinkSync(fpath);
done();
} catch (e) {
console.log('fileIO_test_create_stream_async_004 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_CREATE_CREATESTREAM_ASYNC_0500
* @tc.name fileIO_test_create_stream_async_005
* @tc.desc Test createStream() interfaces. Callback.
* Create stream in 'r+' mode, reading and writing data from this stream.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 1
* @tc.require
*/
it('fileIO_test_create_stream_async_005', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_create_stream_async_005');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
fileIO.createStream(fpath, 'r+', (err, sr) => {
if (err) {
console.log('fileIO_test_create_stream_async_005 error package: ' + JSON.stringify(err));
expect(false).assertTrue();
}
expect(sr !== null).assertTrue();
expect(sr.readSync(new ArrayBuffer(4096)) == FILE_CONTENT.length).assertTrue();
expect(sr.writeSync(FILE_CONTENT) == FILE_CONTENT.length).assertTrue();
sr.closeSync();
fileIO.unlinkSync(fpath);
done();
});
} catch (e) {
console.log('fileIO_test_create_stream_async_005 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_CREATE_CREATESTREAM_ASYNC_0600
* @tc.name fileIO_test_create_stream_async_006
* @tc.desc Test createStream() interfaces. Promise.
* Create stream in 'r+' mode, File does not exist.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_create_stream_async_006', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_create_stream_async_006');
try {
await fileIO.createStream(fpath, 'r+');
expect(false).assertTrue();
} catch (e) {
console.log('fileIO_test_create_stream_async_006 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_CREATE_CREATESTREAM_ASYNC_0700
* @tc.name fileIO_test_create_stream_async_007
* @tc.desc Test createStream() interfaces. Callback.
* Create stream in 'r+' mode, file does not exist.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_create_stream_async_007', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_create_stream_async_007');
try {
fileIO.createStream(fpath, 'r+', (err) => {
console.log('fileIO_test_create_stream_async_007 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_create_stream_async_007 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_CREATE_CREATESTREAM_ASYNC_0800
* @tc.name fileIO_test_create_stream_async_008
* @tc.desc Test createStream() interfaces. Promise.
* Invalid mode.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_create_stream_async_008', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_create_stream_async_008');
try {
await fileIO.createStream(fpath, 'ohos');
expect(false).assertTrue();
} catch (e) {
console.log('fileIO_test_create_stream_async_008 has failed for ' + e.message + ', code: ' + e.code);
expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue();
done();
}
});
/**
* @tc.number SUB_DF_FILEIO_CREATE_CREATESTREAM_ASYNC_0900
* @tc.name fileIO_test_create_stream_async_009
* @tc.desc Test createStream() interfaces. Promise.
* Missing parameter.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_create_stream_async_009', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_create_stream_async_009');
try {
await fileIO.createStream(fpath);
expect(false).assertTrue();
} catch (e) {
console.log('fileIO_test_create_stream_async_009 has failed for ' + e.message + ', code: ' + e.code);
expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue();
done();
}
});
/**
* @tc.number SUB_DF_FILEIO_CREATE_CREATESTREAM_ASYNC_1000
* @tc.name fileIO_test_create_stream_async_010
* @tc.desc Test createStream() interfaces. Promise.
* Create stream in 'w' mode and write data to file.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_create_stream_async_010', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_create_stream_async_010');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let sw = await fileIO.createStream(fpath, 'w');
expect(sw !== null).assertTrue();
expect(sw.writeSync(FILE_CONTENT) == FILE_CONTENT.length).assertTrue();
sw.closeSync();
let sr = fileIO.createStreamSync(fpath, 'r');
expect(sr.readSync(new ArrayBuffer(4096)) == FILE_CONTENT.length).assertTrue();
sr.closeSync();
fileIO.unlinkSync(fpath);
done();
} catch (e) {
console.log('fileIO_test_create_stream_async_010 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_CREATE_CREATESTREAM_ASYNC_1100
* @tc.name fileIO_test_create_stream_async_011
* @tc.desc Test createStream() interfaces. Promise.
* Create stream in 'w' mode, can't to read data from this stream.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_create_stream_async_011', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_create_stream_async_011');
let sw = await fileIO.createStream(fpath, 'w');
try {
expect(sw !== null).assertTrue();
expect(sw.writeSync(FILE_CONTENT) == FILE_CONTENT.length).assertTrue();
sw.readSync(new ArrayBuffer(4096));
expect(false).assertTrue();
} catch (e) {
sw.closeSync();
fileIO.unlinkSync(fpath);
console.log('fileIO_test_create_stream_async_011 has failed for ' + e.message + ', code: ' + e.code);
expect(e.code == 13900005 && e.message == 'I/O error').assertTrue();
done();
}
});
/**
* @tc.number SUB_DF_FILEIO_CREATE_CREATESTREAM_ASYNC_1200
* @tc.name fileIO_test_create_stream_async_012
* @tc.desc Test createStream() interfaces. Callback.
* Create stream in 'w' mode, can't to read data from this stream.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_create_stream_async_012', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_create_stream_async_012');
try {
fileIO.createStream(fpath, 'w', (err, sw) => {
if (err) {
console.log('fileIO_test_create_stream_async_012 error package: ' + JSON.stringify(err));
expect(false).assertTrue();
}
expect(sw !== null).assertTrue();
expect(sw.writeSync(FILE_CONTENT) == FILE_CONTENT.length).assertTrue();
sw.read(new ArrayBuffer(4096), (err) => {
if (err) {
sw.closeSync();
fileIO.unlinkSync(fpath);
console.log(
'fileIO_test_create_stream_async_012 error: {message: ' + err.message + ', code: ' + err.code + '}'
);
expect(err.code == 13900005 && err.message == 'I/O error').assertTrue();
done();
} else {
expect(false).assertTrue();
}
});
});
} catch (e) {
console.log('fileIO_test_create_stream_async_012 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_CREATE_CREATESTREAM_ASYNC_1300
* @tc.name fileIO_test_create_stream_async_013
* @tc.desc Test createStream() interfaces. Promise.
* Create stream in 'w+' mode and write/read data from this stream.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_create_stream_async_013', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_create_stream_async_013');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let sw = await fileIO.createStream(fpath, 'w+');
expect(sw !== null).assertTrue();
expect(sw.writeSync(FILE_CONTENT) == FILE_CONTENT.length).assertTrue();
expect(sw.readSync(new ArrayBuffer(4096)) == FILE_CONTENT.length).assertTrue();
sw.closeSync();
fileIO.unlinkSync(fpath);
done();
} catch (e) {
console.log('fileIO_test_create_stream_async_013 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_CREATE_CREATESTREAM_ASYNC_1400
* @tc.name fileIO_test_create_stream_async_014
* @tc.desc Test createStream() interfaces. Promise.
* Create stream in 'w+' mode and creat a file.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_create_stream_async_014', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_create_stream_async_014');
try {
let sw = await fileIO.createStream(fpath, 'w+');
expect(sw !== null).assertTrue();
expect(sw.writeSync(FILE_CONTENT) == FILE_CONTENT.length).assertTrue();
expect(sw.readSync(new ArrayBuffer(4096)) == FILE_CONTENT.length).assertTrue();
sw.closeSync();
fileIO.unlinkSync(fpath);
done();
} catch (e) {
console.log('fileIO_test_create_stream_async_014 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_CREATE_CREATESTREAM_ASYNC_1500
* @tc.name fileIO_test_create_stream_async_015
* @tc.desc Test createStream() interfaces. Callback.
* Create stream in 'w+' mode and creat a file.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_create_stream_async_015', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_create_stream_async_015');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
fileIO.createStream(fpath, 'w+', (err, sw) => {
if (err) {
console.log('fileIO_test_create_stream_async_015 error package: ' + JSON.stringify(err));
expect(false).assertTrue();
}
expect(sw !== null).assertTrue();
expect(sw.writeSync(FILE_CONTENT) == FILE_CONTENT.length).assertTrue();
expect(sw.readSync(new ArrayBuffer(4096)) == FILE_CONTENT.length).assertTrue();
sw.closeSync();
fileIO.unlinkSync(fpath);
done();
});
} catch (e) {
console.log('fileIO_test_create_stream_async_015 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_CREATE_CREATESTREAM_ASYNC_1600
* @tc.name fileIO_test_create_stream_async_016
* @tc.desc Test createStream() interfaces. Promise.
* Create stream in 'a' mode and append content to file.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_create_stream_async_016', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_create_stream_async_016');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let sa = await fileIO.createStream(fpath, 'a');
expect(sa !== null).assertTrue();
expect(sa.writeSync(FILE_CONTENT) == FILE_CONTENT.length).assertTrue();
sa.closeSync();
let sr = fileIO.createStreamSync(fpath, 'r');
expect(sr.readSync(new ArrayBuffer(4096)) == FILE_CONTENT.length * 2).assertTrue();
sr.closeSync();
fileIO.unlinkSync(fpath);
done();
} catch (e) {
console.log('fileIO_test_create_stream_async_016 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_CREATE_CREATESTREAM_ASYNC_1700
* @tc.name fileIO_test_create_stream_async_017
* @tc.desc Test createStream() interfaces. Promise.
* Create stream in 'a' mode and can't to read data from stream.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_create_stream_async_017', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_create_stream_async_017');
let sa = await fileIO.createStream(fpath, 'a');
try {
expect(sa !== null).assertTrue();
expect(sa.writeSync(FILE_CONTENT) == FILE_CONTENT.length).assertTrue();
sa.readSync(new ArrayBuffer(4096));
expect(false).assertTrue();
} catch (e) {
sa.closeSync();
fileIO.unlinkSync(fpath);
console.log('fileIO_test_create_stream_async_017 has failed for ' + e.message + ', code: ' + e.code);
expect(e.code == 13900005 && e.message == 'I/O error').assertTrue();
done();
}
});
/**
* @tc.number SUB_DF_FILEIO_CREATE_CREATESTREAM_ASYNC_1800
* @tc.name fileIO_test_create_stream_async_018
* @tc.desc Test createStream() interfaces. Callback.
* Create stream in 'a' mode and can't to read data from stream.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_create_stream_async_018', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_create_stream_async_018');
try {
fileIO.createStream(fpath, 'a', (err, sa) => {
if (err) {
console.log('fileIO_test_create_stream_async_018 error package: ' + JSON.stringify(err));
expect(false).assertTrue();
}
expect(sa !== null).assertTrue();
expect(sa.writeSync(FILE_CONTENT) == FILE_CONTENT.length).assertTrue();
sa.read(new ArrayBuffer(4096), (err) => {
if (err) {
sa.closeSync();
fileIO.unlinkSync(fpath);
console.log(
'fileIO_test_create_stream_async_018 error: {message: ' + err.message + ', code: ' + err.code + '}'
);
expect(err.code == 13900005 && err.message == 'I/O error').assertTrue();
done();
} else {
expect(false).assertTrue();
}
})
});
} catch (e) {
console.log('fileIO_test_create_stream_async_018 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_CREATE_CREATESTREAM_ASYNC_1900
* @tc.name fileIO_test_create_stream_async_019
* @tc.desc Test createStream() interfaces. Promise.
* Create stream in 'a+' mode and append content to file.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_create_stream_async_019', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_create_stream_async_019');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let sa = await fileIO.createStream(fpath, 'a+');
expect(sa !== null).assertTrue();
expect(sa.writeSync(FILE_CONTENT) == FILE_CONTENT.length).assertTrue();
expect(sa.readSync(new ArrayBuffer(4096)) == FILE_CONTENT.length * 2).assertTrue();
sa.closeSync();
fileIO.unlinkSync(fpath);
done();
} catch (e) {
console.log('fileIO_test_create_stream_async_019 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_CREATE_CREATESTREAM_ASYNC_2000
* @tc.name fileIO_test_create_stream_async_020
* @tc.desc Test createStream() interfaces. Promise.
* Create stream in 'a+' mode and creat a file.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_create_stream_async_020', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_create_stream_async_019');
try {
let sa = await fileIO.createStream(fpath, 'a+');
expect(sa !== null).assertTrue();
expect(sa.writeSync(FILE_CONTENT) == FILE_CONTENT.length).assertTrue();
expect(sa.readSync(new ArrayBuffer(4096)) == FILE_CONTENT.length).assertTrue();
sa.closeSync();
fileIO.unlinkSync(fpath);
done();
} catch (e) {
console.log('fileIO_test_create_stream_async_020 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_CREATE_CREATESTREAM_ASYNC_2100
* @tc.name fileIO_test_create_stream_async_021
* @tc.desc Test createStream() interfaces. Callback.
* Create stream in 'a+' mode and append content to file.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_create_stream_async_021', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_create_stream_async_021');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
fileIO.createStream(fpath, 'a+', (err, sa) => {
if (err) {
console.log('fileIO_test_create_stream_async_021 error package: ' + JSON.stringify(err));
expect(false).assertTrue();
}
expect(sa !== null).assertTrue();
expect(sa.writeSync(FILE_CONTENT) == FILE_CONTENT.length).assertTrue();
expect(sa.readSync(new ArrayBuffer(4096)) == FILE_CONTENT.length * 2).assertTrue();
sa.closeSync();
fileIO.unlinkSync(fpath);
done();
});
} catch (e) {
console.log('fileIO_test_create_stream_async_021 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, FILE_CONTENT, prepareFile, nextFileName, isIntNum, describe, it, expect,
} from '../Common';
export default function fileIOFdOpenStream() {
describe('fileIO_fs_FdOpenStream', async function () {
/**
* @tc.number SUB_DF_FILEIO_FDOPENSTREAM_SYNC_0000
* @tc.name fileIO_test_fdopenstream_sync_000
* @tc.desc Test fdopenStreamSync() interface.
* Create a file stream in 'r' mode and read data from this stream.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_fdopenstream_sync_000', 0, async function () {
let fpath = await nextFileName('fileIO_test_fdopenstream_sync_000');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
let file = fileIO.openSync(fpath, fileIO.OpenMode.READ_WRITE);
expect(isIntNum(file.fd)).assertTrue();
let fpr = fileIO.fdopenStreamSync(file.fd, 'r');
try {
expect(fpr !== null).assertTrue();
expect(fpr.readSync(new ArrayBuffer(4096)) == FILE_CONTENT.length).assertTrue();
fpr.writeSync(FILE_CONTENT);
expect(false).assertTrue();
} catch (e) {
fpr.closeSync();
fileIO.unlinkSync(fpath);
console.log('fileIO_test_fdopenstream_sync_000 has failed for ' + e.message + ', code: ' + e.code);
expect(e.code == 13900005 && e.message == 'I/O error').assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_FDOPENSTREAM_SYNC_0010
* @tc.name fileIO_test_fdopenstream_sync_001
* @tc.desc Test fdopenStreamSync() interface.
* Invalid file descriptor.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_fdopenstream_sync_001', 0, async function () {
try {
fileIO.fdopenStreamSync(-1, 'r');
expect(false).assertTrue();
} catch (e) {
console.log('fileIO_test_fdopenstream_sync_001 has failed for ' + e.message + ', code: ' + e.code);
expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_FDOPENSTREAM_SYNC_0200
* @tc.name fileIO_test_fdopenstream_sync_002
* @tc.desc Test fdopenStreamSync() interface.
* Create a file stream in 'r+' mode, reading and writing data from this stream.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('fileIO_test_fdopenstream_sync_002', 0, async function () {
let fpath = await nextFileName('fileIO_test_fdopenstream_sync_002');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
let file = fileIO.openSync(fpath, fileIO.OpenMode.READ_WRITE);
try {
expect(isIntNum(file.fd)).assertTrue();
let fpr = fileIO.fdopenStreamSync(file.fd, 'r+');
expect(fpr !== null).assertTrue();
expect(fpr.readSync(new ArrayBuffer(4096)) == FILE_CONTENT.length).assertTrue();
expect(fpr.writeSync(FILE_CONTENT) == FILE_CONTENT.length).assertTrue();
fpr.closeSync();
fileIO.unlinkSync(fpath);
} catch (e) {
console.log('fileIO_test_fdopenstream_sync_002 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_FDOPENSTREAM_SYNC_0300
* @tc.name fileIO_test_fdopenstream_sync_003
* @tc.desc Test fdopenStreamSync() interface.
* Invalid file descriptor.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_fdopenstream_sync_003', 0, async function () {
try {
fileIO.fdopenStreamSync(-1, 'r+');
expect(false).assertTrue();
} catch (e) {
console.log('fileIO_test_fdopenstream_sync_003 has failed for ' + e.message + ', code: ' + e.code);
expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_FDOPENSTREAM_SYNC_0400
* @tc.name fileIO_test_fdopenstream_sync_004
* @tc.desc Test fdopenStreamSync() interface.
* Invalid mode.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_fdopenstream_sync_004', 0, async function () {
let fpath = await nextFileName('fileIO_test_fdopenstream_sync_004');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
let file = fileIO.openSync(fpath, fileIO.OpenMode.READ_WRITE);
try {
expect(isIntNum(file.fd)).assertTrue();
fileIO.fdopenStreamSync(file.fd, 'ohos');
expect(false).assertTrue();
} catch (e) {
console.log('fileIO_test_fdopenstream_sync_004 has failed for ' + e.message + ', code: ' + e.code);
expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_FDOPENSTREAM_SYNC_0500
* @tc.name fileIO_test_fdopenstream_sync_005
* @tc.desc Test fdopenStreamSync() interface.
* Missing parameter.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_fdopenstream_sync_005', 0, async function () {
let fpath = await nextFileName('fileIO_test_fdopenstream_sync_005');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
let file = fileIO.openSync(fpath, fileIO.OpenMode.READ_WRITE);
try {
expect(isIntNum(file.fd)).assertTrue();
fileIO.fdopenStreamSync(file.fd);
expect(false).assertTrue();
} catch (e) {
console.log('fileIO_test_fdopenstream_sync_005 has failed for ' + e.message + ', code: ' + e.code);
expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_FDOPENSTREAM_SYNC_0600
* @tc.name fileIO_test_fdopenstream_sync_006
* @tc.desc Test fdopenStreamSync() interface.
* Create a file stream in 'w' mode, writing data to file.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_fdopenstream_sync_006', 0, async function () {
let fpath = await nextFileName('fileIO_test_fdopenstream_sync_006');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
let file = fileIO.openSync(fpath, fileIO.OpenMode.READ_WRITE);
expect(isIntNum(file.fd)).assertTrue();
let fpw = fileIO.fdopenStreamSync(file.fd, 'w');
try {
expect(fpw !== null).assertTrue();
expect(fpw.writeSync(FILE_CONTENT) == FILE_CONTENT.length).assertTrue();
fpw.readSync(new ArrayBuffer(4096));
expect(false).assertTrue();
} catch (e) {
fpw.closeSync();
fileIO.unlinkSync(fpath);
console.log('fileIO_test_fdopenstream_sync_006 has failed for ' + e.message + ', code: ' + e.code);
expect(e.code == 13900005 && e.message == 'I/O error').assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_FDOPENSTREAM_SYNC_0700
* @tc.name fileIO_test_fdopenstream_sync_007
* @tc.desc Test fdopenStreamSync() interface.
* Create a file stream in 'w' mode and empty contents.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_fdopenstream_sync_007', 0, async function () {
let fpath = await nextFileName('fileIO_test_fdopenstream_sync_007');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let file1 = fileIO.openSync(fpath, fileIO.OpenMode.WRITE_ONLY);
expect(isIntNum(file1.fd)).assertTrue();
let fpw = fileIO.fdopenStreamSync(file1.fd, 'w');
expect(fpw !== null).assertTrue();
expect(fpw.writeSync(FILE_CONTENT) == FILE_CONTENT.length).assertTrue();
fpw.closeSync();
let file2 = fileIO.openSync(fpath, fileIO.OpenMode.READ_ONLY);
let fpr = fileIO.fdopenStreamSync(file2.fd, 'r');
expect(fpr.readSync(new ArrayBuffer(4096)) == FILE_CONTENT.length).assertTrue();
fpr.closeSync();
fileIO.unlinkSync(fpath);
} catch (e) {
console.log('fileIO_test_fdopenstream_sync_007 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_FDOPENSTREAM_SYNC_0800
* @tc.name fileIO_test_fdopenstream_sync_008
* @tc.desc Test fdopenStreamSync() interface.
* Create a file stream in 'w+' mode and empty contents.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_fdopenstream_sync_008', 0, async function () {
let fpath = await nextFileName('fileIO_test_fdopenstream_sync_008');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
let file = fileIO.openSync(fpath, fileIO.OpenMode.READ_WRITE);
try {
expect(isIntNum(file.fd)).assertTrue();
let fpw = fileIO.fdopenStreamSync(file.fd, 'w+');
expect(fpw !== null).assertTrue();
expect(fpw.writeSync(FILE_CONTENT) == FILE_CONTENT.length).assertTrue();
expect(fpw.readSync(new ArrayBuffer(4096)) == FILE_CONTENT.length).assertTrue();
fpw.closeSync();
fileIO.unlinkSync(fpath);
} catch (e) {
console.log('fileIO_test_fdopenstream_sync_008 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_FDOPENSTREAM_SYNC_0900
* @tc.name fileIO_test_fdopenstream_sync_009
* @tc.desc Test fdopenStreamSync() interface.
* Create a file stream in 'a' mode and append contents.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_fdopenstream_sync_009', 0, async function () {
let fpath = await nextFileName('fileIO_test_fdopenstream_sync_009');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let file1 = fileIO.openSync(fpath, fileIO.OpenMode.READ_WRITE);
expect(isIntNum(file1.fd)).assertTrue();
let fpa = fileIO.fdopenStreamSync(file1.fd, 'a');
expect(fpa !== null).assertTrue();
expect(fpa.writeSync(FILE_CONTENT) == FILE_CONTENT.length).assertTrue();
fpa.closeSync();
let file2 = fileIO.openSync(fpath, fileIO.OpenMode.READ_WRITE);
let fpr = fileIO.fdopenStreamSync(file2.fd, 'r');
expect(fpr.readSync(new ArrayBuffer(4096)) == FILE_CONTENT.length * 2).assertTrue();
fpr.closeSync();
fileIO.unlinkSync(fpath);
} catch (e) {
console.log('fileIO_test_fdopenstream_sync_009 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_FDOPENSTREAM_SYNC_0100
* @tc.name fileIO_test_fdopenstream_sync_010
* @tc.desc Test fdopenStreamSync() interface.
* Create a file stream in 'a' mode and write data to file.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_fdopenstream_sync_010', 0, async function () {
let fpath = await nextFileName('fileIO_test_fdopenstream_sync_010');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
let file = fileIO.openSync(fpath, fileIO.OpenMode.READ_WRITE);
expect(isIntNum(file.fd)).assertTrue();
let fpa = fileIO.fdopenStreamSync(file.fd, 'a');
try {
expect(fpa !== null).assertTrue();
expect(fpa.writeSync(FILE_CONTENT) == FILE_CONTENT.length).assertTrue();
fpa.readSync(new ArrayBuffer(4096));
expect(false).assertTrue();
} catch (e) {
fpa.closeSync();
fileIO.unlinkSync(fpath);
console.log('fileIO_test_fdopenstream_sync_010 has failed for ' + e.message + ', code: ' + e.code);
expect(e.code == 13900005 && e.message == 'I/O error').assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_FDOPENSTREAM_SYNC_0110
* @tc.name fileIO_test_fdopenstream_sync_011
* @tc.desc Test fdopenStreamSync() interface.
* Create a file stream in 'a+' mode and append contents.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_fdopenstream_sync_011', 0, async function () {
let fpath = await nextFileName('fileIO_test_fdopenstream_sync_011');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
let file = fileIO.openSync(fpath, fileIO.OpenMode.READ_WRITE);
try {
expect(isIntNum(file.fd)).assertTrue();
let fpa = fileIO.fdopenStreamSync(file.fd, 'a+');
expect(fpa !== null).assertTrue();
expect(fpa.writeSync(FILE_CONTENT) == FILE_CONTENT.length).assertTrue();
expect(fpa.readSync(new ArrayBuffer(4096)) == FILE_CONTENT.length * 2).assertTrue();
fpa.closeSync();
fileIO.unlinkSync(fpath);
} catch (e) {
console.log('fileIO_test_fdopenstream_sync_011 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_FDOPENSTREAM_ASYNC_0000
* @tc.name fileIO_test_fdopenstream_async_000
* @tc.desc Test fdopenStream() interface. Promise.
* Create a file stream in 'r' mode and read data from stream.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_fdopenstream_async_000', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_fdopenstream_async_000');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
let file = fileIO.openSync(fpath, fileIO.OpenMode.READ_WRITE);
let fpr = await fileIO.fdopenStream(file.fd, 'r');
try {
expect(isIntNum(file.fd)).assertTrue();
expect(fpr !== null).assertTrue();
expect(fpr.readSync(new ArrayBuffer(4096)) == FILE_CONTENT.length).assertTrue();
fpr.writeSync(FILE_CONTENT);
expect(false).assertTrue();
} catch (e) {
fpr.closeSync();
fileIO.unlinkSync(fpath);
console.log('fileIO_test_fdopenstream_async_000 has failed for ' + e.message + ', code: ' + e.code);
expect(e.code == 13900005 && e.message == 'I/O error').assertTrue();
done();
}
});
/**
* @tc.number SUB_DF_FILEIO_FDOPENSTREAM_ASYNC_0100
* @tc.name fileIO_test_fdopenstream_async_001
* @tc.desc Test fdopenStream() interface. Callback.
* Create a file stream in 'r' mode and read data from stream.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_fdopenstream_async_001', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_fdopenstream_async_001');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
let file = fileIO.openSync(fpath, fileIO.OpenMode.READ_WRITE);
try {
expect(isIntNum(file.fd)).assertTrue();
fileIO.fdopenStream(file.fd, 'r', (err, fpr) => {
if (err) {
console.log('fileIO_test_fdopenstream_async_001 error package: ' + JSON.stringify(err));
expect(false).assertTrue();
}
expect(fpr !== null).assertTrue();
expect(fpr.readSync(new ArrayBuffer(4096)) == FILE_CONTENT.length).assertTrue();
fpr.write(FILE_CONTENT, (err) => {
if (err) {
fpr.closeSync();
fileIO.unlinkSync(fpath);
console.log(
'fileIO_test_fdopenstream_async_001 error: {message: ' + err.message + ', code: ' + err.code + '}'
);
expect(err.code == 13900005 && err.message == 'I/O error').assertTrue();
done();
} else {
expect(false).assertTrue();
}
});
});
} catch (e) {
console.log('fileIO_test_fdopenstream_async_001 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_FDOPENSTREAM_ASYNC_0200
* @tc.name fileIO_test_fdopenstream_async_002
* @tc.desc Test fdopenStream() interface.
* Invalid file descriptor.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_fdopenstream_async_002', 0, async function (done) {
try {
await fileIO.fdopenStream(-1, 'r');
expect(false).assertTrue();
} catch (e) {
console.log('fileIO_test_fdopenstream_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_FDOPENSTREAM_ASYNC_0300
* @tc.name fileIO_test_fdopenstream_async_003
* @tc.desc Test fdopenStream() interface.
* Invalid file descriptor.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_fdopenstream_async_003', 0, async function (done) {
try {
fileIO.fdopenStream(-1, 'r', (err) => {
expect(false).assertTrue();
});
} catch (e) {
console.log('fileIO_test_fdopenstream_async_003 has failed for ' + e.message + ', code: ' + e.code);
expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue();
done();
}
});
/**
* @tc.number SUB_DF_FILEIO_FDOPENSTREAM_ASYNC_0400
* @tc.name fileIO_test_fdopenstream_async_004
* @tc.desc Test fdopenStream() interface. Promise.
* Create a file stream in 'r+' mode, reading and writing data from this stream.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 1
* @tc.require
*/
it('fileIO_test_fdopenstream_async_004', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_fdopenstream_async_004');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
let file = fileIO.openSync(fpath, fileIO.OpenMode.READ_WRITE);
try {
expect(isIntNum(file.fd)).assertTrue();
let fpr = await fileIO.fdopenStream(file.fd, 'r+');
expect(fpr !== null).assertTrue();
expect(fpr.writeSync(FILE_CONTENT) == FILE_CONTENT.length).assertTrue();
expect(fpr.readSync(new ArrayBuffer(4096)) == FILE_CONTENT.length).assertTrue();
fpr.closeSync();
fileIO.unlinkSync(fpath);
done();
} catch (e) {
console.log('fileIO_test_fdopenstream_async_004 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_FDOPENSTREAM_ASYNC_0500
* @tc.name fileIO_test_fdopenstream_async_005
* @tc.desc Test fdopenStream() interface. Callback.
* Create a file stream in 'r+' mode, reading and writing data from this stream.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 1
* @tc.require
*/
it('fileIO_test_fdopenstream_async_005', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_fdopenstream_async_005');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
let file = fileIO.openSync(fpath, fileIO.OpenMode.READ_WRITE);
try {
expect(isIntNum(file.fd)).assertTrue();
fileIO.fdopenStream(file.fd, 'r+', (err, fpr) => {
if (err) {
console.log('fileIO_test_fdopenstream_async_005 error package: ' + JSON.stringify(err));
expect(false).assertTrue();
}
expect(fpr !== null).assertTrue();
expect(fpr.writeSync(FILE_CONTENT) == FILE_CONTENT.length).assertTrue();
expect(fpr.readSync(new ArrayBuffer(4096)) == FILE_CONTENT.length).assertTrue();
fpr.closeSync();
fileIO.unlinkSync(fpath);
done();
});
} catch (e) {
console.log('fileIO_test_fdopenstream_async_005 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_FDOPENSTREAM_ASYNC_0600
* @tc.name fileIO_test_fdopenstream_async_006
* @tc.desc Test fdopenStream() interface. Promise.
* Invalid mode.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_fdopenstream_async_006', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_fdopenstream_async_006');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
let file = fileIO.openSync(fpath, fileIO.OpenMode.READ_WRITE);
try {
expect(isIntNum(file.fd)).assertTrue();
await fileIO.fdopenStream(file.fd, 'ohos');
expect(false).assertTrue();
} catch (e) {
console.log('fileIO_test_fdopenstream_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_FDOPENSTREAM_ASYNC_0700
* @tc.name fileIO_test_fdopenstream_async_007
* @tc.desc Test fdopenStream() interface. Promise.
* Missing parameter.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_fdopenstream_async_007', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_fdopenstream_async_007');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
let file = fileIO.openSync(fpath, fileIO.OpenMode.READ_WRITE);
try {
expect(isIntNum(file.fd)).assertTrue();
await fileIO.fdopenStream(file.fd);
expect(false).assertTrue();
} catch (e) {
console.log('fileIO_test_fdopenstream_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_FDOPENSTREAM_ASYNC_0800
* @tc.name fileIO_test_fdopenstream_async_008
* @tc.desc Test fdopenStream() interface. Promise.
* Create a file stream in 'w' mode, can't to read data from this stream.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_fdopenstream_async_008', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_fdopenstream_async_008');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
let file = fileIO.openSync(fpath, fileIO.OpenMode.READ_WRITE);
expect(isIntNum(file.fd)).assertTrue();
let fpw = await fileIO.fdopenStream(file.fd, 'w');
try {
expect(fpw !== null).assertTrue();
expect(fpw.writeSync(FILE_CONTENT) == FILE_CONTENT.length).assertTrue();
fpw.readSync(new ArrayBuffer(4096));
expect(false).assertTrue();
} catch (e) {
fpw.closeSync();
fileIO.unlinkSync(fpath);
console.log('fileIO_test_fdopenstream_async_008 has failed for ' + e.message + ', code: ' + e.code);
expect(e.code == 13900005 && e.message == 'I/O error').assertTrue();
done();
}
});
/**
* @tc.number SUB_DF_FILEIO_FDOPENSTREAM_ASYNC_0900
* @tc.name fileIO_test_fdopenstream_async_009
* @tc.desc Test fdopenStream() interface. Callback.
* Create a file stream in 'w' mode, can't to read data from this stream.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_fdopenstream_async_009', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_fdopenstream_async_009');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
let file = fileIO.openSync(fpath, fileIO.OpenMode.READ_WRITE);
try {
expect(isIntNum(file.fd)).assertTrue();
fileIO.fdopenStream(file.fd, 'w', (err, fpw) => {
if (err) {
console.log('fileIO_test_fdopenstream_async_009 error package: ' + JSON.stringify(err));
expect(false).assertTrue();
}
expect(fpw !== null).assertTrue();
expect(fpw.writeSync(FILE_CONTENT) == FILE_CONTENT.length).assertTrue();
fpw.read(new ArrayBuffer(4096), (err) => {
if (err) {
fpw.closeSync();
fileIO.unlinkSync(fpath);
console.log(
'fileIO_test_fdopenstream_async_009 error: {message: ' + err.message + ', code: ' + err.code + '}'
);
expect(err.code == 13900005 && err.message == 'I/O error').assertTrue();
done();
} else {
expect(false).assertTrue();
}
});
});
} catch (e) {
console.log('fileIO_test_fdopenstream_async_009 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_FDOPENSTREAM_ASYNC_1000
* @tc.name fileIO_test_fdopenstream_async_010
* @tc.desc Test fdopenStream() interface. Promise.
* Create a file stream in 'w' mode and write data to file.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_fdopenstream_async_010', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_fdopenstream_async_010');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let file1 = fileIO.openSync(fpath, fileIO.OpenMode.READ_WRITE);
let fpw = await fileIO.fdopenStream(file1.fd, 'w');
expect(fpw !== null).assertTrue();
expect(fpw.writeSync(FILE_CONTENT) == FILE_CONTENT.length).assertTrue();
fpw.closeSync();
let file2 = fileIO.openSync(fpath, fileIO.OpenMode.READ_WRITE);
let fpr = await fileIO.fdopenStream(file2.fd, 'r');
expect(fpr.readSync(new ArrayBuffer(4096)) == FILE_CONTENT.length).assertTrue();
fpr.closeSync();
fileIO.unlinkSync(fpath);
done();
} catch (e) {
console.log('fileIO_test_fdopenstream_async_010 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_FDOPENSTREAM_ASYNC_1100
* @tc.name fileIO_test_fdopenstream_async_011
* @tc.desc Test fdopenStream() interface. Promise.
* Create a file stream in 'w+' mode and write/read data from this stream.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_fdopenstream_async_011', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_fdopenstream_async_011');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
let file = fileIO.openSync(fpath, fileIO.OpenMode.READ_WRITE);
try {
expect(isIntNum(file.fd)).assertTrue();
let fpw = await fileIO.fdopenStream(file.fd, 'w+');
expect(fpw !== null).assertTrue();
expect(fpw.writeSync(FILE_CONTENT) == FILE_CONTENT.length).assertTrue();
expect(fpw.readSync(new ArrayBuffer(4096)) == FILE_CONTENT.length).assertTrue();
fpw.closeSync();
fileIO.unlinkSync(fpath);
done();
} catch (e) {
console.log('fileIO_test_fdopenstream_async_011 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_FDOPENSTREAM_ASYNC_1200
* @tc.name fileIO_test_fdopenstream_async_012
* @tc.desc Test fdopenStream() interface. Callback.
* Create a file stream in 'w+' mode and write/read data from this stream.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_fdopenstream_async_012', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_fdopenstream_async_012');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
let file = fileIO.openSync(fpath, fileIO.OpenMode.READ_WRITE);
try {
expect(isIntNum(file.fd)).assertTrue();
fileIO.fdopenStream(file.fd, 'w+', (err, fpw) => {
if (err) {
console.log('fileIO_test_fdopenstream_async_012 error package: ' + JSON.stringify(err));
expect(false).assertTrue();
}
expect(fpw !== null).assertTrue();
expect(fpw.writeSync(FILE_CONTENT) == FILE_CONTENT.length).assertTrue();
expect(fpw.readSync(new ArrayBuffer(4096)) == FILE_CONTENT.length).assertTrue();
fpw.closeSync();
fileIO.unlinkSync(fpath);
done();
});
} catch (e) {
console.log('fileIO_test_fdopenstream_async_012 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_FDOPENSTREAM_ASYNC_1300
* @tc.name fileIO_test_fdopenstream_async_013
* @tc.desc Test fdopenStream() interface. Promise.
* Create a file stream in 'a' mode and append content to file.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_fdopenstream_async_013', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_fdopenstream_async_013');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let file1 = fileIO.openSync(fpath, fileIO.OpenMode.READ_WRITE);
let fpa = await fileIO.fdopenStream(file1.fd, 'a');
expect(fpa !== null).assertTrue();
expect(fpa.writeSync(FILE_CONTENT) == FILE_CONTENT.length).assertTrue();
fpa.closeSync();
let file2 = fileIO.openSync(fpath, fileIO.OpenMode.READ_WRITE);
let fpr = await fileIO.fdopenStream(file2.fd, 'r');
expect(fpr.readSync(new ArrayBuffer(4096)) == FILE_CONTENT.length * 2).assertTrue();
fpr.closeSync();
fileIO.unlinkSync(fpath);
done();
} catch (e) {
console.log('fileIO_test_fdopenstream_async_013 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_FDOPENSTREAM_ASYNC_1400
* @tc.name fileIO_test_fdopenstream_async_014
* @tc.desc Test fdopenStream() interface. Promise.
* Create a file stream in 'a' mode and can't to read data from stream.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_fdopenstream_async_014', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_fdopenstream_async_014');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
let file = fileIO.openSync(fpath, fileIO.OpenMode.READ_WRITE);
expect(isIntNum(file.fd)).assertTrue();
let fpa = await fileIO.fdopenStream(file.fd, 'a');
try {
expect(fpa !== null).assertTrue();
expect(fpa.writeSync(FILE_CONTENT) == FILE_CONTENT.length).assertTrue();
fpa.readSync(new ArrayBuffer(4096));
expect(false).assertTrue();
} catch (e) {
fpa.closeSync();
fileIO.unlinkSync(fpath);
console.log('fileIO_test_fdopenstream_async_014 has failed for ' + e.message + ', code: ' + e.code);
expect(e.code == 13900005 && e.message == 'I/O error').assertTrue();
done();
}
});
/**
* @tc.number SUB_DF_FILEIO_FDOPENSTREAM_ASYNC_1500
* @tc.name fileIO_test_fdopenstream_async_015
* @tc.desc Test fdopenStream() interface. Callback.
* Create a file stream in 'a' mode and can't to read data from stream.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_fdopenstream_async_015', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_fdopenstream_async_015');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
let file = fileIO.openSync(fpath, fileIO.OpenMode.READ_WRITE);
expect(isIntNum(file.fd)).assertTrue();
try {
fileIO.fdopenStream(file.fd, 'a', (err, fpa) => {
if (err) {
console.log('fileIO_test_fdopenstream_async_015 error package: ' + JSON.stringify(err));
expect(false).assertTrue();
}
expect(fpa !== null).assertTrue();
expect(fpa.writeSync(FILE_CONTENT) == FILE_CONTENT.length).assertTrue();
fpa.read(new ArrayBuffer(4096), (err) => {
if (err) {
fpa.closeSync();
fileIO.unlinkSync(fpath);
console.log(
'fileIO_test_fdopenstream_async_015 error: {message: ' + err.message + ', code: ' + err.code + '}'
);
expect(err.code == 13900005 && err.message == 'I/O error').assertTrue();
done();
} else {
expect(false).assertTrue();
}
});
});
} catch (e) {
console.log('fileIO_test_fdopenstream_async_015 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_FDOPENSTREAM_ASYNC_1600
* @tc.name fileIO_test_fdopenstream_async_016
* @tc.desc Test fdopenStream() interface. Promise.
* Create a file stream in 'a+' mode and append content to file.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_fdopenstream_async_016', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_fdopenstream_async_016');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
let file = fileIO.openSync(fpath, fileIO.OpenMode.READ_WRITE);
try {
expect(isIntNum(file.fd)).assertTrue();
let fpa = await fileIO.fdopenStream(file.fd, 'a+');
expect(fpa !== null).assertTrue();
expect(fpa.writeSync(FILE_CONTENT) == FILE_CONTENT.length).assertTrue();
expect(fpa.readSync(new ArrayBuffer(4096)) == FILE_CONTENT.length * 2).assertTrue();
fpa.closeSync();
fileIO.unlinkSync(fpath);
done();
} catch (e) {
console.log('fileIO_test_fdopenstream_async_016 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_FDOPENSTREAM_ASYNC_1700
* @tc.name fileIO_test_fdopenstream_async_017
* @tc.desc Test fdopenStream() interface. Callback.
* Create a file stream in 'a+' mode and append content to file.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_fdopenstream_async_017', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_fdopenstream_async_017');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
let file = fileIO.openSync(fpath, fileIO.OpenMode.READ_WRITE);
try {
expect(isIntNum(file.fd)).assertTrue();
fileIO.fdopenStream(file.fd, 'a+', (err, fpa) => {
if (err) {
console.log('fileIO_test_fdopenstream_async_017 error package: ' + JSON.stringify(err));
expect(false).assertTrue();
}
expect(fpa !== null).assertTrue();
expect(fpa.writeSync(FILE_CONTENT) == FILE_CONTENT.length).assertTrue();
expect(fpa.readSync(new ArrayBuffer(4096)) == FILE_CONTENT.length * 2).assertTrue();
fpa.closeSync();
fileIO.unlinkSync(fpath);
done();
});
} catch (e) {
console.log('fileIO_test_fdopenstream_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, 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();
}
});
})
}
/*
* 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 fileIORmdir() {
describe('fileIO_fs_rmdir', function () {
/**
* @tc.number SUB_STORAGE_FILEIO_RMDIR_SYNC_0000
* @tc.name fileIO_test_rmdir_sync_000
* @tc.desc Test rmdirSync() interface.
* Recursively delete all files and subfolders in a directory.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('fileIO_test_rmdir_sync_000', 0, async function () {
let dpath = await nextFileName('fileIO_test_rmdir_sync_000') + 'd';
let fpath = dpath + '/rmdir_sync_000';
let ffpath = dpath + '/rmdir_sync_000_1';
let ddpath = dpath + '/rmdir_sync_000_1d';
let fffpath = ddpath + '/rmdir_sync_000';
fileIO.mkdirSync(dpath);
fileIO.mkdirSync(ddpath);
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
expect(prepareFile(ffpath, FILE_CONTENT)).assertTrue();
expect(prepareFile(fffpath, FILE_CONTENT)).assertTrue();
try {
expect(fileIO.accessSync(ddpath)).assertTrue();
expect(fileIO.accessSync(fffpath)).assertTrue();
fileIO.rmdirSync(dpath);
expect(!fileIO.accessSync(dpath)).assertTrue();
expect(!fileIO.accessSync(ddpath)).assertTrue();
expect(!fileIO.accessSync(fffpath)).assertTrue();
} catch (e) {
console.log('fileIO_test_rmdir_sync_000 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_STORAGE_FILEIO_RMDIR_SYNC_0100
* @tc.name fileIO_test_rmdir_sync_001
* @tc.desc Test rmdirSync() interface.
* Invalid path.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_rmdir_sync_001', 0, async function () {
let dpath = await nextFileName('fileIO_test_rmdir_sync_001') + 'd';
try {
fileIO.rmdirSync(dpath);
expect(false).assertTrue();
} catch (e) {
console.log('fileIO_test_rmdir_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_STORAGE_FILEIO_RMDIR_SYNC_0200
* @tc.name fileIO_test_rmdir_sync_002
* @tc.desc Test rmdirSync() interface.
* Missing parameters.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_rmdir_sync_002', 0, async function () {
try {
fileIO.rmdirSync();
expect(false).assertTrue();
} catch (e) {
console.log('fileIO_test_rmdir_sync_002 has failed for ' + e.message + ', code: ' + e.code);
expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue();
}
});
/**
* @tc.number SUB_STORAGE_FILEIO_RMDIR_SYNC_0300
* @tc.name fileIO_test_rmdir_sync_003
* @tc.desc Test rmdirSync() interface.
* Invalid type of parameter.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_rmdir_sync_003', 0, function () {
try {
fileIO.rmdirSync(12);
expect(false).assertTrue();
} catch (e) {
console.log('fileIO_test_rmdir_sync_003 has failed for ' + e.message + ', code: ' + e.code);
expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue();
}
});
/**
* @tc.number SUB_STORAGE_FILEIO_RMDIR_SYNC_0400
* @tc.name fileIO_test_rmdir_sync_004
* @tc.desc Test rmdirSync() interface.
* The path contains ../, normal call.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_rmdir_sync_004', 0, async function () {
let dpath = await nextFileName('../cache/fileIO_test_rmdir_sync_003') + 'd';
try {
fileIO.mkdirSync(dpath);
expect(fileIO.accessSync(dpath)).assertTrue();
fileIO.rmdirSync(dpath);
expect(!fileIO.accessSync(dpath)).assertTrue();
} catch (e) {
console.log('fileIO_test_rmdir_sync_004 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_STORAGE_FILEIO_RMDIR_ASYNC_0000
* @tc.name fileIO_test_rmdir_async_000
* @tc.desc Test rmdir() interface. Promise.
* Recursively delete all files and subfolders in a directory.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_rmdir_async_000', 0, async function (done) {
let dpath = await nextFileName('fileIO_test_rmdir_async_000') + 'd';
let fpath = dpath + '/rmdir_async_000';
let ffpath = dpath + '/rmdir_async_000_1';
let ddpath = dpath + '/rmdir_async_000_1d';
let fffpath = ddpath + '/rmdir_async_000_2';
fileIO.mkdirSync(dpath);
fileIO.mkdirSync(ddpath);
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
expect(prepareFile(ffpath, FILE_CONTENT)).assertTrue();
expect(prepareFile(fffpath, FILE_CONTENT)).assertTrue();
try {
expect(fileIO.accessSync(ddpath)).assertTrue();
expect(fileIO.accessSync(fffpath)).assertTrue();
await fileIO.rmdir(dpath);
expect(!fileIO.accessSync(dpath)).assertTrue();
expect(!fileIO.accessSync(ddpath)).assertTrue();
expect(!fileIO.accessSync(fffpath)).assertTrue();
done();
} catch (e) {
console.log('fileIO_test_rmdir_async_000 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_STORAGE_FILEIO_RMDIR_ASYNC_0100
* @tc.name fileIO_test_rmdir_async_001
* @tc.desc Test rmdir() interface. Callback.
* Recursively delete all files and subfolders in a directory.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_rmdir_async_001', 0, async function (done) {
let dpath = await nextFileName('fileIO_test_rmdir_async_001') + 'd';
let fpath = dpath + '/rmdir_async_001';
let ffpath = dpath + '/rmdir_async_001_1';
let ddpath = dpath + '/rmdir_async_001_1d';
let fffpath = ddpath + '/rmdir_async_001_2';
fileIO.mkdirSync(dpath);
fileIO.mkdirSync(ddpath);
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
expect(prepareFile(ffpath, FILE_CONTENT)).assertTrue();
expect(prepareFile(fffpath, FILE_CONTENT)).assertTrue();
try {
expect(fileIO.accessSync(ddpath)).assertTrue();
expect(fileIO.accessSync(fffpath)).assertTrue();
fileIO.rmdir(dpath, (err) => {
if(err) {
console.log('fileIO_test_rmdir_async_001 error package: ' + JSON.stringify(err));
expect(false).assertTrue();
}
expect(!fileIO.accessSync(dpath)).assertTrue();
expect(!fileIO.accessSync(ddpath)).assertTrue();
expect(!fileIO.accessSync(fffpath)).assertTrue();
done();
});
} catch (e) {
console.log('fileIO_test_rmdir_async_001 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_STORAGE_FILEIO_RMDIR_ASYNC_0200
* @tc.name fileIO_test_rmdir_async_002
* @tc.desc Test rmdir() interface. Promise.
* Invalid path.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_rmdir_async_002', 0, async function (done) {
let dpath = await nextFileName('fileIO_test_rmdir_async_002') + 'd';
try {
await fileIO.rmdir(dpath);
expect(false).assertTrue();
} catch (e) {
console.log('fileIO_test_rmdir_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_STORAGE_FILEIO_RMDIR_ASYNC_0300
* @tc.name fileIO_test_rmdir_async_003
* @tc.desc Test rmdir() interface. Callback.
* Invalid path.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_rmdir_async_003', 0, async function (done) {
let dpath = await nextFileName('fileIO_test_rmdir_async_003') + 'd';
try {
fileIO.rmdir(dpath, (err) => {
if (err) {
console.log('fileIO_test_rmdir_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_rmdir_async_003 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_STORAGE_FILEIO_RMDIR_ASYNC_0400
* @tc.name fileIO_test_rmdir_async_004
* @tc.desc Test rmdir() interface. Callback.
* Parameter mismatch.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_rmdir_async_004', 0, async function (done) {
let dpath = await nextFileName('fileIO_test_rmdir_async_004') + 'd';
try {
fileIO.mkdirSync(dpath);
expect(fileIO.accessSync(dpath)).assertTrue();
fileIO.rmdir(dpath, '', (err) => {
expect(false).assertTrue();
});
} catch (e) {
fileIO.rmdirSync(dpath);
console.log('fileIO_test_rmdir_async_004 has failed for ' + e.message + ', code: ' + e.code);
expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue();
done();
}
});
/**
* @tc.number SUB_STORAGE_FILEIO_RMDIR_ASYNC_0500
* @tc.name fileIO_test_rmdir_async_005
* @tc.desc Test rmdir() interfaces. Promise.
* Missing parameter.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_rmdir_async_005', 0, async function (done) {
try {
await fileIO.rmdir();
expect(false).assertTrue();
} catch (e) {
console.log('fileIO_test_rmdir_async_005 has failed for ' + e.message + ', code: ' + e.code);
expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue();
done();
}
});
/**
* @tc.number SUB_STORAGE_FILEIO_RMDIR_ASYNC_0600
* @tc.name fileIO_test_rmdir_async_006
* @tc.desc Test rmdirSync() interface. Promise.
* The path contains ../, normal call.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_rmdir_async_006', 0, async function () {
let dpath = await nextFileName('../cache/fileIO_test_rmdir_async_006') + 'd';
try {
fileIO.mkdirSync(dpath);
expect(fileIO.accessSync(dpath)).assertTrue();
await fileIO.rmdir(dpath);
expect(!fileIO.accessSync(dpath)).assertTrue();
} catch (e) {
console.log('fileIO_test_rmdir_async_006 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
})
}
\ No newline at end of file
/*
* 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 fileIOUnlink() {
describe('fileIO_fs_unlink', function () {
/**
* @tc.number SUB_DF_FILEIO_UNLINK_SYNC_0000
* @tc.name fileIO_test_unlink_sync_000
* @tc.desc Test unlinkSync() interfaces.
* Missing parameter.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_unlink_sync_000', 0, function () {
try {
fileIO.unlinkSync();
expect(false).assertTrue();
} catch (e) {
console.log('fileIO_test_unlink_sync_000 has failed for ' + e.message + ', code: ' + e.code);
expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_UNLINK_SYNC_0100
* @tc.name fileIO_test_unlink_sync_001
* @tc.desc Test unlinkSync() interfaces.
* The path point to nothing, no such file.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_unlink_sync_001', 0, async function () {
let fpath = await nextFileName('fileIOTest');
try {
fileIO.unlinkSync(fpath);
expect(false).assertTrue();
} catch (e) {
console.log('fileIO_test_unlink_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_UNLINK_SYNC_0200
* @tc.name fileIO_test_unlink_sync_002
* @tc.desc Test unlinkSync() interfaces.
* Delete the file by path, verify the normal function.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it('fileIO_test_unlink_sync_002', 0, async function () {
let fpath = await nextFileName('fileIO_test_unlink_sync_002');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
expect(fileIO.accessSync(fpath)).assertTrue();
fileIO.unlinkSync(fpath);
expect(!fileIO.accessSync(fpath)).assertTrue();
} catch (e) {
console.log('fileIO_test_unlink_sync_002 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FileIO_UNLINK_ASYNC_0000
* @tc.name fileIO_test_unlink_async_000
* @tc.desc Test unlinkAsync() interfaces. Promise.
* Delete the file by path, verify the normal function.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_unlink_async_000', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_unlink_async_000');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
expect(fileIO.accessSync(fpath)).assertTrue();
await fileIO.unlink(fpath);
expect(!fileIO.accessSync(fpath)).assertTrue();
done();
} catch (e) {
console.log('fileIO_test_unlink_async_000 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FileIO_UNLINK_ASYNC_0100
* @tc.name fileIO_test_unlink_async_001
* @tc.desc Test unlinkAsync() interfaces. Callback.
* Delete the file by path, verify the normal function.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_unlink_async_001', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_unlink_async_001');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
expect(fileIO.accessSync(fpath)).assertTrue();
fileIO.unlink(fpath, (err) => {
if (err) {
console.log('fileIO_test_unlink_async_001 error package: ' + JSON.stringify(err));
expect(false).assertTrue();
}
expect(!fileIO.accessSync(fpath)).assertTrue();
done();
});
} catch (e) {
console.log('fileIO_test_unlink_async_001 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FileIO_UNLINK_ASYNC_0200
* @tc.name fileIO_test_unlink_async_002
* @tc.desc Test unlink() 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_unlink_async_002', 0, async function (done) {
let fpath = await nextFileName('fileIOTest');
try {
fileIO.unlink(fpath, (err) => {
if (err) {
console.log('fileIO_test_unlink_async_002 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_unlink_async_002 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FileIO_UNLINK_ASYNC_0300
* @tc.name fileIO_test_unlink_async_003
* @tc.desc Test unlink() 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_unlink_async_003', 0, async function (done) {
let fpath = await nextFileName('fileIOTest');
try {
await fileIO.unlink(fpath);
expect(false).assertTrue();
} catch (e) {
console.log('fileIO_test_unlink_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_UNLINK_ASYNC_0400
* @tc.name fileIO_test_unlink_async_004
* @tc.desc Test unlink() interfaces. Promise.
* Missing parameter.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 3
* @tc.require
*/
it('fileIO_test_unlink_async_004', 0, async function (done) {
try {
await fileIO.unlink();
expect(false).assertTrue();
} catch (e) {
console.log('fileIO_test_unlink_async_004 has failed for ' + e.message + ', code: ' + e.code);
expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue();
done();
}
});
});
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册