提交 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 { 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('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.
先完成此消息的编辑!
想要评论请 注册