提交 38f1a5d9 编写于 作者: R raoxian

update storagefileioerrorjstest

Signed-off-by: Nraoxian <raoxian@huawei.com>
上级 32f56178
{ {
"description": "Configuration for storage file and fileio Tests", "description": "Configuration for storage fileio Tests",
"driver": { "driver": {
"type": "JSUnitTest", "type": "JSUnitTest",
"test-timeout": "60000", "test-timeout": "60000",
"package": "ohos.acts.stroage.fileio", "package": "ohos.acts.storage.fileioerror",
"shell-timeout": "60000" "shell-timeout": "60000"
}, },
"kits": [ "kits": [
......
{ {
"app": { "app": {
"bundleName": "ohos.acts.stroage.fileio", "bundleName": "ohos.acts.storage.fileioerror",
"vendor": "example", "vendor": "example",
"version": { "version": {
"code": 1000000, "code": 1000000,
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
}, },
"deviceConfig": {}, "deviceConfig": {},
"module": { "module": {
"package": "ohos.acts.stroage.fileio", "package": "ohos.acts.storage.fileioerror",
"name": ".MyApplication", "name": ".MyApplication",
"deviceType": [ "deviceType": [
"phone" "phone"
...@@ -36,7 +36,7 @@ ...@@ -36,7 +36,7 @@
] ]
} }
], ],
"name": "ohos.acts.stroage.fileio.MainAbility", "name": "ohos.acts.storage.fileioerror.MainAbility",
"icon": "$media:icon", "icon": "$media:icon",
"description": "$string:mainability_description", "description": "$string:mainability_description",
"label": "$string:app_name", "label": "$string:app_name",
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
* limitations under the License. * limitations under the License.
*/ */
import fileio from '@system.fileio' import fileio from '@ohos.fileio'
export const FILE_CONTENT = 'hello world' export const FILE_CONTENT = 'hello world'
...@@ -31,133 +31,16 @@ export function prepareFile(fpath, content) { ...@@ -31,133 +31,16 @@ export function prepareFile(fpath, content) {
return false return false
} }
} }
export function prepareFile1(fpath, content) {
try {
let fd = fileio.openSync(fpath, 0o102, 0o777)
fileio.ftruncateSync(fd)
fileio.writeSync(fd, content)
fileio.fsyncSync(fd)
fileio.closeSync(fd)
return true
}
catch (e) {
console.log('Failed to prepareFile for ' + e)
return false
}
}
export function prepareEmptyFile(fpath) {
try {
let fd = fileio.openSync(fpath, 0o102, 0o777)
fileio.closeSync(fd)
return true
}
catch (e) {
console.log('Failed to prepareFile for ' + e)
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 function fileToReadAndWrite(fpath) {
try {
let fd = fileio.openSync(fpath, 0o1)
fileio.fchmodSync(fd, 0o777)
fileio.fsyncSync(fd)
fileio.closeSync(fd)
return true
}
catch (e) {
console.log('Failed to fileToReadAndWrite ' + e);
return false
}
}
export function appName(testName) {
const BASE_PATH = '/data/accounts/account_0/appdata/ohos.acts.stroage.fileio/'
return BASE_PATH + testName
}
export function nextFileName(testName) { export function nextFileName(testName) {
const BASE_PATH = '/data/accounts/account_0/appdata/ohos.acts.stroage.fileio/cache/' const BASE_PATH = '/data/storage/el2/base/haps/entry/cache/'
return BASE_PATH + testName return BASE_PATH + testName
} }
export function fileName(testName) { export function fileName(testName) {
const BASE_PATH = '/data/accounts/account_0/appdata/ohos.acts.stroage.fileio/files/' const BASE_PATH = '/data/storage/el2/base/haps/entry/files/'
return BASE_PATH + testName
}
export function cacheFileName(testName) {
const BASE_PATH = '/data/accounts/account_0/appdata/ohos.acts.stroage.fileio/files/cache/'
return BASE_PATH + testName
}
export function differentFileName(testName) {
const BASE_PATH = '/data/accounts/account_0/ohos.acts.distributeddatamgr.distributedfile/'
return BASE_PATH + testName
}
export function differentCacheName(testName) {
const BASE_PATH = '/data/accounts/account_0/ohos.acts.distributeddatamgr.distributedfile/cache/'
return BASE_PATH + testName return BASE_PATH + testName
} }
export function getFileTextLen(fpath) {
let ss
try {
ss = fileio.Stream.createStreamSync(fpath, 'r+')
expect(ss !== null).assertTrue()
let len = ss.readSync(new ArrayBuffer(4096))
console.log('file:' + fpath)
console.log('file length:' + len)
expect(ss.closeSync() !== null).assertTrue()
return len
}
catch (e) {
console.log('Failed to getFileTextLen ' + e)
expect(ss.closeSync() !== null).assertTrue()
return null
}
}
export function isFileExist(fpath) {
try {
expect(fileio.accessSync(fpath) !== null).assertTrue()
console.log('file:' + fpath)
console.log('status:exist')
return true
}
catch (e) {
console.log('file:' + fpath)
console.log('status:non-existen')
return false
}
}
export function sleep(n) {
var start = new Date().getTime();
while (true) {
if (new Date().getTime() - start > n) {
break;
}
}
}
export function randomString(num) { export function randomString(num) {
let len= num; let len= num;
var $chars = 'aaaabbbbcccc'; var $chars = 'aaaabbbbcccc';
...@@ -168,3 +51,11 @@ export function randomString(num) { ...@@ -168,3 +51,11 @@ export function randomString(num) {
} }
return pwd; return pwd;
} }
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
/*
* Copyright (C) 2021 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import fileio from '@system.fileio'
import file from '@system.file';
import {
describe,
it,
expect
}
from 'deccjsunit/index'
import {
FILE_CONTENT,
prepareFile,
fileName,
randomString,
}
from './Common'
describe('FileError', function () {
/**
* @tc.number SUB_STORAGE_File_test_error_0000
* @tc.name File_test_error_000
* @tc.desc Function of API, Move files when disk space is full.
* Create the file (file_test_error) in advance and give 777 permission,
* path:/data/accounts/account_0/appdata/ohos.acts.stroage.fileio/files/file_test_error
*/
it('File_test_error_000', 0, async function (done) {
file.move({
srcUri: 'internal://app/file_test_error',
dstUri: 'internal://cache/file_test_error',
success: function (uri) {
console.log('file_test_error_000 pass, uri:' + uri);
expect(null).assertFail();
},
fail: function (data, code) {
console.log('file_test_error_000 call move fail, code: ' + code + ', data: ' + data);
done();
},
});
setTimeout(
function(){
expect(null).assertFail();
done();
},30)
});
/**
* @tc.number SUB_STORAGE_File_test_error_0100
* @tc.name File_test_error_001
* @tc.desc Function of API, Copy files when disk space is full.
* Create the file (file_test_error) in advance and give 777 permission,
* path:/data/accounts/account_0/appdata/ohos.acts.stroage.fileio/files/file_test_error
*/
it('File_test_error_001', 0, async function (done) {
file.copy({
srcUri: 'internal://app/file_test_error',
dstUri: 'internal://cache/file_test_error',
success: function (uri) {
console.log('file_test_error_001 pass, uri:' + uri);
expect(null).assertFail();
},
fail: function (data, code) {
console.log('file_test_error_001 call copy fail, code: ' + code + ', data: ' + data);
done();
},
});
setTimeout(
function(){
expect(null).assertFail();
done();
},30)
});
/**
* @tc.number SUB_STORAGE_File_test_error_0200
* @tc.name File_test_error_002
* @tc.desc Function of API, Write files when disk space is full.
*/
it('File_test_error_002', 0, async function (done) {
file.writeText({
uri: 'internal://app../file_test_error',
text: FILE_CONTENT,
success: function () {
console.log('file_test_error_002 call writeText success.');
expect(null).assertFail();
},
fail: function (data, code) {
console.log('file_test_error_002 call writeText fail, code: ' + code + ', data: ' + data);
done();
},
});
setTimeout(
function(){
expect(null).assertFail();
done();
},30)
});
/**
* @tc.number SUB_STORAGE_File_test_error_0300
* @tc.name File_test_error_003
* @tc.desc Function of API, Write files when disk space is full.
*/
it('File_test_error_003', 0, async function (done) {
let buf = new Uint8Array([48, 49, 50, 51, 65, 66, 67, 68, 32, 33]);
file.writeArrayBuffer({
uri: 'internal://app/file_test_error',
buffer: buf,
success: function () {
console.log('file_test_error_003 call writeArrayBuffer success.');
expect(null).assertFail();
},
fail: function (data, code) {
console.log('file_test_error_003 call writeArrayBuffer fail, code: ' + code + ', data: ' + data);
done();
},
});
setTimeout(
function(){
expect(null).assertFail();
done();
},30)
});
/**
* @tc.number SUB_STORAGE_File_test_error_0400
* @tc.name File_test_error_004
* @tc.desc Function of API, When inode is full, verify the folder creation function
*/
it('File_test_error_004', 0, async function (done) {
file.mkdir({
uri: 'internal://app/file_test_error004d',
success: function () {
console.log('file_test_error_004 call mkdir success.');
expect(null).assertFail();
},
fail: function (data, code) {
console.log('file_test_error_004 call mkdir fail, code: ' + code + ', data: ' + data);
done();
},
});
setTimeout(
function(){
expect(null).assertFail();
done();
},30)
});
/**
* @tc.number SUB_STORAGE_File_test_error_0500
* @tc.name File_test_error_005
* @tc.desc Function of API, Prerequisites create file 200M,When ram is filled to
* the remaining 100m, verify the function of reading 200m files
*/
it('File_test_error_005', 0, async function (done) {
file.readText({
uri: 'internal://app/file_test_error_005',
success: function (data) {
console.log('file_test_error_005 pass, Content:' + data.text);
expect(null).assertFail();
},
fail: function (data, code) {
console.log('file_test_error_005 call readText fail, code: ' + code + ', data: ' + data);
done();
},
});
setTimeout(
function(){
expect(null).assertFail();
done();
},30)
});
/**
* @tc.number SUB_STORAGE_File_test_error_0600
* @tc.name File_test_error_006
* @tc.desc Function of API, Prerequisites create file 200M,When ram is filled to
* the remaining 100m, verify the function of reading 200m files
*/
it('File_test_error_006', 0, async function (done) {
file.readArrayBuffer({
uri: 'internal://app/file_test_error_006',
success: function (data) {
console.log('file_test_error_006 pass, Content:' + data.buffer);
expect(null).assertFail();
},
fail: function (data, code) {
console.log('file_test_error_006 call readArrayBuffer fail, code: ' + code + ', data: ' + data);
done();
},
});
setTimeout(
function(){
expect(null).assertFail();
done();
},30)
});
/**
* @tc.number SUB_STORAGE_File_test_error_0700
* @tc.name File_test_error_007
* @tc.desc Function of API, delete file
*/
it('File_test_error_007', 0, async function (done) {
let fpath = fileName('file_test_error_007');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
file.rmdir({
uri: 'internal://app/file_test_error_007',
recursive: true,
success: function () {
console.log('file_test_error_007 call rmdir success.');
expect(null).assertFail();
},
fail: function (data, code) {
console.log('file_test_error_007 call rmdir fail, code: ' + code + ', data: ' + data);
done();
},
});
setTimeout(
function(){
expect(null).assertFail();
done();
},30)
});
/**
* @tc.number SUB_STORAGE_File_test_error_0800
* @tc.name File_test_error_008
* @tc.desc Function of API, Try to delete the folder while the file in the folder is reading and writing
*/
it('File_test_error_008', 0, async function (done) {
file.writeText({
uri: 'internal://app/file_test_error_008',
text: randomString(4096),
success: function () {
console.log('file_test_error_008 call mkdir success.');
done();
},
fail: function (data, code) {
console.log('file_test_error_008 call mkdir fail, code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
file.rmdir({
uri: 'internal://app/file_test_error_008',
success: function () {
console.log('file_test_error_008 call rmdir success.');
expect(null).assertFail();
},
fail: function (data, code) {
console.log('file_test_error_008 call rmdir fail, code: ' + code + ', data: ' + data);
done();
},
});
setTimeout(
function(){
expect(null).assertFail();
done();
},30)
});
/**
* @tc.number SUB_STORAGE_File_test_error_0900
* @tc.name File_test_error_009
* @tc.desc Function of API, Delete non empty folder
*/
it('File_test_error_009', 0, async function (done) {
let dpath = fileName('file_test_error_009') + 'd';
let fpath = dpath + '/file_test_error_009';
expect(fileio.mkdirSync(dpath) !== null).assertTrue();
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
file.rmdir({
uri: 'internal://app/file_test_error_009d',
recursive: true,
success: function () {
console.log('file_test_error_009 call rmdir success.');
expect(null).assertFail();
},
fail: function (data, code) {
console.log('file_test_error_009 call rmdir fail, code: ' + code + ', data: ' + data);
done();
},
});
setTimeout(
function(){
expect(null).assertFail();
done();
},30)
});
/**
* @tc.number SUB_STORAGE_File_test_error_1000
* @tc.name File_test_error_010
* @tc.desc Function of API, Delete non empty folder
*/
it('File_test_error_010', 0, async function (done) {
let dpath = fileName('file_test_error_010') + 'd';
let fpath = dpath + '/file_test_error_010';
expect(fileio.mkdirSync(dpath) !== null).assertTrue();
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
file.rmdir({
uri: 'internal://app/file_test_error_010d',
recursive: false,
success: function () {
console.log('file_test_error_010 call rmdir success.');
expect(null).assertFail();
},
fail: function (data, code) {
console.log('file_test_error_010 call rmdir fail, code: ' + code + ', data: ' + data);
done();
},
});
setTimeout(
function(){
expect(null).assertFail();
done();
},30)
});
/**
* @tc.number SUB_STORAGE_File_test_error_1100
* @tc.name File_test_error_011
* @tc.desc Function of API, Unsupported same encoding format
*/
it('File_test_error_011', 0, async function (done) {
file.writeText({
uri: 'internal://app/file_test_error_011',
text: 'hello',
encoding: 'gbk',
success: function () {
console.log('file_test_error_011 call writeText success.');
expect(null).assertFail();
},
fail: function (data, code) {
console.log('file_test_error_011 call writeText fail, code: ' + code + ', data: ' + data);
done();
},
});
setTimeout(
function(){
expect(null).assertFail();
done();
},30)
});
/**
* @tc.number SUB_STORAGE_File_test_error_1200
* @tc.name File_test_error_012
* @tc.desc Function of API, Unsupported same encoding format
*/
it('File_test_error_012', 0, async function (done) {
file.writeText({
uri: 'internal://app/file_test_error_012',
text: 'Text that just for test.',
encoding: 'Utf-8',
success: function () {
console.log('file_test_error_012 call writeText success.');
done();
},
fail: function (data, code) {
console.log('file_test_error_012 call writeText fail, code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
file.readText({
uri: 'internal://app/file_test_error_012',
encoding: 'GBK',
success: function (data) {
console.log('file_test_error_012 call readText success.' + data.text);
expect(null).assertFail();
},
fail: function (data, code) {
console.log('file_test_error_012 call readText fail, code: ' + code + ', data: ' + data);
file.delete({
uri: 'internal://app/file_test_error_012',
success: function () {
console.log('file_test_error_012 call delete success');
done();
},
fail: function (data, code) {
console.log('file_test_error_012 call delete fail, code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
},
});
setTimeout(
function(){
expect(null).assertFail();
done();
},30)
});
});
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
* limitations under the License. * limitations under the License.
*/ */
import fileio from '@system.fileio' import fileio from '@ohos.fileio'
import { import {
describe, describe,
it, it,
...@@ -25,188 +25,14 @@ import { ...@@ -25,188 +25,14 @@ import {
prepareFile, prepareFile,
fileName, fileName,
nextFileName, nextFileName,
appName,
randomString, randomString,
isIntNum,
isInclude
} }
from './Common' from './Common'
describe('FileIOError', function () { describe('FileIOError', function () {
/**
* @tc.number SUB_STORAGE_FileIo_test_error_0000
* @tc.name FileIo_test_error_000
* @tc.desc Function of API, Copy files when disk space is full
* Create the file (fileio_test_error) in advance and give 777 permission,
* path:/data/accounts/account_0/appdata/ohos.acts.stroage.fileio/cache/fileio_test_error
*/
it('FileIo_test_error_000', 0, function () {
let fpath = nextFileName('fileio_test_error');
let fpathTarget = appName('fileio_test_error');
try {
expect(fileio.copyFileSync(fpath, fpathTarget) !== null).assertTrue();
expect(null).assertFail();
}
catch (e) {
console.log('fileio_test_error_000 has failed for ' + e);
}
});
/**
* @tc.number SUB_STORAGE_FileIo_test_error_0100
* @tc.name FileIo_test_error_001
* @tc.desc Function of API, mkdir files when disk space is full
*/
it('FileIo_test_error_001', 0, function () {
let dpath = nextFileName('fileio_test_error_001d');
try {
expect(fileio.mkdirSync(dpath) !== null).assertTrue();
expect(null).assertFail();
}
catch (e) {
console.log('fileio_test_error_001 has failed for ' + e);
}
});
/**
* @tc.number SUB_STORAGE_FileIo_test_error_0200
* @tc.name FileIo_test_error_002
* @tc.desc Function of API, When inode is full, verify the folder creation function
*/
it('FileIo_test_error_002', 0, function () {
let dpath = fileName('fileio_test_error_002d');
try {
expect(fileio.mkdirSync(dpath) !== null).assertTrue();
expect(null).assertFail();
}
catch (e) {
console.log('fileio_test_error_002 has failed for ' + e);
}
});
/**
* @tc.number SUB_STORAGE_FileIo_test_error_0300
* @tc.name FileIo_test_error_003
* @tc.desc Function of API, When the disk space is full, verify the synchronous write file data function
*/
it('FileIo_test_error_003', 0, function () {
let fpath = nextFileName('fileio_test_error_003');
try {
let fd = fileio.openSync(fpath, 0o102, 0o777);
expect(fd !== null).assertTrue();
expect(fileio.writeSync(fd, FILE_CONTENT) !== null).assertTrue();
expect(fileio.closeSync(fd) !== null).assertTrue();
expect(null).assertFail();
}
catch (e) {
console.log('fileio_test_error_003 has failed for ' + e);
}
});
/**
* @tc.number SUB_STORAGE_FileIo_test_error_0400
* @tc.name FileIo_test_error_004
* @tc.desc Function of API, When the disk space is full,
* verify synchronization and write the buffer data back to the disk for data synchronization
*/
it('FileIo_test_error_004', 0, function () {
let fpath = nextFileName('fileio_test_error_004');
try {
let fd = fileio.openSync(fpath, 0o102, 0o777);
expect(fd !== null).assertTrue();
expect(fileio.fsyncSync(fd) !== null).assertTrue();
expect(fileio.closeSync(fd) !== null).assertTrue();
expect(null).assertFail();
}
catch (e) {
console.log('fileio_test_error_004 has failed for ' + e);
}
});
/**
* @tc.number SUB_STORAGE_FileIo_test_error_0500
* @tc.name FileIo_test_error_005
* @tc.desc Function of API, Open 200m file function when there is 100m left in RAM
* Create a 200m file (fileio_test_error_005) and grant 777 permissions,
* path:/data/accounts/account_0/appdata/ohos.acts.stroage.fileio/cache/fileio_test_error_005
*/
it('FileIo_test_error_005', 0, function () {
let fpath = nextFileName('fileio_test_error_005');
try {
let fd = fileio.openSync(fpath);
expect(fd !== null).assertTrue();
expect(fileio.closeSync(fd) !== null).assertTrue();
expect(null).assertFail();
}
catch (e) {
console.log('fileio_test_error_005 has failed for ' + e);
}
});
/**
* @tc.number SUB_STORAGE_FileIo_test_error_0600
* @tc.name FileIo_test_error_006
* @tc.desc Function of API, Read 200m file function when there is 100m left in RAM
* Create a 200m file (fileio_test_error_005) and grant 777 permissions,
* path:/data/accounts/account_0/appdata/ohos.acts.stroage.fileio/cache/fileio_test_error_005
*/
it('FileIo_test_error_006', 0, function () {
let fpath = nextFileName('fileio_test_error_005');
try {
let fd = fileio.openSync(fpath);
expect(fd !== null).assertTrue();
let rlen = fileio.readSync(fd, new ArrayBuffer(209715200));
expect(rlen == 209715200).assertTrue();
expect(fileio.closeSync(fd) !== null).assertTrue();
expect(null).assertFail();
}
catch (e) {
console.log('fileio_test_error_006 has failed for ' + e);
}
});
/**
* @tc.number SUB_STORAGE_FileIo_test_error_0700
* @tc.name FileIo_test_error_007
* @tc.desc Function of API, Verify the function of obtaining
* 200m file stream synchronously when 100m ram is left
* Create a 200m file (fileio_test_error_005) and grant 777 permissions,
* path:/data/accounts/account_0/appdata/ohos.acts.stroage.fileio/cache/fileio_test_error_005
*/
it('FileIo_test_error_007', 0, function () {
let fpath = nextFileName('fileio_test_error_005');
try {
let ss = fileio.createStreamSync(fpath, 'r+');
expect(ss !== null).assertTrue();
expect(ss.closeSync() !== null).assertTrue();
expect(null).assertFail();
}
catch (e) {
console.log('fileio_test_error_007 has failed for ' + e);
}
});
/**
* @tc.number SUB_STORAGE_FileIo_test_error_0800
* @tc.name FileIo_test_error_008
* @tc.desc Function of API, Read 200m file function when there is 100m left in RAM
* Create a 200m file (fileio_test_error_005) and grant 777 permissions,
* path:/data/accounts/account_0/appdata/ohos.acts.stroage.fileio/cache/fileio_test_error_005
*/
it('FileIo_test_error_008', 0, function () {
let fpath = nextFileName('fileio_test_error_005');
try {
let ss = fileio.createStreamSync(fpath, 'r+');
expect(ss !== null).assertTrue();
let rlen = ss.readSync(new ArrayBuffer(209715200));
expect(rlen == 209715200).assertTrue();
expect(ss.closeSync() !== null).assertTrue();
expect(null).assertFail();
}
catch (e) {
console.log('fileio_test_error_008 has failed for ' + e);
}
});
/** /**
* @tc.number SUB_STORAGE_FileIo_test_error_0900 * @tc.number SUB_STORAGE_FileIo_test_error_0900
* @tc.name FileIo_test_error_009 * @tc.name FileIo_test_error_009
...@@ -218,18 +44,20 @@ describe('FileIOError', function () { ...@@ -218,18 +44,20 @@ describe('FileIOError', function () {
fileio.mkdirSync(dpath); fileio.mkdirSync(dpath);
expect(prepareFile(fpath, 'hello')).assertTrue(); expect(prepareFile(fpath, 'hello')).assertTrue();
try { try {
expect(fileio.rmdirSync(dpath) !== null).assertTrue(); let fd = fileio.openSync(dpath);
expect(null).assertFail(); expect(isIntNum(fd)).assertTrue();
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);
} }
}); });
/** /**
* @tc.number SUB_STORAGE_FileIo_test_error1000 * @tc.number SUB_STORAGE_FileIo_test_error_1000
* @tc.name FileIo_test_error_010 * @tc.name FileIo_test_error_010
* @tc.desc Function of API, delete file * @tc.desc Function of API, delete file
*/ */
...@@ -237,49 +65,22 @@ describe('FileIOError', function () { ...@@ -237,49 +65,22 @@ describe('FileIOError', function () {
let fpath = fileName('fileio_test_error_010f'); let fpath = fileName('fileio_test_error_010f');
expect(prepareFile(fpath, 'hello')).assertTrue(); expect(prepareFile(fpath, 'hello')).assertTrue();
try { try {
expect(fileio.rmdirSync(fpath) !== null).assertTrue(); let fd = fileio.openSync(fpath);
expect(isIntNum(fd)).assertTrue();
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);
expect(isInclude(err.message, 'Not a directory')).assertTrue();
fileio.unlinkSync(fpath); fileio.unlinkSync(fpath);
} }
}); });
/** /**
* @tc.number SUB_STORAGE_FileIo_test_error_1100 * @tc.number SUB_STORAGE_FileIo_test_error_1200
* @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');
fileio.openSync(fpath, 0o102, 0o777);
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);
expect(fileio.copyFileSync(fpath, fpathTarget) !== null).assertTrue();
console.log((i + 1) + ' copy success');
expect(null).assertFail();
} else {
dpath = dpath + '/d' + randomString(248);
fileio.mkdirSync(dpath);
console.log((i + 1) + ' mkdir success');
}
}
}
catch (e) {
console.log('fileio_test_error_011 has failed for ' + e);
}
});
/**
* @tc.number SUB_STORAGE_FileIo_test_error_0120
* @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');
...@@ -288,16 +89,17 @@ describe('FileIOError', function () { ...@@ -288,16 +89,17 @@ 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(fileio.unlinkSync(fpath) !== null).assertTrue(); expect(isInclude(err.message, 'called with O_CREAT/O_TMPFILE but no mode')).assertTrue();
fileio.unlinkSync(fpath);
} }
}); });
/** /**
* @tc.number SUB_STORAGE_FileIO_OpenSync_0130 * @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');
...@@ -305,31 +107,14 @@ describe('FileIOError', function () { ...@@ -305,31 +107,14 @@ 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_0140
* @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);
expect(fileio.unlinkSync(fpath) !== null).assertTrue();
} }
}); });
/** /**
* @tc.number SUB_STORAGE_FileIO_OpenSync_0150 * @tc.number SUB_STORAGE_FileIO_OpenSync_1500
* @tc.name FileIo_test_error_015 * @tc.name FileIo_test_error_015
* @tc.desc Function of API, flags=0o302. The test file is exist. * @tc.desc Function of API, flags=0o302. The test file is exist.
*/ */
...@@ -337,17 +122,17 @@ describe('FileIOError', function () { ...@@ -337,17 +122,17 @@ describe('FileIOError', function () {
let fpath = nextFileName('FileIo_test_error_015'); let fpath = nextFileName('FileIo_test_error_015');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try { try {
fileio.openSync(fpath, 0o302); fileio.openSync(fpath, 0o302, 0o666);
expect(null).assertFail();
} }
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(fileio.unlinkSync(fpath) !== null).assertTrue(); expect(isInclude(err.message, 'File exists')).assertTrue();
fileio.unlinkSync(fpath);
} }
}); });
/** /**
* @tc.number SUB_STORAGE_FileIO_OpenSync_0160 * @tc.number SUB_STORAGE_FileIO_OpenSync_1600
* @tc.name FileIo_test_error_016 * @tc.name FileIo_test_error_016
* @tc.desc Function of API, flags=0o100002. The test file is exist. * @tc.desc Function of API, flags=0o100002. The test file is exist.
*/ */
...@@ -358,48 +143,33 @@ describe('FileIOError', function () { ...@@ -358,48 +143,33 @@ 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);
expect(fileio.unlinkSync(fpath) !== null).assertTrue(); fileio.unlinkSync(fpath);
} }
}); });
/** /**
* @tc.number SUB_STORAGE_FileIO_OpenSync_0170 * @tc.number SUB_STORAGE_FileIO_OpenSync_1700
* @tc.name FileIo_test_error_017 * @tc.name FileIo_test_error_017
* @tc.desc Function of API, flags=0o40002 The test file is exist. * @tc.desc Function of API, flags=0o40002 The test file is exist.
*/ */
it('FileIo_test_error_017', 0, function () { it('FileIo_test_error_017', 0, function () {
let dpath = nextFileName('FileIo_test_error_017'); let dpath = nextFileName('FileIo_test_error_017');
expect(fileio.mkdirSync(dpath) !== null).assertTrue(); fileio.mkdirSync(dpath);
try { try {
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(fileio.rmdirSync(dpath) !== null).assertTrue(); expect(isInclude(err.message, 'called with O_CREAT/O_TMPFILE but no mode')).assertTrue();
} fileio.rmdirSync(dpath);
});
/**
* @tc.number SUB_STORAGE_FileIO_OpenSync_0180
* @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_0190 * @tc.number SUB_STORAGE_FileIO_OpenSync_1900
* @tc.name FileIo_test_error_019 * @tc.name FileIo_test_error_019
* @tc.desc Function of API, flags=0o400002. The test file is exist. * @tc.desc Function of API, flags=0o400002. The test file is exist.
*/ */
...@@ -411,14 +181,14 @@ describe('FileIOError', function () { ...@@ -411,14 +181,14 @@ 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);
expect(fileio.unlinkSync(fpath) !== null).assertTrue(); fileio.unlinkSync(fpath);
} }
}); });
/** /**
* @tc.number SUB_STORAGE_FileIO_OpenSync_0200 * @tc.number SUB_STORAGE_FileIO_OpenSync_2000
* @tc.name FileIo_test_error_020 * @tc.name FileIo_test_error_020
* @tc.desc Function of API, flags=0o400002. The test file is exist. * @tc.desc Function of API, flags=0o400002. The test file is exist.
*/ */
...@@ -430,14 +200,14 @@ describe('FileIOError', function () { ...@@ -430,14 +200,14 @@ 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);
expect(fileio.unlinkSync(fpath) !== null).assertTrue(); fileio.unlinkSync(fpath);
} }
}); });
/** /**
* @tc.number SUB_STORAGE_FileIO_OpenSync_0210 * @tc.number SUB_STORAGE_FileIO_OpenSync_2100
* @tc.name FileIo_test_error_021 * @tc.name FileIo_test_error_021
* @tc.desc Function of API, flags=0o10000102. The test file is exist. * @tc.desc Function of API, flags=0o10000102. The test file is exist.
*/ */
...@@ -447,27 +217,28 @@ describe('FileIOError', function () { ...@@ -447,27 +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_0220 * @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_021 has failed for ' + e); console.log('FileIo_test_error_023 has failed for ' + err);
expect(fileio.unlinkSync(fpath) !== null).assertTrue(); 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.
先完成此消息的编辑!
想要评论请 注册