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

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

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