提交 be85f8d8 编写于 作者: O openharmony_ci 提交者: Gitee

!474 浏览文件删除重复的FileIO测试用例

Merge pull request !474 from XTStarry/master
......@@ -18,7 +18,6 @@ group("distributeddatamgr") {
deps = [
"appdatamgrjstest/hap:appdatamgr_js_test",
"distributeddatamgrjstest/hap:distributeddatamgr_js_test",
"distributedfilejstest:distributedfile_js_test",
]
} else {
deps = [
......
# 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("distributedfile_js_test") {
test_hap_name = "DistributedfileJSTest"
hap_source_path = "hap/entry-debug-rich-signed.hap"
}
{
"description": "Configuration for distributed file Tests",
"driver": {
"type": "JSUnitTest",
"test-timeout": "21600000",
"package": "ohos.acts.distributeddatamgr.distributedfile",
"shell-timeout": "21600000"
},
"kits": [
{
"test-file-name": [
"DistributedfileJSTest.hap"
],
"type": "AppInstallKit",
"cleanup-apps": true
}
]
}
{
"app": {
"bundleName": "ohos.acts.distributeddatamgr.distributedfile",
"vendor": "example",
"version": {
"code": 1,
"name": "1.0"
},
"apiVersion": {
"compatible": 4,
"target": 4
}
},
"deviceConfig": {},
"module": {
"package": "ohos.acts.distributeddatamgr.distributedfile",
"name": ".DistributedFileJSTest",
"deviceType": [
"phone"
],
"distro": {
"deliveryWithInstall": true,
"moduleName": "entry",
"moduleType": "entry"
},
"abilities": [
{
"skills": [
{
"entities": [
"entity.system.home"
],
"actions": [
"action.system.home"
]
}
],
"name": "ohos.acts.distributeddatamgr.distributedfile.MainAbility",
"icon": "$media:icon",
"description": "$string:mainability_description",
"label": "DistributedFileJSTest",
"type": "page",
"launchType": "standard"
}
],
"js": [
{
"pages": [
"pages/index/index"
],
"name": "default",
"window": {
"designWidth": 720,
"autoDesignWidth": false
}
}
]
}
}
/*
* 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 device from '@system.device';
export default {
onCreate() {
console.info('ohos.acts.distributeddatamgr.distributedfile onCreate');
},
onDestroy() {
console.info('ohos.acts.distributeddatamgr.distributedfile onCreate');
}
};
{
"strings": {
"hello": "Hello",
"world": "World"
}
}
\ 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)
core.addService('expect', expectExtend)
core.addService('report', reportExtend)
core.init()
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 '@ohos.fileio'
export const FILE_CONTENT = "hello, world"
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
}
}
var fileSeed = 0
export function nextFileName(testName) {
const BASE_PATH = "/data/accounts/account_0/appdata/ohos.acts.distributeddatamgr.distributedfile/cache/"
return BASE_PATH + testName + fileSeed++
}
\ 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 bundle_mgr from '@ohos.bundle_mgr'
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index'
import { FILE_CONTENT, prepareFile, nextFileName } from './Common'
describe('fileIOTest', function () {
/**
* @tc.number SUB_DF_FileIO_UnlinkSync_0000
* @tc.name fileio_test_unlink_sync_000
* @tc.desc Test unlinkSync() interface.
*/
it('fileio_test_unlink_sync_000', 0, function () {
let fpath = nextFileName('fileIOTest')
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue()
try {
expect(fileio.unlinkSync(fpath)).assertNull()
} catch (e) {
console.log("fileio_test_unlink_sync_000 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_DF_FileIO_UnlinkSync_0010
* @tc.name fileio_test_unlink_sync_001
* @tc.desc Test unlinkSync() interface.
*/
it('fileio_test_unlink_sync_001', 0, function () {
try {
fileio.unlinkSync()
expect(null).assertFail()
} catch (e) {
}
})
/**
* @tc.number SUB_DF_FileIO_UnlinkSync_0020
* @tc.name fileio_test_unlink_sync_002
* @tc.desc Test unlinkSync() interface.
*/
it('fileio_test_unlink_sync_002', 0, function () {
let fpath = nextFileName('fileIOTest')
try {
fileio.unlinkSync(fpath)
expect(null).assertFail()
} catch (e) {
}
})
/**
* @tc.number SUB_DF_FileIO_AccessSync_0000
* @tc.name fileio_test_access_sync_000
* @tc.desc Test accessSync() interface.
*/
it('fileio_test_access_sync_000', 0, function () {
let fpath = nextFileName('fileio_test_access_sync_000')
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue()
try {
expect(fileio.accessSync(fpath)).assertNull()
expect(fileio.unlinkSync(fpath)).assertNull()
} catch (e) {
console.log("fileio_test_access_sync_000 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_DF_FileIO_AccessSync_0010
* @tc.name fileio_test_access_sync_001
* @tc.desc Test accessSync() interface.
*/
it('fileio_test_access_sync_001', 0, function () {
try {
fileio.accessSync()
expect(null).assertFail()
} catch (e) {
}
})
/**
* @tc.number SUB_DF_FileIO_AccessSync_0020
* @tc.name fileio_test_access_sync_002
* @tc.desc Test accessSync() interface.
*/
it('fileio_test_access_sync_002', 0, function () {
let fpath = nextFileName('fileIOTest')
try {
fileio.accessSync(fpath)
expect(null).assertFail()
} catch (e) {
}
})
/**
* @tc.number SUB_DF_FileIO_OpenCloseSync_0000
* @tc.name fileio_test_open_close_sync_000
* @tc.desc Test openSync() and closeSync() interfaces.
*/
it('fileio_test_open_close_sync_000', 0, function () {
let fpath = nextFileName('fileio_test_open_close_sync_000')
try {
let fd = fileio.openSync(fpath, 0o102, 0o666)
expect(fd).assertInstanceOf('Number')
expect(fileio.closeSync(fd)).assertNull()
expect(fileio.unlinkSync(fpath)).assertNull()
} catch (e) {
console.log("fileio_test_open_close_sync_000 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_DF_FileIO_OpenSync_0000
* @tc.name fileio_test_open_sync_000
* @tc.desc Test openSync() interface.
*/
it('fileio_test_open_sync_000', 0, function () {
try {
fileio.openSync("/", 0o102, 0o666)
expect(null).assertFail()
} catch (e) {
}
})
/**
* @tc.number SUB_DF_FileIO_OpenSync_0010
* @tc.name fileio_test_open_sync_001
* @tc.desc Test openSync() interface.
*/
it('fileio_test_open_sync_001', 0, function () {
let fpath = nextFileName('fileio_test_open_sync_001')
try {
fileio.openSync(fpath, 0o102)
expect(null).assertFail()
} catch (e) {
}
})
/**
* @tc.number SUB_DF_FileIO_CloseSync_0000
* @tc.name fileio_test_close_sync_000
* @tc.desc Test closeSync() interface.
*/
it('fileio_test_close_sync_000', 0, function () {
try {
fileio.closeSync()
expect(null).assertFail()
} catch (e) {
}
})
/**
* @tc.number SUB_DF_FileIO_CloseSync_0010
* @tc.name fileio_test_close_sync_001
* @tc.desc Test closeSync() interface.
*/
it('fileio_test_close_sync_001', 0, function () {
try {
fileio.closeSync(-1)
expect(null).assertFail()
} catch (e) {
}
})
/**
* @tc.number SUB_DF_FileIO_WriteSync_0000
* @tc.name fileio_test_write_sync_000
* @tc.desc Test writeSync() interface.
*/
it('fileio_test_write_sync_000', 0, function () {
let fpath = nextFileName('fileio_test_write_sync_000')
try {
let fd = fileio.openSync(fpath, 0o102, 0o666)
expect(fd).assertInstanceOf('Number')
expect(fileio.writeSync(fd, FILE_CONTENT)).assertEqual(FILE_CONTENT.length)
expect(fileio.closeSync(fd)).assertNull()
expect(fileio.unlinkSync(fpath)).assertNull()
} catch (e) {
console.log("fileio_test_write_sync_000 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_DF_FileIO_WriteSync_0010
* @tc.name fileio_test_write_sync_001
* @tc.desc Test writeSync() interface.
*/
it('fileio_test_write_sync_001', 0, function () {
let fpath = nextFileName('fileio_test_write_sync_001')
try {
let fd = fileio.openSync(fpath, 0o102, 0o666)
expect(fd).assertInstanceOf('Number')
expect(fileio.writeSync(fd, FILE_CONTENT, {
encoding: "utf-8",
})).assertEqual(FILE_CONTENT.length)
expect(fileio.closeSync(fd)).assertNull()
expect(fileio.unlinkSync(fpath)).assertNull()
} catch (e) {
console.log("fileio_test_write_sync_001 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_DF_FileIO_WriteSync_0020
* @tc.name fileio_test_write_sync_002
* @tc.desc Test writeSync() interface.
*/
it('fileio_test_write_sync_002', 0, function () {
let fpath = nextFileName('fileio_test_write_sync_002')
try {
let fd = fileio.openSync(fpath, 0o102, 0o666)
expect(fd).assertInstanceOf('Number')
expect(fileio.writeSync(fd, FILE_CONTENT, {
offset: 1,
})).assertEqual(FILE_CONTENT.length - 1)
expect(fileio.closeSync(fd)).assertNull()
expect(fileio.unlinkSync(fpath)).assertNull()
} catch (e) {
console.log("fileio_test_write_sync_002 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_DF_FileIO_WriteSync_0030
* @tc.name fileio_test_write_sync_003
* @tc.desc Test writeSync() interface.
*/
it('fileio_test_write_sync_003', 0, function () {
let fpath = nextFileName('fileio_test_write_sync_003')
try {
let fd = fileio.openSync(fpath, 0o102, 0o666)
expect(fd).assertInstanceOf('Number')
expect(fileio.writeSync(fd, FILE_CONTENT, {
length: FILE_CONTENT.length - 1,
})).assertEqual(FILE_CONTENT.length - 1)
expect(fileio.closeSync(fd)).assertNull()
expect(fileio.unlinkSync(fpath)).assertNull()
} catch (e) {
console.log("fileio_test_write_sync_003 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_DF_FileIO_WriteSync_0040
* @tc.name fileio_test_write_sync_004
* @tc.desc Test writeSync() interface.
*/
it('fileio_test_write_sync_004', 0, function () {
let fpath = nextFileName('fileio_test_write_sync_004')
try {
let fd = fileio.openSync(fpath, 0o102, 0o666)
expect(fd).assertInstanceOf('Number')
expect(fileio.writeSync(fd, FILE_CONTENT, {
offset: 1,
length: 1,
})).assertEqual(1)
expect(fileio.closeSync(fd)).assertNull()
expect(fileio.unlinkSync(fpath)).assertNull()
} catch (e) {
console.log("fileio_test_write_sync_004 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_DF_FileIO_WriteSync_0050
* @tc.name fileio_test_write_sync_005
* @tc.desc Test writeSync() interface.
*/
it('fileio_test_write_sync_005', 0, function () {
let fpath = nextFileName('fileio_test_write_sync_005')
const invalidOffset = 999
let fd
try {
fd = fileio.openSync(fpath, 0o102, 0o666)
expect(fd).assertInstanceOf('Number')
expect(fileio.writeSync(fd, FILE_CONTENT, {
offset: invalidOffset,
})).assertEqual(1)
expect(null).assertFail()
} catch (e) {
expect(fileio.closeSync(fd)).assertNull()
expect(fileio.unlinkSync(fpath)).assertNull()
}
})
/**
* @tc.number SUB_DF_FileIO_WriteSync_0060
* @tc.name fileio_test_write_sync_006
* @tc.desc Test writeSync() interface.
*/
it('fileio_test_write_sync_006', 0, function () {
let fpath = nextFileName('fileio_test_write_sync_006')
const invalidLength = 999
let fd
try {
fd = fileio.openSync(fpath, 0o102, 0o666)
expect(fd).assertInstanceOf('Number')
expect(fileio.writeSync(fd, FILE_CONTENT, {
length: invalidLength,
})).assertEqual(1)
expect(null).assertFail()
} catch (e) {
expect(fileio.closeSync(fd)).assertNull()
expect(fileio.unlinkSync(fpath)).assertNull()
}
})
/**
* @tc.number SUB_DF_FileIO_WriteSync_0070
* @tc.name fileio_test_write_sync_007
* @tc.desc Test writeSync() interface.
*/
it('fileio_test_write_sync_007', 0, function () {
try {
fileio.writeSync()
expect(null).assertFail()
} catch (e) {
}
})
/**
* @tc.number SUB_DF_FileIO_WriteSync_0080
* @tc.name fileio_test_write_sync_008
* @tc.desc Test writeSync() interface.
*/
it('fileio_test_write_sync_008', 0, function () {
try {
fileio.writeSync(-1, FILE_CONTENT)
expect(null).assertFail()
} catch (e) {
}
})
/**
* @tc.number SUB_DF_FileIO_ReadSync_0000
* @tc.name fileio_test_read_sync_000
* @tc.desc Test readSync() interface.
*/
it('fileio_test_read_sync_000', 0, function () {
let fpath = nextFileName('fileio_test_read_sync_000')
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue()
try {
let fd = fileio.openSync(fpath, 0o2)
expect(fd).assertInstanceOf('Number')
let len = fileio.readSync(fd, new ArrayBuffer(4096))
expect(len).assertEqual(FILE_CONTENT.length)
expect(fileio.closeSync(fd)).assertNull()
expect(fileio.unlinkSync(fpath)).assertNull()
} catch (e) {
console.log("fileio_test_read_sync_000 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_DF_FileIO_ReadSync_0001
* @tc.name fileio_test_read_sync_001
* @tc.desc Test readSync() interface.
*/
it('fileio_test_read_sync_001', 0, function () {
let bufLen = 5
expect(FILE_CONTENT.length).assertLarger(bufLen)
let fpath = nextFileName('fileio_test_read_sync_001')
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue()
try {
let fd = fileio.openSync(fpath, 0o2)
expect(fd).assertInstanceOf('Number')
let len = fileio.readSync(fd, new ArrayBuffer(bufLen), {
offset: 1,
})
expect(len).assertEqual(bufLen - 1)
expect(fileio.closeSync(fd)).assertNull()
expect(fileio.unlinkSync(fpath)).assertNull()
} catch (e) {
console.log("fileio_test_read_sync_001 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_DF_FileIO_ReadSync_0020
* @tc.name fileio_test_read_sync_002
* @tc.desc Test readSync() interface.
*/
it('fileio_test_read_sync_002', 0, function () {
let fpath = nextFileName('fileio_test_read_sync_002')
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue()
try {
let fd = fileio.openSync(fpath, 0o2)
expect(fd).assertInstanceOf('Number')
let len = fileio.readSync(fd, new ArrayBuffer(4096), {
length: 1,
})
expect(len).assertEqual(1)
expect(fileio.closeSync(fd)).assertNull()
expect(fileio.unlinkSync(fpath)).assertNull()
} catch (e) {
console.log("fileio_test_read_sync_002 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_DF_FileIO_ReadSync_0030
* @tc.name fileio_test_read_sync_003
* @tc.desc Test readSync() interface.
*/
it('fileio_test_read_sync_003', 0, function () {
let fd
const invalidOffset = 99999
let fpath = nextFileName('fileio_test_read_sync_003')
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue()
try {
fd = fileio.openSync(fpath, 0o2)
expect(fd).assertInstanceOf('Number')
fileio.readSync(fd, new ArrayBuffer(4096), {
offset: invalidOffset,
})
expect(null).assertFail()
} catch (e) {
expect(fileio.closeSync(fd)).assertNull()
expect(fileio.unlinkSync(fpath)).assertNull()
}
})
/**
* @tc.number SUB_DF_FileIO_ReadSync_0040
* @tc.name fileio_test_read_sync_004
* @tc.desc Test readSync() interface.
*/
it('fileio_test_read_sync_004', 0, function () {
let fd
const invalidLength = 9999
let fpath = nextFileName('fileio_test_read_sync_004')
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue()
try {
fd = fileio.openSync(fpath, 0o2)
expect(fd).assertInstanceOf('Number')
fileio.readSync(fd, new ArrayBuffer(4096), {
length: invalidLength,
})
expect(null).assertFail()
} catch (e) {
expect(fileio.closeSync(fd)).assertNull()
expect(fileio.unlinkSync(fpath)).assertNull()
}
})
/**
* @tc.number SUB_DF_FileIO_ReadSync_0050
* @tc.name fileio_test_read_sync_005
* @tc.desc Test readSync() interface.
*/
it('fileio_test_read_sync_005', 0, function () {
let fpath = nextFileName('fileio_test_read_sync_005')
let fd
try {
fileio.readSync(-1, new ArrayBuffer(4096))
expect(null).assertFail()
} catch (e) {
}
})
/**
* @tc.number SUB_DF_FileIO_ReadSync_0060
* @tc.name fileio_test_read_sync_006
* @tc.desc Test readSync() interface.
*/
it('fileio_test_read_sync_006', 0, function () {
let fpath = nextFileName('fileio_test_read_sync_006')
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue()
try {
let fd = fileio.openSync(fpath, 0o2)
expect(fd).assertInstanceOf('Number')
let len = fileio.readSync(fd, new ArrayBuffer(4096), {
position: 1,
})
expect(len).assertEqual(FILE_CONTENT.length - 1)
expect(fileio.closeSync(fd)).assertNull()
expect(fileio.unlinkSync(fpath)).assertNull()
} catch (e) {
console.log("fileio_test_read_sync_006 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_DF_FileIO_ReadSync_0070
* @tc.name fileio_test_read_sync_007
* @tc.desc Test readSync() interface.
*/
it('fileio_test_read_sync_007', 0, function () {
let fpath = nextFileName('fileio_test_read_sync_007')
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue()
try {
let fd = fileio.openSync(fpath, 0o2)
expect(fd).assertInstanceOf('Number')
let invalidPos = FILE_CONTENT.length + 1
let len = fileio.readSync(fd, new ArrayBuffer(4096), {
position: invalidPos,
})
expect(len).assertEqual(0)
expect(fileio.closeSync(fd)).assertNull()
expect(fileio.unlinkSync(fpath)).assertNull()
} catch (e) {
console.log("fileio_test_read_sync_007 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_DF_FileIO_ChmodSync_0000
* @tc.name fileio_test_chmod_sync_000
* @tc.desc Test chmodSync() interface.
*/
it('fileio_test_chmod_sync_000', 0, function () {
let fpath = nextFileName('fileio_test_chmod_sync_000')
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue()
try {
expect(fileio.chmodSync(fpath, 0o660)).assertNull()
expect(fileio.statSync(fpath).mode & 0o777).assertEqual(0o660)
expect(fileio.unlinkSync(fpath)).assertNull()
} catch (e) {
console.log("fileio_test_chmod_sync_000 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_DF_FileIO_ChmodSync_0010
* @tc.name fileio_test_chmod_sync_001
* @tc.desc Test chmodSync() interface.
*/
it('fileio_test_chmod_sync_001', 0, function () {
let fpath = nextFileName('fileio_test_chmod_sync_001')
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue()
try {
fileio.chmodSync(fpath)
expect(null).assertFail()
} catch (e) {
expect(fileio.unlinkSync(fpath)).assertNull()
}
})
/**
* @tc.number SUB_DF_FileIO_ChmodSync_0020
* @tc.name fileio_test_chmod_sync_002
* @tc.desc Test chmodSync() interface.
*/
it('fileio_test_chmod_sync_002', 0, function () {
let fpath = nextFileName('fileio_test_chmod_sync_002')
try {
fileio.chmodSync(fpath, 0o660)
expect(null).assertFail()
} catch (e) {
}
})
/**
* @tc.number SUB_DF_FileIO_CopyFileSync_0000
* @tc.name fileio_test_copy_file_sync_000
* @tc.desc Test copyFileSync() interface.
*/
it('fileio_test_copy_file_sync_000', 0, function () {
let fpath = nextFileName('fileio_test_copy_file_sync_000')
let fpathTarget = fpath + 'tgt'
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue()
try {
expect(fileio.copyFileSync(fpath, fpathTarget)).assertNull()
expect(fileio.unlinkSync(fpath)).assertNull()
expect(fileio.unlinkSync(fpathTarget)).assertNull()
} catch (e) {
console.log("fileio_test_copy_file_sync_000 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_DF_FileIO_CopyFileSync_0010
* @tc.name fileio_test_copy_file_sync_001
* @tc.desc Test copyFileSync() interface.
*/
it('fileio_test_copy_file_sync_001', 0, function () {
let fpath = nextFileName('fileio_test_copy_file_sync_000')
let fpathTarget = fpath + 'tgt'
try {
fileio.copyFileSync(fpath, fpathTarget)
expect(null).assertFail()
} catch (e) {
}
})
/**
* @tc.number SUB_DF_FileIO_CopyFileSync_0020
* @tc.name fileio_test_copy_file_sync_002
* @tc.desc Test copyFileSync() interface.
*/
it('fileio_test_copy_file_sync_002', 0, function () {
try {
fileio.copyFileSync()
expect(null).assertFail()
} catch (e) {
}
})
/**
* @tc.number SUB_DF_FileIO_TruncateSync_0000
* @tc.name fileio_test_truncate_sync_000
* @tc.desc Test truncateSync() interface.
*/
it('fileio_test_truncate_sync_000', 0, function () {
let fpath = nextFileName('fileio_test_truncate_sync_000')
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue()
try {
expect(fileio.truncateSync(fpath)).assertNull()
expect(fileio.statSync(fpath).size).assertEqual(0)
expect(fileio.unlinkSync(fpath)).assertNull()
} catch (e) {
console.log("fileio_test_truncate_sync_000 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_DF_FileIO_TruncateSync_0010
* @tc.name fileio_test_truncate_sync_001
* @tc.desc Test truncateSync() interface.
*/
it('fileio_test_truncate_sync_001', 0, function () {
let fpath = nextFileName('fileio_test_truncate_sync_001')
try {
fileio.truncateSync(fpath)
expect(null).assertFail()
} catch (e) {
}
})
/**
* @tc.number SUB_DF_FileIO_TruncateSync_0020
* @tc.name fileio_test_truncate_sync_002
* @tc.desc Test truncateSync() interface.
*/
it('fileio_test_truncate_sync_002', 0, function () {
try {
fileio.truncateSync()
expect(null).assertFail()
} catch (e) {
}
})
/**
* @tc.number SUB_DF_FileIO_RenameSync_0000
* @tc.name fileio_test_rename_sync_000
* @tc.desc Test renameSync() interface.
*/
it('fileio_test_rename_sync_000', 0, function () {
let fpath = nextFileName('fileio_test_rename_sync_000')
let fpathTarget = fpath + 'tgt'
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue()
try {
expect(fileio.renameSync(fpath, fpathTarget)).assertNull()
expect(fileio.accessSync(fpathTarget)).assertNull()
expect(fileio.unlinkSync(fpathTarget)).assertNull()
} catch (e) {
console.log("fileio_test_rename_sync_000 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_DF_FileIO_RenameSync_0010
* @tc.name fileio_test_rename_sync_001
* @tc.desc Test renameSync() interface.
*/
it('fileio_test_rename_sync_001', 0, function () {
let fpath = nextFileName('fileio_test_rename_sync_001')
let fpathTarget = fpath + 'tgt'
try {
fileio.renameSync(fpath, fpathTarget)
expect(null).assertFail()
} catch (e) {
}
})
/**
* @tc.number SUB_DF_FileIO_RenameSync_0020
* @tc.name fileio_test_rename_sync_002
* @tc.desc Test renameSync() interface.
*/
it('fileio_test_rename_sync_002', 0, function () {
let fpath = nextFileName('fileio_test_rename_sync_002')
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue()
try {
fileio.renameSync(fpath, "/")
} catch (e) {
expect(fileio.unlinkSync(fpath)).assertNull()
}
})
/**
* @tc.number SUB_DF_FileIO_FchmodSync_0000
* @tc.name fileio_test_fchmod_sync_000
* @tc.desc Test fchmodSync() interface.
*/
it('fileio_test_fchmod_sync_000', 0, function () {
let fpath = nextFileName('fileio_test_fchmod_sync_000')
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue()
try {
let fd = fileio.openSync(fpath, 0o2)
expect(fileio.fchmodSync(fd, 0o660)).assertNull()
expect(fileio.statSync(fpath).mode & 0o777).assertEqual(0o660)
expect(fileio.unlinkSync(fpath)).assertNull()
} catch (e) {
console.log("fileio_test_fchmod_sync_000 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_DF_FileIO_FchmodSync_0010
* @tc.name fileio_test_fchmod_sync_001
* @tc.desc Test fchmodSync() interface.
*/
it('fileio_test_fchmod_sync_001', 0, function () {
try {
expect(fileio.fchmodSync(-1, 0o660)).assertNull()
expect(null).assertFail()
} catch (e) {
}
})
/**
* @tc.number SUB_DF_FileIO_FtruncateSync_0000
* @tc.name fileio_test_ftruncate_sync_000
* @tc.desc Test ftruncateSync() interface.
*/
it('fileio_test_ftruncate_sync_000', 0, function () {
let fpath = nextFileName('fileio_test_ftruncate_sync_000')
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue()
try {
let fd = fileio.openSync(fpath, 0o2)
expect(fileio.ftruncateSync(fd)).assertNull()
expect(fileio.statSync(fpath).size).assertEqual(0)
expect(fileio.unlinkSync(fpath)).assertNull()
} catch (e) {
console.log("fileio_test_ftruncate_sync_000 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_DF_FileIO_FtruncateSync_0010
* @tc.name fileio_test_ftruncate_sync_001
* @tc.desc Test ftruncateSync() interface.
*/
it('fileio_test_ftruncate_sync_001', 0, function () {
try {
fileio.ftruncateSync(-1)
expect(null).assertFail()
} catch (e) {
}
})
/**
* @tc.number SUB_DF_FileIO_FsyncSync_0000
* @tc.name fileio_test_fsync_sync_000
* @tc.desc Test fsyncSync() interface.
*/
it('fileio_test_fsync_sync_000', 0, function () {
let fpath = nextFileName('fileio_test_fsync_sync_000')
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue()
try {
let fd = fileio.openSync(fpath, 0o2)
expect(fileio.fsyncSync(fd)).assertNull()
expect(fileio.unlinkSync(fpath)).assertNull()
} catch (e) {
console.log("fileio_test_fsync_sync_000 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_DF_FileIO_FsyncSync_0010
* @tc.name fileio_test_fsync_sync_001
* @tc.desc Test fsyncSync() interface.
*/
it('fileio_test_fsync_sync_001', 0, function () {
try {
fileio.fsyncSync(-1)
expect(null).assertFail()
} catch (e) {
}
})
/**
* @tc.number SUB_DF_FileIO_MkdirSync_0000
* @tc.name fileio_test_mkdir_sync_rmdir_sync_000
* @tc.desc Test mkdirSync() interface.
*/
it('fileio_test_mkdir_sync_rmdir_sync_000', 0, function () {
let dpath = nextFileName('fileio_test_fsync_sync_000') + 'd'
try {
expect(fileio.mkdirSync(dpath)).assertNull()
expect(fileio.rmdirSync(dpath)).assertNull()
} catch (e) {
console.log("fileio_test_mkdir_sync_rmdir_sync_000 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_DF_FileIO_MkdirSync_0010
* @tc.name fileio_test_mkdir_sync_rmdir_sync_001
* @tc.desc Test mkdirSync() interface.
*/
it('fileio_test_mkdir_sync_rmdir_sync_001', 0, function () {
try {
expect(fileio.mkdirSync("/")).assertNull()
expect(null).assertFail()
} catch (e) {
}
})
/**
* @tc.number SUB_DF_FileIO_ChownSync_0000
* @tc.name fileio_test_chown_sync_000
* @tc.desc Test chownSync() interface.
*/
it('fileio_test_chown_sync_000', 0, async function (done) {
let fpath = nextFileName('fileio_test_chown_sync_000')
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue()
let bundleInfo = await bundle_mgr.getBundleInfo("ohos.acts.distributeddatamgr.distributedfile")
let UID = bundleInfo.uid
let GID = bundleInfo.gid
try {
expect(fileio.chownSync(fpath, UID, GID))
expect(fileio.unlinkSync(fpath)).assertNull()
} catch (e) {
console.log("fileio_test_chown_sync_000 has failed for " + e)
expect(null).assertFail()
}
done()
})
/**
* @tc.number SUB_DF_FileIO_ChownSync_0010
* @tc.name fileio_test_chown_sync_001
* @tc.desc Test chownSync() interface.
*/
it('fileio_test_chown_sync_001', 0, async function (done) {
let bundleInfo = await bundle_mgr.getBundleInfo("ohos.acts.distributeddatamgr.distributedfile")
let UID = bundleInfo.uid
let GID = bundleInfo.gid
let fpath = nextFileName('fileio_test_chown_sync_001')
try {
expect(fileio.chownSync(fpath, UID, GID))
expect(null).assertFail()
} catch (e) {
}
done()
})
/**
* @tc.number SUB_DF_FileIO_ChownSync_0020
* @tc.name fileio_test_chown_sync_002
* @tc.desc Test chownSync() interface.
*/
it('fileio_test_chown_sync_002', 0, function () {
let fpath = nextFileName('fileio_test_chown_sync_002')
try {
expect(fileio.chownSync(fpath, 0, 0))
expect(null).assertFail()
} catch (e) {
}
})
/**
* @tc.number SUB_DF_FileIO_FchownSync_0000
* @tc.name fileio_test_fchown_sync_000
* @tc.desc Test fchownSync() interface.
*/
it('fileio_test_fchown_sync_000', 0, async function (done) {
let fpath = nextFileName('fileio_test_fchown_sync_000')
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue()
let bundleInfo = await bundle_mgr.getBundleInfo("ohos.acts.distributeddatamgr.distributedfile")
let UID = bundleInfo.uid
let GID = bundleInfo.gid
try {
let fd = fileio.openSync(fpath, 0o2)
expect(fileio.fchownSync(fd, UID, GID))
expect(fd).assertInstanceOf('Number')
expect(fileio.closeSync(fd)).assertNull()
expect(fileio.unlinkSync(fpath)).assertNull()
} catch (e) {
console.log("fileio_test_fchown_sync_000 has failed for " + e)
expect(null).assertFail()
}
done()
})
/**
* @tc.number SUB_DF_FileIO_FchownSync_0010
* @tc.name fileio_test_fchown_sync_001
* @tc.desc Test fchownSync() interface.
*/
it('fileio_test_fchown_sync_001', 0, async function (done) {
let bundleInfo = await bundle_mgr.getBundleInfo("ohos.acts.distributeddatamgr.distributedfile")
let UID = bundleInfo.uid
let GID = bundleInfo.gid
try {
expect(fileio.fchownSync(-1, UID, GID))
expect(null).assertFail()
} catch (e) {
}
done()
})
/**
* @tc.number SUB_DF_FileIO_FchownSync_0020
* @tc.name fileio_test_fchown_sync_002
* @tc.desc Test fchownSync() interface.
*/
it('fileio_test_fchown_sync_002', 0, function () {
let fd
let fpath = nextFileName('fileio_test_fchown_sync_002')
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue()
try {
fd = fileio.openSync(fpath, 0o2)
fileio.fchownSync(fd, 0, 0)
expect(null).assertFail()
} catch (e) {
expect(fileio.closeSync(fd)).assertNull()
expect(fileio.unlinkSync(fpath)).assertNull()
}
})
})
\ 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 } from './Common'
describe('fileIOTestDir', function () {
/**
* @tc.number SUB_DF_FileIO_OpenClosedirSync_0000
* @tc.name fileio_test_dir_open_close_sync_000
* @tc.desc Test opendirSync() and Dir.closeSync() interfaces.
*/
it('fileio_test_dir_open_close_sync_000', 0, function () {
let dpath = nextFileName('fileio_test_dir_open_close_sync_000') + 'd'
try {
expect(fileio.mkdirSync(dpath)).assertNull()
let dd = fileio.opendirSync(dpath)
expect(dd !== null).assertTrue()
expect(dd.closeSync()).assertNull()
expect(fileio.rmdirSync(dpath)).assertNull()
} catch (e) {
console.log("fileio_test_dir_open_close_sync_000 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_DF_FileIO_OpenClosedirSync_0010
* @tc.name fileio_test_dir_open_close_sync_001
* @tc.desc Test opendirSync() interface.
*/
it('fileio_test_dir_open_close_sync_001', 0, function () {
try {
fileio.opendirSync()
expect(null).assertFail()
} catch (e) {
}
})
/**
* @tc.number SUB_DF_FileIO_OpenClosedirSync_0020
* @tc.name fileio_test_dir_open_close_sync_002
* @tc.desc Test opendirSync() interface.
*/
it('fileio_test_dir_open_close_sync_002', 0, function () {
let dpath = nextFileName('fileio_test_dir_read_sync_000') + 'd'
try {
fileio.opendirSync(dpath)
expect(null).assertFail()
} catch (e) {
}
})
/**
* @tc.number SUB_DF_FileIO_Dir_ReadSync_0000
* @tc.name fileio_test_dir_read_sync_000
* @tc.desc Test Dir.readSync() interface.
*/
it('fileio_test_dir_read_sync_000', 0, function () {
let dpath = nextFileName('fileio_test_dir_read_sync_000') + 'd'
let fpath = dpath + '/f1'
try {
expect(fileio.mkdirSync(dpath)).assertNull()
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue()
let dd = fileio.opendirSync(dpath)
expect(dd !== null).assertTrue()
expect(dd.readSync() != null).assertTrue()
expect(dd.closeSync()).assertNull()
expect(fileio.unlinkSync(fpath)).assertNull()
expect(fileio.rmdirSync(dpath)).assertNull()
} catch (e) {
console.log("fileio_test_dir_read_sync_000 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_DF_FileIO_Dir_ReadSync_0010
* @tc.name fileio_test_dir_read_sync_001
* @tc.desc Test Dir.readSync() interface.
*/
it('fileio_test_dir_read_sync_001', 0, function () {
let dpath = nextFileName('fileio_test_dir_read_sync_001') + 'd'
let fpath = dpath + '/f1'
let dd
try {
expect(fileio.mkdirSync(dpath)).assertNull()
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()).assertNull()
expect(fileio.unlinkSync(fpath)).assertNull()
expect(fileio.rmdirSync(dpath)).assertNull()
}
})
})
\ 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} from './Common'
describe('fileIOTestDirent', function () {
/**
* @tc.number SUB_DF_FileIO_Dir_ReadSync_0000
* @tc.name fileio_test_dirent_name_000
* @tc.desc Test Dir.readSync() interface.
*/
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)).assertNull()
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.name).assertInstanceOf('String')
expect(dd.closeSync()).assertNull()
expect(fileio.unlinkSync(fpath)).assertNull()
expect(fileio.rmdirSync(dpath)).assertNull()
} catch (e) {
console.log("fileio_test_dirent_name_000 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_DF_FileIO_Dir_IsBlockDevice_0000
* @tc.name fileio_test_dirent_is_block_device_000
* @tc.desc Test Dir.isBlockDevice() interface.
*/
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)).assertNull()
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()).assertInstanceOf('Boolean')
expect(dd.closeSync()).assertNull()
expect(fileio.unlinkSync(fpath)).assertNull()
expect(fileio.rmdirSync(dpath)).assertNull()
} catch (e) {
console.log("fileio_test_dirent_is_block_device_000 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_DF_FileIO_Dir_IsBlockDevice_0010
* @tc.name fileio_test_dirent_is_block_device_001
* @tc.desc Test Dir.isBlockDevice() interface.
*/
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)).assertNull()
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()).assertNull()
expect(fileio.unlinkSync(fpath)).assertNull()
expect(fileio.rmdirSync(dpath)).assertNull()
}
})
/**
* @tc.number SUB_DF_FileIO_Dir_IsCharacterDevice_0000
* @tc.name fileio_test_dirent_is_character_device_000
* @tc.desc Test Dir.isCharacterDevice() interface.
*/
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)).assertNull()
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()).assertInstanceOf('Boolean')
expect(dd.closeSync()).assertNull()
expect(fileio.unlinkSync(fpath)).assertNull()
expect(fileio.rmdirSync(dpath)).assertNull()
} catch (e) {
console.log("fileio_test_dirent_is_character_device_000 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_DF_FileIO_Dir_IsCharacterDevice_0010
* @tc.name fileio_test_dirent_is_character_device_001
* @tc.desc Test Dir.isCharacterDevice() interface.
*/
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)).assertNull()
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()).assertNull()
expect(fileio.unlinkSync(fpath)).assertNull()
expect(fileio.rmdirSync(dpath)).assertNull()
}
})
/**
* @tc.number SUB_DF_FileIO_Dir_IsDirectory_0000
* @tc.name fileio_test_dirent_is_directory_000
* @tc.desc Test Dir.isDirectory() interface.
*/
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)).assertNull()
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()).assertInstanceOf('Boolean')
expect(dd.closeSync()).assertNull()
expect(fileio.unlinkSync(fpath)).assertNull()
expect(fileio.rmdirSync(dpath)).assertNull()
} catch (e) {
console.log("fileio_test_dirent_is_directory_000 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_DF_FileIO_Dir_IsDirectory_0010
* @tc.name fileio_test_dirent_is_directory_001
* @tc.desc Test Dir.isDirectory() interface.
*/
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)).assertNull()
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()).assertNull()
expect(fileio.unlinkSync(fpath)).assertNull()
expect(fileio.rmdirSync(dpath)).assertNull()
}
})
/**
* @tc.number SUB_DF_FileIO_Dir_IsFIFO_0000
* @tc.name fileio_test_dirent_is_fifo_000
* @tc.desc Test Dir.isFIFO() interface.
*/
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)).assertNull()
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()).assertInstanceOf('Boolean')
expect(dd.closeSync()).assertNull()
expect(fileio.unlinkSync(fpath)).assertNull()
expect(fileio.rmdirSync(dpath)).assertNull()
} catch (e) {
console.log("fileio_test_dirent_is_fifo_000 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_DF_FileIO_Dir_IsFIFO_0010
* @tc.name fileio_test_dirent_is_fifo_001
* @tc.desc Test Dir.isFIFO() interface.
*/
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)).assertNull()
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()).assertNull()
expect(fileio.unlinkSync(fpath)).assertNull()
expect(fileio.rmdirSync(dpath)).assertNull()
}
})
/**
* @tc.number SUB_DF_FileIO_Dir_IsFILE_0000
* @tc.name fileio_test_dirent_is_file_000
* @tc.desc Test Dir.isFILE() interface.
*/
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)).assertNull()
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()).assertInstanceOf('Boolean')
expect(dd.closeSync()).assertNull()
expect(fileio.unlinkSync(fpath)).assertNull()
expect(fileio.rmdirSync(dpath)).assertNull()
} catch (e) {
console.log("fileio_test_dirent_is_file_000 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_DF_FileIO_Dir_IsFILE_0010
* @tc.name fileio_test_dirent_is_file_001
* @tc.desc Test Dir.isFILE() interface.
*/
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)).assertNull()
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()).assertNull()
expect(fileio.unlinkSync(fpath)).assertNull()
expect(fileio.rmdirSync(dpath)).assertNull()
}
})
/**
* @tc.number SUB_DF_FileIO_Dir_IsSocket_0000
* @tc.name fileio_test_dirent_is_socket_000
* @tc.desc Test Dir.isSocket() interface.
*/
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)).assertNull()
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()).assertInstanceOf('Boolean')
expect(dd.closeSync()).assertNull()
expect(fileio.unlinkSync(fpath)).assertNull()
expect(fileio.rmdirSync(dpath)).assertNull()
} catch (e) {
console.log("fileio_test_dirent_is_socket_000 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_DF_FileIO_Dir_IsSocket_0010
* @tc.name fileio_test_dirent_is_socket_001
* @tc.desc Test Dir.isSocket() interface.
*/
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)).assertNull()
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()).assertNull()
expect(fileio.unlinkSync(fpath)).assertNull()
expect(fileio.rmdirSync(dpath)).assertNull()
}
})
/**
* @tc.number SUB_DF_FileIO_Dir_IsSymbolicLink_0000
* @tc.name fileio_test_dirent_is_symbolic_link_000
* @tc.desc Test Dir.isSymbolicLink() interface.
*/
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)).assertNull()
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()).assertInstanceOf('Boolean')
expect(dd.closeSync()).assertNull()
expect(fileio.unlinkSync(fpath)).assertNull()
expect(fileio.rmdirSync(dpath)).assertNull()
} catch (e) {
console.log("fileio_test_dirent_is_symbolic_link_000 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_DF_FileIO_Dir_IsSymbolicLink_0010
* @tc.name fileio_test_dirent_is_symbolic_link_001
* @tc.desc Test Dir.isSymbolicLink() interface.
*/
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)).assertNull()
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()).assertNull()
expect(fileio.unlinkSync(fpath)).assertNull()
expect(fileio.rmdirSync(dpath)).assertNull()
}
})
})
/*
* 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 } from './Common'
describe('fileIOTestStat', function () {
/**
* @tc.number SUB_DF_FileIO_Stat_FstatSync_0000
* @tc.name fileio_test_stat_fstat_sync_000
* @tc.desc Test fileio.fstatSync() interface.
*/
it('fileio_test_stat_fstat_sync_000', 0, function () {
let fpath = nextFileName('fileio_test_stat_fstat_sync_000')
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue()
try {
let fd = fileio.openSync(fpath, 0o2)
expect(fd).assertInstanceOf('Number')
let stat = fileio.fstatSync(fd)
expect(stat !== null).assertTrue()
expect(fileio.closeSync(fd)).assertNull()
expect(fileio.unlinkSync(fpath)).assertNull()
} catch (e) {
console.log("fileio_test_stat_stat_sync_000 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_DF_FileIO_Stat_FstatSync_0010
* @tc.name fileio_test_stat_fstat_sync_001
* @tc.desc Test fstatSync() interface.
*/
it('fileio_test_stat_fstat_sync_001', 0, function () {
try {
let invalidFD = -1
fileio.fstatSync(invalidFD)
expect(null).assertFail()
} catch (e) {
}
})
/**
* @tc.number SUB_DF_FileIO_Stat_StatSync_0000
* @tc.name fileio_test_stat_stat_sync_000
* @tc.desc Test Stat.statSync() interface.
*/
it('fileio_test_stat_stat_sync_000', 0, function () {
let fpath = nextFileName('fileio_test_stat_stat_sync_000')
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue()
try {
let stat = fileio.statSync(fpath)
expect(stat !== null).assertTrue()
expect(fileio.unlinkSync(fpath)).assertNull()
} catch (e) {
console.log("fileio_test_stat_stat_sync_000 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_DF_FileIO_Stat_StatSync_0010
* @tc.name fileio_test_stat_stat_sync_001
* @tc.desc Test Stat.statSync() interface.
*/
it('fileio_test_stat_stat_sync_001', 0, function () {
let fpath = nextFileName('fileio_test_stat_stat_sync_001')
try {
let stat = fileio.statSync(fpath)
expect(null).assertFail()
} catch (e) {
}
})
/**
* @tc.number SUB_DF_FileIO_Stat_Dev_0000
* @tc.name fileio_test_stat_dev_000
* @tc.desc Test Stat.dev() interface.
*/
it('fileio_test_stat_dev_000', 0, function () {
let fpath = nextFileName('fileio_test_stat_dev_000')
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue()
try {
let stat = fileio.statSync(fpath)
expect(stat.dev).assertInstanceOf('Number')
expect(fileio.unlinkSync(fpath)).assertNull()
} catch (e) {
console.log("fileio_test_stat_dev_000 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_DF_FileIO_Stat_Ino_0000
* @tc.name fileio_test_stat_ino_000
* @tc.desc Test Stat.ino() interface.
*/
it('fileio_test_stat_ino_000', 0, function () {
let fpath = nextFileName('fileio_test_stat_ino_000')
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue()
try {
let stat = fileio.statSync(fpath)
expect(stat.ino).assertInstanceOf('Number')
expect(fileio.unlinkSync(fpath)).assertNull()
} catch (e) {
console.log("fileio_test_stat_ino_000 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_DF_FileIO_Stat_Mode_0000
* @tc.name fileio_test_stat_mode_000
* @tc.desc Test Stat.mode() interface.
*/
it('fileio_test_stat_mode_000', 0, function () {
let fpath = nextFileName('fileio_test_stat_mode_000')
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue()
try {
let stat = fileio.statSync(fpath)
expect(stat.mode).assertInstanceOf('Number')
expect(fileio.unlinkSync(fpath)).assertNull()
} catch (e) {
console.log("fileio_test_stat_mode_000 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_DF_FileIO_Stat_Nlink_0000
* @tc.name fileio_test_stat_nlink_000
* @tc.desc Test Stat.nlink() interface.
*/
it('fileio_test_stat_nlink_000', 0, function () {
let fpath = nextFileName('fileio_test_stat_nlink_000')
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue()
try {
let stat = fileio.statSync(fpath)
expect(stat.nlink).assertInstanceOf('Number')
expect(fileio.unlinkSync(fpath)).assertNull()
} catch (e) {
console.log("fileio_test_stat_nlink_000 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_DF_FileIO_Stat_Uid_0000
* @tc.name fileio_test_stat_uid_000
* @tc.desc Test Stat.uid() interface.
*/
it('fileio_test_stat_uid_000', 0, function () {
let fpath = nextFileName('fileio_test_stat_uid_000')
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue()
try {
let stat = fileio.statSync(fpath)
expect(stat.uid).assertInstanceOf('Number')
expect(fileio.unlinkSync(fpath)).assertNull()
} catch (e) {
console.log("fileio_test_stat_uid_000 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_DF_FileIO_Stat_Gid_0000
* @tc.name fileio_test_stat_gid_000
* @tc.desc Test Stat.gid() interface.
*/
it('fileio_test_stat_gid_000', 0, function () {
let fpath = nextFileName('fileio_test_stat_gid_000')
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue()
try {
let stat = fileio.statSync(fpath)
expect(stat.gid).assertInstanceOf('Number')
expect(fileio.unlinkSync(fpath)).assertNull()
} catch (e) {
console.log("fileio_test_stat_gid_000 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_DF_FileIO_Stat_Rdev_0000
* @tc.name fileio_test_stat_rdev_000
* @tc.desc Test Stat.rdev() interface.
*/
it('fileio_test_stat_rdev_000', 0, function () {
let fpath = nextFileName('fileio_test_stat_rdev_000')
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue()
try {
let stat = fileio.statSync(fpath)
expect(stat.rdev).assertInstanceOf('Number')
expect(fileio.unlinkSync(fpath)).assertNull()
} catch (e) {
console.log("fileio_test_stat_rdev_000 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_DF_FileIO_Stat_Size_0000
* @tc.name fileio_test_stat_size_000
* @tc.desc Test Stat.size() interface.
*/
it('fileio_test_stat_size_000', 0, function () {
let fpath = nextFileName('fileio_test_stat_size_000')
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue()
try {
let stat = fileio.statSync(fpath)
expect(stat.size).assertInstanceOf('Number')
expect(fileio.unlinkSync(fpath)).assertNull()
} catch (e) {
console.log("fileio_test_stat_size_000 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_DF_FileIO_Stat_Blocks_0000
* @tc.name fileio_test_stat_blocks_000
* @tc.desc Test Stat.blocks() interface.
*/
it('fileio_test_stat_blocks_000', 0, function () {
let fpath = nextFileName('fileio_test_stat_blocks_000')
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue()
try {
let stat = fileio.statSync(fpath)
expect(stat.blocks).assertInstanceOf('Number')
expect(fileio.unlinkSync(fpath)).assertNull()
} catch (e) {
console.log("fileio_test_stat_blocks_000 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_DF_FileIO_Stat_Atime_0000
* @tc.name fileio_test_stat_atime_000
* @tc.desc Test Stat.atime() interface.
*/
it('fileio_test_stat_atime_000', 0, function () {
let fpath = nextFileName('fileio_test_stat_atime_000')
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue()
try {
let stat = fileio.statSync(fpath)
expect(stat.atime).assertInstanceOf('Number')
expect(fileio.unlinkSync(fpath)).assertNull()
} catch (e) {
console.log("fileio_test_stat_atime_000 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_DF_FileIO_Stat_Mtime_0000
* @tc.name fileio_test_stat_mtime_000
* @tc.desc Test Stat.mtime() interface.
*/
it('fileio_test_stat_mtime_000', 0, function () {
let fpath = nextFileName('fileio_test_stat_mtime_000')
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue()
try {
let stat = fileio.statSync(fpath)
expect(stat.mtime).assertInstanceOf('Number')
expect(fileio.unlinkSync(fpath)).assertNull()
} catch (e) {
console.log("fileio_test_stat_mtime_000 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_DF_FileIO_Stat_Ctime_0000
* @tc.name fileio_test_stat_ctime_000
* @tc.desc Test Stat.ctime() interface.
*/
it('fileio_test_stat_ctime_000', 0, function () {
let fpath = nextFileName('fileio_test_stat_ctime_000')
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue()
try {
let stat = fileio.statSync(fpath)
expect(stat.ctime).assertInstanceOf('Number')
expect(fileio.unlinkSync(fpath)).assertNull()
} catch (e) {
console.log("fileio_test_stat_ctime_000 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_DF_FileIO_Stat_IsBlockDevice_0000
* @tc.name fileio_test_stat_is_block_device_000
* @tc.desc Test Stat.isBlockDevice() interface.
*/
it('fileio_test_stat_is_block_device_000', 0, function () {
let fpath = nextFileName('fileio_test_stat_is_block_device_000')
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue()
try {
let stat = fileio.statSync(fpath)
expect(stat.isBlockDevice()).assertInstanceOf('Boolean')
expect(fileio.unlinkSync(fpath)).assertNull()
} catch (e) {
console.log("fileio_test_stat_is_block_device_000 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_DF_FileIO_Stat_IsBlockDevice_0010
* @tc.name fileio_test_stat_is_block_device_001
* @tc.desc Test Stat.isBlockDevice() interface.
*/
it('fileio_test_stat_is_block_device_001', 0, function () {
let fpath = nextFileName('fileio_test_stat_is_block_device_001')
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue()
try {
let stat = fileio.statSync(fpath)
expect(stat.isBlockDevice()).assertFalse()
expect(fileio.unlinkSync(fpath)).assertNull()
} catch (e) {
console.log("fileio_test_stat_is_block_device_001 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_DF_FileIO_Stat_IsBlockDevice_0020
* @tc.name fileio_test_stat_is_block_device_002
* @tc.desc Test Stat.isBlockDevice() interface.
*/
it('fileio_test_stat_is_block_device_002', 0, function () {
let fpath = nextFileName('fileio_test_stat_is_block_device_002')
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue()
try {
let stat = fileio.statSync(fpath)
expect(stat.isBlockDevice(-1)).assertFalse()
expect(null).assertFail()
} catch (e) {
expect(fileio.unlinkSync(fpath)).assertNull()
}
})
/**
* @tc.number SUB_DF_FileIO_Stat_IsCharacterDevice_0000
* @tc.name fileio_test_stat_is_character_device_000
* @tc.desc Test Stat.isCharacterDevice() interface.
*/
it('fileio_test_stat_is_character_device_000', 0, function () {
let fpath = nextFileName('fileio_test_stat_is_character_device_000')
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue()
try {
let stat = fileio.statSync(fpath)
expect(stat.isCharacterDevice()).assertInstanceOf('Boolean')
expect(fileio.unlinkSync(fpath)).assertNull()
} catch (e) {
console.log("fileio_test_stat_is_character_device_000 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_DF_FileIO_Stat_IsCharacterDevice_0010
* @tc.name fileio_test_stat_is_character_device_001
* @tc.desc Test Stat.isCharacterDevice() interface.
*/
it('fileio_test_stat_is_character_device_001', 0, function () {
let fpath = nextFileName('fileio_test_stat_is_character_device_001')
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue()
try {
let stat = fileio.statSync(fpath)
expect(stat.isCharacterDevice()).assertFalse()
expect(fileio.unlinkSync(fpath)).assertNull()
} catch (e) {
console.log("fileio_test_stat_is_character_device_001 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_DF_FileIO_Stat_IsCharacterDevice_0020
* @tc.name fileio_test_stat_is_character_device_002
* @tc.desc Test Stat.isCharacterDevice() interface.
*/
it('fileio_test_stat_is_character_device_002', 0, function () {
let fpath = nextFileName('fileio_test_stat_is_character_device_002')
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue()
try {
let stat = fileio.statSync(fpath)
expect(stat.isCharacterDevice(-1)).assertFalse()
expect(null).assertFail()
} catch (e) {
expect(fileio.unlinkSync(fpath)).assertNull()
}
})
/**
* @tc.number SUB_DF_FileIO_Stat_IsDirectory_0000
* @tc.name fileio_test_stat_is_directory_000
* @tc.desc Test Stat.isDirectory() interface.
*/
it('fileio_test_stat_is_directory_000', 0, function () {
let fpath = nextFileName('fileio_test_stat_is_directory_000')
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue()
try {
let stat = fileio.statSync(fpath)
expect(stat.isDirectory()).assertInstanceOf('Boolean')
expect(fileio.unlinkSync(fpath)).assertNull()
} catch (e) {
console.log("fileio_test_stat_is_directory_000 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_DF_FileIO_Stat_IsDirectory_0010
* @tc.name fileio_test_stat_is_directory_001
* @tc.desc Test Stat.isDirectory() interface.
*/
it('fileio_test_stat_is_directory_001', 0, function () {
let fpath = nextFileName('fileio_test_stat_is_directory_001')
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue()
try {
let stat = fileio.statSync(fpath)
expect(stat.isDirectory()).assertFalse()
expect(fileio.unlinkSync(fpath)).assertNull()
} catch (e) {
console.log("fileio_test_stat_is_directory_001 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_DF_FileIO_Stat_IsDirectory_0020
* @tc.name fileio_test_stat_is_directory_002
* @tc.desc Test Stat.isDirectory() interface.
*/
it('fileio_test_stat_is_directory_002', 0, function () {
let dpath = nextFileName('fileio_test_stat_is_directory_002') + 'd'
try {
expect(fileio.mkdirSync(dpath)).assertNull()
let stat = fileio.statSync(dpath)
expect(stat.isDirectory()).assertTrue()
expect(fileio.rmdirSync(dpath)).assertNull()
} catch (e) {
console.log("fileio_test_stat_is_directory_002 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_DF_FileIO_Stat_IsDirectory_0030
* @tc.name fileio_test_stat_is_directory_003
* @tc.desc Test Stat.isDirectory() interface.
*/
it('fileio_test_stat_is_directory_003', 0, function () {
let dpath = nextFileName('fileio_test_stat_is_directory_003') + 'd'
try {
expect(fileio.mkdirSync(dpath)).assertNull()
let stat = fileio.statSync(dpath)
expect(stat.isDirectory(-1)).assertTrue()
expect(null).assertFail()
} catch (e) {
expect(fileio.rmdirSync(dpath)).assertNull()
}
})
/**
* @tc.number SUB_DF_FileIO_Stat_IsFIFO_0000
* @tc.name fileio_test_stat_is_fifo_000
* @tc.desc Test Stat.isFIFO() interface.
*/
it('fileio_test_stat_is_fifo_000', 0, function () {
let fpath = nextFileName('fileio_test_stat_is_fifo_000')
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue()
try {
let stat = fileio.statSync(fpath)
expect(stat.isFIFO()).assertInstanceOf('Boolean')
expect(fileio.unlinkSync(fpath)).assertNull()
} catch (e) {
console.log("fileio_test_stat_is_fifo_000 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_DF_FileIO_Stat_IsFIFO_0010
* @tc.name fileio_test_stat_is_fifo_001
* @tc.desc Test Stat.isFIFO() interface.
*/
it('fileio_test_stat_is_fifo_001', 0, function () {
let fpath = nextFileName('fileio_test_stat_is_fifo_001')
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue()
try {
let stat = fileio.statSync(fpath)
expect(stat.isFIFO()).assertFalse()
expect(fileio.unlinkSync(fpath)).assertNull()
} catch (e) {
console.log("fileio_test_stat_is_fifo_001 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_DF_FileIO_Stat_IsFIFO_0020
* @tc.name fileio_test_stat_is_fifo_002
* @tc.desc Test Stat.isFIFO() interface.
*/
it('fileio_test_stat_is_fifo_002', 0, function () {
let fpath = nextFileName('fileio_test_stat_is_fifo_001')
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue()
try {
let stat = fileio.statSync(fpath)
expect(stat.isFIFO(-1)).assertFalse()
expect(null).assertFail()
} catch (e) {
expect(fileio.unlinkSync(fpath)).assertNull()
}
})
/**
* @tc.number SUB_DF_FileIO_Stat_IsFILE_0000
* @tc.name fileio_test_stat_is_file_000
* @tc.desc Test Stat.isFile() interface.
*/
it('fileio_test_stat_is_file_000', 0, function () {
let fpath = nextFileName('fileio_test_stat_is_file_000')
expect(prepareFile(fpath, FILE_CONTENT)).assertInstanceOf('Boolean')
try {
let stat = fileio.statSync(fpath)
expect(stat.isFile()).assertInstanceOf('Boolean')
expect(fileio.unlinkSync(fpath)).assertNull()
} catch (e) {
console.log("fileio_test_stat_is_file_000 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_DF_FileIO_Stat_IsFILE_0010
* @tc.name fileio_test_stat_is_file_001
* @tc.desc Test Stat.isFile() interface.
*/
it('fileio_test_stat_is_file_001', 0, function () {
let fpath = nextFileName('fileio_test_stat_is_file_001')
expect(prepareFile(fpath, FILE_CONTENT)).assertInstanceOf('Boolean')
try {
let stat = fileio.statSync(fpath)
expect(stat.isFile()).assertTrue()
expect(fileio.unlinkSync(fpath)).assertNull()
} catch (e) {
console.log("fileio_test_stat_is_file_001 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_DF_FileIO_Stat_IsFILE_0020
* @tc.name fileio_test_stat_is_file_002
* @tc.desc Test Stat.isFile() interface.
*/
it('fileio_test_stat_is_file_002', 0, function () {
let dpath = nextFileName('fileio_test_stat_is_file_002')
try {
expect(fileio.mkdirSync(dpath)).assertNull()
let stat = fileio.statSync(dpath)
expect(stat.isFile()).assertFalse()
expect(fileio.rmdirSync(dpath)).assertNull()
} catch (e) {
console.log("fileio_test_stat_is_file_002 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_DF_FileIO_Stat_IsFILE_0030
* @tc.name fileio_test_stat_is_file_003
* @tc.desc Test Stat.isFile() interface.
*/
it('fileio_test_stat_is_file_003', 0, function () {
let dpath = nextFileName('fileio_test_stat_is_file_003')
try {
expect(fileio.mkdirSync(dpath)).assertNull()
let stat = fileio.statSync(dpath)
expect(stat.isFile(-1)).assertFalse()
expect(null).assertFail()
} catch (e) {
expect(fileio.rmdirSync(dpath)).assertNull()
}
})
/**
* @tc.number SUB_DF_FileIO_Stat_IsSocket_0000
* @tc.name fileio_test_stat_is_socket_000
* @tc.desc Test Stat.isSocket() interface.
*/
it('fileio_test_stat_is_socket_000', 0, function () {
let fpath = nextFileName('fileio_test_stat_is_socket_000')
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue()
try {
let stat = fileio.statSync(fpath)
expect(stat.isSocket()).assertInstanceOf('Boolean')
expect(fileio.unlinkSync(fpath)).assertNull()
} catch (e) {
console.log("fileio_test_stat_is_socket_000 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_DF_FileIO_Stat_IsSocket_0010
* @tc.name fileio_test_stat_is_socket_001
* @tc.desc Test Stat.isSocket() interface.
*/
it('fileio_test_stat_is_socket_001', 0, function () {
let fpath = nextFileName('fileio_test_stat_is_socket_001')
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue()
try {
let stat = fileio.statSync(fpath)
expect(stat.isSocket()).assertFalse()
expect(fileio.unlinkSync(fpath)).assertNull()
} catch (e) {
console.log("fileio_test_stat_is_socket_001 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_DF_FileIO_Stat_IsSocket_0020
* @tc.name fileio_test_stat_is_socket_002
* @tc.desc Test Stat.isSocket() interface.
*/
it('fileio_test_stat_is_socket_002', 0, function () {
let fpath = nextFileName('fileio_test_stat_is_socket_002')
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue()
try {
let stat = fileio.statSync(fpath)
expect(stat.isSocket(-1)).assertFalse()
expect(null).assertFail()
} catch (e) {
expect(fileio.unlinkSync(fpath)).assertNull()
}
})
/**
* @tc.number SUB_DF_FileIO_Stat_IsSymbolicLink_0000
* @tc.name fileio_test_stat_is_symbolic_link_000
* @tc.desc Test Stat.isSymbolicLink() interface.
*/
it('fileio_test_stat_is_symbolic_link_000', 0, function () {
let fpath = nextFileName('fileio_test_stat_is_symbolic_link_000')
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue()
try {
let stat = fileio.statSync(fpath)
expect(stat.isSymbolicLink()).assertInstanceOf('Boolean')
expect(fileio.unlinkSync(fpath)).assertNull()
} catch (e) {
console.log("fileio_test_stat_is_symbolic_link_000 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_DF_FileIO_Stat_IsSymbolicLink_0010
* @tc.name fileio_test_stat_is_symbolic_link_001
* @tc.desc Test Stat.isSymbolicLink() interface.
*/
it('fileio_test_stat_is_symbolic_link_001', 0, function () {
let fpath = nextFileName('fileio_test_stat_is_symbolic_link_001')
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue()
try {
let stat = fileio.statSync(fpath)
expect(stat.isSymbolicLink()).assertFalse()
expect(fileio.unlinkSync(fpath)).assertNull()
} catch (e) {
console.log("fileio_test_stat_is_symbolic_link_001 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_DF_FileIO_Stat_IsSymbolicLink_0020
* @tc.name fileio_test_stat_is_symbolic_link_002
* @tc.desc Test Stat.isSymbolicLink() interface.
*/
it('fileio_test_stat_is_symbolic_link_002', 0, function () {
let fpath = nextFileName('fileio_test_stat_is_symbolic_link_002')
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue()
try {
let stat = fileio.statSync(fpath)
expect(stat.isSymbolicLink(-1)).assertFalse()
expect(null).assertFail()
} catch (e) {
expect(fileio.unlinkSync(fpath)).assertNull()
}
})
})
/*
* 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 } from './Common'
describe('fileIOTestStream', function () {
/**
* @tc.number SUB_DF_FileIO_Stream_CreateStreamSync_0000
* @tc.name fileio_test_stream_create_stream_sync_000
* @tc.desc Test Stream.createStreamSync() interface.
*/
it('fileio_test_stream_create_stream_sync_000', 0, function () {
let fpath = nextFileName('fileio_test_stream_create_stream_sync_000')
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue()
try {
var ss = fileio.createStreamSync(fpath, "r+")
expect(ss !== null).assertTrue()
expect(ss.closeSync()).assertNull()
expect(fileio.unlinkSync(fpath)).assertNull()
} catch (e) {
console.log("fileio_test_stream_create_stream_sync_000 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_DF_FileIO_Stream_CreateStreamSync_0010
* @tc.name fileio_test_stream_create_stream_sync_001
* @tc.desc Test Stream.createStreamSync() interface.
*/
it('fileio_test_stream_create_stream_sync_001', 0, function () {
let fpath = nextFileName('fileio_test_stream_create_stream_sync_001')
try {
fileio.createStreamSync(fpath, "r+")
expect(null).assertFail()
} catch (e) {
}
})
/**
* @tc.number SUB_DF_FileIO_Stream_CreateStreamSync_0020
* @tc.name fileio_test_stream_create_stream_sync_002
* @tc.desc Test Stream.createStreamSync() interface.
*/
it('fileio_test_stream_create_stream_sync_002', 0, function () {
let fpath = nextFileName('fileio_test_stream_create_stream_sync_002')
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue()
try {
fileio.createStreamSync(fpath, "ohos")
expect(null).assertFail()
} catch (e) {
expect(fileio.unlinkSync(fpath)).assertNull()
}
})
/**
* @tc.number SUB_DF_FileIO_Stream_FdopenStreamSync_0000
* @tc.name fileio_test_stream_fdopen_stream_sync_000
* @tc.desc Test Stream.fdopenStreamSync() interface.
*/
it('fileio_test_stream_fdopen_stream_sync_000', 0, function () {
let fpath = nextFileName('fileio_test_stream_fdopen_stream_sync_000')
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue()
try {
var fd = fileio.openSync(fpath, 0o2)
let ss = fileio.fdopenStreamSync(fd, "r+")
expect(ss !== null).assertTrue()
expect(ss.closeSync()).assertNull()
expect(fileio.unlinkSync(fpath)).assertNull()
} catch (e) {
console.log("fileio_test_stream_fdopen_stream_sync_000 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_DF_FileIO_Stream_FdopenStreamSync_0010
* @tc.name fileio_test_stream_fdopen_stream_sync_001
* @tc.desc Test Stream.fdopenStreamSync() interface.
*/
it('fileio_test_stream_fdopen_stream_sync_001', 0, function () {
try {
let ss = fileio.fdopenStreamSync(-1, "r+")
expect(null).assertFail()
} catch (e) {
}
})
/**
* @tc.number SUB_DF_FileIO_Stream_ReadSync_0000
* @tc.name fileio_test_stream_read_sync_000
* @tc.desc Test Stream.readSync() interface.
*/
it('fileio_test_stream_read_sync_000', 0, function () {
let fpath = nextFileName('fileio_test_stream_read_sync_000')
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue()
try {
let ss = fileio.createStreamSync(fpath, "r+")
expect(ss !== null).assertTrue()
let len = ss.readSync(new ArrayBuffer(4096))
expect(len).assertEqual(FILE_CONTENT.length)
expect(ss.closeSync()).assertNull()
expect(fileio.unlinkSync(fpath)).assertNull()
} catch (e) {
console.log("fileio_test_stream_read_sync_000 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_DF_FileIO_Stream_WriteSync_0000
* @tc.name fileio_test_stream_write_sync_000
* @tc.desc Test Stream.writeSync() interface.
*/
it('fileio_test_stream_write_sync_000', 0, function () {
let fpath = nextFileName('fileio_test_stream_write_sync_000')
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue()
try {
let ss = fileio.createStreamSync(fpath, "r+")
expect(ss !== null).assertTrue()
expect(ss.writeSync(FILE_CONTENT)).assertEqual(FILE_CONTENT.length)
expect(ss.closeSync()).assertNull()
expect(fileio.unlinkSync(fpath)).assertNull()
} catch (e) {
console.log("fileio_test_stream_write_sync_000 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_DF_FileIO_Stream_FlushSync_0000
* @tc.name fileio_test_stream_flush_sync_000
* @tc.desc Test Stream.flushSync() interface.
*/
it('fileio_test_stream_flush_sync_000', 0, function () {
let fpath = nextFileName('fileio_test_stream_flush_sync_000')
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue()
try {
let ss = fileio.createStreamSync(fpath, "r+")
expect(ss !== null).assertTrue()
expect(ss.writeSync(FILE_CONTENT)).assertEqual(FILE_CONTENT.length)
expect(ss.flushSync()).assertNull()
expect(ss.closeSync()).assertNull()
expect(fileio.unlinkSync(fpath)).assertNull()
} catch (e) {
console.log("fileio_test_stream_flush_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.
*/
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": "DistributedFileJSTest"
},
{
"name": "mainability_description",
"value": "JS_Phone_Empty Feature Ability"
}
]
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册