提交 6761a358 编写于 作者: R raoxian

新增randomaccessfile测试用例

Signed-off-by: Nraoxian <raoxian@huawei.com>
上级 b510db8c
......@@ -23,6 +23,10 @@ import fileioDirListfile from './module_fileio/class_dir/listfile.test.js'
import fileioDirRead from './module_fileio/class_dir/read.test.js'
import fileioDirent from './module_fileio/class_dirent/all.test.js'
import fileioStream from './module_fileio/class_stream/all.test.js'
import fileioRandomAccessFileClose from './module_fileio/class_randomAccessFile/close.test.js'
import fileioRandomAccessFileRead from './module_fileio/class_randomAccessFile/read.test.js'
import fileioRandomAccessFileSetFilePointer from './module_fileio/class_randomAccessFile/setFilePointer.test.js'
import fileioRandomAccessFileWrite from './module_fileio/class_randomAccessFile/write.test.js'
import fileioStreamClose from './module_fileio/class_stream/close.test.js'
import fileioStreamFlush from './module_fileio/class_stream/flush.test.js'
import fileioStreamRead from './module_fileio/class_stream/read.test.js'
......@@ -33,6 +37,7 @@ import fileioChmod from './module_fileio/members/chmod.test.js'
import fileioChown from './module_fileio/members/chown.test.js'
import fileioClose from './module_fileio/members/close.test.js'
import fileioCopyfile from './module_fileio/members/copyFile.test.js'
import fileioCreateRandomAccessFile from './module_fileio/members/createRandomAccessFile.test.js'
import fileioCreateStream from './module_fileio/members/createStream.test.js'
import fileioFchmod from './module_fileio/members/fchmod.test.js'
import fileioFchown from './module_fileio/members/fchown.test.js'
......@@ -71,6 +76,10 @@ export default function testsuite() {
fileioDirRead()
fileioDirent()
fileioStream()
fileioRandomAccessFileClose()
fileioRandomAccessFileRead()
fileioRandomAccessFileSetFilePointer()
fileioRandomAccessFileWrite()
fileioStreamClose()
fileioStreamFlush()
fileioStreamRead()
......@@ -81,6 +90,7 @@ export default function testsuite() {
fileioChown()
fileioClose()
fileioCopyfile()
fileioCreateRandomAccessFile()
fileioCreateStream()
fileioFchmod()
fileioFchown()
......
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the 'License');
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an 'AS IS' BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {
fileio, nextFileName,
describe, it, expect
} from '../../Common';
export default function fileioRandomAccessFileClose() {
describe('fileio_randomAccessFile_close', function () {
/**
* @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_CLOSE_SYNC_0000
* @tc.name fileio_randomaccessfile_close_sync_000
* @tc.desc Test closeSync() interface. Close the RandomAccessFile object.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('fileio_randomaccessfile_close_sync_000', 0, async function () {
let fpath = await nextFileName('fileio_randomaccessfile_close_sync_000');
try {
let randomaccessfile = fileio.createRandomAccessFileSync(fpath, 0, 0o102);
randomaccessfile.closeSync();
fileio.unlinkSync(fpath);
} catch(err) {
console.info('fileio_randomaccessfile_close_sync_000 has failed for ' + err);
expect(null).assertFail();
}
});
/**
* @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_CLOSE_SYNC_0100
* @tc.name fileio_randomaccessfile_close_sync_001
* @tc.desc Test closeSync() interface. Parameter mismatch.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('fileio_randomaccessfile_close_sync_001', 0, async function () {
let fpath = await nextFileName('fileio_randomaccessfile_close_sync_001');
let randomaccessfile = fileio.createRandomAccessFileSync(fpath, 0, 0o102);
try {
randomaccessfile.closeSync(1);
} catch(err) {
console.info('fileio_randomaccessfile_close_sync_001 has failed for ' + err);
expect(err.message == "Number of arguments unmatched").assertTrue();
randomaccessfile.closeSync();
fileio.unlinkSync(fpath);
}
});
})
}
\ No newline at end of file
/*
* Copyright (C) 2021 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 fileioRandomAccessFileRead() {
describe('fileio_randomAccessFile_read', function () {
/**
* @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_READ_SYNC_0000
* @tc.name fileio_randomaccessfile_read_sync_000
* @tc.desc Test readSync() interface. Test to read data synchronously.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('fileio_randomaccessfile_read_sync_000', 0, async function () {
let fpath = await nextFileName('fileio_randomaccessfile_read_sync_000');
try {
let fd = fileio.openSync(fpath, 0o102, 0o666);
let randomaccessfile = fileio.createRandomAccessFileSync(fd, 0);
let length = 4096;
let num = randomaccessfile.writeSync(new ArrayBuffer(length));
expect(num == length).assertTrue();
randomaccessfile.setFilePointerSync(0);
let number = randomaccessfile.readSync(new ArrayBuffer(length));
expect(number == length).assertTrue();
randomaccessfile.closeSync();
fileio.unlinkSync(fpath);
} catch (err) {
console.info('fileio_randomaccessfile_read_sync_000 has failed for ' + err);
expect(null).assertFail();
}
});
/**
* @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_READ_SYNC_0100
* @tc.name fileio_randomaccessfile_read_sync_001
* @tc.desc Test readSync() interface. When the position is 1. Test to read data synchronously.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('fileio_randomaccessfile_read_sync_001', 0, async function () {
let fpath = await nextFileName('fileio_randomaccessfile_read_sync_001');
try {
let randomaccessfile = fileio.createRandomAccessFileSync(fpath, 0, 0o102);
let length = 4096;
let num = randomaccessfile.writeSync(new ArrayBuffer(length));
expect(num == length).assertTrue();
randomaccessfile.setFilePointerSync(0);
let number = randomaccessfile.readSync(new ArrayBuffer(length), { position: 1 });
expect(number == length - 1).assertTrue();
randomaccessfile.closeSync();
fileio.unlinkSync(fpath);
} catch (err) {
console.info('fileio_randomaccessfile_read_sync_001 has failed for ' + err);
expect(null).assertFail();
}
});
/**
* @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_READ_SYNC_0200
* @tc.name fileio_randomaccessfile_read_sync_002
* @tc.desc Test readSync() interface. When the offset is 1. Test to read data synchronously.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('fileio_randomaccessfile_read_sync_002', 0, async function () {
let fpath = await nextFileName('fileio_randomaccessfile_read_sync_002');
try {
let randomaccessfile = fileio.createRandomAccessFileSync(fpath, 0, 0o102);
let length = 4096;
let num = randomaccessfile.writeSync(new ArrayBuffer(length));
expect(num == length).assertTrue();
randomaccessfile.setFilePointerSync(0);
let number = randomaccessfile.readSync(new ArrayBuffer(length), { offset: 1 });
expect(number == length - 1).assertTrue();
randomaccessfile.closeSync();
fileio.unlinkSync(fpath);
} catch (err) {
console.info('fileio_randomaccessfile_read_sync_002 has failed for ' + err);
expect(null).assertFail();
}
});
/**
* @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_READ_SYNC_0300
* @tc.name fileio_randomaccessfile_read_sync_003
* @tc.desc Test readSync() interface. When the offset is 1 and the length is 5. Test to read data synchronously.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('fileio_randomaccessfile_read_sync_003', 0, async function () {
let fpath = await nextFileName('fileio_randomaccessfile_read_sync_003');
try {
let randomaccessfile = fileio.createRandomAccessFileSync(fpath, 0, 0o102);
let length = 4096;
let num = randomaccessfile.writeSync(new ArrayBuffer(length));
expect(num == length).assertTrue();
randomaccessfile.setFilePointerSync(0);
let number = randomaccessfile.readSync(new ArrayBuffer(length), { offset: 1, length: 5 });
expect(number == 5).assertTrue();
randomaccessfile.closeSync();
fileio.unlinkSync(fpath);
} catch (err) {
console.info('fileio_randomaccessfile_read_sync_003 has failed for ' + err);
expect(null).assertFail();
}
});
/**
* @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_READ_SYNC_0400
* @tc.name fileio_randomaccessfile_read_sync_004
* @tc.desc Test readSync() interface. When offset equals buffer length. Test to read data synchronously.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('fileio_randomaccessfile_read_sync_004', 0, async function () {
let fpath = await nextFileName('fileio_randomaccessfile_read_sync_004');
try {
let randomaccessfile = fileio.createRandomAccessFileSync(fpath, 0, 0o102);
let length = 4096;
let num = randomaccessfile.writeSync(new ArrayBuffer(length));
expect(num == length).assertTrue();
randomaccessfile.setFilePointerSync(0);
let number = randomaccessfile.readSync(new ArrayBuffer(length), { offset: length });
expect(number == 0).assertTrue();
randomaccessfile.closeSync();
fileio.unlinkSync(fpath);
} catch (err) {
console.info('fileio_randomaccessfile_read_sync_004 has failed for ' + err);
expect(null).assertFail();
}
});
/**
* @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_READ_SYNC_0500
* @tc.name fileio_randomaccessfile_read_sync_005
* @tc.desc Test readSync() interface. When the offset is 1 and the position is 6. Test to read data synchronously.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('fileio_randomaccessfile_read_sync_005', 0, async function () {
let fpath = await nextFileName('fileio_randomaccessfile_read_sync_005');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let randomaccessfile = fileio.createRandomAccessFileSync(fpath, 0, 0o102);
let length = 4096;
let number = randomaccessfile.readSync(new ArrayBuffer(length), { offset: 1, position: 6 });
expect(number == FILE_CONTENT.length - 6).assertTrue();
randomaccessfile.closeSync();
fileio.unlinkSync(fpath);
} catch (err) {
console.info('fileio_randomaccessfile_read_sync_005 has failed for ' + err);
expect(null).assertFail();
}
});
/**
* @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_READ_SYNC_0600
* @tc.name fileio_randomaccessfile_read_sync_006
* @tc.desc Test readSync() interface. When the offset is negative.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('fileio_randomaccessfile_read_sync_006', 0, async function () {
let fpath = await nextFileName('fileio_randomaccessfile_read_sync_006');
let fd = fileio.openSync(fpath, 0o102, 0o666);
let randomaccessfile = fileio.createRandomAccessFileSync(fd, 0);
try {
randomaccessfile.readSync(new ArrayBuffer(4096), { offset: -1 });
} catch (err) {
console.info('fileio_randomaccessfile_read_sync_006 has failed for ' + err);
expect(err.message == "Invalid buffer/options").assertTrue();
randomaccessfile.closeSync();
fileio.unlinkSync(fpath);
}
});
/**
* @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_READ_SYNC_0700
* @tc.name fileio_randomaccessfile_read_sync_007
* @tc.desc Test readSync() interface. When offset+length>buffer.size.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('fileio_randomaccessfile_read_sync_007', 0, async function () {
let fpath = await nextFileName('fileio_randomaccessfile_read_sync_007');
let randomaccessfile = fileio.createRandomAccessFileSync(fpath, 0, 0o102);
try {
randomaccessfile.readSync(new ArrayBuffer(4096), { offset: 1, length: 4096 });
} catch (err) {
console.info('fileio_randomaccessfile_read_sync_007 has failed for ' + err);
expect(err.message == "Invalid buffer/options").assertTrue();
randomaccessfile.closeSync();
fileio.unlinkSync(fpath);
}
});
/**
* @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_READ_SYNC_0800
* @tc.name fileio_randomaccessfile_read_sync_008
* @tc.desc Test readSync() interface. When the offset is greater than the buffer length.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('fileio_randomaccessfile_read_sync_008', 0, async function () {
let fpath = await nextFileName('fileio_randomaccessfile_read_sync_008');
let randomaccessfile = fileio.createRandomAccessFileSync(fpath, 0, 0o102);
try {
let length = 4096;
randomaccessfile.readSync(new ArrayBuffer(length), { offset: length + 1 });
} catch (err) {
console.info('fileio_randomaccessfile_read_sync_008 has failed for ' + err);
expect(err.message == "Invalid buffer/options").assertTrue();
randomaccessfile.closeSync();
fileio.unlinkSync(fpath);
}
});
/**
* @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_READ_SYNC_0900
* @tc.name fileio_randomaccessfile_read_sync_009
* @tc.desc Test readSync() interface. When the length is greater than the buffer length.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('fileio_randomaccessfile_read_sync_009', 0, async function () {
let fpath = await nextFileName('fileio_randomaccessfile_read_sync_009');
let randomaccessfile = fileio.createRandomAccessFileSync(fpath, 0, 0o102);
try {
let length = 4096;
randomaccessfile.readSync(new ArrayBuffer(length), { length: length + 1 });
} catch (err) {
console.info('fileio_randomaccessfile_read_sync_009 has failed for ' + err);
expect(err.message == "Invalid buffer/options").assertTrue();
randomaccessfile.closeSync();
fileio.unlinkSync(fpath);
}
});
/**
* @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_READ_SYNC_1000
* @tc.name fileio_randomaccessfile_read_sync_010
* @tc.desc Test readSync() interface. When the length is negative,equivalent to omitting the parameter.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('fileio_randomaccessfile_read_sync_010', 0, async function () {
let fpath = await nextFileName('fileio_randomaccessfile_read_sync_010');
try {
let randomaccessfile = fileio.createRandomAccessFileSync(fpath, 0, 0o102);
let length = 4096;
let num = randomaccessfile.writeSync(new ArrayBuffer(length));
expect(num == length).assertTrue();
randomaccessfile.setFilePointerSync(0);
let number = randomaccessfile.readSync(new ArrayBuffer(16), { offset: 13, length: -1 });
expect(number == 3).assertTrue();
randomaccessfile.closeSync();
fileio.unlinkSync(fpath);
} catch (err) {
console.info('fileio_randomaccessfile_read_sync_010 has failed for ' + err);
expect(null).assertFail();
}
});
/**
* @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_READ_SYNC_1100
* @tc.name fileio_randomaccessfile_read_sync_011
* @tc.desc Test readSync() interface. When there are no parameters.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('fileio_randomaccessfile_read_sync_011', 0, async function () {
let fpath = await nextFileName('fileio_randomaccessfile_read_sync_011');
let randomaccessfile = fileio.createRandomAccessFileSync(fpath, 0, 0o102);
try {
randomaccessfile.readSync();
} catch (err) {
console.info('fileio_randomaccessfile_read_sync_011 has failed for ' + err);
expect(err.message == "Number of arguments unmatched").assertTrue();
randomaccessfile.closeSync();
fileio.unlinkSync(fpath);
}
});
/**
* @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_READ_SYNC_1200
* @tc.name fileio_randomaccessfile_read_sync_012
* @tc.desc Test readSync() interface. When the position is negative.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('fileio_randomaccessfile_read_sync_012', 0, async function () {
let fpath = await nextFileName('fileio_randomaccessfile_read_sync_012');
let randomaccessfile = fileio.createRandomAccessFileSync(fpath, 0, 0o102);
try {
randomaccessfile.readSync(new ArrayBuffer(4096), { position: -1 });
} catch (err) {
console.info('fileio_randomaccessfile_read_sync_012 has failed for ' + err);
expect(err.message == "Invalid buffer/options").assertTrue();
randomaccessfile.closeSync();
fileio.unlinkSync(fpath);
}
});
/**
* @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_READ_SYNC_1200
* @tc.name fileio_randomaccessfile_read_sync_012
* @tc.desc Test readSync() interface. When the parameter type is wrong.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('fileio_randomaccessfile_read_sync_013', 0, async function () {
let fpath = await nextFileName('fileio_randomaccessfile_read_sync_013');
let randomaccessfile = fileio.createRandomAccessFileSync(fpath, 0, 0o102);
try {
randomaccessfile.readSync('');
} catch (err) {
console.info('fileio_randomaccessfile_read_sync_013 has failed for ' + err);
expect(err.message == "Invalid buffer/options").assertTrue();
randomaccessfile.closeSync();
fileio.unlinkSync(fpath);
}
});
/**
* @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_READ_ASYNC_0000
* @tc.name fileio_randomaccessfile_read_async_000
* @tc.desc Test read() interface. return in callback mode. Test to read data asynchronously.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('fileio_randomaccessfile_read_async_000', 0, async function (done) {
let fpath = await nextFileName('fileio_randomaccessfile_read_async_000');
try {
let randomaccessfile = await fileio.createRandomAccessFile(fpath, 0, 0o102);
let length = 4096;
let num = await randomaccessfile.write(new ArrayBuffer(length));
expect(num == length).assertTrue();
randomaccessfile.setFilePointerSync(0);
randomaccessfile.read(new ArrayBuffer(length), function (err, readOut) {
expect(readOut.bytesRead == length).assertTrue();
randomaccessfile.closeSync();
fileio.unlinkSync(fpath);
done();
});
} catch (err) {
console.info('fileio_randomaccessfile_read_async_000 has failed for ' + err);
expect(null).assertFail();
}
});
/**
* @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_READ_ASYNC_0100
* @tc.name fileio_randomaccessfile_read_async_001
* @tc.desc Test read() interface. When the position is 1. Test to read data asynchronously.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('fileio_randomaccessfile_read_async_001', 0, async function (done) {
let fpath = await nextFileName('fileio_randomaccessfile_read_async_001');
try {
fileio.createRandomAccessFile(fpath, 0, 0o102, async function (err, randomaccessfile) {
let length = 4096;
let num = await randomaccessfile.write(new ArrayBuffer(length));
expect(num == length).assertTrue();
randomaccessfile.setFilePointerSync(0);
let readOut = await randomaccessfile.read(new ArrayBuffer(length), { position: 1 });
expect(readOut.bytesRead == length - 1).assertTrue();
randomaccessfile.closeSync();
fileio.unlinkSync(fpath);
done();
});
} catch (err) {
console.info('fileio_randomaccessfile_read_async_001 has failed for ' + err);
expect(null).assertFail();
}
});
/**
* @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_READ_ASYNC_0200
* @tc.name fileio_randomaccessfile_read_async_002
* @tc.desc Test read() interface. When the offset is 1. Test to read data asynchronously.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('fileio_randomaccessfile_read_async_002', 0, async function (done) {
let fpath = await nextFileName('fileio_randomaccessfile_read_async_002');
try {
let fd = fileio.openSync(fpath, 0o102, 0o666);
let randomaccessfile = await fileio.createRandomAccessFile(fd, 0);
let length = 4096;
let num = await randomaccessfile.write(new ArrayBuffer(length));
expect(num == length).assertTrue();
randomaccessfile.setFilePointerSync(0);
let readOut = await randomaccessfile.read(new ArrayBuffer(length), { offset: 1 });
expect(readOut.bytesRead == length - 1).assertTrue();
expect(readOut.offset == 1).assertTrue();
randomaccessfile.closeSync();
fileio.unlinkSync(fpath);
done();
} catch (err) {
console.info('fileio_randomaccessfile_read_async_002 has failed for ' + err);
expect(null).assertFail();
}
});
/**
* @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_READ_ASYNC_0300
* @tc.name fileio_randomaccessfile_read_async_003
* @tc.desc Test read() interface. When the offset is 1 and the length is 5. Test to read data asynchronously.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('fileio_randomaccessfile_read_async_003', 0, async function (done) {
let fpath = await nextFileName('fileio_randomaccessfile_read_async_003');
try {
let randomaccessfile = await fileio.createRandomAccessFile(fpath, 0, 0o102);
let length = 4096;
let num = await randomaccessfile.write(new ArrayBuffer(length));
expect(num == length).assertTrue();
randomaccessfile.setFilePointerSync(0);
randomaccessfile.read(new ArrayBuffer(length), { offset: 1, length: 5 }, function (err, readOut) {
expect(readOut.bytesRead == 5).assertTrue();
expect(readOut.offset == 1).assertTrue();
randomaccessfile.closeSync();
fileio.unlinkSync(fpath);
done();
});
} catch (err) {
console.info('fileio_randomaccessfile_read_async_003 has failed for ' + err);
expect(null).assertFail();
}
});
/**
* @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_READ_ASYNC_0400
* @tc.name fileio_randomaccessfile_read_async_004
* @tc.desc Test read() interface. When offset equals buffer length. Test to read data asynchronously.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('fileio_randomaccessfile_read_async_004', 0, async function (done) {
let fpath = await nextFileName('fileio_randomaccessfile_read_async_004');
try {
let randomaccessfile = await fileio.createRandomAccessFile(fpath, 0, 0o102);
let length = 4096;
let num = await randomaccessfile.write(new ArrayBuffer(length));
expect(num == length).assertTrue();
randomaccessfile.setFilePointerSync(0);
let readOut = await randomaccessfile.read(new ArrayBuffer(length), { offset: length });
expect(readOut.bytesRead == 0).assertTrue();
expect(readOut.offset == 4096).assertTrue();
randomaccessfile.closeSync();
fileio.unlinkSync(fpath);
done();
} catch (err) {
console.info('fileio_randomaccessfile_read_async_004 has failed for ' + err);
expect(null).assertFail();
}
});
/**
* @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_READ_ASYNC_0500
* @tc.name fileio_randomaccessfile_read_async_005
* @tc.desc Test read() interface. When the offset is 1 and the position is 6. Test to read data asynchronously.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('fileio_randomaccessfile_read_async_005', 0, async function (done) {
let fpath = await nextFileName('fileio_randomaccessfile_read_async_005');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let randomaccessfile = await fileio.createRandomAccessFile(fpath, 0, 0o102);
let length = 4096;
let readOut = await randomaccessfile.read(new ArrayBuffer(length), { offset: 1, position: 6 });
expect(readOut.bytesRead == FILE_CONTENT.length - 6).assertTrue();
expect(readOut.offset == 1).assertTrue();
let start = readOut.offset;
let end = readOut.offset + readOut.bytesRead;
let result = String.fromCharCode.apply(null, new Uint8Array(readOut.buffer.slice(start, end)));
expect(result == "world").assertTrue();
randomaccessfile.closeSync();
fileio.unlinkSync(fpath);
done();
} catch (err) {
console.info('fileio_randomaccessfile_read_async_005 has failed for ' + err);
expect(null).assertFail();
}
});
/**
* @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_READ_ASYNC_0600
* @tc.name fileio_randomaccessfile_read_async_006
* @tc.desc Test read() interface. When the offset is negative.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('fileio_randomaccessfile_read_async_006', 0, async function (done) {
let fpath = await nextFileName('fileio_randomaccessfile_read_async_006');
let randomaccessfile = await fileio.createRandomAccessFile(fpath, 0, 0o102);
try {
await randomaccessfile.read(new ArrayBuffer(4096), { offset: -1 });
} catch (err) {
console.info('fileio_randomaccessfile_read_async_006 has failed for ' + err);
expect(err.message == "Invalid buffer/options").assertTrue();
randomaccessfile.closeSync();
fileio.unlinkSync(fpath);
done();
}
});
/**
* @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_READ_ASYNC_0700
* @tc.name fileio_randomaccessfile_read_async_007
* @tc.desc Test read() interface. When offset+length>buffer.size.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('fileio_randomaccessfile_read_async_007', 0, async function (done) {
let fpath = await nextFileName('fileio_randomaccessfile_read_async_007');
let randomaccessfile = await fileio.createRandomAccessFile(fpath, 0, 0o102);
try {
await randomaccessfile.read(new ArrayBuffer(4096), { offset: 1, length: 4096 });
} catch (err) {
console.info('fileio_randomaccessfile_read_async_007 has failed for ' + err);
expect(err.message == "Invalid buffer/options").assertTrue();
randomaccessfile.closeSync();
fileio.unlinkSync(fpath);
done();
}
});
/**
* @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_READ_ASYNC_0800
* @tc.name fileio_randomaccessfile_read_async_008
* @tc.desc Test read() interface. When the offset is greater than the buffer length.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('fileio_randomaccessfile_read_async_008', 0, async function (done) {
let fpath = await nextFileName('fileio_randomaccessfile_read_async_008');
let fd = fileio.openSync(fpath, 0o102, 0o666);
let randomaccessfile = await fileio.createRandomAccessFile(fd, 0);
try {
let length = 4096;
randomaccessfile.read(new ArrayBuffer(length), { offset: length + 1 }, function (err) {
});
} catch (err) {
console.info('fileio_randomaccessfile_read_async_008 has failed for ' + err);
expect(err.message == "Invalid buffer/options").assertTrue();
randomaccessfile.closeSync();
fileio.unlinkSync(fpath);
done();
}
});
/**
* @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_READ_ASYNC_0900
* @tc.name fileio_randomaccessfile_read_async_009
* @tc.desc Test read() interface. When the length is greater than the buffer length.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('fileio_randomaccessfile_read_async_009', 0, async function (done) {
let fpath = await nextFileName('fileio_randomaccessfile_read_async_009');
let randomaccessfile = await fileio.createRandomAccessFile(fpath, 0, 0o102);
try {
let length = 4096;
await randomaccessfile.read(new ArrayBuffer(length), { length: length + 1 });
} catch (err) {
console.info('fileio_randomaccessfile_read_async_009 has failed for ' + err);
expect(err.message == "Invalid buffer/options").assertTrue();
randomaccessfile.closeSync();
fileio.unlinkSync(fpath);
done();
}
});
/**
* @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_READ_ASYNC_1000
* @tc.name fileio_randomaccessfile_read_async_010
* @tc.desc Test read() interface. When the length is negative,equivalent to omitting the parameter.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('fileio_randomaccessfile_read_async_010', 0, async function (done) {
let fpath = await nextFileName('fileio_randomaccessfile_read_async_010');
try {
let randomaccessfile = await fileio.createRandomAccessFile(fpath, 0, 0o102);
let length = 4096;
let num = randomaccessfile.writeSync(new ArrayBuffer(length));
expect(num == length).assertTrue();
randomaccessfile.setFilePointerSync(0);
let readOut = await randomaccessfile.read(new ArrayBuffer(16), { offset: 13, length: -1 });
expect(readOut.bytesRead == 3).assertTrue();
randomaccessfile.closeSync();
fileio.unlinkSync(fpath);
done();
} catch (err) {
console.info('fileio_randomaccessfile_read_async_010 has failed for ' + err);
expect(null).assertFail();
}
});
/**
* @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_READ_ASYNC_1100
* @tc.name fileio_randomaccessfile_read_async_011
* @tc.desc Test read() interface. When there are no parameters.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('fileio_randomaccessfile_read_async_011', 0, async function (done) {
let fpath = await nextFileName('fileio_randomaccessfile_read_async_011');
let randomaccessfile = await fileio.createRandomAccessFile(fpath, 0, 0o102);
try {
await randomaccessfile.read();
} catch (err) {
console.info('fileio_randomaccessfile_read_async_011 has failed for ' + err);
expect(err.message == "Number of arguments unmatched").assertTrue();
randomaccessfile.closeSync();
fileio.unlinkSync(fpath);
done();
}
});
/**
* @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_READ_ASYNC_1200
* @tc.name fileio_randomaccessfile_read_async_012
* @tc.desc Test read() interface. When the position is negative.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('fileio_randomaccessfile_read_async_012', 0, async function (done) {
let fpath = await nextFileName('fileio_randomaccessfile_read_async_012');
let randomaccessfile = await fileio.createRandomAccessFile(fpath, 0, 0o102);
try {
await randomaccessfile.read(new ArrayBuffer(4096), { position: -1 });
} catch (err) {
console.info('fileio_randomaccessfile_read_async_012 has failed for ' + err);
expect(err.message == "Invalid buffer/options").assertTrue();
randomaccessfile.closeSync();
fileio.unlinkSync(fpath);
done();
}
});
/**
* @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_READ_ASYNC_1300
* @tc.name fileio_randomaccessfile_read_async_013
* @tc.desc Test read() interface. When the parameter type is wrong.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('fileio_randomaccessfile_read_async_013', 0, async function (done) {
let fpath = await nextFileName('fileio_randomaccessfile_read_async_013');
let randomaccessfile = await fileio.createRandomAccessFile(fpath, 0, 0o102);
try {
await randomaccessfile.read('');
} catch (err) {
console.info('fileio_randomaccessfile_read_async_013 has failed for ' + err);
expect(err.message == "Invalid buffer/options").assertTrue();
randomaccessfile.closeSync();
fileio.unlinkSync(fpath);
done()
}
});
})
}
\ No newline at end of file
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the 'License');
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an 'AS IS' BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {
fileio, nextFileName, describe, it, expect
} from '../../Common';
export default function fileioRandomAccessFileSetFilePointer() {
describe('fileio_randomAccessFile_setFilePointer', function () {
/**
* @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_SET_FILE_POINTER_SYNC_0000
* @tc.name fileio_randomaccessfile_set_file_pointer_sync_000
* @tc.desc Test setFilePointerSync() interface. Set file offset pointer position.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('fileio_randomaccessfile_set_file_pointer_sync_000', 0, async function () {
let fpath = await nextFileName('fileio_randomaccessfile_set_file_pointer_sync_000');
try {
let randomaccessfile = fileio.createRandomAccessFileSync(fpath, 0, 0o102);
expect(randomaccessfile.fpointer == 0).assertTrue();
randomaccessfile.setFilePointerSync(5);
expect(randomaccessfile.fpointer == 5).assertTrue();
randomaccessfile.closeSync();
fileio.unlinkSync(fpath);
} catch(err) {
console.info('fileio_randomaccessfile_set_file_pointer_sync_000 has failed for ' + err);
expect(null).assertFail();
}
});
/**
* @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_SET_FILE_POINTER_SYNC_0100
* @tc.name fileio_randomaccessfile_set_file_pointer_sync_001
* @tc.desc Test setFilePointerSync() interface. Invalid fpointer.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('fileio_randomaccessfile_set_file_pointer_sync_001', 0, async function () {
let fpath = await nextFileName('fileio_randomaccessfile_set_file_pointer_sync_001');
let randomaccessfile = fileio.createRandomAccessFileSync(fpath, 0, 0o102);
try {
randomaccessfile.setFilePointerSync('5');
} catch(err) {
console.info('fileio_randomaccessfile_set_file_pointer_sync_001 has failed for ' + err);
expect(err.message == "Invalid fpointer").assertTrue();
randomaccessfile.closeSync();
fileio.unlinkSync(fpath);
}
});
/**
* @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_SET_FILE_POINTER_SYNC_0200
* @tc.name fileio_randomaccessfile_set_file_pointer_sync_002
* @tc.desc Test setFilePointerSync() interface. Missing Parameter.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('fileio_randomaccessfile_set_file_pointer_sync_002', 0, async function () {
let fpath = await nextFileName('fileio_randomaccessfile_set_file_pointer_sync_002');
let randomaccessfile = fileio.createRandomAccessFileSync(fpath, 0, 0o102);
try {
randomaccessfile.setFilePointerSync();
} catch(err) {
console.info('fileio_randomaccessfile_set_file_pointer_sync_002 has failed for ' + err);
expect(err.message == "Number of arguments unmatched").assertTrue();
randomaccessfile.closeSync();
fileio.unlinkSync(fpath);
}
});
})
}
\ No newline at end of file
/*
* Copyright (C) 2021 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, prepareFile, FILE_CONTENT, nextFileName,
describe, it, expect
} from '../../Common';
export default function fileioRandomAccessFileWrite() {
describe('fileio_randomAccessFile_write', function () {
/**
* @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_WRITE_SYNC_0000
* @tc.name fileio_randomaccessfile_write_sync_000
* @tc.desc Test writeSync() interface. Test write data synchronously.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('fileio_randomaccessfile_write_sync_000', 0, async function () {
let fpath = await nextFileName('fileio_randomaccessfile_write_sync_000');
try {
let randomaccessfile = fileio.createRandomAccessFileSync(fpath, 0, 0o102);
let length = 4096;
let num = randomaccessfile.writeSync(new ArrayBuffer(length));
expect(num == length).assertTrue();
randomaccessfile.closeSync();
fileio.unlinkSync(fpath);
} catch(err) {
console.info('fileio_randomaccessfile_write_sync_000 has failed for ' + err);
expect(null).assertFail();
}
});
/**
* @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_WRITE_SYNC_0100
* @tc.name fileio_randomaccessfile_write_sync_001
* @tc.desc Test writeSync() interface. When the offset is 1. Test write data synchronously.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('fileio_randomaccessfile_write_sync_001', 0, async function () {
let fpath = await nextFileName('fileio_randomaccessfile_write_sync_001');
try {
let randomaccessfile = fileio.createRandomAccessFileSync(fpath, 0, 0o102);
let length = 4096;
let num = randomaccessfile.writeSync(new ArrayBuffer(length), { offset: 1 });
expect(num == length - 1).assertTrue();
randomaccessfile.closeSync();
fileio.unlinkSync(fpath);
} catch(err) {
console.info('fileio_randomaccessfile_write_sync_001 has failed for ' + err);
expect(null).assertFail();
}
});
/**
* @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_WRITE_SYNC_0200
* @tc.name fileio_randomaccessfile_write_sync_002
* @tc.desc Test writeSync() interface. When the position is 1. Test write data synchronously.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('fileio_randomaccessfile_write_sync_002', 0, async function () {
let fpath = await nextFileName('fileio_randomaccessfile_write_sync_002');
try {
let fd = fileio.openSync(fpath, 0o102, 0o666);
let randomaccessfile = fileio.createRandomAccessFileSync(fd, 0);
let length = 4096;
let num = randomaccessfile.writeSync(new ArrayBuffer(length), { position: 1 });
expect(num == length).assertTrue();
randomaccessfile.closeSync();
fileio.unlinkSync(fpath);
} catch(err) {
console.info('fileio_randomaccessfile_write_sync_002 has failed for ' + err);
expect(null).assertFail();
}
});
/**
* @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_WRITE_SYNC_0300
* @tc.name fileio_randomaccessfile_write_sync_003
* @tc.desc Test writeSync() interface. When the offset is 1 and length is 10. Test write data synchronously.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('fileio_randomaccessfile_write_sync_003', 0, async function () {
let fpath = await nextFileName('fileio_randomaccessfile_write_sync_003');
try {
let randomaccessfile = fileio.createRandomAccessFileSync(fpath, 0, 0o102);
let length = 4096;
let num = randomaccessfile.writeSync(new ArrayBuffer(length), { offset: 1, length: 10 });
expect(num == 10).assertTrue();
randomaccessfile.closeSync();
fileio.unlinkSync(fpath);
} catch(err) {
console.info('fileio_randomaccessfile_write_sync_003 has failed for ' + err);
expect(null).assertFail();
}
});
/**
* @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_WRITE_SYNC_0400
* @tc.name fileio_randomaccessfile_write_sync_004
* @tc.desc Test writeSync() interface. When the offset is 1 and position is 5. Test write data synchronously.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('fileio_randomaccessfile_write_sync_004', 0, async function () {
let fpath = await nextFileName('fileio_randomaccessfile_write_sync_004');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let randomaccessfile = fileio.createRandomAccessFileSync(fpath, 0, 0o102);
let length = 20;
let options = {
offset: 1,
position:5
}
let num = randomaccessfile.writeSync(new ArrayBuffer(length), options);
expect(num == length - 1).assertTrue();
randomaccessfile.setFilePointerSync(0);
let number = randomaccessfile.readSync(new ArrayBuffer(4096));
expect(number == (length - options.offset + options.position)).assertTrue();
randomaccessfile.closeSync();
fileio.unlinkSync(fpath);
} catch(err) {
console.info('fileio_randomaccessfile_write_sync_004 has failed for ' + err);
expect(null).assertFail();
}
});
/**
* @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_WRITE_SYNC_0500
* @tc.name fileio_randomaccessfile_write_sync_005
* @tc.desc Test writeSync() interface. When offset equals buffer length. Test write data synchronously.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('fileio_randomaccessfile_write_sync_005', 0, async function () {
let fpath = await nextFileName('fileio_randomaccessfile_write_sync_005');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let randomaccessfile = fileio.createRandomAccessFileSync(fpath, 0, 0o102);
let length = 4096;
let num = randomaccessfile.writeSync(new ArrayBuffer(length), { offset: length });
expect(num == 0).assertTrue();
randomaccessfile.closeSync();
fileio.unlinkSync(fpath);
} catch(err) {
console.info('fileio_randomaccessfile_write_sync_005 has failed for ' + err);
expect(null).assertFail();
}
});
/**
* @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_WRITE_SYNC_0600
* @tc.name fileio_randomaccessfile_write_sync_006
* @tc.desc Test writeSync() interface. When offset+length>buffer.size.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('fileio_randomaccessfile_write_sync_006', 0, async function () {
let fpath = await nextFileName('fileio_randomaccessfile_write_sync_006');
let randomaccessfile = fileio.createRandomAccessFileSync(fpath, 0, 0o102);
try {
randomaccessfile.writeSync(new ArrayBuffer(4096), { offset: 5, length: 4095 });
} catch(err) {
console.info('fileio_randomaccessfile_write_sync_006 has failed for ' + err);
expect(err.message == "Invalid buffer/options").assertTrue();
randomaccessfile.closeSync();
fileio.unlinkSync(fpath);
}
});
/**
* @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_WRITE_SYNC_0700
* @tc.name fileio_randomaccessfile_write_sync_007
* @tc.desc Test writeSync() interface. When the offset is greater than the buffer length.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('fileio_randomaccessfile_write_sync_007', 0, async function () {
let fpath = await nextFileName('fileio_randomaccessfile_write_sync_007');
let randomaccessfile = fileio.createRandomAccessFileSync(fpath, 0, 0o102);
try {
let length = 4096;
randomaccessfile.writeSync(new ArrayBuffer(length), { offset: length + 1 });
} catch(err) {
console.info('fileio_randomaccessfile_write_sync_007 has failed for ' + err);
expect(err.message == "Invalid buffer/options").assertTrue();
randomaccessfile.closeSync();
fileio.unlinkSync(fpath);
}
});
/**
* @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_WRITE_SYNC_0800
* @tc.name fileio_randomaccessfile_write_sync_008
* @tc.desc Test writeSync() interface. When there are no parameters.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('fileio_randomaccessfile_write_sync_008', 0, async function () {
let fpath = await nextFileName('fileio_randomaccessfile_write_sync_008');
let randomaccessfile = fileio.createRandomAccessFileSync(fpath, 0, 0o102);
try {
randomaccessfile.writeSync();
} catch(err) {
console.info('fileio_randomaccessfile_write_sync_008 has failed for ' + err);
expect(err.message == "Number of arguments unmatched").assertTrue();
randomaccessfile.closeSync();
fileio.unlinkSync(fpath);
}
});
/**
* @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_WRITE_SYNC_0900
* @tc.name fileio_randomaccessfile_write_sync_009
* @tc.desc Test writeSync() interface. When the offset is negative.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('fileio_randomaccessfile_write_sync_009', 0, async function () {
let fpath = await nextFileName('fileio_randomaccessfile_write_sync_009');
let fd = fileio.openSync(fpath, 0o102, 0o666);
let randomaccessfile = fileio.createRandomAccessFileSync(fd, 0);
try {
randomaccessfile.writeSync(new ArrayBuffer(4096), { offset: -1 });
} catch(err) {
console.info('fileio_randomaccessfile_write_sync_009 has failed for ' + err);
expect(err.message == "Invalid buffer/options").assertTrue();
randomaccessfile.closeSync();
fileio.unlinkSync(fpath);
}
});
/**
* @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_WRITE_SYNC_1000
* @tc.name fileio_randomaccessfile_write_sync_010
* @tc.desc Test writeSync() interface. When the length is negative,equivalent to omitting the parameter.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('fileio_randomaccessfile_write_sync_010', 0, async function () {
let fpath = await nextFileName('fileio_randomaccessfile_write_sync_010');
try {
let randomaccessfile = fileio.createRandomAccessFileSync(fpath, 0, 0o102);
let length = 100;
let num = randomaccessfile.writeSync(new ArrayBuffer(length), { offset: 1, length: -1 });
expect(num == length - 1).assertTrue();
randomaccessfile.closeSync();
fileio.unlinkSync(fpath);
} catch(err) {
console.info('fileio_randomaccessfile_write_sync_010 has failed for ' + err);
expect(null).assertFail();
}
});
/**
* @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_WRITE_SYNC_1100
* @tc.name fileio_randomaccessfile_write_sync_011
* @tc.desc Test writeSync() interface. When the buffer parameter type is wrong.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('fileio_randomaccessfile_write_sync_011', 0, async function () {
let fpath = await nextFileName('fileio_randomaccessfile_write_sync_011');
let randomaccessfile = fileio.createRandomAccessFileSync(fpath, 0, 0o102);
try {
randomaccessfile.writeSync(10, { length: -1 });
} catch(err) {
console.info('fileio_randomaccessfile_write_sync_011 has failed for ' + err);
expect(err.message == "Invalid buffer/options").assertTrue();
randomaccessfile.closeSync();
fileio.unlinkSync(fpath);
}
});
/**
* @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_WRITE_SYNC_1200
* @tc.name fileio_randomaccessfile_write_sync_012
* @tc.desc Test writeSync() interface. When the length is greater than the buffer length.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('fileio_randomaccessfile_write_sync_012', 0, async function () {
let fpath = await nextFileName('fileio_randomaccessfile_write_sync_012');
let randomaccessfile = fileio.createRandomAccessFileSync(fpath, 0, 0o102);
try {
let length = 4096;
randomaccessfile.writeSync(new ArrayBuffer(length), { length: length + 1 });
} catch(err) {
console.info('fileio_randomaccessfile_write_sync_012 has failed for ' + err);
expect(err.message == "Invalid buffer/options").assertTrue();
randomaccessfile.closeSync();
fileio.unlinkSync(fpath);
}
});
/**
* @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_WRITE_SYNC_1300
* @tc.name fileio_randomaccessfile_write_sync_013
* @tc.desc Test writeSync() interface. When the position is negative.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('fileio_randomaccessfile_write_sync_013', 0, async function () {
let fpath = await nextFileName('fileio_randomaccessfile_write_sync_013');
let randomaccessfile = fileio.createRandomAccessFileSync(fpath, 0, 0o102);
try {
randomaccessfile.writeSync(new ArrayBuffer(4096), { position: -1 });
} catch(err) {
console.info('fileio_randomaccessfile_write_sync_013 has failed for ' + err);
expect(err.message == "Invalid buffer/options").assertTrue();
randomaccessfile.closeSync();
fileio.unlinkSync(fpath);
}
});
/**
* @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_WRITE_ASYNC_0000
* @tc.name fileio_randomaccessfile_write_async_000
* @tc.desc Test write() interface. return in promise mode. Test write data asynchronously.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('fileio_randomaccessfile_write_async_000', 0, async function (done) {
let fpath = await nextFileName('fileio_randomaccessfile_write_async_000');
try {
fileio.createRandomAccessFile(fpath, 0, 0o102, async function(err, randomaccessfile) {
let length = 4096;
let num = await randomaccessfile.write(new ArrayBuffer(length));
expect(num == length).assertTrue();
randomaccessfile.closeSync();
fileio.unlinkSync(fpath);
done();
});
} catch(err) {
console.info('fileio_randomaccessfile_write_async_000 has failed for ' + err);
expect(null).assertFail();
}
});
/**
* @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_WRITE_ASYNC_0100
* @tc.name fileio_randomaccessfile_write_async_001
* @tc.desc Test write() interface. When the offset is 1. return in callback mode. Test write data asynchronously.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('fileio_randomaccessfile_write_async_001', 0, async function (done) {
let fpath = await nextFileName('fileio_randomaccessfile_write_async_001');
try {
let fd = fileio.openSync(fpath, 0o102, 0o666);
let randomaccessfile = await fileio.createRandomAccessFile(fd, 0);
let length = 4096;
randomaccessfile.write(new ArrayBuffer(length), { offset: 1 }, function(err, bytesWritten) {
expect(bytesWritten == length - 1).assertTrue();
randomaccessfile.closeSync();
fileio.unlinkSync(fpath);
done();
});
} catch(err) {
console.info('fileio_randomaccessfile_write_async_001 has failed for ' + err);
expect(null).assertFail();
}
});
/**
* @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_WRITE_ASYNC_0200
* @tc.name fileio_randomaccessfile_write_async_002
* @tc.desc Test write() interface. When the position is 1. Test write data asynchronously.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('fileio_randomaccessfile_write_async_002', 0, async function (done) {
let fpath = await nextFileName('fileio_randomaccessfile_write_async_002');
try {
let randomaccessfile = await fileio.createRandomAccessFile(fpath, 0, 0o102);
let length = 4096;
let num = await randomaccessfile.write(new ArrayBuffer(length), { position: 1 });
expect(num == length).assertTrue();
randomaccessfile.closeSync();
fileio.unlinkSync(fpath);
done();
} catch(err) {
console.info('fileio_randomaccessfile_write_async_002 has failed for ' + err);
expect(null).assertFail();
}
});
/**
* @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_WRITE_ASYNC_0300
* @tc.name fileio_randomaccessfile_write_async_003
* @tc.desc Test write() interface. When the offset is 1 and length is 10. Test write data asynchronously.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('fileio_randomaccessfile_write_async_003', 0, async function (done) {
let fpath = await nextFileName('fileio_randomaccessfile_write_async_003');
try {
let randomaccessfile = await fileio.createRandomAccessFile(fpath, 0, 0o102);
let length = 4096;
let num = await randomaccessfile.write(new ArrayBuffer(length), { offset: 1, length: 10 });
expect(num == 10).assertTrue();
randomaccessfile.closeSync();
fileio.unlinkSync(fpath);
done();
} catch(err) {
console.info('fileio_randomaccessfile_write_async_003 has failed for ' + err);
expect(null).assertFail();
}
});
/**
* @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_WRITE_ASYNC_0400
* @tc.name fileio_randomaccessfile_write_async_004
* @tc.desc Test write() interface. When the offset is 1 and position is 5. Test write data asynchronously.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('fileio_randomaccessfile_write_async_004', 0, async function (done) {
let fpath = await nextFileName('fileio_randomaccessfile_write_async_004');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let randomaccessfile = await fileio.createRandomAccessFile(fpath, 0, 0o102);
let length = 20;
let options = {
offset: 1,
position:5
}
let num = await randomaccessfile.write(new ArrayBuffer(length), options);
expect(num == length - 1).assertTrue();
randomaccessfile.setFilePointerSync(0);
let readOut = await randomaccessfile.read(new ArrayBuffer(4096));
expect(readOut.bytesRead == (length - options.offset + options.position)).assertTrue();
randomaccessfile.closeSync();
fileio.unlinkSync(fpath);
done();
} catch(err) {
console.info('fileio_randomaccessfile_write_async_004 has failed for ' + err);
expect(null).assertFail();
}
});
/**
* @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_WRITE_ASYNC_0500
* @tc.name fileio_randomaccessfile_write_async_005
* @tc.desc Test write() interface. When offset equals buffer length. Test write data asynchronously.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('fileio_randomaccessfile_write_async_005', 0, async function (done) {
let fpath = await nextFileName('fileio_randomaccessfile_write_async_005');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let randomaccessfile = await fileio.createRandomAccessFile(fpath, 0, 0o102);
let length = 4096;
let num = await randomaccessfile.write(new ArrayBuffer(length), { offset: length });
expect(num == 0).assertTrue();
randomaccessfile.closeSync();
fileio.unlinkSync(fpath);
done();
} catch(err) {
console.info('fileio_randomaccessfile_write_async_005 has failed for ' + err);
expect(null).assertFail();
}
});
/**
* @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_WRITE_ASYNC_0600
* @tc.name fileio_randomaccessfile_write_async_006
* @tc.desc Test write() interface. When offset+length>buffer.size.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('fileio_randomaccessfile_write_async_006', 0, async function (done) {
let fpath = await nextFileName('fileio_randomaccessfile_write_async_006');
let randomaccessfile = await fileio.createRandomAccessFile(fpath, 0, 0o102);
try {
let length = 4096;
await randomaccessfile.write(new ArrayBuffer(length), { offset: 5, length: 4095 });
} catch(err) {
console.info('fileio_randomaccessfile_write_async_006 has failed for ' + err);
expect(err.message == "Invalid buffer/options").assertTrue();
randomaccessfile.closeSync();
fileio.unlinkSync(fpath);
done();
}
});
/**
* @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_WRITE_ASYNC_0700
* @tc.name fileio_randomaccessfile_write_async_007
* @tc.desc Test write() interface. When the offset is greater than the buffer length.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('fileio_randomaccessfile_write_async_007', 0, async function (done) {
let fpath = await nextFileName('fileio_randomaccessfile_write_async_007');
let randomaccessfile = await fileio.createRandomAccessFile(fpath, 0, 0o102);
try {
let length = 4096;
randomaccessfile.write(new ArrayBuffer(length), { offset: length + 1 }, function(err) {
});
} catch(err) {
console.info('fileio_randomaccessfile_write_async_007 has failed for ' + err);
expect(err.message == "Invalid buffer/options").assertTrue();
randomaccessfile.closeSync();
fileio.unlinkSync(fpath);
done();
}
});
/**
* @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_WRITE_ASYNC_0800
* @tc.name fileio_randomaccessfile_write_async_008
* @tc.desc Test write() interface. When there are no parameters.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('fileio_randomaccessfile_write_async_008', 0, async function (done) {
let fpath = await nextFileName('fileio_randomaccessfile_write_async_008');
let randomaccessfile = await fileio.createRandomAccessFile(fpath, 0, 0o102);
try {
await randomaccessfile.write();
} catch(err) {
console.info('fileio_randomaccessfile_write_async_008 has failed for ' + err);
expect(err.message == "Number of arguments unmatched").assertTrue();
randomaccessfile.closeSync();
fileio.unlinkSync(fpath);
done();
}
});
/**
* @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_WRITE_ASYNC_0900
* @tc.name fileio_randomaccessfile_write_async_009
* @tc.desc Test write() interface. When the offset is negative.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('fileio_randomaccessfile_write_async_009', 0, async function (done) {
let fpath = await nextFileName('fileio_randomaccessfile_write_async_009');
let fd = fileio.openSync(fpath, 0o102, 0o666);
let randomaccessfile = await fileio.createRandomAccessFile(fd, 0);
try {
await randomaccessfile.write(new ArrayBuffer(4096), { offset: -1 });
} catch(err) {
console.info('fileio_randomaccessfile_write_async_009 has failed for ' + err);
expect(err.message == "Invalid buffer/options").assertTrue();
randomaccessfile.closeSync();
fileio.unlinkSync(fpath);
done();
}
});
/**
* @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_WRITE_ASYNC_1000
* @tc.name fileio_randomaccessfile_write_async_010
* @tc.desc Test write() interface. When the length is negative,equivalent to omitting the parameter.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('fileio_randomaccessfile_write_async_010', 0, async function (done) {
let fpath = await nextFileName('fileio_randomaccessfile_write_async_010');
try {
let randomaccessfile = await fileio.createRandomAccessFile(fpath, 0, 0o102);
let length = 100;
let num = await randomaccessfile.write(new ArrayBuffer(length), { offset: 1, length: -1 });
expect(num == length - 1).assertTrue();
randomaccessfile.closeSync();
fileio.unlinkSync(fpath);
done();
} catch(err) {
console.info('fileio_randomaccessfile_write_async_010 has failed for ' + err);
expect(null).assertFail();
}
});
/**
* @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_WRITE_ASYNC_1100
* @tc.name fileio_randomaccessfile_write_async_011
* @tc.desc Test write() interface. When the buffer parameter type is wrong.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('fileio_randomaccessfile_write_async_011', 0, async function (done) {
let fpath = await nextFileName('fileio_randomaccessfile_write_async_011');
let randomaccessfile = await fileio.createRandomAccessFile(fpath, 0, 0o102);
try {
await randomaccessfile.write(10, { length: -1 });
} catch(err) {
console.info('fileio_randomaccessfile_write_async_011 has failed for ' + err);
expect(err.message == "Invalid buffer/options").assertTrue();
randomaccessfile.closeSync();
fileio.unlinkSync(fpath);
done();
}
});
/**
* @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_WRITE_ASYNC_1200
* @tc.name fileio_randomaccessfile_write_async_012
* @tc.desc Test write() interface. When the length is greater than the buffer length.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('fileio_randomaccessfile_write_async_012', 0, async function (done) {
let fpath = await nextFileName('fileio_randomaccessfile_write_async_012');
let randomaccessfile = await fileio.createRandomAccessFile(fpath, 0, 0o102);
try {
let length = 4096;
await randomaccessfile.write(new ArrayBuffer(length), { length: length + 1 });
} catch(err) {
console.info('fileio_randomaccessfile_write_async_012 has failed for ' + err);
expect(err.message == "Invalid buffer/options").assertTrue();
randomaccessfile.closeSync();
fileio.unlinkSync(fpath);
done();
}
});
/**
* @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_WRITE_ASYNC_1300
* @tc.name fileio_randomaccessfile_write_async_013
* @tc.desc Test write() interface. When the position is negative.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('fileio_randomaccessfile_write_async_013', 0, async function (done) {
let fpath = await nextFileName('fileio_randomaccessfile_write_async_013');
let randomaccessfile = await fileio.createRandomAccessFile(fpath, 0, 0o102);
try {
await randomaccessfile.write(new ArrayBuffer(4096), { position: -1 });
} catch(err) {
console.info('fileio_randomaccessfile_write_async_013 has failed for ' + err);
expect(err.message == "Invalid buffer/options").assertTrue();
randomaccessfile.closeSync();
fileio.unlinkSync(fpath);
done();
}
});
})
}
\ No newline at end of file
/*
* Copyright (C) 2021 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, prepareFile, nextFileName, isIntNum, FILE_CONTENT,
describe, it, expect
} from '../../Common';
export default function fileioCreateRandomAccessFile() {
describe('fileio_create_randomAccessFile', function () {
/**
* @tc.number SUB_STORAGE_FILEIO_CREATE_RANDOMACCESSFILE_SYNC_0000
* @tc.name fileio_create_randomaccessfile_sync_000
* @tc.desc Test createRandomAccessFileSync() interface.
* Create RandomAccessFile object to access file based on file path.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('fileio_create_randomaccessfile_sync_000', 0, async function () {
let fpath = await nextFileName('fileio_create_randomaccessfile_sync_000');
expect(prepareFile(fpath, '')).assertTrue();
try {
let randomaccessfile = fileio.createRandomAccessFileSync(fpath, 0, 0o2);
expect(isIntNum(randomaccessfile.fd)).assertTrue();
randomaccessfile.closeSync();
fileio.unlinkSync(fpath);
} catch(err) {
console.info('fileio_create_randomaccessfile_sync_000 has failed for ' + err);
expect(null).assertFail();
}
});
/**
* @tc.number SUB_STORAGE_FILEIO_CREATE_RANDOMACCESSFILE_SYNC_0100
* @tc.name fileio_create_randomaccessfile_sync_001
* @tc.desc Test createRandomAccessFileSync() interface. fpointer = 5.
* Create RandomAccessFile object to access file from fpointer location.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('fileio_create_randomaccessfile_sync_001', 0, async function () {
let fpath = await nextFileName('fileio_create_randomaccessfile_sync_001');
try {
let randomaccessfile = fileio.createRandomAccessFileSync(fpath, 5, 0o102);
expect(isIntNum(randomaccessfile.fd)).assertTrue();
expect(randomaccessfile.fpointer == 5).assertTrue();
randomaccessfile.closeSync();
fileio.unlinkSync(fpath);
} catch(err) {
console.info('fileio_create_randomaccessfile_sync_001 has failed for ' + err);
expect(null).assertFail();
}
});
/**
* @tc.number SUB_STORAGE_FILEIO_CREATE_RANDOMACCESSFILE_SYNC_0200
* @tc.name fileio_create_randomaccessfile_sync_002
* @tc.desc Test createRandomAccessFileSync() interface.
* Create RandomAccessFile object based on file descriptor to access file.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('fileio_create_randomaccessfile_sync_002', 0, async function () {
let fpath = await nextFileName('fileio_create_randomaccessfile_sync_002');
try {
let fd = fileio.openSync(fpath, 0o102, 0o666);
let randomaccessfile = fileio.createRandomAccessFileSync(fd, 0);
expect(isIntNum(randomaccessfile.fd)).assertTrue();
randomaccessfile.closeSync();
fileio.unlinkSync(fpath);
} catch(err) {
console.info('fileio_create_randomaccessfile_sync_002 has failed for ' + err);
expect(null).assertFail();
}
});
/**
* @tc.number SUB_STORAGE_FILEIO_CREATE_RANDOMACCESSFILE_SYNC_0300
* @tc.name fileio_create_randomaccessfile_sync_003
* @tc.desc Test createRandomAccessFileSync() interface. fpointer = 1.
* Create RandomAccessFile object based on file descriptor to access file.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('fileio_create_randomaccessfile_sync_003', 0, async function () {
let fpath = await nextFileName('fileio_create_randomaccessfile_sync_003');
try {
let fd = fileio.openSync(fpath, 0o102, 0o666);
let randomaccessfile = fileio.createRandomAccessFileSync(fd, 1);
expect(isIntNum(randomaccessfile.fd)).assertTrue();
expect(randomaccessfile.fpointer == 1).assertTrue();
randomaccessfile.closeSync();
fileio.unlinkSync(fpath);
} catch(err) {
console.info('fileio_create_randomaccessfile_sync_003 has failed for ' + err);
expect(null).assertFail();
}
});
/**
* @tc.number SUB_STORAGE_FILEIO_CREATE_RANDOMACCESSFILE_SYNC_0400
* @tc.name fileio_create_randomaccessfile_sync_004
* @tc.desc Test createRandomAccessFileSync() interface. No such file or directory.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('fileio_create_randomaccessfile_sync_004', 0, async function () {
let fpath = await nextFileName('fileio_create_randomaccessfile_sync_004');
try {
fileio.createRandomAccessFileSync(fpath, 0, 0o2);
} catch(err) {
console.info('fileio_create_randomaccessfile_sync_004 has failed for ' + err);
expect(err.message == "No such file or directory").assertTrue();
}
});
/**
* @tc.number SUB_STORAGE_FILEIO_CREATE_RANDOMACCESSFILE_SYNC_0500
* @tc.name fileio_create_randomaccessfile_sync_005
* @tc.desc Test createRandomAccessFileSync() interface. Invalid fd.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('fileio_create_randomaccessfile_sync_005', 0, async function () {
try {
fileio.createRandomAccessFileSync(-1, 0);
} catch(err) {
console.info('fileio_create_randomaccessfile_sync_005 has failed for ' + err);
expect(err.message == "Invalid fd").assertTrue();
}
});
/**
* @tc.number SUB_STORAGE_FILEIO_CREATE_RANDOMACCESSFILE_SYNC_0600
* @tc.name fileio_create_randomaccessfile_sync_006
* @tc.desc Test createRandomAccessFileSync() interface. Invalid fp.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('fileio_create_randomaccessfile_sync_006', 0, async function () {
let fpath = await nextFileName('fileio_create_randomaccessfile_sync_006');
let fd = fileio.openSync(fpath, 0o102, 0o666);
try {
fileio.createRandomAccessFileSync(fd, '1');
} catch(err) {
console.info('fileio_create_randomaccessfile_sync_006 has failed for ' + err);
expect(err.message == "Invalid fp").assertTrue();
fileio.closeSync(fd);
fileio.unlinkSync(fpath);
}
});
/**
* @tc.number SUB_STORAGE_FILEIO_CREATE_RANDOMACCESSFILE_SYNC_0700
* @tc.name fileio_create_randomaccessfile_sync_007
* @tc.desc Test createRandomAccessFileSync() interface. Missing Parameter.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('fileio_create_randomaccessfile_sync_007', 0, async function () {
let fpath = await nextFileName('fileio_create_randomaccessfile_sync_007');
let fd = fileio.openSync(fpath, 0o102, 0o666);
try {
fileio.createRandomAccessFileSync(fd);
} catch(err) {
console.info('fileio_create_randomaccessfile_sync_007 has failed for ' + err);
expect(err.message == "Number of arguments unmatched").assertTrue();
fileio.closeSync(fd);
fileio.unlinkSync(fpath);
}
});
/**
* @tc.number SUB_STORAGE_FILEIO_CREATE_RANDOMACCESSFILE_SYNC_0800
* @tc.name fileio_create_randomaccessfile_sync_008
* @tc.desc Test createRandomAccessFileSync() interface. flags=0o202.
* Create RandomAccessFile object to access file based on file path.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('fileio_create_randomaccessfile_sync_008', 0, async function () {
let fpath = await nextFileName('fileio_create_randomaccessfile_sync_008');
expect(prepareFile(fpath, '')).assertTrue();
try {
let randomaccessfile = fileio.createRandomAccessFileSync(fpath, 0, 0o202);
expect(isIntNum(randomaccessfile.fd)).assertTrue();
randomaccessfile.closeSync();
fileio.unlinkSync(fpath);
} catch(err) {
console.info('fileio_create_randomaccessfile_sync_008 has failed for ' + err);
expect(null).assertFail();
}
});
/**
* @tc.number SUB_STORAGE_FILEIO_CREATE_RANDOMACCESSFILE_SYNC_0900
* @tc.name fileio_create_randomaccessfile_sync_009
* @tc.desc Test createRandomAccessFileSync() interface. flags=0o302. File exists.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('fileio_create_randomaccessfile_sync_009', 0, async function () {
let fpath = await nextFileName('fileio_create_randomaccessfile_sync_009');
expect(prepareFile(fpath, '')).assertTrue();
try {
fileio.createRandomAccessFileSync(fpath, 0, 0o302);
} catch(err) {
console.info('fileio_create_randomaccessfile_sync_009 has failed for ' + err);
expect(err.message == "File exists").assertTrue();
fileio.unlinkSync(fpath);
}
});
/**
* @tc.number SUB_STORAGE_FILEIO_CREATE_RANDOMACCESSFILE_SYNC_1000
* @tc.name fileio_create_randomaccessfile_sync_010
* @tc.desc Test createRandomAccessFileSync() interface. flags=0o1002.
* If the file exists and the file is opened for write-only or read-write, trim its length to zero.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('fileio_create_randomaccessfile_sync_010', 0, async function () {
let fpath = await nextFileName('fileio_create_randomaccessfile_sync_010');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let randomaccessfile = fileio.createRandomAccessFileSync(fpath, 0, 0o1002);
let number = randomaccessfile.readSync(new ArrayBuffer(4096));
expect(number == 0).assertTrue();
randomaccessfile.closeSync();
fileio.unlinkSync(fpath);
} catch(err) {
console.info('fileio_create_randomaccessfile_sync_010 has failed for ' + err);
expect(null).assertFail();
}
});
/**
* @tc.number SUB_STORAGE_FILEIO_CREATE_RANDOMACCESSFILE_SYNC_1100
* @tc.name fileio_create_randomaccessfile_sync_011
* @tc.desc Test createRandomAccessFileSync() interface. flags=0o2002.
* Open as append, subsequent writes will append to the end of the file.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('fileio_create_randomaccessfile_sync_011', 0, async function () {
let fpath = await nextFileName('fileio_create_randomaccessfile_sync_011');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let randomaccessfile = fileio.createRandomAccessFileSync(fpath, 0, 0o2002);
let length = 100;
let num = randomaccessfile.writeSync(new ArrayBuffer(length));
expect(num == length).assertTrue();
randomaccessfile.setFilePointerSync(0);
let number = randomaccessfile.readSync(new ArrayBuffer(4096), { position: 0 });
expect(number == length + FILE_CONTENT.length).assertTrue();
randomaccessfile.closeSync();
fileio.unlinkSync(fpath);
} catch(err) {
console.info('fileio_create_randomaccessfile_sync_011 has failed for ' + err);
expect(null).assertFail();
}
});
/**
* @tc.number SUB_STORAGE_FILEIO_CREATE_RANDOMACCESSFILE_SYNC_1200
* @tc.name fileio_create_randomaccessfile_sync_012
* @tc.desc Test createRandomAccessFileSync() interface. flags=0o200002. Not a directory.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('fileio_create_randomaccessfile_sync_012', 0, async function () {
let fpath = await nextFileName('fileio_create_randomaccessfile_sync_012');
expect(prepareFile(fpath, '')).assertTrue();
try {
fileio.createRandomAccessFileSync(fpath, 0, 0o200002);
} catch(err) {
console.info('fileio_create_randomaccessfile_sync_012 has failed for ' + err);
expect(err.message == "Not a directory").assertTrue();
fileio.unlinkSync(fpath);
}
});
/**
* @tc.number SUB_STORAGE_FILEIO_CREATE_RANDOMACCESSFILE_SYNC_1300
* @tc.name fileio_create_randomaccessfile_sync_013
* @tc.desc Test createRandomAccessFileSync() interface. flags=0o400002.
* Create RandomAccessFile object to access file based on file path.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('fileio_create_randomaccessfile_sync_013', 0, async function () {
let fpath = await nextFileName('fileio_create_randomaccessfile_sync_013');
expect(prepareFile(fpath, '')).assertTrue();
try {
let randomaccessfile = fileio.createRandomAccessFileSync(fpath, 0, 0o400002);
expect(isIntNum(randomaccessfile.fd)).assertTrue();
randomaccessfile.closeSync();
fileio.unlinkSync(fpath);
} catch(err) {
console.info('fileio_create_randomaccessfile_sync_013 has failed for ' + err);
expect(null).assertFail();
}
});
/**
* @tc.number SUB_STORAGE_FILEIO_CREATE_RANDOMACCESSFILE_SYNC_1400
* @tc.name fileio_create_randomaccessfile_sync_014
* @tc.desc Test createRandomAccessFileSync() interface. flags=0o4010002.
* Create RandomAccessFile object to access file based on file path.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('fileio_create_randomaccessfile_sync_014', 0, async function () {
let fpath = await nextFileName('fileio_create_randomaccessfile_sync_014');
expect(prepareFile(fpath, '')).assertTrue();
try {
let randomaccessfile = fileio.createRandomAccessFileSync(fpath, 0, 0o4010002);
expect(isIntNum(randomaccessfile.fd)).assertTrue();
randomaccessfile.closeSync();
fileio.unlinkSync(fpath);
} catch(err) {
console.info('fileio_create_randomaccessfile_sync_015 has failed for ' + err);
expect(null).assertFail();
}
});
/**
* @tc.number SUB_STORAGE_FILEIO_CREATE_RANDOMACCESSFILE_ASYNC_0000
* @tc.name fileio_create_randomaccessfile_async_000
* @tc.desc Test createRandomAccessFile() interface. return in promise mode.
* Create RandomAccessFile object to access file based on file path.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('fileio_create_randomaccessfile_async_000', 0, async function (done) {
let fpath = await nextFileName('fileio_create_randomaccessfile_async_000');
expect(prepareFile(fpath, '')).assertTrue();
try {
let randomaccessfile = await fileio.createRandomAccessFile(fpath, 0, 0o2);
expect(isIntNum(randomaccessfile.fd)).assertTrue();
randomaccessfile.closeSync();
fileio.unlinkSync(fpath);
done();
} catch(err) {
console.info('fileio_create_randomaccessfile_async_000 has failed for ' + err);
expect(null).assertFail();
}
});
/**
* @tc.number SUB_STORAGE_FILEIO_CREATE_RANDOMACCESSFILE_ASYNC_0100
* @tc.name fileio_create_randomaccessfile_async_001
* @tc.desc Test createRandomAccessFile() interface. fpointer = 10. return in callback mode.
* Create RandomAccessFile object to access file based on file path.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('fileio_create_randomaccessfile_async_001', 0, async function (done) {
let fpath = await nextFileName('fileio_create_randomaccessfile_async_001');
try {
fileio.createRandomAccessFile(fpath, 10, 0o102, function(err, randomaccessfile) {
expect(isIntNum(randomaccessfile.fd)).assertTrue();
expect(randomaccessfile.fpointer == 10).assertTrue();
randomaccessfile.closeSync();
fileio.unlinkSync(fpath);
done();
});
} catch(err) {
console.info('fileio_create_randomaccessfile_async_001 has failed for ' + err);
expect(null).assertFail();
}
});
/**
* @tc.number SUB_STORAGE_FILEIO_CREATE_RANDOMACCESSFILE_ASYNC_0200
* @tc.name fileio_create_randomaccessfile_async_002
* @tc.desc Test createRandomAccessFile() interface.
* Create RandomAccessFile object based on file descriptor to access file.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('fileio_create_randomaccessfile_async_002', 0, async function (done) {
let fpath = await nextFileName('fileio_create_randomaccessfile_async_002');
try {
let fd = fileio.openSync(fpath, 0o102, 0o666);
fileio.createRandomAccessFile(fd, 0, function(err, randomaccessfile) {
expect(isIntNum(randomaccessfile.fd)).assertTrue();
randomaccessfile.closeSync();
fileio.unlinkSync(fpath);
done();
});
} catch(err) {
console.info('fileio_create_randomaccessfile_async_002 has failed for ' + err);
expect(null).assertFail();
}
});
/**
* @tc.number SUB_STORAGE_FILEIO_CREATE_RANDOMACCESSFILE_ASYNC_0300
* @tc.name fileio_create_randomaccessfile_async_003
* @tc.desc Test createRandomAccessFile() interface. fpointer = 1.
* Create RandomAccessFile object based on file descriptor to access file.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('fileio_create_randomaccessfile_async_003', 0, async function (done) {
let fpath = await nextFileName('fileio_create_randomaccessfile_async_003');
try {
let fd = fileio.openSync(fpath, 0o102, 0o666);
let randomaccessfile = await fileio.createRandomAccessFile(fd, 1);
expect(isIntNum(randomaccessfile.fd)).assertTrue();
expect(randomaccessfile.fpointer == 1).assertTrue();
randomaccessfile.closeSync();
fileio.unlinkSync(fpath);
done();
} catch(err) {
console.info('fileio_create_randomaccessfile_async_003 has failed for ' + err);
expect(null).assertFail();
}
});
/**
* @tc.number SUB_STORAGE_FILEIO_CREATE_RANDOMACCESSFILE_ASYNC_0400
* @tc.name fileio_create_randomaccessfile_async_004
* @tc.desc Test createRandomAccessFile() interface. No such file or directory.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('fileio_create_randomaccessfile_async_004', 0, async function (done) {
let fpath = await nextFileName('fileio_create_randomaccessfile_async_004');
try {
await fileio.createRandomAccessFile(fpath, 0, 0o2);
} catch(err) {
console.info('fileio_create_randomaccessfile_async_004 has failed for ' + err);
expect(err.message == "No such file or directory").assertTrue();
done();
}
});
/**
* @tc.number SUB_STORAGE_FILEIO_CREATE_RANDOMACCESSFILE_ASYNC_0500
* @tc.name fileio_create_randomaccessfile_async_005
* @tc.desc Test createRandomAccessFile() interface. Invalid fd.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('fileio_create_randomaccessfile_async_005', 0, async function (done) {
try {
fileio.createRandomAccessFile(-1, 0, function(err) {
});
} catch(err) {
console.info('fileio_create_randomaccessfile_async_005 has failed for ' + err);
expect(err.message == "Invalid fd").assertTrue();
done();
}
});
/**
* @tc.number SUB_STORAGE_FILEIO_CREATE_RANDOMACCESSFILE_ASYNC_0600
* @tc.name fileio_create_randomaccessfile_async_006
* @tc.desc Test createRandomAccessFile() interface. Invalid fp.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('fileio_create_randomaccessfile_async_006', 0, async function (done) {
let fpath = await nextFileName('fileio_create_randomaccessfile_async_006');
let fd = fileio.openSync(fpath, 0o102, 0o666);
try {
await fileio.createRandomAccessFile(fd, '1');
} catch(err) {
console.info('fileio_create_randomaccessfile_async_006 has failed for ' + err);
expect(err.message == "Invalid fp").assertTrue();
fileio.closeSync(fd);
fileio.unlinkSync(fpath);
done();
}
});
/**
* @tc.number SUB_STORAGE_FILEIO_CREATE_RANDOMACCESSFILE_ASYNC_0700
* @tc.name fileio_create_randomaccessfile_async_007
* @tc.desc Test createRandomAccessFile() interface. Missing Parameter.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('fileio_create_randomaccessfile_async_007', 0, async function (done) {
let fpath = await nextFileName('fileio_create_randomaccessfile_async_007');
let fd = fileio.openSync(fpath, 0o102, 0o666);
try {
await fileio.createRandomAccessFile(fd);
} catch(err) {
console.info('fileio_create_randomaccessfile_async_007 has failed for ' + err);
expect(err.message == "Number of arguments unmatched").assertTrue();
fileio.closeSync(fd);
fileio.unlinkSync(fpath);
done();
}
});
/**
* @tc.number SUB_STORAGE_FILEIO_CREATE_RANDOMACCESSFILE_ASYNC_0800
* @tc.name fileio_create_randomaccessfile_async_008
* @tc.desc Test createRandomAccessFile() interface. flags=0o202.
* Create RandomAccessFile object to access file based on file path.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('fileio_create_randomaccessfile_async_008', 0, async function (done) {
let fpath = await nextFileName('fileio_create_randomaccessfile_async_008');
expect(prepareFile(fpath, '')).assertTrue();
try {
fileio.createRandomAccessFile(fpath, 0, 0o202, function(err, randomaccessfile) {
expect(isIntNum(randomaccessfile.fd)).assertTrue();
randomaccessfile.closeSync();
fileio.unlinkSync(fpath);
done();
});
} catch(err) {
console.info('fileio_create_randomaccessfile_async_008 has failed for ' + err);
expect(null).assertFail();
}
});
/**
* @tc.number SUB_STORAGE_FILEIO_CREATE_RANDOMACCESSFILE_SYNC_0900
* @tc.name fileio_create_randomaccessfile_sync_009
* @tc.desc Test createRandomAccessFile() interface. flags=0o302. File exists.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('fileio_create_randomaccessfile_async_009', 0, async function (done) {
let fpath = await nextFileName('fileio_create_randomaccessfile_async_009');
expect(prepareFile(fpath, '')).assertTrue();
try {
await fileio.createRandomAccessFile(fpath, 0, 0o302);
} catch(err) {
console.info('fileio_create_randomaccessfile_async_009 has failed for ' + err);
expect(err.message == "File exists").assertTrue();
fileio.unlinkSync(fpath);
done();
}
});
/**
* @tc.number SUB_STORAGE_FILEIO_CREATE_RANDOMACCESSFILE_ASYNC_1000
* @tc.name fileio_create_randomaccessfile_async_010
* @tc.desc Test createRandomAccessFile() interface. flags=0o1002.
* If the file exists and the file is opened for write-only or read-write, trim its length to zero.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('fileio_create_randomaccessfile_async_010', 0, async function (done) {
let fpath = await nextFileName('fileio_create_randomaccessfile_async_010');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let randomaccessfile = await fileio.createRandomAccessFile(fpath, 0, 0o1002);
let number = randomaccessfile.readSync(new ArrayBuffer(4096));
expect(number == 0).assertTrue();
randomaccessfile.closeSync();
fileio.unlinkSync(fpath);
done();
} catch(err) {
console.info('fileio_create_randomaccessfile_async_010 has failed for ' + err);
expect(null).assertFail();
}
});
/**
* @tc.number SUB_STORAGE_FILEIO_CREATE_RANDOMACCESSFILE_ASYNC_1100
* @tc.name fileio_create_randomaccessfile_async_011
* @tc.desc Test createRandomAccessFile() interface. flags=0o2002.
* Open as append, subsequent writes will append to the end of the file.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('fileio_create_randomaccessfile_async_011', 0, async function (done) {
let fpath = await nextFileName('fileio_create_randomaccessfile_async_011');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let randomaccessfile = await fileio.createRandomAccessFile(fpath, 0, 0o2002);
let length = 100;
let num = randomaccessfile.writeSync(new ArrayBuffer(length));
expect(num == length).assertTrue();
randomaccessfile.setFilePointerSync(0);
let number = randomaccessfile.readSync(new ArrayBuffer(4096), { position: 0 });
expect(number == length + FILE_CONTENT.length).assertTrue();
randomaccessfile.closeSync();
fileio.unlinkSync(fpath);
done();
} catch(err) {
console.info('fileio_create_randomaccessfile_async_011 has failed for ' + err);
expect(null).assertFail();
}
});
/**
* @tc.number SUB_STORAGE_FILEIO_CREATE_RANDOMACCESSFILE_ASYNC_1200
* @tc.name fileio_create_randomaccessfile_async_012
* @tc.desc Test createRandomAccessFile() interface. flags=0o200002. Not a directory.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('fileio_create_randomaccessfile_async_012', 0, async function (done) {
let fpath = await nextFileName('fileio_create_randomaccessfile_async_012');
expect(prepareFile(fpath, '')).assertTrue();
try {
await fileio.createRandomAccessFile(fpath, 0, 0o200002);
} catch(err) {
console.info('fileio_create_randomaccessfile_async_012 has failed for ' + err);
expect(err.message == "Not a directory").assertTrue();
fileio.unlinkSync(fpath);
done();
}
});
/**
* @tc.number SUB_STORAGE_FILEIO_CREATE_RANDOMACCESSFILE_ASYNC_1300
* @tc.name fileio_create_randomaccessfile_async_013
* @tc.desc Test createRandomAccessFile() interface. flags=0o400002.
* Create RandomAccessFile object to access file based on file path.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('fileio_create_randomaccessfile_async_013', 0, async function (done) {
let fpath = await nextFileName('fileio_create_randomaccessfile_async_013');
expect(prepareFile(fpath, '')).assertTrue();
try {
let randomaccessfile = await fileio.createRandomAccessFile(fpath, 0, 0o400002);
expect(isIntNum(randomaccessfile.fd)).assertTrue();
randomaccessfile.closeSync();
fileio.unlinkSync(fpath);
done();
} catch(err) {
console.info('fileio_create_randomaccessfile_async_013 has failed for ' + err);
expect(null).assertFail();
}
});
/**
* @tc.number SUB_STORAGE_FILEIO_CREATE_RANDOMACCESSFILE_ASYNC_1400
* @tc.name fileio_create_randomaccessfile_async_014
* @tc.desc Test createRandomAccessFile() interface. flags=0o4010002.
* Create RandomAccessFile object to access file based on file path.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('fileio_create_randomaccessfile_async_014', 0, async function (done) {
let fpath = await nextFileName('fileio_create_randomaccessfile_async_014');
expect(prepareFile(fpath, '')).assertTrue();
try {
let randomaccessfile = await fileio.createRandomAccessFile(fpath, 0, 0o4010002);
expect(isIntNum(randomaccessfile.fd)).assertTrue();
randomaccessfile.closeSync();
fileio.unlinkSync(fpath);
done();
} catch(err) {
console.info('fileio_create_randomaccessfile_async_014 has failed for ' + err);
expect(null).assertFail();
}
});
})
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册