提交 6090e20d 编写于 作者: R raoxian

新增randomaccessfile测试用例

Signed-off-by: Nraoxian <raoxian@huawei.com>
上级 a97bffad
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Copyright (C) 2022 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
......@@ -58,6 +58,7 @@ describe('fileio_randomAccessFile_close', function () {
try {
randomaccessfile.closeSync(1);
expect(false).assertTrue();
} catch(err) {
console.info('fileio_randomaccessfile_close_sync_001 has failed for ' + err);
expect(err.message == "Number of arguments unmatched").assertTrue();
......
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Copyright (C) 2022 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
......@@ -64,7 +64,7 @@ describe('fileio_randomAccessFile_read', function () {
try {
let randomaccessfile = fileio.createRandomAccessFileSync(fpath, 0, 0o102);
let length = 4096;
let length = 20;
let num = randomaccessfile.writeSync(new ArrayBuffer(length));
expect(num == length).assertTrue();
randomaccessfile.setFilePointerSync(0);
......@@ -92,7 +92,7 @@ describe('fileio_randomAccessFile_read', function () {
try {
let randomaccessfile = fileio.createRandomAccessFileSync(fpath, 0, 0o102);
let length = 4096;
let length = 20;
let num = randomaccessfile.writeSync(new ArrayBuffer(length));
expect(num == length).assertTrue();
randomaccessfile.setFilePointerSync(0);
......@@ -120,7 +120,7 @@ describe('fileio_randomAccessFile_read', function () {
try {
let randomaccessfile = fileio.createRandomAccessFileSync(fpath, 0, 0o102);
let length = 4096;
let length = 20;
let num = randomaccessfile.writeSync(new ArrayBuffer(length));
expect(num == length).assertTrue();
randomaccessfile.setFilePointerSync(0);
......@@ -177,7 +177,7 @@ describe('fileio_randomAccessFile_read', function () {
try {
let randomaccessfile = fileio.createRandomAccessFileSync(fpath, 0, 0o102);
let length = 4096;
let length = 20;
let number = randomaccessfile.readSync(new ArrayBuffer(length), { offset: 1, position: 6 });
expect(number == FILE_CONTENT.length - 6).assertTrue();
randomaccessfile.closeSync();
......@@ -204,6 +204,7 @@ describe('fileio_randomAccessFile_read', function () {
try {
randomaccessfile.readSync(new ArrayBuffer(4096), { offset: -1 });
expect(false).assertTrue();
} catch (err) {
console.info('fileio_randomaccessfile_read_sync_006 has failed for ' + err);
expect(err.message == "Invalid buffer/options").assertTrue();
......@@ -227,6 +228,7 @@ describe('fileio_randomAccessFile_read', function () {
try {
randomaccessfile.readSync(new ArrayBuffer(4096), { offset: 1, length: 4096 });
expect(false).assertTrue();
} catch (err) {
console.info('fileio_randomaccessfile_read_sync_007 has failed for ' + err);
expect(err.message == "Invalid buffer/options").assertTrue();
......@@ -251,6 +253,7 @@ describe('fileio_randomAccessFile_read', function () {
try {
let length = 4096;
randomaccessfile.readSync(new ArrayBuffer(length), { offset: length + 1 });
expect(false).assertTrue();
} catch (err) {
console.info('fileio_randomaccessfile_read_sync_008 has failed for ' + err);
expect(err.message == "Invalid buffer/options").assertTrue();
......@@ -275,6 +278,7 @@ describe('fileio_randomAccessFile_read', function () {
try {
let length = 4096;
randomaccessfile.readSync(new ArrayBuffer(length), { length: length + 1 });
expect(false).assertTrue();
} catch (err) {
console.info('fileio_randomaccessfile_read_sync_009 has failed for ' + err);
expect(err.message == "Invalid buffer/options").assertTrue();
......@@ -326,6 +330,7 @@ describe('fileio_randomAccessFile_read', function () {
try {
randomaccessfile.readSync();
expect(false).assertTrue();
} catch (err) {
console.info('fileio_randomaccessfile_read_sync_011 has failed for ' + err);
expect(err.message == "Number of arguments unmatched").assertTrue();
......@@ -349,6 +354,7 @@ describe('fileio_randomAccessFile_read', function () {
try {
randomaccessfile.readSync(new ArrayBuffer(4096), { position: -1 });
expect(false).assertTrue();
} catch (err) {
console.info('fileio_randomaccessfile_read_sync_012 has failed for ' + err);
expect(err.message == "Invalid buffer/options").assertTrue();
......@@ -358,8 +364,8 @@ describe('fileio_randomAccessFile_read', function () {
});
/**
* @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_READ_SYNC_1200
* @tc.name fileio_randomaccessfile_read_sync_012
* @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_READ_SYNC_1300
* @tc.name fileio_randomaccessfile_read_sync_013
* @tc.desc Test readSync() interface. When the parameter type is wrong.
* @tc.size MEDIUM
* @tc.type Function
......@@ -372,6 +378,7 @@ describe('fileio_randomAccessFile_read', function () {
try {
randomaccessfile.readSync('');
expect(false).assertTrue();
} catch (err) {
console.info('fileio_randomaccessfile_read_sync_013 has failed for ' + err);
expect(err.message == "Invalid buffer/options").assertTrue();
......@@ -424,7 +431,7 @@ describe('fileio_randomAccessFile_read', function () {
try {
fileio.createRandomAccessFile(fpath, 0, 0o102, async function (err, randomaccessfile) {
let length = 4096;
let length = 20;
let num = await randomaccessfile.write(new ArrayBuffer(length));
expect(num == length).assertTrue();
randomaccessfile.setFilePointerSync(0);
......@@ -455,7 +462,7 @@ describe('fileio_randomAccessFile_read', function () {
try {
let fd = fileio.openSync(fpath, 0o102, 0o666);
let randomaccessfile = await fileio.createRandomAccessFile(fd, 0);
let length = 4096;
let length = 20;
let num = await randomaccessfile.write(new ArrayBuffer(length));
expect(num == length).assertTrue();
randomaccessfile.setFilePointerSync(0);
......@@ -485,7 +492,7 @@ describe('fileio_randomAccessFile_read', function () {
try {
let randomaccessfile = await fileio.createRandomAccessFile(fpath, 0, 0o102);
let length = 4096;
let length = 20;
let num = await randomaccessfile.write(new ArrayBuffer(length));
expect(num == length).assertTrue();
randomaccessfile.setFilePointerSync(0);
......@@ -547,7 +554,7 @@ describe('fileio_randomAccessFile_read', function () {
try {
let randomaccessfile = await fileio.createRandomAccessFile(fpath, 0, 0o102);
let length = 4096;
let length = 20;
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();
......
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Copyright (C) 2022 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
......@@ -60,6 +60,7 @@ describe('fileio_randomAccessFile_setFilePointer', function () {
try {
randomaccessfile.setFilePointerSync('5');
expect(false).assertTrue();
} catch(err) {
console.info('fileio_randomaccessfile_set_file_pointer_sync_001 has failed for ' + err);
expect(err.message == "Invalid fpointer").assertTrue();
......@@ -83,6 +84,7 @@ describe('fileio_randomAccessFile_setFilePointer', function () {
try {
randomaccessfile.setFilePointerSync();
expect(false).assertTrue();
} catch(err) {
console.info('fileio_randomaccessfile_set_file_pointer_sync_002 has failed for ' + err);
expect(err.message == "Number of arguments unmatched").assertTrue();
......
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Copyright (C) 2022 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
......@@ -60,7 +60,7 @@ describe('fileio_randomAccessFile_write', function () {
try {
let randomaccessfile = fileio.createRandomAccessFileSync(fpath, 0, 0o102);
let length = 4096;
let length = 20;
let num = randomaccessfile.writeSync(new ArrayBuffer(length), { offset: 1 });
expect(num == length - 1).assertTrue();
randomaccessfile.closeSync();
......@@ -86,7 +86,7 @@ describe('fileio_randomAccessFile_write', function () {
try {
let fd = fileio.openSync(fpath, 0o102, 0o666);
let randomaccessfile = fileio.createRandomAccessFileSync(fd, 0);
let length = 4096;
let length = 20;
let num = randomaccessfile.writeSync(new ArrayBuffer(length), { position: 1 });
expect(num == length).assertTrue();
randomaccessfile.closeSync();
......@@ -111,7 +111,7 @@ describe('fileio_randomAccessFile_write', function () {
try {
let randomaccessfile = fileio.createRandomAccessFileSync(fpath, 0, 0o102);
let length = 4096;
let length = 20;
let num = randomaccessfile.writeSync(new ArrayBuffer(length), { offset: 1, length: 10 });
expect(num == 10).assertTrue();
randomaccessfile.closeSync();
......@@ -196,6 +196,7 @@ describe('fileio_randomAccessFile_write', function () {
try {
randomaccessfile.writeSync(new ArrayBuffer(4096), { offset: 5, length: 4095 });
expect(false).assertTrue();
} catch(err) {
console.info('fileio_randomaccessfile_write_sync_006 has failed for ' + err);
expect(err.message == "Invalid buffer/options").assertTrue();
......@@ -220,6 +221,7 @@ describe('fileio_randomAccessFile_write', function () {
try {
let length = 4096;
randomaccessfile.writeSync(new ArrayBuffer(length), { offset: length + 1 });
expect(false).assertTrue();
} catch(err) {
console.info('fileio_randomaccessfile_write_sync_007 has failed for ' + err);
expect(err.message == "Invalid buffer/options").assertTrue();
......@@ -243,6 +245,7 @@ describe('fileio_randomAccessFile_write', function () {
try {
randomaccessfile.writeSync();
expect(false).assertTrue();
} catch(err) {
console.info('fileio_randomaccessfile_write_sync_008 has failed for ' + err);
expect(err.message == "Number of arguments unmatched").assertTrue();
......@@ -267,6 +270,7 @@ describe('fileio_randomAccessFile_write', function () {
try {
randomaccessfile.writeSync(new ArrayBuffer(4096), { offset: -1 });
expect(false).assertTrue();
} catch(err) {
console.info('fileio_randomaccessfile_write_sync_009 has failed for ' + err);
expect(err.message == "Invalid buffer/options").assertTrue();
......@@ -315,6 +319,7 @@ describe('fileio_randomAccessFile_write', function () {
try {
randomaccessfile.writeSync(10, { length: -1 });
expect(false).assertTrue();
} catch(err) {
console.info('fileio_randomaccessfile_write_sync_011 has failed for ' + err);
expect(err.message == "Invalid buffer/options").assertTrue();
......@@ -339,6 +344,7 @@ describe('fileio_randomAccessFile_write', function () {
try {
let length = 4096;
randomaccessfile.writeSync(new ArrayBuffer(length), { length: length + 1 });
expect(false).assertTrue();
} catch(err) {
console.info('fileio_randomaccessfile_write_sync_012 has failed for ' + err);
expect(err.message == "Invalid buffer/options").assertTrue();
......@@ -362,6 +368,7 @@ describe('fileio_randomAccessFile_write', function () {
try {
randomaccessfile.writeSync(new ArrayBuffer(4096), { position: -1 });
expect(false).assertTrue();
} catch(err) {
console.info('fileio_randomaccessfile_write_sync_013 has failed for ' + err);
expect(err.message == "Invalid buffer/options").assertTrue();
......@@ -412,7 +419,7 @@ describe('fileio_randomAccessFile_write', function () {
try {
let fd = fileio.openSync(fpath, 0o102, 0o666);
let randomaccessfile = await fileio.createRandomAccessFile(fd, 0);
let length = 4096;
let length = 20;
randomaccessfile.write(new ArrayBuffer(length), { offset: 1 }, function(err, bytesWritten) {
expect(bytesWritten == length - 1).assertTrue();
randomaccessfile.closeSync();
......@@ -439,7 +446,7 @@ describe('fileio_randomAccessFile_write', function () {
try {
let randomaccessfile = await fileio.createRandomAccessFile(fpath, 0, 0o102);
let length = 4096;
let length = 20;
let num = await randomaccessfile.write(new ArrayBuffer(length), { position: 1 });
expect(num == length).assertTrue();
randomaccessfile.closeSync();
......@@ -465,7 +472,7 @@ describe('fileio_randomAccessFile_write', function () {
try {
let randomaccessfile = await fileio.createRandomAccessFile(fpath, 0, 0o102);
let length = 4096;
let length = 20;
let num = await randomaccessfile.write(new ArrayBuffer(length), { offset: 1, length: 10 });
expect(num == 10).assertTrue();
randomaccessfile.closeSync();
......
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Copyright (C) 2022 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
......@@ -136,6 +136,7 @@ describe('fileio_create_randomAccessFile', function () {
try {
fileio.createRandomAccessFileSync(fpath, 0, 0o2);
expect(false).assertTrue();
} catch(err) {
console.info('fileio_create_randomaccessfile_sync_004 has failed for ' + err);
expect(err.message == "No such file or directory").assertTrue();
......@@ -154,6 +155,7 @@ describe('fileio_create_randomAccessFile', function () {
it('fileio_create_randomaccessfile_sync_005', 0, async function () {
try {
fileio.createRandomAccessFileSync(-1, 0);
expect(false).assertTrue();
} catch(err) {
console.info('fileio_create_randomaccessfile_sync_005 has failed for ' + err);
expect(err.message == "Invalid fd").assertTrue();
......@@ -175,6 +177,7 @@ describe('fileio_create_randomAccessFile', function () {
try {
fileio.createRandomAccessFileSync(fd, '1');
expect(false).assertTrue();
} catch(err) {
console.info('fileio_create_randomaccessfile_sync_006 has failed for ' + err);
expect(err.message == "Invalid fp").assertTrue();
......@@ -198,6 +201,7 @@ describe('fileio_create_randomAccessFile', function () {
try {
fileio.createRandomAccessFileSync(fd);
expect(false).assertTrue();
} catch(err) {
console.info('fileio_create_randomaccessfile_sync_007 has failed for ' + err);
expect(err.message == "Number of arguments unmatched").assertTrue();
......@@ -246,6 +250,7 @@ describe('fileio_create_randomAccessFile', function () {
try {
fileio.createRandomAccessFileSync(fpath, 0, 0o302);
expect(false).assertTrue();
} catch(err) {
console.info('fileio_create_randomaccessfile_sync_009 has failed for ' + err);
expect(err.message == "File exists").assertTrue();
......@@ -324,6 +329,7 @@ describe('fileio_create_randomAccessFile', function () {
try {
fileio.createRandomAccessFileSync(fpath, 0, 0o200002);
expect(false).assertTrue();
} catch(err) {
console.info('fileio_create_randomaccessfile_sync_012 has failed for ' + err);
expect(err.message == "Not a directory").assertTrue();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册