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

!448 添加File和FileIO接口的新用例,并整改部分旧用例

Merge pull request !448 from XTStarry/master
......@@ -15,6 +15,14 @@ import("//test/xts/tools/build/suite.gni")
group("storage") {
testonly = true
if (is_standard_system) {
deps = [ "storagefileiojstest:storagefileio_js_test" ]
deps = [
"storagefileconcurrentjstest:storagefileconcurrent_js_test",
"storagefileioerrorjstest:storagefileioerror_js_test",
"storagefileiojstest:storagefileio_js_test",
"storagefileioperformancejstest:storagefileioperformance_js_test",
"storagefileioreliabilityjstest:storagefileioreliability_js_test",
"storagefileiostabilityjstest:storagefileiostability_js_test",
"storagefilestabilityjstest:storagefilestability_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("storagefileioerror_js_test") {
test_hap_name = "storagefileioerrorjstest"
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": [
"storagefileioerrorjstest.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
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} from 'deccjsunit/index'
export default {
data: {
title: ''
},
onInit() {
this.title = this.$t('strings.world');
},
onShow() {
console.info('onShow finish')
const core = Core.getInstance()
core.init()
const configService = core.getDefaultService('config')
configService.setConfig(this)
require('../../../test/List.test')
core.execute()
},
onReady() {
},
}
\ No newline at end of file
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the 'License');
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an 'AS IS' BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import fileio from '@system.fileio'
export const FILE_CONTENT = 'hello world'
export function prepareFile(fpath, content) {
try {
let fd = fileio.openSync(fpath, 0o102, 0o666)
fileio.ftruncateSync(fd)
fileio.writeSync(fd, content)
fileio.fsyncSync(fd)
fileio.closeSync(fd)
return true
}
catch (e) {
console.log('Failed to prepareFile for ' + e)
return false
}
}
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
}
}
export function appName(testName) {
const BASE_PATH = '/data/accounts/account_0/appdata/ohos.acts.stroage.fileio/'
return BASE_PATH + testName
}
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 cacheFileName(testName) {
const BASE_PATH = '/data/accounts/account_0/appdata/ohos.acts.stroage.fileio/files/cache/'
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 differentCacheName(testName) {
const BASE_PATH = '/data/accounts/account_0/ohos.acts.distributeddatamgr.distributedfile/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('file:' + fpath)
console.log('file lenth:' + 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('file:' + fpath)
console.log('status:exist')
return true
}
catch (e) {
console.log('file:' + fpath)
console.log('status:non-existen')
return false
}
}
export function sleep(n) {
var start = new Date().getTime();
while (true) {
if (new Date().getTime() - start > n) {
break;
}
}
}
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;
}
/*
* 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,
it,
expect
}
from 'deccjsunit/index'
import {
FILE_CONTENT,
prepareFile,
fileName,
randomString,
}
from './Common'
describe('FileError', function () {
/**
* @tc.number SUB_STORAGE_File_test_error_0000
* @tc.name File_test_error_000
* @tc.desc Function of API, Move files when disk space is full.
* Create the file (file_test_error) in advance and give 777 permission,
* path:/data/accounts/account_0/appdata/ohos.acts.stroage.fileio/files/file_test_error
*/
it('File_test_error_000', 0, async function (done) {
file.move({
srcUri: 'internal://app/file_test_error',
dstUri: 'internal://cache/file_test_error',
success: function (uri) {
console.log('file_test_error_000 pass, uri:' + uri);
expect(null).assertFail();
},
fail: function (data, code) {
console.log('file_test_error_000 call move fail, code: ' + code + ', data: ' + data);
done();
},
});
});
/**
* @tc.number SUB_STORAGE_File_test_error_0100
* @tc.name File_test_error_001
* @tc.desc Function of API, Copy files when disk space is full.
* Create the file (file_test_error) in advance and give 777 permission,
* path:/data/accounts/account_0/appdata/ohos.acts.stroage.fileio/files/file_test_error
*/
it('File_test_error_001', 0, async function (done) {
file.copy({
srcUri: 'internal://app/file_test_error',
dstUri: 'internal://cache/file_test_error',
success: function (uri) {
console.log('file_test_error_001 pass, uri:' + uri);
expect(null).assertFail();
},
fail: function (data, code) {
console.log('file_test_error_001 call copy fail, code: ' + code + ', data: ' + data);
done();
},
});
});
/**
* @tc.number SUB_STORAGE_File_test_error_0200
* @tc.name File_test_error_002
* @tc.desc Function of API, Write files when disk space is full.
*/
it('File_test_error_002', 0, async function (done) {
file.writeText({
uri: 'internal://app/file_test_error',
text: FILE_CONTENT,
success: function () {
console.log('file_test_error_002 call writeText success.');
expect(null).assertFail();
},
fail: function (data, code) {
console.log('file_test_error_002 call writeText fail, code: ' + code + ', data: ' + data);
done();
},
});
});
/**
* @tc.number SUB_STORAGE_File_test_error_0300
* @tc.name File_test_error_003
* @tc.desc Function of API, Write files when disk space is full.
*/
it('File_test_error_003', 0, async function (done) {
let buf = new Uint8Array([48, 49, 50, 51, 65, 66, 67, 68, 32, 33]);
file.writeArrayBuffer({
uri: 'internal://app/file_test_error',
buffer: buf,
success: function () {
console.log('file_test_error_003 call writeArrayBuffer success.');
expect(null).assertFail();
},
fail: function (data, code) {
console.log('file_test_error_003 call writeArrayBuffer fail, code: ' + code + ', data: ' + data);
done();
},
});
});
/**
* @tc.number SUB_STORAGE_File_test_error_0400
* @tc.name File_test_error_004
* @tc.desc Function of API, When inode is full, verify the folder creation function
*/
it('File_test_error_004', 0, async function (done) {
file.mkdir({
uri: 'internal://app/file_test_error004d',
success: function () {
console.log('file_test_error_004 call mkdir success.');
expect(null).assertFail();
},
fail: function (data, code) {
console.log('file_test_error_004 call mkdir fail, code: ' + code + ', data: ' + data);
done();
},
});
});
/**
* @tc.number SUB_STORAGE_File_test_error_0500
* @tc.name File_test_error_005
* @tc.desc Function of API, Prerequisites create file 200M,When ram is filled to
* the remaining 100m, verify the function of reading 200m files
*/
it('File_test_error_005', 0, async function (done) {
file.readText({
uri: 'internal://app/file_test_error_005',
success: function (data) {
console.log('file_test_error_005 pass, Content:' + data.text);
done();
},
fail: function (data, code) {
console.log('file_test_error_005 call readText fail, code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
});
/**
* @tc.number SUB_STORAGE_File_test_error_0600
* @tc.name File_test_error_006
* @tc.desc Function of API, Prerequisites create file 200M,When ram is filled to
* the remaining 100m, verify the function of reading 200m files
*/
it('File_test_error_006', 0, async function (done) {
file.readArrayBuffer({
uri: 'internal://app/file_test_error_006',
success: function (data) {
console.log('file_test_error_006 pass, Content:' + data.buffer);
done();
},
fail: function (data, code) {
console.log('file_test_error_006 call readArrayBuffer fail, code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
});
/**
* @tc.number SUB_STORAGE_File_test_error_0700
* @tc.name File_test_error_007
* @tc.desc Function of API, delete file
*/
it('File_test_error_007', 0, async function (done) {
let fpath = fileName('file_test_error_007');
expect(prepareFile(fpath, FILE_CONTENT) !== null).assertTrue();
file.rmdir({
uri: 'internal://app/file_test_error_007',
recursive: true,
success: function () {
console.log('file_test_error_007 call rmdir success.');
done();
},
fail: function (data, code) {
console.log('file_test_error_007 call rmdir fail, code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
});
/**
* @tc.number SUB_STORAGE_File_test_error_0800
* @tc.name File_test_error_008
* @tc.desc Function of API, Try to delete the folder while the file in the folder is reading and writing
*/
it('File_test_error_008', 0, async function (done) {
file.writeText({
uri: 'internal://app/file_test_error_008',
text: randomString(4096),
success: function () {
console.log('file_test_error_008 call mkdir success.');
done();
},
fail: function (data, code) {
console.log('file_test_error_008 call mkdir fail, code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
file.rmdir({
uri: 'internal://app/file_test_error_008',
success: function () {
console.log('file_test_error_008 call rmdir success.');
expect(null).assertFail();
},
fail: function (data, code) {
console.log('file_test_error_008 call rmdir fail, code: ' + code + ', data: ' + data);
done();
},
});
});
/**
* @tc.number SUB_STORAGE_File_test_error_0900
* @tc.name File_test_error_009
* @tc.desc Function of API, Delete non empty folder
*/
it('File_test_error_009', 0, async function (done) {
let dpath = fileName('file_test_error_009') + 'd';
let fpath = dpath + '/file_test_error_009';
expect(fileio.mkdirSync(dpath) !== null).assertTrue();
expect(prepareFile(fpath, FILE_CONTENT) !== null).assertTrue();
file.rmdir({
uri: 'internal://app/file_test_error_009d',
recursive: true,
success: function () {
console.log('file_test_error_009 call rmdir success.');
done();
},
fail: function (data, code) {
console.log('file_test_error_009 call rmdir fail, code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
});
/**
* @tc.number SUB_STORAGE_File_test_error_1000
* @tc.name File_test_error_010
* @tc.desc Function of API, Delete non empty folder
*/
it('File_test_error_010', 0, async function (done) {
let dpath = fileName('file_test_error_010') + 'd';
let fpath = dpath + '/file_test_error_010';
expect(fileio.mkdirSync(dpath) !== null).assertTrue();
expect(prepareFile(fpath, FILE_CONTENT) !== null).assertTrue();
file.rmdir({
uri: 'internal://app/file_test_error_010d',
recursive: false,
success: function () {
console.log('file_test_error_010 call rmdir success.');
expect(null).assertFail();
},
fail: function (data, code) {
console.log('file_test_error_010 call rmdir fail, code: ' + code + ', data: ' + data);
done();
},
});
});
/**
* @tc.number SUB_STORAGE_File_test_error_1100
* @tc.name File_test_error_011
* @tc.desc Function of API, Unsupported same encoding format
*/
it('File_test_error_011', 0, async function (done) {
file.writeText({
uri: 'internal://app/file_test_error_011',
text: 'hello',
encoding: 'gbk',
success: function () {
console.log('file_test_error_011 call writeText success.');
expect(null).assertFail();
},
fail: function (data, code) {
console.log('file_test_error_011 call writeText fail, code: ' + code + ', data: ' + data);
done();
},
});
});
/**
* @tc.number SUB_STORAGE_File_test_error_1200
* @tc.name File_test_error_012
* @tc.desc Function of API, Unsupported same encoding format
*/
it('File_test_error_012', 0, async function (done) {
file.writeText({
uri: 'internal://app/file_test_error_012',
text: 'Text that just for test.',
encoding: 'Utf-8',
success: function () {
console.log('file_test_error_012 call writeText success.');
done();
},
fail: function (data, code) {
console.log('file_test_error_012 call writeText fail, code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
file.readText({
uri: 'internal://app/file_test_error_012',
encoding: 'GBK',
success: function (data) {
console.log('file_test_error_012 call readText success.' + data.text);
expect(null).assertFail();
},
fail: function (data, code) {
console.log('file_test_error_012 call readText fail, code: ' + code + ', data: ' + data);
file.delete({
uri: 'internal://app/file_test_error_012',
success: function () {
console.log('file_test_error_012 call delete success');
done();
},
fail: function (data, code) {
console.log('file_test_error_012 call delete fail, code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
},
});
});
});
/*
* 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,
it,
expect
}
from 'deccjsunit/index'
import {
FILE_CONTENT,
prepareFile,
fileName,
nextFileName,
appName,
randomString,
}
from './Common'
describe('FileIOError', function () {
/**
* @tc.number SUB_STORAGE_FileIo_test_error_0000
* @tc.name FileIo_test_error_000
* @tc.desc Function of API, Copy files when disk space is full
* Create the file (fileio_test_error) in advance and give 777 permission,
* path:/data/accounts/account_0/appdata/ohos.acts.stroage.fileio/cache/fileio_test_error
*/
it('FileIo_test_error_000', 0, function () {
let fpath = nextFileName('fileio_test_error');
let fpathTarget = appName('fileio_test_error');
try {
expect(fileio.copyFileSync(fpath, fpathTarget) !== null).assertTrue();
expect(null).assertFail();
}
catch (e) {
console.log('fileio_test_error_000 has failed for ' + e);
}
});
/**
* @tc.number SUB_STORAGE_FileIo_test_error_0100
* @tc.name FileIo_test_error_001
* @tc.desc Function of API, mkdir files when disk space is full
*/
it('FileIo_test_error_001', 0, function () {
let dpath = nextFileName('fileio_test_error_001d');
try {
expect(fileio.mkdirSync(dpath) !== null).assertTrue();
}
catch (e) {
console.log('fileio_test_error_001 has failed for ' + e);
expect(null).assertFail();
}
});
/**
* @tc.number SUB_STORAGE_FileIo_test_error_0200
* @tc.name FileIo_test_error_002
* @tc.desc Function of API, When inode is full, verify the folder creation function
*/
it('FileIo_test_error_002', 0, function () {
let dpath = fileName('fileio_test_error_002d');
try {
expect(fileio.mkdirSync(dpath) !== null).assertTrue();
expect(null).assertFail();
}
catch (e) {
console.log('fileio_test_error_002 has failed for ' + e);
}
});
/**
* @tc.number SUB_STORAGE_FileIo_test_error_0300
* @tc.name FileIo_test_error_003
* @tc.desc Function of API, When the disk space is full, verify the synchronous write file data function
*/
it('FileIo_test_error_003', 0, function () {
let fpath = nextFileName('fileio_test_error_003');
try {
let fd = fileio.openSync(fpath, 0o102, 0o777);
expect(fd !== null).assertTrue();
expect(fileio.writeSync(fd, FILE_CONTENT) !== null).assertTrue();
expect(fileio.closeSync(fd) !== null).assertTrue();
expect(null).assertFail();
}
catch (e) {
console.log('fileio_test_error_003 has failed for ' + e);
}
});
/**
* @tc.number SUB_STORAGE_FileIo_test_error_0400
* @tc.name FileIo_test_error_004
* @tc.desc Function of API, When the disk space is full, verify synchronization and write the buffer data back to the disk for data synchronization
*/
it('FileIo_test_error_004', 0, function () {
let fpath = nextFileName('fileio_test_error_004');
try {
let fd = fileio.openSync(fpath, 0o102, 0o777);
expect(fd !== null).assertTrue();
expect(fileio.fsyncSync(fd) !== null).assertTrue();
expect(fileio.closeSync(fd) !== null).assertTrue();
expect(null).assertFail();
}
catch (e) {
console.log('fileio_test_error_004 has failed for ' + e);
}
});
/**
* @tc.number SUB_STORAGE_FileIo_test_error_0500
* @tc.name FileIo_test_error_005
* @tc.desc Function of API, Open 200m file function when there is 100m left in RAM
* Create a 200m file (fileio_test_error_005) and grant 777 permissions,
* path:/data/accounts/account_0/appdata/ohos.acts.stroage.fileio/cache/fileio_test_error_005
*/
it('FileIo_test_error_005', 0, function () {
let fpath = nextFileName('fileio_test_error_005');
try {
let fd = fileio.openSync(fpath);
expect(fd !== null).assertTrue();
expect(fileio.closeSync(fd) !== null).assertTrue();
}
catch (e) {
console.log('fileio_test_error_005 has failed for ' + e);
expect(null).assertFail();
}
});
/**
* @tc.number SUB_STORAGE_FileIo_test_error_0600
* @tc.name FileIo_test_error_006
* @tc.desc Function of API, Read 200m file function when there is 100m left in RAM
* Create a 200m file (fileio_test_error_005) and grant 777 permissions,
* path:/data/accounts/account_0/appdata/ohos.acts.stroage.fileio/cache/fileio_test_error_005
*/
it('FileIo_test_error_006', 0, function () {
let fpath = nextFileName('fileio_test_error_005');
try {
let fd = fileio.openSync(fpath);
expect(fd !== null).assertTrue();
let rlen = fileio.readSync(fd, new ArrayBuffer(209715200));
expect(rlen == 209715200).assertTrue();
expect(fileio.closeSync(fd) !== null).assertTrue();
}
catch (e) {
console.log('fileio_test_error_006 has failed for ' + e);
expect(null).assertFail();
}
});
/**
* @tc.number SUB_STORAGE_FileIo_test_error_0700
* @tc.name FileIo_test_error_007
* @tc.desc Function of API, Verify the function of obtaining 200m file stream synchronously when 100m ram is left
* Create a 200m file (fileio_test_error_005) and grant 777 permissions,
* path:/data/accounts/account_0/appdata/ohos.acts.stroage.fileio/cache/fileio_test_error_005
*/
it('FileIo_test_error_007', 0, function () {
let fpath = nextFileName('fileio_test_error_005');
try {
let ss = fileio.createStreamSync(fpath, 'r+');
expect(ss !== null).assertTrue();
expect(ss.closeSync() !== null).assertTrue();
}
catch (e) {
console.log('fileio_test_error_007 has failed for ' + e);
expect(null).assertFail();
}
});
/**
* @tc.number SUB_STORAGE_FileIo_test_error_0800
* @tc.name FileIo_test_error_008
* @tc.desc Function of API, Read 200m file function when there is 100m left in RAM
* Create a 200m file (fileio_test_error_005) and grant 777 permissions,
* path:/data/accounts/account_0/appdata/ohos.acts.stroage.fileio/cache/fileio_test_error_005
*/
it('FileIo_test_error_008', 0, function () {
let fpath = nextFileName('fileio_test_error_005');
try {
let ss = fileio.createStreamSync(fpath, 'r+');
expect(ss !== null).assertTrue();
let rlen = ss.readSync(new ArrayBuffer(209715200));
expect(rlen == 209715200).assertTrue();
expect(ss.closeSync() !== null).assertTrue();
}
catch (e) {
console.log('fileio_test_error_008 has failed for ' + e);
expect(null).assertFail();
}
});
/**
* @tc.number SUB_STORAGE_FileIo_test_error_0900
* @tc.name FileIo_test_error_009
* @tc.desc Function of API, Delete directories with files
*/
it('FileIo_test_error_009', 0, function () {
let dpath = fileName('fileio_test_error_009d');
let fpath = dpath + '/fileio_test_error_009f';
fileio.mkdirSync(dpath);
prepareFile(fpath, 'hello');
try {
expect(fileio.rmdirSync(dpath) !== null).assertTrue();
expect(null).assertFail();
}
catch (e) {
console.log('fileio_test_error_009 has failed for ' + e);
fileio.unlinkSync(fpath);
fileio.rmdirSync(dpath);
}
});
/**
* @tc.number SUB_STORAGE_FileIo_test_error1000
* @tc.name FileIo_test_error_010
* @tc.desc Function of API, delete file
*/
it('FileIo_test_error_010', 0, function () {
let fpath = fileName('fileio_test_error_010f');
prepareFile(fpath, 'hello');
try {
expect(fileio.rmdirSync(fpath) !== null).assertTrue();
expect(null).assertFail();
}
catch (e) {
console.log('fileio_test_error_010 has failed for ' + e);
fileio.unlinkSync(fpath);
}
});
/**
* @tc.number SUB_STORAGE_FileIo_test_error_1100
* @tc.name FileIo_test_error_011
* @tc.desc Function of API, Pass in a path that exceeds 4096 bytes to copy the file
*/
it('FileIo_test_error_011', 0, function () {
let fpath = nextFileName('fileio_test_error_011');
fileio.openSync(fpath, 0o102, 0o777);
let dpath = nextFileName('fileio_error_011d');
fileio.mkdirSync(dpath);
try {
for (let i = 0; i < 16; i++) {
if (i == 15) {
let fpathTarget = dpath + '/f' + randomString(248);
expect(fileio.copyFileSync(fpath, fpathTarget) !== null).assertTrue();
console.log((i + 1) + ' copy success');
expect(null).assertFail();
} else {
dpath = dpath + '/d' + randomString(248);
fileio.mkdirSync(dpath);
console.log((i + 1) + ' mkdir success');
}
}
}
catch (e) {
console.log('fileio_test_error_011 has failed for ' + e);
}
});
/**
* @tc.number SUB_STORAGE_FileIo_test_error_0120
* @tc.name FileIo_test_error_012
* @tc.desc Function of API, flags=0o102. The test file is exist.
*/
it('FileIo_test_error_012', 0, function () {
let fpath = nextFileName('FileIo_test_error_012');
prepareFile(fpath, FILE_CONTENT);
try {
fileio.openSync(fpath, 0o102);
expect(null).assertFail();
}
catch (e) {
console.log('FileIo_test_error_012 has failed for ' + e);
expect(fileio.unlinkSync(fpath) !== null).assertTrue();
}
});
/**
* @tc.number SUB_STORAGE_FileIO_OpenSync_0130
* @tc.name FileIo_test_error_013
* @tc.desc Function of API, flags=0o102
*/
it('FileIo_test_error_013', 0, function () {
let fpath = nextFileName('FileIo_test_error_013');
try {
fileio.openSync(fpath, 0o102);
expect(null).assertFail();
}
catch (e) {
console.log('FileIo_test_error_013 has failed for ' + e);
}
});
/**
* @tc.number SUB_STORAGE_FileIO_OpenSync_0140
* @tc.name FileIo_test_error_014
* @tc.desc Function of API, flags=0o202. The test file is exist.
*/
it('FileIo_test_error_014', 0, function () {
let fpath = nextFileName('FileIo_test_error_014');
prepareFile(fpath, FILE_CONTENT);
try {
fileio.openSync(fpath, 0o202);
expect(null).assertFail();
}
catch (e) {
console.log('FileIo_test_error_014 has failed for ' + e);
expect(fileio.unlinkSync(fpath) !== null).assertTrue();
}
});
/**
* @tc.number SUB_STORAGE_FileIO_OpenSync_0150
* @tc.name FileIo_test_error_015
* @tc.desc Function of API, flags=0o302. The test file is exist.
*/
it('FileIo_test_error_015', 0, function () {
let fpath = nextFileName('FileIo_test_error_015');
prepareFile(fpath, FILE_CONTENT);
try {
fileio.openSync(fpath, 0o302);
expect(null).assertFail();
}
catch (e) {
console.log('FileIo_test_error_015 has failed for ' + e);
expect(fileio.unlinkSync(fpath) !== null).assertTrue();
}
});
/**
* @tc.number SUB_STORAGE_FileIO_OpenSync_0160
* @tc.name FileIo_test_error_016
* @tc.desc Function of API, flags=0o100002. The test file is exist.
*/
it('FileIo_test_error_016', 0, function () {
let fpath = nextFileName('FileIo_test_error_016');
prepareFile(fpath, FILE_CONTENT);
try {
fileio.openSync(fpath, 0o100002);
expect(null).assertFail();
}
catch (e) {
console.log('FileIo_test_error_016 has failed for ' + e);
expect(fileio.unlinkSync(fpath) !== null).assertTrue();
}
});
/**
* @tc.number SUB_STORAGE_FileIO_OpenSync_0170
* @tc.name FileIo_test_error_017
* @tc.desc Function of API, flags=0o40002 The test file is exist.
*/
it('FileIo_test_error_017', 0, function () {
let dpath = nextFileName('FileIo_test_error_017');
expect(fileio.mkdirSync(dpath) !== null).assertTrue();
try {
fileio.openSync(dpath, 0o40002);
expect(null).assertFail();
}
catch (e) {
console.log('FileIo_test_error_017 has failed for ' + e);
expect(fileio.rmdirSync(dpath) !== null).assertTrue();
}
});
/**
* @tc.number SUB_STORAGE_FileIO_OpenSync_0180
* @tc.name FileIo_test_error_018
* @tc.desc Function of API, flags=0o20040002. The test file is exist.
*/
it('FileIo_test_error_018', 0, function () {
let fpath = nextFileName('FileIo_test_error_018');
try {
fileio.openSync(fpath, 0o20040002);
expect(null).assertFail();
}
catch (e) {
console.log('FileIo_test_error_018 has failed for ' + e);
}
});
/**
* @tc.number SUB_STORAGE_FileIO_OpenSync_0190
* @tc.name FileIo_test_error_019
* @tc.desc Function of API, flags=0o400002. The test file is exist.
*/
it('FileIo_test_error_019', 0, function () {
let fpath = nextFileName('FileIo_test_error_019');
let txt = 'h'
prepareFile(fpath, txt);
try {
fileio.openSync(fpath, 0o400002);
expect(null).assertFail();
}
catch (e) {
console.log('FileIo_test_error_019 has failed for ' + e);
expect(fileio.unlinkSync(fpath) !== null).assertTrue();
}
});
/**
* @tc.number SUB_STORAGE_FileIO_OpenSync_0200
* @tc.name FileIo_test_error_020
* @tc.desc Function of API, flags=0o400002. The test file is exist.
*/
it('FileIo_test_error_020', 0, function () {
let fpath = nextFileName('FileIo_test_error_020');
let txt = randomString(5000);
prepareFile(fpath, txt);
try {
fileio.openSync(fpath, 0o400002);
expect(null).assertFail();
}
catch (e) {
console.log('FileIo_test_error_020 has failed for ' + e);
expect(fileio.unlinkSync(fpath) !== null).assertTrue();
}
});
/**
* @tc.number SUB_STORAGE_FileIO_OpenSync_0210
* @tc.name FileIo_test_error_021
* @tc.desc Function of API, flags=0o10000102. The test file is exist.
*/
it('FileIo_test_error_021', 0, function () {
let fpath = nextFileName('FileIo_test_error_021');
try {
fileio.openSync(fpath, 0o10000102);
expect(null).assertFail();
}
catch (e) {
console.log('FileIo_test_error_021 has failed for ' + e);
}
});
/**
* @tc.number SUB_STORAGE_FileIO_OpenSync_0220
* @tc.name FileIo_test_error_022
* @tc.desc Function of API,mode=1 The test file is exist.
*/
it('FileIo_test_error_022', 0, function () {
let fpath = nextFileName('FileIo_test_error_022');
prepareFile(fpath, FILE_CONTENT);
let fpathTarget = fpath + 'f1';
try {
fileio.copyFileSync(fpath, fpathTarget, 1);
expect(null).assertFail();
}
catch (e) {
console.log('FileIo_test_error_021 has failed for ' + e);
expect(fileio.unlinkSync(fpath) !== null).assertTrue();
}
});
});
/*
* 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,
it,
expect
}
from 'deccjsunit/index'
import {
FILE_CONTENT,
prepareFile,
fileName,
}
from './Common'
describe('fileVirtualPath', function () {
/**
* @tc.number SUB_STORAGE_File_Delete_0900
* @tc.name File_Delete_009
* @tc.desc Function of API, virtual path, Delete files from outside the package.
* create directory and grant 777 permission:
* /data/accounts/account_0/appdata/ohos.acts.distributeddatamgr.distributedfile
*/
it('File_Delete_009', 0, async function (done) {
file.writeText({
uri: 'internal://app/../../ohos.acts.distributeddatamgr.distributedfile/File_Delete_009',
text: 'sawyerwang',
success: function () {
console.log('File_Delete_009 mkdir success');
done();
},
fail: function (data, code) {
console.log('File_Delete_009 , code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
file.delete({
uri: 'internal://app/../../ohos.acts.distributeddatamgr.distributedfile/File_Delete_009',
success: function () {
console.log('File_Delete_009 call delete success');
done();
},
fail: function (data, code) {
console.log(code);
expect(null).assertFail();
},
});
});
/**
* @tc.number SUB_STORAGE_File_Delete_1000
* @tc.name File_Delete_010
* @tc.desc Function of API, virtual path, Delete files from outside the package.
* Create files and maintain file permissions(755):/data/accounts/account_0/appdata/123456
*/
it('File_Delete_010', 0, async function (done) {
file.delete({
uri: 'internal://app/../../123456',
success: function () {
console.log('File_Delete_010 => pass');
expect(null).assertFail();
},
fail: function (data, code) {
console.log('File_Delete_010 => fail ,code: ' + code + ', data: ' + data);
expect(code == 300).assertTrue();
done();
},
});
});
/**
* @tc.number SUB_STORAGE_File_writeText_1200
* @tc.name File_writeText_012
* @tc.desc Function of API, virtual path, Write files from outside the package.
* create directory and grant 777 permission:
* /data/accounts/account_0/appdata/ohos.acts.distributeddatamgr.distributedfile
*/
it('File_writeText_012', 0, async function (done) {
file.writeText({
uri: 'internal://app/../../ohos.acts.distributeddatamgr.distributedfile/File_writeText_012',
text: 'sawyerwang',
success: function () {
console.log('File_writeText_012 mkdir success');
done();
},
fail: function (data, code) {
console.log('File_writeText_012 , code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
file.readText({
uri: 'internal://app/../../ohos.acts.distributeddatamgr.distributedfile/File_writeText_012',
success: function (data) {
console.log('File_writeText_012 => call readText pass, ' + data.text);
done();
},
fail: function (data, code) {
console.log('File_writeText_012 call readText callback fail, code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
file.delete({
uri: 'internal://app/../../ohos.acts.distributeddatamgr.distributedfile/File_writeText_012',
success: function () {
console.log('File_writeText_012 delete success');
done();
},
fail: function (data, code) {
console.log('File_writeText_012 call delete callback fail, code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
});
/**
* @tc.number SUB_STORAGE_File_writeArrayBuffer_1100
* @tc.name File_writeArrayBuffer_011
* @tc.desc Function of API, virtual path, Write files from outside the package.
* create directory and grant 777 permission:
* /data/accounts/account_0/appdata/ohos.acts.distributeddatamgr.distributedfile
*/
it('File_writeArrayBuffer_011', 0, async function (done) {
let buf = new Uint8Array([48, 49, 50, 51, 65, 66, 67, 68, 32, 33]);
file.writeArrayBuffer({
uri: 'internal://app/../../ohos.acts.distributeddatamgr.distributedfile/File_writeArrayBuffer_011',
buffer: buf,
append: true,
success: function () {
console.log('File_writeArrayBuffer_011 call writeArrayBuffer success.');
done();
},
fail: function (data, code) {
console.log('File_writeArrayBuffer_011 , code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
file.readArrayBuffer({
uri: 'internal://app/../../ohos.acts.distributeddatamgr.distributedfile/File_writeArrayBuffer_011',
success: function (data) {
console.log('File_writeArrayBuffer_011 readArrayBuffer: call success' + data.buffer);
done();
},
fail: function (data, code) {
console.log('File_writeArrayBuffer_011 readArrayBuffer , code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
file.delete({
uri: 'internal://app/../../ohos.acts.distributeddatamgr.distributedfile/File_writeArrayBuffer_011'
});
});
/**
* @tc.number SUB_STORAGE_File_readText_0800
* @tc.name File_readText_008
* @tc.desc Function of API, virtual path, Read files from outside the package.
* create directory and grant 777 permission:
* /data/accounts/account_0/appdata/ohos.acts.distributeddatamgr.distributedfile
*/
it('File_readText_008', 0, async function (done) {
file.writeText({
uri: 'internal://app/../../ohos.acts.distributeddatamgr.distributedfile/File_readText_008',
text: 'Text that just for test.',
success: function () {
console.log('File_readText_008 call writeText success.');
done();
},
fail: function (data, code) {
console.log('File_readText_008 call writeText callback fail, code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
file.readText({
uri: 'internal://app/../../ohos.acts.distributeddatamgr.distributedfile/File_readText_008',
success: function (data) {
console.log('File_readText_008 call readText success. data.text:' + data.text);
done();
},
fail: function (data, code) {
console.log('File_readText_008 call readText callback fail, code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
file.delete({
uri: 'internal://app/../../ohos.acts.distributeddatamgr.distributedfile/File_readText_008'
});
});
/**
* @tc.number SUB_STORAGE_File_readText_0900
* @tc.name File_readText_009
* @tc.desc Function of API, virtual path, Read files from outside the package.
* Create files and maintain file permissions(755):/data/accounts/account_0/appdata/123456
*/
it('File_readText_009', 0, async function (done) {
file.readText({
uri: 'internal://app/../../123456',
success: function (data) {
console.log('File_readText_009 => pass, data.text:' + data.text);
done();
},
fail: function (data, code) {
console.log('File_readText_009 call readText callback fail, code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
});
/**
* @tc.number SUB_STORAGE_File_read_array_buffer_1000
* @tc.name File_read_array_buffer_010
* @tc.desc Function of API, virtual path, Read files from outside the package.
* create directory and grant 777 permission:
* /data/accounts/account_0/appdata/ohos.acts.distributeddatamgr.distributedfile
*/
it('File_read_array_buffer_010', 0, async function (done) {
var buffer = new Uint8Array([48, 49, 50, 51, 65, 66, 67, 68, 32, 33]);
file.writeArrayBuffer({
uri: 'internal://cache/../../ohos.acts.distributeddatamgr.distributedfile/File_read_array_buffer_010',
buffer: buffer,
success: function () {
console.log('File_read_array_buffer_010 call writeArrayBuffer success.');
done();
},
fail: function (data, code) {
console.log('File_read_array_buffer_010 , code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
file.readArrayBuffer({
uri: 'internal://cache/../../ohos.acts.distributeddatamgr.distributedfile/File_read_array_buffer_010',
position: 0,
length: 10,
success: function (data) {
console.log('File_read_array_buffer_010 call readArrayBuffer success. data.buffer:' + data.buffer);
done();
},
fail: function (data, code) {
console.log('File_read_array_buffer_010 , code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
file.delete({
uri: 'internal://cache/../../ohos.acts.distributeddatamgr.distributedfile/File_read_array_buffer_010'
});
});
/**
* @tc.number SUB_STORAGE_File_read_array_buffer_1100
* @tc.name File_read_array_buffer_011
* @tc.desc Function of API, virtual path, Read files from outside the package.
* Create files and maintain file permissions(755):/data/accounts/account_0/appdata/123456
*/
it('File_read_array_buffer_011', 0, async function (done) {
file.readArrayBuffer({
uri: 'internal://cache/../../123456',
position: 0,
length: 10,
success: function (data) {
console.log('File_read_array_buffer_011 => pass, data.buffer: ' + data.buffer);
done();
},
fail: function (data, code) {
console.log('File_read_array_buffer_011 , code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
});
/**
* @tc.number SUB_STORAGE_File_access_0900
* @tc.name File_access_009
* @tc.desc Function of API, virtual path, Determine whether files outside the package exist.
* create directory and grant 777 permission:
* /data/accounts/account_0/appdata/ohos.acts.distributeddatamgr.distributedfile
*/
it('File_access_009', 0, async function (done) {
file.writeText({
uri: 'internal://cache/../../ohos.acts.distributeddatamgr.distributedfile/File_access_009',
text: 'Text that just for test.',
success: function () {
console.log('File_access_009 mkdir success.');
done();
},
fail: function (data, code) {
console.log('File_access_009 fail,code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
file.access({
uri: 'internal://cache/../../ohos.acts.distributeddatamgr.distributedfile/File_access_009',
success: function () {
console.log('File_access_009 call access success.');
done();
},
fail: function (data, code) {
console.log('File_access_009 , code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
file.delete({
uri: 'internal://cache/../../ohos.acts.distributeddatamgr.distributedfile/File_access_009',
success: function () {
console.log('File_access_009 call delete success.');
done();
},
fail: function (data, code) {
console.log('File_access_009 , code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
});
/**
* @tc.number SUB_STORAGE_File_access_1000
* @tc.name File_access_010
* @tc.desc Function of API, virtual path, Determine whether files outside the package exist.
* Create files and maintain file permissions(755):
* /data/accounts/account_0/appdata/123456
*/
it('File_access_010', 0, async function (done) {
file.access({
uri: 'internal://cache/../../123456',
success: function () {
console.log('File_access_010 call access success.');
done();
},
fail: function (data, code) {
console.log('File_access_010 , code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
});
/**
* @tc.number SUB_STORAGE_File_mkdir_0900
* @tc.name File_mkdir_009
* @tc.desc Function of API, virtual path, Create directory outside package.
* create directory and grant 777 permission:
* /data/accounts/account_0/appdata/ohos.acts.distributeddatamgr.distributedfile
*/
it('File_mkdir_009', 0, async function (done) {
file.mkdir({
uri: 'internal://app/../../ohos.acts.distributeddatamgr.distributedfile/File_mkdir_009',
success: function () {
console.log('File_mkdir_009 call mkdir success.');
done();
},
fail: function (data, code) {
console.log('File_mkdir_009 call mkdir callback fail, code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
file.rmdir({
uri: 'internal://app/../../ohos.acts.distributeddatamgr.distributedfile/File_mkdir_009',
success: function () {
console.log('File_mkdir_009 call rmdir success.');
done();
},
fail: function (data, code) {
console.log('File_mkdir_009 call rmdir callback fail, code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
});
/**
* @tc.number SUB_STORAGE_File_rmdir_0900
* @tc.name File_rmdir_009
* @tc.desc Function of API, virtual path, Delete directory outside package.
* create directory and grant 777 permission:
* /data/accounts/account_0/appdata/ohos.acts.distributeddatamgr.distributedfile
*/
it('File_rmdir_009', 0, async function (done) {
file.mkdir({
uri: 'internal://app/../../ohos.acts.distributeddatamgr.distributedfile/File_rmdir_009',
success: function () {
console.log('File_rmdir_009 call mkdir success.');
done();
},
fail: function (data, code) {
console.log('File_rmdir_009 call mkdir callback fail, code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
file.rmdir({
uri: 'internal://app/../../ohos.acts.distributeddatamgr.distributedfile/File_rmdir_009',
success: function () {
console.log('File_rmdir_009 call rmdir success.');
done();
},
fail: function (data, code) {
console.log('File_rmdir_009 call rmdir callback fail, code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
});
/**
* @tc.number SUB_STORAGE_File_Move_1300
* @tc.name File_Move_013
* @tc.desc Function of API, virtual path, Move files out of package.
* create directory and grant 777 permission:
* /data/accounts/account_0/appdata/ohos.acts.distributeddatamgr.distributedfile
*/
it('File_Move_013', 0, async function (done) {
let srcFpath = fileName('File_Move_013');
expect(prepareFile(srcFpath, FILE_CONTENT) !== null).assertTrue();
file.move({
srcUri: 'internal://app/../files/File_Move_013',
dstUri: 'internal://app/../../ohos.acts.distributeddatamgr.distributedfile/File_Move_013',
success: function (uri) {
console.log('File_Move_013 => pass,uri: ' + uri);
done();
},
fail: function (data, code) {
console.log('File_Move_013 , code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
});
/**
* @tc.number SUB_STORAGE_File_Copy_1300
* @tc.name File_Copy_013
* @tc.desc Function of API, virtual path, Copy files out of package.
* create directory and grant 777 permission:
* /data/accounts/account_0/appdata/ohos.acts.distributeddatamgr.distributedfile
*/
it('File_Copy_013', 0, async function (done) {
let srcFpath = fileName('File_Copy_013');
expect(prepareFile(srcFpath, 'test') !== null).assertTrue();
file.copy({
srcUri: 'internal://app/../files/File_Copy_013',
dstUri: 'internal://app/../../ohos.acts.distributeddatamgr.distributedfile/File_Copy_013',
success: function (uri) {
console.log('File_Copy_013=> pass uri:' + uri);
done();
},
fail: function (data, code) {
console.log('File_Copy_013 , code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
});
/**
* @tc.number SUB_STORAGE_File_List_1500
* @tc.name File_List_015
* @tc.desc Function of API, virtual path, Query the files in the directory outside the package.
* create directory and grant 777 permission:
* /data/accounts/account_0/appdata/ohos.acts.distributeddatamgr.distributedfile
*/
it('File_List_015', 0, async function (done) {
file.writeText({
uri: 'internal://cache/../../ohos.acts.distributeddatamgr.distributedfile/File_List_015',
text: 'Text that just for test.',
success: function () {
console.log('File_List_015 mkdir success.');
done();
},
fail: function (data, code) {
console.log('File_List_015 fail,code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
file.writeText({
uri: 'internal://cache/../../ohos.acts.distributeddatamgr.distributedfile/File_List_015_1',
text: 'Text that just for test.',
success: function () {
console.log('File_List_015_1 mkdir success.');
done();
},
fail: function (data, code) {
console.log('File_List_015_1 fail,code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
file.list({
uri: 'internal://app/../../ohos.acts.distributeddatamgr.distributedfile',
success: function (data) {
console.log('File_List_015 => pass' + JSON.stringify(data.fileList));
done();
},
fail: function (data, code) {
console.log('File_List_015 , code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
});
/**
* @tc.number SUB_STORAGE_File_List_1500
* @tc.name File_List_015
* @tc.desc Function of API, virtual path, Query the files in the directory outside the package.
* create directory and grant 777 permission:
* /data/accounts/account_0/appdata/ohos.acts.distributeddatamgr.distributedfile
*/
it('File_Get_017', 0, async function (done) {
file.get({
uri: 'internal://app/../../ohos.acts.distributeddatamgr.distributedfile',
success: function (data) {
console.log('File_Get_017 => pass');
done();
},
fail: function (data, code) {
console.log('File_Get_017 , code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
});
});
/*
* 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('./FileIOError.test.js')
require('./FileError.test.js')
require('./FileVirtualPath.test.js')
# 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("storagefileconcurrent_js_test") {
test_hap_name = "storagefileconcurrentjstest"
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": [
"storagefileconcurrentjstest.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
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} from 'deccjsunit/index'
export default {
data: {
title: ''
},
onInit() {
this.title = this.$t('strings.world');
},
onShow() {
console.info('onShow finish')
const core = Core.getInstance()
core.init()
const configService = core.getDefaultService('config')
configService.setConfig(this)
require('../../../test/List.test')
core.execute()
},
onReady() {
},
}
\ No newline at end of file
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the 'License');
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an 'AS IS' BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import fileio from '@system.fileio'
export const FILE_CONTENT = 'hello world'
export function prepareFile(fpath, content) {
try {
let fd = fileio.openSync(fpath, 0o102, 0o666)
fileio.ftruncateSync(fd)
fileio.writeSync(fd, content)
fileio.fsyncSync(fd)
fileio.closeSync(fd)
return true
}
catch (e) {
console.log('Failed to prepareFile for ' + e)
return false
}
}
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
}
}
export function appName(testName) {
const BASE_PATH = '/data/accounts/account_0/appdata/ohos.acts.stroage.fileio/'
return BASE_PATH + testName
}
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 cacheFileName(testName) {
const BASE_PATH = '/data/accounts/account_0/appdata/ohos.acts.stroage.fileio/files/cache/'
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 differentCacheName(testName) {
const BASE_PATH = '/data/accounts/account_0/ohos.acts.distributeddatamgr.distributedfile/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('file:' + fpath)
console.log('file lenth:' + 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('file:' + fpath)
console.log('status:exist')
return true
}
catch (e) {
console.log('file:' + fpath)
console.log('status:non-existen')
return false
}
}
export function sleep(n) {
var start = new Date().getTime();
while (true) {
if (new Date().getTime() - start > n) {
break;
}
}
}
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;
}
/*
* 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,
cacheFileName,
getFileTextLen,
isFileExist,
prepareEmptyFile,
randomString
}
from './Common'
describe('fileconcurrent', function () {
/**
* @tc.number SUB_STORAGE_file_test_0000
* @tc.name file_test_0000 Function of API, out of package, Virtual path(create and give 777 authority).
* @tc.desc Function of API, Simultaneous write.
*/
it('file_test_000', 0, async function (done) {
for (let i = 0; i < 10; i++) {
file.writeText({
uri: 'internal://app/file_test_000',
text: 'Text',
success: function () {
console.log('file_test_000 => pass, call writeText success. ');
done();
},
fail: function (data, code) {
console.log('file_test_000 => call writeText fail, code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
file.writeText({
uri: 'internal://app/file_test_000',
text: 'Text1',
success: function () {
console.log('file_test_000 => pass, call writeText success. ');
done();
},
fail: function (data, code) {
console.log('file_test_000 => call writeText fail, code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
file.writeText({
uri: 'internal://app/file_test_000',
text: 'Text2',
success: function () {
console.log('file_test_000 => pass, call writeText success. ');
done();
},
fail: function (data, code) {
console.log('file_test_000 => call writeText fail, code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
}
});
/**
* @tc.number SUB_STORAGE_File_readText_0100
* @tc.name file_test_001
* @tc.desc Function of API Simultaneous reading.
*/
it('file_test_001', 0, async function (done) {
file.writeText({
uri: 'internal://app/file_test_001',
text: 'Text',
success: function () {
console.log('file_test_001 call writeText success.');
done();
},
fail: function (data, code) {
console.log('file_test_001 call writeText fail, code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
for (let i = 0; i < 10; i++) {
file.readText({
uri: 'internal://app/file_test_001',
success: function (data) {
console.log('file_test_001 => pass, call readText success. data.text: ' );
done();
},
fail: function (data, code) {
console.log('file_test_001 => call readText fail, code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
file.readText({
uri: 'internal://app/file_test_001',
success: function (data) {
console.log('file_test_001 => pass, call readText success. data.text: ' );
done();
},
fail: function (data, code) {
console.log('file_test_001 => call readText fail, code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
file.readText({
uri: 'internal://app/file_test_001',
success: function (data) {
console.log('file_test_001 => pass, call readText success. data.text: ' );
done();
},
fail: function (code, data) {
console.log('file_test_001 => call readText fail, code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
}
});
/**
* @tc.number SUB_STORAGE_file_test_0200
* @tc.name file_test_002
* @tc.desc Function of API Simultaneous copying.
*/
it('file_test_002', 0, async function (done) {
file.writeText({
uri: 'internal://app/file_test_002',
text: 'Text',
append: true,
success: function () {
console.log('file_test_002 call writeText success.');
done();
},
fail: function (data, code) {
console.log('file_test_002 call writeText fail, code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
for (let i = 0; i < 10; i++) {
file.copy({
srcUri: 'internal://app/file_test_002',
dstUri: 'internal://app/file_test_002',
success: function (uri) {
console.log('file_test_002 => pass,call copy success. uri:' );
done();
},
fail: function (data, code) {
console.log('file_test_002 => call copy fail, code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
file.copy({
srcUri: 'internal://app/file_test_002',
dstUri: 'internal://app/file_test_002' + '100',
success: function (uri) {
console.log('file_test_002 => pass,call copy success. uri:' );
done();
},
fail: function (data, code) {
console.log('file_test_002 => call copy fail, code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
file.copy({
srcUri: 'internal://app/file_test_002',
dstUri: 'internal://app/file_test_002' + '200',
success: function (uri) {
console.log('file_test_002 => pass,call copy success. uri:' );
done();
},
fail: function (data, code) {
console.log('file_test_002 => call copy fail, code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
}
});
/**
* @tc.number SUB_STORAGE_file_test_0300
* @tc.name file_test_003
* @tc.desc Function of API, Move files while writing to them continuously
*/
it('file_test_003', 0, async function (done) {
for (let i = 0; i < 10; i++) {
file.writeText({
uri: 'internal://app/file_test_003',
text: 'Text',
append: true,
success: function () {
console.log('file_test_003 => pass,call writeText success.');
done();
},
fail: function (data, code) {
console.log('file_test_003 => call writeText fail, code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
file.move({
srcUri: 'internal://app/file_test_003',
dstUri: 'internal://file_test_003',
success: function (uri) {
console.log('file_test_003 => pass,call move success. uri:' );
done();
},
fail: function (data, code) {
console.log('file_test_003 =>call move fail, code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
}
});
/**
* @tc.number SUB_STORAGE_file_test_0400
* @tc.name file_test_004
* @tc.desc Function of API,Continuous reading
*/
it('file_test_004', 0, async function (done) {
let buf = new Uint8Array([48, 49, 50, 51, 65, 66, 67, 68, 32, 33]);
file.writeArrayBuffer({
uri: 'internal://app/file_test_004',
buffer: buf,
success: function () {
console.log('file_test_004 call writeArrayBuffer success.');
done();
},
fail: function (data, code) {
console.error('file_test_004 call writeArrayBuffer fail, code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
for (let i = 0; i < 10; i++) {
file.readArrayBuffer({
uri: 'internal://app/file_test_004',
success: function (data) {
console.log('file_test_004 => pass,call readArrayBuffer success. ');
done();
},
fail: function (data, code) {
console.log('file_test_004 => call readArrayBuffer fail, code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
file.readArrayBuffer({
uri: 'internal://app/file_test_004',
success: function (data) {
console.log('file_test_004 => pass,call readArrayBuffer success. ');
done();
},
fail: function (data, code) {
console.log('file_test_004 => call readArrayBuffer fail, code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
file.readArrayBuffer({
uri: 'internal://app/file_test_004',
success: function (data) {
console.log('file_test_004 => pass,call readArrayBuffer success. ');
done();
},
fail: function (data, code) {
console.log('file_test_004 => call readArrayBuffer fail, code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
}
});
/**
* @tc.number SUB_STORAGE_file_test_0500
* @tc.name file_test_005
* @tc.desc Function of API,Continuous writeing
*/
it('file_test_005', 0, async function (done) {
let buf = new Uint8Array([48, 49, 50, 51, 65, 66, 67, 68, 32, 33]);
for (let i = 0; i < 10; i++) {
file.writeArrayBuffer({
uri: 'internal://app/file_test_005',
buffer: buf,
success: function () {
console.log('file_test_005 => pass,call writeArrayBuffer success.');
done();
},
fail: function (data, code) {
console.log('file_test_005 => call writeArrayBuffer fail, code: ' + code);
expect(null).assertFail();
},
});
file.writeArrayBuffer({
uri: 'internal://app/file_test_005',
buffer: buf,
success: function () {
console.log('file_test_005 => pass,call writeArrayBuffer success.');
done();
},
fail: function (data, code) {
console.log('file_test_005 => call writeArrayBuffer fail, code: ' + code);
expect(null).assertFail();
},
});
file.writeArrayBuffer({
uri: 'internal://app/file_test_005',
buffer: buf,
success: function () {
console.log('file_test_005 => pass,call writeArrayBuffer success.');
done();
},
fail: function (data, code) {
console.log('file_test_005 => call writeArrayBuffer fail, code: ' + code);
expect(null).assertFail();
},
});
}
});
/**
* @tc.number SUB_STORAGE_file_test_0600
* @tc.name file_test_006
* @tc.desc Function of API,Write and read simultaneously for one file
*/
it('file_test_006', 0, async function (done) {
for (let i = 0; i < 10; i++) {
file.writeText({
uri: 'internal://app/file_test_006',
text: 'Text',
success: function () {
console.log('file_test_006 => pass,call writeText success.');
done();
},
fail: function (data, code) {
console.log('file_test_006 => call fail callback fail, code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
file.readText({
uri: 'internal://app/file_test_006',
success: function (data) {
console.log('file_test_006 => pass,call readText success: ');
done();
},
fail: function (data, code) {
console.log('file_test_006 => call readText fail, code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
}
});
/**
* @tc.number SUB_STORAGE_file_test_0700
* @tc.name file_test_007
* @tc.desc Function of API,Write and read simultaneously for one file
*/
it('file_test_007', 0, async function (done) {
let buf = new Uint8Array([48, 49, 50, 51, 65, 66, 67, 68, 32, 33]);
for (let i = 0; i < 10; i++) {
file.writeArrayBuffer({
uri: 'internal://app/file_test_007',
buffer: buf,
success: function () {
console.log('file_test_007 => pass,call writeArrayBuffer success.');
done();
},
fail: function (data, code) {
console.log('file_test_007 => call writeArrayBuffer fail, code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
file.readArrayBuffer({
uri: 'internal://app/file_test_007',
success: function (data) {
console.log('file_test_007 => pass,call readArrayBuffer success: ');
done();
},
fail: function (data, code) {
console.log('file_test_007 => call readArrayBuffer fail, code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
}
});
/**
* @tc.number SUB_STORAGE_file_test_0800
* @tc.name file_test_008
* @tc.desc Function of API, Copy files while writing
*/
it('file_test_008', 0, async function (done) {
for (let i = 0; i < 10; i++) {
file.writeText({
uri: 'internal://app/file_test_008',
text: 'Text',
success: function () {
console.log('file_test_008 => pass, call writeText success.');
done();
},
fail: function (data, code) {
console.log('file_test_008 => call writeText fail, code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
file.copy({
srcUri: 'internal://app/file_test_008',
dstUri: 'internal://app/file_test_008',
success: function (uri) {
console.log('file_test_008 => pass,call copy success. uri:');
done();
},
fail: function (data, code) {
console.log('file_test_008 => call copy fail, code: ' + code + ', data: ' + data);
expect(null).assertFail();
},
});
}
});
});
/*
* 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('./FileConcurrent.test.js')
......@@ -13,6 +13,6 @@
import("//test/xts/tools/build/suite.gni")
ohos_js_hap_suite("storagefileio_js_test") {
test_hap_name = "StoragefileioJSTest"
test_hap_name = "Storagefileiojstest"
hap_source_path = "hap/entry-debug-rich-signed.hap"
}
{
"description": "Configuration for storage file and fileio Tests",
"driver": {
......
/*
* 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');
......
......@@ -16,11 +16,10 @@
import file from '@system.file'
import app from '@system.app'
import {Core, ExpectExtend, ReportExtend} from 'deccjsunit/index'
import {Core} from 'deccjsunit/index'
export default {
data: {
title: ""
title: ''
},
onInit() {
this.title = this.$t('strings.world');
......@@ -28,24 +27,9 @@ export default {
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()
},
......
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* 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,
* 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.
......@@ -15,10 +15,8 @@
import fileio from '@system.fileio'
export const FILE_CONTENT = "仙女星系 (英语: Andromeda Galaxy; M31; NGC 224 ;曾被称为 仙女座大星云 ),位于仙女座方位的拥有巨大盘状结构的 \
旋涡星系 , 梅西耶星表 编号为M31, 星云星团新总表 编号位 NGC 224 ,直径22万光年,距离地球有254万光年,是距银河系最近的大星系。"
export const FILE_CONTENT = 'hello world'
//创建一个可读写文件
export function prepareFile(fpath, content) {
try {
let fd = fileio.openSync(fpath, 0o102, 0o666)
......@@ -27,8 +25,9 @@ export function prepareFile(fpath, content) {
fileio.fsyncSync(fd)
fileio.closeSync(fd)
return true
} catch (e) {
console.log("Failed to prepareFile for " + e)
}
catch (e) {
console.log('Failed to prepareFile for ' + e)
return false
}
}
......@@ -40,23 +39,23 @@ export function prepareFile1(fpath, content) {
fileio.fsyncSync(fd)
fileio.closeSync(fd)
return true
} catch (e) {
console.log("Failed to prepareFile for " + e)
}
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)
}
catch (e) {
console.log('Failed to prepareFile for ' + e)
return false
}
}
//将已存在的文件访问权限改为只读
export function fileToReadOnly(fpath) {
try {
let fd = fileio.openSync(fpath, 0o1)
......@@ -64,12 +63,12 @@ export function fileToReadOnly(fpath) {
fileio.fsyncSync(fd)
fileio.closeSync(fd)
return true
} catch (e) {
console.log("Failed to fileToReadOnly for " + e)
}
catch (e) {
console.log('Failed to fileToReadOnly for ' + e);
return false
}
}
//将已存在的文件访问权限改为只写
export function fileToWriteOnly(fpath) {
try {
let fd = fileio.openSync(fpath, 0o2)
......@@ -77,12 +76,12 @@ export function fileToWriteOnly(fpath) {
fileio.fsyncSync(fd)
fileio.closeSync(fd)
return true
} catch (e) {
console.log("Failed to fileToWriteOnly " + e)
}
catch (e) {
console.log('Failed to fileToWriteOnly ' + e)
return false
}
}
//将已存在的文件访问权限改为读写
export function fileToReadAndWrite(fpath) {
try {
let fd = fileio.openSync(fpath, 0o1)
......@@ -90,54 +89,64 @@ export function fileToReadAndWrite(fpath) {
fileio.fsyncSync(fd)
fileio.closeSync(fd)
return true
} catch (e) {
console.log("Failed to fileToReadAndWrite " + e)
}
catch (e) {
console.log('Failed to fileToReadAndWrite ' + e);
return false
}
}
var fileSeed = 0
export function appName(testName) {
const BASE_PATH = '/data/accounts/account_0/appdata/ohos.acts.stroage.fileio/'
return BASE_PATH + testName
}
export function nextFileName(testName) {
const BASE_PATH = "/data/accounts/account_0/appdata/ohos.acts.stroage.fileio/cache/"
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/"
const BASE_PATH = '/data/accounts/account_0/appdata/ohos.acts.stroage.fileio/files/'
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 differentFileName(testName) {
const BASE_PATH = "/data/accounts/account_0/ohos.acts.distributeddatamgr.distributedfile/"
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/"
export function differentCacheName(testName) {
const BASE_PATH = '/data/accounts/account_0/ohos.acts.distributeddatamgr.distributedfile/cache/'
return BASE_PATH + testName
}
export function getFileTextLen(fpath) {
let ss
try{
ss = fileio.Stream.createStreamSync(fpath, "r+")
try {
ss = fileio.Stream.createStreamSync(fpath, 'r+')
expect(ss !== null).assertTrue()
let len = ss.readSync(new ArrayBuffer(4096))
console.log("文件:" + fpath)
console.log("文本长度:" + len)
console.log('file:' + fpath)
console.log('file lenth:' + len)
expect(ss.closeSync() !== null).assertTrue()
return len
} catch (e) {
console.log("Failed to getFileTextLen " + e)
}
catch (e) {
console.log('Failed to getFileTextLen ' + e)
expect(ss.closeSync() !== null).assertTrue()
return null
}
}
export function isFileExist(fpath) {
try{
try {
expect(fileio.accessSync(fpath) !== null).assertTrue()
console.log("文件:" + fpath)
console.log("状态:存在")
console.log('file:' + fpath)
console.log('status:exist')
return true
} catch (e) {
console.log("文件:" + fpath)
console.log("状态:不存在")
}
catch (e) {
console.log('file:' + fpath)
console.log('status:non-existen')
return false
}
}
......@@ -149,8 +158,8 @@ export function sleep(n) {
}
}
}
export function randomString(len) {
len = len;
export function randomString(num) {
let len= num;
var $chars = 'aaaabbbbcccc';
var maxPos = $chars.length;
var pwd = '';
......
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* 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,
* 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'
import {
describe,
it,
expect
}
from 'deccjsunit/index'
import {
FILE_CONTENT,
prepareFile,
nextFileName,
randomString
}
from './Common'
describe('fileIOTestDir', function () {
......@@ -27,16 +38,17 @@ describe('fileIOTestDir', function () {
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()
}
})
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
......@@ -45,12 +57,13 @@ describe('fileIOTestDir', function () {
*/
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)
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
......@@ -60,12 +73,13 @@ describe('fileIOTestDir', function () {
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)
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
......@@ -73,19 +87,20 @@ describe('fileIOTestDir', function () {
* @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)
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)
console.log('time' + i);
dpath = dpath + '/f' + randomString(248);
fileio.mkdirSync(dpath);
}
expect(null).assertFail();
}
expect(null).assertFail()
} catch (e) {
console.log("fileio_test_dir_open_sync_003 has failed for " + e)
catch (e) {
console.log('fileio_test_dir_open_sync_003 has failed for ' + e);
}
})
});
/**
* @tc.number SUB_STORAGE_FileIO_dir_OpenSync_0400
......@@ -93,14 +108,15 @@ describe('fileIOTestDir', function () {
* @tc.desc Function of API, filename too long.
*/
it('fileio_test_dir_open_sync_004', 0, function () {
let dpath = nextFileName(randomString(256))
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)
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
......@@ -108,19 +124,20 @@ describe('fileIOTestDir', function () {
* @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)
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)
console.log('time' + i);
dpath = dpath + '/' + i
fileio.mkdirSync(dpath);
}
expect(null).assertFail();
}
expect(null).assertFail()
} catch (e) {
console.log("fileio_test_dir_open_sync_005 has failed for " + e)
catch (e) {
console.log('fileio_test_dir_open_sync_005 has failed for ' + e);
}
})
});
/**
* @tc.number SUB_STORAGE_FileIO_dir_OpenSync_0600
......@@ -128,14 +145,15 @@ describe('fileIOTestDir', function () {
* @tc.desc Function of API, file name contain special character.
*/
it('fileio_test_dir_open_sync_006', 0, function () {
let dpath = nextFileName("?*:<>/|")
let dpath = nextFileName('?*:<>/|');
try {
fileio.mkdirSync(dpath)
expect(null).assertFail()
} catch (e) {
console.log("fileio_test_dir_open_sync_006 has failed for " + e)
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
......@@ -146,19 +164,20 @@ describe('fileIOTestDir', 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()
}
})
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
......@@ -167,41 +186,42 @@ describe('fileIOTestDir', function () {
*/
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')
let fpathArray = new Array(dpath + '/f1', dpath + '/f2', dpath + '/d3');
try {
expect(fileio.mkdirSync(dpath) !== null).assertTrue()
expect(fileio.mkdirSync(dpath) !== null).assertTrue();
for (let i = 0; i < 3; i++) {
if (i == 2) {
expect(fileio.mkdirSync(fpathArray[i]) !== null).assertTrue()
expect(fileio.mkdirSync(fpathArray[i]) !== null).assertTrue();
} else {
expect(prepareFile(fpathArray[i], FILE_CONTENT)).assertTrue()
expect(prepareFile(fpathArray[i], FILE_CONTENT)).assertTrue();
}
}
let dd = fileio.opendirSync(dpath)
expect(dd !== null).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)
let bool = typeof(dd.readSync());
expect(bool == 'object').assertTrue();
console.log('---bool=' + bool);
} else {
expect(dd.readSync() !== null).assertTrue()
expect(dd.readSync() !== null).assertTrue();
}
}
expect(dd.closeSync() == null).assertTrue()
expect(dd.closeSync() == null).assertTrue();
for (let i = 0; i < 3; i++) {
if (i == 2) {
expect(fileio.rmdirSync(fpathArray[i]) !== null).assertTrue()
expect(fileio.rmdirSync(fpathArray[i]) !== null).assertTrue();
} else {
expect(fileio.unlinkSync(fpathArray[i]) !== null).assertTrue()
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()
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
......@@ -210,36 +230,37 @@ describe('fileIOTestDir', function () {
*/
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')
let fpathArray = new Array(dpath + '/f1', dpath + '/f2', dpath + '/d3');
try {
expect(fileio.mkdirSync(dpath) !== null).assertTrue()
expect(fileio.mkdirSync(dpath) !== null).assertTrue();
for (let i = 0; i < 3; i++) {
if (i == 2) {
expect(fileio.mkdirSync(fpathArray[i]) !== null).assertTrue()
expect(fileio.mkdirSync(fpathArray[i]) !== null).assertTrue();
} else {
expect(prepareFile(fpathArray[i], FILE_CONTENT)).assertTrue()
expect(prepareFile(fpathArray[i], FILE_CONTENT)).assertTrue();
}
}
var dd = fileio.opendirSync(dpath)
expect(dd !== null).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(dd.readSync() == null).assertTrue();
expect(null).assertFail();
}
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()
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()
expect(fileio.rmdirSync(fpathArray[i]) !== null).assertTrue();
} else {
expect(fileio.unlinkSync(fpathArray[i]) !== null).assertTrue()
expect(fileio.unlinkSync(fpathArray[i]) !== null).assertTrue();
}
}
expect(fileio.rmdirSync(dpath) !== null).assertTrue()
expect(fileio.rmdirSync(dpath) !== null).assertTrue();
}
})
});
/**
* @tc.number SUB_STORAGE_FileIO_dir_ReadSync_0300
......@@ -250,17 +271,18 @@ describe('fileIOTestDir', 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)
}
})
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
......@@ -272,19 +294,20 @@ describe('fileIOTestDir', function () {
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)
}
})
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
......@@ -295,23 +318,24 @@ describe('fileIOTestDir', function () {
let dpath = nextFileName('fileio_test_dir_read_sync_005') + 'd'
let fpath = dpath + '/f'
try {
expect(typeof (fileio.mkdirSync(dpath)) == "undefined").assertTrue()
expect(typeof(fileio.mkdirSync(dpath)) == 'undefined').assertTrue();
for (let i = 0; i < 10001; i++) {
expect(prepareFile(fpath + i, "test_text")).assertTrue()
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()
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)
fileio.unlinkSync(fpath + i);
}
expect(fileio.rmdirSync(dpath) !== null).assertTrue();
}
expect(fileio.rmdirSync(dpath) !== null).assertTrue()
} catch (e) {
console.log("fileio_test_dir_read_sync_005 has failed for " + e)
expect(null).assertFail()
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
......@@ -321,14 +345,15 @@ describe('fileIOTestDir', function () {
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
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();
}
});
});
{
"string": [
{
"name": "app_name",
"value": "MyApplication"
},
{
"name": "mainability_description",
"value": "JS_Phone_Empty Feature Ability"
}
]
}
\ 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("//test/xts/tools/build/suite.gni")
ohos_js_hap_suite("storagefileioperformance_js_test") {
test_hap_name = "storagefileioperformancejstest"
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": [
"storagefileioperformancejstest.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
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册