diff --git a/storage/BUILD.gn b/storage/BUILD.gn index a5aa713b24e123854e5d3e981bcf3250827580cc..0e2f7040e50d10992faa11ded08e8d4f1235a23c 100644 --- a/storage/BUILD.gn +++ b/storage/BUILD.gn @@ -21,6 +21,7 @@ group("storage") { "storagefilejstest:storagefile_js_test", "storagesecuritylabeljstest:storagesecuritylabel_js_test", "storagestatfsjstest:storagestatfs_js_test", + "storagestatisticsjstest:storagestatistics_js_test", ] } } diff --git a/storage/storagestatisticsjstest/AppScope/app.json b/storage/storagestatisticsjstest/AppScope/app.json new file mode 100644 index 0000000000000000000000000000000000000000..bd440e5a8a390130bce75f7fafff6ab534d3874e --- /dev/null +++ b/storage/storagestatisticsjstest/AppScope/app.json @@ -0,0 +1,20 @@ +{ + "app": { + "bundleName": "com.example.statistics", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name", + "debug": false, + "distributedNotificationEnabled": true, + "keepAlive": true, + "singleUser": true, + "minAPIVersion": 9, + "targetAPIVersion": 9, + "car": { + "apiCompatibleVersion": 9, + "singleUser": false + } + } +} diff --git a/storage/storagestatisticsjstest/AppScope/resources/base/element/string.json b/storage/storagestatisticsjstest/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..52612339e84606772d7e07520bfb16c6723dac8f --- /dev/null +++ b/storage/storagestatisticsjstest/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "storageStatistics" + } + ] +} diff --git a/storage/storagestatisticsjstest/AppScope/resources/base/media/app_icon.png b/storage/storagestatisticsjstest/AppScope/resources/base/media/app_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/storage/storagestatisticsjstest/AppScope/resources/base/media/app_icon.png differ diff --git a/storage/storagestatisticsjstest/BUILD.gn b/storage/storagestatisticsjstest/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..72f1dfc3d41b7707274cde827d9078813a77f16d --- /dev/null +++ b/storage/storagestatisticsjstest/BUILD.gn @@ -0,0 +1,43 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//test/xts/tools/build/suite.gni") + +ohos_js_hap_suite("storagestatistics_js_test") { + hap_profile = "entry/src/main/module.json" + js_build_mode = "debug" + deps = [ + ":storagestatistics_js_assets", + ":storagestatistics_resources", + ] + ets2abc = true + certificate_profile = "signature/openharmony_sx.p7b" + hap_name = "ActsStorageStatisticsJsTest" + subsystem_name = "xts" + part_name = "xts_acts" +} + +ohos_app_scope("storagestatistics_app_profile") { + app_profile = "AppScope/app.json" + sources = [ "AppScope/resources" ] +} + +ohos_js_assets("storagestatistics_js_assets") { + source_dir = "entry/src/main/ets" +} + +ohos_resources("storagestatistics_resources") { + sources = [ "entry/src/main/resources" ] + deps = [ ":storagestatistics_app_profile" ] + hap_profile = "entry/src/main/module.json" +} diff --git a/storage/storagestatisticsjstest/Test.json b/storage/storagestatisticsjstest/Test.json new file mode 100644 index 0000000000000000000000000000000000000000..f434991857190ca5e5fedb75bd6ba477efa9b28e --- /dev/null +++ b/storage/storagestatisticsjstest/Test.json @@ -0,0 +1,20 @@ +{ + "description": "Configuration for hjunit demo Tests", + "driver": { + "type": "OHJSUnitTest", + "test-timeout": "180000", + "bundle-name": "com.example.statistics", + "module-name": "entry", + "shell-timeout": "600000", + "testcase-timeout": 70000 + }, + "kits": [ + { + "test-file-name": [ + "ActsStorageStatisticsJsTest.hap" + ], + "type": "AppInstallKit", + "cleanup-apps": true + } + ] +} \ No newline at end of file diff --git a/storage/storagestatisticsjstest/entry/src/main/ets/Application/AbilityStage.ts b/storage/storagestatisticsjstest/entry/src/main/ets/Application/AbilityStage.ts new file mode 100644 index 0000000000000000000000000000000000000000..ab2682985f2ed3ade10aefeecb9501a67eb05fbc --- /dev/null +++ b/storage/storagestatisticsjstest/entry/src/main/ets/Application/AbilityStage.ts @@ -0,0 +1,22 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import AbilityStage from "@ohos.application.AbilityStage" + +export default class MyAbilityStage extends AbilityStage { + onCreate() { + console.log("[Demo] MyAbilityStage onCreate") + } +} \ No newline at end of file diff --git a/storage/storagestatisticsjstest/entry/src/main/ets/MainAbility/MainAbility.ts b/storage/storagestatisticsjstest/entry/src/main/ets/MainAbility/MainAbility.ts new file mode 100644 index 0000000000000000000000000000000000000000..50fe24cd159e565e53e8c2d35d583b8249a43e45 --- /dev/null +++ b/storage/storagestatisticsjstest/entry/src/main/ets/MainAbility/MainAbility.ts @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import Ability from '@ohos.application.Ability' + +export default class MainAbility extends Ability { + onCreate(want, launchParam) { + // Ability is creating, initialize resources for this ability + console.log("[Demo] MainAbility onCreate"); + globalThis.abilityWant = want; + } + + onDestroy() { + // Ability is destroying, release resources for this ability + console.log("[Demo] MainAbility onDestroy") + } + + onWindowStageCreate(windowStage) { + // Main window is created, set main page for this ability + console.log("[Demo] MainAbility onWindowStageCreate") + globalThis.abilityContext = this.context; + windowStage.setUIContent(this.context, "MainAbility/pages/index", null) + } + + onWindowStageDestroy() { + // Main window is destroyed, release UI related resources + console.log("[Demo] MainAbility onWindowStageDestroy") + } + + onForeground() { + // Ability has brought to foreground + console.log("[Demo] MainAbility onForeground") + } + + onBackground() { + // Ability has back to background + console.log("[Demo] MainAbility onBackground") + } +}; diff --git a/storage/storagestatisticsjstest/entry/src/main/ets/MainAbility/pages/index.ets b/storage/storagestatisticsjstest/entry/src/main/ets/MainAbility/pages/index.ets new file mode 100644 index 0000000000000000000000000000000000000000..6e5301ca39493449d91b2af391d6dd772732f7ec --- /dev/null +++ b/storage/storagestatisticsjstest/entry/src/main/ets/MainAbility/pages/index.ets @@ -0,0 +1,41 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry' +import { Hypium } from '@ohos/hypium' +import testsuite from '../../test/List.test' + +//InstrumentLog, ReportExtend +@Entry +@Component +struct Index { + + aboutToAppear(){ + var abilityDelegator: any + abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() + var abilityDelegatorArguments: any + abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() + Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite); + } + + build() { + Flex({ direction:FlexDirection.Column, alignItems:ItemAlign.Center, justifyContent: FlexAlign.Center }) { + Text('你好,测试...') + .fontSize(50) + .fontWeight(FontWeight.Bold) + } + .width('100%') + .height('100%') + } +} \ No newline at end of file diff --git a/storage/storagestatisticsjstest/entry/src/main/ets/TestAbility/TestAbility.ts b/storage/storagestatisticsjstest/entry/src/main/ets/TestAbility/TestAbility.ts new file mode 100644 index 0000000000000000000000000000000000000000..89a84730505783ba229175ab4b55d37f91a16266 --- /dev/null +++ b/storage/storagestatisticsjstest/entry/src/main/ets/TestAbility/TestAbility.ts @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import Ability from '@ohos.application.Ability' + +export default class TestAbility extends Ability { + onCreate(want, launchParam) { + console.log('TestAbility onCreate') + } + + onDestroy() { + console.log('TestAbility onDestroy') + } + + onWindowStageCreate(windowStage) { + console.log('TestAbility onWindowStageCreate') + windowStage.loadContent("TestAbility/pages/index", (err, data) => { + if (err.code) { + console.error('Failed to load the content. Cause:' + JSON.stringify(err)); + return; + } + console.info('Succeeded in loading the content. Data: ' + JSON.stringify(data)) + }); + + globalThis.abilityContext = this.context; + } + + onWindowStageDestroy() { + console.log('TestAbility onWindowStageDestroy') + } + + onForeground() { + console.log('TestAbility onForeground') + } + + onBackground() { + console.log('TestAbility onBackground') + } +}; \ No newline at end of file diff --git a/storage/storagestatisticsjstest/entry/src/main/ets/TestAbility/pages/index.ets b/storage/storagestatisticsjstest/entry/src/main/ets/TestAbility/pages/index.ets new file mode 100644 index 0000000000000000000000000000000000000000..b93567f962921124b282f78c8ef123965d1460c9 --- /dev/null +++ b/storage/storagestatisticsjstest/entry/src/main/ets/TestAbility/pages/index.ets @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import router from '@ohos.router'; + +@Entry +@Component +struct Index { + aboutToAppear() { + console.info('TestAbility index aboutToAppear') + } + @State message: string = 'Hello World' + build() { + Row() { + Column() { + Text(this.message) + .fontSize(50) + .fontWeight(FontWeight.Bold) + Button() { + Text('next page') + .fontSize(20) + .fontWeight(FontWeight.Bold) + }.type(ButtonType.Capsule) + .margin({ + top: 20 + }) + .backgroundColor('#0D9FFB') + .width('35%') + .height('5%') + .onClick(()=>{ + }) + } + .width('100%') + } + .height('100%') + } + } \ No newline at end of file diff --git a/storage/storagestatisticsjstest/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts b/storage/storagestatisticsjstest/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts new file mode 100644 index 0000000000000000000000000000000000000000..932d665bf5b31598b4c2b109f745044c0abdb143 --- /dev/null +++ b/storage/storagestatisticsjstest/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import TestRunner from '@ohos.application.testRunner' +import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry' + +var abilityDelegator = undefined +var abilityDelegatorArguments = undefined + +function translateParamsToString(parameters) { + const keySet = new Set([ + '-s class', '-s notClass', '-s suite', '-s it', + '-s level', '-s testType', '-s size', '-s timeout', + '-s dryRun' + ]) + let targetParams = ''; + for (const key in parameters) { + if (keySet.has(key)) { + targetParams = `${targetParams} ${key} ${parameters[key]}` + } + } + return targetParams.trim() +} + +async function onAbilityCreateCallback() { + console.log("onAbilityCreateCallback"); +} + +async function addAbilityMonitorCallback(err: any) { + console.info("addAbilityMonitorCallback : " + JSON.stringify(err)) +} + +export default class OpenHarmonyTestRunner implements TestRunner { + constructor() { + } + + onPrepare() { + console.info("OpenHarmonyTestRunner OnPrepare ") + } + + async onRun() { + console.log('OpenHarmonyTestRunner onRun run') + abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() + abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() + var testAbilityName = abilityDelegatorArguments.bundleName + '.MainAbility' + let lMonitor = { + abilityName: testAbilityName, + onAbilityCreate: onAbilityCreateCallback, + }; + abilityDelegator.addAbilityMonitor(lMonitor, addAbilityMonitorCallback) + var cmd = 'aa start -d 0 -a com.example.statistics.MainAbility' + ' -b ' + abilityDelegatorArguments.bundleName + cmd += ' '+translateParamsToString(abilityDelegatorArguments.parameters) + var debug = abilityDelegatorArguments.parameters["-D"] + if (debug == 'true') + { + cmd += ' -D' + } + console.info('cmd : '+cmd) + abilityDelegator.executeShellCommand(cmd, + (err: any, d: any) => { + console.info('executeShellCommand : err : ' + JSON.stringify(err)); + console.info('executeShellCommand : data : ' + d.stdResult); + console.info('executeShellCommand : data : ' + d.exitCode); + }) + console.info('OpenHarmonyTestRunner onRun end') + } +}; \ No newline at end of file diff --git a/storage/storagestatisticsjstest/entry/src/main/ets/test/Common.ets b/storage/storagestatisticsjstest/entry/src/main/ets/test/Common.ets new file mode 100644 index 0000000000000000000000000000000000000000..49af64ae4147414bb2916889e6dc0f95b1b2bdf1 --- /dev/null +++ b/storage/storagestatisticsjstest/entry/src/main/ets/test/Common.ets @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the 'License'); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an 'AS IS' BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +function isIntNum(val) { + return typeof val === "number" && val % 1 === 0; +} + +function isNegativeNum(val) { + return val < 0; +} + +function isInclude(error, message) { + return error.toString().indexOf(message) != -1; +} + +export { + isIntNum, + isNegativeNum, + isInclude +}; diff --git a/storage/storagestatisticsjstest/entry/src/main/ets/test/List.test.ets b/storage/storagestatisticsjstest/entry/src/main/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..6dba954b5f34b357abddbdaab48b5be602c62a85 --- /dev/null +++ b/storage/storagestatisticsjstest/entry/src/main/ets/test/List.test.ets @@ -0,0 +1,23 @@ +// @ts-nocheck +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import storageStatisticsTest from './StorageStatistics.test.ets' + +export default function testsuite() { + storageStatisticsTest() +} + + diff --git a/storage/storagestatisticsjstest/entry/src/main/ets/test/StorageStatistics.test.ets b/storage/storagestatisticsjstest/entry/src/main/ets/test/StorageStatistics.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..c94ce23e4fc22370bcf81e480dbf5abefff36512 --- /dev/null +++ b/storage/storagestatisticsjstest/entry/src/main/ets/test/StorageStatistics.test.ets @@ -0,0 +1,143 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the 'License'); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an 'AS IS' BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// @ts-nocheck +import storageStatistics from "@ohos.storageStatistics"; +import { describe, it, expect } from "@ohos/hypium" +import {isIntNum, isNegativeNum, isInclude} from "./Common"; + +export default function storageStatisticsTest() { + describe("storageStatisticsTest", function () { + /** + * @tc.number SUB_DF_STORAGE_STATISTICS_GET_CURRENT_BUNDLE_STATS_0000 + * @tc.name storage_statistics_test_get_current_bundle_stats_async_000 + * @tc.desc Test getCurrentBundleStats() interfaces, returned in promise mode. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it("storage_statistics_test_get_current_bundle_stats_async_000", 0, async function (done) { + try { + let bundleStat = await storageStatistics.getCurrentBundleStats(); + expect(bundleStat != null).assertTrue(); + expect(isIntNum(bundleStat.appSize) && !isNegativeNum(bundleStat.appSize)).assertTrue(); + expect(isIntNum(bundleStat.cacheSize) && !isNegativeNum(bundleStat.cacheSize)).assertTrue(); + expect(isIntNum(bundleStat.dataSize) && !isNegativeNum(bundleStat.dataSize)).assertTrue(); + done(); + } catch (e) { + console.log("storage_statistics_test_get_current_bundle_stats_async_000 has failed for " + e); + } + }); + + /** + * @tc.number SUB_DF_STORAGE_STATISTICS_GET_CURRENT_BUNDLE_STATS_0010 + * @tc.name storage_statistics_test_get_current_bundle_stats_async_001 + * @tc.desc Test getCurrentBundleStats() interfaces , returned in callback mode. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it("storage_statistics_test_get_current_bundle_stats_async_001", 0, async function (done) { + try { + storageStatistics.getCurrentBundleStats((error, bundleStat) => { + expect(bundleStat != null).assertTrue(); + expect(isIntNum(bundleStat.appSize) && !isNegativeNum(bundleStat.appSize)).assertTrue(); + expect(isIntNum(bundleStat.cacheSize) && !isNegativeNum(bundleStat.cacheSize)).assertTrue(); + expect(isIntNum(bundleStat.dataSize) && !isNegativeNum(bundleStat.dataSize)).assertTrue(); + done(); + }); + } catch (e) { + console.log("storage_statistics_test_get_current_bundle_stats_async_001 has failed for " + e); + } + }); + + /** + * @tc.number SUB_DF_STORAGE_STATISTICS_GET_CURRENT_BUNDLE_STATS_0020 + * @tc.name storage_statistics_test_get_current_bundle_stats_async_002 + * @tc.desc Test getCurrentBundleStats() interfaces, When the parameter type is wrong. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it("storage_statistics_test_get_current_bundle_stats_async_002", 0, async function (done) { + try { + await storageStatistics.getCurrentBundleStats("1"); + } catch (error) { + console.log("storage_statistics_test_get_current_bundle_stats_async_002 has failed for " + error); + expect(isInclude(error, "The callback shall be a function")).assertTrue(); + done(); + } + }); + + /** + * @tc.number SUB_DF_STORAGE_STATISTICS_GET_CURRENT_BUNDLE_STATS_0030 + * @tc.name storage_statistics_test_get_current_bundle_stats_async_003 + * @tc.desc Test getCurrentBundleStats() interfaces, When there are redundant parameters. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it("storage_statistics_test_get_current_bundle_stats_async_003", 0, async function (done) { + try { + storageStatistics.getCurrentBundleStats("", (error, bundleStat) => { + + }); + } catch (error) { + console.log("storage_statistics_test_get_current_bundle_stats_async_003 has failed for " + error); + expect(isInclude(error, "Number of arguments unmatched")).assertTrue(); + done(); + } + }); + + /** + * @tc.number SUB_DF_STORAGE_STATISTICS_GET_CURRENT_BUNDLE_STATS_0040 + * @tc.name storage_statistics_test_get_current_bundle_stats_async_004 + * @tc.desc Test getCurrentBundleStats() interfaces,Concurrent requests. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it("storage_statistics_test_get_current_bundle_stats_async_004", 0, async function (done) { + try { + const delay = function delay() { + return new Promise((resolve, reject) => { + storageStatistics.getCurrentBundleStats((err, result)=>{ + resolve(result); + }) + }); + }; + let tasks = [delay(), delay(), delay(), delay()]; + Promise.all(tasks).then(results => { + let isNotNull = results.every(bundleStat => { + return bundleStat != null && JSON.stringify(bundleStat) != "{}"; + }); + let flag = !results.some(value => { + return JSON.stringify(value) !== JSON.stringify(results[0]); + }); + expect(results.length == tasks.length).assertTrue(); + expect(flag).assertTrue(); + expect(isNotNull).assertTrue(); + done(); + }); + } catch (error) { + console.log("storage_statistics_test_get_current_bundle_stats_async_004 has failed for " + error); + } + }) + }); +} \ No newline at end of file diff --git a/storage/storagestatisticsjstest/entry/src/main/module.json b/storage/storagestatisticsjstest/entry/src/main/module.json new file mode 100644 index 0000000000000000000000000000000000000000..3d0ff25f8d39b3c59147086cd5925ad4b041cb4f --- /dev/null +++ b/storage/storagestatisticsjstest/entry/src/main/module.json @@ -0,0 +1,38 @@ +{ + "module": { + "package": "com.example.statistics", + "name": "entry", + "mainAbility": "com.example.statistics.MainAbility", + "type": "entry", + "srcEntrance": "./ets/Application/AbilityStage.ts", + "description": "$string:entry_desc", + "mainElement": "MainAbility", + "deviceTypes": [ + "phone" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "uiSyntax": "ets", + "abilities": [ + { + "name": "com.example.statistics.MainAbility", + "srcEntrance": "./ets/MainAbility/MainAbility.ts", + "description": "$string:MainAbility_desc", + "icon": "$media:icon", + "label": "$string:MainAbility_label", + "visible": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ] + } + ] + } +} \ No newline at end of file diff --git a/storage/storagestatisticsjstest/entry/src/main/resources/base/element/string.json b/storage/storagestatisticsjstest/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..5be1bde95e8ca1f8a731c6530b5781d667f07290 --- /dev/null +++ b/storage/storagestatisticsjstest/entry/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "entry_desc", + "value": "description" + }, + { + "name": "MainAbility_desc", + "value": "description" + }, + { + "name": "MainAbility_label", + "value": "ActsStorageStatisticsJsTest" + } + ] +} \ No newline at end of file diff --git a/storage/storagestatisticsjstest/entry/src/main/resources/base/media/icon.png b/storage/storagestatisticsjstest/entry/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/storage/storagestatisticsjstest/entry/src/main/resources/base/media/icon.png differ diff --git a/storage/storagestatisticsjstest/entry/src/main/resources/base/profile/main_pages.json b/storage/storagestatisticsjstest/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..c1858c216308ad312862a877139a8ba6908ec3c6 --- /dev/null +++ b/storage/storagestatisticsjstest/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "MainAbility/pages/index" + ] +} diff --git a/storage/storagestatisticsjstest/signature/openharmony_sx.p7b b/storage/storagestatisticsjstest/signature/openharmony_sx.p7b new file mode 100644 index 0000000000000000000000000000000000000000..66b4457a8a81fb8d3356cf46d67226c850944858 Binary files /dev/null and b/storage/storagestatisticsjstest/signature/openharmony_sx.p7b differ