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

!1568 修改fileio测试套报错,file代码和黄区同步

Merge pull request !1568 from raoxian/master
......@@ -2,7 +2,7 @@
"description": "Configuration for storage file and fileio Tests",
"driver": {
"type": "JSUnitTest",
"test-timeout": "600000",
"test-timeout": "1800000",
"package": "ohos.acts.storage.fileio",
"shell-timeout": "60000"
},
......
......@@ -3745,12 +3745,11 @@ describe('fileIOTest', function () {
let fpath = await nextFileName('fileio_test_fchown_sync_006');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
let stat = fileio.statSync(fpath);
let UID = stat.uid
let GID = null
let UID = stat.uid;
let fd;
try {
fd = fileio.openSync(fpath);
expect(fileio.fchownSync(fd, UID, GID));
fileio.fchownSync(fd, UID, 0);
expect(null).assertFail();
}
catch (e) {
......@@ -3769,11 +3768,9 @@ describe('fileIOTest', function () {
let fpath = await nextFileName('fileio_test_fchown_sync_007');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
let fd;
let UID = null
let GID = null
try {
fd = fileio.openSync(fpath, 0o2);
expect(fileio.fchownSync(fd, UID, GID));
fileio.fchownSync(fd, 0, 0);
expect(null).assertFail();
}
catch (e) {
......
......@@ -447,7 +447,7 @@ describe('fileio_read', function () {
*/
it('fileio_test_read_async_006', 0, async function (done) {
let fd;
const invalidOffset = 99999;
const invalidOffset = 999;
let fpath = await nextFileName('fileio_test_read_async_006');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
......@@ -458,6 +458,7 @@ describe('fileio_read', function () {
offset: invalidOffset,
});
expect(null).assertFail();
done();
} catch (e) {
expect(fileio.closeSync(fd) == null).assertTrue();
expect(fileio.unlinkSync(fpath) == null).assertTrue();
......
......@@ -59,8 +59,7 @@ describe('fileio_readtext', function () {
try {
let str = fileio.readTextSync(fpath, { position: pos });
console.log(str);
expect(str == FILE_CONTENT.substr(pos, FILE_CONTENT.length)).assertTrue();
expect(str == FILE_CONTENT.substring(pos, FILE_CONTENT.length + 1)).assertTrue();
expect(fileio.unlinkSync(fpath) == null).assertTrue();
} catch (e) {
console.log('fileio_test_readtext_sync_001 has failed for ' + e);
......@@ -85,7 +84,7 @@ describe('fileio_readtext', function () {
try {
let str = fileio.readTextSync(fpath, { position: pos, length: len });
expect(str == FILE_CONTENT.substr(pos, len)).assertTrue();
expect(str == FILE_CONTENT.substring(pos, len + 1)).assertTrue();
expect(fileio.unlinkSync(fpath) == null).assertTrue();
} catch (e) {
console.log('fileio_test_readtext_sync_002 has failed for ' + e);
......
......@@ -2,7 +2,7 @@
"description": "Configuration for storage file Tests",
"driver": {
"type": "JSUnitTest",
"test-timeout": "60000",
"test-timeout": "600000",
"package": "ohos.acts.storage.file",
"shell-timeout": "60000"
},
......
......@@ -14,7 +14,7 @@
*/
import fileio from '@ohos.fileio';
import featureAbility from '@ohos.ability.featureAbility';
import featureAbility from '@ohos.ability.featureAbility'
export const FILE_CONTENT = 'hello world';
......@@ -31,7 +31,7 @@ export function prepareFile(fpath, content) {
fileio.fsyncSync(fd)
fileio.closeSync(fd)
return true
}
}
catch (e) {
console.log('Failed to prepareFile for ' + e)
return false
......@@ -48,46 +48,21 @@ export function prepareEmptyFile(fpath) {
return false
}
}
export function fileToReadOnly(fpath) {
try {
let fd = fileio.openSync(fpath, 0o1)
fileio.fchmodSync(fd, 0o444)
fileio.fsyncSync(fd)
fileio.closeSync(fd)
return true
}
catch (e) {
console.log('Failed to fileToReadOnly for ' + e);
return false
}
}
export function fileToWriteOnly(fpath) {
try {
let fd = fileio.openSync(fpath, 0o2)
fileio.fchmodSync(fd, 0o222)
fileio.fsyncSync(fd)
fileio.closeSync(fd)
return true
}
catch (e) {
console.log('Failed to fileToWriteOnly ' + e)
return false
}
}
export async function nextFileName(testName) {
let context = featureAbility.getContext();
var context = featureAbility.getContext();
let data = await context.getFilesDir();
let BASE_PATH = data.substring(0, data.length - 5) + 'cache/';
return BASE_PATH + testName
}
export async function fileName(testName) {
let context = featureAbility.getContext();
var context = featureAbility.getContext();
let data = await context.getFilesDir();
let BASE_PATH = data + '/';
return BASE_PATH + testName
}
export async function cacheFileName(testName) {
let context = featureAbility.getContext();
var context = featureAbility.getContext();
let data = await context.getFilesDir();
let BASE_PATH = data + '/cache/';
return BASE_PATH + testName
......@@ -101,6 +76,7 @@ export function sleep(n) {
}
}
}
export function randomString(num) {
let len= num;
var $chars = 'aaaabbbbcccc';
......@@ -112,23 +88,8 @@ export function randomString(num) {
return pwd;
}
function isIntNum(val) {
return typeof val === 'number' && val % 1 === 0;
}
function isString(str) {
return (typeof str == 'string') && str.constructor == String;
}
function isBoolean(val) {
return typeof val == 'boolean';
}
export {
fileio,
isIntNum,
isString,
isBoolean,
describe,
beforeAll,
beforeEach,
......
......@@ -24,7 +24,7 @@ import {
it,
expect
}
from 'deccjsunit/index'
from 'deccjsunit/index'
import {
FILE_CONTENT,
prepareFile,
......@@ -35,7 +35,7 @@ import {
nextFileName,
sleep
}
from './Common'
from './Common'
describe('fileTest', function () {
......@@ -1006,18 +1006,18 @@ describe('fileTest', function () {
*/
it('File_writeArrayBuffer_009', 0, async function (done) {
let buf = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]);
file.writeArrayBuffer({
uri: 'internal://cache/File_writeArrayBuffer_009',
buffer: buf,
success: function () {
console.log('File_writeArrayBuffer_009 call success');
done();
},
fail: function (data, code) {
console.log('File_writeArrayBuffer_009 fail');
expect(null).assertFail();
},
});
file.writeArrayBuffer({
uri: 'internal://cache/File_writeArrayBuffer_009',
buffer: buf,
success: function () {
console.log('File_writeArrayBuffer_009 call success');
done();
},
fail: function (data, code) {
console.log('File_writeArrayBuffer_009 fail');
expect(null).assertFail();
},
});
file.readArrayBuffer({
uri: 'internal://cache/File_writeArrayBuffer_009',
success: function (data) {
......@@ -1318,9 +1318,7 @@ describe('fileTest', function () {
done();
},
fail: function (data, code) {
console.error(
"call fail callback fail, code: " + code + ", data: " + data
);
console.error("call fail callback fail, code: " + code + ", data: " + data);
expect(null).assertFail();
},
});
......@@ -2823,7 +2821,7 @@ describe('fileTest', function () {
},
fail: function (data, code) {
console.log('File_Copy_005 , code: ' + code + ', data: ' + data);
expect(code == 301).assertTrue();
expect(code == 300).assertTrue();
done();
},
});
......@@ -3332,7 +3330,7 @@ describe('fileTest', function () {
expect(prepareFile(fpath, FILE_CONTENT) !== null).assertTrue();
expect(prepareFile(ffpath, FILE_CONTENT) !== null).assertTrue();
expect(prepareFile(fffpath, FILE_CONTENT) !== null).assertTrue();
}
}
catch (e) {
console.log('File_List_010 has failed for ' + e);
expect(null).assertFail();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册