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

!9229 randomAccessFile XTS 修改

Merge pull request !9229 from yangjingbo/xts_random_new
......@@ -45,8 +45,8 @@ export function prepare200MFile(fpath) {
fileIO.truncateSync(file.fd)
let bf = new ArrayBuffer(1024 * 1024 * 20);
for (let i = 0; i < 10; i++) {
let position = bf.byteLength * i;
let writeLen = fileIO.writeSync(file.fd, bf, { offset: 0, length: bf.byteLength, position: position, encoding: 'utf-8' });
let offset = bf.byteLength * i;
let writeLen = fileIO.writeSync(file.fd, bf, { offset: offset, length: bf.byteLength, encoding: 'utf-8' });
}
fileIO.fsyncSync(file.fd)
fileIO.closeSync(file)
......
......@@ -17,6 +17,7 @@ import fileIOAccess from './members/access.test.js'
import fileIOClose from './members/close.test.js'
import fileIOCopyDir from './members/copyDir.test'
import fileIOCopyfile from './members/copyFile.test.js'
import fileIOCreateRandomAccessFile from './members/createRandomAccessFile.test.js'
import fileIOCreateStream from './members/createStream.test.js'
import fileIOFdatasync from './members/fdatasync.test.js'
import fileIOFdOpenStream from './members/fdopenStream.test.js'
......@@ -30,6 +31,10 @@ import fileIOMkdtemp from './members/mkdtemp.test.js'
import fileIOMoveDir from './members/moveDir.test.js'
import fileIOMoveFile from './members/moveFile.test.js'
import fileIOOpen from './members/open.test.js'
import fileIORandomAccessFileClose from './class_randomAccessFile/close.test.js'
import fileIORandomAccessFileRead from './class_randomAccessFile/read.test.js'
import fileIORandomAccessFileSetFilePointer from './class_randomAccessFile/setFilePointer.test.js'
import fileIORandomAccessFileWrite from './class_randomAccessFile/write.test.js'
import fileIORead from './members/read.test.js'
import fileIOReadtext from './members/readtext.test.js'
import fileIORename from './members/rename.test.js'
......@@ -49,6 +54,7 @@ export default function testsuite() {
fileIOClose()
fileIOCopyDir()
fileIOCopyfile()
fileIOCreateRandomAccessFile()
fileIOCreateStream()
fileIOFdatasync()
fileIOFdOpenStream()
......@@ -62,6 +68,10 @@ export default function testsuite() {
fileIOMoveDir()
fileIOMoveFile()
fileIOOpen()
fileIORandomAccessFileClose()
fileIORandomAccessFileRead()
fileIORandomAccessFileSetFilePointer()
fileIORandomAccessFileWrite()
fileIORead()
fileIOReadtext()
fileIORename()
......
/*
* Copyright (C) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the 'License');
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an 'AS IS' BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {
fileIO, nextFileName,
describe, it, expect
} from '../Common';
export default function 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 close() 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, fileIO.OpenMode.CREATE | fileIO.OpenMode.READ_WRITE);
randomaccessfile.close();
fileIO.unlinkSync(fpath);
} catch(err) {
console.info('fileIO_randomaccessfile_close_sync_000 has failed for ' + err);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_CLOSE_SYNC_0100
* @tc.name fileIO_randomaccessfile_close_sync_001
* @tc.desc Test close() interface. Parameter mismatch.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_randomaccessfile_close_sync_001', 3, async function () {
let fpath = await nextFileName('fileIO_randomaccessfile_close_sync_001');
let randomaccessfile = fileIO.createRandomAccessFileSync(fpath, fileIO.OpenMode.CREATE | fileIO.OpenMode.READ_WRITE);
try {
randomaccessfile.close(1);
expect(false).assertTrue();
} catch(err) {
console.info('fileIO_randomaccessfile_close_sync_001 has failed for ' + err);
randomaccessfile.close();
fileIO.unlinkSync(fpath);
expect(err.code == 13900020 && err.message == "Invalid argument").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 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 setFilePointer() interface. Set file offset pointer position and read will start from filePointer + offset
* @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');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let randomaccessfile = fileIO.createRandomAccessFileSync(fpath, fileIO.OpenMode.CREATE | fileIO.OpenMode.READ_WRITE);
expect(randomaccessfile.filePointer == 0).assertTrue();
let initFilePointer = 5;
randomaccessfile.setFilePointer(initFilePointer);
expect(randomaccessfile.filePointer == initFilePointer).assertTrue();
let initOffset = 5;
let readLen = randomaccessfile.readSync(new ArrayBuffer(4096), { offset: initOffset });
expect(readLen == FILE_CONTENT.length - initFilePointer - initOffset).assertTrue();
randomaccessfile.close();
fileIO.unlinkSync(fpath);
} catch(err) {
console.info('fileIO_randomaccessfile_set_file_pointer_sync_000 has failed for ' + err);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_SET_FILE_POINTER_SYNC_0100
* @tc.name fileIO_randomaccessfile_set_file_pointer_sync_001
* @tc.desc Test setFilePointer() interface. Invalid fpointer.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_randomaccessfile_set_file_pointer_sync_001', 3, async function () {
let fpath = await nextFileName('fileIO_randomaccessfile_set_file_pointer_sync_001');
let randomaccessfile = fileIO.createRandomAccessFileSync(fpath, fileIO.OpenMode.CREATE | fileIO.OpenMode.READ_WRITE);
try {
randomaccessfile.setFilePointer('5');
expect(false).assertTrue();
} catch(err) {
console.info('fileIO_randomaccessfile_set_file_pointer_sync_001 has failed for ' + err);
randomaccessfile.close();
fileIO.unlinkSync(fpath);
expect(err.code == 13900020 && err.message == "Invalid argument").assertTrue();
}
});
/**
* @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_SET_FILE_POINTER_SYNC_0200
* @tc.name fileIO_randomaccessfile_set_file_pointer_sync_002
* @tc.desc Test setFilePointer() interface. Missing Parameter.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileIO_randomaccessfile_set_file_pointer_sync_002', 3, async function () {
let fpath = await nextFileName('fileIO_randomaccessfile_set_file_pointer_sync_002');
let randomaccessfile = fileIO.createRandomAccessFileSync(fpath, fileIO.OpenMode.CREATE | fileIO.OpenMode.READ_WRITE);
try {
randomaccessfile.setFilePointer();
expect(false).assertTrue();
} catch(err) {
console.info('fileIO_randomaccessfile_set_file_pointer_sync_002 has failed for ' + err);
randomaccessfile.close();
fileIO.unlinkSync(fpath);
expect(err.code == 13900020 && err.message == "Invalid argument").assertTrue();
}
});
})
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册