diff --git a/storage/BUILD.gn b/storage/BUILD.gn index c28cdb205bbf00061ef28d8702e4e222159364af..f07f9d9493d854f6424b53849d0567ab90d668d5 100644 --- a/storage/BUILD.gn +++ b/storage/BUILD.gn @@ -16,9 +16,14 @@ group("storage") { testonly = true if (is_standard_system) { deps = [ + "storagedsmjstest:storagedsm_js_test", + + # "storagedsmstabilityjstest:storagedsmstability_js_test", "storagefileconcurrentjstest:storagefileconcurrent_js_test", "storagefileioerrorjstest:storagefileioerror_js_test", "storagefileiojstest:storagefileio_js_test", + "storagefmspublicjstest:storagefmspublic_js_test", + "storagefmssharejstest:storagefmsshare_js_test", # "storagefileioperformancejstest:storagefileioperformance_js_test", # "storagefileioreliabilityjstest:storagefileioreliability_js_test", diff --git a/storage/storagedsmjstest/BUILD.gn b/storage/storagedsmjstest/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..f605e04f1e3aea5009bf171b94dbe768bbf3dd8f --- /dev/null +++ b/storage/storagedsmjstest/BUILD.gn @@ -0,0 +1,38 @@ +# 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("storagedsm_js_test") { + hap_profile = "./src/main/config.json" + deps = [ + ":storagedsm_js_assets", + ":storagedsm_js_resources", + ] + + # shared_libraries = [ + # "//third_party/giflib:libgif", + # "//third_party/libpng:libpng", + # ] + certificate_profile = "./signature/openharmony_sx.p7b" + hap_name = "storagedsmjstest" + + # part_name = "prebuilt_hap" + # subsystem_name = "xts" +} +ohos_js_assets("storagedsm_js_assets") { + source_dir = "./src/main/js/default" +} +ohos_resources("storagedsm_js_resources") { + sources = [ "./src/main/resources" ] + hap_profile = "./src/main/config.json" +} diff --git a/storage/storagedsmjstest/Test.json b/storage/storagedsmjstest/Test.json new file mode 100644 index 0000000000000000000000000000000000000000..4d5073412c3c9800aa1e4be440198263a74e080f --- /dev/null +++ b/storage/storagedsmjstest/Test.json @@ -0,0 +1,18 @@ +{ + "description": "Configuration for storage file and fileio Tests", + "driver": { + "type": "JSUnitTest", + "test-timeout": "60000", + "package": "ohos.acts.stroage.fileio", + "shell-timeout": "60000" + }, + "kits": [ + { + "test-file-name": [ + "storagefmspublicjstest.hap" + ], + "type": "AppInstallKit", + "cleanup-apps": true + } + ] +} \ No newline at end of file diff --git a/storage/storagedsmjstest/signature/openharmony_sx.p7b b/storage/storagedsmjstest/signature/openharmony_sx.p7b new file mode 100644 index 0000000000000000000000000000000000000000..9be1e98fa4c0c28ca997ed660112fa16b194f0f5 Binary files /dev/null and b/storage/storagedsmjstest/signature/openharmony_sx.p7b differ diff --git a/storage/storagedsmjstest/src/main/config.json b/storage/storagedsmjstest/src/main/config.json new file mode 100644 index 0000000000000000000000000000000000000000..9b7cfe5d04d1f2f807e5c7dc8ceff403cde6a9df --- /dev/null +++ b/storage/storagedsmjstest/src/main/config.json @@ -0,0 +1,61 @@ +{ + "app": { + "bundleName": "ohos.acts.stroage.fileio", + "vendor": "example", + "version": { + "code": 1000000, + "name": "1.0.0" + }, + "apiVersion": { + "compatible": 4, + "target": 5 + } + }, + "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 diff --git a/storage/storagedsmjstest/src/main/js/default/app.js b/storage/storagedsmjstest/src/main/js/default/app.js new file mode 100644 index 0000000000000000000000000000000000000000..60ee141c8dbd251c763b7b74552b5a133a774d6a --- /dev/null +++ b/storage/storagedsmjstest/src/main/js/default/app.js @@ -0,0 +1,23 @@ +/* + * Copyright (C) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export default { + onCreate() { + console.info('ohos.acts.distributeddatamgr.distributedfile onCreate'); + }, + onDestroy() { + console.info('ohos.acts.distributeddatamgr.distributedfile onCreate'); + } +}; diff --git a/storage/storagedsmjstest/src/main/js/default/i18n/en-US.json b/storage/storagedsmjstest/src/main/js/default/i18n/en-US.json new file mode 100644 index 0000000000000000000000000000000000000000..ead52ed2e09ec82aaf7aa9f4e714ed39ea88308e --- /dev/null +++ b/storage/storagedsmjstest/src/main/js/default/i18n/en-US.json @@ -0,0 +1,6 @@ +{ + "strings": { + "hello": "Hello", + "world": "Test" + } +} \ No newline at end of file diff --git a/storage/storagedsmjstest/src/main/js/default/i18n/zh-CN.json b/storage/storagedsmjstest/src/main/js/default/i18n/zh-CN.json new file mode 100644 index 0000000000000000000000000000000000000000..3f48f2585b24a8fe4a745e8ee2972a9e991a7803 --- /dev/null +++ b/storage/storagedsmjstest/src/main/js/default/i18n/zh-CN.json @@ -0,0 +1,6 @@ +{ + "strings": { + "hello": "您好", + "world": "测试" + } +} \ No newline at end of file diff --git a/storage/storagedsmjstest/src/main/js/default/pages/index/index.css b/storage/storagedsmjstest/src/main/js/default/pages/index/index.css new file mode 100644 index 0000000000000000000000000000000000000000..6fda792753f2e15f22b529c7b90a82185b2770bf --- /dev/null +++ b/storage/storagedsmjstest/src/main/js/default/pages/index/index.css @@ -0,0 +1,9 @@ +.container { + flex-direction: column; + justify-content: center; + align-items: center; +} + +.title { + font-size: 100px; +} diff --git a/storage/storagedsmjstest/src/main/js/default/pages/index/index.hml b/storage/storagedsmjstest/src/main/js/default/pages/index/index.hml new file mode 100644 index 0000000000000000000000000000000000000000..f64b040a5ae394dbaa5e185e1ecd4f4556b92184 --- /dev/null +++ b/storage/storagedsmjstest/src/main/js/default/pages/index/index.hml @@ -0,0 +1,5 @@ +
+ + {{ $t('strings.hello') }} {{ title }} + +
diff --git a/storage/storagedsmjstest/src/main/js/default/pages/index/index.js b/storage/storagedsmjstest/src/main/js/default/pages/index/index.js new file mode 100644 index 0000000000000000000000000000000000000000..f7894a72230dd2356d1ce272896c9e0fd09e08cd --- /dev/null +++ b/storage/storagedsmjstest/src/main/js/default/pages/index/index.js @@ -0,0 +1,40 @@ +/* + * 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 app from '@system.app' + +import {Core} from 'deccjsunit/index' + +const injectRef = Object.getPrototypeOf(global) || global +injectRef.regeneratorRuntime = require('@babel/runtime/regenerator') + +export default { + data: { + title: '' + }, + onInit() { + this.title = this.$t('strings.world'); + }, + onShow() { + console.info('onShow finish') + 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 diff --git a/storage/storagedsmjstest/src/main/js/default/test/Common.js b/storage/storagedsmjstest/src/main/js/default/test/Common.js new file mode 100644 index 0000000000000000000000000000000000000000..c7b15f7ce870c57af41cbaadd146c05ba0b91c0d --- /dev/null +++ b/storage/storagedsmjstest/src/main/js/default/test/Common.js @@ -0,0 +1,192 @@ +/* + * 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 filePickerName(testName,deviceID) { + const BASE_PATH = '/data/ss/'+deviceID+'/fms_test/' + return BASE_PATH + testName +} +export function filePickerName1(testName,deviceID) { + const BASE_PATH = '/data/ss/'+ deviceID +'/fms_test/' + return BASE_PATH + testName +} +export function filePickerName2(testName,deviceID) { + const BASE_PATH = '/data/ss/'+ deviceID + return BASE_PATH + testName +} +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 fmsFileName(testName) { + const BASE_PATH = "/data/accounts/account_0/appdata/ohos.acts.test/files/" + return BASE_PATH + testName +} +export function fmsCacheName(testName) { + const BASE_PATH = "/data/accounts/account_0/appdata/ohos.acts.test/cache/" + return BASE_PATH + testName +} +export function fmsPublic(testName) { + const BASE_PATH = '/data/ss/files/' + 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; +} diff --git a/storage/storagedsmjstest/src/main/js/default/test/Dsm.test.js b/storage/storagedsmjstest/src/main/js/default/test/Dsm.test.js new file mode 100644 index 0000000000000000000000000000000000000000..9565b1d85c48797718fd86ccfb191253ecf8ce79 --- /dev/null +++ b/storage/storagedsmjstest/src/main/js/default/test/Dsm.test.js @@ -0,0 +1,544 @@ +/* + * 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 devicesmgr from '@system.devicesmgr'; +import { + describe, + beforeAll, + beforeEach, + afterEach, + afterAll, + it, + expect +} +from 'deccjsunit/index' + +describe('dsmTest', function () { + + /** + * @tc.number SUB_STORAGE_DSM_JS_Function_0000 + * @tc.name DSM_JS_Function_0000 + * @tc.desc Insert SD card to start up in shutdown state + */ + it('DSM_JS_Function_0000', 0, function () { + devicesmgr.getVolumes({ + success: function (data) { + console.log('DSM_JS_Function_0000 call getVolumes success. data:' + JSON.stringify(data)); + expect(data.volumeInfos[2].mId !== null).assertTrue(); + expect(data.volumeInfos[2].mState == 2).assertTrue(); + }, + fail: function (data, code) { + console.log('DSM_JS_Function_0000 call getVolumes fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + }) + + /** + * @tc.number SUB_STORAGE_DSM_JS_Function_0100 + * @tc.name DSM_JS_Function_0100 + * @tc.desc Insert SD card in power on state + */ + it('DSM_JS_Function_0100', 0, function () { + devicesmgr.getVolumes({ + success: function (data) { + console.log('DSM_JS_Function_0100 call getVolumes success. data:' + JSON.stringify(data)); + expect(data.volumeInfos[2].mId !== null).assertTrue(); + expect(data.volumeInfos[2].mState == 2).assertTrue(); + }, + fail: function (data, code) { + console.log('DSM_JS_Function_0100 call getVolumes fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + }) + + /** + * @tc.number SUB_STORAGE_DSM_JS_Function_0200 + * @tc.name DSM_JS_Function_0200 + * @tc.desc Unplug the SD card in the power on state + */ + it('DSM_JS_Function_0200', 0, function () { + devicesmgr.getVolumes({ + success: function (data) { + console.log('DSM_JS_Function_0200 call getVolumes success. data:' + JSON.stringify(data)); + for (let i = 0; i < data.volumeInfos.length; i++) { + expect(typeof(data.volumeInfos[i].mId) == 'string').assertTrue(); + expect(typeof(data.volumeInfos[i].mDiskId) == 'string').assertTrue(); + expect(typeof(data.volumeInfos[i].mPartGuid) == 'string').assertTrue(); + expect(typeof(data.volumeInfos[i].mFsUuid) == 'string').assertTrue(); + expect(typeof(data.volumeInfos[i].mType) == 'number').assertTrue(); + expect(typeof(data.volumeInfos[i].mMountFlags) == 'number').assertTrue(); + expect(typeof(data.volumeInfos[i].mMountUserId) == 'number').assertTrue(); + expect(typeof(data.volumeInfos[i].mState) == 'number').assertTrue(); + expect(typeof(data.volumeInfos[i].mPath) == 'string').assertTrue(); + expect(typeof(data.volumeInfos[i].mInternalPath) == 'string').assertTrue(); + expect(typeof(data.volumeInfos[i].mFsLabel) == 'string').assertTrue(); + expect(typeof(data.volumeInfos[i].Description) == 'string').assertTrue(); + expect(typeof(data.volumeInfos[i].IsVisibleForUser) == 'boolean').assertTrue(); + expect(typeof(data.volumeInfos[i].IsEmulated) == 'boolean').assertTrue(); + expect(typeof(data.volumeInfos[i].IsPrimaryEmulatedForUser) == 'boolean').assertTrue(); + expect(typeof(data.volumeInfos[i].IsRemovable) == 'boolean').assertTrue(); + expect(typeof(data.volumeInfos[i].IsPrimary) == 'boolean').assertTrue(); + } + }, + fail: function (data, code) { + console.log('DSM_JS_Function_0200 call getVolumes fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + }) + + /** + * @tc.number SUB_STORAGE_DSM_JS_Function_0300 + * @tc.name DSM_JS_Function_0300 + * @tc.desc Uninstall SD card. + */ + it('DSM_JS_Function_0300', 0, function () { + let mId = 0; + devicesmgr.getVolumes({ + success: function (data) { + console.log('DSM_JS_Function_0300 call getVolumes success.' + JSON.stringify(data)); + mId = data.volumeInfos[2].mId; + }, + fail: function (data, code) { + console.log('DSM_JS_Function_0300 call getVolumes fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + devicesmgr.unMount({ + volId: mId, + success: function () { + console.log('DSM_JS_Function_0300 call unMount success.'); + }, + fail: function (data, code) { + console.log('DSM_JS_Function_0300 call unMount fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + } + }) + devicesmgr.getVolumes({ + success: function (data) { + console.log('DSM_JS_Function_0300 call getVolumes success.' + JSON.stringify(data)); + for (let i = 0; i < data.getDisks.length; i++) { + expect(data.volumeInfos[i].mId !== 'public:179,33').assertTrue(); + expect(data.volumeInfos[i].mState !== 2).assertTrue(); + } + }, + fail: function (data, code) { + console.log('DSM_JS_Function_0300 call getVolumes fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }) + }) + + /** + * @tc.number SUB_STORAGE_DSM_JS_Function_0400 + * @tc.name DSM_JS_Function_0400 + * @tc.desc Mount SD card. + */ + it('DSM_JS_Function_0400', 0, function () { + devicesmgr.mount({ + volId: 'public:179,33', + success: function () { + devicesmgr.getVolumes({ + success: function (data) { + console.log('DSM_JS_Function_0400 call getVolumes success. data:' + JSON.stringify(data)); + expect(data.volumeInfos[2].mState == 2).assertTure() + expect(data.volumeInfos[2].mInternalPath !== null).assertTure() + }, + fail: function (data, code) { + console.log('DSM_JS_Function_0400 call getVolumes fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }) + }, + }) + }) + + /** + * @tc.number SUB_STORAGE_DSM_JS_Function_0700 + * @tc.name DSM_JS_Function_0700 + * @tc.desc Obtain disk information and check whether it is successful. + */ + it('DSM_JS_Function_0700', 0, function () { + devicesmgr.getDisks({ + success: function (data) { + console.log('DSM_JS_Function_0700 call getDisks success.' + JSON.stringify(data)); + expect(data.getDisks[2].Description == 'SD card').assertTrue() + }, + fail: function (data, code) { + console.log('DSM_JS_Function_0700 call getDisks fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }) + }) + + /** + * @tc.number SUB_STORAGE_DSM_JS_Function_0800 + * @tc.name DSM_JS_Function_0800 + * @tc.desc Find the corresponding volume information through the volume ID + */ + it('DSM_JS_Function_0800', 0, function () { + let mId; + devicesmgr.getVolumes({ + success: function (data) { + console.log('DSM_JS_Function_0800 call getVolumes success' + JSON.stringify(data)); + mId = data.volumeInfos[2].mId; + }, + fail: function (data, code) { + console.log('DSM_JS_Function_0800 call getVolumes fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + devicesmgr.findVolumeById({ + volId: mId, + success: function (vol) { + console.log('DSM_JS_Function_0800 call findVolumeById success' + JSON.stringify(vol)) + expect(vol.volumeInfos[2].mId !== null).assertTrue(); + expect(vol.volumeInfos[2].mState == 2).assertTrue(); + }, + fail: function (data, code) { + console.log('DSM_JS_Function_0800 call findVolumeById fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }) + }) + + /** + * @tc.number SUB_STORAGE_DSM_JS_Function_0900 + * @tc.name DSM_JS_Function_0900 + * @tc.desc Find the corresponding volume information through the volume ID + */ + it('DSM_JS_Function_0900', 0, function () { + let mId; + devicesmgr.getVolumes({ + success: function (data) { + console.log('DSM_JS_Function_0900 call getVolumes success' + JSON.stringify(data)); + mId = data.volumeInfos[0].mId; + }, + fail: function (data, code) { + console.log('DSM_JS_Function_0900 call getVolumes fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + devicesmgr.findVolumeById({ + volId: mId, + success: function (vol) { + console.log('DSM_JS_Function_0900 call findVolumeById success' + JSON.stringify(vol)) + expect(vol.volumeInfos[0].mId == 'emulated;0').assertTrue(); + expect(vol.volumeInfos[0].mInternalPath !== null).assertTrue(); + }, + fail: function (data, code) { + console.log('DSM_JS_Function_0900 call findVolumeById fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }) + }) + + /** + * @tc.number SUB_STORAGE_DSM_JS_Function_1000 + * @tc.name DSM_JS_Function_1000 + * @tc.desc Find the corresponding volume information through the volume ID + */ + it('DSM_JS_Function_1000', 0, function () { + let mId; + devicesmgr.getVolumes({ + success: function (data) { + console.log('DSM_JS_Function_0900 call getVolumes success' + JSON.stringify(data)); + mId = data.volumeInfos[1].mId; + }, + fail: function (data, code) { + console.log('DSM_JS_Function_0900 call getVolumes fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + devicesmgr.findVolumeById({ + volId: mId, + success: function (vol) { + console.log('DSM_JS_Function_1000 call findVolumeById success' + JSON.stringify(vol)) + expect(vol.volumeInfos[1].mId == 'private').assertTrue(); + expect(vol.volumeInfos[1].mState == 2).assertTrue(); + }, + fail: function (data, code) { + console.log('DSM_JS_Function_1000 call findVolumeById fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }) + }) + + /** + * @tc.number SUB_STORAGE_DSM_JS_Function_1100 + * @tc.name DSM_JS_Function_1100 + * @tc.desc Obtain the corresponding volume information through the UUID of the volume + */ + it('DSM_JS_Function_1100', 0, function () { + let mFsUuid; + devicesmgr.getVolumes({ + success: function (data) { + console.log('DSM_JS_Function_1100 call getVolumes success' + JSON.stringify(data)); + mFsUuid = data.volumeInfos[2].mFsUuid; + }, + fail: function (data, code) { + console.log('DSM_JS_Function_1100 call getVolumes fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + devicesmgr.findVolumeByUuid({ + volumeUuid: mFsUuid, + success: function (vol) { + console.log('DSM_JS_Function_1100 call findVolumeByUuid success' + JSON.stringify(vol)) + expect(vol.volumeInfos[2].mId !== null).assertTrue(); + expect(vol.volumeInfos[2].mState == 2).assertTrue(); + }, + fail: function (data, code) { + console.log('DSM_JS_Function_1100 call findVolumeByUuid fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }) + }) + + /** + * @tc.number SUB_STORAGE_DSM_JS_Function_1200 + * @tc.name DSM_JS_Function_1200 + * @tc.desc Get information about writable volumes + */ + it('DSM_JS_Function_1200', 0, function () { + devicesmgr.getWritableVolumes({ + success: function (data) { + console.log('DSM_JS_Function_1200 call getWritableVolumes success. data:' + JSON.stringify(data)); + for (let i = 0; i < data.volumeInfos.length; i++) { + expect(typeof(data.volumeInfos[i].mId) == 'string').assertTrue(); + expect(typeof(data.volumeInfos[i].mDiskId) == 'string').assertTrue(); + expect(typeof(data.volumeInfos[i].mPartGuid) == 'string').assertTrue(); + expect(typeof(data.volumeInfos[i].mFsUuid) == 'string').assertTrue(); + expect(typeof(data.volumeInfos[i].mType) == 'number').assertTrue(); + expect(typeof(data.volumeInfos[i].mMountFlags) == 'number').assertTrue(); + expect(typeof(data.volumeInfos[i].mMountUserId) == 'number').assertTrue(); + expect(typeof(data.volumeInfos[i].mState) == 'number').assertTrue(); + expect(typeof(data.volumeInfos[i].mPath) == 'string').assertTrue(); + expect(typeof(data.volumeInfos[i].mInternalPath) == 'string').assertTrue(); + expect(typeof(data.volumeInfos[i].mFsLabel) == 'string').assertTrue(); + expect(typeof(data.volumeInfos[i].Description) == 'string').assertTrue(); + expect(typeof(data.volumeInfos[i].IsVisibleForUser) == 'boolean').assertTrue(); + expect(typeof(data.volumeInfos[i].IsEmulated) == 'boolean').assertTrue(); + expect(typeof(data.volumeInfos[i].IsPrimaryEmulatedForUser) == 'boolean').assertTrue(); + expect(typeof(data.volumeInfos[i].IsRemovable) == 'boolean').assertTrue(); + expect(typeof(data.volumeInfos[i].IsPrimary) == 'boolean').assertTrue(); + } + }, + fail: function (data, code) { + console.log('DSM_JS_Function_1200 call getWritableVolumes fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + }) + + /** + * @tc.number SUB_STORAGE_DSM_JS_Function_1300 + * @tc.name DSM_JS_Function_1300 + * @tc.desc Obtain the corresponding disk information through the disk ID + */ + it('DSM_JS_Function_1300', 0, function () { + let mDiskId; + devicesmgr.getVolumes({ + success: function (data) { + console.log('DSM_JS_Function_1300 call getVolumes success' + data); + mDiskId = data.volumeInfos[2].mDiskId; + console.log('DSM_JS_Function_1300---' + data.volumeInfos[2].mDiskId); + }, + fail: function (data, code) { + console.log('DSM_JS_Function_1300 call getVolumes fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + devicesmgr.findDiskById({ + diskId: mDiskId, + success: function (disk) { + console.log('DSM_JS_Function_1300 call findDiskById success' + JSON.stringify(disk)) + expect(disk.findDiskById[0].mId == mDiskId).assertTrue(); + }, + fail: function (data, code) { + console.log('DSM_JS_Function_1300 call findDiskById fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }) + }) + + /** + * @tc.number SUB_STORAGE_DSM_JS_Function_1400 + * @tc.name DSM_JS_Function_1400 + * @tc.desc Get UUID of primary storage + */ + it('DSM_JS_Function_1400', 0, function () { + devicesmgr.getPrimaryStorageUuid({ + success: function (primaryUuid) { + console.log('DSM_JS_Function_1400 call getPrimaryStorageUuid success.' + JSON.stringify(primaryUuid)); + }, + fail: function (data, code) { + console.log('DSM_JS_Function_1400 call getPrimaryStorageUuid fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + }) + + /** + * @tc.number SUB_STORAGE_DSM_JS_Function_1500 + * @tc.name DSM_JS_Function_1500 + * @tc.desc Find its corresponding private volume through simulate volume + */ + it('DSM_JS_Function_1500', 0, function () { + let emuVol; + devicesmgr.getVolumes({ + success: function (data) { + console.log('DSM_JS_Function_1500 call getVolumes success' + data); + emuVol = data.volumeInfos[0] + }, + fail: function (data, code) { + console.log('DSM_JS_Function_1500 call getVolumes fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + devicesmgr.findPrivateForEmulate({ + emuVol: emuVol, + success: function (priVol) { + console.log('DSM_JS_Function_1500 call findPrivateForEmulate success' + JSON.stringify(priVol)) + expect(priVol.volumeInfos[1].mId == 'private').assertTrue(); + expect(priVol.volumeInfos[1].mState == 2).assertTrue(); + }, + fail: function (data, code) { + console.log('DSM_JS_Function_1500 call findPrivateForEmulate fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }) + }) + + /** + * @tc.number SUB_STORAGE_DSM_JS_Function_1600 + * @tc.name DSM_JS_Function_1600 + * @tc.desc Find its corresponding emulated volume through private volume + */ + it('DSM_JS_Function_1600', 0, function () { + var priVol; + devicesmgr.getVolumes({ + success: function (data) { + console.log('DSM_JS_Function_1600 call getVolumes success' + data); + priVol = data.volumeInfos[1] + }, + fail: function (data, code) { + console.log('DSM_JS_Function_1600 call getVolumes fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + devicesmgr.findEmulateForPrivate({ + priVol: priVol, + success: function (emuVol) { + console.log('DSM_JS_Function_1600 call findEmulateForPrivate success' + JSON.stringify(emuVol)) + expect(priVol.volumeInfos[0].mId == 'emulated;0').assertTrue(); + }, + fail: function (data, code) { + console.log('DSM_JS_Function_1600 call findEmulateForPrivate fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }) + }) + + /** + * @tc.number SUB_STORAGE_DSM_JS_Function_1700 + * @tc.name DSM_JS_Function_1700 + * @tc.desc Get the name of the volume (SD card) + */ + it('DSM_JS_Function_1700', 0, function () { + var vol; + devicesmgr.getVolumes({ + success: function (data) { + console.log('DSM_JS_Function_1700 call getVolumes success' + data); + vol = data.volumeInfos[2] + }, + fail: function (data, code) { + console.log('DSM_JS_Function_1700 call getVolumes fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + devicesmgr.getBestVolumeDescription({ + vol: vol, + success: function (desCription) { + console.log('DSM_JS_Function_1700 call getBestVolumeDescription success' +JSON.stringify(desCription)) + }, + fail: function (data, code) { + console.log('DSM_JS_Function_1700 call getBestVolumeDescription fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }) + }) + + /** + * @tc.number SUB_STORAGE_DSM_JS_Function_1800 + * @tc.name DSM_JS_Function_1800 + * @tc.desc Get the name of the volume (Internal storage public) + */ + it('DSM_JS_Function_1800', 0, function () { + var vol; + devicesmgr.getVolumes({ + success: function (data) { + console.log('DSM_JS_Function_1800 call getVolumes success' + data); + vol = data.volumeInfos[0] + }, + fail: function (data, code) { + console.log('DSM_JS_Function_1800 call getVolumes fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + devicesmgr.getBestVolumeDescription({ + vol: vol, + success: function (desCription) { + console.log('DSM_JS_Function_1800 call getBestVolumeDescription success' + JSON.stringify(desCription)) + }, + fail: function (data, code) { + console.log('DSM_JS_Function_1800 call getBestVolumeDescription fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }) + }) + + /** + * @tc.number SUB_STORAGE_DSM_JS_Function_1900 + * @tc.name DSM_JS_Function_1900 + * @tc.desc Get the name of the volume (Internal storage private) + */ + it('DSM_JS_Function_1900', 0, function () { + var vol; + devicesmgr.getVolumes({ + success: function (data) { + console.log('DSM_JS_Function_1900 call getVolumes success' + data); + vol = data.volumeInfos[1] + }, + fail: function (data, code) { + console.log('DSM_JS_Function_1900 call getVolumes fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + devicesmgr.getBestVolumeDescription({ + vol: vol, + success: function (desCription) { + console.log('DSM_JS_Function_1900 call getBestVolumeDescription success' + JSON.stringify(desCription)) + }, + fail: function (data, code) { + console.log('DSM_JS_Function_1900 call getBestVolumeDescription fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }) + }) + +}) diff --git a/storage/storagedsmjstest/src/main/js/default/test/DsmError.test.js b/storage/storagedsmjstest/src/main/js/default/test/DsmError.test.js new file mode 100644 index 0000000000000000000000000000000000000000..69f810373d4a5213d6cb378bc46a97402af498a8 --- /dev/null +++ b/storage/storagedsmjstest/src/main/js/default/test/DsmError.test.js @@ -0,0 +1,514 @@ +/* + * 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 devicesmgr from '@system.devicesmgr'; +import { + describe, + beforeAll, + beforeEach, + afterEach, + afterAll, + it, + expect +} +from 'deccjsunit/index' + +describe('dsmErrorTest', function () { + + /** + * @tc.number SUB_STORAGE_DSM_JS_ERROR_0100 + * @tc.name DSM_JS_ERROR_0100 + * @tc.desc Verify that the mount volume ID is null successfully. + */ + it('DSM_JS_ERROR_0100', 0, function () { + devicesmgr.mount({ + volId: '', + success: function () { + console.log('DSM_JS_ERROR_0100 call mount success, fail!'); + expect(null).assertFail(); + }, + fail: function (data, code) { + console.log('DSM_JS_ERROR_0100 call mount pass, code: ' + code + ', data: ' + data); + expect(code == 202).assertTrue(); + }, + }) + }) + + /** + * @tc.number SUB_STORAGE_DSM_JS_ERROR_0200 + * @tc.name DSM_JS_ERROR_0200 + * @tc.desc Verify that the mount does not exist and the volume ID is successful. + */ + it('DSM_JS_ERROR_0200', 0, function () { + devicesmgr.mount({ + volId: '123', + success: function () { + console.log('DSM_JS_ERROR_0200 call mount success, fail!'); + expect(null).assertFail(); + }, + fail: function (data, code) { + console.log('DSM_JS_ERROR_0200 call mount pass, code: ' + code + ', data: ' + data); + expect(code == 300).assertTrue(); + }, + }) + }) + + /** + * @tc.number SUB_STORAGE_DSM_JS_ERROR_0300 + * @tc.name DSM_JS_ERROR_0300 + * @tc.desc Verify that the unmount does not exist and the volume ID is successful. + */ + it('DSM_JS_ERROR_0300', 0, function () { + devicesmgr.unMount({ + volId: '123', + success: function () { + console.log('DSM_JS_ERROR_0300 call unMount success, fail!'); + expect(null).assertFail(); + }, + fail: function (data, code) { + console.log('DSM_JS_ERROR_0300 call unMount pass, code: ' + code + ', data: ' + data); + expect(code == 300).assertTrue(); + }, + }) + }) + + /** + * @tc.number SUB_STORAGE_DSM_JS_ERROR_0400 + * @tc.name DSM_JS_ERROR_0400 + * @tc.desc Verify that the unmount volume ID is null successfully. + */ + it('DSM_JS_ERROR_0400', 0, function () { + devicesmgr.unMount({ + volId: '', + success: function () { + console.log('DSM_JS_ERROR_0400 call unMount success, fail!'); + expect(null).assertFail(); + }, + fail: function (data, code) { + console.log('DSM_JS_ERROR_0400 call unMount pass, code: ' + code + ', data: ' + data); + expect(code == 202).assertTrue(); + }, + }) + }) + + /** + * @tc.number SUB_STORAGE_DSM_JS_ERROR_0500 + * @tc.name DSM_JS_ERROR_0500 + * @tc.desc Verify that the format does not exist and whether the volume ID is successful. + */ + it('DSM_JS_ERROR_0500', 0, function () { + devicesmgr.format({ + volId: '123', + success: function () { + console.log('DSM_JS_ERROR_0500 call format success, fail!'); + expect(null).assertFail(); + }, + fail: function (data, code) { + console.log('DSM_JS_ERROR_0500 call format pass, code: ' + code + ', data: ' + data); + expect(code == 300).assertTrue(); + }, + }) + }) + + /** + * @tc.number SUB_STORAGE_DSM_JS_ERROR_0600 + * @tc.name DSM_JS_ERROR_0600 + * @tc.desc Verify that the ID of the formatted volume is null successfully. + */ + it('DSM_JS_ERROR_0600', 0, function () { + devicesmgr.format({ + volId: '', + success: function () { + console.log('DSM_JS_ERROR_0600 call format success, fail!'); + expect(null).assertFail(); + }, + fail: function (data, code) { + console.log('DSM_JS_ERROR_0600 call format pass, code: ' + code + ', data: ' + data); + expect(code == 202).assertTrue(); + }, + }) + }) + + /** + * @tc.number SUB_STORAGE_DSM_JS_ERROR_0700 + * @tc.name DSM_JS_ERROR_0700 + * @tc.desc Verify that the SD card is successfully copied and mounted.. + */ + it('DSM_JS_ERROR_0700', 0, function () { + let mId; + devicesmgr.getVolumes({ + success: function (data) { + console.log('DSM_JS_ERROR_0900 call getVolumes success. data:' + JSON.stringify(data)); + for (let i = 0; i < data.volumeInfos.length; i++) { + if (data.volumeInfos[i].mState == 2 && data.volumeInfos[i].mId.indexOf('public:179') != -1) { + mId = data.volumeInfos[i].mId; + break; + } + } + }, + fail: function (data, code) { + console.log('DSM_JS_ERROR_0700 call getVolumes fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + devicesmgr.mount({ + volId: mId, + success: function () { + console.log('DSM_JS_ERROR_0700 call mount success'); + }, + fail: function (data, code) { + console.log('DSM_JS_ERROR_0700 call mount fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }) + }) + + /** + * @tc.number SUB_STORAGE_DSM_JS_ERROR_0800 + * @tc.name DSM_JS_ERROR_0800 + * @tc.desc Verify that volId is empty + */ + it('DSM_JS_ERROR_0800', 0, function () { + devicesmgr.findVolumeById({ + volId: '', + success: function () { + console.log('DSM_JS_ERROR_0800 call findVolumeById success, fail!'); + expect(null).assertFail(); + }, + fail: function (data, code) { + console.log('DSM_JS_ERROR_0800 call findVolumeById pass, code: ' + code + ', data: ' + data); + expect(code == 202).assertTrue(); + }, + }) + }) + + /** + * @tc.number SUB_STORAGE_DSM_JS_ERROR_0900 + * @tc.name DSM_JS_ERROR_0900 + * @tc.desc Invalid volId validation + */ + it('DSM_JS_ERROR_0900', 0, function () { + devicesmgr.findVolumeById({ + volId: '1234', + success: function () { + console.log('DSM_JS_ERROR_0900 call findVolumeById success, fail!'); + expect(null).assertFail(); + }, + fail: function (data, code) { + console.log('DSM_JS_ERROR_0900 call findVolumeById pass, code: ' + code + ', data: ' + data); + expect(code == 300).assertTrue(); + }, + }) + }) + + /** + * @tc.number SUB_STORAGE_DSM_JS_ERROR_1000 + * @tc.name DSM_JS_ERROR_1000 + * @tc.desc Verify that volumeUuid is null + */ + it('DSM_JS_ERROR_1000', 0, function () { + devicesmgr.findVolumeByUuid({ + volumeUuid: '', + success: function () { + console.log('DSM_JS_ERROR_1000 call findVolumeByUuid success, fail!'); + expect(null).assertFail(); + }, + fail: function (data, code) { + console.log('DSM_JS_ERROR_1000 call findVolumeByUuid pass, code: ' + code + ', data: ' + data); + expect(code == 202).assertTrue(); + }, + }) + }) + + /** + * @tc.number SUB_STORAGE_DSM_JS_ERROR_1100 + * @tc.name DSM_JS_ERROR_1100 + * @tc.desc Invalid volumeUuid validation + */ + it('DSM_JS_ERROR_1100', 0, function () { + devicesmgr.findVolumeByUuid({ + volumeUuid: '321', + success: function () { + console.log('DSM_JS_ERROR_1100 call findVolumeByUuid success, fail!'); + expect(null).assertFail(); + }, + fail: function (data, code) { + console.log('DSM_JS_ERROR_1100 call findVolumeByUuid pass, code: ' + code + ', data: ' + data); + expect(code == 300).assertTrue(); + }, + }) + }) + + /** + * @tc.number SUB_STORAGE_DSM_JS_ERROR_1200 + * @tc.name DSM_JS_ERROR_1200 + * @tc.desc Verify that diskId is empty + */ + it('DSM_JS_ERROR_1200', 0, function () { + devicesmgr.findDiskById({ + diskId: '', + success: function () { + console.log('DSM_JS_ERROR_1200 call findDiskById success, fail!'); + expect(null).assertFail(); + }, + fail: function (data, code) { + console.log('DSM_JS_ERROR_1200 call findDiskById pass, code: ' + code + ', data: ' + data); + expect(code == 202).assertTrue(); + }, + }) + }) + + /** + * @tc.number SUB_STORAGE_DSM_JS_ERROR_1300 + * @tc.name DSM_JS_ERROR_1300 + * @tc.desc Invalid DiskID verified + */ + it('DSM_JS_ERROR_1300', 0, function () { + devicesmgr.findDiskById({ + diskId: '789', + success: function () { + console.log('DSM_JS_ERROR_1300 call findDiskById success, fail!'); + expect(null).assertFail(); + }, + fail: function (data, code) { + console.log('DSM_JS_ERROR_1300 call findDiskById pass, code: ' + code + ', data: ' + data); + expect(code == 300).assertTrue(); + }, + }) + }) + + /** + * @tc.number SUB_STORAGE_DSM_JS_ERROR_1400 + * @tc.name DSM_JS_ERROR_1400 + * @tc.desc Verify that the value of the incoming simulate collection is null + */ + it('DSM_JS_ERROR_1400', 0, function () { + devicesmgr.findPrivateForEmulate({ + emuVol: { + mId: '', + mDiskId: '', + mPartGuid: '', + mFsUuid: '', + mType: '', + mMountFlags: '', + mMountUserId: '', + mState: '', + mPath: '', + mInternalPath: '', + mFsLabel: '', + Description: '', + IsVisibleForUser: '', + IsEmulated: '', + IsPrimaryEmulatedForUser: '', + IsRemovable: '', + IsPrimary: '' + }, + success: function () { + console.log('DSM_JS_ERROR_1400 call findPrivateForEmulate success, fail!'); + expect(null).assertFail(); + }, + fail: function (data, code) { + console.log('DSM_JS_ERROR_1400 call findPrivateForEmulate pass, code: ' + code + ', data: ' + data); + expect(code == 300).assertTrue(); + }, + }) + }) + + /** + * @tc.number SUB_STORAGE_DSM_JS_ERROR_1500 + * @tc.name DSM_JS_ERROR_1500 + * @tc.desc Verify that an invalid simulate set value was passed in + */ + it('DSM_JS_ERROR_1500', 0, function () { + devicesmgr.findPrivateForEmulate({ + emuVol: { + mId: '1234', + mDiskId: '321', + mPartGuid: '1357', + mFsUuid: '7890', + mType: 2, + mMountFlags: 3, + mMountUserId: 0, + mState: 6, + mPath: '/storage/emulated', + mInternalPath: '/data/media', + mFsLabel: '123', + Description: true, + IsVisibleForUser: true, + IsEmulated: true, + IsPrimaryEmulatedForUser: true, + IsRemovable: true, + IsPrimary: true + }, + success: function () { + console.log('DSM_JS_ERROR_1500 call findPrivateForEmulate success, fail!'); + expect(null).assertFail(); + }, + fail: function (data, code) { + console.log('DSM_JS_ERROR_1500 call findPrivateForEmulate pass, code: ' + code + ', data: ' + data); + expect(code == 300).assertTrue(); + }, + }) + }) + + /** + * @tc.number SUB_STORAGE_DSM_JS_ERROR_1600 + * @tc.name DSM_JS_ERROR_1600 + * @tc.desc Verify that the value of the incoming private collection is empty + */ + it('DSM_JS_ERROR_1600', 0, function () { + devicesmgr.findEmulateForPrivate({ + priVol: { + mId: '', + mDiskId: '', + mPartGuid: '', + mFsUuid: '', + mType: '', + mMountFlags: '', + mMountUserId: '', + mState: '', + mPath: '', + mInternalPath: '', + mFsLabel: '', + Description: '', + IsVisibleForUser: '', + IsEmulated: '', + IsPrimaryEmulatedForUser: '', + IsRemovable: '', + IsPrimary: '' + }, + success: function () { + console.log('DSM_JS_ERROR_1600 call findEmulateForPrivate success, fail!'); + expect(null).assertFail(); + }, + fail: function (data, code) { + console.log('DSM_JS_ERROR_1600 call findEmulateForPrivate pass, code: ' + code + ', data: ' + data); + expect(code == 300).assertTrue(); + }, + }) + }) + + /** + * @tc.number SUB_STORAGE_DSM_JS_ERROR_1700 + * @tc.name DSM_JS_ERROR_1700 + * @tc.desc Verify that an invalid private collection value was passed in + */ + it('DSM_JS_ERROR_1700', 0, function () { + devicesmgr.findEmulateForPrivate({ + priVol: { + mId: '1234', + mDiskId: '321', + mPartGuid: '456', + mFsUuid: '789', + mType: 1, + mMountFlags: 0, + mMountUserId: 0, + mState: 2, + mPath: 'data', + mInternalPath: '', + mFsLabel: '', + Description: true, + IsVisibleForUser: true, + IsEmulated: true, + IsPrimaryEmulatedForUser: true, + IsRemovable: true, + IsPrimary: true + }, + success: function () { + console.log('DSM_JS_ERROR_1700 call findEmulateForPrivate success, fail!'); + expect(null).assertFail(); + }, + fail: function (data, code) { + console.log('DSM_JS_ERROR_1700 call findEmulateForPrivate pass, code: ' + code + ', data: ' + data); + expect(code == 300).assertTrue(); + }, + }) + }) + + /** + * @tc.number SUB_STORAGE_DSM_JS_ERROR_1800 + * @tc.name DSM_JS_ERROR_1800 + * @tc.desc Verify that the vol set value is empty + */ + it('DSM_JS_ERROR_1800', 0, function () { + devicesmgr.getBestVolumeDescription({ + vol: { + mId: '', + mDiskId: '', + mPartGuid: '', + mFsUuid: '', + mType: '', + mMountFlags: '', + mMountUserId: '', + mState: '', + mPath: '', + mInternalPath: '', + mFsLabel: '', + Description: '', + IsVisibleForUser: '', + IsEmulated: '', + IsPrimaryEmulatedForUser: '', + IsRemovable: '', + IsPrimary: '' + }, + success: function () { + console.log('DSM_JS_ERROR_1800 call getBestVolumeDescription success, fail!'); + expect(null).assertFail(); + }, + fail: function (data, code) { + console.log('DSM_JS_ERROR_1800 call getBestVolumeDescription pass, code: ' + code + ', data: ' + data); + expect(code == 300).assertTrue(); + }, + }) + }) + + /** + * @tc.number SUB_STORAGE_DSM_JS_ERROR_1900 + * @tc.name DSM_JS_ERROR_1900 + * @tc.desc Validate invalid vol set value + */ + it('DSM_JS_ERROR_1900', 0, function () { + devicesmgr.getBestVolumeDescription({ + vol: { + mId: 'public:177,25', + mDiskId: 'disk:178,24', + mPartGuid: '', + mFsUuid: 'd87ba2fe-828f-4237-8006-c6dc6c2910e7', + mType: 0, + mMountFlags: 2, + mMountUserId: 0, + mState: 2, + mPath: '/storage/d87ba2fe-828f-4237-8006-c6dc6c2910e7', + mInternalPath: '/data/ss/d87ba2fe-828f-4237-8006-c6dc6c2910e7', + mFsLabel: '', + Description: true, + IsVisibleForUser: true, + IsEmulated: true, + IsPrimaryEmulatedForUser: true, + IsRemovable: true, + IsPrimary: true + }, + success: function () { + console.log('DSM_JS_ERROR_1900 call getBestVolumeDescription success, fail!'); + expect(null).assertFail(); + }, + fail: function (data, code) { + console.log('DSM_JS_ERROR_1900 call getBestVolumeDescription pass, code: ' + code + ', data: ' + data); + expect(code == 300).assertTrue(); + }, + }) + }) + +}) diff --git a/storage/storagedsmjstest/src/main/js/default/test/List.test.js b/storage/storagedsmjstest/src/main/js/default/test/List.test.js new file mode 100644 index 0000000000000000000000000000000000000000..8435a4c9960434a2d3a5ff6b59f9659871a1ec45 --- /dev/null +++ b/storage/storagedsmjstest/src/main/js/default/test/List.test.js @@ -0,0 +1,17 @@ +/* + * 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('./Dsm.test.js') +require('./DsmError.test.js') diff --git a/storage/storagedsmjstest/src/main/resources/base/element/string.json b/storage/storagedsmjstest/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..4b5a8bbc02d07ca41a3c0f63834395a33e02152a --- /dev/null +++ b/storage/storagedsmjstest/src/main/resources/base/element/string.json @@ -0,0 +1,12 @@ +{ + "string": [ + { + "name": "app_name", + "value": "storagefilestabilityjstest" + }, + { + "name": "mainability_description", + "value": "JS_Phone_Empty Feature Ability" + } + ] +} \ No newline at end of file diff --git a/storage/storagedsmjstest/src/main/resources/base/media/icon.png b/storage/storagedsmjstest/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/storage/storagedsmjstest/src/main/resources/base/media/icon.png differ diff --git a/storage/storagedsmstabilityjstest/BUILD.gn b/storage/storagedsmstabilityjstest/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..4e39e88c2b39012662720b598438566365ce9763 --- /dev/null +++ b/storage/storagedsmstabilityjstest/BUILD.gn @@ -0,0 +1,38 @@ +# 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("storagedsmstability_js_test") { + hap_profile = "./src/main/config.json" + deps = [ + ":storagedsmstability_js_assets", + ":storagedsmstability_js_resources", + ] + + # shared_libraries = [ + # "//third_party/giflib:libgif", + # "//third_party/libpng:libpng", + # ] + certificate_profile = "./signature/openharmony_sx.p7b" + hap_name = "storagedsmstabilityjstest" + + # part_name = "prebuilt_hap" + # subsystem_name = "xts" +} +ohos_js_assets("storagedsmstability_js_assets") { + source_dir = "./src/main/js/default" +} +ohos_resources("storagedsmstability_js_resources") { + sources = [ "./src/main/resources" ] + hap_profile = "./src/main/config.json" +} diff --git a/storage/storagedsmstabilityjstest/Test.json b/storage/storagedsmstabilityjstest/Test.json new file mode 100644 index 0000000000000000000000000000000000000000..4d5073412c3c9800aa1e4be440198263a74e080f --- /dev/null +++ b/storage/storagedsmstabilityjstest/Test.json @@ -0,0 +1,18 @@ +{ + "description": "Configuration for storage file and fileio Tests", + "driver": { + "type": "JSUnitTest", + "test-timeout": "60000", + "package": "ohos.acts.stroage.fileio", + "shell-timeout": "60000" + }, + "kits": [ + { + "test-file-name": [ + "storagefmspublicjstest.hap" + ], + "type": "AppInstallKit", + "cleanup-apps": true + } + ] +} \ No newline at end of file diff --git a/storage/storagedsmstabilityjstest/signature/openharmony_sx.p7b b/storage/storagedsmstabilityjstest/signature/openharmony_sx.p7b new file mode 100644 index 0000000000000000000000000000000000000000..9be1e98fa4c0c28ca997ed660112fa16b194f0f5 Binary files /dev/null and b/storage/storagedsmstabilityjstest/signature/openharmony_sx.p7b differ diff --git a/storage/storagedsmstabilityjstest/src/main/config.json b/storage/storagedsmstabilityjstest/src/main/config.json new file mode 100644 index 0000000000000000000000000000000000000000..9b7cfe5d04d1f2f807e5c7dc8ceff403cde6a9df --- /dev/null +++ b/storage/storagedsmstabilityjstest/src/main/config.json @@ -0,0 +1,61 @@ +{ + "app": { + "bundleName": "ohos.acts.stroage.fileio", + "vendor": "example", + "version": { + "code": 1000000, + "name": "1.0.0" + }, + "apiVersion": { + "compatible": 4, + "target": 5 + } + }, + "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 diff --git a/storage/storagedsmstabilityjstest/src/main/js/default/app.js b/storage/storagedsmstabilityjstest/src/main/js/default/app.js new file mode 100644 index 0000000000000000000000000000000000000000..60ee141c8dbd251c763b7b74552b5a133a774d6a --- /dev/null +++ b/storage/storagedsmstabilityjstest/src/main/js/default/app.js @@ -0,0 +1,23 @@ +/* + * Copyright (C) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export default { + onCreate() { + console.info('ohos.acts.distributeddatamgr.distributedfile onCreate'); + }, + onDestroy() { + console.info('ohos.acts.distributeddatamgr.distributedfile onCreate'); + } +}; diff --git a/storage/storagedsmstabilityjstest/src/main/js/default/i18n/en-US.json b/storage/storagedsmstabilityjstest/src/main/js/default/i18n/en-US.json new file mode 100644 index 0000000000000000000000000000000000000000..ead52ed2e09ec82aaf7aa9f4e714ed39ea88308e --- /dev/null +++ b/storage/storagedsmstabilityjstest/src/main/js/default/i18n/en-US.json @@ -0,0 +1,6 @@ +{ + "strings": { + "hello": "Hello", + "world": "Test" + } +} \ No newline at end of file diff --git a/storage/storagedsmstabilityjstest/src/main/js/default/i18n/zh-CN.json b/storage/storagedsmstabilityjstest/src/main/js/default/i18n/zh-CN.json new file mode 100644 index 0000000000000000000000000000000000000000..3f48f2585b24a8fe4a745e8ee2972a9e991a7803 --- /dev/null +++ b/storage/storagedsmstabilityjstest/src/main/js/default/i18n/zh-CN.json @@ -0,0 +1,6 @@ +{ + "strings": { + "hello": "您好", + "world": "测试" + } +} \ No newline at end of file diff --git a/storage/storagedsmstabilityjstest/src/main/js/default/pages/index/index.css b/storage/storagedsmstabilityjstest/src/main/js/default/pages/index/index.css new file mode 100644 index 0000000000000000000000000000000000000000..6fda792753f2e15f22b529c7b90a82185b2770bf --- /dev/null +++ b/storage/storagedsmstabilityjstest/src/main/js/default/pages/index/index.css @@ -0,0 +1,9 @@ +.container { + flex-direction: column; + justify-content: center; + align-items: center; +} + +.title { + font-size: 100px; +} diff --git a/storage/storagedsmstabilityjstest/src/main/js/default/pages/index/index.hml b/storage/storagedsmstabilityjstest/src/main/js/default/pages/index/index.hml new file mode 100644 index 0000000000000000000000000000000000000000..f64b040a5ae394dbaa5e185e1ecd4f4556b92184 --- /dev/null +++ b/storage/storagedsmstabilityjstest/src/main/js/default/pages/index/index.hml @@ -0,0 +1,5 @@ +
+ + {{ $t('strings.hello') }} {{ title }} + +
diff --git a/storage/storagedsmstabilityjstest/src/main/js/default/pages/index/index.js b/storage/storagedsmstabilityjstest/src/main/js/default/pages/index/index.js new file mode 100644 index 0000000000000000000000000000000000000000..f7894a72230dd2356d1ce272896c9e0fd09e08cd --- /dev/null +++ b/storage/storagedsmstabilityjstest/src/main/js/default/pages/index/index.js @@ -0,0 +1,40 @@ +/* + * 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 app from '@system.app' + +import {Core} from 'deccjsunit/index' + +const injectRef = Object.getPrototypeOf(global) || global +injectRef.regeneratorRuntime = require('@babel/runtime/regenerator') + +export default { + data: { + title: '' + }, + onInit() { + this.title = this.$t('strings.world'); + }, + onShow() { + console.info('onShow finish') + 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 diff --git a/storage/storagedsmstabilityjstest/src/main/js/default/test/Common.js b/storage/storagedsmstabilityjstest/src/main/js/default/test/Common.js new file mode 100644 index 0000000000000000000000000000000000000000..e94e7f4049a3da8852e3fcba5be70a7100756bd4 --- /dev/null +++ b/storage/storagedsmstabilityjstest/src/main/js/default/test/Common.js @@ -0,0 +1,180 @@ +/* + * 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 filePickerName(testName,deviceID) { + const BASE_PATH = '/data/ss/'+deviceID+'/fms_test/' + return BASE_PATH + testName +} +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 fmsFileName(testName) { + const BASE_PATH = "/data/accounts/account_0/appdata/ohos.acts.test/files/" + return BASE_PATH + testName +} +export function fmsCacheName(testName) { + const BASE_PATH = "/data/accounts/account_0/appdata/ohos.acts.test/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; +} diff --git a/storage/storagedsmstabilityjstest/src/main/js/default/test/DsmPerformance.test.js b/storage/storagedsmstabilityjstest/src/main/js/default/test/DsmPerformance.test.js new file mode 100644 index 0000000000000000000000000000000000000000..1a5f4dfb9d5de0308278c788dc904d7839260eeb --- /dev/null +++ b/storage/storagedsmstabilityjstest/src/main/js/default/test/DsmPerformance.test.js @@ -0,0 +1,372 @@ +/* + * 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 devicesmgr from '@system.devicesmgr'; +import { + describe, + beforeAll, + beforeEach, + afterEach, + afterAll, + it, + expect +} +from 'deccjsunit/index' + +describe('dsmPerformanceTest', function () { + + /** + * @tc.number SUB_STORAGE_DSM_Performance_0000 + * @tc.name DSM_Performance_0000 + * @tc.desc getVolumes Performance test + */ + it('DSM_Performance_0000', 0, function () { + for (let i = 0; i < 1000; i++) { + var start = new Date().getTime(); + devicesmgr.getVolumes({ + success: function (data) { + var end = new Date().getTime(); + console.log('DSM_Performance_0000 call getVolumes success' + JSON.stringify(data)); + console.log('---DSM_Performance_0000---time:-' + (end - start) + '-----' + i); + }, + fail: function (data, code) { + console.log('DSM_Performance_0000 call getVolumes fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + } + }); + } + }) + + /** + * @tc.number SUB_STORAGE_DSM_Performance_0100 + * @tc.name DSM_Performance_0100 + * @tc.desc unMount mount Performance test + */ + it('DSM_Performance_0100', 0, function () { + let mId; + devicesmgr.getVolumes({ + success: function (data) { + console.log('DSM_Performance_0100 call getVolumes success' + data); + mId = data.volumeInfos[2].mId; + }, + fail: function (data, code) { + console.log('DSM_Performance_0100 call getVolumes fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + for (let i = 0; i < 1000; i++) { + var start = new Date().getTime(); + if (mId != null) { + devicesmgr.unMount({ + volId: mId, + success: function () { + console.log('DSM_Performance_0100 call unMount success.'); + var end = new Date().getTime(); + console.log('---DSM_Performance_0100---time:-' + (end - start) + '-----' + i); + }, + fail: function (data, code) { + console.log('DSM_Performance_0100 call unMount fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + } + }) + var start1 = new Date().getTime(); + devicesmgr.mount({ + volId: mId, + success: function () { + var end1 = new Date().getTime(); + console.log('---DSM_Performance_0200---time:-' + (end1 - start1) + '-----' + i); + }, + fail: function (data, code) { + console.log('DSM_Performance_0200 call mount fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }) + } else { + expect(null).assertFail(); + } + } + }) + + /** + * @tc.number SUB_STORAGE_DSM_Performance_0300 + * @tc.name DSM_Performance_0300 + * @tc.desc getDisks Performance test + */ + it('DSM_Performance_0300', 0, function () { + for (let i = 0; i < 1000; i++) { + var start = new Date().getTime(); + devicesmgr.getDisks({ + success: function (data) { + console.log('DSM_Performance_0300 call getDisks success.' + JSON.stringify(data)); + var end = new Date().getTime(); + console.log('---DSM_Performance_0300---time:-' + (end - start) + '-----' + i); + }, + fail: function (data, code) { + console.log('DSM_Performance_0300 call getDisks fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }) + } + }) + + /** + * @tc.number SUB_STORAGE_DSM_Performance_0400 + * @tc.name DSM_Performance_0400 + * @tc.desc findVolumeById Performance test + */ + it('DSM_Performance_0400', 0, function () { + for (let i = 0; i < 1000; i++) { + let mId; + devicesmgr.getVolumes({ + success: function (data) { + console.log('DSM_Performance_0400 call getVolumes success' + JSON.stringify(data)); + mId = data.volumeInfos[2].mId; + }, + fail: function (data, code) { + console.log('DSM_Performance_0400 call getVolumes fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + var start = new Date().getTime(); + devicesmgr.findVolumeById({ + volId: mId, + success: function (data) { + console.log('DSM_Performance_0400 call findVolumeById success' + JSON.stringify(data)) + var end = new Date().getTime(); + console.log('---DSM_Performance_0400---time:-' + (end - start) + '-----' + i); + }, + fail: function (data, code) { + console.log('DSM_Performance_0400 call findVolumeById fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }) + } + }) + + /** + * @tc.number SUB_STORAGE_DSM_Performance_0500 + * @tc.name DSM_Performance_0500 + * @tc.desc findVolumeByUuid Performance test + */ + it('DSM_Performance_0500', 0, function () { + let mFsUuid; + devicesmgr.getVolumes({ + success: function (data) { + console.log('DSM_Performance_0500 call getVolumes success' + JSON.stringify(data)); + mFsUuid = data.volumeInfos[2].mFsUuid; + }, + fail: function (data, code) { + console.log('DSM_Performance_0500 call getVolumes fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + for (let i = 0; i < 1000; i++) { + var start = new Date().getTime(); + devicesmgr.findVolumeByUuid({ + volumeUuid: mFsUuid, + success: function (vol) { + console.log('DSM_Performance_0500 call findVolumeByUuid success' + JSON.stringify(vol)); + var end = new Date().getTime(); + console.log('---DSM_Performance_0500---time:-' + (end - start) + '-----' + i); + }, + fail: function (data, code) { + console.log('DSM_Performance_0500 call findVolumeByUuid fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }) + } + }) + + /** + * @tc.number SUB_STORAGE_DSM_Performance_0600 + * @tc.name DSM_Performance_0600 + * @tc.desc getWritableVolumes Performance test + */ + it('DSM_Performance_0600', 0, function () { + for (let i = 0; i < 1000; i++) { + var start = new Date().getTime(); + devicesmgr.getWritableVolumes({ + success: function (data) { + console.log('DSM_Performance_0600 call getWritableVolumes success. data:' + JSON.stringify(data)); + var end = new Date().getTime(); + console.log('---DSM_Performance_0600---time:-' + (end - start) + '-----' + i); + }, + fail: function (data, code) { + console.log('DSM_Performance_0600 call getWritableVolumes fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + } + }) + + /** + * @tc.number SUB_STORAGE_DSM_Performance_0700 + * @tc.name DSM_Performance_0700 + * @tc.desc findDiskById Performance test + */ + it('DSM_Performance_0700', 0, function () { + let mDiskId; + devicesmgr.getVolumes({ + success: function (data) { + console.log('DSM_Performance_0700 call getVolumes success' + JSON.stringify(data)); + mDiskId = data.volumeInfos[2].mDiskId; + }, + fail: function (data, code) { + console.log('DSM_Performance_0700 call getVolumes fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + for (let i = 0; i < 1000; i++) { + var start = new Date().getTime(); + devicesmgr.findDiskById({ + diskId: mDiskId, + success: function (disk) { + console.log('DSM_Performance_0700 call findDiskById success' + JSON.stringify(disk)) + var end = new Date().getTime(); + console.log('---DSM_Performance_0700---time:-' + (end - start) + '-----' + i); + }, + fail: function (data, code) { + console.log('DSM_Performance_0700 call findDiskById fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }) + } + }) + + /** + * @tc.number SUB_STORAGE_DSM_Performance_0800 + * @tc.name DSM_Performance_0800 + * @tc.desc getPrimaryStorageUuid Performance test + */ + it('DSM_Performance_0800', 0, function () { + for (let i = 0; i < 1000; i++) { + var start = new Date().getTime(); + devicesmgr.getPrimaryStorageUuid({ + success: function (primaryUuid) { + console.log('DSM_Performance_0800 call getPrimaryStorageUuid success.' + JSON.stringify(primaryUuid)); + var end = new Date().getTime(); + console.log('---DSM_Performance_0800---time:-' + (end - start) + '-----' + i); + }, + fail: function (data, code) { + console.log('DSM_Performance_0800 call getPrimaryStorageUuid fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + } + }) + + /** + * @tc.number SUB_STORAGE_DSM_Performance_0900 + * @tc.name DSM_Performance_0900 + * @tc.desc findPrivateForEmulate Performance test + */ + it('DSM_Performance_0900', 0, function () { + let emuVol; + devicesmgr.getVolumes({ + success: function (data) { + console.log('DSM_Performance_0900 call getVolumes success' + JSON.stringify(data)); + emuVol = data.volumeInfos[0] + }, + fail: function (data, code) { + console.log('DSM_Performance_0900 call getVolumes fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + for (let i = 0; i < 1000; i++) { + var start = new Date().getTime(); + devicesmgr.findPrivateForEmulate({ + emuVol: emuVol, + success: function (priVol) { + console.log('DSM_Performance_0900 call findPrivateForEmulate success' + JSON.stringify(priVol)) + var end = new Date().getTime(); + console.log('---DSM_Performance_0900---time:-' + (end - start) + '-----' + i); + }, + fail: function (data, code) { + console.log('DSM_Performance_0900 call findPrivateForEmulate fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }) + } + }) + + /** + * @tc.number SUB_STORAGE_DSM_Performance_1000 + * @tc.name DSM_Performance_1000 + * @tc.desc findPrivateForEmulate Performance test + */ + it('DSM_Performance_1000', 0, function () { + let emuVol ; + devicesmgr.getVolumes({ + success: function (data) { + console.log('DSM_Performance_1000 call getVolumes success' + JSON.stringify(data)); + emuVol = data.volumeInfos[1] + }, + fail: function (data, code) { + console.log('DSM_Performance_1000 call getVolumes fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + for (let i = 0; i < 1000; i++) { + var start = new Date().getTime(); + devicesmgr.findEmulateForPrivate({ + priVol: emuVol, + success: function (emuVol) { + console.log('DSM_Performance_1000 call findEmulateForPrivate success' + JSON.stringify(emuVol)) + var end = new Date().getTime(); + console.log('---DSM_Performance_1000---time:-' + (end - start) + '-----' + i); + }, + fail: function (data, code) { + console.log('DSM_Performance_1000 call findEmulateForPrivate fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }) + } + }) + + /** + * @tc.number SUB_STORAGE_DSM_Performance_1100 + * @tc.name DSM_Performance_1100 + * @tc.desc findPrivateForEmulate Performance test + */ + it('DSM_Performance_1100', 0, function () { + let emuVol; + devicesmgr.getVolumes({ + success: function (data) { + console.log('DSM_Performance_1100 call getVolumes success' + JSON.stringify(data)); + emuVol = data.volumeInfos[2] + }, + fail: function (data, code) { + console.log('DSM_Performance_1100 call getVolumes fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + for (let i = 0; i < 1000; i++) { + var start = new Date().getTime(); + devicesmgr.getBestVolumeDescription({ + vol: emuVol, + success: function (desCription) { + console.log('DSM_JS_Function_1100 call getBestVolumeDescription success' + desCription) + var end = new Date().getTime(); + console.log('---DSM_Performance_1100---time:-' + (end - start) + '-----' + i); + }, + fail: function (data, code) { + console.log('DSM_JS_Function_1100 call getBestVolumeDescription fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }) + } + }) + +}) diff --git a/storage/storagedsmstabilityjstest/src/main/js/default/test/DsmReliability.test.js b/storage/storagedsmstabilityjstest/src/main/js/default/test/DsmReliability.test.js new file mode 100644 index 0000000000000000000000000000000000000000..aa6139bc7026e3b181f47bc6cee6ca2171a57342 --- /dev/null +++ b/storage/storagedsmstabilityjstest/src/main/js/default/test/DsmReliability.test.js @@ -0,0 +1,224 @@ +/* + * 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 devicesmgr from '@system.devicesmgr'; +import { + describe, + beforeAll, + beforeEach, + afterEach, + afterAll, + it, + expect +} +from 'deccjsunit/index' +describe('dsmReliabilityTest', function () { + + /** + * @tc.number SUB_STORAGE_DSM_Reliability_0000 + * @tc.name DSM_Reliability_0000 + * @tc.desc Reliability test + */ + it('DSM_Reliability_0000', 0, function () { + for (let i = 0; i < 100000; i++) { + let mId; + let mFsUuid; + let mDiskId; + devicesmgr.getVolumes({ + success: function (data) { + console.log('DSM_Reliability_0000 getVolumes success' + JSON.stringify(data) + i); + mId = data.volumeInfos[2].mId; + mFsUuid = data.volumeInfos[2].mFsUuid; + mDiskId = data.volumeInfos[2].mDiskId; + }, + fail: function (data, code) { + console.log('DSM_Reliability_0000 getVolumes fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + } + }); + devicesmgr.getDisks({ + success: function () { + console.log('DSM_Reliability_0300 getDisks success.' + i); + }, + fail: function (data, code) { + console.log('DSM_Reliability_0300 getVolumes fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + devicesmgr.findVolumeById({ + volId: mId, + success: function () { + console.log('DSM_Reliability_0400 findVolumeById success' + i) + }, + fail: function (data, code) { + console.log('DSM_Reliability_0400 findVolumeById fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }) + devicesmgr.findVolumeByUuid({ + volumeUuid: mFsUuid, + success: function () { + console.log('DSM_Reliability_0500 findVolumeByUuid success' + i); + }, + fail: function (data, code) { + console.log('DSM_Reliability_0500 findVolumeByUuid fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }) + devicesmgr.getWritableVolumes({ + success: function () { + console.log('DSM_Reliability_0600 getWritableVolumes success. data:' + i); + }, + fail: function (data, code) { + console.log('DSM_Reliability_0600 getWritableVolumes fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + devicesmgr.findDiskById({ + diskId: mDiskId, + success: function () { + console.log('DSM_Reliability_0700 findDiskById success' + i) + }, + fail: function (data, code) { + console.log('DSM_Reliability_0700 findDiskById fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }) + devicesmgr.getPrimaryStorageUuid({ + success: function () { + console.log('DSM_Reliability_0800 getPrimaryStorageUuid success.' + i); + }, + fail: function (data, code) { + console.log('DSM_Reliability_0800 getPrimaryStorageUuid fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + devicesmgr.unMount({ + volId: mId, + success: function () { + console.log('DSM_Reliability_0100 unMount success.' + i); + }, + fail: function (data, code) { + console.log('DSM_Reliability_0100 unMount fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + } + }) + devicesmgr.mount({ + volId: mId, + success: function () { + console.log('DSM_Reliability_0200 mount success.' + i); + }, + fail: function (data, code) { + console.log('DSM_Reliability_0200 mount fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }) + } + }) + + /** + * @tc.number SUB_STORAGE_DSM_Reliability_0900 + * @tc.name DSM_Reliability_0900 + * @tc.desc Reliability test + */ + it('DSM_Reliability_0900', 0, function () { + let emuVol; + devicesmgr.getVolumes({ + success: function (data) { + console.log('DSM_Reliability_0900 getVolumes success'); + emuVol = data.volumeInfos[0] + }, + fail: function (data, code) { + console.log('DSM_Reliability_0900 getVolumes fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + for (let i = 0; i < 100000; i++) { + devicesmgr.findPrivateForEmulate({ + emuVol: emuVol, + success: function () { + console.log('DSM_Reliability_0900 findPrivateForEmulate success' + i) + }, + fail: function (data, code) { + console.log('DSM_Reliability_0900 findPrivateForEmulate fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }) + } + }) + + /** + * @tc.number SUB_STORAGE_DSM_Reliability_1000 + * @tc.name DSM_Reliability_1000 + * @tc.desc Reliability test + */ + it('DSM_Reliability_1000', 0, function () { + let emuVol; + devicesmgr.getVolumes({ + success: function (data) { + console.log('DSM_Reliability_1000 getVolumes success'); + emuVol = data.volumeInfos[1] + }, + fail: function (data, code) { + console.log('DSM_Reliability_1000 getVolumes fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + for (let i = 0; i < 100000; i++) { + devicesmgr.findEmulateForPrivate({ + emuVol: emuVol, + success: function () { + console.log('DSM_Reliability_1000 findPrivateForEmulate success' + i) + }, + fail: function (data, code) { + console.log('DSM_Reliability_1000 findPrivateForEmulate fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }) + } + }) + + /** + * @tc.number SUB_STORAGE_DSM_Reliability_1100 + * @tc.name DSM_Reliability_1100 + * @tc.desc Reliability test + */ + it('DSM_Reliability_1100', 0, function () { + let vol; + devicesmgr.getVolumes({ + success: function (data) { + console.log('DSM_Reliability_1100 getVolumes success'); + vol = data.volumeInfos[0] + }, + fail: function (data, code) { + console.log('DSM_Reliability_1100 getVolumes fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + for (let i = 0; i < 100000; i++) { + devicesmgr.getBestVolumeDescription({ + vol: vol, + success: function (desCription) { + console.log('DSM_Reliability_1100 call getBestVolumeDescription success' + desCription) + }, + fail: function (data, code) { + console.log('DSM_Reliability_1100 call getBestVolumeDescription fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }) + } + }) + +}) diff --git a/storage/storagedsmstabilityjstest/src/main/js/default/test/List.test.js b/storage/storagedsmstabilityjstest/src/main/js/default/test/List.test.js new file mode 100644 index 0000000000000000000000000000000000000000..79bcbec42023c802a5aeca4fc7239ca881f94b48 --- /dev/null +++ b/storage/storagedsmstabilityjstest/src/main/js/default/test/List.test.js @@ -0,0 +1,17 @@ +/* + * 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('./DsmPerformance.test.js') +require('./DsmReliability.test.js') diff --git a/storage/storagedsmstabilityjstest/src/main/resources/base/element/string.json b/storage/storagedsmstabilityjstest/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..4b5a8bbc02d07ca41a3c0f63834395a33e02152a --- /dev/null +++ b/storage/storagedsmstabilityjstest/src/main/resources/base/element/string.json @@ -0,0 +1,12 @@ +{ + "string": [ + { + "name": "app_name", + "value": "storagefilestabilityjstest" + }, + { + "name": "mainability_description", + "value": "JS_Phone_Empty Feature Ability" + } + ] +} \ No newline at end of file diff --git a/storage/storagedsmstabilityjstest/src/main/resources/base/media/icon.png b/storage/storagedsmstabilityjstest/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/storage/storagedsmstabilityjstest/src/main/resources/base/media/icon.png differ diff --git a/storage/storagefileconcurrentjstest/BUILD.gn b/storage/storagefileconcurrentjstest/BUILD.gn index e0d87da5eeb95fa2be8cb49b08ef8c21c9906ce8..1f8abd12a3a9476bc51fea7523507535bd9b2126 100644 --- a/storage/storagefileconcurrentjstest/BUILD.gn +++ b/storage/storagefileconcurrentjstest/BUILD.gn @@ -18,14 +18,16 @@ ohos_js_hap_suite("storagefileconcurrent_js_test") { ":storagefileconcurrent_js_assets", ":storagefileconcurrent_js_resources", ] -# shared_libraries = [ -# "//third_party/giflib:libgif", -# "//third_party/libpng:libpng", -# ] + + # shared_libraries = [ + # "//third_party/giflib:libgif", + # "//third_party/libpng:libpng", + # ] certificate_profile = "./signature/openharmony_sx.p7b" hap_name = "storagefileconcurrentjstest" -# part_name = "prebuilt_hap" -# subsystem_name = "xts" + + # part_name = "prebuilt_hap" + # subsystem_name = "xts" } ohos_js_assets("storagefileconcurrent_js_assets") { source_dir = "./src/main/js/default" diff --git a/storage/storagefileconcurrentjstest/Test.json b/storage/storagefileconcurrentjstest/Test.json index 12533e991208ad0f56e301528008947bf6d6cb26..70d16ce2193f563098e647a6626fb2ff91e5ee84 100644 --- a/storage/storagefileconcurrentjstest/Test.json +++ b/storage/storagefileconcurrentjstest/Test.json @@ -2,7 +2,7 @@ "description": "Configuration for storage file and fileio Tests", "driver": { "type": "JSUnitTest", - "test-timeout": "120000", + "test-timeout": "60000", "package": "ohos.acts.stroage.fileio", "shell-timeout": "60000" }, diff --git a/storage/storagefileconcurrentjstest/src/main/js/default/app.js b/storage/storagefileconcurrentjstest/src/main/js/default/app.js index 5fefaead87d0899fd7e07a2f2241a40bfd298339..60ee141c8dbd251c763b7b74552b5a133a774d6a 100644 --- a/storage/storagefileconcurrentjstest/src/main/js/default/app.js +++ b/storage/storagefileconcurrentjstest/src/main/js/default/app.js @@ -1,3 +1,18 @@ +/* + * 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'); diff --git a/storage/storagefileconcurrentjstest/src/main/js/default/test/FileConcurrent.test.js b/storage/storagefileconcurrentjstest/src/main/js/default/test/FileConcurrent.test.js index 3e34851c00c4f742ee51bc42a771c08cf447f52b..d3cce86de64606a15a4a7d887d17c108d33dfaf5 100644 --- a/storage/storagefileconcurrentjstest/src/main/js/default/test/FileConcurrent.test.js +++ b/storage/storagefileconcurrentjstest/src/main/js/default/test/FileConcurrent.test.js @@ -12,6 +12,7 @@ * 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 { @@ -24,17 +25,6 @@ import { expect } from 'deccjsunit/index' -import { - FILE_CONTENT, - prepareFile, - fileName, - cacheFileName, - getFileTextLen, - isFileExist, - prepareEmptyFile, - randomString -} - from './Common' describe('fileconcurrent', function () { @@ -105,7 +95,7 @@ describe('fileconcurrent', function () { for (let i = 0; i < 10; i++) { file.readText({ uri: 'internal://app/file_test_001', - success: function (data) { + success: function () { console.log('file_test_001 => pass, call readText success. data.text: ' ); done(); }, @@ -116,7 +106,7 @@ describe('fileconcurrent', function () { }); file.readText({ uri: 'internal://app/file_test_001', - success: function (data) { + success: function () { console.log('file_test_001 => pass, call readText success. data.text: ' ); done(); }, @@ -127,7 +117,7 @@ describe('fileconcurrent', function () { }); file.readText({ uri: 'internal://app/file_test_001', - success: function (data) { + success: function () { console.log('file_test_001 => pass, call readText success. data.text: ' ); done(); }, @@ -162,7 +152,7 @@ describe('fileconcurrent', function () { file.copy({ srcUri: 'internal://app/file_test_002', dstUri: 'internal://app/file_test_002', - success: function (uri) { + success: function () { console.log('file_test_002 => pass,call copy success. uri:' ); done(); }, @@ -174,7 +164,7 @@ describe('fileconcurrent', function () { file.copy({ srcUri: 'internal://app/file_test_002', dstUri: 'internal://app/file_test_002' + '100', - success: function (uri) { + success: function () { console.log('file_test_002 => pass,call copy success. uri:' ); done(); }, @@ -186,7 +176,7 @@ describe('fileconcurrent', function () { file.copy({ srcUri: 'internal://app/file_test_002', dstUri: 'internal://app/file_test_002' + '200', - success: function (uri) { + success: function () { console.log('file_test_002 => pass,call copy success. uri:' ); done(); }, @@ -221,7 +211,7 @@ describe('fileconcurrent', function () { file.move({ srcUri: 'internal://app/file_test_003', dstUri: 'internal://file_test_003', - success: function (uri) { + success: function () { console.log('file_test_003 => pass,call move success. uri:' ); done(); }, @@ -255,7 +245,7 @@ describe('fileconcurrent', function () { for (let i = 0; i < 10; i++) { file.readArrayBuffer({ uri: 'internal://app/file_test_004', - success: function (data) { + success: function () { console.log('file_test_004 => pass,call readArrayBuffer success. '); done(); }, @@ -266,7 +256,7 @@ describe('fileconcurrent', function () { }); file.readArrayBuffer({ uri: 'internal://app/file_test_004', - success: function (data) { + success: function () { console.log('file_test_004 => pass,call readArrayBuffer success. '); done(); }, @@ -277,7 +267,7 @@ describe('fileconcurrent', function () { }); file.readArrayBuffer({ uri: 'internal://app/file_test_004', - success: function (data) { + success: function () { console.log('file_test_004 => pass,call readArrayBuffer success. '); done(); }, @@ -357,7 +347,7 @@ describe('fileconcurrent', function () { }); file.readText({ uri: 'internal://app/file_test_006', - success: function (data) { + success: function () { console.log('file_test_006 => pass,call readText success: '); done(); }, @@ -391,7 +381,7 @@ describe('fileconcurrent', function () { }); file.readArrayBuffer({ uri: 'internal://app/file_test_007', - success: function (data) { + success: function () { console.log('file_test_007 => pass,call readArrayBuffer success: '); done(); }, @@ -425,7 +415,7 @@ describe('fileconcurrent', function () { file.copy({ srcUri: 'internal://app/file_test_008', dstUri: 'internal://app/file_test_008', - success: function (uri) { + success: function () { console.log('file_test_008 => pass,call copy success. uri:'); done(); }, diff --git a/storage/storagefileioerrorjstest/BUILD.gn b/storage/storagefileioerrorjstest/BUILD.gn index 14b6b8a9727ce9e4fe367056d79693a6a9a8d0cb..f5ff1f9484bc16295db8e9cd5d1b9604b7a18bfd 100644 --- a/storage/storagefileioerrorjstest/BUILD.gn +++ b/storage/storagefileioerrorjstest/BUILD.gn @@ -18,14 +18,16 @@ ohos_js_hap_suite("storagefileioerror_js_test") { ":storagefileioerror_js_assets", ":storagefileioerror_js_resources", ] -# shared_libraries = [ -# "//third_party/giflib:libgif", -# "//third_party/libpng:libpng", -# ] + + # shared_libraries = [ + # "//third_party/giflib:libgif", + # "//third_party/libpng:libpng", + # ] certificate_profile = "./signature/openharmony_sx.p7b" hap_name = "storagefileioerrorjstest" -# part_name = "prebuilt_hap" -# subsystem_name = "xts" + + # part_name = "prebuilt_hap" + # subsystem_name = "xts" } ohos_js_assets("storagefileioerror_js_assets") { source_dir = "./src/main/js/default" @@ -33,4 +35,4 @@ ohos_js_assets("storagefileioerror_js_assets") { ohos_resources("storagefileioerror_js_resources") { sources = [ "./src/main/resources" ] hap_profile = "./src/main/config.json" -} \ 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 index 9d10bce6fb499625141f90b4fa26617e8573d50e..a1c847c8a50d8e7c89041e1c5ce0daf53e85ae58 100644 --- a/storage/storagefileioerrorjstest/src/main/js/default/test/FileError.test.js +++ b/storage/storagefileioerrorjstest/src/main/js/default/test/FileError.test.js @@ -12,6 +12,7 @@ * 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 { @@ -145,11 +146,11 @@ describe('FileError', function () { uri: 'internal://app/file_test_error_005', success: function (data) { console.log('file_test_error_005 pass, Content:' + data.text); - done(); + expect(null).assertFail(); }, fail: function (data, code) { console.log('file_test_error_005 call readText fail, code: ' + code + ', data: ' + data); - expect(null).assertFail(); + done(); }, }); }); @@ -165,11 +166,11 @@ describe('FileError', function () { uri: 'internal://app/file_test_error_006', success: function (data) { console.log('file_test_error_006 pass, Content:' + data.buffer); - done(); + expect(null).assertFail(); }, fail: function (data, code) { console.log('file_test_error_006 call readArrayBuffer fail, code: ' + code + ', data: ' + data); - expect(null).assertFail(); + done(); }, }); }); @@ -187,11 +188,11 @@ describe('FileError', function () { recursive: true, success: function () { console.log('file_test_error_007 call rmdir success.'); - done(); + expect(null).assertFail(); }, fail: function (data, code) { console.log('file_test_error_007 call rmdir fail, code: ' + code + ', data: ' + data); - expect(null).assertFail(); + done(); }, }); }); @@ -242,11 +243,11 @@ describe('FileError', function () { recursive: true, success: function () { console.log('file_test_error_009 call rmdir success.'); - done(); + expect(null).assertFail(); }, fail: function (data, code) { console.log('file_test_error_009 call rmdir fail, code: ' + code + ', data: ' + data); - expect(null).assertFail(); + done(); }, }); }); 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 f9039f7ea8803820efd3fc2efe0d6da5113576b2..17b0d6ed011b503d28e445af9ac40d2ddc30138a 100644 --- a/storage/storagefileioerrorjstest/src/main/js/default/test/FileIOError.test.js +++ b/storage/storagefileioerrorjstest/src/main/js/default/test/FileIOError.test.js @@ -12,6 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + import fileio from '@system.fileio' import { describe, @@ -59,10 +60,10 @@ describe('FileIOError', 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); - expect(null).assertFail(); } }); @@ -105,7 +106,7 @@ describe('FileIOError', function () { * @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 + * 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'); @@ -134,10 +135,10 @@ describe('FileIOError', function () { 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); - expect(null).assertFail(); } }); @@ -156,17 +157,18 @@ describe('FileIOError', function () { 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); - 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 + * @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 */ @@ -176,10 +178,10 @@ describe('FileIOError', function () { 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); - expect(null).assertFail(); } }); @@ -198,10 +200,10 @@ describe('FileIOError', function () { 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); - expect(null).assertFail(); } }); @@ -247,7 +249,8 @@ describe('FileIOError', function () { /** * @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 + * @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'); diff --git a/storage/storagefileioerrorjstest/src/main/js/default/test/FileVirtualPath.test.js b/storage/storagefileioerrorjstest/src/main/js/default/test/FileVirtualPath.test.js index dcffe71655ded51570b15f386fce74dbb4bfbb75..26beeb2625ba74cbac77ff78eae6514918148819 100644 --- a/storage/storagefileioerrorjstest/src/main/js/default/test/FileVirtualPath.test.js +++ b/storage/storagefileioerrorjstest/src/main/js/default/test/FileVirtualPath.test.js @@ -12,6 +12,7 @@ * 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 { @@ -24,6 +25,7 @@ import { FILE_CONTENT, prepareFile, fileName, + nextFileName } from './Common' @@ -525,4 +527,47 @@ describe('fileVirtualPath', function () { }); }); + /** + * @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); + }); + + /** + * @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); + }); + }); diff --git a/storage/storagefileiojstest/BUILD.gn b/storage/storagefileiojstest/BUILD.gn index 73cfe90e587aa6021d65a906bc35e2169820d59c..740c32ca7567908db1ce6be2fd35478ccb93c5ed 100644 --- a/storage/storagefileiojstest/BUILD.gn +++ b/storage/storagefileiojstest/BUILD.gn @@ -18,14 +18,16 @@ ohos_js_hap_suite("storagefileio_js_test") { ":storagefileio_js_assets", ":storagefileio_js_resources", ] -# shared_libraries = [ -# "//third_party/giflib:libgif", -# "//third_party/libpng:libpng", -# ] + + # shared_libraries = [ + # "//third_party/giflib:libgif", + # "//third_party/libpng:libpng", + # ] certificate_profile = "./signature/openharmony_sx.p7b" hap_name = "Storagefileiojstest" -# part_name = "prebuilt_hap" -# subsystem_name = "xts" + + # part_name = "prebuilt_hap" + # subsystem_name = "xts" } ohos_js_assets("storagefileio_js_assets") { source_dir = "./src/main/js/default" @@ -33,4 +35,4 @@ ohos_js_assets("storagefileio_js_assets") { ohos_resources("storagefileio_js_resources") { sources = [ "./src/main/resources" ] hap_profile = "./src/main/config.json" -} \ No newline at end of file +} diff --git a/storage/storagefileiojstest/src/main/js/default/app.js b/storage/storagefileiojstest/src/main/js/default/app.js index 5fefaead87d0899fd7e07a2f2241a40bfd298339..60ee141c8dbd251c763b7b74552b5a133a774d6a 100644 --- a/storage/storagefileiojstest/src/main/js/default/app.js +++ b/storage/storagefileiojstest/src/main/js/default/app.js @@ -1,3 +1,18 @@ +/* + * 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'); diff --git a/storage/storagefileiojstest/src/main/js/default/test/File.test.js b/storage/storagefileiojstest/src/main/js/default/test/File.test.js index 789800a3350ffea38b321f757dac2dba4bf38d00..fbb550e7398c002507fb0189229a6619e1c27a46 100644 --- a/storage/storagefileiojstest/src/main/js/default/test/File.test.js +++ b/storage/storagefileiojstest/src/main/js/default/test/File.test.js @@ -12,6 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + import fileio from '@system.fileio'; import bundle_mgr from '@ohos.bundle_mgr' import file from '@system.file'; @@ -606,7 +607,7 @@ describe('fileTest', function () { done(); }, fail: function (data, code) { - console.log('File_writeText_010 fail'); + console.log('File_writeText_010 fail code: ' + code + ', data: ' + data); expect(null).assertFail(); }, }); @@ -633,7 +634,7 @@ describe('fileTest', function () { uri: 'internal://app/../files/File_writeText_011', text: 'sawyerwang', success: function () { - console.log('File_writeText_011 mkdif success'); + console.log('File_writeText_011 mkdir success '); done(); }, fail: function (data, code) { @@ -933,7 +934,7 @@ describe('fileTest', function () { }); file.readArrayBuffer({ uri: 'internal://cache/File_writeArrayBuffer_006', - success: function (data) { + success: function () { console.log('File_writeArrayBuffer_006 pass'); done(); }, diff --git a/storage/storagefileiojstest/src/main/js/default/test/FileIO.test.js b/storage/storagefileiojstest/src/main/js/default/test/FileIO.test.js index b4f52731e5686a3b714c62038752096dac032060..413469d892c8598fb96165e12a2699f38ef772d7 100644 --- a/storage/storagefileiojstest/src/main/js/default/test/FileIO.test.js +++ b/storage/storagefileiojstest/src/main/js/default/test/FileIO.test.js @@ -14,6 +14,7 @@ */ import fileio from '@ohos.fileio'; +import file from '@system.file'; import bundle_mgr from '@ohos.bundle_mgr' import { describe, @@ -1356,7 +1357,7 @@ describe('fileIOTest', function () { expect(null).assertFail(); } catch (e) { - console.log('fileio_test_unlink_sync_003 has failed for ' + e); + console.log('fileio_test_unlink_sync_002 has failed for ' + e); } }); @@ -1609,6 +1610,7 @@ describe('fileIOTest', function () { success: function (data) { console.log('call readText success: ' + data.text); expect(text == data.text).assertTrue(); + expect(fileio.unlinkSync(fpath) !== null).assertTrue(); done(); }, fail: function (data, code) { @@ -1616,8 +1618,7 @@ describe('fileIOTest', function () { expect(null).assertFail(); }, }); - expect(fileio.unlinkSync(fpath) !== null).assertTrue(); - } + } catch (e) { console.log('fileio_test_read_sync_000 has failed for ' + e); expect(null).assertFail(); diff --git a/storage/storagefileioperformancejstest/BUILD.gn b/storage/storagefileioperformancejstest/BUILD.gn index adfc3de270cde74d83c5341dce16c73e1578872b..d89efc741269bb4f78e8d7246106dc3967f990df 100644 --- a/storage/storagefileioperformancejstest/BUILD.gn +++ b/storage/storagefileioperformancejstest/BUILD.gn @@ -18,14 +18,16 @@ ohos_js_hap_suite("storagefileioperformance_js_test") { ":storagefileioperformance_js_assets", ":storagefileioperformance_js_resources", ] -# shared_libraries = [ -# "//third_party/giflib:libgif", -# "//third_party/libpng:libpng", -# ] + + # shared_libraries = [ + # "//third_party/giflib:libgif", + # "//third_party/libpng:libpng", + # ] certificate_profile = "./signature/openharmony_sx.p7b" hap_name = "storagefileioperformancejstest" -# part_name = "prebuilt_hap" -# subsystem_name = "xts" + + # part_name = "prebuilt_hap" + # subsystem_name = "xts" } ohos_js_assets("storagefileioperformance_js_assets") { source_dir = "./src/main/js/default" @@ -33,4 +35,4 @@ ohos_js_assets("storagefileioperformance_js_assets") { ohos_resources("storagefileioperformance_js_resources") { sources = [ "./src/main/resources" ] hap_profile = "./src/main/config.json" -} \ No newline at end of file +} diff --git a/storage/storagefileioperformancejstest/src/main/js/default/app.js b/storage/storagefileioperformancejstest/src/main/js/default/app.js index 5fefaead87d0899fd7e07a2f2241a40bfd298339..60ee141c8dbd251c763b7b74552b5a133a774d6a 100644 --- a/storage/storagefileioperformancejstest/src/main/js/default/app.js +++ b/storage/storagefileioperformancejstest/src/main/js/default/app.js @@ -1,3 +1,18 @@ +/* + * 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'); diff --git a/storage/storagefileioperformancejstest/src/main/js/default/test/FileIOPerformance.js b/storage/storagefileioperformancejstest/src/main/js/default/test/FileIOPerformance.js index ba0281b42e96c01f5f0bf33e53e464f383e76896..46903945c74dc5f606efbbe5b0a67798a6fee1f7 100644 --- a/storage/storagefileioperformancejstest/src/main/js/default/test/FileIOPerformance.js +++ b/storage/storagefileioperformancejstest/src/main/js/default/test/FileIOPerformance.js @@ -12,6 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + import fileio from '@system.fileio' import { describe, diff --git a/storage/storagefileioperformancejstest/src/main/js/default/test/FilePerformance.js b/storage/storagefileioperformancejstest/src/main/js/default/test/FilePerformance.js index c7eef3f2a400014b9464b000fc1bffa1e8ec524d..b71a9411ac48073baaa2e17cab1d00e2599d8dad 100644 --- a/storage/storagefileioperformancejstest/src/main/js/default/test/FilePerformance.js +++ b/storage/storagefileioperformancejstest/src/main/js/default/test/FilePerformance.js @@ -12,6 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + import file from '@system.file'; import fileio from '@ohos.fileio'; import { diff --git a/storage/storagefileioreliabilityjstest/BUILD.gn b/storage/storagefileioreliabilityjstest/BUILD.gn index 6d4ba99da7d32720c7d3e756f0a4f299b07a85a7..d328a15f1e78e3ce3adcfa5edd5a5678ee24ee1e 100644 --- a/storage/storagefileioreliabilityjstest/BUILD.gn +++ b/storage/storagefileioreliabilityjstest/BUILD.gn @@ -18,14 +18,16 @@ ohos_js_hap_suite("storagefileioreliability_js_test") { ":storagefileioreliability_js_assets", ":storagefileioreliability_js_resources", ] -# shared_libraries = [ -# "//third_party/giflib:libgif", -# "//third_party/libpng:libpng", -# ] + + # shared_libraries = [ + # "//third_party/giflib:libgif", + # "//third_party/libpng:libpng", + # ] certificate_profile = "./signature/openharmony_sx.p7b" hap_name = "storagefileioreliabilityjstest" -# part_name = "prebuilt_hap" -# subsystem_name = "xts" + + # part_name = "prebuilt_hap" + # subsystem_name = "xts" } ohos_js_assets("storagefileioreliability_js_assets") { source_dir = "./src/main/js/default" @@ -33,4 +35,4 @@ ohos_js_assets("storagefileioreliability_js_assets") { ohos_resources("storagefileioreliability_js_resources") { sources = [ "./src/main/resources" ] hap_profile = "./src/main/config.json" -} \ No newline at end of file +} diff --git a/storage/storagefileioreliabilityjstest/src/main/js/default/app.js b/storage/storagefileioreliabilityjstest/src/main/js/default/app.js index 5fefaead87d0899fd7e07a2f2241a40bfd298339..60ee141c8dbd251c763b7b74552b5a133a774d6a 100644 --- a/storage/storagefileioreliabilityjstest/src/main/js/default/app.js +++ b/storage/storagefileioreliabilityjstest/src/main/js/default/app.js @@ -1,3 +1,18 @@ +/* + * 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'); diff --git a/storage/storagefileioreliabilityjstest/src/main/js/default/test/FileIOReliability.js b/storage/storagefileioreliabilityjstest/src/main/js/default/test/FileIOReliability.js index 102751321098d5c71c0eb6d3e6216ae7d4eeb980..73fd508a5444f4e8d8dec06eef87712dd80ca3d1 100644 --- a/storage/storagefileioreliabilityjstest/src/main/js/default/test/FileIOReliability.js +++ b/storage/storagefileioreliabilityjstest/src/main/js/default/test/FileIOReliability.js @@ -12,6 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + import fileio from '@system.fileio' import { describe, diff --git a/storage/storagefileiostabilityjstest/BUILD.gn b/storage/storagefileiostabilityjstest/BUILD.gn index bc553e2f654c1487cad4f34c2e2883b00d3b8cee..4a98bb0314edd5c3074456201597b8baa21096fd 100644 --- a/storage/storagefileiostabilityjstest/BUILD.gn +++ b/storage/storagefileiostabilityjstest/BUILD.gn @@ -18,14 +18,16 @@ ohos_js_hap_suite("storagefileiostability_js_test") { ":storagefileiostability_js_assets", ":storagefileiostability_js_resources", ] -# shared_libraries = [ -# "//third_party/giflib:libgif", -# "//third_party/libpng:libpng", -# ] + + # shared_libraries = [ + # "//third_party/giflib:libgif", + # "//third_party/libpng:libpng", + # ] certificate_profile = "./signature/openharmony_sx.p7b" hap_name = "storagefileiostabilityjstest" -# part_name = "prebuilt_hap" -# subsystem_name = "xts" + + # part_name = "prebuilt_hap" + # subsystem_name = "xts" } ohos_js_assets("storagefileiostability_js_assets") { source_dir = "./src/main/js/default" @@ -33,4 +35,4 @@ ohos_js_assets("storagefileiostability_js_assets") { ohos_resources("storagefileiostability_js_resources") { sources = [ "./src/main/resources" ] hap_profile = "./src/main/config.json" -} \ No newline at end of file +} diff --git a/storage/storagefileiostabilityjstest/src/main/js/default/app.js b/storage/storagefileiostabilityjstest/src/main/js/default/app.js index 5fefaead87d0899fd7e07a2f2241a40bfd298339..60ee141c8dbd251c763b7b74552b5a133a774d6a 100644 --- a/storage/storagefileiostabilityjstest/src/main/js/default/app.js +++ b/storage/storagefileiostabilityjstest/src/main/js/default/app.js @@ -1,3 +1,18 @@ +/* + * 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'); diff --git a/storage/storagefileiostabilityjstest/src/main/js/default/test/FileIOStability.js b/storage/storagefileiostabilityjstest/src/main/js/default/test/FileIOStability.js index 882dcdc18ec3bf76c9df42adf0ae844dded4f846..003c0351c9b456122fc6fa628774e87e98c6c314 100644 --- a/storage/storagefileiostabilityjstest/src/main/js/default/test/FileIOStability.js +++ b/storage/storagefileiostabilityjstest/src/main/js/default/test/FileIOStability.js @@ -12,6 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + import fileio from '@system.fileio' import { describe, @@ -55,8 +56,8 @@ describe('fileIOStability', function () { }); /** - * @tc.number SUB_STORAGE_fileIOStability_dir - * @tc.name fileIOStability_dir + * @tc.number SUB_STORAGE_fileIOStability_dirent + * @tc.name fileIOStability_dirent * @tc.desc Function of API, 7*24 */ it('fileIOStability_dirent', 0, function () { diff --git a/storage/storagefilestabilityjstest/BUILD.gn b/storage/storagefilestabilityjstest/BUILD.gn index 15d53876787dbdc808c5555497b29490719056de..c04dc8c1b678cdd57f4849b831878d5bfec62e3a 100644 --- a/storage/storagefilestabilityjstest/BUILD.gn +++ b/storage/storagefilestabilityjstest/BUILD.gn @@ -18,14 +18,16 @@ ohos_js_hap_suite("storagefilestability_js_test") { ":storagefilestability_js_assets", ":storagefilestability_js_resources", ] -# shared_libraries = [ -# "//third_party/giflib:libgif", -# "//third_party/libpng:libpng", -# ] + + # shared_libraries = [ + # "//third_party/giflib:libgif", + # "//third_party/libpng:libpng", + # ] certificate_profile = "./signature/openharmony_sx.p7b" hap_name = "storagefilestabilityjstest" -# part_name = "prebuilt_hap" -# subsystem_name = "xts" + + # part_name = "prebuilt_hap" + # subsystem_name = "xts" } ohos_js_assets("storagefilestability_js_assets") { source_dir = "./src/main/js/default" @@ -33,4 +35,4 @@ ohos_js_assets("storagefilestability_js_assets") { ohos_resources("storagefilestability_js_resources") { sources = [ "./src/main/resources" ] hap_profile = "./src/main/config.json" -} \ No newline at end of file +} diff --git a/storage/storagefilestabilityjstest/src/main/js/default/app.js b/storage/storagefilestabilityjstest/src/main/js/default/app.js index 5fefaead87d0899fd7e07a2f2241a40bfd298339..60ee141c8dbd251c763b7b74552b5a133a774d6a 100644 --- a/storage/storagefilestabilityjstest/src/main/js/default/app.js +++ b/storage/storagefilestabilityjstest/src/main/js/default/app.js @@ -1,3 +1,18 @@ +/* + * 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'); diff --git a/storage/storagefilestabilityjstest/src/main/js/default/test/FileReliability.js b/storage/storagefilestabilityjstest/src/main/js/default/test/FileReliability.js index febc53ebde1c1d08f6a3699d7da855ac21975299..db2cfa80a22e85d4aac6a301e6c09cc3ea4c15f8 100644 --- a/storage/storagefilestabilityjstest/src/main/js/default/test/FileReliability.js +++ b/storage/storagefilestabilityjstest/src/main/js/default/test/FileReliability.js @@ -12,6 +12,7 @@ * 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 { diff --git a/storage/storagefilestabilityjstest/src/main/js/default/test/FileStability.js b/storage/storagefilestabilityjstest/src/main/js/default/test/FileStability.js index d19730c866ad9e8f06c88e61632711ce2fe4705e..548f02ae029acb233f93839d41e4e7e63e25afb5 100644 --- a/storage/storagefilestabilityjstest/src/main/js/default/test/FileStability.js +++ b/storage/storagefilestabilityjstest/src/main/js/default/test/FileStability.js @@ -12,6 +12,7 @@ * 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 { @@ -51,6 +52,7 @@ describe('FileReliability', function () { }); setTimeout(function () { resolve('mkdir success!'); + done() }, 250); }); promiseMkdir.then(function () { @@ -75,6 +77,7 @@ describe('FileReliability', function () { }); promiseWriteText.then(function () { console.log('writeText success'); + done(); }); let promiseReadText = new Promise(function (resolve, reject) { file.readText({ @@ -94,6 +97,7 @@ describe('FileReliability', function () { }); promiseReadText.then(function () { console.log('readText success'); + done(); }); let promiseAccess = new Promise(function (resolve, reject) { file.access({ @@ -113,6 +117,7 @@ describe('FileReliability', function () { }); promiseAccess.then(function () { console.log('access success'); + done(); }); let promiseGet = new Promise(function (resolve, reject) { file.get({ @@ -132,6 +137,7 @@ describe('FileReliability', function () { }); promiseGet.then(function () { console.log('get success'); + done(); }); let promiseList = new Promise(function (resolve, reject) { file.list({ @@ -151,6 +157,7 @@ describe('FileReliability', function () { }); promiseList.then(function () { console.log('list success'); + done(); }); let promiseCopy = new Promise(function (resolve, reject) { file.copy({ @@ -171,6 +178,7 @@ describe('FileReliability', function () { }); promiseCopy.then(function () { console.log('copy success'); + done(); }); let promiseMove = new Promise(function (resolve, reject) { file.move({ @@ -191,6 +199,7 @@ describe('FileReliability', function () { }); promiseMove.then(function () { console.log('move success'); + done(); }); file.delete({ uri: 'internal://app/fileStability01' + i, @@ -234,6 +243,7 @@ describe('FileReliability', function () { }); promiseWriteArrayBuffer.then(function () { console.log('writeArrayBuffer success'); + done(); }); let promiseReadArrayBuffer = new Promise(function (resolve, reject) { file.readArrayBuffer({ @@ -252,6 +262,7 @@ describe('FileReliability', function () { }, 250); }); promiseReadArrayBuffer.then(function () { + done(); console.log('readArrayBuffer success'); }); file.delete({ @@ -284,6 +295,7 @@ describe('FileReliability', function () { }); promiseRmdir.then(function () { console.log('rmdir success'); + done(); }); } diff --git a/storage/storagefmspublicjstest/BUILD.gn b/storage/storagefmspublicjstest/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..805b53e223920bd2ca51ea0dd51b53b85edc1580 --- /dev/null +++ b/storage/storagefmspublicjstest/BUILD.gn @@ -0,0 +1,38 @@ +# 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("storagefmspublic_js_test") { + hap_profile = "./src/main/config.json" + deps = [ + ":storagefmspublic_js_assets", + ":storagefmspublic_js_resources", + ] + + # shared_libraries = [ + # "//third_party/giflib:libgif", + # "//third_party/libpng:libpng", + # ] + certificate_profile = "./signature/openharmony_sx.p7b" + hap_name = "storagefmspublicjstest" + + # part_name = "prebuilt_hap" + # subsystem_name = "xts" +} +ohos_js_assets("storagefmspublic_js_assets") { + source_dir = "./src/main/js/default" +} +ohos_resources("storagefmspublic_js_resources") { + sources = [ "./src/main/resources" ] + hap_profile = "./src/main/config.json" +} diff --git a/storage/storagefmspublicjstest/Test.json b/storage/storagefmspublicjstest/Test.json new file mode 100644 index 0000000000000000000000000000000000000000..4d5073412c3c9800aa1e4be440198263a74e080f --- /dev/null +++ b/storage/storagefmspublicjstest/Test.json @@ -0,0 +1,18 @@ +{ + "description": "Configuration for storage file and fileio Tests", + "driver": { + "type": "JSUnitTest", + "test-timeout": "60000", + "package": "ohos.acts.stroage.fileio", + "shell-timeout": "60000" + }, + "kits": [ + { + "test-file-name": [ + "storagefmspublicjstest.hap" + ], + "type": "AppInstallKit", + "cleanup-apps": true + } + ] +} \ No newline at end of file diff --git a/storage/storagefmspublicjstest/signature/openharmony_sx.p7b b/storage/storagefmspublicjstest/signature/openharmony_sx.p7b new file mode 100644 index 0000000000000000000000000000000000000000..9be1e98fa4c0c28ca997ed660112fa16b194f0f5 Binary files /dev/null and b/storage/storagefmspublicjstest/signature/openharmony_sx.p7b differ diff --git a/storage/storagefmspublicjstest/src/main/config.json b/storage/storagefmspublicjstest/src/main/config.json new file mode 100644 index 0000000000000000000000000000000000000000..9b7cfe5d04d1f2f807e5c7dc8ceff403cde6a9df --- /dev/null +++ b/storage/storagefmspublicjstest/src/main/config.json @@ -0,0 +1,61 @@ +{ + "app": { + "bundleName": "ohos.acts.stroage.fileio", + "vendor": "example", + "version": { + "code": 1000000, + "name": "1.0.0" + }, + "apiVersion": { + "compatible": 4, + "target": 5 + } + }, + "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 diff --git a/storage/storagefmspublicjstest/src/main/js/default/app.js b/storage/storagefmspublicjstest/src/main/js/default/app.js new file mode 100644 index 0000000000000000000000000000000000000000..60ee141c8dbd251c763b7b74552b5a133a774d6a --- /dev/null +++ b/storage/storagefmspublicjstest/src/main/js/default/app.js @@ -0,0 +1,23 @@ +/* + * Copyright (C) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export default { + onCreate() { + console.info('ohos.acts.distributeddatamgr.distributedfile onCreate'); + }, + onDestroy() { + console.info('ohos.acts.distributeddatamgr.distributedfile onCreate'); + } +}; diff --git a/storage/storagefmspublicjstest/src/main/js/default/i18n/en-US.json b/storage/storagefmspublicjstest/src/main/js/default/i18n/en-US.json new file mode 100644 index 0000000000000000000000000000000000000000..ead52ed2e09ec82aaf7aa9f4e714ed39ea88308e --- /dev/null +++ b/storage/storagefmspublicjstest/src/main/js/default/i18n/en-US.json @@ -0,0 +1,6 @@ +{ + "strings": { + "hello": "Hello", + "world": "Test" + } +} \ No newline at end of file diff --git a/storage/storagefmspublicjstest/src/main/js/default/i18n/zh-CN.json b/storage/storagefmspublicjstest/src/main/js/default/i18n/zh-CN.json new file mode 100644 index 0000000000000000000000000000000000000000..3f48f2585b24a8fe4a745e8ee2972a9e991a7803 --- /dev/null +++ b/storage/storagefmspublicjstest/src/main/js/default/i18n/zh-CN.json @@ -0,0 +1,6 @@ +{ + "strings": { + "hello": "您好", + "world": "测试" + } +} \ No newline at end of file diff --git a/storage/storagefmspublicjstest/src/main/js/default/pages/index/index.css b/storage/storagefmspublicjstest/src/main/js/default/pages/index/index.css new file mode 100644 index 0000000000000000000000000000000000000000..6fda792753f2e15f22b529c7b90a82185b2770bf --- /dev/null +++ b/storage/storagefmspublicjstest/src/main/js/default/pages/index/index.css @@ -0,0 +1,9 @@ +.container { + flex-direction: column; + justify-content: center; + align-items: center; +} + +.title { + font-size: 100px; +} diff --git a/storage/storagefmspublicjstest/src/main/js/default/pages/index/index.hml b/storage/storagefmspublicjstest/src/main/js/default/pages/index/index.hml new file mode 100644 index 0000000000000000000000000000000000000000..f64b040a5ae394dbaa5e185e1ecd4f4556b92184 --- /dev/null +++ b/storage/storagefmspublicjstest/src/main/js/default/pages/index/index.hml @@ -0,0 +1,5 @@ +
+ + {{ $t('strings.hello') }} {{ title }} + +
diff --git a/storage/storagefmspublicjstest/src/main/js/default/pages/index/index.js b/storage/storagefmspublicjstest/src/main/js/default/pages/index/index.js new file mode 100644 index 0000000000000000000000000000000000000000..f7894a72230dd2356d1ce272896c9e0fd09e08cd --- /dev/null +++ b/storage/storagefmspublicjstest/src/main/js/default/pages/index/index.js @@ -0,0 +1,40 @@ +/* + * 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 app from '@system.app' + +import {Core} from 'deccjsunit/index' + +const injectRef = Object.getPrototypeOf(global) || global +injectRef.regeneratorRuntime = require('@babel/runtime/regenerator') + +export default { + data: { + title: '' + }, + onInit() { + this.title = this.$t('strings.world'); + }, + onShow() { + console.info('onShow finish') + 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 diff --git a/storage/storagefmspublicjstest/src/main/js/default/test/Common.js b/storage/storagefmspublicjstest/src/main/js/default/test/Common.js new file mode 100644 index 0000000000000000000000000000000000000000..c7b15f7ce870c57af41cbaadd146c05ba0b91c0d --- /dev/null +++ b/storage/storagefmspublicjstest/src/main/js/default/test/Common.js @@ -0,0 +1,192 @@ +/* + * 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 filePickerName(testName,deviceID) { + const BASE_PATH = '/data/ss/'+deviceID+'/fms_test/' + return BASE_PATH + testName +} +export function filePickerName1(testName,deviceID) { + const BASE_PATH = '/data/ss/'+ deviceID +'/fms_test/' + return BASE_PATH + testName +} +export function filePickerName2(testName,deviceID) { + const BASE_PATH = '/data/ss/'+ deviceID + return BASE_PATH + testName +} +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 fmsFileName(testName) { + const BASE_PATH = "/data/accounts/account_0/appdata/ohos.acts.test/files/" + return BASE_PATH + testName +} +export function fmsCacheName(testName) { + const BASE_PATH = "/data/accounts/account_0/appdata/ohos.acts.test/cache/" + return BASE_PATH + testName +} +export function fmsPublic(testName) { + const BASE_PATH = '/data/ss/files/' + 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; +} diff --git a/storage/storagefmspublicjstest/src/main/js/default/test/FmsPublic.test.js b/storage/storagefmspublicjstest/src/main/js/default/test/FmsPublic.test.js new file mode 100644 index 0000000000000000000000000000000000000000..4802049d2e9c47574dde7f23514b96081dd0ba9a --- /dev/null +++ b/storage/storagefmspublicjstest/src/main/js/default/test/FmsPublic.test.js @@ -0,0 +1,400 @@ +/* + * Copyright (C) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the 'License'); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an 'AS IS' BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import fileio from '@ohos.fileio'; +import filepicker from '@ohos.filepicker' +import { + describe, + beforeAll, + beforeEach, + afterEach, + afterAll, + it, + expect +} +from 'deccjsunit/index' +import { + FILE_CONTENT, + prepareFile, + fileName, + filePickerName, + randomString, + cacheFileName, + prepareEmptyFile, + nextFileName +} +from './Common' +describe('FmsTest', function () { + let deviceID = 0; + + /** + * @tc.number SUB_STORAGE_FMS_Function_0000 + * @tc.name FMS_Function_0000 + * @tc.desc Function of API,Get current device information + */ + it('FMS_Function_0000', 0, function (done) { + let progetDeviceInfo = new Promise(function (resolve, reject) { + filepicker.getDeviceInfo({ + success: function (data) { + console.log('FMS_Function_0000 success.' + JSON.stringify(data)); + if (data.deviceList.length == 0) { + console.log('FMS_Function_0000 fail'); + expect(null).assertFail(); + } else { + deviceID = data.deviceList[0].deviceID; + console.log("---FMS_Function_0000------" + deviceID); + done(); + } + }, + fail: function (data, code) { + console.log('FMS_Function_0000 fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }) + }) + progetDeviceInfo.then(function () { + console.log('FMS_Function_0000 success'); + }); + }) + + /** + * @tc.number SUB_STORAGE_FMS_Function_0100 + * @tc.name FMS_Function_0100 + * @tc.desc Function of API, Creates the specified directory recursively + */ + it('FMS_Function_0100', 0, function (done) { + let proMkdir = new Promise(function (resolve, reject) { + filepicker.mkdir({ + uri: 'dataability:///public.storage.ability/' + deviceID + '/document/fms_test/leaf', + success: function () { + console.log('FMS_Function_0100 mkdir success.'); + done() + }, + fail: function (data, code) { + console.log('FMS_Function_0100 fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }) + }) + proMkdir.catch(function () { + console.log('FMS_Function_0100 success'); + }); + }) + + /** + * @tc.number SUB_STORAGE_FMS_Function_0200 + * @tc.name FMS_Function_0200 + * @tc.desc Function of API, Creates the specified directory recursively + */ + it('FMS_Function_0200', 0, function (done) { + let proMkdir = new Promise(function (resolve, reject) { + filepicker.mkdir({ + uri: 'dataability:///public.storage.ability/' + deviceID + '/document/你好/leaf', + success: function () { + console.log('FMS_Function_0200 mkdir success.'); + done() + }, + fail: function (data, code) { + console.log('FMS_Function_0200 fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }) + }) + proMkdir.then(function () { + console.log('FMS_Function_0200 success'); + }); + }) + + /** + * @tc.number SUB_STORAGE_FMS_Function_0300 + * @tc.name FMS_Function_0300 + * @tc.desc Function of API, Creates the specified directory recursively + */ + it('FMS_Function_0300', 0, function (done) { + let proMkdir = new Promise(function (resolve, reject) { + filepicker.mkdir({ + uri: 'dataability:///public.storage.ability/' + deviceID + '/document/a/b/c/leaf', + success: function () { + console.log('FMS_Function_0300 mkdir success.'); + done() + }, + fail: function (data, code) { + console.log('FMS_Function_0300 fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }) + }) + proMkdir.then(function () { + console.log('FMS_Function_0300 success'); + }); + }) + + /** + * @tc.number SUB_STORAGE_FMS_Function_0400 + * @tc.name FMS_Function_0400 + * @tc.desc Function of API, + */ + it('FMS_Function_0400', 0, function (done) { + let proMkdir = new Promise(function (resolve, reject) { + filepicker.mkdir({ + uri: 'dataability:///public.storage.ability/' + deviceID + '/root/files', + success: function () { + console.log('FMS_Function_0400 success.'); + done() + }, + fail: function (data, code) { + console.log('call fail callback fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }) + }) + proMkdir.then(function () { + console.log('FMS_Function_0400 success'); + }); + }) + + /** + * @tc.number SUB_STORAGE_FMS_Function_0500 + * @tc.name FMS_Function_0500 + * @tc.desc Function of API, save file.The test file is exist. + */ + it('FMS_Function_0500', 0, function (done) { + let fpath = filePickerName("a.txt", deviceID); + expect(prepareFile(fpath, FILE_CONTENT) !== null).assertTrue(); + let proMkdir = new Promise(function (resolve, reject) { + filepicker.saveFile({ + srcUri: ['dataability:///public.storage.ability/' + deviceID + '/document/fms_test/a.txt/leaf'], + dstUri: 'dataability:///public.storage.ability/' + deviceID + '/root', + success: function (data) { + console.log('FMS_Function_0500 success.' + data.saveFileList[0].status); + done() + }, + fail: function (data, code) { + console.log('FMS_Function_0500 fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + }) + proMkdir.then(function () { + console.log('FMS_Function_0500 success'); + }); + }) + + /** + * @tc.number SUB_STORAGE_FMS_Function_0600 + * @tc.name FMS_Function_0600 + * @tc.desc Function of API, save file.The test file is exist. + */ + it('FMS_Function_0600', 0, async function (done) { + let fpath = filePickerName("b.txt", deviceID); + expect(prepareFile(fpath, FILE_CONTENT) !== null).assertTrue(); + let proMkdir = new Promise(function (resolve, reject) { + filepicker.saveFile({ + srcUri: ['dataability:///public.storage.ability/' + deviceID + '/document/fms_test/a.txt/leaf', + 'dataability:///public.storage.ability/' + deviceID + '/document/fms_test/b.txt/leaf'], + dstUri: 'dataability:///public.storage.ability/' + deviceID + '/root', + success: function (data) { + console.log('FMS_Function_0600 success.' + data.saveFileList[0].status); + done() + }, + fail: function (data, code) { + console.log('FMS_Function_0600 fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + }) + proMkdir.then(function () { + console.log('FMS_Function_0600 success'); + }); + }) + + /** + * @tc.number SUB_STORAGE_FMS_Function_0700 + * @tc.name FMS_Function_0700 + * @tc.desc Function of API, save file.The test file is exist. + */ + it('FMS_Function_0700', 0, async function (done) { + let proMkdir = new Promise(function (resolve, reject) { + filepicker.saveFile({ + srcUri: ['dataability:///public.storage.ability/' + deviceID + '/document/fms_test/a.txt/leaf'], + dstUri: 'dataability:///public.storage.ability/' + deviceID + '/root/files', + success: function (data) { + console.log('FMS_Function_0700 success.' + data.saveFileList[0].status); + done() + }, + fail: function (data, code) { + console.log('FMS_Function_0700 fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + }) + proMkdir.then(function () { + console.log('FMS_Function_0700 success'); + }); + + }) + + /** + * @tc.number SUB_STORAGE_FMS_Function_0800 + * @tc.name FMS_Function_0800 + * @tc.desc Function of API, save file.The test file is exist. + */ + it('FMS_Function_0800', 0, async function (done) { + let proMkdir = new Promise(function (resolve, reject) { + filepicker.saveFile({ + srcUri: ['dataability:///public.storage.ability/' + deviceID + '/document/fms_test/a.txt/leaf', + 'dataability:///public.storage.ability/' + deviceID + '/document/fms_test/b.txt/leaf'], + dstUri: 'dataability:///public.storage.ability/' + deviceID + '/root/files', + success: function (data) { + console.log('FMS_Function_0800 success.' + data.saveFileList[0].status); + done() + }, + fail: function (data, code) { + console.log('FMS_Function_0800 fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + }) + proMkdir.then(function () { + console.log('FMS_Function_0800 success'); + }); + }) + + /** + * @tc.number SUB_STORAGE_FMS_Function_0900 + * @tc.name FMS_Function_0900 + * @tc.desc Function of API, search file.The test file is exist. + */ + it('FMS_Function_0900', 0, async function (done) { + let proMkdir = new Promise(function (resolve, reject) { + filepicker.searchFile({ + uri: 'dataability:///public.storage.ability/' + deviceID + '/document/fms_test/leaf', + name: 'a.txt', + success: function (data) { + console.log('FMS_Function_0900 success.' + data.fileList[0].uri); + done() + }, + fail: function (data, code) { + console.log('FMS_Function_0900 fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + }) + proMkdir.then(function () { + console.log('FMS_Function_0900 success'); + }); + }) + + /** + * @tc.number SUB_STORAGE_FMS_Function_1000 + * @tc.name FMS_Function_1000 + * @tc.desc Function of API, search file.The test file is exist. + */ + it('FMS_Function_1000', 0, async function (done) { + let proMkdir = new Promise(function (resolve, reject) { + filepicker.searchFile({ + uri: 'dataability:///public.storage.ability/' + deviceID + '/document/fms_test/leaf', + name: 'b.txt', + success: function (data) { + console.log('FMS_Function_1000 success.' + data.fileList[0].uri); + done() + }, + fail: function (data, code) { + console.log('FMS_Function_1000 fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + }) + proMkdir.then(function () { + console.log('FMS_Function_1000 success'); + }); + + }) + + /** + * @tc.number SUB_STORAGE_FMS_Function_1100 + * @tc.name FMS_Function_1100 + * @tc.desc Function of API, search file.The test file is exist. + */ + it('FMS_Function_1100', 0, async function (done) { + let proMkdir = new Promise(function (resolve, reject) { + filepicker.searchFile({ + uri: 'dataability:///public.storage.ability/' + deviceID + '/root/files', + name: 'a.txt', + success: function (data) { + console.log('FMS_Function_1100 success.' + data.fileList[0].uri); + done() + }, + fail: function (data, code) { + console.log('FMS_Function_1100 fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + }) + proMkdir.then(function () { + console.log('FMS_Function_1100 success'); + }); + + }) + + /** + * @tc.number SUB_STORAGE_FMS_Function_1200 + * @tc.name FMS_Function_1200 + * @tc.desc Function of API, Get all file information in the specified directory + */ + it('FMS_Function_1200', 0, async function (done) { + let proMkdir = new Promise(function (resolve, reject) { + filepicker.list({ + uri: 'dataability:///public.storage.ability/' + deviceID + '/document/fms_test/leaf', + success: function (data) { + console.log('FMS_Function_1200 success.' + data.fileList[0].uri); + done() + }, + fail: function (data, code) { + console.log('FMS_Function_1200 fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + }) + proMkdir.then(function () { + console.log('FMS_Function_1200 success'); + }); + }) + + /** + * @tc.number SUB_STORAGE_FMS_Function_1300 + * @tc.name FMS_Function_1300 + * @tc.desc Function of API, Get all file information in the specified directory + */ + it('FMS_Function_1300', 0, async function (done) { + let proMkdir = new Promise(function (resolve, reject) { + filepicker.list({ + uri: 'dataability:///public.storage.ability/' + deviceID + '/root', + success: function (data) { + console.log('FMS_Function_1300 success.' + data.fileList[0].uri); + done() + }, + fail: function (data, code) { + console.log('FMS_Function_1300 fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }); + }) + proMkdir.then(function () { + console.log('FMS_Function_1300 success'); + }); + }) + +}) diff --git a/storage/storagefmspublicjstest/src/main/js/default/test/FmsPublicError.test.js b/storage/storagefmspublicjstest/src/main/js/default/test/FmsPublicError.test.js new file mode 100644 index 0000000000000000000000000000000000000000..dcdedfcb22d42efe0ca8883ed20e8edcb1e9b63f --- /dev/null +++ b/storage/storagefmspublicjstest/src/main/js/default/test/FmsPublicError.test.js @@ -0,0 +1,520 @@ +/* + * 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 filepicker from '@ohos.filepicker'; +import { + describe, + it, + expect +} +from 'deccjsunit/index' +import { + prepareFile, + fmsPublic, +} +from './Common' + +describe('FilepickerTest', function () { + + let deviceID = 0; + + /** + * @tc.number SUB_STORAGE_File_Test_Error_0000 + * @tc.name File_Test_Error_0000 + * @tc.desc Error of API, Move files when disk space is full. + */ + it('File_Test_Error_0000', 0, function (done) { + try { + filepicker.getDeviceInfo({ + success: function (data) { + console.log('File_Test_Error_0000_start call mkdir success.' + data.deviceList[0].deviceID); + deviceID = data.deviceList[2].deviceID; + if(deviceID == 0){ + console.log('SD card not mounted') + done() + }else{ + expect(null).assertFail() + } + }, + fail: function (data, code) { + console.error('File_Test_Error_0000_start call fail callback fail, code: ' + code + ', data: ' + data); + }, + }); + } catch (e) { + console.log('File_Test_Error_0000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_File_Test_Error_0100 + * @tc.name File_Test_Error_0100 + * @tc.desc Error of API, Move files when disk space is full. + * Create the file in advance and give 777 permission, + * path:/dataability:///public.storage.ability/deviceID/udocument/files/leaf + */ + it('File_Test_Error_0100', 0, function (done) { + try { + filepicker.mkdir({ + uri: 'dataability:///public.storage.ability/' + deviceID + '/udocument/files/leaf', + success: function () { + console.log('File_Test_Error_0100 call mkdir success.'); + expect(null).assertFail(); + }, + fail: function (data, code) { + console.error('File_Test_Error_0100 call fail callback fail, code: ' + code + ', data: ' + data); + expect(code == 202).assertTrue(); + done() + }, + }); + } catch (e) { + console.log('File_Test_Error_0100 has failed for ' + e); + } + }); + + /** + * @tc.number SUB_STORAGE_File_Test_Error_0200 + * @tc.name File_Test_Error_0200 + * @tc.desc Error of API, Move files when disk space is full. + * Create the file in advance and give 777 permission, + * path:/data123ability:///public.storage.ability/deviceID/document/files.txt/leaf + */ + it('File_Test_Error_0200', 0, function (done) { + try { + filepicker.mkdir({ + uri: 'data123ability:///public.storage.ability/' + deviceID + '/document/files/leaf', + success: function () { + console.log('File_Test_Error_0200 call mkdir success.'); + expect(null).assertFail(); + }, + fail: function (data, code) { + console.error('File_Test_Error_0200 call fail callback fail, code: ' + code + ', data: ' + data); + expect(code == 302).assertTrue() + done() + }, + }); + } catch (e) { + console.log('File_Test_Error_0200 has failed for ' + e); + } + }); + + /** + * @tc.number SUB_STORAGE_File_Test_Error_0300 + * @tc.name File_Test_Error_0300 + * @tc.desc Error of API, Move files when disk space is full. + * Create the file in advance and give 777 permission, + * path:/dataability:///public.storage.ability/deviceID/document/files/lea + */ + it('File_Test_Error_0300', 0, function (done) { + try { + filepicker.mkdir({ + uri: 'dataability:///public.storage.ability/' + deviceID + '/document/files/lea', + success: function () { + console.log('File_Test_Error_0300 call mkdir success.'); + expect(null).assertFail(); + }, + fail: function (data, code) { + console.error('File_Test_Error_0300 call fail callback fail, code: ' + code + ', data: ' + data); + expect(code == 202).assertTrue() + done() + }, + }); + } catch (e) { + console.log('File_Test_Error_0300 has failed for ' + e); + } + }); + + /** + * @tc.number SUB_STORAGE_File_Test_Error_0400 + * @tc.name File_Test_Error_0400 + * @tc.desc Error of API, Move files when disk space is full. + * Create the file in advance and give 777 permission, + * path:/dataability:///public.storage.ability/‘’/document/files/leaf + */ + it('File_Test_Error_0400', 0, function (done) { + try { + filepicker.mkdir({ + uri: '/data/ss/files' + }); + let fpath = fmsPublic('File_Test_Error_0400'); + prepareFile(fpath, 'hello'); + filepicker.saveFile({ + srcUri: ['dataability:///public.storage.ability/data/ss/files/File_Test_Error_0400'], + dstUri: 'dataability:///public.storage.ability/‘’/document/files/leaf', + success: function (data) { + console.log('File_Test_Error_0400 call mkdir success.' + data.saveFileList[0].status); + expect(null).assertFail(); + }, + fail: function (data, code) { + console.error('File_Test_Error_0400 call fail callback fail, code: ' + code + ', data: ' + data); + expect(code == 300).assertTrue() + done() + }, + }); + } catch (e) { + console.log('File_Test_Error_0400 has failed for ' + e); + } + }); + + /** + * @tc.number SUB_STORAGE_File_Test_Error_0500 + * @tc.name File_Test_Error_0500 + * @tc.desc Error of API, Move files when disk space is full. + * Create the file in advance and give 777 permission, + * path:/dataability:///public.storage.ability/deviceID/document/files/leaf + */ + it('File_Test_Error_0500', 0, function (done) { + try { + let fpath = fmsPublic('File_Test_Error_0500'); + prepareFile(fpath, 'hello'); + filepicker.saveFile({ + srcUri: ['dataability:///public.storage.ability/data/ss/file/File_Test_Error_0500'], + dstUri: 'dataability:///public.storage.ability/' + deviceID + '/document/files/leaf', + success: function (data) { + console.log('File_Test_Error_0500 call mkdir success.' + data.saveFileList[0].status); + expect(null).assertFail(); + }, + fail: function (data, code) { + console.error('File_Test_Error_0500 call fail callback fail, code: ' + code + ', data: ' + data); + expect(code == 300).assertTrue() + done() + }, + }); + } catch (e) { + console.log('File_Test_Error_0500 has failed for ' + e); + } + }); + + /** + * @tc.number SUB_STORAGE_File_Test_Error_0600 + * @tc.name File_Test_Error_0600 + * @tc.desc Error of API, Move files when disk space is full. + * Create the file in advance and give 777 permission, + * path:/dataability:///public.storage.ability/deviceID/document/files/leaf + */ + it('File_Test_Error_0600', 0, function (done) { + try { + filepicker.saveFile({ + srcUri: ['dataability:///public.storage.ability/data/ss/file/A.txt'], + dstUri: 'dataability:///public.storage.ability/' + deviceID + '/document/files/leaf', + success: function (data) { + console.log('File_Test_Error_0600 call mkdir success.' + data.saveFileList[0].status); + expect(null).assertFail(); + }, + fail: function (data, code) { + console.error('File_Test_Error_0600 call fail callback fail, code: ' + code + ', data: ' + data); + expect(code == 300).assertTrue() + done() + }, + }); + } catch (e) { + console.log('File_Test_Error_0600 has failed for ' + e); + } + }); + + /** + * @tc.number SUB_STORAGE_File_Test_Error_0700 + * @tc.name File_Test_Error_0700 + * @tc.desc Error of API, Move files when disk space is full. + * Create the file in advance and give 777 permission, + * path:/dataability:///public.storage.ability/deviceID/document/files/lea + */ + it('File_Test_Error_0700', 0, function (done) { + try { + filepicker.saveFile({ + srcUri: ['dataability:///public.storage.ability/data/ss/files/a.txt'], + dstUri: 'dataability:///public.storage.ability/' + deviceID + '/document/files/lea', + success: function (data) { + console.log('File_Test_Error_0700 call mkdir success.' + data.saveFileList[0].status); + expect(null).assertFail(); + }, + fail: function (data, code) { + console.error('File_Test_Error_0700 call fail callback fail, code: ' + code + ', data: ' + data); + expect(code == 202).assertTrue() + done() + }, + }); + } catch (e) { + console.log('File_Test_Error_0700 has failed for ' + e); + } + }); + + /** + * @tc.number SUB_STORAGE_File_Test_Error_0800 + * @tc.name File_Test_Error_0800 + * @tc.desc Error of API, Move files when disk space is full. + * Create the file in advance and give 777 permission, + * path:/dataability:///public.storage.ability/deviceID/document/bb/aa/files/leaf + */ + it('File_Test_Error_0800', 0, function (done) { + try { + filepicker.saveFile({ + srcUri: ['dataability:///public.storage.ability/data/ss/files/a.txt'], + dstUri: 'dataability:///public.storage.ability/' + deviceID + '/document/bb/aa/files/leaf', + success: function (data) { + console.log('File_Test_Error_0800 call mkdir success.' + data.saveFileList[0].status); + expect(null).assertFail(); + }, + fail: function (data, code) { + console.error('File_Test_Error_0800 call fail callback fail, code: ' + code + ', data: ' + data); + expect(code == 300).assertTrue() + done() + }, + }); + } catch (e) { + console.log('File_Test_Error_0800 has failed for ' + e); + } + }); + + /** + * @tc.number SUB_STORAGE_File_Test_Error_0900 + * @tc.name File_Test_Error_0900 + * @tc.desc Error of API, Move files when disk space is full. + * Create the file in advance and give 777 permission, + * path:/data123ability:///public.storage.ability/' + deviceID + '/document/files/leaf + */ + it('File_Test_Error_0900', 0, function (done) { + try { + filepicker.saveFile({ + srcUri: ['dataability:///public.storage.ability/data/ss/files/a.txt'], + dstUri: 'data123ability:///public.storage.ability/' + deviceID + '/document/files/leaf', + success: function (data) { + console.log('File_Test_Error_0900 call mkdir success.' + data.saveFileList[0].status); + expect(null).assertFail(); + }, + fail: function (data, code) { + console.error('File_Test_Error_0900 call fail callback fail, code: ' + code + ', data: ' + data); + expect(code == 302).assertTrue() + done() + }, + }); + } catch (e) { + console.log('File_Test_Error_0900 has failed for ' + e); + } + }); + + /** + * @tc.number SUB_STORAGE_File_Test_Error_1000 + * @tc.name File_Test_Error_1000 + * @tc.desc Error of API, Move files when disk space is full. + * Create the file in advance and give 777 permission, + * path:/dataability:///public.storage.ability/deviceID/document/files/leaf + */ + it('File_Test_Error_1000', 0, function (done) { + try { + filepicker.saveFile({ + srcUri: ['dataability:///public.storage.ability/data/ss/files/a.txt'], + srcUri1: ['dataability:///public.storage.ability/data/ss/files/a.txt'], + dstUri: 'dataability:///public.storage.ability/' + deviceID + '/document/files/leaf', + success: function (data) { + console.log('File_Test_Error_1000 call mkdir success.' + data.saveFileList[0].status); + expect(null).assertFail(); + }, + fail: function (data, code) { + console.error('File_Test_Error_1000 call fail callback fail, code: ' + code + ', data: ' + data); + expect(code == 300).assertTrue() + done() + }, + }); + } catch (e) { + console.log('File_Test_Error_1000 has failed for ' + e); + } + }); + + /** + * @tc.number SUB_STORAGE_File_Test_Error_1100 + * @tc.name File_Test_Error_1100 + * @tc.desc Error of API, Move files when disk space is full. + * Create the file in advance and give 777 permission, + * path:/dataability:///public.storage.ability/deviceID/document/files/leaf + */ + it('File_Test_Error_1100', 0, function (done) { + try { + filepicker.searchFile({ + uri: 'dataability:///public.storage.ability/' + deviceID + '/document/files/leaf', + name: 'test', + success: function (data) { + console.log('File_Test_Error_1100 call mkdir success.' + data.fileList[0].uri); + expect(null).assertFail(); + }, + fail: function (data, code) { + console.error('File_Test_Error_1100 call fail callback fail, code: ' + code + ', data: ' + data); + expect(code == 300).assertTrue() + done() + }, + }); + } catch (e) { + console.log('File_Test_Error_1100 has failed for ' + e); + } + }); + + /** + * @tc.number SUB_STORAGE_File_Test_Error_1200 + * @tc.name File_Test_Error_1200 + * @tc.desc Error of API, Move files when disk space is full. + * Create the file in advance and give 777 permission, + * path:/dataability:///public.storage.ability/deviceID/document/a/b/files/leaf + */ + it('File_Test_Error_1200', 0, function (done) { + try { + filepicker.searchFile({ + uri: 'dataability:///public.storage.ability/' + deviceID + '/document/a/b/files/leaf', + name: 'test', + success: function (data) { + console.log('File_Test_Error_1200 call mkdir success.' + data.fileList[0].uri); + expect(null).assertFail(); + }, + fail: function (data, code) { + console.error('File_Test_Error_1200 call fail callback fail, code: ' + code + ', data: ' + data); + expect(code == 300).assertTrue() + done() + }, + }); + } catch (e) { + console.log('File_Test_Error_1200 has failed for ' + e); + } + }); + + /** + * @tc.number SUB_STORAGE_File_Test_Error_1300 + * @tc.name File_Test_Error_1300 + * @tc.desc Error of API, Move files when disk space is full. + * Create the file in advance and give 777 permission, + * path:'' + */ + it('File_Test_Error_1300', 0, function (done) { + try { + filepicker.searchFile({ + uri: '', + name: 'a', + success: function (data) { + console.log('File_Test_Error_1300 call mkdir success.' + data.fileList[0].uri); + expect(null).assertFail(); + }, + fail: function (data, code) { + console.error('File_Test_Error_1300 call fail callback fail, code: ' + code + ', data: ' + data); + expect(code == 302).assertTrue() + done() + }, + }); + } catch (e) { + console.log('File_Test_Error_1300 has failed for ' + e); + } + }); + + /** + * @tc.number SUB_STORAGE_File_Test_Error_1400 + * @tc.name File_Test_Error_1400 + * @tc.desc Error of API, Move files when disk space is full. + * Create the file in advance and give 777 permission, + * path:'dataability:///public.storage.ability/device_id/udocument/files/leaf' + */ + it('File_Test_Error_1400', 0, function (done) { + try { + filepicker.list({ + uri: 'dataability:///public.storage.ability/device_id/udocument/files/leaf', + success: function (data) { + console.log('File_Test_Error_1400 call mkdir success.' + data.fileList[0].uri); + expect(null).assertFail(); + }, + fail: function (data, code) { + console.error('File_Test_Error_1400 call fail callback fail, code: ' + code + ', data: ' + data); + expect(code == 202).assertTrue() + done() + }, + }); + } catch (e) { + console.log('File_Test_Error_1400 has failed for ' + e); + } + }); + + /** + * @tc.number SUB_STORAGE_File_Test_Error_1400 + * @tc.name File_Test_Error_1400 + * @tc.desc Error of API, Move files when disk space is full. + * Create the file in advance and give 777 permission, + * path:'' + */ + it('File_Test_Error_1500', 0, function (done) { + try { + filepicker.list({ + uri: '', + success: function (data) { + console.log('File_Test_Error_1500 call mkdir success.' + data.fileList[0].uri); + expect(null).assertFail(); + }, + fail: function (data, code) { + console.error('File_Test_Error_1500 call fail callback fail, code: ' + code + ', data: ' + data); + expect(code == 302).assertTrue() + done() + }, + }); + } catch (e) { + console.log('File_Test_Error_1500 has failed for ' + e); + } + }); + + /** + * @tc.number SUB_STORAGE_File_Test_Error_1500 + * @tc.name File_Test_Error_1500 + * @tc.desc Error of API, Move files when disk space is full. + * Create the file in advance and give 777 permission, + * path:/dataability:///public.storage.ability/deviceID/document/file/leaf + */ + it('File_Test_Error_1600', 0, function (done) { + try { + filepicker.list({ + uri: 'dataability:///public.storage.ability/' + deviceID + '/document/file/leaf', + success: function (data) { + console.log('File_Test_Error_1600 call mkdir success.' + data.fileList[0].uri); + expect(null).assertFail(); + }, + fail: function (data, code) { + console.error('File_Test_Error_1600 call fail callback fail, code: ' + code + ', data: ' + data); + expect(code == 300).assertTrue() + done() + }, + }); + } catch (e) { + console.log('File_Test_Error_1600 has failed for ' + e); + } + }); + + /** + * @tc.number SUB_STORAGE_File_Test_Error_1700 + * @tc.name File_Test_Error_1700 + * @tc.desc Error of API, Move files when disk space is full. + * Create the file in advance and give 777 permission, + * path:/data123ability:///public.storage.ability/deviceID/document/file/leaf + */ + it('File_Test_Error_1700', 0, function (done) { + try { + filepicker.list({ + uri: 'data123ability:///public.storage.ability/' + deviceID + '/document/file/leaf', + success: function (data) { + console.log('File_Test_Error_1700 call mkdir success.' + data.fileList[0].uri); + expect(null).assertFail(); + }, + fail: function (data, code) { + console.error('File_Test_Error_1700 call fail callback fail, code: ' + code + ', data: ' + data); + expect(code == 302).assertTrue() + done() + }, + }); + } catch (e) { + console.log('File_Test_Error_1700 has failed for ' + e); + } + }); +}); diff --git a/storage/storagefmspublicjstest/src/main/js/default/test/List.test.js b/storage/storagefmspublicjstest/src/main/js/default/test/List.test.js new file mode 100644 index 0000000000000000000000000000000000000000..74e71d8580c30f3f186c76c4a4f7db1eaa551001 --- /dev/null +++ b/storage/storagefmspublicjstest/src/main/js/default/test/List.test.js @@ -0,0 +1,17 @@ +/* + * 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('./FmsPublic.test.js') +require('./FmsPublicError.test.js') diff --git a/storage/storagefmspublicjstest/src/main/resources/base/element/string.json b/storage/storagefmspublicjstest/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..4b5a8bbc02d07ca41a3c0f63834395a33e02152a --- /dev/null +++ b/storage/storagefmspublicjstest/src/main/resources/base/element/string.json @@ -0,0 +1,12 @@ +{ + "string": [ + { + "name": "app_name", + "value": "storagefilestabilityjstest" + }, + { + "name": "mainability_description", + "value": "JS_Phone_Empty Feature Ability" + } + ] +} \ No newline at end of file diff --git a/storage/storagefmspublicjstest/src/main/resources/base/media/icon.png b/storage/storagefmspublicjstest/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/storage/storagefmspublicjstest/src/main/resources/base/media/icon.png differ diff --git a/storage/storagefmssharejstest/BUILD.gn b/storage/storagefmssharejstest/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..a468d4b04ff5a561cfc05d367a770792377953d8 --- /dev/null +++ b/storage/storagefmssharejstest/BUILD.gn @@ -0,0 +1,38 @@ +# 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("storagefmsshare_js_test") { + hap_profile = "./src/main/config.json" + deps = [ + ":storagefmsshare_js_assets", + ":storagefmsshare_js_resources", + ] + + # shared_libraries = [ + # "//third_party/giflib:libgif", + # "//third_party/libpng:libpng", + # ] + certificate_profile = "./signature/openharmony_sx.p7b" + hap_name = "storagefmssharejstest" + + # part_name = "prebuilt_hap" + # subsystem_name = "xts" +} +ohos_js_assets("storagefmsshare_js_assets") { + source_dir = "./src/main/js/default" +} +ohos_resources("storagefmsshare_js_resources") { + sources = [ "./src/main/resources" ] + hap_profile = "./src/main/config.json" +} diff --git a/storage/storagefmssharejstest/Test.json b/storage/storagefmssharejstest/Test.json new file mode 100644 index 0000000000000000000000000000000000000000..44dc1ec254deffdbf243ff7ca327163a765c5b98 --- /dev/null +++ b/storage/storagefmssharejstest/Test.json @@ -0,0 +1,18 @@ +{ + "description": "Configuration for storage file and fileio Tests", + "driver": { + "type": "JSUnitTest", + "test-timeout": "60000", + "package": "ohos.acys.test", + "shell-timeout": "60000" + }, + "kits": [ + { + "test-file-name": [ + "storagefmssharejstest.hap" + ], + "type": "AppInstallKit", + "cleanup-apps": true + } + ] +} \ No newline at end of file diff --git a/storage/storagefmssharejstest/signature/openharmony_sx.p7b b/storage/storagefmssharejstest/signature/openharmony_sx.p7b new file mode 100644 index 0000000000000000000000000000000000000000..9be1e98fa4c0c28ca997ed660112fa16b194f0f5 Binary files /dev/null and b/storage/storagefmssharejstest/signature/openharmony_sx.p7b differ diff --git a/storage/storagefmssharejstest/src/main/config.json b/storage/storagefmssharejstest/src/main/config.json new file mode 100644 index 0000000000000000000000000000000000000000..3b243aeb37087a1c304361bb1b52f4bbadaabfc0 --- /dev/null +++ b/storage/storagefmssharejstest/src/main/config.json @@ -0,0 +1,72 @@ +{ + "app": { + "bundleName": "ohos.acts.test", + "vendor": "example", + "version": { + "code": 1000000, + "name": "1.0.0" + }, + "apiVersion": { + "compatible": 4, + "target": 5, + "releaseType": "Release" + } + }, + "deviceConfig": {}, + "module": { + "package": "ohos.acts.test", + "name": ".MyApplication", + "deviceType": [ + "phone" + ], + "distro": { + "installationFree": true, + "deliveryWithInstall": true, + "moduleName": "entry", + "moduleType": "entry" + }, + "abilities": [ + { + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ], + "name": "ohos.acts.test.MainAbility", + "icon": "$media:icon", + "description": "$string:mainability_description", + "label": "$string:app_name", + "type": "page", + "visible": true, + "launchType": "standard" + } + ], + "js": [ + { + "pages": [ + "pages/index/index" + ], + "name": "default", + "window": { + "designWidth": 720, + "autoDesignWidth": false + } + }, + { + "pages": [ + "pages/index/index" + ], + "name": "default2", + "window": { + "designWidth": 720, + "autoDesignWidth": false + } + } + ] + } +} \ No newline at end of file diff --git a/storage/storagefmssharejstest/src/main/js/default/app.js b/storage/storagefmssharejstest/src/main/js/default/app.js new file mode 100644 index 0000000000000000000000000000000000000000..60ee141c8dbd251c763b7b74552b5a133a774d6a --- /dev/null +++ b/storage/storagefmssharejstest/src/main/js/default/app.js @@ -0,0 +1,23 @@ +/* + * Copyright (C) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export default { + onCreate() { + console.info('ohos.acts.distributeddatamgr.distributedfile onCreate'); + }, + onDestroy() { + console.info('ohos.acts.distributeddatamgr.distributedfile onCreate'); + } +}; diff --git a/storage/storagefmssharejstest/src/main/js/default/i18n/en-US.json b/storage/storagefmssharejstest/src/main/js/default/i18n/en-US.json new file mode 100644 index 0000000000000000000000000000000000000000..ead52ed2e09ec82aaf7aa9f4e714ed39ea88308e --- /dev/null +++ b/storage/storagefmssharejstest/src/main/js/default/i18n/en-US.json @@ -0,0 +1,6 @@ +{ + "strings": { + "hello": "Hello", + "world": "Test" + } +} \ No newline at end of file diff --git a/storage/storagefmssharejstest/src/main/js/default/i18n/zh-CN.json b/storage/storagefmssharejstest/src/main/js/default/i18n/zh-CN.json new file mode 100644 index 0000000000000000000000000000000000000000..3f48f2585b24a8fe4a745e8ee2972a9e991a7803 --- /dev/null +++ b/storage/storagefmssharejstest/src/main/js/default/i18n/zh-CN.json @@ -0,0 +1,6 @@ +{ + "strings": { + "hello": "您好", + "world": "测试" + } +} \ No newline at end of file diff --git a/storage/storagefmssharejstest/src/main/js/default/pages/index/index.css b/storage/storagefmssharejstest/src/main/js/default/pages/index/index.css new file mode 100644 index 0000000000000000000000000000000000000000..6fda792753f2e15f22b529c7b90a82185b2770bf --- /dev/null +++ b/storage/storagefmssharejstest/src/main/js/default/pages/index/index.css @@ -0,0 +1,9 @@ +.container { + flex-direction: column; + justify-content: center; + align-items: center; +} + +.title { + font-size: 100px; +} diff --git a/storage/storagefmssharejstest/src/main/js/default/pages/index/index.hml b/storage/storagefmssharejstest/src/main/js/default/pages/index/index.hml new file mode 100644 index 0000000000000000000000000000000000000000..f64b040a5ae394dbaa5e185e1ecd4f4556b92184 --- /dev/null +++ b/storage/storagefmssharejstest/src/main/js/default/pages/index/index.hml @@ -0,0 +1,5 @@ +
+ + {{ $t('strings.hello') }} {{ title }} + +
diff --git a/storage/storagefmssharejstest/src/main/js/default/pages/index/index.js b/storage/storagefmssharejstest/src/main/js/default/pages/index/index.js new file mode 100644 index 0000000000000000000000000000000000000000..f7894a72230dd2356d1ce272896c9e0fd09e08cd --- /dev/null +++ b/storage/storagefmssharejstest/src/main/js/default/pages/index/index.js @@ -0,0 +1,40 @@ +/* + * 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 app from '@system.app' + +import {Core} from 'deccjsunit/index' + +const injectRef = Object.getPrototypeOf(global) || global +injectRef.regeneratorRuntime = require('@babel/runtime/regenerator') + +export default { + data: { + title: '' + }, + onInit() { + this.title = this.$t('strings.world'); + }, + onShow() { + console.info('onShow finish') + 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 diff --git a/storage/storagefmssharejstest/src/main/js/default/test/Common.js b/storage/storagefmssharejstest/src/main/js/default/test/Common.js new file mode 100644 index 0000000000000000000000000000000000000000..e94e7f4049a3da8852e3fcba5be70a7100756bd4 --- /dev/null +++ b/storage/storagefmssharejstest/src/main/js/default/test/Common.js @@ -0,0 +1,180 @@ +/* + * 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 filePickerName(testName,deviceID) { + const BASE_PATH = '/data/ss/'+deviceID+'/fms_test/' + return BASE_PATH + testName +} +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 fmsFileName(testName) { + const BASE_PATH = "/data/accounts/account_0/appdata/ohos.acts.test/files/" + return BASE_PATH + testName +} +export function fmsCacheName(testName) { + const BASE_PATH = "/data/accounts/account_0/appdata/ohos.acts.test/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; +} diff --git a/storage/storagefmssharejstest/src/main/js/default/test/FmsShare.test.js b/storage/storagefmssharejstest/src/main/js/default/test/FmsShare.test.js new file mode 100644 index 0000000000000000000000000000000000000000..93847ddc81f00deb376acf32127bdd261b2dc0dc --- /dev/null +++ b/storage/storagefmssharejstest/src/main/js/default/test/FmsShare.test.js @@ -0,0 +1,463 @@ +/* + * 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 fileShareAbility from '@ohos.fileshare'; +import { + describe, + beforeAll, + it, + expect +} +from 'deccjsunit/index' +import { + prepareFile, + fmsFileName, + fmsCacheName +} +from './Common' + +describe('fileTest', function () { + beforeAll(() => { + prepareFile(fmsFileName('music.mp3'), 'content'); + prepareFile(fmsFileName('f0.txt'), 'content'); + prepareFile(fmsFileName('picture.jpg'), 'content'); + prepareFile(fmsFileName('picture2.jpg'), 'content'); + prepareFile(fmsFileName('文件.doc'), 'content'); + prepareFile(fmsFileName('cross Fire.apk'), 'content'); + prepareFile(fmsCacheName('video.mp4'), 'content'); + prepareFile(fmsFileName('file.xlsx'), 'content'); + prepareFile(fmsFileName('f2.ppt'), 'content'); + prepareFile(fmsFileName('f3.doc'), 'content'); + fileio.mkdirSync(fmsFileName('folder')); + let text = '[{"type": "files-path", "name": "primary_leaf", "path": "/music.mp3"},' + + '{"type": "files-path", "name": "primary_leaf2", "path": "/f0.txt"},' + + '{"type": "files-path", "name": "primary_leaf3", "path": "/picture.jpg"},' + + '{"type": "files-path", "name": "primary_leaf4", "path": "/picture2.jpg"},' + + '{"type": "files-path", "name": "primary_leaf5", "path": "/文件.doc"},' + + '{"type": "files-path", "name": "primary_leaf6", "path": "/cross Fire.apk"},' + + '{"type": "cache-path", "name": "cacheprimary_leaf", "path": "/video.mp4"},' + + '{"type": "files-path", "name": "primary_leaf7", "path": "/file.xlsx"},' + + '{"type": "files-path", "name": "primary_leaf8", "path": "/f3.doc"},' + + '{"type": "files-path", "name": "primary_leaf9", "path": "/folder"' + + '}]'; + prepareFile(fmsFileName('test.json'), text); + }) + + /** + * @tc.number SUB_STORAGE_FMS_fuzzyFileToUri_100 + * @tc.name FMS_fuzzyFileToUri_100 + * @tc.desc Verify device ID,Call fuzzyfiletouri to + * judge whether the return value is correct. + */ + it('FMS_fuzzyFileToUri_100', 0, function () { + fileShareAbility.fuzzyFileToUri({ + deviceId: '440E-0906', + authority: 'ohos.acts.test.ability', + uri: 'internal://app/f0.txt', + displayName: 'f1.txt', + success: function (uri) { + console.log('FMS_fuzzyFileToUri_100 call fuzzyFileToUri success. uri:' + uri); + expect(uri == 'dataability://440E-0906/ohos.acts.test.ability/primary/document/files' + +'/primary_leaf2/f0.txt/leaf?displayName=f1.txt#').assertTrue(); + }, + fail: function (data, code) { + console.log('FMS_fuzzyFileToUri_100 call fuzzyFileToUri fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + complete: function () { + console.log('FMS_fuzzyFileToUri_100 call fuzzyFileToUri in complete'); + } + }); + }) + + /** + * @tc.number SUB_STORAGE_FMS_fuzzyFileToUri_200 + * @tc.name FMS_fuzzyFileToUri_200 + * @tc.desc Verify app path,Call fuzzyfiletouri to + * judge whether the return value is correct. + */ + it('FMS_fuzzyFileToUri_200', 0, function () { + fileShareAbility.fuzzyFileToUri({ + deviceId: '440E-0906', + authority: 'ohos.acts.test.ability', + uri: 'internal://app/picture.jpg', + displayName: 'picture.png', + success: function (uri) { + console.log('FMS_fuzzyFileToUri_200 call fuzzyFileToUri success. uri:' + uri); + expect(uri == 'dataability://440E-0906/ohos.acts.test.ability/primary/document/files' + +'/primary_leaf3/picture.jpg/leaf?displayName=picture.png#').assertTrue(); + }, + fail: function (data, code) { + console.log('FMS_fuzzyFileToUri_200 call fuzzyFileToUri fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }) + }) + + /** + * @tc.number SUB_STORAGE_FMS_fuzzyFileToUri_300 + * @tc.name FMS_fuzzyFileToUri_300 + * @tc.desc Verify that the app path virtual path is an in package file,Call fuzzyfiletouri + * to judge whether the return value is correct. + */ + it('FMS_fuzzyFileToUri_300', 0, function () { + fileShareAbility.fuzzyFileToUri({ + deviceId: '440E-0906', + authority: 'ohos.acts.test.ability', + uri: 'internal://app/../files/picture2.jpg', + displayName: 'picture2.png', + success: function (uri) { + console.log('FMS_fuzzyFileToUri_300 call fuzzyFileToUri success. uri:' + uri); + expect(uri == 'dataability://440E-0906/ohos.acts.test.ability/primary/document/files' + +'/primary_leaf4/picture2.jpg/leaf?displayName=picture2.png#').assertTrue(); + }, + fail: function (data, code) { + console.log('FMS_fuzzyFileToUri_300 call fuzzyFileToUri fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }) + }) + + /** + * @tc.number SUB_STORAGE_FMS_fuzzyFileToUri_400 + * @tc.name FMS_fuzzyFileToUri_400 + * @tc.desc Verify the Chinese file name under the app path,Call fuzzyfiletouri + * to judge whether the return value is correct. + */ + it('FMS_fuzzyFileToUri_400', 0, function () { + fileShareAbility.fuzzyFileToUri({ + deviceId: '440E-0906', + authority: 'ohos.acts.test.ability', + uri: 'internal://app/文件.doc', + displayName: 'file', + success: function (uri) { + console.log('FMS_fuzzyFileToUri_400 call fuzzyFileToUri success. uri:' + uri); + expect(uri == 'dataability://440E-0906/ohos.acts.test.ability/primary/document/files' + +'/primary_leaf5/文件.doc/leaf?displayName=file#').assertTrue(); + }, + fail: function (data, code) { + console.log('FMS_fuzzyFileToUri_400 call fuzzyFileToUri fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }) + }) + + /** + * @tc.number SUB_STORAGE_FMS_fuzzyFileToUri_500 + * @tc.name FMS_fuzzyFileToUri_500 + * @tc.desc Verify the blurred Chinese file name,Call fuzzyfiletouri + * to judge whether the return value is correct. + */ + it('FMS_fuzzyFileToUri_500', 0, function () { + fileShareAbility.fuzzyFileToUri({ + deviceId: '440E-0906', + authority: 'ohos.acts.test.ability', + uri: 'internal://app/cross Fire.apk', + displayName: '你好,世界', + success: function (uri) { + console.log('FMS_fuzzyFileToUri_500 call fuzzyFileToUri success. uri:' + uri); + expect(uri == 'dataability://440E-0906/ohos.acts.test.ability/primary/document/files' + +'/primary_leaf6/cross Fire.apk/leaf?displayName=你好,世界#').assertTrue(); + }, + fail: function (data, code) { + console.log('FMS_fuzzyFileToUri_500 call fuzzyFileToUri fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }) + }) + + /** + * @tc.number SUB_STORAGE_FMS_fuzzyFileToUri_600 + * @tc.name FMS_fuzzyFileToUri_600 + * @tc.desc Verify cache path,Call fuzzyfiletouri + * to judge whether the return value is correct. + */ + it('FMS_fuzzyFileToUri_600', 0, function () { + fileShareAbility.fuzzyFileToUri({ + deviceId: '440E-0906', + authority: 'ohos.acts.test.ability', + uri: 'internal://cache/video.mp4', + displayName: 'v1.mp4', + success: function (uri) { + console.log('FMS_fuzzyFileToUri_600 call fuzzyFileToUri success. uri:' + uri); + expect(uri == 'dataability://440E-0906/ohos.acts.test.ability/primary/document/cache' + +'/cacheprimary_leaf/video.mp4/leaf?displayName=v1.mp4#').assertTrue(); + }, + fail: function (data, code) { + console.log('FMS_fuzzyFileToUri_600 call fuzzyFileToUri fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }) + }) + + /** + * @tc.number SUB_STORAGE_FMS_fuzzyFileToUri_700 + * @tc.name FMS_fuzzyFileToUri_700 + * @tc.desc Verify that displayName does not exist,Call fuzzyfiletouri + * to judge whether the return value is correct. + */ + it('FMS_fuzzyFileToUri_700', 0, function () { + fileShareAbility.fuzzyFileToUri({ + deviceId: '440E-0906', + authority: 'ohos.acts.test.ability', + uri: 'internal://app/file.xlsx', + success: function (uri) { + console.log('FMS_fuzzyFileToUri_700 call fuzzyFileToUri success. uri:' + uri); + expect(uri == 'dataability://440E-0906/ohos.acts.test.ability/primary/document/files' + +'/primary_leaf7/file.xlsx/leaf').assertTrue(); + }, + fail: function (data, code) { + console.log('FMS_fuzzyFileToUri_700 call fuzzyFileToUri fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + }) + }) + + /** + * @tc.number SUB_STORAGE_FMS_fuzzyFileToUri_800 + * @tc.name FMS_fuzzyFileToUri_800 + * @tc.desc Verify that authority = null,Call the interface fuzzyfiletouri + * to check whether the interface call fails. + */ + it('FMS_fuzzyFileToUri_800', 0, function () { + fileShareAbility.fuzzyFileToUri({ + deviceId: '440E-0906', + authority: '', + uri: 'internal://app/f2.ppt', + success: function () { + console.log('FMS_fuzzyFileToUri_800 call fuzzyFileToUri success, fail!'); + expect(null).assertFail(); + }, + fail: function (data, code) { + console.log('FMS_fuzzyFileToUri_800 call fuzzyFileToUri pass, code: ' + code + ', data: ' + data); + expect(code == 202).assertTrue(); + }, + }) + }) + + /** + * @tc.number SUB_STORAGE_FMS_fuzzyFileToUri_900 + * @tc.name FMS_fuzzyFileToUri_900 + * @tc.desc Verify that authority is a different value,Call the interface fuzzyfiletouri + * to check whether the interface call fails. + */ + it('FMS_fuzzyFileToUri_900', 0, function () { + fileShareAbility.fuzzyFileToUri({ + deviceId: '440E-0906', + authority: 'com.abc.test.ability', + uri: 'internal://app/f3.doc', + success: function () { + console.log('FMS_fuzzyFileToUri_900 call fuzzyFileToUri success, fail!'); + expect(null).assertFail(); + }, + fail: function (data, code) { + console.log('FMS_fuzzyFileToUri_900 call fuzzyFileToUri pass, code: ' + code + ', data: ' + data); + expect(code == 202).assertTrue(); + }, + }) + }) + + /** + * @tc.number SUB_STORAGE_FMS_fuzzyFileToUri_1000 + * @tc.name FMS_fuzzyFileToUri_1000 + * @tc.desc Verify that uri = null,Call the interface fuzzyfiletouri + * to check whether the interface call fails. + */ + it('FMS_fuzzyFileToUri_1000', 0, function () { + fileShareAbility.fuzzyFileToUri({ + deviceId: '440E-0906', + authority: 'ohos.acts.test.ability', + uri: '', + success: function () { + console.log('FMS_fuzzyFileToUri_1000 call fuzzyFileToUri success, fail!'); + expect(null).assertFail(); + }, + fail: function (data, code) { + console.log('FMS_fuzzyFileToUri_1000 call fuzzyFileToUri pass, code: ' + code + ', data: ' + data); + expect(code == 302).assertTrue(); + }, + }) + }) + + /** + * @tc.number SUB_STORAGE_FMS_fuzzyFileToUri_1100 + * @tc.name FMS_fuzzyFileToUri_1100 + * @tc.desc Verify that there is no file under the app path,Call the interface fuzzyfiletouri + * to check whether the interface call fails. + */ + it('FMS_fuzzyFileToUri_1100', 0, function () { + fileShareAbility.fuzzyFileToUri({ + deviceId: '440E-0906', + authority: 'ohos.acts.test.ability', + uri: 'internal://app/f4', + success: function () { + console.log('FMS_fuzzyFileToUri_1100 call fuzzyFileToUri success, fail!'); + expect(null).assertFail(); + }, + fail: function (data, code) { + console.log('FMS_fuzzyFileToUri_1100 call fuzzyFileToUri pass, code: ' + code + ', data: ' + data); + expect(code == 301).assertTrue(); + + }, + }) + }) + + /** + * @tc.number SUB_STORAGE_FMS_fuzzyFileToUri_1200 + * @tc.name FMS_fuzzyFileToUri_1200 + * @tc.desc Verify device ID=null,Call the interface fuzzyfiletouri + * to check whether the interface call fails. + */ + it('FMS_fuzzyFileToUri_1200', 0, function () { + fileShareAbility.fuzzyFileToUri({ + deviceId: '', + authority: 'ohos.acts.test.ability', + uri: 'internal://app/music.mp3', + displayName: 'helloworld', + success: function () { + console.log('FMS_fuzzyFileToUri_1200 call fuzzyFileToUri success, fail!'); + expect(null).assertFail(); + }, + fail: function (data, code) { + console.log('FMS_fuzzyFileToUri_1200 call fuzzyFileToUri pass, code: ' + code + ', data: ' + data); + expect(code == 202).assertTrue(); + }, + }); + }) + + /** + * @tc.number SUB_STORAGE_FMS_fuzzyFileToUri_1300 + * @tc.name FMS_fuzzyFileToUri_1300 + * @tc.desc Verify the virtual path to an out of package file,Call the interface fuzzyfiletouri + * to check whether the interface call fails. + */ + it('FMS_fuzzyFileToUri_1300', 0, function () { + fileShareAbility.fuzzyFileToUri({ + deviceId: '440E-0906', + authority: 'ohos.acts.test.ability', + uri: 'internal://app/../../../applications/com.ohos.settings/com.ohos.settings/config.json', + displayName: 'helloworld', + success: function () { + console.log('FMS_fuzzyFileToUri_1300 call fuzzyFileToUri success, fail!'); + expect(null).assertFail(); + }, + fail: function (data, code) { + console.log('FMS_fuzzyFileToUri_1300 call fuzzyFileToUri pass, code: ' + code + ', data: ' + data); + expect(code == 302).assertTrue(); + }, + }); + }) + + /** + * @tc.number SUB_STORAGE_FMS_fuzzyFileToUri_1400 + * @tc.name FMS_fuzzyFileToUri_1400 + * @tc.desc Verify that the folder exists under the app path,Call the interface + * fuzzyfiletouri to check whether the interface call fails. + */ + it('FMS_fuzzyFileToUri_1400', 0, function () { + fileShareAbility.fuzzyFileToUri({ + deviceId: '440E-0906', + authority: 'ohos.acts.test.ability', + uri: 'internal://app/folder', + displayName: 'helloworld', + success: function () { + console.log('FMS_fuzzyFileToUri_1400 call fuzzyFileToUri success, fail!'); + expect(null).assertFail(); + }, + fail: function (data, code) { + console.log('FMS_fuzzyFileToUri_1400 call fuzzyFileToUri pass, code: ' + code + ', data: ' + data); + expect(code == 300).assertTrue(); + }, + }); + }) + + /** + * @tc.number SUB_STORAGE_FMS_fuzzyFileToUri_1500 + * @tc.name FMS_fuzzyFileToUri_1500 + * @tc.desc The shared file is not configured in JSON + */ + it('FMS_fuzzyFileToUri_1500', 0, function () { + fileShareAbility.fuzzyFileToUri({ + deviceId: '440E-0906', + authority: 'ohos.acts.test.ability', + uri: 'internal://app/f2.ppt', + success: function () { + console.log('FMS_fuzzyFileToUri_1500 call fuzzyFileToUri success, fail!'); + expect(null).assertFail(); + }, + fail: function (data, code) { + console.log('FMS_fuzzyFileToUri_1500 call fuzzyFileToUri pass, code: ' + code + ', data: ' + data); + expect(code == 300).assertTrue(); + }, + }); + }) + + /** + * @tc.number SUB_STORAGE_FMS_Performance_0000 + * @tc.name FMS_Performance_0000 + * @tc.desc Performance test + */ + it('FMS_Performance_0000', 0, function () { + let start = new Date().getTime(); + for(let i = 0; i < 1000;i++){ + fileShareAbility.fuzzyFileToUri({ + deviceId: '440E-0906', + authority: 'ohos.acts.test.ability', + uri: 'internal://app/f0.txt', + displayName: 'f1.txt', + success: function () { + let end = new Date().getTime(); + let time = end - start ; + console.log('FMS_Performance_0000 call fuzzyFileToUri success. time:' +time+','+i); + }, + fail: function (data, code) { + console.log('FMS_Performance_0000 call fuzzyFileToUri fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + complete: function () { + console.log('FMS_Performance_0000 call fuzzyFileToUri in complete'); + } + }); + } + }) + + /** + * @tc.number SUB_STORAGE_FMS_Performance_0000 + * @tc.name FMS_Performance_0000 + * @tc.desc stability test + */ + it('FMS_stability_0000', 0, function () { + for(let i = 0; i < 100000;i++){ + fileShareAbility.fuzzyFileToUri({ + deviceId: '440E-0906', + authority: 'ohos.acts.test.ability', + uri: 'internal://app/f0.txt', + displayName: 'f1.txt', + success: function () { + console.log('FMS_stability_0000 success. '+i); + }, + fail: function (data, code) { + console.log('FMS_stability_0000 fail, code: ' + code + ', data: ' + data); + expect(null).assertFail(); + }, + complete: function () { + console.log('FMS_stability_0000 call fuzzyFileToUri in complete'); + } + }); + } + }) + +}) diff --git a/storage/storagefmssharejstest/src/main/js/default/test/List.test.js b/storage/storagefmssharejstest/src/main/js/default/test/List.test.js new file mode 100644 index 0000000000000000000000000000000000000000..971a7603a3f978bf95eb7cee03b59c7aaef42ac1 --- /dev/null +++ b/storage/storagefmssharejstest/src/main/js/default/test/List.test.js @@ -0,0 +1,16 @@ +/* + * 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('./FmsShare.test.js') diff --git a/storage/storagefmssharejstest/src/main/resources/base/element/string.json b/storage/storagefmssharejstest/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..4b5a8bbc02d07ca41a3c0f63834395a33e02152a --- /dev/null +++ b/storage/storagefmssharejstest/src/main/resources/base/element/string.json @@ -0,0 +1,12 @@ +{ + "string": [ + { + "name": "app_name", + "value": "storagefilestabilityjstest" + }, + { + "name": "mainability_description", + "value": "JS_Phone_Empty Feature Ability" + } + ] +} \ No newline at end of file diff --git a/storage/storagefmssharejstest/src/main/resources/base/media/icon.png b/storage/storagefmssharejstest/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/storage/storagefmssharejstest/src/main/resources/base/media/icon.png differ