未验证 提交 0c2ff958 编写于 作者: O openharmony_ci 提交者: Gitee

!6335 【版本回合】xts回合monthly_1018

Merge pull request !6335 from gsl_1234/cherry-pick-1667444801
......@@ -18,6 +18,7 @@ group("storage") {
deps = [
"storagefileioerrorjstest:storagefileioerror_js_test",
"storagefileiojstest:storagefileio_js_test",
"storagefileiov9jstest:storagefileiov9_js_test",
"storagefilejstest:storagefile_js_test",
"storagesecuritylabeljstest:storagesecuritylabel_js_test",
"storagestatfsjstest:storagestatfs_js_test",
......
# Copyright (C) 2022 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("storagefileiov9_js_test") {
hap_profile = "./src/main/config.json"
deps = [
":storagefileiov9_js_assets",
":storagefileiov9_js_resources",
]
certificate_profile = "./signature/openharmony_sx.p7b"
hap_name = "ActsStorageFileIoV9JSTest"
subsystem_name = "filemanagement"
part_name = "file_api"
}
ohos_js_assets("storagefileiov9_js_assets") {
js2abc = true
hap_profile = "./src/main/config.json"
source_dir = "./src/main/js"
}
ohos_resources("storagefileiov9_js_resources") {
sources = [ "./src/main/resources" ]
hap_profile = "./src/main/config.json"
}
{
"description": "Configuration for storage filefs Tests",
"driver": {
"type": "OHJSUnitTest",
"test-timeout": "600000",
"shell-timeout": "600000",
"bundle-name": "ohos.acts.storage.fileiov9",
"package-name": "ohos.acts.storage.fileiov9"
},
"kits": [
{
"test-file-name": ["ActsStorageFileIoV9JSTest.hap"],
"type": "AppInstallKit",
"cleanup-apps": true
}
]
}
\ No newline at end of file
{
"app": {
"bundleName": "ohos.acts.storage.fileiov9",
"vendor": "example",
"version": {
"code": 1000000,
"name": "1.0.0"
},
"apiVersion": {
"compatible": 4,
"target": 5
}
},
"deviceConfig": {},
"module": {
"package": "ohos.acts.storage.fileiov9",
"name": ".entry",
"deviceType": [
"default",
"phone"
],
"distro": {
"deliveryWithInstall": true,
"moduleName": "entry",
"moduleType": "entry",
"installationFree": true
},
"abilities": [
{
"skills": [
{
"entities": [
"entity.system.home"
],
"actions": [
"action.system.home"
]
}
],
"orientation": "unspecified",
"formsEnabled": false,
"name": ".MainAbility",
"srcLanguage": "js",
"srcPath": "MainAbility",
"icon": "$media:icon",
"description": "$string:MainAbility_desc",
"label": "$string:MainAbility_label",
"type": "page",
"visible": true,
"launchType": "standard"
},
{
"orientation": "unspecified",
"formsEnabled": false,
"name": ".TestAbility",
"srcLanguage": "js",
"srcPath": "TestAbility",
"icon": "$media:icon",
"description": "$string:TestAbility_desc",
"label": "$string:TestAbility_label",
"type": "page",
"visible": true,
"launchType": "standard"
}
],
"js": [
{
"pages": [
"pages/index/index"
],
"name": "default",
"window": {
"designWidth": 720,
"autoDesignWidth": false
}
},
{
"pages": [
"pages/index/index"
],
"name": ".TestAbility",
"window": {
"designWidth": 720,
"autoDesignWidth": false
}
}
],
"testRunner": {
"name": "OpenHarmonyTestRunner",
"srcPath": "TestRunner"
},
"mainAbility": ".MainAbility",
"srcPath": ""
}
}
\ No newline at end of file
/*
* Copyright (C) 2022 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.storage.fileio onCreate');
},
onDestroy() {
console.info('ohos.acts.storage.fileio onDestroy');
}
};
{
"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) 2022 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 app from '@system.app'
const injectRef = Object.getPrototypeOf(global) || global
injectRef.regeneratorRuntime = require('@babel/runtime/regenerator')
export default {
data: {
title: ''
},
onInit() {
this.title = this.$t('strings.world');
},
onShow() {
console.info('onShow finish')
},
onReady() {
},
}
/*
* Copyright (c) 2022 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 AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry'
import { Hypium } from '@ohos/hypium'
import testsuite from '../test/List.test'
export default {
onCreate() {
console.info('TestApplication onCreate')
var abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator()
var abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments()
console.info('start run testcase!!!')
Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite)
},
onDestroy() {
console.info("TestApplication onDestroy");
}
};
{
"strings": {
"hello": "Hello",
"world": "World"
},
"Files": {
}
}
\ No newline at end of file
{
"strings": {
"hello": "您好",
"world": "世界"
},
"Files": {
}
}
\ No newline at end of file
.container {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
left: 0px;
top: 0px;
width: 100%;
height: 100%;
}
.title {
font-size: 60px;
text-align: center;
width: 100%;
height: 40%;
margin: 10px;
}
@media screen and (device-type: phone) and (orientation: landscape) {
.title {
font-size: 60px;
}
}
@media screen and (device-type: tablet) and (orientation: landscape) {
.title {
font-size: 100px;
}
}
\ No newline at end of file
<div class="container">
<text class="title">
{{ $t('strings.hello') }} {{ title }}
</text>
</div>
/*
* Copyright (c) 2022 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 {
data: {
title: ""
},
onInit() {
this.title = this.$t('strings.world');
}
}
/*
* Copyright (c) 2022 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 AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry'
function translateParamsToString(parameters) {
const keySet = new Set([
'-s class', '-s notClass', '-s suite', '-s itName',
'-s level', '-s testType', '-s size', '-s timeout',
'-s package', '-s dryRun'
])
let targetParams = '';
for (const key in parameters) {
if (keySet.has(key)) {
targetParams += ' ' + key + ' ' + parameters[key]
}
}
return targetParams.trim()
}
export default {
onPrepare() {
console.info('OpenHarmonyTestRunner OnPrepare')
},
onRun() {
console.log('OpenHarmonyTestRunner onRun run')
var abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments()
var abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator()
var testAbilityName = abilityDelegatorArguments.parameters['-p'] + '.TestAbility'
var cmd = 'aa start -d 0 -a ' + testAbilityName + ' -b ' + abilityDelegatorArguments.bundleName
cmd += ' ' + translateParamsToString(abilityDelegatorArguments.parameters)
var debug = abilityDelegatorArguments.parameters["-D"]
console.info('debug value : '+debug)
if (debug == 'true')
{
cmd += ' -D'
}
console.info('cmd : '+cmd)
abilityDelegator.executeShellCommand(cmd, (err, data) => {
console.info('executeShellCommand : err : ' + JSON.stringify(err));
console.info('executeShellCommand : data : ' + data.stdResult);
console.info('executeShellCommand : data : ' + data.exitCode);
})
}
};
/*
* Copyright (C) 2022 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 fileIO from '@ohos.file.fs';
import featureAbility from '@ohos.ability.featureAbility';
export const FILE_CONTENT = 'hello world';
import {
describe, it, expect
}
from '@ohos/hypium'
export function prepareFile(fpath, content) {
try {
let file = fileIO.openSync(fpath, fileIO.OpenMode.CREATE | fileIO.OpenMode.READ_WRITE)
fileIO.truncateSync(file.fd)
fileIO.writeSync(file.fd, content)
fileio.fsyncSync(file.fd)
fileio.closeSync(file.fd)
return true
}
catch (e) {
console.log('Failed to prepareFile for ' + e)
return false
}
}
export function prepareEmptyFile(fpath) {
try {
let file = fileIO.openSync(fpath, fileIO.OpenMode.CREATE | fileIO.OpenMode.READ_WRITE)
fileio.closeSync(file.fd)
return true
}
catch (e) {
console.log('Failed to prepareFile for ' + e)
return false
}
}
export function fileToReadOnly(fpath) {
try {
let file = fileio.openSync(fpath, fileIO.OpenMode.CREATE)
fileio.fchmodSync(file.fd, 0o444)
fileio.fsyncSync(file.fd)
fileio.closeSync(file.fd)
return true
}
catch (e) {
console.log('Failed to fileToReadOnly for ' + e);
return false
}
}
export function fileToWriteOnly(fpath) {
try {
let file = fileio.openSync(fpath, fileIO.OpenMode.CREATE | fileIO.OpenMode.WRITE_ONLY)
fileio.fchmodSync(file.fd, 0o222)
fileio.fsyncSync(file.fd)
fileio.closeSync(file.fd)
return true
}
catch (e) {
console.log('Failed to fileToWriteOnly ' + e)
return false
}
}
export async function nextFileName(testName) {
let context = featureAbility.getContext();
let data = await context.getCacheDir();
let BASE_PATH = data + '/';
return BASE_PATH + testName + '_' + randomString(testName.length);
}
export async function fileName(testName) {
let context = featureAbility.getContext();
let data = await context.getFilesDir();
let BASE_PATH = data + '/';
return BASE_PATH + testName + '_' + randomString(testName.length);
}
export function randomString(num) {
let len= num;
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;
}
export function forceRemoveDir(path, num) {
for (let i = num; i >= 0; i--) {
if (i < num) {
path = path.replace(`/d${i}`, "");
}
fileio.rmdirSync(path);
}
}
function isIntNum(val) {
return typeof val === 'number' && val % 1 === 0;
}
function isString(str) {
return (typeof str == 'string') && str.constructor == String;
}
function isBoolean(val) {
return typeof val == 'boolean';
}
function isInclude(error, message) {
return error.toString().indexOf(message) != -1;
}
export {
fileio,
fileIO,
isIntNum,
isString,
isBoolean,
isInclude,
describe,
it,
expect
};
\ No newline at end of file
/*
* Copyright (C) 2022 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 fileIOOpen from './members/open.test.js'
import fileIORead from './members/read.test.js'
import fileIOStat from './members/stat.test.js'
import fileIOTruncate from './members/truncate.test.js'
import fileIOWrite from './members/write.test.js'
export default function testsuite() {
fileIOOpen()
fileIORead()
fileIOStat()
fileIOTruncate()
fileIOWrite()
}
/*
* Copyright (C) 2022 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, fileIO, FILE_CONTENT, prepareFile, nextFileName, isIntNum,
describe, it, expect,
} from '../Common';
export default function fileIORead() {
describe('fileIO_fs_read', function () {
/**
* @tc.number SUB_DF_FILEIO_READ_SYNC_0000
* @tc.name fileIO_test_read_sync_000
* @tc.desc Test readSync() interfaces.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it('fileIO_test_read_sync_000', 0, async function () {
let fpath = await nextFileName('fileIO_test_read_sync_000');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let file = fileIO.openSync(fpath, fileIO.OpenMode.READ_ONLY);
expect(isIntNum(file.fd)).assertTrue();
let len = fileIO.readSync(file.fd, new ArrayBuffer(4096));
expect(len == FILE_CONTENT.length).assertTrue();
fileio.closeSync(file.fd);
fileio.unlinkSync(fpath);
} catch (e) {
console.log('fileIO_test_read_sync_000 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_READ_SYNC_0100
* @tc.name fileIO_test_read_sync_001
* @tc.desc Test readSync() interfaces.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it('fileIO_test_read_sync_001', 0, async function () {
let fpath = await nextFileName('fileIO_test_read_sync_001');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let file = fileIO.openSync(fpath, fileIO.OpenMode.READ_ONLY);
expect(isIntNum(file.fd)).assertTrue();
let len = fileIO.readSync(file.fd, new ArrayBuffer(4096), {
length: 1,
});
expect(len == 1).assertTrue();
fileio.closeSync(file.fd);
fileio.unlinkSync(fpath);
} catch (e) {
console.log('fileIO_test_read_sync_001 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_READ_SYNC_0200
* @tc.name fileIO_test_read_sync_002
* @tc.desc Test readSync() interfaces.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it('fileIO_test_read_sync_002', 0, async function () {
let fpath = await nextFileName('fileIO_test_read_sync_002');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let file = fileIO.openSync(fpath, fileIO.OpenMode.READ_ONLY);
expect(isIntNum(file.fd)).assertTrue();
let len = fileIO.readSync(file.fd, new ArrayBuffer(4096), {
offset: 1,
});
expect(len == FILE_CONTENT.length - 1).assertTrue();
fileio.closeSync(file.fd);
fileio.unlinkSync(fpath);
} catch (e) {
console.log('fileIO_test_read_sync_002 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_READ_SYNC_0300
* @tc.name fileIO_test_read_sync_003
* @tc.desc Test readSync() interfaces.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it('fileIO_test_read_sync_003', 0, async function () {
let fpath = await nextFileName('fileIO_test_read_sync_003');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
let file;
const invalidLength = 9999;
try {
file = fileIO.openSync(fpath, fileIO.OpenMode.READ_ONLY);
expect(isIntNum(file.fd)).assertTrue();
fileIO.readSync(file.fd, new ArrayBuffer(4096), {length: invalidLength});
expect(false).assertTrue();
} catch (e) {
console.log('fileIO_test_read_sync_003 has failed for ' + e.message + ', code: ' + e.code);
expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue();
fileio.closeSync(file.fd);
fileio.unlinkSync(fpath);
}
});
/**
* @tc.number SUB_DF_FILEIO_READ_SYNC_0400
* @tc.name fileIO_test_read_sync_004
* @tc.desc Test readSync() interfaces.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it('fileIO_test_read_sync_004', 0, async function () {
try {
fileIO.readSync(-1, new ArrayBuffer(4096));
expect(false).assertTrue();
} catch (e) {
console.log('fileIO_test_read_sync_004 has failed for ' + e.message + ', code: ' + e.code);
expect(e.code == 13900008 && e.message == 'Bad file descriptor').assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_READ_SYNC_0500
* @tc.name fileIO_test_read_sync_005
* @tc.desc Test readSync() interfaces.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it('fileIO_test_read_sync_005', 0, async function () {
let fpath = await nextFileName('fileIO_test_read_sync_005');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let file = fileIO.openSync(fpath, fileIO.OpenMode.READ_ONLY);
expect(isIntNum(file.fd)).assertTrue();
let invalidPos = FILE_CONTENT.length + 1;
let len = fileIO.readSync(file.fd, new ArrayBuffer(4096), {
offset: invalidPos,
});
expect(len == 0).assertTrue();
fileio.closeSync(file.fd);
fileio.unlinkSync(fpath);
} catch (e) {
console.log('fileIO_test_read_sync_005 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_READ_ASYNC_0000
* @tc.name fileIO_test_read_async_000
* @tc.desc Test read() interfaces.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it('fileIO_test_read_async_000', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_read_async_000');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let file = fileIO.openSync(fpath, fileIO.OpenMode.READ_ONLY);
expect(isIntNum(file.fd)).assertTrue();
let res = await fileIO.read(file.fd, new ArrayBuffer(4096));
expect(res == FILE_CONTENT.length).assertTrue();
fileio.closeSync(file.fd);
fileio.unlinkSync(fpath);
done();
} catch (e) {
console.log('fileIO_test_read_async_000 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_READ_ASYNC_0100
* @tc.name fileIO_test_read_async_001
* @tc.desc Test read() interfaces.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it('fileIO_test_read_async_001', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_read_async_001');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let file = fileIO.openSync(fpath, fileIO.OpenMode.READ_ONLY);
expect(isIntNum(file.fd)).assertTrue();
fileIO.read(file.fd, new ArrayBuffer(4096), async function (err, readlen) {
expect(readlen == FILE_CONTENT.length).assertTrue();
fileio.closeSync(file.fd);
fileio.unlinkSync(fpath);
done();
});
} catch (e) {
console.log('fileIO_test_read_async_001 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_READ_ASYNC_0200
* @tc.name fileIO_test_read_async_002
* @tc.desc Test read() interfaces.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it('fileIO_test_read_async_002', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_read_async_002');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let file = fileIO.openSync(fpath, fileIO.OpenMode.READ_ONLY);
expect(isIntNum(file.fd)).assertTrue();
let readlen = await fileIO.read(file.fd, new ArrayBuffer(4096));
expect(readlen == FILE_CONTENT.length).assertTrue();
fileio.closeSync(file.fd);
fileio.unlinkSync(fpath);
done();
} catch (e) {
console.log('fileIO_test_read_async_002 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_READ_ASYNC_0300
* @tc.name fileIO_test_read_async_003
* @tc.desc Test read() interfaces.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it('fileIO_test_read_async_003', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_read_async_003');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let file = fileIO.openSync(fpath, fileIO.OpenMode.READ_ONLY);
expect(isIntNum(file.fd)).assertTrue();
let readlen = await fileIO.read(file.fd, new ArrayBuffer(4096), {
offset: 1,
});
expect(readlen == FILE_CONTENT.length - 1).assertTrue();
fileio.closeSync(file.fd);
fileio.unlinkSync(fpath);
done();
} catch (e) {
console.log('fileIO_test_read_async_003 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_READ_ASYNC_0400
* @tc.name fileIO_test_read_async_004
* @tc.desc Test read() interface.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it('fileIO_test_read_async_004', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_read_async_004');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let file = fileIO.openSync(fpath, fileIO.OpenMode.READ_ONLY);
expect(isIntNum(file.fd)).assertTrue();
let readlen = await fileIO.read(file.fd, new ArrayBuffer(4096), {
length: 3,
});
expect(readlen == 3).assertTrue();
fileio.closeSync(file.fd);
fileio.unlinkSync(fpath);
done();
} catch (e) {
console.log('fileIO_test_read_async_004 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_READ_ASYNC_0500
* @tc.name fileIO_test_read_async_005
* @tc.desc Test read() interfaces.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it('fileIO_test_read_async_005', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_read_async_005');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let file = fileIO.openSync(fpath, fileIO.OpenMode.READ_ONLY);
expect(isIntNum(file.fd)).assertTrue();
let len = await fileIO.read(file.fd, new ArrayBuffer(4096), {
offset: FILE_CONTENT.length + 1,
});
expect(isIntNum(len)).assertTrue();
fileio.closeSync(file.fd);
fileio.unlinkSync(fpath);
done();
} catch (e) {
console.log('fileIO_test_read_async_005 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_READ_ASYNC_0600
* @tc.name fileIO_test_read_async_006
* @tc.desc Test read() interfaces.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it('fileIO_test_read_async_006', 0, async function (done) {
try {
await fileIO.read(-1, new ArrayBuffer(4096));
expect(false).assertTrue();
} catch (e) {
console.log('fileIO_test_read_async_006 has failed for ' + e.message + ', code: ' + e.code);
expect(e.code == 13900008 && e.message == 'Bad file descriptor').assertTrue();
done();
}
});
});
}
/*
* Copyright (C) 2022 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, fileIO, FILE_CONTENT, prepareFile, nextFileName, isIntNum,
describe, it, expect,
} from '../Common';
export default function fileIOTruncate() {
describe('fileIO_fs_truncate', function () {
/**
* @tc.number SUB_DF_FILEIO_TRUNCATE_ASYNC_0000
* @tc.name fileIO_truncate_async_000
* @tc.desc Test the truncate() interface that receives the fpath parameter.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it('fileIO_truncate_async_000', 0, async function (done) {
let fpath = await nextFileName('fileIO_truncate_async_000');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
let truncateLen = 5;
try {
await fileIO.truncate(fpath, truncateLen);
let file = fileIO.openSync(fpath, fileIO.OpenMode.READ_WRITE);
expect(isIntNum(file.fd)).assertTrue();
let len = fileIO.readSync(file.fd, new ArrayBuffer(4096));
expect(len == truncateLen).assertTrue();
fileio.closeSync(file.fd);
fileio.unlinkSync(fpath);
done();
} catch (e) {
console.info('fileIO_truncate_async_000 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_TRUNCATE_ASYNC_0100
* @tc.name fileIO_truncate_async_001
* @tc.desc Test the truncate() interface that receives the fd parameter.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it('fileIO_truncate_async_001', 0, async function (done) {
let fpath = await nextFileName('fileIO_truncate_async_001');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
let file;
let truncateLen = 5;
try {
file = fileIO.openSync(fpath, fileIO.OpenMode.READ_WRITE);
expect(isIntNum(file.fd)).assertTrue();
fileIO.truncate(file.fd, truncateLen, function (err) {
let len = fileIO.readSync(file.fd, new ArrayBuffer(4096));
expect(len == truncateLen).assertTrue();
fileio.closeSync(file.fd);
fileio.unlinkSync(fpath);
done();
})
} catch (e) {
console.log('fileIO_truncate_async_001 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_TRUNCATE_ASYNC_0200
* @tc.name fileIO_truncate_async_002
* @tc.desc Test the truncate() interface that receives the fpath parameter.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it('fileIO_truncate_async_002', 0, async function (done) {
let fpath = await nextFileName('fileIO_truncate_async_002');
expect(prepareFile(fpath, 'truncate')).assertTrue();
let truncateLen = 2;
try {
fileIO
.truncate(fpath, truncateLen)
.then(function (err) {
expect(err == null).assertTrue();
let file = fileIO.openSync(fpath, fileIO.OpenMode.READ_WRITE);
expect(isIntNum(file.fd)).assertTrue();
let len = fileIO.readSync(file.fd, new ArrayBuffer(4096));
expect(len == truncateLen).assertTrue();
fileio.closeSync(file.fd);
fileio.unlinkSync(fpath);
done();
})
.catch(function (e) {
console.log('catch ' + e.message + ', code: ' + e.code);
});
} catch(e) {
console.log('fileIO_truncate_async_002 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_TRUNCATE_ASYNC_0300
* @tc.name fileIO_truncate_async_003
* @tc.desc Test the truncate() interface that receives the fd parameter.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it('fileIO_truncate_async_003', 0, async function (done) {
let fpath = await nextFileName('fileIO_truncate_async_003');
expect(prepareFile(fpath, 'truncate')).assertTrue();
let file;
let truncateLen = 2;
try {
file = fileIO.openSync(fpath, fileIO.OpenMode.READ_WRITE);
expect(isIntNum(file.fd)).assertTrue();
fileIO.truncate(file.fd, truncateLen)
.then(function (err) {
expect(err == null).assertTrue();
let len = fileIO.readSync(file.fd, new ArrayBuffer(4096));
expect(len == truncateLen).assertTrue();
fileio.closeSync(file.fd);
fileio.unlinkSync(fpath);
done();
})
.catch(function (e) {
console.log('catch ' + e.message + ', code: ' + e.code);
})
} catch(e) {
console.log('fileIO_truncate_async_003 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_TRUNCATE_ASYNC_0400
* @tc.name fileIO_truncate_async_004
* @tc.desc Test the truncate() interface that receives the fpath parameter.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it('fileIO_truncate_async_004', 0, async function (done) {
let fpath = await nextFileName('fileIO_truncate_async_004');
let truncateLen = 2;
try {
fileIO.truncate(fpath, truncateLen, function (err) {
done();
});
} catch (e) {
console.log('fileIO_truncate_async_004 has failed for ' + e.message + ', code: ' + e.code);
expect(!!e).assertTrue();
expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue();
done();
}
});
/**
* @tc.number SUB_DF_FILEIO_TRUNCATE_SYNC_0000
* @tc.name fileIO_test_truncate_sync_000
* @tc.desc Test the truncateSync() interface that receives the fpath parameter.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it('fileIO_test_truncate_sync_000', 0, async function () {
let fpath = await nextFileName('fileIO_test_truncate_sync_000');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
fileIO.truncateSync(fpath);
expect(fileIO.statSync(fpath).size == 0).assertTrue();
fileio.unlinkSync(fpath);
} catch (e) {
console.log('fileIO_test_truncate_sync_000 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_TRUNCATE_SYNC_0100
* @tc.name fileIO_test_truncate_sync_001
* @tc.desc Test the truncateSync() interface that receives the fd parameter.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it('fileIO_test_truncate_sync_001', 0, async function () {
let fpath = await nextFileName('fileIO_test_truncate_sync_001');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
let file;
let truncateLen = 5;
try {
file = fileIO.openSync(fpath, fileIO.OpenMode.READ_WRITE);
expect(isIntNum(file.fd)).assertTrue();
fileIO.truncateSync(file.fd, truncateLen);
let len = fileIO.readSync(file.fd, new ArrayBuffer(4096));
expect(len == truncateLen).assertTrue();
fileio.closeSync(file.fd);
fileio.unlinkSync(fpath);
} catch (e) {
console.log('fileIO_test_truncate_sync_001 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_TRUNCATE_SYNC_0200
* @tc.name fileIO_test_truncate_sync_002
* @tc.desc Test the truncateSync() interface that receives the fpath parameter.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it('fileIO_test_truncate_sync_002', 0, async function () {
let fpath = await nextFileName('fileIO_test_truncate_sync_002');
try {
let stat = fileIO.truncateSync(fpath);
console.info('fileIO_test_truncate_sync_002 = ' + stat);
expect(false).assertTrue();
} catch (e) {
expect(e.code == 13900002 && e.message == 'No such file or directory').assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_TRUNCATE_SYNC_0300
* @tc.name fileIO_test_truncate_sync_003
* @tc.desc Test the truncateSync() interface that receives the fd parameter.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it('fileIO_test_truncate_sync_003', 0, async function () {
let fpath = await nextFileName('fileIO_test_truncate_sync_003');
expect(prepareFile(fpath, 'truncate')).assertTrue();
let file;
let truncateLen = 2;
try {
file = fileIO.openSync(fpath, fileIO.OpenMode.READ_WRITE);
expect(isIntNum(file.fd)).assertTrue();
fileIO.truncateSync(file.fd, truncateLen);
let len = fileIO.readSync(file.fd, new ArrayBuffer(4096));
expect(len == truncateLen).assertTrue();
fileio.closeSync(file.fd);
fileio.unlinkSync(fpath);
} catch (e) {
console.log('fileIO_test_truncate_sync_003 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_TRUNCATE_SYNC_0400
* @tc.name fileIO_test_truncate_sync_004
* @tc.desc Test truncateSync() interfaces.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it('fileIO_test_truncate_sync_004', 0, function () {
try {
let stat = fileIO.truncateSync();
console.info('fileIO_test_truncate_sync_004 = ' + stat);
expect(false).assertTrue();
} catch (e) {
expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_TRUNCATE_SYNC_0500
* @tc.name fileIO_test_truncate_sync_005
* @tc.desc Test truncateSync() interfaces.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it('fileIO_test_truncate_sync_005', 0, async function () {
let fpath = await nextFileName('fileIO_test_truncate_sync_005');
let truncateLen = 2;
try {
fileIO.truncateSync(fpath, truncateLen);
} catch (e) {
console.log('fileIO_test_truncate_sync_005 has failed for ' + e.message + ', code: ' + e.code);
expect(!!e).assertTrue();
}
});
});
}
/*
* Copyright (C) 2022 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, fileIO, FILE_CONTENT, prepareFile, nextFileName, isIntNum,
describe, it, expect,
} from '../Common';
export default function fileIOWrite() {
describe('fileIO_fs_write', function () {
/**
* @tc.number SUB_DF_FILEIO_WRITE_SYNC_0000
* @tc.name fileIO_test_write_sync_000
* @tc.desc Test writeSync() interfaces.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it('fileIO_test_write_sync_000', 0, async function () {
let fpath = await nextFileName('fileIO_test_write_sync_000');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let file = fileIO.openSync(fpath, fileIO.OpenMode.WRITE_ONLY);
expect(isIntNum(file.fd)).assertTrue();
expect(fileIO.writeSync(file.fd, FILE_CONTENT) == FILE_CONTENT.length).assertTrue();
fileio.closeSync(file.fd);
fileio.unlinkSync(fpath);
} catch (e) {
console.log('fileIO_test_write_sync_000 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_WRITE_SYNC_0100
* @tc.name fileIO_test_write_sync_001
* @tc.desc Test writeSync() interfaces.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it('fileIO_test_write_sync_001', 0, async function () {
let fpath = await nextFileName('fileIO_test_write_sync_001');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let file = fileIO.openSync(fpath, fileIO.OpenMode.WRITE_ONLY);
expect(isIntNum(file.fd)).assertTrue();
expect(
fileIO.writeSync(file.fd, FILE_CONTENT, {
encoding: 'utf-8',
})
== FILE_CONTENT.length).assertTrue();
fileio.closeSync(file.fd);
fileio.unlinkSync(fpath);
} catch (e) {
console.log('fileIO_test_write_sync_001 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_WRITE_SYNC_0200
* @tc.name fileIO_test_write_sync_002
* @tc.desc Test writeSync() interfaces.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it('fileIO_test_write_sync_002', 0, async function () {
let fpath = await nextFileName('fileIO_test_write_sync_002');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let file = fileIO.openSync(fpath, fileIO.OpenMode.WRITE_ONLY);
expect(isIntNum(file.fd)).assertTrue();
expect(
fileIO.writeSync(file.fd, FILE_CONTENT, {
length: FILE_CONTENT.length - 1,
})
== FILE_CONTENT.length - 1).assertTrue();
fileio.closeSync(file.fd);
fileio.unlinkSync(fpath);
} catch (e) {
console.log('fileIO_test_write_sync_002 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_WRITE_SYNC_0300
* @tc.name fileIO_test_write_sync_003
* @tc.desc Test writeSync() interfaces.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it('fileIO_test_write_sync_003', 0, async function () {
let fpath = await nextFileName('fileIO_test_write_sync_003');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let file = fileIO.openSync(fpath, fileIO.OpenMode.WRITE_ONLY);
expect(isIntNum(file.fd)).assertTrue();
expect(
fileIO.writeSync(file.fd, FILE_CONTENT, {
length: 1,
})
== 1).assertTrue();
fileio.closeSync(file.fd);
fileio.unlinkSync(fpath);
} catch (e) {
console.log('fileIO_test_write_sync_003 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_WRITE_SYNC_0400
* @tc.name fileIO_test_write_sync_004
* @tc.desc Test writeSync() interfaces.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it('fileIO_test_write_sync_004', 0, async function () {
let fpath = await nextFileName('fileIO_test_write_sync_004');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
const invalidLength = 9999;
let file;
try {
file = fileIO.openSync(fpath, fileIO.OpenMode.WRITE_ONLY);
expect(isIntNum(file.fd)).assertTrue();
fileIO.writeSync(file.fd, FILE_CONTENT, {
length: invalidLength,
})
expect(false).assertTrue();
} catch (e) {
fileio.closeSync(file.fd);
fileio.unlinkSync(fpath);
console.info('fileIO_test_write_sync_004 has failed for ' + e.message + ', code: ' + e.code);
expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_WRITE_SYNC_0500
* @tc.name fileIO_test_write_sync_005
* @tc.desc Test writeSync() interfaces.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it('fileIO_test_write_sync_005', 0, function () {
try {
fileIO.writeSync(-1, FILE_CONTENT);
expect(false).assertTrue();
} catch (e) {
console.log('fileIO_test_write_sync_005 has failed for ' + e.message + ', code: ' + e.code);
expect(e.code == 13900008 && e.message == 'Bad file descriptor').assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_WRITE_SYNC_0600
* @tc.name fileIO_test_write_sync_006
* @tc.desc Test writeSync() interfaces.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it('fileIO_test_write_sync_006', 0, async function () {
let fpath = await nextFileName('fileIO_test_write_sync_006');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let file = fileIO.openSync(fpath, fileIO.OpenMode.WRITE_ONLY);
expect(isIntNum(file.fd)).assertTrue();
let writeNum = fileIO.writeSync(file.fd, new ArrayBuffer(4096));
expect(writeNum == 4096).assertTrue();
fileio.closeSync(file.fd);
fileio.unlinkSync(fpath);
} catch (e) {
console.log('fileIO_test_write_sync_006 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_WRITE_ASYNC_0000
* @tc.name fileIO_test_write_async_000
* @tc.desc Test write() interfaces.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it('fileIO_write_async_000', 0, async function (done) {
let fpath = await nextFileName('fileIO_write_async_000');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let file = fileIO.openSync(fpath, fileIO.OpenMode.WRITE_ONLY);
expect(isIntNum(file.fd)).assertTrue();
expect(await fileIO.write(file.fd, FILE_CONTENT) == FILE_CONTENT.length).assertTrue();
fileio.closeSync(file.fd);
fileio.unlinkSync(fpath);
done();
} catch (e) {
console.log('fileIO_write_async_000 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_WRITE_ASYNC_0100
* @tc.name fileIO_test_write_async_001
* @tc.desc Test write() interfaces.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it('fileIO_test_write_async_001', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_write_async_001');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let file = fileIO.openSync(fpath, fileIO.OpenMode.WRITE_ONLY);
expect(isIntNum(file.fd)).assertTrue();
let writeNum = await fileIO.write(file.fd, FILE_CONTENT, {
length: 3,
});
expect(writeNum == 3).assertTrue();
fileio.closeSync(file.fd);
fileio.unlinkSync(fpath);
done();
} catch (e) {
console.log('fileIO_test_write_async_001 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_WRITE_ASYNC_0200
* @tc.name fileIO_test_write_async_002
* @tc.desc Test write() interfaces.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it('fileIO_test_write_async_002', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_write_async_002');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let file = fileIO.openSync(fpath, fileIO.OpenMode.WRITE_ONLY);
expect(isIntNum(file.fd)).assertTrue();
let writeNum = await fileIO.write(file.fd, FILE_CONTENT, {
length: 3,
offset: 5,
});
expect(writeNum == 3).assertTrue();
fileio.closeSync(file.fd);
fileio.unlinkSync(fpath);
done();
} catch (e) {
console.log('fileIO_test_write_async_002 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_WRITE_ASYNC_0300
* @tc.name fileIO_test_write_async_003
* @tc.desc Test write() interfaces.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it('fileIO_test_write_async_003', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_write_async_003');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let file = fileIO.openSync(fpath, fileIO.OpenMode.WRITE_ONLY);
expect(isIntNum(file.fd)).assertTrue();
let writeNum = await fileIO.write(file.fd, FILE_CONTENT, {
length: 4,
offset: 5,
encoding: 'utf-8',
});
expect(writeNum == 4).assertTrue();
fileio.closeSync(file.fd);
fileio.unlinkSync(fpath);
done();
} catch (e) {
console.log('fileIO_test_write_async_003 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_WRITE_ASYNC_0400
* @tc.name fileIO_test_write_async_004
* @tc.desc Test write() interfaces.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it('fileIO_test_write_async_004', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_write_async_004');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let file = fileIO.openSync(fpath, fileIO.OpenMode.WRITE_ONLY);
expect(isIntNum(file.fd)).assertTrue();
await fileIO.write(file.fd, new ArrayBuffer(4096), function (
error,
bytesWritten
) {
expect(bytesWritten == 4096).assertTrue();
fileio.closeSync(file.fd);
fileio.unlinkSync(fpath);
}
);
done();
} catch (e) {
console.log('fileIO_test_write_async_004 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_WRITE_ASYNC_0500
* @tc.name fileIO_test_write_async_005
* @tc.desc Test write() interfaces.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it('fileIO_test_write_async_005', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_write_async_005');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let file = fileIO.openSync(fpath, fileIO.OpenMode.WRITE_ONLY);
expect(isIntNum(file.fd)).assertTrue();
await fileIO.write(
file.fd,
FILE_CONTENT,
{
length: 5,
}, function (error, bytesWritten) {
expect(bytesWritten == 5).assertTrue();
fileio.closeSync(file.fd);
fileio.unlinkSync(fpath);
done();
}
);
} catch (e) {
console.log('fileIO_test_write_async_005 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_WRITE_ASYNC_0600
* @tc.name fileIO_test_write_async_006
* @tc.desc Test write() interfaces.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it('fileIO_test_write_async_006', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_write_async_006');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let file = fileIO.openSync(fpath, fileIO.OpenMode.WRITE_ONLY);
expect(isIntNum(file.fd)).assertTrue();
await fileIO.write(
file.fd,
FILE_CONTENT,
{
length: 5,
offset: 5,
}, function (error, bytesWritten) {
expect(bytesWritten == 5).assertTrue();
fileio.closeSync(file.fd);
fileio.unlinkSync(fpath);
done();
}
);
} catch (e) {
console.log('fileIO_test_write_async_006 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_WRITE_ASYNC_0700
* @tc.name fileIO_test_write_async_007
* @tc.desc Test write() interfaces.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it('fileIO_test_write_async_007', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_write_async_007');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let file = fileIO.openSync(fpath, fileIO.OpenMode.WRITE_ONLY);
expect(isIntNum(file.fd)).assertTrue();
await fileIO.write(
file.fd,
FILE_CONTENT,
{
length: 5,
offset: 5,
encoding: 'utf-8',
}, function (error, bytesWritten) {
expect(bytesWritten == 5).assertTrue();
fileio.closeSync(file.fd);
fileio.unlinkSync(fpath);
done();
}
);
} catch (e) {
console.log('fileIO_test_write_async_007 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
});
}
{
"string": [
{
"name": "app_name",
"value": "storagefilefsjstest"
},
{
"name": "mainability_description",
"value": "JS_Phone_Empty Feature Ability"
},
{
"name": "MainAbility_desc",
"value": "description"
},
{
"name": "MainAbility_label",
"value": "label"
},
{
"name": "TestAbility_desc",
"value": "description"
},
{
"name": "TestAbility_label",
"value": "label"
}
]
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册