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

!3175 update storagefileioerrorjstest

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