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

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

Signed-off-by: NXTStarry <gaoxiaotian@huawei.com>
上级 4dc3f350
# Copyright (C) 2021 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//test/xts/tools/build/suite.gni")
group("storage") {
testonly = true
if (is_standard_system) {
deps = [ "storagefileiojstest:storagefileio_js_test" ]
}
}
# Copyright (C) 2021 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//test/xts/tools/build/suite.gni")
ohos_js_hap_suite("storagefileio_js_test") {
test_hap_name = "StoragefileioJSTest"
hap_source_path = "hap/entry-debug-rich-signed.hap"
}
{
"description": "Configuration for storage file and fileio Tests",
"driver": {
"type": "JSUnitTest",
"test-timeout": "21600000",
"package": "ohos.acts.stroage.fileio",
"shell-timeout": "21600000"
},
"kits": [
{
"test-file-name": [
"StoragefileioJSTest.hap"
],
"type": "AppInstallKit",
"cleanup-apps": true
}
]
}
\ No newline at end of file
{
"devDependencies": {
"chai": "^4.3.4",
"mocha": "^9.0.1"
}
}
{
"app": {
"bundleName": "ohos.acts.stroage.fileio",
"vendor": "example",
"version": {
"code": 1000000,
"name": "1.0.0"
},
"apiVersion": {
"compatible": 4,
"target": 5,
"releaseType": "Release"
}
},
"deviceConfig": {},
"module": {
"package": "ohos.acts.stroage.fileio",
"name": ".MyApplication",
"deviceType": [
"phone"
],
"distro": {
"deliveryWithInstall": true,
"moduleName": "entry",
"moduleType": "entry",
"installationFree": true
},
"abilities": [
{
"skills": [
{
"entities": [
"entity.system.home"
],
"actions": [
"action.system.home"
]
}
],
"name": "ohos.acts.stroage.fileio.MainAbility",
"icon": "$media:icon",
"description": "$string:mainability_description",
"label": "$string:app_name",
"type": "page",
"launchType": "standard",
"visible": true
}
],
"js": [
{
"pages": [
"pages/index/index"
],
"name": "default",
"window": {
"designWidth": 720,
"autoDesignWidth": false
}
}
]
}
}
\ No newline at end of file
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export default {
onCreate() {
console.info('ohos.acts.distributeddatamgr.distributedfile onCreate');
},
onDestroy() {
console.info('ohos.acts.distributeddatamgr.distributedfile onCreate');
}
};
{
"strings": {
"hello": "Hello",
"world": "Test"
}
}
\ No newline at end of file
{
"strings": {
"hello": "您好",
"world": "测试"
}
}
\ No newline at end of file
.container {
flex-direction: column;
justify-content: center;
align-items: center;
}
.title {
font-size: 100px;
}
<div class="container">
<text class="title">
{{ $t('strings.hello') }} {{ title }}
</text>
</div>
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import file from '@system.file'
import app from '@system.app'
import {Core, ExpectExtend, ReportExtend} from 'deccjsunit/index'
export default {
data: {
title: ""
},
onInit() {
this.title = this.$t('strings.world');
},
onShow() {
console.info('onShow finish')
const core = Core.getInstance()
const expectExtend = new ExpectExtend({
'id': 'extend'
})
const reportExtend = new ReportExtend(file)
// const instrumentLog = new InstrumentLog({
// 'id': 'report'
// })
core.addService('expect', expectExtend)
core.addService('report', reportExtend)
// core.addService('report', instrumentLog)
core.init()
// core.subscribeEvent('spec', instrumentLog)
// core.subscribeEvent('suite', instrumentLog)
// core.subscribeEvent('task', instrumentLog)
const configService = core.getDefaultService('config')
configService.setConfig(this)
require('../../../test/List.test')
core.execute()
},
onReady() {
},
}
\ No newline at end of file
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import fileio from '@system.fileio'
export const FILE_CONTENT = "仙女星系 (英语: Andromeda Galaxy; M31; NGC 224 ;曾被称为 仙女座大星云 ),位于仙女座方位的拥有巨大盘状结构的 \
旋涡星系 , 梅西耶星表 编号为M31, 星云星团新总表 编号位 NGC 224 ,直径22万光年,距离地球有254万光年,是距银河系最近的大星系。"
//创建一个可读写文件
export function prepareFile(fpath, content) {
try {
let fd = fileio.openSync(fpath, 0o102, 0o666)
fileio.ftruncateSync(fd)
fileio.writeSync(fd, content)
fileio.fsyncSync(fd)
fileio.closeSync(fd)
return true
} catch (e) {
console.log("Failed to prepareFile for " + e)
return false
}
}
export function prepareFile1(fpath, content) {
try {
let fd = fileio.openSync(fpath, 0o102, 0o777)
fileio.ftruncateSync(fd)
fileio.writeSync(fd, content)
fileio.fsyncSync(fd)
fileio.closeSync(fd)
return true
} catch (e) {
console.log("Failed to prepareFile for " + e)
return false
}
}
//创建一个可读的空文件
export function prepareEmptyFile(fpath) {
try {
let fd = fileio.openSync(fpath, 0o102, 0o777)
fileio.closeSync(fd)
return true
} catch (e) {
console.log("Failed to prepareFile for " + e)
return false
}
}
//将已存在的文件访问权限改为只读
export function fileToReadOnly(fpath) {
try {
let fd = fileio.openSync(fpath, 0o1)
fileio.fchmodSync(fd, 0o444)
fileio.fsyncSync(fd)
fileio.closeSync(fd)
return true
} catch (e) {
console.log("Failed to fileToReadOnly for " + e)
return false
}
}
//将已存在的文件访问权限改为只写
export function fileToWriteOnly(fpath) {
try {
let fd = fileio.openSync(fpath, 0o2)
fileio.fchmodSync(fd, 0o222)
fileio.fsyncSync(fd)
fileio.closeSync(fd)
return true
} catch (e) {
console.log("Failed to fileToWriteOnly " + e)
return false
}
}
//将已存在的文件访问权限改为读写
export function fileToReadAndWrite(fpath) {
try {
let fd = fileio.openSync(fpath, 0o1)
fileio.fchmodSync(fd, 0o777)
fileio.fsyncSync(fd)
fileio.closeSync(fd)
return true
} catch (e) {
console.log("Failed to fileToReadAndWrite " + e)
return false
}
}
var fileSeed = 0
export function nextFileName(testName) {
const BASE_PATH = "/data/accounts/account_0/appdata/ohos.acts.stroage.fileio/cache/"
return BASE_PATH + testName
}
export function fileName(testName) {
const BASE_PATH = "/data/accounts/account_0/appdata/ohos.acts.stroage.fileio/files/"
return BASE_PATH + testName
}
export function differentFileName(testName) {
const BASE_PATH = "/data/accounts/account_0/ohos.acts.distributeddatamgr.distributedfile/"
return BASE_PATH + testName
}
export function cacheFileName(testName) {
const BASE_PATH = "/data/accounts/account_0/appdata/ohos.acts.stroage.fileio/files/cache/"
return BASE_PATH + testName
}
export function getFileTextLen(fpath) {
let ss
try{
ss = fileio.Stream.createStreamSync(fpath, "r+")
expect(ss !== null).assertTrue()
let len = ss.readSync(new ArrayBuffer(4096))
console.log("文件:" + fpath)
console.log("文本长度:" + len)
expect(ss.closeSync() !== null).assertTrue()
return len
} catch (e) {
console.log("Failed to getFileTextLen " + e)
expect(ss.closeSync() !== null).assertTrue()
return null
}
}
export function isFileExist(fpath) {
try{
expect(fileio.accessSync(fpath) !== null).assertTrue()
console.log("文件:" + fpath)
console.log("状态:存在")
return true
} catch (e) {
console.log("文件:" + fpath)
console.log("状态:不存在")
return false
}
}
export function sleep(n) {
var start = new Date().getTime();
while (true) {
if (new Date().getTime() - start > n) {
break;
}
}
}
export function randomString(len) {
len = len;
var $chars = 'aaaabbbbcccc';
var maxPos = $chars.length;
var pwd = '';
for (var i = 0; i < len; i++) {
pwd += $chars.charAt(Math.floor(Math.random() * maxPos));
}
return pwd;
}
\ No newline at end of file
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import fileio from '@system.fileio';
import file from '@system.file';
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index'
import {
FILE_CONTENT, prepareFile, fileName, randomString, sleep,
cacheFileName, prepareEmptyFile, nextFileName
} from './Common'
describe('fileTest', function () {
/**
* @tc.number SUB_STORAGE_File_Delete_0100
* @tc.name File_Delete_001
* @tc.desc Function of API, delete file.The test file is exist.
*/
it('File_Delete_001', 0, async function (done) {
let fpath = fileName("File_Delete_001")
prepareFile(fpath, "hello")
file.delete({
uri: 'internal://app/File_Delete_001',
success: function () {
console.log('File_Delete_001 call delete success');
done();
},
fail: function (data, code) {
console.log('File_Delete_001 call delete fail, code: ' + code + ', data: ' + data);
expect(null).assertFail();
done();
},
});
})
/**
* @tc.number SUB_STORAGE_File_Delete_0200
* @tc.name File_Delete_002
* @tc.desc Function of API, delete dir.The dir is empty.
*/
it('File_Delete_002', 0, async function (done) {
file.mkdir({
uri: 'internal://app/File_Delete_002',
success: function () {
console.log('File_Delete_002 call mkdir success.');
done();
},
fail: function (data, code) {
console.log('File_Delete_002 call mkdir fail, code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
file.delete({
uri: 'internal://app/File_Delete_002',
success: function () {
console.log('File_Delete_002 call delete success.');
done();
},
fail: function (data, code) {
console.log('File_Delete_002 call delete fail, code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
})
/**
* @tc.number SUB_STORAGE_File_Delete_0300
* @tc.name File_Delete_003
* @tc.desc Function of API, error code: 202 The test file or dir are exist.
*/
it('File_Delete_003', 0, async function (done) {
file.delete({
uri: 'internal://ohos/workspace/text.txt',
success: function () {
console.log('File_Delete_003 call delete success.');
expect(null).assertFail()
},
fail: function (data, code) {
console.log('File_Delete_003 call delete fail, code: ' + code + ', data: ' + data);
expect(code == 202).assertTrue();
done();
},
});
})
/**
* @tc.number SUB_STORAGE_File_Delete_0400
* @tc.name File_Delete_004
* @tc.desc Function of API, error code: 300 The dir is exist with files.
*/
it('File_Delete_004', 0, async function (done) {
let dpath = fileName('File_Delete_004');
let fpath = dpath + '/File_Delete_004';
expect(fileio.mkdirSync(dpath) !== null).assertTrue();
expect(prepareFile(fpath, FILE_CONTENT) !== null).assertTrue();
file.delete({
uri: 'internal://app/File_Delete_004',
success: function () {
console.log('File_Delete_004 call delete success.');
expect(null).assertFail();
},
fail: function (data, code) {
console.log('File_Delete_004 call delete fail, code: ' + code + ', data: ' + data);
expect(code == 300).assertTrue();
done();
},
});
})
/**
* @tc.number SUB_STORAGE_File_Delete_0500
* @tc.name File_Delete_005
* @tc.desc Function of API, error code: 301 The file and dir are not exist.
*/
it('File_Delete_005', 0, async function (done) {
file.delete({
uri: 'internal://app/File_Delete_005',
success: function () {
console.log('File_Delete_005 call delete success.');
expect(null).assertFail();
},
fail: function (data, code) {
console.log('File_Delete_005 call delete fail, code: ' + code + ', data: ' + data);
expect(code == 301).assertTrue();
done();
},
});
})
/**
* @tc.number SUB_STORAGE_File_Delete_0600
* @tc.name File_Delete_006
* @tc.desc uri address length more than 4096 The test file is exist.
*/
it('File_Delete_006', 0, async function (done) {
let firstPath = randomString(32);
let dpath = fileName(firstPath);
let uri = 'internal://cache/' + firstPath;
fileio.mkdirSync(dpath);
for (let i = 0; i < 16; i++) {
console.log('frequency' + i);
let sonPath = randomString(251);
uri = uri + '/f' + sonPath;
}
file.delete({
uri: uri,
success: function () {
console.log('File_Delete_006 call delete success');
expect(null).assertFail();
},
fail: function (data, code) {
console.log('File_Delete_006 call delete fail, code: ' + code + ', data: ' + data);
expect(code == 300).assertTrue();
done();
},
});
})
/**
* @tc.number SUB_STORAGE_File_Delete_0700
* @tc.name File_Delete_007
* @tc.desc Function of API, delete file from cache.The test file on cache.
*/
it('File_Delete_007', 0, async function (done) {
file.writeText({
uri: 'internal://cache/File_Delete_007',
text: 'test',
success: function () {
console.log('File_Delete_007 call writeText success');
done();
},
fail: function (data, code) {
console.log('File_Delete_007 call writeText fail, code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
})
file.delete({
uri: 'internal://cache/File_Delete_007',
success: function () {
console.log('File_Delete_007 call delete success');
done();
},
fail: function (data, code) {
console.log('File_Delete_007 call delete fail, code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
})
/**
* @tc.number SUB_STORAGE_File_Delete_0800
* @tc.name File_Delete_008.
* @tc.desc Function of API, delete file from Virtual path.The test file is exist.
*/
it('File_Delete_008', 0, async function (done) {
file.writeText({
uri: 'internal://app/../files/File_Delete_008',
text: 'Text that just for test.',
success: function () {
console.log('File_Delete_008 call writeText success');
done();
},
fail: function (data, code) {
console.log('File_Delete_008 call writeText fail, code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
file.delete({
uri: 'internal://app/../files/File_Delete_008',
success: function () {
console.log('File_Delete_008 call delete success');
done();
},
fail: function (data, code) {
console.log('File_Delete_008 call delete fail, code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
})
/**
* @tc.number SUB_STORAGE_File_writeText_0100
* @tc.name File_writeText_001
* @tc.desc Function of API, write to file(app path).The test file is not exist.
*/
it('File_writeText_001', 0, async function (done) {
file.writeText({
uri: 'internal://app/File_writeText_001',
text: 'sawyerwang.',
success: function () {
console.log('File_writeText_001 call writeText success');
done();
},
fail: function (data, code) {
console.log('File_writeText_001 call writeText fail , code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
file.readText({
uri: 'internal://app/File_writeText_001',
success: function (data) {
console.log('File_writeText_001 call read success. Content: ' + data.text);
done();
},
fail: function (data, code) {
console.log('File_writeText_001 call read fail , code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
})
file.delete({
uri: 'internal://app/File_writeText_001',
success: function () {
console.log('File_writeText_001 call delete success');
done();
},
fail: function (data, code) {
console.log('File_writeText_001 call delete fail, code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
})
/**
* @tc.number SUB_STORAGE_File_writeText_0200
* @tc.name File_writeText_002
* @tc.desc Function of API, write to file.The test file is exist, it can be edited.
*/
it('File_writeText_002', 0, async function (done) {
file.writeText({
uri: 'internal://app/File_writeText_002',
text: 'Text1.',
success: function () {
console.log('File_writeText_002 call writeText success.');
done();
},
fail: function (data, code) {
console.log('File_writeText_002 call writeText fail, code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
file.writeText({
uri: 'internal://app/File_writeText_002',
text: 'Text2.',
append: true,
success: function () {
console.log('File_writeText_002 call writeText success.');
done();
},
fail: function (data, code) {
console.log('File_writeText_002 call writeText fail, code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
file.readText({
uri: 'internal://app/File_writeText_002',
success: function (data) {
console.log('File_writeText_002 call read success. Content: ' + data.text);
done();
},
fail: function (data, code) {
console.log('File_writeText_002 call read fail, code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
file.delete({
uri: 'internal://app/File_writeText_002',
success: function () {
console.log('File_writeText_002 call delete success');
done();
},
fail: function (data, code) {
console.log('File_writeText_002 call delete fail, code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
})
/**
* @tc.number SUB_STORAGE_File_writeText_0300
* @tc.name File_writeText_003
* @tc.desc Different types of strings for text.
*/
it('File_writeText_003', 0, async function (done) {
let txt = 'hello 你好 مرحبا こんにちは 안녕하세요.'
file.writeText({
uri: 'internal://app/File_writeText_003',
text: txt,
success: function () {
console.log('File_writeText_003 call writeText success.');
done();
},
fail: function (data, code) {
console.log('File_writeText_003 call writeText fail, code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
file.readText({
uri: 'internal://app/File_writeText_003',
success: function (data) {
console.log('File_writeText_003 call read success. Content: ' + data.text);
done();
},
fail: function (data, code) {
console.log('File_writeText_003 call read fail, code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
file.delete({
uri: 'internal://app/File_writeText_003',
success: function () {
console.log('File_writeText_003 call delete success');
done();
},
fail: function (data, code) {
console.log('File_writeText_003 call delete fail, code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
})
/**
* @tc.number SUB_STORAGE_File_writeText_0400
* @tc.name File_writeText_004
* @tc.desc Defferent encoding(UTF-8).
*/
it('File_writeText_004', 0, async function (done) {
file.writeText({
uri: 'internal://app/File_writeText_004',
text: 'hello',
encoding: 'UTF-8',
success: function () {
console.log('File_writeText_004 call writeText success.');
done();
},
fail: function (data, code) {
console.log('File_writeText_004 call writeText fail, code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
file.readText({
uri: 'internal://app/File_writeText_004',
encoding: 'UTF-8',
success: function (data) {
console.log('File_writeText_004 call readText success. Content: ' + data.text);
done();
},
fail: function (data, code) {
console.log('File_writeText_004 call readText fail, code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
file.delete({
uri: 'internal://app/File_writeText_004',
success: function () {
console.log('File_writeText_004 delete success');
done();
},
fail: function (data, code) {
console.log('File_writeText_004 delete , code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
})
/**
* @tc.number SUB_STORAGE_File_writeText_0500
* @tc.name File_writeText_005
* @tc.desc Function of API, append mode.The test file is exist and it can be edited.
*/
it('File_writeText_005', 0, async function (done) {
file.writeText({
uri: 'internal://app/File_writeText_005',
text: 'hello,world',
success: function () {
console.log('File_writeText_005 call writeText success.');
done();
},
fail: function (data, code) {
console.log('File_writeText_005 call writeText fail, code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
file.writeText({
uri: 'internal://app/File_writeText_005',
text: 'hello',
append: true,
success: function () {
console.log('File_writeText_005 call writeText success.');
done();
},
fail: function (data, code) {
console.log('File_writeText_005 call writeText fail, code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
file.readText({
uri: 'internal://app/File_writeText_005',
success: function (data) {
console.log('File_writeText_005 call read success ' + data.text);
done();
},
fail: function (data, code) {
console.log('File_writeText_005 call readText fail , code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
file.delete({
uri: 'internal://app/File_writeText_005',
success: function () {
console.log('File_writeText_005 call delete success');
done();
},
fail: function (data, code) {
console.log('File_writeText_005 call delete fail, code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
})
/**
* @tc.number SUB_STORAGE_File_writeText_0600
* @tc.name File_writeText_006
* @tc.desc Function of API, non-append mode.The test file is exist and it can be edited.
*/
it('File_writeText_006', 0, async function (done) {
file.writeText({
uri: 'internal://app/File_writeText_006',
text: 'hello',
success: function () {
console.log('File_writeText_006 call writeText success.');
done();
},
fail: function (data, code) {
console.log('File_writeText_006 call writeText fail, code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
file.readText({
uri: 'internal://app/File_writeText_006',
success: function (data) {
console.log('File_writeText_006 call read success ' + data.text);
done();
},
fail: function (data, code) {
console.log('File_writeText_006 call readText fail, code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
file.delete({
uri: 'internal://app/File_writeText_006',
success: function () {
console.log('File_writeText_006 delete success');
done();
},
fail: function (data, code) {
console.log('File_writeText_006 delete , code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
})
/**
* @tc.number SUB_STORAGE_File_writeText_0700
* @tc.name File_writeText_007
* @tc.desc Function of API, error code: 202 The test file and dir are exist.
*/
it('File_writeText_007', 0, async function (done) {
file.writeText({
uri: '/data/accounts/account_0/appdata',
text: 'hello',
success: function () {
console.log('File_writeText_007 call writeText success.');
expect(null).assertFail();
},
fail: function (data, code) {
console.log('File_writeText_007, code: ' + code + ', data: ' + data);
expect(code == 202).assertTrue();
done();
},
});
})
/**
* @tc.number SUB_STORAGE_File_writeText_0800
* @tc.name File_writeText_008
* @tc.desc Function of API, error code: 300 The uri path is dir path.
*/
it('File_writeText_008', 0, async function (done) {
let dpath = fileName("File_writeText_008d");
expect(fileio.mkdirSync(dpath) !== null).assertTrue();
file.writeText({
uri: 'internal://app/File_writeText_008d/',
text: 'hello',
success: function () {
console.log('File_writeText_008 call writeText success.');
expect(null).assertFail();
},
fail: function (data, code) {
console.log('File_writeText_008 , code: ' + code + ', data: ' + data);
expect(code == 300).assertTrue();
done();
},
});
})
/**
* @tc.number SUB_STORAGE_File_writeText_0900
* @tc.name File_writeText_009
* @tc.desc Function of API, error code: 300.The file path is not exist.
*/
it('File_writeText_009', 0, async function (done) {
file.writeText({
uri: 'internal://app/File_writeText_009d/File_writeText_009',
text: 'test',
success: function () {
console.log('File_writeText_009 call writeText success.');
expect(null).assertFail();
},
fail: function (data, code) {
console.log('File_writeText_009 , code: ' + code + ', data: ' + data);
expect(code == 300).assertTrue();
done();
},
});
})
/**
* @tc.number SUB_STORAGE_File_writeText_1000
* @tc.name File_writeText_010
* @tc.desc Function of API, write to file(cache path).The test file is not exist.
*/
it('File_writeText_010', 0, async function (done) {
file.writeText({
uri: 'internal://cache/File_writeText_010',
text: 'test',
success: function () {
console.log('File_writeText_010 mkdir success');
done();
},
fail: function (data, code) {
console.log('File_writeText_010 fail');
expect(null).assertFail();
},
});
file.delete({
uri: 'internal://cache/File_writeText_010',
success: function () {
console.log('File_writeText_010 delete success');
done();
},
fail: function (data, code) {
console.log('File_writeText_010 fail, code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
})
})
/**
* @tc.number SUB_STORAGE_File_writeText_1100
* @tc.name File_writeText_011
* @tc.desc Function of API, Virtual path.The test file is exist.
*/
it('File_writeText_011', 0, async function (done) {
file.writeText({
uri: 'internal://app/../files/File_writeText_011',
text: 'sawyerwang',
success: function () {
console.log('File_writeText_011 mkdif success');
done();
},
fail: function (data, code) {
console.log('File_writeText_011 , code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
file.readText({
uri: 'internal://app/../files/File_writeText_011',
success: function (data) {
console.log('File_writeText_011 read success ' + data.text);
done();
},
fail: function (data, code) {
console.log('File_writeText_011 , code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
})
file.delete({
uri: 'internal://app/../files/File_writeText_011',
success: function () {
console.log('File_writeText_011 delete success');
done();
},
fail: function (data, code) {
console.log('File_writeText_011 delete , code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
})
/**
* @tc.number SUB_STORAGE_File_writeText_1300
* @tc.name File_writeText_013
* @tc.desc Function of API, write file out of package, Virtual path, save the dir authority.The test file is exist.
*/
it('File_writeText_013', 0, async function (done) {
file.writeText({
uri: 'internal://app/../../File_writeText_013',
text: 'sawyerwang',
success: function () {
console.log('File_writeText_013 mkdir success')
expect(null).assertFail();
},
fail: function (data, code) {
expect(code == 300).assertTrue();
console.log('File_writeText_013 , code: ' + code + ', data: ' + data);
done();
},
});
})
/**
* @tc.number SUB_STORAGE_File_writeArrayBuffer_0100
* @tc.name File_writeArrayBuffer_001
* @tc.desc Write the buffer content to file.(cache path, append mode) The file path is not exist.
*/
it('File_writeArrayBuffer_001', 0, async function (done) {
let buf = new Uint8Array([48, 49, 50, 51, 65, 66, 67, 68, 32, 33]);
file.writeArrayBuffer({
uri: 'internal://cache/File_writeArrayBuffer_001',
buffer: buf,
append: true,
success: function () {
console.log('File_writeArrayBuffer_001 call writeArrayBuffer success.');
done();
},
fail: function (data, code) {
console.log('File_writeArrayBuffer_001 , code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
file.readArrayBuffer({
uri: 'internal://cache/File_writeArrayBuffer_001',
success: function (data) {
console.log('File_writeArrayBuffer_001 call readArrayBuffer success.' + data.buffer);
done();
},
fail: function (data, code) {
console.log('File_writeArrayBuffer_001 readArrayBuffer , code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
file.delete({
uri: 'internal://cache/File_writeArrayBuffer_001'
});
})
/**
* @tc.number SUB_STORAGE_File_writeArrayBuffer_0200
* @tc.name File_writeArrayBuffer_002
* @tc.desc Write the buffer content to file.(cache path, non-append mode) The file path is not exist.
*/
it('File_writeArrayBuffer_002', 0, async function (done) {
let buf = new Uint8Array([48, 49, 50, 51, 65, 66, 67, 68, 32, 33]);
file.writeArrayBuffer({
uri: 'internal://cache/File_writeArrayBuffer_002',
buffer: buf,
success: function () {
console.log('File_writeArrayBuffer_002 call writeArrayBuffer success.');
done();
},
fail: function (data, code) {
console.log('File_writeArrayBuffer_002 , code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
file.readArrayBuffer({
uri: 'internal://cache/File_writeArrayBuffer_002',
success: function (data) {
console.log('File_writeArrayBuffer_002 call readArrayBuffer success.' + data.buffer);
done();
},
fail: function (data, code) {
console.log('File_writeArrayBuffer_002 , code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
})
file.delete({
uri: 'internal://cache/File_writeArrayBuffer_002'
});
})
/**
* @tc.number SUB_STORAGE_File_writeArrayBuffer_0300
* @tc.name File_writeArrayBuffer_003
* @tc.desc Write the buffer content to file.(cache path, append mode) The file path is not exist.
*/
it('File_writeArrayBuffer_003', 0, async function (done) {
let buf = new Uint8Array([48, 49, 50, 51, 65, 66, 67, 68, 32, 33, 48, 49, 50, 51, 65, 66, 67, 68, 32, 33]);
file.writeArrayBuffer({
uri: 'internal://cache/File_writeArrayBuffer_003',
buffer: buf,
success: function () {
console.log('File_writeArrayBuffer_003 call writeText success.');
done();
},
fail: function (data, code) {
console.log('File_writeArrayBuffer_003 , code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
file.writeArrayBuffer({
uri: 'internal://cache/File_writeArrayBuffer_003',
buffer: buf,
append: true,
success: function () {
console.log('File_writeArrayBuffer_003 call writeArrayBuffer success.');
done();
},
fail: function (data, code) {
console.log('File_writeArrayBuffer_003 , code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
file.readArrayBuffer({
uri: 'internal://cache/File_writeArrayBuffer_003',
success: function (data) {
console.log('File_writeArrayBuffer_003 readArrayBuffer success:' + data.buffer)
done();
},
fail: function (data, code) {
console.log('File_writeArrayBuffer_003 , code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
})
/**
* @tc.number SUB_STORAGE_File_writeArrayBuffer_0400
* @tc.name File_writeArrayBuffer_004
* @tc.desc Write the buffer content to file.(cache path, non-append mode) The file path is exist.
*/
it('File_writeArrayBuffer_004', 0, async function (done) {
let buf = new Uint8Array([48, 49, 50, 51, 65, 66, 67, 68, 32, 33]);
file.writeArrayBuffer({
uri: 'internal://cache/File_writeArrayBuffer_004',
buffer: buf,
append: false,
success: function () {
console.log('File_writeArrayBuffer_004 success call writeText success.');
done();
},
fail: function (data, code) {
console.log('File_writeArrayBuffer_004 , code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
file.writeArrayBuffer({
uri: 'internal://cache/File_writeArrayBuffer_004',
buffer: buf,
append: false,
success: function () {
console.log('File_writeArrayBuffer_004 call writeArrayBuffer success.');
done();
},
fail: function (data, code) {
console.log('File_writeArrayBuffer_004 , code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
file.readArrayBuffer({
uri: 'internal://cache/File_writeArrayBuffer_004',
success: function (data) {
console.log('File_writeArrayBuffer_004: readArrayBuffer success ' + data.buffer)
done();
},
fail: function (data, code) {
console.log('File_writeArrayBuffer_004 , code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
file.delete({
uri: 'internal://cache/File_writeArrayBuffer_004'
});
})
/**
* @tc.number SUB_STORAGE_File_writeArrayBuffer_0500
* @tc.name File_writeArrayBuffer_005
* @tc.desc Function of API, set value for position.The file path is exist.
*/
it('File_writeArrayBuffer_005', 0, async function (done) {
let buf = new Uint8Array([48, 49, 50, 51, 65, 66, 67, 68, 32, 33, 44, 55, 66, 77]);
file.writeArrayBuffer({
uri: 'internal://cache/File_writeArrayBuffer_005',
buffer: buf,
success: function () {
console.log('File_writeArrayBuffer_005 call writeText success.');
done();
},
fail: function (data, code) {
console.log('File_writeArrayBuffer_005 , code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
file.writeArrayBuffer({
uri: 'internal://cache/File_writeArrayBuffer_005',
buffer: buf,
position: 10,
success: function () {
console.log('File_writeArrayBuffer_005 call writeArrayBuffer success.');
done();
},
fail: function (data, code) {
console.log('File_writeArrayBuffer_005 , code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
file.readArrayBuffer({
uri: 'internal://cache/File_writeArrayBuffer_005',
success: function (data) {
console.log('File_writeArrayBuffer_005 read success:' + data.buffer);
done();
},
fail: function (data, code) {
console.log('File_writeArrayBuffer_005 , code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
file.delete({
uri: 'internal://cache/File_writeArrayBuffer_005'
});
})
/**
* @tc.number SUB_STORAGE_File_writeArrayBuffer_0600
* @tc.name File_writeArrayBuffer_006
* @tc.desc Function of API, not set value for position & append.The file path is exist.
*/
it('File_writeArrayBuffer_006', 0, async function (done) {
let buf = new Uint8Array([48, 49, 50, 51, 65, 66, 67, 68, 32, 33]);
file.writeArrayBuffer({
uri: 'internal://cache/File_writeArrayBuffer_006',
buffer: buf,
success: function () {
console.log('File_writeArrayBuffer_006 call writeText success.');
done();
},
fail: function (data, code) {
console.log('File_writeArrayBuffer_006 , code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
file.writeArrayBuffer({
uri: 'internal://cache/File_writeArrayBuffer_006',
buffer: buf,
success: function () {
console.log('File_writeArrayBuffer_006 call writeArrayBuffer success.');
done();
},
fail: function (data, code) {
console.log('File_writeArrayBuffer_006 , code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
file.readArrayBuffer({
uri: 'internal://cache/File_writeArrayBuffer_006',
success: function (data) {
console.log('File_writeArrayBuffer_006 pass');
done();
},
fail: function (data, code) {
console.log('File_writeArrayBuffer_006 , code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
})
/**
* @tc.number SUB_STORAGE_File_writeArrayBuffer_0700
* @tc.name File_writeArrayBuffer_007
* @tc.desc Function of API, error code: 202
*/
it('File_writeArrayBuffer_007', 0, async function (done) {
let buf = new Uint8Array([48, 49, 50, 51, 65, 66, 67, 68, 32, 33]);
file.writeArrayBuffer({
uri: '',
buffer: buf,
success: function () {
console.log('File_writeArrayBuffer_007 call writeArrayBuffer success.');
expect(null).assertFail();
},
fail: function (data, code) {
console.log('File_writeArrayBuffer_007 , code: ' + code + ', data: ' + data);
expect(code == 202).assertTrue();
done();
},
});
})
/**
* @tc.number SUB_STORAGE_File_writeArrayBuffer_0800
* @tc.name File_writeArrayBuffer_008
* @tc.desc Function of API, error code: 300
*/
it('File_writeArrayBuffer_008', 0, async function (done) {
let buf = new Uint8Array([48, 49, 50, 51, 65, 66, 67, 68, 32, 33]);
file.mkdir({
uri: 'internal://app/File_writeArrayBuffer_008',
success: function () {
console.log('call mkdir success.');
done()
},
fail: function (data, code) {
console.error('call fail callback fail, code: ' + code + ', data: ' + data);
},
});
file.writeArrayBuffer({
uri: 'internal://app/File_writeArrayBuffer_008',
buffer: buf,
success: function () {
console.log('File_writeArrayBuffer_008 call writeArrayBuffer success.');
expect(null).assertFail();
},
fail: function (data, code) {
console.log('File_writeArrayBuffer_008 , code: ' + code + ', data: ' + data);
expect(code == 300).assertTrue();
done();
},
});
})
/**
* @tc.number SUB_STORAGE_File_writeArrayBuffer_0900
* @tc.name File_writeArrayBuffer_009
* @tc.desc Function of API, error code: 300
*/
it('File_writeArrayBuffer_009', 0, async function (done) {
let buf = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8])
file.writeArrayBuffer({
uri: 'internal://app/File_writeArrayBuffer_009',
buffer: buf,
success: function () {
console.log('File_writeArrayBuffer_009 call success');
done();
},
fail: function (data, code) {
console.log('File_writeArrayBuffer_009 fail');
expect(null).assertFail();
},
});
file.readArrayBuffer({
uri: 'internal://app/File_writeArrayBuffer_009',
success: function (data) {
console.log('File_writeArrayBuffer_009 pass');
done();
},
fail: function (data, code) {
console.log('File_writeArrayBuffer_009 , code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
file.delete({
uri: 'internal://app/File_writeArrayBuffer_009',
success: function () {
console.log('File_writeArrayBuffer_009 call success');
done();
},
fail: function (data, code) {
console.log('File_writeArrayBuffer_009 fail, code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
})
/**
* @tc.number SUB_STORAGE_File_writeArrayBuffer_1000
* @tc.name File_writeArrayBuffer_010
* @tc.desc Function of API, path = cache, virtual path The test file is exist.
*/
it('File_writeArrayBuffer_010', 0, async function (done) {
let buf = new Uint8Array([48, 49, 50, 51, 65, 66, 67, 68, 32, 33]);
file.writeArrayBuffer({
uri: 'internal://cache/../cache/File_writeArrayBuffer_010',
buffer: buf,
append: true,
success: function () {
console.log('File_writeArrayBuffer_010 call writeArrayBuffer success.');
done();
},
fail: function (data, code) {
console.log('File_writeArrayBuffer_010 , code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
file.readArrayBuffer({
uri: 'internal://cache/../cache/File_writeArrayBuffer_010',
success: function (data) {
console.log('File_writeArrayBuffer_010 pass');
done();
},
fail: function (data, code) {
console.log('File_writeArrayBuffer_010 readArrayBuffer , code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
})
})
/**
* @tc.number SUB_STORAGE_File_writeArrayBuffer_1200
* @tc.name File_writeArrayBuffer_012
* @tc.desc Function of API, out of package, Virtual path, save the dir authority.The test file is exist.
*/
it('File_writeArrayBuffer_012', 0, async function (done) {
let buf = new Uint8Array([48, 49, 50, 51, 65, 66, 67, 68, 32, 33]);
file.writeArrayBuffer({
uri: 'internal://app/../../File_writeArrayBuffer_012',
buffer: buf,
append: true,
success: function () {
console.log('File_writeArrayBuffer_012 => pass');
expect(null).assertFail();
},
fail: function (data, code) {
console.log('File_writeArrayBuffer_012 , code: ' + code + ', data: ' + data);
expect(code == 300).assertTrue();
done();
},
});
})
/**
* @tc.number SUB_STORAGE_File_readText_0100
* @tc.name File_readText_001
* @tc.desc Function of API, readText, app path.
*/
it('File_readText_001', 0, async function (done) {
file.writeText({
uri: 'internal://app/File_readText_001',
text: 'Text that just for test.',
success: function () {
console.log('File_readText_001 call writeText success.');
done();
},
fail: function (data, code) {
console.log('File_readText_001 , code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
file.readText({
uri: 'internal://app/File_readText_001',
success: function (data) {
console.log('File_readText_001 call readText success.');
done();
},
fail: function (data, code) {
console.log('File_readText_001 , code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
})
/**
* @tc.number SUB_STORAGE_File_readText_0200
* @tc.name File_readText_002
* @tc.desc Function of API, encoding = UTF-8.The test file is exist.
*/
it('File_readText_002', 0, async function (done) {
file.writeText({
uri: 'internal://app/File_readText_002',
text: 'Text that just for test.',
encoding: 'utf-8',
success: function () {
console.log('File_readText_002 call writeText success.');
done();
},
fail: function (data, code) {
console.log('File_readText_002 , code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
file.readText({
uri: 'internal://app/File_readText_002',
encoding: 'utf-8',
success: function (data) {
console.log('File_readText_002 call readText success.');
done();
},
fail: function (data, code) {
console.log('File_readText_002 , code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
})
/**
* @tc.number SUB_STORAGE_File_readText_0300
* @tc.name File_readText_003
* @tc.desc Function of API, error code: 202.The test file and dir is exist.
*/
it('File_readText_003', 0, async function (done) {
file.readText({
uri: '',
success: function (data) {
console.log(data.text);
expect(null).assertFail();
},
fail: function (data, code) {
console.log('File_readText_003 , code: ' + code + ', data: ' + data);
expect(code == 202).assertTrue();
done();
},
});
})
/**
* @tc.number SUB_STORAGE_File_readText_0400
* @tc.name File_readText_004
* @tc.desc Function of API, error code: 300.The test dir is exist.
*/
it('File_readText_004', 0, async function (done) {
file.readText({
uri: 'internal://cache/',
success: function (data) {
console.log(data.text);
expect(null).assertFail();
},
fail: function (data, code) {
console.log('File_readText_004 , code: ' + code + ', data: ' + data);
expect(code == 300).assertTrue();
done();
},
});
})
/**
* @tc.number SUB_STORAGE_File_readText_0500
* @tc.name File_readText_005
* @tc.desc Function of API, error code: 301.The test file and dir is exist.
*/
it('File_readText_005', 0, async function (done) {
file.readText({
uri: 'internal://cache/workspace/text.txt',
success: function (data) {
console.log(data.text);
expect(null).assertFail();
},
fail: function (data, code) {
console.log('File_readText_005 , code: ' + code + ', data: ' + data);
expect(code == 301).assertTrue();
done();
},
});
})
/**
* @tc.number SUB_STORAGE_File_readText_0600
* @tc.name File_readText_006
* @tc.desc Function of API, readText, cache path.
*/
it('File_readText_006', 0, async function (done) {
file.writeText({
uri: 'internal://cache/File_readText_006',
text: 'test',
success: function () {
console.log('File_readText_006 call success');
done();
},
fail: function (data, code) {
console.log('File_readText_006 fail, code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
file.readText({
uri: 'internal://cache/File_readText_006',
success: function (data) {
console.log('File_readText_006 call success' + data.text);
done();
},
fail: function (data, code) {
console.log('File_readText_006 fail');
expect(null).assertFail();
},
});
file.delete({
uri: 'internal://cache/File_readText_006',
success: function () {
console.log('File_readText_006 call success');
done();
},
fail: function (data, code) {
console.log('File_readText_006 fail, code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
})
})
/**
* @tc.number SUB_STORAGE_File_readText_0700
* @tc.name File_readText_007
* @tc.desc Function of API, virtual path.The test file is exist.
*/
it('File_readText_007', 0, async function (done) {
file.writeText({
uri: 'internal://app/../files/../files/File_readText_007',
text: 'Text that just for test.',
success: function () {
console.log('File_readText_007 call writeText success.');
done();
},
fail: function (data, code) {
console.log('File_readText_007 , code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
file.readText({
uri: 'internal://app/../files/../files/File_readText_007',
success: function (data) {
console.log('File_readText_007 call readText success. data.text:' + data.text);
done();
},
fail: function (data, code) {
console.log('File_readText_007 , code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
file.delete({
uri: 'internal://app/../files/../files/File_readText_007'
});
})
/**
* @tc.number SUB_STORAGE_File_read_array_buffer_0100
* @tc.name File_read_array_buffer_001
* @tc.desc Function of API, readArrayBuffer, cache path.position = 0, length = 10.
*/
it('File_read_array_buffer_001', 0, async function (done) {
var buffer = new Uint8Array([48, 49, 50, 51, 65, 66, 67, 68, 32, 33]);
file.writeArrayBuffer({
uri: 'internal://cache/File_read_array_buffer_001',
buffer: buffer,
success: function () {
console.log('File_read_array_buffer_001 call writeArrayBuffer success.');
done();
},
fail: function (data, code) {
console.log('File_read_array_buffer_001 , code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
file.readArrayBuffer({
uri: 'internal://cache/File_read_array_buffer_001',
position: 0,
length: 10,
success: function (data) {
console.log('File_read_array_buffer_001 pass');
done();
},
fail: function (data, code) {
console.log('File_read_array_buffer_001 , code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
file.delete({
uri: 'internal://cache/File_read_array_buffer_001'
});
})
/**
* @tc.number SUB_STORAGE_File_read_array_buffer_0200
* @tc.name File_read_array_buffer_002
* @tc.desc Function of API, readArrayBuffer,
*/
it('File_read_array_buffer_002', 0, async function (done) {
var buffer = new Uint8Array([48, 49, 50, 51, 65, 66, 67, 68, 32, 33]);
file.writeArrayBuffer({
uri: 'internal://cache/File_read_array_buffer_002',
buffer: buffer,
success: function () {
console.log('File_read_array_buffer_002 call writeArrayBuffer success.');
done();
},
fail: function (data, code) {
console.log('File_read_array_buffer_002 , code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
file.readArrayBuffer({
uri: 'internal://cache/File_read_array_buffer_002',
success: function (data) {
console.log('File_read_array_buffer_002 pass');
done();
},
fail: function (data, code) {
console.log('File_read_array_buffer_002 , code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
})
/**
* @tc.number SUB_STORAGE_File_read_array_buffer_0300
* @tc.name File_read_array_buffer_003
* @tc.desc Function of API, readArrayBuffer, wrong uri.
*/
it('File_read_array_buffer_003', 0, async function (done) {
file.readArrayBuffer({
uri: '',
success: function (data) {
console.log('File_read_array_buffer_003 call readArrayBuffer success: ' + data.buffer);
expect(null).assertFail();
},
fail: function (data, code) {
console.log('File_read_array_buffer_003 , code: ' + code + ', data: ' + data);
expect(code == 202).assertTrue();
done();
},
});
})
/**
* @tc.number SUB_STORAGE_File_read_array_buffer_0400
* @tc.name File_read_array_buffer_004
* @tc.desc Function of API, readArrayBuffer, wrong position.
*/
it('File_read_array_buffer_004', 0, async function (done) {
let fpath = fileName('File_read_array_buffer_004')
prepareFile(fpath, FILE_CONTENT)
file.readArrayBuffer({
uri: fpath,
position: 100,
success: function (data) {
console.log('File_read_array_buffer_004 call readArrayBuffer success: ' + data.buffer);
expect(null).assertFail();
},
fail: function (data, code) {
console.log('File_read_array_buffer_004 , code: ' + code + ', data: ' + data);
expect(code == 202).assertTrue();
done();
},
});
})
/**
* @tc.number SUB_STORAGE_File_read_array_buffer_0500
* @tc.name File_read_array_buffer_005
* @tc.desc Function of API, readArrayBuffer, wrong length.
*/
it('File_read_array_buffer_005', 0, async function (done) {
let fpath = fileName('File_read_array_buffer_005')
prepareFile(fpath, FILE_CONTENT)
file.readArrayBuffer({
uri: fpath,
length: -1,
success: function (data) {
console.log('File_read_array_buffer_005 call readArrayBuffer success: ' + data.buffer);
expect(null).assertFail();
},
fail: function (data, code) {
console.log('File_read_array_buffer_005 , code: ' + code + ', data: ' + data);
expect(code == 202).assertTrue();
done();
},
})
})
/**
* @tc.number SUB_STORAGE_File_read_array_buffer_0600
* @tc.name File_read_array_buffer_006
* @tc.desc Function of API, error code: 202 Set uri is dir path.
*/
it('File_read_array_buffer_006', 0, async function (done) {
file.readArrayBuffer({
uri: 'internal://app',
success: function (data) {
console.log('File_read_array_buffer_006 call readArrayBuffer success: ' + data.buffer);
expect(null).assertFail();
},
fail: function (data, code) {
console.log('File_read_array_buffer_006 , code: ' + code + ', data: ' + data);
expect(code == 202).assertTrue();
done();
},
});
})
/**
* @tc.number SUB_STORAGE_File_read_array_buffer_0700
* @tc.name File_read_array_buffer_007
* @tc.desc Function of API, error code: 301
*/
it('File_read_array_buffer_007', 0, async function (done) {
file.readArrayBuffer({
uri: 'internal://cache/File_read_array_buffer_007',
success: function (data) {
resolve('File_read_array_buffer_007 call readArrayBuffer success: ' + data.buffer);
expect(null).assertFail();
},
fail: function (data, code) {
console.log('File_read_array_buffer_007 , code: ' + code + ', data: ' + data);
expect(code == 301).assertTrue();
done();
},
});
})
/**
* @tc.number SUB_STORAGE_File_read_array_buffer_0800
* @tc.name File_read_array_buffer_008
* @tc.desc Function of API, cache path.The test file is exist.
*/
it('File_read_array_buffer_008', 0, async function (done) {
let buf = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8])
file.writeArrayBuffer({
uri: 'internal://app/File_read_array_buffer_008',
buffer: buf,
success: function () {
console.log('File_read_array_buffer_008 call success');
done();
},
fail: function (data, code) {
console.log('File_read_array_buffer_008 fail, code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
})
file.readArrayBuffer({
uri: 'internal://app/File_read_array_buffer_008',
success: function (data) {
console.log('File_read_array_buffer_008 call success ' + data.buffer);
done();
},
fail: function (data, code) {
console.log('File_read_array_buffer_008 fail');
expect(null).assertFail();
},
});
file.delete({
uri: 'internal://app/File_read_array_buffer_008',
success: function () {
console.log('File_read_array_buffer_008:call success');
done();
},
fail: function (data, code) {
console.log('File_read_array_buffer_008 fail, code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
})
/**
* @tc.number SUB_STORAGE_File_read_array_buffer_0900
* @tc.name File_read_array_buffer_009
* @tc.desc Function of API, virtual path.The test file is exist.
*/
it('File_read_array_buffer_009', 0, async function (done) {
var buffer = new Uint8Array([48, 49, 50, 51, 65, 66, 67, 68, 32, 33]);
file.writeArrayBuffer({
uri: 'internal://cache/../cache/File_read_array_buffer_009',
buffer: buffer,
success: function () {
console.log('File_read_array_buffer_009 call writeArrayBuffer success.');
done();
},
fail: function (data, code) {
console.log('File_read_array_buffer_009 , code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
file.readArrayBuffer({
uri: 'internal://cache/../cache/File_read_array_buffer_009',
position: 0,
length: 10,
success: function (data) {
console.log('File_read_array_buffer_009 call readArrayBuffer success. data.buffer:' + data.buffer);
done();
},
fail: function (data, code) {
console.log('File_read_array_buffer_009 , code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
file.delete({
uri: 'internal://cache/../cache/File_read_array_buffer_009'
});
})
/**
* @tc.number SUB_STORAGE_File_access_0100
* @tc.name File_access_001
* @tc.desc Function of API, access, cache path.The test file is exist.
*/
it('File_access_001', 0, async function (done) {
file.writeText({
uri: 'internal://cache/File_access_001',
text: 'Text that just for test.',
success: function () {
console.log('File_access_001 call success.');
done();
},
fail: function (data, code) {
console.log('File_access_001 fail,code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
file.access({
uri: 'internal://cache/File_access_001',
success: function () {
console.log('File_access_001 call access success.');
done();
},
fail: function (data, code) {
console.log('File_access_001 , code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
file.delete({
uri: 'internal://cache/File_access_001',
success: function () {
console.log('File_access_001 call delete success.');
done();
},
fail: function (data, code) {
console.log('File_access_001 , code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
})
/**
* @tc.number SUB_STORAGE_File_access_0200
* @tc.name File_access_002
* @tc.desc Function of API, access, app path.The test file is exist.
*/
it('File_access_002', 0, async function (done) {
file.mkdir({
uri: 'internal://app/File_access_002',
success: function () {
console.log('File_access_002 call success.');
done();
},
fail: function (data, code) {
console.log('File_access_002 fail, code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
file.access({
uri: 'internal://app/File_access_002',
success: function () {
console.log('File_access_002 call access success.');
done();
},
fail: function (data, code) {
console.log('File_access_002 , code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
file.rmdir({
uri: 'internal://app/File_access_002',
success: function () {
console.log('File_access_002 call rmdir success.');
done();
},
fail: function (data, code) {
console.log('File_access_002 , code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
})
/**
* @tc.number SUB_STORAGE_File_access_0300
* @tc.name File_access_003
* @tc.desc Function of API, error code: 202 The test file and dir are exist.
*/
it('File_access_003', 0, async function (done) {
let fpath = fileName('File_access_003')
file.access({
uri: fpath,
success: function () {
console.log('File_access_003 call access success.');
expect(null).assertFail();
},
fail: function (data, code) {
console.log('File_access_003 , code: ' + code + ', data: ' + data);
expect(code == 202).assertTrue();
done();
},
});
})
/**
* @tc.number SUB_STORAGE_File_access_0400
* @tc.name File_access_004
* @tc.desc Function of API, error code: 301
*/
it('File_access_004', 0, async function (done) {
file.access({
uri: 'internal://app/File_access_004.txt',
success: function () {
console.log('File_access_004 call access success.');
expect(null).assertFail();
},
fail: function (data, code) {
console.log('File_access_004 , code: ' + code + ', data: ' + data);
expect(code == 301).assertTrue();
done();
},
});
})
/**
* @tc.number SUB_STORAGE_File_access_0500
* @tc.name File_access_005
* @tc.desc Function of API, error code: 301
*/
it('File_access_005', 0, async function (done) {
file.access({
uri: 'internal://app/File_access_005',
success: function () {
console.log('File_access_005 call access success.');
expect(null).assertFail();
},
fail: function (data, code) {
console.log('File_access_005 , code: ' + code + ', data: ' + data);
expect(code == 301).assertTrue();
done();
},
});
})
/**
* @tc.number SUB_STORAGE_File_access_0600
* @tc.name File_access_006
* @tc.desc Function of API, parameter more than 4096.The test file and dir are exist.
*/
it('File_access_006', 0, async function (done) {
let firstPath = randomString(32);
let dpath = fileName(firstPath);
let uri = 'internal://cache/' + firstPath;
fileio.mkdirSync(dpath);
for (let i = 0; i < 16; i++) {
console.log('time' + i);
let sonPath = randomString(251);
uri = uri + '/f' + sonPath;
}
file.access({
uri: uri,
success: function () {
console.log('File_access_006 => pass');
expect(null).assertFail();
},
fail: function (data, code) {
console.log('File_access_006 , code: ' + code + ', data: ' + data);
expect(code == 300).assertTrue();
fileio.rmdirSync(dpath);
done();
},
});
})
/**
* @tc.number SUB_STORAGE_File_access_0700
* @tc.name File_access_007
* @tc.desc Function of API, app path.The test file is exist.
*/
it('File_access_007', 0, async function (done) {
file.writeText({
uri: 'internal://app/File_access_007',
text: 'hello',
success: function () {
console.log('File_access_007 mkdir success ')
done();
},
fail: function (data, code) {
console.log('File_access_007 fail, code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
file.access({
uri: 'internal://app/File_access_007',
success: function () {
console.log('File_access_007 access success');
done();
},
fail: function (data, code) {
console.log('File_access_007 fail');
expect(null).assertFail();
},
});
file.delete({
uri: 'internal://app/File_access_007',
success: function () {
console.log('File_access_007 delete success');
done();
},
fail: function (data, code) {
console.log('File_access_007 fail, code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
})
/**
* @tc.number SUB_STORAGE_File_access_0800
* @tc.name File_access_008
* @tc.desc Function of API, virtual path.The test file is exist.
*/
it('File_access_008', 0, async function (done) {
file.writeText({
uri: 'internal://cache/../cache/File_access_008',
text: 'Text that just for test.',
success: function () {
console.log('File_access_008 mkdir success.');
done();
},
fail: function (data, code) {
console.log('File_access_008 fail,code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
file.access({
uri: 'internal://cache/../cache/File_access_008',
success: function () {
console.log('File_access_008 call access success.');
done();
},
fail: function (data, code) {
console.log('File_access_008 , code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
file.delete({
uri: 'internal://cache/../cache/File_access_008',
success: function () {
console.log('File_access_008 call delete success.');
done();
},
fail: function (data, code) {
console.log('File_access_008 , code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
})
/**
* @tc.number SUB_STORAGE_File_mkdir_0100
* @tc.name File_mkdir_001
* @tc.desc Function of API, mkdir, app path.
*/
it('File_mkdir_001', 0, async function (done) {
file.mkdir({
uri: 'internal://app/File_mkdir_001',
success: function () {
console.log('File_mkdir_001 call mkdir success.');
done();
},
fail: function (data, code) {
console.log('File_mkdir_001 , code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
file.rmdir({
uri: 'internal://app/File_mkdir_001',
success: function () {
console.log('File_mkdir_001 call rmdir success.');
done();
},
fail: function (data, code) {
console.log('File_mkdir_001 , code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
})
/**
* @tc.number SUB_STORAGE_File_mkdir_0200
* @tc.name File_mkdir_002
* @tc.desc Function of API, mkdir, recursive not set value.
*/
it('File_mkdir_002', 0, async function (done) {
file.mkdir({
uri: 'internal://app/test/File_mkdir_002',
success: function () {
console.log('File_mkdir_002 call mkdir success.');
expect(null).assertFail();
},
fail: function (data, code) {
console.log('File_mkdir_002 , code: ' + code + ', data: ' + data);
expect(code == 300).assertTrue();
done();
},
});
})
/**
* @tc.number SUB_STORAGE_File_mkdir_0300
* @tc.name File_mkdir_003
* @tc.desc Function of API, mkdir, recursive.
*/
it('File_mkdir_003', 0, async function (done) {
file.mkdir({
uri: 'internal://app/test/File_mkdir_003d',
recursive: true,
success: function () {
console.log('File_mkdir_003 call mkdir success.');
done();
},
fail: function (data, code) {
console.log('File_mkdir_003 , code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
})
/**
* @tc.number SUB_STORAGE_File_mkdir_0400
* @tc.name File_mkdir_004
* @tc.desc Function of API, error code: 202
*/
it('File_mkdir_004', 0, async function (done) {
file.mkdir({
uri: 'internal://files/test/File_mkdir_002d',
success: function () {
console.log('File_mkdir_004 call mkdir success.');
expect(null).assertFail();
},
fail: function (data, code) {
console.log('File_mkdir_004, code: ' + code + ', data: ' + data);
expect(code == 202).assertTrue();
done();
},
});
})
/**
* @tc.number SUB_STORAGE_File_mkdir_0500
* @tc.name File_mkdir_005
* @tc.desc Function of API, special characters.
*/
it('File_mkdir_005', 0, async function (done) {
file.mkdir({
uri: 'internal://cache/!@/<>',
success: function () {
console.log('File_mkdir_005 mkdir success');
expect(null).assertFail();
},
fail: function (data, code) {
console.log('File_mkdir_005 fail, code: ' + code + ', data: ' + data);
expect(code == 300).assertTrue();
done();
},
});
})
/**
* @tc.number SUB_STORAGE_File_mkdir_0600
* @tc.name File_mkdir_006
* @tc.desc Function of API, parameter too long.
*/
it('File_mkdir_006', 0, async function (done) {
let fileName = randomString(257);
file.mkdir({
uri: 'internal://cache/' + fileName,
success: function () {
console.log('File_mkdir_006 mkdir success');
expect(null).assertFail();
},
fail: function (data, code) {
console.log('File_mkdir_006 =>fail ,code:' + code + ',data: ' + data);
expect(code == 300).assertTrue();
done();
},
});
})
/**
* @tc.number SUB_STORAGE_File_mkdir_0700
* @tc.name File_mkdir_007
* @tc.desc Function of API, cache path.
*/
it('File_mkdir_007', 0, async function (done) {
file.mkdir({
uri: 'internal://cache/File_mkdir_007d',
success: function () {
console.log('File_mkdir_007 mkdir success');
done();
},
fail: function (data, code) {
console.log('File_mkdir_007 fail, code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
file.rmdir({
uri: 'internal://cache/File_mkdir_007d',
success: function () {
console.log('File_mkdir_007 delete success');
done();
},
fail: function (data, code) {
console.log('File_mkdir_007 fail, code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
})
})
/**
* @tc.number SUB_STORAGE_File_mkdir_0800
* @tc.name File_mkdir_008
* @tc.desc Function of API, virtual path.
*/
it('File_mkdir_008', 0, async function (done) {
file.mkdir({
uri: 'internal://app/../files/File_mkdir_008',
success: function () {
console.log('File_mkdir_008 call mkdir success.');
done();
},
fail: function (data, code) {
console.log('File_mkdir_008 , code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
file.rmdir({
uri: 'internal://app/../files/File_mkdir_008',
success: function () {
console.log('File_mkdir_008 call rmdir success.');
done();
},
fail: function (data, code) {
console.log('File_mkdir_008 , code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
})
/**
* @tc.number SUB_STORAGE_File_mkdir_1000
* @tc.name File_mkdir_010
* @tc.desc Function of API, out of package, out of package, Virtual path, save the dir authority.
*/
it('File_mkdir_010', 0, async function (done) {
file.mkdir({
uri: 'internal://app/../../File_mkdir_010',
success: function () {
console.log('File_mkdir_010 call mkdir success.');
expect(null).assertFail();
},
fail: function (data, code) {
console.log('File_mkdir_010 call mkdir callback fail, code: ' + code + ', data: ' + data);
expect(code == 300).assertTrue();
done();
},
});
})
/**
* @tc.number SUB_STORAGE_File_rmdir_0100
* @tc.name File_rmdir_001
* @tc.desc Function of API, rmdir, app path.The test dir is exist, and it can be delete, the dir is empty.
*/
it('File_rmdir_001', 0, async function (done) {
file.mkdir({
uri: 'internal://app/File_rmdir_001',
success: function () {
console.log('File_rmdir_001 call mkdir success.');
done();
},
fail: function (data, code) {
console.log('File_rmdir_001 fail, code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
file.rmdir({
uri: 'internal://app/File_rmdir_001',
success: function () {
console.log('File_rmdir_001 call rmdir success.');
done();
},
fail: function (data, code) {
console.log('File_rmdir_001 fail, code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
})
/**
* @tc.number SUB_STORAGE_File_rmdir_0200
* @tc.name File_rmdir_002
* @tc.desc Function of API, recursive not set value.The test dir is exist, and it not empty.
*/
it('File_rmdir_002', 0, async function (done) {
file.mkdir({
uri: 'internal://app/test/File_rmdir_002',
recursive: true,
success: function () {
console.log('File_rmdir_002 mkdir success.');
done();
},
fail: function (data, code) {
console.log('File_rmdir_002 fail, code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
file.rmdir({
uri: 'internal://app/test',
recursive: false,
success: function () {
console.log('File_rmdir_002 call rmdir success.');
expect(null).assertFail();
},
fail: function (data, code) {
console.log('File_rmdir_002 fail, code: ' + code + ', data: ' + data);
expect(code == 300).assertTrue();
done();
},
});
})
/**
* @tc.number SUB_STORAGE_File_rmdir_0300
* @tc.name File_rmdir_003
* @tc.desc Function of API, recursive = ture.The test dir is exist, and it not empty.
*/
it('File_rmdir_003', 0, async function (done) {
file.mkdir({
uri: 'internal://app/test/File_rmdir_003',
recursive: true,
success: function () {
console.log('File_rmdir_003 mkdir success.');
done();
},
fail: function (data, code) {
console.log('File_rmdir_003 fail');
expect(null).assertFail();
},
});
file.rmdir({
uri: 'internal://app/test',
recursive: true,
success: function () {
console.log('File_rmdir_003 call rmdir success.');
done();
},
fail: function (data, code) {
console.log('File_rmdir_003 , code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
})
/**
* @tc.number SUB_STORAGE_File_rmdir_0400
* @tc.name File_rmdir_004
* @tc.desc Function of API, error code: 202
*/
it('File_rmdir_004', 0, async function (done) {
file.rmdir({
uri: '/data/accounts/account_0/appdata/ohos.acts.distributeddatamgr.distributedfile/cache/',
success: function () {
console.log('File_rmdir_004 call rmdir success.');
expect(null).assertFail();
},
fail: function (data, code) {
console.log('File_rmdir_004 , code: ' + code + ', data: ' + data);
expect(code == 202).assertTrue();
done();
},
});
})
/**
* @tc.number SUB_STORAGE_File_rmdir_0500
* @tc.name File_rmdir_005
* @tc.desc Function of API, error code: 301
*/
it('File_rmdir_005', 0, async function (done) {
file.rmdir({
uri: 'internal://app/test/123',
success: function () {
console.log('File_rmdir_005 call rmdir success.');
expect(null).assertFail();
},
fail: function (data, code) {
console.log('File_rmdir_005 , code: ' + code + ', data: ' + data);
expect(code == 301).assertTrue();
done();
},
});
})
/**
* @tc.number SUB_STORAGE_File_rmdir_0600
* @tc.name File_rmdir_006
* @tc.desc Function of API, too long path.
*/
it('File_rmdir_006', 0, async function (done) {
let firstPath = randomString(255);
let uri = 'internal://app/' + firstPath;
file.mkdir({
uri: uri,
success: function () {
console.log('File_rmdir_006 mkdir success');
done();
},
fail: function (data, code) {
console.log('File_rmdir_006 fail');
expect(null).assertFail();
},
});
file.rmdir({
uri: uri,
success: function () {
console.log('File_rmdir_006 => rmdir success');
done();
},
fail: function (data, code) {
console.log('File_rmdir_006 => fail');
expect(null).assertFail();
},
});
})
/**
* @tc.number SUB_STORAGE_File_rmdir_0700
* @tc.name File_rmdir_007
* @tc.desc Function of API, cache path.The test dir is exist, and it can be delete, it is empty.
*/
it('File_rmdir_007', 0, async function (done) {
file.mkdir({
uri: 'internal://cache/File_rmdir_007d',
success: function () {
console.log('File_rmdir_007 mkdir success');
done();
},
fail: function (data, code) {
console.log('File_rmdir_007 fail, code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
file.rmdir({
uri: 'internal://cache/File_rmdir_007d',
success: function () {
console.log('File_rmdir_007 mkdir success');
done();
},
fail: function (data, code) {
console.log('File_rmdir_007 fail, code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
})
})
/**
* @tc.number SUB_STORAGE_File_rmdir_0800
* @tc.name File_rmdir_008
* @tc.desc Function of API, virtual path.The test dir is exist.
*/
it('File_rmdir_008', 0, async function (done) {
file.mkdir({
uri: 'internal://app/../files/File_rmdir_008',
success: function () {
console.log('File_rmdir_008 call mkdir success.');
done();
},
fail: function (data, code) {
console.log('File_rmdir_008 , code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
file.rmdir({
uri: 'internal://app/../files/File_rmdir_008',
success: function () {
console.log('File_rmdir_008 call rmdir success.');
done();
},
fail: function (data, code) {
console.log('File_rmdir_008 , code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
})
/**
* @tc.number SUB_STORAGE_File_rmdir_1000
* @tc.name File_rmdir_010
* @tc.desc Function of API, out of package, Virtual path, save the dir authority.The test dir is exist.
*/
it('File_rmdir_010', 0, async function (done) {
file.rmdir({
uri: 'internal://app/../../com.ohos.systemui',
success: function () {
console.log('File_rmdir_010 call rmdir success.');
expect(null).assertFail();
},
fail: function (data, code) {
console.log('File_rmdir_010 call rmdir callback fail, code: ' + code + ', data: ' + data);
expect(code == 300).assertTrue();
done();
},
});
})
/**
* @tc.number SUB_STORAGE_File_Move_0100
* @tc.name File_Move_001
* @tc.desc Function of API, move.The test file is exist.
*/
it('File_Move_001', 0, async function (done) {
file.writeText({
uri: 'internal://app/File_Move_001',
text: 'Text that just for test.',
success: function () {
console.log('File_Move_001 call writeText success.');
done();
},
fail: function (data, code) {
console.error('File_Move_001 call writeText fail, code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
file.move({
srcUri: 'internal://app/File_Move_001',
dstUri: 'internal://app/File_Move_001_1',
success: function (data) {
console.log('File_Move_001 call writeText success. data:' + data);
done();
},
fail: function (data, code) {
console.log('File_Move_001 , code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
})
/**
* @tc.number SUB_STORAGE_File_Move_0200
* @tc.name File_Move_002
* @tc.desc Function of API, document integrity.The test file is exist.
*/
it('File_Move_002', 0, async function (done) {
let typeArray = new Array('.txt', '.ppt', '.flac', '.mp4', '.so', '.zip');
let dpath = fileName('cache');
fileio.mkdirSync(dpath);
for (let i = 0; i < typeArray.length; i++) {
let srcFpath = fileName('File_Move_002') + typeArray[i];
let dstFpath = cacheFileName('File_Move_002') + typeArray[i];
expect(prepareEmptyFile(srcFpath) !== null).assertTrue();
file.move({
srcUri: 'internal://app/File_Move_002' + typeArray[i],
dstUri: 'internal://app/cache/File_Move_002' + typeArray[i],
success: function (uri) {
console.log('File_Move_002 call move success. uri: ' + uri);
done();
},
fail: function (data, code) {
console.log('File_Move_002 , code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
}
})
/**
* @tc.number SUB_STORAGE_File_Move_0300
* @tc.name File_Move_003
* @tc.desc Function of API, different size file.The test file is exist.
*/
it('File_Move_003', 0, async function (done) {
let srcFpath = fileName('File_Move_003');
expect(prepareFile(srcFpath, FILE_CONTENT) !== null).assertTrue();
let dstFpath = cacheFileName('File_Move_003');
let srcUri = 'internal://app/File_Move_003'
let dstUri = 'internal://app/cache/File_Move_003'
file.move({
srcUri: srcUri,
dstUri: dstUri,
success: function () {
console.log('File_Move_003 call move success.');
done();
},
fail: function (data, code) {
console.log('File_Move_003 , code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
})
/**
* @tc.number SUB_STORAGE_File_Move_0400
* @tc.name File_Move_004
* @tc.desc Function of API, error code: 202.The test file is exist.
*/
it('File_Move_004', 0, async function (done) {
let srcFpath = fileName('File_Move_004');
expect(prepareFile(srcFpath, FILE_CONTENT) !== null).assertTrue();
file.move({
srcUri: 'internal://app/File_Move_004',
dstUri: null,
success: function () {
console.log('File_Move_004 call move success.');
expect(null).assertFail();
},
fail: function (data, code) {
console.log('File_Move_004 , code: ' + code + ', data: ' + data);
expect(code == 202).assertTrue();
done();
},
});
})
/**
* @tc.number SUB_STORAGE_File_Move_0500
* @tc.name File_Move_005
* @tc.desc Function of API, error code: 300.The test file is exist.
*/
it('File_Move_005', 0, async function (done) {
let srcDpath = fileName('File_Move_005d')
expect(fileio.mkdirSync(srcDpath) !== null).assertTrue()
file.move({
srcUri: 'internal://app/File_Move_005d',
dstUri: 'internal://app/cache/File_Move_005d',
success: function () {
console.log('File_Move_005 call move success.');
expect(null).assertFail();
},
fail: function (data, code) {
console.log('File_Move_005 , code: ' + code + ', data: ' + data);
expect(code == 300).assertTrue();
done();
},
});
})
/**
* @tc.number SUB_STORAGE_File_Move_0600
* @tc.name File_Move_006
* @tc.desc Function of API, error code: 301.The test file is not exist.
*/
it('File_Move_006', 0, async function (done) {
let dstUri = fileName('File_Move_006');
expect(prepareFile(dstUri, FILE_CONTENT) !== null).assertTrue();
file.move({
srcUri: 'internal://app/File_Move',
dstUri: 'internal://app/File_Move_006',
success: function () {
console.log('File_Move_006 call move success.');
expect(null).assertFail();
},
fail: function (data, code) {
console.log('File_Move_006 , code: ' + code + ', data: ' + data);
expect(code == 301).assertTrue();
done();
},
});
})
/**
* @tc.number SUB_STORAGE_File_Move_0700
* @tc.name File_Move_007
* @tc.desc Function of API, uri more too long.
*/
it('File_Move_007', 0, async function (done) {
let firstPath = randomString(32);
let dpath = fileName(firstPath);
let uri = 'internal://app/' + firstPath;
fileio.mkdirSync(dpath);
for (let i = 0; i < 16; i++) {
console.log('time' + i);
let sonPath = randomString(251);
uri = uri + '/f' + sonPath;
}
file.move({
srcUri: uri,
dstUri: 'internal://cache/File_Move_007',
success: function () {
console.log('File_Move_007 => move success');
expect(null).assertFail();
},
fail: function (data, code) {
console.log('File_Move_007 => move fail');
expect(code == 300).assertTrue();
done();
},
});
fileio.rmdirSync(dpath);
})
/**
* @tc.number SUB_STORAGE_File_Move_0800
* @tc.name File_Move_008
* @tc.desc Function of API, cache path.The test file is exist.
*/
it('File_Move_008', 0, async function (done) {
file.writeText({
uri: 'internal://cache/File_Move_008',
text: 'sss',
success: function () {
console.log('File_Move_008 mkdir success ');
done();
},
fail: function (data, code) {
console.log('File_Move_008 fail, code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
file.move({
srcUri: 'internal://cache/File_Move_008',
dstUri: 'internal://app/File_Move_008',
success: function (uri) {
console.log('File_Move_008 => pass, uri:' + uri);
done();
},
fail: function (data, code) {
console.log('File_Move_008 , code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
file.delete({
uri: 'internal://app/File_Move_008',
success: function () {
console.log('File_Move_008 delete success');
done();
},
fail: function (data, code) {
console.log('File_Move_008 fail, code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
})
/**
* @tc.number SUB_STORAGE_File_Move_0900
* @tc.name File_Move_009
* @tc.desc Function of API, same path.
*/
it('File_Move_009', 0, async function (done) {
let srcFpath = fileName('File_Move_009');
expect(prepareFile(srcFpath, FILE_CONTENT) !== null).assertTrue();
file.move({
srcUri: 'internal://app/File_Move_009',
dstUri: 'internal://app/File_Move_009',
success: function (data) {
console.log('File_Move_009 => pass');
expect(null).assertFail();
},
fail: function (data, code) {
console.log('File_Move_009 , code: ' + code + ', data: ' + data);
expect(code == 300).assertTrue();
done();
},
});
})
/**
* @tc.number SUB_STORAGE_File_Move_1000
* @tc.name File_Move_010
* @tc.desc Function of API, dstFpath has same file.
*/
it('File_Move_010', 0, async function (done) {
let srcFpath = fileName('File_Move_010');
let dstFpath = cacheFileName('File_Move_010');
expect(prepareFile(srcFpath, 'aaa') !== null).assertTrue();
expect(prepareFile(dstFpath, 'bbb') !== null).assertTrue();
file.move({
srcUri: 'internal://app/File_Move_010',
dstUri: 'internal://app/cache/File_Move_010',
success: function (data) {
console.log('File_Move_010 => pass');
expect(null).assertFail();
},
fail: function (data, code) {
console.log('File_Move_010 , code: ' + code + ', data: ' + data);
expect(code == 300).assertTrue();
done();
},
});
})
/**
* @tc.number SUB_STORAGE_File_Move_1100
* @tc.name File_Move_011
* @tc.desc Function of API, move app path file to cache path.
*/
it('File_Move_011', 0, async function (done) {
let srcFpath = fileName('File_Move_011');
expect(prepareFile(srcFpath, FILE_CONTENT) !== null).assertTrue();
file.move({
srcUri: 'internal://app/../files/File_Move_011',
dstUri: 'internal://app/cache/../../cache/File_Move_011',
success: function (uri) {
console.log('File_Move_011 => pass, uri' + uri);
done()
},
fail: function (data, code) {
console.log('File_Move_011 , code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
})
/**
* @tc.number SUB_STORAGE_File_Move_1200
* @tc.name File_Move_012
* @tc.desc Function of API, out of package, Virtual path(create and give 777 authority).
*/
it('File_Move_012', 0, async function (done) {
let srcFpath = fileName('File_Move_012');
expect(prepareFile(srcFpath, FILE_CONTENT) !== null).assertTrue();
file.move({
srcUri: 'internal://app/../files/File_Move_012',
dstUri: 'internal://app/../../File_Move_012',
success: function (uri) {
console.log('File_Move_012 => pass, uri' + uri);
expect(null).assertFail();
},
fail: function (data, code) {
console.log('File_Move_012 , code: ' + code + ', data: ' + data);
expect(code == 300).assertTrue();
done();
},
});
})
/**
* @tc.number SUB_STORAGE_File_Move_1400
* @tc.name File_Move_014
* @tc.desc Function of API, check back value.
*/
it('File_Move_014', 0, async function (done) {
let srcFpath = fileName('File_Move_014');
let dstFpath = cacheFileName('File_Move_014');
expect(prepareFile(srcFpath, 'test') !== null).assertTrue();
let dstUri = 'internal://app/cache/../../cache/File_Move_014';
file.move({
srcUri: 'internal://app/../files/File_Move_014',
dstUri: dstUri,
success: function (uri) {
console.log('File_Move_014 move pass');
done();
},
fail: function (data, code) {
console.log('File_Move_014 => fail , code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
})
/**
* @tc.number SUB_STORAGE_File_Copy_0100
* @tc.name File_Copy_001
* @tc.desc Function of API, copy, app path.The test file is exist.
*/
it('File_Copy_001', 0, async function (done) {
let srcFpath = fileName('File_Copy_001');
let dstFpath = cacheFileName('File_Copy_001');
expect(prepareFile(srcFpath, 'test.') !== null).assertTrue();
sleep(10);
file.copy({
srcUri: 'internal://app/File_Copy_001',
dstUri: 'internal://app/cache/File_Copy_001',
success: function () {
console.log('File_Copy_001 call copy success.');
done();
},
fail: function (data, code) {
console.log('File_Copy_001 , code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
file.readText({
uri: 'internal://app/cache/File_Copy_001',
success: function (data) {
console.log('File_Copy_001 read success:' + data.text);
expect(fileio.unlinkSync(srcFpath) !== null).assertTrue();
expect(fileio.unlinkSync(dstFpath) !== null).assertTrue();
done();
},
fail: function (data, code) {
console.log('File_Copy_001 call readText callback fail, code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
})
/**
* @tc.number SUB_STORAGE_File_Copy_0200
* @tc.name File_Copy_002
* @tc.desc Function of API, document integrity.The test file is exist.
*/
it('File_Copy_002', 0, async function (done) {
let typeArray = new Array('.txt', '.ppt', '.flac', '.mp4', '.so', '.zip');
for (let i = 0; i < typeArray.length; i++) {
let srcFpath = fileName('File_Copy_002') + typeArray[i];
let dstFpath = cacheFileName('File_Copy_002') + typeArray[i];
expect(prepareEmptyFile(srcFpath) !== null).assertTrue();
file.copy({
srcUri: 'internal://app/File_Copy_002' + typeArray[i],
dstUri: 'internal://app/cache/File_Copy_002' + typeArray[i],
success: function () {
console.log('File_Copy_002 call copy success.');
expect(fileio.unlinkSync(srcFpath) !== null).assertTrue();
expect(fileio.unlinkSync(dstFpath) !== null).assertTrue();
done();
},
fail: function (data, code) {
console.log('File_Copy_002 , code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
}
})
/**
* @tc.number SUB_STORAGE_File_Copy_0300
* @tc.name File_Copy_003
* @tc.desc Function of API, different size of files. The test file is exist.
*/
it('File_Copy_003', 0, async function (done) {
let srcFpath = fileName('File_Copy_003');
expect(prepareFile(srcFpath, FILE_CONTENT) !== null).assertTrue();
let dstFpath = cacheFileName('File_Copy_003');
file.copy({
srcUri: 'internal://app/File_Copy_003',
dstUri: 'internal://app/cache/File_Copy_003',
success: function () {
console.log('File_Copy_003 call copy success.');
done();
},
fail: function (data, code) {
console.log('File_Copy_003 , code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
file.readText({
uri: 'internal://app/cache/File_Copy_003',
success: function (data) {
console.log('File_Copy_003 readText success, data.text:' + data.text);
expect(fileio.unlinkSync(srcFpath) !== null).assertTrue();
expect(fileio.unlinkSync(dstFpath) !== null).assertTrue();
done();
},
fail: function (data, code) {
console.log('File_Copy_003 call readText callback fail, code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
})
/**
* @tc.number SUB_STORAGE_File_Copy_0400
* @tc.name File_Copy_004
* @tc.desc Function of API, error code: 202 The test file is exist.
*/
it('File_Copy_004', 0, async function (done) {
let srcFpath = fileName('File_Copy_004');
expect(prepareFile(srcFpath, FILE_CONTENT) !== null).assertTrue();
file.copy({
srcUri: 'internal://app/File_Copy_004',
dstUri: null,
success: function () {
console.log('File_Copy_004 call copy success.');
expect(null).assertFail();
},
fail: function (data, code) {
console.log('File_Copy_004 , code: ' + code + ', data: ' + data);
expect(code == 202).assertTrue();
expect(fileio.unlinkSync(srcFpath) !== null).assertTrue();
done();
},
});
})
/**
* @tc.number SUB_STORAGE_File_Copy_0500
* @tc.name File_Copy_005
* @tc.desc Function of API, error code: 300
*/
it('File_Copy_005', 0, async function (done) {
file.mkdir({
uri: 'internal://app/File_Copy_005d',
success: function () {
console.log('File_Copy_005 call mkdir success.');
done();
},
fail: function (data, code) {
console.error('File_Copy_005 call mkdir fail, code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
file.copy({
srcUri: 'internal://app/File_Copy_005d',
dstUri: 'internal://app/File_Copy_005d_1',
success: function () {
console.log('File_Copy_005 call copy success.');
expect(null).assertFail();
},
fail: function (data, code) {
console.log('File_Copy_005 , code: ' + code + ', data: ' + data);
expect(code == 300).assertTrue();
done();
},
});
})
/**
* @tc.number SUB_STORAGE_File_Copy_0600
* @tc.name File_Copy_006
* @tc.desc Function of API, error code: 301
*/
it('File_Copy_006', 0, async function (done) {
file.copy({
srcUri: 'internal://app/fakepath',
dstUri: 'internal://app/fakepath1',
success: function () {
console.log('File_Copy_006 call copy success.');
expect(null).assertFail();
},
fail: function (data, code) {
console.log('File_Copy_006 , code: ' + code + ', data: ' + data);
expect(code == 301).assertTrue();
done();
},
});
})
/**
* @tc.number SUB_STORAGE_File_Copy_0700
* @tc.name File_Copy_007
* @tc.desc Function of API, uri too long.
*/
it('File_Copy_007', 0, async function (done) {
let firstPath = randomString(32);
let dpath = fileName(firstPath);
let uri = 'internal://cache/' + firstPath;
fileio.mkdirSync(dpath);
for (let i = 0; i < 16; i++) {
console.log('time' + i);
let sonPath = randomString(251);
uri = uri + '/f' + sonPath;
}
file.copy({
srcUri: uri,
dstUri: uri,
success: function () {
console.log('File_Copy_007 => copy success');
expect(null).assertFail();
},
fail: function (data, code) {
console.log('File_Copy_007 => fail, code: ' + code + ', data: ' + data);
fileio.rmdirSync(dpath);
expect(code == 300).assertTrue();
done();
},
});
})
/**
* @tc.number SUB_STORAGE_File_Copy_0800
* @tc.name File_Copy_008
* @tc.desc Function of API, cache path.
*/
it('File_Copy_008', 0, async function (done) {
file.writeText({
uri: 'internal://cache/File_Copy_008',
text: 'test',
success: function () {
console.log('File_Copy_008 mkdir success');
done();
},
fail: function (data, code) {
console.log('File_Copy_008 fail, code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
file.copy({
srcUri: 'internal://cache/File_Copy_008',
dstUri: 'internal://app/File_Copy_008',
success: function () {
console.log('File_Copy_008 move success');
done();
},
fail: function (data, code) {
console.log('File_Copy_008 , code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
file.delete({
uri: 'internal://app/File_Copy_008',
success: function () {
console.log('File_Copy_008 delete success ');
done();
},
fail: function (data, code) {
console.log('File_Copy_008 fail, code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
})
file.delete({
uri: 'internal://cache/File_Copy_008',
success: function () {
console.log('File_Copy_008 delete success');
done();
},
fail: function (data, code) {
console.log('File_Copy_008 fail, code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
})
})
/**
* @tc.number SUB_STORAGE_File_Copy_0900
* @tc.name File_Copy_009
* @tc.desc Function of API, same path.
*/
it('File_Copy_009', 0, async function (done) {
let srcFpath = fileName('File_Copy_009')
expect(prepareFile(srcFpath, FILE_CONTENT) !== null).assertTrue();
file.copy({
srcUri: 'internal://app/File_Copy_009',
dstUri: 'internal://app/File_Copy_009',
success: function (data) {
console.log('File_Copy_009 => pass');
expect(null).assertFail();
},
fail: function (data, code) {
console.log('File_Copy_009 , code: ' + code + ', data: ' + data);
expect(code == 300).assertTrue();
fileio.unlinkSync(srcFpath);
done();
},
});
})
/**
* @tc.number SUB_STORAGE_File_Copy_1000
* @tc.name File_Copy_010
* @tc.desc Function of API, dstFpath path has same file.
*/
it('File_Copy_010', 0, async function (done) {
let srcFpath = fileName('File_Copy_010');
let dstFpath = cacheFileName('File_Copy_010');
expect(prepareFile(srcFpath, 'aaa') !== null).assertTrue();
expect(prepareFile(dstFpath, 'bbb') !== null).assertTrue();
file.copy({
srcUri: 'internal://app/File_Copy_010',
dstUri: 'internal://app/cache/File_Copy_010',
success: function (data) {
console.log('File_Copy_010 => pass');
expect(null).assertFail();
},
fail: function (data, code) {
console.log('File_Copy_010 , code: ' + code + ', data: ' + data);
expect(code == 300).assertTrue();
fileio.unlinkSync(srcFpath);
fileio.unlinkSync(dstFpath);
done();
},
});
})
/**
* @tc.number SUB_STORAGE_File_Copy_1100
* @tc.name File_Copy_011
* @tc.desc Function of API, copy file to cache path.The test file is exist.
*/
it('File_Copy_011', 0, async function (done) {
let srcFpath = fileName('File_Copy_011');
expect(prepareFile(srcFpath, 'test.') !== null).assertTrue();
file.copy({
srcUri: 'internal://app/../files/File_Copy_011',
dstUri: 'internal://app/cache/../../cache/File_Copy_011',
success: function () {
console.log('File_Copy_011 copy pass');
done();
},
fail: function (data, code) {
console.log('File_Copy_011 , code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
file.readText({
uri: 'internal://app/cache/../../cache/File_Copy_011',
success: function (data) {
console.log('File_Copy_011 read success:' + data.text);
done();
},
fail: function (data, code) {
console.log('File_Copy_011 call readText callback fail, code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
})
/**
* @tc.number SUB_STORAGE_File_Copy_1200
* @tc.name File_Copy_012
* @tc.desc Function of API, out of package, Virtual path(create and give 777 authority).The test file is exist.
*/
it('File_Copy_012', 0, async function (done) {
let srcFpath = fileName('File_Copy_012');
expect(prepareFile(srcFpath, 'test') !== null).assertTrue();
file.copy({
srcUri: 'internal://app/../files/File_Copy_012',
dstUri: 'internal://app/../../File_Move_012',
success: function () {
console.log('File_Copy_012 copy pass');
expect(null).assertFail();
},
fail: function (data, code) {
console.log('File_Copy_012 , code: ' + code + ', data: ' + data);
expect(code == 300).assertTrue();
expect(fileio.unlinkSync(srcFpath) !== null).assertTrue();
done();
},
});
})
/**
* @tc.number SUB_STORAGE_File_Copy_1400
* @tc.name File_Copy_014
* @tc.desc Function of API, check back value.The test file is exist.
*/
it('File_Copy_014', 0, async function (done) {
let srcFpath = fileName('File_Copy_014');
let dstFpath = cacheFileName('File_Copy_014');
expect(prepareFile(srcFpath, 'test') !== null).assertTrue();
let dstUri = 'internal://app/cache/../../cache/File_Copy_014';
file.copy({
srcUri: 'internal://app/../files/File_Copy_014',
dstUri: dstUri,
success: function (uri) {
console.log('File_Copy_014 copy pass');
done();
},
fail: function (data, code) {
console.log('File_Copy_014 => fail , code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
})
/**
* @tc.number SUB_STORAGE_File_List_0100
* @tc.name File_List_001
* @tc.desc Function of API, list.The test file and dir are exist.
*/
it('File_List_001', 0, async function (done) {
let dpath = fileName('File_List_001') + 'd';
let fpath = dpath + '/File_List_001';
let ddpath = dpath + '/File_List_001_1d';
expect(fileio.mkdirSync(dpath) !== null).assertTrue();
expect(fileio.mkdirSync(ddpath) !== null).assertTrue();
expect(prepareFile(fpath, FILE_CONTENT) !== null).assertTrue();
file.list({
uri: 'internal://app/File_List_001d',
success: function (data) {
console.log('File_List_001 call list success.' + JSON.stringify(data.fileList))
expect(fileio.unlinkSync(fpath) !== null).assertTrue();
expect(fileio.rmdirSync(ddpath) !== null).assertTrue();
expect(fileio.rmdirSync(dpath) !== null).assertTrue();
done();
},
fail: function (data, code) {
console.log('File_List_001 , code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
})
/**
* @tc.number SUB_STORAGE_File_List_0200
* @tc.name File_List_002
* @tc.desc Function of API, set value of uri.The test file and dir are exist.
*/
it('File_List_002', 0, async function (done) {
let dpath = fileName('File_List_002') + 'd';
let fpath = dpath + '/File_List_002';
let ddpath = dpath + '/File_List_002_1d';
expect(fileio.mkdirSync(dpath) !== null).assertTrue();
expect(fileio.mkdirSync(ddpath) !== null).assertTrue();
expect(prepareFile(fpath, FILE_CONTENT) !== null).assertTrue();
file.list({
uri: 'internal://app/File_List_002d',
success: function (data) {
console.log('File_List_002 call list success.' + JSON.stringify(data.fileList));
expect(fileio.unlinkSync(fpath) !== null).assertTrue();
expect(fileio.rmdirSync(ddpath) !== null).assertTrue();
expect(fileio.rmdirSync(dpath) !== null).assertTrue();
done();
},
fail: function (data, code) {
console.log('File_List_002 , code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
})
/**
* @tc.number SUB_STORAGE_File_List_0300
* @tc.name File_List_003
* @tc.desc Function of API, check lastModifiedTime.The test file and dir are exist.
*/
it('File_List_003', 0, async function (done) {
let dpath = fileName('File_List_003') + 'd';
let fpath = dpath + '/File_List_003';
let ddpath = dpath + '/File_List_003_1d';
expect(fileio.mkdirSync(dpath) !== null).assertTrue();
expect(fileio.mkdirSync(ddpath) !== null).assertTrue();
expect(prepareFile(fpath, FILE_CONTENT) !== null).assertTrue();
file.list({
uri: 'internal://app/File_List_003d',
success: function (data) {
console.log('File_List_003 call list success.' + JSON.stringify(data.fileList));
done();
},
fail: function (data, code) {
console.log('File_List_003 , code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
file.writeText({
uri: 'internal://app/File_List_003d/File_List_003',
text: '1',
success: function (data) {
console.log('File_List_003 call write success.');
done();
}
});
file.list({
uri: 'internal://app/File_List_003d',
success: function (data) {
console.log('File_List_003 call list success.' + JSON.stringify(data.fileList));
expect(fileio.unlinkSync(fpath) !== null).assertTrue();
expect(fileio.rmdirSync(ddpath) !== null).assertTrue();
expect(fileio.rmdirSync(dpath) !== null).assertTrue();
done();
},
fail: function (data, code) {
console.log('File_List_003 , code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
})
/**
* @tc.number SUB_STORAGE_File_List_0400
* @tc.name File_List_004
* @tc.desc Function of API, check length.The test file and dir are exist.
*/
it('File_List_004', 0, async function (done) {
let dpath = fileName('File_List_004') + 'd';
let fpath = dpath + '/File_List_004';
let ddpath = dpath + '/File_List_004_1d';
expect(fileio.mkdirSync(dpath) !== null).assertTrue();
expect(fileio.mkdirSync(ddpath) !== null).assertTrue();
expect(prepareFile(fpath, FILE_CONTENT) !== null).assertTrue();
file.list({
uri: 'internal://app/File_List_004d',
success: function (data) {
console.log('File_List_004 call list success.');
done();
},
fail: function (data, code) {
console.log('File_List_004 , code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
})
/**
* @tc.number SUB_STORAGE_File_List_0500
* @tc.name File_List_005
* @tc.desc Function of API, check type.The test file and dir are exist.
*/
it('File_List_005', 0, async function (done) {
let dpath = fileName('File_List_005') + 'd';
let fpath = dpath + '/File_List_005';
let ddpath = dpath + '/File_List_005_1d';
expect(fileio.mkdirSync(dpath) !== null).assertTrue();
expect(fileio.mkdirSync(ddpath) !== null).assertTrue();
expect(prepareFile(fpath, FILE_CONTENT) !== null).assertTrue();
file.list({
uri: 'internal://app/File_List_005d',
success: function (data) {
console.log('File_List_005 call list success.');
done();
},
fail: function (data, code) {
console.log('File_List_005 , code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
})
/**
* @tc.number SUB_STORAGE_File_List_0600
* @tc.name File_List_006
* @tc.desc Function of API, error code:202
*/
it('File_List_006', 0, async function (done) {
let dpath = fileName('File_List_006') + 'd'
file.list({
uri: dpath,
success: function (data) {
console.log('File_List_006 call list success.' + data.fileList);
expect(null).assertFail();
},
fail: function (data, code) {
console.log('File_List_006 , code: ' + code + ', data: ' + data);
expect(code == 202).assertTrue();
done();
},
});
})
/**
* @tc.number SUB_STORAGE_File_List_0700
* @tc.name File_List_007
* @tc.desc Function of API, uri set value of file.
*/
it('File_List_007', 0, async function (done) {
let fpath = fileName('File_List_007');
expect(prepareFile(fpath, FILE_CONTENT) !== null).assertTrue();
file.list({
uri: 'internal://app/File_List_007',
success: function (data) {
console.log('File_List_007 pass, data.fileList:' + JSON.stringify(data.fileList));
expect(fileio.unlinkSync(fpath) !== null).assertTrue();
done();
},
fail: function (data, code) {
console.log('File_List_007 , code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
})
/**
* @tc.number SUB_STORAGE_File_List_0800
* @tc.name File_List_008
* @tc.desc Function of API, error code: 301
*/
it('File_List_008', 0, async function (done) {
file.list({
uri: 'internal://app/fakepath',
success: function (data) {
console.log('File_List_008 call list success.' + JSON.stringify(data.fileList));
expect(null).assertFail();
},
fail: function (data, code) {
console.log('File_List_008 , code: ' + code + ', data: ' + data);
expect(code == 301).assertTrue();
done();
},
});
})
/**
* @tc.number SUB_STORAGE_File_List_0900
* @tc.name File_List_009
* @tc.desc Function of API, uri too long.
*/
it('File_List_009', 0, async function (done) {
let firstPath = randomString(32);
let dpath = fileName(firstPath);
let uri = 'internal://app/' + firstPath;
fileio.mkdirSync(dpath);
for (let i = 0; i < 16; i++) {
console.log('time' + i);
let sonPath = randomString(251);
uri = uri + '/f' + sonPath;
}
file.list({
uri: uri,
success: function (data) {
console.log('File_List_009 => pass' + data);
expect(null).assertFail();
},
fail: function (data, code) {
console.log('File_List_009 , code: ' + code + ', data: ' + data);
expect(code == 300).assertTrue();
fileio.rmdirSync(dpath);
done();
},
});
})
/**
* @tc.number SUB_STORAGE_File_List_1000
* @tc.name File_List_010
* @tc.desc Function of API, cache path.The test file and dir are exist.
*/
it('File_List_010', 0, async function (done) {
let dpath = nextFileName('File_List_010d');
let fpath = dpath + '/File_List_010';
let ffpath = dpath + '/File_List_010_1';
let ddpath = dpath + '/File_List_010_1d';
let fffpath = ddpath + '/File_List_010_2';
try {
expect(fileio.mkdirSync(dpath) !== null).assertTrue();
expect(fileio.mkdirSync(ddpath) !== null).assertTrue();
expect(prepareFile(fpath, FILE_CONTENT) !== null).assertTrue();
expect(prepareFile(ffpath, FILE_CONTENT) !== null).assertTrue();
expect(prepareFile(fffpath, FILE_CONTENT) !== null).assertTrue();
} catch (e) {
console.log("File_List_010 has failed for " + e)
expect(null).assertFail();
}
file.list({
uri: 'internal://cache/File_List_010d',
success: function (data) {
console.log('File_List_010 => pass' + JSON.stringify(data.fileList));
expect(fileio.unlinkSync(fpath) !== null).assertTrue();
expect(fileio.unlinkSync(ffpath) !== null).assertTrue();
expect(fileio.unlinkSync(fffpath) !== null).assertTrue();
expect(fileio.rmdirSync(ddpath) !== null).assertTrue();
expect(fileio.rmdirSync(dpath) !== null).assertTrue();
done();
},
fail: function (data, code) {
console.log('File_List_010 fail, code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
})
/**
* @tc.number SUB_STORAGE_File_List_1100
* @tc.name File_List_011
* @tc.desc Function of API, virtual path.The test dir are exist.
*/
it('File_List_011', 0, async function (done) {
let dpath = fileName('File_List_011') + 'd';
let fpath = dpath + '/File_List_011';
let ddpath = dpath + '/File_List_011_1d';
expect(fileio.mkdirSync(dpath) !== null).assertTrue();
expect(fileio.mkdirSync(ddpath) !== null).assertTrue();
expect(prepareFile(fpath, FILE_CONTENT) !== null).assertTrue();
file.list({
uri: 'internal://app/../files/File_List_011d',
success: function (data) {
console.log('File_List_011 call list success.' + JSON.stringify(data.fileList));
expect(fileio.unlinkSync(fpath) !== null).assertTrue();
expect(fileio.rmdirSync(ddpath) !== null).assertTrue();
expect(fileio.rmdirSync(dpath) !== null).assertTrue();
done();
},
fail: function (data, code) {
console.log('File_List_011 fail, code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
})
/**
* @tc.number SUB_STORAGE_File_List_1200
* @tc.name Function of API, out of package, Virtual path(create and give 777 authority).
* @tc.desc The test dir are exist.
*/
it('File_List_012', 0, async function (done) {
file.list({
uri: 'internal://app/../files/../../',
success: function (data) {
console.log('File_List_012 call list success.' + JSON.stringify(data.fileList));
done();
},
fail: function (data, code) {
console.log('File_List_012 fail, code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
})
/**
* @tc.number SUB_STORAGE_File_Get_0100
* @tc.name File_Get_001
* @tc.desc Function of API, Get.The test file is exist.
*/
it('File_Get_001', 0, async function (done) {
let fpath = fileName('File_Get_001');
expect(prepareFile(fpath, FILE_CONTENT) !== null).assertTrue();
file.get({
uri: 'internal://app/File_Get_001',
recursive: true,
success: function (data) {
console.log('File_Get_001 pass,data.uri:' + data.uri);
expect(fileio.unlinkSync(fpath) !== null).assertTrue();
done();
},
fail: function (data, code) {
console.log('File_Get_001 fail, code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
})
/**
* @tc.number SUB_STORAGE_File_Get_0200
* @tc.name File_Get_002
* @tc.desc Function of API, recursive = false.The test file is exist.
*/
it('File_Get_002', 0, async function (done) {
let fpath = fileName('File_Get_002');
expect(prepareFile(fpath, FILE_CONTENT) !== null).assertTrue();
file.get({
uri: 'internal://app/File_Get_002',
recursive: false,
success: function (data) {
console.log('File_Get_002 => file list:');
console.log('{uri:' + data.uri);
console.log('length:' + data.length);
console.log('lastModifiedTime:' + data.lastModifiedTime);
console.log('type:' + data.type);
console.log('subFiles:' + data.subFiles + '}');
expect(fileio.unlinkSync(fpath) !== null).assertTrue();
done();
},
fail: function (data, code) {
console.log('File_Get_002 fail, code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
})
/**
* @tc.number SUB_STORAGE_File_Get_0300
* @tc.name File_Get_003
* @tc.desc Function of API, not input recursive.The test file is exist.
*/
it('File_Get_003', 0, async function (done) {
let fpath = fileName('File_Get_003');
expect(prepareFile(fpath, FILE_CONTENT) !== null).assertTrue();
file.get({
uri: 'internal://app/File_Get_003',
success: function (data) {
console.log('File_Get_003 => file list:');
console.log('{uri:' + data.uri);
console.log('length:' + data.length);
console.log('lastModifiedTime:' + data.lastModifiedTime);
console.log('type:' + data.type);
console.log('subFiles:' + data.subFiles + '}');
console.log('File_Get_003 => pass');
expect(fileio.unlinkSync(fpath) !== null).assertTrue();
done();
},
fail: function (data, code) {
console.log('File_Get_003 fail, code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
})
/**
* @tc.number SUB_STORAGE_File_Get_0400
* @tc.name File_Get_004
* @tc.desc Function of API, recursive = ture.The test file is exist.
*/
it('File_Get_004', 0, async function (done) {
let dpath = fileName('File_Get_004d')
let ddpath = dpath + '/File_Get_004dd'
let fpath = dpath + '/File_Get_004f'
let ffpath = ddpath + '/File_Get_004ff'
expect(fileio.mkdirSync(dpath) !== null).assertTrue();
expect(fileio.mkdirSync(ddpath) !== null).assertTrue();
expect(prepareFile(fpath, FILE_CONTENT) !== null).assertTrue();
expect(prepareFile(ffpath, FILE_CONTENT) !== null).assertTrue();
file.get({
uri: 'internal://app/File_Get_004d',
recursive: true,
success: function (data) {
console.log('File_Get_004 => file list:');
console.log('{uri:' + data.uri);
console.log('length:' + data.length);
console.log('lastModifiedTime:' + data.lastModifiedTime);
console.log('type:' + data.type);
console.log('subFiles:' + data.subFiles + '}');
console.log('File_Get_004 => pass');
expect(fileio.unlinkSync(ffpath) !== null).assertTrue();
expect(fileio.unlinkSync(fpath) !== null).assertTrue();
expect(fileio.rmdirSync(ddpath) !== null).assertTrue();
expect(fileio.rmdirSync(dpath) !== null).assertTrue();
done();
},
fail: function (data, code) {
console.log('File_Get_004 fail, code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
})
/**
* @tc.number SUB_STORAGE_File_Get_0500
* @tc.name File_Get_005
* @tc.desc Function of API, recursive = false.The test file is exist.
*/
it('File_Get_005', 0, async function (done) {
let dpath = fileName('File_Get_005d');
let ddpath = dpath + '/File_Get_005dd';
let fpath = dpath + '/File_Get_005f';
let ffpath = ddpath + '/File_Get_005ff';
expect(fileio.mkdirSync(dpath) !== null).assertTrue();
expect(fileio.mkdirSync(ddpath) !== null).assertTrue();
expect(prepareFile(fpath, FILE_CONTENT) !== null).assertTrue();
expect(prepareFile(ffpath, FILE_CONTENT) !== null).assertTrue();
file.get({
uri: 'internal://app/File_Get_005d',
recursive: false,
success: function (data) {
console.log('File_Get_005 => file list :');
console.log('{uri:' + data.uri);
console.log('length:' + data.length);
console.log('lastModifiedTime:' + data.lastModifiedTime);
console.log('type:' + data.type);
console.log('subFiles:' + data.subFiles + '}');
console.log('File_Get_005 => pass');
expect(fileio.unlinkSync(ffpath) !== null).assertTrue();
expect(fileio.unlinkSync(fpath) !== null).assertTrue();
expect(fileio.rmdirSync(ddpath) !== null).assertTrue();
expect(fileio.rmdirSync(dpath) !== null).assertTrue();
done();
},
fail: function (data, code) {
console.log('File_Get_005 fail, code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
})
/**
* @tc.number SUB_STORAGE_File_Get_0600
* @tc.name File_Get_006
* @tc.desc Function of API, not input recursive.The test file is exist.
*/
it('File_Get_006', 0, async function (done) {
let dpath = fileName('File_Get_006d');
let ddpath = dpath + '/File_Get_006dd';
let fpath = dpath + '/File_Get_006f';
let ffpath = ddpath + '/File_Get_006ff';
expect(fileio.mkdirSync(dpath) !== null).assertTrue();
expect(fileio.mkdirSync(ddpath) !== null).assertTrue();
expect(prepareFile(fpath, FILE_CONTENT) !== null).assertTrue();
expect(prepareFile(ffpath, FILE_CONTENT) !== null).assertTrue();
file.get({
uri: 'internal://app/File_Get_006d',
success: function (data) {
console.log('File_Get_006 file list:');
console.log('{uri:' + data.uri);
console.log('length:' + data.length);
console.log('lastModifiedTime:' + data.lastModifiedTime);
console.log('type:' + data.type);
console.log('subFiles:' + data.subFiles + '}');
console.log('File_Get_006 => pass');
expect(fileio.unlinkSync(ffpath) !== null).assertTrue();
expect(fileio.unlinkSync(fpath) !== null).assertTrue();
expect(fileio.rmdirSync(ddpath) !== null).assertTrue();
expect(fileio.rmdirSync(dpath) !== null).assertTrue();
done();
},
fail: function (data, code) {
console.log('File_Get_006 fail, code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
})
/**
* @tc.number SUB_STORAGE_File_Get_0700
* @tc.name File_Get_007
* @tc.desc Function of API, not input uri.The test file is exist.
*/
it('File_Get_007', 0, async function (done) {
file.get({
recursive: true,
success: function (data) {
console.log('File_Get_007 call Copy success.')
expect(null).assertFail();
},
fail: function (data, code) {
console.log('File_Get_007 fail, code: ' + code + ', data: ' + data);
expect(code == 202).assertTrue();
done();
},
});
})
/**
* @tc.number SUB_STORAGE_File_Get_0800
* @tc.name File_Get_008
* @tc.desc Function of API, not input parameter.The test file is exist.
*/
it('File_Get_008', 0, async function (done) {
file.get({
success: function (data) {
console.log(data);
expect(null).assertFail();
},
fail: function (data, code) {
console.log('File_Get_008 fail, code: ' + code + ', data: ' + data);
expect(code == 202).assertTrue();
done();
},
});
})
/**
* @tc.number SUB_STORAGE_File_Get_0900
* @tc.name File_Get_009
* @tc.desc Function of API, error parameter.The test file and dir are not exist.
*/
it('File_Get_009', 0, async function (done) {
file.get({
uri: 'internal://app/File_Get_009',
success: function (data) {
console.log('File_Get_009 call Copy success.');
expect(null).assertFail();
},
fail: function (data, code) {
console.log('File_Get_009 fail, code: ' + code + ', data: ' + data);
expect(code == 301).assertTrue();
done();
},
});
})
/**
* @tc.number SUB_STORAGE_File_Get_1000
* @tc.name File_Get_010
* @tc.desc Function of API, uri = -1.
*/
it('File_Get_010', 0, async function (done) {
file.get({
uri: -1,
success: function (data) {
console.log('File_Get_010 call Copy success.');
expect(null).assertFail();
},
fail: function (data, code) {
console.log('File_Get_010 fail, code: ' + code + ', data: ' + data);
expect(code == 202).assertTrue();
done();
},
});
})
/**
* @tc.number SUB_STORAGE_File_Get_1100
* @tc.name File_Get_011
* @tc.desc Function of API, cacahe path.
*/
it('File_Get_011', 0, async function (done) {
file.writeText({
uri: 'internal://cache/File_Get_011',
text: 'test',
success: function () {
console.log('File_Get_011 mkdir success');
done();
},
fail: function (data, code) {
console.log('File_Get_011 fail, code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
})
file.get({
uri: 'internal://cache/File_Get_011',
recursive: true,
success: function (data) {
console.log('file list');
console.log('uri:' + data.uri);
console.log('length:' + data.length);
console.log('lastModifiedTime:' + data.lastModifiedTime);
console.log('type:' + data.type);
console.log('subFiles:' + data.subFiles);
done();
},
fail: function (data, code) {
console.log('File_Get_011 fail, code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
file.delete({
uri: 'internal://cache/File_Get_011',
success: function () {
console.log('File_Get_011 delete success');
done();
},
fail: function (data, code) {
console.log('File_Get_011 fail, code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
})
})
/**
* @tc.number SUB_STORAGE_File_Get_1200
* @tc.name File_Get_012
* @tc.desc Function of API, uri too long.
*/
it('File_Get_012', 0, async function (done) {
let firstPath = randomString(32);
let dpath = fileName(firstPath);
let uri = 'internal://cache/' + firstPath;
expect(fileio.mkdirSync(dpath) !== null).assertTrue();
for (let i = 0; i < 16; i++) {
console.log('time' + i);
let sonPath = randomString(251);
uri = uri + '/f' + sonPath;
}
file.get({
uri: uri,
recursive: true,
success: function (data) {
console.log('file list');
console.log('uri:' + data.uri);
console.log('length:' + data.length);
console.log('lastModifiedTime:' + data.lastModifiedTime);
console.log('type:' + data.type);
console.log('subFiles:' + data.subFiles);
console.log('File_Get_012 => pass');
expect(null).assertFail();
},
fail: function (data, code) {
console.log('File_Get_012 fail, code: ' + code + ', data: ' + data);
expect(code == 300).assertTrue();
done();
},
});
})
/**
* @tc.number SUB_STORAGE_File_Get_1300
* @tc.name File_Get_013
* @tc.desc Function of API, virtual path.
*/
it('File_Get_013', 0, async function (done) {
let dpath = fileName('File_Get_013d');
let ddpath = dpath + '/File_Get_013dd';
let fpath = dpath + '/File_Get_013f';
let ffpath = ddpath + '/File_Get_013ff';
expect(fileio.mkdirSync(dpath) !== null).assertTrue();
expect(fileio.mkdirSync(ddpath) !== null).assertTrue();
expect(prepareFile(fpath, FILE_CONTENT) !== null).assertTrue();
expect(prepareFile(ffpath, FILE_CONTENT) !== null).assertTrue();
file.get({
uri: 'internal://app/../files/File_Get_013d',
recursive: true,
success: function (data) {
console.log('File_Get_013 => file list:');
console.log('{uri:' + data.uri);
console.log('length:' + data.length);
console.log('lastModifiedTime:' + data.lastModifiedTime);
console.log('type:' + data.type);
console.log('subFiles:' + data.subFiles + '}');
console.log('File_Get_013 => pass');
expect(fileio.unlinkSync(ffpath) !== null).assertTrue();
expect(fileio.unlinkSync(fpath) !== null).assertTrue();
expect(fileio.rmdirSync(ddpath) !== null).assertTrue();
expect(fileio.rmdirSync(dpath) !== null).assertTrue();
done();
},
fail: function (data, code) {
console.log('File_Get_013 fail, code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
})
/**
* @tc.number SUB_STORAGE_File_Get_1400
* @tc.name File_Get_014
* @tc.desc Function of API, out of package, Virtual path, save the dir authority.
*/
it('File_Get_014', 0, async function (done) {
file.get({
uri: 'internal://app/../files/../../',
success: function (data) {
console.log('File_Get_014 => file list :');
console.log('{uri:' + data.uri);
console.log('length:' + data.length);
console.log('lastModifiedTime:' + data.lastModifiedTime);
console.log('type:' + data.type);
console.log('subFiles:' + data.subFiles + '}');
console.log('File_Get_014 => pass');
done();
},
fail: function (data, code) {
console.log('File_Get_014 fail, code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
})
})
\ No newline at end of file
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import fileio from '@ohos.fileio';
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index'
import {
FILE_CONTENT, prepareFile, nextFileName, prepareEmptyFile, differentFileName, randomString, fileName
} from './Common'
describe('fileIOTest', function () {
/**
* @tc.number SUB_STORAGE_FileIO_open&closesync_0000
* @tc.name fileio_test_open_close_sync_000
* @tc.desc Function of API, openSync. The test file is exist.
*/
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 !== null).assertTrue()
expect(fileio.closeSync(fd) !== null).assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_open_close_sync_000 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_OpenSync_0000
* @tc.name fileio_test_open_000
* @tc.desc Function of API, openSync(mode not for value). The test file is exist.
*/
it('fileio_test_open_000', 0, function () {
let fpath = nextFileName('fileio_test_open_000')
prepareFile(fpath, FILE_CONTENT)
try {
let fd = fileio.openSync(fpath, 0o202)
expect(fd !== null).assertTrue()
expect(fileio.closeSync(fd) !== null).assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_open_000 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_OpenSync_0100
* @tc.name fileio_test_open_sync_001
* @tc.desc Function of API, openSync(flags=0o200). The test file is exist.
*/
it('fileio_test_open_sync_001', 0, function () {
let fpath = nextFileName('fileio_test_open_sync_001')
prepareFile(fpath, FILE_CONTENT)
try {
let fd = fileio.openSync(fpath, 0o200)
expect(fd !== null).assertTrue()
expect(fileio.closeSync(fd) !== null).assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_open_sync_001 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_OpenSync_0200
* @tc.name fileio_test_open_sync_002
* @tc.desc Function of API, openSync(flags=0o201). The test file is exist.
*/
it('fileio_test_open_sync_002', 0, function () {
let fpath = nextFileName('fileio_test_open_sync_002')
prepareFile(fpath, FILE_CONTENT)
try {
let fd = fileio.openSync(fpath, 0o201)
expect(fd !== null).assertTrue()
expect(fileio.closeSync(fd) !== null).assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_open_sync_002 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_OpenSync_0300
* @tc.name fileio_test_open_sync_003
* @tc.desc Function of API, openSync(flags=0o202). The test file is exist.
*/
it('fileio_test_open_sync_003', 0, function () {
let fpath = nextFileName('fileio_test_open_sync_003')
prepareFile(fpath, FILE_CONTENT)
try {
let fd = fileio.openSync(fpath, 0o202)
expect(fd !== null).assertTrue()
expect(fileio.closeSync(fd) !== null).assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_open_sync_003 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_OpenSync_0400
* @tc.name fileio_test_open_sync_004
* @tc.desc Function of API, openSync(flags=0o102, mode=0o777). The test file is not exist.
*/
it('fileio_test_open_sync_004', 0, function () {
let fpath = nextFileName('fileio_test_open_sync_004')
try {
let fd = fileio.openSync(fpath, 0o102, 0o777)
expect(fd !== null).assertTrue()
expect(fileio.closeSync(fd) !== null).assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_open_sync_004 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_OpenSync_0500
* @tc.name fileio_test_open_sync_005
* @tc.desc Function of API, openSync(flags not for value, mode not for value).
*/
it('fileio_test_open_sync_005', 0, function () {
let dpath = nextFileName('fileio_test_open_sync_005') + 'd'
try {
expect(fileio.mkdirSync(dpath) !== null).assertTrue()
let fd = fileio.openSync(dpath)
expect(fd !== null).assertTrue()
expect(fileio.closeSync(fd) !== null).assertTrue()
expect(fileio.rmdirSync(dpath) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_open_sync_005 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_OpenSync_0600
* @tc.name fileio_test_open_sync_006
* @tc.desc Function of API, openSync(flags=0o1, illegal parameter).
*/
it('fileio_test_open_sync_006', 0, function () {
let dpath = nextFileName('fileio_test_open_sync_006') + 'd'
try {
expect(fileio.mkdirSync(dpath) !== null).assertTrue()
fileio.openSync(dpath, 0o1)
expect(null).assertFail()
} catch (e) {
console.log("fileio_test_open_sync_006 has failed for " + e)
fileio.rmdirSync(dpath)
}
})
/**
* @tc.number SUB_STORAGE_FileIO_OpenSync_0700
* @tc.name fileio_test_open_sync_007
* @tc.desc Function of API, openSync(fpath too long).
*/
it('fileio_test_open_sync_007', 0, function () {
let dpath = nextFileName("fileio_open1")
fileio.mkdirSync(dpath)
try {
for (let i = 0; i < 16; i++) {
if (i == 15) {
let fpath = dpath + "/f" + randomString(248)
fileio.openSync(fpath, 0o102, 0o777)
} else {
dpath = dpath + "/d" + randomString(248)
fileio.mkdirSync(dpath)
}
}
expect(null).assertFail()
} catch (e) {
console.log("fileio_test_open_sync_007 has failed for " + e)
}
})
/**
* @tc.number SUB_STORAGE_FileIO_OpenSync_0800
* @tc.name fileio_test_open_sync_008
* @tc.desc Function of API, openSync(filename too long).
*/
it('fileio_test_open_sync_008', 0, function () {
let fpath = nextFileName(randomString(256))
try {
fileio.openSync(fpath, 0o102, 0o777)
expect(null).assertFail()
} catch (e) {
console.log("fileio_test_open_sync_008 has failed for " + e)
}
})
/**
* @tc.number SUB_STORAGE_FileIO_OpenSync_0900
* @tc.name fileio_test_open_sync_009
* @tc.desc Function of API, openSync(dir layers too long).
*/
it('fileio_test_open_sync_009', 0, function () {
let dpath = nextFileName("prop1")
fileio.mkdirSync(dpath)
try {
for (let i = 0; i < 113; i++) {
if (i == 112) {
let fpath = dpath + "/f" + i
fileio.openSync(fpath, 0o102, 0o777)
} else {
dpath = dpath + "/" + i
fileio.mkdirSync(dpath)
}
}
expect(null).assertFail()
} catch (e) {
console.log("fileio_test_open_sync_009 has failed for " + e)
}
})
/**
* @tc.number SUB_STORAGE_FileIO_OpenSync_1000
* @tc.name fileio_test_open_sync_010
* @tc.desc Function of API, openSync(filename has special characters).
*/
it('fileio_test_open_sync_010', 0, function () {
let fpath = nextFileName("?*:<>/|")
try {
fileio.openSync(fpath, 0o102, 0o777)
expect(null).assertFail()
} catch (e) {
console.log("fileio_test_open_sync_010 has failed for " + e)
}
})
/**
* @tc.number SUB_STORAGE_FileIO_CloseSync_0000
* @tc.name fileio_test_close_sync_000
* @tc.desc Function of API, close. The test file is not exist.
*/
it('fileio_test_close_sync_000', 0, function () {
let fpath = nextFileName('fileio_test_chmod_sync_000')
try {
fileio.closeSync(fpath)
expect(null).assertFail()
} catch (e) {
console.log("fileio_test_close_sync_000 has failed for " + e)
}
})
/**
* @tc.number SUB_STORAGE_FileIO_CloseSync_0100
* @tc.name fileio_test_close_sync_001
* @tc.desc Function of API, close(fpath=vaild value). The test file is not exist.
*/
it('fileio_test_close_sync_001', 0, function () {
try {
fileio.closeSync(-1)
expect(null).assertFail()
} catch (e) {
console.log("fileio_test_close_sync_001 has failed for " + e)
}
})
/**
* @tc.number SUB_STORAGE_FileIO_AccessSync_0000
* @tc.name fileio_test_access_sync_000
* @tc.desc Function of API,access. The test file is exist.
*/
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) !== null).assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_access_sync_000 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_AccessSync_0100
* @tc.name fileio_test_access_sync_001
* @tc.desc Function of API, launch via fileio. The test file is not exist.
*/
it('fileio_test_access_sync_001', 0, function () {
try {
fileio.accessSync(1)
expect(null).assertFail()
} catch (e) {
console.log("fileio_test_access_sync_001 has failed for " + e)
}
})
/**
* @tc.number SUB_STORAGE_FileIO_AccessSync_0200
* @tc.name fileio_test_access_sync_002
* @tc.desc Function of API, access. The test file is not exist.
*/
it('fileio_test_access_sync_002', 0, function () {
let fpath = nextFileName('fileIOTest')
try {
fileio.accessSync(fpath)
expect(null).assertFail()
} catch (e) {
console.log("fileio_test_access_sync_002 has failed for " + e)
}
})
/**
* @tc.number SUB_STORAGE_FileIO_AccessSync_0300
* @tc.name fileio_test_access_sync_003
* @tc.desc Function of API, access(mode=1). The test file is exist and have the authority.
*/
it('fileio_test_access_sync_003', 0, function () {
let fpath = nextFileName('fileio_test_access_sync_004')
expect(prepareEmptyFile(fpath)).assertTrue()
try {
let fd = fileio.accessSync(fpath)
console.log(fd)
expect(fileio.accessSync(fpath, 1) !== null).assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_access_sync_004 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_AccessSync_0400
* @tc.name fileio_test_access_sync_004
* @tc.desc Function of API, access(mode=2). The test file is exist and have the authority.
*/
it('fileio_test_access_sync_004', 0, function () {
let fpath = nextFileName('fileio_test_access_sync_004')
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue()
try {
let fd = fileio.accessSync(fpath)
expect(fd !== null).assertTrue()
expect(fileio.accessSync(fpath, 2) !== null).assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_access_sync_004 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_AccessSync_0500
* @tc.name fileio_test_access_sync_005
* @tc.desc Function of API, access(fpath=dir address). The test dir is exist.
*/
it('fileio_test_access_sync_005', 0, function () {
let dpath = nextFileName('fileio_test_access_sync_005') + 'd'
try {
expect(fileio.mkdirSync(dpath) !== null).assertTrue()
let fd = fileio.accessSync(dpath)
expect(fd == undefined).assertTrue()
expect(fileio.rmdirSync(dpath) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_access_sync_005 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_AccessSync_0600
* @tc.name fileio_test_access_sync_006
* @tc.desc Function of API, access(fpath=dir address). The test dir is not exist.
*/
it('fileio_test_access_sync_006', 0, function () {
let dpath = nextFileName('fileio_test_access_sync_006') + 'd'
try {
fileio.accessSync(dpath)
expect(null).assertFail()
} catch (e) {
console.log("fileio_test_access_sync_006 has failed for " + e)
}
})
/**
* @tc.number SUB_STORAGE_FileIO_UnlinkSync_0000
* @tc.name fileio_test_unlink_sync_000
* @tc.desc Function of API,unlinkSync. The test file is exist.
*/
it('fileio_test_unlink_sync_000', 0, function () {
let fpath = nextFileName('fileio_test_unlink_sync_000')
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue()
try {
expect(fileio.unlinkSync(fpath) !== null)
} catch (e) {
console.log("fileio_test_unlink_sync_000 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_UnlinkSync_0100
* @tc.name fileio_test_unlink_sync_001
* @tc.desc Function of API, no parameter.
*/
it('fileio_test_unlink_sync_001', 0, function () {
try {
fileio.unlinkSync(1)
expect(null).assertFail()
} catch (e) {
console.log("fileio_test_unlink_sync_002 has failed for " + e)
}
})
/**
* @tc.number SUB_STORAGE_FileIO_UnlinkSync_0200
* @tc.name fileio_test_unlink_sync_002
* @tc.desc Function of API, invaild parameter
*/
it('fileio_test_unlink_sync_002', 0, function () {
let fpath = nextFileName('fileIOTest')
try {
fileio.unlinkSync(fpath)
expect(null).assertFail()
} catch (e) {
console.log("fileio_test_unlink_sync_003 has failed for " + e)
}
})
/**
* @tc.number SUB_STORAGE_FileIO_WriteSync_0000
* @tc.name fileio_test_write_sync_000
* @tc.desc Function of API, writeSync.
*/
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(fileio.writeSync(fd, FILE_CONTENT) !== null).assertTrue()
expect(fileio.closeSync(fd) !== null).assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_write_sync_000 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_WriteSync_0100
* @tc.name fileio_test_write_sync_001
* @tc.desc Function of API, encoding=UTF-8.
*/
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(fileio.writeSync(fd, FILE_CONTENT, {
encoding: "utf-8",
}) !== null).assertTrue()
expect(fileio.closeSync(fd) !== null).assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_write_sync_001 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_WriteSync_0200
* @tc.name fileio_test_write_sync_002
* @tc.desc Function of API, offset=1.
*/
it('fileio_test_write_sync_002', 0, function () {
let fpath = nextFileName('fileio_test_write_sync_002')
let text = "0123456789abcdefg";
try {
let fd = fileio.openSync(fpath, 0o102, 0o666)
expect(fileio.writeSync(fd, text, {
offset: 1,
}) == text.length - 1).assertTrue()
expect(fileio.closeSync(fd) !== null).assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_write_sync_002 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_WriteSync_0300
* @tc.name fileio_test_write_sync_003
* @tc.desc Function of API, length = - 1.
*/
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(fileio.writeSync(fd, FILE_CONTENT, {
length: FILE_CONTENT.length - 1,
}) == (FILE_CONTENT.length - 1)).assertTrue()
expect(fileio.closeSync(fd) !== null).assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_write_sync_003 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_WriteSync_0400
* @tc.name fileio_test_write_sync_004
* @tc.desc Function of API, length = 1, offset = 1.
*/
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(fileio.writeSync(fd, FILE_CONTENT, {
offset: 1,
length: 1,
}) !== null).assertTrue()
expect(fileio.closeSync(fd) !== null).assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_write_sync_004 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_WriteSync_0500
* @tc.name fileio_test_write_sync_005
* @tc.desc Function of API, invaild offset.
*/
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,
}) == 1).assertTrue()
expect(null).assertFail()
} catch (e) {
expect(fileio.closeSync(fd) !== null).assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_WriteSync_0600
* @tc.name fileio_test_write_sync_006
* @tc.desc Function of API, invaild length.
*/
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,
}) == 1)
expect(null).assertFail()
} catch (e) {
expect(fileio.closeSync(fd) !== null).assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_WriteSync_0700
* @tc.name fileio_test_write_sync_007
* @tc.desc Function of API, no parameter.
*/
it('fileio_test_write_sync_007', 0, function () {
try {
fileio.writeSync(1, 1)
expect(null).assertFail()
} catch (e) {
console.log("fileio_test_write_sync_007 has failed for " + e)
}
})
/**
* @tc.number SUB_STORAGE_FileIO_WriteSync_0800
* @tc.name fileio_test_write_sync_008
* @tc.desc Function of API, invaild parameter.
*/
it('fileio_test_write_sync_008', 0, function () {
try {
console.log(fileio.writeSync(-1, FILE_CONTENT))
expect(null).assertFail()
} catch (e) {
console.log("fileio_test_write_sync_008 has failed for " + e)
}
})
/**
* @tc.number SUB_STORAGE_FileIO_ReadSync_0000
* @tc.name fileio_test_read_sync_000
* @tc.desc Function of API, readSync.
*/
it('fileio_test_read_sync_000', 0, function () {
let fpath = nextFileName('fileio_test_read_sync_000')
let text = "0123456789abcdefg";
expect(prepareFile(fpath, text)).assertTrue()
try {
let fd = fileio.openSync(fpath, 0o2)
let len = fileio.readSync(fd, new ArrayBuffer(4096))
expect(len == text.length).assertTrue()
expect(fileio.closeSync(fd) !== null).assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_read_sync_000 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_ReadSync_0100
* @tc.name fileio_test_read_sync_001
* @tc.desc Function of API, offset = 1.
*/
it('fileio_test_read_sync_001', 0, function () {
let bufLen = 5
expect(FILE_CONTENT.length > bufLen).assertTrue()
let fpath = nextFileName('fileio_test_read_sync_001')
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue()
try {
let fd = fileio.openSync(fpath, 0o2)
let len = fileio.readSync(fd, new ArrayBuffer(bufLen), {
offset: 1,
})
expect(len == bufLen - 1).assertTrue()
expect(fileio.closeSync(fd) !== null).assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_read_sync_001 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_ReadSync_0200
* @tc.name fileio_test_read_sync_002
* @tc.desc Function of API, length = 1.
*/
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)
let len = fileio.readSync(fd, new ArrayBuffer(4096), {
length: 1,
})
expect(len == 1).assertTrue()
expect(fileio.closeSync(fd) !== null).assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_read_sync_002 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_ReadSync_0300
* @tc.name fileio_test_read_sync_003
* @tc.desc Function of API, invaild offset
*/
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)
fileio.readSync(fd, new ArrayBuffer(4096), {
offset: invalidOffset,
})
expect(null).assertFail()
} catch (e) {
expect(fileio.closeSync(fd) !== null).assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
console.log("fileio_test_read_sync_003 has failed for " + e)
}
})
/**
* @tc.number SUB_STORAGE_FileIO_ReadSync_0300
* @tc.name fileio_test_read_sync_004
* @tc.desc Function of API, invaild length.
*/
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)
fileio.readSync(fd, new ArrayBuffer(4096), {
length: invalidLength,
})
expect(null).assertFail()
} catch (e) {
expect(fileio.closeSync(fd) !== null).assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
console.log("fileio_test_read_sync_004 has failed for " + e)
}
})
/**
* @tc.number SUB_STORAGE_FileIO_ReadSync_0500
* @tc.name fileio_test_read_sync_005
* @tc.desc Function of API, fpatch = -1.
*/
it('fileio_test_read_sync_005', 0, function () {
try {
fileio.readSync(-1, new ArrayBuffer(4096))
expect(null).assertFail()
} catch (e) {
console.log("fileio_test_read_sync_005 has failed for " + e)
}
})
/**
* @tc.number SUB_STORAGE_FileIO_ReadSync_0600
* @tc.name fileio_test_read_sync_006
* @tc.desc Function of API, offset & length & position = 1.
*/
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)
let len = fileio.readSync(fd, new ArrayBuffer(4096), {
position: 1,
})
expect(len == FILE_CONTENT.length - 1)
expect(fileio.closeSync(fd) !== null).assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_read_sync_006 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_ReadSync_0700
* @tc.name fileio_test_read_sync_007
* @tc.desc Function of API, invaild position.
*/
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)
let invalidPos = FILE_CONTENT.length
let len = fileio.readSync(fd, new ArrayBuffer(4096), {
position: invalidPos,
})
expect(fileio.closeSync(fd) !== null).assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_read_sync_007 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_ChmodSync_0000
* @tc.name fileio_test_chmod_sync_000
* @tc.desc Function of API, mode=0o660
*/
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) !== null).assertTrue()
expect((fileio.statSync(fpath).mode & 0o777) == 0o660).assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_chmod_sync_000 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_ChmodSync_0100
* @tc.name fileio_test_chmod_sync_001
* @tc.desc Function of API, mode=0o460
*/
it('fileio_test_chmod_sync_001', 0, function () {
let fpath = nextFileName('fileio_test_chmod_sync_001')
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue()
try {
expect(fileio.chmodSync(fpath, 0o460) !== null).assertTrue()
expect((fileio.statSync(fpath).mode & 0o777) == 0o460).assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_chmod_sync_001 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_ChmodSync_0200
* @tc.name fileio_test_chmod_sync_002
* @tc.desc Function of API, mode=0o260. The test file is exist.
*/
it('fileio_test_chmod_sync_002', 0, function () {
let fpath = nextFileName('fileio_test_chmod_sync_002')
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue()
try {
expect(fileio.chmodSync(fpath, 0o260) !== null).assertTrue()
expect((fileio.statSync(fpath).mode & 0o777) == 0o260).assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_chmod_sync_002 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_ChmodSync_0300
* @tc.name fileio_test_chmod_sync_003
* @tc.desc Function of API, chmodSync. The test file is not exist.
*/
it('fileio_test_chmod_sync_003', 0, function () {
let fpath = nextFileName('fileio_test_chmod_sync_003')
try {
fileio.chmodSync(fpath, 0o260)
expect(null).assertFail()
} catch (e) {
console.log("fileio_test_chmod_sync_003 has failed for " + e)
}
})
/**
* @tc.number SUB_STORAGE_FileIO_ChmodSync_0400
* @tc.name fileio_test_chmod_sync_004
* @tc.desc Function of API, fpatch=dir address. The test dir is exist.
*/
it('fileio_test_chmod_sync_004', 0, function () {
let dpath = nextFileName('fileio_test_chmod_sync_004')
try {
expect(fileio.mkdirSync(dpath, 0o777) !== null).assertTrue()
expect(fileio.chmodSync(dpath, 0o660) !== null).assertTrue()
expect((fileio.statSync(dpath).mode & 0o777) == 0o660).assertTrue()
expect(fileio.rmdirSync(dpath) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_chmod_sync_000 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_ChmodSync_0500
* @tc.name fileio_test_chmod_sync_005
* @tc.desc Function of API, fpatch=dir address. The test dir is not exist.
*/
it('fileio_test_chmod_sync_005', 0, function () {
let dpath;
try {
fileio.chmodSync(dpath, 0o660)
expect(null).assertFail()
} catch (e) {
console.log("fileio_test_chmod_sync_005 has failed for " + e)
}
})
/**
* @tc.number SUB_STORAGE_FileIO_copyFileSync_0000
* @tc.name fileio_test_copy_file_sync_000
* @tc.desc Function of API, copy. fpatch is vaild, fpathTarget is vaild, same path, file not same.
*/
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) !== null).assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
expect(fileio.unlinkSync(fpathTarget) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_copy_file_sync_000 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_copyFileSync_0100
* @tc.name fileio_test_copy_file_sync_001
* @tc.desc Function of API, copy. fpatch is invaild, fpathTarget is vaild, same path, file not same.
*/
it('fileio_test_copy_file_sync_001', 0, function () {
let fpath = nextFileName('fileio_test_copy_file_sync_001') + 'd'
let fpathTarget = fpath + 'tgt'
try {
fileio.copyFileSync(fpath, fpathTarget)
expect(null).assertFail()
} catch (e) {
console.log("fileio_test_copy_file_sync_001 has failed for " + e);
}
})
/**
* @tc.number SUB_STORAGE_FileIO_copyFileSync_0200
* @tc.name fileio_test_copy_file_sync_002
* @tc.desc Function of API, copy. fpatch is vaild, fpathTarget is invaild.
*/
it('fileio_test_copy_file_sync_002', 0, function () {
let fpath = nextFileName('fileio_test_copy_file_sync_002')
try {
fileio.copyFileSync(fpath, 0)
expect(null).assertFail()
} catch (e) {
console.log("fileio_test_copy_file_sync_002 has failed for " + e);
}
})
/**
* @tc.number SUB_STORAGE_FileIO_copyFileSync_0300
* @tc.name fileio_test_copy_file_sync_003
* @tc.desc Function of API, copy. fpatch is vaild, fpathTarget is vaild, path not same, file not same.
*/
it('fileio_test_copy_file_sync_003', 0, function () {
let fpath = nextFileName('fileio_test_copy_file_sync_003')
let fpathTarget = fpath + 'f1'
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue()
try {
expect(fileio.copyFileSync(fpath, fpathTarget) !== null).assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
expect(fileio.unlinkSync(fpathTarget) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_copy_file_sync_003 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_copyFileSync_0400
* @tc.name fileio_test_copy_file_sync_004
* @tc.desc Function of API, copy. fpatch is vaild, fpathTarget is vaild, path not same, file not same.
*/
it('fileio_test_copy_file_sync_004', 0, function () {
let fpath = nextFileName('fileio_test_copy_file_sync_004')
let fpathTarget = fileName('fileio_test_copy_file_sync_004')
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue()
try {
expect(fileio.copyFileSync(fpath, fpathTarget) !== null).assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
expect(fileio.unlinkSync(fpathTarget) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_copy_file_sync_004 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_copyFileSync_0500
* @tc.name fileio_test_copy_file_sync_005
* @tc.desc Function of API, copy. fpatch is vaild, fpathTarget is vaild, path not same, file not same.
*/
it('fileio_test_copy_file_sync_005', 0, function () {
let fpath = nextFileName('fileio_test_copy_file_sync_005')
let fpathTarget = fpath
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue()
try {
expect(fileio.copyFileSync(fpath, fpathTarget) !== null).assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue();
} catch (e) {
console.log("fileio_test_copy_file_sync_005 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_copyFileSync_0600
* @tc.name fileio_test_copy_file_sync_006
* @tc.desc Function of API, copy. fpathTarget is invaild.
*/
it('fileio_test_copy_file_sync_006', 0, function () {
let fpath = nextFileName('fileio_test_copy_file_sync_006')
let fpathTarget = fpath + 'tgt'
try {
fileio.copyFileSync(fpath, fpathTarget)
expect(null).assertFail()
} catch (e) {
console.log("fileio_test_copy_file_sync_006 has failed for " + e)
}
})
/**
* @tc.number SUB_STORAGE_FileIO_copyFileSync_0700
* @tc.name fileio_test_copy_file_sync_007
* @tc.desc Function of API, copy. fpatch is invaild, fpathTarget is invaild.
*/
it('fileio_test_copy_file_sync_007', 0, function () {
try {
fileio.copyFileSync(1, 1)
expect(null).assertFail()
} catch (e) {
console.log("fileio_test_copy_file_sync_007 has failed for " + e)
}
})
/**
* @tc.number SUB_STORAGE_FileIO_copyFileSync_0800
* @tc.name fileio_test_copy_file_sync_008
* @tc.desc Function of API, parameter more than 4096.
*/
it('fileio_test_copy_file_sync_008', 0, function () {
let fpath = nextFileName("fileio_test_copy_file_sync_008")
fileio.openSync(fpath, 0o102, 0o777)
let dpath = nextFileName("fileio_copy1")
fileio.mkdirSync(dpath)
try {
for (let i = 0; i < 16; i++) {
if (i == 15) {
let fpathTarget = dpath + "/f" + randomString(248)
fileio.copyFileSync(fpath, fpathTarget)
} else {
dpath = dpath + "/d" + randomString(248)
fileio.mkdirSync(dpath)
}
}
expect(null).assertFail()
} catch (e) {
console.log("fileio_test_copy_file_sync_008 has failed for " + e)
}
})
/**
* @tc.number SUB_STORAGE_FileIO_copyFileSync_0900
* @tc.name fileio_test_copy_file_sync_009
* @tc.desc Function of API, filename is too long.
*/
it('fileio_test_copy_file_sync_009', 0, function () {
let fpath = nextFileName("fileio_test_copy_file_sync_009")
fileio.openSync(fpath, 0o102, 0o777)
let fpathTarget = nextFileName(randomString(256))
try {
fileio.copyFileSync(fpath, fpathTarget)
expect(null).assertFail()
} catch (e) {
fileio.unlinkSync(fpath)
console.log("fileio_test_open_sync_008 has failed for " + e)
}
})
/**
* @tc.number SUB_STORAGE_FileIO_OpenSync_1000
* @tc.name fileio_test_open_sync_010
* @tc.desc Function of API, dir layers too long
*/
it('fileio_test_open_sync_010', 0, function () {
let fpath = nextFileName("fileio_test_open_sync_010")
fileio.openSync(fpath, 0o102, 0o777)
let dpath = nextFileName("prop")
fileio.mkdirSync(dpath)
try {
for (let i = 0; i < 113; i++) {
if (i == 112) {
let fpathTarget = dpath + "/f" + i
fileio.copyFileSync(fpath, fpathTarget)
} else {
dpath = dpath + "/" + i
fileio.mkdirSync(dpath)
}
}
expect(null).assertFail()
} catch (e) {
fileio.unlinkSync(fpath)
console.log("fileio_test_open_sync_010 has failed for " + e)
}
})
/**
* @tc.number SUB_STORAGE_FileIO_OpenSync_1100
* @tc.name fileio_test_open_sync_011
* @tc.desc Function of API, special parameter.
*/
it('fileio_test_open_sync_011', 0, function () {
let fpath = nextFileName("fileio_test_open_sync_011")
fileio.openSync(fpath, 0o102, 0o777)
let fpathTarget = nextFileName("?*:<>/|")
try {
fileio.copyFileSync(fpath, fpathTarget)
expect(null).assertFail()
} catch (e) {
fileio.unlinkSync(fpath)
console.log("fileio_test_open_sync_011 has failed for " + e)
}
})
/**
* @tc.number SUB_STORAGE_FileIO_truncateSync_0000
* @tc.name fileio_test_truncate_sync_000
* @tc.desc Function of API, truncateSync.
*/
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) !== null).assertTrue()
expect(fileio.statSync(fpath).size == 0).assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_truncate_sync_000 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_truncateSync_0100
* @tc.name fileio_test_truncate_sync_001
* @tc.desc Function of API, no value for parameter.
*/
it('fileio_test_truncate_sync_001', 0, function () {
try {
fileio.truncateSync()
expect(null).assertFail()
} catch (e) {
console.log("fileio_test_truncate_sync_001 has failed for " + e)
}
})
/**
* @tc.number SUB_STORAGE_FileIO_truncateSync_0200
* @tc.name fileio_test_truncate_sync_002
* @tc.desc Function of API, no invaild parameter.
*/
it('fileio_test_truncate_sync_002', 0, function () {
let fpath = nextFileName('fileio_test_truncate_sync_001')
try {
fileio.truncateSync(fpath)
expect(null).assertFail()
} catch (e) {
console.log("fileio_test_truncate_sync_002 has failed for " + e)
}
})
/**
* @tc.number SUB_STORAGE_FileIO_RenameSync_0000
* @tc.name fileio_test_rename_sync_000
* @tc.desc Function of API, renameSync. The test file is exist, fpathTarget is not same with fpatch, file name are same.
*/
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) !== null).assertTrue()
expect(fileio.accessSync(fpathTarget) !== null).assertTrue()
expect(fileio.unlinkSync(fpathTarget) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_rename_sync_000 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_RenameSync_0100
* @tc.name fileio_test_rename_sync_001
* @tc.desc Function of API, renameSync. The test file is not exist, fpathTarget is not same with fpatch, file name are same.
*/
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) {
console.log("fileio_test_rename_sync_001 has failed for " + e)
}
})
/**
* @tc.number SUB_STORAGE_FileIO_RenameSync_0200
* @tc.name fileio_test_rename_sync_002
* @tc.desc Function of API, renameSync. The test file is exist, fpathTarget is invaild.
*/
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, "/")
expect(null).assertFail()
} catch (e) {
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
console.log("fileio_test_rename_sync_002 has failed for " + e)
}
})
/**
* @tc.number SUB_STORAGE_FileIO_RenameSync_0300
* @tc.name fileio_test_rename_sync_003
* @tc.desc Function of API, renameSync. The test file is not exist, fpathTarget is same with fpatch, file name are same.
*/
it('fileio_test_rename_sync_003', 0, function () {
let fpath = nextFileName('fileio_test_rename_sync_003')
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue()
try {
console.log("fileio_test_rename_sync_003 Test start");
fileio.renameSync(fpath, fpath)
expect(null).assertFail()
} catch (e) {
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
console.log("fileio_test_rename_sync_003 Test finish. " + e);
}
})
/**
* @tc.number SUB_STORAGE_FileIO_RenameSync_0400
* @tc.name fileio_test_rename_sync_004
* @tc.desc Function of API, no fpath parameter.
*/
it('fileio_test_rename_sync_004', 0, function () {
try {
fileio.renameSync(1, 1)
expect(null).assertNull()
} catch (e) {
console.log("fileio_test_rename_sync_004 pass. " + e);
}
})
/**
* @tc.number SUB_STORAGE_FileIO_RenameSync_0500
* @tc.name fileio_test_rename_sync_005
* @tc.desc Function of API, no fpathTarget parameter.
*/
it('fileio_test_rename_sync_005', 0, function () {
let fpath = nextFileName('fileio_test_rename_sync_005')
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue()
try {
fileio.renameSync(fpath, 1)
expect(null).assertFail()
} catch (e) {
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
console.log("fileio_test_rename_sync_005 pass. " + e);
}
})
/**
* @tc.number SUB_STORAGE_FileIO_RenameSync_0600
* @tc.name fileio_test_rename_sync_006
* @tc.desc Function of API, rename dir.
*/
it('fileio_test_rename_sync_006', 0, function () {
let dpath = nextFileName('fileio_test_rename_sync_006') + 'd'
let dpathTarget = nextFileName('fileio_test_rename_sync_006-1') + 'd'
try {
expect(fileio.mkdirSync(dpath) !== null).assertTrue()
expect(fileio.renameSync(dpath, dpathTarget) == undefined).assertTrue()
expect(fileio.accessSync(dpathTarget) !== null).assertTrue()
expect(fileio.rmdirSync(dpathTarget) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_rename_sync_006 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_RenameSync_0700
* @tc.name fileio_test_rename_sync_007
* @tc.desc Function of API, dir not exist. The test dir is not exist.
*/
it('fileio_test_rename_sync_007', 0, function () {
let dpath = nextFileName('fileio_test_rename_sync_007') + 'd'
let dpathTarget = nextFileName('fileio_test_rename_sync_007-1') + 'd'
try {
fileio.renameSync(dpath, dpathTarget)
expect(null).assertFail()
} catch (e) {
console.log("fileio_test_rename_sync_007 has failed for " + e)
}
})
/**
* @tc.number SUB_STORAGE_FileIO_RenameSync_0800
* @tc.name fileio_test_rename_sync_008
* @tc.desc Function of API, fpathTarget not exist. fpathTarget not exist.
*/
it('fileio_test_rename_sync_008', 0, function () {
let dpath = nextFileName('fileio_test_rename_sync_008') + 'd'
let dpathTarget = '/data/accounts/account_0/appdata/aaa/bbb/fileio_test_rename_sync_008-1d'
try {
expect(fileio.mkdirSync(dpath) !== null).assertTrue()
fileio.renameSync(dpath, dpathTarget)
expect(null).assertFail()
} catch (e) {
expect(fileio.rmdirSync(dpath) !== null).assertTrue()
console.log("fileio_test_rename_sync_008 has failed for " + e)
}
})
/**
* @tc.number SUB_STORAGE_FileIO_RenameSync_0900
* @tc.name fileio_test_rename_sync_009
* @tc.desc Function of API, fpath is same with fpathTarget. fpath is same with fpathTarget.
*/
it('fileio_test_rename_sync_009', 0, function () {
let dpath = nextFileName('fileio_test_rename_sync_009') + 'd'
try {
expect(fileio.mkdirSync(dpath) !== null).assertTrue()
let result = fileio.renameSync(dpath, dpath);
expect(result === undefined).assertTrue()
expect(fileio.accessSync(dpath) !== null).assertTrue()
expect(fileio.rmdirSync(dpath) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_rename_sync_009 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_FchmodSync_0000
* @tc.name fileio_test_fchmod_sync_000
* @tc.desc Function of API, fchmodSync(mode=0o660). The test file is exist.
*/
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)
expect(fileio.fchmodSync(fd, 0o660) !== null).assertTrue()
expect((fileio.statSync(fpath).mode & 0o777) == 0o660).assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_fchmod_sync_000 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_FchmodSync_0100
* @tc.name fileio_test_fchmod_sync_001
* @tc.desc Function of API, fchmodSync(mode=0o460). The test file is exist.
*/
it('fileio_test_fchmod_sync_001', 0, function () {
let fpath = nextFileName('fileio_test_fchmod_sync_001')
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue()
try {
let fd = fileio.openSync(fpath)
expect(fileio.fchmodSync(fd, 0o460) !== null).assertTrue()
expect((fileio.statSync(fpath).mode & 0o777) == 0o460).assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_fchmod_sync_001 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_FchmodSync_0200
* @tc.name fileio_test_fchmod_sync_002
* @tc.desc Function of API, fchmodSync(mode=0o260). The test file is exist.
*/
it('fileio_test_fchmod_sync_002', 0, function () {
let fpath = nextFileName('fileio_test_fchmod_sync_002')
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue()
try {
let fd = fileio.openSync(fpath)
expect(fileio.fchmodSync(fd, 0o260) !== null).assertTrue()
expect((fileio.statSync(fpath).mode & 0o777) == 0o260).assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_fchmod_sync_002 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_FchmodSync_0300
* @tc.name fileio_test_fchmod_sync_003
* @tc.desc Function of API, file not exist. The test file is not exist.
*/
it('fileio_test_fchmod_sync_003', 0, function () {
try {
expect(fileio.fchmodSync(-1, 0o660) !== null).assertTrue()
expect(null).assertFail()
} catch (e) {
console.log("fileio_test_fchmod_sync_003 has failed for " + e)
}
})
/**
* @tc.number SUB_STORAGE_FileIO_FchmodSync_0400
* @tc.name fileio_test_fchmod_sync_004
* @tc.desc Function of API, mode is invaild. The test file is exist.
*/
it('fileio_test_fchmod_sync_004', 0, function () {
let fpath = nextFileName('fileio_test_fchmod_sync_004')
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue()
try {
let fd = fileio.openSync(fpath)
expect(fileio.fchmodSync(fd, 2222222222222) !== null).assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_fchmod_sync_004 has failed for A" + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_FchmodSync_0500
* @tc.name fileio_test_fchmod_sync_005
* @tc.desc Function of API, fpath = dir. The test dir is exist.
*/
it('fileio_test_fchmod_sync_005', 0, function () {
let dpath = nextFileName('fileio_test_fchmod_sync_005') + 'd'
try {
expect(fileio.mkdirSync(dpath, 0o777) !== null).assertTrue()
let fd = fileio.openSync(dpath)
console.log(fd);
expect(fileio.fchmodSync(fd, 0o660) !== null).assertTrue()
expect(fileio.rmdirSync(dpath) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_fchmod_sync_005 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_FchmodSync_0600
* @tc.name fileio_test_fchmod_sync_006
* @tc.desc Function of API, fpatch = dir. The test dir is not exist.
*/
it('fileio_test_fchmod_sync_006', 0, function () {
let dpath
try {
fileio.fchmodSync(dpath, 0o660)
expect(null).assertNull()
} catch (e) {
console.log("fileio_test_fchmod_sync_006 has failed for " + e)
}
})
/**
* @tc.number SUB_STORAGE_FileIO_FtruncateSync_0000
* @tc.name fileio_test_ftruncate_sync_000
* @tc.desc Function of API, ftruncateSync. The test file is exist.
*/
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) !== null).assertTrue()
expect(fileio.statSync(fpath).size == 0).assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_ftruncate_sync_000 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_FtruncateSync_0100
* @tc.name fileio_test_ftruncate_sync_001
* @tc.desc Function of API, len not for value. The test file is exist.
*/
it('fileio_test_ftruncate_sync_001', 0, function () {
let fpath = nextFileName('fileio_test_ftruncate_sync_001')
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue()
try {
let fd = fileio.openSync(fpath, 0o2)
expect(fileio.ftruncateSync(fd) !== null).assertTrue()
expect(fileio.closeSync(fd) !== null).assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_ftruncate_sync_001 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_FtruncateSync_0200
* @tc.name fileio_test_ftruncate_sync_002
* @tc.desc Function of API, invaild parameter. The test file is not exist.
*/
it('fileio_test_ftruncate_sync_002', 0, function () {
try {
fileio.ftruncateSync(1)
expect(null).assertFail()
} catch (e) {
console.log("fileio_test_ftruncate_sync_002 has failed for " + e)
}
})
/**
* @tc.number SUB_STORAGE_FileIO_FtruncateSync_0300
* @tc.name fileio_test_ftruncate_sync_003
* @tc.desc Function of API, invaild parameter. The test file is not exist.
*/
it('fileio_test_ftruncate_sync_003', 0, function () {
try {
fileio.ftruncateSync(-1)
expect(null).assertFail()
} catch (e) {
console.log("fileio_test_ftruncate_sync_003 has failed for " + e)
}
})
/**
* @tc.number SUB_STORAGE_FileIO_FsyncSync_0000
* @tc.name fileio_test_fsync_sync_000
* @tc.desc Function of API, fsyneSync.
*/
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) !== null).assertTrue()
expect(fileio.closeSync(fd) !== null).assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_fsync_sync_000 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_FsyncSync_0100
* @tc.name fileio_test_fsync_sync_001
* @tc.desc Function of API, no value of parameter.
*/
it('fileio_test_fsync_sync_001', 0, function () {
try {
fileio.fsyncSync(1)
expect(null).assertFail()
} catch (e) {
console.log("fileio_test_fsync_sync_001 has failed for " + e)
}
})
/**
* @tc.number SUB_STORAGE_FileIO_FsyncSync_0200
* @tc.name fileio_test_fsync_sync_002
* @tc.desc Function of API, invaild parameter.
*/
it('fileio_test_fsync_sync_002', 0, function () {
try {
fileio.fsyncSync(-1)
expect(null).assertFail()
} catch (e) {
console.log("fileio_test_fsync_sync_002 has failed for " + e)
}
})
/**
* @tc.number SUB_STORAGE_FileIO_MkdirSync_RmdirSync_0000
* @tc.name fileio_test_mkdir_sync_rmdir_sync_000
* @tc.desc Sync to mkdir and rmdir.
*/
it('fileio_test_mkdir_sync_rmdir_sync_000', 0, function () {
let dpath = nextFileName('fileio_test_fsync_sync_000') + 'd'
try {
expect(fileio.mkdirSync(dpath) !== null).assertTrue()
expect(fileio.rmdirSync(dpath) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_mkdir_sync_rmdir_sync_000 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_MkdirSync_RmdirSync_0100
* @tc.name fileio_test_mkdir_sync_rmdir_sync_001
* @tc.desc Sync to mkdir and rmdir. mkdirSync(mode=0o660).
*/
it('fileio_test_mkdir_sync_rmdir_sync_001', 0, function () {
let dpath = nextFileName('fileio_test_mkdir_sync_rmdir_sync_001') + 'd'
try {
expect(fileio.mkdirSync(dpath, 0o660) !== null).assertTrue()
expect(fileio.rmdirSync(dpath) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_mkdir_sync_rmdir_sync_001 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_MkdirSync_RmdirSync_0200
* @tc.name fileio_test_mkdir_sync_rmdir_sync_002
* @tc.desc Sync to mkdir and rmdir. mkdirSync(mode=0o460).
*/
it('fileio_test_mkdir_sync_rmdir_sync_002', 0, function () {
let dpath = nextFileName('fileio_test_mkdir_sync_rmdir_sync_002') + 'd'
try {
expect(fileio.mkdirSync(dpath, 0o460) !== null).assertTrue()
expect(fileio.rmdirSync(dpath) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_mkdir_sync_rmdir_sync_002 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_MkdirSync_RmdirSync_0300
* @tc.name fileio_test_mkdir_sync_rmdir_sync_003
* @tc.desc Sync to mkdir and rmdir. mkdirSync(mode=0o260).
*/
it('fileio_test_mkdir_sync_rmdir_sync_003', 0, function () {
let dpath = nextFileName('fileio_test_mkdir_sync_rmdir_sync_003') + 'd'
try {
expect(fileio.mkdirSync(dpath, 0o260) !== null).assertTrue()
expect(fileio.rmdirSync(dpath) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_mkdir_sync_rmdir_sync_003 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_MkdirSync_RmdirSync_0400
* @tc.name fileio_test_mkdir_sync_rmdir_sync_004
* @tc.desc Function of API, invaild parameter. The test file is not exist.
*/
it('fileio_test_mkdir_sync_rmdir_sync_004', 0, function () {
try {
expect(fileio.mkdirSync(1) !== null)
expect(null).assertFail()
} catch (e) {
console.log("fileio_test_fsync_sync_004 has failed for " + e)
}
})
/**
* @tc.number SUB_STORAGE_FileIO_MkdirSync_RmdirSync_0500
* @tc.name fileio_test_mkdir_sync_rmdir_sync_005
* @tc.desc Function of API, invaild parameter. The test file is not exist.
*/
it('fileio_test_mkdir_sync_rmdir_sync_005', 0, function () {
try {
expect(fileio.mkdirSync("/", 1) !== null).assertTrue()
expect(null).assertFail()
} catch (e) {
console.log("fileio_test_fsync_sync_005 has failed for " + e)
}
})
/**
* @tc.number SUB_STORAGE_FileIO_FstatSync_0000
* @tc.name fileio_test_fstat_sync_000
* @tc.desc Function of API, fstatSync. The test file is exist.
*/
it('fileio_test_fstat_sync_000', 0, function () {
let fpath = nextFileName('fileio_test_fstat_sync_000')
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue()
try {
let fd = fileio.openSync(fpath, 0o2)
let stat = fileio.fstatSync(fd)
expect(stat !== null).assertTrue()
expect(fileio.closeSync(fd) !== null).assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_fstat_sync_000 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_FstatSync_0100
* @tc.name fileio_test_fstat_sync_001
* @tc.desc Function of API, fstatSync, fd = -1. The test file is not exist.
*/
it('fileio_test_fstat_sync_001', 0, function () {
try {
expect(fileio.fstatSync(1) !== null).assertTrue()
expect(null).assertFail()
} catch (e) {
console.log("fileio_test_fstat_sync_001 has failed for " + e)
}
})
/**
* @tc.number SUB_STORAGE_FileIO_FstatSync_0200
* @tc.name fileio_test_fstat_sync_002
* @tc.desc Function of API, fstatSync, fd = 1. The test file is not exist.
*/
it('fileio_test_fstat_sync_002', 0, function () {
try {
expect(fileio.fstatSync(1) !== null).assertTrue()
expect(null).assertFail()
} catch (e) {
console.log("fileio_test_fstat_sync_002 has failed for " + e)
}
})
/**
* @tc.number SUB_STORAGE_FileIO_FstatSync_0300
* @tc.name fileio_test_fstat_sync_003
* @tc.desc Function of API, fstatSync, vaild fd. The test file is exist.
*/
it('fileio_test_fstat_sync_003', 0, function () {
let dpath = nextFileName('fileio_test_fstat_sync_003') + 'd'
try {
expect(fileio.mkdirSync(dpath) !== null).assertTrue()
let fd = fileio.openSync(dpath)
expect(fd !== null).assertTrue()
let stat = fileio.fstatSync(fd)
expect(stat !== null).assertTrue()
expect(fileio.closeSync(fd) !== null).assertTrue()
expect(fileio.rmdirSync(dpath) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_fstat_sync_003 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_ChownSync_0000
* @tc.name fileio_test_chown_sync_000
* @tc.desc Function of API, chownSync. The test file is exist.
*/
it('fileio_test_chown_sync_000', 0, function () {
let fpath = nextFileName('fileio_test_chown_sync_000')
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue()
let stat = fileio.statSync(fpath)
let UID = stat.uid
let GID = stat.gid
try {
expect(fileio.chownSync(fpath, UID, GID) !== null).assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_chown_sync_000 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_ChownSync_0100
* @tc.name fileio_test_chown_sync_001
* @tc.desc Function of API, chownSync. The test file is not exist.
*/
it('fileio_test_chown_sync_001', 0, function () {
let fpath = nextFileName('fileio_test_chown_sync_001')
let fpath_1 = nextFileName('fileio_test_chown_sync_001_1')
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue()
let stat = fileio.statSync(fpath)
let UID = stat.uid
let GID = stat.gid
try {
expect(fileio.chownSync(fpath_1, UID, GID))
expect(null).assertFail()
} catch (e) {
console.log("fileio_test_chown_sync_001 has failed for " + e)
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_ChownSync_0200
* @tc.name fileio_test_chown_sync_002
* @tc.desc Function of API, invaild fd. The test file is not exist.
*/
it('fileio_test_chown_sync_002', 0, function () {
let fpath = nextFileName('fileio_test_chown_sync_002')
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue()
try {
expect(fileio.chownSync(fpath, 0, 0))
expect(null).assertFail()
} catch (e) {
console.log("fileio_test_chown_sync_002 has failed for " + e)
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_FchownSync_0000
* @tc.name fileio_test_fchown_sync_000
* @tc.desc Function of API, fchownSync. The test file is exist.
*/
it('fileio_test_fchown_sync_000', 0, function () {
let fpath = nextFileName('fileio_test_fchown_sync_000')
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue()
let stat = fileio.statSync(fpath)
let UID = stat.uid
let GID = stat.gid
try {
let fd = fileio.openSync(fpath)
expect(fileio.fchownSync(fd, UID, GID) !== null).assertTrue()
expect(fileio.closeSync(fd) !== null).assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_fchown_sync_000 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_FchownSync_0100
* @tc.name fileio_test_fchown_sync_001
* @tc.desc Function of API, fchownSync. The test file is not exist.
*/
it('fileio_test_fchown_sync_001', 0, function () {
let fpath = nextFileName('fileio_test_fchown_sync_001')
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue()
let stat = fileio.statSync(fpath)
let UID = stat.uid
let GID = stat.gid
try {
expect(fileio.fchownSync(-1, UID, GID))
expect(null).assertFail()
} catch (e) {
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
console.log("fileio_test_fchown_sync_001 has failed for " + e)
}
})
/**
* @tc.number SUB_STORAGE_FileIO_FchownSync_0200
* @tc.name fileio_test_fchown_sync_002
* @tc.desc Function of API, fchownSync, wrong owner. The test file is exist.
*/
it('fileio_test_fchown_sync_002', 0, function () {
let fpath = nextFileName('fileio_test_fchown_sync_002')
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue()
let stat = fileio.statSync(fpath)
let fd;
let GID = stat.gid
try {
let fd = fileio.openSync(fpath)
fileio.fchownSync(fd, cc, GID)
expect(null).assertFail()
} catch (e) {
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
console.log("fileio_test_fchown_sync_002 has failed for " + e)
}
})
/**
* @tc.number SUB_STORAGE_FileIO_FchownSync_0300
* @tc.name fileio_test_fchown_sync_003
* @tc.desc Function of API, fchownSync, wrong group. The test file is exist.
*/
it('fileio_test_fchown_sync_003', 0, function () {
let fpath = nextFileName('fileio_test_fchown_sync_003')
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue()
let stat = fileio.statSync(fpath)
let UID = stat.uid;
let fd;
try {
fd = fileio.openSync(fpath, 0o2)
expect(fileio.fchownSync(fd, UID, 0))
expect(null).assertFail()
} catch (e) {
expect(fileio.closeSync(fd) !== null).assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
console.log("fileio_test_fchown_sync_003 has failed for " + e)
}
})
/**
* @tc.number SUB_STORAGE_FileIO_FchownSync_0400
* @tc.name fileio_test_fchown_sync_004
* @tc.desc Function of API, fchownSync, no value of fd. The test file is exist.
*/
it('fileio_test_fchown_sync_004', 0, function () {
let fpath = nextFileName('fileio_test_fchown_sync_004')
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue()
let stat = fileio.statSync(fpath)
let UID = stat.uid
let GID = stat.gid
let fd = null
try {
expect(fileio.fchownSync(fd, UID, GID))
expect(null).assertFail()
} catch (e) {
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
console.log("fileio_test_fchown_sync_004 has failed for " + e)
}
})
/**
* @tc.number SUB_STORAGE_FileIO_FchownSync_0500
* @tc.name fileio_test_fchown_sync_005
* @tc.desc Function of API, fchownSync, no value of owner. The test file is exist.
*/
it('fileio_test_fchown_sync_005', 0, function () {
let fpath = nextFileName('fileio_test_fchown_sync_005')
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue()
let stat = fileio.statSync(fpath)
let UID = null
let GID = stat.gid
let fd;
try {
fd = fileio.openSync(fpath)
expect(fileio.fchownSync(fd, UID, GID))
expect(null).assertFail()
} catch (e) {
expect(fileio.closeSync(fd) !== null).assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
console.log("fileio_test_fchown_sync_005 has failed for " + e)
}
})
/**
* @tc.number SUB_STORAGE_FileIO_FchownSync_0600
* @tc.name fileio_test_fchown_sync_006
* @tc.desc Function of API, fchownSync, no value of group. The test file is exist.
*/
it('fileio_test_fchown_sync_006', 0, function () {
let fpath = nextFileName('fileio_test_fchown_sync_006')
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue()
let stat = fileio.statSync(fpath)
let UID = stat.uid
let GID = null
let fd;
try {
fd = fileio.openSync(fpath)
expect(fileio.fchownSync(fd, UID, GID))
expect(null).assertFail()
} catch (e) {
expect(fileio.closeSync(fd) !== null).assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
console.log("fileio_test_fchown_sync_006 has failed for " + e)
}
})
/**
* @tc.number SUB_STORAGE_FileIO_FchownSync_0700
* @tc.name fileio_test_fchown_sync_007
* @tc.desc Function of API, fchownSync, no value of GID,UID. The test file is exist.
*/
it('fileio_test_fchown_sync_007', 0, function () {
let fpath = nextFileName('fileio_test_fchown_sync_007')
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue()
let fd;
let UID = null
let GID = null
try {
fd = fileio.openSync(fpath, 0o2)
expect(fileio.fchownSync(fd, UID, GID))
expect(null).assertFail()
} catch (e) {
expect(fileio.closeSync(fd) !== null).assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
console.log("fileio_test_fchown_sync_007 has failed for " + e)
}
})
/**
* @tc.number SUB_STORAGE_FileIO_prop_write_open_read_4k_sync
* @tc.name fileio_test_prop_write_open_read_4k_sync
* @tc.desc Sync to write & open & read 4K file.
*/
it('fileio_test_prop_write_open_read_4k_sync', 0, function () {
let fpath = nextFileName('fileio_test_prop_write_open_read_4k_sync')
try {
let fd = fileio.openSync(fpath, 0o102, 0o777)
expect(fd !== null).assertTrue()
expect(fileio.writeSync(fd, randomString(4096)) !== null).assertTrue()
expect(fileio.closeSync(fd) !== null).assertTrue()
let fd1 = fileio.openSync(fpath, 0o2)
let rlen = fileio.readSync(fd1, new ArrayBuffer(4096))
expect(rlen == 4096).assertTrue()
expect(fileio.closeSync(fd1) !== null).assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_prop_write_open_read_4k_sync has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_prop_write_open_read_4k_sync
* @tc.name fileio_test_prop_copyFile_4k_sync
* @tc.desc Sync to copy 4K file.
*/
it('fileio_test_prop_copyFile_4k_sync', 0, function () {
let fpath = nextFileName('fileio_test_prop_copyFile_4k_sync')
let fpath1 = fileName('fileio_test_prop_copyFile_4k_1_sync')
try {
let fd = fileio.openSync(fpath, 0o102, 0o777)
expect(fd !== null).assertTrue()
expect(fileio.writeSync(fd, randomString(4096)) !== null).assertTrue()
expect(fileio.closeSync(fd) !== null).assertTrue()
expect(fileio.copyFileSync(fpath, fpath1) !== null).assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
expect(fileio.unlinkSync(fpath1) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_prop_copyFile_4k_sync has failed for " + e)
expect(null).assertFail()
}
})
})
\ No newline at end of file
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import fileio from '@ohos.fileio';
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index'
import { FILE_CONTENT, prepareFile, nextFileName, prepareFile1, randomString } from './Common'
describe('fileIOTestDir', function () {
/**
* @tc.number SUB_STORAGE_FileIO_dir_OpenSync_0000
* @tc.name fileio_test_dir_open_sync_000
* @tc.desc Function of API, opendirSync.
*/
it('fileio_test_dir_open_sync_000', 0, function () {
let dpath = nextFileName('fileio_test_dir_open_sync_000') + 'd'
try {
expect(fileio.mkdirSync(dpath) !== null).assertTrue()
let dd = fileio.opendirSync(dpath)
expect(dd !== null).assertTrue()
expect(dd.closeSync() == null).assertTrue()
expect(fileio.rmdirSync(dpath) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_dir_open_sync_000 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_dir_OpenSync_0100
* @tc.name fileio_test_dir_open_sync_001
* @tc.desc Function of API, not set parameter.
*/
it('fileio_test_dir_open_sync_001', 0, function () {
try {
fileio.opendirSync()
expect(null).assertFail()
} catch (e) {
console.log("fileio_test_dir_open_sync_001 has failed for " + e)
}
})
/**
* @tc.number SUB_STORAGE_FileIO_dir_OpenSync_0200
* @tc.name fileio_test_dir_open_sync_002
* @tc.desc Function of API, dpath value is not exist.
*/
it('fileio_test_dir_open_sync_002', 0, function () {
let dpath = nextFileName('fileio_test_dir_open_sync_003') + 'd'
try {
fileio.opendirSync(dpath)
expect(null).assertFail()
} catch (e) {
console.log("fileio_test_dir_open_sync_002 has failed for " + e)
}
})
/**
* @tc.number SUB_STORAGE_FileIO_dir_OpenSync_0300
* @tc.name fileio_test_dir_open_sync_003
* @tc.desc Function of API, dpath too long.
*/
it('fileio_test_dir_open_sync_003', 0, function () {
let dpath = nextFileName("fileio_dir11")
fileio.mkdirSync(dpath)
try {
for (let i = 0; i < 16; i++) {
console.log("time" + i)
dpath = dpath + "/f" + randomString(248)
fileio.mkdirSync(dpath)
}
expect(null).assertFail()
} catch (e) {
console.log("fileio_test_dir_open_sync_003 has failed for " + e)
}
})
/**
* @tc.number SUB_STORAGE_FileIO_dir_OpenSync_0400
* @tc.name fileio_test_dir_open_sync_004
* @tc.desc Function of API, filename too long.
*/
it('fileio_test_dir_open_sync_004', 0, function () {
let dpath = nextFileName(randomString(256))
try {
fileio.mkdirSync(dpath)
expect(null).assertFail()
} catch (e) {
console.log("fileio_test_dir_open_sync_004 has failed for " + e)
}
})
/**
* @tc.number SUB_STORAGE_FileIO_dir_OpenSync_0500
* @tc.name fileio_test_dir_open_sync_005
* @tc.desc Function of API, uri dir too many layers.
*/
it('fileio_test_dir_open_sync_005', 0, function () {
let dpath = nextFileName("dir")
fileio.mkdirSync(dpath)
try {
for (let i = 0; i < 1024; i++) {
console.log("time" + i)
dpath = dpath + "/" + i
fileio.mkdirSync(dpath)
}
expect(null).assertFail()
} catch (e) {
console.log("fileio_test_dir_open_sync_005 has failed for " + e)
}
})
/**
* @tc.number SUB_STORAGE_FileIO_dir_OpenSync_0600
* @tc.name fileio_test_dir_open_sync_006
* @tc.desc Function of API, file name contain special character.
*/
it('fileio_test_dir_open_sync_006', 0, function () {
let dpath = nextFileName("?*:<>/|")
try {
fileio.mkdirSync(dpath)
expect(null).assertFail()
} catch (e) {
console.log("fileio_test_dir_open_sync_006 has failed for " + e)
}
})
/**
* @tc.number SUB_STORAGE_FileIO_dir_ReadSync_0000
* @tc.name fileio_test_dir_read_sync_000
* @tc.desc Function of API, readSync. The dir contains 1 file.
*/
it('fileio_test_dir_read_sync_000', 0, function () {
let dpath = nextFileName('fileio_test_dir_read_sync_000') + 'd'
let fpath = dpath + '/f0'
try {
expect(typeof (fileio.mkdirSync(dpath)) == "undefined").assertTrue()
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue()
let dd = fileio.opendirSync(dpath)
expect(dd !== null).assertTrue()
expect(dd.readSync() !== null).assertTrue()
expect(dd.closeSync() == null).assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
expect(fileio.rmdirSync(dpath) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_dir_read_sync_000 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_dir_ReadSync_0100
* @tc.name fileio_test_dir_read_sync_001
* @tc.desc Function of API, readSync. The dir contains more than 1 files.
*/
it('fileio_test_dir_read_sync_001', 0, function () {
let dpath = nextFileName('fileio_test_dir_read_sync_001') + 'd'
let fpathArray = new Array(dpath + '/f1', dpath + '/f2', dpath + '/d3')
try {
expect(fileio.mkdirSync(dpath) !== null).assertTrue()
for (let i = 0; i < 3; i++) {
if (i == 2) {
expect(fileio.mkdirSync(fpathArray[i]) !== null).assertTrue()
} else {
expect(prepareFile(fpathArray[i], FILE_CONTENT)).assertTrue()
}
}
let dd = fileio.opendirSync(dpath)
expect(dd !== null).assertTrue()
for (let i = 0; i < 3; i++) {
if (i == 2) {
let bool = typeof (dd.readSync())
expect(bool == "object").assertTrue()
console.log("---bool=" + bool)
} else {
expect(dd.readSync() !== null).assertTrue()
}
}
expect(dd.closeSync() == null).assertTrue()
for (let i = 0; i < 3; i++) {
if (i == 2) {
expect(fileio.rmdirSync(fpathArray[i]) !== null).assertTrue()
} else {
expect(fileio.unlinkSync(fpathArray[i]) !== null).assertTrue()
}
}
expect(fileio.rmdirSync(dpath) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_dir_read_sync_001 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_dir_ReadSync_0200
* @tc.name fileio_test_dir_read_sync_002
* @tc.desc Function of API, repeat read. The dir contains more than 1 files.
*/
it('fileio_test_dir_read_sync_002', 0, function () {
let dpath = nextFileName('fileio_test_dir_read_sync_002') + 'd'
let fpathArray = new Array(dpath + '/f1', dpath + '/f2', dpath + '/d3')
try {
expect(fileio.mkdirSync(dpath) !== null).assertTrue()
for (let i = 0; i < 3; i++) {
if (i == 2) {
expect(fileio.mkdirSync(fpathArray[i]) !== null).assertTrue()
} else {
expect(prepareFile(fpathArray[i], FILE_CONTENT)).assertTrue()
}
}
var dd = fileio.opendirSync(dpath)
expect(dd !== null).assertTrue()
for (let i = 0; i < 3; i++) {
expect(dd.readSync() !== null).assertTrue()
}
expect(dd.readSync() == null).assertTrue()
expect(null).assertFail()
} catch (e) {
console.log("fileio_test_dir_read_sync_002 has failed for " + e)
expect(dd.closeSync() == null).assertTrue()
for (let i = 0; i < 3; i++) {
if (i == 2) {
expect(fileio.rmdirSync(fpathArray[i]) !== null).assertTrue()
} else {
expect(fileio.unlinkSync(fpathArray[i]) !== null).assertTrue()
}
}
expect(fileio.rmdirSync(dpath) !== null).assertTrue()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_dir_ReadSync_0300
* @tc.name fileio_test_dir_read_sync_003
* @tc.desc Function of API, readSync. The dir no any files.
*/
it('fileio_test_dir_read_sync_003', 0, function () {
let dpath = nextFileName('fileio_test_dir_read_sync_003') + 'd'
let dd;
try {
expect(fileio.mkdirSync(dpath) !== null).assertTrue()
dd = fileio.opendirSync(dpath)
expect(dd !== null).assertTrue()
expect(dd.readSync() == null).assertTrue()
expect(null).assertFail()
} catch (e) {
expect(dd.closeSync() == null).assertTrue()
expect(fileio.rmdirSync(dpath) !== null).assertTrue()
console.log("fileio_test_dir_read_sync_003 has failed for " + e)
}
})
/**
* @tc.number SUB_STORAGE_FileIO_dir_ReadSync_0400
* @tc.name fileio_test_dir_read_sync_004
* @tc.desc Function of API, error parameter.
*/
it('fileio_test_dir_read_sync_004', 0, function () {
let dpath = nextFileName('fileio_test_dir_read_sync_004') + 'd'
let fpath = dpath + '/f1'
let dd
try {
expect(fileio.mkdirSync(dpath) !== null).assertTrue()
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue()
dd = fileio.opendirSync(dpath)
expect(dd !== null).assertTrue()
expect(dd.readSync(-1) == null).assertTrue()
expect(null).assertFail()
} catch (e) {
expect(dd.closeSync() == null).assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
expect(fileio.rmdirSync(dpath) !== null).assertTrue()
console.log("fileio_test_dir_read_sync_004 has failed for " + e)
}
})
/**
* @tc.number SUB_STORAGE_FileIO_dir_ReadSync_0500
* @tc.name fileio_test_dir_read_sync_005
* @tc.desc Function of API, excess files.
*/
it('fileio_test_dir_read_sync_005', 0, function () {
let dpath = nextFileName('fileio_test_dir_read_sync_005') + 'd'
let fpath = dpath + '/f'
try {
expect(typeof (fileio.mkdirSync(dpath)) == "undefined").assertTrue()
for (let i = 0; i < 10001; i++) {
expect(prepareFile(fpath + i, "test_text")).assertTrue()
}
let dd = fileio.opendirSync(dpath)
expect(dd !== null).assertTrue()
expect(dd.readSync() !== null).assertTrue()
expect(dd.closeSync() == null).assertTrue()
for (let i = 0; i < 10001; i++) {
fileio.unlinkSync(fpath + i)
}
expect(fileio.rmdirSync(dpath) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_dir_read_sync_005 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_dir_CloseSync_0000
* @tc.name fileio_test_dir_close_sync_000
* @tc.desc Function of API, closeSync.
*/
it('fileio_test_dir_close_sync_000', 0, function () {
let dpath = nextFileName('fileio_test_dir_close_sync_000') + 'd'
try {
expect(fileio.mkdirSync(dpath) !== null).assertTrue()
let dd = fileio.opendirSync(dpath)
expect(dd !== null).assertTrue()
expect(dd.closeSync() == null).assertTrue()
expect(fileio.rmdirSync(dpath) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_dir_close_sync_000 has failed for " + e)
expect(null).assertFail()
}
})
})
\ No newline at end of file
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import fileio from '@system.fileio'
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index'
import { FILE_CONTENT, prepareFile, nextFileName } from './Common'
describe('fileIOTestDirent', function () {
/**
* @tc.number SUB_STORAGE_FileIO_dirent_name_0000
* @tc.name fileio_test_dirent_name_000
* @tc.desc Function of API, Get file name.
*/
it('fileio_test_dirent_name_000', 0, function () {
let dpath = nextFileName('fileio_test_dirent_name_000') + 'd'
let fpath = dpath + '/f1'
try {
expect(fileio.mkdirSync(dpath) !== null)
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue()
let dd = fileio.opendirSync(dpath)
expect(dd !== null).assertTrue()
let dirent = dd.readSync()
expect(dirent.name !== null).assertTrue()
expect(dd.closeSync() !== null)
expect(fileio.unlinkSync(fpath) !== null)
expect(fileio.rmdirSync(dpath) !== null)
} catch (e) {
console.log("fileio_test_dirent_name_000 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_dirent_isBlockDevice_0000
* @tc.name fileio_test_dirent_is_block_device_000
* @tc.desc Function of API, isBlockDevice. Determine whether it is a block device.
*/
it('fileio_test_dirent_is_block_device_000', 0, function () {
let dpath = nextFileName('fileio_test_dirent_is_block_device_000') + 'd'
let fpath = dpath + '/f1'
try {
expect(fileio.mkdirSync(dpath) !== null)
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue()
let dd = fileio.opendirSync(dpath)
expect(dd !== null).assertTrue()
let dirent = dd.readSync()
expect(dirent !== null).assertTrue()
expect(dirent.isBlockDevice() !== null)
expect(dd.closeSync() !== null)
expect(fileio.unlinkSync(fpath) !== null)
expect(fileio.rmdirSync(dpath) !== null)
return
} catch (e) {
console.log("fileio_test_dirent_is_block_device_000 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_dirent_isBlockDevice_0100
* @tc.name fileio_test_dirent_is_block_device_001
* @tc.desc Function of API, isBlockDevice. The parameter is - 1.
*/
it('fileio_test_dirent_is_block_device_001', 0, function () {
let dpath = nextFileName('fileio_test_dirent_is_block_device_001') + 'd'
let fpath = dpath + '/f1'
let dd
try {
expect(fileio.mkdirSync(dpath) !== null)
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue()
dd = fileio.opendirSync(dpath)
expect(dd !== null).assertTrue()
let dirent = dd.readSync()
expect(dirent !== null).assertTrue()
dirent.isBlockDevice(-1)
expect(null).assertFail()
} catch (e) {
expect(dd.closeSync() !== null)
expect(fileio.unlinkSync(fpath) !== null)
expect(fileio.rmdirSync(dpath) !== null)
console.log("fileio_test_dirent_is_block_device_001 has failed for " + e)
}
})
/**
* @tc.number SUB_STORAGE_FileIO_dirent_isCharacterDevice_0000
* @tc.name fileio_test_dirent_is_character_device_000
* @tc.desc Function of API, isCharacterDevice. Determine whether it is a character device.
*/
it('fileio_test_dirent_is_character_device_000', 0, function () {
let dpath = nextFileName('fileio_test_dirent_is_character_device_000') + 'd'
let fpath = dpath + '/f1'
try {
expect(fileio.mkdirSync(dpath) !== null)
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue()
let dd = fileio.opendirSync(dpath)
expect(dd !== null).assertTrue()
let dirent = dd.readSync()
expect(dirent !== null).assertTrue()
expect(dirent.isCharacterDevice() !== null)
expect(dd.closeSync() !== null !== null)
expect(fileio.unlinkSync(fpath) !== null)
expect(fileio.rmdirSync(dpath) !== null)
} catch (e) {
console.log("fileio_test_dirent_is_character_device_000 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_dirent_isCharacterDevice_0100
* @tc.name fileio_test_dirent_is_character_device_001
* @tc.desc Function of API, isCharacterDevice. The parameter is - 1.
*/
it('fileio_test_dirent_is_character_device_001', 0, function () {
let dpath = nextFileName('fileio_test_dirent_is_character_device_001') + 'd'
let fpath = dpath + '/f1'
let dd
try {
expect(fileio.mkdirSync(dpath) !== null)
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue()
dd = fileio.opendirSync(dpath)
expect(dd !== null).assertTrue()
let dirent = dd.readSync()
expect(dirent !== null).assertTrue()
dirent.isCharacterDevice(-1)
expect(null).assertFail()
} catch (e) {
expect(dd.closeSync() !== null)
expect(fileio.unlinkSync(fpath) !== null)
expect(fileio.rmdirSync(dpath) !== null)
console.log("fileio_test_dirent_is_character_device_001 has failed for " + e)
}
})
/**
* @tc.number SUB_STORAGE_FileIO_dirent_isDirectory_0000
* @tc.name fileio_test_dirent_is_directory_000
* @tc.desc Function of API, isDirectory. Determine whether it is a directory.
*/
it('fileio_test_dirent_is_directory_000', 0, function () {
let dpath = nextFileName('fileio_test_dirent_is_directory_000') + 'd'
let fpath = dpath + '/f1'
try {
expect(fileio.mkdirSync(dpath) !== null)
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue()
let dd = fileio.opendirSync(dpath)
expect(dd !== null).assertTrue()
let dirent = dd.readSync()
expect(dirent !== null).assertTrue()
expect(dirent.isDirectory() !== null)
expect(dd.closeSync() !== null)
expect(fileio.unlinkSync(fpath) !== null)
expect(fileio.rmdirSync(dpath) !== null)
} catch (e) {
console.log("fileio_test_dirent_is_directory_000 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_dirent_isDirectory_0100
* @tc.name fileio_test_dirent_is_directory_001
* @tc.desc Function of API, isDirectory. The parameter is - 1
*/
it('fileio_test_dirent_is_directory_001', 0, function () {
let dpath = nextFileName('fileio_test_dirent_is_directory_001') + 'd'
let fpath = dpath + '/f1'
let dd
try {
expect(fileio.mkdirSync(dpath) !== null)
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue()
dd = fileio.opendirSync(dpath)
expect(dd !== null).assertTrue()
let dirent = dd.readSync()
expect(dirent !== null).assertTrue()
dirent.isDirectory(-1)
expect(null).assertFail()
} catch (e) {
expect(dd.closeSync() !== null)
expect(fileio.unlinkSync(fpath) !== null)
expect(fileio.rmdirSync(dpath) !== null)
console.log("fileio_test_dirent_is_directory_001 has failed for " + e)
}
})
/**
* @tc.number SUB_STORAGE_FileIO_dirent_isFifo_0000
* @tc.name fileio_test_dirent_is_fifo_000
* @tc.desc Function of API, isFIFO. Determine whether it is a fifo.
*/
it('fileio_test_dirent_is_fifo_000', 0, function () {
let dpath = nextFileName('fileio_test_dirent_is_fifo_000') + 'd'
let fpath = dpath + '/f1'
try {
expect(fileio.mkdirSync(dpath) !== null)
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue()
let dd = fileio.opendirSync(dpath)
expect(dd !== null).assertTrue()
let dirent = dd.readSync()
expect(dirent !== null).assertTrue()
expect(dirent.isFIFO() !== null)
expect(dd.closeSync() !== null)
expect(fileio.unlinkSync(fpath) !== null)
expect(fileio.rmdirSync(dpath) !== null)
} catch (e) {
console.log("fileio_test_dirent_is_fifo_000 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_dirent_isFifo_0100
* @tc.name fileio_test_dirent_is_fifo_001
* @tc.desc Function of API, isFIFO. The parameter is - 1
*/
it('fileio_test_dirent_is_fifo_001', 0, function () {
let dpath = nextFileName('fileio_test_dirent_is_fifo_001') + 'd'
let fpath = dpath + '/f1'
let dd
try {
expect(fileio.mkdirSync(dpath) !== null)
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue()
dd = fileio.opendirSync(dpath)
expect(dd !== null).assertTrue()
let dirent = dd.readSync()
expect(dirent !== null).assertTrue()
dirent.isFIFO(-1)
expect(null).assertFail()
} catch (e) {
expect(dd.closeSync() !== null)
expect(fileio.unlinkSync(fpath) !== null)
expect(fileio.rmdirSync(dpath) !== null)
console.log("fileio_test_dirent_is_fifo_001 has failed for " + e)
}
})
/**
* @tc.number SUB_STORAGE_FileIO_dirent_isFile_0000
* @tc.name fileio_test_dirent_is_file_000
* @tc.desc Function of API, isFile. Determine whether it is a file.
*/
it('fileio_test_dirent_is_file_000', 0, function () {
let dpath = nextFileName('fileio_test_dirent_is_file_000') + 'd'
let fpath = dpath + '/f1'
try {
expect(fileio.mkdirSync(dpath) !== null)
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue()
let dd = fileio.opendirSync(dpath)
expect(dd !== null).assertTrue()
let dirent = dd.readSync()
expect(dirent !== null).assertTrue()
expect(dirent.isFile() !== null)
expect(dd.closeSync() !== null)
expect(fileio.unlinkSync(fpath) !== null)
expect(fileio.rmdirSync(dpath) !== null)
} catch (e) {
console.log("fileio_test_dirent_is_file_000 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_dirent_isFile_0100
* @tc.name fileio_test_dirent_is_file_001
* @tc.desc Function of API, isFile. The parameter is - 1
*/
it('fileio_test_dirent_is_file_001', 0, function () {
let dpath = nextFileName('fileio_test_dirent_is_file_001') + 'd'
let fpath = dpath + '/f1'
let dd
try {
expect(fileio.mkdirSync(dpath) !== null)
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue()
dd = fileio.opendirSync(dpath)
expect(dd !== null).assertTrue()
let dirent = dd.readSync()
expect(dirent !== null).assertTrue()
dirent.isFile(-1)
expect(null).assertFail()
} catch (e) {
expect(dd.closeSync() !== null)
expect(fileio.unlinkSync(fpath) !== null)
expect(fileio.rmdirSync(dpath) !== null)
console.log("fileio_test_dirent_is_file_001 has failed for " + e)
}
})
/**
* @tc.number SUB_STORAGE_FileIO_dirent_isSocket_0000
* @tc.name fileio_test_dirent_is_socket_000
* @tc.desc Function of API, isSocket. Determine whether it is a socket.
*/
it('fileio_test_dirent_is_socket_000', 0, function () {
let dpath = nextFileName('fileio_test_dirent_is_socket_000') + 'd'
let fpath = dpath + '/f1'
try {
expect(fileio.mkdirSync(dpath) !== null)
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue()
let dd = fileio.opendirSync(dpath)
expect(dd !== null).assertTrue()
let dirent = dd.readSync()
expect(dirent !== null).assertTrue()
expect(dirent.isSocket() !== null)
expect(dd.closeSync() !== null)
expect(fileio.unlinkSync(fpath) !== null)
expect(fileio.rmdirSync(dpath) !== null)
} catch (e) {
console.log("fileio_test_dirent_is_socket_000 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_dirent_isSocket_0100
* @tc.name fileio_test_dirent_is_socket_001
* @tc.desc Function of API, isSocket. The parameter is - 1
*/
it('fileio_test_dirent_is_socket_001', 0, function () {
let dpath = nextFileName('fileio_test_dirent_is_socket_001') + 'd'
let fpath = dpath + '/f1'
let dd
try {
expect(fileio.mkdirSync(dpath) !== null)
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue()
dd = fileio.opendirSync(dpath)
expect(dd !== null).assertTrue()
let dirent = dd.readSync()
expect(dirent !== null).assertTrue()
dirent.isSocket(-1)
expect(null).assertFail()
} catch (e) {
expect(dd.closeSync() !== null)
expect(fileio.unlinkSync(fpath) !== null)
expect(fileio.rmdirSync(dpath) !== null)
console.log("fileio_test_dirent_is_socket_001 has failed for " + e)
}
})
/**
* @tc.number SUB_STORAGE_FileIO_dirent_isSymbolicLlink_0000
* @tc.name fileio_test_dirent_is_symbolic_link_000
* @tc.desc Function of API, isSymbolicLink. Determine whether it is a symbolic link.
*/
it('fileio_test_dirent_is_symbolic_link_000', 0, function () {
let dpath = nextFileName('fileio_test_dirent_is_symbolic_link_000') + 'd'
let fpath = dpath + '/f1'
try {
expect(fileio.mkdirSync(dpath) !== null)
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue()
let dd = fileio.opendirSync(dpath)
expect(dd !== null).assertTrue()
let dirent = dd.readSync()
expect(dirent !== null).assertTrue()
expect(dirent.isSymbolicLink() !== null)
expect(dd.closeSync() !== null)
expect(fileio.unlinkSync(fpath) !== null)
expect(fileio.rmdirSync(dpath) !== null)
} catch (e) {
console.log("fileio_test_dirent_is_symbolic_link_000 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_dirent_isSymbolicLlink_0100
* @tc.name fileio_test_dirent_is_symbolic_link_001
* @tc.desc Function of API, isSymbolicLink. The parameter is - 1
*/
it('fileio_test_dirent_is_symbolic_link_001', 0, function () {
let dpath = nextFileName('fileio_test_dirent_is_symbolic_link_001') + 'd'
let fpath = dpath + '/f1'
let dd
try {
expect(fileio.mkdirSync(dpath) !== null)
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue()
dd = fileio.opendirSync(dpath)
expect(dd !== null).assertTrue()
let dirent = dd.readSync()
expect(dirent !== null).assertTrue()
dirent.isSymbolicLink(-1)
expect(null).assertFail()
} catch (e) {
expect(dd.closeSync() !== null)
expect(fileio.unlinkSync(fpath) !== null)
expect(fileio.rmdirSync(dpath) !== null)
console.log("fileio_test_dirent_is_symbolic_link_001 has failed for " + e)
}
})
})
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import fileio from '@ohos.fileio';
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index'
import { FILE_CONTENT, prepareFile, nextFileName, randomString } from './Common'
describe('fileIOTestStat', function () {
/**
* @tc.number SUB_STORAGE_FileIO_statSync_0000
* @tc.name fileio_test_stat_stat_sync_000
* @tc.desc Function of API, statSync. Gets information about the file in the specified path.
*/
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) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_stat_stat_sync_000 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_statSync_0100
* @tc.name fileio_test_stat_stat_sync_001
* @tc.desc Function of API, statSync. The specified file does not exist.
*/
it('fileio_test_stat_stat_sync_001', 0, function () {
let fpath = nextFileName('fileio_test_stat_stat_sync_001')
try {
fileio.statSync(fpath)
expect(null).assertFail()
} catch (e) {
console.log("fileio_test_stat_stat_sync_001 has failed for " + e)
}
})
/**
* @tc.number SUB_STORAGE_FileIO_statSync_0200
* @tc.name fileio_test_stat_stat_sync_002
* @tc.desc Function of API, statSync. The parameter is the directory path.
*/
it('fileio_test_stat_stat_sync_002', 0, function () {
let dpath = nextFileName('fileio_test_stat_stat_sync_002') + 'd'
expect(fileio.mkdirSync(dpath) !== null).assertTrue()
try {
let stat = fileio.statSync(dpath)
expect(stat !== null).assertTrue()
expect(fileio.rmdirSync(dpath) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_stat_stat_sync_002 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_statSync_0300
* @tc.name fileio_test_stat_stat_sync_003
* @tc.desc Function of API, statSync. The file path is greater than 4096.
*/
it('fileio_test_stat_stat_sync_003', 0, function () {
let dpath = nextFileName("fileio_stat1")
try {
for (let i = 0; i < 16; i++) {
if (i == 15) {
let fpath = dpath + "/f" + randomString(252)
fileio.statSync(fpath)
} else {
dpath = dpath + "/d" + randomString(252)
}
}
expect(null).assertFail()
} catch (e) {
console.log("fileio_test_stat_stat_sync_003 has failed for " + e)
}
})
/**
* @tc.number SUB_STORAGE_FileIO_Stat_dev_0000
* @tc.name fileio_test_stat_dev_000
* @tc.desc Function of API. Get the device number used by the file.
*/
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(typeof (stat.dev) == "number").assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_stat_dev_000 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_Stat_ino_0000
* @tc.name fileio_test_stat_ino_000
* @tc.desc Function of API. Get inode number.
*/
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(typeof (stat.ino) == "number").assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_stat_ino_000 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_Stat_mode_0000
* @tc.name fileio_test_stat_mode_000
* @tc.desc Function of API. Get file type and access rights.
*/
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(typeof (stat.mode) == "number").assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_stat_mode_000 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_Stat_nlink_0000
* @tc.name fileio_test_stat_nlink_000
* @tc.desc Function of API. Gets the number of hard connections to the file.
*/
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(typeof (stat.nlink) == "number").assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_stat_nlink_000 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_Stat_uid_0000
* @tc.name fileio_test_stat_uid_000
* @tc.desc Function of API. Get file owner user ID.
*/
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(typeof (stat.uid) == "number").assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_stat_uid_000 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_Stat_gid_0000
* @tc.name fileio_test_stat_gid_000
* @tc.desc Function of API. Get group ID.
*/
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(typeof (stat.gid) == "number").assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_stat_gid_000 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_Stat_rdev_0000
* @tc.name fileio_test_stat_rdev_000
* @tc.desc Function of API. Get the device number of the device file.
*/
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(typeof (stat.rdev) == "number").assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_stat_rdev_000 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_stat_size_0000
* @tc.name fileio_test_stat_size_000
* @tc.desc Function of API. Gets the file capacity in bytes.
*/
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(typeof (stat.size) == "number").assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_stat_size_000 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_Stat_blksize_0000
* @tc.name fileio_test_stat_blksize_000
* @tc.desc Function of API. Gets the size of the disk block containing the file.
*/
it('fileio_test_stat_blksize_000', 0, function () {
let fpath = nextFileName('fileio_test_stat_blksize_000')
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue()
try {
let stat = fileio.statSync(fpath)
expect(typeof (stat.blksize) == "number").assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_stat_blksize_000 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_Stat_blocks_0000
* @tc.name fileio_test_stat_blocks_000
* @tc.desc Function of API. Gets the disk block occupied by the file.
*/
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(typeof (stat.blocks) == "number").assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_stat_blocks_000 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_stat_atime_0000
* @tc.name fileio_test_stat_atime_000
* @tc.desc Function of API. Gets the time when a file was last accessed.
*/
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(typeof (stat.atime) == "number").assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_stat_atime_000 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_Stat_mtime_0000
* @tc.name fileio_test_stat_mtime_000
* @tc.desc Function of API. Gets the time when a file was last modified
*/
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(typeof (stat.mtime) == "number").assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_stat_mtime_000 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_Stat_ctime_0000
* @tc.name fileio_test_stat_ctime_000
* @tc.desc Function of API. Gets the time when a file last changed state
*/
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(typeof (stat.ctime) == "number").assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_stat_ctime_000 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_Stat_isBlockDevice_0000
* @tc.name fileio_test_stat_is_block_device_000
* @tc.desc Function of API, isBlockDevice. Determine whether it is a block device. The return value is Boolean.
*/
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(typeof (stat.isBlockDevice()) == "boolean").assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_stat_is_block_device_000 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_Stat_isBlockDevice_0100
* @tc.name fileio_test_stat_is_block_device_001
* @tc.desc Function of API, isBlockDevice. Determine whether it is a block device. The return value is false.
*/
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()).assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_stat_is_block_device_001 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_Stat_isBlockDevice_0200
* @tc.name fileio_test_stat_is_block_device_002
* @tc.desc Function of API, isBlockDevice. The parameter is - 1
*/
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)).assertTrue()
expect(null).assertFail()
} catch (e) {
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
console.log("fileio_test_stat_is_block_device_002 has failed for " + e)
}
})
/**
* @tc.number SUB_STORAGE_FileIO_stat_isCharacterDevice_0000
* @tc.name fileio_test_stat_is_character_device_000
* @tc.desc Function of API, isCharacterDevice. Determine whether it is a character device. The return value is Boolean.
*/
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(typeof (stat.isCharacterDevice()) == "boolean").assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_stat_is_character_device_000 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_Stat_isCharacterDevice_0100
* @tc.name fileio_test_stat_is_character_device_001
* @tc.desc Function of API, isCharacterDevice. Determine whether it is a character device. The return value is false.
*/
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()).assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_stat_is_character_device_001 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_Stat_isCharacterDevice_0200
* @tc.name fileio_test_stat_is_character_device_002
* @tc.desc Function of API, isCharacterDevice. The parameter is - 1
*/
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)).assertTrue()
expect(null).assertFail()
} catch (e) {
console.log("fileio_test_stat_is_character_device_002 has failed for " + e)
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_Stat_isDirectory_0000
* @tc.name fileio_test_stat_is_directory_000
* @tc.desc Function of API, isDirectory. Determine whether it is a directory. The return value is Boolean.
*/
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(typeof (stat.isDirectory()) == "boolean").assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_stat_is_directory_000 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_Stat_isDirectory_0100
* @tc.name fileio_test_stat_is_directory_001
* @tc.desc Function of API, isDirectory. Determine whether it is a directory. The return value is false.
*/
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()).assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_stat_is_directory_001 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_Stat_isDirectory_0200
* @tc.name fileio_test_stat_is_directory_002
* @tc.desc Function of API, isDirectory. Determine whether it is a directory. The return value is true.
*/
it('fileio_test_stat_is_directory_002', 0, function () {
let dpath = nextFileName('fileio_test_stat_is_directory_002') + 'd'
try {
expect(fileio.mkdirSync(dpath) !== null).assertTrue()
let stat = fileio.statSync(dpath)
expect(stat.isDirectory()).assertTrue()
expect(fileio.rmdirSync(dpath) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_stat_is_directory_002 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_Stat_isDirectory_0300
* @tc.name fileio_test_stat_is_directory_003
* @tc.desc Function of API, isDirectory. The parameter is - 1
*/
it('fileio_test_stat_is_directory_003', 0, function () {
let dpath = nextFileName('fileio_test_stat_is_directory_003') + 'd'
try {
expect(fileio.mkdirSync(dpath) !== null).assertTrue()
let stat = fileio.statSync(dpath)
expect(stat.isDirectory(-1) == null).assertTrue()
expect(null).assertFail()
} catch (e) {
console.log("fileio_test_stat_is_directory_003 has failed for " + e)
expect(fileio.rmdirSync(dpath) !== null).assertTrue()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_stat_isFifo_0000
* @tc.name fileio_test_stat_is_fifo_000
* @tc.desc Function of API, isFIFO. Determine whether it is a fifo. The return value is Boolean.
*/
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(typeof (stat.isFIFO()) == "boolean").assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_stat_is_fifo_000 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_Stat_isFifo_0100
* @tc.name fileio_test_stat_is_fifo_001
* @tc.desc Function of API, isFIFO. Determine whether it is a fifo. The return value is false.
*/
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()).assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_stat_is_fifo_001 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_Stat_isFifo_0200
* @tc.name fileio_test_stat_is_fifo_002
* @tc.desc Function of API, isFIFO. The parameter is - 1
*/
it('fileio_test_stat_is_fifo_002', 0, function () {
let fpath = nextFileName('fileio_test_stat_is_fifo_002')
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue()
try {
let stat = fileio.statSync(fpath)
expect(stat.isFIFO(-1) == null).assertTrue()
expect(null).assertFail()
} catch (e) {
console.log("fileio_test_stat_is_fifo_002 has failed for " + e)
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_Stat_isFile_0000
* @tc.name fileio_test_stat_is_file_000
* @tc.desc Function of API, isFile. Determine whether it is a file. The return value is Boolean.
*/
it('fileio_test_stat_is_file_000', 0, function () {
let fpath = nextFileName('fileio_test_stat_is_file_000')
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue()
try {
let stat = fileio.statSync(fpath)
expect(typeof (stat.isFile()) == "boolean").assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_stat_is_file_000 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_Stat_isFile_0100
* @tc.name fileio_test_stat_is_file_001
* @tc.desc Function of API, isFile. Determine whether it is a file. The return value is true.
*/
it('fileio_test_stat_is_file_001', 0, function () {
let fpath = nextFileName('fileio_test_stat_is_file_001')
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue()
try {
let stat = fileio.statSync(fpath)
expect(stat.isFile()).assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
console.log("---fileio_test_stat_is_file_001 is passed!")
} catch (e) {
console.log("fileio_test_stat_is_file_001 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_Stat_isFile_0200
* @tc.name fileio_test_stat_is_file_002
* @tc.desc Function of API, isFile. Determine whether it is a file. The return value is false.
*/
it('fileio_test_stat_is_file_002', 0, function () {
let dpath = nextFileName('fileio_test_stat_is_file_002')
try {
expect(fileio.mkdirSync(dpath) !== null).assertTrue()
let stat = fileio.statSync(dpath)
expect(!stat.isFile()).assertTrue()
expect(fileio.rmdirSync(dpath) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_stat_is_file_002 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_Stat_isFile_0300
* @tc.name fileio_test_stat_is_file_003
* @tc.desc Function of API, isFile. The parameter is - 1
*/
it('fileio_test_stat_is_file_003', 0, function () {
let dpath = nextFileName('fileio_test_stat_is_file_003')
try {
expect(fileio.mkdirSync(dpath) !== null).assertTrue()
let stat = fileio.statSync(dpath)
expect(stat.isFile(-1) == null).assertTrue()
expect(null).assertFail()
} catch (e) {
expect(fileio.rmdirSync(dpath) !== null).assertTrue()
console.log("fileio_test_stat_is_file_003 has failed for " + e)
}
})
/**
* @tc.number SUB_STORAGE_FileIO_Stat_isSocket_0000
* @tc.name fileio_test_stat_is_socket_000
* @tc.desc Function of API, isSocket. Determine whether it is a socket. The return value is Boolean.
*/
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(typeof (stat.isSocket()) == "boolean").assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_stat_is_socket_000 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_Stat_isSocket_0100
* @tc.name fileio_test_stat_is_socket_001
* @tc.desc Function of API, isSocket. Determine whether it is a socket. The return value is false.
*/
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()).assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_stat_is_socket_001 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_Stat_isSocket_0200
* @tc.name fileio_test_stat_is_socket_002
* @tc.desc Function of API, isSocket. The parameter is - 1
*/
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) == null).assertTrue()
expect(null).assertFail()
} catch (e) {
console.log("fileio_test_stat_is_socket_002 has failed for " + e)
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_Stat_isSymbolicLink_0000
* @tc.name fileio_test_stat_is_symbolic_link_000
* @tc.desc Function of API, isSymbolicLink. Determine whether it is a symbolic link. The return value is Boolean.
*/
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(typeof (stat.isSymbolicLink()) == "boolean").assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_stat_is_symbolic_link_000 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_Stat_isSymbolicLink_0100
* @tc.name fileio_test_stat_is_symbolic_link_001
* @tc.desc Function of API, isSymbolicLink. Determine whether it is a symbolic link. The return value is false.
*/
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()).assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_stat_is_symbolic_link_001 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_Stat_isSymbolicLink_0200
* @tc.name fileio_test_stat_is_symbolic_link_002
* @tc.desc Function of API, isSymbolicLink. The parameter is - 1
*/
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) == null).assertTrue()
expect(null).assertFail()
} catch (e) {
console.log("fileio_test_stat_is_symbolic_link_002 has failed for " + e)
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
}
})
})
\ 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, fileToReadOnly, fileToWriteOnly, sleep, fileToReadAndWrite, nextFileName, randomString
} from './Common'
describe('fileIOTestStream', function () {
/**
* @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_0000
* @tc.name fileio_test_stream_create_stream_sync_000
* @tc.desc Function of API, mode = r. The test file is exist.
*/
it('fileio_test_stream_create_stream_sync_000', 0, function () {
let fpath = nextFileName('fileio_test_stream_create_stream_sync_000')
expect(prepareFile(fpath, "")).assertTrue()
expect(fileToReadOnly(fpath)).assertTrue()
try {
let ss = fileio.createStreamSync(fpath, "r")
expect(ss !== null).assertTrue()
expect(ss.closeSync() !== null).assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
console.log("fileio_test_stream_create_stream_sync_000 is passed!")
} catch (e) {
console.log("fileio_test_stream_create_stream_sync_000 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_0100
* @tc.name fileio_test_stream_create_stream_sync_001
* @tc.desc Function of API, mode = r. The test file is not exist.
*/
it('fileio_test_stream_create_stream_sync_001', 0, function () {
let fpath = nextFileName('fileio_test_stream_create_stream_sync_001')
try {
expect(fileio.createStreamSync(fpath, "r") == null).assertTrue()
expect(null).assertFail()
} catch (e) {
console.log("fileio_test_stream_create_stream_sync_001 has failed for " + e)
}
})
/**
* @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_0200
* @tc.name fileio_test_stream_create_stream_sync_002
* @tc.desc Function of API, mode = w. The test file is exist.
*/
it('fileio_test_stream_create_stream_sync_002', 0, function () {
let fpath = nextFileName('fileio_test_stream_create_stream_sync_002')
expect(prepareFile(fpath, "")).assertTrue()
expect(fileToWriteOnly(fpath)).assertTrue()
let text = "0123456789abcdefg";
try {
let ss = fileio.createStreamSync(fpath, "w")
expect(ss !== null).assertTrue()
let wlen = ss.writeSync(text)
expect(wlen !== null).assertTrue()
expect(ss.closeSync() !== null).assertTrue()
expect(fileToReadOnly(fpath)).assertTrue()
ss = fileio.createStreamSync(fpath, "r")
let rlen = ss.readSync(new ArrayBuffer(4096))
expect(rlen == text.length).assertTrue()
expect(ss.closeSync() !== null).assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_stream_create_stream_sync_002 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_0300
* @tc.name fileio_test_stream_create_stream_sync_003
* @tc.desc Function of API, mode = w. The test file is not exist.
*/
it('fileio_test_stream_create_stream_sync_003', 0, function () {
let fpath = nextFileName('fileio_test_stream_create_stream_sync_003')
try {
let ss = fileio.createStreamSync(fpath, "w")
expect(ss !== null).assertTrue()
expect(ss.closeSync() !== null).assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_stream_create_stream_sync_003 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_0400
* @tc.name fileio_test_stream_create_stream_sync_004
* @tc.desc Function of API, mode = a. The test file is exist.
*/
it('fileio_test_stream_create_stream_sync_004', 0, function () {
let fpath = nextFileName('fileio_test_stream_create_stream_sync_004')
expect(prepareFile(fpath, "a")).assertTrue()
expect(fileToWriteOnly(fpath)).assertTrue()
let text = "0123456789abcdefg";
try {
let ss = fileio.createStreamSync(fpath, "a")
expect(ss !== null).assertTrue()
let wlen = ss.writeSync(text)
expect(wlen !== null).assertTrue()
expect(ss.closeSync() !== null).assertTrue()
expect(fileToReadOnly(fpath)).assertTrue()
ss = fileio.createStreamSync(fpath, "r")
let rlen = ss.readSync(new ArrayBuffer(4096))
expect(rlen == text.length + 1).assertTrue()
expect(ss.closeSync() !== null).assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_stream_create_stream_sync_004 has failed for " + e)
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_0500
* @tc.name fileio_test_stream_create_stream_sync_005
* @tc.desc Function of API, mode = a. The test file is not exist.
*/
it('fileio_test_stream_create_stream_sync_005', 0, function () {
let fpath = nextFileName('fileio_test_stream_create_stream_sync_005')
try {
let ss = fileio.createStreamSync(fpath, "a")
expect(ss !== null).assertTrue()
expect(ss.closeSync() !== null).assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_stream_create_stream_sync_005 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_0600
* @tc.name fileio_test_stream_create_stream_sync_006
* @tc.desc Function of API, mode = r+. The test file is exist.
*/
it('fileio_test_stream_create_stream_sync_006', 0, function () {
let fpath = nextFileName('fileio_test_stream_create_stream_sync_006')
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue()
try {
let ss = fileio.createStreamSync(fpath, "r+")
expect(ss !== null).assertTrue()
expect(ss.closeSync() !== null).assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_stream_create_stream_sync_006 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_0700
* @tc.name fileio_test_stream_create_stream_sync_007
* @tc.desc Function of API, mode = r+. The test file is not exist.
*/
it('fileio_test_stream_create_stream_sync_007', 0, function () {
let fpath = nextFileName('fileio_test_stream_create_stream_sync_007')
try {
fileio.createStreamSync(fpath, "r+")
expect(null).assertFail()
} catch (e) {
console.log("fileio_test_stream_create_stream_sync_007 has failed for " + e)
}
})
/**
* @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_0800
* @tc.name fileio_test_stream_create_stream_sync_008
* @tc.desc Function of API, mode = w+. The test file is exist.
*/
it('fileio_test_stream_create_stream_sync_008', 0, function () {
let fpath = nextFileName('fileio_test_stream_create_stream_sync_008')
expect(prepareFile(fpath, "")).assertTrue()
let text = "0123456789abcdefg";
try {
let ss = fileio.createStreamSync(fpath, "w+")
expect(ss !== null).assertTrue()
let wlen = ss.writeSync(text)
expect(wlen !== null).assertTrue()
expect(ss.closeSync() !== null).assertTrue()
expect(fileToReadOnly(fpath)).assertTrue()
ss = fileio.createStreamSync(fpath, "r")
let rlen = ss.readSync(new ArrayBuffer(4096))
expect(rlen == text.length).assertTrue()
expect(ss.closeSync() !== null).assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_stream_create_stream_sync_008 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_0900
* @tc.name fileio_test_stream_create_stream_sync_009
* @tc.desc Function of API, mode = w+. The test file is not exist.
*/
it('fileio_test_stream_create_stream_sync_009', 0, function () {
let fpath = nextFileName('fileio_test_stream_create_stream_sync_009')
try {
let ss = fileio.createStreamSync(fpath, "w+")
expect(ss !== null).assertTrue()
expect(ss.closeSync() !== null).assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_stream_create_stream_sync_009 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_1000
* @tc.name fileio_test_stream_create_stream_sync_010
* @tc.desc Function of API, mode = a+. The test file is exist.
*/
it('fileio_test_stream_create_stream_sync_010', 0, function () {
let fpath = nextFileName('fileio_test_stream_create_stream_sync_010')
expect(prepareFile(fpath, "a")).assertTrue()
let text = "0123456789abcdefg";
try {
let ss = fileio.createStreamSync(fpath, "a+")
expect(ss !== null).assertTrue()
let wlen = ss.writeSync(text)
expect(wlen !== null).assertTrue()
expect(ss.closeSync() !== null).assertTrue()
expect(fileToReadOnly(fpath)).assertTrue()
ss = fileio.createStreamSync(fpath, "r")
let rlen = ss.readSync(new ArrayBuffer(4096))
expect(rlen == text.length + 1).assertTrue()
expect(ss.closeSync() !== null).assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_stream_create_stream_sync_010 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_1100
* @tc.name fileio_test_stream_create_stream_sync_011
* @tc.desc Function of API, mode = a+. The test file is not exist.
*/
it('fileio_test_stream_create_stream_sync_011', 0, function () {
let fpath = nextFileName('fileio_test_stream_create_stream_sync_011')
try {
let ss = fileio.createStreamSync(fpath, "a+")
expect(ss !== null).assertTrue()
expect(ss.closeSync() !== null).assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_stream_create_stream_sync_011 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_1200
* @tc.name fileio_test_stream_create_stream_sync_012
* @tc.desc Function of API, mode = ab. The test file is exist.
*/
it('fileio_test_stream_create_stream_sync_012', 0, function () {
let fpath = nextFileName('fileio_test_stream_create_stream_sync_012')
expect(prepareFile(fpath, "")).assertTrue()
expect(fileToReadOnly(fpath)).assertTrue()
try {
let ss = fileio.createStreamSync(fpath, "rb")
expect(ss !== null).assertTrue()
expect(ss.closeSync() !== null).assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_stream_create_stream_sync_012 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_1300
* @tc.name fileio_test_stream_create_stream_sync_013
* @tc.desc Function of API, mode = ab. The test file is not exist.
*/
it('fileio_test_stream_create_stream_sync_013', 0, function () {
let fpath = nextFileName('fileio_test_stream_create_stream_sync_013')
try {
fileio.createStreamSync(fpath, "rb")
expect(null).assertFail()
} catch (e) {
console.log("fileio_test_stream_create_stream_sync_013 has failed for " + e)
}
})
/**
* @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_1400
* @tc.name fileio_test_stream_create_stream_sync_014
* @tc.desc Function of API, mode = wb. The test file is exist.
*/
it('fileio_test_stream_create_stream_sync_014', 0, function () {
let fpath = nextFileName('fileio_test_stream_create_stream_sync_014')
expect(prepareFile(fpath, "")).assertTrue()
expect(fileToWriteOnly(fpath)).assertTrue()
let text = "0123456789abcdefg";
try {
let ss = fileio.createStreamSync(fpath, "wb")
expect(ss !== null).assertTrue()
let wlen = ss.writeSync(text)
expect(wlen !== null).assertTrue()
expect(ss.closeSync() !== null).assertTrue()
expect(fileToReadOnly(fpath)).assertTrue()
ss = fileio.createStreamSync(fpath, "r")
let rlen = ss.readSync(new ArrayBuffer(4096))
expect(rlen == text.length).assertTrue()
expect(ss.closeSync() !== null).assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_stream_create_stream_sync_014 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_1500
* @tc.name fileio_test_stream_create_stream_sync_015
* @tc.desc Function of API, mode = wb. The test file is not exist.
*/
it('fileio_test_stream_create_stream_sync_015', 0, function () {
let fpath = nextFileName('fileio_test_stream_create_stream_sync_015')
try {
let ss = fileio.createStreamSync(fpath, "wb")
expect(ss !== null).assertTrue()
expect(ss.closeSync() !== null).assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_stream_create_stream_sync_015 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_1600
* @tc.name fileio_test_stream_create_stream_sync_016
* @tc.desc Function of API, mode = ab. The test file is exist.
*/
it('fileio_test_stream_create_stream_sync_016', 0, function () {
let fpath = nextFileName('fileio_test_stream_create_stream_sync_016')
expect(prepareFile(fpath, "a")).assertTrue()
expect(fileToWriteOnly(fpath)).assertTrue()
let text = "0123456789abcdefg";
try {
let ss = fileio.createStreamSync(fpath, "ab")
expect(ss !== null).assertTrue()
let wlen = ss.writeSync(text)
expect(wlen !== null).assertTrue()
expect(ss.closeSync() !== null).assertTrue()
expect(fileToReadOnly(fpath)).assertTrue()
ss = fileio.createStreamSync(fpath, "r")
let rlen = ss.readSync(new ArrayBuffer(4096))
expect(rlen == text.length + 1).assertTrue()
expect(ss.closeSync() !== null).assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
console.log("fileio_test_stream_create_stream_sync_016 is passed!")
} catch (e) {
console.log("fileio_test_stream_create_stream_sync_016 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_1700
* @tc.name fileio_test_stream_create_stream_sync_017
* @tc.desc Function of API, mode = ab. The test file is not exist.
*/
it('fileio_test_stream_create_stream_sync_017', 0, function () {
let fpath = nextFileName('fileio_test_stream_create_stream_sync_017')
try {
let ss = fileio.createStreamSync(fpath, "ab")
expect(ss !== null).assertTrue()
expect(ss.closeSync() !== null).assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_stream_create_stream_sync_017 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_1800
* @tc.name fileio_test_stream_create_stream_sync_018
* @tc.desc Function of API, mode = rb+. The test file is exist.
*/
it('fileio_test_stream_create_stream_sync_018', 0, function () {
let fpath = nextFileName('fileio_test_stream_create_stream_sync_018')
expect(prepareFile(fpath, "")).assertTrue()
try {
let ss = fileio.createStreamSync(fpath, "rb+")
expect(ss !== null).assertTrue()
expect(ss.closeSync() !== null).assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_stream_create_stream_sync_018 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_1900
* @tc.name fileio_test_stream_create_stream_sync_019
* @tc.desc Function of API, mode = rb+. The test file is not exist.
*/
it('fileio_test_stream_create_stream_sync_019', 0, function () {
let fpath = nextFileName('fileio_test_stream_create_stream_sync_019')
try {
fileio.createStreamSync(fpath, "rb+")
expect(null).assertFail()
} catch (e) {
console.log("fileio_test_stream_create_stream_sync_019 has failed for " + e)
}
})
/**
* @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_2000
* @tc.name fileio_test_stream_create_stream_sync_020
* @tc.desc Function of API, mode = wb+. The test file is exist.
*/
it('fileio_test_stream_create_stream_sync_020', 0, function () {
let fpath = nextFileName('fileio_test_stream_create_stream_sync_020')
expect(prepareFile(fpath, "")).assertTrue()
let text = "0123456789abcdefg";
try {
let ss = fileio.createStreamSync(fpath, "wb+")
expect(ss !== null).assertTrue()
let wlen = ss.writeSync(text)
expect(wlen !== null).assertTrue()
expect(ss.closeSync() !== null).assertTrue()
expect(fileToReadOnly(fpath)).assertTrue()
ss = fileio.createStreamSync(fpath, "r")
let rlen = ss.readSync(new ArrayBuffer(4096))
expect(rlen == text.length).assertTrue()
expect(ss.closeSync() !== null).assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_stream_create_stream_sync_020 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_2100
* @tc.name fileio_test_stream_create_stream_sync_021
* @tc.desc Function of API, mode = wb+. The test file is not exist.
*/
it('fileio_test_stream_create_stream_sync_021', 0, function () {
let fpath = nextFileName('fileio_test_stream_create_stream_sync_021')
try {
let ss = fileio.createStreamSync(fpath, "wb+")
expect(ss !== null).assertTrue()
expect(ss.closeSync() !== null).assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_stream_create_stream_sync_021 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_2200
* @tc.name fileio_test_stream_create_stream_sync_022
* @tc.desc Function of API, mode = ab+. The test file is exist.
*/
it('fileio_test_stream_create_stream_sync_022', 0, function () {
let fpath = nextFileName('fileio_test_stream_create_stream_sync_022')
expect(prepareFile(fpath, "a")).assertTrue()
let text = "0123456789abcdefg";
try {
let ss = fileio.createStreamSync(fpath, "ab+")
expect(ss !== null).assertTrue()
let wlen = ss.writeSync(text)
expect(wlen !== null).assertTrue()
expect(ss.closeSync() !== null).assertTrue()
expect(fileToReadOnly(fpath)).assertTrue()
ss = fileio.createStreamSync(fpath, "r")
let rlen = ss.readSync(new ArrayBuffer(4096))
expect(rlen == text.length + 1).assertTrue()
expect(ss.closeSync() !== null).assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_stream_create_stream_sync_022 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_2300
* @tc.name fileio_test_stream_create_stream_sync_023
* @tc.desc Function of API, mode = ab+. The test file is not exist.
*/
it('fileio_test_stream_create_stream_sync_023', 0, function () {
let fpath = nextFileName('fileio_test_stream_create_stream_sync_023')
try {
let ss = fileio.createStreamSync(fpath, "ab+")
expect(ss !== null).assertTrue()
expect(ss.closeSync() !== null).assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_stream_create_stream_sync_023 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_2400
* @tc.name fileio_test_stream_create_stream_sync_024
* @tc.desc Function of API, invaild fpath.
*/
it('fileio_test_stream_create_stream_sync_024', 0, function () {
try {
fileio.createStreamSync("", "r")
expect(null).assertFail()
} catch (e) {
console.log("fileio_test_stream_create_stream_sync_024 is passed!" + e)
}
})
/**
* @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_2500
* @tc.name fileio_test_stream_create_stream_sync_025
* @tc.desc Function of API, invaild mode.
*/
it('fileio_test_stream_create_stream_sync_025', 0, function () {
let fpath = nextFileName('fileio_test_stream_create_stream_sync_025')
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue()
try {
fileio.createStreamSync(fpath, "")
expect(null).assertFail()
} catch (e) {
console.log("fileio_test_stream_create_stream_sync_025 is passed!" + e)
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_2600
* @tc.name fileio_test_stream_create_stream_sync_026
* @tc.desc Function of API, fpath too long.
*/
it('fileio_test_stream_create_stream_sync_026', 0, function () {
let dpath = nextFileName("fileio_stream")
fileio.mkdirSync(dpath)
try {
for (let i = 0; i < 16; i++) {
if (i == 15) {
let fpath = dpath + "/f" + randomString(248)
fileio.createStreamSync(fpath, "w+")
} else {
dpath = dpath + "/d" + randomString(248)
fileio.mkdirSync(dpath)
}
}
expect(null).assertFail()
} catch (e) {
console.log("fileio_test_stream_create_stream_sync_026 has failed for " + e)
}
})
/**
* @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_2700
* @tc.name fileio_test_stream_create_stream_sync_027
* @tc.desc Function of API, filename too long.
*/
it('fileio_test_stream_create_stream_sync_027', 0, function () {
let fpath = nextFileName(randomString(256))
try {
fileio.createStreamSync(fpath, "w+")
expect(null).assertFail()
} catch (e) {
console.log("fileio_test_stream_create_stream_sync_027 has failed for " + e)
}
})
/**
* @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_2800
* @tc.name fileio_test_stream_create_stream_sync_028
* @tc.desc Function of API, path too deep.
*/
it('fileio_test_stream_create_stream_sync_028', 0, function () {
let dpath = nextFileName("stream")
fileio.mkdirSync(dpath)
try {
for (let i = 0; i < 113; i++) {
if (i == 112) {
let fpath = dpath + "/f" + i
fileio.createStreamSync(fpath, "w+")
} else {
dpath = dpath + "/" + i
fileio.mkdirSync(dpath)
}
}
expect(null).assertFail()
} catch (e) {
console.log("fileio_test_stream_create_stream_sync_028 has failed for " + e)
}
})
/**
* @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_2900
* @tc.name fileio_test_stream_create_stream_sync_029
* @tc.desc Function of API, special character.
*/
it('fileio_test_stream_create_stream_sync_029', 0, function () {
let fpath = nextFileName("?*:<>/|")
try {
fileio.createStreamSync(fpath, "w+")
expect(null).assertFail()
} catch (e) {
console.log("fileio_test_stream_create_stream_sync_029 has failed for " + e)
}
})
/**
* @tc.number SUB_STORAGE_FileIO_stream_FdopenStreamSync_0000
* @tc.name fileio_test_stream_fdopen_stream_sync_000
* @tc.desc Function of API, mode=r. The test file is exist.
*/
it('fileio_test_stream_fdopen_stream_sync_000', 0, function () {
let fpath = nextFileName('fileio_test_stream_fdopen_stream_sync_000')
expect(prepareFile(fpath, "")).assertTrue()
expect(fileToReadOnly(fpath)).assertTrue()
try {
let fd = fileio.openSync(fpath, 0o0)
let ss = fileio.fdopenStreamSync(fd, "r")
expect(ss !== null).assertTrue()
expect(fileio.closeSync(fd) !== null).assertTrue()
expect(ss.closeSync() !== null).assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_stream_fdopen_stream_sync_000 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_stream_FdopenStreamSync_0100
* @tc.name fileio_test_stream_fdopen_stream_sync_001
* @tc.desc Function of API, mode=r. The test file is not exist.
*/
it('fileio_test_stream_fdopen_stream_sync_001', 0, function () {
try {
expect(fileio.fdopenStreamSync(-1, "r") == null).assertTrue()
expect(null).assertFail()
} catch (e) {
console.log("fileio_test_stream_fdopen_stream_sync_001 has failed for " + e)
}
})
/**
* @tc.number SUB_STORAGE_FileIO_stream_FdopenStreamSync_0200
* @tc.name fileio_test_stream_fdopen_stream_sync_002
* @tc.desc Function of API, mode=w. The test file is exist.
*/
it('fileio_test_stream_fdopen_stream_sync_002', 0, function () {
let fpath = nextFileName('fileio_test_stream_fdopen_stream_sync_002')
let fd;
expect(prepareFile(fpath, "")).assertTrue()
expect(fileToWriteOnly(fpath)).assertTrue()
let text = "0123456789abcdefg";
try {
fd = fileio.openSync(fpath, 0o001)
expect(fd !== null).assertTrue()
let ss = fileio.fdopenStreamSync(fd, "w")
expect(ss !== null).assertTrue()
let wlen = ss.writeSync(text)
expect(wlen !== null).assertTrue()
expect(ss.closeSync() !== null).assertTrue()
expect(fileToReadOnly(fpath)).assertTrue()
ss = fileio.createStreamSync(fpath, "r")
let rlen = ss.readSync(new ArrayBuffer(4096))
expect(rlen == text.length).assertTrue()
expect(fileio.closeSync(fd) !== null).assertTrue()
expect(ss.closeSync() !== null).assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_stream_fdopen_stream_sync_002 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_stream_FdopenStreamSync_0300
* @tc.name fileio_test_stream_fdopen_stream_sync_003
* @tc.desc Function of API, mode=w. The test file is not exist.
*/
it('fileio_test_stream_fdopen_stream_sync_003', 0, function () {
let fpath = nextFileName('fileio_test_stream_fdopen_stream_sync_003')
try {
let fd = fileio.openSync(fpath, 0o101, 0o222)
let ss = fileio.fdopenStreamSync(fd, "w")
expect(ss !== null).assertTrue()
expect(fileio.closeSync(fd) !== null).assertTrue()
expect(ss.closeSync() !== null).assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_stream_fdopen_stream_sync_003 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_stream_FdopenStreamSync_0400
* @tc.name fileio_test_stream_fdopen_stream_sync_004
* @tc.desc Function of API, mode=a. The test file is exist.
*/
it('fileio_test_stream_fdopen_stream_sync_004', 0, function () {
let fpath = nextFileName('fileio_test_stream_fdopen_stream_sync_004')
expect(prepareFile(fpath, "1")).assertTrue()
expect(fileToWriteOnly(fpath)).assertTrue()
let text = "0123456789abcdefg";
try {
let fd = fileio.openSync(fpath, 0o2001)
expect(fd !== null).assertTrue()
let ss = fileio.fdopenStreamSync(fd, "a")
expect(ss !== null).assertTrue()
let wlen = ss.writeSync(text)
expect(wlen !== null).assertTrue()
expect(ss.closeSync() !== null).assertTrue()
expect(fileToReadOnly(fpath)).assertTrue()
ss = fileio.createStreamSync(fpath, "r")
let rlen = ss.readSync(new ArrayBuffer(4096))
expect(rlen == text.length + 1).assertTrue()
expect(fileio.closeSync(fd) !== null).assertTrue()
expect(ss.closeSync() !== null).assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_stream_fdopen_stream_sync_004 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_stream_FdopenStreamSync_0500
* @tc.name fileio_test_stream_fdopen_stream_sync_005
* @tc.desc Function of API, mode=a. The test file is not exist.
*/
it('fileio_test_stream_fdopen_stream_sync_005', 0, function () {
let fpath = nextFileName('fileio_test_stream_fdopen_stream_sync_005')
try {
let fd = fileio.openSync(fpath, 0o101, 0o222)
let ss = fileio.fdopenStreamSync(fd, "a")
expect(ss !== null).assertTrue()
expect(fileio.closeSync(fd) !== null).assertTrue()
expect(ss.closeSync() !== null).assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_stream_fdopen_stream_sync_005 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_stream_FdopenStreamSync_0600
* @tc.name fileio_test_stream_fdopen_stream_sync_006
* @tc.desc Function of API, mode=r+. The test file is exist.
*/
it('fileio_test_stream_fdopen_stream_sync_006', 0, function () {
let fpath = nextFileName('fileio_test_stream_fdopen_stream_sync_006')
expect(prepareFile(fpath, "")).assertTrue()
try {
let fd = fileio.openSync(fpath, 0o2)
let ss = fileio.fdopenStreamSync(fd, "r+")
expect(ss !== null).assertTrue()
expect(fileio.closeSync(fd) !== null).assertTrue()
expect(ss.closeSync() !== null).assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_stream_fdopen_stream_sync_006 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_stream_FdopenStreamSync_0700
* @tc.name fileio_test_stream_fdopen_stream_sync_007
* @tc.desc Function of API, mode=r+. The test file is not exist.
*/
it('fileio_test_stream_fdopen_stream_sync_007', 0, function () {
try {
fileio.fdopenStreamSync(-1, "r+")
expect(null).assertFail()
} catch (e) {
console.log("fileio_test_stream_fdopen_stream_sync_007 has failed for " + e)
}
})
/**
* @tc.number SUB_STORAGE_FileIO_stream_FdopenStreamSync_0800
* @tc.name fileio_test_stream_fdopen_stream_sync_008
* @tc.desc Function of API, mode=w+. The test file is exist.
*/
it('fileio_test_stream_fdopen_stream_sync_008', 0, function () {
let fpath = nextFileName('fileio_test_stream_fdopen_stream_sync_008')
expect(prepareFile(fpath, "")).assertTrue()
let text = "0123456789abcdefg";
try {
let fd = fileio.openSync(fpath, 0o2)
expect(fd !== null).assertTrue()
let ss = fileio.fdopenStreamSync(fd, "w+")
expect(ss !== null).assertTrue()
let wlen = ss.writeSync(text)
expect(wlen !== null).assertTrue()
expect(ss.closeSync() !== null).assertTrue()
expect(fileToReadOnly(fpath)).assertTrue()
ss = fileio.createStreamSync(fpath, "r")
let rlen = ss.readSync(new ArrayBuffer(4096))
expect(rlen == text.length).assertTrue()
expect(fileio.closeSync(fd) !== null).assertTrue()
expect(ss.closeSync() !== null).assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_stream_fdopen_stream_sync_008 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_stream_FdopenStreamSync_0900
* @tc.name fileio_test_stream_fdopen_stream_sync_009
* @tc.desc Function of API, mode=w+. The test file is not exist.
*/
it('fileio_test_stream_fdopen_stream_sync_009', 0, function () {
let fpath = nextFileName('fileio_test_stream_fdopen_stream_sync_009')
try {
let fd = fileio.openSync(fpath, 0o102, 0o666)
let ss = fileio.fdopenStreamSync(fd, "w+")
expect(ss !== null).assertTrue()
expect(fileio.closeSync(fd) !== null).assertTrue()
expect(ss.closeSync() !== null).assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_stream_fdopen_stream_sync_009 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_stream_FdopenStreamSync_1000
* @tc.name fileio_test_stream_fdopen_stream_sync_010
* @tc.desc Function of API, mode=a+. The test file is exist.
*/
it('fileio_test_stream_fdopen_stream_sync_010', 0, function () {
let fpath = nextFileName('fileio_test_stream_fdopen_stream_sync_010')
expect(prepareFile(fpath, "1")).assertTrue()
let text = "0123456789abcdefg";
try {
let fd = fileio.openSync(fpath, 0o2002)
expect(fd !== null).assertTrue()
let ss = fileio.fdopenStreamSync(fd, "a+")
expect(ss !== null).assertTrue()
let wlen = ss.writeSync(text)
expect(wlen !== null).assertTrue()
expect(ss.closeSync() !== null).assertTrue()
expect(fileToReadOnly(fpath)).assertTrue()
ss = fileio.createStreamSync(fpath, "r")
let rlen = ss.readSync(new ArrayBuffer(4096))
expect(rlen == text.length + 1).assertTrue()
expect(fileio.closeSync(fd) !== null).assertTrue()
expect(ss.closeSync() !== null).assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_stream_fdopen_stream_sync_010 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_stream_FdopenStreamSync_1100
* @tc.name fileio_test_stream_fdopen_stream_sync_011
* @tc.desc Function of API, mode=a+. The test file is not exist.
*/
it('fileio_test_stream_fdopen_stream_sync_011', 0, function () {
let fpath = nextFileName('fileio_test_stream_fdopen_stream_sync_011')
try {
let fd = fileio.openSync(fpath, 0o102, 0o666)
let ss = fileio.fdopenStreamSync(fd, "a+")
expect(ss !== null).assertTrue()
expect(fileio.closeSync(fd) !== null).assertTrue()
expect(ss.closeSync() !== null).assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_stream_fdopen_stream_sync_011 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_stream_FdopenStreamSync_1200
* @tc.name fileio_test_stream_fdopen_stream_sync_012
* @tc.desc Function of API, mode=rb. The test file is exist.
*/
it('fileio_test_stream_fdopen_stream_sync_012', 0, function () {
let fpath = nextFileName('fileio_test_stream_fdopen_stream_sync_012')
expect(prepareFile(fpath, "")).assertTrue()
expect(fileToReadOnly(fpath)).assertTrue()
try {
let fd = fileio.openSync(fpath, 0o0)
let ss = fileio.fdopenStreamSync(fd, "rb")
expect(ss !== null).assertTrue()
expect(fileio.closeSync(fd) !== null).assertTrue()
expect(ss.closeSync() !== null).assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_stream_fdopen_stream_sync_012 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_stream_FdopenStreamSync_1300
* @tc.name fileio_test_stream_fdopen_stream_sync_013
* @tc.desc Function of API, mode=rb. The test file is not exist.
*/
it('fileio_test_stream_fdopen_stream_sync_013', 0, function () {
try {
fileio.fdopenStreamSync(-1, "rb")
expect(null).assertFail()
} catch (e) {
console.log("fileio_test_stream_fdopen_stream_sync_013 has failed for " + e)
}
})
/**
* @tc.number SUB_STORAGE_FileIO_stream_FdopenStreamSync_1400
* @tc.name fileio_test_stream_fdopen_stream_sync_014
* @tc.desc Function of API, mode=wb. The test file is exist.
*/
it('fileio_test_stream_fdopen_stream_sync_014', 0, function () {
let fpath = nextFileName('fileio_test_stream_fdopen_stream_sync_014')
expect(prepareFile(fpath, "")).assertTrue()
expect(fileToWriteOnly(fpath)).assertTrue()
let text = "0123456789abcdefg";
try {
let fd = fileio.openSync(fpath, 0o001)
expect(fd !== null).assertTrue()
let ss = fileio.fdopenStreamSync(fd, "wb")
expect(ss !== null).assertTrue()
let wlen = ss.writeSync(text)
expect(wlen !== null).assertTrue()
expect(ss.closeSync() !== null).assertTrue()
expect(fileToReadOnly(fpath)).assertTrue()
ss = fileio.createStreamSync(fpath, "r")
let rlen = ss.readSync(new ArrayBuffer(4096))
expect(rlen == text.length).assertTrue()
expect(fileio.closeSync(fd) !== null).assertTrue()
expect(ss.closeSync() !== null).assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_stream_fdopen_stream_sync_014 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_stream_FdopenStreamSync_1500
* @tc.name fileio_test_stream_fdopen_stream_sync_015
* @tc.desc Function of API, mode=wb. The test file is not exist.
*/
it('fileio_test_stream_fdopen_stream_sync_015', 0, function () {
let fpath = nextFileName('fileio_test_stream_fdopen_stream_sync_015')
try {
let fd = fileio.openSync(fpath, 0o101, 0o222)
let ss = fileio.fdopenStreamSync(fd, "wb")
expect(ss !== null).assertTrue()
expect(fileio.closeSync(fd) !== null).assertTrue()
expect(ss.closeSync() !== null).assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_stream_fdopen_stream_sync_015 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_stream_FdopenStreamSync_1600
* @tc.name fileio_test_stream_fdopen_stream_sync_016
* @tc.desc Function of API, mode=ab. The test file is exist.
*/
it('fileio_test_stream_fdopen_stream_sync_016', 0, function () {
let fpath = nextFileName('fileio_test_stream_fdopen_stream_sync_016')
expect(prepareFile(fpath, "1")).assertTrue()
expect(fileToWriteOnly(fpath)).assertTrue()
let text = "0123456789abcdefg";
try {
let fd = fileio.openSync(fpath, 0o2001)
expect(fd !== null).assertTrue()
let ss = fileio.fdopenStreamSync(fd, "ab")
expect(ss !== null).assertTrue()
let wlen = ss.writeSync(text)
expect(wlen !== null).assertTrue()
expect(ss.closeSync() !== null).assertTrue()
expect(fileToReadOnly(fpath)).assertTrue()
ss = fileio.createStreamSync(fpath, "r")
let rlen = ss.readSync(new ArrayBuffer(4096))
expect(rlen == text.length + 1).assertTrue()
expect(fileio.closeSync(fd) !== null).assertTrue()
expect(ss.closeSync() !== null).assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_stream_fdopen_stream_sync_016 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_stream_FdopenStreamSync_1700
* @tc.name fileio_test_stream_fdopen_stream_sync_017
* @tc.desc Function of API, mode=ab. The test file is not exist.
*/
it('fileio_test_stream_fdopen_stream_sync_017', 0, function () {
let fpath = nextFileName('fileio_test_stream_fdopen_stream_sync_017')
try {
let fd = fileio.openSync(fpath, 0o101, 0o222)
let ss = fileio.fdopenStreamSync(fd, "ab")
expect(ss !== null).assertTrue()
expect(fileio.closeSync(fd) !== null).assertTrue()
expect(ss.closeSync() !== null).assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_stream_fdopen_stream_sync_017 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_stream_FdopenStreamSync_1800
* @tc.name fileio_test_stream_fdopen_stream_sync_018
* @tc.desc Function of API, mode=rb+. The test file is exist.
*/
it('fileio_test_stream_fdopen_stream_sync_018', 0, function () {
let fpath = nextFileName('fileio_test_stream_fdopen_stream_sync_018')
expect(prepareFile(fpath, "")).assertTrue()
try {
let fd = fileio.openSync(fpath, 0o2)
let ss = fileio.fdopenStreamSync(fd, "rb+")
expect(ss !== null).assertTrue()
expect(ss.closeSync() !== null).assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_stream_fdopen_stream_sync_018 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_stream_FdopenStreamSync_1900
* @tc.name fileio_test_stream_fdopen_stream_sync_019
* @tc.desc Function of API, mode=rb+. The test file is not exist.
*/
it('fileio_test_stream_fdopen_stream_sync_019', 0, function () {
try {
fileio.fdopenStreamSync(-1, "rb+")
expect(null).assertFail()
} catch (e) {
console.log("fileio_test_stream_fdopen_stream_sync_019 has failed for " + e)
}
})
/**
* @tc.number SUB_STORAGE_FileIO_stream_FdopenStreamSync_2000
* @tc.name fileio_test_stream_fdopen_stream_sync_020
* @tc.desc Function of API, mode=wb+. The test file is exist.
*/
it('fileio_test_stream_fdopen_stream_sync_020', 0, function () {
let fpath = nextFileName('fileio_test_stream_fdopen_stream_sync_020')
expect(prepareFile(fpath, "")).assertTrue()
let text = "0123456789abcdefg";
try {
let fd = fileio.openSync(fpath, 0o002)
expect(fd !== null).assertTrue()
let ss = fileio.fdopenStreamSync(fd, "wb+")
expect(ss !== null).assertTrue()
let wlen = ss.writeSync(text)
expect(wlen !== null).assertTrue()
expect(ss.closeSync() !== null).assertTrue()
expect(fileToReadOnly(fpath)).assertTrue()
ss = fileio.createStreamSync(fpath, "r")
let rlen = ss.readSync(new ArrayBuffer(4096))
expect(rlen == text.length).assertTrue()
expect(fileio.closeSync(fd) !== null).assertTrue()
expect(ss.closeSync() !== null).assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_stream_fdopen_stream_sync_020 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_stream_FdopenStreamSync_2100
* @tc.name fileio_test_stream_fdopen_stream_sync_021
* @tc.desc Function of API, mode=wb+. The test file is not exist.
*/
it('fileio_test_stream_fdopen_stream_sync_021', 0, function () {
let fpath = nextFileName('fileio_test_stream_fdopen_stream_sync_021')
try {
let fd = fileio.openSync(fpath, 0o102, 0o666)
let ss = fileio.fdopenStreamSync(fd, "wb+")
expect(ss !== null).assertTrue()
expect(fileio.closeSync(fd) !== null).assertTrue()
expect(ss.closeSync() !== null).assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_stream_fdopen_stream_sync_021 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_stream_FdopenStreamSync_2200
* @tc.name fileio_test_stream_fdopen_stream_sync_022
* @tc.desc Function of API, mode=ab+. The test file is exist.
*/
it('fileio_test_stream_fdopen_stream_sync_022', 0, function () {
let fpath = nextFileName('fileio_test_stream_fdopen_stream_sync_022')
expect(prepareFile(fpath, "1")).assertTrue()
let text = "0123456789abcdefg";
try {
let fd = fileio.openSync(fpath, 0o2002)
expect(fd !== null).assertTrue()
let ss = fileio.fdopenStreamSync(fd, "ab+")
expect(ss !== null).assertTrue()
let wlen = ss.writeSync(text)
expect(wlen !== null).assertTrue()
expect(ss.closeSync() !== null).assertTrue()
expect(fileToReadOnly(fpath)).assertTrue()
ss = fileio.createStreamSync(fpath, "r")
let rlen = ss.readSync(new ArrayBuffer(4096))
expect(rlen == text.length + 1).assertTrue()
expect(fileio.closeSync(fd) !== null).assertTrue()
expect(ss.closeSync() !== null).assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_stream_fdopen_stream_sync_022 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_stream_FdopenStreamSync_2300
* @tc.name fileio_test_stream_fdopen_stream_sync_023
* @tc.desc Function of API, mode=ab+. The test file is not exist.
*/
it('fileio_test_stream_fdopen_stream_sync_023', 0, function () {
let fpath = nextFileName('fileio_test_stream_fdopen_stream_sync_023')
try {
let fd = fileio.openSync(fpath, 0o102, 0o666)
let ss = fileio.fdopenStreamSync(fd, "ab+")
expect(ss !== null).assertTrue()
expect(fileio.closeSync(fd) !== null).assertTrue()
expect(ss.closeSync() !== null).assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_stream_fdopen_stream_sync_023 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_stream_FdopenStreamSync_2400
* @tc.name fileio_test_stream_fdopen_stream_sync_024
* @tc.desc Function of API, invaild fildes. The test file is exist.
*/
it('fileio_test_stream_fdopen_stream_sync_024', 0, function () {
try {
expect(fileio.fdopenStreamSync(null, "r") == null).assertTrue()
expect(null).assertFail();
} catch (e) {
console.log("---fileio_test_stream_fdopen_stream_sync_024 is passed!" + e)
}
})
/**
* @tc.number SUB_STORAGE_FileIO_stream_FdopenStreamSync_2400
* @tc.name fileio_test_stream_fdopen_stream_sync_025
* @tc.desc Function of API, invaild mode. The test file is exist.
*/
it('fileio_test_stream_fdopen_stream_sync_025', 0, function () {
let fpath = nextFileName('fileio_test_stream_fdopen_stream_sync_025')
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue()
try {
let fd = fileio.openSync(fpath, 0o2)
expect(fileio.fdopenStreamSync(fd, "") == null).assertTrue()
expect(null).assertFail();
} catch (e) {
console.log("---fileio_test_stream_fdopen_stream_sync_025 is passed!" + e)
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_stream_ReadSync_0000
* @tc.name fileio_test_stream_read_sync_000
* @tc.desc Function of API, not set options.
*/
it('fileio_test_stream_read_sync_000', 0, function () {
let fpath = nextFileName('fileio_test_stream_read_sync_000')
let text = "0123456789abcdefg";
expect(prepareFile(fpath, text)).assertTrue()
try {
let ss = fileio.createStreamSync(fpath, "r+")
expect(ss !== null).assertTrue()
let len = ss.readSync(new ArrayBuffer(4096))
expect(len == text.length).assertTrue()
expect(ss.closeSync() !== null).assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_stream_read_sync_000 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_stream_ReadSync_0100
* @tc.name fileio_test_stream_read_sync_001
* @tc.desc Function of API, position.
*/
it('fileio_test_stream_read_sync_001', 0, function () {
let fpath = nextFileName('fileio_test_stream_read_sync_001')
let text = "0123456789abcdefg";
expect(prepareFile(fpath, text)).assertTrue()
try {
let ss = fileio.createStreamSync(fpath, "r+")
expect(ss !== null).assertTrue()
let len = ss.readSync(new ArrayBuffer(4096), {
position: 1
})
expect(len == text.length - 1).assertTrue()
expect(ss.closeSync() !== null).assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_stream_read_sync_001 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_stream_ReadSync_0200
* @tc.name fileio_test_stream_read_sync_002
* @tc.desc Function of API, offset.
*/
it('fileio_test_stream_read_sync_002', 0, function () {
let fpath = nextFileName('fileio_test_stream_read_sync_002')
let text = "0123456789abcdefg";
expect(prepareFile(fpath, text)).assertTrue()
try {
let ss = fileio.createStreamSync(fpath, "r+")
expect(ss !== null).assertTrue()
let len = ss.readSync(new ArrayBuffer(4096), {
offset: 1
})
expect(len == text.length).assertTrue()
expect(ss.closeSync() !== null).assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_stream_read_sync_002 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_stream_ReadSync_0300
* @tc.name fileio_test_stream_read_sync_003
* @tc.desc Function of API, length.
*/
it('fileio_test_stream_read_sync_003', 0, function () {
let fpath = nextFileName('fileio_test_stream_read_sync_003')
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue()
try {
let ss = fileio.createStreamSync(fpath, "r+")
expect(ss !== null).assertTrue()
let len = ss.readSync(new ArrayBuffer(4096), {
length: 1
})
expect(len == 1).assertTrue()
expect(ss.closeSync() !== null).assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_stream_read_sync_003 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_stream_ReadSync_0400
* @tc.name fileio_test_stream_read_sync_004
* @tc.desc Function of API, readBuf.
*/
it('fileio_test_stream_read_sync_004', 0, function () {
let fpath = nextFileName('fileio_test_stream_read_sync_004')
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue()
try {
var ss = fileio.createStreamSync(fpath, "r+")
expect(ss !== null).assertTrue()
let len = ss.readSync(null)
expect(len == null).assertTrue()
expect(null).assertFail()
} catch (e) {
console.log("fileio_test_stream_read_sync_004 has failed for " + e)
expect(ss.closeSync() !== null).assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_stream_ReadSync_0500
* @tc.name fileio_test_stream_read_sync_005
* @tc.desc Function of API, position = -1.
*/
it('fileio_test_stream_read_sync_005', 0, function () {
let fpath = nextFileName('fileio_test_stream_read_sync_005')
let text = "0123456789abcdefg";
expect(prepareFile(fpath, text)).assertTrue()
try {
var ss = fileio.createStreamSync(fpath, "r+")
expect(ss !== null).assertTrue()
let len = ss.readSync(new ArrayBuffer(4096), {
position: -1
})
expect(len == text.length).assertTrue()
expect(ss.closeSync() !== null).assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
} catch (e) {
console.log("---fileio_test_stream_read_sync_005 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_stream_ReadSync_0600
* @tc.name fileio_test_stream_read_sync_006
* @tc.desc Function of API, offset.
*/
it('fileio_test_stream_read_sync_006', 0, function () {
let fpath = nextFileName('fileio_test_stream_read_sync_006')
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue()
try {
var ss = fileio.createStreamSync(fpath, "r+")
expect(ss !== null).assertTrue()
let len = ss.readSync(new ArrayBuffer(4096), {
offset: -1
})
expect(len == null).assertTrue()
expect(null).assertFail()
} catch (e) {
console.log("fileio_test_stream_read_sync_006 has failed for " + e)
expect(ss.closeSync() !== null).assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_stream_WriteSync_0000
* @tc.name fileio_test_stream_write_sync_000
* @tc.desc Function of API, not set options.
*/
it('fileio_test_stream_write_sync_000', 0, function () {
let fpath = nextFileName('fileio_test_stream_write_sync_000')
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue()
let text = "0123456789abcdefg";
try {
let ss = fileio.createStreamSync(fpath, "r+")
expect(ss !== null).assertTrue()
expect(ss.writeSync(text) == text.length).assertTrue()
expect(ss.closeSync() !== null).assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
console.log("---fileio_test_stream_write_sync_000 is passed!")
} catch (e) {
console.log("fileio_test_stream_write_sync_000 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_stream_WriteSync_0100
* @tc.name fileio_test_stream_write_sync_001
* @tc.desc Function of API, invaild encoding.
*/
it('fileio_test_stream_write_sync_001', 0, function () {
let fpath = nextFileName('fileio_test_stream_write_sync_001')
expect(prepareFile(fpath, "")).assertTrue()
let ss
try {
ss = fileio.createStreamSync(fpath, "w+")
expect(ss !== null).assertTrue()
expect(ss.writeSync(FILE_CONTENT, {
encoding: "ASCII"
}) !== null).assertTrue()
expect(null).assertFail()
} catch (e) {
console.log("fileio_test_stream_write_sync_001 has failed for " + e)
expect(ss.closeSync() !== null).assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_stream_WriteSync_0200
* @tc.name fileio_test_stream_write_sync_002
* @tc.desc Function of API, position.
*/
it('fileio_test_stream_write_sync_002', 0, function () {
let fpath = nextFileName('fileio_test_stream_write_sync_002')
expect(prepareFile(fpath, "a")).assertTrue()
expect(fileToWriteOnly(fpath)).assertTrue()
try {
let fd = fileio.openSync(fpath, 0o001)
expect(fd !== null).assertTrue()
let ss = fileio.fdopenStreamSync(fd, "w")
expect(ss !== null).assertTrue()
expect(ss.writeSync("aaa") !== null).assertTrue()
expect(ss.closeSync() !== null).assertTrue()
expect(fileToReadOnly(fpath)).assertTrue()
ss = fileio.createStreamSync(fpath, "r")
let rlen = ss.readSync(new ArrayBuffer(4096))
expect(rlen == 3).assertTrue()
expect(fileio.closeSync(fd) !== null).assertTrue()
expect(ss.closeSync() !== null).assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_stream_write_sync_002 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_stream_WriteSync_0300
* @tc.name fileio_test_stream_write_sync_003
* @tc.desc Function of API, offset.
*/
it('fileio_test_stream_write_sync_003', 0, function () {
let fpath = nextFileName('fileio_test_stream_write_sync_003')
expect(prepareFile(fpath, "a")).assertTrue()
expect(fileToWriteOnly(fpath)).assertTrue()
try {
let fd = fileio.openSync(fpath, 0o001)
expect(fd !== null).assertTrue()
let ss = fileio.fdopenStreamSync(fd, "w")
expect(ss !== null).assertTrue()
expect(ss.writeSync("aaa") !== null).assertTrue()
expect(ss.closeSync() !== null).assertTrue()
expect(fileToReadOnly(fpath)).assertTrue()
ss = fileio.createStreamSync(fpath, "r")
let rlen = ss.readSync(new ArrayBuffer(4096))
expect(rlen == 3).assertTrue()
expect(fileio.closeSync(fd) !== null).assertTrue()
expect(ss.closeSync() !== null).assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_stream_write_sync_003 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_stream_WriteSync_0400
* @tc.name fileio_test_stream_write_sync_004
* @tc.desc Function of API, length.
*/
it('fileio_test_stream_write_sync_004', 0, function () {
let fpath = nextFileName('fileio_test_stream_write_sync_004')
expect(prepareFile(fpath, "a")).assertTrue()
let text = "0123456789abcdefg";
try {
let ss = fileio.createStreamSync(fpath, "r+")
expect(ss !== null).assertTrue()
let wlen = ss.writeSync(text)
expect(wlen == text.length).assertTrue()
expect(ss.closeSync() !== null).assertTrue()
ss = fileio.createStreamSync(fpath, "r+")
let rlen = ss.readSync(new ArrayBuffer(4096))
expect(rlen == text.length).assertTrue()
expect(ss.closeSync() !== null).assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_stream_write_sync_004 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_stream_WriteSync_0500
* @tc.name fileio_test_stream_write_sync_005
* @tc.desc Function of API, encoding.
*/
it('fileio_test_stream_write_sync_005', 0, function () {
let fpath = nextFileName('fileio_test_stream_write_sync_005')
expect(prepareFile(fpath, "")).assertTrue()
let writeStrArray = new Array("aaa", "123")
let encodingArray = new Array('utf-8', 'utf-16')
try {
for (let i = 0; i < encodingArray.length; i++) {
let ss = fileio.createStreamSync(fpath, "w+")
expect(ss !== null).assertTrue()
expect(ss.writeSync(writeStrArray[i], {
encoding: encodingArray[i]
}) !== null).assertTrue()
expect(ss.closeSync() !== null).assertTrue()
ss = fileio.createStreamSync(fpath, "r+")
let rlen = ss.readSync(new ArrayBuffer(4096))
expect(rlen !== null).assertTrue()
expect(ss.closeSync() !== null).assertTrue()
}
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_stream_write_sync_005 has failed for " + e)
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_stream_WriteSync_0600
* @tc.name fileio_test_stream_write_sync_006
* @tc.desc Function of API, position.
*/
it('fileio_test_stream_write_sync_006', 0, function () {
let fpath = nextFileName('fileio_test_stream_write_sync_006')
expect(prepareFile(fpath, "a")).assertTrue()
expect(fileToWriteOnly(fpath)).assertTrue()
try {
let fd = fileio.openSync(fpath, 0o001)
expect(fd !== null).assertTrue()
let ss = fileio.fdopenStreamSync(fd, "w")
expect(ss !== null).assertTrue()
expect(ss.writeSync("aaa", {
position: 1
}) !== null).assertTrue()
expect(ss.closeSync() !== null).assertTrue()
expect(fileToReadOnly(fpath)).assertTrue()
ss = fileio.createStreamSync(fpath, "r")
let rlen = ss.readSync(new ArrayBuffer(4096))
expect(rlen == 4).assertTrue()
expect(fileio.closeSync(fd) !== null).assertTrue()
expect(ss.closeSync() !== null).assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_stream_write_sync_006 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_stream_WriteSync_0700
* @tc.name fileio_test_stream_write_sync_007
* @tc.desc Function of API, offset.
*/
it('fileio_test_stream_write_sync_007', 0, function () {
let fpath = nextFileName('fileio_test_stream_write_sync_007')
expect(prepareFile(fpath, "a")).assertTrue()
expect(fileToWriteOnly(fpath)).assertTrue()
try {
let fd = fileio.openSync(fpath, 0o001)
expect(fd !== null).assertTrue()
let ss = fileio.fdopenStreamSync(fd, "w")
expect(ss !== null).assertTrue()
expect(ss.writeSync("aaa", {
offset: 1
}) !== null).assertTrue()
expect(ss.closeSync() !== null).assertTrue()
expect(fileToReadOnly(fpath)).assertTrue()
ss = fileio.createStreamSync(fpath, "r")
let rlen = ss.readSync(new ArrayBuffer(4096))
expect(rlen == 2).assertTrue()
expect(fileio.closeSync(fd) !== null).assertTrue()
expect(ss.closeSync() !== null).assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_stream_write_sync_007 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_stream_WriteSync_0800
* @tc.name fileio_test_stream_write_sync_008
* @tc.desc Function of API, length.
*/
it('fileio_test_stream_write_sync_008', 0, function () {
let fpath = nextFileName('fileio_test_stream_write_sync_008')
expect(prepareFile(fpath, "")).assertTrue()
let text = "0123456789abcdefg";
try {
let ss = fileio.createStreamSync(fpath, "r+")
expect(ss !== null).assertTrue()
let wlen = ss.writeSync(text, {
length: text.length
})
expect(wlen == text.length).assertTrue()
expect(ss.closeSync() !== null).assertTrue()
ss = fileio.createStreamSync(fpath, "r+")
let rlen = ss.readSync(new ArrayBuffer(4096))
expect(rlen == text.length).assertTrue()
expect(ss.closeSync() !== null).assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_stream_write_sync_008 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_stream_WriteSync_0900
* @tc.name fileio_test_stream_write_sync_009
* @tc.desc Function of API, invaild fcontent.
*/
it('fileio_test_stream_write_sync_009', 0, function () {
let fpath = nextFileName('fileio_test_stream_write_sync_009')
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue()
try {
var ss = fileio.createStreamSync(fpath, "r+")
expect(ss !== null).assertTrue()
ss.writeSync(-1)
expect(null).assertFail()
} catch (e) {
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
console.log("fileio_test_stream_write_sync_009 has failed for " + e)
}
})
/**
* @tc.number SUB_STORAGE_FileIO_stream_WriteSync_1000
* @tc.name fileio_test_stream_write_sync_010
* @tc.desc Function of API, invaild encoding.
*/
it('fileio_test_stream_write_sync_010', 0, function () {
let fpath = nextFileName('fileio_test_stream_write_sync_010')
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue()
try {
var ss = fileio.createStreamSync(fpath, "r+")
expect(ss !== null).assertTrue()
expect(ss.writeSync(FILE_CONTENT, {
encoding: ""
}) == null).assertTrue()
expect(null).assertFail()
} catch (e) {
console.log("fileio_test_stream_write_sync_010 has failed for " + e)
expect(ss.closeSync() !== null).assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_stream_WriteSync_1100
* @tc.name fileio_test_stream_write_sync_011
* @tc.desc Function of API, invaild position.
*/
it('fileio_test_stream_write_sync_011', 0, function () {
let fpath = nextFileName('fileio_test_stream_write_sync_011')
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue()
try {
var ss = fileio.createStreamSync(fpath, "r+")
expect(ss !== null).assertTrue()
expect(ss.writeSync(FILE_CONTENT, {
position: -1
}) == null).assertTrue()
expect(null).assertFail()
} catch (e) {
console.log("fileio_test_stream_write_sync_011 has failed for " + e)
expect(ss.closeSync() !== null).assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_stream_WriteSync_1200
* @tc.name fileio_test_stream_write_sync_012
* @tc.desc Function of API, invaild offset.
*/
it('fileio_test_stream_write_sync_012', 0, function () {
let fpath = nextFileName('fileio_test_stream_write_sync_012')
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue()
try {
var ss = fileio.createStreamSync(fpath, "r+")
expect(ss !== null).assertTrue()
expect(ss.writeSync(FILE_CONTENT, {
offset: -1
}) == null).assertTrue()
expect(null).assertFail()
} catch (e) {
console.log("fileio_test_stream_write_sync_012 has failed for " + e)
expect(ss.closeSync() !== null).assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_stream_write_read_4k_sync
* @tc.name fileio_test_stream_write_read_4k_sync
* @tc.desc Function of API, read 4k file.
*/
it('fileio_test_stream_write_read_4k_sync', 0, function () {
let fpath = nextFileName('fileio_test_stream_write_read_4k_sync')
expect(prepareFile(fpath, "a")).assertTrue()
expect(fileToWriteOnly(fpath)).assertTrue()
try {
let fd = fileio.openSync(fpath, 0o001)
expect(fd !== null).assertTrue()
let ss = fileio.fdopenStreamSync(fd, "w")
expect(ss !== null).assertTrue()
expect(ss.writeSync(randomString(4096)) !== null).assertTrue()
expect(ss.closeSync() !== null).assertTrue()
expect(fileToReadOnly(fpath)).assertTrue()
ss = fileio.createStreamSync(fpath, "r")
let rlen = ss.readSync(new ArrayBuffer(4096))
expect(fileio.closeSync(fd) !== null).assertTrue()
expect(ss.closeSync() !== null).assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_stream_write_read_4k_sync has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_stream_FlushSync_0000
* @tc.name fileio_test_stream_flush_sync_000
* @tc.desc Function of API, flushSync.
*/
it('fileio_test_stream_flush_sync_000', 0, function () {
let fpath = nextFileName('fileio_test_stream_flush_sync_000')
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue()
let text = "0123456789abcdefg";
try {
let ss = fileio.createStreamSync(fpath, "r+")
expect(ss !== null).assertTrue()
expect(ss.writeSync(text) == text.length).assertTrue()
expect(ss.flushSync() !== null).assertTrue()
expect(ss.closeSync() !== null).assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_stream_flush_sync_001 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_stream_FlushSync_0100
* @tc.name fileio_test_stream_flush_sync_001
* @tc.desc Function of API, error.
*/
it('fileio_test_stream_flush_sync_001', 0, function () {
let fpath = nextFileName('fileio_test_stream_flush_sync_001')
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue()
try {
let ss = fileio.createStreamSync(fpath, "r+")
expect(ss !== null).assertTrue()
expect(ss.closeSync() !== null).assertTrue()
ss.flushSync()
expect(null).assertFail()
} catch (e) {
console.log("fileio_test_stream_flush_sync_001 has failed for " + e)
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_stream_CloseSync_0000
* @tc.name fileio_test_stream_close_sync_000
* @tc.desc Function of API, closeSync.
*/
it('fileio_test_stream_close_sync_000', 0, function () {
let fpath = nextFileName('fileio_test_stream_close_sync_000')
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue()
try {
let ss = fileio.createStreamSync(fpath, "r+")
expect(ss.closeSync() !== null).assertTrue()
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_stream_close_sync_000 has failed for " + e)
expect(null).assertFail()
}
})
/**
* @tc.number SUB_STORAGE_FileIO_stream_CloseSync_0100
* @tc.name fileio_test_stream_close_sync_001
* @tc.desc Function of API, error.
*/
it('fileio_test_stream_close_sync_001', 0, function () {
let fpath = nextFileName('fileio_test_stream_close_sync_001')
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue()
let ss;
try {
ss = fileio.createStreamSync(fpath, "r+")
expect(ss.closeSync() !== null).assertTrue()
expect(ss.closeSync() == null).assertTrue()
expect(null).assertFail()
} catch (e) {
expect(fileio.unlinkSync(fpath) !== null).assertTrue()
console.log("fileio_test_stream_close_sync_001 has failed for " + e)
}
})
})
\ 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('./File.test.js')
require('./FileIO.test.js')
require('./FileIODir.test.js')
require('./FileIODirent.test.js')
require('./FileIOStat.test.js')
require('./FileIOStream.test.js')
\ No newline at end of file
{
"string": [
{
"name": "app_name",
"value": "MyApplication"
},
{
"name": "mainability_description",
"value": "JS_Phone_Empty Feature Ability"
}
]
}
\ No newline at end of file
...@@ -39,6 +39,7 @@ _all_test_packages = [ ...@@ -39,6 +39,7 @@ _all_test_packages = [
"${ACTS_ROOT}/updater:update", "${ACTS_ROOT}/updater:update",
"${ACTS_ROOT}/graphic:graphic", "${ACTS_ROOT}/graphic:graphic",
"${ACTS_ROOT}/ace:ace", "${ACTS_ROOT}/ace:ace",
"${ACTS_ROOT}/storage:storage",
] ]
_all_test_packages_ivi = [ _all_test_packages_ivi = [
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册