From b6c33151351ece67293803bf9b399ffff7823403 Mon Sep 17 00:00:00 2001 From: raoxian Date: Fri, 29 Apr 2022 10:54:30 +0800 Subject: [PATCH] update storagefileioerrorjstest Signed-off-by: raoxian --- storage/storagefileioerrorjstest/Test.json | 4 +- .../src/main/config.json | 6 +- .../src/main/js/default/test/Common.js | 127 +--- .../main/js/default/test/FileError.test.js | 407 ----------- .../main/js/default/test/FileIOError.test.js | 246 +------ .../js/default/test/FileVirtualPath.test.js | 663 ------------------ 6 files changed, 49 insertions(+), 1404 deletions(-) delete mode 100644 storage/storagefileioerrorjstest/src/main/js/default/test/FileError.test.js delete mode 100644 storage/storagefileioerrorjstest/src/main/js/default/test/FileVirtualPath.test.js diff --git a/storage/storagefileioerrorjstest/Test.json b/storage/storagefileioerrorjstest/Test.json index 24f1d6ed3..da66d7517 100644 --- a/storage/storagefileioerrorjstest/Test.json +++ b/storage/storagefileioerrorjstest/Test.json @@ -1,9 +1,9 @@ { - "description": "Configuration for storage file and fileio Tests", + "description": "Configuration for storage fileio Tests", "driver": { "type": "JSUnitTest", "test-timeout": "60000", - "package": "ohos.acts.stroage.fileio", + "package": "ohos.acts.storage.fileioerror", "shell-timeout": "60000" }, "kits": [ diff --git a/storage/storagefileioerrorjstest/src/main/config.json b/storage/storagefileioerrorjstest/src/main/config.json index 9b7cfe5d0..c4441ce4b 100644 --- a/storage/storagefileioerrorjstest/src/main/config.json +++ b/storage/storagefileioerrorjstest/src/main/config.json @@ -1,6 +1,6 @@ { "app": { - "bundleName": "ohos.acts.stroage.fileio", + "bundleName": "ohos.acts.storage.fileioerror", "vendor": "example", "version": { "code": 1000000, @@ -13,7 +13,7 @@ }, "deviceConfig": {}, "module": { - "package": "ohos.acts.stroage.fileio", + "package": "ohos.acts.storage.fileioerror", "name": ".MyApplication", "deviceType": [ "phone" @@ -36,7 +36,7 @@ ] } ], - "name": "ohos.acts.stroage.fileio.MainAbility", + "name": "ohos.acts.storage.fileioerror.MainAbility", "icon": "$media:icon", "description": "$string:mainability_description", "label": "$string:app_name", diff --git a/storage/storagefileioerrorjstest/src/main/js/default/test/Common.js b/storage/storagefileioerrorjstest/src/main/js/default/test/Common.js index d8e28d69a..e92b66fd9 100644 --- a/storage/storagefileioerrorjstest/src/main/js/default/test/Common.js +++ b/storage/storagefileioerrorjstest/src/main/js/default/test/Common.js @@ -13,7 +13,7 @@ * limitations under the License. */ -import fileio from '@system.fileio' +import fileio from '@ohos.fileio' export const FILE_CONTENT = 'hello world' @@ -31,133 +31,16 @@ export function prepareFile(fpath, content) { 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/storage/el2/base/haps/entry/' - return BASE_PATH + testName -} + export function nextFileName(testName) { const BASE_PATH = '/data/storage/el2/base/haps/entry/cache/' - return BASE_PATH + testName + return BASE_PATH + testName + '_' + randomString(testName.length); } export function fileName(testName) { const BASE_PATH = '/data/storage/el2/base/haps/entry/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 length:' + 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'; @@ -168,3 +51,7 @@ export function randomString(num) { } return pwd; } + +export function isIntNum(val) { + return typeof val === 'number' && val % 1 === 0; +} \ No newline at end of file diff --git a/storage/storagefileioerrorjstest/src/main/js/default/test/FileError.test.js b/storage/storagefileioerrorjstest/src/main/js/default/test/FileError.test.js deleted file mode 100644 index e2a19778e..000000000 --- a/storage/storagefileioerrorjstest/src/main/js/default/test/FileError.test.js +++ /dev/null @@ -1,407 +0,0 @@ -/* - * 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(); - }, - }); - setTimeout( - function(){ - expect(null).assertFail(); - done(); - },30) - }); - - /** - * @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(); - }, - }); - setTimeout( - function(){ - expect(null).assertFail(); - done(); - },30) - }); - - /** - * @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(); - }, - }); - setTimeout( - function(){ - expect(null).assertFail(); - done(); - },30) - }); - - /** - * @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(); - }, - }); - setTimeout( - function(){ - expect(null).assertFail(); - done(); - },30) - }); - - /** - * @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(); - }, - }); - setTimeout( - function(){ - expect(null).assertFail(); - done(); - },30) - }); - - /** - * @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); - expect(null).assertFail(); - }, - fail: function (data, code) { - console.log('file_test_error_005 call readText fail, code: ' + code + ', data: ' + data); - done(); - }, - }); - setTimeout( - function(){ - expect(null).assertFail(); - done(); - },30) - }); - - /** - * @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); - expect(null).assertFail(); - }, - fail: function (data, code) { - console.log('file_test_error_006 call readArrayBuffer fail, code: ' + code + ', data: ' + data); - done(); - }, - }); - setTimeout( - function(){ - expect(null).assertFail(); - done(); - },30) - }); - - /** - * @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)).assertTrue(); - file.rmdir({ - uri: 'internal://app/file_test_error_007', - recursive: true, - success: function () { - console.log('file_test_error_007 call rmdir success.'); - expect(null).assertFail(); - }, - fail: function (data, code) { - console.log('file_test_error_007 call rmdir fail, code: ' + code + ', data: ' + data); - done(); - }, - }); - setTimeout( - function(){ - expect(null).assertFail(); - done(); - },30) - }); - - /** - * @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(); - }, - }); - setTimeout( - function(){ - expect(null).assertFail(); - done(); - },30) - }); - - /** - * @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)).assertTrue(); - file.rmdir({ - uri: 'internal://app/file_test_error_009d', - recursive: true, - success: function () { - console.log('file_test_error_009 call rmdir success.'); - expect(null).assertFail(); - }, - fail: function (data, code) { - console.log('file_test_error_009 call rmdir fail, code: ' + code + ', data: ' + data); - done(); - }, - }); - setTimeout( - function(){ - expect(null).assertFail(); - done(); - },30) - }); - - /** - * @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)).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(); - }, - }); - setTimeout( - function(){ - expect(null).assertFail(); - done(); - },30) - }); - - /** - * @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(); - }, - }); - setTimeout( - function(){ - expect(null).assertFail(); - done(); - },30) - }); - - /** - * @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(); - }, - }); - }, - }); - setTimeout( - function(){ - expect(null).assertFail(); - done(); - },30) - }); -}); diff --git a/storage/storagefileioerrorjstest/src/main/js/default/test/FileIOError.test.js b/storage/storagefileioerrorjstest/src/main/js/default/test/FileIOError.test.js index 4e2c3f792..e709b1ce4 100644 --- a/storage/storagefileioerrorjstest/src/main/js/default/test/FileIOError.test.js +++ b/storage/storagefileioerrorjstest/src/main/js/default/test/FileIOError.test.js @@ -19,194 +19,19 @@ import { it, expect } - from 'deccjsunit/index' +from 'deccjsunit/index' import { FILE_CONTENT, prepareFile, fileName, nextFileName, - appName, randomString, + isIntNum } - from './Common' +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(); - expect(null).assertFail(); - } - catch (e) { - console.log('fileio_test_error_001 has failed for ' + e); - } - }); - - /** - * @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(); - expect(null).assertFail(); - } - catch (e) { - console.log('fileio_test_error_005 has failed for ' + e); - } - }); - - /** - * @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(); - expect(null).assertFail(); - } - catch (e) { - console.log('fileio_test_error_006 has failed for ' + e); - } - }); - - /** - * @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(); - expect(null).assertFail(); - } - catch (e) { - console.log('fileio_test_error_007 has failed for ' + e); - } - }); - - /** - * @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(); - expect(null).assertFail(); - } - catch (e) { - console.log('fileio_test_error_008 has failed for ' + e); - } - }); - /** * @tc.number SUB_STORAGE_FileIo_test_error_0900 * @tc.name FileIo_test_error_009 @@ -218,8 +43,9 @@ describe('FileIOError', function () { fileio.mkdirSync(dpath); expect(prepareFile(fpath, 'hello')).assertTrue(); try { - expect(fileio.rmdirSync(dpath) !== null).assertTrue(); - expect(null).assertFail(); + let fd = fileio.openSync(dpath); + expect(isIntNum(fd)).assertTrue(); + fileio.rmdirSync(dpath); } catch (e) { console.log('fileio_test_error_009 has failed for ' + e); @@ -229,7 +55,7 @@ describe('FileIOError', function () { }); /** - * @tc.number SUB_STORAGE_FileIo_test_error1000 + * @tc.number SUB_STORAGE_FileIo_test_error_1000 * @tc.name FileIo_test_error_010 * @tc.desc Function of API, delete file */ @@ -237,7 +63,9 @@ describe('FileIOError', function () { let fpath = fileName('fileio_test_error_010f'); expect(prepareFile(fpath, 'hello')).assertTrue(); try { - expect(fileio.rmdirSync(fpath) !== null).assertTrue(); + let fd = fileio.openSync(fpath); + expect(isIntNum(fd)).assertTrue(); + fileio.rmdirSync(fpath); expect(null).assertFail(); } catch (e) { @@ -254,30 +82,30 @@ describe('FileIOError', function () { */ it('FileIo_test_error_011', 0, function () { let fpath = nextFileName('fileio_test_error_011'); - fileio.openSync(fpath, 0o102, 0o777); + let fd = fileio.openSync(fpath, 0o102, 0o777); + expect(isIntNum(fd)).assertTrue(); 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'); + fileio.copyFileSync(fpath, fpathTarget); 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); + fileio.unlinkSync(fpath); } }); /** - * @tc.number SUB_STORAGE_FileIo_test_error_0120 + * @tc.number SUB_STORAGE_FileIo_test_error_1200 * @tc.name FileIo_test_error_012 * @tc.desc Function of API, flags=0o102. The test file is exist. */ @@ -290,12 +118,12 @@ describe('FileIOError', function () { } catch (e) { console.log('FileIo_test_error_012 has failed for ' + e); - expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + fileio.unlinkSync(fpath); } }); /** - * @tc.number SUB_STORAGE_FileIO_OpenSync_0130 + * @tc.number SUB_STORAGE_FileIO_OpenSync_1300 * @tc.name FileIo_test_error_013 * @tc.desc Function of API, flags=0o102 */ @@ -311,7 +139,7 @@ describe('FileIOError', function () { }); /** - * @tc.number SUB_STORAGE_FileIO_OpenSync_0140 + * @tc.number SUB_STORAGE_FileIO_OpenSync_1400 * @tc.name FileIo_test_error_014 * @tc.desc Function of API, flags=0o202. The test file is exist. */ @@ -324,12 +152,12 @@ describe('FileIOError', function () { } catch (e) { console.log('FileIo_test_error_014 has failed for ' + e); - expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + fileio.unlinkSync(fpath); } }); /** - * @tc.number SUB_STORAGE_FileIO_OpenSync_0150 + * @tc.number SUB_STORAGE_FileIO_OpenSync_1500 * @tc.name FileIo_test_error_015 * @tc.desc Function of API, flags=0o302. The test file is exist. */ @@ -337,17 +165,16 @@ describe('FileIOError', function () { let fpath = nextFileName('FileIo_test_error_015'); expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); try { - fileio.openSync(fpath, 0o302); - expect(null).assertFail(); + fileio.openSync(fpath, 0o302, 0o666); } catch (e) { console.log('FileIo_test_error_015 has failed for ' + e); - expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + fileio.unlinkSync(fpath); } }); /** - * @tc.number SUB_STORAGE_FileIO_OpenSync_0160 + * @tc.number SUB_STORAGE_FileIO_OpenSync_1600 * @tc.name FileIo_test_error_016 * @tc.desc Function of API, flags=0o100002. The test file is exist. */ @@ -360,30 +187,30 @@ describe('FileIOError', function () { } catch (e) { console.log('FileIo_test_error_016 has failed for ' + e); - expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + fileio.unlinkSync(fpath); } }); /** - * @tc.number SUB_STORAGE_FileIO_OpenSync_0170 + * @tc.number SUB_STORAGE_FileIO_OpenSync_1700 * @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(); + fileio.mkdirSync(dpath); 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(); + fileio.rmdirSync(dpath); } }); /** - * @tc.number SUB_STORAGE_FileIO_OpenSync_0180 + * @tc.number SUB_STORAGE_FileIO_OpenSync_1800 * @tc.name FileIo_test_error_018 * @tc.desc Function of API, flags=0o20040002. The test file is exist. */ @@ -399,7 +226,7 @@ describe('FileIOError', function () { }); /** - * @tc.number SUB_STORAGE_FileIO_OpenSync_0190 + * @tc.number SUB_STORAGE_FileIO_OpenSync_1900 * @tc.name FileIo_test_error_019 * @tc.desc Function of API, flags=0o400002. The test file is exist. */ @@ -413,12 +240,12 @@ describe('FileIOError', function () { } catch (e) { console.log('FileIo_test_error_019 has failed for ' + e); - expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + fileio.unlinkSync(fpath); } }); /** - * @tc.number SUB_STORAGE_FileIO_OpenSync_0200 + * @tc.number SUB_STORAGE_FileIO_OpenSync_2000 * @tc.name FileIo_test_error_020 * @tc.desc Function of API, flags=0o400002. The test file is exist. */ @@ -432,12 +259,12 @@ describe('FileIOError', function () { } catch (e) { console.log('FileIo_test_error_020 has failed for ' + e); - expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + fileio.unlinkSync(fpath); } }); /** - * @tc.number SUB_STORAGE_FileIO_OpenSync_0210 + * @tc.number SUB_STORAGE_FileIO_OpenSync_2100 * @tc.name FileIo_test_error_021 * @tc.desc Function of API, flags=0o10000102. The test file is exist. */ @@ -453,7 +280,7 @@ describe('FileIOError', function () { }); /** - * @tc.number SUB_STORAGE_FileIO_OpenSync_0220 + * @tc.number SUB_STORAGE_FileIO_OpenSync_2200 * @tc.name FileIo_test_error_022 * @tc.desc Function of API,mode=1 The test file is exist. */ @@ -466,8 +293,9 @@ describe('FileIOError', function () { expect(null).assertFail(); } catch (e) { - console.log('FileIo_test_error_021 has failed for ' + e); - expect(fileio.unlinkSync(fpath) !== null).assertTrue(); + console.log('FileIo_test_error_022 has failed for ' + e); + fileio.unlinkSync(fpath); + fileio.unlinkSync(fpathTarget); } }); diff --git a/storage/storagefileioerrorjstest/src/main/js/default/test/FileVirtualPath.test.js b/storage/storagefileioerrorjstest/src/main/js/default/test/FileVirtualPath.test.js deleted file mode 100644 index 77ad57700..000000000 --- a/storage/storagefileioerrorjstest/src/main/js/default/test/FileVirtualPath.test.js +++ /dev/null @@ -1,663 +0,0 @@ -/* - * 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, - nextFileName -} - 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(); - }, - }); - setTimeout( - function(){ - expect(null).assertFail(); - done(); - },30) - }); - - /** - * @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(); - }, - }); - setTimeout( - function(){ - expect(null).assertFail(); - done(); - },30) - }); - - /** - * @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(); - }, - }); - setTimeout( - function(){ - expect(null).assertFail(); - done(); - },30) - }); - - /** - * @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' - }); - setTimeout( - function(){ - expect(null).assertFail(); - done(); - },30) - }); - - /** - * @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' - }); - setTimeout( - function(){ - expect(null).assertFail(); - done(); - },30) - }); - - /** - * @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(); - }, - }); - setTimeout( - function(){ - expect(null).assertFail(); - done(); - },30) - }); - - /** - * @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' - }); - setTimeout( - function(){ - expect(null).assertFail(); - done(); - },30) - }); - - /** - * @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(); - }, - }); - setTimeout( - function(){ - expect(null).assertFail(); - done(); - },30) - }); - - /** - * @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(); - }, - }); - setTimeout( - function(){ - expect(null).assertFail(); - done(); - },30) - }); - - /** - * @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(); - }, - }); - setTimeout( - function(){ - expect(null).assertFail(); - done(); - },30) - }); - - /** - * @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(); - }, - }); - setTimeout( - function(){ - expect(null).assertFail(); - done(); - },30) - }); - - /** - * @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(); - }, - }); - setTimeout( - function(){ - expect(null).assertFail(); - done(); - },30) - }); - - /** - * @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)).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(); - }, - }); - setTimeout( - function(){ - expect(null).assertFail(); - done(); - },30) - }); - - /** - * @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')).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(); - }, - }); - setTimeout( - function(){ - expect(null).assertFail(); - done(); - },30) - }); - - /** - * @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(); - }, - }); - setTimeout( - function(){ - expect(null).assertFail(); - done(); - },30) - }); - - /** - * @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(); - }, - }); - setTimeout( - function(){ - expect(null).assertFail(); - done(); - },30) - }); - - /** - * @tc.number SUB_STORAGE_fileioPerformance_prop_copyFile - * @tc.name fileioPerformance_prop_copyFile - * @tc.desc 0.5G Synchronous opening performance test of test files - * The path needs to be manually placed in advance - * data/accounts/account_0/appdata/ohos.acts.distributeddatamgr.distributedfile/cache/p1'的0.5g文件) - */ - it('fileioPerformance_prop_copyFile', 0, function () { - console.log('---fileioPerformance_prop_copyFile 0.5G---start---'); - let fpath = nextFileName('p1'); - let fpathTarget = nextFileName('p2'); - for (let i = 0; i < 1000; i++) { - let start2 = new Date().getTime(); - let copyFileSync = fileio.copyFileSync(fpath, fpathTarget); - let end2 = new Date().getTime(); - let time2 = end2 - start2 - console.log('fileioPerformance_prop_copyFileSync,copyFileSync:' + copyFileSync + ', time2:' + time2 + ',' + i); - fileio.unlinkSync(fpathTarget); - } - fileio.closeSync(fd); - setTimeout( - function(){ - expect(null).assertFail(); - done(); - },30) - }); - - /** - * @tc.number SUB_STORAGE_fileioPerformance_prop_openSync - * @tc.name fileioPerformance_prop_openSync - * @tc.desc 0.5G Synchronous opening performance test of test files - * The path needs to be manually placed in advance - * data/accounts/account_0/appdata/ohos.acts.distributeddatamgr.distributedfile/cache/p1'的0.5g文件) - */ - it('fileioPerformance_prop_openSync', 0, function () { - console.log('---fileioPerformance_prop_openSync 0.5G---start---'); - let fpath = nextFileName('p1'); - let fd - for (let i = 0; i < 1000; i++) { - let start = new Date().getTime(); - fd = fileio.openSync(fpath, 0o2002); - let end = new Date().getTime(); - let time = end - start - console.log('fileioPerformance_prop_openSync,openSync:' + fd + ', time:' + time + ',' + i); - } - fileio.closeSync(fd); - setTimeout( - function(){ - expect(null).assertFail(); - done(); - },30) - }); - -}); -- GitLab