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

!3175 update storagefileioerrorjstest

Merge pull request !3175 from raoxian/master
......@@ -34,7 +34,7 @@ export function prepareFile(fpath, content) {
export function nextFileName(testName) {
const BASE_PATH = '/data/storage/el2/base/haps/entry/cache/'
return BASE_PATH + testName + '_' + randomString(testName.length);
return BASE_PATH + testName
}
export function fileName(testName) {
const BASE_PATH = '/data/storage/el2/base/haps/entry/files/'
......@@ -54,4 +54,8 @@ export function randomString(num) {
export function isIntNum(val) {
return typeof val === 'number' && val % 1 === 0;
}
export function isInclude(error, message) {
return error.toString().indexOf(message) != -1;
}
\ No newline at end of file
......@@ -26,7 +26,8 @@ import {
fileName,
nextFileName,
randomString,
isIntNum
isIntNum,
isInclude
}
from './Common'
......@@ -47,8 +48,9 @@ describe('FileIOError', function () {
expect(isIntNum(fd)).assertTrue();
fileio.rmdirSync(dpath);
}
catch (e) {
console.log('fileio_test_error_009 has failed for ' + e);
catch (err) {
console.log('fileio_test_error_009 has failed for ' + err);
expect(isInclude(err.message, 'Directory not empty')).assertTrue();
fileio.unlinkSync(fpath);
fileio.rmdirSync(dpath);
}
......@@ -68,38 +70,9 @@ describe('FileIOError', function () {
fileio.rmdirSync(fpath);
expect(null).assertFail();
}
catch (e) {
console.log('fileio_test_error_010 has failed for ' + e);
fileio.unlinkSync(fpath);
}
});
/**
* @tc.number SUB_STORAGE_FileIo_test_error_1100
* @tc.name FileIo_test_error_011
* @tc.desc Function of API, Pass in a
* path that exceeds 4096 bytes to copy the file
*/
it('FileIo_test_error_011', 0, function () {
let fpath = nextFileName('fileio_test_error_011');
let fd = fileio.openSync(fpath, 0o102, 0o777);
expect(isIntNum(fd)).assertTrue();
let dpath = nextFileName('fileio_error_011d');
fileio.mkdirSync(dpath);
try {
for (let i = 0; i < 16; i++) {
if (i == 15) {
let fpathTarget = dpath + '/f' + randomString(248);
fileio.copyFileSync(fpath, fpathTarget);
expect(null).assertFail();
} else {
dpath = dpath + '/d' + randomString(248);
fileio.mkdirSync(dpath);
}
}
}
catch (e) {
console.log('fileio_test_error_011 has failed for ' + e);
catch (err) {
console.log('fileio_test_error_010 has failed for ' + err);
expect(isInclude(err.message, 'Not a directory')).assertTrue();
fileio.unlinkSync(fpath);
}
});
......@@ -107,7 +80,7 @@ describe('FileIOError', function () {
/**
* @tc.number SUB_STORAGE_FileIo_test_error_1200
* @tc.name FileIo_test_error_012
* @tc.desc Function of API, flags=0o102. The test file is exist.
* @tc.desc Function of API, flags=0o102. missing mode parameter.
*/
it('FileIo_test_error_012', 0, function () {
let fpath = nextFileName('FileIo_test_error_012');
......@@ -116,8 +89,9 @@ describe('FileIOError', function () {
fileio.openSync(fpath, 0o102);
expect(null).assertFail();
}
catch (e) {
console.log('FileIo_test_error_012 has failed for ' + e);
catch (err) {
console.log('FileIo_test_error_012 has failed for ' + err);
expect(isInclude(err.message, 'called with O_CREAT/O_TMPFILE but no mode')).assertTrue();
fileio.unlinkSync(fpath);
}
});
......@@ -125,7 +99,7 @@ describe('FileIOError', function () {
/**
* @tc.number SUB_STORAGE_FileIO_OpenSync_1300
* @tc.name FileIo_test_error_013
* @tc.desc Function of API, flags=0o102
* @tc.desc Function of API, flags=0o102, missing mode parameter.
*/
it('FileIo_test_error_013', 0, function () {
let fpath = nextFileName('FileIo_test_error_013');
......@@ -133,26 +107,9 @@ describe('FileIOError', function () {
fileio.openSync(fpath, 0o102);
expect(null).assertFail();
}
catch (e) {
console.log('FileIo_test_error_013 has failed for ' + e);
}
});
/**
* @tc.number SUB_STORAGE_FileIO_OpenSync_1400
* @tc.name FileIo_test_error_014
* @tc.desc Function of API, flags=0o202. The test file is exist.
*/
it('FileIo_test_error_014', 0, function () {
let fpath = nextFileName('FileIo_test_error_014');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
fileio.openSync(fpath, 0o202);
expect(null).assertFail();
}
catch (e) {
console.log('FileIo_test_error_014 has failed for ' + e);
fileio.unlinkSync(fpath);
catch (err) {
console.log('FileIo_test_error_013 has failed for ' + err);
expect(isInclude(err.message, 'called with O_CREAT/O_TMPFILE but no mode')).assertTrue();
}
});
......@@ -167,8 +124,9 @@ describe('FileIOError', function () {
try {
fileio.openSync(fpath, 0o302, 0o666);
}
catch (e) {
console.log('FileIo_test_error_015 has failed for ' + e);
catch (err) {
console.log('FileIo_test_error_015 has failed for ' + err);
expect(isInclude(err.message, 'File exists')).assertTrue();
fileio.unlinkSync(fpath);
}
});
......@@ -185,8 +143,8 @@ describe('FileIOError', function () {
fileio.openSync(fpath, 0o100002);
expect(null).assertFail();
}
catch (e) {
console.log('FileIo_test_error_016 has failed for ' + e);
catch (err) {
console.log('FileIo_test_error_016 has failed for ' + err);
fileio.unlinkSync(fpath);
}
});
......@@ -203,28 +161,13 @@ describe('FileIOError', function () {
fileio.openSync(dpath, 0o40002);
expect(null).assertFail();
}
catch (e) {
console.log('FileIo_test_error_017 has failed for ' + e);
catch (err) {
console.log('FileIo_test_error_017 has failed for ' + err);
expect(isInclude(err.message, 'called with O_CREAT/O_TMPFILE but no mode')).assertTrue();
fileio.rmdirSync(dpath);
}
});
/**
* @tc.number SUB_STORAGE_FileIO_OpenSync_1800
* @tc.name FileIo_test_error_018
* @tc.desc Function of API, flags=0o20040002. The test file is exist.
*/
it('FileIo_test_error_018', 0, function () {
let fpath = nextFileName('FileIo_test_error_018');
try {
fileio.openSync(fpath, 0o20040002);
expect(null).assertFail();
}
catch (e) {
console.log('FileIo_test_error_018 has failed for ' + e);
}
});
/**
* @tc.number SUB_STORAGE_FileIO_OpenSync_1900
* @tc.name FileIo_test_error_019
......@@ -238,8 +181,8 @@ describe('FileIOError', function () {
fileio.openSync(fpath, 0o400002);
expect(null).assertFail();
}
catch (e) {
console.log('FileIo_test_error_019 has failed for ' + e);
catch (err) {
console.log('FileIo_test_error_019 has failed for ' + err);
fileio.unlinkSync(fpath);
}
});
......@@ -257,8 +200,8 @@ describe('FileIOError', function () {
fileio.openSync(fpath, 0o400002);
expect(null).assertFail();
}
catch (e) {
console.log('FileIo_test_error_020 has failed for ' + e);
catch (err) {
console.log('FileIo_test_error_020 has failed for ' + err);
fileio.unlinkSync(fpath);
}
});
......@@ -274,28 +217,28 @@ describe('FileIOError', function () {
fileio.openSync(fpath, 0o10000102);
expect(null).assertFail();
}
catch (e) {
console.log('FileIo_test_error_021 has failed for ' + e);
catch (err) {
console.log('FileIo_test_error_021 has failed for ' + err);
expect(isInclude(err.message, 'called with O_CREAT/O_TMPFILE but no mode')).assertTrue();
}
});
/**
* @tc.number SUB_STORAGE_FileIO_OpenSync_2200
* @tc.name FileIo_test_error_022
* @tc.desc Function of API,mode=1 The test file is exist.
* @tc.number SUB_STORAGE_FileIO_OpenSync_2300
* @tc.name FileIo_test_error_023
* @tc.desc Function of API, flags=0o200000. Invalid argument.
*/
it('FileIo_test_error_022', 0, function () {
let fpath = nextFileName('FileIo_test_error_022');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
let fpathTarget = fpath + 'f1';
it('FileIo_test_error_023', 0, function () {
let dpath = fileName('FileIo_test_error_023d');
fileio.mkdirSync(dpath);
try {
fileio.copyFileSync(fpath, fpathTarget, 1);
fileio.openSync(dpath, 0o200000);
expect(null).assertFail();
}
catch (e) {
console.log('FileIo_test_error_022 has failed for ' + e);
fileio.unlinkSync(fpath);
fileio.unlinkSync(fpathTarget);
catch (err) {
console.log('FileIo_test_error_023 has failed for ' + err);
expect(isInclude(err.message, 'Invalid argument')).assertTrue();
fileio.rmdirSync(dpath);
}
});
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册