提交 0d31d855 编写于 作者: X XTStarry

添加File和FileIO接口的测试用例

Signed-off-by: NXTStarry <gaoxiaotian@huawei.com>
上级 4dc3f350
# 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("//test/xts/tools/build/suite.gni")
group("storage") {
testonly = true
if (is_standard_system) {
deps = [ "storagefileiojstest:storagefileio_js_test" ]
}
}
# 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("//test/xts/tools/build/suite.gni")
ohos_js_hap_suite("storagefileio_js_test") {
test_hap_name = "StoragefileioJSTest"
hap_source_path = "hap/entry-debug-rich-signed.hap"
}
{
"description": "Configuration for storage file and fileio Tests",
"driver": {
"type": "JSUnitTest",
"test-timeout": "21600000",
"package": "ohos.acts.stroage.fileio",
"shell-timeout": "21600000"
},
"kits": [
{
"test-file-name": [
"StoragefileioJSTest.hap"
],
"type": "AppInstallKit",
"cleanup-apps": true
}
]
}
\ No newline at end of file
{
"devDependencies": {
"chai": "^4.3.4",
"mocha": "^9.0.1"
}
}
{
"app": {
"bundleName": "ohos.acts.stroage.fileio",
"vendor": "example",
"version": {
"code": 1000000,
"name": "1.0.0"
},
"apiVersion": {
"compatible": 4,
"target": 5,
"releaseType": "Release"
}
},
"deviceConfig": {},
"module": {
"package": "ohos.acts.stroage.fileio",
"name": ".MyApplication",
"deviceType": [
"phone"
],
"distro": {
"deliveryWithInstall": true,
"moduleName": "entry",
"moduleType": "entry",
"installationFree": true
},
"abilities": [
{
"skills": [
{
"entities": [
"entity.system.home"
],
"actions": [
"action.system.home"
]
}
],
"name": "ohos.acts.stroage.fileio.MainAbility",
"icon": "$media:icon",
"description": "$string:mainability_description",
"label": "$string:app_name",
"type": "page",
"launchType": "standard",
"visible": true
}
],
"js": [
{
"pages": [
"pages/index/index"
],
"name": "default",
"window": {
"designWidth": 720,
"autoDesignWidth": false
}
}
]
}
}
\ 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.
*/
export default {
onCreate() {
console.info('ohos.acts.distributeddatamgr.distributedfile onCreate');
},
onDestroy() {
console.info('ohos.acts.distributeddatamgr.distributedfile onCreate');
}
};
{
"strings": {
"hello": "Hello",
"world": "Test"
}
}
\ No newline at end of file
{
"strings": {
"hello": "您好",
"world": "测试"
}
}
\ No newline at end of file
.container {
flex-direction: column;
justify-content: center;
align-items: center;
}
.title {
font-size: 100px;
}
<div class="container">
<text class="title">
{{ $t('strings.hello') }} {{ title }}
</text>
</div>
/*
* 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 file from '@system.file'
import app from '@system.app'
import {Core, ExpectExtend, ReportExtend} from 'deccjsunit/index'
export default {
data: {
title: ""
},
onInit() {
this.title = this.$t('strings.world');
},
onShow() {
console.info('onShow finish')
const core = Core.getInstance()
const expectExtend = new ExpectExtend({
'id': 'extend'
})
const reportExtend = new ReportExtend(file)
// const instrumentLog = new InstrumentLog({
// 'id': 'report'
// })
core.addService('expect', expectExtend)
core.addService('report', reportExtend)
// core.addService('report', instrumentLog)
core.init()
// core.subscribeEvent('spec', instrumentLog)
// core.subscribeEvent('suite', instrumentLog)
// core.subscribeEvent('task', instrumentLog)
const configService = core.getDefaultService('config')
configService.setConfig(this)
require('../../../test/List.test')
core.execute()
},
onReady() {
},
}
\ 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'
export const FILE_CONTENT = "仙女星系 (英语: Andromeda Galaxy; M31; NGC 224 ;曾被称为 仙女座大星云 ),位于仙女座方位的拥有巨大盘状结构的 \
旋涡星系 , 梅西耶星表 编号为M31, 星云星团新总表 编号位 NGC 224 ,直径22万光年,距离地球有254万光年,是距银河系最近的大星系。"
//创建一个可读写文件
export function prepareFile(fpath, content) {
try {
let fd = fileio.openSync(fpath, 0o102, 0o666)
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 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
}
}
var fileSeed = 0
export function nextFileName(testName) {
const BASE_PATH = "/data/accounts/account_0/appdata/ohos.acts.stroage.fileio/cache/"
return BASE_PATH + testName
}
export function fileName(testName) {
const BASE_PATH = "/data/accounts/account_0/appdata/ohos.acts.stroage.fileio/files/"
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 cacheFileName(testName) {
const BASE_PATH = "/data/accounts/account_0/appdata/ohos.acts.stroage.fileio/files/cache/"
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("文件:" + fpath)
console.log("文本长度:" + 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("文件:" + fpath)
console.log("状态:存在")
return true
} catch (e) {
console.log("文件:" + fpath)
console.log("状态:不存在")
return false
}
}
export function sleep(n) {
var start = new Date().getTime();
while (true) {
if (new Date().getTime() - start > n) {
break;
}
}
}
export function randomString(len) {
len = len;
var $chars = 'aaaabbbbcccc';
var maxPos = $chars.length;
var pwd = '';
for (var i = 0; i < len; i++) {
pwd += $chars.charAt(Math.floor(Math.random() * maxPos));
}
return pwd;
}
\ 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 '@ohos.fileio';
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index'
import { FILE_CONTENT, prepareFile, nextFileName, prepareFile1, randomString } from './Common'
describe('fileIOTestDir', function () {
/**
* @tc.number SUB_STORAGE_FileIO_dir_OpenSync_0000
* @tc.name fileio_test_dir_open_sync_000
* @tc.desc Function of API, opendirSync.
*/
it('fileio_test_dir_open_sync_000', 0, function () {
let dpath = nextFileName('fileio_test_dir_open_sync_000') + 'd'
try {
expect(fileio.mkdirSync(dpath) !== null).assertTrue()
let dd = fileio.opendirSync(dpath)
expect(dd !== null).assertTrue()
expect(dd.closeSync() == null).assertTrue()
expect(fileio.rmdirSync(dpath) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_dir_open_sync_000 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_dir_OpenSync_0100
* @tc.name fileio_test_dir_open_sync_001
* @tc.desc Function of API, not set parameter.
*/
it('fileio_test_dir_open_sync_001', 0, function () {
try {
fileio.opendirSync()
expect(null).assertFail()
} catch (e) {
console.log("fileio_test_dir_open_sync_001 has failed for " + e)
}
})
/**
* @tc.number SUB_STORAGE_FileIO_dir_OpenSync_0200
* @tc.name fileio_test_dir_open_sync_002
* @tc.desc Function of API, dpath value is not exist.
*/
it('fileio_test_dir_open_sync_002', 0, function () {
let dpath = nextFileName('fileio_test_dir_open_sync_003') + 'd'
try {
fileio.opendirSync(dpath)
expect(null).assertFail()
} catch (e) {
console.log("fileio_test_dir_open_sync_002 has failed for " + e)
}
})
/**
* @tc.number SUB_STORAGE_FileIO_dir_OpenSync_0300
* @tc.name fileio_test_dir_open_sync_003
* @tc.desc Function of API, dpath too long.
*/
it('fileio_test_dir_open_sync_003', 0, function () {
let dpath = nextFileName("fileio_dir11")
fileio.mkdirSync(dpath)
try {
for (let i = 0; i < 16; i++) {
console.log("time" + i)
dpath = dpath + "/f" + randomString(248)
fileio.mkdirSync(dpath)
}
expect(null).assertFail()
} catch (e) {
console.log("fileio_test_dir_open_sync_003 has failed for " + e)
}
})
/**
* @tc.number SUB_STORAGE_FileIO_dir_OpenSync_0400
* @tc.name fileio_test_dir_open_sync_004
* @tc.desc Function of API, filename too long.
*/
it('fileio_test_dir_open_sync_004', 0, function () {
let dpath = nextFileName(randomString(256))
try {
fileio.mkdirSync(dpath)
expect(null).assertFail()
} catch (e) {
console.log("fileio_test_dir_open_sync_004 has failed for " + e)
}
})
/**
* @tc.number SUB_STORAGE_FileIO_dir_OpenSync_0500
* @tc.name fileio_test_dir_open_sync_005
* @tc.desc Function of API, uri dir too many layers.
*/
it('fileio_test_dir_open_sync_005', 0, function () {
let dpath = nextFileName("dir")
fileio.mkdirSync(dpath)
try {
for (let i = 0; i < 1024; i++) {
console.log("time" + i)
dpath = dpath + "/" + i
fileio.mkdirSync(dpath)
}
expect(null).assertFail()
} catch (e) {
console.log("fileio_test_dir_open_sync_005 has failed for " + e)
}
})
/**
* @tc.number SUB_STORAGE_FileIO_dir_OpenSync_0600
* @tc.name fileio_test_dir_open_sync_006
* @tc.desc Function of API, file name contain special character.
*/
it('fileio_test_dir_open_sync_006', 0, function () {
let dpath = nextFileName("?*:<>/|")
try {
fileio.mkdirSync(dpath)
expect(null).assertFail()
} catch (e) {
console.log("fileio_test_dir_open_sync_006 has failed for " + e)
}
})
/**
* @tc.number SUB_STORAGE_FileIO_dir_ReadSync_0000
* @tc.name fileio_test_dir_read_sync_000
* @tc.desc Function of API, readSync. The dir contains 1 file.
*/
it('fileio_test_dir_read_sync_000', 0, function () {
let dpath = nextFileName('fileio_test_dir_read_sync_000') + 'd'
let fpath = dpath + '/f0'
try {
expect(typeof (fileio.mkdirSync(dpath)) == "undefined").assertTrue()
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue()
let dd = fileio.opendirSync(dpath)
expect(dd !== null).assertTrue()
expect(dd.readSync() !== null).assertTrue()
expect(dd.closeSync() == null).assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
expect(fileio.rmdirSync(dpath) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_dir_read_sync_000 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_dir_ReadSync_0100
* @tc.name fileio_test_dir_read_sync_001
* @tc.desc Function of API, readSync. The dir contains more than 1 files.
*/
it('fileio_test_dir_read_sync_001', 0, function () {
let dpath = nextFileName('fileio_test_dir_read_sync_001') + 'd'
let fpathArray = new Array(dpath + '/f1', dpath + '/f2', dpath + '/d3')
try {
expect(fileio.mkdirSync(dpath) !== null).assertTrue()
for (let i = 0; i < 3; i++) {
if (i == 2) {
expect(fileio.mkdirSync(fpathArray[i]) !== null).assertTrue()
} else {
expect(prepareFile(fpathArray[i], FILE_CONTENT)).assertTrue()
}
}
let dd = fileio.opendirSync(dpath)
expect(dd !== null).assertTrue()
for (let i = 0; i < 3; i++) {
if (i == 2) {
let bool = typeof (dd.readSync())
expect(bool == "object").assertTrue()
console.log("---bool=" + bool)
} else {
expect(dd.readSync() !== null).assertTrue()
}
}
expect(dd.closeSync() == null).assertTrue()
for (let i = 0; i < 3; i++) {
if (i == 2) {
expect(fileio.rmdirSync(fpathArray[i]) !== null).assertTrue()
} else {
expect(fileio.unlinkSync(fpathArray[i]) !== null).assertTrue()
}
}
expect(fileio.rmdirSync(dpath) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_dir_read_sync_001 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_dir_ReadSync_0200
* @tc.name fileio_test_dir_read_sync_002
* @tc.desc Function of API, repeat read. The dir contains more than 1 files.
*/
it('fileio_test_dir_read_sync_002', 0, function () {
let dpath = nextFileName('fileio_test_dir_read_sync_002') + 'd'
let fpathArray = new Array(dpath + '/f1', dpath + '/f2', dpath + '/d3')
try {
expect(fileio.mkdirSync(dpath) !== null).assertTrue()
for (let i = 0; i < 3; i++) {
if (i == 2) {
expect(fileio.mkdirSync(fpathArray[i]) !== null).assertTrue()
} else {
expect(prepareFile(fpathArray[i], FILE_CONTENT)).assertTrue()
}
}
var dd = fileio.opendirSync(dpath)
expect(dd !== null).assertTrue()
for (let i = 0; i < 3; i++) {
expect(dd.readSync() !== null).assertTrue()
}
expect(dd.readSync() == null).assertTrue()
expect(null).assertFail()
} catch (e) {
console.log("fileio_test_dir_read_sync_002 has failed for " + e)
expect(dd.closeSync() == null).assertTrue()
for (let i = 0; i < 3; i++) {
if (i == 2) {
expect(fileio.rmdirSync(fpathArray[i]) !== null).assertTrue()
} else {
expect(fileio.unlinkSync(fpathArray[i]) !== null).assertTrue()
}
}
expect(fileio.rmdirSync(dpath) !== null).assertTrue()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_dir_ReadSync_0300
* @tc.name fileio_test_dir_read_sync_003
* @tc.desc Function of API, readSync. The dir no any files.
*/
it('fileio_test_dir_read_sync_003', 0, function () {
let dpath = nextFileName('fileio_test_dir_read_sync_003') + 'd'
let dd;
try {
expect(fileio.mkdirSync(dpath) !== null).assertTrue()
dd = fileio.opendirSync(dpath)
expect(dd !== null).assertTrue()
expect(dd.readSync() == null).assertTrue()
expect(null).assertFail()
} catch (e) {
expect(dd.closeSync() == null).assertTrue()
expect(fileio.rmdirSync(dpath) !== null).assertTrue()
console.log("fileio_test_dir_read_sync_003 has failed for " + e)
}
})
/**
* @tc.number SUB_STORAGE_FileIO_dir_ReadSync_0400
* @tc.name fileio_test_dir_read_sync_004
* @tc.desc Function of API, error parameter.
*/
it('fileio_test_dir_read_sync_004', 0, function () {
let dpath = nextFileName('fileio_test_dir_read_sync_004') + 'd'
let fpath = dpath + '/f1'
let dd
try {
expect(fileio.mkdirSync(dpath) !== null).assertTrue()
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue()
dd = fileio.opendirSync(dpath)
expect(dd !== null).assertTrue()
expect(dd.readSync(-1) == null).assertTrue()
expect(null).assertFail()
} catch (e) {
expect(dd.closeSync() == null).assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
expect(fileio.rmdirSync(dpath) !== null).assertTrue()
console.log("fileio_test_dir_read_sync_004 has failed for " + e)
}
})
/**
* @tc.number SUB_STORAGE_FileIO_dir_ReadSync_0500
* @tc.name fileio_test_dir_read_sync_005
* @tc.desc Function of API, excess files.
*/
it('fileio_test_dir_read_sync_005', 0, function () {
let dpath = nextFileName('fileio_test_dir_read_sync_005') + 'd'
let fpath = dpath + '/f'
try {
expect(typeof (fileio.mkdirSync(dpath)) == "undefined").assertTrue()
for (let i = 0; i < 10001; i++) {
expect(prepareFile(fpath + i, "test_text")).assertTrue()
}
let dd = fileio.opendirSync(dpath)
expect(dd !== null).assertTrue()
expect(dd.readSync() !== null).assertTrue()
expect(dd.closeSync() == null).assertTrue()
for (let i = 0; i < 10001; i++) {
fileio.unlinkSync(fpath + i)
}
expect(fileio.rmdirSync(dpath) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_dir_read_sync_005 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_dir_CloseSync_0000
* @tc.name fileio_test_dir_close_sync_000
* @tc.desc Function of API, closeSync.
*/
it('fileio_test_dir_close_sync_000', 0, function () {
let dpath = nextFileName('fileio_test_dir_close_sync_000') + 'd'
try {
expect(fileio.mkdirSync(dpath) !== null).assertTrue()
let dd = fileio.opendirSync(dpath)
expect(dd !== null).assertTrue()
expect(dd.closeSync() == null).assertTrue()
expect(fileio.rmdirSync(dpath) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_dir_close_sync_000 has failed for " + e)
expect(null).assertFail()
}
})
})
\ 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 { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index'
import { FILE_CONTENT, prepareFile, nextFileName } from './Common'
describe('fileIOTestDirent', function () {
/**
* @tc.number SUB_STORAGE_FileIO_dirent_name_0000
* @tc.name fileio_test_dirent_name_000
* @tc.desc Function of API, Get file name.
*/
it('fileio_test_dirent_name_000', 0, function () {
let dpath = nextFileName('fileio_test_dirent_name_000') + 'd'
let fpath = dpath + '/f1'
try {
expect(fileio.mkdirSync(dpath) !== null)
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue()
let dd = fileio.opendirSync(dpath)
expect(dd !== null).assertTrue()
let dirent = dd.readSync()
expect(dirent.name !== null).assertTrue()
expect(dd.closeSync() !== null)
expect(fileio.unlinkSync(fpath) !== null)
expect(fileio.rmdirSync(dpath) !== null)
} catch (e) {
console.log("fileio_test_dirent_name_000 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_dirent_isBlockDevice_0000
* @tc.name fileio_test_dirent_is_block_device_000
* @tc.desc Function of API, isBlockDevice. Determine whether it is a block device.
*/
it('fileio_test_dirent_is_block_device_000', 0, function () {
let dpath = nextFileName('fileio_test_dirent_is_block_device_000') + 'd'
let fpath = dpath + '/f1'
try {
expect(fileio.mkdirSync(dpath) !== null)
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue()
let dd = fileio.opendirSync(dpath)
expect(dd !== null).assertTrue()
let dirent = dd.readSync()
expect(dirent !== null).assertTrue()
expect(dirent.isBlockDevice() !== null)
expect(dd.closeSync() !== null)
expect(fileio.unlinkSync(fpath) !== null)
expect(fileio.rmdirSync(dpath) !== null)
return
} catch (e) {
console.log("fileio_test_dirent_is_block_device_000 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_dirent_isBlockDevice_0100
* @tc.name fileio_test_dirent_is_block_device_001
* @tc.desc Function of API, isBlockDevice. The parameter is - 1.
*/
it('fileio_test_dirent_is_block_device_001', 0, function () {
let dpath = nextFileName('fileio_test_dirent_is_block_device_001') + 'd'
let fpath = dpath + '/f1'
let dd
try {
expect(fileio.mkdirSync(dpath) !== null)
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue()
dd = fileio.opendirSync(dpath)
expect(dd !== null).assertTrue()
let dirent = dd.readSync()
expect(dirent !== null).assertTrue()
dirent.isBlockDevice(-1)
expect(null).assertFail()
} catch (e) {
expect(dd.closeSync() !== null)
expect(fileio.unlinkSync(fpath) !== null)
expect(fileio.rmdirSync(dpath) !== null)
console.log("fileio_test_dirent_is_block_device_001 has failed for " + e)
}
})
/**
* @tc.number SUB_STORAGE_FileIO_dirent_isCharacterDevice_0000
* @tc.name fileio_test_dirent_is_character_device_000
* @tc.desc Function of API, isCharacterDevice. Determine whether it is a character device.
*/
it('fileio_test_dirent_is_character_device_000', 0, function () {
let dpath = nextFileName('fileio_test_dirent_is_character_device_000') + 'd'
let fpath = dpath + '/f1'
try {
expect(fileio.mkdirSync(dpath) !== null)
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue()
let dd = fileio.opendirSync(dpath)
expect(dd !== null).assertTrue()
let dirent = dd.readSync()
expect(dirent !== null).assertTrue()
expect(dirent.isCharacterDevice() !== null)
expect(dd.closeSync() !== null !== null)
expect(fileio.unlinkSync(fpath) !== null)
expect(fileio.rmdirSync(dpath) !== null)
} catch (e) {
console.log("fileio_test_dirent_is_character_device_000 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_dirent_isCharacterDevice_0100
* @tc.name fileio_test_dirent_is_character_device_001
* @tc.desc Function of API, isCharacterDevice. The parameter is - 1.
*/
it('fileio_test_dirent_is_character_device_001', 0, function () {
let dpath = nextFileName('fileio_test_dirent_is_character_device_001') + 'd'
let fpath = dpath + '/f1'
let dd
try {
expect(fileio.mkdirSync(dpath) !== null)
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue()
dd = fileio.opendirSync(dpath)
expect(dd !== null).assertTrue()
let dirent = dd.readSync()
expect(dirent !== null).assertTrue()
dirent.isCharacterDevice(-1)
expect(null).assertFail()
} catch (e) {
expect(dd.closeSync() !== null)
expect(fileio.unlinkSync(fpath) !== null)
expect(fileio.rmdirSync(dpath) !== null)
console.log("fileio_test_dirent_is_character_device_001 has failed for " + e)
}
})
/**
* @tc.number SUB_STORAGE_FileIO_dirent_isDirectory_0000
* @tc.name fileio_test_dirent_is_directory_000
* @tc.desc Function of API, isDirectory. Determine whether it is a directory.
*/
it('fileio_test_dirent_is_directory_000', 0, function () {
let dpath = nextFileName('fileio_test_dirent_is_directory_000') + 'd'
let fpath = dpath + '/f1'
try {
expect(fileio.mkdirSync(dpath) !== null)
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue()
let dd = fileio.opendirSync(dpath)
expect(dd !== null).assertTrue()
let dirent = dd.readSync()
expect(dirent !== null).assertTrue()
expect(dirent.isDirectory() !== null)
expect(dd.closeSync() !== null)
expect(fileio.unlinkSync(fpath) !== null)
expect(fileio.rmdirSync(dpath) !== null)
} catch (e) {
console.log("fileio_test_dirent_is_directory_000 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_dirent_isDirectory_0100
* @tc.name fileio_test_dirent_is_directory_001
* @tc.desc Function of API, isDirectory. The parameter is - 1
*/
it('fileio_test_dirent_is_directory_001', 0, function () {
let dpath = nextFileName('fileio_test_dirent_is_directory_001') + 'd'
let fpath = dpath + '/f1'
let dd
try {
expect(fileio.mkdirSync(dpath) !== null)
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue()
dd = fileio.opendirSync(dpath)
expect(dd !== null).assertTrue()
let dirent = dd.readSync()
expect(dirent !== null).assertTrue()
dirent.isDirectory(-1)
expect(null).assertFail()
} catch (e) {
expect(dd.closeSync() !== null)
expect(fileio.unlinkSync(fpath) !== null)
expect(fileio.rmdirSync(dpath) !== null)
console.log("fileio_test_dirent_is_directory_001 has failed for " + e)
}
})
/**
* @tc.number SUB_STORAGE_FileIO_dirent_isFifo_0000
* @tc.name fileio_test_dirent_is_fifo_000
* @tc.desc Function of API, isFIFO. Determine whether it is a fifo.
*/
it('fileio_test_dirent_is_fifo_000', 0, function () {
let dpath = nextFileName('fileio_test_dirent_is_fifo_000') + 'd'
let fpath = dpath + '/f1'
try {
expect(fileio.mkdirSync(dpath) !== null)
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue()
let dd = fileio.opendirSync(dpath)
expect(dd !== null).assertTrue()
let dirent = dd.readSync()
expect(dirent !== null).assertTrue()
expect(dirent.isFIFO() !== null)
expect(dd.closeSync() !== null)
expect(fileio.unlinkSync(fpath) !== null)
expect(fileio.rmdirSync(dpath) !== null)
} catch (e) {
console.log("fileio_test_dirent_is_fifo_000 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_dirent_isFifo_0100
* @tc.name fileio_test_dirent_is_fifo_001
* @tc.desc Function of API, isFIFO. The parameter is - 1
*/
it('fileio_test_dirent_is_fifo_001', 0, function () {
let dpath = nextFileName('fileio_test_dirent_is_fifo_001') + 'd'
let fpath = dpath + '/f1'
let dd
try {
expect(fileio.mkdirSync(dpath) !== null)
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue()
dd = fileio.opendirSync(dpath)
expect(dd !== null).assertTrue()
let dirent = dd.readSync()
expect(dirent !== null).assertTrue()
dirent.isFIFO(-1)
expect(null).assertFail()
} catch (e) {
expect(dd.closeSync() !== null)
expect(fileio.unlinkSync(fpath) !== null)
expect(fileio.rmdirSync(dpath) !== null)
console.log("fileio_test_dirent_is_fifo_001 has failed for " + e)
}
})
/**
* @tc.number SUB_STORAGE_FileIO_dirent_isFile_0000
* @tc.name fileio_test_dirent_is_file_000
* @tc.desc Function of API, isFile. Determine whether it is a file.
*/
it('fileio_test_dirent_is_file_000', 0, function () {
let dpath = nextFileName('fileio_test_dirent_is_file_000') + 'd'
let fpath = dpath + '/f1'
try {
expect(fileio.mkdirSync(dpath) !== null)
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue()
let dd = fileio.opendirSync(dpath)
expect(dd !== null).assertTrue()
let dirent = dd.readSync()
expect(dirent !== null).assertTrue()
expect(dirent.isFile() !== null)
expect(dd.closeSync() !== null)
expect(fileio.unlinkSync(fpath) !== null)
expect(fileio.rmdirSync(dpath) !== null)
} catch (e) {
console.log("fileio_test_dirent_is_file_000 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_dirent_isFile_0100
* @tc.name fileio_test_dirent_is_file_001
* @tc.desc Function of API, isFile. The parameter is - 1
*/
it('fileio_test_dirent_is_file_001', 0, function () {
let dpath = nextFileName('fileio_test_dirent_is_file_001') + 'd'
let fpath = dpath + '/f1'
let dd
try {
expect(fileio.mkdirSync(dpath) !== null)
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue()
dd = fileio.opendirSync(dpath)
expect(dd !== null).assertTrue()
let dirent = dd.readSync()
expect(dirent !== null).assertTrue()
dirent.isFile(-1)
expect(null).assertFail()
} catch (e) {
expect(dd.closeSync() !== null)
expect(fileio.unlinkSync(fpath) !== null)
expect(fileio.rmdirSync(dpath) !== null)
console.log("fileio_test_dirent_is_file_001 has failed for " + e)
}
})
/**
* @tc.number SUB_STORAGE_FileIO_dirent_isSocket_0000
* @tc.name fileio_test_dirent_is_socket_000
* @tc.desc Function of API, isSocket. Determine whether it is a socket.
*/
it('fileio_test_dirent_is_socket_000', 0, function () {
let dpath = nextFileName('fileio_test_dirent_is_socket_000') + 'd'
let fpath = dpath + '/f1'
try {
expect(fileio.mkdirSync(dpath) !== null)
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue()
let dd = fileio.opendirSync(dpath)
expect(dd !== null).assertTrue()
let dirent = dd.readSync()
expect(dirent !== null).assertTrue()
expect(dirent.isSocket() !== null)
expect(dd.closeSync() !== null)
expect(fileio.unlinkSync(fpath) !== null)
expect(fileio.rmdirSync(dpath) !== null)
} catch (e) {
console.log("fileio_test_dirent_is_socket_000 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_dirent_isSocket_0100
* @tc.name fileio_test_dirent_is_socket_001
* @tc.desc Function of API, isSocket. The parameter is - 1
*/
it('fileio_test_dirent_is_socket_001', 0, function () {
let dpath = nextFileName('fileio_test_dirent_is_socket_001') + 'd'
let fpath = dpath + '/f1'
let dd
try {
expect(fileio.mkdirSync(dpath) !== null)
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue()
dd = fileio.opendirSync(dpath)
expect(dd !== null).assertTrue()
let dirent = dd.readSync()
expect(dirent !== null).assertTrue()
dirent.isSocket(-1)
expect(null).assertFail()
} catch (e) {
expect(dd.closeSync() !== null)
expect(fileio.unlinkSync(fpath) !== null)
expect(fileio.rmdirSync(dpath) !== null)
console.log("fileio_test_dirent_is_socket_001 has failed for " + e)
}
})
/**
* @tc.number SUB_STORAGE_FileIO_dirent_isSymbolicLlink_0000
* @tc.name fileio_test_dirent_is_symbolic_link_000
* @tc.desc Function of API, isSymbolicLink. Determine whether it is a symbolic link.
*/
it('fileio_test_dirent_is_symbolic_link_000', 0, function () {
let dpath = nextFileName('fileio_test_dirent_is_symbolic_link_000') + 'd'
let fpath = dpath + '/f1'
try {
expect(fileio.mkdirSync(dpath) !== null)
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue()
let dd = fileio.opendirSync(dpath)
expect(dd !== null).assertTrue()
let dirent = dd.readSync()
expect(dirent !== null).assertTrue()
expect(dirent.isSymbolicLink() !== null)
expect(dd.closeSync() !== null)
expect(fileio.unlinkSync(fpath) !== null)
expect(fileio.rmdirSync(dpath) !== null)
} catch (e) {
console.log("fileio_test_dirent_is_symbolic_link_000 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_dirent_isSymbolicLlink_0100
* @tc.name fileio_test_dirent_is_symbolic_link_001
* @tc.desc Function of API, isSymbolicLink. The parameter is - 1
*/
it('fileio_test_dirent_is_symbolic_link_001', 0, function () {
let dpath = nextFileName('fileio_test_dirent_is_symbolic_link_001') + 'd'
let fpath = dpath + '/f1'
let dd
try {
expect(fileio.mkdirSync(dpath) !== null)
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue()
dd = fileio.opendirSync(dpath)
expect(dd !== null).assertTrue()
let dirent = dd.readSync()
expect(dirent !== null).assertTrue()
dirent.isSymbolicLink(-1)
expect(null).assertFail()
} catch (e) {
expect(dd.closeSync() !== null)
expect(fileio.unlinkSync(fpath) !== null)
expect(fileio.rmdirSync(dpath) !== null)
console.log("fileio_test_dirent_is_symbolic_link_001 has failed for " + e)
}
})
})
/*
* 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.
*/
require('./File.test.js')
require('./FileIO.test.js')
require('./FileIODir.test.js')
require('./FileIODirent.test.js')
require('./FileIOStat.test.js')
require('./FileIOStream.test.js')
\ No newline at end of file
{
"string": [
{
"name": "app_name",
"value": "MyApplication"
},
{
"name": "mainability_description",
"value": "JS_Phone_Empty Feature Ability"
}
]
}
\ No newline at end of file
......@@ -39,6 +39,7 @@ _all_test_packages = [
"${ACTS_ROOT}/updater:update",
"${ACTS_ROOT}/graphic:graphic",
"${ACTS_ROOT}/ace:ace",
"${ACTS_ROOT}/storage:storage",
]
_all_test_packages_ivi = [
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册